make style

This commit is contained in:
Philippe Teuwen 2019-07-23 23:43:30 +02:00
commit ac233a346a
6 changed files with 689 additions and 670 deletions

View file

@ -113,16 +113,22 @@
/* /*
// Note: Moved * 8 to apply when used. Saving 28 bytes here (- the *8) and 28 bytes flash. // Note: Moved * 8 to apply when used. Saving 28 bytes here (- the *8) and 28 bytes flash.
// StartGap WriteGap Bit 0/00 Bit 1/01 Bit 10 Bit 11 ReadGap // StartGap WriteGap Bit 0/00 Bit 1/01 Bit 10 Bit 11 ReadGap
t55xx_config T55xx_Timing = {{{ 29 , 17 , 15 , 50 , 0 , 0 , 15 }, // Default Fixed t55xx_config T55xx_Timing = {{
{ 29 , 17 , 15 , 50 , 0 , 0 , 15 }, // Default Fixed
{ 31 , 20 , 18 , 50 , 0 , 0 , 15 }, // Long Leading Ref. { 31 , 20 , 18 , 50 , 0 , 0 , 15 }, // Long Leading Ref.
{ 31 , 20 , 18 , 40 , 0 , 0 , 15 }, // Leading 0 { 31 , 20 , 18 , 40 , 0 , 0 , 15 }, // Leading 0
{ 29 , 17 , 15 , 31 , 47 , 63 , 15 } }}; // 1 of 4 { 29 , 17 , 15 , 31 , 47 , 63 , 15 } // 1 of 4
}
};
*/ */
// StartGap WriteGap Bit 0/00 Bit 1/01 Bit 10 Bit 11 ReadGap // StartGap WriteGap Bit 0/00 Bit 1/01 Bit 10 Bit 11 ReadGap
t55xx_config T55xx_Timing = {{{ 29 * 8 , 17 * 8 , 15 * 8 , 50 * 8 , 0 , 0 , 15 * 8 }, // Default Fixed t55xx_config T55xx_Timing = {{
{ 29 * 8, 17 * 8, 15 * 8, 50 * 8, 0, 0, 15 * 8 }, // Default Fixed
{ 31 * 8, 20 * 8, 18 * 8, 50 * 8, 0, 0, 15 * 8 }, // Long Leading Ref. { 31 * 8, 20 * 8, 18 * 8, 50 * 8, 0, 0, 15 * 8 }, // Long Leading Ref.
{ 31 * 8, 20 * 8, 18 * 8, 40 * 8, 0, 0, 15 * 8 }, // Leading 0 { 31 * 8, 20 * 8, 18 * 8, 40 * 8, 0, 0, 15 * 8 }, // Leading 0
{ 29 * 8 , 17 * 8 , 15 * 8 , 31 * 8 , 47 * 8, 63 * 8, 15 * 8 } }}; // 1 of 4 { 29 * 8, 17 * 8, 15 * 8, 31 * 8, 47 * 8, 63 * 8, 15 * 8 } // 1 of 4
}
};
// Some defines for readability // Some defines for readability
@ -138,10 +144,18 @@ void printT55xxConfig(void) {
DbpString(_BLUE_("LF T55XX config")); DbpString(_BLUE_("LF T55XX config"));
for (DLMode = 0; DLMode < 4; DLMode++) { for (DLMode = 0; DLMode < 4; DLMode++) {
switch (DLMode) { switch (DLMode) {
case T55xx_DLMode_Fixed : Dbprintf("r 0 fixed bit length (default)"); break; case T55xx_DLMode_Fixed :
case T55xx_DLMode_LLR : Dbprintf("r 1 long leading reference"); break; Dbprintf("r 0 fixed bit length (default)");
case T55xx_DLMode_Leading0 : Dbprintf("r 2 leading zero"); break; break;
case T55xx_DLMode_1of4 : Dbprintf("r 3 1 of 4 coding reference"); break; case T55xx_DLMode_LLR :
Dbprintf("r 1 long leading reference");
break;
case T55xx_DLMode_Leading0 :
Dbprintf("r 2 leading zero");
break;
case T55xx_DLMode_1of4 :
Dbprintf("r 3 1 of 4 coding reference");
break;
} }
Dbprintf(" [a] startgap............%d*8 (%d)", T55xx_Timing.m[DLMode].start_gap / 8, T55xx_Timing.m[DLMode].start_gap); Dbprintf(" [a] startgap............%d*8 (%d)", T55xx_Timing.m[DLMode].start_gap / 8, T55xx_Timing.m[DLMode].start_gap);
Dbprintf(" [b] writegap............%d*8 (%d)", T55xx_Timing.m[DLMode].write_gap / 8, T55xx_Timing.m[DLMode].write_gap); Dbprintf(" [b] writegap............%d*8 (%d)", T55xx_Timing.m[DLMode].write_gap / 8, T55xx_Timing.m[DLMode].write_gap);
@ -168,8 +182,7 @@ void setT55xxConfig(uint8_t arg0, t55xx_config *c) {
if (DLMode == T55xx_DLMode_1of4) { if (DLMode == T55xx_DLMode_1of4) {
if (c->m[DLMode].write_2 != 0) T55xx_Timing.m[DLMode].write_2 = c->m[DLMode].write_2;// * 8; if (c->m[DLMode].write_2 != 0) T55xx_Timing.m[DLMode].write_2 = c->m[DLMode].write_2;// * 8;
if (c->m[DLMode].write_3 != 0) T55xx_Timing.m[DLMode].write_3 = c->m[DLMode].write_3;// * 8 ; if (c->m[DLMode].write_3 != 0) T55xx_Timing.m[DLMode].write_3 = c->m[DLMode].write_3;// * 8 ;
} } else {
else{
T55xx_Timing.m[DLMode].write_2 = 0x00; T55xx_Timing.m[DLMode].write_2 = 0x00;
T55xx_Timing.m[DLMode].write_3 = 0x00; T55xx_Timing.m[DLMode].write_3 = 0x00;
} }
@ -1482,11 +1495,21 @@ void T55xxWriteBit(uint8_t bit, uint8_t downlink_idx) {
// Dbprintf ("%d",bit); // Dbprintf ("%d",bit);
// If bit = 4 Send Long Leading Reference which is (138*8) + WRITE_0 // If bit = 4 Send Long Leading Reference which is (138*8) + WRITE_0
switch (bit) { switch (bit) {
case 0 : TurnReadLFOn(T55xx_Timing.m[downlink_idx].write_0 ); break; // Send bit 0/00 case 0 :
case 1 : TurnReadLFOn(T55xx_Timing.m[downlink_idx].write_1 ); break; // Send bit 1/01 TurnReadLFOn(T55xx_Timing.m[downlink_idx].write_0);
case 2 : TurnReadLFOn(T55xx_Timing.m[downlink_idx].write_2 ); break; // Send bits 10 (1 of 4) break; // Send bit 0/00
case 3 : TurnReadLFOn(T55xx_Timing.m[downlink_idx].write_3 ); break; // Send bits 11 (1 of 4) case 1 :
case 4 : TurnReadLFOn(T55xx_Timing.m[downlink_idx].write_0 + (136 * 8)); break; // Send Long Leading Reference TurnReadLFOn(T55xx_Timing.m[downlink_idx].write_1);
break; // Send bit 1/01
case 2 :
TurnReadLFOn(T55xx_Timing.m[downlink_idx].write_2);
break; // Send bits 10 (1 of 4)
case 3 :
TurnReadLFOn(T55xx_Timing.m[downlink_idx].write_3);
break; // Send bits 11 (1 of 4)
case 4 :
TurnReadLFOn(T55xx_Timing.m[downlink_idx].write_0 + (136 * 8));
break; // Send Long Leading Reference
} }
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
@ -1500,8 +1523,7 @@ void T55xxWriteBit(uint8_t bit, uint8_t downlink_idx) {
// num_bits - how many bits (low x bits of data) Max 32 bits at a time // num_bits - how many bits (low x bits of data) Max 32 bits at a time
// max_len - how many bytes can the bit_array hold (ensure no buffer overflow) // max_len - how many bytes can the bit_array hold (ensure no buffer overflow)
// returns "Next" bit offset / bits stored (for next store) // returns "Next" bit offset / bits stored (for next store)
uint8_t T55xx_SetBits (uint8_t *BitStream, uint8_t start_offset, uint32_t data , uint8_t num_bits, uint8_t max_len) uint8_t T55xx_SetBits(uint8_t *BitStream, uint8_t start_offset, uint32_t data, uint8_t num_bits, uint8_t max_len) {
{
int8_t offset; int8_t offset;
int8_t NextOffset = start_offset; int8_t NextOffset = start_offset;
@ -1515,8 +1537,7 @@ uint8_t T55xx_SetBits (uint8_t *BitStream, uint8_t start_offset, uint32_t data ,
NextOffset++; NextOffset++;
} }
} } else {
else {
// Note: This should never happen unless some code changes cause it. // Note: This should never happen unless some code changes cause it.
// So short message for coders when testing. // So short message for coders when testing.
Dbprintf("T55 too many bits"); Dbprintf("T55 too many bits");
@ -1539,7 +1560,6 @@ void T55xx_SendCMD (uint32_t Data, uint32_t Pwd, uint16_t arg) {
xxxx 1xxxxxxx 0x080 reset xxxx 1xxxxxxx 0x080 reset
xxx1 xxxxxxxx 0x100 brute force xxx1 xxxxxxxx 0x100 brute force
111x xxxxxxxx 0xE00 Block 111x xxxxxxxx 0xE00 Block
*/ */
uint8_t downlink_mode = (arg >> 3) & 0x03; uint8_t downlink_mode = (arg >> 3) & 0x03;
@ -1570,8 +1590,7 @@ void T55xx_SendCMD (uint32_t Data, uint32_t Pwd, uint16_t arg) {
if (t55_send_Reset) { if (t55_send_Reset) {
// Reset : r*) 00 // Reset : r*) 00
BitStreamLen = T55xx_SetBits(BitStream, BitStreamLen, 0, 2, sizeof(BitStream)); BitStreamLen = T55xx_SetBits(BitStream, BitStreamLen, 0, 2, sizeof(BitStream));
} } else {
else {
if (t55_send_TestMode) Dbprintf("TestMODE"); if (t55_send_TestMode) Dbprintf("TestMODE");
BitStreamLen = T55xx_SetBits(BitStream, BitStreamLen, t55_send_TestMode ? 0 : 1, 1, sizeof(BitStream)); BitStreamLen = T55xx_SetBits(BitStream, BitStreamLen, t55_send_TestMode ? 0 : 1, 1, sizeof(BitStream));
BitStreamLen = T55xx_SetBits(BitStream, BitStreamLen, t55_send_TestMode ? 1 : t55_send_Page, 1, sizeof(BitStream)); BitStreamLen = T55xx_SetBits(BitStream, BitStreamLen, t55_send_TestMode ? 1 : t55_send_Page, 1, sizeof(BitStream));
@ -1615,8 +1634,7 @@ void T55xx_SendCMD (uint32_t Data, uint32_t Pwd, uint16_t arg) {
SendBits += (BitStream[BitStream_Byte(i + 1)] >> (BitStream_Bit(i + 1)) & 1); // Bit i+1; SendBits += (BitStream[BitStream_Byte(i + 1)] >> (BitStream_Bit(i + 1)) & 1); // Bit i+1;
T55xxWriteBit(SendBits & 3, downlink_mode);//Timing); T55xxWriteBit(SendBits & 3, downlink_mode);//Timing);
} }
} } else {
else {
for (i = 0; i < BitStreamLen; i++) { for (i = 0; i < BitStreamLen; i++) {
SendBits = (BitStream[BitStream_Byte(i)] >> BitStream_Bit(i)); SendBits = (BitStream[BitStream_Byte(i)] >> BitStream_Bit(i));
T55xxWriteBit(SendBits & 1, downlink_mode);//Timing); T55xxWriteBit(SendBits & 1, downlink_mode);//Timing);
@ -1775,14 +1793,14 @@ void T55xxReadBlockExt (uint16_t flags, uint8_t block, uint32_t pwd) {
void T55xxReadBlock(uint8_t page, bool pwd_mode, bool brute_mem, uint8_t block, uint32_t pwd, uint8_t downlink_mode) { void T55xxReadBlock(uint8_t page, bool pwd_mode, bool brute_mem, uint8_t block, uint32_t pwd, uint8_t downlink_mode) {
/* /*
flag bits flag bits
xxxxxxx1 0x0001 PwdMode xxxx xxxxxxx1 0x0001 PwdMode
xxxxxx1x 0x0002 Page xxxx xxxxxx1x 0x0002 Page
xxxxx1xx 0x0004 testMode xxxx xxxxx1xx 0x0004 testMode
xxx11xxx 0x0018 downlink mode xxxx xxx11xxx 0x0018 downlink mode
xx1xxxxx 0x0020 !reg_readmode xxxx xx1xxxxx 0x0020 !reg_readmode
x1xxxxxx 0x0040 called for a read, so no data packet xxxx x1xxxxxx 0x0040 called for a read, so no data packet
1xxxxxxx 0x0080 reset xxxx 1xxxxxxx 0x0080 reset
1xxxxxxxx 0x0100 brute/leave field on xxx1 xxxxxxxx 0x0100 brute / leave field on
*/ */
uint16_t flags = 0x0040; // read packet uint16_t flags = 0x0040; // read packet
if (pwd_mode) flags |= 0x0001; if (pwd_mode) flags |= 0x0001;

View file

@ -556,18 +556,26 @@ static int SanityOfflineCheck(bool useGraphBuffer) {
return PM3_SUCCESS; return PM3_SUCCESS;
} }
void T55xx_Print_DownlinkMode (uint8_t downlink_mode) void T55xx_Print_DownlinkMode(uint8_t downlink_mode) {
{
char Msg[80]; char Msg[80];
sprintf(Msg, "Downlink Mode used : "); sprintf(Msg, "Downlink Mode used : ");
switch (downlink_mode) { switch (downlink_mode) {
case 0 : strcat (Msg,"default/fixed bit length"); break; case 0 :
case 1 : strcat (Msg,"long leading reference (r 1)"); break; strcat(Msg, "default/fixed bit length");
case 2 : strcat (Msg,"leading zero reference (r 2)"); break; break;
case 3 : strcat (Msg,"1 of 4 coding reference (r 3)"); break; case 1 :
strcat(Msg, "long leading reference (r 1)");
break;
case 2 :
strcat(Msg, "leading zero reference (r 2)");
break;
case 3 :
strcat(Msg, "1 of 4 coding reference (r 3)");
break;
default : default :
strcat (Msg,"default/fixed bit length"); break; strcat(Msg, "default/fixed bit length");
break;
} }
PrintAndLogEx(NORMAL, Msg); PrintAndLogEx(NORMAL, Msg);
@ -622,18 +630,17 @@ static int CmdT55xxDetect(const char *Cmd) {
// found = false if password is supplied but wrong d/l mode // found = false if password is supplied but wrong d/l mode
// so keep trying other modes (if requested) // so keep trying other modes (if requested)
/* if (!found) { /*
if (!found) {
printf ("Aquire not found"); printf ("Aquire not found");
return PM3_ENODATA; return PM3_ENODATA;
} }
*/ */
if (tryDetectModulation()) if (tryDetectModulation()) {
{
T55xx_Print_DownlinkMode(dl_mode); T55xx_Print_DownlinkMode(dl_mode);
dl_mode = 4; dl_mode = 4;
found = true; found = true;
} } else found = false;
else found = false;
if (!try_all_dl_modes) dl_mode = 4; if (!try_all_dl_modes) dl_mode = 4;
} }
@ -646,7 +653,8 @@ static int CmdT55xxDetect(const char *Cmd) {
PrintAndLogEx(WARNING, "Could not detect modulation automatically. Try setting it manually with " _YELLOW_("\'lf t55xx config\'")); PrintAndLogEx(WARNING, "Could not detect modulation automatically. Try setting it manually with " _YELLOW_("\'lf t55xx config\'"));
/* if (!useGB) { /*
if (!useGB) {
if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password,downlink_mode)) if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password,downlink_mode))
return PM3_ENODATA; return PM3_ENODATA;
} }
@ -2227,8 +2235,7 @@ static int CmdT55xxBruteForce(const char *Cmd) {
if (found) { if (found) {
PrintAndLogEx(SUCCESS, "Found valid password: [ " _GREEN_("%08X") "]", curr - 1); PrintAndLogEx(SUCCESS, "Found valid password: [ " _GREEN_("%08X") "]", curr - 1);
T55xx_Print_DownlinkMode((found >> 1) & 3); T55xx_Print_DownlinkMode((found >> 1) & 3);
} } else
else
PrintAndLogEx(WARNING, "Bruteforce failed, last tried: [ " _YELLOW_("%08X") " ]", curr); PrintAndLogEx(WARNING, "Bruteforce failed, last tried: [ " _YELLOW_("%08X") " ]", curr);
t1 = msclock() - t1; t1 = msclock() - t1;
@ -2254,8 +2261,7 @@ uint8_t tryOnePassword(uint32_t password, uint8_t downlink_mode) {
// if (getSignalProperties()->isnoise == false) { // if (getSignalProperties()->isnoise == false) {
// } else { // } else {
if (tryDetectModulation()) if (tryDetectModulation()) {
{
return 1 + (dl_mode << 1); return 1 + (dl_mode << 1);
} }
// } // }
@ -2353,8 +2359,7 @@ out:
if (found > 0) { if (found > 0) {
PrintAndLogEx(SUCCESS, "Found valid password: [ " _GREEN_("%08X") "]", curr_password); PrintAndLogEx(SUCCESS, "Found valid password: [ " _GREEN_("%08X") "]", curr_password);
T55xx_Print_DownlinkMode((found >> 1) & 3); T55xx_Print_DownlinkMode((found >> 1) & 3);
} } else
else
PrintAndLogEx(WARNING, "Recover pwd failed"); PrintAndLogEx(WARNING, "Recover pwd failed");
return PM3_SUCCESS; return PM3_SUCCESS;
@ -2516,12 +2521,10 @@ static int CmdT55xxDetectPage1(const char *Cmd) {
for (dl_mode = downlink_mode; dl_mode < 4; dl_mode++) { for (dl_mode = downlink_mode; dl_mode < 4; dl_mode++) {
found = AquireData(T55x7_PAGE1, T55x7_TRACE_BLOCK1, usepwd, password, dl_mode); found = AquireData(T55x7_PAGE1, T55x7_TRACE_BLOCK1, usepwd, password, dl_mode);
//return PM3_ENODATA; //return PM3_ENODATA;
if (tryDetectP1(false)) //tryDetectModulation()) if (tryDetectP1(false)) { //tryDetectModulation())
{
found = dl_mode; found = dl_mode;
dl_mode = 4; dl_mode = 4;
} } else found = false;
else found = false;
if (!try_all_dl_modes) dl_mode = 4; if (!try_all_dl_modes) dl_mode = 4;
} }
@ -2533,8 +2536,7 @@ static int CmdT55xxDetectPage1(const char *Cmd) {
if (found) { if (found) {
PrintAndLogEx(SUCCESS, "T55xx chip found!"); PrintAndLogEx(SUCCESS, "T55xx chip found!");
T55xx_Print_DownlinkMode(found); T55xx_Print_DownlinkMode(found);
} } else
else
PrintAndLogEx(WARNING, "Could not detect modulation automatically. Try setting it manually with " _YELLOW_("\'lf t55xx config\'")); PrintAndLogEx(WARNING, "Could not detect modulation automatically. Try setting it manually with " _YELLOW_("\'lf t55xx config\'"));
@ -2610,8 +2612,7 @@ static int CmdT55xxSetDeviceConfig(const char *Cmd) {
if (erase) { if (erase) {
memset(&conf, 0xff, sizeof(conf)); memset(&conf, 0xff, sizeof(conf));
printf("Conf.m[0] %x\n", conf.m[0].start_gap); printf("Conf.m[0] %x\n", conf.m[0].start_gap);
} } else {
else {
conf.m[downlink_mode].start_gap = startgap * 8; conf.m[downlink_mode].start_gap = startgap * 8;
conf.m[downlink_mode].write_gap = writegap * 8; conf.m[downlink_mode].write_gap = writegap * 8;