1 /* RFID scanning implementation
3 * (C) 2006 by Harald Welte <laforge@gnumonks.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <librfid/rfid.h>
23 #include <librfid/rfid_layer2.h>
24 #include <librfid/rfid_reader.h>
25 #include <librfid/rfid_protocol.h>
27 static struct rfid_layer2_handle *
28 rfid_layer2_scan1(struct rfid_reader_handle *rh, int l2)
30 struct rfid_layer2_handle *l2h;
32 if (rh->reader->l2_supported & (1 << l2)) {
33 l2h = rfid_layer2_init(rh, l2);
36 if (rfid_layer2_open(l2h) < 0) {
37 rfid_layer2_fini(l2h);
46 struct rfid_layer2_handle *
47 rfid_layer2_scan(struct rfid_reader_handle *rh)
49 struct rfid_layer2_handle *l2h;
52 #define RFID_LAYER2_MAX 16
53 for (i = 0; i < RFID_LAYER2_MAX; i++) {
54 DEBUGP("testing l2 %u\n", i);
55 l2h = rfid_layer2_scan1(rh, i);
63 static struct rfid_protocol_handle *
64 rfid_protocol_scan1(struct rfid_layer2_handle *l2h, int proto)
66 struct rfid_protocol_handle *ph;
68 if (l2h->rh->reader->proto_supported & (1 << proto) &&
69 l2h->proto_supported & (1 << proto)) {
70 ph = rfid_protocol_init(l2h, proto);
73 if (rfid_protocol_open(ph) < 0) {
74 rfid_protocol_fini(ph);
83 struct rfid_protocol_handle *
84 rfid_protocol_scan(struct rfid_layer2_handle *l2h)
86 struct rfid_protocol_handle *ph;
89 #define RFID_PROTOCOL_MAX 16
90 for (i = 0; i < RFID_PROTOCOL_MAX; i++) {
91 DEBUGP("testing proto %u\n", i);
92 ph = rfid_protocol_scan1(l2h, i);
100 /* Scan for any RFID transponder within range of the given reader.
101 * Abort after the first successfully found transponder. */
102 int rfid_scan(struct rfid_reader_handle *rh,
103 struct rfid_layer2_handle **l2h,
104 struct rfid_protocol_handle **ph)
106 *l2h = rfid_layer2_scan(rh);
110 *ph = rfid_protocol_scan(*l2h);