Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+38 -3
+1
drivers/nfc/nfcwilink.c
··· 542 542 543 543 drv->ndev = nci_allocate_device(&nfcwilink_ops, 544 544 protocols, 545 + NFC_SE_NONE, 545 546 NFCWILINK_HDR_LEN, 546 547 0); 547 548 if (!drv->ndev) {
+1
drivers/nfc/pn533.c
··· 2525 2525 2526 2526 2527 2527 dev->nfc_dev = nfc_allocate_device(&pn533_nfc_ops, protocols, 2528 + NFC_SE_NONE, 2528 2529 dev->ops->tx_header_len + 2529 2530 PN533_CMD_DATAEXCH_HEAD_LEN, 2530 2531 dev->ops->tx_tail_len);
+4 -2
drivers/nfc/pn544/pn544.c
··· 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 ··· 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) {
+3
include/net/nfc/hci.h
··· 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 */ ··· 152 150 struct nfc_hci_init_data *init_data, 153 151 unsigned long quirks, 154 152 u32 protocols, 153 + u32 supported_se, 155 154 const char *llc_name, 156 155 int tx_headroom, 157 156 int tx_tailroom,
+1
include/net/nfc/nci_core.h
··· 147 147 /* ----- NCI Devices ----- */ 148 148 struct nci_dev *nci_allocate_device(struct nci_ops *ops, 149 149 __u32 supported_protocols, 150 + __u32 supported_se, 150 151 int tx_headroom, 151 152 int tx_tailroom); 152 153 void nci_free_device(struct nci_dev *ndev);
+6
include/net/nfc/nfc.h
··· 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 ··· 111 109 struct nfc_genl_data genl_data; 112 110 u32 supported_protocols; 113 111 112 + u32 supported_se; 113 + u32 active_se; 114 + 114 115 int tx_headroom; 115 116 int tx_tailroom; 116 117 ··· 130 125 131 126 struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops, 132 127 u32 supported_protocols, 128 + u32 supported_se, 133 129 int tx_headroom, 134 130 int tx_tailroom); 135 131
+14
include/uapi/linux/nfc.h
··· 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, ··· 91 86 NFC_EVENT_TM_DEACTIVATED, 92 87 NFC_CMD_LLC_GET_PARAMS, 93 88 NFC_CMD_LLC_SET_PARAMS, 89 + NFC_CMD_ENABLE_SE, 90 + NFC_CMD_DISABLE_SE, 94 91 /* private: internal use only */ 95 92 __NFC_CMD_AFTER_LAST 96 93 }; ··· 121 114 * @NFC_ATTR_LLC_PARAM_LTO: Link TimeOut parameter 122 115 * @NFC_ATTR_LLC_PARAM_RW: Receive Window size parameter 123 116 * @NFC_ATTR_LLC_PARAM_MIUX: MIU eXtension parameter 117 + * @NFC_ATTR_SE: Available Secure Elements 124 118 */ 125 119 enum nfc_attrs { 126 120 NFC_ATTR_UNSPEC, ··· 142 134 NFC_ATTR_LLC_PARAM_LTO, 143 135 NFC_ATTR_LLC_PARAM_RW, 144 136 NFC_ATTR_LLC_PARAM_MIUX, 137 + NFC_ATTR_SE, 145 138 /* private: internal use only */ 146 139 __NFC_ATTR_AFTER_LAST 147 140 }; ··· 180 171 #define NFC_PROTO_ISO14443_MASK (1 << NFC_PROTO_ISO14443) 181 172 #define NFC_PROTO_NFC_DEP_MASK (1 << NFC_PROTO_NFC_DEP) 182 173 #define NFC_PROTO_ISO14443_B_MASK (1 << NFC_PROTO_ISO14443_B) 174 + 175 + /* NFC Secure Elements */ 176 + #define NFC_SE_NONE 0x0 177 + #define NFC_SE_UICC 0x1 178 + #define NFC_SE_EMBEDDED 0x2 183 179 184 180 struct sockaddr_nfc { 185 181 sa_family_t sa_family;
+3
net/nfc/core.c
··· 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; ··· 775 774 776 775 dev->ops = ops; 777 776 dev->supported_protocols = supported_protocols; 777 + dev->supported_se = supported_se; 778 + dev->active_se = NFC_SE_NONE; 778 779 dev->tx_headroom = tx_headroom; 779 780 dev->tx_tailroom = tx_tailroom; 780 781
+2 -1
net/nfc/hci/core.c
··· 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, ··· 823 822 return NULL; 824 823 } 825 824 826 - hdev->ndev = nfc_allocate_device(&hci_nfc_ops, protocols, 825 + hdev->ndev = nfc_allocate_device(&hci_nfc_ops, protocols, supported_se, 827 826 tx_headroom + HCI_CMDS_HEADROOM, 828 827 tx_tailroom); 829 828 if (!hdev->ndev) {
+2
net/nfc/nci/core.c
··· 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; ··· 681 680 682 681 ndev->nfc_dev = nfc_allocate_device(&nci_nfc_ops, 683 682 supported_protocols, 683 + supported_se, 684 684 tx_headroom + NCI_DATA_HDR_SIZE, 685 685 tx_tailroom); 686 686 if (!ndev->nfc_dev)
+1
net/nfc/netlink.c
··· 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;