diff options
Diffstat (limited to 'reader.c')
| -rw-r--r-- | reader.c | 43 | 
1 files changed, 43 insertions, 0 deletions
| @@ -12,10 +12,21 @@  #define MAX_PLUGIN_PATH NAME_MAX  #define DEFAULT_POLL_TIMEOUT 1000 + +/* + * Pointers into the tags array are used as stable identifiers + * across the different NFCommander modules, so this array should + * never be reallocated dynamically. + * + * As most readers have a limited number of tags they can power in + * the field, this should not pose a practical limitation. + */  #define MAX_TAGS 5  #define FLAG_PRESENT 16  #define FLAG_ACTIVE 32 +#define FLAG_WRITE_FULL 64 +#define FLAG_WRITE_DYNAMIC 128  static void* reader_module = NULL;  static reader_plugin_handle reader_backend_handle = NULL; @@ -195,6 +206,15 @@ int reader_tag_present(uint8_t flags, nfc_tag_info_t* tag){  				//if data has not yet been fully read, request a full read  				return TAG_READ_REQUESTED;  			} + +			if(tags[n].flags & (FLAG_WRITE_FULL | FLAG_WRITE_DYNAMIC)){ +				flags = tags[n].flags; +				tags[n].flags &= ~(FLAG_WRITE_FULL | FLAG_WRITE_DYNAMIC); +				//this is kinda dangerous as we hand the reader backend our pointers +				memcpy(tag, &(tags[n].info), sizeof(nfc_tag_info_t)); + +				return (flags & FLAG_WRITE_FULL) ? TAG_WRITE_FULL : TAG_WRITE_DYNAMIC; +			}  			return 0;  		}  	} @@ -214,6 +234,23 @@ int reader_tag_present(uint8_t flags, nfc_tag_info_t* tag){  	return 0;  } +int reader_write(nfc_tag_info_t* tag, uint8_t flags){ +	size_t n = 0; + +	for(n = 0; n < MAX_TAGS; n++){ +		if(tag == &(tags[n].info)){ +			if(flags & TAG_WRITE_FULL){ +				tags[n].flags |= FLAG_WRITE_FULL; +			} + +			if(flags & TAG_WRITE_DYNAMIC){ +				tags[n].flags |= FLAG_WRITE_DYNAMIC; +			} +		} +	} +	return 0; +} +  int reader_handle(int fd){  	uint8_t buffer[1024]; @@ -240,6 +277,8 @@ int reader_handle(int fd){  }  void reader_free(){ +	size_t n = 0; +  	if(reader_module){  		dlclose(reader_module);  		reader_backend_handle = NULL; @@ -247,6 +286,10 @@ void reader_free(){  		reader_module = NULL;  	} +	for(n = 0; n < MAX_TAGS; n++){ +		tag_info_free(&(tags[n].info)); +	} +  	core_manage_fd(timer_fd, 0, system_reader);  	close(timer_fd);  	timer_fd = -1; | 
