- use C99 compiler flags
[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_reader_cm5121.h>
22 #include <librfid/rfid_reader_openpcd.h>
23 #include <librfid/rfid_protocol.h>
24 #include <librfid/rfid_protocol_tcl.h>
25 #include <librfid/rfid_protocol_mifare_ul.h>
26 #include <librfid/rfid_protocol_mifare_classic.h>
27
28 const char *
29 rfid_hexdump(const void *data, unsigned int len)
30 {
31         static char string[1024];
32         unsigned char *d = (unsigned char *) data;
33         unsigned int i, left;
34
35         string[0] = '\0';
36         left = sizeof(string);
37         for (i = 0; len--; i += 3) {
38                 if (i >= sizeof(string) -4)
39                         break;
40                 snprintf(string+i, 4, " %02x", *d++);
41         }
42         return string;
43 }
44
45 #if 0
46 int rfid_setopt(struct rfid_handle *rh, unsigned int level,
47                 unsigned int optname,
48                 const void *opt, unsigned int *optlen)
49 {
50         switch (level) {
51         case RFID_LEVEL_ASIC:
52         case RFID_LEVEL_READER:
53                 return -EINVAL;
54                 break;
55         case RFID_LEVEL_LAYER2:
56                 return rfid_layer2_setopt(optname, opt, optlen);
57                 break;
58         case RFID_LEVEL_LAYER3:
59                 return rfid_layer3_setopt(optname, opt, optlen);
60                 break;
61         default:
62                 return -EINVAL;
63                 break;
64         }
65
66         return 0;
67 }
68
69 int rfid_getopt(struct rfid_handle *rh, unsigned int level,
70                 unsigned int optname,
71                 void *opt, unsigned int *optlen)
72 {
73         switch (level) {
74         case RFID_LEVEL_ASIC:
75         case RFID_LEVEL_READER:
76                 return -EINVAL;
77                 break;
78         case RFID_LEVEL_LAYER2:
79                 return rfid_layer2_getopt(optname, opt, optlen);
80                 break;
81         case RFID_LEVEL_LAYER3:
82                 return rfid_layer3_getopt(optname, opt, optlen);
83                 break;
84         default:
85                 return -EINVAL;
86                 break;
87         }
88
89         return 0;
90 }
91 #endif
92
93 int rfid_init()
94 {
95         rfid_reader_register(&rfid_reader_cm5121);
96         rfid_reader_register(&rfid_reader_openpcd);
97         rfid_layer2_register(&rfid_layer2_iso14443a);
98         rfid_layer2_register(&rfid_layer2_iso14443b);
99         rfid_protocol_register(&rfid_protocol_tcl);
100         rfid_protocol_register(&rfid_protocol_mful);
101         rfid_protocol_register(&rfid_protocol_mfcl);
102
103         return 0;
104 }
105
106 void rfid_fini()
107 {
108         /* FIXME: implementation */
109 }