]> git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfpac.c
mock of key checking
[proxmark3-svn] / client / cmdlfpac.c
1 //-----------------------------------------------------------------------------
2 //
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
5 // the license.
6 //-----------------------------------------------------------------------------
7 // Low frequency Stanley/PAC tag commands
8 // NRZ, RF/32, 128 bits long (unknown cs)
9 //-----------------------------------------------------------------------------
10 #include "cmdlfpac.h"
11 #include <string.h>
12 #include <inttypes.h>
13 #include "proxmark3.h"
14 #include "ui.h"
15 #include "util.h"
16 #include "graph.h"
17 #include "cmdparser.h"
18 #include "cmddata.h"
19 #include "cmdmain.h"
20 #include "cmdlf.h"
21 #include "lfdemod.h" // preamble test
22
23 static int CmdHelp(const char *Cmd);
24
25 // by marshmellow
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
29 size_t startIdx = 0;
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
35 return (int)startIdx;
36 }
37
38 //see NRZDemod for what args are accepted
39 int CmdPacDemod(const char *Cmd) {
40
41 //NRZ
42 if (!NRZrawDemod(Cmd, false)) {
43 if (g_debugMode) PrintAndLog("DEBUG: Error - PAC: NRZ Demod failed");
44 return 0;
45 }
46 size_t size = DemodBufferLen;
47 int ans = PacFind(DemodBuffer, &size);
48 if (ans < 0) {
49 if (g_debugMode) {
50 if (ans == -1)
51 PrintAndLog("DEBUG: Error - PAC: too few bits found");
52 else if (ans == -2)
53 PrintAndLog("DEBUG: Error - PAC: preamble not found");
54 else if (ans == -3)
55 PrintAndLog("DEBUG: Error - PAC: Size not correct: %d", size);
56 else
57 PrintAndLog("DEBUG: Error - PAC: ans: %d", ans);
58 }
59 return 0;
60 }
61 setDemodBuf(DemodBuffer, 128, ans);
62 setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock));
63
64 //got a good demod
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);
69
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
73
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");
76 return 1;
77 }
78
79 int CmdPacRead(const char *Cmd) {
80 lf_read(true, 4096*2 + 20);
81 return CmdPacDemod(Cmd);
82 }
83
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"},
88 {NULL, NULL, 0, NULL}
89 };
90
91 int CmdLFPac(const char *Cmd) {
92 clearCommandBuffer();
93 CmdsParse(CommandTable, Cmd);
94 return 0;
95 }
96
97 int CmdHelp(const char *Cmd) {
98 CmdsHelp(CommandTable);
99 return 0;
100 }
Impressum, Datenschutz