make style

This commit is contained in:
Philippe Teuwen
2019-03-10 00:00:59 +01:00
parent 0d9223a547
commit 0373696662
483 changed files with 56514 additions and 52451 deletions

View File

@@ -11,7 +11,8 @@
static int CmdHelp(const char *Cmd);
int usage_lf_guard_clone(void){
int usage_lf_guard_clone(void)
{
PrintAndLogEx(NORMAL, "clone a Guardall tag to a T55x7 tag.");
PrintAndLogEx(NORMAL, "The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated. ");
PrintAndLogEx(NORMAL, "Currently work only on 26bit");
@@ -27,7 +28,8 @@ int usage_lf_guard_clone(void){
return 0;
}
int usage_lf_guard_sim(void) {
int usage_lf_guard_sim(void)
{
PrintAndLogEx(NORMAL, "Enables simulation of Guardall card with specified card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated.");
@@ -45,7 +47,8 @@ int usage_lf_guard_sim(void) {
}
// Works for 26bits.
int GetGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits) {
int GetGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits)
{
uint8_t xorKey = 0x66;
uint8_t i;
@@ -69,7 +72,7 @@ int GetGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits) {
uint8_t wiegand[34];
memset(wiegand, 0x00, sizeof(wiegand));
num_to_bytebits(fc, 8, wiegand);
num_to_bytebits(cn, 26, wiegand+8);
num_to_bytebits(cn, 26, wiegand + 8);
// add wiegand parity bits (dest, source, len)
wiegand_add_parity(pre, wiegand, 34);
@@ -86,7 +89,7 @@ int GetGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits) {
uint8_t wiegand[24];
memset(wiegand, 0x00, sizeof(wiegand));
num_to_bytebits(fc, 8, wiegand);
num_to_bytebits(cn, 16, wiegand+8);
num_to_bytebits(cn, 16, wiegand + 8);
// add wiegand parity bits (dest, source, len)
wiegand_add_parity(pre, wiegand, 24);
@@ -105,7 +108,7 @@ int GetGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits) {
// add wiegand to rawbytes
for (i = 0; i < 4; ++i)
rawbytes[i+4] = bytebits_to_byte( pre + (i*8), 8);
rawbytes[i + 4] = bytebits_to_byte(pre + (i * 8), 8);
PrintAndLogEx(DEBUG, " WIE | %s\n", sprint_hex(rawbytes, sizeof(rawbytes)));
@@ -118,14 +121,14 @@ int GetGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits) {
// convert rawbytes to bits in pre
for (i = 0; i < 12; ++i)
num_to_bytebitsLSBF( rawbytes[i], 8, pre + (i*8));
num_to_bytebitsLSBF(rawbytes[i], 8, pre + (i * 8));
PrintAndLogEx(DEBUG, "\n Raw | %s \n", sprint_hex(rawbytes, sizeof(rawbytes)));
PrintAndLogEx(DEBUG, " Raw | %s\n", sprint_bin(pre, 64) );
PrintAndLogEx(DEBUG, " Raw | %s\n", sprint_bin(pre, 64));
// add spacer bit 0 every 4 bits, starting with index 0,
// 12 bytes, 24 nibbles. 24+1 extra bites. 3bytes. ie 9bytes | 1byte xorkey, 8bytes rawdata (64bits, should be enough for a 40bit wiegand)
addParity(pre, guardBits+6, 64, 5, 3);
addParity(pre, guardBits + 6, 64, 5, 3);
// preamble
guardBits[0] = 1;
@@ -135,7 +138,7 @@ int GetGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits) {
guardBits[4] = 1;
guardBits[5] = 0;
PrintAndLogEx(DEBUG, " FIN | %s\n", sprint_bin(guardBits, 96) );
PrintAndLogEx(DEBUG, " FIN | %s\n", sprint_bin(guardBits, 96));
return 1;
}
@@ -144,22 +147,23 @@ int GetGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits) {
// error returns as -x
// success returns start position in bitstream
// Bitstream must contain previously askrawdemod and biphasedemoded data
int detectGProxII(uint8_t *bits, size_t *size) {
int detectGProxII(uint8_t *bits, size_t *size)
{
size_t startIdx = 0;
uint8_t preamble[] = {1,1,1,1,1,0};
uint8_t preamble[] = {1, 1, 1, 1, 1, 0};
// sanity check
if ( *size < sizeof(preamble) ) return -1;
if (*size < sizeof(preamble)) return -1;
if (!preambleSearch(bits, preamble, sizeof(preamble), size, &startIdx))
return -2; //preamble not found
//gProxII should be 96 bits
//gProxII should be 96 bits
if (*size != 96) return -3;
//check first 6 spacer bits to verify format
if (!bits[startIdx+5] && !bits[startIdx+10] && !bits[startIdx+15] && !bits[startIdx+20] && !bits[startIdx+25] && !bits[startIdx+30]){
if (!bits[startIdx + 5] && !bits[startIdx + 10] && !bits[startIdx + 15] && !bits[startIdx + 20] && !bits[startIdx + 25] && !bits[startIdx + 30]) {
//confirmed proper separator bits found
//return start position
return (int) startIdx;
@@ -172,7 +176,8 @@ int detectGProxII(uint8_t *bits, size_t *size) {
//WARNING: if it fails during some points it will destroy the DemodBuffer data
// but will leave the GraphBuffer intact.
//if successful it will push askraw data back to demod buffer ready for emulation
int CmdGuardDemod(const char *Cmd) {
int CmdGuardDemod(const char *Cmd)
{
//Differential Biphase
//get binary from ask wave
@@ -184,7 +189,7 @@ int CmdGuardDemod(const char *Cmd) {
size_t size = DemodBufferLen;
int preambleIndex = detectGProxII(DemodBuffer, &size);
if (preambleIndex < 0){
if (preambleIndex < 0) {
if (preambleIndex == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - gProxII too few bits found");
@@ -216,36 +221,36 @@ int CmdGuardDemod(const char *Cmd) {
// get key and then get all 8 bytes of payload decoded
xorKey = (uint8_t)bytebits_to_byteLSBF(bits_no_spacer, 8);
for (size_t idx = 0; idx < 8; idx++) {
ByteStream[idx] = ((uint8_t)bytebits_to_byteLSBF(bits_no_spacer+8 + (idx*8),8)) ^ xorKey;
ByteStream[idx] = ((uint8_t)bytebits_to_byteLSBF(bits_no_spacer + 8 + (idx * 8), 8)) ^ xorKey;
PrintAndLogEx(DEBUG, "DEBUG: gProxII byte %u after xor: %02x", (unsigned int)idx, ByteStream[idx]);
}
setDemodBuf(DemodBuffer, 96, preambleIndex);
setClockGrid(g_DemodClock, g_DemodStartIdx + (preambleIndex*g_DemodClock));
setClockGrid(g_DemodClock, g_DemodStartIdx + (preambleIndex * g_DemodClock));
//ByteStream contains 8 Bytes (64 bits) of decrypted raw tag data
uint8_t fmtLen = ByteStream[0] >> 2;
uint32_t FC = 0;
uint32_t Card = 0;
//get raw 96 bits to print
uint32_t raw1 = bytebits_to_byte(DemodBuffer,32);
uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32);
uint32_t raw2 = bytebits_to_byte(DemodBuffer + 32, 32);
uint32_t raw3 = bytebits_to_byte(DemodBuffer + 64, 32);
bool unknown = false;
switch(fmtLen) {
switch (fmtLen) {
case 36:
FC = ((ByteStream[3] & 0x7F)<<7) | (ByteStream[4]>>1);
Card = ((ByteStream[4]&1)<<19) | (ByteStream[5]<<11) | (ByteStream[6]<<3) | (ByteStream[7]>>5);
FC = ((ByteStream[3] & 0x7F) << 7) | (ByteStream[4] >> 1);
Card = ((ByteStream[4] & 1) << 19) | (ByteStream[5] << 11) | (ByteStream[6] << 3) | (ByteStream[7] >> 5);
break;
case 26:
FC = ((ByteStream[3] & 0x7F)<<1) | (ByteStream[4]>>7);
Card = ((ByteStream[4]&0x7F)<<9) | (ByteStream[5]<<1) | (ByteStream[6]>>7);
FC = ((ByteStream[3] & 0x7F) << 1) | (ByteStream[4] >> 7);
Card = ((ByteStream[4] & 0x7F) << 9) | (ByteStream[5] << 1) | (ByteStream[6] >> 7);
break;
default :
unknown = true;
break;
}
if ( !unknown)
if (!unknown)
PrintAndLogEx(SUCCESS, "G-Prox-II Found: Format Len: %ubit - FC: %u - Card: %u, Raw: %08x%08x%08x", fmtLen, FC, Card, raw1, raw2, raw3);
else
PrintAndLogEx(SUCCESS, "Unknown G-Prox-II Fmt Found: Format Len: %u, Raw: %08x%08x%08x", fmtLen, raw1, raw2, raw3);
@@ -253,12 +258,14 @@ int CmdGuardDemod(const char *Cmd) {
return 1;
}
int CmdGuardRead(const char *Cmd) {
int CmdGuardRead(const char *Cmd)
{
lf_read(true, 10000);
return CmdGuardDemod(Cmd);
}
int CmdGuardClone(const char *Cmd) {
int CmdGuardClone(const char *Cmd)
{
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_guard_clone();
@@ -271,13 +278,13 @@ int CmdGuardClone(const char *Cmd) {
//GuardProxII - compat mode, ASK/Biphase, data rate 64, 3 data blocks
uint32_t blocks[4] = {T55x7_MODULATION_BIPHASE | T55x7_BITRATE_RF_64 | 3 << T55x7_MAXBLOCK_SHIFT, 0, 0, 0};
if (sscanf(Cmd, "%u %u %u", &fmtlen, &fc, &cn ) != 3) return usage_lf_guard_clone();
if (sscanf(Cmd, "%u %u %u", &fmtlen, &fc, &cn) != 3) return usage_lf_guard_clone();
fmtlen &= 0x7f;
facilitycode = (fc & 0x000000FF);
cardnumber = (cn & 0x0000FFFF);
if ( !GetGuardBits(fmtlen, facilitycode, cardnumber, bs)) {
if (!GetGuardBits(fmtlen, facilitycode, cardnumber, bs)) {
PrintAndLogEx(WARNING, "Error with tag bitstream generation.");
return 1;
}
@@ -294,14 +301,14 @@ int CmdGuardClone(const char *Cmd) {
print_blocks(blocks, 4);
UsbCommand resp;
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}};
for ( i = 0; i<4; ++i ) {
for (i = 0; i < 4; ++i) {
c.arg[0] = blocks[i];
c.arg[1] = i;
clearCommandBuffer();
SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)){
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
return -1;
}
@@ -309,7 +316,8 @@ int CmdGuardClone(const char *Cmd) {
return 0;
}
int CmdGuardSim(const char *Cmd) {
int CmdGuardSim(const char *Cmd)
{
// Guard uses: clk: 64, invert: 0, encoding: 2 (ASK Biphase)
uint8_t clock = 64, encoding = 2, separator = 0, invert = 0;
@@ -318,7 +326,7 @@ int CmdGuardSim(const char *Cmd) {
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_guard_sim();
if (sscanf(Cmd, "%u %u %u", &fmtlen, &fc, &cn ) != 3) return usage_lf_guard_sim();
if (sscanf(Cmd, "%u %u %u", &fmtlen, &fc, &cn) != 3) return usage_lf_guard_sim();
uint8_t bs[96];
size_t size = sizeof(bs);
@@ -328,19 +336,19 @@ int CmdGuardSim(const char *Cmd) {
facilitycode = (fc & 0x000000FF);
cardnumber = (cn & 0x0000FFFF);
if ( !GetGuardBits(fmtlen, facilitycode, cardnumber, bs)) {
if (!GetGuardBits(fmtlen, facilitycode, cardnumber, bs)) {
PrintAndLogEx(WARNING, "Error with tag bitstream generation.");
return 1;
}
PrintAndLogEx(SUCCESS, "Simulating Guardall - Facility Code: %u, CardNumber: %u", facilitycode, cardnumber );
PrintAndLogEx(SUCCESS, "Simulating Guardall - Facility Code: %u, CardNumber: %u", facilitycode, cardnumber);
uint64_t arg1, arg2;
arg1 = (clock << 8) | encoding;
arg2 = (invert << 8) | separator;
UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
memcpy(c.d.asBytes, bs, size );
memcpy(c.d.asBytes, bs, size);
clearCommandBuffer();
SendCommand(&c);
return 0;
@@ -355,13 +363,15 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFGuard(const char *Cmd) {
int CmdLFGuard(const char *Cmd)
{
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd) {
int CmdHelp(const char *Cmd)
{
CmdsHelp(CommandTable);
return 0;
}