-
-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){
- *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);
+// 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) {
+ // 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:{
+ // 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:
+ // 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;
+ }