size_t size;
uint32_t hi2=0, hi=0, lo=0;
int idx=0;
+ int dummyIdx = 0;
// Configure to go in 125Khz listen mode
LFSetupFPGAForADC(95, true);
// FSK demodulator
//size = sizeOfBigBuff; //variable size will change after demod so re initialize it before use
size = 50*128*2; //big enough to catch 2 sequences of largest format
- idx = HIDdemodFSK(dest, &size, &hi2, &hi, &lo);
+ idx = HIDdemodFSK(dest, &size, &hi2, &hi, &lo, &dummyIdx);
if (idx>0 && lo>0 && (size==96 || size==192)){
// go over previously decoded manchester data and decode into usable tag ID
{
uint8_t *dest = BigBuf_get_addr();
size_t size;
- int idx=0;
+ int idx=0, dummyIdx=0;
//clear read buffer
BigBuf_Clear_keep_EM();
// Configure to go in 125Khz listen mode
DoAcquisition_default(-1,true);
// FSK demodulator
size = 50*128*2; //big enough to catch 2 sequences of largest format
- idx = AWIDdemodFSK(dest, &size);
+ idx = AWIDdemodFSK(dest, &size, &dummyIdx);
if (idx<=0 || size!=96) continue;
// Index map
uint8_t version=0;
uint8_t facilitycode=0;
uint16_t number=0;
+ int dummyIdx=0;
//clear read buffer
BigBuf_Clear_keep_EM();
// Configure to go in 125Khz listen mode
DoAcquisition_default(-1,true);
//fskdemod and get start index
WDT_HIT();
- idx = IOdemodFSK(dest, BigBuf_max_traceLen());
+ idx = IOdemodFSK(dest, BigBuf_max_traceLen(), &dummyIdx);
if (idx<0) continue;
//valid tag found
static uint8_t SavedDB[MAX_DEMOD_BUF_LEN];
static size_t SavedDBlen;
static bool DB_Saved = false;
+ static int savedDemodStartIdx = 0;
+ static int savedDemodClock = 0;
if (saveOpt==1) { //save
memcpy(SavedDB, DemodBuffer, sizeof(DemodBuffer));
SavedDBlen = DemodBufferLen;
DB_Saved=true;
+ savedDemodStartIdx = g_DemodStartIdx;
+ savedDemodClock = g_DemodClock;
} else if (DB_Saved) { //restore
memcpy(DemodBuffer, SavedDB, sizeof(DemodBuffer));
DemodBufferLen = SavedDBlen;
+ g_DemodClock = savedDemodClock;
+ g_DemodStartIdx = savedDemodStartIdx;
}
return;
}
if (!rfLen) rfLen = 50;
}
int startIdx = 0;
- int size = fskdemod_ext(BitStream, BitLen, rfLen, invert, fchigh, fclow, &startIdx);
+ int size = fskdemod(BitStream, BitLen, rfLen, invert, fchigh, fclow, &startIdx);
if (size > 0) {
setDemodBuf(BitStream,size,0);
setClockGrid(rfLen, startIdx);
size_t size = getFromGraphBuf(BitStream);
if (size==0) return 0;
+ int waveIdx = 0;
//get binary from fsk wave
- int idx = AWIDdemodFSK(BitStream, &size);
+ int idx = AWIDdemodFSK(BitStream, &size, &waveIdx);
if (idx<=0){
if (g_debugMode){
if (idx == -1)
uint32_t rawHi = bytebits_to_byte(BitStream+idx+32,32);
uint32_t rawHi2 = bytebits_to_byte(BitStream+idx,32);
setDemodBuf(BitStream,96,idx);
- setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock));
+ setClockGrid(50, waveIdx + (idx*50));
size = removeParity(BitStream, idx+8, 4, 1, 88);
if (size != 66){
size_t BitLen = getFromGraphBuf(BitStream);
if (BitLen==0) return 0;
//get binary from fsk wave
- int idx = HIDdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo);
+ int waveIdx = 0;
+ int idx = HIDdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo, &waveIdx);
if (idx<0){
if (g_debugMode){
if (idx==-1){
(unsigned int) fmtLen, (unsigned int) fc, (unsigned int) cardnum);
}
setDemodBuf(BitStream,BitLen,idx);
- setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock));
+ setClockGrid(50, waveIdx + (idx*50));
if (g_debugMode){
PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen);
printDemodBuff();
size_t BitLen = getFromGraphBuf(BitStream);
if (BitLen==0) return 0;
+ int waveIdx = 0;
//get binary from fsk wave
- idx = IOdemodFSK(BitStream,BitLen);
+ idx = IOdemodFSK(BitStream,BitLen, &waveIdx);
if (idx<0){
if (g_debugMode){
if (idx==-1){
PrintAndLog("IO Prox XSF(%02d)%02x:%05d (%08x%08x) [%02x %s]",version,facilitycode,number,code,code2, crc, crcStr);
setDemodBuf(BitStream,64,idx);
- setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock));
+ setClockGrid(64, waveIdx + (idx*64));
if (g_debugMode){
PrintAndLog("DEBUG: idx: %d, Len: %d, Printing demod buffer:",idx,64);
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
size_t BitLen = getFromGraphBuf(BitStream);
if (BitLen==0) return 0;
+ int waveIdx=0;
//get binary from fsk wave
- int idx = ParadoxdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo);
+ int idx = ParadoxdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo,&waveIdx);
if (idx<0){
if (g_debugMode){
if (idx==-1){
PrintAndLog("Paradox TAG ID: %x%08x - FC: %d - Card: %d - Checksum: %02x - RAW: %08x%08x%08x",
hi>>10, (hi & 0x3)<<26 | (lo>>10), fc, cardnum, (lo>>2) & 0xFF, rawHi2, rawHi, rawLo);
setDemodBuf(BitStream,BitLen,idx);
- setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock));
+ setClockGrid(50, waveIdx + (idx*50));
if (g_debugMode){
PrintAndLog("DEBUG: idx: %d, len: %d, Printing Demod Buffer:", idx, BitLen);
printDemodBuff();
size_t size = getFromGraphBuf(BitStream);
if (size==0) return 0;
+ int waveIdx=0;
//get binary from fsk wave
- int idx = PyramiddemodFSK(BitStream, &size);
+ int idx = PyramiddemodFSK(BitStream, &size, &waveIdx);
if (idx < 0){
if (g_debugMode){
if (idx == -5)
uint32_t rawHi2 = bytebits_to_byte(BitStream+idx+32,32);
uint32_t rawHi3 = bytebits_to_byte(BitStream+idx,32);
setDemodBuf(BitStream,128,idx);
- setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock));
+ setClockGrid(50, waveIdx + (idx*50));
size = removeParity(BitStream, idx+8, 8, 1, 120);
if (size != 105){
//by marshmellow (from holiman's base)
// full fsk demod from GraphBuffer wave to decoded 1s and 0s (no mandemod)
-int fskdemod_ext(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx) {
+int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx) {
if (justNoise(dest, size)) return 0;
// FSK demodulator
size = fsk_wave_demod(dest, size, fchigh, fclow, startIdx);
return size;
}
-int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow) {
- int startIdx=0;
- return fskdemod_ext(dest, size, rfLen, invert, fchigh, fclow, &startIdx);
-}
-
// by marshmellow
// convert psk1 demod to psk2 demod
// only transition waves are 1s
// by marshmellow
// FSK Demod then try to locate an AWID ID
-int AWIDdemodFSK(uint8_t *dest, size_t *size) {
+int AWIDdemodFSK(uint8_t *dest, size_t *size, int *waveStartIdx) {
//make sure buffer has enough data
if (*size < 96*50) return -1;
// FSK demodulator
- *size = fskdemod(dest, *size, 50, 1, 10, 8); // fsk2a RF/50
+ *size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // fsk2a RF/50
if (*size < 96) return -3; //did we get a good demod?
uint8_t preamble[] = {0,0,0,0,0,0,0,1};
}
// 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 HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx) {
size_t numStart=0, size2=*size, startIdx=0;
- // FSK demodulator
- *size = fskdemod(dest, size2,50,1,10,8); //fsk2a
+ // FSK demodulator fsk2a so invert and fc/10/8
+ *size = fskdemod(dest, size2, 50, 1, 10, 8, waveStartIdx);
if (*size < 96*2) return -2;
// 00011101 bit pattern represent start of frame, 01 pattern represents a 0 and 10 represents a 1
uint8_t preamble[] = {0,0,0,1,1,1,0,1};
return (int)startIdx;
}
-int IOdemodFSK(uint8_t *dest, size_t size) {
+int IOdemodFSK(uint8_t *dest, size_t size, int *waveStartIdx) {
//make sure buffer has data
if (size < 66*64) return -2;
- // FSK demodulator
- size = fskdemod(dest, size, 64, 1, 10, 8); // FSK2a RF/64
+ // FSK demodulator RF/64, fsk2a so invert, and fc/10/8
+ size = fskdemod(dest, size, 64, 1, 10, 8, waveStartIdx);
if (size < 65) return -3; //did we get a good demod?
//Index map
//0 10 20 30 40 50 60
}
// loop to get raw paradox waveform then FSK demodulate the TAG ID from it
-int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo) {
+int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx) {
size_t numStart=0, size2=*size, startIdx=0;
// FSK demodulator
- *size = fskdemod(dest, size2,50,1,10,8); //fsk2a
+ *size = fskdemod(dest, size2,50,1,10,8,waveStartIdx); //fsk2a
if (*size < 96) return -2;
// 00001111 bit pattern represent start of frame, 01 pattern represents a 0 and 10 represents a 1
// by marshmellow
// FSK Demod then try to locate a Farpointe Data (pyramid) ID
-int PyramiddemodFSK(uint8_t *dest, size_t *size) {
+int PyramiddemodFSK(uint8_t *dest, size_t *size, int *waveStartIdx) {
//make sure buffer has data
if (*size < 128*50) return -5;
// FSK demodulator
- *size = fskdemod(dest, *size, 50, 1, 10, 8); // fsk2a RF/50
+ *size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // fsk2a RF/50
if (*size < 128) return -2; //did we get a good demod?
uint8_t preamble[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
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 int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow);
-extern int fskdemod_ext(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx);
+extern int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx);
extern int getHiLo(uint8_t *BitStream, size_t size, int *high, int *low, uint8_t fuzzHi, uint8_t fuzzLo);
extern uint32_t manchesterEncode2Bytes(uint16_t datain);
extern int ManchesterEncode(uint8_t *BitStream, size_t size);
extern size_t removeParity(uint8_t *BitStream, size_t startIdx, uint8_t pLen, uint8_t pType, size_t bLen);
//tag specific
-extern int AWIDdemodFSK(uint8_t *dest, size_t *size);
+extern int AWIDdemodFSK(uint8_t *dest, size_t *size, int *waveStartIdx);
extern uint8_t Em410xDecode(uint8_t *BitStream, size_t *size, size_t *startIdx, uint32_t *hi, uint64_t *lo);
extern int FDXBdemodBI(uint8_t *dest, size_t *size);
extern int gProxII_Demod(uint8_t BitStream[], size_t *size);
-extern int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo);
-extern int IOdemodFSK(uint8_t *dest, size_t size);
+extern int HIDdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx);
+extern int IOdemodFSK(uint8_t *dest, size_t size, int *waveStartIdx);
extern int indala26decode(uint8_t *bitStream, size_t *size, uint8_t *invert);
-extern int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo);
+extern int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx);
extern int PrescoDemod(uint8_t *dest, size_t *size);
-extern int PyramiddemodFSK(uint8_t *dest, size_t *size);
+extern int PyramiddemodFSK(uint8_t *dest, size_t *size, int *waveStartIdx);
extern int VikingDemod_AM(uint8_t *dest, size_t *size);
extern int Visa2kDemod_AM(uint8_t *dest, size_t *size);