textual
[RRG-proxmark3.git] / client / src / wiegand_formatutils.h
blob3709f2e003f6fb5b9a1b366c3ada086efd4b2e73
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2018 grauerfuchs
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // Weigand card format packing/unpacking support functions
9 //-----------------------------------------------------------------------------
11 #ifndef WIEGAND_FORMATUTILS_H__
12 #define WIEGAND_FORMATUTILS_H__
14 #include <stdarg.h>
15 #include <stdint.h>
16 #include <stdbool.h>
18 // Structure for packed wiegand messages
19 // Always align lowest value (last transmitted) bit to ordinal position 0 (lowest valued bit bottom)
20 typedef struct {
21 uint8_t Length; // Number of encoded bits in wiegand message (excluding headers and preamble)
22 uint32_t Top; // Bits in x<<64 positions
23 uint32_t Mid; // Bits in x<<32 positions
24 uint32_t Bot; // Lowest ordinal positions
25 } wiegand_message_t;
27 // Structure for unpacked wiegand card, like HID prox
28 typedef struct {
29 uint32_t FacilityCode;
30 uint64_t CardNumber;
31 uint32_t IssueLevel;
32 uint32_t OEM;
33 bool ParityValid; // Only valid for responses
34 } wiegand_card_t;
36 uint8_t get_bit_by_position(wiegand_message_t *data, uint8_t pos);
37 bool set_bit_by_position(wiegand_message_t *data, bool value, uint8_t pos);
39 uint64_t get_linear_field(wiegand_message_t *data, uint8_t firstBit, uint8_t length);
40 bool set_linear_field(wiegand_message_t *data, uint64_t value, uint8_t firstBit, uint8_t length);
42 uint64_t get_nonlinear_field(wiegand_message_t *data, uint8_t numBits, uint8_t *bits);
43 bool set_nonlinear_field(wiegand_message_t *data, uint64_t value, uint8_t numBits, uint8_t *bits);
45 wiegand_message_t initialize_message_object(uint32_t top, uint32_t mid, uint32_t bot, int n);
47 bool add_HID_header(wiegand_message_t *data);
49 #endif