Release v4.13441 - midsummer
[RRG-proxmark3.git] / common / lfdemod.h
blobe8d516604c8e7204ab899b0e60b2f3e8993d4fe6
1 // Copyright (C) 2014
2 //
3 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
4 // at your option, any later version. See the LICENSE.txt file for the text of
5 // the license.
6 //-----------------------------------------------------------------------------
7 // Low frequency demod related commands
8 // marshmellow
9 // note that many of these demods are not the slickest code and they often rely
10 // on peaks and clock instead of converting to clean signal.
12 //-----------------------------------------------------------------------------
14 #ifndef LFDEMOD_H__
15 #define LFDEMOD_H__
17 #include "common.h"
19 //might not be high enough for noisy environments
20 #define NOISE_AMPLITUDE_THRESHOLD 8
21 //ignore buffer with less than x samples
22 #define SIGNAL_MIN_SAMPLES 100
23 //ignore first x samples of the buffer
24 #define SIGNAL_IGNORE_FIRST_SAMPLES 10
26 //generic
27 typedef struct {
28 int low;
29 int high;
30 int mean;
31 int amplitude;
32 bool isnoise;
33 } signal_t;
34 signal_t *getSignalProperties(void);
36 void computeSignalProperties(uint8_t *samples, uint32_t size);
37 void removeSignalOffset(uint8_t *samples, uint32_t size);
38 void getNextLow(uint8_t *samples, size_t size, int low, size_t *i);
39 void getNextHigh(uint8_t *samples, size_t size, int high, size_t *i);
40 bool loadWaveCounters(uint8_t *samples, size_t size, int lowToLowWaveLen[], int highToLowWaveLen[], int *waveCnt, int *skip, int *minClk, int *high, int *low);
41 size_t pskFindFirstPhaseShift(uint8_t *samples, size_t size, uint8_t *curPhase, size_t waveStart, uint16_t fc, uint16_t *fullWaveLen);
43 size_t addParity(uint8_t *src, uint8_t *dest, uint8_t sourceLen, uint8_t pLen, uint8_t pType);
44 int askdemod(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType);
45 int askdemod_ext(uint8_t *bits, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType, int *startIdx);
46 void askAmp(uint8_t *bits, size_t size);
47 int BiphaseRawDecode(uint8_t *bits, size_t *size, int *offset, int invert);
48 int bits_to_array(const uint8_t *bits, size_t size, uint8_t *dest);
49 uint32_t bytebits_to_byte(uint8_t *src, size_t numbits);
50 uint32_t bytebits_to_byteLSBF(uint8_t *src, size_t numbits);
51 uint16_t countFC(uint8_t *bits, size_t size, bool fskAdj);
52 int DetectASKClock(uint8_t *dest, size_t size, int *clock, int maxErr);
53 bool DetectCleanAskWave(uint8_t *dest, size_t size, uint8_t high, uint8_t low);
54 uint8_t detectFSKClk(uint8_t *bits, size_t size, uint8_t fcHigh, uint8_t fcLow, int *firstClockEdge);
55 int DetectNRZClock(uint8_t *dest, size_t size, int clock, size_t *clockStartIdx);
56 int DetectPSKClock(uint8_t *dest, size_t size, int clock, size_t *firstPhaseShift, uint8_t *curPhase, uint8_t *fc);
57 int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clock);
58 int DetectStrongNRZClk(uint8_t *dest, size_t size, int peak, int low, bool *strong);
59 bool DetectST(uint8_t *buffer, size_t *size, int *foundclock, size_t *ststart, size_t *stend);
60 size_t fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *start_idx);
61 //void getHiLo(uint8_t *bits, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo);
62 void getHiLo(int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo);
63 uint32_t manchesterEncode2Bytes(uint16_t datain);
64 void manchesterEncodeUint32(uint32_t data_in, uint8_t bitlen_in, uint8_t *bits_out, uint16_t *index);
65 int ManchesterEncode(uint8_t *bits, size_t size);
66 uint16_t manrawdecode(uint8_t *bits, size_t *size, uint8_t invert, uint8_t *alignPos);
67 int nrzRawDemod(uint8_t *dest, size_t *size, int *clk, int *invert, int *startIdx);
68 bool parityTest(uint32_t bits, uint8_t bitLen, uint8_t pType);
69 bool preambleSearch(uint8_t *bits, uint8_t *preamble, size_t pLen, size_t *size, size_t *startIdx);
70 bool preambleSearchEx(uint8_t *bits, uint8_t *preamble, size_t pLen, size_t *size, size_t *startIdx, bool findone);
71 int pskRawDemod(uint8_t *dest, size_t *size, int *clock, int *invert);
72 int pskRawDemod_ext(uint8_t *dest, size_t *size, int *clock, int *invert, int *startIdx);
73 void psk2TOpsk1(uint8_t *bits, size_t size);
74 void psk1TOpsk2(uint8_t *bits, size_t size);
75 size_t removeParity(uint8_t *bits, size_t startIdx, uint8_t pLen, uint8_t pType, size_t bLen);
77 //tag specific
78 int detectAWID(uint8_t *dest, size_t *size, int *waveStartIdx);
79 int Em410xDecode(uint8_t *bits, size_t *size, size_t *start_idx, uint32_t *hi, uint64_t *lo);
80 int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx);
81 int detectIOProx(uint8_t *dest, size_t *size, int *waveStartIdx);
83 #endif