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