#include <stdio.h>\r
#include <string.h>\r
#include <inttypes.h>\r
+#include <time.h>\r
#include "proxmark3.h"\r
#include "ui.h"\r
#include "graph.h"\r
\r
bool DecodeT55xxBlock(){\r
\r
- char buf[8] = {0x00};\r
+ char buf[9] = {0x00};\r
char *cmdStr = buf;\r
int ans = 0;\r
uint8_t bitRate[8] = {8,16,32,40,50,64,100,128};\r
ans = FSKrawDemod(cmdStr, FALSE);\r
break;\r
case DEMOD_FSK1:\r
+ case DEMOD_FSK1a: \r
sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );\r
CmdLtrim(cmdStr); \r
- sprintf(cmdStr,"%d 1 8 5", bitRate[config.bitrate] );\r
- ans = FSKrawDemod(cmdStr, FALSE);\r
- break;\r
- case DEMOD_FSK1a:\r
- sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );\r
- CmdLtrim(cmdStr); \r
- sprintf(cmdStr,"%d 0 8 5", bitRate[config.bitrate] );\r
+ sprintf(cmdStr,"%d %d 8 5", bitRate[config.bitrate], config.inverted );\r
ans = FSKrawDemod(cmdStr, FALSE);\r
break;\r
case DEMOD_FSK2:\r
- sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );\r
- CmdLtrim(cmdStr); \r
- sprintf(cmdStr,"%d 0 10 8", bitRate[config.bitrate] );\r
- ans = FSKrawDemod(cmdStr, FALSE);\r
- break;\r
case DEMOD_FSK2a:\r
sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );\r
CmdLtrim(cmdStr); \r
- sprintf(cmdStr,"%d 1 10 8", bitRate[config.bitrate] );\r
+ sprintf(cmdStr,"%d %d 10 8", bitRate[config.bitrate], config.inverted );\r
ans = FSKrawDemod(cmdStr, FALSE);\r
break;\r
case DEMOD_ASK:\r
ans = PSKDemod(cmdStr, FALSE);\r
break;\r
case DEMOD_PSK2:\r
- sprintf(cmdStr,"%d 1", bitRate[config.bitrate] );\r
+ sprintf(cmdStr,"%d %d 1", bitRate[config.bitrate], config.inverted );\r
ans = PSKDemod(cmdStr, FALSE);\r
psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
break;\r
ans = NRZrawDemod(cmdStr, FALSE);\r
break;\r
case DEMOD_BI:\r
- sprintf(cmdStr,"0 %d 0 1", bitRate[config.bitrate] );\r
- ans = ASKbiphaseDemod(cmdStr, FALSE);\r
- break;\r
case DEMOD_BIa:\r
- sprintf(cmdStr,"0 %d 1 1", bitRate[config.bitrate] );\r
+ sprintf(cmdStr,"0 %d %d 0", bitRate[config.bitrate], config.inverted );\r
ans = ASKbiphaseDemod(cmdStr, FALSE);\r
break;\r
default:\r
}\r
break;\r
case DEMOD_BI:\r
+ case DEMOD_BIa:\r
detRate = GetAskClock("",FALSE, FALSE); \r
if (expected[readRate] == detRate) {\r
config.bitrate = readRate;\r
uint8_t si = 0;\r
for (uint8_t idx = 0; idx < 64; idx++){\r
si = idx;\r
- if ( PackBits(si, 32, DemodBuffer) == 0x00 ) continue;\r
+ if ( PackBits(si, 32, DemodBuffer) == 0x00 ) continue; // configuration block with only zeros is impossible.\r
\r
uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key\r
uint8_t resv = PackBits(si, 4, DemodBuffer); si += 4; //was 7 & +=7+3 //should be only 4 bits if extended mode\r
return FALSE;\r
}\r
\r
-void printT55xxBlock(const char *demodStr){\r
+void printT55xxBlock(const char *blockNum){\r
\r
uint8_t i = config.offset;\r
uint8_t endpos = 32 + i;\r
bits[i - config.offset]=DemodBuffer[i];\r
\r
blockData = PackBits(0, 32, bits);\r
- PrintAndLog("0x%08X %s [%s]", blockData, sprint_bin(bits,32), demodStr);\r
+ PrintAndLog("[%s] 0x%08X %s", blockNum, blockData, sprint_bin(bits,32));\r
}\r
\r
int special(const char *Cmd) {\r
uint8_t si = config.offset+repeat;\r
uint32_t bl0 = PackBits(si, 32, DemodBuffer);\r
uint32_t bl1 = PackBits(si+32, 32, DemodBuffer);\r
+ // uint32_t bl2 = PackBits(si+64, 32, DemodBuffer);\r
\r
uint32_t acl = PackBits(si, 8, DemodBuffer); si += 8;\r
uint32_t mfc = PackBits(si, 8, DemodBuffer); si += 8;\r
uint32_t icr = PackBits(si, 3, DemodBuffer); si += 3;\r
uint32_t year = PackBits(si, 4, DemodBuffer); si += 4;\r
uint32_t quarter = PackBits(si, 2, DemodBuffer); si += 2;\r
- uint32_t lotid = PackBits(si, 12, DemodBuffer); si += 12;\r
+ uint32_t lotid = PackBits(si, 14, DemodBuffer); si += 14;\r
uint32_t wafer = PackBits(si, 5, DemodBuffer); si += 5;\r
uint32_t dw = PackBits(si, 15, DemodBuffer); \r
\r
- year += 2000;\r
\r
- PrintAndLog("");\r
+ time_t t = time(NULL);\r
+ struct tm tm = *localtime(&t);\r
+ if ( year > tm.tm_year-110)\r
+ year += 2000;\r
+ else\r
+ year += 2010;\r
+\r
+ if ( acl != 0xE0 ) {\r
+ PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");\r
+ return 1;\r
+ }\r
+\r
PrintAndLog("-- T55xx Trace Information ----------------------------------");\r
PrintAndLog("-------------------------------------------------------------");\r
PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl, acl);\r
PrintAndLog(" CID : 0x%02X (%d) - %s", cid, cid, GetModelStrFromCID(cid));\r
PrintAndLog(" ICR IC Revision : %d",icr );\r
PrintAndLog(" Manufactured");\r
- PrintAndLog(" Year/Quarter : %d/%d",year, quarter );\r
+ PrintAndLog(" Year/Quarter : 20?%d/%d",year, quarter);\r
PrintAndLog(" Lot ID : %d", lotid );\r
PrintAndLog(" Wafer number : %d", wafer);\r
PrintAndLog(" Die Number : %d", dw);\r
PrintAndLog(" Raw Data - Page 1");\r
PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+config.offset+repeat,32) );\r
PrintAndLog(" Block 1 : 0x%08X %s", bl1, sprint_bin(DemodBuffer+config.offset+repeat+32,32) );\r
+ //PrintAndLog(" Block 2 : 0x%08X %s", bl2, sprint_bin(DemodBuffer+config.offset+repeat+64,32) );\r
PrintAndLog("-------------------------------------------------------------");\r
\r
- if ( acl != 0xE0 )\r
- PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");\r
+\r
/*\r
TRACE - BLOCK O\r
Bits Definition HEX\r
}\r
\r
char * GetBitRateStr(uint32_t id){\r
- static char buf[40];\r
+ static char buf[20];\r
char *retStr = buf;\r
switch (id){\r
case 0: \r
- sprintf(retStr,"%d - RF/8",id);\r
+ snprintf(retStr,sizeof(buf),"%d - RF/8",id);\r
break;\r
case 1:\r
- sprintf(retStr,"%d - RF/16",id);\r
+ snprintf(retStr,sizeof(buf),"%d - RF/16",id);\r
break;\r
case 2: \r
- sprintf(retStr,"%d - RF/32",id);\r
+ snprintf(retStr,sizeof(buf),"%d - RF/32",id);\r
break;\r
case 3:\r
- sprintf(retStr,"%d - RF/40",id);\r
+ snprintf(retStr,sizeof(buf),"%d - RF/40",id);\r
break;\r
case 4:\r
- sprintf(retStr,"%d - RF/50",id);\r
+ snprintf(retStr,sizeof(buf),"%d - RF/50",id);\r
break;\r
case 5:\r
- sprintf(retStr,"%d - RF/64",id);\r
+ snprintf(retStr,sizeof(buf),"%d - RF/64",id);\r
break;\r
case 6:\r
- sprintf(retStr,"%d - RF/100",id);\r
+ snprintf(retStr,sizeof(buf),"%d - RF/100",id);\r
break;\r
case 7:\r
- sprintf(retStr,"%d - RF/128",id);\r
+ snprintf(retStr,sizeof(buf),"%d - RF/128",id);\r
break;\r
default:\r
- sprintf(retStr,"%d - (Unknown)",id);\r
+ snprintf(retStr,sizeof(buf),"%d - (Unknown)",id);\r
break;\r
}\r
\r
}\r
\r
char * GetSaferStr(uint32_t id){\r
- static char buf[40];\r
+ static char buf[20];\r
char *retStr = buf;\r
\r
- sprintf(retStr,"%d",id);\r
+ snprintf(retStr,sizeof(buf),"%d",id);\r
if (id == 6) {\r
- sprintf(retStr,"%d - passwd",id);\r
+ snprintf(retStr,sizeof(buf),"%d - passwd",id);\r
}\r
if (id == 9 ){\r
- sprintf(retStr,"%d - testmode",id);\r
+ snprintf(retStr,sizeof(buf),"%d - testmode",id);\r
}\r
\r
return buf;\r
}\r
+\r
char * GetModulationStr( uint32_t id){\r
- static char buf[40];\r
+ static char buf[60];\r
char *retStr = buf;\r
\r
switch (id){\r
case 0: \r
- sprintf(retStr,"%d - DIRECT (ASK/NRZ)",id);\r
+ snprintf(retStr,sizeof(buf),"%d - DIRECT (ASK/NRZ)",id);\r
break;\r
case 1:\r
- sprintf(retStr,"%d - PSK 1 phase change when input changes",id);\r
+ snprintf(retStr,sizeof(buf),"%d - PSK 1 phase change when input changes",id);\r
break;\r
case 2: \r
- sprintf(retStr,"%d - PSK 2 phase change on bitclk if input high",id);\r
+ snprintf(retStr,sizeof(buf),"%d - PSK 2 phase change on bitclk if input high",id);\r
break;\r
case 3:\r
- sprintf(retStr,"%d - PSK 3 phase change on rising edge of input",id);\r
+ snprintf(retStr,sizeof(buf),"%d - PSK 3 phase change on rising edge of input",id);\r
break;\r
case 4:\r
- sprintf(retStr,"%d - FSK 1 RF/8 RF/5",id);\r
+ snprintf(retStr,sizeof(buf),"%d - FSK 1 RF/8 RF/5",id);\r
break;\r
case 5:\r
- sprintf(retStr,"%d - FSK 2 RF/8 RF/10",id);\r
+ snprintf(retStr,sizeof(buf),"%d - FSK 2 RF/8 RF/10",id);\r
break;\r
case 6:\r
- sprintf(retStr,"%d - FSK 1a RF/5 RF/8",id);\r
+ snprintf(retStr,sizeof(buf),"%d - FSK 1a RF/5 RF/8",id);\r
break;\r
case 7:\r
- sprintf(retStr,"%d - FSK 2a RF/10 RF/8",id);\r
+ snprintf(retStr,sizeof(buf),"%d - FSK 2a RF/10 RF/8",id);\r
break;\r
case 8:\r
- sprintf(retStr,"%d - Manschester",id);\r
+ snprintf(retStr,sizeof(buf),"%d - Manschester",id);\r
break;\r
case 16:\r
- sprintf(retStr,"%d - Biphase",id);\r
+ snprintf(retStr,sizeof(buf),"%d - Biphase",id);\r
break;\r
case 0x18:\r
- sprintf(retStr,"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id);\r
+ snprintf(retStr,sizeof(buf),"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id);\r
break;\r
case 17:\r
- sprintf(retStr,"%d - Reserved",id);\r
+ snprintf(retStr,sizeof(buf),"%d - Reserved",id);\r
break;\r
default:\r
- sprintf(retStr,"0x%02X (Unknown)",id);\r
+ snprintf(retStr,sizeof(buf),"0x%02X (Unknown)",id);\r
break;\r
}\r
return buf;\r
static char buf[10];\r
char *retStr = buf;\r
\r
- if (cid == 1) sprintf(retStr,"ATA5577M1");\r
- if (cid == 2) sprintf(retStr,"ATA5577M2"); \r
+ if (cid == 1) snprintf(retStr, sizeof(buf),"ATA5577M1");\r
+ if (cid == 2) snprintf(retStr, sizeof(buf),"ATA5577M2"); \r
return buf;\r
}\r
\r
char * GetSelectedModulationStr( uint8_t id){\r
\r
- static char buf[16];\r
+ static char buf[20];\r
char *retStr = buf;\r
\r
switch (id){\r
case DEMOD_FSK:\r
- sprintf(retStr,"FSK");\r
+ snprintf(retStr,sizeof(buf),"FSK");\r
break;\r
case DEMOD_FSK1:\r
- sprintf(retStr,"FSK1");\r
+ snprintf(retStr,sizeof(buf),"FSK1");\r
break;\r
case DEMOD_FSK1a:\r
- sprintf(retStr,"FSK1a");\r
+ snprintf(retStr,sizeof(buf),"FSK1a");\r
break;\r
case DEMOD_FSK2:\r
- sprintf(retStr,"FSK2");\r
+ snprintf(retStr,sizeof(buf),"FSK2");\r
break;\r
case DEMOD_FSK2a:\r
- sprintf(retStr,"FSK2a");\r
+ snprintf(retStr,sizeof(buf),"FSK2a");\r
break;\r
case DEMOD_ASK: \r
- sprintf(retStr,"ASK");\r
+ snprintf(retStr,sizeof(buf),"ASK");\r
break;\r
case DEMOD_NRZ:\r
- sprintf(retStr,"DIRECT/NRZ");\r
+ snprintf(retStr,sizeof(buf),"DIRECT/NRZ");\r
break;\r
case DEMOD_PSK1:\r
- sprintf(retStr,"PSK1");\r
+ snprintf(retStr,sizeof(buf),"PSK1");\r
break;\r
case DEMOD_PSK2:\r
- sprintf(retStr,"PSK2");\r
+ snprintf(retStr,sizeof(buf),"PSK2");\r
break;\r
case DEMOD_PSK3:\r
- sprintf(retStr,"PSK3");\r
+ snprintf(retStr,sizeof(buf),"PSK3");\r
break;\r
case DEMOD_BI:\r
- sprintf(retStr,"BIPHASE");\r
+ snprintf(retStr,sizeof(buf),"BIPHASE");\r
break;\r
case DEMOD_BIa:\r
- sprintf(retStr,"BIPHASEa - (CDP)");\r
+ snprintf(retStr,sizeof(buf),"BIPHASEa - (CDP)");\r
break;\r
default:\r
- sprintf(retStr,"(Unknown)");\r
+ snprintf(retStr,sizeof(buf),"(Unknown)");\r
break;\r
}\r
return buf;\r