summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2023-08-24 02:06:48 +0200
committercbdev <cb@cbcdn.com>2023-08-24 02:06:48 +0200
commita7c6ecb320ff1ba6ee85767bffde41cfab1a0cd0 (patch)
treeca99949651d0441bf4044f97b21b14c524bd3104
parente9b7a6ef8fc575e0ee4f55ae16169d1917be9dea (diff)
downloadlibtwn-a7c6ecb320ff1ba6ee85767bffde41cfab1a0cd0.tar.gz
libtwn-a7c6ecb320ff1ba6ee85767bffde41cfab1a0cd0.tar.bz2
libtwn-a7c6ecb320ff1ba6ee85767bffde41cfab1a0cd0.zip
Mifare prototypes
-rw-r--r--libtwn3.c5
-rw-r--r--libtwn3.h22
-rw-r--r--twn3_test.c3
3 files changed, 30 insertions, 0 deletions
diff --git a/libtwn3.c b/libtwn3.c
index e07fbb5..4d862cd 100644
--- a/libtwn3.c
+++ b/libtwn3.c
@@ -162,6 +162,11 @@ ssize_t twn3_sync_command(int fd, uint8_t flags, uint8_t* cmd, size_t cmd_len, u
return twn3_receive_response(fd, flags, response, max_length);
}
+int twn3_sync_restart(int fd, uint8_t flags){
+ ssize_t bytes = twn3_sync_command(fd, flags, (uint8_t*) "x", 1, NULL, 0);
+ return (bytes >= 2) ? 0 : -1;
+}
+
int twn3_sync_read_version(int fd, uint8_t flags, char* version, size_t max_length){
ssize_t bytes = twn3_sync_command(fd, flags, (uint8_t*) "v", 1, (uint8_t*) version, max_length);
if(bytes >= max_length){
diff --git a/libtwn3.h b/libtwn3.h
index 63e9b93..b6a8b93 100644
--- a/libtwn3.h
+++ b/libtwn3.h
@@ -2,6 +2,16 @@
#include <stdint.h>
#include <inttypes.h>
+typedef enum /*_twn3_tag_type*/ {
+ tag_mf_light = 0x01,
+ tag_mf_classic_1k = 0x02,
+ tag_mf_classic_4l = 0x03,
+ tag_mf_prox = 0x04,
+ tag_mf_ultralight = 0x05,
+ tag_mf_desfire = 0x06,
+ tag_unknown = 0xFF
+} twn3_tag_type_t;
+
/* Open a device port */
int twn3_open(char* device);
@@ -17,9 +27,21 @@ ssize_t twn3_sync_command(int fd, uint8_t flags, uint8_t* cmd, size_t cmd_len, u
/* Synchronous API */
/* These calls will return data directly, at the cost of blocking execution */
+int twn3_sync_restart(int fd, uint8_t flags);
int twn3_sync_read_version(int fd, uint8_t flags, char* version, size_t max_length);
int twn3_sync_read_eeprom(int fd, uint8_t flags, uint8_t reg, uint8_t* data);
int twn3_sync_write_eeprom(int fd, uint8_t flags, uint8_t reg, uint8_t data);
int twn3_sync_storekey(int fd, uint8_t flags, uint8_t keyid, uint8_t key[6]);
int twn3_sync_antenna(int fd, uint8_t flags, uint8_t enable);
+/* Mifare commands */
+int twn3_sync_select_first(int fd, uint8_t flags, uint8_t* type, uint8_t* serial, size_t* length);
+
+//TBD clarify interface
+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_auth(int fd, uint8_t flags, uint8_t key_a, uint8_t block, uint8_t key[6]);
+int twn3_sync_auth_stored(int fd, uint8_t flags, uint8_t key_a, uint8_t block, uint8_t key_id);
+int twn3_sync_read(int fd, uint8_t flags, uint8_t block, uint8_t* data, size_t max_len);
+int twn3_sync_write(int fd, uint8_t flags, uint8_t block, uint8_t data[16]);
diff --git a/twn3_test.c b/twn3_test.c
index 583deca..cb4fb3a 100644
--- a/twn3_test.c
+++ b/twn3_test.c
@@ -36,6 +36,9 @@ int main(int argc, char** argv){
//write some userdata
twn3_sync_write_eeprom(device, 0, 19, 0xAA);
+ //set ExtendID bit
+ twn3_sync_write_eeprom(device, 0, 5, 0x05);
+
//store a key
uint8_t key[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
twn3_sync_storekey(device, 0, 12, key);