diff --git a/Makefile.am b/Makefile.am index b4373f99..a17890d6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -196,7 +196,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \ src/rfkill.h src/rfkill.c \ src/ft.h src/ft.c \ src/ap.h src/ap.c \ - src/adhoc.h src/adhoc.c \ + src/adhoc.c \ src/sae.h src/sae.c \ src/nl80211util.h src/nl80211util.c \ src/owe.h src/owe.c \ diff --git a/src/adhoc.c b/src/adhoc.c index ec89bc34..7a93b86c 100644 --- a/src/adhoc.c +++ b/src/adhoc.c @@ -38,12 +38,12 @@ #include "src/eapol.h" #include "src/handshake.h" #include "src/mpdu.h" -#include "src/adhoc.h" #include "src/dbus.h" #include "src/nl80211util.h" struct adhoc_state { struct netdev *netdev; + struct l_genl_family *nl80211; char *ssid; uint8_t pmk[32]; struct l_queue *sta_states; @@ -72,7 +72,6 @@ struct sta_state { bool authenticated : 1; }; -static struct l_genl_family *nl80211 = NULL; static uint32_t netdev_watch; static void adhoc_sta_free(void *data) @@ -83,7 +82,8 @@ static void adhoc_sta_free(void *data) goto end; if (sta->gtk_query_cmd_id) - l_genl_family_cancel(nl80211, sta->gtk_query_cmd_id); + l_genl_family_cancel(sta->adhoc->nl80211, + sta->gtk_query_cmd_id); if (sta->sm) eapol_sm_free(sta->sm); @@ -109,7 +109,8 @@ static void adhoc_remove_sta(struct sta_state *sta) } if (sta->gtk_query_cmd_id) { - l_genl_family_cancel(nl80211, sta->gtk_query_cmd_id); + l_genl_family_cancel(sta->adhoc->nl80211, + sta->gtk_query_cmd_id); sta->gtk_query_cmd_id = 0; } @@ -264,6 +265,7 @@ static struct eapol_sm *adhoc_new_sm(struct sta_state *sta, bool authenticator, static void adhoc_free(struct adhoc_state *adhoc) { adhoc_reset(adhoc); + l_genl_family_free(adhoc->nl80211); l_free(adhoc); } @@ -358,8 +360,8 @@ static void adhoc_new_station(struct adhoc_state *adhoc, const uint8_t *mac) adhoc->gtk, gtk_len, NULL, 0, NULL); - if (!l_genl_family_send(nl80211, msg, adhoc_gtk_op_cb, NULL, - NULL)) { + if (!l_genl_family_send(adhoc->nl80211, msg, adhoc_gtk_op_cb, + NULL, NULL)) { l_genl_msg_unref(msg); l_error("Issuing NEW_KEY failed"); return; @@ -367,8 +369,8 @@ static void adhoc_new_station(struct adhoc_state *adhoc, const uint8_t *mac) msg = nl80211_build_set_key(netdev_get_ifindex(adhoc->netdev), adhoc->gtk_index); - if (!l_genl_family_send(nl80211, msg, adhoc_gtk_op_cb, NULL, - NULL)) { + if (!l_genl_family_send(adhoc->nl80211, msg, adhoc_gtk_op_cb, + NULL, NULL)) { l_genl_msg_unref(msg); l_error("Issuing SET_KEY failed"); return; @@ -406,7 +408,7 @@ static void adhoc_new_station(struct adhoc_state *adhoc, const uint8_t *mac) else { msg = nl80211_build_get_key(netdev_get_ifindex(adhoc->netdev), adhoc->gtk_index); - sta->gtk_query_cmd_id = l_genl_family_send(nl80211, msg, + sta->gtk_query_cmd_id = l_genl_family_send(adhoc->nl80211, msg, adhoc_gtk_query_cb, sta, NULL); if (!sta->gtk_query_cmd_id) { @@ -651,6 +653,7 @@ static void adhoc_add_interface(struct netdev *netdev) /* just allocate/set device, Start method will complete setup */ adhoc = l_new(struct adhoc_state, 1); adhoc->netdev = netdev; + adhoc->nl80211 = l_genl_family_new(iwd_get_genl(), NL80211_GENL_NAME); /* setup adhoc dbus interface */ l_dbus_object_add_interface(dbus_get_bus(), @@ -682,19 +685,19 @@ static void adhoc_netdev_watch(struct netdev *netdev, } } -bool adhoc_init(struct l_genl_family *nl) +static int adhoc_init(void) { netdev_watch = netdev_watch_add(adhoc_netdev_watch, NULL, NULL); l_dbus_register_interface(dbus_get_bus(), IWD_ADHOC_INTERFACE, adhoc_setup_interface, adhoc_destroy_interface, false); - nl80211 = nl; - - return true; + return 0; } -void adhoc_exit(void) +static void adhoc_exit(void) { netdev_watch_remove(netdev_watch); l_dbus_unregister_interface(dbus_get_bus(), IWD_ADHOC_INTERFACE); } + +IWD_MODULE(adhoc, adhoc_init, adhoc_exit) diff --git a/src/adhoc.h b/src/adhoc.h deleted file mode 100644 index b7835bdf..00000000 --- a/src/adhoc.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * - * Wireless daemon for Linux - * - * Copyright (C) 2017 Intel Corporation. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -struct device; - -bool adhoc_init(struct l_genl_family *nl); -void adhoc_exit(void); diff --git a/src/main.c b/src/main.c index b0f0b97c..96d02cca 100644 --- a/src/main.c +++ b/src/main.c @@ -41,7 +41,6 @@ #include "src/rfkill.h" #include "src/ap.h" #include "src/plugin.h" -#include "src/adhoc.h" #include "src/storage.h" #include "src/backtrace.h" @@ -158,7 +157,6 @@ static void nl80211_appeared(const struct l_genl_family_info *info, netdev_set_nl80211(nl80211); ap_init(nl80211); - adhoc_init(nl80211); } extern struct iwd_module_desc __start___iwd_module[]; @@ -535,7 +533,6 @@ fail_netdev: if (nl80211) { manager_exit(); ap_exit(); - adhoc_exit(); wiphy_exit(); l_genl_family_free(nl80211); }