* implement rfid_reader_{get,set}opt()
[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_UNKNOWN  = 0x0f, /* unknown error */
132         RFID_15693_ERR_BLOCK_NA = 0x10, /* block not available */
133         RFID_15693_ERR_BLOCK_LOCKED = 0x11,
134         RFID_15693_ERR_BLOCK_LOCKED_CH = 0x12,
135         RFID_15693_ERR_BLOCK_NOTPROG = 0x13,
136         RFID_15693_ERR_BLOCK_NOTLOCK = 0x14,
137         /* 0xA0 .. 0xDF Custom Command error Codes */
138 };
139
140 /* ISO 15693, Ch. 7.4 */
141 enum iso15693_vicc_states {
142         RFID_15693_STATE_POWER_OFF,
143         RFID_15693_STATE_READY,
144         RFID_15693_STATE_QUIET,
145         RFID_15693_STATE_SELECTED,
146 };
147
148 /* ISO 15693, Ch. 9.1 Table 10*/
149 enum iso15693_commands {
150         /* Mandatory 0x01 .. 0x1f */
151         ISO15693_CMD_INVENTORY          = 0x01,
152         ISO15693_CMD_STAY_QUIET         = 0x02,
153         /* Optional 0x20 .. 0x9f */
154         ISO15693_CMD_READ_BLOCK_SINGLE  = 0x20,
155         ISO15693_CMD_WRITE_BLOCK_SINGLE = 0x21,
156         ISO15693_CMD_LOCK_BLOCK         = 0x22,
157         ISO15693_CMD_READ_BLOCK_MULTI   = 0x23,
158         ISO15693_CMD_WRITE_BLOCK_MULTI  = 0x24,
159         ISO15693_CMD_SELECT             = 0x25,
160         ISO15693_CMD_RESET_TO_READY     = 0x26,
161         ISO15693_CMD_WRITE_AFI          = 0x27,
162         ISO15693_CMD_LOCK_AFI           = 0x28,
163         ISO15693_CMD_WRITE_DSFID        = 0x29,
164         ISO15693_CMD_LOCK_DSFID         = 0x2a,
165         ISO15693_CMD_GET_SYSINFO        = 0x2b,
166         ISO15693_CMD_GET_BLOCK_SECURITY = 0x2c,
167         /* Custom 0xa0 .. 0xdf */
168         ICODE_CMD_INVENTORY_READ        = 0xa0,
169         ICODE_CMD_FAST_INVENTORY_READ   = 0xa1,
170         ICODE_CMD_EAS_SET               = 0xa2,
171         ICODE_CMD_EAS_RESET             = 0xa3,
172         ICODE_CMD_EAS_LOCK              = 0xa4,
173         ICODE_CMD_EAS_ALARM             = 0xa5,
174         /* Proprietary 0xe0 .. 0xff */
175 };
176
177 struct iso15693_anticol_cmd {
178         struct iso15693_request req;
179         unsigned char mask_len;
180         unsigned char mask_bits[ISO15693_UID_LEN];
181         unsigned char current_slot;
182 } __attribute__((packed));
183
184 struct iso15693_anticol_cmd_afi {
185         struct iso15693_request req;
186         unsigned char afi;
187         unsigned char mask_len;
188         unsigned char mask_bits[ISO15693_UID_LEN];
189 } __attribute__((packed));
190
191 /* Figure 11, Chapter 9.2.1 */
192 struct iso15693_anticol_resp {
193         struct iso15693_response resp;
194         u_int8_t dsfid;
195         u_int8_t uuid[ISO15693_UID_LEN];
196 } __attribute__((packed));
197
198
199 #define ISO15693_T_SLOW 0
200 #define ISO15693_T_FAST 1
201 enum iso15693_t {
202         ISO15693_T1,
203         ISO15693_T2,
204         ISO15693_T3,
205         ISO15693_T4,
206         ISO15693_T4_WRITE,
207 };
208
209 /* in microseconds as per Chapter 8.4 table 8 */
210 extern const unsigned int iso15693_timing[2][5];
211
212 #include <librfid/rfid_layer2.h>
213 extern const struct rfid_layer2 rfid_layer2_iso15693;
214
215 #endif /* __LIBRFID__ */
216 #endif /* _ISO15693_H */