partial ISO15693 support (based on patch by Bjoern Kaiser)
[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 #if 0
33 struct rfid_15693_handle;
34
35 struct rfid_layer2_15693t {
36         unsigned char   *name;
37
38         struct {
39                 int (*init)(struct iso15693_handle *handle);
40                 int (*fini)(struct iso15693_handle *handle);
41
42 #if 0
43                 int (*transceive_sf)(struct iso14443a_handle *handle,
44                                      unsigned char cmd,
45                                      struct iso14443a_atqa *atqa);
46                 int (*transceive_acf)(struct iso14443a_handle *handle,
47                                       struct iso14443a_anticol_cmd *acf,
48                                       unsigned int *bit_of_col);
49 #endif
50                 int (*transceive)(struct iso15693_handle *handle,
51                                   const unsigned char *tx_buf,
52                                   unsigned int tx_len,
53                                   unsigned char *rx_buf,
54                                   unsigned int *rx_len);
55         } fn;
56
57         union {
58         } priv;
59 };
60 #endif
61
62 struct iso15693_handle {
63         unsigned int state;
64         unsigned int ask100:1,
65                      out256:1;
66 };
67
68 enum rfid_15693_state {
69         ISO15693_STATE_ERROR,
70         ISO15693_STATE_NONE,
71         ISO15693_STATE_ANTICOL_RUNNING,
72 };
73
74 enum rfid_15693_opt {
75         RFID_OPT_15693_MOD_DEPTH        = 0x00010001,
76         RFID_OPT_15693_VCD_CODING       = 0x00010002,
77         RFID_OPT_15693_VICC_SUBC        = 0x00010003,
78         RFID_OPT_15693_VICC_SPEED       = 0x00010004,
79 };
80
81 enum rfid_15693_opt_mod_depth {
82         RFID_15693_MOD_10ASK    = 0x01,
83         RFID_15693_MOD_100ASK   = 0x02,
84 };
85
86 enum rfid_15693_opt_vcd_coding {
87         RFID_15693_VCD_CODING_1OUT256   = 0x01,
88         RFID_15693_VCD_CODING_1OUT4     = 0x02,
89 };
90
91 enum rfid_15693_opt_vicc_subc {
92         RFID_15693_VICC_SUBC_SINGLE     = 0x01,
93         RFID_15693_VICC_SUBC_DUAL       = 0x02,
94 };
95
96 enum rfid_15693_opt_vicc_speed {
97         RFID_15693_VICC_SPEED_SLOW      = 0x01,
98         RFID_15693_VICC_SPEED_FAST      = 0x02,
99 };
100
101 #ifdef __LIBRFID__
102
103 #define ISO15693_UID_LEN        8
104 #define ISO15693_CRC_LEN        2
105
106 /* ISO 15693-3, Ch. 7.2 Table 3 */
107 enum iso15693_request_flags {
108         RFID_15693_F_SUBC_TWO    = 0x01,
109         RFID_15693_F_RATE_HIGH   = 0x02,
110         RFID_15693_F_INV_TABLE_5 = 0x04,
111         RFID_15693_F_PROT_OEXT   = 0x08,
112 };
113
114 /* ISO 15693-3, Ch. 7.2 Table 4 */
115 enum iso15693_request_flags_table4 {
116         RFID_15693_F4_SELECTED  =  0x10, /* only VICC in 'select' state */
117         RFID_15693_F4_ADDRESS   =  0x20, /* request is addressed */
118         RFID_15693_F4_CUSTOM    =  0x40,
119 };
120
121 /* ISO 15693-3, Ch. 7.2 Table 5 */
122 enum iso15693_request_flags_table5 {
123         RFID_15693_F5_AFI_PRES  =  0x10, /* AFI is present */
124         RFID_15693_F5_NSLOTS_1  =  0x20, /* only 1 slot (instead of 16) */
125         RFID_15693_F5_CUSTOM    =  0x40,
126 };
127
128 /* ISO 15963-3, Ch. 7.2 Figure 4 */
129 struct iso15693_request {
130         u_int8_t flags;
131         u_int8_t command;
132         u_int8_t data[0];
133 } __attribute__ ((packed));
134
135 /* ISO 15963-3, Ch. 7.2 Figure 5 */
136 struct iso15693_response {
137         u_int8_t flags;
138         u_int8_t data[0];
139 } __attribute__ ((packed));
140
141 /* ISO 15693, Ch. 7.3 Table 6 */
142 enum iso15693_response_flags {
143         RFID_15693_RF_ERROR     = 0x01,
144         RFID_15693_RF_EXTENDED  = 0x08,
145 };
146
147 /* ISO 15693, Ch. 7.3.2 Table 7 */
148 enum iso15693_response_errors {
149         RFID_15693_ERR_NOTSUPP  = 0x01,
150         RFID_15693_ERR_INVALID  = 0x02, /* command not recognized */
151         RFID_15693_ERR_UNKNOWN  = 0x0f, /* unknown error */
152         RFID_15693_ERR_BLOCK_NA = 0x10, /* block not available */
153         RFID_15693_ERR_BLOCK_LOCKED = 0x11,
154         RFID_15693_ERR_BLOCK_LOCKED_CH = 0x12,
155         RFID_15693_ERR_BLOCK_NOTPROG = 0x13,
156         RFID_15693_ERR_BLOCK_NOTLOCK = 0x14,
157         /* 0xA0 .. 0xDF Custom Command error Codes */
158 };
159
160 /* ISO 15693, Ch. 7.4 */
161 enum iso15693_vicc_states {
162         RFID_15693_STATE_POWER_OFF,
163         RFID_15693_STATE_READY,
164         RFID_15693_STATE_QUIET,
165         RFID_15693_STATE_SELECTED,
166 };
167
168 /* ISO 15693, Ch. 9.1 Table 10*/
169 enum iso15693_commands {
170         /* Mandatory 0x01 .. 0x1f */
171         ISO15693_CMD_INVENTORY          = 0x01,
172         ISO15693_CMD_STAY_QUIET         = 0x02,
173         /* Optional 0x20 .. 0x9f */
174         ISO15693_CMD_READ_BLOCK_SINGLE  = 0x20,
175         ISO15693_CMD_WRITE_BLOCK_SINGLE = 0x21,
176         ISO15693_CMD_LOCK_BLOCK         = 0x22,
177         ISO15693_CMD_READ_BLOCK_MULTI   = 0x23,
178         ISO15693_CMD_WRITE_BLOCK_MULTI  = 0x24,
179         ISO15693_CMD_SELECT             = 0x25,
180         ISO15693_CMD_RESET_TO_READY     = 0x26,
181         ISO15693_CMD_WRITE_AFI          = 0x27,
182         ISO15693_CMD_LOCK_AFI           = 0x28,
183         ISO15693_CMD_WRITE_DSFID        = 0x29,
184         ISO15693_CMD_LOCK_DSFID         = 0x2a,
185         ISO15693_CMD_GET_SYSINFO        = 0x2b,
186         ISO15693_CMD_GET_BLOCK_SECURITY = 0x2c,
187         /* Custom 0xa0 .. 0xdf */
188         ICODE_CMD_INVENTORY_READ        = 0xa0,
189         ICODE_CMD_FAST_INVENTORY_READ   = 0xa1,
190         ICODE_CMD_EAS_SET               = 0xa2,
191         ICODE_CMD_EAS_RESET             = 0xa3,
192         ICODE_CMD_EAS_LOCK              = 0xa4,
193         ICODE_CMD_EAS_ALARM             = 0xa5,
194         /* Proprietary 0xe0 .. 0xff */
195 };
196
197 struct iso15693_anticol_cmd {
198         /* iso15693-3 table5 flags*/
199         unsigned char flags;    // SLOTS16 | SLOT1, AFI_PRESENT, OPTION_FLAG
200         unsigned char afi;              // AFI 0 for any
201         unsigned char mask_len;
202         unsigned char mask_bits[ISO15693_UID_LEN];
203         unsigned char current_slot;
204 } __attribute__((packed));
205
206 #include <librfid/rfid_layer2.h>
207 extern const struct rfid_layer2 rfid_layer2_iso15693;
208
209 #endif /* __LIBRFID__ */
210 #endif /* _ISO15693_H */