From 29ada8fc08807d8b279afee69862c22b71aaad8f Mon Sep 17 00:00:00 2001
From: marshmellow42 <marshmellowrf@gmail.com>
Date: Mon, 7 Mar 2016 01:01:40 -0500
Subject: [PATCH] add ST to ask/manchester sim, finish presco...

...as it is currently understood - need to add base 12 printed ID to
demod output...
add Q5 option to pyramid
fix missing include I mistakenly removed in cmdlf
---
 armsrc/lfops.c        |  18 ++-
 client/cmdlf.c        |   3 +-
 client/cmdlfpresco.c  | 254 ++++++++++++++++++++++++------------------
 client/cmdlfpresco.h  |  20 ++--
 client/cmdlfpyramid.c |  52 +++++----
 client/cmdlfpyramid.h |  11 --
 client/util.h         |   2 +-
 7 files changed, 206 insertions(+), 154 deletions(-)

diff --git a/armsrc/lfops.c b/armsrc/lfops.c
index 610781d2..2079f263 100644
--- a/armsrc/lfops.c
+++ b/armsrc/lfops.c
@@ -645,6 +645,18 @@ static void biphaseSimBit(uint8_t c, int *n, uint8_t clock, uint8_t *phase)
 	*n += clock;
 }
 
+static void stAskSimBit(int *n, uint8_t clock) {
+	uint8_t *dest = BigBuf_get_addr();
+	uint8_t halfClk = clock/2;
+	//ST = .5 high .5 low 1.5 high .5 low 1 high	
+	memset(dest+(*n), 1, halfClk);
+	memset(dest+(*n) + halfClk, 0, halfClk);
+	memset(dest+(*n) + clock, 1, clock + halfClk);
+	memset(dest+(*n) + clock*2 + halfClk, 0, halfClk);
+	memset(dest+(*n) + clock*3, 1, clock);
+	*n += clock*4;
+}
+
 // args clock, ask/man or askraw, invert, transmission separator
 void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
 {
@@ -675,8 +687,10 @@ void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
 			}
 		}
 	}
-	
-	if (separator==1) Dbprintf("sorry but separator option not yet available"); 
+	if (separator==1 && encoding == 1)
+		stAskSimBit(&n, clk);
+	else if (separator==1)
+		Dbprintf("sorry but separator option not yet available");
 
 	Dbprintf("Simulating with clk: %d, invert: %d, encoding: %d, separator: %d, n: %d",clk, invert, encoding, separator, n);
 	//DEBUG
diff --git a/client/cmdlf.c b/client/cmdlf.c
index 22bceda4..245eb224 100644
--- a/client/cmdlf.c
+++ b/client/cmdlf.c
@@ -14,6 +14,7 @@
 #include <limits.h>
 #include "proxmark3.h"
 #include "cmdlf.h"
+#include "lfdemod.h"     // for psk2TOpsk1
 #include "util.h"        // for parsing cli command utils
 #include "ui.h"          // for show graph controls
 #include "graph.h"       // for graph data
@@ -664,7 +665,7 @@ int usage_lf_simask(void)
 	PrintAndLog("       b              sim ask/biphase");
 	PrintAndLog("       m              sim ask/manchester - Default");
 	PrintAndLog("       r              sim ask/raw");
-	PrintAndLog("       s              TBD- -to enable a gap between playback repetitions - default: no gap");
+	PrintAndLog("       s              add t55xx Sequence Terminator gap - default: no gaps (only manchester)");
 	PrintAndLog("       d <hexdata>    Data to sim as hex - omit to sim from DemodBuffer");
 	return 0;
 }
diff --git a/client/cmdlfpresco.c b/client/cmdlfpresco.c
index 20b42bc1..abae165d 100644
--- a/client/cmdlfpresco.c
+++ b/client/cmdlfpresco.c
@@ -9,16 +9,28 @@
 #include <string.h>
 #include <inttypes.h>
 #include "cmdlfpresco.h"
+#include "proxmark3.h"
+#include "ui.h"
+#include "util.h"
+#include "graph.h"
+#include "cmdparser.h"
+#include "cmddata.h"
+#include "cmdmain.h"
+#include "cmdlf.h"
+#include "protocols.h"  // for T55xx config register definitions
+#include "lfdemod.h"    // parityTest
+
 static int CmdHelp(const char *Cmd);
 
 int usage_lf_presco_clone(void){
 	PrintAndLog("clone a Presco tag to a T55x7 tag.");
-	PrintAndLog("Usage: lf presco clone <Card ID - 9 digits> <Q5>");
+	PrintAndLog("Usage: lf presco clone d <Card-ID> H <hex-ID> <Q5>");
 	PrintAndLog("Options :");
-	PrintAndLog("  <Card Number>  : 9 digit presco card number");
-	//PrintAndLog("  <Q5>           : specify write to Q5 (t5555 instead of t55x7)");
+	PrintAndLog("  d <Card-ID>   : 9 digit presco card ID");
+	PrintAndLog("  H <hex-ID>    : 8 digit hex card number");
+	PrintAndLog("  <Q5>          : specify write to Q5 (t5555 instead of t55x7)");
 	PrintAndLog("");
-	PrintAndLog("Sample  : lf presco clone 123456789");
+	PrintAndLog("Sample  : lf presco clone d 123456789");
 	return 0;
 }
 
@@ -27,53 +39,88 @@ int usage_lf_presco_sim(void) {
 	PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
 	PrintAndLog("Per presco format, the card number is 9 digit number and can contain *# chars. Larger values are truncated.");
 	PrintAndLog("");
-	PrintAndLog("Usage:  lf presco sim <Card-Number>");
+	PrintAndLog("Usage:  lf presco sim d <Card-ID> or H <hex-ID>");
 	PrintAndLog("Options :");
-	PrintAndLog("  <Card Number>   : 9 digit presco card number");
+	PrintAndLog("  d <Card-ID>   : 9 digit presco card number");
+	PrintAndLog("  H <hex-ID>    : 8 digit hex card number");
 	PrintAndLog("");
-	PrintAndLog("Sample  : lf presco sim 123456789");
+	PrintAndLog("Sample  : lf presco sim d 123456789");
 	return 0;
 }
 
-// calc checksum
-int GetWiegandFromPresco(const char *id, uint32_t *sitecode, uint32_t *usercode) {
-	
+// convert base 12 ID to sitecode & usercode & 8 bit other unknown code
+int GetWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode, uint32_t *fullcode, bool *Q5) {
+
 	uint8_t val = 0;
-	for (int index =0; index < strlen(id); ++index) {
-		
-		// Get value from number string.
-		if ( id[index] == '*' ) val = 10;
-		if ( id[index] == '#')	val = 11;		
-		if ( id[index] >= 0x30 && id[index] <= 0x39 )
-			val = id[index] - 0x30;
-		
-		*sitecode += val;
-		
-		// last digit is only added, not multipled.
-		if ( index < strlen(id)-1 ) 
-			*sitecode *= 12;
+	bool hex = false, errors = false;
+	uint8_t cmdp = 0;
+	char id[11];
+	int stringlen = 0;
+	while(param_getchar(Cmd, cmdp) != 0x00) {
+		switch(param_getchar(Cmd, cmdp)) {
+			case 'h':
+				return -1;
+			case 'H':
+				hex = true;
+				//get hex
+				*fullcode = param_get32ex(Cmd, cmdp+1, 0, 10);
+				cmdp+=2;
+				break;
+			case 'P':
+			case 'p':
+				//param get string int param_getstr(const char *line, int paramnum, char * str)
+				stringlen = param_getstr(Cmd, cmdp+1, id);
+				if (stringlen < 2) return -1;
+				cmdp+=2;
+				break;
+			case 'Q':
+			case 'q':
+				*Q5 = true;
+				cmdp++;
+				break;
+			default:
+				PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
+				errors = 1;
+				break;
+		}
+		if(errors) break;
 	}
-	*usercode = *sitecode % 65536;
-	*sitecode /= 16777216;
-	return 0;
-}
+	// No args
+	if(cmdp == 0) errors = 1;
 
-int GetPrescoBits(uint32_t sitecode, uint32_t usercode, uint8_t	*prescoBits) {
-	uint8_t pre[66];
-	memset(pre, 0, sizeof(pre));
-	prescoBits[7]=1;
-	num_to_bytebits(26, 8, pre);
+	//Validations
+	if(errors) return -1;
 
-	uint8_t wiegand[24];
-	num_to_bytebits(sitecode, 8, wiegand);
-	num_to_bytebits(usercode, 16, wiegand+8);
+	if (!hex) {
+		for (int index =0; index < strlen(id); ++index) {
+			// Get value from number string.
+			if ( id[index] == '*' ) val = 10;
+			if ( id[index] == '#')	val = 11;		
+			if ( id[index] >= 0x30 && id[index] <= 0x39 )
+				val = id[index] - 0x30;
+			
+			*fullcode += val;
+			
+			// last digit is only added, not multipled.
+			if ( index < strlen(id)-1 ) 
+				*fullcode *= 12;
+		}
+	}
 
-	wiegand_add_parity(pre+8, wiegand, 24);
-	size_t bitLen = addParity(pre, prescoBits+8, 66, 4, 1);
+	*usercode = *fullcode & 0x0000FFFF; //% 65566
+	*sitecode = (*fullcode >> 24) & 0x000000FF;  // /= 16777216;
+	return 0;
+}
 
-	if (bitLen != 88) return 0;
+// calc not certain - intended to get bitstream for programming / sim
+int GetPrescoBits(uint32_t fullcode, uint8_t *prescoBits) {
+	num_to_bytebits(0x10D00000, 32, prescoBits);
+	num_to_bytebits(0x00000000, 32, prescoBits+32);
+	num_to_bytebits(0x00000000, 32, prescoBits+64);
+	num_to_bytebits(fullcode  , 32, prescoBits+96);
 	return 1;
 }
+
 //see ASKDemod for what args are accepted
 int CmdPrescoDemod(const char *Cmd) {
 	if (!ASKDemod(Cmd, false, false, 1)) {
@@ -90,21 +137,26 @@ int CmdPrescoDemod(const char *Cmd) {
 	//got a good demod
 	uint32_t raw1 = bytebits_to_byte(DemodBuffer+ans, 32);
 	uint32_t raw2 = bytebits_to_byte(DemodBuffer+ans+32, 32);
-	uint32_t cardid = bytebits_to_byte(DemodBuffer+ans+24, 32);
+	uint32_t raw3 = bytebits_to_byte(DemodBuffer+ans+64, 32);
+	uint32_t raw4 = bytebits_to_byte(DemodBuffer+ans+96, 32);
+	uint32_t cardid = raw4;
 	PrintAndLog("Presco Tag Found: Card ID %08X", cardid);
-	PrintAndLog("Raw: %08X%08X", raw1,raw2);
-	setDemodBuf(DemodBuffer+ans, 64, 0);
-	
-	// uint32_t sitecode = 0, usercode = 0;
-	// GetWiegandFromPresco(id, &sitecode, &usercode);
-	// PrintAndLog8("SiteCode %d  |  UserCode %d", sitecode, usercode);
+	PrintAndLog("Raw: %08X%08X%08X%08X", raw1,raw2,raw3,raw4);
+	setDemodBuf(DemodBuffer+ans, 128, 0);
 	
+	uint32_t sitecode = 0, usercode = 0, fullcode = 0;
+	bool Q5=false;
+	char cmd[12] = {0};
+	sprintf(cmd, "H %08X", cardid);
+	GetWiegandFromPresco(cmd, &sitecode, &usercode, &fullcode, &Q5);
+	PrintAndLog("SiteCode %u, UserCode %u, FullCode, %08X", sitecode, usercode, fullcode);
+
 	return 1;
 }
 
 //see ASKDemod for what args are accepted
 int CmdPrescoRead(const char *Cmd) {
-	//	Presco Number: 123456789 --> Sitecode 30 | usercode 8665
+	// Presco Number: 123456789 --> Sitecode 30 | usercode 8665
 
 	// read lf silently
 	CmdLFRead("s");
@@ -114,23 +166,20 @@ int CmdPrescoRead(const char *Cmd) {
 	return CmdPrescoDemod(Cmd);
 }
 
+// takes base 12 ID converts to hex
+// Or takes 8 digit hex ID
 int CmdPrescoClone(const char *Cmd) {
 
-	char cmdp = param_getchar(Cmd, 0);
-	if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_presco_clone();
-
-	uint32_t sitecode=0, usercode=0;
-	uint8_t bits[96];
-	uint8_t *bs = bits;
-	memset(bs,0,sizeof(bits));
+	bool Q5 = false;
+	uint32_t sitecode=0, usercode=0, fullcode=0;
 	uint32_t blocks[5] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | 4<<T55x7_MAXBLOCK_SHIFT | T55x7_ST_TERMINATOR, 0, 0, 0, 5};
 	
-	if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
+	// get wiegand from printed number.
+	if (GetWiegandFromPresco(Cmd, &sitecode, &usercode, &fullcode, &Q5) == -1) return usage_lf_presco_clone();
+
+	if (Q5)
 		blocks[0] = T5555_MODULATION_MANCHESTER | 32<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT | T5555_ST_TERMINATOR;
 
-	// get wiegand from printed number.
-	GetWiegandFromPresco(Cmd, &sitecode, &usercode);
-	
 	if ((sitecode & 0xFF) != sitecode) {
 		sitecode &= 0xFF;
 		PrintAndLog("Facility-Code Truncated to 8-bits (Presco): %u", sitecode);
@@ -141,17 +190,12 @@ int CmdPrescoClone(const char *Cmd) {
 		PrintAndLog("Card Number Truncated to 16-bits (Presco): %u", usercode);
 	}
 	
-	if ( !GetPrescoBits(sitecode, usercode, bs)) {
-		PrintAndLog("Error with tag bitstream generation.");
-		return 1;
-	}	
+	blocks[1] = 0x10D00000; //preamble
+	blocks[2] = 0x00000000;
+	blocks[3] = 0x00000000;
+	blocks[4] = fullcode;
 
-	blocks[1] = bytebits_to_byte(bs,32);
-	blocks[2] = bytebits_to_byte(bs+32,32);
-	blocks[3] = bytebits_to_byte(bs+64,32);
-	blocks[4] = bytebits_to_byte(bs+96,32);
-
-	PrintAndLog("Preparing to clone Presco to T55x7 with SiteCode: %u, UserCode: %u", sitecode, usercode);
+	PrintAndLog("Preparing to clone Presco to T55x7 with SiteCode: %u, UserCode: %u, FullCode: %08x", sitecode, usercode, fullcode);
 	PrintAndLog("Blk | Data ");
 	PrintAndLog("----+------------");
 	PrintAndLog(" 00 | 0x%08x", blocks[0]);
@@ -159,56 +203,52 @@ int CmdPrescoClone(const char *Cmd) {
 	PrintAndLog(" 02 | 0x%08x", blocks[2]);
 	PrintAndLog(" 03 | 0x%08x", blocks[3]);	
 	PrintAndLog(" 04 | 0x%08x", blocks[4]);	
-	
-	// UsbCommand resp;
-	// UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
-
-	// for (uint8_t i=0; i<5; i++) {
-		// c.arg[0] = blocks[i];
-		// c.arg[1] = i;
-		// clearCommandBuffer();
-		// SendCommand(&c);
-		// if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
-			// PrintAndLog("Error occurred, device did not respond during write operation.");
-			// return -1;
-		// }
-	// }
-    return 0;
-}
 
-int CmdPrescoSim(const char *Cmd) {
-	// uint32_t id = 0;
-	// uint64_t rawID = 0;
-	// uint8_t clk = 32, encoding = 1, separator = 0, invert = 0;
+	UsbCommand resp;
+	UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
 
-	// char cmdp = param_getchar(Cmd, 0);
-	// if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_presco_sim();
+	for (int i=4; i>=0; i--) {
+		c.arg[0] = blocks[i];
+		c.arg[1] = i;
+		clearCommandBuffer();
+		SendCommand(&c);
+		if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
+			PrintAndLog("Error occurred, device did not respond during write operation.");
+			return -1;
+		}
+	}
+	return 0;
+}
 
-	// id = param_get32ex(Cmd, 0, 0, 16);
-	// if (id == 0) return usage_lf_presco_sim();
+// takes base 12 ID converts to hex
+// Or takes 8 digit hex ID
+int CmdPrescoSim(const char *Cmd) {
+	uint32_t sitecode=0, usercode=0, fullcode=0;
+	bool Q5=false;
+	// get wiegand from printed number.
+	if (GetWiegandFromPresco(Cmd, &sitecode, &usercode, &fullcode, &Q5) == -1) return usage_lf_presco_sim();
 
-	//rawID = getVikingBits(id);
+	uint8_t clk = 32, encoding = 1, separator = 1, invert = 0;
+	uint16_t arg1, arg2;
+	size_t size = 128;
+	arg1 = clk << 8 | encoding;
+	arg2 = invert << 8 | separator;
 
-	// uint16_t arg1, arg2;
-	// size_t size = 64;
-	// arg1 = clk << 8 | encoding;
-	// arg2 = invert << 8 | separator;
+	PrintAndLog("Simulating Presco - SiteCode: %u, UserCode: %u, FullCode: %08X",sitecode, usercode, fullcode);
 
-	// PrintAndLog("Simulating - ID: %08X, Raw: %08X%08X",id,(uint32_t)(rawID >> 32),(uint32_t) (rawID & 0xFFFFFFFF));
-	
-	// UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
-	// num_to_bytebits(rawID, size, c.d.asBytes);
-	// clearCommandBuffer();
-	// SendCommand(&c);
+	UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
+	GetPrescoBits(fullcode, c.d.asBytes);
+	clearCommandBuffer();
+	SendCommand(&c);
 	return 0;
 }
 
 static command_t CommandTable[] = {
-    {"help",	CmdHelp,		1, "This help"},
-	{"read",	CmdPrescoRead,  0, "Attempt to read and Extract tag data"},
-	{"clone",	CmdPrescoClone, 0, "<8 digit ID number> clone presco tag"},
-//	{"sim",		CmdPrescoSim,   0, "<8 digit ID number> simulate presco tag"},
-    {NULL, NULL, 0, NULL}
+	{"help",  CmdHelp,        1, "This help"},
+	{"read",  CmdPrescoRead,  0, "Attempt to read and Extract tag data"},
+	{"clone", CmdPrescoClone, 0, "d <9 digit ID> or h <hex> [Q5] clone presco tag"},
+	{"sim",   CmdPrescoSim,   0, "d <9 digit ID> or h <hex> simulate presco tag"},
+	{NULL, NULL, 0, NULL}
 };
 
 int CmdLFPresco(const char *Cmd) {
diff --git a/client/cmdlfpresco.h b/client/cmdlfpresco.h
index f9cfbd95..801df8a9 100644
--- a/client/cmdlfpresco.h
+++ b/client/cmdlfpresco.h
@@ -8,23 +8,17 @@
 //-----------------------------------------------------------------------------
 #ifndef CMDLFPRESCO_H__
 #define CMDLFPRESCO_H__
-#include "proxmark3.h"
-#include "ui.h"
-#include "util.h"
-#include "graph.h"
-#include "cmdparser.h"
-#include "cmddata.h"
-#include "cmdmain.h"
-#include "cmdlf.h"
-#include "protocols.h"  // for T55xx config register definitions
-#include "lfdemod.h"    // parityTest
+
+#include <stdint.h>  //uint_32+
+#include <stdbool.h> //bool
+
 int CmdLFPresco(const char *Cmd);
 int CmdPrescoClone(const char *Cmd);
-//int CmdPrescoSim(const char *Cmd);
+int CmdPrescoSim(const char *Cmd);
+
+int GetWiegandFromPresco(const char *id, uint32_t *sitecode, uint32_t *usercode, uint32_t *fullcode, bool *Q5);
 
 int usage_lf_presco_clone(void);
 int usage_lf_presco_sim(void);
-
-int GetWiegandFromPresco(const char *id, uint32_t *sitecode, uint32_t *usercode);
 #endif
 
diff --git a/client/cmdlfpyramid.c b/client/cmdlfpyramid.c
index 990dccbb..7c19fbdb 100644
--- a/client/cmdlfpyramid.c
+++ b/client/cmdlfpyramid.c
@@ -9,6 +9,18 @@
 #include <string.h>
 #include <inttypes.h>
 #include "cmdlfpyramid.h"
+#include "proxmark3.h"
+#include "ui.h"
+#include "util.h"
+#include "graph.h"
+#include "cmdparser.h"
+#include "cmddata.h"
+#include "cmdmain.h"
+#include "cmdlf.h"
+#include "protocols.h"  // for T55xx config register definitions
+#include "lfdemod.h"    // parityTest
+#include "crc.h"
+
 static int CmdHelp(const char *Cmd);
 
 int usage_lf_pyramid_clone(void){
@@ -20,6 +32,7 @@ int usage_lf_pyramid_clone(void){
 	PrintAndLog("Options :");
 	PrintAndLog("  <Facility-Code> :  8-bit value facility code");
 	PrintAndLog("  <Card Number>   : 16-bit value card number");
+	PrintAndLog("  Q5              : optional - clone to Q5 (T5555) instead of T55x7 chip");
 	PrintAndLog("");
 	PrintAndLog("Sample  : lf pyramid clone 123 11223");
 	return 0;
@@ -96,13 +109,14 @@ int CmdPyramidClone(const char *Cmd) {
 	if ( !GetPyramidBits(facilitycode, cardnumber, bs)) {
 		PrintAndLog("Error with tag bitstream generation.");
 		return 1;
-	}	
-
-//	if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
-//		blocks[0] = T5555_MODULATION_FSK2 | 50<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT;
+	}
 
 	//Pyramid - compat mode, FSK2a, data rate 50, 4 data blocks
 	blocks[0] = T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 4<<T55x7_MAXBLOCK_SHIFT;
+
+	if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
+		blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 50<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT;
+
 	blocks[1] = bytebits_to_byte(bs,32);
 	blocks[2] = bytebits_to_byte(bs+32,32);
 	blocks[3] = bytebits_to_byte(bs+64,32);
@@ -127,7 +141,7 @@ int CmdPyramidClone(const char *Cmd) {
 			return -1;
 		}
 	}
-    return 0;
+	return 0;
 }
 
 int CmdPyramidSim(const char *Cmd) {
@@ -136,11 +150,11 @@ int CmdPyramidSim(const char *Cmd) {
 	if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_pyramid_sim();
 
 	uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0;
-	
+
 	uint8_t bs[128];
 	size_t size = sizeof(bs);
 	memset(bs, 0x00, size);
-	
+
 	// Pyramid uses:  fcHigh: 10, fcLow: 8, clk: 50, invert: 0
 	uint64_t arg1, arg2;
 	arg1 = (10 << 8) + 8;
@@ -150,14 +164,14 @@ int CmdPyramidSim(const char *Cmd) {
 
 	facilitycode = (fc & 0x000000FF);
 	cardnumber = (cn & 0x0000FFFF);
-	
+
 	if ( !GetPyramidBits(facilitycode, cardnumber, bs)) {
 		PrintAndLog("Error with tag bitstream generation.");
 		return 1;
-	}	
+	}
 
 	PrintAndLog("Simulating Farpointe/Pyramid - Facility Code: %u, CardNumber: %u", facilitycode, cardnumber );
-	
+
 	UsbCommand c = {CMD_FSK_SIM_TAG, {arg1, arg2, size}};
 	memcpy(c.d.asBytes, bs, size);
 	clearCommandBuffer();
@@ -166,20 +180,20 @@ int CmdPyramidSim(const char *Cmd) {
 }
 
 static command_t CommandTable[] = {
-    {"help",	CmdHelp,		1, "This help"},
-	{"read",	CmdPyramidRead,  0, "Attempt to read and extract tag data"},
-	{"clone",	CmdPyramidClone, 0, "<Facility-Code> <Card Number>  clone pyramid tag"},
-	{"sim",		CmdPyramidSim,   0, "<Facility-Code> <Card Number>  simulate pyramid tag"},
-    {NULL, NULL, 0, NULL}
+	{"help",  CmdHelp,         1, "This help"},
+	{"read",  CmdPyramidRead,  0, "Attempt to read and extract tag data"},
+	{"clone", CmdPyramidClone, 0, "<Facility-Code> <Card Number>  clone pyramid tag"},
+	{"sim",   CmdPyramidSim,   0, "<Facility-Code> <Card Number>  simulate pyramid tag"},
+	{NULL, NULL, 0, NULL}
 };
 
 int CmdLFPyramid(const char *Cmd) {
 	clearCommandBuffer();
-    CmdsParse(CommandTable, Cmd);
-    return 0;
+	CmdsParse(CommandTable, Cmd);
+	return 0;
 }
 
 int CmdHelp(const char *Cmd) {
-    CmdsHelp(CommandTable);
-    return 0;
+	CmdsHelp(CommandTable);
+	return 0;
 }
diff --git a/client/cmdlfpyramid.h b/client/cmdlfpyramid.h
index d00b7d06..73e8338a 100644
--- a/client/cmdlfpyramid.h
+++ b/client/cmdlfpyramid.h
@@ -8,17 +8,6 @@
 //-----------------------------------------------------------------------------
 #ifndef CMDLFPYRAMID_H__
 #define CMDLFPYRAMID_H__
-#include "proxmark3.h"
-#include "ui.h"
-#include "util.h"
-#include "graph.h"
-#include "cmdparser.h"
-#include "cmddata.h"
-#include "cmdmain.h"
-#include "cmdlf.h"
-#include "protocols.h"  // for T55xx config register definitions
-#include "lfdemod.h"    // parityTest
-#include "crc.h"
 
 int CmdLFPyramid(const char *Cmd);
 int CmdPyramidClone(const char *Cmd);
diff --git a/client/util.h b/client/util.h
index fd48a26f..34e821bf 100644
--- a/client/util.h
+++ b/client/util.h
@@ -14,7 +14,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <time.h>
-#include "data.h"  //for FILE_PATH_SIZE
+#include "data.h"    //for FILE_PATH_SIZE
 
 #ifndef ROTR
 # define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n))))
-- 
2.39.5