Skip to content
Snippets Groups Projects
Commit a346be84 authored by Mohd Husaam Mehdi's avatar Mohd Husaam Mehdi Committed by Markus Gothe
Browse files

R#33045 Merge SNMP Fix For EXT/LAN5 To GNX-11

Merge commit : cd2778a4c9cb30210d1823ff90d2f50fbc8f3b28
to GNX-11.

Cherry-picked and tested on GNX-11.

Change-Id: I9693b06a2942c9920efcb8a52ef56d2a5846eb60
parent af8b1116
No related branches found
No related tags found
No related merge requests found
......@@ -108,6 +108,108 @@ out:
return rc;
}
/*
* Return link status of the LAN/EXT5 port.
* @return status success (1) or failure (0).
*/
static int get_lan_ext5_link_status(void)
{
int ret = 0;
char val[64] = {0};
char *cmd = "ethctl phy ext 0x14 0x00 | grep mii | awk '{ print $5 }'";
FILE *fp = popen(cmd, "r");
if (!fp) {
return ret;
}
if ((fgets(val, sizeof(val), fp) != NULL) && (strncmp(val, "0x", 2) == 0)) {
// Skip first two characters (0x) for conversion
int phy_status = (int)strtol(val + 2, NULL, 16);
int BIT_100M = (1 << 8);
int BIT_1000M = (2 << 8);
// Check if 8th (100M) or 9th (1000M) bit is set in phy_status, then link up
if ((phy_status & BIT_100M) == BIT_100M ||
(phy_status & BIT_1000M) == BIT_1000M) {
ret = 1; // Link up
}
}
pclose(fp);
return ret;
}
/*
* check if board supported for LAN/EXT5 port.
* @return status success (1) or failure (0).
*/
static int is_board_supported(void)
{
int ret = 0;
char *model_name = NULL;
json_object *router_system_info = NULL;
snmp_ubus_call("router.system", "info", UBUS_ARGS{}, 0, &router_system_info);
snmp_json_get_value_in_obj(&model_name, router_system_info, 1, "model_name");
if (strncmp(model_name, "XG6846B", 7) == 0) {
ret = 1; // Board name Supported
}
snmp_json_obj_release(router_system_info);
return ret;
}
/*
* check if ifname matches with ifname of LAN/EXT5 port.
* @param ifname interface: interface.
* @return status success (1) or failure (0).
*/
int check_if_lan_ext5_port(const char *ifname)
{
int ret = 0;
if (!is_board_supported()) {
return ret;
}
json_object *res = NULL;
struct json_object *section = NULL;
struct json_object *values = NULL;
struct json_object_iterator it;
struct json_object_iterator itEnd;
char *obj_value = NULL;
snmp_ubus_call("uci", "get", UBUS_ARGS{{"config", "ports", String}}, 1, &res);
json_object_object_get_ex(res, "values", &values);
it = json_object_iter_begin(values);
itEnd = json_object_iter_end(values);
while (!json_object_iter_equal(&it, &itEnd)) {
/*Getting hold of the required section, to get its "ifname" value.*/
section = NULL;
obj_value = NULL;
section = json_object_iter_peek_value(&it);
snmp_json_get_value_in_obj(&obj_value, section, 1, "ifname");
if (strncmp(obj_value, ifname, strlen(obj_value)) == 0) {
char *obj_value2 = NULL;
snmp_json_get_value_in_obj(&obj_value2, section, 1, "name");
if (strncmp(obj_value2, "EXT/LAN5", strlen(obj_value2)) == 0) {
ret = 1;
}
break;
}
snmp_json_obj_release(section);
json_object_iter_next(&it);
}
snmp_json_obj_release(res);
snmp_json_obj_release(values);
snmp_json_obj_release(section);
return ret;
}
/*
* Return operational state of the interface
* @param ifname interface: wan or lan interface
......@@ -121,11 +223,20 @@ static int get_operational_status(const char *ifname)
if (ifname == NULL)
return IFOPERSTATUS_DOWN;
snprintf(file, sizeof(file), "/sys/class/net/%s/operstate", ifname);
read_sysfs_file(file, val, sizeof(val));
if (check_if_lan_ext5_port(ifname)) {
int link = get_lan_ext5_link_status();
if (link) {
return IFOPERSTATUS_UP;
}
} else {
snprintf(file, sizeof(file), "/sys/class/net/%s/operstate", ifname);
read_sysfs_file(file, val, sizeof(val));
if (strncmp(val, "up", 2) == 0)
return IFOPERSTATUS_UP;
if (strncmp(val, "up", 2) == 0)
return IFOPERSTATUS_UP;
}
return IFOPERSTATUS_DOWN;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment