- add size detection for mifare classic / ultralight
[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 07h = TagIt
8 04h = I.CODE
9 05h = Infineon
10 02h = ST
11 */
12
13 /* protocol definitions */
14
15 #if 0
16 struct rfid_15693_handle;
17
18 struct rfid_layer2_15693t {
19         unsigned char   *name;
20
21         struct {
22                 int (*init)(struct iso15693_handle *handle);
23                 int (*fini)(struct iso15693_handle *handle);
24
25 #if 0
26                 int (*transceive_sf)(struct iso14443a_handle *handle,
27                                      unsigned char cmd,
28                                      struct iso14443a_atqa *atqa);
29                 int (*transceive_acf)(struct iso14443a_handle *handle,
30                                       struct iso14443a_anticol_cmd *acf,
31                                       unsigned int *bit_of_col);
32 #endif
33                 int (*transceive)(struct iso15693_handle *handle,
34                                   const unsigned char *tx_buf,
35                                   unsigned int tx_len,
36                                   unsigned char *rx_buf,
37                                   unsigned int *rx_len);
38         } fn;
39
40         union {
41         } priv;
42 };
43 #endif
44
45 struct iso15693_handle {
46         unsigned int state;
47         unsigned int ask100:1,
48                      out256:1;
49 };
50
51 enum rfid_15693_state {
52         ISO15693_STATE_ERROR,
53         ISO15693_STATE_NONE,
54 };
55
56 enum rfid_15693_opt {
57         RFID_OPT_15693_MOD_DEPTH        = 0x00010001,
58         RFID_OPT_15693_VCD_CODING       = 0x00010002,
59         RFID_OPT_15693_VICC_SUBC        = 0x00010003,
60         RFID_OPT_15693_VICC_SPEED       = 0x00010004,
61 };
62
63 enum rfid_15693_opt_mod_depth {
64         RFID_15693_MOD_10ASK    = 0x01,
65         RFID_15693_MOD_100ASK   = 0x02,
66 };
67
68 enum rfid_15693_opt_vcd_coding {
69         RFID_15693_VCD_CODING_1OUT256   = 0x01,
70         RFID_15693_VCD_CODING_1OUT4     = 0x02,
71 };
72
73 enum rfid_15693_opt_vicc_subc {
74         RFID_15693_VICC_SUBC_SINGLE     = 0x01,
75         RFID_15693_VICC_SUBC_DUAL       = 0x02,
76 };
77
78 enum rfid_15693_opt_vicc_speed {
79         RFID_15693_VICC_SPEED_SLOW      = 0x01,
80         RFID_15693_VICC_SPEED_FAST      = 0x02,
81 };
82
83 #ifdef __LIBRFID__
84
85 #define ISO15693_UID_LEN        8
86 #define ISO15693_CRC_LEN        2
87
88 /* ISO 15693-3, Ch. 7.2 Table 3*/
89 enum iso15693_request_flags {
90         RFID_15693_F_SUBC_TWO    = 0x01,
91         RFID_15693_F_RATE_HIGH   = 0x02,
92         RFID_15693_F_INV_TABLE_5 = 0x04,
93         RFID_15693_F_PROT_OEXT   = 0x08,
94 };
95
96 /* ISO 15693-3, Ch. 7.2 Table 4 */
97 enum iso15693_request_flags_table4 {
98         RFID_15693_F4_SELECTED  =  0x10, /* only VICC in 'select' state */
99         RFID_15693_F4_ADDRESS   =  0x20, /* request is addressed */
100         RFID_15693_F4_CUSTOM    =  0x40,
101 };
102
103 /* ISO 15693-3, Ch. 7.2 Table 5 */
104 enum iso15693_request_flags_table5 {
105         RFID_15693_F5_AFI_PRES  =  0x10, /* AFI is present */
106         RFID_15693_F5_NSLOTS_1  =  0x20, /* only 1 slot (instead of 16) */
107         RFID_15693_F5_CUSTOM    =  0x40,
108 };
109
110 /* ISO 15963-3, Ch. 7.2 Figure 4 */
111 struct iso15693_request {
112         u_int8_t flags;
113         u_int8_t command;
114         u_int8_t data[0];
115 } __attribute__ ((packed));
116
117 /* ISO 15693, Ch. 7.3 Table 6 */
118 enum iso15693_response_flags {
119         RFID_15693_RF_ERROR     = 0x01,
120         RFID_15693_RF_EXTENDED  = 0x08,
121 };
122
123 /* ISO 15693, Ch. 7.3.2 Table 7 */
124 enum iso15693_response_errors {
125         RFID_15693_ERR_NOTSUPP  = 0x01,
126         RFID_15693_ERR_INVALID  = 0x02, /* command not recognized */
127         RFID_15693_ERR_UNKNOWN  = 0x0f, /* unknown error */
128         RFID_15693_ERR_BLOCK_NA = 0x10, /* block not available */
129         RFID_15693_ERR_BLOCK_LOCKED = 0x11,
130         RFID_15693_ERR_BLOCK_LOCKED_CH = 0x12,
131         RFID_15693_ERR_BLOCK_NOTPROG = 0x13,
132         RFID_15693_ERR_BLOCK_NOTLOCK = 0x14,
133 };
134
135 /* ISO 15693, Ch. 7.4 */
136 enum iso15693_vicc_states {
137         RFID_15693_STATE_POWER_OFF,
138         RFID_15693_STATE_READY,
139         RFID_15693_STATE_QUIET,
140         RFID_15693_STATE_SELECTED,
141 };
142
143 /* ISO 15693, Ch. 9.1 Table 10*/
144 enum iso15693_commands {
145         /* Mandatory 0x01 .. 0x1f */
146         ISO15693_CMD_INVENTORY          = 0x01,
147         ISO15693_CMD_STAY_QUIET         = 0x02,
148         /* Optional 0x20 .. 0x9f */
149         ISO15693_CMD_READ_BLOCK_SINGLE  = 0x20,
150         ISO15693_CMD_WRITE_BLOCK_SINGLE = 0x21,
151         ISO15693_CMD_LOCK_BLOCK         = 0x22,
152         ISO15693_CMD_READ_BLOCK_MULTI   = 0x23,
153         ISO15693_CMD_WRITE_BLOCK_MULTI  = 0x24,
154         ISO15693_CMD_SELECT             = 0x25,
155         ISO15693_CMD_RESET_TO_READY     = 0x26,
156         ISO15693_CMD_WRITE_AFI          = 0x27,
157         ISO15693_CMD_LOCK_AFI           = 0x28,
158         ISO15693_CMD_WRITE_DSFID        = 0x29,
159         ISO15693_CMD_LOCK_DSFID         = 0x2a,
160         ISO15693_CMD_GET_SYSINFO        = 0x2b,
161         ISO15693_CMD_GET_BLOCK_SECURITY = 0x2c,
162         /* Custom 0xa0 .. 0xdf */
163         ICODE_CMD_INVENTORY_READ        = 0xa0,
164         ICODE_CMD_FAST_INVENTORY_READ   = 0xa1,
165         ICODE_CMD_EAS_SET               = 0xa2,
166         ICODE_CMD_EAS_RESET             = 0xa3,
167         ICODE_CMD_EAS_LOCK              = 0xa4,
168         ICODE_CMD_EAS_ALARM             = 0xa5,
169         /* Proprietary 0xe0 .. 0xff */
170 };
171
172
173 #include <librfid/rfid_layer2.h>
174 extern const struct rfid_layer2 rfid_layer2_iso15693;
175
176 #endif /* __LIBRFID__ */
177 #endif /* _ISO15693_H */