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,
33 struct rfid_protocol_handle *
34 rfid_protocol_init(struct rfid_layer2_handle *l2h, unsigned int id)
36 const struct rfid_protocol *p;
37 struct rfid_protocol_handle *ph = NULL;
39 if (id >= ARRAY_SIZE(rfid_protocols))
42 p = rfid_protocols[id];
55 rfid_protocol_open(struct rfid_protocol_handle *ph)
57 if (ph->proto->fn.open)
58 return ph->proto->fn.open(ph);
63 rfid_protocol_transceive(struct rfid_protocol_handle *ph,
64 const unsigned char *tx_buf, unsigned int len,
65 unsigned char *rx_buf, unsigned int *rx_len,
66 unsigned int timeout, unsigned int flags)
68 return ph->proto->fn.transceive(ph, tx_buf, len, rx_buf, rx_len,
73 rfid_protocol_read(struct rfid_protocol_handle *ph,
75 unsigned char *rx_data,
78 if (ph->proto->fn.read)
79 return ph->proto->fn.read(ph, page, rx_data, rx_len);
85 rfid_protocol_write(struct rfid_protocol_handle *ph,
87 unsigned char *tx_data,
90 if (ph->proto->fn.write)
91 return ph->proto->fn.write(ph, page, tx_data, tx_len);
96 int rfid_protocol_fini(struct rfid_protocol_handle *ph)
98 return ph->proto->fn.fini(ph);
102 rfid_protocol_close(struct rfid_protocol_handle *ph)
104 if (ph->proto->fn.close)
105 return ph->proto->fn.close(ph);
110 rfid_protocol_getopt(struct rfid_protocol_handle *ph, int optname,
111 void *optval, unsigned int *optlen)
113 if (optname >> 16 == 0) {
114 unsigned char *optchar = optval;
122 if (!ph->proto->fn.getopt)
125 return ph->proto->fn.getopt(ph, optname, optval, optlen);
131 rfid_protocol_setopt(struct rfid_protocol_handle *ph, int optname,
132 const void *optval, unsigned int optlen)
134 if (optname >> 16 == 0) {
141 if (!ph->proto->fn.setopt)
144 return ph->proto->fn.setopt(ph, optname, optval, optlen);
149 char *rfid_protocol_name(struct rfid_protocol_handle *ph)
151 return ph->proto->name;