mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-20 21:33:19 -07:00
data psk demod minor fixes, pyramid demod add CS
also adjusted autocorrelate and added a printout for lf search u
This commit is contained in:
parent
1302428367
commit
73d04bb417
6 changed files with 104 additions and 50 deletions
15
common/crc.c
15
common/crc.c
|
@ -5,8 +5,9 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Generic CRC calculation code.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "crc.h"
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
void crc_init(crc_t *crc, int order, uint32_t polynom, uint32_t initial_value, uint32_t final_xor)
|
||||
{
|
||||
|
@ -40,3 +41,15 @@ uint32_t crc_finish(crc_t *crc)
|
|||
{
|
||||
return ( crc->state ^ crc->final_xor ) & crc->mask;
|
||||
}
|
||||
|
||||
uint32_t CRC8Maxim(uint8_t *buff, size_t size )
|
||||
{
|
||||
crc_t crc;
|
||||
crc_init(&crc, 9, 0x8c, 0x00, 0x00);
|
||||
crc_clear(&crc);
|
||||
|
||||
for (size_t i=0; i < size; ++i){
|
||||
crc_update(&crc, buff[i], 8);
|
||||
}
|
||||
return crc_finish(&crc);
|
||||
}
|
||||
|
|
51
common/crc.h
Normal file
51
common/crc.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Generic CRC calculation code.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CRC_H
|
||||
#define __CRC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct crc {
|
||||
uint32_t state;
|
||||
int order;
|
||||
uint32_t polynom;
|
||||
uint32_t initial_value;
|
||||
uint32_t final_xor;
|
||||
uint32_t mask;
|
||||
} crc_t;
|
||||
|
||||
/* Initialize a crc structure. order is the order of the polynom, e.g. 32 for a CRC-32
|
||||
* polynom is the CRC polynom. initial_value is the initial value of a clean state.
|
||||
* final_xor is XORed onto the state before returning it from crc_result(). */
|
||||
extern void crc_init(crc_t *crc, int order, uint32_t polynom, uint32_t initial_value, uint32_t final_xor);
|
||||
|
||||
/* Update the crc state. data is the data of length data_width bits (only the the
|
||||
* data_width lower-most bits are used).
|
||||
*/
|
||||
extern void crc_update(crc_t *crc, uint32_t data, int data_width);
|
||||
|
||||
/* Clean the crc state, e.g. reset it to initial_value */
|
||||
extern void crc_clear(crc_t *crc);
|
||||
|
||||
/* Get the result of the crc calculation */
|
||||
extern uint32_t crc_finish(crc_t *crc);
|
||||
|
||||
// Calculate CRC-8/Maxim checksum
|
||||
uint32_t CRC8Maxim(uint8_t *buff, size_t size );
|
||||
/* Static initialization of a crc structure */
|
||||
#define CRC_INITIALIZER(_order, _polynom, _initial_value, _final_xor) { \
|
||||
.state = ((_initial_value) & ((1L<<(_order))-1)), \
|
||||
.order = (_order), \
|
||||
.polynom = (_polynom), \
|
||||
.initial_value = (_initial_value), \
|
||||
.final_xor = (_final_xor), \
|
||||
.mask = ((1L<<(_order))-1) }
|
||||
|
||||
#endif /* __CRC_H */
|
|
@ -1589,7 +1589,7 @@ int pskRawDemod(uint8_t dest[], size_t *size, int *clock, int *invert)
|
|||
if (*size<loopCnt) loopCnt = *size;
|
||||
|
||||
uint8_t curPhase = *invert;
|
||||
size_t i, waveStart=0, waveEnd=0, firstFullWave=0, lastClkBit=0;
|
||||
size_t i, waveStart=1, waveEnd=0, firstFullWave=0, lastClkBit=0;
|
||||
uint8_t fc=0, fullWaveLen=0, tol=1;
|
||||
uint16_t errCnt=0, waveLenCnt=0;
|
||||
fc = countPSK_FC(dest, *size);
|
||||
|
@ -1601,27 +1601,21 @@ int pskRawDemod(uint8_t dest[], size_t *size, int *clock, int *invert)
|
|||
//find first phase shift
|
||||
for (i=0; i<loopCnt; i++){
|
||||
if (dest[i]+fc < dest[i+1] && dest[i+1] >= dest[i+2]){
|
||||
if (waveStart == 0) {
|
||||
waveStart = i+1;
|
||||
avgWaveVal=dest[i+1];
|
||||
//PrintAndLog("DEBUG: waveStart: %d",waveStart);
|
||||
} else {
|
||||
waveEnd = i+1;
|
||||
//PrintAndLog("DEBUG: waveEnd: %d",waveEnd);
|
||||
waveLenCnt = waveEnd-waveStart;
|
||||
lastAvgWaveVal = avgWaveVal/waveLenCnt;
|
||||
if (waveLenCnt > fc){
|
||||
firstFullWave = waveStart;
|
||||
fullWaveLen=waveLenCnt;
|
||||
//if average wave value is > graph 0 then it is an up wave or a 1
|
||||
if (lastAvgWaveVal > 128) curPhase^=1;
|
||||
break;
|
||||
}
|
||||
waveStart=0;
|
||||
avgWaveVal=0;
|
||||
}
|
||||
waveEnd = i+1;
|
||||
//PrintAndLog("DEBUG: waveEnd: %d",waveEnd);
|
||||
waveLenCnt = waveEnd-waveStart;
|
||||
if (waveLenCnt > fc && waveStart > fc){ //not first peak and is a large wave
|
||||
lastAvgWaveVal = avgWaveVal/(waveLenCnt);
|
||||
firstFullWave = waveStart;
|
||||
fullWaveLen=waveLenCnt;
|
||||
//if average wave value is > graph 0 then it is an up wave or a 1
|
||||
if (lastAvgWaveVal > 123) curPhase^=1; //fudge graph 0 a little 123 vs 128
|
||||
break;
|
||||
}
|
||||
waveStart = i+1;
|
||||
avgWaveVal = 0;
|
||||
}
|
||||
avgWaveVal+=dest[i+1];
|
||||
avgWaveVal+=dest[i+2];
|
||||
}
|
||||
//PrintAndLog("DEBUG: firstFullWave: %d, waveLen: %d",firstFullWave,fullWaveLen);
|
||||
lastClkBit = firstFullWave; //set start of wave as clock align
|
||||
|
@ -1629,7 +1623,7 @@ int pskRawDemod(uint8_t dest[], size_t *size, int *clock, int *invert)
|
|||
errCnt=0;
|
||||
size_t numBits=0;
|
||||
//PrintAndLog("DEBUG: clk: %d, lastClkBit: %d", *clock, lastClkBit);
|
||||
|
||||
dest[numBits++] = curPhase; //set first read bit
|
||||
for (i = firstFullWave+fullWaveLen-1; i < *size-3; i++){
|
||||
//top edge of wave = start of new wave
|
||||
if (dest[i]+fc < dest[i+1] && dest[i+1] >= dest[i+2]){
|
||||
|
@ -1641,26 +1635,23 @@ int pskRawDemod(uint8_t dest[], size_t *size, int *clock, int *invert)
|
|||
waveEnd = i+1;
|
||||
waveLenCnt = waveEnd-waveStart;
|
||||
lastAvgWaveVal = avgWaveVal/waveLenCnt;
|
||||
if (waveLenCnt > fc){
|
||||
if (waveLenCnt > fc){
|
||||
//PrintAndLog("DEBUG: avgWaveVal: %d, waveSum: %d",lastAvgWaveVal,avgWaveVal);
|
||||
//if this wave is a phase shift
|
||||
//PrintAndLog("DEBUG: phase shift at: %d, len: %d, nextClk: %d, i: %d, fc: %d",waveStart,waveLenCnt,lastClkBit+*clock-tol,i+1,fc);
|
||||
if (i+1 >= lastClkBit + *clock - tol){ //should be a clock bit
|
||||
curPhase^=1;
|
||||
dest[numBits] = curPhase;
|
||||
numBits++;
|
||||
dest[numBits++] = curPhase;
|
||||
lastClkBit += *clock;
|
||||
} else if (i<lastClkBit+10){
|
||||
} else if (i<lastClkBit+10+fc){
|
||||
//noise after a phase shift - ignore
|
||||
} else { //phase shift before supposed to based on clock
|
||||
errCnt++;
|
||||
dest[numBits] = 77;
|
||||
numBits++;
|
||||
dest[numBits++] = 77;
|
||||
}
|
||||
} else if (i+1 > lastClkBit + *clock + tol + fc){
|
||||
lastClkBit += *clock; //no phase shift but clock bit
|
||||
dest[numBits] = curPhase;
|
||||
numBits++;
|
||||
dest[numBits++] = curPhase;
|
||||
}
|
||||
avgWaveVal=0;
|
||||
waveStart=i+1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue