Skip to content

Commit 390a1bd

Browse files
author
Samuel Ortiz
committed
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>
1 parent 2ad554a commit 390a1bd

11 files changed

Lines changed: 38 additions & 3 deletions

File tree

‎drivers/nfc/nfcwilink.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ static int nfcwilink_probe(struct platform_device *pdev)
542542

543543
drv->ndev = nci_allocate_device(&nfcwilink_ops,
544544
protocols,
545+
NFC_SE_NONE,
545546
NFCWILINK_HDR_LEN,
546547
0);
547548
if (!drv->ndev) {

‎drivers/nfc/pn533.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,6 +2525,7 @@ static int pn533_probe(struct usb_interface *interface,
25252525

25262526

25272527
dev->nfc_dev = nfc_allocate_device(&pn533_nfc_ops, protocols,
2528+
NFC_SE_NONE,
25282529
dev->ops->tx_header_len +
25292530
PN533_CMD_DATAEXCH_HEAD_LEN,
25302531
dev->ops->tx_tail_len);

‎drivers/nfc/pn544/pn544.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ int pn544_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops, char *llc_name,
801801
struct nfc_hci_dev **hdev)
802802
{
803803
struct pn544_hci_info *info;
804-
u32 protocols;
804+
u32 protocols, se;
805805
struct nfc_hci_init_data init_data;
806806
int r;
807807

@@ -834,8 +834,10 @@ int pn544_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops, char *llc_name,
834834
NFC_PROTO_ISO14443_B_MASK |
835835
NFC_PROTO_NFC_DEP_MASK;
836836

837+
se = NFC_SE_UICC | NFC_SE_EMBEDDED;
838+
837839
info->hdev = nfc_hci_allocate_device(&pn544_hci_ops, &init_data, 0,
838-
protocols, llc_name,
840+
protocols, se, llc_name,
839841
phy_headroom + PN544_CMDS_HEADROOM,
840842
phy_tailroom, phy_payload);
841843
if (!info->hdev) {

‎include/net/nfc/hci.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ struct nfc_hci_ops {
5959
struct nfc_target *target);
6060
int (*event_received)(struct nfc_hci_dev *hdev, u8 gate, u8 event,
6161
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);
6264
};
6365

6466
/* Pipes */
@@ -150,6 +152,7 @@ struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
150152
struct nfc_hci_init_data *init_data,
151153
unsigned long quirks,
152154
u32 protocols,
155+
u32 supported_se,
153156
const char *llc_name,
154157
int tx_headroom,
155158
int tx_tailroom,

‎include/net/nfc/nci_core.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ struct nci_dev {
147147
/* ----- NCI Devices ----- */
148148
struct nci_dev *nci_allocate_device(struct nci_ops *ops,
149149
__u32 supported_protocols,
150+
__u32 supported_se,
150151
int tx_headroom,
151152
int tx_tailroom);
152153
void nci_free_device(struct nci_dev *ndev);

‎include/net/nfc/nfc.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ struct nfc_ops {
6868
void *cb_context);
6969
int (*tm_send)(struct nfc_dev *dev, struct sk_buff *skb);
7070
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);
7173
};
7274

7375
#define NFC_TARGET_IDX_ANY -1
@@ -109,6 +111,9 @@ struct nfc_dev {
109111
struct nfc_genl_data genl_data;
110112
u32 supported_protocols;
111113

114+
u32 supported_se;
115+
u32 active_se;
116+
112117
int tx_headroom;
113118
int tx_tailroom;
114119

@@ -125,6 +130,7 @@ extern struct class nfc_class;
125130

126131
struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
127132
u32 supported_protocols,
133+
u32 supported_se,
128134
int tx_headroom,
129135
int tx_tailroom);
130136

‎include/uapi/linux/nfc.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
* subsequent CONNECT and CC messages.
6868
* If one of the passed parameters is wrong none is set and -EINVAL is
6969
* 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.
7075
*/
7176
enum nfc_commands {
7277
NFC_CMD_UNSPEC,
@@ -86,6 +91,8 @@ enum nfc_commands {
8691
NFC_EVENT_TM_DEACTIVATED,
8792
NFC_CMD_LLC_GET_PARAMS,
8893
NFC_CMD_LLC_SET_PARAMS,
94+
NFC_CMD_ENABLE_SE,
95+
NFC_CMD_DISABLE_SE,
8996
/* private: internal use only */
9097
__NFC_CMD_AFTER_LAST
9198
};
@@ -114,6 +121,7 @@ enum nfc_commands {
114121
* @NFC_ATTR_LLC_PARAM_LTO: Link TimeOut parameter
115122
* @NFC_ATTR_LLC_PARAM_RW: Receive Window size parameter
116123
* @NFC_ATTR_LLC_PARAM_MIUX: MIU eXtension parameter
124+
* @NFC_ATTR_SE: Available Secure Elements
117125
*/
118126
enum nfc_attrs {
119127
NFC_ATTR_UNSPEC,
@@ -134,6 +142,7 @@ enum nfc_attrs {
134142
NFC_ATTR_LLC_PARAM_LTO,
135143
NFC_ATTR_LLC_PARAM_RW,
136144
NFC_ATTR_LLC_PARAM_MIUX,
145+
NFC_ATTR_SE,
137146
/* private: internal use only */
138147
__NFC_ATTR_AFTER_LAST
139148
};
@@ -172,6 +181,11 @@ enum nfc_attrs {
172181
#define NFC_PROTO_NFC_DEP_MASK (1 << NFC_PROTO_NFC_DEP)
173182
#define NFC_PROTO_ISO14443_B_MASK (1 << NFC_PROTO_ISO14443_B)
174183

184+
/* NFC Secure Elements */
185+
#define NFC_SE_NONE 0x0
186+
#define NFC_SE_UICC 0x1
187+
#define NFC_SE_EMBEDDED 0x2
188+
175189
struct sockaddr_nfc {
176190
sa_family_t sa_family;
177191
__u32 dev_idx;

‎net/nfc/core.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ struct nfc_dev *nfc_get_device(unsigned int idx)
757757
*/
758758
struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
759759
u32 supported_protocols,
760+
u32 supported_se,
760761
int tx_headroom, int tx_tailroom)
761762
{
762763
struct nfc_dev *dev;
@@ -774,6 +775,8 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
774775

775776
dev->ops = ops;
776777
dev->supported_protocols = supported_protocols;
778+
dev->supported_se = supported_se;
779+
dev->active_se = NFC_SE_NONE;
777780
dev->tx_headroom = tx_headroom;
778781
dev->tx_tailroom = tx_tailroom;
779782

‎net/nfc/hci/core.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
797797
struct nfc_hci_init_data *init_data,
798798
unsigned long quirks,
799799
u32 protocols,
800+
u32 supported_se,
800801
const char *llc_name,
801802
int tx_headroom,
802803
int tx_tailroom,
@@ -822,7 +823,7 @@ struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
822823
return NULL;
823824
}
824825

825-
hdev->ndev = nfc_allocate_device(&hci_nfc_ops, protocols,
826+
hdev->ndev = nfc_allocate_device(&hci_nfc_ops, protocols, supported_se,
826827
tx_headroom + HCI_CMDS_HEADROOM,
827828
tx_tailroom);
828829
if (!hdev->ndev) {

‎net/nfc/nci/core.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ static struct nfc_ops nci_nfc_ops = {
658658
*/
659659
struct nci_dev *nci_allocate_device(struct nci_ops *ops,
660660
__u32 supported_protocols,
661+
__u32 supported_se,
661662
int tx_headroom, int tx_tailroom)
662663
{
663664
struct nci_dev *ndev;
@@ -680,6 +681,7 @@ struct nci_dev *nci_allocate_device(struct nci_ops *ops,
680681

681682
ndev->nfc_dev = nfc_allocate_device(&nci_nfc_ops,
682683
supported_protocols,
684+
supported_se,
683685
tx_headroom + NCI_DATA_HDR_SIZE,
684686
tx_tailroom);
685687
if (!ndev->nfc_dev)

0 commit comments

Comments
 (0)