+static int CmdHF15CSetUID(const char *Cmd) {
+ uint8_t uid[8] = {0x00};
+ uint8_t oldUid[8], newUid[8] = {0x00};
+
+ uint8_t needHelp = 0;
+ char cmdp = 1;
+
+ if (param_getchar(Cmd, 0) && param_gethex(Cmd, 0, uid, 16)) {
+ PrintAndLog("UID must include 16 HEX symbols");
+ return 1;
+ }
+
+ if (uid[0] != 0xe0) {
+ PrintAndLog("UID must begin with the byte 'E0'");
+ return 1;
+ }
+
+ while (param_getchar(Cmd, cmdp) != 0x00) {
+ switch (param_getchar(Cmd, cmdp)) {
+ case 'h':
+ case 'H':
+ needHelp = 1;
+ break;
+ default:
+ PrintAndLog("ERROR: Unknown parameter '%c'", param_getchar(Cmd, cmdp));
+ needHelp = 1;
+ break;
+ }
+ cmdp++;
+ }
+
+ if (strlen(Cmd) < 1 || needHelp) {
+ PrintAndLog("");
+ PrintAndLog("Usage: hf 15 csetuid <UID 16 hex symbols>");
+ PrintAndLog("sample: hf 15 csetuid E004013344556677");
+ PrintAndLog("Set UID for magic Chinese card (only works with such cards)");
+ return 0;
+ }
+
+ PrintAndLog("Using backdoor Magic tag function");
+
+ if (!getUID(oldUid)) {
+ PrintAndLog("Can't get old UID.");
+ return 1;
+ }
+
+ UsbCommand c = {CMD_CSETUID_ISO_15693, {0, 0, 0}};
+ memcpy(c.d.asBytes, uid, 8);
+
+ SendCommand(&c);
+
+ UsbCommand resp;
+ if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
+ int recv_len = resp.arg[0];
+ uint8_t *recv = resp.d.asBytes;
+ if (recv_len == 0) {
+ PrintAndLog("Received SOF only. Maybe Picopass/iCLASS?");
+ } else if (recv_len == -1) {
+ PrintAndLog("Tag didn't respond");
+ } else if (recv_len == -2) {
+ PrintAndLog("Receive buffer overflow");
+ } else if (ISO15693_CRC_CHECK != Crc(recv, recv_len)) {
+ PrintAndLog("CRC check failed on Tag response");
+ } else if (!(recv[0] & ISO15693_RES_ERROR)) {
+ PrintAndLog("Tag returned OK");
+ } else {
+ PrintAndLog("Tag returned Error %i: %s", recv[1], TagErrorStr(recv[1]));
+ }
+ } else {
+ PrintAndLog("No answer from Proxmark");
+ }
+
+ if (!getUID(newUid)) {
+ PrintAndLog("Can't get new UID.");
+ return 1;
+ }
+
+ PrintAndLog("");
+ PrintAndLog("old UID : %02X %02X %02X %02X %02X %02X %02X %02X", oldUid[7], oldUid[6], oldUid[5], oldUid[4], oldUid[3], oldUid[2], oldUid[1], oldUid[0]);
+ PrintAndLog("new UID : %02X %02X %02X %02X %02X %02X %02X %02X", newUid[7], newUid[6], newUid[5], newUid[4], newUid[3], newUid[2], newUid[1], newUid[0]);
+ return 0;
+}
+
+
+// "HF 15 Cmd" Interface
+// Allows direct communication with the tag on command level