Commit fed7c25e authored by Samuel Ortiz's avatar Samuel Ortiz

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: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent 0a946301
...@@ -97,6 +97,23 @@ struct nfc_target { ...@@ -97,6 +97,23 @@ struct nfc_target {
u8 logical_idx; u8 logical_idx;
}; };
/**
* nfc_se - A structure for NFC accessible secure elements.
*
* @idx: The secure element index. User space will enable or
* disable a secure element by its index.
* @type: The secure element type. It can be SE_UICC or
* SE_EMBEDDED.
* @state: The secure element state, either enabled or disabled.
*
*/
struct nfc_se {
struct list_head list;
u32 idx;
u16 type;
u16 state;
};
struct nfc_genl_data { struct nfc_genl_data {
u32 poll_req_portid; u32 poll_req_portid;
struct mutex genl_data_mutex; struct mutex genl_data_mutex;
...@@ -118,7 +135,7 @@ struct nfc_dev { ...@@ -118,7 +135,7 @@ struct nfc_dev {
struct nfc_genl_data genl_data; struct nfc_genl_data genl_data;
u32 supported_protocols; u32 supported_protocols;
u32 active_se; struct list_head secure_elements;
int tx_headroom; int tx_headroom;
int tx_tailroom; int tx_tailroom;
...@@ -221,4 +238,7 @@ int nfc_tm_data_received(struct nfc_dev *dev, struct sk_buff *skb); ...@@ -221,4 +238,7 @@ int nfc_tm_data_received(struct nfc_dev *dev, struct sk_buff *skb);
void nfc_driver_failure(struct nfc_dev *dev, int err); void nfc_driver_failure(struct nfc_dev *dev, int err);
int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type);
int nfc_remove_se(struct nfc_dev *dev, u32 se_idx);
#endif /* __NET_NFC_H */ #endif /* __NET_NFC_H */
...@@ -199,10 +199,12 @@ enum nfc_sdp_attr { ...@@ -199,10 +199,12 @@ enum nfc_sdp_attr {
#define NFC_PROTO_ISO14443_B_MASK (1 << NFC_PROTO_ISO14443_B) #define NFC_PROTO_ISO14443_B_MASK (1 << NFC_PROTO_ISO14443_B)
/* NFC Secure Elements */ /* NFC Secure Elements */
#define NFC_SE_NONE 0x0
#define NFC_SE_UICC 0x1 #define NFC_SE_UICC 0x1
#define NFC_SE_EMBEDDED 0x2 #define NFC_SE_EMBEDDED 0x2
#define NFC_SE_DISABLED 0x0
#define NFC_SE_ENABLED 0x1
struct sockaddr_nfc { struct sockaddr_nfc {
sa_family_t sa_family; sa_family_t sa_family;
__u32 dev_idx; __u32 dev_idx;
......
...@@ -760,6 +760,49 @@ inline void nfc_driver_failure(struct nfc_dev *dev, int err) ...@@ -760,6 +760,49 @@ inline void nfc_driver_failure(struct nfc_dev *dev, int err)
} }
EXPORT_SYMBOL(nfc_driver_failure); EXPORT_SYMBOL(nfc_driver_failure);
int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type)
{
struct nfc_se *se, *n;
pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
list_for_each_entry_safe(se, n, &dev->secure_elements, list)
if (se->idx == se_idx)
return -EALREADY;
se = kzalloc(sizeof(struct nfc_se), GFP_KERNEL);
if (!se)
return -ENOMEM;
se->idx = se_idx;
se->type = type;
se->state = NFC_SE_DISABLED;
INIT_LIST_HEAD(&se->list);
list_add(&se->list, &dev->secure_elements);
return 0;
}
EXPORT_SYMBOL(nfc_add_se);
int nfc_remove_se(struct nfc_dev *dev, u32 se_idx)
{
struct nfc_se *se, *n;
pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
list_for_each_entry_safe(se, n, &dev->secure_elements, list)
if (se->idx == se_idx) {
list_del(&se->list);
kfree(se);
return 0;
}
return -EINVAL;
}
EXPORT_SYMBOL(nfc_remove_se);
static void nfc_release(struct device *d) static void nfc_release(struct device *d)
{ {
struct nfc_dev *dev = to_nfc_dev(d); struct nfc_dev *dev = to_nfc_dev(d);
...@@ -856,9 +899,9 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops, ...@@ -856,9 +899,9 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
dev->ops = ops; dev->ops = ops;
dev->supported_protocols = supported_protocols; dev->supported_protocols = supported_protocols;
dev->active_se = NFC_SE_NONE;
dev->tx_headroom = tx_headroom; dev->tx_headroom = tx_headroom;
dev->tx_tailroom = tx_tailroom; dev->tx_tailroom = tx_tailroom;
INIT_LIST_HEAD(&dev->secure_elements);
nfc_genl_data_init(&dev->genl_data); nfc_genl_data_init(&dev->genl_data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment