add support for mifare ultralight
[librfid] / include / rfid / rfid_layer2_iso14443a.h
1 #ifndef _RFID_ISO14443A_H
2 #define _RFID_ISO14443A_H
3
4 #include <sys/types.h>
5
6 /* protocol definitions */
7
8 /* ISO 14443-3, Chapter 6.3.1 */
9 enum iso14443a_sf_cmd {
10         ISO14443A_SF_CMD_REQA           = 0x26,
11         ISO14443A_SF_CMD_WUPA           = 0x52,
12         ISO14443A_SF_CMD_OPT_TIMESLOT   = 0x35,         /* Annex C */
13         /* 40 to 4f and 78 to 7f: proprietary */
14 };
15
16 struct iso14443a_atqa {
17         u_int8_t bf_anticol:5,
18                  rfu1:1,
19                  uid_size:2;
20         u_int8_t proprietary:4,
21                  rfu2:4;
22 };
23
24 #define ISO14443A_HLTA          0x5000
25
26 /* ISO 14443-3, Chapter 6.3.2 */
27 struct iso14443a_anticol_cmd {
28         unsigned char           sel_code;
29         unsigned char           nvb;
30         unsigned char           uid_bits[5];
31 };
32
33 enum iso14443a_anticol_sel_code {
34         ISO14443A_AC_SEL_CODE_CL1       = 0x93,
35         ISO14443A_AC_SEL_CODE_CL2       = 0x95,
36         ISO14443A_AC_SEL_CODE_CL3       = 0x97,
37 };
38
39 #define ISO14443A_BITOFCOL_NONE         0xffffffff
40
41 struct iso14443a_handle;
42
43 struct iso14443a_transport {
44         unsigned char   *name;
45
46         struct {
47                 int (*init)(struct iso14443a_handle *handle);
48                 int (*fini)(struct iso14443a_handle *handle);
49
50                 int (*transcieve_sf)(struct iso14443a_handle *handle,
51                                      unsigned char cmd,
52                                      struct iso14443a_atqa *atqa);
53                 int (*transcieve_acf)(struct iso14443a_handle *handle,
54                                       struct iso14443a_anticol_cmd *acf,
55                                       unsigned int *bit_of_col);
56                 int (*transcieve)(struct iso14443a_handle *handle,
57                                   const unsigned char *tx_buf,
58                                   unsigned int tx_len,
59                                   unsigned char *rx_buf,
60                                   unsigned int *rx_len);
61         } fn;
62
63         union {
64         } priv;
65 };
66
67 struct iso14443a_handle {
68         unsigned int state;
69         unsigned int level;
70         unsigned int tcl_capable;
71         unsigned int uid_len;
72         unsigned char uid[10];          /* Triple size UID is 10 bytes */
73 };
74
75 enum iso14443a_level {
76         ISO14443A_LEVEL_NONE,
77         ISO14443A_LEVEL_CL1,
78         ISO14443A_LEVEL_CL2,
79         ISO14443A_LEVEL_CL3,
80 };
81
82 enum iso14443a_state {
83         ISO14443A_STATE_ERROR,
84         ISO14443A_STATE_NONE,
85         ISO14443A_STATE_REQA_SENT,
86         ISO14443A_STATE_ATQA_RCVD,
87         ISO14443A_STATE_NO_BITFRAME_ANTICOL,
88         ISO14443A_STATE_ANTICOL_RUNNING,
89         ISO14443A_STATE_SELECTED,
90 };
91
92 #include <rfid/rfid_layer2.h>
93 struct rfid_layer2 rfid_layer2_iso14443a;
94
95 #endif /* _ISO14443A_H */