]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cmdlfviking.c
adjust lf menu descriptions
[proxmark3-svn] / client / cmdlfviking.c
CommitLineData
709665b5 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 Viking tag commands
8//-----------------------------------------------------------------------------
9#include <stdio.h>
10#include <string.h>
11#include <inttypes.h>
12#include "proxmark3.h"
2b4898ec 13#include "cmdlfviking.h"
709665b5 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"
709665b5 21#include "lfdemod.h"
22static int CmdHelp(const char *Cmd);
23
24int usage_lf_viking_clone(void) {
25 PrintAndLog("clone a Viking AM tag to a T55x7 tag.");
26 PrintAndLog("Usage: lf viking clone <Card ID - 8 hex digits> <Q5>");
27 PrintAndLog("Options :");
28 PrintAndLog(" <Card Number> : 8 digit hex viking card number");
29 PrintAndLog(" <Q5> : specify write to Q5 (t5555 instead of t55x7)");
30 PrintAndLog("");
31 PrintAndLog("Sample : lf viking clone 1A337 Q5");
32 return 0;
33}
34
35int usage_lf_viking_sim(void) {
36 PrintAndLog("Enables simulation of viking card with specified card number.");
37 PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
38 PrintAndLog("Per viking format, the card number is 8 digit hex number. Larger values are truncated.");
39 PrintAndLog("");
40 PrintAndLog("Usage: lf viking sim <Card-Number>");
41 PrintAndLog("Options :");
42 PrintAndLog(" <Card Number> : 8 digit hex viking card number");
43 PrintAndLog("");
44 PrintAndLog("Sample : lf viking sim 1A337");
45 return 0;
46}
47
48uint64_t getVikingBits(uint32_t id) {
49 //calc checksum
8f226839 50 uint8_t checksum = ((id>>24) & 0xFF) ^ ((id>>16) & 0xFF) ^ ((id>>8) & 0xFF) ^ (id & 0xFF) ^ 0xF2 ^ 0xA8;
51 return ((uint64_t)0xF2 << 56) | ((uint64_t)id << 8) | checksum;
709665b5 52}
f2fc0a9c 53
f2fc0a9c 54//by marshmellow
55//see ASKDemod for what args are accepted
56int CmdVikingDemod(const char *Cmd) {
57 if (!ASKDemod(Cmd, false, false, 1)) {
58 if (g_debugMode) PrintAndLog("ASKDemod failed");
59 return 0;
60 }
61 size_t size = DemodBufferLen;
62 //call lfdemod.c demod for Viking
63 int ans = VikingDemod_AM(DemodBuffer, &size);
64 if (ans < 0) {
65 if (g_debugMode) PrintAndLog("Error Viking_Demod %d", ans);
66 return 0;
67 }
68 //got a good demod
69 uint32_t raw1 = bytebits_to_byte(DemodBuffer+ans, 32);
70 uint32_t raw2 = bytebits_to_byte(DemodBuffer+ans+32, 32);
71 uint32_t cardid = bytebits_to_byte(DemodBuffer+ans+24, 32);
72 uint8_t checksum = bytebits_to_byte(DemodBuffer+ans+32+24, 8);
73 PrintAndLog("Viking Tag Found: Card ID %08X, Checksum: %02X", cardid, (unsigned int) checksum);
74 PrintAndLog("Raw: %08X%08X", raw1,raw2);
75 setDemodBuf(DemodBuffer+ans, 64, 0);
76 return 1;
77}
78
709665b5 79//by marshmellow
80//see ASKDemod for what args are accepted
81int CmdVikingRead(const char *Cmd) {
82 // read lf silently
83 CmdLFRead("s");
84 // get samples silently
f2fc0a9c 85 getSamples("10000",false);
709665b5 86 // demod and output viking ID
87 return CmdVikingDemod(Cmd);
88}
89
90int CmdVikingClone(const char *Cmd) {
91 uint32_t id = 0;
92 uint64_t rawID = 0;
93 bool Q5 = false;
94 char cmdp = param_getchar(Cmd, 0);
735136e6 95 if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_viking_clone();
709665b5 96
fe876493 97 id = param_get32ex(Cmd, 0, 0, 16);
709665b5 98 if (id == 0) return usage_lf_viking_clone();
99 if (param_getchar(Cmd, 1)=='Q' || param_getchar(Cmd, 1)=='q')
100 Q5 = true;
101
102 rawID = getVikingBits(id);
776f7e61 103 PrintAndLog("Cloning - ID: %08X, Raw: %08X%08X",id,(uint32_t)(rawID >> 32),(uint32_t) (rawID & 0xFFFFFFFF));
104 UsbCommand c = {CMD_VIKING_CLONE_TAG,{rawID >> 32, rawID & 0xFFFFFFFF, Q5}};
709665b5 105 clearCommandBuffer();
106 SendCommand(&c);
107 //check for ACK
108 WaitForResponse(CMD_ACK,NULL);
109 return 0;
110}
111
d1cea2a4 112int CmdVikingSim(const char *Cmd) {
709665b5 113 uint32_t id = 0;
114 uint64_t rawID = 0;
115 uint8_t clk = 32, encoding = 1, separator = 0, invert = 0;
fe876493 116 char cmdp = param_getchar(Cmd, 0);
709665b5 117
735136e6 118 if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_viking_sim();
fe876493 119 id = param_get32ex(Cmd, 0, 0, 16);
709665b5 120 if (id == 0) return usage_lf_viking_sim();
121
122 rawID = getVikingBits(id);
123
124 uint16_t arg1, arg2;
125 size_t size = 64;
126 arg1 = clk << 8 | encoding;
127 arg2 = invert << 8 | separator;
128
129 UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
130 PrintAndLog("preparing to sim ask data: %d bits", size);
131 num_to_bytebits(rawID, 64, c.d.asBytes);
132 clearCommandBuffer();
133 SendCommand(&c);
fe876493 134 return 0;
709665b5 135}
136
137static command_t CommandTable[] = {
138 {"help", CmdHelp, 1, "This help"},
f2fc0a9c 139 {"demod", CmdVikingDemod, 1, "Demodulate a Viking tag from the GraphBuffer"},
140 {"read", CmdVikingRead, 0, "Attempt to read and Extract tag data from the antenna"},
709665b5 141 {"clone", CmdVikingClone, 0, "<8 digit ID number> clone viking tag"},
142 {"sim", CmdVikingSim, 0, "<8 digit ID number> simulate viking tag"},
143 {NULL, NULL, 0, NULL}
144};
145
146int CmdLFViking(const char *Cmd) {
147 CmdsParse(CommandTable, Cmd);
148 return 0;
149}
150
151int CmdHelp(const char *Cmd) {
152 CmdsHelp(CommandTable);
153 return 0;
154}
Impressum, Datenschutz