diff --git a/src/core/agent_map.c b/src/core/agent_map.c index a97e67a1d0af31116133b1d38d3c16697760f5dd..e5ee1ddb7178d8f2deb9a49dc448eccf038b7e97 100644 --- a/src/core/agent_map.c +++ b/src/core/agent_map.c @@ -772,8 +772,11 @@ int check_wireless_ifname(struct agent *a, const char *device, char *wifi_gen_first_ifname(struct agent *a, char *device, char *ifname) { int i; + int devnum = get_device_num_from_name(device); - strncpy(ifname, device, IFNAMSIZ); + snprintf(ifname, IFNAMSIZ, "%s%d", + a->cfg.netdev, + devnum); /* maximum number of interface per BSSID is currently 4 * setting a higher number may cause segfault within libwsc.so, @@ -786,8 +789,9 @@ char *wifi_gen_first_ifname(struct agent *a, char *device, char *ifname) if (!check_wireless_ifname(a, device, ifname)) return ifname; - snprintf(ifname, IFNAMSIZ, "%s%s%d", - device, + snprintf(ifname, IFNAMSIZ, "%s%d%s%d", + a->cfg.netdev, + devnum, (a->cfg.brcm_setup ? "." : "_"), i); } diff --git a/src/core/config.c b/src/core/config.c index d2e17bde8131671baf2ca9eea39087b60fe0f1ba..05af1f4cc370b82a2e6ddc9e6e50fe20c4aac4ed 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -10,6 +10,11 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> + +#ifndef IFNAMSIZ +#define IFNAMSIZ 16 +#endif + #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif @@ -1242,6 +1247,7 @@ static int agent_config_get_wifi_agent(struct agent_config *a, A_EXCLUDE, A_EXCLUDE_BTM, A_AL_BRIDGE, + A_NETDEV, NUM_POLICIES }; const struct uci_parse_option opts[] = { @@ -1254,6 +1260,7 @@ static int agent_config_get_wifi_agent(struct agent_config *a, { .name = "exclude", .type = UCI_TYPE_LIST }, { .name = "exclude_btm", .type = UCI_TYPE_LIST }, { .name = "al_bridge", .type = UCI_TYPE_STRING }, + { .name = "netdev", .type = UCI_TYPE_STRING }, }; struct uci_option *tb[NUM_POLICIES]; @@ -1310,6 +1317,14 @@ static int agent_config_get_wifi_agent(struct agent_config *a, } else /* Default to br-lan if non-specfied */ strncpy(a->al_bridge, "br-lan", sizeof(a->al_bridge) - 1); + if (tb[A_NETDEV]) { + const char *ifname; + ifname = tb[A_NETDEV]->v.string; + strncpy(a->netdev, ifname, sizeof(a->netdev) - 1); + } else { /* Default to wl/wlan if not specfied */ + strncpy(a->netdev, (a->brcm_setup)?"wl":"wlan", sizeof(a->netdev) - 1); + } + return 0; } @@ -2070,11 +2085,12 @@ int agent_config_clean(struct agent_config *cfg) return 0; } -int wifi_reorder_interfaces_by_device(struct agent_config *a, +int wifi_reorder_interfaces_by_device(struct agent_config *ac, struct uci_context *ctx, struct uci_package *pkg, char *device) { int i, j = 0; - char ifname[16] = {0}; + int devnum = 0; + char ifname[IFNAMSIZ] = {0}; enum { W_IFNAME, NUM_POLICIES @@ -2087,7 +2103,10 @@ int wifi_reorder_interfaces_by_device(struct agent_config *a, trace("reordering interfaces for device %s\n", device); - strncpy(ifname, device, sizeof(ifname)); + devnum = get_device_num_from_name(device); + snprintf(ifname, IFNAMSIZ, "%s%d", + ac->netdev, + devnum); for (i = 1; i < 16; i++) { trace("iterating in search of %s\n", ifname); @@ -2111,16 +2130,17 @@ int wifi_reorder_interfaces_by_device(struct agent_config *a, break; } - snprintf(ifname, sizeof(ifname), "%s%s%d", - device, - (a->brcm_setup ? "." : "_"), + snprintf(ifname, IFNAMSIZ, "%s%d%s%d", + ac->netdev, + devnum, + (ac->brcm_setup ? "." : "_"), i); } return 0; } -int wifi_reorder_interfaces(struct agent_config *a) +int wifi_reorder_interfaces(struct agent_config *ac) { struct uci_context *ctx; @@ -2142,7 +2162,7 @@ int wifi_reorder_interfaces(struct agent_config *a) if (strncmp(s->type, UCI_WL_DEVICE, strlen(UCI_WL_DEVICE))) continue; - wifi_reorder_interfaces_by_device(a, ctx, pkg, s->e.name); + wifi_reorder_interfaces_by_device(ac, ctx, pkg, s->e.name); } uci_commit(ctx, &pkg, false); diff --git a/src/core/config.h b/src/core/config.h index 60844c767bb82c056c97ed0346032aa65415f3eb..5594f026e85ef222691e8897b2a2fe14c895eb1e 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -158,6 +158,7 @@ struct agent_config { bool configured; uint8_t cntlr_almac[6]; char al_bridge[16]; + char netdev[16]; struct policy_cfg *pcfg; /* policy section */ struct uloop_timeout metric_report_timer; @@ -245,9 +246,9 @@ int uci_apply_m2(struct agent_config *cfg, char *interface_name, char *device, uint8_t *bridge, uint8_t *proto, uint8_t vid, uint32_t br_ip, uint8_t *bk_ssid, uint8_t *bk_key, bool onboaded); int uci_apply_wps_credentials(struct agent_config *cfg, enum wifi_band band); -int wifi_reorder_interfaces_by_device(struct agent_config *a, +int wifi_reorder_interfaces_by_device(struct agent_config *ac, struct uci_context *ctx, struct uci_package *pkg, char *device); -int wifi_reorder_interfaces(struct agent_config *a); +int wifi_reorder_interfaces(struct agent_config *ac); int uci_set_bridge(char *config, char *bridge, char *proto, char *ipaddress); int uci_add_dhcp(char *interface); int uci_add_fw(struct agent_config *cfg, char *interface); diff --git a/src/utils/utils.c b/src/utils/utils.c index 7d44bb921308d7ab2b8ae1cfbffdc26bff407123..dabe805d92cad98286206ee3835f7efef2d5b7f8 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -468,3 +468,13 @@ uint8_t wifi_band_to_ieee1905band(uint8_t band) return ieee1905band; } + +uint8_t get_device_num_from_name(char *device) +{ + char *p = device; + + while (*p && !isdigit(*p)) + p++; + + return atoi(p); +} diff --git a/src/utils/utils.h b/src/utils/utils.h index 3dabc4c8169711c1f40227d882e74adeaee319b5..53149596fdc5fe3a743e3f74b4d45beb1cac25e8 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -156,5 +156,5 @@ int set_sighandler(int sig, void (*handler)(int)); int unset_sighandler(int sig); void do_daemonize(const char *pidfile); uint8_t wifi_band_to_ieee1905band(uint8_t band); - +uint8_t get_device_num_from_name(char *device); #endif /* UTILS_H */