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