Commit fe7c5800 authored by Samuel Ortiz's avatar Samuel Ortiz

NFC: Add target mode protocols to the polling loop startup routine

Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent ab73b751
...@@ -1078,27 +1078,23 @@ static int pn533_start_poll_complete(struct pn533 *dev, void *arg, ...@@ -1078,27 +1078,23 @@ static int pn533_start_poll_complete(struct pn533 *dev, void *arg,
return 0; return 0;
} }
static int pn533_start_poll(struct nfc_dev *nfc_dev, u32 protocols) static int pn533_init_target(struct nfc_dev *nfc_dev, u32 protocols)
{
return 0;
}
static int pn533_start_im_poll(struct nfc_dev *nfc_dev, u32 protocols)
{ {
struct pn533 *dev = nfc_get_drvdata(nfc_dev); struct pn533 *dev = nfc_get_drvdata(nfc_dev);
struct pn533_poll_modulations *start_mod; struct pn533_poll_modulations *start_mod;
int rc; int rc;
nfc_dev_dbg(&dev->interface->dev, "%s - protocols=0x%x", __func__,
protocols);
if (dev->poll_mod_count) { if (dev->poll_mod_count) {
nfc_dev_err(&dev->interface->dev, "Polling operation already" nfc_dev_err(&dev->interface->dev, "Polling operation already"
" active"); " active");
return -EBUSY; return -EBUSY;
} }
if (dev->tgt_active_prot) {
nfc_dev_err(&dev->interface->dev, "Cannot poll with a target"
" already activated");
return -EBUSY;
}
pn533_poll_create_mod_list(dev, protocols); pn533_poll_create_mod_list(dev, protocols);
if (!dev->poll_mod_count) { if (!dev->poll_mod_count) {
...@@ -1135,6 +1131,29 @@ static int pn533_start_poll(struct nfc_dev *nfc_dev, u32 protocols) ...@@ -1135,6 +1131,29 @@ static int pn533_start_poll(struct nfc_dev *nfc_dev, u32 protocols)
return rc; return rc;
} }
static int pn533_start_poll(struct nfc_dev *nfc_dev,
u32 im_protocols, u32 tm_protocols)
{
struct pn533 *dev = nfc_get_drvdata(nfc_dev);
nfc_dev_dbg(&dev->interface->dev,
"%s: im protocols 0x%x tm protocols 0x%x",
__func__, im_protocols, tm_protocols);
if (dev->tgt_active_prot) {
nfc_dev_err(&dev->interface->dev,
"Cannot poll with a target already activated");
return -EBUSY;
}
if (!tm_protocols)
return pn533_start_im_poll(nfc_dev, im_protocols);
else if (!im_protocols)
return pn533_init_target(nfc_dev, tm_protocols);
else
return -EINVAL;
}
static void pn533_stop_poll(struct nfc_dev *nfc_dev) static void pn533_stop_poll(struct nfc_dev *nfc_dev)
{ {
struct pn533 *dev = nfc_get_drvdata(nfc_dev); struct pn533 *dev = nfc_get_drvdata(nfc_dev);
......
...@@ -576,7 +576,8 @@ static int pn544_hci_xmit(struct nfc_shdlc *shdlc, struct sk_buff *skb) ...@@ -576,7 +576,8 @@ static int pn544_hci_xmit(struct nfc_shdlc *shdlc, struct sk_buff *skb)
return pn544_hci_i2c_write(client, skb->data, skb->len); return pn544_hci_i2c_write(client, skb->data, skb->len);
} }
static int pn544_hci_start_poll(struct nfc_shdlc *shdlc, u32 protocols) static int pn544_hci_start_poll(struct nfc_shdlc *shdlc,
u32 im_protocols, u32 tm_protocols)
{ {
struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev(shdlc); struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev(shdlc);
u8 phases = 0; u8 phases = 0;
...@@ -584,7 +585,8 @@ static int pn544_hci_start_poll(struct nfc_shdlc *shdlc, u32 protocols) ...@@ -584,7 +585,8 @@ static int pn544_hci_start_poll(struct nfc_shdlc *shdlc, u32 protocols)
u8 duration[2]; u8 duration[2];
u8 activated; u8 activated;
pr_info(DRIVER_DESC ": %s protocols = %d\n", __func__, protocols); pr_info(DRIVER_DESC ": %s protocols 0x%x 0x%x\n",
__func__, im_protocols, tm_protocols);
r = nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE, r = nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE,
NFC_HCI_EVT_END_OPERATION, NULL, 0); NFC_HCI_EVT_END_OPERATION, NULL, 0);
...@@ -604,10 +606,10 @@ static int pn544_hci_start_poll(struct nfc_shdlc *shdlc, u32 protocols) ...@@ -604,10 +606,10 @@ static int pn544_hci_start_poll(struct nfc_shdlc *shdlc, u32 protocols)
if (r < 0) if (r < 0)
return r; return r;
if (protocols & (NFC_PROTO_ISO14443_MASK | NFC_PROTO_MIFARE_MASK | if (im_protocols & (NFC_PROTO_ISO14443_MASK | NFC_PROTO_MIFARE_MASK |
NFC_PROTO_JEWEL_MASK)) NFC_PROTO_JEWEL_MASK))
phases |= 1; /* Type A */ phases |= 1; /* Type A */
if (protocols & NFC_PROTO_FELICA_MASK) { if (im_protocols & NFC_PROTO_FELICA_MASK) {
phases |= (1 << 2); /* Type F 212 */ phases |= (1 << 2); /* Type F 212 */
phases |= (1 << 3); /* Type F 424 */ phases |= (1 << 3); /* Type F 424 */
} }
......
...@@ -94,6 +94,8 @@ enum nfc_commands { ...@@ -94,6 +94,8 @@ enum nfc_commands {
* @NFC_ATTR_TARGET_SENSF_RES: NFC-F targets extra information, max 18 bytes * @NFC_ATTR_TARGET_SENSF_RES: NFC-F targets extra information, max 18 bytes
* @NFC_ATTR_COMM_MODE: Passive or active mode * @NFC_ATTR_COMM_MODE: Passive or active mode
* @NFC_ATTR_RF_MODE: Initiator or target * @NFC_ATTR_RF_MODE: Initiator or target
* @NFC_ATTR_IM_PROTOCOLS: Initiator mode protocols to poll for
* @NFC_ATTR_TM_PROTOCOLS: Target mode protocols to listen for
*/ */
enum nfc_attrs { enum nfc_attrs {
NFC_ATTR_UNSPEC, NFC_ATTR_UNSPEC,
...@@ -109,6 +111,8 @@ enum nfc_attrs { ...@@ -109,6 +111,8 @@ enum nfc_attrs {
NFC_ATTR_COMM_MODE, NFC_ATTR_COMM_MODE,
NFC_ATTR_RF_MODE, NFC_ATTR_RF_MODE,
NFC_ATTR_DEVICE_POWERED, NFC_ATTR_DEVICE_POWERED,
NFC_ATTR_IM_PROTOCOLS,
NFC_ATTR_TM_PROTOCOLS,
/* private: internal use only */ /* private: internal use only */
__NFC_ATTR_AFTER_LAST __NFC_ATTR_AFTER_LAST
}; };
......
...@@ -31,7 +31,8 @@ struct nfc_hci_ops { ...@@ -31,7 +31,8 @@ struct nfc_hci_ops {
void (*close) (struct nfc_hci_dev *hdev); void (*close) (struct nfc_hci_dev *hdev);
int (*hci_ready) (struct nfc_hci_dev *hdev); int (*hci_ready) (struct nfc_hci_dev *hdev);
int (*xmit) (struct nfc_hci_dev *hdev, struct sk_buff *skb); int (*xmit) (struct nfc_hci_dev *hdev, struct sk_buff *skb);
int (*start_poll) (struct nfc_hci_dev *hdev, u32 protocols); int (*start_poll) (struct nfc_hci_dev *hdev,
u32 im_protocols, u32 tm_protocols);
int (*target_from_gate) (struct nfc_hci_dev *hdev, u8 gate, int (*target_from_gate) (struct nfc_hci_dev *hdev, u8 gate,
struct nfc_target *target); struct nfc_target *target);
int (*complete_target_discovered) (struct nfc_hci_dev *hdev, u8 gate, int (*complete_target_discovered) (struct nfc_hci_dev *hdev, u8 gate,
......
...@@ -53,7 +53,8 @@ struct nfc_target; ...@@ -53,7 +53,8 @@ struct nfc_target;
struct nfc_ops { struct nfc_ops {
int (*dev_up)(struct nfc_dev *dev); int (*dev_up)(struct nfc_dev *dev);
int (*dev_down)(struct nfc_dev *dev); int (*dev_down)(struct nfc_dev *dev);
int (*start_poll)(struct nfc_dev *dev, u32 protocols); int (*start_poll)(struct nfc_dev *dev,
u32 im_protocols, u32 tm_protocols);
void (*stop_poll)(struct nfc_dev *dev); void (*stop_poll)(struct nfc_dev *dev);
int (*dep_link_up)(struct nfc_dev *dev, struct nfc_target *target, int (*dep_link_up)(struct nfc_dev *dev, struct nfc_target *target,
u8 comm_mode, u8 *gb, size_t gb_len); u8 comm_mode, u8 *gb, size_t gb_len);
......
...@@ -27,7 +27,8 @@ struct nfc_shdlc_ops { ...@@ -27,7 +27,8 @@ struct nfc_shdlc_ops {
void (*close) (struct nfc_shdlc *shdlc); void (*close) (struct nfc_shdlc *shdlc);
int (*hci_ready) (struct nfc_shdlc *shdlc); int (*hci_ready) (struct nfc_shdlc *shdlc);
int (*xmit) (struct nfc_shdlc *shdlc, struct sk_buff *skb); int (*xmit) (struct nfc_shdlc *shdlc, struct sk_buff *skb);
int (*start_poll) (struct nfc_shdlc *shdlc, u32 protocols); int (*start_poll) (struct nfc_shdlc *shdlc,
u32 im_protocols, u32 tm_protocols);
int (*target_from_gate) (struct nfc_shdlc *shdlc, u8 gate, int (*target_from_gate) (struct nfc_shdlc *shdlc, u8 gate,
struct nfc_target *target); struct nfc_target *target);
int (*complete_target_discovered) (struct nfc_shdlc *shdlc, u8 gate, int (*complete_target_discovered) (struct nfc_shdlc *shdlc, u8 gate,
......
...@@ -121,14 +121,14 @@ int nfc_dev_down(struct nfc_dev *dev) ...@@ -121,14 +121,14 @@ int nfc_dev_down(struct nfc_dev *dev)
* The device remains polling for targets until a target is found or * The device remains polling for targets until a target is found or
* the nfc_stop_poll function is called. * the nfc_stop_poll function is called.
*/ */
int nfc_start_poll(struct nfc_dev *dev, u32 protocols) int nfc_start_poll(struct nfc_dev *dev, u32 im_protocols, u32 tm_protocols)
{ {
int rc; int rc;
pr_debug("dev_name=%s protocols=0x%x\n", pr_debug("dev_name %s initiator protocols 0x%x target protocols 0x%x\n",
dev_name(&dev->dev), protocols); dev_name(&dev->dev), im_protocols, tm_protocols);
if (!protocols) if (!im_protocols && !tm_protocols)
return -EINVAL; return -EINVAL;
device_lock(&dev->dev); device_lock(&dev->dev);
...@@ -143,7 +143,7 @@ int nfc_start_poll(struct nfc_dev *dev, u32 protocols) ...@@ -143,7 +143,7 @@ int nfc_start_poll(struct nfc_dev *dev, u32 protocols)
goto error; goto error;
} }
rc = dev->ops->start_poll(dev, protocols); rc = dev->ops->start_poll(dev, im_protocols, tm_protocols);
if (!rc) if (!rc)
dev->polling = true; dev->polling = true;
......
...@@ -481,12 +481,13 @@ static int hci_dev_down(struct nfc_dev *nfc_dev) ...@@ -481,12 +481,13 @@ static int hci_dev_down(struct nfc_dev *nfc_dev)
return 0; return 0;
} }
static int hci_start_poll(struct nfc_dev *nfc_dev, u32 protocols) static int hci_start_poll(struct nfc_dev *nfc_dev,
u32 im_protocols, u32 tm_protocols)
{ {
struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev); struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
if (hdev->ops->start_poll) if (hdev->ops->start_poll)
return hdev->ops->start_poll(hdev, protocols); return hdev->ops->start_poll(hdev, im_protocols, tm_protocols);
else else
return nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE, return nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE,
NFC_HCI_EVT_READER_REQUESTED, NULL, 0); NFC_HCI_EVT_READER_REQUESTED, NULL, 0);
......
...@@ -765,14 +765,16 @@ static int nfc_shdlc_xmit(struct nfc_hci_dev *hdev, struct sk_buff *skb) ...@@ -765,14 +765,16 @@ static int nfc_shdlc_xmit(struct nfc_hci_dev *hdev, struct sk_buff *skb)
return 0; return 0;
} }
static int nfc_shdlc_start_poll(struct nfc_hci_dev *hdev, u32 protocols) static int nfc_shdlc_start_poll(struct nfc_hci_dev *hdev,
u32 im_protocols, u32 tm_protocols)
{ {
struct nfc_shdlc *shdlc = nfc_hci_get_clientdata(hdev); struct nfc_shdlc *shdlc = nfc_hci_get_clientdata(hdev);
pr_debug("\n"); pr_debug("\n");
if (shdlc->ops->start_poll) if (shdlc->ops->start_poll)
return shdlc->ops->start_poll(shdlc, protocols); return shdlc->ops->start_poll(shdlc,
im_protocols, tm_protocols);
return 0; return 0;
} }
......
...@@ -387,7 +387,8 @@ static int nci_dev_down(struct nfc_dev *nfc_dev) ...@@ -387,7 +387,8 @@ static int nci_dev_down(struct nfc_dev *nfc_dev)
return nci_close_device(ndev); return nci_close_device(ndev);
} }
static int nci_start_poll(struct nfc_dev *nfc_dev, __u32 protocols) static int nci_start_poll(struct nfc_dev *nfc_dev,
__u32 im_protocols, __u32 tm_protocols)
{ {
struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
int rc; int rc;
...@@ -413,11 +414,11 @@ static int nci_start_poll(struct nfc_dev *nfc_dev, __u32 protocols) ...@@ -413,11 +414,11 @@ static int nci_start_poll(struct nfc_dev *nfc_dev, __u32 protocols)
return -EBUSY; return -EBUSY;
} }
rc = nci_request(ndev, nci_rf_discover_req, protocols, rc = nci_request(ndev, nci_rf_discover_req, im_protocols,
msecs_to_jiffies(NCI_RF_DISC_TIMEOUT)); msecs_to_jiffies(NCI_RF_DISC_TIMEOUT));
if (!rc) if (!rc)
ndev->poll_prots = protocols; ndev->poll_prots = im_protocols;
return rc; return rc;
} }
......
...@@ -49,6 +49,8 @@ static const struct nla_policy nfc_genl_policy[NFC_ATTR_MAX + 1] = { ...@@ -49,6 +49,8 @@ static const struct nla_policy nfc_genl_policy[NFC_ATTR_MAX + 1] = {
[NFC_ATTR_COMM_MODE] = { .type = NLA_U8 }, [NFC_ATTR_COMM_MODE] = { .type = NLA_U8 },
[NFC_ATTR_RF_MODE] = { .type = NLA_U8 }, [NFC_ATTR_RF_MODE] = { .type = NLA_U8 },
[NFC_ATTR_DEVICE_POWERED] = { .type = NLA_U8 }, [NFC_ATTR_DEVICE_POWERED] = { .type = NLA_U8 },
[NFC_ATTR_IM_PROTOCOLS] = { .type = NLA_U32 },
[NFC_ATTR_TM_PROTOCOLS] = { .type = NLA_U32 },
}; };
static int nfc_genl_send_target(struct sk_buff *msg, struct nfc_target *target, static int nfc_genl_send_target(struct sk_buff *msg, struct nfc_target *target,
...@@ -519,16 +521,25 @@ static int nfc_genl_start_poll(struct sk_buff *skb, struct genl_info *info) ...@@ -519,16 +521,25 @@ static int nfc_genl_start_poll(struct sk_buff *skb, struct genl_info *info)
struct nfc_dev *dev; struct nfc_dev *dev;
int rc; int rc;
u32 idx; u32 idx;
u32 protocols; u32 im_protocols = 0, tm_protocols = 0;
pr_debug("Poll start\n"); pr_debug("Poll start\n");
if (!info->attrs[NFC_ATTR_DEVICE_INDEX] || if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
!info->attrs[NFC_ATTR_PROTOCOLS]) ((!info->attrs[NFC_ATTR_IM_PROTOCOLS] &&
!info->attrs[NFC_ATTR_PROTOCOLS]) &&
!info->attrs[NFC_ATTR_TM_PROTOCOLS]))
return -EINVAL; return -EINVAL;
idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]); idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
protocols = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]);
if (info->attrs[NFC_ATTR_TM_PROTOCOLS])
tm_protocols = nla_get_u32(info->attrs[NFC_ATTR_TM_PROTOCOLS]);
else if (info->attrs[NFC_ATTR_PROTOCOLS])
tm_protocols = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]);
if (info->attrs[NFC_ATTR_IM_PROTOCOLS])
im_protocols = nla_get_u32(info->attrs[NFC_ATTR_IM_PROTOCOLS]);
dev = nfc_get_device(idx); dev = nfc_get_device(idx);
if (!dev) if (!dev)
...@@ -536,7 +547,7 @@ static int nfc_genl_start_poll(struct sk_buff *skb, struct genl_info *info) ...@@ -536,7 +547,7 @@ static int nfc_genl_start_poll(struct sk_buff *skb, struct genl_info *info)
mutex_lock(&dev->genl_data.genl_data_mutex); mutex_lock(&dev->genl_data.genl_data_mutex);
rc = nfc_start_poll(dev, protocols); rc = nfc_start_poll(dev, im_protocols, tm_protocols);
if (!rc) if (!rc)
dev->genl_data.poll_req_pid = info->snd_pid; dev->genl_data.poll_req_pid = info->snd_pid;
......
...@@ -158,7 +158,7 @@ int nfc_dev_up(struct nfc_dev *dev); ...@@ -158,7 +158,7 @@ int nfc_dev_up(struct nfc_dev *dev);
int nfc_dev_down(struct nfc_dev *dev); int nfc_dev_down(struct nfc_dev *dev);
int nfc_start_poll(struct nfc_dev *dev, u32 protocols); int nfc_start_poll(struct nfc_dev *dev, u32 im_protocols, u32 tm_protocols);
int nfc_stop_poll(struct nfc_dev *dev); int nfc_stop_poll(struct nfc_dev *dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment