]> git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfviking.c
added @marshmellows new viking demod.
[proxmark3-svn] / client / cmdlfviking.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <inttypes.h>
4 #include "proxmark3.h"
5 #include "ui.h"
6 #include "util.h"
7 #include "graph.h"
8 #include "cmdparser.h"
9 #include "cmddata.h"
10 #include "cmdmain.h"
11 #include "cmdlf.h"
12 #include "cmdlfviking.h"
13 #include "lfdemod.h"
14 static int CmdHelp(const char *Cmd);
15
16 int usage_lf_viking_clone(void){
17 PrintAndLog("clone a Viking AM tag to a T55x7 tag.");
18 PrintAndLog("Usage: lf viking clone <Card ID 16 bytes of hex number>");
19 return 0;
20 }
21
22 //by marshmellow
23 //see ASKDemod for what args are accepted
24 int CmdVikingDemod(const char *Cmd)
25 {
26 CmdLFRead("s");
27 getSamples("30000",false);
28
29 if (!ASKDemod(Cmd, false, false, 1)) {
30 if (g_debugMode) PrintAndLog("ASKDemod failed");
31 return 0;
32 }
33 size_t size = DemodBufferLen;
34
35 int ans = VikingDemod_AM(DemodBuffer, &size);
36 if (ans < 0) {
37 if (g_debugMode) PrintAndLog("Error Viking_Demod");
38 return 0;
39 }
40 //got a good demod
41 uint32_t raw1 = bytebits_to_byte(DemodBuffer+ans, 32);
42 uint32_t raw2 = bytebits_to_byte(DemodBuffer+ans+32, 32);
43 uint32_t cardid = bytebits_to_byte(DemodBuffer+ans+24, 32);
44 uint8_t checksum = bytebits_to_byte(DemodBuffer+ans+32+24, 8);
45 PrintAndLog("Viking Tag Found: Card ID %08X, Checksum: %02X", cardid, checksum);
46 PrintAndLog("Raw: %08X%08X", raw1,raw2);
47 setDemodBuf(DemodBuffer+ans, 64, 0);
48 return 1;
49 }
50
51 int CmdVikingClone(const char *Cmd)
52 {
53 uint32_t b1,b2;
54 // get the tag number 64 bits (8 bytes) in hex
55 uint8_t id[8];
56
57 char cmdp = param_getchar(Cmd, 0);
58 if (strlen(Cmd) < 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_viking_clone();
59
60 if (param_gethex(Cmd, 0, id, 16) == 1)
61 return usage_lf_viking_clone();
62
63 b1 = bytes_to_num(id, sizeof(uint32_t));
64 b2 = bytes_to_num(id + sizeof(uint32_t), sizeof(uint32_t));
65 UsbCommand c = {CMD_VIKING_CLONE_TAG,{b1,b2}};
66 clearCommandBuffer();
67 SendCommand(&c);
68 //check for ACK?
69 return 0;
70 }
71
72 static command_t CommandTable[] =
73 {
74 {"help", CmdHelp, 1, "This help"},
75 {"demod", CmdVikingDemod, 1, "Extract tag data"},
76 {"clone", CmdVikingClone, 1, "<16 digits card data> clone viking tag"},
77 {NULL, NULL, 0, NULL}
78 };
79
80 int CmdLFViking(const char *Cmd)
81 {
82 CmdsParse(CommandTable, Cmd);
83 return 0;
84 }
85
86 int CmdHelp(const char *Cmd)
87 {
88 CmdsHelp(CommandTable);
89 return 0;
90 }
Impressum, Datenschutz