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