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