Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nl80211: handle per_sta_vif case properly #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions iwinfo_nl80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,38 @@ static int nl80211_readstr(const char *path, char *buffer, int length)
return rv;
}

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

static bool nl80211_strstarts(const char *str, const char *prefix, size_t len)
{
return strncmp(str, prefix, len) == 0;
}

static bool nl80211_should_get_station(const char *cur_name, const char *req_name,
size_t req_name_len)
{
if (!nl80211_strstarts(cur_name, req_name, req_name_len))
return false;

if (!cur_name[req_name_len])
return true;

if (cur_name[req_name_len] == '.')
{
if (nl80211_strstarts(&cur_name[req_name_len + 1], "sta", 3) &&
nl80211_is_numeric(&cur_name[req_name_len + 4]))
return true;

if (nl80211_is_numeric(&cur_name[req_name_len + 1]))
return true;
}

return false;
}

static int nl80211_get_band(int nla_type)
{
switch (nla_type)
Expand Down Expand Up @@ -1608,16 +1640,15 @@ static void nl80211_fill_signal(const char *ifname, struct nl80211_rssi_rate *r)
{
DIR *d;
struct dirent *de;
size_t ifname_len = strlen(ifname);

memset(r, 0, sizeof(*r));

if ((d = opendir("/sys/class/net")) != NULL)
{
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(de->d_name, ifname, ifname_len))
{
nl80211_request(de->d_name, NL80211_CMD_GET_STATION,
NLM_F_DUMP, nl80211_fill_signal_cb, r);
Expand Down Expand Up @@ -2384,14 +2415,13 @@ static int nl80211_get_assoclist(const char *ifname, char *buf, int *len)
struct dirent *de;
struct nl80211_array_buf arr = { .buf = buf, .count = 0 };
struct iwinfo_assoclist_entry *e;
size_t ifname_len = strlen(ifname);

if ((d = opendir("/sys/class/net")) != NULL)
{
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(de->d_name, ifname, ifname_len))
{
nl80211_request(de->d_name, NL80211_CMD_GET_STATION,
NLM_F_DUMP, nl80211_get_assoclist_cb, &arr);
Expand Down