move librfid to new location in repository
[librfid] / rfid_protocol.c
1 /* librfid - layer 3 protocol handler 
2  * (C) 2005 by Harald Welte <laforge@gnumonks.org>
3  */
4
5 #include <stdlib.h>
6 #include <unistd.h>
7
8 #include <rfid/rfid_layer2.h>
9 #include <rfid/rfid_protocol.h>
10
11 static struct rfid_protocol *rfid_protocol_list;
12
13 struct rfid_protocol_handle *
14 rfid_protocol_init(struct rfid_layer2_handle *l2h, unsigned int id)
15 {
16         struct rfid_protocol *p;
17
18         for (p = rfid_protocol_list; p; p = p->next)
19                 if (p->id == id)
20                         return p->fn.init(l2h);
21
22         return NULL;
23 }
24
25 int
26 rfid_protocol_open(struct rfid_protocol_handle *ph)
27 {
28         return ph->proto->fn.open(ph);
29 }
30
31 int
32 rfid_protocol_transcieve(struct rfid_protocol_handle *ph,
33                          const unsigned char *tx_buf, unsigned int len,
34                          unsigned char *rx_buf, unsigned int *rx_len,
35                          unsigned int timeout, unsigned int flags)
36 {
37         return ph->proto->fn.transcieve(ph, tx_buf, len, rx_buf, rx_len,
38                                         timeout, flags);
39 }
40
41 int rfid_protocol_fini(struct rfid_protocol_handle *ph)
42 {
43         return ph->proto->fn.fini(ph);
44 }
45
46 int
47 rfid_protocol_close(struct rfid_protocol_handle *ph)
48 {
49         return ph->proto->fn.close(ph);
50 }
51
52 int
53 rfid_protocol_register(struct rfid_protocol *p)
54 {
55         p->next = rfid_protocol_list;
56         rfid_protocol_list = p;
57
58         return 0;
59 }