summaryrefslogtreecommitdiff
path: root/libtwn3.c
diff options
context:
space:
mode:
Diffstat (limited to 'libtwn3.c')
-rw-r--r--libtwn3.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/libtwn3.c b/libtwn3.c
index 03e56c0..6359995 100644
--- a/libtwn3.c
+++ b/libtwn3.c
@@ -51,7 +51,7 @@ static inline size_t decode_ascii_inplace(uint8_t* data, size_t bytes){
break;
}
if(!isxdigit(data[u * 2]) || !isxdigit(data[u * 2 + 1])){
- return -1;
+ return 0;
}
data[u] = (hex_nibble(data[u * 2]) << 4) | hex_nibble(data[u * 2 + 1]);
}
@@ -268,7 +268,7 @@ int twn3_sync_antenna(int fd, uint8_t flags, uint8_t enable){
return (bytes > 2 && data[0] == 'P') ? 0 : -1;
}
-int twn3_sync_select_first(int fd, uint8_t flags, uint8_t* type, uint8_t* serial, size_t* length){
+int twn3_sync_select_first(int fd, uint8_t flags, uint8_t* type, uint8_t* uid, size_t* length){
char data[30];
size_t u = 0;
ssize_t bytes = twn3_sync_command(fd, flags, (uint8_t*) "s", 1, (uint8_t*) data, sizeof(data));
@@ -279,23 +279,23 @@ int twn3_sync_select_first(int fd, uint8_t flags, uint8_t* type, uint8_t* serial
u = decode_ascii_inplace((uint8_t*) data, bytes - 2);
- //TBD
- if(u % 2){
+ //currently, all uids are either 4, 7, or 10 bytes
+ if(u == 5 || u == 8 || u == 11){
//type tag prepended
*type = data[0];
- memcpy(serial, data + 1, MIN(*length, u - 1));
+ memcpy(uid, data + 1, MIN(*length, u - 1));
*length = u - 1;
}
else{
- memcpy(serial, data, MIN(*length, u));
+ memcpy(uid, data, MIN(*length, u));
*length = u;
}
}
return (bytes > 0) ? 0 : -1;
}
-int twn3_sync_list(int fd, uint8_t flags, uint8_t* type, uint8_t* serial, size_t* length);
-int twn3_sync_select(int fd, uint8_t flags, uint8_t* type, uint8_t* serial, size_t* length);
+int twn3_sync_list(int fd, uint8_t flags, uint8_t* type, uint8_t* uid, size_t* length);
+int twn3_sync_select(int fd, uint8_t flags, uint8_t* type, uint8_t* uid, size_t* length);
int twn3_sync_auth(int fd, uint8_t flags, uint8_t key_a, uint8_t sector, uint8_t key[6]){
char data[20];
@@ -361,7 +361,7 @@ int twn3_sync_write(int fd, uint8_t flags, uint8_t block, uint8_t value[16]){
value[8], value[9], value[10], value[11],
value[12], value[13], value[14], value[15]);
- bytes = twn3_sync_command(fd, flags, (uint8_t*) data, 19, (uint8_t*) data, sizeof(data));
+ bytes = twn3_sync_command(fd, flags, (uint8_t*) data, 35, (uint8_t*) data, sizeof(data));
if(bytes > 0){
if(data[1] != '\r'){
return 0;