mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-23 14:45:37 -07:00
changing {} style to match majority of previous style
This commit is contained in:
parent
da6cdf014b
commit
961d929f4d
320 changed files with 5502 additions and 10485 deletions
166
common/lfdemod.c
166
common/lfdemod.c
|
@ -64,13 +64,11 @@ uint8_t g_debugMode = 0;
|
|||
#endif
|
||||
|
||||
signal_t signalprop = { 255, -255, 0, 0, true };
|
||||
signal_t *getSignalProperties(void)
|
||||
{
|
||||
signal_t *getSignalProperties(void) {
|
||||
return &signalprop;
|
||||
}
|
||||
|
||||
static void resetSignal(void)
|
||||
{
|
||||
static void resetSignal(void) {
|
||||
signalprop.low = 255;
|
||||
signalprop.high = -255;
|
||||
signalprop.mean = 0;
|
||||
|
@ -78,8 +76,7 @@ static void resetSignal(void)
|
|||
signalprop.isnoise = true;
|
||||
}
|
||||
|
||||
static void printSignal(void)
|
||||
{
|
||||
static void printSignal(void) {
|
||||
prnt("LF signal properties:");
|
||||
prnt(" high..........%d", signalprop.high);
|
||||
prnt(" low...........%d", signalprop.low);
|
||||
|
@ -89,8 +86,7 @@ static void printSignal(void)
|
|||
prnt(" THRESHOLD noise amplitude......%d", NOISE_AMPLITUDE_THRESHOLD);
|
||||
}
|
||||
|
||||
void computeSignalProperties(uint8_t *samples, uint32_t size)
|
||||
{
|
||||
void computeSignalProperties(uint8_t *samples, uint32_t size) {
|
||||
resetSignal();
|
||||
|
||||
uint32_t sum = 0;
|
||||
|
@ -111,8 +107,7 @@ void computeSignalProperties(uint8_t *samples, uint32_t size)
|
|||
printSignal();
|
||||
}
|
||||
|
||||
void removeSignalOffset(uint8_t *samples, uint32_t size)
|
||||
{
|
||||
void removeSignalOffset(uint8_t *samples, uint32_t size) {
|
||||
if (samples == NULL || size < SIGNAL_MIN_SAMPLES) return;
|
||||
|
||||
int acc_off = 0;
|
||||
|
@ -134,8 +129,7 @@ void removeSignalOffset(uint8_t *samples, uint32_t size)
|
|||
//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
|
||||
//void getHiLo(uint8_t *bits, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo) {
|
||||
void getHiLo(int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo)
|
||||
{
|
||||
void getHiLo(int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo) {
|
||||
// add fuzz.
|
||||
*high = (signalprop.high * fuzzHi) / 100;
|
||||
if (signalprop.low < 0) {
|
||||
|
@ -159,16 +153,14 @@ void getHiLo(int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo)
|
|||
// by marshmellow
|
||||
// pass bits to be tested in bits, length bits passed in bitLen, and parity type (even=0 | odd=1) in pType
|
||||
// returns 1 if passed
|
||||
bool parityTest(uint32_t bits, uint8_t bitLen, uint8_t pType)
|
||||
{
|
||||
bool parityTest(uint32_t bits, uint8_t bitLen, uint8_t pType) {
|
||||
return oddparity32(bits) ^ pType;
|
||||
}
|
||||
|
||||
//by marshmellow
|
||||
// takes a array of binary values, start position, length of bits per parity (includes parity bit - MAX 32),
|
||||
// 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 *bits, 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 bitCnt = 0;
|
||||
for (int word = 0; word < (bLen); word += pLen) {
|
||||
|
@ -203,8 +195,7 @@ size_t removeParity(uint8_t *bits, size_t startIdx, uint8_t pLen, uint8_t pType,
|
|||
// takes a array of binary values, length of bits per parity (includes parity bit),
|
||||
// Parity Type (1 for odd; 0 for even; 2 Always 1's; 3 Always 0's), and binary Length (length to run)
|
||||
// Make sure *dest is long enough to store original sourceLen + #_of_parities_to_be_added
|
||||
size_t addParity(uint8_t *src, uint8_t *dest, uint8_t sourceLen, uint8_t pLen, uint8_t pType)
|
||||
{
|
||||
size_t addParity(uint8_t *src, uint8_t *dest, uint8_t sourceLen, uint8_t pLen, uint8_t pType) {
|
||||
uint32_t parityWd = 0;
|
||||
size_t j = 0, bitCnt = 0;
|
||||
for (int word = 0; word < sourceLen; word += pLen - 1) {
|
||||
|
@ -233,8 +224,7 @@ size_t addParity(uint8_t *src, uint8_t *dest, uint8_t sourceLen, uint8_t pLen, u
|
|||
}
|
||||
|
||||
// array must be size dividable with 8
|
||||
uint8_t bits_to_array(const uint8_t *bits, size_t size, uint8_t *dest)
|
||||
{
|
||||
uint8_t bits_to_array(const uint8_t *bits, size_t size, uint8_t *dest) {
|
||||
if ((size == 0) || (size % 8) != 0) return 0;
|
||||
|
||||
for (uint32_t i = 0; i < (size / 8); i++)
|
||||
|
@ -243,8 +233,7 @@ uint8_t bits_to_array(const uint8_t *bits, size_t size, uint8_t *dest)
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint32_t bytebits_to_byte(uint8_t *src, size_t numbits)
|
||||
{
|
||||
uint32_t bytebits_to_byte(uint8_t *src, size_t numbits) {
|
||||
uint32_t num = 0;
|
||||
for (int i = 0 ; i < numbits ; i++) {
|
||||
num = (num << 1) | (*src);
|
||||
|
@ -254,8 +243,7 @@ uint32_t bytebits_to_byte(uint8_t *src, size_t numbits)
|
|||
}
|
||||
|
||||
//least significant bit first
|
||||
uint32_t bytebits_to_byteLSBF(uint8_t *src, size_t numbits)
|
||||
{
|
||||
uint32_t bytebits_to_byteLSBF(uint8_t *src, size_t numbits) {
|
||||
uint32_t num = 0;
|
||||
for (int i = 0 ; i < numbits ; i++) {
|
||||
num = (num << 1) | *(src + (numbits - (i + 1)));
|
||||
|
@ -265,16 +253,14 @@ uint32_t bytebits_to_byteLSBF(uint8_t *src, size_t numbits)
|
|||
|
||||
//by marshmellow
|
||||
//search for given preamble in given BitStream and return success = TRUE or fail = FALSE and startIndex and length
|
||||
bool preambleSearch(uint8_t *bits, uint8_t *preamble, size_t pLen, size_t *size, size_t *startIdx)
|
||||
{
|
||||
bool preambleSearch(uint8_t *bits, uint8_t *preamble, size_t pLen, size_t *size, size_t *startIdx) {
|
||||
return preambleSearchEx(bits, preamble, pLen, size, startIdx, false);
|
||||
}
|
||||
//by marshmellow
|
||||
// search for given preamble in given BitStream and return success=1 or fail=0 and startIndex (where it was found) and length if not fineone
|
||||
// fineone does not look for a repeating preamble for em4x05/4x69 sends preamble once, so look for it once in the first pLen bits
|
||||
//(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)
|
||||
{
|
||||
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;
|
||||
|
||||
|
@ -299,8 +285,7 @@ bool preambleSearchEx(uint8_t *bits, uint8_t *preamble, size_t pLen, size_t *siz
|
|||
}
|
||||
|
||||
// find start of modulating data (for fsk and psk) in case of beginning noise or slow chip startup.
|
||||
size_t findModStart(uint8_t *src, 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;
|
||||
|
@ -325,8 +310,7 @@ size_t findModStart(uint8_t *src, size_t size, uint8_t expWaveSize)
|
|||
return i;
|
||||
}
|
||||
|
||||
int getClosestClock(int testclk)
|
||||
{
|
||||
int getClosestClock(int testclk) {
|
||||
uint16_t clocks[] = {8, 16, 32, 40, 50, 64, 128, 256, 384};
|
||||
uint8_t limit[] = {1, 2, 4, 4, 5, 8, 8, 8, 8};
|
||||
|
||||
|
@ -337,21 +321,18 @@ int getClosestClock(int testclk)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void getNextLow(uint8_t *samples, size_t size, int low, size_t *i)
|
||||
{
|
||||
void getNextLow(uint8_t *samples, size_t size, int low, size_t *i) {
|
||||
while ((samples[*i] > low) && (*i < size))
|
||||
*i += 1;
|
||||
}
|
||||
|
||||
void getNextHigh(uint8_t *samples, size_t size, int high, size_t *i)
|
||||
{
|
||||
void getNextHigh(uint8_t *samples, size_t size, int high, size_t *i) {
|
||||
while ((samples[*i] < high) && (*i < size))
|
||||
*i += 1;
|
||||
}
|
||||
|
||||
// load wave counters
|
||||
bool loadWaveCounters(uint8_t *samples, size_t size, int lowToLowWaveLen[], int highToLowWaveLen[], int *waveCnt, int *skip, int *minClk, int *high, int *low)
|
||||
{
|
||||
bool loadWaveCounters(uint8_t *samples, size_t size, int lowToLowWaveLen[], int highToLowWaveLen[], int *waveCnt, int *skip, int *minClk, int *high, int *low) {
|
||||
size_t i = 0, firstLow, firstHigh;
|
||||
//size_t testsize = (size < 512) ? size : 512;
|
||||
|
||||
|
@ -391,8 +372,7 @@ bool loadWaveCounters(uint8_t *samples, size_t size, int lowToLowWaveLen[], int
|
|||
return true;
|
||||
}
|
||||
|
||||
size_t pskFindFirstPhaseShift(uint8_t *samples, size_t size, uint8_t *curPhase, size_t waveStart, uint16_t fc, uint16_t *fullWaveLen)
|
||||
{
|
||||
size_t pskFindFirstPhaseShift(uint8_t *samples, size_t size, uint8_t *curPhase, size_t waveStart, uint16_t fc, uint16_t *fullWaveLen) {
|
||||
uint16_t loopCnt = (size + 3 < 4096) ? size : 4096; //don't need to loop through entire array...
|
||||
|
||||
uint16_t avgWaveVal = 0, lastAvgWaveVal = 0;
|
||||
|
@ -421,8 +401,7 @@ size_t pskFindFirstPhaseShift(uint8_t *samples, size_t size, uint8_t *curPhase,
|
|||
|
||||
//by marshmellow
|
||||
//amplify based on ask edge detection - not accurate enough to use all the time
|
||||
void askAmp(uint8_t *bits, size_t size)
|
||||
{
|
||||
void askAmp(uint8_t *bits, size_t size) {
|
||||
uint8_t last = 128;
|
||||
for (size_t i = 1; i < size; ++i) {
|
||||
if (bits[i] - bits[i - 1] >= 30) //large jump up
|
||||
|
@ -435,8 +414,7 @@ void askAmp(uint8_t *bits, size_t size)
|
|||
}
|
||||
|
||||
// iceman, simplify this
|
||||
uint32_t manchesterEncode2Bytes(uint16_t datain)
|
||||
{
|
||||
uint32_t manchesterEncode2Bytes(uint16_t datain) {
|
||||
uint32_t output = 0;
|
||||
uint8_t curBit = 0;
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
|
@ -449,8 +427,7 @@ uint32_t manchesterEncode2Bytes(uint16_t datain)
|
|||
//by marshmellow
|
||||
//encode binary data into binary manchester
|
||||
//NOTE: bitstream must have triple the size of "size" available in memory to do the swap
|
||||
int ManchesterEncode(uint8_t *bits, size_t size)
|
||||
{
|
||||
int ManchesterEncode(uint8_t *bits, size_t size) {
|
||||
//allow up to 4096b out (means bits must be at least 2048+4096 to handle the swap)
|
||||
size = (size > 2048) ? 2048 : size;
|
||||
size_t modIdx = size;
|
||||
|
@ -468,8 +445,7 @@ int ManchesterEncode(uint8_t *bits, size_t size)
|
|||
// by marshmellow
|
||||
// to detect a wave that has heavily clipped (clean) samples
|
||||
// loop 512 samples, if 250 of them is deemed maxed out, we assume the wave is clipped.
|
||||
bool DetectCleanAskWave(uint8_t *dest, size_t size, uint8_t high, uint8_t low)
|
||||
{
|
||||
bool DetectCleanAskWave(uint8_t *dest, size_t size, uint8_t high, uint8_t low) {
|
||||
bool allArePeaks = true;
|
||||
uint16_t cntPeaks = 0;
|
||||
size_t loopEnd = 512 + 160;
|
||||
|
@ -500,8 +476,7 @@ bool DetectCleanAskWave(uint8_t *dest, size_t size, uint8_t high, uint8_t low)
|
|||
// by marshmellow
|
||||
// to help detect clocks on heavily clipped samples
|
||||
// based on count of low to low
|
||||
int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clock)
|
||||
{
|
||||
int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clock) {
|
||||
size_t startwave;
|
||||
size_t i = 100;
|
||||
size_t minClk = 512;
|
||||
|
@ -540,8 +515,7 @@ int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clo
|
|||
// not perfect especially with lower clocks or VERY good antennas (heavy wave clipping)
|
||||
// maybe somehow adjust peak trimming value based on samples to fix?
|
||||
// return start index of best starting position for that clock and return clock (by reference)
|
||||
int DetectASKClock(uint8_t *dest, size_t size, int *clock, int maxErr)
|
||||
{
|
||||
int DetectASKClock(uint8_t *dest, size_t size, int *clock, int maxErr) {
|
||||
|
||||
//don't need to loop through entire array. (cotag has clock of 384)
|
||||
uint16_t loopCnt = 1500;
|
||||
|
@ -680,8 +654,7 @@ int DetectASKClock(uint8_t *dest, size_t size, int *clock, int maxErr)
|
|||
return bestStart[best];
|
||||
}
|
||||
|
||||
int DetectStrongNRZClk(uint8_t *dest, size_t size, int peak, int low, bool *strong)
|
||||
{
|
||||
int DetectStrongNRZClk(uint8_t *dest, size_t size, int peak, int low, bool *strong) {
|
||||
//find shortest transition from high to low
|
||||
*strong = false;
|
||||
size_t i = 0;
|
||||
|
@ -726,8 +699,7 @@ int DetectStrongNRZClk(uint8_t *dest, size_t size, int peak, int low, bool *stro
|
|||
|
||||
//by marshmellow
|
||||
//detect nrz clock by reading #peaks vs no peaks(or errors)
|
||||
int DetectNRZClock(uint8_t *dest, size_t size, int clock, size_t *clockStartIdx)
|
||||
{
|
||||
int DetectNRZClock(uint8_t *dest, size_t size, int clock, size_t *clockStartIdx) {
|
||||
size_t i = 0;
|
||||
uint8_t clk[] = {8, 16, 32, 40, 50, 64, 100, 128, 255};
|
||||
size_t loopCnt = 4096; //don't need to loop through entire array...
|
||||
|
@ -857,8 +829,7 @@ int DetectNRZClock(uint8_t *dest, size_t size, int clock, size_t *clockStartIdx)
|
|||
//countFC is to detect the field clock lengths.
|
||||
//counts and returns the 2 most common wave lengths
|
||||
//mainly used for FSK field clock detection
|
||||
uint16_t countFC(uint8_t *bits, size_t size, bool fskAdj)
|
||||
{
|
||||
uint16_t countFC(uint8_t *bits, size_t size, bool fskAdj) {
|
||||
uint8_t fcLens[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
uint16_t fcCnts[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
uint8_t fcLensFnd = 0;
|
||||
|
@ -948,8 +919,7 @@ uint16_t countFC(uint8_t *bits, size_t size, bool fskAdj)
|
|||
//by marshmellow
|
||||
//detect psk clock by reading each phase shift
|
||||
// a phase shift is determined by measuring the sample length of each wave
|
||||
int DetectPSKClock(uint8_t *dest, size_t size, int clock, size_t *firstPhaseShift, uint8_t *curPhase, uint8_t *fc)
|
||||
{
|
||||
int DetectPSKClock(uint8_t *dest, size_t size, int clock, size_t *firstPhaseShift, uint8_t *curPhase, uint8_t *fc) {
|
||||
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...
|
||||
|
||||
|
@ -1048,8 +1018,7 @@ int DetectPSKClock(uint8_t *dest, size_t size, int clock, size_t *firstPhaseShif
|
|||
|
||||
//by marshmellow
|
||||
//detects the bit clock for FSK given the high and low Field Clocks
|
||||
uint8_t detectFSKClk(uint8_t *bits, size_t size, uint8_t fcHigh, uint8_t fcLow, int *firstClockEdge)
|
||||
{
|
||||
uint8_t detectFSKClk(uint8_t *bits, size_t size, uint8_t fcHigh, uint8_t fcLow, int *firstClockEdge) {
|
||||
|
||||
if (size == 0)
|
||||
return 0;
|
||||
|
@ -1163,8 +1132,7 @@ uint8_t detectFSKClk(uint8_t *bits, size_t size, uint8_t fcHigh, uint8_t fcLow,
|
|||
|
||||
|
||||
// look for Sequence Terminator - should be pulses of clk*(1 or 2), clk*2, clk*(1.5 or 2), by idx we mean graph position index...
|
||||
bool findST(int *stStopLoc, int *stStartIdx, int lowToLowWaveLen[], int highToLowWaveLen[], int clk, int tol, int buffSize, size_t *i)
|
||||
{
|
||||
bool findST(int *stStopLoc, int *stStartIdx, int lowToLowWaveLen[], int highToLowWaveLen[], int clk, int tol, int buffSize, size_t *i) {
|
||||
if (buffSize < *i + 4) return false;
|
||||
|
||||
for (; *i < buffSize - 4; *i += 1) {
|
||||
|
@ -1184,8 +1152,7 @@ bool findST(int *stStopLoc, int *stStartIdx, int lowToLowWaveLen[], int highToLo
|
|||
}
|
||||
//by marshmellow
|
||||
//attempt to identify a Sequence Terminator in ASK modulated raw wave
|
||||
bool DetectST(uint8_t *buffer, size_t *size, int *foundclock, size_t *ststart, size_t *stend)
|
||||
{
|
||||
bool DetectST(uint8_t *buffer, size_t *size, int *foundclock, size_t *ststart, size_t *stend) {
|
||||
size_t bufsize = *size;
|
||||
//need to loop through all samples and identify our clock, look for the ST pattern
|
||||
int clk = 0;
|
||||
|
@ -1312,8 +1279,7 @@ bool DetectST(uint8_t *buffer, size_t *size, int *foundclock, size_t *ststart, s
|
|||
//check for phase errors - should never have half a 1 or 0 by itself and should never exceed 1111 or 0000 in a row
|
||||
//decodes miller encoded binary
|
||||
//NOTE askrawdemod will NOT demod miller encoded ask unless the clock is manually set to 1/2 what it is detected as!
|
||||
int millerRawDecode(uint8_t *bits, size_t *size, int invert)
|
||||
{
|
||||
int millerRawDecode(uint8_t *bits, size_t *size, int invert) {
|
||||
if (*size < 16) return -1;
|
||||
|
||||
uint16_t MaxBits = 512, errCnt = 0;
|
||||
|
@ -1351,8 +1317,7 @@ int millerRawDecode(uint8_t *bits, size_t *size, int invert)
|
|||
//take 01 or 10 = 1 and 11 or 00 = 0
|
||||
//check for phase errors - should never have 111 or 000 should be 01001011 or 10110100 for 1010
|
||||
//decodes biphase or if inverted it is AKA conditional dephase encoding AKA differential manchester encoding
|
||||
int BiphaseRawDecode(uint8_t *bits, size_t *size, int *offset, int invert)
|
||||
{
|
||||
int BiphaseRawDecode(uint8_t *bits, size_t *size, int *offset, int invert) {
|
||||
//sanity check
|
||||
if (*size < 51) return -1;
|
||||
|
||||
|
@ -1392,8 +1357,7 @@ int BiphaseRawDecode(uint8_t *bits, size_t *size, int *offset, int invert)
|
|||
//by marshmellow
|
||||
//take 10 and 01 and manchester decode
|
||||
//run through 2 times and take least errCnt
|
||||
int manrawdecode(uint8_t *bits, size_t *size, uint8_t invert, uint8_t *alignPos)
|
||||
{
|
||||
int manrawdecode(uint8_t *bits, size_t *size, uint8_t invert, uint8_t *alignPos) {
|
||||
|
||||
// sanity check
|
||||
if (*size < 16) return -1;
|
||||
|
@ -1433,8 +1397,7 @@ int manrawdecode(uint8_t *bits, size_t *size, uint8_t invert, uint8_t *alignPos)
|
|||
//by marshmellow
|
||||
//demodulates strong heavily clipped samples
|
||||
//RETURN: num of errors. if 0, is ok.
|
||||
int cleanAskRawDemod(uint8_t *bits, size_t *size, int clk, int invert, int high, int low, int *startIdx)
|
||||
{
|
||||
int cleanAskRawDemod(uint8_t *bits, size_t *size, int clk, int invert, int high, int low, int *startIdx) {
|
||||
*startIdx = 0;
|
||||
size_t bitCnt = 0, smplCnt = 1, errCnt = 0, pos = 0;
|
||||
uint8_t cl_4 = clk / 4;
|
||||
|
@ -1505,8 +1468,7 @@ int cleanAskRawDemod(uint8_t *bits, size_t *size, int clk, int invert, int high,
|
|||
|
||||
//by marshmellow
|
||||
//attempts to demodulate ask modulations, askType == 0 for ask/raw, askType==1 for ask/manchester
|
||||
int askdemod_ext(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType, int *startIdx)
|
||||
{
|
||||
int askdemod_ext(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType, int *startIdx) {
|
||||
|
||||
if (*size == 0) return -1;
|
||||
|
||||
|
@ -1604,16 +1566,14 @@ int askdemod_ext(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr,
|
|||
return errCnt;
|
||||
}
|
||||
|
||||
int askdemod(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType)
|
||||
{
|
||||
int askdemod(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType) {
|
||||
int start = 0;
|
||||
return askdemod_ext(bits, size, clk, invert, maxErr, amp, askType, &start);
|
||||
}
|
||||
|
||||
// by marshmellow - demodulate NRZ wave - requires a read with strong signal
|
||||
// peaks invert bit (high=1 low=0) each clock cycle = 1 bit determined by last peak
|
||||
int nrzRawDemod(uint8_t *dest, size_t *size, int *clk, int *invert, int *startIdx)
|
||||
{
|
||||
int nrzRawDemod(uint8_t *dest, size_t *size, int *clk, int *invert, int *startIdx) {
|
||||
if (signalprop.isnoise) return -1;
|
||||
|
||||
size_t clkStartIdx = 0;
|
||||
|
@ -1663,8 +1623,7 @@ int nrzRawDemod(uint8_t *dest, size_t *size, int *clk, int *invert, int *startId
|
|||
}
|
||||
|
||||
//translate wave to 11111100000 (1 for each short wave [higher freq] 0 for each long wave [lower freq])
|
||||
size_t fsk_wave_demod(uint8_t *dest, size_t size, uint8_t fchigh, uint8_t fclow, int *startIdx)
|
||||
{
|
||||
size_t fsk_wave_demod(uint8_t *dest, size_t size, uint8_t fchigh, uint8_t fclow, int *startIdx) {
|
||||
|
||||
if (size < 1024) return 0; // not enough samples
|
||||
|
||||
|
@ -1762,8 +1721,7 @@ size_t fsk_wave_demod(uint8_t *dest, size_t size, uint8_t fchigh, uint8_t fclow,
|
|||
|
||||
//translate 11111100000 to 10
|
||||
//rfLen = clock, fchigh = larger field clock, fclow = smaller field clock
|
||||
size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t clk, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx)
|
||||
{
|
||||
size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t clk, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx) {
|
||||
|
||||
uint8_t lastval = dest[0];
|
||||
size_t i = 0;
|
||||
|
@ -1822,8 +1780,7 @@ size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t clk, uint8_t invert, u
|
|||
|
||||
//by marshmellow (from holiman's base)
|
||||
// full fsk demod from GraphBuffer wave to decoded 1s and 0s (no mandemod)
|
||||
size_t fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *start_idx)
|
||||
{
|
||||
size_t fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *start_idx) {
|
||||
if (signalprop.isnoise) return 0;
|
||||
// FSK demodulator
|
||||
size = fsk_wave_demod(dest, size, fchigh, fclow, start_idx);
|
||||
|
@ -1835,8 +1792,7 @@ size_t fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8
|
|||
// convert psk1 demod to psk2 demod
|
||||
// only transition waves are 1s
|
||||
//TODO: Iceman - hard coded value 7, should be #define
|
||||
void psk1TOpsk2(uint8_t *bits, size_t size)
|
||||
{
|
||||
void psk1TOpsk2(uint8_t *bits, size_t size) {
|
||||
uint8_t lastbit = bits[0];
|
||||
for (size_t i = 1; i < size; i++) {
|
||||
//ignore errors
|
||||
|
@ -1854,8 +1810,7 @@ void psk1TOpsk2(uint8_t *bits, size_t size)
|
|||
// by marshmellow
|
||||
// convert psk2 demod to psk1 demod
|
||||
// from only transition waves are 1s to phase shifts change bit
|
||||
void psk2TOpsk1(uint8_t *bits, size_t size)
|
||||
{
|
||||
void psk2TOpsk1(uint8_t *bits, size_t size) {
|
||||
uint8_t phase = 0;
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
if (bits[i] == 1) {
|
||||
|
@ -1868,8 +1823,7 @@ void psk2TOpsk1(uint8_t *bits, size_t size)
|
|||
//by marshmellow - demodulate PSK1 wave
|
||||
//uses wave lengths (# Samples)
|
||||
//TODO: Iceman - hard coded value 7, should be #define
|
||||
int pskRawDemod_ext(uint8_t *dest, size_t *size, int *clock, int *invert, int *startIdx)
|
||||
{
|
||||
int pskRawDemod_ext(uint8_t *dest, size_t *size, int *clock, int *invert, int *startIdx) {
|
||||
|
||||
// sanity check
|
||||
if (*size < 170) return -1;
|
||||
|
@ -1951,8 +1905,7 @@ int pskRawDemod_ext(uint8_t *dest, size_t *size, int *clock, int *invert, int *s
|
|||
return errCnt;
|
||||
}
|
||||
|
||||
int pskRawDemod(uint8_t *dest, size_t *size, int *clock, int *invert)
|
||||
{
|
||||
int pskRawDemod(uint8_t *dest, size_t *size, int *clock, int *invert) {
|
||||
int start_idx = 0;
|
||||
return pskRawDemod_ext(dest, size, clock, invert, &start_idx);
|
||||
}
|
||||
|
@ -1965,8 +1918,7 @@ int pskRawDemod(uint8_t *dest, size_t *size, int *clock, int *invert)
|
|||
|
||||
// by marshmellow
|
||||
// FSK Demod then try to locate an AWID ID
|
||||
int detectAWID(uint8_t *dest, size_t *size, int *waveStartIdx)
|
||||
{
|
||||
int detectAWID(uint8_t *dest, size_t *size, int *waveStartIdx) {
|
||||
//make sure buffer has enough data (96bits * 50clock samples)
|
||||
if (*size < 96 * 50) return -1;
|
||||
|
||||
|
@ -1991,8 +1943,7 @@ int detectAWID(uint8_t *dest, size_t *size, int *waveStartIdx)
|
|||
|
||||
//by marshmellow
|
||||
//takes 1s and 0s and searches for EM410x format - output EM ID
|
||||
int Em410xDecode(uint8_t *bits, size_t *size, size_t *start_idx, uint32_t *hi, uint64_t *lo)
|
||||
{
|
||||
int Em410xDecode(uint8_t *bits, size_t *size, size_t *start_idx, uint32_t *hi, uint64_t *lo) {
|
||||
// sanity check
|
||||
if (bits[1] > 1) return -1;
|
||||
if (*size < 64) return -2;
|
||||
|
@ -2033,8 +1984,7 @@ int Em410xDecode(uint8_t *bits, size_t *size, size_t *start_idx, uint32_t *hi, u
|
|||
|
||||
|
||||
// loop to get raw HID waveform then FSK demodulate the TAG ID from it
|
||||
int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx)
|
||||
{
|
||||
int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx) {
|
||||
//make sure buffer has data
|
||||
if (*size < 96 * 50) return -1;
|
||||
|
||||
|
@ -2075,8 +2025,7 @@ int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32
|
|||
|
||||
// Find IDTEC PSK1, RF Preamble == 0x4944544B, Demodsize 64bits
|
||||
// by iceman
|
||||
int detectIdteck(uint8_t *dest, size_t *size)
|
||||
{
|
||||
int detectIdteck(uint8_t *dest, size_t *size) {
|
||||
//make sure buffer has data
|
||||
if (*size < 64 * 2) return -1;
|
||||
|
||||
|
@ -2094,8 +2043,7 @@ int detectIdteck(uint8_t *dest, size_t *size)
|
|||
return (int)start_idx;
|
||||
}
|
||||
|
||||
int detectIOProx(uint8_t *dest, size_t *size, int *waveStartIdx)
|
||||
{
|
||||
int detectIOProx(uint8_t *dest, size_t *size, int *waveStartIdx) {
|
||||
//make sure buffer has data
|
||||
if (*size < 66 * 64) return -1;
|
||||
|
||||
|
@ -2125,11 +2073,11 @@ int detectIOProx(uint8_t *dest, size_t *size, int *waveStartIdx)
|
|||
if (*size != 64) return -5;
|
||||
|
||||
if (!dest[start_idx + 8]
|
||||
&& dest[start_idx + 17] == 1
|
||||
&& dest[start_idx + 26] == 1
|
||||
&& dest[start_idx + 35] == 1
|
||||
&& dest[start_idx + 44] == 1
|
||||
&& dest[start_idx + 53] == 1) {
|
||||
&& dest[start_idx + 17] == 1
|
||||
&& dest[start_idx + 26] == 1
|
||||
&& dest[start_idx + 35] == 1
|
||||
&& dest[start_idx + 44] == 1
|
||||
&& dest[start_idx + 53] == 1) {
|
||||
//confirmed proper separator bits found
|
||||
//return start position
|
||||
return (int) start_idx;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue