Phase E - dismantle MIX functionality

This commit is contained in:
iceman1001
2026-08-29 16:50:29 +02:00
parent 07a0ff70db
commit 0f11c5c4d1
7 changed files with 9 additions and 48 deletions
+3 -2
View File
@@ -163,10 +163,11 @@ void RunMod(void) {
SpinDelay(500);
// Begin clone function here:
/* Example from client/mifarehost.c for commanding a block write for "magic Chinese" cards:
SendCommandMIX(CMD_HF_MIFARE_CSETBL, params & (0xFE | (uid == NULL ? 0:1)), blockNo, 0, data, 16);
SendCommandNG(CMD_HF_MIFARE_CSETBL, payload, sizeof(mf_chinese_blk_t) + 16);
where payload is mf_chinese_blk_t { u8 params, u8 blockno, u8 data[] }
Block read is similar:
SendCommandMIX(CMD_HF_MIFARE_CGETBL, params, blockNo, 0,...};
SendCommandNG(CMD_HF_MIFARE_CGETBL, payload, sizeof(mf_chinese_blk_t));
We need to imitate that call with blockNo 0 to set a uid.
The get and set commands are handled in this file:
-15
View File
@@ -157,21 +157,6 @@ int reply_ng(uint16_t cmd, int8_t status, const uint8_t *data, size_t len) {
return reply_ng_internal(cmd, status, PM3_REASON_UNKNOWN, data, len, true);
}
int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, const void *data, size_t len) {
int8_t status = PM3_SUCCESS;
uint64_t arg[3] = {arg0, arg1, arg2};
if (len > PM3_CMD_DATA_SIZE - sizeof(arg)) {
len = PM3_CMD_DATA_SIZE - sizeof(arg);
status = PM3_EOVFLOW;
}
uint8_t cmddata[PM3_CMD_DATA_SIZE];
memcpy(cmddata, arg, sizeof(arg));
if (len && data) {
memcpy(cmddata + sizeof(arg), data, (int)len);
}
return reply_ng_internal((cmd & 0xFFFF), status, PM3_REASON_UNKNOWN, cmddata, len + sizeof(arg), false);
}
int reply_reason(uint16_t cmd, int8_t status, int8_t reason, const uint8_t *data, size_t len) {
return reply_ng_internal(cmd, status, reason, data, len, true);
-1
View File
@@ -29,7 +29,6 @@ extern bool g_reply_via_usb;
int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, const void *data, size_t len);
int reply_ng(uint16_t cmd, int8_t status, const uint8_t *data, size_t len);
int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, const void *data, size_t len);
int reply_reason(uint16_t cmd, int8_t status, int8_t reason, const uint8_t *data, size_t len);
int receive_ng(PacketCommandNG *rx);
+1 -1
View File
@@ -112,7 +112,7 @@ void MifareSendCommand(uint8_t *datain) {
if (payload->flags & DISCONNECT)
OnSuccess();
//reply_mix(CMD_ACK, 1, len, 0, resp, len);
//reply_ng(CMD_HF_DESFIRE_COMMAND, PM3_SUCCESS, resp, len);
LED_B_ON();
+5 -27
View File
@@ -169,9 +169,9 @@ void SendCommandOLD(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, c
//__atomic_test_and_set(&txcmd_pending, __ATOMIC_SEQ_CST);
}
static void SendCommandNG_internal(uint16_t cmd, uint8_t *data, size_t len, bool ng) {
void SendCommandNG(uint16_t cmd, uint8_t *data, size_t len) {
#ifdef COMMS_DEBUG
PrintAndLogEx(INFO, "Sending %s", ng ? "NG" : "MIX");
PrintAndLogEx(INFO, "Sending NG");
#endif
if (!g_session.pm3_present) {
@@ -196,7 +196,7 @@ static void SendCommandNG_internal(uint16_t cmd, uint8_t *data, size_t len, bool
}
txBufferNG.pre.magic = COMMANDNG_PREAMBLE_MAGIC;
txBufferNG.pre.ng = ng;
txBufferNG.pre.ng = true;
txBufferNG.pre.length = len;
txBufferNG.pre.cmd = cmd;
if (len > 0 && data) {
@@ -215,12 +215,7 @@ static void SendCommandNG_internal(uint16_t cmd, uint8_t *data, size_t len, bool
#ifdef COMMS_DEBUG_RAW
print_hex_break((uint8_t *)&txBufferNG.pre, sizeof(PacketCommandNGPreamble), 32);
if (ng) {
print_hex_break((uint8_t *)&txBufferNG.data, len, 32);
} else {
print_hex_break((uint8_t *)&txBufferNG.data, 3 * sizeof(uint64_t), 32);
print_hex_break((uint8_t *)&txBufferNG.data + 3 * sizeof(uint64_t), len - 3 * sizeof(uint64_t), 32);
}
print_hex_break((uint8_t *)&txBufferNG.data, len, 32);
print_hex_break((uint8_t *)tx_post, sizeof(PacketCommandNGPostamble), 32);
#endif
txBuffer_pending = true;
@@ -237,23 +232,6 @@ static void SendCommandNG_internal(uint16_t cmd, uint8_t *data, size_t len, bool
//__atomic_test_and_set(&txcmd_pending, __ATOMIC_SEQ_CST);
}
void SendCommandNG(uint16_t cmd, uint8_t *data, size_t len) {
SendCommandNG_internal(cmd, data, len, true);
}
void SendCommandMIX(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, const void *data, size_t len) {
uint64_t arg[3] = {arg0, arg1, arg2};
if (len > PM3_CMD_DATA_SIZE_MIX) {
PrintAndLogEx(WARNING, "Sending " _RED_("%zu") " bytes of payload is too much for MIX frames, abort", len);
return;
}
uint8_t cmddata[PM3_CMD_DATA_SIZE];
memcpy(cmddata, arg, sizeof(arg));
if (len && data)
memcpy(cmddata + sizeof(arg), data, len);
SendCommandNG_internal(cmd, cmddata, len + sizeof(arg), false);
}
/**
* @brief This method should be called when sending a new command to the pm3. In case any old
@@ -1248,7 +1226,7 @@ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint3
return dl_it(dest, bytes, response, ms_timeout, show_warning, CMD_FLASHMEM_DOWNLOADED, CMD_FLASHMEM_DOWNLOAD);
}
case SIM_MEM: {
//SendCommandMIX(CMD_DOWNLOAD_SIM_MEM, start_index, bytes, 0, NULL, 0);
//SendCommandNG(CMD_DOWNLOAD_SIM_MEM, (uint8_t *)&req, sizeof(req));
//return dl_it(dest, bytes, response, ms_timeout, show_warning, CMD_DOWNLOADED_SIMMEM);
return false;
}
-1
View File
@@ -93,7 +93,6 @@ void *uart_receiver(void *targ);
void SendCommandBL(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
void SendCommandOLD(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, const void *data, size_t len);
void SendCommandNG(uint16_t cmd, uint8_t *data, size_t len);
void SendCommandMIX(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, const void *data, size_t len);
void clearCommandBuffer(void);
#define FLASHMODE_SPEED 460800
-1
View File
@@ -26,7 +26,6 @@
#define USART_SLOW_LINK
#define PM3_CMD_DATA_SIZE 512
#define PM3_CMD_DATA_SIZE_MIX (PM3_CMD_DATA_SIZE - 3 * sizeof(uint64_t))
typedef struct {
uint64_t cmd;