]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cmdlft55xx.c
ADD: printConfiguration method for a nice printout of the selected configuration.
[proxmark3-svn] / client / cmdlft55xx.c
CommitLineData
54a942b0 1//-----------------------------------------------------------------------------\r
2//\r
3// This code is licensed to you under the terms of the GNU GPL, version 2 or,\r
4// at your option, any later version. See the LICENSE.txt file for the text of\r
5// the license.\r
6//-----------------------------------------------------------------------------\r
7// Low frequency T55xx commands\r
8//-----------------------------------------------------------------------------\r
9\r
10#include <stdio.h>\r
11#include <string.h>\r
12#include <inttypes.h>\r
54a942b0 13#include "proxmark3.h"\r
14#include "ui.h"\r
15#include "graph.h"\r
f38a1528 16#include "cmdmain.h"\r
54a942b0 17#include "cmdparser.h"\r
18#include "cmddata.h"\r
19#include "cmdlf.h"\r
20#include "cmdlft55xx.h"\r
f38a1528 21#include "util.h"\r
22#include "data.h"\r
c4e3b1b6 23#include "lfdemod.h"\r
83a42ef9 24#include "../common/crc.h"\r
54a942b0 25\r
8d0a3e87 26#define LF_TRACE_BUFF_SIZE 20000 // 32 x 32 x 10 (32 bit times numofblock (7), times clock skip..)\r
c6be64da 27#define LF_BITSSTREAM_LEN 1000 // more then 1000 bits shouldn't happend.. 8block * 4 bytes * 8bits = \r
54a942b0 28\r
71020824 29\r
30\r
31// Default configuration: ASK, not inversed.\r
33add187 32t55xx_conf_block_t config = { .modulation = 2, .inversed = FALSE, .block0 = 0x00};\r
83a42ef9 33\r
34int usage_t55xx_config(){\r
118bfa1b 35 PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1]");\r
83a42ef9 36 PrintAndLog("Options: ");\r
118bfa1b 37 PrintAndLog(" h This help");\r
38 PrintAndLog(" d <FSK|ASK|PSK|NZ|BI> Set demodulation FSK / ASK / PSK / NZ / Biphase");\r
39 PrintAndLog(" i [1] Inverse data signal, defaults to normal");\r
40 PrintAndLog("");\r
83a42ef9 41 PrintAndLog("Examples:");\r
118bfa1b 42 PrintAndLog(" lf t55xx config d FSK - FSK demodulation");\r
43 PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");\r
44 PrintAndLog("");\r
83a42ef9 45 return 0;\r
46}\r
68008fb5 47int usage_t55xx_read(){\r
48 PrintAndLog("Usage: lf t55xx read <block> <password>");\r
4ecde0e1 49 PrintAndLog(" <block>, block number to read. Between 0-7");\r
50 PrintAndLog(" <password>, OPTIONAL password (8 hex characters)");\r
51 PrintAndLog("");\r
118bfa1b 52 PrintAndLog("Examples:");\r
53 PrintAndLog(" lf t55xx read 0 - read data from block 0");\r
54 PrintAndLog(" lf t55xx read 0 feedbeef - read data from block 0 password feedbeef");\r
4ecde0e1 55 PrintAndLog("");\r
56 return 0;\r
57}\r
68008fb5 58int usage_t55xx_write(){\r
4ecde0e1 59 PrintAndLog("Usage: lf t55xx wr <block> <data> [password]");\r
60 PrintAndLog(" <block>, block number to read. Between 0-7");\r
61 PrintAndLog(" <data>, 4 bytes of data to write (8 hex characters)");\r
62 PrintAndLog(" [password], OPTIONAL password 4bytes (8 hex characters)");\r
63 PrintAndLog("");\r
118bfa1b 64 PrintAndLog("Examples:");\r
65 PrintAndLog(" lf t55xx wd 3 11223344 - write 11223344 to block 3");\r
66 PrintAndLog(" lf t55xx wd 3 11223344 feedbeef - write 11223344 to block 3 password feedbeef");\r
4ecde0e1 67 PrintAndLog("");\r
68 return 0;\r
69}\r
70int usage_t55xx_trace() {\r
118bfa1b 71 PrintAndLog("Usage: lf t55xx trace [1]");\r
4ecde0e1 72 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");\r
73 PrintAndLog("");\r
118bfa1b 74 PrintAndLog("Examples:");\r
75 PrintAndLog(" lf t55xx trace");\r
76 PrintAndLog(" lf t55xx trace 1");\r
4ecde0e1 77 PrintAndLog("");\r
78 return 0;\r
79}\r
80int usage_t55xx_info() {\r
118bfa1b 81 PrintAndLog("Usage: lf t55xx info [1]");\r
4ecde0e1 82 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");\r
83 PrintAndLog("");\r
118bfa1b 84 PrintAndLog("Examples:");\r
85 PrintAndLog(" lf t55xx info");\r
86 PrintAndLog(" lf t55xx info 1");\r
4ecde0e1 87 PrintAndLog("");\r
88 return 0;\r
89}\r
4ecde0e1 90int usage_t55xx_dump(){\r
91 PrintAndLog("Usage: lf t55xx dump <password>");\r
118bfa1b 92 PrintAndLog(" <password>, OPTIONAL password 4bytes (8 hex symbols)");\r
4ecde0e1 93 PrintAndLog("");\r
118bfa1b 94 PrintAndLog("Examples:");\r
95 PrintAndLog(" lf t55xx dump");\r
96 PrintAndLog(" lf t55xx dump feedbeef");\r
4ecde0e1 97 PrintAndLog("");\r
98 return 0;\r
99}\r
33add187 100int usage_t55xx_detect(){\r
101 PrintAndLog("Usage: lf t55xx detect");\r
102 PrintAndLog("");\r
103 PrintAndLog("Examples:");\r
104 PrintAndLog(" lf t55xx detect");\r
105 PrintAndLog(" lf t55xx detect 1");\r
106 PrintAndLog("");\r
107 return 0;\r
108}\r
0310364d 109\r
4ecde0e1 110static int CmdHelp(const char *Cmd);\r
c4e3b1b6 111\r
83a42ef9 112int CmdT55xxSetConfig(const char *Cmd){\r
118bfa1b 113\r
d8c927bc 114 int len = 0;\r
115 int foundModulation = 2;\r
116 bool inverse = FALSE;\r
118bfa1b 117 bool errors = FALSE;\r
118 uint8_t cmdp = 0;\r
119 char modulation[4] = {0x00};\r
83a42ef9 120 \r
118bfa1b 121 while(param_getchar(Cmd, cmdp) != 0x00 && !errors)\r
83a42ef9 122 {\r
118bfa1b 123 switch(param_getchar(Cmd, cmdp))\r
124 {\r
125 case 'h':\r
126 case 'H':\r
127 return usage_t55xx_config();\r
128 case 'd':\r
129 len = param_getstr(Cmd, cmdp+1, modulation);\r
130 cmdp+= len+1;\r
131 //FSK|ASK|PSK|NZ|BI\r
132 if ( strcmp(modulation, "FSK" ) == 0)\r
d8c927bc 133 foundModulation = 1;\r
118bfa1b 134 else if ( strcmp(modulation, "ASK" ) == 0)\r
d8c927bc 135 foundModulation = 2;\r
118bfa1b 136 else if ( strcmp(modulation, "PSK" ) == 0)\r
d8c927bc 137 foundModulation = 3;\r
118bfa1b 138 else if ( strcmp(modulation, "NZ" ) == 0)\r
d8c927bc 139 foundModulation = 4;\r
118bfa1b 140 else if ( strcmp(modulation, "BI" ) == 0)\r
d8c927bc 141 foundModulation = 5;\r
118bfa1b 142 else {\r
143 PrintAndLog("Unknown modulation '%s'", modulation);\r
144 errors = TRUE;\r
145 }\r
146 break;\r
147 case 'i':\r
148 inverse = param_getchar(Cmd,cmdp+1) == '1';\r
149 cmdp+=2;\r
150 break;\r
151 default:\r
152 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
153 errors = TRUE;\r
154 break;\r
155 }\r
83a42ef9 156 }\r
118bfa1b 157 // No args\r
158 if (cmdp == 0) {\r
71020824 159 printConfiguration( config );\r
118bfa1b 160 return 0;\r
161 }\r
162 //Validations\r
163 if (errors)\r
164 return usage_t55xx_config();\r
165 \r
d8c927bc 166 config.modulation = foundModulation;\r
118bfa1b 167 config.inversed = inverse;\r
168 config.block0 = 0;\r
83a42ef9 169 return 0;\r
170}\r
83a42ef9 171\r
33add187 172int CmdT55xxReadBlock(const char *Cmd)\r
54a942b0 173{\r
c6be64da 174 int block = -1;\r
4ecde0e1 175 int password = 0xFFFFFFFF; //default to blank Block 7\r
83a42ef9 176\r
4ecde0e1 177 char cmdp = param_getchar(Cmd, 0);\r
83a42ef9 178 if (cmdp == 'h' || cmdp == 'H')\r
179 return usage_t55xx_read();\r
54a942b0 180\r
4ecde0e1 181 int res = sscanf(Cmd, "%d %x", &block, &password);\r
54a942b0 182\r
7b40affb 183 if ( res < 1 || res > 2 )\r
184 return usage_t55xx_read();\r
185\r
4ecde0e1 186 \r
187 if ((block < 0) | (block > 7)) {\r
b44e5233 188 PrintAndLog("Block must be between 0 and 7");\r
189 return 1;\r
4ecde0e1 190 } \r
54a942b0 191\r
4ecde0e1 192 UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, block, 0}};\r
193 c.d.asBytes[0] = 0x0; \r
54a942b0 194\r
4ecde0e1 195 //Password mode\r
196 if ( res == 2 ) {\r
197 c.arg[2] = password;\r
198 c.d.asBytes[0] = 0x1; \r
c4e3b1b6 199 }\r
54a942b0 200\r
b44e5233 201 SendCommand(&c);\r
68008fb5 202 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r
c4e3b1b6 203 PrintAndLog("command execution time out");\r
385f3987 204 return 2;\r
c4e3b1b6 205 }\r
f38a1528 206 \r
68008fb5 207 uint8_t got[12000];\r
208 GetFromBigBuf(got,sizeof(got),0);\r
209 WaitForResponse(CMD_ACK,NULL);\r
68008fb5 210 setGraphBuf(got, 12000);\r
83a42ef9 211\r
33add187 212 DecodeT55xxBlock();\r
33add187 213 printT55xxBlock("");\r
33add187 214 return 0;\r
215}\r
216\r
217void DecodeT55xxBlock(){\r
218 \r
219 char buf[6] = {0x00};\r
220 char *cmdStr = buf;\r
221\r
222 // use the configuration\r
223 switch( config.modulation ){\r
224 case 1:\r
225 sprintf(cmdStr,"0 %d", config.inversed );\r
226 FSKrawDemod(cmdStr, FALSE);\r
227 break;\r
228 case 2:\r
229 sprintf(cmdStr,"0 %d 1", config.inversed );\r
230 ASKmanDemod(cmdStr, FALSE, FALSE);\r
33add187 231 break;\r
232 case 3:\r
233 sprintf(cmdStr,"0 %d 1", config.inversed );\r
234 PSKDemod(cmdStr, FALSE);\r
235 break;\r
236 case 4:\r
237 sprintf(cmdStr,"0 %d 1", config.inversed );\r
238 NRZrawDemod(cmdStr, FALSE);\r
239 break;\r
240 case 5:\r
241 //BiphaseRawDecode("0",FALSE);\r
242 break;\r
243 default:\r
244 return;\r
245 }\r
246}\r
247\r
248int CmdT55xxDetect(const char *Cmd){\r
249 char cmdp = param_getchar(Cmd, 0);\r
250 if (cmdp == 'h' || cmdp == 'H')\r
251 return usage_t55xx_detect();\r
252 \r
253 // read block 0, Page 0. Configuration.\r
254 UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, 0, 0}};\r
255 c.d.asBytes[0] = 0x0; \r
256\r
257 //Password mode\r
258 // if ( res == 2 ) {\r
259 // c.arg[2] = password;\r
260 // c.d.asBytes[0] = 0x1; \r
261 // }\r
262\r
263 SendCommand(&c);\r
264 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r
265 PrintAndLog("command execution time out");\r
266 return FALSE;\r
83a42ef9 267 }\r
68008fb5 268 \r
33add187 269 uint8_t got[12000];\r
270 GetFromBigBuf(got,sizeof(got),0);\r
271 WaitForResponse(CMD_ACK,NULL);\r
272 setGraphBuf(got, 12000);\r
273 \r
7b40affb 274 if ( !tryDetectModulation() ){\r
275 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");\r
276 }\r
33add187 277 return 0;\r
278}\r
279\r
280// detect configuration?\r
281bool tryDetectModulation(){\r
282 \r
283 uint8_t hits = 0;\r
7b40affb 284 t55xx_conf_block_t tests[10];\r
33add187 285 \r
33add187 286 if (GetFskClock("", FALSE, FALSE)){ \r
33add187 287 if ( FSKrawDemod("0 0", FALSE) && test()){\r
7b40affb 288 tests[hits].modulation = 1;\r
289 tests[hits].inversed = 0;\r
33add187 290 ++hits;\r
291 }\r
292 if ( FSKrawDemod("0 1", FALSE) && test()) {\r
7b40affb 293 tests[hits].modulation = 1;\r
294 tests[hits].inversed = 1;\r
33add187 295 ++hits;\r
7b40affb 296 }\r
83a42ef9 297 } else {\r
33add187 298 if ( ASKmanDemod("0 0 1", FALSE, FALSE) && test()) {\r
7b40affb 299 tests[hits].modulation = 2;\r
300 tests[hits].inversed = 0;\r
33add187 301 ++hits;\r
7b40affb 302 }\r
33add187 303\r
304 if ( ASKmanDemod("0 1 1", FALSE, FALSE) && test()) {\r
7b40affb 305 tests[hits].modulation = 2;\r
306 tests[hits].inversed = 1;\r
33add187 307 ++hits;\r
7b40affb 308 }\r
83a42ef9 309 \r
33add187 310 if ( NRZrawDemod("0 0 1", FALSE) && test()) {\r
7b40affb 311 tests[hits].modulation = 3;\r
312 tests[hits].inversed = 0;\r
33add187 313 ++hits;\r
314 }\r
83a42ef9 315\r
33add187 316 if ( NRZrawDemod("0 1 1", FALSE) && test()) {\r
7b40affb 317 tests[hits].modulation = 3;\r
318 tests[hits].inversed = 1;\r
33add187 319 ++hits;\r
7b40affb 320 }\r
118bfa1b 321 \r
33add187 322 if ( PSKDemod("0 0 1", FALSE) && test()) {\r
7b40affb 323 tests[hits].modulation = 4;\r
324 tests[hits].inversed = 0;\r
33add187 325 ++hits;\r
326 }\r
118bfa1b 327 \r
33add187 328 if ( PSKDemod("0 1 1", FALSE) && test()) {\r
7b40affb 329 tests[++hits].modulation = 4;\r
330 tests[hits].inversed = 1;\r
33add187 331 ++hits;\r
332 }\r
333 //PSK2?\r
334 // if (!BiphaseRawDecode("0",FALSE) && test()) {\r
7b40affb 335 // tests[++hits].modulation = 5;\r
336 // tests[hits].inversed = 0;\r
33add187 337 //}\r
338 // if (!BiphaseRawDecode("1",FALSE) && test()) {\r
7b40affb 339 // tests[++hits].modulation = 5;\r
340 // tests[hits].inversed = 1;\r
33add187 341 // }\r
342 } \r
7b40affb 343 if ( hits == 1) {\r
7b40affb 344 config.modulation = tests[0].modulation;\r
345 config.inversed = tests[0].inversed;\r
71020824 346 printConfiguration( config );\r
33add187 347 return TRUE;\r
7b40affb 348 }\r
33add187 349 \r
7b40affb 350 if ( hits > 1) {\r
33add187 351 PrintAndLog("Found [%d] possible matches for modulation.",hits);\r
7b40affb 352 for(int i=0; i<hits; ++i){\r
71020824 353 printConfiguration( tests[i] );\r
7b40affb 354 }\r
355 }\r
33add187 356 return FALSE;\r
83a42ef9 357}\r
33add187 358\r
3e4811c8 359bool test(){\r
360\r
361 if ( !DemodBufferLen) \r
362 return false;\r
363 \r
364 uint8_t si = 1;\r
365 uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; \r
366 uint8_t resv = PackBits(si, 7, DemodBuffer); si += 7+3;\r
367 uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1;\r
368\r
369 //PrintAndLog("test: %X %X %X ", safer, resv, extend);\r
370 \r
371 // 2nibble must be zeroed.\r
372 if ( resv > 0x00) return FALSE;\r
373\r
374 if ( safer == 0x6 || safer == 0x9){\r
375 if ( extend == 0x00)\r
376 return TRUE;\r
377 }\r
378 if ( resv== 0x00) return TRUE;\r
379 return FALSE;\r
380}\r
83a42ef9 381\r
33add187 382void printT55xxBlock(const char *demodStr){\r
68008fb5 383 \r
83a42ef9 384 uint32_t blockData = 0;\r
385 uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0x00};\r
386 \r
68008fb5 387 if ( !DemodBufferLen) \r
83a42ef9 388 return;\r
4e7af352 389 \r
83a42ef9 390 int i =0;\r
68008fb5 391 for (;i<DemodBufferLen;++i)\r
392 bits[i]=DemodBuffer[i];\r
385f3987 393 \r
0310364d 394 blockData = PackBits(1, 32, bits);\r
33add187 395 PrintAndLog("0x%08X %s [%s]", blockData, sprint_bin(bits+1,32), demodStr);\r
54a942b0 396}\r
397\r
71020824 398void printConfiguration( t55xx_conf_block_t b){\r
399 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b.modulation) );\r
400 PrintAndLog("Inverted : %s", (b.inversed) ? "Yes" : "No" );\r
401 PrintAndLog("Block0 : %08X", b.block0);\r
402 PrintAndLog("");\r
403}\r
404\r
4e7af352 405/*\r
406FSK1 / FSK1a\r
407size = fskdemod(dest, size, 32, 0, 8, 10); // fsk1 RF/32 \r
408size = fskdemod(dest, size, 32, 1, 8, 10); // fsk1a RF/32 \r
409\r
410FSK2 / FSK2a\r
411size = fskdemod(dest, size, 32, 0, 10, 8); // fsk2 RF/32 \r
412size = fskdemod(dest, size, 32, 1, 10, 8); // fsk2a RF/32 \r
413size = fskdemod(dest, size, 50, 1, 10, 8); // fsk2a RF/50 \r
414size = fskdemod(dest, size, 64, 1, 10, 8); // FSK2a RF/64 \r
415\r
416PSK1\r
417errCnt = pskRawDemod(bits, &bitlen, 32, 0);\r
418*/\r
33add187 419int CmdT55xxWriteBlock(const char *Cmd)\r
54a942b0 420{\r
4ecde0e1 421 int block = 8; //default to invalid block\r
422 int data = 0xFFFFFFFF; //default to blank Block \r
423 int password = 0xFFFFFFFF; //default to blank Block 7\r
424 \r
425 char cmdp = param_getchar(Cmd, 0);\r
426 if (cmdp == 'h' || cmdp == 'H') {\r
68008fb5 427 usage_t55xx_write();\r
4ecde0e1 428 return 0;\r
429 }\r
430 \r
431 int res = sscanf(Cmd, "%d %x %x",&block, &data, &password);\r
432 \r
433 if ( res < 2 || res > 3) {\r
68008fb5 434 usage_t55xx_write();\r
4ecde0e1 435 return 1;\r
436 }\r
54a942b0 437\r
4ecde0e1 438 if (block > 7) {\r
b44e5233 439 PrintAndLog("Block must be between 0 and 7");\r
440 return 1;\r
f38a1528 441 }\r
4ecde0e1 442 \r
443 UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}};\r
444 c.d.asBytes[0] = 0x0; \r
54a942b0 445\r
68008fb5 446 PrintAndLog("Writing to T55x7");\r
447 PrintAndLog("block : %d", block);\r
448 PrintAndLog("data : 0x%08X", data);\r
449\r
450 //Password mode\r
451 if (res == 3) {\r
4ecde0e1 452 c.arg[2] = password;\r
453 c.d.asBytes[0] = 0x1; \r
68008fb5 454 PrintAndLog("pwd : 0x%08X", password);\r
4ecde0e1 455 }\r
4ecde0e1 456 SendCommand(&c);\r
457 return 0;\r
54a942b0 458}\r
459\r
33add187 460int CmdT55xxReadTrace(const char *Cmd)\r
54a942b0 461{\r
0310364d 462 char cmdp = param_getchar(Cmd, 0);\r
463 \r
7b40affb 464 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') \r
465 return usage_t55xx_trace();\r
f38a1528 466\r
fbceacc5 467 if ( strlen(Cmd)==0){\r
c4e3b1b6 468 \r
fbceacc5 469 UsbCommand c = {CMD_T55XX_READ_TRACE, {0, 0, 0}};\r
470 SendCommand(&c);\r
68008fb5 471 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r
472 PrintAndLog("command execution time out");\r
473 return 1;\r
474 }\r
7b40affb 475\r
476 uint8_t got[12000];\r
477 GetFromBigBuf(got,sizeof(got),0);\r
478 WaitForResponse(CMD_ACK,NULL);\r
479 setGraphBuf(got, 12000);\r
f38a1528 480 }\r
f38a1528 481 \r
7b40affb 482 DecodeT55xxBlock();\r
483\r
484 if ( !DemodBufferLen) \r
83a42ef9 485 return 2;\r
486 \r
f6c18637 487 RepaintGraphWindow();\r
b44e5233 488\r
f6c18637 489 uint8_t si = 5;\r
7b40affb 490 uint32_t bl0 = PackBits(si, 32, DemodBuffer);\r
491 uint32_t bl1 = PackBits(si+32, 32, DemodBuffer);\r
492 \r
493 uint32_t acl = PackBits(si, 8, DemodBuffer); si += 8;\r
494 uint32_t mfc = PackBits(si, 8, DemodBuffer); si += 8;\r
495 uint32_t cid = PackBits(si, 5, DemodBuffer); si += 5;\r
496 uint32_t icr = PackBits(si, 3, DemodBuffer); si += 3;\r
497 uint32_t year = PackBits(si, 4, DemodBuffer); si += 4;\r
498 uint32_t quarter = PackBits(si, 2, DemodBuffer); si += 2;\r
499 uint32_t lotid = PackBits(si, 12, DemodBuffer); si += 12;\r
500 uint32_t wafer = PackBits(si, 5, DemodBuffer); si += 5;\r
501 uint32_t dw = PackBits(si, 15, DemodBuffer); \r
502 \r
503 year += 2000;\r
f6c18637 504 \r
505 PrintAndLog("");\r
506 PrintAndLog("-- T55xx Trace Information ----------------------------------");\r
507 PrintAndLog("-------------------------------------------------------------");\r
508 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl, acl);\r
509 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d)", mfc, mfc);\r
510 PrintAndLog(" CID : 0x%02X (%d)", cid, cid);\r
511 PrintAndLog(" ICR IC Revision : %d",icr );\r
512 PrintAndLog(" Manufactured");\r
7b40affb 513 PrintAndLog(" Year/Quarter : %d/%d",year, quarter );\r
77376577 514 PrintAndLog(" Lot ID : %d", lotid );\r
f6c18637 515 PrintAndLog(" Wafer number : %d", wafer);\r
516 PrintAndLog(" Die Number : %d", dw);\r
517 PrintAndLog("-------------------------------------------------------------");\r
77376577 518 PrintAndLog(" Raw Data - Page 1");\r
7b40affb 519 PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+5,32) );\r
520 PrintAndLog(" Block 0 : 0x%08X %s", bl1, sprint_bin(DemodBuffer+37,32) );\r
f6c18637 521 PrintAndLog("-------------------------------------------------------------");\r
522 /*\r
523 TRACE - BLOCK O\r
524 Bits Definition HEX\r
525 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0 \r
526 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation\r
527 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2 \r
528 22-24 ICR IC revision\r
529 25-28 YEAR (BCD encoded) 9 (= 2009)\r
530 29-30 QUARTER 1,2,3,4 \r
77376577 531 31-32 LOT ID\r
f6c18637 532 \r
533 TRACE - BLOCK 1\r
77376577 534 1-12 LOT ID \r
f6c18637 535 13-17 Wafer number\r
536 18-32 DW, die number sequential\r
537 */\r
538 \r
539 return 0;\r
540}\r
f38a1528 541\r
33add187 542int CmdT55xxInfo(const char *Cmd){\r
f6c18637 543 /*\r
544 Page 0 Block 0 Configuration data.\r
545 Normal mode\r
546 Extended mode\r
547 */\r
fbceacc5 548 char cmdp = param_getchar(Cmd, 0);\r
549\r
7b40affb 550 if (cmdp == 'h' || cmdp == 'H')\r
83a42ef9 551 return usage_t55xx_info();\r
7b40affb 552 \r
553 if (strlen(Cmd)==0){\r
554 \r
555 // read block 0, Page 0. Configuration.\r
556 UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, 0, 0}};\r
557 c.d.asBytes[0] = 0x0; \r
558\r
559 //Password mode\r
560 // if ( res == 2 ) {\r
561 // c.arg[2] = password;\r
562 // c.d.asBytes[0] = 0x1; \r
563 // }\r
564\r
565 SendCommand(&c);\r
566 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r
567 PrintAndLog("command execution time out");\r
568 return 1;\r
569 }\r
fbceacc5 570\r
7b40affb 571 uint8_t got[12000];\r
572 GetFromBigBuf(got,sizeof(got),0);\r
573 WaitForResponse(CMD_ACK,NULL);\r
574 setGraphBuf(got, 12000);\r
575 }\r
83a42ef9 576 \r
7b40affb 577 DecodeT55xxBlock();\r
8d0a3e87 578\r
7b40affb 579 if ( !DemodBufferLen) \r
580 return 2;\r
581 \r
582 \r
83a42ef9 583 uint8_t si = 1;\r
7b40affb 584 uint32_t bl0 = PackBits(si, 32, DemodBuffer);\r
585 \r
586 uint32_t safer = PackBits(si, 4, DemodBuffer); si += 4; \r
587 uint32_t resv = PackBits(si, 7, DemodBuffer); si += 7;\r
588 uint32_t dbr = PackBits(si, 3, DemodBuffer); si += 3;\r
589 uint32_t extend = PackBits(si, 1, DemodBuffer); si += 1;\r
590 uint32_t datamod = PackBits(si, 5, DemodBuffer); si += 5;\r
591 uint32_t pskcf = PackBits(si, 2, DemodBuffer); si += 2;\r
592 uint32_t aor = PackBits(si, 1, DemodBuffer); si += 1; \r
593 uint32_t otp = PackBits(si, 1, DemodBuffer); si += 1; \r
594 uint32_t maxblk = PackBits(si, 3, DemodBuffer); si += 3;\r
595 uint32_t pwd = PackBits(si, 1, DemodBuffer); si += 1; \r
596 uint32_t sst = PackBits(si, 1, DemodBuffer); si += 1; \r
597 uint32_t fw = PackBits(si, 1, DemodBuffer); si += 1;\r
598 uint32_t inv = PackBits(si, 1, DemodBuffer); si += 1; \r
599 uint32_t por = PackBits(si, 1, DemodBuffer); si += 1;\r
b44e5233 600 \r
f6c18637 601 PrintAndLog("");\r
99a71418 602 PrintAndLog("-- T55xx Configuration & Tag Information --------------------");\r
f6c18637 603 PrintAndLog("-------------------------------------------------------------");\r
604 PrintAndLog(" Safer key : %s", GetSaferStr(safer));\r
605 PrintAndLog(" reserved : %d", resv);\r
606 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr));\r
607 PrintAndLog(" eXtended mode : %s", (extend) ? "Yes - Warning":"No");\r
3e4811c8 608 PrintAndLog(" Modulation : %s", GetModulationStr(datamod));\r
f6c18637 609 PrintAndLog(" PSK clock freq : %d", pskcf);\r
610 PrintAndLog(" AOR - Answer on Request : %s", (aor) ? "Yes":"No");\r
611 PrintAndLog(" OTP - One Time Pad : %s", (otp) ? "Yes - Warning":"No" );\r
612 PrintAndLog(" Max block : %d", maxblk);\r
613 PrintAndLog(" Password mode : %s", (pwd) ? "Yes":"No");\r
614 PrintAndLog(" Sequence Start Terminator : %s", (sst) ? "Yes":"No");\r
3e4811c8 615 PrintAndLog(" Fast Write : %s", (fw) ? "Yes":"No");\r
f6c18637 616 PrintAndLog(" Inverse data : %s", (inv) ? "Yes":"No");\r
617 PrintAndLog(" POR-Delay : %s", (por) ? "Yes":"No");\r
618 PrintAndLog("-------------------------------------------------------------");\r
77376577 619 PrintAndLog(" Raw Data - Page 0");\r
7b40affb 620 PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+5,32) );\r
f6c18637 621 PrintAndLog("-------------------------------------------------------------");\r
622 \r
623 return 0;\r
624}\r
625\r
33add187 626int CmdT55xxDump(const char *Cmd){\r
77376577 627\r
4ecde0e1 628 char s[20] = {0x00};\r
77376577 629 uint8_t pwd[4] = {0x00};\r
54a942b0 630\r
4ecde0e1 631 char cmdp = param_getchar(Cmd, 0);\r
149aeada 632 if ( cmdp == 'h' || cmdp == 'H') {\r
4ecde0e1 633 usage_t55xx_dump();\r
77376577 634 return 0;\r
635 }\r
4ecde0e1 636\r
637 bool hasPwd = ( strlen(Cmd) > 0); \r
77376577 638 if ( hasPwd ){\r
2ae8a312 639 if (param_gethex(Cmd, 0, pwd, 8)) {\r
640 PrintAndLog("password must include 8 HEX symbols");\r
c4e3b1b6 641 return 1;\r
77376577 642 }\r
643 }\r
a501c82b 644 \r
77376577 645 for ( int i = 0; i <8; ++i){\r
149aeada 646 memset(s,0,sizeof(s));\r
77376577 647 if ( hasPwd ) {\r
c6be64da 648 sprintf(s,"%d %02x%02x%02x%02x", i, pwd[0],pwd[1],pwd[2],pwd[3]);\r
77376577 649 } else {\r
650 sprintf(s,"%d", i);\r
77376577 651 }\r
33add187 652 CmdT55xxReadBlock(s);\r
77376577 653 }\r
654 return 0;\r
655}\r
656\r
f6c18637 657char * GetBitRateStr(uint32_t id){\r
658 static char buf[40];\r
659 char *retStr = buf;\r
660 switch (id){\r
661 case 0: \r
662 sprintf(retStr,"%d - RF/8",id);\r
663 break;\r
664 case 1:\r
665 sprintf(retStr,"%d - RF/16",id);\r
666 break;\r
667 case 2: \r
668 sprintf(retStr,"%d - RF/32",id);\r
669 break;\r
670 case 3:\r
671 sprintf(retStr,"%d - RF/40",id);\r
672 break;\r
673 case 4:\r
674 sprintf(retStr,"%d - RF/50",id);\r
675 break;\r
676 case 5:\r
677 sprintf(retStr,"%d - RF/64",id);\r
678 break;\r
679 case 6:\r
680 sprintf(retStr,"%d - RF/100",id);\r
681 break;\r
682 case 7:\r
683 sprintf(retStr,"%d - RF/128",id);\r
684 break;\r
685 default:\r
686 sprintf(retStr,"%d - (Unknown)",id);\r
687 break;\r
688 }\r
689\r
690 return buf;\r
691}\r
692\r
f6c18637 693char * GetSaferStr(uint32_t id){\r
694 static char buf[40];\r
695 char *retStr = buf;\r
696 \r
697 sprintf(retStr,"%d",id);\r
698 if (id == 6) {\r
3e4811c8 699 sprintf(retStr,"%d - passwd",id);\r
f6c18637 700 }\r
701 if (id == 9 ){\r
3e4811c8 702 sprintf(retStr,"%d - testmode",id);\r
f6c18637 703 }\r
704 \r
705 return buf;\r
706}\r
707char * GetModulationStr( uint32_t id){\r
708 static char buf[40];\r
709 char *retStr = buf;\r
710 \r
711 switch (id){\r
712 case 0: \r
7bd30f12 713 sprintf(retStr,"%d - DIRECT (ASK/NRZ)",id);\r
f6c18637 714 break;\r
715 case 1:\r
716 sprintf(retStr,"%d - PSK 1 phase change when input changes",id);\r
717 break;\r
718 case 2: \r
719 sprintf(retStr,"%d - PSK 2 phase change on bitclk if input high",id);\r
720 break;\r
721 case 3:\r
722 sprintf(retStr,"%d - PSK 3 phase change on rising edge of input",id);\r
723 break;\r
724 case 4:\r
725 sprintf(retStr,"%d - FSK 1 RF/8 RF/5",id);\r
726 break;\r
727 case 5:\r
728 sprintf(retStr,"%d - FSK 2 RF/8 RF/10",id);\r
729 break;\r
730 case 6:\r
731 sprintf(retStr,"%d - FSK 1a RF/5 RF/8",id);\r
732 break;\r
733 case 7:\r
734 sprintf(retStr,"%d - FSK 2a RF/10 RF/8",id);\r
735 break;\r
736 case 8:\r
737 sprintf(retStr,"%d - Manschester",id);\r
738 break;\r
739 case 16:\r
740 sprintf(retStr,"%d - Biphase",id);\r
741 break;\r
742 case 17:\r
743 sprintf(retStr,"%d - Reserved",id);\r
744 break;\r
745 default:\r
746 sprintf(retStr,"0x%02X (Unknown)",id);\r
747 break;\r
748 }\r
749 return buf;\r
750}\r
751\r
71020824 752char * GetSelectedModulationStr( uint8_t id){\r
753\r
754 static char buf[16];\r
755 char *retStr = buf;\r
756 \r
757 switch (id){\r
758 case 1:\r
759 sprintf(retStr,"FSK (%d)",id);\r
760 break;\r
761 case 2: \r
762 sprintf(retStr,"ASK (%d)",id);\r
763 break;\r
764 case 3:\r
765 sprintf(retStr,"DIRECT/NRZ (%d)",id);\r
766 break;\r
767 case 4:\r
768 sprintf(retStr,"PSK (%d)",id);\r
769 break;\r
770 case 5:\r
771 sprintf(retStr,"BIPHASE (%d)",id);\r
772 break;\r
773 default:\r
774 sprintf(retStr,"(Unknown)");\r
775 break;\r
776 }\r
777 return buf;\r
778}\r
779\r
f6c18637 780uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits){\r
781 \r
782 int i = start;\r
783 int j = len-1;\r
3bc3598e 784 if (len > 32) {\r
785 return 0;\r
786 }\r
f6c18637 787 uint32_t tmp = 0;\r
788 for (; j >= 0; --j, ++i){\r
789 tmp |= bits[i] << j;\r
790 }\r
791 return tmp;\r
54a942b0 792}\r
793\r
794static command_t CommandTable[] =\r
795{\r
83a42ef9 796 {"help", CmdHelp, 1, "This help"},\r
797 {"config", CmdT55xxSetConfig, 1, "Set T55XX config for modulation, inversed data"},\r
33add187 798 {"detect", CmdT55xxDetect, 0, "Try detecting the tag modulation from reading the configuration block."},\r
799 {"read", CmdT55xxReadBlock, 0, "<block> [password] -- Read T55xx block data (page 0) [optional password]"},\r
800 {"write", CmdT55xxWriteBlock,0, "<block> <data> [password] -- Write T55xx block data (page 0) [optional password]"},\r
801 {"trace", CmdT55xxReadTrace, 0, "[1] Show T55xx traceability data (page 1/ blk 0-1)"},\r
802 {"info", CmdT55xxInfo, 0, "[1] Show T55xx configuration data (page 0/ blk 0)"},\r
803 {"dump", CmdT55xxDump, 0, "[password] Dump T55xx card block 0-7. [optional password]"},\r
54a942b0 804 {NULL, NULL, 0, NULL}\r
805};\r
806\r
807int CmdLFT55XX(const char *Cmd)\r
808{\r
809 CmdsParse(CommandTable, Cmd);\r
810 return 0;\r
811}\r
812\r
813int CmdHelp(const char *Cmd)\r
814{\r
815 CmdsHelp(CommandTable);\r
816 return 0;\r
817}\r
Impressum, Datenschutz