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
40 #include "cmdlffdx.h" // for fdx-b menu
41 #include "cmdlfparadox.h"// for paradox menu
42 #include "cmdlfnexwatch.h"//for nexwatch menu
43 #include "cmdlfjablotron.h" //for jablotron menu
44 #include "cmdlfnoralsy.h"// for noralsy menu
46 bool g_lf_threshold_set
= false;
47 static int CmdHelp(const char *Cmd
);
51 int usage_lf_cmdread(void)
53 PrintAndLog("Usage: lf cmdread d <delay period> z <zero period> o <one period> c <cmdbytes> [H] ");
54 PrintAndLog("Options: ");
55 PrintAndLog(" h This help");
56 PrintAndLog(" L Low frequency (125 KHz)");
57 PrintAndLog(" H High frequency (134 KHz)");
58 PrintAndLog(" d <delay> delay OFF period");
59 PrintAndLog(" z <zero> time period ZERO");
60 PrintAndLog(" o <one> time period ONE");
61 PrintAndLog(" c <cmd> Command bytes");
62 PrintAndLog(" ************* All periods in microseconds");
63 PrintAndLog("Examples:");
64 PrintAndLog(" lf cmdread d 80 z 100 o 200 c 11000");
65 PrintAndLog(" lf cmdread d 80 z 100 o 100 c 11000 H");
69 /* send a command before reading */
70 int CmdLFCommandRead(const char *Cmd
)
72 static char dummy
[3] = {0x20,0x00,0x00};
73 UsbCommand c
= {CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K
};
75 //uint8_t divisor = 95; //125khz
77 while(param_getchar(Cmd
, cmdp
) != 0x00)
79 switch(param_getchar(Cmd
, cmdp
))
82 return usage_lf_cmdread();
92 param_getstr(Cmd
, cmdp
+1, (char *)&c
.d
.asBytes
);
96 c
.arg
[0] = param_get32ex(Cmd
, cmdp
+1, 0, 10);
100 c
.arg
[1] = param_get32ex(Cmd
, cmdp
+1, 0, 10);
104 c
.arg
[2] = param_get32ex(Cmd
, cmdp
+1, 0, 10);
108 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
115 if(cmdp
== 0) errors
= 1;
118 if(errors
) return usage_lf_cmdread();
120 // in case they specified 'H'
121 strcpy((char *)&c
.d
.asBytes
+ strlen((char *)c
.d
.asBytes
), dummy
);
123 clearCommandBuffer();
128 int CmdFlexdemod(const char *Cmd
)
131 for (i
= 0; i
< GraphTraceLen
; ++i
) {
132 if (GraphBuffer
[i
] < 0) {
139 #define LONG_WAIT 100
141 for (start
= 0; start
< GraphTraceLen
- LONG_WAIT
; start
++) {
142 int first
= GraphBuffer
[start
];
143 for (i
= start
; i
< start
+ LONG_WAIT
; i
++) {
144 if (GraphBuffer
[i
] != first
) {
148 if (i
== (start
+ LONG_WAIT
)) {
152 if (start
== GraphTraceLen
- LONG_WAIT
) {
153 PrintAndLog("nothing to wait for");
157 GraphBuffer
[start
] = 2;
158 GraphBuffer
[start
+1] = -2;
159 uint8_t bits
[64] = {0x00};
163 for (bit
= 0; bit
< 64; bit
++) {
165 for (int j
= 0; j
< 16; j
++) {
166 sum
+= GraphBuffer
[i
++];
169 bits
[bit
] = (sum
> 0) ? 1 : 0;
171 PrintAndLog("bit %d sum %d", bit
, sum
);
174 for (bit
= 0; bit
< 64; bit
++) {
177 for (j
= 0; j
< 16; j
++) {
178 sum
+= GraphBuffer
[i
++];
180 if (sum
> 0 && bits
[bit
] != 1) {
181 PrintAndLog("oops1 at %d", bit
);
183 if (sum
< 0 && bits
[bit
] != 0) {
184 PrintAndLog("oops2 at %d", bit
);
188 // HACK writing back to graphbuffer.
189 GraphTraceLen
= 32*64;
192 for (bit
= 0; bit
< 64; bit
++) {
194 phase
= (bits
[bit
] == 0) ? 0 : 1;
197 for (j
= 0; j
< 32; j
++) {
198 GraphBuffer
[i
++] = phase
;
203 RepaintGraphWindow();
207 int usage_lf_read(void)
209 PrintAndLog("Usage: lf read");
210 PrintAndLog("Options: ");
211 PrintAndLog(" h This help");
212 PrintAndLog(" s silent run no printout");
213 PrintAndLog("This function takes no arguments. ");
214 PrintAndLog("Use 'lf config' to set parameters.");
217 int usage_lf_snoop(void)
219 PrintAndLog("Usage: lf snoop");
220 PrintAndLog("Options: ");
221 PrintAndLog(" h This help");
222 PrintAndLog("This function takes no arguments. ");
223 PrintAndLog("Use 'lf config' to set parameters.");
227 int usage_lf_config(void)
229 PrintAndLog("Usage: lf config [H|<divisor>] [b <bps>] [d <decim>] [a 0|1]");
230 PrintAndLog("Options: ");
231 PrintAndLog(" h This help");
232 PrintAndLog(" L Low frequency (125 KHz)");
233 PrintAndLog(" H High frequency (134 KHz)");
234 PrintAndLog(" q <divisor> Manually set divisor. 88-> 134KHz, 95-> 125 Hz");
235 PrintAndLog(" b <bps> Sets resolution of bits per sample. Default (max): 8");
236 PrintAndLog(" d <decim> Sets decimation. A value of N saves only 1 in N samples. Default: 1");
237 PrintAndLog(" a [0|1] Averaging - if set, will average the stored sample value when decimating. Default: 1");
238 PrintAndLog(" t <threshold> Sets trigger threshold. 0 means no threshold (range: 0-128)");
239 PrintAndLog("Examples:");
240 PrintAndLog(" lf config b 8 L");
241 PrintAndLog(" Samples at 125KHz, 8bps.");
242 PrintAndLog(" lf config H b 4 d 3");
243 PrintAndLog(" Samples at 134KHz, averages three samples into one, stored with ");
244 PrintAndLog(" a resolution of 4 bits per sample.");
245 PrintAndLog(" lf read");
246 PrintAndLog(" Performs a read (active field)");
247 PrintAndLog(" lf snoop");
248 PrintAndLog(" Performs a snoop (no active field)");
252 int CmdLFSetConfig(const char *Cmd
)
255 uint8_t divisor
= 0;//Frequency divisor
256 uint8_t bps
= 0; // Bits per sample
257 uint8_t decimation
= 0; //How many to keep
258 bool averaging
= 1; // Defaults to true
260 int trigger_threshold
=-1;//Means no change
261 uint8_t unsigned_trigg
= 0;
264 while(param_getchar(Cmd
, cmdp
) != 0x00)
266 switch(param_getchar(Cmd
, cmdp
))
269 return usage_lf_config();
279 errors
|= param_getdec(Cmd
,cmdp
+1,&divisor
);
283 errors
|= param_getdec(Cmd
,cmdp
+1,&unsigned_trigg
);
286 trigger_threshold
= unsigned_trigg
;
287 if (trigger_threshold
> 0) g_lf_threshold_set
= true;
291 errors
|= param_getdec(Cmd
,cmdp
+1,&bps
);
295 errors
|= param_getdec(Cmd
,cmdp
+1,&decimation
);
299 averaging
= param_getchar(Cmd
,cmdp
+1) == '1';
303 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
311 errors
= 1;// No args
317 return usage_lf_config();
319 //Bps is limited to 8, so fits in lower half of arg1
320 if(bps
>> 4) bps
= 8;
322 sample_config config
= {
323 decimation
,bps
,averaging
,divisor
,trigger_threshold
325 //Averaging is a flag on high-bit of arg[1]
326 UsbCommand c
= {CMD_SET_LF_SAMPLING_CONFIG
};
327 memcpy(c
.d
.asBytes
,&config
,sizeof(sample_config
));
328 clearCommandBuffer();
333 int CmdLFRead(const char *Cmd
)
335 if (offline
) return 0;
338 if (param_getchar(Cmd
, cmdp
) == 'h')
340 return usage_lf_read();
342 if (param_getchar(Cmd
, cmdp
) == 's') arg1
= true; //suppress print
343 //And ship it to device
344 UsbCommand c
= {CMD_ACQUIRE_RAW_ADC_SAMPLES_125K
, {arg1
,0,0}};
345 clearCommandBuffer();
347 if (g_lf_threshold_set
) {
348 WaitForResponse(CMD_ACK
,NULL
);
350 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) {
351 PrintAndLog("command execution time out");
358 int CmdLFSnoop(const char *Cmd
)
361 if(param_getchar(Cmd
, cmdp
) == 'h')
363 return usage_lf_snoop();
366 UsbCommand c
= {CMD_LF_SNOOP_RAW_ADC_SAMPLES
};
367 clearCommandBuffer();
369 WaitForResponse(CMD_ACK
,NULL
);
373 static void ChkBitstream(const char *str
)
377 /* convert to bitstream if necessary */
378 for (i
= 0; i
< (int)(GraphTraceLen
/ 2); i
++){
379 if (GraphBuffer
[i
] > 1 || GraphBuffer
[i
] < 0) {
385 //Attempt to simulate any wave in buffer (one bit per output sample)
386 // converts GraphBuffer to bitstream (based on zero crossings) if needed.
387 int CmdLFSim(const char *Cmd
)
392 sscanf(Cmd
, "%i", &gap
);
394 // convert to bitstream if necessary
398 //can send only 512 bits at a time (1 byte sent per bit...)
399 printf("Sending [%d bytes]", GraphTraceLen
);
400 for (i
= 0; i
< GraphTraceLen
; i
+= USB_CMD_DATA_SIZE
) {
401 UsbCommand c
={CMD_DOWNLOADED_SIM_SAMPLES_125K
, {i
, 0, 0}};
403 for (j
= 0; j
< USB_CMD_DATA_SIZE
; j
++) {
404 c
.d
.asBytes
[j
] = GraphBuffer
[i
+j
];
407 WaitForResponse(CMD_ACK
,NULL
);
412 PrintAndLog("Starting to simulate");
413 UsbCommand c
= {CMD_SIMULATE_TAG_125K
, {GraphTraceLen
, gap
, 0}};
414 clearCommandBuffer();
419 int usage_lf_simfsk(void)
422 PrintAndLog("Usage: lf simfsk [c <clock>] [i] [H <fcHigh>] [L <fcLow>] [d <hexdata>]");
423 PrintAndLog("Options: ");
424 PrintAndLog(" h This help");
425 PrintAndLog(" c <clock> Manually set clock - can autodetect if using DemodBuffer");
426 PrintAndLog(" i invert data");
427 PrintAndLog(" H <fcHigh> Manually set the larger Field Clock");
428 PrintAndLog(" L <fcLow> Manually set the smaller Field Clock");
429 //PrintAndLog(" s TBD- -to enable a gap between playback repetitions - default: no gap");
430 PrintAndLog(" d <hexdata> Data to sim as hex - omit to sim from DemodBuffer");
431 PrintAndLog("\n NOTE: if you set one clock manually set them all manually");
435 int usage_lf_simask(void)
438 PrintAndLog("Usage: lf simask [c <clock>] [i] [b|m|r] [s] [d <raw hex to sim>]");
439 PrintAndLog("Options: ");
440 PrintAndLog(" h This help");
441 PrintAndLog(" c <clock> Manually set clock - can autodetect if using DemodBuffer");
442 PrintAndLog(" i invert data");
443 PrintAndLog(" b sim ask/biphase");
444 PrintAndLog(" m sim ask/manchester - Default");
445 PrintAndLog(" r sim ask/raw");
446 PrintAndLog(" s add t55xx Sequence Terminator gap - default: no gaps (only manchester)");
447 PrintAndLog(" d <hexdata> Data to sim as hex - omit to sim from DemodBuffer");
451 int usage_lf_simpsk(void)
454 PrintAndLog("Usage: lf simpsk [1|2|3] [c <clock>] [i] [r <carrier>] [d <raw hex to sim>]");
455 PrintAndLog("Options: ");
456 PrintAndLog(" h This help");
457 PrintAndLog(" c <clock> Manually set clock - can autodetect if using DemodBuffer");
458 PrintAndLog(" i invert data");
459 PrintAndLog(" 1 set PSK1 (default)");
460 PrintAndLog(" 2 set PSK2");
461 PrintAndLog(" 3 set PSK3");
462 PrintAndLog(" r <carrier> 2|4|8 are valid carriers: default = 2");
463 PrintAndLog(" d <hexdata> Data to sim as hex - omit to sim from DemodBuffer");
467 // by marshmellow - sim fsk data given clock, fcHigh, fcLow, invert
468 // - allow pull data from DemodBuffer
469 int CmdLFfskSim(const char *Cmd
)
471 //might be able to autodetect FCs and clock from Graphbuffer if using demod buffer
472 // otherwise will need FChigh, FClow, Clock, and bitstream
473 uint8_t fcHigh
=0, fcLow
=0, clk
=0;
476 char hexData
[32] = {0x00}; // store entered hex data
477 uint8_t data
[255] = {0x00};
480 while(param_getchar(Cmd
, cmdp
) != 0x00)
482 switch(param_getchar(Cmd
, cmdp
))
485 return usage_lf_simfsk();
491 errors
|= param_getdec(Cmd
,cmdp
+1,&clk
);
495 errors
|= param_getdec(Cmd
,cmdp
+1,&fcHigh
);
499 errors
|= param_getdec(Cmd
,cmdp
+1,&fcLow
);
507 dataLen
= param_getstr(Cmd
, cmdp
+1, hexData
);
511 dataLen
= hextobinarray((char *)data
, hexData
);
513 if (dataLen
==0) errors
=true;
514 if (errors
) PrintAndLog ("Error getting hex data");
518 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
524 if(cmdp
== 0 && DemodBufferLen
== 0)
526 errors
= true;// No args
532 return usage_lf_simfsk();
535 if (dataLen
== 0){ //using DemodBuffer
536 if (clk
==0 || fcHigh
==0 || fcLow
==0){ //manual settings must set them all
537 uint8_t ans
= fskClocks(&fcHigh
, &fcLow
, &clk
, 0);
539 if (!fcHigh
) fcHigh
=10;
545 setDemodBuf(data
, dataLen
, 0);
548 //default if not found
549 if (clk
== 0) clk
= 50;
550 if (fcHigh
== 0) fcHigh
= 10;
551 if (fcLow
== 0) fcLow
= 8;
554 arg1
= fcHigh
<< 8 | fcLow
;
555 arg2
= invert
<< 8 | clk
;
556 size_t size
= DemodBufferLen
;
557 if (size
> USB_CMD_DATA_SIZE
) {
558 PrintAndLog("DemodBuffer too long for current implementation - length: %d - max: %d", size
, USB_CMD_DATA_SIZE
);
559 size
= USB_CMD_DATA_SIZE
;
561 UsbCommand c
= {CMD_FSK_SIM_TAG
, {arg1
, arg2
, size
}};
563 memcpy(c
.d
.asBytes
, DemodBuffer
, size
);
564 clearCommandBuffer();
569 // by marshmellow - sim ask data given clock, invert, manchester or raw, separator
570 // - allow pull data from DemodBuffer
571 int CmdLFaskSim(const char *Cmd
)
573 //autodetect clock from Graphbuffer if using demod buffer
574 // needs clock, invert, manchester/raw as m or r, separator as s, and bitstream
575 uint8_t encoding
= 1, separator
= 0;
576 uint8_t clk
=0, invert
=0;
578 char hexData
[32] = {0x00};
579 uint8_t data
[255]= {0x00}; // store entered hex data
582 while(param_getchar(Cmd
, cmdp
) != 0x00)
584 switch(param_getchar(Cmd
, cmdp
))
587 return usage_lf_simask();
593 errors
|= param_getdec(Cmd
,cmdp
+1,&clk
);
597 encoding
=2; //biphase
613 dataLen
= param_getstr(Cmd
, cmdp
+1, hexData
);
617 dataLen
= hextobinarray((char *)data
, hexData
);
619 if (dataLen
==0) errors
=true;
620 if (errors
) PrintAndLog ("Error getting hex data, datalen: %d",dataLen
);
624 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
630 if(cmdp
== 0 && DemodBufferLen
== 0)
632 errors
= true;// No args
638 return usage_lf_simask();
640 if (dataLen
== 0){ //using DemodBuffer
641 if (clk
== 0) clk
= GetAskClock("0", false, false);
643 setDemodBuf(data
, dataLen
, 0);
645 if (clk
== 0) clk
= 64;
646 if (encoding
== 0) clk
= clk
/2; //askraw needs to double the clock speed
648 size_t size
=DemodBufferLen
;
649 arg1
= clk
<< 8 | encoding
;
650 arg2
= invert
<< 8 | separator
;
651 if (size
> USB_CMD_DATA_SIZE
) {
652 PrintAndLog("DemodBuffer too long for current implementation - length: %d - max: %d", size
, USB_CMD_DATA_SIZE
);
653 size
= USB_CMD_DATA_SIZE
;
655 UsbCommand c
= {CMD_ASK_SIM_TAG
, {arg1
, arg2
, size
}};
656 PrintAndLog("preparing to sim ask data: %d bits", size
);
657 memcpy(c
.d
.asBytes
, DemodBuffer
, size
);
658 clearCommandBuffer();
663 // by marshmellow - sim psk data given carrier, clock, invert
664 // - allow pull data from DemodBuffer or parameters
665 int CmdLFpskSim(const char *Cmd
)
667 //might be able to autodetect FC and clock from Graphbuffer if using demod buffer
668 //will need carrier, Clock, and bitstream
669 uint8_t carrier
=0, clk
=0;
672 char hexData
[32] = {0x00}; // store entered hex data
673 uint8_t data
[255] = {0x00};
677 while(param_getchar(Cmd
, cmdp
) != 0x00)
679 switch(param_getchar(Cmd
, cmdp
))
682 return usage_lf_simpsk();
688 errors
|= param_getdec(Cmd
,cmdp
+1,&clk
);
692 errors
|= param_getdec(Cmd
,cmdp
+1,&carrier
);
708 dataLen
= param_getstr(Cmd
, cmdp
+1, hexData
);
712 dataLen
= hextobinarray((char *)data
, hexData
);
714 if (dataLen
==0) errors
=true;
715 if (errors
) PrintAndLog ("Error getting hex data");
719 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
725 if (cmdp
== 0 && DemodBufferLen
== 0)
727 errors
= true;// No args
733 return usage_lf_simpsk();
735 if (dataLen
== 0){ //using DemodBuffer
736 PrintAndLog("Getting Clocks");
737 if (clk
==0) clk
= GetPskClock("", false, false);
738 PrintAndLog("clk: %d",clk
);
739 if (!carrier
) carrier
= GetPskCarrier("", false, false);
740 PrintAndLog("carrier: %d", carrier
);
742 setDemodBuf(data
, dataLen
, 0);
745 if (clk
<= 0) clk
= 32;
746 if (carrier
== 0) carrier
= 2;
749 //need to convert psk2 to psk1 data before sim
750 psk2TOpsk1(DemodBuffer
, DemodBufferLen
);
752 PrintAndLog("Sorry, PSK3 not yet available");
756 arg1
= clk
<< 8 | carrier
;
758 size_t size
=DemodBufferLen
;
759 if (size
> USB_CMD_DATA_SIZE
) {
760 PrintAndLog("DemodBuffer too long for current implementation - length: %d - max: %d", size
, USB_CMD_DATA_SIZE
);
761 size
=USB_CMD_DATA_SIZE
;
763 UsbCommand c
= {CMD_PSK_SIM_TAG
, {arg1
, arg2
, size
}};
764 PrintAndLog("DEBUG: Sending DemodBuffer Length: %d", size
);
765 memcpy(c
.d
.asBytes
, DemodBuffer
, size
);
766 clearCommandBuffer();
772 int CmdLFSimBidir(const char *Cmd
)
774 // Set ADC to twice the carrier for a slight supersampling
775 // HACK: not implemented in ARMSRC.
776 PrintAndLog("Not implemented yet.");
777 UsbCommand c
= {CMD_LF_SIMULATE_BIDIR
, {47, 384, 0}};
782 int CmdVchDemod(const char *Cmd
)
784 // Is this the entire sync pattern, or does this also include some
785 // data bits that happen to be the same everywhere? That would be
787 static const int SyncPattern
[] = {
788 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
789 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
790 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
791 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
792 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
793 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
794 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
795 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
796 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
797 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
800 // So first, we correlate for the sync pattern, and mark that.
801 int bestCorrel
= 0, bestPos
= 0;
803 // It does us no good to find the sync pattern, with fewer than
804 // 2048 samples after it...
805 for (i
= 0; i
< (GraphTraceLen
-2048); i
++) {
808 for (j
= 0; j
< arraylen(SyncPattern
); j
++) {
809 sum
+= GraphBuffer
[i
+j
]*SyncPattern
[j
];
811 if (sum
> bestCorrel
) {
816 PrintAndLog("best sync at %d [metric %d]", bestPos
, bestCorrel
);
824 for (i
= 0; i
< 2048; i
+= 8) {
827 for (j
= 0; j
< 8; j
++) {
828 sum
+= GraphBuffer
[bestPos
+i
+j
];
835 if(abs(sum
) < worst
) {
840 PrintAndLog("bits:");
841 PrintAndLog("%s", bits
);
842 PrintAndLog("worst metric: %d at pos %d", worst
, worstPos
);
844 if (strcmp(Cmd
, "clone")==0) {
847 for(s
= bits
; *s
; s
++) {
849 for(j
= 0; j
< 16; j
++) {
850 GraphBuffer
[GraphTraceLen
++] = (*s
== '1') ? 1 : 0;
853 RepaintGraphWindow();
860 int CheckChipType(char cmdp
) {
861 uint32_t wordData
= 0;
863 //check for em4x05/em4x69 chips first
865 if ((!offline
&& (cmdp
!= '1')) && EM4x05Block0Test(&wordData
)) {
866 PrintAndLog("\nValid EM4x05/EM4x69 Chip Found\nTry lf em 4x05... commands\n");
871 //TODO check for t55xx chip...
878 int CmdLFfind(const char *Cmd
)
880 uint32_t wordData
= 0;
882 size_t minLength
= 1000;
883 char cmdp
= param_getchar(Cmd
, 0);
884 char testRaw
= param_getchar(Cmd
, 1);
885 if (strlen(Cmd
) > 3 || cmdp
== 'h' || cmdp
== 'H') {
886 PrintAndLog("Usage: lf search <0|1> [u]");
887 PrintAndLog(" <use data from Graphbuffer> , if not set, try reading data from tag.");
888 PrintAndLog(" [Search for Unknown tags] , if not set, reads only known tags.");
890 PrintAndLog(" sample: lf search = try reading data from tag & search for known tags");
891 PrintAndLog(" : lf search 1 = use data from GraphBuffer & search for known tags");
892 PrintAndLog(" : lf search u = try reading data from tag & search for known and unknown tags");
893 PrintAndLog(" : lf search 1 u = use data from GraphBuffer & search for known and unknown tags");
898 if (!offline
&& (cmdp
!= '1')){
900 getSamples("30000",false);
901 } else if (GraphTraceLen
< minLength
) {
902 PrintAndLog("Data in Graphbuffer was too small.");
905 if (cmdp
== 'u' || cmdp
== 'U') testRaw
= 'u';
907 PrintAndLog("NOTE: some demods output possible binary\n if it finds something that looks like a tag");
908 PrintAndLog("False Positives ARE possible\n");
909 PrintAndLog("\nChecking for known tags:\n");
911 size_t testLen
= minLength
;
912 // only run if graphbuffer is just noise as it should be for hitag/cotag
913 if (graphJustNoise(GraphBuffer
, testLen
)) {
914 // only run these tests if we are in online mode
915 if (!offline
&& (cmdp
!= '1')) {
916 // test for em4x05 in reader talk first mode.
917 if (EM4x05Block0Test(&wordData
)) {
918 PrintAndLog("\nValid EM4x05/EM4x69 Chip Found\nUse lf em 4x05readword/dump commands to read\n");
921 ans
=CmdLFHitagReader("26");
925 ans
=CmdCOTAGRead("");
927 PrintAndLog("\nValid COTAG ID Found!");
934 ans
=CmdFSKdemodIO("");
936 PrintAndLog("\nValid IO Prox ID Found!");
937 return CheckChipType(cmdp
);
940 ans
=CmdFSKdemodPyramid("");
942 PrintAndLog("\nValid Pyramid ID Found!");
943 return CheckChipType(cmdp
);
946 ans
=CmdFSKdemodParadox("");
948 PrintAndLog("\nValid Paradox ID Found!");
949 return CheckChipType(cmdp
);
952 ans
=CmdFSKdemodAWID("");
954 PrintAndLog("\nValid AWID ID Found!");
955 return CheckChipType(cmdp
);
958 ans
=CmdFSKdemodHID("");
960 PrintAndLog("\nValid HID Prox ID Found!");
961 return CheckChipType(cmdp
);
964 ans
=CmdAskEM410xDemod("");
966 PrintAndLog("\nValid EM410x ID Found!");
967 return CheckChipType(cmdp
);
970 ans
=CmdVisa2kDemod("");
972 PrintAndLog("\nValid Visa2000 ID Found!");
973 return CheckChipType(cmdp
);
976 ans
=CmdG_Prox_II_Demod("");
978 PrintAndLog("\nValid G Prox II ID Found!");
979 return CheckChipType(cmdp
);
984 PrintAndLog("\nValid FDX-B ID Found!");
985 return CheckChipType(cmdp
);
988 ans
=EM4x50Read("", false);
990 PrintAndLog("\nValid EM4x50 ID Found!");
994 ans
=CmdJablotronDemod("");
996 PrintAndLog("\nValid Jablotron ID Found!");
997 return CheckChipType(cmdp
);
1000 ans
=CmdNoralsyDemod("");
1002 PrintAndLog("\nValid Noralsy ID Found!");
1003 return CheckChipType(cmdp
);
1006 ans
=CmdVikingDemod("");
1008 PrintAndLog("\nValid Viking ID Found!");
1009 return CheckChipType(cmdp
);
1012 ans
=CmdIndalaDecode("");
1014 PrintAndLog("\nValid Indala ID Found!");
1015 return CheckChipType(cmdp
);
1018 ans
=CmdPSKNexWatch("");
1020 PrintAndLog("\nValid NexWatch ID Found!");
1021 return CheckChipType(cmdp
);
1024 PrintAndLog("\nNo Known Tags Found!\n");
1025 if (testRaw
=='u' || testRaw
=='U'){
1026 ans
=CheckChipType(cmdp
);
1027 //test unknown tag formats (raw mode)0
1028 PrintAndLog("\nChecking for Unknown tags:\n");
1029 ans
=AutoCorrelate(4000, false, false);
1030 if (ans
> 0) PrintAndLog("Possible Auto Correlation of %d repeating samples",ans
);
1031 ans
=GetFskClock("",false,false);
1032 if (ans
!= 0){ //fsk
1033 ans
=FSKrawDemod("",true);
1035 PrintAndLog("\nUnknown FSK Modulated Tag Found!");
1040 ans
=ASKDemod_ext("0 0 0",true,false,1,&st
);
1042 PrintAndLog("\nUnknown ASK Modulated and Manchester encoded Tag Found!");
1043 PrintAndLog("\nif it does not look right it could instead be ASK/Biphase - try 'data rawdemod ab'");
1046 ans
=CmdPSK1rawDemod("");
1048 PrintAndLog("Possible unknown PSK1 Modulated Tag Found above!\n\nCould also be PSK2 - try 'data rawdemod p2'");
1049 PrintAndLog("\nCould also be PSK3 - [currently not supported]");
1050 PrintAndLog("\nCould also be NRZ - try 'data nrzrawdemod");
1053 PrintAndLog("\nNo Data Found!\n");
1058 static command_t CommandTable
[] =
1060 {"help", CmdHelp
, 1, "This help"},
1061 {"awid", CmdLFAWID
, 1, "{ AWID RFIDs... }"},
1062 {"cotag", CmdLFCOTAG
, 1, "{ COTAG CHIPs... }"},
1063 {"em", CmdLFEM4X
, 1, "{ EM4X CHIPs & RFIDs... }"},
1064 {"fdx", CmdLFFdx
, 1, "{ FDX-B RFIDs... }"},
1065 {"gproxii", CmdLF_G_Prox_II
, 1, "{ G Prox II RFIDs... }"},
1066 {"hid", CmdLFHID
, 1, "{ HID RFIDs... }"},
1067 {"hitag", CmdLFHitag
, 1, "{ Hitag CHIPs... }"},
1068 {"io", CmdLFIO
, 1, "{ ioProx RFIDs... }"},
1069 {"indala", CmdLFINDALA
, 1, "{ Indala RFIDs... }"},
1070 {"jablotron", CmdLFJablotron
, 1, "{ Jablotron RFIDs... }"},
1071 {"nexwatch", CmdLFNexWatch
, 1, "{ NexWatch RFIDs... }"},
1072 {"noralsy", CmdLFNoralsy
, 1, "{ Noralsy RFIDs... }"},
1073 {"paradox", CmdLFParadox
, 1, "{ Paradox RFIDs... }"},
1074 {"presco", CmdLFPresco
, 1, "{ Presco RFIDs... }"},
1075 {"pcf7931", CmdLFPCF7931
, 1, "{ PCF7931 CHIPs... }"},
1076 {"pyramid", CmdLFPyramid
, 1, "{ Farpointe/Pyramid RFIDs... }"},
1077 {"t55xx", CmdLFT55XX
, 1, "{ T55xx CHIPs... }"},
1078 {"ti", CmdLFTI
, 1, "{ TI CHIPs... }"},
1079 {"viking", CmdLFViking
, 1, "{ Viking RFIDs... }"},
1080 {"visa2000", CmdLFVisa2k
, 1, "{ Visa2000 RFIDs... }"},
1081 {"cmdread", CmdLFCommandRead
, 0, "<d period> <z period> <o period> <c command> ['H'] -- Modulate LF reader field to send command before read (all periods in microseconds) (option 'H' for 134)"},
1082 {"config", CmdLFSetConfig
, 0, "Set config for LF sampling, bit/sample, decimation, frequency"},
1083 {"flexdemod", CmdFlexdemod
, 1, "Demodulate samples for FlexPass"},
1084 {"read", CmdLFRead
, 0, "['s' silent] Read 125/134 kHz LF ID-only tag. Do 'lf read h' for help"},
1085 {"search", CmdLFfind
, 1, "[offline] ['u'] Read and Search for valid known tag (in offline mode it you can load first then search) - 'u' to search for unknown tags"},
1086 {"sim", CmdLFSim
, 0, "[GAP] -- Simulate LF tag from buffer with optional GAP (in microseconds)"},
1087 {"simask", CmdLFaskSim
, 0, "[clock] [invert <1|0>] [biphase/manchester/raw <'b'|'m'|'r'>] [msg separator 's'] [d <hexdata>] -- Simulate LF ASK tag from demodbuffer or input"},
1088 {"simfsk", CmdLFfskSim
, 0, "[c <clock>] [i] [H <fcHigh>] [L <fcLow>] [d <hexdata>] -- Simulate LF FSK tag from demodbuffer or input"},
1089 {"simpsk", CmdLFpskSim
, 0, "[1|2|3] [c <clock>] [i] [r <carrier>] [d <raw hex to sim>] -- Simulate LF PSK tag from demodbuffer or input"},
1090 {"simbidir", CmdLFSimBidir
, 0, "Simulate LF tag (with bidirectional data transmission between reader and tag)"},
1091 {"snoop", CmdLFSnoop
, 0, "['l'|'h'|<divisor>] [trigger threshold]-- Snoop LF (l:125khz, h:134khz)"},
1092 {"vchdemod", CmdVchDemod
, 1, "['clone'] -- Demodulate samples for VeriChip"},
1093 {NULL
, NULL
, 0, NULL
}
1096 int CmdLF(const char *Cmd
)
1098 CmdsParse(CommandTable
, Cmd
);
1102 int CmdHelp(const char *Cmd
)
1104 CmdsHelp(CommandTable
);