nl80211: support reading hardware id from phy directly

Do not require a temporary interface just to read the hardware ID numbers
from a given phy name, instead read the data from the ieee80211 sysfs
directory.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-08-28 11:11:28 +02:00
parent c586cd3c3a
commit a9f9557034

View file

@ -2926,37 +2926,37 @@ static int nl80211_get_mbssid_support(const char *ifname, int *buf)
static int nl80211_get_hardware_id(const char *ifname, char *buf) static int nl80211_get_hardware_id(const char *ifname, char *buf)
{ {
int rv = -1; struct iwinfo_hardware_id *id = (struct iwinfo_hardware_id *)buf;
char *res; char *phy, num[8], path[PATH_MAX];
int i;
/* Got a radioX pseudo interface, find some interface on it or create one */ struct { const char *path; uint16_t *dest; } lookup[] = {
if (!strncmp(ifname, "radio", 5)) { "vendor", &id->vendor_id },
{ { "device", &id->device_id },
/* Reuse existing interface */ { "subsystem_vendor", &id->subsystem_vendor_id },
if ((res = nl80211_phy2ifname(ifname)) != NULL) { "subsystem_device", &id->subsystem_device_id }
{ };
rv = wext_ops.hardware_id(res, buf);
}
/* Need to spawn a temporary iface for finding IDs */ memset(id, 0, sizeof(*id));
else if ((res = nl80211_ifadd(ifname)) != NULL)
/* Try to determine the phy name from the given interface */
phy = nl80211_ifname2phy(ifname);
for (i = 0; i < ARRAY_SIZE(lookup); i++)
{ {
rv = wext_ops.hardware_id(res, buf); snprintf(path, sizeof(path), "/sys/class/%s/%s/device/%s",
nl80211_ifdel(res); phy ? "ieee80211" : "net",
} phy ? phy : ifname, lookup[i].path);
}
else if (nl80211_readstr(path, num, sizeof(num)) > 0)
{ *lookup[i].dest = strtoul(num, NULL, 16);
rv = wext_ops.hardware_id(ifname, buf);
} }
/* Failed to obtain hardware IDs, search board config */ /* Failed to obtain hardware IDs, search board config */
if (rv) if (id->vendor_id == 0 || id->device_id == 0)
{ return iwinfo_hardware_id_from_mtd(id);
rv = iwinfo_hardware_id_from_mtd((struct iwinfo_hardware_id *)buf);
}
return rv; return 0;
} }
static const struct iwinfo_hardware_entry * static const struct iwinfo_hardware_entry *