eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

commit a9e3b3e906933ff0df87f99661d5f30c1de0441e
parent d74fcfd25ca18eab65d5399a5487744c8986c6b8
Author: Denis Kenzior <denkenz@gmail.com>
Date:   Tue, 28 May 2019 14:12:25 -0500

scan: Convert to IWD_MODULE

Diffstat:
Msrc/main.c | 5-----
Msrc/scan.c | 110+++++++++++++++++++++++++++++++++++++------------------------------------------
Msrc/scan.h | 3---
3 files changed, 51 insertions(+), 67 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -38,7 +38,6 @@ #include "src/dbus.h" #include "src/eap.h" #include "src/eapol.h" -#include "src/scan.h" #include "src/rfkill.h" #include "src/ap.h" #include "src/plugin.h" @@ -158,9 +157,6 @@ static void nl80211_appeared(const struct l_genl_family_info *info, netdev_set_nl80211(nl80211); - if (!scan_init(nl80211)) - l_error("Unable to init scan functionality"); - ap_init(nl80211); adhoc_init(nl80211); } @@ -540,7 +536,6 @@ fail_netdev: manager_exit(); ap_exit(); adhoc_exit(); - scan_exit(); wiphy_exit(); l_genl_family_free(nl80211); } diff --git a/src/scan.c b/src/scan.c @@ -52,7 +52,6 @@ static struct l_queue *scan_contexts; static struct l_genl_family *nl80211; -static uint32_t scan_id; static uint32_t next_scan_request_id; struct scan_periodic { @@ -198,41 +197,6 @@ static void scan_context_free(struct scan_context *sc) l_free(sc); } -bool scan_ifindex_add(uint32_t ifindex) -{ - struct scan_context *sc; - - sc = l_queue_find(scan_contexts, scan_context_match, - L_UINT_TO_PTR(ifindex)); - - if (sc) - return false; - - sc = scan_context_new(ifindex); - if (!sc) - return false; - - l_queue_push_head(scan_contexts, sc); - - return true; -} - -bool scan_ifindex_remove(uint32_t ifindex) -{ - struct scan_context *sc; - - sc = l_queue_remove_if(scan_contexts, scan_context_match, - L_UINT_TO_PTR(ifindex)); - - if (!sc) - return false; - - l_info("Removing scan context for ifindex: %u", ifindex); - scan_context_free(sc); - - return true; -} - static void scan_request_triggered(struct l_genl_msg *msg, void *userdata) { struct scan_context *sc = userdata; @@ -1775,45 +1739,73 @@ void scan_freq_set_constrain(struct scan_freq_set *set, set->channels_2ghz &= constraint->channels_2ghz; } -bool scan_init(struct l_genl_family *in) +bool scan_ifindex_add(uint32_t ifindex) { - const struct l_settings *config = iwd_get_config(); + struct scan_context *sc; - nl80211 = in; - scan_id = l_genl_family_register(nl80211, "scan", scan_notify, - NULL, NULL); + sc = l_queue_find(scan_contexts, scan_context_match, + L_UINT_TO_PTR(ifindex)); - if (!scan_id) { - l_error("Registering for scan notification failed"); + if (sc) return false; - } - scan_contexts = l_queue_new(); + sc = scan_context_new(ifindex); + if (!sc) + return false; - if (!l_settings_get_double(config, "Rank", "rank_5g_factor", - &RANK_5G_FACTOR)) - RANK_5G_FACTOR = 1.0; + l_queue_push_head(scan_contexts, sc); + + if (l_queue_length(scan_contexts) > 1) + goto done; + nl80211 = l_genl_family_new(iwd_get_genl(), NL80211_GENL_NAME); + l_genl_family_register(nl80211, "scan", scan_notify, NULL, NULL); + +done: return true; } -bool scan_exit() +bool scan_ifindex_remove(uint32_t ifindex) { - bool r; + struct scan_context *sc; - l_debug(""); + sc = l_queue_remove_if(scan_contexts, scan_context_match, + L_UINT_TO_PTR(ifindex)); - if (!nl80211) + if (!sc) return false; - l_queue_destroy(scan_contexts, - (l_queue_destroy_func_t) scan_context_free); - scan_contexts = NULL; + l_info("Removing scan context for ifindex: %u", ifindex); + scan_context_free(sc); - r = l_genl_family_unregister(nl80211, scan_id); - scan_id = 0; + if (l_queue_isempty(scan_contexts)) { + l_genl_family_free(nl80211); + nl80211 = NULL; + } - nl80211 = 0; + return true; +} - return r; +static int scan_init(void) +{ + const struct l_settings *config = iwd_get_config(); + + scan_contexts = l_queue_new(); + + if (!l_settings_get_double(config, "Rank", "rank_5g_factor", + &RANK_5G_FACTOR)) + RANK_5G_FACTOR = 1.0; + + return 0; +} + +static void scan_exit() +{ + l_queue_destroy(scan_contexts, + (l_queue_destroy_func_t) scan_context_free); + scan_contexts = NULL; + l_genl_family_free(nl80211); + nl80211 = NULL; } + +IWD_MODULE(scan, scan_init, scan_exit) diff --git a/src/scan.h b/src/scan.h @@ -131,6 +131,3 @@ void scan_freq_set_constrain(struct scan_freq_set *set, bool scan_ifindex_add(uint32_t ifindex); bool scan_ifindex_remove(uint32_t ifindex); - -bool scan_init(struct l_genl_family *in); -bool scan_exit();