summaryrefslogtreecommitdiff
path: root/reader.c
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2023-06-24 21:52:34 +0200
committercbdev <cb@cbcdn.com>2023-06-24 21:52:34 +0200
commitbf9f1fd058c5ca324b2df5223c582ef1ece7a698 (patch)
tree2825cca86cba15661e6a6e28893450c938392810 /reader.c
parente3a80ac2d337b92514f3246dbacb8e4ca7b62d90 (diff)
downloadnfcommander-bf9f1fd058c5ca324b2df5223c582ef1ece7a698.tar.gz
nfcommander-bf9f1fd058c5ca324b2df5223c582ef1ece7a698.tar.bz2
nfcommander-bf9f1fd058c5ca324b2df5223c582ef1ece7a698.zip
Tag data management skeleton
Diffstat (limited to 'reader.c')
-rw-r--r--reader.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/reader.c b/reader.c
index 0ca56cf..5f1316b 100644
--- a/reader.c
+++ b/reader.c
@@ -13,8 +13,8 @@
#define DEFAULT_POLL_TIMEOUT 1000
#define MAX_TAGS 5
-#define FLAG_PRESENT 8
-#define FLAG_ACTIVE 16
+#define FLAG_PRESENT 16
+#define FLAG_ACTIVE 32
static void* reader_module = NULL;
static reader_plugin_handle reader_backend_handle = NULL;
@@ -92,12 +92,12 @@ static void reader_print_tag(nfc_tag_info_t tag){
switch(tag.type){
case tag_unset: type = "UNST"; break;
case tag_unknown: type = "UNKN"; break;
- case tag_mifare1: type = "MFR1"; break;
+ case tag_mifare1: type = "MIFR"; break;
case tag_ntag: type = "NTAG"; break;
case tag_desfire: type = "DESF"; break;
}
- printf("[%s", type);
+ printf("[%s:%lu", type, tag.bytes_available);
for(n = 0; n < tag.uid_length; n++){
printf(" %02X", tag.uid[n]);
}
@@ -111,6 +111,16 @@ static void reader_expire(){
}
}
+static void tag_info_free(nfc_tag_info_t* tag){
+ free(tag->static_data);
+ tag->static_data = NULL;
+ tag->static_length = 0;
+
+ free(tag->dynamic_data);
+ tag->dynamic_data = NULL;
+ tag->dynamic_length = 0;
+}
+
static int reader_process(){
size_t n = 0;
for(n = 0; n < MAX_TAGS; n++){
@@ -144,8 +154,8 @@ static int reader_process(){
}
else{
if(tags[n].flags & FLAG_ACTIVE){
- //tag was removed
- //TODO
+ //tag was removed - free any allocated members
+ tag_info_free(&(tags[n].info));
printf("Tag in slot %lu removed\n", n);
}
@@ -156,7 +166,7 @@ static int reader_process(){
return 0;
}
-int reader_tag_present(uint8_t flags, nfc_tag_info_t tag){
+int reader_tag_present(uint8_t flags, nfc_tag_info_t* tag){
size_t n = 0;
//sanitize input flags
@@ -165,15 +175,15 @@ int reader_tag_present(uint8_t flags, nfc_tag_info_t tag){
//check if tag already known
for(n = 0; n < MAX_TAGS; n++){
if((tags[n].flags & (FLAG_PRESENT | FLAG_ACTIVE))
- && tags[n].info.uid_length == tag.uid_length
- && !memcmp(tags[n].info.uid, tag.uid, tag.uid_length)){
+ && tags[n].info.uid_length == tag->uid_length
+ && !memcmp(tags[n].info.uid, tag->uid, tag->uid_length)){
//mark still present
tags[n].flags |= FLAG_PRESENT;
//if full data submitted, copy in and set flags
if(!(tags[n].flags & TAG_STATUS_FLAGS)){
if(flags & TAG_STATUS_FLAGS){
- memcpy(&(tags[n].info), &tag, sizeof(tag));
+ memcpy(&(tags[n].info), tag, sizeof(nfc_tag_info_t));
tags[n].flags |= flags;
return 0;
}
@@ -188,7 +198,7 @@ int reader_tag_present(uint8_t flags, nfc_tag_info_t tag){
for(n = 0; n < MAX_TAGS; n++){
if(!tags[n].flags){
tags[n].flags |= FLAG_PRESENT | flags;
- memcpy(&(tags[n].info), &tag, sizeof(tag));
+ memcpy(&(tags[n].info), tag, sizeof(nfc_tag_info_t));
return (tags[n].flags & TAG_STATUS_FLAGS) ? 0 : TAG_READ_REQUESTED;
}
}