Redesign of lf hid card format handler as discussed with @marshmellow42

The new handler accepts multiple formats of the same length.
Because of this, the existing pack/unpack commands are unsupported
and have been removed and replaced with 'lf hid encode' and 'lf hid decode'.
The decode command will test a packed Prox ID against all programmed
formats and return results for all matching formats.
The encode command takes the parameter of format name instead of
bit length (as per the old pack command). Additionally, an 'lf hid write'
command has been added as a single-command combination of encode and clone.

To support easier addition of new formats, a library for handling card
fields has been added. This will allow direct access to the card bits,
to linear fields, and to non-linear (jumping) fields in a single line
of code without having to resort to managing bit positions or masks
on the underlying data. A number of new formats have been added as working
examples of the new support functions.
This commit is contained in:
grauerfuchs 2018-08-27 14:03:46 -04:00
parent 18a3bf6119
commit b5a5fc4d9f
7 changed files with 874 additions and 304 deletions

View file

@ -14,37 +14,12 @@
#include <stdint.h>
#include <stdbool.h>
// Structure for unpacked HID Prox tags.
typedef struct {
// Format length, in bits.
uint8_t fmtLen;
// Facility code.
uint32_t fc;
// Card number.
uint64_t cardnum;
// Parity validity.
//
// When used with pack_hid, this determines if we should calculate
// parity values for the ID.
//
// When used with unpack_hid, this indicates if we got valid parity
// values for the ID.
bool parityValid;
} hid_info;
bool pack_hid(/* out */ uint32_t *hi2, /* out */ uint32_t *hi, /* out */ uint32_t *lo, /* in */ const hid_info *info);
bool unpack_hid(hid_info* out, uint32_t hi2, uint32_t hi, uint32_t lo);
int CmdLFHID(const char *Cmd);
int CmdFSKdemodHID(const char *Cmd);
int CmdHIDReadDemod(const char *Cmd);
int CmdHIDSim(const char *Cmd);
int CmdHIDClone(const char *Cmd);
int CmdHIDPack(const char *Cmd);
int CmdHIDUnpack(const char *Cmd);
int CmdHIDDecode(const char *Cmd);
int CmdHIDEncode(const char *Cmd);
int CmdHIDWrite(const char *Cmd);
#endif