summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2021-06-09 14:03:29 +0200
committerFelix Fietkau <nbd@nbd.name>2021-06-09 14:05:05 +0200
commitdd6d6d2dec3515e26847e6ff8e8950d71745d560 (patch)
treeeb0cb7921292e183389e2e22119a2ce7a89ea1cd
parentaa0e3c4bbe12f02ddb3a0a2e69b3b4f0b30b9b79 (diff)
downloadiwinfo-dd6d6d2dec3515e26847e6ff8e8950d71745d560.tar.gz
iwinfo: nl80211: use new path lookup function for nl80211_phy_idx_from_uci_path
Fixes issues with multiple phy instances of one device Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--iwinfo_nl80211.c47
1 files changed, 17 insertions, 30 deletions
diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c
index be90824..8decdb0 100644
--- a/iwinfo_nl80211.c
+++ b/iwinfo_nl80211.c
@@ -295,10 +295,9 @@ static const char *nl80211_phy_path_str(const char *phyname)
static int nl80211_phy_idx_from_uci_path(struct uci_section *s)
{
- size_t linklen, pathlen;
- char buf[128], *link;
+ char buf[128];
struct dirent *e;
- const char *path;
+ const char *path, *cur_path;
int idx = -1;
DIR *d;
@@ -306,39 +305,27 @@ static int nl80211_phy_idx_from_uci_path(struct uci_section *s)
if (!path)
return -1;
- if ((d = opendir("/sys/class/ieee80211")) != NULL)
- {
- while ((e = readdir(d)) != NULL)
- {
- snprintf(buf, sizeof(buf), "/sys/class/ieee80211/%s/device", e->d_name);
-
- link = realpath(buf, NULL);
-
- if (link == NULL)
- continue;
-
- linklen = strlen(link);
- pathlen = strlen(path);
-
- if (pathlen >= linklen || strcmp(link + (linklen - pathlen), path))
- linklen = 0;
-
- free(link);
-
- if (linklen == 0)
- continue;
+ d = opendir("/sys/class/ieee80211");
+ if (!d)
+ return -1;
- snprintf(buf, sizeof(buf), "/sys/class/ieee80211/%s/index", e->d_name);
+ while ((e = readdir(d)) != NULL) {
+ cur_path = nl80211_phy_path_str(e->d_name);
+ if (!cur_path)
+ continue;
- idx = nl80211_readint(buf);
+ if (strcmp(cur_path, path) != 0)
+ continue;
- if (idx >= 0)
- break;
- }
+ snprintf(buf, sizeof(buf), "/sys/class/ieee80211/%s/index", e->d_name);
+ idx = nl80211_readint(buf);
- closedir(d);
+ if (idx >= 0)
+ break;
}
+ closedir(d);
+
return idx;
}