*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <unistd.h>
#include "rfid_iso14443_common.h"
#include "rc632.h"
-//#include "rc632_14443a.h"
+#ifdef __MINGW32__
+#include "usleep.h"
+#endif/*__MINGW32__*/
-#define RC632_TMO_AUTH1 14000
+#define RC632_TMO_AUTH1 140
#define ENTER() DEBUGP("entering\n")
const struct rfid_asic rc632;
if (ret < 0)
return ret;
+ /* switch off rf */
+ ret = rc632_turn_off_rf(ah);
+ if (ret < 0)
+ return ret;
+
+ usleep(100000);
+
/* switch on rf */
ret = rc632_turn_on_rf(ah);
if (ret < 0)
return NULL;
memset(h, 0, sizeof(*h));
- h->asic = &rc632;
+ h->asic = (void*)&rc632;
h->rath = th;
h->fc = h->asic->fc;
/* FIXME: this is only cm5121 specific, since the latency
// FIXME: some fifo work (drain fifo?)
/* flush fifo (our way) */
- ret = rc632_reg_write(handle, RC632_REG_CONTROL, 0x01);
+ ret = rc632_reg_write(handle, RC632_REG_CONTROL,
+ RC632_CONTROL_FIFO_FLUSH);
ret = rc632_reg_write(handle, RC632_REG_TX_CONTROL,
(RC632_TXCTRL_TX1_RF_EN |
int ret;
u_int8_t rx_buf[64];
u_int8_t rx_len = sizeof(rx_buf);
- u_int8_t rx_align = 0, tx_last_bits, tx_bytes;
+ u_int8_t rx_align = 0, tx_last_bits, tx_bytes, tx_bytes_total;
u_int8_t boc;
u_int8_t error_flag;
*bit_of_col = ISO14443A_BITOFCOL_NONE;
if (ret < 0)
return ret;
- tx_last_bits = acf->nvb & 0x0f; /* lower nibble indicates bits */
- tx_bytes = acf->nvb >> 4;
+ tx_last_bits = acf->nvb & 0x07; /* lower nibble indicates bits */
+ tx_bytes = ( acf->nvb >> 4 ) & 0x07;
if (tx_last_bits) {
- tx_bytes++;
- rx_align = (tx_last_bits+1) % 8;/* rx frame complements tx */
+ tx_bytes_total = tx_bytes+1;
+ rx_align = tx_last_bits & 0x07; /* rx frame complements tx */
}
-
- //rx_align = 8 - tx_last_bits;/* rx frame complements tx */
+ else
+ tx_bytes_total = tx_bytes;
/* set RxAlign and TxLastBits*/
ret = rc632_reg_write(handle, RC632_REG_BIT_FRAMING,
if (ret < 0)
return ret;
- ret = rc632_transceive(handle, (u_int8_t *)acf, tx_bytes,
+ ret = rc632_transceive(handle, (u_int8_t *)acf, tx_bytes_total,
rx_buf, &rx_len, 0x32, 0);
if (ret < 0)
return ret;
acf->uid_bits[tx_bytes-2] = (
(acf->uid_bits[tx_bytes-2] & (0xff >> (8-tx_last_bits)))
| rx_buf[0]);
+
/* copy the rest */
- memcpy(&acf->uid_bits[tx_bytes+1-2], &rx_buf[1], rx_len-1);
+ if(rx_len)
+ memcpy(&acf->uid_bits[tx_bytes-1], &rx_buf[1], rx_len-1);
/* determine whether there was a collission */
ret = rc632_reg_read(handle, RC632_REG_ERROR_FLAG, &error_flag);
// FIXME: some FIFO work
/* flush fifo (our way) */
- ret = rc632_reg_write(handle, RC632_REG_CONTROL, 0x01);
+ ret = rc632_reg_write(handle, RC632_REG_CONTROL,
+ RC632_CONTROL_FIFO_FLUSH);
if (ret < 0)
return ret;
if (ret < 0)
return ret;
+ /* Terminate probably running command */
+ ret = rc632_reg_write(h, RC632_REG_COMMAND, RC632_CMD_IDLE);
+ if (ret < 0)
+ return ret;
+
ret = rc632_fifo_write(h, RFID_MIFARE_KEY_CODED_LEN, coded_key, 0x03);
if (ret < 0)
return ret;
struct mifare_authcmd acmd;
u_int8_t reg;
- if (cmd != RFID_CMD_MIFARE_AUTH1A && cmd != RFID_CMD_MIFARE_AUTH1B)
+ if (cmd != RFID_CMD_MIFARE_AUTH1A && cmd != RFID_CMD_MIFARE_AUTH1B) {
+ DEBUGP("invalid auth command\n");
return -EINVAL;
+ }
/* Initialize acmd */
acmd.block_address = block & 0xff;
//acmd.serno = htonl(serno);
acmd.serno = serno;
+#if 1
/* Clear Rx CRC */
ret = rc632_clear_bits(h, RC632_REG_CHANNEL_REDUNDANCY,
RC632_CR_RX_CRC_ENABLE);
+#else
+ /* Clear Rx CRC, Set Tx CRC and Odd Parity */
+ ret = rc632_reg_write(h, RC632_REG_CHANNEL_REDUNDANCY,
+ RC632_CR_TX_CRC_ENABLE | RC632_CR_PARITY_ODD |
+ RC632_CR_PARITY_ENABLE);
+#endif
if (ret < 0)
return ret;
return ret;
ret = rc632_reg_write(h, RC632_REG_COMMAND, RC632_CMD_AUTHENT1);
- if (ret < 0)
+ if (ret < 0) {
+ DEBUGP("error during AUTHENT1");
return ret;
+ }
/* Wait until transmitter is idle */
ret = rc632_wait_idle(h, RC632_TMO_AUTH1);
ret = rc632_reg_read(h, RC632_REG_SECONDARY_STATUS, ®);
if (ret < 0)
return ret;
- if (reg & 0x07)
+ if (reg & 0x07) {
+ DEBUGP("bitframe?");
return -EIO;
+ }
/* Clear Tx CRC */
ret = rc632_clear_bits(h, RC632_REG_CHANNEL_REDUNDANCY,
if (ret < 0)
return ret;
- if (!(reg & RC632_CONTROL_CRYPTO1_ON))
+ if (!(reg & RC632_CONTROL_CRYPTO1_ON)) {
+ DEBUGP("authentication not successful");
return -EACCES;
+ }
return 0;
-
}
/* transceive regular frame */