]> git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfnexwatch.c
030c61c74dc5489759a35b45012d0047da8a0222
[proxmark3-svn] / client / cmdlfnexwatch.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 Honeywell NexWatch tag commands
8 // PSK1 RF/16, RF/2, 128 bits long
9 //-----------------------------------------------------------------------------
10 #include <stdio.h>
11 #include <string.h>
12 #include <inttypes.h>
13 #include <stdbool.h>
14 #include "cmdlfnexwatch.h"
15 #include "proxmark3.h"
16 #include "ui.h"
17 #include "util.h"
18 #include "graph.h"
19 #include "cmdparser.h"
20 #include "cmddata.h"
21 #include "cmdlf.h"
22 #include "lfdemod.h"
23
24 static int CmdHelp(const char *Cmd);
25
26 int CmdPSKNexWatch(const char *Cmd)
27 {
28 if (!PSKDemod("", false)) return 0;
29 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};
30 size_t startIdx = 0, size = DemodBufferLen;
31 bool invert = false;
32 if (!preambleSearch(DemodBuffer, preamble, sizeof(preamble), &size, &startIdx)){
33 // if didn't find preamble try again inverting
34 if (!PSKDemod("1", false)) return 0;
35 size = DemodBufferLen;
36 if (!preambleSearch(DemodBuffer, preamble, sizeof(preamble), &size, &startIdx)) return 0;
37 invert = true;
38 }
39 if (size != 128) return 0;
40 setDemodBuf(DemodBuffer, size, startIdx+4);
41 startIdx = 8+32; //4 = extra i added, 8 = preamble, 32 = reserved bits (always 0)
42 //get ID
43 uint32_t ID = 0;
44 for (uint8_t wordIdx=0; wordIdx<4; wordIdx++){
45 for (uint8_t idx=0; idx<8; idx++){
46 ID = (ID << 1) | DemodBuffer[startIdx+wordIdx+(idx*4)];
47 }
48 }
49 //parity check (TBD)
50
51 //checksum check (TBD)
52
53 //output
54 PrintAndLog("NexWatch ID: %d", ID);
55 if (invert){
56 PrintAndLog("Had to Invert - probably NexKey");
57 for (uint8_t idx=0; idx<size; idx++)
58 DemodBuffer[idx] ^= 1;
59 }
60
61 CmdPrintDemodBuff("x");
62 return 1;
63 }
64
65 //by marshmellow
66 //see ASKDemod for what args are accepted
67 int CmdNexWatchRead(const char *Cmd) {
68 // read lf silently
69 CmdLFRead("s");
70 // get samples silently
71 getSamples("10000",false);
72 // demod and output viking ID
73 return CmdPSKNexWatch(Cmd);
74 }
75
76 static command_t CommandTable[] = {
77 {"help", CmdHelp, 1, "This help"},
78 {"demod", CmdPSKNexWatch, 1, "Demodulate a NexWatch tag (nexkey, quadrakey) from the GraphBuffer"},
79 {"read", CmdNexWatchRead, 0, "Attempt to Read and Extract tag data from the antenna"},
80 {NULL, NULL, 0, NULL}
81 };
82
83 int CmdLFNexWatch(const char *Cmd) {
84 CmdsParse(CommandTable, Cmd);
85 return 0;
86 }
87
88 int CmdHelp(const char *Cmd) {
89 CmdsHelp(CommandTable);
90 return 0;
91 }
Impressum, Datenschutz