+int CmdHIDDecode(const char *Cmd){
+ if (strlen(Cmd)<3) {
+ PrintAndLog("Usage: lf hid decode <id> {p}");
+ PrintAndLog(" (optional) p: Ignore invalid parity");
+ PrintAndLog(" sample: lf hid decode 2006f623ae");
+ return 0;
+ }
+
+ uint32_t top = 0, mid = 0, bot = 0;
+ bool ignoreParity = false;
+ hexstring_to_int96(&top, &mid, &bot, Cmd);
+ hidproxmessage_t packed = initialize_proxmessage_object(top, mid, bot);
+
+ char opt = param_getchar(Cmd, 1);
+ if (opt == 'p') ignoreParity = true;
+
+ HIDTryUnpack(&packed, ignoreParity);
+ return 0;
+}
+int CmdHIDEncode(const char *Cmd) {
+ if (strlen(Cmd) == 0) {
+ PrintAndLog("Usage: lf hid encode <format> <facility code (decimal)> <card number (decimal)> [issue level (decimal)]");
+ PrintAndLog(" sample: lf hid encode H10301 123 4567");
+ return 0;
+ }
+
+ int formatIndex = -1;
+ if (!strcmp(Cmd, "help") || !strcmp(Cmd, "h") || !strcmp(Cmd, "list") || !strcmp(Cmd, "?")){
+ HIDListFormats();
+ return 0;
+ } else {
+ char format[16];
+ memset(format, 0, sizeof(format));
+ param_getstr(Cmd, 0, format, sizeof(format));
+ formatIndex = HIDFindCardFormat(format);
+ if (formatIndex == -1) {
+ HIDListFormats();
+ return 0;
+ }
+ }
+
+ hidproxcard_t card;
+ memset(&card, 0, sizeof(hidproxcard_t));
+ card.FacilityCode = param_get32ex(Cmd, 1, 0, 10);
+ card.CardNumber = param_get64ex(Cmd, 2, 0, 10);
+ card.IssueLevel = param_get32ex(Cmd, 3, 0, 10);
+ card.ParitySupported = true; // Try to encode parity if supported.
+
+ hidproxmessage_t packed;
+ memset(&packed, 0, sizeof(hidproxmessage_t));
+ if (HIDPack(formatIndex, &card, &packed)){
+ if (packed.top != 0) {
+ PrintAndLog("HID Prox TAG ID: %x%08x%08x",
+ (unsigned int)packed.top, (unsigned int)packed.mid, (unsigned int)packed.bot);
+ } else {
+ PrintAndLog("HID Prox TAG ID: %x%08x",
+ (unsigned int)packed.mid, (unsigned int)packed.bot);
+ }
+ } else {
+ PrintAndLog("The provided data could not be encoded with the selected format.");
+ }
+ return 0;
+}
+
+int CmdHIDWrite(const char *Cmd) {
+ if (strlen(Cmd) == 0) {
+ PrintAndLog("Usage: lf hid write <format> <facility code (decimal)> <card number (decimal)> [issue level (decimal)]");
+ PrintAndLog(" sample: lf hid write H10301 123 4567");
+ return 0;
+ }
+
+ int formatIndex = -1;
+ if (!strcmp(Cmd, "help") || !strcmp(Cmd, "h") || !strcmp(Cmd, "list") || !strcmp(Cmd, "?")){
+ HIDListFormats();
+ return 0;
+ } else {
+ char format[16];
+ memset(format, 0, sizeof(format));
+ param_getstr(Cmd, 0, format, sizeof(format));
+ formatIndex = HIDFindCardFormat(format);
+ if (formatIndex == -1) {
+ HIDListFormats();
+ return 0;
+ }
+ }
+
+ hidproxcard_t card;
+ memset(&card, 0, sizeof(hidproxcard_t));
+ card.FacilityCode = param_get32ex(Cmd, 1, 0, 10);
+ card.CardNumber = param_get64ex(Cmd, 2, 0, 10);
+ card.IssueLevel = param_get32ex(Cmd, 3, 0, 10);
+ card.ParitySupported = true; // Try to encode parity if supported.
+
+ hidproxmessage_t packed;
+ memset(&packed, 0, sizeof(hidproxmessage_t));
+ if (HIDPack(formatIndex, &card, &packed)){
+ UsbCommand c;
+ if (packed.top != 0) {
+ PrintAndLog("HID Prox TAG ID: %x%08x%08x",
+ (unsigned int)packed.top, (unsigned int)packed.mid, (unsigned int)packed.bot);
+ c.d.asBytes[0] = 1;
+ } else {
+ PrintAndLog("HID Prox TAG ID: %x%08x",
+ (unsigned int)packed.mid, (unsigned int)packed.bot);
+ c.d.asBytes[0] = 0;
+ }
+
+ c.cmd = CMD_HID_CLONE_TAG;
+ c.arg[0] = (packed.top & 0x000FFFFF);
+ c.arg[1] = packed.mid;
+ c.arg[2] = packed.bot;
+ SendCommand(&c);
+
+ } else {
+ PrintAndLog("The provided data could not be encoded with the selected format.");
+ }
+ return 0;
+}
+
+static int CmdHelp(const char *Cmd); // define this now so the below won't error out.