#include <string.h>
#include <errno.h>
-#include <rfid/rfid.h>
-#include <rfid/rfid_protocol_tcl.h>
-#include <rfid/rfid_protocol.h>
-#include <rfid/rfid_layer2.h>
-#include <rfid/rfid_layer2_iso14443b.h>
+#include <librfid/rfid.h>
+#include <librfid/rfid_protocol_tcl.h>
+#include <librfid/rfid_protocol.h>
+#include <librfid/rfid_layer2.h>
+#include <librfid/rfid_layer2_iso14443b.h>
-#include <rfid/rfid_asic.h>
-#include <rfid/rfid_reader.h>
+#include <librfid/rfid_asic.h>
+#include <librfid/rfid_reader.h>
#include "rfid_iso14443_common.h"
-#if 1
+#if 0
#ifdef DEBUGP
#undef DEBUGP
#define DEBUGP(x, ...)
+#endif
+#ifdef DEBUGPC
+#undef DEBUGPC
#define DEBUGPC(x, ...)
#endif
#endif
rats[1] = (h->priv.tcl.cid & 0x0f) | ((fsdi << 4) & 0xf0);
/* transcieve (with CRC) */
- ret = h->l2h->l2->fn.transcieve(h->l2h, RFID_14443A_FRAME_REGULAR,
- rats, 2, h->priv.tcl.ats,
- &h->priv.tcl.ats_len, activation_fwt(h),
- TCL_TRANSP_F_TX_CRC);
+ ret = rfid_layer2_transcieve(h->l2h, RFID_14443A_FRAME_REGULAR,
+ rats, 2, h->priv.tcl.ats,
+ &h->priv.tcl.ats_len, activation_fwt(h),
+ TCL_TRANSP_F_TX_CRC);
if (ret < 0) {
DEBUGP("transcieve of rats failed\n");
h->priv.tcl.state = TCL_STATE_RATS_SENT;
static char DI;
unsigned int speed = h->l2h->rh->reader->iso14443a.speed;
- if ((D & ATS_TA_DIV_8) && (speed & RFID_READER_SPEED_848K))
+ if ((D & ATS_TA_DIV_8) && (speed & RFID_14443A_SPEED_848K))
DI = PPS_DIV_8;
- else if ((D & ATS_TA_DIV_4) && (speed & RFID_READER_SPEED_424K))
+ else if ((D & ATS_TA_DIV_4) && (speed & RFID_14443A_SPEED_424K))
DI = PPS_DIV_4;
- else if ((D & ATS_TA_DIV_2) && (speed & RFID_READER_SPEED_212K))
+ else if ((D & ATS_TA_DIV_2) && (speed & RFID_14443A_SPEED_212K))
DI = PPS_DIV_2;
else
DI = PPS_DIV_1;
return DI;
}
+static unsigned int di_to_speed(unsigned char DI)
+{
+ switch (DI) {
+ case PPS_DIV_8:
+ return RFID_14443A_SPEED_848K;
+ break;
+ case PPS_DIV_4:
+ return RFID_14443A_SPEED_424K;
+ break;
+ case PPS_DIV_2:
+ return RFID_14443A_SPEED_212K;
+ break;
+ case PPS_DIV_1:
+ return RFID_14443A_SPEED_106K;
+ break;
+ }
+}
-/* start a PSS run (autimatically configure highest possible speed */
+/* start a PPS run (autimatically configure highest possible speed */
static int
tcl_do_pps(struct rfid_protocol_handle *h)
{
-#if 0
int ret;
unsigned char ppss[3];
unsigned char pps_response[1];
unsigned int rx_len = 1;
unsigned char Dr, Ds, DrI, DsI;
+ unsigned int speed;
if (h->priv.tcl.state != TCL_STATE_ATS_RCVD)
return -1;
Dr = h->priv.tcl.ta & 0x07;
Ds = h->priv.tcl.ta & 0x70 >> 4;
+ DEBUGP("Dr = 0x%x, Ds = 0x%x\n", Dr, Ds);
if (Dr != Ds && !(h->priv.tcl.ta & 0x80)) {
- /* device supports different divisors for rx and tx, but not ?!? */
+ /* device supports different divisors for rx and tx, but not
+ * really ?!? */
DEBUGP("PICC has contradictory TA, aborting PPS\n");
return -1;
};
/* ISO 14443-4:2000(E) Section 5.3. */
- ppss[0] = 0xd0 & (h->priv.tcl.cid & 0x0f);
+ ppss[0] = 0xd0 | (h->priv.tcl.cid & 0x0f);
ppss[1] = 0x11;
/* FIXME: deal with different speed for each direction */
DrI = d_to_di(h, Dr);
DsI = d_to_di(h, Ds);
+ DEBUGP("DrI = 0x%x, DsI = 0x%x\n", DrI, DsI);
ppss[2] = (ppss[2] & 0xf0) | (DrI | DsI << 2);
- ret = h->l2h->l2->fn.transcieve(h->l2h, ppss, 3, pps_response,
- &rx_len, h->priv.tcl.fwt,
- TCL_TRANSP_F_TX_CRC);
+ ret = rfid_layer2_transcieve(h->l2h, RFID_14443A_FRAME_REGULAR,
+ ppss, 3, pps_response, &rx_len,
+ h->priv.tcl.fwt, TCL_TRANSP_F_TX_CRC);
if (ret < 0)
return ret;
DEBUGP("PPS Response != PPSS\n");
return -1;
}
+
+ speed = di_to_speed(DrI);
+
+ ret = rfid_layer2_setopt(h->l2h, RFID_OPT_14443A_SPEED_RX,
+ &speed, sizeof(speed));
+ if (ret < 0)
+ return ret;
+
+ ret = rfid_layer2_setopt(h->l2h, RFID_OPT_14443A_SPEED_TX,
+ &speed, sizeof(speed));
+ if (ret < 0)
+ return ret;
- h->priv.tcl.state = TCL_STATE_ESTABLISHED;
-#endif
return 0;
}
break;
}
+ h->priv.tcl.state = TCL_STATE_ESTABLISHED;
+
return 0;
}
if (ret < 0)
return ret;
- ret = h->l2h->l2->fn.transcieve(h->l2h, RFID_14443A_FRAME_REGULAR,
- frame, prlg_len, rx,
+ ret = rfid_layer2_transcieve(h->l2h, RFID_14443A_FRAME_REGULAR,
+ frame, prlg_len, rx,
&rx_len, deactivation_fwt(h),
TCL_TRANSP_F_TX_CRC);
if (ret < 0) {
*rx_len = 0;
do_tx:
- ret = h->l2h->l2->fn.transcieve(h->l2h, l2_to_frame(h->l2h->l2->id),
- _tx, _tx_len,
- rx_buf, &_rx_len, _timeout, 0);
+ ret = rfid_layer2_transcieve(h->l2h, l2_to_frame(h->l2h->l2->id),
+ _tx, _tx_len,
+ rx_buf, &_rx_len, _timeout, 0);
DEBUGP("l2 transcieve finished\n");
if (ret < 0)
goto out_rxb;
net_payload_len = _rx_len - (inf - rx_buf);
DEBUGPC("%u bytes\n", net_payload_len);
memcpy(_rx_data, inf, net_payload_len);
- /* increment the number of payload bytes that we actually received */
+ /* increment the number of payload bytes that we actually
+ * received */
*rx_len += net_payload_len;
_rx_data += net_payload_len;
if (*rx_buf & 0x10) {
/* we're not the last frame in the chain, continue rx */
- DEBUGP("we're not the last frame in the chain, continue\n");
+ DEBUGP("not the last frame in the chain, continue\n");
ack_len = sizeof(ack);
tcl_build_prologue_r(&h->priv.tcl, ack, &ack_len, 0);
_tx = ack;