From ade5cd40b1aa7a5894242aff37b3985605165cd1 Mon Sep 17 00:00:00 2001 From: Ravi kumar Veeramally Date: Wed, 1 Feb 2012 16:00:20 +0200 Subject: [PATCH] tag: Caching type3 tag manufacturer ID and attribute block Caching manufacturer ID and attribute block in tag data. This data is required while sending write command for Type3 tag. --- include/tag.h | 4 ++++ src/tag.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/tag.h b/include/tag.h index 7044528..3389649 100644 --- a/include/tag.h +++ b/include/tag.h @@ -88,5 +88,9 @@ void near_tag_set_max_ndef_size(struct near_tag *tag, uint16_t size); uint16_t near_tag_get_max_ndef_size(struct near_tag *tag); void near_tag_set_c_apdu_max_size(struct near_tag *tag, uint16_t size); uint16_t near_tag_get_c_apdu_max_size(struct near_tag *tag); +void near_tag_set_idm(struct near_tag *tag, uint8_t *idm, uint8_t len); +uint8_t *near_tag_get_idm(struct near_tag *tag, uint8_t *len); +void near_tag_set_attr_block(struct near_tag *tag, uint8_t *attr, uint8_t len); +uint8_t *near_tag_get_attr_block(struct near_tag *tag, uint8_t *len); #endif diff --git a/src/tag.c b/src/tag.c index ada7b2f..9043ba9 100644 --- a/src/tag.c +++ b/src/tag.c @@ -36,6 +36,9 @@ #define TAG_UID_MAX_LEN 8 +#define TYPE3_IDM_LEN 8 +#define TYPE3_ATTR_BLOCK_SIZE 16 + struct near_tag { uint32_t adapter_idx; uint32_t target_idx; @@ -51,6 +54,11 @@ struct near_tag { GList *records; struct { + uint8_t IDm[TYPE3_IDM_LEN]; + uint8_t attr[TYPE3_ATTR_BLOCK_SIZE]; + } t3; + + struct { uint16_t max_ndef_size; uint16_t c_apdu_max_size; } t4; @@ -235,6 +243,42 @@ uint16_t near_tag_get_c_apdu_max_size(struct near_tag *tag) return tag->t4.c_apdu_max_size; } +void near_tag_set_idm(struct near_tag *tag, uint8_t *idm, uint8_t len) +{ + if (tag == NULL || len > TYPE3_IDM_LEN) + return; + + memset(tag->t3.IDm, 0, TYPE3_IDM_LEN); + memcpy(tag->t3.IDm, idm, len); +} + +uint8_t *near_tag_get_idm(struct near_tag *tag, uint8_t *len) +{ + if (tag == NULL || len == NULL) + return NULL; + + *len = TYPE3_IDM_LEN; + return tag->t3.IDm; +} + +void near_tag_set_attr_block(struct near_tag *tag, uint8_t *attr, uint8_t len) +{ + if (tag == NULL || len > TYPE3_ATTR_BLOCK_SIZE) + return; + + memset(tag->t3.attr, 0, TYPE3_ATTR_BLOCK_SIZE); + memcpy(tag->t3.attr, attr, len); +} + +uint8_t *near_tag_get_attr_block(struct near_tag *tag, uint8_t *len) +{ + if (tag == NULL || len == NULL) + return NULL; + + *len = TYPE3_ATTR_BLOCK_SIZE; + return tag->t3.attr; +} + int near_tag_driver_register(struct near_tag_driver *driver) { DBG(""); -- 2.7.4