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