NFC: Add a target lost netlink event
authorSamuel Ortiz <sameo@linux.intel.com>
Tue, 10 Apr 2012 17:43:04 +0000 (19:43 +0200)
committerJohn W. Linville <linville@tuxdriver.com>
Thu, 12 Apr 2012 19:10:33 +0000 (15:10 -0400)
Some chips are capable of detecting when a tag is out of the field, so
they could send a netlink event about it to userspace.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
include/linux/nfc.h
net/nfc/netlink.c
net/nfc/nfc.h

index 39c1fcf089c0a99ec654d4c5fb190eda696dd665..0ae9b5857c83b0786a9f7ea92ffe51991c34a1b8 100644 (file)
@@ -70,6 +70,7 @@ enum nfc_commands {
        NFC_EVENT_TARGETS_FOUND,
        NFC_EVENT_DEVICE_ADDED,
        NFC_EVENT_DEVICE_REMOVED,
+       NFC_EVENT_TARGET_LOST,
 /* private: internal use only */
        __NFC_CMD_AFTER_LAST
 };
index 6404052d6c070ccf8f54c4827408d5f9291d6b67..ebdb605f8dbd16f40e8028309340d46d18e75bee 100644 (file)
@@ -183,6 +183,36 @@ free_msg:
        return -EMSGSIZE;
 }
 
+int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx)
+{
+       struct sk_buff *msg;
+       void *hdr;
+
+       msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+       if (!msg)
+               return -ENOMEM;
+
+       hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
+                         NFC_EVENT_TARGET_LOST);
+       if (!hdr)
+               goto free_msg;
+
+       NLA_PUT_STRING(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev));
+       NLA_PUT_U32(msg, NFC_ATTR_TARGET_INDEX, target_idx);
+
+       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_device_added(struct nfc_dev *dev)
 {
        struct sk_buff *msg;
index ec8794c1099c9c2961446f101d9f0846caa96aca..2c868d2b3c57bed9672ca2dff1880befc79001ef 100644 (file)
@@ -119,6 +119,7 @@ void nfc_genl_data_init(struct nfc_genl_data *genl_data);
 void nfc_genl_data_exit(struct nfc_genl_data *genl_data);
 
 int nfc_genl_targets_found(struct nfc_dev *dev);
+int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx);
 
 int nfc_genl_device_added(struct nfc_dev *dev);
 int nfc_genl_device_removed(struct nfc_dev *dev);