diff --git a/Makefile.am b/Makefile.am index d6c6ce29..1d572db5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -189,7 +189,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \ src/plugin.h src/plugin.c \ src/netdev.h src/netdev.c \ src/wiphy.h src/wiphy.c \ - src/device.h src/device.c \ + src/device.c \ src/station.h src/station.c \ src/ie.h src/ie.c \ src/dbus.h src/dbus.c \ diff --git a/src/adhoc.c b/src/adhoc.c index a63c4669..52164a0a 100644 --- a/src/adhoc.c +++ b/src/adhoc.c @@ -30,7 +30,6 @@ #include "src/iwd.h" #include "src/module.h" -#include "src/device.h" #include "src/netdev.h" #include "src/wiphy.h" #include "src/crypto.h" diff --git a/src/ap.c b/src/ap.c index e79de108..f8698e9a 100644 --- a/src/ap.c +++ b/src/ap.c @@ -34,7 +34,6 @@ #include "src/iwd.h" #include "src/module.h" #include "src/scan.h" -#include "src/device.h" #include "src/netdev.h" #include "src/wiphy.h" #include "src/crypto.h" diff --git a/src/device.c b/src/device.c index db8bbbac..3ed39619 100644 --- a/src/device.c +++ b/src/device.c @@ -38,7 +38,6 @@ #include "src/netdev.h" #include "src/dbus.h" #include "src/station.h" -#include "src/device.h" struct device { uint32_t index; @@ -285,6 +284,75 @@ static void setup_device_interface(struct l_dbus_interface *interface) device_property_set_mode); } +static void device_wiphy_state_changed_event(struct wiphy *wiphy, + enum wiphy_state_watch_event event, + void *user_data) +{ + struct device *device = user_data; + + switch (event) { + case WIPHY_STATE_WATCH_EVENT_RFKILLED: + break; + case WIPHY_STATE_WATCH_EVENT_POWERED: + if (device->dbus_powered) + netdev_set_powered(device->netdev, true, + NULL, NULL, NULL); + break; + } +} + +static struct device *device_create(struct wiphy *wiphy, struct netdev *netdev) +{ + struct device *device; + struct l_dbus *dbus = dbus_get_bus(); + uint32_t ifindex = netdev_get_ifindex(netdev); + const uint8_t action_ap_roam_prefix[2] = { 0x0a, 0x07 }; + + device = l_new(struct device, 1); + device->index = ifindex; + device->wiphy = wiphy; + device->netdev = netdev; + + if (!l_dbus_object_add_interface(dbus, netdev_get_path(device->netdev), + IWD_DEVICE_INTERFACE, device)) + l_info("Unable to register %s interface", IWD_DEVICE_INTERFACE); + + if (!l_dbus_object_add_interface(dbus, netdev_get_path(device->netdev), + L_DBUS_INTERFACE_PROPERTIES, device)) + l_info("Unable to register %s interface", + L_DBUS_INTERFACE_PROPERTIES); + + scan_wdev_add(netdev_get_wdev_id(device->netdev)); + + /* + * register for AP roam transition watch + */ + device->ap_roam_watch = netdev_frame_watch_add(netdev, 0x00d0, + action_ap_roam_prefix, sizeof(action_ap_roam_prefix), + device_ap_roam_frame_event, device); + + device->powered = netdev_get_is_up(netdev); + + device->dbus_powered = true; + device->wiphy_rfkill_watch = + wiphy_state_watch_add(wiphy, device_wiphy_state_changed_event, + device, NULL); + + return device; +} + +static void device_free(struct device *device) +{ + l_debug(""); + + scan_wdev_remove(netdev_get_wdev_id(device->netdev)); + + netdev_frame_watch_remove(device->netdev, device->ap_roam_watch); + wiphy_state_watch_remove(device->wiphy, device->wiphy_rfkill_watch); + + l_free(device); +} + static void device_netdev_notify(struct netdev *netdev, enum netdev_watch_event event, void *user_data) @@ -338,80 +406,11 @@ static void device_netdev_notify(struct netdev *netdev, } } -static void device_wiphy_state_changed_event(struct wiphy *wiphy, - enum wiphy_state_watch_event event, - void *user_data) -{ - struct device *device = user_data; - - switch (event) { - case WIPHY_STATE_WATCH_EVENT_RFKILLED: - break; - case WIPHY_STATE_WATCH_EVENT_POWERED: - if (device->dbus_powered) - netdev_set_powered(device->netdev, true, - NULL, NULL, NULL); - break; - } -} - -struct device *device_create(struct wiphy *wiphy, struct netdev *netdev) -{ - struct device *device; - struct l_dbus *dbus = dbus_get_bus(); - uint32_t ifindex = netdev_get_ifindex(netdev); - const uint8_t action_ap_roam_prefix[2] = { 0x0a, 0x07 }; - - device = l_new(struct device, 1); - device->index = ifindex; - device->wiphy = wiphy; - device->netdev = netdev; - - if (!l_dbus_object_add_interface(dbus, netdev_get_path(device->netdev), - IWD_DEVICE_INTERFACE, device)) - l_info("Unable to register %s interface", IWD_DEVICE_INTERFACE); - - if (!l_dbus_object_add_interface(dbus, netdev_get_path(device->netdev), - L_DBUS_INTERFACE_PROPERTIES, device)) - l_info("Unable to register %s interface", - L_DBUS_INTERFACE_PROPERTIES); - - scan_wdev_add(netdev_get_wdev_id(device->netdev)); - - /* - * register for AP roam transition watch - */ - device->ap_roam_watch = netdev_frame_watch_add(netdev, 0x00d0, - action_ap_roam_prefix, sizeof(action_ap_roam_prefix), - device_ap_roam_frame_event, device); - - device->powered = netdev_get_is_up(netdev); - - device->dbus_powered = true; - device->wiphy_rfkill_watch = - wiphy_state_watch_add(wiphy, device_wiphy_state_changed_event, - device, NULL); - - return device; -} - -void device_remove(struct device *device) -{ - l_debug(""); - - scan_wdev_remove(netdev_get_wdev_id(device->netdev)); - - netdev_frame_watch_remove(device->netdev, device->ap_roam_watch); - wiphy_state_watch_remove(device->wiphy, device->wiphy_rfkill_watch); - - l_free(device); -} - static void destroy_device_interface(void *user_data) { struct device *device = user_data; - device_remove(device); + device_free(device); } static int device_init(void) diff --git a/src/device.h b/src/device.h deleted file mode 100644 index 31e472be..00000000 --- a/src/device.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * Wireless daemon for Linux - * - * Copyright (C) 2013-2019 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 - * - */ - -#include - -struct wiphy; -struct netdev; -struct device; - -struct device *device_create(struct wiphy *wiphy, struct netdev *netdev); -void device_remove(struct device *device); diff --git a/src/station.c b/src/station.c index 0da352c3..c6029423 100644 --- a/src/station.c +++ b/src/station.c @@ -37,7 +37,6 @@ #include "src/iwd.h" #include "src/module.h" #include "src/common.h" -#include "src/device.h" #include "src/watchlist.h" #include "src/scan.h" #include "src/netdev.h"