1c536775a76d00bfcd36aef5a64655d1d46f08b9
[librfid] / include / librfid / rfid_reader.h
1 #ifndef _RFID_READER_H
2 #define _RFID_READER_H
3
4 #include <librfid/rfid_asic.h>
5 #include <librfid/rfid_layer2_iso14443a.h>
6 #include <librfid/rfid_layer2_iso15693.h>
7
8 struct rfid_reader_handle;
9
10 /* 0...0xffff = global options, 0x10000...0x1ffff = private options */
11 #define RFID_OPT_RDR_PRIV               0x00010000
12 enum rfid_reader_opt {
13         RFID_OPT_RDR_FW_VERSION         = 0x0001,
14         RFID_OPT_RDR_RF_KILL            = 0x0002,
15 };
16
17
18 struct rfid_reader {
19         char *name;
20         unsigned int id;
21         unsigned int l2_supported;
22         unsigned int proto_supported;
23
24         int (*reset)(struct rfid_reader_handle *h);
25
26         /* open the reader */
27         struct rfid_reader_handle * (*open)(void *data);
28
29         /* Initialize the reader for a given layer 2 */
30         int (*init)(struct rfid_reader_handle *h, enum rfid_layer2_id);
31
32         /* completely close the reader */
33         void (*close)(struct rfid_reader_handle *h);
34
35
36         int (*getopt)(struct rfid_reader_handle *rh, int optname,
37                       void *optval, unsigned int *optlen);
38
39         int (*setopt)(struct rfid_reader_handle *rh, int optname,
40                       const void *optval, unsigned int optlen);
41
42         /* transceive one frame */
43         int (*transceive)(struct rfid_reader_handle *h,
44                           enum rfid_frametype frametype,
45                           const unsigned char *tx_buf, unsigned int tx_len,
46                           unsigned char *rx_buf, unsigned int *rx_len,
47                           u_int64_t timeout, unsigned int flags);
48
49         struct rfid_14443a_reader {
50                 int (*transceive_sf)(struct rfid_reader_handle *h,
51                                      unsigned char cmd,
52                                      struct iso14443a_atqa *atqa);
53                 int (*transceive_acf)(struct rfid_reader_handle *h,
54                                       struct iso14443a_anticol_cmd *cmd,
55                                       unsigned int *bit_of_col);
56                 int (*set_speed)(struct rfid_reader_handle *h,
57                                  unsigned int tx,
58                                  unsigned int speed);
59                 unsigned int speed;
60         } iso14443a;
61         struct rfid_14443b_reader {
62                 unsigned int speed;
63         } iso14443b;
64         struct rfid_15693_reader {
65                 int (*transceive_ac)(struct rfid_reader_handle *h,
66                                      const struct iso15693_anticol_cmd *acf,
67                                      unsigned int acf_len,
68                                      struct iso15693_anticol_resp *resp,
69                                      unsigned int *rx_len, char *bit_of_col);
70         } iso15693;
71         struct rfid_mifare_classic_reader {
72                 int (*setkey)(struct rfid_reader_handle *h, const unsigned char *key);
73                 int (*auth)(struct rfid_reader_handle *h, u_int8_t cmd,
74                             u_int32_t serno, u_int8_t block);
75         } mifare_classic;
76 };
77
78 enum rfid_reader_id {
79         RFID_READER_CM5121,
80         RFID_READER_PEGODA,
81         RFID_READER_OPENPCD,
82         RFID_READER_SPIDEV,
83 };
84
85 struct rfid_reader_handle {
86         struct rfid_asic_handle *ah;
87
88         union {
89
90         } priv;
91         const struct rfid_reader *reader;
92 };
93
94 extern struct rfid_reader_handle *
95 rfid_reader_open(void *data, unsigned int id);
96
97 extern void rfid_reader_close(struct rfid_reader_handle *rh);
98
99 extern int rfid_reader_getopt(struct rfid_reader_handle *rh, int optname,
100                               void *optval, unsigned int *optlen);
101 extern int rfid_reader_setopt(struct rfid_reader_handle *rh, int optname,
102                               const void *optval, unsigned int optlen);
103
104 #endif