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