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