1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
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
7 //-----------------------------------------------------------------------------
8 // Low frequency commands
9 //-----------------------------------------------------------------------------
15 #include "proxmark3.h"
17 #include "lfdemod.h" // for psk2TOpsk1
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
36 #include "cmdlfcotag.h" // for COTAG menu
37 #include "cmdlfvisa2000.h" // for VISA2000 menu
38 #include "cmdlfindala.h" // for indala menu
39 #include "cmdlfgproxii.h"// for gproxii menu
41 bool g_lf_threshold_set
= false;
42 static int CmdHelp(const char *Cmd
);
46 int usage_lf_cmdread(void)
48 PrintAndLog("Usage: lf cmdread d <delay period> z <zero period> o <one period> c <cmdbytes> [H] ");
49 PrintAndLog("Options: ");
50 PrintAndLog(" h This help");
51 PrintAndLog(" L Low frequency (125 KHz)");
52 PrintAndLog(" H High frequency (134 KHz)");
53 PrintAndLog(" d <delay> delay OFF period");
54 PrintAndLog(" z <zero> time period ZERO");
55 PrintAndLog(" o <one> time period ONE");
56 PrintAndLog(" c <cmd> Command bytes");
57 PrintAndLog(" ************* All periods in microseconds");
58 PrintAndLog("Examples:");
59 PrintAndLog(" lf cmdread d 80 z 100 o 200 c 11000");
60 PrintAndLog(" lf cmdread d 80 z 100 o 100 c 11000 H");
64 /* send a command before reading */
65 int CmdLFCommandRead(const char *Cmd
)
67 static char dummy
[3] = {0x20,0x00,0x00};
68 UsbCommand c
= {CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K
};
70 //uint8_t divisor = 95; //125khz
72 while(param_getchar(Cmd
, cmdp
) != 0x00)
74 switch(param_getchar(Cmd
, cmdp
))
77 return usage_lf_cmdread();
87 param_getstr(Cmd
, cmdp
+1, (char *)&c
.d
.asBytes
);
91 c
.arg
[0] = param_get32ex(Cmd
, cmdp
+1, 0, 10);
95 c
.arg
[1] = param_get32ex(Cmd
, cmdp
+1, 0, 10);
99 c
.arg
[2] = param_get32ex(Cmd
, cmdp
+1, 0, 10);
103 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
110 if(cmdp
== 0) errors
= 1;
113 if(errors
) return usage_lf_cmdread();
115 // in case they specified 'H'
116 strcpy((char *)&c
.d
.asBytes
+ strlen((char *)c
.d
.asBytes
), dummy
);
118 clearCommandBuffer();
123 int CmdFlexdemod(const char *Cmd
)
126 for (i
= 0; i
< GraphTraceLen
; ++i
) {
127 if (GraphBuffer
[i
] < 0) {
134 #define LONG_WAIT 100
136 for (start
= 0; start
< GraphTraceLen
- LONG_WAIT
; start
++) {
137 int first
= GraphBuffer
[start
];
138 for (i
= start
; i
< start
+ LONG_WAIT
; i
++) {
139 if (GraphBuffer
[i
] != first
) {
143 if (i
== (start
+ LONG_WAIT
)) {
147 if (start
== GraphTraceLen
- LONG_WAIT
) {
148 PrintAndLog("nothing to wait for");
152 GraphBuffer
[start
] = 2;
153 GraphBuffer
[start
+1] = -2;
154 uint8_t bits
[64] = {0x00};
158 for (bit
= 0; bit
< 64; bit
++) {
160 for (int j
= 0; j
< 16; j
++) {
161 sum
+= GraphBuffer
[i
++];
164 bits
[bit
] = (sum
> 0) ? 1 : 0;
166 PrintAndLog("bit %d sum %d", bit
, sum
);
169 for (bit
= 0; bit
< 64; bit
++) {
172 for (j
= 0; j
< 16; j
++) {
173 sum
+= GraphBuffer
[i
++];
175 if (sum
> 0 && bits
[bit
] != 1) {
176 PrintAndLog("oops1 at %d", bit
);
178 if (sum
< 0 && bits
[bit
] != 0) {
179 PrintAndLog("oops2 at %d", bit
);
183 // HACK writing back to graphbuffer.
184 GraphTraceLen
= 32*64;
187 for (bit
= 0; bit
< 64; bit
++) {
189 phase
= (bits
[bit
] == 0) ? 0 : 1;
192 for (j
= 0; j
< 32; j
++) {
193 GraphBuffer
[i
++] = phase
;
198 RepaintGraphWindow();
202 int usage_lf_read(void)
204 PrintAndLog("Usage: lf read");
205 PrintAndLog("Options: ");
206 PrintAndLog(" h This help");
207 PrintAndLog(" s silent run no printout");
208 PrintAndLog("This function takes no arguments. ");
209 PrintAndLog("Use 'lf config' to set parameters.");
212 int usage_lf_snoop(void)
214 PrintAndLog("Usage: lf snoop");
215 PrintAndLog("Options: ");
216 PrintAndLog(" h This help");
217 PrintAndLog("This function takes no arguments. ");
218 PrintAndLog("Use 'lf config' to set parameters.");
222 int usage_lf_config(void)
224 PrintAndLog("Usage: lf config [H|<divisor>] [b <bps>] [d <decim>] [a 0|1]");
225 PrintAndLog("Options: ");
226 PrintAndLog(" h This help");
227 PrintAndLog(" L Low frequency (125 KHz)");
228 PrintAndLog(" H High frequency (134 KHz)");
229 PrintAndLog(" q <divisor> Manually set divisor. 88-> 134KHz, 95-> 125 Hz");
230 PrintAndLog(" b <bps> Sets resolution of bits per sample. Default (max): 8");
231 PrintAndLog(" d <decim> Sets decimation. A value of N saves only 1 in N samples. Default: 1");
232 PrintAndLog(" a [0|1] Averaging - if set, will average the stored sample value when decimating. Default: 1");
233 PrintAndLog(" t <threshold> Sets trigger threshold. 0 means no threshold (range: 0-128)");
234 PrintAndLog("Examples:");
235 PrintAndLog(" lf config b 8 L");
236 PrintAndLog(" Samples at 125KHz, 8bps.");
237 PrintAndLog(" lf config H b 4 d 3");
238 PrintAndLog(" Samples at 134KHz, averages three samples into one, stored with ");
239 PrintAndLog(" a resolution of 4 bits per sample.");
240 PrintAndLog(" lf read");
241 PrintAndLog(" Performs a read (active field)");
242 PrintAndLog(" lf snoop");
243 PrintAndLog(" Performs a snoop (no active field)");
247 int CmdLFSetConfig(const char *Cmd
)
250 uint8_t divisor
= 0;//Frequency divisor
251 uint8_t bps
= 0; // Bits per sample
252 uint8_t decimation
= 0; //How many to keep
253 bool averaging
= 1; // Defaults to true
255 int trigger_threshold
=-1;//Means no change
256 uint8_t unsigned_trigg
= 0;
259 while(param_getchar(Cmd
, cmdp
) != 0x00)
261 switch(param_getchar(Cmd
, cmdp
))
264 return usage_lf_config();
274 errors
|= param_getdec(Cmd
,cmdp
+1,&divisor
);
278 errors
|= param_getdec(Cmd
,cmdp
+1,&unsigned_trigg
);
281 trigger_threshold
= unsigned_trigg
;
282 if (trigger_threshold
> 0) g_lf_threshold_set
= true;
286 errors
|= param_getdec(Cmd
,cmdp
+1,&bps
);
290 errors
|= param_getdec(Cmd
,cmdp
+1,&decimation
);
294 averaging
= param_getchar(Cmd
,cmdp
+1) == '1';
298 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
306 errors
= 1;// No args
312 return usage_lf_config();
314 //Bps is limited to 8, so fits in lower half of arg1
315 if(bps
>> 4) bps
= 8;
317 sample_config config
= {
318 decimation
,bps
,averaging
,divisor
,trigger_threshold
320 //Averaging is a flag on high-bit of arg[1]
321 UsbCommand c
= {CMD_SET_LF_SAMPLING_CONFIG
};
322 memcpy(c
.d
.asBytes
,&config
,sizeof(sample_config
));
323 clearCommandBuffer();
328 int CmdLFRead(const char *Cmd
)
330 if (offline
) return 0;
333 if (param_getchar(Cmd
, cmdp
) == 'h')
335 return usage_lf_read();
337 if (param_getchar(Cmd
, cmdp
) == 's') arg1
= true; //suppress print
338 //And ship it to device
339 UsbCommand c
= {CMD_ACQUIRE_RAW_ADC_SAMPLES_125K
, {arg1
,0,0}};
340 clearCommandBuffer();
342 if (g_lf_threshold_set
) {
343 WaitForResponse(CMD_ACK
,NULL
);
345 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) {
346 PrintAndLog("command execution time out");
353 int CmdLFSnoop(const char *Cmd
)
356 if(param_getchar(Cmd
, cmdp
) == 'h')
358 return usage_lf_snoop();
361 UsbCommand c
= {CMD_LF_SNOOP_RAW_ADC_SAMPLES
};
362 clearCommandBuffer();
364 WaitForResponse(CMD_ACK
,NULL
);
368 static void ChkBitstream(const char *str
)
372 /* convert to bitstream if necessary */
373 for (i
= 0; i
< (int)(GraphTraceLen
/ 2); i
++){
374 if (GraphBuffer
[i
] > 1 || GraphBuffer
[i
] < 0) {
380 //Attempt to simulate any wave in buffer (one bit per output sample)
381 // converts GraphBuffer to bitstream (based on zero crossings) if needed.
382 int CmdLFSim(const char *Cmd
)
387 sscanf(Cmd
, "%i", &gap
);
389 // convert to bitstream if necessary
393 //can send only 512 bits at a time (1 byte sent per bit...)
394 printf("Sending [%d bytes]", GraphTraceLen
);
395 for (i
= 0; i
< GraphTraceLen
; i
+= USB_CMD_DATA_SIZE
) {
396 UsbCommand c
={CMD_DOWNLOADED_SIM_SAMPLES_125K
, {i
, 0, 0}};
398 for (j
= 0; j
< USB_CMD_DATA_SIZE
; j
++) {
399 c
.d
.asBytes
[j
] = GraphBuffer
[i
+j
];
402 WaitForResponse(CMD_ACK
,NULL
);
407 PrintAndLog("Starting to simulate");
408 UsbCommand c
= {CMD_SIMULATE_TAG_125K
, {GraphTraceLen
, gap
, 0}};
409 clearCommandBuffer();
414 int usage_lf_simfsk(void)
417 PrintAndLog("Usage: lf simfsk [c <clock>] [i] [H <fcHigh>] [L <fcLow>] [d <hexdata>]");
418 PrintAndLog("Options: ");
419 PrintAndLog(" h This help");
420 PrintAndLog(" c <clock> Manually set clock - can autodetect if using DemodBuffer");
421 PrintAndLog(" i invert data");
422 PrintAndLog(" H <fcHigh> Manually set the larger Field Clock");
423 PrintAndLog(" L <fcLow> Manually set the smaller Field Clock");
424 //PrintAndLog(" s TBD- -to enable a gap between playback repetitions - default: no gap");
425 PrintAndLog(" d <hexdata> Data to sim as hex - omit to sim from DemodBuffer");
426 PrintAndLog("\n NOTE: if you set one clock manually set them all manually");
430 int usage_lf_simask(void)
433 PrintAndLog("Usage: lf simask [c <clock>] [i] [b|m|r] [s] [d <raw hex to sim>]");
434 PrintAndLog("Options: ");
435 PrintAndLog(" h This help");
436 PrintAndLog(" c <clock> Manually set clock - can autodetect if using DemodBuffer");
437 PrintAndLog(" i invert data");
438 PrintAndLog(" b sim ask/biphase");
439 PrintAndLog(" m sim ask/manchester - Default");
440 PrintAndLog(" r sim ask/raw");
441 PrintAndLog(" s add t55xx Sequence Terminator gap - default: no gaps (only manchester)");
442 PrintAndLog(" d <hexdata> Data to sim as hex - omit to sim from DemodBuffer");
446 int usage_lf_simpsk(void)
449 PrintAndLog("Usage: lf simpsk [1|2|3] [c <clock>] [i] [r <carrier>] [d <raw hex to sim>]");
450 PrintAndLog("Options: ");
451 PrintAndLog(" h This help");
452 PrintAndLog(" c <clock> Manually set clock - can autodetect if using DemodBuffer");
453 PrintAndLog(" i invert data");
454 PrintAndLog(" 1 set PSK1 (default)");
455 PrintAndLog(" 2 set PSK2");
456 PrintAndLog(" 3 set PSK3");
457 PrintAndLog(" r <carrier> 2|4|8 are valid carriers: default = 2");
458 PrintAndLog(" d <hexdata> Data to sim as hex - omit to sim from DemodBuffer");
462 // by marshmellow - sim fsk data given clock, fcHigh, fcLow, invert
463 // - allow pull data from DemodBuffer
464 int CmdLFfskSim(const char *Cmd
)
466 //might be able to autodetect FCs and clock from Graphbuffer if using demod buffer
467 // otherwise will need FChigh, FClow, Clock, and bitstream
468 uint8_t fcHigh
=0, fcLow
=0, clk
=0;
471 char hexData
[32] = {0x00}; // store entered hex data
472 uint8_t data
[255] = {0x00};
475 while(param_getchar(Cmd
, cmdp
) != 0x00)
477 switch(param_getchar(Cmd
, cmdp
))
480 return usage_lf_simfsk();
486 errors
|= param_getdec(Cmd
,cmdp
+1,&clk
);
490 errors
|= param_getdec(Cmd
,cmdp
+1,&fcHigh
);
494 errors
|= param_getdec(Cmd
,cmdp
+1,&fcLow
);
502 dataLen
= param_getstr(Cmd
, cmdp
+1, hexData
);
506 dataLen
= hextobinarray((char *)data
, hexData
);
508 if (dataLen
==0) errors
=true;
509 if (errors
) PrintAndLog ("Error getting hex data");
513 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
519 if(cmdp
== 0 && DemodBufferLen
== 0)
521 errors
= true;// No args
527 return usage_lf_simfsk();
530 if (dataLen
== 0){ //using DemodBuffer
531 if (clk
==0 || fcHigh
==0 || fcLow
==0){ //manual settings must set them all
532 uint8_t ans
= fskClocks(&fcHigh
, &fcLow
, &clk
, 0);
534 if (!fcHigh
) fcHigh
=10;
540 setDemodBuf(data
, dataLen
, 0);
543 //default if not found
544 if (clk
== 0) clk
= 50;
545 if (fcHigh
== 0) fcHigh
= 10;
546 if (fcLow
== 0) fcLow
= 8;
549 arg1
= fcHigh
<< 8 | fcLow
;
550 arg2
= invert
<< 8 | clk
;
551 size_t size
= DemodBufferLen
;
552 if (size
> USB_CMD_DATA_SIZE
) {
553 PrintAndLog("DemodBuffer too long for current implementation - length: %d - max: %d", size
, USB_CMD_DATA_SIZE
);
554 size
= USB_CMD_DATA_SIZE
;
556 UsbCommand c
= {CMD_FSK_SIM_TAG
, {arg1
, arg2
, size
}};
558 memcpy(c
.d
.asBytes
, DemodBuffer
, size
);
559 clearCommandBuffer();
564 // by marshmellow - sim ask data given clock, invert, manchester or raw, separator
565 // - allow pull data from DemodBuffer
566 int CmdLFaskSim(const char *Cmd
)
568 //autodetect clock from Graphbuffer if using demod buffer
569 // needs clock, invert, manchester/raw as m or r, separator as s, and bitstream
570 uint8_t encoding
= 1, separator
= 0;
571 uint8_t clk
=0, invert
=0;
573 char hexData
[32] = {0x00};
574 uint8_t data
[255]= {0x00}; // store entered hex data
577 while(param_getchar(Cmd
, cmdp
) != 0x00)
579 switch(param_getchar(Cmd
, cmdp
))
582 return usage_lf_simask();
588 errors
|= param_getdec(Cmd
,cmdp
+1,&clk
);
592 encoding
=2; //biphase
608 dataLen
= param_getstr(Cmd
, cmdp
+1, hexData
);
612 dataLen
= hextobinarray((char *)data
, hexData
);
614 if (dataLen
==0) errors
=true;
615 if (errors
) PrintAndLog ("Error getting hex data, datalen: %d",dataLen
);
619 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
625 if(cmdp
== 0 && DemodBufferLen
== 0)
627 errors
= true;// No args
633 return usage_lf_simask();
635 if (dataLen
== 0){ //using DemodBuffer
636 if (clk
== 0) clk
= GetAskClock("0", false, false);
638 setDemodBuf(data
, dataLen
, 0);
640 if (clk
== 0) clk
= 64;
641 if (encoding
== 0) clk
= clk
/2; //askraw needs to double the clock speed
643 size_t size
=DemodBufferLen
;
644 arg1
= clk
<< 8 | encoding
;
645 arg2
= invert
<< 8 | separator
;
646 if (size
> USB_CMD_DATA_SIZE
) {
647 PrintAndLog("DemodBuffer too long for current implementation - length: %d - max: %d", size
, USB_CMD_DATA_SIZE
);
648 size
= USB_CMD_DATA_SIZE
;
650 UsbCommand c
= {CMD_ASK_SIM_TAG
, {arg1
, arg2
, size
}};
651 PrintAndLog("preparing to sim ask data: %d bits", size
);
652 memcpy(c
.d
.asBytes
, DemodBuffer
, size
);
653 clearCommandBuffer();
658 // by marshmellow - sim psk data given carrier, clock, invert
659 // - allow pull data from DemodBuffer or parameters
660 int CmdLFpskSim(const char *Cmd
)
662 //might be able to autodetect FC and clock from Graphbuffer if using demod buffer
663 //will need carrier, Clock, and bitstream
664 uint8_t carrier
=0, clk
=0;
667 char hexData
[32] = {0x00}; // store entered hex data
668 uint8_t data
[255] = {0x00};
672 while(param_getchar(Cmd
, cmdp
) != 0x00)
674 switch(param_getchar(Cmd
, cmdp
))
677 return usage_lf_simpsk();
683 errors
|= param_getdec(Cmd
,cmdp
+1,&clk
);
687 errors
|= param_getdec(Cmd
,cmdp
+1,&carrier
);
703 dataLen
= param_getstr(Cmd
, cmdp
+1, hexData
);
707 dataLen
= hextobinarray((char *)data
, hexData
);
709 if (dataLen
==0) errors
=true;
710 if (errors
) PrintAndLog ("Error getting hex data");
714 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
720 if (cmdp
== 0 && DemodBufferLen
== 0)
722 errors
= true;// No args
728 return usage_lf_simpsk();
730 if (dataLen
== 0){ //using DemodBuffer
731 PrintAndLog("Getting Clocks");
732 if (clk
==0) clk
= GetPskClock("", false, false);
733 PrintAndLog("clk: %d",clk
);
734 if (!carrier
) carrier
= GetPskCarrier("", false, false);
735 PrintAndLog("carrier: %d", carrier
);
737 setDemodBuf(data
, dataLen
, 0);
740 if (clk
<= 0) clk
= 32;
741 if (carrier
== 0) carrier
= 2;
744 //need to convert psk2 to psk1 data before sim
745 psk2TOpsk1(DemodBuffer
, DemodBufferLen
);
747 PrintAndLog("Sorry, PSK3 not yet available");
751 arg1
= clk
<< 8 | carrier
;
753 size_t size
=DemodBufferLen
;
754 if (size
> USB_CMD_DATA_SIZE
) {
755 PrintAndLog("DemodBuffer too long for current implementation - length: %d - max: %d", size
, USB_CMD_DATA_SIZE
);
756 size
=USB_CMD_DATA_SIZE
;
758 UsbCommand c
= {CMD_PSK_SIM_TAG
, {arg1
, arg2
, size
}};
759 PrintAndLog("DEBUG: Sending DemodBuffer Length: %d", size
);
760 memcpy(c
.d
.asBytes
, DemodBuffer
, size
);
761 clearCommandBuffer();
767 int CmdLFSimBidir(const char *Cmd
)
769 // Set ADC to twice the carrier for a slight supersampling
770 // HACK: not implemented in ARMSRC.
771 PrintAndLog("Not implemented yet.");
772 UsbCommand c
= {CMD_LF_SIMULATE_BIDIR
, {47, 384, 0}};
777 int CmdVchDemod(const char *Cmd
)
779 // Is this the entire sync pattern, or does this also include some
780 // data bits that happen to be the same everywhere? That would be
782 static const int SyncPattern
[] = {
783 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
784 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
785 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
786 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
787 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
788 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
789 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
790 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
791 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
792 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
795 // So first, we correlate for the sync pattern, and mark that.
796 int bestCorrel
= 0, bestPos
= 0;
798 // It does us no good to find the sync pattern, with fewer than
799 // 2048 samples after it...
800 for (i
= 0; i
< (GraphTraceLen
-2048); i
++) {
803 for (j
= 0; j
< arraylen(SyncPattern
); j
++) {
804 sum
+= GraphBuffer
[i
+j
]*SyncPattern
[j
];
806 if (sum
> bestCorrel
) {
811 PrintAndLog("best sync at %d [metric %d]", bestPos
, bestCorrel
);
819 for (i
= 0; i
< 2048; i
+= 8) {
822 for (j
= 0; j
< 8; j
++) {
823 sum
+= GraphBuffer
[bestPos
+i
+j
];
830 if(abs(sum
) < worst
) {
835 PrintAndLog("bits:");
836 PrintAndLog("%s", bits
);
837 PrintAndLog("worst metric: %d at pos %d", worst
, worstPos
);
839 if (strcmp(Cmd
, "clone")==0) {
842 for(s
= bits
; *s
; s
++) {
844 for(j
= 0; j
< 16; j
++) {
845 GraphBuffer
[GraphTraceLen
++] = (*s
== '1') ? 1 : 0;
848 RepaintGraphWindow();
855 int CheckChipType(char cmdp
) {
856 uint32_t wordData
= 0;
858 //check for em4x05/em4x69 chips first
860 if ((!offline
&& (cmdp
!= '1')) && EM4x05Block0Test(&wordData
)) {
861 PrintAndLog("\nValid EM4x05/EM4x69 Chip Found\nTry lf em 4x05... commands\n");
866 //TODO check for t55xx chip...
873 int CmdLFfind(const char *Cmd
)
875 uint32_t wordData
= 0;
877 size_t minLength
= 1000;
878 char cmdp
= param_getchar(Cmd
, 0);
879 char testRaw
= param_getchar(Cmd
, 1);
880 if (strlen(Cmd
) > 3 || cmdp
== 'h' || cmdp
== 'H') {
881 PrintAndLog("Usage: lf search <0|1> [u]");
882 PrintAndLog(" <use data from Graphbuffer> , if not set, try reading data from tag.");
883 PrintAndLog(" [Search for Unknown tags] , if not set, reads only known tags.");
885 PrintAndLog(" sample: lf search = try reading data from tag & search for known tags");
886 PrintAndLog(" : lf search 1 = use data from GraphBuffer & search for known tags");
887 PrintAndLog(" : lf search u = try reading data from tag & search for known and unknown tags");
888 PrintAndLog(" : lf search 1 u = use data from GraphBuffer & search for known and unknown tags");
893 if (!offline
&& (cmdp
!= '1')){
895 getSamples("30000",false);
896 } else if (GraphTraceLen
< minLength
) {
897 PrintAndLog("Data in Graphbuffer was too small.");
900 if (cmdp
== 'u' || cmdp
== 'U') testRaw
= 'u';
902 PrintAndLog("NOTE: some demods output possible binary\n if it finds something that looks like a tag");
903 PrintAndLog("False Positives ARE possible\n");
904 PrintAndLog("\nChecking for known tags:\n");
906 size_t testLen
= minLength
;
907 // only run if graphbuffer is just noise as it should be for hitag/cotag
908 if (graphJustNoise(GraphBuffer
, testLen
)) {
909 // only run these tests if we are in online mode
910 if (!offline
&& (cmdp
!= '1')) {
911 // test for em4x05 in reader talk first mode.
912 if (EM4x05Block0Test(&wordData
)) {
913 PrintAndLog("\nValid EM4x05/EM4x69 Chip Found\nUse lf em 4x05readword/dump commands to read\n");
916 ans
=CmdLFHitagReader("26");
920 ans
=CmdCOTAGRead("");
922 PrintAndLog("\nValid COTAG ID Found!");
929 ans
=CmdFSKdemodIO("");
931 PrintAndLog("\nValid IO Prox ID Found!");
932 return CheckChipType(cmdp
);
935 ans
=CmdFSKdemodPyramid("");
937 PrintAndLog("\nValid Pyramid ID Found!");
938 return CheckChipType(cmdp
);
941 ans
=CmdFSKdemodParadox("");
943 PrintAndLog("\nValid Paradox ID Found!");
944 return CheckChipType(cmdp
);
947 ans
=CmdFSKdemodAWID("");
949 PrintAndLog("\nValid AWID ID Found!");
950 return CheckChipType(cmdp
);
953 ans
=CmdFSKdemodHID("");
955 PrintAndLog("\nValid HID Prox ID Found!");
956 return CheckChipType(cmdp
);
959 ans
=CmdAskEM410xDemod("");
961 PrintAndLog("\nValid EM410x ID Found!");
962 return CheckChipType(cmdp
);
965 ans
=CmdVisa2kDemod("");
967 PrintAndLog("\nValid Visa2000 ID Found!");
968 return CheckChipType(cmdp
);
971 ans
=CmdG_Prox_II_Demod("");
973 PrintAndLog("\nValid G Prox II ID Found!");
974 return CheckChipType(cmdp
);
977 ans
=CmdFDXBdemodBI("");
979 PrintAndLog("\nValid FDX-B ID Found!");
980 return CheckChipType(cmdp
);
983 ans
=EM4x50Read("", false);
985 PrintAndLog("\nValid EM4x50 ID Found!");
989 ans
=CmdVikingDemod("");
991 PrintAndLog("\nValid Viking ID Found!");
992 return CheckChipType(cmdp
);
995 ans
=CmdIndalaDecode("");
997 PrintAndLog("\nValid Indala ID Found!");
998 return CheckChipType(cmdp
);
1001 ans
=CmdPSKNexWatch("");
1003 PrintAndLog("\nValid NexWatch ID Found!");
1004 return CheckChipType(cmdp
);
1007 PrintAndLog("\nNo Known Tags Found!\n");
1008 if (testRaw
=='u' || testRaw
=='U'){
1009 ans
=CheckChipType(cmdp
);
1010 //test unknown tag formats (raw mode)0
1011 PrintAndLog("\nChecking for Unknown tags:\n");
1012 ans
=AutoCorrelate(4000, false, false);
1013 if (ans
> 0) PrintAndLog("Possible Auto Correlation of %d repeating samples",ans
);
1014 ans
=GetFskClock("",false,false);
1015 if (ans
!= 0){ //fsk
1016 ans
=FSKrawDemod("",true);
1018 PrintAndLog("\nUnknown FSK Modulated Tag Found!");
1023 ans
=ASKDemod_ext("0 0 0",true,false,1,&st
);
1025 PrintAndLog("\nUnknown ASK Modulated and Manchester encoded Tag Found!");
1026 PrintAndLog("\nif it does not look right it could instead be ASK/Biphase - try 'data rawdemod ab'");
1029 ans
=CmdPSK1rawDemod("");
1031 PrintAndLog("Possible unknown PSK1 Modulated Tag Found above!\n\nCould also be PSK2 - try 'data rawdemod p2'");
1032 PrintAndLog("\nCould also be PSK3 - [currently not supported]");
1033 PrintAndLog("\nCould also be NRZ - try 'data nrzrawdemod");
1036 PrintAndLog("\nNo Data Found!\n");
1041 static command_t CommandTable
[] =
1043 {"help", CmdHelp
, 1, "This help"},
1044 {"awid", CmdLFAWID
, 1, "{ AWID RFIDs... }"},
1045 {"cotag", CmdLFCOTAG
, 1, "{ COTAG RFIDs... }"},
1046 {"em", CmdLFEM4X
, 1, "{ EM4X RFIDs... }"},
1047 {"gproxii", CmdLF_G_Prox_II
, 1, "{ G Prox II tags... }"},
1048 {"hid", CmdLFHID
, 1, "{ HID RFIDs... }"},
1049 {"hitag", CmdLFHitag
, 1, "{ Hitag tags and transponders... }"},
1050 {"io", CmdLFIO
, 1, "{ ioProx tags... }"},
1051 {"indala", CmdLFINDALA
, 1, "{ Indala tags... }"},
1052 {"presco", CmdLFPresco
, 1, "{ Presco RFIDs... }"},
1053 {"pcf7931", CmdLFPCF7931
, 1, "{ PCF7931 RFIDs... }"},
1054 {"pyramid", CmdLFPyramid
, 1, "{ Farpointe/Pyramid RFIDs... }"},
1055 {"t55xx", CmdLFT55XX
, 1, "{ T55xx RFIDs... }"},
1056 {"ti", CmdLFTI
, 1, "{ TI RFIDs... }"},
1057 {"viking", CmdLFViking
, 1, "{ Viking tags... }"},
1058 {"visa2000", CmdLFVisa2k
, 1, "{ Visa2000 RFIDs...}"},
1059 {"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)"},
1060 {"config", CmdLFSetConfig
, 0, "Set config for LF sampling, bit/sample, decimation, frequency"},
1061 {"flexdemod", CmdFlexdemod
, 1, "Demodulate samples for FlexPass"},
1062 {"read", CmdLFRead
, 0, "['s' silent] Read 125/134 kHz LF ID-only tag. Do 'lf read h' for help"},
1063 {"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"},
1064 {"sim", CmdLFSim
, 0, "[GAP] -- Simulate LF tag from buffer with optional GAP (in microseconds)"},
1065 {"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"},
1066 {"simfsk", CmdLFfskSim
, 0, "[c <clock>] [i] [H <fcHigh>] [L <fcLow>] [d <hexdata>] -- Simulate LF FSK tag from demodbuffer or input"},
1067 {"simpsk", CmdLFpskSim
, 0, "[1|2|3] [c <clock>] [i] [r <carrier>] [d <raw hex to sim>] -- Simulate LF PSK tag from demodbuffer or input"},
1068 {"simbidir", CmdLFSimBidir
, 0, "Simulate LF tag (with bidirectional data transmission between reader and tag)"},
1069 {"snoop", CmdLFSnoop
, 0, "['l'|'h'|<divisor>] [trigger threshold]-- Snoop LF (l:125khz, h:134khz)"},
1070 {"vchdemod", CmdVchDemod
, 1, "['clone'] -- Demodulate samples for VeriChip"},
1071 {NULL
, NULL
, 0, NULL
}
1074 int CmdLF(const char *Cmd
)
1076 CmdsParse(CommandTable
, Cmd
);
1080 int CmdHelp(const char *Cmd
)
1082 CmdsHelp(CommandTable
);