aboutsummaryrefslogtreecommitdiffstats
path: root/net/nfc
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 /net/nfc
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>
Diffstat (limited to 'net/nfc')
-rw-r--r--net/nfc/core.c14
-rw-r--r--net/nfc/netlink.c63
-rw-r--r--net/nfc/nfc.h3
3 files changed, 80 insertions, 0 deletions
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)