summaryrefslogtreecommitdiff
path: root/libtwn3.h
blob: 16e21c80849fbdb849245e37355d4dbea87fd5b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>

typedef enum /*_twn3_tag_type*/ {
	twn3_tag_none = 0x00,
	twn3_tag_mf_light = 0x01,
	twn3_tag_mf_classic_1k = 0x02,
	twn3_tag_mf_classic_4k = 0x03,
	twn3_tag_mf_prox = 0x04,
	twn3_tag_mf_ultralight = 0x05,
	twn3_tag_mf_desfire = 0x06,
	twn3_tag_unknown = 0xFF
} twn3_tag_type_t;

/* Open a device port */
int twn3_open(char* device);

/* Low-level command API */
#define TX_FLAG_BINARY 1

#define RX_FLAG_BINARY 1
#define RX_FLAG_UNTIL_TIMEOUT 2

ssize_t twn3_send_command(int fd, uint8_t flags, uint8_t* data, size_t len);
ssize_t twn3_receive_response(int fd, uint8_t flags, uint8_t* response, size_t max_length);
ssize_t twn3_sync_command(int fd, uint8_t flags, uint8_t* cmd, size_t cmd_len, uint8_t* response, size_t max_length);

/* 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* uid, size_t* length);

//TBD clarify interface
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 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]);