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