minor corrections..

This commit is contained in:
iceman1001 2017-08-29 15:47:26 +02:00
commit c5616dfe76
9 changed files with 124 additions and 119 deletions

View file

@ -167,13 +167,14 @@ int CmdHF14AList(const char *Cmd) {
} }
int CmdHF14AReader(const char *Cmd) { int CmdHF14AReader(const char *Cmd) {
bool silent = (Cmd[0] == 's' || Cmd[0] == 'S');
UsbCommand cDisconnect = {CMD_READER_ISO_14443a, {0,0,0}}; UsbCommand cDisconnect = {CMD_READER_ISO_14443a, {0,0,0}};
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}}; UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}};
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
UsbCommand resp; UsbCommand resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
if (Cmd[0] != 's') PrintAndLog("iso14443a card select failed"); if (!silent) PrintAndLog("iso14443a card select failed");
SendCommand(&cDisconnect); SendCommand(&cDisconnect);
return 0; return 0;
} }
@ -181,15 +182,21 @@ int CmdHF14AReader(const char *Cmd) {
iso14a_card_select_t card; iso14a_card_select_t card;
memcpy(&card, (iso14a_card_select_t *)resp.d.asBytes, sizeof(iso14a_card_select_t)); memcpy(&card, (iso14a_card_select_t *)resp.d.asBytes, sizeof(iso14a_card_select_t));
uint64_t select_status = resp.arg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision /*
0: couldn't read
1: OK, with ATS
2: OK, no ATS
3: proprietary Anticollision
*/
uint64_t select_status = resp.arg[0];
if(select_status == 0) { if (select_status == 0) {
if (Cmd[0] != 's') PrintAndLog("iso14443a card select failed"); if (!silent) PrintAndLog("iso14443a card select failed");
SendCommand(&cDisconnect); SendCommand(&cDisconnect);
return 0; return 0;
} }
if(select_status == 3) { if (select_status == 3) {
PrintAndLog("Card doesn't support standard iso14443-3 anticollision"); PrintAndLog("Card doesn't support standard iso14443-3 anticollision");
PrintAndLog("ATQA : %02x %02x", card.atqa[1], card.atqa[0]); PrintAndLog("ATQA : %02x %02x", card.atqa[1], card.atqa[0]);
SendCommand(&cDisconnect); SendCommand(&cDisconnect);

View file

@ -462,7 +462,7 @@ int CmdHF15DumpMem(const char*Cmd) {
SendCommand(&c); SendCommand(&c);
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) { if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {
recv = resp.d.asBytes; recv = resp.d.asBytes;
if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) { if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
if (!(recv[0] & ISO15_RES_ERROR)) { if (!(recv[0] & ISO15_RES_ERROR)) {
@ -484,7 +484,8 @@ int CmdHF15DumpMem(const char*Cmd) {
return 1; return 1;
} }
} // else PrintAndLog("crc"); } // else PrintAndLog("crc");
} // else PrintAndLog("r null"); }
// else PrintAndLog("r null");
} // retry } // retry
// TODO: need fix // TODO: need fix
// if (resp.arg[0]<3) // if (resp.arg[0]<3)
@ -547,7 +548,7 @@ int CmdHF15CmdInquiry(const char *Cmd)
SendCommand(&c); SendCommand(&c);
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) { if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
if (resp.arg[0]>=12) { if (resp.arg[0] >= 12) {
recv = resp.d.asBytes; recv = resp.d.asBytes;
PrintAndLog("UID=%s", sprintUID(NULL, &recv[2])); PrintAndLog("UID=%s", sprintUID(NULL, &recv[2]));
PrintAndLog("Tag Info: %s", getTagInfo_15(&recv[2])); PrintAndLog("Tag Info: %s", getTagInfo_15(&recv[2]));
@ -555,7 +556,7 @@ int CmdHF15CmdInquiry(const char *Cmd)
PrintAndLog("Response to short, just %i bytes. No tag?\n", resp.arg[0]); PrintAndLog("Response to short, just %i bytes. No tag?\n", resp.arg[0]);
} }
} else { } else {
PrintAndLog("timeout."); PrintAndLog("timeout while waiting for reply.");
} }
return 0; return 0;
} }
@ -849,7 +850,7 @@ int CmdHF15CmdSysinfo(const char *Cmd) {
PrintAndLog("CRC failed"); PrintAndLog("CRC failed");
} }
} else { } else {
PrintAndLog("timeout: no answer"); PrintAndLog("timeout while waiting for reply.");
} }
return 0; return 0;
@ -928,7 +929,7 @@ int CmdHF15CmdReadmulti(const char *Cmd) {
PrintAndLog("CRC failed"); PrintAndLog("CRC failed");
} }
} else { } else {
PrintAndLog("no answer"); PrintAndLog("timeout while waiting for reply.");
} }
return 0; return 0;
@ -1002,7 +1003,7 @@ int CmdHF15CmdRead(const char *Cmd) {
PrintAndLog("CRC failed"); PrintAndLog("CRC failed");
} }
} else { } else {
PrintAndLog("no answer"); PrintAndLog("timeout while waiting for reply.");
} }
return 0; return 0;

View file

@ -173,7 +173,7 @@ int CmdHfEmvTrans(const char *Cmd) {
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
UsbCommand resp; UsbCommand resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, 5000)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 5000)) {
PrintAndLog("Command execute time-out"); PrintAndLog("Command execute time-out");
return 1; return 1;
} }
@ -312,7 +312,7 @@ int CmdHfEmvSim(const char *Cmd) {
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
UsbCommand resp; UsbCommand resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
PrintAndLog("Command execute time-out"); PrintAndLog("Command execute time-out");
return 1; return 1;
} }

View file

@ -318,6 +318,7 @@ int CmdHFiClassSim(const char *Cmd) {
memcpy(c.d.asBytes, csns, 8*NUM_CSNS); memcpy(c.d.asBytes, csns, 8*NUM_CSNS);
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
// -1 make it wait all the time (iceman)
if (!WaitForResponseTimeout(CMD_ACK, &resp, -1)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, -1)) {
PrintAndLog("Command timed out"); PrintAndLog("Command timed out");
return 0; return 0;

View file

@ -356,7 +356,7 @@ int CmdHF14AMfWrBl(const char *Cmd) {
SendCommand(&c); SendCommand(&c);
UsbCommand resp; UsbCommand resp;
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) { if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
uint8_t isOK = resp.arg[0] & 0xff; uint8_t isOK = resp.arg[0] & 0xff;
PrintAndLog("isOk:%02x", isOK); PrintAndLog("isOk:%02x", isOK);
} else { } else {
@ -448,10 +448,10 @@ int CmdHF14AMfRdSc(const char *Cmd) {
memcpy(c.d.asBytes, key, 6); memcpy(c.d.asBytes, key, 6);
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
PrintAndLog(" "); PrintAndLog("");
UsbCommand resp; UsbCommand resp;
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) { if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
isOK = resp.arg[0] & 0xff; isOK = resp.arg[0] & 0xff;
data = resp.d.asBytes; data = resp.d.asBytes;
@ -1619,97 +1619,97 @@ int CmdHF14AMfSniff(const char *Cmd){
} }
UsbCommand resp; UsbCommand resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { if ( !WaitForResponseTimeout(CMD_ACK, &resp, 2000) ) continue;
res = resp.arg[0] & 0xff;
traceLen = resp.arg[1];
len = resp.arg[2];
// we are done? res = resp.arg[0] & 0xff;
if (res == 0) { traceLen = resp.arg[1];
free(buf); len = resp.arg[2];
return 0;
}
if (res == 1) { // there is (more) data to be transferred // we are done?
if (pckNum == 0) { // first packet, (re)allocate necessary buffer if (res == 0) {
if (traceLen > bufsize || buf == NULL) { free(buf);
uint8_t *p; return 0;
if (buf == NULL) // not yet allocated }
p = malloc(traceLen);
else // need more memory
p = realloc(buf, traceLen);
if (p == NULL) { if (res == 1) { // there is (more) data to be transferred
PrintAndLog("Cannot allocate memory for trace"); if (pckNum == 0) { // first packet, (re)allocate necessary buffer
free(buf); if (traceLen > bufsize || buf == NULL) {
return 2; uint8_t *p;
} if (buf == NULL) // not yet allocated
buf = p; p = malloc(traceLen);
else // need more memory
p = realloc(buf, traceLen);
if (p == NULL) {
PrintAndLog("Cannot allocate memory for trace");
free(buf);
return 2;
} }
bufPtr = buf; buf = p;
bufsize = traceLen;
memset(buf, 0x00, traceLen);
} }
if (bufPtr == NULL) {
PrintAndLog("Cannot allocate memory for trace");
free(buf);
return 2;
}
// what happens if LEN is bigger then TRACELEN --iceman
memcpy(bufPtr, resp.d.asBytes, len);
bufPtr += len;
pckNum++;
}
if (res == 2) { // received all data, start displaying
blockLen = bufPtr - buf;
bufPtr = buf; bufPtr = buf;
printf(">\n"); bufsize = traceLen;
PrintAndLog("received trace len: %d packages: %d", blockLen, pckNum); memset(buf, 0x00, traceLen);
while (bufPtr - buf < blockLen) {
bufPtr += 6; // skip (void) timing information
len = *((uint16_t *)bufPtr);
if(len & 0x8000) {
isTag = true;
len &= 0x7fff;
} else {
isTag = false;
}
bufPtr += 2;
if ((len == 17) && (bufPtr[0] == 0xff) && (bufPtr[1] == 0xff) && (bufPtr[15] == 0xff) && (bufPtr[16] == 0xff)) {
memcpy(uid, bufPtr + 2, 10);
memcpy(atqa, bufPtr + 2 + 10, 2);
switch (atqa[0] & 0xC0) {
case 0x80: uid_len = 10; break;
case 0x40: uid_len = 7; break;
default: uid_len = 4; break;
}
sak = bufPtr[14];
PrintAndLog("tag select uid| %s atqa:0x%02x%02x sak:0x%02x",
sprint_hex(uid, uid_len),
atqa[1],
atqa[0],
sak);
if (wantLogToFile || wantDecrypt) {
FillFileNameByUID(logHexFileName, uid, ".log", uid_len);
AddLogCurrentDT(logHexFileName);
}
if (wantDecrypt)
mfTraceInit(uid, uid_len, atqa, sak, wantSaveToEmlFile);
} else {
PrintAndLog("%03d| %s |%s", num, isTag ? "TAG" : "RDR", sprint_hex(bufPtr, len));
if (wantLogToFile)
AddLogHex(logHexFileName, isTag ? "TAG| ":"RDR| ", bufPtr, len);
if (wantDecrypt)
mfTraceDecode(bufPtr, len, wantSaveToEmlFile);
num++;
}
bufPtr += len;
bufPtr += ((len-1)/8+1); // ignore parity
}
pckNum = 0;
} }
} // resp not NULL if (bufPtr == NULL) {
PrintAndLog("Cannot allocate memory for trace");
free(buf);
return 2;
}
// what happens if LEN is bigger then TRACELEN --iceman
memcpy(bufPtr, resp.d.asBytes, len);
bufPtr += len;
pckNum++;
}
if (res == 2) { // received all data, start displaying
blockLen = bufPtr - buf;
bufPtr = buf;
printf(">\n");
PrintAndLog("received trace len: %d packages: %d", blockLen, pckNum);
while (bufPtr - buf < blockLen) {
bufPtr += 6; // skip (void) timing information
len = *((uint16_t *)bufPtr);
if(len & 0x8000) {
isTag = true;
len &= 0x7fff;
} else {
isTag = false;
}
bufPtr += 2;
if ((len == 17) && (bufPtr[0] == 0xff) && (bufPtr[1] == 0xff) && (bufPtr[15] == 0xff) && (bufPtr[16] == 0xff)) {
memcpy(uid, bufPtr + 2, 10);
memcpy(atqa, bufPtr + 2 + 10, 2);
switch (atqa[0] & 0xC0) {
case 0x80: uid_len = 10; break;
case 0x40: uid_len = 7; break;
default: uid_len = 4; break;
}
sak = bufPtr[14];
PrintAndLog("tag select uid| %s atqa:0x%02x%02x sak:0x%02x",
sprint_hex(uid, uid_len),
atqa[1],
atqa[0],
sak);
if (wantLogToFile || wantDecrypt) {
FillFileNameByUID(logHexFileName, uid, ".log", uid_len);
AddLogCurrentDT(logHexFileName);
}
if (wantDecrypt)
mfTraceInit(uid, uid_len, atqa, sak, wantSaveToEmlFile);
} else {
PrintAndLog("%03d| %s |%s", num, isTag ? "TAG" : "RDR", sprint_hex(bufPtr, len));
if (wantLogToFile)
AddLogHex(logHexFileName, isTag ? "TAG| ":"RDR| ", bufPtr, len);
if (wantDecrypt)
mfTraceDecode(bufPtr, len, wantSaveToEmlFile);
num++;
}
bufPtr += len;
bufPtr += ((len-1)/8+1); // ignore parity
}
pckNum = 0;
}
} // while (true) } // while (true)
free(buf); free(buf);

View file

@ -181,9 +181,8 @@ int CmdHF14ADesInfo(const char *Cmd){
c.arg[1] = 0x01; c.arg[1] = 0x01;
c.d.asBytes[0] = GET_FREE_MEMORY; c.d.asBytes[0] = GET_FREE_MEMORY;
SendCommand(&c); SendCommand(&c);
if ( !WaitForResponseTimeout(CMD_ACK,&resp,1500)) { if ( !WaitForResponseTimeout(CMD_ACK,&resp,1500))
return 0; return 0;
}
uint8_t tmp[3]; uint8_t tmp[3];
memcpy(tmp, resp.d.asBytes+3,3); memcpy(tmp, resp.d.asBytes+3,3);
@ -299,9 +298,7 @@ void GetKeySettings( uint8_t *aid){
c.d.asBytes[0] = GET_KEY_VERSION; //0x64 c.d.asBytes[0] = GET_KEY_VERSION; //0x64
c.d.asBytes[1] = 0x00; c.d.asBytes[1] = 0x00;
SendCommand(&c); SendCommand(&c);
if ( !WaitForResponseTimeout(CMD_ACK,&resp,1000) ) { if ( !WaitForResponseTimeout(CMD_ACK,&resp,1000) ) { return; }
return;
}
isOK = resp.arg[0] & 0xff; isOK = resp.arg[0] & 0xff;
if ( !isOK ){ if ( !isOK ){
PrintAndLog(" Can't read key-version"); PrintAndLog(" Can't read key-version");

View file

@ -71,7 +71,7 @@ int CmdHF14AMfDESAuth(const char *Cmd){
if (isOK){ if (isOK){
PrintAndLog("enc(nc)/b0:%s", sprint_hex(data+2,8)); PrintAndLog("enc(nc)/b0:%s", sprint_hex(data+2,8));
memcpy(b0,data+2,8); memcpy(b0,data+2,8);
} }
} else { } else {
PrintAndLog("Command execute timeout"); PrintAndLog("Command execute timeout");
} }
@ -107,9 +107,8 @@ int CmdHF14AMfDESAuth(const char *Cmd){
uint8_t isOK = respb.arg[0] & 0xff; uint8_t isOK = respb.arg[0] & 0xff;
uint8_t * data2= respb.d.asBytes; uint8_t * data2= respb.d.asBytes;
if (isOK){ if (isOK)
PrintAndLog("b3:%s", sprint_hex(data2+2, 8)); PrintAndLog("b3:%s", sprint_hex(data2+2, 8));
}
} else { } else {
PrintAndLog("Command execute timeout"); PrintAndLog("Command execute timeout");
@ -163,7 +162,7 @@ int CmdHF14AMfAESAuth(const char *Cmd){
UsbCommand c = {CMD_MIFARE_DES_AUTH1, {blockNo}}; UsbCommand c = {CMD_MIFARE_DES_AUTH1, {blockNo}};
SendCommand(&c); SendCommand(&c);
UsbCommand resp; UsbCommand resp;
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) { if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
uint8_t isOK = resp.arg[0] & 0xff; uint8_t isOK = resp.arg[0] & 0xff;
cuid = resp.arg[1]; cuid = resp.arg[1];
uint8_t * data= resp.d.asBytes; uint8_t * data= resp.d.asBytes;
@ -171,7 +170,7 @@ int CmdHF14AMfAESAuth(const char *Cmd){
if (isOK){ if (isOK){
PrintAndLog("enc(nc)/b0:%s", sprint_hex(data+2,16)); PrintAndLog("enc(nc)/b0:%s", sprint_hex(data+2,16));
memcpy(b0,data+2,16); memcpy(b0,data+2,16);
} }
} else { } else {
PrintAndLog("Command execute timeout"); PrintAndLog("Command execute timeout");
} }
@ -210,13 +209,12 @@ int CmdHF14AMfAESAuth(const char *Cmd){
SendCommand(&d); SendCommand(&d);
UsbCommand respb; UsbCommand respb;
if (WaitForResponseTimeout(CMD_ACK,&respb,1500)) { if (WaitForResponseTimeout(CMD_ACK, &respb, 1500)) {
uint8_t isOK = respb.arg[0] & 0xff; uint8_t isOK = respb.arg[0] & 0xff;
uint8_t * data2= respb.d.asBytes; uint8_t * data2= respb.d.asBytes;
if (isOK){ if (isOK)
PrintAndLog("b3:%s", sprint_hex(data2+2, 16)); PrintAndLog("b3:%s", sprint_hex(data2+2, 16));
}
} else { } else {
PrintAndLog("Command execute timeout"); PrintAndLog("Command execute timeout");

View file

@ -1459,6 +1459,7 @@ static int acquire_nonces(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_
if (initialize) { if (initialize) {
if (!WaitForResponseTimeout(CMD_ACK, &resp, 3000)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 3000)) {
//strange second call (iceman)
UsbCommand c = {CMD_MIFARE_ACQUIRE_ENCRYPTED_NONCES, {blockNo + keyType * 0x100, trgBlockNo + trgKeyType * 0x100, 4}}; UsbCommand c = {CMD_MIFARE_ACQUIRE_ENCRYPTED_NONCES, {blockNo + keyType * 0x100, trgBlockNo + trgKeyType * 0x100, 4}};
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);

View file

@ -1029,7 +1029,7 @@ int CmdT55xxWriteBlock(const char *Cmd) {
} }
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)){ if ( !WaitForResponseTimeout(CMD_ACK, &resp, 1500 )){
PrintAndLog("Error occurred, device did not ACK write operation. (May be due to old firmware)"); PrintAndLog("Error occurred, device did not ACK write operation. (May be due to old firmware)");
return 0; return 0;
} }