diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 223bd2155..2c16d8f56 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1569,7 +1569,7 @@ void __attribute__((noreturn)) AppMain(void) { reply_via_fpc = 1; UsbPacketReceived(rx, sizeof(rx)); } - usart_readcheck(rx, sizeof(rx)); + usart_readcheck(rx, sizeof(rx)); #endif // Press button for one second to enter a possible standalone mode diff --git a/client/cmdanalyse.c b/client/cmdanalyse.c index 7196134b1..2f669d7e5 100644 --- a/client/cmdanalyse.c +++ b/client/cmdanalyse.c @@ -528,67 +528,67 @@ static int CmdAnalyseA(const char *Cmd) { } PrintAndLogEx(NORMAL, "got ack. Status %d", resp.arg[0]); return 0; -/* - PrintAndLogEx(NORMAL, "-- " _BLUE_("its my message") "\n"); - PrintAndLogEx(NORMAL, "-- " _RED_("its my message") "\n"); - PrintAndLogEx(NORMAL, "-- " _YELLOW_("its my message") "\n"); - PrintAndLogEx(NORMAL, "-- " _GREEN_("its my message") "\n"); + /* + PrintAndLogEx(NORMAL, "-- " _BLUE_("its my message") "\n"); + PrintAndLogEx(NORMAL, "-- " _RED_("its my message") "\n"); + PrintAndLogEx(NORMAL, "-- " _YELLOW_("its my message") "\n"); + PrintAndLogEx(NORMAL, "-- " _GREEN_("its my message") "\n"); - //uint8_t syncBit = 99; - // The start bit is one ore more Sequence Y followed by a Sequence Z (... 11111111 00x11111). We need to distinguish from - // Sequence X followed by Sequence Y followed by Sequence Z (111100x1 11111111 00x11111) - // we therefore look for a ...xx1111 11111111 00x11111xxxxxx... pattern - // (12 '1's followed by 2 '0's, eventually followed by another '0', followed by 5 '1's) -# define SYNC_16BIT 0xB24D - uint32_t shiftReg = param_get32ex(Cmd, 0, 0xb24d, 16); - uint8_t bt = param_get8ex(Cmd, 1, 0xBB, 16); - uint8_t byte_offset = 99; - // reverse byte - uint8_t rev = reflect8(bt); - PrintAndLogEx(NORMAL, "input %02x | %02x \n", bt, rev); - // add byte to shift register - shiftReg = shiftReg << 8 | rev; + //uint8_t syncBit = 99; + // The start bit is one ore more Sequence Y followed by a Sequence Z (... 11111111 00x11111). We need to distinguish from + // Sequence X followed by Sequence Y followed by Sequence Z (111100x1 11111111 00x11111) + // we therefore look for a ...xx1111 11111111 00x11111xxxxxx... pattern + // (12 '1's followed by 2 '0's, eventually followed by another '0', followed by 5 '1's) + # define SYNC_16BIT 0xB24D + uint32_t shiftReg = param_get32ex(Cmd, 0, 0xb24d, 16); + uint8_t bt = param_get8ex(Cmd, 1, 0xBB, 16); + uint8_t byte_offset = 99; + // reverse byte + uint8_t rev = reflect8(bt); + PrintAndLogEx(NORMAL, "input %02x | %02x \n", bt, rev); + // add byte to shift register + shiftReg = shiftReg << 8 | rev; - PrintAndLogEx(NORMAL, "shiftreg after %08x | pattern %08x \n", shiftReg, SYNC_16BIT); + PrintAndLogEx(NORMAL, "shiftreg after %08x | pattern %08x \n", shiftReg, SYNC_16BIT); - uint8_t n0 = 0, n1 = 0; + uint8_t n0 = 0, n1 = 0; - n0 = (rev & (uint8_t)(~(0xFF >> (8 - 4)))) >> 4; - n1 = (n1 << 4) | (rev & (uint8_t)(~(0xFF << 4))); + n0 = (rev & (uint8_t)(~(0xFF >> (8 - 4)))) >> 4; + n1 = (n1 << 4) | (rev & (uint8_t)(~(0xFF << 4))); - PrintAndLogEx(NORMAL, "rev %02X | %02X %s | %02X %s |\n", rev, n0, pb(n0), n1, pb(n1)); -*/ + PrintAndLogEx(NORMAL, "rev %02X | %02X %s | %02X %s |\n", rev, n0, pb(n0), n1, pb(n1)); + */ /* hex(0xb24d shr 0) 0xB24D 0b1011001001001101 hex(0xb24d shr 1) 0x5926 hex(0xb24d shr 2) 0x2C93 */ -/* - for (int i = 0; i < 16; i++) { - PrintAndLogEx(NORMAL, " (shiftReg >> %d) & 0xFFFF == %08x ---", i, ((shiftReg >> i) & 0xFFFF)); + /* + for (int i = 0; i < 16; i++) { + PrintAndLogEx(NORMAL, " (shiftReg >> %d) & 0xFFFF == %08x ---", i, ((shiftReg >> i) & 0xFFFF)); - // kolla om SYNC_PATTERN finns. - if (((shiftReg >> 7) & 0xFFFF) == SYNC_16BIT) byte_offset = 7; - else if (((shiftReg >> 6) & 0xFFFF) == SYNC_16BIT) byte_offset = 6; - else if (((shiftReg >> 5) & 0xFFFF) == SYNC_16BIT) byte_offset = 5; - else if (((shiftReg >> 4) & 0xFFFF) == SYNC_16BIT) byte_offset = 4; - else if (((shiftReg >> 3) & 0xFFFF) == SYNC_16BIT) byte_offset = 3; - else if (((shiftReg >> 2) & 0xFFFF) == SYNC_16BIT) byte_offset = 2; - else if (((shiftReg >> 1) & 0xFFFF) == SYNC_16BIT) byte_offset = 1; - else if (((shiftReg >> 0) & 0xFFFF) == SYNC_16BIT) byte_offset = 0; + // kolla om SYNC_PATTERN finns. + if (((shiftReg >> 7) & 0xFFFF) == SYNC_16BIT) byte_offset = 7; + else if (((shiftReg >> 6) & 0xFFFF) == SYNC_16BIT) byte_offset = 6; + else if (((shiftReg >> 5) & 0xFFFF) == SYNC_16BIT) byte_offset = 5; + else if (((shiftReg >> 4) & 0xFFFF) == SYNC_16BIT) byte_offset = 4; + else if (((shiftReg >> 3) & 0xFFFF) == SYNC_16BIT) byte_offset = 3; + else if (((shiftReg >> 2) & 0xFFFF) == SYNC_16BIT) byte_offset = 2; + else if (((shiftReg >> 1) & 0xFFFF) == SYNC_16BIT) byte_offset = 1; + else if (((shiftReg >> 0) & 0xFFFF) == SYNC_16BIT) byte_offset = 0; - PrintAndLogEx(NORMAL, "Offset %u \n", byte_offset); - if (byte_offset != 99) - break; + PrintAndLogEx(NORMAL, "Offset %u \n", byte_offset); + if (byte_offset != 99) + break; - shiftReg >>= 1; - } + shiftReg >>= 1; + } - uint8_t p1 = (rev & (uint8_t)(~(0xFF << byte_offset))); - PrintAndLogEx(NORMAL, "Offset %u | leftovers %02x %s \n", byte_offset, p1, pb(p1)); + uint8_t p1 = (rev & (uint8_t)(~(0xFF << byte_offset))); + PrintAndLogEx(NORMAL, "Offset %u | leftovers %02x %s \n", byte_offset, p1, pb(p1)); -*/ + */ /* pm3 --> da hex2bin 4db2 0100110110110010 @@ -621,39 +621,39 @@ static int CmdAnalyseA(const char *Cmd) { */ // return 0; -/* - // 14443-A - uint8_t u14_c[] = {0x09, 0x78, 0x00, 0x92, 0x02, 0x54, 0x13, 0x02, 0x04, 0x2d, 0xe8 }; // atqs w crc - uint8_t u14_w[] = {0x09, 0x78, 0x00, 0x92, 0x02, 0x54, 0x13, 0x02, 0x04, 0x2d, 0xe7 }; // atqs w crc - PrintAndLogEx(FAILED, "14a check wrong crc | %s\n", (check_crc(CRC_14443_A, u14_w, sizeof(u14_w))) ? "YES" : "NO"); - PrintAndLogEx(SUCCESS, "14a check correct crc | %s\n", (check_crc(CRC_14443_A, u14_c, sizeof(u14_c))) ? "YES" : "NO"); + /* + // 14443-A + uint8_t u14_c[] = {0x09, 0x78, 0x00, 0x92, 0x02, 0x54, 0x13, 0x02, 0x04, 0x2d, 0xe8 }; // atqs w crc + uint8_t u14_w[] = {0x09, 0x78, 0x00, 0x92, 0x02, 0x54, 0x13, 0x02, 0x04, 0x2d, 0xe7 }; // atqs w crc + PrintAndLogEx(FAILED, "14a check wrong crc | %s\n", (check_crc(CRC_14443_A, u14_w, sizeof(u14_w))) ? "YES" : "NO"); + PrintAndLogEx(SUCCESS, "14a check correct crc | %s\n", (check_crc(CRC_14443_A, u14_c, sizeof(u14_c))) ? "YES" : "NO"); - // 14443-B - uint8_t u14b[] = {0x05, 0x00, 0x08, 0x39, 0x73}; - PrintAndLogEx(NORMAL, "14b check crc | %s\n", (check_crc(CRC_14443_B, u14b, sizeof(u14b))) ? "YES" : "NO"); + // 14443-B + uint8_t u14b[] = {0x05, 0x00, 0x08, 0x39, 0x73}; + PrintAndLogEx(NORMAL, "14b check crc | %s\n", (check_crc(CRC_14443_B, u14b, sizeof(u14b))) ? "YES" : "NO"); - // 15693 test - uint8_t u15_c[] = {0x05, 0x00, 0x08, 0x39, 0x73}; // correct - uint8_t u15_w[] = {0x05, 0x00, 0x08, 0x39, 0x72}; // wrong - PrintAndLogEx(FAILED, "15 check wrong crc | %s\n", (check_crc(CRC_15693, u15_w, sizeof(u15_w))) ? "YES" : "NO"); - PrintAndLogEx(SUCCESS, "15 check correct crc | %s\n", (check_crc(CRC_15693, u15_c, sizeof(u15_c))) ? "YES" : "NO"); + // 15693 test + uint8_t u15_c[] = {0x05, 0x00, 0x08, 0x39, 0x73}; // correct + uint8_t u15_w[] = {0x05, 0x00, 0x08, 0x39, 0x72}; // wrong + PrintAndLogEx(FAILED, "15 check wrong crc | %s\n", (check_crc(CRC_15693, u15_w, sizeof(u15_w))) ? "YES" : "NO"); + PrintAndLogEx(SUCCESS, "15 check correct crc | %s\n", (check_crc(CRC_15693, u15_c, sizeof(u15_c))) ? "YES" : "NO"); - // iCLASS test - wrong crc , swapped bytes. - uint8_t iclass_w[] = { 0x40, 0xe1, 0xe1, 0xff, 0xfe, 0x5f, 0x02, 0x3c, 0x01, 0x43}; - uint8_t iclass_c[] = { 0x40, 0xe1, 0xe1, 0xff, 0xfe, 0x5f, 0x02, 0x3c, 0x43, 0x01}; - PrintAndLogEx(FAILED, "iCLASS check wrong crc | %s\n", (check_crc(CRC_ICLASS, iclass_w, sizeof(iclass_w))) ? "YES" : "NO"); - PrintAndLogEx(SUCCESS, "iCLASS check correct crc | %s\n", (check_crc(CRC_ICLASS, iclass_c, sizeof(iclass_c))) ? "YES" : "NO"); + // iCLASS test - wrong crc , swapped bytes. + uint8_t iclass_w[] = { 0x40, 0xe1, 0xe1, 0xff, 0xfe, 0x5f, 0x02, 0x3c, 0x01, 0x43}; + uint8_t iclass_c[] = { 0x40, 0xe1, 0xe1, 0xff, 0xfe, 0x5f, 0x02, 0x3c, 0x43, 0x01}; + PrintAndLogEx(FAILED, "iCLASS check wrong crc | %s\n", (check_crc(CRC_ICLASS, iclass_w, sizeof(iclass_w))) ? "YES" : "NO"); + PrintAndLogEx(SUCCESS, "iCLASS check correct crc | %s\n", (check_crc(CRC_ICLASS, iclass_c, sizeof(iclass_c))) ? "YES" : "NO"); - // FeliCa test - uint8_t felica_w[] = {0x12, 0x01, 0x01, 0x2e, 0x3d, 0x17, 0x26, 0x47, 0x80, 0x95, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x01, 0x43, 0x00, 0xb3, 0x7e}; - uint8_t felica_c[] = {0x12, 0x01, 0x01, 0x2e, 0x3d, 0x17, 0x26, 0x47, 0x80, 0x95, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x01, 0x43, 0x00, 0xb3, 0x7f}; - PrintAndLogEx(FAILED, "FeliCa check wrong crc | %s\n", (check_crc(CRC_FELICA, felica_w, sizeof(felica_w))) ? "YES" : "NO"); - PrintAndLogEx(SUCCESS, "FeliCa check correct crc | %s\n", (check_crc(CRC_FELICA, felica_c, sizeof(felica_c))) ? "YES" : "NO"); + // FeliCa test + uint8_t felica_w[] = {0x12, 0x01, 0x01, 0x2e, 0x3d, 0x17, 0x26, 0x47, 0x80, 0x95, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x01, 0x43, 0x00, 0xb3, 0x7e}; + uint8_t felica_c[] = {0x12, 0x01, 0x01, 0x2e, 0x3d, 0x17, 0x26, 0x47, 0x80, 0x95, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x01, 0x43, 0x00, 0xb3, 0x7f}; + PrintAndLogEx(FAILED, "FeliCa check wrong crc | %s\n", (check_crc(CRC_FELICA, felica_w, sizeof(felica_w))) ? "YES" : "NO"); + PrintAndLogEx(SUCCESS, "FeliCa check correct crc | %s\n", (check_crc(CRC_FELICA, felica_c, sizeof(felica_c))) ? "YES" : "NO"); - PrintAndLogEx(NORMAL, "\n\n"); + PrintAndLogEx(NORMAL, "\n\n"); - return 0; - */ + return 0; + */ /* bool term = !isatty(STDIN_FILENO); if (!term) { @@ -697,37 +697,37 @@ static int CmdAnalyseA(const char *Cmd) { uid(3e172b29) nt(039b7bd2) ks(0c0e0f0505080800) nr(00000001) uid(3e172b29) nt(039b7bd2) ks(0e06090d03000b0f) nr(00000002) */ -/* - uint64_t *keylistA = NULL, *keylistB = NULL; - uint32_t keycountA = 0, keycountB = 0; -// uint64_t d1[] = {0x3e172b29, 0x039b7bd2, 0x0000001, 0, 0x0c0e0f0505080800}; -// uint64_t d2[] = {0x3e172b29, 0x039b7bd2, 0x0000002, 0, 0x0e06090d03000b0f}; - uint64_t d1[] = {0x6e442129, 0x8f699195, 0x0000001, 0, 0x090d0b0305020f02}; - uint64_t d2[] = {0x6e442129, 0x8f699195, 0x0000004, 0, 0x00040f0f0305030e}; + /* + uint64_t *keylistA = NULL, *keylistB = NULL; + uint32_t keycountA = 0, keycountB = 0; + // uint64_t d1[] = {0x3e172b29, 0x039b7bd2, 0x0000001, 0, 0x0c0e0f0505080800}; + // uint64_t d2[] = {0x3e172b29, 0x039b7bd2, 0x0000002, 0, 0x0e06090d03000b0f}; + uint64_t d1[] = {0x6e442129, 0x8f699195, 0x0000001, 0, 0x090d0b0305020f02}; + uint64_t d2[] = {0x6e442129, 0x8f699195, 0x0000004, 0, 0x00040f0f0305030e}; - keycountA = nonce2key(d1[0], d1[1], d1[2], 0, d1[3], d1[4], &keylistA); - keycountB = nonce2key(d2[0], d2[1], d2[2], 0, d2[3], d2[4], &keylistB); + keycountA = nonce2key(d1[0], d1[1], d1[2], 0, d1[3], d1[4], &keylistA); + keycountB = nonce2key(d2[0], d2[1], d2[2], 0, d2[3], d2[4], &keylistB); - switch (keycountA) { - case 0: - PrintAndLogEx(FAILED, "Key test A failed\n"); - break; - case 1: - PrintAndLogEx(SUCCESS, "KEY A | %012" PRIX64 " ", keylistA[0]); - break; - } - switch (keycountB) { - case 0: - PrintAndLogEx(FAILED, "Key test B failed\n"); - break; - case 1: - PrintAndLogEx(SUCCESS, "KEY B | %012" PRIX64 " ", keylistB[0]); - break; - } + switch (keycountA) { + case 0: + PrintAndLogEx(FAILED, "Key test A failed\n"); + break; + case 1: + PrintAndLogEx(SUCCESS, "KEY A | %012" PRIX64 " ", keylistA[0]); + break; + } + switch (keycountB) { + case 0: + PrintAndLogEx(FAILED, "Key test B failed\n"); + break; + case 1: + PrintAndLogEx(SUCCESS, "KEY B | %012" PRIX64 " ", keylistB[0]); + break; + } - free(keylistA); - free(keylistB); -*/ + free(keylistA); + free(keylistB); + */ // qsort(keylist, keycount, sizeof(*keylist), compare_uint64); // keycount = intersection(last_keylist, keylist); diff --git a/client/cmddata.c b/client/cmddata.c index 1a38fc00f..e8c33c70c 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -1314,11 +1314,11 @@ static int CmdRawDemod(const char *Cmd) { str_lower((char *)Cmd); - if (str_startswith(Cmd, "fs") || Cmd[0] == 'f' ) ans = CmdFSKrawdemod(Cmd+2); + if (str_startswith(Cmd, "fs") || Cmd[0] == 'f') ans = CmdFSKrawdemod(Cmd + 2); else if (str_startswith(Cmd, "ab")) ans = Cmdaskbiphdemod(Cmd + 2); else if (str_startswith(Cmd, "am")) ans = Cmdaskmandemod(Cmd + 2); else if (str_startswith(Cmd, "ar")) ans = Cmdaskrawdemod(Cmd + 2); - else if (str_startswith(Cmd, "nr") || Cmd[0] == 'n') ans = CmdNRZrawDemod(Cmd+2); + else if (str_startswith(Cmd, "nr") || Cmd[0] == 'n') ans = CmdNRZrawDemod(Cmd + 2); else if (str_startswith(Cmd, "p1") || Cmd[0] == 'p') ans = CmdPSK1rawDemod(Cmd + 2); else if (str_startswith(Cmd, "p2")) ans = CmdPSK2rawDemod(Cmd + 2); else PrintAndLogEx(WARNING, "Unknown modulation entered - see help ('h') for parameter structure"); diff --git a/client/cmdhflegic.c b/client/cmdhflegic.c index 238f81641..0da3daaaa 100644 --- a/client/cmdhflegic.c +++ b/client/cmdhflegic.c @@ -200,7 +200,7 @@ static int CmdLegicInfo(const char *Cmd) { crc = data[4]; uint32_t calc_crc = CRC8Legic(data, 4); - PrintAndLogEx(NORMAL, _YELLOW_("CDF: System Area") ); + PrintAndLogEx(NORMAL, _YELLOW_("CDF: System Area")); PrintAndLogEx(NORMAL, "------------------------------------------------------"); PrintAndLogEx(NORMAL, "MCD: %02x, MSN: %02x %02x %02x, MCC: %02x %s", data[0], @@ -304,7 +304,7 @@ static int CmdLegicInfo(const char *Cmd) { } } PrintAndLogEx(NORMAL, "------------------------------------------------------"); - + uint8_t segCrcBytes[8] = {0, 0, 0, 0, 0, 0, 0, 0}; uint32_t segCalcCRC = 0; uint32_t segCRC = 0; @@ -313,7 +313,7 @@ static int CmdLegicInfo(const char *Cmd) { if (dcf > 60000) goto out; - PrintAndLogEx(NORMAL, _YELLOW_("\nADF: User Area") ); + PrintAndLogEx(NORMAL, _YELLOW_("\nADF: User Area")); PrintAndLogEx(NORMAL, "------------------------------------------------------"); if (bIsSegmented) { @@ -348,24 +348,24 @@ static int CmdLegicInfo(const char *Cmd) { PrintAndLogEx(NORMAL, "Segment | %02u ", segmentNum); PrintAndLogEx(NORMAL, "raw header | 0x%02X 0x%02X 0x%02X 0x%02X", - data[i] ^ crc, - data[i + 1] ^ crc, - data[i + 2] ^ crc, - data[i + 3] ^ crc - ); + data[i] ^ crc, + data[i + 1] ^ crc, + data[i + 2] ^ crc, + data[i + 3] ^ crc + ); PrintAndLogEx(NORMAL, "Segment len | %u, Flag: 0x%X (valid:%01u, last:%01u)", - segment_len, - segment_flag, - (segment_flag & 0x4) >> 2, - (segment_flag & 0x8) >> 3 - ); + segment_len, + segment_flag, + (segment_flag & 0x4) >> 2, + (segment_flag & 0x8) >> 3 + ); PrintAndLogEx(NORMAL, " | WRP: %02u, WRC: %02u, RD: %01u, CRC: 0x%02X (%s)", - wrp, - wrc, - ((data[i + 3] ^ crc) & 0x80) >> 7, - segCRC, - (segCRC == segCalcCRC) ? _GREEN_("OK") : _RED_("Fail") - ); + wrp, + wrc, + ((data[i + 3] ^ crc) & 0x80) >> 7, + segCRC, + (segCRC == segCalcCRC) ? _GREEN_("OK") : _RED_("Fail") + ); i += 5; @@ -397,13 +397,13 @@ static int CmdLegicInfo(const char *Cmd) { // does this one work? (Answer: Only if KGH/BGH is used with BCD encoded card number! So maybe this will show just garbage...) if (wrp_len == 8) { PrintAndLogEx(NORMAL, "Card ID: " _YELLOW_("%2X%02X%02X"), - data[i - 4] ^ crc, - data[i - 3] ^ crc, - data[i - 2] ^ crc - ); + data[i - 4] ^ crc, + data[i - 3] ^ crc, + data[i - 2] ^ crc + ); } } - if (remain_seg_payload_len > 0 ) { + if (remain_seg_payload_len > 0) { PrintAndLogEx(NORMAL, "Remaining segment payload: (I %d | K %d | Remain LEN %d)", i, k, remain_seg_payload_len); PrintAndLogEx(NORMAL, "\nrow | data"); PrintAndLogEx(NORMAL, "-----+------------------------------------------------"); @@ -445,7 +445,7 @@ static int CmdLegicInfo(const char *Cmd) { PrintAndLogEx(NORMAL, "\nrow | data"); PrintAndLogEx(NORMAL, "-----+------------------------------------------------"); print_hex_break(data + i, wrc, 16); - PrintAndLogEx(NORMAL, "-----+------------------------------------------------\n"); + PrintAndLogEx(NORMAL, "-----+------------------------------------------------\n"); i += wrc; } @@ -461,19 +461,19 @@ static int CmdLegicInfo(const char *Cmd) { // A: Only if KGH/BGH is used with BCD encoded card number. Maybe this will show just garbage if (wrp_len == 8) { PrintAndLogEx(NORMAL, "Card ID: " _YELLOW_("%2X%02X%02X"), - data[i - 4], - data[i - 3], - data[i - 2] - ); + data[i - 4], + data[i - 3], + data[i - 2] + ); } } - if ( remain_seg_payload_len > 0 ) { + if (remain_seg_payload_len > 0) { PrintAndLogEx(NORMAL, "Remaining segment payload: (I %d | Remain LEN %d)", i, remain_seg_payload_len); PrintAndLogEx(NORMAL, "\nrow | data"); PrintAndLogEx(NORMAL, "-----+------------------------------------------------"); print_hex_break(data + i, remain_seg_payload_len, 16); - PrintAndLogEx(NORMAL, "-----+------------------------------------------------\n"); + PrintAndLogEx(NORMAL, "-----+------------------------------------------------\n"); } } diff --git a/client/cmdlffdx.c b/client/cmdlffdx.c index 027f12895..e09caca9d 100644 --- a/client/cmdlffdx.c +++ b/client/cmdlffdx.c @@ -226,7 +226,7 @@ static int CmdFdxDemod(const char *Cmd) { PrintAndLogEx(SUCCESS, "Reserved/RFU %u (0x04%X)", reservedCode, reservedCode); PrintAndLogEx(SUCCESS, "Animal Tag %s", animalBit ? _YELLOW_("True") : "False"); PrintAndLogEx(SUCCESS, "Has extended data %s [0x%X]", dataBlockBit ? _YELLOW_("True") : "False", extended); - PrintAndLogEx(SUCCESS, "CRC-16 0x%04X - 0x%04X [%s]", crc_16, calcCrc, (calcCrc == crc_16) ? _GREEN_("Ok") : _RED_("Fail") ); + PrintAndLogEx(SUCCESS, "CRC-16 0x%04X - 0x%04X [%s]", crc_16, calcCrc, (calcCrc == crc_16) ? _GREEN_("Ok") : _RED_("Fail")); if (g_debugMode) { PrintAndLogEx(DEBUG, "Start marker %d; Size %d", preambleIndex, size); diff --git a/client/proxmark3.c b/client/proxmark3.c index ffb8b295f..aed464d50 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -223,9 +223,9 @@ const char *get_my_executable_directory(void) { static void set_my_executable_path(void) { int path_length = wai_getExecutablePath(NULL, 0, NULL); - if (path_length == -1) + if (path_length == -1) return; - + my_executable_path = (char *)calloc(path_length + 1, sizeof(uint8_t)); int dirname_length = 0; if (wai_getExecutablePath(my_executable_path, path_length, &dirname_length) != -1) { @@ -287,8 +287,8 @@ int main(int argc, char *argv[]) { #if defined(_WIN32) for (int m = strlen(argv[0]); m > 0; m--) { - if ( argv[0][m] == '\\' ) { - show_help(true, argv[0] + (++m) ); + if (argv[0][m] == '\\') { + show_help(true, argv[0] + (++m)); break; } } diff --git a/client/util.c b/client/util.c index 05e9d700c..b14023067 100644 --- a/client/util.c +++ b/client/util.c @@ -9,7 +9,7 @@ //----------------------------------------------------------------------------- // ensure gmtime_r is available even with -std=c99; must be included before - #if !defined(_WIN32) +#if !defined(_WIN32) #define _POSIX_C_SOURCE 200112L #endif diff --git a/common/usart.c b/common/usart.c index d04ff7d4b..1a46b93c4 100644 --- a/common/usart.c +++ b/common/usart.c @@ -62,33 +62,33 @@ inline int16_t usart_readbuffer(uint8_t *data) { uint8_t check = 0; inline int16_t usart_readbuffer(uint8_t *data) { - // Check if the first PDC bank is free + // Check if the first PDC bank is free if (pUS1->US_RCR == 0) { pUS1->US_RPR = (uint32_t)data; pUS1->US_RCR = sizeof(UsbCommand); - pUS1->US_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTEN; - check = 0; + pUS1->US_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTEN; + check = 0; return 2; } else { return 0; } } -void usart_readcheck(uint8_t *data,size_t len) { - if (pUS1->US_RCR 300000){ - pUS1->US_RPR = (uint32_t)data; - pUS1->US_RCR = len; - check = 0; - } - } else { - check = 0; - } +void usart_readcheck(uint8_t *data, size_t len) { + if (pUS1->US_RCR < len) { + if (check == 0) { + StartCountUS(); + check = 1; + } + //300ms + if (GetCountUS() > 300000) { + pUS1->US_RPR = (uint32_t)data; + pUS1->US_RCR = len; + check = 0; + } + } else { + check = 0; + } } inline bool usart_dataavailable(void) { @@ -99,7 +99,7 @@ inline int16_t usart_readcommand(uint8_t *data) { if (pUS1->US_RCR == 0) return usart_readbuffer(data); - return 0; + return 0; } inline bool usart_commandavailable(void) { @@ -126,26 +126,26 @@ inline int16_t usart_writebuffer(uint8_t *data, size_t len) { // transfer from device to client inline int16_t usart_writebuffer(uint8_t *data, size_t len) { - - while (pUS1->US_TCR && pUS1->US_TNCR) {}; - + + while (pUS1->US_TCR && pUS1->US_TNCR) {}; + // Check if the first PDC bank is free if (pUS1->US_TCR == 0) { - memcpy(us_outbuf, data, len); - pUS1->US_TPR = (uint32_t)us_outbuf; + memcpy(us_outbuf, data, len); + pUS1->US_TPR = (uint32_t)us_outbuf; pUS1->US_TCR = sizeof(us_outbuf); - pUS1->US_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN; + pUS1->US_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN; } // Check if the second PDC bank is free else if (pUS1->US_TNCR == 0) { - memcpy(us_outbuf, data, len); + memcpy(us_outbuf, data, len); pUS1->US_TNPR = (uint32_t)us_outbuf; pUS1->US_TNCR = sizeof(us_outbuf); - pUS1->US_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN; - } - //wait until finishing transfer - while (pUS1->US_TCR && pUS1->US_TNCR) {}; - return 0; + pUS1->US_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN; + } + //wait until finishing transfer + while (pUS1->US_TCR && pUS1->US_TNCR) {}; + return 0; } @@ -200,10 +200,10 @@ void usart_init(void) { // re-enable receiver / transmitter pUS1->US_CR = (AT91C_US_RXEN | AT91C_US_TXEN); - + // ready to receive pUS1->US_RPR = (uint32_t)us_inbuf; - pUS1->US_RCR = 0; - pUS1->US_RNCR = 0; + pUS1->US_RCR = 0; + pUS1->US_RNCR = 0; pUS1->US_PTCR = AT91C_PDC_RXTEN; } diff --git a/common/usart.h b/common/usart.h index aed86db45..9200d8731 100644 --- a/common/usart.h +++ b/common/usart.h @@ -13,7 +13,7 @@ int16_t usart_readbuffer(uint8_t *data); int16_t usart_writebuffer(uint8_t *data, size_t len); bool usart_dataavailable(void); int16_t usart_readcommand(uint8_t *data); -void usart_readcheck(uint8_t *data,size_t len); +void usart_readcheck(uint8_t *data, size_t len); bool usart_commandavailable(void); #endif