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