- add size detection for mifare classic / ultralight
[librfid] / include / librfid / rfid_layer2_iso14443a.h
1 #ifndef _RFID_ISO14443A_H
2 #define _RFID_ISO14443A_H
3
4 enum rfid_14443a_opt {
5         RFID_OPT_14443A_SPEED_RX        = 0x00010001,
6         RFID_OPT_14443A_SPEED_TX        = 0x00010002,
7         RFID_OPT_14443A_ATQA            = 0x00010003,
8 };
9
10 enum rfid_14443_opt_speed {
11         RFID_14443A_SPEED_106K  = 0x01,
12         RFID_14443A_SPEED_212K  = 0x02,
13         RFID_14443A_SPEED_424K  = 0x04,
14         RFID_14443A_SPEED_848K  = 0x08,
15 };
16
17 #ifdef __LIBRFID__
18
19 #include <sys/types.h>
20
21 /* protocol definitions */
22
23 /* ISO 14443-3, Chapter 6.3.1 */
24 enum iso14443a_sf_cmd {
25         ISO14443A_SF_CMD_REQA           = 0x26,
26         ISO14443A_SF_CMD_WUPA           = 0x52,
27         ISO14443A_SF_CMD_OPT_TIMESLOT   = 0x35,         /* Annex C */
28         /* 40 to 4f and 78 to 7f: proprietary */
29 };
30
31 struct iso14443a_atqa {
32         u_int8_t bf_anticol:5,
33                  rfu1:1,
34                  uid_size:2;
35         u_int8_t proprietary:4,
36                  rfu2:4;
37 } __attribute__((packed));
38
39 #define ISO14443A_HLTA          0x5000
40
41 /* ISO 14443-3, Chapter 6.3.2 */
42 struct iso14443a_anticol_cmd {
43         unsigned char           sel_code;
44         unsigned char           nvb;
45         unsigned char           uid_bits[5];
46 } __attribute__((packed));
47
48 enum iso14443a_anticol_sel_code {
49         ISO14443A_AC_SEL_CODE_CL1       = 0x93,
50         ISO14443A_AC_SEL_CODE_CL2       = 0x95,
51         ISO14443A_AC_SEL_CODE_CL3       = 0x97,
52 };
53
54 #define ISO14443A_BITOFCOL_NONE         0xffffffff
55
56 struct iso14443a_handle {
57         unsigned int state;
58         unsigned int level;
59         unsigned int tcl_capable;
60         struct iso14443a_atqa atqa;
61 };
62
63 enum iso14443a_level {
64         ISO14443A_LEVEL_NONE,
65         ISO14443A_LEVEL_CL1,
66         ISO14443A_LEVEL_CL2,
67         ISO14443A_LEVEL_CL3,
68 };
69
70 enum iso14443a_state {
71         ISO14443A_STATE_ERROR,
72         ISO14443A_STATE_NONE,
73         ISO14443A_STATE_REQA_SENT,
74         ISO14443A_STATE_ATQA_RCVD,
75         ISO14443A_STATE_NO_BITFRAME_ANTICOL,
76         ISO14443A_STATE_ANTICOL_RUNNING,
77         ISO14443A_STATE_SELECTED,
78 };
79
80 /* Section 6.1.2 values in usec, rounded up to next usec */
81 #define ISO14443A_FDT_ANTICOL_LAST1     92      /* 1236 / fc = 91.15 usec */
82 #define ISO14443A_FDT_ANTICOL_LAST0     87      /* 1172 / fc = 86.43 usec */
83
84 #define ISO14443_CARRIER_FREQ   13560000
85 #define ISO14443A_FDT_OTHER_LAST1(n)    (((n*128+84)*1000000)/ISO14443_CARRIER_FREQ)
86
87
88 #include <librfid/rfid_layer2.h>
89 extern const struct rfid_layer2 rfid_layer2_iso14443a;
90
91 #endif /* __LIBRFID__ */
92
93
94 #endif /* _ISO14443A_H */