aboutsummaryrefslogtreecommitdiffstats
path: root/package/network/config
diff options
context:
space:
mode:
authorRafał Miłecki <zajec5@gmail.com>2016-02-03 09:38:42 +0000
committerRafał Miłecki <zajec5@gmail.com>2016-02-03 09:38:42 +0000
commit6219b3deae1c8dfbf405f5a701d3f3b00ebacce1 (patch)
tree2a5357da35389b4019903ef2f86df7d3fcb0d409 /package/network/config
parent6831bac31fde2f22bd0c26f500941e5feec17939 (diff)
downloadupstream-6219b3deae1c8dfbf405f5a701d3f3b00ebacce1.tar.gz
upstream-6219b3deae1c8dfbf405f5a701d3f3b00ebacce1.tar.bz2
upstream-6219b3deae1c8dfbf405f5a701d3f3b00ebacce1.zip
swconfig: support setting SWITCH_TYPE_LINK attributes
Supported syntax is inspired by ethtool. Example usages: swconfig dev switch0 port 2 set link "duplex half speed 100" swconfig dev switch0 port 2 set link "autoneg on" Signed-off-by: Rafał Miłecki <zajec5@gmail.com> SVN-Revision: 48624
Diffstat (limited to 'package/network/config')
-rw-r--r--package/network/config/swconfig/src/swlib.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/package/network/config/swconfig/src/swlib.c b/package/network/config/swconfig/src/swlib.c
index eeabbf14e9..9b675a924a 100644
--- a/package/network/config/swconfig/src/swlib.c
+++ b/package/network/config/swconfig/src/swlib.c
@@ -420,11 +420,20 @@ swlib_set_attr(struct switch_dev *dev, struct switch_attr *attr, struct switch_v
return swlib_call(cmd, NULL, send_attr_val, val);
}
+enum {
+ CMD_NONE,
+ CMD_DUPLEX,
+ CMD_ANEG,
+ CMD_SPEED,
+};
+
int swlib_set_attr_string(struct switch_dev *dev, struct switch_attr *a, int port_vlan, const char *str)
{
struct switch_port *ports;
+ struct switch_port_link *link;
struct switch_val val;
char *ptr;
+ int cmd = CMD_NONE;
memset(&val, 0, sizeof(val));
val.port_vlan = port_vlan;
@@ -470,6 +479,48 @@ int swlib_set_attr_string(struct switch_dev *dev, struct switch_attr *a, int por
}
val.value.ports = ports;
break;
+ case SWITCH_TYPE_LINK:
+ link = malloc(sizeof(struct switch_port_link));
+ memset(link, 0, sizeof(struct switch_port_link));
+ ptr = (char *)str;
+ for (ptr = strtok(ptr," "); ptr; ptr = strtok(NULL, " ")) {
+ switch (cmd) {
+ case CMD_NONE:
+ if (!strcmp(ptr, "duplex"))
+ cmd = CMD_DUPLEX;
+ else if (!strcmp(ptr, "autoneg"))
+ cmd = CMD_ANEG;
+ else if (!strcmp(ptr, "speed"))
+ cmd = CMD_SPEED;
+ else
+ fprintf(stderr, "Unsupported option %s\n", ptr);
+ break;
+ case CMD_DUPLEX:
+ if (!strcmp(ptr, "half"))
+ link->duplex = 0;
+ else if (!strcmp(ptr, "full"))
+ link->duplex = 1;
+ else
+ fprintf(stderr, "Unsupported value %s\n", ptr);
+ cmd = CMD_NONE;
+ break;
+ case CMD_ANEG:
+ if (!strcmp(ptr, "on"))
+ link->aneg = 1;
+ else if (!strcmp(ptr, "off"))
+ link->aneg = 0;
+ else
+ fprintf(stderr, "Unsupported value %s\n", ptr);
+ cmd = CMD_NONE;
+ break;
+ case CMD_SPEED:
+ link->speed = atoi(ptr);
+ cmd = CMD_NONE;
+ break;
+ }
+ }
+ val.value.link = link;
+ break;
case SWITCH_TYPE_NOVAL:
if (str && !strcmp(str, "0"))
return 0;