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