From 4437c52ba1444509babd11aaa6d6373f419387c2 Mon Sep 17 00:00:00 2001 From: laforge Date: Wed, 16 Aug 2006 22:11:21 +0000 Subject: - fix treatment of rx_length in low-level transceive routines git-svn-id: https://svn.gnumonks.org/trunk/librfid@1870 e0336214-984f-0b4b-a45f-81c69e1f0ede --- src/rfid_asic_rc632.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/rfid_asic_rc632.c b/src/rfid_asic_rc632.c index 666c69e..ac3df2c 100644 --- a/src/rfid_asic_rc632.c +++ b/src/rfid_asic_rc632.c @@ -362,6 +362,7 @@ rc632_transceive(struct rfid_asic_handle *handle, unsigned int toggle) { int ret, cur_tx_len; + u_int8_t rx_avail; const u_int8_t *cur_tx_buf = tx_buf; DEBUGP("timer = %u\n", timer); @@ -414,11 +415,16 @@ rc632_transceive(struct rfid_asic_handle *handle, if (ret < 0) return ret; - ret = rc632_reg_read(handle, RC632_REG_FIFO_LENGTH, rx_len); + ret = rc632_reg_read(handle, RC632_REG_FIFO_LENGTH, &rx_avail); if (ret < 0) return ret; - if (*rx_len == 0) { + if (rx_avail > *rx_len) + printf("rx_avail(%d) > rx_len(%d), JFYI\n", rx_avail, *rx_len); + else if (*rx_len > rx_avail) + *rx_len = rx_avail; + + if (rx_avail == 0) { u_int8_t tmp; DEBUGP("rx_len == 0\n"); @@ -430,6 +436,7 @@ rc632_transceive(struct rfid_asic_handle *handle, } return rc632_fifo_read(handle, *rx_len, rx_buf); + /* FIXME: discard addidional bytes in FIFO */ } static int @@ -807,9 +814,14 @@ rc632_iso14443ab_transceive(struct rfid_asic_handle *handle, u_int64_t timeout, unsigned int flags) { int ret; - u_int8_t rxl = *rx_len & 0xff; + u_int8_t rxl; u_int8_t channel_red; + if (*rx_len > 0xff) + rxl = 0xff; + else + rxl = *rx_len; + memset(rx_buf, 0, *rx_len); switch (frametype) { -- cgit v1.2.3