]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhw.c
alphabet ;)
[proxmark3-svn] / client / cmdhw.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <limits.h>
5 #include "ui.h"
6 #include "proxusb.h"
7 #include "cmdparser.h"
8 #include "cmdhw.h"
9
10 /* low-level hardware control */
11
12 static int CmdHelp(const char *Cmd);
13
14 int CmdDetectReader(const char *Cmd)
15 {
16 UsbCommand c={CMD_LISTEN_READER_FIELD};
17 // 'l' means LF - 125/134 kHz
18 if(*Cmd == 'l') {
19 c.arg[0] = 1;
20 } else if (*Cmd == 'h') {
21 c.arg[0] = 2;
22 } else if (*Cmd != '\0') {
23 PrintAndLog("use 'detectreader' or 'detectreader l' or 'detectreader h'");
24 return 0;
25 }
26 SendCommand(&c);
27 return 0;
28 }
29
30 // ## FPGA Control
31 int CmdFPGAOff(const char *Cmd)
32 {
33 UsbCommand c = {CMD_FPGA_MAJOR_MODE_OFF};
34 SendCommand(&c);
35 return 0;
36 }
37
38 int CmdLCD(const char *Cmd)
39 {
40 int i, j;
41
42 UsbCommand c={CMD_LCD};
43 sscanf(Cmd, "%x %d", &i, &j);
44 while (j--) {
45 c.arg[0] = i & 0x1ff;
46 SendCommand(&c);
47 }
48 return 0;
49 }
50
51 int CmdLCDReset(const char *Cmd)
52 {
53 UsbCommand c = {CMD_LCD_RESET, {strtol(Cmd, NULL, 0), 0, 0}};
54 SendCommand(&c);
55 return 0;
56 }
57
58 int CmdReadmem(const char *Cmd)
59 {
60 UsbCommand c = {CMD_READ_MEM, {strtol(Cmd, NULL, 0), 0, 0}};
61 SendCommand(&c);
62 return 0;
63 }
64
65 int CmdReset(const char *Cmd)
66 {
67 UsbCommand c = {CMD_HARDWARE_RESET};
68 SendCommand(&c);
69 return 0;
70 }
71
72 /*
73 * Sets the divisor for LF frequency clock: lets the user choose any LF frequency below
74 * 600kHz.
75 */
76 int CmdSetDivisor(const char *Cmd)
77 {
78 UsbCommand c = {CMD_SET_LF_DIVISOR, {strtol(Cmd, NULL, 0), 0, 0}};
79 if (c.arg[0] < 0 || c.arg[0] > 255) {
80 PrintAndLog("divisor must be between 19 and 255");
81 } else {
82 SendCommand(&c);
83 PrintAndLog("Divisor set, expected freq=%dHz", 12000000 / (c.arg[0]+1));
84 }
85 return 0;
86 }
87
88 int CmdSetMux(const char *Cmd)
89 {
90 UsbCommand c={CMD_SET_ADC_MUX};
91 if (strcmp(Cmd, "lopkd") == 0) {
92 c.arg[0] = 0;
93 } else if (strcmp(Cmd, "loraw") == 0) {
94 c.arg[0] = 1;
95 } else if (strcmp(Cmd, "hipkd") == 0) {
96 c.arg[0] = 2;
97 } else if (strcmp(Cmd, "hiraw") == 0) {
98 c.arg[0] = 3;
99 }
100 SendCommand(&c);
101 return 0;
102 }
103
104 int CmdTune(const char *Cmd)
105 {
106 UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING};
107 SendCommand(&c);
108 return 0;
109 }
110
111 int CmdVersion(const char *Cmd)
112 {
113 UsbCommand c = {CMD_VERSION};
114 SendCommand(&c);
115 return 0;
116 }
117
118 static command_t CommandTable[] =
119 {
120 {"help", CmdHelp, 1, "This help"},
121 {"detectreader", CmdDetectReader,0, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},
122 {"fpgaoff", CmdFPGAOff, 0, "Set FPGA off"},
123 {"lcd", CmdLCD, 0, "<HEX command> <count> -- Send command/data to LCD"},
124 {"lcdreset", CmdLCDReset, 0, "Hardware reset LCD"},
125 {"readmem", CmdReadmem, 0, "[address] -- Read memory at decimal address from flash"},
126 {"reset", CmdReset, 0, "Reset the Proxmark3"},
127 {"setlfdivisor", CmdSetDivisor, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
128 {"setmux", CmdSetMux, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
129 {"tune", CmdTune, 0, "Measure antenna tuning"},
130 {"version", CmdVersion, 0, "Show version inforation about the connected Proxmark"},
131 {NULL, NULL, 0, NULL}
132 };
133
134 int CmdHW(const char *Cmd)
135 {
136 CmdsParse(CommandTable, Cmd);
137 return 0;
138 }
139
140 int CmdHelp(const char *Cmd)
141 {
142 CmdsHelp(CommandTable);
143 return 0;
144 }
Impressum, Datenschutz