summaryrefslogtreecommitdiff
path: root/src/rfid_reader_rc632_common.c
blob: 101c1f8e359d49dde6f0ef8fca5e7cf966999f7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* Shared/Common functions for all RC632 based readers
 *
 * (C) 2006-2008 by Harald Welte <laforge@gnumonks.org>
 *
 */

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 
 *  as published by the Free Software Foundation
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */


#include <errno.h>

#include <librfid/rfid.h>
#include <librfid/rfid_reader.h>
#include <librfid/rfid_asic.h>
#include <librfid/rfid_asic_rc632.h>
#include <librfid/rfid_layer2.h>

#include "rfid_reader_rc632_common.h"

int _rdr_rc632_transceive(struct rfid_reader_handle *rh,
			  enum rfid_frametype frametype,
			  const unsigned char *tx_data, unsigned int tx_len,
			  unsigned char *rx_data, unsigned int *rx_len,
			  u_int64_t timeout, unsigned int flags)
{
	return rh->ah->asic->priv.rc632.fn.transceive(rh->ah, frametype,
						      tx_data, tx_len, 
						      rx_data, rx_len,
						      timeout, flags);
}

int _rdr_rc632_transceive_sf(struct rfid_reader_handle *rh,
			     unsigned char cmd, struct iso14443a_atqa *atqa)
{
	return rh->ah->asic->priv.rc632.fn.iso14443a.transceive_sf(rh->ah,
								   cmd,
								   atqa);
}

int
_rdr_rc632_transceive_acf(struct rfid_reader_handle *rh,
			  struct iso14443a_anticol_cmd *cmd,
			  unsigned int *bit_of_col)
{
	return rh->ah->asic->priv.rc632.fn.iso14443a.transceive_acf(rh->ah,
							 cmd, bit_of_col);
}

int
_rdr_rc632_iso15693_transceive_ac(struct rfid_reader_handle *rh,
				  const struct iso15693_anticol_cmd *acf,
				  unsigned int acf_len,
				  struct iso15693_anticol_resp *resp,
				  unsigned int *resp_len, char *bit_of_col)
{
	return 	rh->ah->asic->priv.rc632.fn.iso15693.transceive_ac(
					rh->ah, acf, acf_len, resp, resp_len,
					bit_of_col);
}


int
_rdr_rc632_14443a_set_speed(struct rfid_reader_handle *rh, 
			    unsigned int tx, unsigned int speed)
{
	u_int8_t rate;
	
	DEBUGP("setting rate: ");
	switch (speed) {
	case RFID_14443A_SPEED_106K:
		rate = 0x00;
		DEBUGPC("106K\n");
		break;
	case RFID_14443A_SPEED_212K:
		rate = 0x01;
		DEBUGPC("212K\n");
		break;
	case RFID_14443A_SPEED_424K:
		rate = 0x02;
 		DEBUGPC("424K\n");
		break;
	case RFID_14443A_SPEED_848K:
		rate = 0x03;
		DEBUGPC("848K\n");
		break;
	default:
		return -EINVAL;
		break;
	}
	return rh->ah->asic->priv.rc632.fn.iso14443a.set_speed(rh->ah,
								tx, rate);
}

int
_rdr_rc632_l2_init(struct rfid_reader_handle *rh, enum rfid_layer2_id l2)
{
	return rh->ah->asic->priv.rc632.fn.init(rh->ah, l2);
}

int
_rdr_rc632_mifare_setkey(struct rfid_reader_handle *rh, const u_int8_t *key)
{
	return rh->ah->asic->priv.rc632.fn.mifare_classic.setkey(rh->ah, key);
}

int
_rdr_rc632_mifare_setkey_ee(struct rfid_reader_handle *rh, unsigned int addr)
{
	return rh->ah->asic->priv.rc632.fn.mifare_classic.setkey_ee(rh->ah, addr);
}

int
_rdr_rc632_mifare_auth(struct rfid_reader_handle *rh, u_int8_t cmd, 
		   u_int32_t serno, u_int8_t block)
{
	return rh->ah->asic->priv.rc632.fn.mifare_classic.auth(rh->ah, 
							cmd, serno, block);
}

int
_rdr_rc632_getopt(struct rfid_reader_handle *rh, int optname,
		  void *optval, unsigned int *optlen)
{
	return -EINVAL;
}

int
_rdr_rc632_setopt(struct rfid_reader_handle *rh, int optname,
		  const void *optval, unsigned int optlen)
{
	unsigned int *val = (unsigned int *)optval;

	if (!optval || optlen < sizeof(*val))
		return -EINVAL;

	switch (optname) {
	case RFID_OPT_RDR_RF_KILL:
		if (*val)
			return rh->ah->asic->priv.rc632.fn.rf_power(rh->ah, 0);
		else
			return rh->ah->asic->priv.rc632.fn.rf_power(rh->ah, 1);
	default:
		return -EINVAL;
	}
}
personal git repositories of Harald Welte. Your mileage may vary