]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfem4x.c
6567ee41014698b15f6b21ec9b7fed73cf588544
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
);
33 int CmdEMdemodASK(const char *Cmd
)
36 UsbCommand c
={CMD_EM410X_DEMOD
};
37 if(Cmd
[0]=='1') findone
=1;
45 /* Read the ID of an EM410x tag.
47 * 1111 1111 1 <-- standard non-repeatable header
48 * XXXX [row parity bit] <-- 10 rows of 5 bits for our 40 bit tag ID
50 * CCCC <-- each bit here is parity for the 10 bits above in corresponding column
51 * 0 <-- stop bit, end of tag
53 int CmdEM410xRead(const char *Cmd
)
55 int i
, j
, clock
, header
, rows
, bit
, hithigh
, hitlow
, first
, bit2idx
, high
, low
;
60 uint8_t BitStream
[MAX_GRAPH_TRACE_LEN
];
63 /* Detect high and lows and clock */
64 for (i
= 0; i
< GraphTraceLen
; i
++)
66 if (GraphBuffer
[i
] > high
)
67 high
= GraphBuffer
[i
];
68 else if (GraphBuffer
[i
] < low
)
73 clock
= GetClock(Cmd
, high
, 0);
75 /* parity for our 4 columns */
76 parity
[0] = parity
[1] = parity
[2] = parity
[3] = 0;
79 /* manchester demodulate */
81 for (i
= 0; i
< (int)(GraphTraceLen
/ clock
); i
++)
87 /* Find out if we hit both high and low peaks */
88 for (j
= 0; j
< clock
; j
++)
90 if (GraphBuffer
[(i
* clock
) + j
] == high
)
92 else if (GraphBuffer
[(i
* clock
) + j
] == low
)
95 /* it doesn't count if it's the first part of our read
96 because it's really just trailing from the last sequence */
97 if (first
&& (hithigh
|| hitlow
))
102 if (hithigh
&& hitlow
)
106 /* If we didn't hit both high and low peaks, we had a bit transition */
107 if (!hithigh
|| !hitlow
)
110 BitStream
[bit2idx
++] = bit
;
114 /* We go till 5 before the graph ends because we'll get that far below */
115 for (i
= 0; i
< bit2idx
- 5; i
++)
117 /* Step 2: We have our header but need our tag ID */
118 if (header
== 9 && rows
< 10)
120 /* Confirm parity is correct */
121 if ((BitStream
[i
] ^ BitStream
[i
+1] ^ BitStream
[i
+2] ^ BitStream
[i
+3]) == BitStream
[i
+4])
123 /* Read another byte! */
124 sprintf(id
+rows
, "%x", (8 * BitStream
[i
]) + (4 * BitStream
[i
+1]) + (2 * BitStream
[i
+2]) + (1 * BitStream
[i
+3]));
125 sprintf(id2
+rows
, "%x", (8 * BitStream
[i
+3]) + (4 * BitStream
[i
+2]) + (2 * BitStream
[i
+1]) + (1 * BitStream
[i
]));
128 /* Keep parity info */
129 parity
[0] ^= BitStream
[i
];
130 parity
[1] ^= BitStream
[i
+1];
131 parity
[2] ^= BitStream
[i
+2];
132 parity
[3] ^= BitStream
[i
+3];
134 /* Move 4 bits ahead */
138 /* Damn, something wrong! reset */
141 PrintAndLog("Thought we had a valid tag but failed at word %d (i=%d)", rows
+ 1, i
);
143 /* Start back rows * 5 + 9 header bits, -1 to not start at same place */
144 i
-= 9 + (5 * rows
) -5;
150 /* Step 3: Got our 40 bits! confirm column parity */
153 /* We need to make sure our 4 bits of parity are correct and we have a stop bit */
154 if (BitStream
[i
] == parity
[0] && BitStream
[i
+1] == parity
[1] &&
155 BitStream
[i
+2] == parity
[2] && BitStream
[i
+3] == parity
[3] &&
159 PrintAndLog("EM410x Tag ID: %s", id
);
160 PrintAndLog("Unique Tag ID: %s", id2
);
162 global_em410xId
= id
;
168 /* Crap! Incorrect parity or no stop bit, start all over */
173 /* Go back 59 bits (9 header bits + 10 rows at 4+1 parity) */
178 /* Step 1: get our header */
181 /* Need 9 consecutive 1's */
182 if (BitStream
[i
] == 1)
185 /* We don't have a header, not enough consecutive 1 bits */
191 /* if we've already retested after flipping bits, return */
196 /* if this didn't work, try flipping bits */
197 for (i
= 0; i
< bit2idx
; i
++)
203 /* emulate an EM410X tag
205 * 1111 1111 1 <-- standard non-repeatable header
206 * XXXX [row parity bit] <-- 10 rows of 5 bits for our 40 bit tag ID
208 * CCCC <-- each bit here is parity for the 10 bits above in corresponding column
209 * 0 <-- stop bit, end of tag
211 int CmdEM410xSim(const char *Cmd
)
213 int i
, n
, j
, binary
[4], parity
[4];
215 char cmdp
= param_getchar(Cmd
, 0);
216 uint8_t uid
[5] = {0x00};
218 if (cmdp
== 'h' || cmdp
== 'H') {
219 PrintAndLog("Usage: lf em4x 410xsim <UID>");
221 PrintAndLog(" sample: lf em4x 410xsim 0F0368568B");
225 if (param_gethex(Cmd
, 0, uid
, 10)) {
226 PrintAndLog("UID must include 10 HEX symbols");
230 PrintAndLog("Starting simulating UID %02X%02X%02X%02X%02X", uid
[0],uid
[1],uid
[2],uid
[3],uid
[4]);
231 PrintAndLog("Press pm3-button to about simulation");
233 /* clock is 64 in EM410x tags */
236 /* clear our graph */
239 /* write 9 start bits */
240 for (i
= 0; i
< 9; i
++)
241 AppendGraph(0, clock
, 1);
243 /* for each hex char */
244 parity
[0] = parity
[1] = parity
[2] = parity
[3] = 0;
245 for (i
= 0; i
< 10; i
++)
247 /* read each hex char */
248 sscanf(&Cmd
[i
], "%1x", &n
);
249 for (j
= 3; j
>= 0; j
--, n
/= 2)
252 /* append each bit */
253 AppendGraph(0, clock
, binary
[0]);
254 AppendGraph(0, clock
, binary
[1]);
255 AppendGraph(0, clock
, binary
[2]);
256 AppendGraph(0, clock
, binary
[3]);
258 /* append parity bit */
259 AppendGraph(0, clock
, binary
[0] ^ binary
[1] ^ binary
[2] ^ binary
[3]);
261 /* keep track of column parity */
262 parity
[0] ^= binary
[0];
263 parity
[1] ^= binary
[1];
264 parity
[2] ^= binary
[2];
265 parity
[3] ^= binary
[3];
269 AppendGraph(0, clock
, parity
[0]);
270 AppendGraph(0, clock
, parity
[1]);
271 AppendGraph(0, clock
, parity
[2]);
272 AppendGraph(0, clock
, parity
[3]);
275 AppendGraph(1, clock
, 0);
277 CmdLFSim("240"); //240 start_gap.
281 /* Function is equivalent of lf read + data samples + em410xread
282 * looped until an EM410x tag is detected
284 * Why is CmdSamples("16000")?
285 * TBD: Auto-grow sample size based on detected sample rate. IE: If the
286 * rate gets lower, then grow the number of samples
287 * Changed by martin, 4000 x 4 = 16000,
288 * see http://www.proxmark.org/forum/viewtopic.php?pid=7235#p7235
291 int CmdEM410xWatch(const char *Cmd
)
293 int read_h
= (*Cmd
== 'h');
297 printf("\naborted via keyboard!\n");
301 CmdLFRead(read_h
? "h" : "");
310 int CmdEM410xWatchnSpoof(const char *Cmd
)
313 PrintAndLog("# Replaying : %s",global_em410xId
);
314 CmdEM410xSim(global_em410xId
);
318 /* Read the transmitted data of an EM4x50 tag
321 * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity
322 * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity
323 * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity
324 * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity
325 * CCCCCCCC <- column parity bits
327 * LW <- Listen Window
329 * This pattern repeats for every block of data being transmitted.
330 * Transmission starts with two Listen Windows (LW - a modulated
331 * pattern of 320 cycles each (32/32/128/64/64)).
333 * Note that this data may or may not be the UID. It is whatever data
334 * is stored in the blocks defined in the control word First and Last
335 * Word Read values. UID is stored in block 32.
337 int CmdEM4x50Read(const char *Cmd
)
339 int i
, j
, startblock
, skip
, block
, start
, end
, low
, high
;
340 bool complete
= false;
341 int tmpbuff
[MAX_GRAPH_TRACE_LEN
/ 64];
345 memset(tmpbuff
, 0, MAX_GRAPH_TRACE_LEN
/ 64);
347 /* first get high and low values */
348 for (i
= 0; i
< GraphTraceLen
; i
++)
350 if (GraphBuffer
[i
] > high
)
351 high
= GraphBuffer
[i
];
352 else if (GraphBuffer
[i
] < low
)
353 low
= GraphBuffer
[i
];
356 /* populate a buffer with pulse lengths */
359 while (i
< GraphTraceLen
)
361 // measure from low to low
362 while ((GraphBuffer
[i
] > low
) && (i
<GraphTraceLen
))
365 while ((GraphBuffer
[i
] < high
) && (i
<GraphTraceLen
))
367 while ((GraphBuffer
[i
] > low
) && (i
<GraphTraceLen
))
369 if (j
>=(MAX_GRAPH_TRACE_LEN
/64)) {
372 tmpbuff
[j
++]= i
- start
;
375 /* look for data start - should be 2 pairs of LW (pulses of 192,128) */
378 for (i
= 0; i
< j
- 4 ; ++i
)
381 if (tmpbuff
[i
] >= 190 && tmpbuff
[i
] <= 194)
382 if (tmpbuff
[i
+1] >= 126 && tmpbuff
[i
+1] <= 130)
383 if (tmpbuff
[i
+2] >= 190 && tmpbuff
[i
+2] <= 194)
384 if (tmpbuff
[i
+3] >= 126 && tmpbuff
[i
+3] <= 130)
392 /* skip over the remainder of the LW */
393 skip
+= tmpbuff
[i
+1]+tmpbuff
[i
+2];
394 while (skip
< MAX_GRAPH_TRACE_LEN
&& GraphBuffer
[skip
] > low
)
398 /* now do it again to find the end */
400 for (i
+= 3; i
< j
- 4 ; ++i
)
403 if (tmpbuff
[i
] >= 190 && tmpbuff
[i
] <= 194)
404 if (tmpbuff
[i
+1] >= 126 && tmpbuff
[i
+1] <= 130)
405 if (tmpbuff
[i
+2] >= 190 && tmpbuff
[i
+2] <= 194)
406 if (tmpbuff
[i
+3] >= 126 && tmpbuff
[i
+3] <= 130)
414 PrintAndLog("Found data at sample: %i",skip
);
417 PrintAndLog("No data found!");
418 PrintAndLog("Try again with more samples.");
424 PrintAndLog("*** Warning!");
425 PrintAndLog("Partial data - no end found!");
426 PrintAndLog("Try again with more samples.");
429 /* get rid of leading crap */
430 sprintf(tmp
,"%i",skip
);
433 /* now work through remaining buffer printing out data blocks */
438 PrintAndLog("Block %i:", block
);
439 // mandemod routine needs to be split so we can call it for data
440 // just print for now for debugging
441 CmdManchesterDemod("i 64");
443 /* look for LW before start of next block */
444 for ( ; i
< j
- 4 ; ++i
)
447 if (tmpbuff
[i
] >= 190 && tmpbuff
[i
] <= 194)
448 if (tmpbuff
[i
+1] >= 126 && tmpbuff
[i
+1] <= 130)
451 while (GraphBuffer
[skip
] > low
)
454 sprintf(tmp
,"%i",skip
);
462 int CmdEM410xWrite(const char *Cmd
)
464 uint64_t id
= 0xFFFFFFFFFFFFFFFF; // invalid id value
465 int card
= 0xFF; // invalid card value
466 unsigned int clock
= 0; // invalid clock value
468 sscanf(Cmd
, "%" PRIx64
" %d %d", &id
, &card
, &clock
);
471 if (id
== 0xFFFFFFFFFFFFFFFF) {
472 PrintAndLog("Error! ID is required.\n");
475 if (id
>= 0x10000000000) {
476 PrintAndLog("Error! Given EM410x ID is longer than 40 bits.\n");
482 PrintAndLog("Error! Card type required.\n");
486 PrintAndLog("Error! Bad card type selected.\n");
497 // Allowed clock rates: 16, 32 and 64
498 if ((clock
!= 16) && (clock
!= 32) && (clock
!= 64)) {
499 PrintAndLog("Error! Clock rate %d not valid. Supported clock rates are 16, 32 and 64.\n", clock
);
505 PrintAndLog("Error! Clock rate is only supported on T55x7 tags.\n");
510 PrintAndLog("Writing %s tag with UID 0x%010" PRIx64
" (clock rate: %d)", "T55x7", id
, clock
);
511 // NOTE: We really should pass the clock in as a separate argument, but to
512 // provide for backwards-compatibility for older firmware, and to avoid
513 // having to add another argument to CMD_EM410X_WRITE_TAG, we just store
514 // the clock rate in bits 8-15 of the card value
515 card
= (card
& 0xFF) | (((uint64_t)clock
<< 8) & 0xFF00);
518 PrintAndLog("Writing %s tag with UID 0x%010" PRIx64
, "T5555", id
, clock
);
520 PrintAndLog("Error! Bad card type selected.\n");
524 UsbCommand c
= {CMD_EM410X_WRITE_TAG
, {card
, (uint32_t)(id
>> 32), (uint32_t)id
}};
530 int CmdReadWord(const char *Cmd
)
532 int Word
= -1; //default to invalid word
535 sscanf(Cmd
, "%d", &Word
);
537 if ( (Word
> 15) | (Word
< 0) ) {
538 PrintAndLog("Word must be between 0 and 15");
542 PrintAndLog("Reading word %d", Word
);
544 c
.cmd
= CMD_EM4X_READ_WORD
;
545 c
.d
.asBytes
[0] = 0x0; //Normal mode
550 WaitForResponse(CMD_ACK
, NULL
);
552 uint8_t data
[LF_TRACE_BUFF_SIZE
] = {0x00};
554 GetFromBigBuf(data
,LF_TRACE_BUFF_SIZE
,3560); //3560 -- should be offset..
555 WaitForResponseTimeout(CMD_ACK
,NULL
, 1500);
557 for (int j
= 0; j
< LF_TRACE_BUFF_SIZE
; j
++) {
558 GraphBuffer
[j
] = ((int)data
[j
]);
560 GraphTraceLen
= LF_TRACE_BUFF_SIZE
;
562 uint8_t bits
[LF_BITSSTREAM_LEN
] = {0x00};
563 uint8_t * bitstream
= bits
;
564 manchester_decode(GraphBuffer
, LF_TRACE_BUFF_SIZE
, bitstream
,LF_BITSSTREAM_LEN
);
565 RepaintGraphWindow();
569 int CmdReadWordPWD(const char *Cmd
)
571 int Word
= -1; //default to invalid word
572 int Password
= 0xFFFFFFFF; //default to blank password
575 sscanf(Cmd
, "%d %x", &Word
, &Password
);
577 if ( (Word
> 15) | (Word
< 0) ) {
578 PrintAndLog("Word must be between 0 and 15");
582 PrintAndLog("Reading word %d with password %08X", Word
, Password
);
584 c
.cmd
= CMD_EM4X_READ_WORD
;
585 c
.d
.asBytes
[0] = 0x1; //Password mode
590 WaitForResponse(CMD_ACK
, NULL
);
592 uint8_t data
[LF_TRACE_BUFF_SIZE
] = {0x00};
594 GetFromBigBuf(data
,LF_TRACE_BUFF_SIZE
,3560); //3560 -- should be offset..
595 WaitForResponseTimeout(CMD_ACK
,NULL
, 1500);
597 for (int j
= 0; j
< LF_TRACE_BUFF_SIZE
; j
++) {
598 GraphBuffer
[j
] = ((int)data
[j
]);
600 GraphTraceLen
= LF_TRACE_BUFF_SIZE
;
602 uint8_t bits
[LF_BITSSTREAM_LEN
] = {0x00};
603 uint8_t * bitstream
= bits
;
604 manchester_decode(GraphBuffer
, LF_TRACE_BUFF_SIZE
, bitstream
, LF_BITSSTREAM_LEN
);
605 RepaintGraphWindow();
609 int CmdWriteWord(const char *Cmd
)
611 int Word
= 16; //default to invalid block
612 int Data
= 0xFFFFFFFF; //default to blank data
615 sscanf(Cmd
, "%x %d", &Data
, &Word
);
618 PrintAndLog("Word must be between 0 and 15");
622 PrintAndLog("Writing word %d with data %08X", Word
, Data
);
624 c
.cmd
= CMD_EM4X_WRITE_WORD
;
625 c
.d
.asBytes
[0] = 0x0; //Normal mode
633 int CmdWriteWordPWD(const char *Cmd
)
635 int Word
= 16; //default to invalid word
636 int Data
= 0xFFFFFFFF; //default to blank data
637 int Password
= 0xFFFFFFFF; //default to blank password
640 sscanf(Cmd
, "%x %d %x", &Data
, &Word
, &Password
);
643 PrintAndLog("Word must be between 0 and 15");
647 PrintAndLog("Writing word %d with data %08X and password %08X", Word
, Data
, Password
);
649 c
.cmd
= CMD_EM4X_WRITE_WORD
;
650 c
.d
.asBytes
[0] = 0x1; //Password mode
658 static command_t CommandTable
[] =
660 {"help", CmdHelp
, 1, "This help"},
661 {"410xdemod", CmdEMdemodASK
, 0, "[clock rate] -- Extract ID from EM410x tag"},
662 {"410xread", CmdEM410xRead
, 1, "[clock rate] -- Extract ID from EM410x tag"},
663 {"410xsim", CmdEM410xSim
, 0, "<UID> -- Simulate EM410x tag"},
664 {"replay", MWRem4xReplay
, 0, "Watches for tag and simulates manchester encoded em4x tag"},
665 {"410xwatch", CmdEM410xWatch
, 0, "['h'] -- Watches for EM410x 125/134 kHz tags (option 'h' for 134)"},
666 {"410xspoof", CmdEM410xWatchnSpoof
, 0, "['h'] --- Watches for EM410x 125/134 kHz tags, and replays them. (option 'h' for 134)" },
667 {"410xwrite", CmdEM410xWrite
, 1, "<UID> <'0' T5555> <'1' T55x7> [clock rate] -- Write EM410x UID to T5555(Q5) or T55x7 tag, optionally setting clock rate"},
668 {"4x50read", CmdEM4x50Read
, 1, "Extract data from EM4x50 tag"},
669 {"rd", CmdReadWord
, 1, "<Word 1-15> -- Read EM4xxx word data"},
670 {"rdpwd", CmdReadWordPWD
, 1, "<Word 1-15> <Password> -- Read EM4xxx word data in password mode "},
671 {"wr", CmdWriteWord
, 1, "<Data> <Word 1-15> -- Write EM4xxx word data"},
672 {"wrpwd", CmdWriteWordPWD
, 1, "<Data> <Word 1-15> <Password> -- Write EM4xxx word data in password mode"},
673 {NULL
, NULL
, 0, NULL
}
677 //Confirms the parity of a bitstream as well as obtaining the data (TagID) from within the appropriate memory space.
679 // Pointer to a string containing the desired bitsream
680 // Pointer to a string that will receive the decoded tag ID
681 // Length of the bitsream pointed at in the first argument, char* _strBitStream
684 //0 Parity not confirmed
685 int ConfirmEm410xTagParity( char* _strBitStream
, char* pID
, int LengthOfBitstream
)
689 int Parity
[4] = {0x00};
690 char ID
[11] = {0x00};
692 int BitStream
[70] = {0x00};
695 for ( i
= 0; i
<= LengthOfBitstream
; i
++)
697 if (_strBitStream
[i
] == '1')
700 memcpy(&BitStream
[i
], &k
,4);
702 else if (_strBitStream
[i
] == '0')
705 memcpy(&BitStream
[i
], &k
,4);
708 while ( counter
< 2 )
710 //set/reset variables and counters
711 memset(ID
,0x00,sizeof(ID
));
712 memset(Parity
,0x00,sizeof(Parity
));
714 for ( i
= 9; i
<= LengthOfBitstream
; i
++)
718 if ((BitStream
[i
] ^ BitStream
[i
+1] ^ BitStream
[i
+2] ^ BitStream
[i
+3]) == BitStream
[i
+4])
720 sprintf(ID
+rows
, "%x", (8 * BitStream
[i
]) + (4 * BitStream
[i
+1]) + (2 * BitStream
[i
+2]) + (1 * BitStream
[i
+3]));
722 /* Keep parity info and move four bits ahead*/
723 Parity
[0] ^= BitStream
[i
];
724 Parity
[1] ^= BitStream
[i
+1];
725 Parity
[2] ^= BitStream
[i
+2];
726 Parity
[3] ^= BitStream
[i
+3];
732 if ( BitStream
[i
] == Parity
[0] && BitStream
[i
+1] == Parity
[1] &&
733 BitStream
[i
+2] == Parity
[2] && BitStream
[i
+3] == Parity
[3] &&
736 memcpy(pID
,ID
,strlen(ID
));
741 printf("[PARITY ->]Failed. Flipping Bits, and rechecking parity for bitstream:\n[PARITY ->]");
742 for (k
= 0; k
< LengthOfBitstream
; k
++)
745 printf("%i", BitStream
[k
]);
752 //Reads and demodulates an em410x RFID tag. It further allows slight modification to the decoded bitstream
753 //Once a suitable bitstream has been identified, and if needed, modified, it is replayed. Allowing emulation of the
755 //No meaningful returns or arguments.
756 int MWRem4xReplay(const char* Cmd
)
759 // static char ArrayTraceZero[] = { '0','0','0','0','0','0','0','0','0' };
760 // static char ArrayTraceOne[] = { '1','1','1','1','1','1','1','1','1' };
761 // //local string variables
762 // char strClockRate[10] = {0x00};
763 // char strAnswer[4] = {0x00};
764 // char strTempBufferMini[2] = {0x00};
765 // //our outbound bit-stream
766 // char strSimulateBitStream[65] = {0x00};
768 // int iClockRate = 0;
771 // int iFirstHeaderOffset = 0x00000000;
772 // int numManchesterDemodBits=0;
774 // bool bInverted = false;
775 // //pointers to strings. memory will be allocated.
776 // char* pstrInvertBitStream = 0x00000000;
777 // char* pTempBuffer = 0x00000000;
778 // char* pID = 0x00000000;
779 // char* strBitStreamBuffer = 0x00000000;
782 // puts("###################################");
783 // puts("#### Em4x Replay ##");
784 // puts("#### R.A.M. June 2013 ##");
785 // puts("###################################");
788 // //Collect ourselves 10,000 samples
789 // CmdSamples("10000");
790 // puts("[->]preforming ASK demodulation\n");
793 // iClockRate = DetectClock(0);
794 // sprintf(strClockRate, "%i\n",iClockRate);
795 // printf("[->]Detected ClockRate: %s\n", strClockRate);
797 // //If detected clock rate is something completely unreasonable, dont go ahead
798 // if ( iClockRate < 0xFFFE )
800 // pTempBuffer = (char*)malloc(MAX_GRAPH_TRACE_LEN);
801 // if (pTempBuffer == 0x00000000)
803 // memset(pTempBuffer,0x00,MAX_GRAPH_TRACE_LEN);
804 // //Preform manchester de-modulation and display in a single line.
805 // numManchesterDemodBits = CmdManchesterDemod( strClockRate );
806 // //note: numManchesterDemodBits is set above in CmdManchesterDemod()
807 // if ( numManchesterDemodBits == 0 )
809 // strBitStreamBuffer = malloc(numManchesterDemodBits+1);
810 // if ( strBitStreamBuffer == 0x00000000 )
812 // memset(strBitStreamBuffer, 0x00, (numManchesterDemodBits+1));
813 // //fill strBitStreamBuffer with demodulated, string formatted bits.
814 // for ( j = 0; j <= numManchesterDemodBits; j++ )
816 // sprintf(strTempBufferMini, "%i",BitStream[j]);
817 // strcat(strBitStreamBuffer,strTempBufferMini);
819 // printf("[->]Demodulated Bitstream: \n%s\n", strBitStreamBuffer);
820 // //Reset counter and select most probable bit stream
822 // while ( j < numManchesterDemodBits )
824 // memset(strSimulateBitStream,0x00,64);
825 // //search for header of nine (9) 0's : 000000000 or nine (9) 1's : 1111 1111 1
826 // if ( ( strncmp(strBitStreamBuffer+j, ArrayTraceZero, sizeof(ArrayTraceZero)) == 0 ) ||
827 // ( strncmp(strBitStreamBuffer+j, ArrayTraceOne, sizeof(ArrayTraceOne)) == 0 ) )
829 // iFirstHeaderOffset = j;
830 // memcpy(strSimulateBitStream, strBitStreamBuffer+j,64);
831 // printf("[->]Offset of Header");
832 // if ( strncmp(strBitStreamBuffer+iFirstHeaderOffset, "0", 1) == 0 )
833 // printf("'%s'", ArrayTraceZero );
835 // printf("'%s'", ArrayTraceOne );
836 // printf(": %i\nHighlighted string : %s\n",iFirstHeaderOffset,strSimulateBitStream);
837 // //allow us to escape loop or choose another frame
838 // puts("[<-]Are we happy with this sample? [Y]es/[N]o");
840 // if ( ( strncmp(strAnswer,"y",1) == 0 ) || ( strncmp(strAnswer,"Y",1) == 0 ) )
842 // j = numManchesterDemodBits+1;
851 // //Do we want the buffer inverted?
852 // memset(strAnswer, 0x00, sizeof(strAnswer));
853 // printf("[<-]Do you wish to invert the highlighted bitstream? [Y]es/[N]o\n");
855 // if ( ( strncmp("y", strAnswer,1) == 0 ) || ( strncmp("Y", strAnswer, 1 ) == 0 ) )
857 // //allocate heap memory
858 // pstrInvertBitStream = (char*)malloc(numManchesterDemodBits);
859 // if ( pstrInvertBitStream != 0x00000000 )
861 // memset(pstrInvertBitStream,0x00,numManchesterDemodBits);
863 // //Invert Bitstream
864 // for ( needle = 0; needle <= numManchesterDemodBits; needle++ )
866 // if (strSimulateBitStream[needle] == '0')
867 // strcat(pstrInvertBitStream,"1");
868 // else if (strSimulateBitStream[needle] == '1')
869 // strcat(pstrInvertBitStream,"0");
871 // printf("[->]Inverted bitstream: %s\n", pstrInvertBitStream);
874 // //Confirm parity of selected string
875 // pID = (char*)malloc(11);
876 // if (pID != 0x00000000)
878 // memset(pID, 0x00, 11);
879 // if (ConfirmEm410xTagParity(strSimulateBitStream,pID, 64) == 1)
881 // printf("[->]Parity confirmed for selected bitstream!\n");
882 // printf("[->]Tag ID was detected as: [hex]:%s\n",pID );
885 // printf("[->]Parity check failed for the selected bitstream!\n");
889 // memset(strAnswer, 0x00, sizeof(strAnswer));
890 // printf("[<-]Do you wish to continue with the EM4x simulation? [Y]es/[N]o\n");
892 // if ( ( strncmp(strAnswer,"y",1) == 0 ) || ( strncmp(strAnswer,"Y",1) == 0 ) )
894 // strcat(pTempBuffer, strClockRate);
895 // strcat(pTempBuffer, " ");
896 // if (bInverted == true)
897 // strcat(pTempBuffer,pstrInvertBitStream);
898 // if (bInverted == false)
899 // strcat(pTempBuffer,strSimulateBitStream);
901 // puts("[->]Starting simulation now: \n");
902 // //Simulate tag with prepared buffer.
903 // CmdLFSimManchester(pTempBuffer);
905 // else if ( ( strcmp("n", strAnswer) == 0 ) || ( strcmp("N", strAnswer ) == 0 ) )
906 // printf("[->]Exiting procedure now...\n");
908 // printf("[->]Erroneous selection\nExiting procedure now....\n");
910 // //Clean up -- Exit function
911 // //clear memory, then release pointer.
912 // if ( pstrInvertBitStream != 0x00000000 )
914 // memset(pstrInvertBitStream,0x00,numManchesterDemodBits);
915 // free(pstrInvertBitStream);
917 // if ( pTempBuffer != 0x00000000 )
919 // memset(pTempBuffer,0x00,MAX_GRAPH_TRACE_LEN);
920 // free(pTempBuffer);
922 // if ( pID != 0x00000000 )
924 // memset(pID,0x00,11);
927 // if ( strBitStreamBuffer != 0x00000000 )
929 // memset(strBitStreamBuffer,0x00,numManchesterDemodBits);
930 // free(strBitStreamBuffer);
935 int CmdLFEM4X(const char *Cmd
)
937 CmdsParse(CommandTable
, Cmd
);
941 int CmdHelp(const char *Cmd
)
943 CmdsHelp(CommandTable
);