Commit 4e384293 authored by Wesley W. Terpstra's avatar Wesley W. Terpstra

Add controls to get/set the MAC+IP in onewire EEPROM or runtime

Tidy up printing at startup
parent 196cba51
......@@ -47,7 +47,7 @@ void pcs_write(int location, int value)
}
/* MAC address setting */
static void set_mac_addr(uint8_t dev_addr[])
void set_mac_addr(uint8_t dev_addr[])
{
EP->MACL = ((uint32_t)dev_addr[2] << 24)
| ((uint32_t)dev_addr[3] << 16)
......@@ -101,7 +101,7 @@ int ep_enable(int enabled, int autoneg)
/* Disable the endpoint */
EP->ECR = 0;
mprintf("ID: %x", EP->IDCODE);
mprintf("ID: %x\n", EP->IDCODE);
/* Load default packet classifier rules - see ep_pfilter.c for details */
pfilter_init_default();
......
......@@ -19,6 +19,7 @@ NOT=7
void ep_init(uint8_t mac_addr[]);
void get_mac_addr(uint8_t dev_addr[]);
void set_mac_addr(uint8_t dev_addr[]);
int ep_enable(int enabled, int autoneg);
int ep_link_up(uint16_t *lpa);
int ep_get_deltas(uint32_t *delta_tx, uint32_t *delta_rx);
......
......@@ -28,7 +28,7 @@ void ipv4_init(const char* if_name, uint32_t ip) {
arp_init(if_name);
icmp_init(if_name);
TRACE_DEV("My IP: %d.%d.%d.%d\n", myIP[0], myIP[1], myIP[2], myIP[3]);
// TRACE_DEV("My IP: %d.%d.%d.%d\n", myIP[0], myIP[1], myIP[2], myIP[3]);
}
void ipv4_poll(void) {
......
......@@ -6,8 +6,31 @@
#include "shell.h"
#include "../lib/ipv4.h"
static decode_ip(const char *str, unsigned char* ip) {
int i, x;
/* Don't try to detect bad input; need small code */
for (i = 0; i < 4; ++i) {
str = fromdec(str, &x);
ip[i] = x;
if (*str == '.') ++str;
}
}
int cmd_ip(const char *args[])
{
mprintf("My IP-address: %d.%d.%d.%d\n",
myIP[0], myIP[1], myIP[2], myIP[3]);
unsigned char ip[4];
if (!args[0] || !strcasecmp(args[0], "get")) {
/* get current IP */
memcpy(ip, myIP, 4);
} else if (!strcasecmp(args[0], "set") && args[1]) {
decode_ip(args[1], ip);
memcpy(myIP, ip, 4);
} else {
return -EINVAL;
}
mprintf("IP-address: %d.%d.%d.%d\n",
ip[0], ip[1], ip[2], ip[3]);
}
......@@ -17,7 +17,7 @@ static decode_mac(const char *str, unsigned char* mac) {
}
}
int cmd_ip(const char *args[])
int cmd_mac(const char *args[])
{
unsigned char mac[6];
......@@ -26,6 +26,7 @@ int cmd_ip(const char *args[])
get_mac_addr(mac);
} else if (!strcasecmp(args[0], "getp")) {
/* get persistent MAC */
get_mac_addr(mac);
get_persistent_mac(mac);
} else if (!strcasecmp(args[0], "set") && args[1]) {
decode_mac(args[1], mac);
......
......@@ -46,6 +46,7 @@ static const struct shell_cmd cmds_list[] = {
{ "time", cmd_time },
{ "sfp", cmd_sfp },
{ "ip", cmd_ip },
{ "mac", cmd_mac },
{ NULL, NULL }
};
......@@ -136,7 +137,7 @@ void shell_init()
env_init();
cmd_len = cmd_pos = 0;
state = SH_PROMPT;
// mprintf("\033[2J\033[1;1H");
mprintf("\033[2J\033[1;1H");
}
void shell_interactive()
......@@ -228,3 +229,37 @@ void shell_interactive()
break;
}
}
const char* fromhex(const char* hex, int* v) {
int o = 0;
for (; *hex; ++hex) {
if (*hex >= '0' && *hex <= '9') {
o = (o << 4) + (*hex - '0');
} else if (*hex >= 'A' && *hex <= 'F') {
o = (o << 4) + (*hex - 'A') + 10;
} else if (*hex >= 'a' && *hex <= 'f') {
o = (o << 4) + (*hex - 'a') + 10;
} else {
break;
}
}
*v = o;
return hex;
}
const char* fromdec(const char* dec, int* v) {
int o = 0;
for (; *dec; ++dec) {
if (*dec >= '0' && *dec <= '9') {
o = (o * 10) + (*dec - '0');
} else {
break;
}
}
*v = o;
return dec;
}
#ifndef __SHELL_H
#define __SHELL_H
const char* fromhex(const char* hex, int* v);
const char* fromdec(const char* dec, int* v);
int cmd_gui(const char *args[]);
int cmd_pll(const char *args[]);
int cmd_sfp(const char *args[]);
......@@ -12,6 +15,7 @@ int cmd_mode(const char *args[]);
int cmd_measure_t24p(const char *args[]);
int cmd_time(const char *args[]);
int cmd_ip(const char *args[]);
int cmd_mac(const char *args[]);
int cmd_env(const char *args[]);
int cmd_saveenv(const char *args[]);
......
......@@ -9,4 +9,5 @@ OBJS_SHELL = shell/shell.o \
shell/cmd_measure_t24p.o \
shell/cmd_time.o \
shell/cmd_gui.o \
shell/cmd_ip.o
shell/cmd_ip.o \
shell/cmd_mac.o
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment