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