]> git.karo-electronics.de Git - linux-beck.git/commitdiff
NFC: nci: Add NFCEE discover support
authorChristophe Ricard <christophe.ricard@gmail.com>
Sun, 1 Feb 2015 21:26:10 +0000 (22:26 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 2 Feb 2015 20:50:38 +0000 (21:50 +0100)
NFCEEs (NFC Execution Environment) have to be explicitly
discovered by sending the NCI_OP_NFCEE_DISCOVER_CMD
command. The NFCC will respond to this command by telling
us how many NFCEEs are connected to it. Then the NFCC sends
a notification command for each and every NFCEE connected.
Here we implement support for sending
NCI_OP_NFCEE_DISCOVER_CMD command, receiving the response
and the potential notifications.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
include/net/nfc/nci_core.h
net/nfc/nci/core.c
net/nfc/nci/ntf.c
net/nfc/nci/rsp.c

index 5e508741f208b2ba189e3b01cc4bd29a10498d3b..31ad795aa4b51d8b72cec5150fc181df32d7185c 100644 (file)
@@ -100,6 +100,8 @@ struct nci_conn_info {
        struct sk_buff *rx_skb;
 };
 
+#define NCI_INVALID_CONN_ID 0x80
+
 /* NCI Core structures */
 struct nci_dev {
        struct nfc_dev          *nfc_dev;
@@ -182,6 +184,8 @@ void nci_unregister_device(struct nci_dev *ndev);
 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);
+
 static inline struct sk_buff *nci_skb_alloc(struct nci_dev *ndev,
                                            unsigned int len,
                                            gfp_t how)
index eb607970bd569af5a19c516969539f1c8c15927c..a258575485248b38764127d37eb273b5d6588340 100644 (file)
@@ -469,6 +469,23 @@ int nci_set_config(struct nci_dev *ndev, __u8 id, size_t len, __u8 *val)
 }
 EXPORT_SYMBOL(nci_set_config);
 
+static void nci_nfcee_discover_req(struct nci_dev *ndev, unsigned long opt)
+{
+       struct nci_nfcee_discover_cmd cmd;
+       __u8 action = opt;
+
+       cmd.discovery_action = action;
+
+       nci_send_cmd(ndev, NCI_OP_NFCEE_DISCOVER_CMD, 1, &cmd);
+}
+
+int nci_nfcee_discover(struct nci_dev *ndev, u8 action)
+{
+       return nci_request(ndev, nci_nfcee_discover_req, action,
+                               msecs_to_jiffies(NCI_CMD_TIMEOUT));
+}
+EXPORT_SYMBOL(nci_nfcee_discover);
+
 static int nci_set_local_general_bytes(struct nfc_dev *nfc_dev)
 {
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
index 28fdbe234bd4175e212607b317e888341228e431..4c0be7e82d29d08d11bbf568cc9b8e4794784c29 100644 (file)
@@ -713,6 +713,33 @@ static void nci_rf_deactivate_ntf_packet(struct nci_dev *ndev,
        nci_req_complete(ndev, NCI_STATUS_OK);
 }
 
+static void nci_nfcee_discover_ntf_packet(struct nci_dev *ndev,
+                                         struct sk_buff *skb)
+{
+       u8 status = NCI_STATUS_OK;
+       struct nci_conn_info    *conn_info;
+       struct nci_nfcee_discover_ntf   *nfcee_ntf =
+                               (struct nci_nfcee_discover_ntf *)skb->data;
+
+       pr_debug("\n");
+
+       conn_info = devm_kzalloc(&ndev->nfc_dev->dev,
+                                sizeof(struct nci_conn_info), GFP_KERNEL);
+       if (!conn_info) {
+               status = NCI_STATUS_REJECTED;
+               goto exit;
+       }
+
+       conn_info->id = nfcee_ntf->nfcee_id;
+       conn_info->conn_id = NCI_INVALID_CONN_ID;
+
+       INIT_LIST_HEAD(&conn_info->list);
+       list_add(&conn_info->list, &ndev->conn_info_list);
+
+exit:
+       nci_req_complete(ndev, status);
+}
+
 void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb)
 {
        __u16 ntf_opcode = nci_opcode(skb->data);
@@ -751,6 +778,9 @@ void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb)
                nci_rf_deactivate_ntf_packet(ndev, skb);
                break;
 
+       case NCI_OP_NFCEE_DISCOVER_NTF:
+               nci_nfcee_discover_ntf_packet(ndev, skb);
+               break;
        default:
                pr_err("unknown ntf opcode 0x%x\n", ntf_opcode);
                break;
index 93b914937263c70e9b3af5ad9de7122677c9052b..ee094dfab2edd25d9696ec981b3128eabc941884 100644 (file)
@@ -196,6 +196,23 @@ static void nci_rf_deactivate_rsp_packet(struct nci_dev *ndev,
        }
 }
 
+static void nci_nfcee_discover_rsp_packet(struct nci_dev *ndev,
+                                         struct sk_buff *skb)
+{
+       struct nci_nfcee_discover_rsp *discover_rsp;
+
+       if (skb->len != 2) {
+               nci_req_complete(ndev, NCI_STATUS_NFCEE_PROTOCOL_ERROR);
+               return;
+       }
+
+       discover_rsp = (struct nci_nfcee_discover_rsp *)skb->data;
+
+       if (discover_rsp->status != NCI_STATUS_OK ||
+           discover_rsp->num_nfcee == 0)
+               nci_req_complete(ndev, discover_rsp->status);
+}
+
 void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
 {
        __u16 rsp_opcode = nci_opcode(skb->data);
@@ -241,6 +258,10 @@ void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
                nci_rf_deactivate_rsp_packet(ndev, skb);
                break;
 
+       case NCI_OP_NFCEE_DISCOVER_RSP:
+               nci_nfcee_discover_rsp_packet(ndev, skb);
+               break;
+
        default:
                pr_err("unknown rsp opcode 0x%x\n", rsp_opcode);
                break;