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