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