+bool Pack_S12906(/*in*/hidproxcard_t* card, /*out*/hidproxmessage_t* packed){
+ memset(packed, 0, sizeof(hidproxmessage_t));
+ if (card->FacilityCode > 0xFF) return false; // Can't encode FC.
+ if (card->IssueLevel > 0x03) return false; // Can't encode IL.
+ if (card->CardNumber > 0x00FFFFFF) return false; // Can't encode CN.
+
+ packed->Length = 36; // Set number of bits
+ set_linear_field(packed, card->FacilityCode, 1, 8);
+ set_linear_field(packed, card->IssueLevel, 9, 2);
+ set_linear_field(packed, card->CardNumber, 11, 24);
+ if (card->ParitySupported){
+ set_bit_by_position(packed,
+ oddparity32(get_linear_field(packed, 1, 17))
+ , 0);
+ set_bit_by_position(packed,
+ oddparity32(get_linear_field(packed, 17, 18))
+ , 35);
+ }
+ return add_HID_header(packed);
+}
+bool Unpack_S12906(/*in*/hidproxmessage_t* packed, /*out*/hidproxcard_t* card){
+ memset(card, 0, sizeof(hidproxcard_t));
+ if (packed->Length != 36) return false; // Wrong length? Stop here.
+
+ card->FacilityCode = get_linear_field(packed, 1, 8);
+ card->IssueLevel = get_linear_field(packed, 9, 2);
+ card->CardNumber = get_linear_field(packed, 11, 24);
+
+ card->ParitySupported = true;
+ card->ParityValid =
+ (get_bit_by_position(packed, 0) == oddparity32(get_linear_field(packed, 1, 17))) &&
+ (get_bit_by_position(packed, 35) == oddparity32(get_linear_field(packed, 17, 18)));
+
+ return true;
+}
+
+bool Pack_Sie36(/*in*/hidproxcard_t* card, /*out*/hidproxmessage_t* packed){
+ memset(packed, 0, sizeof(hidproxmessage_t));
+ if (card->FacilityCode > 0x0003FFFF) return false; // Can't encode FC.
+ if (card->IssueLevel > 0x00) return false; // Can't encode IL.
+ if (card->CardNumber > 0x0000FFFF) return false; // Can't encode CN.
+ if (card->IssueLevel > 0) return false; // Not used in this format
+
+ packed->Length = 36; // Set number of bits
+ set_linear_field(packed, card->FacilityCode, 1, 18);
+ set_linear_field(packed, card->CardNumber, 19, 16);
+ if (card->ParitySupported){
+ set_bit_by_position(packed,
+ oddparity32(get_nonlinear_field(packed, 23, (uint8_t[]){1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19, 21, 22, 24, 25, 27, 28, 30, 31, 33, 34}))
+ , 0);
+ set_bit_by_position(packed,
+ evenparity32(get_nonlinear_field(packed, 23, (uint8_t[]){1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29, 31, 32, 34}))
+ , 35);
+ }
+ return add_HID_header(packed);
+}
+bool Unpack_Sie36(/*in*/hidproxmessage_t* packed, /*out*/hidproxcard_t* card){
+ memset(card, 0, sizeof(hidproxcard_t));
+ if (packed->Length != 36) return false; // Wrong length? Stop here.
+
+ card->FacilityCode = get_linear_field(packed, 1, 18);
+ card->CardNumber = get_linear_field(packed, 19, 16);
+
+ card->ParitySupported = true;
+ card->ParityValid =
+ (get_bit_by_position(packed, 0) == oddparity32(get_nonlinear_field(packed, 23, (uint8_t[]){1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19, 21, 22, 24, 25, 27, 28, 30, 31, 33, 34}))) &&
+ (get_bit_by_position(packed, 35) == oddparity32(get_nonlinear_field(packed, 23, (uint8_t[]){1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29, 31, 32, 34})));
+
+ return true;
+}
+