NFC: Export target lost function
authorEric Lapuyade <eric.lapuyade@linux.intel.com>
Tue, 10 Apr 2012 17:43:05 +0000 (19:43 +0200)
committerJohn W. Linville <linville@tuxdriver.com>
Thu, 12 Apr 2012 19:10:34 +0000 (15:10 -0400)
NFC drivers will call this routine when they detect that a tag leaves the
RF field. This will eventually lead to the corresponding netlink event
to be sent.

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

index bac070bf3514188c589b1769484abacfa8470ca1..57ea09533ae1437ca377bdf9044b1efd065e44ba 100644 (file)
@@ -181,6 +181,7 @@ int nfc_set_remote_general_bytes(struct nfc_dev *dev,
 
 int nfc_targets_found(struct nfc_dev *dev,
                      struct nfc_target *targets, int ntargets);
+int nfc_target_lost(struct nfc_dev *dev, u32 target_idx);
 
 int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx,
                       u8 comm_mode, u8 rf_mode);
index 295d129864d246cb6c1a3b993dfbc54ebc826bad..deb4721ce8a129699bae9a68e8d5fcb3af35c8db 100644 (file)
@@ -455,6 +455,45 @@ int nfc_targets_found(struct nfc_dev *dev,
 }
 EXPORT_SYMBOL(nfc_targets_found);
 
+int nfc_target_lost(struct nfc_dev *dev, u32 target_idx)
+{
+       struct nfc_target *tg;
+       int i;
+
+       pr_debug("dev_name %s n_target %d\n", dev_name(&dev->dev), target_idx);
+
+       spin_lock_bh(&dev->targets_lock);
+
+       for (i = 0; i < dev->n_targets; i++) {
+               tg = &dev->targets[i];
+               if (tg->idx == target_idx)
+                       break;
+       }
+
+       if (i == dev->n_targets) {
+               spin_unlock_bh(&dev->targets_lock);
+               return -EINVAL;
+       }
+
+       dev->targets_generation++;
+       dev->n_targets--;
+
+       if (dev->n_targets) {
+               memcpy(&dev->targets[i], &dev->targets[i + 1],
+                      (dev->n_targets - i) * sizeof(struct nfc_target));
+       } else {
+               kfree(dev->targets);
+               dev->targets = NULL;
+       }
+
+       spin_unlock_bh(&dev->targets_lock);
+
+       nfc_genl_target_lost(dev, target_idx);
+
+       return 0;
+}
+EXPORT_SYMBOL(nfc_target_lost);
+
 static void nfc_release(struct device *d)
 {
        struct nfc_dev *dev = to_nfc_dev(d);