提交 c4fbb651 编写于 作者: S Samuel Ortiz 提交者: John W. Linville

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: NSamuel Ortiz <sameo@linux.intel.com>
Signed-off-by: NJohn W. Linville <linville@tuxdriver.com>
上级 0efbf7fb
...@@ -79,6 +79,7 @@ struct nfc_target { ...@@ -79,6 +79,7 @@ struct nfc_target {
u8 sensf_res_len; u8 sensf_res_len;
u8 sensf_res[NFC_SENSF_RES_MAXSIZE]; u8 sensf_res[NFC_SENSF_RES_MAXSIZE];
u8 hci_reader_gate; u8 hci_reader_gate;
u8 logical_idx;
}; };
struct nfc_genl_data { struct nfc_genl_data {
...@@ -88,6 +89,7 @@ struct nfc_genl_data { ...@@ -88,6 +89,7 @@ struct nfc_genl_data {
struct nfc_dev { struct nfc_dev {
unsigned idx; unsigned idx;
unsigned target_idx;
struct nfc_target *targets; struct nfc_target *targets;
int n_targets; int n_targets;
int targets_generation; int targets_generation;
......
...@@ -428,10 +428,15 @@ EXPORT_SYMBOL(nfc_alloc_recv_skb); ...@@ -428,10 +428,15 @@ EXPORT_SYMBOL(nfc_alloc_recv_skb);
int nfc_targets_found(struct nfc_dev *dev, int nfc_targets_found(struct nfc_dev *dev,
struct nfc_target *targets, int n_targets) struct nfc_target *targets, int n_targets)
{ {
int i;
pr_debug("dev_name=%s n_targets=%d\n", dev_name(&dev->dev), n_targets); pr_debug("dev_name=%s n_targets=%d\n", dev_name(&dev->dev), n_targets);
dev->polling = false; dev->polling = false;
for (i = 0; i < n_targets; i++)
targets[i].idx = dev->target_idx++;
spin_lock_bh(&dev->targets_lock); spin_lock_bh(&dev->targets_lock);
dev->targets_generation++; dev->targets_generation++;
......
...@@ -477,7 +477,7 @@ static int nci_activate_target(struct nfc_dev *nfc_dev, __u32 target_idx, ...@@ -477,7 +477,7 @@ static int nci_activate_target(struct nfc_dev *nfc_dev, __u32 target_idx,
} }
if (atomic_read(&ndev->state) == NCI_W4_HOST_SELECT) { if (atomic_read(&ndev->state) == NCI_W4_HOST_SELECT) {
param.rf_discovery_id = target->idx; param.rf_discovery_id = target->logical_idx;
if (protocol == NFC_PROTO_JEWEL) if (protocol == NFC_PROTO_JEWEL)
param.rf_protocol = NCI_RF_PROTOCOL_T1T; param.rf_protocol = NCI_RF_PROTOCOL_T1T;
......
...@@ -227,7 +227,7 @@ static void nci_add_new_target(struct nci_dev *ndev, ...@@ -227,7 +227,7 @@ static void nci_add_new_target(struct nci_dev *ndev,
for (i = 0; i < ndev->n_targets; i++) { for (i = 0; i < ndev->n_targets; i++) {
target = &ndev->targets[i]; target = &ndev->targets[i];
if (target->idx == ntf->rf_discovery_id) { if (target->logical_idx == ntf->rf_discovery_id) {
/* This target already exists, add the new protocol */ /* This target already exists, add the new protocol */
nci_add_new_protocol(ndev, target, ntf->rf_protocol, nci_add_new_protocol(ndev, target, ntf->rf_protocol,
ntf->rf_tech_and_mode, ntf->rf_tech_and_mode,
...@@ -248,10 +248,10 @@ static void nci_add_new_target(struct nci_dev *ndev, ...@@ -248,10 +248,10 @@ static void nci_add_new_target(struct nci_dev *ndev,
ntf->rf_tech_and_mode, ntf->rf_tech_and_mode,
&ntf->rf_tech_specific_params); &ntf->rf_tech_specific_params);
if (!rc) { if (!rc) {
target->idx = ntf->rf_discovery_id; target->logical_idx = ntf->rf_discovery_id;
ndev->n_targets++; ndev->n_targets++;
pr_debug("target_idx %d, n_targets %d\n", target->idx, pr_debug("logical idx %d, n_targets %d\n", target->logical_idx,
ndev->n_targets); ndev->n_targets);
} }
} }
...@@ -372,10 +372,11 @@ static void nci_target_auto_activated(struct nci_dev *ndev, ...@@ -372,10 +372,11 @@ static void nci_target_auto_activated(struct nci_dev *ndev,
if (rc) if (rc)
return; return;
target->idx = ntf->rf_discovery_id; target->logical_idx = ntf->rf_discovery_id;
ndev->n_targets++; ndev->n_targets++;
pr_debug("target_idx %d, n_targets %d\n", target->idx, ndev->n_targets); pr_debug("logical idx %d, n_targets %d\n",
target->logical_idx, ndev->n_targets);
nfc_targets_found(ndev->nfc_dev, ndev->targets, ndev->n_targets); nfc_targets_found(ndev->nfc_dev, ndev->targets, ndev->n_targets);
} }
......
...@@ -92,6 +92,12 @@ static int rawsock_connect(struct socket *sock, struct sockaddr *_addr, ...@@ -92,6 +92,12 @@ static int rawsock_connect(struct socket *sock, struct sockaddr *_addr,
goto error; goto error;
} }
if (addr->target_idx > dev->target_idx - 1 ||
addr->target_idx < dev->target_idx - dev->n_targets) {
rc = -EINVAL;
goto error;
}
rc = nfc_activate_target(dev, addr->target_idx, addr->nfc_protocol); rc = nfc_activate_target(dev, addr->target_idx, addr->nfc_protocol);
if (rc) if (rc)
goto put_dev; goto put_dev;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册