]> git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfjablotron.c
CHG: help text changes in cmdlfjablotron.c
[proxmark3-svn] / client / cmdlfjablotron.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 Presco tag commands
8 //-----------------------------------------------------------------------------
9 #include "cmdlfjablotron.h"
10
11 static int CmdHelp(const char *Cmd);
12
13 int usage_lf_jablotron_clone(void){
14 PrintAndLog("clone a Jablotron tag to a T55x7 tag.");
15 PrintAndLog("Usage: lf jablotron clone [h] <card ID> <Q5>");
16 PrintAndLog("Options:");
17 PrintAndLog(" h : This help");
18 PrintAndLog(" <card ID> : jablotron card ID");
19 PrintAndLog(" <Q5> : specify write to Q5 (t5555 instead of t55x7)");
20 PrintAndLog("");
21 PrintAndLog("Sample: lf jablotron clone 112233");
22 return 0;
23 }
24
25 int usage_lf_jablotron_sim(void) {
26 PrintAndLog("Enables simulation of jablotron card with specified card number.");
27 PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
28 PrintAndLog("");
29 PrintAndLog("Usage: lf jablotron sim [h] <card ID>");
30 PrintAndLog("Options:");
31 PrintAndLog(" h : This help");
32 PrintAndLog(" <card ID> : jablotron card ID");
33 PrintAndLog("");
34 PrintAndLog("Sample: lf jablotron sim 112233");
35 return 0;
36 }
37
38 static uint8_t jablontron_chksum(uint8_t *bits){
39 uint8_t chksum = 0;
40 for (int i=16; i < 56; i += 8) {
41 chksum += bytebits_to_byte(bits+i,8);
42 }
43 chksum ^= 0x3A;
44 return chksum;
45 }
46
47 int getJablotronBits(uint64_t fullcode, uint8_t *bits) {
48 //preamp
49 num_to_bytebits(0xFFFF, 16, bits);
50
51 //fullcode
52 num_to_bytebits(fullcode, 40, bits+16);
53
54 //chksum byte
55 uint8_t chksum = jablontron_chksum(bits);
56 num_to_bytebits(chksum, 8, bits+56);
57 return 1;
58 }
59
60 //see ASKDemod for what args are accepted
61 int CmdJablotronDemod(const char *Cmd) {
62
63 //Differential Biphase / di-phase (inverted biphase)
64 //get binary from ask wave
65 if (!ASKbiphaseDemod("0 64 1 0", FALSE)) {
66 if (g_debugMode) PrintAndLog("Error Jablotron: ASKbiphaseDemod failed");
67 return 0;
68 }
69 size_t size = DemodBufferLen;
70 int ans = JablotronDemod(DemodBuffer, &size);
71 if (ans < 0){
72 if (g_debugMode){
73 // if (ans == -5)
74 // PrintAndLog("DEBUG: Error - not enough samples");
75 if (ans == -1)
76 PrintAndLog("DEBUG: Error - Jablotron too few bits found");
77 // else if (ans == -2)
78 // PrintAndLog("DEBUG: Error - problem during ASK/Biphase demod");
79 else if (ans == -3)
80 PrintAndLog("DEBUG: Error - Jablotron Size not correct: %d", size);
81 else if (ans == -4)
82 PrintAndLog("DEBUG: Error - Jablotron preamble not found");
83 else if (ans == -5)
84 PrintAndLog("DEBUG: Error - Jablotron checksum failed");
85 else
86 PrintAndLog("DEBUG: Error - ans: %d", ans);
87 }
88 return 0;
89 }
90
91 setDemodBuf(DemodBuffer+ans, 64, 0);
92
93 //got a good demod
94 uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32);
95 uint32_t raw2 = bytebits_to_byte(DemodBuffer+32, 32);
96 uint64_t cardid = (raw1 & 0xFFFF);
97 cardid <<= 24;
98 cardid |= (raw2 >> 8);
99
100 PrintAndLog("Jablotron Tag Found: Card ID %"PRIx64, cardid);
101 PrintAndLog("Raw: %08X%08X", raw1 ,raw2);
102
103 uint8_t chksum = raw2 & 0xFF;
104 PrintAndLog("Checksum: %02X [%s]",
105 chksum,
106 (chksum == jablontron_chksum(DemodBuffer)) ? "OK":"FAIL"
107 );
108
109 // Printed format: 1410-nn-nnnn-nnnn
110 PrintAndLog("Printed: 1410-%02X-%04X-%04X",
111 (raw1 & 0x0000FF00) >> 8,
112 (raw1 & 0xFF) << 8 | ((raw2 >> 24) & 0xFF),
113 (raw2 & 0x00FFFF00) >> 8
114 );
115 return 1;
116 }
117
118 int CmdJablotronRead(const char *Cmd) {
119 CmdLFRead("s");
120 getSamples("30000",false);
121 return CmdJablotronDemod(Cmd);
122 }
123
124 int CmdJablotronClone(const char *Cmd) {
125
126 uint64_t fullcode = 0;
127 uint32_t blocks[3] = {T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_64 | 2<<T55x7_MAXBLOCK_SHIFT, 0, 0};
128
129 uint8_t bits[64];
130 uint8_t *bs = bits;
131 memset(bs, 0, sizeof(bits));
132
133 char cmdp = param_getchar(Cmd, 0);
134 if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_jablotron_clone();
135
136 fullcode = param_get64ex(Cmd, 0, 0, 16);
137
138 //Q5
139 if (param_getchar(Cmd, 1) == 'Q' || param_getchar(Cmd, 1) == 'q') {
140 //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
141 blocks[0] = T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | 64<<T5555_BITRATE_SHIFT | 2<<T5555_MAXBLOCK_SHIFT;
142 }
143
144 // clearing the topbit needed for the preambl detection.
145 if ((fullcode & 0x7FFFFFFFFF) != fullcode) {
146 fullcode &= 0x7FFFFFFFFF;
147 PrintAndLog("Card Number Truncated to 39bits: %"PRIx64, fullcode);
148 }
149
150 if ( !getJablotronBits(fullcode, bs)) {
151 PrintAndLog("Error with tag bitstream generation.");
152 return 1;
153 }
154
155 //
156 blocks[1] = bytebits_to_byte(bs,32);
157 blocks[2] = bytebits_to_byte(bs+32,32);
158
159 PrintAndLog("Preparing to clone Jablotron to T55x7 with FullCode: %"PRIx64, fullcode);
160 PrintAndLog("Blk | Data ");
161 PrintAndLog("----+------------");
162 PrintAndLog(" 00 | 0x%08x", blocks[0]);
163 PrintAndLog(" 01 | 0x%08x", blocks[1]);
164 PrintAndLog(" 02 | 0x%08x", blocks[2]);
165
166 UsbCommand resp;
167 UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
168
169 for (int i=4; i>=0; i--) {
170 c.arg[0] = blocks[i];
171 c.arg[1] = i;
172 clearCommandBuffer();
173 SendCommand(&c);
174 if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
175 PrintAndLog("Error occurred, device did not respond during write operation.");
176 return -1;
177 }
178 }
179 return 0;
180 }
181
182 int CmdJablotronSim(const char *Cmd) {
183 uint64_t fullcode = 0;
184
185 char cmdp = param_getchar(Cmd, 0);
186 if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_jablotron_sim();
187
188 fullcode = param_get64ex(Cmd, 0, 0, 16);
189
190 // clearing the topbit needed for the preambl detection.
191 if ((fullcode & 0x7FFFFFFFFF) != fullcode) {
192 fullcode &= 0x7FFFFFFFFF;
193 PrintAndLog("Card Number Truncated to 39bits: %"PRIx64, fullcode);
194 }
195
196 uint8_t clk = 64, encoding = 2, separator = 0, invert = 1;
197 uint16_t arg1, arg2;
198 size_t size = 64;
199 arg1 = clk << 8 | encoding;
200 arg2 = invert << 8 | separator;
201
202 PrintAndLog("Simulating Jablotron - FullCode: %"PRIx64, fullcode);
203
204 UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
205 getJablotronBits(fullcode, c.d.asBytes);
206 clearCommandBuffer();
207 SendCommand(&c);
208 return 0;
209 }
210
211 static command_t CommandTable[] = {
212 {"help", CmdHelp, 1, "This help"},
213 {"read", CmdJablotronRead, 0, "Attempt to read and extract tag data"},
214 {"clone", CmdJablotronClone, 0, "clone jablotron tag"},
215 {"sim", CmdJablotronSim, 0, "simulate jablotron tag"},
216 {NULL, NULL, 0, NULL}
217 };
218
219 int CmdLFJablotron(const char *Cmd) {
220 clearCommandBuffer();
221 CmdsParse(CommandTable, Cmd);
222 return 0;
223 }
224
225 int CmdHelp(const char *Cmd) {
226 CmdsHelp(CommandTable);
227 return 0;
228 }
Impressum, Datenschutz