Skip to content

Commit

Permalink
timeout in listening window EM4x50
Browse files Browse the repository at this point in the history
  • Loading branch information
iceman1001 committed Sep 5, 2020
1 parent d6548d1 commit 6aa65b7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions armsrc/em4x50.c
Expand Up @@ -90,6 +90,7 @@ static em4x50_tag_t tag = {
#define EM4X50_COMMAND_WRITE_PASSWORD 0x11
#define EM4X50_COMMAND_SELECTIVE_READ 0x0A

#define EM4X50_COMMAND_TIMEOUT 5000
#define FPGA_TIMER_0 0

int gHigh = 0;
Expand Down Expand Up @@ -412,13 +413,13 @@ static void em4x50_send_word(const uint8_t bytes[4]) {
em4x50_send_bit(0);
}

static bool find_single_listen_window(void) {
static bool find_single_listen_window(int16_t timeout) {

// find single listen window

int cnt_pulses = 0;

while (cnt_pulses < EM4X50_T_WAITING_FOR_SNGLLIW) {
while (cnt_pulses < EM4X50_T_WAITING_FOR_SNGLLIW && timeout--) {

// identification of listen window is done via evaluation of
// pulse lengths
Expand All @@ -440,7 +441,7 @@ static bool find_single_listen_window(void) {
return false;
}

static bool find_double_listen_window(bool bcommand) {
static bool find_double_listen_window(bool bcommand, int16_t timeout) {

// find two successive listen windows that indicate the beginning of
// data transmission
Expand All @@ -450,7 +451,7 @@ static bool find_double_listen_window(bool bcommand) {

int cnt_pulses = 0;

while (cnt_pulses < EM4X50_T_WAITING_FOR_DBLLIW) {
while (cnt_pulses < EM4X50_T_WAITING_FOR_DBLLIW && timeout--) {

// identification of listen window is done via evaluation of
// pulse lengths
Expand Down Expand Up @@ -507,7 +508,7 @@ static bool find_em4x50_tag(void) {
// function is used to check wether a tag on the proxmark is an
// EM4x50 tag or not -> speed up "lf search" process

return (find_single_listen_window());
return (find_single_listen_window(EM4X50_COMMAND_TIMEOUT));

}

Expand All @@ -519,7 +520,7 @@ static bool request_receive_mode(void) {

bool bcommand = true;

return find_double_listen_window(bcommand);
return find_double_listen_window(bcommand, EM4X50_COMMAND_TIMEOUT);
}

static bool check_ack(bool bliw) {
Expand Down Expand Up @@ -725,7 +726,7 @@ static bool standard_read(int *now) {
uint8_t bits[EM4X50_TAG_WORD] = {0};

// start with the identification of two succsessive listening windows
if (find_double_listen_window(false)) {
if (find_double_listen_window(false, EM4X50_COMMAND_TIMEOUT)) {

// read and save words until following double listen window is detected
while (get_word_from_bitstream(bits) == EM4X50_TAG_WORD)
Expand Down

0 comments on commit 6aa65b7

Please sign in to comment.