]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cmdlft55xx.c
ADD: LF T55XX CONFIG, is almost there, Usage: lf t55xx config [d <demodulation...
[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
118bfa1b 40t55xx_conf_block_t config = { .modulation = 0, .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
0310364d 108\r
4ecde0e1 109static int CmdHelp(const char *Cmd);\r
c4e3b1b6 110\r
83a42ef9 111int CmdT55xxSetConfig(const char *Cmd){\r
118bfa1b 112\r
113 int len;\r
114 bool inverse;\r
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
131 len = 1;\r
132 else if ( strcmp(modulation, "ASK" ) == 0)\r
133 len = 2;\r
134 else if ( strcmp(modulation, "PSK" ) == 0)\r
135 len = 3;\r
136 else if ( strcmp(modulation, "NZ" ) == 0)\r
137 len = 4;\r
138 else if ( strcmp(modulation, "BI" ) == 0)\r
139 len = 5;\r
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
157 PrintAndLog("Modulation: %d", config.modulation);\r
158 PrintAndLog("Invert : %d", config.inversed);\r
159 PrintAndLog("Block0 : %08X", config.block0);\r
160 return 0;\r
161 }\r
162 //Validations\r
163 if (errors)\r
164 return usage_t55xx_config();\r
165 \r
166 config.modulation = len;\r
167 config.inversed = inverse;\r
168 config.block0 = 0;\r
83a42ef9 169 return 0;\r
170}\r
83a42ef9 171// detect configuration?\r
172\r
54a942b0 173int CmdReadBlk(const char *Cmd)\r
174{\r
c6be64da 175 int block = -1;\r
4ecde0e1 176 int password = 0xFFFFFFFF; //default to blank Block 7\r
83a42ef9 177\r
4ecde0e1 178 char cmdp = param_getchar(Cmd, 0);\r
83a42ef9 179 if (cmdp == 'h' || cmdp == 'H')\r
180 return usage_t55xx_read();\r
54a942b0 181\r
4ecde0e1 182 int res = sscanf(Cmd, "%d %x", &block, &password);\r
54a942b0 183\r
4ecde0e1 184 if ( res < 1 || res > 2 ){\r
68008fb5 185 usage_t55xx_read();\r
4ecde0e1 186 return 1;\r
187 }\r
188 \r
189 if ((block < 0) | (block > 7)) {\r
b44e5233 190 PrintAndLog("Block must be between 0 and 7");\r
191 return 1;\r
4ecde0e1 192 } \r
54a942b0 193\r
4ecde0e1 194 UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, block, 0}};\r
195 c.d.asBytes[0] = 0x0; \r
54a942b0 196\r
4ecde0e1 197 //Password mode\r
198 if ( res == 2 ) {\r
199 c.arg[2] = password;\r
200 c.d.asBytes[0] = 0x1; \r
c4e3b1b6 201 }\r
54a942b0 202\r
b44e5233 203 SendCommand(&c);\r
68008fb5 204 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r
c4e3b1b6 205 PrintAndLog("command execution time out");\r
385f3987 206 return 2;\r
c4e3b1b6 207 }\r
f38a1528 208 \r
68008fb5 209 uint8_t got[12000];\r
210 GetFromBigBuf(got,sizeof(got),0);\r
211 WaitForResponse(CMD_ACK,NULL);\r
a501c82b 212\r
68008fb5 213 setGraphBuf(got, 12000);\r
83a42ef9 214\r
215 if (block == 0){\r
118bfa1b 216 // try a detection. \r
83a42ef9 217 }\r
68008fb5 218 \r
83a42ef9 219 if (CmdDetectClockRate("f")){ //wave is almost certainly FSK\r
83a42ef9 220 // FSK\r
118bfa1b 221 if ( FSKrawDemod("0 0", FALSE))\r
83a42ef9 222 printT55xx("FSK");\r
223 // FSK inverted\r
118bfa1b 224 if ( FSKrawDemod("0 1", FALSE)) \r
83a42ef9 225 printT55xx("FSK inv");\r
226 } else {\r
227 // ASK/MAN (autoclock, normal, maxerrors 1)\r
228 if ( ASKmanDemod("0 0 1", FALSE, FALSE) )\r
229 printT55xx("ASK/MAN");\r
230 \r
231 // ASK/MAN (autoclock, inverted, maxerrors 1)\r
232 if ( ASKmanDemod("0 1 1", FALSE, FALSE) )\r
233 printT55xx("ASK/MAN Inv");\r
234\r
235 // NZR (autoclock, normal, maxerrors 1)\r
236 if ( NRZrawDemod("0 0 1", FALSE) )\r
237 printT55xx("NZR");\r
238 // NZR (autoclock, inverted, maxerrors 1)\r
239 if ( NRZrawDemod("0 1 1", FALSE) )\r
240 printT55xx("NZR inv");\r
241 \r
242 // PSK (autoclock, normal, maxerrors 1)\r
243 if (!PSKDemod("0 0 1", FALSE))\r
244 printT55xx("PSK");\r
245\r
246 // PSK (autoclock, inverted, maxerrors 1)\r
247 if (!PSKDemod("0 1 1", FALSE))\r
248 printT55xx("PSK inv");\r
118bfa1b 249 \r
250 //PSK2?\r
251 \r
252 // if (!BiphaseRawDecode("0",FALSE))\r
253 // printT55xx("BIPHASE");\r
254 \r
255 // if (!BiphaseRawDecode("1",FALSE))\r
256 // printT55xx("BIPHASE inv");\r
83a42ef9 257 }\r
258 return 0;\r
259}\r
260\r
261void printT55xx(const char *demodStr){\r
68008fb5 262 \r
83a42ef9 263 uint32_t blockData = 0;\r
264 uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0x00};\r
265 \r
68008fb5 266 if ( !DemodBufferLen) \r
83a42ef9 267 return;\r
4e7af352 268 \r
83a42ef9 269 int i =0;\r
68008fb5 270 for (;i<DemodBufferLen;++i)\r
271 bits[i]=DemodBuffer[i];\r
385f3987 272 \r
0310364d 273 blockData = PackBits(1, 32, bits);\r
83a42ef9 274 PrintAndLog("0x%08X %s [%s]", blockData, sprint_bin(bits+1,32), demodStr );\r
54a942b0 275}\r
276\r
4e7af352 277/*\r
278FSK1 / FSK1a\r
279size = fskdemod(dest, size, 32, 0, 8, 10); // fsk1 RF/32 \r
280size = fskdemod(dest, size, 32, 1, 8, 10); // fsk1a RF/32 \r
281\r
282FSK2 / FSK2a\r
283size = fskdemod(dest, size, 32, 0, 10, 8); // fsk2 RF/32 \r
284size = fskdemod(dest, size, 32, 1, 10, 8); // fsk2a RF/32 \r
285size = fskdemod(dest, size, 50, 1, 10, 8); // fsk2a RF/50 \r
286size = fskdemod(dest, size, 64, 1, 10, 8); // FSK2a RF/64 \r
287\r
288PSK1\r
289errCnt = pskRawDemod(bits, &bitlen, 32, 0);\r
290*/\r
54a942b0 291int CmdWriteBlk(const char *Cmd)\r
54a942b0 292{\r
4ecde0e1 293 int block = 8; //default to invalid block\r
294 int data = 0xFFFFFFFF; //default to blank Block \r
295 int password = 0xFFFFFFFF; //default to blank Block 7\r
296 \r
297 char cmdp = param_getchar(Cmd, 0);\r
298 if (cmdp == 'h' || cmdp == 'H') {\r
68008fb5 299 usage_t55xx_write();\r
4ecde0e1 300 return 0;\r
301 }\r
302 \r
303 int res = sscanf(Cmd, "%d %x %x",&block, &data, &password);\r
304 \r
305 if ( res < 2 || res > 3) {\r
68008fb5 306 usage_t55xx_write();\r
4ecde0e1 307 return 1;\r
308 }\r
54a942b0 309\r
4ecde0e1 310 if (block > 7) {\r
b44e5233 311 PrintAndLog("Block must be between 0 and 7");\r
312 return 1;\r
f38a1528 313 }\r
4ecde0e1 314 \r
315 UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}};\r
316 c.d.asBytes[0] = 0x0; \r
54a942b0 317\r
68008fb5 318 PrintAndLog("Writing to T55x7");\r
319 PrintAndLog("block : %d", block);\r
320 PrintAndLog("data : 0x%08X", data);\r
321\r
322 //Password mode\r
323 if (res == 3) {\r
4ecde0e1 324 c.arg[2] = password;\r
325 c.d.asBytes[0] = 0x1; \r
68008fb5 326 PrintAndLog("pwd : 0x%08X", password);\r
4ecde0e1 327 }\r
4ecde0e1 328 SendCommand(&c);\r
329 return 0;\r
54a942b0 330}\r
331\r
332int CmdReadTrace(const char *Cmd)\r
333{\r
0310364d 334 uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0x00};\r
f38a1528 335\r
0310364d 336 char cmdp = param_getchar(Cmd, 0);\r
337 \r
fbceacc5 338 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') {\r
4ecde0e1 339 usage_t55xx_trace();\r
fbceacc5 340 return 0;\r
341 }\r
f38a1528 342\r
fbceacc5 343 if ( strlen(Cmd)==0){\r
c4e3b1b6 344 \r
fbceacc5 345 UsbCommand c = {CMD_T55XX_READ_TRACE, {0, 0, 0}};\r
346 SendCommand(&c);\r
68008fb5 347 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r
348 PrintAndLog("command execution time out");\r
349 return 1;\r
350 }\r
351 //darn\r
352 //CmdSamples("12000");\r
f38a1528 353 }\r
f38a1528 354 \r
83a42ef9 355 size_t bitlen = getFromGraphBuf(bits);\r
356 if ( bitlen == 0 )\r
357 return 2;\r
358 \r
f6c18637 359 RepaintGraphWindow();\r
b44e5233 360\r
f6c18637 361 uint8_t si = 5;\r
0310364d 362 uint32_t bl0 = PackBits(si, 32, bits);\r
363 uint32_t bl1 = PackBits(si+32, 32, bits);\r
f6c18637 364 \r
0310364d 365 uint32_t acl = PackBits(si, 8, bits); si += 8;\r
366 uint32_t mfc = PackBits(si, 8, bits); si += 8;\r
367 uint32_t cid = PackBits(si, 5, bits); si += 5;\r
368 uint32_t icr = PackBits(si, 3, bits); si += 3;\r
369 uint32_t year = PackBits(si, 4, bits); si += 4;\r
370 uint32_t quarter = PackBits(si, 2, bits); si += 2;\r
371 uint32_t lotid = PackBits(si, 12, bits); si += 12;\r
372 uint32_t wafer = PackBits(si, 5, bits); si += 5;\r
373 uint32_t dw = PackBits(si, 15, bits); \r
f6c18637 374 \r
375 PrintAndLog("");\r
376 PrintAndLog("-- T55xx Trace Information ----------------------------------");\r
377 PrintAndLog("-------------------------------------------------------------");\r
378 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl, acl);\r
379 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d)", mfc, mfc);\r
380 PrintAndLog(" CID : 0x%02X (%d)", cid, cid);\r
381 PrintAndLog(" ICR IC Revision : %d",icr );\r
382 PrintAndLog(" Manufactured");\r
383 PrintAndLog(" Year/Quarter : %d/%d",2000+year, quarter );\r
77376577 384 PrintAndLog(" Lot ID : %d", lotid );\r
f6c18637 385 PrintAndLog(" Wafer number : %d", wafer);\r
386 PrintAndLog(" Die Number : %d", dw);\r
387 PrintAndLog("-------------------------------------------------------------");\r
77376577 388 PrintAndLog(" Raw Data - Page 1");\r
0310364d 389 PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(bits+5,32) );\r
390 PrintAndLog(" Block 0 : 0x%08X %s", bl1, sprint_bin(bits+37,32) );\r
f6c18637 391 PrintAndLog("-------------------------------------------------------------");\r
392 /*\r
393 TRACE - BLOCK O\r
394 Bits Definition HEX\r
395 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0 \r
396 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation\r
397 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2 \r
398 22-24 ICR IC revision\r
399 25-28 YEAR (BCD encoded) 9 (= 2009)\r
400 29-30 QUARTER 1,2,3,4 \r
77376577 401 31-32 LOT ID\r
f6c18637 402 \r
403 TRACE - BLOCK 1\r
77376577 404 1-12 LOT ID \r
f6c18637 405 13-17 Wafer number\r
406 18-32 DW, die number sequential\r
407 */\r
408 \r
409 return 0;\r
410}\r
f38a1528 411\r
f6c18637 412int CmdInfo(const char *Cmd){\r
413 /*\r
414 Page 0 Block 0 Configuration data.\r
415 Normal mode\r
416 Extended mode\r
417 */\r
fbceacc5 418 char cmdp = param_getchar(Cmd, 0);\r
419\r
83a42ef9 420 if (cmdp == 'h' || cmdp == 'H') {\r
421 return usage_t55xx_info();\r
4ecde0e1 422 } else {\r
fbceacc5 423 CmdReadBlk("0");\r
081151ea 424 } \r
fbceacc5 425\r
83a42ef9 426 // config\r
427 \r
c6be64da 428 uint8_t bits[LF_BITSSTREAM_LEN] = {0x00};\r
8d0a3e87 429\r
83a42ef9 430 uint8_t si = 1;\r
8d0a3e87 431 uint32_t bl0 = PackBits(si, 32, bits);\r
f6c18637 432 \r
8d0a3e87 433 uint32_t safer = PackBits(si, 4, bits); si += 4; \r
434 uint32_t resv = PackBits(si, 7, bits); si += 7;\r
435 uint32_t dbr = PackBits(si, 3, bits); si += 3;\r
436 uint32_t extend = PackBits(si, 1, bits); si += 1;\r
437 uint32_t datamodulation = PackBits(si, 5, bits); si += 5;\r
438 uint32_t pskcf = PackBits(si, 2, bits); si += 2;\r
439 uint32_t aor = PackBits(si, 1, bits); si += 1; \r
440 uint32_t otp = PackBits(si, 1, bits); si += 1; \r
441 uint32_t maxblk = PackBits(si, 3, bits); si += 3;\r
442 uint32_t pwd = PackBits(si, 1, bits); si += 1; \r
443 uint32_t sst = PackBits(si, 1, bits); si += 1; \r
444 uint32_t fw = PackBits(si, 1, bits); si += 1;\r
445 uint32_t inv = PackBits(si, 1, bits); si += 1; \r
446 uint32_t por = PackBits(si, 1, bits); si += 1;\r
b44e5233 447 \r
f6c18637 448 PrintAndLog("");\r
99a71418 449 PrintAndLog("-- T55xx Configuration & Tag Information --------------------");\r
f6c18637 450 PrintAndLog("-------------------------------------------------------------");\r
451 PrintAndLog(" Safer key : %s", GetSaferStr(safer));\r
452 PrintAndLog(" reserved : %d", resv);\r
453 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr));\r
454 PrintAndLog(" eXtended mode : %s", (extend) ? "Yes - Warning":"No");\r
455 PrintAndLog(" Modulation : %s", GetModulationStr(datamodulation) );\r
456 PrintAndLog(" PSK clock freq : %d", pskcf);\r
457 PrintAndLog(" AOR - Answer on Request : %s", (aor) ? "Yes":"No");\r
458 PrintAndLog(" OTP - One Time Pad : %s", (otp) ? "Yes - Warning":"No" );\r
459 PrintAndLog(" Max block : %d", maxblk);\r
460 PrintAndLog(" Password mode : %s", (pwd) ? "Yes":"No");\r
461 PrintAndLog(" Sequence Start Terminator : %s", (sst) ? "Yes":"No");\r
462 PrintAndLog(" Fast Write : %s", (fw) ? "Yes":"No");\r
463 PrintAndLog(" Inverse data : %s", (inv) ? "Yes":"No");\r
464 PrintAndLog(" POR-Delay : %s", (por) ? "Yes":"No");\r
465 PrintAndLog("-------------------------------------------------------------");\r
77376577 466 PrintAndLog(" Raw Data - Page 0");\r
8d0a3e87 467 PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(bits+5,32) );\r
f6c18637 468 PrintAndLog("-------------------------------------------------------------");\r
469 \r
470 return 0;\r
471}\r
472\r
77376577 473int CmdDump(const char *Cmd){\r
474\r
4ecde0e1 475 char s[20] = {0x00};\r
77376577 476 uint8_t pwd[4] = {0x00};\r
54a942b0 477\r
4ecde0e1 478 char cmdp = param_getchar(Cmd, 0);\r
149aeada 479 if ( cmdp == 'h' || cmdp == 'H') {\r
4ecde0e1 480 usage_t55xx_dump();\r
77376577 481 return 0;\r
482 }\r
4ecde0e1 483\r
484 bool hasPwd = ( strlen(Cmd) > 0); \r
77376577 485 if ( hasPwd ){\r
2ae8a312 486 if (param_gethex(Cmd, 0, pwd, 8)) {\r
487 PrintAndLog("password must include 8 HEX symbols");\r
c4e3b1b6 488 return 1;\r
77376577 489 }\r
490 }\r
a501c82b 491 \r
77376577 492 for ( int i = 0; i <8; ++i){\r
149aeada 493 memset(s,0,sizeof(s));\r
77376577 494 if ( hasPwd ) {\r
c6be64da 495 sprintf(s,"%d %02x%02x%02x%02x", i, pwd[0],pwd[1],pwd[2],pwd[3]);\r
77376577 496 } else {\r
497 sprintf(s,"%d", i);\r
77376577 498 }\r
4ecde0e1 499 CmdReadBlk(s);\r
77376577 500 }\r
501 return 0;\r
502}\r
503\r
f6c18637 504char * GetBitRateStr(uint32_t id){\r
505 static char buf[40];\r
506 char *retStr = buf;\r
507 switch (id){\r
508 case 0: \r
509 sprintf(retStr,"%d - RF/8",id);\r
510 break;\r
511 case 1:\r
512 sprintf(retStr,"%d - RF/16",id);\r
513 break;\r
514 case 2: \r
515 sprintf(retStr,"%d - RF/32",id);\r
516 break;\r
517 case 3:\r
518 sprintf(retStr,"%d - RF/40",id);\r
519 break;\r
520 case 4:\r
521 sprintf(retStr,"%d - RF/50",id);\r
522 break;\r
523 case 5:\r
524 sprintf(retStr,"%d - RF/64",id);\r
525 break;\r
526 case 6:\r
527 sprintf(retStr,"%d - RF/100",id);\r
528 break;\r
529 case 7:\r
530 sprintf(retStr,"%d - RF/128",id);\r
531 break;\r
532 default:\r
533 sprintf(retStr,"%d - (Unknown)",id);\r
534 break;\r
535 }\r
536\r
537 return buf;\r
538}\r
539\r
f6c18637 540char * GetSaferStr(uint32_t id){\r
541 static char buf[40];\r
542 char *retStr = buf;\r
543 \r
544 sprintf(retStr,"%d",id);\r
545 if (id == 6) {\r
546 sprintf(retStr,"%d - pasdwd",id);\r
547 }\r
548 if (id == 9 ){\r
549 sprintf(retStr,"%d - testmode ",id);\r
550 }\r
551 \r
552 return buf;\r
553}\r
554char * GetModulationStr( uint32_t id){\r
555 static char buf[40];\r
556 char *retStr = buf;\r
557 \r
558 switch (id){\r
559 case 0: \r
7bd30f12 560 sprintf(retStr,"%d - DIRECT (ASK/NRZ)",id);\r
f6c18637 561 break;\r
562 case 1:\r
563 sprintf(retStr,"%d - PSK 1 phase change when input changes",id);\r
564 break;\r
565 case 2: \r
566 sprintf(retStr,"%d - PSK 2 phase change on bitclk if input high",id);\r
567 break;\r
568 case 3:\r
569 sprintf(retStr,"%d - PSK 3 phase change on rising edge of input",id);\r
570 break;\r
571 case 4:\r
572 sprintf(retStr,"%d - FSK 1 RF/8 RF/5",id);\r
573 break;\r
574 case 5:\r
575 sprintf(retStr,"%d - FSK 2 RF/8 RF/10",id);\r
576 break;\r
577 case 6:\r
578 sprintf(retStr,"%d - FSK 1a RF/5 RF/8",id);\r
579 break;\r
580 case 7:\r
581 sprintf(retStr,"%d - FSK 2a RF/10 RF/8",id);\r
582 break;\r
583 case 8:\r
584 sprintf(retStr,"%d - Manschester",id);\r
585 break;\r
586 case 16:\r
587 sprintf(retStr,"%d - Biphase",id);\r
588 break;\r
589 case 17:\r
590 sprintf(retStr,"%d - Reserved",id);\r
591 break;\r
592 default:\r
593 sprintf(retStr,"0x%02X (Unknown)",id);\r
594 break;\r
595 }\r
596 return buf;\r
597}\r
598\r
f6c18637 599uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits){\r
600 \r
601 int i = start;\r
602 int j = len-1;\r
3bc3598e 603 if (len > 32) {\r
604 return 0;\r
605 }\r
f6c18637 606 uint32_t tmp = 0;\r
607 for (; j >= 0; --j, ++i){\r
608 tmp |= bits[i] << j;\r
609 }\r
610 return tmp;\r
54a942b0 611}\r
612\r
613static command_t CommandTable[] =\r
614{\r
83a42ef9 615 {"help", CmdHelp, 1, "This help"},\r
616 {"config", CmdT55xxSetConfig, 1, "Set T55XX config for modulation, inversed data"},\r
617 {"read", CmdReadBlk, 0, "<block> [password] -- Read T55xx block data (page 0) [optional password]"},\r
618 {"write", CmdWriteBlk, 0, "<block> <data> [password] -- Write T55xx block data (page 0) [optional password]"},\r
619 {"trace", CmdReadTrace, 0, "[1] Read T55xx traceability data (page 1/ blk 0-1)"},\r
620 {"info", CmdInfo, 0, "[1] Read T55xx configuration data (page 0/ blk 0)"},\r
621 {"dump", CmdDump, 0, "[password] Dump T55xx card block 0-7. [optional password]"},\r
54a942b0 622 {NULL, NULL, 0, NULL}\r
623};\r
624\r
625int CmdLFT55XX(const char *Cmd)\r
626{\r
627 CmdsParse(CommandTable, Cmd);\r
628 return 0;\r
629}\r
630\r
631int CmdHelp(const char *Cmd)\r
632{\r
633 CmdsHelp(CommandTable);\r
634 return 0;\r
635}\r
Impressum, Datenschutz