mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 10:37:23 -07:00
make style
This commit is contained in:
parent
8a602ed99d
commit
4ed57c7c4d
57 changed files with 878 additions and 878 deletions
278
armsrc/em4x50.c
278
armsrc/em4x50.c
|
@ -113,7 +113,7 @@ static uint8_t bits2byte(uint8_t *bits, int length) {
|
|||
|
||||
byte |= bits[i];
|
||||
|
||||
if (i != length-1)
|
||||
if (i != length - 1)
|
||||
byte <<= 1;
|
||||
}
|
||||
|
||||
|
@ -145,17 +145,17 @@ static void save_word(int pos, uint8_t bits[EM4X50_TAG_WORD]) {
|
|||
|
||||
// data and row parities
|
||||
for (int i = 0; i < 4; i++) {
|
||||
tag.sectors[pos][i] = bits2byte(&bits[9*i],8);
|
||||
row_parity[i] = bits[9*i+8];
|
||||
tag.sectors[pos][i] = bits2byte(&bits[9 * i], 8);
|
||||
row_parity[i] = bits[9 * i + 8];
|
||||
}
|
||||
|
||||
tag.sectors[pos][4] = bits2byte(row_parity,4);
|
||||
tag.sectors[pos][4] = bits2byte(row_parity, 4);
|
||||
|
||||
// column parities
|
||||
for (int i = 0; i < 8; i++)
|
||||
col_parity[i] = bits[36+i];
|
||||
col_parity[i] = bits[36 + i];
|
||||
|
||||
tag.sectors[pos][5] = bits2byte(col_parity,8);
|
||||
tag.sectors[pos][5] = bits2byte(col_parity, 8);
|
||||
|
||||
// stop bit
|
||||
tag.sectors[pos][6] = bits[44];
|
||||
|
@ -311,13 +311,13 @@ static int get_next_bit(void) {
|
|||
}
|
||||
|
||||
static uint32_t get_pulse_length(void) {
|
||||
|
||||
|
||||
// iterates pulse length (low -> high -> low)
|
||||
|
||||
|
||||
uint8_t sample = 0;
|
||||
|
||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
|
||||
|
||||
while (sample > gLow)
|
||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
|
||||
|
@ -333,20 +333,20 @@ static uint32_t get_pulse_length(void) {
|
|||
}
|
||||
|
||||
static bool check_pulse_length(uint32_t pl, int length) {
|
||||
|
||||
|
||||
// check if pulse length <pl> corresponds to given length <length>
|
||||
|
||||
|
||||
if ((pl >= T0 * (length - EM4X50_TAG_TOLERANCE)) &
|
||||
(pl <= T0 * (length + EM4X50_TAG_TOLERANCE)))
|
||||
(pl <= T0 * (length + EM4X50_TAG_TOLERANCE)))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
static void em4x50_send_bit(int bit) {
|
||||
|
||||
|
||||
// send single bit according to EM4x50 application note and datasheet
|
||||
|
||||
|
||||
// reset clock for the next bit
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||
|
||||
|
@ -361,13 +361,13 @@ static void em4x50_send_bit(int bit) {
|
|||
// half of bit period
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * EM4X50_T_TAG_HALF_PERIOD);
|
||||
|
||||
|
||||
// disable modulation for second half of bit period
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * EM4X50_T_TAG_FULL_PERIOD);
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// bit = "1" means disable modulation for full bit period
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * EM4X50_T_TAG_FULL_PERIOD);
|
||||
|
@ -377,20 +377,20 @@ static void em4x50_send_bit(int bit) {
|
|||
static void em4x50_send_byte(uint8_t byte) {
|
||||
|
||||
// send byte (without parity)
|
||||
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
em4x50_send_bit((byte >> (7-i)) & 1);
|
||||
em4x50_send_bit((byte >> (7 - i)) & 1);
|
||||
|
||||
}
|
||||
|
||||
static void em4x50_send_byte_with_parity(uint8_t byte) {
|
||||
|
||||
// send byte followed by its (equal) parity bit
|
||||
|
||||
|
||||
int parity = 0, bit = 0;
|
||||
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
bit = (byte >> (7-i)) & 1;
|
||||
bit = (byte >> (7 - i)) & 1;
|
||||
em4x50_send_bit(bit);
|
||||
parity ^= bit;
|
||||
}
|
||||
|
@ -399,12 +399,12 @@ static void em4x50_send_byte_with_parity(uint8_t byte) {
|
|||
}
|
||||
|
||||
static void em4x50_send_word(const uint8_t bytes[4]) {
|
||||
|
||||
|
||||
// send 32 bit word with parity bits according to EM4x50 datasheet
|
||||
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
em4x50_send_byte_with_parity(bytes[i]);
|
||||
|
||||
|
||||
// send column parities
|
||||
em4x50_send_byte(bytes[0] ^ bytes[1] ^ bytes[2] ^ bytes[3]);
|
||||
|
||||
|
@ -413,70 +413,70 @@ static void em4x50_send_word(const uint8_t bytes[4]) {
|
|||
}
|
||||
|
||||
static bool find_single_listen_window(void) {
|
||||
|
||||
|
||||
// find single listen window
|
||||
|
||||
|
||||
int cnt_pulses = 0;
|
||||
|
||||
|
||||
while (cnt_pulses < EM4X50_T_WAITING_FOR_SNGLLIW) {
|
||||
|
||||
|
||||
// identification of listen window is done via evaluation of
|
||||
// pulse lengths
|
||||
if (check_pulse_length(get_pulse_length(), 3 * EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
||||
|
||||
if (check_pulse_length(get_pulse_length(), 2 * EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
||||
|
||||
// listen window found
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
cnt_pulses++;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool find_double_listen_window(bool bcommand) {
|
||||
|
||||
|
||||
// find two successive listen windows that indicate the beginning of
|
||||
// data transmission
|
||||
// double listen window to be detected within 1600 pulses -> worst case
|
||||
// reason: first detectable double listen window after 34 words
|
||||
// -> 34 words + 34 single listen windows -> about 1600 pulses
|
||||
|
||||
|
||||
int cnt_pulses = 0;
|
||||
|
||||
|
||||
while (cnt_pulses < EM4X50_T_WAITING_FOR_DBLLIW) {
|
||||
|
||||
|
||||
// identification of listen window is done via evaluation of
|
||||
// pulse lengths
|
||||
if (check_pulse_length(get_pulse_length(), 3 * EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
||||
|
||||
if (check_pulse_length(get_pulse_length(), 2 * EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
||||
|
||||
// first listen window found
|
||||
|
||||
|
||||
if (bcommand) {
|
||||
|
||||
// data transmission from card has to be stopped, because
|
||||
// a commamd shall be issued
|
||||
|
||||
|
||||
// unfortunately the posititon in listen window (where
|
||||
// command request has to be sent) has gone, so if a
|
||||
// second window follows - sync on this to issue a command
|
||||
|
||||
|
||||
// skip the next bit...
|
||||
wait_timer(FPGA_TIMER_0, T0 * EM4X50_T_TAG_FULL_PERIOD);
|
||||
|
||||
|
||||
// ...and check if the following bit does make sense
|
||||
// (if not it is the correct position within the second
|
||||
// listen window)
|
||||
if (get_next_bit() == EM4X50_BIT_OTHER) {
|
||||
|
||||
|
||||
// send RM for request mode
|
||||
em4x50_send_bit(0);
|
||||
em4x50_send_bit(0);
|
||||
|
@ -498,47 +498,47 @@ static bool find_double_listen_window(bool bcommand) {
|
|||
cnt_pulses++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
|
||||
}
|
||||
|
||||
static bool request_receive_mode(void) {
|
||||
|
||||
|
||||
// To issue a command we have to find a listen window first.
|
||||
// Because identification and sychronization at the same time is not
|
||||
// possible when using pulse lengths a double listen window is used.
|
||||
|
||||
bool bcommand = true;
|
||||
|
||||
|
||||
return find_double_listen_window(bcommand);
|
||||
}
|
||||
|
||||
static bool check_ack(bool bliw) {
|
||||
|
||||
|
||||
// returns true if signal structue corresponds to ACK, anything else is
|
||||
// counted as NAK (-> false)
|
||||
// Only relevant for pasword writing function:
|
||||
// If <bliw> is true then within the single listen window right after the
|
||||
// ack signal a RM request has to be sent.
|
||||
|
||||
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 4 * EM4X50_T_TAG_FULL_PERIOD) {
|
||||
|
||||
|
||||
if (check_pulse_length(get_pulse_length(), 2 * EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
||||
|
||||
// The received signal is either ACK or NAK.
|
||||
|
||||
|
||||
if (check_pulse_length(get_pulse_length(), 2 * EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
||||
|
||||
// Now the signal must be ACK.
|
||||
|
||||
if (!bliw) {
|
||||
|
@ -546,17 +546,17 @@ static bool check_ack(bool bliw) {
|
|||
return true;
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// send RM request after ack signal
|
||||
|
||||
// wait for 2 bits (remaining "bit" of ACK signal + first
|
||||
// "bit" of listen window)
|
||||
wait_timer(FPGA_TIMER_0, T0 * 2 * EM4X50_T_TAG_FULL_PERIOD);
|
||||
|
||||
|
||||
// check for listen window (if first bit cannot be inerpreted
|
||||
// as a valid bit it must belong to a listen window)
|
||||
if (get_next_bit() == EM4X50_BIT_OTHER) {
|
||||
|
||||
|
||||
// send RM for request mode
|
||||
em4x50_send_bit(0);
|
||||
em4x50_send_bit(0);
|
||||
|
@ -565,7 +565,7 @@ static bool check_ack(bool bliw) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
// It's NAK -> stop searching
|
||||
break;
|
||||
}
|
||||
|
@ -580,7 +580,7 @@ static int get_word_from_bitstream(uint8_t bits[EM4X50_TAG_WORD]) {
|
|||
// decodes one word by evaluating pulse lengths and previous bit;
|
||||
// word must have 45 bits in total:
|
||||
// 32 data bits + 4 row parity bits + 8 column parity bits + 1 stop bit
|
||||
|
||||
|
||||
bool bbitchange = false;
|
||||
int i = 0;
|
||||
uint32_t pl = 0;
|
||||
|
@ -599,7 +599,7 @@ static int get_word_from_bitstream(uint8_t bits[EM4X50_TAG_WORD]) {
|
|||
bbitchange = true;
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// pulse length = 2.5
|
||||
bits[0] = 0;
|
||||
bits[1] = 1;
|
||||
|
@ -609,35 +609,35 @@ static int get_word_from_bitstream(uint8_t bits[EM4X50_TAG_WORD]) {
|
|||
// identify remaining bits based on pulse lengths
|
||||
// between two listen windows only pulse lengths of 1, 1.5 and 2 are possible
|
||||
while (true) {
|
||||
|
||||
|
||||
i++;
|
||||
pl = get_pulse_length();
|
||||
|
||||
|
||||
if (check_pulse_length(pl, EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
||||
// pulse length = 1 -> keep former bit value
|
||||
bits[i] = bits[i-1];
|
||||
bits[i] = bits[i - 1];
|
||||
|
||||
} else if (check_pulse_length(pl, 3 * EM4X50_T_TAG_HALF_PERIOD)) {
|
||||
|
||||
// pulse length = 1.5 -> decision on bit change
|
||||
|
||||
|
||||
if (bbitchange) {
|
||||
|
||||
// if number of pulse lengths with 1.5 periods is even -> add bit
|
||||
bits[i] = (bits[i-1] == 1) ? 1 : 0;
|
||||
bits[i] = (bits[i - 1] == 1) ? 1 : 0;
|
||||
|
||||
// pulse length of 1.5 changes bit value
|
||||
bits[i+1] = (bits[i] == 1) ? 0 : 1;
|
||||
bits[i + 1] = (bits[i] == 1) ? 0 : 1;
|
||||
i++;
|
||||
|
||||
|
||||
// next time add only one bit
|
||||
bbitchange = false;
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
bits[i] = (bits[i-1] == 1) ? 0 : 1;
|
||||
|
||||
bits[i] = (bits[i - 1] == 1) ? 0 : 1;
|
||||
|
||||
// next time two bits have to be added
|
||||
bbitchange = true;
|
||||
}
|
||||
|
@ -646,7 +646,7 @@ static int get_word_from_bitstream(uint8_t bits[EM4X50_TAG_WORD]) {
|
|||
|
||||
// pulse length of 2 means: adding 2 bits "01"
|
||||
bits[i] = 0;
|
||||
bits[i+1] = 1;
|
||||
bits[i + 1] = 1;
|
||||
i++;
|
||||
|
||||
} else if (check_pulse_length(pl, 3 * EM4X50_T_TAG_FULL_PERIOD)) {
|
||||
|
@ -654,7 +654,7 @@ static int get_word_from_bitstream(uint8_t bits[EM4X50_TAG_WORD]) {
|
|||
// pulse length of 3 indicates listen window -> clear last
|
||||
// bit (= 0) and return
|
||||
return --i;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -667,8 +667,8 @@ static bool login(uint8_t password[4]) {
|
|||
|
||||
// simple login to EM4x50,
|
||||
// used in operations that require authentication
|
||||
|
||||
if (request_receive_mode ()) {
|
||||
|
||||
if (request_receive_mode()) {
|
||||
|
||||
// send login command
|
||||
em4x50_send_byte_with_parity(EM4X50_COMMAND_LOGIN);
|
||||
|
@ -679,12 +679,12 @@ static bool login(uint8_t password[4]) {
|
|||
// check if ACK is returned
|
||||
if (check_ack(false))
|
||||
return true;
|
||||
|
||||
|
||||
} else {
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -695,18 +695,18 @@ static bool login(uint8_t password[4]) {
|
|||
static bool reset(void) {
|
||||
|
||||
// resets EM4x50 tag (used by write function)
|
||||
|
||||
if (request_receive_mode ()) {
|
||||
|
||||
if (request_receive_mode()) {
|
||||
|
||||
// send login command
|
||||
em4x50_send_byte_with_parity(EM4X50_COMMAND_RESET);
|
||||
|
||||
|
||||
if (check_ack(false))
|
||||
return true;
|
||||
|
||||
} else {
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -717,10 +717,10 @@ static bool reset(void) {
|
|||
//==============================================================================
|
||||
|
||||
static bool standard_read(int *now) {
|
||||
|
||||
|
||||
// reads data that tag transmits when exposed to reader field
|
||||
// (standard read mode); number of read words is saved in <now>
|
||||
|
||||
|
||||
int fwr = *now;
|
||||
uint8_t bits[EM4X50_TAG_WORD] = {0};
|
||||
|
||||
|
@ -733,23 +733,23 @@ static bool standard_read(int *now) {
|
|||
|
||||
// number of detected words
|
||||
*now -= fwr;
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("didn't find a listen window");
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("didn't find a listen window");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool selective_read(uint8_t addresses[4]) {
|
||||
|
||||
|
||||
// reads from "first word read" (fwr = addresses[3]) to "last word read"
|
||||
// (lwr = addresses[2])
|
||||
// result is verified by "standard read mode"
|
||||
|
||||
|
||||
int fwr = addresses[3]; // first word read
|
||||
int lwr = addresses[2]; // last word read
|
||||
int now = fwr; // number of words
|
||||
|
@ -764,26 +764,26 @@ static bool selective_read(uint8_t addresses[4]) {
|
|||
|
||||
// look for ACK sequence
|
||||
if (check_ack(false))
|
||||
|
||||
|
||||
// save and verify via standard read mode (compare number of words)
|
||||
if (standard_read(&now))
|
||||
if (now == (lwr - fwr + 1))
|
||||
return true;
|
||||
|
||||
|
||||
} else {
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void em4x50_info(em4x50_data_t *etd) {
|
||||
|
||||
|
||||
// collects as much information as possible via selective read mode
|
||||
// if no password is given -> try with standard password "0x00000000"
|
||||
// otherwise continue without login
|
||||
|
||||
|
||||
bool bsuccess = false, blogin = false;
|
||||
uint8_t status = 0;
|
||||
uint8_t addresses[] = {0x00, 0x00, 0x21, 0x00}; // fwr = 0, lwr = 33
|
||||
|
@ -801,28 +801,28 @@ void em4x50_info(em4x50_data_t *etd) {
|
|||
blogin = login(etd->password);
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// if no password is given, try to login with "0x00000000"
|
||||
blogin = login(password);
|
||||
|
||||
}
|
||||
|
||||
|
||||
bsuccess = selective_read(addresses);
|
||||
}
|
||||
|
||||
status = (bsuccess << 1) + blogin;
|
||||
|
||||
|
||||
lf_finalize();
|
||||
reply_ng(CMD_ACK, status, (uint8_t *)tag.sectors, 238);
|
||||
}
|
||||
|
||||
void em4x50_read(em4x50_data_t *etd) {
|
||||
|
||||
|
||||
// reads in two different ways:
|
||||
// - using "selective read mode" -> bidirectional communication
|
||||
// - using "standard read mode" -> unidirectional communication (read
|
||||
// data that tag transmits "voluntarily")
|
||||
|
||||
|
||||
bool bsuccess = false, blogin = false;
|
||||
int now = 0;
|
||||
uint8_t status = 0;
|
||||
|
@ -830,32 +830,32 @@ void em4x50_read(em4x50_data_t *etd) {
|
|||
|
||||
init_tag();
|
||||
em4x50_setup_read();
|
||||
|
||||
|
||||
// set gHigh and gLow
|
||||
if (get_signalproperties() && find_em4x50_tag()) {
|
||||
|
||||
|
||||
if (etd->addr_given) {
|
||||
|
||||
// selective read mode
|
||||
|
||||
|
||||
// try to login with given password
|
||||
if (etd->pwd_given)
|
||||
blogin = login(etd->password);
|
||||
|
||||
|
||||
// only one word has to be read -> first word read = last word read
|
||||
addresses[2] = addresses[3] = etd->address;
|
||||
bsuccess = selective_read(addresses);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// standard read mode
|
||||
bsuccess = standard_read(&now);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status = (now << 2) + (bsuccess << 1) + blogin;
|
||||
|
||||
|
||||
lf_finalize();
|
||||
reply_ng(CMD_ACK, status, (uint8_t *)tag.sectors, 238);
|
||||
}
|
||||
|
@ -867,7 +867,7 @@ void em4x50_read(em4x50_data_t *etd) {
|
|||
static bool write(uint8_t word[4], uint8_t address) {
|
||||
|
||||
// writes <word> to specified <address>
|
||||
|
||||
|
||||
if (request_receive_mode()) {
|
||||
|
||||
// send write command
|
||||
|
@ -893,8 +893,8 @@ static bool write(uint8_t word[4], uint8_t address) {
|
|||
}
|
||||
|
||||
} else {
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -903,7 +903,7 @@ static bool write(uint8_t word[4], uint8_t address) {
|
|||
static bool write_password(uint8_t password[4], uint8_t new_password[4]) {
|
||||
|
||||
// changes password from <password> to <new_password>
|
||||
|
||||
|
||||
if (request_receive_mode()) {
|
||||
|
||||
// send write password command
|
||||
|
@ -932,36 +932,36 @@ static bool write_password(uint8_t password[4], uint8_t new_password[4]) {
|
|||
}
|
||||
|
||||
} else {
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
if (DBGLEVEL >= DBG_DEBUG)
|
||||
Dbprintf("error in command request");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void em4x50_write(em4x50_data_t *etd) {
|
||||
|
||||
|
||||
// write operation process for EM4x50 tag,
|
||||
// single word is written to given address, verified by selective read operation
|
||||
|
||||
|
||||
bool bsuccess = false, blogin = false;
|
||||
uint8_t status = 0;
|
||||
uint8_t word[4] = {0x00, 0x00, 0x00, 0x00};
|
||||
uint8_t addresses[4] = {0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
|
||||
init_tag();
|
||||
em4x50_setup_read();
|
||||
|
||||
|
||||
// set gHigh and gLow
|
||||
if (get_signalproperties() && find_em4x50_tag()) {
|
||||
|
||||
|
||||
// reorder word according to datasheet
|
||||
msb2lsb_word(etd->word);
|
||||
|
||||
|
||||
// if password is given try to login first
|
||||
if (etd->pwd_given)
|
||||
blogin = login(etd->password);
|
||||
|
||||
|
||||
// write word to given address
|
||||
if (write(etd->word, etd->address)) {
|
||||
|
||||
|
@ -982,7 +982,7 @@ void em4x50_write(em4x50_data_t *etd) {
|
|||
word[2] = tag.sectors[etd->address][2];
|
||||
word[3] = tag.sectors[etd->address][3];
|
||||
msb2lsb_word(word);
|
||||
|
||||
|
||||
bsuccess = true;
|
||||
for (int i = 0; i < 4; i++)
|
||||
bsuccess &= (word[i] == etd->word[i]) ? true : false;
|
||||
|
@ -993,20 +993,20 @@ void em4x50_write(em4x50_data_t *etd) {
|
|||
}
|
||||
|
||||
status = (bsuccess << 1) + blogin;
|
||||
|
||||
|
||||
lf_finalize();
|
||||
reply_ng(CMD_ACK, status, (uint8_t *)tag.sectors, 238);
|
||||
}
|
||||
|
||||
void em4x50_write_password(em4x50_data_t *etd) {
|
||||
|
||||
|
||||
// sinmple change of password
|
||||
|
||||
|
||||
bool bsuccess = false;
|
||||
|
||||
|
||||
init_tag();
|
||||
em4x50_setup_read();
|
||||
|
||||
|
||||
// set gHigh and gLow
|
||||
if (get_signalproperties() && find_em4x50_tag()) {
|
||||
|
||||
|
@ -1021,19 +1021,19 @@ void em4x50_write_password(em4x50_data_t *etd) {
|
|||
}
|
||||
|
||||
void em4x50_wipe(em4x50_data_t *etd) {
|
||||
|
||||
|
||||
// set all data of EM4x50 tag to 0x0 including password
|
||||
|
||||
|
||||
bool bsuccess = false;
|
||||
uint8_t zero[4] = {0, 0, 0, 0};
|
||||
uint8_t addresses[4] = {0, 0, EM4X50_NO_WORDS - 3, 1};
|
||||
|
||||
|
||||
init_tag();
|
||||
em4x50_setup_read();
|
||||
|
||||
|
||||
// set gHigh and gLow
|
||||
if (get_signalproperties() && find_em4x50_tag()) {
|
||||
|
||||
|
||||
// login first
|
||||
if (login(etd->password)) {
|
||||
|
||||
|
@ -1058,9 +1058,9 @@ void em4x50_wipe(em4x50_data_t *etd) {
|
|||
bsuccess &= (tag.sectors[i][j] == 0) ? true : false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (bsuccess) {
|
||||
|
||||
|
||||
// so far everything is fine
|
||||
// last task: reset password
|
||||
if (login(etd->password))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue