]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfviking.c
551718e42f8dbe2879b180fef318bd492108031c
[proxmark3-svn] / client / cmdlfviking.c
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"
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"
22 static int CmdHelp(const char *Cmd);
23
24 int 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
35 int 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 uint64_t getVikingBits(uint32_t id) {
49 //calc checksum
50 uint8_t checksum = (id>>24) ^ ((id>>16) & 0xFF) ^ ((id>>8) & 0xFF) ^ (id & 0xFF) ^ 0xF2 ^ 0xA8;
51 return (0xF2 << 56) | (id << 8) | checksum;
52 }
53 //by marshmellow
54 //see ASKDemod for what args are accepted
55 int CmdVikingRead(const char *Cmd) {
56 // read lf silently
57 CmdLFRead("s");
58 // get samples silently
59 getSamples("30000",false);
60 // demod and output viking ID
61 return CmdVikingDemod(Cmd);
62 }
63
64 int CmdVikingClone(const char *Cmd) {
65 uint32_t id = 0;
66 uint64_t rawID = 0;
67 bool Q5 = false;
68 char cmdp = param_getchar(Cmd, 0);
69 if (strlen(Cmd) < 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_viking_clone();
70
71 id = param_get32ex(Cmd, 0, 0, 16)
72 if (id == 0) return usage_lf_viking_clone();
73 if (param_getchar(Cmd, 1)=='Q' || param_getchar(Cmd, 1)=='q')
74 Q5 = true;
75
76 rawID = getVikingBits(id);
77
78 UsbCommand c = {CMD_VIKING_CLONE_TAG,{rawID >> 32, rawID & 0xFFFF, Q5}};
79 clearCommandBuffer();
80 SendCommand(&c);
81 //check for ACK
82 WaitForResponse(CMD_ACK,NULL);
83 return 0;
84 }
85
86 int CmdVikingSim(const char *Cmd) {
87 uint32_t id = 0;
88 uint64_t rawID = 0;
89 uint8_t clk = 32, encoding = 1, separator = 0, invert = 0;
90
91 if (strlen(Cmd) < 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_viking_sim();
92 id = param_get32ex(Cmd, 0, 0, 16)
93 if (id == 0) return usage_lf_viking_sim();
94
95 rawID = getVikingBits(id);
96
97 uint16_t arg1, arg2;
98 size_t size = 64;
99 arg1 = clk << 8 | encoding;
100 arg2 = invert << 8 | separator;
101
102 UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
103 PrintAndLog("preparing to sim ask data: %d bits", size);
104 num_to_bytebits(rawID, 64, c.d.asBytes);
105 clearCommandBuffer();
106 SendCommand(&c);
107 }
108
109 static command_t CommandTable[] = {
110 {"help", CmdHelp, 1, "This help"},
111 {"read", CmdVikingRead, 0, "Attempt to read and Extract tag data"},
112 {"clone", CmdVikingClone, 0, "<8 digit ID number> clone viking tag"},
113 {"sim", CmdVikingSim, 0, "<8 digit ID number> simulate viking tag"},
114 {NULL, NULL, 0, NULL}
115 };
116
117 int CmdLFViking(const char *Cmd) {
118 CmdsParse(CommandTable, Cmd);
119 return 0;
120 }
121
122 int CmdHelp(const char *Cmd) {
123 CmdsHelp(CommandTable);
124 return 0;
125 }
Impressum, Datenschutz