aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2012-04-10 13:43:09 -0400
committerJohn W. Linville <linville@tuxdriver.com>2012-04-12 15:10:37 -0400
commitc4fbb6515a4dcec83d340247639b5644c4745528 (patch)
tree9123c1e0b56ea1f9910ce4db1e9046bd5a8a29c4 /net
parent0efbf7fb308d0c6f8419922850a2d0b45d4d4401 (diff)
NFC: The core part should generate the target index
The target index can be used by userspace to uniquely identify a target and thus should be kept unique, per NFC adapter. Moreover, some protocols do not provide a logical index when discovering new targets, so we have to generate one for them. For NCI or pn533 to fetch their logical index, we added a logical_idx field to the target structure. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net')
-rw-r--r--net/nfc/core.c5
-rw-r--r--net/nfc/nci/core.c2
-rw-r--r--net/nfc/nci/ntf.c11
-rw-r--r--net/nfc/rawsock.c6
4 files changed, 18 insertions, 6 deletions
diff --git a/net/nfc/core.c b/net/nfc/core.c
index deb4721ce8a1..d92400087b61 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -428,10 +428,15 @@ EXPORT_SYMBOL(nfc_alloc_recv_skb);
428int nfc_targets_found(struct nfc_dev *dev, 428int nfc_targets_found(struct nfc_dev *dev,
429 struct nfc_target *targets, int n_targets) 429 struct nfc_target *targets, int n_targets)
430{ 430{
431 int i;
432
431 pr_debug("dev_name=%s n_targets=%d\n", dev_name(&dev->dev), n_targets); 433 pr_debug("dev_name=%s n_targets=%d\n", dev_name(&dev->dev), n_targets);
432 434
433 dev->polling = false; 435 dev->polling = false;
434 436
437 for (i = 0; i < n_targets; i++)
438 targets[i].idx = dev->target_idx++;
439
435 spin_lock_bh(&dev->targets_lock); 440 spin_lock_bh(&dev->targets_lock);
436 441
437 dev->targets_generation++; 442 dev->targets_generation++;
diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index 9ec065bb9ee1..8737c2089fdd 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -477,7 +477,7 @@ static int nci_activate_target(struct nfc_dev *nfc_dev, __u32 target_idx,
477 } 477 }
478 478
479 if (atomic_read(&ndev->state) == NCI_W4_HOST_SELECT) { 479 if (atomic_read(&ndev->state) == NCI_W4_HOST_SELECT) {
480 param.rf_discovery_id = target->idx; 480 param.rf_discovery_id = target->logical_idx;
481 481
482 if (protocol == NFC_PROTO_JEWEL) 482 if (protocol == NFC_PROTO_JEWEL)
483 param.rf_protocol = NCI_RF_PROTOCOL_T1T; 483 param.rf_protocol = NCI_RF_PROTOCOL_T1T;
diff --git a/net/nfc/nci/ntf.c b/net/nfc/nci/ntf.c
index 2e3dee42196d..99e1632e6aac 100644
--- a/net/nfc/nci/ntf.c
+++ b/net/nfc/nci/ntf.c
@@ -227,7 +227,7 @@ static void nci_add_new_target(struct nci_dev *ndev,
227 227
228 for (i = 0; i < ndev->n_targets; i++) { 228 for (i = 0; i < ndev->n_targets; i++) {
229 target = &ndev->targets[i]; 229 target = &ndev->targets[i];
230 if (target->idx == ntf->rf_discovery_id) { 230 if (target->logical_idx == ntf->rf_discovery_id) {
231 /* This target already exists, add the new protocol */ 231 /* This target already exists, add the new protocol */
232 nci_add_new_protocol(ndev, target, ntf->rf_protocol, 232 nci_add_new_protocol(ndev, target, ntf->rf_protocol,
233 ntf->rf_tech_and_mode, 233 ntf->rf_tech_and_mode,
@@ -248,10 +248,10 @@ static void nci_add_new_target(struct nci_dev *ndev,
248 ntf->rf_tech_and_mode, 248 ntf->rf_tech_and_mode,
249 &ntf->rf_tech_specific_params); 249 &ntf->rf_tech_specific_params);
250 if (!rc) { 250 if (!rc) {
251 target->idx = ntf->rf_discovery_id; 251 target->logical_idx = ntf->rf_discovery_id;
252 ndev->n_targets++; 252 ndev->n_targets++;
253 253
254 pr_debug("target_idx %d, n_targets %d\n", target->idx, 254 pr_debug("logical idx %d, n_targets %d\n", target->logical_idx,
255 ndev->n_targets); 255 ndev->n_targets);
256 } 256 }
257} 257}
@@ -372,10 +372,11 @@ static void nci_target_auto_activated(struct nci_dev *ndev,
372 if (rc) 372 if (rc)
373 return; 373 return;
374 374
375 target->idx = ntf->rf_discovery_id; 375 target->logical_idx = ntf->rf_discovery_id;
376 ndev->n_targets++; 376 ndev->n_targets++;
377 377
378 pr_debug("target_idx %d, n_targets %d\n", target->idx, ndev->n_targets); 378 pr_debug("logical idx %d, n_targets %d\n",
379 target->logical_idx, ndev->n_targets);
379 380
380 nfc_targets_found(ndev->nfc_dev, ndev->targets, ndev->n_targets); 381 nfc_targets_found(ndev->nfc_dev, ndev->targets, ndev->n_targets);
381} 382}
diff --git a/net/nfc/rawsock.c b/net/nfc/rawsock.c
index 5a839ceb2e82..b2825aa85f64 100644
--- a/net/nfc/rawsock.c
+++ b/net/nfc/rawsock.c
@@ -92,6 +92,12 @@ static int rawsock_connect(struct socket *sock, struct sockaddr *_addr,
92 goto error; 92 goto error;
93 } 93 }
94 94
95 if (addr->target_idx > dev->target_idx - 1 ||
96 addr->target_idx < dev->target_idx - dev->n_targets) {
97 rc = -EINVAL;
98 goto error;
99 }
100
95 rc = nfc_activate_target(dev, addr->target_idx, addr->nfc_protocol); 101 rc = nfc_activate_target(dev, addr->target_idx, addr->nfc_protocol);
96 if (rc) 102 if (rc)
97 goto put_dev; 103 goto put_dev;