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