partial ISO15693 support (based on patch by Bjoern Kaiser)
[librfid] / include / librfid / rfid_asic_rc632.h
1 #ifndef _RFID_ASIC_RC632_H
2 #define _RFID_ASIC_RC632_H
3
4 struct rfid_asic_transport_handle;
5
6 #include <librfid/rfid.h>
7 #include <librfid/rfid_asic.h>
8
9 struct rfid_asic_rc632_transport {
10         struct {
11                 int (*reg_write)(struct rfid_asic_transport_handle *rath,
12                                  u_int8_t reg,
13                                  u_int8_t value);
14                 int (*reg_read)(struct rfid_asic_transport_handle *rath,
15                                 u_int8_t reg,
16                                 u_int8_t *value);
17                 int (*fifo_write)(struct rfid_asic_transport_handle *rath,
18                                   u_int8_t len,
19                                   const u_int8_t *buf,
20                                   u_int8_t flags);
21                 int (*fifo_read)(struct rfid_asic_transport_handle *rath,
22                                  u_int8_t len,
23                                  u_int8_t *buf);
24         } fn;
25 };
26
27 struct rfid_asic_handle;
28
29 struct iso14443a_atqa;
30 struct iso14443a_anticol_cmd;
31 struct iso15693_anticol_cmd;
32
33 struct rfid_asic_rc632 {
34         struct {
35                 int (*power_up)(struct rfid_asic_handle *h);
36                 int (*power_down)(struct rfid_asic_handle *h);
37                 int (*rf_power)(struct rfid_asic_handle *h, int on);
38                 int (*transceive)(struct rfid_asic_handle *h,
39                                   enum rfid_frametype,
40                                   const u_int8_t *tx_buf,
41                                   unsigned int tx_len,
42                                   u_int8_t *rx_buf,
43                                   unsigned int *rx_len,
44                                   u_int64_t timeout,
45                                   unsigned int flags);
46                 struct {
47                         int (*init)(struct rfid_asic_handle *h);
48                         int (*transceive_sf)(struct rfid_asic_handle *h,
49                                              u_int8_t cmd,
50                                              struct iso14443a_atqa *atqa);
51                         int (*transceive_acf)(struct rfid_asic_handle *h,
52                                               struct iso14443a_anticol_cmd *cmd,
53                                               unsigned int *bit_of_col);
54                         int (*set_speed)(struct rfid_asic_handle *h,
55                                          unsigned int tx,
56                                          unsigned int speed);
57                 } iso14443a;
58                 struct {
59                         int (*init)(struct rfid_asic_handle *h);
60                 } iso14443b;
61                 struct {
62                         int (*init)(struct rfid_asic_handle *h);
63                         int (*transceive_ac)(struct rfid_asic_handle *h,
64                                              struct iso15693_anticol_cmd *acf,
65                                              unsigned char *uuid,
66                                              char *bit_of_col);
67                 } iso15693;
68                 struct {
69                         int (*setkey)(struct rfid_asic_handle *h,
70                                       const unsigned char *key);
71                         int (*auth)(struct rfid_asic_handle *h, u_int8_t cmd, 
72                                     u_int32_t serno, u_int8_t block);
73                 } mifare_classic;
74         } fn;
75 };
76
77 struct rc632_transport_handle {
78 };
79
80 /* A handle to a specific RC632 chip */
81 struct rfid_asic_rc632_handle {
82         struct rc632_transport_handle th;
83 };
84
85 struct rfid_asic_rc632_impl_proto {
86         u_int8_t mod_conductance;
87         u_int8_t cw_conductance;
88         u_int8_t bitphase;
89         u_int8_t threshold;
90 };
91
92 struct rfid_asic_rc632_impl {
93         u_int32_t mru;          /* maximum receive unit (PICC->PCD) */
94         u_int32_t mtu;          /* maximum transmit unit (PCD->PICC) */
95         //struct rfid_asic_rc632_impl_proto proto[NUM_RFID_PROTOCOLS];
96 };
97
98 extern struct rfid_asic_handle * rc632_open(struct rfid_asic_transport_handle *th);
99 extern void rc632_close(struct rfid_asic_handle *h);
100
101
102 /* register decoding inlines... */
103 #define DEBUGP_ERROR_FLAG(value) do {DEBUGP("error_flag: 0x%0.2x",value); \
104                                 if (value & RC632_ERR_FLAG_CRC_ERR ) \
105                                         DEBUGPC(", CRC"); \
106                                 if (value & RC632_ERR_FLAG_COL_ERR ) \
107                                         DEBUGPC(", COL"); \
108                                 if (value & RC632_ERR_FLAG_FRAMING_ERR ) \
109                                         DEBUGPC(", FRAMING"); \
110                                 if (value & RC632_ERR_FLAG_PARITY_ERR) \
111                                         DEBUGPC(", PARITY"); \
112                                 if (value & RC632_ERR_FLAG_KEY_ERR ) \
113                                         DEBUGPC(", KEY"); \
114                                 if (value & RC632_ERR_FLAG_ACCESS_ERR ) \
115                                         DEBUGPC(", ACCESS"); \
116                 DEBUGPC("\n");} while (0);
117
118 #define DEBUGP_STATUS_FLAG(foo) do {\
119                         DEBUGP("status_flag: 0x%0.2x",foo); \
120                         if (foo & RC632_STAT_ERR ) \
121                                 DEBUGPC(", ERR"); \
122                         if (foo & RC632_STAT_HIALERT ) \
123                                 DEBUGPC(", Hi"); \
124                         if (foo & RC632_STAT_IRQ ) \
125                                 DEBUGPC(", IRQ"); \
126                         if (foo & RC632_STAT_LOALERT )  \
127                                 DEBUGPC(", Lo"); \
128                         if ((foo & RC632_STAT_MODEM_MASK) == RC632_STAT_MODEM_AWAITINGRX )  \
129                                 DEBUGPC(", mAwaitingRX"); \
130                         if ((foo & RC632_STAT_MODEM_MASK) == RC632_STAT_MODEM_GOTORX )  \
131                                 DEBUGPC(", mGotoRX"); \
132                         if ((foo & RC632_STAT_MODEM_MASK) == RC632_STAT_MODEM_IDLE )  \
133                                 DEBUGPC(", mIdle"); \
134                         if ((foo & RC632_STAT_MODEM_MASK) == RC632_STAT_MODEM_PREPARERX )  \
135                                 DEBUGPC(", mPrepareRX"); \
136                         if ((foo & RC632_STAT_MODEM_MASK) == RC632_STAT_MODEM_RECV )  \
137                                 DEBUGPC(", mRX"); \
138                         if ((foo & RC632_STAT_MODEM_MASK) == RC632_STAT_MODEM_TXDATA )  \
139                                 DEBUGPC(", mTXData"); \
140                         if ((foo & RC632_STAT_MODEM_MASK) == RC632_STAT_MODEM_TXEOF )  \
141                                 DEBUGPC(", mTXeof"); \
142                         if ((foo & RC632_STAT_MODEM_MASK) == RC632_STAT_MODEM_TXSOF )  \
143                                 DEBUGPC(", mTXsof"); \
144             DEBUGPC("\n"); } while (0);
145
146 #define DEBUGP_INTERRUPT_FLAG(foo) do {\
147                 DEBUGP("interrupt_flag: 0x%0.2x",foo); \
148                 if (foo & RC632_INT_HIALERT) \
149                     DEBUGPC(", HiA"); \
150                 if (foo & RC632_INT_LOALERT) \
151                     DEBUGPC(", LoA"); \
152                 if (foo & RC632_INT_IDLE) \
153                     DEBUGPC(", IDLE"); \
154                 if (foo & RC632_INT_RX) \
155                     DEBUGPC(", RX"); \
156                 if (foo & RC632_INT_TX) \
157                     DEBUGPC(", TX"); \
158                 if (foo & RC632_INT_TIMER) \
159                     DEBUGPC(", TIMER"); \
160                 if (foo & RC632_INT_SET) \
161                     DEBUGPC(", SET"); \
162                 DEBUGPC("\n"); } while (0);
163
164 #endif