commit 12ce9debec16498675e4576855ab1ef37192ec54
parent ee91cfcb7e79dc83782cdbf4596eecfe2b94b2b5
Author: Denis Kenzior <denkenz@gmail.com>
Date: Tue, 4 Sep 2018 19:54:48 -0500
station: Move device_disconnect to station
Diffstat:
6 files changed, 64 insertions(+), 63 deletions(-)
diff --git a/src/device.c b/src/device.c
@@ -49,7 +49,6 @@
struct device {
uint32_t index;
- struct l_dbus_message *disconnect_pending;
uint8_t preauth_bssid[ETH_ALEN];
struct signal_agent *signal_agent;
@@ -521,60 +520,6 @@ static struct l_dbus_message *device_scan(struct l_dbus *dbus,
return station_dbus_scan(dbus, message, station);
}
-static void device_disconnect_cb(struct netdev *netdev, bool success,
- void *user_data)
-{
- struct device *device = user_data;
- struct station *station = device->station;
-
- l_debug("%d, success: %d", device->index, success);
-
- if (device->disconnect_pending) {
- struct l_dbus_message *reply;
-
- if (success) {
- reply = l_dbus_message_new_method_return(
- device->disconnect_pending);
- l_dbus_message_set_arguments(reply, "");
- } else
- reply = dbus_error_failed(device->disconnect_pending);
-
-
- dbus_pending_reply(&device->disconnect_pending, reply);
-
- }
-
- station_enter_state(station, STATION_STATE_DISCONNECTED);
-
- if (station->autoconnect)
- station_enter_state(station, STATION_STATE_AUTOCONNECT);
-}
-
-int device_disconnect(struct device *device)
-{
- struct station *station = device->station;
-
- if (station->state == STATION_STATE_DISCONNECTING)
- return -EBUSY;
-
- if (!station->connected_bss)
- return -ENOTCONN;
-
- if (netdev_disconnect(device->netdev, device_disconnect_cb, device) < 0)
- return -EIO;
-
- /*
- * If the disconnect somehow fails we won't know if we're still
- * connected so we may as well indicate now that we're no longer
- * connected.
- */
- station_reset_connection_state(station);
-
- station_enter_state(station, STATION_STATE_DISCONNECTING);
-
- return 0;
-}
-
static struct l_dbus_message *device_dbus_disconnect(struct l_dbus *dbus,
struct l_dbus_message *message,
void *user_data)
@@ -595,11 +540,11 @@ static struct l_dbus_message *device_dbus_disconnect(struct l_dbus *dbus,
station->state == STATION_STATE_DISCONNECTED)
return l_dbus_message_new_method_return(message);
- result = device_disconnect(device);
+ result = station_disconnect(station);
if (result < 0)
return dbus_error_from_errno(result, message);
- device->disconnect_pending = l_dbus_message_ref(message);
+ station->disconnect_pending = l_dbus_message_ref(message);
return NULL;
}
diff --git a/src/device.h b/src/device.h
@@ -36,7 +36,5 @@ int __device_connect_network(struct device *device, struct network *network,
void device_connect_network(struct device *device, struct network *network,
struct scan_bss *bss,
struct l_dbus_message *message);
-int device_disconnect(struct device *device);
-
struct device *device_create(struct wiphy *wiphy, struct netdev *netdev);
void device_remove(struct device *device);
diff --git a/src/network.c b/src/network.c
@@ -1334,13 +1334,12 @@ struct network_info *network_info_add_known(const char *ssid,
static void disconnect_no_longer_known(struct station *station, void *user_data)
{
struct network_info *info = user_data;
- struct device *device = netdev_get_device(station_get_netdev(station));
struct network *network;
network = station_get_connected_network(station);
if (network && network->info == info)
- device_disconnect(device);
+ station_disconnect(station);
}
void network_info_forget_known(struct network_info *network)
diff --git a/src/station.c b/src/station.c
@@ -1383,6 +1383,59 @@ struct l_dbus_message *station_dbus_connect_hidden_network(
return NULL;
}
+static void station_disconnect_cb(struct netdev *netdev, bool success,
+ void *user_data)
+{
+ struct station *station = user_data;
+
+ l_debug("%u, success: %d",
+ netdev_get_ifindex(station->netdev), success);
+
+ if (station->disconnect_pending) {
+ struct l_dbus_message *reply;
+
+ if (success) {
+ reply = l_dbus_message_new_method_return(
+ station->disconnect_pending);
+ l_dbus_message_set_arguments(reply, "");
+ } else
+ reply = dbus_error_failed(station->disconnect_pending);
+
+
+ dbus_pending_reply(&station->disconnect_pending, reply);
+
+ }
+
+ station_enter_state(station, STATION_STATE_DISCONNECTED);
+
+ if (station->autoconnect)
+ station_enter_state(station, STATION_STATE_AUTOCONNECT);
+}
+
+int station_disconnect(struct station *station)
+{
+ if (station->state == STATION_STATE_DISCONNECTING)
+ return -EBUSY;
+
+ if (!station->connected_bss)
+ return -ENOTCONN;
+
+ if (netdev_disconnect(station->netdev,
+ station_disconnect_cb, station) < 0)
+ return -EIO;
+
+ /*
+ * If the disconnect somehow fails we won't know if we're still
+ * connected so we may as well indicate now that we're no longer
+ * connected.
+ */
+ station_reset_connection_state(station);
+
+ station_enter_state(station, STATION_STATE_DISCONNECTING);
+
+ return 0;
+}
+
static void station_dbus_scan_triggered(int err, void *user_data)
{
struct station *station = user_data;
@@ -1514,6 +1567,10 @@ void station_free(struct station *station)
dbus_pending_reply(&station->connect_pending,
dbus_error_aborted(station->connect_pending));
+ if (station->disconnect_pending)
+ dbus_pending_reply(&station->disconnect_pending,
+ dbus_error_aborted(station->disconnect_pending));
+
if (station->scan_pending)
dbus_pending_reply(&station->scan_pending,
dbus_error_aborted(station->scan_pending));
diff --git a/src/station.h b/src/station.h
@@ -52,6 +52,7 @@ struct station {
struct l_hashmap *networks;
struct l_queue *networks_sorted;
struct l_dbus_message *connect_pending;
+ struct l_dbus_message *disconnect_pending;
struct l_dbus_message *scan_pending;
/* Roaming related members */
@@ -117,6 +118,8 @@ struct l_dbus_message *station_dbus_scan(struct l_dbus *dbus,
struct l_dbus_message *message,
void *user_data);
+int station_disconnect(struct station *station);
+
struct station *station_find(uint32_t ifindex);
void station_foreach(station_foreach_func_t func, void *user_data);
struct station *station_create(struct wiphy *wiphy, struct netdev *netdev);
diff --git a/src/wsc.c b/src/wsc.c
@@ -489,7 +489,6 @@ static void station_state_watch(enum station_state state, void *userdata)
static void wsc_check_can_connect(struct wsc *wsc, struct scan_bss *target)
{
- struct device *device = netdev_get_device(wsc->netdev);
l_debug("%p", wsc);
/*
@@ -505,7 +504,7 @@ static void wsc_check_can_connect(struct wsc *wsc, struct scan_bss *target)
return;
case STATION_STATE_CONNECTING:
case STATION_STATE_CONNECTED:
- if (device_disconnect(device) < 0)
+ if (station_disconnect(wsc->station) < 0)
goto error;
/* fall through */