initial checkin of harald welte's original librfid project
[rfid/librfid.git] / 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 struct rfid_layer2_handle *rfid_layer2_init(struct rfid_reader_handle *rh,
18                                             unsigned int id);
19 int rfid_layer2_open(struct rfid_layer2_handle *l2h);
20 int rfid_layer2_transcieve(struct rfid_layer2_handle *l2h,
21                            enum rfid_frametype frametype,
22                            const unsigned char *tx_buf, unsigned int tx_len,
23                            unsigned char *rx_buf, unsigned int *rx_len,
24                            u_int64_t timeout, unsigned int flags);
25 int rfid_layer2_close(struct rfid_layer2_handle *l2h);
26 int rfid_layer2_fini(struct rfid_layer2_handle *l2h);
27 int rfid_layer2_getopt(struct rfid_layer2_handle *ph, int optname,
28                         void *optval, unsigned int *optlen);
29 int rfid_layer2_setopt(struct rfid_layer2_handle *ph, int optname,
30                         const void *optval, unsigned int optlen);
31
32 #ifdef __LIBRFID__
33
34 #include <librfid/rfid_layer2_iso14443a.h>
35 #include <librfid/rfid_layer2_iso14443b.h>
36 #include <librfid/rfid_layer2_iso15693.h>
37
38 struct rfid_layer2 {
39         unsigned int id;
40         char *name;
41
42         struct {
43                 struct rfid_layer2_handle *(*init)(struct rfid_reader_handle *h);
44                 int (*open)(struct rfid_layer2_handle *h);
45                 int (*transcieve)(struct rfid_layer2_handle *h,
46                                   enum rfid_frametype frametype,
47                                   const unsigned char *tx_buf, 
48                                   unsigned int tx_len, unsigned char *rx_buf, 
49                                   unsigned int *rx_len, u_int64_t timeout,
50                                   unsigned int flags);
51                 int (*close)(struct rfid_layer2_handle *h);
52                 int (*fini)(struct rfid_layer2_handle *h);
53                 int (*getopt)(struct rfid_layer2_handle *h,
54                               int optname, void *optval, unsigned int *optlen);
55                 int (*setopt)(struct rfid_layer2_handle *h,
56                               int optname, const void *optval,
57                               unsigned int optlen);
58         } fn;
59         struct rfid_layer2 *next;
60 };
61
62 struct rfid_layer2_handle {
63         struct rfid_reader_handle *rh;
64         unsigned char uid[10];  /* triple size 14443a id is 10 bytes */
65         unsigned int uid_len;
66         union {
67                 struct iso14443a_handle iso14443a;
68                 struct iso14443b_handle iso14443b;
69                 struct iso15693_handle iso15693;
70         } priv;
71         struct rfid_layer2 *l2;
72 };
73
74 #endif /* __LIBRFID__ */
75
76 #endif