1 /* Generic Philips CL RC632 Routines
2 * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <sys/types.h>
30 #include <librfid/rfid_layer2_iso14443a.h>
31 #include <librfid/rfid_protocol_mifare_classic.h>
33 /* initially we use the same values as cm5121 */
34 #define OPENPCD_CW_CONDUCTANCE 0x3f
35 #define OPENPCD_MOD_CONDUCTANCE 0x3f
36 #define OPENPCD_14443A_BITPHASE 0xa9
37 #define OPENPCD_14443A_THRESHOLD 0xff
38 #define OPENPCD_14443B_BITPHASE 0xad
39 #define OPENPCD_14443B_THRESHOLD 0xff
41 #define RC632_TMO_AUTH1 14000
43 #define RC632_TIMEOUT_FUZZ_FACTOR 10
47 #define ENTER() DEBUGPCRF("entering")
48 struct rfid_asic rc632;
51 rc632_set_bit_mask(struct rfid_asic_handle *handle,
52 u_int8_t reg, u_int8_t mask, u_int8_t val)
57 ret = opcd_rc632_reg_read(handle, reg, &tmp);
61 /* if bits are already like we want them, abort */
62 if ((tmp & mask) == val)
65 return opcd_rc632_reg_write(handle, reg, (tmp & ~mask)|(val & mask));
69 rc632_turn_on_rf(struct rfid_asic_handle *handle)
72 return opcd_rc632_set_bits(handle, RC632_REG_TX_CONTROL, 0x03);
76 rc632_turn_off_rf(struct rfid_asic_handle *handle)
79 return opcd_rc632_clear_bits(handle, RC632_REG_TX_CONTROL, 0x03);
83 rc632_power_up(struct rfid_asic_handle *handle)
86 return opcd_rc632_clear_bits(handle, RC632_REG_CONTROL,
87 RC632_CONTROL_POWERDOWN);
91 rc632_power_down(struct rfid_asic_handle *handle)
93 return opcd_rc632_set_bits(handle, RC632_REG_CONTROL,
94 RC632_CONTROL_POWERDOWN);
97 #define MAX_WRITE_LEN 16 /* see Sec. 18.6.1.2 of RC632 Spec Rev. 3.2. */
100 rc632_write_eeprom(struct rfid_asic_handle *handle,
101 u_int16_t addr, u_int8_t len, u_int8_t *data)
103 u_int8_t sndbuf[MAX_WRITE_LEN + 2];
107 if (len > MAX_WRITE_LEN)
114 sndbuf[0] = addr & 0x00ff; /* LSB */
115 sndbuf[1] = addr >> 8; /* MSB */
116 memcpy(&sndbuf[2], data, len);
118 ret = opcd_rc632_fifo_write(handle, len + 2, sndbuf, 0x03);
122 ret = opcd_rc632_reg_write(handle, RC632_REG_COMMAND, RC632_CMD_WRITE_E2);
126 ret = opcd_rc632_reg_read(handle, RC632_REG_ERROR_FLAG, ®);
130 if (reg & RC632_ERR_FLAG_ACCESS_ERR)
134 ret = opcd_rc632_reg_read(handle, RC632_REG_SECONDARY_STATUS, ®);
138 if (reg & RC632_SEC_ST_E2_READY) {
139 /* the E2Write command must be terminated, See sec. 18.6.1.3 */
140 ret = opcd_rc632_reg_write(handle, RC632_REG_COMMAND, RC632_CMD_IDLE);
149 rc632_read_eeprom(struct rfid_asic_handle *handle, u_int16_t addr, u_int8_t len,
156 sndbuf[0] = (addr & 0xff);
157 sndbuf[1] = addr >> 8;
160 ret = opcd_rc632_fifo_write(handle, 3, sndbuf, 0x03);
164 ret = opcd_rc632_reg_write(handle, RC632_REG_COMMAND, RC632_CMD_READ_E2);
170 ret = opcd_rc632_reg_read(handle, RC632_REG_ERROR_FLAG, &err);
171 if (err & RC632_ERR_FLAG_ACCESS_ERR)
174 ret = opcd_rc632_reg_read(handle, RC632_REG_FIFO_LENGTH, &err);
178 ret = opcd_rc632_fifo_read(handle, len, recvbuf);
185 #define RC632_E2_PRODUCT_TYPE 0
186 #define RC632_E2_PRODUCT_SERIAL 8
187 #define RC632_E2_RS_MAX_P 14
189 int rc632_get_serial(struct rfid_asic_handle *handle,
192 return rc632_read_eeprom(handle, RC632_E2_PRODUCT_SERIAL,
193 4, (u_int8_t *)serial);