fix: askdemod - enhances which solves some viking demod errors
This commit is contained in:
@@ -584,7 +584,8 @@ static int Cmdmandecoderaw(const char *Cmd) {
|
||||
size_t size = 0;
|
||||
int high = 0, low = 0;
|
||||
size_t i = 0;
|
||||
int errCnt = 0, invert = 0, maxErr = 20;
|
||||
uint16_t errCnt = 0;
|
||||
int invert = 0, maxErr = 20;
|
||||
char cmdp = tolower(param_getchar(Cmd, 0));
|
||||
if (strlen(Cmd) > 5 || cmdp == 'h') return usage_data_manrawdecode();
|
||||
|
||||
@@ -610,7 +611,7 @@ static int Cmdmandecoderaw(const char *Cmd) {
|
||||
uint8_t alignPos = 0;
|
||||
errCnt = manrawdecode(bits, &size, invert, &alignPos);
|
||||
if (errCnt >= maxErr) {
|
||||
PrintAndLogEx(WARNING, "Too many errors: %d", errCnt);
|
||||
PrintAndLogEx(WARNING, "Too many errors: %u", errCnt);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ static int usage_lf_cotag_read(void) {
|
||||
PrintAndLogEx(NORMAL, "Example:");
|
||||
PrintAndLogEx(NORMAL, " lf cotag read 0");
|
||||
PrintAndLogEx(NORMAL, " lf cotag read 1");
|
||||
return 0;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// COTAG demod should be able to use GraphBuffer,
|
||||
@@ -35,10 +35,10 @@ static int CmdCOTAGDemod(const char *Cmd) {
|
||||
memcpy(bits, DemodBuffer, COTAG_BITS);
|
||||
|
||||
uint8_t alignPos = 0;
|
||||
int err = manrawdecode(bits, &bitlen, 1, &alignPos);
|
||||
if (err) {
|
||||
uint16_t err = manrawdecode(bits, &bitlen, 1, &alignPos);
|
||||
if (err == 0xFFFF) {
|
||||
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - COTAG too many errors: %d", err);
|
||||
return -1;
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
setDemodBuff(bits, bitlen, 0);
|
||||
@@ -60,7 +60,7 @@ static int CmdCOTAGDemod(const char *Cmd) {
|
||||
1001 1100 1100 0001 10000101
|
||||
*/
|
||||
PrintAndLogEx(SUCCESS, "COTAG Found: FC %u, CN: %u Raw: %08X%08X%08X%08X", fc, cn, raw1, raw2, raw3, raw4);
|
||||
return 1;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// When reading a COTAG.
|
||||
@@ -78,7 +78,7 @@ static int CmdCOTAGRead(const char *Cmd) {
|
||||
SendCommandMIX(CMD_COTAG, rawsignal, 0, 0, NULL, 0);
|
||||
if (!WaitForResponseTimeout(CMD_ACK, NULL, 7000)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return -1;
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
switch (rawsignal) {
|
||||
@@ -93,13 +93,13 @@ static int CmdCOTAGRead(const char *Cmd) {
|
||||
|
||||
if (!GetFromDevice(BIG_BUF, DemodBuffer, COTAG_BITS, 0, NULL, 1000, false)) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
return -1;
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
DemodBufferLen = COTAG_BITS;
|
||||
return CmdCOTAGDemod("");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
@@ -112,7 +112,7 @@ static command_t CommandTable[] = {
|
||||
static int CmdHelp(const char *Cmd) {
|
||||
(void)Cmd; // Cmd is not used so far
|
||||
CmdsHelp(CommandTable);
|
||||
return 0;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
int CmdLFCOTAG(const char *Cmd) {
|
||||
@@ -125,5 +125,5 @@ int demodCOTAG(void) {
|
||||
}
|
||||
|
||||
int readCOTAGUid(void) {
|
||||
return CmdCOTAGRead("") > 0;
|
||||
return (CmdCOTAGRead("") == PM3_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -45,10 +45,9 @@ static int CmdVikingDemod(const char *Cmd) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
size_t size = DemodBufferLen;
|
||||
|
||||
int ans = detectViking(DemodBuffer, &size);
|
||||
if (ans < 0) {
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Viking Demod %d %s", ans, (ans == -5) ? "[chksum error]" : "");
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Viking Demod %d %s", ans, (ans == -5) ? _RED_("[chksum error]") : "");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
//got a good demod
|
||||
@@ -56,8 +55,8 @@ static int CmdVikingDemod(const char *Cmd) {
|
||||
uint32_t raw2 = bytebits_to_byte(DemodBuffer + ans + 32, 32);
|
||||
uint32_t cardid = bytebits_to_byte(DemodBuffer + ans + 24, 32);
|
||||
uint8_t checksum = bytebits_to_byte(DemodBuffer + ans + 32 + 24, 8);
|
||||
PrintAndLogEx(SUCCESS, "Viking Tag Found: Card ID %08X, Checksum: %02X", cardid, checksum);
|
||||
PrintAndLogEx(SUCCESS, "Raw: %08X%08X", raw1, raw2);
|
||||
PrintAndLogEx(SUCCESS, "Viking Tag Found: Card ID " _YELLOW_("%08X")" checksum "_YELLOW_("%02X"), cardid, checksum);
|
||||
PrintAndLogEx(SUCCESS, "Raw hex: %08X%08X", raw1, raw2);
|
||||
setDemodBuff(DemodBuffer, 64, ans);
|
||||
setClockGrid(g_DemodClock, g_DemodStartIdx + (ans * g_DemodClock));
|
||||
return PM3_SUCCESS;
|
||||
@@ -86,7 +85,7 @@ static int CmdVikingClone(const char *Cmd) {
|
||||
|
||||
rawID = getVikingBits(id);
|
||||
|
||||
PrintAndLogEx(INFO, "Preparing to clone Viking tag - ID: %08X, Raw: %08X%08X", id, (uint32_t)(rawID >> 32), (uint32_t)(rawID & 0xFFFFFFFF));
|
||||
PrintAndLogEx(INFO, "Preparing to clone Viking tag - ID " _YELLOW_("%08X")" raw " _YELLOW_("%08X%08X"), id, (uint32_t)(rawID >> 32), (uint32_t)(rawID & 0xFFFFFFFF));
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandMIX(CMD_VIKING_CLONE_TAG, rawID >> 32, rawID & 0xFFFFFFFF, Q5, NULL, 0);
|
||||
@@ -109,7 +108,7 @@ static int CmdVikingSim(const char *Cmd) {
|
||||
|
||||
rawID = getVikingBits(id);
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Simulating Viking - ID: %08X, Raw: %08X%08X", id, (uint32_t)(rawID >> 32), (uint32_t)(rawID & 0xFFFFFFFF));
|
||||
PrintAndLogEx(SUCCESS, "Simulating Viking - ID " _YELLOW_("%08X")" raw "_YELLOW_("%08X%08X"), id, (uint32_t)(rawID >> 32), (uint32_t)(rawID & 0xFFFFFFFF));
|
||||
|
||||
uint8_t bs[64];
|
||||
num_to_bytebits(rawID, sizeof(bs), bs);
|
||||
@@ -164,22 +163,23 @@ uint64_t getVikingBits(uint32_t id) {
|
||||
}
|
||||
// by marshmellow
|
||||
// find viking preamble 0xF200 in already demoded data
|
||||
int detectViking(uint8_t *dest, size_t *size) {
|
||||
int detectViking(uint8_t *src, size_t *size) {
|
||||
//make sure buffer has data
|
||||
if (*size < 64 * 2) return -2;
|
||||
if (*size < 64) return -2;
|
||||
size_t startIdx = 0;
|
||||
uint8_t preamble[] = {1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
|
||||
if (!preambleSearch(src, preamble, sizeof(preamble), size, &startIdx))
|
||||
return -4; //preamble not found
|
||||
|
||||
uint32_t checkCalc = bytebits_to_byte(dest + startIdx, 8) ^
|
||||
bytebits_to_byte(dest + startIdx + 8, 8) ^
|
||||
bytebits_to_byte(dest + startIdx + 16, 8) ^
|
||||
bytebits_to_byte(dest + startIdx + 24, 8) ^
|
||||
bytebits_to_byte(dest + startIdx + 32, 8) ^
|
||||
bytebits_to_byte(dest + startIdx + 40, 8) ^
|
||||
bytebits_to_byte(dest + startIdx + 48, 8) ^
|
||||
bytebits_to_byte(dest + startIdx + 56, 8);
|
||||
uint32_t checkCalc = bytebits_to_byte(src + startIdx, 8) ^
|
||||
bytebits_to_byte(src + startIdx + 8, 8) ^
|
||||
bytebits_to_byte(src + startIdx + 16, 8) ^
|
||||
bytebits_to_byte(src + startIdx + 24, 8) ^
|
||||
bytebits_to_byte(src + startIdx + 32, 8) ^
|
||||
bytebits_to_byte(src + startIdx + 40, 8) ^
|
||||
bytebits_to_byte(src + startIdx + 48, 8) ^
|
||||
bytebits_to_byte(src + startIdx + 56, 8);
|
||||
|
||||
if (checkCalc != 0xA8) return -5;
|
||||
if (*size != 64) return -6;
|
||||
//return start position
|
||||
|
||||
Reference in New Issue
Block a user