+ if ( config.Q5 ){\r
+ if (!DecodeT5555TraceBlock()) return 0;\r
+ }\r
+ else {\r
+ if (!DecodeT55xxBlock()) return 0;\r
+ }\r
+ \r
+ if ( !DemodBufferLen ) return 0;\r
+ \r
+ RepaintGraphWindow();\r
+ uint8_t repeat = (config.offset > 5) ? 32 : 0;\r
+ \r
+ uint8_t si = config.offset + repeat;\r
+ uint32_t bl1 = PackBits(si, 32, DemodBuffer);\r
+ uint32_t bl2 = PackBits(si+32, 32, DemodBuffer); \r
+ \r
+ if (config.Q5) {\r
+ uint32_t hdr = PackBits(si, 9, DemodBuffer); si += 9;\r
+ \r
+ if (hdr != 0x1FF) {\r
+ PrintAndLog("Invalid Q5 Trace data header (expected 0x1FF, found %X)", hdr);\r
+ return 0;\r
+ }\r
+ \r
+ t5555_tracedata_t data = {.bl1 = bl1, .bl2 = bl2, .icr = 0, .lotidc = '?', .lotid = 0, .wafer = 0, .dw =0};\r
+ \r
+ data.icr = PackBits(si, 2, DemodBuffer); si += 2;\r
+ data.lotidc = 'Z' - PackBits(si, 2, DemodBuffer); si += 3;\r
+ \r
+ data.lotid = PackBits(si, 4, DemodBuffer); si += 5;\r
+ data.lotid <<= 4;\r
+ data.lotid |= PackBits(si, 4, DemodBuffer); si += 5;\r
+ data.lotid <<= 4;\r
+ data.lotid |= PackBits(si, 4, DemodBuffer); si += 5;\r
+ data.lotid <<= 4;\r
+ data.lotid |= PackBits(si, 4, DemodBuffer); si += 5;\r
+ data.lotid <<= 1;\r
+ data.lotid |= PackBits(si, 1, DemodBuffer); si += 1;\r
+ \r
+ data.wafer = PackBits(si, 3, DemodBuffer); si += 4;\r
+ data.wafer <<= 2;\r
+ data.wafer |= PackBits(si, 2, DemodBuffer); si += 2;\r
+ \r
+ data.dw = PackBits(si, 2, DemodBuffer); si += 3;\r
+ data.dw <<= 4;\r
+ data.dw |= PackBits(si, 4, DemodBuffer); si += 5;\r
+ data.dw <<= 4;\r
+ data.dw |= PackBits(si, 4, DemodBuffer); si += 5;\r
+ data.dw <<= 4;\r
+ data.dw |= PackBits(si, 4, DemodBuffer); si += 5;\r
+ \r
+ printT5555Trace(data, repeat);\r
+ \r
+ } else {\r
+ \r
+ t55xx_tracedata_t data = {.bl1 = bl1, .bl2 = bl2, .acl = 0, .mfc = 0, .cid = 0, .year = 0, .quarter = 0, .icr = 0, .lotid = 0, .wafer = 0, .dw = 0};\r
+ \r
+ data.acl = PackBits(si, 8, DemodBuffer); si += 8;\r
+ if ( data.acl != 0xE0 ) {\r
+ PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");\r
+ return 0;\r
+ }\r
+\r
+ data.mfc = PackBits(si, 8, DemodBuffer); si += 8;\r
+ data.cid = PackBits(si, 5, DemodBuffer); si += 5;\r
+ data.icr = PackBits(si, 3, DemodBuffer); si += 3;\r
+ data.year = PackBits(si, 4, DemodBuffer); si += 4;\r
+ data.quarter = PackBits(si, 2, DemodBuffer); si += 2;\r
+ data.lotid = PackBits(si, 14, DemodBuffer); si += 14;\r
+ data.wafer = PackBits(si, 5, DemodBuffer); si += 5;\r
+ data.dw = PackBits(si, 15, DemodBuffer); \r
+\r
+ time_t t = time(NULL);\r
+ struct tm tm = *localtime(&t);\r
+ if ( data.year > tm.tm_year-110)\r
+ data.year += 2000;\r
+ else\r
+ data.year += 2010;\r
+\r
+ \r
+ printT55xxTrace(data, repeat);\r
+ }\r
+ return 0;\r
+}\r
+\r
+void printT55xxTrace( t55xx_tracedata_t data, uint8_t repeat ){\r
+ PrintAndLog("-- T55xx Trace Information ----------------------------------");\r
+ PrintAndLog("-------------------------------------------------------------");\r
+ PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", data.acl, data.acl);\r
+ PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", data.mfc, data.mfc, getTagInfo(data.mfc));\r
+ PrintAndLog(" CID : 0x%02X (%d) - %s", data.cid, data.cid, GetModelStrFromCID(data.cid));\r
+ PrintAndLog(" ICR IC Revision : %d", data.icr );\r
+ PrintAndLog(" Manufactured");\r
+ PrintAndLog(" Year/Quarter : %d/%d", data.year, data.quarter);\r
+ PrintAndLog(" Lot ID : %d", data.lotid );\r
+ PrintAndLog(" Wafer number : %d", data.wafer);\r
+ PrintAndLog(" Die Number : %d", data.dw);\r
+ PrintAndLog("-------------------------------------------------------------");\r
+ PrintAndLog(" Raw Data - Page 1");\r
+ PrintAndLog(" Block 1 : 0x%08X %s", data.bl1, sprint_bin(DemodBuffer+config.offset+repeat,32) );\r
+ PrintAndLog(" Block 2 : 0x%08X %s", data.bl2, sprint_bin(DemodBuffer+config.offset+repeat+32,32) );\r
+ PrintAndLog("-------------------------------------------------------------"); \r
+\r
+ /*\r
+ TRACE - BLOCK O\r
+ Bits Definition HEX\r
+ 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0 \r
+ 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation\r
+ 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2 \r
+ 22-24 ICR IC revision\r
+ 25-28 YEAR (BCD encoded) 9 (= 2009)\r
+ 29-30 QUARTER 1,2,3,4 \r
+ 31-32 LOT ID\r
+ \r
+ TRACE - BLOCK 1\r
+ 1-12 LOT ID \r
+ 13-17 Wafer number\r
+ 18-32 DW, die number sequential\r
+ */\r
+}\r
+void printT5555Trace( t5555_tracedata_t data, uint8_t repeat ){\r
+ PrintAndLog("-- T5555 (Q5) Trace Information -----------------------------");\r
+ PrintAndLog("-------------------------------------------------------------");\r
+ PrintAndLog(" ICR IC Revision : %d", data.icr ); \r
+ PrintAndLog(" Lot : %c%d", data.lotidc, data.lotid);\r
+ PrintAndLog(" Wafer number : %d", data.wafer);\r
+ PrintAndLog(" Die Number : %d", data.dw);\r
+ PrintAndLog("-------------------------------------------------------------");\r
+ PrintAndLog(" Raw Data - Page 1");\r
+ PrintAndLog(" Block 1 : 0x%08X %s", data.bl1, sprint_bin(DemodBuffer+config.offset+repeat,32) );\r
+ PrintAndLog(" Block 2 : 0x%08X %s", data.bl2, sprint_bin(DemodBuffer+config.offset+repeat+32,32) );\r
+ \r
+ /*\r
+ ** Q5 **\r
+ TRACE - BLOCK O and BLOCK1\r
+ Bits Definition HEX\r
+ 1-9 Header 0x1FF\r
+ 10-11 IC Revision\r
+ 12-13 Lot ID char\r
+ 15-35 Lot ID (NB parity)\r
+ 36-41 Wafer number (NB parity)\r
+ 42-58 DW, die number sequential (NB parity)\r
+ 60-63 Parity bits\r
+ 64 Always zero\r
+ */\r
+}\r
+\r
+int CmdT55xxInfo(const char *Cmd){\r
+ /*\r
+ Page 0 Block 0 Configuration data.\r
+ Normal mode\r
+ Extended mode\r
+ */\r
+ bool pwdmode = false;\r
+ uint32_t password = 0;\r
+ char cmdp = param_getchar(Cmd, 0);\r
+\r
+ if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') return usage_t55xx_info();\r
+ \r
+ if (strlen(Cmd)==0)\r
+ if ( !AquireData( T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, pwdmode, password ) )\r
+ return 1;\r
+\r
+ if (!DecodeT55xxBlock()) return 1;\r
+\r
+ // too little space to start with\r
+ if ( DemodBufferLen < 32) return 1;\r
+\r
+ // \r
+ PrintAndLog("Offset+32 ==%d\n DemodLen == %d", config.offset + 32,DemodBufferLen );\r
+\r
+ uint8_t si = config.offset;\r
+ uint32_t bl0 = PackBits(si, 32, DemodBuffer); \r
+ uint32_t safer = PackBits(si, 4, DemodBuffer); si += 4; \r
+ uint32_t resv = PackBits(si, 7, DemodBuffer); si += 7;\r
+ uint32_t dbr = PackBits(si, 3, DemodBuffer); si += 3;\r
+ uint32_t extend = PackBits(si, 1, DemodBuffer); si += 1;\r
+ uint32_t datamod = PackBits(si, 5, DemodBuffer); si += 5;\r
+ uint32_t pskcf = PackBits(si, 2, DemodBuffer); si += 2;\r
+ uint32_t aor = PackBits(si, 1, DemodBuffer); si += 1; \r
+ uint32_t otp = PackBits(si, 1, DemodBuffer); si += 1; \r
+ uint32_t maxblk = PackBits(si, 3, DemodBuffer); si += 3;\r
+ uint32_t pwd = PackBits(si, 1, DemodBuffer); si += 1; \r
+ uint32_t sst = PackBits(si, 1, DemodBuffer); si += 1; \r
+ uint32_t fw = PackBits(si, 1, DemodBuffer); si += 1;\r
+ uint32_t inv = PackBits(si, 1, DemodBuffer); si += 1; \r
+ uint32_t por = PackBits(si, 1, DemodBuffer); si += 1;\r
+ \r
+ if (config.Q5) PrintAndLog("*** Warning *** Config Info read off a Q5 will not display as expected");\r
+ PrintAndLog("");\r
+ PrintAndLog("-- T55xx Configuration & Tag Information --------------------");\r
+ PrintAndLog("-------------------------------------------------------------");\r
+ PrintAndLog(" Safer key : %s", GetSaferStr(safer));\r
+ PrintAndLog(" reserved : %d", resv);\r
+ PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr));\r
+ PrintAndLog(" eXtended mode : %s", (extend) ? "Yes - Warning":"No");\r
+ PrintAndLog(" Modulation : %s", GetModulationStr(datamod));\r
+ PrintAndLog(" PSK clock frequency : %d", pskcf);\r
+ PrintAndLog(" AOR - Answer on Request : %s", (aor) ? "Yes":"No");\r
+ PrintAndLog(" OTP - One Time Pad : %s", (otp) ? "Yes - Warning":"No" );\r
+ PrintAndLog(" Max block : %d", maxblk);\r
+ PrintAndLog(" Password mode : %s", (pwd) ? "Yes":"No");\r
+ PrintAndLog(" Sequence Start Terminator : %s", (sst) ? "Yes":"No");\r
+ PrintAndLog(" Fast Write : %s", (fw) ? "Yes":"No");\r
+ PrintAndLog(" Inverse data : %s", (inv) ? "Yes":"No");\r
+ PrintAndLog(" POR-Delay : %s", (por) ? "Yes":"No");\r
+ PrintAndLog("-------------------------------------------------------------");\r
+ PrintAndLog(" Raw Data - Page 0");\r
+ PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+config.offset,32) );\r
+ PrintAndLog("-------------------------------------------------------------");\r
+ \r
+ return 0;\r
+}\r
+\r
+int CmdT55xxDump(const char *Cmd){\r
+\r
+ uint32_t password = 0;\r
+ bool override = false;\r
+ char cmdp = param_getchar(Cmd, 0); \r
+ if ( cmdp == 'h' || cmdp == 'H') return usage_t55xx_dump();\r
+\r
+ bool usepwd = ( strlen(Cmd) > 0); \r
+ if ( usepwd ){\r
+ password = param_get32ex(Cmd, 0, 0, 16);\r
+ if (param_getchar(Cmd, 1) =='o' )\r
+ override = true;\r
+ }\r
+ \r
+ printT5xxHeader(0);\r
+ for ( uint8_t i = 0; i < 8; ++i)\r
+ T55xxReadBlock(i, 0, usepwd, override, password);\r
+\r
+ printT5xxHeader(1);\r
+ for ( uint8_t i = 0; i < 4; i++)\r
+ T55xxReadBlock(i, 1, usepwd, override, password); \r
+\r
+ return 1;\r
+}\r
+\r
+int AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){\r
+ // arg0 bitmodes:\r
+ // bit0 = pwdmode\r
+ // bit1 = page to read from\r
+ uint8_t arg0 = (page<<1) | pwdmode;\r
+ UsbCommand c = {CMD_T55XX_READ_BLOCK, {arg0, block, password}};\r
+ \r
+ clearCommandBuffer();\r
+ SendCommand(&c);\r
+ if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r
+ PrintAndLog("command execution time out");\r
+ return 0;\r
+ }\r
+\r
+ uint8_t got[12000];\r
+ GetFromBigBuf(got,sizeof(got),0);\r
+ WaitForResponse(CMD_ACK,NULL);\r
+ setGraphBuf(got, sizeof(got));\r
+ return 1;\r
+}\r