]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfem4x.c
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 EM4x commands
9 //-----------------------------------------------------------------------------
14 #include "proxmark3.h"
18 #include "cmdparser.h"
21 #include "cmdlfem4x.h"
24 #define LF_TRACE_BUFF_SIZE 12000
25 #define LF_BITSSTREAM_LEN 1000
27 char *global_em410xId
;
29 static int CmdHelp(const char *Cmd
);
31 int CmdEMdemodASK(const char *Cmd
)
33 char cmdp
= param_getchar(Cmd
, 0);
34 int findone
= (cmdp
== '1') ? 1 : 0;
35 UsbCommand c
= { CMD_EM410X_DEMOD
};
41 /* Read the ID of an EM410x tag.
43 * 1111 1111 1 <-- standard non-repeatable header
44 * XXXX [row parity bit] <-- 10 rows of 5 bits for our 40 bit tag ID
46 * CCCC <-- each bit here is parity for the 10 bits above in corresponding column
47 * 0 <-- stop bit, end of tag
49 int CmdEM410xRead(const char *Cmd
)
51 int i
, j
, clock
, header
, rows
, bit
, hithigh
, hitlow
, first
, bit2idx
, high
, low
;
54 char id2
[11] = {0x00};
56 uint8_t BitStream
[MAX_GRAPH_TRACE_LEN
];
60 clock
= GetClock(Cmd
, 0);
62 // Detect high and lows and clock
63 DetectHighLowInGraph( &high
, &low
, TRUE
);
65 PrintAndLog("NUMNUM");
67 // parity for our 4 columns
68 parity
[0] = parity
[1] = parity
[2] = parity
[3] = 0;
71 // manchester demodulate
73 for (i
= 0; i
< (int)(GraphTraceLen
/ clock
); i
++)
79 /* Find out if we hit both high and low peaks */
80 for (j
= 0; j
< clock
; j
++)
82 if (GraphBuffer
[(i
* clock
) + j
] >= high
)
84 else if (GraphBuffer
[(i
* clock
) + j
] <= low
)
87 /* it doesn't count if it's the first part of our read
88 because it's really just trailing from the last sequence */
89 if (first
&& (hithigh
|| hitlow
))
94 if (hithigh
&& hitlow
)
98 /* If we didn't hit both high and low peaks, we had a bit transition */
99 if (!hithigh
|| !hitlow
)
102 BitStream
[bit2idx
++] = bit
;
106 /* We go till 5 before the graph ends because we'll get that far below */
107 for (i
= 0; i
< bit2idx
- 5; i
++)
109 /* Step 2: We have our header but need our tag ID */
110 if (header
== 9 && rows
< 10)
112 /* Confirm parity is correct */
113 if ((BitStream
[i
] ^ BitStream
[i
+1] ^ BitStream
[i
+2] ^ BitStream
[i
+3]) == BitStream
[i
+4])
115 /* Read another byte! */
116 sprintf(id
+rows
, "%x", (8 * BitStream
[i
]) + (4 * BitStream
[i
+1]) + (2 * BitStream
[i
+2]) + (1 * BitStream
[i
+3]));
117 sprintf(id2
+rows
, "%x", (8 * BitStream
[i
+3]) + (4 * BitStream
[i
+2]) + (2 * BitStream
[i
+1]) + (1 * BitStream
[i
]));
120 /* Keep parity info */
121 parity
[0] ^= BitStream
[i
];
122 parity
[1] ^= BitStream
[i
+1];
123 parity
[2] ^= BitStream
[i
+2];
124 parity
[3] ^= BitStream
[i
+3];
126 /* Move 4 bits ahead */
130 /* Damn, something wrong! reset */
133 PrintAndLog("Thought we had a valid tag but failed at word %d (i=%d)", rows
+ 1, i
);
135 /* Start back rows * 5 + 9 header bits, -1 to not start at same place */
136 i
-= 9 + (5 * rows
) -5;
142 /* Step 3: Got our 40 bits! confirm column parity */
145 /* We need to make sure our 4 bits of parity are correct and we have a stop bit */
146 if (BitStream
[i
] == parity
[0] && BitStream
[i
+1] == parity
[1] &&
147 BitStream
[i
+2] == parity
[2] && BitStream
[i
+3] == parity
[3] &&
151 PrintAndLog("EM410x Tag ID: %s", id
);
152 PrintAndLog("Unique Tag ID: %s", id2
);
154 global_em410xId
= id
;
160 /* Crap! Incorrect parity or no stop bit, start all over */
165 /* Go back 59 bits (9 header bits + 10 rows at 4+1 parity) */
170 /* Step 1: get our header */
173 /* Need 9 consecutive 1's */
174 if (BitStream
[i
] == 1)
177 /* We don't have a header, not enough consecutive 1 bits */
183 /* if we've already retested after flipping bits, return */
185 PrintAndLog("Failed to decode");
189 /* if this didn't work, try flipping bits */
190 for (i
= 0; i
< bit2idx
; i
++)
196 /* emulate an EM410X tag
198 * 1111 1111 1 <-- standard non-repeatable header
199 * XXXX [row parity bit] <-- 10 rows of 5 bits for our 40 bit tag ID
201 * CCCC <-- each bit here is parity for the 10 bits above in corresponding column
202 * 0 <-- stop bit, end of tag
204 int CmdEM410xSim(const char *Cmd
)
206 int i
, n
, j
, binary
[4], parity
[4];
208 char cmdp
= param_getchar(Cmd
, 0);
209 uint8_t uid
[5] = {0x00};
211 if (cmdp
== 'h' || cmdp
== 'H') {
212 PrintAndLog("Usage: lf em4x 410xsim <UID>");
214 PrintAndLog(" sample: lf em4x 410xsim 0F0368568B");
218 if (param_gethex(Cmd
, 0, uid
, 10)) {
219 PrintAndLog("UID must include 10 HEX symbols");
223 PrintAndLog("Starting simulating UID %02X%02X%02X%02X%02X", uid
[0],uid
[1],uid
[2],uid
[3],uid
[4]);
224 PrintAndLog("Press pm3-button to about simulation");
226 /* clock is 64 in EM410x tags */
229 /* clear our graph */
232 /* write 9 start bits */
233 for (i
= 0; i
< 9; i
++)
234 AppendGraph(0, clock
, 1);
236 /* for each hex char */
237 parity
[0] = parity
[1] = parity
[2] = parity
[3] = 0;
238 for (i
= 0; i
< 10; i
++)
240 /* read each hex char */
241 sscanf(&Cmd
[i
], "%1x", &n
);
242 for (j
= 3; j
>= 0; j
--, n
/= 2)
245 /* append each bit */
246 AppendGraph(0, clock
, binary
[0]);
247 AppendGraph(0, clock
, binary
[1]);
248 AppendGraph(0, clock
, binary
[2]);
249 AppendGraph(0, clock
, binary
[3]);
251 /* append parity bit */
252 AppendGraph(0, clock
, binary
[0] ^ binary
[1] ^ binary
[2] ^ binary
[3]);
254 /* keep track of column parity */
255 parity
[0] ^= binary
[0];
256 parity
[1] ^= binary
[1];
257 parity
[2] ^= binary
[2];
258 parity
[3] ^= binary
[3];
262 AppendGraph(0, clock
, parity
[0]);
263 AppendGraph(0, clock
, parity
[1]);
264 AppendGraph(0, clock
, parity
[2]);
265 AppendGraph(0, clock
, parity
[3]);
268 AppendGraph(1, clock
, 0);
270 CmdLFSim("240"); //240 start_gap.
274 /* Function is equivalent of lf read + data samples + em410xread
275 * looped until an EM410x tag is detected
277 * Why is CmdSamples("16000")?
278 * TBD: Auto-grow sample size based on detected sample rate. IE: If the
279 * rate gets lower, then grow the number of samples
280 * Changed by martin, 4000 x 4 = 16000,
281 * see http://www.proxmark.org/forum/viewtopic.php?pid=7235#p7235
284 int CmdEM410xWatch(const char *Cmd
)
286 char cmdp
= param_getchar(Cmd
, 0);
287 int read_h
= (cmdp
== 'h');
290 printf("\naborted via keyboard!\n");
294 CmdLFRead(read_h
? "h" : "");
302 int CmdEM410xWatchnSpoof(const char *Cmd
)
305 PrintAndLog("# Replaying : %s",global_em410xId
);
306 CmdEM410xSim(global_em410xId
);
310 /* Read the transmitted data of an EM4x50 tag
313 * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity
314 * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity
315 * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity
316 * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity
317 * CCCCCCCC <- column parity bits
319 * LW <- Listen Window
321 * This pattern repeats for every block of data being transmitted.
322 * Transmission starts with two Listen Windows (LW - a modulated
323 * pattern of 320 cycles each (32/32/128/64/64)).
325 * Note that this data may or may not be the UID. It is whatever data
326 * is stored in the blocks defined in the control word First and Last
327 * Word Read values. UID is stored in block 32.
329 int CmdEM4x50Read(const char *Cmd
)
331 int i
, j
, startblock
, skip
, block
, start
, end
, low
, high
;
332 bool complete
= false;
333 int tmpbuff
[MAX_GRAPH_TRACE_LEN
/ 64];
337 memset(tmpbuff
, 0, MAX_GRAPH_TRACE_LEN
/ 64);
339 /* first get high and low values */
340 for (i
= 0; i
< GraphTraceLen
; i
++)
342 if (GraphBuffer
[i
] > high
)
343 high
= GraphBuffer
[i
];
344 else if (GraphBuffer
[i
] < low
)
345 low
= GraphBuffer
[i
];
348 /* populate a buffer with pulse lengths */
351 while (i
< GraphTraceLen
)
353 // measure from low to low
354 while ((GraphBuffer
[i
] > low
) && (i
<GraphTraceLen
))
357 while ((GraphBuffer
[i
] < high
) && (i
<GraphTraceLen
))
359 while ((GraphBuffer
[i
] > low
) && (i
<GraphTraceLen
))
361 if (j
>=(MAX_GRAPH_TRACE_LEN
/64)) {
364 tmpbuff
[j
++]= i
- start
;
367 /* look for data start - should be 2 pairs of LW (pulses of 192,128) */
370 for (i
= 0; i
< j
- 4 ; ++i
)
373 if (tmpbuff
[i
] >= 190 && tmpbuff
[i
] <= 194)
374 if (tmpbuff
[i
+1] >= 126 && tmpbuff
[i
+1] <= 130)
375 if (tmpbuff
[i
+2] >= 190 && tmpbuff
[i
+2] <= 194)
376 if (tmpbuff
[i
+3] >= 126 && tmpbuff
[i
+3] <= 130)
384 /* skip over the remainder of the LW */
385 skip
+= tmpbuff
[i
+1]+tmpbuff
[i
+2];
386 while (skip
< MAX_GRAPH_TRACE_LEN
&& GraphBuffer
[skip
] > low
)
390 /* now do it again to find the end */
392 for (i
+= 3; i
< j
- 4 ; ++i
)
395 if (tmpbuff
[i
] >= 190 && tmpbuff
[i
] <= 194)
396 if (tmpbuff
[i
+1] >= 126 && tmpbuff
[i
+1] <= 130)
397 if (tmpbuff
[i
+2] >= 190 && tmpbuff
[i
+2] <= 194)
398 if (tmpbuff
[i
+3] >= 126 && tmpbuff
[i
+3] <= 130)
406 PrintAndLog("Found data at sample: %i",skip
);
409 PrintAndLog("No data found!");
410 PrintAndLog("Try again with more samples.");
416 PrintAndLog("*** Warning!");
417 PrintAndLog("Partial data - no end found!");
418 PrintAndLog("Try again with more samples.");
421 /* get rid of leading crap */
422 sprintf(tmp
,"%i",skip
);
425 /* now work through remaining buffer printing out data blocks */
430 PrintAndLog("Block %i:", block
);
431 // mandemod routine needs to be split so we can call it for data
432 // just print for now for debugging
433 CmdManchesterDemod("i 64");
435 /* look for LW before start of next block */
436 for ( ; i
< j
- 4 ; ++i
)
439 if (tmpbuff
[i
] >= 190 && tmpbuff
[i
] <= 194)
440 if (tmpbuff
[i
+1] >= 126 && tmpbuff
[i
+1] <= 130)
443 while (GraphBuffer
[skip
] > low
)
446 sprintf(tmp
,"%i",skip
);
454 int CmdEM410xWrite(const char *Cmd
)
456 uint64_t id
= 0xFFFFFFFFFFFFFFFF; // invalid id value
457 int card
= 0xFF; // invalid card value
458 unsigned int clock
= 0; // invalid clock value
460 sscanf(Cmd
, "%" PRIx64
" %d %d", &id
, &card
, &clock
);
463 if (id
== 0xFFFFFFFFFFFFFFFF) {
464 PrintAndLog("Error! ID is required.\n");
467 if (id
>= 0x10000000000) {
468 PrintAndLog("Error! Given EM410x ID is longer than 40 bits.\n");
474 PrintAndLog("Error! Card type required.\n");
478 PrintAndLog("Error! Bad card type selected.\n");
489 // Allowed clock rates: 16, 32 and 64
490 if ((clock
!= 16) && (clock
!= 32) && (clock
!= 64)) {
491 PrintAndLog("Error! Clock rate %d not valid. Supported clock rates are 16, 32 and 64.\n", clock
);
497 PrintAndLog("Error! Clock rate is only supported on T55x7 tags.\n");
502 PrintAndLog("Writing %s tag with UID 0x%010" PRIx64
" (clock rate: %d)", "T55x7", id
, clock
);
503 // NOTE: We really should pass the clock in as a separate argument, but to
504 // provide for backwards-compatibility for older firmware, and to avoid
505 // having to add another argument to CMD_EM410X_WRITE_TAG, we just store
506 // the clock rate in bits 8-15 of the card value
507 card
= (card
& 0xFF) | (((uint64_t)clock
<< 8) & 0xFF00);
510 PrintAndLog("Writing %s tag with UID 0x%010" PRIx64
, "T5555", id
, clock
);
512 PrintAndLog("Error! Bad card type selected.\n");
516 UsbCommand c
= {CMD_EM410X_WRITE_TAG
, {card
, (uint32_t)(id
>> 32), (uint32_t)id
}};
522 int CmdReadWord(const char *Cmd
)
524 int Word
= -1; //default to invalid word
527 sscanf(Cmd
, "%d", &Word
);
529 if ( (Word
> 15) | (Word
< 0) ) {
530 PrintAndLog("Word must be between 0 and 15");
534 PrintAndLog("Reading word %d", Word
);
536 c
.cmd
= CMD_EM4X_READ_WORD
;
537 c
.d
.asBytes
[0] = 0x0; //Normal mode
542 WaitForResponse(CMD_ACK
, NULL
);
544 uint8_t data
[LF_TRACE_BUFF_SIZE
] = {0x00};
546 GetFromBigBuf(data
,LF_TRACE_BUFF_SIZE
,0); //3560 -- should be offset..
547 WaitForResponseTimeout(CMD_ACK
,NULL
, 1500);
549 for (int j
= 0; j
< LF_TRACE_BUFF_SIZE
; j
++) {
550 GraphBuffer
[j
] = ((int)data
[j
]);
552 GraphTraceLen
= LF_TRACE_BUFF_SIZE
;
554 uint8_t bits
[LF_BITSSTREAM_LEN
] = {0x00};
555 uint8_t * bitstream
= bits
;
556 manchester_decode(GraphBuffer
, LF_TRACE_BUFF_SIZE
, bitstream
,LF_BITSSTREAM_LEN
);
557 RepaintGraphWindow();
561 int CmdReadWordPWD(const char *Cmd
)
563 int Word
= -1; //default to invalid word
564 int Password
= 0xFFFFFFFF; //default to blank password
567 sscanf(Cmd
, "%d %x", &Word
, &Password
);
569 if ( (Word
> 15) | (Word
< 0) ) {
570 PrintAndLog("Word must be between 0 and 15");
574 PrintAndLog("Reading word %d with password %08X", Word
, Password
);
576 c
.cmd
= CMD_EM4X_READ_WORD
;
577 c
.d
.asBytes
[0] = 0x1; //Password mode
582 WaitForResponse(CMD_ACK
, NULL
);
584 uint8_t data
[LF_TRACE_BUFF_SIZE
] = {0x00};
586 GetFromBigBuf(data
,LF_TRACE_BUFF_SIZE
,0); //3560 -- should be offset..
587 WaitForResponseTimeout(CMD_ACK
,NULL
, 1500);
589 for (int j
= 0; j
< LF_TRACE_BUFF_SIZE
; j
++) {
590 GraphBuffer
[j
] = ((int)data
[j
]);
592 GraphTraceLen
= LF_TRACE_BUFF_SIZE
;
594 uint8_t bits
[LF_BITSSTREAM_LEN
] = {0x00};
595 uint8_t * bitstream
= bits
;
596 manchester_decode(GraphBuffer
, LF_TRACE_BUFF_SIZE
, bitstream
, LF_BITSSTREAM_LEN
);
597 RepaintGraphWindow();
601 int CmdWriteWord(const char *Cmd
)
603 int Word
= 16; //default to invalid block
604 int Data
= 0xFFFFFFFF; //default to blank data
607 sscanf(Cmd
, "%x %d", &Data
, &Word
);
610 PrintAndLog("Word must be between 0 and 15");
614 PrintAndLog("Writing word %d with data %08X", Word
, Data
);
616 c
.cmd
= CMD_EM4X_WRITE_WORD
;
617 c
.d
.asBytes
[0] = 0x0; //Normal mode
625 int CmdWriteWordPWD(const char *Cmd
)
627 int Word
= 16; //default to invalid word
628 int Data
= 0xFFFFFFFF; //default to blank data
629 int Password
= 0xFFFFFFFF; //default to blank password
632 sscanf(Cmd
, "%x %d %x", &Data
, &Word
, &Password
);
635 PrintAndLog("Word must be between 0 and 15");
639 PrintAndLog("Writing word %d with data %08X and password %08X", Word
, Data
, Password
);
641 c
.cmd
= CMD_EM4X_WRITE_WORD
;
642 c
.d
.asBytes
[0] = 0x1; //Password mode
650 static command_t CommandTable
[] =
652 {"help", CmdHelp
, 1, "This help"},
653 {"410xdemod", CmdEMdemodASK
, 0, "[clock rate] -- Extract ID from EM410x tag"},
654 {"410xread", CmdEM410xRead
, 1, "[clock rate] -- Extract ID from EM410x tag"},
655 {"410xsim", CmdEM410xSim
, 0, "<UID> -- Simulate EM410x tag"},
656 {"replay", MWRem4xReplay
, 0, "Watches for tag and simulates manchester encoded em4x tag"},
657 {"410xwatch", CmdEM410xWatch
, 0, "['h'] -- Watches for EM410x 125/134 kHz tags (option 'h' for 134)"},
658 {"410xspoof", CmdEM410xWatchnSpoof
, 0, "['h'] --- Watches for EM410x 125/134 kHz tags, and replays them. (option 'h' for 134)" },
659 {"410xwrite", CmdEM410xWrite
, 1, "<UID> <'0' T5555> <'1' T55x7> [clock rate] -- Write EM410x UID to T5555(Q5) or T55x7 tag, optionally setting clock rate"},
660 {"4x50read", CmdEM4x50Read
, 1, "Extract data from EM4x50 tag"},
661 {"rd", CmdReadWord
, 1, "<Word 1-15> -- Read EM4xxx word data"},
662 {"rdpwd", CmdReadWordPWD
, 1, "<Word 1-15> <Password> -- Read EM4xxx word data in password mode "},
663 {"wr", CmdWriteWord
, 1, "<Data> <Word 1-15> -- Write EM4xxx word data"},
664 {"wrpwd", CmdWriteWordPWD
, 1, "<Data> <Word 1-15> <Password> -- Write EM4xxx word data in password mode"},
665 {NULL
, NULL
, 0, NULL
}
669 //Confirms the parity of a bitstream as well as obtaining the data (TagID) from within the appropriate memory space.
671 // Pointer to a string containing the desired bitsream
672 // Pointer to a string that will receive the decoded tag ID
673 // Length of the bitsream pointed at in the first argument, char* _strBitStream
676 //0 Parity not confirmed
677 int ConfirmEm410xTagParity( char* _strBitStream
, char* pID
, int LengthOfBitstream
)
681 int Parity
[4] = {0x00};
682 char ID
[11] = {0x00};
684 int BitStream
[70] = {0x00};
687 for ( i
= 0; i
<= LengthOfBitstream
; i
++)
689 if (_strBitStream
[i
] == '1')
692 memcpy(&BitStream
[i
], &k
,4);
694 else if (_strBitStream
[i
] == '0')
697 memcpy(&BitStream
[i
], &k
,4);
700 while ( counter
< 2 )
702 //set/reset variables and counters
703 memset(ID
,0x00,sizeof(ID
));
704 memset(Parity
,0x00,sizeof(Parity
));
706 for ( i
= 9; i
<= LengthOfBitstream
; i
++)
710 if ((BitStream
[i
] ^ BitStream
[i
+1] ^ BitStream
[i
+2] ^ BitStream
[i
+3]) == BitStream
[i
+4])
712 sprintf(ID
+rows
, "%x", (8 * BitStream
[i
]) + (4 * BitStream
[i
+1]) + (2 * BitStream
[i
+2]) + (1 * BitStream
[i
+3]));
714 /* Keep parity info and move four bits ahead*/
715 Parity
[0] ^= BitStream
[i
];
716 Parity
[1] ^= BitStream
[i
+1];
717 Parity
[2] ^= BitStream
[i
+2];
718 Parity
[3] ^= BitStream
[i
+3];
724 if ( BitStream
[i
] == Parity
[0] && BitStream
[i
+1] == Parity
[1] &&
725 BitStream
[i
+2] == Parity
[2] && BitStream
[i
+3] == Parity
[3] &&
728 memcpy(pID
,ID
,strlen(ID
));
733 printf("[PARITY ->]Failed. Flipping Bits, and rechecking parity for bitstream:\n[PARITY ->]");
734 for (k
= 0; k
< LengthOfBitstream
; k
++)
737 printf("%i", BitStream
[k
]);
744 //Reads and demodulates an em410x RFID tag. It further allows slight modification to the decoded bitstream
745 //Once a suitable bitstream has been identified, and if needed, modified, it is replayed. Allowing emulation of the
747 //No meaningful returns or arguments.
748 int MWRem4xReplay(const char* Cmd
)
751 // static char ArrayTraceZero[] = { '0','0','0','0','0','0','0','0','0' };
752 // static char ArrayTraceOne[] = { '1','1','1','1','1','1','1','1','1' };
753 // //local string variables
754 // char strClockRate[10] = {0x00};
755 // char strAnswer[4] = {0x00};
756 // char strTempBufferMini[2] = {0x00};
757 // //our outbound bit-stream
758 // char strSimulateBitStream[65] = {0x00};
760 // int iClockRate = 0;
763 // int iFirstHeaderOffset = 0x00000000;
764 // int numManchesterDemodBits=0;
766 // bool bInverted = false;
767 // //pointers to strings. memory will be allocated.
768 // char* pstrInvertBitStream = 0x00000000;
769 // char* pTempBuffer = 0x00000000;
770 // char* pID = 0x00000000;
771 // char* strBitStreamBuffer = 0x00000000;
774 // puts("###################################");
775 // puts("#### Em4x Replay ##");
776 // puts("#### R.A.M. June 2013 ##");
777 // puts("###################################");
780 // //Collect ourselves 10,000 samples
781 // CmdSamples("10000");
782 // puts("[->]preforming ASK demodulation\n");
785 // iClockRate = DetectClock(0);
786 // sprintf(strClockRate, "%i\n",iClockRate);
787 // printf("[->]Detected ClockRate: %s\n", strClockRate);
789 // //If detected clock rate is something completely unreasonable, dont go ahead
790 // if ( iClockRate < 0xFFFE )
792 // pTempBuffer = (char*)malloc(MAX_GRAPH_TRACE_LEN);
793 // if (pTempBuffer == 0x00000000)
795 // memset(pTempBuffer,0x00,MAX_GRAPH_TRACE_LEN);
796 // //Preform manchester de-modulation and display in a single line.
797 // numManchesterDemodBits = CmdManchesterDemod( strClockRate );
798 // //note: numManchesterDemodBits is set above in CmdManchesterDemod()
799 // if ( numManchesterDemodBits == 0 )
801 // strBitStreamBuffer = malloc(numManchesterDemodBits+1);
802 // if ( strBitStreamBuffer == 0x00000000 )
804 // memset(strBitStreamBuffer, 0x00, (numManchesterDemodBits+1));
805 // //fill strBitStreamBuffer with demodulated, string formatted bits.
806 // for ( j = 0; j <= numManchesterDemodBits; j++ )
808 // sprintf(strTempBufferMini, "%i",BitStream[j]);
809 // strcat(strBitStreamBuffer,strTempBufferMini);
811 // printf("[->]Demodulated Bitstream: \n%s\n", strBitStreamBuffer);
812 // //Reset counter and select most probable bit stream
814 // while ( j < numManchesterDemodBits )
816 // memset(strSimulateBitStream,0x00,64);
817 // //search for header of nine (9) 0's : 000000000 or nine (9) 1's : 1111 1111 1
818 // if ( ( strncmp(strBitStreamBuffer+j, ArrayTraceZero, sizeof(ArrayTraceZero)) == 0 ) ||
819 // ( strncmp(strBitStreamBuffer+j, ArrayTraceOne, sizeof(ArrayTraceOne)) == 0 ) )
821 // iFirstHeaderOffset = j;
822 // memcpy(strSimulateBitStream, strBitStreamBuffer+j,64);
823 // printf("[->]Offset of Header");
824 // if ( strncmp(strBitStreamBuffer+iFirstHeaderOffset, "0", 1) == 0 )
825 // printf("'%s'", ArrayTraceZero );
827 // printf("'%s'", ArrayTraceOne );
828 // printf(": %i\nHighlighted string : %s\n",iFirstHeaderOffset,strSimulateBitStream);
829 // //allow us to escape loop or choose another frame
830 // puts("[<-]Are we happy with this sample? [Y]es/[N]o");
832 // if ( ( strncmp(strAnswer,"y",1) == 0 ) || ( strncmp(strAnswer,"Y",1) == 0 ) )
834 // j = numManchesterDemodBits+1;
843 // //Do we want the buffer inverted?
844 // memset(strAnswer, 0x00, sizeof(strAnswer));
845 // printf("[<-]Do you wish to invert the highlighted bitstream? [Y]es/[N]o\n");
847 // if ( ( strncmp("y", strAnswer,1) == 0 ) || ( strncmp("Y", strAnswer, 1 ) == 0 ) )
849 // //allocate heap memory
850 // pstrInvertBitStream = (char*)malloc(numManchesterDemodBits);
851 // if ( pstrInvertBitStream != 0x00000000 )
853 // memset(pstrInvertBitStream,0x00,numManchesterDemodBits);
855 // //Invert Bitstream
856 // for ( needle = 0; needle <= numManchesterDemodBits; needle++ )
858 // if (strSimulateBitStream[needle] == '0')
859 // strcat(pstrInvertBitStream,"1");
860 // else if (strSimulateBitStream[needle] == '1')
861 // strcat(pstrInvertBitStream,"0");
863 // printf("[->]Inverted bitstream: %s\n", pstrInvertBitStream);
866 // //Confirm parity of selected string
867 // pID = (char*)malloc(11);
868 // if (pID != 0x00000000)
870 // memset(pID, 0x00, 11);
871 // if (ConfirmEm410xTagParity(strSimulateBitStream,pID, 64) == 1)
873 // printf("[->]Parity confirmed for selected bitstream!\n");
874 // printf("[->]Tag ID was detected as: [hex]:%s\n",pID );
877 // printf("[->]Parity check failed for the selected bitstream!\n");
881 // memset(strAnswer, 0x00, sizeof(strAnswer));
882 // printf("[<-]Do you wish to continue with the EM4x simulation? [Y]es/[N]o\n");
884 // if ( ( strncmp(strAnswer,"y",1) == 0 ) || ( strncmp(strAnswer,"Y",1) == 0 ) )
886 // strcat(pTempBuffer, strClockRate);
887 // strcat(pTempBuffer, " ");
888 // if (bInverted == true)
889 // strcat(pTempBuffer,pstrInvertBitStream);
890 // if (bInverted == false)
891 // strcat(pTempBuffer,strSimulateBitStream);
893 // puts("[->]Starting simulation now: \n");
894 // //Simulate tag with prepared buffer.
895 // CmdLFSimManchester(pTempBuffer);
897 // else if ( ( strcmp("n", strAnswer) == 0 ) || ( strcmp("N", strAnswer ) == 0 ) )
898 // printf("[->]Exiting procedure now...\n");
900 // printf("[->]Erroneous selection\nExiting procedure now....\n");
902 // //Clean up -- Exit function
903 // //clear memory, then release pointer.
904 // if ( pstrInvertBitStream != 0x00000000 )
906 // memset(pstrInvertBitStream,0x00,numManchesterDemodBits);
907 // free(pstrInvertBitStream);
909 // if ( pTempBuffer != 0x00000000 )
911 // memset(pTempBuffer,0x00,MAX_GRAPH_TRACE_LEN);
912 // free(pTempBuffer);
914 // if ( pID != 0x00000000 )
916 // memset(pID,0x00,11);
919 // if ( strBitStreamBuffer != 0x00000000 )
921 // memset(strBitStreamBuffer,0x00,numManchesterDemodBits);
922 // free(strBitStreamBuffer);
927 int CmdLFEM4X(const char *Cmd
)
929 CmdsParse(CommandTable
, Cmd
);
933 int CmdHelp(const char *Cmd
)
935 CmdsHelp(CommandTable
);