summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am12
-rw-r--r--src/rc632.h25
-rw-r--r--src/rfid_asic_rc632.c596
-rw-r--r--src/rfid_layer2.c9
-rw-r--r--src/rfid_layer2_iso15693.c154
-rw-r--r--src/rfid_proto_icode.c120
-rw-r--r--src/rfid_proto_tagit.c141
-rw-r--r--src/rfid_protocol.c1
-rw-r--r--src/rfid_reader_cm5121.c11
-rw-r--r--src/rfid_reader_openpcd.c43
-rw-r--r--src/rfid_reader_spidev.c13
11 files changed, 935 insertions, 190 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 45036b1..f0e5a6e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,11 +14,13 @@ endif
noinst_HEADERS=rfid_iso14443_common.h rc632.h libusb_dyn.h usleep.h cm5121_source.h
-CORE=rfid.c rfid_layer2.c rfid_protocol.c rfid_reader.c rfid_scan.c
-L2=rfid_layer2_iso14443a.c rfid_layer2_iso14443b.c rfid_layer2_iso15693.c rfid_iso14443_common.c
-PROTO=rfid_proto_tcl.c rfid_proto_mifare_ul.c rfid_proto_mifare_classic.c
-ASIC=rfid_asic_rc632.c
-MISC=rfid_access_mifare_classic.c
+CORE = rfid.c rfid_layer2.c rfid_protocol.c rfid_reader.c rfid_scan.c
+L2 = rfid_layer2_iso14443a.c rfid_layer2_iso14443b.c rfid_iso14443_common.c \
+ rfid_layer2_iso15693.c
+PROTO = rfid_proto_tcl.c rfid_proto_mifare_ul.c rfid_proto_mifare_classic.c \
+ rfid_proto_icode.c rfid_proto_tagit.c
+ASIC = rfid_asic_rc632.c
+MISC = rfid_access_mifare_classic.c
if ENABLE_WIN32
WIN32=usleep.c libusb_dyn.c
diff --git a/src/rc632.h b/src/rc632.h
index c7690ed..9cecab9 100644
--- a/src/rc632.h
+++ b/src/rc632.h
@@ -67,6 +67,22 @@ enum rc632_registers {
RC632_REG_TEST_DIGI_SELECT = 0x3d,
};
+enum rc632_reg_status {
+ RC632_STAT_LOALERT = 0x01,
+ RC632_STAT_HIALERT = 0x02,
+ RC632_STAT_IRQ = 0x04,
+ RC632_STAT_ERR = 0x08,
+#define RC632_STAT_MODEM_MASK 0x70
+ RC632_STAT_MODEM_IDLE = 0x00,
+ RC632_STAT_MODEM_TXSOF = 0x10,
+ RC632_STAT_MODEM_TXDATA = 0x20,
+ RC632_STAT_MODEM_TXEOF = 0x30,
+ RC632_STAT_MODEM_GOTORX = 0x40,
+ RC632_STAT_MODEM_PREPARERX = 0x50,
+ RC632_STAT_MODEM_AWAITINGRX = 0x60,
+ RC632_STAT_MODEM_RECV = 0x70,
+};
+
enum rc632_reg_command {
RC632_CMD_IDLE = 0x00,
RC632_CMD_WRITE_E2 = 0x01,
@@ -126,10 +142,16 @@ enum rc632_reg_tx_control {
};
enum rc632_reg_coder_control {
+ /* bit 2-0 TXCoding */
+#define RC632_CDRCTRL_TXCD_MASK 0x07
RC632_CDRCTRL_TXCD_NRZ = 0x00,
RC632_CDRCTRL_TXCD_14443A = 0x01,
RC632_CDRCTRL_TXCD_ICODE_STD = 0x04,
+ RC632_CDRCTRL_TXCD_ICODE_FAST = 0x05,
+ RC632_CDRCTRL_TXCD_15693_STD = 0x06,
+ RC632_CDRCTRL_TXCD_15693_FAST = 0x07,
+ /* bit5-3 CoderRate*/
#define RC632_CDRCTRL_RATE_MASK 0x38
RC632_CDRCTRL_RATE_848K = 0x00,
RC632_CDRCTRL_RATE_424K = 0x08,
@@ -138,6 +160,9 @@ enum rc632_reg_coder_control {
RC632_CDRCTRL_RATE_14443B = 0x20,
RC632_CDRCTRL_RATE_15693 = 0x28,
RC632_CDRCTRL_RATE_ICODE_FAST = 0x30,
+
+ /* bit 7 SendOnePuls */
+ RC632_CDRCTRL_15693_EOF_PULSE = 0x80,
};
enum rc632_erg_type_b_framing {
diff --git a/src/rfid_asic_rc632.c b/src/rfid_asic_rc632.c
index b8d8db3..8fc5cb9 100644
--- a/src/rfid_asic_rc632.c
+++ b/src/rfid_asic_rc632.c
@@ -31,6 +31,7 @@
#include <librfid/rfid_asic_rc632.h>
#include <librfid/rfid_reader_cm5121.h>
#include <librfid/rfid_layer2_iso14443a.h>
+#include <librfid/rfid_layer2_iso15693.h>
#include <librfid/rfid_protocol_mifare_classic.h>
#include "rfid_iso14443_common.h"
@@ -138,6 +139,12 @@ rc632_clear_bits(struct rfid_asic_handle *handle,
return rc632_reg_write(handle, reg, (tmp & ~val)&0xff);
}
+static int
+rc632_clear_irqs(struct rfid_asic_handle *handle, u_int8_t bits)
+{
+ return rc632_reg_write(handle, RC632_REG_INTERRUPT_RQ, (~RC632_INT_SET)&bits);
+}
+
static int
rc632_rf_power(struct rfid_asic_handle *handle, int on)
{
@@ -284,20 +291,32 @@ rc632_wait_idle(struct rfid_asic_handle *handle, u_int64_t timeout)
if (ret < 0)
return ret;
- if (cmd == 0) {
- /* FIXME: read second time ?? */
- return 0;
- }
-
{
u_int8_t foo;
rc632_reg_read(handle, RC632_REG_PRIMARY_STATUS, &foo);
- if (foo & 0x04)
+ DEBUGP_STATUS_FLAG(foo);
+ /* check if Error has occured (ERR flag set) */
+ if (foo & RC632_STAT_ERR) {
rc632_reg_read(handle, RC632_REG_ERROR_FLAG, &foo);
+ DEBUGP_ERROR_FLAG(foo);
+ }
+ /* check if IRQ has occurred (IRQ flag set)*/
+ if (foo & RC632_STAT_IRQ) {
+ ret = rc632_reg_read(handle, RC632_REG_INTERRUPT_RQ, &foo);
+ DEBUGP_INTERRUPT_FLAG(foo);
+ /* clear all interrupts */
+ rc632_clear_irqs(handle, 0xff);
+ }
+ }
+ if (cmd == 0) {
+ /* FIXME: read second time ?? */
+ DEBUGP("cmd == 0 (IDLE)\n");
+ return 0;
}
/* Abort after some timeout */
if (cycles > timeout*100/USLEEP_PER_CYCLE) {
+ DEBUGP("timeout...\n");
return -ETIMEDOUT;
}
@@ -351,7 +370,7 @@ rc632_transmit(struct rfid_asic_handle *handle,
static int
tcl_toggle_pcb(struct rfid_asic_handle *handle)
{
- // FIXME: toggle something between 0x0a and 0x0b
+ /* FIXME: toggle something between 0x0a and 0x0b */
return 0;
}
@@ -364,11 +383,11 @@ rc632_transceive(struct rfid_asic_handle *handle,
u_int64_t timer,
unsigned int toggle)
{
- int ret, cur_tx_len;
+ int ret, cur_tx_len, i;
u_int8_t rx_avail;
const u_int8_t *cur_tx_buf = tx_buf;
- DEBUGP("timer = %u\n", timer);
+ DEBUGP("timer=%u, rx_len=%u, tx_len=%u,", timer, rx_len, tx_len);
if (tx_len > 64)
cur_tx_len = 64;
@@ -382,6 +401,7 @@ rc632_transceive(struct rfid_asic_handle *handle,
ret = rc632_reg_write(handle, RC632_REG_COMMAND, 0x00);
/* clear all interrupts */
ret = rc632_reg_write(handle, RC632_REG_INTERRUPT_RQ, 0x7f);
+ ret = rc632_reg_write(handle, RC632_REG_ERROR_FLAG, 0xff);
do {
ret = rc632_fifo_write(handle, cur_tx_len, cur_tx_buf, 0x03);
@@ -404,7 +424,6 @@ rc632_transceive(struct rfid_asic_handle *handle,
return ret;
cur_tx_len = 64 - fifo_fill;
- //printf("refilling tx fifo with %u bytes\n", cur_tx_len);
} else
cur_tx_len = 0;
@@ -415,6 +434,66 @@ rc632_transceive(struct rfid_asic_handle *handle,
//ret = rc632_wait_idle_timer(handle);
ret = rc632_wait_idle(handle, timer);
+
+ DEBUGP("rc632_wait_idle>>ret=%d %s\n",ret,(ret==-ETIMEDOUT)?"ETIMEDOUT":"");
+ if (ret < 0)
+ return ret;
+
+ ret = rc632_reg_read(handle, RC632_REG_FIFO_LENGTH, &rx_avail);
+ if (ret < 0)
+ return ret;
+
+ if (rx_avail > *rx_len)
+ DEBUGP("rx_avail(%d) > rx_len(%d), JFYI\n", rx_avail, *rx_len);
+ else if (*rx_len > rx_avail)
+ *rx_len = rx_avail;
+
+ DEBUGP("rx_len == %d\n",*rx_len);
+
+ if (rx_avail == 0) {
+ u_int8_t tmp;
+
+ for (i = 0; i < 1; i++){
+ rc632_reg_read(handle, RC632_REG_PRIMARY_STATUS, &tmp);
+ DEBUGP_STATUS_FLAG(tmp);
+ rc632_reg_read(handle, RC632_REG_ERROR_FLAG, &tmp);
+ DEBUGP_ERROR_FLAG(tmp);
+ }
+ rc632_reg_read(handle, RC632_REG_CHANNEL_REDUNDANCY, &tmp);
+
+ //return 0;
+ return -1;
+ }
+
+ return rc632_fifo_read(handle, *rx_len, rx_buf);
+ /* FIXME: discard addidional bytes in FIFO */
+}
+
+
+static int
+rc632_receive(struct rfid_asic_handle *handle,
+ u_int8_t *rx_buf,
+ u_int8_t *rx_len,
+ u_int64_t timer)
+{
+ int ret, cur_tx_len, i;
+ u_int8_t rx_avail;
+
+ /*
+ DEBUGP("timer = %u\n", timer);
+ ret = rc632_timer_set(handle, timer*10);
+ if (ret < 0)
+ return ret;
+ /*
+ ret = rc632_reg_write(handle, RC632_REG_COMMAND, 0x00); /* IDLE */
+ /* clear all interrupts */
+ ret = rc632_reg_write(handle, RC632_REG_INTERRUPT_RQ, 0x7f);
+
+ ret = rc632_reg_write(handle, RC632_REG_COMMAND,RC632_CMD_RECEIVE);
+ if (ret < 0)
+ return ret;
+
+ ret = rc632_wait_idle(handle, timer);
if (ret < 0)
return ret;
@@ -432,14 +511,19 @@ rc632_transceive(struct rfid_asic_handle *handle,
DEBUGP("rx_len == 0\n");
- rc632_reg_read(handle, RC632_REG_ERROR_FLAG, &tmp);
- rc632_reg_read(handle, RC632_REG_CHANNEL_REDUNDANCY, &tmp);
+ for (i = 0; i < 1; i++) {
+ rc632_reg_read(handle, RC632_REG_PRIMARY_STATUS, &tmp);
+ DEBUGP_STATUS_FLAG(tmp);
+ rc632_reg_read(handle, RC632_REG_ERROR_FLAG, &tmp);
+ DEBUGP_ERROR_FLAG(tmp);
+ }
+ rc632_reg_read(handle, RC632_REG_CHANNEL_REDUNDANCY, &tmp);
return -1;
}
return rc632_fifo_read(handle, *rx_len, rx_buf);
- /* FIXME: discard addidional bytes in FIFO */
+ /* FIXME: discard additional bytes in FIFO */
}
static int
@@ -467,7 +551,7 @@ rc632_read_eeprom(struct rfid_asic_handle *handle)
if (ret < 0)
return ret;
- // FIXME: do something with eeprom contents
+ /* FIXME: do something with eeprom contents */
return ret;
}
@@ -494,7 +578,7 @@ rc632_calc_crc16_from(struct rfid_asic_handle *handle)
if (ret < 0)
return ret;
- usleep(10000); // FIXME: no checking for cmd completion?
+ usleep(10000); /* FIXME: no checking for cmd completion? *
ret = rc632_reg_read(handle, RC632_REG_CRC_RESULT_LSB, &crc_lsb);
if (ret < 0)
@@ -504,7 +588,7 @@ rc632_calc_crc16_from(struct rfid_asic_handle *handle)
if (ret < 0)
return ret;
- // FIXME: what to do with crc result?
+ /* FIXME: what to do with crc result? */
return ret;
}
@@ -527,14 +611,14 @@ rc632_register_dump(struct rfid_asic_handle *handle, u_int8_t *buf)
static int
generic_fifo_write()
{
- // FIXME: implementation (not needed for CM 5121)
+ /* FIXME: implementation (not needed for CM 5121) */
return -1;
}
static int
generic_fifo_read()
{
- // FIXME: implementation (not neded for CM 5121)
+ /* FIXME: implementation (not neded for CM 5121) */
return -1;
}
@@ -642,7 +726,7 @@ rc632_iso14443a_init(struct rfid_asic_handle *handle)
{
int ret;
- // FIXME: some fifo work (drain fifo?)
+ /* FIXME: some fifo work (drain fifo?) */
/* flush fifo (our way) */
ret = rc632_reg_write(handle, RC632_REG_CONTROL,
@@ -863,6 +947,12 @@ rc632_iso14443ab_transceive(struct rfid_asic_handle *handle,
channel_red = RC632_CR_PARITY_ENABLE|RC632_CR_PARITY_ODD;
break;
#endif
+ case RFID_15693_FRAME:
+ channel_red = RC632_CR_CRC3309 | RC632_CR_RX_CRC_ENABLE
+ | RC632_CR_TX_CRC_ENABLE;
+ break;
+ case RFID_15693_FRAME_ICODE1:
+ /* FIXME: implement */
default:
return -EINVAL;
break;
@@ -871,7 +961,7 @@ rc632_iso14443ab_transceive(struct rfid_asic_handle *handle,
channel_red);
if (ret < 0)
return ret;
-
+ DEBUGP("tx_len=%u\n",tx_len);
ret = rc632_transceive(handle, tx_buf, tx_len, rx_buf, &rxl, timeout, 0);
*rx_len = rxl;
if (ret < 0)
@@ -962,6 +1052,138 @@ rc632_iso14443a_transceive_acf(struct rfid_asic_handle *handle,
return 0;
}
+static void uuid_reversecpy(unsigned char* out, unsigned char* in, int len)
+{
+ int i = 0;
+ while (len > 0) {
+ out[i] = in[len];
+ len--;
+ i++;
+ }
+}
+
+
+static int
+rc632_iso15693_transceive_ac(struct rfid_asic_handle *handle,
+ struct iso15693_anticol_cmd *acf,
+ unsigned char uuid[ISO15693_UID_LEN],
+ char *bit_of_col)
+{
+ u_int8_t boc;
+ u_int8_t error_flag, tmp;
+ u_int8_t rx_len;
+
+ int ret, tx_len, mask_len_bytes;
+
+ struct iso15693_request_inventory {
+ struct iso15693_request head;
+ unsigned char mask_length;
+ /* mask_value[0] + (maybe crc[2]) */
+ unsigned char data[ISO15693_UID_LEN];
+ } req;
+
+ struct {
+ struct iso15693_response head;
+ unsigned char dsfid;
+ unsigned char uuid[ISO15693_UID_LEN];
+ } rx_buf;
+
+ memset(uuid, 0, ISO15693_UID_LEN);
+
+ *bit_of_col = 0;
+ rx_len = sizeof(rx_buf);
+ mask_len_bytes = (acf->mask_len % 8) ? acf->mask_len/8+1 : acf->mask_len/8;
+
+
+ if (acf->current_slot == 0) {
+ /* first call: transmit Inventory frame */
+ DEBUGP("first_frame\n");
+ req.head.command = ISO15693_CMD_INVENTORY;
+ req.head.flags = (acf->flags & 0xf0)
+ | RFID_15693_F_INV_TABLE_5
+ | RFID_15693_F_RATE_HIGH;
+ //| RFID_15693_F_SUBC_TWO | RFID_15693_F_RATE_HIGH;
+ req.mask_length = acf->mask_len;
+ memset(req.data, 0, ISO15693_UID_LEN);
+ memcpy(req.data, acf->mask_bits, mask_len_bytes);
+
+ tx_len = sizeof(struct iso15693_request) + 1 + mask_len_bytes;
+
+ ret = rc632_transceive(handle, (u_int8_t *)&req, tx_len,
+ (u_int8_t *)&rx_buf, &rx_len, 10, 0);
+ acf->current_slot = 1;
+ DEBUGP("rc632_transceive ret: %d rx_len: %d\n",ret,rx_len);
+ /* if ((ret < 0)&&(ret != -ETIMEDOUT))
+ return ret; */
+
+ } else {
+ /* second++ call: end timeslot with EOFpulse and read */
+ DEBUGP("second++_frame\n");
+ if ((acf->current_slot > 16) ||
+ ((acf->flags & RFID_15693_F5_NSLOTS_1 == 0)
+ && (acf->current_slot > 1))) {
+
+ memset(uuid, 0, ISO15693_UID_LEN);
+ return -1;
+ }
+
+ /* reset EOF-pulse-bit to 0 */
+ ret = rc632_clear_bits(handle, RC632_REG_CODER_CONTROL,
+ RC632_CDRCTRL_15693_EOF_PULSE);
+ usleep(50);
+ /* generate EOF pulse */
+ ret = rc632_set_bits(handle, RC632_REG_CODER_CONTROL,
+ RC632_CDRCTRL_15693_EOF_PULSE);
+ if (ret < 0)
+ return ret;
+ // DEBUGP("waiting for EOF pulse\n");
+ // ret = rc632_wait_idle(handle, 10); //wait for idle
+
+ rx_len = sizeof(rx_buf);
+ ret = rc632_receive(handle, (u_int8_t*)&rx_buf, &rx_len, 50);
+ DEBUGP("rc632_receive ret: %d rx_len: %d\n", ret, rx_len);
+ acf->current_slot++;
+
+ /* if ((ret < 0)&&(ret != -ETIMEDOUT))
+ return ret; */
+ }
+
+ rc632_reg_read(handle, RC632_REG_PRIMARY_STATUS, &tmp);
+ DEBUGP_STATUS_FLAG(tmp);
+
+ if (ret == -ETIMEDOUT) {
+ /* no VICC answer in this timeslot*/
+ memset(uuid, 0, ISO15693_UID_LEN);
+ return -ETIMEDOUT;
+ } else {
+ /* determine whether there was a collission */
+ ret = rc632_reg_read(handle, RC632_REG_ERROR_FLAG, &error_flag);
+ DEBUGP_ERROR_FLAG(error_flag);
+ if (ret < 0)
+ return ret;
+
+ if (error_flag & RC632_ERR_FLAG_COL_ERR) {
+ /* retrieve bit of collission */
+ ret = rc632_reg_read(handle, RC632_REG_COLL_POS, &boc);
+ if (ret < 0)
+ return ret;
+ *bit_of_col = boc;
+ memcpy(uuid, rx_buf.uuid, ISO15693_UID_LEN);
+ // uuid_reversecpy(uuid, rx_buf.uuid, ISO15693_UID_LEN);
+ DEBUGP("Collision in slot %d bit %d\n",
+ acf->current_slot,boc);
+ return -ECOLLISION;
+ } else {
+ /* no collision-> retrieve uuid */
+ DEBUGP("no collision in slot %d\n", acf->current_slot);
+ memcpy(uuid, rx_buf.uuid, ISO15693_UID_LEN);
+ //uuid_reversecpy(uuid, rx_buf.uuid, ISO15693_UID_LEN);
+ }
+ }
+
+ return 0;
+}
+
enum rc632_rate {
RC632_RATE_106 = 0x00,
RC632_RATE_212 = 0x01,
@@ -1086,8 +1308,8 @@ static int rc632_iso14443a_set_speed(struct rfid_asic_handle *handle,
static int rc632_iso14443b_init(struct rfid_asic_handle *handle)
{
int ret;
-
- // FIXME: some FIFO work
+ ENTER();
+ /* FIXME: some FIFO work */
/* flush fifo (our way) */
ret = rc632_reg_write(handle, RC632_REG_CONTROL,
@@ -1192,170 +1414,201 @@ static int rc632_iso14443b_init(struct rfid_asic_handle *handle)
return 0;
}
-static int
-rc632_iso15693_init(struct rfid_asic_handle *h)
-{
- int ret;
-
- ret = rc632_reg_write(h, RC632_REG_TX_CONTROL,
- (RC632_TXCTRL_MOD_SRC_INT |
- RC632_TXCTRL_TX2_INV |
- RC632_TXCTRL_TX2_RF_EN |
- RC632_TXCTRL_TX1_RF_EN));
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_CW_CONDUCTANCE, 0x3f);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_MOD_CONDUCTANCE, 0x03);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_CODER_CONTROL,
- (RC632_CDRCTRL_RATE_15693 |
- 0x03)); /* FIXME */
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_MOD_WIDTH, 0x3f);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_MOD_WIDTH_SOF, 0x3f);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_TYPE_B_FRAMING, 0x00);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_RX_CONTROL1,
- (RC632_RXCTRL1_SUBCP_16 |
- RC632_RXCTRL1_ISO15693 |
- RC632_RXCTRL1_GAIN_35DB));
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_DECODER_CONTROL,
- (RC632_DECCTRL_RXFR_15693 |
- RC632_DECCTRL_RX_INVERT));
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_BIT_PHASE, 0xe0);
- if (ret < 0)
- return ret;
+struct register_file {
+ u_int8_t reg;
+ u_int8_t val;
+};
- ret = rc632_reg_write(h, RC632_REG_RX_THRESHOLD, 0xff);
- if (ret < 0)
- return ret;
+/* Register file for ISO15693 standard */
+static struct register_file iso15693_fast_script[] = {
+ {
+ .reg = RC632_REG_TX_CONTROL,
+ .val = RC632_TXCTRL_MOD_SRC_INT |
+ RC632_TXCTRL_TX2_INV |
+ RC632_TXCTRL_TX2_RF_EN |
+ RC632_TXCTRL_TX1_RF_EN,
+ }, {
+ .reg = RC632_REG_CW_CONDUCTANCE,
+ .val = 0x3f,
+ }, {
+ .reg = RC632_REG_MOD_CONDUCTANCE,
+ /* FIXME: nxp default for icode1/15693: 0x05 */
+ //.val = 0x02,
+ .val = 0x21, /* omnikey */
+ }, {
+ .reg = RC632_REG_CODER_CONTROL,
+ .val = RC632_CDRCTRL_TXCD_15693_FAST |
+ RC632_CDRCTRL_RATE_15693,
+ }, {
+ .reg = RC632_REG_MOD_WIDTH,
+ .val = 0x3f,
+ }, {
+ .reg = RC632_REG_MOD_WIDTH_SOF,
+ .val = 0x3f,
+ }, {
+ .reg = RC632_REG_TYPE_B_FRAMING,
+ .val = 0x00,
+ }, {
+ .reg = RC632_REG_RX_CONTROL1,
+ .val = RC632_RXCTRL1_ISO15693 |
+ RC632_RXCTRL1_SUBCP_16 |
+ RC632_RXCTRL1_GAIN_35DB,
+ }, {
+ /* FIXME: this should always be the case */
+ .reg = RC632_REG_RX_CONTROL2,
+ .val = RC632_RXCTRL2_DECSRC_INT,
+ }, {
+ .reg = RC632_REG_DECODER_CONTROL,
+ .val = RC632_DECCTRL_MANCHESTER |
+ RC632_DECCTRL_RX_INVERT |
+ RC632_DECCTRL_ZEROAFTERCOL |
+ RC632_DECCTRL_RXFR_15693,
+ }, {
+ .reg = RC632_REG_BIT_PHASE,
+ /* FIXME: nxp default for icode1/15693: 0x54 */
+ //.val = 0x52,
+ .val = 0xd0, /* omnikey */
+ }, {
+ .reg = RC632_REG_RX_THRESHOLD,
+ /* FIXME: nxp default for icode1/15693: 0x68 */
+ //.val = 0x66,
+ .val = 0xed,
+ }, {
+ .reg = RC632_REG_BPSK_DEM_CONTROL,
+ .val = 0x00,
+ }, {
+ .reg = RC632_REG_CHANNEL_REDUNDANCY,
+ .val = RC632_CR_RX_CRC_ENABLE |
+ RC632_CR_TX_CRC_ENABLE |
+ RC632_CR_CRC3309,
+ }, {
+ .reg = RC632_REG_CRC_PRESET_LSB,
+ .val = 0xff,
+ }, {
+ .reg = RC632_REG_CRC_PRESET_MSB,
+ .val = 0xff,
+ },
+};
- ret = rc632_reg_write(h, RC632_REG_BPSK_DEM_CONTROL, 0x00);
- if (ret < 0)
- return ret;
+/* Register file for I*Code standard */
+static struct register_file icode1_std_script[] = {
+ {
+ .reg = RC632_REG_TX_CONTROL,
+ .val = RC632_TXCTRL_MOD_SRC_INT |
+ RC632_TXCTRL_TX2_INV |
+ RC632_TXCTRL_TX2_RF_EN |
+ RC632_TXCTRL_TX1_RF_EN,
+ }, {
+ .reg = RC632_REG_CW_CONDUCTANCE,
+ .val = 0x3f,
+ }, {
+ .reg = RC632_REG_MOD_CONDUCTANCE,
+ /* FIXME: nxp default for icode1/15693: 0x05 */
+ .val = 0x02,
+ }, {
+ .reg = RC632_REG_CODER_CONTROL,
+ .val = RC632_CDRCTRL_TXCD_ICODE_STD |
+ RC632_CDRCTRL_RATE_15693,
+ }, {
+ .reg = RC632_REG_MOD_WIDTH,
+ .val = 0x3f,
+ }, {
+ .reg = RC632_REG_MOD_WIDTH_SOF,
+ .val = 0x3f,
+ }, {
+ .reg = RC632_REG_TYPE_B_FRAMING,
+ .val = 0x00,
+ }, {
+ .reg = RC632_REG_RX_CONTROL1,
+ .val = RC632_RXCTRL1_ISO15693 |
+ RC632_RXCTRL1_SUBCP_16 |
+ RC632_RXCTRL1_GAIN_35DB,
+ }, {
+ /* FIXME: this should always be the case */
+ .reg = RC632_REG_RX_CONTROL2,
+ .val = RC632_RXCTRL2_DECSRC_INT,
+ }, {
+ .reg = RC632_REG_DECODER_CONTROL,
+ .val = RC632_DECCTRL_MANCHESTER |
+ RC632_DECCTRL_RXFR_ICODE,
+ }, {
+ .reg = RC632_REG_BIT_PHASE,
+ /* FIXME: nxp default for icode1/15693: 0x54 */
+ .val = 0x52,
+ }, {
+ .reg = RC632_REG_RX_THRESHOLD,
+ /* FIXME: nxp default for icode1/15693: 0x68 */
+ .val = 0x66,
+ }, {
+ .reg = RC632_REG_BPSK_DEM_CONTROL,
+ .val = 0x00,
+ }, {
+ .reg = RC632_REG_CHANNEL_REDUNDANCY,
+ /* 16bit CRC, no parity, not CRC3309 */
+ .val = RC632_CR_RX_CRC_ENABLE |
+ RC632_CR_TX_CRC_ENABLE,
+ }, {
+ .reg = RC632_REG_CRC_PRESET_LSB,
+ .val = 0xfe,
+ }, {
+ .reg = RC632_REG_CRC_PRESET_MSB,
+ .val = 0xff,
+ }
+};
- ret = rc632_reg_write(h, RC632_REG_RX_CONTROL2,
- (RC632_RXCTRL2_AUTO_PD |
- RC632_RXCTRL2_DECSRC_INT));
- if (ret < 0)
- return ret;
+/* incremental changes on top of icode1_std_script */
+static struct register_file icode1_fast_patch[] = {
+ {
+ .reg = RC632_REG_CODER_CONTROL,
+ .val = RC632_CDRCTRL_TXCD_ICODE_FAST |
+ RC632_CDRCTRL_RATE_ICODE_FAST,
+ }, {
+ .reg = RC632_REG_MOD_WIDTH_SOF,
+ .val = 0x73, /* 18.88uS */
+ },
+};
- ret = rc632_reg_write(h, RC632_REG_CHANNEL_REDUNDANCY,
- (RC632_CR_CRC3309 |
- RC632_CR_RX_CRC_ENABLE |
- RC632_CR_TX_CRC_ENABLE));
- if (ret < 0)
- return ret;
+static int
+rc632_iso15693_init(struct rfid_asic_handle *h)
+{
+ int ret, i;
+ ENTER();
- ret = rc632_reg_write(h, RC632_REG_CRC_PRESET_LSB, 0xff);
- if (ret < 0)
- return ret;
+ /* flush fifo (our way) */
+ ret = rc632_reg_write(h, RC632_REG_CONTROL,
+ RC632_CONTROL_FIFO_FLUSH);
- ret = rc632_reg_write(h, RC632_REG_CRC_PRESET_MSB, 0xff);
- if (ret < 0)
- return ret;
+ for (i = 0; i < ARRAY_SIZE(iso15693_fast_script); i++) {
+ ret = rc632_reg_write(h, iso15693_fast_script[i].reg,
+ iso15693_fast_script[i].val);
+ if (ret < 0)
+ return ret;
+ }
return 0;
}
static int
-rc632_iso15693_icode_init(struct rfid_asic_handle *h)
+rc632_iso15693_icode1_init(struct rfid_asic_handle *h, int fast)
{
int ret;
+ int i;
- ret = rc632_reg_write(h, RC632_REG_TX_CONTROL,
- (RC632_TXCTRL_MOD_SRC_INT |
- RC632_TXCTRL_TX2_INV |
- RC632_TXCTRL_TX2_RF_EN |
- RC632_TXCTRL_TX1_RF_EN));
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_CW_CONDUCTANCE, 0x3f);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_MOD_CONDUCTANCE, 0x02);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_CODER_CONTROL, 0x2c);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_MOD_WIDTH, 0x3f);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_MOD_WIDTH_SOF, 0x3f);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_MOD_WIDTH_SOF, 0x3f);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_TYPE_B_FRAMING, 0x00);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_RX_CONTROL1, 0x8b); /* FIXME */
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_DECODER_CONTROL, 0x00);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_BIT_PHASE, 0x52);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_RX_THRESHOLD, 0x66);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_BPSK_DEM_CONTROL, 0x00);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_RX_CONTROL2,
- RC632_RXCTRL2_DECSRC_INT);
- if (ret < 0)
- return ret;
-
- ret = rc632_reg_write(h, RC632_REG_CHANNEL_REDUNDANCY,
- (RC632_CR_RX_CRC_ENABLE |
- RC632_CR_TX_CRC_ENABLE));
- ret = rc632_reg_write(h, RC632_REG_CRC_PRESET_LSB, 0xfe);
- if (ret < 0)
- return ret;
+ for (i = 0; i < ARRAY_SIZE(icode1_std_script); i++) {
+ ret = rc632_reg_write(h, icode1_std_script[i].reg,
+ icode1_std_script[i].val);
+ if (ret < 0)
+ return ret;
+ }
- ret = rc632_reg_write(h, RC632_REG_CRC_PRESET_MSB, 0xff);
- if (ret < 0)
- return ret;
+ if (fast) {
+ for (i = 0; i < ARRAY_SIZE(icode1_fast_patch); i++) {
+ ret = rc632_reg_write(h, icode1_fast_patch[i].reg,
+ icode1_fast_patch[i].val);
+ if (ret < 0)
+ return ret;
+ }
+ }
return 0;
}
@@ -1646,6 +1899,7 @@ const struct rfid_asic rc632 = {
},
.iso15693 = {
.init = &rc632_iso15693_init,
+ .transceive_ac = &rc632_iso15693_transceive_ac,
},
.mifare_classic = {
.setkey = &rc632_mifare_set_key,
diff --git a/src/rfid_layer2.c b/src/rfid_layer2.c
index bc5a4ec..4cad6c3 100644
--- a/src/rfid_layer2.c
+++ b/src/rfid_layer2.c
@@ -117,6 +117,15 @@ rfid_layer2_setopt(struct rfid_layer2_handle *ph, int optname,
{
if (optname >> 16 == 0) {
switch (optname) {
+ case RFID_OPT_LAYER2_UID:
+ printf("----> sizeof(ph->uid): %d\n",sizeof(ph->uid));
+ if ((ph->uid_len < sizeof(ph->uid)) && (optlen<=sizeof(ph->uid))) {
+ //(ph->uid_len<optlen)
+ ph->uid_len = optlen;
+ memcpy(ph->uid, optval, optlen);
+ } else
+ return -EINVAL;
+ break;
default:
return -EINVAL;
break;
diff --git a/src/rfid_layer2_iso15693.c b/src/rfid_layer2_iso15693.c
index 1c1ee1c..09dd632 100644
--- a/src/rfid_layer2_iso15693.c
+++ b/src/rfid_layer2_iso15693.c
@@ -1,7 +1,7 @@
/* ISO 15693 anticollision implementation
*
- * (C) 2005-2006 by Harald Welte <laforge@gnumonks.org>
- *
+ * (C) 2005-2008 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2007 by Bjoern Riemer <bjoern.riemer@web.de>
*/
/*
@@ -19,6 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
+#define DEBUG_LIBRFID
+
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
@@ -35,10 +37,41 @@ struct iso15693_request_read {
u_int8_t blocknum;
} __attribute__ ((packed));
+struct iso15693_request_adressed {
+ struct iso15693_request head;
+ u_int64_t uid;
+} __attribute__ ((packed));
+
#define ISO15693_BLOCK_SIZE_MAX (256/8)
#define ISO15693_RESP_SIZE_MAX (4+ISO15693_BLOCK_SIZE_MAX)
+#define TIMEOUT 200
+
+static int iso15693_transceive(struct rfid_layer2_handle *handle,
+ enum rfid_frametype frametype,
+ const unsigned char *tx_buf, unsigned int tx_len,
+ unsigned char *rx_buf, unsigned int *rx_len,
+ u_int64_t timeout, unsigned int flags)
+{
+ return handle->rh->reader->transceive(handle->rh, frametype, tx_buf,
+ tx_len, rx_buf, rx_len, timeout, flags);
+}
+
+/* Transmit an anticollission frame */
+static int
+iso15693_transceive_acf(struct rfid_layer2_handle *handle,
+ struct iso15693_anticol_cmd *acf,
+ unsigned char uuid[ISO15693_UID_LEN],
+ char *bit_of_col)
+{
+ struct rfid_reader *rdr = handle->rh->reader;
+ if (!rdr->iso15693.transceive_ac)
+ return -1;
+ return rdr->iso15693.transceive_ac(handle->rh, acf, uuid, bit_of_col);
+}
+
#if 0
+
static int
iso15693_read_block(struct rfid_layer2_handle *handle,
u_int8_t blocknr, u_int32_t *data)
@@ -90,6 +123,121 @@ iso15693_lock_block()
static int
iso15693_anticol(struct rfid_layer2_handle *handle)
{
+ int i, ret;
+ int rx_len = 0;
+ int num_valid = 0;
+ struct iso15693_anticol_cmd acf;
+ char uuid[ISO15693_UID_LEN];
+ char boc;
+
+ char uuid_list[16][ISO15693_UID_LEN];
+ int uuid_list_valid[16];
+
+#define MY_NONE 0
+#define MY_COLL 1
+#define MY_UUID 2
+
+ memset(uuid_list_valid, MY_NONE, 16);
+ memset(uuid_list, 0, ISO15693_UID_LEN * 16);
+
+ memset(&acf, 0, sizeof(struct iso15693_anticol_cmd));
+ acf.afi = 0;
+ acf.flags = RFID_15693_F5_NSLOTS_1 | /* comment out for 16 slots */
+ RFID_15693_F_INV_TABLE_5 |
+ RFID_15693_F_RATE_HIGH;
+ //RFID_15693_F_SUBC_TWO
+ acf.mask_len = 0;
+ //acf.mask_bits[0] = 3;
+ acf.current_slot = 0;
+
+ if (acf.flags & RFID_15693_F5_NSLOTS_1)
+ i = 1;
+ else
+ i = 16;
+ for (; i >=1; i--) {
+ //acf.current_slot=0;
+ ret = iso15693_transceive_acf(handle, &acf, &uuid[0], &boc);
+ switch (ret) {
+ case -ETIMEDOUT:
+ DEBUGP("no answer from vicc in slot %d\n",
+ acf.current_slot);
+ uuid_list_valid[acf.current_slot] = MY_NONE;
+ break;
+ case -ECOLLISION:
+ DEBUGP("Collision during anticol. slot %d bit %d\n",
+ acf.current_slot,boc);
+ uuid_list_valid[acf.current_slot] = -boc;
+ memcpy(uuid_list[acf.current_slot], uuid, ISO15693_UID_LEN);
+ break;
+ default:
+ if (ret < 0) {
+ DEBUGP("ERROR ret: %d, slot %d\n", ret,
+ acf.current_slot);
+ uuid_list_valid[acf.current_slot] = MY_NONE;
+ } else {
+ DEBUGP("Slot %d ret: %d UUID: %s\n",
+ acf.current_slot, ret,
+ rfid_hexdump(uuid, ISO15693_UID_LEN));
+ uuid_list_valid[acf.current_slot] = MY_UUID;
+ memcpy(&uuid_list[acf.current_slot][0], uuid,
+ ISO15693_UID_LEN);
+ }
+ }
+ usleep(1000*200);
+ }
+ if (acf.flags & RFID_15693_F5_NSLOTS_1)
+ i = 1;
+ else
+ i = 16;
+
+ while (i) {
+ if (uuid_list_valid[i] == MY_NONE) {
+ DEBUGP("slot[%d]: timeout\n",i);
+ } else if (uuid_list_valid[i] == MY_UUID) {
+ DEBUGP("slot[%d]: VALID uuid: %s\n", i,
+ rfid_hexdump(uuid_list[i], ISO15693_UID_LEN));
+ num_valid++;
+ } else if (uuid_list_valid[i] < 0) {
+ DEBUGP("slot[%d]: collision(%d %d,%d) uuid: %s\n",
+ i,uuid_list_valid[i]*-1,
+ (uuid_list_valid[i]*-1)/8,
+ (uuid_list_valid[i]*-1)%8,
+ rfid_hexdump(uuid_list[i], ISO15693_UID_LEN));
+ }
+ i--;
+ }
+ if (num_valid == 0)
+ return -1;
+
+ return num_valid;
+}
+
+static int
+iso15693_select(struct rfid_layer2_handle *handle)
+{
+ struct iso15693_request_adressed tx_req;
+ int ret;
+ unsigned int rx_len, tx_len;
+
+ struct {
+ struct iso15693_response head;
+ u_int8_t error;
+ unsigned char crc[2];
+ } rx_buf;
+ rx_len = sizeof(rx_buf);
+
+ tx_req.head.command = ISO15693_CMD_SELECT;
+ tx_req.head.flags = RFID_15693_F4_ADDRESS | RFID_15693_F_SUBC_TWO ;
+ tx_req.uid = 0xE0070000020C1F18;
+ //req.uid = 0x181F0C02000007E0;
+ //req.uid = 0xe004010001950837;
+ //req.uid = 0x37089501000104e0;
+ tx_len = sizeof(tx_req);
+ DEBUGP("tx_len=%u", tx_len); DEBUGPC(" rx_len=%u\n",rx_len);
+ ret = iso15693_transceive(handle, RFID_15693_FRAME, (u_int8_t*)&tx_req,
+ tx_len, (u_int8_t*)&rx_buf, &rx_len, 50,0);
+ DEBUGP("ret: %d, error_flag: %d error: %d\n", ret,
+ rx_buf.head.flags&RFID_15693_RF_ERROR, 0);
return -1;
}
@@ -127,6 +275,7 @@ iso15693_setopt(struct rfid_layer2_handle *handle, int optname,
static int transceive_inventory(struct rfid_layer2_handle *l2h)
{
+ return -1;
}
static struct rfid_layer2_handle *
@@ -163,6 +312,7 @@ const struct rfid_layer2 rfid_layer2_iso15693 = {
.fn = {
.init = &iso15693_init,
.open = &iso15693_anticol,
+ //.open = &iso15693_select,
//.transceive = &iso15693_transceive,
//.close = &iso14443a_hlta,
.fini = &iso15693_fini,
diff --git a/src/rfid_proto_icode.c b/src/rfid_proto_icode.c
new file mode 100644
index 0000000..f8e6cbd
--- /dev/null
+++ b/src/rfid_proto_icode.c
@@ -0,0 +1,120 @@
+
+/* Philips/NXP I*Code implementation, PCD side.
+ *
+ * (C) 2005-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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <librfid/rfid.h>
+#include <librfid/rfid_protocol.h>
+#include <librfid/rfid_layer2.h>
+#include <librfid/rfid_layer2_icode1.h>
+#include <librfid/rfid_protocol_icode.h>
+
+static int
+icode_read(struct rfid_protocol_handle *ph, unsigned int page,
+ unsigned char *rx_data, unsigned int *rx_len)
+{
+ unsigned char rx_buf[16];
+ unsigned int real_rx_len = sizeof(rx_buf);
+ unsigned char tx[2];
+ int ret;
+
+ /* FIXME */
+ return -EINVAL;
+}
+
+static int
+icode_write(struct rfid_protocol_handle *ph, unsigned int page,
+ unsigned char *tx_data, unsigned int tx_len)
+{
+ unsigned int i;
+ unsigned char tx[6];
+ unsigned char rx[10];
+ unsigned int rx_len = sizeof(rx);
+ int ret;
+
+ return -EINVAL;
+}
+
+static int
+icode_getopt(struct rfid_protocol_handle *ph, int optname, void *optval,
+ unsigned int *optlen)
+{
+ int ret = -EINVAL;
+ unsigned int *size = optval;
+
+ switch (optname) {
+ case RFID_OPT_PROTO_SIZE:
+ ret = 0;
+ /* we have to return the size in bytes, not bits */
+ /* FIXME: implement this */
+ *size = 12345;
+ break;
+ }
+
+ return ret;
+}
+
+
+static struct rfid_protocol_handle *
+icode_init(struct rfid_layer2_handle *l2h)
+{
+ struct rfid_protocol_handle *ph;
+ u_int8_t uid[6];
+ int uid_len = sizeof(uid);
+
+ if (l2h->l2->id != RFID_LAYER2_ICODE1)
+ return NULL;
+
+ /* According to "SCBU002 - November 2005 */
+ rfid_layer2_getopt(l2h, RFID_OPT_LAYER2_UID,
+ uid, &uid_len);
+ if (uid[5] != 0xe0 || uid[4] != 0x07)
+ return NULL;
+ if (l2h->uid_len != 6)
+ return NULL;
+
+ ph = malloc_protocol_handle(sizeof(struct rfid_protocol_handle));
+ return ph;
+}
+
+static int icode_fini(struct rfid_protocol_handle *ph)
+{
+ free_protocol_handle(ph);
+ return 0;
+}
+
+const struct rfid_protocol rfid_protocol_icode = {
+ .id = RFID_PROTOCOL_ICODE_SLI,
+ .name = "I*Code SLI",
+ .fn = {
+ .init = &icode_init,
+ .read = &icode_read,
+ .write = &icode_write,
+ .fini = &icode_fini,
+ .getopt = &icode_getopt,
+ },
+};
+
+/* Functions below are not (yet? covered in the generic librfid api */
diff --git a/src/rfid_proto_tagit.c b/src/rfid_proto_tagit.c
new file mode 100644
index 0000000..0388baa
--- /dev/null
+++ b/src/rfid_proto_tagit.c
@@ -0,0 +1,141 @@
+
+/* UNFINISHED TI Tag-it implementation, PCD side.
+ *
+ * (C) 2005-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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <librfid/rfid.h>
+#include <librfid/rfid_protocol.h>
+#include <librfid/rfid_layer2.h>
+#include <librfid/rfid_layer2_iso15693.h>
+#include <librfid/rfid_protocol_tagit.h>
+
+struct tagit_version {
+ u_int8_t version; /* bit 47..40 (last bit masked) of uid */
+ const char *name;
+};
+
+const struct tagit_version tagit_versions[] = {
+ {
+ .version = 0x00,
+ .name = "HF-I Plus Inlay",
+ }, {
+ .version = 0x80,
+ .name = "HF-I Plus Chip",
+ }, {
+ .version = 0xc0,
+ .name = "HF-I Standard Chip / Inlay",
+ }, {
+ .version = 0xc4,
+ .name = "HF-I Pro Chip / Inlay",
+ },
+};
+
+static int
+tagit_read(struct rfid_protocol_handle *ph, unsigned int page,
+ unsigned char *rx_data, unsigned int *rx_len)
+{
+ unsigned char rx_buf[16];
+ unsigned int real_rx_len = sizeof(rx_buf);
+ unsigned char tx[2];
+ int ret;
+
+ /* FIXME */
+ return -EINVAL;
+}
+
+static int
+tagit_write(struct rfid_protocol_handle *ph, unsigned int page,
+ unsigned char *tx_data, unsigned int tx_len)
+{
+ unsigned int i;
+ unsigned char tx[6];
+ unsigned char rx[10];
+ unsigned int rx_len = sizeof(rx);
+ int ret;
+
+ return -EINVAL;
+}
+
+static int
+tagit_getopt(struct rfid_protocol_handle *ph, int optname, void *optval,
+ unsigned int *optlen)
+{
+ int ret = -EINVAL;
+ unsigned int *size = optval;
+
+ switch (optname) {
+ case RFID_OPT_PROTO_SIZE:
+ ret = 0;
+ /* we have to return the size in bytes, not bits */
+ /* FIXME: implement this */
+ *size = 12345;
+ break;
+ }
+
+ return ret;
+}
+
+
+static struct rfid_protocol_handle *
+tagit_init(struct rfid_layer2_handle *l2h)
+{
+ struct rfid_protocol_handle *ph;
+ u_int8_t uid[6];
+ unsigned int uid_len = sizeof(uid);
+
+ if (l2h->l2->id != RFID_LAYER2_ISO15693)
+ return NULL;
+
+ /* According to "SCBU002 - November 2005 */
+ rfid_layer2_getopt(l2h, RFID_OPT_LAYER2_UID,
+ uid, &uid_len);
+ if (uid[5] != 0xe0 || uid[4] != 0x07)
+ return NULL;
+ if (l2h->uid_len != 6)
+ return NULL;
+
+ ph = malloc_protocol_handle(sizeof(struct rfid_protocol_handle));
+ return ph;
+}
+
+static int tagit_fini(struct rfid_protocol_handle *ph)
+{
+ free_protocol_handle(ph);
+ return 0;
+}
+
+const struct rfid_protocol rfid_protocol_tagit = {
+ .id = RFID_PROTOCOL_TAGIT,
+ .name = "TI Tag-it HF",
+ .fn = {
+ .init = &tagit_init,
+ .read = &tagit_read,
+ .write = &tagit_write,
+ .fini = &tagit_fini,
+ .getopt = &tagit_getopt,
+ },
+};
+
+/* Functions below are not (yet? covered in the generic librfid api */
diff --git a/src/rfid_protocol.c b/src/rfid_protocol.c
index 9d70e90..71c52ff 100644
--- a/src/rfid_protocol.c
+++ b/src/rfid_protocol.c
@@ -28,6 +28,7 @@ static const struct rfid_protocol *rfid_protocols[] = {
[RFID_PROTOCOL_MIFARE_CLASSIC] = &rfid_protocol_mfcl,
[RFID_PROTOCOL_MIFARE_UL] = &rfid_protocol_mful,
[RFID_PROTOCOL_TCL] = &rfid_protocol_tcl,
+ [RFID_PROTOCOL_TAGIT] = &rfid_protocol_tagit,
};
struct rfid_protocol_handle *
diff --git a/src/rfid_reader_cm5121.c b/src/rfid_reader_cm5121.c
index 053b953..f51cd82 100644
--- a/src/rfid_reader_cm5121.c
+++ b/src/rfid_reader_cm5121.c
@@ -366,6 +366,16 @@ cm5121_close(struct rfid_reader_handle *rh)
free_reader_handle(rh);
}
+static int
+cm5121_iso15693_transceive_ac(struct rfid_reader_handle *rh,
+ struct iso15693_anticol_cmd *acf,
+ unsigned char uuid[ISO15693_UID_LEN],
+ char *bit_of_col)
+{
+ return rh->ah->asic->priv.rc632.fn.iso15693.transceive_ac(
+ rh->ah, acf, uuid, bit_of_col);
+}
+
const struct rfid_reader rfid_reader_cm5121 = {
.name = "Omnikey CardMan 5121 RFID",
.open = &cm5121_open,
@@ -391,6 +401,7 @@ const struct rfid_reader rfid_reader_cm5121 = {
},
.iso15693 = {
.init = &cm5121_15693_init,
+ .transceive_ac = &cm5121_iso15693_transceive_ac,
},
.mifare_classic = {
.setkey = &cm5121_mifare_setkey,
diff --git a/src/rfid_reader_openpcd.c b/src/rfid_reader_openpcd.c
index 88c55ee..19ea7c2 100644
--- a/src/rfid_reader_openpcd.c
+++ b/src/rfid_reader_openpcd.c
@@ -58,6 +58,14 @@ static struct openpcd_hdr *rcv_hdr;
#include <usb.h>
#endif/*__MINGW32__*/
+#ifdef DEBUG_REGISTER
+#define DEBUGRC DEBUGPC
+#define DEBUGR DEBUGP
+#else
+#define DEBUGRC(x, args ...) do {} while(0)
+#define DEBUGR(x, args ...) do {} while(0)
+#endif
+
static struct usb_device *dev;
static struct usb_dev_handle *hdl;
@@ -138,13 +146,13 @@ static int openpcd_reg_write(struct rfid_asic_transport_handle *rath,
{
int ret;
- DEBUGP("reg=0x%02x, val=%02x: ", reg, value);
+ DEBUGR("reg=0x%02x, val=%02x: ", reg, value);
ret = openpcd_xcv(OPENPCD_CMD_WRITE_REG, reg, value, 0, NULL);
if (ret < 0)
- DEBUGPC("ERROR sending command\n");
+ DEBUGRC("ERROR sending command\n");
else
- DEBUGPC("OK\n");
+ DEBUGRC("OK\n");
return ret;
}
@@ -155,21 +163,21 @@ static int openpcd_reg_read(struct rfid_asic_transport_handle *rath,
{
int ret;
- DEBUGP("reg=0x%02x, ", reg);
+ DEBUGR("reg=0x%02x, ", reg);
ret = openpcd_xcv(OPENPCD_CMD_READ_REG, reg, 0, 0, NULL);
if (ret < 0) {
- DEBUGPC("ERROR sending command\n");
+ DEBUGRC("ERROR sending command\n");
return ret;
}
if (ret < sizeof(struct openpcd_hdr)) {
- DEBUGPC("ERROR: short packet\n");
+ DEBUGRC("ERROR: short packet\n");
return ret;
}
*value = rcv_hdr->val;
- DEBUGPC("val=%02x: OK\n", *value);
+ DEBUGRC("val=%02x: OK\n", *value);
return ret;
}
@@ -180,17 +188,17 @@ static int openpcd_fifo_read(struct rfid_asic_transport_handle *rath,
{
int ret;
- DEBUGP(" ");
+ DEBUGR(" ");
ret = openpcd_xcv(OPENPCD_CMD_READ_FIFO, 0x00, num_bytes, 0, NULL);
if (ret < 0) {
- DEBUGPC("ERROR sending command\n");
+ DEBUGRC("ERROR sending command\n");
return ret;
}
- DEBUGPC("ret = %d\n", ret);
+ DEBUGRC("ret = %d\n", ret);
memcpy(buf, rcv_hdr->data, ret - sizeof(struct openpcd_hdr));
- DEBUGPC("len=%d val=%s: OK\n", ret - sizeof(struct openpcd_hdr),
+ DEBUGRC("len=%d val=%s: OK\n", ret - sizeof(struct openpcd_hdr),
rfid_hexdump(rcv_hdr->data, ret - sizeof(struct openpcd_hdr)));
return ret;
@@ -203,7 +211,7 @@ static int openpcd_fifo_write(struct rfid_asic_transport_handle *rath,
{
int ret;
- DEBUGP("len=%u, data=%s\n", len, rfid_hexdump(bytes, len));
+ DEBUGR("len=%u, data=%s\n", len, rfid_hexdump(bytes, len));
ret = openpcd_xcv(OPENPCD_CMD_WRITE_FIFO, 0, 0, len, bytes);
return ret;
@@ -374,6 +382,16 @@ openpcd_transceive_acf(struct rfid_reader_handle *rh,
}
static int
+openpcd_iso15693_transceive_ac(struct rfid_reader_handle *rh,
+ struct iso15693_anticol_cmd *acf, unsigned char uuid[ISO15693_UID_LEN],
+ char *bit_of_col)
+{
+ return rh->ah->asic->priv.rc632.fn.iso15693.transceive_ac(
+ rh->ah, acf, uuid, bit_of_col);
+}
+
+
+static int
openpcd_14443a_init(struct rfid_reader_handle *rh)
{
return rh->ah->asic->priv.rc632.fn.iso14443a.init(rh->ah);
@@ -562,6 +580,7 @@ const struct rfid_reader rfid_reader_openpcd = {
},
.iso15693 = {
.init = &openpcd_15693_init,
+ .transceive_ac = &openpcd_iso15693_transceive_ac,
},
.mifare_classic = {
.setkey = &openpcd_mifare_setkey,
diff --git a/src/rfid_reader_spidev.c b/src/rfid_reader_spidev.c
index b0676eb..b704e9b 100644
--- a/src/rfid_reader_spidev.c
+++ b/src/rfid_reader_spidev.c
@@ -260,6 +260,15 @@ static int spidev_15693_init(struct rfid_reader_handle *rh)
return rh->ah->asic->priv.rc632.fn.iso15693.init(rh->ah);
}
+static int spidev_15693_transceive_ac(struct rfid_reader_handle *rh,
+ struct iso15693_anticol_cmd *acf,
+ unsigned char uuid[ISO15693_UID_LEN],
+ char *bit_of_col)
+{
+ return rh->ah->asic->priv.rc632.fn.iso15693.transceive_ac(
+ rh->ah, acf, uuid, bit_of_col);
+}
+
static int
spidev_mifare_setkey(struct rfid_reader_handle *rh, const u_int8_t * key)
{
@@ -387,6 +396,10 @@ struct rfid_reader rfid_reader_spidev = {
.iso14443b = {
.init = &spidev_14443b_init,
},
+ .iso15693 = {
+ .init = &spidev_15693_init,
+ .transceive_ac = &spidev_15693_transceive_ac,
+ },
.mifare_classic = {
.setkey = &spidev_mifare_setkey,
.auth = &spidev_mifare_auth,
personal git repositories of Harald Welte. Your mileage may vary