Skip to content

Commit

Permalink
nl80211: handle per_sta_vif case properly
Browse files Browse the repository at this point in the history
When per_sta_vif is enabled in hostapd BSS config, we need to iterate
through every interface in /sys/class/net which matches
`${interface_requested}.${number}`. Otherwise data requested from iwinfo
will be incomplete/nonexistant. This is already handled for WDS so there is
precedence for a change like this.

Also refactor logic on whether to issue a NL80211_CMD_GET_STATION request
on the interface into a seperate function.

Closes openwrt/openwrt#14339

Signed-off-by: Rany Hany <[email protected]>
  • Loading branch information
rany2 committed Jan 6, 2024
1 parent a34977c commit c421d75
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions iwinfo_nl80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,33 @@ static int nl80211_readstr(const char *path, char *buffer, int length)
return rv;
}

static bool nl80211_is_numeric(const char *str)
{
return strlen(str) > 0 && !str[strspn(str, "0123456789")];
}

static bool nl80211_should_get_station(const char *req_name,
const char *cur_name)
{
if (strncmp(cur_name, req_name, strlen(req_name)))
return false;

if (!cur_name[strlen(req_name)])
return true;

if (cur_name[strlen(req_name)] == '.')
{
if (!strncmp(&cur_name[strlen(req_name) + 1], "sta", 3) &&
nl80211_is_numeric(&cur_name[strlen(req_name) + sizeof(".sta") - 1]))
return true;

if (nl80211_is_numeric(&cur_name[strlen(req_name) + sizeof(".") - 1]))
return true;
}

return false;
}

static int nl80211_get_band(int nla_type)
{
switch (nla_type)
Expand Down Expand Up @@ -1615,9 +1642,7 @@ static void nl80211_fill_signal(const char *ifname, struct nl80211_rssi_rate *r)
{
while ((de = readdir(d)) != NULL)
{
if (!strncmp(de->d_name, ifname, strlen(ifname)) &&
(!de->d_name[strlen(ifname)] ||
!strncmp(&de->d_name[strlen(ifname)], ".sta", 4)))
if (nl80211_should_get_station(ifname, de->d_name))
{
nl80211_request(de->d_name, NL80211_CMD_GET_STATION,
NLM_F_DUMP, nl80211_fill_signal_cb, r);
Expand Down Expand Up @@ -2389,9 +2414,7 @@ static int nl80211_get_assoclist(const char *ifname, char *buf, int *len)
{
while ((de = readdir(d)) != NULL)
{
if (!strncmp(de->d_name, ifname, strlen(ifname)) &&
(!de->d_name[strlen(ifname)] ||
!strncmp(&de->d_name[strlen(ifname)], ".sta", 4)))
if (nl80211_should_get_station(ifname, de->d_name))
{
nl80211_request(de->d_name, NL80211_CMD_GET_STATION,
NLM_F_DUMP, nl80211_get_assoclist_cb, &arr);
Expand Down

0 comments on commit c421d75

Please sign in to comment.