3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 13:02:44 +01:00

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.
This commit is contained in:
Andrew Zaborowski 2019-05-08 03:15:26 +02:00 committed by Denis Kenzior
parent 7ce8d9d8b6
commit ac2eeab570
2 changed files with 33 additions and 0 deletions

View File

@ -24,11 +24,14 @@
#include <config.h>
#endif
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <linux/if_ether.h>
#include <fnmatch.h>
#include <unistd.h>
#include <string.h>
#include <ell/ell.h>
@ -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",

View File

@ -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,