Commit b368b8fe authored by Dan Williams's avatar Dan Williams

Merge remote branch 'origin/sup-rework'

parents 8310593c f532f41c
......@@ -78,30 +78,17 @@ typedef enum
#define NM_ETHERNET_ERROR (nm_ethernet_error_quark ())
#define NM_TYPE_ETHERNET_ERROR (nm_ethernet_error_get_type ())
typedef struct SupplicantStateTask {
NMDeviceEthernet *self;
guint32 new_state;
guint32 old_state;
gboolean mgr_task;
guint source_id;
} SupplicantStateTask;
typedef struct Supplicant {
NMSupplicantManager *mgr;
NMSupplicantInterface *iface;
/* signal handler ids */
guint mgr_state_id;
guint iface_error_id;
guint iface_state_id;
guint iface_con_state_id;
/* Timeouts and idles */
guint iface_con_error_cb_id;
guint con_timeout_id;
GSList *iface_tasks;
GSList *mgr_tasks;
} Supplicant;
typedef struct {
......@@ -996,30 +983,6 @@ remove_supplicant_timeouts (NMDeviceEthernet *self)
}
}
static void
finish_supplicant_task (SupplicantStateTask *task, gboolean remove_source)
{
NMDeviceEthernet *self = task->self;
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
/* idle/timeout handlers should pass FALSE for remove_source, since they
* will tell glib to remove their source from the mainloop by returning
* FALSE when they exit. When called from this NMDevice's dispose handler,
* remove_source should be TRUE to cancel all outstanding idle/timeout
* handlers asynchronously.
*/
if (task->source_id && remove_source)
g_source_remove (task->source_id);
if (task->mgr_task)
priv->supplicant.mgr_tasks = g_slist_remove (priv->supplicant.mgr_tasks, task);
else
priv->supplicant.iface_tasks = g_slist_remove (priv->supplicant.iface_tasks, task);
memset (task, 0, sizeof (SupplicantStateTask));
g_slice_free (SupplicantStateTask, task);
}
static void
remove_supplicant_interface_error_handler (NMDeviceEthernet *self)
{
......@@ -1044,28 +1007,14 @@ supplicant_interface_release (NMDeviceEthernet *self)
remove_supplicant_timeouts (self);
remove_supplicant_interface_error_handler (self);
/* Clean up all pending supplicant interface state idle tasks */
while (priv->supplicant.iface_tasks)
finish_supplicant_task ((SupplicantStateTask *) priv->supplicant.iface_tasks->data, TRUE);
if (priv->supplicant.iface_con_state_id) {
g_signal_handler_disconnect (priv->supplicant.iface, priv->supplicant.iface_con_state_id);
priv->supplicant.iface_con_state_id = 0;
}
if (priv->supplicant.iface_state_id > 0) {
g_signal_handler_disconnect (priv->supplicant.iface, priv->supplicant.iface_state_id);
priv->supplicant.iface_state_id = 0;
}
if (priv->supplicant.mgr_state_id) {
g_signal_handler_disconnect (priv->supplicant.mgr, priv->supplicant.mgr_state_id);
priv->supplicant.mgr_state_id = 0;
}
if (priv->supplicant.iface) {
nm_supplicant_interface_disconnect (priv->supplicant.iface);
nm_supplicant_manager_release_iface (priv->supplicant.mgr, priv->supplicant.iface);
nm_supplicant_manager_iface_release (priv->supplicant.mgr, priv->supplicant.iface);
priv->supplicant.iface = NULL;
}
}
......@@ -1127,77 +1076,6 @@ time_out:
return FALSE;
}
static gboolean
schedule_state_handler (NMDeviceEthernet *self,
GSourceFunc handler,
guint32 new_state,
guint32 old_state,
gboolean mgr_task)
{
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
SupplicantStateTask *task;
if (new_state == old_state)
return TRUE;
task = g_slice_new0 (SupplicantStateTask);
if (!task) {
nm_log_err (LOGD_DEVICE, "Not enough memory to process supplicant manager state change.");
return FALSE;
}
task->self = self;
task->new_state = new_state;
task->old_state = old_state;
task->mgr_task = mgr_task;
task->source_id = g_idle_add (handler, task);
if (mgr_task)
priv->supplicant.mgr_tasks = g_slist_append (priv->supplicant.mgr_tasks, task);
else
priv->supplicant.iface_tasks = g_slist_append (priv->supplicant.iface_tasks, task);
return TRUE;
}
static gboolean
supplicant_mgr_state_cb_handler (gpointer user_data)
{
SupplicantStateTask *task = (SupplicantStateTask *) user_data;
NMDevice *device = NM_DEVICE (task->self);
/* If the supplicant went away, release the supplicant interface */
if (task->new_state == NM_SUPPLICANT_MANAGER_STATE_DOWN) {
supplicant_interface_release (task->self);
if (nm_device_get_state (device) > NM_DEVICE_STATE_UNAVAILABLE) {
nm_device_state_changed (device, NM_DEVICE_STATE_UNAVAILABLE,
NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED);
}
}
finish_supplicant_task (task, FALSE);
return FALSE;
}
static void
supplicant_mgr_state_cb (NMSupplicantInterface * iface,
guint32 new_state,
guint32 old_state,
gpointer user_data)
{
nm_log_info (LOGD_DEVICE | LOGD_ETHER,
"(%s): supplicant manager state: %s -> %s",
nm_device_get_iface (NM_DEVICE (user_data)),
nm_supplicant_manager_state_to_string (old_state),
nm_supplicant_manager_state_to_string (new_state));
schedule_state_handler (NM_DEVICE_ETHERNET (user_data),
supplicant_mgr_state_cb_handler,
new_state,
old_state,
TRUE);
}
static NMSupplicantConfig *
build_supplicant_config (NMDeviceEthernet *self)
{
......@@ -1224,20 +1102,33 @@ build_supplicant_config (NMDeviceEthernet *self)
return config;
}
static gboolean
supplicant_iface_state_cb_handler (gpointer user_data)
static void
supplicant_iface_state_cb (NMSupplicantInterface *iface,
guint32 new_state,
guint32 old_state,
gpointer user_data)
{
SupplicantStateTask *task = (SupplicantStateTask *) user_data;
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (task->self);
NMDevice *device = NM_DEVICE (task->self);
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (user_data);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
NMDevice *device = NM_DEVICE (self);
NMSupplicantConfig *config;
gboolean success = FALSE;
NMDeviceState devstate;
if (new_state == old_state)
return;
nm_log_info (LOGD_DEVICE | LOGD_ETHER,
"(%s): supplicant interface state: %s -> %s",
nm_device_get_iface (device),
nm_supplicant_interface_state_to_string (old_state),
nm_supplicant_interface_state_to_string (new_state));
if (task->new_state == NM_SUPPLICANT_INTERFACE_STATE_READY) {
NMSupplicantConfig *config;
const char *iface;
gboolean success = FALSE;
devstate = nm_device_get_state (device);
iface = nm_device_get_iface (device);
config = build_supplicant_config (task->self);
switch (new_state) {
case NM_SUPPLICANT_INTERFACE_STATE_READY:
config = build_supplicant_config (self);
if (config) {
success = nm_supplicant_interface_set_config (priv->supplicant.iface, config);
g_object_unref (config);
......@@ -1246,99 +1137,54 @@ supplicant_iface_state_cb_handler (gpointer user_data)
nm_log_err (LOGD_DEVICE | LOGD_ETHER,
"Activation (%s/wired): couldn't send security "
"configuration to the supplicant.",
iface);
nm_device_get_iface (device));
}
} else {
nm_log_warn (LOGD_DEVICE | LOGD_ETHER,
"Activation (%s/wired): couldn't build security configuration.",
iface);
nm_device_get_iface (device));
}
if (!success)
nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED);
} else if (task->new_state == NM_SUPPLICANT_INTERFACE_STATE_DOWN) {
NMDeviceState state = nm_device_get_state (device);
supplicant_interface_release (task->self);
if (nm_device_is_activating (device) || state == NM_DEVICE_STATE_ACTIVATED)
nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED);
}
finish_supplicant_task (task, FALSE);
return FALSE;
}
static void
supplicant_iface_state_cb (NMSupplicantInterface * iface,
guint32 new_state,
guint32 old_state,
gpointer user_data)
{
nm_log_info (LOGD_DEVICE | LOGD_ETHER,
"(%s): supplicant interface state: %s -> %s",
nm_device_get_iface (NM_DEVICE (user_data)),
nm_supplicant_interface_state_to_string (old_state),
nm_supplicant_interface_state_to_string (new_state));
schedule_state_handler (NM_DEVICE_ETHERNET (user_data),
supplicant_iface_state_cb_handler,
new_state,
old_state,
FALSE);
}
static gboolean
supplicant_iface_connection_state_cb_handler (gpointer user_data)
{
SupplicantStateTask *task = (SupplicantStateTask *) user_data;
NMDevice *dev = NM_DEVICE (task->self);
if (task->new_state == NM_SUPPLICANT_INTERFACE_CON_STATE_COMPLETED) {
remove_supplicant_interface_error_handler (task->self);
remove_supplicant_timeouts (task->self);
if (!success) {
nm_device_state_changed (device,
NM_DEVICE_STATE_FAILED,
NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED);
}
break;
case NM_SUPPLICANT_INTERFACE_STATE_COMPLETED:
remove_supplicant_interface_error_handler (self);
remove_supplicant_timeouts (self);
/* If this is the initial association during device activation,
* schedule the next activation stage.
*/
if (nm_device_get_state (dev) == NM_DEVICE_STATE_CONFIG) {
if (devstate == NM_DEVICE_STATE_CONFIG) {
nm_log_info (LOGD_DEVICE | LOGD_ETHER,
"Activation (%s/wired) Stage 2 of 5 (Device Configure) successful.",
nm_device_get_iface (dev));
nm_device_activate_schedule_stage3_ip_config_start (dev);
nm_device_get_iface (device));
nm_device_activate_schedule_stage3_ip_config_start (device);
}
} else if (task->new_state == NM_SUPPLICANT_INTERFACE_CON_STATE_DISCONNECTED) {
if (nm_device_get_state (dev) == NM_DEVICE_STATE_ACTIVATED || nm_device_is_activating (dev)) {
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (task->self);
break;
case NM_SUPPLICANT_INTERFACE_STATE_DISCONNECTED:
if ((devstate == NM_DEVICE_STATE_ACTIVATED) || nm_device_is_activating (device)) {
/* Start the link timeout so we allow some time for reauthentication */
if (!priv->supplicant_timeout_id)
priv->supplicant_timeout_id = g_timeout_add_seconds (15, link_timeout_cb, dev);
priv->supplicant_timeout_id = g_timeout_add_seconds (15, link_timeout_cb, device);
}
}
finish_supplicant_task (task, FALSE);
return FALSE;
}
static void
supplicant_iface_connection_state_cb (NMSupplicantInterface * iface,
guint32 new_state,
guint32 old_state,
gpointer user_data)
{
nm_log_info (LOGD_DEVICE | LOGD_ETHER,
"(%s) supplicant connection state: %s -> %s",
nm_device_get_iface (NM_DEVICE (user_data)),
nm_supplicant_interface_connection_state_to_string (old_state),
nm_supplicant_interface_connection_state_to_string (new_state));
break;
case NM_SUPPLICANT_INTERFACE_STATE_DOWN:
supplicant_interface_release (self);
remove_supplicant_timeouts (self);
schedule_state_handler (NM_DEVICE_ETHERNET (user_data),
supplicant_iface_connection_state_cb_handler,
new_state,
old_state,
FALSE);
if ((devstate == NM_DEVICE_STATE_ACTIVATED) || nm_device_is_activating (device)) {
nm_device_state_changed (device,
NM_DEVICE_STATE_FAILED,
NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED);
}
break;
default:
break;
}
}
static gboolean
......@@ -1456,38 +1302,26 @@ supplicant_interface_init (NMDeviceEthernet *self)
iface = nm_device_get_iface (NM_DEVICE (self));
/* Create supplicant interface */
priv->supplicant.iface = nm_supplicant_manager_get_iface (priv->supplicant.mgr, iface, FALSE);
priv->supplicant.iface = nm_supplicant_manager_iface_get (priv->supplicant.mgr, iface, FALSE);
if (!priv->supplicant.iface) {
nm_log_err (LOGD_DEVICE | LOGD_ETHER,
"Couldn't initialize supplicant interface for %s.",
iface);
supplicant_interface_release (self);
return FALSE;
}
/* Listen for it's state signals */
priv->supplicant.iface_state_id = g_signal_connect (priv->supplicant.iface,
"state",
G_CALLBACK (supplicant_iface_state_cb),
self);
"state",
G_CALLBACK (supplicant_iface_state_cb),
self);
/* Hook up error signal handler to capture association errors */
priv->supplicant.iface_error_id = g_signal_connect (priv->supplicant.iface,
"connection-error",
G_CALLBACK (supplicant_iface_connection_error_cb),
self);
priv->supplicant.iface_con_state_id = g_signal_connect (priv->supplicant.iface,
"connection-state",
G_CALLBACK (supplicant_iface_connection_state_cb),
self);
/* Listen for supplicant manager state changes */
priv->supplicant.mgr_state_id = g_signal_connect (priv->supplicant.mgr,
"state",
G_CALLBACK (supplicant_mgr_state_cb),
self);
"connection-error",
G_CALLBACK (supplicant_iface_connection_error_cb),
self);
/* Set up a timeout on the connection attempt to fail it after 25 seconds */
priv->supplicant.con_timeout_id = g_timeout_add_seconds (25, supplicant_connection_timeout_cb, self);
......@@ -2047,12 +1881,6 @@ dispose (GObject *object)
priv->disposed = TRUE;
/* Clean up all pending supplicant tasks */
while (priv->supplicant.iface_tasks)
finish_supplicant_task ((SupplicantStateTask *) priv->supplicant.iface_tasks->data, TRUE);
while (priv->supplicant.mgr_tasks)
finish_supplicant_task ((SupplicantStateTask *) priv->supplicant.mgr_tasks->data, TRUE);
if (priv->link_connected_id) {
g_signal_handler_disconnect (priv->monitor, priv->link_connected_id);
priv->link_connected_id = 0;
......
This diff is collapsed.
......@@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2006 - 2008 Red Hat, Inc.
* Copyright (C) 2006 - 2010 Red Hat, Inc.
* Copyright (C) 2007 - 2008 Novell, Inc.
*/
......@@ -26,47 +26,26 @@
#include <dbus/dbus.h>
#include "nm-supplicant-types.h"
G_BEGIN_DECLS
/*
* Supplicant interface states
* The states are linear, ie INIT -> READY -> DOWN and state may only be
* changed in one direction. If an interface reaches the DOWN state, it
* cannot be re-initialized; it must be torn down and a new one created.
*
* INIT: interface has been created, but cannot be used yet; it is waiting
* for pending requests of the supplicant to complete.
* READY: interface is ready for use
* DOWN: interface has been removed or has otherwise been made invalid; it
* must be torn down.
*
* Note: LAST is an invalid state and only used for boundary checking.
* A mix of wpa_supplicant interface states and internal states.
*/
enum {
NM_SUPPLICANT_INTERFACE_STATE_INIT = 0,
NM_SUPPLICANT_INTERFACE_STATE_STARTING,
NM_SUPPLICANT_INTERFACE_STATE_READY,
NM_SUPPLICANT_INTERFACE_STATE_DISCONNECTED,
NM_SUPPLICANT_INTERFACE_STATE_INACTIVE,
NM_SUPPLICANT_INTERFACE_STATE_SCANNING,
NM_SUPPLICANT_INTERFACE_STATE_ASSOCIATING,
NM_SUPPLICANT_INTERFACE_STATE_ASSOCIATED,
NM_SUPPLICANT_INTERFACE_STATE_4WAY_HANDSHAKE,
NM_SUPPLICANT_INTERFACE_STATE_GROUP_HANDSHAKE,
NM_SUPPLICANT_INTERFACE_STATE_COMPLETED,
NM_SUPPLICANT_INTERFACE_STATE_DOWN,
NM_SUPPLICANT_INTERFACE_STATE_LAST
};
/*
* Supplicant interface connection states
* The wpa_supplicant state for the connection.
*/
enum {
NM_SUPPLICANT_INTERFACE_CON_STATE_DISCONNECTED = 0,
NM_SUPPLICANT_INTERFACE_CON_STATE_INACTIVE,
NM_SUPPLICANT_INTERFACE_CON_STATE_SCANNING,
NM_SUPPLICANT_INTERFACE_CON_STATE_ASSOCIATING,
NM_SUPPLICANT_INTERFACE_CON_STATE_ASSOCIATED,
NM_SUPPLICANT_INTERFACE_CON_STATE_4WAY_HANDSHAKE,
NM_SUPPLICANT_INTERFACE_CON_STATE_GROUP_HANDSHAKE,
NM_SUPPLICANT_INTERFACE_CON_STATE_COMPLETED,
NM_SUPPLICANT_INTERFACE_CON_STATE_LAST
};
#define NM_TYPE_SUPPLICANT_INTERFACE (nm_supplicant_interface_get_type ())
#define NM_SUPPLICANT_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SUPPLICANT_INTERFACE, NMSupplicantInterface))
#define NM_SUPPLICANT_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SUPPLICANT_INTERFACE, NMSupplicantInterfaceClass))
......@@ -103,11 +82,6 @@ typedef struct {
void (*scan_results) (NMSupplicantInterface * iface,
guint num_bssids);
/* link state of the device's connection */
void (*connection_state) (NMSupplicantInterface * iface,
guint32 new_state,
guint32 old_state);
/* an error occurred during a connection request */
void (*connection_error) (NMSupplicantInterface * iface,
const char * name,
......@@ -119,7 +93,8 @@ GType nm_supplicant_interface_get_type (void);
NMSupplicantInterface * nm_supplicant_interface_new (NMSupplicantManager * smgr,
const char *ifname,
gboolean is_wireless);
gboolean is_wireless,
gboolean start_now);
gboolean nm_supplicant_interface_set_config (NMSupplicantInterface * iface,
NMSupplicantConfig * cfg);
......@@ -128,18 +103,16 @@ void nm_supplicant_interface_disconnect (NMSupplicantInterface * iface);
const char * nm_supplicant_interface_get_device (NMSupplicantInterface * iface);
const char *nm_supplicant_interface_get_object_path (NMSupplicantInterface * iface);
gboolean nm_supplicant_interface_request_scan (NMSupplicantInterface * self);
guint32 nm_supplicant_interface_get_state (NMSupplicantInterface * self);
guint32 nm_supplicant_interface_get_connection_state (NMSupplicantInterface * self);
const char *nm_supplicant_interface_state_to_string (guint32 state);
const char *nm_supplicant_interface_connection_state_to_string (guint32 state);
gboolean nm_supplicant_interface_get_scanning (NMSupplicantInterface *self);
G_END_DECLS
const char *nm_supplicant_interface_get_ifname (NMSupplicantInterface *self);
#endif /* NM_SUPPLICANT_INTERFACE_H */
......@@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2006 - 2008 Red Hat, Inc.
* Copyright (C) 2006 - 2010 Red Hat, Inc.
* Copyright (C) 2007 - 2008 Novell, Inc.
*/
......@@ -26,19 +26,7 @@
#include "nm-supplicant-manager.h"
#include "nm-supplicant-interface.h"
#include "nm-dbus-manager.h"
#include "nm-marshal.h"
#include "nm-logging.h"
#include "nm-glib-compat.h"
#define SUPPLICANT_POKE_INTERVAL 120
typedef struct {
NMDBusManager * dbus_mgr;
guint32 state;
GSList * ifaces;
gboolean dispose_has_run;
guint poke_id;
} NMSupplicantManagerPrivate;
#define NM_SUPPLICANT_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
NM_TYPE_SUPPLICANT_MANAGER, \
......@@ -46,298 +34,283 @@ typedef struct {
G_DEFINE_TYPE (NMSupplicantManager, nm_supplicant_manager, G_TYPE_OBJECT)
/* Properties */
enum {
PROP_0 = 0,
PROP_AVAILABLE,
LAST_PROP
};
static void nm_supplicant_manager_name_owner_changed (NMDBusManager *dbus_mgr,
const char *name,
const char *old,
const char *new,
gpointer user_data);
typedef struct {
NMDBusManager * dbus_mgr;
guint name_owner_id;
DBusGProxy * proxy;
gboolean running;
GHashTable * ifaces;
guint die_count_reset_id;
guint die_count;
gboolean disposed;
} NMSupplicantManagerPrivate;
static void nm_supplicant_manager_set_state (NMSupplicantManager * self,
guint32 new_state);
/********************************************************************/
static gboolean nm_supplicant_manager_startup (NMSupplicantManager * self);
static inline gboolean
die_count_exceeded (guint32 count)
{
return count > 2;
}
NMSupplicantInterface *
nm_supplicant_manager_iface_get (NMSupplicantManager * self,
const char *ifname,
gboolean is_wireless)
{
NMSupplicantManagerPrivate *priv;
NMSupplicantInterface *iface = NULL;
gboolean start_now;
/* Signals */
enum {
STATE, /* change in the manager's state */
LAST_SIGNAL
};
static guint nm_supplicant_manager_signals[LAST_SIGNAL] = { 0 };
g_return_val_if_fail (NM_IS_SUPPLICANT_MANAGER (self), NULL);
g_return_val_if_fail (ifname != NULL, NULL);
priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self);
NMSupplicantManager *
nm_supplicant_manager_get (void)
{
static NMSupplicantManager * singleton = NULL;
iface = g_hash_table_lookup (priv->ifaces, ifname);
if (!iface) {
/* If we're making the supplicant take a time out for a bit, don't
* let the supplicant interface start immediately, just let it hang
* around in INIT state until we're ready to talk to the supplicant
* again.
*/
start_now = !die_count_exceeded (priv->die_count);
if (!singleton) {
singleton = NM_SUPPLICANT_MANAGER (g_object_new (NM_TYPE_SUPPLICANT_MANAGER, NULL));
nm_log_dbg (LOGD_SUPPLICANT, "(%s): creating new supplicant interface", ifname);
iface = nm_supplicant_interface_new (self, ifname, is_wireless, start_now);
if (iface)