mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
Better Command structs
This commit is contained in:
parent
533667ea6d
commit
4e31c6110b
8 changed files with 219 additions and 206 deletions
315
armsrc/appmain.c
315
armsrc/appmain.c
|
@ -634,32 +634,29 @@ void ListenReaderField(int limit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UsbPacketReceived(UsbCommandNG *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.
|
/*
|
||||||
|
|
||||||
// For cmd handlers still using old cmd format:
|
|
||||||
if (packet->ng) {
|
if (packet->ng) {
|
||||||
cmd = packet->core.ng.cmd;
|
Dbprintf("received NG frame with %d bytes payload, with command: 0x%04x", packet->length, cmd);
|
||||||
// Dbprintf("received NG frame with %d bytes payload, with command: 0x%04x", packet->length, cmd);
|
|
||||||
} else {
|
} else {
|
||||||
cmd = packet->core.old.cmd;
|
Dbprintf("received OLD frame of %d bytes, with command: 0x%04x and args: %d %d %d", packet->length, packet->cmd, packet->oldarg[0], packet->oldarg[1], packet->oldarg[2]);
|
||||||
// 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 (packet->cmd) {
|
||||||
#ifdef WITH_LF
|
#ifdef WITH_LF
|
||||||
case CMD_SET_LF_T55XX_CONFIG:
|
case CMD_SET_LF_T55XX_CONFIG:
|
||||||
setT55xxConfig(packet->core.old.arg[0], (t55xx_config *) packet->core.old.d.asBytes);
|
setT55xxConfig(packet->oldarg[0], (t55xx_config *) packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_SET_LF_SAMPLING_CONFIG:
|
case CMD_SET_LF_SAMPLING_CONFIG:
|
||||||
setSamplingConfig((sample_config *) packet->core.old.d.asBytes);
|
setSamplingConfig((sample_config *) packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K: {
|
case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K: {
|
||||||
uint32_t bits = SampleLF(packet->core.old.arg[0], packet->core.old.arg[1]);
|
uint32_t bits = SampleLF(packet->oldarg[0], packet->oldarg[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(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
ModThenAcquireRawAdcSamples125k(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.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();
|
||||||
|
@ -668,73 +665,73 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
}
|
}
|
||||||
case CMD_HID_DEMOD_FSK: {
|
case CMD_HID_DEMOD_FSK: {
|
||||||
uint32_t high, low;
|
uint32_t high, low;
|
||||||
CmdHIDdemodFSK(packet->core.old.arg[0], &high, &low, 1);
|
CmdHIDdemodFSK(packet->oldarg[0], &high, &low, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_HID_SIM_TAG:
|
case CMD_HID_SIM_TAG:
|
||||||
CmdHIDsimTAG(packet->core.old.arg[0], packet->core.old.arg[1], 1);
|
CmdHIDsimTAG(packet->oldarg[0], packet->oldarg[1], 1);
|
||||||
break;
|
break;
|
||||||
case CMD_FSK_SIM_TAG:
|
case CMD_FSK_SIM_TAG:
|
||||||
CmdFSKsimTAG(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes, 1);
|
CmdFSKsimTAG(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes, 1);
|
||||||
break;
|
break;
|
||||||
case CMD_ASK_SIM_TAG:
|
case CMD_ASK_SIM_TAG:
|
||||||
CmdASKsimTag(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes, 1);
|
CmdASKsimTag(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes, 1);
|
||||||
break;
|
break;
|
||||||
case CMD_PSK_SIM_TAG:
|
case CMD_PSK_SIM_TAG:
|
||||||
CmdPSKsimTag(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes, 1);
|
CmdPSKsimTag(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes, 1);
|
||||||
break;
|
break;
|
||||||
case CMD_HID_CLONE_TAG:
|
case CMD_HID_CLONE_TAG:
|
||||||
CopyHIDtoT55x7(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes[0]);
|
CopyHIDtoT55x7(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_IO_DEMOD_FSK: {
|
case CMD_IO_DEMOD_FSK: {
|
||||||
uint32_t high, low;
|
uint32_t high, low;
|
||||||
CmdIOdemodFSK(packet->core.old.arg[0], &high, &low, 1);
|
CmdIOdemodFSK(packet->oldarg[0], &high, &low, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_IO_CLONE_TAG:
|
case CMD_IO_CLONE_TAG:
|
||||||
CopyIOtoT55x7(packet->core.old.arg[0], packet->core.old.arg[1]);
|
CopyIOtoT55x7(packet->oldarg[0], packet->oldarg[1]);
|
||||||
break;
|
break;
|
||||||
case CMD_EM410X_DEMOD: {
|
case CMD_EM410X_DEMOD: {
|
||||||
uint32_t high;
|
uint32_t high;
|
||||||
uint64_t low;
|
uint64_t low;
|
||||||
CmdEM410xdemod(packet->core.old.arg[0], &high, &low, 1);
|
CmdEM410xdemod(packet->oldarg[0], &high, &low, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_EM410X_WRITE_TAG:
|
case CMD_EM410X_WRITE_TAG:
|
||||||
WriteEM410x(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
WriteEM410x(packet->oldarg[0], packet->oldarg[1], packet->oldarg[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(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
WriteTItag(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_SIMULATE_TAG_125K:
|
case CMD_SIMULATE_TAG_125K:
|
||||||
LED_A_ON();
|
LED_A_ON();
|
||||||
SimulateTagLowFrequency(packet->core.old.arg[0], packet->core.old.arg[1], 1);
|
SimulateTagLowFrequency(packet->oldarg[0], packet->oldarg[1], 1);
|
||||||
LED_A_OFF();
|
LED_A_OFF();
|
||||||
break;
|
break;
|
||||||
case CMD_LF_SIMULATE_BIDIR:
|
case CMD_LF_SIMULATE_BIDIR:
|
||||||
SimulateTagLowFrequencyBidir(packet->core.old.arg[0], packet->core.old.arg[1]);
|
SimulateTagLowFrequencyBidir(packet->oldarg[0], packet->oldarg[1]);
|
||||||
break;
|
break;
|
||||||
case CMD_INDALA_CLONE_TAG:
|
case CMD_INDALA_CLONE_TAG:
|
||||||
CopyIndala64toT55x7(packet->core.old.d.asDwords[0], packet->core.old.d.asDwords[1]);
|
CopyIndala64toT55x7(packet->data.asDwords[0], packet->data.asDwords[1]);
|
||||||
break;
|
break;
|
||||||
case CMD_INDALA_CLONE_TAG_L:
|
case CMD_INDALA_CLONE_TAG_L:
|
||||||
CopyIndala224toT55x7(
|
CopyIndala224toT55x7(
|
||||||
packet->core.old.d.asDwords[0], packet->core.old.d.asDwords[1], packet->core.old.d.asDwords[2], packet->core.old.d.asDwords[3],
|
packet->data.asDwords[0], packet->data.asDwords[1], packet->data.asDwords[2], packet->data.asDwords[3],
|
||||||
packet->core.old.d.asDwords[4], packet->core.old.d.asDwords[5], packet->core.old.d.asDwords[6]
|
packet->data.asDwords[4], packet->data.asDwords[5], packet->data.asDwords[6]
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case CMD_T55XX_READ_BLOCK: {
|
case CMD_T55XX_READ_BLOCK: {
|
||||||
T55xxReadBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
T55xxReadBlock(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_T55XX_WRITE_BLOCK:
|
case CMD_T55XX_WRITE_BLOCK:
|
||||||
T55xxWriteBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes[0]);
|
T55xxWriteBlock(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_T55XX_WAKEUP:
|
case CMD_T55XX_WAKEUP:
|
||||||
T55xxWakeUp(packet->core.old.arg[0]);
|
T55xxWakeUp(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_T55XX_RESET_READ:
|
case CMD_T55XX_RESET_READ:
|
||||||
T55xxResetRead();
|
T55xxResetRead();
|
||||||
|
@ -747,58 +744,58 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
break;
|
break;
|
||||||
case CMD_PCF7931_WRITE:
|
case CMD_PCF7931_WRITE:
|
||||||
WritePCF7931(
|
WritePCF7931(
|
||||||
packet->core.old.d.asBytes[0], packet->core.old.d.asBytes[1], packet->core.old.d.asBytes[2], packet->core.old.d.asBytes[3],
|
packet->data.asBytes[0], packet->data.asBytes[1], packet->data.asBytes[2], packet->data.asBytes[3],
|
||||||
packet->core.old.d.asBytes[4], packet->core.old.d.asBytes[5], packet->core.old.d.asBytes[6], packet->core.old.d.asBytes[9],
|
packet->data.asBytes[4], packet->data.asBytes[5], packet->data.asBytes[6], packet->data.asBytes[9],
|
||||||
packet->core.old.d.asBytes[7] - 128, packet->core.old.d.asBytes[8] - 128,
|
packet->data.asBytes[7] - 128, packet->data.asBytes[8] - 128,
|
||||||
packet->core.old.arg[0],
|
packet->oldarg[0],
|
||||||
packet->core.old.arg[1],
|
packet->oldarg[1],
|
||||||
packet->core.old.arg[2]
|
packet->oldarg[2]
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case CMD_EM4X_READ_WORD:
|
case CMD_EM4X_READ_WORD:
|
||||||
EM4xReadWord(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
EM4xReadWord(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_EM4X_WRITE_WORD:
|
case CMD_EM4X_WRITE_WORD:
|
||||||
EM4xWriteWord(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
EM4xWriteWord(packet->oldarg[0], packet->oldarg[1], packet->oldarg[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(packet->core.old.arg[0], &high, &low, 1);
|
CmdAWIDdemodFSK(packet->oldarg[0], &high, &low, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_VIKING_CLONE_TAG:
|
case CMD_VIKING_CLONE_TAG:
|
||||||
CopyVikingtoT55xx(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
CopyVikingtoT55xx(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_COTAG:
|
case CMD_COTAG:
|
||||||
Cotag(packet->core.old.arg[0]);
|
Cotag(packet->oldarg[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(packet->core.old.arg[0]);
|
SniffHitag(packet->oldarg[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)packet->core.old.arg[0], packet->core.old.d.asBytes);
|
SimulateHitagTag((bool)packet->oldarg[0], packet->data.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)packet->core.old.arg[0], (hitag_data *)packet->core.old.d.asBytes);
|
ReaderHitag((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.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)packet->core.old.arg[0], packet->core.old.d.asBytes);
|
SimulateHitagSTag((bool)packet->oldarg[0], packet->data.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)packet->core.old.arg[0], packet->core.old.d.asBytes);
|
check_challenges((bool)packet->oldarg[0], packet->data.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)packet->core.old.arg[0], (hitag_data *)packet->core.old.d.asBytes);
|
ReadHitagS((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.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)packet->core.old.arg[0] < 10) {
|
if ((hitag_function)packet->oldarg[0] < 10) {
|
||||||
WritePageHitagS((hitag_function)packet->core.old.arg[0], (hitag_data *)packet->core.old.d.asBytes, packet->core.old.arg[2]);
|
WritePageHitagS((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.asBytes, packet->oldarg[2]);
|
||||||
} else {
|
} else {
|
||||||
WriterHitag((hitag_function)packet->core.old.arg[0], (hitag_data *)packet->core.old.d.asBytes, packet->core.old.arg[2]);
|
WriterHitag((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.asBytes, packet->oldarg[2]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -811,28 +808,28 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
RecordRawAdcSamplesIso15693();
|
RecordRawAdcSamplesIso15693();
|
||||||
break;
|
break;
|
||||||
case CMD_ISO_15693_COMMAND:
|
case CMD_ISO_15693_COMMAND:
|
||||||
DirectTag15693Command(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
DirectTag15693Command(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_ISO_15693_FIND_AFI:
|
case CMD_ISO_15693_FIND_AFI:
|
||||||
BruteforceIso15693Afi(packet->core.old.arg[0]);
|
BruteforceIso15693Afi(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_READER_ISO_15693:
|
case CMD_READER_ISO_15693:
|
||||||
ReaderIso15693(packet->core.old.arg[0]);
|
ReaderIso15693(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_SIMTAG_ISO_15693:
|
case CMD_SIMTAG_ISO_15693:
|
||||||
SimTagIso15693(packet->core.old.arg[0], packet->core.old.d.asBytes);
|
SimTagIso15693(packet->oldarg[0], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_LEGICRF
|
#ifdef WITH_LEGICRF
|
||||||
case CMD_SIMULATE_TAG_LEGIC_RF:
|
case CMD_SIMULATE_TAG_LEGIC_RF:
|
||||||
LegicRfSimulate(packet->core.old.arg[0]);
|
LegicRfSimulate(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_WRITER_LEGIC_RF:
|
case CMD_WRITER_LEGIC_RF:
|
||||||
LegicRfWriter(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
LegicRfWriter(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_READER_LEGIC_RF:
|
case CMD_READER_LEGIC_RF:
|
||||||
LegicRfReader(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
LegicRfReader(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_LEGIC_INFO:
|
case CMD_LEGIC_INFO:
|
||||||
LegicRfInfo();
|
LegicRfInfo();
|
||||||
|
@ -846,22 +843,22 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
// arg0 = offset
|
// arg0 = offset
|
||||||
// arg1 = num of bytes
|
// arg1 = num of bytes
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||||
emlSet(packet->core.old.d.asBytes, packet->core.old.arg[0], packet->core.old.arg[1]);
|
emlSet(packet->data.asBytes, packet->oldarg[0], packet->oldarg[1]);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_ISO14443b
|
#ifdef WITH_ISO14443b
|
||||||
case CMD_READ_SRI_TAG:
|
case CMD_READ_SRI_TAG:
|
||||||
ReadSTMemoryIso14443b(packet->core.old.arg[0]);
|
ReadSTMemoryIso14443b(packet->oldarg[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(packet->core.old.arg[0]);
|
SimulateIso14443bTag(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_ISO_14443B_COMMAND:
|
case CMD_ISO_14443B_COMMAND:
|
||||||
//SendRawCommand14443B(packet->core.old.arg[0],packet->core.old.arg[1],packet->core.old.arg[2],packet->core.old.d.asBytes);
|
//SendRawCommand14443B(packet->oldarg[0],packet->oldarg[1],packet->oldarg[2],packet->data.asBytes);
|
||||||
SendRawCommand14443B_Ex(packet);
|
SendRawCommand14443B_Ex(packet);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -871,10 +868,10 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
felica_sendraw(packet);
|
felica_sendraw(packet);
|
||||||
break;
|
break;
|
||||||
case CMD_FELICA_LITE_SIM:
|
case CMD_FELICA_LITE_SIM:
|
||||||
felica_sim_lite(packet->core.old.arg[0]);
|
felica_sim_lite(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_FELICA_SNIFF:
|
case CMD_FELICA_SNIFF:
|
||||||
felica_sniff(packet->core.old.arg[0], packet->core.old.arg[1]);
|
felica_sniff(packet->oldarg[0], packet->oldarg[1]);
|
||||||
break;
|
break;
|
||||||
case CMD_FELICA_LITE_DUMP:
|
case CMD_FELICA_LITE_DUMP:
|
||||||
felica_dump_lite_s();
|
felica_dump_lite_s();
|
||||||
|
@ -883,16 +880,16 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
|
|
||||||
#ifdef WITH_ISO14443a
|
#ifdef WITH_ISO14443a
|
||||||
case CMD_SNIFF_ISO_14443a:
|
case CMD_SNIFF_ISO_14443a:
|
||||||
SniffIso14443a(packet->core.old.arg[0]);
|
SniffIso14443a(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_READER_ISO_14443a:
|
case CMD_READER_ISO_14443a:
|
||||||
ReaderIso14443a(packet);
|
ReaderIso14443a(packet);
|
||||||
break;
|
break;
|
||||||
case CMD_SIMULATE_TAG_ISO_14443a:
|
case CMD_SIMULATE_TAG_ISO_14443a:
|
||||||
SimulateIso14443aTag(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes); // ## Simulate iso14443a tag - pass tag type & UID
|
SimulateIso14443aTag(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes); // ## Simulate iso14443a tag - pass tag type & UID
|
||||||
break;
|
break;
|
||||||
case CMD_ANTIFUZZ_ISO_14443a:
|
case CMD_ANTIFUZZ_ISO_14443a:
|
||||||
iso14443a_antifuzz(packet->core.old.arg[0]);
|
iso14443a_antifuzz(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_EPA_PACE_COLLECT_NONCE:
|
case CMD_EPA_PACE_COLLECT_NONCE:
|
||||||
EPA_PACE_Collect_Nonce(packet);
|
EPA_PACE_Collect_Nonce(packet);
|
||||||
|
@ -901,89 +898,89 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
EPA_PACE_Replay(packet);
|
EPA_PACE_Replay(packet);
|
||||||
break;
|
break;
|
||||||
case CMD_READER_MIFARE:
|
case CMD_READER_MIFARE:
|
||||||
ReaderMifare(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2]);
|
ReaderMifare(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_READBL:
|
case CMD_MIFARE_READBL:
|
||||||
MifareReadBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
MifareReadBlock(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFAREU_READBL:
|
case CMD_MIFAREU_READBL:
|
||||||
MifareUReadBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
MifareUReadBlock(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFAREUC_AUTH:
|
case CMD_MIFAREUC_AUTH:
|
||||||
MifareUC_Auth(packet->core.old.arg[0], packet->core.old.d.asBytes);
|
MifareUC_Auth(packet->oldarg[0], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFAREU_READCARD:
|
case CMD_MIFAREU_READCARD:
|
||||||
MifareUReadCard(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
MifareUReadCard(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFAREUC_SETPWD:
|
case CMD_MIFAREUC_SETPWD:
|
||||||
MifareUSetPwd(packet->core.old.arg[0], packet->core.old.d.asBytes);
|
MifareUSetPwd(packet->oldarg[0], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_READSC:
|
case CMD_MIFARE_READSC:
|
||||||
MifareReadSector(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
MifareReadSector(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_WRITEBL:
|
case CMD_MIFARE_WRITEBL:
|
||||||
MifareWriteBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
MifareWriteBlock(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
//case CMD_MIFAREU_WRITEBL_COMPAT:
|
//case CMD_MIFAREU_WRITEBL_COMPAT:
|
||||||
//MifareUWriteBlockCompat(packet->core.old.arg[0], packet->core.old.d.asBytes);
|
//MifareUWriteBlockCompat(packet->oldarg[0], packet->data.asBytes);
|
||||||
//break;
|
//break;
|
||||||
case CMD_MIFAREU_WRITEBL:
|
case CMD_MIFAREU_WRITEBL:
|
||||||
MifareUWriteBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
MifareUWriteBlock(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_ACQUIRE_ENCRYPTED_NONCES:
|
case CMD_MIFARE_ACQUIRE_ENCRYPTED_NONCES:
|
||||||
MifareAcquireEncryptedNonces(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
MifareAcquireEncryptedNonces(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_ACQUIRE_NONCES:
|
case CMD_MIFARE_ACQUIRE_NONCES:
|
||||||
MifareAcquireNonces(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
MifareAcquireNonces(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_NESTED:
|
case CMD_MIFARE_NESTED:
|
||||||
MifareNested(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
MifareNested(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_CHKKEYS: {
|
case CMD_MIFARE_CHKKEYS: {
|
||||||
MifareChkKeys(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
MifareChkKeys(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_MIFARE_CHKKEYS_FAST: {
|
case CMD_MIFARE_CHKKEYS_FAST: {
|
||||||
MifareChkKeys_fast(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
MifareChkKeys_fast(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SIMULATE_MIFARE_CARD:
|
case CMD_SIMULATE_MIFARE_CARD:
|
||||||
Mifare1ksim(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
Mifare1ksim(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// emulator
|
// emulator
|
||||||
case CMD_MIFARE_SET_DBGMODE:
|
case CMD_MIFARE_SET_DBGMODE:
|
||||||
MifareSetDbgLvl(packet->core.old.arg[0]);
|
MifareSetDbgLvl(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_EML_MEMCLR:
|
case CMD_MIFARE_EML_MEMCLR:
|
||||||
MifareEMemClr(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
MifareEMemClr(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_EML_MEMSET:
|
case CMD_MIFARE_EML_MEMSET:
|
||||||
MifareEMemSet(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
MifareEMemSet(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_EML_MEMGET:
|
case CMD_MIFARE_EML_MEMGET:
|
||||||
MifareEMemGet(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
MifareEMemGet(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_EML_CARDLOAD:
|
case CMD_MIFARE_EML_CARDLOAD:
|
||||||
MifareECardLoad(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
MifareECardLoad(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Work with "magic Chinese" card
|
// Work with "magic Chinese" card
|
||||||
case CMD_MIFARE_CSETBLOCK:
|
case CMD_MIFARE_CSETBLOCK:
|
||||||
MifareCSetBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
MifareCSetBlock(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_CGETBLOCK:
|
case CMD_MIFARE_CGETBLOCK:
|
||||||
MifareCGetBlock(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
MifareCGetBlock(packet->oldarg[0], packet->oldarg[1], packet->data.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(packet->core.old.arg[0]);
|
// SniffMifare(packet->oldarg[0]);
|
||||||
// break;
|
// break;
|
||||||
case CMD_MIFARE_SETMOD:
|
case CMD_MIFARE_SETMOD:
|
||||||
MifareSetMod(packet->core.old.arg[0], packet->core.old.d.asBytes);
|
MifareSetMod(packet->oldarg[0], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
//mifare desfire
|
//mifare desfire
|
||||||
case CMD_MIFARE_DESFIRE_READBL:
|
case CMD_MIFARE_DESFIRE_READBL:
|
||||||
|
@ -991,19 +988,19 @@ static void UsbPacketReceived(UsbCommandNG *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(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
MifareDES_Auth1(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_DESFIRE_AUTH2:
|
case CMD_MIFARE_DESFIRE_AUTH2:
|
||||||
//MifareDES_Auth2(packet->core.old.arg[0],packet->core.old.d.asBytes);
|
//MifareDES_Auth2(packet->oldarg[0],packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_DES_READER:
|
case CMD_MIFARE_DES_READER:
|
||||||
//readermifaredes(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
//readermifaredes(packet->oldarg[0], packet->oldarg[1], packet->data.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(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
MifareSendCommand(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_MIFARE_COLLECT_NONCES:
|
case CMD_MIFARE_COLLECT_NONCES:
|
||||||
break;
|
break;
|
||||||
|
@ -1018,45 +1015,45 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
SniffIClass();
|
SniffIClass();
|
||||||
break;
|
break;
|
||||||
case CMD_SIMULATE_TAG_ICLASS:
|
case CMD_SIMULATE_TAG_ICLASS:
|
||||||
SimulateIClass(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.arg[2], packet->core.old.d.asBytes);
|
SimulateIClass(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_READER_ICLASS:
|
case CMD_READER_ICLASS:
|
||||||
ReaderIClass(packet->core.old.arg[0]);
|
ReaderIClass(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_READER_ICLASS_REPLAY:
|
case CMD_READER_ICLASS_REPLAY:
|
||||||
ReaderIClass_Replay(packet->core.old.arg[0], packet->core.old.d.asBytes);
|
ReaderIClass_Replay(packet->oldarg[0], packet->data.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(packet->core.old.d.asBytes, packet->core.old.arg[0], packet->core.old.arg[1]);
|
emlSet(packet->data.asBytes, packet->oldarg[0], packet->oldarg[1]);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_WRITEBLOCK:
|
case CMD_ICLASS_WRITEBLOCK:
|
||||||
iClass_WriteBlock(packet->core.old.arg[0], packet->core.old.d.asBytes);
|
iClass_WriteBlock(packet->oldarg[0], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_READCHECK: // auth step 1
|
case CMD_ICLASS_READCHECK: // auth step 1
|
||||||
iClass_ReadCheck(packet->core.old.arg[0], packet->core.old.arg[1]);
|
iClass_ReadCheck(packet->oldarg[0], packet->oldarg[1]);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_READBLOCK:
|
case CMD_ICLASS_READBLOCK:
|
||||||
iClass_ReadBlk(packet->core.old.arg[0]);
|
iClass_ReadBlk(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_AUTHENTICATION: //check
|
case CMD_ICLASS_AUTHENTICATION: //check
|
||||||
iClass_Authentication(packet->core.old.d.asBytes);
|
iClass_Authentication(packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_CHECK_KEYS:
|
case CMD_ICLASS_CHECK_KEYS:
|
||||||
iClass_Authentication_fast(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
iClass_Authentication_fast(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_DUMP:
|
case CMD_ICLASS_DUMP:
|
||||||
iClass_Dump(packet->core.old.arg[0], packet->core.old.arg[1]);
|
iClass_Dump(packet->oldarg[0], packet->oldarg[1]);
|
||||||
break;
|
break;
|
||||||
case CMD_ICLASS_CLONE:
|
case CMD_ICLASS_CLONE:
|
||||||
iClass_Clone(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
iClass_Clone(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_HFSNIFF
|
#ifdef WITH_HFSNIFF
|
||||||
case CMD_HF_SNIFFER:
|
case CMD_HF_SNIFFER:
|
||||||
HfSniff(packet->core.old.arg[0], packet->core.old.arg[1]);
|
HfSniff(packet->oldarg[0], packet->oldarg[1]);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1066,26 +1063,26 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SMART_SETBAUD: {
|
case CMD_SMART_SETBAUD: {
|
||||||
SmartCardSetBaud(packet->core.old.arg[0]);
|
SmartCardSetBaud(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SMART_SETCLOCK: {
|
case CMD_SMART_SETCLOCK: {
|
||||||
SmartCardSetClock(packet->core.old.arg[0]);
|
SmartCardSetClock(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SMART_RAW: {
|
case CMD_SMART_RAW: {
|
||||||
SmartCardRaw(packet->core.old.arg[0], packet->core.old.arg[1], packet->core.old.d.asBytes);
|
SmartCardRaw(packet->oldarg[0], packet->oldarg[1], packet->data.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 + packet->core.old.arg[0], packet->core.old.d.asBytes, USB_CMD_DATA_SIZE);
|
memcpy(mem + packet->oldarg[0], packet->data.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(packet->core.old.arg[0]);
|
SmartCardUpgrade(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1127,10 +1124,10 @@ static void UsbPacketReceived(UsbCommandNG *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"
|
||||||
, packet->core.old.d.asBytes[0]
|
, packet->data.asBytes[0]
|
||||||
, packet->core.old.d.asBytes[1]
|
, packet->data.asBytes[1]
|
||||||
, packet->core.old.d.asBytes[2]
|
, packet->data.asBytes[2]
|
||||||
, packet->core.old.d.asBytes[3]
|
, packet->data.asBytes[3]
|
||||||
);
|
);
|
||||||
usart_writebuffer((uint8_t *)dest, strlen(dest));
|
usart_writebuffer((uint8_t *)dest, strlen(dest));
|
||||||
|
|
||||||
|
@ -1176,7 +1173,7 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_LISTEN_READER_FIELD:
|
case CMD_LISTEN_READER_FIELD:
|
||||||
ListenReaderField(packet->core.old.arg[0]);
|
ListenReaderField(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_FPGA_MAJOR_MODE_OFF: // ## FPGA Control
|
case CMD_FPGA_MAJOR_MODE_OFF: // ## FPGA Control
|
||||||
|
@ -1188,12 +1185,12 @@ static void UsbPacketReceived(UsbCommandNG *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 = packet->core.old.arg[0];
|
uint32_t startidx = packet->oldarg[0];
|
||||||
uint32_t numofbytes = packet->core.old.arg[1];
|
uint32_t numofbytes = packet->oldarg[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, packet->core.old.arg[2]);
|
//Dbprintf("transfer to client parameters: %" PRIu32 " | %" PRIu32 " | %" PRIu32, startidx, numofbytes, packet->oldarg[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);
|
||||||
|
@ -1218,13 +1215,13 @@ static void UsbPacketReceived(UsbCommandNG *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 (packet->core.old.arg[1] == FPGA_LF)
|
if (packet->oldarg[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 + packet->core.old.arg[0], packet->core.old.d.asBytes, USB_CMD_DATA_SIZE);
|
memcpy(mem + packet->oldarg[0], packet->data.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;
|
||||||
}
|
}
|
||||||
|
@ -1233,8 +1230,8 @@ static void UsbPacketReceived(UsbCommandNG *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 = packet->core.old.arg[0];
|
uint32_t startidx = packet->oldarg[0];
|
||||||
uint32_t numofbytes = packet->core.old.arg[1];
|
uint32_t numofbytes = packet->oldarg[1];
|
||||||
|
|
||||||
// arg0 = startindex
|
// arg0 = startindex
|
||||||
// arg1 = length bytes to transfer
|
// arg1 = length bytes to transfer
|
||||||
|
@ -1252,16 +1249,16 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_READ_MEM:
|
case CMD_READ_MEM:
|
||||||
ReadMem(packet->core.old.arg[0]);
|
ReadMem(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
#ifdef WITH_FLASH
|
#ifdef WITH_FLASH
|
||||||
case CMD_FLASHMEM_SET_SPIBAUDRATE:
|
case CMD_FLASHMEM_SET_SPIBAUDRATE:
|
||||||
FlashmemSetSpiBaudrate(packet->core.old.arg[0]);
|
FlashmemSetSpiBaudrate(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
case CMD_FLASHMEM_READ: {
|
case CMD_FLASHMEM_READ: {
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
uint32_t startidx = packet->core.old.arg[0];
|
uint32_t startidx = packet->oldarg[0];
|
||||||
uint16_t len = packet->core.old.arg[1];
|
uint16_t len = packet->oldarg[1];
|
||||||
|
|
||||||
Dbprintf("FlashMem read | %d - %d | ", startidx, len);
|
Dbprintf("FlashMem read | %d - %d | ", startidx, len);
|
||||||
|
|
||||||
|
@ -1294,9 +1291,9 @@ static void UsbPacketReceived(UsbCommandNG *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 = packet->core.old.arg[0];
|
uint32_t startidx = packet->oldarg[0];
|
||||||
uint16_t len = packet->core.old.arg[1];
|
uint16_t len = packet->oldarg[1];
|
||||||
uint8_t *data = packet->core.old.d.asBytes;
|
uint8_t *data = packet->data.asBytes;
|
||||||
|
|
||||||
uint32_t tmp = startidx + len;
|
uint32_t tmp = startidx + len;
|
||||||
|
|
||||||
|
@ -1355,8 +1352,8 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
}
|
}
|
||||||
case CMD_FLASHMEM_WIPE: {
|
case CMD_FLASHMEM_WIPE: {
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
uint8_t page = packet->core.old.arg[0];
|
uint8_t page = packet->oldarg[0];
|
||||||
uint8_t initalwipe = packet->core.old.arg[1];
|
uint8_t initalwipe = packet->oldarg[1];
|
||||||
bool isok = false;
|
bool isok = false;
|
||||||
if (initalwipe) {
|
if (initalwipe) {
|
||||||
isok = Flash_WipeMemory();
|
isok = Flash_WipeMemory();
|
||||||
|
@ -1375,8 +1372,8 @@ static void UsbPacketReceived(UsbCommandNG *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 = packet->core.old.arg[0];
|
uint32_t startidx = packet->oldarg[0];
|
||||||
uint32_t numofbytes = packet->core.old.arg[1];
|
uint32_t numofbytes = packet->oldarg[1];
|
||||||
// arg0 = startindex
|
// arg0 = startindex
|
||||||
// arg1 = length bytes to transfer
|
// arg1 = length bytes to transfer
|
||||||
// arg2 = RFU
|
// arg2 = RFU
|
||||||
|
@ -1423,11 +1420,11 @@ static void UsbPacketReceived(UsbCommandNG *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, packet->core.old.arg[0]);
|
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_SET_ADC_MUX:
|
case CMD_SET_ADC_MUX:
|
||||||
switch (packet->core.old.arg[0]) {
|
switch (packet->oldarg[0]) {
|
||||||
case 0:
|
case 0:
|
||||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||||
break;
|
break;
|
||||||
|
@ -1453,7 +1450,7 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
break;
|
break;
|
||||||
case CMD_PING:
|
case CMD_PING:
|
||||||
if (packet->ng) {
|
if (packet->ng) {
|
||||||
reply_ng(CMD_PING, PM3_SUCCESS, packet->core.ng.data, packet->length);
|
reply_ng(CMD_PING, PM3_SUCCESS, packet->data.asBytes, 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);
|
||||||
|
@ -1467,7 +1464,7 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
LCDReset();
|
LCDReset();
|
||||||
break;
|
break;
|
||||||
case CMD_LCD:
|
case CMD_LCD:
|
||||||
LCDSend(packet->core.old.arg[0]);
|
LCDSend(packet->oldarg[0]);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case CMD_SETUP_WRITE:
|
case CMD_SETUP_WRITE:
|
||||||
|
@ -1501,7 +1498,7 @@ static void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
Dbprintf("%s: 0x%04x", "unknown command:", cmd);
|
Dbprintf("%s: 0x%04x", "unknown command:", packet->cmd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1567,6 +1564,7 @@ void __attribute__((noreturn)) AppMain(void) {
|
||||||
usb_enable();
|
usb_enable();
|
||||||
|
|
||||||
UsbCommandNG rx;
|
UsbCommandNG rx;
|
||||||
|
UsbCommandNGRaw rx_raw;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
|
@ -1574,28 +1572,36 @@ 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((uint8_t *)&rx, sizeof(UsbCommandNGPreamble));
|
size_t bytes = usb_read_ng((uint8_t *)&rx_raw.pre, sizeof(UsbCommandNGPreamble));
|
||||||
if (bytes == sizeof(UsbCommandNGPreamble)) {
|
if (bytes == sizeof(UsbCommandNGPreamble)) {
|
||||||
|
rx.magic = rx_raw.pre.magic;
|
||||||
|
rx.length = rx_raw.pre.length;
|
||||||
|
rx.cmd = rx_raw.pre.cmd;
|
||||||
if (rx.magic == USB_COMMANDNG_PREAMBLE_MAGIC) { // New style NG command
|
if (rx.magic == USB_COMMANDNG_PREAMBLE_MAGIC) { // New style NG command
|
||||||
if (rx.length > USB_CMD_DATA_SIZE) {
|
if (rx.length > USB_CMD_DATA_SIZE) {
|
||||||
Dbprintf("Packet frame with incompatible length: 0x%04x", rx.length);
|
Dbprintf("Packet frame with incompatible length: 0x%04x", rx.length);
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
if (!error) { // Get the core and variable length payload
|
if (!error) { // Get the core and variable length payload
|
||||||
bytes = usb_read_ng(((uint8_t *)&rx.core), sizeof(UsbPacketNGCore) - USB_CMD_DATA_SIZE + rx.length);
|
bytes = usb_read_ng(((uint8_t *)&rx_raw.data), rx.length);
|
||||||
if (bytes != sizeof(UsbPacketNGCore) - USB_CMD_DATA_SIZE + rx.length) {
|
if (bytes != rx.length) {
|
||||||
Dbprintf("Packet frame error variable part too short? %d/%d", bytes, rx.length);
|
Dbprintf("Packet frame error variable part too short? %d/%d", bytes, rx.length);
|
||||||
error = true;
|
error = true;
|
||||||
|
} else {
|
||||||
|
memcpy(&rx.data, &rx_raw.data, rx.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!error) { // Get the postamble
|
if (!error) { // Get the postamble
|
||||||
bytes = usb_read_ng(((uint8_t *)&rx.crc), sizeof(UsbCommandNGPostamble));
|
bytes = usb_read_ng(((uint8_t *)&rx_raw.foopost), 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;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (!error) { // Check CRC
|
||||||
|
rx.crc = rx_raw.foopost.crc;
|
||||||
uint8_t first, second;
|
uint8_t first, second;
|
||||||
compute_crc(CRC_14443_A, (uint8_t *)&rx, sizeof(UsbCommandNGPreamble) + sizeof(UsbPacketNGCore) - USB_CMD_DATA_SIZE + rx.length, &first, &second);
|
compute_crc(CRC_14443_A, (uint8_t *)&rx_raw, sizeof(UsbCommandNGPreamble) + rx.length, &first, &second);
|
||||||
if ((first << 8) + second != rx.crc) {
|
if ((first << 8) + second != rx.crc) {
|
||||||
Dbprintf("Packet frame CRC error %02X%02X <> %04X", first, second, rx.crc);
|
Dbprintf("Packet frame CRC error %02X%02X <> %04X", first, second, rx.crc);
|
||||||
error = true;
|
error = true;
|
||||||
|
@ -1609,13 +1615,9 @@ void __attribute__((noreturn)) AppMain(void) {
|
||||||
UsbPacketReceived(&rx);
|
UsbPacketReceived(&rx);
|
||||||
}
|
}
|
||||||
} else { // Old style command
|
} else { // Old style command
|
||||||
uint8_t tmp[sizeof(UsbCommandNGPreamble)];
|
UsbCommandOLD rx_old;
|
||||||
memcpy(tmp, &rx, sizeof(UsbCommandNGPreamble));
|
memcpy(&rx_old, &rx_raw.pre, sizeof(UsbCommandNGPreamble));
|
||||||
memcpy(&rx.core.old, tmp, sizeof(UsbCommandNGPreamble));
|
bytes = usb_read_ng(((uint8_t *)&rx_old) + sizeof(UsbCommandNGPreamble), sizeof(UsbCommandOLD) - sizeof(UsbCommandNGPreamble));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bytes = usb_read_ng(((uint8_t *)&rx.core.old) + sizeof(UsbCommandNGPreamble), sizeof(UsbCommandOLD) - sizeof(UsbCommandNGPreamble));
|
|
||||||
if (bytes != sizeof(UsbCommandOLD) - sizeof(UsbCommandNGPreamble)) {
|
if (bytes != sizeof(UsbCommandOLD) - sizeof(UsbCommandNGPreamble)) {
|
||||||
Dbprintf("Packet frame error var part too short? %d/%d", bytes, sizeof(UsbCommandOLD) - sizeof(UsbCommandNGPreamble));
|
Dbprintf("Packet frame error var part too short? %d/%d", bytes, sizeof(UsbCommandOLD) - sizeof(UsbCommandNGPreamble));
|
||||||
error = true;
|
error = true;
|
||||||
|
@ -1626,8 +1628,13 @@ void __attribute__((noreturn)) AppMain(void) {
|
||||||
#endif
|
#endif
|
||||||
rx.ng = false;
|
rx.ng = false;
|
||||||
rx.magic = 0;
|
rx.magic = 0;
|
||||||
rx.length = USB_CMD_DATA_SIZE;
|
|
||||||
rx.crc = 0;
|
rx.crc = 0;
|
||||||
|
rx.cmd = rx_old.cmd;
|
||||||
|
rx.oldarg[0] = rx_old.arg[0];
|
||||||
|
rx.oldarg[1] = rx_old.arg[1];
|
||||||
|
rx.oldarg[2] = rx_old.arg[2];
|
||||||
|
rx.length = USB_CMD_DATA_SIZE;
|
||||||
|
memcpy(&rx.data, &rx_old.d, rx.length);
|
||||||
UsbPacketReceived(&rx);
|
UsbPacketReceived(&rx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
18
armsrc/epa.c
18
armsrc/epa.c
|
@ -313,7 +313,7 @@ void EPA_PACE_Collect_Nonce(UsbCommandNG *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->core.old.arg[0];
|
uint8_t requested_size = (uint8_t)c->oldarg[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) {
|
||||||
|
@ -434,19 +434,19 @@ 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->core.old.arg[0] != 0) {
|
if (c->oldarg[0] != 0) {
|
||||||
// make sure it's not too big
|
// make sure it's not too big
|
||||||
if (c->core.old.arg[2] > apdus_replay[c->core.old.arg[0] - 1].len) {
|
if (c->oldarg[2] > apdus_replay[c->oldarg[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->core.old.arg[0] - 1].data + c->core.old.arg[1],
|
memcpy(apdus_replay[c->oldarg[0] - 1].data + c->oldarg[1],
|
||||||
c->core.old.d.asBytes,
|
c->data.asBytes,
|
||||||
c->core.old.arg[2]);
|
c->oldarg[2]);
|
||||||
// save/update APDU length
|
// save/update APDU length
|
||||||
if (c->core.old.arg[1] == 0) {
|
if (c->oldarg[1] == 0) {
|
||||||
apdu_lengths_replay[c->core.old.arg[0] - 1] = c->core.old.arg[2];
|
apdu_lengths_replay[c->oldarg[0] - 1] = c->oldarg[2];
|
||||||
} else {
|
} else {
|
||||||
apdu_lengths_replay[c->core.old.arg[0] - 1] += c->core.old.arg[2];
|
apdu_lengths_replay[c->oldarg[0] - 1] += c->oldarg[2];
|
||||||
}
|
}
|
||||||
cmd_send(CMD_ACK, 0, 0, 0, NULL, 0);
|
cmd_send(CMD_ACK, 0, 0, 0, NULL, 0);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -479,9 +479,9 @@ 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->core.old.arg[0];
|
felica_command_t param = c->oldarg[0];
|
||||||
size_t len = c->core.old.arg[1] & 0xffff;
|
size_t len = c->oldarg[1] & 0xffff;
|
||||||
uint8_t *cmd = c->core.old.d.asBytes;
|
uint8_t *cmd = c->data.asBytes;
|
||||||
uint32_t arg0;
|
uint32_t arg0;
|
||||||
|
|
||||||
felica_card_select_t card;
|
felica_card_select_t card;
|
||||||
|
|
|
@ -2351,11 +2351,11 @@ int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, u
|
||||||
// arg2 timeout
|
// arg2 timeout
|
||||||
// d.asBytes command bytes to send
|
// d.asBytes command bytes to send
|
||||||
void ReaderIso14443a(UsbCommandNG *c) {
|
void ReaderIso14443a(UsbCommandNG *c) {
|
||||||
iso14a_command_t param = c->core.old.arg[0];
|
iso14a_command_t param = c->oldarg[0];
|
||||||
size_t len = c->core.old.arg[1] & 0xffff;
|
size_t len = c->oldarg[1] & 0xffff;
|
||||||
size_t lenbits = c->core.old.arg[1] >> 16;
|
size_t lenbits = c->oldarg[1] >> 16;
|
||||||
uint32_t timeout = c->core.old.arg[2];
|
uint32_t timeout = c->oldarg[2];
|
||||||
uint8_t *cmd = c->core.old.d.asBytes;
|
uint8_t *cmd = c->data.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};
|
||||||
|
|
|
@ -1567,10 +1567,10 @@ void iso14b_set_trigger(bool enable) {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void SendRawCommand14443B_Ex(UsbCommandNG *c) {
|
void SendRawCommand14443B_Ex(UsbCommandNG *c) {
|
||||||
iso14b_command_t param = c->core.old.arg[0];
|
iso14b_command_t param = c->oldarg[0];
|
||||||
size_t len = c->core.old.arg[1] & 0xffff;
|
size_t len = c->oldarg[1] & 0xffff;
|
||||||
uint32_t timeout = c->core.old.arg[2];
|
uint32_t timeout = c->oldarg[2];
|
||||||
uint8_t *cmd = c->core.old.d.asBytes;
|
uint8_t *cmd = c->data.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};
|
||||||
|
|
|
@ -90,9 +90,9 @@ void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
|
|
||||||
//if ( len != sizeof(UsbCommand)) Fatal();
|
//if ( len != sizeof(UsbCommand)) Fatal();
|
||||||
|
|
||||||
uint32_t arg0 = (uint32_t)packet->core.old.arg[0];
|
uint32_t arg0 = (uint32_t)packet->oldarg[0];
|
||||||
|
|
||||||
switch (packet->core.old.cmd) {
|
switch (packet->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 |
|
||||||
|
@ -110,7 +110,7 @@ void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
*/
|
*/
|
||||||
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] = packet->core.old.d.asDwords[i];
|
p[i + arg0] = packet->data.asDwords[i];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
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] = packet->core.old.d.asDwords[i];
|
flash_mem[i] = packet->data.asDwords[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t flash_address = arg0 + (0x100 * j);
|
uint32_t flash_address = arg0 + (0x100 * j);
|
||||||
|
@ -154,7 +154,7 @@ void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_START_FLASH: {
|
case CMD_START_FLASH: {
|
||||||
if (packet->core.old.arg[2] == START_FLASH_MAGIC)
|
if (packet->oldarg[2] == START_FLASH_MAGIC)
|
||||||
bootrom_unlocked = 1;
|
bootrom_unlocked = 1;
|
||||||
else
|
else
|
||||||
bootrom_unlocked = 0;
|
bootrom_unlocked = 0;
|
||||||
|
@ -163,8 +163,8 @@ void UsbPacketReceived(UsbCommandNG *packet) {
|
||||||
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 = packet->core.old.arg[0];
|
int cmd_start = packet->oldarg[0];
|
||||||
int cmd_end = packet->core.old.arg[1];
|
int cmd_end = packet->oldarg[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.
|
||||||
|
|
|
@ -26,7 +26,7 @@ static pthread_t USB_communication_thread;
|
||||||
|
|
||||||
// Transmit buffer.
|
// Transmit buffer.
|
||||||
static UsbCommandOLD txBuffer;
|
static UsbCommandOLD txBuffer;
|
||||||
static UsbCommandNG txBufferNG;
|
static UsbCommandNGRaw 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;
|
||||||
|
@ -104,7 +104,7 @@ void SendCommandNG(uint16_t cmd, uint8_t *data, size_t len) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UsbCommandNGPostamble *tx_post = (UsbCommandNGPostamble *)((uint8_t *)&txBufferNG + sizeof(UsbCommandNGPreamble) + sizeof(UsbPacketNGCore) - USB_CMD_DATA_SIZE + len);
|
UsbCommandNGPostamble *tx_post = (UsbCommandNGPostamble *)((uint8_t *)&txBufferNG + sizeof(UsbCommandNGPreamble) + len);
|
||||||
|
|
||||||
pthread_mutex_lock(&txBufferMutex);
|
pthread_mutex_lock(&txBufferMutex);
|
||||||
/**
|
/**
|
||||||
|
@ -116,14 +116,14 @@ void SendCommandNG(uint16_t cmd, uint8_t *data, size_t len) {
|
||||||
pthread_cond_wait(&txBufferSig, &txBufferMutex);
|
pthread_cond_wait(&txBufferSig, &txBufferMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
txBufferNG.magic = USB_COMMANDNG_PREAMBLE_MAGIC;
|
txBufferNG.pre.magic = USB_COMMANDNG_PREAMBLE_MAGIC;
|
||||||
txBufferNG.length = len;
|
txBufferNG.pre.length = len;
|
||||||
txBufferNG.core.ng.cmd = cmd;
|
txBufferNG.pre.cmd = cmd;
|
||||||
memcpy(&txBufferNG.core.ng.data, data, len);
|
memcpy(&txBufferNG.data, data, len);
|
||||||
uint8_t first, second;
|
uint8_t first, second;
|
||||||
compute_crc(CRC_14443_A, (uint8_t *)&txBufferNG, sizeof(UsbCommandNGPreamble) + sizeof(UsbPacketNGCore) - USB_CMD_DATA_SIZE + len, &first, &second);
|
compute_crc(CRC_14443_A, (uint8_t *)&txBufferNG, sizeof(UsbCommandNGPreamble) + len, &first, &second);
|
||||||
tx_post->crc = (first << 8) + second;
|
tx_post->crc = (first << 8) + second;
|
||||||
txBufferNGLen = sizeof(UsbCommandNGPreamble) + sizeof(UsbPacketNGCore) - USB_CMD_DATA_SIZE + len + sizeof(UsbCommandNGPostamble);
|
txBufferNGLen = sizeof(UsbCommandNGPreamble) + 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
|
||||||
|
@ -311,13 +311,13 @@ __attribute__((force_align_arg_pointer))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!error) { // Get the postamble
|
if (!error) { // Get the postamble
|
||||||
if ((!uart_receive(sp, (uint8_t *)&rx_raw.post, sizeof(UsbReplyNGPostamble), &rxlen)) || (rxlen != sizeof(UsbReplyNGPostamble))) {
|
if ((!uart_receive(sp, (uint8_t *)&rx_raw.foopost, 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!error) { // Check CRC
|
if (!error) { // Check CRC
|
||||||
rx.crc = rx_raw.post.crc;
|
rx.crc = rx_raw.foopost.crc;
|
||||||
uint8_t first, second;
|
uint8_t first, second;
|
||||||
compute_crc(CRC_14443_A, (uint8_t *)&rx_raw, sizeof(UsbReplyNGPreamble) + rx.length, &first, &second);
|
compute_crc(CRC_14443_A, (uint8_t *)&rx_raw, sizeof(UsbReplyNGPreamble) + rx.length, &first, &second);
|
||||||
if ((first << 8) + second != rx.crc) {
|
if ((first << 8) + second != rx.crc) {
|
||||||
|
|
|
@ -35,14 +35,10 @@ typedef struct {
|
||||||
} d;
|
} d;
|
||||||
} PACKED UsbCommandOLD;
|
} PACKED UsbCommandOLD;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint16_t cmd;
|
|
||||||
uint8_t data[USB_CMD_DATA_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
|
||||||
|
@ -51,17 +47,27 @@ typedef struct {
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
} PACKED UsbCommandNGPostamble;
|
} PACKED UsbCommandNGPostamble;
|
||||||
|
|
||||||
|
// For internal usage
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t magic;
|
uint16_t cmd;
|
||||||
uint16_t length; // length of the variable part, 0 if none.
|
uint16_t length;
|
||||||
union { // we can simplify it once we get rid of old format compatibility
|
uint32_t magic; // NG
|
||||||
UsbPacketNGCore ng;
|
uint16_t crc; // NG
|
||||||
UsbCommandOLD old;
|
uint64_t oldarg[3]; // OLD
|
||||||
} core;
|
union {
|
||||||
uint16_t crc;
|
uint8_t asBytes[USB_CMD_DATA_SIZE];
|
||||||
bool ng;
|
uint32_t asDwords[USB_CMD_DATA_SIZE / 4];
|
||||||
|
} data;
|
||||||
|
bool ng; // does it store NG data or OLD data?
|
||||||
} PACKED UsbCommandNG;
|
} PACKED UsbCommandNG;
|
||||||
|
|
||||||
|
// For reception and CRC check
|
||||||
|
typedef struct {
|
||||||
|
UsbCommandNGPreamble pre;
|
||||||
|
uint8_t data[USB_CMD_DATA_SIZE];
|
||||||
|
UsbCommandNGPostamble foopost; // Probably not at that offset!
|
||||||
|
} PACKED UsbCommandNGRaw;
|
||||||
|
|
||||||
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.
|
||||||
|
@ -94,7 +100,7 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UsbReplyNGPreamble pre;
|
UsbReplyNGPreamble pre;
|
||||||
uint8_t data[USB_CMD_DATA_SIZE];
|
uint8_t data[USB_CMD_DATA_SIZE];
|
||||||
UsbReplyNGPostamble post;
|
UsbReplyNGPostamble foopost; // Probably not at that offset!
|
||||||
} PACKED UsbReplyNGRaw;
|
} PACKED UsbReplyNGRaw;
|
||||||
|
|
||||||
#ifdef WITH_FPC_HOST
|
#ifdef WITH_FPC_HOST
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue