mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 18:48:13 -07:00
CHG: some average / mean functions to enhance justNoise functions.
FIX: 'lf t55xx' - verifying that collected signal is not just noise..
This commit is contained in:
parent
d5a1e4c7d4
commit
6f948be842
5 changed files with 105 additions and 55 deletions
|
@ -60,26 +60,62 @@ void dummy(char *fmt, ...){}
|
|||
# define prnt dummy
|
||||
#endif
|
||||
|
||||
//test samples are not just noise
|
||||
uint8_t justNoise(uint8_t *bits, size_t size) {
|
||||
// Function to compute mean for a series
|
||||
// rounded to integer..
|
||||
uint32_t compute_mean_uint(uint8_t *in, size_t N) {
|
||||
uint32_t mean = 0;
|
||||
for (size_t i = 0; i < N; i++)
|
||||
mean += in[i];
|
||||
return (uint32_t)mean/N;
|
||||
}
|
||||
// Function to compute mean for a series
|
||||
// rounded to integer..
|
||||
int32_t compute_mean_int(int *in, size_t N) {
|
||||
int32_t mean = 0;
|
||||
for (size_t i = 0; i < N; i++)
|
||||
mean += in[i];
|
||||
return (int32_t)mean/N;
|
||||
}
|
||||
|
||||
//test samples are not just noise
|
||||
bool justNoise(uint8_t *bits, size_t size) {
|
||||
|
||||
// if we take the mean on the sample set and see if its
|
||||
// below the threshold, it will be a better indicator
|
||||
uint32_t mean = compute_mean_uint(bits, size);
|
||||
uint8_t counter = 0;
|
||||
for ( size_t i = 0; i < size && counter < 10; i++) {
|
||||
if ( bits[i] > mean ) counter++;
|
||||
}
|
||||
if (g_debugMode == 2) prnt("DEBUG: (justNoise) mean %u | %i | counter %u", mean, FSK_PSK_THRESHOLD, counter);
|
||||
return counter < 10;
|
||||
|
||||
/*
|
||||
// loop until a sample is larger than threshold.
|
||||
// one sample above threshold is not a good indicator.
|
||||
uint8_t val = 1;
|
||||
for(size_t idx = 0; idx < size && val; idx++)
|
||||
val = bits[idx] < FSK_PSK_THRESHOLD;
|
||||
return val;
|
||||
*/
|
||||
}
|
||||
|
||||
//by marshmellow
|
||||
//get high and low values of a wave with passed in fuzz factor. also return noise test = 1 for passed or 0 for only noise
|
||||
int getHiLo(uint8_t *BitStream, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo) {
|
||||
*high=0;
|
||||
*low=255;
|
||||
int getHiLo(uint8_t *bits, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo) {
|
||||
|
||||
*high = 0; *low = 255;
|
||||
|
||||
// get high and low thresholds
|
||||
for (size_t i=0; i < size; i++){
|
||||
if (BitStream[i] > *high) *high = BitStream[i];
|
||||
if (BitStream[i] < *low) *low = BitStream[i];
|
||||
if (bits[i] > *high) *high = bits[i];
|
||||
if (bits[i] < *low) *low = bits[i];
|
||||
}
|
||||
if (*high < FSK_PSK_THRESHOLD) return -1; // just noise
|
||||
|
||||
// just noise - no super good detection. good enough
|
||||
if (*high < FSK_PSK_THRESHOLD) return -1;
|
||||
|
||||
// add fuzz.
|
||||
*high = ((*high-128)*fuzzHi + 12800)/100;
|
||||
*low = ((*low-128)*fuzzLo + 12800)/100;
|
||||
return 1;
|
||||
|
@ -203,18 +239,18 @@ bool preambleSearchEx(uint8_t *BitStream, uint8_t *preamble, size_t pLen, size_t
|
|||
}
|
||||
|
||||
// find start of modulating data (for fsk and psk) in case of beginning noise or slow chip startup.
|
||||
size_t findModStart(uint8_t dest[], size_t size, uint8_t expWaveSize) {
|
||||
size_t findModStart(uint8_t *src, size_t size, uint8_t expWaveSize) {
|
||||
size_t i = 0;
|
||||
size_t waveSizeCnt = 0;
|
||||
uint8_t thresholdCnt = 0;
|
||||
bool isAboveThreshold = dest[i++] >= FSK_PSK_THRESHOLD;
|
||||
bool isAboveThreshold = src[i++] >= FSK_PSK_THRESHOLD;
|
||||
for (; i < size-20; i++ ) {
|
||||
if(dest[i] < FSK_PSK_THRESHOLD && isAboveThreshold) {
|
||||
if(src[i] < FSK_PSK_THRESHOLD && isAboveThreshold) {
|
||||
thresholdCnt++;
|
||||
if (thresholdCnt > 2 && waveSizeCnt < expWaveSize+1) break;
|
||||
isAboveThreshold = false;
|
||||
waveSizeCnt = 0;
|
||||
} else if (dest[i] >= FSK_PSK_THRESHOLD && !isAboveThreshold) {
|
||||
} else if (src[i] >= FSK_PSK_THRESHOLD && !isAboveThreshold) {
|
||||
thresholdCnt++;
|
||||
if (thresholdCnt > 2 && waveSizeCnt < expWaveSize+1) break;
|
||||
isAboveThreshold = true;
|
||||
|
@ -224,7 +260,7 @@ size_t findModStart(uint8_t dest[], size_t size, uint8_t expWaveSize) {
|
|||
}
|
||||
if (thresholdCnt > 10) break;
|
||||
}
|
||||
if (g_debugMode == 2) prnt("DEBUG: threshold Count reached at %u, count: %u",i, thresholdCnt);
|
||||
if (g_debugMode == 2) prnt("DEBUG: threshold Count reached at %u, count: %u", i, thresholdCnt);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -1441,7 +1477,7 @@ size_t fsk_wave_demod(uint8_t * dest, size_t size, uint8_t fchigh, uint8_t fclow
|
|||
size_t last_transition = 0;
|
||||
size_t idx = 1;
|
||||
|
||||
//find start of modulating data in trace
|
||||
//find start of modulating data in trace
|
||||
idx = findModStart(dest, size, fchigh);
|
||||
// Need to threshold first sample
|
||||
if(dest[idx] < FSK_PSK_THRESHOLD) dest[0] = 0;
|
||||
|
@ -1769,8 +1805,8 @@ int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32
|
|||
if (dest[idx] == dest[idx+1]){
|
||||
return -5; //not manchester data
|
||||
}
|
||||
*hi2 = (*hi2<<1)|(*hi>>31);
|
||||
*hi = (*hi<<1)|(*lo>>31);
|
||||
*hi2 = (*hi2 << 1) | (*hi >> 31);
|
||||
*hi = (*hi << 1) | (*lo >> 31);
|
||||
//Then, shift in a 0 or one into low
|
||||
*lo <<= 1;
|
||||
if (dest[idx] && !dest[idx+1]) // 1 0
|
||||
|
|
|
@ -21,7 +21,10 @@
|
|||
#include "parity.h" // for parity test
|
||||
|
||||
//generic
|
||||
extern uint8_t justNoise(uint8_t *bits, size_t size);
|
||||
extern uint32_t compute_mean_uint(uint8_t *in, size_t N);
|
||||
extern int32_t compute_mean_int(int *in, size_t N);
|
||||
|
||||
extern bool justNoise(uint8_t *bits, size_t size);
|
||||
extern size_t addParity(uint8_t *BitSource, uint8_t *dest, uint8_t sourceLen, uint8_t pLen, uint8_t pType);
|
||||
extern int askdemod(uint8_t *BinStream, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType);
|
||||
extern int askdemod_ext(uint8_t *BinStream, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType, int *startIdx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue