proxmark3/client/cmdlfpac.c

89 lines
3.3 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 Stanley/PAC tag commands
// NRZ, RF/32, 128 bits long (unknown cs)
//-----------------------------------------------------------------------------
#include "cmdlfpac.h"
static int CmdHelp(const char *Cmd);
// by marshmellow
// find PAC preamble in already demoded data
int detectPac(uint8_t *dest, size_t *size) {
2019-03-10 06:35:06 +08:00
if (*size < 128) return -1; //make sure buffer has data
size_t startIdx = 0;
2019-03-10 07:00:59 +08:00
uint8_t preamble[] = {1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0};
2019-03-10 06:35:06 +08:00
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -2; //preamble not found
if (*size != 128) return -3; //wrong demoded size
//return start position
return (int)startIdx;
}
//see NRZDemod for what args are accepted
int CmdPacDemod(const char *Cmd) {
2019-03-10 06:35:06 +08:00
//NRZ
if (!NRZrawDemod(Cmd, false)) {
PrintAndLogEx(DEBUG, "DEBUG: Error - PAC: NRZ Demod failed");
return 0;
}
size_t size = DemodBufferLen;
int ans = detectPac(DemodBuffer, &size);
if (ans < 0) {
if (ans == -1)
PrintAndLogEx(DEBUG, "DEBUG: Error - PAC: too few bits found");
else if (ans == -2)
PrintAndLogEx(DEBUG, "DEBUG: Error - PAC: preamble not found");
else if (ans == -3)
PrintAndLogEx(DEBUG, "DEBUG: Error - PAC: Size not correct: %d", size);
else
PrintAndLogEx(DEBUG, "DEBUG: Error - PAC: ans: %d", ans);
2018-02-21 23:48:52 +08:00
2019-03-10 06:35:06 +08:00
return 0;
}
2019-04-07 03:46:00 +08:00
setDemodBuff(DemodBuffer, 128, ans);
2019-03-10 07:00:59 +08:00
setClockGrid(g_DemodClock, g_DemodStartIdx + (ans * g_DemodClock));
2019-03-10 06:35:06 +08:00
//got a good demod
2019-03-10 07:00:59 +08:00
uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32);
uint32_t raw2 = bytebits_to_byte(DemodBuffer + 32, 32);
uint32_t raw3 = bytebits_to_byte(DemodBuffer + 64, 32);
uint32_t raw4 = bytebits_to_byte(DemodBuffer + 96, 32);
2019-03-10 06:35:06 +08:00
// preamble then appears to have marker bits of "10" CS?
// 11111111001000000 10 01001100 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 10001100 10 100000001
// unknown checksum 9 bits at the end
2019-03-10 07:00:59 +08:00
PrintAndLogEx(NORMAL, "PAC/Stanley Tag Found -- Raw: %08X%08X%08X%08X", raw1, raw2, raw3, raw4);
2019-03-10 06:35:06 +08:00
PrintAndLogEx(NORMAL, "\nHow the Raw ID is translated by the reader is unknown");
return 1;
}
int CmdPacRead(const char *Cmd) {
2019-03-10 07:00:59 +08:00
lf_read(true, 4096 * 2 + 20);
2019-03-10 06:35:06 +08:00
return CmdPacDemod(Cmd);
}
static command_t CommandTable[] = {
2019-03-10 06:35:06 +08:00
{"help", CmdHelp, 1, "This help"},
2019-03-10 07:00:59 +08:00
{"demod", CmdPacDemod, 1, "Demodulate an PAC tag from the GraphBuffer"},
2019-03-10 06:35:06 +08:00
{"read", CmdPacRead, 0, "Attempt to read and extract tag data from the antenna"},
{NULL, NULL, 0, NULL}
};
int CmdLFPac(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;
}