]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/cmdlft55xx.c
CHG: minor fixes to some tnp luascripts
[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
13d77ef9 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
13d77ef9 21#include "util.h"\r
22#include "data.h"\r
23#include "lfdemod.h"\r
24#include "../common/crc.h"\r
25#include "../common/iso14443crc.h"\r
26#include "cmdhf14a.h"\r
27\r
28#define CONFIGURATION_BLOCK 0x00\r
29#define TRACE_BLOCK 0x01\r
30\r
31// Default configuration\r
32t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = FALSE, .offset = 0x00, .block0 = 0x00};\r
33\r
34int usage_t55xx_config(){\r
35 PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>]");\r
36 PrintAndLog("Options: ");\r
37 PrintAndLog(" h This help");\r
38 PrintAndLog(" b <8|16|32|40|50|64|100|128> Set bitrate");\r
39 PrintAndLog(" d <FSK|FSK1|FSK1a|FSK2|FSK2a|ASK|PSK1|PSK2|NZ|BI|BIa> Set demodulation FSK / ASK / PSK / NZ / Biphase / Biphase A");\r
40 PrintAndLog(" i [1] Invert data signal, defaults to normal");\r
41 PrintAndLog(" o [offset] Set offset, where data should start decode in bitstream");\r
42 PrintAndLog("");\r
43 PrintAndLog("Examples:");\r
44 PrintAndLog(" lf t55xx config d FSK - FSK demodulation");\r
45 PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");\r
46 PrintAndLog(" lf t55xx config d FSK i 1 o 3 - FSK demodulation, inverse data, offset=3,start from position 3 to decode data");\r
47 PrintAndLog("");\r
48 return 0;\r
49}\r
50int usage_t55xx_read(){\r
51 PrintAndLog("Usage: lf t55xx read <block> <password>");\r
52 PrintAndLog(" <block>, block number to read. Between 0-7");\r
53 PrintAndLog(" <password>, OPTIONAL password (8 hex characters)");\r
54 PrintAndLog("");\r
55 PrintAndLog("Examples:");\r
56 PrintAndLog(" lf t55xx read 0 - read data from block 0");\r
57 PrintAndLog(" lf t55xx read 0 feedbeef - read data from block 0 password feedbeef");\r
58 PrintAndLog("");\r
59 return 0;\r
60}\r
61int usage_t55xx_write(){\r
62 PrintAndLog("Usage: lf t55xx wr <block> <data> [password]");\r
63 PrintAndLog(" <block>, block number to read. Between 0-7");\r
64 PrintAndLog(" <data>, 4 bytes of data to write (8 hex characters)");\r
65 PrintAndLog(" [password], OPTIONAL password 4bytes (8 hex characters)");\r
66 PrintAndLog("");\r
67 PrintAndLog("Examples:");\r
68 PrintAndLog(" lf t55xx wd 3 11223344 - write 11223344 to block 3");\r
69 PrintAndLog(" lf t55xx wd 3 11223344 feedbeef - write 11223344 to block 3 password feedbeef");\r
70 PrintAndLog("");\r
71 return 0;\r
72}\r
73int usage_t55xx_trace() {\r
74 PrintAndLog("Usage: lf t55xx trace [1]");\r
75 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");\r
76 PrintAndLog("");\r
77 PrintAndLog("Examples:");\r
78 PrintAndLog(" lf t55xx trace");\r
79 PrintAndLog(" lf t55xx trace 1");\r
80 PrintAndLog("");\r
81 return 0;\r
82}\r
83int usage_t55xx_info() {\r
84 PrintAndLog("Usage: lf t55xx info [1]");\r
85 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");\r
86 PrintAndLog("");\r
87 PrintAndLog("Examples:");\r
88 PrintAndLog(" lf t55xx info");\r
89 PrintAndLog(" lf t55xx info 1");\r
90 PrintAndLog("");\r
91 return 0;\r
92}\r
93int usage_t55xx_dump(){\r
94 PrintAndLog("Usage: lf t55xx dump <password>");\r
95 PrintAndLog(" <password>, OPTIONAL password 4bytes (8 hex symbols)");\r
96 PrintAndLog("");\r
97 PrintAndLog("Examples:");\r
98 PrintAndLog(" lf t55xx dump");\r
99 PrintAndLog(" lf t55xx dump feedbeef");\r
100 PrintAndLog("");\r
101 return 0;\r
102}\r
103int usage_t55xx_detect(){\r
104 PrintAndLog("Usage: lf t55xx detect");\r
105 PrintAndLog("");\r
106 PrintAndLog("Examples:");\r
107 PrintAndLog(" lf t55xx detect");\r
108 PrintAndLog(" lf t55xx detect 1");\r
109 PrintAndLog("");\r
110 return 0;\r
111}\r
54a942b0 112\r
113static int CmdHelp(const char *Cmd);\r
114\r
13d77ef9 115int CmdT55xxSetConfig(const char *Cmd) {\r
54a942b0 116\r
13d77ef9 117 uint8_t offset = 0;\r
118 bool errors = FALSE;\r
119 uint8_t cmdp = 0;\r
120 char modulation[5] = {0x00};\r
121 char tmp = 0x00;\r
122 uint8_t bitRate = 0;\r
123 uint8_t rates[9] = {8,16,32,40,50,64,100,128,0};\r
124 while(param_getchar(Cmd, cmdp) != 0x00 && !errors)\r
125 {\r
126 tmp = param_getchar(Cmd, cmdp);\r
127 switch(tmp)\r
128 {\r
129 case 'h':\r
130 case 'H':\r
131 return usage_t55xx_config();\r
132 case 'b':\r
133 errors |= param_getdec(Cmd, cmdp+1, &bitRate);\r
134 if ( !errors){\r
135 uint8_t i = 0;\r
136 for (; i < 9; i++){\r
137 if (rates[i]==bitRate) {\r
138 config.bitrate = i;\r
139 break;\r
140 }\r
141 }\r
142 if (i==9) errors = TRUE;\r
143 }\r
144 cmdp+=2;\r
145 break;\r
146 case 'd':\r
147 param_getstr(Cmd, cmdp+1, modulation);\r
148 cmdp += 2;\r
54a942b0 149\r
13d77ef9 150 if ( strcmp(modulation, "FSK" ) == 0)\r
151 config.modulation = DEMOD_FSK;\r
152 else if ( strcmp(modulation, "FSK1" ) == 0)\r
153 config.modulation = DEMOD_FSK1;\r
154 else if ( strcmp(modulation, "FSK1a" ) == 0)\r
155 config.modulation = DEMOD_FSK1a;\r
156 else if ( strcmp(modulation, "FSK2" ) == 0)\r
157 config.modulation = DEMOD_FSK2;\r
158 else if ( strcmp(modulation, "FSK2a" ) == 0)\r
159 config.modulation = DEMOD_FSK2a;\r
160 else if ( strcmp(modulation, "ASK" ) == 0)\r
161 config.modulation = DEMOD_ASK;\r
162 else if ( strcmp(modulation, "NRZ" ) == 0)\r
163 config.modulation = DEMOD_NRZ;\r
164 else if ( strcmp(modulation, "PSK1" ) == 0)\r
165 config.modulation = DEMOD_PSK1;\r
166 else if ( strcmp(modulation, "PSK2" ) == 0)\r
167 config.modulation = DEMOD_PSK2;\r
168 else if ( strcmp(modulation, "PSK3" ) == 0)\r
169 config.modulation = DEMOD_PSK3;\r
170 else if ( strcmp(modulation, "BIa" ) == 0)\r
171 config.modulation = DEMOD_BIa;\r
172 else if ( strcmp(modulation, "BI" ) == 0)\r
173 config.modulation = DEMOD_BI;\r
174 else {\r
175 PrintAndLog("Unknown modulation '%s'", modulation);\r
176 errors = TRUE;\r
177 }\r
178 break;\r
179 case 'i':\r
180 config.inverted = param_getchar(Cmd,cmdp+1) == '1';\r
181 cmdp+=2;\r
182 break;\r
183 case 'o':\r
184 errors |= param_getdec(Cmd, cmdp+1, &offset);\r
185 if ( !errors )\r
186 config.offset = offset;\r
187 cmdp+=2;\r
188 break;\r
189 default:\r
190 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
191 errors = TRUE;\r
192 break;\r
193 }\r
194 }\r
54a942b0 195\r
13d77ef9 196 // No args\r
197 if (cmdp == 0) {\r
198 printConfiguration( config );\r
199 return 0;\r
200 }\r
201 //Validations\r
202 if (errors)\r
203 return usage_t55xx_config();\r
54a942b0 204\r
13d77ef9 205 config.block0 = 0;\r
206 printConfiguration ( config );\r
207 return 0;\r
208}\r
54a942b0 209\r
13d77ef9 210int CmdT55xxReadBlock(const char *Cmd) {\r
211 int block = -1;\r
212 int password = 0xFFFFFFFF; //default to blank Block 7\r
213\r
214 char cmdp = param_getchar(Cmd, 0);\r
215 if (cmdp == 'h' || cmdp == 'H')\r
216 return usage_t55xx_read();\r
217\r
218 int res = sscanf(Cmd, "%d %x", &block, &password);\r
219\r
220 if ( res < 1 || res > 2 )\r
221 return usage_t55xx_read();\r
222\r
223 \r
224 if ((block < 0) | (block > 7)) {\r
225 PrintAndLog("Block must be between 0 and 7");\r
226 return 1;\r
227 } \r
228\r
229 UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, block, 0}};\r
230 c.d.asBytes[0] = 0x0; \r
231\r
232 //Password mode\r
233 if ( res == 2 ) {\r
234 c.arg[2] = password;\r
235 c.d.asBytes[0] = 0x1; \r
236 }\r
237\r
238 SendCommand(&c);\r
239 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r
240 PrintAndLog("command execution time out");\r
241 return 2;\r
242 }\r
243 \r
244 uint8_t got[12000];\r
245 GetFromBigBuf(got,sizeof(got),0);\r
246 WaitForResponse(CMD_ACK,NULL);\r
247 setGraphBuf(got, 12000);\r
248 DemodBufferLen=0;\r
1fbf8956 249 if (!DecodeT55xxBlock()) return 3;\r
13d77ef9 250 char blk[10]={0};\r
251 sprintf(blk,"%d", block);\r
252 printT55xxBlock(blk);\r
253 return 0;\r
54a942b0 254}\r
255\r
13d77ef9 256bool DecodeT55xxBlock(){\r
257 \r
258 char buf[8] = {0x00};\r
259 char *cmdStr = buf;\r
260 int ans = 0;\r
261 uint8_t bitRate[8] = {8,16,32,40,50,64,100,128};\r
54a942b0 262\r
13d77ef9 263 DemodBufferLen = 0x00;\r
54a942b0 264\r
13d77ef9 265 switch( config.modulation ){\r
266 case DEMOD_FSK:\r
267 //CmdLtrim("26");\r
268 sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );\r
269 CmdLtrim(cmdStr); \r
270 sprintf(cmdStr,"%d %d", bitRate[config.bitrate], config.inverted );\r
271 ans = FSKrawDemod(cmdStr, FALSE);\r
272 break;\r
273 case DEMOD_FSK1:\r
274 //CmdLtrim("26");\r
275 sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );\r
276 CmdLtrim(cmdStr); \r
277 sprintf(cmdStr,"%d 1 8 5", bitRate[config.bitrate] );\r
278 ans = FSKrawDemod(cmdStr, FALSE);\r
279 break;\r
280 case DEMOD_FSK1a:\r
281 //CmdLtrim("26");\r
282 sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );\r
283 CmdLtrim(cmdStr); \r
284 sprintf(cmdStr,"%d 0 8 5", bitRate[config.bitrate] );\r
285 ans = FSKrawDemod(cmdStr, FALSE);\r
286 break;\r
287 case DEMOD_FSK2:\r
288 //CmdLtrim("26");\r
289 sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );\r
290 CmdLtrim(cmdStr); \r
291 sprintf(cmdStr,"%d 0 10 8", bitRate[config.bitrate] );\r
292 ans = FSKrawDemod(cmdStr, FALSE);\r
293 break;\r
294 case DEMOD_FSK2a:\r
295 //CmdLtrim("26");\r
296 sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );\r
297 CmdLtrim(cmdStr); \r
298 sprintf(cmdStr,"%d 1 10 8", bitRate[config.bitrate] );\r
299 ans = FSKrawDemod(cmdStr, FALSE);\r
300 break;\r
301 case DEMOD_ASK:\r
302 sprintf(cmdStr,"%d %d 1", bitRate[config.bitrate], config.inverted );\r
303 ans = ASKmanDemod(cmdStr, FALSE, FALSE);\r
304 break;\r
305 case DEMOD_PSK1:\r
306 sprintf(cmdStr,"%d %d 1", bitRate[config.bitrate], config.inverted );\r
307 ans = PSKDemod(cmdStr, FALSE);\r
308 break;\r
309 case DEMOD_PSK2:\r
310 sprintf(cmdStr,"%d 1", bitRate[config.bitrate] );\r
311 ans = PSKDemod(cmdStr, FALSE);\r
312 psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
313 break;\r
314 case DEMOD_PSK3:\r
315 sprintf(cmdStr,"%d %d 1", bitRate[config.bitrate], config.inverted );\r
316 ans = PSKDemod(cmdStr, FALSE);\r
317 psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
318 break;\r
319 case DEMOD_NRZ:\r
320 sprintf(cmdStr,"%d %d 1", bitRate[config.bitrate], config.inverted );\r
321 ans = NRZrawDemod(cmdStr, FALSE);\r
322 break;\r
323 case DEMOD_BI:\r
324 sprintf(cmdStr,"0 %d 0 1", bitRate[config.bitrate] );\r
325 ans = ASKbiphaseDemod(cmdStr, FALSE);\r
326 break;\r
327 case DEMOD_BIa:\r
328 sprintf(cmdStr,"0 %d 1 1", bitRate[config.bitrate] );\r
329 ans = ASKbiphaseDemod(cmdStr, FALSE);\r
330 break;\r
331 default:\r
332 return FALSE;\r
333 }\r
334 return (bool) ans;\r
335}\r
54a942b0 336\r
13d77ef9 337int CmdT55xxDetect(const char *Cmd){\r
54a942b0 338\r
13d77ef9 339 char cmdp = param_getchar(Cmd, 0);\r
340 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H')\r
341 return usage_t55xx_detect();\r
342 \r
343 if (strlen(Cmd)==0)\r
344 AquireData( CONFIGURATION_BLOCK );\r
345\r
346 if ( !tryDetectModulation() )\r
347 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");\r
348\r
349 return 0;\r
54a942b0 350}\r
351\r
13d77ef9 352// detect configuration?\r
353bool tryDetectModulation(){\r
354 char cmdStr[8] = {0};\r
355 uint8_t hits = 0;\r
356 t55xx_conf_block_t tests[15];\r
357 \r
358 if (GetFskClock("", FALSE, FALSE)){ \r
359 uint8_t fc1 = 0, fc2 = 0, clk=0;\r
360 fskClocks(&fc1, &fc2, &clk, FALSE);\r
361 sprintf(cmdStr,"%d", clk/2);\r
362 CmdLtrim(cmdStr);\r
363 if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset)){\r
364 tests[hits].modulation = DEMOD_FSK;\r
365 if (fc1==8 && fc2 == 5)\r
366 tests[hits].modulation = DEMOD_FSK1a;\r
367 else if (fc1==10 && fc2 == 8)\r
368 tests[hits].modulation = DEMOD_FSK2;\r
54a942b0 369\r
13d77ef9 370 tests[hits].inverted = FALSE;\r
371 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
372 ++hits;\r
373 }\r
374 if ( FSKrawDemod("0 1", FALSE) && test(DEMOD_FSK, &tests[hits].offset)) {\r
375 tests[hits].modulation = DEMOD_FSK;\r
376 if (fc1==8 && fc2 == 5)\r
377 tests[hits].modulation = DEMOD_FSK1;\r
378 else if (fc1==10 && fc2 == 8)\r
379 tests[hits].modulation = DEMOD_FSK2a;\r
54a942b0 380\r
13d77ef9 381 tests[hits].inverted = TRUE;\r
382 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
383 ++hits;\r
384 }\r
385 } else {\r
386 if ( ASKmanDemod("0 0 1", FALSE, FALSE) && test(DEMOD_ASK, &tests[hits].offset)) {\r
387 tests[hits].modulation = DEMOD_ASK;\r
388 tests[hits].inverted = FALSE;\r
389 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
390 ++hits;\r
391 }\r
54a942b0 392\r
13d77ef9 393 if ( ASKmanDemod("0 1 1", FALSE, FALSE) && test(DEMOD_ASK, &tests[hits].offset)) {\r
394 tests[hits].modulation = DEMOD_ASK;\r
395 tests[hits].inverted = TRUE;\r
396 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
397 ++hits;\r
398 }\r
399 \r
400 if ( NRZrawDemod("0 0 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset)) {\r
401 tests[hits].modulation = DEMOD_NRZ;\r
402 tests[hits].inverted = FALSE;\r
403 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
404 ++hits;\r
405 }\r
54a942b0 406\r
13d77ef9 407 if ( NRZrawDemod("0 1 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset)) {\r
408 tests[hits].modulation = DEMOD_NRZ;\r
409 tests[hits].inverted = TRUE;\r
410 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
411 ++hits;\r
412 }\r
413 \r
414 if ( PSKDemod("0 0 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset)) {\r
415 tests[hits].modulation = DEMOD_PSK1;\r
416 tests[hits].inverted = FALSE;\r
417 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
418 ++hits;\r
419 }\r
420 \r
421 if ( PSKDemod("0 1 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset)) {\r
422 tests[hits].modulation = DEMOD_PSK1;\r
423 tests[hits].inverted = TRUE;\r
424 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
425 ++hits;\r
426 }\r
427\r
428 // PSK2 - needs a call to psk1TOpsk2.\r
429 if ( PSKDemod("0 0 1", FALSE)) {\r
430 psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
431 if (test(DEMOD_PSK2, &tests[hits].offset)){\r
432 tests[hits].modulation = DEMOD_PSK2;\r
433 tests[hits].inverted = FALSE;\r
434 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
435 ++hits;\r
436 }\r
437 } // inverse waves does not affect this demod\r
438\r
439 // PSK3 - needs a call to psk1TOpsk2.\r
440 if ( PSKDemod("0 0 1", FALSE)) {\r
441 psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
442 if (test(DEMOD_PSK3, &tests[hits].offset)){\r
443 tests[hits].modulation = DEMOD_PSK3;\r
444 tests[hits].inverted = FALSE;\r
445 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
446 ++hits;\r
447 }\r
448 } // inverse waves does not affect this demod\r
449 \r
450 if ( ASKbiphaseDemod("0 0 0 1", FALSE) && test(DEMOD_BI, &tests[hits].offset) ) {\r
451 tests[hits].modulation = DEMOD_BI;\r
452 tests[hits].inverted = FALSE;\r
453 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
454 ++hits;\r
455 }\r
456 if ( ASKbiphaseDemod("0 0 1 1", FALSE) && test(DEMOD_BIa, &tests[hits].offset) ) {\r
457 tests[hits].modulation = DEMOD_BIa;\r
458 tests[hits].inverted = TRUE;\r
459 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
460 ++hits;\r
461 }\r
462 } \r
463 if ( hits == 1) {\r
464 config.modulation = tests[0].modulation;\r
465 config.inverted = tests[0].inverted;\r
466 config.offset = tests[0].offset;\r
467 config.block0 = tests[0].block0;\r
468 printConfiguration( config );\r
469 return TRUE;\r
470 }\r
471 \r
472 if ( hits > 1) {\r
473 PrintAndLog("Found [%d] possible matches for modulation.",hits);\r
474 for(int i=0; i<hits; ++i){\r
475 PrintAndLog("--[%d]---------------", i+1);\r
476 printConfiguration( tests[i] );\r
477 }\r
478 }\r
479 return FALSE;\r
480}\r
481\r
482bool testModulation(uint8_t mode, uint8_t modread){\r
483 switch( mode ){\r
484 case DEMOD_FSK:\r
485 if (modread > 3 && modread < 8) return TRUE;\r
486 break;\r
487 case DEMOD_ASK:\r
488 if (modread == DEMOD_ASK) return TRUE;\r
489 break;\r
490 case DEMOD_PSK1:\r
491 if (modread == DEMOD_PSK1) return TRUE;\r
492 break;\r
493 case DEMOD_PSK2:\r
494 if (modread == DEMOD_PSK2) return TRUE;\r
495 break;\r
496 case DEMOD_PSK3:\r
497 if (modread == DEMOD_PSK3) return TRUE;\r
498 break;\r
499 case DEMOD_NRZ:\r
500 if (modread == DEMOD_NRZ) return TRUE;\r
501 break;\r
502 case DEMOD_BI:\r
503 if (modread == DEMOD_BI) return TRUE;\r
504 break;\r
505 case DEMOD_BIa:\r
506 if (modread == DEMOD_BIa) return TRUE;\r
507 break; \r
508 default:\r
509 return FALSE;\r
510 }\r
511 return FALSE;\r
512}\r
513\r
514bool testBitRate(uint8_t readRate, uint8_t mod){\r
515 uint8_t expected[8] = {8, 16, 32, 40, 50, 64, 100, 128};\r
516 uint8_t detRate = 0;\r
517 switch( mod ){\r
518 case DEMOD_FSK:\r
519 detRate = GetFskClock("",FALSE, FALSE); \r
520 if (expected[readRate] == detRate) {\r
521 config.bitrate = readRate;\r
522 return TRUE;\r
523 }\r
524 break;\r
525 case DEMOD_FSK1:\r
526 detRate = GetFskClock("",FALSE, FALSE); \r
527 if (expected[readRate] == detRate) {\r
528 config.bitrate = readRate;\r
529 return TRUE;\r
530 }\r
531 break;\r
532 case DEMOD_FSK1a:\r
533 detRate = GetFskClock("",FALSE, FALSE); \r
534 if (expected[readRate] == detRate) {\r
535 config.bitrate = readRate;\r
536 return TRUE;\r
537 }\r
538 break;\r
539 case DEMOD_FSK2:\r
540 detRate = GetFskClock("",FALSE, FALSE); \r
541 if (expected[readRate] == detRate) {\r
542 config.bitrate = readRate;\r
543 return TRUE;\r
544 }\r
545 break;\r
546 case DEMOD_FSK2a:\r
547 detRate = GetFskClock("",FALSE, FALSE); \r
548 if (expected[readRate] == detRate) {\r
549 config.bitrate = readRate;\r
550 return TRUE;\r
551 }\r
552 break;\r
553 case DEMOD_ASK:\r
554 detRate = GetAskClock("",FALSE, FALSE); \r
555 if (expected[readRate] == detRate) {\r
556 config.bitrate = readRate;\r
557 return TRUE;\r
558 }\r
559 break;\r
560 case DEMOD_PSK1:\r
561 detRate = GetPskClock("",FALSE, FALSE); \r
562 if (expected[readRate] == detRate) {\r
563 config.bitrate = readRate;\r
564 return TRUE;\r
565 }\r
566 break;\r
567 case DEMOD_PSK2:\r
568 detRate = GetPskClock("",FALSE, FALSE); \r
569 if (expected[readRate] == detRate) {\r
570 config.bitrate = readRate;\r
571 return TRUE;\r
572 }\r
573 break;\r
574 case DEMOD_PSK3:\r
575 detRate = GetPskClock("",FALSE, FALSE); \r
576 if (expected[readRate] == detRate) {\r
577 config.bitrate = readRate;\r
578 return TRUE;\r
579 }\r
580 break;\r
581 case DEMOD_NRZ:\r
582 detRate = GetNrzClock("",FALSE, FALSE); \r
583 if (expected[readRate] == detRate) {\r
584 config.bitrate = readRate;\r
585 return TRUE;\r
586 }\r
587 break;\r
588 case DEMOD_BI:\r
589 detRate = GetAskClock("",FALSE, FALSE); \r
590 if (expected[readRate] == detRate) {\r
591 config.bitrate = readRate;\r
592 return TRUE;\r
593 }\r
594 break;\r
595 default:\r
596 return FALSE;\r
597 }\r
598 return FALSE;\r
599}\r
600\r
601bool test(uint8_t mode, uint8_t *offset){\r
602\r
603 if ( !DemodBufferLen) return FALSE;\r
604 uint8_t si = 0;\r
605 for (uint8_t idx = 0; idx < 64; idx++){\r
606 si = idx;\r
607 if ( PackBits(si, 32, DemodBuffer) == 0x00 ) continue;\r
608\r
609 uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key\r
610 uint8_t resv = PackBits(si, 4, DemodBuffer); si += 4; //was 7 & +=7+3 //should be only 4 bits if extended mode\r
611 // 2nibble must be zeroed.\r
612 // moved test to here, since this gets most faults first.\r
613 if ( resv > 0x00) continue;\r
614\r
615 uint8_t xtRate = PackBits(si, 3, DemodBuffer); si += 3; //new\r
616 uint8_t bitRate = PackBits(si, 3, DemodBuffer); si += 3; //new could check bit rate\r
617 uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1; //bit 15 extended mode\r
618 uint8_t modread = PackBits(si, 5, DemodBuffer); si += 5+2+1; //new\r
619 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //new could check psk cr\r
620 uint8_t nml01 = PackBits(si, 1, DemodBuffer); si += 1+5; //bit 24 , 30, 31 could be tested for 0 if not extended mode\r
621 uint8_t nml02 = PackBits(si, 2, DemodBuffer); si += 2;\r
622 \r
623 //if extended mode\r
624 bool extMode =( (safer == 0x6 || safer == 0x9) && extend) ? TRUE : FALSE;\r
625\r
626 if (!extMode){\r
627 if (nml01 || nml02 || xtRate) continue;\r
628 }\r
629 //test modulation\r
630 if (!testModulation(mode, modread)) continue;\r
631\r
632 *offset = idx;\r
633 if (!testBitRate(bitRate, mode)) continue;\r
634 return TRUE;\r
635 }\r
636 return FALSE;\r
54a942b0 637}\r
638\r
13d77ef9 639void printT55xxBlock(const char *demodStr){\r
640 \r
641 uint8_t i = config.offset;\r
642 uint8_t endpos = 32 + i;\r
643 uint32_t blockData = 0;\r
644 uint8_t bits[64] = {0x00};\r
645\r
646 if ( !DemodBufferLen) return;\r
647\r
648 if ( endpos > DemodBufferLen){\r
649 PrintAndLog("The configured offset %d is too big. Possible offset: %d)", i, DemodBufferLen-32);\r
650 return;\r
651 }\r
652\r
653 for (; i < endpos; ++i)\r
654 bits[i - config.offset]=DemodBuffer[i];\r
655\r
656 blockData = PackBits(0, 32, bits);\r
657 PrintAndLog("0x%08X %s [%s]", blockData, sprint_bin(bits,32), demodStr);\r
658}\r
659\r
660int special(const char *Cmd) {\r
661 uint32_t blockData = 0;\r
662 uint8_t bits[32] = {0x00};\r
663\r
664 PrintAndLog("[OFFSET] [DATA] [BINARY]");\r
665 PrintAndLog("----------------------------------------------------");\r
666 int i,j = 0;\r
667 for (; j < 64; ++j){\r
668 \r
669 for (i = 0; i < 32; ++i)\r
670 bits[i]=DemodBuffer[j+i];\r
671 \r
672 blockData = PackBits(0, 32, bits);\r
673 \r
674 PrintAndLog("[%02d] 0x%08X %s",j , blockData, sprint_bin(bits,32)); \r
675 }\r
676 return 0;\r
677}\r
678\r
679void printConfiguration( t55xx_conf_block_t b){\r
680 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b.modulation) );\r
681 PrintAndLog("Bit Rate : %s", GetBitRateStr(b.bitrate) );\r
682 PrintAndLog("Inverted : %s", (b.inverted) ? "Yes" : "No" );\r
683 PrintAndLog("Offset : %d", b.offset);\r
684 PrintAndLog("Block0 : 0x%08X", b.block0);\r
685 PrintAndLog("");\r
686}\r
687\r
688int CmdT55xxWriteBlock(const char *Cmd)\r
54a942b0 689{\r
13d77ef9 690 int block = 8; //default to invalid block\r
691 int data = 0xFFFFFFFF; //default to blank Block \r
692 int password = 0xFFFFFFFF; //default to blank Block 7\r
693 \r
694 char cmdp = param_getchar(Cmd, 0);\r
695 if (cmdp == 'h' || cmdp == 'H') {\r
696 usage_t55xx_write();\r
697 return 0;\r
698 }\r
699 \r
700 int res = sscanf(Cmd, "%d %x %x",&block, &data, &password);\r
701 \r
702 if ( res < 2 || res > 3) {\r
703 usage_t55xx_write();\r
704 return 1;\r
705 }\r
706\r
707 if (block > 7) {\r
708 PrintAndLog("Block number must be between 0 and 7");\r
709 return 1;\r
710 }\r
711 \r
712 UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}};\r
713 c.d.asBytes[0] = 0x0; \r
714\r
715 PrintAndLog("Writing to block: %d data : 0x%08X", block, data);\r
716\r
717 //Password mode\r
718 if (res == 3) {\r
719 c.arg[2] = password;\r
720 c.d.asBytes[0] = 0x1; \r
721 PrintAndLog("pwd : 0x%08X", password);\r
722 }\r
723 SendCommand(&c);\r
724 return 0;\r
54a942b0 725}\r
726\r
13d77ef9 727int CmdT55xxReadTrace(const char *Cmd)\r
54a942b0 728{\r
13d77ef9 729 char cmdp = param_getchar(Cmd, 0);\r
730 \r
731 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') \r
732 return usage_t55xx_trace();\r
733\r
734 if (strlen(Cmd)==0)\r
735 AquireData( TRACE_BLOCK );\r
736 \r
737 if (!DecodeT55xxBlock()) return 1;\r
54a942b0 738\r
13d77ef9 739 if ( !DemodBufferLen) return 1;\r
740 \r
741 RepaintGraphWindow();\r
742 uint8_t repeat = 0;\r
743 if (config.offset > 5) \r
744 repeat = 32;\r
745 uint8_t si = config.offset+repeat;\r
746 uint32_t bl0 = PackBits(si, 32, DemodBuffer);\r
747 uint32_t bl1 = PackBits(si+32, 32, DemodBuffer);\r
748 \r
749 uint32_t acl = PackBits(si, 8, DemodBuffer); si += 8;\r
750 uint32_t mfc = PackBits(si, 8, DemodBuffer); si += 8;\r
751 uint32_t cid = PackBits(si, 5, DemodBuffer); si += 5;\r
752 uint32_t icr = PackBits(si, 3, DemodBuffer); si += 3;\r
753 uint32_t year = PackBits(si, 4, DemodBuffer); si += 4;\r
754 uint32_t quarter = PackBits(si, 2, DemodBuffer); si += 2;\r
755 uint32_t lotid = PackBits(si, 12, DemodBuffer); si += 12;\r
756 uint32_t wafer = PackBits(si, 5, DemodBuffer); si += 5;\r
757 uint32_t dw = PackBits(si, 15, DemodBuffer); \r
758 \r
759 year += 2000;\r
760 \r
761 PrintAndLog("");\r
762 PrintAndLog("-- T55xx Trace Information ----------------------------------");\r
763 PrintAndLog("-------------------------------------------------------------");\r
764 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl, acl);\r
765 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", mfc, mfc, getTagInfo(mfc));\r
766 PrintAndLog(" CID : 0x%02X (%d) - %s", cid, cid, GetModelStrFromCID(cid));\r
767 PrintAndLog(" ICR IC Revision : %d",icr );\r
768 PrintAndLog(" Manufactured");\r
769 PrintAndLog(" Year/Quarter : %d/%d",year, quarter );\r
770 PrintAndLog(" Lot ID : %d", lotid );\r
771 PrintAndLog(" Wafer number : %d", wafer);\r
772 PrintAndLog(" Die Number : %d", dw);\r
773 PrintAndLog("-------------------------------------------------------------");\r
774 PrintAndLog(" Raw Data - Page 1");\r
775 PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+config.offset+repeat,32) );\r
776 PrintAndLog(" Block 1 : 0x%08X %s", bl1, sprint_bin(DemodBuffer+config.offset+repeat+32,32) );\r
777 PrintAndLog("-------------------------------------------------------------");\r
54a942b0 778\r
13d77ef9 779 if ( acl != 0xE0 )\r
780 PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");\r
781 /*\r
782 TRACE - BLOCK O\r
783 Bits Definition HEX\r
784 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0 \r
785 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation\r
786 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2 \r
787 22-24 ICR IC revision\r
788 25-28 YEAR (BCD encoded) 9 (= 2009)\r
789 29-30 QUARTER 1,2,3,4 \r
790 31-32 LOT ID\r
791 \r
792 TRACE - BLOCK 1\r
793 1-12 LOT ID \r
794 13-17 Wafer number\r
795 18-32 DW, die number sequential\r
796 */\r
797 \r
54a942b0 798 return 0;\r
799}\r
800\r
13d77ef9 801int CmdT55xxInfo(const char *Cmd){\r
802 /*\r
803 Page 0 Block 0 Configuration data.\r
804 Normal mode\r
805 Extended mode\r
806 */\r
807 char cmdp = param_getchar(Cmd, 0);\r
808\r
809 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H')\r
810 return usage_t55xx_info();\r
811 \r
812 if (strlen(Cmd)==0)\r
813 AquireData( CONFIGURATION_BLOCK );\r
814 \r
815 if (!DecodeT55xxBlock()) return 1;\r
816\r
817 if ( !DemodBufferLen) return 1;\r
818\r
819 uint8_t si = config.offset;\r
820 uint32_t bl0 = PackBits(si, 32, DemodBuffer);\r
821 \r
822 uint32_t safer = PackBits(si, 4, DemodBuffer); si += 4; \r
823 uint32_t resv = PackBits(si, 7, DemodBuffer); si += 7;\r
824 uint32_t dbr = PackBits(si, 3, DemodBuffer); si += 3;\r
825 uint32_t extend = PackBits(si, 1, DemodBuffer); si += 1;\r
826 uint32_t datamod = PackBits(si, 5, DemodBuffer); si += 5;\r
827 uint32_t pskcf = PackBits(si, 2, DemodBuffer); si += 2;\r
828 uint32_t aor = PackBits(si, 1, DemodBuffer); si += 1; \r
829 uint32_t otp = PackBits(si, 1, DemodBuffer); si += 1; \r
830 uint32_t maxblk = PackBits(si, 3, DemodBuffer); si += 3;\r
831 uint32_t pwd = PackBits(si, 1, DemodBuffer); si += 1; \r
832 uint32_t sst = PackBits(si, 1, DemodBuffer); si += 1; \r
833 uint32_t fw = PackBits(si, 1, DemodBuffer); si += 1;\r
834 uint32_t inv = PackBits(si, 1, DemodBuffer); si += 1; \r
835 uint32_t por = PackBits(si, 1, DemodBuffer); si += 1;\r
836 \r
837 PrintAndLog("");\r
838 PrintAndLog("-- T55xx Configuration & Tag Information --------------------");\r
839 PrintAndLog("-------------------------------------------------------------");\r
840 PrintAndLog(" Safer key : %s", GetSaferStr(safer));\r
841 PrintAndLog(" reserved : %d", resv);\r
842 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr));\r
843 PrintAndLog(" eXtended mode : %s", (extend) ? "Yes - Warning":"No");\r
844 PrintAndLog(" Modulation : %s", GetModulationStr(datamod));\r
845 PrintAndLog(" PSK clock frequency : %d", pskcf);\r
846 PrintAndLog(" AOR - Answer on Request : %s", (aor) ? "Yes":"No");\r
847 PrintAndLog(" OTP - One Time Pad : %s", (otp) ? "Yes - Warning":"No" );\r
848 PrintAndLog(" Max block : %d", maxblk);\r
849 PrintAndLog(" Password mode : %s", (pwd) ? "Yes":"No");\r
850 PrintAndLog(" Sequence Start Terminator : %s", (sst) ? "Yes":"No");\r
851 PrintAndLog(" Fast Write : %s", (fw) ? "Yes":"No");\r
852 PrintAndLog(" Inverse data : %s", (inv) ? "Yes":"No");\r
853 PrintAndLog(" POR-Delay : %s", (por) ? "Yes":"No");\r
854 PrintAndLog("-------------------------------------------------------------");\r
855 PrintAndLog(" Raw Data - Page 0");\r
856 PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+config.offset,32) );\r
857 PrintAndLog("-------------------------------------------------------------");\r
858 \r
859 return 0;\r
860}\r
861\r
862int CmdT55xxDump(const char *Cmd){\r
863\r
864 char s[20] = {0x00};\r
865 uint8_t pwd[4] = {0x00};\r
866\r
867 char cmdp = param_getchar(Cmd, 0);\r
868 if ( cmdp == 'h' || cmdp == 'H') {\r
869 usage_t55xx_dump();\r
870 return 0;\r
871 }\r
872\r
873 bool hasPwd = ( strlen(Cmd) > 0); \r
874 if ( hasPwd ){\r
875 if (param_gethex(Cmd, 0, pwd, 8)) {\r
876 PrintAndLog("password must include 8 HEX symbols");\r
877 return 1;\r
878 }\r
879 }\r
880 \r
881 for ( int i = 0; i <8; ++i){\r
882 memset(s,0,sizeof(s));\r
883 if ( hasPwd ) {\r
884 sprintf(s,"%d %02x%02x%02x%02x", i, pwd[0],pwd[1],pwd[2],pwd[3]);\r
885 } else {\r
886 sprintf(s,"%d", i);\r
887 }\r
888 CmdT55xxReadBlock(s);\r
889 }\r
890 return 0;\r
891}\r
892\r
893int AquireData( uint8_t block ){\r
894\r
895 UsbCommand c;\r
896 \r
897 if ( block == CONFIGURATION_BLOCK ) \r
898 c.cmd = CMD_T55XX_READ_BLOCK;\r
899 else if (block == TRACE_BLOCK )\r
900 c.cmd = CMD_T55XX_READ_TRACE;\r
901 \r
902 c.arg[0] = 0x00;\r
903 c.arg[1] = 0x00;\r
904 c.arg[2] = 0x00;\r
905 c.d.asBytes[0] = 0x0; \r
906\r
907 //Password mode\r
908 // if ( res == 2 ) {\r
909 // c.arg[2] = password;\r
910 // c.d.asBytes[0] = 0x1; \r
911 // }\r
912\r
913 SendCommand(&c);\r
914 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r
915 PrintAndLog("command execution time out");\r
916 return 1;\r
917 }\r
918\r
919 uint8_t got[12000];\r
920 GetFromBigBuf(got,sizeof(got),0);\r
921 WaitForResponse(CMD_ACK,NULL);\r
922 setGraphBuf(got, 12000);\r
923 return 0;\r
924}\r
925\r
926char * GetBitRateStr(uint32_t id){\r
927 static char buf[40];\r
928 char *retStr = buf;\r
929 switch (id){\r
930 case 0: \r
931 sprintf(retStr,"%d - RF/8",id);\r
932 break;\r
933 case 1:\r
934 sprintf(retStr,"%d - RF/16",id);\r
935 break;\r
936 case 2: \r
937 sprintf(retStr,"%d - RF/32",id);\r
938 break;\r
939 case 3:\r
940 sprintf(retStr,"%d - RF/40",id);\r
941 break;\r
942 case 4:\r
943 sprintf(retStr,"%d - RF/50",id);\r
944 break;\r
945 case 5:\r
946 sprintf(retStr,"%d - RF/64",id);\r
947 break;\r
948 case 6:\r
949 sprintf(retStr,"%d - RF/100",id);\r
950 break;\r
951 case 7:\r
952 sprintf(retStr,"%d - RF/128",id);\r
953 break;\r
954 default:\r
955 sprintf(retStr,"%d - (Unknown)",id);\r
956 break;\r
957 }\r
958\r
959 return buf;\r
960}\r
961\r
962char * GetSaferStr(uint32_t id){\r
963 static char buf[40];\r
964 char *retStr = buf;\r
965 \r
966 sprintf(retStr,"%d",id);\r
967 if (id == 6) {\r
968 sprintf(retStr,"%d - passwd",id);\r
969 }\r
970 if (id == 9 ){\r
971 sprintf(retStr,"%d - testmode",id);\r
972 }\r
973 \r
974 return buf;\r
975}\r
976char * GetModulationStr( uint32_t id){\r
977 static char buf[40];\r
978 char *retStr = buf;\r
979 \r
980 switch (id){\r
981 case 0: \r
982 sprintf(retStr,"%d - DIRECT (ASK/NRZ)",id);\r
983 break;\r
984 case 1:\r
985 sprintf(retStr,"%d - PSK 1 phase change when input changes",id);\r
986 break;\r
987 case 2: \r
988 sprintf(retStr,"%d - PSK 2 phase change on bitclk if input high",id);\r
989 break;\r
990 case 3:\r
991 sprintf(retStr,"%d - PSK 3 phase change on rising edge of input",id);\r
992 break;\r
993 case 4:\r
994 sprintf(retStr,"%d - FSK 1 RF/8 RF/5",id);\r
995 break;\r
996 case 5:\r
997 sprintf(retStr,"%d - FSK 2 RF/8 RF/10",id);\r
998 break;\r
999 case 6:\r
1000 sprintf(retStr,"%d - FSK 1a RF/5 RF/8",id);\r
1001 break;\r
1002 case 7:\r
1003 sprintf(retStr,"%d - FSK 2a RF/10 RF/8",id);\r
1004 break;\r
1005 case 8:\r
1006 sprintf(retStr,"%d - Manschester",id);\r
1007 break;\r
1008 case 16:\r
1009 sprintf(retStr,"%d - Biphase",id);\r
1010 break;\r
1011 case 0x18:\r
1fbf8956 1012 sprintf(retStr,"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id);\r
13d77ef9 1013 break;\r
1014 case 17:\r
1015 sprintf(retStr,"%d - Reserved",id);\r
1016 break;\r
1017 default:\r
1018 sprintf(retStr,"0x%02X (Unknown)",id);\r
1019 break;\r
1020 }\r
1021 return buf;\r
1022}\r
1023\r
1024char * GetModelStrFromCID(uint32_t cid){\r
1025 \r
1026 static char buf[10];\r
1027 char *retStr = buf;\r
1028 \r
1029 if (cid == 1) sprintf(retStr,"ATA5577M1");\r
1030 if (cid == 2) sprintf(retStr,"ATA5577M2"); \r
1031 return buf;\r
1032}\r
1033\r
1034char * GetSelectedModulationStr( uint8_t id){\r
1035\r
1036 static char buf[16];\r
1037 char *retStr = buf;\r
1038\r
1039 switch (id){\r
1040 case DEMOD_FSK:\r
1041 sprintf(retStr,"FSK");\r
1042 break;\r
1043 case DEMOD_FSK1:\r
1044 sprintf(retStr,"FSK1");\r
1045 break;\r
1046 case DEMOD_FSK1a:\r
1047 sprintf(retStr,"FSK1a");\r
1048 break;\r
1049 case DEMOD_FSK2:\r
1050 sprintf(retStr,"FSK2");\r
1051 break;\r
1052 case DEMOD_FSK2a:\r
1053 sprintf(retStr,"FSK2a");\r
1054 break;\r
1055 case DEMOD_ASK: \r
1056 sprintf(retStr,"ASK");\r
1057 break;\r
1058 case DEMOD_NRZ:\r
1059 sprintf(retStr,"DIRECT/NRZ");\r
1060 break;\r
1061 case DEMOD_PSK1:\r
1062 sprintf(retStr,"PSK1");\r
1063 break;\r
1064 case DEMOD_PSK2:\r
1065 sprintf(retStr,"PSK2");\r
1066 break;\r
1067 case DEMOD_PSK3:\r
1068 sprintf(retStr,"PSK3");\r
1069 break;\r
1070 case DEMOD_BI:\r
1071 sprintf(retStr,"BIPHASE");\r
1072 break;\r
1073 case DEMOD_BIa:\r
1fbf8956 1074 sprintf(retStr,"BIPHASEa - (CDP)");\r
13d77ef9 1075 break;\r
1076 default:\r
1077 sprintf(retStr,"(Unknown)");\r
1078 break;\r
1079 }\r
1080 return buf;\r
1081}\r
1082\r
1083uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits){\r
1084 \r
1085 int i = start;\r
1086 int j = len-1;\r
1087\r
1088 if (len > 32) return 0;\r
1089\r
1090 uint32_t tmp = 0;\r
1091 for (; j >= 0; --j, ++i)\r
1092 tmp |= bits[i] << j;\r
1093\r
1094 return tmp;\r
1095}\r
1096\r
54a942b0 1097static command_t CommandTable[] =\r
1098{\r
13d77ef9 1099 {"help", CmdHelp, 1, "This help"},\r
1100 {"config", CmdT55xxSetConfig, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"},\r
1101 {"detect", CmdT55xxDetect, 0, "[1] Try detecting the tag modulation from reading the configuration block."},\r
1102 {"read", CmdT55xxReadBlock, 0, "<block> [password] -- Read T55xx block data (page 0) [optional password]"},\r
1103 {"write", CmdT55xxWriteBlock,0, "<block> <data> [password] -- Write T55xx block data (page 0) [optional password]"},\r
1104 {"trace", CmdT55xxReadTrace, 0, "[1] Show T55xx traceability data (page 1/ blk 0-1)"},\r
1105 {"info", CmdT55xxInfo, 0, "[1] Show T55xx configuration data (page 0/ blk 0)"},\r
1106 {"dump", CmdT55xxDump, 0, "[password] Dump T55xx card block 0-7. [optional password]"},\r
1107 {"special", special, 0, "Show block changes with 64 different offsets"},\r
54a942b0 1108 {NULL, NULL, 0, NULL}\r
1109};\r
1110\r
1111int CmdLFT55XX(const char *Cmd)\r
1112{\r
1113 CmdsParse(CommandTable, Cmd);\r
1114 return 0;\r
1115}\r
1116\r
1117int CmdHelp(const char *Cmd)\r
1118{\r
1119 CmdsHelp(CommandTable);\r
1120 return 0;\r
1121}\r
Impressum, Datenschutz