diff options
author | Samuel Ortiz <sameo@linux.intel.com> | 2012-02-23 01:05:34 +0100 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2012-02-23 01:29:51 +0100 |
commit | 90219f25489ef5bf97ac0a47c75a14426d99a330 (patch) | |
tree | 1b3b51e320a7502eb730f607f7708da20253555d | |
parent | a1aece5260bb4673a158f1fa527a51d8db309d2d (diff) | |
download | neard-90219f25489ef5bf97ac0a47c75a14426d99a330.tar.gz neard-90219f25489ef5bf97ac0a47c75a14426d99a330.tar.bz2 neard-90219f25489ef5bf97ac0a47c75a14426d99a330.zip |
nfctype4: Implement check_presence
-rw-r--r-- | plugins/nfctype4.c | 58 |
1 files changed, 54 insertions, 4 deletions
diff --git a/plugins/nfctype4.c b/plugins/nfctype4.c index f03d2ef..7c21150 100644 --- a/plugins/nfctype4.c +++ b/plugins/nfctype4.c @@ -698,11 +698,61 @@ static int nfctype4_write_tag(uint32_t adapter_idx, uint32_t target_idx, return data_write(adapter_idx, target_idx, ndef, tag, 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 nfctype4_check_presence(uint32_t adapter_idx, + uint32_t target_idx, near_tag_io_cb cb) +{ + struct recv_cookie *cookie; + int err = 0; + + DBG(""); + + cookie = g_try_malloc0(sizeof(struct recv_cookie)); + if (cookie == NULL) { + err = -ENOMEM; + goto out_err; + } + + cookie->adapter_idx = adapter_idx; + cookie->target_idx = target_idx; + cookie->cb = cb; + cookie->tag = NULL; + cookie->read_data = 0;; + + /* Check for V2 type 4 tag */ + err = ISO_Select(iso_appname_v2, ARRAY_SIZE(iso_appname_v2), + 0x4, check_presence, cookie); + if (err < 0) + goto out_err; + + return err; + +out_err: + return t4_cookie_release(err, cookie); +} + static struct near_tag_driver type4_driver = { - .type = NFC_PROTO_ISO14443, - .priority = NEAR_TAG_PRIORITY_DEFAULT, - .read_tag = nfctype4_read_tag, - .add_ndef = nfctype4_write_tag, + .type = NFC_PROTO_ISO14443, + .priority = NEAR_TAG_PRIORITY_DEFAULT, + .read_tag = nfctype4_read_tag, + .add_ndef = nfctype4_write_tag, + .check_presence = nfctype4_check_presence, }; static int nfctype4_init(void) |