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