3340b25f7a51d59fcd5ad7992b0666578eaf4b6f
[librfid] / rfid_protocol.c
1 /* librfid - layer 3 protocol handler 
2  * (C) 2005 by Harald Welte <laforge@gnumonks.org>
3  */
4
5 /*
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License version 2 
8  *  as published by the Free Software Foundation
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <stdlib.h>
21 #include <unistd.h>
22
23 #include <rfid/rfid_layer2.h>
24 #include <rfid/rfid_protocol.h>
25
26 static struct rfid_protocol *rfid_protocol_list;
27
28 struct rfid_protocol_handle *
29 rfid_protocol_init(struct rfid_layer2_handle *l2h, unsigned int id)
30 {
31         struct rfid_protocol *p;
32
33         for (p = rfid_protocol_list; p; p = p->next)
34                 if (p->id == id)
35                         return p->fn.init(l2h);
36
37         return NULL;
38 }
39
40 int
41 rfid_protocol_open(struct rfid_protocol_handle *ph)
42 {
43         return ph->proto->fn.open(ph);
44 }
45
46 int
47 rfid_protocol_transcieve(struct rfid_protocol_handle *ph,
48                          const unsigned char *tx_buf, unsigned int len,
49                          unsigned char *rx_buf, unsigned int *rx_len,
50                          unsigned int timeout, unsigned int flags)
51 {
52         return ph->proto->fn.transcieve(ph, tx_buf, len, rx_buf, rx_len,
53                                         timeout, flags);
54 }
55
56 int rfid_protocol_fini(struct rfid_protocol_handle *ph)
57 {
58         return ph->proto->fn.fini(ph);
59 }
60
61 int
62 rfid_protocol_close(struct rfid_protocol_handle *ph)
63 {
64         return ph->proto->fn.close(ph);
65 }
66
67 int
68 rfid_protocol_register(struct rfid_protocol *p)
69 {
70         p->next = rfid_protocol_list;
71         rfid_protocol_list = p;
72
73         return 0;
74 }