3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 21:22:37 +01:00

device: Move device creation from netdev.c to event watch

Create and destroy the device state struct and the DBus interfaces in a
way more similar to the Station, AdHoc and AP interfaces.  Drop
netdev_get_device() and the device specific code in netdev that as far
as I can tell wasn't needed.
This commit is contained in:
Andrew Zaborowski 2019-11-20 23:23:42 +01:00 committed by Denis Kenzior
parent bc1b9ce10c
commit 1057d8aa74
3 changed files with 35 additions and 25 deletions

View File

@ -289,31 +289,48 @@ static void device_netdev_notify(struct netdev *netdev,
enum netdev_watch_event event, enum netdev_watch_event event,
void *user_data) void *user_data)
{ {
struct device *device = netdev_get_device(netdev); struct device *device;
struct l_dbus *dbus = dbus_get_bus(); struct l_dbus *dbus = dbus_get_bus();
const char *path = netdev_get_path(netdev);
if (!device) device = l_dbus_object_get_data(dbus, path, IWD_DEVICE_INTERFACE);
if (!device && event != NETDEV_WATCH_EVENT_NEW)
return; return;
switch (event) { switch (event) {
case NETDEV_WATCH_EVENT_NEW:
if (L_WARN_ON(device))
break;
if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_P2P_CLIENT ||
netdev_get_iftype(netdev) ==
NETDEV_IFTYPE_P2P_GO)
return;
device_create(netdev_get_wiphy(netdev), netdev);
break;
case NETDEV_WATCH_EVENT_DEL:
l_dbus_unregister_object(dbus, path);
break;
case NETDEV_WATCH_EVENT_UP: case NETDEV_WATCH_EVENT_UP:
device->powered = true; device->powered = true;
l_dbus_property_changed(dbus, netdev_get_path(device->netdev), l_dbus_property_changed(dbus, path,
IWD_DEVICE_INTERFACE, "Powered"); IWD_DEVICE_INTERFACE, "Powered");
break; break;
case NETDEV_WATCH_EVENT_DOWN: case NETDEV_WATCH_EVENT_DOWN:
device->powered = false; device->powered = false;
l_dbus_property_changed(dbus, netdev_get_path(device->netdev), l_dbus_property_changed(dbus, path,
IWD_DEVICE_INTERFACE, "Powered"); IWD_DEVICE_INTERFACE, "Powered");
break; break;
case NETDEV_WATCH_EVENT_NAME_CHANGE: case NETDEV_WATCH_EVENT_NAME_CHANGE:
l_dbus_property_changed(dbus, netdev_get_path(device->netdev), l_dbus_property_changed(dbus, path,
IWD_DEVICE_INTERFACE, "Name"); IWD_DEVICE_INTERFACE, "Name");
break; break;
case NETDEV_WATCH_EVENT_ADDRESS_CHANGE: case NETDEV_WATCH_EVENT_ADDRESS_CHANGE:
l_dbus_property_changed(dbus, netdev_get_path(device->netdev), l_dbus_property_changed(dbus, path,
IWD_DEVICE_INTERFACE, "Address"); IWD_DEVICE_INTERFACE, "Address");
break; break;
default: default:
@ -380,12 +397,8 @@ struct device *device_create(struct wiphy *wiphy, struct netdev *netdev)
void device_remove(struct device *device) void device_remove(struct device *device)
{ {
struct l_dbus *dbus = dbus_get_bus();
l_debug(""); l_debug("");
l_dbus_unregister_object(dbus, netdev_get_path(device->netdev));
scan_wdev_remove(netdev_get_wdev_id(device->netdev)); scan_wdev_remove(netdev_get_wdev_id(device->netdev));
netdev_frame_watch_remove(device->netdev, device->ap_roam_watch); netdev_frame_watch_remove(device->netdev, device->ap_roam_watch);
@ -394,12 +407,19 @@ void device_remove(struct device *device)
l_free(device); l_free(device);
} }
static void destroy_device_interface(void *user_data)
{
struct device *device = user_data;
device_remove(device);
}
static int device_init(void) static int device_init(void)
{ {
if (!l_dbus_register_interface(dbus_get_bus(), if (!l_dbus_register_interface(dbus_get_bus(),
IWD_DEVICE_INTERFACE, IWD_DEVICE_INTERFACE,
setup_device_interface, setup_device_interface,
NULL, false)) destroy_device_interface, false))
return false; return false;
netdev_watch = netdev_watch_add(device_netdev_notify, NULL, NULL); netdev_watch = netdev_watch_add(device_netdev_notify, NULL, NULL);

View File

@ -49,7 +49,6 @@
#include "src/eapol.h" #include "src/eapol.h"
#include "src/handshake.h" #include "src/handshake.h"
#include "src/crypto.h" #include "src/crypto.h"
#include "src/device.h"
#include "src/scan.h" #include "src/scan.h"
#include "src/netdev.h" #include "src/netdev.h"
#include "src/ft.h" #include "src/ft.h"
@ -88,7 +87,6 @@ struct netdev {
char name[IFNAMSIZ]; char name[IFNAMSIZ];
uint32_t type; uint32_t type;
uint8_t addr[ETH_ALEN]; uint8_t addr[ETH_ALEN];
struct device *device;
struct wiphy *wiphy; struct wiphy *wiphy;
unsigned int ifi_flags; unsigned int ifi_flags;
uint32_t frequency; uint32_t frequency;
@ -149,6 +147,7 @@ struct netdev {
bool expect_connect_failure : 1; bool expect_connect_failure : 1;
bool aborting : 1; bool aborting : 1;
bool mac_randomize_once : 1; bool mac_randomize_once : 1;
bool events_ready : 1;
}; };
struct netdev_preauth_state { struct netdev_preauth_state {
@ -303,11 +302,6 @@ struct handshake_state *netdev_get_handshake(struct netdev *netdev)
return netdev->handshake; return netdev->handshake;
} }
struct device *netdev_get_device(struct netdev *netdev)
{
return netdev->device;
}
const char *netdev_get_path(struct netdev *netdev) const char *netdev_get_path(struct netdev *netdev)
{ {
static char path[256]; static char path[256];
@ -653,11 +647,9 @@ static void netdev_free(void *data)
netdev->qos_map_cmd_id = 0; netdev->qos_map_cmd_id = 0;
} }
if (netdev->device) { if (netdev->events_ready)
WATCHLIST_NOTIFY(&netdev_watches, netdev_watch_func_t, WATCHLIST_NOTIFY(&netdev_watches, netdev_watch_func_t,
netdev, NETDEV_WATCH_EVENT_DEL); netdev, NETDEV_WATCH_EVENT_DEL);
device_remove(netdev->device);
}
watchlist_destroy(&netdev->frame_watches); watchlist_destroy(&netdev->frame_watches);
watchlist_destroy(&netdev->station_watches); watchlist_destroy(&netdev->station_watches);
@ -4171,7 +4163,7 @@ static void netdev_newlink_notify(const struct ifinfomsg *ifi, int bytes)
} }
} }
if (!netdev->device) /* Did we send NETDEV_WATCH_EVENT_NEW yet? */ if (!netdev->events_ready) /* Did we send NETDEV_WATCH_EVENT_NEW yet? */
return; return;
new_up = netdev_get_is_up(netdev); new_up = netdev_get_is_up(netdev);
@ -4237,9 +4229,9 @@ static void netdev_initial_up_cb(int error, uint16_t type, const void *data,
l_debug("Interface %i initialized", netdev->index); l_debug("Interface %i initialized", netdev->index);
netdev->device = device_create(netdev->wiphy, netdev);
WATCHLIST_NOTIFY(&netdev_watches, netdev_watch_func_t, WATCHLIST_NOTIFY(&netdev_watches, netdev_watch_func_t,
netdev, NETDEV_WATCH_EVENT_NEW); netdev, NETDEV_WATCH_EVENT_NEW);
netdev->events_ready = true;
} }
static void netdev_set_mac_cb(int error, uint16_t type, const void *data, static void netdev_set_mac_cb(int error, uint16_t type, const void *data,

View File

@ -23,7 +23,6 @@
#include <stdbool.h> #include <stdbool.h>
struct netdev; struct netdev;
struct device;
struct scan_bss; struct scan_bss;
struct handshake_state; struct handshake_state;
struct eapol_sm; struct eapol_sm;
@ -135,7 +134,6 @@ int netdev_set_4addr(struct netdev *netdev, bool use_4addr,
bool netdev_get_4addr(struct netdev *netdev); bool netdev_get_4addr(struct netdev *netdev);
const char *netdev_get_name(struct netdev *netdev); const char *netdev_get_name(struct netdev *netdev);
bool netdev_get_is_up(struct netdev *netdev); bool netdev_get_is_up(struct netdev *netdev);
struct device *netdev_get_device(struct netdev *netdev);
const char *netdev_get_path(struct netdev *netdev); const char *netdev_get_path(struct netdev *netdev);
struct handshake_state *netdev_handshake_state_new(struct netdev *netdev); struct handshake_state *netdev_handshake_state_new(struct netdev *netdev);