From bcc75d30ce0fb09618f82bb70cdde82094e86ed8 Mon Sep 17 00:00:00 2001 From: henryk Date: Sat, 15 Dec 2007 12:52:35 +0000 Subject: Fix consistency check Fix miller decoder for the case of a buffer containing only zeroes git-svn-id: https://svn.openpcd.org:2342/trunk@388 6dc7ffe9-61d6-0310-9af1-9938baff3ed1 --- openpicc/application/iso14443_layer3a.c | 25 +++++++++++-------------- openpicc/application/iso14443a_miller.c | 5 ++--- openpicc/application/ssc_picc.c | 10 ++++++++-- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/openpicc/application/iso14443_layer3a.c b/openpicc/application/iso14443_layer3a.c index 7d91250..b9ee0b9 100644 --- a/openpicc/application/iso14443_layer3a.c +++ b/openpicc/application/iso14443_layer3a.c @@ -297,6 +297,17 @@ void iso14443_layer3a_state_machine (void *pvParameters) main_help_print_buffer(buffer, &pktcount); } vLedBlinkGreen(); + if(1) { + int i = usb_print_set_default_flush(0); + DumpBufferToUSB((char*)buffer->data, buffer->len/8); + DumpStringToUSB(" Decoded: "); + DumpUIntToUSB(buffer->len); + DumpStringToUSB(" "); + iso14443a_decode_miller(&received_frame, buffer->data, buffer->len/8); + DumpBufferToUSB((char*)received_frame.data, received_frame.numbytes + (received_frame.numbits+7)/8); + DumpStringToUSB("\n\r"); + usb_print_set_default_flush(i); + } switch(state) { case IDLE: @@ -309,14 +320,6 @@ void iso14443_layer3a_state_machine (void *pvParameters) LAYER3_DEBUG(", woke up to send ATQA\n\r"); atqa_sent = 0; } - if(1) { - DumpStringToUSB("Decoded: "); - DumpUIntToUSB(buffer->len); - DumpStringToUSB(" "); - iso14443a_decode_miller(&received_frame, buffer->data, buffer->len/8); - DumpBufferToUSB((char*)received_frame.data, received_frame.numbytes + (received_frame.numbits+7)/8); - DumpStringToUSB("\n\r"); - } /* For debugging, wait 1ms, then wait for another frame * Normally we'd go to anticol from here*/ vTaskDelay(portTICK_RATE_MS); @@ -330,12 +333,6 @@ void iso14443_layer3a_state_machine (void *pvParameters) break; case ACTIVE: case ACTIVE_STAR: -#if 0 - DumpStringToUSB("Decoded: "); - decoder_decode(DECODER_MILLER, (const char*)buffer->data, buffer->len, received_buffer); - DumpBufferToUSB((char*)received_buffer, 100); - DumpStringToUSB("\n\r"); -#endif /* Wait for another frame */ if(0) { ssc_rx_mode_set(SSC_MODE_14443A_STANDARD); diff --git a/openpicc/application/iso14443a_miller.c b/openpicc/application/iso14443a_miller.c index 3d132c2..16f0c89 100644 --- a/openpicc/application/iso14443a_miller.c +++ b/openpicc/application/iso14443a_miller.c @@ -51,7 +51,7 @@ enum miller_sequence { int iso14443a_decode_miller(iso14443_frame *frame, const u_int8_t *sample_buf, const u_int16_t sample_buf_len) { - signed int i, j, bit = 0, last_bit = 0; + signed int i, j, bit = 0, last_bit = -1; enum miller_sequence current_seq; unsigned int bitpos = 0; @@ -111,8 +111,7 @@ int iso14443a_decode_miller(iso14443_frame *frame, DumpUIntToUSB(frame->numbytes); DumpStringToUSB(" bytes, "); DumpUIntToUSB(frame->numbits); - DumpStringToUSB(" bits"); - DumpStringToUSB("\n\r"); + DumpStringToUSB(" bits "); return 0; } diff --git a/openpicc/application/ssc_picc.c b/openpicc/application/ssc_picc.c index 085fa48..721989f 100644 --- a/openpicc/application/ssc_picc.c +++ b/openpicc/application/ssc_picc.c @@ -199,9 +199,15 @@ static ssc_dma_rx_buffer_t* __ramfunc __ssc_rx_unload(int secondary) u_int16_t remaining_transfers = (secondary ? rx_pdc->PDC_RNCR : rx_pdc->PDC_RCR); u_int8_t* next_transfer_location = (u_int8_t*)(secondary ? rx_pdc->PDC_RNPR : rx_pdc->PDC_RPR); - u_int32_t remaining_size = buffer->reception_mode->transfersize * remaining_transfers; + u_int16_t elapsed_transfers = buffer->reception_mode->transfers - remaining_transfers; + u_int32_t elapsed_size = buffer->reception_mode->transfersize/8 * elapsed_transfers; + /* Consistency check */ - if( next_transfer_location - remaining_size != buffer->data ) { + if( next_transfer_location - elapsed_size != buffer->data ) { + int i=usb_print_set_default_flush(0); + DumpStringToUSB("!!! "); DumpUIntToUSB((int)next_transfer_location); DumpStringToUSB(" "); + DumpUIntToUSB(elapsed_size); DumpStringToUSB(" "); DumpUIntToUSB((int)buffer->data); DumpStringToUSB(" "); + usb_print_set_default_flush(i); ssc_buffer_errors++; if(buffer->state == PENDING) buffer->state = FREE; ssc_state.buffer[secondary] = NULL; -- cgit v1.2.3