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