summaryrefslogtreecommitdiff
path: root/twn3_test.c
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2023-08-26 15:15:07 +0200
committercbdev <cb@cbcdn.com>2023-08-26 15:15:07 +0200
commit2d2c7d80ca6a90d0b0eef469fa4bf68c0d71c722 (patch)
tree9d305eb46e0b9107b152a6df1b87c88f077083f7 /twn3_test.c
parent12cf1472f159b5aaf26d871d88f684f1f46cf856 (diff)
downloadlibtwn-2d2c7d80ca6a90d0b0eef469fa4bf68c0d71c722.tar.gz
libtwn-2d2c7d80ca6a90d0b0eef469fa4bf68c0d71c722.tar.bz2
libtwn-2d2c7d80ca6a90d0b0eef469fa4bf68c0d71c722.zip
Implement basic writing
Diffstat (limited to 'twn3_test.c')
-rw-r--r--twn3_test.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/twn3_test.c b/twn3_test.c
index 734201e..692cd3a 100644
--- a/twn3_test.c
+++ b/twn3_test.c
@@ -11,6 +11,7 @@
int main(int argc, char** argv){
char data[1024];
unsigned u;
+ uint8_t test_block = 4, test_sector = 1;
int device = twn3_open("/dev/ttyACM3");
@@ -44,7 +45,7 @@ int main(int argc, char** argv){
//store a key
//uint8_t key[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
//twn3_sync_storekey(device, 0, 12, key);
-
+
//wait for a single tag
int status;
uint8_t type = tag_none;
@@ -60,6 +61,29 @@ int main(int argc, char** argv){
serial_length = sizeof(serial);
}
+ printf("Authenticating for sector %d\n", test_sector);
+ uint8_t key[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+ twn3_sync_auth(device, 0, 1, test_sector, key);
+ printf("\n");
+
+ printf("Reading block %d\n", test_block);
+ twn3_sync_read(device, 0, test_block, (uint8_t*) data, 16);
+ printf("Block %d data: ", test_block);
+ for(u = 0; u < 16; u++){
+ printf("%02x ", data[u]);
+ }
+ printf("\n\n");
+
+ printf("Incrementing all bytes in block %d\n", test_block);
+ for(u = 0; u < 16; u++){
+ data[u]++;
+ }
+
+ printf("Writing block %d\n", test_block);
+ twn3_sync_write(device, 0, test_block, (uint8_t*) data);
+ printf("\n");
+
+
close(device);
return EXIT_SUCCESS;
}