NFC: digital: Set current target active on activate_target() call
authorThierry Escande <thierry.escande@linux.intel.com>
Mon, 6 Jan 2014 22:34:37 +0000 (23:34 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Tue, 7 Jan 2014 17:48:12 +0000 (18:48 +0100)
The curr_protocol field of nfc_digital_dev structure used to determine
if a target is currently active was set too soon, immediately when a
target is found. This is not good since there is no other way than
deactivate_target() to reset curr_protocol and if activate_target() is
not called, the target remains active and it's not possible to put the
device in poll mode anymore.

With this patch curr_protocol is set when nfc core activates a target,
puts a device up, or when an ATR_REQ is received in target mode.

Signed-off-by: Thierry Escande <thierry.escande@linux.intel.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
net/nfc/digital_core.c
net/nfc/digital_dep.c

index 09fc95439955052c2b2f6f178ae0ea421f3fab24..c129d1571ca6c55281807781aeb803d6f9f9415b 100644 (file)
@@ -339,7 +339,6 @@ int digital_target_found(struct nfc_digital_dev *ddev,
        pr_debug("rf_tech=%d, protocol=%d\n", rf_tech, protocol);
 
        ddev->curr_rf_tech = rf_tech;
-       ddev->curr_protocol = protocol;
 
        if (DIGITAL_DRV_CAPS_IN_CRC(ddev)) {
                ddev->skb_add_crc = digital_skb_add_crc_none;
@@ -541,8 +540,14 @@ static int digital_dep_link_up(struct nfc_dev *nfc_dev,
                               __u8 comm_mode, __u8 *gb, size_t gb_len)
 {
        struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
+       int rc;
+
+       rc = digital_in_send_atr_req(ddev, target, comm_mode, gb, gb_len);
 
-       return digital_in_send_atr_req(ddev, target, comm_mode, gb, gb_len);
+       if (!rc)
+               ddev->curr_protocol = NFC_PROTO_NFC_DEP;
+
+       return rc;
 }
 
 static int digital_dep_link_down(struct nfc_dev *nfc_dev)
@@ -557,6 +562,20 @@ static int digital_dep_link_down(struct nfc_dev *nfc_dev)
 static int digital_activate_target(struct nfc_dev *nfc_dev,
                                   struct nfc_target *target, __u32 protocol)
 {
+       struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
+
+       if (ddev->poll_tech_count) {
+               pr_err("Can't activate a target while polling\n");
+               return -EBUSY;
+       }
+
+       if (ddev->curr_protocol) {
+               pr_err("A target is already active\n");
+               return -EBUSY;
+       }
+
+       ddev->curr_protocol = protocol;
+
        return 0;
 }
 
@@ -565,6 +584,11 @@ static void digital_deactivate_target(struct nfc_dev *nfc_dev,
 {
        struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
 
+       if (!ddev->curr_protocol) {
+               pr_err("No active target\n");
+               return;
+       }
+
        ddev->curr_protocol = 0;
 }
 
index 470a0b4016edb346c62c213664590acd8b86d607..562bec9ad8d9db7f3e964950920539ea90e5acd4 100644 (file)
@@ -681,6 +681,8 @@ void digital_tg_recv_atr_req(struct nfc_digital_dev *ddev, void *arg,
                ddev->skb_check_crc = digital_skb_check_crc_none;
        }
 
+       ddev->curr_protocol = NFC_PROTO_NFC_DEP_MASK;
+
        rc = ddev->skb_check_crc(resp);
        if (rc) {
                PROTOCOL_ERR("14.4.1.6");
This page took 0.027374 seconds and 5 git commands to generate.