summaryrefslogtreecommitdiff
path: root/nfcommander.h
blob: 4693a422470cd554152161099bb95de2c61c0688 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>

#ifndef NFCOMMANDER_VERSION
        #define NFCOMMANDER_VERSION "v0.1-dev"
#endif
#define MIN(a,b) (((a) < (b)) ? (a) : (b))

typedef enum {
	tag_unset, /*unknown tag type*/
	tag_unknown, /*unsupported tag*/
	tag_mifare1,
	tag_ntag,
	tag_desfire
} nfc_tag_t;

#define FLAG_TAG_DATA_VALID 1
#define FLAG_TAG_UNPROGRAMMED 2
#define FLAG_TAG_LOCKED 4
#define FLAG_TAG_READONLY 8
#define TAG_STATUS_FLAGS ((FLAG_TAG_DATA_VALID | FLAG_TAG_UNPROGRAMMED | FLAG_TAG_LOCKED))

typedef struct {
	//core identifying properties
	nfc_tag_t type;
	uint8_t uid_length;
	uint8_t uid[10];
	//storage info
	size_t bytes_available;
	size_t granularity;
	//data
	size_t static_length;
	uint8_t* static_data;
	size_t dynamic_length;
	uint8_t* dynamic_data;
	size_t dynamic_max;
} nfc_tag_info_t;

typedef int (*reader_plugin_init)(void);
typedef int (*reader_plugin_handle)(int fd);
typedef int (*reader_plugin_scan)(void);

typedef enum {
	system_control,
	system_reader,
	system_command
} notification_target_t;

int core_manage_fd(int fd, int manage, notification_target_t system);

/*
 * This API is to be called by reader backends to indicate presence of a tag.
 * This can be done as soon as the UID of the tag has been read (ie. before
 * reading EEPROM contents) to check whether the card has already been read.
 *
 * If this API returns TAG_READ_REQUESTED, a full read is requested and the
 * nfc_tag_info_t should be submitted again with the data fully read.
 *
 * If this API returns TAG_WRITE_FULL, the nfc_tag_into_t has been filled
 * with valid data pointers and sizes for both the static and dynamic parts
 * to be written to the tag
 * In the same fashion, if this API returns TAG_WRITE_DYNAMIC, a write for
 * only the dynamic section of the tag is requested.
 */
#define TAG_READ_REQUESTED 1
#define TAG_WRITE_FULL 2
#define TAG_WRITE_DYNAMIC 4
int reader_tag_present(uint8_t flags, nfc_tag_info_t* tag);