aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2013-05-10 09:47:37 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2013-06-14 07:44:59 -0400
commit2757c3723c3d2b13e3a8bfaa034826f64e9cca43 (patch)
tree05a2c978fc9edbc973f1f6b55afbddf6ccb79f55
parentfed7c25ec0d4894edfc36bbe5c5231e52f45483a (diff)
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>
-rw-r--r--include/uapi/linux/nfc.h6
-rw-r--r--net/nfc/core.c14
-rw-r--r--net/nfc/netlink.c63
-rw-r--r--net/nfc/nfc.h3
4 files changed, 86 insertions, 0 deletions
diff --git a/include/uapi/linux/nfc.h b/include/uapi/linux/nfc.h
index 3a57cef0b986..caed0f324d5f 100644
--- a/include/uapi/linux/nfc.h
+++ b/include/uapi/linux/nfc.h
@@ -95,6 +95,8 @@ enum nfc_commands {
95 NFC_CMD_LLC_SDREQ, 95 NFC_CMD_LLC_SDREQ,
96 NFC_EVENT_LLC_SDRES, 96 NFC_EVENT_LLC_SDRES,
97 NFC_CMD_FW_UPLOAD, 97 NFC_CMD_FW_UPLOAD,
98 NFC_EVENT_SE_ADDED,
99 NFC_EVENT_SE_REMOVED,
98/* private: internal use only */ 100/* private: internal use only */
99 __NFC_CMD_AFTER_LAST 101 __NFC_CMD_AFTER_LAST
100}; 102};
@@ -125,6 +127,8 @@ enum nfc_commands {
125 * @NFC_ATTR_LLC_PARAM_MIUX: MIU eXtension parameter 127 * @NFC_ATTR_LLC_PARAM_MIUX: MIU eXtension parameter
126 * @NFC_ATTR_SE: Available Secure Elements 128 * @NFC_ATTR_SE: Available Secure Elements
127 * @NFC_ATTR_FIRMWARE_NAME: Free format firmware version 129 * @NFC_ATTR_FIRMWARE_NAME: Free format firmware version
130 * @NFC_ATTR_SE_INDEX: Secure element index
131 * @NFC_ATTR_SE_TYPE: Secure element type (UICC or EMBEDDED)
128 */ 132 */
129enum nfc_attrs { 133enum nfc_attrs {
130 NFC_ATTR_UNSPEC, 134 NFC_ATTR_UNSPEC,
@@ -148,6 +152,8 @@ enum nfc_attrs {
148 NFC_ATTR_SE, 152 NFC_ATTR_SE,
149 NFC_ATTR_LLC_SDP, 153 NFC_ATTR_LLC_SDP,
150 NFC_ATTR_FIRMWARE_NAME, 154 NFC_ATTR_FIRMWARE_NAME,
155 NFC_ATTR_SE_INDEX,
156 NFC_ATTR_SE_TYPE,
151/* private: internal use only */ 157/* private: internal use only */
152 __NFC_ATTR_AFTER_LAST 158 __NFC_ATTR_AFTER_LAST
153}; 159};
diff --git a/net/nfc/core.c b/net/nfc/core.c
index dacadfbcacea..bb5f16cfc201 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -763,6 +763,7 @@ EXPORT_SYMBOL(nfc_driver_failure);
763int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type) 763int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type)
764{ 764{
765 struct nfc_se *se, *n; 765 struct nfc_se *se, *n;
766 int rc;
766 767
767 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx); 768 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
768 769
@@ -781,6 +782,14 @@ int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type)
781 782
782 list_add(&se->list, &dev->secure_elements); 783 list_add(&se->list, &dev->secure_elements);
783 784
785 rc = nfc_genl_se_added(dev, se_idx, type);
786 if (rc < 0) {
787 list_del(&se->list);
788 kfree(se);
789
790 return rc;
791 }
792
784 return 0; 793 return 0;
785} 794}
786EXPORT_SYMBOL(nfc_add_se); 795EXPORT_SYMBOL(nfc_add_se);
@@ -788,11 +797,16 @@ EXPORT_SYMBOL(nfc_add_se);
788int nfc_remove_se(struct nfc_dev *dev, u32 se_idx) 797int nfc_remove_se(struct nfc_dev *dev, u32 se_idx)
789{ 798{
790 struct nfc_se *se, *n; 799 struct nfc_se *se, *n;
800 int rc;
791 801
792 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx); 802 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
793 803
794 list_for_each_entry_safe(se, n, &dev->secure_elements, list) 804 list_for_each_entry_safe(se, n, &dev->secure_elements, list)
795 if (se->idx == se_idx) { 805 if (se->idx == se_idx) {
806 rc = nfc_genl_se_removed(dev, se_idx);
807 if (rc < 0)
808 return rc;
809
796 list_del(&se->list); 810 list_del(&se->list);
797 kfree(se); 811 kfree(se);
798 812
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index fdbc662c564a..8a11a3a27e69 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -426,6 +426,69 @@ free_msg:
426 return rc; 426 return rc;
427} 427}
428 428
429int nfc_genl_se_added(struct nfc_dev *dev, u32 se_idx, u16 type)
430{
431 struct sk_buff *msg;
432 void *hdr;
433
434 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
435 if (!msg)
436 return -ENOMEM;
437
438 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
439 NFC_EVENT_SE_ADDED);
440 if (!hdr)
441 goto free_msg;
442
443 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
444 nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx) ||
445 nla_put_u8(msg, NFC_ATTR_SE_TYPE, type))
446 goto nla_put_failure;
447
448 genlmsg_end(msg, hdr);
449
450 genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
451
452 return 0;
453
454nla_put_failure:
455 genlmsg_cancel(msg, hdr);
456free_msg:
457 nlmsg_free(msg);
458 return -EMSGSIZE;
459}
460
461int nfc_genl_se_removed(struct nfc_dev *dev, u32 se_idx)
462{
463 struct sk_buff *msg;
464 void *hdr;
465
466 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
467 if (!msg)
468 return -ENOMEM;
469
470 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
471 NFC_EVENT_SE_REMOVED);
472 if (!hdr)
473 goto free_msg;
474
475 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
476 nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx))
477 goto nla_put_failure;
478
479 genlmsg_end(msg, hdr);
480
481 genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
482
483 return 0;
484
485nla_put_failure:
486 genlmsg_cancel(msg, hdr);
487free_msg:
488 nlmsg_free(msg);
489 return -EMSGSIZE;
490}
491
429static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev, 492static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev,
430 u32 portid, u32 seq, 493 u32 portid, u32 seq,
431 struct netlink_callback *cb, 494 struct netlink_callback *cb,
diff --git a/net/nfc/nfc.h b/net/nfc/nfc.h
index cf0c48165996..a6aeee094aa4 100644
--- a/net/nfc/nfc.h
+++ b/net/nfc/nfc.h
@@ -94,6 +94,9 @@ int nfc_genl_tm_deactivated(struct nfc_dev *dev);
94 94
95int nfc_genl_llc_send_sdres(struct nfc_dev *dev, struct hlist_head *sdres_list); 95int nfc_genl_llc_send_sdres(struct nfc_dev *dev, struct hlist_head *sdres_list);
96 96
97int nfc_genl_se_added(struct nfc_dev *dev, u32 se_idx, u16 type);
98int nfc_genl_se_removed(struct nfc_dev *dev, u32 se_idx);
99
97struct nfc_dev *nfc_get_device(unsigned int idx); 100struct nfc_dev *nfc_get_device(unsigned int idx);
98 101
99static inline void nfc_put_device(struct nfc_dev *dev) 102static inline void nfc_put_device(struct nfc_dev *dev)