+
+ PrintAndLog("Emulating tag with ID %x%16x", hi, lo);
+ PrintAndLog("Press pm3-button to abort simulation");
+
+ UsbCommand c = {CMD_HID_SIM_TAG, {hi, lo, 0}};
+ clearCommandBuffer();
+ SendCommand(&c);
+ return 0;
+}
+
+int CmdHIDClone(const char *Cmd) {
+
+ unsigned int hi2 = 0, hi = 0, lo = 0;
+ int n = 0, i = 0;
+ UsbCommand c;
+
+ uint8_t ctmp = param_getchar(Cmd, 0);
+ if ( strlen(Cmd) == 0 || ctmp == 'H' || ctmp == 'h' ) return usage_lf_hid_clone();
+
+ if (strchr(Cmd,'l') != 0) {
+ while (sscanf(&Cmd[i++], "%1x", &n ) == 1) {
+ hi2 = (hi2 << 4) | (hi >> 28);
+ hi = (hi << 4) | (lo >> 28);
+ lo = (lo << 4) | (n & 0xf);
+ }
+
+ PrintAndLog("Cloning tag with long ID %x%08x%08x", hi2, hi, lo);
+
+ c.d.asBytes[0] = 1;
+ } else {
+ while (sscanf(&Cmd[i++], "%1x", &n ) == 1) {
+ hi = (hi << 4) | (lo >> 28);
+ lo = (lo << 4) | (n & 0xf);
+ }
+
+ PrintAndLog("Cloning tag with ID %x%08x", hi, lo);
+
+ hi2 = 0;
+ c.d.asBytes[0] = 0;
+ }
+
+ c.cmd = CMD_HID_CLONE_TAG;
+ c.arg[0] = hi2;
+ c.arg[1] = hi;
+ c.arg[2] = lo;
+
+ clearCommandBuffer();
+ SendCommand(&c);
+ return 0;
+}
+// struct to handle wiegand
+typedef struct {
+ uint8_t FormatLen;
+ uint8_t SiteCode;
+ uint8_t FacilityCode;
+ uint8_t CardNumber;
+ uint8_t* Wiegand;
+ size_t Wiegand_n;
+ } wiegand_t;
+
+// static void addHIDMarker(uint8_t fmtlen, uint8_t *out) {
+
+// }
+//static void getParity26(uint32_t *hi, uint32_t *lo){
+ // uint32_t result = 0;
+ // int i;
+ // // even parity
+ // for (i = 24;i >= 13;i--)
+ // result ^= (*lo >> i) & 1;
+ // // even parity 26th bit
+ // *lo |= result << 25;
+
+ // // odd parity
+ // result = 0;
+ // for (i = 12;i >= 1;i--)
+ // result ^= (*lo >> i) & 1;
+ // *lo |= !result;
+//}
+
+// static void getParity33(uint32_t *hi, uint32_t *lo){
+
+// }
+// static void getParity34(uint32_t *hi, uint32_t *lo){
+ // uint32_t result = 0;
+ // int i;
+
+ // // even parity
+ // for (i = 7;i >= 0;i--)
+ // result ^= (*hi >> i) & i;
+ // for (i = 31;i >= 24;i--)
+ // result ^= (*lo >> i) & 1;
+
+ // *hi |= result << 2;
+
+ // // odd parity bit
+ // result = 0;
+ // for (i = 23;i >= 1;i--)
+ // result ^= (*lo >> i) & 1;
+
+ // *lo |= !result;
+// }
+// static void getParity35(uint32_t *hi, uint32_t *lo){
+// }
+// static void getParity37S(uint32_t *hi,uint32_t *lo){
+ // uint32_t result = 0;
+ // int i;
+
+ // // even parity
+ // for (i = 4; i >= 0; i--)
+ // result ^= (*hi >> i) & 1;
+
+ // for (i = 31; i >= 20; i--)
+ // result ^= (*lo >> i) & 1;
+
+ // *hi |= result;
+
+ // // odd parity
+ // result = 0;
+ // for (i = 19; i >= 1; i--)
+ // result ^= (*lo >> i) & 1;
+
+ // *lo |= result;
+// }
+// static void getParity37H(uint32_t *hi, uint32_t *lo){
+ // uint32_t result = 0;
+ // int i;
+
+ // // even parity
+ // for (i = 4;i >= 0;i--)
+ // result ^= (*hi >> i) & 1;
+ // for (i = 31;i >= 20;i--)
+ // result ^= (*lo >> i) & 1;
+ // *hi |= result << 4;
+
+ // // odd parity
+ // result = 0;
+ // for (i = 19;i >= 1;i--)
+ // result ^= (*lo >> i) & 1;
+ // *lo |= result;
+// }
+
+//static void calc26(uint16_t fc, uint32_t cardno, uint32_t *hi, uint32_t *lo){
+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) );
+
+// *out |= (1 << 26); // why this?
+// *out |= (1 << 37); // bit format for hid?