From ac2eeab570b75819124d55155d606a5e926eb556 Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Wed, 8 May 2019 03:15:26 +0200 Subject: [PATCH] wiphy: Add wiphy_get_driver api Read the driver name for each wiphy from sysfs if available. I didn't find a better way to obtain the driver name for a phy than by reading the dir name that the "driver" symlink points at. For an existing netdev this can be done using the SIOCETHTOOL ioctl. --- src/wiphy.c | 32 ++++++++++++++++++++++++++++++++ src/wiphy.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/wiphy.c b/src/wiphy.c index 54b6de63..cb66c037 100644 --- a/src/wiphy.c +++ b/src/wiphy.c @@ -24,11 +24,14 @@ #include #endif +#define _GNU_SOURCE #include #include #include #include #include +#include +#include #include @@ -63,6 +66,7 @@ struct wiphy { struct scan_freq_set *supported_freqs; char *model_str; char *vendor_str; + char *driver_str; struct watchlist state_watches; bool support_scheduled_scan:1; @@ -185,6 +189,7 @@ static void wiphy_free(void *data) watchlist_destroy(&wiphy->state_watches); l_free(wiphy->model_str); l_free(wiphy->vendor_str); + l_free(wiphy->driver_str); l_free(wiphy); } @@ -316,6 +321,11 @@ bool wiphy_supports_adhoc_rsn(struct wiphy *wiphy) return wiphy->support_adhoc_rsn; } +const char *wiphy_get_driver(struct wiphy *wiphy) +{ + return wiphy->driver_str; +} + bool wiphy_constrain_freq_set(const struct wiphy *wiphy, struct scan_freq_set *set) { @@ -659,6 +669,26 @@ bool wiphy_parse_id_and_name(struct l_genl_attr *attr, uint32_t *out_id, return true; } +static bool wiphy_get_driver_name(struct wiphy *wiphy) +{ + L_AUTO_FREE_VAR(char *, driver_link) = NULL; + char driver_path[256]; + ssize_t len; + + driver_link = l_strdup_printf("/sys/class/ieee80211/%s/device/driver", + wiphy->name); + len = readlink(driver_link, driver_path, sizeof(driver_path) - 1); + + if (len == -1) { + l_error("Can't read %s: %s", driver_link, strerror(errno)); + return false; + } + + driver_path[len] = '\0'; + wiphy->driver_str = l_strdup(basename(driver_path)); + return true; +} + static void wiphy_register(struct wiphy *wiphy) { struct l_dbus *dbus = dbus_get_bus(); @@ -699,6 +729,8 @@ static void wiphy_register(struct wiphy *wiphy) l_hwdb_lookup_free(entries); } + wiphy_get_driver_name(wiphy); + if (!l_dbus_object_add_interface(dbus, wiphy_get_path(wiphy), IWD_WIPHY_INTERFACE, wiphy)) l_info("Unable to add the %s interface to %s", diff --git a/src/wiphy.h b/src/wiphy.h index 792602c8..c187d3e5 100644 --- a/src/wiphy.h +++ b/src/wiphy.h @@ -67,6 +67,7 @@ bool wiphy_has_ext_feature(struct wiphy *wiphy, uint32_t feature); uint8_t wiphy_get_max_num_ssids_per_scan(struct wiphy *wiphy); bool wiphy_supports_iftype(struct wiphy *wiphy, uint32_t iftype); bool wiphy_supports_adhoc_rsn(struct wiphy *wiphy); +const char *wiphy_get_driver(struct wiphy *wiphy); uint32_t wiphy_state_watch_add(struct wiphy *wiphy, wiphy_state_watch_func_t func, void *user_data,