X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/a0a61c91ccefed75187e810cca0e3bcb319ecdcf..c6e5c7ea46eae6180eee3eb592a291257a0400b1:/client/cmdlfhid.c diff --git a/client/cmdlfhid.c b/client/cmdlfhid.c index 3abbfdec..6ed6c4fd 100644 --- a/client/cmdlfhid.c +++ b/client/cmdlfhid.c @@ -10,6 +10,10 @@ #include "cmdlfhid.h" +#ifndef BITS +# define BITS 96 +#endif + static int CmdHelp(const char *Cmd); int usage_lf_hid_wiegand(void){ @@ -97,7 +101,7 @@ static bool sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, ui } int CmdHIDDemodFSK(const char *Cmd) { - int findone = ( Cmd[0] == '1' ) ? 1 : 0; + uint8_t findone = ( Cmd[0] == '1' ) ? 1 : 0; UsbCommand c = {CMD_HID_DEMOD_FSK, {findone, 0 , 0}}; clearCommandBuffer(); SendCommand(&c); @@ -175,17 +179,31 @@ typedef struct { size_t Wiegand_n; } wiegand_t; -static void addHIDMarker(uint8_t fmtlen, uint8_t *out) { - +static void addHIDMarker(uint8_t fmtlen, uint8_t *out) { + // temp array + uint8_t arr[BITS]; + memset(arr, 0, BITS); + + // copy inpu + uint8_t pos = sizeof(arr)-fmtlen; + memcpy(arr+pos, out, fmtlen); + switch(fmtlen) { - case 26: - //*out |= (1 << 26); // why this? - //*out |= (1 << 37); // bit format for hid? + case 26:{ + // start sentinel, BITS-bit 27 = 1 + arr[BITS-27] = 1; + // fmt smaller than 37 used, bit37 = 1 + arr[BITS-38] = 1; + memcpy(out, arr, BITS); break; + } case 34: - // set bit format for less than 37 bit format - // 5+32= 1 - //*hi = (1 << 5) | (fc >> 15); + // start sentinel, BITS-bit 27 = 1 + arr[BITS-35] = 1; + + // fmt smaller than 37 used, bit37 = 1 + arr[BITS-38] = 1; + memcpy(out, arr, BITS); break; default:break; } @@ -228,14 +246,14 @@ static void addHIDMarker(uint8_t fmtlen, uint8_t *out) { // *lo |= result; // } -//static void calc26(uint16_t fc, uint32_t cardno, uint32_t *hi, uint32_t *lo){ +//static void calc26(uint16_t fc, uint32_t cardno, uint8_t *out){ static void calc26(uint16_t fc, uint32_t cardno, uint8_t *out){ uint8_t wiegand[24]; num_to_bytebits(fc, 8, wiegand); num_to_bytebits(cardno, 16, wiegand+8); wiegand_add_parity(out, wiegand, sizeof(wiegand) ); } -// static void calc33(uint16_t fc, uint32_t cardno, uint32_t *hi, uint32_t *lo){ +// static void calc33(uint16_t fc, uint32_t cardno, uint8_t *out){ // } static void calc34(uint16_t fc, uint32_t cardno, uint8_t *out){ uint8_t wiegand[32]; @@ -243,7 +261,7 @@ static void calc34(uint16_t fc, uint32_t cardno, uint8_t *out){ num_to_bytebits(cardno, 16, wiegand + 16); wiegand_add_parity(out, wiegand, sizeof(wiegand) ); } -// static void calc35(uint16_t fc, uint32_t cardno, uint32_t *hi, uint32_t *lo){ +// static void calc35(uint16_t fc, uint32_t cardno, uint8_t *out){ // *lo = ((cardno & 0xFFFFF) << 1) | fc << 21; // *hi = (1 << 5) | ((fc >> 11) & 1); // } @@ -269,47 +287,22 @@ static void calc37H(uint64_t cardno, uint8_t *out){ printf("%x %x\n", (uint32_t)(cardno >> 32), (uint32_t)cardno ); } -// static void calc40(uint64_t cardno, uint32_t *hi, uint32_t *lo){ +// static void calc40(uint64_t cardno, uint8_t *out){ // cardno = (cardno & 0xFFFFFFFFFF); // *lo = ((cardno & 0xFFFFFFFF) << 1 ); // *hi = (cardno >> 31); // } void calcWiegand(uint8_t fmtlen, uint16_t fc, uint64_t cardno, uint8_t *bits){ - - // uint32_t hi = 0, lo = 0; uint32_t cn32 = (cardno & 0xFFFFFFFF); switch ( fmtlen ) { - case 26 : { - calc26(fc, cn32, bits); - //addHIDFormatMarker(fmtlen, bits); - break; - } - // case 33 : { - // // calc33(fc, cn32, hi, lo); - // // getParity33(hi, lo); - // break; - // } - case 34 : { - calc34(fc, cn32, bits); - //addHIDFormatMarker(fmtlen, bits); - break; - } - // case 35 : { - // calc35(fc, cn32, hi, lo); - // getParity35(hi, lo); - // break; - // } - case 37 : { - calc37S(fc, cn32, bits); - //addHIDFormatMarker(fmtlen, bits); - break; - } - case 38 : { - calc37H(cardno, bits); - break; - } - // case 40 : calc40(cardno, hi, lo); break; + case 26: calc26(fc, cn32, bits); break; + // case 33 : calc33(fc, cn32, bits); break; + case 34: calc34(fc, cn32, bits); break; + // case 35 : calc35(fc, cn32, bits); break; + case 37: calc37S(fc, cn32, bits); break; + case 38: calc37H(cardno, bits); break; + // case 40 : calc40(cardno, bits); break; // case 44 : { break; } // case 84 : { break; } default: break; @@ -321,7 +314,7 @@ int CmdHIDWiegand(const char *Cmd) { uint64_t cardnum = 0; uint64_t blocks = 0, wiegand = 0; - uint8_t bits[96]; + uint8_t bits[BITS]; uint8_t *bs = bits; memset(bs, 0, sizeof(bits)); @@ -339,12 +332,16 @@ int CmdHIDWiegand(const char *Cmd) { for (uint8_t i = 0; i < sizeof(fmtlen); i++){ memset(bits, 0x00, sizeof(bits)); calcWiegand( fmtlen[i], fc, cardnum, bs); + printf("ice:: %s \n", sprint_bin(bs, fmtlen[i])); wiegand = (uint64_t)bytebits_to_byte(bs, 32) << 32 | bytebits_to_byte(bs+32, 32); - blocks = (uint64_t)bytebits_to_byte(bs, 32) << 32 | bytebits_to_byte(bs+32, 32); + + addHIDMarker(fmtlen[i], bs); + printf("ice:: %s\n", sprint_bin(bs, BITS)); + blocks = (uint64_t)bytebits_to_byte(bs+32, 32) << 32 | bytebits_to_byte(bs+64, 32); uint8_t shifts = 64-fmtlen[i]; wiegand >>= shifts; - PrintAndLog(" %u | %03u | %03u | %llu | %llX | %llX", + PrintAndLog(" %u | %03u | %03u | %" PRIu64 " | %" PRIX64 " | %" PRIX64 , fmtlen[i], oem, fc,