From 280f2d40adec7ac9c055b2e041f4bd1daaf3f64e Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Wed, 1 Jun 2016 14:58:51 -0500 Subject: [PATCH] netdev: Make netdev_init accept nl80211 --- src/main.c | 12 ++++-------- src/netdev.c | 7 ++++++- src/netdev.h | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main.c b/src/main.c index c08326a0..975f55ed 100644 --- a/src/main.c +++ b/src/main.c @@ -100,6 +100,9 @@ static void nl80211_appeared(void *user_data) if (!wiphy_init(nl80211)) l_error("Unable to init wiphy functionality"); + if (!netdev_init(nl80211)) + l_error("Unable to init netdev functionality"); + if (!scan_init(nl80211)) l_error("Unable to init scan functionality"); @@ -113,6 +116,7 @@ static void nl80211_vanished(void *user_data) wsc_exit(); scan_exit(); + netdev_exit(); wiphy_exit(); } @@ -191,11 +195,6 @@ int main(int argc, char *argv[]) goto fail_device; } - if (!netdev_init()) { - exit_status = EXIT_FAILURE; - goto fail_netdev; - } - l_debug("Opening nl80211 interface"); nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME); @@ -220,9 +219,6 @@ int main(int argc, char *argv[]) l_genl_family_unref(nl80211); fail_nl80211: - netdev_exit(); - -fail_netdev: device_exit(); fail_device: diff --git a/src/netdev.c b/src/netdev.c index dddd04d8..41074554 100644 --- a/src/netdev.c +++ b/src/netdev.c @@ -35,6 +35,7 @@ #include "src/netdev.h" static struct l_netlink *rtnl = NULL; +static struct l_genl_family *nl80211; static void do_debug(const char *str, void *user_data) { @@ -108,7 +109,7 @@ void netdev_set_linkmode_and_operstate(uint32_t ifindex, l_free(rtmmsg); } -bool netdev_init(void) +bool netdev_init(struct l_genl_family *in) { if (rtnl) return false; @@ -124,6 +125,8 @@ bool netdev_init(void) if (getenv("IWD_RTNL_DEBUG")) l_netlink_set_debug(rtnl, do_debug, "[RTNL] ", NULL); + nl80211 = in; + return true; } @@ -132,6 +135,8 @@ bool netdev_exit(void) if (!rtnl) return false; + nl80211 = NULL; + l_debug("Closing route netlink socket"); /* diff --git a/src/netdev.h b/src/netdev.h index fa994209..399f136b 100644 --- a/src/netdev.h +++ b/src/netdev.h @@ -30,5 +30,5 @@ void netdev_set_linkmode_and_operstate(uint32_t ifindex, uint8_t linkmode, uint8_t operstate, netdev_command_func_t cb, void *user_data); -bool netdev_init(void); +bool netdev_init(struct l_genl_family *in); bool netdev_exit(void);