fix mifare frame crc
[librfid] / rfid_layer2.c
1 /* librfid - layer 2 protocol handler 
2  * (C) 2005 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 <rfid/rfid.h>
24 #include <rfid/rfid_layer2.h>
25
26 static struct rfid_layer2 *rfid_layer2_list;
27
28 struct rfid_layer2_handle *
29 rfid_layer2_init(struct rfid_reader_handle *rh, unsigned int id)
30 {
31         struct rfid_layer2 *p;
32
33         for (p = rfid_layer2_list; p; p = p->next)
34                 if (p->id == id)
35                         return p->fn.init(rh);
36
37         DEBUGP("unable to find matching layer2 protocol\n");
38         return NULL;
39 }
40
41 int
42 rfid_layer2_open(struct rfid_layer2_handle *ph)
43 {
44         return ph->l2->fn.open(ph);
45 }
46
47 int
48 rfid_layer2_transcieve(struct rfid_layer2_handle *ph,
49                         enum rfid_frametype frametype,
50                          const unsigned char *tx_buf, unsigned int len,
51                          unsigned char *rx_buf, unsigned int *rx_len,
52                          u_int64_t timeout, unsigned int flags)
53 {
54         return ph->l2->fn.transcieve(ph, frametype, tx_buf, len, rx_buf,
55                                      rx_len, timeout, flags);
56 }
57
58 int rfid_layer2_fini(struct rfid_layer2_handle *ph)
59 {
60         return ph->l2->fn.fini(ph);
61 }
62
63 int
64 rfid_layer2_close(struct rfid_layer2_handle *ph)
65 {
66         return ph->l2->fn.close(ph);
67 }
68
69 int
70 rfid_layer2_register(struct rfid_layer2 *p)
71 {
72         p->next = rfid_layer2_list;
73         rfid_layer2_list = p;
74
75         return 0;
76 }