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