diff --git a/Makefile b/Makefile index fa3bcf3bc..ba73cff56 100644 --- a/Makefile +++ b/Makefile @@ -93,7 +93,7 @@ style: find . \( -name "*.[ch]" -or -name "*.cpp" \) -exec astyle --formatted --mode=c --suffix=none \ --indent=spaces=4 --indent-switches --indent-preprocessor \ --keep-one-line-blocks --max-instatement-indent=60 \ - --style=linux --pad-oper --unpad-paren --pad-header \ + --style=google --pad-oper --unpad-paren --pad-header \ --align-pointer=name {} \; # Dummy target to test for GNU make availability diff --git a/armsrc/BigBuf.c b/armsrc/BigBuf.c index fcbf898ab..ab45a2681 100644 --- a/armsrc/BigBuf.c +++ b/armsrc/BigBuf.c @@ -34,14 +34,12 @@ static uint32_t traceLen = 0; static bool tracing = true; //todo static? // get the address of BigBuf -uint8_t *BigBuf_get_addr(void) -{ +uint8_t *BigBuf_get_addr(void) { return (uint8_t *)BigBuf; } // get the address of the emulator memory. Allocate part of Bigbuf for it, if not yet done -uint8_t *BigBuf_get_EM_addr(void) -{ +uint8_t *BigBuf_get_EM_addr(void) { // not yet allocated if (emulator_memory == NULL) emulator_memory = BigBuf_malloc(CARD_MEMORY_SIZE); @@ -50,33 +48,28 @@ uint8_t *BigBuf_get_EM_addr(void) } // clear ALL of BigBuf -void BigBuf_Clear(void) -{ +void BigBuf_Clear(void) { BigBuf_Clear_ext(true); } // clear ALL of BigBuf -void BigBuf_Clear_ext(bool verbose) -{ +void BigBuf_Clear_ext(bool verbose) { memset(BigBuf, 0, BIGBUF_SIZE); if (verbose) Dbprintf("Buffer cleared (%i bytes)", BIGBUF_SIZE); } -void BigBuf_Clear_EM(void) -{ +void BigBuf_Clear_EM(void) { memset(BigBuf_get_EM_addr(), 0, CARD_MEMORY_SIZE); } -void BigBuf_Clear_keep_EM(void) -{ +void BigBuf_Clear_keep_EM(void) { memset(BigBuf, 0, BigBuf_hi); } // allocate a chunk of memory from BigBuf. We allocate high memory first. The unallocated memory // at the beginning of BigBuf is always for traces/samples -uint8_t *BigBuf_malloc(uint16_t chunksize) -{ +uint8_t *BigBuf_malloc(uint16_t chunksize) { if (BigBuf_hi - chunksize < 0) return NULL; // no memory left @@ -86,16 +79,14 @@ uint8_t *BigBuf_malloc(uint16_t chunksize) } // free ALL allocated chunks. The whole BigBuf is available for traces or samples again. -void BigBuf_free(void) -{ +void BigBuf_free(void) { BigBuf_hi = BIGBUF_SIZE; emulator_memory = NULL; // shouldn't this empty BigBuf also? } // free allocated chunks EXCEPT the emulator memory -void BigBuf_free_keep_EM(void) -{ +void BigBuf_free_keep_EM(void) { if (emulator_memory != NULL) BigBuf_hi = emulator_memory - (uint8_t *)BigBuf; else @@ -104,8 +95,7 @@ void BigBuf_free_keep_EM(void) // shouldn't this empty BigBuf also? } -void BigBuf_print_status(void) -{ +void BigBuf_print_status(void) { Dbprintf("Memory"); Dbprintf(" BIGBUF_SIZE.............%d", BIGBUF_SIZE); Dbprintf(" Available memory........%d", BigBuf_hi); @@ -115,26 +105,21 @@ void BigBuf_print_status(void) } // return the maximum trace length (i.e. the unallocated size of BigBuf) -uint16_t BigBuf_max_traceLen(void) -{ +uint16_t BigBuf_max_traceLen(void) { return BigBuf_hi; } -void clear_trace(void) -{ +void clear_trace(void) { traceLen = 0; } -void set_tracelen(uint32_t value) -{ +void set_tracelen(uint32_t value) { traceLen = value; } -void set_tracing(bool enable) -{ +void set_tracing(bool enable) { tracing = enable; } -bool get_tracing(void) -{ +bool get_tracing(void) { return tracing; } @@ -142,8 +127,7 @@ bool get_tracing(void) * Get the number of bytes traced * @return */ -uint32_t BigBuf_get_traceLen(void) -{ +uint32_t BigBuf_get_traceLen(void) { return traceLen; } @@ -153,8 +137,7 @@ uint32_t BigBuf_get_traceLen(void) by 'hf list raw', alternatively 'hf list ' 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 readerToTag) -{ +bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag) { if (!tracing) return false; uint8_t *trace = BigBuf_get_addr(); @@ -212,8 +195,7 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_ return true; } -int LogTraceHitag(const uint8_t *btBytes, int iBits, int iSamples, uint32_t dwParity, int readerToTag) -{ +int LogTraceHitag(const uint8_t *btBytes, int iBits, int iSamples, uint32_t dwParity, int readerToTag) { /** Todo, rewrite the logger to use the generic functionality instead. It should be noted, however, that this logger takes number of bits as argument, not number of bytes. @@ -255,8 +237,7 @@ int LogTraceHitag(const uint8_t *btBytes, int iBits, int iSamples, uint32_t dwPa } // Emulator memory -uint8_t emlSet(uint8_t *data, uint32_t offset, uint32_t length) -{ +uint8_t emlSet(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/LCD.c b/armsrc/LCD.c index 05c09964b..32a917928 100644 --- a/armsrc/LCD.c +++ b/armsrc/LCD.c @@ -7,8 +7,7 @@ //----------------------------------------------------------------------------- #include "LCD.h" -void LCDSend(unsigned int data) -{ +void LCDSend(unsigned int data) { // 9th bit set for data, clear for command while ((AT91C_BASE_SPI->SPI_SR & AT91C_SPI_TXEMPTY) == 0); // wait for the transfer to complete // For clarity's sake we pass data with 9th bit clear and commands with 9th @@ -16,8 +15,7 @@ void LCDSend(unsigned int data) AT91C_BASE_SPI->SPI_TDR = data ^ 0x100; // Send the data/command } -void LCDSetXY(unsigned char x, unsigned char y) -{ +void LCDSetXY(unsigned char x, unsigned char y) { LCDSend(PPASET); // page start/end ram LCDSend(y); // Start Page to display to LCDSend(131); // End Page to display to @@ -27,15 +25,13 @@ void LCDSetXY(unsigned char x, unsigned char y) LCDSend(131); // End Column to display to } -void LCDSetPixel(unsigned char x, unsigned char y, unsigned char color) -{ +void LCDSetPixel(unsigned char x, unsigned char y, unsigned char color) { LCDSetXY(x, y); // Set position LCDSend(PRAMWR); // Now write the pixel to the display LCDSend(color); // Write the data in the specified Color } -void LCDFill(unsigned char xs, unsigned char ys, unsigned char width, unsigned char height, unsigned char color) -{ +void LCDFill(unsigned char xs, unsigned char ys, unsigned char width, unsigned char height, unsigned char color) { unsigned char i, j; for (i = 0; i < height; i++) { // Number of horizontal lines @@ -47,8 +43,7 @@ void LCDFill(unsigned char xs, unsigned char ys, unsigned char width, unsigned c } } -void LCDString(char *lcd_string, const char *font_style, unsigned char x, unsigned char y, unsigned char fcolor, unsigned char bcolor) -{ +void LCDString(char *lcd_string, const char *font_style, unsigned char x, unsigned char y, unsigned char fcolor, unsigned char bcolor) { unsigned int i; unsigned char mask = 0, px, py, xme, yme, offset; const char *data; @@ -85,8 +80,7 @@ void LCDString(char *lcd_string, const char *font_style, unsigned char x, unsign } while (*lcd_string != '\0'); // keep spitting chars out until end of string } -void LCDReset(void) -{ +void LCDReset(void) { LED_A_ON(); SetupSpi(SPI_LCD_MODE); LOW(GPIO_LRST); @@ -97,8 +91,7 @@ void LCDReset(void) LED_A_OFF(); } -void LCDInit(void) -{ +void LCDInit(void) { int i; LCDReset(); diff --git a/armsrc/Standalone/hf_bog.c b/armsrc/Standalone/hf_bog.c index a1197bdbe..40f3abba9 100644 --- a/armsrc/Standalone/hf_bog.c +++ b/armsrc/Standalone/hf_bog.c @@ -27,8 +27,7 @@ from the client to view the stored quadlets. // Maximum number of auth attempts per standalone session #define MAX_PWDS_PER_SESSION 64 -uint8_t FindOffsetInFlash() -{ +uint8_t FindOffsetInFlash() { uint8_t mem[4] = { 0x00, 0x00, 0x00, 0x00 }; uint8_t eom[4] = { 0xFF, 0xFF, 0xFF, 0xFF }; uint8_t memcnt = 0; @@ -44,8 +43,7 @@ uint8_t FindOffsetInFlash() return 0; // wrap-around } -void EraseMemory() -{ +void EraseMemory() { if (!FlashInit()) { return; } @@ -60,8 +58,7 @@ void EraseMemory() } // This is actually copied from SniffIso14443a -void RAMFUNC SniffAndStore(uint8_t param) -{ +void RAMFUNC SniffAndStore(uint8_t param) { iso14443a_setup(FPGA_HF_ISO14443A_SNIFFER); @@ -284,8 +281,7 @@ void RAMFUNC SniffAndStore(uint8_t param) } } -void RunMod() -{ +void RunMod() { StandAloneMode(); diff --git a/armsrc/Standalone/hf_colin.c b/armsrc/Standalone/hf_colin.c index 335269c71..97ee329de 100644 --- a/armsrc/Standalone/hf_colin.c +++ b/armsrc/Standalone/hf_colin.c @@ -59,36 +59,31 @@ void cjPrintBigArray(const char *bigar, int len, uint8_t newlines, uint8_t debug } */ -void cjSetCursFRight() -{ +void cjSetCursFRight() { vtsend_cursor_position(NULL, 98, (currfline)); currfline++; } -void cjSetCursRight() -{ +void cjSetCursRight() { vtsend_cursor_position(NULL, 59, (currline)); currline++; } -void cjSetCursLeft() -{ +void cjSetCursLeft() { vtsend_cursor_position(NULL, 0, (curlline)); curlline++; } void cjTabulize() { DbprintfEx(FLAG_RAWPRINT, "\t\t\t"); } -void cjPrintKey(uint64_t key, uint8_t *foundKey, uint16_t sectorNo, uint8_t type) -{ +void cjPrintKey(uint64_t key, uint8_t *foundKey, uint16_t sectorNo, uint8_t type) { char tosendkey[13]; sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[0], foundKey[1], foundKey[2], foundKey[3], foundKey[4], foundKey[5]); cjSetCursRight(); DbprintfEx(FLAG_NOLOG, "SEC: %02x | KEY : %s | TYP: %d", sectorNo, tosendkey, type); } -void ReadLastTagFromFlash() -{ +void ReadLastTagFromFlash() { SpinOff(0); LED_A_ON(); LED_B_ON(); @@ -135,8 +130,7 @@ void ReadLastTagFromFlash() return; } -void WriteTagToFlash(uint8_t index, size_t size) -{ +void WriteTagToFlash(uint8_t index, size_t size) { SpinOff(0); LED_A_ON(); LED_B_ON(); @@ -202,8 +196,7 @@ void WriteTagToFlash(uint8_t index, size_t size) return; } -void RunMod() -{ +void RunMod() { StandAloneMode(); FpgaDownloadAndGo(FPGA_BITSTREAM_HF); @@ -803,8 +796,7 @@ readysim: * - *datain used as error return * - tracing is falsed */ -void e_MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) -{ +void e_MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) { MF_DBGLEVEL = MF_DBG_NONE; uint8_t numSectors = arg0; @@ -888,8 +880,7 @@ void e_MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *dat /* the chk function is a piwi’ed(tm) check that will try all keys for a particular sector. also no tracing no dbg */ -int cjat91_saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, uint8_t keyCount, uint8_t *datain, uint64_t *key) -{ +int cjat91_saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, uint8_t keyCount, uint8_t *datain, uint64_t *key) { MF_DBGLEVEL = MF_DBG_NONE; iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); set_tracing(false); @@ -927,8 +918,7 @@ int cjat91_saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, ui return -1; } -void saMifareMakeTag(void) -{ +void saMifareMakeTag(void) { uint8_t cfail = 0; cjSetCursLeft(); cjTabulize(); @@ -999,8 +989,7 @@ void saMifareMakeTag(void) // Matt's StandAlone mod. // Work with "magic Chinese" card (email him: ouyangweidaxian@live.cn) //----------------------------------------------------------------------------- -int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) -{ +int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) { // params uint8_t needWipe = arg0; // bit 0 - need get UID diff --git a/armsrc/Standalone/hf_mattyrun.c b/armsrc/Standalone/hf_mattyrun.c index a6caecef5..bf4b71d61 100644 --- a/armsrc/Standalone/hf_mattyrun.c +++ b/armsrc/Standalone/hf_mattyrun.c @@ -42,8 +42,7 @@ uint32_t cuid; // Matt's StandAlone mod. // Work with "magic Chinese" card (email him: ouyangweidaxian@live.cn) //----------------------------------------------------------------------------- -static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) -{ +static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) { // params uint8_t needWipe = arg0; // bit 0 - need get UID @@ -155,8 +154,7 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_ /* the chk function is a piwi’ed(tm) check that will try all keys for a particular sector. also no tracing no dbg */ -static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, uint8_t keyCount, uint8_t *datain, uint64_t *key) -{ +static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, uint8_t keyCount, uint8_t *datain, uint64_t *key) { MF_DBGLEVEL = MF_DBG_NONE; iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); set_tracing(false); @@ -194,8 +192,7 @@ static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, ui } -void RunMod() -{ +void RunMod() { StandAloneMode(); Dbprintf(">> Matty mifare chk/dump/sim a.k.a MattyRun Started <<"); FpgaDownloadAndGo(FPGA_BITSTREAM_HF); diff --git a/armsrc/Standalone/hf_young.c b/armsrc/Standalone/hf_young.c index d5dfd69bd..99af4ef1e 100644 --- a/armsrc/Standalone/hf_young.c +++ b/armsrc/Standalone/hf_young.c @@ -18,8 +18,7 @@ typedef struct { } __attribute__((__packed__)) card_clone_t; -void RunMod() -{ +void RunMod() { StandAloneMode(); Dbprintf(">> Craig Young Mifare sniff UID/clone uid 2 magic/sim a.k.a YoungRun Started <<"); FpgaDownloadAndGo(FPGA_BITSTREAM_HF); diff --git a/armsrc/Standalone/lf_hidbrute.c b/armsrc/Standalone/lf_hidbrute.c index ce5b7d337..aaeae9a9a 100644 --- a/armsrc/Standalone/lf_hidbrute.c +++ b/armsrc/Standalone/lf_hidbrute.c @@ -27,8 +27,7 @@ #include "lf_hidbrute.h" // samy's sniff and repeat routine for LF -void RunMod() -{ +void RunMod() { StandAloneMode(); Dbprintf(">> LF HID corporate bruteforce a.k.a CorporateBrute Started <<"); FpgaDownloadAndGo(FPGA_BITSTREAM_LF); @@ -245,8 +244,7 @@ out: } // Function that calculate next value for the brutforce of HID corporate 1000 -void hid_corporate_1000_calculate_checksum_and_set(uint32_t *high, uint32_t *low, uint32_t cardnum, uint32_t fc) -{ +void hid_corporate_1000_calculate_checksum_and_set(uint32_t *high, uint32_t *low, uint32_t cardnum, uint32_t fc) { uint32_t new_high = 0; uint32_t new_low = 0; diff --git a/armsrc/Standalone/lf_proxbrute.c b/armsrc/Standalone/lf_proxbrute.c index baa7fe72a..ea1bd1f6f 100644 --- a/armsrc/Standalone/lf_proxbrute.c +++ b/armsrc/Standalone/lf_proxbrute.c @@ -12,8 +12,7 @@ #include "lf_proxbrute.h" // samy's sniff and repeat routine for LF -void RunMod() -{ +void RunMod() { StandAloneMode(); Dbprintf(">> LF HID proxII bruteforce a.k.a ProxBrute Started (Brad Antoniewicz) <<"); FpgaDownloadAndGo(FPGA_BITSTREAM_LF); diff --git a/armsrc/Standalone/lf_samyrun.c b/armsrc/Standalone/lf_samyrun.c index 4f4545374..ec0e4d19e 100644 --- a/armsrc/Standalone/lf_samyrun.c +++ b/armsrc/Standalone/lf_samyrun.c @@ -11,8 +11,7 @@ #include "lf_samyrun.h" // samy's sniff and repeat routine for LF -void RunMod() -{ +void RunMod() { StandAloneMode(); Dbprintf(">> LF HID Read/Clone/Sim a.k.a SamyRun Started <<"); FpgaDownloadAndGo(FPGA_BITSTREAM_LF); diff --git a/armsrc/aes.c b/armsrc/aes.c index fd6543745..61a8da76b 100644 --- a/armsrc/aes.c +++ b/armsrc/aes.c @@ -680,8 +680,7 @@ static const unsigned int rcon[] = { * Expand the cipher key into the encryption key schedule and return the * number of rounds for the given cipher key size. */ -int aes_setkey_enc(unsigned int rk[], const unsigned char cipherKey[], int keyBytes) -{ +int aes_setkey_enc(unsigned int rk[], const unsigned char cipherKey[], int keyBytes) { int i = 0; unsigned int temp; @@ -766,8 +765,7 @@ int aes_setkey_enc(unsigned int rk[], const unsigned char cipherKey[], int keyBy * Expand the cipher key into encryption and decryption key schedule and * return the number of rounds for the given cipher key size. */ -int AesGenKeySched(unsigned int rk[], unsigned int rrk[], const unsigned char cipherKey[], int keyBytes) -{ +int AesGenKeySched(unsigned int rk[], unsigned int rrk[], const unsigned char cipherKey[], int keyBytes) { int Nr, i; // expand the cipher key @@ -821,8 +819,7 @@ int AesGenKeySched(unsigned int rk[], unsigned int rrk[], const unsigned char ci /* * Encrypt the plain text into cipher */ -void AesEncBlk(AesCtx *pCtx, const unsigned char pt[], unsigned char ct[]) -{ +void AesEncBlk(AesCtx *pCtx, const unsigned char pt[], unsigned char ct[]) { unsigned int s0, s1, s2, s3, t0, t1, t2, t3, *iv; const unsigned int *rk; int r; @@ -947,8 +944,7 @@ void AesEncBlk(AesCtx *pCtx, const unsigned char pt[], unsigned char ct[]) /* * Decrypt the cipher into plain text */ -void AesDecBlk(AesCtx *pCtx, const unsigned char ct[], unsigned char pt[]) -{ +void AesDecBlk(AesCtx *pCtx, const unsigned char ct[], unsigned char pt[]) { unsigned int s0, s1, s2, s3, t0, t1, t2, t3, v0, v1, v2, v3, *iv; const unsigned int *rk; int r; @@ -1080,8 +1076,7 @@ void AesDecBlk(AesCtx *pCtx, const unsigned char ct[], unsigned char pt[]) /* * initialize AES context */ -int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned int KeyLen, unsigned char Mode) -{ +int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned int KeyLen, unsigned char Mode) { if (pKey == 0 || pCtx == 0 || (KeyLen != KEY128 && KeyLen != KEY192 && KeyLen != KEY256)) return -1; @@ -1105,8 +1100,7 @@ int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned in /* * Encrypt plain text */ -int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsigned int DataLen) -{ +int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsigned int DataLen) { int i; if (pData == 0 || pCipher == 0 || pCtx == 0 || (DataLen & 0xf) != 0) @@ -1124,8 +1118,7 @@ int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsig /* * Decrypt cipher */ -int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen) -{ +int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen) { int i; if (pData == 0 || pCipher == 0 || pCtx == 0 || (CipherLen & 0xf) != 0) @@ -1148,8 +1141,7 @@ int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsig #include -int main() -{ +int main() { AesCtx ctx; unsigned char iv[] = "INI VECTINI VECT"; unsigned char key[] = "This is a sample AESKey"; diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 1982c57a7..dbe20b2b7 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -54,14 +54,12 @@ int ToSendMax = -1; static int ToSendBit; struct common_area common_area __attribute__((section(".commonarea"))); -void ToSendReset(void) -{ +void ToSendReset(void) { ToSendMax = -1; ToSendBit = 8; } -void ToSendStuffBit(int b) -{ +void ToSendStuffBit(int b) { if (ToSendBit >= 8) { ToSendMax++; ToSend[ToSendMax] = 0; @@ -79,14 +77,12 @@ void ToSendStuffBit(int b) } } -void PrintToSendBuffer(void) -{ +void PrintToSendBuffer(void) { DbpString("Printing ToSendBuffer:"); Dbhexdump(ToSendMax, ToSend, 0); } -void print_result(char *name, uint8_t *buf, size_t len) -{ +void print_result(char *name, uint8_t *buf, size_t len) { uint8_t *p = buf; uint16_t tmp = len & 0xFFF0; @@ -114,29 +110,25 @@ void print_result(char *name, uint8_t *buf, size_t len) // Debug print functions, to go out over USB, to the usual PC-side client. //============================================================================= -void DbpStringEx(char *str, uint32_t cmd) -{ +void DbpStringEx(char *str, uint32_t cmd) { #if DEBUG uint8_t len = strlen(str); cmd_send(CMD_DEBUG_PRINT_STRING, len, cmd, 0, (uint8_t *)str, len); #endif } -void DbpString(char *str) -{ +void DbpString(char *str) { #if DEBUG DbpStringEx(str, 0); #endif } #if 0 -void DbpIntegers(int x1, int x2, int x3) -{ +void DbpIntegers(int x1, int x2, int x3) { cmd_send(CMD_DEBUG_PRINT_INTEGERS, x1, x2, x3, 0, 0); } #endif -void DbprintfEx(uint32_t cmd, const char *fmt, ...) -{ +void DbprintfEx(uint32_t cmd, const char *fmt, ...) { #if DEBUG // should probably limit size here; oh well, let's just use a big buffer char output_string[128] = {0x00}; @@ -149,8 +141,7 @@ void DbprintfEx(uint32_t cmd, const char *fmt, ...) #endif } -void Dbprintf(const char *fmt, ...) -{ +void Dbprintf(const char *fmt, ...) { #if DEBUG // should probably limit size here; oh well, let's just use a big buffer char output_string[128] = {0x00}; @@ -165,8 +156,7 @@ void Dbprintf(const char *fmt, ...) } // prints HEX & ASCII -void Dbhexdump(int len, uint8_t *d, bool bAsci) -{ +void Dbhexdump(int len, uint8_t *d, bool bAsci) { #if DEBUG int l = 0, i; char ascii[9]; @@ -201,8 +191,7 @@ void Dbhexdump(int len, uint8_t *d, bool bAsci) // in ADC units (0 to 1023). Also a routine to average 32 samples and // return that. //----------------------------------------------------------------------------- -static uint16_t ReadAdc(int ch) -{ +static uint16_t ReadAdc(int ch) { // Note: ADC_MODE_PRESCALE and ADC_MODE_SAMPLE_HOLD_TIME are set to the maximum allowed value. // AMPL_HI is are high impedance (10MOhm || 1MOhm) output, the input capacitance of the ADC is 12pF (typical). This results in a time constant @@ -228,8 +217,7 @@ static uint16_t ReadAdc(int ch) } // was static - merlok -uint16_t AvgAdc(int ch) -{ +uint16_t AvgAdc(int ch) { uint16_t a = 0; for (uint8_t i = 0; i < 32; i++) a += ReadAdc(ch); @@ -238,8 +226,7 @@ uint16_t AvgAdc(int ch) return (a + 15) >> 5; } -void MeasureAntennaTuning(void) -{ +void MeasureAntennaTuning(void) { uint8_t LF_Results[256]; uint32_t i, adcval = 0, peak = 0, peakv = 0, peakf = 0; @@ -304,8 +291,7 @@ void MeasureAntennaTuning(void) LEDsoff(); } -void MeasureAntennaTuningHf(void) -{ +void MeasureAntennaTuningHf(void) { uint16_t volt = 0; // in mV // Let the FPGA drive the high-frequency antenna around 13.56 MHz. FpgaDownloadAndGo(FPGA_BITSTREAM_HF); @@ -327,8 +313,7 @@ void MeasureAntennaTuningHf(void) DbprintfEx(FLAG_NOOPT, "\n[+] cancelled", 1); } -void ReadMem(int addr) -{ +void ReadMem(int addr) { const uint8_t *data = ((uint8_t *)addr); Dbprintf("%x: %02x %02x %02x %02x %02x %02x %02x %02x", addr, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]); @@ -338,8 +323,7 @@ void ReadMem(int addr) extern struct version_information version_information; /* bootrom version information is pointed to from _bootphase1_version_pointer */ extern char *_bootphase1_version_pointer, _flash_start, _flash_end, _bootrom_start, _bootrom_end, __data_src_start__; -void SendVersion(void) -{ +void SendVersion(void) { char temp[USB_CMD_DATA_SIZE]; /* Limited data payload in USB packets */ char VersionString[USB_CMD_DATA_SIZE] = { '\0' }; @@ -377,8 +361,7 @@ void SendVersion(void) // measure the USB Speed by sending SpeedTestBufferSize bytes to client and measuring the elapsed time. // Note: this mimics GetFromBigbuf(), i.e. we have the overhead of the UsbCommand structure included. -void printUSBSpeed(void) -{ +void printUSBSpeed(void) { Dbprintf("USB Speed"); Dbprintf(" Sending USB packets to client..."); @@ -405,8 +388,7 @@ void printUSBSpeed(void) /** * Prints runtime information about the PM3. **/ -void SendStatus(void) -{ +void SendStatus(void) { BigBuf_print_status(); Fpga_print_status(); #ifdef WITH_FLASH @@ -430,8 +412,7 @@ void SendStatus(void) } // Show some leds in a pattern to identify StandAlone mod is running -void StandAloneMode(void) -{ +void StandAloneMode(void) { DbpString("Stand-alone mode! No PC necessary."); @@ -444,8 +425,7 @@ void StandAloneMode(void) } // detection of which Standalone Modes is installed // (iceman) -void printStandAloneModes(void) -{ +void printStandAloneModes(void) { DbpString("Installed StandAlone Mode"); @@ -523,8 +503,7 @@ static const char LIGHT_SCHEME[] = { }; static const int LIGHT_LEN = sizeof(LIGHT_SCHEME) / sizeof(LIGHT_SCHEME[0]); -void ListenReaderField(int limit) -{ +void ListenReaderField(int limit) { #define LF_ONLY 1 #define HF_ONLY 2 #define REPORT_CHANGE 10 // report new values only if they have changed at least by REPORT_CHANGE @@ -650,8 +629,7 @@ void ListenReaderField(int limit) } } -void UsbPacketReceived(uint8_t *packet, int len) -{ +void UsbPacketReceived(uint8_t *packet, int len) { UsbCommand *c = (UsbCommand *)packet; //Dbprintf("received %d bytes, with command: 0x%04x and args: %d %d %d", len, c->cmd, c->arg[0], c->arg[1], c->arg[2]); @@ -1509,8 +1487,7 @@ void UsbPacketReceived(uint8_t *packet, int len) } } -void __attribute__((noreturn)) AppMain(void) -{ +void __attribute__((noreturn)) AppMain(void) { SpinDelay(100); clear_trace(); diff --git a/armsrc/buzzer.c b/armsrc/buzzer.c index a06b1adbb..27d0cd12a 100644 --- a/armsrc/buzzer.c +++ b/armsrc/buzzer.c @@ -1,27 +1,23 @@ #include "buzzer.h" -void Ring_BEE_ONCE(uint16_t music_note) -{ +void Ring_BEE_ONCE(uint16_t music_note) { BEE_ON(); SpinDelayUs(music_note); BEE_OFF(); SpinDelayUs(music_note); } -void ring_2_7khz(uint16_t count) -{ +void ring_2_7khz(uint16_t count) { Ring_BEE_TIME(n_2_7khz, count); } -void Ring_BEE_TIME(uint16_t music_note, uint16_t count) -{ +void Ring_BEE_TIME(uint16_t music_note, uint16_t count) { for (uint16_t i = 0 ; i < count; i++) Ring_BEE_ONCE(music_note); SpinDelay(9); } -void Ring_ALL(uint16_t count) -{ +void Ring_ALL(uint16_t count) { Ring_BEE_TIME(note_1, count); Ring_BEE_TIME(note_2, count); Ring_BEE_TIME(note_3, count); @@ -32,8 +28,7 @@ void Ring_ALL(uint16_t count) SpinDelay(10); } -void Ring_Little_Star(uint16_t count) -{ +void Ring_Little_Star(uint16_t count) { Ring_BEE_TIME(note_1, count); Ring_BEE_TIME(note_1, count); Ring_BEE_TIME(note_5, count); diff --git a/armsrc/des.c b/armsrc/des.c index 2e9cfaef1..6229ac8f6 100644 --- a/armsrc/des.c +++ b/armsrc/des.c @@ -202,8 +202,7 @@ const uint8_t shiftkeyinv_permtab[] = { #define ROTTABLE_INV 0x3F7E /******************************************************************************/ -void permute(const uint8_t *ptable, const uint8_t *in, uint8_t *out) -{ +void permute(const uint8_t *ptable, const uint8_t *in, uint8_t *out) { uint8_t ob; /* in-bytes and out-bytes */ uint8_t byte, bit; /* counter for bit and byte */ ob = ptable[1]; @@ -223,8 +222,7 @@ void permute(const uint8_t *ptable, const uint8_t *in, uint8_t *out) /******************************************************************************/ -void changeendian32(uint32_t *a) -{ +void changeendian32(uint32_t *a) { *a = (*a & 0x000000FF) << 24 | (*a & 0x0000FF00) << 8 | (*a & 0x00FF0000) >> 8 | @@ -233,8 +231,7 @@ void changeendian32(uint32_t *a) /******************************************************************************/ static inline -void shiftkey(uint8_t *key) -{ +void shiftkey(uint8_t *key) { uint8_t k[7]; memcpy(k, key, 7); permute((uint8_t *)shiftkey_permtab, k, key); @@ -242,8 +239,7 @@ void shiftkey(uint8_t *key) /******************************************************************************/ static inline -void shiftkey_inv(uint8_t *key) -{ +void shiftkey_inv(uint8_t *key) { uint8_t k[7]; memcpy(k, key, 7); permute((uint8_t *)shiftkeyinv_permtab, k, key); @@ -252,8 +248,7 @@ void shiftkey_inv(uint8_t *key) /******************************************************************************/ static inline -uint64_t splitin6bitwords(uint64_t a) -{ +uint64_t splitin6bitwords(uint64_t a) { uint64_t ret = 0; a &= 0x0000ffffffffffffLL; permute((uint8_t *)splitin6bitword_permtab, (uint8_t *)&a, (uint8_t *)&ret); @@ -263,8 +258,7 @@ uint64_t splitin6bitwords(uint64_t a) /******************************************************************************/ static inline -uint8_t substitute(uint8_t a, uint8_t *sbp) -{ +uint8_t substitute(uint8_t a, uint8_t *sbp) { uint8_t x; x = sbp[a >> 1]; x = (a & 1) ? x & 0x0F : x >> 4; @@ -274,8 +268,7 @@ uint8_t substitute(uint8_t a, uint8_t *sbp) /******************************************************************************/ -uint32_t des_f(uint32_t r, uint8_t *kr) -{ +uint32_t des_f(uint32_t r, uint8_t *kr) { uint8_t i; uint32_t t = 0, ret; uint64_t data; @@ -312,8 +305,7 @@ typedef struct { #define R (data.d.v32[1]) #define L (data.d.v32[0]) -void des_enc(void *out, const void *in, const void *key) -{ +void des_enc(void *out, const void *in, const void *key) { uint8_t kr[6], k[7]; uint8_t i; @@ -346,8 +338,7 @@ void des_enc(void *out, const void *in, const void *key) /******************************************************************************/ -void des_dec(void *out, const void *in, const uint8_t *key) -{ +void des_dec(void *out, const void *in, const uint8_t *key) { uint8_t kr[6], k[7]; int8_t i; @@ -382,8 +373,7 @@ void des_dec(void *out, const void *in, const uint8_t *key) /******************************************************************************/ -void tdes_enc(void *out, void *in, const void *key) -{ +void tdes_enc(void *out, void *in, const void *key) { des_enc(out, in, (uint8_t *)key + 0); des_dec(out, out, (uint8_t *)key + 8); des_enc(out, out, (uint8_t *)key + 16); @@ -391,15 +381,13 @@ void tdes_enc(void *out, void *in, const void *key) /******************************************************************************/ -void tdes_dec(void *out, void *in, const uint8_t *key) -{ +void tdes_dec(void *out, void *in, const uint8_t *key) { des_dec(out, in, (uint8_t *)key + 16); des_enc(out, out, (uint8_t *)key + 8); des_dec(out, out, (uint8_t *)key + 0); } -void tdes_2key_enc(void *out, const void *in, size_t length, const void *key, unsigned char iv[8]) -{ +void tdes_2key_enc(void *out, const void *in, size_t length, const void *key, unsigned char iv[8]) { if (length % 8) return; @@ -423,8 +411,7 @@ void tdes_2key_enc(void *out, const void *in, size_t length, const void *key, un } } -void tdes_2key_dec(void *out, const void *in, size_t length, const void *key, unsigned char iv[8]) -{ +void tdes_2key_dec(void *out, const void *in, size_t length, const void *key, unsigned char iv[8]) { if (length % 8) return; diff --git a/armsrc/desfire_crypto.c b/armsrc/desfire_crypto.c index 55dde9c4c..0a23305fd 100644 --- a/armsrc/desfire_crypto.c +++ b/armsrc/desfire_crypto.c @@ -31,15 +31,13 @@ static void xor(const uint8_t *ivect, uint8_t *data, const size_t len); static size_t key_macing_length(desfirekey_t key); // iceman, see memxor inside string.c, dest/src swapped.. -static void xor(const uint8_t *ivect, uint8_t *data, const size_t len) -{ +static void xor(const uint8_t *ivect, uint8_t *data, const size_t len) { for (size_t i = 0; i < len; i++) { data[i] ^= ivect[i]; } } -void cmac_generate_subkeys(desfirekey_t key) -{ +void cmac_generate_subkeys(desfirekey_t key) { int kbs = key_block_size(key); const uint8_t R = (kbs == 8) ? 0x1B : 0x87; @@ -68,8 +66,7 @@ void cmac_generate_subkeys(desfirekey_t key) key->cmac_sk2[kbs - 1] ^= R; } -void cmac(const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac) -{ +void cmac(const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac) { int kbs = key_block_size(key); uint8_t *buffer = malloc(padded_data_length(len, kbs)); @@ -91,8 +88,7 @@ void cmac(const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t le free(buffer); } -size_t key_block_size(const desfirekey_t key) -{ +size_t key_block_size(const desfirekey_t key) { size_t block_size = 8; switch (key->type) { case T_DES: @@ -110,8 +106,7 @@ size_t key_block_size(const desfirekey_t key) /* * Size of MACing produced with the key. */ -static size_t key_macing_length(const desfirekey_t key) -{ +static size_t key_macing_length(const desfirekey_t key) { size_t mac_length = MAC_LENGTH; switch (key->type) { case T_DES: @@ -129,8 +124,7 @@ static size_t key_macing_length(const desfirekey_t key) /* * Size required to store nbytes of data in a buffer of size n*block_size. */ -size_t padded_data_length(const size_t nbytes, const size_t block_size) -{ +size_t padded_data_length(const size_t nbytes, const size_t block_size) { if ((!nbytes) || (nbytes % block_size)) return ((nbytes / block_size) + 1) * block_size; else @@ -140,15 +134,13 @@ size_t padded_data_length(const size_t nbytes, const size_t block_size) /* * Buffer size required to MAC nbytes of data */ -size_t maced_data_length(const desfirekey_t key, const size_t nbytes) -{ +size_t maced_data_length(const desfirekey_t key, const size_t nbytes) { return nbytes + key_macing_length(key); } /* * Buffer size required to encipher nbytes of data and a two bytes CRC. */ -size_t enciphered_data_length(const desfiretag_t tag, const size_t nbytes, int communication_settings) -{ +size_t enciphered_data_length(const desfiretag_t tag, const size_t nbytes, int communication_settings) { size_t crc_length = 0; if (!(communication_settings & NO_CRC)) { switch (DESFIRE(tag)->authentication_scheme) { @@ -166,8 +158,7 @@ size_t enciphered_data_length(const desfiretag_t tag, const size_t nbytes, int c return padded_data_length(nbytes + crc_length, block_size); } -void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes, size_t offset, int communication_settings) -{ +void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes, size_t offset, int communication_settings) { uint8_t *res = data; uint8_t mac[4]; size_t edl; @@ -295,8 +286,7 @@ void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes, } -void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes, int communication_settings) -{ +void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes, int communication_settings) { void *res = data; size_t edl; void *edata = NULL; @@ -521,8 +511,7 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes } -void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size) -{ +void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size) { uint8_t ovect[MAX_CRYPTO_BLOCK_SIZE]; if (direction == MCD_SEND) { @@ -616,8 +605,7 @@ void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect, * Because the tag may contain additional data, one may need to call this * function with tag, key and ivect defined. */ -void mifare_cypher_blocks_chained(desfiretag_t tag, desfirekey_t key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation) -{ +void mifare_cypher_blocks_chained(desfiretag_t tag, desfirekey_t key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation) { size_t block_size; if (tag) { diff --git a/armsrc/desfire_key.c b/armsrc/desfire_key.c index 1123225bb..a723a203e 100644 --- a/armsrc/desfire_key.c +++ b/armsrc/desfire_key.c @@ -21,8 +21,7 @@ static inline void update_key_schedules(desfirekey_t key); -static inline void update_key_schedules(desfirekey_t key) -{ +static inline void update_key_schedules(desfirekey_t key) { // DES_set_key ((DES_cblock *)key->data, &(key->ks1)); // DES_set_key ((DES_cblock *)(key->data + 8), &(key->ks2)); // if (T_3K3DES == key->type) { @@ -30,8 +29,7 @@ static inline void update_key_schedules(desfirekey_t key) // } } -void Desfire_des_key_new(const uint8_t value[8], desfirekey_t key) -{ +void Desfire_des_key_new(const uint8_t value[8], desfirekey_t key) { uint8_t data[8]; memcpy(data, value, 8); for (int n = 0; n < 8; n++) @@ -39,8 +37,7 @@ void Desfire_des_key_new(const uint8_t value[8], desfirekey_t key) Desfire_des_key_new_with_version(data, key); } -void Desfire_des_key_new_with_version(const uint8_t value[8], desfirekey_t key) -{ +void Desfire_des_key_new_with_version(const uint8_t value[8], desfirekey_t key) { if (key != NULL) { key->type = T_DES; memcpy(key->data, value, 8); @@ -49,8 +46,7 @@ void Desfire_des_key_new_with_version(const uint8_t value[8], desfirekey_t key) } } -void Desfire_3des_key_new(const uint8_t value[16], desfirekey_t key) -{ +void Desfire_3des_key_new(const uint8_t value[16], desfirekey_t key) { uint8_t data[16]; memcpy(data, value, 16); for (int n = 0; n < 8; n++) @@ -60,8 +56,7 @@ void Desfire_3des_key_new(const uint8_t value[16], desfirekey_t key) Desfire_3des_key_new_with_version(data, key); } -void Desfire_3des_key_new_with_version(const uint8_t value[16], desfirekey_t key) -{ +void Desfire_3des_key_new_with_version(const uint8_t value[16], desfirekey_t key) { if (key != NULL) { key->type = T_3DES; memcpy(key->data, value, 16); @@ -70,8 +65,7 @@ void Desfire_3des_key_new_with_version(const uint8_t value[16], desfirekey_t key } } -void Desfire_3k3des_key_new(const uint8_t value[24], desfirekey_t key) -{ +void Desfire_3k3des_key_new(const uint8_t value[24], desfirekey_t key) { uint8_t data[24]; memcpy(data, value, 24); for (int n = 0; n < 8; n++) @@ -79,8 +73,7 @@ void Desfire_3k3des_key_new(const uint8_t value[24], desfirekey_t key) Desfire_3k3des_key_new_with_version(data, key); } -void Desfire_3k3des_key_new_with_version(const uint8_t value[24], desfirekey_t key) -{ +void Desfire_3k3des_key_new_with_version(const uint8_t value[24], desfirekey_t key) { if (key != NULL) { key->type = T_3K3DES; memcpy(key->data, value, 24); @@ -88,13 +81,11 @@ void Desfire_3k3des_key_new_with_version(const uint8_t value[24], desfirekey_t k } } -void Desfire_aes_key_new(const uint8_t value[16], desfirekey_t key) -{ +void Desfire_aes_key_new(const uint8_t value[16], desfirekey_t key) { Desfire_aes_key_new_with_version(value, 0, key); } -void Desfire_aes_key_new_with_version(const uint8_t value[16], uint8_t version, desfirekey_t key) -{ +void Desfire_aes_key_new_with_version(const uint8_t value[16], uint8_t version, desfirekey_t key) { if (key != NULL) { memcpy(key->data, value, 16); @@ -103,8 +94,7 @@ void Desfire_aes_key_new_with_version(const uint8_t value[16], uint8_t version, } } -uint8_t Desfire_key_get_version(desfirekey_t key) -{ +uint8_t Desfire_key_get_version(desfirekey_t key) { uint8_t version = 0; for (int n = 0; n < 8; n++) { @@ -113,8 +103,7 @@ uint8_t Desfire_key_get_version(desfirekey_t key) return version; } -void Desfire_key_set_version(desfirekey_t key, uint8_t version) -{ +void Desfire_key_set_version(desfirekey_t key, uint8_t version) { for (int n = 0; n < 8; n++) { uint8_t version_bit = ((version & (1 << (7 - n))) >> (7 - n)); key->data[n] &= 0xfe; @@ -129,8 +118,7 @@ void Desfire_key_set_version(desfirekey_t key, uint8_t version) } } -void Desfire_session_key_new(const uint8_t rnda[], const uint8_t rndb[], desfirekey_t authkey, desfirekey_t key) -{ +void Desfire_session_key_new(const uint8_t rnda[], const uint8_t rndb[], desfirekey_t authkey, desfirekey_t key) { uint8_t buffer[24]; diff --git a/armsrc/epa.c b/armsrc/epa.c index 0f09980ee..95de11550 100644 --- a/armsrc/epa.c +++ b/armsrc/epa.c @@ -103,8 +103,7 @@ static char iso_type = 0; //----------------------------------------------------------------------------- // Wrapper for sending APDUs to type A and B cards //----------------------------------------------------------------------------- -int EPA_APDU(uint8_t *apdu, size_t length, uint8_t *response) -{ +int EPA_APDU(uint8_t *apdu, size_t length, uint8_t *response) { switch (iso_type) { case 'a': return iso14_apdu(apdu, (uint16_t) length, false, response, NULL); @@ -121,8 +120,7 @@ int EPA_APDU(uint8_t *apdu, size_t length, uint8_t *response) //----------------------------------------------------------------------------- // Closes the communication channel and turns off the field //----------------------------------------------------------------------------- -void EPA_Finish() -{ +void EPA_Finish() { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); LEDsoff(); iso_type = 0; @@ -143,8 +141,7 @@ void EPA_Finish() //----------------------------------------------------------------------------- size_t EPA_Parse_CardAccess(uint8_t *data, size_t length, - pace_version_info_t *pace_info) -{ + pace_version_info_t *pace_info) { size_t index = 0; while (index <= length - 2) { @@ -162,10 +159,10 @@ size_t EPA_Parse_CardAccess(uint8_t *data, else if (data[index] == 0x06) { // is this a PACE OID? if (data[index + 1] == 0x0A // length matches - && memcmp(data + index + 2, - oid_pace_start, - sizeof(oid_pace_start)) == 0 // content matches - && pace_info != NULL) { + && memcmp(data + index + 2, + oid_pace_start, + sizeof(oid_pace_start)) == 0 // content matches + && pace_info != NULL) { // first, clear the pace_info struct memset(pace_info, 0, sizeof(pace_version_info_t)); memcpy(pace_info->oid, data + index + 2, sizeof(pace_info->oid)); @@ -210,8 +207,7 @@ size_t EPA_Parse_CardAccess(uint8_t *data, // 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) -{ +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) @@ -223,8 +219,8 @@ int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length) sizeof(apdu_select_binary_cardaccess), response_apdu); if (rapdu_length < 6 - || response_apdu[rapdu_length - 4] != 0x90 - || response_apdu[rapdu_length - 3] != 0x00) { + || response_apdu[rapdu_length - 4] != 0x90 + || response_apdu[rapdu_length - 3] != 0x00) { DbpString("Failed to select EF.CardAccess!"); return -1; } @@ -234,8 +230,8 @@ int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length) sizeof(apdu_read_binary), response_apdu); if (rapdu_length <= 6 - || response_apdu[rapdu_length - 4] != 0x90 - || response_apdu[rapdu_length - 3] != 0x00) { + || response_apdu[rapdu_length - 4] != 0x90 + || response_apdu[rapdu_length - 3] != 0x00) { Dbprintf("Failed to read EF.CardAccess!"); return -1; } @@ -252,8 +248,7 @@ int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length) // Abort helper function for EPA_PACE_Collect_Nonce // sets relevant data in ack, sends the response //----------------------------------------------------------------------------- -static void EPA_PACE_Collect_Nonce_Abort(uint8_t step, int func_return) -{ +static void EPA_PACE_Collect_Nonce_Abort(uint8_t step, int func_return) { // power down the field EPA_Finish(); @@ -264,8 +259,7 @@ static void EPA_PACE_Collect_Nonce_Abort(uint8_t step, int func_return) //----------------------------------------------------------------------------- // Acquire one encrypted PACE nonce //----------------------------------------------------------------------------- -void EPA_PACE_Collect_Nonce(UsbCommand *c) -{ +void EPA_PACE_Collect_Nonce(UsbCommand *c) { /* * ack layout: * arg: @@ -337,8 +331,7 @@ void EPA_PACE_Collect_Nonce(UsbCommand *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) -{ +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]; // copy the constant part @@ -355,8 +348,8 @@ int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce) response_apdu); // check if the command succeeded if (send_return < 6 - || response_apdu[send_return - 4] != 0x90 - || response_apdu[send_return - 3] != 0x00) { + || response_apdu[send_return - 4] != 0x90 + || response_apdu[send_return - 3] != 0x00) { return -1; } @@ -380,8 +373,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) -{ +int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password) { // create the MSE: Set AT APDU uint8_t apdu[23]; // the minimum length (will be increased as more data is added) @@ -423,8 +415,8 @@ int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password) response_apdu); // check if the command succeeded if (send_return != 6 - || response_apdu[send_return - 4] != 0x90 - || response_apdu[send_return - 3] != 0x00) { + || response_apdu[send_return - 4] != 0x90 + || response_apdu[send_return - 3] != 0x00) { return 1; } return 0; @@ -433,8 +425,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(UsbCommand *c) -{ +void EPA_PACE_Replay(UsbCommand *c) { uint32_t timings[sizeof(apdu_lengths_replay) / sizeof(apdu_lengths_replay[0])] = {0}; // if an APDU has been passed, save it @@ -482,9 +473,9 @@ void EPA_PACE_Replay(UsbCommand *c) timings[i] = GetCountUS(); // every step but the last one should succeed if (i < sizeof(apdu_lengths_replay) - 1 - && (func_return < 6 - || response_apdu[func_return - 4] != 0x90 - || response_apdu[func_return - 3] != 0x00)) { + && (func_return < 6 + || response_apdu[func_return - 4] != 0x90 + || response_apdu[func_return - 3] != 0x00)) { EPA_Finish(); cmd_send(CMD_ACK, 3 + i, func_return, 0, timings, 20); return; @@ -499,8 +490,7 @@ void EPA_PACE_Replay(UsbCommand *c) // Set up a communication channel (Card Select, PPS) // Returns 0 on success or a non-zero error code on failure //----------------------------------------------------------------------------- -int EPA_Setup() -{ +int EPA_Setup() { int return_code = 0; uint8_t uid[10]; uint8_t pps_response[3]; diff --git a/armsrc/felica.c b/armsrc/felica.c index 1d3ef781e..3aa3c282d 100644 --- a/armsrc/felica.c +++ b/armsrc/felica.c @@ -34,13 +34,11 @@ static uint8_t felica_select_card(felica_card_select_t *card); static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing, uint8_t power, uint8_t highspeed); bool WaitForFelicaReply(uint16_t maxbytes); -void iso18092_set_timeout(uint32_t timeout) -{ +void iso18092_set_timeout(uint32_t timeout) { felica_timeout = timeout + (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / (16 * 8) + 2; } -uint32_t iso18092_get_timeout(void) -{ +uint32_t iso18092_get_timeout(void) { return felica_timeout - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / (16 * 8) - 2; } @@ -79,22 +77,19 @@ static struct { # define SYNC_16BIT 0xB24D #endif -static void FelicaFrameReset() -{ +static void FelicaFrameReset() { FelicaFrame.state = STATE_UNSYNCD; FelicaFrame.posCnt = 0; FelicaFrame.crc_ok = false; FelicaFrame.byte_offset = 0; } -static void FelicaFrameinit(uint8_t *data) -{ +static void FelicaFrameinit(uint8_t *data) { FelicaFrame.framebytes = data; FelicaFrameReset(); } //shift byte into frame, reversing it at the same time -static void shiftInByte(uint8_t bt) -{ +static void shiftInByte(uint8_t bt) { uint8_t j; for (j = 0; j < FelicaFrame.byte_offset; j++) { FelicaFrame.framebytes[FelicaFrame.posCnt] = (FelicaFrame.framebytes[FelicaFrame.posCnt] << 1) + (bt & 1); @@ -108,8 +103,7 @@ static void shiftInByte(uint8_t bt) } } -static void Process18092Byte(uint8_t bt) -{ +static void Process18092Byte(uint8_t bt) { switch (FelicaFrame.state) { case STATE_UNSYNCD: { //almost any nonzero byte can be start of SYNC. SYNC should be preceded by zeros, but that is not alsways the case @@ -196,8 +190,7 @@ static void Process18092Byte(uint8_t bt) * Currently does NOT do any collision handling. * It expects 0-1 cards in the device's range. */ -static uint8_t felica_select_card(felica_card_select_t *card) -{ +static uint8_t felica_select_card(felica_card_select_t *card) { // POLL command // 0xB2 0x4B = sync code @@ -271,8 +264,7 @@ static uint8_t felica_select_card(felica_card_select_t *card) // Felica standard has a different file system, AFAIK, // 8-byte IDm, number of blocks, blocks numbers // number of blocks limited to 4 for FelicaLite(S) -static void BuildFliteRdblk(uint8_t *idm, int blocknum, uint16_t *blocks) -{ +static void BuildFliteRdblk(uint8_t *idm, int blocknum, uint16_t *blocks) { if (blocknum > 4 || blocknum <= 0) Dbprintf("Invalid number of blocks, %d != 4", blocknum); @@ -324,8 +316,7 @@ static void BuildFliteRdblk(uint8_t *idm, int blocknum, uint16_t *blocks) AddCrc(frameSpace, c - 2); } -static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing, uint8_t power, uint8_t highspeed) -{ +static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing, uint8_t power, uint8_t highspeed) { uint8_t flags = FPGA_MAJOR_MODE_ISO18092; @@ -389,8 +380,7 @@ static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing, // Wait for tag reply // stop when button is pressed // or return TRUE when command is captured -bool WaitForFelicaReply(uint16_t maxbytes) -{ +bool WaitForFelicaReply(uint16_t maxbytes) { uint32_t c = 0; @@ -440,8 +430,7 @@ bool WaitForFelicaReply(uint16_t maxbytes) // Set up FeliCa communication (similar to iso14443a_setup) // field is setup for "Sending as Reader" -static void iso18092_setup(uint8_t fpga_minor_mode) -{ +static void iso18092_setup(uint8_t fpga_minor_mode) { LEDsoff(); FpgaDownloadAndGo(FPGA_BITSTREAM_HF); @@ -485,8 +474,7 @@ static void iso18092_setup(uint8_t fpga_minor_mode) // arg0 FeliCa flags // arg1 len of commandbytes // d.asBytes command bytes to send -void felica_sendraw(UsbCommand *c) -{ +void felica_sendraw(UsbCommand *c) { if (MF_DBGLEVEL > 3) Dbprintf("FeliCa_sendraw Enter"); @@ -552,8 +540,7 @@ OUT: if (MF_DBGLEVEL > 3) Dbprintf("FeliCa_sendraw Exit"); } -void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) -{ +void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) { int remFrames = (samplesToSkip) ? samplesToSkip : 0; @@ -624,8 +611,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(uint64_t nfcid) -{ +void felica_sim_lite(uint64_t nfcid) { int i, curlen = 0; uint8_t *curresp = 0; @@ -731,8 +717,7 @@ void felica_sim_lite(uint64_t nfcid) DbpString("Felica Lite-S sim end"); } -void felica_dump_lite_s() -{ +void felica_dump_lite_s() { uint8_t ndef[8]; uint8_t poll[10] = { 0xb2, 0x4d, 0x06, FELICA_POLL_REQ, 0xff, 0xff, 0x00, 0x00, 0x09, 0x21}; diff --git a/armsrc/flashmem.c b/armsrc/flashmem.c index 6773af444..56b564b1d 100644 --- a/armsrc/flashmem.c +++ b/armsrc/flashmem.c @@ -13,15 +13,13 @@ uint32_t FLASHMEM_SPIBAUDRATE = FLASH_BAUD; -void FlashmemSetSpiBaudrate(uint32_t baudrate) -{ +void FlashmemSetSpiBaudrate(uint32_t baudrate) { FLASHMEM_SPIBAUDRATE = baudrate; Dbprintf("Spi Baudrate : %dMhz", FLASHMEM_SPIBAUDRATE / 1000000); } // initialize -bool FlashInit() -{ +bool FlashInit() { FlashSetup(FLASHMEM_SPIBAUDRATE); StartTicks(); @@ -34,8 +32,7 @@ bool FlashInit() return true; } -void FlashSetup(uint32_t baudrate) -{ +void FlashSetup(uint32_t baudrate) { //WDT_DISABLE AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS; @@ -130,8 +127,7 @@ void FlashSetup(uint32_t baudrate) if (AT91C_BASE_SPI->SPI_RDR == 0) {}; } -void FlashStop(void) -{ +void FlashStop(void) { //Bof //* Reset all the Chip Select register AT91C_BASE_SPI->SPI_CSR[0] = 0; @@ -154,8 +150,7 @@ void FlashStop(void) } // send one byte over SPI -uint16_t FlashSendByte(uint32_t data) -{ +uint16_t FlashSendByte(uint32_t data) { // wait until SPI is ready for transfer //if you are checking for incoming data returned then the TXEMPTY flag is redundant @@ -174,20 +169,17 @@ uint16_t FlashSendByte(uint32_t data) } // send last byte over SPI -uint16_t FlashSendLastByte(uint32_t data) -{ +uint16_t FlashSendLastByte(uint32_t data) { return FlashSendByte(data | AT91C_SPI_LASTXFER); } // read state register 1 -uint8_t Flash_ReadStat1(void) -{ +uint8_t Flash_ReadStat1(void) { FlashSendByte(READSTAT1); return FlashSendLastByte(0xFF); } -bool Flash_CheckBusy(uint32_t timeout) -{ +bool Flash_CheckBusy(uint32_t timeout) { WaitUS(WINBOND_WRITE_DELAY); StartCountUS(); uint32_t _time = GetCountUS(); @@ -208,8 +200,7 @@ bool Flash_CheckBusy(uint32_t timeout) } // read ID out -uint8_t Flash_ReadID(void) -{ +uint8_t Flash_ReadID(void) { if (Flash_CheckBusy(BUSY_TIMEOUT)) return 0; @@ -231,8 +222,7 @@ uint8_t Flash_ReadID(void) } // read unique id for chip. -void Flash_UniqueID(uint8_t *uid) -{ +void Flash_UniqueID(uint8_t *uid) { if (Flash_CheckBusy(BUSY_TIMEOUT)) return; @@ -253,8 +243,7 @@ void Flash_UniqueID(uint8_t *uid) uid[0] = FlashSendLastByte(0xFF); } -uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len) -{ +uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len) { if (!FlashInit()) return 0; @@ -279,16 +268,14 @@ uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len) return len; } -void Flash_TransferAdresse(uint32_t address) -{ +void Flash_TransferAdresse(uint32_t address) { FlashSendByte((address >> 16) & 0xFF); FlashSendByte((address >> 8) & 0xFF); FlashSendByte((address >> 0) & 0xFF); } /* This ensure we can ReadData without having to cycle through initialization everytime */ -uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len) -{ +uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len) { // length should never be zero if (!len) return 0; @@ -314,8 +301,7 @@ uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len) //////////////////////////////////////// // Write data can only program one page. A page has 256 bytes. // if len > 256, it might wrap around and overwrite pos 0. -uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len) -{ +uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len) { // length should never be zero if (!len) @@ -361,8 +347,7 @@ uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len) // length should never be zero // Max 256 bytes write // out-of-range -uint16_t Flash_WriteDataCont(uint32_t address, uint8_t *in, uint16_t len) -{ +uint16_t Flash_WriteDataCont(uint32_t address, uint8_t *in, uint16_t len) { if (!len) return 0; @@ -392,8 +377,7 @@ uint16_t Flash_WriteDataCont(uint32_t address, uint8_t *in, uint16_t len) // assumes valid start 256 based 00 address // -uint16_t Flash_Write(uint32_t address, uint8_t *in, uint16_t len) -{ +uint16_t Flash_Write(uint32_t address, uint8_t *in, uint16_t len) { bool isok; uint16_t res, bytes_sent = 0, bytes_remaining = len; @@ -424,8 +408,7 @@ out: } -bool Flash_WipeMemoryPage(uint8_t page) -{ +bool Flash_WipeMemoryPage(uint8_t page) { if (!FlashInit()) { if (MF_DBGLEVEL > 3) Dbprintf("Flash_WriteData init fail"); return false; @@ -441,8 +424,7 @@ bool Flash_WipeMemoryPage(uint8_t page) return true; } // Wipes flash memory completely, fills with 0xFF -bool Flash_WipeMemory() -{ +bool Flash_WipeMemory() { if (!FlashInit()) { if (MF_DBGLEVEL > 3) Dbprintf("Flash_WriteData init fail"); return false; @@ -469,16 +451,14 @@ bool Flash_WipeMemory() } // enable the flash write -void Flash_WriteEnable() -{ +void Flash_WriteEnable() { FlashSendLastByte(WRITEENABLE); if (MF_DBGLEVEL > 3) Dbprintf("Flash Write enabled"); } // erase 4K at one time // execution time: 0.8ms / 800us -bool Flash_Erase4k(uint8_t block, uint8_t sector) -{ +bool Flash_Erase4k(uint8_t block, uint8_t sector) { if (block > MAX_BLOCKS || sector > MAX_SECTORS) return false; @@ -513,8 +493,7 @@ bool Flash_Erase32k(uint32_t address) { // 0x01 00 00 -- 0x 01 FF FF == block 1 // 0x02 00 00 -- 0x 02 FF FF == block 2 // 0x03 00 00 -- 0x 03 FF FF == block 3 -bool Flash_Erase64k(uint8_t block) -{ +bool Flash_Erase64k(uint8_t block) { if (block > MAX_BLOCKS) return false; @@ -526,13 +505,11 @@ bool Flash_Erase64k(uint8_t block) } // Erase chip -void Flash_EraseChip(void) -{ +void Flash_EraseChip(void) { FlashSendLastByte(CHIPERASE); } -void Flashmem_print_status(void) -{ +void Flashmem_print_status(void) { DbpString("Flash memory"); Dbprintf(" Baudrate................%dMHz", FLASHMEM_SPIBAUDRATE / 1000000); diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index 76a33bd9e..0b94bba45 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -28,8 +28,7 @@ static uint32_t uncompressed_bytes_cnt; // Used to write the FPGA config word // May also be used to write to other SPI attached devices like an LCD //----------------------------------------------------------------------------- -static void DisableSpi(void) -{ +static void DisableSpi(void) { //* Reset all the Chip Select register AT91C_BASE_SPI->SPI_CSR[0] = 0; AT91C_BASE_SPI->SPI_CSR[1] = 0; @@ -46,8 +45,7 @@ static void DisableSpi(void) AT91C_BASE_SPI->SPI_CR = AT91C_SPI_SPIDIS; } -void SetupSpi(int mode) -{ +void SetupSpi(int mode) { // PA1 -> SPI_NCS3 chip select (MEM) // PA10 -> SPI_NCS2 chip select (LCD) // PA11 -> SPI_NCS0 chip select (FPGA) @@ -120,8 +118,7 @@ void SetupSpi(int mode) // Set up the synchronous serial port, with the one set of options that we // always use when we are talking to the FPGA. Both RX and TX are enabled. //----------------------------------------------------------------------------- -void FpgaSetupSsc(void) -{ +void FpgaSetupSsc(void) { // First configure the GPIOs, and get ourselves a clock. AT91C_BASE_PIOA->PIO_ASR = GPIO_SSC_FRAME | @@ -159,8 +156,7 @@ void FpgaSetupSsc(void) // ourselves, not to another buffer). The stuff to manipulate those buffers // is in apps.h, because it should be inlined, for speed. //----------------------------------------------------------------------------- -bool FpgaSetupSscDma(uint8_t *buf, int len) -{ +bool FpgaSetupSscDma(uint8_t *buf, int len) { if (buf == NULL) return false; FpgaDisableSscDma(); @@ -176,8 +172,7 @@ bool FpgaSetupSscDma(uint8_t *buf, int len) // Uncompress (inflate) the FPGA data. Returns one decompressed byte with // each call. //---------------------------------------------------------------------------- -static int get_from_fpga_combined_stream(z_streamp compressed_fpga_stream, uint8_t *output_buffer) -{ +static int get_from_fpga_combined_stream(z_streamp compressed_fpga_stream, uint8_t *output_buffer) { if (fpga_image_ptr == compressed_fpga_stream->next_out) { // need more data compressed_fpga_stream->next_out = output_buffer; compressed_fpga_stream->avail_out = OUTPUT_BUFFER_LEN; @@ -199,8 +194,7 @@ static int get_from_fpga_combined_stream(z_streamp compressed_fpga_stream, uint8 // are combined into one big file: // 288 bytes from FPGA file 1, followed by 288 bytes from FGPA file 2, etc. //---------------------------------------------------------------------------- -static int get_from_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer) -{ +static int get_from_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer) { while ((uncompressed_bytes_cnt / FPGA_INTERLEAVE_SIZE) % fpga_bitstream_num != (bitstream_version - 1)) { // skip undesired data belonging to other bitstream_versions get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer); @@ -209,14 +203,12 @@ static int get_from_fpga_stream(int bitstream_version, z_streamp compressed_fpga return get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer); } -static voidpf fpga_inflate_malloc(voidpf opaque, uInt items, uInt size) -{ +static voidpf fpga_inflate_malloc(voidpf opaque, uInt items, uInt size) { return BigBuf_malloc(items * size); } // free eventually allocated BigBuf memory -static void fpga_inflate_free(voidpf opaque, voidpf address) -{ +static void fpga_inflate_free(voidpf opaque, voidpf address) { BigBuf_free(); BigBuf_Clear_ext(false); } @@ -224,8 +216,7 @@ static void fpga_inflate_free(voidpf opaque, voidpf address) //---------------------------------------------------------------------------- // Initialize decompression of the respective (HF or LF) FPGA stream //---------------------------------------------------------------------------- -static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer) -{ +static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer) { uint8_t header[FPGA_BITSTREAM_FIXED_HEADER_SIZE]; uncompressed_bytes_cnt = 0; @@ -252,8 +243,7 @@ static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_s return false; } -static void DownloadFPGA_byte(uint8_t w) -{ +static void DownloadFPGA_byte(uint8_t w) { #define SEND_BIT(x) { if(w & (1<PIO_OER = GPIO_FPGA_ON; @@ -349,8 +338,7 @@ static void DownloadFPGA(int bitstream_version, int FpgaImageLen, z_streamp comp * (big endian), bytes content. Except for section 'e' which has 4 bytes * length. */ -static int bitparse_find_section(int bitstream_version, char section_name, uint32_t *section_length, z_streamp compressed_fpga_stream, uint8_t *output_buffer) -{ +static int bitparse_find_section(int bitstream_version, char section_name, uint32_t *section_length, z_streamp compressed_fpga_stream, uint8_t *output_buffer) { int result = 0; #define MAX_FPGA_BIT_STREAM_HEADER_SEARCH 100 // maximum number of bytes to search for the requested section uint16_t numbytes = 0; @@ -399,8 +387,7 @@ static int bitparse_find_section(int bitstream_version, char section_name, uint3 // Check which FPGA image is currently loaded (if any). If necessary // decompress and load the correct (HF or LF) image to the FPGA //---------------------------------------------------------------------------- -void FpgaDownloadAndGo(int bitstream_version) -{ +void FpgaDownloadAndGo(int bitstream_version) { // check whether or not the bitstream is already loaded if (downloaded_bitstream == bitstream_version) @@ -439,8 +426,7 @@ void FpgaDownloadAndGo(int bitstream_version) // The bit format is: C3 C2 C1 C0 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 // where C is the 4 bit command and D is the 12 bit data //----------------------------------------------------------------------------- -void FpgaSendCommand(uint16_t cmd, uint16_t v) -{ +void FpgaSendCommand(uint16_t cmd, uint16_t v) { SetupSpi(SPI_FPGA_MODE); while ((AT91C_BASE_SPI->SPI_SR & AT91C_SPI_TXEMPTY) == 0); // wait for the transfer to complete AT91C_BASE_SPI->SPI_TDR = AT91C_SPI_LASTXFER | cmd | v; // send the data @@ -451,8 +437,7 @@ void FpgaSendCommand(uint16_t cmd, uint16_t v) // vs. clone vs. etc.). This is now a special case of FpgaSendCommand() to // avoid changing this function's occurence everywhere in the source code. //----------------------------------------------------------------------------- -void FpgaWriteConfWord(uint8_t v) -{ +void FpgaWriteConfWord(uint8_t v) { FpgaSendCommand(FPGA_CMD_SET_CONFREG, v); } @@ -461,8 +446,7 @@ void FpgaWriteConfWord(uint8_t v) // closable, but should only close one at a time. Not an FPGA thing, but // the samples from the ADC always flow through the FPGA. //----------------------------------------------------------------------------- -void SetAdcMuxFor(uint32_t whichGpio) -{ +void SetAdcMuxFor(uint32_t whichGpio) { AT91C_BASE_PIOA->PIO_OER = GPIO_MUXSEL_HIPKD | GPIO_MUXSEL_LOPKD | @@ -485,14 +469,12 @@ void SetAdcMuxFor(uint32_t whichGpio) HIGH(whichGpio); } -void Fpga_print_status(void) -{ +void Fpga_print_status(void) { Dbprintf("Currently loaded FPGA image"); Dbprintf(" mode....................%s", fpga_version_information[downloaded_bitstream - 1]); } -int FpgaGetCurrent(void) -{ +int FpgaGetCurrent(void) { return downloaded_bitstream; } @@ -500,8 +482,7 @@ int FpgaGetCurrent(void) // log message // if HF, Disable SSC DMA // turn off trace and leds off. -void switch_off(void) -{ +void switch_off(void) { if (MF_DBGLEVEL > 3) Dbprintf("switch_off"); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); if (downloaded_bitstream == FPGA_BITSTREAM_HF) diff --git a/armsrc/hfsnoop.c b/armsrc/hfsnoop.c index 9400b6b3d..4ec60d175 100644 --- a/armsrc/hfsnoop.c +++ b/armsrc/hfsnoop.c @@ -6,8 +6,7 @@ static void RAMFUNC optimizedSnoop(void); -static void RAMFUNC optimizedSnoop(void) -{ +static void RAMFUNC optimizedSnoop(void) { int n = BigBuf_max_traceLen() / sizeof(uint16_t); // take all memory uint16_t *dest = (uint16_t *)BigBuf_get_addr(); @@ -24,8 +23,7 @@ static void RAMFUNC optimizedSnoop(void) set_tracelen(BigBuf_max_traceLen()); } -void HfSnoop(int samplesToSkip, int triggersToSkip) -{ +void HfSnoop(int samplesToSkip, int triggersToSkip) { BigBuf_free(); BigBuf_Clear(); diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index 4bbc8fc6b..d408c0ab3 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -108,8 +108,7 @@ static const u32 ht2_f4a = 0x2C79; // 0010 1100 0111 1001 static const u32 ht2_f4b = 0x6671; // 0110 0110 0111 0001 static const u32 ht2_f5c = 0x7907287B; // 0111 1001 0000 0111 0010 1000 0111 1011 -static u32 _f20(const u64 x) -{ +static u32 _f20(const u64 x) { u32 i5; i5 = ((ht2_f4a >> i4(x, 1, 2, 4, 5)) & 1) * 1 @@ -121,8 +120,7 @@ static u32 _f20(const u64 x) return (ht2_f5c >> i5) & 1; } -static u64 _hitag2_init(const u64 key, const u32 serial, const u32 IV) -{ +static u64 _hitag2_init(const u64 key, const u32 serial, const u32 IV) { u32 i; u64 x = ((key & 0xFFFF) << 32) + serial; @@ -133,8 +131,7 @@ static u64 _hitag2_init(const u64 key, const u32 serial, const u32 IV) return x; } -static u64 _hitag2_round(u64 *state) -{ +static u64 _hitag2_round(u64 *state) { u64 x = *state; x = (x >> 1) + @@ -157,29 +154,25 @@ static u64 _hitag2_round(u64 *state) // The inverse of the first 4 bytes is sent to the tag to authenticate. // The rest is encrypted by XORing it with the subsequent keystream. -static u32 _hitag2_byte(u64 *x) -{ +static u32 _hitag2_byte(u64 *x) { u32 i, c; for (i = 0, c = 0; i < 8; i++) c += (u32) _hitag2_round(x) << (i ^ 7); return c; } -static int hitag2_reset(void) -{ +static int hitag2_reset(void) { tag.state = TAG_STATE_RESET; tag.crypto_active = 0; return 0; } -static int hitag2_init(void) -{ +static int hitag2_init(void) { hitag2_reset(); return 0; } -static void hitag2_cipher_reset(struct hitag2_tag *tag, const uint8_t *iv) -{ +static 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)tag->sectors[1][0] << 16) | @@ -197,8 +190,7 @@ static void hitag2_cipher_reset(struct hitag2_tag *tag, const uint8_t *iv) tag->cs = _hitag2_init(rev64(key), rev32(uid), rev32(iv_)); } -static int hitag2_cipher_authenticate(uint64_t *cs, const uint8_t *authenticator_is) -{ +static int hitag2_cipher_authenticate(uint64_t *cs, const uint8_t *authenticator_is) { uint8_t authenticator_should[4]; authenticator_should[0] = ~_hitag2_byte(cs); authenticator_should[1] = ~_hitag2_byte(cs); @@ -207,8 +199,7 @@ static int hitag2_cipher_authenticate(uint64_t *cs, const uint8_t *authenticator return (memcmp(authenticator_should, authenticator_is, 4) == 0); } -static int hitag2_cipher_transcrypt(uint64_t *cs, uint8_t *data, unsigned int bytes, unsigned int bits) -{ +static int hitag2_cipher_transcrypt(uint64_t *cs, uint8_t *data, unsigned int bytes, unsigned int bits) { int i; for (i = 0; i < bytes; i++) data[i] ^= _hitag2_byte(cs); for (i = 0; i < bits; i++) data[bytes] ^= _hitag2_round(cs) << (7 - i); @@ -250,8 +241,7 @@ static int hitag2_cipher_transcrypt(uint64_t *cs, uint8_t *data, unsigned int by #define HITAG_T_TAG_CAPTURE_FOUR_HALF 57 -static void hitag_send_bit(int bit) -{ +static void hitag_send_bit(int bit) { LED_A_ON(); // Reset clock for the next bit AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG; @@ -273,8 +263,7 @@ static void hitag_send_bit(int bit) LED_A_OFF(); } -static void hitag_send_frame(const uint8_t *frame, size_t frame_len) -{ +static void hitag_send_frame(const uint8_t *frame, size_t frame_len) { // Send start of frame for (size_t i = 0; i < 5; i++) { hitag_send_bit(1); @@ -290,8 +279,7 @@ static void hitag_send_frame(const uint8_t *frame, size_t frame_len) } -static void hitag2_handle_reader_command(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) -{ +static void hitag2_handle_reader_command(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) { uint8_t rx_air[HITAG_FRAME_LEN]; // Copy the (original) received frame how it is send over the air @@ -417,8 +405,7 @@ static void hitag2_handle_reader_command(uint8_t *rx, const size_t rxlen, uint8_ } } -static void hitag_reader_send_bit(int bit) -{ +static void hitag_reader_send_bit(int bit) { LED_A_ON(); // Reset clock for the next bit AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG; @@ -448,8 +435,7 @@ static void hitag_reader_send_bit(int bit) } -static void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len) -{ +static void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len) { // Send the content of the frame for (size_t i = 0; i < frame_len; i++) { hitag_reader_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1); @@ -466,8 +452,7 @@ static void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len) size_t blocknr; -static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) -{ +static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) { // Reset the transmission frame length *txlen = 0; @@ -525,8 +510,7 @@ static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t return true; } -static bool hitag2_write_page(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) -{ +static bool hitag2_write_page(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) { switch (writestate) { case WRITE_STATE_START: *txlen = 10; @@ -537,8 +521,8 @@ static bool hitag2_write_page(uint8_t *rx, const size_t rxlen, uint8_t *tx, size case WRITE_STATE_PAGENUM_WRITTEN: // Check if page number was received correctly if ((rxlen == 10) && - (rx[0] == (0x82 | (blocknr << 3) | ((blocknr ^ 7) >> 2))) && - (rx[1] == (((blocknr & 0x3) ^ 0x3) << 6))) { + (rx[0] == (0x82 | (blocknr << 3) | ((blocknr ^ 7) >> 2))) && + (rx[1] == (((blocknr & 0x3) ^ 0x3) << 6))) { *txlen = 32; memset(tx, 0, HITAG_FRAME_LEN); memcpy(tx, writedata, 4); @@ -567,8 +551,7 @@ static bool hitag2_write_page(uint8_t *rx, const size_t rxlen, uint8_t *tx, size return true; } -static bool hitag2_crypto(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen, bool write) -{ +static bool hitag2_crypto(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen, bool write) { // Reset the transmission frame length *txlen = 0; @@ -677,8 +660,7 @@ static bool hitag2_crypto(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t * } -static bool hitag2_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) -{ +static bool hitag2_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) { // Reset the transmission frame length *txlen = 0; @@ -721,8 +703,7 @@ static bool hitag2_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, si } -static bool hitag2_test_auth_attempts(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) -{ +static bool hitag2_test_auth_attempts(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) { // Reset the transmission frame length *txlen = 0; @@ -781,8 +762,7 @@ static bool hitag2_test_auth_attempts(uint8_t *rx, const size_t rxlen, uint8_t * return true; } -static bool hitag2_read_uid(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) -{ +static bool hitag2_read_uid(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) { // Reset the transmission frame length *txlen = 0; @@ -822,8 +802,7 @@ static bool hitag2_read_uid(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t return true; } -void SnoopHitag(uint32_t type) -{ +void SnoopHitag(uint32_t type) { int frame_count; int response; int overflow; @@ -1041,8 +1020,7 @@ void SnoopHitag(uint32_t type) // DbpString("All done"); } -void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) -{ +void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) { int frame_count; int response; int overflow; @@ -1233,8 +1211,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) set_tracing(false); } -void ReaderHitag(hitag_function htf, hitag_data *htd) -{ +void ReaderHitag(hitag_function htf, hitag_data *htd) { int frame_count = 0; int response = 0; uint8_t rx[HITAG_FRAME_LEN]; @@ -1548,8 +1525,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) cmd_send(CMD_ACK, bSuccessful, 0, 0, 0, 0); } -void WriterHitag(hitag_function htf, hitag_data *htd, int page) -{ +void WriterHitag(hitag_function htf, hitag_data *htd, int page) { int frame_count; int response; uint8_t rx[HITAG_FRAME_LEN]; diff --git a/armsrc/hitagS.c b/armsrc/hitagS.c index 33028b777..b53112081 100644 --- a/armsrc/hitagS.c +++ b/armsrc/hitagS.c @@ -65,8 +65,7 @@ static const u32 ht2_f5c = 0x7907287B; // 0111 1001 0000 0111 0010 1000 0 #define ht2bs_5c(a,b,c,d,e) (~((((((c^e)|d)&a)^b)&(c^b))^(((d^e)|a)&((d^b)|c)))) #define uf20bs u32 -static u32 f20(const u64 x) -{ +static u32 f20(const u64 x) { u32 i5; i5 = ((ht2_f4a >> i4(x, 1, 2, 4, 5)) & 1) * 1 @@ -77,8 +76,7 @@ static u32 f20(const u64 x) return (ht2_f5c >> i5) & 1; } -static u64 hitag2_round(u64 *state) -{ +static u64 hitag2_round(u64 *state) { u64 x = *state; x = (x >> 1) @@ -90,8 +88,7 @@ static u64 hitag2_round(u64 *state) *state = x; return f20(x); } -static u64 hitag2_init(const u64 key, const u32 serial, const u32 IV) -{ +static u64 hitag2_init(const u64 key, const u32 serial, const u32 IV) { u32 i; u64 x = ((key & 0xFFFF) << 32) + serial; for (i = 0; i < 32; i++) { @@ -100,8 +97,7 @@ static u64 hitag2_init(const u64 key, const u32 serial, const u32 IV) } return x; } -static u32 hitag2_byte(u64 *x) -{ +static u32 hitag2_byte(u64 *x) { u32 i, c; for (i = 0, c = 0; i < 8; i++) @@ -148,8 +144,7 @@ static u32 hitag2_byte(u64 *x) * Implementation of the crc8 calculation from Hitag S * from http://www.proxmark.org/files/Documents/125%20kHz%20-%20Hitag/HitagS.V11.pdf */ -void calc_crc(unsigned char *crc, unsigned char data, unsigned char Bitcount) -{ +void calc_crc(unsigned char *crc, unsigned char data, unsigned char Bitcount) { *crc ^= data; // crc = crc (exor) data do { if (*crc & 0x80) { // if (MSB-CRC == 1) @@ -161,8 +156,7 @@ void calc_crc(unsigned char *crc, unsigned char data, unsigned char Bitcount) } while (--Bitcount); } -static void hitag_send_bit(int bit) -{ +static void hitag_send_bit(int bit) { LED_A_ON(); // Reset clock for the next bit AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG; @@ -264,8 +258,7 @@ static void hitag_send_bit(int bit) } } -static void hitag_send_frame(const byte_t *frame, size_t frame_len) -{ +static void hitag_send_frame(const byte_t *frame, size_t frame_len) { // Send start of frame for (size_t i = 0; i < sof_bits; i++) { @@ -280,8 +273,7 @@ static void hitag_send_frame(const byte_t *frame, size_t frame_len) LOW(GPIO_SSC_DOUT); } -static void hitag_reader_send_bit(int bit) -{ +static void hitag_reader_send_bit(int bit) { //Dbprintf("BIT: %d",bit); LED_A_ON(); // Reset clock for the next bit @@ -337,8 +329,7 @@ static void hitag_reader_send_bit(int bit) LED_A_OFF(); } -static void hitag_reader_send_frame(const byte_t *frame, size_t frame_len) -{ +static void hitag_reader_send_frame(const byte_t *frame, size_t frame_len) { // Send the content of the frame for (size_t i = 0; i < frame_len; i++) { if (frame[0] == 0xf8) { @@ -360,8 +351,7 @@ static void hitag_reader_send_frame(const byte_t *frame, size_t frame_len) /* * to check if the right uid was selected */ -static int check_select(byte_t *rx, uint32_t uid) -{ +static int check_select(byte_t *rx, uint32_t uid) { unsigned char resp[48]; int i; uint32_t ans = 0x0; @@ -382,8 +372,7 @@ static int check_select(byte_t *rx, uint32_t uid) * handles all commands from a reader */ static void hitagS_handle_reader_command(byte_t *rx, const size_t rxlen, - byte_t *tx, size_t *txlen) -{ + byte_t *tx, size_t *txlen) { byte_t rx_air[HITAG_FRAME_LEN]; byte_t page; int i; @@ -679,7 +668,7 @@ static void hitagS_handle_reader_command(byte_t *rx, const size_t rxlen, break; } if ((tag.LCON && page == 1) - || (tag.LKP && (page == 2 || page == 3))) { + || (tag.LKP && (page == 2 || page == 3))) { //deny *txlen = 0; } else { @@ -732,8 +721,7 @@ static void hitagS_handle_reader_command(byte_t *rx, const size_t rxlen, * to autenticate to a tag with the given key or challenge */ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrAr, byte_t *rx, const size_t rxlen, byte_t *tx, - size_t *txlen) -{ + size_t *txlen) { byte_t rx_air[HITAG_FRAME_LEN]; int response_bit[200]; int i, j, z, k; @@ -945,8 +933,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA /* * Emulates a Hitag S Tag with the given data from the .hts file */ -void SimulateHitagSTag(bool tag_mem_supplied, byte_t *data) -{ +void SimulateHitagSTag(bool tag_mem_supplied, byte_t *data) { int frame_count; int response; int overflow; @@ -1172,8 +1159,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, byte_t *data) * If the key was given the password will be decrypted. * Reads every page of a hitag S transpoder. */ -void ReadHitagS(hitag_function htf, hitag_data *htd) -{ +void ReadHitagS(hitag_function htf, hitag_data *htd) { int i, j, z, k; int frame_count; int response_bit[200]; @@ -1518,8 +1504,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) * Authenticates to the Tag with the given Key or Challenge. * Writes the given 32Bit data into page_ */ -void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_) -{ +void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_) { int frame_count; int response; byte_t rx[HITAG_FRAME_LEN]; @@ -1727,7 +1712,7 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_) // All timer values are in terms of T0 units while (AT91C_BASE_TC0->TC_CV - < T0 * (t_wait + (HITAG_T_TAG_HALF_PERIOD * lastbit))) + < T0 * (t_wait + (HITAG_T_TAG_HALF_PERIOD * lastbit))) ; // Transmit the reader frame @@ -1835,8 +1820,7 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_) * is not received correctly due to Antenna problems. This function * detects these challenges. */ -void check_challenges(bool file_given, byte_t *data) -{ +void check_challenges(bool file_given, byte_t *data) { int i, j, z, k; byte_t uid_byte[4]; int frame_count; @@ -2060,7 +2044,7 @@ void check_challenges(bool file_given, byte_t *data) // All timer values are in terms of T0 units while (AT91C_BASE_TC0->TC_CV - < T0 * (t_wait + (HITAG_T_TAG_HALF_PERIOD * lastbit))) + < T0 * (t_wait + (HITAG_T_TAG_HALF_PERIOD * lastbit))) ; // Transmit the reader frame diff --git a/armsrc/iclass.c b/armsrc/iclass.c index d5f908a12..7bd725eab 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -141,19 +141,16 @@ typedef struct { } tUart; static tUart Uart; -static void uart_reset(void) -{ +static void uart_reset(void) { Uart.frame_done = false; Uart.synced = false; Uart.frame = false; } -static void uart_init(uint8_t *data) -{ +static void uart_init(uint8_t *data) { Uart.buf = data; uart_reset(); } -static void uart_bit(uint8_t bit) -{ +static void uart_bit(uint8_t bit) { static uint8_t buf = 0xff; static uint8_t n_buf; static uint8_t msg_byte; @@ -208,8 +205,7 @@ static void uart_bit(uint8_t bit) } } -static void uart_samples(uint8_t byte) -{ +static void uart_samples(uint8_t byte) { static uint32_t buf; static int window; static int drop_next = 0; @@ -504,8 +500,7 @@ static RAMFUNC int OutOfNDecoding(int bit) { // Manchester //============================================================================= static tDemod Demod; -static void DemodReset() -{ +static void DemodReset() { Demod.bitCount = 0; Demod.posCount = 0; Demod.syncBit = 0; @@ -519,8 +514,7 @@ static void DemodReset() Demod.sub = SUB_NONE; Demod.state = DEMOD_UNSYNCD; } -static void DemodInit(uint8_t *data) -{ +static void DemodInit(uint8_t *data) { Demod.output = data; DemodReset(); } @@ -546,8 +540,7 @@ Recorded Activity (TraceLen = 162 bytes) 2720 | 2720 | Rdr |0c | | IDENTIFY 3232 | 3232 | Tag |bb! d4! bb! 02 02 08 04 bb! | ok | */ -static void uart_debug(int error, int bit) -{ +static void uart_debug(int error, int bit) { Demod.output[Demod.len] = 0xBB; Demod.len++; Demod.output[Demod.len] = error & 0xFF; @@ -583,8 +576,7 @@ static void uart_debug(int error, int bit) * * So for current implementation in ISO15693, its 330 µs from end of reader, to start of card. */ -static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) -{ +static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) { int bit; int modulation; int error = 0; @@ -806,8 +798,7 @@ static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) // Finally, a `sniffer' for iClass communication // Both sides of communication! //============================================================================= -static void iclass_setup_sniff(void) -{ +static void iclass_setup_sniff(void) { if (MF_DBGLEVEL > 3) Dbprintf("iclass_setup_sniff Enter"); LEDsoff(); @@ -860,8 +851,7 @@ static void iclass_setup_sniff(void) // near the reader. //----------------------------------------------------------------------------- // turn off afterwards -void RAMFUNC SniffIClass(void) -{ +void RAMFUNC SniffIClass(void) { //int datalen = 0; uint32_t previous_data = 0; @@ -983,8 +973,7 @@ void RAMFUNC SniffIClass(void) switch_off(); } -void rotateCSN(uint8_t *originalCSN, uint8_t *rotatedCSN) -{ +void rotateCSN(uint8_t *originalCSN, uint8_t *rotatedCSN) { int i; for (i = 0; i < 8; i++) rotatedCSN[i] = (originalCSN[i] >> 3) | (originalCSN[(i + 1) % 8] << 5); @@ -996,8 +985,7 @@ void rotateCSN(uint8_t *originalCSN, uint8_t *rotatedCSN) // Stop when button is pressed // Or return TRUE when command is captured //----------------------------------------------------------------------------- -static bool GetIClassCommandFromReader(uint8_t *received, int *len, int maxLen) -{ +static bool GetIClassCommandFromReader(uint8_t *received, int *len, int maxLen) { // Set FPGA mode to "simulated ISO 14443 tag", no modulation (listen // only, since we are receiving, not transmitting). // Signal field is off with the appropriate LED @@ -1029,8 +1017,7 @@ static bool GetIClassCommandFromReader(uint8_t *received, int *len, int maxLen) return false; } -static uint8_t encode4Bits(const uint8_t b) -{ +static uint8_t encode4Bits(const uint8_t b) { // OTA, the least significant bits first // Manchester encoding added // The columns are @@ -1080,8 +1067,7 @@ static uint8_t encode4Bits(const uint8_t b) //----------------------------------------------------------------------------- // Prepare tag messages //----------------------------------------------------------------------------- -static void CodeIClassTagAnswer(const uint8_t *cmd, int len) -{ +static void CodeIClassTagAnswer(const uint8_t *cmd, int len) { /* * SOF comprises 3 parts; * * An unmodulated time of 56.64 us @@ -1135,8 +1121,7 @@ static void CodeIClassTagAnswer(const uint8_t *cmd, int len) } // Only SOF -static void CodeIClassTagSOF() -{ +static void CodeIClassTagSOF() { //So far a dummy implementation, not used //int lastProxToAirDuration =0; @@ -1162,8 +1147,7 @@ static void CodeIClassTagSOF() * @param datain */ // turn off afterwards -void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) -{ +void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) { if (MF_DBGLEVEL > 3) Dbprintf("[+] iClass_simulate Enter"); @@ -1273,8 +1257,7 @@ out: * @param csn - csn to use * @param breakAfterMacReceived if true, returns after reader MAC has been received. */ -int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) -{ +int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) { // free eventually allocated BigBuf memory BigBuf_free_keep_EM(); @@ -1641,8 +1624,7 @@ send: * @param respLen * @param delay */ -static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay) -{ +static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay) { int i = 0; volatile uint8_t b = 0; @@ -1680,8 +1662,7 @@ static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay) //----------------------------------------------------------------------------- // Transmit the command (to the tag) that was placed in ToSend[]. //----------------------------------------------------------------------------- -static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int *wait) -{ +static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int *wait) { int c = 0; volatile uint32_t b; @@ -1737,8 +1718,7 @@ static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int //----------------------------------------------------------------------------- // Prepare iClass reader command to send to FPGA //----------------------------------------------------------------------------- -void CodeIClassCommand(const uint8_t *cmd, int len) -{ +void CodeIClassCommand(const uint8_t *cmd, int len) { int i, j, k; uint8_t b; @@ -1775,8 +1755,7 @@ void CodeIClassCommand(const uint8_t *cmd, int len) ToSendMax++; } -void ReaderTransmitIClass_ext(uint8_t *frame, int len, int wait) -{ +void ReaderTransmitIClass_ext(uint8_t *frame, int len, int wait) { int samples = 0; @@ -1792,8 +1771,7 @@ void ReaderTransmitIClass_ext(uint8_t *frame, int len, int wait) LogTrace(frame, len, rsamples, rsamples, NULL, true); } -void ReaderTransmitIClass(uint8_t *frame, int len) -{ +void ReaderTransmitIClass(uint8_t *frame, int len) { ReaderTransmitIClass_ext(frame, len, 330); } @@ -1802,8 +1780,7 @@ void ReaderTransmitIClass(uint8_t *frame, int len) // If a response is captured return TRUE // If it takes too long return FALSE //----------------------------------------------------------------------------- -static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed) -{ +static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed) { // buffer needs to be 512 bytes // maxLen is not used... @@ -1854,8 +1831,7 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, return false; } -int ReaderReceiveIClass(uint8_t *receivedAnswer) -{ +int ReaderReceiveIClass(uint8_t *receivedAnswer) { int samples = 0; if (!GetIClassAnswer(receivedAnswer, 0, &samples, NULL)) @@ -1871,8 +1847,7 @@ int ReaderReceiveIClass(uint8_t *receivedAnswer) return Demod.len; } -void setupIclassReader() -{ +void setupIclassReader() { LEDsoff(); @@ -1899,8 +1874,7 @@ void setupIclassReader() LED_A_ON(); } -bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *resp, uint8_t expected_size, uint8_t retries) -{ +bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *resp, uint8_t expected_size, uint8_t retries) { uint8_t got_n = 0; while (retries-- > 0) { @@ -1929,8 +1903,7 @@ bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *re * 1 = Got CSN * 2 = Got CSN and CC */ -uint8_t handshakeIclassTag_ext(uint8_t *card_data, bool use_credit_key) -{ +uint8_t handshakeIclassTag_ext(uint8_t *card_data, bool use_credit_key) { // act_all... static uint8_t act_all[] = { ICLASS_CMD_ACTALL }; @@ -1989,15 +1962,13 @@ uint8_t handshakeIclassTag_ext(uint8_t *card_data, bool use_credit_key) read_status++; return read_status; } -uint8_t handshakeIclassTag(uint8_t *card_data) -{ +uint8_t handshakeIclassTag(uint8_t *card_data) { return handshakeIclassTag_ext(card_data, false); } // Reader iClass Anticollission // turn off afterwards -void ReaderIClass(uint8_t arg0) -{ +void ReaderIClass(uint8_t arg0) { uint8_t card_data[6 * 8] = {0}; uint8_t last_csn[8] = {0, 0, 0, 0, 0, 0, 0, 0}; @@ -2136,8 +2107,7 @@ void ReaderIClass(uint8_t arg0) } // turn off afterwards -void ReaderIClass_Replay(uint8_t arg0, uint8_t *MAC) -{ +void ReaderIClass_Replay(uint8_t arg0, uint8_t *MAC) { uint8_t cardsize = 0; uint8_t mem = 0; @@ -2257,8 +2227,7 @@ void ReaderIClass_Replay(uint8_t arg0, uint8_t *MAC) // not used. ?!? ( CMD_ICLASS_READCHECK) // turn off afterwards -void iClass_ReadCheck(uint8_t blockNo, uint8_t keyType) -{ +void iClass_ReadCheck(uint8_t blockNo, uint8_t keyType) { uint8_t readcheck[] = { keyType, blockNo }; uint8_t resp[] = {0, 0, 0, 0, 0, 0, 0, 0}; size_t isOK = 0; @@ -2269,8 +2238,7 @@ void iClass_ReadCheck(uint8_t blockNo, uint8_t keyType) // used with function select_and_auth (cmdhficlass.c) // which needs to authenticate before doing more things like read/write -void iClass_Authentication(uint8_t *mac) -{ +void iClass_Authentication(uint8_t *mac) { uint8_t check[] = { ICLASS_CMD_CHECK, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; uint8_t resp[ICLASS_BUFFER_SIZE]; @@ -2297,8 +2265,7 @@ typedef struct iclass_premac { * - key loop only test one type of authtication key. Ie two calls needed * to cover debit and credit key. (AA1/AA2) */ -void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) -{ +void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) { uint8_t i = 0, isOK = 0; uint8_t lastChunk = ((arg0 >> 8) & 0xFF); bool use_credit_key = ((arg0 >> 16) & 0xFF); @@ -2381,8 +2348,7 @@ out: // Tries to read block. // retries 10times. -bool iClass_ReadBlock(uint8_t blockNo, uint8_t *data, uint8_t len) -{ +bool iClass_ReadBlock(uint8_t blockNo, uint8_t *data, uint8_t len) { uint8_t resp[10]; uint8_t cmd[] = {ICLASS_CMD_READ_OR_IDENTIFY, blockNo, 0x00, 0x00}; AddCrc(cmd + 1, 1); @@ -2394,8 +2360,7 @@ bool iClass_ReadBlock(uint8_t blockNo, uint8_t *data, uint8_t len) // turn off afterwards // readblock 8 + 2. only want 8. -void iClass_ReadBlk(uint8_t blockno) -{ +void iClass_ReadBlk(uint8_t blockno) { uint8_t data[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; bool isOK = iClass_ReadBlock(blockno, data, sizeof(data)); cmd_send(CMD_ACK, isOK, 0, 0, data, sizeof(data)); @@ -2403,8 +2368,7 @@ void iClass_ReadBlk(uint8_t blockno) } // turn off afterwards -void iClass_Dump(uint8_t blockno, uint8_t numblks) -{ +void iClass_Dump(uint8_t blockno, uint8_t numblks) { uint8_t blockdata[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; bool isOK = false; uint8_t blkCnt = 0; @@ -2438,8 +2402,7 @@ void iClass_Dump(uint8_t blockno, uint8_t numblks) BigBuf_free(); } -bool iClass_WriteBlock_ext(uint8_t blockNo, uint8_t *data) -{ +bool iClass_WriteBlock_ext(uint8_t blockNo, uint8_t *data) { uint8_t resp[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t write[] = { ICLASS_CMD_UPDATE, blockNo, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -2462,16 +2425,14 @@ bool iClass_WriteBlock_ext(uint8_t blockNo, uint8_t *data) } // turn off afterwards -void iClass_WriteBlock(uint8_t blockNo, uint8_t *data) -{ +void iClass_WriteBlock(uint8_t blockNo, uint8_t *data) { bool isOK = iClass_WriteBlock_ext(blockNo, data); cmd_send(CMD_ACK, isOK, 0, 0, 0, 0); switch_off(); } // turn off afterwards -void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data) -{ +void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data) { int i, written = 0; int total_block = (endblock - startblock) + 1; for (i = 0; i < total_block; i++) { diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 4469ca402..a22a79390 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -120,26 +120,22 @@ static uint32_t LastProxToAirDuration; #define SEC_Y 0x00 #define SEC_Z 0xc0 -void iso14a_set_trigger(bool enable) -{ +void iso14a_set_trigger(bool enable) { trigger = enable; } -void iso14a_set_timeout(uint32_t timeout) -{ +void iso14a_set_timeout(uint32_t timeout) { iso14a_timeout = timeout + (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / (16 * 8) + 2; } -uint32_t iso14a_get_timeout(void) -{ +uint32_t iso14a_get_timeout(void) { return iso14a_timeout - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / (16 * 8) - 2; } //----------------------------------------------------------------------------- // Generate the parity value for a byte sequence //----------------------------------------------------------------------------- -void GetParity(const uint8_t *pbtCmd, uint16_t iLen, uint8_t *par) -{ +void GetParity(const uint8_t *pbtCmd, uint16_t iLen, uint8_t *par) { uint16_t paritybit_cnt = 0; uint16_t paritybyte_cnt = 0; uint8_t parityBits = 0; @@ -193,13 +189,11 @@ const bool Mod_Miller_LUT[] = { #define IsMillerModulationNibble1(b) (Mod_Miller_LUT[(b & 0x000000F0) >> 4]) #define IsMillerModulationNibble2(b) (Mod_Miller_LUT[(b & 0x0000000F)]) -tUart *GetUart() -{ +tUart *GetUart() { return &Uart; } -void UartReset(void) -{ +void UartReset(void) { Uart.state = STATE_UNSYNCD; Uart.bitCount = 0; Uart.len = 0; // number of decoded data bytes @@ -213,16 +207,14 @@ void UartReset(void) Uart.syncBit = 9999; } -void UartInit(uint8_t *data, uint8_t *parity) -{ +void UartInit(uint8_t *data, uint8_t *parity) { Uart.output = data; Uart.parity = parity; UartReset(); } // use parameter non_real_time to provide a timestamp. Set to 0 if the decoder should measure real time -RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) -{ +RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) { Uart.fourBits = (Uart.fourBits << 8) | bit; if (Uart.state == STATE_UNSYNCD) { // not yet synced @@ -369,12 +361,10 @@ const bool Mod_Manchester_LUT[] = { #define IsManchesterModulationNibble1(b) (Mod_Manchester_LUT[(b & 0x00F0) >> 4]) #define IsManchesterModulationNibble2(b) (Mod_Manchester_LUT[(b & 0x000F)]) -tDemod *GetDemod() -{ +tDemod *GetDemod() { return &Demod; } -void DemodReset(void) -{ +void DemodReset(void) { Demod.state = DEMOD_UNSYNCD; Demod.len = 0; // number of decoded data bytes Demod.parityLen = 0; @@ -390,16 +380,14 @@ void DemodReset(void) Demod.samples = 0; } -void DemodInit(uint8_t *data, uint8_t *parity) -{ +void DemodInit(uint8_t *data, uint8_t *parity) { Demod.output = data; Demod.parity = parity; DemodReset(); } // use parameter non_real_time to provide a timestamp. Set to 0 if the decoder should measure real time -RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_time) -{ +RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_time) { Demod.twoBits = (Demod.twoBits << 8) | bit; if (Demod.state == DEMOD_UNSYNCD) { @@ -499,8 +487,7 @@ RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_t // near the reader. // "hf 14a sniff" //----------------------------------------------------------------------------- -void RAMFUNC SniffIso14443a(uint8_t param) -{ +void RAMFUNC SniffIso14443a(uint8_t param) { LEDsoff(); // param: // bit 0 - trigger from first card answer @@ -663,8 +650,7 @@ void RAMFUNC SniffIso14443a(uint8_t param) //----------------------------------------------------------------------------- // Prepare tag messages //----------------------------------------------------------------------------- -static void CodeIso14443aAsTagPar(const uint8_t *cmd, uint16_t len, uint8_t *parity, bool collision) -{ +static void CodeIso14443aAsTagPar(const uint8_t *cmd, uint16_t len, uint8_t *parity, bool collision) { //uint8_t localCol = 0; ToSendReset(); @@ -724,19 +710,16 @@ static void CodeIso14443aAsTagPar(const uint8_t *cmd, uint16_t len, uint8_t *par ToSendMax++; } -static void CodeIso14443aAsTagEx(const uint8_t *cmd, uint16_t len, bool collision) -{ +static void CodeIso14443aAsTagEx(const uint8_t *cmd, uint16_t len, bool collision) { uint8_t par[MAX_PARITY_SIZE] = {0}; GetParity(cmd, len, par); CodeIso14443aAsTagPar(cmd, len, par, collision); } -static void CodeIso14443aAsTag(const uint8_t *cmd, uint16_t len) -{ +static void CodeIso14443aAsTag(const uint8_t *cmd, uint16_t len) { CodeIso14443aAsTagEx(cmd, len, false); } -static void Code4bitAnswerAsTag(uint8_t cmd) -{ +static void Code4bitAnswerAsTag(uint8_t cmd) { uint8_t b = cmd; ToSendReset(); @@ -777,8 +760,7 @@ static void Code4bitAnswerAsTag(uint8_t cmd) // stop when button is pressed // or return TRUE when command is captured //----------------------------------------------------------------------------- -int GetIso14443aCommandFromReader(uint8_t *received, uint8_t *parity, int *len) -{ +int GetIso14443aCommandFromReader(uint8_t *received, uint8_t *parity, int *len) { // Set FPGA mode to "simulated ISO 14443 tag", no modulation (listen // only, since we are receiving, not transmitting). // Signal field is off with the appropriate LED @@ -805,8 +787,7 @@ int GetIso14443aCommandFromReader(uint8_t *received, uint8_t *parity, int *len) return false; } -bool prepare_tag_modulation(tag_response_info_t *response_info, size_t max_buffer_size) -{ +bool prepare_tag_modulation(tag_response_info_t *response_info, size_t max_buffer_size) { // Example response, answer to MIFARE Classic read block will be 16 bytes + 2 CRC = 18 bytes // This will need the following byte array for a modulation sequence // 144 data bits (18 * 8) @@ -844,8 +825,7 @@ bool prepare_tag_modulation(tag_response_info_t *response_info, size_t max_buffe // 47 * 8 data bits, 47 * 1 parity bits, 10 start bits, 10 stop bits, 10 correction bits #define ALLOCATED_TAG_MODULATION_BUFFER_SIZE 453 -bool prepare_allocated_tag_modulation(tag_response_info_t *response_info) -{ +bool prepare_allocated_tag_modulation(tag_response_info_t *response_info) { // Retrieve and store the current buffer index response_info->modulation = free_buffer_pointer; @@ -867,8 +847,7 @@ bool prepare_allocated_tag_modulation(tag_response_info_t *response_info) // response to send, and send it. // 'hf 14a sim' //----------------------------------------------------------------------------- -void SimulateIso14443aTag(int tagType, int flags, uint8_t *data) -{ +void SimulateIso14443aTag(int tagType, int flags, uint8_t *data) { #define ATTACK_KEY_COUNT 8 // keep same as define in cmdhfmf.c -> readerAttack() @@ -1437,8 +1416,7 @@ void SimulateIso14443aTag(int tagType, int flags, uint8_t *data) // prepare a delayed transfer. This simply shifts ToSend[] by a number // of bits specified in the delay parameter. -void PrepareDelayedTransfer(uint16_t delay) -{ +void PrepareDelayedTransfer(uint16_t delay) { delay &= 0x07; if (!delay) return; @@ -1469,8 +1447,7 @@ void PrepareDelayedTransfer(uint16_t delay) // if == 0: transfer immediately and return time of transfer // if != 0: delay transfer until time specified //------------------------------------------------------------------------------------- -static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing) -{ +static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing) { FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_MOD); @@ -1516,8 +1493,7 @@ static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing //----------------------------------------------------------------------------- // Prepare reader command (in bits, support short frames) to send to FPGA //----------------------------------------------------------------------------- -void CodeIso14443aBitsAsReaderPar(const uint8_t *cmd, uint16_t bits, const uint8_t *parity) -{ +void CodeIso14443aBitsAsReaderPar(const uint8_t *cmd, uint16_t bits, const uint8_t *parity) { int i, j; int last = 0; uint8_t b; @@ -1596,8 +1572,7 @@ void CodeIso14443aBitsAsReaderPar(const uint8_t *cmd, uint16_t bits, const uint8 //----------------------------------------------------------------------------- // Prepare reader command to send to FPGA //----------------------------------------------------------------------------- -void CodeIso14443aAsReaderPar(const uint8_t *cmd, uint16_t len, const uint8_t *parity) -{ +void CodeIso14443aAsReaderPar(const uint8_t *cmd, uint16_t len, const uint8_t *parity) { CodeIso14443aBitsAsReaderPar(cmd, len * 8, parity); } @@ -1606,8 +1581,7 @@ void CodeIso14443aAsReaderPar(const uint8_t *cmd, uint16_t len, const uint8_t *p // Stop when button is pressed (return 1) or field was gone (return 2) // Or return 0 when command is captured //----------------------------------------------------------------------------- -int EmGetCmd(uint8_t *received, uint16_t *len, uint8_t *parity) -{ +int EmGetCmd(uint8_t *received, uint16_t *len, uint8_t *parity) { *len = 0; uint32_t timer = 0, vtime = 0; @@ -1669,8 +1643,7 @@ int EmGetCmd(uint8_t *received, uint16_t *len, uint8_t *parity) } } -int EmSendCmd14443aRaw(uint8_t *resp, uint16_t respLen) -{ +int EmSendCmd14443aRaw(uint8_t *resp, uint16_t respLen) { volatile uint8_t b; uint16_t i = 0; uint32_t ThisTransferTime; @@ -1736,8 +1709,7 @@ int EmSendCmd14443aRaw(uint8_t *resp, uint16_t respLen) return 0; } -int EmSend4bit(uint8_t resp) -{ +int EmSend4bit(uint8_t resp) { Code4bitAnswerAsTag(resp); int res = EmSendCmd14443aRaw(ToSend, ToSendMax); // do the tracing for the previous reader request and this tag answer: @@ -1755,12 +1727,10 @@ int EmSend4bit(uint8_t resp) par); return res; } -int EmSendCmdPar(uint8_t *resp, uint16_t respLen, uint8_t *par) -{ +int EmSendCmdPar(uint8_t *resp, uint16_t respLen, uint8_t *par) { return EmSendCmdParEx(resp, respLen, par, false); } -int EmSendCmdParEx(uint8_t *resp, uint16_t respLen, uint8_t *par, bool collision) -{ +int EmSendCmdParEx(uint8_t *resp, uint16_t respLen, uint8_t *par, bool collision) { CodeIso14443aAsTagPar(resp, respLen, par, collision); int res = EmSendCmd14443aRaw(ToSend, ToSendMax); // do the tracing for the previous reader request and this tag answer: @@ -1776,20 +1746,17 @@ int EmSendCmdParEx(uint8_t *resp, uint16_t respLen, uint8_t *par, bool collision par); return res; } -int EmSendCmd(uint8_t *resp, uint16_t respLen) -{ +int EmSendCmd(uint8_t *resp, uint16_t respLen) { return EmSendCmdEx(resp, respLen, false); } -int EmSendCmdEx(uint8_t *resp, uint16_t respLen, bool collision) -{ +int EmSendCmdEx(uint8_t *resp, uint16_t respLen, bool collision) { uint8_t par[MAX_PARITY_SIZE] = {0x00}; GetParity(resp, respLen, par); return EmSendCmdParEx(resp, respLen, par, collision); } bool EmLogTrace(uint8_t *reader_data, uint16_t reader_len, uint32_t reader_StartTime, uint32_t reader_EndTime, uint8_t *reader_Parity, - uint8_t *tag_data, uint16_t tag_len, uint32_t tag_StartTime, uint32_t tag_EndTime, uint8_t *tag_Parity) -{ + uint8_t *tag_data, uint16_t tag_len, uint32_t tag_StartTime, uint32_t tag_EndTime, uint8_t *tag_Parity) { // we cannot exactly measure the end and start of a received command from reader. However we know that the delay from // end of the received command to start of the tag's (simulated by us) answer is n*128+20 or n*128+84 resp. // with n >= 9. The start of the tags answer can be measured and therefore the end of the received command be calculated: @@ -1811,8 +1778,7 @@ bool EmLogTrace(uint8_t *reader_data, uint16_t reader_len, uint32_t reader_Start // If a response is captured return TRUE // If it takes too long return FALSE //----------------------------------------------------------------------------- -static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, uint8_t *receivedResponsePar, uint16_t offset) -{ +static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, uint8_t *receivedResponsePar, uint16_t offset) { uint32_t c = 0; // Set FPGA mode to "reader listen mode", no modulation (listen @@ -1843,8 +1809,7 @@ static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, uint8_t *receive } } -void ReaderTransmitBitsPar(uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t *timing) -{ +void ReaderTransmitBitsPar(uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t *timing) { CodeIso14443aBitsAsReaderPar(frame, bits, par); // Send command to tag @@ -1854,37 +1819,32 @@ void ReaderTransmitBitsPar(uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t LogTrace(frame, nbytes(bits), (LastTimeProxToAirStart << 4) + DELAY_ARM2AIR_AS_READER, ((LastTimeProxToAirStart + LastProxToAirDuration) << 4) + DELAY_ARM2AIR_AS_READER, par, true); } -void ReaderTransmitPar(uint8_t *frame, uint16_t len, uint8_t *par, uint32_t *timing) -{ +void ReaderTransmitPar(uint8_t *frame, uint16_t len, uint8_t *par, uint32_t *timing) { ReaderTransmitBitsPar(frame, len * 8, par, timing); } -void ReaderTransmitBits(uint8_t *frame, uint16_t len, uint32_t *timing) -{ +void ReaderTransmitBits(uint8_t *frame, uint16_t len, uint32_t *timing) { // Generate parity and redirect uint8_t par[MAX_PARITY_SIZE] = {0x00}; GetParity(frame, len / 8, par); ReaderTransmitBitsPar(frame, len, par, timing); } -void ReaderTransmit(uint8_t *frame, uint16_t len, uint32_t *timing) -{ +void ReaderTransmit(uint8_t *frame, uint16_t len, uint32_t *timing) { // Generate parity and redirect uint8_t par[MAX_PARITY_SIZE] = {0x00}; GetParity(frame, len, par); ReaderTransmitBitsPar(frame, len * 8, par, timing); } -int ReaderReceiveOffset(uint8_t *receivedAnswer, uint16_t offset, uint8_t *parity) -{ +int ReaderReceiveOffset(uint8_t *receivedAnswer, uint16_t offset, uint8_t *parity) { if (!GetIso14443aAnswerFromTag(receivedAnswer, parity, offset)) return false; LogTrace(receivedAnswer, Demod.len, Demod.startTime * 16 - DELAY_AIR2ARM_AS_READER, Demod.endTime * 16 - DELAY_AIR2ARM_AS_READER, parity, false); return Demod.len; } -int ReaderReceive(uint8_t *receivedAnswer, uint8_t *parity) -{ +int ReaderReceive(uint8_t *receivedAnswer, uint8_t *parity) { if (!GetIso14443aAnswerFromTag(receivedAnswer, parity, 0)) return false; LogTrace(receivedAnswer, Demod.len, Demod.startTime * 16 - DELAY_AIR2ARM_AS_READER, Demod.endTime * 16 - DELAY_AIR2ARM_AS_READER, parity, false); @@ -1894,8 +1854,7 @@ int ReaderReceive(uint8_t *receivedAnswer, uint8_t *parity) // This function misstreats the ISO 14443a anticollision procedure. // by fooling the reader there is a collision and forceing the reader to // increase the uid bytes. The might be an overflow, DoS will occure. -void iso14443a_antifuzz(uint32_t flags) -{ +void iso14443a_antifuzz(uint32_t flags) { // We need to listen to the high-frequency, peak-detected path. iso14443a_setup(FPGA_HF_ISO14443A_TAGSIM_LISTEN); @@ -1968,8 +1927,7 @@ void iso14443a_antifuzz(uint32_t flags) BigBuf_free_keep_EM(); } -static void iso14a_set_ATS_times(uint8_t *ats) -{ +static void iso14a_set_ATS_times(uint8_t *ats) { uint8_t tb1; uint8_t fwi, sfgi; @@ -1996,8 +1954,7 @@ static void iso14a_set_ATS_times(uint8_t *ats) } } -static int GetATQA(uint8_t *resp, uint8_t *resp_par) -{ +static int GetATQA(uint8_t *resp, uint8_t *resp_par) { #define WUPA_RETRY_TIMEOUT 10 // 10ms uint8_t wupa[] = { ISO14443A_CMD_WUPA }; // 0x26 - REQA 0x52 - WAKE-UP @@ -2026,8 +1983,7 @@ static int GetATQA(uint8_t *resp, uint8_t *resp_par) // if anticollision is false, then the UID must be provided in uid_ptr[] // and num_cascades must be set (1: 4 Byte UID, 2: 7 Byte UID, 3: 10 Byte UID) // requests ATS unless no_rats is true -int iso14443a_select_card(byte_t *uid_ptr, iso14a_card_select_t *p_card, uint32_t *cuid_ptr, bool anticollision, uint8_t num_cascades, bool no_rats) -{ +int iso14443a_select_card(byte_t *uid_ptr, iso14a_card_select_t *p_card, uint32_t *cuid_ptr, bool anticollision, uint8_t num_cascades, bool no_rats) { uint8_t sel_all[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x20 }; uint8_t sel_uid[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; @@ -2184,8 +2140,7 @@ int iso14443a_select_card(byte_t *uid_ptr, iso14a_card_select_t *p_card, uint32_ return 1; } -int iso14443a_fast_select_card(uint8_t *uid_ptr, uint8_t num_cascades) -{ +int iso14443a_fast_select_card(uint8_t *uid_ptr, uint8_t num_cascades) { uint8_t sel_all[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x20 }; uint8_t sel_uid[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; uint8_t resp[5] = {0}; // theoretically. A usual RATS will be much smaller @@ -2237,8 +2192,7 @@ int iso14443a_fast_select_card(uint8_t *uid_ptr, uint8_t num_cascades) return 1; } -void iso14443a_setup(uint8_t fpga_minor_mode) -{ +void iso14443a_setup(uint8_t fpga_minor_mode) { FpgaDownloadAndGo(FPGA_BITSTREAM_HF); // Set up the synchronous serial port @@ -2249,7 +2203,7 @@ void iso14443a_setup(uint8_t fpga_minor_mode) LED_D_OFF(); // Signal field is on with the appropriate LED if (fpga_minor_mode == FPGA_HF_ISO14443A_READER_MOD || - fpga_minor_mode == FPGA_HF_ISO14443A_READER_LISTEN) + fpga_minor_mode == FPGA_HF_ISO14443A_READER_LISTEN) LED_D_ON(); FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | fpga_minor_mode); @@ -2289,8 +2243,7 @@ b8 b7 b6 b5 b4 b3 b2 b1 b5,b6 = 00 - DESELECT 11 - WTX */ -int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, uint8_t *res) -{ +int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, uint8_t *res) { uint8_t parity[MAX_PARITY_SIZE] = {0x00}; uint8_t real_cmd[cmd_len + 4]; @@ -2340,9 +2293,9 @@ int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, u // if we received an I- or R(ACK)-Block with a block number equal to the // current block number, toggle the current block number if (len >= 3 // PCB+CRC = 3 bytes - && ((data_bytes[0] & 0xC0) == 0 // I-Block - || (data_bytes[0] & 0xD0) == 0x80) // R-Block with ACK bit set to 0 - && (data_bytes[0] & 0x01) == iso14_pcb_blocknum) { // equal block numbers + && ((data_bytes[0] & 0xC0) == 0 // I-Block + || (data_bytes[0] & 0xD0) == 0x80) // R-Block with ACK bit set to 0 + && (data_bytes[0] & 0x01) == iso14_pcb_blocknum) { // equal block numbers iso14_pcb_blocknum ^= 1; } @@ -2376,8 +2329,7 @@ int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, u // low :: len of commandbytes // arg2 timeout // d.asBytes command bytes to send -void ReaderIso14443a(UsbCommand *c) -{ +void ReaderIso14443a(UsbCommand *c) { iso14a_command_t param = c->arg[0]; size_t len = c->arg[1] & 0xffff; size_t lenbits = c->arg[1] >> 16; @@ -2477,8 +2429,7 @@ OUT: // Determine the distance between two nonces. // Assume that the difference is small, but we don't know which is first. // Therefore try in alternating directions. -int32_t dist_nt(uint32_t nt1, uint32_t nt2) -{ +int32_t dist_nt(uint32_t nt1, uint32_t nt2) { if (nt1 == nt2) return 0; @@ -2507,8 +2458,7 @@ int32_t dist_nt(uint32_t nt1, uint32_t nt2) // Cloning MiFare Classic Rail and Building Passes, Anywhere, Anytime" // (article by Nicolas T. Courtois, 2009) //----------------------------------------------------------------------------- -void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) -{ +void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) { iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD); @@ -2777,8 +2727,7 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) * Mifare Classic NACK-bug detection * Thanks to @doegox for the feedback and new approaches. */ -void DetectNACKbug() -{ +void DetectNACKbug() { uint8_t mf_auth[] = {0x60, 0x00, 0xF5, 0x7B}; uint8_t mf_nr_ar[] = {0, 0, 0, 0, 0, 0, 0, 0}; uint8_t uid[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -3013,8 +2962,7 @@ void DetectNACKbug() *@param exitAfterNReads, exit simulation after n blocks have been read, 0 is inifite * (unless reader attack mode enabled then it runs util it gets enough nonces to recover all keys attmpted) */ -void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *datain) -{ +void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *datain) { int cardSTATE = MFEMUL_NOFIELD; int _UID_LEN = 0; // 4, 7, 10 @@ -3217,9 +3165,9 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t * } // select card if (len == 9 && - (receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT && - receivedCmd[1] == 0x70 && - memcmp(&receivedCmd[2], rUIDBCC1, 4) == 0)) { + (receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT && + receivedCmd[1] == 0x70 && + memcmp(&receivedCmd[2], rUIDBCC1, 4) == 0)) { // SAK 4b EmSendCmd(sak_4, sizeof(sak_4)); @@ -3251,9 +3199,9 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t * break; } if (len == 9 && - (receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2 && - receivedCmd[1] == 0x70 && - memcmp(&receivedCmd[2], rUIDBCC2, 4) == 0)) { + (receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2 && + receivedCmd[1] == 0x70 && + memcmp(&receivedCmd[2], rUIDBCC2, 4) == 0)) { EmSendCmd(sak_7, sizeof(sak_7)); switch (_UID_LEN) { @@ -3282,9 +3230,9 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t * break; } if (len == 9 && - (receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_3 && - receivedCmd[1] == 0x70 && - memcmp(&receivedCmd[2], rUIDBCC3, 4) == 0)) { + (receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_3 && + receivedCmd[1] == 0x70 && + memcmp(&receivedCmd[2], rUIDBCC3, 4) == 0)) { EmSendCmd(sak_10, sizeof(sak_10)); cardSTATE = MFEMUL_WORK; @@ -3459,11 +3407,11 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t * } if (receivedCmd[0] == ISO14443A_CMD_READBLOCK || - receivedCmd[0] == ISO14443A_CMD_WRITEBLOCK || - receivedCmd[0] == MIFARE_CMD_INC || - receivedCmd[0] == MIFARE_CMD_DEC || - receivedCmd[0] == MIFARE_CMD_RESTORE || - receivedCmd[0] == MIFARE_CMD_TRANSFER) { + receivedCmd[0] == ISO14443A_CMD_WRITEBLOCK || + receivedCmd[0] == MIFARE_CMD_INC || + receivedCmd[0] == MIFARE_CMD_DEC || + receivedCmd[0] == MIFARE_CMD_RESTORE || + receivedCmd[0] == MIFARE_CMD_TRANSFER) { if (receivedCmd[1] >= 16 * 4) { EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA)); @@ -3502,8 +3450,8 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t * } // increment, decrement, restore if (receivedCmd[0] == MIFARE_CMD_INC || - receivedCmd[0] == MIFARE_CMD_DEC || - receivedCmd[0] == MIFARE_CMD_RESTORE) { + receivedCmd[0] == MIFARE_CMD_DEC || + receivedCmd[0] == MIFARE_CMD_RESTORE) { if (MF_DBGLEVEL >= 4) Dbprintf("RECV 0x%02x inc(0xC1)/dec(0xC0)/restore(0xC2) block %d (%02x)", receivedCmd[0], receivedCmd[1], receivedCmd[1]); diff --git a/armsrc/iso14443b.c b/armsrc/iso14443b.c index 5041d9b3f..5b6a85477 100644 --- a/armsrc/iso14443b.c +++ b/armsrc/iso14443b.c @@ -77,8 +77,7 @@ static struct { uint8_t *output; } Uart; -static void UartReset() -{ +static void UartReset() { Uart.state = STATE_UNSYNCD; Uart.shiftReg = 0; Uart.bitCnt = 0; @@ -87,8 +86,7 @@ static void UartReset() Uart.posCnt = 0; } -static void UartInit(uint8_t *data) -{ +static void UartInit(uint8_t *data) { Uart.output = data; UartReset(); // memset(Uart.output, 0x00, MAX_FRAME_SIZE); @@ -122,8 +120,7 @@ static struct { } Demod; // Clear out the state of the "UART" that receives from the tag. -static void DemodReset() -{ +static void DemodReset() { Demod.state = DEMOD_UNSYNCD; Demod.bitCount = 0; Demod.posCount = 0; @@ -136,8 +133,7 @@ static void DemodReset() Demod.endTime = 0; } -static void DemodInit(uint8_t *data) -{ +static void DemodInit(uint8_t *data) { Demod.output = data; DemodReset(); // memset(Demod.output, 0x00, MAX_FRAME_SIZE); @@ -157,8 +153,7 @@ static void DemodInit(uint8_t *data) * 13560000000 / 384000 = 35312 FWT * @param timeout is in frame wait time, fwt, measured in ETUs */ -static void iso14b_set_timeout(uint32_t timeout) -{ +static void iso14b_set_timeout(uint32_t timeout) { #define MAX_TIMEOUT 40542464 // 13560000Hz * 1000ms / (2^32-1) * (8*16) if (timeout > MAX_TIMEOUT) timeout = MAX_TIMEOUT; @@ -166,8 +161,7 @@ static void iso14b_set_timeout(uint32_t timeout) iso14b_timeout = timeout; if (MF_DBGLEVEL >= 3) Dbprintf("ISO14443B Timeout set to %ld fwt", iso14b_timeout); } -static void iso14b_set_maxframesize(uint16_t size) -{ +static void iso14b_set_maxframesize(uint16_t size) { if (size > 256) size = MAX_FRAME_SIZE; @@ -180,8 +174,7 @@ static void iso14b_set_maxframesize(uint16_t size) // that here) so that they can be transmitted to the reader. Doesn't transmit // them yet, just leaves them ready to send in ToSend[]. //----------------------------------------------------------------------------- -static void CodeIso14443bAsTag(const uint8_t *cmd, int len) -{ +static void CodeIso14443bAsTag(const uint8_t *cmd, int len) { /* ISO 14443 B * * Reader to card | ASK - Amplitude Shift Keying Modulation (PCD to PICC for Type B) (NRZ-L encodig) @@ -323,8 +316,7 @@ static void CodeIso14443bAsTag(const uint8_t *cmd, int len) * Returns: true if we received a EOF * false if we are still waiting for some more */ -static RAMFUNC int Handle14443bReaderUartBit(uint8_t bit) -{ +static RAMFUNC int Handle14443bReaderUartBit(uint8_t bit) { switch (Uart.state) { case STATE_UNSYNCD: if (!bit) { @@ -440,8 +432,7 @@ static RAMFUNC int Handle14443bReaderUartBit(uint8_t bit) // Assume that we're called with the SSC (to the FPGA) and ADC path set // correctly. //----------------------------------------------------------------------------- -static int GetIso14443bCommandFromReader(uint8_t *received, uint16_t *len) -{ +static int GetIso14443bCommandFromReader(uint8_t *received, uint16_t *len) { // Set FPGA mode to "simulated ISO 14443B tag", no modulation (listen // only, since we are receiving, not transmitting). // Signal field is off with the appropriate LED @@ -493,8 +484,7 @@ static int GetIso14443bCommandFromReader(uint8_t *received, uint16_t *len) return false; } -void ClearFpgaShiftingRegisters(void) -{ +void ClearFpgaShiftingRegisters(void) { volatile uint8_t b; @@ -519,8 +509,7 @@ void ClearFpgaShiftingRegisters(void) //AT91C_BASE_SSC->SSC_THR = 0xFF; } -void WaitForFpgaDelayQueueIsEmpty(uint16_t delay) -{ +void WaitForFpgaDelayQueueIsEmpty(uint16_t delay) { // Ensure that the FPGA Delay Queue is empty before we switch to TAGSIM_LISTEN again: uint8_t fpga_queued_bits = delay >> 3; // twich /8 ?? >>3, for (uint8_t i = 0; i <= fpga_queued_bits / 8 + 1;) { @@ -531,8 +520,7 @@ void WaitForFpgaDelayQueueIsEmpty(uint16_t delay) } } -static void TransmitFor14443b_AsTag(uint8_t *response, uint16_t len) -{ +static void TransmitFor14443b_AsTag(uint8_t *response, uint16_t len) { volatile uint32_t b; @@ -570,8 +558,7 @@ static void TransmitFor14443b_AsTag(uint8_t *response, uint16_t len) // Main loop of simulated tag: receive commands from reader, decide what // response to send, and send it. //----------------------------------------------------------------------------- -void SimulateIso14443bTag(uint32_t pupi) -{ +void SimulateIso14443bTag(uint32_t pupi) { // setup device. FpgaDownloadAndGo(FPGA_BITSTREAM_HF); @@ -656,7 +643,7 @@ void SimulateIso14443bTag(uint32_t pupi) // WUP in HALTED state if (len == 5) { if ((receivedCmd[0] == ISO14443B_REQB && (receivedCmd[2] & 0x8) == 0x8 && cardSTATE == SIM_HALTED) || - receivedCmd[0] == ISO14443B_REQB) { + receivedCmd[0] == ISO14443B_REQB) { LogTrace(receivedCmd, len, 0, 0, NULL, true); cardSTATE = SIM_SELECTING; } @@ -753,8 +740,7 @@ void SimulateIso14443bTag(uint32_t pupi) * false if we are still waiting for some more * */ -static RAMFUNC int Handle14443bTagSamplesDemod(int ci, int cq) -{ +static RAMFUNC int Handle14443bTagSamplesDemod(int ci, int cq) { int v = 0, myI = ABS(ci), myQ = ABS(cq); // The soft decision on the bit uses an estimate of just the @@ -958,8 +944,7 @@ static RAMFUNC int Handle14443bTagSamplesDemod(int ci, int cq) * Demodulate the samples we received from the tag, also log to tracebuffer * quiet: set to 'TRUE' to disable debug output */ -static void GetTagSamplesFor14443bDemod() -{ +static void GetTagSamplesFor14443bDemod() { bool gotFrame = false, finished = false; int lastRxCounter = ISO14443B_DMA_BUFFER_SIZE; int ci = 0, cq = 0; @@ -1025,8 +1010,7 @@ static void GetTagSamplesFor14443bDemod() //----------------------------------------------------------------------------- // Transmit the command (to the tag) that was placed in ToSend[]. //----------------------------------------------------------------------------- -static void TransmitFor14443b_AsReader(void) -{ +static void TransmitFor14443b_AsReader(void) { int c; FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX | FPGA_HF_READER_TX_SHALLOW_MOD); @@ -1060,8 +1044,7 @@ static void TransmitFor14443b_AsReader(void) // Code a layer 2 command (string of octets, including CRC) into ToSend[], // so that it is ready to transmit to the tag using TransmitFor14443b(). //----------------------------------------------------------------------------- -static void CodeIso14443bAsReader(const uint8_t *cmd, int len) -{ +static void CodeIso14443bAsReader(const uint8_t *cmd, int len) { /* * Reader data transmission: * - no modulation ONES @@ -1142,8 +1125,7 @@ static void CodeIso14443bAsReader(const uint8_t *cmd, int len) /* * Convenience function to encode, transmit and trace iso 14443b comms */ -static void CodeAndTransmit14443bAsReader(const uint8_t *cmd, int len) -{ +static void CodeAndTransmit14443bAsReader(const uint8_t *cmd, int len) { uint32_t time_start = GetCountSspClk(); @@ -1159,8 +1141,7 @@ static void CodeAndTransmit14443bAsReader(const uint8_t *cmd, int len) /* Sends an APDU to the tag * TODO: check CRC and preamble */ -uint8_t iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *response) -{ +uint8_t iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *response) { uint8_t message_frame[message_length + 4]; // PCB @@ -1194,8 +1175,7 @@ uint8_t iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *r /** * SRx Initialise. */ -uint8_t iso14443b_select_srx_card(iso14b_card_select_t *card) -{ +uint8_t iso14443b_select_srx_card(iso14b_card_select_t *card) { // INITIATE command: wake up the tag using the INITIATE static const uint8_t init_srx[] = { ISO14443B_INITIATE, 0x00, 0x97, 0x5b }; // SELECT command (with space for CRC) @@ -1255,8 +1235,7 @@ uint8_t iso14443b_select_srx_card(iso14b_card_select_t *card) * TODO: Support multiple cards (perform anticollision) * TODO: Verify CRC checksums */ -uint8_t iso14443b_select_card(iso14b_card_select_t *card) -{ +uint8_t iso14443b_select_card(iso14b_card_select_t *card) { // WUPB command (including CRC) // Note: WUPB wakes up all tags, REQB doesn't wake up tags in HALT state static const uint8_t wupb[] = { ISO14443B_REQB, 0x00, 0x08, 0x39, 0x73 }; @@ -1328,8 +1307,7 @@ uint8_t iso14443b_select_card(iso14b_card_select_t *card) // Set up ISO 14443 Type B communication (similar to iso14443a_setup) // field is setup for "Sending as Reader" -void iso14443b_setup() -{ +void iso14443b_setup() { LEDsoff(); FpgaDownloadAndGo(FPGA_BITSTREAM_HF); @@ -1362,8 +1340,7 @@ void iso14443b_setup() // // I tried to be systematic and check every answer of the tag, every CRC, etc... //----------------------------------------------------------------------------- -static bool ReadSTBlock(uint8_t block) -{ +static bool ReadSTBlock(uint8_t block) { uint8_t cmd[] = {ISO14443B_READ_BLK, block, 0x00, 0x00}; AddCrc14B(cmd, 2); CodeAndTransmit14443bAsReader(cmd, sizeof(cmd)); @@ -1381,8 +1358,7 @@ static bool ReadSTBlock(uint8_t block) } return true; } -void ReadSTMemoryIso14443b(uint8_t numofblocks) -{ +void ReadSTMemoryIso14443b(uint8_t numofblocks) { // Make sure that we start from off, since the tags are stateful; // confusing things will happen if we don't reset them between reads. //switch_off(); @@ -1431,8 +1407,7 @@ out: SpinDelay(20); } -static void iso1444b_setup_sniff(void) -{ +static void iso1444b_setup_sniff(void) { LEDsoff(); FpgaDownloadAndGo(FPGA_BITSTREAM_HF); @@ -1485,8 +1460,7 @@ static void iso1444b_setup_sniff(void) * DMA Buffer - ISO14443B_DMA_BUFFER_SIZE * Demodulated samples received - all the rest */ -void RAMFUNC SniffIso14443b(void) -{ +void RAMFUNC SniffIso14443b(void) { uint32_t time_0 = 0, time_start = 0, time_stop = 0; int ci = 0, cq = 0; @@ -1578,8 +1552,7 @@ void RAMFUNC SniffIso14443b(void) switch_off(); } -void iso14b_set_trigger(bool enable) -{ +void iso14b_set_trigger(bool enable) { trigger = enable; } @@ -1594,8 +1567,7 @@ void iso14b_set_trigger(bool enable) * none * */ -void SendRawCommand14443B_Ex(UsbCommand *c) -{ +void SendRawCommand14443B_Ex(UsbCommand *c) { iso14b_command_t param = c->arg[0]; size_t len = c->arg[1] & 0xffff; uint8_t *cmd = c->d.asBytes; diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index 5702ddcac..b6d53ccea 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -99,8 +99,7 @@ static void BuildInventoryResponse(uint8_t *cmdout, uint8_t *uid); // resulting data rate is 26,48 kbit/s (fc/512) // cmd ... data // n ... length of data -static void CodeIso15693AsReader(uint8_t *cmd, int n) -{ +static void CodeIso15693AsReader(uint8_t *cmd, int n) { int i, j; ToSendReset(); @@ -179,8 +178,7 @@ static void CodeIso15693AsReader(uint8_t *cmd, int n) // encode data using "1 out of 256" sheme // data rate is 1,66 kbit/s (fc/8192) // is designed for more robust communication over longer distances -static void CodeIso15693AsReader256(uint8_t *cmd, int n) -{ +static void CodeIso15693AsReader256(uint8_t *cmd, int n) { int i, j; ToSendReset(); @@ -222,8 +220,7 @@ static void CodeIso15693AsReader256(uint8_t *cmd, int n) } // Transmit the command (to the tag) that was placed in ToSend[]. -static void TransmitTo15693Tag(const uint8_t *cmd, int len, int *samples, int *wait) -{ +static void TransmitTo15693Tag(const uint8_t *cmd, int len, int *samples, int *wait) { int c; FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX); @@ -258,8 +255,7 @@ static void TransmitTo15693Tag(const uint8_t *cmd, int len, int *samples, int *w //----------------------------------------------------------------------------- // Transmit the command (to the reader) that was placed in ToSend[]. //----------------------------------------------------------------------------- -static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int *wait) -{ +static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int *wait) { int c = 0; FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR | FPGA_HF_SIMULATOR_MODULATE_424K); @@ -292,8 +288,7 @@ static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int //----------------------------------------------------------------------------- // DEMODULATE tag answer //----------------------------------------------------------------------------- -static int DemodAnswer(uint8_t *received, uint8_t *dest, uint16_t samplecount) -{ +static int DemodAnswer(uint8_t *received, uint8_t *dest, uint16_t samplecount) { int i, j; int max = 0, maxPos = 0, skip = 4; @@ -386,8 +381,7 @@ static int DemodAnswer(uint8_t *received, uint8_t *dest, uint16_t samplecount) // returns: // number of decoded bytes // logging enabled -static int GetIso15693AnswerFromTag(uint8_t *received, int *elapsed) -{ +static int GetIso15693AnswerFromTag(uint8_t *received, int *elapsed) { #define SIGNAL_BUFF_SIZE 15000 // get current clock @@ -441,8 +435,7 @@ static int GetIso15693AnswerFromTag(uint8_t *received, int *elapsed) // Now the GetISO15693 message from sniffing command // logging enable, -static int GetIso15693AnswerFromSniff(uint8_t *received, int *samples, int *elapsed) -{ +static int GetIso15693AnswerFromSniff(uint8_t *received, int *samples, int *elapsed) { bool getNext = false; int counter = 0, ci = 0, cq = 0; @@ -490,8 +483,7 @@ static int GetIso15693AnswerFromSniff(uint8_t *received, int *samples, int *elap // for the response. The response is not demodulated, just left in the buffer // so that it can be downloaded to a PC and processed there. //----------------------------------------------------------------------------- -void AcquireRawAdcSamplesIso15693(void) -{ +void AcquireRawAdcSamplesIso15693(void) { int c = 0, getNext = false; int ci = 0, cq = 0; @@ -557,8 +549,7 @@ void AcquireRawAdcSamplesIso15693(void) } // switch_off, initreader, no logging -void RecordRawAdcSamplesIso15693(void) -{ +void RecordRawAdcSamplesIso15693(void) { int c = 0, getNext = false; int ci = 0, cq = 0; @@ -598,8 +589,7 @@ void RecordRawAdcSamplesIso15693(void) // Initialize the proxmark as iso15k reader // (this might produces glitches that confuse some tags -void Iso15693InitReader(void) -{ +void Iso15693InitReader(void) { LEDsoff(); clear_trace(); set_tracing(true); @@ -631,8 +621,7 @@ void Iso15693InitReader(void) // Encode (into the ToSend buffers) an identify request, which is the first // thing that you must send to a tag to get a response. -static void BuildIdentifyRequest(uint8_t *out) -{ +static void BuildIdentifyRequest(uint8_t *out) { uint8_t cmd[CMD_ID_RESP] = {0, ISO15_CMD_INVENTORY, 0, 0, 0}; // flags @@ -676,8 +665,7 @@ static void BuildReadBlockRequest(uint8_t **out, uint8_t *uid, uint8_t blockNumb */ // Now the VICC>VCD responses when we are simulating a tag -static void BuildInventoryResponse(uint8_t *out, uint8_t *uid) -{ +static void BuildInventoryResponse(uint8_t *out, uint8_t *uid) { uint8_t cmd[CMD_INV_RESP] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -708,8 +696,7 @@ static void BuildInventoryResponse(uint8_t *out, uint8_t *uid) // If you do not need the answer use NULL for *recv[] // return: lenght of received data // logging enabled -int SendDataTag(uint8_t *send, int sendlen, bool init, int speed, uint8_t *outdata) -{ +int SendDataTag(uint8_t *send, int sendlen, bool init, int speed, uint8_t *outdata) { int t_samples = 0, wait = 0, elapsed = 0, answer_len = 0; @@ -747,8 +734,7 @@ int SendDataTag(uint8_t *send, int sendlen, bool init, int speed, uint8_t *outda // Decodes a message from a tag and displays its metadata and content #define DBD15STATLEN 48 -void DbdecodeIso15693Answer(int len, uint8_t *d) -{ +void DbdecodeIso15693Answer(int len, uint8_t *d) { char status[DBD15STATLEN + 1] = {0}; if (len > 3) { @@ -812,8 +798,7 @@ void DbdecodeIso15693Answer(int len, uint8_t *d) //----------------------------------------------------------------------------- // ok // parameter is unused !?! -void ReaderIso15693(uint32_t parameter) -{ +void ReaderIso15693(uint32_t parameter) { int answerLen1 = 0; int tsamples = 0, wait = 0, elapsed = 0; @@ -877,8 +862,7 @@ void ReaderIso15693(uint32_t parameter) // Simulate an ISO15693 TAG, perform anti-collision and then print any reader commands // all demodulation performed in arm rather than host. - greg -void SimTagIso15693(uint32_t parameter, uint8_t *uid) -{ +void SimTagIso15693(uint32_t parameter, uint8_t *uid) { LEDsoff(); FpgaDownloadAndGo(FPGA_BITSTREAM_HF); @@ -932,8 +916,7 @@ void SimTagIso15693(uint32_t parameter, uint8_t *uid) // Since there is no standardized way of reading the AFI out of a tag, we will brute force it // (some manufactures offer a way to read the AFI, though) -void BruteforceIso15693Afi(uint32_t speed) -{ +void BruteforceIso15693Afi(uint32_t speed) { uint8_t data[7] = {0, 0, 0, 0, 0, 0, 0}; uint8_t buf[ISO15_MAX_FRAME]; @@ -987,8 +970,7 @@ void BruteforceIso15693Afi(uint32_t speed) // Allows to directly send commands to the tag via the client // Has to increase dialog between device and client. -void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint8_t *data) -{ +void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint8_t *data) { bool init = true; int buflen = 0; diff --git a/armsrc/legicrf.c b/armsrc/legicrf.c index eef626ff7..6a2cccd7c 100644 --- a/armsrc/legicrf.c +++ b/armsrc/legicrf.c @@ -56,8 +56,7 @@ static uint32_t last_frame_end; /* ts of last bit of previews rx or tx frame */ // I/O interface abstraction (FPGA -> ARM) //----------------------------------------------------------------------------- -static inline uint8_t rx_byte_from_fpga() -{ +static inline uint8_t rx_byte_from_fpga() { for (;;) { WDT_HIT(); @@ -84,8 +83,7 @@ static inline uint8_t rx_byte_from_fpga() // // Note: The SSC receiver is never synchronized the calculation may be performed // on a i/q pair from two subsequent correlations, but does not matter. -static inline int32_t sample_power() -{ +static inline int32_t sample_power() { int32_t q = (int8_t)rx_byte_from_fpga(); q = ABS(q); int32_t i = (int8_t)rx_byte_from_fpga(); @@ -101,8 +99,7 @@ static inline int32_t sample_power() // // Note: The demodulator would be drifting (18.9us * 5 != 100us), rx_frame // has a delay loop that aligns rx_bit calls to the TAG tx timeslots. -static inline bool rx_bit() -{ +static inline bool rx_bit() { int32_t power; for (size_t i = 0; i < 5; ++i) { @@ -121,8 +118,7 @@ static inline bool rx_bit() // be circumvented, but the adventage over bitbang would be little. //----------------------------------------------------------------------------- -static inline void tx_bit(bool bit) -{ +static inline void tx_bit(bool bit) { // insert pause LOW(GPIO_SSC_DOUT); last_frame_end += RWD_TIME_PAUSE; @@ -144,8 +140,7 @@ static inline void tx_bit(bool bit) // present. //----------------------------------------------------------------------------- -static void tx_frame(uint32_t frame, uint8_t len) -{ +static void tx_frame(uint32_t frame, uint8_t len) { FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX); // wait for next tx timeslot @@ -173,8 +168,7 @@ static void tx_frame(uint32_t frame, uint8_t len) LogTrace(cmdbytes, sizeof(cmdbytes), last_frame_start, last_frame_end, NULL, true); } -static uint32_t rx_frame(uint8_t len) -{ +static uint32_t rx_frame(uint8_t len) { FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR | FPGA_HF_READER_RX_XCORR_848_KHZ | FPGA_HF_READER_RX_XCORR_QUARTER); @@ -203,8 +197,7 @@ static uint32_t rx_frame(uint8_t len) return frame; } -static bool rx_ack() -{ +static bool rx_ack() { // change fpga into rx mode FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR | FPGA_HF_READER_RX_XCORR_848_KHZ @@ -244,8 +237,7 @@ static bool rx_ack() // Legic Reader //----------------------------------------------------------------------------- -static int init_card(uint8_t cardtype, legic_card_select_t *p_card) -{ +static int init_card(uint8_t cardtype, legic_card_select_t *p_card) { p_card->tagtype = cardtype; switch (p_card->tagtype) { @@ -273,8 +265,7 @@ static int init_card(uint8_t cardtype, legic_card_select_t *p_card) return 0; } -static void init_reader(bool clear_mem) -{ +static void init_reader(bool clear_mem) { // configure FPGA FpgaDownloadAndGo(FPGA_BITSTREAM_HF); FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR @@ -314,8 +305,7 @@ static void init_reader(bool clear_mem) // - Transmit initialisation vector 7 bits // - Receive card type 6 bits // - Transmit Acknowledge 6 bits -static uint32_t setup_phase(uint8_t iv) -{ +static uint32_t setup_phase(uint8_t iv) { // init coordination timestamp last_frame_end = GET_TICKS; @@ -348,15 +338,13 @@ static uint32_t setup_phase(uint8_t iv) return card_type; } -static uint8_t calc_crc4(uint16_t cmd, uint8_t cmd_sz, uint8_t value) -{ +static uint8_t calc_crc4(uint16_t cmd, uint8_t cmd_sz, uint8_t value) { crc_clear(&legic_crc); crc_update(&legic_crc, (value << cmd_sz) | cmd, 8 + cmd_sz); return crc_finish(&legic_crc); } -static int16_t read_byte(uint16_t index, uint8_t cmd_sz) -{ +static int16_t read_byte(uint16_t index, uint8_t cmd_sz) { uint16_t cmd = (index << 1) | LEGIC_READ; // read one byte @@ -385,8 +373,7 @@ static int16_t read_byte(uint16_t index, uint8_t cmd_sz) // Transmit write command, wait until (3.6ms) the tag sends back an unencrypted // ACK ('1' bit) and forward the prng time based. -bool write_byte(uint16_t index, uint8_t byte, uint8_t addr_sz) -{ +bool write_byte(uint16_t index, uint8_t byte, uint8_t addr_sz) { uint32_t cmd = index << 1 | LEGIC_WRITE; // prepare command uint8_t crc = calc_crc4(cmd, addr_sz + 1, byte); // calculate crc cmd |= byte << (addr_sz + 1); // append value @@ -408,8 +395,7 @@ bool write_byte(uint16_t index, uint8_t byte, uint8_t addr_sz) // // Only this functions are public / called from appmain.c //----------------------------------------------------------------------------- -void LegicRfInfo(void) -{ +void LegicRfInfo(void) { // configure ARM and FPGA init_reader(false); @@ -446,8 +432,7 @@ OUT: StopTicks(); } -void LegicRfReader(uint16_t offset, uint16_t len, uint8_t iv) -{ +void LegicRfReader(uint16_t offset, uint16_t len, uint8_t iv) { // configure ARM and FPGA init_reader(false); @@ -480,8 +465,7 @@ OUT: StopTicks(); } -void LegicRfWriter(uint16_t offset, uint16_t len, uint8_t iv, uint8_t *data) -{ +void LegicRfWriter(uint16_t offset, uint16_t len, uint8_t iv, uint8_t *data) { // configure ARM and FPGA init_reader(false); diff --git a/armsrc/legicrfsim.c b/armsrc/legicrfsim.c index a855401a4..c32558921 100644 --- a/armsrc/legicrfsim.c +++ b/armsrc/legicrfsim.c @@ -58,8 +58,7 @@ static uint32_t last_frame_end; /* ts of last bit of previews rx or tx frame */ //----------------------------------------------------------------------------- // Returns true if a pulse/pause is received within timeout -static inline bool wait_for(bool value, const uint32_t timeout) -{ +static inline bool wait_for(bool value, const uint32_t timeout) { while ((bool)(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_DIN) != value) { if (GetCountSspClk() > timeout) { return false; @@ -77,8 +76,7 @@ static inline bool wait_for(bool value, const uint32_t timeout) // - A bit length >80.2us is a 1 // - A bit length <80.2us is a 0 // - A bit length >148.6us is a code violation -static inline int8_t rx_bit() -{ +static inline int8_t rx_bit() { // backup ts for threshold calculation uint32_t bit_start = last_frame_end; @@ -121,8 +119,7 @@ static inline int8_t rx_bit() // Note: The Subcarrier is not disabled during bits to prevent glitches. This is // not mandatory but results in a cleaner signal. tx_frame will disable // the subcarrier when the frame is done. -static inline void tx_bit(bool bit) -{ +static inline void tx_bit(bool bit) { LED_C_ON(); if (bit) { @@ -149,8 +146,7 @@ static inline void tx_bit(bool bit) // and depends only the command received (IV, ACK, READ or WRITE). //----------------------------------------------------------------------------- -static void tx_frame(uint32_t frame, uint8_t len) -{ +static void tx_frame(uint32_t frame, uint8_t len) { // wait for next tx timeslot last_frame_end += TAG_FRAME_WAIT; legic_prng_forward(TAG_FRAME_WAIT / TAG_BIT_PERIOD - 1); @@ -174,8 +170,7 @@ static void tx_frame(uint32_t frame, uint8_t len) LogTrace(cmdbytes, sizeof(cmdbytes), last_frame_start, last_frame_end, NULL, false); } -static void tx_ack() -{ +static void tx_ack() { // wait for ack timeslot last_frame_end += TAG_ACK_WAIT; legic_prng_forward(TAG_ACK_WAIT / TAG_BIT_PERIOD - 1); @@ -203,8 +198,7 @@ static void tx_ack() // - forward prng based on ts/TAG_BIT_PERIOD // - receive the frame // - detect end of frame (last pause) -static int32_t rx_frame(uint8_t *len) -{ +static int32_t rx_frame(uint8_t *len) { int32_t frame = 0; // add 2 SSP clock cycles (1 for tx and 1 for rx pipeline delay) @@ -269,8 +263,7 @@ static int32_t rx_frame(uint8_t *len) // Legic Simulator //----------------------------------------------------------------------------- -static int32_t init_card(uint8_t cardtype, legic_card_select_t *p_card) -{ +static int32_t init_card(uint8_t cardtype, legic_card_select_t *p_card) { p_card->tagtype = cardtype; switch (p_card->tagtype) { @@ -298,8 +291,7 @@ static int32_t init_card(uint8_t cardtype, legic_card_select_t *p_card) return 0; } -static void init_tag() -{ +static void init_tag() { // configure FPGA FpgaDownloadAndGo(FPGA_BITSTREAM_HF); FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR @@ -334,8 +326,7 @@ static void init_tag() // - Receive initialisation vector 7 bits // - Transmit card type 6 bits // - Receive Acknowledge 6 bits -static int32_t setup_phase(legic_card_select_t *p_card) -{ +static int32_t setup_phase(legic_card_select_t *p_card) { uint8_t len = 0; // init coordination timestamp @@ -396,15 +387,13 @@ static int32_t setup_phase(legic_card_select_t *p_card) return 0; } -static uint8_t calc_crc4(uint16_t cmd, uint8_t cmd_sz, uint8_t value) -{ +static uint8_t calc_crc4(uint16_t cmd, uint8_t cmd_sz, uint8_t value) { crc_clear(&legic_crc); crc_update(&legic_crc, (value << cmd_sz) | cmd, 8 + cmd_sz); return crc_finish(&legic_crc); } -static int32_t connected_phase(legic_card_select_t *p_card) -{ +static int32_t connected_phase(legic_card_select_t *p_card) { uint8_t len = 0; // wait for command @@ -458,8 +447,7 @@ static int32_t connected_phase(legic_card_select_t *p_card) // Only this function is public / called from appmain.c //----------------------------------------------------------------------------- -void LegicRfSimulate(uint8_t cardtype) -{ +void LegicRfSimulate(uint8_t cardtype) { // configure ARM and FPGA init_tag(); diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 87a0bcfb9..ac9f08ed3 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -61,8 +61,7 @@ Default LF T55xx config is set to: */ t55xx_config t_config = { 29 * 8, 17 * 8, 15 * 8, 47 * 8, 15 * 8 } ; -void printT55xxConfig(void) -{ +void printT55xxConfig(void) { Dbprintf("LF T55XX config"); Dbprintf(" [a] startgap............%d*8 (%d)", t_config.start_gap / 8, t_config.start_gap); Dbprintf(" [b] writegap............%d*8 (%d)", t_config.write_gap / 8, t_config.write_gap); @@ -71,8 +70,7 @@ void printT55xxConfig(void) Dbprintf(" [e] readgap.............%d*8 (%d)", t_config.read_gap / 8, t_config.read_gap); } -void setT55xxConfig(uint8_t arg0, t55xx_config *c) -{ +void setT55xxConfig(uint8_t arg0, t55xx_config *c) { if (c->start_gap != 0) t_config.start_gap = c->start_gap; if (c->write_gap != 0) t_config.write_gap = c->write_gap; @@ -116,13 +114,11 @@ void setT55xxConfig(uint8_t arg0, t55xx_config *c) #endif } -t55xx_config *getT55xxConfig(void) -{ +t55xx_config *getT55xxConfig(void) { return &t_config; } -void loadT55xxConfig(void) -{ +void loadT55xxConfig(void) { #ifdef WITH_FLASH if (!FlashInit()) { return; @@ -160,8 +156,7 @@ void loadT55xxConfig(void) * @param period_1 * @param command (in binary char array) */ -void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint32_t period_1, uint8_t *command) -{ +void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint32_t period_1, uint8_t *command) { // start timer StartTicks(); @@ -266,8 +261,7 @@ void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint [5555fe852c5555555555555555fe0000] */ -void ReadTItag(void) -{ +void ReadTItag(void) { StartTicks(); // some hardcoded initial params // when we read a TI tag we sample the zerocross line at 2Mhz @@ -397,8 +391,7 @@ void ReadTItag(void) StopTicks(); } -void WriteTIbyte(uint8_t b) -{ +void WriteTIbyte(uint8_t b) { int i = 0; // modulate 8 bits out to the antenna @@ -421,8 +414,7 @@ void WriteTIbyte(uint8_t b) } } -void AcquireTiType(void) -{ +void AcquireTiType(void) { int i, j, n; // tag transmission is <20ms, sampling at 2M gives us 40K samples max // each sample is 1 bit stuffed into a uint32_t so we need 1250 uint32_t @@ -504,8 +496,7 @@ void AcquireTiType(void) // arguments: 64bit data split into 32bit idhi:idlo and optional 16bit crc // if crc provided, it will be written with the data verbatim (even if bogus) // if not provided a valid crc will be computed from the data and written. -void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc) -{ +void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc) { FpgaDownloadAndGo(FPGA_BITSTREAM_LF); if (crc == 0) { crc = update_crc16(crc, (idlo) & 0xff); @@ -577,8 +568,7 @@ void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc) // note: a call to FpgaDownloadAndGo(FPGA_BITSTREAM_LF) must be done before, but // this may destroy the bigbuf so be sure this is called before calling SimulateTagLowFrequencyEx -void SimulateTagLowFrequencyEx(int period, int gap, int ledcontrol, int numcycles) -{ +void SimulateTagLowFrequencyEx(int period, int gap, int ledcontrol, int numcycles) { // start us timer StartTicks(); @@ -662,22 +652,19 @@ OUT: LED_D_OFF(); } -void SimulateTagLowFrequency(int period, int gap, int ledcontrol) -{ +void SimulateTagLowFrequency(int period, int gap, int ledcontrol) { SimulateTagLowFrequencyEx(period, gap, ledcontrol, -1); } #define DEBUG_FRAME_CONTENTS 1 -void SimulateTagLowFrequencyBidir(int divisor, int t0) -{ +void SimulateTagLowFrequencyBidir(int divisor, int t0) { } // compose fc/5 fc/8 waveform (FSK1) // compose fc/8 fc/10 waveform (FSK2) // also manchester, -static void fc(int c, int *n) -{ +static void fc(int c, int *n) { uint8_t *dest = BigBuf_get_addr(); int idx; @@ -726,8 +713,7 @@ static void fc(int c, int *n) // special start of frame marker containing invalid bit sequences // this one is focused on HID, with manchester encoding. -static void fcSTT(int *n) -{ +static void fcSTT(int *n) { fc(8, n); fc(8, n); // invalid fc(8, n); @@ -739,8 +725,7 @@ static void fcSTT(int *n) } // compose fc/X fc/Y waveform (FSKx) -static void fcAll(uint8_t fc, int *n, uint8_t clock, uint16_t *modCnt) -{ +static void fcAll(uint8_t fc, int *n, uint8_t clock, uint16_t *modCnt) { uint8_t *dest = BigBuf_get_addr(); uint8_t halfFC = fc >> 1; uint8_t wavesPerClock = clock / fc; @@ -773,8 +758,7 @@ static void fcAll(uint8_t fc, int *n, uint8_t clock, uint16_t *modCnt) // prepare a waveform pattern in the buffer based on the ID given then // simulate a HID tag until the button is pressed -void CmdHIDsimTAGEx(uint32_t hi, uint32_t lo, int ledcontrol, int numcycles) -{ +void CmdHIDsimTAGEx(uint32_t hi, uint32_t lo, int ledcontrol, int numcycles) { if (hi > 0xFFF) { DbpString("[!] tags can only have 44 bits. - USE lf simfsk for larger tags"); @@ -837,8 +821,7 @@ void CmdHIDsimTAGEx(uint32_t hi, uint32_t lo, int ledcontrol, int numcycles) if (ledcontrol) LED_A_OFF(); } -void CmdHIDsimTAG(uint32_t hi, uint32_t lo, int ledcontrol) -{ +void CmdHIDsimTAG(uint32_t hi, uint32_t lo, int ledcontrol) { CmdHIDsimTAGEx(hi, lo, ledcontrol, -1); DbpString("[!] simulation finished"); } @@ -846,8 +829,7 @@ void CmdHIDsimTAG(uint32_t hi, uint32_t lo, int ledcontrol) // prepare a waveform pattern in the buffer based on the ID given then // simulate a FSK tag until the button is pressed // arg1 contains fcHigh and fcLow, arg2 contains STT marker and clock -void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *bits) -{ +void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *bits) { FpgaDownloadAndGo(FPGA_BITSTREAM_LF); // free eventually allocated BigBuf memory @@ -885,8 +867,7 @@ void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *bits) } // compose ask waveform for one bit(ASK) -static void askSimBit(uint8_t c, int *n, uint8_t clock, uint8_t manchester) -{ +static void askSimBit(uint8_t c, int *n, uint8_t clock, uint8_t manchester) { uint8_t *dest = BigBuf_get_addr(); uint8_t halfClk = clock / 2; // c = current bit 1 or 0 @@ -899,8 +880,7 @@ static void askSimBit(uint8_t c, int *n, uint8_t clock, uint8_t manchester) *n += clock; } -static void biphaseSimBit(uint8_t c, int *n, uint8_t clock, uint8_t *phase) -{ +static void biphaseSimBit(uint8_t c, int *n, uint8_t clock, uint8_t *phase) { uint8_t *dest = BigBuf_get_addr(); uint8_t halfClk = clock / 2; if (c) { @@ -913,8 +893,7 @@ static void biphaseSimBit(uint8_t c, int *n, uint8_t clock, uint8_t *phase) *n += clock; } -static void stAskSimBit(int *n, uint8_t clock) -{ +static void stAskSimBit(int *n, uint8_t clock) { uint8_t *dest = BigBuf_get_addr(); uint8_t halfClk = clock / 2; //ST = .5 high .5 low 1.5 high .5 low 1 high @@ -927,8 +906,7 @@ static void stAskSimBit(int *n, uint8_t clock) } // args clock, ask/man or askraw, invert, transmission separator -void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream) -{ +void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream) { FpgaDownloadAndGo(FPGA_BITSTREAM_LF); set_tracing(false); @@ -973,8 +951,7 @@ void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream) } //carrier can be 2,4 or 8 -static void pskSimBit(uint8_t waveLen, int *n, uint8_t clk, uint8_t *curPhase, bool phaseChg) -{ +static void pskSimBit(uint8_t waveLen, int *n, uint8_t clk, uint8_t *curPhase, bool phaseChg) { uint8_t *dest = BigBuf_get_addr(); uint8_t halfWave = waveLen / 2; //uint8_t idx; @@ -996,8 +973,7 @@ static void pskSimBit(uint8_t waveLen, int *n, uint8_t clk, uint8_t *curPhase, b } // args clock, carrier, invert, -void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream) -{ +void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream) { FpgaDownloadAndGo(FPGA_BITSTREAM_LF); set_tracing(false); @@ -1024,8 +1000,7 @@ void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream) } // loop to get raw HID waveform then FSK demodulate the TAG ID from it -void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) -{ +void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) { uint8_t *dest = BigBuf_get_addr(); size_t size = 0; uint32_t hi2 = 0, hi = 0, lo = 0; @@ -1122,8 +1097,7 @@ void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) } // loop to get raw HID waveform then FSK demodulate the TAG ID from it -void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) -{ +void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) { uint8_t *dest = BigBuf_get_addr(); @@ -1218,8 +1192,7 @@ void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) if (ledcontrol) LED_A_OFF(); } -void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol) -{ +void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol) { uint8_t *dest = BigBuf_get_addr(); size_t size = 0, idx = 0; @@ -1281,8 +1254,7 @@ void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol) if (ledcontrol) LED_A_OFF(); } -void CmdIOdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) -{ +void CmdIOdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) { uint8_t *dest = BigBuf_get_addr(); @@ -1382,23 +1354,20 @@ void CmdIOdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) * Q5 tags seems to have issues when these values changes. */ -void TurnReadLFOn(uint32_t delay) -{ +void TurnReadLFOn(uint32_t delay) { FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD); // measure antenna strength. //int adcval = ((MAX_ADC_LF_VOLTAGE * AvgAdc(ADC_CHAN_LF)) >> 10); WaitUS(delay); } -void TurnReadLF_off(uint32_t delay) -{ +void TurnReadLF_off(uint32_t delay) { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); WaitUS(delay); } // Write one bit to card -void T55xxWriteBit(int bit) -{ +void T55xxWriteBit(int bit) { if (!bit) TurnReadLFOn(t_config.write_0); else @@ -1408,8 +1377,7 @@ void T55xxWriteBit(int bit) } // Send T5577 reset command then read stream (see if we can identify the start of the stream) -void T55xxResetRead(void) -{ +void T55xxResetRead(void) { LED_A_ON(); //clear buffer now so it does not interfere with timing later BigBuf_Clear_keep_EM(); @@ -1441,8 +1409,7 @@ void T55xxResetRead(void) } // Write one card block in page 0, no lock -void T55xxWriteBlockExt(uint32_t Data, uint8_t Block, uint32_t Pwd, uint8_t arg) -{ +void T55xxWriteBlockExt(uint32_t Data, uint8_t Block, uint32_t Pwd, uint8_t arg) { LED_A_ON(); bool PwdMode = arg & 0x1; uint8_t Page = (arg & 0x2) >> 1; @@ -1516,15 +1483,13 @@ void T55xxWriteBlockExt(uint32_t Data, uint8_t Block, uint32_t Pwd, uint8_t arg) } // Write one card block in page 0, no lock -void T55xxWriteBlock(uint32_t Data, uint8_t Block, uint32_t Pwd, uint8_t arg) -{ +void T55xxWriteBlock(uint32_t Data, uint8_t Block, uint32_t Pwd, uint8_t arg) { T55xxWriteBlockExt(Data, Block, Pwd, arg); cmd_send(CMD_ACK, 0, 0, 0, 0, 0); } // Read one card block in page [page] -void T55xxReadBlock(uint16_t arg0, uint8_t Block, uint32_t Pwd) -{ +void T55xxReadBlock(uint16_t arg0, uint8_t Block, uint32_t Pwd) { LED_A_ON(); bool PwdMode = arg0 & 0x1; uint8_t Page = (arg0 & 0x2) >> 1; @@ -1593,8 +1558,7 @@ void T55xxReadBlock(uint16_t arg0, uint8_t Block, uint32_t Pwd) } } -void T55xx_ChkPwds() -{ +void T55xx_ChkPwds() { DbpString("[+] T55XX Check pwds using flashmemory starting"); @@ -1693,8 +1657,7 @@ OUT: LEDsoff(); } -void T55xxWakeUp(uint32_t Pwd) -{ +void T55xxWakeUp(uint32_t Pwd) { LED_B_ON(); uint32_t i = 0; @@ -1722,16 +1685,14 @@ void T55xxWakeUp(uint32_t Pwd) } /*-------------- Cloning routines -----------*/ -void WriteT55xx(uint32_t *blockdata, uint8_t startblock, uint8_t numblocks) -{ +void WriteT55xx(uint32_t *blockdata, uint8_t startblock, uint8_t numblocks) { // write last block first and config block last (if included) for (uint8_t i = numblocks + startblock; i > startblock; i--) T55xxWriteBlockExt(blockdata[i - 1], i - 1, 0, 0); } // Copy HID id to card and setup block 0 config -void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT) -{ +void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT) { uint32_t data[] = {0, 0, 0, 0, 0, 0, 0}; uint8_t last_block = 0; @@ -1775,8 +1736,7 @@ void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT) LED_D_OFF(); } -void CopyIOtoT55x7(uint32_t hi, uint32_t lo) -{ +void CopyIOtoT55x7(uint32_t hi, uint32_t lo) { uint32_t data[] = {T55x7_BITRATE_RF_64 | T55x7_MODULATION_FSK2a | (2 << T55x7_MAXBLOCK_SHIFT), hi, lo}; //TODO add selection of chip for Q5 or T55x7 // data[0] = T5555_SET_BITRATE(64) | T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 2 << T5555_MAXBLOCK_SHIFT; @@ -1789,8 +1749,7 @@ void CopyIOtoT55x7(uint32_t hi, uint32_t lo) } // Clone Indala 64-bit tag by UID to T55x7 -void CopyIndala64toT55x7(uint32_t hi, uint32_t lo) -{ +void CopyIndala64toT55x7(uint32_t hi, uint32_t lo) { //Program the 2 data blocks for supplied 64bit UID // and the Config for Indala 64 format (RF/32;PSK2 with RF/2;Maxblock=2) uint32_t data[] = { T55x7_BITRATE_RF_32 | T55x7_MODULATION_PSK2 | (2 << T55x7_MAXBLOCK_SHIFT), hi, lo}; @@ -1802,8 +1761,7 @@ void CopyIndala64toT55x7(uint32_t hi, uint32_t lo) // T5567WriteBlock(0x603E1042,0); } // Clone Indala 224-bit tag by UID to T55x7 -void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t uid4, uint32_t uid5, uint32_t uid6, uint32_t uid7) -{ +void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t uid4, uint32_t uid5, uint32_t uid6, uint32_t uid7) { //Program the 7 data blocks for supplied 224bit UID uint32_t data[] = {0, uid1, uid2, uid3, uid4, uid5, uid6, uid7}; // and the block 0 for Indala224 format @@ -1816,8 +1774,7 @@ void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t // T5567WriteBlock(0x603E10E2,0); } // clone viking tag to T55xx -void CopyVikingtoT55xx(uint32_t block1, uint32_t block2, uint8_t Q5) -{ +void CopyVikingtoT55xx(uint32_t block1, uint32_t block2, uint8_t Q5) { uint32_t data[] = {T55x7_BITRATE_RF_32 | T55x7_MODULATION_MANCHESTER | (2 << T55x7_MAXBLOCK_SHIFT), block1, block2}; if (Q5) data[0] = T5555_SET_BITRATE(32) | T5555_MODULATION_MANCHESTER | 2 << T5555_MAXBLOCK_SHIFT; // Program the data blocks for supplied ID and the block 0 config @@ -1830,8 +1787,7 @@ void CopyVikingtoT55xx(uint32_t block1, uint32_t block2, uint8_t Q5) #define EM410X_HEADER 0x1FF #define EM410X_ID_LENGTH 40 -void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo) -{ +void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo) { int i, id_bit; uint64_t id = EM410X_HEADER; uint64_t rev_id = 0; // reversed ID @@ -1944,8 +1900,7 @@ uint8_t *fwd_write_ptr; //forwardlink bit pointer // These timings work for 4469/4269/4305 (with the 55*8 above) // WRITE_0 = 23*8 , 9*8 -uint8_t Prepare_Cmd(uint8_t cmd) -{ +uint8_t Prepare_Cmd(uint8_t cmd) { *forward_ptr++ = 0; //start bit *forward_ptr++ = 0; //second pause for 4050 code @@ -1965,8 +1920,7 @@ uint8_t Prepare_Cmd(uint8_t cmd) // prepares address bits // see EM4469 spec //==================================================================== -uint8_t Prepare_Addr(uint8_t addr) -{ +uint8_t Prepare_Addr(uint8_t addr) { register uint8_t line_parity; @@ -1987,8 +1941,7 @@ uint8_t Prepare_Addr(uint8_t addr) // prepares data bits intreleaved with parity bits // see EM4469 spec //==================================================================== -uint8_t Prepare_Data(uint16_t data_low, uint16_t data_hi) -{ +uint8_t Prepare_Data(uint16_t data_low, uint16_t data_hi) { register uint8_t line_parity; register uint8_t column_parity; @@ -2025,8 +1978,7 @@ uint8_t Prepare_Data(uint16_t data_low, uint16_t data_hi) // Requires: forwarLink_data filled with valid bits (1 bit per byte) // fwd_bit_count set with number of bits to be sent //==================================================================== -void SendForward(uint8_t fwd_bit_count) -{ +void SendForward(uint8_t fwd_bit_count) { // iceman, 21.3us increments for the USclock verification. // 55FC * 8us == 440us / 21.3 === 20.65 steps. could be too short. Go for 56FC instead @@ -2060,8 +2012,7 @@ void SendForward(uint8_t fwd_bit_count) } } -void EM4xLogin(uint32_t pwd) -{ +void EM4xLogin(uint32_t pwd) { uint8_t len; forward_ptr = forwardLink_data; len = Prepare_Cmd(FWD_CMD_LOGIN); @@ -2073,8 +2024,7 @@ void EM4xLogin(uint32_t pwd) // 0000 0001 fail } -void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd) -{ +void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd) { LED_A_ON(); uint8_t len; @@ -2106,8 +2056,7 @@ void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd) LED_A_OFF(); } -void EM4xWriteWord(uint32_t flag, uint32_t data, uint32_t pwd) -{ +void EM4xWriteWord(uint32_t flag, uint32_t data, uint32_t pwd) { LED_A_ON(); @@ -2157,8 +2106,7 @@ pulse 3.6 msecs This triggers a COTAG tag to response */ -void Cotag(uint32_t arg0) -{ +void Cotag(uint32_t arg0) { #ifndef OFF # define OFF(x) { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); WaitUS((x)); } #endif diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index 086b60d2f..12517132e 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -18,8 +18,7 @@ Default LF config is set to: */ sample_config config = { 1, 8, 1, 95, 0 } ; -void printConfig() -{ +void printConfig() { Dbprintf("LF Sampling config"); Dbprintf(" [q] divisor.............%d (%d KHz)", config.divisor, 12000 / (config.divisor + 1)); Dbprintf(" [b] bps.................%d", config.bits_per_sample); @@ -39,8 +38,7 @@ void printConfig() * @brief setSamplingConfig * @param sc */ -void setSamplingConfig(sample_config *sc) -{ +void setSamplingConfig(sample_config *sc) { if (sc->divisor != 0) config.divisor = sc->divisor; if (sc->bits_per_sample != 0) config.bits_per_sample = sc->bits_per_sample; if (sc->trigger_threshold != -1) config.trigger_threshold = sc->trigger_threshold; @@ -52,8 +50,7 @@ void setSamplingConfig(sample_config *sc) printConfig(); } -sample_config *getSamplingConfig() -{ +sample_config *getSamplingConfig() { return &config; } @@ -68,8 +65,7 @@ struct BitstreamOut { * @param stream * @param bit */ -void pushBit(BitstreamOut *stream, uint8_t bit) -{ +void pushBit(BitstreamOut *stream, uint8_t bit) { int bytepos = stream->position >> 3; // divide by 8 int bitpos = stream->position & 7; *(stream->buffer + bytepos) |= (bit > 0) << (7 - bitpos); @@ -84,8 +80,7 @@ void pushBit(BitstreamOut *stream, uint8_t bit) * 0 or 95 ==> 125 KHz * **/ -void LFSetupFPGAForADC(int divisor, bool lf_field) -{ +void LFSetupFPGAForADC(int divisor, bool lf_field) { FpgaDownloadAndGo(FPGA_BITSTREAM_LF); if ((divisor == 1) || (divisor < 0) || (divisor > 255)) FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz @@ -121,8 +116,7 @@ void LFSetupFPGAForADC(int divisor, bool lf_field) * @param silent - is true, now outputs are made. If false, dbprints the status * @return the number of bits occupied by the samples. */ -uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averaging, int trigger_threshold, bool silent, int bufsize, uint32_t cancel_after) -{ +uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averaging, int trigger_threshold, bool silent, int bufsize, uint32_t cancel_after) { uint8_t *dest = BigBuf_get_addr(); bufsize = (bufsize > 0 && bufsize < BigBuf_max_traceLen()) ? bufsize : BigBuf_max_traceLen(); @@ -224,12 +218,10 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag * @param silent * @return number of bits sampled */ -uint32_t DoAcquisition_default(int trigger_threshold, bool silent) -{ +uint32_t DoAcquisition_default(int trigger_threshold, bool silent) { return DoAcquisition(1, 8, 0, trigger_threshold, silent, 0, 0); } -uint32_t DoAcquisition_config(bool silent, int sample_size) -{ +uint32_t DoAcquisition_config(bool silent, int sample_size) { return DoAcquisition(config.decimation , config.bits_per_sample , config.averaging @@ -239,13 +231,11 @@ uint32_t DoAcquisition_config(bool silent, int sample_size) , 0); } -uint32_t DoPartialAcquisition(int trigger_threshold, bool silent, int sample_size, uint32_t cancel_after) -{ +uint32_t DoPartialAcquisition(int trigger_threshold, bool silent, int sample_size, uint32_t cancel_after) { return DoAcquisition(1, 8, 0, trigger_threshold, silent, sample_size, cancel_after); } -uint32_t ReadLF(bool activeField, bool silent, int sample_size) -{ +uint32_t ReadLF(bool activeField, bool silent, int sample_size) { if (!silent) printConfig(); LFSetupFPGAForADC(config.divisor, activeField); @@ -256,8 +246,7 @@ uint32_t ReadLF(bool activeField, bool silent, int sample_size) * Initializes the FPGA for reader-mode (field on), and acquires the samples. * @return number of bits sampled **/ -uint32_t SampleLF(bool printCfg, int sample_size) -{ +uint32_t SampleLF(bool printCfg, int sample_size) { BigBuf_Clear_ext(false); uint32_t ret = ReadLF(true, printCfg, sample_size); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); @@ -267,8 +256,7 @@ uint32_t SampleLF(bool printCfg, int sample_size) * Initializes the FPGA for snoop-mode (field off), and acquires the samples. * @return number of bits sampled **/ -uint32_t SnoopLF() -{ +uint32_t SnoopLF() { BigBuf_Clear_ext(false); uint32_t ret = ReadLF(false, true, 0); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); @@ -279,8 +267,7 @@ uint32_t SnoopLF() * acquisition of T55x7 LF signal. Similar to other LF, but adjusted with @marshmellows thresholds * the data is collected in BigBuf. **/ -void doT55x7Acquisition(size_t sample_size) -{ +void doT55x7Acquisition(size_t sample_size) { #define T55xx_READ_UPPER_THRESHOLD 128+60 // 60 grph #define T55xx_READ_LOWER_THRESHOLD 128-60 // -60 grph @@ -350,8 +337,7 @@ void doT55x7Acquisition(size_t sample_size) #ifndef COTAG_BITS #define COTAG_BITS 264 #endif -void doCotagAcquisition(size_t sample_size) -{ +void doCotagAcquisition(size_t sample_size) { uint8_t *dest = BigBuf_get_addr(); uint16_t bufsize = BigBuf_max_traceLen(); @@ -401,8 +387,7 @@ void doCotagAcquisition(size_t sample_size) } } -uint32_t doCotagAcquisitionManchester() -{ +uint32_t doCotagAcquisitionManchester() { uint8_t *dest = BigBuf_get_addr(); uint16_t bufsize = BigBuf_max_traceLen(); diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index c4710d936..1f1932e27 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -38,8 +38,7 @@ static uint8_t dummy_answer = 0; // Select, Authenticate, Read a MIFARE tag. // read block //----------------------------------------------------------------------------- -void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) -{ +void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) { // params uint8_t blockNo = arg0; uint8_t keyType = arg1; @@ -101,8 +100,7 @@ void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) LEDsoff(); } -void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes) -{ +void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes) { bool turnOffField = (arg0 == 1); @@ -137,8 +135,7 @@ void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes) // Arg0 = BlockNo, // Arg1 = UsePwd bool // datain = PWD bytes, -void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) -{ +void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) { uint8_t blockNo = arg0; byte_t dataout[16] = {0x00}; bool useKey = (arg1 == 1); //UL_C @@ -201,8 +198,7 @@ void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) // Select, Authenticate, Read a MIFARE tag. // read sector (data = 4 x 16 bytes = 64 bytes, or 16 x 16 bytes = 256 bytes) //----------------------------------------------------------------------------- -void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) -{ +void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) { // params uint8_t sectorNo = arg0; uint8_t keyType = arg1; @@ -268,8 +264,7 @@ void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) // arg1 = Pages (number of blocks) // arg2 = useKey // datain = KEY bytes -void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain) -{ +void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain) { LEDsoff(); LED_A_ON(); iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); @@ -368,8 +363,7 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain) // Select, Authenticate, Write a MIFARE tag. // read block //----------------------------------------------------------------------------- -void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) -{ +void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) { // params uint8_t blockNo = arg0; uint8_t keyType = arg1; @@ -479,8 +473,7 @@ void MifareUWriteBlockCompat(uint8_t arg0, uint8_t *datain) // 2 = use 0x1B authentication. // datain : 4 first bytes is data to be written. // : 4/16 next bytes is authentication key. -void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) -{ +void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) { uint8_t blockNo = arg0; bool useKey = (arg1 == 1); //UL_C bool usePwd = (arg1 == 2); //UL_EV1/NTAG @@ -543,8 +536,7 @@ void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) set_tracing(false); } -void MifareUSetPwd(uint8_t arg0, uint8_t *datain) -{ +void MifareUSetPwd(uint8_t arg0, uint8_t *datain) { uint8_t pwd[16] = {0x00}; byte_t blockdata[4] = {0x00}; @@ -618,15 +610,13 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain) } // Return 1 if the nonce is invalid else return 0 -int valid_nonce(uint32_t Nt, uint32_t NtEnc, uint32_t Ks1, uint8_t *parity) -{ +int valid_nonce(uint32_t Nt, uint32_t NtEnc, uint32_t Ks1, uint8_t *parity) { return ((oddparity8((Nt >> 24) & 0xFF) == ((parity[0]) ^ oddparity8((NtEnc >> 24) & 0xFF) ^ BIT(Ks1, 16))) & \ (oddparity8((Nt >> 16) & 0xFF) == ((parity[1]) ^ oddparity8((NtEnc >> 16) & 0xFF) ^ BIT(Ks1, 8))) & \ (oddparity8((Nt >> 8) & 0xFF) == ((parity[2]) ^ oddparity8((NtEnc >> 8) & 0xFF) ^ BIT(Ks1, 0)))) ? 1 : 0; } -void MifareAcquireNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t *datain) -{ +void MifareAcquireNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t *datain) { uint8_t uid[10] = {0x00}; uint8_t answer[MAX_MIFARE_FRAME_SIZE] = {0x00}; @@ -734,8 +724,7 @@ void MifareAcquireNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t * // Mifare Classic Cards" in Proceedings of the 22nd ACM SIGSAC Conference on // Computer and Communications Security, 2015 //----------------------------------------------------------------------------- -void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t *datain) -{ +void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t *datain) { struct Crypto1State mpcs = {0, 0}; struct Crypto1State *pcs; @@ -862,8 +851,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, // MIFARE nested authentication. // //----------------------------------------------------------------------------- -void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t calibrate, uint8_t *datain) -{ +void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t calibrate, uint8_t *datain) { // params uint8_t blockNo = arg0 & 0xff; uint8_t keyType = (arg0 >> 8) & 0xff; @@ -1101,8 +1089,7 @@ typedef struct chk_t { // 2 = failed to select. // 1 = wrong key // 0 = correct key -uint8_t chkKey(struct chk_t *c) -{ +uint8_t chkKey(struct chk_t *c) { uint8_t i = 0, res = 2; while (i < 5) { // this part is from Piwi's faster nonce collecting part in Hardnested. @@ -1123,8 +1110,7 @@ uint8_t chkKey(struct chk_t *c) return res; } -uint8_t chkKey_readb(struct chk_t *c, uint8_t *keyb) -{ +uint8_t chkKey_readb(struct chk_t *c, uint8_t *keyb) { if (!iso14443a_fast_select_card(c->uid, c->cl)) return 2; @@ -1149,8 +1135,7 @@ uint8_t chkKey_readb(struct chk_t *c, uint8_t *keyb) return res; } -void chkKey_scanA(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, uint8_t *sectorcnt, uint8_t *foundkeys) -{ +void chkKey_scanA(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, uint8_t *sectorcnt, uint8_t *foundkeys) { for (uint8_t s = 0; s < *sectorcnt; s++) { // skip already found A keys @@ -1168,8 +1153,7 @@ void chkKey_scanA(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, ui } } -void chkKey_scanB(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, uint8_t *sectorcnt, uint8_t *foundkeys) -{ +void chkKey_scanB(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, uint8_t *sectorcnt, uint8_t *foundkeys) { for (uint8_t s = 0; s < *sectorcnt; s++) { // skip already found B keys @@ -1189,8 +1173,7 @@ void chkKey_scanB(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, ui // loop all A keys, // when A is found but not B, try to read B. -void chkKey_loopBonly(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, uint8_t *sectorcnt, uint8_t *foundkeys) -{ +void chkKey_loopBonly(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, uint8_t *sectorcnt, uint8_t *foundkeys) { // read Block B, if A is found. for (uint8_t s = 0; s < *sectorcnt; ++s) { @@ -1228,8 +1211,7 @@ void chkKey_loopBonly(struct chk_t *c, struct sector_t *k_sector, uint8_t *found // arg1 = clear trace // arg2 = antal nycklar i keychunk // datain = keys as array -void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) -{ +void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) { // first call or uint8_t sectorcnt = arg0 & 0xFF; // 16; @@ -1533,8 +1515,7 @@ OUT: } } -void MifareChkKeys(uint16_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) -{ +void MifareChkKeys(uint16_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); @@ -1623,8 +1604,7 @@ void MifareChkKeys(uint16_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) // MIFARE commands set debug level // //----------------------------------------------------------------------------- -void MifareSetDbgLvl(uint16_t arg0) -{ +void MifareSetDbgLvl(uint16_t arg0) { MF_DBGLEVEL = arg0; Dbprintf("Debug level: %d", MF_DBGLEVEL); } @@ -1637,21 +1617,18 @@ void MifareSetDbgLvl(uint16_t arg0) // destroy the Emulator Memory. //----------------------------------------------------------------------------- -void MifareEMemClr(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) -{ +void MifareEMemClr(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) { FpgaDownloadAndGo(FPGA_BITSTREAM_HF); emlClearMem(); } -void MifareEMemSet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) -{ +void MifareEMemSet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) { FpgaDownloadAndGo(FPGA_BITSTREAM_HF); if (arg2 == 0) arg2 = 16; // backwards compat... default bytewidth emlSetMem_xt(datain, arg0, arg1, arg2); // data, block num, blocks count, block byte width } -void MifareEMemGet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) -{ +void MifareEMemGet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) { FpgaDownloadAndGo(FPGA_BITSTREAM_HF); byte_t buf[USB_CMD_DATA_SIZE] = {0x00}; emlGetMem(buf, arg0, arg1); // data, block num, blocks count (max 4) @@ -1665,8 +1642,7 @@ void MifareEMemGet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) // Load a card into the emulator memory // //----------------------------------------------------------------------------- -void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) -{ +void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) { uint8_t numSectors = arg0; uint8_t keyType = arg1; uint64_t ui64Key = 0; @@ -1763,8 +1739,7 @@ uint8_t wupC1[] = { MIFARE_MAGICWUPC1 }; uint8_t wupC2[] = { MIFARE_MAGICWUPC2 }; uint8_t wipeC[] = { MIFARE_MAGICWIPEC }; -void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) -{ +void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) { // params uint8_t workFlags = arg0; @@ -1874,8 +1849,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) OnSuccessMagic(); } -void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) -{ +void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) { uint8_t workFlags = arg0; uint8_t blockNo = arg1; @@ -1951,8 +1925,7 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) OnSuccessMagic(); } -void MifareCIdent() -{ +void MifareCIdent() { #define GEN_1A 1 #define GEN_1B 2 #define GEN_2 4 @@ -2006,21 +1979,18 @@ OUT: OnSuccessMagic(); } -void OnSuccessMagic() -{ +void OnSuccessMagic() { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); LEDsoff(); set_tracing(false); } -void OnErrorMagic(uint8_t reason) -{ +void OnErrorMagic(uint8_t reason) { // ACK, ISOK, reason,0,0,0 cmd_send(CMD_ACK, 0, reason, 0, 0, 0); OnSuccessMagic(); } -void MifareSetMod(uint8_t mod, uint8_t *key) -{ +void MifareSetMod(uint8_t mod, uint8_t *key) { uint64_t ui64Key = bytes_to_num(key, 6); // variables @@ -2080,8 +2050,7 @@ void MifareSetMod(uint8_t mod, uint8_t *key) // // DESFIRE // -void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain) -{ +void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain) { byte_t dataout[12] = {0x00}; uint8_t uid[10] = {0x00}; uint32_t cuid = 0; @@ -2107,8 +2076,7 @@ void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain) cmd_send(CMD_ACK, 1, cuid, 0, dataout, sizeof(dataout)); } -void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain) -{ +void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain) { uint32_t cuid = arg0; uint8_t key[16] = {0x00}; byte_t dataout[12] = {0x00}; diff --git a/armsrc/mifaredesfire.c b/armsrc/mifaredesfire.c index 55dbb4646..3bbf667b5 100644 --- a/armsrc/mifaredesfire.c +++ b/armsrc/mifaredesfire.c @@ -16,8 +16,7 @@ static uint8_t deselect_cmd[] = {0xc2, 0xe0, 0xb4}; /* PCB CID CMD PAYLOAD */ //static uint8_t __res[MAX_FRAME_SIZE]; -bool InitDesfireCard() -{ +bool InitDesfireCard() { iso14a_card_select_t card; @@ -41,8 +40,7 @@ enum { BAR = 0x08, } CmdOptions ; -void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain) -{ +void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain) { /* ARG0 contains flags. 0x01 = init card. @@ -86,8 +84,7 @@ void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain) cmd_send(CMD_ACK, 1, len, 0, resp, len); } -void MifareDesfireGetInformation() -{ +void MifareDesfireGetInformation() { int len = 0; iso14a_card_select_t card; @@ -170,8 +167,7 @@ void MifareDesfireGetInformation() OnSuccess(); } -void MifareDES_Auth1(uint8_t mode, uint8_t algo, uint8_t keyno, uint8_t *datain) -{ +void MifareDES_Auth1(uint8_t mode, uint8_t algo, uint8_t keyno, uint8_t *datain) { int len = 0; //uint8_t PICC_MASTER_KEY8[8] = { 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47}; @@ -503,8 +499,7 @@ void MifareDES_Auth1(uint8_t mode, uint8_t algo, uint8_t keyno, uint8_t *datain // cmd = cmd bytes to send // cmd_len = length of cmd // dataout = pointer to response data array -int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout) -{ +int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout) { size_t len = 0; size_t wrappedLen = 0; @@ -538,8 +533,7 @@ int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout) } // CreateAPDU -size_t CreateAPDU(uint8_t *datain, size_t len, uint8_t *dataout) -{ +size_t CreateAPDU(uint8_t *datain, size_t len, uint8_t *dataout) { size_t cmdlen = MIN(len + 4, USB_CMD_DATA_SIZE - 1); @@ -563,16 +557,14 @@ size_t CreateAPDU(uint8_t *datain, size_t len, uint8_t *dataout) // crc_update(&desfire_crc32, byte, 8); // uint32_t crc = crc_finish(&desfire_crc32); -void OnSuccess() -{ +void OnSuccess() { pcb_blocknum = 0; ReaderTransmit(deselect_cmd, 3, NULL); mifare_ultra_halt(); switch_off(); } -void OnError(uint8_t reason) -{ +void OnError(uint8_t reason) { cmd_send(CMD_ACK, 0, reason, 0, 0, 0); OnSuccess(); } diff --git a/armsrc/mifaresniff.c b/armsrc/mifaresniff.c index 2a32e268e..8f391207e 100644 --- a/armsrc/mifaresniff.c +++ b/armsrc/mifaresniff.c @@ -24,8 +24,7 @@ static uint32_t timerData = 0; // if no activity for 2sec, it sends the collected data to the client. //----------------------------------------------------------------------------- // "hf mf sniff" -void RAMFUNC SniffMifare(uint8_t param) -{ +void RAMFUNC SniffMifare(uint8_t param) { // param: // bit 0 - trigger from first card answer // bit 1 - trigger from first reader 7-bit request @@ -177,8 +176,7 @@ void RAMFUNC SniffMifare(uint8_t param) switch_off(); } -void MfSniffInit(void) -{ +void MfSniffInit(void) { memset(sniffUID, 0x00, sizeof(sniffUID)); memset(sniffATQA, 0x00, sizeof(sniffATQA)); memset(sniffBuf, 0x00, sizeof(sniffBuf)); @@ -187,8 +185,7 @@ void MfSniffInit(void) timerData = 0; } -void MfSniffEnd(void) -{ +void MfSniffEnd(void) { LED_B_ON(); cmd_send(CMD_ACK, 0, 0, 0, 0, 0); LED_B_OFF(); @@ -308,8 +305,7 @@ bool RAMFUNC MfSniffLogic(const uint8_t *data, uint16_t len, uint8_t *parity, ui } */ -void RAMFUNC MfSniffSend() -{ +void RAMFUNC MfSniffSend() { uint16_t tracelen = BigBuf_get_traceLen(); uint16_t chunksize = 0; int packlen = tracelen; // total number of bytes to send diff --git a/armsrc/mifareutil.c b/armsrc/mifareutil.c index 42e69113d..f61987f09 100644 --- a/armsrc/mifareutil.c +++ b/armsrc/mifareutil.c @@ -13,8 +13,7 @@ int MF_DBGLEVEL = MF_DBG_ERROR; // crypto1 helpers -void mf_crypto1_decryptEx(struct Crypto1State *pcs, uint8_t *data_in, int len, uint8_t *data_out) -{ +void mf_crypto1_decryptEx(struct Crypto1State *pcs, uint8_t *data_in, int len, uint8_t *data_out) { uint8_t bt = 0; int i; @@ -31,13 +30,11 @@ void mf_crypto1_decryptEx(struct Crypto1State *pcs, uint8_t *data_in, int len, u return; } -void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len) -{ +void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len) { mf_crypto1_decryptEx(pcs, data, len, data); } -void mf_crypto1_encrypt(struct Crypto1State *pcs, uint8_t *data, uint16_t len, uint8_t *par) -{ +void mf_crypto1_encrypt(struct Crypto1State *pcs, uint8_t *data, uint16_t len, uint8_t *par) { uint8_t bt = 0; int i; par[0] = 0; @@ -51,8 +48,7 @@ void mf_crypto1_encrypt(struct Crypto1State *pcs, uint8_t *data, uint16_t len, u } } -uint8_t mf_crypto1_encrypt4bit(struct Crypto1State *pcs, uint8_t data) -{ +uint8_t mf_crypto1_encrypt4bit(struct Crypto1State *pcs, uint8_t data) { uint8_t bt = 0; bt |= (crypto1_bit(pcs, 0, 0) ^ BIT(data, 0)) << 0; bt |= (crypto1_bit(pcs, 0, 0) ^ BIT(data, 1)) << 1; @@ -62,8 +58,7 @@ uint8_t mf_crypto1_encrypt4bit(struct Crypto1State *pcs, uint8_t data) } // send X byte basic commands -int mifare_sendcmd(uint8_t cmd, uint8_t *data, uint8_t data_size, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) -{ +int mifare_sendcmd(uint8_t cmd, uint8_t *data, uint8_t data_size, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) { uint8_t dcmd[data_size + 3]; dcmd[0] = cmd; memcpy(dcmd + 1, data, data_size); @@ -78,8 +73,7 @@ int mifare_sendcmd(uint8_t cmd, uint8_t *data, uint8_t data_size, uint8_t *answe } // send 2 byte commands -int mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) -{ +int mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) { uint16_t pos, res; uint8_t dcmd[4] = {cmd, data, 0x00, 0x00}; uint8_t ecmd[4] = {0x00, 0x00, 0x00, 0x00}; @@ -119,13 +113,11 @@ int mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, } // mifare classic commands -int mifare_classic_auth(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint8_t isNested) -{ +int mifare_classic_auth(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint8_t isNested) { return mifare_classic_authex(pcs, uid, blockNo, keyType, ui64Key, isNested, NULL, NULL); } -int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint8_t isNested, uint32_t *ntptr, uint32_t *timing) -{ +int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint8_t isNested, uint32_t *ntptr, uint32_t *timing) { int len; uint32_t pos, nt, ntpp; // Supplied tag nonce uint8_t par[1] = {0x00}; @@ -203,8 +195,7 @@ int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockN return 0; } -int mifare_classic_readblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData) -{ +int mifare_classic_readblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData) { int len; uint8_t bt[2] = {0x00, 0x00}; @@ -233,8 +224,7 @@ int mifare_classic_readblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blo } // mifare ultralight commands -int mifare_ul_ev1_auth(uint8_t *keybytes, uint8_t *pack) -{ +int mifare_ul_ev1_auth(uint8_t *keybytes, uint8_t *pack) { uint16_t len = 0; uint8_t resp[4] = {0x00, 0x00, 0x00, 0x00}; @@ -259,8 +249,7 @@ int mifare_ul_ev1_auth(uint8_t *keybytes, uint8_t *pack) return 1; } -int mifare_ultra_auth(uint8_t *keybytes) -{ +int mifare_ultra_auth(uint8_t *keybytes) { /// 3des2k uint8_t random_a[8] = {1, 1, 1, 1, 1, 1, 1, 1}; @@ -345,8 +334,7 @@ int mifare_ultra_auth(uint8_t *keybytes) return 1; } -int mifare_ultra_readblockEx(uint8_t blockNo, uint8_t *blockData) -{ +int mifare_ultra_readblockEx(uint8_t blockNo, uint8_t *blockData) { uint16_t len = 0; uint8_t bt[2] = {0x00, 0x00}; uint8_t receivedAnswer[MAX_FRAME_SIZE] = {0x00}; @@ -372,8 +360,7 @@ int mifare_ultra_readblockEx(uint8_t blockNo, uint8_t *blockData) memcpy(blockData, receivedAnswer, 14); return 0; } -int mifare_ultra_readblock(uint8_t blockNo, uint8_t *blockData) -{ +int mifare_ultra_readblock(uint8_t blockNo, uint8_t *blockData) { #define MFU_MAX_RETRIES 5 uint8_t res; @@ -392,8 +379,7 @@ int mifare_ultra_readblock(uint8_t blockNo, uint8_t *blockData) return res; } -int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData) -{ +int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData) { // variables uint16_t len = 0; uint32_t pos = 0; @@ -471,8 +457,7 @@ int mifare_ultra_writeblock_compat(uint8_t blockNo, uint8_t *blockData) { } */ -int mifare_ultra_writeblock(uint8_t blockNo, uint8_t *blockData) -{ +int mifare_ultra_writeblock(uint8_t blockNo, uint8_t *blockData) { uint16_t len = 0; uint8_t block[5] = {blockNo, 0x00, 0x00, 0x00, 0x00 }; uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE] = {0x00}; @@ -490,8 +475,7 @@ int mifare_ultra_writeblock(uint8_t blockNo, uint8_t *blockData) } return 0; } -int mifare_classic_halt_ex(struct Crypto1State *pcs) -{ +int mifare_classic_halt_ex(struct Crypto1State *pcs) { uint8_t receivedAnswer[4] = {0x00, 0x00, 0x00, 0x00}; uint16_t len = mifare_sendcmd_short(pcs, (pcs == NULL) ? CRYPT_NONE : CRYPT_ALL, ISO14443A_CMD_HALT, 0x00, receivedAnswer, NULL, NULL); if (len != 0) { @@ -500,13 +484,11 @@ int mifare_classic_halt_ex(struct Crypto1State *pcs) } return 0; } -int mifare_classic_halt(struct Crypto1State *pcs, uint32_t uid) -{ +int mifare_classic_halt(struct Crypto1State *pcs, uint32_t uid) { return mifare_classic_halt_ex(pcs); } -int mifare_ultra_halt() -{ +int mifare_ultra_halt() { uint16_t len = 0; uint8_t receivedAnswer[4] = {0x00, 0x00, 0x00, 0x00}; len = mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_HALT, 0x00, receivedAnswer, NULL, NULL); @@ -520,13 +502,11 @@ int mifare_ultra_halt() // Mifare Memory Structure: up to 32 Sectors with 4 blocks each (1k and 2k cards), // plus evtl. 8 sectors with 16 blocks each (4k cards) -uint8_t NumBlocksPerSector(uint8_t sectorNo) -{ +uint8_t NumBlocksPerSector(uint8_t sectorNo) { return (sectorNo < 32) ? 4 : 16; } -uint8_t FirstBlockOfSector(uint8_t sectorNo) -{ +uint8_t FirstBlockOfSector(uint8_t sectorNo) { if (sectorNo < 32) return sectorNo * 4; else @@ -535,47 +515,41 @@ uint8_t FirstBlockOfSector(uint8_t sectorNo) } // work with emulator memory -void emlSetMem(uint8_t *data, int blockNum, int blocksCount) -{ +void emlSetMem(uint8_t *data, int blockNum, int blocksCount) { emlSetMem_xt(data, blockNum, blocksCount, 16); } -void emlSetMem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtWidth) -{ +void emlSetMem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtWidth) { uint8_t *emCARD = BigBuf_get_EM_addr(); memcpy(emCARD + blockNum * blockBtWidth, data, blocksCount * blockBtWidth); } -void emlGetMem(uint8_t *data, int blockNum, int blocksCount) -{ +void emlGetMem(uint8_t *data, int blockNum, int blocksCount) { uint8_t *emCARD = BigBuf_get_EM_addr(); memcpy(data, emCARD + blockNum * 16, blocksCount * 16); } -void emlGetMemBt(uint8_t *data, int bytePtr, int byteCount) -{ +void emlGetMemBt(uint8_t *data, int bytePtr, int byteCount) { uint8_t *emCARD = BigBuf_get_EM_addr(); memcpy(data, emCARD + bytePtr, byteCount); } -int emlCheckValBl(int blockNum) -{ +int emlCheckValBl(int blockNum) { uint8_t *emCARD = BigBuf_get_EM_addr(); uint8_t *data = emCARD + blockNum * 16; if ((data[0] != (data[4] ^ 0xff)) || (data[0] != data[8]) || - (data[1] != (data[5] ^ 0xff)) || (data[1] != data[9]) || - (data[2] != (data[6] ^ 0xff)) || (data[2] != data[10]) || - (data[3] != (data[7] ^ 0xff)) || (data[3] != data[11]) || - (data[12] != (data[13] ^ 0xff)) || (data[12] != data[14]) || - (data[12] != (data[15] ^ 0xff)) + (data[1] != (data[5] ^ 0xff)) || (data[1] != data[9]) || + (data[2] != (data[6] ^ 0xff)) || (data[2] != data[10]) || + (data[3] != (data[7] ^ 0xff)) || (data[3] != data[11]) || + (data[12] != (data[13] ^ 0xff)) || (data[12] != data[14]) || + (data[12] != (data[15] ^ 0xff)) ) return 1; return 0; } -int emlGetValBl(uint32_t *blReg, uint8_t *blBlock, int blockNum) -{ +int emlGetValBl(uint32_t *blReg, uint8_t *blBlock, int blockNum) { uint8_t *emCARD = BigBuf_get_EM_addr(); uint8_t *data = emCARD + blockNum * 16; @@ -587,8 +561,7 @@ int emlGetValBl(uint32_t *blReg, uint8_t *blBlock, int blockNum) return 0; } -int emlSetValBl(uint32_t blReg, uint8_t blBlock, int blockNum) -{ +int emlSetValBl(uint32_t blReg, uint8_t blBlock, int blockNum) { uint8_t *emCARD = BigBuf_get_EM_addr(); uint8_t *data = emCARD + blockNum * 16; @@ -605,16 +578,14 @@ int emlSetValBl(uint32_t blReg, uint8_t blBlock, int blockNum) return 0; } -uint64_t emlGetKey(int sectorNum, int keyType) -{ +uint64_t emlGetKey(int sectorNum, int keyType) { uint8_t key[6] = {0x00}; uint8_t *emCARD = BigBuf_get_EM_addr(); memcpy(key, emCARD + 16 * (FirstBlockOfSector(sectorNum) + NumBlocksPerSector(sectorNum) - 1) + keyType * 10, 6); return bytes_to_num(key, 6); } -void emlClearMem(void) -{ +void emlClearMem(void) { const uint8_t trailer[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x80, 0x69, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; const uint8_t uid[] = {0xe6, 0x84, 0x87, 0xf3, 0x16, 0x88, 0x04, 0x00, 0x46, 0x8e, 0x45, 0x55, 0x4d, 0x70, 0x41, 0x04}; uint8_t *emCARD = BigBuf_get_EM_addr(); @@ -631,8 +602,7 @@ void emlClearMem(void) // Mifare desfire commands -int mifare_sendcmd_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t *data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) -{ +int mifare_sendcmd_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t *data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) { uint8_t dcmd[5] = {cmd, data[0], data[1], 0x00, 0x00}; AddCrc14A(dcmd, 3); @@ -645,8 +615,7 @@ int mifare_sendcmd_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cm return len; } -int mifare_sendcmd_special2(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t *data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) -{ +int mifare_sendcmd_special2(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t *data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) { uint8_t dcmd[20] = {0x00}; dcmd[0] = cmd; memcpy(dcmd + 1, data, 17); @@ -661,8 +630,7 @@ int mifare_sendcmd_special2(struct Crypto1State *pcs, uint8_t crypted, uint8_t c return len; } -int mifare_desfire_des_auth1(uint32_t uid, uint8_t *blockData) -{ +int mifare_desfire_des_auth1(uint32_t uid, uint8_t *blockData) { int len; // load key, keynumber @@ -690,8 +658,7 @@ int mifare_desfire_des_auth1(uint32_t uid, uint8_t *blockData) return 1; } -int mifare_desfire_des_auth2(uint32_t uid, uint8_t *key, uint8_t *blockData) -{ +int mifare_desfire_des_auth2(uint32_t uid, uint8_t *key, uint8_t *blockData) { int len; uint8_t data[17] = {MFDES_AUTHENTICATION_FRAME}; diff --git a/armsrc/optimized_cipher.c b/armsrc/optimized_cipher.c index 377e6f439..faf739beb 100644 --- a/armsrc/optimized_cipher.c +++ b/armsrc/optimized_cipher.c @@ -96,8 +96,7 @@ uint8_t xopt__select(bool x, bool y, uint8_t r) } */ -void opt_successor(const uint8_t *k, State *s, bool y, State *successor) -{ +void opt_successor(const uint8_t *k, State *s, bool y, State *successor) { uint8_t Tt = 1 & opt_T(s); successor->t = (s->t >> 1); @@ -110,8 +109,7 @@ void opt_successor(const uint8_t *k, State *s, bool y, State *successor) successor->l = successor->r + s->r; } -void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32Zeroes) -{ +void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32Zeroes) { State x2; int i; uint8_t head = 0; @@ -150,8 +148,7 @@ void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32 } } -void opt_output(const uint8_t *k, State *s, uint8_t *buffer) -{ +void opt_output(const uint8_t *k, State *s, uint8_t *buffer) { uint8_t times = 0; uint8_t bout = 0; State temp = {0, 0, 0, 0}; @@ -177,8 +174,7 @@ void opt_output(const uint8_t *k, State *s, uint8_t *buffer) } } -void opt_MAC(uint8_t *k, uint8_t *input, uint8_t *out) -{ +void opt_MAC(uint8_t *k, uint8_t *input, uint8_t *out) { State _init = { ((k[0] ^ 0x4c) + 0xEC) & 0xFF,// l ((k[0] ^ 0x4c) + 0x21) & 0xFF,// r @@ -190,23 +186,20 @@ void opt_MAC(uint8_t *k, uint8_t *input, uint8_t *out) opt_output(k, &_init, out); } -uint8_t rev_byte(uint8_t b) -{ +uint8_t rev_byte(uint8_t b) { b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; b = (b & 0xCC) >> 2 | (b & 0x33) << 2; b = (b & 0xAA) >> 1 | (b & 0x55) << 1; return b; } -void opt_reverse_arraybytecpy(uint8_t *dest, uint8_t *src, size_t len) -{ +void opt_reverse_arraybytecpy(uint8_t *dest, uint8_t *src, size_t len) { uint8_t i; for (i = 0; i < len ; i++) dest[i] = rev_byte(src[i]); } -void opt_doReaderMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4]) -{ +void opt_doReaderMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4]) { static uint8_t cc_nr[12]; opt_reverse_arraybytecpy(cc_nr, cc_nr_p, 12); uint8_t dest [] = {0, 0, 0, 0, 0, 0, 0, 0}; @@ -215,8 +208,7 @@ void opt_doReaderMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4]) opt_reverse_arraybytecpy(mac, dest, 4); return; } -void opt_doTagMAC(uint8_t *cc_p, const uint8_t *div_key_p, uint8_t mac[4]) -{ +void opt_doTagMAC(uint8_t *cc_p, const uint8_t *div_key_p, uint8_t mac[4]) { static uint8_t cc_nr[8 + 4 + 4]; opt_reverse_arraybytecpy(cc_nr, cc_p, 12); State _init = { @@ -241,8 +233,7 @@ void opt_doTagMAC(uint8_t *cc_p, const uint8_t *div_key_p, uint8_t mac[4]) * @param div_key_p * @return the cipher state */ -State opt_doTagMAC_1(uint8_t *cc_p, const uint8_t *div_key_p) -{ +State opt_doTagMAC_1(uint8_t *cc_p, const uint8_t *div_key_p) { static uint8_t cc_nr[8]; opt_reverse_arraybytecpy(cc_nr, cc_p, 8); State _init = { @@ -263,8 +254,7 @@ State opt_doTagMAC_1(uint8_t *cc_p, const uint8_t *div_key_p) * @param mac - where to store the MAC * @param div_key_p - the key to use */ -void opt_doTagMAC_2(State _init, uint8_t *nr, uint8_t mac[4], const uint8_t *div_key_p) -{ +void opt_doTagMAC_2(State _init, uint8_t *nr, uint8_t mac[4], const uint8_t *div_key_p) { static uint8_t _nr[4]; opt_reverse_arraybytecpy(_nr, nr, 4); opt_suc(div_key_p, &_init, _nr, 4, true); diff --git a/armsrc/pcf7931.c b/armsrc/pcf7931.c index 568083d7d..ef371b233 100644 --- a/armsrc/pcf7931.c +++ b/armsrc/pcf7931.c @@ -3,8 +3,7 @@ #define T0_PCF 8 //period for the pcf7931 in us #define ALLOC 16 -size_t DemodPCF7931(uint8_t **outBlocks) -{ +size_t DemodPCF7931(uint8_t **outBlocks) { uint8_t bits[256] = {0x00}; uint8_t blocks[8][16]; uint8_t *dest = BigBuf_get_addr(); @@ -128,8 +127,7 @@ size_t DemodPCF7931(uint8_t **outBlocks) return num_blocks; } -bool IsBlock0PCF7931(uint8_t *block) -{ +bool IsBlock0PCF7931(uint8_t *block) { // assuming all RFU bits are set to 0 // if PAC is enabled password is set to 0 if (block[7] == 0x01) { @@ -142,8 +140,7 @@ bool IsBlock0PCF7931(uint8_t *block) return false; } -bool IsBlock1PCF7931(uint8_t *block) -{ +bool IsBlock1PCF7931(uint8_t *block) { // assuming all RFU bits are set to 0 if (block[10] == 0 && block[11] == 0 && block[12] == 0 && block[13] == 0) if ((block[14] & 0x7f) <= 9 && block[15] <= 9) @@ -152,8 +149,7 @@ bool IsBlock1PCF7931(uint8_t *block) return false; } -void ReadPCF7931() -{ +void ReadPCF7931() { int found_blocks = 0; // successfully read blocks int max_blocks = 8; // readable blocks uint8_t memory_blocks[8][17]; // PCF content @@ -303,8 +299,7 @@ end: cmd_send(CMD_ACK, 0, 0, 0, 0, 0); } -static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) -{ +static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) { uint32_t tab[1024] = {0}; // data times frame uint32_t u = 0; uint8_t parity = 0; @@ -386,8 +381,7 @@ static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int3 @param byte : address of the byte to write @param data : data to write */ -void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, uint8_t pass5, uint8_t pass6, uint8_t pass7, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) -{ +void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, uint8_t pass5, uint8_t pass6, uint8_t pass7, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) { Dbprintf("Initialization delay : %d us", init_delay); Dbprintf("Offsets : %d us on the low pulses width, %d us on the low pulses positions", l, p); Dbprintf("Password (LSB first on each byte): %02x %02x %02x %02x %02x %02x %02x", pass1, pass2, pass3, pass4, pass5, pass6, pass7); @@ -405,8 +399,7 @@ void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, ui * @param tab : array of the data frame */ -void SendCmdPCF7931(uint32_t *tab) -{ +void SendCmdPCF7931(uint32_t *tab) { uint16_t u = 0, tempo = 0; Dbprintf("Sending data frame..."); @@ -462,8 +455,7 @@ void SendCmdPCF7931(uint32_t *tab) * @param l : offset on low pulse width * @param p : offset on low pulse positioning */ -bool AddBytePCF7931(uint8_t byte, uint32_t *tab, int32_t l, int32_t p) -{ +bool AddBytePCF7931(uint8_t byte, uint32_t *tab, int32_t l, int32_t p) { uint32_t u; for (u = 0; u < 8; ++u) { if (byte & (1 << u)) { //bit is 1 @@ -482,8 +474,7 @@ bool AddBytePCF7931(uint8_t byte, uint32_t *tab, int32_t l, int32_t p) * @param l : offset on low pulse width * @param p : offset on low pulse positioning */ -bool AddBitPCF7931(bool b, uint32_t *tab, int32_t l, int32_t p) -{ +bool AddBitPCF7931(bool b, uint32_t *tab, int32_t l, int32_t p) { uint8_t u = 0; //we put the cursor at the last value of the array @@ -518,8 +509,7 @@ bool AddBitPCF7931(bool b, uint32_t *tab, int32_t l, int32_t p) * @param c : delay of the last high pulse * @param tab : array of the data frame */ -bool AddPatternPCF7931(uint32_t a, uint32_t b, uint32_t c, uint32_t *tab) -{ +bool AddPatternPCF7931(uint32_t a, uint32_t b, uint32_t c, uint32_t *tab) { uint32_t u = 0; for (u = 0; tab[u] != 0; u += 3) {} //we put the cursor at the last value of the array diff --git a/armsrc/printf.c b/armsrc/printf.c index a355fe2ff..e2862f79e 100644 --- a/armsrc/printf.c +++ b/armsrc/printf.c @@ -59,8 +59,7 @@ char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz"; * The buffer pointed to by `nbuf' must have length >= MAXNBUF. */ static char * -ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) -{ +ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) { char *p, c; p = nbuf; @@ -101,8 +100,7 @@ ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) * ("%*D", len, ptr, " " -> XX XX XX XX ... */ int -kvsprintf(char const *fmt, void *arg, int radix, va_list ap) -{ +kvsprintf(char const *fmt, void *arg, int radix, va_list ap) { #define PCHAR(c) {int cc=(c); *d++ = cc; retval++; } char nbuf[MAXNBUF]; char *d; @@ -387,7 +385,7 @@ number: tmp++; if (!ladjust && padc != '0' && width - && (width -= tmp) > 0) + && (width -= tmp) > 0) while (width--) PCHAR(padc); if (neg) @@ -430,14 +428,12 @@ number: #undef PCHAR } -int vsprintf(char *dest, const char *fmt, va_list ap) -{ +int vsprintf(char *dest, const char *fmt, va_list ap) { return kvsprintf(fmt, dest, 10, ap); } int -sprintf(char *dest, const char *fmt, ...) -{ +sprintf(char *dest, const char *fmt, ...) { /* http://www.pagetable.com/?p=298 */ int retval; va_list ap; diff --git a/armsrc/start.c b/armsrc/start.c index df5e30506..a6503f1ea 100644 --- a/armsrc/start.c +++ b/armsrc/start.c @@ -21,8 +21,7 @@ static uint8_t *next_free_memory; extern struct common_area common_area; extern char __data_src_start__, __data_start__, __data_end__, __bss_start__, __bss_end__; -static voidpf inflate_malloc(voidpf opaque, uInt items, uInt size) -{ +static voidpf inflate_malloc(voidpf opaque, uInt items, uInt size) { uint8_t *allocated_memory; allocated_memory = next_free_memory; @@ -30,13 +29,11 @@ static voidpf inflate_malloc(voidpf opaque, uInt items, uInt size) return allocated_memory; } -static void inflate_free(voidpf opaque, voidpf address) -{ +static void inflate_free(voidpf opaque, voidpf address) { // nothing to do } -static void uncompress_data_section(void) -{ +static void uncompress_data_section(void) { z_stream data_section; next_free_memory = BigBuf_get_addr(); @@ -60,8 +57,7 @@ static void uncompress_data_section(void) common_area.arg1 = data_section.total_in; } -void __attribute__((section(".startos"))) Vector(void) -{ +void __attribute__((section(".startos"))) Vector(void) { /* Stack should have been set up by the bootloader */ // char *src; char *dst, *end; diff --git a/armsrc/string.c b/armsrc/string.c index 5f188fbc4..fe53bf5f4 100644 --- a/armsrc/string.c +++ b/armsrc/string.c @@ -9,8 +9,7 @@ //----------------------------------------------------------------------------- #include "string.h" -void *memcpy(void *dest, const void *src, int len) -{ +void *memcpy(void *dest, const void *src, int len) { uint8_t *d = dest; const uint8_t *s = src; while ((len--) > 0) { @@ -21,8 +20,7 @@ void *memcpy(void *dest, const void *src, int len) return dest; } -void *memset(void *dest, int c, int len) -{ +void *memset(void *dest, int c, int len) { uint8_t *d = dest; while ((len--) > 0) { *d = c; @@ -31,8 +29,7 @@ void *memset(void *dest, int c, int len) return dest; } -int memcmp(const void *av, const void *bv, int len) -{ +int memcmp(const void *av, const void *bv, int len) { const uint8_t *a = av; const uint8_t *b = bv; @@ -46,14 +43,12 @@ int memcmp(const void *av, const void *bv, int len) return 0; } -void memxor(uint8_t *dest, uint8_t *src, size_t len) -{ +void memxor(uint8_t *dest, uint8_t *src, size_t len) { for (; len > 0; len--, dest++, src++) *dest ^= *src; } -int strlen(const char *str) -{ +int strlen(const char *str) { int l = 0; while (*str) { l++; @@ -62,8 +57,7 @@ int strlen(const char *str) return l; } -char *strncat(char *dest, const char *src, unsigned int n) -{ +char *strncat(char *dest, const char *src, unsigned int n) { unsigned int dest_len = strlen(dest); unsigned int i; @@ -74,8 +68,7 @@ char *strncat(char *dest, const char *src, unsigned int n) return dest; } -char *strcat(char *dest, const char *src) -{ +char *strcat(char *dest, const char *src) { unsigned int dest_len = strlen(dest); unsigned int i; @@ -88,8 +81,7 @@ char *strcat(char *dest, const char *src) ////////////////////////////////////////// code to do 'itoa' /* reverse: reverse string s in place */ -void strreverse(char s[]) -{ +void strreverse(char s[]) { int c, i, j; for (i = 0, j = strlen(s) - 1; i < j; i++, j--) { @@ -100,8 +92,7 @@ void strreverse(char s[]) } /* itoa: convert n to characters in s */ -void itoa(int n, char s[]) -{ +void itoa(int n, char s[]) { int i, sign; if ((sign = n) < 0) /* record sign */ diff --git a/armsrc/ticks.c b/armsrc/ticks.c index f30916003..73f68147f 100644 --- a/armsrc/ticks.c +++ b/armsrc/ticks.c @@ -11,8 +11,7 @@ #include "ticks.h" // attempt at high resolution microsecond timer // beware: timer counts in 21.3uS increments (1024/48Mhz) -void SpinDelayUs(int us) -{ +void SpinDelayUs(int us) { int ticks = (48 * us) >> 10; // Borrow a PWM unit for my real-time clock @@ -34,8 +33,7 @@ void SpinDelayUs(int us) } } -void SpinDelay(int ms) -{ +void SpinDelay(int ms) { // convert to uS and call microsecond delay function SpinDelayUs(ms * 1000); } @@ -48,8 +46,7 @@ void SpinDelay(int ms) // SpinDelay(1000); // ti = GetTickCount() - ti; // Dbprintf("timer(1s): %d t=%d", ti, GetTickCount()); -void StartTickCount(void) -{ +void StartTickCount(void) { // This timer is based on the slow clock. The slow clock frequency is between 22kHz and 40kHz. // We can determine the actual slow clock frequency by looking at the Main Clock Frequency Register. uint16_t mainf = AT91C_BASE_PMC->PMC_MCFR & 0xffff; // = 16 * main clock frequency (16MHz) / slow clock frequency @@ -61,16 +58,14 @@ void StartTickCount(void) /* * Get the current count. */ -uint32_t RAMFUNC GetTickCount(void) -{ +uint32_t RAMFUNC GetTickCount(void) { return AT91C_BASE_RTTC->RTTC_RTVR;// was * 2; } // ------------------------------------------------------------------------- // microseconds timer // ------------------------------------------------------------------------- -void StartCountUS(void) -{ +void StartCountUS(void) { AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1); AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC0XC0S_NONE | AT91C_TCB_TC1XC1S_TIOA0 | AT91C_TCB_TC2XC2S_NONE; @@ -93,8 +88,7 @@ void StartCountUS(void) while (AT91C_BASE_TC1->TC_CV > 0); } -uint32_t RAMFUNC GetCountUS(void) -{ +uint32_t RAMFUNC GetCountUS(void) { //return (AT91C_BASE_TC1->TC_CV * 0x8000) + ((AT91C_BASE_TC0->TC_CV / 15) * 10); // By suggestion from PwPiwi, http://www.proxmark.org/forum/viewtopic.php?pid=17548#p17548 return ((uint32_t)AT91C_BASE_TC1->TC_CV) * 0x8000 + (((uint32_t)AT91C_BASE_TC0->TC_CV) * 2) / 3; @@ -103,8 +97,7 @@ uint32_t RAMFUNC GetCountUS(void) // ------------------------------------------------------------------------- // Timer for iso14443 commands. Uses ssp_clk from FPGA // ------------------------------------------------------------------------- -void StartCountSspClk(void) -{ +void StartCountSspClk(void) { AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1) | (1 << AT91C_ID_TC2); // Enable Clock to all timers AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC0XC0S_TIOA1 // XC0 Clock = TIOA1 | AT91C_TCB_TC1XC1S_NONE // XC1 Clock = none @@ -161,16 +154,14 @@ void StartCountSspClk(void) // Therefore need to wait quite some time before we can use the counter. while (AT91C_BASE_TC2->TC_CV > 0); } -void ResetSspClk(void) -{ +void ResetSspClk(void) { //enable clock of timer and software trigger AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; AT91C_BASE_TC2->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; while (AT91C_BASE_TC2->TC_CV > 0); } -uint32_t RAMFUNC GetCountSspClk(void) -{ +uint32_t RAMFUNC GetCountSspClk(void) { uint32_t tmp_count = (AT91C_BASE_TC2->TC_CV << 16) | AT91C_BASE_TC0->TC_CV; if ((tmp_count & 0x0000ffff) == 0) //small chance that we may have missed an increment in TC2 return (AT91C_BASE_TC2->TC_CV << 16); @@ -181,8 +172,7 @@ uint32_t RAMFUNC GetCountSspClk(void) // Timer for bitbanging, or LF stuff when you need a very precis timer // 1us = 1.5ticks // ------------------------------------------------------------------------- -void StartTicks(void) -{ +void StartTicks(void) { // initialization of the timer AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1); AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC0XC0S_NONE | AT91C_TCB_TC1XC1S_TIOA0 | AT91C_TCB_TC2XC2S_NONE; @@ -215,8 +205,7 @@ void StartTicks(void) while (AT91C_BASE_TC0->TC_CV > 0); } -uint32_t GetTicks(void) -{ +uint32_t GetTicks(void) { uint32_t hi, lo; do { @@ -229,8 +218,7 @@ uint32_t GetTicks(void) // Wait - Spindelay in ticks. // if called with a high number, this will trigger the WDT... -void WaitTicks(uint32_t ticks) -{ +void WaitTicks(uint32_t ticks) { if (ticks == 0) return; ticks += GetTicks(); while (GetTicks() < ticks); @@ -238,18 +226,15 @@ void WaitTicks(uint32_t ticks) // Wait / Spindelay in us (microseconds) // 1us = 1.5ticks. -void WaitUS(uint16_t us) -{ +void WaitUS(uint16_t us) { WaitTicks((uint32_t)us * 3 / 2); } -void WaitMS(uint16_t ms) -{ +void WaitMS(uint16_t ms) { WaitTicks((uint32_t)ms * 1500); } // stop clock -void StopTicks(void) -{ +void StopTicks(void) { AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; } diff --git a/armsrc/util.c b/armsrc/util.c index 76b5d96cb..8ee91b464 100644 --- a/armsrc/util.c +++ b/armsrc/util.c @@ -9,8 +9,7 @@ //----------------------------------------------------------------------------- #include "util.h" -size_t nbytes(size_t nbits) -{ +size_t nbytes(size_t nbits) { return (nbits >> 3) + ((nbits % 8) > 0); } @@ -19,8 +18,7 @@ size_t nbytes(size_t nbits) Returns the value v with the bottom b [0,32] bits reflected. Example: reflect(0x3e23L,3) == 0x3e26 */ -uint32_t reflect(uint32_t v, int b) -{ +uint32_t reflect(uint32_t v, int b) { uint32_t t = v; for (int i = 0; i < b; ++i) { if (t & 1) @@ -32,12 +30,10 @@ uint32_t reflect(uint32_t v, int b) return v; } -uint8_t reflect8(uint8_t b) -{ +uint8_t reflect8(uint8_t b) { return ((b * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32; } -uint16_t reflect16(uint16_t b) -{ +uint16_t reflect16(uint16_t b) { uint16_t v = 0; v |= (b & 0x8000) >> 15; v |= (b & 0x4000) >> 13; @@ -59,16 +55,14 @@ uint16_t reflect16(uint16_t b) return v; } -void num_to_bytes(uint64_t n, size_t len, uint8_t *dest) -{ +void num_to_bytes(uint64_t n, size_t len, uint8_t *dest) { while (len--) { dest[len] = (uint8_t) n; n >>= 8; } } -uint64_t bytes_to_num(uint8_t *src, size_t len) -{ +uint64_t bytes_to_num(uint8_t *src, size_t len) { uint64_t num = 0; while (len--) { num = (num << 8) | (*src); @@ -78,8 +72,7 @@ uint64_t bytes_to_num(uint8_t *src, size_t len) } // RotateLeft - Ultralight, Desfire -void rol(uint8_t *data, const size_t len) -{ +void rol(uint8_t *data, const size_t len) { uint8_t first = data[0]; for (size_t i = 0; i < len - 1; i++) { data[i] = data[i + 1]; @@ -87,22 +80,19 @@ void rol(uint8_t *data, const size_t len) data[len - 1] = first; } -void lsl(uint8_t *data, size_t len) -{ +void lsl(uint8_t *data, size_t len) { for (size_t n = 0; n < len - 1; n++) { data[n] = (data[n] << 1) | (data[n + 1] >> 7); } data[len - 1] <<= 1; } -int32_t le24toh(uint8_t data[3]) -{ +int32_t le24toh(uint8_t data[3]) { return (data[2] << 16) | (data[1] << 8) | data[0]; } //convert hex digit to integer -uint8_t hex2int(char hexchar) -{ +uint8_t hex2int(char hexchar) { switch (hexchar) { case '0': return 0; @@ -163,8 +153,7 @@ uint8_t hex2int(char hexchar) } } -void LEDsoff() -{ +void LEDsoff() { LED_A_OFF(); LED_B_OFF(); LED_C_OFF(); @@ -172,8 +161,7 @@ void LEDsoff() } // LEDs: R(C) O(A) G(B) -- R(D) [1, 2, 4 and 8] -void LED(int led, int ms) -{ +void LED(int led, int ms) { if (led & LED_RED) LED_C_ON(); if (led & LED_ORANGE) @@ -198,8 +186,7 @@ void LED(int led, int ms) LED_D_OFF(); } -void SpinOff(uint32_t pause) -{ +void SpinOff(uint32_t pause) { LED_A_OFF(); LED_B_OFF(); LED_C_OFF(); @@ -208,8 +195,7 @@ void SpinOff(uint32_t pause) } // 0=A, 1=B, 2=C, 3=D -void SpinErr(uint8_t led, uint32_t speed, uint8_t times) -{ +void SpinErr(uint8_t led, uint32_t speed, uint8_t times) { SpinOff(speed); NTIME(times) { switch (led) { @@ -230,8 +216,7 @@ void SpinErr(uint8_t led, uint32_t speed, uint8_t times) } } -void SpinDown(uint32_t speed) -{ +void SpinDown(uint32_t speed) { SpinOff(speed); LED_D_ON(); SpinDelay(speed); @@ -247,8 +232,7 @@ void SpinDown(uint32_t speed) LED_A_OFF(); } -void SpinUp(uint32_t speed) -{ +void SpinUp(uint32_t speed) { SpinOff(speed); LED_A_ON(); SpinDelay(speed); @@ -269,8 +253,7 @@ void SpinUp(uint32_t speed) // not clicked, or held down (for ms || 1sec) // In general, don't use this function unless you expect a // double click, otherwise it will waste 500ms -- use BUTTON_HELD instead -int BUTTON_CLICKED(int ms) -{ +int BUTTON_CLICKED(int ms) { // Up to 500ms in between clicks to mean a double click int ticks = (48000 * (ms ? ms : 1000)) >> 10; @@ -328,8 +311,7 @@ int BUTTON_CLICKED(int ms) } // Determine if a button is held down -int BUTTON_HELD(int ms) -{ +int BUTTON_HELD(int ms) { // If button is held for one second int ticks = (48000 * (ms ? ms : 1000)) >> 10; @@ -369,8 +351,7 @@ int BUTTON_HELD(int ms) * verifies the magic properties, then stores a formatted string, prefixed by * prefix in dst. */ -void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_information) -{ +void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_information) { struct version_information *v = (struct version_information *)version_information; dst[0] = 0; strncat(dst, prefix, len - 1); diff --git a/armsrc/vtsend.c b/armsrc/vtsend.c index 666e1aef7..e851d4334 100644 --- a/armsrc/vtsend.c +++ b/armsrc/vtsend.c @@ -37,15 +37,13 @@ //#define UART_WRITE(P, BUF, SIZ) (P)->uart_write(BUF, SIZ, (P)->extobj) #define UART_WRITE(BUF) DbprintfEx(FLAG_RAWPRINT, "%s", BUF) -int vtsend_init(vtsend_t *p, VTSEND_SERIAL_WRITE uart_write, void *extobj) -{ +int vtsend_init(vtsend_t *p, VTSEND_SERIAL_WRITE uart_write, void *extobj) { p->uart_write = uart_write; p->extobj = extobj; return 0; } -int vtsend_cursor_position(vtsend_t *p, const int column, const int line) -{ +int vtsend_cursor_position(vtsend_t *p, const int column, const int line) { char buf[1 + 8]; buf[0] = ESC; buf[1] = '['; @@ -60,8 +58,7 @@ int vtsend_cursor_position(vtsend_t *p, const int column, const int line) return 0; } -int vtsend_cursor_up(vtsend_t *p, const int n) -{ +int vtsend_cursor_up(vtsend_t *p, const int n) { char buf[1 + 5]; buf[0] = ESC; buf[1] = '['; @@ -74,8 +71,7 @@ int vtsend_cursor_up(vtsend_t *p, const int n) return 0; } -int vtsend_cursor_down(vtsend_t *p, const int n) -{ +int vtsend_cursor_down(vtsend_t *p, const int n) { char buf[1 + 5]; buf[0] = ESC; buf[1] = '['; @@ -88,8 +84,7 @@ int vtsend_cursor_down(vtsend_t *p, const int n) return 0; } -int vtsend_cursor_forward(vtsend_t *p, const int n) -{ +int vtsend_cursor_forward(vtsend_t *p, const int n) { char buf[1 + 5]; buf[0] = ESC; buf[1] = '['; @@ -102,8 +97,7 @@ int vtsend_cursor_forward(vtsend_t *p, const int n) return 0; } -int vtsend_cursor_backward(vtsend_t *p, const int n) -{ +int vtsend_cursor_backward(vtsend_t *p, const int n) { char buf[1 + 5]; buf[0] = ESC; buf[1] = '['; @@ -116,8 +110,7 @@ int vtsend_cursor_backward(vtsend_t *p, const int n) return 0; } -int vtsend_cursor_position_save(vtsend_t *p) -{ +int vtsend_cursor_position_save(vtsend_t *p) { char buf[1 + 3]; buf[0] = ESC; buf[1] = '['; @@ -128,8 +121,7 @@ int vtsend_cursor_position_save(vtsend_t *p) return 0; } -int vtsend_cursor_position_restore(vtsend_t *p) -{ +int vtsend_cursor_position_restore(vtsend_t *p) { char buf[1 + 3]; buf[0] = ESC; buf[1] = '['; @@ -140,8 +132,7 @@ int vtsend_cursor_position_restore(vtsend_t *p) return 0; } -int vtsend_erase_display(vtsend_t *p) -{ +int vtsend_erase_display(vtsend_t *p) { char buf[1 + 4]; buf[0] = ESC; buf[1] = '['; @@ -153,8 +144,7 @@ int vtsend_erase_display(vtsend_t *p) return 0; } -int vtsend_erase_line(vtsend_t *p) -{ +int vtsend_erase_line(vtsend_t *p) { char buf[1 + 4]; buf[0] = ESC; buf[1] = '['; @@ -166,8 +156,7 @@ int vtsend_erase_line(vtsend_t *p) return 0; } -int vtsend_set_color_foreground(vtsend_t *p, const int color) -{ +int vtsend_set_color_foreground(vtsend_t *p, const int color) { char buf[1 + 5]; buf[0] = ESC; buf[1] = '['; @@ -180,8 +169,7 @@ int vtsend_set_color_foreground(vtsend_t *p, const int color) return 0; } -int vtsend_set_color_background(vtsend_t *p, const int color) -{ +int vtsend_set_color_background(vtsend_t *p, const int color) { char buf[1 + 5]; buf[0] = ESC; buf[1] = '['; @@ -194,8 +182,7 @@ int vtsend_set_color_background(vtsend_t *p, const int color) return 0; } -int vtsend_set_attribute(vtsend_t *p, const int attr) -{ +int vtsend_set_attribute(vtsend_t *p, const int attr) { char buf[1 + 5]; buf[0] = ESC; buf[1] = '['; @@ -208,8 +195,7 @@ int vtsend_set_attribute(vtsend_t *p, const int attr) return 0; } -int vtsend_set_scroll_region(vtsend_t *p, const int top, const int bottom) -{ +int vtsend_set_scroll_region(vtsend_t *p, const int top, const int bottom) { char buf[1 + 8]; buf[0] = ESC; buf[1] = '['; @@ -225,8 +211,7 @@ int vtsend_set_scroll_region(vtsend_t *p, const int top, const int bottom) return 0; } -int vtsend_set_cursor(vtsend_t *p, const int visible) -{ +int vtsend_set_cursor(vtsend_t *p, const int visible) { if (visible) { char buf[1 + 6]; buf[0] = ESC; @@ -253,8 +238,7 @@ int vtsend_set_cursor(vtsend_t *p, const int visible) return 0; } -int vtsend_reset(vtsend_t *p) -{ +int vtsend_reset(vtsend_t *p) { char buf[1 + 2]; buf[0] = ESC; buf[1] = 'c'; @@ -264,8 +248,7 @@ int vtsend_reset(vtsend_t *p) return 0; } -int vtsend_draw_box(vtsend_t *p, const int x1, const int y1, const int x2, const int y2) -{ +int vtsend_draw_box(vtsend_t *p, const int x1, const int y1, const int x2, const int y2) { int i; vtsend_cursor_position(p, x1, y1); @@ -285,8 +268,7 @@ int vtsend_draw_box(vtsend_t *p, const int x1, const int y1, const int x2, const return 0; } -int vtsend_fill_box(vtsend_t *p, const int x1, const int y1, const int x2, const int y2) -{ +int vtsend_fill_box(vtsend_t *p, const int x1, const int y1, const int x2, const int y2) { int i, j; for (i = y1; i <= y2; i++) { vtsend_cursor_position(p, x1, i); diff --git a/bootrom/bootrom.c b/bootrom/bootrom.c index ec1922cb5..2b5c49e78 100644 --- a/bootrom/bootrom.c +++ b/bootrom/bootrom.c @@ -15,8 +15,7 @@ unsigned int start_addr, end_addr, bootrom_unlocked; extern char _bootrom_start, _bootrom_end, _flash_start, _flash_end; extern uint32_t _osimage_entry; -void DbpString(char *str) -{ +void DbpString(char *str) { byte_t len = 0; while (str[len] != 0x00) len++; @@ -24,8 +23,7 @@ void DbpString(char *str) cmd_send(CMD_DEBUG_PRINT_STRING, len, 0, 0, (byte_t *)str, len); } -static void ConfigClocks(void) -{ +static void ConfigClocks(void) { // we are using a 16 MHz crystal as the basis for everything // slow clock runs at 32Khz typical regardless of crystal @@ -82,13 +80,11 @@ static void ConfigClocks(void) while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY)) {}; } -static void Fatal(void) -{ +static void Fatal(void) { for (;;) {}; } -void UsbPacketReceived(uint8_t *packet, int len) -{ +void UsbPacketReceived(uint8_t *packet, int len) { int i, dont_ack = 0; UsbCommand *c = (UsbCommand *)packet; volatile uint32_t *p; @@ -175,8 +171,8 @@ void UsbPacketReceived(uint8_t *packet, int len) * bootrom area. In any case they must be within the flash area. */ if ((bootrom_unlocked || ((cmd_start >= prot_end) || (cmd_end < prot_start))) && - (cmd_start >= allow_start) && - (cmd_end <= allow_end)) { + (cmd_start >= allow_start) && + (cmd_end <= allow_end)) { start_addr = cmd_start; end_addr = cmd_end; } else { @@ -197,8 +193,7 @@ void UsbPacketReceived(uint8_t *packet, int len) cmd_send(CMD_ACK, arg0, 0, 0, 0, 0); } -static void flash_mode(int externally_entered) -{ +static void flash_mode(int externally_entered) { start_addr = 0; end_addr = 0; bootrom_unlocked = 0; @@ -232,8 +227,7 @@ static void flash_mode(int externally_entered) } } -void BootROM(void) -{ +void BootROM(void) { //------------ // First set up all the I/O pins; GPIOs configured directly, other ones // just need to be assigned to the appropriate peripheral. diff --git a/client/amiitool/amiibo.c b/client/amiitool/amiibo.c index 34038fba3..a8596e30a 100644 --- a/client/amiitool/amiibo.c +++ b/client/amiitool/amiibo.c @@ -12,8 +12,7 @@ #define HMAC_POS_DATA 0x008 #define HMAC_POS_TAG 0x1B4 -void nfc3d_amiibo_calc_seed(const uint8_t *dump, uint8_t *key) -{ +void nfc3d_amiibo_calc_seed(const uint8_t *dump, uint8_t *key) { memcpy(key + 0x00, dump + 0x029, 0x02); memset(key + 0x02, 0x00, 0x0E); memcpy(key + 0x10, dump + 0x1D4, 0x08); @@ -21,16 +20,14 @@ void nfc3d_amiibo_calc_seed(const uint8_t *dump, uint8_t *key) memcpy(key + 0x20, dump + 0x1E8, 0x20); } -void nfc3d_amiibo_keygen(const nfc3d_keygen_masterkeys *masterKeys, const uint8_t *dump, nfc3d_keygen_derivedkeys *derivedKeys) -{ +void nfc3d_amiibo_keygen(const nfc3d_keygen_masterkeys *masterKeys, const uint8_t *dump, nfc3d_keygen_derivedkeys *derivedKeys) { uint8_t seed[NFC3D_KEYGEN_SEED_SIZE]; nfc3d_amiibo_calc_seed(dump, seed); nfc3d_keygen(masterKeys, seed, derivedKeys); } -void nfc3d_amiibo_cipher(const nfc3d_keygen_derivedkeys *keys, const uint8_t *in, uint8_t *out) -{ +void nfc3d_amiibo_cipher(const nfc3d_keygen_derivedkeys *keys, const uint8_t *in, uint8_t *out) { mbedtls_aes_context aes; size_t nc_off = 0; unsigned char nonce_counter[16]; @@ -49,8 +46,7 @@ void nfc3d_amiibo_cipher(const nfc3d_keygen_derivedkeys *keys, const uint8_t *in memcpy(out + 0x1D4, in + 0x1D4, 0x034); } -void nfc3d_amiibo_tag_to_internal(const uint8_t *tag, uint8_t *intl) -{ +void nfc3d_amiibo_tag_to_internal(const uint8_t *tag, uint8_t *intl) { memcpy(intl + 0x000, tag + 0x008, 0x008); memcpy(intl + 0x008, tag + 0x080, 0x020); memcpy(intl + 0x028, tag + 0x010, 0x024); @@ -60,8 +56,7 @@ void nfc3d_amiibo_tag_to_internal(const uint8_t *tag, uint8_t *intl) memcpy(intl + 0x1DC, tag + 0x054, 0x02C); } -void nfc3d_amiibo_internal_to_tag(const uint8_t *intl, uint8_t *tag) -{ +void nfc3d_amiibo_internal_to_tag(const uint8_t *intl, uint8_t *tag) { memcpy(tag + 0x008, intl + 0x000, 0x008); memcpy(tag + 0x080, intl + 0x008, 0x020); memcpy(tag + 0x010, intl + 0x028, 0x024); @@ -71,8 +66,7 @@ void nfc3d_amiibo_internal_to_tag(const uint8_t *intl, uint8_t *tag) memcpy(tag + 0x054, intl + 0x1DC, 0x02C); } -bool nfc3d_amiibo_unpack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *tag, uint8_t *plain) -{ +bool nfc3d_amiibo_unpack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *tag, uint8_t *plain) { uint8_t internal[NFC3D_AMIIBO_SIZE]; nfc3d_keygen_derivedkeys dataKeys; nfc3d_keygen_derivedkeys tagKeys; @@ -100,8 +94,7 @@ bool nfc3d_amiibo_unpack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *tag memcmp(plain + HMAC_POS_TAG, internal + HMAC_POS_TAG, 32) == 0; } -void nfc3d_amiibo_pack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *plain, uint8_t *tag) -{ +void nfc3d_amiibo_pack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *plain, uint8_t *tag) { uint8_t cipher[NFC3D_AMIIBO_SIZE]; nfc3d_keygen_derivedkeys tagKeys; nfc3d_keygen_derivedkeys dataKeys; @@ -137,8 +130,7 @@ void nfc3d_amiibo_pack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *plain nfc3d_amiibo_internal_to_tag(cipher, tag); } -bool nfc3d_amiibo_load_keys(nfc3d_amiibo_keys *amiiboKeys, const char *path) -{ +bool nfc3d_amiibo_load_keys(nfc3d_amiibo_keys *amiiboKeys, const char *path) { FILE *f = fopen(path, "rb"); if (!f) { return false; @@ -160,8 +152,7 @@ bool nfc3d_amiibo_load_keys(nfc3d_amiibo_keys *amiiboKeys, const char *path) return true; } -void nfc3d_amiibo_copy_app_data(const uint8_t *src, uint8_t *dst) -{ +void nfc3d_amiibo_copy_app_data(const uint8_t *src, uint8_t *dst) { //uint16_t *ami_nb_wr = (uint16_t*)(dst + 0x29); diff --git a/client/amiitool/amiitool.c b/client/amiitool/amiitool.c index 9d30e4cb7..a687cb0b1 100644 --- a/client/amiitool/amiitool.c +++ b/client/amiitool/amiitool.c @@ -14,8 +14,7 @@ static char *self; -void amiitool_usage() -{ +void amiitool_usage() { fprintf(stderr, "amiitool build %i (commit %s-%08x)\n" "by Marcos Del Sol Vives \n" @@ -33,8 +32,7 @@ void amiitool_usage() ); } -static bool LoadAmiikey(nfc3d_amiibo_keys keys, char *keyfile) -{ +static bool LoadAmiikey(nfc3d_amiibo_keys keys, char *keyfile) { if (!nfc3d_amiibo_load_keys(&keys, keyfile)) { PrintAndLogEx(ERR, "Could not load keys from '%s'", keyfile); @@ -43,8 +41,7 @@ static bool LoadAmiikey(nfc3d_amiibo_keys keys, char *keyfile) return true; } -int main(int argc, char **argv) -{ +int main(int argc, char **argv) { self = argv[0]; char *infile = NULL; diff --git a/client/amiitool/drbg.c b/client/amiitool/drbg.c index e350ffdf3..623a29776 100644 --- a/client/amiitool/drbg.c +++ b/client/amiitool/drbg.c @@ -10,8 +10,7 @@ #include #include -void nfc3d_drbg_init(nfc3d_drbg_ctx *ctx, const uint8_t *hmacKey, size_t hmacKeySize, const uint8_t *seed, size_t seedSize) -{ +void nfc3d_drbg_init(nfc3d_drbg_ctx *ctx, const uint8_t *hmacKey, size_t hmacKeySize, const uint8_t *seed, size_t seedSize) { assert(ctx != NULL); assert(hmacKey != NULL); assert(seed != NULL); @@ -31,8 +30,7 @@ void nfc3d_drbg_init(nfc3d_drbg_ctx *ctx, const uint8_t *hmacKey, size_t hmacKey mbedtls_md_hmac_starts(&ctx->hmacCtx, hmacKey, hmacKeySize); } -void nfc3d_drbg_step(nfc3d_drbg_ctx *ctx, uint8_t *output) -{ +void nfc3d_drbg_step(nfc3d_drbg_ctx *ctx, uint8_t *output) { assert(ctx != NULL); assert(output != NULL); @@ -53,14 +51,12 @@ void nfc3d_drbg_step(nfc3d_drbg_ctx *ctx, uint8_t *output) mbedtls_md_hmac_finish(&ctx->hmacCtx, output); } -void nfc3d_drbg_cleanup(nfc3d_drbg_ctx *ctx) -{ +void nfc3d_drbg_cleanup(nfc3d_drbg_ctx *ctx) { assert(ctx != NULL); mbedtls_md_free(&ctx->hmacCtx); } -void nfc3d_drbg_generate_bytes(const uint8_t *hmacKey, size_t hmacKeySize, const uint8_t *seed, size_t seedSize, uint8_t *output, size_t outputSize) -{ +void nfc3d_drbg_generate_bytes(const uint8_t *hmacKey, size_t hmacKeySize, const uint8_t *seed, size_t seedSize, uint8_t *output, size_t outputSize) { uint8_t temp[NFC3D_DRBG_OUTPUT_SIZE]; nfc3d_drbg_ctx rngCtx; diff --git a/client/amiitool/keygen.c b/client/amiitool/keygen.c index 52f9c0069..4b74a0232 100644 --- a/client/amiitool/keygen.c +++ b/client/amiitool/keygen.c @@ -10,8 +10,7 @@ #include #include -void nfc3d_keygen_prepare_seed(const nfc3d_keygen_masterkeys *baseKeys, const uint8_t *baseSeed, uint8_t *output, size_t *outputSize) -{ +void nfc3d_keygen_prepare_seed(const nfc3d_keygen_masterkeys *baseKeys, const uint8_t *baseSeed, uint8_t *output, size_t *outputSize) { assert(baseKeys != NULL); assert(baseSeed != NULL); assert(output != NULL); @@ -45,8 +44,7 @@ void nfc3d_keygen_prepare_seed(const nfc3d_keygen_masterkeys *baseKeys, const ui *outputSize = output - start; } -void nfc3d_keygen(const nfc3d_keygen_masterkeys *baseKeys, const uint8_t *baseSeed, nfc3d_keygen_derivedkeys *derivedKeys) -{ +void nfc3d_keygen(const nfc3d_keygen_masterkeys *baseKeys, const uint8_t *baseSeed, nfc3d_keygen_derivedkeys *derivedKeys) { uint8_t preparedSeed[NFC3D_DRBG_MAX_SEED_SIZE]; size_t preparedSeedSize; diff --git a/client/cli.c b/client/cli.c index 66c24b6db..19e472586 100644 --- a/client/cli.c +++ b/client/cli.c @@ -17,8 +17,7 @@ break;\ } -int main(int argc, char **argv) -{ +int main(int argc, char **argv) { if (argc != 3 && argc != 4) { printf("\n\tusage: cli [logfile (default cli.log)]\n"); printf("\n"); diff --git a/client/cliparser/argtable3.c b/client/cliparser/argtable3.c index a982c4084..0750ed601 100644 --- a/client/cliparser/argtable3.c +++ b/client/cliparser/argtable3.c @@ -157,8 +157,7 @@ extern void dbg_printf(const char *fmt, ...); #include -void dbg_printf(const char *fmt, ...) -{ +void dbg_printf(const char *fmt, ...) { va_list args; va_start(args, fmt); vfprintf(stderr, fmt, args); @@ -293,8 +292,7 @@ static const char illoptstring[] = "unknown option -- %s"; extern char opterrmsg[MAX_OPTER_MSG_SIZE]; char opterrmsg[MAX_OPTER_MSG_SIZE]; /* buffer for the last error message */ -static void warnx(const char *fmt, ...) -{ +static void warnx(const char *fmt, ...) { va_list ap; va_start(ap, fmt); /* @@ -322,8 +320,7 @@ static void warnx(const char *fmt, ...) * Compute the greatest common divisor of a and b. */ static int -gcd(int a, int b) -{ +gcd(int a, int b) { int c; c = a % b; @@ -343,8 +340,7 @@ gcd(int a, int b) */ static void permute_args(int panonopt_start, int panonopt_end, int opt_end, - char *const *nargv) -{ + char *const *nargv) { int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; char *swap; @@ -380,8 +376,7 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end, */ static int parse_long_options(char *const *nargv, const char *options, - const struct option *long_options, int *idx, int short_too) -{ + const struct option *long_options, int *idx, int short_too) { char *current_argv, *has_equal; size_t current_argv_len; int i, match; @@ -429,7 +424,7 @@ parse_long_options(char *const *nargv, const char *options, } if (match != -1) { /* option found */ if (long_options[match].has_arg == no_argument - && has_equal) { + && has_equal) { if (PRINT_ERROR) warnx(noarg, (int)current_argv_len, current_argv); @@ -443,7 +438,7 @@ parse_long_options(char *const *nargv, const char *options, return (BADARG); } if (long_options[match].has_arg == required_argument || - long_options[match].has_arg == optional_argument) { + long_options[match].has_arg == optional_argument) { if (has_equal) optarg = has_equal; else if (long_options[match].has_arg == @@ -455,7 +450,7 @@ parse_long_options(char *const *nargv, const char *options, } } if ((long_options[match].has_arg == required_argument) - && (optarg == NULL)) { + && (optarg == NULL)) { /* * Missing argument; leading ':' indicates no error * should be generated. @@ -498,8 +493,7 @@ parse_long_options(char *const *nargv, const char *options, */ static int getopt_internal(int nargc, char *const *nargv, const char *options, - const struct option *long_options, int *idx, int flags) -{ + const struct option *long_options, int *idx, int flags) { char *oli; /* option letter list index */ int optchar, short_too; static int posixly_correct = -1; @@ -567,7 +561,7 @@ start: return (-1); } if (*(place = nargv[optind]) != '-' || - (place[1] == '\0' && strchr(options, '-') == NULL)) { + (place[1] == '\0' && strchr(options, '-') == NULL)) { place = EMSG; /* found non-option */ if (flags & FLAG_ALLARGS) { /* @@ -628,7 +622,7 @@ start: * 3) either the arg starts with -- we are getopt_long_only() */ if (long_options != NULL && place != nargv[optind] && - (*place == '-' || (flags & FLAG_LONGONLY))) { + (*place == '-' || (flags & FLAG_LONGONLY))) { short_too = 0; if (*place == '-') place++; /* --foo long option */ @@ -644,8 +638,8 @@ start: } if ((optchar = (int) * place++) == (int)':' || - (optchar == (int)'-' && *place != '\0') || - (oli = strchr(options, optchar)) == NULL) { + (optchar == (int)'-' && *place != '\0') || + (oli = strchr(options, optchar)) == NULL) { /* * If the user specified "-" and '-' isn't listed in * options, return -1 (non-option) as per POSIX. @@ -709,8 +703,7 @@ start: * [eventually this will replace the BSD getopt] */ int -getopt(int nargc, char *const *nargv, const char *options) -{ +getopt(int nargc, char *const *nargv, const char *options) { /* * We don't pass FLAG_PERMUTE to getopt_internal() since @@ -730,8 +723,7 @@ getopt(int nargc, char *const *nargv, const char *options) */ int getopt_long(int nargc, char *const *nargv, const char *options, - const struct option *long_options, int *idx) -{ + const struct option *long_options, int *idx) { return (getopt_internal(nargc, nargv, options, long_options, idx, FLAG_PERMUTE)); @@ -743,8 +735,7 @@ getopt_long(int nargc, char *const *nargv, const char *options, */ int getopt_long_only(int nargc, char *const *nargv, const char *options, - const struct option *long_options, int *idx) -{ + const struct option *long_options, int *idx) { return (getopt_internal(nargc, nargv, options, long_options, idx, FLAG_PERMUTE | FLAG_LONGONLY)); @@ -788,15 +779,13 @@ getopt_long_only(int nargc, char *const *nargv, const char *options, char *arg_strptime(const char *buf, const char *fmt, struct tm *tm); -static void arg_date_resetfn(struct arg_date *parent) -{ +static void arg_date_resetfn(struct arg_date *parent) { ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); parent->count = 0; } -static int arg_date_scanfn(struct arg_date *parent, const char *argval) -{ +static int arg_date_scanfn(struct arg_date *parent, const char *argval) { int errorcode = 0; if (parent->count == parent->hdr.maxcount) { @@ -821,8 +810,7 @@ static int arg_date_scanfn(struct arg_date *parent, const char *argval) } -static int arg_date_checkfn(struct arg_date *parent) -{ +static int arg_date_checkfn(struct arg_date *parent) { int errorcode = (parent->count < parent->hdr.mincount) ? EMINCOUNT : 0; ARG_TRACE(("%s:checkfn(%p) returns %d\n", __FILE__, parent, errorcode)); @@ -835,8 +823,7 @@ static void arg_date_errorfn( FILE *fp, int errorcode, const char *argval, - const char *progname) -{ + const char *progname) { const char *shortopts = parent->hdr.shortopts; const char *longopts = parent->hdr.longopts; const char *datatype = parent->hdr.datatype; @@ -876,8 +863,7 @@ struct arg_date *arg_date0( const char *longopts, const char *format, const char *datatype, - const char *glossary) -{ + const char *glossary) { return arg_daten(shortopts, longopts, format, datatype, 0, 1, glossary); } @@ -887,8 +873,7 @@ struct arg_date *arg_date1( const char *longopts, const char *format, const char *datatype, - const char *glossary) -{ + const char *glossary) { return arg_daten(shortopts, longopts, format, datatype, 1, 1, glossary); } @@ -900,8 +885,7 @@ struct arg_date *arg_daten( const char *datatype, int mincount, int maxcount, - const char *glossary) -{ + const char *glossary) { size_t nbytes; struct arg_date *result; @@ -1014,8 +998,7 @@ static const char *am_pm[2] = { }; -static int arg_strcasecmp(const char *s1, const char *s2) -{ +static int arg_strcasecmp(const char *s1, const char *s2) { const unsigned char *us1 = (const unsigned char *)s1; const unsigned char *us2 = (const unsigned char *)s2; while (tolower(*us1) == tolower(*us2++)) @@ -1026,8 +1009,7 @@ static int arg_strcasecmp(const char *s1, const char *s2) } -static int arg_strncasecmp(const char *s1, const char *s2, size_t n) -{ +static int arg_strncasecmp(const char *s1, const char *s2, size_t n) { if (n != 0) { const unsigned char *us1 = (const unsigned char *)s1; const unsigned char *us2 = (const unsigned char *)s2; @@ -1044,8 +1026,7 @@ static int arg_strncasecmp(const char *s1, const char *s2, size_t n) } -char *arg_strptime(const char *buf, const char *fmt, struct tm *tm) -{ +char *arg_strptime(const char *buf, const char *fmt, struct tm *tm) { char c; const char *bp; size_t len = 0; @@ -1349,8 +1330,7 @@ literal: } -static int conv_num(const char * *buf, int *dest, int llim, int ulim) -{ +static int conv_num(const char * *buf, int *dest, int llim, int ulim) { int result = 0; /* The limit also determines the number of valid digits. */ @@ -1406,15 +1386,13 @@ static int conv_num(const char * *buf, int *dest, int llim, int ulim) #include "argtable3.h" -static void arg_dbl_resetfn(struct arg_dbl *parent) -{ +static void arg_dbl_resetfn(struct arg_dbl *parent) { ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); parent->count = 0; } -static int arg_dbl_scanfn(struct arg_dbl *parent, const char *argval) -{ +static int arg_dbl_scanfn(struct arg_dbl *parent, const char *argval) { int errorcode = 0; if (parent->count == parent->hdr.maxcount) { @@ -1444,8 +1422,7 @@ static int arg_dbl_scanfn(struct arg_dbl *parent, const char *argval) } -static int arg_dbl_checkfn(struct arg_dbl *parent) -{ +static int arg_dbl_checkfn(struct arg_dbl *parent) { int errorcode = (parent->count < parent->hdr.mincount) ? EMINCOUNT : 0; ARG_TRACE(("%s:checkfn(%p) returns %d\n", __FILE__, parent, errorcode)); @@ -1458,8 +1435,7 @@ static void arg_dbl_errorfn( FILE *fp, int errorcode, const char *argval, - const char *progname) -{ + const char *progname) { const char *shortopts = parent->hdr.shortopts; const char *longopts = parent->hdr.longopts; const char *datatype = parent->hdr.datatype; @@ -1491,8 +1467,7 @@ struct arg_dbl *arg_dbl0( const char *shortopts, const char *longopts, const char *datatype, - const char *glossary) -{ + const char *glossary) { return arg_dbln(shortopts, longopts, datatype, 0, 1, glossary); } @@ -1501,8 +1476,7 @@ struct arg_dbl *arg_dbl1( const char *shortopts, const char *longopts, const char *datatype, - const char *glossary) -{ + const char *glossary) { return arg_dbln(shortopts, longopts, datatype, 1, 1, glossary); } @@ -1513,8 +1487,7 @@ struct arg_dbl *arg_dbln( const char *datatype, int mincount, int maxcount, - const char *glossary) -{ + const char *glossary) { size_t nbytes; struct arg_dbl *result; @@ -1594,8 +1567,7 @@ struct arg_dbl *arg_dbln( #include "argtable3.h" -static void arg_end_resetfn(struct arg_end *parent) -{ +static void arg_end_resetfn(struct arg_end *parent) { ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); parent->count = 0; } @@ -1605,8 +1577,7 @@ static void arg_end_errorfn( FILE *fp, int error, const char *argval, - const char *progname) -{ + const char *progname) { /* suppress unreferenced formal parameter warning */ (void)parent; @@ -1639,8 +1610,7 @@ static void arg_end_errorfn( } -struct arg_end *arg_end(int maxcount) -{ +struct arg_end *arg_end(int maxcount) { size_t nbytes; struct arg_end *result; @@ -1680,8 +1650,7 @@ struct arg_end *arg_end(int maxcount) } -void arg_print_errors(FILE *fp, struct arg_end *end, const char *progname) -{ +void arg_print_errors(FILE *fp, struct arg_end *end, const char *progname) { int i; ARG_TRACE(("arg_errors()\n")); for (i = 0; i < end->count; i++) { @@ -1738,16 +1707,14 @@ void arg_print_errors(FILE *fp, struct arg_end *end, const char *progname) #endif -static void arg_file_resetfn(struct arg_file *parent) -{ +static void arg_file_resetfn(struct arg_file *parent) { ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); parent->count = 0; } /* Returns ptr to the base filename within *filename */ -static const char *arg_basename(const char *filename) -{ +static const char *arg_basename(const char *filename) { const char *result = NULL, *result1, *result2; /* Find the last occurrence of eother file separator character. */ @@ -1774,8 +1741,7 @@ static const char *arg_basename(const char *filename) /* Returns ptr to the file extension within *basename */ -static const char *arg_extension(const char *basename) -{ +static const char *arg_extension(const char *basename) { /* find the last occurrence of '.' in basename */ const char *result = (basename ? strrchr(basename, '.') : NULL); @@ -1795,8 +1761,7 @@ static const char *arg_extension(const char *basename) } -static int arg_file_scanfn(struct arg_file *parent, const char *argval) -{ +static int arg_file_scanfn(struct arg_file *parent, const char *argval) { int errorcode = 0; if (parent->count == parent->hdr.maxcount) { @@ -1820,8 +1785,7 @@ static int arg_file_scanfn(struct arg_file *parent, const char *argval) } -static int arg_file_checkfn(struct arg_file *parent) -{ +static int arg_file_checkfn(struct arg_file *parent) { int errorcode = (parent->count < parent->hdr.mincount) ? EMINCOUNT : 0; ARG_TRACE(("%s:checkfn(%p) returns %d\n", __FILE__, parent, errorcode)); @@ -1834,8 +1798,7 @@ static void arg_file_errorfn( FILE *fp, int errorcode, const char *argval, - const char *progname) -{ + const char *progname) { const char *shortopts = parent->hdr.shortopts; const char *longopts = parent->hdr.longopts; const char *datatype = parent->hdr.datatype; @@ -1865,8 +1828,7 @@ struct arg_file *arg_file0( const char *shortopts, const char *longopts, const char *datatype, - const char *glossary) -{ + const char *glossary) { return arg_filen(shortopts, longopts, datatype, 0, 1, glossary); } @@ -1875,8 +1837,7 @@ struct arg_file *arg_file1( const char *shortopts, const char *longopts, const char *datatype, - const char *glossary) -{ + const char *glossary) { return arg_filen(shortopts, longopts, datatype, 1, 1, glossary); } @@ -1887,8 +1848,7 @@ struct arg_file *arg_filen( const char *datatype, int mincount, int maxcount, - const char *glossary) -{ + const char *glossary) { size_t nbytes; struct arg_file *result; @@ -1972,8 +1932,7 @@ struct arg_file *arg_filen( #include "argtable3.h" -static void arg_int_resetfn(struct arg_int *parent) -{ +static void arg_int_resetfn(struct arg_int *parent) { ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); parent->count = 0; } @@ -1992,8 +1951,7 @@ static void arg_int_resetfn(struct arg_int *parent) static long int strtol0X(const char *str, const char * *endptr, char X, - int base) -{ + int base) { long int val; /* stores result */ int s = 1; /* sign is +1 or -1 */ const char *ptr = str; /* ptr to current position in str */ @@ -2048,8 +2006,7 @@ static long int strtol0X(const char *str, /* Returns 1 if str matches suffix (case insensitive). */ /* Str may contain trailing whitespace, but nothing else. */ -static int detectsuffix(const char *str, const char *suffix) -{ +static int detectsuffix(const char *str, const char *suffix) { /* scan pairwise through strings until mismatch detected */ while (toupper(*str) == toupper(*suffix)) { /* printf("'%c' '%c'\n", *str, *suffix); */ @@ -2077,8 +2034,7 @@ static int detectsuffix(const char *str, const char *suffix) } -static int arg_int_scanfn(struct arg_int *parent, const char *argval) -{ +static int arg_int_scanfn(struct arg_int *parent, const char *argval) { int errorcode = 0; if (parent->count == parent->hdr.maxcount) { @@ -2163,8 +2119,7 @@ static int arg_int_scanfn(struct arg_int *parent, const char *argval) } -static int arg_int_checkfn(struct arg_int *parent) -{ +static int arg_int_checkfn(struct arg_int *parent) { int errorcode = (parent->count < parent->hdr.mincount) ? EMINCOUNT : 0; /*printf("%s:checkfn(%p) returns %d\n",__FILE__,parent,errorcode);*/ return errorcode; @@ -2176,8 +2131,7 @@ static void arg_int_errorfn( FILE *fp, int errorcode, const char *argval, - const char *progname) -{ + const char *progname) { const char *shortopts = parent->hdr.shortopts; const char *longopts = parent->hdr.longopts; const char *datatype = parent->hdr.datatype; @@ -2219,8 +2173,7 @@ struct arg_int *arg_int0( const char *shortopts, const char *longopts, const char *datatype, - const char *glossary) -{ + const char *glossary) { return arg_intn(shortopts, longopts, datatype, 0, 1, glossary); } @@ -2229,8 +2182,7 @@ struct arg_int *arg_int1( const char *shortopts, const char *longopts, const char *datatype, - const char *glossary) -{ + const char *glossary) { return arg_intn(shortopts, longopts, datatype, 1, 1, glossary); } @@ -2241,8 +2193,7 @@ struct arg_int *arg_intn( const char *datatype, int mincount, int maxcount, - const char *glossary) -{ + const char *glossary) { size_t nbytes; struct arg_int *result; @@ -2311,15 +2262,13 @@ struct arg_int *arg_intn( #include "argtable3.h" -static void arg_lit_resetfn(struct arg_lit *parent) -{ +static void arg_lit_resetfn(struct arg_lit *parent) { ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); parent->count = 0; } -static int arg_lit_scanfn(struct arg_lit *parent, const char *argval) -{ +static int arg_lit_scanfn(struct arg_lit *parent, const char *argval) { int errorcode = 0; if (parent->count < parent->hdr.maxcount) parent->count++; @@ -2332,8 +2281,7 @@ static int arg_lit_scanfn(struct arg_lit *parent, const char *argval) } -static int arg_lit_checkfn(struct arg_lit *parent) -{ +static int arg_lit_checkfn(struct arg_lit *parent) { int errorcode = (parent->count < parent->hdr.mincount) ? EMINCOUNT : 0; ARG_TRACE(("%s:checkfn(%p) returns %d\n", __FILE__, parent, errorcode)); return errorcode; @@ -2345,8 +2293,7 @@ static void arg_lit_errorfn( FILE *fp, int errorcode, const char *argval, - const char *progname) -{ + const char *progname) { const char *shortopts = parent->hdr.shortopts; const char *longopts = parent->hdr.longopts; const char *datatype = parent->hdr.datatype; @@ -2372,8 +2319,7 @@ static void arg_lit_errorfn( struct arg_lit *arg_lit0( const char *shortopts, const char *longopts, - const char *glossary) -{ + const char *glossary) { return arg_litn(shortopts, longopts, 0, 1, glossary); } @@ -2381,8 +2327,7 @@ struct arg_lit *arg_lit0( struct arg_lit *arg_lit1( const char *shortopts, const char *longopts, - const char *glossary) -{ + const char *glossary) { return arg_litn(shortopts, longopts, 1, 1, glossary); } @@ -2392,8 +2337,7 @@ struct arg_lit *arg_litn( const char *longopts, int mincount, int maxcount, - const char *glossary) -{ + const char *glossary) { struct arg_lit *result; /* foolproof things by ensuring maxcount is not less than mincount */ @@ -2456,8 +2400,7 @@ struct arg_lit *arg_litn( #include "argtable3.h" -struct arg_rem *arg_rem(const char *datatype, const char *glossary) -{ +struct arg_rem *arg_rem(const char *datatype, const char *glossary) { struct arg_rem *result = (struct arg_rem *)malloc(sizeof(struct arg_rem)); if (result) { result->hdr.flag = 0; @@ -2600,14 +2543,12 @@ struct privhdr { }; -static void arg_rex_resetfn(struct arg_rex *parent) -{ +static void arg_rex_resetfn(struct arg_rex *parent) { ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); parent->count = 0; } -static int arg_rex_scanfn(struct arg_rex *parent, const char *argval) -{ +static int arg_rex_scanfn(struct arg_rex *parent, const char *argval) { int errorcode = 0; const TRexChar *error = NULL; TRex *rex = NULL; @@ -2641,8 +2582,7 @@ static int arg_rex_scanfn(struct arg_rex *parent, const char *argval) return errorcode; } -static int arg_rex_checkfn(struct arg_rex *parent) -{ +static int arg_rex_checkfn(struct arg_rex *parent) { int errorcode = (parent->count < parent->hdr.mincount) ? EMINCOUNT : 0; //struct privhdr *priv = (struct privhdr*)parent->hdr.priv; @@ -2657,8 +2597,7 @@ static void arg_rex_errorfn(struct arg_rex *parent, FILE *fp, int errorcode, const char *argval, - const char *progname) -{ + const char *progname) { const char *shortopts = parent->hdr.shortopts; const char *longopts = parent->hdr.longopts; const char *datatype = parent->hdr.datatype; @@ -2698,8 +2637,7 @@ struct arg_rex *arg_rex0(const char *shortopts, const char *pattern, const char *datatype, int flags, - const char *glossary) -{ + const char *glossary) { return arg_rexn(shortopts, longopts, pattern, @@ -2715,8 +2653,7 @@ struct arg_rex *arg_rex1(const char *shortopts, const char *pattern, const char *datatype, int flags, - const char *glossary) -{ + const char *glossary) { return arg_rexn(shortopts, longopts, pattern, @@ -2735,8 +2672,7 @@ struct arg_rex *arg_rexn(const char *shortopts, int mincount, int maxcount, int flags, - const char *glossary) -{ + const char *glossary) { size_t nbytes; struct arg_rex *result; struct privhdr *priv; @@ -2891,8 +2827,7 @@ struct TRex { static int trex_list(TRex *exp); -static int trex_newnode(TRex *exp, TRexNodeType type) -{ +static int trex_newnode(TRex *exp, TRexNodeType type) { TRexNode n; int newid; n.type = type; @@ -2908,21 +2843,18 @@ static int trex_newnode(TRex *exp, TRexNodeType type) return (int)newid; } -static void trex_error(TRex *exp, const TRexChar *error) -{ +static void trex_error(TRex *exp, const TRexChar *error) { if (exp->_error) *exp->_error = error; longjmp(*((jmp_buf *)exp->_jmpbuf), -1); } -static void trex_expect(TRex *exp, int n) -{ +static void trex_expect(TRex *exp, int n) { if ((*exp->_p) != n) trex_error(exp, _SC("expected paren")); exp->_p++; } -static TRexChar trex_escapechar(TRex *exp) -{ +static TRexChar trex_escapechar(TRex *exp) { if (*exp->_p == TREX_SYMBOL_ESCAPE_CHAR) { exp->_p++; switch (*exp->_p) { @@ -2948,15 +2880,13 @@ static TRexChar trex_escapechar(TRex *exp) return (*exp->_p++); } -static int trex_charclass(TRex *exp, int classid) -{ +static int trex_charclass(TRex *exp, int classid) { int n = trex_newnode(exp, OP_CCLASS); exp->_nodes[n].left = classid; return n; } -static int trex_charnode(TRex *exp, TRexBool isclass) -{ +static int trex_charnode(TRex *exp, TRexBool isclass) { TRexChar t; if (*exp->_p == TREX_SYMBOL_ESCAPE_CHAR) { exp->_p++; @@ -3017,8 +2947,7 @@ static int trex_charnode(TRex *exp, TRexBool isclass) exp->_p++; return trex_newnode(exp, t); } -static int trex_class(TRex *exp) -{ +static int trex_class(TRex *exp) { int ret = -1; int first = -1, chain; if (*exp->_p == TREX_SYMBOL_BEGINNING_OF_STRING) { @@ -3064,8 +2993,7 @@ static int trex_class(TRex *exp) return ret; } -static int trex_parsenumber(TRex *exp) -{ +static int trex_parsenumber(TRex *exp) { int ret = *exp->_p - '0'; int positions = 10; exp->_p++; @@ -3077,8 +3005,7 @@ static int trex_parsenumber(TRex *exp) return ret; } -static int trex_element(TRex *exp) -{ +static int trex_element(TRex *exp) { int ret = -1; switch (*exp->_p) { case '(': { @@ -3179,8 +3106,7 @@ static int trex_element(TRex *exp) return ret; } -static int trex_list(TRex *exp) -{ +static int trex_list(TRex *exp) { int ret = -1, e; if (*exp->_p == TREX_SYMBOL_BEGINNING_OF_STRING) { exp->_p++; @@ -3203,8 +3129,7 @@ static int trex_list(TRex *exp) return ret; } -static TRexBool trex_matchcclass(int cclass, TRexChar c) -{ +static TRexBool trex_matchcclass(int cclass, TRexChar c) { switch (cclass) { case 'a': return isalpha(c) ? TRex_True : TRex_False; @@ -3242,8 +3167,7 @@ static TRexBool trex_matchcclass(int cclass, TRexChar c) return TRex_False; /*cannot happen*/ } -static TRexBool trex_matchclass(TRex *exp, TRexNode *node, TRexChar c) -{ +static TRexBool trex_matchclass(TRex *exp, TRexNode *node, TRexChar c) { do { switch (node->type) { case OP_RANGE: @@ -3269,8 +3193,7 @@ static TRexBool trex_matchclass(TRex *exp, TRexNode *node, TRexChar c) return TRex_False; } -static const TRexChar *trex_matchnode(TRex *exp, TRexNode *node, const TRexChar *str, TRexNode *next) -{ +static const TRexChar *trex_matchnode(TRex *exp, TRexNode *node, const TRexChar *str, TRexNode *next) { TRexNodeType type = node->type; switch (type) { @@ -3297,7 +3220,7 @@ static const TRexChar *trex_matchnode(TRex *exp, TRexNode *node, const TRexChar //checks that 0 matches satisfy the expression(if so skips) //if not would always stop(for instance if is a '?') if (greedystop->type != OP_GREEDY || - (greedystop->type == OP_GREEDY && ((greedystop->right >> 16) & 0x0000FFFF) != 0)) { + (greedystop->type == OP_GREEDY && ((greedystop->right >> 16) & 0x0000FFFF) != 0)) { TRexNode *gnext = NULL; if (greedystop->next != -1) { gnext = &exp->_nodes[greedystop->next]; @@ -3375,9 +3298,9 @@ static const TRexChar *trex_matchnode(TRex *exp, TRexNode *node, const TRexChar } case OP_WB: if ((str == exp->_bol && !ISSPACE(*str)) - || ((str == exp->_eol && !ISSPACE(*(str - 1)))) - || ((!ISSPACE(*str) && ISSPACE(*(str + 1)))) - || ((ISSPACE(*str) && !ISSPACE(*(str + 1))))) { + || ((str == exp->_eol && !ISSPACE(*(str - 1)))) + || ((!ISSPACE(*str) && ISSPACE(*(str + 1)))) + || ((ISSPACE(*str) && !ISSPACE(*(str + 1))))) { return (node->left == 'b') ? str : NULL; } return (node->left == 'b') ? NULL : str; @@ -3416,8 +3339,7 @@ static const TRexChar *trex_matchnode(TRex *exp, TRexNode *node, const TRexChar } /* public api */ -TRex *trex_compile(const TRexChar *pattern, const TRexChar **error, int flags) -{ +TRex *trex_compile(const TRexChar *pattern, const TRexChar **error, int flags) { TRex *exp = (TRex *)malloc(sizeof(TRex)); exp->_eol = exp->_bol = NULL; exp->_p = pattern; @@ -3461,8 +3383,7 @@ TRex *trex_compile(const TRexChar *pattern, const TRexChar **error, int flags) return exp; } -void trex_free(TRex *exp) -{ +void trex_free(TRex *exp) { if (exp) { if (exp->_nodes) free(exp->_nodes); if (exp->_jmpbuf) free(exp->_jmpbuf); @@ -3471,8 +3392,7 @@ void trex_free(TRex *exp) } } -TRexBool trex_match(TRex *exp, const TRexChar *text) -{ +TRexBool trex_match(TRex *exp, const TRexChar *text) { const TRexChar *res = NULL; exp->_bol = text; exp->_eol = text + scstrlen(text); @@ -3483,8 +3403,7 @@ TRexBool trex_match(TRex *exp, const TRexChar *text) return TRex_True; } -TRexBool trex_searchrange(TRex *exp, const TRexChar *text_begin, const TRexChar *text_end, const TRexChar **out_begin, const TRexChar **out_end) -{ +TRexBool trex_searchrange(TRex *exp, const TRexChar *text_begin, const TRexChar *text_end, const TRexChar **out_begin, const TRexChar **out_end) { const TRexChar *cur = NULL; int node = exp->_first; if (text_begin >= text_end) return TRex_False; @@ -3512,18 +3431,15 @@ TRexBool trex_searchrange(TRex *exp, const TRexChar *text_begin, const TRexChar return TRex_True; } -TRexBool trex_search(TRex *exp, const TRexChar *text, const TRexChar **out_begin, const TRexChar **out_end) -{ +TRexBool trex_search(TRex *exp, const TRexChar *text, const TRexChar **out_begin, const TRexChar **out_end) { return trex_searchrange(exp, text, text + scstrlen(text), out_begin, out_end); } -int trex_getsubexpcount(TRex *exp) -{ +int trex_getsubexpcount(TRex *exp) { return exp->_nsubexpr; } -TRexBool trex_getsubexp(TRex *exp, int n, TRexMatch *subexp) -{ +TRexBool trex_getsubexp(TRex *exp, int n, TRexMatch *subexp) { if (n < 0 || n >= exp->_nsubexpr) return TRex_False; *subexp = exp->_matches[n]; return TRex_True; @@ -3563,15 +3479,13 @@ TRexBool trex_getsubexp(TRex *exp, int n, TRexMatch *subexp) #include "argtable3.h" -static void arg_str_resetfn(struct arg_str *parent) -{ +static void arg_str_resetfn(struct arg_str *parent) { ARG_TRACE(("%s:resetfn(%p)\n", __FILE__, parent)); parent->count = 0; } -static int arg_str_scanfn(struct arg_str *parent, const char *argval) -{ +static int arg_str_scanfn(struct arg_str *parent, const char *argval) { int errorcode = 0; if (parent->count == parent->hdr.maxcount) { @@ -3591,8 +3505,7 @@ static int arg_str_scanfn(struct arg_str *parent, const char *argval) } -static int arg_str_checkfn(struct arg_str *parent) -{ +static int arg_str_checkfn(struct arg_str *parent) { int errorcode = (parent->count < parent->hdr.mincount) ? EMINCOUNT : 0; ARG_TRACE(("%s:checkfn(%p) returns %d\n", __FILE__, parent, errorcode)); @@ -3605,8 +3518,7 @@ static void arg_str_errorfn( FILE *fp, int errorcode, const char *argval, - const char *progname) -{ + const char *progname) { const char *shortopts = parent->hdr.shortopts; const char *longopts = parent->hdr.longopts; const char *datatype = parent->hdr.datatype; @@ -3633,8 +3545,7 @@ struct arg_str *arg_str0( const char *shortopts, const char *longopts, const char *datatype, - const char *glossary) -{ + const char *glossary) { return arg_strn(shortopts, longopts, datatype, 0, 1, glossary); } @@ -3643,8 +3554,7 @@ struct arg_str *arg_str1( const char *shortopts, const char *longopts, const char *datatype, - const char *glossary) -{ + const char *glossary) { return arg_strn(shortopts, longopts, datatype, 1, 1, glossary); } @@ -3655,8 +3565,7 @@ struct arg_str *arg_strn( const char *datatype, int mincount, int maxcount, - const char *glossary) -{ + const char *glossary) { size_t nbytes; struct arg_str *result; @@ -3739,8 +3648,7 @@ static void arg_register_error(struct arg_end *end, void *parent, int error, - const char *argval) -{ + const char *argval) { /* printf("arg_register_error(%p,%p,%d,%s)\n",end,parent,error,argval); */ if (end->count < end->hdr.maxcount) { end->error[end->count] = error; @@ -3760,12 +3668,11 @@ void arg_register_error(struct arg_end *end, * or -1 if no match was found. */ static -int find_shortoption(struct arg_hdr * *table, char shortopt) -{ +int find_shortoption(struct arg_hdr * *table, char shortopt) { int tabindex; for (tabindex = 0; !(table[tabindex]->flag & ARG_TERMINATOR); tabindex++) { if (table[tabindex]->shortopts && - strchr(table[tabindex]->shortopts, shortopt)) + strchr(table[tabindex]->shortopts, shortopt)) return tabindex; } return -1; @@ -3780,8 +3687,7 @@ struct longoptions { #if 0 static -void dump_longoptions(struct longoptions *longoptions) -{ +void dump_longoptions(struct longoptions *longoptions) { int i; printf("getoptval = %d\n", longoptions->getoptval); printf("noptions = %d\n", longoptions->noptions); @@ -3797,8 +3703,7 @@ void dump_longoptions(struct longoptions *longoptions) #endif static -struct longoptions *alloc_longoptions(struct arg_hdr * *table) -{ +struct longoptions *alloc_longoptions(struct arg_hdr * *table) { struct longoptions *result; size_t nbytes; int noptions = 1; @@ -3881,8 +3786,7 @@ struct longoptions *alloc_longoptions(struct arg_hdr * *table) } static -char *alloc_shortoptions(struct arg_hdr * *table) -{ +char *alloc_shortoptions(struct arg_hdr * *table) { char *result; size_t len = 2; int tabindex; @@ -3923,8 +3827,7 @@ char *alloc_shortoptions(struct arg_hdr * *table) /* return index of the table terminator entry */ static -int arg_endindex(struct arg_hdr * *table) -{ +int arg_endindex(struct arg_hdr * *table) { int tabindex = 0; while (!(table[tabindex]->flag & ARG_TERMINATOR)) tabindex++; @@ -3936,8 +3839,7 @@ static void arg_parse_tagged(int argc, char * *argv, struct arg_hdr * *table, - struct arg_end *endtable) -{ + struct arg_end *endtable) { struct longoptions *longoptions; char *shortoptions; int copt; @@ -3979,7 +3881,7 @@ void arg_parse_tagged(int argc, void *parent = table[tabindex]->parent; /*printf("long option detected from argtable[%d]\n", tabindex);*/ if (optarg && optarg[0] == 0 && - (table[tabindex]->flag & ARG_HASVALUE)) { + (table[tabindex]->flag & ARG_HASVALUE)) { /* printf(": long option %s requires an argument\n",argv[optind-1]); */ arg_register_error(endtable, endtable, ARG_EMISSARG, argv[optind - 1]); @@ -4051,8 +3953,7 @@ static void arg_parse_untagged(int argc, char * *argv, struct arg_hdr * *table, - struct arg_end *endtable) -{ + struct arg_end *endtable) { int tabindex = 0; int errorlast = 0; const char *optarglast = NULL; @@ -4126,8 +4027,7 @@ void arg_parse_untagged(int argc, static -void arg_parse_check(struct arg_hdr * *table, struct arg_end *endtable) -{ +void arg_parse_check(struct arg_hdr * *table, struct arg_end *endtable) { int tabindex = 0; /* printf("arg_parse_check()\n"); */ do { @@ -4142,8 +4042,7 @@ void arg_parse_check(struct arg_hdr * *table, struct arg_end *endtable) static -void arg_reset(void * *argtable) -{ +void arg_reset(void * *argtable) { struct arg_hdr * *table = (struct arg_hdr * *)argtable; int tabindex = 0; /*printf("arg_reset(%p)\n",argtable);*/ @@ -4154,8 +4053,7 @@ void arg_reset(void * *argtable) } -int arg_parse(int argc, char * *argv, void * *argtable) -{ +int arg_parse(int argc, char * *argv, void * *argtable) { struct arg_hdr * *table = (struct arg_hdr * *)argtable; struct arg_end *endtable; int endindex; @@ -4237,8 +4135,7 @@ int arg_parse(int argc, char * *argv, void * *argtable) * ndest == 10 */ static -void arg_cat(char * *pdest, const char *src, size_t *pndest) -{ +void arg_cat(char * *pdest, const char *src, size_t *pndest) { char *dest = *pdest; char *end = dest + *pndest; @@ -4265,8 +4162,7 @@ void arg_cat_option(char *dest, const char *shortopts, const char *longopts, const char *datatype, - int optvalue) -{ + int optvalue) { if (shortopts) { char option[3]; @@ -4326,8 +4222,7 @@ void arg_cat_optionv(char *dest, const char *longopts, const char *datatype, int optvalue, - const char *separator) -{ + const char *separator) { separator = separator ? separator : ""; if (shortopts) { @@ -4398,8 +4293,7 @@ void arg_print_option(FILE *fp, const char *shortopts, const char *longopts, const char *datatype, - const char *suffix) -{ + const char *suffix) { char syntax[200] = ""; suffix = suffix ? suffix : ""; @@ -4423,8 +4317,7 @@ void arg_print_option(FILE *fp, * in: -xvfsd, or -xvf[sd], or [-xvsfd] */ static -void arg_print_gnuswitch(FILE *fp, struct arg_hdr * *table) -{ +void arg_print_gnuswitch(FILE *fp, struct arg_hdr * *table) { int tabindex; char *format1 = " -%c"; char *format2 = " [-%c"; @@ -4432,8 +4325,8 @@ void arg_print_gnuswitch(FILE *fp, struct arg_hdr * *table) /* print all mandatory switches that are without argument values */ for (tabindex = 0; - table[tabindex] && !(table[tabindex]->flag & ARG_TERMINATOR); - tabindex++) { + table[tabindex] && !(table[tabindex]->flag & ARG_TERMINATOR); + tabindex++) { /* skip optional options */ if (table[tabindex]->mincount < 1) continue; @@ -4454,8 +4347,8 @@ void arg_print_gnuswitch(FILE *fp, struct arg_hdr * *table) /* print all optional switches that are without argument values */ for (tabindex = 0; - table[tabindex] && !(table[tabindex]->flag & ARG_TERMINATOR); - tabindex++) { + table[tabindex] && !(table[tabindex]->flag & ARG_TERMINATOR); + tabindex++) { /* skip mandatory args */ if (table[tabindex]->mincount > 0) continue; @@ -4478,8 +4371,7 @@ void arg_print_gnuswitch(FILE *fp, struct arg_hdr * *table) } -void arg_print_syntax(FILE *fp, void * *argtable, const char *suffix) -{ +void arg_print_syntax(FILE *fp, void * *argtable, const char *suffix) { struct arg_hdr * *table = (struct arg_hdr * *)argtable; int i, tabindex; @@ -4488,14 +4380,14 @@ void arg_print_syntax(FILE *fp, void * *argtable, const char *suffix) /* print remaining options in abbreviated style */ for (tabindex = 0; - table[tabindex] && !(table[tabindex]->flag & ARG_TERMINATOR); - tabindex++) { + table[tabindex] && !(table[tabindex]->flag & ARG_TERMINATOR); + tabindex++) { char syntax[200] = ""; const char *shortopts, *longopts, *datatype; /* skip short options without arg values (they were printed by arg_print_gnu_switch) */ if (table[tabindex]->shortopts && - !(table[tabindex]->flag & ARG_HASVALUE)) + !(table[tabindex]->flag & ARG_HASVALUE)) continue; shortopts = table[tabindex]->shortopts; @@ -4535,15 +4427,14 @@ void arg_print_syntax(FILE *fp, void * *argtable, const char *suffix) } -void arg_print_syntaxv(FILE *fp, void * *argtable, const char *suffix) -{ +void arg_print_syntaxv(FILE *fp, void * *argtable, const char *suffix) { struct arg_hdr * *table = (struct arg_hdr * *)argtable; int i, tabindex; /* print remaining options in abbreviated style */ for (tabindex = 0; - table[tabindex] && !(table[tabindex]->flag & ARG_TERMINATOR); - tabindex++) { + table[tabindex] && !(table[tabindex]->flag & ARG_TERMINATOR); + tabindex++) { char syntax[200] = ""; const char *shortopts, *longopts, *datatype; @@ -4583,8 +4474,7 @@ void arg_print_syntaxv(FILE *fp, void * *argtable, const char *suffix) } -void arg_print_glossary(FILE *fp, void * *argtable, const char *format) -{ +void arg_print_glossary(FILE *fp, void * *argtable, const char *format) { struct arg_hdr * *table = (struct arg_hdr * *)argtable; int tabindex; @@ -4645,8 +4535,7 @@ static void arg_print_formatted(FILE *fp, const unsigned lmargin, const unsigned rmargin, - const char *text) -{ + const char *text) { const unsigned textlen = (unsigned)strlen(text); unsigned line_start = 0; unsigned line_end = textlen + 1; @@ -4668,8 +4557,8 @@ void arg_print_formatted(FILE *fp, /* Find last whitespace, that fits into line */ while ((line_end > line_start) - && (line_end - line_start > colwidth) - && !ISSPACE(*(text + line_end))) + && (line_end - line_start > colwidth) + && !ISSPACE(*(text + line_end))) { line_end--; } /* Do not print trailing whitespace. If this text @@ -4709,8 +4598,7 @@ void arg_print_formatted(FILE *fp, * * Contributed by Uli Fouquet */ -void arg_print_glossary_gnu(FILE *fp, void * *argtable) -{ +void arg_print_glossary_gnu(FILE *fp, void * *argtable) { struct arg_hdr * *table = (struct arg_hdr * *)argtable; int tabindex; @@ -4755,8 +4643,7 @@ void arg_print_glossary_gnu(FILE *fp, void * *argtable) * Checks the argtable[] array for NULL entries and returns 1 * if any are found, zero otherwise. */ -int arg_nullcheck(void * *argtable) -{ +int arg_nullcheck(void * *argtable) { struct arg_hdr * *table = (struct arg_hdr * *)argtable; int tabindex; /*printf("arg_nullcheck(%p)\n",argtable);*/ @@ -4786,8 +4673,7 @@ int arg_nullcheck(void * *argtable) * with the newer arg_freetable() function. * We still keep arg_free() for backwards compatibility. */ -void arg_free(void * *argtable) -{ +void arg_free(void * *argtable) { struct arg_hdr * *table = (struct arg_hdr * *)argtable; int tabindex = 0; int flag; @@ -4810,8 +4696,7 @@ void arg_free(void * *argtable) } /* frees each non-NULL element of argtable[], where n is the size of the number of entries in the array */ -void arg_freetable(void * *argtable, size_t n) -{ +void arg_freetable(void * *argtable, size_t n) { struct arg_hdr * *table = (struct arg_hdr * *)argtable; size_t tabindex = 0; /*printf("arg_freetable(%p)\n",argtable);*/ diff --git a/client/cliparser/cliparser.c b/client/cliparser/cliparser.c index 5383712b0..766cf9ba4 100644 --- a/client/cliparser/cliparser.c +++ b/client/cliparser/cliparser.c @@ -19,8 +19,7 @@ char *programHint = NULL; char *programHelp = NULL; char buf[500] = {0}; -int CLIParserInit(char *vprogramName, char *vprogramHint, char *vprogramHelp) -{ +int CLIParserInit(char *vprogramName, char *vprogramHint, char *vprogramHelp) { argtable = NULL; argtableLen = 0; programName = vprogramName; @@ -31,8 +30,7 @@ int CLIParserInit(char *vprogramName, char *vprogramHint, char *vprogramHelp) return 0; } -int CLIParserParseArg(int argc, char **argv, void *vargtable[], size_t vargtableLen, bool allowEmptyExec) -{ +int CLIParserParseArg(int argc, char **argv, void *vargtable[], size_t vargtableLen, bool allowEmptyExec) { int nerrors; argtable = vargtable; @@ -81,13 +79,11 @@ enum ParserState { #define isSpace(c)(c == ' ' || c == '\t') -int CLIParserParseString(const char *str, void *vargtable[], size_t vargtableLen, bool allowEmptyExec) -{ +int CLIParserParseString(const char *str, void *vargtable[], size_t vargtableLen, bool allowEmptyExec) { return CLIParserParseStringEx(str, vargtable, vargtableLen, allowEmptyExec, false); } -int CLIParserParseStringEx(const char *str, void *vargtable[], size_t vargtableLen, bool allowEmptyExec, bool clueData) -{ +int CLIParserParseStringEx(const char *str, void *vargtable[], size_t vargtableLen, bool allowEmptyExec, bool clueData) { int argc = 0; char *argv[200] = {NULL}; @@ -147,8 +143,7 @@ int CLIParserParseStringEx(const char *str, void *vargtable[], size_t vargtableL return CLIParserParseArg(argc, argv, vargtable, vargtableLen, allowEmptyExec); } -void CLIParserFree() -{ +void CLIParserFree() { arg_freetable(argtable, argtableLen); argtable = NULL; @@ -156,8 +151,7 @@ void CLIParserFree() } // convertors -int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen) -{ +int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen) { *datalen = 0; int ibuf = 0; @@ -181,8 +175,7 @@ int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int return 0; } -int CLIParamStrToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen) -{ +int CLIParamStrToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen) { *datalen = 0; if (!argstr->count) return 0; diff --git a/client/cmdanalyse.c b/client/cmdanalyse.c index 892312cfa..991d082f5 100644 --- a/client/cmdanalyse.c +++ b/client/cmdanalyse.c @@ -11,8 +11,7 @@ static int CmdHelp(const char *Cmd); -int usage_analyse_lcr(void) -{ +int usage_analyse_lcr(void) { PrintAndLogEx(NORMAL, "Specifying the bytes of a UID with a known LRC will find the last byte value"); PrintAndLogEx(NORMAL, "needed to generate that LRC with a rolling XOR. All bytes should be specified in HEX."); PrintAndLogEx(NORMAL, ""); @@ -26,8 +25,7 @@ int usage_analyse_lcr(void) PrintAndLogEx(NORMAL, "expected output: Target (BA) requires final LRC XOR byte value: 5A"); return 0; } -int usage_analyse_checksum(void) -{ +int usage_analyse_checksum(void) { PrintAndLogEx(NORMAL, "The bytes will be added with eachother and than limited with the applied mask"); PrintAndLogEx(NORMAL, "Finally compute ones' complement of the least significant bytes"); PrintAndLogEx(NORMAL, ""); @@ -43,8 +41,7 @@ int usage_analyse_checksum(void) PrintAndLogEx(NORMAL, "expected output: 0x61"); return 0; } -int usage_analyse_crc(void) -{ +int usage_analyse_crc(void) { PrintAndLogEx(NORMAL, "A stub method to test different crc implementations inside the PM3 sourcecode. Just because you figured out the poly, doesn't mean you get the desired output"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Usage: analyse crc [h] "); @@ -56,8 +53,7 @@ int usage_analyse_crc(void) PrintAndLogEx(NORMAL, " analyse crc 137AF00A0A0D"); return 0; } -int usage_analyse_nuid(void) -{ +int usage_analyse_nuid(void) { PrintAndLogEx(NORMAL, "Generate 4byte NUID from 7byte UID"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Usage: analyse hid [h] "); @@ -69,8 +65,7 @@ int usage_analyse_nuid(void) PrintAndLogEx(NORMAL, " analyse nuid 11223344556677"); return 0; } -int usage_analyse_a(void) -{ +int usage_analyse_a(void) { PrintAndLogEx(NORMAL, "Iceman's personal garbage test command"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Usage: analyse a [h] d "); @@ -83,8 +78,7 @@ int usage_analyse_a(void) return 0; } -static uint8_t calculateLRC(uint8_t *bytes, uint8_t len) -{ +static uint8_t calculateLRC(uint8_t *bytes, uint8_t len) { uint8_t LRC = 0; for (uint8_t i = 0; i < len; i++) LRC ^= bytes[i]; @@ -108,8 +102,7 @@ static uint16_t shiftadd ( uint8_t* bytes, uint8_t len){ return 0; } */ -static uint16_t calcSumCrumbAdd(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcSumCrumbAdd(uint8_t *bytes, uint8_t len, uint32_t mask) { uint16_t sum = 0; for (uint8_t i = 0; i < len; i++) { sum += CRUMB(bytes[i], 0); @@ -120,12 +113,10 @@ static uint16_t calcSumCrumbAdd(uint8_t *bytes, uint8_t len, uint32_t mask) sum &= mask; return sum; } -static uint16_t calcSumCrumbAddOnes(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcSumCrumbAddOnes(uint8_t *bytes, uint8_t len, uint32_t mask) { return (~calcSumCrumbAdd(bytes, len, mask) & mask); } -static uint16_t calcSumNibbleAdd(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcSumNibbleAdd(uint8_t *bytes, uint8_t len, uint32_t mask) { uint16_t sum = 0; for (uint8_t i = 0; i < len; i++) { sum += NIBBLE_LOW(bytes[i]); @@ -134,12 +125,10 @@ static uint16_t calcSumNibbleAdd(uint8_t *bytes, uint8_t len, uint32_t mask) sum &= mask; return sum; } -static uint16_t calcSumNibbleAddOnes(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcSumNibbleAddOnes(uint8_t *bytes, uint8_t len, uint32_t mask) { return (~calcSumNibbleAdd(bytes, len, mask) & mask); } -static uint16_t calcSumCrumbXor(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcSumCrumbXor(uint8_t *bytes, uint8_t len, uint32_t mask) { uint16_t sum = 0; for (uint8_t i = 0; i < len; i++) { sum ^= CRUMB(bytes[i], 0); @@ -150,8 +139,7 @@ static uint16_t calcSumCrumbXor(uint8_t *bytes, uint8_t len, uint32_t mask) sum &= mask; return sum; } -static uint16_t calcSumNibbleXor(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcSumNibbleXor(uint8_t *bytes, uint8_t len, uint32_t mask) { uint16_t sum = 0; for (uint8_t i = 0; i < len; i++) { sum ^= NIBBLE_LOW(bytes[i]); @@ -160,8 +148,7 @@ static uint16_t calcSumNibbleXor(uint8_t *bytes, uint8_t len, uint32_t mask) sum &= mask; return sum; } -static uint16_t calcSumByteXor(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcSumByteXor(uint8_t *bytes, uint8_t len, uint32_t mask) { uint16_t sum = 0; for (uint8_t i = 0; i < len; i++) { sum ^= bytes[i]; @@ -169,8 +156,7 @@ static uint16_t calcSumByteXor(uint8_t *bytes, uint8_t len, uint32_t mask) sum &= mask; return sum; } -static uint16_t calcSumByteAdd(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcSumByteAdd(uint8_t *bytes, uint8_t len, uint32_t mask) { uint16_t sum = 0; for (uint8_t i = 0; i < len; i++) { sum += bytes[i]; @@ -179,13 +165,11 @@ static uint16_t calcSumByteAdd(uint8_t *bytes, uint8_t len, uint32_t mask) return sum; } // Ones complement -static uint16_t calcSumByteAddOnes(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcSumByteAddOnes(uint8_t *bytes, uint8_t len, uint32_t mask) { return (~calcSumByteAdd(bytes, len, mask) & mask); } -static uint16_t calcSumByteSub(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcSumByteSub(uint8_t *bytes, uint8_t len, uint32_t mask) { uint8_t sum = 0; for (uint8_t i = 0; i < len; i++) { sum -= bytes[i]; @@ -193,12 +177,10 @@ static uint16_t calcSumByteSub(uint8_t *bytes, uint8_t len, uint32_t mask) sum &= mask; return sum; } -static uint16_t calcSumByteSubOnes(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcSumByteSubOnes(uint8_t *bytes, uint8_t len, uint32_t mask) { return (~calcSumByteSub(bytes, len, mask) & mask); } -static uint16_t calcSumNibbleSub(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcSumNibbleSub(uint8_t *bytes, uint8_t len, uint32_t mask) { uint8_t sum = 0; for (uint8_t i = 0; i < len; i++) { sum -= NIBBLE_LOW(bytes[i]); @@ -207,14 +189,12 @@ static uint16_t calcSumNibbleSub(uint8_t *bytes, uint8_t len, uint32_t mask) sum &= mask; return sum; } -static uint16_t calcSumNibbleSubOnes(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcSumNibbleSubOnes(uint8_t *bytes, uint8_t len, uint32_t mask) { return (~calcSumNibbleSub(bytes, len, mask) & mask); } // BSD shift checksum 8bit version -static uint16_t calcBSDchecksum8(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcBSDchecksum8(uint8_t *bytes, uint8_t len, uint32_t mask) { uint16_t sum = 0; for (uint8_t i = 0; i < len; i++) { sum = ((sum & 0xFF) >> 1) | ((sum & 0x1) << 7); // rotate accumulator @@ -225,8 +205,7 @@ static uint16_t calcBSDchecksum8(uint8_t *bytes, uint8_t len, uint32_t mask) return sum; } // BSD shift checksum 4bit version -static uint16_t calcBSDchecksum4(uint8_t *bytes, uint8_t len, uint32_t mask) -{ +static uint16_t calcBSDchecksum4(uint8_t *bytes, uint8_t len, uint32_t mask) { uint16_t sum = 0; for (uint8_t i = 0; i < len; i++) { sum = ((sum & 0xF) >> 1) | ((sum & 0x1) << 3); // rotate accumulator @@ -241,8 +220,7 @@ static uint16_t calcBSDchecksum4(uint8_t *bytes, uint8_t len, uint32_t mask) } // measuring LFSR maximum length -int CmdAnalyseLfsr(const char *Cmd) -{ +int CmdAnalyseLfsr(const char *Cmd) { uint16_t start_state = 0; /* Any nonzero start state will work. */ uint16_t lfsr = start_state; @@ -264,8 +242,7 @@ int CmdAnalyseLfsr(const char *Cmd) } return 0; } -int CmdAnalyseLCR(const char *Cmd) -{ +int CmdAnalyseLCR(const char *Cmd) { uint8_t data[50]; char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) == 0 || cmdp == 'h') return usage_analyse_lcr(); @@ -286,8 +263,7 @@ int CmdAnalyseLCR(const char *Cmd) PrintAndLogEx(NORMAL, "Target [%02X] requires final LRC XOR byte value: 0x%02X", data[len - 1], finalXor); return 0; } -int CmdAnalyseCRC(const char *Cmd) -{ +int CmdAnalyseCRC(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) == 0 || cmdp == 'h') return usage_analyse_crc(); @@ -383,8 +359,7 @@ int CmdAnalyseCRC(const char *Cmd) free(data); return 0; } -int CmdAnalyseCHKSUM(const char *Cmd) -{ +int CmdAnalyseCHKSUM(const char *Cmd) { uint8_t data[50]; uint8_t cmdp = 0; @@ -450,14 +425,12 @@ int CmdAnalyseCHKSUM(const char *Cmd) return 0; } -int CmdAnalyseDates(const char *Cmd) -{ +int CmdAnalyseDates(const char *Cmd) { // look for datestamps in a given array of bytes PrintAndLogEx(NORMAL, "To be implemented. Feel free to contribute!"); return 0; } -int CmdAnalyseTEASelfTest(const char *Cmd) -{ +int CmdAnalyseTEASelfTest(const char *Cmd) { uint8_t v[8], v_le[8]; memset(v, 0x00, sizeof(v)); @@ -492,8 +465,7 @@ int CmdAnalyseTEASelfTest(const char *Cmd) return 0; } -char *pb(uint32_t b) -{ +char *pb(uint32_t b) { static char buf1[33] = {0}; static char buf2[33] = {0}; static char *s; @@ -513,8 +485,7 @@ char *pb(uint32_t b) return s; } -int CmdAnalyseA(const char *Cmd) -{ +int CmdAnalyseA(const char *Cmd) { int hexlen = 0; uint8_t cmdp = 0; @@ -880,8 +851,7 @@ int CmdAnalyseA(const char *Cmd) return 0; } -void generate4bNUID(uint8_t *uid, uint8_t *nuid) -{ +void generate4bNUID(uint8_t *uid, uint8_t *nuid) { uint16_t crc; uint8_t b1, b2; @@ -895,8 +865,7 @@ void generate4bNUID(uint8_t *uid, uint8_t *nuid) nuid[3] = crc & 0xFF; } -int CmdAnalyseNuid(const char *Cmd) -{ +int CmdAnalyseNuid(const char *Cmd) { uint8_t nuid[4] = {0}; uint8_t uid[7] = {0}; int len = 0; @@ -942,15 +911,13 @@ static command_t CommandTable[] = { {NULL, NULL, 0, NULL} }; -int CmdAnalyse(const char *Cmd) -{ +int CmdAnalyse(const char *Cmd) { clearCommandBuffer(); CmdsParse(CommandTable, Cmd); return 0; } -int CmdHelp(const char *Cmd) -{ +int CmdHelp(const char *Cmd) { CmdsHelp(CommandTable); return 0; } diff --git a/client/cmdcrc.c b/client/cmdcrc.c index eb46a524d..1a17d1428 100644 --- a/client/cmdcrc.c +++ b/client/cmdcrc.c @@ -11,8 +11,7 @@ #define MAX_ARGS 20 -int split(char *str, char *arr[MAX_ARGS]) -{ +int split(char *str, char *arr[MAX_ARGS]) { int beginIndex = 0; int endIndex; int maxWords = MAX_ARGS; @@ -40,8 +39,7 @@ int split(char *str, char *arr[MAX_ARGS]) return wordCnt; } -int CmdCrc(const char *Cmd) -{ +int CmdCrc(const char *Cmd) { char name[] = {"reveng "}; char Cmd2[100 + 7]; memcpy(Cmd2, name, 7); @@ -62,8 +60,7 @@ int CmdCrc(const char *Cmd) //returns array of model names and the count of models returning // as well as a width array for the width of each model -int GetModels(char *Models[], int *count, uint8_t *width) -{ +int GetModels(char *Models[], int *count, uint8_t *width) { /* default values */ static model_t model = MZERO; @@ -248,8 +245,7 @@ int GetModels(char *Models[], int *count, uint8_t *width) //endian = {0 = calc default endian input and output, b = big endian input and output, B = big endian output, r = right justified // l = little endian input and output, L = little endian output only, t = left justified} //result = calculated crc hex string -int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *result) -{ +int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *result) { /* default values */ static model_t model = MZERO; @@ -368,8 +364,7 @@ int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *res } //test call to RunModel -int CmdrevengTestC(const char *Cmd) -{ +int CmdrevengTestC(const char *Cmd) { int cmdp = 0; char inModel[30] = {0x00}; char inHexStr[30] = {0x00}; @@ -392,8 +387,7 @@ int CmdrevengTestC(const char *Cmd) } //returns a calloced string (needs to be freed) -char *SwapEndianStr(const char *inStr, const size_t len, const uint8_t blockSize) -{ +char *SwapEndianStr(const char *inStr, const size_t len, const uint8_t blockSize) { char *tmp = calloc(len + 1, sizeof(char)); for (uint8_t block = 0; block < (uint8_t)(len / blockSize); block++) { for (size_t i = 0; i < blockSize; i += 2) { @@ -405,8 +399,7 @@ char *SwapEndianStr(const char *inStr, const size_t len, const uint8_t blockSize } // takes hex string in and searches for a matching result (hex string must include checksum) -int CmdrevengSearch(const char *Cmd) -{ +int CmdrevengSearch(const char *Cmd) { #define NMODELS 105 diff --git a/client/cmddata.c b/client/cmddata.c index 2877ca0c8..5aeaca388 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -17,8 +17,7 @@ int g_DemodClock = 0; static int CmdHelp(const char *Cmd); -int usage_data_printdemodbuf(void) -{ +int usage_data_printdemodbuf(void) { PrintAndLogEx(NORMAL, "Usage: data printdemodbuffer x o l "); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h This help"); @@ -27,8 +26,7 @@ int usage_data_printdemodbuf(void) PrintAndLogEx(NORMAL, " l enter length to print in # of bits or hex characters respectively"); return 0; } -int usage_data_manrawdecode(void) -{ +int usage_data_manrawdecode(void) { PrintAndLogEx(NORMAL, "Usage: data manrawdecode [invert] [maxErr]"); PrintAndLogEx(NORMAL, " Takes 10 and 01 and converts to 0 and 1 respectively"); PrintAndLogEx(NORMAL, " --must have binary sequence in demodbuffer (run data askrawdemod first)"); @@ -38,8 +36,7 @@ int usage_data_manrawdecode(void) PrintAndLogEx(NORMAL, " Example: data manrawdecode = decode manchester bitstream from the demodbuffer"); return 0; } -int usage_data_biphaserawdecode(void) -{ +int usage_data_biphaserawdecode(void) { PrintAndLogEx(NORMAL, "Usage: data biphaserawdecode [offset] [invert] [maxErr]"); PrintAndLogEx(NORMAL, " Converts 10 or 01 to 1 and 11 or 00 to 0"); PrintAndLogEx(NORMAL, " --must have binary sequence in demodbuffer (run data askrawdemod first)"); @@ -53,8 +50,7 @@ int usage_data_biphaserawdecode(void) PrintAndLogEx(NORMAL, " Example: data biphaserawdecode 1 1 = decode biphase bitstream from the demodbuffer, set offset, and invert output"); return 0; } -int usage_data_rawdemod(void) -{ +int usage_data_rawdemod(void) { PrintAndLogEx(NORMAL, "Usage: data rawdemod [modulation] |"); PrintAndLogEx(NORMAL, " [modulation] as 2 char, 'ab' for ask/biphase, 'am' for ask/manchester, 'ar' for ask/raw, 'fs' for fsk, ..."); PrintAndLogEx(NORMAL, " 'nr' for nrz/direct, 'p1' for psk1, 'p2' for psk2"); @@ -71,8 +67,7 @@ int usage_data_rawdemod(void) PrintAndLogEx(NORMAL, " : data rawdemod p2 = demod GraphBuffer using: psk2 - autodetect"); return 0; } -int usage_data_rawdemod_am(void) -{ +int usage_data_rawdemod_am(void) { PrintAndLogEx(NORMAL, "Usage: data rawdemod am [clock] [maxError] [maxLen] [amplify]"); PrintAndLogEx(NORMAL, " ['s'] optional, check for Sequence Terminator"); PrintAndLogEx(NORMAL, " [set clock as integer] optional, if not set, autodetect"); @@ -88,8 +83,7 @@ int usage_data_rawdemod_am(void) PrintAndLogEx(NORMAL, " : data rawdemod am 64 1 0 = demod an ask/manchester tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors"); return 0; } -int usage_data_rawdemod_ab(void) -{ +int usage_data_rawdemod_ab(void) { PrintAndLogEx(NORMAL, "Usage: data rawdemod ab [offset] [clock] [maxError] [maxLen] "); PrintAndLogEx(NORMAL, " [offset], offset to begin biphase, default=0"); PrintAndLogEx(NORMAL, " [set clock as integer] optional, if not set, autodetect"); @@ -112,8 +106,7 @@ int usage_data_rawdemod_ab(void) PrintAndLogEx(NORMAL, " : data rawdemod ab 0 64 1 0 0 a = demod an ask/biph tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors, and amp"); return 0; } -int usage_data_rawdemod_ar(void) -{ +int usage_data_rawdemod_ar(void) { PrintAndLogEx(NORMAL, "Usage: data rawdemod ar [clock] [maxError] [maxLen] [amplify]"); PrintAndLogEx(NORMAL, " [set clock as integer] optional, if not set, autodetect"); PrintAndLogEx(NORMAL, " , 1 to invert output"); @@ -130,8 +123,7 @@ int usage_data_rawdemod_ar(void) PrintAndLogEx(NORMAL, " : data rawdemod ar 64 1 0 0 a = demod an ask tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors, and amp"); return 0; } -int usage_data_rawdemod_fs(void) -{ +int usage_data_rawdemod_fs(void) { PrintAndLogEx(NORMAL, "Usage: data rawdemod fs [clock] [fchigh] [fclow]"); PrintAndLogEx(NORMAL, " [set clock as integer] optional, omit for autodetect."); PrintAndLogEx(NORMAL, " , 1 for invert output, can be used even if the clock is omitted"); @@ -147,8 +139,7 @@ int usage_data_rawdemod_fs(void) PrintAndLogEx(NORMAL, " : data rawdemod fs 50 1 10 8 = demod an fsk2a RF/50 tag from GraphBuffer"); return 0; } -int usage_data_rawdemod_nr(void) -{ +int usage_data_rawdemod_nr(void) { PrintAndLogEx(NORMAL, "Usage: data rawdemod nr [clock] <0|1> [maxError]"); PrintAndLogEx(NORMAL, " [set clock as integer] optional, if not set, autodetect."); PrintAndLogEx(NORMAL, " , 1 for invert output"); @@ -161,8 +152,7 @@ int usage_data_rawdemod_nr(void) PrintAndLogEx(NORMAL, " : data rawdemod nr 64 1 0 = demod a nrz/direct tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors"); return 0; } -int usage_data_rawdemod_p1(void) -{ +int usage_data_rawdemod_p1(void) { PrintAndLogEx(NORMAL, "Usage: data rawdemod p1 [clock] <0|1> [maxError]"); PrintAndLogEx(NORMAL, " [set clock as integer] optional, if not set, autodetect."); PrintAndLogEx(NORMAL, " , 1 for invert output"); @@ -175,8 +165,7 @@ int usage_data_rawdemod_p1(void) PrintAndLogEx(NORMAL, " : data rawdemod p1 64 1 0 = demod a psk1 tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors"); return 0; } -int usage_data_rawdemod_p2(void) -{ +int usage_data_rawdemod_p2(void) { PrintAndLogEx(NORMAL, "Usage: data rawdemod p2 [clock] <0|1> [maxError]"); PrintAndLogEx(NORMAL, " [set clock as integer] optional, if not set, autodetect."); PrintAndLogEx(NORMAL, " , 1 for invert output"); @@ -189,8 +178,7 @@ int usage_data_rawdemod_p2(void) PrintAndLogEx(NORMAL, " : data rawdemod p2 64 1 0 = demod a psk2 tag from GraphBuffer using a clock of RF/64, inverting output and allowing 0 demod errors"); return 0; } -int usage_data_autocorr(void) -{ +int usage_data_autocorr(void) { PrintAndLogEx(NORMAL, "Autocorrelate is used to detect repeating sequences. We use it as detection of length in bits a message inside the signal is"); PrintAndLogEx(NORMAL, "Usage: data autocorr w [g]"); PrintAndLogEx(NORMAL, "Options:"); @@ -199,8 +187,7 @@ int usage_data_autocorr(void) PrintAndLogEx(NORMAL, " g save back to GraphBuffer (overwrite)"); return 0; } -int usage_data_undecimate(void) -{ +int usage_data_undecimate(void) { PrintAndLogEx(NORMAL, "Usage: data undec [factor]"); PrintAndLogEx(NORMAL, "This function performs un-decimation, by repeating each sample N times"); PrintAndLogEx(NORMAL, "Options:"); @@ -209,8 +196,7 @@ int usage_data_undecimate(void) PrintAndLogEx(NORMAL, "Example: 'data undec 3'"); return 0; } -int usage_data_detectclock(void) -{ +int usage_data_detectclock(void) { PrintAndLogEx(NORMAL, "Usage: data detectclock [modulation] "); PrintAndLogEx(NORMAL, " [modulation as char], specify the modulation type you want to detect the clock of"); PrintAndLogEx(NORMAL, " , specify the clock (optional - to get best start position only)"); @@ -222,28 +208,24 @@ int usage_data_detectclock(void) PrintAndLogEx(NORMAL, " data detectclock n = detect the clock of an nrz/direct modulated wave in the GraphBuffer"); return 0; } -int usage_data_hex2bin(void) -{ +int usage_data_hex2bin(void) { PrintAndLogEx(NORMAL, "Usage: data hex2bin "); PrintAndLogEx(NORMAL, " This function will ignore all non-hexadecimal characters (but stop reading on whitespace)"); return 0; } -int usage_data_bin2hex(void) -{ +int usage_data_bin2hex(void) { PrintAndLogEx(NORMAL, "Usage: data bin2hex "); PrintAndLogEx(NORMAL, " This function will ignore all characters not 1 or 0 (but stop reading on whitespace)"); return 0; } -int usage_data_buffclear(void) -{ +int usage_data_buffclear(void) { PrintAndLogEx(NORMAL, "This function clears the bigbuff on deviceside"); PrintAndLogEx(NORMAL, "Usage: data buffclear [h]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h This help"); return 0; } -int usage_data_fsktonrz() -{ +int usage_data_fsktonrz() { PrintAndLogEx(NORMAL, "Usage: data fsktonrz c l f "); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h This help"); @@ -255,8 +237,7 @@ int usage_data_fsktonrz() //set the demod buffer with given array of binary (one bit per byte) //by marshmellow -void setDemodBuf(uint8_t *buf, size_t size, size_t start_idx) -{ +void setDemodBuf(uint8_t *buf, size_t size, size_t start_idx) { if (buf == NULL) return; if (size > MAX_DEMOD_BUF_LEN - start_idx) @@ -268,8 +249,7 @@ void setDemodBuf(uint8_t *buf, size_t size, size_t start_idx) DemodBufferLen = size; } -bool getDemodBuf(uint8_t *buf, size_t *size) -{ +bool getDemodBuf(uint8_t *buf, size_t *size) { if (buf == NULL) return false; if (size == NULL) return false; if (*size == 0) return false; @@ -282,41 +262,35 @@ bool getDemodBuf(uint8_t *buf, size_t *size) // include // Root mean square -double rms(double *v, size_t n) -{ +double rms(double *v, size_t n) { double sum = 0.0; for (size_t i = 0; i < n; i++) sum += v[i] * v[i]; return sqrt(sum / n); } -int cmp_int(const void *a, const void *b) -{ +int cmp_int(const void *a, const void *b) { if (*(const int *)a < * (const int *)b) return -1; else return *(const int *)a > *(const int *)b; } -int cmp_uint8(const void *a, const void *b) -{ +int cmp_uint8(const void *a, const void *b) { if (*(const uint8_t *)a < * (const uint8_t *)b) return -1; else return *(const uint8_t *)a > *(const uint8_t *)b; } // Median of a array of values -double median_int(int *src, size_t size) -{ +double median_int(int *src, size_t size) { qsort(src, size, sizeof(int), cmp_int); return 0.5 * (src[size / 2] + src[(size - 1) / 2]); } -double median_uint8(uint8_t *src, size_t size) -{ +double median_uint8(uint8_t *src, size_t size) { qsort(src, size, sizeof(uint8_t), cmp_uint8); return 0.5 * (src[size / 2] + src[(size - 1) / 2]); } // function to compute mean for a series -static double compute_mean(const int *data, size_t n) -{ +static double compute_mean(const int *data, size_t n) { double mean = 0.0; for (size_t i = 0; i < n; i++) mean += data[i]; @@ -325,8 +299,7 @@ static double compute_mean(const int *data, size_t n) } // function to compute variance for a series -static double compute_variance(const int *data, size_t n) -{ +static double compute_variance(const int *data, size_t n) { double variance = 0.0; double mean = compute_mean(data, n); @@ -362,8 +335,7 @@ static double compute_autoc(const int *data, size_t n, int lag) { */ // option '1' to save DemodBuffer any other to restore -void save_restoreDB(uint8_t saveOpt) -{ +void save_restoreDB(uint8_t saveOpt) { static uint8_t SavedDB[MAX_DEMOD_BUF_LEN]; static size_t SavedDBlen; static bool DB_Saved = false; @@ -386,8 +358,7 @@ void save_restoreDB(uint8_t saveOpt) } } -int CmdSetDebugMode(const char *Cmd) -{ +int CmdSetDebugMode(const char *Cmd) { int demod = 0; sscanf(Cmd, "%i", &demod); g_debugMode = (uint8_t)demod; @@ -396,8 +367,7 @@ int CmdSetDebugMode(const char *Cmd) //by marshmellow // max output to 512 bits if we have more - should be plenty -void printDemodBuff(void) -{ +void printDemodBuff(void) { int len = DemodBufferLen; if (len < 1) { PrintAndLogEx(NORMAL, "(printDemodBuff) no bits found in demod buffer"); @@ -408,8 +378,7 @@ void printDemodBuff(void) PrintAndLogEx(NORMAL, "%s", sprint_bin_break(DemodBuffer, len, 16)); } -int CmdPrintDemodBuff(const char *Cmd) -{ +int CmdPrintDemodBuff(const char *Cmd) { char hex[512] = {0x00}; bool hexMode = false; bool errors = false; @@ -466,8 +435,7 @@ int CmdPrintDemodBuff(const char *Cmd) //by marshmellow //this function strictly converts >1 to 1 and <1 to 0 for each sample in the graphbuffer -int CmdGetBitStream(const char *Cmd) -{ +int CmdGetBitStream(const char *Cmd) { CmdHpf(Cmd); for (uint32_t i = 0; i < GraphTraceLen; i++) GraphBuffer[i] = (GraphBuffer[i] >= 1) ? 1 : 0; @@ -482,8 +450,7 @@ int CmdGetBitStream(const char *Cmd) //verbose will print results and demoding messages //emSearch will auto search for EM410x format in bitstream //askType switches decode: ask/raw = 0, ask/manchester = 1 -int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, bool *stCheck) -{ +int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, bool *stCheck) { int invert = 0; int clk = 0; int maxErr = 100; @@ -569,8 +536,7 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, return 1; } -int ASKDemod(const char *Cmd, bool verbose, bool emSearch, uint8_t askType) -{ +int ASKDemod(const char *Cmd, bool verbose, bool emSearch, uint8_t askType) { bool st = false; return ASKDemod_ext(Cmd, verbose, emSearch, askType, &st); } @@ -579,8 +545,7 @@ int ASKDemod(const char *Cmd, bool verbose, bool emSearch, uint8_t askType) //takes 5 arguments - clock, invert, maxErr, maxLen as integers and amplify as char == 'a' //attempts to demodulate ask while decoding manchester //prints binary found and saves in graphbuffer for further commands -int Cmdaskmandemod(const char *Cmd) -{ +int Cmdaskmandemod(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 45 || cmdp == 'h') return usage_data_rawdemod_am(); @@ -596,8 +561,7 @@ int Cmdaskmandemod(const char *Cmd) //by marshmellow //manchester decode //stricktly take 10 and 01 and convert to 0 and 1 -int Cmdmandecoderaw(const char *Cmd) -{ +int Cmdmandecoderaw(const char *Cmd) { size_t size = 0; int high = 0, low = 0; int i = 0, errCnt = 0, invert = 0, maxErr = 20; @@ -652,8 +616,7 @@ int Cmdmandecoderaw(const char *Cmd) //takes 2 arguments "offset" default = 0 if 1 it will shift the decode by one bit // and "invert" default = 0 if 1 it will invert output // the argument offset allows us to manually shift if the output is incorrect - [EDIT: now auto detects] -int CmdBiphaseDecodeRaw(const char *Cmd) -{ +int CmdBiphaseDecodeRaw(const char *Cmd) { size_t size = 0; int offset = 0, invert = 0, maxErr = 20, errCnt = 0; char cmdp = tolower(param_getchar(Cmd, 0)); @@ -695,8 +658,7 @@ int CmdBiphaseDecodeRaw(const char *Cmd) //by marshmellow // - ASK Demod then Biphase decode GraphBuffer samples -int ASKbiphaseDemod(const char *Cmd, bool verbose) -{ +int ASKbiphaseDemod(const char *Cmd, bool verbose) { //ask raw demod GraphBuffer first int offset = 0, clk = 0, invert = 0, maxErr = 0; sscanf(Cmd, "%i %i %i %i", &offset, &clk, &invert, &maxErr); @@ -735,8 +697,7 @@ int ASKbiphaseDemod(const char *Cmd, bool verbose) return 1; } //by marshmellow - see ASKbiphaseDemod -int Cmdaskbiphdemod(const char *Cmd) -{ +int Cmdaskbiphdemod(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 25 || cmdp == 'h') return usage_data_rawdemod_ab(); @@ -744,16 +705,14 @@ int Cmdaskbiphdemod(const char *Cmd) } //by marshmellow - see ASKDemod -int Cmdaskrawdemod(const char *Cmd) -{ +int Cmdaskrawdemod(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 25 || cmdp == 'h') return usage_data_rawdemod_ar(); return ASKDemod(Cmd, true, false, 0); } -int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph, bool verbose) -{ +int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph, bool verbose) { // sanity check if (window > len) window = len; @@ -839,8 +798,7 @@ int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph return retval; } -int CmdAutoCorr(const char *Cmd) -{ +int CmdAutoCorr(const char *Cmd) { uint32_t window = 4000; uint8_t cmdp = 0; @@ -875,8 +833,7 @@ int CmdAutoCorr(const char *Cmd) return AutoCorrelate(GraphBuffer, GraphBuffer, GraphTraceLen, window, updateGrph, true); } -int CmdBitsamples(const char *Cmd) -{ +int CmdBitsamples(const char *Cmd) { int cnt = 0; uint8_t got[12288]; @@ -898,8 +855,7 @@ int CmdBitsamples(const char *Cmd) return 0; } -int CmdBuffClear(const char *Cmd) -{ +int CmdBuffClear(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_data_buffclear(); @@ -910,8 +866,7 @@ int CmdBuffClear(const char *Cmd) return 0; } -int CmdDec(const char *Cmd) -{ +int CmdDec(const char *Cmd) { for (int i = 0; i < (GraphTraceLen / 2); ++i) GraphBuffer[i] = GraphBuffer[i * 2]; GraphTraceLen /= 2; @@ -926,8 +881,7 @@ int CmdDec(const char *Cmd) * @param Cmd * @return */ -int CmdUndec(const char *Cmd) -{ +int CmdUndec(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_data_undecimate(); @@ -952,8 +906,7 @@ int CmdUndec(const char *Cmd) //by marshmellow //shift graph zero up or down based on input + or - -int CmdGraphShiftZero(const char *Cmd) -{ +int CmdGraphShiftZero(const char *Cmd) { int shift = 0, shiftedVal = 0; //set options from parameters entered with the command sscanf(Cmd, "%i", &shift); @@ -974,8 +927,7 @@ int CmdGraphShiftZero(const char *Cmd) return 0; } -int AskEdgeDetect(const int *in, int *out, int len, int threshold) -{ +int AskEdgeDetect(const int *in, int *out, int len, int threshold) { int last = 0; for (int i = 1; i < len; i++) { if (in[i] - in[i - 1] >= threshold) //large jump up @@ -991,8 +943,7 @@ int AskEdgeDetect(const int *in, int *out, int len, int threshold) //use large jumps in read samples to identify edges of waves and then amplify that wave to max //similar to dirtheshold, threshold commands //takes a threshold length which is the measured length between two samples then determines an edge -int CmdAskEdgeDetect(const char *Cmd) -{ +int CmdAskEdgeDetect(const char *Cmd) { int thresLen = 25; int ans = 0; sscanf(Cmd, "%i", &thresLen); @@ -1005,8 +956,7 @@ int CmdAskEdgeDetect(const char *Cmd) /* Print our clock rate */ // uses data from graphbuffer // adjusted to take char parameter for type of modulation to find the clock - by marshmellow. -int CmdDetectClockRate(const char *Cmd) -{ +int CmdDetectClockRate(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 6 || strlen(Cmd) == 0 || cmdp == 'h') return usage_data_detectclock(); @@ -1033,8 +983,7 @@ int CmdDetectClockRate(const char *Cmd) return clock; } -char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert) -{ +char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert) { static char fType[8]; memset(fType, 0x00, 8); char *fskType = fType; @@ -1063,8 +1012,7 @@ char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert) //fsk raw demod and print binary //takes 4 arguments - Clock, invert, fchigh, fclow //defaults: clock = 50, invert=1, fchigh=10, fclow=8 (RF/10 RF/8 (fsk2a)) -int FSKrawDemod(const char *Cmd, bool verbose) -{ +int FSKrawDemod(const char *Cmd, bool verbose) { //raw fsk demod no manchester decoding no start bit finding just get binary from wave uint8_t rfLen, invert, fchigh, fclow; @@ -1130,8 +1078,7 @@ int FSKrawDemod(const char *Cmd, bool verbose) //fsk raw demod and print binary //takes 4 arguments - Clock, invert, fchigh, fclow //defaults: clock = 50, invert=1, fchigh=10, fclow=8 (RF/10 RF/8 (fsk2a)) -int CmdFSKrawdemod(const char *Cmd) -{ +int CmdFSKrawdemod(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 20 || cmdp == 'h') return usage_data_rawdemod_fs(); @@ -1140,8 +1087,7 @@ int CmdFSKrawdemod(const char *Cmd) //by marshmellow //attempt to psk1 demod graph buffer -int PSKDemod(const char *Cmd, bool verbose) -{ +int PSKDemod(const char *Cmd, bool verbose) { int invert = 0, clk = 0, maxErr = 100; sscanf(Cmd, "%i %i %i", &clk, &invert, &maxErr); if (clk == 1) { @@ -1182,8 +1128,7 @@ int PSKDemod(const char *Cmd, bool verbose) return 1; } -int CmdPSKIdteck(const char *Cmd) -{ +int CmdPSKIdteck(const char *Cmd) { if (!PSKDemod("", false)) { PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck PSKDemod failed"); @@ -1247,8 +1192,7 @@ int CmdPSKIdteck(const char *Cmd) // takes 3 arguments - clock, invert, maxErr as integers // attempts to demodulate nrz only // prints binary found and saves in demodbuffer for further commands -int NRZrawDemod(const char *Cmd, bool verbose) -{ +int NRZrawDemod(const char *Cmd, bool verbose) { int errCnt = 0, clkStartIdx = 0; int invert = 0, clk = 0, maxErr = 100; @@ -1295,8 +1239,7 @@ int NRZrawDemod(const char *Cmd, bool verbose) return 1; } -int CmdNRZrawDemod(const char *Cmd) -{ +int CmdNRZrawDemod(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 16 || cmdp == 'h') return usage_data_rawdemod_nr(); @@ -1307,8 +1250,7 @@ int CmdNRZrawDemod(const char *Cmd) // takes 3 arguments - clock, invert, maxErr as integers // attempts to demodulate psk only // prints binary found and saves in demodbuffer for further commands -int CmdPSK1rawDemod(const char *Cmd) -{ +int CmdPSK1rawDemod(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 16 || cmdp == 'h') return usage_data_rawdemod_p1(); @@ -1326,8 +1268,7 @@ int CmdPSK1rawDemod(const char *Cmd) // by marshmellow // takes same args as cmdpsk1rawdemod -int CmdPSK2rawDemod(const char *Cmd) -{ +int CmdPSK2rawDemod(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 16 || cmdp == 'h') return usage_data_rawdemod_p2(); @@ -1344,8 +1285,7 @@ int CmdPSK2rawDemod(const char *Cmd) } // by marshmellow - combines all raw demod functions into one menu command -int CmdRawDemod(const char *Cmd) -{ +int CmdRawDemod(const char *Cmd) { int ans = 0; if (strlen(Cmd) > 35 || strlen(Cmd) < 2) @@ -1365,8 +1305,7 @@ int CmdRawDemod(const char *Cmd) return ans; } -void setClockGrid(int clk, int offset) -{ +void setClockGrid(int clk, int offset) { g_DemodStartIdx = offset; g_DemodClock = clk; PrintAndLogEx(DEBUG, "DEBUG: (setClockGrid) demodoffset %d, clk %d", offset, clk); @@ -1390,8 +1329,7 @@ void setClockGrid(int clk, int offset) } } -int CmdGrid(const char *Cmd) -{ +int CmdGrid(const char *Cmd) { sscanf(Cmd, "%i %i", &PlotGridX, &PlotGridY); PlotGridXdefault = PlotGridX; PlotGridYdefault = PlotGridY; @@ -1399,15 +1337,13 @@ int CmdGrid(const char *Cmd) return 0; } -int CmdSetGraphMarkers(const char *Cmd) -{ +int CmdSetGraphMarkers(const char *Cmd) { sscanf(Cmd, "%i %i", &CursorCPos, &CursorDPos); RepaintGraphWindow(); return 0; } -int CmdHexsamples(const char *Cmd) -{ +int CmdHexsamples(const char *Cmd) { int i, j, requested = 0, offset = 0; char string_buf[25]; char *string_ptr = string_buf; @@ -1449,15 +1385,13 @@ int CmdHexsamples(const char *Cmd) return 0; } -int CmdHide(const char *Cmd) -{ +int CmdHide(const char *Cmd) { HideGraphWindow(); return 0; } //zero mean GraphBuffer -int CmdHpf(const char *Cmd) -{ +int CmdHpf(const char *Cmd) { uint8_t bits[GraphTraceLen]; size_t size = getFromGraphBuf(bits); removeSignalOffset(bits, size); @@ -1470,15 +1404,13 @@ int CmdHpf(const char *Cmd) return 0; } -bool _headBit(BitstreamOut *stream) -{ +bool _headBit(BitstreamOut *stream) { int bytepos = stream->position >> 3; // divide by 8 int bitpos = (stream->position++) & 7; // mask out 00000111 return (*(stream->buffer + bytepos) >> (7 - bitpos)) & 1; } -uint8_t getByte(uint8_t bits_per_sample, BitstreamOut *b) -{ +uint8_t getByte(uint8_t bits_per_sample, BitstreamOut *b) { uint8_t val = 0; for (int i = 0 ; i < bits_per_sample; i++) val |= (_headBit(b) << (7 - i)); @@ -1486,8 +1418,7 @@ uint8_t getByte(uint8_t bits_per_sample, BitstreamOut *b) return val; } -int getSamples(int n, bool silent) -{ +int getSamples(int n, bool silent) { //If we get all but the last byte in bigbuf, // we don't have to worry about remaining trash // in the last byte in case the bits-per-sample @@ -1548,14 +1479,12 @@ int getSamples(int n, bool silent) return 0; } -int CmdSamples(const char *Cmd) -{ +int CmdSamples(const char *Cmd) { int n = strtol(Cmd, NULL, 0); return getSamples(n, false); } -int CmdTuneSamples(const char *Cmd) -{ +int CmdTuneSamples(const char *Cmd) { #define NON_VOLTAGE 1000 #define LF_UNUSABLE_V 2000 #define LF_MARGINAL_V 10000 @@ -1654,8 +1583,7 @@ int CmdTuneSamples(const char *Cmd) return 0; } -int CmdLoad(const char *Cmd) -{ +int CmdLoad(const char *Cmd) { char filename[FILE_PATH_SIZE] = {0x00}; int len = 0; @@ -1698,8 +1626,7 @@ int CmdLoad(const char *Cmd) } // trim graph from the end -int CmdLtrim(const char *Cmd) -{ +int CmdLtrim(const char *Cmd) { // sanitycheck if (GraphTraceLen <= 0) return 1; @@ -1713,8 +1640,7 @@ int CmdLtrim(const char *Cmd) } // trim graph from the beginning -int CmdRtrim(const char *Cmd) -{ +int CmdRtrim(const char *Cmd) { int ds = atoi(Cmd); @@ -1727,8 +1653,7 @@ int CmdRtrim(const char *Cmd) } // trim graph (middle) piece -int CmdMtrim(const char *Cmd) -{ +int CmdMtrim(const char *Cmd) { int start = 0, stop = 0; sscanf(Cmd, "%i %i", &start, &stop); @@ -1744,8 +1669,7 @@ int CmdMtrim(const char *Cmd) return 0; } -int CmdNorm(const char *Cmd) -{ +int CmdNorm(const char *Cmd) { int i; int max = INT_MIN, min = INT_MAX; @@ -1771,14 +1695,12 @@ int CmdNorm(const char *Cmd) return 0; } -int CmdPlot(const char *Cmd) -{ +int CmdPlot(const char *Cmd) { ShowGraphWindow(); return 0; } -int CmdSave(const char *Cmd) -{ +int CmdSave(const char *Cmd) { int len = 0; char filename[FILE_PATH_SIZE] = {0x00}; @@ -1803,8 +1725,7 @@ int CmdSave(const char *Cmd) return 0; } -int CmdScale(const char *Cmd) -{ +int CmdScale(const char *Cmd) { CursorScaleFactor = atoi(Cmd); if (CursorScaleFactor == 0) { PrintAndLogEx(FAILED, "bad, can't have zero scale"); @@ -1814,8 +1735,7 @@ int CmdScale(const char *Cmd) return 0; } -int directionalThreshold(const int *in, int *out, size_t len, int8_t up, int8_t down) -{ +int directionalThreshold(const int *in, int *out, size_t len, int8_t up, int8_t down) { int lastValue = in[0]; @@ -1844,8 +1764,7 @@ int directionalThreshold(const int *in, int *out, size_t len, int8_t up, int8_t return 0; } -int CmdDirectionalThreshold(const char *Cmd) -{ +int CmdDirectionalThreshold(const char *Cmd) { int8_t up = param_get8(Cmd, 0); int8_t down = param_get8(Cmd, 1); @@ -1863,8 +1782,7 @@ int CmdDirectionalThreshold(const char *Cmd) return 0; } -int CmdZerocrossings(const char *Cmd) -{ +int CmdZerocrossings(const char *Cmd) { // Zero-crossings aren't meaningful unless the signal is zero-mean. CmdHpf(""); @@ -1900,8 +1818,7 @@ int CmdZerocrossings(const char *Cmd) * @param Cmd * @return */ -int Cmdbin2hex(const char *Cmd) -{ +int Cmdbin2hex(const char *Cmd) { int bg = 0, en = 0; if (param_getptr(Cmd, &bg, &en, 0)) return usage_data_bin2hex(); @@ -1931,8 +1848,7 @@ int Cmdbin2hex(const char *Cmd) return 0; } -int Cmdhex2bin(const char *Cmd) -{ +int Cmdhex2bin(const char *Cmd) { int bg = 0, en = 0; if (param_getptr(Cmd, &bg, &en, 0)) return usage_data_hex2bin(); @@ -1976,8 +1892,7 @@ static const int HighTone[] = { 1, 1, 1, 1, -1, -1, -1, -1, -1, // note one extra -1 to padd due to 50/8 remainder }; */ -void GetHiLoTone(int *LowTone, int *HighTone, int clk, int LowToneFC, int HighToneFC) -{ +void GetHiLoTone(int *LowTone, int *HighTone, int clk, int LowToneFC, int HighToneFC) { int i, j = 0; int Left_Modifier = ((clk % LowToneFC) % 2) + ((clk % LowToneFC) / 2); int Right_Modifier = (clk % LowToneFC) / 2; @@ -2040,8 +1955,7 @@ void GetHiLoTone(int *LowTone, int *HighTone, int clk, int LowToneFC, int HighTo //old CmdFSKdemod adapted by marshmellow //converts FSK to clear NRZ style wave. (or demodulates) -int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC) -{ +int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC) { uint8_t ans = 0; if (clk == 0 || LowToneFC == 0 || HighToneFC == 0) { int firstClockEdge = 0; @@ -2102,8 +2016,7 @@ int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC) return 0; } -int CmdFSKToNRZ(const char *Cmd) -{ +int CmdFSKToNRZ(const char *Cmd) { // take clk, fc_low, fc_high // blank = auto; bool errors = false; @@ -2143,8 +2056,7 @@ int CmdFSKToNRZ(const char *Cmd) return ans; } -int CmdDataIIR(const char *Cmd) -{ +int CmdDataIIR(const char *Cmd) { uint8_t k = param_get8(Cmd, 0); //iceIIR_Butterworth(GraphBuffer, GraphTraceLen); iceSimple_Filter(GraphBuffer, GraphTraceLen, k); @@ -2198,15 +2110,13 @@ static command_t CommandTable[] = { {NULL, NULL, 0, NULL} }; -int CmdData(const char *Cmd) -{ +int CmdData(const char *Cmd) { clearCommandBuffer(); CmdsParse(CommandTable, Cmd); return 0; } -int CmdHelp(const char *Cmd) -{ +int CmdHelp(const char *Cmd) { CmdsHelp(CommandTable); return 0; } diff --git a/client/cmdflashmem.c b/client/cmdflashmem.c index 68faf826e..0701f1d2d 100644 --- a/client/cmdflashmem.c +++ b/client/cmdflashmem.c @@ -26,8 +26,7 @@ static int CmdHelp(const char *Cmd); -int usage_flashmem_spibaud(void) -{ +int usage_flashmem_spibaud(void) { PrintAndLogEx(NORMAL, "Usage: mem spibaud [h] "); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); @@ -41,8 +40,7 @@ int usage_flashmem_spibaud(void) return 0; } -int usage_flashmem_read(void) -{ +int usage_flashmem_read(void) { PrintAndLogEx(NORMAL, "Read flash memory on device"); PrintAndLogEx(NORMAL, "Usage: mem read o l "); PrintAndLogEx(NORMAL, " o : offset in memory"); @@ -53,8 +51,7 @@ int usage_flashmem_read(void) PrintAndLogEx(NORMAL, " mem read o 1024 l 10"); // read 10 bytes starting at offset 1024 return 0; } -int usage_flashmem_load(void) -{ +int usage_flashmem_load(void) { PrintAndLogEx(NORMAL, "Loads binary file into flash memory on device"); PrintAndLogEx(NORMAL, "Usage: mem load o f m t i"); PrintAndLogEx(NORMAL, " o : offset in memory"); @@ -71,8 +68,7 @@ int usage_flashmem_load(void) PrintAndLogEx(NORMAL, " mem load f default_iclass_keys i"); return 0; } -int usage_flashmem_save(void) -{ +int usage_flashmem_save(void) { PrintAndLogEx(NORMAL, "Saves flash memory on device into the file"); PrintAndLogEx(NORMAL, " Usage: mem save o l f "); PrintAndLogEx(NORMAL, " o : offset in memory"); @@ -85,8 +81,7 @@ int usage_flashmem_save(void) PrintAndLogEx(NORMAL, " mem save f myfile o 1024 l 4096"); // downlowd 4096 bytes from offset 1024 to file myfile return 0; } -int usage_flashmem_wipe(void) -{ +int usage_flashmem_wipe(void) { PrintAndLogEx(WARNING, "[OBS] use with caution."); PrintAndLogEx(NORMAL, "Wipe flash memory on device, which fills memory with 0xFF\n"); @@ -100,8 +95,7 @@ int usage_flashmem_wipe(void) PrintAndLogEx(NORMAL, " mem wipe p 0"); // wipes first page. return 0; } -int usage_flashmem_info(void) -{ +int usage_flashmem_info(void) { PrintAndLogEx(NORMAL, "Collect signature and verify it from flash memory\n"); PrintAndLogEx(NORMAL, " Usage: mem info [h|s|w]"); PrintAndLogEx(NORMAL, " s : create a signature"); @@ -113,8 +107,7 @@ int usage_flashmem_info(void) return 0; } -int CmdFlashMemRead(const char *Cmd) -{ +int CmdFlashMemRead(const char *Cmd) { uint8_t cmdp = 0; bool errors = false; @@ -153,8 +146,7 @@ int CmdFlashMemRead(const char *Cmd) return 0; } -int CmdFlashmemSpiBaudrate(const char *Cmd) -{ +int CmdFlashmemSpiBaudrate(const char *Cmd) { char ctmp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) < 1 || ctmp == 'h') return usage_flashmem_spibaud(); @@ -166,8 +158,7 @@ int CmdFlashmemSpiBaudrate(const char *Cmd) return 0; } -int CmdFlashMemLoad(const char *Cmd) -{ +int CmdFlashMemLoad(const char *Cmd) { uint32_t start_index = 0; char filename[FILE_PATH_SIZE] = {0}; @@ -304,8 +295,7 @@ int CmdFlashMemLoad(const char *Cmd) PrintAndLogEx(SUCCESS, "Wrote %u bytes to offset %u", datalen, start_index); return 0; } -int CmdFlashMemSave(const char *Cmd) -{ +int CmdFlashMemSave(const char *Cmd) { char filename[FILE_PATH_SIZE] = {0}; uint8_t cmdp = 0; @@ -361,8 +351,7 @@ int CmdFlashMemSave(const char *Cmd) free(dump); return 0; } -int CmdFlashMemWipe(const char *Cmd) -{ +int CmdFlashMemWipe(const char *Cmd) { uint8_t cmdp = 0; bool errors = false; @@ -411,8 +400,7 @@ int CmdFlashMemWipe(const char *Cmd) return 0; } -int CmdFlashMemInfo(const char *Cmd) -{ +int CmdFlashMemInfo(const char *Cmd) { uint8_t sha_hash[20] = {0}; mbedtls_rsa_context rsa; @@ -612,15 +600,13 @@ static command_t CommandTable[] = { {NULL, NULL, 0, NULL} }; -int CmdFlashMem(const char *Cmd) -{ +int CmdFlashMem(const char *Cmd) { clearCommandBuffer(); CmdsParse(CommandTable, Cmd); return 0; } -int CmdHelp(const char *Cmd) -{ +int CmdHelp(const char *Cmd) { CmdsHelp(CommandTable); return 0; } diff --git a/client/cmdhf.c b/client/cmdhf.c index a076d4e6d..294dc4be9 100644 --- a/client/cmdhf.c +++ b/client/cmdhf.c @@ -12,8 +12,7 @@ static int CmdHelp(const char *Cmd); -int usage_hf_search() -{ +int usage_hf_search() { PrintAndLogEx(NORMAL, "Usage: hf search"); PrintAndLogEx(NORMAL, "Will try to find a HF read out of the unknown tag. Stops when found."); PrintAndLogEx(NORMAL, "Options:"); @@ -21,8 +20,7 @@ int usage_hf_search() PrintAndLogEx(NORMAL, ""); return 0; } -int usage_hf_snoop() -{ +int usage_hf_snoop() { PrintAndLogEx(NORMAL, "Usage: hf snoop "); PrintAndLogEx(NORMAL, "The high frequence snoop will assign all available memory on device for snooped data"); PrintAndLogEx(NORMAL, "User the 'data samples' command to download from device, and 'data plot' to look at it"); @@ -38,8 +36,7 @@ int usage_hf_snoop() return 0; } -int CmdHFSearch(const char *Cmd) -{ +int CmdHFSearch(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_hf_search(); @@ -88,8 +85,7 @@ int CmdHFSearch(const char *Cmd) return 0; } -int CmdHFTune(const char *Cmd) -{ +int CmdHFTune(const char *Cmd) { PrintAndLogEx(SUCCESS, "Measuring HF antenna, press button to exit"); UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING_HF}; clearCommandBuffer(); @@ -97,8 +93,7 @@ int CmdHFTune(const char *Cmd) return 0; } -int CmdHFSnoop(const char *Cmd) -{ +int CmdHFSnoop(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_hf_snoop(); @@ -133,15 +128,13 @@ static command_t CommandTable[] = { {NULL, NULL, 0, NULL} }; -int CmdHF(const char *Cmd) -{ +int CmdHF(const char *Cmd) { clearCommandBuffer(); CmdsParse(CommandTable, Cmd); return 0; } -int CmdHelp(const char *Cmd) -{ +int CmdHelp(const char *Cmd) { CmdsHelp(CommandTable); return 0; } diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index 89e88232b..6d4b39e4e 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -136,8 +136,7 @@ static const manufactureName manufactureMapping[] = { // get a product description based on the UID // uid[8] tag uid // returns description of the best match -char *getTagInfo(uint8_t uid) -{ +char *getTagInfo(uint8_t uid) { int i; int len = sizeof(manufactureMapping) / sizeof(manufactureName); @@ -154,8 +153,7 @@ char *getTagInfo(uint8_t uid) static uint16_t frameLength = 0; uint16_t atsFSC[] = {16, 24, 32, 40, 48, 64, 96, 128, 256}; -int usage_hf_14a_sim(void) -{ +int usage_hf_14a_sim(void) { // PrintAndLogEx(NORMAL, "\n Emulating ISO/IEC 14443 type A tag with 4,7 or 10 byte UID\n"); PrintAndLogEx(NORMAL, "\n Emulating ISO/IEC 14443 type A tag with 4,7 byte UID\n"); PrintAndLogEx(NORMAL, "Usage: hf 14a sim [h] t u [x] [e] [v]"); @@ -182,8 +180,7 @@ int usage_hf_14a_sim(void) // PrintAndLogEx(NORMAL, " hf 14a sim t 1 u 11223445566778899AA\n"); return 0; } -int usage_hf_14a_sniff(void) -{ +int usage_hf_14a_sniff(void) { PrintAndLogEx(NORMAL, "It get data from the field and saves it into command buffer."); PrintAndLogEx(NORMAL, "Buffer accessible from command 'hf list 14a'"); PrintAndLogEx(NORMAL, "Usage: hf 14a sniff [c][r]"); @@ -193,8 +190,7 @@ int usage_hf_14a_sniff(void) PrintAndLogEx(NORMAL, " hf 14a sniff c r"); return 0; } -int usage_hf_14a_raw(void) -{ +int usage_hf_14a_raw(void) { PrintAndLogEx(NORMAL, "Usage: hf 14a raw [-h] [-r] [-c] [-p] [-a] [-T] [-t] [-b] <0A 0B 0C ... hex>"); PrintAndLogEx(NORMAL, " -h this help"); PrintAndLogEx(NORMAL, " -r do not read response"); @@ -208,8 +204,7 @@ int usage_hf_14a_raw(void) PrintAndLogEx(NORMAL, " -3 ISO14443-3 select only (skip RATS)"); return 0; } -int usage_hf_14a_reader(void) -{ +int usage_hf_14a_reader(void) { PrintAndLogEx(NORMAL, "Usage: hf 14a reader [k|s|x] [3]"); PrintAndLogEx(NORMAL, " k keep the field active after command executed"); PrintAndLogEx(NORMAL, " s silent (no messages)"); @@ -217,8 +212,7 @@ int usage_hf_14a_reader(void) PrintAndLogEx(NORMAL, " 3 ISO14443-3 select only (skip RATS)"); return 0; } -int usage_hf_14a_info(void) -{ +int usage_hf_14a_info(void) { PrintAndLogEx(NORMAL, "This command makes more extensive tests against a ISO14443a tag in order to collect information"); PrintAndLogEx(NORMAL, "Usage: hf 14a info [h|s]"); PrintAndLogEx(NORMAL, " s silent (no messages)"); @@ -226,15 +220,13 @@ int usage_hf_14a_info(void) return 0; } -int CmdHF14AList(const char *Cmd) -{ +int CmdHF14AList(const char *Cmd) { //PrintAndLogEx(NORMAL, "Deprecated command, use 'hf list 14a' instead"); CmdTraceList("14a"); return 0; } -int Hf14443_4aGetCardData(iso14a_card_select_t *card) -{ +int Hf14443_4aGetCardData(iso14a_card_select_t *card) { UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}}; SendCommand(&c); @@ -273,8 +265,7 @@ int Hf14443_4aGetCardData(iso14a_card_select_t *card) return 0; } -int CmdHF14AReader(const char *Cmd) -{ +int CmdHF14AReader(const char *Cmd) { uint32_t cm = ISO14A_CONNECT; bool disconnectAfter = true, silent = false; @@ -362,8 +353,7 @@ int CmdHF14AReader(const char *Cmd) return 0; } -int CmdHF14AInfo(const char *Cmd) -{ +int CmdHF14AInfo(const char *Cmd) { if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_hf_14a_info(); @@ -665,8 +655,7 @@ int CmdHF14AInfo(const char *Cmd) } // Collect ISO14443 Type A UIDs -int CmdHF14ACUIDs(const char *Cmd) -{ +int CmdHF14ACUIDs(const char *Cmd) { // requested number of UIDs int n = atoi(Cmd); // collect at least 1 (e.g. if no parameter was given) @@ -710,8 +699,7 @@ int CmdHF14ACUIDs(const char *Cmd) } // ## simulate iso14443a tag -int CmdHF14ASim(const char *Cmd) -{ +int CmdHF14ASim(const char *Cmd) { bool errors = false; uint8_t flags = 0; uint8_t tagtype = 1; @@ -806,8 +794,7 @@ int CmdHF14ASim(const char *Cmd) return 0; } -int CmdHF14ASniff(const char *Cmd) -{ +int CmdHF14ASniff(const char *Cmd) { int param = 0; uint8_t ctmp; for (int i = 0; i < 2; i++) { @@ -822,8 +809,7 @@ int CmdHF14ASniff(const char *Cmd) return 0; } -int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) -{ +int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) { static bool responseNum = false; uint16_t cmdc = 0; *dataoutlen = 0; @@ -922,8 +908,7 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav return 0; } -int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) -{ +int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) { UsbCommand resp; frameLength = 0; @@ -993,8 +978,7 @@ int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) return 0; } -int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool activateField, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, bool *chainingout) -{ +int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool activateField, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, bool *chainingout) { *chainingout = false; if (activateField) { @@ -1078,15 +1062,14 @@ int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool activa return 0; } -int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) -{ +int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) { *dataoutlen = 0; bool chaining = false; int res; // 3 byte here - 1b framing header, 2b crc16 if (APDUInFramingEnable && - ((frameLength && (datainlen > frameLength - 3)) || (datainlen > USB_CMD_DATA_SIZE - 3))) { + ((frameLength && (datainlen > frameLength - 3)) || (datainlen > USB_CMD_DATA_SIZE - 3))) { int clen = 0; bool vActivateField = activateField; @@ -1149,8 +1132,7 @@ int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool lea } // ISO14443-4. 7. Half-duplex block transmission protocol -int CmdHF14AAPDU(const char *cmd) -{ +int CmdHF14AAPDU(const char *cmd) { uint8_t data[USB_CMD_DATA_SIZE]; int datalen = 0; bool activateField = false; @@ -1197,8 +1179,7 @@ int CmdHF14AAPDU(const char *cmd) return 0; } -int CmdHF14ACmdRaw(const char *cmd) -{ +int CmdHF14ACmdRaw(const char *cmd) { UsbCommand c = {CMD_READER_ISO_14443a, {0, 0, 0}}; bool reply = 1; bool crc = false; @@ -1271,8 +1252,8 @@ int CmdHF14ACmdRaw(const char *cmd) continue; } if ((cmd[i] >= '0' && cmd[i] <= '9') || - (cmd[i] >= 'a' && cmd[i] <= 'f') || - (cmd[i] >= 'A' && cmd[i] <= 'F')) { + (cmd[i] >= 'a' && cmd[i] <= 'f') || + (cmd[i] >= 'A' && cmd[i] <= 'F')) { buf[strlen(buf) + 1] = 0; buf[strlen(buf)] = cmd[i]; i++; @@ -1354,8 +1335,7 @@ int CmdHF14ACmdRaw(const char *cmd) return 0; } -static int waitCmd(uint8_t iSelect) -{ +static int waitCmd(uint8_t iSelect) { UsbCommand resp; uint16_t len = 0; @@ -1383,8 +1363,7 @@ static int waitCmd(uint8_t iSelect) return 0; } -int CmdHF14AAntiFuzz(const char *cmd) -{ +int CmdHF14AAntiFuzz(const char *cmd) { CLIParserInit("hf 14a antifuzz", "Tries to fuzz the ISO14443a anticollision phase", @@ -1413,8 +1392,7 @@ int CmdHF14AAntiFuzz(const char *cmd) return 0; } -int CmdHF14AChaining(const char *cmd) -{ +int CmdHF14AChaining(const char *cmd) { CLIParserInit("hf 14a chaining", "Enable/Disable ISO14443a input chaining. Maximum input length goes from ATS.", @@ -1460,15 +1438,13 @@ static command_t CommandTable[] = { {NULL, NULL, 0, NULL} }; -int CmdHF14A(const char *Cmd) -{ +int CmdHF14A(const char *Cmd) { clearCommandBuffer(); CmdsParse(CommandTable, Cmd); return 0; } -int CmdHelp(const char *Cmd) -{ +int CmdHelp(const char *Cmd) { CmdsHelp(CommandTable); return 0; } diff --git a/client/cmdhf14b.c b/client/cmdhf14b.c index 0bff7a32d..564b18012 100644 --- a/client/cmdhf14b.c +++ b/client/cmdhf14b.c @@ -14,8 +14,7 @@ #define TIMEOUT 2000 static int CmdHelp(const char *Cmd); -int usage_hf_14b_info(void) -{ +int usage_hf_14b_info(void) { PrintAndLogEx(NORMAL, "Usage: hf 14b info [h] [s]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); @@ -24,8 +23,7 @@ int usage_hf_14b_info(void) PrintAndLogEx(NORMAL, " hf 14b info"); return 0; } -int usage_hf_14b_reader(void) -{ +int usage_hf_14b_reader(void) { PrintAndLogEx(NORMAL, "Usage: hf 14b reader [h] [s]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); @@ -34,8 +32,7 @@ int usage_hf_14b_reader(void) PrintAndLogEx(NORMAL, " hf 14b reader"); return 0; } -int usage_hf_14b_raw(void) -{ +int usage_hf_14b_raw(void) { PrintAndLogEx(NORMAL, "Usage: hf 14b raw [-h] [-r] [-c] [-p] [-s || -ss] <0A 0B 0C ... hex>"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " -h this help"); @@ -48,8 +45,7 @@ int usage_hf_14b_raw(void) PrintAndLogEx(NORMAL, " hf 14b raw -s -c -p 0200a40400"); return 0; } -int usage_hf_14b_sniff(void) -{ +int usage_hf_14b_sniff(void) { PrintAndLogEx(NORMAL, "It get data from the field and saves it into command buffer."); PrintAndLogEx(NORMAL, "Buffer accessible from command 'hf list 14b'"); PrintAndLogEx(NORMAL, "Usage: hf 14b sniff [h]"); @@ -59,8 +55,7 @@ int usage_hf_14b_sniff(void) PrintAndLogEx(NORMAL, " hf 14b sniff"); return 0; } -int usage_hf_14b_sim(void) -{ +int usage_hf_14b_sim(void) { PrintAndLogEx(NORMAL, "Emulating ISO/IEC 14443 type B tag with 4 UID / PUPI"); PrintAndLogEx(NORMAL, "Usage: hf 14b sim [h] u "); PrintAndLogEx(NORMAL, "Options:"); @@ -71,8 +66,7 @@ int usage_hf_14b_sim(void) PrintAndLogEx(NORMAL, " hf 14b sim u 11223344"); return 0; } -int usage_hf_14b_read_srx(void) -{ +int usage_hf_14b_read_srx(void) { PrintAndLogEx(NORMAL, "Usage: hf 14b sriread [h] <1|2>"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); @@ -82,8 +76,7 @@ int usage_hf_14b_read_srx(void) PrintAndLogEx(NORMAL, " hf 14b sriread 2"); return 0; } -int usage_hf_14b_write_srx(void) -{ +int usage_hf_14b_write_srx(void) { PrintAndLogEx(NORMAL, "Usage: hf 14b [h] sriwrite <1|2> "); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); @@ -97,8 +90,7 @@ int usage_hf_14b_write_srx(void) PrintAndLogEx(NORMAL, " hf 14b sriwrite 2 FF 11223344"); return 0; } -int usage_hf_14b_dump(void) -{ +int usage_hf_14b_dump(void) { PrintAndLogEx(NORMAL, "This command dumps the contents of a ISO-14443-B tag and save it to file\n" "\n" "Usage: hf 14b dump [h] [card memory] \n" @@ -121,22 +113,19 @@ static void switch_on_field_14b(void) { } */ -static int switch_off_field_14b(void) -{ +static int switch_off_field_14b(void) { UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_DISCONNECT, 0, 0}}; clearCommandBuffer(); SendCommand(&c); return 0; } -int CmdHF14BList(const char *Cmd) -{ +int CmdHF14BList(const char *Cmd) { CmdTraceList("14b"); return 0; } -int CmdHF14BSim(const char *Cmd) -{ +int CmdHF14BSim(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_hf_14b_sim(); @@ -151,8 +140,7 @@ int CmdHF14BSim(const char *Cmd) return 0; } -int CmdHF14BSniff(const char *Cmd) -{ +int CmdHF14BSniff(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_hf_14b_sniff(); @@ -163,8 +151,7 @@ int CmdHF14BSniff(const char *Cmd) return 0; } -int CmdHF14BCmdRaw(const char *Cmd) -{ +int CmdHF14BCmdRaw(const char *Cmd) { bool reply = true, power = false, select = false; char buf[5] = ""; int i = 0; @@ -209,8 +196,8 @@ int CmdHF14BCmdRaw(const char *Cmd) continue; } if ((Cmd[i] >= '0' && Cmd[i] <= '9') || - (Cmd[i] >= 'a' && Cmd[i] <= 'f') || - (Cmd[i] >= 'A' && Cmd[i] <= 'F')) { + (Cmd[i] >= 'a' && Cmd[i] <= 'f') || + (Cmd[i] >= 'A' && Cmd[i] <= 'F')) { buf[strlen(buf) + 1] = 0; buf[strlen(buf)] = Cmd[i]; i++; @@ -254,8 +241,7 @@ int CmdHF14BCmdRaw(const char *Cmd) return 1; } -static bool get_14b_UID(iso14b_card_select_t *card) -{ +static bool get_14b_UID(iso14b_card_select_t *card) { if (!card) return false; @@ -309,8 +295,7 @@ static bool get_14b_UID(iso14b_card_select_t *card) // 4 = bit rate capacity // 5 = max frame size / -4 info // 6 = FWI / Coding options -static void print_atqb_resp(uint8_t *data, uint8_t cid) -{ +static void print_atqb_resp(uint8_t *data, uint8_t cid) { //PrintAndLogEx(NORMAL, " UID: %s", sprint_hex(data+1,4)); PrintAndLogEx(NORMAL, " App Data: %s", sprint_hex(data, 4)); PrintAndLogEx(NORMAL, " Protocol: %s", sprint_hex(data + 4, 3)); @@ -356,8 +341,7 @@ static void print_atqb_resp(uint8_t *data, uint8_t cid) } // get SRx chip model (from UID) // from ST Microelectronics -char *get_ST_Chip_Model(uint8_t data) -{ +char *get_ST_Chip_Model(uint8_t data) { static char model[20]; char *retStr = model; memset(model, 0, sizeof(model)); @@ -392,8 +376,7 @@ char *get_ST_Chip_Model(uint8_t data) } // REMAKE: -int print_ST_Lock_info(uint8_t model) -{ +int print_ST_Lock_info(uint8_t model) { // PrintAndLogEx(NORMAL, "Chip Write Protection Bits:"); // // now interpret the data @@ -439,8 +422,7 @@ int print_ST_Lock_info(uint8_t model) } // print UID info from SRx chips (ST Microelectronics) -static void print_st_general_info(uint8_t *data, uint8_t len) -{ +static void print_st_general_info(uint8_t *data, uint8_t len) { //uid = first 8 bytes in data PrintAndLogEx(NORMAL, " UID: %s", sprint_hex(SwapEndian64(data, 8, 8), len)); PrintAndLogEx(NORMAL, " MFG: %02X, %s", data[6], getTagInfo(data[6])); @@ -467,8 +449,7 @@ static void print_st_general_info(uint8_t *data, uint8_t len) //a2 = ? (resp 02 [6a d3]) // 14b get and print Full Info (as much as we know) -bool HF14B_Std_Info(bool verbose) -{ +bool HF14B_Std_Info(bool verbose) { bool isSuccess = false; @@ -512,8 +493,7 @@ bool HF14B_Std_Info(bool verbose) } // SRx get and print full info (needs more info...) -bool HF14B_ST_Info(bool verbose) -{ +bool HF14B_ST_Info(bool verbose) { UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_CONNECT | ISO14B_SELECT_SR | ISO14B_DISCONNECT, 0, 0}}; clearCommandBuffer(); @@ -559,8 +539,7 @@ bool HF14B_ST_Info(bool verbose) } // get and print all info known about any known 14b tag -bool HF14BInfo(bool verbose) -{ +bool HF14BInfo(bool verbose) { // try std 14b (atqb) if (HF14B_Std_Info(verbose)) return true; @@ -575,8 +554,7 @@ bool HF14BInfo(bool verbose) } // menu command to get and print all info known about any known 14b tag -int CmdHF14Binfo(const char *Cmd) -{ +int CmdHF14Binfo(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_hf_14b_info(); @@ -584,8 +562,7 @@ int CmdHF14Binfo(const char *Cmd) return HF14BInfo(verbose); } -bool HF14B_ST_Reader(bool verbose) -{ +bool HF14B_ST_Reader(bool verbose) { bool isSuccess = false; @@ -625,8 +602,7 @@ bool HF14B_ST_Reader(bool verbose) return isSuccess; } -bool HF14B_Std_Reader(bool verbose) -{ +bool HF14B_Std_Reader(bool verbose) { bool isSuccess = false; @@ -668,8 +644,7 @@ bool HF14B_Std_Reader(bool verbose) } // test for other 14b type tags (mimic another reader - don't have tags to identify) -bool HF14B_Other_Reader() -{ +bool HF14B_Other_Reader() { // uint8_t data[] = {0x00, 0x0b, 0x3f, 0x80}; // uint8_t datalen = 4; @@ -728,8 +703,7 @@ bool HF14B_Other_Reader() } // get and print general info about all known 14b chips -bool HF14BReader(bool verbose) -{ +bool HF14BReader(bool verbose) { // try std 14b (atqb) if (HF14B_Std_Reader(verbose)) return true; @@ -746,8 +720,7 @@ bool HF14BReader(bool verbose) } // menu command to get and print general info about all known 14b chips -int CmdHF14BReader(const char *Cmd) -{ +int CmdHF14BReader(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_hf_14b_reader(); @@ -759,8 +732,7 @@ int CmdHF14BReader(const char *Cmd) * SRI* tags are ISO14443-B modulated memory tags, * this command just dumps the contents of the memory/ */ -int CmdHF14BReadSri(const char *Cmd) -{ +int CmdHF14BReadSri(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) < 1 || cmdp == 'h') return usage_hf_14b_read_srx(); @@ -773,8 +745,7 @@ int CmdHF14BReadSri(const char *Cmd) return 0; } // New command to write a SRI512/SRIX4K tag. -int CmdHF14BWriteSri(const char *Cmd) -{ +int CmdHF14BWriteSri(const char *Cmd) { /* * For SRIX4K blocks 00 - 7F * hf 14b raw -c -p 09 $srix4kwblock $srix4kwdata @@ -841,8 +812,7 @@ int CmdHF14BWriteSri(const char *Cmd) } // need to write to file -int CmdHF14BDump(const char *Cmd) -{ +int CmdHF14BDump(const char *Cmd) { uint8_t fileNameLen = 0; char filename[FILE_PATH_SIZE] = {0}; @@ -998,8 +968,7 @@ out: return switch_off_field_14b(); } -uint32_t srix4kEncode(uint32_t value) -{ +uint32_t srix4kEncode(uint32_t value) { /* // vv = value // pp = position @@ -1055,8 +1024,7 @@ uint32_t srix4kEncode(uint32_t value) PrintAndLogEx(NORMAL, "ICE encoded | %08X -> %08X", value, encvalue); return encvalue; } -uint32_t srix4kDecode(uint32_t value) -{ +uint32_t srix4kDecode(uint32_t value) { switch (value) { case 0xC04F42C5: return 0x003139; @@ -1067,15 +1035,13 @@ uint32_t srix4kDecode(uint32_t value) } return 0; } -uint32_t srix4kDecodeCounter(uint32_t num) -{ +uint32_t srix4kDecodeCounter(uint32_t num) { uint32_t value = ~num; ++value; return value; } -uint32_t srix4kGetMagicbytes(uint64_t uid, uint32_t block6, uint32_t block18, uint32_t block19) -{ +uint32_t srix4kGetMagicbytes(uint64_t uid, uint32_t block6, uint32_t block18, uint32_t block19) { #define MASK 0xFFFFFFFF; uint32_t uid32 = uid & MASK; uint32_t counter = srix4kDecodeCounter(block6); @@ -1087,8 +1053,7 @@ uint32_t srix4kGetMagicbytes(uint64_t uid, uint32_t block6, uint32_t block18, ui PrintAndLogEx(SUCCESS, "Magic bytes | %08X", result); return result; } -int srix4kValid(const char *Cmd) -{ +int srix4kValid(const char *Cmd) { uint64_t uid = 0xD00202501A4532F9; uint32_t block6 = 0xFFFFFFFF; @@ -1106,8 +1071,7 @@ int srix4kValid(const char *Cmd) return 0; } -bool waitCmd14b(bool verbose) -{ +bool waitCmd14b(bool verbose) { bool crc = false; uint8_t data[USB_CMD_DATA_SIZE] = {0x00}; @@ -1161,15 +1125,13 @@ static command_t CommandTable[] = { {NULL, NULL, 0, NULL} }; -int CmdHF14B(const char *Cmd) -{ +int CmdHF14B(const char *Cmd) { clearCommandBuffer(); CmdsParse(CommandTable, Cmd); return 0; } -int CmdHelp(const char *Cmd) -{ +int CmdHelp(const char *Cmd) { CmdsHelp(CommandTable); return 0; } diff --git a/client/cmdhf15.c b/client/cmdhf15.c index 193290297..2e784962c 100644 --- a/client/cmdhf15.c +++ b/client/cmdhf15.c @@ -189,8 +189,7 @@ const productName uidmapping[] = { // fast method to just read the UID of a tag (collission detection not supported) // *buf should be large enough to fit the 64bit uid // returns 1 if suceeded -int getUID(uint8_t *buf) -{ +int getUID(uint8_t *buf) { UsbCommand resp; UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv? @@ -229,8 +228,7 @@ int getUID(uint8_t *buf) // get a product description based on the UID // uid[8] tag uid // returns description of the best match -static char *getTagInfo_15(uint8_t *uid) -{ +static char *getTagInfo_15(uint8_t *uid) { uint64_t myuid, mask; int i = 0, best = -1; memcpy(&myuid, uid, sizeof(uint64_t)); @@ -254,8 +252,7 @@ static char *getTagInfo_15(uint8_t *uid) } // return a clear-text message to an errorcode -static char *TagErrorStr(uint8_t error) -{ +static char *TagErrorStr(uint8_t error) { switch (error) { case 0x01: return "The command is not supported"; @@ -280,20 +277,17 @@ static char *TagErrorStr(uint8_t error) } } -int usage_15_demod(void) -{ +int usage_15_demod(void) { PrintAndLogEx(NORMAL, "Tries to demodulate / decode ISO15693, from downloaded samples.\n" "Gather samples with 'hf 15 read' / 'hf 15 record'"); return 0; } -int usage_15_samples(void) -{ +int usage_15_samples(void) { PrintAndLogEx(NORMAL, "Acquire samples as Reader (enables carrier, send inquiry\n" "and download it to graphbuffer. Try 'hf 15 demod' to try to demodulate/decode signal"); return 0; } -int usage_15_info(void) -{ +int usage_15_info(void) { PrintAndLogEx(NORMAL, "Uses the optional command 'get_systeminfo' 0x2B to try and extract information\n" "command may fail, depending on tag.\n" "defaults to '1 out of 4' mode\n" @@ -309,13 +303,11 @@ int usage_15_info(void) "\thf 15 info u"); return 0; } -int usage_15_record(void) -{ +int usage_15_record(void) { PrintAndLogEx(NORMAL, "Record activity without enableing carrier"); return 0; } -int usage_15_reader(void) -{ +int usage_15_reader(void) { PrintAndLogEx(NORMAL, "This command identifies a ISO 15693 tag\n" "\n" "Usage: hf 15 reader [h]\n" @@ -326,21 +318,18 @@ int usage_15_reader(void) "\thf 15 reader"); return 0; } -int usage_15_sim(void) -{ +int usage_15_sim(void) { PrintAndLogEx(NORMAL, "Usage: hf 15 sim \n" "\n" "Example:\n" "\thf 15 sim E016240000000000"); return 0; } -int usage_15_findafi(void) -{ +int usage_15_findafi(void) { PrintAndLogEx(NORMAL, "'hf 15 finafi' This command needs a helptext. Feel free to add one!"); return 0; } -int usage_15_dump(void) -{ +int usage_15_dump(void) { PrintAndLogEx(NORMAL, "This command dumps the contents of a ISO-15693 tag and save it to file\n" "\n" "Usage: hf 15 dump [h] \n" @@ -353,8 +342,7 @@ int usage_15_dump(void) "\thf 15 dump f mydump"); return 0; } -int usage_15_restore(void) -{ +int usage_15_restore(void) { char *options[][2] = { {"h", "this help"}, {"-2", "use slower '1 out of 256' mode"}, @@ -368,8 +356,7 @@ int usage_15_restore(void) PrintAndLogOptions(options, 7, 3); return 0; } -int usage_15_raw(void) -{ +int usage_15_raw(void) { char *options[][2] = { {"-r", "do not read response" }, {"-2", "use slower '1 out of 256' mode" }, @@ -380,8 +367,7 @@ int usage_15_raw(void) PrintAndLogOptions(options, 4, 3); return 0; } -int usage_15_read(void) -{ +int usage_15_read(void) { PrintAndLogEx(NORMAL, "Usage: hf 15 read [options] \n" "Options:\n" "\t-2 use slower '1 out of 256' mode\n" @@ -392,8 +378,7 @@ int usage_15_read(void) "\tpage#: page number 0-255"); return 0; } -int usage_15_write(void) -{ +int usage_15_write(void) { PrintAndLogEx(NORMAL, "Usage: hf 15 write [options] \n" "Options:\n" "\t-2 use slower '1 out of 256' mode\n" @@ -406,8 +391,7 @@ int usage_15_write(void) "\thexdata: data to be written eg AA BB CC DD"); return 0; } -int usage_15_readmulti(void) -{ +int usage_15_readmulti(void) { PrintAndLogEx(NORMAL, "Usage: hf 15 readmulti [options] \n" "Options:\n" "\t-2 use slower '1 out of 256' mode\n" @@ -421,8 +405,7 @@ int usage_15_readmulti(void) } // Mode 3 //helptext -int CmdHF15Demod(const char *Cmd) -{ +int CmdHF15Demod(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_15_demod(); @@ -502,8 +485,7 @@ int CmdHF15Demod(const char *Cmd) // * Acquire Samples as Reader (enables carrier, sends inquiry) //helptext -int CmdHF15Samples(const char *Cmd) -{ +int CmdHF15Samples(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_15_samples(); @@ -519,8 +501,7 @@ int CmdHF15Samples(const char *Cmd) * Commandline handling: HF15 CMD SYSINFO * get system information from tag/VICC */ -int CmdHF15Info(const char *Cmd) -{ +int CmdHF15Info(const char *Cmd) { char cmdp = param_getchar(Cmd, 0); if (strlen(Cmd) < 1 || cmdp == 'h' || cmdp == 'H') return usage_15_info(); @@ -602,8 +583,7 @@ int CmdHF15Info(const char *Cmd) // Record Activity without enabeling carrier //helptext -int CmdHF15Record(const char *Cmd) -{ +int CmdHF15Record(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_15_record(); @@ -614,8 +594,7 @@ int CmdHF15Record(const char *Cmd) } // used with 'hf search' -int HF15Reader(const char *Cmd, bool verbose) -{ +int HF15Reader(const char *Cmd, bool verbose) { uint8_t uid[8] = {0, 0, 0, 0, 0, 0, 0, 0}; if (!getUID(uid)) { if (verbose) PrintAndLogEx(WARNING, "No tag found."); @@ -627,8 +606,7 @@ int HF15Reader(const char *Cmd, bool verbose) return 1; } -int CmdHF15Reader(const char *Cmd) -{ +int CmdHF15Reader(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_15_reader(); @@ -638,8 +616,7 @@ int CmdHF15Reader(const char *Cmd) // Simulation is still not working very good // helptext -int CmdHF15Sim(const char *Cmd) -{ +int CmdHF15Sim(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) < 1 || cmdp == 'h') return usage_15_sim(); @@ -661,8 +638,7 @@ int CmdHF15Sim(const char *Cmd) // finds the AFI (Application Family Idendifier) of a card, by trying all values // (There is no standard way of reading the AFI, allthough some tags support this) // helptext -int CmdHF15Afi(const char *Cmd) -{ +int CmdHF15Afi(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_15_findafi(); @@ -681,8 +657,7 @@ typedef struct { // Reads all memory pages // need to write to file -int CmdHF15Dump(const char *Cmd) -{ +int CmdHF15Dump(const char *Cmd) { uint8_t fileNameLen = 0; char filename[FILE_PATH_SIZE] = {0}; @@ -798,8 +773,7 @@ int CmdHF15Dump(const char *Cmd) return 0; } -int CmdHF15Restore(const char *Cmd) -{ +int CmdHF15Restore(const char *Cmd) { FILE *f; uint8_t uid[8] = {0x00}; @@ -911,15 +885,13 @@ int CmdHF15Restore(const char *Cmd) fclose(f); } -int CmdHF15List(const char *Cmd) -{ +int CmdHF15List(const char *Cmd) { //PrintAndLogEx(WARNING, "Deprecated command, use 'hf list 15' instead"); CmdTraceList("15"); return 0; } -int CmdHF15Raw(const char *Cmd) -{ +int CmdHF15Raw(const char *Cmd) { char cmdp = param_getchar(Cmd, 0); if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_raw(); @@ -958,8 +930,8 @@ int CmdHF15Raw(const char *Cmd) continue; } if ((Cmd[i] >= '0' && Cmd[i] <= '9') || - (Cmd[i] >= 'a' && Cmd[i] <= 'f') || - (Cmd[i] >= 'A' && Cmd[i] <= 'F')) { + (Cmd[i] >= 'a' && Cmd[i] <= 'f') || + (Cmd[i] >= 'A' && Cmd[i] <= 'F')) { buf[strlen(buf) + 1] = 0; buf[strlen(buf)] = Cmd[i]; i++; @@ -1006,8 +978,7 @@ int CmdHF15Raw(const char *Cmd) * Parameters: * **cmd command line */ -int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd) -{ +int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd) { int temp; uint8_t *req = c->d.asBytes; uint8_t uid[8] = {0x00}; @@ -1084,8 +1055,7 @@ int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd) * Commandline handling: HF15 CMD READMULTI * Read multiple blocks at once (not all tags support this) */ -int CmdHF15Readmulti(const char *Cmd) -{ +int CmdHF15Readmulti(const char *Cmd) { char cmdp = param_getchar(Cmd, 0); if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_readmulti(); @@ -1168,8 +1138,7 @@ int CmdHF15Readmulti(const char *Cmd) * Commandline handling: HF15 CMD READ * Reads a single Block */ -int CmdHF15Read(const char *Cmd) -{ +int CmdHF15Read(const char *Cmd) { char cmdp = param_getchar(Cmd, 0); if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_read(); @@ -1243,8 +1212,7 @@ int CmdHF15Read(const char *Cmd) * Commandline handling: HF15 CMD WRITE * Writes a single Block - might run into timeout, even when successful */ -int CmdHF15Write(const char *Cmd) -{ +int CmdHF15Write(const char *Cmd) { char cmdp = param_getchar(Cmd, 0); if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_write(); @@ -1338,15 +1306,13 @@ static command_t CommandTable15[] = { {NULL, NULL, 0, NULL} }; -int CmdHF15(const char *Cmd) -{ +int CmdHF15(const char *Cmd) { clearCommandBuffer(); CmdsParse(CommandTable15, Cmd); return 0; } -int CmdHF15Help(const char *Cmd) -{ +int CmdHF15Help(const char *Cmd) { CmdsHelp(CommandTable15); return 0; } \ No newline at end of file diff --git a/client/cmdhfepa.c b/client/cmdhfepa.c index 3c2299d7f..fce18f11b 100644 --- a/client/cmdhfepa.c +++ b/client/cmdhfepa.c @@ -12,8 +12,7 @@ static int CmdHelp(const char *Cmd); // Perform (part of) the PACE protocol -int CmdHFEPACollectPACENonces(const char *Cmd) -{ +int CmdHFEPACollectPACENonces(const char *Cmd) { // requested nonce size uint32_t m = 0; // requested number of Nonces @@ -60,8 +59,7 @@ int CmdHFEPACollectPACENonces(const char *Cmd) } // perform the PACE protocol by replaying APDUs -int CmdHFEPAPACEReplay(const char *Cmd) -{ +int CmdHFEPAPACEReplay(const char *Cmd) { // the 4 APDUs which are replayed + their lengths uint8_t msesa_apdu[41], gn_apdu[8], map_apdu[75]; uint8_t pka_apdu[75], ma_apdu[18], apdu_lengths[5] = {0}; @@ -169,14 +167,12 @@ static command_t CommandTable[] = { {NULL, NULL, 0, NULL} }; -int CmdHelp(const char *Cmd) -{ +int CmdHelp(const char *Cmd) { CmdsHelp(CommandTable); return 0; } -int CmdHFEPA(const char *Cmd) -{ +int CmdHFEPA(const char *Cmd) { clearCommandBuffer(); CmdsParse(CommandTable, Cmd); return 0; diff --git a/client/cmdhffelica.c b/client/cmdhffelica.c index 06da1b8b4..59ddc5d65 100644 --- a/client/cmdhffelica.c +++ b/client/cmdhffelica.c @@ -11,8 +11,7 @@ static int CmdHelp(const char *Cmd); -int usage_hf_felica_sim(void) -{ +int usage_hf_felica_sim(void) { PrintAndLogEx(NORMAL, "\n Emulating ISO/18092 FeliCa tag \n"); PrintAndLogEx(NORMAL, "Usage: hf felica sim [h] t [v]"); PrintAndLogEx(NORMAL, "Options:"); @@ -24,8 +23,7 @@ int usage_hf_felica_sim(void) PrintAndLogEx(NORMAL, " hf felica sim t 1 "); return 0; } -int usage_hf_felica_sniff(void) -{ +int usage_hf_felica_sniff(void) { PrintAndLogEx(NORMAL, "It get data from the field and saves it into command buffer."); PrintAndLogEx(NORMAL, "Buffer accessible from command 'hf list felica'"); PrintAndLogEx(NORMAL, "Usage: hf felica sniff "); @@ -35,8 +33,7 @@ int usage_hf_felica_sniff(void) PrintAndLogEx(NORMAL, " hf felica sniff s 1000"); return 0; } -int usage_hf_felica_simlite(void) -{ +int usage_hf_felica_simlite(void) { PrintAndLogEx(NORMAL, "\n Emulating ISO/18092 FeliCa Lite tag \n"); PrintAndLogEx(NORMAL, "Usage: hf felica litesim [h] u "); PrintAndLogEx(NORMAL, "Options:"); @@ -46,8 +43,7 @@ int usage_hf_felica_simlite(void) PrintAndLogEx(NORMAL, " hf felica litesim 11223344556677"); return 0; } -int usage_hf_felica_dumplite(void) -{ +int usage_hf_felica_dumplite(void) { PrintAndLogEx(NORMAL, "\n Dump ISO/18092 FeliCa Lite tag \n"); PrintAndLogEx(NORMAL, "press button to abort run, otherwise it will loop for 200sec."); PrintAndLogEx(NORMAL, "Usage: hf felica litedump [h]"); @@ -57,8 +53,7 @@ int usage_hf_felica_dumplite(void) PrintAndLogEx(NORMAL, " hf felica litedump"); return 0; } -int usage_hf_felica_raw(void) -{ +int usage_hf_felica_raw(void) { PrintAndLogEx(NORMAL, "Usage: hf felica raw [-h] [-r] [-c] [-p] [-a] <0A 0B 0C ... hex>"); PrintAndLogEx(NORMAL, " -h this help"); PrintAndLogEx(NORMAL, " -r do not read response"); @@ -69,15 +64,13 @@ int usage_hf_felica_raw(void) return 0; } -int CmdHFFelicaList(const char *Cmd) -{ +int CmdHFFelicaList(const char *Cmd) { //PrintAndLogEx(NORMAL, "Deprecated command, use 'hf list felica' instead"); CmdTraceList("felica"); return 0; } -int CmdHFFelicaReader(const char *Cmd) -{ +int CmdHFFelicaReader(const char *Cmd) { bool silent = (Cmd[0] == 's' || Cmd[0] == 'S'); //UsbCommand cDisconnect = {CMD_FELICA_COMMAND, {0,0,0}}; UsbCommand c = {CMD_FELICA_COMMAND, {FELICA_CONNECT, 0, 0}}; @@ -129,8 +122,7 @@ int CmdHFFelicaReader(const char *Cmd) } // simulate iso18092 / FeliCa tag -int CmdHFFelicaSim(const char *Cmd) -{ +int CmdHFFelicaSim(const char *Cmd) { bool errors = false; uint8_t flags = 0; uint8_t tagtype = 1; @@ -195,8 +187,7 @@ int CmdHFFelicaSim(const char *Cmd) return 0; } -int CmdHFFelicaSniff(const char *Cmd) -{ +int CmdHFFelicaSniff(const char *Cmd) { uint8_t cmdp = 0; uint64_t samples2skip = 0; @@ -234,8 +225,7 @@ int CmdHFFelicaSniff(const char *Cmd) } // uid hex -int CmdHFFelicaSimLite(const char *Cmd) -{ +int CmdHFFelicaSimLite(const char *Cmd) { uint64_t uid = param_get64ex(Cmd, 0, 0, 16); @@ -248,13 +238,11 @@ int CmdHFFelicaSimLite(const char *Cmd) return 0; } -static void printSep() -{ +static void printSep() { PrintAndLogEx(NORMAL, "------------------------------------------------------------------------------------"); } -uint16_t PrintFliteBlock(uint16_t tracepos, uint8_t *trace, uint16_t tracelen) -{ +uint16_t PrintFliteBlock(uint16_t tracepos, uint8_t *trace, uint16_t tracelen) { if (tracepos + 19 >= tracelen) return tracelen; @@ -401,8 +389,7 @@ uint16_t PrintFliteBlock(uint16_t tracepos, uint8_t *trace, uint16_t tracelen) return tracepos + 19; } -int CmdHFFelicaDumpLite(const char *Cmd) -{ +int CmdHFFelicaDumpLite(const char *Cmd) { char ctmp = tolower(param_getchar(Cmd, 0)); if (ctmp == 'h') return usage_hf_felica_dumplite(); @@ -469,8 +456,7 @@ int CmdHFFelicaDumpLite(const char *Cmd) return 0; } -int CmdHFFelicaCmdRaw(const char *cmd) -{ +int CmdHFFelicaCmdRaw(const char *cmd) { UsbCommand c = {CMD_FELICA_COMMAND, {0, 0, 0}}; bool reply = 1; bool crc = false; @@ -525,8 +511,8 @@ int CmdHFFelicaCmdRaw(const char *cmd) continue; } if ((cmd[i] >= '0' && cmd[i] <= '9') || - (cmd[i] >= 'a' && cmd[i] <= 'f') || - (cmd[i] >= 'A' && cmd[i] <= 'F')) { + (cmd[i] >= 'a' && cmd[i] <= 'f') || + (cmd[i] >= 'A' && cmd[i] <= 'F')) { buf[strlen(buf) + 1] = 0; buf[strlen(buf)] = cmd[i]; i++; @@ -586,8 +572,7 @@ int CmdHFFelicaCmdRaw(const char *cmd) return 0; } -void waitCmdFelica(uint8_t iSelect) -{ +void waitCmdFelica(uint8_t iSelect) { UsbCommand resp; uint16_t len = 0; @@ -615,15 +600,13 @@ static command_t CommandTable[] = { {NULL, NULL, 0, NULL} }; -int CmdHFFelica(const char *Cmd) -{ +int CmdHFFelica(const char *Cmd) { clearCommandBuffer(); CmdsParse(CommandTable, Cmd); return 0; } -int CmdHelp(const char *Cmd) -{ +int CmdHelp(const char *Cmd) { CmdsHelp(CommandTable); return 0; } \ No newline at end of file diff --git a/client/cmdhffido.c b/client/cmdhffido.c index 80d2416d7..e099c35d0 100644 --- a/client/cmdhffido.c +++ b/client/cmdhffido.c @@ -49,8 +49,7 @@ static int CmdHelp(const char *Cmd); -int CmdHFFidoInfo(const char *cmd) -{ +int CmdHFFidoInfo(const char *cmd) { if (cmd && strlen(cmd) > 0) PrintAndLog("WARNING: command don't have any parameters.\n"); @@ -125,8 +124,7 @@ int CmdHFFidoInfo(const char *cmd) return 0; } -json_t *OpenJson(int paramnum, char *fname, void *argtable[], bool *err) -{ +json_t *OpenJson(int paramnum, char *fname, void *argtable[], bool *err) { json_t *root = NULL; json_error_t error; *err = false; @@ -170,8 +168,7 @@ json_t *OpenJson(int paramnum, char *fname, void *argtable[], bool *err) return root; } -int CmdHFFidoRegister(const char *cmd) -{ +int CmdHFFidoRegister(const char *cmd) { uint8_t data[64] = {0}; int chlen = 0; uint8_t cdata[250] = {0}; @@ -400,8 +397,7 @@ int CmdHFFidoRegister(const char *cmd) return 0; }; -int CmdHFFidoAuthenticate(const char *cmd) -{ +int CmdHFFidoAuthenticate(const char *cmd) { uint8_t data[512] = {0}; uint8_t hdata[250] = {0}; bool public_key_loaded = false; @@ -619,15 +615,13 @@ int CmdHFFidoAuthenticate(const char *cmd) return 0; }; -void CheckSlash(char *fileName) -{ +void CheckSlash(char *fileName) { if ((fileName[strlen(fileName) - 1] != '/') && - (fileName[strlen(fileName) - 1] != '\\')) + (fileName[strlen(fileName) - 1] != '\\')) strcat(fileName, "/"); } -int GetExistsFileNameJson(char *prefixDir, char *reqestedFileName, char *fileName) -{ +int GetExistsFileNameJson(char *prefixDir, char *reqestedFileName, char *fileName) { fileName[0] = 0x00; strcpy(fileName, get_my_executable_directory()); CheckSlash(fileName); @@ -654,8 +648,7 @@ int GetExistsFileNameJson(char *prefixDir, char *reqestedFileName, char *fileNam return 0; } -int CmdHFFido2MakeCredential(const char *cmd) -{ +int CmdHFFido2MakeCredential(const char *cmd) { json_error_t error; json_t *root = NULL; char fname[300] = {0}; @@ -782,8 +775,7 @@ int CmdHFFido2MakeCredential(const char *cmd) return 0; }; -int CmdHFFido2GetAssertion(const char *cmd) -{ +int CmdHFFido2GetAssertion(const char *cmd) { json_error_t error; json_t *root = NULL; char fname[300] = {0}; @@ -920,15 +912,13 @@ static command_t CommandTable[] = { {NULL, NULL, 0, NULL} }; -int CmdHFFido(const char *Cmd) -{ +int CmdHFFido(const char *Cmd) { (void)WaitForResponseTimeout(CMD_ACK, NULL, 100); CmdsParse(CommandTable, Cmd); return 0; } -int CmdHelp(const char *Cmd) -{ +int CmdHelp(const char *Cmd) { CmdsHelp(CommandTable); return 0; } diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index fa3fe9515..b71f2fd03 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -29,8 +29,7 @@ static uint8_t iClass_Key_Table[ICLASS_KEYS_MAX][8] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; -int usage_hf_iclass_sim(void) -{ +int usage_hf_iclass_sim(void) { PrintAndLogEx(NORMAL, "Usage: hf iclass sim