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