+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.
+ if (card->OEM > 0) return false; // Not used in this format
+ 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);
+ 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->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->CardNumber > 0x0000FFFF) return false; // Can't encode CN.
+ if (card->IssueLevel > 0) return false; // Not used in this format
+ if (card->OEM > 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);
+ 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->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;
+}
+
+bool Pack_C15001(/*in*/hidproxcard_t* card, /*out*/hidproxmessage_t* packed){
+ memset(packed, 0, sizeof(hidproxmessage_t));
+ if (card->FacilityCode > 0x000000FF) return false; // Can't encode FC.
+ if (card->CardNumber > 0x0000FFFF) return false; // Can't encode CN.
+ if (card->IssueLevel > 0) return false; // Not used in this format
+ if (card->OEM > 0x000003FF) return false; // Can't encode OEM.
+ packed->Length = 36; // Set number of bits
+ set_linear_field(packed, card->OEM, 1, 10);
+ set_linear_field(packed, card->FacilityCode, 11, 8);
+ set_linear_field(packed, card->CardNumber, 19, 16);
+ set_bit_by_position(packed,
+ evenparity32(get_linear_field(packed, 1, 17))
+ , 0);
+ set_bit_by_position(packed,
+ oddparity32(get_linear_field(packed, 18, 17))
+ , 35);
+ return add_HID_header(packed);
+}
+bool Unpack_C15001(/*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->OEM = get_linear_field(packed, 1, 10);
+ card->FacilityCode = get_linear_field(packed, 11, 8);
+ card->CardNumber = get_linear_field(packed, 19, 16);
+ card->ParityValid =
+ (get_bit_by_position(packed, 0) == evenparity32(get_linear_field(packed, 1, 17))) &&
+ (get_bit_by_position(packed, 35) == oddparity32(get_linear_field(packed, 18, 17)));
+ return true;
+}