mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
Viva la revolucion
This commit is contained in:
parent
8bfc5c1b47
commit
be15ad7fec
53 changed files with 861 additions and 870 deletions
350
armsrc/appmain.c
350
armsrc/appmain.c
|
@ -633,37 +633,33 @@ void ListenReaderField(int limit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
uint64_t cmd; // To accommodate old cmd, can be reduced to uint16_t once all old cmds are gone.
|
uint64_t cmd; // To accommodate old cmd, can be reduced to uint16_t once all old cmds are gone.
|
||||||
UsbCommandNGPreamble *pre_ng = (UsbCommandNGPreamble *)packet;
|
|
||||||
uint8_t *data_ng = packet + sizeof(UsbCommandNGPreamble);
|
|
||||||
uint16_t datalen_ng = pre_ng->length;
|
|
||||||
|
|
||||||
// For cmd handlers still using old cmd format:
|
// For cmd handlers still using old cmd format:
|
||||||
UsbCommand *c = (UsbCommand *)packet;
|
if (packet->ng) {
|
||||||
if (cmd_ng) {
|
cmd = packet->core.ng.cmd;
|
||||||
cmd = pre_ng->cmd;
|
// Dbprintf("received NG frame with %d bytes payload, with command: 0x%04x", packet->length, cmd);
|
||||||
// Dbprintf("received %d bytes payload, with command: 0x%04x", datalen_ng, cmd);
|
|
||||||
} else {
|
} else {
|
||||||
// Dbprintf("received %d bytes, with command: 0x%04x and args: %d %d %d", USB_CMD_DATA_SIZE, c->cmd, c->arg[0], c->arg[1], c->arg[2]);
|
cmd = packet->core.old.cmd;
|
||||||
cmd = c->cmd;
|
// Dbprintf("received OLD frame of %d bytes, with command: 0x%04x and args: %d %d %d", packet->length, packet->core.old.cmd, packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
#ifdef WITH_LF
|
#ifdef WITH_LF
|
||||||
case CMD_SET_LF_T55XX_CONFIG:
|
case CMD_SET_LF_T55XX_CONFIG:
|
||||||
setT55xxConfig(c->arg[0], (t55xx_config *) c->d.asBytes);
|
setT55xxConfig(packet->core.old.arg[0], (t55xx_config *) packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_SET_LF_SAMPLING_CONFIG:
|
case CMD_SET_LF_SAMPLING_CONFIG:
|
||||||
setSamplingConfig((sample_config *) c->d.asBytes);
|
setSamplingConfig((sample_config *) packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K: {
|
case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K: {
|
||||||
uint32_t bits = SampleLF(c->arg[0], c->arg[1]);
|
uint32_t bits = SampleLF(packet->core.old.arg[0], packet->core.old.arg[1]);
|
||||||
cmd_send(CMD_ACK, bits, 0, 0, 0, 0);
|
cmd_send(CMD_ACK, bits, 0, 0, 0, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K:
|
case CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K:
|
||||||
ModThenAcquireRawAdcSamples125k(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
ModThenAcquireRawAdcSamples125k(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_LF_SNIFF_RAW_ADC_SAMPLES: {
|
case CMD_LF_SNIFF_RAW_ADC_SAMPLES: {
|
||||||
uint32_t bits = SniffLF();
|
uint32_t bits = SniffLF();
|
||||||
|
@ -672,73 +668,73 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
}
|
}
|
||||||
case CMD_HID_DEMOD_FSK: {
|
case CMD_HID_DEMOD_FSK: {
|
||||||
uint32_t high, low;
|
uint32_t high, low;
|
||||||
CmdHIDdemodFSK(c->arg[0], &high, &low, 1);
|
CmdHIDdemodFSK(packet->core.old.arg[0], &high, &low, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_HID_SIM_TAG:
|
case CMD_HID_SIM_TAG:
|
||||||
CmdHIDsimTAG(c->arg[0], c->arg[1], 1);
|
CmdHIDsimTAG(packet->core.old.arg[0], packet->core.old.arg[1], 1);
|
||||||
break;
|
break;
|
||||||
case CMD_FSK_SIM_TAG:
|
case CMD_FSK_SIM_TAG:
|
||||||
CmdFSKsimTAG(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes, 1);
|
CmdFSKsimTAG(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes, 1);
|
||||||
break;
|
break;
|
||||||
case CMD_ASK_SIM_TAG:
|
case CMD_ASK_SIM_TAG:
|
||||||
CmdASKsimTag(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes, 1);
|
CmdASKsimTag(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes, 1);
|
||||||
break;
|
break;
|
||||||
case CMD_PSK_SIM_TAG:
|
case CMD_PSK_SIM_TAG:
|
||||||
CmdPSKsimTag(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes, 1);
|
CmdPSKsimTag(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes, 1);
|
||||||
break;
|
break;
|
||||||
case CMD_HID_CLONE_TAG:
|
case CMD_HID_CLONE_TAG:
|
||||||
CopyHIDtoT55x7(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes[0]);
|
CopyHIDtoT55x7(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_IO_DEMOD_FSK: {
|
case CMD_IO_DEMOD_FSK: {
|
||||||
uint32_t high, low;
|
uint32_t high, low;
|
||||||
CmdIOdemodFSK(c->arg[0], &high, &low, 1);
|
CmdIOdemodFSK(packet->core.old.arg[0], &high, &low, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_IO_CLONE_TAG:
|
case CMD_IO_CLONE_TAG:
|
||||||
CopyIOtoT55x7(c->arg[0], c->arg[1]);
|
CopyIOtoT55x7(packet->core.old.arg[0], packet->core.old.arg[1]);
|
||||||
break;
|
break;
|
||||||
case CMD_EM410X_DEMOD: {
|
case CMD_EM410X_DEMOD: {
|
||||||
uint32_t high;
|
uint32_t high;
|
||||||
uint64_t low;
|
uint64_t low;
|
||||||
CmdEM410xdemod(c->arg[0], &high, &low, 1);
|
CmdEM410xdemod(packet->core.old.arg[0], &high, &low, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_EM410X_WRITE_TAG:
|
case CMD_EM410X_WRITE_TAG:
|
||||||
WriteEM410x(c->arg[0], c->arg[1], c->arg[2]);
|
WriteEM410x(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_READ_TI_TYPE:
|
case CMD_READ_TI_TYPE:
|
||||||
ReadTItag();
|
ReadTItag();
|
||||||
break;
|
break;
|
||||||
case CMD_WRITE_TI_TYPE:
|
case CMD_WRITE_TI_TYPE:
|
||||||
WriteTItag(c->arg[0], c->arg[1], c->arg[2]);
|
WriteTItag(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_SIMULATE_TAG_125K:
|
case CMD_SIMULATE_TAG_125K:
|
||||||
LED_A_ON();
|
LED_A_ON();
|
||||||
SimulateTagLowFrequency(c->arg[0], c->arg[1], 1);
|
SimulateTagLowFrequency(packet->core.old.arg[0], packet->core.old.arg[1], 1);
|
||||||
LED_A_OFF();
|
LED_A_OFF();
|
||||||
break;
|
break;
|
||||||
case CMD_LF_SIMULATE_BIDIR:
|
case CMD_LF_SIMULATE_BIDIR:
|
||||||
SimulateTagLowFrequencyBidir(c->arg[0], c->arg[1]);
|
SimulateTagLowFrequencyBidir(packet->core.old.arg[0], packet->core.old.arg[1]);
|
||||||
break;
|
break;
|
||||||
case CMD_INDALA_CLONE_TAG:
|
case CMD_INDALA_CLONE_TAG:
|
||||||
CopyIndala64toT55x7(c->d.asDwords[0], c->d.asDwords[1]);
|
CopyIndala64toT55x7(packet->core.old.d.asDwords[0], packet->core.old.d.asDwords[1]);
|
||||||
break;
|
break;
|
||||||
case CMD_INDALA_CLONE_TAG_L:
|
case CMD_INDALA_CLONE_TAG_L:
|
||||||
CopyIndala224toT55x7(
|
CopyIndala224toT55x7(
|
||||||
c->d.asDwords[0], c->d.asDwords[1], c->d.asDwords[2], c->d.asDwords[3],
|
packet->core.old.d.asDwords[0], packet->core.old.d.asDwords[1], packet->core.old.d.asDwords[2], packet->core.old.d.asDwords[3],
|
||||||
c->d.asDwords[4], c->d.asDwords[5], c->d.asDwords[6]
|
packet->core.old.d.asDwords[4], packet->core.old.d.asDwords[5], packet->core.old.d.asDwords[6]
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case CMD_T55XX_READ_BLOCK: {
|
case CMD_T55XX_READ_BLOCK: {
|
||||||
T55xxReadBlock(c->arg[0], c->arg[1], c->arg[2]);
|
T55xxReadBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_T55XX_WRITE_BLOCK:
|
case CMD_T55XX_WRITE_BLOCK:
|
||||||
T55xxWriteBlock(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes[0]);
|
T55xxWriteBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_T55XX_WAKEUP:
|
case CMD_T55XX_WAKEUP:
|
||||||
T55xxWakeUp(c->arg[0]);
|
T55xxWakeUp(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_T55XX_RESET_READ:
|
case CMD_T55XX_RESET_READ:
|
||||||
T55xxResetRead();
|
T55xxResetRead();
|
||||||
|
@ -751,58 +747,58 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
break;
|
break;
|
||||||
case CMD_PCF7931_WRITE:
|
case CMD_PCF7931_WRITE:
|
||||||
WritePCF7931(
|
WritePCF7931(
|
||||||
c->d.asBytes[0], c->d.asBytes[1], c->d.asBytes[2], c->d.asBytes[3],
|
packet->core.old.d.asBytes[0], packet->core.old.d.asBytes[1], packet->core.old.d.asBytes[2], packet->core.old.d.asBytes[3],
|
||||||
c->d.asBytes[4], c->d.asBytes[5], c->d.asBytes[6], c->d.asBytes[9],
|
packet->core.old.d.asBytes[4], packet->core.old.d.asBytes[5], packet->core.old.d.asBytes[6], packet->core.old.d.asBytes[9],
|
||||||
c->d.asBytes[7] - 128, c->d.asBytes[8] - 128,
|
packet->core.old.d.asBytes[7] - 128, packet->core.old.d.asBytes[8] - 128,
|
||||||
c->arg[0],
|
packet->core.old.arg[0],
|
||||||
c->arg[1],
|
packet->core.old.arg[1],
|
||||||
c->arg[2]
|
packet->core.old.arg[2]
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case CMD_EM4X_READ_WORD:
|
case CMD_EM4X_READ_WORD:
|
||||||
EM4xReadWord(c->arg[0], c->arg[1], c->arg[2]);
|
EM4xReadWord(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_EM4X_WRITE_WORD:
|
case CMD_EM4X_WRITE_WORD:
|
||||||
EM4xWriteWord(c->arg[0], c->arg[1], c->arg[2]);
|
EM4xWriteWord(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_AWID_DEMOD_FSK: {
|
case CMD_AWID_DEMOD_FSK: {
|
||||||
uint32_t high, low;
|
uint32_t high, low;
|
||||||
// Set realtime AWID demodulation
|
// Set realtime AWID demodulation
|
||||||
CmdAWIDdemodFSK(c->arg[0], &high, &low, 1);
|
CmdAWIDdemodFSK(packet->core.old.arg[0], &high, &low, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_VIKING_CLONE_TAG:
|
case CMD_VIKING_CLONE_TAG:
|
||||||
CopyVikingtoT55xx(c->arg[0], c->arg[1], c->arg[2]);
|
CopyVikingtoT55xx(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_COTAG:
|
case CMD_COTAG:
|
||||||
Cotag(c->arg[0]);
|
Cotag(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_HITAG
|
#ifdef WITH_HITAG
|
||||||
case CMD_SNIFF_HITAG: // Eavesdrop Hitag tag, args = type
|
case CMD_SNIFF_HITAG: // Eavesdrop Hitag tag, args = type
|
||||||
SniffHitag(c->arg[0]);
|
SniffHitag(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_SIMULATE_HITAG: // Simulate Hitag tag, args = memory content
|
case CMD_SIMULATE_HITAG: // Simulate Hitag tag, args = memory content
|
||||||
SimulateHitagTag((bool)c->arg[0], c->d.asBytes);
|
SimulateHitagTag((bool)packet->core.old.arg[0], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_READER_HITAG: // Reader for Hitag tags, args = type and function
|
case CMD_READER_HITAG: // Reader for Hitag tags, args = type and function
|
||||||
ReaderHitag((hitag_function)c->arg[0], (hitag_data *)c->d.asBytes);
|
ReaderHitag((hitag_function)packet->core.old.arg[0], (hitag_data *)packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_SIMULATE_HITAG_S:// Simulate Hitag s tag, args = memory content
|
case CMD_SIMULATE_HITAG_S:// Simulate Hitag s tag, args = memory content
|
||||||
SimulateHitagSTag((bool)c->arg[0], c->d.asBytes);
|
SimulateHitagSTag((bool)packet->core.old.arg[0], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_TEST_HITAGS_TRACES:// Tests every challenge within the given file
|
case CMD_TEST_HITAGS_TRACES:// Tests every challenge within the given file
|
||||||
check_challenges((bool)c->arg[0], c->d.asBytes);
|
check_challenges((bool)packet->core.old.arg[0], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_READ_HITAG_S: //Reader for only Hitag S tags, args = key or challenge
|
case CMD_READ_HITAG_S: //Reader for only Hitag S tags, args = key or challenge
|
||||||
ReadHitagS((hitag_function)c->arg[0], (hitag_data *)c->d.asBytes);
|
ReadHitagS((hitag_function)packet->core.old.arg[0], (hitag_data *)packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_WR_HITAG_S: //writer for Hitag tags args=data to write,page and key or challenge
|
case CMD_WR_HITAG_S: //writer for Hitag tags args=data to write,page and key or challenge
|
||||||
if ((hitag_function)c->arg[0] < 10) {
|
if ((hitag_function)packet->core.old.arg[0] < 10) {
|
||||||
WritePageHitagS((hitag_function)c->arg[0], (hitag_data *)c->d.asBytes, c->arg[2]);
|
WritePageHitagS((hitag_function)packet->core.old.arg[0], (hitag_data *)packet->core.old.d.asBytes, packet->core.old.arg[2]);
|
||||||
} else {
|
} else {
|
||||||
WriterHitag((hitag_function)c->arg[0], (hitag_data *)c->d.asBytes, c->arg[2]);
|
WriterHitag((hitag_function)packet->core.old.arg[0], (hitag_data *)packet->core.old.d.asBytes, packet->core.old.arg[2]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -815,28 +811,28 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
RecordRawAdcSamplesIso15693();
|
RecordRawAdcSamplesIso15693();
|
||||||
break;
|
break;
|
||||||
case CMD_ISO_15693_COMMAND:
|
case CMD_ISO_15693_COMMAND:
|
||||||
DirectTag15693Command(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
DirectTag15693Command(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_ISO_15693_FIND_AFI:
|
case CMD_ISO_15693_FIND_AFI:
|
||||||
BruteforceIso15693Afi(c->arg[0]);
|
BruteforceIso15693Afi(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_READER_ISO_15693:
|
case CMD_READER_ISO_15693:
|
||||||
ReaderIso15693(c->arg[0]);
|
ReaderIso15693(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_SIMTAG_ISO_15693:
|
case CMD_SIMTAG_ISO_15693:
|
||||||
SimTagIso15693(c->arg[0], c->d.asBytes);
|
SimTagIso15693(packet->core.old.arg[0], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_LEGICRF
|
#ifdef WITH_LEGICRF
|
||||||
case CMD_SIMULATE_TAG_LEGIC_RF:
|
case CMD_SIMULATE_TAG_LEGIC_RF:
|
||||||
LegicRfSimulate(c->arg[0]);
|
LegicRfSimulate(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_WRITER_LEGIC_RF:
|
case CMD_WRITER_LEGIC_RF:
|
||||||
LegicRfWriter(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
LegicRfWriter(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_READER_LEGIC_RF:
|
case CMD_READER_LEGIC_RF:
|
||||||
LegicRfReader(c->arg[0], c->arg[1], c->arg[2]);
|
LegicRfReader(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_LEGIC_INFO:
|
case CMD_LEGIC_INFO:
|
||||||
LegicRfInfo();
|
LegicRfInfo();
|
||||||
|
@ -850,35 +846,35 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
// arg0 = offset
|
// arg0 = offset
|
||||||
// arg1 = num of bytes
|
// arg1 = num of bytes
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
emlSet(c->d.asBytes, c->arg[0], c->arg[1]);
|
emlSet(packet->core.old.d.asBytes, packet->core.old.arg[0], packet->core.old.arg[1]);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_ISO14443b
|
#ifdef WITH_ISO14443b
|
||||||
case CMD_READ_SRI_TAG:
|
case CMD_READ_SRI_TAG:
|
||||||
ReadSTMemoryIso14443b(c->arg[0]);
|
ReadSTMemoryIso14443b(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_SNIFF_ISO_14443B:
|
case CMD_SNIFF_ISO_14443B:
|
||||||
SniffIso14443b();
|
SniffIso14443b();
|
||||||
break;
|
break;
|
||||||
case CMD_SIMULATE_TAG_ISO_14443B:
|
case CMD_SIMULATE_TAG_ISO_14443B:
|
||||||
SimulateIso14443bTag(c->arg[0]);
|
SimulateIso14443bTag(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_ISO_14443B_COMMAND:
|
case CMD_ISO_14443B_COMMAND:
|
||||||
//SendRawCommand14443B(c->arg[0],c->arg[1],c->arg[2],c->d.asBytes);
|
//SendRawCommand14443B(packet->core.old.arg[0],packet->core.old.arg[1],packet->core.old.arg[2],packet->core.old.d.asBytes);
|
||||||
SendRawCommand14443B_Ex(c);
|
SendRawCommand14443B_Ex(packet);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_FELICA
|
#ifdef WITH_FELICA
|
||||||
case CMD_FELICA_COMMAND:
|
case CMD_FELICA_COMMAND:
|
||||||
felica_sendraw(c);
|
felica_sendraw(packet);
|
||||||
break;
|
break;
|
||||||
case CMD_FELICA_LITE_SIM:
|
case CMD_FELICA_LITE_SIM:
|
||||||
felica_sim_lite(c->arg[0]);
|
felica_sim_lite(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_FELICA_SNIFF:
|
case CMD_FELICA_SNIFF:
|
||||||
felica_sniff(c->arg[0], c->arg[1]);
|
felica_sniff(packet->core.old.arg[0], packet->core.old.arg[1]);
|
||||||
break;
|
break;
|
||||||
case CMD_FELICA_LITE_DUMP:
|
case CMD_FELICA_LITE_DUMP:
|
||||||
felica_dump_lite_s();
|
felica_dump_lite_s();
|
||||||
|
@ -887,107 +883,107 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
|
|
||||||
#ifdef WITH_ISO14443a
|
#ifdef WITH_ISO14443a
|
||||||
case CMD_SNIFF_ISO_14443a:
|
case CMD_SNIFF_ISO_14443a:
|
||||||
SniffIso14443a(c->arg[0]);
|
SniffIso14443a(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_READER_ISO_14443a:
|
case CMD_READER_ISO_14443a:
|
||||||
ReaderIso14443a(c);
|
ReaderIso14443a(packet);
|
||||||
break;
|
break;
|
||||||
case CMD_SIMULATE_TAG_ISO_14443a:
|
case CMD_SIMULATE_TAG_ISO_14443a:
|
||||||
SimulateIso14443aTag(c->arg[0], c->arg[1], c->d.asBytes); // ## Simulate iso14443a tag - pass tag type & UID
|
SimulateIso14443aTag(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes); // ## Simulate iso14443a tag - pass tag type & UID
|
||||||
break;
|
break;
|
||||||
case CMD_ANTIFUZZ_ISO_14443a:
|
case CMD_ANTIFUZZ_ISO_14443a:
|
||||||
iso14443a_antifuzz(c->arg[0]);
|
iso14443a_antifuzz(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_EPA_PACE_COLLECT_NONCE:
|
case CMD_EPA_PACE_COLLECT_NONCE:
|
||||||
EPA_PACE_Collect_Nonce(c);
|
EPA_PACE_Collect_Nonce(packet);
|
||||||
break;
|
break;
|
||||||
case CMD_EPA_PACE_REPLAY:
|
case CMD_EPA_PACE_REPLAY:
|
||||||
EPA_PACE_Replay(c);
|
EPA_PACE_Replay(packet);
|
||||||
break;
|
break;
|
||||||
case CMD_READER_MIFARE:
|
case CMD_READER_MIFARE:
|
||||||
ReaderMifare(c->arg[0], c->arg[1], c->arg[2]);
|
ReaderMifare(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_READBL:
|
case CMD_MIFARE_READBL:
|
||||||
MifareReadBlock(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareReadBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFAREU_READBL:
|
case CMD_MIFAREU_READBL:
|
||||||
MifareUReadBlock(c->arg[0], c->arg[1], c->d.asBytes);
|
MifareUReadBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFAREUC_AUTH:
|
case CMD_MIFAREUC_AUTH:
|
||||||
MifareUC_Auth(c->arg[0], c->d.asBytes);
|
MifareUC_Auth(packet->core.old.arg[0], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFAREU_READCARD:
|
case CMD_MIFAREU_READCARD:
|
||||||
MifareUReadCard(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareUReadCard(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFAREUC_SETPWD:
|
case CMD_MIFAREUC_SETPWD:
|
||||||
MifareUSetPwd(c->arg[0], c->d.asBytes);
|
MifareUSetPwd(packet->core.old.arg[0], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_READSC:
|
case CMD_MIFARE_READSC:
|
||||||
MifareReadSector(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareReadSector(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_WRITEBL:
|
case CMD_MIFARE_WRITEBL:
|
||||||
MifareWriteBlock(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareWriteBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
//case CMD_MIFAREU_WRITEBL_COMPAT:
|
//case CMD_MIFAREU_WRITEBL_COMPAT:
|
||||||
//MifareUWriteBlockCompat(c->arg[0], c->d.asBytes);
|
//MifareUWriteBlockCompat(packet->core.old.arg[0], packet->core.old.d.asBytes);
|
||||||
//break;
|
//break;
|
||||||
case CMD_MIFAREU_WRITEBL:
|
case CMD_MIFAREU_WRITEBL:
|
||||||
MifareUWriteBlock(c->arg[0], c->arg[1], c->d.asBytes);
|
MifareUWriteBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_ACQUIRE_ENCRYPTED_NONCES:
|
case CMD_MIFARE_ACQUIRE_ENCRYPTED_NONCES:
|
||||||
MifareAcquireEncryptedNonces(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareAcquireEncryptedNonces(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_ACQUIRE_NONCES:
|
case CMD_MIFARE_ACQUIRE_NONCES:
|
||||||
MifareAcquireNonces(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareAcquireNonces(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_NESTED:
|
case CMD_MIFARE_NESTED:
|
||||||
MifareNested(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareNested(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_CHKKEYS: {
|
case CMD_MIFARE_CHKKEYS: {
|
||||||
MifareChkKeys(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareChkKeys(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_MIFARE_CHKKEYS_FAST: {
|
case CMD_MIFARE_CHKKEYS_FAST: {
|
||||||
MifareChkKeys_fast(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareChkKeys_fast(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SIMULATE_MIFARE_CARD:
|
case CMD_SIMULATE_MIFARE_CARD:
|
||||||
Mifare1ksim(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
Mifare1ksim(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// emulator
|
// emulator
|
||||||
case CMD_MIFARE_SET_DBGMODE:
|
case CMD_MIFARE_SET_DBGMODE:
|
||||||
MifareSetDbgLvl(c->arg[0]);
|
MifareSetDbgLvl(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_EML_MEMCLR:
|
case CMD_MIFARE_EML_MEMCLR:
|
||||||
MifareEMemClr(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareEMemClr(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_EML_MEMSET:
|
case CMD_MIFARE_EML_MEMSET:
|
||||||
MifareEMemSet(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareEMemSet(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_EML_MEMGET:
|
case CMD_MIFARE_EML_MEMGET:
|
||||||
MifareEMemGet(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareEMemGet(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_EML_CARDLOAD:
|
case CMD_MIFARE_EML_CARDLOAD:
|
||||||
MifareECardLoad(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareECardLoad(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Work with "magic Chinese" card
|
// Work with "magic Chinese" card
|
||||||
case CMD_MIFARE_CSETBLOCK:
|
case CMD_MIFARE_CSETBLOCK:
|
||||||
MifareCSetBlock(c->arg[0], c->arg[1], c->d.asBytes);
|
MifareCSetBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_CGETBLOCK:
|
case CMD_MIFARE_CGETBLOCK:
|
||||||
MifareCGetBlock(c->arg[0], c->arg[1], c->d.asBytes);
|
MifareCGetBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_CIDENT:
|
case CMD_MIFARE_CIDENT:
|
||||||
MifareCIdent();
|
MifareCIdent();
|
||||||
break;
|
break;
|
||||||
// mifare sniffer
|
// mifare sniffer
|
||||||
// case CMD_MIFARE_SNIFFER:
|
// case CMD_MIFARE_SNIFFER:
|
||||||
// SniffMifare(c->arg[0]);
|
// SniffMifare(packet->core.old.arg[0]);
|
||||||
// break;
|
// break;
|
||||||
case CMD_MIFARE_SETMOD:
|
case CMD_MIFARE_SETMOD:
|
||||||
MifareSetMod(c->arg[0], c->d.asBytes);
|
MifareSetMod(packet->core.old.arg[0], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
//mifare desfire
|
//mifare desfire
|
||||||
case CMD_MIFARE_DESFIRE_READBL:
|
case CMD_MIFARE_DESFIRE_READBL:
|
||||||
|
@ -995,19 +991,19 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
case CMD_MIFARE_DESFIRE_WRITEBL:
|
case CMD_MIFARE_DESFIRE_WRITEBL:
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_DESFIRE_AUTH1:
|
case CMD_MIFARE_DESFIRE_AUTH1:
|
||||||
MifareDES_Auth1(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
MifareDES_Auth1(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_DESFIRE_AUTH2:
|
case CMD_MIFARE_DESFIRE_AUTH2:
|
||||||
//MifareDES_Auth2(c->arg[0],c->d.asBytes);
|
//MifareDES_Auth2(packet->core.old.arg[0],packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_DES_READER:
|
case CMD_MIFARE_DES_READER:
|
||||||
//readermifaredes(c->arg[0], c->arg[1], c->d.asBytes);
|
//readermifaredes(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_DESFIRE_INFO:
|
case CMD_MIFARE_DESFIRE_INFO:
|
||||||
MifareDesfireGetInformation();
|
MifareDesfireGetInformation();
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_DESFIRE:
|
case CMD_MIFARE_DESFIRE:
|
||||||
MifareSendCommand(c->arg[0], c->arg[1], c->d.asBytes);
|
MifareSendCommand(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_COLLECT_NONCES:
|
case CMD_MIFARE_COLLECT_NONCES:
|
||||||
break;
|
break;
|
||||||
|
@ -1022,45 +1018,45 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
SniffIClass();
|
SniffIClass();
|
||||||
break;
|
break;
|
||||||
case CMD_SIMULATE_TAG_ICLASS:
|
case CMD_SIMULATE_TAG_ICLASS:
|
||||||
SimulateIClass(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
SimulateIClass(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_READER_ICLASS:
|
case CMD_READER_ICLASS:
|
||||||
ReaderIClass(c->arg[0]);
|
ReaderIClass(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_READER_ICLASS_REPLAY:
|
case CMD_READER_ICLASS_REPLAY:
|
||||||
ReaderIClass_Replay(c->arg[0], c->d.asBytes);
|
ReaderIClass_Replay(packet->core.old.arg[0], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_EML_MEMSET:
|
case CMD_ICLASS_EML_MEMSET:
|
||||||
//iceman, should call FPGADOWNLOAD before, since it corrupts BigBuf
|
//iceman, should call FPGADOWNLOAD before, since it corrupts BigBuf
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
emlSet(c->d.asBytes, c->arg[0], c->arg[1]);
|
emlSet(packet->core.old.d.asBytes, packet->core.old.arg[0], packet->core.old.arg[1]);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_WRITEBLOCK:
|
case CMD_ICLASS_WRITEBLOCK:
|
||||||
iClass_WriteBlock(c->arg[0], c->d.asBytes);
|
iClass_WriteBlock(packet->core.old.arg[0], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_READCHECK: // auth step 1
|
case CMD_ICLASS_READCHECK: // auth step 1
|
||||||
iClass_ReadCheck(c->arg[0], c->arg[1]);
|
iClass_ReadCheck(packet->core.old.arg[0], packet->core.old.arg[1]);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_READBLOCK:
|
case CMD_ICLASS_READBLOCK:
|
||||||
iClass_ReadBlk(c->arg[0]);
|
iClass_ReadBlk(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_AUTHENTICATION: //check
|
case CMD_ICLASS_AUTHENTICATION: //check
|
||||||
iClass_Authentication(c->d.asBytes);
|
iClass_Authentication(packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_CHECK_KEYS:
|
case CMD_ICLASS_CHECK_KEYS:
|
||||||
iClass_Authentication_fast(c->arg[0], c->arg[1], c->d.asBytes);
|
iClass_Authentication_fast(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_DUMP:
|
case CMD_ICLASS_DUMP:
|
||||||
iClass_Dump(c->arg[0], c->arg[1]);
|
iClass_Dump(packet->core.old.arg[0], packet->core.old.arg[1]);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_CLONE:
|
case CMD_ICLASS_CLONE:
|
||||||
iClass_Clone(c->arg[0], c->arg[1], c->d.asBytes);
|
iClass_Clone(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_HFSNIFF
|
#ifdef WITH_HFSNIFF
|
||||||
case CMD_HF_SNIFFER:
|
case CMD_HF_SNIFFER:
|
||||||
HfSniff(c->arg[0], c->arg[1]);
|
HfSniff(packet->core.old.arg[0], packet->core.old.arg[1]);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1070,26 +1066,26 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SMART_SETBAUD: {
|
case CMD_SMART_SETBAUD: {
|
||||||
SmartCardSetBaud(c->arg[0]);
|
SmartCardSetBaud(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SMART_SETCLOCK: {
|
case CMD_SMART_SETCLOCK: {
|
||||||
SmartCardSetClock(c->arg[0]);
|
SmartCardSetClock(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SMART_RAW: {
|
case CMD_SMART_RAW: {
|
||||||
SmartCardRaw(c->arg[0], c->arg[1], c->d.asBytes);
|
SmartCardRaw(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SMART_UPLOAD: {
|
case CMD_SMART_UPLOAD: {
|
||||||
// upload file from client
|
// upload file from client
|
||||||
uint8_t *mem = BigBuf_get_addr();
|
uint8_t *mem = BigBuf_get_addr();
|
||||||
memcpy(mem + c->arg[0], c->d.asBytes, USB_CMD_DATA_SIZE);
|
memcpy(mem + packet->core.old.arg[0], packet->core.old.d.asBytes, USB_CMD_DATA_SIZE);
|
||||||
cmd_send(CMD_ACK, 1, 0, 0, 0, 0);
|
cmd_send(CMD_ACK, 1, 0, 0, 0, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SMART_UPGRADE: {
|
case CMD_SMART_UPGRADE: {
|
||||||
SmartCardUpgrade(c->arg[0]);
|
SmartCardUpgrade(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1131,10 +1127,10 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
usart_writebuffer((uint8_t *)welcome, strlen(welcome));
|
usart_writebuffer((uint8_t *)welcome, strlen(welcome));
|
||||||
|
|
||||||
sprintf(dest, "| bytes 0x%02x 0x%02x 0x%02x 0x%02x\r\n"
|
sprintf(dest, "| bytes 0x%02x 0x%02x 0x%02x 0x%02x\r\n"
|
||||||
, c->d.asBytes[0]
|
, packet->core.old.d.asBytes[0]
|
||||||
, c->d.asBytes[1]
|
, packet->core.old.d.asBytes[1]
|
||||||
, c->d.asBytes[2]
|
, packet->core.old.d.asBytes[2]
|
||||||
, c->d.asBytes[3]
|
, packet->core.old.d.asBytes[3]
|
||||||
);
|
);
|
||||||
usart_writebuffer((uint8_t *)dest, strlen(dest));
|
usart_writebuffer((uint8_t *)dest, strlen(dest));
|
||||||
|
|
||||||
|
@ -1180,7 +1176,7 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_LISTEN_READER_FIELD:
|
case CMD_LISTEN_READER_FIELD:
|
||||||
ListenReaderField(c->arg[0]);
|
ListenReaderField(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_FPGA_MAJOR_MODE_OFF: // ## FPGA Control
|
case CMD_FPGA_MAJOR_MODE_OFF: // ## FPGA Control
|
||||||
|
@ -1192,12 +1188,12 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K: {
|
case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K: {
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
uint8_t *mem = BigBuf_get_addr();
|
uint8_t *mem = BigBuf_get_addr();
|
||||||
uint32_t startidx = c->arg[0];
|
uint32_t startidx = packet->core.old.arg[0];
|
||||||
uint32_t numofbytes = c->arg[1];
|
uint32_t numofbytes = packet->core.old.arg[1];
|
||||||
// arg0 = startindex
|
// arg0 = startindex
|
||||||
// arg1 = length bytes to transfer
|
// arg1 = length bytes to transfer
|
||||||
// arg2 = BigBuf tracelen
|
// arg2 = BigBuf tracelen
|
||||||
//Dbprintf("transfer to client parameters: %" PRIu32 " | %" PRIu32 " | %" PRIu32, startidx, numofbytes, c->arg[2]);
|
//Dbprintf("transfer to client parameters: %" PRIu32 " | %" PRIu32 " | %" PRIu32, startidx, numofbytes, packet->core.old.arg[2]);
|
||||||
|
|
||||||
for (size_t i = 0; i < numofbytes; i += USB_CMD_DATA_SIZE) {
|
for (size_t i = 0; i < numofbytes; i += USB_CMD_DATA_SIZE) {
|
||||||
size_t len = MIN((numofbytes - i), USB_CMD_DATA_SIZE);
|
size_t len = MIN((numofbytes - i), USB_CMD_DATA_SIZE);
|
||||||
|
@ -1222,13 +1218,13 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
// arg1 = 0 upload for LF usage
|
// arg1 = 0 upload for LF usage
|
||||||
// 1 upload for HF usage
|
// 1 upload for HF usage
|
||||||
#define FPGA_LF 1
|
#define FPGA_LF 1
|
||||||
if (c->arg[1] == FPGA_LF)
|
if (packet->core.old.arg[1] == FPGA_LF)
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||||
else
|
else
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
|
|
||||||
uint8_t *mem = BigBuf_get_addr();
|
uint8_t *mem = BigBuf_get_addr();
|
||||||
memcpy(mem + c->arg[0], c->d.asBytes, USB_CMD_DATA_SIZE);
|
memcpy(mem + packet->core.old.arg[0], packet->core.old.d.asBytes, USB_CMD_DATA_SIZE);
|
||||||
cmd_send(CMD_ACK, 1, 0, 0, 0, 0);
|
cmd_send(CMD_ACK, 1, 0, 0, 0, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1237,8 +1233,8 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
uint8_t *mem = BigBuf_get_EM_addr();
|
uint8_t *mem = BigBuf_get_EM_addr();
|
||||||
bool isok = false;
|
bool isok = false;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
uint32_t startidx = c->arg[0];
|
uint32_t startidx = packet->core.old.arg[0];
|
||||||
uint32_t numofbytes = c->arg[1];
|
uint32_t numofbytes = packet->core.old.arg[1];
|
||||||
|
|
||||||
// arg0 = startindex
|
// arg0 = startindex
|
||||||
// arg1 = length bytes to transfer
|
// arg1 = length bytes to transfer
|
||||||
|
@ -1256,16 +1252,16 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_READ_MEM:
|
case CMD_READ_MEM:
|
||||||
ReadMem(c->arg[0]);
|
ReadMem(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
#ifdef WITH_FLASH
|
#ifdef WITH_FLASH
|
||||||
case CMD_FLASHMEM_SET_SPIBAUDRATE:
|
case CMD_FLASHMEM_SET_SPIBAUDRATE:
|
||||||
FlashmemSetSpiBaudrate(c->arg[0]);
|
FlashmemSetSpiBaudrate(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_FLASHMEM_READ: {
|
case CMD_FLASHMEM_READ: {
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
uint32_t startidx = c->arg[0];
|
uint32_t startidx = packet->core.old.arg[0];
|
||||||
uint16_t len = c->arg[1];
|
uint16_t len = packet->core.old.arg[1];
|
||||||
|
|
||||||
Dbprintf("FlashMem read | %d - %d | ", startidx, len);
|
Dbprintf("FlashMem read | %d - %d | ", startidx, len);
|
||||||
|
|
||||||
|
@ -1298,9 +1294,9 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
uint8_t isok = 0;
|
uint8_t isok = 0;
|
||||||
uint16_t res = 0;
|
uint16_t res = 0;
|
||||||
uint32_t startidx = c->arg[0];
|
uint32_t startidx = packet->core.old.arg[0];
|
||||||
uint16_t len = c->arg[1];
|
uint16_t len = packet->core.old.arg[1];
|
||||||
uint8_t *data = c->d.asBytes;
|
uint8_t *data = packet->core.old.d.asBytes;
|
||||||
|
|
||||||
uint32_t tmp = startidx + len;
|
uint32_t tmp = startidx + len;
|
||||||
|
|
||||||
|
@ -1359,8 +1355,8 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
}
|
}
|
||||||
case CMD_FLASHMEM_WIPE: {
|
case CMD_FLASHMEM_WIPE: {
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
uint8_t page = c->arg[0];
|
uint8_t page = packet->core.old.arg[0];
|
||||||
uint8_t initalwipe = c->arg[1];
|
uint8_t initalwipe = packet->core.old.arg[1];
|
||||||
bool isok = false;
|
bool isok = false;
|
||||||
if (initalwipe) {
|
if (initalwipe) {
|
||||||
isok = Flash_WipeMemory();
|
isok = Flash_WipeMemory();
|
||||||
|
@ -1379,8 +1375,8 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
|
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
uint8_t *mem = BigBuf_malloc(USB_CMD_DATA_SIZE);
|
uint8_t *mem = BigBuf_malloc(USB_CMD_DATA_SIZE);
|
||||||
uint32_t startidx = c->arg[0];
|
uint32_t startidx = packet->core.old.arg[0];
|
||||||
uint32_t numofbytes = c->arg[1];
|
uint32_t numofbytes = packet->core.old.arg[1];
|
||||||
// arg0 = startindex
|
// arg0 = startindex
|
||||||
// arg1 = length bytes to transfer
|
// arg1 = length bytes to transfer
|
||||||
// arg2 = RFU
|
// arg2 = RFU
|
||||||
|
@ -1427,11 +1423,11 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
#endif
|
#endif
|
||||||
case CMD_SET_LF_DIVISOR:
|
case CMD_SET_LF_DIVISOR:
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, c->arg[0]);
|
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_SET_ADC_MUX:
|
case CMD_SET_ADC_MUX:
|
||||||
switch (c->arg[0]) {
|
switch (packet->core.old.arg[0]) {
|
||||||
case 0:
|
case 0:
|
||||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||||
break;
|
break;
|
||||||
|
@ -1456,8 +1452,8 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
SendStatus();
|
SendStatus();
|
||||||
break;
|
break;
|
||||||
case CMD_PING:
|
case CMD_PING:
|
||||||
if (cmd_ng) {
|
if (packet->ng) {
|
||||||
reply_ng(CMD_PING, PM3_SUCCESS, data_ng, datalen_ng);
|
reply_ng(CMD_PING, PM3_SUCCESS, packet->core.ng.data, packet->length);
|
||||||
} else {
|
} else {
|
||||||
#ifdef WITH_FPC_HOST
|
#ifdef WITH_FPC_HOST
|
||||||
cmd_send(CMD_ACK, reply_via_fpc, 0, 0, 0, 0);
|
cmd_send(CMD_ACK, reply_via_fpc, 0, 0, 0, 0);
|
||||||
|
@ -1471,7 +1467,7 @@ static void UsbPacketReceived(bool cmd_ng, uint8_t *packet) {
|
||||||
LCDReset();
|
LCDReset();
|
||||||
break;
|
break;
|
||||||
case CMD_LCD:
|
case CMD_LCD:
|
||||||
LCDSend(c->arg[0]);
|
LCDSend(packet->core.old.arg[0]);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case CMD_SETUP_WRITE:
|
case CMD_SETUP_WRITE:
|
||||||
|
@ -1570,9 +1566,7 @@ void __attribute__((noreturn)) AppMain(void) {
|
||||||
usb_disable();
|
usb_disable();
|
||||||
usb_enable();
|
usb_enable();
|
||||||
|
|
||||||
uint8_t rx[USB_COMMANDNG_MAXLEN];
|
UsbCommandNG rx;
|
||||||
UsbCommandNGPreamble *pre = (UsbCommandNGPreamble *)rx;
|
|
||||||
UsbCommandNGPostamble *post = (UsbCommandNGPostamble *)(rx + sizeof(UsbCommandNGPreamble) + USB_DATANG_SIZE);
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
|
@ -1580,30 +1574,30 @@ void __attribute__((noreturn)) AppMain(void) {
|
||||||
// Check if there is a usb packet available
|
// Check if there is a usb packet available
|
||||||
if (usb_poll_validate_length()) {
|
if (usb_poll_validate_length()) {
|
||||||
bool error = false;
|
bool error = false;
|
||||||
size_t bytes = usb_read_ng(rx, sizeof(UsbCommandNGPreamble));
|
size_t bytes = usb_read_ng((uint8_t *)&rx, sizeof(UsbCommandNGPreamble));
|
||||||
if (bytes == sizeof(UsbCommandNGPreamble)) {
|
if (bytes == sizeof(UsbCommandNGPreamble)) {
|
||||||
if (pre->magic == USB_COMMANDNG_PREAMBLE_MAGIC) { // New style NG command
|
if (rx.magic == USB_COMMANDNG_PREAMBLE_MAGIC) { // New style NG command
|
||||||
if (pre->length > USB_DATANG_SIZE) {
|
if (rx.length > USB_DATANG_SIZE) {
|
||||||
Dbprintf("Packet frame with incompatible length: 0x%04x", pre->length);
|
Dbprintf("Packet frame with incompatible length: 0x%04x", rx.length);
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
if ((!error) && (pre->length > 0)) { // Get the variable length payload
|
if (!error) { // Get the core and variable length payload
|
||||||
bytes = usb_read_ng(rx + sizeof(UsbCommandNGPreamble), pre->length);
|
bytes = usb_read_ng(((uint8_t *)&rx.core), sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + rx.length);
|
||||||
if (bytes != pre->length) {
|
if (bytes != sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + rx.length) {
|
||||||
Dbprintf("Packet frame error variable part too short? %d/%d", bytes, pre->length);
|
Dbprintf("Packet frame error variable part too short? %d/%d", bytes, rx.length);
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!error) { // Get the postamble
|
if (!error) { // Get the postamble
|
||||||
bytes = usb_read_ng(rx + sizeof(UsbCommandNGPreamble) + USB_DATANG_SIZE, sizeof(UsbCommandNGPostamble));
|
bytes = usb_read_ng(((uint8_t *)&rx.crc), sizeof(UsbCommandNGPostamble));
|
||||||
if (bytes != sizeof(UsbCommandNGPostamble)) {
|
if (bytes != sizeof(UsbCommandNGPostamble)) {
|
||||||
Dbprintf("Packet frame error fetching postamble");
|
Dbprintf("Packet frame error fetching postamble");
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
uint8_t first, second;
|
uint8_t first, second;
|
||||||
compute_crc(CRC_14443_A, rx, sizeof(UsbCommandNGPreamble) + pre->length, &first, &second);
|
compute_crc(CRC_14443_A, (uint8_t *)&rx, sizeof(UsbCommandNGPreamble) + sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + rx.length, &first, &second);
|
||||||
if ((first << 8) + second != post->crc) {
|
if ((first << 8) + second != rx.crc) {
|
||||||
Dbprintf("Packet frame CRC error %02X%02X <> %04X", first, second, post->crc);
|
Dbprintf("Packet frame CRC error %02X%02X <> %04X", first, second, rx.crc);
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1611,10 +1605,17 @@ void __attribute__((noreturn)) AppMain(void) {
|
||||||
#ifdef WITH_FPC_HOST
|
#ifdef WITH_FPC_HOST
|
||||||
reply_via_fpc = false;
|
reply_via_fpc = false;
|
||||||
#endif
|
#endif
|
||||||
UsbPacketReceived(true, rx);
|
rx.ng = true;
|
||||||
|
UsbPacketReceived(&rx);
|
||||||
}
|
}
|
||||||
} else { // Old style command
|
} else { // Old style command
|
||||||
bytes = usb_read_ng(rx + sizeof(UsbCommandNGPreamble), sizeof(UsbCommand) - sizeof(UsbCommandNGPreamble));
|
uint8_t tmp[sizeof(UsbCommandNGPreamble)];
|
||||||
|
memcpy(tmp, &rx, sizeof(UsbCommandNGPreamble));
|
||||||
|
memcpy(&rx.core.old, tmp, sizeof(UsbCommandNGPreamble));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bytes = usb_read_ng(((uint8_t *)&rx.core.old) + sizeof(UsbCommandNGPreamble), sizeof(UsbCommand) - sizeof(UsbCommandNGPreamble));
|
||||||
if (bytes != sizeof(UsbCommand) - sizeof(UsbCommandNGPreamble)) {
|
if (bytes != sizeof(UsbCommand) - sizeof(UsbCommandNGPreamble)) {
|
||||||
Dbprintf("Packet frame error var part too short? %d/%d", bytes, sizeof(UsbCommand) - sizeof(UsbCommandNGPreamble));
|
Dbprintf("Packet frame error var part too short? %d/%d", bytes, sizeof(UsbCommand) - sizeof(UsbCommandNGPreamble));
|
||||||
error = true;
|
error = true;
|
||||||
|
@ -1623,22 +1624,31 @@ void __attribute__((noreturn)) AppMain(void) {
|
||||||
#ifdef WITH_FPC_HOST
|
#ifdef WITH_FPC_HOST
|
||||||
reply_via_fpc = false;
|
reply_via_fpc = false;
|
||||||
#endif
|
#endif
|
||||||
UsbPacketReceived(false, rx);
|
rx.ng = false;
|
||||||
|
rx.magic = 0;
|
||||||
|
rx.length = USB_CMD_DATA_SIZE;
|
||||||
|
rx.crc = 0;
|
||||||
|
UsbPacketReceived(&rx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Dbprintf("Packet frame preamble too short: %d/%d", bytes, sizeof(UsbCommandNGPreamble));
|
Dbprintf("Packet frame preamble too short: %d/%d", bytes, sizeof(UsbCommandNGPreamble));
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
// TODO if error, shall we resync ?
|
// TODO DOEGOX if error, shall we resync ?
|
||||||
}
|
}
|
||||||
#ifdef WITH_FPC_HOST
|
#ifdef WITH_FPC_HOST
|
||||||
// Check if there is a FPC packet available
|
// Check if there is a FPC packet available
|
||||||
if (usart_readbuffer(rx)) {
|
// TODO DOEGOX NG packets support here too
|
||||||
|
if (usart_readbuffer((uint8_t *)&rx)) {
|
||||||
reply_via_fpc = true;
|
reply_via_fpc = true;
|
||||||
UsbPacketReceived(false, rx);
|
rx.ng = false;
|
||||||
|
rx.magic = 0;
|
||||||
|
rx.length = USB_CMD_DATA_SIZE;
|
||||||
|
rx.crc = 0;
|
||||||
|
UsbPacketReceived(&rx);
|
||||||
}
|
}
|
||||||
usart_readcheck(rx, sizeof(rx));
|
usart_readcheck((uint8_t *)&rx, sizeof(rx));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Press button for one second to enter a possible standalone mode
|
// Press button for one second to enter a possible standalone mode
|
||||||
|
|
|
@ -120,13 +120,13 @@ void AcquireRawAdcSamplesIso14443b(uint32_t parameter);
|
||||||
void ReadSTMemoryIso14443b(uint8_t numofblocks);
|
void ReadSTMemoryIso14443b(uint8_t numofblocks);
|
||||||
void RAMFUNC SniffIso14443b(void);
|
void RAMFUNC SniffIso14443b(void);
|
||||||
void SendRawCommand14443B(uint32_t, uint32_t, uint8_t, uint8_t[]);
|
void SendRawCommand14443B(uint32_t, uint32_t, uint8_t, uint8_t[]);
|
||||||
void SendRawCommand14443B_Ex(UsbCommand *c);
|
void SendRawCommand14443B_Ex(UsbCommandNG *c);
|
||||||
void ClearFpgaShiftingRegisters(void);
|
void ClearFpgaShiftingRegisters(void);
|
||||||
|
|
||||||
// iso14443a.h
|
// iso14443a.h
|
||||||
void RAMFUNC SniffIso14443a(uint8_t param);
|
void RAMFUNC SniffIso14443a(uint8_t param);
|
||||||
void SimulateIso14443aTag(int tagType, int flags, uint8_t *data);
|
void SimulateIso14443aTag(int tagType, int flags, uint8_t *data);
|
||||||
void ReaderIso14443a(UsbCommand *c);
|
void ReaderIso14443a(UsbCommandNG *c);
|
||||||
|
|
||||||
// Also used in iclass.c
|
// Also used in iclass.c
|
||||||
//bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t len, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag);
|
//bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t len, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag);
|
||||||
|
@ -137,8 +137,8 @@ void iso14a_set_trigger(bool enable);
|
||||||
//int GetIso14443aCommandFromReader(uint8_t *received, uint8_t *parity, int *len);
|
//int GetIso14443aCommandFromReader(uint8_t *received, uint8_t *parity, int *len);
|
||||||
|
|
||||||
// epa.h
|
// epa.h
|
||||||
void EPA_PACE_Collect_Nonce(UsbCommand *c);
|
void EPA_PACE_Collect_Nonce(UsbCommandNG *c);
|
||||||
void EPA_PACE_Replay(UsbCommand *c);
|
void EPA_PACE_Replay(UsbCommandNG *c);
|
||||||
|
|
||||||
// mifarecmd.h
|
// mifarecmd.h
|
||||||
void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain);
|
void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain);
|
||||||
|
@ -229,7 +229,7 @@ uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void
|
||||||
void HfSniff(int, int);
|
void HfSniff(int, int);
|
||||||
|
|
||||||
//felica.c
|
//felica.c
|
||||||
void felica_sendraw(UsbCommand *c);
|
void felica_sendraw(UsbCommandNG *c);
|
||||||
void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip);
|
void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip);
|
||||||
void felica_sim_lite(uint64_t uid);
|
void felica_sim_lite(uint64_t uid);
|
||||||
void felica_dump_lite_s();
|
void felica_dump_lite_s();
|
||||||
|
|
22
armsrc/epa.c
22
armsrc/epa.c
|
@ -259,7 +259,7 @@ static void EPA_PACE_Collect_Nonce_Abort(uint8_t step, int func_return) {
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Acquire one encrypted PACE nonce
|
// Acquire one encrypted PACE nonce
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void EPA_PACE_Collect_Nonce(UsbCommand *c) {
|
void EPA_PACE_Collect_Nonce(UsbCommandNG *c) {
|
||||||
/*
|
/*
|
||||||
* ack layout:
|
* ack layout:
|
||||||
* arg:
|
* arg:
|
||||||
|
@ -313,7 +313,7 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c) {
|
||||||
|
|
||||||
// now get the nonce
|
// now get the nonce
|
||||||
uint8_t nonce[256] = {0};
|
uint8_t nonce[256] = {0};
|
||||||
uint8_t requested_size = (uint8_t)c->arg[0];
|
uint8_t requested_size = (uint8_t)c->core.old.arg[0];
|
||||||
func_return = EPA_PACE_Get_Nonce(requested_size, nonce);
|
func_return = EPA_PACE_Get_Nonce(requested_size, nonce);
|
||||||
// check if the command succeeded
|
// check if the command succeeded
|
||||||
if (func_return < 0) {
|
if (func_return < 0) {
|
||||||
|
@ -430,23 +430,23 @@ int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Perform the PACE protocol by replaying given APDUs
|
// Perform the PACE protocol by replaying given APDUs
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void EPA_PACE_Replay(UsbCommand *c) {
|
void EPA_PACE_Replay(UsbCommandNG *c) {
|
||||||
uint32_t timings[sizeof(apdu_lengths_replay) / sizeof(apdu_lengths_replay[0])] = {0};
|
uint32_t timings[sizeof(apdu_lengths_replay) / sizeof(apdu_lengths_replay[0])] = {0};
|
||||||
|
|
||||||
// if an APDU has been passed, save it
|
// if an APDU has been passed, save it
|
||||||
if (c->arg[0] != 0) {
|
if (c->core.old.arg[0] != 0) {
|
||||||
// make sure it's not too big
|
// make sure it's not too big
|
||||||
if (c->arg[2] > apdus_replay[c->arg[0] - 1].len) {
|
if (c->core.old.arg[2] > apdus_replay[c->core.old.arg[0] - 1].len) {
|
||||||
cmd_send(CMD_ACK, 1, 0, 0, NULL, 0);
|
cmd_send(CMD_ACK, 1, 0, 0, NULL, 0);
|
||||||
}
|
}
|
||||||
memcpy(apdus_replay[c->arg[0] - 1].data + c->arg[1],
|
memcpy(apdus_replay[c->core.old.arg[0] - 1].data + c->core.old.arg[1],
|
||||||
c->d.asBytes,
|
c->core.old.d.asBytes,
|
||||||
c->arg[2]);
|
c->core.old.arg[2]);
|
||||||
// save/update APDU length
|
// save/update APDU length
|
||||||
if (c->arg[1] == 0) {
|
if (c->core.old.arg[1] == 0) {
|
||||||
apdu_lengths_replay[c->arg[0] - 1] = c->arg[2];
|
apdu_lengths_replay[c->core.old.arg[0] - 1] = c->core.old.arg[2];
|
||||||
} else {
|
} else {
|
||||||
apdu_lengths_replay[c->arg[0] - 1] += c->arg[2];
|
apdu_lengths_replay[c->core.old.arg[0] - 1] += c->core.old.arg[2];
|
||||||
}
|
}
|
||||||
cmd_send(CMD_ACK, 0, 0, 0, NULL, 0);
|
cmd_send(CMD_ACK, 0, 0, 0, NULL, 0);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -475,13 +475,13 @@ static void iso18092_setup(uint8_t fpga_minor_mode) {
|
||||||
// arg0 FeliCa flags
|
// arg0 FeliCa flags
|
||||||
// arg1 len of commandbytes
|
// arg1 len of commandbytes
|
||||||
// d.asBytes command bytes to send
|
// d.asBytes command bytes to send
|
||||||
void felica_sendraw(UsbCommand *c) {
|
void felica_sendraw(UsbCommandNG *c) {
|
||||||
|
|
||||||
if (MF_DBGLEVEL > 3) Dbprintf("FeliCa_sendraw Enter");
|
if (MF_DBGLEVEL > 3) Dbprintf("FeliCa_sendraw Enter");
|
||||||
|
|
||||||
felica_command_t param = c->arg[0];
|
felica_command_t param = c->core.old.arg[0];
|
||||||
size_t len = c->arg[1] & 0xffff;
|
size_t len = c->core.old.arg[1] & 0xffff;
|
||||||
uint8_t *cmd = c->d.asBytes;
|
uint8_t *cmd = c->core.old.d.asBytes;
|
||||||
uint32_t arg0;
|
uint32_t arg0;
|
||||||
|
|
||||||
felica_card_select_t card;
|
felica_card_select_t card;
|
||||||
|
|
|
@ -2350,12 +2350,12 @@ int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, u
|
||||||
// low :: len of commandbytes
|
// low :: len of commandbytes
|
||||||
// arg2 timeout
|
// arg2 timeout
|
||||||
// d.asBytes command bytes to send
|
// d.asBytes command bytes to send
|
||||||
void ReaderIso14443a(UsbCommand *c) {
|
void ReaderIso14443a(UsbCommandNG *c) {
|
||||||
iso14a_command_t param = c->arg[0];
|
iso14a_command_t param = c->core.old.arg[0];
|
||||||
size_t len = c->arg[1] & 0xffff;
|
size_t len = c->core.old.arg[1] & 0xffff;
|
||||||
size_t lenbits = c->arg[1] >> 16;
|
size_t lenbits = c->core.old.arg[1] >> 16;
|
||||||
uint32_t timeout = c->arg[2];
|
uint32_t timeout = c->core.old.arg[2];
|
||||||
uint8_t *cmd = c->d.asBytes;
|
uint8_t *cmd = c->core.old.d.asBytes;
|
||||||
uint32_t arg0;
|
uint32_t arg0;
|
||||||
uint8_t buf[USB_CMD_DATA_SIZE] = {0x00};
|
uint8_t buf[USB_CMD_DATA_SIZE] = {0x00};
|
||||||
uint8_t par[MAX_PARITY_SIZE] = {0x00};
|
uint8_t par[MAX_PARITY_SIZE] = {0x00};
|
||||||
|
|
|
@ -121,7 +121,7 @@ RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_t
|
||||||
void RAMFUNC SniffIso14443a(uint8_t param);
|
void RAMFUNC SniffIso14443a(uint8_t param);
|
||||||
void SimulateIso14443aTag(int tagType, int flags, uint8_t *data);
|
void SimulateIso14443aTag(int tagType, int flags, uint8_t *data);
|
||||||
void iso14443a_antifuzz(uint32_t flags);
|
void iso14443a_antifuzz(uint32_t flags);
|
||||||
void ReaderIso14443a(UsbCommand *c);
|
void ReaderIso14443a(UsbCommandNG *c);
|
||||||
void ReaderTransmit(uint8_t *frame, uint16_t len, uint32_t *timing);
|
void ReaderTransmit(uint8_t *frame, uint16_t len, uint32_t *timing);
|
||||||
void ReaderTransmitBitsPar(uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t *timing);
|
void ReaderTransmitBitsPar(uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t *timing);
|
||||||
void ReaderTransmitPar(uint8_t *frame, uint16_t len, uint8_t *par, uint32_t *timing);
|
void ReaderTransmitPar(uint8_t *frame, uint16_t len, uint8_t *par, uint32_t *timing);
|
||||||
|
|
|
@ -1566,11 +1566,11 @@ void iso14b_set_trigger(bool enable) {
|
||||||
* none
|
* none
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void SendRawCommand14443B_Ex(UsbCommand *c) {
|
void SendRawCommand14443B_Ex(UsbCommandNG *c) {
|
||||||
iso14b_command_t param = c->arg[0];
|
iso14b_command_t param = c->core.old.arg[0];
|
||||||
size_t len = c->arg[1] & 0xffff;
|
size_t len = c->core.old.arg[1] & 0xffff;
|
||||||
uint32_t timeout = c->arg[2];
|
uint32_t timeout = c->core.old.arg[2];
|
||||||
uint8_t *cmd = c->d.asBytes;
|
uint8_t *cmd = c->core.old.d.asBytes;
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint32_t sendlen = sizeof(iso14b_card_select_t);
|
uint32_t sendlen = sizeof(iso14b_card_select_t);
|
||||||
uint8_t buf[USB_CMD_DATA_SIZE] = {0x00};
|
uint8_t buf[USB_CMD_DATA_SIZE] = {0x00};
|
||||||
|
|
|
@ -34,7 +34,7 @@ extern "C" {
|
||||||
# define AddCrc14B(data, len) compute_crc(CRC_14443_B, (data), (len), (data)+(len), (data)+(len)+1)
|
# define AddCrc14B(data, len) compute_crc(CRC_14443_B, (data), (len), (data)+(len), (data)+(len)+1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void SendRawCommand14443B_Ex(UsbCommand *c);
|
void SendRawCommand14443B_Ex(UsbCommandNG *c);
|
||||||
void iso14443b_setup();
|
void iso14443b_setup();
|
||||||
uint8_t iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *response);
|
uint8_t iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *response);
|
||||||
uint8_t iso14443b_select_card(iso14b_card_select_t *card);
|
uint8_t iso14443b_select_card(iso14b_card_select_t *card);
|
||||||
|
|
|
@ -84,16 +84,15 @@ static void Fatal(void) {
|
||||||
for (;;) {};
|
for (;;) {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsbPacketReceived(uint8_t *packet, int len) {
|
void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
int i, dont_ack = 0;
|
int i, dont_ack = 0;
|
||||||
UsbCommand *c = (UsbCommand *)packet;
|
|
||||||
volatile uint32_t *p;
|
volatile uint32_t *p;
|
||||||
|
|
||||||
//if ( len != sizeof(UsbCommand)) Fatal();
|
//if ( len != sizeof(UsbCommand)) Fatal();
|
||||||
|
|
||||||
uint32_t arg0 = (uint32_t)c->arg[0];
|
uint32_t arg0 = (uint32_t)packet->core.old.arg[0];
|
||||||
|
|
||||||
switch (c->cmd) {
|
switch (packet->core.old.cmd) {
|
||||||
case CMD_DEVICE_INFO: {
|
case CMD_DEVICE_INFO: {
|
||||||
dont_ack = 1;
|
dont_ack = 1;
|
||||||
arg0 = DEVICE_INFO_FLAG_BOOTROM_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM |
|
arg0 = DEVICE_INFO_FLAG_BOOTROM_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM |
|
||||||
|
@ -111,7 +110,7 @@ void UsbPacketReceived(uint8_t *packet, int len) {
|
||||||
*/
|
*/
|
||||||
p = (volatile uint32_t *)&_flash_start;
|
p = (volatile uint32_t *)&_flash_start;
|
||||||
for (i = 0; i < 12; i++)
|
for (i = 0; i < 12; i++)
|
||||||
p[i + arg0] = c->d.asDwords[i];
|
p[i + arg0] = packet->core.old.d.asDwords[i];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -119,7 +118,7 @@ void UsbPacketReceived(uint8_t *packet, int len) {
|
||||||
uint32_t *flash_mem = (uint32_t *)(&_flash_start);
|
uint32_t *flash_mem = (uint32_t *)(&_flash_start);
|
||||||
for (int j = 0; j < 2; j++) {
|
for (int j = 0; j < 2; j++) {
|
||||||
for (i = 0 + (64 * j); i < 64 + (64 * j); i++) {
|
for (i = 0 + (64 * j); i < 64 + (64 * j); i++) {
|
||||||
flash_mem[i] = c->d.asDwords[i];
|
flash_mem[i] = packet->core.old.d.asDwords[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t flash_address = arg0 + (0x100 * j);
|
uint32_t flash_address = arg0 + (0x100 * j);
|
||||||
|
@ -155,7 +154,7 @@ void UsbPacketReceived(uint8_t *packet, int len) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_START_FLASH: {
|
case CMD_START_FLASH: {
|
||||||
if (c->arg[2] == START_FLASH_MAGIC)
|
if (packet->core.old.arg[2] == START_FLASH_MAGIC)
|
||||||
bootrom_unlocked = 1;
|
bootrom_unlocked = 1;
|
||||||
else
|
else
|
||||||
bootrom_unlocked = 0;
|
bootrom_unlocked = 0;
|
||||||
|
@ -164,8 +163,8 @@ void UsbPacketReceived(uint8_t *packet, int len) {
|
||||||
int prot_end = (int)&_bootrom_end;
|
int prot_end = (int)&_bootrom_end;
|
||||||
int allow_start = (int)&_flash_start;
|
int allow_start = (int)&_flash_start;
|
||||||
int allow_end = (int)&_flash_end;
|
int allow_end = (int)&_flash_end;
|
||||||
int cmd_start = c->arg[0];
|
int cmd_start = packet->core.old.arg[0];
|
||||||
int cmd_end = c->arg[1];
|
int cmd_end = packet->core.old.arg[1];
|
||||||
|
|
||||||
/* Only allow command if the bootrom is unlocked, or the parameters are outside of the protected
|
/* Only allow command if the bootrom is unlocked, or the parameters are outside of the protected
|
||||||
* bootrom area. In any case they must be within the flash area.
|
* bootrom area. In any case they must be within the flash area.
|
||||||
|
@ -197,7 +196,7 @@ static void flash_mode(int externally_entered) {
|
||||||
start_addr = 0;
|
start_addr = 0;
|
||||||
end_addr = 0;
|
end_addr = 0;
|
||||||
bootrom_unlocked = 0;
|
bootrom_unlocked = 0;
|
||||||
uint8_t rx[sizeof(UsbCommand)];
|
UsbCommandNG rx;
|
||||||
|
|
||||||
usb_enable();
|
usb_enable();
|
||||||
|
|
||||||
|
@ -209,8 +208,9 @@ static void flash_mode(int externally_entered) {
|
||||||
|
|
||||||
// Check if there is a usb packet available
|
// Check if there is a usb packet available
|
||||||
if (usb_poll_validate_length()) {
|
if (usb_poll_validate_length()) {
|
||||||
if (usb_read(rx, sizeof(rx)))
|
// TODO DOEGOX
|
||||||
UsbPacketReceived(rx, sizeof(rx));
|
if (usb_read((uint8_t *)&rx, sizeof(rx)))
|
||||||
|
UsbPacketReceived(&rx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!externally_entered && !BUTTON_PRESS()) {
|
if (!externally_entered && !BUTTON_PRESS()) {
|
||||||
|
|
|
@ -517,11 +517,11 @@ static int CmdAnalyseA(const char *Cmd) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "got ack. Status %d", resp.arg[0]);
|
PrintAndLogEx(NORMAL, "got ack. Status %d", resp.core.old.arg[0]);
|
||||||
return 0;
|
return 0;
|
||||||
/*
|
/*
|
||||||
PrintAndLogEx(NORMAL, "-- " _BLUE_("its my message") "\n");
|
PrintAndLogEx(NORMAL, "-- " _BLUE_("its my message") "\n");
|
||||||
|
|
|
@ -1457,7 +1457,7 @@ int getSamples(uint32_t n, bool silent) {
|
||||||
|
|
||||||
if (!silent) PrintAndLogEx(NORMAL, "Reading %d bytes from device memory\n", n);
|
if (!silent) PrintAndLogEx(NORMAL, "Reading %d bytes from device memory\n", n);
|
||||||
|
|
||||||
UsbCommand response;
|
UsbReplyNG response;
|
||||||
if (!GetFromDevice(BIG_BUF, got, n, 0, &response, 10000, true)) {
|
if (!GetFromDevice(BIG_BUF, got, n, 0, &response, 10000, true)) {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1468,8 +1468,8 @@ int getSamples(uint32_t n, bool silent) {
|
||||||
uint8_t bits_per_sample = 8;
|
uint8_t bits_per_sample = 8;
|
||||||
|
|
||||||
//Old devices without this feature would send 0 at arg[0]
|
//Old devices without this feature would send 0 at arg[0]
|
||||||
if (response.arg[0] > 0) {
|
if (response.core.old.arg[0] > 0) {
|
||||||
sample_config *sc = (sample_config *) response.d.asBytes;
|
sample_config *sc = (sample_config *) response.core.old.d.asBytes;
|
||||||
if (!silent) PrintAndLogEx(NORMAL, "Samples @ %d bits/smpl, decimation 1:%d ", sc->bits_per_sample, sc->decimation);
|
if (!silent) PrintAndLogEx(NORMAL, "Samples @ %d bits/smpl, decimation 1:%d ", sc->bits_per_sample, sc->decimation);
|
||||||
bits_per_sample = sc->bits_per_sample;
|
bits_per_sample = sc->bits_per_sample;
|
||||||
}
|
}
|
||||||
|
@ -1532,7 +1532,7 @@ int CmdTuneSamples(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING, {0, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
while (!WaitForResponseTimeout(CMD_MEASURED_ANTENNA_TUNING, &resp, 2000)) {
|
while (!WaitForResponseTimeout(CMD_MEASURED_ANTENNA_TUNING, &resp, 2000)) {
|
||||||
timeout++;
|
timeout++;
|
||||||
printf(".");
|
printf(".");
|
||||||
|
@ -1544,12 +1544,12 @@ int CmdTuneSamples(const char *Cmd) {
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "\n");
|
PrintAndLogEx(NORMAL, "\n");
|
||||||
|
|
||||||
uint32_t v_lf125 = resp.arg[0];
|
uint32_t v_lf125 = resp.core.old.arg[0];
|
||||||
uint32_t v_lf134 = resp.arg[0] >> 32;
|
uint32_t v_lf134 = resp.core.old.arg[0] >> 32;
|
||||||
|
|
||||||
uint32_t v_hf = resp.arg[1];
|
uint32_t v_hf = resp.core.old.arg[1];
|
||||||
uint32_t peakf = resp.arg[2];
|
uint32_t peakf = resp.core.old.arg[2];
|
||||||
uint32_t peakv = resp.arg[2] >> 32;
|
uint32_t peakv = resp.core.old.arg[2] >> 32;
|
||||||
|
|
||||||
if (v_lf125 > NON_VOLTAGE)
|
if (v_lf125 > NON_VOLTAGE)
|
||||||
PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - 125.00 kHz", (v_lf125 * ANTENNA_ERROR) / 1000.0);
|
PrintAndLogEx(SUCCESS, "LF antenna: %5.2f V - 125.00 kHz", (v_lf125 * ANTENNA_ERROR) / 1000.0);
|
||||||
|
@ -1595,8 +1595,8 @@ int CmdTuneSamples(const char *Cmd) {
|
||||||
// even here, these values has 3% error.
|
// even here, these values has 3% error.
|
||||||
uint16_t test1 = 0;
|
uint16_t test1 = 0;
|
||||||
for (int i = 0; i < 256; i++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
GraphBuffer[i] = resp.d.asBytes[i] - 128;
|
GraphBuffer[i] = resp.core.old.d.asBytes[i] - 128;
|
||||||
test1 += resp.d.asBytes[i];
|
test1 += resp.core.old.d.asBytes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (test1 > 0) {
|
if (test1 > 0) {
|
||||||
|
|
|
@ -283,14 +283,14 @@ static int CmdFlashMemLoad(const char *Cmd) {
|
||||||
bytes_remaining -= bytes_in_packet;
|
bytes_remaining -= bytes_in_packet;
|
||||||
bytes_sent += bytes_in_packet;
|
bytes_sent += bytes_in_packet;
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
free(data);
|
free(data);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t isok = resp.arg[0] & 0xFF;
|
uint8_t isok = resp.core.old.arg[0] & 0xFF;
|
||||||
if (!isok)
|
if (!isok)
|
||||||
PrintAndLogEx(FAILED, "Flash write fail [offset %u]", bytes_sent);
|
PrintAndLogEx(FAILED, "Flash write fail [offset %u]", bytes_sent);
|
||||||
|
|
||||||
|
@ -392,12 +392,12 @@ static int CmdFlashMemWipe(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_FLASHMEM_WIPE, {page, initalwipe, 0}, {{0}}};
|
UsbCommand c = {CMD_FLASHMEM_WIPE, {page, initalwipe, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 8000)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 8000)) {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
uint8_t isok = resp.arg[0] & 0xFF;
|
uint8_t isok = resp.core.old.arg[0] & 0xFF;
|
||||||
if (isok)
|
if (isok)
|
||||||
PrintAndLogEx(SUCCESS, "Flash WIPE ok");
|
PrintAndLogEx(SUCCESS, "Flash WIPE ok");
|
||||||
else
|
else
|
||||||
|
@ -438,13 +438,13 @@ static int CmdFlashMemInfo(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_FLASHMEM_INFO, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_FLASHMEM_INFO, {0, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t isok = resp.arg[0] & 0xFF;
|
uint8_t isok = resp.core.old.arg[0] & 0xFF;
|
||||||
if (!isok) {
|
if (!isok) {
|
||||||
PrintAndLogEx(FAILED, "failed");
|
PrintAndLogEx(FAILED, "failed");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -452,7 +452,7 @@ static int CmdFlashMemInfo(const char *Cmd) {
|
||||||
|
|
||||||
// validate signature here
|
// validate signature here
|
||||||
rdv40_validation_t mem;
|
rdv40_validation_t mem;
|
||||||
memcpy(&mem, (rdv40_validation_t *)resp.d.asBytes, sizeof(rdv40_validation_t));
|
memcpy(&mem, (rdv40_validation_t *)resp.core.old.d.asBytes, sizeof(rdv40_validation_t));
|
||||||
|
|
||||||
// Flash ID hash (sha1)
|
// Flash ID hash (sha1)
|
||||||
mbedtls_sha1(mem.flashid, sizeof(mem.flashid), sha_hash);
|
mbedtls_sha1(mem.flashid, sizeof(mem.flashid), sha_hash);
|
||||||
|
@ -572,7 +572,7 @@ static int CmdFlashMemInfo(const char *Cmd) {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (!resp.arg[0])
|
if (!resp.core.old.arg[0])
|
||||||
PrintAndLogEx(FAILED, "Writing signature failed");
|
PrintAndLogEx(FAILED, "Writing signature failed");
|
||||||
else
|
else
|
||||||
PrintAndLogEx(SUCCESS, "Writing signature ok [offset: %u]", FLASH_MEM_SIGNATURE_OFFSET);
|
PrintAndLogEx(SUCCESS, "Writing signature ok [offset: %u]", FLASH_MEM_SIGNATURE_OFFSET);
|
||||||
|
|
|
@ -231,12 +231,12 @@ int Hf14443_4aGetCardData(iso14a_card_select_t *card) {
|
||||||
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}, {{0}}};
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
WaitForResponse(CMD_ACK, &resp);
|
WaitForResponse(CMD_ACK, &resp);
|
||||||
|
|
||||||
memcpy(card, (iso14a_card_select_t *)resp.d.asBytes, sizeof(iso14a_card_select_t));
|
memcpy(card, (iso14a_card_select_t *)resp.core.old.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
|
uint64_t select_status = resp.core.old.arg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
||||||
|
|
||||||
if (select_status == 0) {
|
if (select_status == 0) {
|
||||||
PrintAndLogEx(ERR, "E->iso14443a card select failed");
|
PrintAndLogEx(ERR, "E->iso14443a card select failed");
|
||||||
|
@ -256,7 +256,7 @@ int Hf14443_4aGetCardData(iso14a_card_select_t *card) {
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, " UID: %s", sprint_hex(card->uid, card->uidlen));
|
PrintAndLogEx(NORMAL, " UID: %s", sprint_hex(card->uid, card->uidlen));
|
||||||
PrintAndLogEx(NORMAL, "ATQA: %02x %02x", card->atqa[1], card->atqa[0]);
|
PrintAndLogEx(NORMAL, "ATQA: %02x %02x", card->atqa[1], card->atqa[0]);
|
||||||
PrintAndLogEx(NORMAL, " SAK: %02x [%" PRIu64 "]", card->sak, resp.arg[0]);
|
PrintAndLogEx(NORMAL, " SAK: %02x [%" PRIu64 "]", card->sak, resp.core.old.arg[0]);
|
||||||
if (card->ats_len < 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes
|
if (card->ats_len < 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes
|
||||||
PrintAndLogEx(NORMAL, "E-> Error ATS length(%d) : %s", card->ats_len, sprint_hex(card->ats, card->ats_len));
|
PrintAndLogEx(NORMAL, "E-> Error ATS length(%d) : %s", card->ats_len, sprint_hex(card->ats, card->ats_len));
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -303,7 +303,7 @@ static int CmdHF14AReader(const char *Cmd) {
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
if (ISO14A_CONNECT & cm) {
|
if (ISO14A_CONNECT & cm) {
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
if (!silent) PrintAndLogEx(WARNING, "iso14443a card select failed");
|
if (!silent) PrintAndLogEx(WARNING, "iso14443a card select failed");
|
||||||
DropField();
|
DropField();
|
||||||
|
@ -311,7 +311,7 @@ static 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.core.old.d.asBytes, sizeof(iso14a_card_select_t));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
0: couldn't read
|
0: couldn't read
|
||||||
|
@ -319,7 +319,7 @@ static int CmdHF14AReader(const char *Cmd) {
|
||||||
2: OK, no ATS
|
2: OK, no ATS
|
||||||
3: proprietary Anticollision
|
3: proprietary Anticollision
|
||||||
*/
|
*/
|
||||||
uint64_t select_status = resp.arg[0];
|
uint64_t select_status = resp.core.old.arg[0];
|
||||||
|
|
||||||
if (select_status == 0) {
|
if (select_status == 0) {
|
||||||
if (!silent) PrintAndLogEx(WARNING, "iso14443a card select failed");
|
if (!silent) PrintAndLogEx(WARNING, "iso14443a card select failed");
|
||||||
|
@ -336,7 +336,7 @@ static int CmdHF14AReader(const char *Cmd) {
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, " UID : %s", sprint_hex(card.uid, card.uidlen));
|
PrintAndLogEx(NORMAL, " UID : %s", sprint_hex(card.uid, card.uidlen));
|
||||||
PrintAndLogEx(NORMAL, "ATQA : %02x %02x", card.atqa[1], card.atqa[0]);
|
PrintAndLogEx(NORMAL, "ATQA : %02x %02x", card.atqa[1], card.atqa[0]);
|
||||||
PrintAndLogEx(NORMAL, " SAK : %02x [%" PRIu64 "]", card.sak, resp.arg[0]);
|
PrintAndLogEx(NORMAL, " SAK : %02x [%" PRIu64 "]", card.sak, resp.core.old.arg[0]);
|
||||||
|
|
||||||
if (card.ats_len >= 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes
|
if (card.ats_len >= 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes
|
||||||
PrintAndLogEx(NORMAL, " ATS : %s", sprint_hex(card.ats, card.ats_len));
|
PrintAndLogEx(NORMAL, " ATS : %s", sprint_hex(card.ats, card.ats_len));
|
||||||
|
@ -388,13 +388,13 @@ static int CmdHF14ACUIDs(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_RATS, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_RATS, 0, 0}, {{0}}};
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
WaitForResponse(CMD_ACK, &resp);
|
WaitForResponse(CMD_ACK, &resp);
|
||||||
|
|
||||||
iso14a_card_select_t *card = (iso14a_card_select_t *) resp.d.asBytes;
|
iso14a_card_select_t *card = (iso14a_card_select_t *) resp.core.old.d.asBytes;
|
||||||
|
|
||||||
// check if command failed
|
// check if command failed
|
||||||
if (resp.arg[0] == 0) {
|
if (resp.core.old.arg[0] == 0) {
|
||||||
PrintAndLogEx(WARNING, "card select failed.");
|
PrintAndLogEx(WARNING, "card select failed.");
|
||||||
} else {
|
} else {
|
||||||
char uid_string[20];
|
char uid_string[20];
|
||||||
|
@ -487,16 +487,16 @@ int CmdHF14ASim(const char *Cmd) {
|
||||||
memcpy(c.d.asBytes, uid, uidlen >> 1);
|
memcpy(c.d.asBytes, uid, uidlen >> 1);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
PrintAndLogEx(SUCCESS, "press pm3-button to abort simulation");
|
PrintAndLogEx(SUCCESS, "press pm3-button to abort simulation");
|
||||||
|
|
||||||
while (!ukbhit()) {
|
while (!ukbhit()) {
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue;
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue;
|
||||||
if (!(flags & FLAG_NR_AR_ATTACK)) break;
|
if (!(flags & FLAG_NR_AR_ATTACK)) break;
|
||||||
if ((resp.arg[0] & 0xffff) != CMD_SIMULATE_MIFARE_CARD) break;
|
if ((resp.core.old.arg[0] & 0xffff) != CMD_SIMULATE_MIFARE_CARD) break;
|
||||||
|
|
||||||
memcpy(data, resp.d.asBytes, sizeof(data));
|
memcpy(data, resp.core.old.d.asBytes, sizeof(data));
|
||||||
readerAttack(data[0], setEmulatorMem, verbose);
|
readerAttack(data[0], setEmulatorMem, verbose);
|
||||||
}
|
}
|
||||||
showSectorTable();
|
showSectorTable();
|
||||||
|
@ -525,7 +525,7 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav
|
||||||
|
|
||||||
if (activateField) {
|
if (activateField) {
|
||||||
responseNum = 1;
|
responseNum = 1;
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
// Anticollision + SELECT card
|
// Anticollision + SELECT card
|
||||||
UsbCommand ca = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}, {{0}}};
|
UsbCommand ca = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}, {{0}}};
|
||||||
|
@ -536,17 +536,17 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav
|
||||||
}
|
}
|
||||||
|
|
||||||
// check result
|
// check result
|
||||||
if (resp.arg[0] == 0) {
|
if (resp.core.old.arg[0] == 0) {
|
||||||
PrintAndLogEx(ERR, "No card in field.");
|
PrintAndLogEx(ERR, "No card in field.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.arg[0] != 1 && resp.arg[0] != 2) {
|
if (resp.core.old.arg[0] != 1 && resp.core.old.arg[0] != 2) {
|
||||||
PrintAndLogEx(ERR, "Card not in iso14443-4. res=%d.", resp.arg[0]);
|
PrintAndLogEx(ERR, "Card not in iso14443-4. res=%d.", resp.core.old.arg[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.arg[0] == 2) { // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
if (resp.core.old.arg[0] == 2) { // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
||||||
// get ATS
|
// get ATS
|
||||||
UsbCommand cr = {CMD_READER_ISO_14443a, {ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, 2, 0}, {{0}}};
|
UsbCommand cr = {CMD_READER_ISO_14443a, {ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, 2, 0}, {{0}}};
|
||||||
uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0
|
uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0
|
||||||
|
@ -557,7 +557,7 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.arg[0] == 0) { // ats_len
|
if (resp.core.old.arg[0] == 0) { // ats_len
|
||||||
PrintAndLogEx(ERR, "Can't get ATS.");
|
PrintAndLogEx(ERR, "Can't get ATS.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -575,11 +575,11 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
uint8_t *recv;
|
uint8_t *recv;
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
recv = resp.d.asBytes;
|
recv = resp.core.old.d.asBytes;
|
||||||
int iLen = resp.arg[0];
|
int iLen = resp.core.old.arg[0];
|
||||||
|
|
||||||
if (!iLen) {
|
if (!iLen) {
|
||||||
PrintAndLogEx(ERR, "No card response.");
|
PrintAndLogEx(ERR, "No card response.");
|
||||||
|
@ -617,7 +617,7 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav
|
||||||
}
|
}
|
||||||
|
|
||||||
static int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) {
|
static int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) {
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
frameLength = 0;
|
frameLength = 0;
|
||||||
|
|
||||||
|
@ -635,17 +635,17 @@ static int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check result
|
// check result
|
||||||
if (resp.arg[0] == 0) {
|
if (resp.core.old.arg[0] == 0) {
|
||||||
PrintAndLogEx(ERR, "No card in field.");
|
PrintAndLogEx(ERR, "No card in field.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.arg[0] != 1 && resp.arg[0] != 2) {
|
if (resp.core.old.arg[0] != 1 && resp.core.old.arg[0] != 2) {
|
||||||
PrintAndLogEx(ERR, "Card not in iso14443-4. res=%d.", resp.arg[0]);
|
PrintAndLogEx(ERR, "Card not in iso14443-4. res=%d.", resp.core.old.arg[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.arg[0] == 2) { // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
if (resp.core.old.arg[0] == 2) { // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
||||||
// get ATS
|
// get ATS
|
||||||
UsbCommand cr = {CMD_READER_ISO_14443a, {ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, 2, 0}, {{0}}};
|
UsbCommand cr = {CMD_READER_ISO_14443a, {ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, 2, 0}, {{0}}};
|
||||||
uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0
|
uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0
|
||||||
|
@ -656,20 +656,20 @@ static int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.arg[0] == 0) { // ats_len
|
if (resp.core.old.arg[0] == 0) { // ats_len
|
||||||
PrintAndLogEx(ERR, "Can't get ATS.");
|
PrintAndLogEx(ERR, "Can't get ATS.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get frame length from ATS in data field
|
// get frame length from ATS in data field
|
||||||
if (resp.arg[0] > 1) {
|
if (resp.core.old.arg[0] > 1) {
|
||||||
uint8_t fsci = resp.d.asBytes[1] & 0x0f;
|
uint8_t fsci = resp.core.old.d.asBytes[1] & 0x0f;
|
||||||
if (fsci < sizeof(atsFSC) / sizeof(atsFSC[0]))
|
if (fsci < sizeof(atsFSC) / sizeof(atsFSC[0]))
|
||||||
frameLength = atsFSC[fsci];
|
frameLength = atsFSC[fsci];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// get frame length from ATS in card data structure
|
// get frame length from ATS in card data structure
|
||||||
iso14a_card_select_t *vcard = (iso14a_card_select_t *) resp.d.asBytes;
|
iso14a_card_select_t *vcard = (iso14a_card_select_t *) resp.core.old.d.asBytes;
|
||||||
if (vcard->ats_len > 1) {
|
if (vcard->ats_len > 1) {
|
||||||
uint8_t fsci = vcard->ats[1] & 0x0f;
|
uint8_t fsci = vcard->ats[1] & 0x0f;
|
||||||
if (fsci < sizeof(atsFSC) / sizeof(atsFSC[0]))
|
if (fsci < sizeof(atsFSC) / sizeof(atsFSC[0]))
|
||||||
|
@ -712,12 +712,12 @@ static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
uint8_t *recv;
|
uint8_t *recv;
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
recv = resp.d.asBytes;
|
recv = resp.core.old.d.asBytes;
|
||||||
int iLen = resp.arg[0];
|
int iLen = resp.core.old.arg[0];
|
||||||
uint8_t res = resp.arg[1];
|
uint8_t res = resp.core.old.arg[1];
|
||||||
|
|
||||||
int dlen = iLen - 2;
|
int dlen = iLen - 2;
|
||||||
if (dlen < 0)
|
if (dlen < 0)
|
||||||
|
@ -1047,12 +1047,12 @@ static int CmdHF14ACmdRaw(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int waitCmd(uint8_t iSelect) {
|
static int waitCmd(uint8_t iSelect) {
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
uint16_t len = (resp.arg[0] & 0xFFFF);
|
uint16_t len = (resp.core.old.arg[0] & 0xFFFF);
|
||||||
if (iSelect) {
|
if (iSelect) {
|
||||||
len = (resp.arg[1] & 0xFFFF);
|
len = (resp.core.old.arg[1] & 0xFFFF);
|
||||||
if (len) {
|
if (len) {
|
||||||
PrintAndLogEx(NORMAL, "Card selected. UID[%i]:", len);
|
PrintAndLogEx(NORMAL, "Card selected. UID[%i]:", len);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1065,7 +1065,7 @@ static int waitCmd(uint8_t iSelect) {
|
||||||
if (!len)
|
if (!len)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "%s", sprint_hex(resp.d.asBytes, len));
|
PrintAndLogEx(NORMAL, "%s", sprint_hex(resp.core.old.d.asBytes, len));
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return 3;
|
return 3;
|
||||||
|
@ -1164,7 +1164,7 @@ int infoHF14A(bool verbose, bool do_nack_test) {
|
||||||
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
if (verbose) PrintAndLogEx(WARNING, "iso14443a card select failed");
|
if (verbose) PrintAndLogEx(WARNING, "iso14443a card select failed");
|
||||||
DropField();
|
DropField();
|
||||||
|
@ -1172,7 +1172,7 @@ int infoHF14A(bool verbose, bool do_nack_test) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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.core.old.d.asBytes, sizeof(iso14a_card_select_t));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
0: couldn't read
|
0: couldn't read
|
||||||
|
@ -1180,7 +1180,7 @@ int infoHF14A(bool verbose, bool do_nack_test) {
|
||||||
2: OK, no ATS
|
2: OK, no ATS
|
||||||
3: proprietary Anticollision
|
3: proprietary Anticollision
|
||||||
*/
|
*/
|
||||||
uint64_t select_status = resp.arg[0];
|
uint64_t select_status = resp.core.old.arg[0];
|
||||||
|
|
||||||
if (select_status == 0) {
|
if (select_status == 0) {
|
||||||
if (verbose) PrintAndLogEx(WARNING, "iso14443a card select failed");
|
if (verbose) PrintAndLogEx(WARNING, "iso14443a card select failed");
|
||||||
|
@ -1197,7 +1197,7 @@ int infoHF14A(bool verbose, bool do_nack_test) {
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, " UID : %s", sprint_hex(card.uid, card.uidlen));
|
PrintAndLogEx(NORMAL, " UID : %s", sprint_hex(card.uid, card.uidlen));
|
||||||
PrintAndLogEx(NORMAL, "ATQA : %02x %02x", card.atqa[1], card.atqa[0]);
|
PrintAndLogEx(NORMAL, "ATQA : %02x %02x", card.atqa[1], card.atqa[0]);
|
||||||
PrintAndLogEx(NORMAL, " SAK : %02x [%" PRIu64 "]", card.sak, resp.arg[0]);
|
PrintAndLogEx(NORMAL, " SAK : %02x [%" PRIu64 "]", card.sak, resp.core.old.arg[0]);
|
||||||
|
|
||||||
bool isMifareClassic = true;
|
bool isMifareClassic = true;
|
||||||
switch (card.sak) {
|
switch (card.sak) {
|
||||||
|
@ -1221,9 +1221,9 @@ int infoHF14A(bool verbose, bool do_nack_test) {
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
WaitForResponse(CMD_ACK, &resp);
|
WaitForResponse(CMD_ACK, &resp);
|
||||||
|
|
||||||
memcpy(&card, (iso14a_card_select_t *)resp.d.asBytes, sizeof(iso14a_card_select_t));
|
memcpy(&card, (iso14a_card_select_t *)resp.core.old.d.asBytes, sizeof(iso14a_card_select_t));
|
||||||
|
|
||||||
select_status = resp.arg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS
|
select_status = resp.core.old.arg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS
|
||||||
|
|
||||||
if (select_status == 0) {
|
if (select_status == 0) {
|
||||||
DropField();
|
DropField();
|
||||||
|
@ -1295,8 +1295,8 @@ int infoHF14A(bool verbose, bool do_nack_test) {
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
WaitForResponse(CMD_ACK, &resp);
|
WaitForResponse(CMD_ACK, &resp);
|
||||||
|
|
||||||
memcpy(card.ats, resp.d.asBytes, resp.arg[0]);
|
memcpy(card.ats, resp.core.old.d.asBytes, resp.core.old.arg[0]);
|
||||||
card.ats_len = resp.arg[0]; // note: ats_len includes CRC Bytes
|
card.ats_len = resp.core.old.arg[0]; // note: ats_len includes CRC Bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
if (card.ats_len >= 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes
|
if (card.ats_len >= 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes
|
||||||
|
|
|
@ -124,15 +124,15 @@ static int switch_off_field_14b(void) {
|
||||||
static bool waitCmd14b(bool verbose) {
|
static bool waitCmd14b(bool verbose) {
|
||||||
|
|
||||||
uint8_t data[USB_CMD_DATA_SIZE] = {0x00};
|
uint8_t data[USB_CMD_DATA_SIZE] = {0x00};
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
||||||
|
|
||||||
if ((resp.arg[0] & 0xFF) > 0) return false;
|
if ((resp.core.old.arg[0] & 0xFF) > 0) return false;
|
||||||
|
|
||||||
uint16_t len = (resp.arg[1] & 0xFFFF);
|
uint16_t len = (resp.core.old.arg[1] & 0xFFFF);
|
||||||
|
|
||||||
memcpy(data, resp.d.asBytes, len);
|
memcpy(data, resp.core.old.d.asBytes, len);
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
if (len >= 3) {
|
if (len >= 3) {
|
||||||
|
@ -301,7 +301,7 @@ static bool get_14b_UID(iso14b_card_select_t *card) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int8_t retry = 3;
|
int8_t retry = 3;
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_CONNECT | ISO14B_SELECT_SR | ISO14B_DISCONNECT, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_CONNECT | ISO14B_SELECT_SR | ISO14B_DISCONNECT, 0, 0}, {{0}}};
|
||||||
|
|
||||||
// test for 14b SR
|
// test for 14b SR
|
||||||
|
@ -311,9 +311,9 @@ static bool get_14b_UID(iso14b_card_select_t *card) {
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
||||||
|
|
||||||
uint8_t status = resp.arg[0];
|
uint8_t status = resp.core.old.arg[0];
|
||||||
if (status == 0) {
|
if (status == 0) {
|
||||||
memcpy(card, (iso14b_card_select_t *)resp.d.asBytes, sizeof(iso14b_card_select_t));
|
memcpy(card, (iso14b_card_select_t *)resp.core.old.d.asBytes, sizeof(iso14b_card_select_t));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,9 +329,9 @@ static bool get_14b_UID(iso14b_card_select_t *card) {
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
||||||
|
|
||||||
uint8_t status = resp.arg[0];
|
uint8_t status = resp.core.old.arg[0];
|
||||||
if (status == 0) {
|
if (status == 0) {
|
||||||
memcpy(card, (iso14b_card_select_t *)resp.d.asBytes, sizeof(iso14b_card_select_t));
|
memcpy(card, (iso14b_card_select_t *)resp.core.old.d.asBytes, sizeof(iso14b_card_select_t));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -512,7 +512,7 @@ static bool HF14B_Std_Info(bool verbose) {
|
||||||
UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_CONNECT | ISO14B_SELECT_STD | ISO14B_DISCONNECT, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_CONNECT | ISO14B_SELECT_STD | ISO14B_DISCONNECT, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
||||||
if (verbose) PrintAndLogEx(WARNING, "command execution timeout");
|
if (verbose) PrintAndLogEx(WARNING, "command execution timeout");
|
||||||
|
@ -521,9 +521,9 @@ static bool HF14B_Std_Info(bool verbose) {
|
||||||
}
|
}
|
||||||
|
|
||||||
iso14b_card_select_t card;
|
iso14b_card_select_t card;
|
||||||
memcpy(&card, (iso14b_card_select_t *)resp.d.asBytes, sizeof(iso14b_card_select_t));
|
memcpy(&card, (iso14b_card_select_t *)resp.core.old.d.asBytes, sizeof(iso14b_card_select_t));
|
||||||
|
|
||||||
uint64_t status = resp.arg[0];
|
uint64_t status = resp.core.old.arg[0];
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -553,7 +553,7 @@ static bool HF14B_ST_Info(bool verbose) {
|
||||||
UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_CONNECT | ISO14B_SELECT_SR | ISO14B_DISCONNECT, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_CONNECT | ISO14B_SELECT_SR | ISO14B_DISCONNECT, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
||||||
if (verbose) PrintAndLogEx(WARNING, "command execution timeout");
|
if (verbose) PrintAndLogEx(WARNING, "command execution timeout");
|
||||||
|
@ -561,9 +561,9 @@ static bool HF14B_ST_Info(bool verbose) {
|
||||||
}
|
}
|
||||||
|
|
||||||
iso14b_card_select_t card;
|
iso14b_card_select_t card;
|
||||||
memcpy(&card, (iso14b_card_select_t *)resp.d.asBytes, sizeof(iso14b_card_select_t));
|
memcpy(&card, (iso14b_card_select_t *)resp.core.old.d.asBytes, sizeof(iso14b_card_select_t));
|
||||||
|
|
||||||
uint64_t status = resp.arg[0];
|
uint64_t status = resp.core.old.arg[0];
|
||||||
if (status > 0)
|
if (status > 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -610,16 +610,16 @@ static bool HF14B_ST_Reader(bool verbose) {
|
||||||
UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_CONNECT | ISO14B_SELECT_SR | ISO14B_DISCONNECT, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_CONNECT | ISO14B_SELECT_SR | ISO14B_DISCONNECT, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
||||||
if (verbose) PrintAndLogEx(WARNING, "command execution timeout");
|
if (verbose) PrintAndLogEx(WARNING, "command execution timeout");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
iso14b_card_select_t card;
|
iso14b_card_select_t card;
|
||||||
memcpy(&card, (iso14b_card_select_t *)resp.d.asBytes, sizeof(iso14b_card_select_t));
|
memcpy(&card, (iso14b_card_select_t *)resp.core.old.d.asBytes, sizeof(iso14b_card_select_t));
|
||||||
|
|
||||||
uint64_t status = resp.arg[0];
|
uint64_t status = resp.core.old.arg[0];
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -650,7 +650,7 @@ static bool HF14B_Std_Reader(bool verbose) {
|
||||||
UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_CONNECT | ISO14B_SELECT_STD | ISO14B_DISCONNECT, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_CONNECT | ISO14B_SELECT_STD | ISO14B_DISCONNECT, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
||||||
if (verbose) PrintAndLogEx(WARNING, "command execution timeout");
|
if (verbose) PrintAndLogEx(WARNING, "command execution timeout");
|
||||||
|
@ -658,9 +658,9 @@ static bool HF14B_Std_Reader(bool verbose) {
|
||||||
}
|
}
|
||||||
|
|
||||||
iso14b_card_select_t card;
|
iso14b_card_select_t card;
|
||||||
memcpy(&card, (iso14b_card_select_t *)resp.d.asBytes, sizeof(iso14b_card_select_t));
|
memcpy(&card, (iso14b_card_select_t *)resp.core.old.d.asBytes, sizeof(iso14b_card_select_t));
|
||||||
|
|
||||||
uint64_t status = resp.arg[0];
|
uint64_t status = resp.core.old.arg[0];
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -697,7 +697,7 @@ static bool HF14B_Other_Reader() {
|
||||||
|
|
||||||
// clearCommandBuffer();
|
// clearCommandBuffer();
|
||||||
// SendCommand(&c);
|
// SendCommand(&c);
|
||||||
// UsbCommand resp;
|
// UsbReplyNG resp;
|
||||||
// WaitForResponse(CMD_ACK,&resp);
|
// WaitForResponse(CMD_ACK,&resp);
|
||||||
|
|
||||||
// if (datalen > 2 ) {
|
// if (datalen > 2 ) {
|
||||||
|
@ -712,7 +712,7 @@ static bool HF14B_Other_Reader() {
|
||||||
// c.d.asBytes[0] = ISO14443B_AUTHENTICATE;
|
// c.d.asBytes[0] = ISO14443B_AUTHENTICATE;
|
||||||
// clearCommandBuffer();
|
// clearCommandBuffer();
|
||||||
// SendCommand(&c);
|
// SendCommand(&c);
|
||||||
// UsbCommand resp;
|
// UsbReplyNG resp;
|
||||||
// WaitForResponse(CMD_ACK, &resp);
|
// WaitForResponse(CMD_ACK, &resp);
|
||||||
|
|
||||||
// if (datalen > 0) {
|
// if (datalen > 0) {
|
||||||
|
@ -727,7 +727,7 @@ static bool HF14B_Other_Reader() {
|
||||||
// c.d.asBytes[0] = ISO14443B_RESET;
|
// c.d.asBytes[0] = ISO14443B_RESET;
|
||||||
// clearCommandBuffer();
|
// clearCommandBuffer();
|
||||||
// SendCommand(&c);
|
// SendCommand(&c);
|
||||||
// UsbCommand resp;
|
// UsbReplyNG resp;
|
||||||
// WaitForResponse(CMD_ACK, &resp);
|
// WaitForResponse(CMD_ACK, &resp);
|
||||||
|
|
||||||
// if (datalen > 0) {
|
// if (datalen > 0) {
|
||||||
|
@ -901,15 +901,15 @@ static int CmdHF14BDump(const char *Cmd) {
|
||||||
int blocknum = 0;
|
int blocknum = 0;
|
||||||
uint8_t *recv = NULL;
|
uint8_t *recv = NULL;
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_ISO_14443B_COMMAND, { ISO14B_CONNECT | ISO14B_SELECT_SR, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_ISO_14443B_COMMAND, { ISO14B_CONNECT | ISO14B_SELECT_SR, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
//select
|
//select
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
if (resp.arg[0]) {
|
if (resp.core.old.arg[0]) {
|
||||||
PrintAndLogEx(INFO, "failed to select %d | %d", resp.arg[0], resp.arg[1]);
|
PrintAndLogEx(INFO, "failed to select %d | %d", resp.core.old.arg[0], resp.core.old.arg[1]);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -929,20 +929,20 @@ static int CmdHF14BDump(const char *Cmd) {
|
||||||
|
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
|
|
||||||
uint8_t status = resp.arg[0] & 0xFF;
|
uint8_t status = resp.core.old.arg[0] & 0xFF;
|
||||||
if (status > 0) {
|
if (status > 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t len = (resp.arg[1] & 0xFFFF);
|
uint16_t len = (resp.core.old.arg[1] & 0xFFFF);
|
||||||
recv = resp.d.asBytes;
|
recv = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
if (!check_crc(CRC_14443_B, recv, len)) {
|
if (!check_crc(CRC_14443_B, recv, len)) {
|
||||||
PrintAndLogEx(FAILED, "crc fail, retrying one more time");
|
PrintAndLogEx(FAILED, "crc fail, retrying one more time");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(data + (blocknum * 4), resp.d.asBytes, 4);
|
memcpy(data + (blocknum * 4), resp.core.old.d.asBytes, 4);
|
||||||
|
|
||||||
if (blocknum == 0xFF) {
|
if (blocknum == 0xFF) {
|
||||||
//last read.
|
//last read.
|
||||||
|
|
|
@ -198,7 +198,7 @@ const productName uidmapping[] = {
|
||||||
// returns 1 if suceeded
|
// returns 1 if suceeded
|
||||||
static int getUID(uint8_t *buf) {
|
static int getUID(uint8_t *buf) {
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}, {{0}}}; // len,speed,recv?
|
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}, {{0}}}; // len,speed,recv?
|
||||||
|
|
||||||
c.d.asBytes[0] = ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH | ISO15_REQ_INVENTORY | ISO15_REQINV_SLOT1;
|
c.d.asBytes[0] = ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH | ISO15_REQ_INVENTORY | ISO15_REQINV_SLOT1;
|
||||||
|
@ -218,9 +218,9 @@ static int getUID(uint8_t *buf) {
|
||||||
|
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
|
|
||||||
uint8_t resplen = resp.arg[0];
|
uint8_t resplen = resp.core.old.arg[0];
|
||||||
if (resplen >= 12 && CheckCrc15(resp.d.asBytes, 12)) {
|
if (resplen >= 12 && CheckCrc15(resp.core.old.d.asBytes, 12)) {
|
||||||
memcpy(buf, resp.d.asBytes + 2, 8);
|
memcpy(buf, resp.core.old.d.asBytes + 2, 8);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -594,7 +594,7 @@ static int CmdHF15Info(const char *Cmd) {
|
||||||
char cmdp = param_getchar(Cmd, 0);
|
char cmdp = param_getchar(Cmd, 0);
|
||||||
if (strlen(Cmd) < 1 || cmdp == 'h' || cmdp == 'H') return usage_15_info();
|
if (strlen(Cmd) < 1 || cmdp == 'h' || cmdp == 'H') return usage_15_info();
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
uint8_t *recv;
|
uint8_t *recv;
|
||||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}, {{0}}}; // len,speed,recv?
|
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}, {{0}}}; // len,speed,recv?
|
||||||
uint8_t *req = c.d.asBytes;
|
uint8_t *req = c.d.asBytes;
|
||||||
|
@ -619,14 +619,14 @@ static int CmdHF15Info(const char *Cmd) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t status = resp.arg[0];
|
uint32_t status = resp.core.old.arg[0];
|
||||||
|
|
||||||
if (status < 2) {
|
if (status < 2) {
|
||||||
PrintAndLogEx(WARNING, "iso15693 card doesn't answer to systeminfo command");
|
PrintAndLogEx(WARNING, "iso15693 card doesn't answer to systeminfo command");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
recv = resp.d.asBytes;
|
recv = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
if (recv[0] & ISO15_RES_ERROR) {
|
if (recv[0] & ISO15_RES_ERROR) {
|
||||||
PrintAndLogEx(WARNING, "iso15693 card returned error %i: %s", recv[0], TagErrorStr(recv[0]));
|
PrintAndLogEx(WARNING, "iso15693 card returned error %i: %s", recv[0], TagErrorStr(recv[0]));
|
||||||
|
@ -783,7 +783,7 @@ static int CmdHF15Dump(const char *Cmd) {
|
||||||
uint8_t data[256 * 4] = {0};
|
uint8_t data[256 * 4] = {0};
|
||||||
memset(data, 0, sizeof(data));
|
memset(data, 0, sizeof(data));
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}, {{0}}}; // len,speed,recv?
|
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}, {{0}}}; // len,speed,recv?
|
||||||
uint8_t *req = c.d.asBytes;
|
uint8_t *req = c.d.asBytes;
|
||||||
req[0] = ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH | ISO15_REQ_NONINVENTORY | ISO15_REQ_ADDRESS;
|
req[0] = ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH | ISO15_REQ_NONINVENTORY | ISO15_REQ_ADDRESS;
|
||||||
|
@ -803,13 +803,13 @@ static int CmdHF15Dump(const char *Cmd) {
|
||||||
|
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
|
|
||||||
uint8_t len = resp.arg[0];
|
uint8_t len = resp.core.old.arg[0];
|
||||||
if (len < 2) {
|
if (len < 2) {
|
||||||
PrintAndLogEx(FAILED, "iso15693 card select failed");
|
PrintAndLogEx(FAILED, "iso15693 card select failed");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
recv = resp.d.asBytes;
|
recv = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
if (!CheckCrc15(recv, len)) {
|
if (!CheckCrc15(recv, len)) {
|
||||||
PrintAndLogEx(FAILED, "crc fail");
|
PrintAndLogEx(FAILED, "crc fail");
|
||||||
|
@ -821,9 +821,9 @@ static int CmdHF15Dump(const char *Cmd) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mem[blocknum].lock = resp.d.asBytes[0];
|
mem[blocknum].lock = resp.core.old.d.asBytes[0];
|
||||||
memcpy(mem[blocknum].block, resp.d.asBytes + 1, 4);
|
memcpy(mem[blocknum].block, resp.core.old.d.asBytes + 1, 4);
|
||||||
memcpy(data + (blocknum * 4), resp.d.asBytes + 1, 4);
|
memcpy(data + (blocknum * 4), resp.core.old.d.asBytes + 1, 4);
|
||||||
|
|
||||||
retry = 0;
|
retry = 0;
|
||||||
blocknum++;
|
blocknum++;
|
||||||
|
@ -859,7 +859,7 @@ static int CmdHF15Raw(const char *Cmd) {
|
||||||
char cmdp = param_getchar(Cmd, 0);
|
char cmdp = param_getchar(Cmd, 0);
|
||||||
if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_raw();
|
if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_raw();
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}, {{0}}}; // len,speed,recv?
|
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}, {{0}}}; // len,speed,recv?
|
||||||
int reply = 1, fast = 1, i = 0;
|
int reply = 1, fast = 1, i = 0;
|
||||||
bool crc = false;
|
bool crc = false;
|
||||||
|
@ -926,9 +926,9 @@ static int CmdHF15Raw(const char *Cmd) {
|
||||||
|
|
||||||
if (reply) {
|
if (reply) {
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
uint8_t len = resp.arg[0];
|
uint8_t len = resp.core.old.arg[0];
|
||||||
PrintAndLogEx(NORMAL, "received %i octets", len);
|
PrintAndLogEx(NORMAL, "received %i octets", len);
|
||||||
PrintAndLogEx(NORMAL, "%s", sprint_hex(resp.d.asBytes, len));
|
PrintAndLogEx(NORMAL, "%s", sprint_hex(resp.core.old.d.asBytes, len));
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
}
|
}
|
||||||
|
@ -945,7 +945,7 @@ static int CmdHF15Readmulti(const char *Cmd) {
|
||||||
char cmdp = param_getchar(Cmd, 0);
|
char cmdp = param_getchar(Cmd, 0);
|
||||||
if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_readmulti();
|
if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_readmulti();
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
uint8_t *recv;
|
uint8_t *recv;
|
||||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}, {{0}}}; // len,speed,recv?
|
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}, {{0}}}; // len,speed,recv?
|
||||||
uint8_t *req = c.d.asBytes;
|
uint8_t *req = c.d.asBytes;
|
||||||
|
@ -986,13 +986,13 @@ static int CmdHF15Readmulti(const char *Cmd) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t status = resp.arg[0];
|
uint32_t status = resp.core.old.arg[0];
|
||||||
if (status < 2) {
|
if (status < 2) {
|
||||||
PrintAndLogEx(FAILED, "iso15693 card select failed");
|
PrintAndLogEx(FAILED, "iso15693 card select failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
recv = resp.d.asBytes;
|
recv = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
if (!CheckCrc15(recv, status)) {
|
if (!CheckCrc15(recv, status)) {
|
||||||
PrintAndLogEx(FAILED, "CRC failed");
|
PrintAndLogEx(FAILED, "CRC failed");
|
||||||
|
@ -1028,7 +1028,7 @@ static int CmdHF15Read(const char *Cmd) {
|
||||||
char cmdp = param_getchar(Cmd, 0);
|
char cmdp = param_getchar(Cmd, 0);
|
||||||
if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_read();
|
if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_read();
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
uint8_t *recv;
|
uint8_t *recv;
|
||||||
|
|
||||||
// UsbCommand arg: len, speed, recv?
|
// UsbCommand arg: len, speed, recv?
|
||||||
|
@ -1066,13 +1066,13 @@ static int CmdHF15Read(const char *Cmd) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t status = resp.arg[0];
|
uint32_t status = resp.core.old.arg[0];
|
||||||
if (status < 2) {
|
if (status < 2) {
|
||||||
PrintAndLogEx(NORMAL, "iso15693 card select failed");
|
PrintAndLogEx(NORMAL, "iso15693 card select failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
recv = resp.d.asBytes;
|
recv = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
if (!CheckCrc15(recv, status)) {
|
if (!CheckCrc15(recv, status)) {
|
||||||
PrintAndLogEx(NORMAL, "CRC failed");
|
PrintAndLogEx(NORMAL, "CRC failed");
|
||||||
|
@ -1102,7 +1102,7 @@ static int CmdHF15Write(const char *Cmd) {
|
||||||
char cmdp = param_getchar(Cmd, 0);
|
char cmdp = param_getchar(Cmd, 0);
|
||||||
if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_write();
|
if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_write();
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
uint8_t *recv;
|
uint8_t *recv;
|
||||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}, {{0}}}; // len,speed,recv?
|
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}, {{0}}}; // len,speed,recv?
|
||||||
uint8_t *req = c.d.asBytes;
|
uint8_t *req = c.d.asBytes;
|
||||||
|
@ -1150,13 +1150,13 @@ static int CmdHF15Write(const char *Cmd) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t status = resp.arg[0];
|
uint32_t status = resp.core.old.arg[0];
|
||||||
if (status < 2) {
|
if (status < 2) {
|
||||||
PrintAndLogEx(FAILED, "iso15693 card select failed");
|
PrintAndLogEx(FAILED, "iso15693 card select failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
recv = resp.d.asBytes;
|
recv = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
if (!CheckCrc15(recv, status)) {
|
if (!CheckCrc15(recv, status)) {
|
||||||
PrintAndLogEx(FAILED, "CRC failed");
|
PrintAndLogEx(FAILED, "CRC failed");
|
||||||
|
|
|
@ -34,17 +34,17 @@ static int CmdHFEPACollectPACENonces(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_EPA_PACE_COLLECT_NONCE, {(int)m, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_EPA_PACE_COLLECT_NONCE, {(int)m, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
WaitForResponse(CMD_ACK, &resp);
|
WaitForResponse(CMD_ACK, &resp);
|
||||||
|
|
||||||
// check if command failed
|
// check if command failed
|
||||||
if (resp.arg[0] != 0) {
|
if (resp.core.old.arg[0] != 0) {
|
||||||
PrintAndLogEx(FAILED, "Error in step %d, Return code: %d", resp.arg[0], (int)resp.arg[1]);
|
PrintAndLogEx(FAILED, "Error in step %d, Return code: %d", resp.core.old.arg[0], (int)resp.core.old.arg[1]);
|
||||||
} else {
|
} else {
|
||||||
size_t nonce_length = resp.arg[1];
|
size_t nonce_length = resp.core.old.arg[1];
|
||||||
char *nonce = (char *) calloc(2 * nonce_length + 1, sizeof(uint8_t));
|
char *nonce = (char *) calloc(2 * nonce_length + 1, sizeof(uint8_t));
|
||||||
for (int j = 0; j < nonce_length; j++) {
|
for (int j = 0; j < nonce_length; j++) {
|
||||||
sprintf(nonce + (2 * j), "%02X", resp.d.asBytes[j]);
|
sprintf(nonce + (2 * j), "%02X", resp.core.old.d.asBytes[j]);
|
||||||
}
|
}
|
||||||
// print nonce
|
// print nonce
|
||||||
PrintAndLogEx(NORMAL, "Length: %d, Nonce: %s", nonce_length, nonce);
|
PrintAndLogEx(NORMAL, "Length: %d, Nonce: %s", nonce_length, nonce);
|
||||||
|
@ -72,7 +72,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) {
|
||||||
"Example:\n preplay 0022C1A4 1068000000 1086000002 1234ABCDEF 1A2B3C4D";
|
"Example:\n preplay 0022C1A4 1068000000 1086000002 1234ABCDEF 1A2B3C4D";
|
||||||
|
|
||||||
// Proxmark response
|
// Proxmark response
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
int skip = 0, skip_add = 0, scan_return;
|
int skip = 0, skip_add = 0, scan_return;
|
||||||
// for each APDU
|
// for each APDU
|
||||||
|
@ -132,7 +132,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&usb_cmd);
|
SendCommand(&usb_cmd);
|
||||||
WaitForResponse(CMD_ACK, &resp);
|
WaitForResponse(CMD_ACK, &resp);
|
||||||
if (resp.arg[0] != 0) {
|
if (resp.core.old.arg[0] != 0) {
|
||||||
PrintAndLogEx(WARNING, "Transfer of APDU #%d Part %d failed!", i, j);
|
PrintAndLogEx(WARNING, "Transfer of APDU #%d Part %d failed!", i, j);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -144,21 +144,21 @@ static int CmdHFEPAPACEReplay(const char *Cmd) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&usb_cmd);
|
SendCommand(&usb_cmd);
|
||||||
WaitForResponse(CMD_ACK, &resp);
|
WaitForResponse(CMD_ACK, &resp);
|
||||||
if (resp.arg[0] != 0) {
|
if (resp.core.old.arg[0] != 0) {
|
||||||
PrintAndLogEx(NORMAL, "\nPACE replay failed in step %u!", (uint32_t)resp.arg[0]);
|
PrintAndLogEx(NORMAL, "\nPACE replay failed in step %u!", (uint32_t)resp.core.old.arg[0]);
|
||||||
PrintAndLogEx(NORMAL, "Measured times:");
|
PrintAndLogEx(NORMAL, "Measured times:");
|
||||||
PrintAndLogEx(NORMAL, "MSE Set AT: %u us", resp.d.asDwords[0]);
|
PrintAndLogEx(NORMAL, "MSE Set AT: %u us", resp.core.old.d.asDwords[0]);
|
||||||
PrintAndLogEx(NORMAL, "GA Get Nonce: %u us", resp.d.asDwords[1]);
|
PrintAndLogEx(NORMAL, "GA Get Nonce: %u us", resp.core.old.d.asDwords[1]);
|
||||||
PrintAndLogEx(NORMAL, "GA Map Nonce: %u us", resp.d.asDwords[2]);
|
PrintAndLogEx(NORMAL, "GA Map Nonce: %u us", resp.core.old.d.asDwords[2]);
|
||||||
PrintAndLogEx(NORMAL, "GA Perform Key Agreement: %u us", resp.d.asDwords[3]);
|
PrintAndLogEx(NORMAL, "GA Perform Key Agreement: %u us", resp.core.old.d.asDwords[3]);
|
||||||
PrintAndLogEx(NORMAL, "GA Mutual Authenticate: %u us", resp.d.asDwords[4]);
|
PrintAndLogEx(NORMAL, "GA Mutual Authenticate: %u us", resp.core.old.d.asDwords[4]);
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(NORMAL, "PACE replay successfull!");
|
PrintAndLogEx(NORMAL, "PACE replay successfull!");
|
||||||
PrintAndLogEx(NORMAL, "MSE Set AT: %u us", resp.d.asDwords[0]);
|
PrintAndLogEx(NORMAL, "MSE Set AT: %u us", resp.core.old.d.asDwords[0]);
|
||||||
PrintAndLogEx(NORMAL, "GA Get Nonce: %u us", resp.d.asDwords[1]);
|
PrintAndLogEx(NORMAL, "GA Get Nonce: %u us", resp.core.old.d.asDwords[1]);
|
||||||
PrintAndLogEx(NORMAL, "GA Map Nonce: %u us", resp.d.asDwords[2]);
|
PrintAndLogEx(NORMAL, "GA Map Nonce: %u us", resp.core.old.d.asDwords[2]);
|
||||||
PrintAndLogEx(NORMAL, "GA Perform Key Agreement: %u us", resp.d.asDwords[3]);
|
PrintAndLogEx(NORMAL, "GA Perform Key Agreement: %u us", resp.core.old.d.asDwords[3]);
|
||||||
PrintAndLogEx(NORMAL, "GA Mutual Authenticate: %u us", resp.d.asDwords[4]);
|
PrintAndLogEx(NORMAL, "GA Mutual Authenticate: %u us", resp.core.old.d.asDwords[4]);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ static int CmdHFFelicaSim(const char *Cmd) {
|
||||||
memcpy(c.d.asBytes, uid, uidlen >> 1);
|
memcpy(c.d.asBytes, uid, uidlen >> 1);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
PrintAndLogEx(NORMAL, "Press pm3-button to abort simulation");
|
PrintAndLogEx(NORMAL, "Press pm3-button to abort simulation");
|
||||||
|
@ -355,7 +355,7 @@ static int CmdHFFelicaDumpLite(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_FELICA_LITE_DUMP, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_FELICA_LITE_DUMP, {0, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
uint8_t timeout = 0;
|
uint8_t timeout = 0;
|
||||||
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
|
@ -375,12 +375,12 @@ static int CmdHFFelicaDumpLite(const char *Cmd) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (resp.arg[0] == 0) {
|
if (resp.core.old.arg[0] == 0) {
|
||||||
PrintAndLogEx(WARNING, "\nButton pressed. Aborted.");
|
PrintAndLogEx(WARNING, "\nButton pressed. Aborted.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t tracelen = resp.arg[1];
|
uint64_t tracelen = resp.core.old.arg[1];
|
||||||
if (tracelen == 0)
|
if (tracelen == 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
@ -412,14 +412,14 @@ static int CmdHFFelicaDumpLite(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void waitCmdFelica(uint8_t iSelect) {
|
static void waitCmdFelica(uint8_t iSelect) {
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
uint16_t len = iSelect ? (resp.arg[1] & 0xffff) : (resp.arg[0] & 0xffff);
|
uint16_t len = iSelect ? (resp.core.old.arg[1] & 0xffff) : (resp.core.old.arg[0] & 0xffff);
|
||||||
PrintAndLogEx(NORMAL, "received %i octets", len);
|
PrintAndLogEx(NORMAL, "received %i octets", len);
|
||||||
if (!len)
|
if (!len)
|
||||||
return;
|
return;
|
||||||
PrintAndLogEx(NORMAL, "%s", sprint_hex(resp.d.asBytes, len));
|
PrintAndLogEx(NORMAL, "%s", sprint_hex(resp.core.old.d.asBytes, len));
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
}
|
}
|
||||||
|
@ -572,7 +572,7 @@ int readFelicaUid(bool verbose) {
|
||||||
UsbCommand c = {CMD_FELICA_COMMAND, {FELICA_CONNECT, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_FELICA_COMMAND, {FELICA_CONNECT, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
if (verbose) PrintAndLogEx(WARNING, "FeliCa card select failed");
|
if (verbose) PrintAndLogEx(WARNING, "FeliCa card select failed");
|
||||||
//SendCommand(&cDisconnect);
|
//SendCommand(&cDisconnect);
|
||||||
|
@ -580,8 +580,8 @@ int readFelicaUid(bool verbose) {
|
||||||
}
|
}
|
||||||
|
|
||||||
felica_card_select_t card;
|
felica_card_select_t card;
|
||||||
memcpy(&card, (felica_card_select_t *)resp.d.asBytes, sizeof(felica_card_select_t));
|
memcpy(&card, (felica_card_select_t *)resp.core.old.d.asBytes, sizeof(felica_card_select_t));
|
||||||
uint64_t status = resp.arg[0];
|
uint64_t status = resp.core.old.arg[0];
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 1: {
|
case 1: {
|
||||||
|
|
|
@ -381,7 +381,7 @@ static int CmdHFiClassSim(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, "Starting iCLASS sim 2 attack (elite mode)");
|
PrintAndLogEx(INFO, "Starting iCLASS sim 2 attack (elite mode)");
|
||||||
PrintAndLogEx(INFO, "press keyboard to cancel");
|
PrintAndLogEx(INFO, "press keyboard to cancel");
|
||||||
UsbCommand c = {CMD_SIMULATE_TAG_ICLASS, {simType, NUM_CSNS}, {{0}}};
|
UsbCommand c = {CMD_SIMULATE_TAG_ICLASS, {simType, NUM_CSNS}, {{0}}};
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
memcpy(c.d.asBytes, csns, 8 * NUM_CSNS);
|
memcpy(c.d.asBytes, csns, 8 * NUM_CSNS);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
@ -399,7 +399,7 @@ static int CmdHFiClassSim(const char *Cmd) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint8_t num_mac = resp.arg[1];
|
uint8_t num_mac = resp.core.old.arg[1];
|
||||||
bool success = (NUM_CSNS == num_mac);
|
bool success = (NUM_CSNS == num_mac);
|
||||||
PrintAndLogEx(NORMAL, "[%c] %d out of %d MAC obtained [%s]", (success) ? '+' : '!', num_mac, NUM_CSNS, (success) ? "OK" : "FAIL");
|
PrintAndLogEx(NORMAL, "[%c] %d out of %d MAC obtained [%s]", (success) ? '+' : '!', num_mac, NUM_CSNS, (success) ? "OK" : "FAIL");
|
||||||
|
|
||||||
|
@ -420,9 +420,9 @@ static int CmdHFiClassSim(const char *Cmd) {
|
||||||
//copy CSN
|
//copy CSN
|
||||||
memcpy(dump + i * 24, csns + i * 8, 8);
|
memcpy(dump + i * 24, csns + i * 8, 8);
|
||||||
//copy epurse
|
//copy epurse
|
||||||
memcpy(dump + i * 24 + 8, resp.d.asBytes + i * 16, 8);
|
memcpy(dump + i * 24 + 8, resp.core.old.d.asBytes + i * 16, 8);
|
||||||
// NR_MAC (eight bytes from the response) ( 8b csn + 8b epurse == 16)
|
// NR_MAC (eight bytes from the response) ( 8b csn + 8b epurse == 16)
|
||||||
memcpy(dump + i * 24 + 16, resp.d.asBytes + i * 16 + 8, 8);
|
memcpy(dump + i * 24 + 16, resp.core.old.d.asBytes + i * 16 + 8, 8);
|
||||||
}
|
}
|
||||||
/** Now, save to dumpfile **/
|
/** Now, save to dumpfile **/
|
||||||
saveFile("iclass_mac_attack", "bin", dump, datalen);
|
saveFile("iclass_mac_attack", "bin", dump, datalen);
|
||||||
|
@ -434,7 +434,7 @@ static int CmdHFiClassSim(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, "Starting iCLASS sim 4 attack (elite mode, reader in key roll mode)");
|
PrintAndLogEx(INFO, "Starting iCLASS sim 4 attack (elite mode, reader in key roll mode)");
|
||||||
PrintAndLogEx(INFO, "press keyboard to cancel");
|
PrintAndLogEx(INFO, "press keyboard to cancel");
|
||||||
UsbCommand c = {CMD_SIMULATE_TAG_ICLASS, {simType, NUM_CSNS}, {{0}}};
|
UsbCommand c = {CMD_SIMULATE_TAG_ICLASS, {simType, NUM_CSNS}, {{0}}};
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
memcpy(c.d.asBytes, csns, 8 * NUM_CSNS);
|
memcpy(c.d.asBytes, csns, 8 * NUM_CSNS);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
@ -452,7 +452,7 @@ static int CmdHFiClassSim(const char *Cmd) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint8_t num_mac = resp.arg[1];
|
uint8_t num_mac = resp.core.old.arg[1];
|
||||||
bool success = ((NUM_CSNS * 2) == num_mac);
|
bool success = ((NUM_CSNS * 2) == num_mac);
|
||||||
PrintAndLogEx(NORMAL, "[%c] %d out of %d MAC obtained [%s]", (success) ? '+' : '!', num_mac, NUM_CSNS * 2, (success) ? "OK" : "FAIL");
|
PrintAndLogEx(NORMAL, "[%c] %d out of %d MAC obtained [%s]", (success) ? '+' : '!', num_mac, NUM_CSNS * 2, (success) ? "OK" : "FAIL");
|
||||||
|
|
||||||
|
@ -475,9 +475,9 @@ static int CmdHFiClassSim(const char *Cmd) {
|
||||||
// copy CSN
|
// copy CSN
|
||||||
memcpy(dump + i * MAC_ITEM_SIZE, csns + i * 8, 8); //CSN
|
memcpy(dump + i * MAC_ITEM_SIZE, csns + i * 8, 8); //CSN
|
||||||
// copy EPURSE
|
// copy EPURSE
|
||||||
memcpy(dump + i * MAC_ITEM_SIZE + 8, resp.d.asBytes + i * 16, 8);
|
memcpy(dump + i * MAC_ITEM_SIZE + 8, resp.core.old.d.asBytes + i * 16, 8);
|
||||||
// copy NR_MAC (eight bytes from the response) ( 8b csn + 8b epurse == 16)
|
// copy NR_MAC (eight bytes from the response) ( 8b csn + 8b epurse == 16)
|
||||||
memcpy(dump + i * MAC_ITEM_SIZE + 16, resp.d.asBytes + i * 16 + 8, 8);
|
memcpy(dump + i * MAC_ITEM_SIZE + 16, resp.core.old.d.asBytes + i * 16 + 8, 8);
|
||||||
}
|
}
|
||||||
saveFile("iclass_mac_attack_keyroll_A", "bin", dump, datalen);
|
saveFile("iclass_mac_attack_keyroll_A", "bin", dump, datalen);
|
||||||
|
|
||||||
|
@ -489,9 +489,9 @@ static int CmdHFiClassSim(const char *Cmd) {
|
||||||
// Copy CSN
|
// Copy CSN
|
||||||
memcpy(dump + i * MAC_ITEM_SIZE, csns + i * 8, 8);
|
memcpy(dump + i * MAC_ITEM_SIZE, csns + i * 8, 8);
|
||||||
// copy EPURSE
|
// copy EPURSE
|
||||||
memcpy(dump + i * MAC_ITEM_SIZE + 8, resp.d.asBytes + resp_index, 8);
|
memcpy(dump + i * MAC_ITEM_SIZE + 8, resp.core.old.d.asBytes + resp_index, 8);
|
||||||
// copy NR_MAC (eight bytes from the response) ( 8b csn + 8 epurse == 16)
|
// copy NR_MAC (eight bytes from the response) ( 8b csn + 8 epurse == 16)
|
||||||
memcpy(dump + i * MAC_ITEM_SIZE + 16, resp.d.asBytes + resp_index + 8, 8);
|
memcpy(dump + i * MAC_ITEM_SIZE + 16, resp.core.old.d.asBytes + resp_index + 8, 8);
|
||||||
resp_index++;
|
resp_index++;
|
||||||
}
|
}
|
||||||
saveFile("iclass_mac_attack_keyroll_B", "bin", dump, datalen);
|
saveFile("iclass_mac_attack_keyroll_B", "bin", dump, datalen);
|
||||||
|
@ -767,7 +767,7 @@ static void Calc_wb_mac(uint8_t blockno, uint8_t *data, uint8_t *div_key, uint8_
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool select_only(uint8_t *CSN, uint8_t *CCNR, bool use_credit_key, bool verbose) {
|
static bool select_only(uint8_t *CSN, uint8_t *CCNR, bool use_credit_key, bool verbose) {
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_READER_ICLASS, {0}, {{0}}};
|
UsbCommand c = {CMD_READER_ICLASS, {0}, {{0}}};
|
||||||
c.arg[0] = FLAG_ICLASS_READER_ONLY_ONCE | FLAG_ICLASS_READER_CC | FLAG_ICLASS_READER_ONE_TRY;
|
c.arg[0] = FLAG_ICLASS_READER_ONLY_ONCE | FLAG_ICLASS_READER_CC | FLAG_ICLASS_READER_ONE_TRY;
|
||||||
|
|
||||||
|
@ -781,8 +781,8 @@ static bool select_only(uint8_t *CSN, uint8_t *CCNR, bool use_credit_key, bool v
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
uint8_t *data = resp.d.asBytes;
|
uint8_t *data = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
memcpy(CSN, data, 8);
|
memcpy(CSN, data, 8);
|
||||||
|
|
||||||
|
@ -818,7 +818,7 @@ static bool select_and_auth(uint8_t *KEY, uint8_t *MAC, uint8_t *div_key, bool u
|
||||||
if (verbose) PrintAndLogEx(SUCCESS, "authing with %s: %s", rawkey ? "raw key" : "diversified key", sprint_hex(div_key, 8));
|
if (verbose) PrintAndLogEx(SUCCESS, "authing with %s: %s", rawkey ? "raw key" : "diversified key", sprint_hex(div_key, 8));
|
||||||
|
|
||||||
doMAC(CCNR, div_key, MAC);
|
doMAC(CCNR, div_key, MAC);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand d = {CMD_ICLASS_AUTHENTICATION, {0, 0, 0}, {{0}}};
|
UsbCommand d = {CMD_ICLASS_AUTHENTICATION, {0, 0, 0}, {{0}}};
|
||||||
memcpy(d.d.asBytes, MAC, 4);
|
memcpy(d.d.asBytes, MAC, 4);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
|
@ -827,7 +827,7 @@ static bool select_and_auth(uint8_t *KEY, uint8_t *MAC, uint8_t *div_key, bool u
|
||||||
if (verbose) PrintAndLogEx(FAILED, "auth command execute timeout");
|
if (verbose) PrintAndLogEx(FAILED, "auth command execute timeout");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint8_t isOK = resp.arg[0] & 0xFF;
|
uint8_t isOK = resp.core.old.arg[0] & 0xFF;
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
if (verbose) PrintAndLogEx(FAILED, "authentication error");
|
if (verbose) PrintAndLogEx(FAILED, "authentication error");
|
||||||
return false;
|
return false;
|
||||||
|
@ -940,7 +940,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) {
|
||||||
|
|
||||||
//get config and first 3 blocks
|
//get config and first 3 blocks
|
||||||
UsbCommand c = {CMD_READER_ICLASS, {flags, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_READER_ICLASS, {flags, 0, 0}, {{0}}};
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
uint8_t tag_data[255 * 8];
|
uint8_t tag_data[255 * 8];
|
||||||
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
|
@ -952,8 +952,8 @@ static int CmdHFiClassReader_Dump(const char *Cmd) {
|
||||||
}
|
}
|
||||||
DropField();
|
DropField();
|
||||||
|
|
||||||
uint8_t readStatus = resp.arg[0] & 0xff;
|
uint8_t readStatus = resp.core.old.arg[0] & 0xff;
|
||||||
uint8_t *data = resp.d.asBytes;
|
uint8_t *data = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
if (readStatus == 0) {
|
if (readStatus == 0) {
|
||||||
PrintAndLogEx(FAILED, "no tag found");
|
PrintAndLogEx(FAILED, "no tag found");
|
||||||
|
@ -1000,14 +1000,14 @@ static int CmdHFiClassReader_Dump(const char *Cmd) {
|
||||||
}
|
}
|
||||||
// dump cmd switch off at device when finised.
|
// dump cmd switch off at device when finised.
|
||||||
|
|
||||||
uint32_t blocksRead = resp.arg[1];
|
uint32_t blocksRead = resp.core.old.arg[1];
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (!isOK && !blocksRead) {
|
if (!isOK && !blocksRead) {
|
||||||
PrintAndLogEx(WARNING, "read block failed");
|
PrintAndLogEx(WARNING, "read block failed");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t startindex = resp.arg[2];
|
uint32_t startindex = resp.core.old.arg[2];
|
||||||
if (blocksRead * 8 > sizeof(tag_data) - (blockno * 8)) {
|
if (blocksRead * 8 > sizeof(tag_data) - (blockno * 8)) {
|
||||||
PrintAndLogEx(FAILED, "data exceeded buffer size!");
|
PrintAndLogEx(FAILED, "data exceeded buffer size!");
|
||||||
blocksRead = (sizeof(tag_data) / 8) - blockno;
|
blocksRead = (sizeof(tag_data) / 8) - blockno;
|
||||||
|
@ -1046,14 +1046,14 @@ static int CmdHFiClassReader_Dump(const char *Cmd) {
|
||||||
PrintAndLogEx(WARNING, "command execute timeout 2");
|
PrintAndLogEx(WARNING, "command execute timeout 2");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
isOK = resp.arg[0] & 0xff;
|
isOK = resp.core.old.arg[0] & 0xff;
|
||||||
blocksRead = resp.arg[1];
|
blocksRead = resp.core.old.arg[1];
|
||||||
if (!isOK && !blocksRead) {
|
if (!isOK && !blocksRead) {
|
||||||
PrintAndLogEx(WARNING, "read block failed 2");
|
PrintAndLogEx(WARNING, "read block failed 2");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
startindex = resp.arg[2];
|
startindex = resp.core.old.arg[2];
|
||||||
if (blocksRead * 8 > sizeof(tag_data) - gotBytes) {
|
if (blocksRead * 8 > sizeof(tag_data) - gotBytes) {
|
||||||
PrintAndLogEx(FAILED, "data exceeded buffer size!");
|
PrintAndLogEx(FAILED, "data exceeded buffer size!");
|
||||||
blocksRead = (sizeof(tag_data) - gotBytes) / 8;
|
blocksRead = (sizeof(tag_data) - gotBytes) / 8;
|
||||||
|
@ -1097,7 +1097,7 @@ static int WriteBlock(uint8_t blockno, uint8_t *bldata, uint8_t *KEY, bool use_c
|
||||||
if (!select_and_auth(KEY, MAC, div_key, use_credit_key, elite, rawkey, verbose))
|
if (!select_and_auth(KEY, MAC, div_key, use_credit_key, elite, rawkey, verbose))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
Calc_wb_mac(blockno, bldata, div_key, MAC);
|
Calc_wb_mac(blockno, bldata, div_key, MAC);
|
||||||
UsbCommand w = {CMD_ICLASS_WRITEBLOCK, {blockno}, {{0}}};
|
UsbCommand w = {CMD_ICLASS_WRITEBLOCK, {blockno}, {{0}}};
|
||||||
|
@ -1110,7 +1110,7 @@ static int WriteBlock(uint8_t blockno, uint8_t *bldata, uint8_t *KEY, bool use_c
|
||||||
if (verbose) PrintAndLogEx(WARNING, "Write Command execute timeout");
|
if (verbose) PrintAndLogEx(WARNING, "Write Command execute timeout");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (isOK)
|
if (isOK)
|
||||||
PrintAndLogEx(SUCCESS, "Write block successful");
|
PrintAndLogEx(SUCCESS, "Write block successful");
|
||||||
else
|
else
|
||||||
|
@ -1342,7 +1342,7 @@ static int CmdHFiClassCloneTag(const char *Cmd) {
|
||||||
PrintAndLogEx(NORMAL, " MAC |%02x%02x%02x%02x|\n", p[8], p[9], p[10], p[11]);
|
PrintAndLogEx(NORMAL, " MAC |%02x%02x%02x%02x|\n", p[8], p[9], p[10], p[11]);
|
||||||
}
|
}
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&w);
|
SendCommand(&w);
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 4500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 4500)) {
|
||||||
|
@ -1367,7 +1367,7 @@ static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_ICLASS_READBLOCK, {blockno}, {{0}}};
|
UsbCommand c = {CMD_ICLASS_READBLOCK, {blockno}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
@ -1376,13 +1376,13 @@ static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
PrintAndLogEx(WARNING, "read block failed");
|
PrintAndLogEx(WARNING, "read block failed");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//data read is stored in: resp.d.asBytes[0-15]
|
//data read is stored in: resp.core.old.d.asBytes[0-15]
|
||||||
PrintAndLogEx(NORMAL, "block %02X: %s\n", blockno, sprint_hex(resp.d.asBytes, 8));
|
PrintAndLogEx(NORMAL, "block %02X: %s\n", blockno, sprint_hex(resp.core.old.d.asBytes, 8));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1987,7 +1987,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) {
|
||||||
memcpy(c.d.asBytes, pre + i, 4 * keys);
|
memcpy(c.d.asBytes, pre + i, 4 * keys);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
timeout++;
|
timeout++;
|
||||||
|
@ -1999,8 +1999,8 @@ static int CmdHFiClassCheckKeys(const char *Cmd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t found = resp.arg[1] & 0xFF;
|
uint8_t found = resp.core.old.arg[1] & 0xFF;
|
||||||
uint8_t isOK = resp.arg[0] & 0xFF;
|
uint8_t isOK = resp.core.old.arg[0] & 0xFF;
|
||||||
|
|
||||||
t2 = msclock() - t2;
|
t2 = msclock() - t2;
|
||||||
switch (isOK) {
|
switch (isOK) {
|
||||||
|
@ -2467,14 +2467,14 @@ int readIclass(bool loop, bool verbose) {
|
||||||
|
|
||||||
UsbCommand c = {CMD_READER_ICLASS, {flags, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_READER_ICLASS, {flags, 0, 0}, {{0}}};
|
||||||
// loop in client not device - else on windows have a communication error
|
// loop in client not device - else on windows have a communication error
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
while (!ukbhit()) {
|
while (!ukbhit()) {
|
||||||
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 4500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 4500)) {
|
||||||
uint8_t readStatus = resp.arg[0] & 0xff;
|
uint8_t readStatus = resp.core.old.arg[0] & 0xff;
|
||||||
uint8_t *data = resp.d.asBytes;
|
uint8_t *data = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
if (verbose) PrintAndLogEx(NORMAL, "Readstatus:%02x", readStatus);
|
if (verbose) PrintAndLogEx(NORMAL, "Readstatus:%02x", readStatus);
|
||||||
// no tag found or button pressed
|
// no tag found or button pressed
|
||||||
|
|
|
@ -644,7 +644,7 @@ static int CmdLegicRfWrite(const char *Cmd) {
|
||||||
|
|
||||||
UsbCommand c = {CMD_WRITER_LEGIC_RF, {offset, len, IV}, {{0}}};
|
UsbCommand c = {CMD_WRITER_LEGIC_RF, {offset, len, IV}, {{0}}};
|
||||||
memcpy(c.d.asBytes, data, len);
|
memcpy(c.d.asBytes, data, len);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
|
@ -661,7 +661,7 @@ static int CmdLegicRfWrite(const char *Cmd) {
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "\n");
|
PrintAndLogEx(NORMAL, "\n");
|
||||||
|
|
||||||
uint8_t isOK = resp.arg[0] & 0xFF;
|
uint8_t isOK = resp.core.old.arg[0] & 0xFF;
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
PrintAndLogEx(WARNING, "Failed writing tag");
|
PrintAndLogEx(WARNING, "Failed writing tag");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -759,7 +759,7 @@ int legic_read_mem(uint32_t offset, uint32_t len, uint32_t iv, uint8_t *out, uin
|
||||||
UsbCommand c = {CMD_READER_LEGIC_RF, {offset, len, iv}, {{0}}};
|
UsbCommand c = {CMD_READER_LEGIC_RF, {offset, len, iv}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
uint8_t timeout = 0;
|
uint8_t timeout = 0;
|
||||||
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
|
@ -773,8 +773,8 @@ int legic_read_mem(uint32_t offset, uint32_t len, uint32_t iv, uint8_t *out, uin
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "\n");
|
PrintAndLogEx(NORMAL, "\n");
|
||||||
|
|
||||||
uint8_t isOK = resp.arg[0] & 0xFF;
|
uint8_t isOK = resp.core.old.arg[0] & 0xFF;
|
||||||
*outlen = resp.arg[1];
|
*outlen = resp.core.old.arg[1];
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
PrintAndLogEx(WARNING, "Failed reading tag");
|
PrintAndLogEx(WARNING, "Failed reading tag");
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -813,15 +813,15 @@ int legic_get_type(legic_card_select_t *card) {
|
||||||
UsbCommand c = {CMD_LEGIC_INFO, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_LEGIC_INFO, {0, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500))
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500))
|
||||||
return 2;
|
return 2;
|
||||||
|
|
||||||
uint8_t isOK = resp.arg[0] & 0xFF;
|
uint8_t isOK = resp.core.old.arg[0] & 0xFF;
|
||||||
if (!isOK)
|
if (!isOK)
|
||||||
return 3;
|
return 3;
|
||||||
|
|
||||||
memcpy(card, (legic_card_select_t *)resp.d.asBytes, sizeof(legic_card_select_t));
|
memcpy(card, (legic_card_select_t *)resp.core.old.d.asBytes, sizeof(legic_card_select_t));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void legic_chk_iv(uint32_t *iv) {
|
void legic_chk_iv(uint32_t *iv) {
|
||||||
|
@ -903,7 +903,7 @@ static int CmdLegicDump(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_READER_LEGIC_RF, {0x00, dumplen, 0x55}, {{0}}};
|
UsbCommand c = {CMD_READER_LEGIC_RF, {0x00, dumplen, 0x55}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
uint8_t timeout = 0;
|
uint8_t timeout = 0;
|
||||||
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
|
@ -917,13 +917,13 @@ static int CmdLegicDump(const char *Cmd) {
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "\n");
|
PrintAndLogEx(NORMAL, "\n");
|
||||||
|
|
||||||
uint8_t isOK = resp.arg[0] & 0xFF;
|
uint8_t isOK = resp.core.old.arg[0] & 0xFF;
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
PrintAndLogEx(WARNING, "Failed dumping tag data");
|
PrintAndLogEx(WARNING, "Failed dumping tag data");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t readlen = resp.arg[1];
|
uint16_t readlen = resp.core.old.arg[1];
|
||||||
uint8_t *data = calloc(readlen, sizeof(uint8_t));
|
uint8_t *data = calloc(readlen, sizeof(uint8_t));
|
||||||
if (!data) {
|
if (!data) {
|
||||||
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
|
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
|
||||||
|
@ -1050,7 +1050,7 @@ static int CmdLegicRestore(const char *Cmd) {
|
||||||
|
|
||||||
// transfer to device
|
// transfer to device
|
||||||
UsbCommand c = {CMD_WRITER_LEGIC_RF, {0, 0, 0x55}, {{0}}};
|
UsbCommand c = {CMD_WRITER_LEGIC_RF, {0, 0, 0x55}, {{0}}};
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
for (size_t i = 7; i < numofbytes; i += USB_CMD_DATA_SIZE) {
|
for (size_t i = 7; i < numofbytes; i += USB_CMD_DATA_SIZE) {
|
||||||
|
|
||||||
size_t len = MIN((numofbytes - i), USB_CMD_DATA_SIZE);
|
size_t len = MIN((numofbytes - i), USB_CMD_DATA_SIZE);
|
||||||
|
@ -1073,9 +1073,9 @@ static int CmdLegicRestore(const char *Cmd) {
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "\n");
|
PrintAndLogEx(NORMAL, "\n");
|
||||||
|
|
||||||
uint8_t isOK = resp.arg[0] & 0xFF;
|
uint8_t isOK = resp.core.old.arg[0] & 0xFF;
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
PrintAndLogEx(WARNING, "Failed writing tag [msg = %u]", resp.arg[1] & 0xFF);
|
PrintAndLogEx(WARNING, "Failed writing tag [msg = %u]", resp.core.old.arg[1] & 0xFF);
|
||||||
free(data);
|
free(data);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1243,7 +1243,7 @@ static int CmdLegicWipe(const char *Cmd) {
|
||||||
|
|
||||||
// transfer to device
|
// transfer to device
|
||||||
UsbCommand c = {CMD_WRITER_LEGIC_RF, {0, 0, 0x55}, {{0}}};
|
UsbCommand c = {CMD_WRITER_LEGIC_RF, {0, 0, 0x55}, {{0}}};
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
for (size_t i = 7; i < card.cardsize; i += USB_CMD_DATA_SIZE) {
|
for (size_t i = 7; i < card.cardsize; i += USB_CMD_DATA_SIZE) {
|
||||||
|
|
||||||
printf(".");
|
printf(".");
|
||||||
|
@ -1268,9 +1268,9 @@ static int CmdLegicWipe(const char *Cmd) {
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "\n");
|
PrintAndLogEx(NORMAL, "\n");
|
||||||
|
|
||||||
uint8_t isOK = resp.arg[0] & 0xFF;
|
uint8_t isOK = resp.core.old.arg[0] & 0xFF;
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
PrintAndLogEx(WARNING, "Failed writing tag [msg = %u]", resp.arg[1] & 0xFF);
|
PrintAndLogEx(WARNING, "Failed writing tag [msg = %u]", resp.core.old.arg[1] & 0xFF);
|
||||||
free(data);
|
free(data);
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -414,7 +414,7 @@ static int GetHFMF14AUID(uint8_t *uid, int *uidlen) {
|
||||||
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
PrintAndLogEx(WARNING, "iso14443a card select failed");
|
PrintAndLogEx(WARNING, "iso14443a card select failed");
|
||||||
DropField();
|
DropField();
|
||||||
|
@ -422,7 +422,7 @@ static int GetHFMF14AUID(uint8_t *uid, int *uidlen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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.core.old.d.asBytes, sizeof(iso14a_card_select_t));
|
||||||
memcpy(uid, card.uid, card.uidlen * sizeof(uint8_t));
|
memcpy(uid, card.uid, card.uidlen * sizeof(uint8_t));
|
||||||
*uidlen = card.uidlen;
|
*uidlen = card.uidlen;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -528,9 +528,9 @@ static int CmdHF14AMfWrBl(const char *Cmd) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
PrintAndLogEx(NORMAL, "isOk:%02x", isOK);
|
PrintAndLogEx(NORMAL, "isOk:%02x", isOK);
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(NORMAL, "Command execute timeout");
|
PrintAndLogEx(NORMAL, "Command execute timeout");
|
||||||
|
@ -573,10 +573,10 @@ static int CmdHF14AMfRdBl(const char *Cmd) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
uint8_t *data = resp.d.asBytes;
|
uint8_t *data = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
if (isOK) {
|
if (isOK) {
|
||||||
PrintAndLogEx(NORMAL, "isOk:%02x data:%s", isOK, sprint_hex(data, 16));
|
PrintAndLogEx(NORMAL, "isOk:%02x data:%s", isOK, sprint_hex(data, 16));
|
||||||
|
@ -644,10 +644,10 @@ static int CmdHF14AMfRdSc(const char *Cmd) {
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
isOK = resp.arg[0] & 0xff;
|
isOK = resp.core.old.arg[0] & 0xff;
|
||||||
data = resp.d.asBytes;
|
data = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "isOk:%02x", isOK);
|
PrintAndLogEx(NORMAL, "isOk:%02x", isOK);
|
||||||
if (isOK) {
|
if (isOK) {
|
||||||
|
@ -736,7 +736,7 @@ static int CmdHF14AMfDump(const char *Cmd) {
|
||||||
memset(dataFilename, 0, sizeof(dataFilename));
|
memset(dataFilename, 0, sizeof(dataFilename));
|
||||||
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00) {
|
while (param_getchar(Cmd, cmdp) != 0x00) {
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||||
|
@ -809,8 +809,8 @@ static int CmdHF14AMfDump(const char *Cmd) {
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
uint8_t *data = resp.d.asBytes;
|
uint8_t *data = resp.core.old.d.asBytes;
|
||||||
if (isOK) {
|
if (isOK) {
|
||||||
rights[sectorNo][0] = ((data[7] & 0x10) >> 2) | ((data[8] & 0x1) << 1) | ((data[8] & 0x10) >> 4); // C1C2C3 for data area 0
|
rights[sectorNo][0] = ((data[7] & 0x10) >> 2) | ((data[8] & 0x1) << 1) | ((data[8] & 0x10) >> 4); // C1C2C3 for data area 0
|
||||||
rights[sectorNo][1] = ((data[7] & 0x20) >> 3) | ((data[8] & 0x2) << 0) | ((data[8] & 0x20) >> 5); // C1C2C3 for data area 1
|
rights[sectorNo][1] = ((data[7] & 0x20) >> 3) | ((data[8] & 0x2) << 0) | ((data[8] & 0x20) >> 5); // C1C2C3 for data area 1
|
||||||
|
@ -865,14 +865,14 @@ static int CmdHF14AMfDump(const char *Cmd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (received) {
|
if (received) {
|
||||||
isOK = resp.arg[0] & 0xff;
|
isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (isOK) break;
|
if (isOK) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (received) {
|
if (received) {
|
||||||
isOK = resp.arg[0] & 0xff;
|
isOK = resp.core.old.arg[0] & 0xff;
|
||||||
uint8_t *data = resp.d.asBytes;
|
uint8_t *data = resp.core.old.d.asBytes;
|
||||||
if (blockNo == NumBlocksPerSector(sectorNo) - 1) { // sector trailer. Fill in the keys.
|
if (blockNo == NumBlocksPerSector(sectorNo) - 1) { // sector trailer. Fill in the keys.
|
||||||
data[0] = (keyA[sectorNo][0]);
|
data[0] = (keyA[sectorNo][0]);
|
||||||
data[1] = (keyA[sectorNo][1]);
|
data[1] = (keyA[sectorNo][1]);
|
||||||
|
@ -1050,9 +1050,9 @@ static int CmdHF14AMfRestore(const char *Cmd) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
PrintAndLogEx(SUCCESS, "isOk:%02x", isOK);
|
PrintAndLogEx(SUCCESS, "isOk:%02x", isOK);
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(WARNING, "Command execute timeout");
|
PrintAndLogEx(WARNING, "Command execute timeout");
|
||||||
|
@ -1256,13 +1256,13 @@ static int CmdHF14AMfNested(const char *Cmd) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue;
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue;
|
||||||
|
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (!isOK) continue;
|
if (!isOK) continue;
|
||||||
|
|
||||||
uint8_t *data = resp.d.asBytes;
|
uint8_t *data = resp.core.old.d.asBytes;
|
||||||
key64 = bytes_to_num(data + 10, 6);
|
key64 = bytes_to_num(data + 10, 6);
|
||||||
if (key64) {
|
if (key64) {
|
||||||
PrintAndLogEx(SUCCESS, "data: %s", sprint_hex(data + 10, 6));
|
PrintAndLogEx(SUCCESS, "data: %s", sprint_hex(data + 10, 6));
|
||||||
|
@ -2002,13 +2002,13 @@ static int CmdHF14AMfChk(const char *Cmd) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue;
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue;
|
||||||
|
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (!isOK) continue;
|
if (!isOK) continue;
|
||||||
|
|
||||||
uint8_t *data = resp.d.asBytes;
|
uint8_t *data = resp.core.old.d.asBytes;
|
||||||
key64 = bytes_to_num(data + 10, 6);
|
key64 = bytes_to_num(data + 10, 6);
|
||||||
if (key64) {
|
if (key64) {
|
||||||
PrintAndLogEx(NORMAL, "Data:%s", sprint_hex(data + 10, 6));
|
PrintAndLogEx(NORMAL, "Data:%s", sprint_hex(data + 10, 6));
|
||||||
|
@ -2231,7 +2231,7 @@ static int CmdHF14AMf1kSim(const char *Cmd) {
|
||||||
memcpy(c.d.asBytes, uid, sizeof(uid));
|
memcpy(c.d.asBytes, uid, sizeof(uid));
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (flags & FLAG_INTERACTIVE) {
|
if (flags & FLAG_INTERACTIVE) {
|
||||||
PrintAndLogEx(INFO, "Press pm3-button or send another cmd to abort simulation");
|
PrintAndLogEx(INFO, "Press pm3-button or send another cmd to abort simulation");
|
||||||
|
@ -2239,9 +2239,9 @@ static int CmdHF14AMf1kSim(const char *Cmd) {
|
||||||
while (!ukbhit()) {
|
while (!ukbhit()) {
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue;
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue;
|
||||||
if (!(flags & FLAG_NR_AR_ATTACK)) break;
|
if (!(flags & FLAG_NR_AR_ATTACK)) break;
|
||||||
if ((resp.arg[0] & 0xffff) != CMD_SIMULATE_MIFARE_CARD) break;
|
if ((resp.core.old.arg[0] & 0xffff) != CMD_SIMULATE_MIFARE_CARD) break;
|
||||||
|
|
||||||
memcpy(data, resp.d.asBytes, sizeof(data));
|
memcpy(data, resp.core.old.d.asBytes, sizeof(data));
|
||||||
readerAttack(data[0], setEmulatorMem, verbose);
|
readerAttack(data[0], setEmulatorMem, verbose);
|
||||||
}
|
}
|
||||||
showSectorTable();
|
showSectorTable();
|
||||||
|
@ -2291,7 +2291,7 @@ static int CmdHF14AMfSniff(const char *Cmd) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
// wait cycle
|
// wait cycle
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -2308,9 +2308,9 @@ static int CmdHF14AMfSniff(const char *Cmd) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = resp.arg[0] & 0xff;
|
res = resp.core.old.arg[0] & 0xff;
|
||||||
traceLen = resp.arg[1];
|
traceLen = resp.core.old.arg[1];
|
||||||
len = resp.arg[2];
|
len = resp.core.old.arg[2];
|
||||||
|
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
PrintAndLogEx(SUCCESS, "hf mifare sniff finished");
|
PrintAndLogEx(SUCCESS, "hf mifare sniff finished");
|
||||||
|
@ -2340,7 +2340,7 @@ static int CmdHF14AMfSniff(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// what happens if LEN is bigger then TRACELEN --iceman
|
// what happens if LEN is bigger then TRACELEN --iceman
|
||||||
memcpy(bufPtr, resp.d.asBytes, len);
|
memcpy(bufPtr, resp.core.old.d.asBytes, len);
|
||||||
bufPtr += len;
|
bufPtr += len;
|
||||||
pckNum++;
|
pckNum++;
|
||||||
}
|
}
|
||||||
|
@ -3156,9 +3156,9 @@ static int CmdHf14AMfSetMod(const char *Cmd) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
uint8_t ok = resp.arg[0] & 0xff;
|
uint8_t ok = resp.core.old.arg[0] & 0xff;
|
||||||
PrintAndLogEx(SUCCESS, "isOk:%02x", ok);
|
PrintAndLogEx(SUCCESS, "isOk:%02x", ok);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
PrintAndLogEx(FAILED, "Failed.");
|
PrintAndLogEx(FAILED, "Failed.");
|
||||||
|
@ -3198,7 +3198,7 @@ static int CmdHF14AMfice(const char *Cmd) {
|
||||||
char ctmp;
|
char ctmp;
|
||||||
char filename[FILE_PATH_SIZE], *fptr;
|
char filename[FILE_PATH_SIZE], *fptr;
|
||||||
FILE *fnonces = NULL;
|
FILE *fnonces = NULL;
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
uint32_t part_limit = 3000;
|
uint32_t part_limit = 3000;
|
||||||
uint32_t limit = 50000;
|
uint32_t limit = 50000;
|
||||||
|
@ -3257,11 +3257,11 @@ static int CmdHF14AMfice(const char *Cmd) {
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 3000)) goto out;
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 3000)) goto out;
|
||||||
if (resp.arg[0]) goto out;
|
if (resp.core.old.arg[0]) goto out;
|
||||||
|
|
||||||
uint32_t items = resp.arg[2];
|
uint32_t items = resp.core.old.arg[2];
|
||||||
if (fnonces) {
|
if (fnonces) {
|
||||||
fwrite(resp.d.asBytes, 1, items * 4, fnonces);
|
fwrite(resp.core.old.d.asBytes, 1, items * 4, fnonces);
|
||||||
fflush(fnonces);
|
fflush(fnonces);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,9 @@ static int CmdHF14ADesWb(const char *Cmd) {
|
||||||
memcpy(c.d.asBytes + 10, bldata, 16);
|
memcpy(c.d.asBytes + 10, bldata, 16);
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
PrintAndLogEx(NORMAL, "isOk:%02x", isOK);
|
PrintAndLogEx(NORMAL, "isOk:%02x", isOK);
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(NORMAL, "Command execute timeout");
|
PrintAndLogEx(NORMAL, "Command execute timeout");
|
||||||
|
@ -97,10 +97,10 @@ static int CmdHF14ADesRb(const char *Cmd) {
|
||||||
memcpy(c.d.asBytes, key, 6);
|
memcpy(c.d.asBytes, key, 6);
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
uint8_t * data = resp.d.asBytes;
|
uint8_t * data = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
if (isOK)
|
if (isOK)
|
||||||
PrintAndLogEx(NORMAL, "isOk:%02x data:%s", isOK, sprint_hex(data, 16));
|
PrintAndLogEx(NORMAL, "isOk:%02x data:%s", isOK, sprint_hex(data, 16));
|
||||||
|
@ -118,15 +118,15 @@ static int CmdHF14ADesInfo(const char *Cmd) {
|
||||||
|
|
||||||
UsbCommand c = {CMD_MIFARE_DESFIRE_INFO, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_MIFARE_DESFIRE_INFO, {0, 0, 0}, {{0}}};
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
PrintAndLogEx(WARNING, "Command execute timeout");
|
PrintAndLogEx(WARNING, "Command execute timeout");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
switch (resp.arg[1]) {
|
switch (resp.core.old.arg[1]) {
|
||||||
case 1:
|
case 1:
|
||||||
PrintAndLogEx(WARNING, "Can't select card");
|
PrintAndLogEx(WARNING, "Can't select card");
|
||||||
break;
|
break;
|
||||||
|
@ -143,25 +143,25 @@ static int CmdHF14ADesInfo(const char *Cmd) {
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(NORMAL, "-- Desfire Information --------------------------------------");
|
PrintAndLogEx(NORMAL, "-- Desfire Information --------------------------------------");
|
||||||
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
|
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
|
||||||
PrintAndLogEx(NORMAL, " UID : %s", sprint_hex(resp.d.asBytes, 7));
|
PrintAndLogEx(NORMAL, " UID : %s", sprint_hex(resp.core.old.d.asBytes, 7));
|
||||||
PrintAndLogEx(NORMAL, " Batch number : %s", sprint_hex(resp.d.asBytes + 28, 5));
|
PrintAndLogEx(NORMAL, " Batch number : %s", sprint_hex(resp.core.old.d.asBytes + 28, 5));
|
||||||
PrintAndLogEx(NORMAL, " Production date : week %02x, 20%02x", resp.d.asBytes[33], resp.d.asBytes[34]);
|
PrintAndLogEx(NORMAL, " Production date : week %02x, 20%02x", resp.core.old.d.asBytes[33], resp.core.old.d.asBytes[34]);
|
||||||
PrintAndLogEx(NORMAL, " -----------------------------------------------------------");
|
PrintAndLogEx(NORMAL, " -----------------------------------------------------------");
|
||||||
PrintAndLogEx(NORMAL, " Hardware Information");
|
PrintAndLogEx(NORMAL, " Hardware Information");
|
||||||
PrintAndLogEx(NORMAL, " Vendor Id : %s", getTagInfo(resp.d.asBytes[7]));
|
PrintAndLogEx(NORMAL, " Vendor Id : %s", getTagInfo(resp.core.old.d.asBytes[7]));
|
||||||
PrintAndLogEx(NORMAL, " Type : 0x%02X", resp.d.asBytes[8]);
|
PrintAndLogEx(NORMAL, " Type : 0x%02X", resp.core.old.d.asBytes[8]);
|
||||||
PrintAndLogEx(NORMAL, " Subtype : 0x%02X", resp.d.asBytes[9]);
|
PrintAndLogEx(NORMAL, " Subtype : 0x%02X", resp.core.old.d.asBytes[9]);
|
||||||
PrintAndLogEx(NORMAL, " Version : %s", getVersionStr(resp.d.asBytes[10], resp.d.asBytes[11]));
|
PrintAndLogEx(NORMAL, " Version : %s", getVersionStr(resp.core.old.d.asBytes[10], resp.core.old.d.asBytes[11]));
|
||||||
PrintAndLogEx(NORMAL, " Storage size : %s", getCardSizeStr(resp.d.asBytes[12]));
|
PrintAndLogEx(NORMAL, " Storage size : %s", getCardSizeStr(resp.core.old.d.asBytes[12]));
|
||||||
PrintAndLogEx(NORMAL, " Protocol : %s", getProtocolStr(resp.d.asBytes[13]));
|
PrintAndLogEx(NORMAL, " Protocol : %s", getProtocolStr(resp.core.old.d.asBytes[13]));
|
||||||
PrintAndLogEx(NORMAL, " -----------------------------------------------------------");
|
PrintAndLogEx(NORMAL, " -----------------------------------------------------------");
|
||||||
PrintAndLogEx(NORMAL, " Software Information");
|
PrintAndLogEx(NORMAL, " Software Information");
|
||||||
PrintAndLogEx(NORMAL, " Vendor Id : %s", getTagInfo(resp.d.asBytes[14]));
|
PrintAndLogEx(NORMAL, " Vendor Id : %s", getTagInfo(resp.core.old.d.asBytes[14]));
|
||||||
PrintAndLogEx(NORMAL, " Type : 0x%02X", resp.d.asBytes[15]);
|
PrintAndLogEx(NORMAL, " Type : 0x%02X", resp.core.old.d.asBytes[15]);
|
||||||
PrintAndLogEx(NORMAL, " Subtype : 0x%02X", resp.d.asBytes[16]);
|
PrintAndLogEx(NORMAL, " Subtype : 0x%02X", resp.core.old.d.asBytes[16]);
|
||||||
PrintAndLogEx(NORMAL, " Version : %d.%d", resp.d.asBytes[17], resp.d.asBytes[18]);
|
PrintAndLogEx(NORMAL, " Version : %d.%d", resp.core.old.d.asBytes[17], resp.core.old.d.asBytes[18]);
|
||||||
PrintAndLogEx(NORMAL, " storage size : %s", getCardSizeStr(resp.d.asBytes[19]));
|
PrintAndLogEx(NORMAL, " storage size : %s", getCardSizeStr(resp.core.old.d.asBytes[19]));
|
||||||
PrintAndLogEx(NORMAL, " Protocol : %s", getProtocolStr(resp.d.asBytes[20]));
|
PrintAndLogEx(NORMAL, " Protocol : %s", getProtocolStr(resp.core.old.d.asBytes[20]));
|
||||||
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
|
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
|
||||||
|
|
||||||
// Master Key settings
|
// Master Key settings
|
||||||
|
@ -177,7 +177,7 @@ static int CmdHF14ADesInfo(const char *Cmd) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
uint8_t tmp[3];
|
uint8_t tmp[3];
|
||||||
memcpy(tmp, resp.d.asBytes + 3, 3);
|
memcpy(tmp, resp.core.old.d.asBytes + 3, 3);
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, " Available free memory on card : %d bytes", le24toh(tmp));
|
PrintAndLogEx(NORMAL, " Available free memory on card : %d bytes", le24toh(tmp));
|
||||||
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
|
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
|
||||||
|
@ -257,7 +257,7 @@ void getKeySettings(uint8_t *aid) {
|
||||||
uint8_t isOK = 0;
|
uint8_t isOK = 0;
|
||||||
uint32_t options;
|
uint32_t options;
|
||||||
UsbCommand c = {CMD_MIFARE_DESFIRE, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_MIFARE_DESFIRE, {0, 0, 0}, {{0}}};
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
//memset(messStr, 0x00, 512);
|
//memset(messStr, 0x00, 512);
|
||||||
|
|
||||||
|
@ -269,19 +269,19 @@ void getKeySettings(uint8_t *aid) {
|
||||||
c.d.asBytes[0] = GET_KEY_SETTINGS; // 0x45
|
c.d.asBytes[0] = GET_KEY_SETTINGS; // 0x45
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
|
||||||
isOK = resp.arg[0] & 0xff;
|
isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
PrintAndLogEx(WARNING, " Can't select master application");
|
PrintAndLogEx(WARNING, " Can't select master application");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = (resp.d.asBytes[3] & (1 << 3)) ? "YES" : "NO";
|
str = (resp.core.old.d.asBytes[3] & (1 << 3)) ? "YES" : "NO";
|
||||||
PrintAndLogEx(NORMAL, " [0x08] Configuration changeable : %s", str);
|
PrintAndLogEx(NORMAL, " [0x08] Configuration changeable : %s", str);
|
||||||
str = (resp.d.asBytes[3] & (1 << 2)) ? "NO" : "YES";
|
str = (resp.core.old.d.asBytes[3] & (1 << 2)) ? "NO" : "YES";
|
||||||
PrintAndLogEx(NORMAL, " [0x04] CMK required for create/delete : %s", str);
|
PrintAndLogEx(NORMAL, " [0x04] CMK required for create/delete : %s", str);
|
||||||
str = (resp.d.asBytes[3] & (1 << 1)) ? "NO" : "YES";
|
str = (resp.core.old.d.asBytes[3] & (1 << 1)) ? "NO" : "YES";
|
||||||
PrintAndLogEx(NORMAL, " [0x02] Directory list access with CMK : %s", str);
|
PrintAndLogEx(NORMAL, " [0x02] Directory list access with CMK : %s", str);
|
||||||
str = (resp.d.asBytes[3] & (1 << 0)) ? "YES" : "NO";
|
str = (resp.core.old.d.asBytes[3] & (1 << 0)) ? "YES" : "NO";
|
||||||
PrintAndLogEx(NORMAL, " [0x01] CMK is changeable : %s", str);
|
PrintAndLogEx(NORMAL, " [0x01] CMK is changeable : %s", str);
|
||||||
|
|
||||||
c.arg[LENPOS] = 0x02; //LEN
|
c.arg[LENPOS] = 0x02; //LEN
|
||||||
|
@ -289,14 +289,14 @@ void getKeySettings(uint8_t *aid) {
|
||||||
c.d.asBytes[1] = 0x00;
|
c.d.asBytes[1] = 0x00;
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) { return; }
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) { return; }
|
||||||
isOK = resp.arg[0] & 0xff;
|
isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
PrintAndLogEx(WARNING, " Can't read key-version");
|
PrintAndLogEx(WARNING, " Can't read key-version");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(NORMAL, " Max number of keys : %d", resp.d.asBytes[4]);
|
PrintAndLogEx(NORMAL, " Max number of keys : %d", resp.core.old.d.asBytes[4]);
|
||||||
PrintAndLogEx(NORMAL, " Master key Version : %d (0x%02x)", resp.d.asBytes[3], resp.d.asBytes[3]);
|
PrintAndLogEx(NORMAL, " Master key Version : %d (0x%02x)", resp.core.old.d.asBytes[3], resp.core.old.d.asBytes[3]);
|
||||||
PrintAndLogEx(NORMAL, " ----------------------------------------------------------");
|
PrintAndLogEx(NORMAL, " ----------------------------------------------------------");
|
||||||
|
|
||||||
c.arg[LENPOS] = 0x02; //LEN
|
c.arg[LENPOS] = 0x02; //LEN
|
||||||
|
@ -304,19 +304,19 @@ void getKeySettings(uint8_t *aid) {
|
||||||
c.d.asBytes[1] = 0x00; // KEY 0
|
c.d.asBytes[1] = 0x00; // KEY 0
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
|
||||||
isOK = resp.d.asBytes[2] & 0xff;
|
isOK = resp.core.old.d.asBytes[2] & 0xff;
|
||||||
PrintAndLogEx(NORMAL, " [0x0A] Authenticate : %s", (isOK == 0xAE) ? "NO" : "YES");
|
PrintAndLogEx(NORMAL, " [0x0A] Authenticate : %s", (isOK == 0xAE) ? "NO" : "YES");
|
||||||
|
|
||||||
c.d.asBytes[0] = AUTHENTICATE_ISO; //0x1A
|
c.d.asBytes[0] = AUTHENTICATE_ISO; //0x1A
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
|
||||||
isOK = resp.d.asBytes[2] & 0xff;
|
isOK = resp.core.old.d.asBytes[2] & 0xff;
|
||||||
PrintAndLogEx(NORMAL, " [0x1A] Authenticate ISO : %s", (isOK == 0xAE) ? "NO" : "YES");
|
PrintAndLogEx(NORMAL, " [0x1A] Authenticate ISO : %s", (isOK == 0xAE) ? "NO" : "YES");
|
||||||
|
|
||||||
c.d.asBytes[0] = AUTHENTICATE_AES; //0xAA
|
c.d.asBytes[0] = AUTHENTICATE_AES; //0xAA
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {return;}
|
||||||
isOK = resp.d.asBytes[2] & 0xff;
|
isOK = resp.core.old.d.asBytes[2] & 0xff;
|
||||||
PrintAndLogEx(NORMAL, " [0xAA] Authenticate AES : %s", (isOK == 0xAE) ? "NO" : "YES");
|
PrintAndLogEx(NORMAL, " [0xAA] Authenticate AES : %s", (isOK == 0xAE) ? "NO" : "YES");
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(NORMAL, " ----------------------------------------------------------");
|
PrintAndLogEx(NORMAL, " ----------------------------------------------------------");
|
||||||
|
@ -335,7 +335,7 @@ void getKeySettings(uint8_t *aid) {
|
||||||
PrintAndLogEx(WARNING, " Timed-out");
|
PrintAndLogEx(WARNING, " Timed-out");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isOK = resp.arg[0] & 0xff;
|
isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
PrintAndLogEx(WARNING, " Can't select AID: %s", sprint_hex(aid, 3));
|
PrintAndLogEx(WARNING, " Can't select AID: %s", sprint_hex(aid, 3));
|
||||||
return;
|
return;
|
||||||
|
@ -350,12 +350,12 @@ void getKeySettings(uint8_t *aid) {
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isOK = resp.arg[0] & 0xff;
|
isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
PrintAndLogEx(WARNING, " Can't read Application Master key settings");
|
PrintAndLogEx(WARNING, " Can't read Application Master key settings");
|
||||||
} else {
|
} else {
|
||||||
// Access rights.
|
// Access rights.
|
||||||
uint8_t rights = (resp.d.asBytes[3] >> 4 & 0xff);
|
uint8_t rights = (resp.core.old.d.asBytes[3] >> 4 & 0xff);
|
||||||
switch (rights) {
|
switch (rights) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
str = "AMK authentication is necessary to change any key (default)";
|
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, "-- %s", str);
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
// same as CMK
|
// same as CMK
|
||||||
str = (resp.d.asBytes[3] & (1 << 3)) ? "YES" : "NO";
|
str = (resp.core.old.d.asBytes[3] & (1 << 3)) ? "YES" : "NO";
|
||||||
PrintAndLogEx(NORMAL, " 0x08 Configuration changeable : %s", str);
|
PrintAndLogEx(NORMAL, " 0x08 Configuration changeable : %s", str);
|
||||||
str = (resp.d.asBytes[3] & (1 << 2)) ? "NO" : "YES";
|
str = (resp.core.old.d.asBytes[3] & (1 << 2)) ? "NO" : "YES";
|
||||||
PrintAndLogEx(NORMAL, " 0x04 AMK required for create/delete : %s", str);
|
PrintAndLogEx(NORMAL, " 0x04 AMK required for create/delete : %s", str);
|
||||||
str = (resp.d.asBytes[3] & (1 << 1)) ? "NO" : "YES";
|
str = (resp.core.old.d.asBytes[3] & (1 << 1)) ? "NO" : "YES";
|
||||||
PrintAndLogEx(NORMAL, " 0x02 Directory list access with AMK : %s", str);
|
PrintAndLogEx(NORMAL, " 0x02 Directory list access with AMK : %s", str);
|
||||||
str = (resp.d.asBytes[3] & (1 << 0)) ? "YES" : "NO";
|
str = (resp.core.old.d.asBytes[3] & (1 << 0)) ? "YES" : "NO";
|
||||||
PrintAndLogEx(NORMAL, " 0x01 AMK is changeable : %s", str);
|
PrintAndLogEx(NORMAL, " 0x01 AMK is changeable : %s", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,15 +397,15 @@ void getKeySettings(uint8_t *aid) {
|
||||||
|
|
||||||
int numOfKeys;
|
int numOfKeys;
|
||||||
|
|
||||||
isOK = resp.arg[0] & 0xff;
|
isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (isOK == false) {
|
if (isOK == false) {
|
||||||
PrintAndLogEx(WARNING, " Can't read Application Master key version. Trying all keys");
|
PrintAndLogEx(WARNING, " Can't read Application Master key version. Trying all keys");
|
||||||
//numOfKeys = MAX_NUM_KEYS;
|
//numOfKeys = MAX_NUM_KEYS;
|
||||||
} else {
|
} else {
|
||||||
numOfKeys = resp.d.asBytes[4];
|
numOfKeys = resp.core.old.d.asBytes[4];
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(NORMAL, " Max number of keys : %d", numOfKeys);
|
PrintAndLogEx(NORMAL, " Max number of keys : %d", numOfKeys);
|
||||||
PrintAndLogEx(NORMAL, " Application Master key Version : %d (0x%02x)", resp.d.asBytes[3], resp.d.asBytes[3]);
|
PrintAndLogEx(NORMAL, " Application Master key Version : %d (0x%02x)", resp.core.old.d.asBytes[3], resp.core.old.d.asBytes[3]);
|
||||||
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
|
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,12 +431,12 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
|
||||||
c.d.asBytes[0] = GET_APPLICATION_IDS; //0x6a
|
c.d.asBytes[0] = GET_APPLICATION_IDS; //0x6a
|
||||||
|
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
isOK = resp.arg[0] & 0xff;
|
isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
PrintAndLogEx(NORMAL, "Command unsuccessful");
|
PrintAndLogEx(NORMAL, "Command unsuccessful");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -445,37 +445,37 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
|
||||||
PrintAndLogEx(NORMAL, "-- Desfire Enumerate Applications ---------------------------");
|
PrintAndLogEx(NORMAL, "-- Desfire Enumerate Applications ---------------------------");
|
||||||
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
|
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
|
||||||
|
|
||||||
UsbCommand respAid;
|
UsbReplyNG respAid;
|
||||||
UsbCommand respFiles;
|
UsbReplyNG respFiles;
|
||||||
|
|
||||||
uint8_t num = 0;
|
uint8_t num = 0;
|
||||||
int max = resp.arg[1] - 3 - 2;
|
int max = resp.core.old.arg[1] - 3 - 2;
|
||||||
|
|
||||||
for (int i = 3; i <= max; i += 3) {
|
for (int i = 3; i <= max; i += 3) {
|
||||||
PrintAndLogEx(NORMAL, " Aid %d : %02X %02X %02X ", num, resp.d.asBytes[i], resp.d.asBytes[i + 1], resp.d.asBytes[i + 2]);
|
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]);
|
||||||
num++;
|
num++;
|
||||||
|
|
||||||
aid[0] = resp.d.asBytes[i];
|
aid[0] = resp.core.old.d.asBytes[i];
|
||||||
aid[1] = resp.d.asBytes[i + 1];
|
aid[1] = resp.core.old.d.asBytes[i + 1];
|
||||||
aid[2] = resp.d.asBytes[i + 2];
|
aid[2] = resp.core.old.d.asBytes[i + 2];
|
||||||
getKeySettings(aid);
|
getKeySettings(aid);
|
||||||
|
|
||||||
// Select Application
|
// Select Application
|
||||||
c.arg[CMDPOS] = INIT;
|
c.arg[CMDPOS] = INIT;
|
||||||
c.arg[LENPOS] = 0x04;
|
c.arg[LENPOS] = 0x04;
|
||||||
c.d.asBytes[0] = SELECT_APPLICATION; // 0x5a
|
c.d.asBytes[0] = SELECT_APPLICATION; // 0x5a
|
||||||
c.d.asBytes[1] = resp.d.asBytes[i];
|
c.d.asBytes[1] = resp.core.old.d.asBytes[i];
|
||||||
c.d.asBytes[2] = resp.d.asBytes[i + 1];
|
c.d.asBytes[2] = resp.core.old.d.asBytes[i + 1];
|
||||||
c.d.asBytes[3] = resp.d.asBytes[i + 2];
|
c.d.asBytes[3] = resp.core.old.d.asBytes[i + 2];
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &respAid, 1500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &respAid, 1500)) {
|
||||||
PrintAndLogEx(WARNING, " Timed-out");
|
PrintAndLogEx(WARNING, " Timed-out");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
isOK = respAid.d.asBytes[2] & 0xff;
|
isOK = respAid.core.old.d.asBytes[2] & 0xff;
|
||||||
if (isOK != 0x00) {
|
if (isOK != 0x00) {
|
||||||
PrintAndLogEx(WARNING, " Can't select AID: %s", sprint_hex(resp.d.asBytes + i, 3));
|
PrintAndLogEx(WARNING, " Can't select AID: %s", sprint_hex(resp.core.old.d.asBytes + i, 3));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -489,13 +489,13 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
|
||||||
PrintAndLogEx(WARNING, " Timed-out");
|
PrintAndLogEx(WARNING, " Timed-out");
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
isOK = respFiles.d.asBytes[2] & 0xff;
|
isOK = respFiles.core.old.d.asBytes[2] & 0xff;
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
PrintAndLogEx(WARNING, " Can't get file ids ");
|
PrintAndLogEx(WARNING, " Can't get file ids ");
|
||||||
} else {
|
} else {
|
||||||
int respfileLen = resp.arg[1] - 3 - 2;
|
int respfileLen = resp.core.old.arg[1] - 3 - 2;
|
||||||
for (int j = 0; j < respfileLen; ++j) {
|
for (int j = 0; j < respfileLen; ++j) {
|
||||||
PrintAndLogEx(NORMAL, " Fileid %d :", resp.d.asBytes[j + 3]);
|
PrintAndLogEx(NORMAL, " Fileid %d :", resp.core.old.d.asBytes[j + 3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -510,13 +510,13 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
|
||||||
PrintAndLogEx(WARNING, " Timed-out");
|
PrintAndLogEx(WARNING, " Timed-out");
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
isOK = respFiles.d.asBytes[2] & 0xff;
|
isOK = respFiles.core.old.d.asBytes[2] & 0xff;
|
||||||
if (!isOK) {
|
if (!isOK) {
|
||||||
PrintAndLogEx(WARNING, " Can't get ISO file ids ");
|
PrintAndLogEx(WARNING, " Can't get ISO file ids ");
|
||||||
} else {
|
} else {
|
||||||
int respfileLen = resp.arg[1] - 3 - 2;
|
int respfileLen = resp.core.old.arg[1] - 3 - 2;
|
||||||
for (int j = 0; j < respfileLen; ++j) {
|
for (int j = 0; j < respfileLen; ++j) {
|
||||||
PrintAndLogEx(NORMAL, " ISO Fileid %d :", resp.d.asBytes[j + 3]);
|
PrintAndLogEx(NORMAL, " ISO Fileid %d :", resp.core.old.d.asBytes[j + 3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -617,16 +617,16 @@ static int CmdHF14ADesAuth(const char *Cmd) {
|
||||||
memcpy(c.d.asBytes + 1, key, keylength);
|
memcpy(c.d.asBytes + 1, key, keylength);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 3000)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 3000)) {
|
||||||
PrintAndLogEx(WARNING, "Client command execute timeout");
|
PrintAndLogEx(WARNING, "Client command execute timeout");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (isOK) {
|
if (isOK) {
|
||||||
uint8_t *data = resp.d.asBytes;
|
uint8_t *data = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, " Key :%s", sprint_hex(key, keylength));
|
PrintAndLogEx(NORMAL, " Key :%s", sprint_hex(key, keylength));
|
||||||
PrintAndLogEx(NORMAL, " SESSION :%s", sprint_hex(data, keylength));
|
PrintAndLogEx(NORMAL, " SESSION :%s", sprint_hex(data, keylength));
|
||||||
|
|
|
@ -60,11 +60,11 @@ static int CmdHF14AMfDESAuth(const char *Cmd) {
|
||||||
//Auth1
|
//Auth1
|
||||||
UsbCommand c = {CMD_MIFARE_DES_AUTH1, {blockNo}};
|
UsbCommand c = {CMD_MIFARE_DES_AUTH1, {blockNo}};
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
cuid = resp.arg[1];
|
cuid = resp.core.old.arg[1];
|
||||||
uint8_t *data = resp.d.asBytes;
|
uint8_t *data = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
if (isOK) {
|
if (isOK) {
|
||||||
PrintAndLogEx(NORMAL, "enc(nc)/b0:%s", sprint_hex(data + 2, 8));
|
PrintAndLogEx(NORMAL, "enc(nc)/b0:%s", sprint_hex(data + 2, 8));
|
||||||
|
@ -100,7 +100,7 @@ static int CmdHF14AMfDESAuth(const char *Cmd) {
|
||||||
memcpy(d.d.asBytes, reply, 16);
|
memcpy(d.d.asBytes, reply, 16);
|
||||||
SendCommand(&d);
|
SendCommand(&d);
|
||||||
|
|
||||||
UsbCommand respb;
|
UsbReplyNG 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;
|
||||||
|
@ -160,11 +160,11 @@ static int CmdHF14AMfAESAuth(const char *Cmd) {
|
||||||
//Auth1
|
//Auth1
|
||||||
UsbCommand c = {CMD_MIFARE_DES_AUTH1, {blockNo}};
|
UsbCommand c = {CMD_MIFARE_DES_AUTH1, {blockNo}};
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
cuid = resp.arg[1];
|
cuid = resp.core.old.arg[1];
|
||||||
uint8_t *data = resp.d.asBytes;
|
uint8_t *data = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
if (isOK) {
|
if (isOK) {
|
||||||
PrintAndLogEx(NORMAL, "enc(nc)/b0:%s", sprint_hex(data + 2, 16));
|
PrintAndLogEx(NORMAL, "enc(nc)/b0:%s", sprint_hex(data + 2, 16));
|
||||||
|
@ -207,7 +207,7 @@ static int CmdHF14AMfAESAuth(const char *Cmd) {
|
||||||
memcpy(d.d.asBytes, reply, 32);
|
memcpy(d.d.asBytes, reply, 32);
|
||||||
SendCommand(&d);
|
SendCommand(&d);
|
||||||
|
|
||||||
UsbCommand respb;
|
UsbReplyNG 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;
|
||||||
|
|
|
@ -1372,7 +1372,7 @@ static int acquire_nonces(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_
|
||||||
bool reported_suma8 = false;
|
bool reported_suma8 = false;
|
||||||
char progress_text[80];
|
char progress_text[80];
|
||||||
FILE *fnonces = NULL;
|
FILE *fnonces = NULL;
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
num_acquired_nonces = 0;
|
num_acquired_nonces = 0;
|
||||||
|
|
||||||
|
@ -1399,9 +1399,9 @@ static int acquire_nonces(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_
|
||||||
SendCommand(&c1);
|
SendCommand(&c1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (resp.arg[0]) return resp.arg[0]; // error during nested_hard
|
if (resp.core.old.arg[0]) return resp.core.old.arg[0]; // error during nested_hard
|
||||||
|
|
||||||
cuid = resp.arg[1];
|
cuid = resp.core.old.arg[1];
|
||||||
if (nonce_file_write && fnonces == NULL) {
|
if (nonce_file_write && fnonces == NULL) {
|
||||||
if ((fnonces = fopen(filename, "wb")) == NULL) {
|
if ((fnonces = fopen(filename, "wb")) == NULL) {
|
||||||
PrintAndLogEx(WARNING, "Could not create file %s", filename);
|
PrintAndLogEx(WARNING, "Could not create file %s", filename);
|
||||||
|
@ -1420,8 +1420,8 @@ static int acquire_nonces(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_
|
||||||
if (!initialize) {
|
if (!initialize) {
|
||||||
uint32_t nt_enc1, nt_enc2;
|
uint32_t nt_enc1, nt_enc2;
|
||||||
uint8_t par_enc;
|
uint8_t par_enc;
|
||||||
uint16_t num_sampled_nonces = resp.arg[2];
|
uint16_t num_sampled_nonces = resp.core.old.arg[2];
|
||||||
uint8_t *bufp = resp.d.asBytes;
|
uint8_t *bufp = resp.core.old.d.asBytes;
|
||||||
for (uint16_t i = 0; i < num_sampled_nonces; i += 2) {
|
for (uint16_t i = 0; i < num_sampled_nonces; i += 2) {
|
||||||
nt_enc1 = bytes_to_num(bufp, 4);
|
nt_enc1 = bytes_to_num(bufp, 4);
|
||||||
nt_enc2 = bytes_to_num(bufp + 4, 4);
|
nt_enc2 = bytes_to_num(bufp + 4, 4);
|
||||||
|
@ -1479,11 +1479,11 @@ static int acquire_nonces(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (resp.arg[0]) {
|
if (resp.core.old.arg[0]) {
|
||||||
if (nonce_file_write) {
|
if (nonce_file_write) {
|
||||||
fclose(fnonces);
|
fclose(fnonces);
|
||||||
}
|
}
|
||||||
return resp.arg[0]; // error during nested_hard
|
return resp.core.old.arg[0]; // error during nested_hard
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,13 +45,13 @@ static int CmdHFMFPInfo(const char *cmd) {
|
||||||
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}, {{0}}};
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
WaitForResponse(CMD_ACK, &resp);
|
WaitForResponse(CMD_ACK, &resp);
|
||||||
|
|
||||||
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.core.old.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
|
uint64_t select_status = resp.core.old.arg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
||||||
|
|
||||||
if (select_status == 1 || select_status == 2) {
|
if (select_status == 1 || select_status == 2) {
|
||||||
PrintAndLogEx(NORMAL, "----------------------------------------------");
|
PrintAndLogEx(NORMAL, "----------------------------------------------");
|
||||||
|
|
|
@ -468,12 +468,12 @@ static int ul_send_cmd_raw(uint8_t *cmd, uint8_t cmdlen, uint8_t *response, uint
|
||||||
memcpy(c.d.asBytes, cmd, cmdlen);
|
memcpy(c.d.asBytes, cmd, cmdlen);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return -1;
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return -1;
|
||||||
if (!resp.arg[0] && responseLength) return -1;
|
if (!resp.core.old.arg[0] && responseLength) return -1;
|
||||||
|
|
||||||
uint16_t resplen = (resp.arg[0] < responseLength) ? resp.arg[0] : responseLength;
|
uint16_t resplen = (resp.core.old.arg[0] < responseLength) ? resp.core.old.arg[0] : responseLength;
|
||||||
memcpy(response, resp.d.asBytes, resplen);
|
memcpy(response, resp.core.old.d.asBytes, resplen);
|
||||||
return resplen;
|
return resplen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,17 +481,17 @@ static int ul_select(iso14a_card_select_t *card) {
|
||||||
|
|
||||||
ul_switch_on_field();
|
ul_switch_on_field();
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
bool ans = false;
|
bool ans = false;
|
||||||
ans = WaitForResponseTimeout(CMD_ACK, &resp, 1500);
|
ans = WaitForResponseTimeout(CMD_ACK, &resp, 1500);
|
||||||
|
|
||||||
if (!ans || resp.arg[0] < 1) {
|
if (!ans || resp.core.old.arg[0] < 1) {
|
||||||
PrintAndLogEx(WARNING, "iso14443a card select failed");
|
PrintAndLogEx(WARNING, "iso14443a card select failed");
|
||||||
DropField();
|
DropField();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(card, resp.d.asBytes, sizeof(iso14a_card_select_t));
|
memcpy(card, resp.core.old.d.asBytes, sizeof(iso14a_card_select_t));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,9 +537,9 @@ static int ulc_authentication(uint8_t *key, bool switch_off_field) {
|
||||||
memcpy(c.d.asBytes, key, 16);
|
memcpy(c.d.asBytes, key, 16);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return 0;
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return 0;
|
||||||
if (resp.arg[0] == 1) return 1;
|
if (resp.core.old.arg[0] == 1) return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -627,11 +627,11 @@ static int ul_fudan_check(void) {
|
||||||
memcpy(c.d.asBytes, cmd, 4);
|
memcpy(c.d.asBytes, cmd, 4);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return UL_ERROR;
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return UL_ERROR;
|
||||||
if (resp.arg[0] != 1) return UL_ERROR;
|
if (resp.core.old.arg[0] != 1) return UL_ERROR;
|
||||||
|
|
||||||
return (!resp.d.asBytes[0]) ? FUDAN_UL : UL; //if response == 0x00 then Fudan, else Genuine NXP
|
return (!resp.core.old.d.asBytes[0]) ? FUDAN_UL : UL; //if response == 0x00 then Fudan, else Genuine NXP
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ul_print_default(uint8_t *data) {
|
static int ul_print_default(uint8_t *data) {
|
||||||
|
@ -1488,9 +1488,9 @@ static int CmdHF14AMfUWrBl(const char *Cmd) {
|
||||||
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
PrintAndLogEx(SUCCESS, "isOk:%02x", isOK);
|
PrintAndLogEx(SUCCESS, "isOk:%02x", isOK);
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(WARNING, "Command execute timeout");
|
PrintAndLogEx(WARNING, "Command execute timeout");
|
||||||
|
@ -1592,11 +1592,11 @@ static int CmdHF14AMfURdBl(const char *Cmd) {
|
||||||
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (isOK) {
|
if (isOK) {
|
||||||
uint8_t *d = resp.d.asBytes;
|
uint8_t *d = resp.core.old.d.asBytes;
|
||||||
PrintAndLogEx(NORMAL, "\nBlock# | Data | Ascii");
|
PrintAndLogEx(NORMAL, "\nBlock# | Data | Ascii");
|
||||||
PrintAndLogEx(NORMAL, "-----------------------------");
|
PrintAndLogEx(NORMAL, "-----------------------------");
|
||||||
PrintAndLogEx(NORMAL, "%02d/0x%02X | %s| %s\n", blockNo, blockNo, sprint_hex(d, 4), sprint_ascii(d, 4));
|
PrintAndLogEx(NORMAL, "%02d/0x%02X | %s| %s\n", blockNo, blockNo, sprint_hex(d, 4), sprint_ascii(d, 4));
|
||||||
|
@ -1858,19 +1858,19 @@ static int CmdHF14AMfUDump(const char *Cmd) {
|
||||||
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
PrintAndLogEx(WARNING, "Command execute time-out");
|
PrintAndLogEx(WARNING, "Command execute time-out");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.arg[0] != 1) {
|
if (resp.core.old.arg[0] != 1) {
|
||||||
PrintAndLogEx(WARNING, "Failed dumping card");
|
PrintAndLogEx(WARNING, "Failed dumping card");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t startindex = resp.arg[2];
|
uint32_t startindex = resp.core.old.arg[2];
|
||||||
uint32_t bufferSize = resp.arg[1];
|
uint32_t bufferSize = resp.core.old.arg[1];
|
||||||
if (bufferSize > sizeof(data)) {
|
if (bufferSize > sizeof(data)) {
|
||||||
PrintAndLogEx(FAILED, "Data exceeded Buffer size!");
|
PrintAndLogEx(FAILED, "Data exceeded Buffer size!");
|
||||||
bufferSize = sizeof(data);
|
bufferSize = sizeof(data);
|
||||||
|
@ -1982,9 +1982,9 @@ static int CmdHF14AMfUDump(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wait4response(uint8_t b) {
|
static void wait4response(uint8_t b) {
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (!isOK)
|
if (!isOK)
|
||||||
PrintAndLogEx(WARNING, "failed to write block %d", b);
|
PrintAndLogEx(WARNING, "failed to write block %d", b);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2392,12 +2392,12 @@ static int CmdHF14AMfUCSetPwd(const char *Cmd) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
if ((resp.arg[0] & 0xff) == 1) {
|
if ((resp.core.old.arg[0] & 0xff) == 1) {
|
||||||
PrintAndLogEx(INFO, "Ultralight-C new password: %s", sprint_hex(pwd, 16));
|
PrintAndLogEx(INFO, "Ultralight-C new password: %s", sprint_hex(pwd, 16));
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(WARNING, "Failed writing at block %d", resp.arg[1] & 0xff);
|
PrintAndLogEx(WARNING, "Failed writing at block %d", resp.core.old.arg[1] & 0xff);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -2413,7 +2413,7 @@ static int CmdHF14AMfUCSetPwd(const char *Cmd) {
|
||||||
static int CmdHF14AMfUCSetUid(const char *Cmd) {
|
static int CmdHF14AMfUCSetUid(const char *Cmd) {
|
||||||
|
|
||||||
UsbCommand c = {CMD_MIFAREU_READBL, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_MIFAREU_READBL, {0, 0, 0}, {{0}}};
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
uint8_t uid[7] = {0x00};
|
uint8_t uid[7] = {0x00};
|
||||||
char cmdp = tolower(param_getchar(Cmd, 0));
|
char cmdp = tolower(param_getchar(Cmd, 0));
|
||||||
|
|
||||||
|
@ -2435,7 +2435,7 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) {
|
||||||
|
|
||||||
// save old block2.
|
// save old block2.
|
||||||
uint8_t oldblock2[4] = {0x00};
|
uint8_t oldblock2[4] = {0x00};
|
||||||
memcpy(resp.d.asBytes, oldblock2, 4);
|
memcpy(resp.core.old.d.asBytes, oldblock2, 4);
|
||||||
|
|
||||||
// block 0.
|
// block 0.
|
||||||
c.cmd = CMD_MIFAREU_WRITEBL;
|
c.cmd = CMD_MIFAREU_WRITEBL;
|
||||||
|
@ -2490,12 +2490,12 @@ static int CmdHF14AMfUGenDiverseKeys(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_RATS, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_RATS, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
WaitForResponse(CMD_ACK, &resp);
|
WaitForResponse(CMD_ACK, &resp);
|
||||||
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.core.old.d.asBytes, sizeof(iso14a_card_select_t));
|
||||||
|
|
||||||
uint64_t select_status = resp.arg[0];
|
uint64_t select_status = resp.core.old.arg[0];
|
||||||
// 0: couldn't read,
|
// 0: couldn't read,
|
||||||
// 1: OK, with ATS
|
// 1: OK, with ATS
|
||||||
// 2: OK, no ATS
|
// 2: OK, no ATS
|
||||||
|
@ -2605,12 +2605,12 @@ static int CmdHF14AMfUPwdGen(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_RATS, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_RATS, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
WaitForResponse(CMD_ACK, &resp);
|
WaitForResponse(CMD_ACK, &resp);
|
||||||
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.core.old.d.asBytes, sizeof(iso14a_card_select_t));
|
||||||
|
|
||||||
uint64_t select_status = resp.arg[0];
|
uint64_t select_status = resp.core.old.arg[0];
|
||||||
// 0: couldn't read
|
// 0: couldn't read
|
||||||
// 1: OK with ATS
|
// 1: OK with ATS
|
||||||
// 2: OK, no ATS
|
// 2: OK, no ATS
|
||||||
|
|
|
@ -46,14 +46,14 @@ static int topaz_send_cmd_raw(uint8_t *cmd, uint8_t len, uint8_t *response) {
|
||||||
memcpy(c.d.asBytes, cmd, len);
|
memcpy(c.d.asBytes, cmd, len);
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
WaitForResponse(CMD_ACK, &resp);
|
WaitForResponse(CMD_ACK, &resp);
|
||||||
|
|
||||||
if (resp.arg[0] > 0) {
|
if (resp.core.old.arg[0] > 0) {
|
||||||
memcpy(response, resp.d.asBytes, resp.arg[0]);
|
memcpy(response, resp.core.old.d.asBytes, resp.core.old.arg[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp.arg[0];
|
return resp.core.old.arg[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -418,9 +418,10 @@ static int CmdVersion(const char *Cmd) {
|
||||||
static int CmdStatus(const char *Cmd) {
|
static int CmdStatus(const char *Cmd) {
|
||||||
(void)Cmd; // Cmd is not used so far
|
(void)Cmd; // Cmd is not used so far
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_STATUS, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_STATUS, {0, 0, 0}, {{0}}};
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &c, 1900))
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1900))
|
||||||
PrintAndLogEx(NORMAL, "Status command failed. USB Speed Test timed out");
|
PrintAndLogEx(NORMAL, "Status command failed. USB Speed Test timed out");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -428,7 +429,7 @@ static int CmdStatus(const char *Cmd) {
|
||||||
static int CmdPing(const char *Cmd) {
|
static int CmdPing(const char *Cmd) {
|
||||||
(void)Cmd; // Cmd is not used so far
|
(void)Cmd; // Cmd is not used so far
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_PING, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_PING, {0, 0, 0}, {{0}}};
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1000))
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1000))
|
||||||
|
@ -442,25 +443,21 @@ static int CmdPingNG(const char *Cmd) {
|
||||||
uint32_t len = strtol(Cmd, NULL, 0);
|
uint32_t len = strtol(Cmd, NULL, 0);
|
||||||
if (len > USB_DATANG_SIZE)
|
if (len > USB_DATANG_SIZE)
|
||||||
len = USB_DATANG_SIZE;
|
len = USB_DATANG_SIZE;
|
||||||
PrintAndLogEx(NORMAL, "Pinging with payload len=%d", len);
|
PrintAndLogEx(NORMAL, "PingNG sent with payload len=%d", len);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
uint8_t resp[USB_REPLYNG_MAXLEN];
|
UsbReplyNG resp;
|
||||||
uint8_t data[USB_DATANG_SIZE] = {0};
|
uint8_t data[USB_DATANG_SIZE] = {0};
|
||||||
uint16_t cmd = CMD_PING;
|
uint16_t cmd = CMD_PING;
|
||||||
if (len)
|
|
||||||
for (uint16_t i=0; i<len; i++)
|
for (uint16_t i=0; i<len; i++)
|
||||||
data[i] = i & 0xFF;
|
data[i] = i & 0xFF;
|
||||||
SendCommandNG(cmd, data, len);
|
SendCommandNG(cmd, data, len);
|
||||||
if (WaitForResponseNGTimeout(CMD_PING, resp, 1000)) {
|
if (WaitForResponseTimeout(CMD_PING, &resp, 1000)) {
|
||||||
PrintAndLogEx(NORMAL, "PingNG successful");
|
bool error = false;
|
||||||
UsbReplyNGPreamble *pre = (UsbReplyNGPreamble *)resp;
|
if (len)
|
||||||
uint8_t *respdata = resp + sizeof(UsbReplyNGPreamble);
|
error = memcmp(data, resp.core.ng.data, len) != 0;
|
||||||
if (len >= 4)
|
PrintAndLogEx(NORMAL, "PingNG response received, content is %s", error ? _RED_("NOT ok") : _GREEN_("ok"));
|
||||||
PrintAndLogEx(NORMAL, "%02x%02x%02x%02x ... %02x%02x%02x%02x",
|
|
||||||
respdata[0], respdata[1], respdata[2], respdata[3],
|
|
||||||
respdata[pre->length-4], respdata[pre->length-3], respdata[pre->length-2], respdata[pre->length-1]);
|
|
||||||
} else
|
} else
|
||||||
PrintAndLogEx(NORMAL, "PingNG failed");
|
PrintAndLogEx(NORMAL, "PingNG response " _RED_("timeout"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,7 +497,7 @@ void pm3_version(bool verbose) {
|
||||||
if (!verbose)
|
if (!verbose)
|
||||||
return;
|
return;
|
||||||
UsbCommand c = {CMD_VERSION, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_VERSION, {0, 0, 0}, {{0}}};
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {
|
||||||
|
@ -529,8 +526,8 @@ void pm3_version(bool verbose) {
|
||||||
PrintAndLogEx(NORMAL, "\n [ CLIENT ]");
|
PrintAndLogEx(NORMAL, "\n [ CLIENT ]");
|
||||||
PrintAndLogEx(NORMAL, " client: iceman %s \n", s);
|
PrintAndLogEx(NORMAL, " client: iceman %s \n", s);
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, (char *)resp.d.asBytes);
|
PrintAndLogEx(NORMAL, (char *)resp.core.old.d.asBytes);
|
||||||
lookupChipID(resp.arg[0], resp.arg[1]);
|
lookupChipID(resp.core.old.arg[0], resp.core.old.arg[1]);
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "\n");
|
PrintAndLogEx(NORMAL, "\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -335,7 +335,7 @@ bool lf_read(bool silent, uint32_t samples) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (g_lf_threshold_set) {
|
if (g_lf_threshold_set) {
|
||||||
WaitForResponse(CMD_ACK, &resp);
|
WaitForResponse(CMD_ACK, &resp);
|
||||||
} else {
|
} else {
|
||||||
|
@ -344,8 +344,8 @@ bool lf_read(bool silent, uint32_t samples) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// resp.arg[0] is bits read not bytes read.
|
// resp.core.old.arg[0] is bits read not bytes read.
|
||||||
getSamples(resp.arg[0] / 8, silent);
|
getSamples(resp.core.old.arg[0] / 8, silent);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ static bool sendPing(void) {
|
||||||
SendCommand(&ping);
|
SendCommand(&ping);
|
||||||
SendCommand(&ping);
|
SendCommand(&ping);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000))
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
|
@ -392,7 +392,7 @@ static int CmdAWIDClone(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, "Preparing to clone AWID %u to T55x7 with FC: %u, CN: %u", fmtlen, fc, cn);
|
PrintAndLogEx(INFO, "Preparing to clone AWID %u to T55x7 with FC: %u, CN: %u", fmtlen, fc, cn);
|
||||||
print_blocks(blocks, 4);
|
print_blocks(blocks, 4);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 4; i++) {
|
for (uint8_t i = 0; i < 4; i++) {
|
||||||
|
|
|
@ -1132,7 +1132,7 @@ static int EM4x05ReadWord_ext(uint8_t addr, uint32_t pwd, bool usePwd, uint32_t
|
||||||
UsbCommand c = {CMD_EM4X_READ_WORD, {addr, pwd, usePwd}, {{0}}};
|
UsbCommand c = {CMD_EM4X_READ_WORD, {addr, pwd, usePwd}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
PrintAndLogEx(DEBUG, "timeout while waiting for reply.");
|
PrintAndLogEx(DEBUG, "timeout while waiting for reply.");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1235,7 +1235,7 @@ static int CmdEM4x05Write(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_EM4X_WRITE_WORD, {flag, data, pwd}, {{0}}};
|
UsbCommand c = {CMD_EM4X_WRITE_WORD, {flag, data, pwd}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
|
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -281,7 +281,7 @@ static int CmdFdxClone(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, "Preparing to clone FDX-B to T55x7 with animal ID: %04u-%"PRIu64, countryid, animalid);
|
PrintAndLogEx(INFO, "Preparing to clone FDX-B to T55x7 with animal ID: %04u-%"PRIu64, countryid, animalid);
|
||||||
print_blocks(blocks, 5);
|
print_blocks(blocks, 5);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
||||||
|
|
||||||
for (int i = 4; i >= 0; --i) {
|
for (int i = 4; i >= 0; --i) {
|
||||||
|
|
|
@ -171,7 +171,7 @@ static int CmdGuardClone(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, "Preparing to clone Guardall to T55x7 with Facility Code: %u, Card Number: %u", facilitycode, cardnumber);
|
PrintAndLogEx(INFO, "Preparing to clone Guardall to T55x7 with Facility Code: %u, Card Number: %u", facilitycode, cardnumber);
|
||||||
print_blocks(blocks, 4);
|
print_blocks(blocks, 4);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
||||||
|
|
||||||
for (i = 0; i < 4; ++i) {
|
for (i = 0; i < 4; ++i) {
|
||||||
|
|
|
@ -98,7 +98,7 @@ static bool sendPing(void) {
|
||||||
SendCommand(&ping);
|
SendCommand(&ping);
|
||||||
SendCommand(&ping);
|
SendCommand(&ping);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000))
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -135,7 +135,7 @@ static int CmdLFHitagList(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query for the actual size of the trace
|
// Query for the actual size of the trace
|
||||||
UsbCommand response;
|
UsbReplyNG response;
|
||||||
if (!GetFromDevice(BIG_BUF, got, USB_CMD_DATA_SIZE, 0, &response, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF, got, USB_CMD_DATA_SIZE, 0, &response, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "command execution time out");
|
PrintAndLogEx(WARNING, "command execution time out");
|
||||||
free(got);
|
free(got);
|
||||||
|
@ -461,19 +461,19 @@ static bool getHitagUid(uint32_t *uid) {
|
||||||
UsbCommand c = {CMD_READER_HITAG, {RHT2F_UID_ONLY, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_READER_HITAG, {RHT2F_UID_ONLY, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.arg[0] == false) {
|
if (resp.core.old.arg[0] == false) {
|
||||||
PrintAndLogEx(DEBUG, "DEBUG: Error - failed getting UID");
|
PrintAndLogEx(DEBUG, "DEBUG: Error - failed getting UID");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uid)
|
if (uid)
|
||||||
*uid = bytes_to_num(resp.d.asBytes, 4);
|
*uid = bytes_to_num(resp.core.old.d.asBytes, 4);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -559,24 +559,24 @@ static int CmdLFHitagReader(const char *Cmd) {
|
||||||
c.arg[0] = htf;
|
c.arg[0] = htf;
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 4000)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 4000)) {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.arg[0] == false) {
|
if (resp.core.old.arg[0] == false) {
|
||||||
PrintAndLogEx(DEBUG, "DEBUG: Error - hitag failed");
|
PrintAndLogEx(DEBUG, "DEBUG: Error - hitag failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t id = bytes_to_num(resp.d.asBytes, 4);
|
uint32_t id = bytes_to_num(resp.core.old.d.asBytes, 4);
|
||||||
|
|
||||||
PrintAndLogEx(SUCCESS, "Valid Hitag2 tag found - UID: %08x", id);
|
PrintAndLogEx(SUCCESS, "Valid Hitag2 tag found - UID: %08x", id);
|
||||||
if (htf != RHT2F_UID_ONLY) {
|
if (htf != RHT2F_UID_ONLY) {
|
||||||
|
|
||||||
PrintAndLogEx(SUCCESS, "Dumping tag memory...");
|
PrintAndLogEx(SUCCESS, "Dumping tag memory...");
|
||||||
uint8_t *data = resp.d.asBytes;
|
uint8_t *data = resp.core.old.d.asBytes;
|
||||||
|
|
||||||
char filename[FILE_PATH_SIZE];
|
char filename[FILE_PATH_SIZE];
|
||||||
char *fnameptr = filename;
|
char *fnameptr = filename;
|
||||||
|
@ -676,13 +676,13 @@ static int CmdLFHitagWriter(const char *Cmd) {
|
||||||
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 4000)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 4000)) {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.arg[0] == false) {
|
if (resp.core.old.arg[0] == false) {
|
||||||
PrintAndLogEx(DEBUG, "DEBUG: Error - hitag write failed");
|
PrintAndLogEx(DEBUG, "DEBUG: Error - hitag write failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ static int CmdJablotronClone(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, "Preparing to clone Jablotron to T55x7 with FullCode: %"PRIx64, fullcode);
|
PrintAndLogEx(INFO, "Preparing to clone Jablotron to T55x7 with FullCode: %"PRIx64, fullcode);
|
||||||
print_blocks(blocks, 3);
|
print_blocks(blocks, 3);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 3; i++) {
|
for (uint8_t i = 0; i < 3; i++) {
|
||||||
|
|
|
@ -146,7 +146,7 @@ static int CmdKeriClone(const char *Cmd) {
|
||||||
print_blocks(blocks, 3);
|
print_blocks(blocks, 3);
|
||||||
|
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -202,7 +202,7 @@ static int CmdLFNedapClone(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, "Preparing to clone NEDAP to T55x7 with card number: %u", cardnumber);
|
PrintAndLogEx(INFO, "Preparing to clone NEDAP to T55x7 with card number: %u", cardnumber);
|
||||||
print_blocks(blocks, 5);
|
print_blocks(blocks, 5);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}, {{0}}};
|
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}, {{0}}};
|
||||||
|
|
||||||
for (uint8_t i = 0; i<5; ++i ) {
|
for (uint8_t i = 0; i<5; ++i ) {
|
||||||
|
|
|
@ -154,7 +154,7 @@ static int CmdNoralsyClone(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, "Preparing to clone Noralsy to T55x7 with CardId: %u", id);
|
PrintAndLogEx(INFO, "Preparing to clone Noralsy to T55x7 with CardId: %u", id);
|
||||||
print_blocks(blocks, 4);
|
print_blocks(blocks, 4);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 4; i++) {
|
for (uint8_t i = 0; i < 4; i++) {
|
||||||
|
|
|
@ -99,7 +99,7 @@ static int CmdLFPCF7931Read(const char *Cmd) {
|
||||||
uint8_t ctmp = param_getchar(Cmd, 0);
|
uint8_t ctmp = param_getchar(Cmd, 0);
|
||||||
if (ctmp == 'H' || ctmp == 'h') return usage_pcf7931_read();
|
if (ctmp == 'H' || ctmp == 'h') return usage_pcf7931_read();
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_PCF7931_READ, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_PCF7931_READ, {0, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
|
@ -120,7 +120,7 @@ static int CmdPrescoClone(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, "Preparing to clone Presco to T55x7 with SiteCode: %u, UserCode: %u, FullCode: %08x", sitecode, usercode, fullcode);
|
PrintAndLogEx(INFO, "Preparing to clone Presco to T55x7 with SiteCode: %u, UserCode: %u, FullCode: %08x", sitecode, usercode, fullcode);
|
||||||
print_blocks(blocks, 5);
|
print_blocks(blocks, 5);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 5; i++) {
|
for (uint8_t i = 0; i < 5; i++) {
|
||||||
|
|
|
@ -232,7 +232,7 @@ static int CmdPyramidClone(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, "Preparing to clone Farpointe/Pyramid to T55x7 with Facility Code: %u, Card Number: %u", facilitycode, cardnumber);
|
PrintAndLogEx(INFO, "Preparing to clone Farpointe/Pyramid to T55x7 with Facility Code: %u, Card Number: %u", facilitycode, cardnumber);
|
||||||
print_blocks(blocks, 5);
|
print_blocks(blocks, 5);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 5; ++i) {
|
for (uint8_t i = 0; i < 5; ++i) {
|
||||||
|
|
|
@ -1075,7 +1075,7 @@ static int CmdT55xxWriteBlock(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}, {{0}}};
|
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}, {{0}}};
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
c.d.asBytes[0] = (page1) ? 0x2 : 0;
|
c.d.asBytes[0] = (page1) ? 0x2 : 0;
|
||||||
c.d.asBytes[0] |= (testMode) ? 0x4 : 0;
|
c.d.asBytes[0] |= (testMode) ? 0x4 : 0;
|
||||||
|
|
||||||
|
@ -1859,7 +1859,7 @@ static int CmdT55xxChkPwds(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_T55XX_CHKPWDS, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_T55XX_CHKPWDS, {0, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
timeout++;
|
timeout++;
|
||||||
|
@ -1871,13 +1871,13 @@ static int CmdT55xxChkPwds(const char *Cmd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.arg[0]) {
|
if (resp.core.old.arg[0]) {
|
||||||
PrintAndLogEx(SUCCESS, "\nFound a candidate [ " _YELLOW_("%08X") " ]. Trying to validate", resp.arg[1]);
|
PrintAndLogEx(SUCCESS, "\nFound a candidate [ " _YELLOW_("%08X") " ]. Trying to validate", resp.core.old.arg[1]);
|
||||||
|
|
||||||
if (AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, true, resp.arg[1])) {
|
if (AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, true, resp.core.old.arg[1])) {
|
||||||
found = tryDetectModulation();
|
found = tryDetectModulation();
|
||||||
if (found) {
|
if (found) {
|
||||||
PrintAndLogEx(SUCCESS, "Found valid password: [ " _GREEN_("%08") " ]", resp.arg[1]);
|
PrintAndLogEx(SUCCESS, "Found valid password: [ " _GREEN_("%08") " ]", resp.core.old.arg[1]);
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(WARNING, "Check pwd failed");
|
PrintAndLogEx(WARNING, "Check pwd failed");
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ static int CmdVikingClone(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_VIKING_CLONE_TAG, {rawID >> 32, rawID & 0xFFFFFFFF, Q5}, {{0}}};
|
UsbCommand c = {CMD_VIKING_CLONE_TAG, {rawID >> 32, rawID & 0xFFFFFFFF, Q5}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
|
||||||
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
|
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -166,7 +166,7 @@ static int CmdVisa2kClone(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, "Preparing to clone Visa2000 to T55x7 with CardId: %u", id);
|
PrintAndLogEx(INFO, "Preparing to clone Visa2000 to T55x7 with CardId: %u", id);
|
||||||
print_blocks(blocks, 4);
|
print_blocks(blocks, 4);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0, 0, 0}, {{0}}};
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 4; i++) {
|
for (uint8_t i = 0; i < 4; i++) {
|
||||||
|
|
|
@ -309,18 +309,18 @@ static int PrintATR(uint8_t *atr, size_t atrlen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int smart_wait(uint8_t *data, bool silent) {
|
static int smart_wait(uint8_t *data, bool silent) {
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
if (!silent) PrintAndLogEx(WARNING, "smart card response timeout");
|
if (!silent) PrintAndLogEx(WARNING, "smart card response timeout");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t len = resp.arg[0];
|
uint32_t len = resp.core.old.arg[0];
|
||||||
if (!len) {
|
if (!len) {
|
||||||
if (!silent) PrintAndLogEx(WARNING, "smart card response failed");
|
if (!silent) PrintAndLogEx(WARNING, "smart card response failed");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
memcpy(data, resp.d.asBytes, len);
|
memcpy(data, resp.core.old.d.asBytes, len);
|
||||||
if (len >= 2) {
|
if (len >= 2) {
|
||||||
if (!silent) PrintAndLogEx(SUCCESS, "%02X%02X | %s", data[len - 2], data[len - 1], GetAPDUCodeDescription(data[len - 2], data[len - 1]));
|
if (!silent) PrintAndLogEx(SUCCESS, "%02X%02X | %s", data[len - 2], data[len - 1], GetAPDUCodeDescription(data[len - 2], data[len - 1]));
|
||||||
} else {
|
} else {
|
||||||
|
@ -678,12 +678,12 @@ static int CmdSmartUpgrade(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_SMART_UPGRADE, {firmware_size, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_SMART_UPGRADE, {firmware_size, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if ((resp.arg[0] & 0xFF)) {
|
if ((resp.core.old.arg[0] & 0xFF)) {
|
||||||
PrintAndLogEx(SUCCESS, "Sim module firmware upgrade " _GREEN_("successful"));
|
PrintAndLogEx(SUCCESS, "Sim module firmware upgrade " _GREEN_("successful"));
|
||||||
PrintAndLogEx(SUCCESS, "\n run " _YELLOW_("`hw status`") " to validate the fw version ");
|
PrintAndLogEx(SUCCESS, "\n run " _YELLOW_("`hw status`") " to validate the fw version ");
|
||||||
} else {
|
} else {
|
||||||
|
@ -717,20 +717,20 @@ static int CmdSmartInfo(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t isok = resp.arg[0] & 0xFF;
|
uint8_t isok = resp.core.old.arg[0] & 0xFF;
|
||||||
if (!isok) {
|
if (!isok) {
|
||||||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
smart_card_atr_t card;
|
smart_card_atr_t card;
|
||||||
memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t));
|
memcpy(&card, (smart_card_atr_t *)resp.core.old.d.asBytes, sizeof(smart_card_atr_t));
|
||||||
|
|
||||||
// print header
|
// print header
|
||||||
PrintAndLogEx(INFO, "--- Smartcard Information ---------");
|
PrintAndLogEx(INFO, "--- Smartcard Information ---------");
|
||||||
|
@ -792,19 +792,19 @@ static int CmdSmartReader(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t isok = resp.arg[0] & 0xFF;
|
uint8_t isok = resp.core.old.arg[0] & 0xFF;
|
||||||
if (!isok) {
|
if (!isok) {
|
||||||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
smart_card_atr_t card;
|
smart_card_atr_t card;
|
||||||
memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t));
|
memcpy(&card, (smart_card_atr_t *)resp.core.old.d.asBytes, sizeof(smart_card_atr_t));
|
||||||
|
|
||||||
PrintAndLogEx(INFO, "ISO7816-3 ATR : %s", sprint_hex(card.atr, card.atr_len));
|
PrintAndLogEx(INFO, "ISO7816-3 ATR : %s", sprint_hex(card.atr, card.atr_len));
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -838,13 +838,13 @@ static int CmdSmartSetClock(const char *Cmd) {
|
||||||
UsbCommand c = {CMD_SMART_SETCLOCK, {clock1, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_SMART_SETCLOCK, {clock1, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
PrintAndLogEx(WARNING, "smart card select failed");
|
PrintAndLogEx(WARNING, "smart card select failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t isok = resp.arg[0] & 0xFF;
|
uint8_t isok = resp.core.old.arg[0] & 0xFF;
|
||||||
if (!isok) {
|
if (!isok) {
|
||||||
PrintAndLogEx(WARNING, "smart card set clock failed");
|
PrintAndLogEx(WARNING, "smart card set clock failed");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1217,20 +1217,20 @@ bool smart_select(bool silent, smart_card_atr_t *atr) {
|
||||||
UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
|
||||||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t isok = resp.arg[0] & 0xFF;
|
uint8_t isok = resp.core.old.arg[0] & 0xFF;
|
||||||
if (!isok) {
|
if (!isok) {
|
||||||
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
smart_card_atr_t card;
|
smart_card_atr_t card;
|
||||||
memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t));
|
memcpy(&card, (smart_card_atr_t *)resp.core.old.d.asBytes, sizeof(smart_card_atr_t));
|
||||||
|
|
||||||
if (atr)
|
if (atr)
|
||||||
memcpy(atr, &card, sizeof(smart_card_atr_t));
|
memcpy(atr, &card, sizeof(smart_card_atr_t));
|
||||||
|
|
|
@ -672,13 +672,13 @@ int CmdTraceList(const char *Cmd) {
|
||||||
|
|
||||||
if (isOnline) {
|
if (isOnline) {
|
||||||
// Query for the size of the trace, downloading USB_CMD_DATA_SIZE
|
// Query for the size of the trace, downloading USB_CMD_DATA_SIZE
|
||||||
UsbCommand response;
|
UsbReplyNG response;
|
||||||
if (!GetFromDevice(BIG_BUF, trace, USB_CMD_DATA_SIZE, 0, &response, 4000, true)) {
|
if (!GetFromDevice(BIG_BUF, trace, USB_CMD_DATA_SIZE, 0, &response, 4000, true)) {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
traceLen = response.arg[2];
|
traceLen = response.core.old.arg[2];
|
||||||
if (traceLen > USB_CMD_DATA_SIZE) {
|
if (traceLen > USB_CMD_DATA_SIZE) {
|
||||||
uint8_t *p = realloc(trace, traceLen);
|
uint8_t *p = realloc(trace, traceLen);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
|
|
198
client/comms.c
198
client/comms.c
|
@ -26,7 +26,7 @@ static pthread_t USB_communication_thread;
|
||||||
|
|
||||||
// Transmit buffer.
|
// Transmit buffer.
|
||||||
static UsbCommand txBuffer;
|
static UsbCommand txBuffer;
|
||||||
static uint8_t txBufferNG[USB_COMMANDNG_MAXLEN];
|
static UsbCommandNG txBufferNG;
|
||||||
size_t txBufferNGLen;
|
size_t txBufferNGLen;
|
||||||
static bool txBuffer_pending = false;
|
static bool txBuffer_pending = false;
|
||||||
static pthread_mutex_t txBufferMutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t txBufferMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
@ -34,7 +34,7 @@ static pthread_cond_t txBufferSig = PTHREAD_COND_INITIALIZER;
|
||||||
|
|
||||||
// Used by UsbReceiveCommand as a ring buffer for messages that are yet to be
|
// Used by UsbReceiveCommand as a ring buffer for messages that are yet to be
|
||||||
// processed by a command handler (WaitForResponse{,Timeout})
|
// processed by a command handler (WaitForResponse{,Timeout})
|
||||||
static uint8_t rxBuffer[CMD_BUFFER_SIZE][USB_REPLYNG_MAXLEN];
|
static UsbReplyNG rxBuffer[CMD_BUFFER_SIZE];
|
||||||
|
|
||||||
// Points to the next empty position to write to
|
// Points to the next empty position to write to
|
||||||
static int cmd_head = 0;
|
static int cmd_head = 0;
|
||||||
|
@ -45,6 +45,8 @@ static int cmd_tail = 0;
|
||||||
// to lock rxBuffer operations from different threads
|
// to lock rxBuffer operations from different threads
|
||||||
static pthread_mutex_t rxBufferMutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t rxBufferMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
static bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbReplyNG *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd);
|
||||||
|
|
||||||
// These wrappers are required because it is not possible to access a static
|
// These wrappers are required because it is not possible to access a static
|
||||||
// global variable outside of the context of a single file.
|
// global variable outside of the context of a single file.
|
||||||
void SetOffline(bool value) {
|
void SetOffline(bool value) {
|
||||||
|
@ -102,8 +104,7 @@ void SendCommandNG(uint16_t cmd, uint8_t *data, size_t len) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UsbCommandNGPreamble *tx_pre = (UsbCommandNGPreamble *)txBufferNG;
|
UsbCommandNGPostamble *tx_post = (UsbCommandNGPostamble *)((uint8_t *)&txBufferNG + sizeof(UsbCommandNGPreamble) + sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + len);
|
||||||
UsbCommandNGPostamble *tx_post = (UsbCommandNGPostamble *)(txBufferNG + sizeof(UsbCommandNGPreamble) + len);
|
|
||||||
|
|
||||||
pthread_mutex_lock(&txBufferMutex);
|
pthread_mutex_lock(&txBufferMutex);
|
||||||
/**
|
/**
|
||||||
|
@ -115,14 +116,14 @@ void SendCommandNG(uint16_t cmd, uint8_t *data, size_t len) {
|
||||||
pthread_cond_wait(&txBufferSig, &txBufferMutex);
|
pthread_cond_wait(&txBufferSig, &txBufferMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
tx_pre->magic = USB_COMMANDNG_PREAMBLE_MAGIC;
|
txBufferNG.magic = USB_COMMANDNG_PREAMBLE_MAGIC;
|
||||||
tx_pre->length = len;
|
txBufferNG.length = len;
|
||||||
tx_pre->cmd = cmd;
|
txBufferNG.core.ng.cmd = cmd;
|
||||||
memcpy(txBufferNG + sizeof(UsbCommandNGPreamble), data, len);
|
memcpy(&txBufferNG.core.ng.data, data, len);
|
||||||
uint8_t first, second;
|
uint8_t first, second;
|
||||||
compute_crc(CRC_14443_A, txBufferNG, sizeof(UsbCommandNGPreamble) + len, &first, &second);
|
compute_crc(CRC_14443_A, (uint8_t *)&txBufferNG, sizeof(UsbCommandNGPreamble) + sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + len, &first, &second);
|
||||||
tx_post->crc = (first << 8) + second;
|
tx_post->crc = (first << 8) + second;
|
||||||
txBufferNGLen = sizeof(UsbCommandNGPreamble) + len + sizeof(UsbCommandNGPostamble);
|
txBufferNGLen = sizeof(UsbCommandNGPreamble) + sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + len + sizeof(UsbCommandNGPostamble);
|
||||||
txBuffer_pending = true;
|
txBuffer_pending = true;
|
||||||
|
|
||||||
// tell communication thread that a new command can be send
|
// tell communication thread that a new command can be send
|
||||||
|
@ -149,7 +150,7 @@ void clearCommandBuffer() {
|
||||||
* @brief storeCommand stores a USB command in a circular buffer
|
* @brief storeCommand stores a USB command in a circular buffer
|
||||||
* @param UC
|
* @param UC
|
||||||
*/
|
*/
|
||||||
static void storeReply(uint8_t *packet) {
|
static void storeReply(UsbReplyNG *packet) {
|
||||||
pthread_mutex_lock(&rxBufferMutex);
|
pthread_mutex_lock(&rxBufferMutex);
|
||||||
if ((cmd_head + 1) % CMD_BUFFER_SIZE == cmd_tail) {
|
if ((cmd_head + 1) % CMD_BUFFER_SIZE == cmd_tail) {
|
||||||
//If these two are equal, we're about to overwrite in the
|
//If these two are equal, we're about to overwrite in the
|
||||||
|
@ -158,8 +159,8 @@ static void storeReply(uint8_t *packet) {
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
//Store the command at the 'head' location
|
//Store the command at the 'head' location
|
||||||
uint8_t *destination = rxBuffer[cmd_head];
|
UsbReplyNG *destination = &rxBuffer[cmd_head];
|
||||||
memcpy(destination, packet, USB_REPLYNG_MAXLEN);
|
memcpy(destination, packet, sizeof(UsbReplyNG));
|
||||||
|
|
||||||
//increment head and wrap
|
//increment head and wrap
|
||||||
cmd_head = (cmd_head + 1) % CMD_BUFFER_SIZE;
|
cmd_head = (cmd_head + 1) % CMD_BUFFER_SIZE;
|
||||||
|
@ -170,7 +171,7 @@ static void storeReply(uint8_t *packet) {
|
||||||
* @param response location to write command
|
* @param response location to write command
|
||||||
* @return 1 if response was returned, 0 if nothing has been received
|
* @return 1 if response was returned, 0 if nothing has been received
|
||||||
*/
|
*/
|
||||||
static int getReply(uint8_t *response) {
|
static int getReply(UsbReplyNG *packet) {
|
||||||
pthread_mutex_lock(&rxBufferMutex);
|
pthread_mutex_lock(&rxBufferMutex);
|
||||||
//If head == tail, there's nothing to read, or if we just got initialized
|
//If head == tail, there's nothing to read, or if we just got initialized
|
||||||
if (cmd_head == cmd_tail) {
|
if (cmd_head == cmd_tail) {
|
||||||
|
@ -179,8 +180,7 @@ static int getReply(uint8_t *response) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Pick out the next unread command
|
//Pick out the next unread command
|
||||||
uint8_t *last_unread = rxBuffer[cmd_tail];
|
memcpy(packet, &rxBuffer[cmd_tail], sizeof(UsbReplyNG));
|
||||||
memcpy(response, last_unread, USB_REPLYNG_MAXLEN);
|
|
||||||
|
|
||||||
//Increment tail - this is a circular buffer, so modulo buffer size
|
//Increment tail - this is a circular buffer, so modulo buffer size
|
||||||
cmd_tail = (cmd_tail + 1) % CMD_BUFFER_SIZE;
|
cmd_tail = (cmd_tail + 1) % CMD_BUFFER_SIZE;
|
||||||
|
@ -193,17 +193,26 @@ static int getReply(uint8_t *response) {
|
||||||
// Entry point into our code: called whenever we received a packet over USB
|
// Entry point into our code: called whenever we received a packet over USB
|
||||||
// that we weren't necessarily expecting, for example a debug print.
|
// that we weren't necessarily expecting, for example a debug print.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
static void UsbReplyReceived(bool reply_ng, uint8_t *packet) {
|
static void UsbReplyReceived(UsbReplyNG *packet) {
|
||||||
|
|
||||||
uint64_t cmd; // To accommodate old cmd, can be reduced to uint16_t once all old cmds are gone.
|
uint64_t cmd; // To accommodate old cmd, can be reduced to uint16_t once all old cmds are gone.
|
||||||
UsbReplyNGPreamble *pre_ng = (UsbReplyNGPreamble *)packet;
|
|
||||||
|
|
||||||
|
if (packet->ng) {
|
||||||
|
// PrintAndLogEx(NORMAL, "RECV NG magic %08x length %04x status %04x crc %04x cmd %04x", packet->magic, packet->length, packet->status, packet->crc, packet->core.ng.cmd);
|
||||||
|
cmd = packet->core.ng.cmd;
|
||||||
|
} else {
|
||||||
|
// PrintAndLogEx(NORMAL, "RECV OLD magic %08x length %04x status %04x crc %04x cmd %04x", packet->magic, packet->length, packet->status, packet->crc, packet->core.old.cmd);
|
||||||
|
cmd = packet->core.old.cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// For cmd handlers still using old cmd format:
|
// For cmd handlers still using old cmd format:
|
||||||
UsbCommand *c = (UsbCommand *)packet;
|
if (packet->ng) {
|
||||||
if (reply_ng) {
|
cmd = packet->core.ng.cmd;
|
||||||
cmd = pre_ng->cmd;
|
|
||||||
} else {
|
} else {
|
||||||
cmd = c->cmd;
|
cmd = packet->core.old.cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
|
@ -212,9 +221,9 @@ static void UsbReplyReceived(bool reply_ng, uint8_t *packet) {
|
||||||
|
|
||||||
char s[USB_CMD_DATA_SIZE + 1];
|
char s[USB_CMD_DATA_SIZE + 1];
|
||||||
memset(s, 0x00, sizeof(s));
|
memset(s, 0x00, sizeof(s));
|
||||||
size_t len = MIN(c->arg[0], USB_CMD_DATA_SIZE);
|
size_t len = MIN(packet->core.old.arg[0], USB_CMD_DATA_SIZE);
|
||||||
memcpy(s, c->d.asBytes, len);
|
memcpy(s, packet->core.old.d.asBytes, len);
|
||||||
uint64_t flag = c->arg[1];
|
uint64_t flag = packet->core.old.arg[1];
|
||||||
|
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
case FLAG_RAWPRINT:
|
case FLAG_RAWPRINT:
|
||||||
|
@ -237,7 +246,7 @@ static void UsbReplyReceived(bool reply_ng, uint8_t *packet) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_DEBUG_PRINT_INTEGERS: {
|
case CMD_DEBUG_PRINT_INTEGERS: {
|
||||||
PrintAndLogEx(NORMAL, "#db# %" PRIx64 ", %" PRIx64 ", %" PRIx64 "", c->arg[0], c->arg[1], c->arg[2]);
|
PrintAndLogEx(NORMAL, "#db# %" PRIx64 ", %" PRIx64 ", %" PRIx64 "", packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// iceman: hw status - down the path on device, runs printusbspeed which starts sending a lot of
|
// iceman: hw status - down the path on device, runs printusbspeed which starts sending a lot of
|
||||||
|
@ -287,9 +296,7 @@ __attribute__((force_align_arg_pointer))
|
||||||
communication_arg_t *connection = (communication_arg_t *)targ;
|
communication_arg_t *connection = (communication_arg_t *)targ;
|
||||||
size_t rxlen;
|
size_t rxlen;
|
||||||
|
|
||||||
uint8_t rx[USB_REPLYNG_MAXLEN];
|
UsbReplyNG rx;
|
||||||
UsbReplyNGPreamble *pre = (UsbReplyNGPreamble *)rx;
|
|
||||||
UsbReplyNGPostamble *post = (UsbReplyNGPostamble *)(rx + sizeof(UsbReplyNGPreamble) + USB_DATANG_SIZE);
|
|
||||||
//int counter_to_offline = 0;
|
//int counter_to_offline = 0;
|
||||||
|
|
||||||
#if defined(__MACH__) && defined(__APPLE__)
|
#if defined(__MACH__) && defined(__APPLE__)
|
||||||
|
@ -300,47 +307,56 @@ __attribute__((force_align_arg_pointer))
|
||||||
rxlen = 0;
|
rxlen = 0;
|
||||||
bool ACK_received = false;
|
bool ACK_received = false;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
if (uart_receive(sp, rx, sizeof(UsbReplyNGPreamble), &rxlen) && (rxlen == sizeof(UsbReplyNGPreamble))) {
|
if (uart_receive(sp, (uint8_t *)&rx, sizeof(UsbReplyNGPreamble), &rxlen) && (rxlen == sizeof(UsbReplyNGPreamble))) {
|
||||||
if (pre->magic == USB_REPLYNG_PREAMBLE_MAGIC) { // New style NG reply
|
if (rx.magic == USB_REPLYNG_PREAMBLE_MAGIC) { // New style NG reply
|
||||||
if (pre->length > USB_DATANG_SIZE) {
|
if (rx.length > USB_DATANG_SIZE) {
|
||||||
PrintAndLogEx(WARNING, "Received packet frame with incompatible length: 0x%04x", pre->length);
|
PrintAndLogEx(WARNING, "Received packet frame with incompatible length: 0x%04x", rx.length);
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
if ((!error) && (pre->length > 0)) { // Get the variable length payload
|
if (!error) { // Get the core and variable length payload
|
||||||
if ((!uart_receive(sp, rx + sizeof(UsbReplyNGPreamble), pre->length, &rxlen)) || (rxlen != pre->length)) {
|
if ((!uart_receive(sp, (uint8_t *)&rx.core, sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + rx.length, &rxlen)) || (rxlen != sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + rx.length)) {
|
||||||
PrintAndLogEx(WARNING, "Received packet frame error variable part too short? %d/%d", rxlen, pre->length);
|
PrintAndLogEx(WARNING, "Received packet frame error variable part too short? %d/%d", rxlen, rx.length);
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!error) { // Get the postamble
|
if (!error) { // Get the postamble
|
||||||
if ((!uart_receive(sp, rx + sizeof(UsbReplyNGPreamble) + USB_DATANG_SIZE, sizeof(UsbReplyNGPostamble), &rxlen)) || (rxlen != sizeof(UsbReplyNGPostamble))) {
|
if ((!uart_receive(sp, (uint8_t *)&rx.crc, sizeof(UsbReplyNGPostamble), &rxlen)) || (rxlen != sizeof(UsbReplyNGPostamble))) {
|
||||||
PrintAndLogEx(WARNING, "Received packet frame error fetching postamble");
|
PrintAndLogEx(WARNING, "Received packet frame error fetching postamble");
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
uint8_t first, second;
|
uint8_t first, second;
|
||||||
compute_crc(CRC_14443_A, rx, sizeof(UsbReplyNGPreamble) + pre->length, &first, &second);
|
compute_crc(CRC_14443_A, (uint8_t *)&rx, sizeof(UsbReplyNGPreamble) + sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + rx.length, &first, &second);
|
||||||
if ((first << 8) + second != post->crc) {
|
if ((first << 8) + second != rx.crc) {
|
||||||
PrintAndLogEx(WARNING, "Received packet frame CRC error %02X%02X <> %04X", first, second, post->crc);
|
PrintAndLogEx(WARNING, "Received packet frame CRC error %02X%02X <> %04X", first, second, rx.crc);
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!error) {
|
if (!error) {
|
||||||
// PrintAndLogEx(NORMAL, "Received reply NG full !!");
|
// PrintAndLogEx(NORMAL, "Received reply NG full !!");
|
||||||
UsbReplyReceived(true, rx);
|
rx.ng = true;
|
||||||
//TODO NG don't send ACK anymore but reply with the corresponding cmd, still things seem to work fine...
|
UsbReplyReceived(&rx);
|
||||||
if (pre->cmd == CMD_ACK) {
|
//TODO DOEGOX NG don't send ACK anymore but reply with the corresponding cmd, still things seem to work fine...
|
||||||
|
if (rx.core.ng.cmd == CMD_ACK) {
|
||||||
ACK_received = true;
|
ACK_received = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // Old style reply
|
} else { // Old style reply
|
||||||
|
uint8_t tmp[sizeof(UsbReplyNGPreamble)];
|
||||||
if ((!uart_receive(sp, rx + sizeof(UsbReplyNGPreamble), sizeof(UsbCommand) - sizeof(UsbReplyNGPreamble), &rxlen)) || (rxlen != sizeof(UsbCommand) - sizeof(UsbReplyNGPreamble))) {
|
memcpy(tmp, &rx, sizeof(UsbReplyNGPreamble));
|
||||||
|
memcpy(&rx.core.old, tmp, sizeof(UsbReplyNGPreamble));
|
||||||
|
if ((!uart_receive(sp, ((uint8_t *)&rx.core.old) + sizeof(UsbReplyNGPreamble), sizeof(UsbCommand) - sizeof(UsbReplyNGPreamble), &rxlen)) || (rxlen != sizeof(UsbCommand) - sizeof(UsbReplyNGPreamble))) {
|
||||||
PrintAndLogEx(WARNING, "Received packet frame error var part too short? %d/%d", rxlen, sizeof(UsbCommand) - sizeof(UsbReplyNGPreamble));
|
PrintAndLogEx(WARNING, "Received packet frame error var part too short? %d/%d", rxlen, sizeof(UsbCommand) - sizeof(UsbReplyNGPreamble));
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
if (!error) {
|
if (!error) {
|
||||||
UsbReplyReceived(false, rx);
|
// PrintAndLogEx(NORMAL, "Received reply old full !!");
|
||||||
if (((UsbCommand *)rx)->cmd == CMD_ACK) {
|
rx.ng = false;
|
||||||
|
rx.magic = 0;
|
||||||
|
rx.length = USB_CMD_DATA_SIZE;
|
||||||
|
rx.status = 0;
|
||||||
|
rx.crc = 0;
|
||||||
|
UsbReplyReceived(&rx);
|
||||||
|
if (rx.core.old.cmd == CMD_ACK) {
|
||||||
ACK_received = true;
|
ACK_received = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,7 +367,7 @@ __attribute__((force_align_arg_pointer))
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO if error, shall we resync ?
|
// TODO DOEGOX if error, shall we resync ?
|
||||||
|
|
||||||
pthread_mutex_lock(&txBufferMutex);
|
pthread_mutex_lock(&txBufferMutex);
|
||||||
|
|
||||||
|
@ -445,11 +461,11 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode,
|
||||||
// check if we can communicate with Pm3
|
// check if we can communicate with Pm3
|
||||||
int TestProxmark(void) {
|
int TestProxmark(void) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_PING, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_PING, {0, 0, 0}, {{0}}};
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 5000)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 5000)) {
|
||||||
PrintAndLogEx(INFO, "Communicating with PM3 over %s.", resp.arg[0] == 1 ? "FPC" : "USB");
|
PrintAndLogEx(INFO, "Communicating with PM3 over %s.", resp.core.old.arg[0] == 1 ? "FPC" : "USB");
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -497,9 +513,9 @@ void CloseProxmark(void) {
|
||||||
* @param show_warning display message after 3 seconds
|
* @param show_warning display message after 3 seconds
|
||||||
* @return true if command was returned, otherwise false
|
* @return true if command was returned, otherwise false
|
||||||
*/
|
*/
|
||||||
bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand *response, size_t ms_timeout, bool show_warning) {
|
bool WaitForResponseTimeoutW(uint32_t cmd, UsbReplyNG *response, size_t ms_timeout, bool show_warning) {
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (response == NULL)
|
if (response == NULL)
|
||||||
response = &resp;
|
response = &resp;
|
||||||
|
@ -509,8 +525,10 @@ bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand *response, size_t ms_timeo
|
||||||
// Wait until the command is received
|
// Wait until the command is received
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
while (getReply((uint8_t *)response)) {
|
while (getReply(response)) {
|
||||||
if (cmd == CMD_UNKNOWN || response->cmd == cmd)
|
if (cmd == CMD_UNKNOWN || (response->ng && response->core.ng.cmd == cmd))
|
||||||
|
return true;
|
||||||
|
if (cmd == CMD_UNKNOWN || ((!response->ng) && response->core.old.cmd == cmd))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,62 +545,14 @@ bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand *response, size_t ms_timeo
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaitForResponseTimeout(uint32_t cmd, UsbCommand *response, size_t ms_timeout) {
|
bool WaitForResponseTimeout(uint32_t cmd, UsbReplyNG *response, size_t ms_timeout) {
|
||||||
return WaitForResponseTimeoutW(cmd, response, ms_timeout, true);
|
return WaitForResponseTimeoutW(cmd, response, ms_timeout, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaitForResponse(uint32_t cmd, UsbCommand *response) {
|
bool WaitForResponse(uint32_t cmd, UsbReplyNG *response) {
|
||||||
return WaitForResponseTimeoutW(cmd, response, -1, true);
|
return WaitForResponseTimeoutW(cmd, response, -1, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Waits for a certain response type. This method waits for a maximum of
|
|
||||||
* ms_timeout milliseconds for a specified response command.
|
|
||||||
|
|
||||||
* @param cmd command to wait for, or CMD_UNKNOWN to take any command.
|
|
||||||
* @param response struct to copy received command into.
|
|
||||||
* @param ms_timeout display message after 3 seconds
|
|
||||||
* @param show_warning display message after 3 seconds
|
|
||||||
* @return true if command was returned, otherwise false
|
|
||||||
*/
|
|
||||||
bool WaitForResponseNGTimeoutW(uint32_t cmd, uint8_t *response, size_t ms_timeout, bool show_warning) {
|
|
||||||
|
|
||||||
uint8_t resp[USB_REPLYNG_MAXLEN];
|
|
||||||
if (response == NULL)
|
|
||||||
response = resp;
|
|
||||||
UsbCommandNGPreamble *pre_ng = (UsbCommandNGPreamble *)response;
|
|
||||||
|
|
||||||
uint64_t start_time = msclock();
|
|
||||||
|
|
||||||
// Wait until the command is received
|
|
||||||
while (true) {
|
|
||||||
|
|
||||||
while (getReply(response)) {
|
|
||||||
if (cmd == CMD_UNKNOWN || pre_ng->cmd == cmd)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msclock() - start_time > ms_timeout)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (msclock() - start_time > 3000 && show_warning) {
|
|
||||||
// 3 seconds elapsed (but this doesn't mean the timeout was exceeded)
|
|
||||||
PrintAndLogEx(INFO, "Waiting for a response from the proxmark3...");
|
|
||||||
PrintAndLogEx(INFO, "You can cancel this operation by pressing the pm3 button");
|
|
||||||
show_warning = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WaitForResponseNGTimeout(uint32_t cmd, uint8_t *response, size_t ms_timeout) {
|
|
||||||
return WaitForResponseNGTimeoutW(cmd, response, ms_timeout, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WaitForResponseNG(uint32_t cmd, uint8_t *response) {
|
|
||||||
return WaitForResponseNGTimeoutW(cmd, response, -1, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data transfer from Proxmark to client. This method times out after
|
* Data transfer from Proxmark to client. This method times out after
|
||||||
* ms_timeout milliseconds.
|
* ms_timeout milliseconds.
|
||||||
|
@ -596,12 +566,12 @@ bool WaitForResponseNG(uint32_t cmd, uint8_t *response) {
|
||||||
* @param show_warning display message after 2 seconds
|
* @param show_warning display message after 2 seconds
|
||||||
* @return true if command was returned, otherwise false
|
* @return true if command was returned, otherwise false
|
||||||
*/
|
*/
|
||||||
bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning) {
|
bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbReplyNG *response, size_t ms_timeout, bool show_warning) {
|
||||||
|
|
||||||
if (dest == NULL) return false;
|
if (dest == NULL) return false;
|
||||||
if (bytes == 0) return true;
|
if (bytes == 0) return true;
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (response == NULL)
|
if (response == NULL)
|
||||||
response = &resp;
|
response = &resp;
|
||||||
|
|
||||||
|
@ -634,24 +604,24 @@ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint3
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd) {
|
static bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbReplyNG *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd) {
|
||||||
|
|
||||||
uint32_t bytes_completed = 0;
|
uint32_t bytes_completed = 0;
|
||||||
uint64_t start_time = msclock();
|
uint64_t start_time = msclock();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
if (getReply((uint8_t *)response)) {
|
if (getReply(response)) {
|
||||||
|
|
||||||
// sample_buf is a array pointer, located in data.c
|
// sample_buf is a array pointer, located in data.c
|
||||||
// arg0 = offset in transfer. Startindex of this chunk
|
// arg0 = offset in transfer. Startindex of this chunk
|
||||||
// arg1 = length bytes to transfer
|
// arg1 = length bytes to transfer
|
||||||
// arg2 = bigbuff tracelength (?)
|
// arg2 = bigbuff tracelength (?)
|
||||||
if (response->cmd == rec_cmd) {
|
if (response->core.old.cmd == rec_cmd) {
|
||||||
|
|
||||||
uint32_t offset = response->arg[0];
|
uint32_t offset = response->core.old.arg[0];
|
||||||
uint32_t copy_bytes = MIN(bytes - bytes_completed, response->arg[1]);
|
uint32_t copy_bytes = MIN(bytes - bytes_completed, response->core.old.arg[1]);
|
||||||
//uint32_t tracelen = c->arg[2];
|
//uint32_t tracelen = response->core.old.arg[2];
|
||||||
|
|
||||||
// extended bounds check1. upper limit is USB_CMD_DATA_SIZE
|
// extended bounds check1. upper limit is USB_CMD_DATA_SIZE
|
||||||
// shouldn't happen
|
// shouldn't happen
|
||||||
|
@ -663,9 +633,9 @@ bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *resp
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(dest + offset, response->d.asBytes, copy_bytes);
|
memcpy(dest + offset, response->core.old.d.asBytes, copy_bytes);
|
||||||
bytes_completed += copy_bytes;
|
bytes_completed += copy_bytes;
|
||||||
} else if (response->cmd == CMD_ACK) {
|
} else if (response->core.old.cmd == CMD_ACK) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,6 @@ typedef struct {
|
||||||
} communication_arg_t;
|
} communication_arg_t;
|
||||||
|
|
||||||
|
|
||||||
bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd);
|
|
||||||
|
|
||||||
void SetOffline(bool value);
|
void SetOffline(bool value);
|
||||||
bool IsOffline(void);
|
bool IsOffline(void);
|
||||||
|
|
||||||
|
@ -60,14 +58,11 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode,
|
||||||
int TestProxmark(void);
|
int TestProxmark(void);
|
||||||
void CloseProxmark(void);
|
void CloseProxmark(void);
|
||||||
|
|
||||||
bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand *response, size_t ms_timeout, bool show_warning);
|
bool WaitForResponseTimeoutW(uint32_t cmd, UsbReplyNG *response, size_t ms_timeout, bool show_warning);
|
||||||
bool WaitForResponseTimeout(uint32_t cmd, UsbCommand *response, size_t ms_timeout);
|
bool WaitForResponseTimeout(uint32_t cmd, UsbReplyNG *response, size_t ms_timeout);
|
||||||
bool WaitForResponse(uint32_t cmd, UsbCommand *response);
|
bool WaitForResponse(uint32_t cmd, UsbReplyNG *response);
|
||||||
bool WaitForResponseNGTimeoutW(uint32_t cmd, uint8_t *response, size_t ms_timeout, bool show_warning);
|
|
||||||
bool WaitForResponseNGTimeout(uint32_t cmd, uint8_t *response, size_t ms_timeout);
|
|
||||||
bool WaitForResponseNG(uint32_t cmd, uint8_t *response);
|
|
||||||
|
|
||||||
bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning);
|
bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbReplyNG *response, size_t ms_timeout, bool show_warning);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -261,7 +261,7 @@ fail:
|
||||||
static int get_proxmark_state(uint32_t *state) {
|
static int get_proxmark_state(uint32_t *state) {
|
||||||
UsbCommand c = {CMD_DEVICE_INFO};
|
UsbCommand c = {CMD_DEVICE_INFO};
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
WaitForResponse(CMD_UNKNOWN, &resp); // wait for any response. No timeout.
|
WaitForResponse(CMD_UNKNOWN, &resp); // wait for any response. No timeout.
|
||||||
|
|
||||||
// Three outcomes:
|
// Three outcomes:
|
||||||
|
@ -269,7 +269,7 @@ static int get_proxmark_state(uint32_t *state) {
|
||||||
// 2. The old os code will respond with CMD_DEBUG_PRINT_STRING and "unknown command"
|
// 2. The old os code will respond with CMD_DEBUG_PRINT_STRING and "unknown command"
|
||||||
// 3. The new bootrom and os codes will respond with CMD_DEVICE_INFO and flags
|
// 3. The new bootrom and os codes will respond with CMD_DEVICE_INFO and flags
|
||||||
|
|
||||||
switch (resp.cmd) {
|
switch (resp.core.old.cmd) {
|
||||||
case CMD_ACK:
|
case CMD_ACK:
|
||||||
*state = DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM;
|
*state = DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM;
|
||||||
break;
|
break;
|
||||||
|
@ -277,10 +277,10 @@ static int get_proxmark_state(uint32_t *state) {
|
||||||
*state = DEVICE_INFO_FLAG_CURRENT_MODE_OS;
|
*state = DEVICE_INFO_FLAG_CURRENT_MODE_OS;
|
||||||
break;
|
break;
|
||||||
case CMD_DEVICE_INFO:
|
case CMD_DEVICE_INFO:
|
||||||
*state = resp.arg[0];
|
*state = resp.core.old.arg[0];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, _RED_("Error:") "Couldn't get Proxmark3 state, bad response type: 0x%04" PRIx64 "\n", resp.cmd);
|
fprintf(stderr, _RED_("Error:") "Couldn't get Proxmark3 state, bad response type: 0x%04" PRIx64 "\n", resp.core.old.cmd);
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -335,13 +335,13 @@ static int enter_bootloader(char *serial_port_name) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int wait_for_ack(UsbCommand *ack) {
|
static int wait_for_ack(UsbReplyNG *ack) {
|
||||||
WaitForResponse(CMD_UNKNOWN, ack);
|
WaitForResponse(CMD_UNKNOWN, ack);
|
||||||
|
|
||||||
if (ack->cmd != CMD_ACK) {
|
if (ack->core.old.cmd != CMD_ACK) {
|
||||||
printf("Error: Unexpected reply 0x%04" PRIx64 " %s (expected ACK)\n",
|
printf("Error: Unexpected reply 0x%04" PRIx64 " %s (expected ACK)\n",
|
||||||
ack->cmd,
|
ack->core.old.cmd,
|
||||||
(ack->cmd == CMD_NACK) ? "NACK" : ""
|
(ack->core.old.cmd == CMD_NACK) ? "NACK" : ""
|
||||||
);
|
);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -362,6 +362,7 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name) {
|
||||||
// This command is stupid. Why the heck does it care which area we're
|
// This command is stupid. Why the heck does it care which area we're
|
||||||
// flashing, as long as it's not the bootloader area? The mind boggles.
|
// flashing, as long as it's not the bootloader area? The mind boggles.
|
||||||
UsbCommand c = {CMD_START_FLASH};
|
UsbCommand c = {CMD_START_FLASH};
|
||||||
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (enable_bl_writes) {
|
if (enable_bl_writes) {
|
||||||
c.arg[0] = FLASH_START;
|
c.arg[0] = FLASH_START;
|
||||||
|
@ -373,7 +374,7 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name) {
|
||||||
c.arg[2] = 0;
|
c.arg[2] = 0;
|
||||||
}
|
}
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
return wait_for_ack(&c);
|
return wait_for_ack(&resp);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, _RED_("Note: Your bootloader does not understand the new START_FLASH command") "\n");
|
fprintf(stderr, _RED_("Note: Your bootloader does not understand the new START_FLASH command") "\n");
|
||||||
fprintf(stderr, _RED_("It is recommended that you update your bootloader") "\n\n");
|
fprintf(stderr, _RED_("It is recommended that you update your bootloader") "\n\n");
|
||||||
|
@ -386,14 +387,15 @@ static int write_block(uint32_t address, uint8_t *data, uint32_t length) {
|
||||||
memset(block_buf, 0xFF, BLOCK_SIZE);
|
memset(block_buf, 0xFF, BLOCK_SIZE);
|
||||||
memcpy(block_buf, data, length);
|
memcpy(block_buf, data, length);
|
||||||
UsbCommand c = {CMD_FINISH_WRITE, {address, 0, 0}};
|
UsbCommand c = {CMD_FINISH_WRITE, {address, 0, 0}};
|
||||||
|
UsbReplyNG resp;
|
||||||
memcpy(c.d.asBytes, block_buf, length);
|
memcpy(c.d.asBytes, block_buf, length);
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
int ret = wait_for_ack(&c);
|
int ret = wait_for_ack(&resp);
|
||||||
if (ret && c.arg[0]) {
|
if (ret && resp.core.old.arg[0]) {
|
||||||
uint32_t lock_bits = c.arg[0] >> 16;
|
uint32_t lock_bits = resp.core.old.arg[0] >> 16;
|
||||||
bool lock_error = c.arg[0] & AT91C_MC_LOCKE;
|
bool lock_error = resp.core.old.arg[0] & AT91C_MC_LOCKE;
|
||||||
bool prog_error = c.arg[0] & AT91C_MC_PROGE;
|
bool prog_error = resp.core.old.arg[0] & AT91C_MC_PROGE;
|
||||||
bool security_bit = c.arg[0] & AT91C_MC_SECURITY;
|
bool security_bit = resp.core.old.arg[0] & AT91C_MC_SECURITY;
|
||||||
printf("%s", lock_error ? " Lock Error\n" : "");
|
printf("%s", lock_error ? " Lock Error\n" : "");
|
||||||
printf("%s", prog_error ? " Invalid Command or bad Keyword\n" : "");
|
printf("%s", prog_error ? " Invalid Command or bad Keyword\n" : "");
|
||||||
printf("%s", security_bit ? " Security Bit is set!\n" : "");
|
printf("%s", security_bit ? " Security Bit is set!\n" : "");
|
||||||
|
|
|
@ -45,18 +45,18 @@ int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) {
|
||||||
return -5;
|
return -5;
|
||||||
}
|
}
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
int16_t isOK = resp.arg[0];
|
int16_t isOK = resp.core.old.arg[0];
|
||||||
if (isOK < 0)
|
if (isOK < 0)
|
||||||
return isOK;
|
return isOK;
|
||||||
|
|
||||||
uid = (uint32_t)bytes_to_num(resp.d.asBytes + 0, 4);
|
uid = (uint32_t)bytes_to_num(resp.core.old.d.asBytes + 0, 4);
|
||||||
nt = (uint32_t)bytes_to_num(resp.d.asBytes + 4, 4);
|
nt = (uint32_t)bytes_to_num(resp.core.old.d.asBytes + 4, 4);
|
||||||
par_list = bytes_to_num(resp.d.asBytes + 8, 8);
|
par_list = bytes_to_num(resp.core.old.d.asBytes + 8, 8);
|
||||||
ks_list = bytes_to_num(resp.d.asBytes + 16, 8);
|
ks_list = bytes_to_num(resp.core.old.d.asBytes + 16, 8);
|
||||||
nr = (uint32_t)bytes_to_num(resp.d.asBytes + 24, 4);
|
nr = (uint32_t)bytes_to_num(resp.core.old.d.asBytes + 24, 4);
|
||||||
ar = (uint32_t)bytes_to_num(resp.d.asBytes + 28, 4);
|
ar = (uint32_t)bytes_to_num(resp.core.old.d.asBytes + 28, 4);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,10 +127,10 @@ int mfCheckKeys(uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keyc
|
||||||
memcpy(c.d.asBytes, keyBlock, 6 * keycnt);
|
memcpy(c.d.asBytes, keyBlock, 6 * keycnt);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) return 1;
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) return 1;
|
||||||
if ((resp.arg[0] & 0xff) != 0x01) return 2;
|
if ((resp.core.old.arg[0] & 0xff) != 0x01) return 2;
|
||||||
*key = bytes_to_num(resp.d.asBytes, 6);
|
*key = bytes_to_num(resp.core.old.d.asBytes, 6);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ int mfCheckKeys_fast(uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastChunk,
|
||||||
memcpy(c.d.asBytes, keyBlock, 6 * size);
|
memcpy(c.d.asBytes, keyBlock, 6 * size);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
timeout++;
|
timeout++;
|
||||||
|
@ -166,7 +166,7 @@ int mfCheckKeys_fast(uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastChunk,
|
||||||
t2 = msclock() - t2;
|
t2 = msclock() - t2;
|
||||||
|
|
||||||
// time to convert the returned data.
|
// time to convert the returned data.
|
||||||
uint8_t curr_keys = resp.arg[0];
|
uint8_t curr_keys = resp.core.old.arg[0];
|
||||||
|
|
||||||
PrintAndLogEx(SUCCESS, "\nChunk: %.1fs | found %u/%u keys (%u)", (float)(t2 / 1000.0), curr_keys, (sectorsCnt << 1), size);
|
PrintAndLogEx(SUCCESS, "\nChunk: %.1fs | found %u/%u keys (%u)", (float)(t2 / 1000.0), curr_keys, (sectorsCnt << 1), size);
|
||||||
|
|
||||||
|
@ -177,8 +177,8 @@ int mfCheckKeys_fast(uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastChunk,
|
||||||
uint8_t arr[80];
|
uint8_t arr[80];
|
||||||
uint64_t foo = 0;
|
uint64_t foo = 0;
|
||||||
uint16_t bar = 0;
|
uint16_t bar = 0;
|
||||||
foo = bytes_to_num(resp.d.asBytes + 480, 8);
|
foo = bytes_to_num(resp.core.old.d.asBytes + 480, 8);
|
||||||
bar = (resp.d.asBytes[489] << 8 | resp.d.asBytes[488]);
|
bar = (resp.core.old.d.asBytes[489] << 8 | resp.core.old.d.asBytes[488]);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 64; i++)
|
for (uint8_t i = 0; i < 64; i++)
|
||||||
arr[i] = (foo >> i) & 0x1;
|
arr[i] = (foo >> i) & 0x1;
|
||||||
|
@ -190,7 +190,7 @@ int mfCheckKeys_fast(uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastChunk,
|
||||||
icesector_t *tmp = calloc(sectorsCnt, sizeof(icesector_t));
|
icesector_t *tmp = calloc(sectorsCnt, sizeof(icesector_t));
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
memcpy(tmp, resp.d.asBytes, sectorsCnt * sizeof(icesector_t));
|
memcpy(tmp, resp.core.old.d.asBytes, sectorsCnt * sizeof(icesector_t));
|
||||||
|
|
||||||
for (int i = 0; i < sectorsCnt; i++) {
|
for (int i = 0; i < sectorsCnt; i++) {
|
||||||
// key A
|
// key A
|
||||||
|
@ -293,7 +293,7 @@ __attribute__((force_align_arg_pointer))
|
||||||
int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t *resultKey, bool calibrate) {
|
int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t *resultKey, bool calibrate) {
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
uint32_t uid;
|
uint32_t uid;
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
StateList_t statelists[2];
|
StateList_t statelists[2];
|
||||||
struct Crypto1State *p1, *p2, *p3, *p4;
|
struct Crypto1State *p1, *p2, *p3, *p4;
|
||||||
|
|
||||||
|
@ -304,16 +304,16 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo,
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return -1;
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return -1;
|
||||||
|
|
||||||
// error during nested
|
// error during nested
|
||||||
if (resp.arg[0]) return resp.arg[0];
|
if (resp.core.old.arg[0]) return resp.core.old.arg[0];
|
||||||
|
|
||||||
memcpy(&uid, resp.d.asBytes, 4);
|
memcpy(&uid, resp.core.old.d.asBytes, 4);
|
||||||
|
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
statelists[i].blockNo = resp.arg[2] & 0xff;
|
statelists[i].blockNo = resp.core.old.arg[2] & 0xff;
|
||||||
statelists[i].keyType = (resp.arg[2] >> 8) & 0xff;
|
statelists[i].keyType = (resp.core.old.arg[2] >> 8) & 0xff;
|
||||||
statelists[i].uid = uid;
|
statelists[i].uid = uid;
|
||||||
memcpy(&statelists[i].nt, (void *)(resp.d.asBytes + 4 + i * 8 + 0), 4);
|
memcpy(&statelists[i].nt, (void *)(resp.core.old.d.asBytes + 4 + i * 8 + 0), 4);
|
||||||
memcpy(&statelists[i].ks1, (void *)(resp.d.asBytes + 4 + i * 8 + 4), 4);
|
memcpy(&statelists[i].ks1, (void *)(resp.core.old.d.asBytes + 4 + i * 8 + 4), 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// calc keys
|
// calc keys
|
||||||
|
@ -397,8 +397,8 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo,
|
||||||
num_to_bytes(key64, 6, resultKey);
|
num_to_bytes(key64, 6, resultKey);
|
||||||
|
|
||||||
PrintAndLogEx(SUCCESS, "target block:%3u key type: %c -- found valid key [%012" PRIx64 "]",
|
PrintAndLogEx(SUCCESS, "target block:%3u key type: %c -- found valid key [%012" PRIx64 "]",
|
||||||
(uint16_t)resp.arg[2] & 0xff,
|
(uint16_t)resp.core.old.arg[2] & 0xff,
|
||||||
(resp.arg[2] >> 8) ? 'B' : 'A',
|
(resp.core.old.arg[2] >> 8) ? 'B' : 'A',
|
||||||
key64
|
key64
|
||||||
);
|
);
|
||||||
return -5;
|
return -5;
|
||||||
|
@ -407,8 +407,8 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo,
|
||||||
|
|
||||||
out:
|
out:
|
||||||
PrintAndLogEx(SUCCESS, "target block:%3u key type: %c",
|
PrintAndLogEx(SUCCESS, "target block:%3u key type: %c",
|
||||||
(uint16_t)resp.arg[2] & 0xff,
|
(uint16_t)resp.core.old.arg[2] & 0xff,
|
||||||
(resp.arg[2] >> 8) ? 'B' : 'A'
|
(resp.core.old.arg[2] >> 8) ? 'B' : 'A'
|
||||||
);
|
);
|
||||||
|
|
||||||
free(statelists[0].head.slhead);
|
free(statelists[0].head.slhead);
|
||||||
|
@ -424,12 +424,12 @@ int mfReadSector(uint8_t sectorNo, uint8_t keyType, uint8_t *key, uint8_t *data)
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
|
|
||||||
if (isOK) {
|
if (isOK) {
|
||||||
memcpy(data, resp.d.asBytes, mfNumBlocksPerSector(sectorNo) * 16);
|
memcpy(data, resp.core.old.d.asBytes, mfNumBlocksPerSector(sectorNo) * 16);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -447,9 +447,9 @@ int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) {
|
||||||
UsbCommand c = {CMD_MIFARE_EML_MEMGET, {blockNum, blocksCount, 0}, {{0}}};
|
UsbCommand c = {CMD_MIFARE_EML_MEMGET, {blockNum, blocksCount, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return 1;
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return 1;
|
||||||
memcpy(data, resp.d.asBytes, blocksCount * 16);
|
memcpy(data, resp.core.old.d.asBytes, blocksCount * 16);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -505,11 +505,11 @@ int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, uint8_t params) {
|
||||||
memcpy(c.d.asBytes, data, 16);
|
memcpy(c.d.asBytes, data, 16);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (uid != NULL)
|
if (uid != NULL)
|
||||||
memcpy(uid, resp.d.asBytes, 4);
|
memcpy(uid, resp.core.old.d.asBytes, 4);
|
||||||
if (!isOK)
|
if (!isOK)
|
||||||
return 2;
|
return 2;
|
||||||
} else {
|
} else {
|
||||||
|
@ -523,12 +523,12 @@ int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) {
|
||||||
UsbCommand c = {CMD_MIFARE_CGETBLOCK, {params, blockNo, 0}, {{0}}};
|
UsbCommand c = {CMD_MIFARE_CGETBLOCK, {params, blockNo, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||||
uint8_t isOK = resp.arg[0] & 0xff;
|
uint8_t isOK = resp.core.old.arg[0] & 0xff;
|
||||||
if (!isOK)
|
if (!isOK)
|
||||||
return 2;
|
return 2;
|
||||||
memcpy(data, resp.d.asBytes, 16);
|
memcpy(data, resp.core.old.d.asBytes, 16);
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(WARNING, "command execute timeout");
|
PrintAndLogEx(WARNING, "command execute timeout");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -869,7 +869,7 @@ int tryDecryptWord(uint32_t nt, uint32_t ar_enc, uint32_t at_enc, uint8_t *data,
|
||||||
*/
|
*/
|
||||||
int detect_classic_prng(void) {
|
int detect_classic_prng(void) {
|
||||||
|
|
||||||
UsbCommand resp, respA;
|
UsbReplyNG resp, respA;
|
||||||
uint8_t cmd[] = {MIFARE_AUTH_KEYA, 0x00};
|
uint8_t cmd[] = {MIFARE_AUTH_KEYA, 0x00};
|
||||||
uint32_t flags = ISO14A_CONNECT | ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_RATS;
|
uint32_t flags = ISO14A_CONNECT | ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_RATS;
|
||||||
|
|
||||||
|
@ -885,7 +885,7 @@ int detect_classic_prng(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if select tag failed.
|
// if select tag failed.
|
||||||
if (resp.arg[0] == 0) {
|
if (resp.core.old.arg[0] == 0) {
|
||||||
PrintAndLogEx(WARNING, "error: selecting tag failed, can't detect prng\n");
|
PrintAndLogEx(WARNING, "error: selecting tag failed, can't detect prng\n");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
@ -895,12 +895,12 @@ int detect_classic_prng(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check respA
|
// check respA
|
||||||
if (respA.arg[0] != 4) {
|
if (respA.core.old.arg[0] != 4) {
|
||||||
PrintAndLogEx(WARNING, "PRNG data error: Wrong length: %d", respA.arg[0]);
|
PrintAndLogEx(WARNING, "PRNG data error: Wrong length: %d", respA.core.old.arg[0]);
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t nonce = bytes_to_num(respA.d.asBytes, respA.arg[0]);
|
uint32_t nonce = bytes_to_num(respA.core.old.d.asBytes, respA.core.old.arg[0]);
|
||||||
return validate_prng_nonce(nonce);
|
return validate_prng_nonce(nonce);
|
||||||
}
|
}
|
||||||
/* Detect Mifare Classic NACK bug
|
/* Detect Mifare Classic NACK bug
|
||||||
|
@ -916,7 +916,7 @@ int detect_classic_nackbug(bool verbose) {
|
||||||
UsbCommand c = {CMD_MIFARE_NACK_DETECT, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_MIFARE_NACK_DETECT, {0, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
PrintAndLogEx(SUCCESS, "press pm3-button on the Proxmark3 device to abort both Proxmark3 and client.\n");
|
PrintAndLogEx(SUCCESS, "press pm3-button on the Proxmark3 device to abort both Proxmark3 and client.\n");
|
||||||
|
@ -949,9 +949,9 @@ int detect_classic_nackbug(bool verbose) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 500)) {
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 500)) {
|
||||||
int32_t ok = resp.arg[0];
|
int32_t ok = resp.core.old.arg[0];
|
||||||
uint32_t nacks = resp.arg[1];
|
uint32_t nacks = resp.core.old.arg[1];
|
||||||
uint32_t auths = resp.arg[2];
|
uint32_t auths = resp.core.old.arg[2];
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
|
@ -998,12 +998,12 @@ int detect_classic_nackbug(bool verbose) {
|
||||||
void detect_classic_magic(void) {
|
void detect_classic_magic(void) {
|
||||||
|
|
||||||
uint8_t isGeneration = 0;
|
uint8_t isGeneration = 0;
|
||||||
UsbCommand resp;
|
UsbReplyNG resp;
|
||||||
UsbCommand c = {CMD_MIFARE_CIDENT, {0, 0, 0}, {{0}}};
|
UsbCommand c = {CMD_MIFARE_CIDENT, {0, 0, 0}, {{0}}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500))
|
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500))
|
||||||
isGeneration = resp.arg[0] & 0xff;
|
isGeneration = resp.core.old.arg[0] & 0xff;
|
||||||
|
|
||||||
switch (isGeneration) {
|
switch (isGeneration) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|
|
@ -184,10 +184,10 @@ static int l_WaitForResponseTimeout(lua_State *L) {
|
||||||
ms_timeout = luaL_checkunsigned(L, 2);
|
ms_timeout = luaL_checkunsigned(L, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
UsbCommand response;
|
UsbReplyNG resp;
|
||||||
if (WaitForResponseTimeout(cmd, &response, ms_timeout)) {
|
if (WaitForResponseTimeout(cmd, &resp, ms_timeout)) {
|
||||||
//Push it as a string
|
//Push it as a string
|
||||||
lua_pushlstring(L, (const char *)&response, sizeof(UsbCommand));
|
lua_pushlstring(L, (const char *)&resp, sizeof(UsbReplyNG));
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
//signal error by returning Nil, errorstring
|
//signal error by returning Nil, errorstring
|
||||||
|
|
29
common/cmd.c
29
common/cmd.c
|
@ -81,50 +81,47 @@ uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len) {
|
uint8_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len) {
|
||||||
uint8_t txBufferNG[USB_REPLYNG_MAXLEN];
|
UsbReplyNG txBufferNG;
|
||||||
size_t txBufferNGLen;
|
size_t txBufferNGLen;
|
||||||
// for (size_t i = 0; i < sizeof(txBufferNG); i++)
|
// for (size_t i = 0; i < sizeof(txBufferNG); i++)
|
||||||
// ((uint8_t *)&txBufferNG)[i] = 0x00;
|
// ((uint8_t *)&txBufferNG)[i] = 0x00;
|
||||||
|
|
||||||
// Compose the outgoing command frame
|
// Compose the outgoing command frame
|
||||||
UsbReplyNGPreamble *tx_pre = (UsbReplyNGPreamble *)txBufferNG;
|
txBufferNG.magic = USB_REPLYNG_PREAMBLE_MAGIC;
|
||||||
tx_pre->magic = USB_REPLYNG_PREAMBLE_MAGIC;
|
txBufferNG.core.ng.cmd = cmd;
|
||||||
tx_pre->cmd = cmd;
|
txBufferNG.status = status;
|
||||||
tx_pre->status = status;
|
|
||||||
if (len > USB_DATANG_SIZE) {
|
if (len > USB_DATANG_SIZE) {
|
||||||
len = USB_DATANG_SIZE;
|
len = USB_DATANG_SIZE;
|
||||||
// overwrite status
|
// overwrite status
|
||||||
tx_pre->status = PM3_EOVFLOW;
|
txBufferNG.status = PM3_EOVFLOW;
|
||||||
}
|
}
|
||||||
tx_pre->length = len;
|
txBufferNG.length = len;
|
||||||
uint8_t *tx_data = txBufferNG + sizeof(UsbReplyNGPreamble);
|
UsbReplyNGPostamble *tx_post = (UsbReplyNGPostamble *)((uint8_t *)&txBufferNG + sizeof(UsbReplyNGPreamble) + sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + len);
|
||||||
UsbReplyNGPostamble *tx_post = (UsbReplyNGPostamble *)(txBufferNG + sizeof(UsbReplyNGPreamble) + len);
|
|
||||||
|
|
||||||
// Add the (optional) content to the frame, with a maximum size of USB_DATANG_SIZE
|
// Add the (optional) content to the frame, with a maximum size of USB_DATANG_SIZE
|
||||||
if (data && len) {
|
if (data && len) {
|
||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
tx_data[i] = data[i];
|
txBufferNG.core.ng.data[i] = data[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t first, second;
|
uint8_t first, second;
|
||||||
compute_crc(CRC_14443_A, txBufferNG, sizeof(UsbReplyNGPreamble) + len, &first, &second);
|
compute_crc(CRC_14443_A, (uint8_t *)&txBufferNG, sizeof(UsbReplyNGPreamble) + sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + len, &first, &second);
|
||||||
tx_post->crc = (first << 8) + second;
|
tx_post->crc = (first << 8) + second;
|
||||||
txBufferNGLen = sizeof(UsbReplyNGPreamble) + len + sizeof(UsbReplyNGPostamble);
|
txBufferNGLen = sizeof(UsbReplyNGPreamble) + sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + len + sizeof(UsbReplyNGPostamble);
|
||||||
|
|
||||||
|
|
||||||
uint32_t sendlen = 0;
|
uint32_t sendlen = 0;
|
||||||
// Send frame and make sure all bytes are transmitted
|
// Send frame and make sure all bytes are transmitted
|
||||||
|
|
||||||
#ifdef WITH_FPC_HOST
|
#ifdef WITH_FPC_HOST
|
||||||
if (reply_via_fpc) {
|
if (reply_via_fpc) {
|
||||||
sendlen = usart_writebuffer(txBufferNG, txBufferNGLen);
|
sendlen = usart_writebuffer((uint8_t *)&txBufferNG, txBufferNGLen);
|
||||||
// Dbprintf_usb("Sent %i bytes over usart", len);
|
// Dbprintf_usb("Sent %i bytes over usart", len);
|
||||||
} else {
|
} else {
|
||||||
sendlen = usb_write(txBufferNG, txBufferNGLen);
|
sendlen = usb_write((uint8_t *)&txBufferNG, txBufferNGLen);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
sendlen = usb_write(txBufferNG, txBufferNGLen);
|
sendlen = usb_write((uint8_t *)&txBufferNG, txBufferNGLen);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return sendlen;
|
return sendlen;
|
||||||
|
|
|
@ -36,10 +36,14 @@ typedef struct {
|
||||||
} d;
|
} d;
|
||||||
} PACKED UsbCommand;
|
} PACKED UsbCommand;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t cmd;
|
||||||
|
uint8_t data[USB_DATANG_SIZE];
|
||||||
|
} PACKED UsbPacketNGCore;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t magic;
|
uint32_t magic;
|
||||||
uint16_t length; // length of the variable part, 0 if none.
|
uint16_t length; // length of the variable part, 0 if none.
|
||||||
uint16_t cmd;
|
|
||||||
} PACKED UsbCommandNGPreamble;
|
} PACKED UsbCommandNGPreamble;
|
||||||
|
|
||||||
#define USB_COMMANDNG_PREAMBLE_MAGIC 0x61334d50 // PM3a
|
#define USB_COMMANDNG_PREAMBLE_MAGIC 0x61334d50 // PM3a
|
||||||
|
@ -48,13 +52,20 @@ typedef struct {
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
} PACKED UsbCommandNGPostamble;
|
} PACKED UsbCommandNGPostamble;
|
||||||
|
|
||||||
#define USB_COMMANDNG_MINLEN (sizeof(UsbCommandNGPreamble) + sizeof(UsbCommandNGPostamble))
|
typedef struct {
|
||||||
#define USB_COMMANDNG_MAXLEN (sizeof(UsbCommandNGPreamble) + USB_DATANG_SIZE + sizeof(UsbCommandNGPostamble))
|
uint32_t magic;
|
||||||
|
uint16_t length; // length of the variable part, 0 if none.
|
||||||
|
union { // we can simplify it once we get rid of old format compatibility
|
||||||
|
UsbPacketNGCore ng;
|
||||||
|
UsbCommand old;
|
||||||
|
} core;
|
||||||
|
uint16_t crc;
|
||||||
|
bool ng;
|
||||||
|
} PACKED UsbCommandNG;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t magic;
|
uint32_t magic;
|
||||||
uint16_t length; // length of the variable part, 0 if none.
|
uint16_t length; // length of the variable part, 0 if none.
|
||||||
uint16_t cmd;
|
|
||||||
int16_t status;
|
int16_t status;
|
||||||
} PACKED UsbReplyNGPreamble;
|
} PACKED UsbReplyNGPreamble;
|
||||||
|
|
||||||
|
@ -64,8 +75,17 @@ typedef struct {
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
} PACKED UsbReplyNGPostamble;
|
} PACKED UsbReplyNGPostamble;
|
||||||
|
|
||||||
#define USB_REPLYNG_MINLEN (sizeof(UsbReplyNGPreamble) + sizeof(UsbReplyNGPostamble))
|
typedef struct {
|
||||||
#define USB_REPLYNG_MAXLEN (sizeof(UsbReplyNGPreamble) + USB_DATANG_SIZE + sizeof(UsbReplyNGPostamble))
|
uint32_t magic; // \ //
|
||||||
|
uint16_t length; // Preamble //
|
||||||
|
int16_t status; // / //
|
||||||
|
union { // we can simplify it once we get rid of old format compatibility
|
||||||
|
UsbPacketNGCore ng;
|
||||||
|
UsbCommand old;
|
||||||
|
} core;
|
||||||
|
uint16_t crc; // -- Postamble //
|
||||||
|
bool ng;
|
||||||
|
} PACKED UsbReplyNG;
|
||||||
|
|
||||||
#ifdef WITH_FPC_HOST
|
#ifdef WITH_FPC_HOST
|
||||||
// "Session" flag, to tell via which interface next msgs should be sent: USB or FPC USART
|
// "Session" flag, to tell via which interface next msgs should be sent: USB or FPC USART
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue