CHG: lf hid wiegand got some love. Still not correct.

This commit is contained in:
iceman1001 2017-02-07 22:27:28 +01:00
parent bd94b97883
commit 464f6dc571

View file

@ -10,6 +10,10 @@
#include "cmdlfhid.h" #include "cmdlfhid.h"
#ifndef BITS
# define BITS 96
#endif
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
int usage_lf_hid_wiegand(void){ 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 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}}; UsbCommand c = {CMD_HID_DEMOD_FSK, {findone, 0 , 0}};
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
@ -176,22 +180,30 @@ typedef struct {
} wiegand_t; } 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) { switch(fmtlen) {
case 26:{ case 26:{
uint8_t len = 37; // start sentinel, BITS-bit 27 = 1
uint8_t tmp[len]; arr[BITS-27] = 1;
memset(tmp, 0, len); // fmt smaller than 37 used, bit37 = 1
uint8_t idx = 37-fmtlen; arr[BITS-38] = 1;
memcpy(tmp+idx, out, fmtlen); memcpy(out, arr, BITS);
tmp[idx] = 1; // start sentinel?
tmp[0] = 1; // bit indicates that a format smaller than 37 is used
memcpy(out, tmp, len);
break; break;
} }
case 34: case 34:
// set bit format for less than 37 bit format // start sentinel, BITS-bit 27 = 1
// 5+32= 1 arr[BITS-35] = 1;
//*hi = (1 << 5) | (fc >> 15);
// fmt smaller than 37 used, bit37 = 1
arr[BITS-38] = 1;
memcpy(out, arr, BITS);
break; break;
default:break; default:break;
} }
@ -302,7 +314,7 @@ int CmdHIDWiegand(const char *Cmd) {
uint64_t cardnum = 0; uint64_t cardnum = 0;
uint64_t blocks = 0, wiegand = 0; uint64_t blocks = 0, wiegand = 0;
uint8_t bits[96]; uint8_t bits[BITS];
uint8_t *bs = bits; uint8_t *bs = bits;
memset(bs, 0, sizeof(bits)); memset(bs, 0, sizeof(bits));
@ -320,12 +332,12 @@ int CmdHIDWiegand(const char *Cmd) {
for (uint8_t i = 0; i < sizeof(fmtlen); i++){ for (uint8_t i = 0; i < sizeof(fmtlen); i++){
memset(bits, 0x00, sizeof(bits)); memset(bits, 0x00, sizeof(bits));
calcWiegand( fmtlen[i], fc, cardnum, bs); calcWiegand( fmtlen[i], fc, cardnum, bs);
printf("ice:: %s", sprint_bin(bs, fmtlen[i])); printf("ice:: %s \n", sprint_bin(bs, fmtlen[i]));
wiegand = (uint64_t)bytebits_to_byte(bs, 32) << 32 | bytebits_to_byte(bs+32, 32); wiegand = (uint64_t)bytebits_to_byte(bs, 32) << 32 | bytebits_to_byte(bs+32, 32);
addHIDMarker(fmtlen[i], bs); addHIDMarker(fmtlen[i], bs);
printf("ice:: %s", sprint_bin(bs, 37)); printf("ice:: %s\n", sprint_bin(bs, BITS));
blocks = (uint64_t)bytebits_to_byte(bs, 32) << 32 | bytebits_to_byte(bs+32, 32); blocks = (uint64_t)bytebits_to_byte(bs+32, 32) << 32 | bytebits_to_byte(bs+64, 32);
uint8_t shifts = 64-fmtlen[i]; uint8_t shifts = 64-fmtlen[i];
wiegand >>= shifts; wiegand >>= shifts;