diff options
| author | Eric Lapuyade <eric.lapuyade@linux.intel.com> | 2012-04-10 13:43:05 -0400 |
|---|---|---|
| committer | John W. Linville <linville@tuxdriver.com> | 2012-04-12 15:10:34 -0400 |
| commit | e1da0efa2ee71df957b280bcfa41f82ce6986a1d (patch) | |
| tree | 6b158595ad501b56545a1461104ae8cbbf1b9c76 | |
| parent | 8112a5c91d781a22d2b631f3295386b0b70de7c8 (diff) | |
NFC: Export target lost function
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>
| -rw-r--r-- | include/net/nfc/nfc.h | 1 | ||||
| -rw-r--r-- | net/nfc/core.c | 39 |
2 files changed, 40 insertions, 0 deletions
diff --git a/include/net/nfc/nfc.h b/include/net/nfc/nfc.h index bac070bf3514..57ea09533ae1 100644 --- a/include/net/nfc/nfc.h +++ b/include/net/nfc/nfc.h | |||
| @@ -181,6 +181,7 @@ int nfc_set_remote_general_bytes(struct nfc_dev *dev, | |||
| 181 | 181 | ||
| 182 | int nfc_targets_found(struct nfc_dev *dev, | 182 | int nfc_targets_found(struct nfc_dev *dev, |
| 183 | struct nfc_target *targets, int ntargets); | 183 | struct nfc_target *targets, int ntargets); |
| 184 | int nfc_target_lost(struct nfc_dev *dev, u32 target_idx); | ||
| 184 | 185 | ||
| 185 | int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx, | 186 | int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx, |
| 186 | u8 comm_mode, u8 rf_mode); | 187 | u8 comm_mode, u8 rf_mode); |
diff --git a/net/nfc/core.c b/net/nfc/core.c index 295d129864d2..deb4721ce8a1 100644 --- a/net/nfc/core.c +++ b/net/nfc/core.c | |||
| @@ -455,6 +455,45 @@ int nfc_targets_found(struct nfc_dev *dev, | |||
| 455 | } | 455 | } |
| 456 | EXPORT_SYMBOL(nfc_targets_found); | 456 | EXPORT_SYMBOL(nfc_targets_found); |
| 457 | 457 | ||
| 458 | int nfc_target_lost(struct nfc_dev *dev, u32 target_idx) | ||
| 459 | { | ||
| 460 | struct nfc_target *tg; | ||
| 461 | int i; | ||
| 462 | |||
| 463 | pr_debug("dev_name %s n_target %d\n", dev_name(&dev->dev), target_idx); | ||
| 464 | |||
| 465 | spin_lock_bh(&dev->targets_lock); | ||
| 466 | |||
| 467 | for (i = 0; i < dev->n_targets; i++) { | ||
| 468 | tg = &dev->targets[i]; | ||
| 469 | if (tg->idx == target_idx) | ||
| 470 | break; | ||
| 471 | } | ||
| 472 | |||
| 473 | if (i == dev->n_targets) { | ||
| 474 | spin_unlock_bh(&dev->targets_lock); | ||
| 475 | return -EINVAL; | ||
| 476 | } | ||
| 477 | |||
| 478 | dev->targets_generation++; | ||
| 479 | dev->n_targets--; | ||
| 480 | |||
| 481 | if (dev->n_targets) { | ||
| 482 | memcpy(&dev->targets[i], &dev->targets[i + 1], | ||
| 483 | (dev->n_targets - i) * sizeof(struct nfc_target)); | ||
| 484 | } else { | ||
| 485 | kfree(dev->targets); | ||
| 486 | dev->targets = NULL; | ||
| 487 | } | ||
| 488 | |||
| 489 | spin_unlock_bh(&dev->targets_lock); | ||
| 490 | |||
| 491 | nfc_genl_target_lost(dev, target_idx); | ||
| 492 | |||
| 493 | return 0; | ||
| 494 | } | ||
| 495 | EXPORT_SYMBOL(nfc_target_lost); | ||
| 496 | |||
| 458 | static void nfc_release(struct device *d) | 497 | static void nfc_release(struct device *d) |
| 459 | { | 498 | { |
| 460 | struct nfc_dev *dev = to_nfc_dev(d); | 499 | struct nfc_dev *dev = to_nfc_dev(d); |
