redesign autoconf/automake infrastructure to support
[librfid] / src / rfid_reader.c
1 /* librfid - core reader handling
2  * (C) 2005-2006 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 #include <librfid/rfid_reader_cm5121.h>
26 #include <librfid/rfid_reader_openpcd.h>
27
28 static const struct rfid_reader *rfid_readers[] = {
29 #ifdef ENABLE_CM5121
30         [RFID_READER_CM5121]    = &rfid_reader_cm5121,
31 #endif
32         [RFID_READER_OPENPCD]   = &rfid_reader_openpcd,
33 };
34
35 struct rfid_reader_handle *
36 rfid_reader_open(void *data, unsigned int id)
37 {
38         const struct rfid_reader *p;
39
40         if (id >= ARRAY_SIZE(rfid_readers)) {
41                 DEBUGP("unable to find matching reader\n");
42                 return NULL;
43         }
44
45         p = rfid_readers[id];
46
47         return p->open(data);
48 }
49
50 int
51 rfid_reader_transceive(struct rfid_reader_handle *rh,
52                         enum rfid_frametype frametype,
53                          const unsigned char *tx_buf, unsigned int len,
54                          unsigned char *rx_buf, unsigned int *rx_len,
55                          u_int64_t timeout, unsigned int flags)
56 {
57         return rh->reader->transceive(rh, frametype, tx_buf, len, rx_buf,
58                                       rx_len, timeout, flags);
59 }
60
61 void
62 rfid_reader_close(struct rfid_reader_handle *rh)
63 {
64         rh->reader->close(rh);
65 }