- use C99 compiler flags
[librfid] / include / librfid / rfid_layer2.h
1 #ifndef _RFID_LAYER2_H
2 #define _RFID_LAYER2_H
3
4 #include <sys/types.h>
5 #include <librfid/rfid.h>
6
7 struct rfid_layer2_handle;
8 struct rfid_reader_handle;
9
10 enum rfid_layer2_id {
11         RFID_LAYER2_NONE,
12         RFID_LAYER2_ISO14443A,
13         RFID_LAYER2_ISO14443B,
14         RFID_LAYER2_ISO15693,
15 };
16
17 /* 0...0xffff = global options, 0x10000...0x1ffff = private options */
18 #define RFID_OPT_L2_PRIV                0x00010000
19 enum rfid_layer2_opt {
20         RFID_OPT_LAYER2_UID             = 0x0001,
21 };
22
23 struct rfid_layer2_handle *rfid_layer2_init(struct rfid_reader_handle *rh,
24                                             unsigned int id);
25 int rfid_layer2_open(struct rfid_layer2_handle *l2h);
26 int rfid_layer2_transceive(struct rfid_layer2_handle *l2h,
27                            enum rfid_frametype frametype,
28                            const unsigned char *tx_buf, unsigned int tx_len,
29                            unsigned char *rx_buf, unsigned int *rx_len,
30                            u_int64_t timeout, unsigned int flags);
31 int rfid_layer2_close(struct rfid_layer2_handle *l2h);
32 int rfid_layer2_fini(struct rfid_layer2_handle *l2h);
33 int rfid_layer2_getopt(struct rfid_layer2_handle *ph, int optname,
34                         void *optval, unsigned int *optlen);
35 int rfid_layer2_setopt(struct rfid_layer2_handle *ph, int optname,
36                         const void *optval, unsigned int optlen);
37
38 #ifdef __LIBRFID__
39
40 #include <librfid/rfid_layer2_iso14443a.h>
41 #include <librfid/rfid_layer2_iso14443b.h>
42 #include <librfid/rfid_layer2_iso15693.h>
43
44 struct rfid_layer2 {
45         unsigned int id;
46         char *name;
47
48         struct {
49                 struct rfid_layer2_handle *(*init)(struct rfid_reader_handle *h);
50                 int (*open)(struct rfid_layer2_handle *h);
51                 int (*transceive)(struct rfid_layer2_handle *h,
52                                   enum rfid_frametype frametype,
53                                   const unsigned char *tx_buf, 
54                                   unsigned int tx_len, unsigned char *rx_buf, 
55                                   unsigned int *rx_len, u_int64_t timeout,
56                                   unsigned int flags);
57                 int (*close)(struct rfid_layer2_handle *h);
58                 int (*fini)(struct rfid_layer2_handle *h);
59                 int (*getopt)(struct rfid_layer2_handle *h,
60                               int optname, void *optval, unsigned int *optlen);
61                 int (*setopt)(struct rfid_layer2_handle *h,
62                               int optname, const void *optval,
63                               unsigned int optlen);
64         } fn;
65         struct rfid_layer2 *next;
66 };
67
68 struct rfid_layer2_handle {
69         struct rfid_reader_handle *rh;
70         unsigned char uid[10];  /* triple size 14443a id is 10 bytes */
71         unsigned int uid_len;
72         unsigned int proto_supported;
73         union {
74                 struct iso14443a_handle iso14443a;
75                 struct iso14443b_handle iso14443b;
76                 struct iso15693_handle iso15693;
77         } priv;
78         struct rfid_layer2 *l2;
79 };
80
81 #endif /* __LIBRFID__ */
82
83 #endif