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