]>
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 Presco tag commands | |
8 | //----------------------------------------------------------------------------- | |
9 | ||
10 | #include "cmdlfvisa2000.h" | |
11 | ||
12 | static int CmdHelp(const char *Cmd); | |
13 | ||
14 | int usage_lf_visa2k_clone(void){ | |
15 | PrintAndLog("clone a Visa2000 tag to a T55x7 tag."); | |
16 | PrintAndLog("Usage: lf visa2k clone [h] <card ID> <Q5>"); | |
17 | PrintAndLog("Options:"); | |
18 | PrintAndLog(" h : This help"); | |
19 | PrintAndLog(" <card ID> : Visa2k card ID"); | |
20 | PrintAndLog(" <Q5> : specify write to Q5 (t5555 instead of t55x7)"); | |
21 | PrintAndLog(""); | |
22 | PrintAndLog("Sample: lf visa2k clone 112233"); | |
23 | return 0; | |
24 | } | |
25 | ||
26 | int usage_lf_visa2k_sim(void) { | |
27 | PrintAndLog("Enables simulation of visa2k card with specified card number."); | |
28 | PrintAndLog("Simulation runs until the button is pressed or another USB command is issued."); | |
29 | PrintAndLog(""); | |
30 | PrintAndLog("Usage: lf visa2k sim [h] <card ID>"); | |
31 | PrintAndLog("Options:"); | |
32 | PrintAndLog(" h : This help"); | |
33 | PrintAndLog(" <card ID> : Visa2k card ID"); | |
34 | PrintAndLog(""); | |
35 | PrintAndLog("Sample: lf visa2k sim 112233"); | |
36 | return 0; | |
37 | } | |
38 | ||
39 | //see ASKDemod for what args are accepted | |
40 | int CmdVisa2kDemod(const char *Cmd) { | |
41 | ||
42 | //ASK / Manchester | |
43 | bool st = true; | |
44 | if (!ASKDemod_ext("64 0 0", FALSE, FALSE, 1, &st)) { | |
45 | if (g_debugMode) PrintAndLog("DEBUG: Error - Visa2k: ASK/Manchester Demod failed"); | |
46 | return 0; | |
47 | } | |
48 | size_t size = DemodBufferLen; | |
49 | int ans = Visa2kDemod_AM(DemodBuffer, &size); | |
50 | if (ans < 0){ | |
51 | if (g_debugMode){ | |
52 | if (ans == -1) | |
53 | PrintAndLog("DEBUG: Error - Visa2k: too few bits found"); | |
54 | else if (ans == -2) | |
55 | PrintAndLog("DEBUG: Error - Visa2k: preamble not found"); | |
56 | else if (ans == -3) | |
57 | PrintAndLog("DEBUG: Error - Visa2k: Size not correct: %d", size); | |
58 | else | |
59 | PrintAndLog("DEBUG: Error - Visa2k: ans: %d", ans); | |
60 | } | |
61 | return 0; | |
62 | } | |
63 | setDemodBuf(DemodBuffer, 96, ans); | |
64 | ||
65 | //got a good demod | |
66 | uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32); | |
67 | uint32_t raw2 = bytebits_to_byte(DemodBuffer+32, 32); | |
68 | uint32_t raw3 = bytebits_to_byte(DemodBuffer+64, 32); | |
69 | ||
70 | PrintAndLog("Visa2000 Tag Found: Card ID %u, Raw: %08X%08X%08X", raw2, raw1 ,raw2, raw3); | |
71 | return 1; | |
72 | } | |
73 | ||
74 | int CmdVisa2kRead(const char *Cmd) { | |
75 | CmdLFRead("s"); | |
76 | getSamples("20000",TRUE); | |
77 | return CmdVisa2kDemod(Cmd); | |
78 | } | |
79 | ||
80 | int CmdVisa2kClone(const char *Cmd) { | |
81 | ||
82 | uint64_t id = 0; | |
83 | uint32_t blocks[4] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_64 | T55x7_ST_TERMINATOR |3<<T55x7_MAXBLOCK_SHIFT, 0, 0}; | |
84 | ||
85 | // uint8_t bits[96]; | |
86 | // uint8_t *bs = bits; | |
87 | // memset(bs, 0, sizeof(bits)); | |
88 | ||
89 | char cmdp = param_getchar(Cmd, 0); | |
90 | if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_visa2k_clone(); | |
91 | ||
92 | id = param_get32ex(Cmd, 0, 0, 10); | |
93 | ||
94 | //Q5 | |
95 | if (param_getchar(Cmd, 1) == 'Q' || param_getchar(Cmd, 1) == 'q') { | |
96 | //t5555 (Q5) BITRATE = (RF-2)/2 (iceman) | |
97 | blocks[0] = T5555_MODULATION_MANCHESTER | 64<<T5555_BITRATE_SHIFT | T5555_ST_TERMINATOR | 3<<T5555_MAXBLOCK_SHIFT; | |
98 | } | |
99 | ||
100 | // if ( !getJablotronBits(fullcode, bs)) { | |
101 | // PrintAndLog("Error with tag bitstream generation."); | |
102 | // return 1; | |
103 | // } | |
104 | ||
105 | // | |
106 | blocks[1] = 0x56495332; | |
107 | blocks[2] = id; | |
108 | blocks[3] = 0; | |
109 | ||
110 | PrintAndLog("Preparing to clone Visa2000 to T55x7 with CardId: %u", id); | |
111 | PrintAndLog("Blk | Data "); | |
112 | PrintAndLog("----+------------"); | |
113 | PrintAndLog(" 00 | 0x%08x", blocks[0]); | |
114 | PrintAndLog(" 01 | 0x%08x", blocks[1]); | |
115 | PrintAndLog(" 02 | 0x%08x", blocks[2]); | |
116 | PrintAndLog(" 02 | 0x%08x", blocks[3]); | |
117 | ||
118 | UsbCommand resp; | |
119 | UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}}; | |
120 | ||
121 | for (int i = 3; i >= 0; --i) { | |
122 | c.arg[0] = blocks[i]; | |
123 | c.arg[1] = i; | |
124 | clearCommandBuffer(); | |
125 | SendCommand(&c); | |
126 | if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){ | |
127 | PrintAndLog("Error occurred, device did not respond during write operation."); | |
128 | return -1; | |
129 | } | |
130 | } | |
131 | return 0; | |
132 | } | |
133 | ||
134 | int CmdVisa2kSim(const char *Cmd) { | |
135 | ||
136 | uint32_t id = 0; | |
137 | char cmdp = param_getchar(Cmd, 0); | |
138 | if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_visa2k_sim(); | |
139 | ||
140 | id = param_get32ex(Cmd, 0, 0, 10); | |
141 | ||
142 | uint8_t clk = 64, encoding = 1, separator = 1, invert = 0; | |
143 | uint16_t arg1, arg2; | |
144 | size_t size = 96; | |
145 | arg1 = clk << 8 | encoding; | |
146 | arg2 = invert << 8 | separator; | |
147 | ||
148 | PrintAndLog("Simulating Visa2000 - CardId: %u", id); | |
149 | ||
150 | UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}}; | |
151 | ||
152 | uint32_t blocks[3] = { 0x56495332, id, 0}; | |
153 | ||
154 | for(int i=0; i<3; ++i){ | |
155 | num_to_bytebits(blocks[i], 32, c.d.asBytes + i*32); | |
156 | } | |
157 | clearCommandBuffer(); | |
158 | SendCommand(&c); | |
159 | return 0; | |
160 | } | |
161 | ||
162 | static command_t CommandTable[] = { | |
163 | {"help", CmdHelp, 1, "This help"}, | |
164 | {"read", CmdVisa2kRead, 0, "Attempt to read and extract tag data"}, | |
165 | {"clone", CmdVisa2kClone, 0, "clone Visa2000 tag"}, | |
166 | {"sim", CmdVisa2kSim, 0, "simulate Visa2000 tag"}, | |
167 | {NULL, NULL, 0, NULL} | |
168 | }; | |
169 | ||
170 | int CmdLFVisa2k(const char *Cmd) { | |
171 | clearCommandBuffer(); | |
172 | CmdsParse(CommandTable, Cmd); | |
173 | return 0; | |
174 | } | |
175 | ||
176 | int CmdHelp(const char *Cmd) { | |
177 | CmdsHelp(CommandTable); | |
178 | return 0; | |
179 | } |