]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/cmdlfnexwatch.c
align clock grid with demods on graph (#276)
[proxmark3-svn] / client / cmdlfnexwatch.c
CommitLineData
5bce72d5 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
b9957414 8// PSK1 RF/16, RF/2, 128 bits long (known)
5bce72d5 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
24static int CmdHelp(const char *Cmd);
25
26int 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
67int CmdNexWatchRead(const char *Cmd) {
68 // read lf silently
b9957414 69 lf_read(true, 10000);
5bce72d5 70 // demod and output viking ID
71 return CmdPSKNexWatch(Cmd);
72}
73
74static command_t CommandTable[] = {
75 {"help", CmdHelp, 1, "This help"},
76 {"demod", CmdPSKNexWatch, 1, "Demodulate a NexWatch tag (nexkey, quadrakey) from the GraphBuffer"},
77 {"read", CmdNexWatchRead, 0, "Attempt to Read and Extract tag data from the antenna"},
78 {NULL, NULL, 0, NULL}
79};
80
81int CmdLFNexWatch(const char *Cmd) {
82 CmdsParse(CommandTable, Cmd);
83 return 0;
84}
85
86int CmdHelp(const char *Cmd) {
87 CmdsHelp(CommandTable);
88 return 0;
89}
Impressum, Datenschutz