NFC: Initial Secure Element API
authorSamuel Ortiz <sameo@linux.intel.com>
Wed, 19 Dec 2012 18:11:32 +0000 (19:11 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 9 Jan 2013 23:51:54 +0000 (00:51 +0100)
Each NFC adapter can have several links to different secure elements and
that property needs to be exported by the drivers.
A secure element link can be enabled and disabled, and card emulation will
be handled by the currently active one. Otherwise card emulation will be
host implemented.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/nfc/nfcwilink.c
drivers/nfc/pn533.c
drivers/nfc/pn544/pn544.c
include/net/nfc/hci.h
include/net/nfc/nci_core.h
include/net/nfc/nfc.h
include/uapi/linux/nfc.h
net/nfc/core.c
net/nfc/hci/core.c
net/nfc/nci/core.c
net/nfc/netlink.c

index c7c182d2b7df1d39649a4fb99f3ec1884707dff3..3b731acbc408fbc807ea8ffa4eef9f0dc622e97f 100644 (file)
@@ -542,6 +542,7 @@ static int nfcwilink_probe(struct platform_device *pdev)
 
        drv->ndev = nci_allocate_device(&nfcwilink_ops,
                                        protocols,
+                                       NFC_SE_NONE,
                                        NFCWILINK_HDR_LEN,
                                        0);
        if (!drv->ndev) {
index e8c083203b3334fe39236fec2ae3a0daf91ad80b..31a5b3b53b2a0280d4090ba5a186642b1678fb00 100644 (file)
@@ -2525,6 +2525,7 @@ static int pn533_probe(struct usb_interface *interface,
 
 
        dev->nfc_dev = nfc_allocate_device(&pn533_nfc_ops, protocols,
+                                          NFC_SE_NONE,
                                           dev->ops->tx_header_len +
                                           PN533_CMD_DATAEXCH_HEAD_LEN,
                                           dev->ops->tx_tail_len);
index d108c794008d5920afc7f4fea590090fc509fb99..9c5f16e7baefa40970f7d3274aaff53fcd2f8c9a 100644 (file)
@@ -801,7 +801,7 @@ int pn544_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops, char *llc_name,
                    struct nfc_hci_dev **hdev)
 {
        struct pn544_hci_info *info;
-       u32 protocols;
+       u32 protocols, se;
        struct nfc_hci_init_data init_data;
        int r;
 
@@ -834,8 +834,10 @@ int pn544_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops, char *llc_name,
                    NFC_PROTO_ISO14443_B_MASK |
                    NFC_PROTO_NFC_DEP_MASK;
 
+       se = NFC_SE_UICC | NFC_SE_EMBEDDED;
+
        info->hdev = nfc_hci_allocate_device(&pn544_hci_ops, &init_data, 0,
-                                            protocols, llc_name,
+                                            protocols, se, llc_name,
                                             phy_headroom + PN544_CMDS_HEADROOM,
                                             phy_tailroom, phy_payload);
        if (!info->hdev) {
index 2ff71750c4280dafda7d3736fb07e094c7eee586..b87a1692b0864f436a9185447cbfe74cce6ec7e1 100644 (file)
@@ -59,6 +59,8 @@ struct nfc_hci_ops {
                              struct nfc_target *target);
        int (*event_received)(struct nfc_hci_dev *hdev, u8 gate, u8 event,
                              struct sk_buff *skb);
+       int (*enable_se)(struct nfc_dev *dev, u32 secure_element);
+       int (*disable_se)(struct nfc_dev *dev, u32 secure_element);
 };
 
 /* Pipes */
@@ -150,6 +152,7 @@ struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
                                            struct nfc_hci_init_data *init_data,
                                            unsigned long quirks,
                                            u32 protocols,
+                                           u32 supported_se,
                                            const char *llc_name,
                                            int tx_headroom,
                                            int tx_tailroom,
index d705d867494987b30da4272fe4c1967a7884412a..5bc0c460edc0189b56633a111159a15f7a430131 100644 (file)
@@ -147,6 +147,7 @@ struct nci_dev {
 /* ----- NCI Devices ----- */
 struct nci_dev *nci_allocate_device(struct nci_ops *ops,
                                    __u32 supported_protocols,
+                                   __u32 supported_se,
                                    int tx_headroom,
                                    int tx_tailroom);
 void nci_free_device(struct nci_dev *ndev);
index 1665674e86b28d6158f561045ad8cabc31b63935..87a6417fc934487acb2c734f53af3b78fb09d013 100644 (file)
@@ -68,6 +68,8 @@ struct nfc_ops {
                             void *cb_context);
        int (*tm_send)(struct nfc_dev *dev, struct sk_buff *skb);
        int (*check_presence)(struct nfc_dev *dev, struct nfc_target *target);
+       int (*enable_se)(struct nfc_dev *dev, u32 secure_element);
+       int (*disable_se)(struct nfc_dev *dev, u32 secure_element);
 };
 
 #define NFC_TARGET_IDX_ANY -1
@@ -109,6 +111,9 @@ struct nfc_dev {
        struct nfc_genl_data genl_data;
        u32 supported_protocols;
 
+       u32 supported_se;
+       u32 active_se;
+
        int tx_headroom;
        int tx_tailroom;
 
@@ -125,6 +130,7 @@ extern struct class nfc_class;
 
 struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
                                    u32 supported_protocols,
+                                   u32 supported_se,
                                    int tx_headroom,
                                    int tx_tailroom);
 
index 0e63cee8d810b7ef33832d6f030e4c2dbe246c63..80e4ecd8c04c14481f2b708a34b637f3ff56d324 100644 (file)
  *     subsequent CONNECT and CC messages.
  *     If one of the passed parameters is wrong none is set and -EINVAL is
  *     returned.
+ * @NFC_CMD_ENABLE_SE: Enable the physical link to a specific secure element.
+ *     Once enabled a secure element will handle card emulation mode, i.e.
+ *     starting a poll from a device which has a secure element enabled means
+ *     we want to do SE based card emulation.
+ * @NFC_CMD_DISABLE_SE: Disable the physical link to a specific secure element.
  */
 enum nfc_commands {
        NFC_CMD_UNSPEC,
@@ -86,6 +91,8 @@ enum nfc_commands {
        NFC_EVENT_TM_DEACTIVATED,
        NFC_CMD_LLC_GET_PARAMS,
        NFC_CMD_LLC_SET_PARAMS,
+       NFC_CMD_ENABLE_SE,
+       NFC_CMD_DISABLE_SE,
 /* private: internal use only */
        __NFC_CMD_AFTER_LAST
 };
@@ -114,6 +121,7 @@ enum nfc_commands {
  * @NFC_ATTR_LLC_PARAM_LTO: Link TimeOut parameter
  * @NFC_ATTR_LLC_PARAM_RW: Receive Window size parameter
  * @NFC_ATTR_LLC_PARAM_MIUX: MIU eXtension parameter
+ * @NFC_ATTR_SE: Available Secure Elements
  */
 enum nfc_attrs {
        NFC_ATTR_UNSPEC,
@@ -134,6 +142,7 @@ enum nfc_attrs {
        NFC_ATTR_LLC_PARAM_LTO,
        NFC_ATTR_LLC_PARAM_RW,
        NFC_ATTR_LLC_PARAM_MIUX,
+       NFC_ATTR_SE,
 /* private: internal use only */
        __NFC_ATTR_AFTER_LAST
 };
@@ -172,6 +181,11 @@ enum nfc_attrs {
 #define NFC_PROTO_NFC_DEP_MASK   (1 << NFC_PROTO_NFC_DEP)
 #define NFC_PROTO_ISO14443_B_MASK (1 << NFC_PROTO_ISO14443_B)
 
+/* NFC Secure Elements */
+#define NFC_SE_NONE     0x0
+#define NFC_SE_UICC     0x1
+#define NFC_SE_EMBEDDED 0x2
+
 struct sockaddr_nfc {
        sa_family_t sa_family;
        __u32 dev_idx;
index 7d7b4ee34015ba04c356b7a449537265aed72db8..25522e56d3507645e6aa4d89bc692da91263dad9 100644 (file)
@@ -757,6 +757,7 @@ struct nfc_dev *nfc_get_device(unsigned int idx)
  */
 struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
                                    u32 supported_protocols,
+                                   u32 supported_se,
                                    int tx_headroom, int tx_tailroom)
 {
        struct nfc_dev *dev;
@@ -774,6 +775,8 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
 
        dev->ops = ops;
        dev->supported_protocols = supported_protocols;
+       dev->supported_se = supported_se;
+       dev->active_se = NFC_SE_NONE;
        dev->tx_headroom = tx_headroom;
        dev->tx_tailroom = tx_tailroom;
 
index 755a6b9774ab911daa887be5dedb74183733d230..91020b210d8774416467bf009130cad9db5870a1 100644 (file)
@@ -797,6 +797,7 @@ struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
                                            struct nfc_hci_init_data *init_data,
                                            unsigned long quirks,
                                            u32 protocols,
+                                           u32 supported_se,
                                            const char *llc_name,
                                            int tx_headroom,
                                            int tx_tailroom,
@@ -822,7 +823,7 @@ struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
                return NULL;
        }
 
-       hdev->ndev = nfc_allocate_device(&hci_nfc_ops, protocols,
+       hdev->ndev = nfc_allocate_device(&hci_nfc_ops, protocols, supported_se,
                                         tx_headroom + HCI_CMDS_HEADROOM,
                                         tx_tailroom);
        if (!hdev->ndev) {
index 5f98dc1bf03943abfd3315109acf94431858a9e2..48ada0ec749ec369bb6fc78308f12805cfa90c69 100644 (file)
@@ -658,6 +658,7 @@ static struct nfc_ops nci_nfc_ops = {
  */
 struct nci_dev *nci_allocate_device(struct nci_ops *ops,
                                    __u32 supported_protocols,
+                                   __u32 supported_se,
                                    int tx_headroom, int tx_tailroom)
 {
        struct nci_dev *ndev;
@@ -680,6 +681,7 @@ struct nci_dev *nci_allocate_device(struct nci_ops *ops,
 
        ndev->nfc_dev = nfc_allocate_device(&nci_nfc_ops,
                                            supported_protocols,
+                                           supported_se,
                                            tx_headroom + NCI_DATA_HDR_SIZE,
                                            tx_tailroom);
        if (!ndev->nfc_dev)
index 3568ae16786d513830040ddb020c33237649198b..504b883439f1b535b565c8efdc79e965afe465d4 100644 (file)
@@ -366,6 +366,7 @@ static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev,
        if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) ||
            nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
            nla_put_u32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols) ||
+           nla_put_u32(msg, NFC_ATTR_SE, dev->supported_se) ||
            nla_put_u8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up) ||
            nla_put_u8(msg, NFC_ATTR_RF_MODE, dev->rf_mode))
                goto nla_put_failure;