int ledcontrol = 1;
int n=0, i=0;
uint8_t clk = (arg1 >> 8) & 0xFF;
- uint8_t manchester = arg1 & 1;
+ uint8_t encoding = arg1 & 1;
uint8_t separator = arg2 & 1;
uint8_t invert = (arg2 >> 8) & 1;
- for (i=0; i<size; i++){
+
+ if (encoding==2){ //biphase
+ uint8_t phase=0;
- askSimBit(BitStream[i]^invert, &n, clk, manchester);
+ for (i=0; i<size; i++){
- }
+ biphaseSimBit(BitStream[i]^invert, &n, clk, &phase);
- if (manchester==0 && BitStream[0]==BitStream[size-1]){ //run a second set inverted (for biphase phase)
+ }
- for (i=0; i<size; i++){
+ if (BitStream[0]==BitStream[size-1]){ //run a second set inverted to keep phase in check
- askSimBit(BitStream[i]^invert^1, &n, clk, manchester);
+ for (i=0; i<size; i++){
- }
+ biphaseSimBit(BitStream[i]^invert, &n, clk, &phase);
+ }
+ }
+ } else { // ask/manchester || ask/raw
+ for (i=0; i<size; i++){
+ askSimBit(BitStream[i]^invert, &n, clk, encoding);
+ }
+ if (encoding==0 && BitStream[0]==BitStream[size-1]){ //run a second set inverted (for biphase phase)
+ for (i=0; i<size; i++){
+ askSimBit(BitStream[i]^invert^1, &n, clk, encoding);
++ }
}
}
+
if (separator==1) Dbprintf("sorry but separator option not yet available");
- Dbprintf("Simulating with clk: %d, invert: %d, manchester: %d, separator: %d, n: %d",clk, invert, manchester, separator, n);
+ Dbprintf("Simulating with clk: %d, invert: %d, encoding: %d, separator: %d, n: %d",clk, invert, encoding, separator, n);
//DEBUG
//Dbprintf("First 32:");
//uint8_t *dest = BigBuf_get_addr();
{
uint8_t *dest = BigBuf_get_addr();
- size_t size=0, idx=0;
+ size_t size=0, idx=0;
int clk=0, invert=0, errCnt=0, maxErr=20;
+ uint32_t hi=0;
uint64_t lo=0;
// Configure to go in 125Khz listen mode
LFSetupFPGAForADC(95, true);
WDT_HIT();
if (errCnt>=0){
- lo = Em410xDecode(dest, &size, &idx);
+ errCnt = Em410xDecode(dest, &size, &idx, &hi, &lo);
//Dbprintf("DEBUG: EM GOT");
- if (lo>0){
+ if (errCnt){
+ if (size>64){
+ Dbprintf("EM XL TAG ID: %06x%08x%08x - (%05d_%03d_%08d)",
+ hi,
+ (uint32_t)(lo>>32),
+ (uint32_t)lo,
+ (uint32_t)(lo&0xFFFF),
+ (uint32_t)((lo>>16LL) & 0xFF),
+ (uint32_t)(lo & 0xFFFFFF));
+ } else {
- Dbprintf("EM TAG ID: %02x%08x - (%05d_%03d_%08d)",
- (uint32_t)(lo>>32),
- (uint32_t)lo,
- (uint32_t)(lo&0xFFFF),
- (uint32_t)((lo>>16LL) & 0xFF),
- (uint32_t)(lo & 0xFFFFFF));
- }
+ Dbprintf("EM TAG ID: %02x%08x - (%05d_%03d_%08d)",
+ (uint32_t)(lo>>32),
+ (uint32_t)lo,
+ (uint32_t)(lo&0xFFFF),
+ (uint32_t)((lo>>16LL) & 0xFF),
+ (uint32_t)(lo & 0xFFFFFF));
+ }
+ }
if (findone){
if (ledcontrol) LED_A_OFF();
*high=lo>>32;
id2lo=(id2lo<<1LL) | ((id & (iii << (i+((ii-1)*8)))) >> (i+((ii-1)*8)));
}
}
- //output em id
+ if (hi){
+ //output 88 bit em id
+ PrintAndLog("EM TAG ID : %06x%016llx", hi, id);
+ } else{
+ //output 40 bit em id
- PrintAndLog("EM TAG ID : %010llx", id);
- PrintAndLog("Unique TAG ID: %010llx", id2lo);
- PrintAndLog("DEZ 8 : %08lld",id & 0xFFFFFF);
- PrintAndLog("DEZ 10 : %010lld",id & 0xFFFFFF);
- PrintAndLog("DEZ 5.5 : %05lld.%05lld",(id>>16LL) & 0xFFFF,(id & 0xFFFF));
- PrintAndLog("DEZ 3.5A : %03lld.%05lld",(id>>32ll),(id & 0xFFFF));
- PrintAndLog("DEZ 14/IK2 : %014lld",id);
- PrintAndLog("DEZ 15/IK3 : %015lld",id2lo);
+ PrintAndLog("EM TAG ID : %010llx", id);
+ PrintAndLog("Unique TAG ID: %010llx", id2lo);
+ PrintAndLog("DEZ 8 : %08lld",id & 0xFFFFFF);
+ PrintAndLog("DEZ 10 : %010lld",id & 0xFFFFFF);
+ PrintAndLog("DEZ 5.5 : %05lld.%05lld",(id>>16LL) & 0xFFFF,(id & 0xFFFF));
+ PrintAndLog("DEZ 3.5A : %03lld.%05lld",(id>>32ll),(id & 0xFFFF));
+ PrintAndLog("DEZ 14/IK2 : %014lld",id);
+ PrintAndLog("DEZ 15/IK3 : %015lld",id2lo);
- PrintAndLog("Other : %05lld_%03lld_%08lld",(id&0xFFFF),((id>>16LL) & 0xFF),(id & 0xFFFFFF));
+ PrintAndLog("Other : %05lld_%03lld_%08lld",(id&0xFFFF),((id>>16LL) & 0xFF),(id & 0xFFFFFF));
- }
++ }
}
return;
}
//if successful it will push askraw data back to demod buffer ready for emulation
int CmdG_Prox_II_Demod(const char *Cmd)
{
- int ans = ASKrawDemod(Cmd, FALSE);
- if (ans <= 0) {
- if (g_debugMode) PrintAndLog("Error AskrawDemod: %d",ans);
- return ans;
+ if (!ASKbiphaseDemod(Cmd, FALSE)){
+ if (g_debugMode) PrintAndLog("ASKbiphaseDemod failed 1st try");
+ return 0;
}
size_t size = DemodBufferLen;
- ans = BiphaseRawDecode(DemodBuffer, &size, 0, 0);
- if (ans !=0) {
- if (g_debugMode) PrintAndLog("Error BiphaseRawDecode: %d",ans);
- return ans;
- }
//call lfdemod.c demod for gProxII
- ans = gProxII_Demod(DemodBuffer, &size);
+ int ans = gProxII_Demod(DemodBuffer, &size);
if (ans < 0){
- if (g_debugMode) PrintAndLog("Error gProxII_Demod 1st Try: %d",ans);
- //try biphase again
- ans = BiphaseRawDecode(DemodBuffer, &size, 1, 0);
- if (ans != 0) {
- if (g_debugMode) PrintAndLog("Error BiphaseRawDecode: %d",ans);
- return ans;
- }
- ans = gProxII_Demod(DemodBuffer, &size);
- if (ans < 0) {
- if (g_debugMode) PrintAndLog("Error gProxII_Demod 1st Try: %d",ans);
- return ans;
+ if (g_debugMode) PrintAndLog("Error gProxII_Demod");
+ return 0;
- }
+ }
- }
//got a good demod
uint32_t ByteStream[65] = {0x00};
uint8_t xorKey=0;
sum += (GraphBuffer[j]*GraphBuffer[i + j]) / 256;
}
CorrelBuffer[i] = sum;
- }
+ if (sum >= maxSum-100 && sum <= maxSum+100){
+ //another max
+ Correlation = i-lastMax;
+ lastMax = i;
+ if (sum > maxSum) maxSum = sum;
+ } else if (sum > maxSum){
+ maxSum=sum;
+ lastMax = i;
++ }
+ }
+ if (Correlation==0){
+ //try again with wider margin
+ for (int i = 0; i < GraphTraceLen - window; i++){
+ if (CorrelBuffer[i] >= maxSum-(maxSum*0.05) && CorrelBuffer[i] <= maxSum+(maxSum*0.05)){
+ //another max
+ Correlation = i-lastMax;
+ lastMax = i;
+ //if (CorrelBuffer[i] > maxSum) maxSum = sum;
+ }
+ }
}
- GraphTraceLen = GraphTraceLen - window;
- memcpy(GraphBuffer, CorrelBuffer, GraphTraceLen * sizeof (int));
+ if (verbose && Correlation > 0) PrintAndLog("Possible Correlation: %d samples",Correlation);
+
+ if (SaveGrph){
+ GraphTraceLen = GraphTraceLen - window;
+ memcpy(GraphBuffer, CorrelBuffer, GraphTraceLen * sizeof (int));
+ RepaintGraphWindow();
+ }
+ return Correlation;
+ }
- RepaintGraphWindow();
+ int usage_data_autocorr(void)
+ {
+ //print help
+ PrintAndLog("Usage: data autocorr [window] [g]");
+ PrintAndLog("Options: ");
+ PrintAndLog(" h This help");
+ PrintAndLog(" [window] window length for correlation - default = 4000");
+ PrintAndLog(" g save back to GraphBuffer (overwrite)");
return 0;
}
//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;
+ waveEnd = i+1;
+ //PrintAndLog("DEBUG: waveEnd: %d",waveEnd);
+ waveLenCnt = waveEnd-waveStart;
- lastAvgWaveVal = avgWaveVal/waveLenCnt;
- if (waveLenCnt > fc){
+ 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
+ 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;
+ if (lastAvgWaveVal > 123) curPhase^=1; //fudge graph 0 a little 123 vs 128
- break;
- }
+ break;
+ }
- waveStart=0;
- avgWaveVal=0;
+ waveStart = i+1;
+ avgWaveVal = 0;
- }
+ }
+ avgWaveVal+=dest[i+2];
- }
+ }
- avgWaveVal+=dest[i+1];
- }
//PrintAndLog("DEBUG: firstFullWave: %d, waveLen: %d",firstFullWave,fullWaveLen);
lastClkBit = firstFullWave; //set start of wave as clock align
+ //PrintAndLog("DEBUG: clk: %d, lastClkBit: %d", *clock, lastClkBit);
waveStart = 0;
errCnt=0;
size_t numBits=0;