Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CMD_DOWNLOAD_BIGBUF for getSamples() and download_trace() #2477

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions armsrc/appmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion armsrc/lfsampling.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions client/src/cmddata.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);;
Expand Down
10 changes: 5 additions & 5 deletions client/src/cmdlf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions client/src/cmdlf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions client/src/cmdlffdxb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions client/src/cmdlfmotorola.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/cmdmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -125,7 +125,7 @@ static int lf_search_plus(const char *Cmd) {

}

lf_config(&oldconfig);
lf_setconfig(&oldconfig);
return retval;
}

Expand Down
1 change: 0 additions & 1 deletion client/src/scripting.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading