NFC: Changed target activated state logic
Signed-off-by: Eric Lapuyade <eric.lapuyade@intel.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
diff --git a/net/nfc/core.c b/net/nfc/core.c
index db88429..44a7018 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -95,7 +95,7 @@
goto error;
}
- if (dev->polling || dev->remote_activated) {
+ if (dev->polling || dev->activated_target_idx != NFC_TARGET_IDX_NONE) {
rc = -EBUSY;
goto error;
}
@@ -211,6 +211,8 @@
}
rc = dev->ops->dep_link_up(dev, target_index, comm_mode, gb, gb_len);
+ if (!rc)
+ dev->activated_target_idx = target_index;
error:
device_unlock(&dev->dev);
@@ -246,6 +248,7 @@
rc = dev->ops->dep_link_down(dev);
if (!rc) {
dev->dep_link_up = false;
+ dev->activated_target_idx = NFC_TARGET_IDX_NONE;
nfc_llcp_mac_is_down(dev);
nfc_genl_dep_link_down_event(dev);
}
@@ -290,7 +293,7 @@
rc = dev->ops->activate_target(dev, target_idx, protocol);
if (!rc)
- dev->remote_activated = true;
+ dev->activated_target_idx = target_idx;
error:
device_unlock(&dev->dev);
@@ -318,7 +321,7 @@
}
dev->ops->deactivate_target(dev, target_idx);
- dev->remote_activated = false;
+ dev->activated_target_idx = NFC_TARGET_IDX_NONE;
error:
device_unlock(&dev->dev);
@@ -352,6 +355,18 @@
goto error;
}
+ if (dev->activated_target_idx == NFC_TARGET_IDX_NONE) {
+ rc = -ENOTCONN;
+ kfree_skb(skb);
+ goto error;
+ }
+
+ if (target_idx != dev->activated_target_idx) {
+ rc = -EADDRNOTAVAIL;
+ kfree_skb(skb);
+ goto error;
+ }
+
rc = dev->ops->data_exchange(dev, target_idx, skb, cb, cb_context);
error:
@@ -482,6 +497,7 @@
dev->targets_generation++;
dev->n_targets--;
+ dev->activated_target_idx = NFC_TARGET_IDX_NONE;
if (dev->n_targets) {
memcpy(&dev->targets[i], &dev->targets[i + 1],
@@ -575,6 +591,8 @@
/* first generation must not be 0 */
dev->targets_generation = 1;
+ dev->activated_target_idx = NFC_TARGET_IDX_NONE;
+
return dev;
}
EXPORT_SYMBOL(nfc_allocate_device);