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