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