add function to set mifare key from internal eeprom
[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 (*setkey_ee)(struct rfid_asic_handle *h,
69                                       const unsigned int addr);
70                         int (*auth)(struct rfid_asic_handle *h, u_int8_t cmd, 
71                                     u_int32_t serno, u_int8_t block);
72                 } mifare_classic;
73         } fn;
74 };
75
76 struct rc632_transport_handle {
77 };
78
79 /* A handle to a specific RC632 chip */
80 struct rfid_asic_rc632_handle {
81         struct rc632_transport_handle th;
82 };
83
84 struct rfid_asic_rc632_impl_proto {
85         u_int8_t mod_conductance;
86         u_int8_t cw_conductance;
87         u_int8_t bitphase;
88         u_int8_t threshold;
89 };
90
91 struct rfid_asic_rc632_impl {
92         u_int32_t mru;          /* maximum receive unit (PICC->PCD) */
93         u_int32_t mtu;          /* maximum transmit unit (PCD->PICC) */
94         //struct rfid_asic_rc632_impl_proto proto[NUM_RFID_PROTOCOLS];
95 };
96
97 extern struct rfid_asic_handle * rc632_open(struct rfid_asic_transport_handle *th);
98 extern void rc632_close(struct rfid_asic_handle *h);
99 extern int rc632_register_dump(struct rfid_asic_handle *handle, u_int8_t *buf);
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