mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-07-11 15:56:09 -07:00
Merge pull request #208 from marshmellow42/master
bug fixes - LF rawdemod am and ST
This commit is contained in:
commit
c783fd1bb8
3 changed files with 43 additions and 21 deletions
|
@ -317,7 +317,7 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType,
|
||||||
int clk=0;
|
int clk=0;
|
||||||
int maxErr=100;
|
int maxErr=100;
|
||||||
int maxLen=0;
|
int maxLen=0;
|
||||||
uint8_t askAmp = 0;
|
uint8_t askamp = 0;
|
||||||
char amp = param_getchar(Cmd, 0);
|
char amp = param_getchar(Cmd, 0);
|
||||||
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
|
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
|
||||||
sscanf(Cmd, "%i %i %i %i %c", &clk, &invert, &maxErr, &maxLen, &);
|
sscanf(Cmd, "%i %i %i %i %c", &clk, &invert, &maxErr, &maxLen, &);
|
||||||
|
@ -330,12 +330,15 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType,
|
||||||
invert=1;
|
invert=1;
|
||||||
clk=0;
|
clk=0;
|
||||||
}
|
}
|
||||||
if (amp == 'a' || amp == 'A') askAmp=1;
|
|
||||||
size_t BitLen = getFromGraphBuf(BitStream);
|
size_t BitLen = getFromGraphBuf(BitStream);
|
||||||
if (g_debugMode) PrintAndLog("DEBUG: Bitlen from grphbuff: %d",BitLen);
|
if (g_debugMode) PrintAndLog("DEBUG: Bitlen from grphbuff: %d",BitLen);
|
||||||
if (BitLen < 255) return 0;
|
if (BitLen < 255) return 0;
|
||||||
if (maxLen < BitLen && maxLen != 0) BitLen = maxLen;
|
if (maxLen < BitLen && maxLen != 0) BitLen = maxLen;
|
||||||
int foundclk = 0;
|
int foundclk = 0;
|
||||||
|
//amp before ST check
|
||||||
|
if (amp == 'a' || amp == 'A') {
|
||||||
|
askAmp(BitStream, BitLen);
|
||||||
|
}
|
||||||
bool st = false;
|
bool st = false;
|
||||||
if (*stCheck) st = DetectST(BitStream, &BitLen, &foundclk);
|
if (*stCheck) st = DetectST(BitStream, &BitLen, &foundclk);
|
||||||
if (st) {
|
if (st) {
|
||||||
|
@ -343,7 +346,7 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType,
|
||||||
clk = (clk == 0) ? foundclk : clk;
|
clk = (clk == 0) ? foundclk : clk;
|
||||||
if (verbose || g_debugMode) PrintAndLog("\nFound Sequence Terminator");
|
if (verbose || g_debugMode) PrintAndLog("\nFound Sequence Terminator");
|
||||||
}
|
}
|
||||||
int errCnt = askdemod(BitStream, &BitLen, &clk, &invert, maxErr, askAmp, askType);
|
int errCnt = askdemod(BitStream, &BitLen, &clk, &invert, maxErr, askamp, askType);
|
||||||
if (errCnt<0 || BitLen<16){ //if fatal error (or -1)
|
if (errCnt<0 || BitLen<16){ //if fatal error (or -1)
|
||||||
if (g_debugMode) PrintAndLog("DEBUG: no data found %d, errors:%d, bitlen:%d, clock:%d",errCnt,invert,BitLen,clk);
|
if (g_debugMode) PrintAndLog("DEBUG: no data found %d, errors:%d, bitlen:%d, clock:%d",errCnt,invert,BitLen,clk);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -383,7 +386,7 @@ int ASKDemod(const char *Cmd, bool verbose, bool emSearch, uint8_t askType) {
|
||||||
int Cmdaskmandemod(const char *Cmd)
|
int Cmdaskmandemod(const char *Cmd)
|
||||||
{
|
{
|
||||||
char cmdp = param_getchar(Cmd, 0);
|
char cmdp = param_getchar(Cmd, 0);
|
||||||
if (strlen(Cmd) > 25 || cmdp == 'h' || cmdp == 'H') {
|
if (strlen(Cmd) > 45 || cmdp == 'h' || cmdp == 'H') {
|
||||||
PrintAndLog("Usage: data rawdemod am <s> [clock] <invert> [maxError] [maxLen] [amplify]");
|
PrintAndLog("Usage: data rawdemod am <s> [clock] <invert> [maxError] [maxLen] [amplify]");
|
||||||
PrintAndLog(" ['s'] optional, check for Sequence Terminator");
|
PrintAndLog(" ['s'] optional, check for Sequence Terminator");
|
||||||
PrintAndLog(" [set clock as integer] optional, if not set, autodetect");
|
PrintAndLog(" [set clock as integer] optional, if not set, autodetect");
|
||||||
|
@ -678,7 +681,7 @@ int CmdVikingDemod(const char *Cmd)
|
||||||
int Cmdaskrawdemod(const char *Cmd)
|
int Cmdaskrawdemod(const char *Cmd)
|
||||||
{
|
{
|
||||||
char cmdp = param_getchar(Cmd, 0);
|
char cmdp = param_getchar(Cmd, 0);
|
||||||
if (strlen(Cmd) > 25 || cmdp == 'h' || cmdp == 'H') {
|
if (strlen(Cmd) > 35 || cmdp == 'h' || cmdp == 'H') {
|
||||||
PrintAndLog("Usage: data rawdemod ar [clock] <invert> [maxError] [maxLen] [amplify]");
|
PrintAndLog("Usage: data rawdemod ar [clock] <invert> [maxError] [maxLen] [amplify]");
|
||||||
PrintAndLog(" [set clock as integer] optional, if not set, autodetect");
|
PrintAndLog(" [set clock as integer] optional, if not set, autodetect");
|
||||||
PrintAndLog(" <invert>, 1 to invert output");
|
PrintAndLog(" <invert>, 1 to invert output");
|
||||||
|
@ -1012,7 +1015,7 @@ int FSKrawDemod(const char *Cmd, bool verbose)
|
||||||
int CmdFSKrawdemod(const char *Cmd)
|
int CmdFSKrawdemod(const char *Cmd)
|
||||||
{
|
{
|
||||||
char cmdp = param_getchar(Cmd, 0);
|
char cmdp = param_getchar(Cmd, 0);
|
||||||
if (strlen(Cmd) > 10 || cmdp == 'h' || cmdp == 'H') {
|
if (strlen(Cmd) > 20 || cmdp == 'h' || cmdp == 'H') {
|
||||||
PrintAndLog("Usage: data rawdemod fs [clock] <invert> [fchigh] [fclow]");
|
PrintAndLog("Usage: data rawdemod fs [clock] <invert> [fchigh] [fclow]");
|
||||||
PrintAndLog(" [set clock as integer] optional, omit for autodetect.");
|
PrintAndLog(" [set clock as integer] optional, omit for autodetect.");
|
||||||
PrintAndLog(" <invert>, 1 for invert output, can be used even if the clock is omitted");
|
PrintAndLog(" <invert>, 1 for invert output, can be used even if the clock is omitted");
|
||||||
|
@ -1769,7 +1772,7 @@ int NRZrawDemod(const char *Cmd, bool verbose)
|
||||||
int CmdNRZrawDemod(const char *Cmd)
|
int CmdNRZrawDemod(const char *Cmd)
|
||||||
{
|
{
|
||||||
char cmdp = param_getchar(Cmd, 0);
|
char cmdp = param_getchar(Cmd, 0);
|
||||||
if (strlen(Cmd) > 10 || cmdp == 'h' || cmdp == 'H') {
|
if (strlen(Cmd) > 16 || cmdp == 'h' || cmdp == 'H') {
|
||||||
PrintAndLog("Usage: data rawdemod nr [clock] <0|1> [maxError]");
|
PrintAndLog("Usage: data rawdemod nr [clock] <0|1> [maxError]");
|
||||||
PrintAndLog(" [set clock as integer] optional, if not set, autodetect.");
|
PrintAndLog(" [set clock as integer] optional, if not set, autodetect.");
|
||||||
PrintAndLog(" <invert>, 1 for invert output");
|
PrintAndLog(" <invert>, 1 for invert output");
|
||||||
|
@ -1793,7 +1796,7 @@ int CmdPSK1rawDemod(const char *Cmd)
|
||||||
{
|
{
|
||||||
int ans;
|
int ans;
|
||||||
char cmdp = param_getchar(Cmd, 0);
|
char cmdp = param_getchar(Cmd, 0);
|
||||||
if (strlen(Cmd) > 10 || cmdp == 'h' || cmdp == 'H') {
|
if (strlen(Cmd) > 16 || cmdp == 'h' || cmdp == 'H') {
|
||||||
PrintAndLog("Usage: data rawdemod p1 [clock] <0|1> [maxError]");
|
PrintAndLog("Usage: data rawdemod p1 [clock] <0|1> [maxError]");
|
||||||
PrintAndLog(" [set clock as integer] optional, if not set, autodetect.");
|
PrintAndLog(" [set clock as integer] optional, if not set, autodetect.");
|
||||||
PrintAndLog(" <invert>, 1 for invert output");
|
PrintAndLog(" <invert>, 1 for invert output");
|
||||||
|
@ -1825,7 +1828,7 @@ int CmdPSK2rawDemod(const char *Cmd)
|
||||||
{
|
{
|
||||||
int ans=0;
|
int ans=0;
|
||||||
char cmdp = param_getchar(Cmd, 0);
|
char cmdp = param_getchar(Cmd, 0);
|
||||||
if (strlen(Cmd) > 10 || cmdp == 'h' || cmdp == 'H') {
|
if (strlen(Cmd) > 16 || cmdp == 'h' || cmdp == 'H') {
|
||||||
PrintAndLog("Usage: data rawdemod p2 [clock] <0|1> [maxError]");
|
PrintAndLog("Usage: data rawdemod p2 [clock] <0|1> [maxError]");
|
||||||
PrintAndLog(" [set clock as integer] optional, if not set, autodetect.");
|
PrintAndLog(" [set clock as integer] optional, if not set, autodetect.");
|
||||||
PrintAndLog(" <invert>, 1 for invert output");
|
PrintAndLog(" <invert>, 1 for invert output");
|
||||||
|
@ -1855,7 +1858,7 @@ int CmdRawDemod(const char *Cmd)
|
||||||
{
|
{
|
||||||
char cmdp = Cmd[0]; //param_getchar(Cmd, 0);
|
char cmdp = Cmd[0]; //param_getchar(Cmd, 0);
|
||||||
|
|
||||||
if (strlen(Cmd) > 20 || cmdp == 'h' || cmdp == 'H' || strlen(Cmd)<2) {
|
if (strlen(Cmd) > 35 || cmdp == 'h' || cmdp == 'H' || strlen(Cmd)<2) {
|
||||||
PrintAndLog("Usage: data rawdemod [modulation] <help>|<options>");
|
PrintAndLog("Usage: data rawdemod [modulation] <help>|<options>");
|
||||||
PrintAndLog(" [modulation] as 2 char, 'ab' for ask/biphase, 'am' for ask/manchester, 'ar' for ask/raw, 'fs' for fsk, ...");
|
PrintAndLog(" [modulation] as 2 char, 'ab' for ask/biphase, 'am' for ask/manchester, 'ar' for ask/raw, 'fs' for fsk, ...");
|
||||||
PrintAndLog(" 'nr' for nrz/direct, 'p1' for psk1, 'p2' for psk2");
|
PrintAndLog(" 'nr' for nrz/direct, 'p1' for psk1, 'p2' for psk2");
|
||||||
|
|
|
@ -270,7 +270,7 @@ void askAmp(uint8_t *BitStream, size_t size)
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//by marshmellow
|
//by marshmellow
|
||||||
//attempts to demodulate ask modulations, askType == 0 for ask/raw, askType==1 for ask/manchester
|
//attempts to demodulate ask modulations, askType == 0 for ask/raw, askType==1 for ask/manchester
|
||||||
int askdemod(uint8_t *BinStream, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType)
|
int askdemod(uint8_t *BinStream, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType)
|
||||||
|
@ -280,7 +280,7 @@ int askdemod(uint8_t *BinStream, size_t *size, int *clk, int *invert, int maxErr
|
||||||
if (*clk==0 || start < 0) return -3;
|
if (*clk==0 || start < 0) return -3;
|
||||||
if (*invert != 1) *invert = 0;
|
if (*invert != 1) *invert = 0;
|
||||||
if (amp==1) askAmp(BinStream, *size);
|
if (amp==1) askAmp(BinStream, *size);
|
||||||
if (g_debugMode==2) prnt("DEBUG ASK: clk %d, beststart %d", *clk, start);
|
if (g_debugMode==2) prnt("DEBUG ASK: clk %d, beststart %d, amp %d", *clk, start, amp);
|
||||||
|
|
||||||
uint8_t initLoopMax = 255;
|
uint8_t initLoopMax = 255;
|
||||||
if (initLoopMax > *size) initLoopMax = *size;
|
if (initLoopMax > *size) initLoopMax = *size;
|
||||||
|
@ -1555,8 +1555,8 @@ bool DetectST(uint8_t buffer[], size_t *size, int *foundclock) {
|
||||||
int tol = 0;
|
int tol = 0;
|
||||||
int i, j, skip, start, end, low, high, minClk, waveStart;
|
int i, j, skip, start, end, low, high, minClk, waveStart;
|
||||||
bool complete = false;
|
bool complete = false;
|
||||||
int tmpbuff[bufsize / 64];
|
int tmpbuff[bufsize / 32]; //guess rf/32 clock, if click is smaller we will only have room for a fraction of the samples captured
|
||||||
int waveLen[bufsize / 64];
|
int waveLen[bufsize / 32]; // if clock is larger then we waste memory in array size that is not needed...
|
||||||
size_t testsize = (bufsize < 512) ? bufsize : 512;
|
size_t testsize = (bufsize < 512) ? bufsize : 512;
|
||||||
int phaseoff = 0;
|
int phaseoff = 0;
|
||||||
high = low = 128;
|
high = low = 128;
|
||||||
|
@ -1588,7 +1588,7 @@ bool DetectST(uint8_t buffer[], size_t *size, int *foundclock) {
|
||||||
waveStart = i;
|
waveStart = i;
|
||||||
while ((buffer[i] > low) && (i < bufsize))
|
while ((buffer[i] > low) && (i < bufsize))
|
||||||
++i;
|
++i;
|
||||||
if (j >= (bufsize/64)) {
|
if (j >= (bufsize/32)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
waveLen[j] = i - waveStart; //first high to first low
|
waveLen[j] = i - waveStart; //first high to first low
|
||||||
|
@ -1634,6 +1634,8 @@ bool DetectST(uint8_t buffer[], size_t *size, int *foundclock) {
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
if (g_debugMode==2) prnt("DEBUG STT: first STT not found - quitting");
|
if (g_debugMode==2) prnt("DEBUG STT: first STT not found - quitting");
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
if (g_debugMode==2) prnt("DEBUG STT: first STT found at: %d, j=%d",start, j);
|
||||||
}
|
}
|
||||||
if (waveLen[i+2] > clk*1+tol)
|
if (waveLen[i+2] > clk*1+tol)
|
||||||
phaseoff = 0;
|
phaseoff = 0;
|
||||||
|
@ -1647,7 +1649,7 @@ bool DetectST(uint8_t buffer[], size_t *size, int *foundclock) {
|
||||||
end = skip;
|
end = skip;
|
||||||
for (i += 3; i < j - 4; ++i) {
|
for (i += 3; i < j - 4; ++i) {
|
||||||
end += tmpbuff[i];
|
end += tmpbuff[i];
|
||||||
if (tmpbuff[i] >= clk*1-tol && tmpbuff[i] <= (clk*2)+tol) { //1 to 2 clocks depending on 2 bits prior
|
if (tmpbuff[i] >= clk*1-tol && tmpbuff[i] <= (clk*2)+tol && waveLen[i] < clk+tol) { //1 to 2 clocks depending on 2 bits prior
|
||||||
if (tmpbuff[i+1] >= clk*2-tol && tmpbuff[i+1] <= clk*2+tol && waveLen[i+1] > clk*3/2-tol) { //2 clocks and wave size is 1 1/2
|
if (tmpbuff[i+1] >= clk*2-tol && tmpbuff[i+1] <= clk*2+tol && waveLen[i+1] > clk*3/2-tol) { //2 clocks and wave size is 1 1/2
|
||||||
if (tmpbuff[i+2] >= (clk*3)/2-tol && tmpbuff[i+2] <= clk*2+tol && waveLen[i+2] > clk-tol) { //1 1/2 to 2 clocks and at least one full clock wave
|
if (tmpbuff[i+2] >= (clk*3)/2-tol && tmpbuff[i+2] <= clk*2+tol && waveLen[i+2] > clk-tol) { //1 1/2 to 2 clocks and at least one full clock wave
|
||||||
if (tmpbuff[i+3] >= clk*1-tol && tmpbuff[i+3] <= clk*2+tol) { //1 to 2 clocks for end of ST + first bit
|
if (tmpbuff[i+3] >= clk*1-tol && tmpbuff[i+3] <= clk*2+tol) { //1 to 2 clocks for end of ST + first bit
|
||||||
|
@ -1669,12 +1671,15 @@ bool DetectST(uint8_t buffer[], size_t *size, int *foundclock) {
|
||||||
start = skip;
|
start = skip;
|
||||||
size_t datalen = end - start;
|
size_t datalen = end - start;
|
||||||
// check validity of datalen (should be even clock increments) - use a tolerance of up to 1/8th a clock
|
// check validity of datalen (should be even clock increments) - use a tolerance of up to 1/8th a clock
|
||||||
if (datalen % clk > clk/8) {
|
if ( clk - (datalen % clk) <= clk/8) {
|
||||||
|
// padd the amount off - could be problematic... but shouldn't happen often
|
||||||
|
datalen += clk - (datalen % clk);
|
||||||
|
} else if ( (datalen % clk) <= clk/8 ) {
|
||||||
|
// padd the amount off - could be problematic... but shouldn't happen often
|
||||||
|
datalen -= datalen % clk;
|
||||||
|
} else {
|
||||||
if (g_debugMode==2) prnt("DEBUG STT: datalen not divisible by clk: %u %% %d = %d - quitting", datalen, clk, datalen % clk);
|
if (g_debugMode==2) prnt("DEBUG STT: datalen not divisible by clk: %u %% %d = %d - quitting", datalen, clk, datalen % clk);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
// padd the amount off - could be problematic... but shouldn't happen often
|
|
||||||
datalen += datalen % clk;
|
|
||||||
}
|
}
|
||||||
// if datalen is less than one t55xx block - ERROR
|
// if datalen is less than one t55xx block - ERROR
|
||||||
if (datalen/clk < 8*4) {
|
if (datalen/clk < 8*4) {
|
||||||
|
@ -1682,8 +1687,20 @@ bool DetectST(uint8_t buffer[], size_t *size, int *foundclock) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
size_t dataloc = start;
|
size_t dataloc = start;
|
||||||
|
if (buffer[dataloc-(clk*4)-(clk/8)] <= low && buffer[dataloc] <= low && buffer[dataloc-(clk*4)] >= high) {
|
||||||
|
//we have low drift (and a low just before the ST and a low just after the ST) - compensate by backing up the start
|
||||||
|
for ( i=0; i <= (clk/8); ++i ) {
|
||||||
|
if ( buffer[dataloc - (clk*4) - i] <= low ) {
|
||||||
|
dataloc -= i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t newloc = 0;
|
size_t newloc = 0;
|
||||||
i=0;
|
i=0;
|
||||||
|
if (g_debugMode==2) prnt("DEBUG STT: Starting STT trim - start: %d, datalen: %d ",dataloc, datalen);
|
||||||
|
|
||||||
// warning - overwriting buffer given with raw wave data with ST removed...
|
// warning - overwriting buffer given with raw wave data with ST removed...
|
||||||
while ( dataloc < bufsize-(clk/2) ) {
|
while ( dataloc < bufsize-(clk/2) ) {
|
||||||
//compensate for long high at end of ST not being high due to signal loss... (and we cut out the start of wave high part)
|
//compensate for long high at end of ST not being high due to signal loss... (and we cut out the start of wave high part)
|
||||||
|
@ -1697,11 +1714,12 @@ bool DetectST(uint8_t buffer[], size_t *size, int *foundclock) {
|
||||||
if (i+newloc < dataloc)
|
if (i+newloc < dataloc)
|
||||||
buffer[i+newloc] = buffer[dataloc];
|
buffer[i+newloc] = buffer[dataloc];
|
||||||
|
|
||||||
dataloc++;
|
dataloc++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newloc += i;
|
newloc += i;
|
||||||
//skip next ST - we just assume it will be there from now on...
|
//skip next ST - we just assume it will be there from now on...
|
||||||
|
if (g_debugMode==2) prnt("DEBUG STT: skipping STT at %d to %d", dataloc, dataloc+(clk*4));
|
||||||
dataloc += clk*4;
|
dataloc += clk*4;
|
||||||
}
|
}
|
||||||
*size = newloc;
|
*size = newloc;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
//generic
|
//generic
|
||||||
size_t addParity(uint8_t *BitSource, uint8_t *dest, uint8_t sourceLen, uint8_t pLen, uint8_t pType);
|
size_t addParity(uint8_t *BitSource, uint8_t *dest, uint8_t sourceLen, uint8_t pLen, uint8_t pType);
|
||||||
int askdemod(uint8_t *BinStream, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType);
|
int askdemod(uint8_t *BinStream, size_t *size, int *clk, int *invert, int maxErr, uint8_t amp, uint8_t askType);
|
||||||
|
void askAmp(uint8_t *BitStream, size_t size);
|
||||||
int BiphaseRawDecode(uint8_t * BitStream, size_t *size, int offset, int invert);
|
int BiphaseRawDecode(uint8_t * BitStream, size_t *size, int offset, int invert);
|
||||||
uint32_t bytebits_to_byte(uint8_t* src, size_t numbits);
|
uint32_t bytebits_to_byte(uint8_t* src, size_t numbits);
|
||||||
uint32_t bytebits_to_byteLSBF(uint8_t* src, size_t numbits);
|
uint32_t bytebits_to_byteLSBF(uint8_t* src, size_t numbits);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue