Merge pull request #2477 from douniwan5788/lf_config

fix: CMD_DOWNLOAD_BIGBUF for getSamples() and download_trace()
This commit is contained in:
Iceman 2024-08-28 08:06:14 +02:00 committed by GitHub
commit af73ad2f9e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 26 additions and 26 deletions

View file

@ -2391,15 +2391,15 @@ static void PacketReceived(PacketCommandNG *packet) {
// arg2 = BigBuf tracelen
//Dbprintf("transfer to client parameters: %" PRIu32 " | %" PRIu32 " | %" PRIu32, startidx, numofbytes, packet->oldarg[2]);
for (size_t i = 0; i < numofbytes; i += PM3_CMD_DATA_SIZE) {
size_t len = MIN((numofbytes - i), PM3_CMD_DATA_SIZE);
int result = reply_old(CMD_DOWNLOADED_BIGBUF, i, len, BigBuf_get_traceLen(), mem + startidx + i, len);
for (size_t offset = 0; offset < numofbytes; offset += PM3_CMD_DATA_SIZE) {
size_t len = MIN((numofbytes - offset), PM3_CMD_DATA_SIZE);
int result = reply_old(CMD_DOWNLOADED_BIGBUF, offset, len, BigBuf_get_traceLen(), &mem[startidx + offset], len);
if (result != PM3_SUCCESS)
Dbprintf("transfer to client failed :: | bytes between %d - %d (%d) | result: %d", i, i + len, len, result);
Dbprintf("transfer to client failed :: | bytes between %d - %d (%d) | result: %d", offset, offset + len, len, result);
}
// Trigger a finish downloading signal with an ACK frame
// arg0 = status of download transfer
reply_mix(CMD_ACK, 1, 0, 0, 0, 0);
reply_mix(CMD_ACK, 1, 0, BigBuf_get_traceLen(), NULL, 0);
LED_B_OFF();
break;
}

View file

@ -40,7 +40,7 @@ Default LF config is set to:
verbose = YES
*/
static sample_config def_config = {
static const sample_config def_config = {
.decimation = 1,
.bits_per_sample = 8,
.averaging = 1,

View file

@ -29,6 +29,7 @@
#include "graph.h" // for graph data
#include "comms.h"
#include "lfdemod.h" // for demod code
#include "cmdlf.h" // for lf_getconfig
#include "loclass/cipherutils.h" // for decimating samples in getsamples
#include "cmdlfem410x.h" // askem410xdecode
#include "fileutils.h" // searchFile
@ -1875,13 +1876,13 @@ int getSamplesEx(uint32_t start, uint32_t end, bool verbose, bool ignore_lf_conf
uint8_t bits_per_sample = 8;
// Old devices without this feature would send 0 at arg[0]
if (resp.oldarg[0] > 0 && (ignore_lf_config == false)) {
sample_config *sc = (sample_config *) resp.data.asBytes;
if (IfPm3Lf() && ignore_lf_config == false) {
sample_config sc;
lf_getconfig(&sc);
if (verbose) {
PrintAndLogEx(INFO, "Samples @ " _YELLOW_("%d") " bits/smpl, decimation 1:%d ", sc->bits_per_sample, sc->decimation);
PrintAndLogEx(INFO, "Samples @ " _YELLOW_("%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;
}
return getSamplesFromBufEx(got, n, bits_per_sample, verbose);;

View file

@ -541,7 +541,7 @@ int CmdFlexdemod(const char *Cmd) {
* this function will save a copy of the current lf config value, and set config to default values.
*
*/
int lf_config_savereset(sample_config *config) {
int lf_resetconfig(sample_config *config) {
if (config == NULL) {
return PM3_EINVARG;
@ -565,7 +565,7 @@ int lf_config_savereset(sample_config *config) {
.verbose = false,
};
res = lf_config(&def_config);
res = lf_setconfig(&def_config);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "failed to reset LF configuration to default values");
return res;
@ -595,7 +595,7 @@ int lf_getconfig(sample_config *config) {
return PM3_SUCCESS;
}
int lf_config(sample_config *config) {
int lf_setconfig(sample_config *config) {
if (!g_session.pm3_present) return PM3_ENOTTY;
clearCommandBuffer();
@ -656,7 +656,7 @@ int CmdLFConfig(const char *Cmd) {
// if called with no params, just print the device config
if (strlen(Cmd) == 0) {
return lf_config(NULL);
return lf_setconfig(NULL);
}
if (use_125 + use_134 > 1) {
@ -729,7 +729,7 @@ int CmdLFConfig(const char *Cmd) {
config.trigger_threshold = 0;
}
return lf_config(&config);
return lf_setconfig(&config);
}
static int lf_read_internal(bool realtime, bool verbose, uint64_t samples) {

View file

@ -42,10 +42,10 @@ int CmdLFfind(const char *Cmd);
int lf_read(bool verbose, uint64_t samples);
int lf_sniff(bool realtime, bool verbose, uint64_t samples);
int lf_config(sample_config *config);
int lf_setconfig(sample_config *config);
int lf_getconfig(sample_config *config);
int lf_resetconfig(sample_config *config);
int lfsim_upload_gb(void);
int lfsim_wait_check(uint32_t cmd);
int lf_config_savereset(sample_config *config);
#endif

View file

@ -671,14 +671,14 @@ static int CmdFdxBReader(const char *Cmd) {
if (curr_div == LF_DIVISOR_125) {
config.divisor = LF_DIVISOR_134;
res = lf_config(&config);
res = lf_setconfig(&config);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "failed to change to 134 KHz LF configuration");
return res;
}
} else {
config.divisor = LF_DIVISOR_125;
res = lf_config(&config);
res = lf_setconfig(&config);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "failed to change to 125 KHz LF configuration");
return res;
@ -694,7 +694,7 @@ static int CmdFdxBReader(const char *Cmd) {
if (old_div != curr_div) {
config.divisor = old_div;
res = lf_config(&config);
res = lf_setconfig(&config);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "failed to restore LF configuration");
return res;

View file

@ -172,7 +172,7 @@ static int CmdMotorolaReader(const char *Cmd) {
.samples_to_skip = 4500,
.verbose = false
};
lf_config(&sc);
lf_setconfig(&sc);
int res;
do {
@ -184,7 +184,7 @@ static int CmdMotorolaReader(const char *Cmd) {
// reset back to 125 kHz
sc.divisor = LF_DIVISOR_125;
sc.samples_to_skip = 0;
lf_config(&sc);
lf_setconfig(&sc);
return res;
}

View file

@ -114,7 +114,7 @@ static int lf_search_plus(const char *Cmd) {
d = config.divisor = default_divisor[i];
PrintAndLogEx(INFO, "--> trying ( " _GREEN_("%d.%02d kHz")" )", 12000 / (d + 1), ((1200000 + (d + 1) / 2) / (d + 1)) - ((12000 / (d + 1)) * 100));
retval = lf_config(&config);
retval = lf_setconfig(&config);
if (retval != PM3_SUCCESS)
break;
@ -125,7 +125,7 @@ static int lf_search_plus(const char *Cmd) {
}
lf_config(&oldconfig);
lf_setconfig(&oldconfig);
return retval;
}

View file

@ -41,7 +41,6 @@
#include "crc16.h"
#include "protocols.h"
#include "fileutils.h" // searchfile
#include "cmdlf.h" // lf_config
#include "generator.h"
#include "cmdlfem4x05.h" // read 4305
#include "cmdlfem4x50.h" // read 4350