]>
Commit | Line | Data |
---|---|---|
a553f267 | 1 | //----------------------------------------------------------------------------- |
2 | // Copyright (C) 2010 iZsh <izsh at fail0verflow.com> | |
3 | // | |
4 | // This code is licensed to you under the terms of the GNU GPL, version 2 or, | |
5 | // at your option, any later version. See the LICENSE.txt file for the text of | |
6 | // the license. | |
7 | //----------------------------------------------------------------------------- | |
8 | // Low frequency commands | |
9 | //----------------------------------------------------------------------------- | |
10 | ||
7fe9b0b7 | 11 | #include <stdio.h> |
590f8ff9 | 12 | #include <stdlib.h> |
7fe9b0b7 | 13 | #include <string.h> |
393c3ef9 | 14 | #include <limits.h> |
902cb3c0 | 15 | #include "proxmark3.h" |
7fe9b0b7 | 16 | #include "cmdlf.h" |
29ada8fc | 17 | #include "lfdemod.h" // for psk2TOpsk1 |
6923d3f1 | 18 | #include "util.h" // for parsing cli command utils |
19 | #include "ui.h" // for show graph controls | |
20 | #include "graph.h" // for graph data | |
21 | #include "cmdparser.h" // for getting cli commands included in cmdmain.h | |
22 | #include "cmdmain.h" // for sending cmds to device | |
23 | #include "data.h" // for GetFromBigBuf | |
24 | #include "cmddata.h" // for `lf search` | |
25 | #include "cmdlfawid.h" // for awid menu | |
26 | #include "cmdlfem4x.h" // for em4x menu | |
27 | #include "cmdlfhid.h" // for hid menu | |
28 | #include "cmdlfhitag.h" // for hitag menu | |
29 | #include "cmdlfio.h" // for ioprox menu | |
30 | #include "cmdlft55xx.h" // for t55xx menu | |
31 | #include "cmdlfti.h" // for ti menu | |
32 | #include "cmdlfpresco.h" // for presco menu | |
33 | #include "cmdlfpcf7931.h"// for pcf7931 menu | |
34 | #include "cmdlfpyramid.h"// for pyramid menu | |
35 | #include "cmdlfviking.h" // for viking menu | |
e04475c4 | 36 | #include "cmdlfcotag.h" // for COTAG menu |
8b6abef5 | 37 | #include "cmdlfvisa2000.h" // for VISA2000 menu |
0fb65a26 | 38 | #include "cmdlfindala.h" // for indala menu |
946a84c3 | 39 | #include "cmdlfgproxii.h"// for gproxii menu |
4db6f3bb | 40 | #include "cmdlffdx.h" // for fdx-b menu |
5bce72d5 | 41 | #include "cmdlfparadox.h"// for paradox menu |
42 | #include "cmdlfnexwatch.h"//for nexwatch menu | |
a9968da3 | 43 | #include "cmdlfjablotron.h" //for jablotron menu |
44 | #include "cmdlfnoralsy.h"// for noralsy menu | |
e04475c4 | 45 | |
fac69c3d | 46 | bool g_lf_threshold_set = false; |
7fe9b0b7 | 47 | static int CmdHelp(const char *Cmd); |
48 | ||
21a615cb | 49 | |
50 | ||
f86d6b55 | 51 | int usage_lf_cmdread(void) |
21a615cb | 52 | { |
53 | PrintAndLog("Usage: lf cmdread d <delay period> z <zero period> o <one period> c <cmdbytes> [H] "); | |
54 | PrintAndLog("Options: "); | |
55 | PrintAndLog(" h This help"); | |
56 | PrintAndLog(" L Low frequency (125 KHz)"); | |
57 | PrintAndLog(" H High frequency (134 KHz)"); | |
58 | PrintAndLog(" d <delay> delay OFF period"); | |
59 | PrintAndLog(" z <zero> time period ZERO"); | |
60 | PrintAndLog(" o <one> time period ONE"); | |
61 | PrintAndLog(" c <cmd> Command bytes"); | |
62 | PrintAndLog(" ************* All periods in microseconds"); | |
63 | PrintAndLog("Examples:"); | |
64 | PrintAndLog(" lf cmdread d 80 z 100 o 200 c 11000"); | |
65 | PrintAndLog(" lf cmdread d 80 z 100 o 100 c 11000 H"); | |
66 | return 0; | |
67 | } | |
68 | ||
7fe9b0b7 | 69 | /* send a command before reading */ |
70 | int CmdLFCommandRead(const char *Cmd) | |
71 | { | |
21a615cb | 72 | static char dummy[3] = {0x20,0x00,0x00}; |
e0165dcf | 73 | UsbCommand c = {CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K}; |
7cb8516c | 74 | bool errors = false; |
21a615cb | 75 | //uint8_t divisor = 95; //125khz |
76 | uint8_t cmdp = 0; | |
21a615cb | 77 | while(param_getchar(Cmd, cmdp) != 0x00) |
78 | { | |
79 | switch(param_getchar(Cmd, cmdp)) | |
80 | { | |
81 | case 'h': | |
82 | return usage_lf_cmdread(); | |
83 | case 'H': | |
84 | //divisor = 88; | |
85 | dummy[1]='h'; | |
86 | cmdp++; | |
87 | break; | |
88 | case 'L': | |
89 | cmdp++; | |
90 | break; | |
91 | case 'c': | |
f9ce1c3a | 92 | param_getstr(Cmd, cmdp+1, (char *)&c.d.asBytes); |
21a615cb | 93 | cmdp+=2; |
94 | break; | |
95 | case 'd': | |
96 | c.arg[0] = param_get32ex(Cmd, cmdp+1, 0, 10); | |
97 | cmdp+=2; | |
98 | break; | |
99 | case 'z': | |
100 | c.arg[1] = param_get32ex(Cmd, cmdp+1, 0, 10); | |
101 | cmdp+=2; | |
102 | break; | |
103 | case 'o': | |
104 | c.arg[2] = param_get32ex(Cmd, cmdp+1, 0, 10); | |
105 | cmdp+=2; | |
106 | break; | |
107 | default: | |
108 | PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp)); | |
109 | errors = 1; | |
110 | break; | |
111 | } | |
112 | if(errors) break; | |
113 | } | |
114 | // No args | |
115 | if(cmdp == 0) errors = 1; | |
116 | ||
117 | //Validations | |
118 | if(errors) return usage_lf_cmdread(); | |
119 | ||
120 | // in case they specified 'H' | |
e0165dcf | 121 | strcpy((char *)&c.d.asBytes + strlen((char *)c.d.asBytes), dummy); |
21a615cb | 122 | |
123 | clearCommandBuffer(); | |
e0165dcf | 124 | SendCommand(&c); |
125 | return 0; | |
7fe9b0b7 | 126 | } |
127 | ||
128 | int CmdFlexdemod(const char *Cmd) | |
129 | { | |
e0165dcf | 130 | int i; |
131 | for (i = 0; i < GraphTraceLen; ++i) { | |
132 | if (GraphBuffer[i] < 0) { | |
133 | GraphBuffer[i] = -1; | |
134 | } else { | |
135 | GraphBuffer[i] = 1; | |
136 | } | |
137 | } | |
7fe9b0b7 | 138 | |
f6650679 | 139 | #define LONG_WAIT 100 |
e0165dcf | 140 | int start; |
141 | for (start = 0; start < GraphTraceLen - LONG_WAIT; start++) { | |
142 | int first = GraphBuffer[start]; | |
143 | for (i = start; i < start + LONG_WAIT; i++) { | |
144 | if (GraphBuffer[i] != first) { | |
145 | break; | |
146 | } | |
147 | } | |
148 | if (i == (start + LONG_WAIT)) { | |
149 | break; | |
150 | } | |
151 | } | |
152 | if (start == GraphTraceLen - LONG_WAIT) { | |
153 | PrintAndLog("nothing to wait for"); | |
154 | return 0; | |
155 | } | |
156 | ||
157 | GraphBuffer[start] = 2; | |
158 | GraphBuffer[start+1] = -2; | |
3fe4ff4f | 159 | uint8_t bits[64] = {0x00}; |
7fe9b0b7 | 160 | |
3fe4ff4f | 161 | int bit, sum; |
e0165dcf | 162 | i = start; |
163 | for (bit = 0; bit < 64; bit++) { | |
3fe4ff4f | 164 | sum = 0; |
165 | for (int j = 0; j < 16; j++) { | |
e0165dcf | 166 | sum += GraphBuffer[i++]; |
167 | } | |
3fe4ff4f | 168 | |
169 | bits[bit] = (sum > 0) ? 1 : 0; | |
170 | ||
e0165dcf | 171 | PrintAndLog("bit %d sum %d", bit, sum); |
172 | } | |
173 | ||
174 | for (bit = 0; bit < 64; bit++) { | |
175 | int j; | |
176 | int sum = 0; | |
177 | for (j = 0; j < 16; j++) { | |
178 | sum += GraphBuffer[i++]; | |
179 | } | |
180 | if (sum > 0 && bits[bit] != 1) { | |
181 | PrintAndLog("oops1 at %d", bit); | |
182 | } | |
183 | if (sum < 0 && bits[bit] != 0) { | |
184 | PrintAndLog("oops2 at %d", bit); | |
185 | } | |
186 | } | |
7fe9b0b7 | 187 | |
3fe4ff4f | 188 | // HACK writing back to graphbuffer. |
e0165dcf | 189 | GraphTraceLen = 32*64; |
190 | i = 0; | |
191 | int phase = 0; | |
192 | for (bit = 0; bit < 64; bit++) { | |
3fe4ff4f | 193 | |
194 | phase = (bits[bit] == 0) ? 0 : 1; | |
195 | ||
e0165dcf | 196 | int j; |
197 | for (j = 0; j < 32; j++) { | |
198 | GraphBuffer[i++] = phase; | |
199 | phase = !phase; | |
200 | } | |
201 | } | |
202 | ||
203 | RepaintGraphWindow(); | |
204 | return 0; | |
0fb65a26 | 205 | } |
2414f978 | 206 | |
f86d6b55 | 207 | int usage_lf_read(void) |
f6d9fb17 | 208 | { |
31abe49f | 209 | PrintAndLog("Usage: lf read"); |
f6d9fb17 MHS |
210 | PrintAndLog("Options: "); |
211 | PrintAndLog(" h This help"); | |
1fbf8956 | 212 | PrintAndLog(" s silent run no printout"); |
31abe49f MHS |
213 | PrintAndLog("This function takes no arguments. "); |
214 | PrintAndLog("Use 'lf config' to set parameters."); | |
215 | return 0; | |
216 | } | |
f86d6b55 | 217 | int usage_lf_snoop(void) |
31abe49f MHS |
218 | { |
219 | PrintAndLog("Usage: lf snoop"); | |
220 | PrintAndLog("Options: "); | |
221 | PrintAndLog(" h This help"); | |
222 | PrintAndLog("This function takes no arguments. "); | |
223 | PrintAndLog("Use 'lf config' to set parameters."); | |
224 | return 0; | |
225 | } | |
226 | ||
f86d6b55 | 227 | int usage_lf_config(void) |
31abe49f MHS |
228 | { |
229 | PrintAndLog("Usage: lf config [H|<divisor>] [b <bps>] [d <decim>] [a 0|1]"); | |
230 | PrintAndLog("Options: "); | |
231 | PrintAndLog(" h This help"); | |
232 | PrintAndLog(" L Low frequency (125 KHz)"); | |
233 | PrintAndLog(" H High frequency (134 KHz)"); | |
234 | PrintAndLog(" q <divisor> Manually set divisor. 88-> 134KHz, 95-> 125 Hz"); | |
235 | PrintAndLog(" b <bps> Sets resolution of bits per sample. Default (max): 8"); | |
236 | PrintAndLog(" d <decim> Sets decimation. A value of N saves only 1 in N samples. Default: 1"); | |
237 | PrintAndLog(" a [0|1] Averaging - if set, will average the stored sample value when decimating. Default: 1"); | |
b29d55f2 | 238 | PrintAndLog(" t <threshold> Sets trigger threshold. 0 means no threshold (range: 0-128)"); |
f6d9fb17 | 239 | PrintAndLog("Examples:"); |
31abe49f | 240 | PrintAndLog(" lf config b 8 L"); |
f6d9fb17 | 241 | PrintAndLog(" Samples at 125KHz, 8bps."); |
31abe49f | 242 | PrintAndLog(" lf config H b 4 d 3"); |
f6d9fb17 MHS |
243 | PrintAndLog(" Samples at 134KHz, averages three samples into one, stored with "); |
244 | PrintAndLog(" a resolution of 4 bits per sample."); | |
31abe49f MHS |
245 | PrintAndLog(" lf read"); |
246 | PrintAndLog(" Performs a read (active field)"); | |
247 | PrintAndLog(" lf snoop"); | |
248 | PrintAndLog(" Performs a snoop (no active field)"); | |
f6d9fb17 MHS |
249 | return 0; |
250 | } | |
31abe49f MHS |
251 | |
252 | int CmdLFSetConfig(const char *Cmd) | |
7fe9b0b7 | 253 | { |
31abe49f MHS |
254 | |
255 | uint8_t divisor = 0;//Frequency divisor | |
256 | uint8_t bps = 0; // Bits per sample | |
257 | uint8_t decimation = 0; //How many to keep | |
258 | bool averaging = 1; // Defaults to true | |
7cb8516c | 259 | bool errors = false; |
31abe49f MHS |
260 | int trigger_threshold =-1;//Means no change |
261 | uint8_t unsigned_trigg = 0; | |
f6d9fb17 MHS |
262 | |
263 | uint8_t cmdp =0; | |
31abe49f | 264 | while(param_getchar(Cmd, cmdp) != 0x00) |
f6d9fb17 | 265 | { |
31abe49f MHS |
266 | switch(param_getchar(Cmd, cmdp)) |
267 | { | |
268 | case 'h': | |
269 | return usage_lf_config(); | |
270 | case 'H': | |
271 | divisor = 88; | |
272 | cmdp++; | |
273 | break; | |
274 | case 'L': | |
275 | divisor = 95; | |
276 | cmdp++; | |
277 | break; | |
278 | case 'q': | |
279 | errors |= param_getdec(Cmd,cmdp+1,&divisor); | |
280 | cmdp+=2; | |
281 | break; | |
282 | case 't': | |
283 | errors |= param_getdec(Cmd,cmdp+1,&unsigned_trigg); | |
284 | cmdp+=2; | |
2b11c7c7 | 285 | if(!errors) { |
286 | trigger_threshold = unsigned_trigg; | |
fac69c3d | 287 | if (trigger_threshold > 0) g_lf_threshold_set = true; |
2b11c7c7 | 288 | } |
31abe49f MHS |
289 | break; |
290 | case 'b': | |
291 | errors |= param_getdec(Cmd,cmdp+1,&bps); | |
292 | cmdp+=2; | |
293 | break; | |
294 | case 'd': | |
295 | errors |= param_getdec(Cmd,cmdp+1,&decimation); | |
296 | cmdp+=2; | |
297 | break; | |
298 | case 'a': | |
299 | averaging = param_getchar(Cmd,cmdp+1) == '1'; | |
300 | cmdp+=2; | |
301 | break; | |
302 | default: | |
303 | PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp)); | |
304 | errors = 1; | |
305 | break; | |
306 | } | |
307 | if(errors) break; | |
f6d9fb17 | 308 | } |
31abe49f | 309 | if(cmdp == 0) |
f6d9fb17 | 310 | { |
31abe49f | 311 | errors = 1;// No args |
f6d9fb17 | 312 | } |
31abe49f | 313 | |
f6d9fb17 MHS |
314 | //Validations |
315 | if(errors) | |
316 | { | |
31abe49f | 317 | return usage_lf_config(); |
f6d9fb17 | 318 | } |
f6d9fb17 | 319 | //Bps is limited to 8, so fits in lower half of arg1 |
72c5877a | 320 | if(bps >> 4) bps = 8; |
f6d9fb17 | 321 | |
31abe49f MHS |
322 | sample_config config = { |
323 | decimation,bps,averaging,divisor,trigger_threshold | |
324 | }; | |
325 | //Averaging is a flag on high-bit of arg[1] | |
326 | UsbCommand c = {CMD_SET_LF_SAMPLING_CONFIG}; | |
327 | memcpy(c.d.asBytes,&config,sizeof(sample_config)); | |
709665b5 | 328 | clearCommandBuffer(); |
31abe49f MHS |
329 | SendCommand(&c); |
330 | return 0; | |
331 | } | |
f6d9fb17 | 332 | |
7fe9b0b7 | 333 | int CmdLFRead(const char *Cmd) |
334 | { | |
2b11c7c7 | 335 | if (offline) return 0; |
1fbf8956 | 336 | uint8_t cmdp = 0; |
337 | bool arg1 = false; | |
338 | if (param_getchar(Cmd, cmdp) == 'h') | |
31abe49f MHS |
339 | { |
340 | return usage_lf_read(); | |
341 | } | |
1fbf8956 | 342 | if (param_getchar(Cmd, cmdp) == 's') arg1 = true; //suppress print |
f6d9fb17 | 343 | //And ship it to device |
1fbf8956 | 344 | UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_125K, {arg1,0,0}}; |
709665b5 | 345 | clearCommandBuffer(); |
31abe49f | 346 | SendCommand(&c); |
fac69c3d | 347 | if (g_lf_threshold_set) { |
2b11c7c7 | 348 | WaitForResponse(CMD_ACK,NULL); |
349 | } else { | |
350 | if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) { | |
351 | PrintAndLog("command execution time out"); | |
352 | return 1; | |
353 | } | |
354 | } | |
31abe49f MHS |
355 | return 0; |
356 | } | |
f6d9fb17 | 357 | |
31abe49f MHS |
358 | int CmdLFSnoop(const char *Cmd) |
359 | { | |
360 | uint8_t cmdp =0; | |
361 | if(param_getchar(Cmd, cmdp) == 'h') | |
362 | { | |
363 | return usage_lf_snoop(); | |
364 | } | |
365 | ||
366 | UsbCommand c = {CMD_LF_SNOOP_RAW_ADC_SAMPLES}; | |
709665b5 | 367 | clearCommandBuffer(); |
f6d9fb17 MHS |
368 | SendCommand(&c); |
369 | WaitForResponse(CMD_ACK,NULL); | |
370 | return 0; | |
7fe9b0b7 | 371 | } |
372 | ||
373 | static void ChkBitstream(const char *str) | |
374 | { | |
e0165dcf | 375 | int i; |
78f5b1a7 | 376 | |
e0165dcf | 377 | /* convert to bitstream if necessary */ |
b915fda3 | 378 | for (i = 0; i < (int)(GraphTraceLen / 2); i++){ |
379 | if (GraphBuffer[i] > 1 || GraphBuffer[i] < 0) { | |
e0165dcf | 380 | CmdGetBitStream(""); |
381 | break; | |
382 | } | |
383 | } | |
7fe9b0b7 | 384 | } |
2767fc02 | 385 | //Attempt to simulate any wave in buffer (one bit per output sample) |
386 | // converts GraphBuffer to bitstream (based on zero crossings) if needed. | |
7fe9b0b7 | 387 | int CmdLFSim(const char *Cmd) |
388 | { | |
e0165dcf | 389 | int i,j; |
390 | static int gap; | |
7fe9b0b7 | 391 | |
e0165dcf | 392 | sscanf(Cmd, "%i", &gap); |
7fe9b0b7 | 393 | |
2767fc02 | 394 | // convert to bitstream if necessary |
78f5b1a7 | 395 | |
e0165dcf | 396 | ChkBitstream(Cmd); |
7fe9b0b7 | 397 | |
2767fc02 | 398 | //can send only 512 bits at a time (1 byte sent per bit...) |
e0165dcf | 399 | printf("Sending [%d bytes]", GraphTraceLen); |
400 | for (i = 0; i < GraphTraceLen; i += USB_CMD_DATA_SIZE) { | |
401 | UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {i, 0, 0}}; | |
52ab55ab | 402 | |
e0165dcf | 403 | for (j = 0; j < USB_CMD_DATA_SIZE; j++) { |
404 | c.d.asBytes[j] = GraphBuffer[i+j]; | |
405 | } | |
406 | SendCommand(&c); | |
407 | WaitForResponse(CMD_ACK,NULL); | |
408 | printf("."); | |
409 | } | |
7fe9b0b7 | 410 | |
e0165dcf | 411 | printf("\n"); |
412 | PrintAndLog("Starting to simulate"); | |
413 | UsbCommand c = {CMD_SIMULATE_TAG_125K, {GraphTraceLen, gap, 0}}; | |
709665b5 | 414 | clearCommandBuffer(); |
e0165dcf | 415 | SendCommand(&c); |
416 | return 0; | |
7fe9b0b7 | 417 | } |
418 | ||
abd6112f | 419 | int usage_lf_simfsk(void) |
420 | { | |
e0165dcf | 421 | //print help |
422 | PrintAndLog("Usage: lf simfsk [c <clock>] [i] [H <fcHigh>] [L <fcLow>] [d <hexdata>]"); | |
423 | PrintAndLog("Options: "); | |
424 | PrintAndLog(" h This help"); | |
425 | PrintAndLog(" c <clock> Manually set clock - can autodetect if using DemodBuffer"); | |
426 | PrintAndLog(" i invert data"); | |
427 | PrintAndLog(" H <fcHigh> Manually set the larger Field Clock"); | |
428 | PrintAndLog(" L <fcLow> Manually set the smaller Field Clock"); | |
429 | //PrintAndLog(" s TBD- -to enable a gap between playback repetitions - default: no gap"); | |
430 | PrintAndLog(" d <hexdata> Data to sim as hex - omit to sim from DemodBuffer"); | |
431 | PrintAndLog("\n NOTE: if you set one clock manually set them all manually"); | |
432 | return 0; | |
abd6112f | 433 | } |
434 | ||
435 | int usage_lf_simask(void) | |
436 | { | |
e0165dcf | 437 | //print help |
438 | PrintAndLog("Usage: lf simask [c <clock>] [i] [b|m|r] [s] [d <raw hex to sim>]"); | |
439 | PrintAndLog("Options: "); | |
440 | PrintAndLog(" h This help"); | |
441 | PrintAndLog(" c <clock> Manually set clock - can autodetect if using DemodBuffer"); | |
442 | PrintAndLog(" i invert data"); | |
443 | PrintAndLog(" b sim ask/biphase"); | |
444 | PrintAndLog(" m sim ask/manchester - Default"); | |
445 | PrintAndLog(" r sim ask/raw"); | |
29ada8fc | 446 | PrintAndLog(" s add t55xx Sequence Terminator gap - default: no gaps (only manchester)"); |
e0165dcf | 447 | PrintAndLog(" d <hexdata> Data to sim as hex - omit to sim from DemodBuffer"); |
448 | return 0; | |
abd6112f | 449 | } |
450 | ||
872e3d4d | 451 | int usage_lf_simpsk(void) |
452 | { | |
e0165dcf | 453 | //print help |
454 | PrintAndLog("Usage: lf simpsk [1|2|3] [c <clock>] [i] [r <carrier>] [d <raw hex to sim>]"); | |
455 | PrintAndLog("Options: "); | |
456 | PrintAndLog(" h This help"); | |
457 | PrintAndLog(" c <clock> Manually set clock - can autodetect if using DemodBuffer"); | |
458 | PrintAndLog(" i invert data"); | |
459 | PrintAndLog(" 1 set PSK1 (default)"); | |
460 | PrintAndLog(" 2 set PSK2"); | |
461 | PrintAndLog(" 3 set PSK3"); | |
462 | PrintAndLog(" r <carrier> 2|4|8 are valid carriers: default = 2"); | |
463 | PrintAndLog(" d <hexdata> Data to sim as hex - omit to sim from DemodBuffer"); | |
464 | return 0; | |
872e3d4d | 465 | } |
712ebfa6 | 466 | |
f86d6b55 | 467 | // by marshmellow - sim fsk data given clock, fcHigh, fcLow, invert |
abd6112f | 468 | // - allow pull data from DemodBuffer |
469 | int CmdLFfskSim(const char *Cmd) | |
470 | { | |
2767fc02 | 471 | //might be able to autodetect FCs and clock from Graphbuffer if using demod buffer |
472 | // otherwise will need FChigh, FClow, Clock, and bitstream | |
e0165dcf | 473 | uint8_t fcHigh=0, fcLow=0, clk=0; |
474 | uint8_t invert=0; | |
7cb8516c | 475 | bool errors = false; |
e0165dcf | 476 | char hexData[32] = {0x00}; // store entered hex data |
477 | uint8_t data[255] = {0x00}; | |
478 | int dataLen = 0; | |
479 | uint8_t cmdp = 0; | |
480 | while(param_getchar(Cmd, cmdp) != 0x00) | |
481 | { | |
482 | switch(param_getchar(Cmd, cmdp)) | |
483 | { | |
484 | case 'h': | |
485 | return usage_lf_simfsk(); | |
486 | case 'i': | |
487 | invert = 1; | |
488 | cmdp++; | |
489 | break; | |
490 | case 'c': | |
491 | errors |= param_getdec(Cmd,cmdp+1,&clk); | |
492 | cmdp+=2; | |
493 | break; | |
494 | case 'H': | |
495 | errors |= param_getdec(Cmd,cmdp+1,&fcHigh); | |
496 | cmdp+=2; | |
497 | break; | |
498 | case 'L': | |
499 | errors |= param_getdec(Cmd,cmdp+1,&fcLow); | |
500 | cmdp+=2; | |
501 | break; | |
502 | //case 's': | |
503 | // separator=1; | |
504 | // cmdp++; | |
505 | // break; | |
506 | case 'd': | |
507 | dataLen = param_getstr(Cmd, cmdp+1, hexData); | |
508 | if (dataLen==0) { | |
7cb8516c | 509 | errors=true; |
e0165dcf | 510 | } else { |
511 | dataLen = hextobinarray((char *)data, hexData); | |
512 | } | |
7cb8516c | 513 | if (dataLen==0) errors=true; |
e0165dcf | 514 | if (errors) PrintAndLog ("Error getting hex data"); |
515 | cmdp+=2; | |
516 | break; | |
517 | default: | |
518 | PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp)); | |
7cb8516c | 519 | errors = true; |
e0165dcf | 520 | break; |
521 | } | |
522 | if(errors) break; | |
523 | } | |
524 | if(cmdp == 0 && DemodBufferLen == 0) | |
525 | { | |
7cb8516c | 526 | errors = true;// No args |
e0165dcf | 527 | } |
528 | ||
529 | //Validations | |
530 | if(errors) | |
531 | { | |
532 | return usage_lf_simfsk(); | |
533 | } | |
534 | ||
535 | if (dataLen == 0){ //using DemodBuffer | |
536 | if (clk==0 || fcHigh==0 || fcLow==0){ //manual settings must set them all | |
537 | uint8_t ans = fskClocks(&fcHigh, &fcLow, &clk, 0); | |
538 | if (ans==0){ | |
539 | if (!fcHigh) fcHigh=10; | |
540 | if (!fcLow) fcLow=8; | |
541 | if (!clk) clk=50; | |
542 | } | |
543 | } | |
544 | } else { | |
545 | setDemodBuf(data, dataLen, 0); | |
546 | } | |
2767fc02 | 547 | |
548 | //default if not found | |
e0165dcf | 549 | if (clk == 0) clk = 50; |
550 | if (fcHigh == 0) fcHigh = 10; | |
551 | if (fcLow == 0) fcLow = 8; | |
552 | ||
553 | uint16_t arg1, arg2; | |
554 | arg1 = fcHigh << 8 | fcLow; | |
555 | arg2 = invert << 8 | clk; | |
556 | size_t size = DemodBufferLen; | |
557 | if (size > USB_CMD_DATA_SIZE) { | |
558 | PrintAndLog("DemodBuffer too long for current implementation - length: %d - max: %d", size, USB_CMD_DATA_SIZE); | |
559 | size = USB_CMD_DATA_SIZE; | |
560 | } | |
561 | UsbCommand c = {CMD_FSK_SIM_TAG, {arg1, arg2, size}}; | |
562 | ||
563 | memcpy(c.d.asBytes, DemodBuffer, size); | |
709665b5 | 564 | clearCommandBuffer(); |
e0165dcf | 565 | SendCommand(&c); |
566 | return 0; | |
abd6112f | 567 | } |
568 | ||
569 | // by marshmellow - sim ask data given clock, invert, manchester or raw, separator | |
570 | // - allow pull data from DemodBuffer | |
571 | int CmdLFaskSim(const char *Cmd) | |
572 | { | |
e0165dcf | 573 | //autodetect clock from Graphbuffer if using demod buffer |
2767fc02 | 574 | // needs clock, invert, manchester/raw as m or r, separator as s, and bitstream |
e0165dcf | 575 | uint8_t encoding = 1, separator = 0; |
e0165dcf | 576 | uint8_t clk=0, invert=0; |
7cb8516c | 577 | bool errors = false; |
e0165dcf | 578 | char hexData[32] = {0x00}; |
579 | uint8_t data[255]= {0x00}; // store entered hex data | |
580 | int dataLen = 0; | |
581 | uint8_t cmdp = 0; | |
582 | while(param_getchar(Cmd, cmdp) != 0x00) | |
583 | { | |
584 | switch(param_getchar(Cmd, cmdp)) | |
585 | { | |
586 | case 'h': | |
587 | return usage_lf_simask(); | |
588 | case 'i': | |
589 | invert = 1; | |
590 | cmdp++; | |
591 | break; | |
592 | case 'c': | |
593 | errors |= param_getdec(Cmd,cmdp+1,&clk); | |
594 | cmdp+=2; | |
595 | break; | |
596 | case 'b': | |
597 | encoding=2; //biphase | |
598 | cmdp++; | |
599 | break; | |
600 | case 'm': | |
601 | encoding=1; | |
602 | cmdp++; | |
603 | break; | |
604 | case 'r': | |
605 | encoding=0; | |
606 | cmdp++; | |
607 | break; | |
608 | case 's': | |
609 | separator=1; | |
610 | cmdp++; | |
611 | break; | |
612 | case 'd': | |
613 | dataLen = param_getstr(Cmd, cmdp+1, hexData); | |
614 | if (dataLen==0) { | |
7cb8516c | 615 | errors=true; |
e0165dcf | 616 | } else { |
617 | dataLen = hextobinarray((char *)data, hexData); | |
618 | } | |
7cb8516c | 619 | if (dataLen==0) errors=true; |
e0165dcf | 620 | if (errors) PrintAndLog ("Error getting hex data, datalen: %d",dataLen); |
621 | cmdp+=2; | |
622 | break; | |
623 | default: | |
624 | PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp)); | |
7cb8516c | 625 | errors = true; |
e0165dcf | 626 | break; |
627 | } | |
628 | if(errors) break; | |
629 | } | |
630 | if(cmdp == 0 && DemodBufferLen == 0) | |
631 | { | |
7cb8516c | 632 | errors = true;// No args |
e0165dcf | 633 | } |
634 | ||
635 | //Validations | |
636 | if(errors) | |
637 | { | |
638 | return usage_lf_simask(); | |
639 | } | |
640 | if (dataLen == 0){ //using DemodBuffer | |
641 | if (clk == 0) clk = GetAskClock("0", false, false); | |
642 | } else { | |
643 | setDemodBuf(data, dataLen, 0); | |
644 | } | |
645 | if (clk == 0) clk = 64; | |
646 | if (encoding == 0) clk = clk/2; //askraw needs to double the clock speed | |
647 | uint16_t arg1, arg2; | |
648 | size_t size=DemodBufferLen; | |
649 | arg1 = clk << 8 | encoding; | |
650 | arg2 = invert << 8 | separator; | |
651 | if (size > USB_CMD_DATA_SIZE) { | |
652 | PrintAndLog("DemodBuffer too long for current implementation - length: %d - max: %d", size, USB_CMD_DATA_SIZE); | |
653 | size = USB_CMD_DATA_SIZE; | |
654 | } | |
655 | UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}}; | |
656 | PrintAndLog("preparing to sim ask data: %d bits", size); | |
657 | memcpy(c.d.asBytes, DemodBuffer, size); | |
709665b5 | 658 | clearCommandBuffer(); |
e0165dcf | 659 | SendCommand(&c); |
660 | return 0; | |
abd6112f | 661 | } |
662 | ||
872e3d4d | 663 | // by marshmellow - sim psk data given carrier, clock, invert |
664 | // - allow pull data from DemodBuffer or parameters | |
665 | int CmdLFpskSim(const char *Cmd) | |
666 | { | |
e0165dcf | 667 | //might be able to autodetect FC and clock from Graphbuffer if using demod buffer |
668 | //will need carrier, Clock, and bitstream | |
669 | uint8_t carrier=0, clk=0; | |
670 | uint8_t invert=0; | |
7cb8516c | 671 | bool errors = false; |
e0165dcf | 672 | char hexData[32] = {0x00}; // store entered hex data |
673 | uint8_t data[255] = {0x00}; | |
674 | int dataLen = 0; | |
675 | uint8_t cmdp = 0; | |
676 | uint8_t pskType = 1; | |
677 | while(param_getchar(Cmd, cmdp) != 0x00) | |
678 | { | |
679 | switch(param_getchar(Cmd, cmdp)) | |
680 | { | |
681 | case 'h': | |
682 | return usage_lf_simpsk(); | |
683 | case 'i': | |
684 | invert = 1; | |
685 | cmdp++; | |
686 | break; | |
687 | case 'c': | |
688 | errors |= param_getdec(Cmd,cmdp+1,&clk); | |
689 | cmdp+=2; | |
690 | break; | |
691 | case 'r': | |
692 | errors |= param_getdec(Cmd,cmdp+1,&carrier); | |
693 | cmdp+=2; | |
694 | break; | |
695 | case '1': | |
696 | pskType=1; | |
697 | cmdp++; | |
698 | break; | |
699 | case '2': | |
700 | pskType=2; | |
701 | cmdp++; | |
702 | break; | |
703 | case '3': | |
704 | pskType=3; | |
705 | cmdp++; | |
706 | break; | |
707 | case 'd': | |
708 | dataLen = param_getstr(Cmd, cmdp+1, hexData); | |
709 | if (dataLen==0) { | |
7cb8516c | 710 | errors=true; |
e0165dcf | 711 | } else { |
712 | dataLen = hextobinarray((char *)data, hexData); | |
713 | } | |
7cb8516c | 714 | if (dataLen==0) errors=true; |
e0165dcf | 715 | if (errors) PrintAndLog ("Error getting hex data"); |
716 | cmdp+=2; | |
717 | break; | |
718 | default: | |
719 | PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp)); | |
7cb8516c | 720 | errors = true; |
e0165dcf | 721 | break; |
722 | } | |
723 | if (errors) break; | |
724 | } | |
725 | if (cmdp == 0 && DemodBufferLen == 0) | |
726 | { | |
7cb8516c | 727 | errors = true;// No args |
e0165dcf | 728 | } |
729 | ||
730 | //Validations | |
731 | if (errors) | |
732 | { | |
733 | return usage_lf_simpsk(); | |
734 | } | |
735 | if (dataLen == 0){ //using DemodBuffer | |
736 | PrintAndLog("Getting Clocks"); | |
7cb8516c | 737 | if (clk==0) clk = GetPskClock("", false, false); |
e0165dcf | 738 | PrintAndLog("clk: %d",clk); |
7cb8516c | 739 | if (!carrier) carrier = GetPskCarrier("", false, false); |
e0165dcf | 740 | PrintAndLog("carrier: %d", carrier); |
741 | } else { | |
742 | setDemodBuf(data, dataLen, 0); | |
743 | } | |
744 | ||
745 | if (clk <= 0) clk = 32; | |
746 | if (carrier == 0) carrier = 2; | |
747 | if (pskType != 1){ | |
748 | if (pskType == 2){ | |
749 | //need to convert psk2 to psk1 data before sim | |
750 | psk2TOpsk1(DemodBuffer, DemodBufferLen); | |
751 | } else { | |
752 | PrintAndLog("Sorry, PSK3 not yet available"); | |
753 | } | |
754 | } | |
755 | uint16_t arg1, arg2; | |
756 | arg1 = clk << 8 | carrier; | |
757 | arg2 = invert; | |
758 | size_t size=DemodBufferLen; | |
759 | if (size > USB_CMD_DATA_SIZE) { | |
760 | PrintAndLog("DemodBuffer too long for current implementation - length: %d - max: %d", size, USB_CMD_DATA_SIZE); | |
761 | size=USB_CMD_DATA_SIZE; | |
762 | } | |
763 | UsbCommand c = {CMD_PSK_SIM_TAG, {arg1, arg2, size}}; | |
764 | PrintAndLog("DEBUG: Sending DemodBuffer Length: %d", size); | |
765 | memcpy(c.d.asBytes, DemodBuffer, size); | |
709665b5 | 766 | clearCommandBuffer(); |
e0165dcf | 767 | SendCommand(&c); |
768 | ||
769 | return 0; | |
872e3d4d | 770 | } |
abd6112f | 771 | |
7fe9b0b7 | 772 | int CmdLFSimBidir(const char *Cmd) |
773 | { | |
e0165dcf | 774 | // Set ADC to twice the carrier for a slight supersampling |
775 | // HACK: not implemented in ARMSRC. | |
776 | PrintAndLog("Not implemented yet."); | |
777 | UsbCommand c = {CMD_LF_SIMULATE_BIDIR, {47, 384, 0}}; | |
778 | SendCommand(&c); | |
779 | return 0; | |
7fe9b0b7 | 780 | } |
781 | ||
7fe9b0b7 | 782 | int CmdVchDemod(const char *Cmd) |
783 | { | |
e0165dcf | 784 | // Is this the entire sync pattern, or does this also include some |
785 | // data bits that happen to be the same everywhere? That would be | |
786 | // lovely to know. | |
787 | static const int SyncPattern[] = { | |
788 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
789 | 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
790 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
791 | 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
792 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
793 | 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
794 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
795 | 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
796 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
797 | 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
798 | }; | |
799 | ||
800 | // So first, we correlate for the sync pattern, and mark that. | |
801 | int bestCorrel = 0, bestPos = 0; | |
802 | int i; | |
803 | // It does us no good to find the sync pattern, with fewer than | |
804 | // 2048 samples after it... | |
805 | for (i = 0; i < (GraphTraceLen-2048); i++) { | |
806 | int sum = 0; | |
807 | int j; | |
808 | for (j = 0; j < arraylen(SyncPattern); j++) { | |
809 | sum += GraphBuffer[i+j]*SyncPattern[j]; | |
810 | } | |
811 | if (sum > bestCorrel) { | |
812 | bestCorrel = sum; | |
813 | bestPos = i; | |
814 | } | |
815 | } | |
816 | PrintAndLog("best sync at %d [metric %d]", bestPos, bestCorrel); | |
817 | ||
818 | char bits[257]; | |
819 | bits[256] = '\0'; | |
820 | ||
821 | int worst = INT_MAX; | |
822 | int worstPos = 0; | |
823 | ||
824 | for (i = 0; i < 2048; i += 8) { | |
825 | int sum = 0; | |
826 | int j; | |
827 | for (j = 0; j < 8; j++) { | |
828 | sum += GraphBuffer[bestPos+i+j]; | |
829 | } | |
830 | if (sum < 0) { | |
831 | bits[i/8] = '.'; | |
832 | } else { | |
833 | bits[i/8] = '1'; | |
834 | } | |
835 | if(abs(sum) < worst) { | |
836 | worst = abs(sum); | |
837 | worstPos = i; | |
838 | } | |
839 | } | |
840 | PrintAndLog("bits:"); | |
841 | PrintAndLog("%s", bits); | |
842 | PrintAndLog("worst metric: %d at pos %d", worst, worstPos); | |
843 | ||
844 | if (strcmp(Cmd, "clone")==0) { | |
845 | GraphTraceLen = 0; | |
846 | char *s; | |
847 | for(s = bits; *s; s++) { | |
848 | int j; | |
849 | for(j = 0; j < 16; j++) { | |
850 | GraphBuffer[GraphTraceLen++] = (*s == '1') ? 1 : 0; | |
851 | } | |
852 | } | |
853 | RepaintGraphWindow(); | |
854 | } | |
855 | return 0; | |
7fe9b0b7 | 856 | } |
857 | ||
d0b05864 | 858 | |
859 | //by marshmellow | |
860 | int CheckChipType(char cmdp) { | |
861 | uint32_t wordData = 0; | |
862 | ||
863 | //check for em4x05/em4x69 chips first | |
864 | save_restoreGB(1); | |
865 | if ((!offline && (cmdp != '1')) && EM4x05Block0Test(&wordData)) { | |
866 | PrintAndLog("\nValid EM4x05/EM4x69 Chip Found\nTry lf em 4x05... commands\n"); | |
867 | save_restoreGB(0); | |
868 | return 1; | |
869 | } | |
870 | ||
871 | //TODO check for t55xx chip... | |
872 | ||
873 | save_restoreGB(0); | |
874 | return 1; | |
875 | } | |
876 | ||
d5a72d2f | 877 | //by marshmellow |
878 | int CmdLFfind(const char *Cmd) | |
879 | { | |
d0b05864 | 880 | uint32_t wordData = 0; |
e0165dcf | 881 | int ans=0; |
e04475c4 | 882 | size_t minLength = 1000; |
e0165dcf | 883 | char cmdp = param_getchar(Cmd, 0); |
884 | char testRaw = param_getchar(Cmd, 1); | |
885 | if (strlen(Cmd) > 3 || cmdp == 'h' || cmdp == 'H') { | |
886 | PrintAndLog("Usage: lf search <0|1> [u]"); | |
887 | PrintAndLog(" <use data from Graphbuffer> , if not set, try reading data from tag."); | |
888 | PrintAndLog(" [Search for Unknown tags] , if not set, reads only known tags."); | |
889 | PrintAndLog(""); | |
890 | PrintAndLog(" sample: lf search = try reading data from tag & search for known tags"); | |
891 | PrintAndLog(" : lf search 1 = use data from GraphBuffer & search for known tags"); | |
892 | PrintAndLog(" : lf search u = try reading data from tag & search for known and unknown tags"); | |
893 | PrintAndLog(" : lf search 1 u = use data from GraphBuffer & search for known and unknown tags"); | |
894 | ||
895 | return 0; | |
896 | } | |
897 | ||
898 | if (!offline && (cmdp != '1')){ | |
2767fc02 | 899 | CmdLFRead("s"); |
900 | getSamples("30000",false); | |
e04475c4 | 901 | } else if (GraphTraceLen < minLength) { |
e0165dcf | 902 | PrintAndLog("Data in Graphbuffer was too small."); |
903 | return 0; | |
904 | } | |
905 | if (cmdp == 'u' || cmdp == 'U') testRaw = 'u'; | |
906 | ||
907 | PrintAndLog("NOTE: some demods output possible binary\n if it finds something that looks like a tag"); | |
908 | PrintAndLog("False Positives ARE possible\n"); | |
909 | PrintAndLog("\nChecking for known tags:\n"); | |
910 | ||
e04475c4 | 911 | size_t testLen = minLength; |
912 | // only run if graphbuffer is just noise as it should be for hitag/cotag | |
913 | if (graphJustNoise(GraphBuffer, testLen)) { | |
914 | // only run these tests if we are in online mode | |
d0b05864 | 915 | if (!offline && (cmdp != '1')) { |
916 | // test for em4x05 in reader talk first mode. | |
917 | if (EM4x05Block0Test(&wordData)) { | |
918 | PrintAndLog("\nValid EM4x05/EM4x69 Chip Found\nUse lf em 4x05readword/dump commands to read\n"); | |
919 | return 1; | |
920 | } | |
e04475c4 | 921 | ans=CmdLFHitagReader("26"); |
922 | if (ans==0) { | |
923 | return 1; | |
924 | } | |
925 | ans=CmdCOTAGRead(""); | |
926 | if (ans>0){ | |
927 | PrintAndLog("\nValid COTAG ID Found!"); | |
928 | return 1; | |
929 | } | |
930 | } | |
931 | return 0; | |
932 | } | |
933 | ||
e0165dcf | 934 | ans=CmdFSKdemodIO(""); |
935 | if (ans>0) { | |
936 | PrintAndLog("\nValid IO Prox ID Found!"); | |
d0b05864 | 937 | return CheckChipType(cmdp); |
e0165dcf | 938 | } |
939 | ||
940 | ans=CmdFSKdemodPyramid(""); | |
941 | if (ans>0) { | |
942 | PrintAndLog("\nValid Pyramid ID Found!"); | |
d0b05864 | 943 | return CheckChipType(cmdp); |
e0165dcf | 944 | } |
945 | ||
946 | ans=CmdFSKdemodParadox(""); | |
947 | if (ans>0) { | |
948 | PrintAndLog("\nValid Paradox ID Found!"); | |
d0b05864 | 949 | return CheckChipType(cmdp); |
e0165dcf | 950 | } |
951 | ||
952 | ans=CmdFSKdemodAWID(""); | |
953 | if (ans>0) { | |
954 | PrintAndLog("\nValid AWID ID Found!"); | |
d0b05864 | 955 | return CheckChipType(cmdp); |
e0165dcf | 956 | } |
957 | ||
958 | ans=CmdFSKdemodHID(""); | |
959 | if (ans>0) { | |
960 | PrintAndLog("\nValid HID Prox ID Found!"); | |
d0b05864 | 961 | return CheckChipType(cmdp); |
e0165dcf | 962 | } |
963 | ||
e0165dcf | 964 | ans=CmdAskEM410xDemod(""); |
965 | if (ans>0) { | |
966 | PrintAndLog("\nValid EM410x ID Found!"); | |
d0b05864 | 967 | return CheckChipType(cmdp); |
e0165dcf | 968 | } |
969 | ||
8b6abef5 | 970 | ans=CmdVisa2kDemod(""); |
971 | if (ans>0) { | |
972 | PrintAndLog("\nValid Visa2000 ID Found!"); | |
973 | return CheckChipType(cmdp); | |
974 | } | |
975 | ||
e0165dcf | 976 | ans=CmdG_Prox_II_Demod(""); |
977 | if (ans>0) { | |
978 | PrintAndLog("\nValid G Prox II ID Found!"); | |
d0b05864 | 979 | return CheckChipType(cmdp); |
e0165dcf | 980 | } |
981 | ||
4db6f3bb | 982 | ans=CmdFdxDemod(""); |
ecfcb34c | 983 | if (ans>0) { |
984 | PrintAndLog("\nValid FDX-B ID Found!"); | |
d0b05864 | 985 | return CheckChipType(cmdp); |
ecfcb34c | 986 | } |
987 | ||
23f0a7d8 | 988 | ans=EM4x50Read("", false); |
989 | if (ans>0) { | |
990 | PrintAndLog("\nValid EM4x50 ID Found!"); | |
991 | return 1; | |
a9968da3 | 992 | } |
993 | ||
994 | ans=CmdJablotronDemod(""); | |
995 | if (ans>0) { | |
996 | PrintAndLog("\nValid Jablotron ID Found!"); | |
997 | return CheckChipType(cmdp); | |
998 | } | |
999 | ||
1000 | ans=CmdNoralsyDemod(""); | |
1001 | if (ans>0) { | |
1002 | PrintAndLog("\nValid Noralsy ID Found!"); | |
1003 | return CheckChipType(cmdp); | |
1004 | } | |
411105e0 | 1005 | |
415274a7 | 1006 | ans=CmdVikingDemod(""); |
1007 | if (ans>0) { | |
1008 | PrintAndLog("\nValid Viking ID Found!"); | |
d0b05864 | 1009 | return CheckChipType(cmdp); |
a9968da3 | 1010 | } |
415274a7 | 1011 | |
6fe5c94b | 1012 | ans=CmdIndalaDecode(""); |
1013 | if (ans>0) { | |
1014 | PrintAndLog("\nValid Indala ID Found!"); | |
d0b05864 | 1015 | return CheckChipType(cmdp); |
6fe5c94b | 1016 | } |
1017 | ||
411105e0 | 1018 | ans=CmdPSKNexWatch(""); |
1019 | if (ans>0) { | |
1020 | PrintAndLog("\nValid NexWatch ID Found!"); | |
d0b05864 | 1021 | return CheckChipType(cmdp); |
411105e0 | 1022 | } |
1023 | ||
e0165dcf | 1024 | PrintAndLog("\nNo Known Tags Found!\n"); |
1025 | if (testRaw=='u' || testRaw=='U'){ | |
d0b05864 | 1026 | ans=CheckChipType(cmdp); |
1027 | //test unknown tag formats (raw mode)0 | |
e0165dcf | 1028 | PrintAndLog("\nChecking for Unknown tags:\n"); |
7cb8516c | 1029 | ans=AutoCorrelate(4000, false, false); |
e0165dcf | 1030 | if (ans > 0) PrintAndLog("Possible Auto Correlation of %d repeating samples",ans); |
7cb8516c | 1031 | ans=GetFskClock("",false,false); |
e0165dcf | 1032 | if (ans != 0){ //fsk |
7cb8516c | 1033 | ans=FSKrawDemod("",true); |
e0165dcf | 1034 | if (ans>0) { |
1035 | PrintAndLog("\nUnknown FSK Modulated Tag Found!"); | |
e0165dcf | 1036 | return 1; |
1037 | } | |
1038 | } | |
7cb8516c | 1039 | bool st = true; |
1040 | ans=ASKDemod_ext("0 0 0",true,false,1,&st); | |
e0165dcf | 1041 | if (ans>0) { |
1042 | PrintAndLog("\nUnknown ASK Modulated and Manchester encoded Tag Found!"); | |
1043 | PrintAndLog("\nif it does not look right it could instead be ASK/Biphase - try 'data rawdemod ab'"); | |
e0165dcf | 1044 | return 1; |
1045 | } | |
1046 | ans=CmdPSK1rawDemod(""); | |
1047 | if (ans>0) { | |
1048 | PrintAndLog("Possible unknown PSK1 Modulated Tag Found above!\n\nCould also be PSK2 - try 'data rawdemod p2'"); | |
1049 | PrintAndLog("\nCould also be PSK3 - [currently not supported]"); | |
1050 | PrintAndLog("\nCould also be NRZ - try 'data nrzrawdemod"); | |
e0165dcf | 1051 | return 1; |
1052 | } | |
1053 | PrintAndLog("\nNo Data Found!\n"); | |
1054 | } | |
1055 | return 0; | |
d5a72d2f | 1056 | } |
1057 | ||
7fe9b0b7 | 1058 | static command_t CommandTable[] = |
1059 | { | |
e0165dcf | 1060 | {"help", CmdHelp, 1, "This help"}, |
9b99a6db | 1061 | {"awid", CmdLFAWID, 1, "{ AWID RFIDs... }"}, |
1062 | {"cotag", CmdLFCOTAG, 1, "{ COTAG CHIPs... }"}, | |
1063 | {"em", CmdLFEM4X, 1, "{ EM4X CHIPs & RFIDs... }"}, | |
1064 | {"fdx", CmdLFFdx, 1, "{ FDX-B RFIDs... }"}, | |
1065 | {"gproxii", CmdLF_G_Prox_II, 1, "{ G Prox II RFIDs... }"}, | |
1066 | {"hid", CmdLFHID, 1, "{ HID RFIDs... }"}, | |
1067 | {"hitag", CmdLFHitag, 1, "{ Hitag CHIPs... }"}, | |
1068 | {"io", CmdLFIO, 1, "{ ioProx RFIDs... }"}, | |
1069 | {"indala", CmdLFINDALA, 1, "{ Indala RFIDs... }"}, | |
a9968da3 | 1070 | {"jablotron", CmdLFJablotron, 1, "{ Jablotron RFIDs... }"}, |
5bce72d5 | 1071 | {"nexwatch", CmdLFNexWatch, 1, "{ NexWatch RFIDs... }"}, |
a9968da3 | 1072 | {"noralsy", CmdLFNoralsy, 1, "{ Noralsy RFIDs... }"}, |
5bce72d5 | 1073 | {"paradox", CmdLFParadox, 1, "{ Paradox RFIDs... }"}, |
9b99a6db | 1074 | {"presco", CmdLFPresco, 1, "{ Presco RFIDs... }"}, |
1075 | {"pcf7931", CmdLFPCF7931, 1, "{ PCF7931 CHIPs... }"}, | |
6923d3f1 | 1076 | {"pyramid", CmdLFPyramid, 1, "{ Farpointe/Pyramid RFIDs... }"}, |
9b99a6db | 1077 | {"t55xx", CmdLFT55XX, 1, "{ T55xx CHIPs... }"}, |
1078 | {"ti", CmdLFTI, 1, "{ TI CHIPs... }"}, | |
1079 | {"viking", CmdLFViking, 1, "{ Viking RFIDs... }"}, | |
1080 | {"visa2000", CmdLFVisa2k, 1, "{ Visa2000 RFIDs... }"}, | |
21a615cb | 1081 | {"cmdread", CmdLFCommandRead, 0, "<d period> <z period> <o period> <c command> ['H'] -- Modulate LF reader field to send command before read (all periods in microseconds) (option 'H' for 134)"}, |
e0165dcf | 1082 | {"config", CmdLFSetConfig, 0, "Set config for LF sampling, bit/sample, decimation, frequency"}, |
1083 | {"flexdemod", CmdFlexdemod, 1, "Demodulate samples for FlexPass"}, | |
e0165dcf | 1084 | {"read", CmdLFRead, 0, "['s' silent] Read 125/134 kHz LF ID-only tag. Do 'lf read h' for help"}, |
1085 | {"search", CmdLFfind, 1, "[offline] ['u'] Read and Search for valid known tag (in offline mode it you can load first then search) - 'u' to search for unknown tags"}, | |
1086 | {"sim", CmdLFSim, 0, "[GAP] -- Simulate LF tag from buffer with optional GAP (in microseconds)"}, | |
aa53efc3 | 1087 | {"simask", CmdLFaskSim, 0, "[clock] [invert <1|0>] [biphase/manchester/raw <'b'|'m'|'r'>] [msg separator 's'] [d <hexdata>] -- Simulate LF ASK tag from demodbuffer or input"}, |
e0165dcf | 1088 | {"simfsk", CmdLFfskSim, 0, "[c <clock>] [i] [H <fcHigh>] [L <fcLow>] [d <hexdata>] -- Simulate LF FSK tag from demodbuffer or input"}, |
1089 | {"simpsk", CmdLFpskSim, 0, "[1|2|3] [c <clock>] [i] [r <carrier>] [d <raw hex to sim>] -- Simulate LF PSK tag from demodbuffer or input"}, | |
1090 | {"simbidir", CmdLFSimBidir, 0, "Simulate LF tag (with bidirectional data transmission between reader and tag)"}, | |
e0165dcf | 1091 | {"snoop", CmdLFSnoop, 0, "['l'|'h'|<divisor>] [trigger threshold]-- Snoop LF (l:125khz, h:134khz)"}, |
e0165dcf | 1092 | {"vchdemod", CmdVchDemod, 1, "['clone'] -- Demodulate samples for VeriChip"}, |
e0165dcf | 1093 | {NULL, NULL, 0, NULL} |
7fe9b0b7 | 1094 | }; |
1095 | ||
1096 | int CmdLF(const char *Cmd) | |
1097 | { | |
e0165dcf | 1098 | CmdsParse(CommandTable, Cmd); |
1099 | return 0; | |
7fe9b0b7 | 1100 | } |
1101 | ||
1102 | int CmdHelp(const char *Cmd) | |
1103 | { | |
e0165dcf | 1104 | CmdsHelp(CommandTable); |
1105 | return 0; | |
7fe9b0b7 | 1106 | } |