proxmark3/client/cmdlfnexwatch.c

112 lines
3.6 KiB
C
Raw Normal View History

//-----------------------------------------------------------------------------
//
// 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.
//-----------------------------------------------------------------------------
// Low frequency Honeywell NexWatch tag commands
// PSK1 RF/16, RF/2, 128 bits long (known)
//-----------------------------------------------------------------------------
#include "cmdlfnexwatch.h"
static int CmdHelp(const char *Cmd);
int detectNexWatch(uint8_t *dest, size_t *size, bool *invert) {
2019-03-10 07:00:59 +08:00
uint8_t preamble[28] = {0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t preamble_i[28] = {1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
2019-03-10 06:35:06 +08:00
// sanity check.
2019-03-10 07:00:59 +08:00
if (*size < sizeof(preamble) + 100) return -1;
2019-03-10 06:35:06 +08:00
size_t startIdx = 0;
2019-03-10 07:00:59 +08:00
if (!preambleSearch(DemodBuffer, preamble, sizeof(preamble), size, &startIdx)) {
2019-03-10 06:35:06 +08:00
// if didn't find preamble try again inverting
if (!preambleSearch(DemodBuffer, preamble_i, sizeof(preamble_i), size, &startIdx)) return -4;
*invert ^= 1;
}
2019-03-10 06:35:06 +08:00
// size tests?
return (int) startIdx;
}
int CmdNexWatchDemod(const char *Cmd) {
2019-03-10 06:35:06 +08:00
if (!PSKDemod("", false)) {
PrintAndLogEx(DEBUG, "DEBUG: Error - NexWatch can't demod signal");
return 0;
}
bool invert = false;
size_t size = DemodBufferLen;
int idx = detectNexWatch(DemodBuffer, &size, &invert);
if (idx <= 0) {
2019-03-10 07:00:59 +08:00
if (idx == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - NexWatch not enough samples");
// else if (idx == -2)
// PrintAndLogEx(DEBUG, "DEBUG: Error - NexWatch only noise found");
// else if (idx == -3)
// PrintAndLogEx(DEBUG, "DEBUG: Error - NexWatch problem during PSK demod");
else if (idx == -4)
PrintAndLogEx(DEBUG, "DEBUG: Error - NexWatch preamble not found");
// else if (idx == -5)
// PrintAndLogEx(DEBUG, "DEBUG: Error - NexWatch size not correct: %d", size);
else
PrintAndLogEx(DEBUG, "DEBUG: Error - NexWatch error %d", idx);
2019-03-10 06:35:06 +08:00
return 0;
}
2019-04-07 03:46:00 +08:00
setDemodBuff(DemodBuffer, size, idx + 4);
2019-03-10 07:00:59 +08:00
setClockGrid(g_DemodClock, g_DemodStartIdx + ((idx + 4)*g_DemodClock));
2019-03-10 06:35:06 +08:00
2019-03-10 07:00:59 +08:00
idx = 8 + 32; // 8 = preamble, 32 = reserved bits (always 0)
2019-03-10 06:35:06 +08:00
//get ID
uint32_t ID = 0;
2019-03-10 07:00:59 +08:00
for (uint8_t k = 0; k < 4; k++) {
for (uint8_t m = 0; m < 8; m++) {
ID = (ID << 1) | DemodBuffer[m + k + (m * 4)];
2019-03-10 06:35:06 +08:00
}
}
//parity check (TBD)
//checksum check (TBD)
//output
PrintAndLogEx(NORMAL, "NexWatch ID: %d", ID);
2019-03-10 07:00:59 +08:00
if (invert) {
2019-03-10 06:35:06 +08:00
PrintAndLogEx(NORMAL, "Had to Invert - probably NexKey");
for (size_t i = 0; i < size; i++)
DemodBuffer[i] ^= 1;
}
CmdPrintDemodBuff("x");
return 1;
}
//by marshmellow
//see ASKDemod for what args are accepted
int CmdNexWatchRead(const char *Cmd) {
2019-03-10 06:35:06 +08:00
lf_read(true, 10000);
return CmdNexWatchDemod(Cmd);
}
static command_t CommandTable[] = {
2019-03-10 06:35:06 +08:00
{"help", CmdHelp, 1, "This help"},
{"demod", CmdNexWatchDemod, 1, "Demodulate a NexWatch tag (nexkey, quadrakey) from the GraphBuffer"},
{"read", CmdNexWatchRead, 0, "Attempt to Read and Extract tag data from the antenna"},
{NULL, NULL, 0, NULL}
};
int CmdLFNEXWATCH(const char *Cmd) {
2019-03-10 06:35:06 +08:00
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd) {
2019-03-10 06:35:06 +08:00
CmdsHelp(CommandTable);
return 0;
}