diff --git a/armsrc/BigBuf.c b/armsrc/BigBuf.c index 29f270b80..b622e013b 100644 --- a/armsrc/BigBuf.c +++ b/armsrc/BigBuf.c @@ -233,7 +233,7 @@ uint32_t BigBuf_get_traceLen(void) { by 'hf list -t raw', alternatively 'hf list -t ' for protocol-specific annotation of commands/responses. **/ -bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool reader2tag) { +bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, const uint8_t *parity, bool reader2tag) { if (tracing == false) { return false; } @@ -290,7 +290,7 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_ } // specific LogTrace function for ISO15693: the duration needs to be scaled because otherwise it won't fit into a uint16_t -bool LogTrace_ISO15693(const uint8_t *bytes, uint16_t len, uint32_t ts_start, uint32_t ts_end, uint8_t *parity, bool reader2tag) { +bool LogTrace_ISO15693(const uint8_t *bytes, uint16_t len, uint32_t ts_start, uint32_t ts_end, const uint8_t *parity, bool reader2tag) { uint32_t duration = ts_end - ts_start; duration /= 32; ts_end = ts_start + duration; @@ -306,7 +306,7 @@ bool RAMFUNC LogTraceBits(const uint8_t *btBytes, uint16_t bitLen, uint32_t time } // Emulator memory -uint8_t emlSet(uint8_t *data, uint32_t offset, uint32_t length) { +uint8_t emlSet(const uint8_t *data, uint32_t offset, uint32_t length) { uint8_t *mem = BigBuf_get_EM_addr(); if (offset + length <= CARD_MEMORY_SIZE) { memcpy(mem + offset, data, length); diff --git a/armsrc/BigBuf.h b/armsrc/BigBuf.h index 81c2fbdfc..0938bd555 100644 --- a/armsrc/BigBuf.h +++ b/armsrc/BigBuf.h @@ -51,11 +51,11 @@ void set_tracing(bool enable); void set_tracelen(uint32_t value); bool get_tracing(void); -bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool reader2tag); +bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, const uint8_t *parity, bool reader2tag); bool RAMFUNC LogTraceBits(const uint8_t *btBytes, uint16_t bitLen, uint32_t timestamp_start, uint32_t timestamp_end, bool reader2tag); -bool LogTrace_ISO15693(const uint8_t *bytes, uint16_t len, uint32_t ts_start, uint32_t ts_end, uint8_t *parity, bool reader2tag); +bool LogTrace_ISO15693(const uint8_t *bytes, uint16_t len, uint32_t ts_start, uint32_t ts_end, const uint8_t *parity, bool reader2tag); -uint8_t emlSet(uint8_t *data, uint32_t offset, uint32_t length); +uint8_t emlSet(const uint8_t *data, uint32_t offset, uint32_t length); uint8_t emlGet(uint8_t *out, uint32_t offset, uint32_t length); typedef struct { diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 3c471191f..5908ed855 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1154,27 +1154,27 @@ static void PacketReceived(PacketCommandNG *packet) { #ifdef WITH_EM4x50 case CMD_LF_EM4X50_INFO: { - em4x50_info((em4x50_data_t *)packet->data.asBytes, true); + em4x50_info((const em4x50_data_t *)packet->data.asBytes, true); break; } case CMD_LF_EM4X50_WRITE: { - em4x50_write((em4x50_data_t *)packet->data.asBytes, true); + em4x50_write((const em4x50_data_t *)packet->data.asBytes, true); break; } case CMD_LF_EM4X50_WRITEPWD: { - em4x50_writepwd((em4x50_data_t *)packet->data.asBytes, true); + em4x50_writepwd((const em4x50_data_t *)packet->data.asBytes, true); break; } case CMD_LF_EM4X50_READ: { - em4x50_read((em4x50_data_t *)packet->data.asBytes, true); + em4x50_read((const em4x50_data_t *)packet->data.asBytes, true); break; } case CMD_LF_EM4X50_BRUTE: { - em4x50_brute((em4x50_data_t *)packet->data.asBytes, true); + em4x50_brute((const em4x50_data_t *)packet->data.asBytes, true); break; } case CMD_LF_EM4X50_LOGIN: { - em4x50_login((uint32_t *)packet->data.asBytes, true); + em4x50_login((const uint32_t *)packet->data.asBytes, true); break; } case CMD_LF_EM4X50_SIM: { @@ -1184,7 +1184,7 @@ static void PacketReceived(PacketCommandNG *packet) { // destroy the Emulator Memory. //----------------------------------------------------------------------------- FpgaDownloadAndGo(FPGA_BITSTREAM_LF); - em4x50_sim((uint32_t *)packet->data.asBytes, true); + em4x50_sim((const uint32_t *)packet->data.asBytes, true); break; } case CMD_LF_EM4X50_READER: { @@ -1208,7 +1208,7 @@ static void PacketReceived(PacketCommandNG *packet) { // destroy the Emulator Memory. //----------------------------------------------------------------------------- FpgaDownloadAndGo(FPGA_BITSTREAM_LF); - em4x50_chk((uint8_t *)packet->data.asBytes, true); + em4x50_chk((const char *)packet->data.asBytes, true); break; } #endif diff --git a/armsrc/cmd.c b/armsrc/cmd.c index c179ed2a9..f2b432d33 100644 --- a/armsrc/cmd.c +++ b/armsrc/cmd.c @@ -26,7 +26,7 @@ bool g_reply_with_crc_on_fpc = true; bool g_reply_via_fpc = false; bool g_reply_via_usb = false; -int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) { +int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, const void *data, size_t len) { PacketResponseOLD txcmd = {CMD_UNKNOWN, {0, 0, 0}, {{0}}}; // for (size_t i = 0; i < sizeof(PacketResponseOLD); i++) @@ -42,7 +42,7 @@ int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *d if (data && len) { len = MIN(len, PM3_CMD_DATA_SIZE); for (size_t i = 0; i < len; i++) { - txcmd.d.asBytes[i] = ((uint8_t *)data)[i]; + txcmd.d.asBytes[i] = ((const uint8_t *)data)[i]; } } @@ -135,7 +135,7 @@ int reply_ng(uint16_t cmd, int16_t status, const uint8_t *data, size_t len) { return reply_ng_internal(cmd, status, data, len, true); } -int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) { +int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, const void *data, size_t len) { int16_t status = PM3_SUCCESS; uint64_t arg[3] = {arg0, arg1, arg2}; if (len > PM3_CMD_DATA_SIZE - sizeof(arg)) { diff --git a/armsrc/cmd.h b/armsrc/cmd.h index b578db8e8..22a79ce16 100644 --- a/armsrc/cmd.h +++ b/armsrc/cmd.h @@ -27,9 +27,9 @@ extern bool g_reply_with_crc_on_fpc; extern bool g_reply_via_fpc; extern bool g_reply_via_usb; -int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); +int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, const void *data, size_t len); int reply_ng(uint16_t cmd, int16_t status, const uint8_t *data, size_t len); -int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); +int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, const void *data, size_t len); int receive_ng(PacketCommandNG *rx); #endif // _PROXMARK_CMD_H_ diff --git a/armsrc/dbprint.c b/armsrc/dbprint.c index 7be7bba4c..218223231 100644 --- a/armsrc/dbprint.c +++ b/armsrc/dbprint.c @@ -74,7 +74,7 @@ void Dbprintf(const char *fmt, ...) { } // prints HEX & ASCII -void Dbhexdump(int len, uint8_t *d, bool bAsci) { +void Dbhexdump(int len, const uint8_t *d, bool bAsci) { #if DEBUG char ascii[9]; @@ -103,9 +103,9 @@ void Dbhexdump(int len, uint8_t *d, bool bAsci) { #endif } -void print_result(const char *name, uint8_t *buf, size_t len) { +void print_result(const char *name, const uint8_t *buf, size_t len) { - uint8_t *p = buf; + const uint8_t *p = buf; uint16_t tmp = len & 0xFFF0; for (; p - buf < tmp; p += 16) { diff --git a/armsrc/dbprint.h b/armsrc/dbprint.h index b1a7753da..0795db274 100644 --- a/armsrc/dbprint.h +++ b/armsrc/dbprint.h @@ -22,40 +22,12 @@ #include "common.h" #include "ansi.h" -#define Dbprintf_usb(...) {\ - bool tmpfpc = g_reply_via_fpc;\ - bool tmpusb = g_reply_via_usb;\ - g_reply_via_fpc = false;\ - g_reply_via_usb = true;\ - Dbprintf(__VA_ARGS__);\ - g_reply_via_fpc = tmpfpc;\ - g_reply_via_usb = tmpusb;} - -#define Dbprintf_fpc(...) {\ - bool tmpfpc = g_reply_via_fpc;\ - bool tmpusb = g_reply_via_usb;\ - g_reply_via_fpc = true;\ - g_reply_via_usb = false;\ - Dbprintf(__VA_ARGS__);\ - g_reply_via_fpc = tmpfpc;\ - g_reply_via_usb = tmpusb;} - -#define Dbprintf_all(...) {\ - bool tmpfpc = g_reply_via_fpc;\ - bool tmpusb = g_reply_via_usb;\ - g_reply_via_fpc = true;\ - g_reply_via_usb = true;\ - Dbprintf(__VA_ARGS__);\ - g_reply_via_fpc = tmpfpc;\ - g_reply_via_usb = tmpusb;} - - void DbpString(const char *str); void DbpStringEx(uint32_t flags, const char *src, size_t srclen); void Dbprintf(const char *fmt, ...); void DbprintfEx(uint32_t flags, const char *fmt, ...); -void Dbhexdump(int len, uint8_t *d, bool bAsci); -void print_result(const char *name, uint8_t *buf, size_t len); +void Dbhexdump(int len, const uint8_t *d, bool bAsci); +void print_result(const char *name, const uint8_t *buf, size_t len); //void PrintToSendBuffer(void); #endif diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index d43a6a15f..4910caa31 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -634,7 +634,7 @@ static int login(uint32_t password) { } // searching for password using chosen bruteforce algorithm -static bool brute(em4x50_data_t *etd, uint32_t *pwd) { +static bool brute(const em4x50_data_t *etd, uint32_t *pwd) { generator_context_t ctx; bool pwd_found = false; @@ -694,7 +694,7 @@ static bool brute(em4x50_data_t *etd, uint32_t *pwd) { } // login into EM4x50 -void em4x50_login(uint32_t *password, bool ledcontrol) { +void em4x50_login(const uint32_t *password, bool ledcontrol) { em4x50_setup_read(); int status = PM3_EFAILED; @@ -713,7 +713,7 @@ void em4x50_login(uint32_t *password, bool ledcontrol) { } // invoke password search -void em4x50_brute(em4x50_data_t *etd, bool ledcontrol) { +void em4x50_brute(const em4x50_data_t *etd, bool ledcontrol) { em4x50_setup_read(); bool bsuccess = false; @@ -733,7 +733,7 @@ void em4x50_brute(em4x50_data_t *etd, bool ledcontrol) { } // check passwords from dictionary content in flash memory -void em4x50_chk(uint8_t *filename, bool ledcontrol) { +void em4x50_chk(const char *filename, bool ledcontrol) { int status = PM3_EFAILED; uint32_t pwd = 0x0; @@ -743,11 +743,11 @@ void em4x50_chk(uint8_t *filename, bool ledcontrol) { int changed = rdv40_spiffs_lazy_mount(); uint16_t pwd_count = 0; - uint32_t size = size_in_spiffs((char *)filename); + uint32_t size = size_in_spiffs(filename); pwd_count = size / 4; uint8_t *pwds = BigBuf_malloc(size); - rdv40_spiffs_read_as_filetype((char *)filename, pwds, size, RDV40_SPIFFS_SAFETY_SAFE); + rdv40_spiffs_read_as_filetype(filename, pwds, size, RDV40_SPIFFS_SAFETY_SAFE); if (changed) rdv40_spiffs_lazy_unmount(); @@ -873,7 +873,7 @@ static int selective_read(uint32_t addresses, uint32_t *words) { } // reads by using "selective read mode" -> bidirectional communication -void em4x50_read(em4x50_data_t *etd, bool ledcontrol) { +void em4x50_read(const em4x50_data_t *etd, bool ledcontrol) { int status = PM3_EFAILED; uint32_t words[EM4X50_NO_WORDS] = {0x0}; @@ -906,7 +906,7 @@ void em4x50_read(em4x50_data_t *etd, bool ledcontrol) { } // collects as much information as possible via selective read mode -void em4x50_info(em4x50_data_t *etd, bool ledcontrol) { +void em4x50_info(const em4x50_data_t *etd, bool ledcontrol) { int status = PM3_EFAILED; uint32_t words[EM4X50_NO_WORDS] = {0x0}; @@ -1053,7 +1053,7 @@ static int write_password(uint32_t password, uint32_t new_password) { // write operation process for EM4x50 tag, // single word is written to given address, verified by selective read operation // wrong password -> return with PM3_EFAILED -void em4x50_write(em4x50_data_t *etd, bool ledcontrol) { +void em4x50_write(const em4x50_data_t *etd, bool ledcontrol) { int status = PM3_EFAILED; uint32_t words[EM4X50_NO_WORDS] = {0x0}; @@ -1113,7 +1113,7 @@ void em4x50_write(em4x50_data_t *etd, bool ledcontrol) { } // simple change of password -void em4x50_writepwd(em4x50_data_t *etd, bool ledcontrol) { +void em4x50_writepwd(const em4x50_data_t *etd, bool ledcontrol) { int status = PM3_EFAILED; em4x50_setup_read(); @@ -1358,7 +1358,7 @@ static bool em4x50_sim_read_word(uint32_t *word) { } // check if reader requests receive mode (rm) by sending two zeros -static int check_rm_request(uint32_t *tag, bool ledcontrol) { +static int check_rm_request(const uint32_t *tag, bool ledcontrol) { // look for first zero int bit = em4x50_sim_read_bit(); @@ -1387,7 +1387,7 @@ static int check_rm_request(uint32_t *tag, bool ledcontrol) { } // send single listen window in simulation mode -static int em4x50_sim_send_listen_window(uint32_t *tag, bool ledcontrol) { +static int em4x50_sim_send_listen_window(const uint32_t *tag, bool ledcontrol) { SHORT_COIL(); wait_cycles(EM4X50_T_TAG_HALF_PERIOD); @@ -1460,7 +1460,7 @@ static void em4x50_sim_send_nak(void) { } // standard read mode process (simulation mode) -static int em4x50_sim_handle_standard_read_command(uint32_t *tag, bool ledcontrol) { +static int em4x50_sim_handle_standard_read_command(const uint32_t *tag, bool ledcontrol) { // extract control data int fwr = reflect32(tag[EM4X50_CONTROL]) & 0xFF; // first word read @@ -1500,7 +1500,7 @@ static int em4x50_sim_handle_standard_read_command(uint32_t *tag, bool ledcontro } // selective read mode process (simulation mode) -static int em4x50_sim_handle_selective_read_command(uint32_t *tag, bool ledcontrol) { +static int em4x50_sim_handle_selective_read_command(const uint32_t *tag, bool ledcontrol) { // read password uint32_t address = 0; @@ -1555,7 +1555,7 @@ static int em4x50_sim_handle_selective_read_command(uint32_t *tag, bool ledcontr } // login process (simulation mode) -static int em4x50_sim_handle_login_command(uint32_t *tag, bool ledcontrol) { +static int em4x50_sim_handle_login_command(const uint32_t *tag, bool ledcontrol) { // read password uint32_t password = 0; @@ -1581,7 +1581,7 @@ static int em4x50_sim_handle_login_command(uint32_t *tag, bool ledcontrol) { } // reset process (simulation mode) -static int em4x50_sim_handle_reset_command(uint32_t *tag, bool ledcontrol) { +static int em4x50_sim_handle_reset_command(const uint32_t *tag, bool ledcontrol) { // processing pause time (corresponds to a "1" bit) em4x50_sim_send_bit(1); @@ -1806,7 +1806,7 @@ void em4x50_handle_commands(int *command, uint32_t *tag, bool ledcontrol) { // simulate uploaded data in emulator memory // LED C -> reader command has been detected // LED D -> operations that require authentication are possible -void em4x50_sim(uint32_t *password, bool ledcontrol) { +void em4x50_sim(const uint32_t *password, bool ledcontrol) { int command = PM3_ENODATA; diff --git a/armsrc/em4x50.h b/armsrc/em4x50.h index af3a7a8db..eb52c36e5 100644 --- a/armsrc/em4x50.h +++ b/armsrc/em4x50.h @@ -21,20 +21,21 @@ #include "../include/em4x50.h" +// used by standalone mode void em4x50_setup_read(void); int standard_read(int *now, uint32_t *words); - void em4x50_setup_sim(void); void em4x50_handle_commands(int *command, uint32_t *tag, bool ledcontrol); -void em4x50_info(em4x50_data_t *etd, bool ledcontrol); -void em4x50_write(em4x50_data_t *etd, bool ledcontrol); -void em4x50_writepwd(em4x50_data_t *etd, bool ledcontrol); -void em4x50_read(em4x50_data_t *etd, bool ledcontrol); -void em4x50_brute(em4x50_data_t *etd, bool ledcontrol); -void em4x50_login(uint32_t *password, bool ledcontrol); -void em4x50_sim(uint32_t *password, bool ledcontrol); +// dispatch functions (appmain.c) +void em4x50_info(const em4x50_data_t *etd, bool ledcontrol); +void em4x50_write(const em4x50_data_t *etd, bool ledcontrol); +void em4x50_writepwd(const em4x50_data_t *etd, bool ledcontrol); +void em4x50_read(const em4x50_data_t *etd, bool ledcontrol); +void em4x50_brute(const em4x50_data_t *etd, bool ledcontrol); +void em4x50_login(const uint32_t *password, bool ledcontrol); +void em4x50_sim(const uint32_t *password, bool ledcontrol); void em4x50_reader(bool ledcontrol); -void em4x50_chk(uint8_t *filename, bool ledcontrol); +void em4x50_chk(const char *filename, bool ledcontrol); #endif /* EM4X50_H */ diff --git a/armsrc/em4x70.c b/armsrc/em4x70.c index 806442f7f..ab73bd153 100644 --- a/armsrc/em4x70.c +++ b/armsrc/em4x70.c @@ -310,6 +310,7 @@ static bool check_ack(void) { return false; } +// TODO: define and use structs for rnd, frnd, response static int authenticate(const uint8_t *rnd, const uint8_t *frnd, uint8_t *response) { if (find_listen_window(true)) { @@ -350,8 +351,10 @@ static int authenticate(const uint8_t *rnd, const uint8_t *frnd, uint8_t *respon return PM3_ESOFT; } -static int set_byte(uint8_t *target, int value) { - int c = value > 0xFF; +// Sets one (reflected) byte and returns carry bit +// (1 if `value` parameter was greater than 0xFF) +static int set_byte(uint8_t *target, uint16_t value) { + int c = value > 0xFF ? 1 : 0; // be explicit about carry bit values *target = reflect8(value); return c; } @@ -373,27 +376,27 @@ static int bruteforce(const uint8_t address, const uint8_t *rnd, const uint8_t * uint16_t rev_k = reflect16(k); switch (address) { case 9: - c = set_byte(&temp_rnd[0], rev_rnd[0] + (rev_k & 0xFF)); - c = set_byte(&temp_rnd[1], rev_rnd[1] + c + ((rev_k >> 8) & 0xFF)); + c = set_byte(&temp_rnd[0], rev_rnd[0] + ((rev_k ) & 0xFFu)); + c = set_byte(&temp_rnd[1], rev_rnd[1] + c + ((rev_k >> 8) & 0xFFu)); c = set_byte(&temp_rnd[2], rev_rnd[2] + c); c = set_byte(&temp_rnd[3], rev_rnd[3] + c); c = set_byte(&temp_rnd[4], rev_rnd[4] + c); c = set_byte(&temp_rnd[5], rev_rnd[5] + c); - set_byte(&temp_rnd[6], rev_rnd[6] + c); + set_byte( &temp_rnd[6], rev_rnd[6] + c); break; case 8: - c = set_byte(&temp_rnd[2], rev_rnd[2] + (rev_k & 0xFF)); - c = set_byte(&temp_rnd[3], rev_rnd[3] + c + ((rev_k >> 8) & 0xFF)); + c = set_byte(&temp_rnd[2], rev_rnd[2] + ((rev_k ) & 0xFFu)); + c = set_byte(&temp_rnd[3], rev_rnd[3] + c + ((rev_k >> 8) & 0xFFu)); c = set_byte(&temp_rnd[4], rev_rnd[4] + c); c = set_byte(&temp_rnd[5], rev_rnd[5] + c); - set_byte(&temp_rnd[6], rev_rnd[6] + c); + set_byte( &temp_rnd[6], rev_rnd[6] + c); break; case 7: - c = set_byte(&temp_rnd[4], rev_rnd[4] + (rev_k & 0xFF)); - c = set_byte(&temp_rnd[5], rev_rnd[5] + c + ((rev_k >> 8) & 0xFF)); - set_byte(&temp_rnd[6], rev_rnd[6] + c); + c = set_byte(&temp_rnd[4], rev_rnd[4] + ((rev_k ) & 0xFFu)); + c = set_byte(&temp_rnd[5], rev_rnd[5] + c + ((rev_k >> 8) & 0xFFu)); + set_byte( &temp_rnd[6], rev_rnd[6] + c); break; default: @@ -707,7 +710,7 @@ static int em4x70_receive(uint8_t *bits, size_t length) { return bit_pos; } -void em4x70_info(em4x70_data_t *etd, bool ledcontrol) { +void em4x70_info(const em4x70_data_t *etd, bool ledcontrol) { uint8_t status = 0; @@ -728,7 +731,7 @@ void em4x70_info(em4x70_data_t *etd, bool ledcontrol) { reply_ng(CMD_LF_EM4X70_INFO, status, tag.data, sizeof(tag.data)); } -void em4x70_write(em4x70_data_t *etd, bool ledcontrol) { +void em4x70_write(const em4x70_data_t *etd, bool ledcontrol) { uint8_t status = 0; @@ -758,7 +761,7 @@ void em4x70_write(em4x70_data_t *etd, bool ledcontrol) { reply_ng(CMD_LF_EM4X70_WRITE, status, tag.data, sizeof(tag.data)); } -void em4x70_unlock(em4x70_data_t *etd, bool ledcontrol) { +void em4x70_unlock(const em4x70_data_t *etd, bool ledcontrol) { uint8_t status = 0; @@ -791,7 +794,7 @@ void em4x70_unlock(em4x70_data_t *etd, bool ledcontrol) { reply_ng(CMD_LF_EM4X70_UNLOCK, status, tag.data, sizeof(tag.data)); } -void em4x70_auth(em4x70_data_t *etd, bool ledcontrol) { +void em4x70_auth(const em4x70_data_t *etd, bool ledcontrol) { uint8_t status = 0; uint8_t response[3] = {0}; @@ -813,7 +816,7 @@ void em4x70_auth(em4x70_data_t *etd, bool ledcontrol) { reply_ng(CMD_LF_EM4X70_AUTH, status, response, sizeof(response)); } -void em4x70_brute(em4x70_data_t *etd, bool ledcontrol) { +void em4x70_brute(const em4x70_data_t *etd, bool ledcontrol) { uint8_t status = 0; uint8_t response[2] = {0}; @@ -834,7 +837,7 @@ void em4x70_brute(em4x70_data_t *etd, bool ledcontrol) { reply_ng(CMD_LF_EM4X70_BRUTE, status, response, sizeof(response)); } -void em4x70_write_pin(em4x70_data_t *etd, bool ledcontrol) { +void em4x70_write_pin(const em4x70_data_t *etd, bool ledcontrol) { uint8_t status = 0; @@ -850,8 +853,8 @@ void em4x70_write_pin(em4x70_data_t *etd, bool ledcontrol) { if (em4x70_read_id()) { // Write new PIN - if ((write(etd->pin & 0xFFFF, EM4X70_PIN_WORD_UPPER) == PM3_SUCCESS) && - (write((etd->pin >> 16) & 0xFFFF, EM4X70_PIN_WORD_LOWER) == PM3_SUCCESS)) { + if ((write((etd->pin ) & 0xFFFF, EM4X70_PIN_WORD_UPPER) == PM3_SUCCESS) && + (write((etd->pin >> 16) & 0xFFFF, EM4X70_PIN_WORD_LOWER) == PM3_SUCCESS)) { // Now Try to authenticate using the new PIN @@ -874,7 +877,7 @@ void em4x70_write_pin(em4x70_data_t *etd, bool ledcontrol) { reply_ng(CMD_LF_EM4X70_WRITEPIN, status, tag.data, sizeof(tag.data)); } -void em4x70_write_key(em4x70_data_t *etd, bool ledcontrol) { +void em4x70_write_key(const em4x70_data_t *etd, bool ledcontrol) { uint8_t status = 0; diff --git a/armsrc/em4x70.h b/armsrc/em4x70.h index 0fd640f86..83a8237d7 100644 --- a/armsrc/em4x70.h +++ b/armsrc/em4x70.h @@ -30,12 +30,12 @@ typedef enum { FALLING_EDGE } edge_detection_t; -void em4x70_info(em4x70_data_t *etd, bool ledcontrol); -void em4x70_write(em4x70_data_t *etd, bool ledcontrol); -void em4x70_brute(em4x70_data_t *etd, bool ledcontrol); -void em4x70_unlock(em4x70_data_t *etd, bool ledcontrol); -void em4x70_auth(em4x70_data_t *etd, bool ledcontrol); -void em4x70_write_pin(em4x70_data_t *etd, bool ledcontrol); -void em4x70_write_key(em4x70_data_t *etd, bool ledcontrol); +void em4x70_info(const em4x70_data_t *etd, bool ledcontrol); +void em4x70_write(const em4x70_data_t *etd, bool ledcontrol); +void em4x70_brute(const em4x70_data_t *etd, bool ledcontrol); +void em4x70_unlock(const em4x70_data_t *etd, bool ledcontrol); +void em4x70_auth(const em4x70_data_t *etd, bool ledcontrol); +void em4x70_write_pin(const em4x70_data_t *etd, bool ledcontrol); +void em4x70_write_key(const em4x70_data_t *etd, bool ledcontrol); #endif /* EM4x70_H */ diff --git a/armsrc/epa.c b/armsrc/epa.c index 7bd563676..4e4113d45 100644 --- a/armsrc/epa.c +++ b/armsrc/epa.c @@ -37,6 +37,24 @@ static const uint8_t pps[] = {0xD0, 0x11, 0x00, 0x52, 0xA6}; #endif +// this struct is used by EPA_Parse_CardAccess and contains info about the +// PACE protocol supported by the chip +typedef struct { + uint8_t oid[10]; + uint8_t version; + uint8_t parameter_id; +} pace_version_info_t; + +// general functions +static void EPA_Finish(void); +static size_t EPA_Parse_CardAccess(const uint8_t *data, size_t length, pace_version_info_t *pace_info); +static int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length); +static int EPA_Setup(void); + +// PACE related functions +static int EPA_PACE_MSE_Set_AT(const pace_version_info_t pace_version_info, uint8_t password); +static int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce); + // APDUs for communication with German Identification Card // General Authenticate (request encrypted nonce) WITHOUT the Le at the end @@ -153,7 +171,7 @@ static int EPA_APDU(uint8_t *apdu, size_t length, uint8_t *response, uint16_t re //----------------------------------------------------------------------------- // Closes the communication channel and turns off the field //----------------------------------------------------------------------------- -void EPA_Finish(void) { +static void EPA_Finish(void) { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); LEDsoff(); iso_type = 0; @@ -172,7 +190,7 @@ void EPA_Finish(void) { // TODO: Support elements with long tags (tag is longer than 1 byte) // TODO: Support proprietary PACE domain parameters //----------------------------------------------------------------------------- -size_t EPA_Parse_CardAccess(uint8_t *data, size_t length, pace_version_info_t *pace_info) { +static size_t EPA_Parse_CardAccess(const uint8_t *data, size_t length, pace_version_info_t *pace_info) { size_t index = 0; @@ -243,7 +261,7 @@ size_t EPA_Parse_CardAccess(uint8_t *data, size_t length, pace_version_info_t *p // Returns -1 on failure or the length of the data on success // TODO: for the moment this sends only 1 APDU regardless of the requested length //----------------------------------------------------------------------------- -int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length) { +static int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length) { // the response APDU of the card // since the card doesn't always care for the expected length we send it, // we reserve 262 bytes here just to be safe (256-byte APDU + SW + ISO frame) @@ -300,7 +318,7 @@ static void EPA_PACE_Collect_Nonce_Abort(uint32_t cmd, uint8_t step, int func_re //----------------------------------------------------------------------------- // Acquire one encrypted PACE nonce //----------------------------------------------------------------------------- -void EPA_PACE_Collect_Nonce(PacketCommandNG *c) { +void EPA_PACE_Collect_Nonce(const PacketCommandNG *c) { /* * ack layout: * arg: @@ -354,7 +372,7 @@ void EPA_PACE_Collect_Nonce(PacketCommandNG *c) { struct p { uint32_t m; } PACKED; - struct p *packet = (struct p *)c->data.asBytes; + const struct p *packet = (const struct p *)c->data.asBytes; func_return = EPA_PACE_Get_Nonce(packet->m, nonce); // check if the command succeeded @@ -377,7 +395,7 @@ void EPA_PACE_Collect_Nonce(PacketCommandNG *c) { // Returns the actual size of the nonce on success or a less-than-zero error // code on failure. //----------------------------------------------------------------------------- -int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce) { +static int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce) { // build the APDU uint8_t apdu[sizeof(apdu_general_authenticate_pace_get_nonce) + 1]; @@ -416,7 +434,7 @@ int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce) { // Initializes the PACE protocol by performing the "MSE: Set AT" step // Returns 0 on success or a non-zero error code on failure //----------------------------------------------------------------------------- -int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password) { +static int EPA_PACE_MSE_Set_AT(const pace_version_info_t pace_version_info, uint8_t password) { // create the MSE: Set AT APDU uint8_t apdu[23]; @@ -479,7 +497,7 @@ int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password) //----------------------------------------------------------------------------- // Perform the PACE protocol by replaying given APDUs //----------------------------------------------------------------------------- -void EPA_PACE_Replay(PacketCommandNG *c) { +void EPA_PACE_Replay(const PacketCommandNG *c) { uint32_t timings[ARRAYLEN(apdu_lengths_replay)] = {0}; @@ -547,7 +565,7 @@ void EPA_PACE_Replay(PacketCommandNG *c) { // Set up a communication channel (Card Select, PPS) // Returns 0 on success or a non-zero error code on failure //----------------------------------------------------------------------------- -int EPA_Setup(void) { +static int EPA_Setup(void) { #ifdef WITH_ISO14443a { @@ -593,7 +611,7 @@ int EPA_Setup(void) { return 1; } -void EPA_PACE_Simulate(PacketCommandNG *c) { +void EPA_PACE_Simulate(const PacketCommandNG *c) { //---------Initializing--------- diff --git a/armsrc/epa.h b/armsrc/epa.h index 72524f836..62880eca3 100644 --- a/armsrc/epa.h +++ b/armsrc/epa.h @@ -22,26 +22,8 @@ #include "common.h" #include "pm3_cmd.h" -// this struct is used by EPA_Parse_CardAccess and contains info about the -// PACE protocol supported by the chip -typedef struct { - uint8_t oid[10]; - uint8_t version; - uint8_t parameter_id; -} pace_version_info_t; - -// general functions -void EPA_Finish(void); -size_t EPA_Parse_CardAccess(uint8_t *data, size_t length, pace_version_info_t *pace_info); -int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length); -int EPA_Setup(void); - -// PACE related functions -int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password); -int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce); - -void EPA_PACE_Collect_Nonce(PacketCommandNG *c); -void EPA_PACE_Replay(PacketCommandNG *c); -void EPA_PACE_Simulate(PacketCommandNG *c); +void EPA_PACE_Collect_Nonce(const PacketCommandNG *c); +void EPA_PACE_Replay(const PacketCommandNG *c); +void EPA_PACE_Simulate(const PacketCommandNG *c); #endif /* __EPA_H */ diff --git a/armsrc/felica.c b/armsrc/felica.c index 0a74a30cc..b575ad9c4 100644 --- a/armsrc/felica.c +++ b/armsrc/felica.c @@ -49,7 +49,7 @@ static uint32_t felica_lasttime_prox2air_start; static void iso18092_setup(uint8_t fpga_minor_mode); static uint8_t felica_select_card(felica_card_select_t *card); -static void TransmitFor18092_AsReader(uint8_t *frame, uint16_t len, uint32_t *timing, uint8_t power, uint8_t highspeed); +static void TransmitFor18092_AsReader(const uint8_t *frame, uint16_t len, const uint32_t *NYI_timing_NYI, uint8_t power, uint8_t highspeed); static bool WaitForFelicaReply(uint16_t maxbytes); static void iso18092_set_timeout(uint32_t timeout) { @@ -269,13 +269,13 @@ static uint8_t felica_select_card(felica_card_select_t *card) { // copy UID // idm 8 if (card) { - memcpy(card->IDm, FelicaFrame.framebytes + 4, 8); + memcpy(card->IDm, FelicaFrame.framebytes + 4, 8); memcpy(card->PMm, FelicaFrame.framebytes + 4 + 8, 8); //memcpy(card->servicecode, FelicaFrame.framebytes + 4 + 8 + 8, 2); - memcpy(card->code, card->IDm, 2); - memcpy(card->uid, card->IDm + 2, 6); - memcpy(card->iccode, card->PMm, 2); - memcpy(card->mrt, card->PMm + 2, 6); + memcpy(card->code, card->IDm, 2); + memcpy(card->uid, card->IDm + 2, 6); + memcpy(card->iccode, card->PMm, 2); + memcpy(card->mrt, card->PMm + 2, 6); if (g_dbglevel >= DBG_DEBUG) { Dbprintf("Received Frame: "); Dbhexdump(FelicaFrame.len, FelicaFrame.framebytes, 0); @@ -350,7 +350,12 @@ static void BuildFliteRdblk(const uint8_t *idm, uint8_t blocknum, const uint16_t AddCrc(frameSpace + 2, c - 2); } -static void TransmitFor18092_AsReader(uint8_t *frame, uint16_t len, uint32_t *timing, uint8_t power, uint8_t highspeed) { +static void TransmitFor18092_AsReader(const uint8_t *frame, uint16_t len, const uint32_t *NYI_timing_NYI, uint8_t power, uint8_t highspeed) { + if (NYI_timing_NYI != NULL) { + Dbprintf("Error: TransmitFor18092_AsReader does not check or set parameter NYI_timing_NYI"); + return; + } + uint16_t flags = FPGA_MAJOR_MODE_HF_ISO18092; if (power) flags |= FPGA_HF_ISO18092_FLAG_READER; @@ -512,12 +517,12 @@ static void felica_reset_frame_mode(void) { // arg0 FeliCa flags // arg1 len of commandbytes // d.asBytes command bytes to send -void felica_sendraw(PacketCommandNG *c) { +void felica_sendraw(const PacketCommandNG *c) { if (g_dbglevel >= DBG_DEBUG) Dbprintf("FeliCa_sendraw Enter"); felica_command_t param = c->oldarg[0]; size_t len = c->oldarg[1] & 0xffff; - uint8_t *cmd = c->data.asBytes; + const uint8_t *cmd = c->data.asBytes; uint32_t arg0; felica_card_select_t card; @@ -675,7 +680,7 @@ void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) { #define R_READBLK_LEN 0x21 //simulate NFC Tag3 card - for now only poll response works // second half (4 bytes) of NDEF2 goes into nfcid2_0, first into nfcid2_1 -void felica_sim_lite(uint8_t *uid) { +void felica_sim_lite(const uint8_t *uid) { // prepare our 3 responses... uint8_t resp_poll0[R_POLL0_LEN] = { 0xb2, 0x4d, 0x12, FELICA_POLL_ACK, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x01, 0x43, 0x00, 0xb3, 0x7f}; diff --git a/armsrc/felica.h b/armsrc/felica.h index 8f232b3e4..2677dbfb9 100644 --- a/armsrc/felica.h +++ b/armsrc/felica.h @@ -21,9 +21,9 @@ #include "common.h" #include "cmd.h" -void felica_sendraw(PacketCommandNG *c); +void felica_sendraw(const PacketCommandNG *c); void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip); -void felica_sim_lite(uint8_t *uid); +void felica_sim_lite(const uint8_t *uid); void felica_dump_lite_s(void); #endif diff --git a/armsrc/fpgaloader.h b/armsrc/fpgaloader.h index 6069d3257..3359643f1 100644 --- a/armsrc/fpgaloader.h +++ b/armsrc/fpgaloader.h @@ -34,6 +34,9 @@ /* Communication between ARM / FPGA is done inside armsrc/fpgaloader.c (function FpgaSendCommand) Send 16 bit command / data pair to FPGA + + BUGBUG -- Conflicts with information in ../fpga/define.v + The bit format is: C3 C2 C1 C0 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 where C is 4bit command diff --git a/armsrc/hfops.c b/armsrc/hfops.c index 6a97be76a..df42c8685 100644 --- a/armsrc/hfops.c +++ b/armsrc/hfops.c @@ -200,7 +200,7 @@ static uint32_t HfEncodeTkm(const uint8_t *uid, uint8_t modulation, uint8_t *dat return len; } -int HfSimulateTkm(uint8_t *uid, uint8_t modulation, uint32_t timeout) { +int HfSimulateTkm(const uint8_t *uid, uint8_t modulation, uint32_t timeout) { // free eventually allocated BigBuf memory BigBuf_free_keep_EM(); diff --git a/armsrc/hfops.h b/armsrc/hfops.h index 352f9d2bc..c738887b4 100644 --- a/armsrc/hfops.h +++ b/armsrc/hfops.h @@ -22,6 +22,6 @@ #include "common.h" int HfReadADC(uint32_t samplesCount, bool ledcontrol); -int HfSimulateTkm(uint8_t *uid, uint8_t modulation, uint32_t timeout); +int HfSimulateTkm(const uint8_t *uid, uint8_t modulation, uint32_t timeout); #endif diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index 7206b735c..d4abe9ff1 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -979,7 +979,7 @@ static bool hitag2_read_uid(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t return true; } -void EloadHitag(uint8_t *data, uint16_t len) { +void EloadHitag(const uint8_t *data, uint16_t len) { memcpy(tag.sectors, data, sizeof(tag.sectors)); } @@ -1532,7 +1532,7 @@ void SimulateHitag2(bool ledcontrol) { // reply_ng(CMD_LF_HITAG_SIMULATE, (checked == -1) ? PM3_EOPABORTED : PM3_SUCCESS, (uint8_t *)tag.sectors, tag_size); } -void ReaderHitag(hitag_function htf, hitag_data *htd, bool ledcontrol) { +void ReaderHitag(hitag_function htf, const hitag_data *htd, bool ledcontrol) { uint32_t command_start = 0, command_duration = 0; uint32_t response_start = 0, response_duration = 0; @@ -1928,7 +1928,7 @@ out: reply_mix(CMD_ACK, bSuccessful, 0, 0, 0, 0); } -void WriterHitag(hitag_function htf, hitag_data *htd, int page, bool ledcontrol) { +void WriterHitag(hitag_function htf, const hitag_data *htd, int page, bool ledcontrol) { uint32_t command_start = 0; uint32_t command_duration = 0; diff --git a/armsrc/hitag2.h b/armsrc/hitag2.h index dcad3b417..90aa8132b 100644 --- a/armsrc/hitag2.h +++ b/armsrc/hitag2.h @@ -24,7 +24,7 @@ void SniffHitag2(bool ledcontrol); void SimulateHitag2(bool ledcontrol); -void ReaderHitag(hitag_function htf, hitag_data *htd, bool ledcontrol); -void WriterHitag(hitag_function htf, hitag_data *htd, int page, bool ledcontrol); -void EloadHitag(uint8_t *data, uint16_t len); +void ReaderHitag(hitag_function htf, const hitag_data *htd, bool ledcontrol); +void WriterHitag(hitag_function htf, const hitag_data *htd, int page, bool ledcontrol); +void EloadHitag(const uint8_t *data, uint16_t len); #endif diff --git a/armsrc/hitag2_crypto.c b/armsrc/hitag2_crypto.c index a8a01dae4..9b59b5521 100644 --- a/armsrc/hitag2_crypto.c +++ b/armsrc/hitag2_crypto.c @@ -90,18 +90,18 @@ uint32_t _hitag2_byte(uint64_t *x) { } void hitag2_cipher_reset(struct hitag2_tag *tag, const uint8_t *iv) { - uint64_t key = ((uint64_t)tag->sectors[2][2]) | - ((uint64_t)tag->sectors[2][3] << 8) | + uint64_t key = ((uint64_t)tag->sectors[2][2] ) | + ((uint64_t)tag->sectors[2][3] << 8) | ((uint64_t)tag->sectors[1][0] << 16) | ((uint64_t)tag->sectors[1][1] << 24) | ((uint64_t)tag->sectors[1][2] << 32) | ((uint64_t)tag->sectors[1][3] << 40); - uint32_t uid = ((uint32_t)tag->sectors[0][0]) | - ((uint32_t)tag->sectors[0][1] << 8) | + uint32_t uid = ((uint32_t)tag->sectors[0][0] ) | + ((uint32_t)tag->sectors[0][1] << 8) | ((uint32_t)tag->sectors[0][2] << 16) | ((uint32_t)tag->sectors[0][3] << 24); - uint32_t iv_ = (((uint32_t)(iv[0]))) | - (((uint32_t)(iv[1])) << 8) | + uint32_t iv_ = (((uint32_t)(iv[0])) ) | + (((uint32_t)(iv[1])) << 8) | (((uint32_t)(iv[2])) << 16) | (((uint32_t)(iv[3])) << 24); tag->cs = _hitag2_init(REV64(key), REV32(uid), REV32(iv_)); diff --git a/armsrc/spiffs.c b/armsrc/spiffs.c index e243b8ed1..359f2f07c 100644 --- a/armsrc/spiffs.c +++ b/armsrc/spiffs.c @@ -196,17 +196,19 @@ int rdv40_spiffs_check(void) { ///// Base RDV40_SPIFFS_SAFETY_NORMAL operations//////////////////////////////// -void write_to_spiffs(const char *filename, uint8_t *src, uint32_t size) { +void write_to_spiffs(const char *filename, const uint8_t *src, uint32_t size) { spiffs_file fd = SPIFFS_open(&fs, filename, SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0); - if (SPIFFS_write(&fs, fd, src, size) < 0) { + // Note: SPIFFS_write() doesn't declare third parameter as const (but should) + if (SPIFFS_write(&fs, fd, (void*)src, size) < 0) { Dbprintf("wr errno %i\n", SPIFFS_errno(&fs)); } SPIFFS_close(&fs, fd); } -void append_to_spiffs(const char *filename, uint8_t *src, uint32_t size) { +void append_to_spiffs(const char *filename, const uint8_t *src, uint32_t size) { spiffs_file fd = SPIFFS_open(&fs, filename, SPIFFS_APPEND | SPIFFS_RDWR, 0); - if (SPIFFS_write(&fs, fd, src, size) < 0) { + // Note: SPIFFS_write() doesn't declare third parameter as const (but should) + if (SPIFFS_write(&fs, fd, (void*)src, size) < 0) { Dbprintf("errno %i\n", SPIFFS_errno(&fs)); } SPIFFS_close(&fs, fd); @@ -310,10 +312,10 @@ static int is_valid_filename(const char *filename) { } */ static void copy_in_spiffs(const char *src, const char *dst) { - uint32_t size = size_in_spiffs((char *)src); + uint32_t size = size_in_spiffs(src); uint8_t *mem = BigBuf_malloc(size); - read_from_spiffs((char *)src, (uint8_t *)mem, size); - write_to_spiffs((char *)dst, (uint8_t *)mem, size); + read_from_spiffs(src, (uint8_t *)mem, size); + write_to_spiffs(dst, (uint8_t *)mem, size); } //////////////////////////////////////////////////////////////////////////////// @@ -434,7 +436,7 @@ int rdv40_spiffs_lazy_mount_rollback(int changed) { // TODO : forbid writing to a filename which already exists as lnk ! // TODO : forbid writing to a filename.lnk which already exists without lnk ! // Note: Writing in SPIFFS_WRITE_CHUNK_SIZE (8192) byte chucks helps to ensure "free space" has been erased by GC (Garbage collection) -int rdv40_spiffs_write(const char *filename, uint8_t *src, uint32_t size, RDV40SpiFFSSafetyLevel level) { +int rdv40_spiffs_write(const char *filename, const uint8_t *src, uint32_t size, RDV40SpiFFSSafetyLevel level) { RDV40_SPIFFS_SAFE_FUNCTION( uint32_t idx; if (size <= SPIFFS_WRITE_CHUNK_SIZE) { @@ -457,7 +459,7 @@ int rdv40_spiffs_write(const char *filename, uint8_t *src, uint32_t size, RDV40S ) } -int rdv40_spiffs_append(const char *filename, uint8_t *src, uint32_t size, RDV40SpiFFSSafetyLevel level) { +int rdv40_spiffs_append(const char *filename, const uint8_t *src, uint32_t size, RDV40SpiFFSSafetyLevel level) { RDV40_SPIFFS_SAFE_FUNCTION( uint32_t idx; // Append any SPIFFS_WRITE_CHUNK_SIZE byte chunks @@ -480,26 +482,26 @@ int rdv40_spiffs_read(const char *filename, uint8_t *dst, uint32_t size, RDV40Sp // TODO : forbid writing to a filename which already exists as lnk ! // TODO : forbid writing to a filename.lnk which already exists without lnk ! -int rdv40_spiffs_rename(char *old_filename, char *new_filename, RDV40SpiFFSSafetyLevel level) { +int rdv40_spiffs_rename(const char *old_filename, const char *new_filename, RDV40SpiFFSSafetyLevel level) { RDV40_SPIFFS_SAFE_FUNCTION( // rename_in_spiffs(old_filename, new_filename); // ) } -int rdv40_spiffs_remove(char *filename, RDV40SpiFFSSafetyLevel level) { +int rdv40_spiffs_remove(const char *filename, RDV40SpiFFSSafetyLevel level) { RDV40_SPIFFS_SAFE_FUNCTION( // remove_from_spiffs(filename); // ) } -int rdv40_spiffs_copy(char *src, char *dst, RDV40SpiFFSSafetyLevel level) { +int rdv40_spiffs_copy(const char *src_filename, const char *dst_filename, RDV40SpiFFSSafetyLevel level) { RDV40_SPIFFS_SAFE_FUNCTION( // - copy_in_spiffs(src, dst); // + copy_in_spiffs(src_filename, dst_filename); // ) } -int rdv40_spiffs_stat(char *filename, uint32_t *buf, RDV40SpiFFSSafetyLevel level) { +int rdv40_spiffs_stat(const char *filename, uint32_t *size_in_bytes, RDV40SpiFFSSafetyLevel level) { RDV40_SPIFFS_SAFE_FUNCTION( // - *buf = size_in_spiffs(filename); // + *size_in_bytes = size_in_spiffs(filename); // ) } @@ -530,7 +532,7 @@ int rdv40_spiffs_is_symlink(const char *s) { // symlink ?") // ATTENTION : you must NOT provide the whole filename (so please do not include the .lnk extension) // TODO : integrate in read_function -int rdv40_spiffs_read_as_symlink(char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level) { +int rdv40_spiffs_read_as_symlink(const char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level) { RDV40_SPIFFS_SAFE_FUNCTION( char linkdest[SPIFFS_OBJ_NAME_LEN]; @@ -538,7 +540,7 @@ int rdv40_spiffs_read_as_symlink(char *filename, uint8_t *dst, uint32_t size, RD sprintf(linkfilename, "%s.lnk", filename); if (g_dbglevel >= DBG_DEBUG) - Dbprintf("Linkk real filename is " _YELLOW_("%s"), linkfilename); + Dbprintf("Link real filename is " _YELLOW_("%s"), linkfilename); read_from_spiffs((char *)linkfilename, (uint8_t *)linkdest, SPIFFS_OBJ_NAME_LEN); @@ -561,11 +563,11 @@ int rdv40_spiffs_read_as_symlink(char *filename, uint8_t *dst, uint32_t size, RD // which you can then read back with : // rdv40_spiffs_read_as_symlink((uint8_t *)"world",(uint8_t *) buffer, orig_file_size, RDV40_SPIFFS_SAFETY_SAFE); // TODO : FORBID creating a symlink with a basename (before.lnk) which already exists as a file ! -int rdv40_spiffs_make_symlink(char *linkdest, char *filename, RDV40SpiFFSSafetyLevel level) { +int rdv40_spiffs_make_symlink(const char *linkdest, const char *filename, RDV40SpiFFSSafetyLevel level) { RDV40_SPIFFS_SAFE_FUNCTION( char linkfilename[SPIFFS_OBJ_NAME_LEN]; sprintf(linkfilename, "%s.lnk", filename); - write_to_spiffs((char *)linkfilename, (uint8_t *)linkdest, SPIFFS_OBJ_NAME_LEN); + write_to_spiffs(linkfilename, (const uint8_t *)linkdest, SPIFFS_OBJ_NAME_LEN); ) } @@ -575,15 +577,15 @@ int rdv40_spiffs_make_symlink(char *linkdest, char *filename, RDV40SpiFFSSafetyL // Still, this case won't happen when the write(s) functions will check for both symlink and real file // preexistence, avoiding a link being created if filename exists, or avoiding a file being created if // symlink exists with same name -int rdv40_spiffs_read_as_filetype(char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level) { +int rdv40_spiffs_read_as_filetype(const char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level) { RDV40_SPIFFS_SAFE_FUNCTION( RDV40SpiFFSFileType filetype = filetype_in_spiffs((char *)filename); switch (filetype) { case RDV40_SPIFFS_FILETYPE_REAL: - rdv40_spiffs_read((char *)filename, (uint8_t *)dst, size, level); + rdv40_spiffs_read(filename, dst, size, level); break; case RDV40_SPIFFS_FILETYPE_SYMLINK: - rdv40_spiffs_read_as_symlink(filename, (uint8_t *)dst, size, level); + rdv40_spiffs_read_as_symlink(filename, dst, size, level); break; case RDV40_SPIFFS_FILETYPE_BOTH: case RDV40_SPIFFS_FILETYPE_UNKNOWN: diff --git a/armsrc/spiffs.h b/armsrc/spiffs.h index 5958e559b..7bbfb794b 100644 --- a/armsrc/spiffs.h +++ b/armsrc/spiffs.h @@ -46,18 +46,18 @@ typedef struct rdv40_spiffs_fsinfo { uint32_t usedPercent, freePercent; } rdv40_spiffs_fsinfo; -int rdv40_spiffs_read_as_filetype(char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level); +int rdv40_spiffs_read_as_filetype(const char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level); int rdv40_spiffs_check(void); int rdv40_spiffs_lazy_unmount(void); int rdv40_spiffs_lazy_mount(void); int rdv40_spiffs_lazy_mount_rollback(int changed); -int rdv40_spiffs_write(const char *filename, uint8_t *src, uint32_t size, RDV40SpiFFSSafetyLevel level); +int rdv40_spiffs_write(const char *filename, const uint8_t *src, uint32_t size, RDV40SpiFFSSafetyLevel level); int rdv40_spiffs_read(const char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level); -int rdv40_spiffs_rename(char *old_filename, char *new_filename, RDV40SpiFFSSafetyLevel level); -int rdv40_spiffs_remove(char *filename, RDV40SpiFFSSafetyLevel level); -int rdv40_spiffs_read_as_symlink(char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level); -void write_to_spiffs(const char *filename, uint8_t *src, uint32_t size); +int rdv40_spiffs_rename(const char *old_filename, const char *new_filename, RDV40SpiFFSSafetyLevel level); +int rdv40_spiffs_remove(const char *filename, RDV40SpiFFSSafetyLevel level); +int rdv40_spiffs_read_as_symlink(const char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level); +void write_to_spiffs(const char *filename, const uint8_t *src, uint32_t size); void read_from_spiffs(const char *filename, uint8_t *dst, uint32_t size); void test_spiffs(void); void rdv40_spiffs_safe_print_tree(void); @@ -65,11 +65,11 @@ int rdv40_spiffs_unmount(void); int rdv40_spiffs_mount(void); int rdv40_spiffs_is_symlink(const char *s); void rdv40_spiffs_safe_print_fsinfo(void); -int rdv40_spiffs_make_symlink(char *linkdest, char *filename, RDV40SpiFFSSafetyLevel level); -void append_to_spiffs(const char *filename, uint8_t *src, uint32_t size); -int rdv40_spiffs_copy(char *src, char *dst, RDV40SpiFFSSafetyLevel level); -int rdv40_spiffs_append(const char *filename, uint8_t *src, uint32_t size, RDV40SpiFFSSafetyLevel level); -int rdv40_spiffs_stat(char *filename, uint32_t *buf, RDV40SpiFFSSafetyLevel level); +int rdv40_spiffs_make_symlink(const char *linkdest, const char *filename, RDV40SpiFFSSafetyLevel level); +void append_to_spiffs(const char *filename, const uint8_t *src, uint32_t size); +int rdv40_spiffs_copy(const char *src_filename, const char *dst_filename, RDV40SpiFFSSafetyLevel level); +int rdv40_spiffs_append(const char *filename, const uint8_t *src, uint32_t size, RDV40SpiFFSSafetyLevel level); +int rdv40_spiffs_stat(const char *filename, uint32_t *size_in_bytes, RDV40SpiFFSSafetyLevel level); uint32_t size_in_spiffs(const char *filename); int exists_in_spiffs(const char *filename); diff --git a/armsrc/usart.c b/armsrc/usart.c index 915d4a445..a205acb03 100644 --- a/armsrc/usart.c +++ b/armsrc/usart.c @@ -18,6 +18,34 @@ #include "usart.h" #include "proxmark3_arm.h" +#define Dbprintf_usb(...) {\ + bool tmpfpc = g_reply_via_fpc;\ + bool tmpusb = g_reply_via_usb;\ + g_reply_via_fpc = false;\ + g_reply_via_usb = true;\ + Dbprintf(__VA_ARGS__);\ + g_reply_via_fpc = tmpfpc;\ + g_reply_via_usb = tmpusb;} + +#define Dbprintf_fpc(...) {\ + bool tmpfpc = g_reply_via_fpc;\ + bool tmpusb = g_reply_via_usb;\ + g_reply_via_fpc = true;\ + g_reply_via_usb = false;\ + Dbprintf(__VA_ARGS__);\ + g_reply_via_fpc = tmpfpc;\ + g_reply_via_usb = tmpusb;} + +#define Dbprintf_all(...) {\ + bool tmpfpc = g_reply_via_fpc;\ + bool tmpusb = g_reply_via_usb;\ + g_reply_via_fpc = true;\ + g_reply_via_usb = true;\ + Dbprintf(__VA_ARGS__);\ + g_reply_via_fpc = tmpfpc;\ + g_reply_via_usb = tmpusb;} + + static volatile AT91PS_USART pUS1 = AT91C_BASE_US1; static volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA; static volatile AT91PS_PDC pPDC = AT91C_BASE_PDC_US1;