]>
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 | |
224ce36e | 13 | #include <time.h>\r |
54a942b0 | 14 | #include "proxmark3.h"\r |
15 | #include "ui.h"\r | |
16 | #include "graph.h"\r | |
13d77ef9 | 17 | #include "cmdmain.h"\r |
54a942b0 | 18 | #include "cmdparser.h"\r |
19 | #include "cmddata.h"\r | |
20 | #include "cmdlf.h"\r | |
21 | #include "cmdlft55xx.h"\r | |
13d77ef9 | 22 | #include "util.h"\r |
23 | #include "data.h"\r | |
24 | #include "lfdemod.h"\r | |
25 | #include "../common/crc.h"\r | |
26 | #include "../common/iso14443crc.h"\r | |
27 | #include "cmdhf14a.h"\r | |
28 | \r | |
1d0ccbe0 | 29 | #define T55x7_CONFIGURATION_BLOCK 0x00\r |
30 | #define T55x7_PAGE0 0x00\r | |
31 | #define T55x7_PAGE1 0x01\r | |
952a812c | 32 | #define T55x7_PWD 0x00000010\r |
1d0ccbe0 | 33 | #define REGULAR_READ_MODE_BLOCK 0xFF\r |
13d77ef9 | 34 | \r |
35 | // Default configuration\r | |
6426f6ba | 36 | t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = FALSE, .offset = 0x00, .block0 = 0x00, .Q5 = FALSE };\r |
13d77ef9 | 37 | \r |
94422fa2 | 38 | t55xx_conf_block_t Get_t55xx_Config(){\r |
39 | return config;\r | |
40 | }\r | |
41 | void Set_t55xx_Config(t55xx_conf_block_t conf){\r | |
42 | config = conf;\r | |
43 | }\r | |
44 | \r | |
13d77ef9 | 45 | int usage_t55xx_config(){\r |
6426f6ba | 46 | PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>] [Q5]");\r |
9276e859 | 47 | PrintAndLog("Options:");\r |
13d77ef9 | 48 | PrintAndLog(" h This help");\r |
49 | PrintAndLog(" b <8|16|32|40|50|64|100|128> Set bitrate");\r | |
e98572a1 | 50 | PrintAndLog(" d <FSK|FSK1|FSK1a|FSK2|FSK2a|ASK|PSK1|PSK2|NRZ|BI|BIa> Set demodulation FSK / ASK / PSK / NRZ / Biphase / Biphase A");\r |
13d77ef9 | 51 | PrintAndLog(" i [1] Invert data signal, defaults to normal");\r |
52 | PrintAndLog(" o [offset] Set offset, where data should start decode in bitstream");\r | |
6426f6ba | 53 | PrintAndLog(" Q5 Set as Q5(T5555) chip instead of T55x7");\r |
13d77ef9 | 54 | PrintAndLog("");\r |
55 | PrintAndLog("Examples:");\r | |
56 | PrintAndLog(" lf t55xx config d FSK - FSK demodulation");\r | |
57 | PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");\r | |
58 | PrintAndLog(" lf t55xx config d FSK i 1 o 3 - FSK demodulation, inverse data, offset=3,start from position 3 to decode data");\r | |
59 | PrintAndLog("");\r | |
60 | return 0;\r | |
61 | }\r | |
62 | int usage_t55xx_read(){\r | |
1d0ccbe0 | 63 | PrintAndLog("Usage: lf t55xx read [b <block>] [p <password>] <override_safety> <page1>");\r |
9276e859 | 64 | PrintAndLog("Options:");\r |
1d0ccbe0 | 65 | PrintAndLog(" b <block> - block number to read. Between 0-7");\r |
66 | PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");\r | |
67 | PrintAndLog(" o - OPTIONAL override safety check");\r | |
68 | PrintAndLog(" 1 - OPTIONAL read Page 1 instead of Page 0");\r | |
9276e859 | 69 | PrintAndLog(" ****WARNING****");\r |
70 | PrintAndLog(" Use of read with password on a tag not configured for a pwd");\r | |
71 | PrintAndLog(" can damage the tag");\r | |
13d77ef9 | 72 | PrintAndLog("");\r |
73 | PrintAndLog("Examples:");\r | |
9276e859 | 74 | PrintAndLog(" lf t55xx read b 0 - read data from block 0");\r |
75 | PrintAndLog(" lf t55xx read b 0 p feedbeef - read data from block 0 password feedbeef");\r | |
76 | PrintAndLog(" lf t55xx read b 0 p feedbeef o - read data from block 0 password feedbeef safety check");\r | |
13d77ef9 | 77 | PrintAndLog("");\r |
78 | return 0;\r | |
79 | }\r | |
80 | int usage_t55xx_write(){\r | |
1d0ccbe0 | 81 | PrintAndLog("Usage: lf t55xx wr [b <block>] [d <data>] [p <password>] [1]");\r |
9276e859 | 82 | PrintAndLog("Options:");\r |
1d0ccbe0 | 83 | PrintAndLog(" b <block> - block number to write. Between 0-7");\r |
84 | PrintAndLog(" d <data> - 4 bytes of data to write (8 hex characters)");\r | |
85 | PrintAndLog(" p <password> - OPTIONAL password 4bytes (8 hex characters)");\r | |
86 | PrintAndLog(" 1 - OPTIONAL write Page 1 instead of Page 0");\r | |
13d77ef9 | 87 | PrintAndLog("");\r |
88 | PrintAndLog("Examples:");\r | |
1d0ccbe0 | 89 | PrintAndLog(" lf t55xx write b 3 d 11223344 - write 11223344 to block 3");\r |
90 | PrintAndLog(" lf t55xx write b 3 d 11223344 p feedbeef - write 11223344 to block 3 password feedbeef");\r | |
13d77ef9 | 91 | PrintAndLog("");\r |
92 | return 0;\r | |
93 | }\r | |
94 | int usage_t55xx_trace() {\r | |
95 | PrintAndLog("Usage: lf t55xx trace [1]");\r | |
9276e859 | 96 | PrintAndLog("Options:");\r |
1d0ccbe0 | 97 | PrintAndLog(" [graph buffer data] - if set, use Graphbuffer otherwise read data from tag.");\r |
13d77ef9 | 98 | PrintAndLog("");\r |
99 | PrintAndLog("Examples:");\r | |
100 | PrintAndLog(" lf t55xx trace");\r | |
101 | PrintAndLog(" lf t55xx trace 1");\r | |
102 | PrintAndLog("");\r | |
103 | return 0;\r | |
104 | }\r | |
105 | int usage_t55xx_info() {\r | |
106 | PrintAndLog("Usage: lf t55xx info [1]");\r | |
9276e859 | 107 | PrintAndLog("Options:");\r |
1d0ccbe0 | 108 | PrintAndLog(" [graph buffer data] - if set, use Graphbuffer otherwise read data from tag.");\r |
13d77ef9 | 109 | PrintAndLog("");\r |
110 | PrintAndLog("Examples:");\r | |
111 | PrintAndLog(" lf t55xx info");\r | |
112 | PrintAndLog(" lf t55xx info 1");\r | |
113 | PrintAndLog("");\r | |
114 | return 0;\r | |
115 | }\r | |
116 | int usage_t55xx_dump(){\r | |
1d0ccbe0 | 117 | PrintAndLog("Usage: lf t55xx dump <password> [o]");\r |
9276e859 | 118 | PrintAndLog("Options:");\r |
1d0ccbe0 | 119 | PrintAndLog(" <password> - OPTIONAL password 4bytes (8 hex symbols)");\r |
120 | PrintAndLog(" o - OPTIONAL override, force pwd read despite danger to card");\r | |
13d77ef9 | 121 | PrintAndLog("");\r |
122 | PrintAndLog("Examples:");\r | |
123 | PrintAndLog(" lf t55xx dump");\r | |
1d0ccbe0 | 124 | PrintAndLog(" lf t55xx dump feedbeef o");\r |
13d77ef9 | 125 | PrintAndLog("");\r |
126 | return 0;\r | |
127 | }\r | |
128 | int usage_t55xx_detect(){\r | |
a126332a | 129 | PrintAndLog("Usage: lf t55xx detect [1] [p <password>]");\r |
9276e859 | 130 | PrintAndLog("Options:");\r |
a126332a | 131 | PrintAndLog(" 1 - if set, use Graphbuffer otherwise read data from tag.");\r |
132 | PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");\r | |
13d77ef9 | 133 | PrintAndLog("");\r |
134 | PrintAndLog("Examples:");\r | |
135 | PrintAndLog(" lf t55xx detect");\r | |
136 | PrintAndLog(" lf t55xx detect 1");\r | |
a126332a | 137 | PrintAndLog(" lf t55xx detect 11223344");\r |
13d77ef9 | 138 | PrintAndLog("");\r |
139 | return 0;\r | |
140 | }\r | |
9276e859 | 141 | int usage_t55xx_wakup(){\r |
142 | PrintAndLog("Usage: lf t55xx wakeup [h] p <password>");\r | |
143 | PrintAndLog("This commands send the Answer-On-Request command and leaves the readerfield ON afterwards.");\r | |
144 | PrintAndLog("Options:");\r | |
145 | PrintAndLog(" h - this help");\r | |
146 | PrintAndLog(" p <password> - password 4bytes (8 hex symbols)");\r | |
147 | PrintAndLog("");\r | |
148 | PrintAndLog("Examples:");\r | |
149 | PrintAndLog(" lf t55xx wakeup p 11223344 - send wakeup password");\r | |
150 | return 0;\r | |
151 | }\r | |
54a942b0 | 152 | \r |
153 | static int CmdHelp(const char *Cmd);\r | |
154 | \r | |
6426f6ba | 155 | void printT5xxHeader(uint8_t page){\r |
156 | PrintAndLog("Reading Page %d:", page); \r | |
157 | PrintAndLog("blk | hex data | binary");\r | |
158 | PrintAndLog("----+----------+---------------------------------"); \r | |
159 | }\r | |
160 | \r | |
13d77ef9 | 161 | int CmdT55xxSetConfig(const char *Cmd) {\r |
54a942b0 | 162 | \r |
13d77ef9 | 163 | uint8_t offset = 0;\r |
13d77ef9 | 164 | char modulation[5] = {0x00};\r |
165 | char tmp = 0x00;\r | |
166 | uint8_t bitRate = 0;\r | |
167 | uint8_t rates[9] = {8,16,32,40,50,64,100,128,0};\r | |
6426f6ba | 168 | uint8_t cmdp = 0;\r |
169 | config.Q5 = FALSE;\r | |
170 | bool errors = FALSE;\r | |
171 | while(param_getchar(Cmd, cmdp) != 0x00 && !errors)\r | |
172 | {\r | |
13d77ef9 | 173 | tmp = param_getchar(Cmd, cmdp);\r |
174 | switch(tmp)\r | |
175 | {\r | |
176 | case 'h':\r | |
177 | case 'H':\r | |
178 | return usage_t55xx_config();\r | |
179 | case 'b':\r | |
180 | errors |= param_getdec(Cmd, cmdp+1, &bitRate);\r | |
181 | if ( !errors){\r | |
182 | uint8_t i = 0;\r | |
183 | for (; i < 9; i++){\r | |
184 | if (rates[i]==bitRate) {\r | |
185 | config.bitrate = i;\r | |
186 | break;\r | |
187 | }\r | |
188 | }\r | |
189 | if (i==9) errors = TRUE;\r | |
190 | }\r | |
191 | cmdp+=2;\r | |
192 | break;\r | |
193 | case 'd':\r | |
194 | param_getstr(Cmd, cmdp+1, modulation);\r | |
195 | cmdp += 2;\r | |
54a942b0 | 196 | \r |
2767fc02 | 197 | if ( strcmp(modulation, "FSK" ) == 0) {\r |
13d77ef9 | 198 | config.modulation = DEMOD_FSK;\r |
2767fc02 | 199 | } else if ( strcmp(modulation, "FSK1" ) == 0) {\r |
13d77ef9 | 200 | config.modulation = DEMOD_FSK1;\r |
2767fc02 | 201 | config.inverted=1;\r |
202 | } else if ( strcmp(modulation, "FSK1a" ) == 0) {\r | |
13d77ef9 | 203 | config.modulation = DEMOD_FSK1a;\r |
2767fc02 | 204 | config.inverted=0;\r |
205 | } else if ( strcmp(modulation, "FSK2" ) == 0) {\r | |
13d77ef9 | 206 | config.modulation = DEMOD_FSK2;\r |
2767fc02 | 207 | config.inverted=0;\r |
208 | } else if ( strcmp(modulation, "FSK2a" ) == 0) {\r | |
13d77ef9 | 209 | config.modulation = DEMOD_FSK2a;\r |
2767fc02 | 210 | config.inverted=1;\r |
211 | } else if ( strcmp(modulation, "ASK" ) == 0) {\r | |
13d77ef9 | 212 | config.modulation = DEMOD_ASK;\r |
2767fc02 | 213 | } else if ( strcmp(modulation, "NRZ" ) == 0) {\r |
13d77ef9 | 214 | config.modulation = DEMOD_NRZ;\r |
2767fc02 | 215 | } else if ( strcmp(modulation, "PSK1" ) == 0) {\r |
13d77ef9 | 216 | config.modulation = DEMOD_PSK1;\r |
2767fc02 | 217 | } else if ( strcmp(modulation, "PSK2" ) == 0) {\r |
13d77ef9 | 218 | config.modulation = DEMOD_PSK2;\r |
2767fc02 | 219 | } else if ( strcmp(modulation, "PSK3" ) == 0) {\r |
13d77ef9 | 220 | config.modulation = DEMOD_PSK3;\r |
2767fc02 | 221 | } else if ( strcmp(modulation, "BIa" ) == 0) {\r |
13d77ef9 | 222 | config.modulation = DEMOD_BIa;\r |
2767fc02 | 223 | config.inverted=1;\r |
224 | } else if ( strcmp(modulation, "BI" ) == 0) {\r | |
13d77ef9 | 225 | config.modulation = DEMOD_BI;\r |
2767fc02 | 226 | config.inverted=0;\r |
227 | } else {\r | |
13d77ef9 | 228 | PrintAndLog("Unknown modulation '%s'", modulation);\r |
229 | errors = TRUE;\r | |
230 | }\r | |
231 | break;\r | |
232 | case 'i':\r | |
233 | config.inverted = param_getchar(Cmd,cmdp+1) == '1';\r | |
234 | cmdp+=2;\r | |
235 | break;\r | |
236 | case 'o':\r | |
237 | errors |= param_getdec(Cmd, cmdp+1, &offset);\r | |
238 | if ( !errors )\r | |
239 | config.offset = offset;\r | |
240 | cmdp+=2;\r | |
241 | break;\r | |
6426f6ba | 242 | case 'Q':\r |
243 | case 'q': \r | |
244 | config.Q5 = TRUE;\r | |
245 | cmdp++;\r | |
246 | break;\r | |
13d77ef9 | 247 | default:\r |
248 | PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r | |
249 | errors = TRUE;\r | |
250 | break;\r | |
251 | }\r | |
252 | }\r | |
54a942b0 | 253 | \r |
13d77ef9 | 254 | // No args\r |
1c8fbeb9 | 255 | if (cmdp == 0) return printConfiguration( config );\r |
256 | \r | |
13d77ef9 | 257 | //Validations\r |
1c8fbeb9 | 258 | if (errors) return usage_t55xx_config();\r |
54a942b0 | 259 | \r |
13d77ef9 | 260 | config.block0 = 0;\r |
1c8fbeb9 | 261 | return printConfiguration ( config );\r |
13d77ef9 | 262 | }\r |
54a942b0 | 263 | \r |
1d0ccbe0 | 264 | int T55xxReadBlock(uint8_t block, bool page1, bool usepwd, bool override, uint32_t password){\r |
265 | //Password mode\r | |
266 | if ( usepwd ) {\r | |
267 | // try reading the config block and verify that PWD bit is set before doing this!\r | |
268 | if ( !override ) {\r | |
269 | \r | |
270 | if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, false, 0 ) ) return 0;\r | |
271 | \r | |
272 | if ( !tryDetectModulation() ) {\r | |
273 | PrintAndLog("Safety Check: Could not detect if PWD bit is set in config block. Exits.");\r | |
274 | return 0;\r | |
275 | } else {\r | |
276 | PrintAndLog("Safety Check: PWD bit is NOT set in config block. Reading without password..."); \r | |
277 | usepwd = false;\r | |
278 | page1 = false;\r | |
279 | }\r | |
280 | } else {\r | |
281 | PrintAndLog("Safety Check Overriden - proceeding despite risk");\r | |
282 | }\r | |
283 | }\r | |
284 | \r | |
285 | if (!AquireData(page1, block, usepwd, password) ) return 0;\r | |
286 | if (!DecodeT55xxBlock()) return 0;\r | |
287 | \r | |
288 | char blk[10]={0};\r | |
6426f6ba | 289 | sprintf(blk,"%02d", block);\r |
1d0ccbe0 | 290 | printT55xxBlock(blk); \r |
291 | return 1;\r | |
292 | }\r | |
293 | \r | |
13d77ef9 | 294 | int CmdT55xxReadBlock(const char *Cmd) {\r |
1d0ccbe0 | 295 | uint8_t block = REGULAR_READ_MODE_BLOCK;\r |
1c8fbeb9 | 296 | uint32_t password = 0; //default to blank Block 7\r |
1d0ccbe0 | 297 | bool usepwd = false;\r |
298 | bool override = false;\r | |
299 | bool page1 = false;\r | |
300 | bool errors = false;\r | |
9276e859 | 301 | uint8_t cmdp = 0;\r |
9276e859 | 302 | while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {\r |
303 | switch(param_getchar(Cmd, cmdp)) {\r | |
304 | case 'h':\r | |
305 | case 'H':\r | |
1c8fbeb9 | 306 | return usage_t55xx_read();\r |
9276e859 | 307 | case 'b':\r |
308 | case 'B':\r | |
309 | errors |= param_getdec(Cmd, cmdp+1, &block);\r | |
1c8fbeb9 | 310 | cmdp += 2;\r |
9276e859 | 311 | break;\r |
312 | case 'o':\r | |
313 | case 'O':\r | |
1c8fbeb9 | 314 | override = TRUE;\r |
9276e859 | 315 | cmdp++;\r |
316 | break;\r | |
317 | case 'p':\r | |
318 | case 'P':\r | |
1d0ccbe0 | 319 | password = param_get32ex(Cmd, cmdp+1, 0, 16);\r |
320 | usepwd = true;\r | |
1c8fbeb9 | 321 | cmdp += 2;\r |
9276e859 | 322 | break;\r |
1d0ccbe0 | 323 | case '1':\r |
324 | page1 = true;\r | |
325 | cmdp++;\r | |
326 | break;\r | |
9276e859 | 327 | default:\r |
328 | PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r | |
329 | errors = true;\r | |
330 | break;\r | |
331 | }\r | |
332 | }\r | |
333 | if (errors) return usage_t55xx_read();\r | |
1c8fbeb9 | 334 | \r |
1d0ccbe0 | 335 | if (block > 7 && block != REGULAR_READ_MODE_BLOCK ) {\r |
13d77ef9 | 336 | PrintAndLog("Block must be between 0 and 7");\r |
1d0ccbe0 | 337 | return 0;\r |
13d77ef9 | 338 | }\r |
6426f6ba | 339 | \r |
340 | printT5xxHeader(page1);\r | |
1d0ccbe0 | 341 | return T55xxReadBlock(block, page1, usepwd, override, password);\r |
54a942b0 | 342 | }\r |
343 | \r | |
13d77ef9 | 344 | bool DecodeT55xxBlock(){\r |
345 | \r | |
fef74fdc | 346 | char buf[30] = {0x00};\r |
13d77ef9 | 347 | char *cmdStr = buf;\r |
348 | int ans = 0;\r | |
349 | uint8_t bitRate[8] = {8,16,32,40,50,64,100,128};\r | |
13d77ef9 | 350 | DemodBufferLen = 0x00;\r |
54a942b0 | 351 | \r |
13d77ef9 | 352 | switch( config.modulation ){\r |
353 | case DEMOD_FSK:\r | |
224ce36e | 354 | snprintf(cmdStr, sizeof(buf),"%d %d", bitRate[config.bitrate], config.inverted );\r |
13d77ef9 | 355 | ans = FSKrawDemod(cmdStr, FALSE);\r |
356 | break;\r | |
357 | case DEMOD_FSK1:\r | |
13d77ef9 | 358 | case DEMOD_FSK1a:\r |
224ce36e | 359 | snprintf(cmdStr, sizeof(buf),"%d %d 8 5", bitRate[config.bitrate], config.inverted );\r |
13d77ef9 | 360 | ans = FSKrawDemod(cmdStr, FALSE);\r |
361 | break;\r | |
362 | case DEMOD_FSK2:\r | |
13d77ef9 | 363 | case DEMOD_FSK2a:\r |
224ce36e | 364 | snprintf(cmdStr, sizeof(buf),"%d %d 10 8", bitRate[config.bitrate], config.inverted );\r |
13d77ef9 | 365 | ans = FSKrawDemod(cmdStr, FALSE);\r |
366 | break;\r | |
367 | case DEMOD_ASK:\r | |
6426f6ba | 368 | snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r |
fef74fdc | 369 | ans = ASKDemod(cmdStr, FALSE, FALSE, 1);\r |
13d77ef9 | 370 | break;\r |
371 | case DEMOD_PSK1:\r | |
6426f6ba | 372 | // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r |
373 | CmdLtrim("160");\r | |
374 | snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted );\r | |
13d77ef9 | 375 | ans = PSKDemod(cmdStr, FALSE);\r |
13d77ef9 | 376 | break;\r |
2767fc02 | 377 | case DEMOD_PSK2: //inverted won't affect this\r |
378 | case DEMOD_PSK3: //not fully implemented\r | |
6426f6ba | 379 | // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r |
380 | CmdLtrim("160");\r | |
381 | snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] );\r | |
13d77ef9 | 382 | ans = PSKDemod(cmdStr, FALSE);\r |
383 | psk1TOpsk2(DemodBuffer, DemodBufferLen);\r | |
384 | break;\r | |
385 | case DEMOD_NRZ:\r | |
224ce36e | 386 | snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r |
13d77ef9 | 387 | ans = NRZrawDemod(cmdStr, FALSE);\r |
388 | break;\r | |
389 | case DEMOD_BI:\r | |
13d77ef9 | 390 | case DEMOD_BIa:\r |
6426f6ba | 391 | snprintf(cmdStr, sizeof(buf),"0 %d %d 1", bitRate[config.bitrate], config.inverted );\r |
13d77ef9 | 392 | ans = ASKbiphaseDemod(cmdStr, FALSE);\r |
393 | break;\r | |
394 | default:\r | |
395 | return FALSE;\r | |
396 | }\r | |
397 | return (bool) ans;\r | |
398 | }\r | |
54a942b0 | 399 | \r |
13d77ef9 | 400 | int CmdT55xxDetect(const char *Cmd){\r |
54a942b0 | 401 | \r |
a126332a | 402 | bool errors = FALSE;\r |
403 | bool useGB = FALSE;\r | |
404 | bool usepwd = FALSE;\r | |
405 | uint32_t password = 0;\r | |
406 | uint8_t cmdp = 0;\r | |
1d0ccbe0 | 407 | \r |
a126332a | 408 | while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {\r |
409 | switch(param_getchar(Cmd, cmdp)) {\r | |
410 | case 'h':\r | |
411 | case 'H':\r | |
412 | return usage_t55xx_detect();\r | |
413 | case 'p':\r | |
414 | case 'P':\r | |
415 | password = param_get32ex(Cmd, cmdp+1, 0, 16);\r | |
416 | usepwd = TRUE;\r | |
417 | cmdp += 2;\r | |
418 | break;\r | |
419 | case '1':\r | |
420 | // use Graphbuffer data\r | |
421 | useGB = TRUE;\r | |
422 | cmdp++;\r | |
423 | break;\r | |
424 | default:\r | |
425 | PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r | |
426 | errors = true;\r | |
427 | break;\r | |
428 | }\r | |
1d0ccbe0 | 429 | }\r |
a126332a | 430 | if (errors) return usage_t55xx_detect();\r |
13d77ef9 | 431 | \r |
a126332a | 432 | if ( !useGB) {\r |
433 | if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password) )\r | |
434 | return 0;\r | |
1d0ccbe0 | 435 | }\r |
a126332a | 436 | \r |
13d77ef9 | 437 | if ( !tryDetectModulation() )\r |
438 | PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");\r | |
439 | \r | |
1d0ccbe0 | 440 | return 1;\r |
54a942b0 | 441 | }\r |
442 | \r | |
13d77ef9 | 443 | // detect configuration?\r |
444 | bool tryDetectModulation(){\r | |
13d77ef9 | 445 | uint8_t hits = 0;\r |
446 | t55xx_conf_block_t tests[15];\r | |
fef74fdc | 447 | int bitRate=0;\r |
322f7eb1 | 448 | uint8_t fc1 = 0, fc2 = 0, clk=0;\r |
449 | save_restoreGB(1);\r | |
6426f6ba | 450 | \r |
13d77ef9 | 451 | if (GetFskClock("", FALSE, FALSE)){ \r |
13d77ef9 | 452 | fskClocks(&fc1, &fc2, &clk, FALSE);\r |
6426f6ba | 453 | if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r |
13d77ef9 | 454 | tests[hits].modulation = DEMOD_FSK;\r |
455 | if (fc1==8 && fc2 == 5)\r | |
456 | tests[hits].modulation = DEMOD_FSK1a;\r | |
457 | else if (fc1==10 && fc2 == 8)\r | |
458 | tests[hits].modulation = DEMOD_FSK2;\r | |
fef74fdc | 459 | tests[hits].bitrate = bitRate;\r |
13d77ef9 | 460 | tests[hits].inverted = FALSE;\r |
461 | tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r | |
462 | ++hits;\r | |
463 | }\r | |
6426f6ba | 464 | if ( FSKrawDemod("0 1", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r |
13d77ef9 | 465 | tests[hits].modulation = DEMOD_FSK;\r |
fef74fdc | 466 | if (fc1 == 8 && fc2 == 5)\r |
13d77ef9 | 467 | tests[hits].modulation = DEMOD_FSK1;\r |
fef74fdc | 468 | else if (fc1 == 10 && fc2 == 8)\r |
13d77ef9 | 469 | tests[hits].modulation = DEMOD_FSK2a;\r |
54a942b0 | 470 | \r |
fef74fdc | 471 | tests[hits].bitrate = bitRate;\r |
13d77ef9 | 472 | tests[hits].inverted = TRUE;\r |
473 | tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r | |
474 | ++hits;\r | |
475 | }\r | |
476 | } else {\r | |
322f7eb1 | 477 | clk = GetAskClock("", FALSE, FALSE);\r |
478 | if (clk>0) {\r | |
52f2df61 | 479 | if ( ASKDemod("0 0 1", FALSE, FALSE, 1) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r |
322f7eb1 | 480 | tests[hits].modulation = DEMOD_ASK;\r |
481 | tests[hits].bitrate = bitRate;\r | |
482 | tests[hits].inverted = FALSE;\r | |
483 | tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r | |
484 | ++hits;\r | |
485 | }\r | |
52f2df61 | 486 | if ( ASKDemod("0 1 1", FALSE, FALSE, 1) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r |
322f7eb1 | 487 | tests[hits].modulation = DEMOD_ASK;\r |
488 | tests[hits].bitrate = bitRate;\r | |
489 | tests[hits].inverted = TRUE;\r | |
490 | tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r | |
491 | ++hits;\r | |
492 | }\r | |
6426f6ba | 493 | if ( ASKbiphaseDemod("0 0 0 2", FALSE) && test(DEMOD_BI, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {\r |
322f7eb1 | 494 | tests[hits].modulation = DEMOD_BI;\r |
495 | tests[hits].bitrate = bitRate;\r | |
496 | tests[hits].inverted = FALSE;\r | |
497 | tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r | |
498 | ++hits;\r | |
499 | }\r | |
6426f6ba | 500 | if ( ASKbiphaseDemod("0 0 1 2", FALSE) && test(DEMOD_BIa, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {\r |
322f7eb1 | 501 | tests[hits].modulation = DEMOD_BIa;\r |
502 | tests[hits].bitrate = bitRate;\r | |
503 | tests[hits].inverted = TRUE;\r | |
504 | tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r | |
505 | ++hits;\r | |
506 | }\r | |
13d77ef9 | 507 | }\r |
322f7eb1 | 508 | //undo trim from ask\r |
509 | save_restoreGB(0);\r | |
510 | clk = GetNrzClock("", FALSE, FALSE);\r | |
511 | if (clk>0) {\r | |
6426f6ba | 512 | if ( NRZrawDemod("0 0 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r |
322f7eb1 | 513 | tests[hits].modulation = DEMOD_NRZ;\r |
514 | tests[hits].bitrate = bitRate;\r | |
515 | tests[hits].inverted = FALSE;\r | |
516 | tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r | |
517 | ++hits;\r | |
518 | }\r | |
54a942b0 | 519 | \r |
6426f6ba | 520 | if ( NRZrawDemod("0 1 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r |
322f7eb1 | 521 | tests[hits].modulation = DEMOD_NRZ;\r |
522 | tests[hits].bitrate = bitRate;\r | |
523 | tests[hits].inverted = TRUE;\r | |
524 | tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r | |
525 | ++hits;\r | |
526 | }\r | |
13d77ef9 | 527 | }\r |
528 | \r | |
322f7eb1 | 529 | //undo trim from nrz\r |
530 | save_restoreGB(0);\r | |
6426f6ba | 531 | // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r |
532 | CmdLtrim("160");\r | |
322f7eb1 | 533 | clk = GetPskClock("", FALSE, FALSE);\r |
534 | if (clk>0) {\r | |
6426f6ba | 535 | if ( PSKDemod("0 0 6", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r |
322f7eb1 | 536 | tests[hits].modulation = DEMOD_PSK1;\r |
fef74fdc | 537 | tests[hits].bitrate = bitRate;\r |
13d77ef9 | 538 | tests[hits].inverted = FALSE;\r |
539 | tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r | |
540 | ++hits;\r | |
541 | }\r | |
6426f6ba | 542 | if ( PSKDemod("0 1 6", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r |
322f7eb1 | 543 | tests[hits].modulation = DEMOD_PSK1;\r |
fef74fdc | 544 | tests[hits].bitrate = bitRate;\r |
322f7eb1 | 545 | tests[hits].inverted = TRUE;\r |
13d77ef9 | 546 | tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r |
547 | ++hits;\r | |
548 | }\r | |
322f7eb1 | 549 | // PSK2 - needs a call to psk1TOpsk2.\r |
6426f6ba | 550 | if ( PSKDemod("0 0 6", FALSE)) {\r |
322f7eb1 | 551 | psk1TOpsk2(DemodBuffer, DemodBufferLen);\r |
6426f6ba | 552 | if (test(DEMOD_PSK2, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r |
322f7eb1 | 553 | tests[hits].modulation = DEMOD_PSK2;\r |
554 | tests[hits].bitrate = bitRate;\r | |
555 | tests[hits].inverted = FALSE;\r | |
556 | tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r | |
557 | ++hits;\r | |
558 | }\r | |
559 | } // inverse waves does not affect this demod\r | |
560 | // PSK3 - needs a call to psk1TOpsk2.\r | |
6426f6ba | 561 | if ( PSKDemod("0 0 6", FALSE)) {\r |
322f7eb1 | 562 | psk1TOpsk2(DemodBuffer, DemodBufferLen);\r |
6426f6ba | 563 | if (test(DEMOD_PSK3, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r |
322f7eb1 | 564 | tests[hits].modulation = DEMOD_PSK3;\r |
565 | tests[hits].bitrate = bitRate;\r | |
566 | tests[hits].inverted = FALSE;\r | |
567 | tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r | |
568 | ++hits;\r | |
569 | }\r | |
570 | } // inverse waves does not affect this demod\r | |
13d77ef9 | 571 | }\r |
572 | } \r | |
6426f6ba | 573 | save_restoreGB(0); \r |
13d77ef9 | 574 | if ( hits == 1) {\r |
575 | config.modulation = tests[0].modulation;\r | |
fef74fdc | 576 | config.bitrate = tests[0].bitrate;\r |
13d77ef9 | 577 | config.inverted = tests[0].inverted;\r |
578 | config.offset = tests[0].offset;\r | |
579 | config.block0 = tests[0].block0;\r | |
580 | printConfiguration( config );\r | |
581 | return TRUE;\r | |
582 | }\r | |
583 | \r | |
584 | if ( hits > 1) {\r | |
585 | PrintAndLog("Found [%d] possible matches for modulation.",hits);\r | |
586 | for(int i=0; i<hits; ++i){\r | |
587 | PrintAndLog("--[%d]---------------", i+1);\r | |
588 | printConfiguration( tests[i] );\r | |
589 | }\r | |
590 | }\r | |
591 | return FALSE;\r | |
592 | }\r | |
593 | \r | |
594 | bool testModulation(uint8_t mode, uint8_t modread){\r | |
595 | switch( mode ){\r | |
596 | case DEMOD_FSK:\r | |
94422fa2 | 597 | if (modread >= DEMOD_FSK1 && modread <= DEMOD_FSK2a) return TRUE;\r |
13d77ef9 | 598 | break;\r |
599 | case DEMOD_ASK:\r | |
600 | if (modread == DEMOD_ASK) return TRUE;\r | |
601 | break;\r | |
602 | case DEMOD_PSK1:\r | |
603 | if (modread == DEMOD_PSK1) return TRUE;\r | |
604 | break;\r | |
605 | case DEMOD_PSK2:\r | |
606 | if (modread == DEMOD_PSK2) return TRUE;\r | |
607 | break;\r | |
608 | case DEMOD_PSK3:\r | |
609 | if (modread == DEMOD_PSK3) return TRUE;\r | |
610 | break;\r | |
611 | case DEMOD_NRZ:\r | |
612 | if (modread == DEMOD_NRZ) return TRUE;\r | |
613 | break;\r | |
614 | case DEMOD_BI:\r | |
615 | if (modread == DEMOD_BI) return TRUE;\r | |
616 | break;\r | |
617 | case DEMOD_BIa:\r | |
618 | if (modread == DEMOD_BIa) return TRUE;\r | |
619 | break; \r | |
620 | default:\r | |
621 | return FALSE;\r | |
622 | }\r | |
623 | return FALSE;\r | |
624 | }\r | |
625 | \r | |
6426f6ba | 626 | bool testQ5Modulation(uint8_t mode, uint8_t modread){\r |
627 | switch( mode ){\r | |
13d77ef9 | 628 | case DEMOD_FSK:\r |
6426f6ba | 629 | if (modread >= 4 && modread <= 5) return TRUE;\r |
13d77ef9 | 630 | break;\r |
631 | case DEMOD_ASK:\r | |
6426f6ba | 632 | if (modread == 0) return TRUE;\r |
13d77ef9 | 633 | break;\r |
634 | case DEMOD_PSK1:\r | |
6426f6ba | 635 | if (modread == 1) return TRUE;\r |
636 | break;\r | |
13d77ef9 | 637 | case DEMOD_PSK2:\r |
6426f6ba | 638 | if (modread == 2) return TRUE;\r |
639 | break;\r | |
13d77ef9 | 640 | case DEMOD_PSK3:\r |
6426f6ba | 641 | if (modread == 3) return TRUE;\r |
13d77ef9 | 642 | break;\r |
643 | case DEMOD_NRZ:\r | |
6426f6ba | 644 | if (modread == 7) return TRUE;\r |
645 | break;\r | |
646 | case DEMOD_BI:\r | |
647 | if (modread == 6) return TRUE;\r | |
13d77ef9 | 648 | break;\r |
13d77ef9 | 649 | default:\r |
650 | return FALSE;\r | |
651 | }\r | |
652 | return FALSE;\r | |
653 | }\r | |
654 | \r | |
6426f6ba | 655 | bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk){\r |
656 | \r | |
657 | if ( DemodBufferLen < 64 ) return FALSE;\r | |
658 | uint8_t si = 0;\r | |
659 | for (uint8_t idx = 28; idx < 64; idx++){\r | |
660 | si = idx;\r | |
661 | if ( PackBits(si, 28, DemodBuffer) == 0x00 ) continue;\r | |
662 | \r | |
663 | uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key\r | |
664 | uint8_t resv = PackBits(si, 8, DemodBuffer); si += 8;\r | |
665 | // 2nibble must be zeroed.\r | |
666 | if (safer != 0x6) continue;\r | |
667 | if ( resv > 0x00) continue;\r | |
668 | //uint8_t pageSel = PackBits(si, 1, DemodBuffer); si += 1;\r | |
669 | //uint8_t fastWrite = PackBits(si, 1, DemodBuffer); si += 1;\r | |
670 | si += 1+1;\r | |
671 | int bitRate = PackBits(si, 5, DemodBuffer)*2 + 2; si += 5; //bit rate\r | |
672 | if (bitRate > 128 || bitRate < 8) continue;\r | |
673 | \r | |
674 | //uint8_t AOR = PackBits(si, 1, DemodBuffer); si += 1; \r | |
675 | //uint8_t PWD = PackBits(si, 1, DemodBuffer); si += 1; \r | |
676 | //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2; //could check psk cr\r | |
677 | //uint8_t inverse = PackBits(si, 1, DemodBuffer); si += 1;\r | |
678 | si += 1+1+2+1;\r | |
679 | uint8_t modread = PackBits(si, 3, DemodBuffer); si += 3;\r | |
680 | uint8_t maxBlk = PackBits(si, 3, DemodBuffer); si += 3;\r | |
681 | //uint8_t ST = PackBits(si, 1, DemodBuffer); si += 1;\r | |
682 | if (maxBlk == 0) continue;\r | |
683 | //test modulation\r | |
684 | if (!testQ5Modulation(mode, modread)) continue;\r | |
685 | if (bitRate != clk) continue;\r | |
686 | *fndBitRate = bitRate;\r | |
687 | *offset = idx;\r | |
688 | \r | |
689 | return TRUE;\r | |
690 | }\r | |
691 | return FALSE;\r | |
692 | }\r | |
693 | \r | |
694 | bool testBitRate(uint8_t readRate, uint8_t clk){\r | |
695 | uint8_t expected[] = {8, 16, 32, 40, 50, 64, 100, 128};\r | |
696 | if (expected[readRate] == clk)\r | |
697 | return true;\r | |
698 | \r | |
699 | return false;\r | |
700 | }\r | |
701 | \r | |
702 | bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5){\r | |
13d77ef9 | 703 | \r |
fef74fdc | 704 | if ( DemodBufferLen < 64 ) return FALSE;\r |
13d77ef9 | 705 | uint8_t si = 0;\r |
6426f6ba | 706 | for (uint8_t idx = 28; idx < 64; idx++){\r |
13d77ef9 | 707 | si = idx;\r |
6426f6ba | 708 | if ( PackBits(si, 28, DemodBuffer) == 0x00 ) continue;\r |
13d77ef9 | 709 | \r |
2767fc02 | 710 | uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key\r |
13d77ef9 | 711 | uint8_t resv = PackBits(si, 4, DemodBuffer); si += 4; //was 7 & +=7+3 //should be only 4 bits if extended mode\r |
712 | // 2nibble must be zeroed.\r | |
713 | // moved test to here, since this gets most faults first.\r | |
714 | if ( resv > 0x00) continue;\r | |
715 | \r | |
2767fc02 | 716 | uint8_t xtRate = PackBits(si, 3, DemodBuffer); si += 3; //extended mode part of rate\r |
fef74fdc | 717 | int bitRate = PackBits(si, 3, DemodBuffer); si += 3; //bit rate\r |
718 | if (bitRate > 7) continue;\r | |
13d77ef9 | 719 | uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1; //bit 15 extended mode\r |
2767fc02 | 720 | uint8_t modread = PackBits(si, 5, DemodBuffer); si += 5+2+1; \r |
721 | //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //could check psk cr\r | |
722 | uint8_t nml01 = PackBits(si, 1, DemodBuffer); si += 1+5; //bit 24, 30, 31 could be tested for 0 if not extended mode\r | |
13d77ef9 | 723 | uint8_t nml02 = PackBits(si, 2, DemodBuffer); si += 2;\r |
724 | \r | |
725 | //if extended mode\r | |
726 | bool extMode =( (safer == 0x6 || safer == 0x9) && extend) ? TRUE : FALSE;\r | |
727 | \r | |
728 | if (!extMode){\r | |
729 | if (nml01 || nml02 || xtRate) continue;\r | |
730 | }\r | |
731 | //test modulation\r | |
732 | if (!testModulation(mode, modread)) continue;\r | |
6426f6ba | 733 | if (!testBitRate(bitRate, clk)) continue;\r |
fef74fdc | 734 | *fndBitRate = bitRate;\r |
2767fc02 | 735 | *offset = idx;\r |
6426f6ba | 736 | *Q5 = FALSE;\r |
737 | return TRUE;\r | |
738 | }\r | |
739 | if (testQ5(mode, offset, fndBitRate, clk)) {\r | |
740 | *Q5 = TRUE;\r | |
13d77ef9 | 741 | return TRUE;\r |
742 | }\r | |
743 | return FALSE;\r | |
54a942b0 | 744 | }\r |
745 | \r | |
224ce36e | 746 | void printT55xxBlock(const char *blockNum){\r |
13d77ef9 | 747 | \r |
748 | uint8_t i = config.offset;\r | |
749 | uint8_t endpos = 32 + i;\r | |
750 | uint32_t blockData = 0;\r | |
751 | uint8_t bits[64] = {0x00};\r | |
752 | \r | |
753 | if ( !DemodBufferLen) return;\r | |
754 | \r | |
755 | if ( endpos > DemodBufferLen){\r | |
756 | PrintAndLog("The configured offset %d is too big. Possible offset: %d)", i, DemodBufferLen-32);\r | |
757 | return;\r | |
758 | }\r | |
759 | \r | |
760 | for (; i < endpos; ++i)\r | |
1c8fbeb9 | 761 | bits[i - config.offset] = DemodBuffer[i];\r |
13d77ef9 | 762 | \r |
763 | blockData = PackBits(0, 32, bits);\r | |
6426f6ba | 764 | \r |
765 | PrintAndLog(" %s | %08X | %s", blockNum, blockData, sprint_bin(bits,32));\r | |
13d77ef9 | 766 | }\r |
767 | \r | |
768 | int special(const char *Cmd) {\r | |
769 | uint32_t blockData = 0;\r | |
770 | uint8_t bits[32] = {0x00};\r | |
771 | \r | |
1c8fbeb9 | 772 | PrintAndLog("OFFSET | DATA | BINARY");\r |
13d77ef9 | 773 | PrintAndLog("----------------------------------------------------");\r |
774 | int i,j = 0;\r | |
775 | for (; j < 64; ++j){\r | |
776 | \r | |
777 | for (i = 0; i < 32; ++i)\r | |
778 | bits[i]=DemodBuffer[j+i];\r | |
779 | \r | |
780 | blockData = PackBits(0, 32, bits);\r | |
781 | \r | |
1c8fbeb9 | 782 | PrintAndLog("%02d | 0x%08X | %s",j , blockData, sprint_bin(bits,32)); \r |
13d77ef9 | 783 | }\r |
784 | return 0;\r | |
785 | }\r | |
786 | \r | |
1c8fbeb9 | 787 | int printConfiguration( t55xx_conf_block_t b){\r |
6426f6ba | 788 | PrintAndLog("Chip Type : %s", (b.Q5) ? "T5555(Q5)" : "T55x7");\r |
13d77ef9 | 789 | PrintAndLog("Modulation : %s", GetSelectedModulationStr(b.modulation) );\r |
790 | PrintAndLog("Bit Rate : %s", GetBitRateStr(b.bitrate) );\r | |
791 | PrintAndLog("Inverted : %s", (b.inverted) ? "Yes" : "No" );\r | |
792 | PrintAndLog("Offset : %d", b.offset);\r | |
793 | PrintAndLog("Block0 : 0x%08X", b.block0);\r | |
794 | PrintAndLog("");\r | |
1c8fbeb9 | 795 | return 0;\r |
13d77ef9 | 796 | }\r |
797 | \r | |
1d0ccbe0 | 798 | int CmdT55xxWakeUp(const char *Cmd) {\r |
799 | uint32_t password = 0;\r | |
800 | uint8_t cmdp = 0;\r | |
801 | bool errors = false;\r | |
802 | while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {\r | |
803 | switch(param_getchar(Cmd, cmdp)) {\r | |
804 | case 'h':\r | |
805 | case 'H':\r | |
806 | return usage_t55xx_wakup();\r | |
807 | case 'p':\r | |
808 | case 'P':\r | |
809 | password = param_get32ex(Cmd, cmdp+1, 0, 16);\r | |
810 | cmdp += 2;\r | |
811 | errors = false;\r | |
812 | break;\r | |
813 | default:\r | |
814 | PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r | |
815 | errors = true;\r | |
816 | break;\r | |
817 | }\r | |
818 | }\r | |
819 | if (errors) return usage_t55xx_wakup();\r | |
820 | \r | |
821 | UsbCommand c = {CMD_T55XX_WAKEUP, {password, 0, 0}};\r | |
822 | clearCommandBuffer();\r | |
823 | SendCommand(&c);\r | |
824 | PrintAndLog("Wake up command sent. Try read now");\r | |
825 | return 0;\r | |
826 | }\r | |
827 | \r | |
1c8fbeb9 | 828 | int CmdT55xxWriteBlock(const char *Cmd) {\r |
1d0ccbe0 | 829 | uint8_t block = 0xFF; //default to invalid block\r |
830 | uint32_t data = 0; //default to blank Block \r | |
831 | uint32_t password = 0; //default to blank Block 7\r | |
832 | bool usepwd = false;\r | |
833 | bool page1 = false; \r | |
834 | bool gotdata = false;\r | |
835 | bool errors = false;\r | |
836 | uint8_t cmdp = 0;\r | |
837 | while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {\r | |
838 | switch(param_getchar(Cmd, cmdp)) {\r | |
839 | case 'h':\r | |
840 | case 'H':\r | |
841 | return usage_t55xx_write();\r | |
842 | case 'b':\r | |
843 | case 'B':\r | |
844 | errors |= param_getdec(Cmd, cmdp+1, &block);\r | |
845 | cmdp += 2;\r | |
846 | break;\r | |
847 | case 'd':\r | |
848 | case 'D':\r | |
849 | data = param_get32ex(Cmd, cmdp+1, 0, 16);\r | |
850 | gotdata = true;\r | |
851 | cmdp += 2;\r | |
852 | break;\r | |
853 | case 'p':\r | |
854 | case 'P':\r | |
855 | password = param_get32ex(Cmd, cmdp+1, 0, 16);\r | |
856 | usepwd = true;\r | |
857 | cmdp += 2;\r | |
858 | break;\r | |
859 | case '1':\r | |
860 | page1 = true;\r | |
861 | cmdp++;\r | |
862 | break;\r | |
863 | default:\r | |
864 | PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r | |
865 | errors = true;\r | |
866 | break;\r | |
867 | }\r | |
13d77ef9 | 868 | }\r |
1d0ccbe0 | 869 | if (errors || !gotdata) return usage_t55xx_write();\r |
13d77ef9 | 870 | \r |
871 | if (block > 7) {\r | |
872 | PrintAndLog("Block number must be between 0 and 7");\r | |
1d0ccbe0 | 873 | return 0;\r |
13d77ef9 | 874 | }\r |
875 | \r | |
876 | UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}};\r | |
a739812e | 877 | UsbCommand resp;\r |
1d0ccbe0 | 878 | c.d.asBytes[0] = (page1) ? 0x2 : 0; \r |
13d77ef9 | 879 | \r |
52f2df61 | 880 | char pwdStr[16] = {0};\r |
881 | snprintf(pwdStr, sizeof(pwdStr), "pwd: 0x%08X", password);\r | |
882 | \r | |
883 | PrintAndLog("Writing page %d block: %02d data: 0x%08X %s", page1, block, data, (usepwd) ? pwdStr : "" );\r | |
13d77ef9 | 884 | \r |
885 | //Password mode\r | |
1d0ccbe0 | 886 | if (usepwd) {\r |
13d77ef9 | 887 | c.arg[2] = password;\r |
1d0ccbe0 | 888 | c.d.asBytes[0] |= 0x1; \r |
13d77ef9 | 889 | }\r |
db25599d | 890 | clearCommandBuffer();\r |
13d77ef9 | 891 | SendCommand(&c);\r |
db25599d | 892 | if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){\r |
893 | PrintAndLog("Error occurred, device did not ACK write operation. (May be due to old firmware)");\r | |
52f2df61 | 894 | return 0;\r |
1d0ccbe0 | 895 | }\r |
896 | return 1;\r | |
54a942b0 | 897 | }\r |
898 | \r | |
1c8fbeb9 | 899 | int CmdT55xxReadTrace(const char *Cmd) {\r |
13d77ef9 | 900 | char cmdp = param_getchar(Cmd, 0);\r |
1d0ccbe0 | 901 | bool pwdmode = false;\r |
902 | uint32_t password = 0; \r | |
1c8fbeb9 | 903 | if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') return usage_t55xx_trace();\r |
13d77ef9 | 904 | \r |
905 | if (strlen(Cmd)==0)\r | |
1d0ccbe0 | 906 | if ( !AquireData( T55x7_PAGE1, REGULAR_READ_MODE_BLOCK, pwdmode, password ) )\r |
907 | return 0;\r | |
13d77ef9 | 908 | \r |
1d0ccbe0 | 909 | if (!DecodeT55xxBlock()) return 0;\r |
54a942b0 | 910 | \r |
1d0ccbe0 | 911 | if ( !DemodBufferLen) return 0;\r |
13d77ef9 | 912 | \r |
913 | RepaintGraphWindow();\r | |
914 | uint8_t repeat = 0;\r | |
915 | if (config.offset > 5) \r | |
916 | repeat = 32;\r | |
917 | uint8_t si = config.offset+repeat;\r | |
1d0ccbe0 | 918 | uint32_t bl1 = PackBits(si, 32, DemodBuffer);\r |
919 | uint32_t bl2 = PackBits(si+32, 32, DemodBuffer);\r | |
13d77ef9 | 920 | \r |
224ce36e | 921 | uint32_t acl = PackBits(si, 8, DemodBuffer); si += 8;\r |
922 | uint32_t mfc = PackBits(si, 8, DemodBuffer); si += 8;\r | |
923 | uint32_t cid = PackBits(si, 5, DemodBuffer); si += 5;\r | |
924 | uint32_t icr = PackBits(si, 3, DemodBuffer); si += 3;\r | |
925 | uint32_t year = PackBits(si, 4, DemodBuffer); si += 4;\r | |
926 | uint32_t quarter = PackBits(si, 2, DemodBuffer); si += 2;\r | |
927 | uint32_t lotid = PackBits(si, 14, DemodBuffer); si += 14;\r | |
928 | uint32_t wafer = PackBits(si, 5, DemodBuffer); si += 5;\r | |
13d77ef9 | 929 | uint32_t dw = PackBits(si, 15, DemodBuffer); \r |
930 | \r | |
224ce36e | 931 | time_t t = time(NULL);\r |
932 | struct tm tm = *localtime(&t);\r | |
933 | if ( year > tm.tm_year-110)\r | |
934 | year += 2000;\r | |
935 | else\r | |
936 | year += 2010;\r | |
937 | \r | |
6426f6ba | 938 | if (config.Q5) PrintAndLog("*** Warning *** Info read off a Q5 will not work as expected");\r |
224ce36e | 939 | if ( acl != 0xE0 ) {\r |
940 | PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");\r | |
1d0ccbe0 | 941 | return 0;\r |
224ce36e | 942 | }\r |
13d77ef9 | 943 | PrintAndLog("");\r |
944 | PrintAndLog("-- T55xx Trace Information ----------------------------------");\r | |
945 | PrintAndLog("-------------------------------------------------------------");\r | |
946 | PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl, acl);\r | |
947 | PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", mfc, mfc, getTagInfo(mfc));\r | |
948 | PrintAndLog(" CID : 0x%02X (%d) - %s", cid, cid, GetModelStrFromCID(cid));\r | |
949 | PrintAndLog(" ICR IC Revision : %d",icr );\r | |
950 | PrintAndLog(" Manufactured");\r | |
cc15a118 | 951 | PrintAndLog(" Year/Quarter : %d/%d",year, quarter);\r |
13d77ef9 | 952 | PrintAndLog(" Lot ID : %d", lotid );\r |
953 | PrintAndLog(" Wafer number : %d", wafer);\r | |
954 | PrintAndLog(" Die Number : %d", dw);\r | |
955 | PrintAndLog("-------------------------------------------------------------");\r | |
956 | PrintAndLog(" Raw Data - Page 1");\r | |
1d0ccbe0 | 957 | PrintAndLog(" Block 1 : 0x%08X %s", bl1, sprint_bin(DemodBuffer+config.offset+repeat,32) );\r |
958 | PrintAndLog(" Block 2 : 0x%08X %s", bl2, sprint_bin(DemodBuffer+config.offset+repeat+32,32) );\r | |
13d77ef9 | 959 | PrintAndLog("-------------------------------------------------------------");\r |
54a942b0 | 960 | \r |
13d77ef9 | 961 | /*\r |
962 | TRACE - BLOCK O\r | |
963 | Bits Definition HEX\r | |
964 | 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0 \r | |
965 | 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation\r | |
966 | 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2 \r | |
967 | 22-24 ICR IC revision\r | |
968 | 25-28 YEAR (BCD encoded) 9 (= 2009)\r | |
969 | 29-30 QUARTER 1,2,3,4 \r | |
970 | 31-32 LOT ID\r | |
971 | \r | |
972 | TRACE - BLOCK 1\r | |
973 | 1-12 LOT ID \r | |
974 | 13-17 Wafer number\r | |
975 | 18-32 DW, die number sequential\r | |
976 | */\r | |
977 | \r | |
54a942b0 | 978 | return 0;\r |
979 | }\r | |
980 | \r | |
13d77ef9 | 981 | int CmdT55xxInfo(const char *Cmd){\r |
982 | /*\r | |
983 | Page 0 Block 0 Configuration data.\r | |
984 | Normal mode\r | |
985 | Extended mode\r | |
986 | */\r | |
1d0ccbe0 | 987 | bool pwdmode = false;\r |
988 | uint32_t password = 0;\r | |
13d77ef9 | 989 | char cmdp = param_getchar(Cmd, 0);\r |
990 | \r | |
1c8fbeb9 | 991 | if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') return usage_t55xx_info();\r |
13d77ef9 | 992 | \r |
993 | if (strlen(Cmd)==0)\r | |
1d0ccbe0 | 994 | if ( !AquireData( T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, pwdmode, password ) )\r |
995 | return 1;\r | |
fef74fdc | 996 | \r |
13d77ef9 | 997 | if (!DecodeT55xxBlock()) return 1;\r |
998 | \r | |
fef74fdc | 999 | if ( DemodBufferLen < 32) return 1;\r |
13d77ef9 | 1000 | \r |
1001 | uint8_t si = config.offset;\r | |
1002 | uint32_t bl0 = PackBits(si, 32, DemodBuffer);\r | |
1003 | \r | |
1004 | uint32_t safer = PackBits(si, 4, DemodBuffer); si += 4; \r | |
1005 | uint32_t resv = PackBits(si, 7, DemodBuffer); si += 7;\r | |
1006 | uint32_t dbr = PackBits(si, 3, DemodBuffer); si += 3;\r | |
1007 | uint32_t extend = PackBits(si, 1, DemodBuffer); si += 1;\r | |
1008 | uint32_t datamod = PackBits(si, 5, DemodBuffer); si += 5;\r | |
1009 | uint32_t pskcf = PackBits(si, 2, DemodBuffer); si += 2;\r | |
1010 | uint32_t aor = PackBits(si, 1, DemodBuffer); si += 1; \r | |
1011 | uint32_t otp = PackBits(si, 1, DemodBuffer); si += 1; \r | |
1012 | uint32_t maxblk = PackBits(si, 3, DemodBuffer); si += 3;\r | |
1013 | uint32_t pwd = PackBits(si, 1, DemodBuffer); si += 1; \r | |
1014 | uint32_t sst = PackBits(si, 1, DemodBuffer); si += 1; \r | |
1015 | uint32_t fw = PackBits(si, 1, DemodBuffer); si += 1;\r | |
1016 | uint32_t inv = PackBits(si, 1, DemodBuffer); si += 1; \r | |
1017 | uint32_t por = PackBits(si, 1, DemodBuffer); si += 1;\r | |
6426f6ba | 1018 | if (config.Q5) PrintAndLog("*** Warning *** Config Info read off a Q5 will not display as expected");\r |
13d77ef9 | 1019 | PrintAndLog("");\r |
1020 | PrintAndLog("-- T55xx Configuration & Tag Information --------------------");\r | |
1021 | PrintAndLog("-------------------------------------------------------------");\r | |
1022 | PrintAndLog(" Safer key : %s", GetSaferStr(safer));\r | |
1023 | PrintAndLog(" reserved : %d", resv);\r | |
1024 | PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr));\r | |
1025 | PrintAndLog(" eXtended mode : %s", (extend) ? "Yes - Warning":"No");\r | |
1026 | PrintAndLog(" Modulation : %s", GetModulationStr(datamod));\r | |
1027 | PrintAndLog(" PSK clock frequency : %d", pskcf);\r | |
1028 | PrintAndLog(" AOR - Answer on Request : %s", (aor) ? "Yes":"No");\r | |
1029 | PrintAndLog(" OTP - One Time Pad : %s", (otp) ? "Yes - Warning":"No" );\r | |
1030 | PrintAndLog(" Max block : %d", maxblk);\r | |
1031 | PrintAndLog(" Password mode : %s", (pwd) ? "Yes":"No");\r | |
1032 | PrintAndLog(" Sequence Start Terminator : %s", (sst) ? "Yes":"No");\r | |
1033 | PrintAndLog(" Fast Write : %s", (fw) ? "Yes":"No");\r | |
1034 | PrintAndLog(" Inverse data : %s", (inv) ? "Yes":"No");\r | |
1035 | PrintAndLog(" POR-Delay : %s", (por) ? "Yes":"No");\r | |
1036 | PrintAndLog("-------------------------------------------------------------");\r | |
1037 | PrintAndLog(" Raw Data - Page 0");\r | |
1038 | PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+config.offset,32) );\r | |
1039 | PrintAndLog("-------------------------------------------------------------");\r | |
1040 | \r | |
1041 | return 0;\r | |
1042 | }\r | |
1043 | \r | |
1044 | int CmdT55xxDump(const char *Cmd){\r | |
1045 | \r | |
1d0ccbe0 | 1046 | uint32_t password = 0;\r |
1047 | bool override = false;\r | |
1048 | char cmdp = param_getchar(Cmd, 0); \r | |
1c8fbeb9 | 1049 | if ( cmdp == 'h' || cmdp == 'H') return usage_t55xx_dump();\r |
13d77ef9 | 1050 | \r |
1d0ccbe0 | 1051 | bool usepwd = ( strlen(Cmd) > 0); \r |
1052 | if ( usepwd ){\r | |
1053 | password = param_get32ex(Cmd, 0, 0, 16);\r | |
1054 | if (param_getchar(Cmd, 1) =='o' )\r | |
1055 | override = true;\r | |
13d77ef9 | 1056 | }\r |
1057 | \r | |
6426f6ba | 1058 | printT5xxHeader(0);\r |
1059 | for ( uint8_t i = 0; i < 8; ++i)\r | |
1d0ccbe0 | 1060 | T55xxReadBlock(i, 0, usepwd, override, password);\r |
6426f6ba | 1061 | \r |
1062 | printT5xxHeader(1);\r | |
1063 | for ( uint8_t i = 0; i < 4; i++)\r | |
1d0ccbe0 | 1064 | T55xxReadBlock(i, 1, usepwd, override, password); \r |
6426f6ba | 1065 | \r |
1d0ccbe0 | 1066 | return 1;\r |
13d77ef9 | 1067 | }\r |
1068 | \r | |
1d0ccbe0 | 1069 | int AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){\r |
1070 | // arg0 bitmodes:\r | |
1071 | // bit0 = pwdmode\r | |
1072 | // bit1 = page to read from\r | |
1073 | uint8_t arg0 = (page<<1) | pwdmode;\r | |
1074 | UsbCommand c = {CMD_T55XX_READ_BLOCK, {arg0, block, password}};\r | |
1c8fbeb9 | 1075 | \r |
db25599d | 1076 | clearCommandBuffer();\r |
13d77ef9 | 1077 | SendCommand(&c);\r |
1078 | if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r | |
1079 | PrintAndLog("command execution time out");\r | |
1d0ccbe0 | 1080 | return 0;\r |
13d77ef9 | 1081 | }\r |
1082 | \r | |
1083 | uint8_t got[12000];\r | |
1084 | GetFromBigBuf(got,sizeof(got),0);\r | |
1085 | WaitForResponse(CMD_ACK,NULL);\r | |
1d0ccbe0 | 1086 | setGraphBuf(got, sizeof(got));\r |
1087 | return 1;\r | |
13d77ef9 | 1088 | }\r |
1089 | \r | |
1090 | char * GetBitRateStr(uint32_t id){\r | |
fef74fdc | 1091 | static char buf[25];\r |
1092 | \r | |
13d77ef9 | 1093 | char *retStr = buf;\r |
1094 | switch (id){\r | |
1095 | case 0: \r | |
9795e535 | 1096 | snprintf(retStr,sizeof(buf),"%d - RF/8",id);\r |
13d77ef9 | 1097 | break;\r |
1098 | case 1:\r | |
9795e535 | 1099 | snprintf(retStr,sizeof(buf),"%d - RF/16",id);\r |
13d77ef9 | 1100 | break;\r |
1101 | case 2: \r | |
9795e535 | 1102 | snprintf(retStr,sizeof(buf),"%d - RF/32",id);\r |
13d77ef9 | 1103 | break;\r |
1104 | case 3:\r | |
9795e535 | 1105 | snprintf(retStr,sizeof(buf),"%d - RF/40",id);\r |
13d77ef9 | 1106 | break;\r |
1107 | case 4:\r | |
9795e535 | 1108 | snprintf(retStr,sizeof(buf),"%d - RF/50",id);\r |
13d77ef9 | 1109 | break;\r |
1110 | case 5:\r | |
9795e535 | 1111 | snprintf(retStr,sizeof(buf),"%d - RF/64",id);\r |
13d77ef9 | 1112 | break;\r |
1113 | case 6:\r | |
9795e535 | 1114 | snprintf(retStr,sizeof(buf),"%d - RF/100",id);\r |
13d77ef9 | 1115 | break;\r |
1116 | case 7:\r | |
9795e535 | 1117 | snprintf(retStr,sizeof(buf),"%d - RF/128",id);\r |
13d77ef9 | 1118 | break;\r |
1119 | default:\r | |
9795e535 | 1120 | snprintf(retStr,sizeof(buf),"%d - (Unknown)",id);\r |
13d77ef9 | 1121 | break;\r |
1122 | }\r | |
1123 | \r | |
1124 | return buf;\r | |
1125 | }\r | |
1126 | \r | |
1127 | char * GetSaferStr(uint32_t id){\r | |
1128 | static char buf[40];\r | |
1129 | char *retStr = buf;\r | |
1130 | \r | |
9795e535 | 1131 | snprintf(retStr,sizeof(buf),"%d",id);\r |
13d77ef9 | 1132 | if (id == 6) {\r |
9795e535 | 1133 | snprintf(retStr,sizeof(buf),"%d - passwd",id);\r |
13d77ef9 | 1134 | }\r |
1135 | if (id == 9 ){\r | |
9795e535 | 1136 | snprintf(retStr,sizeof(buf),"%d - testmode",id);\r |
13d77ef9 | 1137 | }\r |
1138 | \r | |
1139 | return buf;\r | |
1140 | }\r | |
9795e535 | 1141 | \r |
13d77ef9 | 1142 | char * GetModulationStr( uint32_t id){\r |
2767fc02 | 1143 | static char buf[60];\r |
13d77ef9 | 1144 | char *retStr = buf;\r |
1145 | \r | |
1146 | switch (id){\r | |
1147 | case 0: \r | |
9795e535 | 1148 | snprintf(retStr,sizeof(buf),"%d - DIRECT (ASK/NRZ)",id);\r |
13d77ef9 | 1149 | break;\r |
1150 | case 1:\r | |
9795e535 | 1151 | snprintf(retStr,sizeof(buf),"%d - PSK 1 phase change when input changes",id);\r |
13d77ef9 | 1152 | break;\r |
1153 | case 2: \r | |
9795e535 | 1154 | snprintf(retStr,sizeof(buf),"%d - PSK 2 phase change on bitclk if input high",id);\r |
13d77ef9 | 1155 | break;\r |
1156 | case 3:\r | |
9795e535 | 1157 | snprintf(retStr,sizeof(buf),"%d - PSK 3 phase change on rising edge of input",id);\r |
13d77ef9 | 1158 | break;\r |
1159 | case 4:\r | |
9795e535 | 1160 | snprintf(retStr,sizeof(buf),"%d - FSK 1 RF/8 RF/5",id);\r |
13d77ef9 | 1161 | break;\r |
1162 | case 5:\r | |
9795e535 | 1163 | snprintf(retStr,sizeof(buf),"%d - FSK 2 RF/8 RF/10",id);\r |
13d77ef9 | 1164 | break;\r |
1165 | case 6:\r | |
9795e535 | 1166 | snprintf(retStr,sizeof(buf),"%d - FSK 1a RF/5 RF/8",id);\r |
13d77ef9 | 1167 | break;\r |
1168 | case 7:\r | |
9795e535 | 1169 | snprintf(retStr,sizeof(buf),"%d - FSK 2a RF/10 RF/8",id);\r |
13d77ef9 | 1170 | break;\r |
1171 | case 8:\r | |
cc15a118 | 1172 | snprintf(retStr,sizeof(buf),"%d - Manchester",id);\r |
13d77ef9 | 1173 | break;\r |
1174 | case 16:\r | |
9795e535 | 1175 | snprintf(retStr,sizeof(buf),"%d - Biphase",id);\r |
13d77ef9 | 1176 | break;\r |
1177 | case 0x18:\r | |
9795e535 | 1178 | snprintf(retStr,sizeof(buf),"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id);\r |
13d77ef9 | 1179 | break;\r |
1180 | case 17:\r | |
9795e535 | 1181 | snprintf(retStr,sizeof(buf),"%d - Reserved",id);\r |
13d77ef9 | 1182 | break;\r |
1183 | default:\r | |
9795e535 | 1184 | snprintf(retStr,sizeof(buf),"0x%02X (Unknown)",id);\r |
13d77ef9 | 1185 | break;\r |
1186 | }\r | |
1187 | return buf;\r | |
1188 | }\r | |
1189 | \r | |
1190 | char * GetModelStrFromCID(uint32_t cid){\r | |
1191 | \r | |
1192 | static char buf[10];\r | |
1193 | char *retStr = buf;\r | |
1194 | \r | |
224ce36e | 1195 | if (cid == 1) snprintf(retStr, sizeof(buf),"ATA5577M1");\r |
1196 | if (cid == 2) snprintf(retStr, sizeof(buf),"ATA5577M2"); \r | |
13d77ef9 | 1197 | return buf;\r |
1198 | }\r | |
1199 | \r | |
1200 | char * GetSelectedModulationStr( uint8_t id){\r | |
1201 | \r | |
9795e535 | 1202 | static char buf[20];\r |
13d77ef9 | 1203 | char *retStr = buf;\r |
1204 | \r | |
1205 | switch (id){\r | |
1206 | case DEMOD_FSK:\r | |
9795e535 | 1207 | snprintf(retStr,sizeof(buf),"FSK");\r |
13d77ef9 | 1208 | break;\r |
1209 | case DEMOD_FSK1:\r | |
9795e535 | 1210 | snprintf(retStr,sizeof(buf),"FSK1");\r |
13d77ef9 | 1211 | break;\r |
1212 | case DEMOD_FSK1a:\r | |
9795e535 | 1213 | snprintf(retStr,sizeof(buf),"FSK1a");\r |
13d77ef9 | 1214 | break;\r |
1215 | case DEMOD_FSK2:\r | |
9795e535 | 1216 | snprintf(retStr,sizeof(buf),"FSK2");\r |
13d77ef9 | 1217 | break;\r |
1218 | case DEMOD_FSK2a:\r | |
9795e535 | 1219 | snprintf(retStr,sizeof(buf),"FSK2a");\r |
13d77ef9 | 1220 | break;\r |
1221 | case DEMOD_ASK: \r | |
9795e535 | 1222 | snprintf(retStr,sizeof(buf),"ASK");\r |
13d77ef9 | 1223 | break;\r |
1224 | case DEMOD_NRZ:\r | |
9795e535 | 1225 | snprintf(retStr,sizeof(buf),"DIRECT/NRZ");\r |
13d77ef9 | 1226 | break;\r |
1227 | case DEMOD_PSK1:\r | |
9795e535 | 1228 | snprintf(retStr,sizeof(buf),"PSK1");\r |
13d77ef9 | 1229 | break;\r |
1230 | case DEMOD_PSK2:\r | |
9795e535 | 1231 | snprintf(retStr,sizeof(buf),"PSK2");\r |
13d77ef9 | 1232 | break;\r |
1233 | case DEMOD_PSK3:\r | |
9795e535 | 1234 | snprintf(retStr,sizeof(buf),"PSK3");\r |
13d77ef9 | 1235 | break;\r |
1236 | case DEMOD_BI:\r | |
9795e535 | 1237 | snprintf(retStr,sizeof(buf),"BIPHASE");\r |
13d77ef9 | 1238 | break;\r |
1239 | case DEMOD_BIa:\r | |
9795e535 | 1240 | snprintf(retStr,sizeof(buf),"BIPHASEa - (CDP)");\r |
13d77ef9 | 1241 | break;\r |
1242 | default:\r | |
9795e535 | 1243 | snprintf(retStr,sizeof(buf),"(Unknown)");\r |
13d77ef9 | 1244 | break;\r |
1245 | }\r | |
1246 | return buf;\r | |
1247 | }\r | |
1248 | \r | |
e98572a1 | 1249 | void t55x7_create_config_block( int tagtype ){\r |
e98572a1 | 1250 | \r |
52f2df61 | 1251 | /*\r |
1252 | T55X7_DEFAULT_CONFIG_BLOCK, T55X7_RAW_CONFIG_BLOCK\r | |
1253 | T55X7_EM_UNIQUE_CONFIG_BLOCK, T55X7_FDXB_CONFIG_BLOCK,\r | |
1254 | T55X7_FDXB_CONFIG_BLOCK, T55X7_HID_26_CONFIG_BLOCK, T55X7_INDALA_64_CONFIG_BLOCK, T55X7_INDALA_224_CONFIG_BLOCK \r | |
1255 | T55X7_GUARDPROXII_CONFIG_BLOCK, T55X7_VIKING_CONFIG_BLOCK, T55X7_NORALYS_CONFIG_BLOCK, T55X7_IOPROX_CONFIG_BLOCK \r | |
1256 | */\r | |
1257 | static char buf[60];\r | |
1258 | char *retStr = buf;\r | |
13d77ef9 | 1259 | \r |
a126332a | 1260 | switch (tagtype){\r |
52f2df61 | 1261 | case 0: snprintf(retStr, sizeof(buf),"%08X - T55X7 Default", T55X7_DEFAULT_CONFIG_BLOCK); break;\r |
1262 | case 1: snprintf(retStr, sizeof(buf),"%08X - T55X7 Raw", T55X7_RAW_CONFIG_BLOCK); break;\r | |
1263 | default:\r | |
1264 | break;\r | |
1265 | }\r | |
1266 | PrintAndLog(buf);\r | |
13d77ef9 | 1267 | }\r |
94422fa2 | 1268 | \r |
1269 | int CmdResetRead(const char *Cmd) {\r | |
1270 | UsbCommand c = {CMD_T55XX_RESET_READ, {0,0,0}};\r | |
1271 | \r | |
1272 | clearCommandBuffer();\r | |
1273 | SendCommand(&c);\r | |
1274 | if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r | |
1275 | PrintAndLog("command execution time out");\r | |
1276 | return 0;\r | |
1277 | }\r | |
1278 | \r | |
1279 | uint8_t got[BIGBUF_SIZE-1];\r | |
1280 | GetFromBigBuf(got,sizeof(got),0);\r | |
1281 | WaitForResponse(CMD_ACK,NULL);\r | |
1282 | setGraphBuf(got, sizeof(got));\r | |
1283 | return 1;\r | |
1284 | }\r | |
1285 | \r | |
6426f6ba | 1286 | int CmdT55xxWipe(const char *Cmd) {\r |
1287 | char writeData[20] = {0};\r | |
1288 | char *ptrData = writeData;\r | |
52f2df61 | 1289 | \r |
6426f6ba | 1290 | PrintAndLog("\nBeginning Wipe of a T55xx tag (assuming the tag is not password protected)\n");\r |
52f2df61 | 1291 | \r |
6426f6ba | 1292 | //try with the default password to reset block 0 (with a pwd should work even if pwd bit not set)\r |
52f2df61 | 1293 | snprintf(ptrData,sizeof(writeData),"b 0 d 000880E0 p 0");\r |
1294 | \r | |
1295 | if (!CmdT55xxWriteBlock(ptrData))\r | |
1296 | PrintAndLog("Error writing blk 0");\r | |
1297 | \r | |
1298 | for (uint8_t blk = 1; blk<8; blk++) {\r | |
1299 | \r | |
6426f6ba | 1300 | snprintf(ptrData,sizeof(writeData),"b %d d 0", blk);\r |
52f2df61 | 1301 | \r |
1302 | if (!CmdT55xxWriteBlock(ptrData)) \r | |
6426f6ba | 1303 | PrintAndLog("Error writing blk %d", blk);\r |
52f2df61 | 1304 | \r |
1305 | memset(writeData, sizeof(writeData), 0x00);\r | |
6426f6ba | 1306 | }\r |
1307 | return 0;\r | |
1308 | }\r | |
1309 | \r | |
a126332a | 1310 | static command_t CommandTable[] = {\r |
13d77ef9 | 1311 | {"help", CmdHelp, 1, "This help"},\r |
1312 | {"config", CmdT55xxSetConfig, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"},\r | |
a126332a | 1313 | {"detect", CmdT55xxDetect, 1, "[1] Try detecting the tag modulation from reading the configuration block."},\r |
94422fa2 | 1314 | {"read", CmdT55xxReadBlock, 0, "b <block> p [password] [o] [1] -- Read T55xx block data. Optional [p password], [override], [page1]"},\r |
1315 | {"resetread",CmdResetRead, 0, "Send Reset Cmd then lf read the stream to attempt to identify the start of it (needs a demod and/or plot after)"},\r | |
1316 | {"write", CmdT55xxWriteBlock,0, "b <block> d <data> p [password] [1] -- Write T55xx block data. Optional [p password], [page1]"},\r | |
a126332a | 1317 | {"trace", CmdT55xxReadTrace, 1, "[1] Show T55x7 traceability data (page 1/ blk 0-1)"},\r |
1318 | {"info", CmdT55xxInfo, 1, "[1] Show T55x7 configuration data (page 0/ blk 0)"},\r | |
94422fa2 | 1319 | {"dump", CmdT55xxDump, 0, "[password] [o] Dump T55xx card block 0-7. Optional [password], [override]"},\r |
13d77ef9 | 1320 | {"special", special, 0, "Show block changes with 64 different offsets"},\r |
9276e859 | 1321 | {"wakeup", CmdT55xxWakeUp, 0, "Send AOR wakeup command"},\r |
6426f6ba | 1322 | {"wipe", CmdT55xxWipe, 0, "Wipe a T55xx tag and set defaults (will destroy any data on tag)"},\r |
54a942b0 | 1323 | {NULL, NULL, 0, NULL}\r |
1324 | };\r | |
1325 | \r | |
a126332a | 1326 | int CmdLFT55XX(const char *Cmd) {\r |
54a942b0 | 1327 | CmdsParse(CommandTable, Cmd);\r |
1328 | return 0;\r | |
1329 | }\r | |
1330 | \r | |
a126332a | 1331 | int CmdHelp(const char *Cmd) {\r |
54a942b0 | 1332 | CmdsHelp(CommandTable);\r |
1333 | return 0;\r | |
1334 | }\r |