use defined hexdump istead of rfid_hexdump
[librfid] / include / librfid / rfid_protocol.h
1 #ifndef _RFID_PROTOCOL_H
2 #define _RFID_PROTOCOL_H
3
4 #include <librfid/rfid_layer2.h>
5
6 struct rfid_protocol_handle;
7
8 struct rfid_protocol_handle *
9 rfid_protocol_init(struct rfid_layer2_handle *l2h, unsigned int id);
10 int rfid_protocol_open(struct rfid_protocol_handle *ph);
11 int rfid_protocol_transceive(struct rfid_protocol_handle *ph,
12                              const unsigned char *tx_buf, unsigned int tx_len,
13                              unsigned char *rx_buf, unsigned int *rx_len,
14                              unsigned int timeout, unsigned int flags);
15 int
16 rfid_protocol_read(struct rfid_protocol_handle *ph,
17                    unsigned int page,
18                    unsigned char *rx_data,
19                    unsigned int *rx_len);
20
21 int
22 rfid_protocol_write(struct rfid_protocol_handle *ph,
23                    unsigned int page,
24                    unsigned char *tx_data,
25                    unsigned int tx_len);
26
27 int rfid_protocol_fini(struct rfid_protocol_handle *ph);
28 int rfid_protocol_close(struct rfid_protocol_handle *ph);
29
30 int rfid_protocol_getopt(struct rfid_protocol_handle *ph, int optname,
31                          void *optval, unsigned int *optlen);
32
33 int rfid_protocol_setopt(struct rfid_protocol_handle *ph, int optname,
34                          const void *optval, unsigned int optlen);
35
36 char *rfid_protocol_name(struct rfid_protocol_handle *ph);
37
38 enum rfid_protocol_id {
39         RFID_PROTOCOL_UNKNOWN,
40         RFID_PROTOCOL_TCL,
41         RFID_PROTOCOL_MIFARE_UL,
42         RFID_PROTOCOL_MIFARE_CLASSIC,
43         RFID_PROTOCOL_ICODE_SLI,
44         RFID_PROTOCOL_TAGIT,
45         NUM_RFID_PROTOCOLS
46 };
47
48 enum rfid_protocol_opt {
49         RFID_OPT_PROTO_ID,
50         RFID_OPT_PROTO_SIZE     = 0x10000001,
51 };
52
53 #ifdef __LIBRFID__
54
55 struct rfid_protocol {
56         unsigned int id;
57         char *name;
58         struct {
59                 struct rfid_protocol_handle *(*init)(struct rfid_layer2_handle *l2h);
60                 int (*open)(struct rfid_protocol_handle *ph);
61                 int (*close)(struct rfid_protocol_handle *ph);
62                 int (*fini)(struct rfid_protocol_handle *ph);
63                 /* transceive for session based transport protocols */
64                 int (*transceive)(struct rfid_protocol_handle *ph,
65                                   const unsigned char *tx_buf,
66                                   unsigned int tx_len,
67                                   unsigned char *rx_buf,
68                                   unsigned int *rx_len,
69                                   unsigned int timeout,
70                                   unsigned int flags);
71                 /* read/write for synchronous memory cards */
72                 int (*read)(struct rfid_protocol_handle *ph,
73                             unsigned int page,
74                             unsigned char *rx_data,
75                             unsigned int *rx_len);
76                 int (*write)(struct rfid_protocol_handle *ph,
77                              unsigned int page,
78                              unsigned char *tx_data,
79                              unsigned int tx_len);
80                 int (*getopt)(struct rfid_protocol_handle *h,
81                               int optname, void *optval, unsigned int *optlen);
82                 int (*setopt)(struct rfid_protocol_handle *h,
83                               int optname, const void *optval,
84                               unsigned int optlen);
85         } fn;
86 };
87
88 #include <librfid/rfid_protocol_tcl.h>
89 #include <librfid/rfid_protocol_mifare_ul.h>
90 #include <librfid/rfid_protocol_mifare_classic.h>
91 #include <librfid/rfid_protocol_tagit.h>
92
93 struct rfid_protocol_handle {
94         struct rfid_layer2_handle *l2h;
95         const struct rfid_protocol *proto;
96         union {
97                 struct tcl_handle tcl;
98         } priv;                         /* priv has to be last, since
99                                          * it could contain additional
100                                          * private data over the end of
101                                          * sizeof(priv). */
102 };
103
104 #endif /* __LIBRFID__ */
105
106 #endif /* _RFID_PROTOCOL_H */