/*
* swconfig.c: Switch configuration utility
*
- * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
+ * Copyright (C) 2008 Felix Fietkau <nbd@nbd.name>
* Copyright (C) 2010 Martin Mares <mj@ucw.cz>
*
* This program is free software; you can redistribute it and/or
CMD_LOAD,
CMD_HELP,
CMD_SHOW,
- CMD_PORTMAP,
};
static void
print_attrs(dev->port_ops);
}
+static const char *
+speed_str(int speed)
+{
+ switch (speed) {
+ case 10:
+ return "10baseT";
+ case 100:
+ return "100baseT";
+ case 1000:
+ return "1000baseT";
+ default:
+ break;
+ }
+
+ return "unknown";
+}
+
static void
print_attr_val(const struct switch_attr *attr, const struct switch_val *val)
{
+ struct switch_port_link *link;
int i;
switch (attr->type) {
SWLIB_PORT_FLAG_TAGGED) ? "t" : "");
}
break;
+ case SWITCH_TYPE_LINK:
+ link = val->value.link;
+ if (link->link)
+ printf("port:%d link:up speed:%s %s-duplex %s%s%s%s%s",
+ val->port_vlan,
+ speed_str(link->speed),
+ link->duplex ? "full" : "half",
+ link->tx_flow ? "txflow " : "",
+ link->rx_flow ? "rxflow " : "",
+ link->eee & SWLIB_LINK_FLAG_EEE_100BASET ? "eee100 " : "",
+ link->eee & SWLIB_LINK_FLAG_EEE_1000BASET ? "eee1000 " : "",
+ link->aneg ? "auto" : "");
+ else
+ printf("port:%d link:down", val->port_vlan);
+ break;
default:
printf("?unknown-type?");
}
print_usage();
cmd = CMD_LOAD;
ckey = argv[++i];
- } else if (!strcmp(arg, "portmap")) {
- if (i + 1 < argc)
- csegment = argv[++i];
- cmd = CMD_PORTMAP;
} else if (!strcmp(arg, "show")) {
cmd = CMD_SHOW;
} else {
if(cvlan > -1)
cport = cvlan;
- if(swlib_set_attr_string(dev, a, cport, cvalue) < 0)
+ retval = swlib_set_attr_string(dev, a, cport, cvalue);
+ if (retval < 0)
{
- fprintf(stderr, "failed\n");
- retval = -1;
+ nl_perror(-retval, "Failed to set attribute");
goto out;
}
break;
val.port_vlan = cvlan;
if(cport > -1)
val.port_vlan = cport;
- if(swlib_get_attr(dev, a, &val) < 0)
+ retval = swlib_get_attr(dev, a, &val);
+ if (retval < 0)
{
- fprintf(stderr, "failed\n");
- retval = -1;
+ nl_perror(-retval, "Failed to get attribute");
goto out;
}
print_attr_val(a, &val);
case CMD_HELP:
list_attributes(dev);
break;
- case CMD_PORTMAP:
- swlib_print_portmap(dev, csegment);
- break;
case CMD_SHOW:
if (cport >= 0 || cvlan >= 0) {
if (cport >= 0)