mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-10 02:04:39 +08:00
defined stop condition for reading processes, otherwise pm 'crashes' if there's no tag on device
This commit is contained in:
parent
81cd478883
commit
9ce9a82803
1 changed files with 87 additions and 66 deletions
|
@ -75,6 +75,7 @@ static em4x50_tag_t tag = {
|
||||||
#define EM4X50_T_WAITING_FOR_LIW 500
|
#define EM4X50_T_WAITING_FOR_LIW 500
|
||||||
#define EM4X50_T_TAG_TPP 64
|
#define EM4X50_T_TAG_TPP 64
|
||||||
#define EM4X50_T_TAG_TWA 64
|
#define EM4X50_T_TAG_TWA 64
|
||||||
|
#define EM4X50_T_TAG_INIT 2112
|
||||||
|
|
||||||
#define EM4X50_TAG_TOLERANCE 8
|
#define EM4X50_TAG_TOLERANCE 8
|
||||||
#define EM4X50_TAG_WORD 45
|
#define EM4X50_TAG_WORD 45
|
||||||
|
@ -237,19 +238,34 @@ static void em4x50_setup_read(void) {
|
||||||
|
|
||||||
// functions for "reader" use case
|
// functions for "reader" use case
|
||||||
|
|
||||||
static void get_signalproperties(void) {
|
static bool get_signalproperties(void) {
|
||||||
|
|
||||||
// calculate signal properties (mean amplitudes) from measured data:
|
// calculate signal properties (mean amplitudes) from measured data:
|
||||||
// 32 amplitudes (maximum values) -> mean amplitude value -> gHigh -> gLow
|
// 32 amplitudes (maximum values) -> mean amplitude value -> gHigh -> gLow
|
||||||
|
|
||||||
|
bool signal_found = false;
|
||||||
int no_periods = 32, pct = 75, noise = 140;
|
int no_periods = 32, pct = 75, noise = 140;
|
||||||
uint8_t sample = 0, sample_ref = 127;
|
uint8_t sample = 0, sample_ref = 127;
|
||||||
uint8_t sample_max_mean = 0;
|
uint8_t sample_max_mean = 0;
|
||||||
uint8_t sample_max[no_periods];
|
uint8_t sample_max[no_periods];
|
||||||
uint32_t sample_max_sum = 0;
|
uint32_t sample_max_sum = 0;
|
||||||
|
|
||||||
// wait until signal/noise > 1
|
|
||||||
while (AT91C_BASE_SSC->SSC_RHR < noise);
|
// wait until signal/noise > 1 (max. 32 periods)
|
||||||
|
for (int i = 0; i < T0 * no_periods; i++) {
|
||||||
|
|
||||||
|
// about 2 samples per bit period
|
||||||
|
wait_timer(0, T0 * EM4X50_T_TAG_HALF_PERIOD);
|
||||||
|
|
||||||
|
if (AT91C_BASE_SSC->SSC_RHR > noise) {
|
||||||
|
signal_found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!signal_found)
|
||||||
|
return false;
|
||||||
|
|
||||||
// calculate mean maximum value of 32 periods, each period has a length of
|
// calculate mean maximum value of 32 periods, each period has a length of
|
||||||
// 3 single "full periods" to eliminate the influence of a listen window
|
// 3 single "full periods" to eliminate the influence of a listen window
|
||||||
|
@ -274,6 +290,7 @@ static void get_signalproperties(void) {
|
||||||
gHigh = sample_ref + pct * (sample_max_mean - sample_ref) / 100;
|
gHigh = sample_ref + pct * (sample_max_mean - sample_ref) / 100;
|
||||||
gLow = sample_ref - pct * (sample_max_mean - sample_ref) / 100;
|
gLow = sample_ref - pct * (sample_max_mean - sample_ref) / 100;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_next_bit(void) {
|
static int get_next_bit(void) {
|
||||||
|
@ -738,7 +755,7 @@ void em4x50_info(em4x50_data_t *etd) {
|
||||||
em4x50_setup_read();
|
em4x50_setup_read();
|
||||||
|
|
||||||
// set gHigh and gLow
|
// set gHigh and gLow
|
||||||
get_signalproperties();
|
if (get_signalproperties()) {
|
||||||
|
|
||||||
if (etd->pwd_given) {
|
if (etd->pwd_given) {
|
||||||
|
|
||||||
|
@ -753,6 +770,7 @@ void em4x50_info(em4x50_data_t *etd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bsuccess = selective_read(addresses);
|
bsuccess = selective_read(addresses);
|
||||||
|
}
|
||||||
|
|
||||||
status = (bsuccess << 1) + blogin;
|
status = (bsuccess << 1) + blogin;
|
||||||
|
|
||||||
|
@ -760,7 +778,7 @@ void em4x50_info(em4x50_data_t *etd) {
|
||||||
reply_ng(CMD_ACK, status, (uint8_t *)tag.sectors, 238);
|
reply_ng(CMD_ACK, status, (uint8_t *)tag.sectors, 238);
|
||||||
}
|
}
|
||||||
|
|
||||||
void em4x50_sread(em4x50_data_t *etd) {
|
void em4x50_read(em4x50_data_t *etd) {
|
||||||
|
|
||||||
// reads in two different ways:
|
// reads in two different ways:
|
||||||
// - using "selective read mode" -> bidirectional communication
|
// - using "selective read mode" -> bidirectional communication
|
||||||
|
@ -776,7 +794,7 @@ void em4x50_sread(em4x50_data_t *etd) {
|
||||||
em4x50_setup_read();
|
em4x50_setup_read();
|
||||||
|
|
||||||
// set gHigh and gLow
|
// set gHigh and gLow
|
||||||
get_signalproperties();
|
if (get_signalproperties()) {
|
||||||
|
|
||||||
if (etd->addr_given) {
|
if (etd->addr_given) {
|
||||||
|
|
||||||
|
@ -796,6 +814,7 @@ void em4x50_sread(em4x50_data_t *etd) {
|
||||||
bsuccess = standard_read(&now);
|
bsuccess = standard_read(&now);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
status = (now << 2) + (bsuccess << 1) + blogin;
|
status = (now << 2) + (bsuccess << 1) + blogin;
|
||||||
|
|
||||||
|
@ -896,7 +915,7 @@ void em4x50_write(em4x50_data_t *etd) {
|
||||||
em4x50_setup_read();
|
em4x50_setup_read();
|
||||||
|
|
||||||
// set gHigh and gLow
|
// set gHigh and gLow
|
||||||
get_signalproperties();
|
if (get_signalproperties()) {
|
||||||
|
|
||||||
// reorder word according to datasheet
|
// reorder word according to datasheet
|
||||||
msb2lsb_word(etd->word);
|
msb2lsb_word(etd->word);
|
||||||
|
@ -933,6 +952,7 @@ void em4x50_write(em4x50_data_t *etd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
status = (bsuccess << 1) + blogin;
|
status = (bsuccess << 1) + blogin;
|
||||||
|
|
||||||
|
@ -950,12 +970,13 @@ void em4x50_write_password(em4x50_data_t *etd) {
|
||||||
em4x50_setup_read();
|
em4x50_setup_read();
|
||||||
|
|
||||||
// set gHigh and gLow
|
// set gHigh and gLow
|
||||||
get_signalproperties();
|
if (get_signalproperties()) {
|
||||||
|
|
||||||
// login and change password
|
// login and change password
|
||||||
if (login(etd->password)) {
|
if (login(etd->password)) {
|
||||||
bsuccess = write_password(etd->password, etd->new_password);
|
bsuccess = write_password(etd->password, etd->new_password);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lf_finalize();
|
lf_finalize();
|
||||||
reply_ng(CMD_ACK, bsuccess, 0, 0);
|
reply_ng(CMD_ACK, bsuccess, 0, 0);
|
||||||
|
|
Loading…
Reference in a new issue