client: unify wiegand input handling
Extract the reusable Wiegand normalization and packing flow into wiegand_formatutils and move existing callers onto that shared path. This rebuilds the feat-wiegand branch as one focused commit against upstream/master instead of trying to preserve the original commit chain. Key changes: - add shared helpers for plain binary, raw HID, new PACS, and formatted Wiegand input - centralize binary rendering used by cmdwiegand and PACS decode output - update lf hid sim/clone to resolve one input mode through the shared Wiegand layer and enforce the LF packed transport limit explicitly - update hf mf encodehid to accept bin/raw/new/formatted Wiegand input through the same normalization path - preserve legacy raw HID transport behavior while clarifying the packed-HID vs LF transport limits in error reporting - add offline regression coverage for the new PACS decode output and add interactive online targets for LF HID Wiegand and MIFARE encodehid Validation performed: - make client - bash -n tools/pm3_tests.sh - bash -n tools/pm3_online_tests.sh - ./tools/pm3_online_tests.sh -h - ./client/proxmark3 -c 'wiegand encode -w H10301 --fc 31 --cn 337' - ./client/proxmark3 -c 'wiegand encode -w H10301 --fc 31 --cn 337 --new' - ./client/proxmark3 -c 'wiegand decode --new 068F80A8C0'
This commit is contained in:
8 files changed
+534
-187
No files matched your search
@@ -40,20 +40,16 @@ static int CmdHelp(const char *Cmd);
|
||||
#define PACS_MAX_WIEGAND_BITS 96
|
||||
#define WIEGAND_MAX_ENCODED_BITS (PACS_MAX_WIEGAND_BITS + 8)
|
||||
|
||||
static void wiegand_packed_to_binstr(const wiegand_message_t *packed, char *binstr) {
|
||||
for (uint8_t i = 0; i < packed->Length; i++) {
|
||||
binstr[i] = get_bit_by_position((wiegand_message_t *)packed, i) ? '1' : '0';
|
||||
}
|
||||
binstr[packed->Length] = '\0';
|
||||
}
|
||||
|
||||
static int wiegand_print_new_pacs_verbose(const wiegand_message_t *packed, const uint8_t *pacs, size_t pacs_len) {
|
||||
char binstr[PACS_MAX_WIEGAND_BITS + 1] = {0};
|
||||
char rawbin[WIEGAND_MAX_ENCODED_BITS + 1] = {0};
|
||||
uint8_t raw[(WIEGAND_MAX_ENCODED_BITS + 7) / 8] = {0};
|
||||
size_t raw_len = 0;
|
||||
|
||||
wiegand_packed_to_binstr(packed, binstr);
|
||||
if (wiegand_message_to_binstr(packed, binstr, sizeof(binstr)) == false) {
|
||||
PrintAndLogEx(ERR, "Failed to render Wiegand payload");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
rawbin[0] = '1';
|
||||
memcpy(rawbin + 1, binstr, packed->Length);
|
||||
binstr_2_bytes(raw, &raw_len, rawbin);
|
||||
@@ -83,7 +79,10 @@ static int wiegand_encode_new_pacs(const wiegand_message_t *packed, bool verbose
|
||||
uint8_t pad = padded_bits - packed->Length;
|
||||
|
||||
char binstr[PACS_MAX_WIEGAND_BITS + 1] = {0};
|
||||
wiegand_packed_to_binstr(packed, binstr);
|
||||
if (wiegand_message_to_binstr(packed, binstr, sizeof(binstr)) == false) {
|
||||
PrintAndLogEx(ERR, "Failed to render Wiegand payload");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
memset(binstr + packed->Length, '0', pad);
|
||||
binstr[padded_bits] = '\0';
|
||||
|
||||
|
||||
Reference in new issue
Block a user