mirror of
https://github.com/FEX-Emu/linux.git
synced 2024-12-16 05:50:19 +00:00
NFC: Send netlink events for secure elements additions and removals
When an NFC driver or host controller stack discovers a secure element, it will call nfc_add_se(). In order for userspace applications to use these secure elements, a netlink event will then be sent with the SE index and its type. With that information userspace applications can decide wether or not to enable SEs, through their indexes. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
fed7c25ec0
commit
2757c3723c
@ -95,6 +95,8 @@ enum nfc_commands {
|
||||
NFC_CMD_LLC_SDREQ,
|
||||
NFC_EVENT_LLC_SDRES,
|
||||
NFC_CMD_FW_UPLOAD,
|
||||
NFC_EVENT_SE_ADDED,
|
||||
NFC_EVENT_SE_REMOVED,
|
||||
/* private: internal use only */
|
||||
__NFC_CMD_AFTER_LAST
|
||||
};
|
||||
@ -125,6 +127,8 @@ enum nfc_commands {
|
||||
* @NFC_ATTR_LLC_PARAM_MIUX: MIU eXtension parameter
|
||||
* @NFC_ATTR_SE: Available Secure Elements
|
||||
* @NFC_ATTR_FIRMWARE_NAME: Free format firmware version
|
||||
* @NFC_ATTR_SE_INDEX: Secure element index
|
||||
* @NFC_ATTR_SE_TYPE: Secure element type (UICC or EMBEDDED)
|
||||
*/
|
||||
enum nfc_attrs {
|
||||
NFC_ATTR_UNSPEC,
|
||||
@ -148,6 +152,8 @@ enum nfc_attrs {
|
||||
NFC_ATTR_SE,
|
||||
NFC_ATTR_LLC_SDP,
|
||||
NFC_ATTR_FIRMWARE_NAME,
|
||||
NFC_ATTR_SE_INDEX,
|
||||
NFC_ATTR_SE_TYPE,
|
||||
/* private: internal use only */
|
||||
__NFC_ATTR_AFTER_LAST
|
||||
};
|
||||
|
@ -763,6 +763,7 @@ EXPORT_SYMBOL(nfc_driver_failure);
|
||||
int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type)
|
||||
{
|
||||
struct nfc_se *se, *n;
|
||||
int rc;
|
||||
|
||||
pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
|
||||
|
||||
@ -781,6 +782,14 @@ int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type)
|
||||
|
||||
list_add(&se->list, &dev->secure_elements);
|
||||
|
||||
rc = nfc_genl_se_added(dev, se_idx, type);
|
||||
if (rc < 0) {
|
||||
list_del(&se->list);
|
||||
kfree(se);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(nfc_add_se);
|
||||
@ -788,11 +797,16 @@ EXPORT_SYMBOL(nfc_add_se);
|
||||
int nfc_remove_se(struct nfc_dev *dev, u32 se_idx)
|
||||
{
|
||||
struct nfc_se *se, *n;
|
||||
int rc;
|
||||
|
||||
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) {
|
||||
rc = nfc_genl_se_removed(dev, se_idx);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
list_del(&se->list);
|
||||
kfree(se);
|
||||
|
||||
|
@ -426,6 +426,69 @@ free_msg:
|
||||
return rc;
|
||||
}
|
||||
|
||||
int nfc_genl_se_added(struct nfc_dev *dev, u32 se_idx, u16 type)
|
||||
{
|
||||
struct sk_buff *msg;
|
||||
void *hdr;
|
||||
|
||||
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
|
||||
if (!msg)
|
||||
return -ENOMEM;
|
||||
|
||||
hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
|
||||
NFC_EVENT_SE_ADDED);
|
||||
if (!hdr)
|
||||
goto free_msg;
|
||||
|
||||
if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
|
||||
nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx) ||
|
||||
nla_put_u8(msg, NFC_ATTR_SE_TYPE, type))
|
||||
goto nla_put_failure;
|
||||
|
||||
genlmsg_end(msg, hdr);
|
||||
|
||||
genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
|
||||
|
||||
return 0;
|
||||
|
||||
nla_put_failure:
|
||||
genlmsg_cancel(msg, hdr);
|
||||
free_msg:
|
||||
nlmsg_free(msg);
|
||||
return -EMSGSIZE;
|
||||
}
|
||||
|
||||
int nfc_genl_se_removed(struct nfc_dev *dev, u32 se_idx)
|
||||
{
|
||||
struct sk_buff *msg;
|
||||
void *hdr;
|
||||
|
||||
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
|
||||
if (!msg)
|
||||
return -ENOMEM;
|
||||
|
||||
hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
|
||||
NFC_EVENT_SE_REMOVED);
|
||||
if (!hdr)
|
||||
goto free_msg;
|
||||
|
||||
if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
|
||||
nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx))
|
||||
goto nla_put_failure;
|
||||
|
||||
genlmsg_end(msg, hdr);
|
||||
|
||||
genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
|
||||
|
||||
return 0;
|
||||
|
||||
nla_put_failure:
|
||||
genlmsg_cancel(msg, hdr);
|
||||
free_msg:
|
||||
nlmsg_free(msg);
|
||||
return -EMSGSIZE;
|
||||
}
|
||||
|
||||
static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev,
|
||||
u32 portid, u32 seq,
|
||||
struct netlink_callback *cb,
|
||||
|
@ -94,6 +94,9 @@ int nfc_genl_tm_deactivated(struct nfc_dev *dev);
|
||||
|
||||
int nfc_genl_llc_send_sdres(struct nfc_dev *dev, struct hlist_head *sdres_list);
|
||||
|
||||
int nfc_genl_se_added(struct nfc_dev *dev, u32 se_idx, u16 type);
|
||||
int nfc_genl_se_removed(struct nfc_dev *dev, u32 se_idx);
|
||||
|
||||
struct nfc_dev *nfc_get_device(unsigned int idx);
|
||||
|
||||
static inline void nfc_put_device(struct nfc_dev *dev)
|
||||
|
Loading…
Reference in New Issue
Block a user