diff options
-rw-r--r-- | openpicc/application/iso14443_layer3a.c | 14 | ||||
-rw-r--r-- | openpicc/application/iso14443_layer3a.h | 3 | ||||
-rw-r--r-- | openpicc/application/iso14443a_miller.c | 4 | ||||
-rw-r--r-- | openpicc/application/ssc_picc.c | 18 | ||||
-rw-r--r-- | openpicc/application/ssc_picc.h | 3 |
5 files changed, 24 insertions, 18 deletions
diff --git a/openpicc/application/iso14443_layer3a.c b/openpicc/application/iso14443_layer3a.c index e3ce769..57a7c23 100644 --- a/openpicc/application/iso14443_layer3a.c +++ b/openpicc/application/iso14443_layer3a.c @@ -43,7 +43,7 @@ static enum ISO14443_STATES state = STARTING_UP; const iso14443_frame ATQA_FRAME = { TYPE_A, - {{STANDARD_FRAME, PARITY}}, + {{STANDARD_FRAME, PARITY, ISO14443A_LAST_BIT_NONE}}, 2, 0, 0, {4, 0}, @@ -52,7 +52,7 @@ const iso14443_frame ATQA_FRAME = { const iso14443_frame NULL_FRAME = { TYPE_A, - {{STANDARD_FRAME, PARITY}}, + {{STANDARD_FRAME, PARITY, ISO14443A_LAST_BIT_NONE}}, 4, 0, 0, //{0xF3, 0xFB, 0xAE, 0xED}, @@ -66,8 +66,8 @@ const iso14443_frame NULL_FRAME = { #define LAYER3_DEBUG usb_print_string -#define INITIAL_STATE IDLE -//#define INITIAL_STATE ACTIVE +//#define INITIAL_STATE IDLE +#define INITIAL_STATE ACTIVE #if INITIAL_STATE == IDLE #define INITIAL_FRAME ATQA_FRAME @@ -307,12 +307,14 @@ void iso14443_layer3a_state_machine (void *pvParameters) vLedBlinkGreen(); if(1) { int i = usb_print_set_default_flush(0); - DumpBufferToUSB((char*)buffer->data, buffer->len/8); + DumpBufferToUSB((char*)buffer->data, (buffer->len+7)/8); DumpStringToUSB(" Decoded: "); DumpUIntToUSB(buffer->len); DumpStringToUSB(" "); - iso14443a_decode_miller(&received_frame, buffer->data, buffer->len/8); + iso14443a_decode_miller(&received_frame, buffer->data, (buffer->len+7)/8); DumpBufferToUSB((char*)received_frame.data, received_frame.numbytes + (received_frame.numbits+7)/8); + DumpStringToUSB(" "); + DumpUIntToUSB(received_frame.parameters.a.last_bit); DumpStringToUSB("\n\r"); usb_print_set_default_flush(i); } diff --git a/openpicc/application/iso14443_layer3a.h b/openpicc/application/iso14443_layer3a.h index 9b00ccb..a31c92f 100644 --- a/openpicc/application/iso14443_layer3a.h +++ b/openpicc/application/iso14443_layer3a.h @@ -100,7 +100,8 @@ typedef struct { enum { PARITY, /* Calculate parity on the fly, ignore the parity field below */ GIVEN_PARITY, /* Use the parity bits from the parity field below */ NO_PARITY, /* Don't send any parity */ - } parity; + } parity; + enum { ISO14443A_LAST_BIT_0 = 0, ISO14443A_LAST_BIT_1 = 1, ISO14443A_LAST_BIT_NONE } last_bit; } a; } parameters; u_int32_t numbytes; diff --git a/openpicc/application/iso14443a_miller.c b/openpicc/application/iso14443a_miller.c index 16f0c89..d7c24cd 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 = -1; + signed int i, j, bit = 0, last_bit = -1, next_to_last_bit = 0; enum miller_sequence current_seq; unsigned int bitpos = 0; @@ -88,6 +88,7 @@ int iso14443a_decode_miller(iso14443_frame *frame, switch(bit) { case BIT_ENDMARKER: bitpos-=2; /* Subtract this sequence and the previous sequence (which was a 0) */ + frame->parameters.a.last_bit = next_to_last_bit; break; case 0: /* Fall-through */ case 1: { @@ -100,6 +101,7 @@ int iso14443a_decode_miller(iso14443_frame *frame, } } + next_to_last_bit = last_bit; last_bit = bit; bitpos++; } diff --git a/openpicc/application/ssc_picc.c b/openpicc/application/ssc_picc.c index 09be1e5..520098d 100644 --- a/openpicc/application/ssc_picc.c +++ b/openpicc/application/ssc_picc.c @@ -72,16 +72,16 @@ static struct ssc_state ssc_state; * the SSC supports different sizes, all PDC tranfers will be either 8, 16 or 32, rounding up.) */ static const ssc_mode_def ssc_sizes[] = { /* Undefined, no size set */ - [SSC_MODE_NONE] = {SSC_MODE_NONE, 0, 0}, + [SSC_MODE_NONE] = {SSC_MODE_NONE, 0, 0, 0}, /* 14443A Short Frame: 1 transfer of ISO14443A_SHORT_LEN bits */ - [SSC_MODE_14443A_SHORT] = {SSC_MODE_14443A_SHORT, ISO14443A_SHORT_TRANSFER_SIZE, 1}, + [SSC_MODE_14443A_SHORT] = {SSC_MODE_14443A_SHORT, ISO14443A_SHORT_LEN, ISO14443A_SHORT_TRANSFER_SIZE, 1}, /* 14443A Standard Frame: FIXME 16 transfers of 32 bits (maximum number), resulting in 512 samples */ - [SSC_MODE_14443A_STANDARD] = {SSC_MODE_14443A_STANDARD, 32, 16}, + [SSC_MODE_14443A_STANDARD] = {SSC_MODE_14443A_STANDARD, 32, 32, 16}, /* 14443A Frame, don't care if standard or short */ - [SSC_MODE_14443A] = {SSC_MODE_14443A, ISO14443A_SAMPLE_LEN, ISO14443A_MAX_RX_FRAME_SIZE_IN_BITS}, - [SSC_MODE_14443B] = {SSC_MODE_14443B, 32, 16}, /* 64 bytes */ - [SSC_MODE_EDGE_ONE_SHOT] = {SSC_MODE_EDGE_ONE_SHOT, 32, 16}, /* 64 bytes */ - [SSC_MODE_CONTINUOUS] = {SSC_MODE_CONTINUOUS, 32, 511}, /* 2044 bytes */ + [SSC_MODE_14443A] = {SSC_MODE_14443A, ISO14443A_SAMPLE_LEN, 8, ISO14443A_MAX_RX_FRAME_SIZE_IN_BITS}, + [SSC_MODE_14443B] = {SSC_MODE_14443B, 32, 32, 16}, /* 64 bytes */ + [SSC_MODE_EDGE_ONE_SHOT] = {SSC_MODE_EDGE_ONE_SHOT, 32, 32, 16}, /* 64 bytes */ + [SSC_MODE_CONTINUOUS] = {SSC_MODE_CONTINUOUS, 32, 32, 511}, /* 2044 bytes */ }; /* ************** SSC BUFFER HANDLING *********************** */ @@ -154,7 +154,7 @@ static int __ramfunc __ssc_rx_load(int secondary) } DEBUGR("filling SSC RX%u dma ctx: %u (len=%u) ", secondary, req_ctx_num(buffer), buffer->size); - buffer->len = ssc_sizes[ssc_state.mode].transfersize * ssc_sizes[ssc_state.mode].transfers; + buffer->len = ssc_sizes[ssc_state.mode].transfersize_ssc * ssc_sizes[ssc_state.mode].transfers; buffer->reception_mode = &ssc_sizes[ssc_state.mode]; if(ssc_state.buffer[secondary] != NULL) { @@ -202,7 +202,7 @@ 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_int16_t elapsed_transfers = buffer->reception_mode->transfers - remaining_transfers; - u_int32_t elapsed_size = buffer->reception_mode->transfersize/8 * elapsed_transfers; + u_int32_t elapsed_size = buffer->reception_mode->transfersize_pdc/8 * elapsed_transfers; /* Consistency check */ if( next_transfer_location - elapsed_size != buffer->data ) { diff --git a/openpicc/application/ssc_picc.h b/openpicc/application/ssc_picc.h index 9600bab..937cab5 100644 --- a/openpicc/application/ssc_picc.h +++ b/openpicc/application/ssc_picc.h @@ -67,7 +67,8 @@ typedef enum { typedef struct { enum ssc_mode mode; - u_int16_t transfersize; + u_int16_t transfersize_ssc; + u_int16_t transfersize_pdc; u_int16_t transfers; } ssc_mode_def; |