tag: Caching type3 tag manufacturer ID and attribute block
authorRavi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Wed, 1 Feb 2012 14:00:20 +0000 (16:00 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Fri, 3 Feb 2012 20:05:42 +0000 (21:05 +0100)
Caching manufacturer ID and attribute block in tag data.
This data is required while sending write command for Type3 tag.

include/tag.h
src/tag.c

index 7044528..3389649 100644 (file)
@@ -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
index ada7b2f..9043ba9 100644 (file)
--- 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("");