* implement rfid_reader_{get,set}opt()
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 #include <librfid/rfid_reader_spidev.h>
28
29 static const struct rfid_reader *rfid_readers[] = {
30 #ifdef HAVE_LIBUSB
31 #ifdef ENABLE_CM5121
32         [RFID_READER_CM5121]    = &rfid_reader_cm5121,
33 #endif
34         [RFID_READER_OPENPCD]   = &rfid_reader_openpcd,
35 #endif
36 #ifdef ENABLE_SPIDEV
37         [RFID_READER_SPIDEV]    = &rfid_reader_spidev,
38 #endif
39 };
40
41 struct rfid_reader_handle *
42 rfid_reader_open(void *data, unsigned int id)
43 {
44         const struct rfid_reader *p;
45
46         if (id >= ARRAY_SIZE(rfid_readers)) {
47                 DEBUGP("unable to find matching reader\n");
48                 return NULL;
49         }
50
51         p = rfid_readers[id];
52         if (!p)
53                 return NULL;
54
55         return p->open(data);
56 }
57
58 int
59 rfid_reader_transceive(struct rfid_reader_handle *rh,
60                         enum rfid_frametype frametype,
61                          const unsigned char *tx_buf, unsigned int len,
62                          unsigned char *rx_buf, unsigned int *rx_len,
63                          u_int64_t timeout, unsigned int flags)
64 {
65         return rh->reader->transceive(rh, frametype, tx_buf, len, rx_buf,
66                                       rx_len, timeout, flags);
67 }
68
69 void
70 rfid_reader_close(struct rfid_reader_handle *rh)
71 {
72         rh->reader->close(rh);
73 }
74
75 int
76 rfid_reader_getopt(struct rfid_reader_handle *rh, int optname,
77                    void *optval, unsigned int *optlen)
78 {
79         return rh->reader->getopt(rh, optname, optval, optlen);
80 }
81
82 int rfid_reader_setopt(struct rfid_reader_handle *rh, int optname,
83                        const void *optval, unsigned int optlen)
84 {
85         return rh->reader->setopt(rh, optname, optval, optlen);
86 }