chg: adapted lfsampling, and swapped from 'silent' logic to the more natural 'verbose' logic

This commit is contained in:
iceman1001
2020-01-07 22:05:01 +01:00
parent a1d93567d2
commit f7156e7485
12 changed files with 236 additions and 166 deletions

View File

@@ -1589,7 +1589,7 @@ static uint8_t getByte(uint8_t bits_per_sample, BitstreamOut *b) {
return val;
}
int getSamples(uint32_t n, bool silent) {
int getSamples(uint32_t n, bool verbose) {
//If we get all but the last byte in bigbuf,
// we don't have to worry about remaining trash
// in the last byte in case the bits-per-sample
@@ -1599,7 +1599,7 @@ int getSamples(uint32_t n, bool silent) {
if (n == 0 || n > sizeof(got))
n = sizeof(got);
if (!silent) PrintAndLogEx(NORMAL, "Reading %d bytes from device memory\n", n);
if (verbose) PrintAndLogEx(NORMAL, "Reading %d bytes from device memory\n", n);
PacketResponseNG response;
if (!GetFromDevice(BIG_BUF, got, n, 0, NULL, 0, &response, 10000, true)) {
@@ -1607,20 +1607,20 @@ int getSamples(uint32_t n, bool silent) {
return PM3_ETIMEOUT;
}
if (!silent) PrintAndLogEx(NORMAL, "Data fetched");
if (verbose) PrintAndLogEx(NORMAL, "Data fetched");
uint8_t bits_per_sample = 8;
//Old devices without this feature would send 0 at arg[0]
if (response.oldarg[0] > 0) {
sample_config *sc = (sample_config *) response.data.asBytes;
if (!silent) PrintAndLogEx(NORMAL, "Samples @ %d bits/smpl, decimation 1:%d ", sc->bits_per_sample, sc->decimation);
if (verbose) PrintAndLogEx(NORMAL, "Samples @ %d bits/smpl, decimation 1:%d ", sc->bits_per_sample, sc->decimation);
bits_per_sample = sc->bits_per_sample;
}
if (bits_per_sample < 8) {
if (!silent) PrintAndLogEx(NORMAL, "Unpacking...");
if (verbose) PrintAndLogEx(NORMAL, "Unpacking...");
BitstreamOut bout = { got, bits_per_sample * n, 0};
int j = 0;
@@ -1630,7 +1630,7 @@ int getSamples(uint32_t n, bool silent) {
}
GraphTraceLen = j;
if (!silent) PrintAndLogEx(NORMAL, "Unpacked %d samples", j);
if (verbose) PrintAndLogEx(NORMAL, "Unpacked %d samples", j);
} else {
for (int j = 0; j < n; j++) {

View File

@@ -68,7 +68,7 @@ void setDemodBuff(uint8_t *buff, size_t size, size_t start_idx);
bool getDemodBuff(uint8_t *buff, size_t *size);
void save_restoreDB(uint8_t saveOpt);// option '1' to save DemodBuffer any other to restore
int AutoCorrelate(const int *in, int *out, size_t len, size_t window, bool SaveGrph, bool verbose);
int getSamples(uint32_t n, bool silent);
int getSamples(uint32_t n, bool verbose);
void setClockGrid(uint32_t clk, int offset);
int directionalThreshold(const int *in, int *out, size_t len, int8_t up, int8_t down);
int AskEdgeDetect(const int *in, int *out, int len, int threshold);

View File

@@ -633,7 +633,7 @@ static int CmdHF15Samples(const char *Cmd) {
clearCommandBuffer();
SendCommandNG(CMD_HF_ISO15693_ACQ_RAW_ADC, NULL, 0);
getSamples(0, false);
getSamples(0, true);
return PM3_SUCCESS;
}
@@ -684,9 +684,9 @@ static int NxpSysInfo(uint8_t *uid) {
return PM3_EWRONGANSVER;
}
bool support_signature = (recv[5] & 0x01);
bool support_signature = (recv[5] & 0x01);
bool support_easmode = (recv[4] & 0x03);
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, " NXP SYSINFO : %s", sprint_hex(recv, 8));
PrintAndLogEx(NORMAL, " Password protection configuration:");

View File

@@ -77,13 +77,13 @@ static int usage_lf_read(void) {
PrintAndLogEx(NORMAL, "Usage: lf read [h] [s] [d numofsamples]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help");
PrintAndLogEx(NORMAL, " s silent run, no printout");
PrintAndLogEx(NORMAL, " d #samples # samples to collect (optional)");
PrintAndLogEx(NORMAL, " s silent");
PrintAndLogEx(NORMAL, "Use 'lf config' to set parameters.");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " lf read s d 12000 - collects 12000samples silent");
PrintAndLogEx(NORMAL, " lf read s");
PrintAndLogEx(NORMAL, " lf read s d 12000 - collects 12000 samples silent");
PrintAndLogEx(NORMAL, " lf read");
return PM3_SUCCESS;
}
static int usage_lf_sim(void) {
@@ -367,7 +367,7 @@ int CmdLFCommandRead(const char *Cmd) {
if (resp.status == PM3_SUCCESS) {
if (i) {
PrintAndLogEx(SUCCESS, "Downloading response signal data");
getSamples(0, true);
getSamples(0, false);
return PM3_SUCCESS;
} else {
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
@@ -552,16 +552,16 @@ int CmdLFConfig(const char *Cmd) {
return lf_config(&config);
}
int lf_read(bool silent, uint32_t samples) {
int lf_read(bool verbose, uint32_t samples) {
if (!session.pm3_present) return PM3_ENOTTY;
struct p {
uint8_t silent;
uint8_t verbose;
uint32_t samples;
} PACKED;
struct p payload;
payload.silent = silent;
payload.verbose = verbose;
payload.samples = samples;
clearCommandBuffer();
@@ -579,7 +579,7 @@ int lf_read(bool silent, uint32_t samples) {
// resp.oldarg[0] is bits read not bytes read.
uint32_t bits = (resp.data.asDwords[0] / 8);
getSamples(bits, silent);
getSamples(bits, verbose);
return PM3_SUCCESS;
}
@@ -589,21 +589,21 @@ int CmdLFRead(const char *Cmd) {
if (!session.pm3_present) return PM3_ENOTTY;
bool errors = false;
bool silent = false;
bool verbose = true;
uint32_t samples = 0;
uint8_t cmdp = 0;
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch (tolower(param_getchar(Cmd, cmdp))) {
case 'h':
return usage_lf_read();
case 's':
silent = true;
cmdp++;
break;
case 'd':
samples = param_get32ex(Cmd, cmdp + 1, 0, 10);
cmdp += 2;
break;
case 's':
verbose = false;
cmdp++;
break;
default:
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
errors = true;
@@ -614,7 +614,7 @@ int CmdLFRead(const char *Cmd) {
//Validations
if (errors) return usage_lf_read();
return lf_read(silent, samples);
return lf_read(verbose, samples);
}
int CmdLFSniff(const char *Cmd) {
@@ -627,7 +627,7 @@ int CmdLFSniff(const char *Cmd) {
clearCommandBuffer();
SendCommandNG(CMD_LF_SNIFF_RAW_ADC, NULL, 0);
WaitForResponse(CMD_ACK, NULL);
getSamples(0, false);
getSamples(0, true);
return PM3_SUCCESS;
}
@@ -1183,7 +1183,7 @@ int CmdLFfind(const char *Cmd) {
bool isOnline = (session.pm3_present && (cmdp != '1'));
if (isOnline)
lf_read(true, 30000);
lf_read(false, 30000);
if (GraphTraceLen < minLength) {
PrintAndLogEx(FAILED, "Data in Graphbuffer was too small.");

View File

@@ -32,7 +32,7 @@ int CmdLFSniff(const char *Cmd);
int CmdVchDemod(const char *Cmd);
int CmdLFfind(const char *Cmd);
int lf_read(bool silent, uint32_t samples);
int lf_read(bool verbose, uint32_t samples);
int lf_config(sample_config *config);
#endif

View File

@@ -96,7 +96,7 @@ static int CmdCOTAGRead(const char *Cmd) {
case 2: {
CmdPlot("");
CmdGrid("384");
getSamples(0, true);
getSamples(0, false);
break;
}
case 1: {

View File

@@ -2528,7 +2528,7 @@ bool AcquireData(uint8_t page, uint8_t block, bool pwdmode, uint32_t password, u
return false;
}
getSamples(12000, true);
getSamples(12000, false);
return !getSignalProperties()->isnoise;
}
@@ -3485,7 +3485,7 @@ static int CmdT55xxDetectPage1(const char *Cmd) {
found = AcquireData(T55x7_PAGE1, T55x7_TRACE_BLOCK1, usepwd, password, dl_mode);
if (found == false)
continue;
if (tryDetectP1(false)) {
found = true;
found_mode = dl_mode;