* implement rfid_reader_{get,set}opt()
[librfid] / src / rfid_reader_rc632_common.c
1 /* Shared/Common functions for all RC632 based readers
2  *
3  * (C) 2006-2008 by Harald Welte <laforge@gnumonks.org>
4  *
5  */
6
7 /*
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License version 2 
10  *  as published by the Free Software Foundation
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22
23 #include <errno.h>
24
25 #include <librfid/rfid.h>
26 #include <librfid/rfid_reader.h>
27 #include <librfid/rfid_asic.h>
28 #include <librfid/rfid_asic_rc632.h>
29 #include <librfid/rfid_layer2.h>
30
31 #include "rfid_reader_rc632_common.h"
32
33 int _rdr_rc632_transceive(struct rfid_reader_handle *rh,
34                           enum rfid_frametype frametype,
35                           const unsigned char *tx_data, unsigned int tx_len,
36                           unsigned char *rx_data, unsigned int *rx_len,
37                           u_int64_t timeout, unsigned int flags)
38 {
39         return rh->ah->asic->priv.rc632.fn.transceive(rh->ah, frametype,
40                                                       tx_data, tx_len, 
41                                                       rx_data, rx_len,
42                                                       timeout, flags);
43 }
44
45 int _rdr_rc632_transceive_sf(struct rfid_reader_handle *rh,
46                              unsigned char cmd, struct iso14443a_atqa *atqa)
47 {
48         return rh->ah->asic->priv.rc632.fn.iso14443a.transceive_sf(rh->ah,
49                                                                    cmd,
50                                                                    atqa);
51 }
52
53 int
54 _rdr_rc632_transceive_acf(struct rfid_reader_handle *rh,
55                           struct iso14443a_anticol_cmd *cmd,
56                           unsigned int *bit_of_col)
57 {
58         return rh->ah->asic->priv.rc632.fn.iso14443a.transceive_acf(rh->ah,
59                                                          cmd, bit_of_col);
60 }
61
62 int
63 _rdr_rc632_iso15693_transceive_ac(struct rfid_reader_handle *rh,
64                                   const struct iso15693_anticol_cmd *acf,
65                                   unsigned int acf_len,
66                                   struct iso15693_anticol_resp *resp,
67                                   unsigned int *resp_len, char *bit_of_col)
68 {
69         return  rh->ah->asic->priv.rc632.fn.iso15693.transceive_ac(
70                                         rh->ah, acf, acf_len, resp, resp_len,
71                                         bit_of_col);
72 }
73
74
75 int
76 _rdr_rc632_14443a_set_speed(struct rfid_reader_handle *rh, 
77                             unsigned int tx, unsigned int speed)
78 {
79         u_int8_t rate;
80         
81         DEBUGP("setting rate: ");
82         switch (speed) {
83         case RFID_14443A_SPEED_106K:
84                 rate = 0x00;
85                 DEBUGPC("106K\n");
86                 break;
87         case RFID_14443A_SPEED_212K:
88                 rate = 0x01;
89                 DEBUGPC("212K\n");
90                 break;
91         case RFID_14443A_SPEED_424K:
92                 rate = 0x02;
93                 DEBUGPC("424K\n");
94                 break;
95         case RFID_14443A_SPEED_848K:
96                 rate = 0x03;
97                 DEBUGPC("848K\n");
98                 break;
99         default:
100                 return -EINVAL;
101                 break;
102         }
103         return rh->ah->asic->priv.rc632.fn.iso14443a.set_speed(rh->ah,
104                                                                 tx, rate);
105 }
106
107 int
108 _rdr_rc632_l2_init(struct rfid_reader_handle *rh, enum rfid_layer2_id l2)
109 {
110         return rh->ah->asic->priv.rc632.fn.init(rh->ah, l2);
111 }
112
113 int
114 _rdr_rc632_mifare_setkey(struct rfid_reader_handle *rh, const u_int8_t *key)
115 {
116         return rh->ah->asic->priv.rc632.fn.mifare_classic.setkey(rh->ah, key);
117 }
118
119 int
120 _rdr_rc632_mifare_auth(struct rfid_reader_handle *rh, u_int8_t cmd, 
121                    u_int32_t serno, u_int8_t block)
122 {
123         return rh->ah->asic->priv.rc632.fn.mifare_classic.auth(rh->ah, 
124                                                         cmd, serno, block);
125 }
126
127 int
128 _rdr_rc632_getopt(struct rfid_reader_handle *rh, int optname,
129                   void *optval, unsigned int *optlen)
130 {
131         return -EINVAL;
132 }
133
134 int
135 _rdr_rc632_setopt(struct rfid_reader_handle *rh, int optname,
136                   const void *optval, unsigned int optlen)
137 {
138         unsigned int *val = (unsigned int *)optval;
139
140         if (!optval || optlen < sizeof(*val))
141                 return -EINVAL;
142
143         switch (optname) {
144         case RFID_OPT_RDR_RF_KILL:
145                 if (*val)
146                         return rh->ah->asic->priv.rc632.fn.rf_power(rh->ah, 0);
147                 else
148                         return rh->ah->asic->priv.rc632.fn.rf_power(rh->ah, 1);
149         default:
150                 return -EINVAL;
151         }
152 }