Ethernet.Interface object: Fix the value of some parameters

*) Device.Ethernet.Interface.{i}.Name
*) Device.Ethernet.Interface.{i}.Upstream
*) Device.Ethernet.Interface.{i}.MaxBitRate
*) Device.Ethernet.Interface.{i}.CurrentBitRate
*) Device.Ethernet.Interface.{i}.DuplexMode
*) Update JSON file
This commit is contained in:
Amin Ben Ramdhane 2020-03-27 21:09:21 +01:00
parent fa92e8af22
commit 0db7a71e1b
2 changed files with 94 additions and 131 deletions

View file

@ -19,8 +19,6 @@ struct eth_port_args
char *ifname; char *ifname;
}; };
static char *wan_ifname = NULL;
/************************************************************* /*************************************************************
* INIT * INIT
**************************************************************/ **************************************************************/
@ -219,13 +217,8 @@ static int browseEthernetInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node,
LIST_HEAD(dup_list); LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("ports", "ethport", "dmmap_ports", &dup_list); synchronize_specific_config_sections_with_dmmap("ports", "ethport", "dmmap_ports", &dup_list);
dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_ifname);
list_for_each_entry(p, &dup_list, list) { list_for_each_entry(p, &dup_list, list) {
dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname); dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname);
if (strcmp(ifname, wan_ifname) == 0) {
if(strchr(ifname, '.')== NULL)
dmasprintf(&ifname, "%s.1", ifname);
}
init_eth_port(&curr_eth_port_args, p->config_section, ifname); init_eth_port(&curr_eth_port_args, p->config_section, ifname);
int_num = handle_update_instance(1, dmctx, &int_num_last, update_instance_alias, 3, p->dmmap_section, "eth_port_instance", "eth_port_alias"); int_num = handle_update_instance(1, dmctx, &int_num_last, update_instance_alias, 3, p->dmmap_section, "eth_port_instance", "eth_port_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_eth_port_args, int_num) == DM_STOP) if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_eth_port_args, int_num) == DM_STOP)
@ -323,12 +316,16 @@ static int browseEthernetVLANTerminationInst(struct dmctx *dmctx, DMNODE *parent
static int get_linker_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) static int get_linker_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker)
{ {
if (data && ((struct eth_port_args *)data)->ifname) { if (data && ((struct eth_port_args *)data)->ifname) {
*linker = ((struct eth_port_args *)data)->ifname; char *wan_ifname = NULL;
return 0; dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_ifname);
} else { if (strcmp(((struct eth_port_args *)data)->ifname, wan_ifname) == 0) {
if(strchr(((struct eth_port_args *)data)->ifname, '.') == NULL)
dmasprintf(linker, "%s.1", wan_ifname);
} else
*linker = ((struct eth_port_args *)data)->ifname;
} else
*linker = ""; *linker = "";
return 0; return 0;
}
} }
static int get_linker_link(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) static int get_linker_link(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker)
@ -581,24 +578,16 @@ static int get_Ethernet_VLANTerminationNumberOfEntries(char *refparam, struct dm
static int get_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
json_object *res; json_object *res;
char *ifname;
if (strstr(((struct eth_port_args *)data)->ifname, wan_ifname)) { dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
ifname = dmstrdup(wan_ifname);
} else
ifname = dmstrdup(((struct eth_port_args *)data)->ifname);
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ifname, String}}, 1, &res);
DM_ASSERT(res, *value = ""); DM_ASSERT(res, *value = "");
*value = dmjson_get_value(res, 1, "carrier"); *value = dmjson_get_value(res, 1, "carrier");
dmfree(ifname);
return 0; return 0;
} }
static int set_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) static int set_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{ {
bool b; bool b;
char *ifname;
switch (action) { switch (action) {
case VALUECHECK: case VALUECHECK:
@ -607,13 +596,7 @@ static int set_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void
return 0; return 0;
case VALUESET: case VALUESET:
string_to_bool(value, &b); string_to_bool(value, &b);
if (strstr(((struct eth_port_args *)data)->ifname, wan_ifname)) DMCMD("ethctl", 3, ((struct eth_port_args *)data)->ifname, "phy-power", b ? "up" : "down");
ifname = dmstrdup(wan_ifname);
else
ifname = dmstrdup(((struct eth_port_args *)data)->ifname);
DMCMD("ethctl", 3, ifname, "phy-power", b ? "up" : "down");
dmfree(ifname);
return 0; return 0;
} }
return 0; return 0;
@ -635,10 +618,7 @@ static int get_EthernetInterface_Alias(char *refparam, struct dmctx *ctx, void *
struct uci_section *dmmap_section = NULL; struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_ports", "ethport", section_name(((struct eth_port_args *)data)->eth_port_sec), &dmmap_section); get_dmmap_section_of_config_section("dmmap_ports", "ethport", section_name(((struct eth_port_args *)data)->eth_port_sec), &dmmap_section);
if (dmmap_section) dmuci_get_value_by_section_string(dmmap_section, "eth_port_alias", value);
dmuci_get_value_by_section_string(dmmap_section, "eth_port_alias", value);
if (*value == NULL || strlen(*value) < 1)
dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "name", value);
return 0; return 0;
} }
@ -663,7 +643,7 @@ static int set_EthernetInterface_Alias(char *refparam, struct dmctx *ctx, void *
/*#Device.Ethernet.Interface.{i}.Name!UCI:ports/ethport,@i-1/name*/ /*#Device.Ethernet.Interface.{i}.Name!UCI:ports/ethport,@i-1/name*/
static int get_EthernetInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_EthernetInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "name", value); dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "ifname", value);
return 0; return 0;
} }
@ -710,11 +690,8 @@ static int set_EthernetInterface_LowerLayers(char *refparam, struct dmctx *ctx,
static int get_EthernetInterface_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_EthernetInterface_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
char *ifname; dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "uplink", value);
dmuci_get_option_value_string("network", "lan", "ifname", &ifname); if ((*value)[0] == '\0')
if (strstr(ifname, ((struct eth_port_args *)data)->ifname))
*value = "1";
else
*value = "0"; *value = "0";
return 0; return 0;
} }
@ -725,49 +702,33 @@ static int get_EthernetInterface_MACAddress(char *refparam, struct dmctx *ctx, v
return eth_port_sysfs(data, "address", value); return eth_port_sysfs(data, "address", value);
} }
/*#Device.Ethernet.Interface.{i}.MaxBitRate!UCI:ports/ethport,@i-1/speed*/ /*#Device.Ethernet.Interface.{i}.MaxBitRate!UBUS:network.device/status/name,@Name/link-supported*/
static int get_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
char *pch, *spch, *speed; json_object *res = NULL, *link_supported = NULL;
int rate = 0;
char *max_link;
dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", &speed); dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
if (speed[0] == '\0' || strcmp(speed, "disabled") == 0 ) DM_ASSERT(res, *value = "-1");
*value = "0"; json_object_object_get_ex(res, "link-supported", &link_supported);
else { if (link_supported) {
if (strcmp(speed, "auto") == 0) max_link = dmjson_get_value_in_array_idx(link_supported, json_object_array_length(link_supported) - 1, 0);
*value = "-1"; sscanf(max_link, "%d%*s", &rate);
else { dmasprintf(value, "%d", rate);
pch = strtok_r(speed, "FHfh", &spch);
*value = dmstrdup(pch);
}
} }
return 0; return 0;
} }
static int set_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) static int set_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{ {
char *duplex, *val = "", *p = "";
switch (action) { switch (action) {
case VALUECHECK: case VALUECHECK:
if (dm_validate_int(value, RANGE_ARGS{{"-1",NULL}}, 1)) if (dm_validate_int(value, RANGE_ARGS{{"-1",NULL}}, 1))
return FAULT_9007; return FAULT_9007;
return 0; return 0;
case VALUESET: case VALUESET:
if (strcasecmp(value, "0") == 0 ) //TODO
dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", "disabled");
else if (strcmp(value, "-1") == 0)
dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", "auto");
else {
dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", &duplex);
if (strcmp(duplex, "auto") == 0 || strcmp(duplex, "disabled") == 0)
p = "FDAUTO";
else
p = strchr(duplex, 'F') ? strchr(duplex, 'F') : strchr(duplex, 'H');
if (p) dmastrcat(&val, value, p);
dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", val);
dmfree(val);
}
return 0; return 0;
} }
return 0; return 0;
@ -776,42 +737,39 @@ static int set_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, v
/*#Device.Ethernet.Interface.{i}.CurrentBitRate!UBUS:network.device/status/name,@Name/speed*/ /*#Device.Ethernet.Interface.{i}.CurrentBitRate!UBUS:network.device/status/name,@Name/speed*/
static int get_EthernetInterface_CurrentBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_EthernetInterface_CurrentBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
json_object *res; json_object *res = NULL;
char *speed, *pch; int speed = 0;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res); dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "0"); DM_ASSERT(res, *value = "0");
speed = dmjson_get_value(res, 1, "speed"); *value = dmjson_get_value(res, 1, "speed");
if(speed[0] != '\0') { sscanf(*value, "%d%*c", &speed);
pch = strtok(speed, "FHfh"); dmasprintf(value, "%d", speed);
*value = dmstrdup(pch);
} else
*value = "0";
return 0; return 0;
} }
/*#Device.Ethernet.Interface.{i}.DuplexMode!UCI:ports/status/ethport,@i-1/speed*/ /*#Device.Ethernet.Interface.{i}.DuplexMode!UBUS:network.device/status/name,@Name/speed*/
static int get_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", value); json_object *res = NULL;
if (*value[0] == '\0') char mode, *speed, *autoneg;
*value = "";
else if (strcmp(*value, "auto") == 0) dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "Auto");
autoneg = dmjson_get_value(res, 1, "autoneg");
if (strcmp(autoneg, "true") == 0) {
*value = "Auto"; *value = "Auto";
else { } else {
if (strchr(*value, 'F')) speed = dmjson_get_value(res, 1, "speed");
*value = "Full"; sscanf(speed, "%*d%c", &mode);
else if (strchr(*value, 'H')) *value = (mode == 'F') ? "Full" : "Half";
*value = "Half";
else
*value = "";
} }
return 0; return 0;
} }
static int set_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) static int set_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{ {
char *m, *spch, *rate, *val = NULL; char *speed, *spch, *val = NULL;
switch (action) { switch (action) {
case VALUECHECK: case VALUECHECK:
@ -819,28 +777,26 @@ static int set_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, v
return FAULT_9007; return FAULT_9007;
return 0; return 0;
case VALUESET: case VALUESET:
if (strcasecmp(value, "auto") == 0) { // For setting Auto
if (strcmp(value, "Auto") == 0) {
dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", "auto"); dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", "auto");
return 0; return 0;
} }
dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", &m);
m = dmstrdup(m); // For setting Full or Half
rate = m; dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", &speed);
if (strcmp(rate, "auto") == 0)
rate = "100"; if (strcmp(speed, "auto") == 0)
else { speed = "100";
strtok_r(rate, "FHfh", &spch); else
} strtok_r(speed, "FHfh", &spch);
if (strcasecmp(value, "full") == 0)
dmastrcat(&val, rate, "FD"); if (strcmp(value, "Full") == 0)
else if (strcasecmp(value, "half") == 0) dmastrcat(&val, speed, "FD");
dmastrcat(&val, rate, "HD"); else
else { dmastrcat(&val, speed, "HD");
dmfree(m);
return 0;
}
dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", val); dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", val);
dmfree(m);
dmfree(val); dmfree(val);
return 0; return 0;
} }

View file

@ -17351,16 +17351,14 @@
"unit": "Mbps", "unit": "Mbps",
"mapping": [ "mapping": [
{ {
"type": "uci", "type": "ubus",
"uci": { "ubus": {
"file": "ports", "object": "network.device",
"section": { "method": "status",
"type": "ethport", "args": {
"index": "@i-1" "name": "@Name"
}, },
"option": { "key": "link-supported"
"name": "speed"
}
} }
} }
] ]
@ -17405,12 +17403,14 @@
], ],
"mapping": [ "mapping": [
{ {
"type": "uci", "type": "ubus",
"uci": { "ubus": {
"file": "ports", "object": "network.device",
"section": { "method": "status",
"type": "status" "args": {
} "name": "@Name"
},
"key": "speed"
} }
} }
] ]
@ -17991,7 +17991,7 @@
"uci": { "uci": {
"file": "network", "file": "network",
"section": { "section": {
"type": "device" "type": "interface"
}, },
"dmmapfile": "dmmap_network" "dmmapfile": "dmmap_network"
} }
@ -28778,16 +28778,12 @@
}, },
"mapping": [ "mapping": [
{ {
"type": "uci", "type": "ubus",
"uci": { "ubus": {
"file": "wireless", "object": "wifi.radio.@Name",
"section": { "method": "status",
"type": "wifi-device", "args": {},
"index": "@i-1" "key": "standard"
},
"option": {
"name": "hwmode"
}
} }
} }
] ]
@ -30887,6 +30883,17 @@
"Enabled", "Enabled",
"Error_Misconfigured", "Error_Misconfigured",
"Error" "Error"
],
"mapping": [
{
"type": "ubus",
"ubus": {
"object": "wifi.ap.@Name",
"method": "status",
"args": {},
"key": "status"
}
}
] ]
}, },
"Alias": { "Alias": {