]>
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 | |
54a942b0 | 13 | #include "proxmark3.h"\r |
14 | #include "ui.h"\r | |
15 | #include "graph.h"\r | |
f38a1528 | 16 | #include "cmdmain.h"\r |
54a942b0 | 17 | #include "cmdparser.h"\r |
18 | #include "cmddata.h"\r | |
19 | #include "cmdlf.h"\r | |
20 | #include "cmdlft55xx.h"\r | |
f38a1528 | 21 | #include "util.h"\r |
22 | #include "data.h"\r | |
c4e3b1b6 | 23 | #include "lfdemod.h"\r |
83a42ef9 | 24 | #include "../common/crc.h"\r |
54a942b0 | 25 | \r |
8d0a3e87 | 26 | #define LF_TRACE_BUFF_SIZE 20000 // 32 x 32 x 10 (32 bit times numofblock (7), times clock skip..)\r |
c6be64da | 27 | #define LF_BITSSTREAM_LEN 1000 // more then 1000 bits shouldn't happend.. 8block * 4 bytes * 8bits = \r |
54a942b0 | 28 | \r |
83a42ef9 | 29 | // 0 = FSK\r |
30 | // 1 = ASK\r | |
31 | // 2 = PSK\r | |
32 | // 4 = NZR (direct)\r | |
33 | typedef struct {\r | |
34 | uint8_t modulation;\r | |
35 | bool inversed;\r | |
36 | uint32_t block0;\r | |
118bfa1b | 37 | } t55xx_conf_block_t;\r |
83a42ef9 | 38 | \r |
39 | // Default configuration: FSK, not inversed.\r | |
33add187 | 40 | t55xx_conf_block_t config = { .modulation = 2, .inversed = FALSE, .block0 = 0x00};\r |
83a42ef9 | 41 | \r |
42 | int usage_t55xx_config(){\r | |
118bfa1b | 43 | PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1]");\r |
83a42ef9 | 44 | PrintAndLog("Options: ");\r |
118bfa1b | 45 | PrintAndLog(" h This help");\r |
46 | PrintAndLog(" d <FSK|ASK|PSK|NZ|BI> Set demodulation FSK / ASK / PSK / NZ / Biphase");\r | |
47 | PrintAndLog(" i [1] Inverse data signal, defaults to normal");\r | |
48 | PrintAndLog("");\r | |
83a42ef9 | 49 | PrintAndLog("Examples:");\r |
118bfa1b | 50 | PrintAndLog(" lf t55xx config d FSK - FSK demodulation");\r |
51 | PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");\r | |
52 | PrintAndLog("");\r | |
83a42ef9 | 53 | return 0;\r |
54 | }\r | |
68008fb5 | 55 | int usage_t55xx_read(){\r |
56 | PrintAndLog("Usage: lf t55xx read <block> <password>");\r | |
4ecde0e1 | 57 | PrintAndLog(" <block>, block number to read. Between 0-7");\r |
58 | PrintAndLog(" <password>, OPTIONAL password (8 hex characters)");\r | |
59 | PrintAndLog("");\r | |
118bfa1b | 60 | PrintAndLog("Examples:");\r |
61 | PrintAndLog(" lf t55xx read 0 - read data from block 0");\r | |
62 | PrintAndLog(" lf t55xx read 0 feedbeef - read data from block 0 password feedbeef");\r | |
4ecde0e1 | 63 | PrintAndLog("");\r |
64 | return 0;\r | |
65 | }\r | |
68008fb5 | 66 | int usage_t55xx_write(){\r |
4ecde0e1 | 67 | PrintAndLog("Usage: lf t55xx wr <block> <data> [password]");\r |
68 | PrintAndLog(" <block>, block number to read. Between 0-7");\r | |
69 | PrintAndLog(" <data>, 4 bytes of data to write (8 hex characters)");\r | |
70 | PrintAndLog(" [password], OPTIONAL password 4bytes (8 hex characters)");\r | |
71 | PrintAndLog("");\r | |
118bfa1b | 72 | PrintAndLog("Examples:");\r |
73 | PrintAndLog(" lf t55xx wd 3 11223344 - write 11223344 to block 3");\r | |
74 | PrintAndLog(" lf t55xx wd 3 11223344 feedbeef - write 11223344 to block 3 password feedbeef");\r | |
4ecde0e1 | 75 | PrintAndLog("");\r |
76 | return 0;\r | |
77 | }\r | |
78 | int usage_t55xx_trace() {\r | |
118bfa1b | 79 | PrintAndLog("Usage: lf t55xx trace [1]");\r |
4ecde0e1 | 80 | PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");\r |
81 | PrintAndLog("");\r | |
118bfa1b | 82 | PrintAndLog("Examples:");\r |
83 | PrintAndLog(" lf t55xx trace");\r | |
84 | PrintAndLog(" lf t55xx trace 1");\r | |
4ecde0e1 | 85 | PrintAndLog("");\r |
86 | return 0;\r | |
87 | }\r | |
88 | int usage_t55xx_info() {\r | |
118bfa1b | 89 | PrintAndLog("Usage: lf t55xx info [1]");\r |
4ecde0e1 | 90 | PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");\r |
91 | PrintAndLog("");\r | |
118bfa1b | 92 | PrintAndLog("Examples:");\r |
93 | PrintAndLog(" lf t55xx info");\r | |
94 | PrintAndLog(" lf t55xx info 1");\r | |
4ecde0e1 | 95 | PrintAndLog("");\r |
96 | return 0;\r | |
97 | }\r | |
4ecde0e1 | 98 | int usage_t55xx_dump(){\r |
99 | PrintAndLog("Usage: lf t55xx dump <password>");\r | |
118bfa1b | 100 | PrintAndLog(" <password>, OPTIONAL password 4bytes (8 hex symbols)");\r |
4ecde0e1 | 101 | PrintAndLog("");\r |
118bfa1b | 102 | PrintAndLog("Examples:");\r |
103 | PrintAndLog(" lf t55xx dump");\r | |
104 | PrintAndLog(" lf t55xx dump feedbeef");\r | |
4ecde0e1 | 105 | PrintAndLog("");\r |
106 | return 0;\r | |
107 | }\r | |
33add187 | 108 | int usage_t55xx_detect(){\r |
109 | PrintAndLog("Usage: lf t55xx detect");\r | |
110 | PrintAndLog("");\r | |
111 | PrintAndLog("Examples:");\r | |
112 | PrintAndLog(" lf t55xx detect");\r | |
113 | PrintAndLog(" lf t55xx detect 1");\r | |
114 | PrintAndLog("");\r | |
115 | return 0;\r | |
116 | }\r | |
0310364d | 117 | \r |
4ecde0e1 | 118 | static int CmdHelp(const char *Cmd);\r |
c4e3b1b6 | 119 | \r |
83a42ef9 | 120 | int CmdT55xxSetConfig(const char *Cmd){\r |
118bfa1b | 121 | \r |
d8c927bc | 122 | int len = 0;\r |
123 | int foundModulation = 2;\r | |
124 | bool inverse = FALSE;\r | |
118bfa1b | 125 | bool errors = FALSE;\r |
126 | uint8_t cmdp = 0;\r | |
127 | char modulation[4] = {0x00};\r | |
83a42ef9 | 128 | \r |
118bfa1b | 129 | while(param_getchar(Cmd, cmdp) != 0x00 && !errors)\r |
83a42ef9 | 130 | {\r |
118bfa1b | 131 | switch(param_getchar(Cmd, cmdp))\r |
132 | {\r | |
133 | case 'h':\r | |
134 | case 'H':\r | |
135 | return usage_t55xx_config();\r | |
136 | case 'd':\r | |
137 | len = param_getstr(Cmd, cmdp+1, modulation);\r | |
138 | cmdp+= len+1;\r | |
139 | //FSK|ASK|PSK|NZ|BI\r | |
140 | if ( strcmp(modulation, "FSK" ) == 0)\r | |
d8c927bc | 141 | foundModulation = 1;\r |
118bfa1b | 142 | else if ( strcmp(modulation, "ASK" ) == 0)\r |
d8c927bc | 143 | foundModulation = 2;\r |
118bfa1b | 144 | else if ( strcmp(modulation, "PSK" ) == 0)\r |
d8c927bc | 145 | foundModulation = 3;\r |
118bfa1b | 146 | else if ( strcmp(modulation, "NZ" ) == 0)\r |
d8c927bc | 147 | foundModulation = 4;\r |
118bfa1b | 148 | else if ( strcmp(modulation, "BI" ) == 0)\r |
d8c927bc | 149 | foundModulation = 5;\r |
118bfa1b | 150 | else {\r |
151 | PrintAndLog("Unknown modulation '%s'", modulation);\r | |
152 | errors = TRUE;\r | |
153 | }\r | |
154 | break;\r | |
155 | case 'i':\r | |
156 | inverse = param_getchar(Cmd,cmdp+1) == '1';\r | |
157 | cmdp+=2;\r | |
158 | break;\r | |
159 | default:\r | |
160 | PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r | |
161 | errors = TRUE;\r | |
162 | break;\r | |
163 | }\r | |
83a42ef9 | 164 | }\r |
118bfa1b | 165 | // No args\r |
166 | if (cmdp == 0) {\r | |
167 | PrintAndLog("Modulation: %d", config.modulation);\r | |
168 | PrintAndLog("Invert : %d", config.inversed);\r | |
169 | PrintAndLog("Block0 : %08X", config.block0);\r | |
170 | return 0;\r | |
171 | }\r | |
172 | //Validations\r | |
173 | if (errors)\r | |
174 | return usage_t55xx_config();\r | |
175 | \r | |
d8c927bc | 176 | config.modulation = foundModulation;\r |
118bfa1b | 177 | config.inversed = inverse;\r |
178 | config.block0 = 0;\r | |
83a42ef9 | 179 | return 0;\r |
180 | }\r | |
83a42ef9 | 181 | \r |
33add187 | 182 | int CmdT55xxReadBlock(const char *Cmd)\r |
54a942b0 | 183 | {\r |
c6be64da | 184 | int block = -1;\r |
4ecde0e1 | 185 | int password = 0xFFFFFFFF; //default to blank Block 7\r |
83a42ef9 | 186 | \r |
4ecde0e1 | 187 | char cmdp = param_getchar(Cmd, 0);\r |
83a42ef9 | 188 | if (cmdp == 'h' || cmdp == 'H')\r |
189 | return usage_t55xx_read();\r | |
54a942b0 | 190 | \r |
4ecde0e1 | 191 | int res = sscanf(Cmd, "%d %x", &block, &password);\r |
54a942b0 | 192 | \r |
7b40affb | 193 | if ( res < 1 || res > 2 )\r |
194 | return usage_t55xx_read();\r | |
195 | \r | |
4ecde0e1 | 196 | \r |
197 | if ((block < 0) | (block > 7)) {\r | |
b44e5233 | 198 | PrintAndLog("Block must be between 0 and 7");\r |
199 | return 1;\r | |
4ecde0e1 | 200 | } \r |
54a942b0 | 201 | \r |
4ecde0e1 | 202 | UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, block, 0}};\r |
203 | c.d.asBytes[0] = 0x0; \r | |
54a942b0 | 204 | \r |
4ecde0e1 | 205 | //Password mode\r |
206 | if ( res == 2 ) {\r | |
207 | c.arg[2] = password;\r | |
208 | c.d.asBytes[0] = 0x1; \r | |
c4e3b1b6 | 209 | }\r |
54a942b0 | 210 | \r |
b44e5233 | 211 | SendCommand(&c);\r |
68008fb5 | 212 | if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r |
c4e3b1b6 | 213 | PrintAndLog("command execution time out");\r |
385f3987 | 214 | return 2;\r |
c4e3b1b6 | 215 | }\r |
f38a1528 | 216 | \r |
68008fb5 | 217 | uint8_t got[12000];\r |
218 | GetFromBigBuf(got,sizeof(got),0);\r | |
219 | WaitForResponse(CMD_ACK,NULL);\r | |
68008fb5 | 220 | setGraphBuf(got, 12000);\r |
83a42ef9 | 221 | \r |
33add187 | 222 | DecodeT55xxBlock();\r |
33add187 | 223 | printT55xxBlock("");\r |
33add187 | 224 | return 0;\r |
225 | }\r | |
226 | \r | |
227 | void DecodeT55xxBlock(){\r | |
228 | \r | |
229 | char buf[6] = {0x00};\r | |
230 | char *cmdStr = buf;\r | |
231 | \r | |
232 | // use the configuration\r | |
233 | switch( config.modulation ){\r | |
234 | case 1:\r | |
235 | sprintf(cmdStr,"0 %d", config.inversed );\r | |
236 | FSKrawDemod(cmdStr, FALSE);\r | |
237 | break;\r | |
238 | case 2:\r | |
239 | sprintf(cmdStr,"0 %d 1", config.inversed );\r | |
240 | ASKmanDemod(cmdStr, FALSE, FALSE);\r | |
33add187 | 241 | break;\r |
242 | case 3:\r | |
243 | sprintf(cmdStr,"0 %d 1", config.inversed );\r | |
244 | PSKDemod(cmdStr, FALSE);\r | |
245 | break;\r | |
246 | case 4:\r | |
247 | sprintf(cmdStr,"0 %d 1", config.inversed );\r | |
248 | NRZrawDemod(cmdStr, FALSE);\r | |
249 | break;\r | |
250 | case 5:\r | |
251 | //BiphaseRawDecode("0",FALSE);\r | |
252 | break;\r | |
253 | default:\r | |
254 | return;\r | |
255 | }\r | |
256 | }\r | |
257 | \r | |
258 | int CmdT55xxDetect(const char *Cmd){\r | |
259 | char cmdp = param_getchar(Cmd, 0);\r | |
260 | if (cmdp == 'h' || cmdp == 'H')\r | |
261 | return usage_t55xx_detect();\r | |
262 | \r | |
263 | // read block 0, Page 0. Configuration.\r | |
264 | UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, 0, 0}};\r | |
265 | c.d.asBytes[0] = 0x0; \r | |
266 | \r | |
267 | //Password mode\r | |
268 | // if ( res == 2 ) {\r | |
269 | // c.arg[2] = password;\r | |
270 | // c.d.asBytes[0] = 0x1; \r | |
271 | // }\r | |
272 | \r | |
273 | SendCommand(&c);\r | |
274 | if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r | |
275 | PrintAndLog("command execution time out");\r | |
276 | return FALSE;\r | |
83a42ef9 | 277 | }\r |
68008fb5 | 278 | \r |
33add187 | 279 | uint8_t got[12000];\r |
280 | GetFromBigBuf(got,sizeof(got),0);\r | |
281 | WaitForResponse(CMD_ACK,NULL);\r | |
282 | setGraphBuf(got, 12000);\r | |
283 | \r | |
7b40affb | 284 | if ( !tryDetectModulation() ){\r |
285 | PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");\r | |
286 | }\r | |
33add187 | 287 | return 0;\r |
288 | }\r | |
289 | \r | |
290 | // detect configuration?\r | |
291 | bool tryDetectModulation(){\r | |
292 | \r | |
293 | uint8_t hits = 0;\r | |
7b40affb | 294 | t55xx_conf_block_t tests[10];\r |
33add187 | 295 | \r |
33add187 | 296 | if (GetFskClock("", FALSE, FALSE)){ \r |
33add187 | 297 | if ( FSKrawDemod("0 0", FALSE) && test()){\r |
7b40affb | 298 | tests[hits].modulation = 1;\r |
299 | tests[hits].inversed = 0;\r | |
33add187 | 300 | ++hits;\r |
301 | }\r | |
302 | if ( FSKrawDemod("0 1", FALSE) && test()) {\r | |
7b40affb | 303 | tests[hits].modulation = 1;\r |
304 | tests[hits].inversed = 1;\r | |
33add187 | 305 | ++hits;\r |
7b40affb | 306 | }\r |
83a42ef9 | 307 | } else {\r |
33add187 | 308 | if ( ASKmanDemod("0 0 1", FALSE, FALSE) && test()) {\r |
7b40affb | 309 | tests[hits].modulation = 2;\r |
310 | tests[hits].inversed = 0;\r | |
33add187 | 311 | ++hits;\r |
7b40affb | 312 | }\r |
33add187 | 313 | \r |
314 | if ( ASKmanDemod("0 1 1", FALSE, FALSE) && test()) {\r | |
7b40affb | 315 | tests[hits].modulation = 2;\r |
316 | tests[hits].inversed = 1;\r | |
33add187 | 317 | ++hits;\r |
7b40affb | 318 | }\r |
83a42ef9 | 319 | \r |
33add187 | 320 | if ( NRZrawDemod("0 0 1", FALSE) && test()) {\r |
7b40affb | 321 | tests[hits].modulation = 3;\r |
322 | tests[hits].inversed = 0;\r | |
33add187 | 323 | ++hits;\r |
324 | }\r | |
83a42ef9 | 325 | \r |
33add187 | 326 | if ( NRZrawDemod("0 1 1", FALSE) && test()) {\r |
7b40affb | 327 | tests[hits].modulation = 3;\r |
328 | tests[hits].inversed = 1;\r | |
33add187 | 329 | ++hits;\r |
7b40affb | 330 | }\r |
118bfa1b | 331 | \r |
33add187 | 332 | if ( PSKDemod("0 0 1", FALSE) && test()) {\r |
7b40affb | 333 | tests[hits].modulation = 4;\r |
334 | tests[hits].inversed = 0;\r | |
33add187 | 335 | ++hits;\r |
336 | }\r | |
118bfa1b | 337 | \r |
33add187 | 338 | if ( PSKDemod("0 1 1", FALSE) && test()) {\r |
7b40affb | 339 | tests[++hits].modulation = 4;\r |
340 | tests[hits].inversed = 1;\r | |
33add187 | 341 | ++hits;\r |
342 | }\r | |
343 | //PSK2?\r | |
344 | // if (!BiphaseRawDecode("0",FALSE) && test()) {\r | |
7b40affb | 345 | // tests[++hits].modulation = 5;\r |
346 | // tests[hits].inversed = 0;\r | |
33add187 | 347 | //}\r |
348 | // if (!BiphaseRawDecode("1",FALSE) && test()) {\r | |
7b40affb | 349 | // tests[++hits].modulation = 5;\r |
350 | // tests[hits].inversed = 1;\r | |
33add187 | 351 | // }\r |
352 | } \r | |
7b40affb | 353 | if ( hits == 1) {\r |
354 | PrintAndLog("Modulation: %d Inverse: %d", tests[0].modulation, tests[0].inversed);\r | |
355 | config.modulation = tests[0].modulation;\r | |
356 | config.inversed = tests[0].inversed;\r | |
33add187 | 357 | return TRUE;\r |
7b40affb | 358 | }\r |
33add187 | 359 | \r |
7b40affb | 360 | if ( hits > 1) {\r |
33add187 | 361 | PrintAndLog("Found [%d] possible matches for modulation.",hits);\r |
7b40affb | 362 | for(int i=0; i<hits; ++i){\r |
363 | PrintAndLog("Modulation: %d Inverse: %d", tests[i].modulation, tests[i].inversed);\r | |
364 | }\r | |
365 | }\r | |
33add187 | 366 | return FALSE;\r |
83a42ef9 | 367 | }\r |
33add187 | 368 | \r |
3e4811c8 | 369 | bool test(){\r |
370 | \r | |
371 | if ( !DemodBufferLen) \r | |
372 | return false;\r | |
373 | \r | |
374 | uint8_t si = 1;\r | |
375 | uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; \r | |
376 | uint8_t resv = PackBits(si, 7, DemodBuffer); si += 7+3;\r | |
377 | uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1;\r | |
378 | \r | |
379 | //PrintAndLog("test: %X %X %X ", safer, resv, extend);\r | |
380 | \r | |
381 | // 2nibble must be zeroed.\r | |
382 | if ( resv > 0x00) return FALSE;\r | |
383 | \r | |
384 | if ( safer == 0x6 || safer == 0x9){\r | |
385 | if ( extend == 0x00)\r | |
386 | return TRUE;\r | |
387 | }\r | |
388 | if ( resv== 0x00) return TRUE;\r | |
389 | return FALSE;\r | |
390 | }\r | |
83a42ef9 | 391 | \r |
33add187 | 392 | void printT55xxBlock(const char *demodStr){\r |
68008fb5 | 393 | \r |
83a42ef9 | 394 | uint32_t blockData = 0;\r |
395 | uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0x00};\r | |
396 | \r | |
68008fb5 | 397 | if ( !DemodBufferLen) \r |
83a42ef9 | 398 | return;\r |
4e7af352 | 399 | \r |
83a42ef9 | 400 | int i =0;\r |
68008fb5 | 401 | for (;i<DemodBufferLen;++i)\r |
402 | bits[i]=DemodBuffer[i];\r | |
385f3987 | 403 | \r |
0310364d | 404 | blockData = PackBits(1, 32, bits);\r |
33add187 | 405 | PrintAndLog("0x%08X %s [%s]", blockData, sprint_bin(bits+1,32), demodStr);\r |
54a942b0 | 406 | }\r |
407 | \r | |
4e7af352 | 408 | /*\r |
409 | FSK1 / FSK1a\r | |
410 | size = fskdemod(dest, size, 32, 0, 8, 10); // fsk1 RF/32 \r | |
411 | size = fskdemod(dest, size, 32, 1, 8, 10); // fsk1a RF/32 \r | |
412 | \r | |
413 | FSK2 / FSK2a\r | |
414 | size = fskdemod(dest, size, 32, 0, 10, 8); // fsk2 RF/32 \r | |
415 | size = fskdemod(dest, size, 32, 1, 10, 8); // fsk2a RF/32 \r | |
416 | size = fskdemod(dest, size, 50, 1, 10, 8); // fsk2a RF/50 \r | |
417 | size = fskdemod(dest, size, 64, 1, 10, 8); // FSK2a RF/64 \r | |
418 | \r | |
419 | PSK1\r | |
420 | errCnt = pskRawDemod(bits, &bitlen, 32, 0);\r | |
421 | */\r | |
33add187 | 422 | int CmdT55xxWriteBlock(const char *Cmd)\r |
54a942b0 | 423 | {\r |
4ecde0e1 | 424 | int block = 8; //default to invalid block\r |
425 | int data = 0xFFFFFFFF; //default to blank Block \r | |
426 | int password = 0xFFFFFFFF; //default to blank Block 7\r | |
427 | \r | |
428 | char cmdp = param_getchar(Cmd, 0);\r | |
429 | if (cmdp == 'h' || cmdp == 'H') {\r | |
68008fb5 | 430 | usage_t55xx_write();\r |
4ecde0e1 | 431 | return 0;\r |
432 | }\r | |
433 | \r | |
434 | int res = sscanf(Cmd, "%d %x %x",&block, &data, &password);\r | |
435 | \r | |
436 | if ( res < 2 || res > 3) {\r | |
68008fb5 | 437 | usage_t55xx_write();\r |
4ecde0e1 | 438 | return 1;\r |
439 | }\r | |
54a942b0 | 440 | \r |
4ecde0e1 | 441 | if (block > 7) {\r |
b44e5233 | 442 | PrintAndLog("Block must be between 0 and 7");\r |
443 | return 1;\r | |
f38a1528 | 444 | }\r |
4ecde0e1 | 445 | \r |
446 | UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}};\r | |
447 | c.d.asBytes[0] = 0x0; \r | |
54a942b0 | 448 | \r |
68008fb5 | 449 | PrintAndLog("Writing to T55x7");\r |
450 | PrintAndLog("block : %d", block);\r | |
451 | PrintAndLog("data : 0x%08X", data);\r | |
452 | \r | |
453 | //Password mode\r | |
454 | if (res == 3) {\r | |
4ecde0e1 | 455 | c.arg[2] = password;\r |
456 | c.d.asBytes[0] = 0x1; \r | |
68008fb5 | 457 | PrintAndLog("pwd : 0x%08X", password);\r |
4ecde0e1 | 458 | }\r |
4ecde0e1 | 459 | SendCommand(&c);\r |
460 | return 0;\r | |
54a942b0 | 461 | }\r |
462 | \r | |
33add187 | 463 | int CmdT55xxReadTrace(const char *Cmd)\r |
54a942b0 | 464 | {\r |
0310364d | 465 | char cmdp = param_getchar(Cmd, 0);\r |
466 | \r | |
7b40affb | 467 | if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') \r |
468 | return usage_t55xx_trace();\r | |
f38a1528 | 469 | \r |
fbceacc5 | 470 | if ( strlen(Cmd)==0){\r |
c4e3b1b6 | 471 | \r |
fbceacc5 | 472 | UsbCommand c = {CMD_T55XX_READ_TRACE, {0, 0, 0}};\r |
473 | SendCommand(&c);\r | |
68008fb5 | 474 | if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r |
475 | PrintAndLog("command execution time out");\r | |
476 | return 1;\r | |
477 | }\r | |
7b40affb | 478 | \r |
479 | uint8_t got[12000];\r | |
480 | GetFromBigBuf(got,sizeof(got),0);\r | |
481 | WaitForResponse(CMD_ACK,NULL);\r | |
482 | setGraphBuf(got, 12000);\r | |
f38a1528 | 483 | }\r |
f38a1528 | 484 | \r |
7b40affb | 485 | DecodeT55xxBlock();\r |
486 | \r | |
487 | if ( !DemodBufferLen) \r | |
83a42ef9 | 488 | return 2;\r |
489 | \r | |
f6c18637 | 490 | RepaintGraphWindow();\r |
b44e5233 | 491 | \r |
f6c18637 | 492 | uint8_t si = 5;\r |
7b40affb | 493 | uint32_t bl0 = PackBits(si, 32, DemodBuffer);\r |
494 | uint32_t bl1 = PackBits(si+32, 32, DemodBuffer);\r | |
495 | \r | |
496 | uint32_t acl = PackBits(si, 8, DemodBuffer); si += 8;\r | |
497 | uint32_t mfc = PackBits(si, 8, DemodBuffer); si += 8;\r | |
498 | uint32_t cid = PackBits(si, 5, DemodBuffer); si += 5;\r | |
499 | uint32_t icr = PackBits(si, 3, DemodBuffer); si += 3;\r | |
500 | uint32_t year = PackBits(si, 4, DemodBuffer); si += 4;\r | |
501 | uint32_t quarter = PackBits(si, 2, DemodBuffer); si += 2;\r | |
502 | uint32_t lotid = PackBits(si, 12, DemodBuffer); si += 12;\r | |
503 | uint32_t wafer = PackBits(si, 5, DemodBuffer); si += 5;\r | |
504 | uint32_t dw = PackBits(si, 15, DemodBuffer); \r | |
505 | \r | |
506 | year += 2000;\r | |
f6c18637 | 507 | \r |
508 | PrintAndLog("");\r | |
509 | PrintAndLog("-- T55xx Trace Information ----------------------------------");\r | |
510 | PrintAndLog("-------------------------------------------------------------");\r | |
511 | PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl, acl);\r | |
512 | PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d)", mfc, mfc);\r | |
513 | PrintAndLog(" CID : 0x%02X (%d)", cid, cid);\r | |
514 | PrintAndLog(" ICR IC Revision : %d",icr );\r | |
515 | PrintAndLog(" Manufactured");\r | |
7b40affb | 516 | PrintAndLog(" Year/Quarter : %d/%d",year, quarter );\r |
77376577 | 517 | PrintAndLog(" Lot ID : %d", lotid );\r |
f6c18637 | 518 | PrintAndLog(" Wafer number : %d", wafer);\r |
519 | PrintAndLog(" Die Number : %d", dw);\r | |
520 | PrintAndLog("-------------------------------------------------------------");\r | |
77376577 | 521 | PrintAndLog(" Raw Data - Page 1");\r |
7b40affb | 522 | PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+5,32) );\r |
523 | PrintAndLog(" Block 0 : 0x%08X %s", bl1, sprint_bin(DemodBuffer+37,32) );\r | |
f6c18637 | 524 | PrintAndLog("-------------------------------------------------------------");\r |
525 | /*\r | |
526 | TRACE - BLOCK O\r | |
527 | Bits Definition HEX\r | |
528 | 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0 \r | |
529 | 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation\r | |
530 | 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2 \r | |
531 | 22-24 ICR IC revision\r | |
532 | 25-28 YEAR (BCD encoded) 9 (= 2009)\r | |
533 | 29-30 QUARTER 1,2,3,4 \r | |
77376577 | 534 | 31-32 LOT ID\r |
f6c18637 | 535 | \r |
536 | TRACE - BLOCK 1\r | |
77376577 | 537 | 1-12 LOT ID \r |
f6c18637 | 538 | 13-17 Wafer number\r |
539 | 18-32 DW, die number sequential\r | |
540 | */\r | |
541 | \r | |
542 | return 0;\r | |
543 | }\r | |
f38a1528 | 544 | \r |
33add187 | 545 | int CmdT55xxInfo(const char *Cmd){\r |
f6c18637 | 546 | /*\r |
547 | Page 0 Block 0 Configuration data.\r | |
548 | Normal mode\r | |
549 | Extended mode\r | |
550 | */\r | |
fbceacc5 | 551 | char cmdp = param_getchar(Cmd, 0);\r |
552 | \r | |
7b40affb | 553 | if (cmdp == 'h' || cmdp == 'H')\r |
83a42ef9 | 554 | return usage_t55xx_info();\r |
7b40affb | 555 | \r |
556 | if (strlen(Cmd)==0){\r | |
557 | \r | |
558 | // read block 0, Page 0. Configuration.\r | |
559 | UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, 0, 0}};\r | |
560 | c.d.asBytes[0] = 0x0; \r | |
561 | \r | |
562 | //Password mode\r | |
563 | // if ( res == 2 ) {\r | |
564 | // c.arg[2] = password;\r | |
565 | // c.d.asBytes[0] = 0x1; \r | |
566 | // }\r | |
567 | \r | |
568 | SendCommand(&c);\r | |
569 | if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r | |
570 | PrintAndLog("command execution time out");\r | |
571 | return 1;\r | |
572 | }\r | |
fbceacc5 | 573 | \r |
7b40affb | 574 | uint8_t got[12000];\r |
575 | GetFromBigBuf(got,sizeof(got),0);\r | |
576 | WaitForResponse(CMD_ACK,NULL);\r | |
577 | setGraphBuf(got, 12000);\r | |
578 | }\r | |
83a42ef9 | 579 | \r |
7b40affb | 580 | DecodeT55xxBlock();\r |
8d0a3e87 | 581 | \r |
7b40affb | 582 | if ( !DemodBufferLen) \r |
583 | return 2;\r | |
584 | \r | |
585 | \r | |
83a42ef9 | 586 | uint8_t si = 1;\r |
7b40affb | 587 | uint32_t bl0 = PackBits(si, 32, DemodBuffer);\r |
588 | \r | |
589 | uint32_t safer = PackBits(si, 4, DemodBuffer); si += 4; \r | |
590 | uint32_t resv = PackBits(si, 7, DemodBuffer); si += 7;\r | |
591 | uint32_t dbr = PackBits(si, 3, DemodBuffer); si += 3;\r | |
592 | uint32_t extend = PackBits(si, 1, DemodBuffer); si += 1;\r | |
593 | uint32_t datamod = PackBits(si, 5, DemodBuffer); si += 5;\r | |
594 | uint32_t pskcf = PackBits(si, 2, DemodBuffer); si += 2;\r | |
595 | uint32_t aor = PackBits(si, 1, DemodBuffer); si += 1; \r | |
596 | uint32_t otp = PackBits(si, 1, DemodBuffer); si += 1; \r | |
597 | uint32_t maxblk = PackBits(si, 3, DemodBuffer); si += 3;\r | |
598 | uint32_t pwd = PackBits(si, 1, DemodBuffer); si += 1; \r | |
599 | uint32_t sst = PackBits(si, 1, DemodBuffer); si += 1; \r | |
600 | uint32_t fw = PackBits(si, 1, DemodBuffer); si += 1;\r | |
601 | uint32_t inv = PackBits(si, 1, DemodBuffer); si += 1; \r | |
602 | uint32_t por = PackBits(si, 1, DemodBuffer); si += 1;\r | |
b44e5233 | 603 | \r |
f6c18637 | 604 | PrintAndLog("");\r |
99a71418 | 605 | PrintAndLog("-- T55xx Configuration & Tag Information --------------------");\r |
f6c18637 | 606 | PrintAndLog("-------------------------------------------------------------");\r |
607 | PrintAndLog(" Safer key : %s", GetSaferStr(safer));\r | |
608 | PrintAndLog(" reserved : %d", resv);\r | |
609 | PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr));\r | |
610 | PrintAndLog(" eXtended mode : %s", (extend) ? "Yes - Warning":"No");\r | |
3e4811c8 | 611 | PrintAndLog(" Modulation : %s", GetModulationStr(datamod));\r |
f6c18637 | 612 | PrintAndLog(" PSK clock freq : %d", pskcf);\r |
613 | PrintAndLog(" AOR - Answer on Request : %s", (aor) ? "Yes":"No");\r | |
614 | PrintAndLog(" OTP - One Time Pad : %s", (otp) ? "Yes - Warning":"No" );\r | |
615 | PrintAndLog(" Max block : %d", maxblk);\r | |
616 | PrintAndLog(" Password mode : %s", (pwd) ? "Yes":"No");\r | |
617 | PrintAndLog(" Sequence Start Terminator : %s", (sst) ? "Yes":"No");\r | |
3e4811c8 | 618 | PrintAndLog(" Fast Write : %s", (fw) ? "Yes":"No");\r |
f6c18637 | 619 | PrintAndLog(" Inverse data : %s", (inv) ? "Yes":"No");\r |
620 | PrintAndLog(" POR-Delay : %s", (por) ? "Yes":"No");\r | |
621 | PrintAndLog("-------------------------------------------------------------");\r | |
77376577 | 622 | PrintAndLog(" Raw Data - Page 0");\r |
7b40affb | 623 | PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+5,32) );\r |
f6c18637 | 624 | PrintAndLog("-------------------------------------------------------------");\r |
625 | \r | |
626 | return 0;\r | |
627 | }\r | |
628 | \r | |
33add187 | 629 | int CmdT55xxDump(const char *Cmd){\r |
77376577 | 630 | \r |
4ecde0e1 | 631 | char s[20] = {0x00};\r |
77376577 | 632 | uint8_t pwd[4] = {0x00};\r |
54a942b0 | 633 | \r |
4ecde0e1 | 634 | char cmdp = param_getchar(Cmd, 0);\r |
149aeada | 635 | if ( cmdp == 'h' || cmdp == 'H') {\r |
4ecde0e1 | 636 | usage_t55xx_dump();\r |
77376577 | 637 | return 0;\r |
638 | }\r | |
4ecde0e1 | 639 | \r |
640 | bool hasPwd = ( strlen(Cmd) > 0); \r | |
77376577 | 641 | if ( hasPwd ){\r |
2ae8a312 | 642 | if (param_gethex(Cmd, 0, pwd, 8)) {\r |
643 | PrintAndLog("password must include 8 HEX symbols");\r | |
c4e3b1b6 | 644 | return 1;\r |
77376577 | 645 | }\r |
646 | }\r | |
a501c82b | 647 | \r |
77376577 | 648 | for ( int i = 0; i <8; ++i){\r |
149aeada | 649 | memset(s,0,sizeof(s));\r |
77376577 | 650 | if ( hasPwd ) {\r |
c6be64da | 651 | sprintf(s,"%d %02x%02x%02x%02x", i, pwd[0],pwd[1],pwd[2],pwd[3]);\r |
77376577 | 652 | } else {\r |
653 | sprintf(s,"%d", i);\r | |
77376577 | 654 | }\r |
33add187 | 655 | CmdT55xxReadBlock(s);\r |
77376577 | 656 | }\r |
657 | return 0;\r | |
658 | }\r | |
659 | \r | |
f6c18637 | 660 | char * GetBitRateStr(uint32_t id){\r |
661 | static char buf[40];\r | |
662 | char *retStr = buf;\r | |
663 | switch (id){\r | |
664 | case 0: \r | |
665 | sprintf(retStr,"%d - RF/8",id);\r | |
666 | break;\r | |
667 | case 1:\r | |
668 | sprintf(retStr,"%d - RF/16",id);\r | |
669 | break;\r | |
670 | case 2: \r | |
671 | sprintf(retStr,"%d - RF/32",id);\r | |
672 | break;\r | |
673 | case 3:\r | |
674 | sprintf(retStr,"%d - RF/40",id);\r | |
675 | break;\r | |
676 | case 4:\r | |
677 | sprintf(retStr,"%d - RF/50",id);\r | |
678 | break;\r | |
679 | case 5:\r | |
680 | sprintf(retStr,"%d - RF/64",id);\r | |
681 | break;\r | |
682 | case 6:\r | |
683 | sprintf(retStr,"%d - RF/100",id);\r | |
684 | break;\r | |
685 | case 7:\r | |
686 | sprintf(retStr,"%d - RF/128",id);\r | |
687 | break;\r | |
688 | default:\r | |
689 | sprintf(retStr,"%d - (Unknown)",id);\r | |
690 | break;\r | |
691 | }\r | |
692 | \r | |
693 | return buf;\r | |
694 | }\r | |
695 | \r | |
f6c18637 | 696 | char * GetSaferStr(uint32_t id){\r |
697 | static char buf[40];\r | |
698 | char *retStr = buf;\r | |
699 | \r | |
700 | sprintf(retStr,"%d",id);\r | |
701 | if (id == 6) {\r | |
3e4811c8 | 702 | sprintf(retStr,"%d - passwd",id);\r |
f6c18637 | 703 | }\r |
704 | if (id == 9 ){\r | |
3e4811c8 | 705 | sprintf(retStr,"%d - testmode",id);\r |
f6c18637 | 706 | }\r |
707 | \r | |
708 | return buf;\r | |
709 | }\r | |
710 | char * GetModulationStr( uint32_t id){\r | |
711 | static char buf[40];\r | |
712 | char *retStr = buf;\r | |
713 | \r | |
714 | switch (id){\r | |
715 | case 0: \r | |
7bd30f12 | 716 | sprintf(retStr,"%d - DIRECT (ASK/NRZ)",id);\r |
f6c18637 | 717 | break;\r |
718 | case 1:\r | |
719 | sprintf(retStr,"%d - PSK 1 phase change when input changes",id);\r | |
720 | break;\r | |
721 | case 2: \r | |
722 | sprintf(retStr,"%d - PSK 2 phase change on bitclk if input high",id);\r | |
723 | break;\r | |
724 | case 3:\r | |
725 | sprintf(retStr,"%d - PSK 3 phase change on rising edge of input",id);\r | |
726 | break;\r | |
727 | case 4:\r | |
728 | sprintf(retStr,"%d - FSK 1 RF/8 RF/5",id);\r | |
729 | break;\r | |
730 | case 5:\r | |
731 | sprintf(retStr,"%d - FSK 2 RF/8 RF/10",id);\r | |
732 | break;\r | |
733 | case 6:\r | |
734 | sprintf(retStr,"%d - FSK 1a RF/5 RF/8",id);\r | |
735 | break;\r | |
736 | case 7:\r | |
737 | sprintf(retStr,"%d - FSK 2a RF/10 RF/8",id);\r | |
738 | break;\r | |
739 | case 8:\r | |
740 | sprintf(retStr,"%d - Manschester",id);\r | |
741 | break;\r | |
742 | case 16:\r | |
743 | sprintf(retStr,"%d - Biphase",id);\r | |
744 | break;\r | |
745 | case 17:\r | |
746 | sprintf(retStr,"%d - Reserved",id);\r | |
747 | break;\r | |
748 | default:\r | |
749 | sprintf(retStr,"0x%02X (Unknown)",id);\r | |
750 | break;\r | |
751 | }\r | |
752 | return buf;\r | |
753 | }\r | |
754 | \r | |
f6c18637 | 755 | uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits){\r |
756 | \r | |
757 | int i = start;\r | |
758 | int j = len-1;\r | |
3bc3598e | 759 | if (len > 32) {\r |
760 | return 0;\r | |
761 | }\r | |
f6c18637 | 762 | uint32_t tmp = 0;\r |
763 | for (; j >= 0; --j, ++i){\r | |
764 | tmp |= bits[i] << j;\r | |
765 | }\r | |
766 | return tmp;\r | |
54a942b0 | 767 | }\r |
768 | \r | |
769 | static command_t CommandTable[] =\r | |
770 | {\r | |
83a42ef9 | 771 | {"help", CmdHelp, 1, "This help"},\r |
772 | {"config", CmdT55xxSetConfig, 1, "Set T55XX config for modulation, inversed data"},\r | |
33add187 | 773 | {"detect", CmdT55xxDetect, 0, "Try detecting the tag modulation from reading the configuration block."},\r |
774 | {"read", CmdT55xxReadBlock, 0, "<block> [password] -- Read T55xx block data (page 0) [optional password]"},\r | |
775 | {"write", CmdT55xxWriteBlock,0, "<block> <data> [password] -- Write T55xx block data (page 0) [optional password]"},\r | |
776 | {"trace", CmdT55xxReadTrace, 0, "[1] Show T55xx traceability data (page 1/ blk 0-1)"},\r | |
777 | {"info", CmdT55xxInfo, 0, "[1] Show T55xx configuration data (page 0/ blk 0)"},\r | |
778 | {"dump", CmdT55xxDump, 0, "[password] Dump T55xx card block 0-7. [optional password]"},\r | |
54a942b0 | 779 | {NULL, NULL, 0, NULL}\r |
780 | };\r | |
781 | \r | |
782 | int CmdLFT55XX(const char *Cmd)\r | |
783 | {\r | |
784 | CmdsParse(CommandTable, Cmd);\r | |
785 | return 0;\r | |
786 | }\r | |
787 | \r | |
788 | int CmdHelp(const char *Cmd)\r | |
789 | {\r | |
790 | CmdsHelp(CommandTable);\r | |
791 | return 0;\r | |
792 | }\r |