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