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