aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2012-05-16 09:55:48 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2012-06-04 15:34:30 -0400
commitbe9ae4ce4ee66e211815122ab4f41913efed4fec (patch)
tree157edfc0f57ab39fe14e1b7f994378da5a91b649
parentf212ad5e993e7efb996fc8ce94a5de8f0bd06d41 (diff)
NFC: Introduce target mode tx ops
And rename the initiator mode data exchange ops for consistency sake. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
-rw-r--r--drivers/nfc/pn533.c8
-rw-r--r--include/net/nfc/nfc.h3
-rw-r--r--net/nfc/core.c37
-rw-r--r--net/nfc/hci/core.c8
-rw-r--r--net/nfc/nci/core.c8
5 files changed, 34 insertions, 30 deletions
diff --git a/drivers/nfc/pn533.c b/drivers/nfc/pn533.c
index c6b9bc5ac6e6..fd94c6f5d6a8 100644
--- a/drivers/nfc/pn533.c
+++ b/drivers/nfc/pn533.c
@@ -1691,9 +1691,9 @@ error:
1691 return 0; 1691 return 0;
1692} 1692}
1693 1693
1694static int pn533_data_exchange(struct nfc_dev *nfc_dev, 1694static int pn533_transceive(struct nfc_dev *nfc_dev,
1695 struct nfc_target *target, struct sk_buff *skb, 1695 struct nfc_target *target, struct sk_buff *skb,
1696 data_exchange_cb_t cb, void *cb_context) 1696 data_exchange_cb_t cb, void *cb_context)
1697{ 1697{
1698 struct pn533 *dev = nfc_get_drvdata(nfc_dev); 1698 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1699 struct pn533_frame *out_frame, *in_frame; 1699 struct pn533_frame *out_frame, *in_frame;
@@ -1853,7 +1853,7 @@ struct nfc_ops pn533_nfc_ops = {
1853 .stop_poll = pn533_stop_poll, 1853 .stop_poll = pn533_stop_poll,
1854 .activate_target = pn533_activate_target, 1854 .activate_target = pn533_activate_target,
1855 .deactivate_target = pn533_deactivate_target, 1855 .deactivate_target = pn533_deactivate_target,
1856 .data_exchange = pn533_data_exchange, 1856 .im_transceive = pn533_transceive,
1857}; 1857};
1858 1858
1859static int pn533_probe(struct usb_interface *interface, 1859static int pn533_probe(struct usb_interface *interface,
diff --git a/include/net/nfc/nfc.h b/include/net/nfc/nfc.h
index a6a7b49a3e2d..45c4c970575c 100644
--- a/include/net/nfc/nfc.h
+++ b/include/net/nfc/nfc.h
@@ -63,9 +63,10 @@ struct nfc_ops {
63 u32 protocol); 63 u32 protocol);
64 void (*deactivate_target)(struct nfc_dev *dev, 64 void (*deactivate_target)(struct nfc_dev *dev,
65 struct nfc_target *target); 65 struct nfc_target *target);
66 int (*data_exchange)(struct nfc_dev *dev, struct nfc_target *target, 66 int (*im_transceive)(struct nfc_dev *dev, struct nfc_target *target,
67 struct sk_buff *skb, data_exchange_cb_t cb, 67 struct sk_buff *skb, data_exchange_cb_t cb,
68 void *cb_context); 68 void *cb_context);
69 int (*tm_send)(struct nfc_dev *dev, struct sk_buff *skb);
69 int (*check_presence)(struct nfc_dev *dev, struct nfc_target *target); 70 int (*check_presence)(struct nfc_dev *dev, struct nfc_target *target);
70}; 71};
71 72
diff --git a/net/nfc/core.c b/net/nfc/core.c
index 722a0c76c669..76c1e207d297 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -413,27 +413,30 @@ int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb,
413 goto error; 413 goto error;
414 } 414 }
415 415
416 if (dev->active_target == NULL) { 416 if (dev->rf_mode == NFC_RF_INITIATOR && dev->active_target != NULL) {
417 rc = -ENOTCONN; 417 if (dev->active_target->idx != target_idx) {
418 kfree_skb(skb); 418 rc = -EADDRNOTAVAIL;
419 goto error; 419 kfree_skb(skb);
420 } 420 goto error;
421 }
421 422
422 if (dev->active_target->idx != target_idx) { 423 if (dev->ops->check_presence)
423 rc = -EADDRNOTAVAIL; 424 del_timer_sync(&dev->check_pres_timer);
425
426 rc = dev->ops->im_transceive(dev, dev->active_target, skb, cb,
427 cb_context);
428
429 if (!rc && dev->ops->check_presence)
430 mod_timer(&dev->check_pres_timer, jiffies +
431 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
432 } else if (dev->rf_mode == NFC_RF_TARGET && dev->ops->tm_send != NULL) {
433 rc = dev->ops->tm_send(dev, skb);
434 } else {
435 rc = -ENOTCONN;
424 kfree_skb(skb); 436 kfree_skb(skb);
425 goto error; 437 goto error;
426 } 438 }
427 439
428 if (dev->ops->check_presence)
429 del_timer_sync(&dev->check_pres_timer);
430
431 rc = dev->ops->data_exchange(dev, dev->active_target, skb, cb,
432 cb_context);
433
434 if (!rc && dev->ops->check_presence)
435 mod_timer(&dev->check_pres_timer, jiffies +
436 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
437 440
438error: 441error:
439 device_unlock(&dev->dev); 442 device_unlock(&dev->dev);
@@ -727,7 +730,7 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
727 struct nfc_dev *dev; 730 struct nfc_dev *dev;
728 731
729 if (!ops->start_poll || !ops->stop_poll || !ops->activate_target || 732 if (!ops->start_poll || !ops->stop_poll || !ops->activate_target ||
730 !ops->deactivate_target || !ops->data_exchange) 733 !ops->deactivate_target || !ops->im_transceive)
731 return NULL; 734 return NULL;
732 735
733 if (!supported_protocols) 736 if (!supported_protocols)
diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c
index 281f3a3bec00..a8b0b71e8f86 100644
--- a/net/nfc/hci/core.c
+++ b/net/nfc/hci/core.c
@@ -512,9 +512,9 @@ static void hci_deactivate_target(struct nfc_dev *nfc_dev,
512{ 512{
513} 513}
514 514
515static int hci_data_exchange(struct nfc_dev *nfc_dev, struct nfc_target *target, 515static int hci_transceive(struct nfc_dev *nfc_dev, struct nfc_target *target,
516 struct sk_buff *skb, data_exchange_cb_t cb, 516 struct sk_buff *skb, data_exchange_cb_t cb,
517 void *cb_context) 517 void *cb_context)
518{ 518{
519 struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev); 519 struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
520 int r; 520 int r;
@@ -580,7 +580,7 @@ static struct nfc_ops hci_nfc_ops = {
580 .stop_poll = hci_stop_poll, 580 .stop_poll = hci_stop_poll,
581 .activate_target = hci_activate_target, 581 .activate_target = hci_activate_target,
582 .deactivate_target = hci_deactivate_target, 582 .deactivate_target = hci_deactivate_target,
583 .data_exchange = hci_data_exchange, 583 .im_transceive = hci_transceive,
584 .check_presence = hci_check_presence, 584 .check_presence = hci_check_presence,
585}; 585};
586 586
diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index 0f718982f808..766a02b1dfa1 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -522,9 +522,9 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev,
522 } 522 }
523} 523}
524 524
525static int nci_data_exchange(struct nfc_dev *nfc_dev, struct nfc_target *target, 525static int nci_transceive(struct nfc_dev *nfc_dev, struct nfc_target *target,
526 struct sk_buff *skb, 526 struct sk_buff *skb,
527 data_exchange_cb_t cb, void *cb_context) 527 data_exchange_cb_t cb, void *cb_context)
528{ 528{
529 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); 529 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
530 int rc; 530 int rc;
@@ -557,7 +557,7 @@ static struct nfc_ops nci_nfc_ops = {
557 .stop_poll = nci_stop_poll, 557 .stop_poll = nci_stop_poll,
558 .activate_target = nci_activate_target, 558 .activate_target = nci_activate_target,
559 .deactivate_target = nci_deactivate_target, 559 .deactivate_target = nci_deactivate_target,
560 .data_exchange = nci_data_exchange, 560 .im_transceive = nci_transceive,
561}; 561};
562 562
563/* ---- Interface to NCI drivers ---- */ 563/* ---- Interface to NCI drivers ---- */