]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cmdlfviking.c
FIX: had to make it clientside only
[proxmark3-svn] / client / cmdlfviking.c
CommitLineData
a126332a 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//-----------------------------------------------------------------------------
0de8e387 9#include <stdio.h>
10#include <string.h>
11#include <inttypes.h>
12#include "proxmark3.h"
13#include "ui.h"
14#include "util.h"
15#include "graph.h"
16#include "cmdparser.h"
17#include "cmddata.h"
18#include "cmdmain.h"
19#include "cmdlf.h"
20#include "cmdlfviking.h"
21#include "lfdemod.h"
22static int CmdHelp(const char *Cmd);
70459879 23
24int usage_lf_viking_clone(void){
25 PrintAndLog("clone a Viking AM tag to a T55x7 tag.");
a126332a 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");
70459879 32 return 0;
33}
34
a126332a 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
48// calc checksum
49uint64_t getVikingBits(uint32_t id) {
c0afa86f 50 uint8_t checksum = ((id>>24) & 0xFF) ^ ((id>>16) & 0xFF) ^ ((id>>8) & 0xFF) ^ (id & 0xFF) ^ 0xF2 ^ 0xA8;
a126332a 51 uint64_t ret = (uint64_t)0xF2 << 56;
c0afa86f 52 ret |= (uint64_t)id << 8;
a126332a 53 ret |= checksum;
54 return ret;
55}
022346a1 56
70459879 57//by marshmellow
58//see ASKDemod for what args are accepted
a126332a 59int CmdVikingRead(const char *Cmd) {
60 // read lf silently
61 CmdLFRead("s");
62 // get samples silently
53484563 63 getSamples("12000", TRUE);
a126332a 64 // demod and output viking ID
65 return CmdVikingDemod(Cmd);
0de8e387 66}
70459879 67
a126332a 68int CmdVikingClone(const char *Cmd) {
69 uint32_t id = 0;
70 uint64_t rawID = 0;
71 bool Q5 = false;
70459879 72 char cmdp = param_getchar(Cmd, 0);
40a532d9 73 if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_viking_clone();
70459879 74
a126332a 75 id = param_get32ex(Cmd, 0, 0, 16);
76 if (id == 0) return usage_lf_viking_clone();
70459879 77
a126332a 78 cmdp = param_getchar(Cmd, 1);
79 if ( cmdp == 'Q' || cmdp == 'q')
80 Q5 = true;
81
82 rawID = getVikingBits(id);
7177c513 83
84 PrintAndLog("Cloning - ID: %08X, Raw: %08X%08X",id,(uint32_t)(rawID >> 32),(uint32_t) (rawID & 0xFFFFFFFF));
022346a1 85 UsbCommand c = {CMD_VIKING_CLONE_TAG,{rawID >> 32, rawID & 0xFFFFFFFF, Q5}};
70459879 86 clearCommandBuffer();
87 SendCommand(&c);
a126332a 88 //check for ACK
89 WaitForResponse(CMD_ACK,NULL);
0de8e387 90 return 0;
91}
92
a126332a 93int CmdVikingSim(const char *Cmd) {
94 uint32_t id = 0;
95 uint64_t rawID = 0;
96 uint8_t clk = 32, encoding = 1, separator = 0, invert = 0;
97
98 char cmdp = param_getchar(Cmd, 0);
40a532d9 99 if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_viking_sim();
a126332a 100
101 id = param_get32ex(Cmd, 0, 0, 16);
102 if (id == 0) return usage_lf_viking_sim();
103
104 rawID = getVikingBits(id);
105
106 uint16_t arg1, arg2;
107 size_t size = 64;
108 arg1 = clk << 8 | encoding;
109 arg2 = invert << 8 | separator;
110
7177c513 111 PrintAndLog("Simulating - ID: %08X, Raw: %08X%08X",id,(uint32_t)(rawID >> 32),(uint32_t) (rawID & 0xFFFFFFFF));
112
a126332a 113 UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
7177c513 114 num_to_bytebits(rawID, size, c.d.asBytes);
a126332a 115 clearCommandBuffer();
116 SendCommand(&c);
117 return 0;
118}
119
120static command_t CommandTable[] = {
70459879 121 {"help", CmdHelp, 1, "This help"},
a126332a 122 {"read", CmdVikingRead, 0, "Attempt to read and Extract tag data"},
123 {"clone", CmdVikingClone, 0, "<8 digit ID number> clone viking tag"},
124 {"sim", CmdVikingSim, 0, "<8 digit ID number> simulate viking tag"},
0de8e387 125 {NULL, NULL, 0, NULL}
126};
127
a126332a 128int CmdLFViking(const char *Cmd) {
4c36581b 129 clearCommandBuffer();
0de8e387 130 CmdsParse(CommandTable, Cmd);
131 return 0;
132}
133
a126332a 134int CmdHelp(const char *Cmd) {
0de8e387 135 CmdsHelp(CommandTable);
136 return 0;
137}
Impressum, Datenschutz