diff options
author | Samuel Ortiz <sameo@linux.intel.com> | 2012-12-19 13:11:32 -0500 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2013-01-09 18:51:54 -0500 |
commit | 390a1bd8538132186ddb679cafe9e75b7ef7e2d2 (patch) | |
tree | 1c548396163a30e0e29f6572cf7b6f0c645085ba | |
parent | 2ad554a502facd705ce6eb362d0f1ac3ca426508 (diff) |
NFC: Initial Secure Element API
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>
-rw-r--r-- | drivers/nfc/nfcwilink.c | 1 | ||||
-rw-r--r-- | drivers/nfc/pn533.c | 1 | ||||
-rw-r--r-- | drivers/nfc/pn544/pn544.c | 6 | ||||
-rw-r--r-- | include/net/nfc/hci.h | 3 | ||||
-rw-r--r-- | include/net/nfc/nci_core.h | 1 | ||||
-rw-r--r-- | include/net/nfc/nfc.h | 6 | ||||
-rw-r--r-- | include/uapi/linux/nfc.h | 14 | ||||
-rw-r--r-- | net/nfc/core.c | 3 | ||||
-rw-r--r-- | net/nfc/hci/core.c | 3 | ||||
-rw-r--r-- | net/nfc/nci/core.c | 2 | ||||
-rw-r--r-- | net/nfc/netlink.c | 1 |
11 files changed, 38 insertions, 3 deletions
diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c index c7c182d2b7df..3b731acbc408 100644 --- a/drivers/nfc/nfcwilink.c +++ b/drivers/nfc/nfcwilink.c | |||
@@ -542,6 +542,7 @@ static int nfcwilink_probe(struct platform_device *pdev) | |||
542 | 542 | ||
543 | drv->ndev = nci_allocate_device(&nfcwilink_ops, | 543 | drv->ndev = nci_allocate_device(&nfcwilink_ops, |
544 | protocols, | 544 | protocols, |
545 | NFC_SE_NONE, | ||
545 | NFCWILINK_HDR_LEN, | 546 | NFCWILINK_HDR_LEN, |
546 | 0); | 547 | 0); |
547 | if (!drv->ndev) { | 548 | if (!drv->ndev) { |
diff --git a/drivers/nfc/pn533.c b/drivers/nfc/pn533.c index e8c083203b33..31a5b3b53b2a 100644 --- a/drivers/nfc/pn533.c +++ b/drivers/nfc/pn533.c | |||
@@ -2525,6 +2525,7 @@ static int pn533_probe(struct usb_interface *interface, | |||
2525 | 2525 | ||
2526 | 2526 | ||
2527 | dev->nfc_dev = nfc_allocate_device(&pn533_nfc_ops, protocols, | 2527 | dev->nfc_dev = nfc_allocate_device(&pn533_nfc_ops, protocols, |
2528 | NFC_SE_NONE, | ||
2528 | dev->ops->tx_header_len + | 2529 | dev->ops->tx_header_len + |
2529 | PN533_CMD_DATAEXCH_HEAD_LEN, | 2530 | PN533_CMD_DATAEXCH_HEAD_LEN, |
2530 | dev->ops->tx_tail_len); | 2531 | dev->ops->tx_tail_len); |
diff --git a/drivers/nfc/pn544/pn544.c b/drivers/nfc/pn544/pn544.c index d108c794008d..9c5f16e7baef 100644 --- a/drivers/nfc/pn544/pn544.c +++ b/drivers/nfc/pn544/pn544.c | |||
@@ -801,7 +801,7 @@ int pn544_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops, char *llc_name, | |||
801 | struct nfc_hci_dev **hdev) | 801 | struct nfc_hci_dev **hdev) |
802 | { | 802 | { |
803 | struct pn544_hci_info *info; | 803 | struct pn544_hci_info *info; |
804 | u32 protocols; | 804 | u32 protocols, se; |
805 | struct nfc_hci_init_data init_data; | 805 | struct nfc_hci_init_data init_data; |
806 | int r; | 806 | int r; |
807 | 807 | ||
@@ -834,8 +834,10 @@ int pn544_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops, char *llc_name, | |||
834 | NFC_PROTO_ISO14443_B_MASK | | 834 | NFC_PROTO_ISO14443_B_MASK | |
835 | NFC_PROTO_NFC_DEP_MASK; | 835 | NFC_PROTO_NFC_DEP_MASK; |
836 | 836 | ||
837 | se = NFC_SE_UICC | NFC_SE_EMBEDDED; | ||
838 | |||
837 | info->hdev = nfc_hci_allocate_device(&pn544_hci_ops, &init_data, 0, | 839 | info->hdev = nfc_hci_allocate_device(&pn544_hci_ops, &init_data, 0, |
838 | protocols, llc_name, | 840 | protocols, se, llc_name, |
839 | phy_headroom + PN544_CMDS_HEADROOM, | 841 | phy_headroom + PN544_CMDS_HEADROOM, |
840 | phy_tailroom, phy_payload); | 842 | phy_tailroom, phy_payload); |
841 | if (!info->hdev) { | 843 | if (!info->hdev) { |
diff --git a/include/net/nfc/hci.h b/include/net/nfc/hci.h index 2ff71750c428..b87a1692b086 100644 --- a/include/net/nfc/hci.h +++ b/include/net/nfc/hci.h | |||
@@ -59,6 +59,8 @@ struct nfc_hci_ops { | |||
59 | struct nfc_target *target); | 59 | struct nfc_target *target); |
60 | int (*event_received)(struct nfc_hci_dev *hdev, u8 gate, u8 event, | 60 | int (*event_received)(struct nfc_hci_dev *hdev, u8 gate, u8 event, |
61 | struct sk_buff *skb); | 61 | struct sk_buff *skb); |
62 | int (*enable_se)(struct nfc_dev *dev, u32 secure_element); | ||
63 | int (*disable_se)(struct nfc_dev *dev, u32 secure_element); | ||
62 | }; | 64 | }; |
63 | 65 | ||
64 | /* Pipes */ | 66 | /* Pipes */ |
@@ -150,6 +152,7 @@ struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops, | |||
150 | struct nfc_hci_init_data *init_data, | 152 | struct nfc_hci_init_data *init_data, |
151 | unsigned long quirks, | 153 | unsigned long quirks, |
152 | u32 protocols, | 154 | u32 protocols, |
155 | u32 supported_se, | ||
153 | const char *llc_name, | 156 | const char *llc_name, |
154 | int tx_headroom, | 157 | int tx_headroom, |
155 | int tx_tailroom, | 158 | int tx_tailroom, |
diff --git a/include/net/nfc/nci_core.h b/include/net/nfc/nci_core.h index d705d8674949..5bc0c460edc0 100644 --- a/include/net/nfc/nci_core.h +++ b/include/net/nfc/nci_core.h | |||
@@ -147,6 +147,7 @@ struct nci_dev { | |||
147 | /* ----- NCI Devices ----- */ | 147 | /* ----- NCI Devices ----- */ |
148 | struct nci_dev *nci_allocate_device(struct nci_ops *ops, | 148 | struct nci_dev *nci_allocate_device(struct nci_ops *ops, |
149 | __u32 supported_protocols, | 149 | __u32 supported_protocols, |
150 | __u32 supported_se, | ||
150 | int tx_headroom, | 151 | int tx_headroom, |
151 | int tx_tailroom); | 152 | int tx_tailroom); |
152 | void nci_free_device(struct nci_dev *ndev); | 153 | void nci_free_device(struct nci_dev *ndev); |
diff --git a/include/net/nfc/nfc.h b/include/net/nfc/nfc.h index 1665674e86b2..87a6417fc934 100644 --- a/include/net/nfc/nfc.h +++ b/include/net/nfc/nfc.h | |||
@@ -68,6 +68,8 @@ struct nfc_ops { | |||
68 | void *cb_context); | 68 | void *cb_context); |
69 | int (*tm_send)(struct nfc_dev *dev, struct sk_buff *skb); | 69 | int (*tm_send)(struct nfc_dev *dev, struct sk_buff *skb); |
70 | int (*check_presence)(struct nfc_dev *dev, struct nfc_target *target); | 70 | int (*check_presence)(struct nfc_dev *dev, struct nfc_target *target); |
71 | int (*enable_se)(struct nfc_dev *dev, u32 secure_element); | ||
72 | int (*disable_se)(struct nfc_dev *dev, u32 secure_element); | ||
71 | }; | 73 | }; |
72 | 74 | ||
73 | #define NFC_TARGET_IDX_ANY -1 | 75 | #define NFC_TARGET_IDX_ANY -1 |
@@ -109,6 +111,9 @@ struct nfc_dev { | |||
109 | struct nfc_genl_data genl_data; | 111 | struct nfc_genl_data genl_data; |
110 | u32 supported_protocols; | 112 | u32 supported_protocols; |
111 | 113 | ||
114 | u32 supported_se; | ||
115 | u32 active_se; | ||
116 | |||
112 | int tx_headroom; | 117 | int tx_headroom; |
113 | int tx_tailroom; | 118 | int tx_tailroom; |
114 | 119 | ||
@@ -125,6 +130,7 @@ extern struct class nfc_class; | |||
125 | 130 | ||
126 | struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops, | 131 | struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops, |
127 | u32 supported_protocols, | 132 | u32 supported_protocols, |
133 | u32 supported_se, | ||
128 | int tx_headroom, | 134 | int tx_headroom, |
129 | int tx_tailroom); | 135 | int tx_tailroom); |
130 | 136 | ||
diff --git a/include/uapi/linux/nfc.h b/include/uapi/linux/nfc.h index 0e63cee8d810..80e4ecd8c04c 100644 --- a/include/uapi/linux/nfc.h +++ b/include/uapi/linux/nfc.h | |||
@@ -67,6 +67,11 @@ | |||
67 | * subsequent CONNECT and CC messages. | 67 | * subsequent CONNECT and CC messages. |
68 | * If one of the passed parameters is wrong none is set and -EINVAL is | 68 | * If one of the passed parameters is wrong none is set and -EINVAL is |
69 | * returned. | 69 | * returned. |
70 | * @NFC_CMD_ENABLE_SE: Enable the physical link to a specific secure element. | ||
71 | * Once enabled a secure element will handle card emulation mode, i.e. | ||
72 | * starting a poll from a device which has a secure element enabled means | ||
73 | * we want to do SE based card emulation. | ||
74 | * @NFC_CMD_DISABLE_SE: Disable the physical link to a specific secure element. | ||
70 | */ | 75 | */ |
71 | enum nfc_commands { | 76 | enum nfc_commands { |
72 | NFC_CMD_UNSPEC, | 77 | NFC_CMD_UNSPEC, |
@@ -86,6 +91,8 @@ enum nfc_commands { | |||
86 | NFC_EVENT_TM_DEACTIVATED, | 91 | NFC_EVENT_TM_DEACTIVATED, |
87 | NFC_CMD_LLC_GET_PARAMS, | 92 | NFC_CMD_LLC_GET_PARAMS, |
88 | NFC_CMD_LLC_SET_PARAMS, | 93 | NFC_CMD_LLC_SET_PARAMS, |
94 | NFC_CMD_ENABLE_SE, | ||
95 | NFC_CMD_DISABLE_SE, | ||
89 | /* private: internal use only */ | 96 | /* private: internal use only */ |
90 | __NFC_CMD_AFTER_LAST | 97 | __NFC_CMD_AFTER_LAST |
91 | }; | 98 | }; |
@@ -114,6 +121,7 @@ enum nfc_commands { | |||
114 | * @NFC_ATTR_LLC_PARAM_LTO: Link TimeOut parameter | 121 | * @NFC_ATTR_LLC_PARAM_LTO: Link TimeOut parameter |
115 | * @NFC_ATTR_LLC_PARAM_RW: Receive Window size parameter | 122 | * @NFC_ATTR_LLC_PARAM_RW: Receive Window size parameter |
116 | * @NFC_ATTR_LLC_PARAM_MIUX: MIU eXtension parameter | 123 | * @NFC_ATTR_LLC_PARAM_MIUX: MIU eXtension parameter |
124 | * @NFC_ATTR_SE: Available Secure Elements | ||
117 | */ | 125 | */ |
118 | enum nfc_attrs { | 126 | enum nfc_attrs { |
119 | NFC_ATTR_UNSPEC, | 127 | NFC_ATTR_UNSPEC, |
@@ -134,6 +142,7 @@ enum nfc_attrs { | |||
134 | NFC_ATTR_LLC_PARAM_LTO, | 142 | NFC_ATTR_LLC_PARAM_LTO, |
135 | NFC_ATTR_LLC_PARAM_RW, | 143 | NFC_ATTR_LLC_PARAM_RW, |
136 | NFC_ATTR_LLC_PARAM_MIUX, | 144 | NFC_ATTR_LLC_PARAM_MIUX, |
145 | NFC_ATTR_SE, | ||
137 | /* private: internal use only */ | 146 | /* private: internal use only */ |
138 | __NFC_ATTR_AFTER_LAST | 147 | __NFC_ATTR_AFTER_LAST |
139 | }; | 148 | }; |
@@ -172,6 +181,11 @@ enum nfc_attrs { | |||
172 | #define NFC_PROTO_NFC_DEP_MASK (1 << NFC_PROTO_NFC_DEP) | 181 | #define NFC_PROTO_NFC_DEP_MASK (1 << NFC_PROTO_NFC_DEP) |
173 | #define NFC_PROTO_ISO14443_B_MASK (1 << NFC_PROTO_ISO14443_B) | 182 | #define NFC_PROTO_ISO14443_B_MASK (1 << NFC_PROTO_ISO14443_B) |
174 | 183 | ||
184 | /* NFC Secure Elements */ | ||
185 | #define NFC_SE_NONE 0x0 | ||
186 | #define NFC_SE_UICC 0x1 | ||
187 | #define NFC_SE_EMBEDDED 0x2 | ||
188 | |||
175 | struct sockaddr_nfc { | 189 | struct sockaddr_nfc { |
176 | sa_family_t sa_family; | 190 | sa_family_t sa_family; |
177 | __u32 dev_idx; | 191 | __u32 dev_idx; |
diff --git a/net/nfc/core.c b/net/nfc/core.c index 7d7b4ee34015..25522e56d350 100644 --- a/net/nfc/core.c +++ b/net/nfc/core.c | |||
@@ -757,6 +757,7 @@ struct nfc_dev *nfc_get_device(unsigned int idx) | |||
757 | */ | 757 | */ |
758 | struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops, | 758 | struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops, |
759 | u32 supported_protocols, | 759 | u32 supported_protocols, |
760 | u32 supported_se, | ||
760 | int tx_headroom, int tx_tailroom) | 761 | int tx_headroom, int tx_tailroom) |
761 | { | 762 | { |
762 | struct nfc_dev *dev; | 763 | struct nfc_dev *dev; |
@@ -774,6 +775,8 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops, | |||
774 | 775 | ||
775 | dev->ops = ops; | 776 | dev->ops = ops; |
776 | dev->supported_protocols = supported_protocols; | 777 | dev->supported_protocols = supported_protocols; |
778 | dev->supported_se = supported_se; | ||
779 | dev->active_se = NFC_SE_NONE; | ||
777 | dev->tx_headroom = tx_headroom; | 780 | dev->tx_headroom = tx_headroom; |
778 | dev->tx_tailroom = tx_tailroom; | 781 | dev->tx_tailroom = tx_tailroom; |
779 | 782 | ||
diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c index 755a6b9774ab..91020b210d87 100644 --- a/net/nfc/hci/core.c +++ b/net/nfc/hci/core.c | |||
@@ -797,6 +797,7 @@ struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops, | |||
797 | struct nfc_hci_init_data *init_data, | 797 | struct nfc_hci_init_data *init_data, |
798 | unsigned long quirks, | 798 | unsigned long quirks, |
799 | u32 protocols, | 799 | u32 protocols, |
800 | u32 supported_se, | ||
800 | const char *llc_name, | 801 | const char *llc_name, |
801 | int tx_headroom, | 802 | int tx_headroom, |
802 | int tx_tailroom, | 803 | int tx_tailroom, |
@@ -822,7 +823,7 @@ struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops, | |||
822 | return NULL; | 823 | return NULL; |
823 | } | 824 | } |
824 | 825 | ||
825 | hdev->ndev = nfc_allocate_device(&hci_nfc_ops, protocols, | 826 | hdev->ndev = nfc_allocate_device(&hci_nfc_ops, protocols, supported_se, |
826 | tx_headroom + HCI_CMDS_HEADROOM, | 827 | tx_headroom + HCI_CMDS_HEADROOM, |
827 | tx_tailroom); | 828 | tx_tailroom); |
828 | if (!hdev->ndev) { | 829 | if (!hdev->ndev) { |
diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c index 5f98dc1bf039..48ada0ec749e 100644 --- a/net/nfc/nci/core.c +++ b/net/nfc/nci/core.c | |||
@@ -658,6 +658,7 @@ static struct nfc_ops nci_nfc_ops = { | |||
658 | */ | 658 | */ |
659 | struct nci_dev *nci_allocate_device(struct nci_ops *ops, | 659 | struct nci_dev *nci_allocate_device(struct nci_ops *ops, |
660 | __u32 supported_protocols, | 660 | __u32 supported_protocols, |
661 | __u32 supported_se, | ||
661 | int tx_headroom, int tx_tailroom) | 662 | int tx_headroom, int tx_tailroom) |
662 | { | 663 | { |
663 | struct nci_dev *ndev; | 664 | struct nci_dev *ndev; |
@@ -680,6 +681,7 @@ struct nci_dev *nci_allocate_device(struct nci_ops *ops, | |||
680 | 681 | ||
681 | ndev->nfc_dev = nfc_allocate_device(&nci_nfc_ops, | 682 | ndev->nfc_dev = nfc_allocate_device(&nci_nfc_ops, |
682 | supported_protocols, | 683 | supported_protocols, |
684 | supported_se, | ||
683 | tx_headroom + NCI_DATA_HDR_SIZE, | 685 | tx_headroom + NCI_DATA_HDR_SIZE, |
684 | tx_tailroom); | 686 | tx_tailroom); |
685 | if (!ndev->nfc_dev) | 687 | if (!ndev->nfc_dev) |
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c index 3568ae16786d..504b883439f1 100644 --- a/net/nfc/netlink.c +++ b/net/nfc/netlink.c | |||
@@ -366,6 +366,7 @@ static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev, | |||
366 | if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) || | 366 | if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) || |
367 | nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) || | 367 | nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) || |
368 | nla_put_u32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols) || | 368 | nla_put_u32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols) || |
369 | nla_put_u32(msg, NFC_ATTR_SE, dev->supported_se) || | ||
369 | nla_put_u8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up) || | 370 | nla_put_u8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up) || |
370 | nla_put_u8(msg, NFC_ATTR_RF_MODE, dev->rf_mode)) | 371 | nla_put_u8(msg, NFC_ATTR_RF_MODE, dev->rf_mode)) |
371 | goto nla_put_failure; | 372 | goto nla_put_failure; |