]> git.zerfleddert.de Git - proxmark3-svn/blame_incremental - client/cmdlfnexwatch.c
Update cmdhficlass.c
[proxmark3-svn] / client / cmdlfnexwatch.c
... / ...
CommitLineData
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 (known)
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 setClockGrid(g_DemodClock, g_DemodStartIdx + ((startIdx+4)*g_DemodClock));
42 startIdx = 8+32; // 8 = preamble, 32 = reserved bits (always 0)
43 //get ID
44 uint32_t ID = 0;
45 for (uint8_t wordIdx=0; wordIdx<4; wordIdx++){
46 for (uint8_t idx=0; idx<8; idx++){
47 ID = (ID << 1) | DemodBuffer[startIdx+wordIdx+(idx*4)];
48 }
49 }
50 //parity check (TBD)
51
52 //checksum check (TBD)
53
54 //output
55 PrintAndLog("NexWatch ID: %d", ID);
56 if (invert){
57 PrintAndLog("Had to Invert - probably NexKey");
58 for (uint8_t idx=0; idx<size; idx++)
59 DemodBuffer[idx] ^= 1;
60 }
61
62 CmdPrintDemodBuff("x");
63 return 1;
64}
65
66//by marshmellow
67//see ASKDemod for what args are accepted
68int CmdNexWatchRead(const char *Cmd) {
69 // read lf silently
70 lf_read(true, 10000);
71 // demod and output viking ID
72 return CmdPSKNexWatch(Cmd);
73}
74
75static command_t CommandTable[] = {
76 {"help", CmdHelp, 1, "This help"},
77 {"demod", CmdPSKNexWatch, 1, "Demodulate a NexWatch tag (nexkey, quadrakey) from the GraphBuffer"},
78 {"read", CmdNexWatchRead, 0, "Attempt to Read and Extract tag data from the antenna"},
79 {NULL, NULL, 0, NULL}
80};
81
82int CmdLFNexWatch(const char *Cmd) {
83 CmdsParse(CommandTable, Cmd);
84 return 0;
85}
86
87int CmdHelp(const char *Cmd) {
88 CmdsHelp(CommandTable);
89 return 0;
90}
Impressum, Datenschutz