]>
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 /* Read the ID of an EM410x tag.
33 * 1111 1111 1 <-- standard non-repeatable header
34 * XXXX [row parity bit] <-- 10 rows of 5 bits for our 40 bit tag ID
36 * CCCC <-- each bit here is parity for the 10 bits above in corresponding column
37 * 0 <-- stop bit, end of tag
39 int CmdEM410xRead(const char *Cmd
)
41 int i
, j
, clock
, header
, rows
, bit
, hithigh
, hitlow
, first
, bit2idx
, high
, low
;
46 uint8_t BitStream
[MAX_GRAPH_TRACE_LEN
];
49 /* Detect high and lows and clock */
50 for (i
= 0; i
< GraphTraceLen
; i
++)
52 if (GraphBuffer
[i
] > high
)
53 high
= GraphBuffer
[i
];
54 else if (GraphBuffer
[i
] < low
)
59 clock
= GetClock(Cmd
, high
, 0);
61 /* parity for our 4 columns */
62 parity
[0] = parity
[1] = parity
[2] = parity
[3] = 0;
65 /* manchester demodulate */
67 for (i
= 0; i
< (int)(GraphTraceLen
/ clock
); i
++)
73 /* Find out if we hit both high and low peaks */
74 for (j
= 0; j
< clock
; j
++)
76 if (GraphBuffer
[(i
* clock
) + j
] == high
)
78 else if (GraphBuffer
[(i
* clock
) + j
] == low
)
81 /* it doesn't count if it's the first part of our read
82 because it's really just trailing from the last sequence */
83 if (first
&& (hithigh
|| hitlow
))
88 if (hithigh
&& hitlow
)
92 /* If we didn't hit both high and low peaks, we had a bit transition */
93 if (!hithigh
|| !hitlow
)
96 BitStream
[bit2idx
++] = bit
;
100 /* We go till 5 before the graph ends because we'll get that far below */
101 for (i
= 0; i
< bit2idx
- 5; i
++)
103 /* Step 2: We have our header but need our tag ID */
104 if (header
== 9 && rows
< 10)
106 /* Confirm parity is correct */
107 if ((BitStream
[i
] ^ BitStream
[i
+1] ^ BitStream
[i
+2] ^ BitStream
[i
+3]) == BitStream
[i
+4])
109 /* Read another byte! */
110 sprintf(id
+rows
, "%x", (8 * BitStream
[i
]) + (4 * BitStream
[i
+1]) + (2 * BitStream
[i
+2]) + (1 * BitStream
[i
+3]));
111 sprintf(id2
+rows
, "%x", (8 * BitStream
[i
+3]) + (4 * BitStream
[i
+2]) + (2 * BitStream
[i
+1]) + (1 * BitStream
[i
]));
114 /* Keep parity info */
115 parity
[0] ^= BitStream
[i
];
116 parity
[1] ^= BitStream
[i
+1];
117 parity
[2] ^= BitStream
[i
+2];
118 parity
[3] ^= BitStream
[i
+3];
120 /* Move 4 bits ahead */
124 /* Damn, something wrong! reset */
127 PrintAndLog("Thought we had a valid tag but failed at word %d (i=%d)", rows
+ 1, i
);
129 /* Start back rows * 5 + 9 header bits, -1 to not start at same place */
130 i
-= 9 + (5 * rows
) -5;
136 /* Step 3: Got our 40 bits! confirm column parity */
139 /* We need to make sure our 4 bits of parity are correct and we have a stop bit */
140 if (BitStream
[i
] == parity
[0] && BitStream
[i
+1] == parity
[1] &&
141 BitStream
[i
+2] == parity
[2] && BitStream
[i
+3] == parity
[3] &&
145 PrintAndLog("EM410x Tag ID: %s", id
);
146 PrintAndLog("Unique Tag ID: %s", id2
);
148 global_em410xId
= id
;
154 /* Crap! Incorrect parity or no stop bit, start all over */
159 /* Go back 59 bits (9 header bits + 10 rows at 4+1 parity) */
164 /* Step 1: get our header */
167 /* Need 9 consecutive 1's */
168 if (BitStream
[i
] == 1)
171 /* We don't have a header, not enough consecutive 1 bits */
177 /* if we've already retested after flipping bits, return */
182 /* if this didn't work, try flipping bits */
183 for (i
= 0; i
< bit2idx
; i
++)
189 /* emulate an EM410X tag
191 * 1111 1111 1 <-- standard non-repeatable header
192 * XXXX [row parity bit] <-- 10 rows of 5 bits for our 40 bit tag ID
194 * CCCC <-- each bit here is parity for the 10 bits above in corresponding column
195 * 0 <-- stop bit, end of tag
197 int CmdEM410xSim(const char *Cmd
)
199 int i
, n
, j
, binary
[4], parity
[4];
201 char cmdp
= param_getchar(Cmd
, 0);
202 uint8_t uid
[5] = {0x00};
204 if (cmdp
== 'h' || cmdp
== 'H') {
205 PrintAndLog("Usage: lf em4x sim <UID>");
207 PrintAndLog(" sample: lf em4x sim 0F0368568B");
211 if (param_gethex(Cmd
, 0, uid
, 10)) {
212 PrintAndLog("UID must include 10 HEX symbols");
216 PrintAndLog("Starting simulating UID %02X%02X%02X%02X%02X", uid
[0],uid
[1],uid
[2],uid
[3],uid
[4]);
217 PrintAndLog("Press pm3-button to about simulation");
219 /* clock is 64 in EM410x tags */
222 /* clear our graph */
225 /* write 9 start bits */
226 for (i
= 0; i
< 9; i
++)
227 AppendGraph(0, clock
, 1);
229 /* for each hex char */
230 parity
[0] = parity
[1] = parity
[2] = parity
[3] = 0;
231 for (i
= 0; i
< 10; i
++)
233 /* read each hex char */
234 sscanf(&Cmd
[i
], "%1x", &n
);
235 for (j
= 3; j
>= 0; j
--, n
/= 2)
238 /* append each bit */
239 AppendGraph(0, clock
, binary
[0]);
240 AppendGraph(0, clock
, binary
[1]);
241 AppendGraph(0, clock
, binary
[2]);
242 AppendGraph(0, clock
, binary
[3]);
244 /* append parity bit */
245 AppendGraph(0, clock
, binary
[0] ^ binary
[1] ^ binary
[2] ^ binary
[3]);
247 /* keep track of column parity */
248 parity
[0] ^= binary
[0];
249 parity
[1] ^= binary
[1];
250 parity
[2] ^= binary
[2];
251 parity
[3] ^= binary
[3];
255 AppendGraph(0, clock
, parity
[0]);
256 AppendGraph(0, clock
, parity
[1]);
257 AppendGraph(0, clock
, parity
[2]);
258 AppendGraph(0, clock
, parity
[3]);
261 AppendGraph(0, clock
, 0);
263 //CmdManchesterMod("64");
266 RepaintGraphWindow();
272 /* Function is equivalent of lf read + data samples + em410xread
273 * looped until an EM410x tag is detected
275 * Why is CmdSamples("16000")?
276 * TBD: Auto-grow sample size based on detected sample rate. IE: If the
277 * rate gets lower, then grow the number of samples
278 * Changed by martin, 4000 x 4 = 16000,
279 * see http://www.proxmark.org/forum/viewtopic.php?pid=7235#p7235
282 int CmdEM410xWatch(const char *Cmd
)
284 int read_h
= (*Cmd
== 'h');
288 printf("\naborted via keyboard!\n");
292 CmdLFRead(read_h
? "h" : "");
301 int CmdEM410xWatchnSpoof(const char *Cmd
)
304 PrintAndLog("# Replaying : %s",global_em410xId
);
305 CmdEM410xSim(global_em410xId
);
309 /* Read the transmitted data of an EM4x50 tag
312 * XXXXXXXX [row parity bit (even)] <- 8 bits plus parity
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 * CCCCCCCC <- column parity bits
318 * LW <- Listen Window
320 * This pattern repeats for every block of data being transmitted.
321 * Transmission starts with two Listen Windows (LW - a modulated
322 * pattern of 320 cycles each (32/32/128/64/64)).
324 * Note that this data may or may not be the UID. It is whatever data
325 * is stored in the blocks defined in the control word First and Last
326 * Word Read values. UID is stored in block 32.
328 int CmdEM4x50Read(const char *Cmd
)
330 int i
, j
, startblock
, skip
, block
, start
, end
, low
, high
;
331 bool complete
= false;
332 int tmpbuff
[MAX_GRAPH_TRACE_LEN
/ 64];
336 memset(tmpbuff
, 0, MAX_GRAPH_TRACE_LEN
/ 64);
338 /* first get high and low values */
339 for (i
= 0; i
< GraphTraceLen
; i
++)
341 if (GraphBuffer
[i
] > high
)
342 high
= GraphBuffer
[i
];
343 else if (GraphBuffer
[i
] < low
)
344 low
= GraphBuffer
[i
];
347 /* populate a buffer with pulse lengths */
350 while (i
< GraphTraceLen
)
352 // measure from low to low
353 while ((GraphBuffer
[i
] > low
) && (i
<GraphTraceLen
))
356 while ((GraphBuffer
[i
] < high
) && (i
<GraphTraceLen
))
358 while ((GraphBuffer
[i
] > low
) && (i
<GraphTraceLen
))
360 if (j
>=(MAX_GRAPH_TRACE_LEN
/64)) {
363 tmpbuff
[j
++]= i
- start
;
366 /* look for data start - should be 2 pairs of LW (pulses of 192,128) */
369 for (i
= 0; i
< j
- 4 ; ++i
)
372 if (tmpbuff
[i
] >= 190 && tmpbuff
[i
] <= 194)
373 if (tmpbuff
[i
+1] >= 126 && tmpbuff
[i
+1] <= 130)
374 if (tmpbuff
[i
+2] >= 190 && tmpbuff
[i
+2] <= 194)
375 if (tmpbuff
[i
+3] >= 126 && tmpbuff
[i
+3] <= 130)
383 /* skip over the remainder of the LW */
384 skip
+= tmpbuff
[i
+1]+tmpbuff
[i
+2];
385 while (skip
< MAX_GRAPH_TRACE_LEN
&& GraphBuffer
[skip
] > low
)
389 /* now do it again to find the end */
391 for (i
+= 3; i
< j
- 4 ; ++i
)
394 if (tmpbuff
[i
] >= 190 && tmpbuff
[i
] <= 194)
395 if (tmpbuff
[i
+1] >= 126 && tmpbuff
[i
+1] <= 130)
396 if (tmpbuff
[i
+2] >= 190 && tmpbuff
[i
+2] <= 194)
397 if (tmpbuff
[i
+3] >= 126 && tmpbuff
[i
+3] <= 130)
405 PrintAndLog("Found data at sample: %i",skip
);
408 PrintAndLog("No data found!");
409 PrintAndLog("Try again with more samples.");
415 PrintAndLog("*** Warning!");
416 PrintAndLog("Partial data - no end found!");
417 PrintAndLog("Try again with more samples.");
420 /* get rid of leading crap */
421 sprintf(tmp
,"%i",skip
);
424 /* now work through remaining buffer printing out data blocks */
429 PrintAndLog("Block %i:", block
);
430 // mandemod routine needs to be split so we can call it for data
431 // just print for now for debugging
432 CmdManchesterDemod("i 64");
434 /* look for LW before start of next block */
435 for ( ; i
< j
- 4 ; ++i
)
438 if (tmpbuff
[i
] >= 190 && tmpbuff
[i
] <= 194)
439 if (tmpbuff
[i
+1] >= 126 && tmpbuff
[i
+1] <= 130)
442 while (GraphBuffer
[skip
] > low
)
445 sprintf(tmp
,"%i",skip
);
453 int CmdEM410xWrite(const char *Cmd
)
455 uint64_t id
= 0xFFFFFFFFFFFFFFFF; // invalid id value
456 int card
= 0xFF; // invalid card value
457 unsigned int clock
= 0; // invalid clock value
459 sscanf(Cmd
, "%" PRIx64
" %d %d", &id
, &card
, &clock
);
462 if (id
== 0xFFFFFFFFFFFFFFFF) {
463 PrintAndLog("Error! ID is required.\n");
466 if (id
>= 0x10000000000) {
467 PrintAndLog("Error! Given EM410x ID is longer than 40 bits.\n");
473 PrintAndLog("Error! Card type required.\n");
477 PrintAndLog("Error! Bad card type selected.\n");
488 // Allowed clock rates: 16, 32 and 64
489 if ((clock
!= 16) && (clock
!= 32) && (clock
!= 64)) {
490 PrintAndLog("Error! Clock rate %d not valid. Supported clock rates are 16, 32 and 64.\n", clock
);
496 PrintAndLog("Error! Clock rate is only supported on T55x7 tags.\n");
501 PrintAndLog("Writing %s tag with UID 0x%010" PRIx64
" (clock rate: %d)", "T55x7", id
, clock
);
502 // NOTE: We really should pass the clock in as a separate argument, but to
503 // provide for backwards-compatibility for older firmware, and to avoid
504 // having to add another argument to CMD_EM410X_WRITE_TAG, we just store
505 // the clock rate in bits 8-15 of the card value
506 card
= (card
& 0xFF) | (((uint64_t)clock
<< 8) & 0xFF00);
509 PrintAndLog("Writing %s tag with UID 0x%010" PRIx64
, "T5555", id
, clock
);
511 PrintAndLog("Error! Bad card type selected.\n");
515 UsbCommand c
= {CMD_EM410X_WRITE_TAG
, {card
, (uint32_t)(id
>> 32), (uint32_t)id
}};
521 int CmdReadWord(const char *Cmd
)
523 int Word
= -1; //default to invalid word
526 sscanf(Cmd
, "%d", &Word
);
528 if ( (Word
> 15) | (Word
< 0) ) {
529 PrintAndLog("Word must be between 0 and 15");
533 PrintAndLog("Reading word %d", Word
);
535 c
.cmd
= CMD_EM4X_READ_WORD
;
536 c
.d
.asBytes
[0] = 0x0; //Normal mode
541 WaitForResponse(CMD_ACK
, NULL
);
543 uint8_t data
[LF_TRACE_BUFF_SIZE
] = {0x00};
545 GetFromBigBuf(data
,LF_TRACE_BUFF_SIZE
,3560); //3560 -- should be offset..
546 WaitForResponseTimeout(CMD_ACK
,NULL
, 1500);
548 for (int j
= 0; j
< LF_TRACE_BUFF_SIZE
; j
++) {
549 GraphBuffer
[j
] = ((int)data
[j
]);
551 GraphTraceLen
= LF_TRACE_BUFF_SIZE
;
553 uint8_t bits
[LF_BITSSTREAM_LEN
] = {0x00};
554 uint8_t * bitstream
= bits
;
555 manchester_decode(GraphBuffer
, LF_TRACE_BUFF_SIZE
, bitstream
,LF_BITSSTREAM_LEN
);
556 RepaintGraphWindow();
560 int CmdReadWordPWD(const char *Cmd
)
562 int Word
= -1; //default to invalid word
563 int Password
= 0xFFFFFFFF; //default to blank password
566 sscanf(Cmd
, "%d %x", &Word
, &Password
);
568 if ( (Word
> 15) | (Word
< 0) ) {
569 PrintAndLog("Word must be between 0 and 15");
573 PrintAndLog("Reading word %d with password %08X", Word
, Password
);
575 c
.cmd
= CMD_EM4X_READ_WORD
;
576 c
.d
.asBytes
[0] = 0x1; //Password mode
581 WaitForResponse(CMD_ACK
, NULL
);
583 uint8_t data
[LF_TRACE_BUFF_SIZE
] = {0x00};
585 GetFromBigBuf(data
,LF_TRACE_BUFF_SIZE
,3560); //3560 -- should be offset..
586 WaitForResponseTimeout(CMD_ACK
,NULL
, 1500);
588 for (int j
= 0; j
< LF_TRACE_BUFF_SIZE
; j
++) {
589 GraphBuffer
[j
] = ((int)data
[j
]);
591 GraphTraceLen
= LF_TRACE_BUFF_SIZE
;
593 uint8_t bits
[LF_BITSSTREAM_LEN
] = {0x00};
594 uint8_t * bitstream
= bits
;
595 manchester_decode(GraphBuffer
, LF_TRACE_BUFF_SIZE
, bitstream
, LF_BITSSTREAM_LEN
);
596 RepaintGraphWindow();
600 int CmdWriteWord(const char *Cmd
)
602 int Word
= 16; //default to invalid block
603 int Data
= 0xFFFFFFFF; //default to blank data
606 sscanf(Cmd
, "%x %d", &Data
, &Word
);
609 PrintAndLog("Word must be between 0 and 15");
613 PrintAndLog("Writing word %d with data %08X", Word
, Data
);
615 c
.cmd
= CMD_EM4X_WRITE_WORD
;
616 c
.d
.asBytes
[0] = 0x0; //Normal mode
624 int CmdWriteWordPWD(const char *Cmd
)
626 int Word
= 16; //default to invalid word
627 int Data
= 0xFFFFFFFF; //default to blank data
628 int Password
= 0xFFFFFFFF; //default to blank password
631 sscanf(Cmd
, "%x %d %x", &Data
, &Word
, &Password
);
634 PrintAndLog("Word must be between 0 and 15");
638 PrintAndLog("Writing word %d with data %08X and password %08X", Word
, Data
, Password
);
640 c
.cmd
= CMD_EM4X_WRITE_WORD
;
641 c
.d
.asBytes
[0] = 0x1; //Password mode
649 static command_t CommandTable
[] =
651 {"help", CmdHelp
, 1, "This help"},
653 {"410xread", CmdEM410xRead
, 1, "[clock rate] -- Extract ID from EM410x tag"},
654 {"410xsim", CmdEM410xSim
, 0, "<UID> -- Simulate EM410x tag"},
655 {"replay", MWRem4xReplay
, 0, "Watches for tag and simulates manchester encoded em4x tag"},
656 {"410xwatch", CmdEM410xWatch
, 0, "['h'] -- Watches for EM410x 125/134 kHz tags (option 'h' for 134)"},
657 {"410xspoof", CmdEM410xWatchnSpoof
, 0, "['h'] --- Watches for EM410x 125/134 kHz tags, and replays them. (option 'h' for 134)" },
658 {"410xwrite", CmdEM410xWrite
, 1, "<UID> <'0' T5555> <'1' T55x7> [clock rate] -- Write EM410x UID to T5555(Q5) or T55x7 tag, optionally setting clock rate"},
659 {"4x50read", CmdEM4x50Read
, 1, "Extract data from EM4x50 tag"},
660 {"rd", CmdReadWord
, 1, "<Word 1-15> -- Read EM4xxx word data"},
661 {"rdpwd", CmdReadWordPWD
, 1, "<Word 1-15> <Password> -- Read EM4xxx word data in password mode "},
662 {"wr", CmdWriteWord
, 1, "<Data> <Word 1-15> -- Write EM4xxx word data"},
663 {"wrpwd", CmdWriteWordPWD
, 1, "<Data> <Word 1-15> <Password> -- Write EM4xxx word data in password mode"},
664 {NULL
, NULL
, 0, NULL
}
668 //Confirms the parity of a bitstream as well as obtaining the data (TagID) from within the appropriate memory space.
670 // Pointer to a string containing the desired bitsream
671 // Pointer to a string that will receive the decoded tag ID
672 // Length of the bitsream pointed at in the first argument, char* _strBitStream
675 //0 Parity not confirmed
676 int ConfirmEm410xTagParity( char* _strBitStream
, char* pID
, int LengthOfBitstream
)
680 int Parity
[4] = {0x00};
681 char ID
[11] = {0x00};
683 int BitStream
[70] = {0x00};
686 for ( i
= 0; i
<= LengthOfBitstream
; i
++)
688 if (_strBitStream
[i
] == '1')
691 memcpy(&BitStream
[i
], &k
,4);
693 else if (_strBitStream
[i
] == '0')
696 memcpy(&BitStream
[i
], &k
,4);
699 while ( counter
< 2 )
701 //set/reset variables and counters
702 memset(ID
,0x00,sizeof(ID
));
703 memset(Parity
,0x00,sizeof(Parity
));
705 for ( i
= 9; i
<= LengthOfBitstream
; i
++)
709 if ((BitStream
[i
] ^ BitStream
[i
+1] ^ BitStream
[i
+2] ^ BitStream
[i
+3]) == BitStream
[i
+4])
711 sprintf(ID
+rows
, "%x", (8 * BitStream
[i
]) + (4 * BitStream
[i
+1]) + (2 * BitStream
[i
+2]) + (1 * BitStream
[i
+3]));
713 /* Keep parity info and move four bits ahead*/
714 Parity
[0] ^= BitStream
[i
];
715 Parity
[1] ^= BitStream
[i
+1];
716 Parity
[2] ^= BitStream
[i
+2];
717 Parity
[3] ^= BitStream
[i
+3];
723 if ( BitStream
[i
] == Parity
[0] && BitStream
[i
+1] == Parity
[1] &&
724 BitStream
[i
+2] == Parity
[2] && BitStream
[i
+3] == Parity
[3] &&
727 memcpy(pID
,ID
,strlen(ID
));
732 printf("[PARITY ->]Failed. Flipping Bits, and rechecking parity for bitstream:\n[PARITY ->]");
733 for (k
= 0; k
< LengthOfBitstream
; k
++)
736 printf("%i", BitStream
[k
]);
743 //Reads and demodulates an em410x RFID tag. It further allows slight modification to the decoded bitstream
744 //Once a suitable bitstream has been identified, and if needed, modified, it is replayed. Allowing emulation of the
746 //No meaningful returns or arguments.
747 int MWRem4xReplay(const char* Cmd
)
750 // static char ArrayTraceZero[] = { '0','0','0','0','0','0','0','0','0' };
751 // static char ArrayTraceOne[] = { '1','1','1','1','1','1','1','1','1' };
752 // //local string variables
753 // char strClockRate[10] = {0x00};
754 // char strAnswer[4] = {0x00};
755 // char strTempBufferMini[2] = {0x00};
756 // //our outbound bit-stream
757 // char strSimulateBitStream[65] = {0x00};
759 // int iClockRate = 0;
762 // int iFirstHeaderOffset = 0x00000000;
763 // int numManchesterDemodBits=0;
765 // bool bInverted = false;
766 // //pointers to strings. memory will be allocated.
767 // char* pstrInvertBitStream = 0x00000000;
768 // char* pTempBuffer = 0x00000000;
769 // char* pID = 0x00000000;
770 // char* strBitStreamBuffer = 0x00000000;
773 // puts("###################################");
774 // puts("#### Em4x Replay ##");
775 // puts("#### R.A.M. June 2013 ##");
776 // puts("###################################");
779 // //Collect ourselves 10,000 samples
780 // CmdSamples("10000");
781 // puts("[->]preforming ASK demodulation\n");
784 // iClockRate = DetectClock(0);
785 // sprintf(strClockRate, "%i\n",iClockRate);
786 // printf("[->]Detected ClockRate: %s\n", strClockRate);
788 // //If detected clock rate is something completely unreasonable, dont go ahead
789 // if ( iClockRate < 0xFFFE )
791 // pTempBuffer = (char*)malloc(MAX_GRAPH_TRACE_LEN);
792 // if (pTempBuffer == 0x00000000)
794 // memset(pTempBuffer,0x00,MAX_GRAPH_TRACE_LEN);
795 // //Preform manchester de-modulation and display in a single line.
796 // numManchesterDemodBits = CmdManchesterDemod( strClockRate );
797 // //note: numManchesterDemodBits is set above in CmdManchesterDemod()
798 // if ( numManchesterDemodBits == 0 )
800 // strBitStreamBuffer = malloc(numManchesterDemodBits+1);
801 // if ( strBitStreamBuffer == 0x00000000 )
803 // memset(strBitStreamBuffer, 0x00, (numManchesterDemodBits+1));
804 // //fill strBitStreamBuffer with demodulated, string formatted bits.
805 // for ( j = 0; j <= numManchesterDemodBits; j++ )
807 // sprintf(strTempBufferMini, "%i",BitStream[j]);
808 // strcat(strBitStreamBuffer,strTempBufferMini);
810 // printf("[->]Demodulated Bitstream: \n%s\n", strBitStreamBuffer);
811 // //Reset counter and select most probable bit stream
813 // while ( j < numManchesterDemodBits )
815 // memset(strSimulateBitStream,0x00,64);
816 // //search for header of nine (9) 0's : 000000000 or nine (9) 1's : 1111 1111 1
817 // if ( ( strncmp(strBitStreamBuffer+j, ArrayTraceZero, sizeof(ArrayTraceZero)) == 0 ) ||
818 // ( strncmp(strBitStreamBuffer+j, ArrayTraceOne, sizeof(ArrayTraceOne)) == 0 ) )
820 // iFirstHeaderOffset = j;
821 // memcpy(strSimulateBitStream, strBitStreamBuffer+j,64);
822 // printf("[->]Offset of Header");
823 // if ( strncmp(strBitStreamBuffer+iFirstHeaderOffset, "0", 1) == 0 )
824 // printf("'%s'", ArrayTraceZero );
826 // printf("'%s'", ArrayTraceOne );
827 // printf(": %i\nHighlighted string : %s\n",iFirstHeaderOffset,strSimulateBitStream);
828 // //allow us to escape loop or choose another frame
829 // puts("[<-]Are we happy with this sample? [Y]es/[N]o");
831 // if ( ( strncmp(strAnswer,"y",1) == 0 ) || ( strncmp(strAnswer,"Y",1) == 0 ) )
833 // j = numManchesterDemodBits+1;
842 // //Do we want the buffer inverted?
843 // memset(strAnswer, 0x00, sizeof(strAnswer));
844 // printf("[<-]Do you wish to invert the highlighted bitstream? [Y]es/[N]o\n");
846 // if ( ( strncmp("y", strAnswer,1) == 0 ) || ( strncmp("Y", strAnswer, 1 ) == 0 ) )
848 // //allocate heap memory
849 // pstrInvertBitStream = (char*)malloc(numManchesterDemodBits);
850 // if ( pstrInvertBitStream != 0x00000000 )
852 // memset(pstrInvertBitStream,0x00,numManchesterDemodBits);
854 // //Invert Bitstream
855 // for ( needle = 0; needle <= numManchesterDemodBits; needle++ )
857 // if (strSimulateBitStream[needle] == '0')
858 // strcat(pstrInvertBitStream,"1");
859 // else if (strSimulateBitStream[needle] == '1')
860 // strcat(pstrInvertBitStream,"0");
862 // printf("[->]Inverted bitstream: %s\n", pstrInvertBitStream);
865 // //Confirm parity of selected string
866 // pID = (char*)malloc(11);
867 // if (pID != 0x00000000)
869 // memset(pID, 0x00, 11);
870 // if (ConfirmEm410xTagParity(strSimulateBitStream,pID, 64) == 1)
872 // printf("[->]Parity confirmed for selected bitstream!\n");
873 // printf("[->]Tag ID was detected as: [hex]:%s\n",pID );
876 // printf("[->]Parity check failed for the selected bitstream!\n");
880 // memset(strAnswer, 0x00, sizeof(strAnswer));
881 // printf("[<-]Do you wish to continue with the EM4x simulation? [Y]es/[N]o\n");
883 // if ( ( strncmp(strAnswer,"y",1) == 0 ) || ( strncmp(strAnswer,"Y",1) == 0 ) )
885 // strcat(pTempBuffer, strClockRate);
886 // strcat(pTempBuffer, " ");
887 // if (bInverted == true)
888 // strcat(pTempBuffer,pstrInvertBitStream);
889 // if (bInverted == false)
890 // strcat(pTempBuffer,strSimulateBitStream);
892 // puts("[->]Starting simulation now: \n");
893 // //Simulate tag with prepared buffer.
894 // CmdLFSimManchester(pTempBuffer);
896 // else if ( ( strcmp("n", strAnswer) == 0 ) || ( strcmp("N", strAnswer ) == 0 ) )
897 // printf("[->]Exiting procedure now...\n");
899 // printf("[->]Erroneous selection\nExiting procedure now....\n");
901 // //Clean up -- Exit function
902 // //clear memory, then release pointer.
903 // if ( pstrInvertBitStream != 0x00000000 )
905 // memset(pstrInvertBitStream,0x00,numManchesterDemodBits);
906 // free(pstrInvertBitStream);
908 // if ( pTempBuffer != 0x00000000 )
910 // memset(pTempBuffer,0x00,MAX_GRAPH_TRACE_LEN);
911 // free(pTempBuffer);
913 // if ( pID != 0x00000000 )
915 // memset(pID,0x00,11);
918 // if ( strBitStreamBuffer != 0x00000000 )
920 // memset(strBitStreamBuffer,0x00,numManchesterDemodBits);
921 // free(strBitStreamBuffer);
926 int CmdLFEM4X(const char *Cmd
)
928 CmdsParse(CommandTable
, Cmd
);
932 int CmdHelp(const char *Cmd
)
934 CmdsHelp(CommandTable
);