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