NFC: nci: Handle proprietary response and notifications
authorSamuel Ortiz <sameo@linux.intel.com>
Sat, 6 Jun 2015 11:16:37 +0000 (13:16 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 8 Jun 2015 22:34:20 +0000 (00:34 +0200)
Allow for drivers to explicitly define handlers for each
proprietary notifications and responses they expect to support.

Reviewed-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 d4dcc7199fd766aeddd2cfe51a8411d6a873581f..c49688c0985362a274cfa69407256ccd86d4a83d 100644 (file)
@@ -66,6 +66,12 @@ enum nci_state {
 
 struct nci_dev;
 
+struct nci_prop_ops {
+       __u16 opcode;
+       int (*rsp)(struct nci_dev *dev, struct sk_buff *skb);
+       int (*ntf)(struct nci_dev *dev, struct sk_buff *skb);
+};
+
 struct nci_ops {
        int   (*open)(struct nci_dev *ndev);
        int   (*close)(struct nci_dev *ndev);
@@ -84,12 +90,16 @@ struct nci_ops {
                                    struct sk_buff *skb);
        void  (*hci_cmd_received)(struct nci_dev *ndev, u8 pipe, u8 cmd,
                                  struct sk_buff *skb);
+
+       struct nci_prop_ops *prop_ops;
+       size_t n_prop_ops;
 };
 
 #define NCI_MAX_SUPPORTED_RF_INTERFACES                4
 #define NCI_MAX_DISCOVERED_TARGETS             10
 #define NCI_MAX_NUM_NFCEE   255
 #define NCI_MAX_CONN_ID                7
+#define NCI_MAX_PROPRIETARY_CMD 64
 
 struct nci_conn_info {
        struct list_head list;
@@ -320,6 +330,10 @@ static inline void *nci_get_drvdata(struct nci_dev *ndev)
 
 void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb);
 void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb);
+int nci_prop_rsp_packet(struct nci_dev *ndev, __u16 opcode,
+                       struct sk_buff *skb);
+int nci_prop_ntf_packet(struct nci_dev *ndev, __u16 opcode,
+                       struct sk_buff *skb);
 void nci_rx_data_packet(struct nci_dev *ndev, struct sk_buff *skb);
 int nci_send_cmd(struct nci_dev *ndev, __u16 opcode, __u8 plen, void *payload);
 int nci_send_data(struct nci_dev *ndev, __u8 conn_id, struct sk_buff *skb);
index 49ff321060809a320966d5efc24ea6aaaab1add8..56d57c93ea1a20dd2fb64a56f61d0dd4cab28fd4 100644 (file)
@@ -28,6 +28,7 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
 
 #include <linux/module.h>
+#include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/workqueue.h>
 #include <linux/completion.h>
@@ -961,6 +962,14 @@ struct nci_dev *nci_allocate_device(struct nci_ops *ops,
                return NULL;
 
        ndev->ops = ops;
+
+       if (ops->n_prop_ops > NCI_MAX_PROPRIETARY_CMD) {
+               pr_err("Too many proprietary commands: %zd\n",
+                      ops->n_prop_ops);
+               ops->prop_ops = NULL;
+               ops->n_prop_ops = 0;
+       }
+
        ndev->tx_headroom = tx_headroom;
        ndev->tx_tailroom = tx_tailroom;
        init_completion(&ndev->req_completion);
@@ -1165,6 +1174,49 @@ int nci_send_cmd(struct nci_dev *ndev, __u16 opcode, __u8 plen, void *payload)
        return 0;
 }
 
+/* Proprietary commands API */
+static struct nci_prop_ops *prop_cmd_lookup(struct nci_dev *ndev,
+                                           __u16 opcode)
+{
+       size_t i;
+       struct nci_prop_ops *prop_op;
+
+       if (!ndev->ops->prop_ops || !ndev->ops->n_prop_ops)
+               return NULL;
+
+       for (i = 0; i < ndev->ops->n_prop_ops; i++) {
+               prop_op = &ndev->ops->prop_ops[i];
+               if (prop_op->opcode == opcode)
+                       return prop_op;
+       }
+
+       return NULL;
+}
+
+int nci_prop_rsp_packet(struct nci_dev *ndev, __u16 rsp_opcode,
+                       struct sk_buff *skb)
+{
+       struct nci_prop_ops *prop_op;
+
+       prop_op = prop_cmd_lookup(ndev, rsp_opcode);
+       if (!prop_op || !prop_op->rsp)
+               return -ENOTSUPP;
+
+       return prop_op->rsp(ndev, skb);
+}
+
+int nci_prop_ntf_packet(struct nci_dev *ndev, __u16 ntf_opcode,
+                       struct sk_buff *skb)
+{
+       struct nci_prop_ops *prop_op;
+
+       prop_op = prop_cmd_lookup(ndev, ntf_opcode);
+       if (!prop_op || !prop_op->ntf)
+               return -ENOTSUPP;
+
+       return prop_op->ntf(ndev, skb);
+}
+
 /* ---- NCI TX Data worker thread ---- */
 
 static void nci_tx_work(struct work_struct *work)
index 3218071072ac698a85e88fdb5c1b7e6d55a6217d..5d1c2e391c56a8caf3b457796bcfbc60bf8982a9 100644 (file)
@@ -758,6 +758,15 @@ void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb)
        /* strip the nci control header */
        skb_pull(skb, NCI_CTRL_HDR_SIZE);
 
+       if (nci_opcode_gid(ntf_opcode) == NCI_GID_PROPRIETARY) {
+               if (nci_prop_ntf_packet(ndev, ntf_opcode, skb)) {
+                       pr_err("unsupported ntf opcode 0x%x\n",
+                              ntf_opcode);
+               }
+
+               goto end;
+       }
+
        switch (ntf_opcode) {
        case NCI_OP_CORE_CONN_CREDITS_NTF:
                nci_core_conn_credits_ntf_packet(ndev, skb);
@@ -796,5 +805,6 @@ void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb)
                break;
        }
 
+end:
        kfree_skb(skb);
 }
index 02486bc2ceea961200169d599fce407922fedcb6..408bd8f857ab9fd506ad137dd0333db0b2556613 100644 (file)
@@ -296,6 +296,15 @@ void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
        /* strip the nci control header */
        skb_pull(skb, NCI_CTRL_HDR_SIZE);
 
+       if (nci_opcode_gid(rsp_opcode) == NCI_GID_PROPRIETARY) {
+               if (nci_prop_rsp_packet(ndev, rsp_opcode, skb) == -ENOTSUPP) {
+                       pr_err("unsupported rsp opcode 0x%x\n",
+                              rsp_opcode);
+               }
+
+               goto end;
+       }
+
        switch (rsp_opcode) {
        case NCI_OP_CORE_RESET_RSP:
                nci_core_reset_rsp_packet(ndev, skb);
@@ -346,6 +355,7 @@ void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
                break;
        }
 
+end:
        kfree_skb(skb);
 
        /* trigger the next cmd */
This page took 0.028739 seconds and 5 git commands to generate.