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