Use struct for parameter passing in CMD_HF_ISO14443A_SET_THRESHOLDS

This commit is contained in:
Christian Zietz 2024-02-03 11:59:49 +01:00
commit c1b23a761c
2 changed files with 19 additions and 7 deletions

View file

@ -1561,9 +1561,15 @@ static void PacketReceived(PacketCommandNG *packet) {
break;
}
case CMD_HF_ISO14443A_SET_THRESHOLDS: {
struct p {
uint8_t threshold;
uint8_t threshold_high;
uint8_t legic_threshold;
} PACKED;
struct p *payload = (struct p *) packet->data.asBytes;
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
FpgaSendCommand(FPGA_CMD_SET_EDGE_DETECT_THRESHOLD, (packet->data.asBytes[0] & 0x3f) | ((packet->data.asBytes[1] & 0x3f) << 6));
LegicRfSetThreshold((uint32_t)packet->data.asBytes[2]);
FpgaSendCommand(FPGA_CMD_SET_EDGE_DETECT_THRESHOLD, (payload->threshold & 0x3f) | ((payload->threshold_high & 0x3f) << 6));
LegicRfSetThreshold((uint32_t)payload->legic_threshold);
break;
}
case CMD_HF_ISO14443A_SNIFF: {

View file

@ -759,13 +759,19 @@ static int CmdSetHFThreshold(const char *Cmd) {
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
uint8_t params[3];
params[0] = arg_get_int_def(ctx, 1, 7);
params[1] = arg_get_int_def(ctx, 2, 20);
params[2] = arg_get_int_def(ctx, 3, 8);
struct {
uint8_t threshold;
uint8_t threshold_high;
uint8_t legic_threshold;
} PACKED params;
params.threshold = arg_get_int_def(ctx, 1, 7);
params.threshold_high = arg_get_int_def(ctx, 2, 20);
params.legic_threshold = arg_get_int_def(ctx, 3, 8);
CLIParserFree(ctx);
if ((params[0] < 1) || (params[0] > 63) || (params[1] < 1) || (params[1] > 63)) {
if ((params.threshold < 1) || (params.threshold > 63) || (params.threshold_high < 1) || (params.threshold_high > 63)) {
PrintAndLogEx(ERR, "Thresholds must be between " _YELLOW_("1") " and " _YELLOW_("63"));
return PM3_EINVARG;
}