Commit 390a1bd8538132186ddb679cafe9e75b7ef7e2d2
1 parent
2ad554a502
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
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>
Showing 11 changed files with 38 additions and 3 deletions Side-by-side Diff
drivers/nfc/nfcwilink.c
drivers/nfc/pn533.c
drivers/nfc/pn544/pn544.c
... | ... | @@ -801,7 +801,7 @@ |
801 | 801 | struct nfc_hci_dev **hdev) |
802 | 802 | { |
803 | 803 | struct pn544_hci_info *info; |
804 | - u32 protocols; | |
804 | + u32 protocols, se; | |
805 | 805 | struct nfc_hci_init_data init_data; |
806 | 806 | int r; |
807 | 807 | |
808 | 808 | |
... | ... | @@ -834,8 +834,10 @@ |
834 | 834 | NFC_PROTO_ISO14443_B_MASK | |
835 | 835 | NFC_PROTO_NFC_DEP_MASK; |
836 | 836 | |
837 | + se = NFC_SE_UICC | NFC_SE_EMBEDDED; | |
838 | + | |
837 | 839 | info->hdev = nfc_hci_allocate_device(&pn544_hci_ops, &init_data, 0, |
838 | - protocols, llc_name, | |
840 | + protocols, se, llc_name, | |
839 | 841 | phy_headroom + PN544_CMDS_HEADROOM, |
840 | 842 | phy_tailroom, phy_payload); |
841 | 843 | if (!info->hdev) { |
include/net/nfc/hci.h
... | ... | @@ -59,6 +59,8 @@ |
59 | 59 | struct nfc_target *target); |
60 | 60 | int (*event_received)(struct nfc_hci_dev *hdev, u8 gate, u8 event, |
61 | 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 | 66 | /* Pipes */ |
... | ... | @@ -150,6 +152,7 @@ |
150 | 152 | struct nfc_hci_init_data *init_data, |
151 | 153 | unsigned long quirks, |
152 | 154 | u32 protocols, |
155 | + u32 supported_se, | |
153 | 156 | const char *llc_name, |
154 | 157 | int tx_headroom, |
155 | 158 | int tx_tailroom, |
include/net/nfc/nci_core.h
include/net/nfc/nfc.h
... | ... | @@ -68,6 +68,8 @@ |
68 | 68 | void *cb_context); |
69 | 69 | int (*tm_send)(struct nfc_dev *dev, struct sk_buff *skb); |
70 | 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 | 75 | #define NFC_TARGET_IDX_ANY -1 |
... | ... | @@ -109,6 +111,9 @@ |
109 | 111 | struct nfc_genl_data genl_data; |
110 | 112 | u32 supported_protocols; |
111 | 113 | |
114 | + u32 supported_se; | |
115 | + u32 active_se; | |
116 | + | |
112 | 117 | int tx_headroom; |
113 | 118 | int tx_tailroom; |
114 | 119 | |
... | ... | @@ -125,6 +130,7 @@ |
125 | 130 | |
126 | 131 | struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops, |
127 | 132 | u32 supported_protocols, |
133 | + u32 supported_se, | |
128 | 134 | int tx_headroom, |
129 | 135 | int tx_tailroom); |
130 | 136 |
include/uapi/linux/nfc.h
... | ... | @@ -67,6 +67,11 @@ |
67 | 67 | * subsequent CONNECT and CC messages. |
68 | 68 | * If one of the passed parameters is wrong none is set and -EINVAL is |
69 | 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 | 76 | enum nfc_commands { |
72 | 77 | NFC_CMD_UNSPEC, |
... | ... | @@ -86,6 +91,8 @@ |
86 | 91 | NFC_EVENT_TM_DEACTIVATED, |
87 | 92 | NFC_CMD_LLC_GET_PARAMS, |
88 | 93 | NFC_CMD_LLC_SET_PARAMS, |
94 | + NFC_CMD_ENABLE_SE, | |
95 | + NFC_CMD_DISABLE_SE, | |
89 | 96 | /* private: internal use only */ |
90 | 97 | __NFC_CMD_AFTER_LAST |
91 | 98 | }; |
... | ... | @@ -114,6 +121,7 @@ |
114 | 121 | * @NFC_ATTR_LLC_PARAM_LTO: Link TimeOut parameter |
115 | 122 | * @NFC_ATTR_LLC_PARAM_RW: Receive Window size parameter |
116 | 123 | * @NFC_ATTR_LLC_PARAM_MIUX: MIU eXtension parameter |
124 | + * @NFC_ATTR_SE: Available Secure Elements | |
117 | 125 | */ |
118 | 126 | enum nfc_attrs { |
119 | 127 | NFC_ATTR_UNSPEC, |
... | ... | @@ -134,6 +142,7 @@ |
134 | 142 | NFC_ATTR_LLC_PARAM_LTO, |
135 | 143 | NFC_ATTR_LLC_PARAM_RW, |
136 | 144 | NFC_ATTR_LLC_PARAM_MIUX, |
145 | + NFC_ATTR_SE, | |
137 | 146 | /* private: internal use only */ |
138 | 147 | __NFC_ATTR_AFTER_LAST |
139 | 148 | }; |
... | ... | @@ -171,6 +180,11 @@ |
171 | 180 | #define NFC_PROTO_ISO14443_MASK (1 << NFC_PROTO_ISO14443) |
172 | 181 | #define NFC_PROTO_NFC_DEP_MASK (1 << NFC_PROTO_NFC_DEP) |
173 | 182 | #define NFC_PROTO_ISO14443_B_MASK (1 << NFC_PROTO_ISO14443_B) |
183 | + | |
184 | +/* NFC Secure Elements */ | |
185 | +#define NFC_SE_NONE 0x0 | |
186 | +#define NFC_SE_UICC 0x1 | |
187 | +#define NFC_SE_EMBEDDED 0x2 | |
174 | 188 | |
175 | 189 | struct sockaddr_nfc { |
176 | 190 | sa_family_t sa_family; |
net/nfc/core.c
... | ... | @@ -757,6 +757,7 @@ |
757 | 757 | */ |
758 | 758 | struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops, |
759 | 759 | u32 supported_protocols, |
760 | + u32 supported_se, | |
760 | 761 | int tx_headroom, int tx_tailroom) |
761 | 762 | { |
762 | 763 | struct nfc_dev *dev; |
... | ... | @@ -774,6 +775,8 @@ |
774 | 775 | |
775 | 776 | dev->ops = ops; |
776 | 777 | dev->supported_protocols = supported_protocols; |
778 | + dev->supported_se = supported_se; | |
779 | + dev->active_se = NFC_SE_NONE; | |
777 | 780 | dev->tx_headroom = tx_headroom; |
778 | 781 | dev->tx_tailroom = tx_tailroom; |
779 | 782 |
net/nfc/hci/core.c
... | ... | @@ -797,6 +797,7 @@ |
797 | 797 | struct nfc_hci_init_data *init_data, |
798 | 798 | unsigned long quirks, |
799 | 799 | u32 protocols, |
800 | + u32 supported_se, | |
800 | 801 | const char *llc_name, |
801 | 802 | int tx_headroom, |
802 | 803 | int tx_tailroom, |
... | ... | @@ -822,7 +823,7 @@ |
822 | 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 | 827 | tx_headroom + HCI_CMDS_HEADROOM, |
827 | 828 | tx_tailroom); |
828 | 829 | if (!hdev->ndev) { |
net/nfc/nci/core.c
... | ... | @@ -658,6 +658,7 @@ |
658 | 658 | */ |
659 | 659 | struct nci_dev *nci_allocate_device(struct nci_ops *ops, |
660 | 660 | __u32 supported_protocols, |
661 | + __u32 supported_se, | |
661 | 662 | int tx_headroom, int tx_tailroom) |
662 | 663 | { |
663 | 664 | struct nci_dev *ndev; |
... | ... | @@ -680,6 +681,7 @@ |
680 | 681 | |
681 | 682 | ndev->nfc_dev = nfc_allocate_device(&nci_nfc_ops, |
682 | 683 | supported_protocols, |
684 | + supported_se, | |
683 | 685 | tx_headroom + NCI_DATA_HDR_SIZE, |
684 | 686 | tx_tailroom); |
685 | 687 | if (!ndev->nfc_dev) |
net/nfc/netlink.c
... | ... | @@ -366,6 +366,7 @@ |
366 | 366 | if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) || |
367 | 367 | nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) || |
368 | 368 | nla_put_u32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols) || |
369 | + nla_put_u32(msg, NFC_ATTR_SE, dev->supported_se) || | |
369 | 370 | nla_put_u8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up) || |
370 | 371 | nla_put_u8(msg, NFC_ATTR_RF_MODE, dev->rf_mode)) |
371 | 372 | goto nla_put_failure; |