aboutsummaryrefslogtreecommitdiffstats
path: root/net/nfc/core.c
diff options
context:
space:
mode:
authorEric Lapuyade <eric.lapuyade@intel.com>2012-04-10 13:43:11 -0400
committerJohn W. Linville <linville@tuxdriver.com>2012-04-12 15:10:38 -0400
commit144612cacc0b5c230f0b3aebc3a3a53854c332ee (patch)
treeec2b6fa0faf19ca9977c50a84ba9ba21aabe725a /net/nfc/core.c
parent01ae0eea9bed132a9c4a2c207dbf8e05b0051071 (diff)
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>
Diffstat (limited to 'net/nfc/core.c')
-rw-r--r--net/nfc/core.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/net/nfc/core.c b/net/nfc/core.c
index db88429cfc1a..44a701806ba5 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -95,7 +95,7 @@ int nfc_dev_down(struct nfc_dev *dev)
95 goto error; 95 goto error;
96 } 96 }
97 97
98 if (dev->polling || dev->remote_activated) { 98 if (dev->polling || dev->activated_target_idx != NFC_TARGET_IDX_NONE) {
99 rc = -EBUSY; 99 rc = -EBUSY;
100 goto error; 100 goto error;
101 } 101 }
@@ -211,6 +211,8 @@ int nfc_dep_link_up(struct nfc_dev *dev, int target_index, u8 comm_mode)
211 } 211 }
212 212
213 rc = dev->ops->dep_link_up(dev, target_index, comm_mode, gb, gb_len); 213 rc = dev->ops->dep_link_up(dev, target_index, comm_mode, gb, gb_len);
214 if (!rc)
215 dev->activated_target_idx = target_index;
214 216
215error: 217error:
216 device_unlock(&dev->dev); 218 device_unlock(&dev->dev);
@@ -246,6 +248,7 @@ int nfc_dep_link_down(struct nfc_dev *dev)
246 rc = dev->ops->dep_link_down(dev); 248 rc = dev->ops->dep_link_down(dev);
247 if (!rc) { 249 if (!rc) {
248 dev->dep_link_up = false; 250 dev->dep_link_up = false;
251 dev->activated_target_idx = NFC_TARGET_IDX_NONE;
249 nfc_llcp_mac_is_down(dev); 252 nfc_llcp_mac_is_down(dev);
250 nfc_genl_dep_link_down_event(dev); 253 nfc_genl_dep_link_down_event(dev);
251 } 254 }
@@ -290,7 +293,7 @@ int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol)
290 293
291 rc = dev->ops->activate_target(dev, target_idx, protocol); 294 rc = dev->ops->activate_target(dev, target_idx, protocol);
292 if (!rc) 295 if (!rc)
293 dev->remote_activated = true; 296 dev->activated_target_idx = target_idx;
294 297
295error: 298error:
296 device_unlock(&dev->dev); 299 device_unlock(&dev->dev);
@@ -318,7 +321,7 @@ int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx)
318 } 321 }
319 322
320 dev->ops->deactivate_target(dev, target_idx); 323 dev->ops->deactivate_target(dev, target_idx);
321 dev->remote_activated = false; 324 dev->activated_target_idx = NFC_TARGET_IDX_NONE;
322 325
323error: 326error:
324 device_unlock(&dev->dev); 327 device_unlock(&dev->dev);
@@ -352,6 +355,18 @@ int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb,
352 goto error; 355 goto error;
353 } 356 }
354 357
358 if (dev->activated_target_idx == NFC_TARGET_IDX_NONE) {
359 rc = -ENOTCONN;
360 kfree_skb(skb);
361 goto error;
362 }
363
364 if (target_idx != dev->activated_target_idx) {
365 rc = -EADDRNOTAVAIL;
366 kfree_skb(skb);
367 goto error;
368 }
369
355 rc = dev->ops->data_exchange(dev, target_idx, skb, cb, cb_context); 370 rc = dev->ops->data_exchange(dev, target_idx, skb, cb, cb_context);
356 371
357error: 372error:
@@ -482,6 +497,7 @@ int nfc_target_lost(struct nfc_dev *dev, u32 target_idx)
482 497
483 dev->targets_generation++; 498 dev->targets_generation++;
484 dev->n_targets--; 499 dev->n_targets--;
500 dev->activated_target_idx = NFC_TARGET_IDX_NONE;
485 501
486 if (dev->n_targets) { 502 if (dev->n_targets) {
487 memcpy(&dev->targets[i], &dev->targets[i + 1], 503 memcpy(&dev->targets[i], &dev->targets[i + 1],
@@ -575,6 +591,8 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
575 /* first generation must not be 0 */ 591 /* first generation must not be 0 */
576 dev->targets_generation = 1; 592 dev->targets_generation = 1;
577 593
594 dev->activated_target_idx = NFC_TARGET_IDX_NONE;
595
578 return dev; 596 return dev;
579} 597}
580EXPORT_SYMBOL(nfc_allocate_device); 598EXPORT_SYMBOL(nfc_allocate_device);