X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/ec09716a65c29dffaedcc232c0b6414bc7e0c598..9c09e006d667665f7e81eaddfd977a55442854ff:/client/cmdlft55xx.c?ds=inline diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 34c8e1ef..a75d2fd3 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "proxmark3.h" #include "ui.h" #include "graph.h" @@ -255,7 +256,7 @@ int CmdT55xxReadBlock(const char *Cmd) { bool DecodeT55xxBlock(){ - char buf[8] = {0x00}; + char buf[9] = {0x00}; char *cmdStr = buf; int ans = 0; uint8_t bitRate[8] = {8,16,32,40,50,64,100,128}; @@ -270,27 +271,17 @@ bool DecodeT55xxBlock(){ ans = FSKrawDemod(cmdStr, FALSE); break; case DEMOD_FSK1: + case DEMOD_FSK1a: sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 ); CmdLtrim(cmdStr); - sprintf(cmdStr,"%d 1 8 5", bitRate[config.bitrate] ); - ans = FSKrawDemod(cmdStr, FALSE); - break; - case DEMOD_FSK1a: - sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 ); - CmdLtrim(cmdStr); - sprintf(cmdStr,"%d 0 8 5", bitRate[config.bitrate] ); + sprintf(cmdStr,"%d %d 8 5", bitRate[config.bitrate], config.inverted ); ans = FSKrawDemod(cmdStr, FALSE); break; case DEMOD_FSK2: - sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 ); - CmdLtrim(cmdStr); - sprintf(cmdStr,"%d 0 10 8", bitRate[config.bitrate] ); - ans = FSKrawDemod(cmdStr, FALSE); - break; case DEMOD_FSK2a: sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 ); CmdLtrim(cmdStr); - sprintf(cmdStr,"%d 1 10 8", bitRate[config.bitrate] ); + sprintf(cmdStr,"%d %d 10 8", bitRate[config.bitrate], config.inverted ); ans = FSKrawDemod(cmdStr, FALSE); break; case DEMOD_ASK: @@ -302,7 +293,7 @@ bool DecodeT55xxBlock(){ ans = PSKDemod(cmdStr, FALSE); break; case DEMOD_PSK2: - sprintf(cmdStr,"%d 1", bitRate[config.bitrate] ); + sprintf(cmdStr,"%d %d 1", bitRate[config.bitrate], config.inverted ); ans = PSKDemod(cmdStr, FALSE); psk1TOpsk2(DemodBuffer, DemodBufferLen); break; @@ -316,11 +307,8 @@ bool DecodeT55xxBlock(){ ans = NRZrawDemod(cmdStr, FALSE); break; case DEMOD_BI: - sprintf(cmdStr,"0 %d 0 1", bitRate[config.bitrate] ); - ans = ASKbiphaseDemod(cmdStr, FALSE); - break; case DEMOD_BIa: - sprintf(cmdStr,"0 %d 1 1", bitRate[config.bitrate] ); + sprintf(cmdStr,"0 %d %d 0", bitRate[config.bitrate], config.inverted ); ans = ASKbiphaseDemod(cmdStr, FALSE); break; default: @@ -581,6 +569,7 @@ bool testBitRate(uint8_t readRate, uint8_t mod){ } break; case DEMOD_BI: + case DEMOD_BIa: detRate = GetAskClock("",FALSE, FALSE); if (expected[readRate] == detRate) { config.bitrate = readRate; @@ -599,7 +588,7 @@ bool test(uint8_t mode, uint8_t *offset){ uint8_t si = 0; for (uint8_t idx = 0; idx < 64; idx++){ si = idx; - if ( PackBits(si, 32, DemodBuffer) == 0x00 ) continue; + if ( PackBits(si, 32, DemodBuffer) == 0x00 ) continue; // configuration block with only zeros is impossible. uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key uint8_t resv = PackBits(si, 4, DemodBuffer); si += 4; //was 7 & +=7+3 //should be only 4 bits if extended mode @@ -631,7 +620,7 @@ bool test(uint8_t mode, uint8_t *offset){ return FALSE; } -void printT55xxBlock(const char *demodStr){ +void printT55xxBlock(const char *blockNum){ uint8_t i = config.offset; uint8_t endpos = 32 + i; @@ -649,7 +638,7 @@ void printT55xxBlock(const char *demodStr){ bits[i - config.offset]=DemodBuffer[i]; blockData = PackBits(0, 32, bits); - PrintAndLog("0x%08X %s [%s]", blockData, sprint_bin(bits,32), demodStr); + PrintAndLog("[%s] 0x%08X %s", blockNum, blockData, sprint_bin(bits,32)); } int special(const char *Cmd) { @@ -740,6 +729,7 @@ int CmdT55xxReadTrace(const char *Cmd) uint8_t si = config.offset+repeat; uint32_t bl0 = PackBits(si, 32, DemodBuffer); uint32_t bl1 = PackBits(si+32, 32, DemodBuffer); + // uint32_t bl2 = PackBits(si+64, 32, DemodBuffer); uint32_t acl = PackBits(si, 8, DemodBuffer); si += 8; uint32_t mfc = PackBits(si, 8, DemodBuffer); si += 8; @@ -747,13 +737,23 @@ int CmdT55xxReadTrace(const char *Cmd) uint32_t icr = PackBits(si, 3, DemodBuffer); si += 3; uint32_t year = PackBits(si, 4, DemodBuffer); si += 4; uint32_t quarter = PackBits(si, 2, DemodBuffer); si += 2; - uint32_t lotid = PackBits(si, 12, DemodBuffer); si += 12; + uint32_t lotid = PackBits(si, 14, DemodBuffer); si += 14; uint32_t wafer = PackBits(si, 5, DemodBuffer); si += 5; uint32_t dw = PackBits(si, 15, DemodBuffer); - year += 2000; - PrintAndLog(""); + time_t t = time(NULL); + struct tm tm = *localtime(&t); + if ( year > tm.tm_year-110) + year += 2000; + else + year += 2010; + + if ( acl != 0xE0 ) { + PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. "); + return 1; + } + PrintAndLog("-- T55xx Trace Information ----------------------------------"); PrintAndLog("-------------------------------------------------------------"); PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl, acl); @@ -761,7 +761,7 @@ int CmdT55xxReadTrace(const char *Cmd) PrintAndLog(" CID : 0x%02X (%d) - %s", cid, cid, GetModelStrFromCID(cid)); PrintAndLog(" ICR IC Revision : %d",icr ); PrintAndLog(" Manufactured"); - PrintAndLog(" Year/Quarter : %d/%d",year, quarter ); + PrintAndLog(" Year/Quarter : 20?%d/%d",year, quarter); PrintAndLog(" Lot ID : %d", lotid ); PrintAndLog(" Wafer number : %d", wafer); PrintAndLog(" Die Number : %d", dw); @@ -769,10 +769,10 @@ int CmdT55xxReadTrace(const char *Cmd) PrintAndLog(" Raw Data - Page 1"); PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+config.offset+repeat,32) ); PrintAndLog(" Block 1 : 0x%08X %s", bl1, sprint_bin(DemodBuffer+config.offset+repeat+32,32) ); + //PrintAndLog(" Block 2 : 0x%08X %s", bl2, sprint_bin(DemodBuffer+config.offset+repeat+64,32) ); PrintAndLog("-------------------------------------------------------------"); - if ( acl != 0xE0 ) - PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. "); + /* TRACE - BLOCK O Bits Definition HEX @@ -919,35 +919,35 @@ int AquireData( uint8_t block ){ } char * GetBitRateStr(uint32_t id){ - static char buf[40]; + static char buf[20]; char *retStr = buf; switch (id){ case 0: - sprintf(retStr,"%d - RF/8",id); + snprintf(retStr,sizeof(buf),"%d - RF/8",id); break; case 1: - sprintf(retStr,"%d - RF/16",id); + snprintf(retStr,sizeof(buf),"%d - RF/16",id); break; case 2: - sprintf(retStr,"%d - RF/32",id); + snprintf(retStr,sizeof(buf),"%d - RF/32",id); break; case 3: - sprintf(retStr,"%d - RF/40",id); + snprintf(retStr,sizeof(buf),"%d - RF/40",id); break; case 4: - sprintf(retStr,"%d - RF/50",id); + snprintf(retStr,sizeof(buf),"%d - RF/50",id); break; case 5: - sprintf(retStr,"%d - RF/64",id); + snprintf(retStr,sizeof(buf),"%d - RF/64",id); break; case 6: - sprintf(retStr,"%d - RF/100",id); + snprintf(retStr,sizeof(buf),"%d - RF/100",id); break; case 7: - sprintf(retStr,"%d - RF/128",id); + snprintf(retStr,sizeof(buf),"%d - RF/128",id); break; default: - sprintf(retStr,"%d - (Unknown)",id); + snprintf(retStr,sizeof(buf),"%d - (Unknown)",id); break; } @@ -955,62 +955,63 @@ char * GetBitRateStr(uint32_t id){ } char * GetSaferStr(uint32_t id){ - static char buf[40]; + static char buf[20]; char *retStr = buf; - sprintf(retStr,"%d",id); + snprintf(retStr,sizeof(buf),"%d",id); if (id == 6) { - sprintf(retStr,"%d - passwd",id); + snprintf(retStr,sizeof(buf),"%d - passwd",id); } if (id == 9 ){ - sprintf(retStr,"%d - testmode",id); + snprintf(retStr,sizeof(buf),"%d - testmode",id); } return buf; } + char * GetModulationStr( uint32_t id){ - static char buf[40]; + static char buf[60]; char *retStr = buf; switch (id){ case 0: - sprintf(retStr,"%d - DIRECT (ASK/NRZ)",id); + snprintf(retStr,sizeof(buf),"%d - DIRECT (ASK/NRZ)",id); break; case 1: - sprintf(retStr,"%d - PSK 1 phase change when input changes",id); + snprintf(retStr,sizeof(buf),"%d - PSK 1 phase change when input changes",id); break; case 2: - sprintf(retStr,"%d - PSK 2 phase change on bitclk if input high",id); + snprintf(retStr,sizeof(buf),"%d - PSK 2 phase change on bitclk if input high",id); break; case 3: - sprintf(retStr,"%d - PSK 3 phase change on rising edge of input",id); + snprintf(retStr,sizeof(buf),"%d - PSK 3 phase change on rising edge of input",id); break; case 4: - sprintf(retStr,"%d - FSK 1 RF/8 RF/5",id); + snprintf(retStr,sizeof(buf),"%d - FSK 1 RF/8 RF/5",id); break; case 5: - sprintf(retStr,"%d - FSK 2 RF/8 RF/10",id); + snprintf(retStr,sizeof(buf),"%d - FSK 2 RF/8 RF/10",id); break; case 6: - sprintf(retStr,"%d - FSK 1a RF/5 RF/8",id); + snprintf(retStr,sizeof(buf),"%d - FSK 1a RF/5 RF/8",id); break; case 7: - sprintf(retStr,"%d - FSK 2a RF/10 RF/8",id); + snprintf(retStr,sizeof(buf),"%d - FSK 2a RF/10 RF/8",id); break; case 8: - sprintf(retStr,"%d - Manschester",id); + snprintf(retStr,sizeof(buf),"%d - Manschester",id); break; case 16: - sprintf(retStr,"%d - Biphase",id); + snprintf(retStr,sizeof(buf),"%d - Biphase",id); break; case 0x18: - sprintf(retStr,"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id); + snprintf(retStr,sizeof(buf),"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id); break; case 17: - sprintf(retStr,"%d - Reserved",id); + snprintf(retStr,sizeof(buf),"%d - Reserved",id); break; default: - sprintf(retStr,"0x%02X (Unknown)",id); + snprintf(retStr,sizeof(buf),"0x%02X (Unknown)",id); break; } return buf; @@ -1021,55 +1022,55 @@ char * GetModelStrFromCID(uint32_t cid){ static char buf[10]; char *retStr = buf; - if (cid == 1) sprintf(retStr,"ATA5577M1"); - if (cid == 2) sprintf(retStr,"ATA5577M2"); + if (cid == 1) snprintf(retStr, sizeof(buf),"ATA5577M1"); + if (cid == 2) snprintf(retStr, sizeof(buf),"ATA5577M2"); return buf; } char * GetSelectedModulationStr( uint8_t id){ - static char buf[16]; + static char buf[20]; char *retStr = buf; switch (id){ case DEMOD_FSK: - sprintf(retStr,"FSK"); + snprintf(retStr,sizeof(buf),"FSK"); break; case DEMOD_FSK1: - sprintf(retStr,"FSK1"); + snprintf(retStr,sizeof(buf),"FSK1"); break; case DEMOD_FSK1a: - sprintf(retStr,"FSK1a"); + snprintf(retStr,sizeof(buf),"FSK1a"); break; case DEMOD_FSK2: - sprintf(retStr,"FSK2"); + snprintf(retStr,sizeof(buf),"FSK2"); break; case DEMOD_FSK2a: - sprintf(retStr,"FSK2a"); + snprintf(retStr,sizeof(buf),"FSK2a"); break; case DEMOD_ASK: - sprintf(retStr,"ASK"); + snprintf(retStr,sizeof(buf),"ASK"); break; case DEMOD_NRZ: - sprintf(retStr,"DIRECT/NRZ"); + snprintf(retStr,sizeof(buf),"DIRECT/NRZ"); break; case DEMOD_PSK1: - sprintf(retStr,"PSK1"); + snprintf(retStr,sizeof(buf),"PSK1"); break; case DEMOD_PSK2: - sprintf(retStr,"PSK2"); + snprintf(retStr,sizeof(buf),"PSK2"); break; case DEMOD_PSK3: - sprintf(retStr,"PSK3"); + snprintf(retStr,sizeof(buf),"PSK3"); break; case DEMOD_BI: - sprintf(retStr,"BIPHASE"); + snprintf(retStr,sizeof(buf),"BIPHASE"); break; case DEMOD_BIa: - sprintf(retStr,"BIPHASEa - (CDP)"); + snprintf(retStr,sizeof(buf),"BIPHASEa - (CDP)"); break; default: - sprintf(retStr,"(Unknown)"); + snprintf(retStr,sizeof(buf),"(Unknown)"); break; } return buf;