summaryrefslogtreecommitdiff
path: root/openpicc/application/iso14443a_diffmiller.c
diff options
context:
space:
mode:
authorhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2008-03-14 18:29:28 +0000
committerhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2008-03-14 18:29:28 +0000
commitf7a420f2387b0bb660df08954d4bf35a66937203 (patch)
tree43d7ca7aef351e23bde9081bf7f41433b71ed3b3 /openpicc/application/iso14443a_diffmiller.c
parentb7a11d3b34aebfc77addfcd2ef7803c38d4e1dcc (diff)
Faked anticollision working now. During stress test (OpenPCD reqa firmware in anticol mode performing one cycle every 70ms) there were 52 late frames in 15992.
git-svn-id: https://svn.openpcd.org:2342/trunk@454 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
Diffstat (limited to 'openpicc/application/iso14443a_diffmiller.c')
-rw-r--r--openpicc/application/iso14443a_diffmiller.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/openpicc/application/iso14443a_diffmiller.c b/openpicc/application/iso14443a_diffmiller.c
index d73bf95..a36ea6b 100644
--- a/openpicc/application/iso14443a_diffmiller.c
+++ b/openpicc/application/iso14443a_diffmiller.c
@@ -101,6 +101,7 @@ struct diffmiller_state {
u_int32_t counter;
u_int16_t byte,crc;
u_int8_t parity;
+ u_int8_t last_data_bit;
struct {
u_int8_t in_frame:1;
u_int8_t frame_finished:1;
@@ -155,7 +156,7 @@ static inline void append_to_frame(struct diffmiller_state *const state,
}
-static inline void end_frame(struct diffmiller_state * const state, const u_int32_t counter)
+static inline void end_frame(struct diffmiller_state * const state, const u_int32_t counter, const int last_data_bit)
{
if(state->frame != NULL) {
if(counter > 0) {
@@ -167,6 +168,11 @@ static inline void end_frame(struct diffmiller_state * const state, const u_int3
else
state->frame->parameters.a.crc = CRC_ERROR;
+ if(last_data_bit)
+ state->frame->parameters.a.last_bit = ISO14443A_LAST_BIT_1;
+ else
+ state->frame->parameters.a.last_bit = ISO14443A_LAST_BIT_0;
+
state->flags.frame_finished = 1;
}
}
@@ -175,6 +181,7 @@ static inline void end_frame(struct diffmiller_state * const state, const u_int3
//#define PRINT_BIT(a) usb_print_string_f(a,0)
#define DO_BIT_0 { \
+ last_data_bit = 0; \
if(++counter==9) { \
append_to_frame(state, state->byte, 0, 8); \
counter=state->byte=state->parity=0; \
@@ -183,6 +190,7 @@ static inline void end_frame(struct diffmiller_state * const state, const u_int3
}
#define DO_BIT_1 { \
+ last_data_bit = 1; \
if(counter<8) { \
state->byte |= (1<<counter); \
state->parity ^= 1; \
@@ -218,7 +226,7 @@ static inline void end_frame(struct diffmiller_state * const state, const u_int3
in_frame = 0; \
} else { \
if(last_bit == BIT_0) { \
- end_frame(state, counter); \
+ end_frame(state, counter, last_data_bit); \
PRINT_BIT(" EOF\n"); \
last_bit = BIT_EOF; \
in_frame = 0; \
@@ -255,6 +263,7 @@ int iso14443a_decode_diffmiller(struct diffmiller_state * const state, iso14443_
int in_frame = state->flags.in_frame;
int error = state->flags.error;
int counter = state->counter;
+ int last_data_bit = state->last_data_bit;
for(; *offset < buflen; ) {
int delta;
@@ -324,6 +333,7 @@ int iso14443a_decode_diffmiller(struct diffmiller_state * const state, iso14443_
state->old_state = old_state;
state->last_bit = last_bit;
state->counter = counter;
+ state->last_data_bit = last_data_bit;
state->flags.in_frame = in_frame;
state->flags.error = error;
@@ -338,7 +348,7 @@ int iso14443a_diffmiller_assert_frame_ended(struct diffmiller_state * const stat
if(state->frame != NULL && state->frame != frame) return -EINVAL;
state->frame = frame;
- end_frame(state, state->counter);
+ end_frame(state, state->counter, state->last_data_bit);
PRINT_BIT(" EOF2\n");
state->flags.in_frame = 0;
personal git repositories of Harald Welte. Your mileage may vary