Skip to content

Commit fed7c25

Browse files
author
Samuel Ortiz
committed
NFC: Add secure elements addition and removal API
This API will allow NFC drivers to add and remove the secure elements they know about or detect. Typically this should be called (asynchronously or not) from the driver or the host interface stack detect_se hook. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent 0a94630 commit fed7c25

3 files changed

Lines changed: 68 additions & 3 deletions

File tree

‎include/net/nfc/nfc.h‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ struct nfc_target {
9797
u8 logical_idx;
9898
};
9999

100+
/**
101+
* nfc_se - A structure for NFC accessible secure elements.
102+
*
103+
* @idx: The secure element index. User space will enable or
104+
* disable a secure element by its index.
105+
* @type: The secure element type. It can be SE_UICC or
106+
* SE_EMBEDDED.
107+
* @state: The secure element state, either enabled or disabled.
108+
*
109+
*/
110+
struct nfc_se {
111+
struct list_head list;
112+
u32 idx;
113+
u16 type;
114+
u16 state;
115+
};
116+
100117
struct nfc_genl_data {
101118
u32 poll_req_portid;
102119
struct mutex genl_data_mutex;
@@ -118,7 +135,7 @@ struct nfc_dev {
118135
struct nfc_genl_data genl_data;
119136
u32 supported_protocols;
120137

121-
u32 active_se;
138+
struct list_head secure_elements;
122139

123140
int tx_headroom;
124141
int tx_tailroom;
@@ -221,4 +238,7 @@ int nfc_tm_data_received(struct nfc_dev *dev, struct sk_buff *skb);
221238

222239
void nfc_driver_failure(struct nfc_dev *dev, int err);
223240

241+
int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type);
242+
int nfc_remove_se(struct nfc_dev *dev, u32 se_idx);
243+
224244
#endif /* __NET_NFC_H */

‎include/uapi/linux/nfc.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,12 @@ enum nfc_sdp_attr {
199199
#define NFC_PROTO_ISO14443_B_MASK (1 << NFC_PROTO_ISO14443_B)
200200

201201
/* NFC Secure Elements */
202-
#define NFC_SE_NONE 0x0
203202
#define NFC_SE_UICC 0x1
204203
#define NFC_SE_EMBEDDED 0x2
205204

205+
#define NFC_SE_DISABLED 0x0
206+
#define NFC_SE_ENABLED 0x1
207+
206208
struct sockaddr_nfc {
207209
sa_family_t sa_family;
208210
__u32 dev_idx;

‎net/nfc/core.c‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,49 @@ inline void nfc_driver_failure(struct nfc_dev *dev, int err)
760760
}
761761
EXPORT_SYMBOL(nfc_driver_failure);
762762

763+
int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type)
764+
{
765+
struct nfc_se *se, *n;
766+
767+
pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
768+
769+
list_for_each_entry_safe(se, n, &dev->secure_elements, list)
770+
if (se->idx == se_idx)
771+
return -EALREADY;
772+
773+
se = kzalloc(sizeof(struct nfc_se), GFP_KERNEL);
774+
if (!se)
775+
return -ENOMEM;
776+
777+
se->idx = se_idx;
778+
se->type = type;
779+
se->state = NFC_SE_DISABLED;
780+
INIT_LIST_HEAD(&se->list);
781+
782+
list_add(&se->list, &dev->secure_elements);
783+
784+
return 0;
785+
}
786+
EXPORT_SYMBOL(nfc_add_se);
787+
788+
int nfc_remove_se(struct nfc_dev *dev, u32 se_idx)
789+
{
790+
struct nfc_se *se, *n;
791+
792+
pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
793+
794+
list_for_each_entry_safe(se, n, &dev->secure_elements, list)
795+
if (se->idx == se_idx) {
796+
list_del(&se->list);
797+
kfree(se);
798+
799+
return 0;
800+
}
801+
802+
return -EINVAL;
803+
}
804+
EXPORT_SYMBOL(nfc_remove_se);
805+
763806
static void nfc_release(struct device *d)
764807
{
765808
struct nfc_dev *dev = to_nfc_dev(d);
@@ -856,9 +899,9 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
856899

857900
dev->ops = ops;
858901
dev->supported_protocols = supported_protocols;
859-
dev->active_se = NFC_SE_NONE;
860902
dev->tx_headroom = tx_headroom;
861903
dev->tx_tailroom = tx_tailroom;
904+
INIT_LIST_HEAD(&dev->secure_elements);
862905

863906
nfc_genl_data_init(&dev->genl_data);
864907

0 commit comments

Comments
 (0)