From d3499d369d191057fea1335c4e50e907c6a9369f Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 17 Dec 2014 22:26:16 +0100 Subject: [PATCH] minor fixes regaring the newly released patches from the pm3 community plus removed old comments in cmdmain.c --- armsrc/appmain.c | 23 ++---- armsrc/iso14443a.c | 78 +++++++++--------- client/cmddata.c | 56 ++++++++++--- client/cmdhf14a.c | 172 +++++++++++++++++++++++++--------------- client/cmdhfmfu.c | 28 +++---- client/cmdhw.c | 18 +---- client/cmdmain.c | 191 ++++++++++++--------------------------------- 7 files changed, 261 insertions(+), 305 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 2ee234fb..c3cf3999 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -169,13 +169,11 @@ int AvgAdc(int ch) // was static - merlok void MeasureAntennaTuning(void) { - uint8_t *dest = (uint8_t *)BigBuf + FREE_BUFFER_OFFSET; + uint8_t LF_Results[256]; int i, adcval = 0, peak = 0, peakv = 0, peakf = 0; //ptr = 0 int vLf125 = 0, vLf134 = 0, vHf = 0; // in mV LED_B_ON(); - DbpString("Measuring antenna characteristics, please wait..."); - memset(dest,0,FREE_BUFFER_SIZE); /* * Sweeps the useful LF range of the proxmark from @@ -188,7 +186,7 @@ void MeasureAntennaTuning(void) FpgaDownloadAndGo(FPGA_BITSTREAM_LF); FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD); - for (i=255; i>19; i--) { + for (i=255; i>=19; i--) { WDT_HIT(); FpgaSendCommand(FPGA_CMD_SET_DIVISOR, i); SpinDelay(20); @@ -198,15 +196,17 @@ void MeasureAntennaTuning(void) if (i==95) vLf125 = adcval; // voltage at 125Khz if (i==89) vLf134 = adcval; // voltage at 134Khz - dest[i] = adcval>>8; // scale int to fit in byte for graphing purposes - if(dest[i] > peak) { + LF_Results[i] = adcval>>8; // scale int to fit in byte for graphing purposes + if(LF_Results[i] > peak) { peakv = adcval; - peak = dest[i]; + peak = LF_Results[i]; peakf = i; //ptr = i; } } + for (i=18; i >= 0; i--) LF_Results[i] = 0; + LED_A_ON(); // Let the FPGA drive the high-frequency antenna around 13.56 MHz. FpgaDownloadAndGo(FPGA_BITSTREAM_HF); @@ -216,14 +216,7 @@ void MeasureAntennaTuning(void) // can measure voltages up to 33000 mV vHf = (33000 * AvgAdc(ADC_CHAN_HF)) >> 10; -// c.cmd = CMD_MEASURED_ANTENNA_TUNING; -// c.arg[0] = (vLf125 << 0) | (vLf134 << 16); -// c.arg[1] = vHf; -// c.arg[2] = peakf | (peakv << 16); - - DbpString("Measuring complete, sending report back to host"); - cmd_send(CMD_MEASURED_ANTENNA_TUNING,vLf125|(vLf134<<16),vHf,peakf|(peakv<<16),0,0); -// UsbSendPacket((uint8_t *)&c, sizeof(c)); + cmd_send(CMD_MEASURED_ANTENNA_TUNING,vLf125|(vLf134<<16),vHf,peakf|(peakv<<16),LF_Results,256); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); LED_A_OFF(); LED_B_OFF(); diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index aed6a1fe..7dfa53e7 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -1714,7 +1714,7 @@ int ReaderReceive(uint8_t *receivedAnswer, uint8_t *parity) * fills the uid pointer unless NULL * fills resp_data unless NULL */ int iso14443a_select_card(byte_t* uid_ptr, iso14a_card_select_t* p_hi14a_card, uint32_t* cuid_ptr) { - uint8_t halt[] = { 0x50 }; // HALT + //uint8_t halt[] = { 0x50 }; // HALT uint8_t wupa[] = { 0x52 }; // WAKE-UP //uint8_t reqa[] = { 0x26 }; // REQUEST A uint8_t sel_all[] = { 0x93,0x20 }; @@ -1725,30 +1725,29 @@ int iso14443a_select_card(byte_t* uid_ptr, iso14a_card_select_t* p_hi14a_card, u byte_t uid_resp[4]; size_t uid_resp_len; - - uint8_t sak = 0x04; // cascade uid - int cascade_level = 0; - int len; + uint8_t sak = 0x04; // cascade uid + int cascade_level = 0; + int len; - ReaderTransmit(halt,sizeof(halt), NULL); + // test for the SKYLANDERS TOY. + //ReaderTransmit(halt,sizeof(halt), NULL); - // Broadcast for a card, WUPA (0x52) will force response from all cards in the field - ReaderTransmitBitsPar(wupa,7,0, NULL); + // Broadcast for a card, WUPA (0x52) will force response from all cards in the field + ReaderTransmitBitsPar(wupa,7,0, NULL); - // Receive the ATQA - if(!ReaderReceive(resp, resp_par)) return 0; - // Dbprintf("atqa: %02x %02x",resp[0],resp[1]); - - if(p_hi14a_card) { - memcpy(p_hi14a_card->atqa, resp, 2); - p_hi14a_card->uidlen = 0; - memset(p_hi14a_card->uid,0,10); - } + // Receive the ATQA + if(!ReaderReceive(resp, resp_par)) return 0; + + if(p_hi14a_card) { + memcpy(p_hi14a_card->atqa, resp, 2); + p_hi14a_card->uidlen = 0; + memset(p_hi14a_card->uid,0,10); + } - // clear uid - if (uid_ptr) { - memset(uid_ptr,0,10); - } + // clear uid + if (uid_ptr) { + memset(uid_ptr,0,10); + } // OK we will select at least at cascade 1, lets see if first byte of UID was 0x88 in // which case we need to make a cascade 2 request and select - this is a long UID @@ -1794,7 +1793,6 @@ int iso14443a_select_card(byte_t* uid_ptr, iso14a_card_select_t* p_hi14a_card, u } uid_resp_len = 4; - // calculate crypto UID. Always use last 4 Bytes. if(cuid_ptr) { *cuid_ptr = bytes_to_num(uid_resp, 4); @@ -1811,17 +1809,11 @@ int iso14443a_select_card(byte_t* uid_ptr, iso14a_card_select_t* p_hi14a_card, u if (!ReaderReceive(resp, resp_par)) return 0; sak = resp[0]; - //Dbprintf("SAK: %02x",resp[0]); - // Test if more parts of the uid are comming + // Test if more parts of the uid are coming if ((sak & 0x04) /* && uid_resp[0] == 0x88 */) { // Remove first byte, 0x88 is not an UID byte, it CT, see page 3 of: // http://www.nxp.com/documents/application_note/AN10927.pdf - // This was earlier: - //memcpy(uid_resp, uid_resp + 1, 3); - // But memcpy should not be used for overlapping arrays, - // and memmove appears to not be available in the arm build. - // Therefore: uid_resp[0] = uid_resp[1]; uid_resp[1] = uid_resp[2]; uid_resp[2] = uid_resp[3]; @@ -1844,24 +1836,24 @@ int iso14443a_select_card(byte_t* uid_ptr, iso14a_card_select_t* p_hi14a_card, u p_hi14a_card->ats_len = 0; } - if( (sak & 0x20) == 0) { - return 2; // non iso14443a compliant tag - } + if( (sak & 0x20) == 0) { + return 2; // non iso14443a compliant tag + } - // Request for answer to select - AppendCrc14443a(rats, 2); - ReaderTransmit(rats, sizeof(rats), NULL); + // Request for answer to select + AppendCrc14443a(rats, 2); + ReaderTransmit(rats, sizeof(rats), NULL); - if (!(len = ReaderReceive(resp,resp_par))) return 0; + if (!(len = ReaderReceive(resp, resp_par))) return 2; - if(p_hi14a_card) { - memcpy(p_hi14a_card->ats, resp, sizeof(p_hi14a_card->ats)); - p_hi14a_card->ats_len = len; - } + if(p_hi14a_card) { + memcpy(p_hi14a_card->ats, resp, sizeof(p_hi14a_card->ats)); + p_hi14a_card->ats_len = len; + } - // reset the PCB block number - iso14_pcb_blocknum = 0; - return 1; + // reset the PCB block number + iso14_pcb_blocknum = 0; + return 1; } void iso14443a_setup(uint8_t fpga_minor_mode) { diff --git a/client/cmddata.c b/client/cmddata.c index a1a0d484..0ba04b79 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -477,20 +477,52 @@ int CmdSamples(const char *Cmd) } int CmdTuneSamples(const char *Cmd) { - int cnt = 0; - int n = 255; - uint8_t got[255] = {0x00}; + int timeout = 0; + printf("\nMeasuring antenna characteristics, please wait..."); + + UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING}; + SendCommand(&c); + + UsbCommand resp; + while(!WaitForResponseTimeout(CMD_MEASURED_ANTENNA_TUNING,&resp,1000)) { + timeout++; + printf("."); + if (timeout > 7) { + PrintAndLog("\nNo response from Proxmark. Aborting..."); + return 1; + } + } - PrintAndLog("Reading %d samples\n", n); - GetFromBigBuf(got,n,7256); // armsrc/apps.h: #define FREE_BUFFER_OFFSET 7256 - WaitForResponse(CMD_ACK,NULL); - for (int j = 0; j < n; j++) { - GraphBuffer[cnt++] = ((int)got[j]) - 128; - } + int peakv, peakf; + int vLf125, vLf134, vHf; + vLf125 = resp.arg[0] & 0xffff; + vLf134 = resp.arg[0] >> 16; + vHf = resp.arg[1] & 0xffff;; + peakf = resp.arg[2] & 0xffff; + peakv = resp.arg[2] >> 16; + PrintAndLog(""); + PrintAndLog("# LF antenna: %5.2f V @ 125.00 kHz", vLf125/1000.0); + PrintAndLog("# LF antenna: %5.2f V @ 134.00 kHz", vLf134/1000.0); + PrintAndLog("# LF optimal: %5.2f V @%9.2f kHz", peakv/1000.0, 12000.0/(peakf+1)); + PrintAndLog("# HF antenna: %5.2f V @ 13.56 MHz", vHf/1000.0); + if (peakv<2000) + PrintAndLog("# Your LF antenna is unusable."); + else if (peakv<10000) + PrintAndLog("# Your LF antenna is marginal."); + if (vHf<2000) + PrintAndLog("# Your HF antenna is unusable."); + else if (vHf<5000) + PrintAndLog("# Your HF antenna is marginal."); + + for (int i = 0; i < 256; i++) { + GraphBuffer[i] = resp.d.asBytes[i] - 128; + } - PrintAndLog("Done! Divisor 89 is 134khz, 95 is 125khz.\n"); - GraphTraceLen = n; - RepaintGraphWindow(); + PrintAndLog("Done! Divisor 89 is 134khz, 95 is 125khz.\n"); + PrintAndLog("\n"); + GraphTraceLen = 256; + ShowGraphWindow(); + return 0; } diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index d1d440ee..46720d44 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -44,8 +44,11 @@ int CmdHF14AList(const char *Cmd) ShowWaitCycles = true; } - uint8_t trace[TRACE_BUFFER_SIZE]; - GetFromBigBuf(trace,TRACE_BUFFER_SIZE,0); +// for the time being. Need better Bigbuf handling. +#define TRACE_SIZE 3000 + + uint8_t trace[TRACE_SIZE]; + GetFromBigBuf(trace, TRACE_SIZE, 0); WaitForResponse(CMD_ACK,NULL); PrintAndLog("Recorded Activity"); @@ -67,7 +70,9 @@ int CmdHF14AList(const char *Cmd) for (;;) { - if( tracepos >= TRACE_BUFFER_SIZE) break; + if(tracepos >= TRACE_SIZE) { + break; + } timestamp = *((uint32_t *)(trace + tracepos)); if(tracepos == 0) { @@ -88,8 +93,9 @@ int CmdHF14AList(const char *Cmd) parity_len = (data_len-1)/8 + 1; - - if (tracepos + data_len + parity_len >= TRACE_BUFFER_SIZE) { break; } + if (tracepos + data_len + parity_len >= TRACE_SIZE) { + break; + } uint8_t *frame = trace + tracepos; tracepos += data_len; @@ -126,6 +132,7 @@ int CmdHF14AList(const char *Cmd) } else { sprintf(crc, ""); } + } EndOfTransmissionTimestamp = timestamp + duration; @@ -137,6 +144,7 @@ int CmdHF14AList(const char *Cmd) crc); bool next_isResponse = *((uint16_t *)(trace + tracepos + 6)) & 0x8000; + if (ShowWaitCycles && !isResponse && next_isResponse) { uint32_t next_timestamp = *((uint32_t *)(trace + tracepos)); if (next_timestamp != 0x44444444) { @@ -147,8 +155,9 @@ int CmdHF14AList(const char *Cmd) (next_timestamp - EndOfTransmissionTimestamp)); } } - } + } + return 0; } @@ -159,26 +168,30 @@ void iso14a_set_timeout(uint32_t timeout) { int CmdHF14AReader(const char *Cmd) { - UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}}; + //UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}}; + UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT , 0, 0}}; SendCommand(&c); UsbCommand resp; WaitForResponse(CMD_ACK,&resp); - iso14a_card_select_t *card = (iso14a_card_select_t *)resp.d.asBytes; + iso14a_card_select_t card; + memcpy(&card, (iso14a_card_select_t *)resp.d.asBytes, sizeof(iso14a_card_select_t)); - if(resp.arg[0] == 0) { + uint64_t select_status = resp.arg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS + + if(select_status == 0) { PrintAndLog("iso14443a card select failed"); return 0; } - PrintAndLog("ATQA : %02x %02x", card->atqa[0], card->atqa[1]); - PrintAndLog(" UID : %s", sprint_hex(card->uid, card->uidlen)); - PrintAndLog(" SAK : %02x [%d]", card->sak, resp.arg[0]); + PrintAndLog("ATQA : %02x %02x", card.atqa[1], card.atqa[0]); + PrintAndLog(" UID : %s", sprint_hex(card.uid, card.uidlen)); + PrintAndLog(" SAK : %02x [%d]", card.sak, resp.arg[0]); - switch (card->sak) { + switch (card.sak) { case 0x00: PrintAndLog("TYPE : NXP MIFARE Ultralight | Ultralight C"); break; - case 0x01: PrintAndLog("TYPE : NXP TNP3xxx Activision Game Appliance"); break; + case 0x01: PrintAndLog("TYPE : NXP TNP3xxx Activision Game Appliance"); break; case 0x04: PrintAndLog("TYPE : NXP MIFARE (various !DESFire !DESFire EV1)"); break; case 0x08: PrintAndLog("TYPE : NXP MIFARE CLASSIC 1k | Plus 2k SL1"); break; case 0x09: PrintAndLog("TYPE : NXP MIFARE Mini 0.3k"); break; @@ -193,67 +206,107 @@ int CmdHF14AReader(const char *Cmd) case 0x98: PrintAndLog("TYPE : Gemplus MPCOS"); break; default: ; } - if(resp.arg[0] == 1) { + + + // try to request ATS even if tag claims not to support it + if (select_status == 2) { + uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0 + c.arg[0] = ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT; + c.arg[1] = 2; + c.arg[2] = 0; + memcpy(c.d.asBytes, rats, 2); + SendCommand(&c); + WaitForResponse(CMD_ACK,&resp); + + memcpy(&card.ats, resp.d.asBytes, resp.arg[0]); + card.ats_len = resp.arg[0]; // note: ats_len includes CRC Bytes + } + + // disconnect + c.arg[0] = 0; + c.arg[1] = 0; + c.arg[2] = 0; + SendCommand(&c); + + + if(card.ats_len >= 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes bool ta1 = 0, tb1 = 0, tc1 = 0; int pos; - PrintAndLog(" ATS : %s", sprint_hex(card->ats, card->ats_len)); - if (card->ats_len > 0) { - PrintAndLog(" - TL : length is %d bytes", card->ats[0]); + if (select_status == 2) { + PrintAndLog("SAK incorrectly claims that card doesn't support RATS"); + } + PrintAndLog(" ATS : %s", sprint_hex(card.ats, card.ats_len)); + PrintAndLog(" - TL : length is %d bytes", card.ats[0]); + if (card.ats[0] != card.ats_len - 2) { + PrintAndLog("ATS may be corrupted. Length of ATS (%d bytes incl. 2 Bytes CRC) doesn't match TL", card.ats_len); } - if (card->ats_len > 1) { - ta1 = (card->ats[1] & 0x10) == 0x10; - tb1 = (card->ats[1] & 0x20) == 0x20; - tc1 = (card->ats[1] & 0x40) == 0x40; + + if (card.ats[0] > 1) { // there is a format byte (T0) + ta1 = (card.ats[1] & 0x10) == 0x10; + tb1 = (card.ats[1] & 0x20) == 0x20; + tc1 = (card.ats[1] & 0x40) == 0x40; + int16_t fsci = card.ats[1] & 0x0f; PrintAndLog(" - T0 : TA1 is%s present, TB1 is%s present, " - "TC1 is%s present, FSCI is %d", + "TC1 is%s present, FSCI is %d (FSC = %ld)", (ta1 ? "" : " NOT"), (tb1 ? "" : " NOT"), (tc1 ? "" : " NOT"), - (card->ats[1] & 0x0f)); + fsci, + fsci < 5 ? (fsci - 2) * 8 : + fsci < 8 ? (fsci - 3) * 32 : + fsci == 8 ? 256 : + -1 + ); } pos = 2; - if (ta1 && card->ats_len > pos) { + if (ta1) { char dr[16], ds[16]; dr[0] = ds[0] = '\0'; - if (card->ats[pos] & 0x10) strcat(ds, "2, "); - if (card->ats[pos] & 0x20) strcat(ds, "4, "); - if (card->ats[pos] & 0x40) strcat(ds, "8, "); - if (card->ats[pos] & 0x01) strcat(dr, "2, "); - if (card->ats[pos] & 0x02) strcat(dr, "4, "); - if (card->ats[pos] & 0x04) strcat(dr, "8, "); + if (card.ats[pos] & 0x10) strcat(ds, "2, "); + if (card.ats[pos] & 0x20) strcat(ds, "4, "); + if (card.ats[pos] & 0x40) strcat(ds, "8, "); + if (card.ats[pos] & 0x01) strcat(dr, "2, "); + if (card.ats[pos] & 0x02) strcat(dr, "4, "); + if (card.ats[pos] & 0x04) strcat(dr, "8, "); if (strlen(ds) != 0) ds[strlen(ds) - 2] = '\0'; if (strlen(dr) != 0) dr[strlen(dr) - 2] = '\0'; PrintAndLog(" - TA1 : different divisors are%s supported, " "DR: [%s], DS: [%s]", - (card->ats[pos] & 0x80 ? " NOT" : ""), dr, ds); + (card.ats[pos] & 0x80 ? " NOT" : ""), dr, ds); pos++; } - if (tb1 && card->ats_len > pos) { - PrintAndLog(" - TB1 : SFGI = %d, FWI = %d", - (card->ats[pos] & 0x08), - (card->ats[pos] & 0x80) >> 4); + if (tb1) { + uint32_t sfgi = card.ats[pos] & 0x0F; + uint32_t fwi = card.ats[pos] >> 4; + PrintAndLog(" - TB1 : SFGI = %d (SFGT = %s%ld/fc), FWI = %d (FWT = %ld/fc)", + (sfgi), + sfgi ? "" : "(not needed) ", + sfgi ? (1 << 12) << sfgi : 0, + fwi, + (1 << 12) << fwi + ); pos++; } - if (tc1 && card->ats_len > pos) { + if (tc1) { PrintAndLog(" - TC1 : NAD is%s supported, CID is%s supported", - (card->ats[pos] & 0x01) ? "" : " NOT", - (card->ats[pos] & 0x02) ? "" : " NOT"); + (card.ats[pos] & 0x01) ? "" : " NOT", + (card.ats[pos] & 0x02) ? "" : " NOT"); pos++; } - if (card->ats_len > pos) { + if (card.ats[0] > pos) { char *tip = ""; - if (card->ats_len - pos > 7) { - if (memcmp(card->ats + pos, "\xC1\x05\x2F\x2F\x01\xBC\xD6", 7) == 0) { + if (card.ats[0] - pos >= 7) { + if (memcmp(card.ats + pos, "\xC1\x05\x2F\x2F\x01\xBC\xD6", 7) == 0) { tip = "-> MIFARE Plus X 2K or 4K"; - } else if (memcmp(card->ats + pos, "\xC1\x05\x2F\x2F\x00\x35\xC7", 7) == 0) { + } else if (memcmp(card.ats + pos, "\xC1\x05\x2F\x2F\x00\x35\xC7", 7) == 0) { tip = "-> MIFARE Plus S 2K or 4K"; } } - PrintAndLog(" - HB : %s%s", sprint_hex(card->ats + pos, card->ats_len - pos - 2), tip); - if (card->ats[pos] == 0xC1) { + PrintAndLog(" - HB : %s%s", sprint_hex(card.ats + pos, card.ats[0] - pos), tip); + if (card.ats[pos] == 0xC1) { PrintAndLog(" c1 -> Mifare or (multiple) virtual cards of various type"); PrintAndLog(" %02x -> Length is %d bytes", - card->ats[pos + 1], card->ats[pos + 1]); - switch (card->ats[pos + 2] & 0xf0) { + card.ats[pos + 1], card.ats[pos + 1]); + switch (card.ats[pos + 2] & 0xf0) { case 0x10: PrintAndLog(" 1x -> MIFARE DESFire"); break; @@ -261,7 +314,7 @@ int CmdHF14AReader(const char *Cmd) PrintAndLog(" 2x -> MIFARE Plus"); break; } - switch (card->ats[pos + 2] & 0x0f) { + switch (card.ats[pos + 2] & 0x0f) { case 0x00: PrintAndLog(" x0 -> <1 kByte"); break; @@ -278,7 +331,7 @@ int CmdHF14AReader(const char *Cmd) PrintAndLog(" x0 -> 8 kByte"); break; } - switch (card->ats[pos + 3] & 0xf0) { + switch (card.ats[pos + 3] & 0xf0) { case 0x00: PrintAndLog(" 0x -> Engineering sample"); break; @@ -286,7 +339,7 @@ int CmdHF14AReader(const char *Cmd) PrintAndLog(" 2x -> Released"); break; } - switch (card->ats[pos + 3] & 0x0f) { + switch (card.ats[pos + 3] & 0x0f) { case 0x00: PrintAndLog(" x0 -> Generation 1"); break; @@ -297,7 +350,7 @@ int CmdHF14AReader(const char *Cmd) PrintAndLog(" x2 -> Generation 3"); break; } - switch (card->ats[pos + 4] & 0x0f) { + switch (card.ats[pos + 4] & 0x0f) { case 0x00: PrintAndLog(" x0 -> Only VCSL supported"); break; @@ -311,10 +364,10 @@ int CmdHF14AReader(const char *Cmd) } } } else { - PrintAndLog("proprietary non iso14443a-4 card found, RATS not supported"); + PrintAndLog("proprietary non iso14443-4 card found, RATS not supported"); } - return resp.arg[0]; + return select_status; } // Collect ISO14443 Type A UIDs @@ -336,20 +389,17 @@ int CmdHF14ACUIDs(const char *Cmd) UsbCommand resp; WaitForResponse(CMD_ACK,&resp); - uint8_t *uid = resp.d.asBytes; - iso14a_card_select_t *card = (iso14a_card_select_t *)(uid + 12); + iso14a_card_select_t *card = (iso14a_card_select_t *) resp.d.asBytes; // check if command failed if (resp.arg[0] == 0) { PrintAndLog("Card select failed."); } else { - // check if UID is 4 bytes - if ((card->atqa[1] & 0xC0) == 0) { - PrintAndLog("%02X%02X%02X%02X", - *uid, *(uid + 1), *(uid + 2), *(uid + 3)); - } else { - PrintAndLog("UID longer than 4 bytes"); + char uid_string[20]; + for (uint16_t i = 0; i < card->uidlen; i++) { + sprintf(&uid_string[2*i], "%02X", card->uid[i]); } + PrintAndLog("%s", uid_string); } } PrintAndLog("End: %u", time(NULL)); diff --git a/client/cmdhfmfu.c b/client/cmdhfmfu.c index afe54bb4..52b7ad14 100644 --- a/client/cmdhfmfu.c +++ b/client/cmdhfmfu.c @@ -158,10 +158,11 @@ int CmdHF14AMfURdBl(const char *Cmd){ if (isOK) PrintAndLog("isOk:%02x data:%s", isOK, sprint_hex(data, 4)); else - PrintAndLog("isOk:%02x", isOK); - } else { - PrintAndLog("Command execute timeout"); + PrintAndLog("isOk:%02x", isOK); } + else { + PrintAndLog("Command execute timeout"); + } return 0; } @@ -171,7 +172,7 @@ int CmdHF14AMfURdBl(const char *Cmd){ int CmdHF14AMfURdCard(const char *Cmd){ int i; uint8_t BlockNo = 0; - int Pages=16; + int pages=16; uint8_t *lockbytes_t=NULL; uint8_t lockbytes[2]={0x00}; bool bit[16]={0x00}; @@ -191,7 +192,7 @@ int CmdHF14AMfURdCard(const char *Cmd){ PrintAndLog("Dumping Ultralight Card Data..."); } PrintAndLog("Attempting to Read Ultralight... "); - UsbCommand c = {CMD_MIFAREU_READCARD, {BlockNo, Pages}}; + UsbCommand c = {CMD_MIFAREU_READCARD, {BlockNo, pages}}; SendCommand(&c); UsbCommand resp; @@ -231,7 +232,7 @@ int CmdHF14AMfURdCard(const char *Cmd){ PrintAndLog(" OneTimePad :%s ", sprint_hex(data + 3*4, 4)); PrintAndLog(""); - for (i = 0; i < Pages; i++) { + for (i = 0; i < pages; i++) { switch(i){ case 2: //process lock bytes @@ -634,7 +635,7 @@ int CmdHF14AMfUCRdCard(const char *Cmd){ if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) { isOK = resp.arg[0] & 0xff; data = resp.d.asBytes; - //Pages=sizeof(data)/sizeof(data[0]); + PrintAndLog("isOk:%02x", isOK); if (isOK) for (i = 0; i < Pages; i++) { @@ -833,7 +834,7 @@ int CmdHF14AMfUCDump(const char *Cmd){ return 1; } PrintAndLog("Dumping Ultralight C Card Data..."); - PrintAndLog("Attempting to Read Ultralight C... "); + PrintAndLog("Attempting to Read Ultralight C... "); UsbCommand c = {CMD_MIFAREU_READCARD, {BlockNo,Pages}}; SendCommand(&c); UsbCommand resp; @@ -1130,14 +1131,14 @@ int CmdHF14AMfUCWrBl(const char *Cmd){ //------------------------------------ static command_t CommandTable[] = { - {"help", CmdHelp, 1,"This help"}, + {"help", CmdHelp, 1,"This help"}, {"dbg", CmdHF14AMfDbg, 0,"Set default debug mode"}, - {"urdbl", CmdHF14AMfURdBl, 0,"Read MIFARE Ultralight block"}, - {"urdcard", CmdHF14AMfURdCard, 0,"Read MIFARE Ultralight Card"}, + {"urdbl", CmdHF14AMfURdBl, 0,"Read MIFARE Ultralight block"}, + {"urdcard", CmdHF14AMfURdCard, 0,"Read MIFARE Ultralight Card"}, {"udump", CmdHF14AMfUDump, 0,"Dump MIFARE Ultralight tag to binary file"}, {"uwrbl", CmdHF14AMfUWrBl, 0,"Write MIFARE Ultralight block"}, - {"ucrdbl", CmdHF14AMfUCRdBl, 0,"Read MIFARE Ultralight C block"}, - {"ucrdcard",CmdHF14AMfUCRdCard, 0,"Read MIFARE Ultralight C Card"}, + {"ucrdbl", CmdHF14AMfUCRdBl, 0,"Read MIFARE Ultralight C block"}, + {"ucrdcard",CmdHF14AMfUCRdCard, 0,"Read MIFARE Ultralight C Card"}, {"ucdump", CmdHF14AMfUCDump, 0,"Dump MIFARE Ultralight C tag to binary file"}, {"ucwrbl", CmdHF14AMfUCWrBl, 0,"Write MIFARE Ultralight C block"}, {"auth", CmdHF14AMfucAuth, 0,"Ultralight C Authentication"}, @@ -1145,7 +1146,6 @@ static command_t CommandTable[] = }; int CmdHFMFUltra(const char *Cmd){ - // flush WaitForResponseTimeout(CMD_ACK,NULL,100); CmdsParse(CommandTable, Cmd); return 0; diff --git a/client/cmdhw.c b/client/cmdhw.c index 28cd01ba..642f63c5 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -391,23 +391,7 @@ int CmdSetMux(const char *Cmd) int CmdTune(const char *Cmd) { - UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING}; - SendCommand(&c); - - char cmdp = param_getchar(Cmd, 0); - if (cmdp == 'h' || cmdp == 'H') { - PrintAndLog("Usage: hw tune

"); - PrintAndLog(""); - PrintAndLog(" sample: hw tune"); - PrintAndLog(" hw tune p"); - return 0; - } - - if ( cmdp == 'p' || cmdp == 'P'){ - ShowGraphWindow(); - CmdTuneSamples(""); - } - return 0; + return CmdTuneSamples(Cmd); } int CmdVersion(const char *Cmd) diff --git a/client/cmdmain.c b/client/cmdmain.c index 0641f9c8..b3f04e10 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -26,15 +26,8 @@ #include "util.h" #include "cmdscript.h" -int delta125[2]; -int delta134[2]; -int deltahf[2]; -int deltaReset = 0; unsigned int current_command = CMD_UNKNOWN; -//unsigned int received_command = CMD_UNKNOWN; -//UsbCommand current_response; -//UsbCommand current_response_user; static int CmdHelp(const char *Cmd); static int CmdQuit(const char *Cmd); @@ -49,14 +42,14 @@ static int cmd_tail;//Starts as 0 static command_t CommandTable[] = { - {"help", CmdHelp, 1, "This help. Use ' help' for details of a particular command."}, - {"data", CmdData, 1, "{ Plot window / data buffer manipulation... }"}, - {"hf", CmdHF, 1, "{ High Frequency commands... }"}, - {"hw", CmdHW, 1, "{ Hardware commands... }"}, - {"lf", CmdLF, 1, "{ Low Frequency commands... }"}, - {"script", CmdScript, 1,"{ Scripting commands }"}, - {"quit", CmdQuit, 1, "Exit program"}, - {"exit", CmdQuit, 1, "Exit program"}, + {"help", CmdHelp, 1, "This help. Use ' help' for details of a particular command."}, + {"data", CmdData, 1, "{ Plot window / data buffer manipulation... }"}, + {"hf", CmdHF, 1, "{ High Frequency commands... }"}, + {"hw", CmdHW, 1, "{ Hardware commands... }"}, + {"lf", CmdLF, 1, "{ Low Frequency commands... }"}, + {"script", CmdScript, 1,"{ Scripting commands }"}, + {"quit", CmdQuit, 1, "Exit program"}, + {"exit", CmdQuit, 1, "Exit program"}, {NULL, NULL, 0, NULL} }; @@ -138,29 +131,25 @@ int getCommand(UsbCommand* response) */ bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout) { - UsbCommand resp; + UsbCommand resp; - if (response == NULL) { - - response = &resp; - } - - // Wait until the command is received - for(size_t dm_seconds=0; dm_seconds < ms_timeout/10; dm_seconds++) { - - while(getCommand(response)) - { - if(response->cmd == cmd){ - //We got what we expected - return true; - } - - } - msleep(10); // XXX ugh - if (dm_seconds == 200) { // Two seconds elapsed - PrintAndLog("Waiting for a response from the proxmark..."); - PrintAndLog("Don't forget to cancel its operation first by pressing on the button"); - } + if (response == NULL) + response = &resp; + + + // Wait until the command is received + for(size_t dm_seconds=0; dm_seconds < ms_timeout/10; dm_seconds++) { + + while(getCommand(response)) { + if(response->cmd == cmd){ + return true; + } + } + msleep(10); // XXX ugh + if (dm_seconds == 200) { // Two seconds elapsed + PrintAndLog("Waiting for a response from the proxmark..."); + PrintAndLog("Don't forget to cancel its operation first by pressing on the button"); + } } return false; } @@ -183,114 +172,30 @@ void CommandReceived(char *Cmd) { //----------------------------------------------------------------------------- void UsbCommandReceived(UsbCommand *UC) { - /* - // Debug - printf("UsbCommand length[len=%zd]\n",sizeof(UsbCommand)); - printf(" cmd[len=%zd]: %"llx"\n",sizeof(UC->cmd),UC->cmd); - printf(" arg0[len=%zd]: %"llx"\n",sizeof(UC->arg[0]),UC->arg[0]); - printf(" arg1[len=%zd]: %"llx"\n",sizeof(UC->arg[1]),UC->arg[1]); - printf(" arg2[len=%zd]: %"llx"\n",sizeof(UC->arg[2]),UC->arg[2]); - printf(" data[len=%zd]: %02x%02x%02x...\n",sizeof(UC->d.asBytes),UC->d.asBytes[0],UC->d.asBytes[1],UC->d.asBytes[2]); - */ - - // printf("%s(%x) current cmd = %x\n", __FUNCTION__, c->cmd, current_command); - // If we recognize a response, return to avoid further processing - switch(UC->cmd) { - // First check if we are handling a debug message - case CMD_DEBUG_PRINT_STRING: { - char s[USB_CMD_DATA_SIZE+1] = {0x00}; - size_t len = MIN(UC->arg[0],USB_CMD_DATA_SIZE); - memcpy(s,UC->d.asBytes,len); - PrintAndLog("#db# %s ", s); - return; - } break; - - case CMD_DEBUG_PRINT_INTEGERS: { - PrintAndLog("#db# %08x, %08x, %08x \r\n", UC->arg[0], UC->arg[1], UC->arg[2]); - return; - } break; - - case CMD_MEASURED_ANTENNA_TUNING: { - int peakv, peakf; - int vLf125, vLf134, vHf; - vLf125 = UC->arg[0] & 0xffff; - vLf134 = UC->arg[0] >> 16; - vHf = UC->arg[1] & 0xffff;; - peakf = UC->arg[2] & 0xffff; - peakv = UC->arg[2] >> 16; - - //Reset delta trigger every 3:d time - - if ( deltaReset == 4){ - delta125[0] = vLf125; - delta134[0] = vLf134; - deltahf[0] = vHf; - } else if ( deltaReset == 2){ - delta125[1] = vLf125; - delta134[1] = vLf134; - deltahf[1] = vHf; - } - - if ( deltaReset == 0){ - + switch(UC->cmd) { + // First check if we are handling a debug message + case CMD_DEBUG_PRINT_STRING: { + char s[USB_CMD_DATA_SIZE+1] = {0x00}; + size_t len = MIN(UC->arg[0],USB_CMD_DATA_SIZE); + memcpy(s,UC->d.asBytes,len); + PrintAndLog("#db# %s ", s); + return; + } break; + + case CMD_DEBUG_PRINT_INTEGERS: { + PrintAndLog("#db# %08x, %08x, %08x \r\n", UC->arg[0], UC->arg[1], UC->arg[2]); + return; + } break; + + case CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K: { + sample_buf_len += UC->arg[1]; + memcpy(sample_buf+(UC->arg[0]),UC->d.asBytes,UC->arg[1]); + } break; + + default: + break; } - - PrintAndLog(""); - PrintAndLog("# LF antenna: %5.2f V @ 125.00 kHz", vLf125/1000.0); - PrintAndLog("# LF antenna: %5.2f V @ 134.00 kHz", vLf134/1000.0); - PrintAndLog("# LF optimal: %5.2f V @ %9.2f kHz", peakv/1000.0, 12000.0/(peakf+1)); - PrintAndLog("# HF antenna: %5.2f V @ 13.56 MHz", vHf/1000.0); - if (peakv<2000) - PrintAndLog("# Your LF antenna is unusable."); - else if (peakv<10000) - PrintAndLog("# Your LF antenna is marginal."); - if (vHf<2000) - PrintAndLog("# Your HF antenna is unusable."); - else if (vHf<5000) - PrintAndLog("# Your HF antenna is marginal."); - } - - deltaReset = (deltaReset == 0) ? 4 : deltaReset>>1; - break; - - case CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K: { -// printf("received samples: "); -// print_hex(UC->d.asBytes,512); - sample_buf_len += UC->arg[1]; -// printf("samples: %zd offset: %d\n",sample_buf_len,UC->arg[0]); - memcpy(sample_buf+(UC->arg[0]),UC->d.asBytes,UC->arg[1]); - } break; - - -// case CMD_ACK: { -// PrintAndLog("Receive ACK\n"); -// } break; - - default: { - // Maybe it's a response - /* - switch(current_command) { - case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K: { - if (UC->cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) { - PrintAndLog("unrecognized command %08x\n", UC->cmd); - break; - } -// int i; - PrintAndLog("received samples %d\n",UC->arg[0]); - memcpy(sample_buf+UC->arg[0],UC->d.asBytes,48); - sample_buf_len += 48; -// for(i=0; i<48; i++) sample_buf[i] = UC->d.asBytes[i]; - //received_command = UC->cmd; - } break; - - default: { - } break; - }*/ - } - break; - } storeCommand(UC); - } -- 2.39.2