Better Reply structs

This commit is contained in:
Philippe Teuwen 2019-04-17 23:44:48 +02:00
commit 533667ea6d
57 changed files with 725 additions and 718 deletions

View file

@ -51,14 +51,14 @@ static int CmdHF14ADesWb(const char *Cmd) {
PrintAndLogEx(NORMAL, "--block no:%02x key type:%02x key:%s", blockNo, keyType, sprint_hex(key, 6));
PrintAndLogEx(NORMAL, "--data: %s", sprint_hex(bldata, 16));
UsbCommand c = {CMD_MIFARE_WRITEBL, {blockNo, keyType, 0}, {{0}}};
UsbCommandOLD c = {CMD_MIFARE_WRITEBL, {blockNo, keyType, 0}, {{0}}};
memcpy(c.d.asBytes, key, 6);
memcpy(c.d.asBytes + 10, bldata, 16);
SendCommand(&c);
UsbReplyNG resp;
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
uint8_t isOK = resp.core.old.arg[0] & 0xff;
uint8_t isOK = resp.oldarg[0] & 0xff;
PrintAndLogEx(NORMAL, "isOk:%02x", isOK);
} else {
PrintAndLogEx(NORMAL, "Command execute timeout");
@ -93,14 +93,14 @@ static int CmdHF14ADesRb(const char *Cmd) {
}
PrintAndLogEx(NORMAL, "--block no:%02x key type:%02x key:%s ", blockNo, keyType, sprint_hex(key, 6));
UsbCommand c = {CMD_MIFARE_READBL, {blockNo, keyType, 0}, {{0}}};
UsbCommandOLD c = {CMD_MIFARE_READBL, {blockNo, keyType, 0}, {{0}}};
memcpy(c.d.asBytes, key, 6);
SendCommand(&c);
UsbReplyNG resp;
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
uint8_t isOK = resp.core.old.arg[0] & 0xff;
uint8_t * data = resp.core.old.d.asBytes;
uint8_t isOK = resp.oldarg[0] & 0xff;
uint8_t * data = resp.data.asBytes;
if (isOK)
PrintAndLogEx(NORMAL, "isOk:%02x data:%s", isOK, sprint_hex(data, 16));
@ -116,7 +116,7 @@ static int CmdHF14ADesRb(const char *Cmd) {
static int CmdHF14ADesInfo(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
UsbCommand c = {CMD_MIFARE_DESFIRE_INFO, {0, 0, 0}, {{0}}};
UsbCommandOLD c = {CMD_MIFARE_DESFIRE_INFO, {0, 0, 0}, {{0}}};
SendCommand(&c);
UsbReplyNG resp;
@ -124,9 +124,9 @@ static int CmdHF14ADesInfo(const char *Cmd) {
PrintAndLogEx(WARNING, "Command execute timeout");
return 0;
}
uint8_t isOK = resp.core.old.arg[0] & 0xff;
uint8_t isOK = resp.oldarg[0] & 0xff;
if (!isOK) {
switch (resp.core.old.arg[1]) {
switch (resp.oldarg[1]) {
case 1:
PrintAndLogEx(WARNING, "Can't select card");
break;
@ -143,25 +143,25 @@ static int CmdHF14ADesInfo(const char *Cmd) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "-- Desfire Information --------------------------------------");
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
PrintAndLogEx(NORMAL, " UID : %s", sprint_hex(resp.core.old.d.asBytes, 7));
PrintAndLogEx(NORMAL, " Batch number : %s", sprint_hex(resp.core.old.d.asBytes + 28, 5));
PrintAndLogEx(NORMAL, " Production date : week %02x, 20%02x", resp.core.old.d.asBytes[33], resp.core.old.d.asBytes[34]);
PrintAndLogEx(NORMAL, " UID : %s", sprint_hex(resp.data.asBytes, 7));
PrintAndLogEx(NORMAL, " Batch number : %s", sprint_hex(resp.data.asBytes + 28, 5));
PrintAndLogEx(NORMAL, " Production date : week %02x, 20%02x", resp.data.asBytes[33], resp.data.asBytes[34]);
PrintAndLogEx(NORMAL, " -----------------------------------------------------------");
PrintAndLogEx(NORMAL, " Hardware Information");
PrintAndLogEx(NORMAL, " Vendor Id : %s", getTagInfo(resp.core.old.d.asBytes[7]));
PrintAndLogEx(NORMAL, " Type : 0x%02X", resp.core.old.d.asBytes[8]);
PrintAndLogEx(NORMAL, " Subtype : 0x%02X", resp.core.old.d.asBytes[9]);
PrintAndLogEx(NORMAL, " Version : %s", getVersionStr(resp.core.old.d.asBytes[10], resp.core.old.d.asBytes[11]));
PrintAndLogEx(NORMAL, " Storage size : %s", getCardSizeStr(resp.core.old.d.asBytes[12]));
PrintAndLogEx(NORMAL, " Protocol : %s", getProtocolStr(resp.core.old.d.asBytes[13]));
PrintAndLogEx(NORMAL, " Vendor Id : %s", getTagInfo(resp.data.asBytes[7]));
PrintAndLogEx(NORMAL, " Type : 0x%02X", resp.data.asBytes[8]);
PrintAndLogEx(NORMAL, " Subtype : 0x%02X", resp.data.asBytes[9]);
PrintAndLogEx(NORMAL, " Version : %s", getVersionStr(resp.data.asBytes[10], resp.data.asBytes[11]));
PrintAndLogEx(NORMAL, " Storage size : %s", getCardSizeStr(resp.data.asBytes[12]));
PrintAndLogEx(NORMAL, " Protocol : %s", getProtocolStr(resp.data.asBytes[13]));
PrintAndLogEx(NORMAL, " -----------------------------------------------------------");
PrintAndLogEx(NORMAL, " Software Information");
PrintAndLogEx(NORMAL, " Vendor Id : %s", getTagInfo(resp.core.old.d.asBytes[14]));
PrintAndLogEx(NORMAL, " Type : 0x%02X", resp.core.old.d.asBytes[15]);
PrintAndLogEx(NORMAL, " Subtype : 0x%02X", resp.core.old.d.asBytes[16]);
PrintAndLogEx(NORMAL, " Version : %d.%d", resp.core.old.d.asBytes[17], resp.core.old.d.asBytes[18]);
PrintAndLogEx(NORMAL, " storage size : %s", getCardSizeStr(resp.core.old.d.asBytes[19]));
PrintAndLogEx(NORMAL, " Protocol : %s", getProtocolStr(resp.core.old.d.asBytes[20]));
PrintAndLogEx(NORMAL, " Vendor Id : %s", getTagInfo(resp.data.asBytes[14]));
PrintAndLogEx(NORMAL, " Type : 0x%02X", resp.data.asBytes[15]);
PrintAndLogEx(NORMAL, " Subtype : 0x%02X", resp.data.asBytes[16]);
PrintAndLogEx(NORMAL, " Version : %d.%d", resp.data.asBytes[17], resp.data.asBytes[18]);
PrintAndLogEx(NORMAL, " storage size : %s", getCardSizeStr(resp.data.asBytes[19]));
PrintAndLogEx(NORMAL, " Protocol : %s", getProtocolStr(resp.data.asBytes[20]));
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
// Master Key settings
@ -177,7 +177,7 @@ static int CmdHF14ADesInfo(const char *Cmd) {
return 0;
uint8_t tmp[3];
memcpy(tmp, resp.core.old.d.asBytes + 3, 3);
memcpy(tmp, resp.data.asBytes + 3, 3);
PrintAndLogEx(NORMAL, " Available free memory on card : %d bytes", le24toh(tmp));
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
@ -256,7 +256,7 @@ void getKeySettings(uint8_t *aid) {
const char *str = messStr;
uint8_t isOK = 0;
uint32_t options;
UsbCommand c = {CMD_MIFARE_DESFIRE, {0, 0, 0}, {{0}}};
UsbCommandOLD c = {CMD_MIFARE_DESFIRE, {0, 0, 0}, {{0}}};
UsbReplyNG resp;
//memset(messStr, 0x00, 512);
@ -269,19 +269,19 @@ void getKeySettings(uint8_t *aid) {
c.d.asBytes[0] = GET_KEY_SETTINGS; // 0x45
SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
isOK = resp.core.old.arg[0] & 0xff;
isOK = resp.oldarg[0] & 0xff;
if (!isOK) {
PrintAndLogEx(WARNING, " Can't select master application");
return;
}
str = (resp.core.old.d.asBytes[3] & (1 << 3)) ? "YES" : "NO";
str = (resp.data.asBytes[3] & (1 << 3)) ? "YES" : "NO";
PrintAndLogEx(NORMAL, " [0x08] Configuration changeable : %s", str);
str = (resp.core.old.d.asBytes[3] & (1 << 2)) ? "NO" : "YES";
str = (resp.data.asBytes[3] & (1 << 2)) ? "NO" : "YES";
PrintAndLogEx(NORMAL, " [0x04] CMK required for create/delete : %s", str);
str = (resp.core.old.d.asBytes[3] & (1 << 1)) ? "NO" : "YES";
str = (resp.data.asBytes[3] & (1 << 1)) ? "NO" : "YES";
PrintAndLogEx(NORMAL, " [0x02] Directory list access with CMK : %s", str);
str = (resp.core.old.d.asBytes[3] & (1 << 0)) ? "YES" : "NO";
str = (resp.data.asBytes[3] & (1 << 0)) ? "YES" : "NO";
PrintAndLogEx(NORMAL, " [0x01] CMK is changeable : %s", str);
c.arg[LENPOS] = 0x02; //LEN
@ -289,14 +289,14 @@ void getKeySettings(uint8_t *aid) {
c.d.asBytes[1] = 0x00;
SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) { return; }
isOK = resp.core.old.arg[0] & 0xff;
isOK = resp.oldarg[0] & 0xff;
if (!isOK) {
PrintAndLogEx(WARNING, " Can't read key-version");
return;
}
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, " Max number of keys : %d", resp.core.old.d.asBytes[4]);
PrintAndLogEx(NORMAL, " Master key Version : %d (0x%02x)", resp.core.old.d.asBytes[3], resp.core.old.d.asBytes[3]);
PrintAndLogEx(NORMAL, " Max number of keys : %d", resp.data.asBytes[4]);
PrintAndLogEx(NORMAL, " Master key Version : %d (0x%02x)", resp.data.asBytes[3], resp.data.asBytes[3]);
PrintAndLogEx(NORMAL, " ----------------------------------------------------------");
c.arg[LENPOS] = 0x02; //LEN
@ -304,19 +304,19 @@ void getKeySettings(uint8_t *aid) {
c.d.asBytes[1] = 0x00; // KEY 0
SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
isOK = resp.core.old.d.asBytes[2] & 0xff;
isOK = resp.data.asBytes[2] & 0xff;
PrintAndLogEx(NORMAL, " [0x0A] Authenticate : %s", (isOK == 0xAE) ? "NO" : "YES");
c.d.asBytes[0] = AUTHENTICATE_ISO; //0x1A
SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
isOK = resp.core.old.d.asBytes[2] & 0xff;
isOK = resp.data.asBytes[2] & 0xff;
PrintAndLogEx(NORMAL, " [0x1A] Authenticate ISO : %s", (isOK == 0xAE) ? "NO" : "YES");
c.d.asBytes[0] = AUTHENTICATE_AES; //0xAA
SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
isOK = resp.core.old.d.asBytes[2] & 0xff;
isOK = resp.data.asBytes[2] & 0xff;
PrintAndLogEx(NORMAL, " [0xAA] Authenticate AES : %s", (isOK == 0xAE) ? "NO" : "YES");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, " ----------------------------------------------------------");
@ -335,7 +335,7 @@ void getKeySettings(uint8_t *aid) {
PrintAndLogEx(WARNING, " Timed-out");
return;
}
isOK = resp.core.old.arg[0] & 0xff;
isOK = resp.oldarg[0] & 0xff;
if (!isOK) {
PrintAndLogEx(WARNING, " Can't select AID: %s", sprint_hex(aid, 3));
return;
@ -350,12 +350,12 @@ void getKeySettings(uint8_t *aid) {
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
return;
}
isOK = resp.core.old.arg[0] & 0xff;
isOK = resp.oldarg[0] & 0xff;
if (!isOK) {
PrintAndLogEx(WARNING, " Can't read Application Master key settings");
} else {
// Access rights.
uint8_t rights = (resp.core.old.d.asBytes[3] >> 4 & 0xff);
uint8_t rights = (resp.data.asBytes[3] >> 4 & 0xff);
switch (rights) {
case 0x00:
str = "AMK authentication is necessary to change any key (default)";
@ -374,13 +374,13 @@ void getKeySettings(uint8_t *aid) {
PrintAndLogEx(NORMAL, "-- %s", str);
PrintAndLogEx(NORMAL, "");
// same as CMK
str = (resp.core.old.d.asBytes[3] & (1 << 3)) ? "YES" : "NO";
str = (resp.data.asBytes[3] & (1 << 3)) ? "YES" : "NO";
PrintAndLogEx(NORMAL, " 0x08 Configuration changeable : %s", str);
str = (resp.core.old.d.asBytes[3] & (1 << 2)) ? "NO" : "YES";
str = (resp.data.asBytes[3] & (1 << 2)) ? "NO" : "YES";
PrintAndLogEx(NORMAL, " 0x04 AMK required for create/delete : %s", str);
str = (resp.core.old.d.asBytes[3] & (1 << 1)) ? "NO" : "YES";
str = (resp.data.asBytes[3] & (1 << 1)) ? "NO" : "YES";
PrintAndLogEx(NORMAL, " 0x02 Directory list access with AMK : %s", str);
str = (resp.core.old.d.asBytes[3] & (1 << 0)) ? "YES" : "NO";
str = (resp.data.asBytes[3] & (1 << 0)) ? "YES" : "NO";
PrintAndLogEx(NORMAL, " 0x01 AMK is changeable : %s", str);
}
@ -397,15 +397,15 @@ void getKeySettings(uint8_t *aid) {
int numOfKeys;
isOK = resp.core.old.arg[0] & 0xff;
isOK = resp.oldarg[0] & 0xff;
if (isOK == false) {
PrintAndLogEx(WARNING, " Can't read Application Master key version. Trying all keys");
//numOfKeys = MAX_NUM_KEYS;
} else {
numOfKeys = resp.core.old.d.asBytes[4];
numOfKeys = resp.data.asBytes[4];
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, " Max number of keys : %d", numOfKeys);
PrintAndLogEx(NORMAL, " Application Master key Version : %d (0x%02x)", resp.core.old.d.asBytes[3], resp.core.old.d.asBytes[3]);
PrintAndLogEx(NORMAL, " Application Master key Version : %d (0x%02x)", resp.data.asBytes[3], resp.data.asBytes[3]);
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
}
@ -427,7 +427,7 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
uint8_t aid[3];
uint32_t options = (INIT | DISCONNECT);
UsbCommand c = {CMD_MIFARE_DESFIRE, {options, 0x01 }, {{0}}};
UsbCommandOLD c = {CMD_MIFARE_DESFIRE, {options, 0x01 }, {{0}}};
c.d.asBytes[0] = GET_APPLICATION_IDS; //0x6a
SendCommand(&c);
@ -436,7 +436,7 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
return 0;
}
isOK = resp.core.old.arg[0] & 0xff;
isOK = resp.oldarg[0] & 0xff;
if (!isOK) {
PrintAndLogEx(NORMAL, "Command unsuccessful");
return 0;
@ -449,33 +449,33 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
UsbReplyNG respFiles;
uint8_t num = 0;
int max = resp.core.old.arg[1] - 3 - 2;
int max = resp.oldarg[1] - 3 - 2;
for (int i = 3; i <= max; i += 3) {
PrintAndLogEx(NORMAL, " Aid %d : %02X %02X %02X ", num, resp.core.old.d.asBytes[i], resp.core.old.d.asBytes[i + 1], resp.core.old.d.asBytes[i + 2]);
PrintAndLogEx(NORMAL, " Aid %d : %02X %02X %02X ", num, resp.data.asBytes[i], resp.data.asBytes[i + 1], resp.data.asBytes[i + 2]);
num++;
aid[0] = resp.core.old.d.asBytes[i];
aid[1] = resp.core.old.d.asBytes[i + 1];
aid[2] = resp.core.old.d.asBytes[i + 2];
aid[0] = resp.data.asBytes[i];
aid[1] = resp.data.asBytes[i + 1];
aid[2] = resp.data.asBytes[i + 2];
getKeySettings(aid);
// Select Application
c.arg[CMDPOS] = INIT;
c.arg[LENPOS] = 0x04;
c.d.asBytes[0] = SELECT_APPLICATION; // 0x5a
c.d.asBytes[1] = resp.core.old.d.asBytes[i];
c.d.asBytes[2] = resp.core.old.d.asBytes[i + 1];
c.d.asBytes[3] = resp.core.old.d.asBytes[i + 2];
c.d.asBytes[1] = resp.data.asBytes[i];
c.d.asBytes[2] = resp.data.asBytes[i + 1];
c.d.asBytes[3] = resp.data.asBytes[i + 2];
SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK, &respAid, 1500)) {
PrintAndLogEx(WARNING, " Timed-out");
continue;
}
isOK = respAid.core.old.d.asBytes[2] & 0xff;
isOK = respAid.data.asBytes[2] & 0xff;
if (isOK != 0x00) {
PrintAndLogEx(WARNING, " Can't select AID: %s", sprint_hex(resp.core.old.d.asBytes + i, 3));
PrintAndLogEx(WARNING, " Can't select AID: %s", sprint_hex(resp.data.asBytes + i, 3));
continue;
}
@ -489,13 +489,13 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
PrintAndLogEx(WARNING, " Timed-out");
continue;
} else {
isOK = respFiles.core.old.d.asBytes[2] & 0xff;
isOK = respFiles.data.asBytes[2] & 0xff;
if (!isOK) {
PrintAndLogEx(WARNING, " Can't get file ids ");
} else {
int respfileLen = resp.core.old.arg[1] - 3 - 2;
int respfileLen = resp.oldarg[1] - 3 - 2;
for (int j = 0; j < respfileLen; ++j) {
PrintAndLogEx(NORMAL, " Fileid %d :", resp.core.old.d.asBytes[j + 3]);
PrintAndLogEx(NORMAL, " Fileid %d :", resp.data.asBytes[j + 3]);
}
}
}
@ -510,13 +510,13 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
PrintAndLogEx(WARNING, " Timed-out");
continue;
} else {
isOK = respFiles.core.old.d.asBytes[2] & 0xff;
isOK = respFiles.data.asBytes[2] & 0xff;
if (!isOK) {
PrintAndLogEx(WARNING, " Can't get ISO file ids ");
} else {
int respfileLen = resp.core.old.arg[1] - 3 - 2;
int respfileLen = resp.oldarg[1] - 3 - 2;
for (int j = 0; j < respfileLen; ++j) {
PrintAndLogEx(NORMAL, " ISO Fileid %d :", resp.core.old.d.asBytes[j + 3]);
PrintAndLogEx(NORMAL, " ISO Fileid %d :", resp.data.asBytes[j + 3]);
}
}
}
@ -611,7 +611,7 @@ static int CmdHF14ADesAuth(const char *Cmd) {
return 1;
}
// algo, nyckell<6C>ngd,
UsbCommand c = {CMD_MIFARE_DESFIRE_AUTH1, { cmdAuthMode, cmdAuthAlgo, cmdKeyNo }, {{0}}};
UsbCommandOLD c = {CMD_MIFARE_DESFIRE_AUTH1, { cmdAuthMode, cmdAuthAlgo, cmdKeyNo }, {{0}}};
c.d.asBytes[0] = keylength;
memcpy(c.d.asBytes + 1, key, keylength);
@ -624,9 +624,9 @@ static int CmdHF14ADesAuth(const char *Cmd) {
return 0;
}
uint8_t isOK = resp.core.old.arg[0] & 0xff;
uint8_t isOK = resp.oldarg[0] & 0xff;
if (isOK) {
uint8_t *data = resp.core.old.d.asBytes;
uint8_t *data = resp.data.asBytes;
PrintAndLogEx(NORMAL, " Key :%s", sprint_hex(key, keylength));
PrintAndLogEx(NORMAL, " SESSION :%s", sprint_hex(data, keylength));