diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 70256e80c..e11f75a19 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1126,8 +1126,8 @@ static void PacketReceived(PacketCommandNG *packet) { em4x50_sim(); break; } - case CMD_LF_EM4X50_STD_READ: { - em4x50_std_read(); + case CMD_LF_EM4X50_STDREAD: { + em4x50_stdread(); break; } case CMD_LF_EM4X50_ESET: { diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index 38c3c8269..f4ed5ba01 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -122,22 +122,6 @@ static void em4x50_setup_sim(void) { AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_CLK; } -static void emlGetMem(uint32_t *words, size_t nowords) { - - // read words from emulator memory - - uint8_t *em4x50_mem = BigBuf_get_EM_addr(); - - for (int i = 0; i < EM4X50_NO_WORDS; i++) { - - for (int j = 0; j < 4; j++) - words[i] |= (em4x50_mem[4 * i + j]) << ((3 - j) * 8); - - // lsb is needed (given format is msb) - words[i] = reflect32(words[i]); - } -} - // functions for "reader" use case static bool get_signalproperties(void) { @@ -1346,6 +1330,7 @@ void em4x50_restore(em4x50_data_t *etd) { int res = 0; int start_word = 0; uint8_t status = 0; + uint8_t *em4x50_mem = BigBuf_get_EM_addr(); uint32_t addresses = 0x00001F01; // from fwr = 1 to lwr = 31 (0x1F) uint32_t words_client[EM4X50_NO_WORDS] = {0x0}; uint32_t words_read[EM4X50_NO_WORDS] = {0x0}; @@ -1353,8 +1338,9 @@ void em4x50_restore(em4x50_data_t *etd) { em4x50_setup_read(); // read data from emulator memory - emlGetMem(words_client, EM4X50_NO_WORDS); - + for (int i = 0; i < EM4X50_NO_WORDS; i++) + words_client[i] = reflect32(bytes_to_num(em4x50_mem + (i * 4), 4)); + // set gHigh and gLow if (get_signalproperties() && find_em4x50_tag()) { @@ -1403,12 +1389,14 @@ void em4x50_sim(void) { // simulate uploaded data in emulator memory // (currently only a one-way communication is possible) + uint8_t *em4x50_mem = BigBuf_get_EM_addr(); uint32_t words[EM4X50_NO_WORDS] = {0x0}; em4x50_setup_sim(); // read data from emulator memory - emlGetMem(words, EM4X50_NO_WORDS); + for (int i = 0; i < EM4X50_NO_WORDS; i++) + words[i] = reflect32(bytes_to_num(em4x50_mem + (i * 4), 4)); // extract control data int fwr = words[CONFIG_BLOCK] & 0xFF; // first word read @@ -1437,7 +1425,7 @@ void em4x50_sim(void) { reply_ng(CMD_LF_EM4X50_SIM, 1, 0, 0); } -void em4x50_std_read(void) { +void em4x50_stdread(void) { // reads data that tag transmits "voluntarily" -> standard read mode @@ -1452,5 +1440,5 @@ void em4x50_std_read(void) { LOW(GPIO_SSC_DOUT); lf_finalize(); - reply_ng(CMD_LF_EM4X50_STD_READ, now, (uint8_t *)words, 4 * now); + reply_ng(CMD_LF_EM4X50_STDREAD, now, (uint8_t *)words, 4 * now); } diff --git a/armsrc/em4x50.h b/armsrc/em4x50.h index 35c519a9e..57ad94b4d 100644 --- a/armsrc/em4x50.h +++ b/armsrc/em4x50.h @@ -30,6 +30,6 @@ void em4x50_reset(void); void em4x50_watch(void); void em4x50_restore(em4x50_data_t *etd); void em4x50_sim(void); -void em4x50_std_read(void); +void em4x50_stdread(void); #endif /* EM4X50_H */ diff --git a/client/src/cmdlfem4x.c b/client/src/cmdlfem4x.c index 56681af91..8370edcfb 100644 --- a/client/src/cmdlfem4x.c +++ b/client/src/cmdlfem4x.c @@ -663,7 +663,7 @@ static command_t CommandTable[] = { {"4x50_watch", CmdEM4x50Watch, IfPm3EM4x50, "read EM4x50 continously"}, {"4x50_restore",CmdEM4x50Restore, IfPm3EM4x50, "restore EM4x50 dump to tag"}, {"4x50_sim", CmdEM4x50Sim, IfPm3EM4x50, "simulate single EM4x50 word (uid)"}, - {"4x50_std_read",CmdEM4x50StdRead, IfPm3EM4x50, "show standard read mode data of EM4x50 tag"}, + {"4x50_stdread",CmdEM4x50StdRead, IfPm3EM4x50, "show standard read mode data of EM4x50 tag"}, {"4x50_eload", CmdEM4x50ELoad, IfPm3EM4x50, "load a binary dump into emulator memory"}, {"4x50_esave", CmdEM4x50ESave, IfPm3EM4x50, "save emulator memory to file"}, {NULL, NULL, NULL, NULL} diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index ed311242c..ffd4c236c 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -175,7 +175,7 @@ static int usage_lf_em4x50_sim(void) { PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } -static int usage_lf_em4x50_std_read(void) { +static int usage_lf_em4x50_stdread(void) { PrintAndLogEx(NORMAL, "Show standard read mode data of EM4x50 tag. Tag must be on antenna."); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Usage: lf em 4x50_std_read [h]"); @@ -1168,7 +1168,7 @@ int CmdEM4x50StdRead(const char *Cmd) { switch (tolower(param_getchar(Cmd, cmdp))) { case 'h': - return usage_lf_em4x50_std_read(); + return usage_lf_em4x50_stdread(); default: PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); @@ -1178,12 +1178,12 @@ int CmdEM4x50StdRead(const char *Cmd) { } if (errors) - return usage_lf_em4x50_std_read(); + return usage_lf_em4x50_stdread(); // start clearCommandBuffer(); - SendCommandNG(CMD_LF_EM4X50_STD_READ, 0, 0); - if (!WaitForResponseTimeout(CMD_LF_EM4X50_STD_READ, &resp, TIMEOUT)) { + SendCommandNG(CMD_LF_EM4X50_STDREAD, 0, 0); + if (!WaitForResponseTimeout(CMD_LF_EM4X50_STDREAD, &resp, TIMEOUT)) { PrintAndLogEx(WARNING, "Timeout while waiting for reply."); return PM3_ETIMEOUT; } diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index f588f19b3..9ad61d4a7 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -514,7 +514,7 @@ typedef struct { #define CMD_LF_EM4X50_WATCH 0x0248 #define CMD_LF_EM4X50_RESTORE 0x0249 #define CMD_LF_EM4X50_SIM 0x0250 -#define CMD_LF_EM4X50_STD_READ 0x0251 +#define CMD_LF_EM4X50_STDREAD 0x0251 #define CMD_LF_EM4X50_ESET 0x0252 // Sampling configuration for LF reader/sniffer #define CMD_LF_SAMPLING_SET_CONFIG 0x021D