mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-18 10:19:24 +01:00
wiphy: Add phy filtering
This commit is contained in:
parent
c9a98d9681
commit
cacd0d83f4
17
src/main.c
17
src/main.c
@ -50,6 +50,8 @@ static struct l_settings *iwd_config;
|
||||
static struct l_timeout *timeout;
|
||||
static const char *interfaces;
|
||||
static const char *nointerfaces;
|
||||
static const char *phys;
|
||||
static const char *nophys;
|
||||
static const char *config_dir;
|
||||
|
||||
static void main_loop_quit(struct l_timeout *timeout, void *user_data)
|
||||
@ -87,6 +89,8 @@ static void usage(void)
|
||||
"\t-B, --dbus-debug Enable D-Bus debugging\n"
|
||||
"\t-i, --interfaces Interfaces to manage\n"
|
||||
"\t-I, --nointerfaces Interfaces to ignore\n"
|
||||
"\t-p, --phys Phys to manage\n"
|
||||
"\t-P, --nophys Phys to ignore\n"
|
||||
"\t-c, --config Configuration directory to use\n"
|
||||
"\t-h, --help Show help options\n");
|
||||
}
|
||||
@ -96,6 +100,8 @@ static const struct option main_options[] = {
|
||||
{ "version", no_argument, NULL, 'v' },
|
||||
{ "interfaces", required_argument, NULL, 'i' },
|
||||
{ "nointerfaces", required_argument, NULL, 'I' },
|
||||
{ "phys", required_argument, NULL, 'p' },
|
||||
{ "nophys", required_argument, NULL, 'P' },
|
||||
{ "config", required_argument, NULL, 'c' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ }
|
||||
@ -114,7 +120,7 @@ static void nl80211_appeared(void *user_data)
|
||||
|
||||
l_debug("Found nl80211 interface");
|
||||
|
||||
if (!wiphy_init(nl80211))
|
||||
if (!wiphy_init(nl80211, phys, nophys))
|
||||
l_error("Unable to init wiphy functionality");
|
||||
|
||||
if (!netdev_init(nl80211, interfaces, nointerfaces))
|
||||
@ -151,7 +157,8 @@ int main(int argc, char *argv[])
|
||||
for (;;) {
|
||||
int opt;
|
||||
|
||||
opt = getopt_long(argc, argv, "Bi:I:c:vh", main_options, NULL);
|
||||
opt = getopt_long(argc, argv, "Bi:I:p:P:c:vh",
|
||||
main_options, NULL);
|
||||
if (opt < 0)
|
||||
break;
|
||||
|
||||
@ -165,6 +172,12 @@ int main(int argc, char *argv[])
|
||||
case 'I':
|
||||
nointerfaces = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
phys = optarg;
|
||||
break;
|
||||
case 'P':
|
||||
nophys = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
printf("%s\n", VERSION);
|
||||
return EXIT_SUCCESS;
|
||||
|
53
src/wiphy.c
53
src/wiphy.c
@ -28,6 +28,7 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
#include <ell/ell.h>
|
||||
|
||||
@ -45,6 +46,8 @@
|
||||
|
||||
static struct l_genl_family *nl80211 = NULL;
|
||||
static struct l_hwdb *hwdb;
|
||||
static char **whitelist_filter;
|
||||
static char **blacklist_filter;
|
||||
|
||||
struct wiphy {
|
||||
uint32_t id;
|
||||
@ -104,6 +107,38 @@ struct wiphy *wiphy_find(int wiphy_id)
|
||||
return l_queue_find(wiphy_list, wiphy_match, L_UINT_TO_PTR(wiphy_id));
|
||||
}
|
||||
|
||||
static bool wiphy_is_managed(const char *phy)
|
||||
{
|
||||
char *pattern;
|
||||
unsigned int i;
|
||||
|
||||
if (!whitelist_filter)
|
||||
goto check_blacklist;
|
||||
|
||||
for (i = 0; (pattern = whitelist_filter[i]); i++) {
|
||||
if (fnmatch(pattern, phy, 0) != 0)
|
||||
continue;
|
||||
|
||||
goto check_blacklist;
|
||||
}
|
||||
|
||||
l_debug("whitelist filtered phy: %s", phy);
|
||||
return false;
|
||||
|
||||
check_blacklist:
|
||||
if (!blacklist_filter)
|
||||
return true;
|
||||
|
||||
for (i = 0; (pattern = blacklist_filter[i]); i++) {
|
||||
if (fnmatch(pattern, phy, 0) == 0) {
|
||||
l_debug("blacklist filtered ifname: %s", phy);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *wiphy_get_path(struct wiphy *wiphy)
|
||||
{
|
||||
static char path[15];
|
||||
@ -411,6 +446,9 @@ static void wiphy_dump_callback(struct l_genl_msg *msg, void *user_data)
|
||||
|
||||
wiphy = l_queue_find(wiphy_list, wiphy_match, L_UINT_TO_PTR(id));
|
||||
if (!wiphy) {
|
||||
if (!wiphy_is_managed(name))
|
||||
return;
|
||||
|
||||
wiphy = l_new(struct wiphy, 1);
|
||||
wiphy->id = id;
|
||||
wiphy->supported_freqs = scan_freq_set_new();
|
||||
@ -520,6 +558,9 @@ static void wiphy_new_wiphy_event(struct l_genl_msg *msg)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wiphy_is_managed(name))
|
||||
return;
|
||||
|
||||
wiphy = l_new(struct wiphy, 1);
|
||||
wiphy->id = id;
|
||||
memcpy(wiphy->name, name, name_len);
|
||||
@ -773,7 +814,8 @@ static void setup_wiphy_interface(struct l_dbus_interface *interface)
|
||||
wiphy_property_get_name, NULL);
|
||||
}
|
||||
|
||||
bool wiphy_init(struct l_genl_family *in)
|
||||
bool wiphy_init(struct l_genl_family *in, const char *whitelist,
|
||||
const char *blacklist)
|
||||
{
|
||||
struct l_genl_msg *msg;
|
||||
|
||||
@ -824,11 +866,20 @@ bool wiphy_init(struct l_genl_family *in)
|
||||
|
||||
hwdb = l_hwdb_new_default();
|
||||
|
||||
if (whitelist)
|
||||
whitelist_filter = l_strsplit(whitelist, ',');
|
||||
|
||||
if (blacklist)
|
||||
blacklist_filter = l_strsplit(blacklist, ',');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wiphy_exit(void)
|
||||
{
|
||||
l_strfreev(whitelist_filter);
|
||||
l_strfreev(blacklist_filter);
|
||||
|
||||
l_queue_destroy(wiphy_list, wiphy_free);
|
||||
wiphy_list = NULL;
|
||||
|
||||
|
@ -35,5 +35,6 @@ const char *wiphy_get_path(struct wiphy *wiphy);
|
||||
uint32_t wiphy_get_supported_bands(struct wiphy *wiphy);
|
||||
bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss);
|
||||
|
||||
bool wiphy_init(struct l_genl_family *in);
|
||||
bool wiphy_init(struct l_genl_family *in, const char *whitelist,
|
||||
const char *blacklist);
|
||||
bool wiphy_exit(void);
|
||||
|
Loading…
Reference in New Issue
Block a user