use defined hexdump istead of rfid_hexdump
[librfid] / include / librfid / rfid_layer2_iso15693.h
1 #ifndef _RFID_ISO15693_H
2 #define _RFID_ISO15693_H
3
4 #include <sys/types.h>
5
6 /*
7  * ISO15693 tag manufacturer codes as found at
8  * http://rfid-handbook.de/forum/read.php?5,437,580#msg-580
9  *
10  * 01h = Motorola
11  * 02h = ST Microelectronics
12  * 03h = Hitachi
13  * 04h = Philips/NXP I.CODE
14  * 05h = Siemens/Infineon
15  * 06h = Cylinc
16  * 07h = Texas Instruments TagIt
17  * 08h = Fujitsu Limited
18  * 09h = Mashushita Electric Industrial
19  * 0Ah = NEC
20  * 0Bh = Oki Electric
21  * 0Ch = Toshiba
22  * 0Dh = Mishubishi Electric
23  * 0Eh = Samsung Electronics
24  * 0Fh = Hyundai Electronics
25  * 10h = LG Semiconductors
26  * 16h = EMarin Microelectronic
27  *
28  */
29
30 /* protocol definitions */
31
32 struct iso15693_handle {
33         unsigned int state;
34         unsigned int vcd_ask100:1,
35                      vicc_two_subc:1,
36                      vicc_fast:1,
37                      single_slot:1,
38                      use_afi:1,
39                      vcd_out256:1;
40         u_int8_t afi;   /* appplication family identifier */
41         u_int8_t dsfid; /* data storage format identifier */
42 };
43
44 enum rfid_15693_state {
45         ISO15693_STATE_ERROR,
46         ISO15693_STATE_NONE,
47         ISO15693_STATE_ANTICOL_RUNNING,
48 };
49
50 enum rfid_15693_opt {
51         RFID_OPT_15693_MOD_DEPTH        = 0x00010001,
52         RFID_OPT_15693_VCD_CODING       = 0x00010002,
53         RFID_OPT_15693_VICC_SUBC        = 0x00010003,
54         RFID_OPT_15693_VICC_SPEED       = 0x00010004,
55         RFID_OPT_15693_VCD_SLOTS        = 0x00010005,
56         RFID_OPT_15693_USE_AFI          = 0x00010006,
57         RFID_OPT_15693_AFI              = 0x00010007,
58         RFID_OPT_15693_DSFID            = 0x00010008,
59 };
60
61 enum rfid_15693_opt_mod_depth {
62         RFID_15693_MOD_10ASK    = 0x01,
63         RFID_15693_MOD_100ASK   = 0x02,
64 };
65
66 enum rfid_15693_opt_vcd_coding {
67         RFID_15693_VCD_CODING_1OUT256   = 0x01,
68         RFID_15693_VCD_CODING_1OUT4     = 0x02,
69 };
70
71 enum rfid_15693_opt_vicc_subc {
72         RFID_15693_VICC_SUBC_SINGLE     = 0x01,
73         RFID_15693_VICC_SUBC_DUAL       = 0x02,
74 };
75
76 enum rfid_15693_opt_vicc_speed {
77         RFID_15693_VICC_SPEED_SLOW      = 0x01,
78         RFID_15693_VICC_SPEED_FAST      = 0x02,
79 };
80
81 #ifdef __LIBRFID__
82
83 #define ISO15693_UID_LEN        8
84 #define ISO15693_CRC_LEN        2
85
86 /* ISO 15693-3, Ch. 7.2 Table 3 */
87 enum iso15693_request_flags {
88         RFID_15693_F_SUBC_TWO    = 0x01,
89         RFID_15693_F_RATE_HIGH   = 0x02,
90         RFID_15693_F_INV_TABLE_5 = 0x04,
91         RFID_15693_F_PROT_OEXT   = 0x08,
92 };
93
94 /* ISO 15693-3, Ch. 7.2 Table 4 */
95 enum iso15693_request_flags_table4 {
96         RFID_15693_F4_SELECTED  =  0x10, /* only VICC in 'select' state */
97         RFID_15693_F4_ADDRESS   =  0x20, /* request is addressed */
98         RFID_15693_F4_CUSTOM    =  0x40,
99 };
100
101 /* ISO 15693-3, Ch. 7.2 Table 5 */
102 enum iso15693_request_flags_table5 {
103         RFID_15693_F5_AFI_PRES  =  0x10, /* AFI is present */
104         RFID_15693_F5_NSLOTS_1  =  0x20, /* only 1 slot (instead of 16) */
105         RFID_15693_F5_CUSTOM    =  0x40,
106 };
107
108 /* ISO 15963-3, Ch. 7.2 Figure 4 */
109 struct iso15693_request {
110         u_int8_t flags;
111         u_int8_t command;
112         u_int8_t data[0];
113 } __attribute__ ((packed));
114
115 /* ISO 15963-3, Ch. 7.2 Figure 5 */
116 struct iso15693_response {
117         u_int8_t flags;
118         u_int8_t data[0];
119 } __attribute__ ((packed));
120
121 /* ISO 15693, Ch. 7.3 Table 6 */
122 enum iso15693_response_flags {
123         RFID_15693_RF_ERROR     = 0x01,
124         RFID_15693_RF_EXTENDED  = 0x08,
125 };
126
127 /* ISO 15693, Ch. 7.3.2 Table 7 */
128 enum iso15693_response_errors {
129         RFID_15693_ERR_NOTSUPP  = 0x01,
130         RFID_15693_ERR_INVALID  = 0x02, /* command not recognized */
131     RFID_15693_ERR_NOTSUPP_OPTION = 0x03, /* option not supported*/
132         RFID_15693_ERR_UNKNOWN  = 0x0f, /* unknown error */
133         RFID_15693_ERR_BLOCK_NA = 0x10, /* block not available */
134         RFID_15693_ERR_BLOCK_LOCKED = 0x11,
135         RFID_15693_ERR_BLOCK_LOCKED_CH = 0x12,
136         RFID_15693_ERR_BLOCK_NOTPROG = 0x13,
137         RFID_15693_ERR_BLOCK_NOTLOCK = 0x14,
138         /* 0xA0 .. 0xDF Custom Command error Codes */
139 };
140
141 /* ISO 15693, Ch. 7.4 */
142 enum iso15693_vicc_states {
143         RFID_15693_STATE_POWER_OFF,
144         RFID_15693_STATE_READY,
145         RFID_15693_STATE_QUIET,
146         RFID_15693_STATE_SELECTED,
147 };
148
149 /* ISO 15693, Ch. 9.1 Table 10*/
150 enum iso15693_commands {
151         /* Mandatory 0x01 .. 0x1f */
152         ISO15693_CMD_INVENTORY          = 0x01,
153         ISO15693_CMD_STAY_QUIET         = 0x02,
154         /* Optional 0x20 .. 0x9f */
155         ISO15693_CMD_READ_BLOCK_SINGLE  = 0x20,
156         ISO15693_CMD_WRITE_BLOCK_SINGLE = 0x21,
157         ISO15693_CMD_LOCK_BLOCK         = 0x22,
158         ISO15693_CMD_READ_BLOCK_MULTI   = 0x23,
159         ISO15693_CMD_WRITE_BLOCK_MULTI  = 0x24,
160         ISO15693_CMD_SELECT             = 0x25,
161         ISO15693_CMD_RESET_TO_READY     = 0x26,
162         ISO15693_CMD_WRITE_AFI          = 0x27,
163         ISO15693_CMD_LOCK_AFI           = 0x28,
164         ISO15693_CMD_WRITE_DSFID        = 0x29,
165         ISO15693_CMD_LOCK_DSFID         = 0x2a,
166         ISO15693_CMD_GET_SYSINFO        = 0x2b,
167         ISO15693_CMD_GET_BLOCK_SECURITY = 0x2c,
168         /* Custom 0xa0 .. 0xdf */
169         ICODE_CMD_INVENTORY_READ        = 0xa0,
170         ICODE_CMD_FAST_INVENTORY_READ   = 0xa1,
171         ICODE_CMD_EAS_SET               = 0xa2,
172         ICODE_CMD_EAS_RESET             = 0xa3,
173         ICODE_CMD_EAS_LOCK              = 0xa4,
174         ICODE_CMD_EAS_ALARM             = 0xa5,
175         /* Proprietary 0xe0 .. 0xff */
176 };
177
178 struct iso15693_anticol_cmd {
179         struct iso15693_request req;
180         unsigned char mask_len;
181         unsigned char mask_bits[ISO15693_UID_LEN];
182         unsigned char current_slot;
183 } __attribute__((packed));
184
185 struct iso15693_anticol_cmd_afi {
186         struct iso15693_request req;
187         unsigned char afi;
188         unsigned char mask_len;
189         unsigned char mask_bits[ISO15693_UID_LEN];
190 } __attribute__((packed));
191
192 /* Figure 11, Chapter 9.2.1 */
193 struct iso15693_anticol_resp {
194         struct iso15693_response resp;
195         u_int8_t dsfid;
196         u_int8_t uuid[ISO15693_UID_LEN];
197 } __attribute__((packed));
198
199
200 #define ISO15693_T_SLOW 0
201 #define ISO15693_T_FAST 1
202 enum iso15693_t {
203         ISO15693_T1,
204         ISO15693_T2,
205         ISO15693_T3,
206         ISO15693_T4,
207         ISO15693_T4_WRITE,
208 };
209
210 /* in microseconds as per Chapter 8.4 table 8 */
211 extern const unsigned int iso15693_timing[2][5];
212
213 #include <librfid/rfid_layer2.h>
214 extern const struct rfid_layer2 rfid_layer2_iso15693;
215
216 #endif /* __LIBRFID__ */
217 #endif /* _ISO15693_H */