Skip to content

Commit

Permalink
NFC: nci: Add NFCEE enabling and disabling support
Browse files Browse the repository at this point in the history
NFCEEs can be enabled or disabled by sending the
NCI_OP_NFCEE_MODE_SET_CMD command to the NFCC. This patch
provides an API for drivers to enable and disable e.g. their
NCI discoveredd secure elements.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
  • Loading branch information
Christophe Ricard authored and Samuel Ortiz committed Feb 2, 2015
1 parent af9c8aa commit f7f793f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/net/nfc/nci.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ struct nci_nfcee_discover_cmd {
__u8 discovery_action;
} __packed;

#define NCI_OP_NFCEE_MODE_SET_CMD nci_opcode_pack(NCI_GID_NFCEE_MGMT, 0x01)
#define NCI_NFCEE_DISABLE 0x00
#define NCI_NFCEE_ENABLE 0x01
struct nci_nfcee_mode_set_cmd {
__u8 nfcee_id;
__u8 nfcee_mode;
} __packed;

/* ----------------------- */
/* ---- NCI Responses ---- */
/* ----------------------- */
Expand Down Expand Up @@ -333,6 +341,7 @@ struct nci_nfcee_discover_rsp {
__u8 num_nfcee;
} __packed;

#define NCI_OP_NFCEE_MODE_SET_RSP nci_opcode_pack(NCI_GID_NFCEE_MGMT, 0x01)
/* --------------------------- */
/* ---- NCI Notifications ---- */
/* --------------------------- */
Expand Down
1 change: 1 addition & 0 deletions include/net/nfc/nci_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ int nci_recv_frame(struct nci_dev *ndev, struct sk_buff *skb);
int nci_set_config(struct nci_dev *ndev, __u8 id, size_t len, __u8 *val);

int nci_nfcee_discover(struct nci_dev *ndev, u8 action);
int nci_nfcee_mode_set(struct nci_dev *ndev, u8 nfcee_id, u8 nfcee_mode);

static inline struct sk_buff *nci_skb_alloc(struct nci_dev *ndev,
unsigned int len,
Expand Down
21 changes: 21 additions & 0 deletions net/nfc/nci/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,27 @@ int nci_nfcee_discover(struct nci_dev *ndev, u8 action)
}
EXPORT_SYMBOL(nci_nfcee_discover);

static void nci_nfcee_mode_set_req(struct nci_dev *ndev, unsigned long opt)
{
struct nci_nfcee_mode_set_cmd *cmd =
(struct nci_nfcee_mode_set_cmd *)opt;

nci_send_cmd(ndev, NCI_OP_NFCEE_MODE_SET_CMD,
sizeof(struct nci_nfcee_mode_set_cmd), cmd);
}

int nci_nfcee_mode_set(struct nci_dev *ndev, u8 nfcee_id, u8 nfcee_mode)
{
struct nci_nfcee_mode_set_cmd cmd;

cmd.nfcee_id = nfcee_id;
cmd.nfcee_mode = nfcee_mode;

return nci_request(ndev, nci_nfcee_mode_set_req, (unsigned long)&cmd,
msecs_to_jiffies(NCI_CMD_TIMEOUT));
}
EXPORT_SYMBOL(nci_nfcee_mode_set);

static int nci_set_local_general_bytes(struct nfc_dev *nfc_dev)
{
struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
Expand Down
13 changes: 13 additions & 0 deletions net/nfc/nci/rsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ static void nci_nfcee_discover_rsp_packet(struct nci_dev *ndev,
nci_req_complete(ndev, discover_rsp->status);
}

static void nci_nfcee_mode_set_rsp_packet(struct nci_dev *ndev,
struct sk_buff *skb)
{
__u8 status = skb->data[0];

pr_debug("status 0x%x\n", status);
nci_req_complete(ndev, status);
}

void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
{
__u16 rsp_opcode = nci_opcode(skb->data);
Expand Down Expand Up @@ -262,6 +271,10 @@ void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
nci_nfcee_discover_rsp_packet(ndev, skb);
break;

case NCI_OP_NFCEE_MODE_SET_RSP:
nci_nfcee_mode_set_rsp_packet(ndev, skb);
break;

default:
pr_err("unknown rsp opcode 0x%x\n", rsp_opcode);
break;
Expand Down

0 comments on commit f7f793f

Please sign in to comment.