Merge pull request #84 from marshmellow42/master

EM410x bug fix
This commit is contained in:
Martin Holst Swende 2015-03-25 11:10:51 +01:00
commit 062e28912c
3 changed files with 46 additions and 51 deletions

View file

@ -896,6 +896,7 @@ void CmdEM410xdemod(int findone, int *high, int *low, int ledcontrol)
//Dbprintf("DEBUG: No Tag"); //Dbprintf("DEBUG: No Tag");
} }
WDT_HIT(); WDT_HIT();
hi = 0;
lo = 0; lo = 0;
clk=0; clk=0;
invert=0; invert=0;

View file

@ -280,24 +280,22 @@ void printEM410x(uint32_t hi, uint64_t id)
} }
if (hi){ if (hi){
//output 88 bit em id //output 88 bit em id
PrintAndLog("EM TAG ID : %06x%016llx", hi, id); PrintAndLog("\nEM TAG ID : %06x%016llx", hi, id);
} else{ } else{
//output 40 bit em id //output 40 bit em id
PrintAndLog("EM TAG ID : %010llx", id); PrintAndLog("\nEM TAG ID : %010llx", id);
PrintAndLog("Unique TAG ID: %010llx", id2lo); PrintAndLog("Unique TAG ID : %010llx", id2lo);
PrintAndLog(""); PrintAndLog("\nPossible de-scramble patterns");
PrintAndLog("Possible de-scramble patterns"); PrintAndLog("HoneyWell IdentKey {");
PrintAndLog("HoneyWell IdentKey"); PrintAndLog("DEZ 8 : %08lld",id & 0xFFFFFF);
PrintAndLog("DEZ 8 : %08lld",id & 0xFFFFFF); PrintAndLog("DEZ 10 : %010lld",id & 0xFFFFFFFF);
PrintAndLog("DEZ 10 : %010lld",id & 0xFFFFFFFF); PrintAndLog("DEZ 5.5 : %05lld.%05lld",(id>>16LL) & 0xFFFF,(id & 0xFFFF));
PrintAndLog("DEZ 5.5 : %05lld.%05lld",(id>>16LL) & 0xFFFF,(id & 0xFFFF)); PrintAndLog("DEZ 3.5A : %03lld.%05lld",(id>>32ll),(id & 0xFFFF));
PrintAndLog("DEZ 3.5A : %03lld.%05lld",(id>>32ll),(id & 0xFFFF)); PrintAndLog("DEZ 3.5B : %03lld.%05lld",(id & 0xFF000000) >> 24,(id & 0xFFFF));
PrintAndLog("DEZ 3.5B : %03lld.%05lld",(id & 0xFF000000) >> 24,(id & 0xFFFF)); PrintAndLog("DEZ 3.5C : %03lld.%05lld",(id & 0xFF0000) >> 16,(id & 0xFFFF));
PrintAndLog("DEZ 3.5C : %03lld.%05lld",(id & 0xFF0000) >> 16,(id & 0xFFFF)); PrintAndLog("DEZ 14/IK2 : %014lld",id);
PrintAndLog("DEZ 14/IK2 : %014lld",id); PrintAndLog("DEZ 15/IK3 : %015lld",id2lo);
PrintAndLog("DEZ 15/IK3 : %015lld",id2lo); PrintAndLog("DEZ 20/ZK : %02lld%02lld%02lld%02lld%02lld%02lld%02lld%02lld%02lld%02lld",
PrintAndLog("Other : %05lld_%03lld_%08lld",(id&0xFFFF),((id>>16LL) & 0xFF),(id & 0xFFFFFF));
PrintAndLog("DEZ 20/ZK : %02lld%02lld%02lld%02lld%02lld%02lld%02lld%02lld%02lld%02lld",
(id2lo & 0xf000000000) >> 36, (id2lo & 0xf000000000) >> 36,
(id2lo & 0x0f00000000) >> 32, (id2lo & 0x0f00000000) >> 32,
(id2lo & 0x00f0000000) >> 28, (id2lo & 0x00f0000000) >> 28,
@ -309,10 +307,9 @@ void printEM410x(uint32_t hi, uint64_t id)
(id2lo & 0x00000000f0) >> 4, (id2lo & 0x00000000f0) >> 4,
(id2lo & 0x000000000f) (id2lo & 0x000000000f)
); );
PrintAndLog("");
uint64_t paxton = (((id>>32) << 24) | (id & 0xffffff)) + 0x143e00; uint64_t paxton = (((id>>32) << 24) | (id & 0xffffff)) + 0x143e00;
PrintAndLog("Pattern Paxton : %0d", paxton); PrintAndLog("}\nOther : %05lld_%03lld_%08lld",(id&0xFFFF),((id>>16LL) & 0xFF),(id & 0xFFFFFF));
PrintAndLog("Pattern Paxton : %0d", paxton);
uint32_t p1id = (id & 0xFFFFFF); uint32_t p1id = (id & 0xFFFFFF);
uint8_t arr[32] = {0x00}; uint8_t arr[32] = {0x00};
@ -353,12 +350,12 @@ void printEM410x(uint32_t hi, uint64_t id)
p1 |= arr[2] << 4; p1 |= arr[2] << 4;
p1 |= arr[1] << 5; p1 |= arr[1] << 5;
p1 |= arr[0] << 9; p1 |= arr[0] << 9;
PrintAndLog("Pattern 1 : 0x%X - %d", p1, p1); PrintAndLog("Pattern 1 : 0x%X - %d", p1, p1);
uint16_t sebury1 = id & 0xFFFF; uint16_t sebury1 = id & 0xFFFF;
uint8_t sebury2 = (id >> 16) & 0x7F; uint8_t sebury2 = (id >> 16) & 0x7F;
uint32_t sebury3 = id & 0x7FFFFF; uint32_t sebury3 = id & 0x7FFFFF;
PrintAndLog("Pattern Sebury : %d %d %d (hex: %X %X %X)", sebury1, sebury2, sebury3, sebury1, sebury2, sebury3); PrintAndLog("Pattern Sebury : %d %d %d (hex: %X %X %X)", sebury1, sebury2, sebury3, sebury1, sebury2, sebury3);
} }
} }
return; return;
@ -400,8 +397,8 @@ int CmdAskEM410xDemod(const char *Cmd)
PrintAndLog(" : data askem410xdemod 64 1 0 = demod an EM410x Tag ID from GraphBuffer using a clock of RF/64 and inverting data and allowing 0 demod errors"); PrintAndLog(" : data askem410xdemod 64 1 0 = demod an EM410x Tag ID from GraphBuffer using a clock of RF/64 and inverting data and allowing 0 demod errors");
return 0; return 0;
} }
uint32_t hi; uint32_t hi = 0;
uint64_t lo; uint64_t lo = 0;
if (AskEm410xDemod(Cmd, &hi, &lo)) { if (AskEm410xDemod(Cmd, &hi, &lo)) {
PrintAndLog("EM410x pattern found: "); PrintAndLog("EM410x pattern found: ");
printEM410x(hi, lo); printEM410x(hi, lo);

View file

@ -88,37 +88,34 @@ uint8_t Em410xDecode(uint8_t *BitStream, size_t *size, size_t *startIdx, uint32_
return 0; return 0;
} }
// 111111111 bit pattern represent start of frame // 111111111 bit pattern represent start of frame
uint8_t preamble[] = {1,1,1,1,1,1,1,1,1}; // include 0 in front to help get start pos
uint8_t preamble[] = {0,1,1,1,1,1,1,1,1,1};
uint32_t idx = 0; uint32_t idx = 0;
uint32_t parityBits = 0; uint32_t parityBits = 0;
uint8_t errChk = 0; uint8_t errChk = 0;
uint8_t FmtLen = 10; uint8_t FmtLen = 10;
*startIdx = 0; *startIdx = 0;
for (uint8_t extraBitChk=0; extraBitChk<5; extraBitChk++){ errChk = preambleSearch(BitStream, preamble, sizeof(preamble), size, startIdx);
errChk = preambleSearch(BitStream+extraBitChk+*startIdx, preamble, sizeof(preamble), size, startIdx); if (errChk == 0 || *size < 64) return 0;
if (errChk == 0) return 0; if (*size > 64) FmtLen = 22;
if (*size>64) FmtLen = 22; *startIdx += 1; //get rid of 0 from preamble
if (*size<64) return 0; idx = *startIdx + 9;
idx = *startIdx + 9; for (i=0; i<FmtLen; i++){ //loop through 10 or 22 sets of 5 bits (50-10p = 40 bits or 88 bits)
for (i=0; i<FmtLen; i++){ //loop through 10 or 22 sets of 5 bits (50-10p = 40 bits or 88 bits) parityBits = bytebits_to_byte(BitStream+(i*5)+idx,5);
parityBits = bytebits_to_byte(BitStream+(i*5)+idx,5); //check even parity
//check even parity if (parityTest(parityBits, 5, 0) == 0){
if (parityTest(parityBits, 5, 0) == 0){ //parity failed quit
//parity failed try next bit (in the case of 1111111111) but last 9 = preamble return 0;
startIdx++; }
errChk = 0; //set uint64 with ID from BitStream
break; for (uint8_t ii=0; ii<4; ii++){
} *hi = (*hi << 1) | (*lo >> 63);
//set uint64 with ID from BitStream *lo = (*lo << 1) | (BitStream[(i*5)+ii+idx]);
for (uint8_t ii=0; ii<4; ii++){
*hi = (*hi << 1) | (*lo >> 63);
*lo = (*lo << 1) | (BitStream[(i*5)+ii+idx]);
}
} }
if (errChk != 0) return 1;
//skip last 5 bit parity test for simplicity.
// *size = 64 | 128;
} }
if (errChk != 0) return 1;
//skip last 5 bit parity test for simplicity.
// *size = 64 | 128;
return 0; return 0;
} }