diff --git a/armsrc/Standalone/hf_14asniff.c b/armsrc/Standalone/hf_14asniff.c index 3cbaa05f6..c52928825 100644 --- a/armsrc/Standalone/hf_14asniff.c +++ b/armsrc/Standalone/hf_14asniff.c @@ -68,7 +68,7 @@ #define HF_14ASNIFF_LOGFILE "hf_14asniff.trc" -void DownloadTraceInstructions(void) { +static void DownloadTraceInstructions(void) { Dbprintf(""); Dbprintf("To get the trace from flash and display it:"); Dbprintf("1. mem spiffs dump o "HF_14ASNIFF_LOGFILE" f trace.trc"); diff --git a/armsrc/Standalone/hf_bog.c b/armsrc/Standalone/hf_bog.c index c34f0e20a..50e1d824f 100644 --- a/armsrc/Standalone/hf_bog.c +++ b/armsrc/Standalone/hf_bog.c @@ -41,7 +41,7 @@ from the client to view the stored quadlets. #define HF_BOG_LOGFILE "hf_bog.log" // This is actually copied from SniffIso14443a -void RAMFUNC SniffAndStore(uint8_t param) { +static void RAMFUNC SniffAndStore(uint8_t param) { iso14443a_setup(FPGA_HF_ISO14443A_SNIFFER); diff --git a/armsrc/Standalone/hf_colin.c b/armsrc/Standalone/hf_colin.c index 78b36eb78..b1090a019 100644 --- a/armsrc/Standalone/hf_colin.c +++ b/armsrc/Standalone/hf_colin.c @@ -104,7 +104,12 @@ static const uint8_t is_hex[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +// Note: inlining this function would fail with -Os +#ifdef __OPTIMIZE_SIZE__ +static uint64_t hex2i(const char *s) { +#else static inline uint64_t hex2i(const char *s) { +#endif uint64_t val = 0; if (s == NULL || s[0] == 0) return 0; @@ -198,14 +203,14 @@ MFC1KSchema InfiHexact = {.name = "Infineon/Hexact", int total_schemas = 0; -void add_schema(MFC1KSchema *p, MFC1KSchema a, int *schemas_counter) { +static void add_schema(MFC1KSchema *p, MFC1KSchema a, int *schemas_counter) { if (*schemas_counter < MAX_SCHEMAS) { p[*schemas_counter] = a; *schemas_counter += 1; } } - -void delete_schema(MFC1KSchema *p, int *schemas_counter, int index) { +/* +static void delete_schema(MFC1KSchema *p, int *schemas_counter, int index) { if (*schemas_counter > 0 && index < *schemas_counter && index > -1) { int last_index = *schemas_counter - 1; for (int i = index; i < last_index; i++) { @@ -214,23 +219,23 @@ void delete_schema(MFC1KSchema *p, int *schemas_counter, int index) { *schemas_counter -= 1; } } - -void cjSetCursFRight(void) { +*/ +static void cjSetCursFRight(void) { vtsend_cursor_position(NULL, 98, (currfline)); currfline++; } -void cjSetCursRight(void) { +static void cjSetCursRight(void) { vtsend_cursor_position(NULL, 59, (currline)); currline++; } -void cjSetCursLeft(void) { +static void cjSetCursLeft(void) { vtsend_cursor_position(NULL, 0, (curlline)); curlline++; } -void cjTabulize(void) { DbprintfEx(FLAG_RAWPRINT, "\t\t\t"); } +static void cjTabulize(void) { DbprintfEx(FLAG_RAWPRINT, "\t\t\t"); } /* void cjPrintKey(uint64_t key, uint8_t *foundKey, uint16_t sectorNo, uint8_t type) { @@ -240,7 +245,7 @@ foundKey[5]); cjSetCursRight(); DbprintfEx(FLAG_NEWLINE, "SEC: %02x | KEY : %s | } */ -char *ReadSchemasFromSPIFFS(char *filename) { +static char *ReadSchemasFromSPIFFS(char *filename) { SpinOff(0); int changed = rdv40_spiffs_lazy_mount(); @@ -255,7 +260,7 @@ char *ReadSchemasFromSPIFFS(char *filename) { return (char *)mem; } -void add_schemas_from_json_in_spiffs(char *filename) { +static void add_schemas_from_json_in_spiffs(char *filename) { char *jsonfile = ReadSchemasFromSPIFFS((char *)filename); @@ -275,7 +280,7 @@ void add_schemas_from_json_in_spiffs(char *filename) { } } -void ReadLastTagFromFlash(void) { +static void ReadLastTagFromFlash(void) { SpinOff(0); LED_A_ON(); LED_B_ON(); diff --git a/armsrc/Standalone/hf_legic.c b/armsrc/Standalone/hf_legic.c index d1add7fe3..5bcbfca63 100644 --- a/armsrc/Standalone/hf_legic.c +++ b/armsrc/Standalone/hf_legic.c @@ -44,7 +44,7 @@ * */ -void DownloadLogInstructions(void) { +static void DownloadLogInstructions(void) { Dbprintf(""); Dbprintf("[=] List all dumps from flash:"); Dbprintf("[=] " _YELLOW_("-") " mem spiffs tree"); @@ -53,7 +53,7 @@ void DownloadLogInstructions(void) { Dbprintf("[=] " _YELLOW_("-") " mem spiffs dump o hf-legic-UID-dump.bin f hf-legic-UID-dump.bin"); } -void save_dump_to_file(legic_card_select_t *p_card) { +static void save_dump_to_file(legic_card_select_t *p_card) { #ifdef WITH_FLASH diff --git a/armsrc/Standalone/lf_em4100emul.c b/armsrc/Standalone/lf_em4100emul.c index 166c668f8..6ad2580a4 100644 --- a/armsrc/Standalone/lf_em4100emul.c +++ b/armsrc/Standalone/lf_em4100emul.c @@ -18,6 +18,7 @@ #include "ticks.h" #include "string.h" #include "BigBuf.h" +#include "commonutil.h" #define MAX_IND 16 // 4 LEDs - 2^4 combinations #define CLOCK 64 //for 125kHz @@ -34,7 +35,7 @@ void ModInfo(void) { DbpString(" LF EM4100 simulator standalone mode"); } -uint64_t ReversQuads(uint64_t bits) { +static uint64_t ReversQuads(uint64_t bits) { uint64_t result = 0; for (int i = 0; i < 16; i++) { result += ((bits >> (60 - 4 * i)) & 0xf) << (4 * i); @@ -42,14 +43,14 @@ uint64_t ReversQuads(uint64_t bits) { return result >> 24; } -void FillBuff(uint8_t bit) { +static void FillBuff(uint8_t bit) { memset(bba + buflen, bit, CLOCK / 2); buflen += (CLOCK / 2); memset(bba + buflen, bit ^ 1, CLOCK / 2); buflen += (CLOCK / 2); } -void ConstructEM410xEmulBuf(uint64_t id) { +static void ConstructEM410xEmulBuf(uint64_t id) { int i, j, binary[4], parity[4]; buflen = 0; @@ -70,7 +71,7 @@ void ConstructEM410xEmulBuf(uint64_t id) { FillBuff(0); } -void LED_Slot(int i) { +static void LED_Slot(int i) { LEDsoff(); if (slots_count > 4) { LED(i % MAX_IND, 0); //binary indication for slots_count > 4 diff --git a/armsrc/Standalone/lf_em4100rwc.c b/armsrc/Standalone/lf_em4100rwc.c index 19aa39919..a7364bd81 100644 --- a/armsrc/Standalone/lf_em4100rwc.c +++ b/armsrc/Standalone/lf_em4100rwc.c @@ -27,6 +27,7 @@ #include "string.h" #include "BigBuf.h" #include "spiffs.h" +#include "commonutil.h" #ifdef WITH_FLASH #include "flashmem.h" @@ -47,7 +48,7 @@ void ModInfo(void) { DbpString(" LF EM4100 read/write/clone mode"); } -uint64_t ReversQuads(uint64_t bits) { +static uint64_t ReversQuads(uint64_t bits) { uint64_t result = 0; for (int i = 0; i < 16; i++) { result += ((bits >> (60 - 4 * i)) & 0xf) << (4 * i); @@ -55,14 +56,14 @@ uint64_t ReversQuads(uint64_t bits) { return result >> 24; } -void FillBuff(uint8_t bit) { +static void FillBuff(uint8_t bit) { memset(bba + buflen, bit, CLOCK / 2); buflen += (CLOCK / 2); memset(bba + buflen, bit ^ 1, CLOCK / 2); buflen += (CLOCK / 2); } -void ConstructEM410xEmulBuf(uint64_t id) { +static void ConstructEM410xEmulBuf(uint64_t id) { int i, j, binary[4], parity[4]; buflen = 0; @@ -83,7 +84,7 @@ void ConstructEM410xEmulBuf(uint64_t id) { FillBuff(0); } -void LED_Slot(int i) { +static void LED_Slot(int i) { LEDsoff(); if (slots_count > 4) { LED(i % MAX_IND, 0); //binary indication, usefully for slots_count > 4 @@ -92,7 +93,7 @@ void LED_Slot(int i) { } } -void FlashLEDs(uint32_t speed, uint8_t times) { +static void FlashLEDs(uint32_t speed, uint8_t times) { for (int i = 0; i < times * 2; i++) { LED_A_INV(); LED_B_INV(); @@ -103,9 +104,9 @@ void FlashLEDs(uint32_t speed, uint8_t times) { } #ifdef WITH_FLASH -void SaveIDtoFlash(int addr, uint64_t id) { +static void SaveIDtoFlash(int addr, uint64_t id) { uint8_t bt[5]; - char *filename = "emdump"; + const char *filename = "emdump"; rdv40_spiffs_mount(); for (int i = 0; i < 5; i++) { bt[4 - i] = (uint8_t)(id >> 8 * i & 0xff); diff --git a/armsrc/Standalone/lf_icehid.c b/armsrc/Standalone/lf_icehid.c index 29a87305d..7ac91d126 100644 --- a/armsrc/Standalone/lf_icehid.c +++ b/armsrc/Standalone/lf_icehid.c @@ -54,7 +54,7 @@ #define LF_HIDCOLLECT_LOGFILE "lf_hidcollect.log" -void DownloadLogInstructions(void) { +static void DownloadLogInstructions(void) { Dbprintf(""); Dbprintf("[=] To get the logfile from flash and display it:"); Dbprintf("[=] " _YELLOW_("1.") " mem spiffs dump o "LF_HIDCOLLECT_LOGFILE" f "LF_HIDCOLLECT_LOGFILE); @@ -64,7 +64,7 @@ void DownloadLogInstructions(void) { bool log_exists; -void append(uint8_t *entry, size_t entry_len) { +static void append(uint8_t *entry, size_t entry_len) { LED_B_ON(); if (log_exists == false) { @@ -76,7 +76,7 @@ void append(uint8_t *entry, size_t entry_len) { LED_B_OFF(); } -uint32_t IceEM410xdemod(void) { +static uint32_t IceEM410xdemod(void) { uint8_t *dest = BigBuf_get_addr(); size_t idx = 0; @@ -128,7 +128,7 @@ uint32_t IceEM410xdemod(void) { return PM3_SUCCESS; } -uint32_t IceAWIDdemod(void) { +static uint32_t IceAWIDdemod(void) { uint8_t *dest = BigBuf_get_addr(); size_t size = MIN(12800, BigBuf_max_traceLen()); @@ -180,7 +180,7 @@ uint32_t IceAWIDdemod(void) { return PM3_SUCCESS; } -uint32_t IceIOdemod(void) { +static uint32_t IceIOdemod(void) { int dummyIdx = 0; uint8_t version = 0, facilitycode = 0; @@ -224,7 +224,7 @@ uint32_t IceIOdemod(void) { return PM3_SUCCESS; } -uint32_t IceHIDDemod(void) { +static uint32_t IceHIDDemod(void) { int dummyIdx = 0; diff --git a/armsrc/spiffs.c b/armsrc/spiffs.c index 0ade78239..4267412c5 100644 --- a/armsrc/spiffs.c +++ b/armsrc/spiffs.c @@ -400,20 +400,20 @@ int rdv40_spiffs_lazy_mount_rollback(int changed) { // statement or some function taking function parameters // 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_write(char *filename, uint8_t *src, uint32_t size, RDV40SpiFFSSafetyLevel level) { +int rdv40_spiffs_write(const char *filename, uint8_t *src, uint32_t size, RDV40SpiFFSSafetyLevel level) { RDV40_SPIFFS_SAFE_FUNCTION( write_to_spiffs(filename, src, size); ) } -int rdv40_spiffs_append(char *filename, uint8_t *src, uint32_t size, RDV40SpiFFSSafetyLevel level) { +int rdv40_spiffs_append(const char *filename, uint8_t *src, uint32_t size, RDV40SpiFFSSafetyLevel level) { RDV40_SPIFFS_SAFE_FUNCTION( append_to_spiffs(filename, src, size); ) } // todo integrate reading symlinks transparently -int rdv40_spiffs_read(char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level) { +int rdv40_spiffs_read(const char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level) { RDV40_SPIFFS_SAFE_FUNCTION( read_from_spiffs(filename, dst, size); ) diff --git a/armsrc/spiffs.h b/armsrc/spiffs.h index b3578f599..5a9e58a94 100644 --- a/armsrc/spiffs.h +++ b/armsrc/spiffs.h @@ -37,8 +37,8 @@ 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(char *filename, uint8_t *src, uint32_t size, RDV40SpiFFSSafetyLevel level); -int rdv40_spiffs_read(char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level); +int rdv40_spiffs_write(const char *filename, 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); @@ -53,7 +53,7 @@ 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(char *filename, uint8_t *src, uint32_t size, 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); uint32_t size_in_spiffs(const char *filename); int exists_in_spiffs(const char *filename); diff --git a/armsrc/string.c b/armsrc/string.c index 95b53b6ec..8dbe26808 100644 --- a/armsrc/string.c +++ b/armsrc/string.c @@ -247,7 +247,7 @@ int strncmp(const char *s1, const char *s2, size_t n) { #define isspace(a) __extension__ ({ unsigned char bb__isspace = (a) - 9; bb__isspace == (' ' - 9) || bb__isspace <= (13 - 9); }) -/* + unsigned long strtoul(const char *p, char **out_p, int base) { unsigned long v = 0; @@ -319,7 +319,6 @@ long strtol(const char *p, char **out_p, int base) { if (out_p) *out_p = (char *)p; return v; } -*/ char c_tolower(int c) { // (int)a = 97, (int)A = 65 diff --git a/armsrc/string.h b/armsrc/string.h index 0ebb4ab54..f8388d0a1 100644 --- a/armsrc/string.h +++ b/armsrc/string.h @@ -33,6 +33,8 @@ char *strrchr(const char *s, int c); size_t strcspn(const char *s1, const char *s2); char *strpbrk(const char *s1, const char *s2); int strncmp(const char *s1, const char *s2, size_t n); +unsigned long strtoul(const char *p, char **out_p, int base); +long strtol(const char *p, char **out_p, int base); char c_tolower(int c); char c_isprint(unsigned char c);