Merge remote-tracking branch 'upstream/master' into hf_mf_sim

This commit is contained in:
vratiskol
2019-03-25 15:51:21 +01:00
10 changed files with 41 additions and 41 deletions

View File

@@ -46,10 +46,6 @@ void legic_prng_forward(int count) {
}
}
uint32_t legic_prng_count() {
return lfsr.c;
}
uint8_t legic_prng_get_bit() {
uint8_t idx = 7 - ((lfsr.a & 4) | (lfsr.a >> 2 & 2) | (lfsr.a >> 4 & 1));
return lfsr.b >> idx & 1;

View File

@@ -57,7 +57,7 @@ extern void Dbprintf(const char *fmt, ...);
#include "ui.h"
# include "cmdparser.h"
# include "cmddata.h"
# define prnt PrintAndLog
# define prnt(args...) PrintAndLogEx(DEBUG, ## args );
#else
uint8_t g_debugMode = 0;
# define prnt Dbprintf
@@ -262,7 +262,8 @@ bool preambleSearch(uint8_t *bits, uint8_t *preamble, size_t pLen, size_t *size,
//(iceman) FINDONE, only finds start index. NOT SIZE!. I see Em410xDecode (lfdemod.c) uses SIZE to determine success
bool preambleSearchEx(uint8_t *bits, uint8_t *preamble, size_t pLen, size_t *size, size_t *startIdx, bool findone) {
// Sanity check. If preamble length is bigger than bits length.
if (*size <= pLen) return false;
if (*size <= pLen)
return false;
uint8_t foundCnt = 0;
for (size_t idx = 0; idx < *size - pLen; idx++) {
@@ -967,11 +968,6 @@ int DetectPSKClock(uint8_t *dest, size_t size, int clock, size_t *firstPhaseShif
uint8_t clk[] = {255, 16, 32, 40, 50, 64, 100, 128, 255}; //255 is not a valid clock
uint16_t loopCnt = 4096; //don't need to loop through entire array...
//if we already have a valid clock quit
size_t i = 1;
for (; i < 8; ++i)
if (clk[i] == clock) return clock;
if (size < 160 + 20) return 0;
// size must be larger than 20 here, and 160 later on.
if (size < loopCnt) loopCnt = size - 20;
@@ -995,7 +991,7 @@ int DetectPSKClock(uint8_t *dest, size_t size, int clock, size_t *firstPhaseShif
uint16_t peaksdet[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
//find start of modulating data in trace
i = findModStart(dest, size, *fc);
size_t i = findModStart(dest, size, *fc);
firstFullWave = pskFindFirstPhaseShift(dest, size, curPhase, i, *fc, &fullWaveLen);
if (firstFullWave == 0) {

View File

@@ -38,7 +38,7 @@ typedef struct {
} signal_t;
signal_t *getSignalProperties(void);
void computeSignalProperties(uint8_t *bits, uint32_t size);
void computeSignalProperties(uint8_t *samples, uint32_t size);
void removeSignalOffset(uint8_t *samples, uint32_t size);
void getNextLow(uint8_t *samples, size_t size, int low, size_t *i);
void getNextHigh(uint8_t *samples, size_t size, int high, size_t *i);
@@ -61,7 +61,7 @@ extern int DetectNRZClock(uint8_t *dest, size_t size, int clock, size_t *cl
extern int DetectPSKClock(uint8_t *dest, size_t size, int clock, size_t *firstPhaseShift, uint8_t *curPhase, uint8_t *fc);
extern int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clock);
extern bool DetectST(uint8_t *buffer, size_t *size, int *foundclock, size_t *ststart, size_t *stend);
extern size_t fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx);
extern size_t fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *start_idx);
//extern void getHiLo(uint8_t *bits, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo);
extern void getHiLo(int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo);
extern uint32_t manchesterEncode2Bytes(uint16_t datain);

View File

@@ -36,22 +36,22 @@ uint8_t checkParity(uint32_t bits, uint8_t len, uint8_t type);
// by marshmellow
// takes a array of binary values, start position, length of bits per parity (includes parity bit),
// Parity Type (1 for odd; 0 for even; 2 for Always 1's; 3 for Always 0's), and binary Length (length to run)
size_t removeParity(uint8_t *bitstream, size_t startIdx, uint8_t pLen, uint8_t pType, size_t bLen) {
size_t removeParity(uint8_t *bits, size_t startIdx, uint8_t pLen, uint8_t pType, size_t bLen) {
uint32_t parityWd = 0;
size_t j = 0, bitcount = 0;
for (int word = 0; word < (bLen); word += pLen) {
for (int bit = 0; bit < pLen; ++bit) {
parityWd = (parityWd << 1) | bitstream[startIdx + word + bit];
bitstream[j++] = (bitstream[startIdx + word + bit]);
parityWd = (parityWd << 1) | bits[startIdx + word + bit];
bits[j++] = (bits[startIdx + word + bit]);
}
j--; // overwrite parity with next data
// if parity fails then return 0
switch (pType) {
case 3:
if (bitstream[j] == 1) return 0;
if (bits[j] == 1) return 0;
break; //should be 0 spacer bit
case 2:
if (bitstream[j] == 0) return 0;
if (bits[j] == 0) return 0;
break; //should be 1 spacer bit
default: //test parity
if (parityTest(parityWd, pLen, pType) == 0) return 0;

View File

@@ -12,8 +12,8 @@
#include "common.h"
#include "util.h"
uint8_t getParity(uint8_t *bits, uint8_t length, uint8_t type);
uint8_t checkParity(uint32_t bits, uint8_t bitlen, uint8_t type);
uint8_t getParity(uint8_t *bits, uint8_t len, uint8_t type);
uint8_t checkParity(uint32_t bits, uint8_t len, uint8_t type);
void num_to_wiegand_bytes(uint64_t oem, uint64_t fc, uint64_t cn, uint8_t *dest, uint8_t formatlen);
void num_to_wiegand_bits(uint64_t oem, uint64_t fc, uint64_t cn, uint8_t *dest, uint8_t formatlen);