initial checkin of harald welte's original librfid project
[rfid/librfid.git] / src / rfid_reader.c
1 /* librfid - core reader handling
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 <stdio.h>
22
23 #include <librfid/rfid.h>
24 #include <librfid/rfid_reader.h>
25
26 static struct rfid_reader *rfid_reader_list;
27
28 struct rfid_reader_handle *
29 rfid_reader_open(void *data, unsigned int id)
30 {
31         struct rfid_reader *p;
32
33         for (p = rfid_reader_list; p; p = p->next)
34                 if (p->id == id)
35                         return p->open(data);
36
37         DEBUGP("unable to find matching reader\n");
38         return NULL;
39 }
40
41 int
42 rfid_reader_transcieve(struct rfid_reader_handle *rh,
43                         enum rfid_frametype frametype,
44                          const unsigned char *tx_buf, unsigned int len,
45                          unsigned char *rx_buf, unsigned int *rx_len,
46                          u_int64_t timeout, unsigned int flags)
47 {
48         return rh->reader->transcieve(rh, frametype, tx_buf, len, rx_buf,
49                                       rx_len, timeout, flags);
50 }
51
52 void
53 rfid_reader_close(struct rfid_reader_handle *rh)
54 {
55         rh->reader->close(rh);
56 }
57
58 int
59 rfid_reader_register(struct rfid_reader *r)
60 {
61         r->next = rfid_reader_list;
62         rfid_reader_list = r;
63
64         return 0;
65 }