]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhw.c
First check in.
[proxmark3-svn] / client / cmdhw.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // Hardware commands
9 //-----------------------------------------------------------------------------
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <limits.h>
15 #include "ui.h"
16 #include "proxmark3.h"
17 #include "cmdparser.h"
18 #include "cmdhw.h"
19 #include "cmdmain.h"
20
21 /* low-level hardware control */
22
23 static int CmdHelp(const char *Cmd);
24
25 static void lookupChipID(uint32_t iChipID)
26 {
27 char asBuff[100];
28 switch(iChipID)
29 {
30 case 0x270B0A40:
31 sprintf(asBuff,"AT91SAM7S512 Rev A");
32 break;
33 case 0x270B0A4F:
34 sprintf(asBuff,"AT91SAM7S512 Rev B");
35 break;
36 case 0x270D0940:
37 sprintf(asBuff,"AT91SAM7S256 Rev A");
38 break;
39 case 0x270B0941:
40 sprintf(asBuff,"AT91SAM7S256 Rev B");
41 break;
42 case 0x270B0942:
43 sprintf(asBuff,"AT91SAM7S256 Rev C");
44 break;
45 case 0x270B0943:
46 sprintf(asBuff,"AT91SAM7S256 Rev D");
47 break;
48 case 0x270C0740:
49 sprintf(asBuff,"AT91SAM7S128 Rev A");
50 break;
51 case 0x270A0741:
52 sprintf(asBuff,"AT91SAM7S128 Rev B");
53 break;
54 case 0x270A0742:
55 sprintf(asBuff,"AT91SAM7S128 Rev C");
56 break;
57 case 0x270A0743:
58 sprintf(asBuff,"AT91SAM7S128 Rev D");
59 break;
60 case 0x27090540:
61 sprintf(asBuff,"AT91SAM7S64 Rev A");
62 break;
63 case 0x27090543:
64 sprintf(asBuff,"AT91SAM7S64 Rev B");
65 break;
66 case 0x27090544:
67 sprintf(asBuff,"AT91SAM7S64 Rev C");
68 break;
69 case 0x27080342:
70 sprintf(asBuff,"AT91SAM7S321 Rev A");
71 break;
72 case 0x27080340:
73 sprintf(asBuff,"AT91SAM7S32 Rev A");
74 break;
75 case 0x27080341:
76 sprintf(asBuff,"AT91SAM7S32 Rev B");
77 break;
78 case 0x27050241:
79 sprintf(asBuff,"AT9SAM7S161 Rev A");
80 break;
81 case 0x27050240:
82 sprintf(asBuff,"AT91SAM7S16 Rev A");
83 break;
84 }
85 PrintAndLog("uC: %s",asBuff);
86 switch((iChipID&0xE0)>>5)
87 {
88 case 1:
89 sprintf(asBuff,"ARM946ES");
90 break;
91 case 2:
92 sprintf(asBuff,"ARM7TDMI");
93 break;
94 case 4:
95 sprintf(asBuff,"ARM920T");
96 break;
97 case 5:
98 sprintf(asBuff,"ARM926EJS");
99 break;
100 }
101 PrintAndLog("Embedded Processor: %s",asBuff);
102 switch((iChipID&0xF00)>>8)
103 {
104 case 0:
105 sprintf(asBuff,"None");
106 break;
107 case 1:
108 sprintf(asBuff,"8K bytes");
109 break;
110 case 2:
111 sprintf(asBuff,"16K bytes");
112 break;
113 case 3:
114 sprintf(asBuff,"32K bytes");
115 break;
116 case 5:
117 sprintf(asBuff,"64K bytes");
118 break;
119 case 7:
120 sprintf(asBuff,"128K bytes");
121 break;
122 case 9:
123 sprintf(asBuff,"256K bytes");
124 break;
125 case 10:
126 sprintf(asBuff,"512K bytes");
127 break;
128 case 12:
129 sprintf(asBuff,"1024K bytes");
130 break;
131 case 14:
132 sprintf(asBuff,"2048K bytes");
133 break;
134 }
135 PrintAndLog("Nonvolatile Program Memory Size: %s",asBuff);
136 switch((iChipID&0xF000)>>12)
137 {
138 case 0:
139 sprintf(asBuff,"None");
140 break;
141 case 1:
142 sprintf(asBuff,"8K bytes");
143 break;
144 case 2:
145 sprintf(asBuff,"16K bytes");
146 break;
147 case 3:
148 sprintf(asBuff,"32K bytes");
149 break;
150 case 5:
151 sprintf(asBuff,"64K bytes");
152 break;
153 case 7:
154 sprintf(asBuff,"128K bytes");
155 break;
156 case 9:
157 sprintf(asBuff,"256K bytes");
158 break;
159 case 10:
160 sprintf(asBuff,"512K bytes");
161 break;
162 case 12:
163 sprintf(asBuff,"1024K bytes");
164 break;
165 case 14:
166 sprintf(asBuff,"2048K bytes");
167 break;
168 }
169 PrintAndLog("Second Nonvolatile Program Memory Size: %s",asBuff);
170 switch((iChipID&0xF0000)>>16)
171 {
172 case 1:
173 sprintf(asBuff,"1K bytes");
174 break;
175 case 2:
176 sprintf(asBuff,"2K bytes");
177 break;
178 case 3:
179 sprintf(asBuff,"6K bytes");
180 break;
181 case 4:
182 sprintf(asBuff,"112K bytes");
183 break;
184 case 5:
185 sprintf(asBuff,"4K bytes");
186 break;
187 case 6:
188 sprintf(asBuff,"80K bytes");
189 break;
190 case 7:
191 sprintf(asBuff,"160K bytes");
192 break;
193 case 8:
194 sprintf(asBuff,"8K bytes");
195 break;
196 case 9:
197 sprintf(asBuff,"16K bytes");
198 break;
199 case 10:
200 sprintf(asBuff,"32K bytes");
201 break;
202 case 11:
203 sprintf(asBuff,"64K bytes");
204 break;
205 case 12:
206 sprintf(asBuff,"128K bytes");
207 break;
208 case 13:
209 sprintf(asBuff,"256K bytes");
210 break;
211 case 14:
212 sprintf(asBuff,"96K bytes");
213 break;
214 case 15:
215 sprintf(asBuff,"512K bytes");
216 break;
217 }
218 PrintAndLog("Internal SRAM Size: %s",asBuff);
219 switch((iChipID&0xFF00000)>>20)
220 {
221 case 0x19:
222 sprintf(asBuff,"AT91SAM9xx Series");
223 break;
224 case 0x29:
225 sprintf(asBuff,"AT91SAM9XExx Series");
226 break;
227 case 0x34:
228 sprintf(asBuff,"AT91x34 Series");
229 break;
230 case 0x37:
231 sprintf(asBuff,"CAP7 Series");
232 break;
233 case 0x39:
234 sprintf(asBuff,"CAP9 Series");
235 break;
236 case 0x3B:
237 sprintf(asBuff,"CAP11 Series");
238 break;
239 case 0x40:
240 sprintf(asBuff,"AT91x40 Series");
241 break;
242 case 0x42:
243 sprintf(asBuff,"AT91x42 Series");
244 break;
245 case 0x55:
246 sprintf(asBuff,"AT91x55 Series");
247 break;
248 case 0x60:
249 sprintf(asBuff,"AT91SAM7Axx Series");
250 break;
251 case 0x61:
252 sprintf(asBuff,"AT91SAM7AQxx Series");
253 break;
254 case 0x63:
255 sprintf(asBuff,"AT91x63 Series");
256 break;
257 case 0x70:
258 sprintf(asBuff,"AT91SAM7Sxx Series");
259 break;
260 case 0x71:
261 sprintf(asBuff,"AT91SAM7XCxx Series");
262 break;
263 case 0x72:
264 sprintf(asBuff,"AT91SAM7SExx Series");
265 break;
266 case 0x73:
267 sprintf(asBuff,"AT91SAM7Lxx Series");
268 break;
269 case 0x75:
270 sprintf(asBuff,"AT91SAM7Xxx Series");
271 break;
272 case 0x92:
273 sprintf(asBuff,"AT91x92 Series");
274 break;
275 case 0xF0:
276 sprintf(asBuff,"AT75Cxx Series");
277 break;
278 }
279 PrintAndLog("Architecture Identifier: %s",asBuff);
280 switch((iChipID&0x70000000)>>28)
281 {
282 case 0:
283 sprintf(asBuff,"ROM");
284 break;
285 case 1:
286 sprintf(asBuff,"ROMless or on-chip Flash");
287 break;
288 case 4:
289 sprintf(asBuff,"SRAM emulating ROM");
290 break;
291 case 2:
292 sprintf(asBuff,"Embedded Flash Memory");
293 break;
294 case 3:
295 sprintf(asBuff,"ROM and Embedded Flash Memory\nNVPSIZ is ROM size\nNVPSIZ2 is Flash size");
296 break;
297 }
298 PrintAndLog("Nonvolatile Program Memory Type: %s",asBuff);
299 }
300
301 int CmdDetectReader(const char *Cmd)
302 {
303 UsbCommand c={CMD_LISTEN_READER_FIELD};
304 // 'l' means LF - 125/134 kHz
305 if(*Cmd == 'l') {
306 c.arg[0] = 1;
307 } else if (*Cmd == 'h') {
308 c.arg[0] = 2;
309 } else if (*Cmd != '\0') {
310 PrintAndLog("use 'detectreader' or 'detectreader l' or 'detectreader h'");
311 return 0;
312 }
313 SendCommand(&c);
314 return 0;
315 }
316
317 // ## FPGA Control
318 int CmdFPGAOff(const char *Cmd)
319 {
320 UsbCommand c = {CMD_FPGA_MAJOR_MODE_OFF};
321 SendCommand(&c);
322 return 0;
323 }
324
325 int CmdLCD(const char *Cmd)
326 {
327 int i, j;
328
329 UsbCommand c={CMD_LCD};
330 sscanf(Cmd, "%x %d", &i, &j);
331 while (j--) {
332 c.arg[0] = i & 0x1ff;
333 SendCommand(&c);
334 }
335 return 0;
336 }
337
338 int CmdLCDReset(const char *Cmd)
339 {
340 UsbCommand c = {CMD_LCD_RESET, {strtol(Cmd, NULL, 0), 0, 0}};
341 SendCommand(&c);
342 return 0;
343 }
344
345 int CmdReadmem(const char *Cmd)
346 {
347 UsbCommand c = {CMD_READ_MEM, {strtol(Cmd, NULL, 0), 0, 0}};
348 SendCommand(&c);
349 return 0;
350 }
351
352 int CmdReset(const char *Cmd)
353 {
354 UsbCommand c = {CMD_HARDWARE_RESET};
355 SendCommand(&c);
356 return 0;
357 }
358
359 /*
360 * Sets the divisor for LF frequency clock: lets the user choose any LF frequency below
361 * 600kHz.
362 */
363 int CmdSetDivisor(const char *Cmd)
364 {
365 UsbCommand c = {CMD_SET_LF_DIVISOR, {strtol(Cmd, NULL, 0), 0, 0}};
366 if (c.arg[0] < 19 || c.arg[0] > 255) {
367 PrintAndLog("divisor must be between 19 and 255");
368 } else {
369 SendCommand(&c);
370 PrintAndLog("Divisor set, expected freq=%dHz", 12000000 / (c.arg[0]+1));
371 }
372 return 0;
373 }
374
375 int CmdSetMux(const char *Cmd)
376 {
377 UsbCommand c={CMD_SET_ADC_MUX};
378 if (strcmp(Cmd, "lopkd") == 0) {
379 c.arg[0] = 0;
380 } else if (strcmp(Cmd, "loraw") == 0) {
381 c.arg[0] = 1;
382 } else if (strcmp(Cmd, "hipkd") == 0) {
383 c.arg[0] = 2;
384 } else if (strcmp(Cmd, "hiraw") == 0) {
385 c.arg[0] = 3;
386 }
387 SendCommand(&c);
388 return 0;
389 }
390
391 int CmdTune(const char *Cmd)
392 {
393 UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING};
394 SendCommand(&c);
395 return 0;
396 }
397
398 int CmdVersion(const char *Cmd)
399 {
400 UsbCommand c = {CMD_VERSION};
401 UsbCommand resp;
402 SendCommand(&c);
403 if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
404 lookupChipID(resp.arg[0]);
405 }
406 return 0;
407 }
408
409 static command_t CommandTable[] =
410 {
411 {"help", CmdHelp, 1, "This help"},
412 {"detectreader", CmdDetectReader,0, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},
413 {"fpgaoff", CmdFPGAOff, 0, "Set FPGA off"},
414 {"lcd", CmdLCD, 0, "<HEX command> <count> -- Send command/data to LCD"},
415 {"lcdreset", CmdLCDReset, 0, "Hardware reset LCD"},
416 {"readmem", CmdReadmem, 0, "[address] -- Read memory at decimal address from flash"},
417 {"reset", CmdReset, 0, "Reset the Proxmark3"},
418 {"setlfdivisor", CmdSetDivisor, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
419 {"setmux", CmdSetMux, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
420 {"tune", CmdTune, 0, "Measure antenna tuning"},
421 {"version", CmdVersion, 0, "Show version inforation about the connected Proxmark"},
422 {NULL, NULL, 0, NULL}
423 };
424
425 int CmdHW(const char *Cmd)
426 {
427 CmdsParse(CommandTable, Cmd);
428 return 0;
429 }
430
431 int CmdHelp(const char *Cmd)
432 {
433 CmdsHelp(CommandTable);
434 return 0;
435 }
Impressum, Datenschutz