summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2007-07-05 18:01:34 +0200
committerSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-07-05 18:01:34 +0200
commit8dcc816ba942e4db1622df05e4bb0e049684dacf (patch)
tree50f3042d32a1220646f92dce2ecd443cd0f180fe /net
parent62fb48c82b44436e85ae2a8a5c93ef178583cf65 (diff)
downloadbarebox-8dcc816ba942e4db1622df05e4bb0e049684dacf.tar.gz
barebox-8dcc816ba942e4db1622df05e4bb0e049684dacf.tar.xz
svn_rev_227
fix parameter handling
Diffstat (limited to 'net')
-rw-r--r--net/eth.c61
-rw-r--r--net/net.c13
2 files changed, 16 insertions, 58 deletions
diff --git a/net/eth.c b/net/eth.c
index e2db385e9d..abf3ec9c2d 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -30,57 +30,12 @@
#include <malloc.h>
#include <asm-generic/errno.h>
-typedef enum eth_cookies {
- PARAM_IP,
- PARAM_MAC,
- PARAM_GW,
- PARAM_NM,
-} eth_cookies_t;
-
-static char *eth_get(struct device_d* dev, struct param_d *param)
-{
- struct eth_device *edev = dev->priv;
- char *buf;
-
- switch (param->cookie) {
- case PARAM_MAC:
- buf = malloc(18);
- enet_addr_to_string(edev->enetaddr, buf);
- break;
- default:
- buf = strdup((char *)param->val);
- }
-
- return buf;
-}
-
-static int eth_set(struct device_d* dev, struct param_d *param, char *newval)
-{
- struct eth_device *edev = dev->priv;
- int ret;
-
- switch (param->cookie) {
- case PARAM_MAC:
- if (string_to_enet_addr(newval, edev->enetaddr))
- return -EINVAL;
-
- if ((ret = edev->set_mac_address(edev, newval)))
- return ret;
- /* Fall through */
- default:
- if (param->val)
- free(param->val);
- param->val = strdup(newval);
- }
-
- return 0;
-}
-
static struct param_d eth_params[] = {
- { .name = "ip", .cookie = PARAM_IP, .set = eth_set, .get = eth_get},
- { .name = "mac", .cookie = PARAM_MAC, .set = eth_set, .get = eth_get},
- { .name = "gateway", .cookie = PARAM_GW, .set = eth_set, .get = eth_get},
- { .name = "netmask", .cookie = PARAM_NM, .set = eth_set, .get = eth_get},
+ { .name = "ip", .type = PARAM_TYPE_IPADDR,},
+ { .name = "mac", .type = PARAM_TYPE_STRING,},
+ { .name = "gateway", .type = PARAM_TYPE_IPADDR,},
+ { .name = "netmask", .type = PARAM_TYPE_IPADDR,},
+ { .name = "serverip", .type = PARAM_TYPE_IPADDR,},
};
static struct eth_device *eth_current;
@@ -137,6 +92,7 @@ int eth_register(struct eth_device *edev)
struct device_d *dev = edev->dev;
unsigned char ethaddr_str[20];
unsigned char ethaddr[6];
+ value_t val;
int i;
@@ -147,14 +103,15 @@ int eth_register(struct eth_device *edev)
return -1;
}
- for (i = 0; i < 4; i++)
+ for (i = 0; i < 5; i++)
dev_add_parameter(dev, &eth_params[i]);
if (edev->get_mac_address(edev, ethaddr) == 0) {
sprintf (ethaddr_str, "%02X:%02X:%02X:%02X:%02X:%02X",
ethaddr[0], ethaddr[1], ethaddr[2], ethaddr[3], ethaddr[4], ethaddr[5]);
printf("got MAC address from EEPROM: %s\n",ethaddr_str);
- dev_set_param(dev, "mac", ethaddr);
+ val.val_str = ethaddr_str;
+ dev_set_param(dev, "mac", val);
memcpy(edev->enetaddr, ethaddr, 6);
}
diff --git a/net/net.c b/net/net.c
index da504b4561..7f36c0132a 100644
--- a/net/net.c
+++ b/net/net.c
@@ -253,9 +253,10 @@ void ArpTimeoutCheck(void)
int
NetLoop(proto_t protocol)
{
+ struct eth_device *eth_current = eth_get_current();
IPaddr_t ip;
- ip = getenv_IPaddr ("ipaddr");
+ ip = dev_get_param_ip(eth_current->dev, "ip");
NetCopyIP(&NetOurIP, &ip);
/* XXX problem with bss workaround */
@@ -310,8 +311,8 @@ restart:
#endif
case NETCONS:
case TFTP:
- NetOurGatewayIP = getenv_IPaddr ("gatewayip");
- NetOurSubnetMask= getenv_IPaddr ("netmask");
+ NetOurGatewayIP = dev_get_param_ip(eth_current->dev, "gateway");
+ NetOurSubnetMask = dev_get_param_ip(eth_current->dev, "netmask");
NetOurVLAN = getenv_VLAN("vlan");
NetOurNativeVLAN = getenv_VLAN("nvlan");
@@ -321,7 +322,7 @@ restart:
#endif
case NETCONS:
case TFTP:
- NetServerIP = getenv_IPaddr ("serverip");
+ NetServerIP = dev_get_param_ip(eth_current->dev, "serverip");
break;
#ifdef CONFIG_NET_PING
case PING:
@@ -345,7 +346,7 @@ restart:
* IP addr assigned to us by the BOOTP / RARP server
*/
NetOurIP = 0;
- NetServerIP = getenv_IPaddr ("serverip");
+ NetServerIP = dev_get_param_ip(eth_current->dev, "serverip");
NetOurVLAN = getenv_VLAN("vlan"); /* VLANs must be read */
NetOurNativeVLAN = getenv_VLAN("nvlan");
case CDP:
@@ -374,7 +375,7 @@ restart:
/* Start with a clean slate... */
BootpTry = 0;
NetOurIP = 0;
- NetServerIP = getenv_IPaddr ("serverip");
+ NetServerIP = dev_get_param_ip(eth_current->dev, "serverip");
DhcpRequest(); /* Basically same as BOOTP */
break;
#endif