]> hackdaworld.org Git - rfid/librfid.git/blob - include/librfid/rfid_protocol.h
more constants fro the cmds
[rfid/librfid.git] / 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_transcieve(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 enum rfid_protocol_id {
31         RFID_PROTOCOL_UNKNOWN,
32         RFID_PROTOCOL_TCL,
33         RFID_PROTOCOL_MIFARE_UL,
34         RFID_PROTOCOL_MIFARE_CLASSIC,
35 };
36
37
38 #ifdef __LIBRFID__
39
40 struct rfid_protocol {
41         struct rfid_protocol *next;
42         unsigned int id;
43         char *name;
44         struct {
45                 struct rfid_protocol_handle *(*init)(struct rfid_layer2_handle *l2h);
46                 int (*open)(struct rfid_protocol_handle *ph);
47                 int (*close)(struct rfid_protocol_handle *ph);
48                 int (*fini)(struct rfid_protocol_handle *ph);
49                 /* transcieve for session based transport protocols */
50                 int (*transcieve)(struct rfid_protocol_handle *ph,
51                                   const unsigned char *tx_buf,
52                                   unsigned int tx_len,
53                                   unsigned char *rx_buf,
54                                   unsigned int *rx_len,
55                                   unsigned int timeout,
56                                   unsigned int flags);
57                 /* read/write for synchronous memory cards */
58                 int (*read)(struct rfid_protocol_handle *ph,
59                             unsigned int page,
60                             unsigned char *rx_data,
61                             unsigned int *rx_len);
62                 int (*write)(struct rfid_protocol_handle *ph,
63                              unsigned int page,
64                              unsigned char *tx_data,
65                              unsigned int tx_len);
66         } fn;
67 };
68
69 int rfid_protocol_register(struct rfid_protocol *p);
70
71 #include <librfid/rfid_protocol_tcl.h>
72 #include <librfid/rfid_protocol_mifare_ul.h>
73 #include <librfid/rfid_protocol_mifare_classic.h>
74
75 struct rfid_protocol_handle {
76         struct rfid_layer2_handle *l2h;
77         struct rfid_protocol *proto;
78         union {
79                 struct tcl_handle tcl;
80         } priv;                         /* priv has to be last, since
81                                          * it could contain additional
82                                          * private data over the end of
83                                          * sizeof(priv). */
84 };
85
86 #endif /* __LIBRFID__ */
87
88 #endif /* _RFID_PROTOCOL_H */