]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfpac.c
1 //-----------------------------------------------------------------------------
3 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
4 // at your option, any later version. See the LICENSE.txt file for the text of
6 //-----------------------------------------------------------------------------
7 // Low frequency Stanley/PAC tag commands
8 // NRZ, RF/32, 128 bits long (unknown cs)
9 //-----------------------------------------------------------------------------
13 #include "proxmark3.h"
17 #include "cmdparser.h"
21 #include "lfdemod.h" // preamble test
23 static int CmdHelp(const char *Cmd
);
26 // find PAC preamble in already demoded data
27 int PacFind(uint8_t *dest
, size_t *size
) {
28 if (*size
< 128) return -1; //make sure buffer has data
30 uint8_t preamble
[] = {1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,0,0,1,0};
31 if (!preambleSearch(dest
, preamble
, sizeof(preamble
), size
, &startIdx
))
32 return -2; //preamble not found
33 if (*size
!= 128) return -3; //wrong demoded size
34 //return start position
38 //see NRZDemod for what args are accepted
39 int CmdPacDemod(const char *Cmd
) {
42 if (!NRZrawDemod(Cmd
, false)) {
43 if (g_debugMode
) PrintAndLog("DEBUG: Error - PAC: NRZ Demod failed");
46 size_t size
= DemodBufferLen
;
47 int ans
= PacFind(DemodBuffer
, &size
);
51 PrintAndLog("DEBUG: Error - PAC: too few bits found");
53 PrintAndLog("DEBUG: Error - PAC: preamble not found");
55 PrintAndLog("DEBUG: Error - PAC: Size not correct: %d", size
);
57 PrintAndLog("DEBUG: Error - PAC: ans: %d", ans
);
61 setDemodBuf(DemodBuffer
, 128, ans
);
62 setClockGrid(g_DemodClock
, g_DemodStartIdx
+ (ans
*g_DemodClock
));
65 uint32_t raw1
= bytebits_to_byte(DemodBuffer
, 32);
66 uint32_t raw2
= bytebits_to_byte(DemodBuffer
+32, 32);
67 uint32_t raw3
= bytebits_to_byte(DemodBuffer
+64, 32);
68 uint32_t raw4
= bytebits_to_byte(DemodBuffer
+96, 32);
70 // preamble then appears to have marker bits of "10" CS?
71 // 11111111001000000 10 01001100 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 10001100 10 100000001
72 // unknown checksum 9 bits at the end
74 PrintAndLog("PAC/Stanley Tag Found -- Raw: %08X%08X%08X%08X", raw1
,raw2
, raw3
, raw4
);
75 PrintAndLog("\nHow the Raw ID is translated by the reader is unknown");
79 int CmdPacRead(const char *Cmd
) {
80 lf_read(true, 4096*2 + 20);
81 return CmdPacDemod(Cmd
);
84 static command_t CommandTable
[] = {
85 {"help", CmdHelp
, 1, "This help"},
86 {"demod", CmdPacDemod
,1, "Attempt to read and extract tag data from the GraphBuffer"},
87 {"read", CmdPacRead
, 0, "Attempt to read and extract tag data from the antenna"},
91 int CmdLFPac(const char *Cmd
) {
93 CmdsParse(CommandTable
, Cmd
);
97 int CmdHelp(const char *Cmd
) {
98 CmdsHelp(CommandTable
);