]>
git.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');
291 printf("\naborted via keyboard!\n");
295 CmdLFRead(read_h
? "h" : "");
304 int CmdEM410xWatchnSpoof(const char *Cmd
)
307 PrintAndLog("# Replaying : %s",global_em410xId
);
308 CmdEM410xSim(global_em410xId
);
312 /* Read the transmitted data of an EM4x50 tag
315 * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity
316 * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity
317 * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity
318 * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity
319 * CCCCCCCC <- column parity bits
321 * LW <- Listen Window
323 * This pattern repeats for every block of data being transmitted.
324 * Transmission starts with two Listen Windows (LW - a modulated
325 * pattern of 320 cycles each (32/32/128/64/64)).
327 * Note that this data may or may not be the UID. It is whatever data
328 * is stored in the blocks defined in the control word First and Last
329 * Word Read values. UID is stored in block 32.
331 int CmdEM4x50Read(const char *Cmd
)
333 int i
, j
, startblock
, skip
, block
, start
, end
, low
, high
;
334 bool complete
= false;
335 int tmpbuff
[MAX_GRAPH_TRACE_LEN
/ 64];
339 memset(tmpbuff
, 0, MAX_GRAPH_TRACE_LEN
/ 64);
341 /* first get high and low values */
342 for (i
= 0; i
< GraphTraceLen
; i
++)
344 if (GraphBuffer
[i
] > high
)
345 high
= GraphBuffer
[i
];
346 else if (GraphBuffer
[i
] < low
)
347 low
= GraphBuffer
[i
];
350 /* populate a buffer with pulse lengths */
353 while (i
< GraphTraceLen
)
355 // measure from low to low
356 while ((GraphBuffer
[i
] > low
) && (i
<GraphTraceLen
))
359 while ((GraphBuffer
[i
] < high
) && (i
<GraphTraceLen
))
361 while ((GraphBuffer
[i
] > low
) && (i
<GraphTraceLen
))
363 if (j
>=(MAX_GRAPH_TRACE_LEN
/64)) {
366 tmpbuff
[j
++]= i
- start
;
369 /* look for data start - should be 2 pairs of LW (pulses of 192,128) */
372 for (i
= 0; i
< j
- 4 ; ++i
)
375 if (tmpbuff
[i
] >= 190 && tmpbuff
[i
] <= 194)
376 if (tmpbuff
[i
+1] >= 126 && tmpbuff
[i
+1] <= 130)
377 if (tmpbuff
[i
+2] >= 190 && tmpbuff
[i
+2] <= 194)
378 if (tmpbuff
[i
+3] >= 126 && tmpbuff
[i
+3] <= 130)
386 /* skip over the remainder of the LW */
387 skip
+= tmpbuff
[i
+1]+tmpbuff
[i
+2];
388 while (skip
< MAX_GRAPH_TRACE_LEN
&& GraphBuffer
[skip
] > low
)
392 /* now do it again to find the end */
394 for (i
+= 3; i
< j
- 4 ; ++i
)
397 if (tmpbuff
[i
] >= 190 && tmpbuff
[i
] <= 194)
398 if (tmpbuff
[i
+1] >= 126 && tmpbuff
[i
+1] <= 130)
399 if (tmpbuff
[i
+2] >= 190 && tmpbuff
[i
+2] <= 194)
400 if (tmpbuff
[i
+3] >= 126 && tmpbuff
[i
+3] <= 130)
408 PrintAndLog("Found data at sample: %i",skip
);
411 PrintAndLog("No data found!");
412 PrintAndLog("Try again with more samples.");
418 PrintAndLog("*** Warning!");
419 PrintAndLog("Partial data - no end found!");
420 PrintAndLog("Try again with more samples.");
423 /* get rid of leading crap */
424 sprintf(tmp
,"%i",skip
);
427 /* now work through remaining buffer printing out data blocks */
432 PrintAndLog("Block %i:", block
);
433 // mandemod routine needs to be split so we can call it for data
434 // just print for now for debugging
435 CmdManchesterDemod("i 64");
437 /* look for LW before start of next block */
438 for ( ; i
< j
- 4 ; ++i
)
441 if (tmpbuff
[i
] >= 190 && tmpbuff
[i
] <= 194)
442 if (tmpbuff
[i
+1] >= 126 && tmpbuff
[i
+1] <= 130)
445 while (GraphBuffer
[skip
] > low
)
448 sprintf(tmp
,"%i",skip
);
456 int CmdEM410xWrite(const char *Cmd
)
458 uint64_t id
= 0xFFFFFFFFFFFFFFFF; // invalid id value
459 int card
= 0xFF; // invalid card value
460 unsigned int clock
= 0; // invalid clock value
462 sscanf(Cmd
, "%" PRIx64
" %d %d", &id
, &card
, &clock
);
465 if (id
== 0xFFFFFFFFFFFFFFFF) {
466 PrintAndLog("Error! ID is required.\n");
469 if (id
>= 0x10000000000) {
470 PrintAndLog("Error! Given EM410x ID is longer than 40 bits.\n");
476 PrintAndLog("Error! Card type required.\n");
480 PrintAndLog("Error! Bad card type selected.\n");
491 // Allowed clock rates: 16, 32 and 64
492 if ((clock
!= 16) && (clock
!= 32) && (clock
!= 64)) {
493 PrintAndLog("Error! Clock rate %d not valid. Supported clock rates are 16, 32 and 64.\n", clock
);
499 PrintAndLog("Error! Clock rate is only supported on T55x7 tags.\n");
504 PrintAndLog("Writing %s tag with UID 0x%010" PRIx64
" (clock rate: %d)", "T55x7", id
, clock
);
505 // NOTE: We really should pass the clock in as a separate argument, but to
506 // provide for backwards-compatibility for older firmware, and to avoid
507 // having to add another argument to CMD_EM410X_WRITE_TAG, we just store
508 // the clock rate in bits 8-15 of the card value
509 card
= (card
& 0xFF) | (((uint64_t)clock
<< 8) & 0xFF00);
512 PrintAndLog("Writing %s tag with UID 0x%010" PRIx64
, "T5555", id
, clock
);
514 PrintAndLog("Error! Bad card type selected.\n");
518 UsbCommand c
= {CMD_EM410X_WRITE_TAG
, {card
, (uint32_t)(id
>> 32), (uint32_t)id
}};
524 int CmdReadWord(const char *Cmd
)
526 int Word
= -1; //default to invalid word
529 sscanf(Cmd
, "%d", &Word
);
531 if ( (Word
> 15) | (Word
< 0) ) {
532 PrintAndLog("Word must be between 0 and 15");
536 PrintAndLog("Reading word %d", Word
);
538 c
.cmd
= CMD_EM4X_READ_WORD
;
539 c
.d
.asBytes
[0] = 0x0; //Normal mode
544 WaitForResponse(CMD_ACK
, NULL
);
546 uint8_t data
[LF_TRACE_BUFF_SIZE
] = {0x00};
548 GetFromBigBuf(data
,LF_TRACE_BUFF_SIZE
,0); //3560 -- should be offset..
549 WaitForResponseTimeout(CMD_ACK
,NULL
, 1500);
551 for (int j
= 0; j
< LF_TRACE_BUFF_SIZE
; j
++) {
552 GraphBuffer
[j
] = ((int)data
[j
]);
554 GraphTraceLen
= LF_TRACE_BUFF_SIZE
;
556 uint8_t bits
[LF_BITSSTREAM_LEN
] = {0x00};
557 uint8_t * bitstream
= bits
;
558 manchester_decode(GraphBuffer
, LF_TRACE_BUFF_SIZE
, bitstream
,LF_BITSSTREAM_LEN
);
559 RepaintGraphWindow();
563 int CmdReadWordPWD(const char *Cmd
)
565 int Word
= -1; //default to invalid word
566 int Password
= 0xFFFFFFFF; //default to blank password
569 sscanf(Cmd
, "%d %x", &Word
, &Password
);
571 if ( (Word
> 15) | (Word
< 0) ) {
572 PrintAndLog("Word must be between 0 and 15");
576 PrintAndLog("Reading word %d with password %08X", Word
, Password
);
578 c
.cmd
= CMD_EM4X_READ_WORD
;
579 c
.d
.asBytes
[0] = 0x1; //Password mode
584 WaitForResponse(CMD_ACK
, NULL
);
586 uint8_t data
[LF_TRACE_BUFF_SIZE
] = {0x00};
588 GetFromBigBuf(data
,LF_TRACE_BUFF_SIZE
,0); //3560 -- should be offset..
589 WaitForResponseTimeout(CMD_ACK
,NULL
, 1500);
591 for (int j
= 0; j
< LF_TRACE_BUFF_SIZE
; j
++) {
592 GraphBuffer
[j
] = ((int)data
[j
]);
594 GraphTraceLen
= LF_TRACE_BUFF_SIZE
;
596 uint8_t bits
[LF_BITSSTREAM_LEN
] = {0x00};
597 uint8_t * bitstream
= bits
;
598 manchester_decode(GraphBuffer
, LF_TRACE_BUFF_SIZE
, bitstream
, LF_BITSSTREAM_LEN
);
599 RepaintGraphWindow();
603 int CmdWriteWord(const char *Cmd
)
605 int Word
= 16; //default to invalid block
606 int Data
= 0xFFFFFFFF; //default to blank data
609 sscanf(Cmd
, "%x %d", &Data
, &Word
);
612 PrintAndLog("Word must be between 0 and 15");
616 PrintAndLog("Writing word %d with data %08X", Word
, Data
);
618 c
.cmd
= CMD_EM4X_WRITE_WORD
;
619 c
.d
.asBytes
[0] = 0x0; //Normal mode
627 int CmdWriteWordPWD(const char *Cmd
)
629 int Word
= 16; //default to invalid word
630 int Data
= 0xFFFFFFFF; //default to blank data
631 int Password
= 0xFFFFFFFF; //default to blank password
634 sscanf(Cmd
, "%x %d %x", &Data
, &Word
, &Password
);
637 PrintAndLog("Word must be between 0 and 15");
641 PrintAndLog("Writing word %d with data %08X and password %08X", Word
, Data
, Password
);
643 c
.cmd
= CMD_EM4X_WRITE_WORD
;
644 c
.d
.asBytes
[0] = 0x1; //Password mode
652 static command_t CommandTable
[] =
654 {"help", CmdHelp
, 1, "This help"},
655 {"410xdemod", CmdEMdemodASK
, 0, "[clock rate] -- Extract ID from EM410x tag"},
656 {"410xread", CmdEM410xRead
, 1, "[clock rate] -- Extract ID from EM410x tag"},
657 {"410xsim", CmdEM410xSim
, 0, "<UID> -- Simulate EM410x tag"},
658 {"replay", MWRem4xReplay
, 0, "Watches for tag and simulates manchester encoded em4x tag"},
659 {"410xwatch", CmdEM410xWatch
, 0, "['h'] -- Watches for EM410x 125/134 kHz tags (option 'h' for 134)"},
660 {"410xspoof", CmdEM410xWatchnSpoof
, 0, "['h'] --- Watches for EM410x 125/134 kHz tags, and replays them. (option 'h' for 134)" },
661 {"410xwrite", CmdEM410xWrite
, 1, "<UID> <'0' T5555> <'1' T55x7> [clock rate] -- Write EM410x UID to T5555(Q5) or T55x7 tag, optionally setting clock rate"},
662 {"4x50read", CmdEM4x50Read
, 1, "Extract data from EM4x50 tag"},
663 {"rd", CmdReadWord
, 1, "<Word 1-15> -- Read EM4xxx word data"},
664 {"rdpwd", CmdReadWordPWD
, 1, "<Word 1-15> <Password> -- Read EM4xxx word data in password mode "},
665 {"wr", CmdWriteWord
, 1, "<Data> <Word 1-15> -- Write EM4xxx word data"},
666 {"wrpwd", CmdWriteWordPWD
, 1, "<Data> <Word 1-15> <Password> -- Write EM4xxx word data in password mode"},
667 {NULL
, NULL
, 0, NULL
}
671 //Confirms the parity of a bitstream as well as obtaining the data (TagID) from within the appropriate memory space.
673 // Pointer to a string containing the desired bitsream
674 // Pointer to a string that will receive the decoded tag ID
675 // Length of the bitsream pointed at in the first argument, char* _strBitStream
678 //0 Parity not confirmed
679 int ConfirmEm410xTagParity( char* _strBitStream
, char* pID
, int LengthOfBitstream
)
683 int Parity
[4] = {0x00};
684 char ID
[11] = {0x00};
686 int BitStream
[70] = {0x00};
689 for ( i
= 0; i
<= LengthOfBitstream
; i
++)
691 if (_strBitStream
[i
] == '1')
694 memcpy(&BitStream
[i
], &k
,4);
696 else if (_strBitStream
[i
] == '0')
699 memcpy(&BitStream
[i
], &k
,4);
702 while ( counter
< 2 )
704 //set/reset variables and counters
705 memset(ID
,0x00,sizeof(ID
));
706 memset(Parity
,0x00,sizeof(Parity
));
708 for ( i
= 9; i
<= LengthOfBitstream
; i
++)
712 if ((BitStream
[i
] ^ BitStream
[i
+1] ^ BitStream
[i
+2] ^ BitStream
[i
+3]) == BitStream
[i
+4])
714 sprintf(ID
+rows
, "%x", (8 * BitStream
[i
]) + (4 * BitStream
[i
+1]) + (2 * BitStream
[i
+2]) + (1 * BitStream
[i
+3]));
716 /* Keep parity info and move four bits ahead*/
717 Parity
[0] ^= BitStream
[i
];
718 Parity
[1] ^= BitStream
[i
+1];
719 Parity
[2] ^= BitStream
[i
+2];
720 Parity
[3] ^= BitStream
[i
+3];
726 if ( BitStream
[i
] == Parity
[0] && BitStream
[i
+1] == Parity
[1] &&
727 BitStream
[i
+2] == Parity
[2] && BitStream
[i
+3] == Parity
[3] &&
730 memcpy(pID
,ID
,strlen(ID
));
735 printf("[PARITY ->]Failed. Flipping Bits, and rechecking parity for bitstream:\n[PARITY ->]");
736 for (k
= 0; k
< LengthOfBitstream
; k
++)
739 printf("%i", BitStream
[k
]);
746 //Reads and demodulates an em410x RFID tag. It further allows slight modification to the decoded bitstream
747 //Once a suitable bitstream has been identified, and if needed, modified, it is replayed. Allowing emulation of the
749 //No meaningful returns or arguments.
750 int MWRem4xReplay(const char* Cmd
)
753 // static char ArrayTraceZero[] = { '0','0','0','0','0','0','0','0','0' };
754 // static char ArrayTraceOne[] = { '1','1','1','1','1','1','1','1','1' };
755 // //local string variables
756 // char strClockRate[10] = {0x00};
757 // char strAnswer[4] = {0x00};
758 // char strTempBufferMini[2] = {0x00};
759 // //our outbound bit-stream
760 // char strSimulateBitStream[65] = {0x00};
762 // int iClockRate = 0;
765 // int iFirstHeaderOffset = 0x00000000;
766 // int numManchesterDemodBits=0;
768 // bool bInverted = false;
769 // //pointers to strings. memory will be allocated.
770 // char* pstrInvertBitStream = 0x00000000;
771 // char* pTempBuffer = 0x00000000;
772 // char* pID = 0x00000000;
773 // char* strBitStreamBuffer = 0x00000000;
776 // puts("###################################");
777 // puts("#### Em4x Replay ##");
778 // puts("#### R.A.M. June 2013 ##");
779 // puts("###################################");
782 // //Collect ourselves 10,000 samples
783 // CmdSamples("10000");
784 // puts("[->]preforming ASK demodulation\n");
787 // iClockRate = DetectClock(0);
788 // sprintf(strClockRate, "%i\n",iClockRate);
789 // printf("[->]Detected ClockRate: %s\n", strClockRate);
791 // //If detected clock rate is something completely unreasonable, dont go ahead
792 // if ( iClockRate < 0xFFFE )
794 // pTempBuffer = (char*)malloc(MAX_GRAPH_TRACE_LEN);
795 // if (pTempBuffer == 0x00000000)
797 // memset(pTempBuffer,0x00,MAX_GRAPH_TRACE_LEN);
798 // //Preform manchester de-modulation and display in a single line.
799 // numManchesterDemodBits = CmdManchesterDemod( strClockRate );
800 // //note: numManchesterDemodBits is set above in CmdManchesterDemod()
801 // if ( numManchesterDemodBits == 0 )
803 // strBitStreamBuffer = malloc(numManchesterDemodBits+1);
804 // if ( strBitStreamBuffer == 0x00000000 )
806 // memset(strBitStreamBuffer, 0x00, (numManchesterDemodBits+1));
807 // //fill strBitStreamBuffer with demodulated, string formatted bits.
808 // for ( j = 0; j <= numManchesterDemodBits; j++ )
810 // sprintf(strTempBufferMini, "%i",BitStream[j]);
811 // strcat(strBitStreamBuffer,strTempBufferMini);
813 // printf("[->]Demodulated Bitstream: \n%s\n", strBitStreamBuffer);
814 // //Reset counter and select most probable bit stream
816 // while ( j < numManchesterDemodBits )
818 // memset(strSimulateBitStream,0x00,64);
819 // //search for header of nine (9) 0's : 000000000 or nine (9) 1's : 1111 1111 1
820 // if ( ( strncmp(strBitStreamBuffer+j, ArrayTraceZero, sizeof(ArrayTraceZero)) == 0 ) ||
821 // ( strncmp(strBitStreamBuffer+j, ArrayTraceOne, sizeof(ArrayTraceOne)) == 0 ) )
823 // iFirstHeaderOffset = j;
824 // memcpy(strSimulateBitStream, strBitStreamBuffer+j,64);
825 // printf("[->]Offset of Header");
826 // if ( strncmp(strBitStreamBuffer+iFirstHeaderOffset, "0", 1) == 0 )
827 // printf("'%s'", ArrayTraceZero );
829 // printf("'%s'", ArrayTraceOne );
830 // printf(": %i\nHighlighted string : %s\n",iFirstHeaderOffset,strSimulateBitStream);
831 // //allow us to escape loop or choose another frame
832 // puts("[<-]Are we happy with this sample? [Y]es/[N]o");
834 // if ( ( strncmp(strAnswer,"y",1) == 0 ) || ( strncmp(strAnswer,"Y",1) == 0 ) )
836 // j = numManchesterDemodBits+1;
845 // //Do we want the buffer inverted?
846 // memset(strAnswer, 0x00, sizeof(strAnswer));
847 // printf("[<-]Do you wish to invert the highlighted bitstream? [Y]es/[N]o\n");
849 // if ( ( strncmp("y", strAnswer,1) == 0 ) || ( strncmp("Y", strAnswer, 1 ) == 0 ) )
851 // //allocate heap memory
852 // pstrInvertBitStream = (char*)malloc(numManchesterDemodBits);
853 // if ( pstrInvertBitStream != 0x00000000 )
855 // memset(pstrInvertBitStream,0x00,numManchesterDemodBits);
857 // //Invert Bitstream
858 // for ( needle = 0; needle <= numManchesterDemodBits; needle++ )
860 // if (strSimulateBitStream[needle] == '0')
861 // strcat(pstrInvertBitStream,"1");
862 // else if (strSimulateBitStream[needle] == '1')
863 // strcat(pstrInvertBitStream,"0");
865 // printf("[->]Inverted bitstream: %s\n", pstrInvertBitStream);
868 // //Confirm parity of selected string
869 // pID = (char*)malloc(11);
870 // if (pID != 0x00000000)
872 // memset(pID, 0x00, 11);
873 // if (ConfirmEm410xTagParity(strSimulateBitStream,pID, 64) == 1)
875 // printf("[->]Parity confirmed for selected bitstream!\n");
876 // printf("[->]Tag ID was detected as: [hex]:%s\n",pID );
879 // printf("[->]Parity check failed for the selected bitstream!\n");
883 // memset(strAnswer, 0x00, sizeof(strAnswer));
884 // printf("[<-]Do you wish to continue with the EM4x simulation? [Y]es/[N]o\n");
886 // if ( ( strncmp(strAnswer,"y",1) == 0 ) || ( strncmp(strAnswer,"Y",1) == 0 ) )
888 // strcat(pTempBuffer, strClockRate);
889 // strcat(pTempBuffer, " ");
890 // if (bInverted == true)
891 // strcat(pTempBuffer,pstrInvertBitStream);
892 // if (bInverted == false)
893 // strcat(pTempBuffer,strSimulateBitStream);
895 // puts("[->]Starting simulation now: \n");
896 // //Simulate tag with prepared buffer.
897 // CmdLFSimManchester(pTempBuffer);
899 // else if ( ( strcmp("n", strAnswer) == 0 ) || ( strcmp("N", strAnswer ) == 0 ) )
900 // printf("[->]Exiting procedure now...\n");
902 // printf("[->]Erroneous selection\nExiting procedure now....\n");
904 // //Clean up -- Exit function
905 // //clear memory, then release pointer.
906 // if ( pstrInvertBitStream != 0x00000000 )
908 // memset(pstrInvertBitStream,0x00,numManchesterDemodBits);
909 // free(pstrInvertBitStream);
911 // if ( pTempBuffer != 0x00000000 )
913 // memset(pTempBuffer,0x00,MAX_GRAPH_TRACE_LEN);
914 // free(pTempBuffer);
916 // if ( pID != 0x00000000 )
918 // memset(pID,0x00,11);
921 // if ( strBitStreamBuffer != 0x00000000 )
923 // memset(strBitStreamBuffer,0x00,numManchesterDemodBits);
924 // free(strBitStreamBuffer);
929 int CmdLFEM4X(const char *Cmd
)
931 CmdsParse(CommandTable
, Cmd
);
935 int CmdHelp(const char *Cmd
)
937 CmdsHelp(CommandTable
);