]>
git.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 //-----------------------------------------------------------------------------
19 #include "cmdparser.h"
23 #include "lfdemod.h" // preamble test
25 static int CmdHelp(const char *Cmd
);
28 // find PAC preamble in already demoded data
29 int PacFind(uint8_t *dest
, size_t *size
) {
30 if (*size
< 128) return -1; //make sure buffer has data
32 uint8_t preamble
[] = {1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,0,0,1,0};
33 if (!preambleSearch(dest
, preamble
, sizeof(preamble
), size
, &startIdx
))
34 return -2; //preamble not found
35 if (*size
!= 128) return -3; //wrong demoded size
36 //return start position
40 //see NRZDemod for what args are accepted
41 int CmdPacDemod(const char *Cmd
) {
44 if (!NRZrawDemod(Cmd
, false)) {
45 if (g_debugMode
) PrintAndLog("DEBUG: Error - PAC: NRZ Demod failed");
48 size_t size
= DemodBufferLen
;
49 int ans
= PacFind(DemodBuffer
, &size
);
53 PrintAndLog("DEBUG: Error - PAC: too few bits found");
55 PrintAndLog("DEBUG: Error - PAC: preamble not found");
57 PrintAndLog("DEBUG: Error - PAC: Size not correct: %d", size
);
59 PrintAndLog("DEBUG: Error - PAC: ans: %d", ans
);
63 setDemodBuf(DemodBuffer
, 128, ans
);
64 setClockGrid(g_DemodClock
, g_DemodStartIdx
+ (ans
*g_DemodClock
));
67 uint32_t raw1
= bytebits_to_byte(DemodBuffer
, 32);
68 uint32_t raw2
= bytebits_to_byte(DemodBuffer
+32, 32);
69 uint32_t raw3
= bytebits_to_byte(DemodBuffer
+64, 32);
70 uint32_t raw4
= bytebits_to_byte(DemodBuffer
+96, 32);
72 // preamble then appears to have marker bits of "10" CS?
73 // 11111111001000000 10 01001100 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 10001100 10 100000001
74 // unknown checksum 9 bits at the end
76 PrintAndLog("PAC/Stanley Tag Found -- Raw: %08X%08X%08X%08X", raw1
,raw2
, raw3
, raw4
);
77 PrintAndLog("\nHow the Raw ID is translated by the reader is unknown");
81 int CmdPacRead(const char *Cmd
) {
82 lf_read(true, 4096*2 + 20);
83 return CmdPacDemod(Cmd
);
86 static command_t CommandTable
[] = {
87 {"help", CmdHelp
, 1, "This help"},
88 {"demod", CmdPacDemod
,1, "Attempt to read and extract tag data from the GraphBuffer"},
89 {"read", CmdPacRead
, 0, "Attempt to read and extract tag data from the antenna"},
93 int CmdLFPac(const char *Cmd
) {
95 CmdsParse(CommandTable
, Cmd
);
99 int CmdHelp(const char *Cmd
) {
100 CmdsHelp(CommandTable
);