summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2022-10-14 10:59:07 +0200
committerFelix Fietkau <nbd@nbd.name>2022-10-14 10:59:08 +0200
commit0496c722f1d798789d9280d9e357f87b920349eb (patch)
treefe2e3aa4311b0ec80f71d23ddf8c2633c297504d
parent4a43b0d40ba50a21de1d47e7bf0f759be9cf646a (diff)
downloadiwinfo-0496c722f1d798789d9280d9e357f87b920349eb.tar.gz
nl80211: fix issues with renamed wiphy and multiple phy per device
Remove the assumption that phy names follow the format phy%d and instead look up the phy index from sysfs properly Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--iwinfo_nl80211.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c
index 5d224b3..1898373 100644
--- a/iwinfo_nl80211.c
+++ b/iwinfo_nl80211.c
@@ -241,11 +241,15 @@ static const char *nl80211_phy_path_str(const char *phyname)
int buf_len, offset;
struct dirent *e;
char buf[128], *link;
- int phy_id;
+ int phy_idx;
int seq = 0;
DIR *d;
- phy_id = atoi(phyname + 3);
+ snprintf(buf, sizeof(buf), "/sys/class/ieee80211/%s/index", phyname);
+ phy_idx = nl80211_readint(buf);
+ if (phy_idx < 0)
+ return NULL;
+
buf_len = snprintf(buf, sizeof(buf), "/sys/class/ieee80211/%s/device", phyname);
link = realpath(buf, path);
if (!link)
@@ -267,13 +271,14 @@ static const char *nl80211_phy_path_str(const char *phyname)
return link;
while ((e = readdir(d)) != NULL) {
- int cur_id;
+ int cur_idx;
- if (strncmp(e->d_name, "phy", 3) != 0)
+ snprintf(buf, sizeof(buf), "/sys/class/ieee80211/%s/index", e->d_name);
+ cur_idx = nl80211_readint(buf);
+ if (cur_idx < 0)
continue;
- cur_id = atoi(e->d_name + 3);
- if (cur_id >= phy_id)
+ if (cur_idx >= phy_idx)
continue;
seq++;