add mifare ultralight support (incomplete)
[librfid] / include / rfid / rfid_protocol.h
1 #ifndef _RFID_PROTOCOL_H
2 #define _RFID_PROTOCOL_H
3
4 #include <rfid/rfid_layer2.h>
5
6 #include <rfid/rfid_protocol_tcl.h>
7
8 struct rfid_protocol_handle;
9
10 struct rfid_protocol {
11         struct rfid_protocol *next;
12         unsigned int id;
13         char *name;
14         struct {
15                 struct rfid_protocol_handle *(*init)(struct rfid_layer2_handle *l2h);
16                 int (*open)(struct rfid_protocol_handle *ph);
17                 int (*close)(struct rfid_protocol_handle *ph);
18                 int (*fini)(struct rfid_protocol_handle *ph);
19                 /* transcieve for session based transport protocols */
20                 int (*transcieve)(struct rfid_protocol_handle *ph,
21                                   const unsigned char *tx_buf,
22                                   unsigned int tx_len,
23                                   unsigned char *rx_buf,
24                                   unsigned int *rx_len,
25                                   unsigned int timeout,
26                                   unsigned int flags);
27                 /* read/write for synchronous memory cards */
28                 int (*read)(struct rfid_protocol_handle *ph,
29                             unsigned int page,
30                             unsigned char *rx_data,
31                             unsigned int *rx_len);
32                 int (*write)(struct rfid_protocol_handle *ph,
33                              unsigned int page,
34                              unsigned char *tx_data,
35                              unsigned int tx_len);
36         } fn;
37 };
38
39 struct rfid_protocol_handle {
40         struct rfid_layer2_handle *l2h;
41         struct rfid_protocol *proto;
42         union {
43                 struct tcl_handle tcl;
44         } priv;                         /* priv has to be last, since
45                                          * it could contain additional
46                                          * private data over the end of
47                                          * sizeof(priv). */
48 };
49
50 struct rfid_protocol_handle *
51 rfid_protocol_init(struct rfid_layer2_handle *l2h, unsigned int id);
52 int rfid_protocol_open(struct rfid_protocol_handle *ph);
53 int rfid_protocol_transcieve(struct rfid_protocol_handle *ph,
54                              const unsigned char *tx_buf, unsigned int tx_len,
55                              unsigned char *rx_buf, unsigned int *rx_len,
56                              unsigned int timeout, unsigned int flags);
57 int
58 rfid_protocol_read(struct rfid_protocol_handle *ph,
59                    unsigned int page,
60                    unsigned char *rx_data,
61                    unsigned int rx_len);
62
63 int
64 rfid_protocol_write(struct rfid_protocol_handle *ph,
65                    unsigned int page,
66                    unsigned char *tx_data,
67                    unsigned int tx_len);
68
69 int rfid_protocol_fini(struct rfid_protocol_handle *ph);
70 int rfid_protocol_close(struct rfid_protocol_handle *ph);
71
72 int rfid_protocol_register(struct rfid_protocol *p);
73
74 enum rfid_protocol_id {
75         RFID_PROTOCOL_UNKNOWN,
76         RFID_PROTOCOL_TCL,
77         RFID_PROTOCOL_MIFARE_UL,
78 };
79 #endif