Skip to content

Commit fe7c580

Browse files
author
Samuel Ortiz
committed
NFC: Add target mode protocols to the polling loop startup routine
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent ab73b75 commit fe7c580

12 files changed

Lines changed: 77 additions & 34 deletions

File tree

‎drivers/nfc/pn533.c‎

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,27 +1078,23 @@ static int pn533_start_poll_complete(struct pn533 *dev, void *arg,
10781078
return 0;
10791079
}
10801080

1081-
static int pn533_start_poll(struct nfc_dev *nfc_dev, u32 protocols)
1081+
static int pn533_init_target(struct nfc_dev *nfc_dev, u32 protocols)
1082+
{
1083+
return 0;
1084+
}
1085+
1086+
static int pn533_start_im_poll(struct nfc_dev *nfc_dev, u32 protocols)
10821087
{
10831088
struct pn533 *dev = nfc_get_drvdata(nfc_dev);
10841089
struct pn533_poll_modulations *start_mod;
10851090
int rc;
10861091

1087-
nfc_dev_dbg(&dev->interface->dev, "%s - protocols=0x%x", __func__,
1088-
protocols);
1089-
10901092
if (dev->poll_mod_count) {
10911093
nfc_dev_err(&dev->interface->dev, "Polling operation already"
10921094
" active");
10931095
return -EBUSY;
10941096
}
10951097

1096-
if (dev->tgt_active_prot) {
1097-
nfc_dev_err(&dev->interface->dev, "Cannot poll with a target"
1098-
" already activated");
1099-
return -EBUSY;
1100-
}
1101-
11021098
pn533_poll_create_mod_list(dev, protocols);
11031099

11041100
if (!dev->poll_mod_count) {
@@ -1135,6 +1131,29 @@ static int pn533_start_poll(struct nfc_dev *nfc_dev, u32 protocols)
11351131
return rc;
11361132
}
11371133

1134+
static int pn533_start_poll(struct nfc_dev *nfc_dev,
1135+
u32 im_protocols, u32 tm_protocols)
1136+
{
1137+
struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1138+
1139+
nfc_dev_dbg(&dev->interface->dev,
1140+
"%s: im protocols 0x%x tm protocols 0x%x",
1141+
__func__, im_protocols, tm_protocols);
1142+
1143+
if (dev->tgt_active_prot) {
1144+
nfc_dev_err(&dev->interface->dev,
1145+
"Cannot poll with a target already activated");
1146+
return -EBUSY;
1147+
}
1148+
1149+
if (!tm_protocols)
1150+
return pn533_start_im_poll(nfc_dev, im_protocols);
1151+
else if (!im_protocols)
1152+
return pn533_init_target(nfc_dev, tm_protocols);
1153+
else
1154+
return -EINVAL;
1155+
}
1156+
11381157
static void pn533_stop_poll(struct nfc_dev *nfc_dev)
11391158
{
11401159
struct pn533 *dev = nfc_get_drvdata(nfc_dev);

‎drivers/nfc/pn544_hci.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,15 +576,17 @@ static int pn544_hci_xmit(struct nfc_shdlc *shdlc, struct sk_buff *skb)
576576
return pn544_hci_i2c_write(client, skb->data, skb->len);
577577
}
578578

579-
static int pn544_hci_start_poll(struct nfc_shdlc *shdlc, u32 protocols)
579+
static int pn544_hci_start_poll(struct nfc_shdlc *shdlc,
580+
u32 im_protocols, u32 tm_protocols)
580581
{
581582
struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev(shdlc);
582583
u8 phases = 0;
583584
int r;
584585
u8 duration[2];
585586
u8 activated;
586587

587-
pr_info(DRIVER_DESC ": %s protocols = %d\n", __func__, protocols);
588+
pr_info(DRIVER_DESC ": %s protocols 0x%x 0x%x\n",
589+
__func__, im_protocols, tm_protocols);
588590

589591
r = nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE,
590592
NFC_HCI_EVT_END_OPERATION, NULL, 0);
@@ -604,10 +606,10 @@ static int pn544_hci_start_poll(struct nfc_shdlc *shdlc, u32 protocols)
604606
if (r < 0)
605607
return r;
606608

607-
if (protocols & (NFC_PROTO_ISO14443_MASK | NFC_PROTO_MIFARE_MASK |
609+
if (im_protocols & (NFC_PROTO_ISO14443_MASK | NFC_PROTO_MIFARE_MASK |
608610
NFC_PROTO_JEWEL_MASK))
609611
phases |= 1; /* Type A */
610-
if (protocols & NFC_PROTO_FELICA_MASK) {
612+
if (im_protocols & NFC_PROTO_FELICA_MASK) {
611613
phases |= (1 << 2); /* Type F 212 */
612614
phases |= (1 << 3); /* Type F 424 */
613615
}

‎include/linux/nfc.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ enum nfc_commands {
9494
* @NFC_ATTR_TARGET_SENSF_RES: NFC-F targets extra information, max 18 bytes
9595
* @NFC_ATTR_COMM_MODE: Passive or active mode
9696
* @NFC_ATTR_RF_MODE: Initiator or target
97+
* @NFC_ATTR_IM_PROTOCOLS: Initiator mode protocols to poll for
98+
* @NFC_ATTR_TM_PROTOCOLS: Target mode protocols to listen for
9799
*/
98100
enum nfc_attrs {
99101
NFC_ATTR_UNSPEC,
@@ -109,6 +111,8 @@ enum nfc_attrs {
109111
NFC_ATTR_COMM_MODE,
110112
NFC_ATTR_RF_MODE,
111113
NFC_ATTR_DEVICE_POWERED,
114+
NFC_ATTR_IM_PROTOCOLS,
115+
NFC_ATTR_TM_PROTOCOLS,
112116
/* private: internal use only */
113117
__NFC_ATTR_AFTER_LAST
114118
};

‎include/net/nfc/hci.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ struct nfc_hci_ops {
3131
void (*close) (struct nfc_hci_dev *hdev);
3232
int (*hci_ready) (struct nfc_hci_dev *hdev);
3333
int (*xmit) (struct nfc_hci_dev *hdev, struct sk_buff *skb);
34-
int (*start_poll) (struct nfc_hci_dev *hdev, u32 protocols);
34+
int (*start_poll) (struct nfc_hci_dev *hdev,
35+
u32 im_protocols, u32 tm_protocols);
3536
int (*target_from_gate) (struct nfc_hci_dev *hdev, u8 gate,
3637
struct nfc_target *target);
3738
int (*complete_target_discovered) (struct nfc_hci_dev *hdev, u8 gate,

‎include/net/nfc/nfc.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ struct nfc_target;
5353
struct nfc_ops {
5454
int (*dev_up)(struct nfc_dev *dev);
5555
int (*dev_down)(struct nfc_dev *dev);
56-
int (*start_poll)(struct nfc_dev *dev, u32 protocols);
56+
int (*start_poll)(struct nfc_dev *dev,
57+
u32 im_protocols, u32 tm_protocols);
5758
void (*stop_poll)(struct nfc_dev *dev);
5859
int (*dep_link_up)(struct nfc_dev *dev, struct nfc_target *target,
5960
u8 comm_mode, u8 *gb, size_t gb_len);

‎include/net/nfc/shdlc.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ struct nfc_shdlc_ops {
2727
void (*close) (struct nfc_shdlc *shdlc);
2828
int (*hci_ready) (struct nfc_shdlc *shdlc);
2929
int (*xmit) (struct nfc_shdlc *shdlc, struct sk_buff *skb);
30-
int (*start_poll) (struct nfc_shdlc *shdlc, u32 protocols);
30+
int (*start_poll) (struct nfc_shdlc *shdlc,
31+
u32 im_protocols, u32 tm_protocols);
3132
int (*target_from_gate) (struct nfc_shdlc *shdlc, u8 gate,
3233
struct nfc_target *target);
3334
int (*complete_target_discovered) (struct nfc_shdlc *shdlc, u8 gate,

‎net/nfc/core.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ int nfc_dev_down(struct nfc_dev *dev)
121121
* The device remains polling for targets until a target is found or
122122
* the nfc_stop_poll function is called.
123123
*/
124-
int nfc_start_poll(struct nfc_dev *dev, u32 protocols)
124+
int nfc_start_poll(struct nfc_dev *dev, u32 im_protocols, u32 tm_protocols)
125125
{
126126
int rc;
127127

128-
pr_debug("dev_name=%s protocols=0x%x\n",
129-
dev_name(&dev->dev), protocols);
128+
pr_debug("dev_name %s initiator protocols 0x%x target protocols 0x%x\n",
129+
dev_name(&dev->dev), im_protocols, tm_protocols);
130130

131-
if (!protocols)
131+
if (!im_protocols && !tm_protocols)
132132
return -EINVAL;
133133

134134
device_lock(&dev->dev);
@@ -143,7 +143,7 @@ int nfc_start_poll(struct nfc_dev *dev, u32 protocols)
143143
goto error;
144144
}
145145

146-
rc = dev->ops->start_poll(dev, protocols);
146+
rc = dev->ops->start_poll(dev, im_protocols, tm_protocols);
147147
if (!rc)
148148
dev->polling = true;
149149

‎net/nfc/hci/core.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,13 @@ static int hci_dev_down(struct nfc_dev *nfc_dev)
481481
return 0;
482482
}
483483

484-
static int hci_start_poll(struct nfc_dev *nfc_dev, u32 protocols)
484+
static int hci_start_poll(struct nfc_dev *nfc_dev,
485+
u32 im_protocols, u32 tm_protocols)
485486
{
486487
struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
487488

488489
if (hdev->ops->start_poll)
489-
return hdev->ops->start_poll(hdev, protocols);
490+
return hdev->ops->start_poll(hdev, im_protocols, tm_protocols);
490491
else
491492
return nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE,
492493
NFC_HCI_EVT_READER_REQUESTED, NULL, 0);

‎net/nfc/hci/shdlc.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,14 +765,16 @@ static int nfc_shdlc_xmit(struct nfc_hci_dev *hdev, struct sk_buff *skb)
765765
return 0;
766766
}
767767

768-
static int nfc_shdlc_start_poll(struct nfc_hci_dev *hdev, u32 protocols)
768+
static int nfc_shdlc_start_poll(struct nfc_hci_dev *hdev,
769+
u32 im_protocols, u32 tm_protocols)
769770
{
770771
struct nfc_shdlc *shdlc = nfc_hci_get_clientdata(hdev);
771772

772773
pr_debug("\n");
773774

774775
if (shdlc->ops->start_poll)
775-
return shdlc->ops->start_poll(shdlc, protocols);
776+
return shdlc->ops->start_poll(shdlc,
777+
im_protocols, tm_protocols);
776778

777779
return 0;
778780
}

‎net/nfc/nci/core.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ static int nci_dev_down(struct nfc_dev *nfc_dev)
387387
return nci_close_device(ndev);
388388
}
389389

390-
static int nci_start_poll(struct nfc_dev *nfc_dev, __u32 protocols)
390+
static int nci_start_poll(struct nfc_dev *nfc_dev,
391+
__u32 im_protocols, __u32 tm_protocols)
391392
{
392393
struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
393394
int rc;
@@ -413,11 +414,11 @@ static int nci_start_poll(struct nfc_dev *nfc_dev, __u32 protocols)
413414
return -EBUSY;
414415
}
415416

416-
rc = nci_request(ndev, nci_rf_discover_req, protocols,
417+
rc = nci_request(ndev, nci_rf_discover_req, im_protocols,
417418
msecs_to_jiffies(NCI_RF_DISC_TIMEOUT));
418419

419420
if (!rc)
420-
ndev->poll_prots = protocols;
421+
ndev->poll_prots = im_protocols;
421422

422423
return rc;
423424
}

0 commit comments

Comments
 (0)