Prepare RFID compilation in firmware mode
[librfid] / src / rfid.c
1 /* librfid core 
2  *  (C) 2005-2006 by Harald Welte <laforge@gnumonks.org>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License version 2 
6  *  as published by the Free Software Foundation
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17 #include <stdio.h>
18 #include <string.h>
19
20 #include <librfid/rfid_reader.h>
21 #include <librfid/rfid_protocol.h>
22 #include <librfid/rfid_protocol_tcl.h>
23 #include <librfid/rfid_protocol_mifare_ul.h>
24 #include <librfid/rfid_protocol_mifare_classic.h>
25
26 #ifdef LIBRFID_FIRMWARE
27 struct rfid_asic_handle rfid_ah;
28 struct rfid_layer2_handle rfid_l2h;
29 struct rfid_protocol_handle rfid_ph;
30 struct rfid_asic_transport_handle rfid_ath;
31 struct rfid_reader_handle rfid_rh;
32 #endif
33
34 const char *
35 rfid_hexdump(const void *data, unsigned int len)
36 {
37         static char string[1024];
38         unsigned char *d = (unsigned char *) data;
39         unsigned int i, left;
40
41         string[0] = '\0';
42         left = sizeof(string);
43         for (i = 0; len--; i += 3) {
44                 if (i >= sizeof(string) -4)
45                         break;
46                 snprintf(string+i, 4, " %02x", *d++);
47         }
48         return string;
49 }
50
51 #if 0
52 int rfid_setopt(struct rfid_handle *rh, unsigned int level,
53                 unsigned int optname,
54                 const void *opt, unsigned int *optlen)
55 {
56         switch (level) {
57         case RFID_LEVEL_ASIC:
58         case RFID_LEVEL_READER:
59                 return -EINVAL;
60                 break;
61         case RFID_LEVEL_LAYER2:
62                 return rfid_layer2_setopt(optname, opt, optlen);
63                 break;
64         case RFID_LEVEL_LAYER3:
65                 return rfid_layer3_setopt(optname, opt, optlen);
66                 break;
67         default:
68                 return -EINVAL;
69                 break;
70         }
71
72         return 0;
73 }
74
75 int rfid_getopt(struct rfid_handle *rh, unsigned int level,
76                 unsigned int optname,
77                 void *opt, unsigned int *optlen)
78 {
79         switch (level) {
80         case RFID_LEVEL_ASIC:
81         case RFID_LEVEL_READER:
82                 return -EINVAL;
83                 break;
84         case RFID_LEVEL_LAYER2:
85                 return rfid_layer2_getopt(optname, opt, optlen);
86                 break;
87         case RFID_LEVEL_LAYER3:
88                 return rfid_layer3_getopt(optname, opt, optlen);
89                 break;
90         default:
91                 return -EINVAL;
92                 break;
93         }
94
95         return 0;
96 }
97 #endif
98
99 int rfid_init()
100 {
101 #if 0
102         rfid_reader_register(&rfid_reader_cm5121);
103         rfid_reader_register(&rfid_reader_openpcd);
104         rfid_layer2_register(&rfid_layer2_iso14443a);
105         rfid_layer2_register(&rfid_layer2_iso14443b);
106         rfid_protocol_register(&rfid_protocol_tcl);
107         rfid_protocol_register(&rfid_protocol_mful);
108         rfid_protocol_register(&rfid_protocol_mfcl);
109 #endif
110
111         return 0;
112 }
113
114 void rfid_fini()
115 {
116         /* FIXME: implementation */
117 }