* implement rfid_reader_{get,set}opt()
[librfid] / include / librfid / rfid_layer2.h
1 #ifndef _RFID_LAYER2_H
2 #define _RFID_LAYER2_H
3
4 #include <librfid/rfid.h>
5
6 struct rfid_layer2_handle;
7 struct rfid_reader_handle;
8
9 enum rfid_layer2_id {
10         RFID_LAYER2_NONE,
11         RFID_LAYER2_ISO14443A,
12         RFID_LAYER2_ISO14443B,
13         RFID_LAYER2_ISO15693,
14         RFID_LAYER2_ICODE1,
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         RFID_OPT_LAYER2_PROTO_SUPP      = 0x0002,
22         RFID_OPT_LAYER2_WUP             = 0x0003,
23 };
24
25 struct rfid_layer2_handle *rfid_layer2_init(struct rfid_reader_handle *rh,
26                                             unsigned int id);
27 int rfid_layer2_open(struct rfid_layer2_handle *l2h);
28 int rfid_layer2_transceive(struct rfid_layer2_handle *l2h,
29                            enum rfid_frametype frametype,
30                            const unsigned char *tx_buf, unsigned int tx_len,
31                            unsigned char *rx_buf, unsigned int *rx_len,
32                            u_int64_t timeout, unsigned int flags);
33 int rfid_layer2_close(struct rfid_layer2_handle *l2h);
34 int rfid_layer2_fini(struct rfid_layer2_handle *l2h);
35 int rfid_layer2_getopt(struct rfid_layer2_handle *l2h, int optname,
36                         void *optval, unsigned int *optlen);
37 int rfid_layer2_setopt(struct rfid_layer2_handle *l2h, int optname,
38                         const void *optval, unsigned int optlen);
39 char *rfid_layer2_name(struct rfid_layer2_handle *l2h);
40 #ifdef __LIBRFID__
41
42 #include <librfid/rfid_layer2_iso14443a.h>
43 #include <librfid/rfid_layer2_iso14443b.h>
44 #include <librfid/rfid_layer2_iso15693.h>
45 #include <librfid/rfid_layer2_icode1.h>
46
47 struct rfid_layer2 {
48         unsigned int id;
49         char *name;
50
51         struct {
52                 struct rfid_layer2_handle *(*init)(struct rfid_reader_handle *h);
53                 int (*open)(struct rfid_layer2_handle *h);
54                 int (*transceive)(struct rfid_layer2_handle *h,
55                                   enum rfid_frametype frametype,
56                                   const unsigned char *tx_buf, 
57                                   unsigned int tx_len, unsigned char *rx_buf, 
58                                   unsigned int *rx_len, u_int64_t timeout,
59                                   unsigned int flags);
60                 int (*close)(struct rfid_layer2_handle *h);
61                 int (*fini)(struct rfid_layer2_handle *h);
62                 int (*getopt)(struct rfid_layer2_handle *h,
63                               int optname, void *optval, unsigned int *optlen);
64                 int (*setopt)(struct rfid_layer2_handle *h,
65                               int optname, const void *optval,
66                               unsigned int optlen);
67         } fn;
68 };
69
70 struct rfid_layer2_handle {
71         struct rfid_reader_handle *rh;
72         unsigned char uid[10];  /* triple size 14443a id is 10 bytes */
73         unsigned int uid_len;
74         unsigned int proto_supported;
75         unsigned int flags;
76         union {
77                 struct iso14443a_handle iso14443a;
78                 struct iso14443b_handle iso14443b;
79                 struct iso15693_handle iso15693;
80         } priv;
81         const struct rfid_layer2 *l2;
82 };
83
84 #endif /* __LIBRFID__ */
85
86 #endif