summaryrefslogtreecommitdiff
path: root/reader.c
diff options
context:
space:
mode:
Diffstat (limited to 'reader.c')
-rw-r--r--reader.c56
1 files changed, 37 insertions, 19 deletions
diff --git a/reader.c b/reader.c
index 0704fca..f37ade4 100644
--- a/reader.c
+++ b/reader.c
@@ -13,10 +13,8 @@
#define DEFAULT_POLL_TIMEOUT 1000
#define MAX_TAGS 5
-#define FLAG_PRESENT 1
-#define FLAG_FULLY_READ 2
-#define FLAG_UNPROGRAMMED 4
-#define FLAG_ACTIVE 8
+#define FLAG_PRESENT 8
+#define FLAG_ACTIVE 16
static void* reader_module = NULL;
static reader_plugin_handle reader_backend_handle = NULL;
@@ -99,20 +97,32 @@ static int reader_process(){
size_t n = 0;
for(n = 0; n < MAX_TAGS; n++){
if(tags[n].flags & FLAG_PRESENT){
- //TODO verify tag is fully read before pushing
-
if(!(tags[n].flags & FLAG_ACTIVE)){
//new tag
- //TODO
- printf("Tag index %lu detected\n", n);
tags[n].flags |= FLAG_ACTIVE;
+ if(tags[n].flags & FLAG_TAG_LOCKED){
+ printf("A tag was detected (slot %lu), but no key is known\n", n);
+ return 0;
+ }
+ if(tags[n].flags & FLAG_TAG_UNPROGRAMMED){
+ printf("Unprogrammed tag detected (slot %lu)\n", n);
+ //TODO
+ return 0;
+ }
+ if(tags[n].flags & FLAG_TAG_DATA_VALID){
+ printf("Command tag detected (slot %lu)\n", n);
+ //TODO
+ return 0;
+ }
+
+ printf("Tag detected (slot %lu), but no state flags set by reader\n", n);
}
}
else{
if(tags[n].flags & FLAG_ACTIVE){
//tag was removed
//TODO
- printf("Tag index %lu removed\n", n);
+ printf("Tag in slot %lu removed\n", n);
}
//reset all flags
@@ -122,32 +132,40 @@ static int reader_process(){
return 0;
}
-int reader_tag_present(nfc_tag_info_t tag){
+int reader_tag_present(uint8_t flags, nfc_tag_info_t tag){
size_t n = 0;
+ //sanitize input flags
+ flags &= (FLAG_TAG_DATA_VALID | FLAG_TAG_UNPROGRAMMED | FLAG_TAG_LOCKED);
+
//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)){
- //mark still active
+ //mark still present
tags[n].flags |= FLAG_PRESENT;
- //TODO if full data submitted, copy in
-
- //if data has not yet been fully read, request a full read
- return (tags[n].flags & (FLAG_FULLY_READ | FLAG_UNPROGRAMMED)) ? 0 : TAG_READ_REQUESTED;
+ //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));
+ tags[n].flags |= flags;
+ return 0;
+ }
+ //if data has not yet been fully read, request a full read
+ return TAG_READ_REQUESTED;
+ }
+ return 0;
}
}
//if not, add it
for(n = 0; n < MAX_TAGS; n++){
if(!tags[n].flags){
- tags[n].flags |= FLAG_PRESENT;
+ tags[n].flags |= FLAG_PRESENT | flags;
memcpy(&(tags[n].info), &tag, sizeof(tag));
-
- //TODO set FULLY_READ flag if necessary
- return 0;
+ return (tags[n].flags & TAG_STATUS_FLAGS) ? 0 : TAG_READ_REQUESTED;
}
}