mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2026-05-12 11:18:11 -07:00
CMD_HF_DECAY: factor with structs, remove cast align warning
This commit is contained in:
+5
-15
@@ -262,27 +262,17 @@ static uint32_t MeasureAntennaTuningLfData(void) {
|
||||
|
||||
// Measure HF antenna decay after field-off.
|
||||
// Captures peak-detect capacitor discharge curve via burst ADC sampling.
|
||||
static void MeasureAntennaTuningHfDecay(const uint8_t *params, uint16_t params_len) {
|
||||
static void MeasureAntennaTuningHfDecay(const hf_decay_params_t *params) {
|
||||
|
||||
// Parse parameters with defaults
|
||||
uint16_t stabilize_ms = 50;
|
||||
uint16_t measure_us = 2000;
|
||||
uint16_t stabilize_ms = params->stabilize_ms;
|
||||
uint16_t measure_us = params->measure_us;
|
||||
|
||||
if (params_len >= 4) {
|
||||
stabilize_ms = params[0] | (params[1] << 8);
|
||||
measure_us = params[2] | (params[3] << 8);
|
||||
}
|
||||
if (stabilize_ms == 0) stabilize_ms = 50;
|
||||
if (measure_us == 0) measure_us = 2000;
|
||||
|
||||
// Response: 8-byte header + up to 252 uint16_t samples = 512 bytes max
|
||||
struct {
|
||||
uint16_t baseline_mv;
|
||||
uint16_t num_samples;
|
||||
uint16_t sample_interval_us;
|
||||
uint16_t measure_window_us;
|
||||
uint16_t samples_mv[252];
|
||||
} PACKED payload;
|
||||
hf_decay_response_t payload;
|
||||
memset(&payload, 0, sizeof(payload));
|
||||
|
||||
LED_B_ON();
|
||||
@@ -2644,7 +2634,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
break;
|
||||
}
|
||||
case CMD_HF_DECAY: {
|
||||
MeasureAntennaTuningHfDecay(packet->data.asBytes, packet->length);
|
||||
MeasureAntennaTuningHfDecay((const hf_decay_params_t *)packet->data.asBytes);
|
||||
break;
|
||||
}
|
||||
case CMD_MEASURE_ANTENNA_TUNING_LF: {
|
||||
|
||||
+31
-63
@@ -897,16 +897,9 @@ static int CmdDecay(const char *Cmd) {
|
||||
CLIParserFree(ctx);
|
||||
|
||||
// Build parameter packet
|
||||
struct {
|
||||
uint16_t stabilize_ms;
|
||||
uint16_t measure_us;
|
||||
uint8_t num_pulses;
|
||||
uint8_t padding[3];
|
||||
} PACKED params = {
|
||||
hf_decay_params_t decay_params = {
|
||||
.stabilize_ms = stabilize_ms,
|
||||
.measure_us = measure_us,
|
||||
.num_pulses = 1,
|
||||
.padding = {0}
|
||||
};
|
||||
|
||||
PrintAndLogEx(INFO, "Measuring HF antenna decay...");
|
||||
@@ -914,7 +907,7 @@ static int CmdDecay(const char *Cmd) {
|
||||
PrintAndLogEx(INFO, " Measurement window: " _YELLOW_("%d") " us", measure_us);
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_DECAY, (uint8_t *)¶ms, sizeof(params));
|
||||
SendCommandNG(CMD_HF_DECAY, (uint8_t *)&decay_params, sizeof(decay_params));
|
||||
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_HF_DECAY, &resp, 5000) == false) {
|
||||
@@ -928,11 +921,13 @@ static int CmdDecay(const char *Cmd) {
|
||||
}
|
||||
|
||||
// Parse response header
|
||||
uint16_t baseline_mv = resp.data.asBytes[0] | (resp.data.asBytes[1] << 8);
|
||||
uint16_t num_samples = resp.data.asBytes[2] | (resp.data.asBytes[3] << 8);
|
||||
uint16_t sample_interval_us = resp.data.asBytes[4] | (resp.data.asBytes[5] << 8);
|
||||
uint16_t measure_window_us = resp.data.asBytes[6] | (resp.data.asBytes[7] << 8);
|
||||
uint16_t *samples = (uint16_t *)(resp.data.asBytes + 8);
|
||||
hf_decay_response_t *decay_resp = (hf_decay_response_t *)resp.data.asBytes;
|
||||
uint16_t baseline_mv = decay_resp->baseline_mv;
|
||||
uint16_t num_samples = decay_resp->num_samples;
|
||||
uint16_t sample_interval_us = decay_resp->sample_interval_us;
|
||||
uint16_t measure_window_us = decay_resp->measure_window_us;
|
||||
uint16_t samples[num_samples];
|
||||
memcpy(samples, decay_resp->samples_mv, num_samples * sizeof(uint16_t));
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "-------- " _CYAN_("HF Decay Measurement") " ----------");
|
||||
@@ -1180,29 +1175,22 @@ static int CmdTune(const char *Cmd) {
|
||||
// 50-500 (rapid discharge). Without a booster, it reads >1000.
|
||||
bool hf_booster_detected = false;
|
||||
if (!IfPm3Rdv4Fw() && package->v_hf < HF_MARGINAL_V) {
|
||||
struct {
|
||||
uint16_t stabilize_ms;
|
||||
uint16_t measure_us;
|
||||
uint8_t num_pulses;
|
||||
uint8_t padding[3];
|
||||
} PACKED decay_params = {
|
||||
hf_decay_params_t decay_params = {
|
||||
.stabilize_ms = 50,
|
||||
.measure_us = 50,
|
||||
.num_pulses = 1,
|
||||
.padding = {0}
|
||||
};
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_DECAY, (uint8_t *)&decay_params, sizeof(decay_params));
|
||||
|
||||
PacketResponseNG decay_resp;
|
||||
if (WaitForResponseTimeout(CMD_HF_DECAY, &decay_resp, 3000) && decay_resp.status == PM3_SUCCESS) {
|
||||
|
||||
uint16_t decay_num = decay_resp.data.asBytes[2] | (decay_resp.data.asBytes[3] << 8);
|
||||
uint16_t *decay_samples = (uint16_t *)(decay_resp.data.asBytes + 8);
|
||||
|
||||
if (decay_num > 0 && decay_samples[0] >= 50 && decay_samples[0] <= 500) {
|
||||
hf_booster_detected = true;
|
||||
if (WaitForResponseTimeout(CMD_HF_DECAY, &resp, 3000) && resp.status == PM3_SUCCESS) {
|
||||
hf_decay_response_t *decay_resp = (hf_decay_response_t *)resp.data.asBytes;
|
||||
if (decay_resp->num_samples > 0) {
|
||||
uint16_t samples[1];
|
||||
memcpy(samples, decay_resp->samples_mv, sizeof(uint16_t));
|
||||
if (samples[0] >= 50 && samples[0] <= 500) {
|
||||
hf_booster_detected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1240,45 +1228,25 @@ static int CmdTune(const char *Cmd) {
|
||||
// surface interference via decay measurement.
|
||||
// Only on PM3 Easy — RDV4 has different voltage divider.
|
||||
if (!IfPm3Rdv4Fw() && package->v_hf >= HF_MARGINAL_V && package->v_hf < 13000) {
|
||||
|
||||
struct {
|
||||
uint16_t stabilize_ms;
|
||||
uint16_t measure_us;
|
||||
uint8_t num_pulses;
|
||||
uint8_t padding[3];
|
||||
} PACKED surface_params = {
|
||||
hf_decay_params_t surface_params = {
|
||||
.stabilize_ms = 50,
|
||||
.measure_us = 50,
|
||||
.num_pulses = 1,
|
||||
.padding = {0}
|
||||
};
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_DECAY,
|
||||
(uint8_t *)&surface_params,
|
||||
sizeof(surface_params));
|
||||
SendCommandNG(CMD_HF_DECAY, (uint8_t *)&surface_params, sizeof(surface_params));
|
||||
|
||||
PacketResponseNG surface_resp;
|
||||
if (WaitForResponseTimeout(
|
||||
CMD_HF_DECAY,
|
||||
&surface_resp, 3000) &&
|
||||
surface_resp.status == PM3_SUCCESS) {
|
||||
|
||||
uint16_t sn = surface_resp.data.asBytes[2] | (surface_resp.data.asBytes[3] << 8);
|
||||
uint16_t *ss =
|
||||
(uint16_t *)(surface_resp.data.asBytes + 8);
|
||||
|
||||
if (sn > 0 && ss[0] >= 600 && ss[0] <= 900) {
|
||||
PrintAndLogEx(SUCCESS, "");
|
||||
PrintAndLogEx(SUCCESS,
|
||||
"The surface your proxmark"
|
||||
" is on could");
|
||||
PrintAndLogEx(SUCCESS,
|
||||
"contain interfering"
|
||||
" materials. Try again");
|
||||
PrintAndLogEx(SUCCESS,
|
||||
"while holding the"
|
||||
" proxmark in free space.");
|
||||
if (WaitForResponseTimeout(CMD_HF_DECAY, &resp, 3000) && resp.status == PM3_SUCCESS) {
|
||||
hf_decay_response_t *surface_resp = (hf_decay_response_t *)resp.data.asBytes;
|
||||
if (surface_resp->num_samples > 0) {
|
||||
uint16_t samples[1];
|
||||
memcpy(samples, surface_resp->samples_mv, sizeof(uint16_t));
|
||||
if (samples[0] >= 600 && samples[0] <= 900) {
|
||||
PrintAndLogEx(SUCCESS, "");
|
||||
PrintAndLogEx(SUCCESS, "The surface your proxmark is on could");
|
||||
PrintAndLogEx(SUCCESS, "contain interfering materials. Try again");
|
||||
PrintAndLogEx(SUCCESS, "while holding the proxmark in free space.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,6 +247,20 @@ typedef struct {
|
||||
#define CAPABILITIES_VERSION 7
|
||||
extern capabilities_t g_pm3_capabilities;
|
||||
|
||||
typedef struct {
|
||||
uint16_t stabilize_ms;
|
||||
uint16_t measure_us;
|
||||
// uint8_t num_pulses;
|
||||
} PACKED hf_decay_params_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t baseline_mv;
|
||||
uint16_t num_samples;
|
||||
uint16_t sample_interval_us;
|
||||
uint16_t measure_window_us;
|
||||
uint16_t samples_mv[252];
|
||||
} PACKED hf_decay_response_t;
|
||||
|
||||
// For CMD_LF_T55XX_WRITEBL
|
||||
typedef struct {
|
||||
uint32_t data;
|
||||
|
||||
Reference in New Issue
Block a user