Detect SoC wireless mac such as AR9340 using the devices modalias string. Beside PCI IDs the hardware.txt can now contain modalias strings as device identification.
Signed-off-by: Stefan Agner <ste...@agner.ch> --- package/network/utils/iwinfo/src/hardware.txt | 1 + package/network/utils/iwinfo/src/include/iwinfo.h | 1 + .../utils/iwinfo/src/include/iwinfo/utils.h | 3 +- .../network/utils/iwinfo/src/include/iwinfo/wext.h | 1 + package/network/utils/iwinfo/src/iwinfo_nl80211.c | 50 +++++++++++----------- package/network/utils/iwinfo/src/iwinfo_utils.c | 39 ++++++++++++++++- package/network/utils/iwinfo/src/iwinfo_wext.c | 9 ++++ 7 files changed, 78 insertions(+), 26 deletions(-) diff --git a/package/network/utils/iwinfo/src/hardware.txt b/package/network/utils/iwinfo/src/hardware.txt index 153ffeb..85b2986 100644 --- a/package/network/utils/iwinfo/src/hardware.txt +++ b/package/network/utils/iwinfo/src/hardware.txt @@ -51,6 +51,7 @@ 0x168c 0x0029 0x168c 0xa095 0 0 "Atheros" "AR9223" 0x168c 0x002a 0x168c 0xa093 0 0 "Atheros" "AR9280" 0x168c 0x002b 0x168c 0xa091 0 0 "Atheros" "AR9285" +"platform:ar934x_wmac" 0 0 "Atheros" "AR9340" 0x168c 0x0033 0x168c 0xa120 0 0 "Atheros" "AR9580" 0x1814 0x3050 0x1814 0x0005 0 0 "RaLink" "Rt3050" 0x1814 0x3052 0x1814 0x0008 0 0 "RaLink" "Rt3052" diff --git a/package/network/utils/iwinfo/src/include/iwinfo.h b/package/network/utils/iwinfo/src/include/iwinfo.h index ebea319..474b44f 100644 --- a/package/network/utils/iwinfo/src/include/iwinfo.h +++ b/package/network/utils/iwinfo/src/include/iwinfo.h @@ -138,6 +138,7 @@ struct iwinfo_hardware_entry { uint16_t device_id; uint16_t subsystem_vendor_id; uint16_t subsystem_device_id; + char modalias[64]; int16_t txpower_offset; int16_t frequency_offset; }; diff --git a/package/network/utils/iwinfo/src/include/iwinfo/utils.h b/package/network/utils/iwinfo/src/include/iwinfo/utils.h index d58ec5f..90aa84a 100644 --- a/package/network/utils/iwinfo/src/include/iwinfo/utils.h +++ b/package/network/utils/iwinfo/src/include/iwinfo/utils.h @@ -37,7 +37,8 @@ int iwinfo_ifmac(const char *ifname); void iwinfo_close(void); -struct iwinfo_hardware_entry * iwinfo_hardware(struct iwinfo_hardware_id *id); +struct iwinfo_hardware_entry * iwinfo_hardware_modalias(char *modalias); +struct iwinfo_hardware_entry * iwinfo_hardware_pci(struct iwinfo_hardware_id *id); int iwinfo_hardware_id_from_mtd(struct iwinfo_hardware_id *id); diff --git a/package/network/utils/iwinfo/src/include/iwinfo/wext.h b/package/network/utils/iwinfo/src/include/iwinfo/wext.h index e84f6a6..b86b050 100644 --- a/package/network/utils/iwinfo/src/include/iwinfo/wext.h +++ b/package/network/utils/iwinfo/src/include/iwinfo/wext.h @@ -51,6 +51,7 @@ int wext_get_countrylist(const char *ifname, char *buf, int *len); int wext_get_hwmodelist(const char *ifname, int *buf); int wext_get_mbssid_support(const char *ifname, int *buf); int wext_get_hardware_id(const char *ifname, char *buf); +int wext_get_hardware_modalias(const char *ifname, char *buf); int wext_get_hardware_name(const char *ifname, char *buf); void wext_close(void); diff --git a/package/network/utils/iwinfo/src/iwinfo_nl80211.c b/package/network/utils/iwinfo/src/iwinfo_nl80211.c index a258d2f..c43bd09 100644 --- a/package/network/utils/iwinfo/src/iwinfo_nl80211.c +++ b/package/network/utils/iwinfo/src/iwinfo_nl80211.c @@ -2281,28 +2281,8 @@ int nl80211_get_mbssid_support(const char *ifname, int *buf) int nl80211_get_hardware_id(const char *ifname, char *buf) { int rv; - char *res; - /* Got a radioX pseudo interface, find some interface on it or create one */ - if (!strncmp(ifname, "radio", 5)) - { - /* Reuse existing interface */ - if ((res = nl80211_phy2ifname(ifname)) != NULL) - { - rv = wext_get_hardware_id(res, buf); - } - - /* Need to spawn a temporary iface for finding IDs */ - else if ((res = nl80211_ifadd(ifname)) != NULL) - { - rv = wext_get_hardware_id(res, buf); - nl80211_ifdel(res); - } - } - else - { - rv = wext_get_hardware_id(ifname, buf); - } + rv = wext_get_hardware_id(ifname, buf); /* Failed to obtain hardware IDs, search board config */ if (rv) @@ -2317,11 +2297,33 @@ static const struct iwinfo_hardware_entry * nl80211_get_hardware_entry(const char *ifname) { struct iwinfo_hardware_id id; + static struct iwinfo_hardware_entry *he = NULL; + char *res, *real_ifname = ifname, *tmp_ifname = NULL; + static char modalias[64]; - if (nl80211_get_hardware_id(ifname, (char *)&id)) - return NULL; + if (!strncmp(ifname, "radio", 5)) + { + /* Reuse existing interface */ + if ((res = nl80211_phy2ifname(ifname)) != NULL) + real_ifname = res; + + /* Need to spawn a temporary iface for finding IDs */ + else if ((tmp_ifname = nl80211_ifadd(ifname)) != NULL) + real_ifname = tmp_ifname; + } + + /* Try to get hardware using PCI IDs */ + if (!nl80211_get_hardware_id(real_ifname, (char *)&id)) + he = iwinfo_hardware_pci(&id); + + /* Try to get hardware from modalias (SoC) */ + else if (!wext_get_hardware_modalias(real_ifname, modalias)) + he = iwinfo_hardware_modalias(modalias); + + if (tmp_ifname != NULL) + nl80211_ifdel(tmp_ifname); - return iwinfo_hardware(&id); + return he; } int nl80211_get_hardware_name(const char *ifname, char *buf) diff --git a/package/network/utils/iwinfo/src/iwinfo_utils.c b/package/network/utils/iwinfo/src/iwinfo_utils.c index 1a831f3..6b55e9e 100644 --- a/package/network/utils/iwinfo/src/iwinfo_utils.c +++ b/package/network/utils/iwinfo/src/iwinfo_utils.c @@ -127,7 +127,7 @@ void iwinfo_close(void) ioctl_socket = -1; } -struct iwinfo_hardware_entry * iwinfo_hardware(struct iwinfo_hardware_id *id) +struct iwinfo_hardware_entry * iwinfo_hardware_modalias(char *modalias) { FILE *db; char buf[256] = { 0 }; @@ -140,6 +140,43 @@ struct iwinfo_hardware_entry * iwinfo_hardware(struct iwinfo_hardware_id *id) { memset(&e, 0, sizeof(e)); + if (!strcmp(buf, "\"platform:")) + continue; + + if (sscanf(buf, "\"%63[^\"]\" %hd %hd \"%63[^\"]\" \"%63[^\"]\"", + e.modalias, &e.txpower_offset, + &e.frequency_offset, e.vendor_name, + e.device_name) < 5) + continue; + + if (!strcmp(e.modalias, modalias)) + continue; + + rv = &e; + break; + } + + fclose(db); + return rv; +} + +struct iwinfo_hardware_entry * iwinfo_hardware_pci(struct iwinfo_hardware_id *id) +{ + FILE *db; + char buf[256] = { 0 }; + static struct iwinfo_hardware_entry e, *rv = NULL; + + if (!(db = fopen(IWINFO_HARDWARE_FILE, "r"))) + return NULL; + + while (fgets(buf, sizeof(buf) - 1, db) != NULL) + { + memset(&e, 0, sizeof(e)); + + /* Parse PCI device IDs only */ + if (buf[0] != '0' || buf[1] != 'x') + continue; + if (sscanf(buf, "%hx %hx %hx %hx %hd %hd \"%63[^\"]\" \"%63[^\"]\"", &e.vendor_id, &e.device_id, &e.subsystem_vendor_id, &e.subsystem_device_id, diff --git a/package/network/utils/iwinfo/src/iwinfo_wext.c b/package/network/utils/iwinfo/src/iwinfo_wext.c index 890a36d..163480e 100644 --- a/package/network/utils/iwinfo/src/iwinfo_wext.c +++ b/package/network/utils/iwinfo/src/iwinfo_wext.c @@ -506,6 +506,15 @@ int wext_get_hardware_id(const char *ifname, char *buf) return (id->vendor_id > 0 && id->device_id > 0) ? 0 : -1; } +int wext_get_hardware_modalias(const char *ifname, char *buf) +{ + char *data = wext_sysfs_ifname_file(ifname, "device/modalias"); + if (data) + strcpy(buf, data); + + return data ? 0 : -1; +} + int wext_get_hardware_name(const char *ifname, char *buf) { sprintf(buf, "Generic WEXT"); -- 1.8.4.2 _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel