+ c.cmd = CMD_HID_CLONE_TAG;
+ c.arg[0] = hi2;
+ c.arg[1] = hi;
+ c.arg[2] = lo;
+
+ clearCommandBuffer();
+ SendCommand(&c);
+ return 0;
+}
+
+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 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){
+ *hi = *hi;
+}
+static void getParity37S(uint32_t *hi,uint32_t *lo){
+ uint32_t result = 0;
+ uint8_t 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){
+ *lo = ((cardno & 0xFFFF) << 1) | ((fc & 0xFF) << 17) | (1 << 26);
+ *hi = (1 << 5);
+}
+static void calc34(uint16_t fc, uint32_t cardno, uint32_t *hi, uint32_t *lo){
+ // put card number first bit 1 .. 20 //
+ *lo = ((cardno & 0X000F7FFF) << 1) | ((fc & 0XFFFF) << 17);
+ // set bit format for less than 37 bit format
+ *hi = (1 << 5) | (fc >> 15);
+}
+static void calc35(uint16_t fc, uint32_t cardno, uint32_t *hi, uint32_t *lo){
+ *lo = ((cardno & 0xFFFFF) << 1) | fc << 21;
+ *hi = (1 << 5) | ((fc >> 11) & 1);
+}
+static void calc37S(uint16_t sc, uint32_t cn, uint32_t *hi, uint32_t *lo){
+ // SC 2 - 17 - 16 bit
+ // CN 18 - 36 - 19 bit
+ // Even P1 1 - 19
+ // Odd P37 19 - 36
+
+ sc = sc & 0xFFFF;
+ *lo = ( (sc << 20) | (cn & 0x7FFFF) << 1);
+ *hi = (sc >> 12);
+}
+static void calc37H(uint64_t cn, uint32_t *hi, uint32_t *lo){
+ // SC NONE
+ // CN 1-35 34 bits
+ // Even Parity 0th bit 1-18
+ // Odd Parity 36th bit 19-35
+ cn = (cn & 0x00000003FFFFFFFF);
+ *lo = (cn << 1);
+ *hi = (cn >> 31);
+}
+static void calc40(uint64_t cn, uint32_t *hi, uint32_t *lo){
+ cn = (cn & 0xFFFFFFFFFF);
+ *lo = ((cn & 0xFFFFFFFF) << 1 );
+ *hi = (cn >> 31);