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