1 /* librfid - layer 4 protocol handler
2 * (C) 2005-2006 by Harald Welte <laforge@gnumonks.org>
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
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.
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
24 #include <librfid/rfid_layer2.h>
25 #include <librfid/rfid_protocol.h>
27 static const struct rfid_protocol *rfid_protocols[] = {
28 [RFID_PROTOCOL_MIFARE_CLASSIC] = &rfid_protocol_mfcl,
29 [RFID_PROTOCOL_MIFARE_UL] = &rfid_protocol_mful,
30 [RFID_PROTOCOL_TCL] = &rfid_protocol_tcl,
31 [RFID_PROTOCOL_TAGIT] = &rfid_protocol_tagit,
34 struct rfid_protocol_handle *
35 rfid_protocol_init(struct rfid_layer2_handle *l2h, unsigned int id)
37 const struct rfid_protocol *p;
38 struct rfid_protocol_handle *ph = NULL;
40 if (id >= ARRAY_SIZE(rfid_protocols))
43 p = rfid_protocols[id];
56 rfid_protocol_open(struct rfid_protocol_handle *ph)
58 if (ph->proto->fn.open)
59 return ph->proto->fn.open(ph);
64 rfid_protocol_transceive(struct rfid_protocol_handle *ph,
65 const unsigned char *tx_buf, unsigned int len,
66 unsigned char *rx_buf, unsigned int *rx_len,
67 unsigned int timeout, unsigned int flags)
69 return ph->proto->fn.transceive(ph, tx_buf, len, rx_buf, rx_len,
74 rfid_protocol_read(struct rfid_protocol_handle *ph,
76 unsigned char *rx_data,
79 if (ph->proto->fn.read)
80 return ph->proto->fn.read(ph, page, rx_data, rx_len);
86 rfid_protocol_write(struct rfid_protocol_handle *ph,
88 unsigned char *tx_data,
91 if (ph->proto->fn.write)
92 return ph->proto->fn.write(ph, page, tx_data, tx_len);
97 int rfid_protocol_fini(struct rfid_protocol_handle *ph)
99 return ph->proto->fn.fini(ph);
103 rfid_protocol_close(struct rfid_protocol_handle *ph)
105 if (ph->proto->fn.close)
106 return ph->proto->fn.close(ph);
111 rfid_protocol_getopt(struct rfid_protocol_handle *ph, int optname,
112 void *optval, unsigned int *optlen)
114 if (optname >> 16 == 0) {
115 unsigned char *optchar = optval;
123 if (!ph->proto->fn.getopt)
126 return ph->proto->fn.getopt(ph, optname, optval, optlen);
132 rfid_protocol_setopt(struct rfid_protocol_handle *ph, int optname,
133 const void *optval, unsigned int optlen)
135 if (optname >> 16 == 0) {
142 if (!ph->proto->fn.setopt)
145 return ph->proto->fn.setopt(ph, optname, optval, optlen);
150 char *rfid_protocol_name(struct rfid_protocol_handle *ph)
152 return ph->proto->name;