nfctype1: Implement check_presence
authorSamuel Ortiz <sameo@linux.intel.com>
Wed, 22 Feb 2012 23:45:28 +0000 (00:45 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 23 Feb 2012 00:29:51 +0000 (01:29 +0100)
plugins/nfctype1.c

index c62cc02..680feea 100644 (file)
@@ -492,11 +492,50 @@ static int nfctype1_write_tag(uint32_t adapter_idx, uint32_t target_idx,
        return write_nmn_0(adapter_idx, target_idx, ndef, cb);
 }
 
+static int check_presence(uint8_t *resp, int length, void *data)
+{
+       struct recv_cookie *cookie = data;
+       int err = 0;
+
+       DBG("%d", length);
+
+       if (length < 0)
+               err = -EIO;
+
+       if (cookie->cb)
+               cookie->cb(cookie->adapter_idx,
+                               cookie->target_idx, err);
+
+       return 0;
+}
+
+static int nfctype1_check_presence(uint32_t adapter_idx,
+                               uint32_t target_idx, near_tag_io_cb cb)
+{
+       struct type1_cmd t1_cmd;
+       struct recv_cookie *cookie;
+
+       DBG("");
+
+       t1_cmd.cmd = CMD_READ_ALL;     /* Read ALL cmd give 124 bytes */
+       t1_cmd.addr = 0;               /* NA */
+
+       cookie = g_try_malloc0(sizeof(struct recv_cookie));
+       cookie->adapter_idx = adapter_idx;
+       cookie->target_idx = target_idx;
+       cookie->cb = cb;
+
+       return near_adapter_send(adapter_idx, (uint8_t *)&t1_cmd, sizeof(t1_cmd),
+                                                       check_presence, cookie);
+
+}
+
 static struct near_tag_driver type1_driver = {
-       .type     = NFC_PROTO_JEWEL,
-       .priority = NEAR_TAG_PRIORITY_DEFAULT,
-       .read_tag = nfctype1_read_tag,
-       .add_ndef = nfctype1_write_tag,
+       .type           = NFC_PROTO_JEWEL,
+       .priority       = NEAR_TAG_PRIORITY_DEFAULT,
+       .read_tag       = nfctype1_read_tag,
+       .add_ndef       = nfctype1_write_tag,
+       .check_presence = nfctype1_check_presence,
 };
 
 static int nfctype1_init(void)