diff options
| author | Michael Biebl <biebl@debian.org> | 2015-01-22 00:29:39 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2015-01-22 00:29:39 +0100 |
| commit | 2c032d8f1c6292c1338a615e6ec40252889ba85c (patch) | |
| tree | 1f77182220b2b0264288ba4a476ab47e5bc48716 /src/devices/wifi/nm-device-wifi.c | |
| parent | 33491bc4279481db8ae47213e34a6d695a0e8830 (diff) | |
Imported Upstream version 1.0.0 upstream/1.0.0
Diffstat (limited to 'src/devices/wifi/nm-device-wifi.c')
| -rw-r--r-- | src/devices/wifi/nm-device-wifi.c | 931 |
1 files changed, 434 insertions, 497 deletions
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 95173cf4..dd7754b3 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -19,12 +19,13 @@ * Copyright (C) 2006 - 2008 Novell, Inc. */ +#include "config.h" + #include <glib.h> #include <glib/gi18n.h> #include <dbus/dbus.h> #include <netinet/in.h> #include <string.h> -#include <net/ethernet.h> #include <sys/stat.h> #include <sys/wait.h> #include <signal.h> @@ -32,7 +33,6 @@ #include <linux/sockios.h> #include <linux/ethtool.h> #include <sys/ioctl.h> -#include <netinet/ether.h> #include <errno.h> #include "nm-glib-compat.h" @@ -52,9 +52,10 @@ #include "nm-setting-wireless-security.h" #include "nm-setting-8021x.h" #include "nm-setting-ip4-config.h" +#include "nm-ip4-config.h" #include "nm-setting-ip6-config.h" #include "nm-platform.h" -#include "nm-manager-auth.h" +#include "nm-auth-utils.h" #include "nm-settings-connection.h" #include "nm-enum-types.h" #include "nm-dbus-glib-types.h" @@ -76,6 +77,8 @@ static void impl_device_request_scan (NMDeviceWifi *device, #include "nm-device-wifi-glue.h" +#include "nm-device-logging.h" +_LOG_DECLARE_SELF(NMDeviceWifi); /* All of these are in seconds */ #define SCAN_INTERVAL_MIN 3 @@ -115,8 +118,8 @@ static guint signals[LAST_SIGNAL] = { 0 }; struct _NMDeviceWifiPrivate { gboolean disposed; - guint8 perm_hw_addr[ETH_ALEN]; /* Permanent MAC address */ - guint8 initial_hw_addr[ETH_ALEN]; /* Initial MAC address (as seen when NM starts) */ + char * perm_hw_addr; /* Permanent MAC address */ + char * initial_hw_addr; /* Initial MAC address (as seen when NM starts) */ gint8 invalid_strength_counter; @@ -192,19 +195,6 @@ static void remove_supplicant_interface_error_handler (NMDeviceWifi *self); /*****************************************************************/ -#define NM_WIFI_ERROR (nm_wifi_error_quark ()) - -static GQuark -nm_wifi_error_quark (void) -{ - static GQuark quark = 0; - if (!quark) - quark = g_quark_from_static_string ("nm-wifi-error"); - return quark; -} - -/*****************************************************************/ - static GObject* constructor (GType type, guint n_construct_params, @@ -223,22 +213,15 @@ constructor (GType type, self = NM_DEVICE_WIFI (object); priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - nm_log_dbg (LOGD_HW | LOGD_WIFI, "(%s): kernel ifindex %d", - nm_device_get_iface (NM_DEVICE (self)), - nm_device_get_ifindex (NM_DEVICE (self))); - if (!nm_platform_wifi_get_capabilities (nm_device_get_ifindex (NM_DEVICE (self)), &priv->capabilities)) { - nm_log_warn (LOGD_HW | LOGD_WIFI, "(%s): failed to initialize WiFi driver", - nm_device_get_iface (NM_DEVICE (self))); + _LOGW (LOGD_HW | LOGD_WIFI, "failed to initialize WiFi driver"); g_object_unref (object); return NULL; } - if (priv->capabilities & NM_WIFI_DEVICE_CAP_AP) { - nm_log_info (LOGD_HW | LOGD_WIFI, "(%s): driver supports Access Point (AP) mode", - nm_device_get_iface (NM_DEVICE (self))); - } + if (priv->capabilities & NM_WIFI_DEVICE_CAP_AP) + _LOGI (LOGD_HW | LOGD_WIFI, "driver supports Access Point (AP) mode"); /* Connect to the supplicant manager */ priv->sup_mgr = nm_supplicant_manager_get (); @@ -260,13 +243,12 @@ supplicant_interface_acquire (NMDeviceWifi *self) nm_device_get_iface (NM_DEVICE (self)), TRUE); if (priv->sup_iface == NULL) { - nm_log_err (LOGD_WIFI, "Couldn't initialize supplicant interface for %s.", - nm_device_get_iface (NM_DEVICE (self))); + _LOGE (LOGD_WIFI, "Couldn't initialize supplicant interface"); return FALSE; } if (nm_supplicant_interface_get_state (priv->sup_iface) < NM_SUPPLICANT_INTERFACE_STATE_READY) - nm_device_add_pending_action (NM_DEVICE (self), "waiting for supplicant", TRUE); + nm_device_add_pending_action (NM_DEVICE (self), "waiting for supplicant", FALSE); g_signal_connect (priv->sup_iface, NM_SUPPLICANT_INTERFACE_STATE, @@ -309,9 +291,8 @@ supplicant_interface_release (NMDeviceWifi *self) /* Reset the scan interval to be pretty frequent when disconnected */ priv->scan_interval = SCAN_INTERVAL_MIN + SCAN_INTERVAL_STEP; - nm_log_dbg (LOGD_WIFI_SCAN, "(%s): reset scanning interval to %d seconds", - nm_device_get_iface (NM_DEVICE (self)), - priv->scan_interval); + _LOGD (LOGD_WIFI_SCAN, "reset scanning interval to %d seconds", + priv->scan_interval); if (priv->scanlist_cull_id) { g_source_remove (priv->scanlist_cull_id); @@ -370,9 +351,8 @@ find_active_ap (NMDeviceWifi *self, gboolean match_hidden) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - const char *iface = nm_device_get_iface (NM_DEVICE (self)); int ifindex = nm_device_get_ifindex (NM_DEVICE (self)); - struct ether_addr bssid; + guint8 bssid[ETH_ALEN]; GByteArray *ssid; GSList *iter; int i = 0; @@ -382,22 +362,18 @@ find_active_ap (NMDeviceWifi *self, NM80211Mode devmode; guint32 devfreq; - nm_platform_wifi_get_bssid (ifindex, &bssid); - nm_log_dbg (LOGD_WIFI, "(%s): active BSSID: %02x:%02x:%02x:%02x:%02x:%02x", - iface, - bssid.ether_addr_octet[0], bssid.ether_addr_octet[1], - bssid.ether_addr_octet[2], bssid.ether_addr_octet[3], - bssid.ether_addr_octet[4], bssid.ether_addr_octet[5]); + nm_platform_wifi_get_bssid (ifindex, bssid); + _LOGD (LOGD_WIFI, "active BSSID: %02x:%02x:%02x:%02x:%02x:%02x", + bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]); - if (!nm_ethernet_address_is_valid (&bssid)) + if (!nm_ethernet_address_is_valid (bssid, ETH_ALEN)) return NULL; ssid = nm_platform_wifi_get_ssid (ifindex); - nm_log_dbg (LOGD_WIFI, "(%s): active SSID: %s%s%s", - iface, - ssid ? "'" : "", - ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)", - ssid ? "'" : ""); + _LOGD (LOGD_WIFI, "active SSID: %s%s%s", + ssid ? "'" : "", + ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)", + ssid ? "'" : ""); devmode = nm_platform_wifi_get_mode (ifindex); devfreq = nm_platform_wifi_get_frequency (ifindex); @@ -407,50 +383,54 @@ find_active_ap (NMDeviceWifi *self, * and therefore it won't get matched the first time around. */ while (i++ < (match_hidden ? 2 : 1)) { - nm_log_dbg (LOGD_WIFI, " Pass #%d %s", i, i > 1 ? "(ignoring SSID)" : ""); + _LOGD (LOGD_WIFI, " Pass #%d %s", i, i > 1 ? "(ignoring SSID)" : ""); /* Find this SSID + BSSID in the device's AP list */ for (iter = priv->ap_list; iter; iter = g_slist_next (iter)) { NMAccessPoint *ap = NM_AP (iter->data); - const struct ether_addr *ap_bssid = nm_ap_get_address (ap); + const char *ap_bssid = nm_ap_get_address (ap); const GByteArray *ap_ssid = nm_ap_get_ssid (ap); NM80211Mode apmode; guint32 apfreq; - nm_log_dbg (LOGD_WIFI, " AP: %s%s%s %02x:%02x:%02x:%02x:%02x:%02x", - ap_ssid ? "'" : "", - ap_ssid ? nm_utils_escape_ssid (ap_ssid->data, ap_ssid->len) : "(none)", - ap_ssid ? "'" : "", - ap_bssid->ether_addr_octet[0], ap_bssid->ether_addr_octet[1], - ap_bssid->ether_addr_octet[2], ap_bssid->ether_addr_octet[3], - ap_bssid->ether_addr_octet[4], ap_bssid->ether_addr_octet[5]); + _LOGD (LOGD_WIFI, " AP: %s%s%s %s", + ap_ssid ? "'" : "", + ap_ssid ? nm_utils_escape_ssid (ap_ssid->data, ap_ssid->len) : "(none)", + ap_ssid ? "'" : "", + str_if_set (ap_bssid, "(none)")); if (ap == ignore_ap) { - nm_log_dbg (LOGD_WIFI, " ignored"); + _LOGD (LOGD_WIFI, " ignored"); continue; } - if (memcmp (bssid.ether_addr_octet, ap_bssid->ether_addr_octet, ETH_ALEN)) { - nm_log_dbg (LOGD_WIFI, " BSSID mismatch"); + if (!nm_utils_hwaddr_matches (bssid, ETH_ALEN, ap_bssid, -1)) { + _LOGD (LOGD_WIFI, " BSSID mismatch"); continue; } - if ((i == 0) && !nm_utils_same_ssid (ssid, ap_ssid, TRUE)) { - nm_log_dbg (LOGD_WIFI, " SSID mismatch"); - continue; + if (i == 0) { + if ( (ssid && !ap_ssid) + || (ap_ssid && !ssid) + || (ssid && ap_ssid && !nm_utils_same_ssid (ssid->data, ssid->len, + ap_ssid->data, ap_ssid->len, + TRUE))) { + _LOGD (LOGD_WIFI, " SSID mismatch"); + continue; + } } apmode = nm_ap_get_mode (ap); if (devmode != apmode) { - nm_log_dbg (LOGD_WIFI, " mode mismatch (device %d, ap %d)", - devmode, apmode); + _LOGD (LOGD_WIFI, " mode mismatch (device %d, ap %d)", + devmode, apmode); continue; } apfreq = nm_ap_get_freq (ap); if (devfreq != apfreq) { - nm_log_dbg (LOGD_WIFI, " frequency mismatch (device %u, ap %u)", - devfreq, apfreq); + _LOGD (LOGD_WIFI, " frequency mismatch (device %u, ap %u)", + devfreq, apfreq); if (match_nofreq == NULL) match_nofreq = ap; @@ -463,7 +443,7 @@ find_active_ap (NMDeviceWifi *self, } // FIXME: handle security settings here too - nm_log_dbg (LOGD_WIFI, " matched"); + _LOGD (LOGD_WIFI, " matched"); active_ap = ap; goto done; } @@ -482,22 +462,19 @@ find_active_ap (NMDeviceWifi *self, * we can't match the AP based on frequency at all, just give up. */ if (match_nofreq && ((found_a_band != found_bg_band) || (devfreq == 0))) { - const struct ether_addr *ap_bssid = nm_ap_get_address (match_nofreq); const GByteArray *ap_ssid = nm_ap_get_ssid (match_nofreq); - nm_log_dbg (LOGD_WIFI, " matched %s%s%s %02x:%02x:%02x:%02x:%02x:%02x", - ap_ssid ? "'" : "", - ap_ssid ? nm_utils_escape_ssid (ap_ssid->data, ap_ssid->len) : "(none)", - ap_ssid ? "'" : "", - ap_bssid->ether_addr_octet[0], ap_bssid->ether_addr_octet[1], - ap_bssid->ether_addr_octet[2], ap_bssid->ether_addr_octet[3], - ap_bssid->ether_addr_octet[4], ap_bssid->ether_addr_octet[5]); + _LOGD (LOGD_WIFI, " matched %s%s%s %s", + ap_ssid ? "'" : "", + ap_ssid ? nm_utils_escape_ssid (ap_ssid->data, ap_ssid->len) : "(none)", + ap_ssid ? "'" : "", + str_if_set (nm_ap_get_address (match_nofreq), "(none)")); active_ap = match_nofreq; goto done; } - nm_log_dbg (LOGD_WIFI, " No matching AP found."); + _LOGD (LOGD_WIFI, " No matching AP found."); done: if (ssid) @@ -612,15 +589,17 @@ periodic_update (NMDeviceWifi *self, NMAccessPoint *ignore_ap) * current AP with it, if the current AP is adhoc. */ if (priv->current_ap && (nm_ap_get_mode (priv->current_ap) == NM_802_11_MODE_ADHOC)) { - struct ether_addr bssid = { {0x0, 0x0, 0x0, 0x0, 0x0, 0x0} }; + guint8 bssid[ETH_ALEN] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; - nm_platform_wifi_get_bssid (ifindex, &bssid); + nm_platform_wifi_get_bssid (ifindex, bssid); /* 0x02 means "locally administered" and should be OR-ed into * the first byte of IBSS BSSIDs. */ - if ( (bssid.ether_addr_octet[0] & 0x02) - && nm_ethernet_address_is_valid (&bssid)) - nm_ap_set_address (priv->current_ap, &bssid); + if ((bssid[0] & 0x02) && nm_ethernet_address_is_valid (bssid, ETH_ALEN)) { + char *bssid_str = nm_utils_hwaddr_ntoa (bssid, ETH_ALEN); + nm_ap_set_address (priv->current_ap, bssid_str); + g_free (bssid_str); + } } new_ap = find_active_ap (self, ignore_ap, FALSE); @@ -636,32 +615,26 @@ periodic_update (NMDeviceWifi *self, NMAccessPoint *ignore_ap) } if (new_ap != priv->current_ap) { - const struct ether_addr *new_bssid = NULL; + const char *new_bssid = NULL; const GByteArray *new_ssid = NULL; - const struct ether_addr *old_bssid = NULL; + const char *old_bssid = NULL; const GByteArray *old_ssid = NULL; - char *old_addr = NULL, *new_addr = NULL; if (new_ap) { new_bssid = nm_ap_get_address (new_ap); - new_addr = nm_utils_hwaddr_ntoa (new_bssid, ARPHRD_ETHER); new_ssid = nm_ap_get_ssid (new_ap); } if (priv->current_ap) { old_bssid = nm_ap_get_address (priv->current_ap); - old_addr = nm_utils_hwaddr_ntoa (old_bssid, ARPHRD_ETHER); old_ssid = nm_ap_get_ssid (priv->current_ap); } - nm_log_info (LOGD_WIFI, "(%s): roamed from BSSID %s (%s) to %s (%s)", - nm_device_get_iface (NM_DEVICE (self)), - old_addr ? old_addr : "(none)", - old_ssid ? nm_utils_escape_ssid (old_ssid->data, old_ssid->len) : "(none)", - new_addr ? new_addr : "(none)", - new_ssid ? nm_utils_escape_ssid (new_ssid->data, new_ssid->len) : "(none)"); - g_free (old_addr); - g_free (new_addr); + _LOGI (LOGD_WIFI, "roamed from BSSID %s (%s) to %s (%s)", + old_bssid ? old_bssid : "(none)", + old_ssid ? nm_utils_escape_ssid (old_ssid->data, old_ssid->len) : "(none)", + new_bssid ? new_bssid : "(none)", + new_ssid ? nm_utils_escape_ssid (new_ssid->data, new_ssid->len) : "(none)"); set_current_ap (self, new_ap, TRUE, FALSE); } @@ -734,15 +707,15 @@ remove_all_aps (NMDeviceWifi *self) } static void -deactivate (NMDevice *dev) +deactivate (NMDevice *device) { - NMDeviceWifi *self = NM_DEVICE_WIFI (dev); + NMDeviceWifi *self = NM_DEVICE_WIFI (device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - int ifindex = nm_device_get_ifindex (dev); + int ifindex = nm_device_get_ifindex (device); NMConnection *connection; NM80211Mode old_mode = priv->mode; - connection = nm_device_get_connection (dev); + connection = nm_device_get_connection (device); if (connection) { /* Clear wireless secrets tries when deactivating */ g_object_set_data (G_OBJECT (connection), WIRELESS_SECRETS_TRIES, NULL); @@ -768,7 +741,8 @@ deactivate (NMDevice *dev) nm_platform_wifi_indicate_addressing_running (ifindex, FALSE); /* Reset MAC address back to initial address */ - nm_device_set_hw_addr (dev, priv->initial_hw_addr, "reset", LOGD_WIFI); + if (priv->initial_hw_addr) + nm_device_set_hw_addr (device, priv->initial_hw_addr, "reset", LOGD_WIFI); /* Ensure we're in infrastructure mode after deactivation; some devices * (usually older ones) don't scan well in adhoc mode. @@ -828,8 +802,9 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); NMSettingConnection *s_con; NMSettingWireless *s_wireless; - const GByteArray *mac; - const GSList *mac_blacklist, *mac_blacklist_iter; + const char *mac; + const char * const *mac_blacklist; + int i; const char *mode; if (!NM_DEVICE_CLASS (nm_device_wifi_parent_class)->check_connection_compatible (device, connection)) @@ -846,21 +821,18 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) return FALSE; mac = nm_setting_wireless_get_mac_address (s_wireless); - if (mac && memcmp (mac->data, &priv->perm_hw_addr, ETH_ALEN)) + if (mac && !nm_utils_hwaddr_matches (mac, -1, priv->perm_hw_addr, -1)) return FALSE; /* Check for MAC address blacklist */ mac_blacklist = nm_setting_wireless_get_mac_address_blacklist (s_wireless); - for (mac_blacklist_iter = mac_blacklist; mac_blacklist_iter; - mac_blacklist_iter = g_slist_next (mac_blacklist_iter)) { - struct ether_addr addr; - - if (!ether_aton_r (mac_blacklist_iter->data, &addr)) { + for (i = 0; mac_blacklist[i]; i++) { + if (!nm_utils_hwaddr_valid (mac_blacklist[i], ETH_ALEN)) { g_warn_if_reached (); - continue; + return FALSE; } - if (memcmp (&addr, &priv->perm_hw_addr, ETH_ALEN) == 0) + if (nm_utils_hwaddr_matches (mac_blacklist[i], -1, priv->perm_hw_addr, -1)) return FALSE; } @@ -998,10 +970,12 @@ complete_connection (NMDevice *device, NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; - const GByteArray *setting_mac; - char *format, *str_ssid = NULL; + const char *setting_mac; + char *str_ssid = NULL; NMAccessPoint *ap = NULL; const GByteArray *ssid = NULL; + GByteArray *tmp_ssid = NULL; + GBytes *setting_ssid = NULL; GSList *iter; gboolean hidden = FALSE; @@ -1013,17 +987,17 @@ complete_connection (NMDevice *device, /* If not given a specific object, we need at minimum an SSID */ if (!s_wifi) { g_set_error_literal (error, - NM_WIFI_ERROR, - NM_WIFI_ERROR_CONNECTION_INVALID, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, "A 'wireless' setting is required if no AP path was given."); return FALSE; } - ssid = nm_setting_wireless_get_ssid (s_wifi); - if (!ssid || !ssid->len) { + setting_ssid = nm_setting_wireless_get_ssid (s_wifi); + if (!setting_ssid || g_bytes_get_size (setting_ssid) == 0) { g_set_error_literal (error, - NM_WIFI_ERROR, - NM_WIFI_ERROR_CONNECTION_INVALID, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, "A 'wireless' setting with a valid SSID is required if no AP path was given."); return FALSE; } @@ -1041,17 +1015,7 @@ complete_connection (NMDevice *device, * if the network isn't broadcasting the SSID for example. */ if (!ap) { - GSList *settings = NULL; - gboolean valid; - - settings = g_slist_prepend (settings, s_wifi); - if (s_wsec) - settings = g_slist_prepend (settings, s_wsec); - if (s_8021x) - settings = g_slist_prepend (settings, s_8021x); - valid = nm_setting_verify (NM_SETTING (s_wifi), settings, error); - g_slist_free (settings); - if (!valid) + if (!nm_setting_verify (NM_SETTING (s_wifi), connection, error)) return FALSE; hidden = TRUE; @@ -1060,8 +1024,8 @@ complete_connection (NMDevice *device, ap = get_ap_by_path (self, specific_object); if (!ap) { g_set_error (error, - NM_WIFI_ERROR, - NM_WIFI_ERROR_ACCESS_POINT_NOT_FOUND, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_SPECIFIC_OBJECT_NOT_FOUND, "The access point %s was not in the scan list.", specific_object); return FALSE; @@ -1074,37 +1038,48 @@ complete_connection (NMDevice *device, nm_connection_add_setting (connection, NM_SETTING (s_wifi)); } - if (ap) { + if (ap) ssid = nm_ap_get_ssid (ap); - - if (ssid == NULL) { - /* The AP must be hidden. Connecting to a WiFi AP requires the SSID - * as part of the initial handshake, so check the connection details - * for the SSID. The AP object will still be used for encryption - * settings and such. - */ - ssid = nm_setting_wireless_get_ssid (s_wifi); + if (ssid == NULL) { + /* The AP must be hidden. Connecting to a WiFi AP requires the SSID + * as part of the initial handshake, so check the connection details + * for the SSID. The AP object will still be used for encryption + * settings and such. + */ + setting_ssid = nm_setting_wireless_get_ssid (s_wifi); + if (setting_ssid) { + ssid = tmp_ssid = g_byte_array_new (); + g_byte_array_append (tmp_ssid, + g_bytes_get_data (setting_ssid, NULL), + g_bytes_get_size (setting_ssid)); } + } - if (ssid == NULL) { - /* If there's no SSID on the AP itself, and no SSID in the - * connection data, then we cannot connect at all. Return an error. - */ - g_set_error_literal (error, - NM_WIFI_ERROR, - NM_WIFI_ERROR_CONNECTION_INVALID, - "A 'wireless' setting with a valid SSID is required for hidden access points."); - return FALSE; - } + if (ssid == NULL) { + /* If there's no SSID on the AP itself, and no SSID in the + * connection data, then we cannot connect at all. Return an error. + */ + g_set_error_literal (error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + ap + ? "A 'wireless' setting with a valid SSID is required for hidden access points." + : "Cannot create 'wireless' setting due to missing SSID."); + return FALSE; + } + if (ap) { /* If the SSID is a well-known SSID, lock the connection to the AP's * specific BSSID so NM doesn't autoconnect to some random wifi net. */ if (!nm_ap_complete_connection (ap, connection, is_manf_default_ssid (ssid), - error)) + error)) { + if (tmp_ssid) + g_byte_array_unref (tmp_ssid); return FALSE; + } } /* The kernel doesn't support Ad-Hoc WPA connections well at this time, @@ -1113,24 +1088,27 @@ complete_connection (NMDevice *device, */ if (is_adhoc_wpa (connection)) { g_set_error_literal (error, - NM_SETTING_WIRELESS_ERROR, - NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY, - "WPA Ad-Hoc disabled due to kernel bugs"); + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_SETTING, + _("WPA Ad-Hoc disabled due to kernel bugs")); + g_prefix_error (error, "%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); + if (tmp_ssid) + g_byte_array_unref (tmp_ssid); return FALSE; } - g_assert (ssid); - str_ssid = nm_utils_ssid_to_utf8 (ssid); - format = g_strdup_printf ("%s %%d", str_ssid); + str_ssid = nm_utils_ssid_to_utf8 (ssid->data, ssid->len); nm_utils_complete_generic (connection, NM_SETTING_WIRELESS_SETTING_NAME, existing_connections, - format, str_ssid, + str_ssid, + NULL, TRUE); g_free (str_ssid); - g_free (format); + if (tmp_ssid) + g_byte_array_unref (tmp_ssid); if (hidden) g_object_set (s_wifi, NM_SETTING_WIRELESS_HIDDEN, TRUE, NULL); @@ -1138,26 +1116,26 @@ complete_connection (NMDevice *device, setting_mac = nm_setting_wireless_get_mac_address (s_wifi); if (setting_mac) { /* Make sure the setting MAC (if any) matches the device's permanent MAC */ - if (memcmp (setting_mac->data, priv->perm_hw_addr, ETH_ALEN)) { - g_set_error (error, - NM_SETTING_WIRELESS_ERROR, - NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_MAC_ADDRESS); + if (!nm_utils_hwaddr_matches (setting_mac, -1, priv->perm_hw_addr, -1)) { + g_set_error_literal (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("connection does not match device")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MAC_ADDRESS); return FALSE; } } else { - GByteArray *mac; - const guint8 null_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 }; + guint8 perm_hw_addr[ETH_ALEN]; /* Lock the connection to this device by default if it uses a * permanent MAC address (ie not a 'locally administered' one) */ - if ( !(priv->perm_hw_addr[0] & 0x02) - && memcmp (priv->perm_hw_addr, null_mac, ETH_ALEN)) { - mac = g_byte_array_sized_new (ETH_ALEN); - g_byte_array_append (mac, priv->perm_hw_addr, ETH_ALEN); - g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_MAC_ADDRESS, mac, NULL); - g_byte_array_free (mac, TRUE); + nm_utils_hwaddr_aton (priv->perm_hw_addr, perm_hw_addr, ETH_ALEN); + if ( !(perm_hw_addr[0] & 0x02) + && !nm_utils_hwaddr_matches (perm_hw_addr, ETH_ALEN, NULL, ETH_ALEN)) { + g_object_set (G_OBJECT (s_wifi), + NM_SETTING_WIRELESS_MAC_ADDRESS, priv->perm_hw_addr, + NULL); } } @@ -1165,31 +1143,26 @@ complete_connection (NMDevice *device, } static gboolean -is_available (NMDevice *dev) +is_available (NMDevice *device) { - NMDeviceWifi *self = NM_DEVICE_WIFI (dev); + NMDeviceWifi *self = NM_DEVICE_WIFI (device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - NMSupplicantInterface *sup_iface; guint32 state; if (!priv->enabled) { - nm_log_dbg (LOGD_WIFI, "(%s): not available because not enabled", - nm_device_get_iface (dev)); + _LOGD (LOGD_WIFI, "not available because not enabled"); return FALSE; } - sup_iface = priv->sup_iface; - if (!sup_iface) { - nm_log_dbg (LOGD_WIFI, "(%s): not available because supplicant not running", - nm_device_get_iface (dev)); + if (!priv->sup_iface) { + _LOGD (LOGD_WIFI, "not available because supplicant not running"); return FALSE; } - state = nm_supplicant_interface_get_state (sup_iface); + state = nm_supplicant_interface_get_state (priv->sup_iface); if ( state < NM_SUPPLICANT_INTERFACE_STATE_READY || state > NM_SUPPLICANT_INTERFACE_STATE_COMPLETED) { - nm_log_dbg (LOGD_WIFI, "(%s): not available because supplicant interface not ready", - nm_device_get_iface (dev)); + _LOGD (LOGD_WIFI, "not available because supplicant interface not ready"); return FALSE; } @@ -1197,17 +1170,17 @@ is_available (NMDevice *dev) } static gboolean -can_auto_connect (NMDevice *dev, +can_auto_connect (NMDevice *device, NMConnection *connection, char **specific_object) { - NMDeviceWifi *self = NM_DEVICE_WIFI (dev); + NMDeviceWifi *self = NM_DEVICE_WIFI (device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); GSList *ap_iter; const char *method = NULL; guint64 timestamp = 0; - if (!NM_DEVICE_CLASS (nm_device_wifi_parent_class)->can_auto_connect (dev, connection, specific_object)) + if (!NM_DEVICE_CLASS (nm_device_wifi_parent_class)->can_auto_connect (device, connection, specific_object)) return FALSE; /* Don't autoconnect to networks that have been tried at least once @@ -1246,12 +1219,12 @@ ap_list_dump (NMDeviceWifi *self) g_return_if_fail (NM_IS_DEVICE_WIFI (self)); - nm_log_dbg (LOGD_WIFI_SCAN, "Current AP list:"); + _LOGD (LOGD_WIFI_SCAN, "Current AP list:"); for (elt = priv->ap_list; elt; elt = g_slist_next (elt), i++) { NMAccessPoint * ap = NM_AP (elt->data); nm_ap_dump (ap, "List AP: "); } - nm_log_dbg (LOGD_WIFI_SCAN, "Current AP list: done"); + _LOGD (LOGD_WIFI_SCAN, "Current AP list: done"); } static gboolean @@ -1301,8 +1274,8 @@ request_scan_cb (NMDevice *device, } if (!check_scanning_allowed (self)) { - local = g_error_new_literal (NM_WIFI_ERROR, - NM_WIFI_ERROR_SCAN_NOT_ALLOWED, + local = g_error_new_literal (NM_DEVICE_ERROR, + NM_DEVICE_ERROR_NOT_ALLOWED, "Scanning not allowed at this time"); dbus_g_method_return_error (context, local); g_error_free (local); @@ -1328,23 +1301,23 @@ impl_device_request_scan (NMDeviceWifi *self, || !priv->sup_iface || nm_device_get_state (device) < NM_DEVICE_STATE_DISCONNECTED || nm_device_is_activating (device)) { - error = g_error_new_literal (NM_WIFI_ERROR, - NM_WIFI_ERROR_SCAN_NOT_ALLOWED, + error = g_error_new_literal (NM_DEVICE_ERROR, + NM_DEVICE_ERROR_NOT_ALLOWED, "Scanning not allowed while unavailable or activating"); goto error; } if (nm_supplicant_interface_get_scanning (priv->sup_iface)) { - error = g_error_new_literal (NM_WIFI_ERROR, - NM_WIFI_ERROR_SCAN_NOT_ALLOWED, + error = g_error_new_literal (NM_DEVICE_ERROR, + NM_DEVICE_ERROR_NOT_ALLOWED, "Scanning not allowed while already scanning"); goto error; } last_scan = nm_supplicant_interface_get_last_scan_time (priv->sup_iface); if (last_scan && (nm_utils_get_monotonic_timestamp_s () - last_scan) < 10) { - error = g_error_new_literal (NM_WIFI_ERROR, - NM_WIFI_ERROR_SCAN_NOT_ALLOWED, + error = g_error_new_literal (NM_DEVICE_ERROR, + NM_DEVICE_ERROR_NOT_ALLOWED, "Scanning not allowed immediately following previous scan"); goto error; } @@ -1413,7 +1386,6 @@ scanning_allowed (NMDeviceWifi *self) if (connection) { NMSettingWireless *s_wifi; const char *ip4_method = NULL; - const GByteArray *bssid; /* Don't scan when a shared connection is active; it makes drivers mad */ ip4_method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG); @@ -1427,8 +1399,7 @@ scanning_allowed (NMDeviceWifi *self) */ s_wifi = nm_connection_get_setting_wireless (connection); g_assert (s_wifi); - bssid = nm_setting_wireless_get_bssid (s_wifi); - if (bssid && bssid->len == ETH_ALEN) + if (nm_setting_wireless_get_bssid (s_wifi)) return FALSE; } @@ -1500,20 +1471,25 @@ build_hidden_probe_list (NMDeviceWifi *self) hidden_filter_func, NULL); if (connections && connections->data) { - ssids = g_ptr_array_sized_new (max_scan_ssids - 1); - g_ptr_array_add (ssids, nullssid); /* Add wildcard SSID */ + ssids = g_ptr_array_new_full (max_scan_ssids - 1, (GDestroyNotify) g_byte_array_unref); + g_ptr_array_add (ssids, g_byte_array_ref (nullssid)); /* Add wildcard SSID */ } for (iter = connections; iter; iter = g_slist_next (iter)) { NMConnection *connection = iter->data; NMSettingWireless *s_wifi; - const GByteArray *ssid; + GBytes *ssid; + GByteArray *ssid_array; s_wifi = (NMSettingWireless *) nm_connection_get_setting_wireless (connection); g_assert (s_wifi); ssid = nm_setting_wireless_get_ssid (s_wifi); g_assert (ssid); - g_ptr_array_add (ssids, (gpointer) ssid); + ssid_array = g_byte_array_new (); + g_byte_array_append (ssid_array, + g_bytes_get_data (ssid, NULL), + g_bytes_get_size (ssid)); + g_ptr_array_add (ssids, ssid_array); } g_slist_free (connections); @@ -1534,27 +1510,25 @@ request_wireless_scan (gpointer user_data) } if (check_scanning_allowed (self)) { - nm_log_dbg (LOGD_WIFI_SCAN, "(%s): scanning requested", - nm_device_get_iface (NM_DEVICE (self))); + _LOGD (LOGD_WIFI_SCAN, "scanning requested"); ssids = build_hidden_probe_list (self); if (nm_logging_enabled (LOGL_DEBUG, LOGD_WIFI_SCAN)) { if (ssids) { + const GByteArray *ssid; guint i; char *foo; for (i = 0; i < ssids->len; i++) { - foo = nm_utils_ssid_to_utf8 (g_ptr_array_index (ssids, i)); - nm_log_dbg (LOGD_WIFI_SCAN, "(%s): (%d) probe scanning SSID '%s'", - nm_device_get_iface (NM_DEVICE (self)), + ssid = g_ptr_array_index (ssids, i); + foo = nm_utils_ssid_to_utf8 (ssid->data, ssid->len); + _LOGD (LOGD_WIFI_SCAN, "(%d) probe scanning SSID '%s'", i, foo ? foo : "<hidden>"); g_free (foo); } - } else { - nm_log_dbg (LOGD_WIFI_SCAN, "(%s): no SSIDs to probe scan", - nm_device_get_iface (NM_DEVICE (self))); - } + } else + _LOGD (LOGD_WIFI_SCAN, "no SSIDs to probe scan"); } if (nm_supplicant_interface_request_scan (priv->sup_iface, ssids)) { @@ -1564,14 +1538,10 @@ request_wireless_scan (gpointer user_data) nm_device_add_pending_action (NM_DEVICE (self), "scan", TRUE); } - if (ssids) { - /* Elements owned by the connections, so we don't free them here */ - g_ptr_array_free (ssids, TRUE); - } - } else { - nm_log_dbg (LOGD_WIFI_SCAN, "(%s): scan requested but not allowed at this time", - nm_device_get_iface (NM_DEVICE (self))); - } + if (ssids) + g_ptr_array_unref (ssids); + } else + _LOGD (LOGD_WIFI_SCAN, "scan requested but not allowed at this time"); priv->pending_scan_id = 0; schedule_scan (self, backoff); @@ -1622,11 +1592,8 @@ schedule_scan (NMDeviceWifi *self, gboolean backoff) priv->scan_interval = 5; } - nm_log_dbg (LOGD_WIFI_SCAN, "(%s): scheduled scan in %d seconds (interval now %d seconds)", - nm_device_get_iface (NM_DEVICE (self)), - next_scan, - priv->scan_interval); - + _LOGD (LOGD_WIFI_SCAN, "scheduled scan in %d seconds (interval now %d seconds)", + next_scan, priv->scan_interval); } } @@ -1649,9 +1616,7 @@ supplicant_iface_scan_done_cb (NMSupplicantInterface *iface, { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - nm_log_dbg (LOGD_WIFI_SCAN, "(%s): scan %s", - nm_device_get_iface (NM_DEVICE (self)), - success ? "successful" : "failed"); + _LOGD (LOGD_WIFI_SCAN, "scan %s", success ? "successful" : "failed"); schedule_scan (self, success); @@ -1674,7 +1639,7 @@ supplicant_iface_scan_done_cb (NMSupplicantInterface *iface, static void try_fill_ssid_for_hidden_ap (NMAccessPoint *ap) { - const struct ether_addr *bssid; + const char *bssid; const GSList *connections, *iter; g_return_if_fail (nm_ap_get_ssid (ap) == NULL); @@ -1692,16 +1657,17 @@ try_fill_ssid_for_hidden_ap (NMAccessPoint *ap) s_wifi = nm_connection_get_setting_wireless (connection); if (s_wifi) { if (nm_settings_connection_has_seen_bssid (NM_SETTINGS_CONNECTION (connection), bssid)) { - nm_ap_set_ssid (ap, nm_setting_wireless_get_ssid (s_wifi)); + GBytes *ssid = nm_setting_wireless_get_ssid (s_wifi); + + nm_ap_set_ssid (ap, + g_bytes_get_data (ssid, NULL), + g_bytes_get_size (ssid)); break; } } } } -#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x" -#define MAC_ARG(x) ((guint8*)(x))[0],((guint8*)(x))[1],((guint8*)(x))[2],((guint8*)(x))[3],((guint8*)(x))[4],((guint8*)(x))[5] - /* * merge_scanned_ap * @@ -1721,7 +1687,7 @@ merge_scanned_ap (NMDeviceWifi *self, NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); NMAccessPoint *found_ap = NULL; const GByteArray *ssid; - const struct ether_addr *bssid; + const char *bssid; gboolean strict_match = TRUE; /* Let the manager try to fill in the SSID from seen-bssids lists */ @@ -1734,16 +1700,13 @@ merge_scanned_ap (NMDeviceWifi *self, ssid = nm_ap_get_ssid (merge_ap); if (ssid && (nm_utils_is_empty_ssid (ssid->data, ssid->len) == FALSE)) { /* Yay, matched it, no longer treat as hidden */ - nm_log_dbg (LOGD_WIFI_SCAN, "(%s): matched hidden AP " MAC_FMT " => '%s'", - nm_device_get_iface (NM_DEVICE (self)), - MAC_ARG (bssid->ether_addr_octet), - nm_utils_escape_ssid (ssid->data, ssid->len)); + _LOGD (LOGD_WIFI_SCAN, "matched hidden AP %s => '%s'", + str_if_set (bssid, "(none)"), nm_utils_escape_ssid (ssid->data, ssid->len)); nm_ap_set_broadcast (merge_ap, FALSE); } else { /* Didn't have an entry for this AP in the database */ - nm_log_dbg (LOGD_WIFI_SCAN, "(%s): failed to match hidden AP " MAC_FMT, - nm_device_get_iface (NM_DEVICE (self)), - MAC_ARG (bssid->ether_addr_octet)); + _LOGD (LOGD_WIFI_SCAN, "failed to match hidden AP %s", + str_if_set (bssid, "(none)")); } } @@ -1760,10 +1723,9 @@ merge_scanned_ap (NMDeviceWifi *self, if (!found_ap) found_ap = nm_ap_match_in_list (merge_ap, priv->ap_list, strict_match); if (found_ap) { - nm_log_dbg (LOGD_WIFI_SCAN, "(%s): merging AP '%s' " MAC_FMT " (%p) with existing (%p)", - nm_device_get_iface (NM_DEVICE (self)), + _LOGD (LOGD_WIFI_SCAN, "merging AP '%s' %s (%p) with existing (%p)", ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)", - MAC_ARG (bssid->ether_addr_octet), + str_if_set (bssid, "(none)"), merge_ap, found_ap); @@ -1783,11 +1745,9 @@ merge_scanned_ap (NMDeviceWifi *self, nm_ap_set_fake (found_ap, FALSE); } else { /* New entry in the list */ - nm_log_dbg (LOGD_WIFI_SCAN, "(%s): adding new AP '%s' " MAC_FMT " (%p)", - nm_device_get_iface (NM_DEVICE (self)), - ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)", - MAC_ARG (bssid->ether_addr_octet), - merge_ap); + _LOGD (LOGD_WIFI_SCAN, "adding new AP '%s' %s (%p)", + ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)", + str_if_set (bssid, "(none)"), merge_ap); g_object_ref (merge_ap); priv->ap_list = g_slist_prepend (priv->ap_list, merge_ap); @@ -1809,8 +1769,7 @@ cull_scan_list (NMDeviceWifi *self) priv->scanlist_cull_id = 0; - nm_log_dbg (LOGD_WIFI_SCAN, "(%s): checking scan list for outdated APs", - nm_device_get_iface (NM_DEVICE (self))); + _LOGD (LOGD_WIFI_SCAN, "checking scan list for outdated APs"); /* Walk the access point list and remove any access points older than * three times the inactive scan interval. @@ -1844,28 +1803,23 @@ cull_scan_list (NMDeviceWifi *self) /* Remove outdated APs */ for (elt = outdated_list; elt; elt = g_slist_next (elt)) { NMAccessPoint *outdated_ap = NM_AP (elt->data); - const struct ether_addr *bssid; const GByteArray *ssid; - bssid = nm_ap_get_address (outdated_ap); ssid = nm_ap_get_ssid (outdated_ap); - nm_log_dbg (LOGD_WIFI_SCAN, - " removing %02x:%02x:%02x:%02x:%02x:%02x (%s%s%s)", - bssid->ether_addr_octet[0], bssid->ether_addr_octet[1], - bssid->ether_addr_octet[2], bssid->ether_addr_octet[3], - bssid->ether_addr_octet[4], bssid->ether_addr_octet[5], - ssid ? "'" : "", - ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)", - ssid ? "'" : ""); + _LOGD (LOGD_WIFI_SCAN, + " removing %s (%s%s%s)", + str_if_set (nm_ap_get_address (outdated_ap), "(none)"), + ssid ? "'" : "", + ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)", + ssid ? "'" : ""); remove_access_point (self, outdated_ap); removed++; } g_slist_free (outdated_list); - nm_log_dbg (LOGD_WIFI_SCAN, "(%s): removed %d APs (of %d)", - nm_device_get_iface (NM_DEVICE (self)), - removed, total); + _LOGD (LOGD_WIFI_SCAN, "removed %d APs (of %d)", + removed, total); ap_list_dump (self); @@ -1913,10 +1867,8 @@ supplicant_iface_new_bss_cb (NMSupplicantInterface *iface, /* Add the AP to the device's AP list */ merge_scanned_ap (self, ap); g_object_unref (ap); - } else { - nm_log_warn (LOGD_WIFI_SCAN, "(%s): invalid AP properties received", - nm_device_get_iface (NM_DEVICE (self))); - } + } else + _LOGW (LOGD_WIFI_SCAN, "invalid AP properties received"); /* Remove outdated access points */ schedule_scanlist_cull (self); @@ -1998,19 +1950,20 @@ wifi_secrets_cb (NMActRequest *req, GError *error, gpointer user_data) { - NMDevice *dev = NM_DEVICE (user_data); + NMDevice *device = NM_DEVICE (user_data); + NMDeviceWifi *self = NM_DEVICE_WIFI (device); - g_return_if_fail (req == nm_device_get_act_request (dev)); - g_return_if_fail (nm_device_get_state (dev) == NM_DEVICE_STATE_NEED_AUTH); + g_return_if_fail (req == nm_device_get_act_request (device)); + g_return_if_fail (nm_device_get_state (device) == NM_DEVICE_STATE_NEED_AUTH); g_return_if_fail (nm_act_request_get_connection (req) == connection); if (error) { - nm_log_warn (LOGD_WIFI, "%s", error->message); - nm_device_state_changed (dev, + _LOGW (LOGD_WIFI, "%s", error->message); + nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_NO_SECRETS); } else - nm_device_activate_schedule_stage1_device_prepare (dev); + nm_device_activate_schedule_stage1_device_prepare (device); } /* @@ -2022,11 +1975,11 @@ wifi_secrets_cb (NMActRequest *req, static gboolean link_timeout_cb (gpointer user_data) { - NMDevice *dev = NM_DEVICE (user_data); - NMDeviceWifi *self = NM_DEVICE_WIFI (dev); + NMDevice *device = NM_DEVICE (user_data); + NMDeviceWifi *self = NM_DEVICE_WIFI (device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - nm_log_warn (LOGD_WIFI, "(%s): link timed out.", nm_device_get_iface (dev)); + _LOGW (LOGD_WIFI, "link timed out."); priv->link_timeout_id = 0; @@ -2034,7 +1987,7 @@ link_timeout_cb (gpointer user_data) * to reassociate within the timeout period, so the connection must * fail. */ - if (nm_device_get_state (dev) != NM_DEVICE_STATE_ACTIVATED) + if (nm_device_get_state (device) != NM_DEVICE_STATE_ACTIVATED) return FALSE; /* If the access point failed, and wasn't found by the supplicant when it @@ -2045,7 +1998,7 @@ link_timeout_cb (gpointer user_data) if (priv->ssid_found == FALSE && priv->current_ap) set_current_ap (self, NULL, TRUE, TRUE); - nm_device_state_changed (dev, + nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, priv->ssid_found ? NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT : NM_DEVICE_STATE_REASON_SSID_NOT_FOUND); @@ -2080,10 +2033,11 @@ need_new_8021x_secrets (NMDeviceWifi *self, s_8021x = nm_connection_get_setting_802_1x (connection); if (s_8021x) { - nm_setting_get_secret_flags (NM_SETTING (s_8021x), - NM_SETTING_802_1X_PASSWORD, - &secret_flags, - NULL); + if (!nm_setting_get_secret_flags (NM_SETTING (s_8021x), + NM_SETTING_802_1X_PASSWORD, + &secret_flags, + NULL)) + g_assert_not_reached (); if (secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) *setting_name = NM_SETTING_802_1X_SETTING_NAME; return *setting_name ? TRUE : FALSE; @@ -2091,10 +2045,11 @@ need_new_8021x_secrets (NMDeviceWifi *self, s_wsec = nm_connection_get_setting_wireless_security (connection); if (s_wsec) { - nm_setting_get_secret_flags (NM_SETTING (s_wsec), - NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, - &secret_flags, - NULL); + if (!nm_setting_get_secret_flags (NM_SETTING (s_wsec), + NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, + &secret_flags, + NULL)) + g_assert_not_reached (); if (secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) *setting_name = NM_SETTING_WIRELESS_SECURITY_SETTING_NAME; return *setting_name ? TRUE : FALSE; @@ -2160,16 +2115,15 @@ handle_8021x_or_psk_auth_fail (NMDeviceWifi *self, nm_connection_clear_secrets (connection); - nm_log_info (LOGD_DEVICE | LOGD_WIFI, - "Activation (%s/wireless): disconnected during association," - " asking for new key.", nm_device_get_iface (device)); + _LOGI (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) disconnected during association, asking for new key"); cleanup_association_attempt (self, TRUE); nm_device_state_changed (device, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT); nm_act_request_get_secrets (req, setting_name, - NM_SETTINGS_GET_SECRETS_FLAG_ALLOW_INTERACTION - | NM_SETTINGS_GET_SECRETS_FLAG_REQUEST_NEW, + NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION + | NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW, NULL, wifi_secrets_cb, self); @@ -2195,11 +2149,10 @@ supplicant_iface_state_cb (NMSupplicantInterface *iface, if (new_state == old_state) return; - nm_log_info (LOGD_DEVICE | LOGD_WIFI, - "(%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)); + _LOGI (LOGD_DEVICE | LOGD_WIFI, + "supplicant interface state: %s -> %s", + nm_supplicant_interface_state_to_string (old_state), + nm_supplicant_interface_state_to_string (new_state)); devstate = nm_device_get_state (device); scanning = nm_supplicant_interface_get_scanning (iface); @@ -2222,9 +2175,7 @@ supplicant_iface_state_cb (NMSupplicantInterface *iface, NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE); } - nm_log_dbg (LOGD_WIFI_SCAN, - "(%s): supplicant ready, requesting initial scan", - nm_device_get_iface (device)); + _LOGD (LOGD_WIFI_SCAN, "supplicant ready, requesting initial scan"); /* Request a scan to get latest results */ cancel_pending_scan (self); @@ -2243,7 +2194,7 @@ supplicant_iface_state_cb (NMSupplicantInterface *iface, if (devstate == NM_DEVICE_STATE_CONFIG) { NMConnection *connection; NMSettingWireless *s_wifi; - const GByteArray *ssid; + GBytes *ssid; connection = nm_device_get_connection (NM_DEVICE (self)); g_return_if_fail (connection); @@ -2254,13 +2205,12 @@ supplicant_iface_state_cb (NMSupplicantInterface *iface, ssid = nm_setting_wireless_get_ssid (s_wifi); g_return_if_fail (ssid); - nm_log_info (LOGD_DEVICE | LOGD_WIFI, - "Activation (%s/wireless) Stage 2 of 5 (Device Configure) " - "successful. %s '%s'.", - nm_device_get_iface (device), - priv->mode == NM_802_11_MODE_AP ? "Started Wi-Fi Hotspot" : - "Connected to wireless network", - ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)"); + _LOGI (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) Stage 2 of 5 (Device Configure) successful. %s '%s'.", + priv->mode == NM_802_11_MODE_AP ? "Started Wi-Fi Hotspot" : + "Connected to wireless network", + ssid ? nm_utils_escape_ssid (g_bytes_get_data (ssid, NULL), + g_bytes_get_size (ssid)) : "(none)"); nm_device_activate_schedule_stage3_ip_config_start (device); } else if (devstate == NM_DEVICE_STATE_ACTIVATED) periodic_update (self, NULL); @@ -2326,9 +2276,9 @@ supplicant_iface_connection_error_cb (NMSupplicantInterface *iface, NMDevice *device = NM_DEVICE (self); if (nm_device_is_activating (device)) { - nm_log_warn (LOGD_DEVICE | LOGD_WIFI, - "Activation (%s/wireless): supplicant association failed: %s - %s", - nm_device_get_iface (device), name, message); + _LOGW (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) supplicant association failed: %s - %s", + name, message); cleanup_association_attempt (self, TRUE); nm_device_queue_state (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED); @@ -2356,9 +2306,7 @@ supplicant_iface_notify_scanning_cb (NMSupplicantInterface *iface, gboolean scanning; scanning = nm_supplicant_interface_get_scanning (iface); - nm_log_dbg (LOGD_WIFI_SCAN, "(%s): now %s", - nm_device_get_iface (NM_DEVICE (self)), - scanning ? "scanning" : "idle"); + _LOGD (LOGD_WIFI_SCAN, "now %s", scanning ? "scanning" : "idle"); g_object_notify (G_OBJECT (self), "scanning"); @@ -2397,16 +2345,16 @@ handle_auth_or_fail (NMDeviceWifi *self, nm_connection_clear_secrets (connection); setting_name = nm_connection_need_secrets (connection, NULL); if (setting_name) { - NMSettingsGetSecretsFlags flags = NM_SETTINGS_GET_SECRETS_FLAG_ALLOW_INTERACTION; + NMSecretAgentGetSecretsFlags flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; if (new_secrets) - flags |= NM_SETTINGS_GET_SECRETS_FLAG_REQUEST_NEW; + flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW; nm_act_request_get_secrets (req, setting_name, flags, NULL, wifi_secrets_cb, self); g_object_set_data (G_OBJECT (connection), WIRELESS_SECRETS_TRIES, GUINT_TO_POINTER (++tries)); ret = NM_ACT_STAGE_RETURN_POSTPONE; } else - nm_log_warn (LOGD_DEVICE, "Cleared secrets, but setting didn't need any secrets."); + _LOGW (LOGD_DEVICE, "Cleared secrets, but setting didn't need any secrets."); return ret; } @@ -2420,7 +2368,7 @@ handle_auth_or_fail (NMDeviceWifi *self, static gboolean supplicant_connection_timeout_cb (gpointer user_data) { - NMDevice *dev = NM_DEVICE (user_data); + NMDevice *device = NM_DEVICE (user_data); NMDeviceWifi *self = NM_DEVICE_WIFI (user_data); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); NMActRequest *req; @@ -2428,7 +2376,7 @@ supplicant_connection_timeout_cb (gpointer user_data) cleanup_association_attempt (self, TRUE); - if (!nm_device_is_activating (dev)) + if (!nm_device_is_activating (device)) return FALSE; /* Timed out waiting for a successful connection to the AP; if the AP's @@ -2437,7 +2385,7 @@ supplicant_connection_timeout_cb (gpointer user_data) * information (passwords, pin codes, etc) are wrong. */ - req = nm_device_get_act_request (dev); + req = nm_device_get_act_request (device); g_assert (req); connection = nm_act_request_get_connection (req); @@ -2449,12 +2397,10 @@ supplicant_connection_timeout_cb (gpointer user_data) * (if any), so supplicant timeouts here are almost certainly the wifi * driver being really stupid. */ - nm_log_warn (LOGD_DEVICE | LOGD_WIFI, - "Activation (%s/wireless): %s network creation took " - "too long, failing activation.", - nm_device_get_iface (dev), - priv->mode == NM_802_11_MODE_ADHOC ? "Ad-Hoc" : "Hotspot"); - nm_device_state_changed (dev, NM_DEVICE_STATE_FAILED, + _LOGW (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) %s network creation took too long, failing activation", + priv->mode == NM_802_11_MODE_ADHOC ? "Ad-Hoc" : "Hotspot"); + nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT); return FALSE; } @@ -2468,9 +2414,8 @@ supplicant_connection_timeout_cb (gpointer user_data) /* Connection failed; either driver problems, the encryption key is * wrong, or the passwords or certificates were wrong. */ - nm_log_warn (LOGD_DEVICE | LOGD_WIFI, - "Activation (%s/wireless): association took too long.", - nm_device_get_iface (dev)); + _LOGW (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) association took too long"); /* Ask for new secrets only if we've never activated this connection * before. If we've connected before, don't bother the user with @@ -2480,20 +2425,16 @@ supplicant_connection_timeout_cb (gpointer user_data) if (nm_settings_connection_get_timestamp (NM_SETTINGS_CONNECTION (connection), ×tamp)) new_secrets = !timestamp; - if (handle_auth_or_fail (self, req, new_secrets) == NM_ACT_STAGE_RETURN_POSTPONE) { - nm_log_warn (LOGD_DEVICE | LOGD_WIFI, - "Activation (%s/wireless): asking for new secrets", - nm_device_get_iface (dev)); - } else { - nm_device_state_changed (dev, NM_DEVICE_STATE_FAILED, + if (handle_auth_or_fail (self, req, new_secrets) == NM_ACT_STAGE_RETURN_POSTPONE) + _LOGW (LOGD_DEVICE | LOGD_WIFI, "Activation: (wifi) asking for new secrets"); + else { + nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_NO_SECRETS); } } else { - nm_log_warn (LOGD_DEVICE | LOGD_WIFI, - "Activation (%s/wireless): association took too long, " - "failing activation.", - nm_device_get_iface (dev)); - nm_device_state_changed (dev, NM_DEVICE_STATE_FAILED, + _LOGW (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) association took too long, failing activation"); + nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, priv->ssid_found ? NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT : NM_DEVICE_STATE_REASON_SSID_NOT_FOUND); } @@ -2523,13 +2464,13 @@ build_supplicant_config (NMDeviceWifi *self, /* Warn if AP mode may not be supported */ if ( g_strcmp0 (nm_setting_wireless_get_mode (s_wireless), NM_SETTING_WIRELESS_MODE_AP) == 0 && nm_supplicant_interface_get_ap_support (priv->sup_iface) == AP_SUPPORT_UNKNOWN) { - nm_log_warn (LOGD_WIFI, "Supplicant may not support AP mode; connection may time out."); + _LOGW (LOGD_WIFI, "Supplicant may not support AP mode; connection may time out."); } if (!nm_supplicant_config_add_setting_wireless (config, s_wireless, fixed_freq)) { - nm_log_err (LOGD_WIFI, "Couldn't add 802-11-wireless setting to supplicant config."); + _LOGE (LOGD_WIFI, "Couldn't add 802-11-wireless setting to supplicant config."); goto error; } @@ -2544,13 +2485,12 @@ build_supplicant_config (NMDeviceWifi *self, s_wireless_sec, s_8021x, con_uuid)) { - nm_log_err (LOGD_WIFI, "Couldn't add 802-11-wireless-security setting to " - "supplicant config."); + _LOGE (LOGD_WIFI, "Couldn't add 802-11-wireless-security setting to supplicant config."); goto error; } } else { if (!nm_supplicant_config_add_no_security (config)) { - nm_log_err (LOGD_WIFI, "Couldn't add unsecured option to supplicant config."); + _LOGE (LOGD_WIFI, "Couldn't add unsecured option to supplicant config."); goto error; } } @@ -2565,23 +2505,25 @@ error: /****************************************************************************/ static void -update_permanent_hw_address (NMDevice *dev) +update_permanent_hw_address (NMDevice *device) { - NMDeviceWifi *self = NM_DEVICE_WIFI (dev); + NMDeviceWifi *self = NM_DEVICE_WIFI (device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); struct ifreq req; struct ethtool_perm_addr *epaddr = NULL; - int fd, ret; + int fd, ret, errsv; + + g_return_if_fail (priv->perm_hw_addr == NULL); fd = socket (PF_INET, SOCK_DGRAM, 0); if (fd < 0) { - nm_log_err (LOGD_HW, "could not open control socket."); + _LOGE (LOGD_HW, "could not open control socket."); return; } /* Get permanent MAC address */ memset (&req, 0, sizeof (struct ifreq)); - strncpy (req.ifr_name, nm_device_get_iface (dev), IFNAMSIZ); + strncpy (req.ifr_name, nm_device_get_iface (device), IFNAMSIZ); epaddr = g_malloc0 (sizeof (struct ethtool_perm_addr) + ETH_ALEN); epaddr->cmd = ETHTOOL_GPERMADDR; @@ -2590,56 +2532,50 @@ update_permanent_hw_address (NMDevice *dev) errno = 0; ret = ioctl (fd, SIOCETHTOOL, &req); - if ((ret < 0) || !nm_ethernet_address_is_valid ((struct ether_addr *) epaddr->data)) { - nm_log_dbg (LOGD_HW | LOGD_ETHER, "(%s): unable to read permanent MAC address (error %d)", - nm_device_get_iface (dev), errno); + errsv = errno; + if ((ret < 0) || !nm_ethernet_address_is_valid (epaddr->data, ETH_ALEN)) { + _LOGD (LOGD_HW | LOGD_ETHER, "unable to read permanent MAC address (error %d)", + errsv); /* Fall back to current address */ - memcpy (epaddr->data, nm_device_get_hw_address (dev, NULL), ETH_ALEN); + nm_utils_hwaddr_aton (nm_device_get_hw_address (device), epaddr->data, ETH_ALEN); } - if (memcmp (&priv->perm_hw_addr, epaddr->data, ETH_ALEN)) { - memcpy (&priv->perm_hw_addr, epaddr->data, ETH_ALEN); - g_object_notify (G_OBJECT (dev), NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS); - } + priv->perm_hw_addr = nm_utils_hwaddr_ntoa (epaddr->data, ETH_ALEN); g_free (epaddr); close (fd); } static void -update_initial_hw_address (NMDevice *dev) +update_initial_hw_address (NMDevice *device) { - NMDeviceWifi *self = NM_DEVICE_WIFI (dev); + NMDeviceWifi *self = NM_DEVICE_WIFI (device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - char *mac_str; /* This sets initial MAC address from current MAC address. It should only * be called from NMDevice constructor() to really get the initial address. */ - memcpy (priv->initial_hw_addr, nm_device_get_hw_address (dev, NULL), ETH_ALEN); + priv->initial_hw_addr = g_strdup (nm_device_get_hw_address (device)); - mac_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ARPHRD_ETHER); - nm_log_dbg (LOGD_DEVICE | LOGD_ETHER, "(%s): read initial MAC address %s", - nm_device_get_iface (dev), mac_str); - g_free (mac_str); + _LOGD (LOGD_DEVICE | LOGD_ETHER, "read initial MAC address %s", priv->initial_hw_addr); } static NMActStageReturn -act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) +act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason) { - NMDeviceWifi *self = NM_DEVICE_WIFI (dev); + NMDeviceWifi *self = NM_DEVICE_WIFI (device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); NMActStageReturn ret; NMAccessPoint *ap = NULL; NMActRequest *req; NMConnection *connection; NMSettingWireless *s_wireless; - const GByteArray *cloned_mac; + const char *cloned_mac; GSList *iter; const char *mode; const char *ap_path; - ret = NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage1_prepare (dev, reason); + ret = NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage1_prepare (device, reason); if (ret != NM_ACT_STAGE_RETURN_SUCCESS) return ret; @@ -2670,15 +2606,15 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) * 2.6.30 or so; until that's fixed, disable WPA-protected Ad-Hoc networks. */ if (is_adhoc_wpa (connection)) { - nm_log_warn (LOGD_WIFI, "Ad-Hoc WPA disabled due to kernel bugs"); + _LOGW (LOGD_WIFI, "Ad-Hoc WPA disabled due to kernel bugs"); *reason = NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED; return NM_ACT_STAGE_RETURN_FAILURE; } /* Set spoof MAC to the interface */ cloned_mac = nm_setting_wireless_get_cloned_mac_address (s_wireless); - if (cloned_mac && (cloned_mac->len == ETH_ALEN)) - nm_device_set_hw_addr (dev, (const guint8 *) cloned_mac->data, "set", LOGD_WIFI); + if (cloned_mac) + nm_device_set_hw_addr (device, cloned_mac, "set", LOGD_WIFI); /* AP mode never uses a specific object or existing scanned AP */ if (priv->mode != NM_802_11_MODE_AP) { @@ -2716,7 +2652,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) if (nm_ap_get_mode (ap) == NM_802_11_MODE_INFRA) nm_ap_set_broadcast (ap, FALSE); else if (nm_ap_is_hotspot (ap)) - nm_ap_set_address (ap, (const struct ether_addr *) nm_device_get_hw_address (dev, NULL)); + nm_ap_set_address (ap, nm_device_get_hw_address (device)); priv->ap_list = g_slist_prepend (priv->ap_list, ap); nm_ap_export_to_dbus (ap); @@ -2759,12 +2695,11 @@ ensure_hotspot_frequency (NMDeviceWifi *self, } static NMActStageReturn -act_stage2_config (NMDevice *dev, NMDeviceStateReason *reason) +act_stage2_config (NMDevice *device, NMDeviceStateReason *reason) { - NMDeviceWifi *self = NM_DEVICE_WIFI (dev); + NMDeviceWifi *self = NM_DEVICE_WIFI (device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; - const char *iface = nm_device_get_iface (dev); NMSupplicantConfig *config = NULL; NMActRequest *req; NMAccessPoint *ap; @@ -2776,7 +2711,7 @@ act_stage2_config (NMDevice *dev, NMDeviceStateReason *reason) remove_supplicant_timeouts (self); - req = nm_device_get_act_request (dev); + req = nm_device_get_act_request (device); g_assert (req); ap = priv->current_ap; @@ -2794,10 +2729,9 @@ act_stage2_config (NMDevice *dev, NMDeviceStateReason *reason) /* If we need secrets, get them */ setting_name = nm_connection_need_secrets (connection, NULL); if (setting_name) { - nm_log_info (LOGD_DEVICE | LOGD_WIFI, - "Activation (%s/wireless): access point '%s' has security," - " but secrets are required.", - iface, nm_connection_get_id (connection)); + _LOGI (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) access point '%s' has security, but secrets are required.", + nm_connection_get_id (connection)); ret = handle_auth_or_fail (self, req, FALSE); if (ret == NM_ACT_STAGE_RETURN_FAILURE) @@ -2807,15 +2741,13 @@ act_stage2_config (NMDevice *dev, NMDeviceStateReason *reason) /* have secrets, or no secrets required */ if (nm_connection_get_setting_wireless_security (connection)) { - nm_log_info (LOGD_DEVICE | LOGD_WIFI, - "Activation (%s/wireless): connection '%s' has security" - ", and secrets exist. No new secrets needed.", - iface, nm_connection_get_id (connection)); + _LOGI (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) connection '%s' has security, and secrets exist. No new secrets needed.", + nm_connection_get_id (connection)); } else { - nm_log_info (LOGD_DEVICE | LOGD_WIFI, - "Activation (%s/wireless): connection '%s' requires no " - "security. No secrets needed.", - iface, nm_connection_get_id (connection)); + _LOGI (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) connection '%s' requires no security. No secrets needed.", + nm_connection_get_id (connection)); } priv->ssid_found = FALSE; @@ -2830,9 +2762,8 @@ act_stage2_config (NMDevice *dev, NMDeviceStateReason *reason) /* Build up the supplicant configuration */ config = build_supplicant_config (self, connection, nm_ap_get_freq (ap)); if (config == NULL) { - nm_log_err (LOGD_DEVICE | LOGD_WIFI, - "Activation (%s/wireless): couldn't build wireless configuration.", - iface); + _LOGE (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) couldn't build wireless configuration."); *reason = NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED; goto out; } @@ -2844,9 +2775,8 @@ act_stage2_config (NMDevice *dev, NMDeviceStateReason *reason) self); if (!nm_supplicant_interface_set_config (priv->sup_iface, config)) { - nm_log_err (LOGD_DEVICE | LOGD_WIFI, - "Activation (%s/wireless): couldn't send wireless " - "configuration to the supplicant.", iface); + _LOGE (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) couldn't send wireless configuration to the supplicant."); *reason = NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED; goto out; } @@ -2879,14 +2809,14 @@ act_stage3_ip4_config_start (NMDevice *device, NMDeviceStateReason *reason) { NMConnection *connection; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; const char *method = NM_SETTING_IP4_CONFIG_METHOD_AUTO; connection = nm_device_get_connection (device); g_assert (connection); s_ip4 = nm_connection_get_setting_ip4_config (connection); if (s_ip4) - method = nm_setting_ip4_config_get_method (s_ip4); + method = nm_setting_ip_config_get_method (s_ip4); /* Indicate that a critical protocol is about to start */ if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0) @@ -2901,14 +2831,14 @@ act_stage3_ip6_config_start (NMDevice *device, NMDeviceStateReason *reason) { NMConnection *connection; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip6; const char *method = NM_SETTING_IP6_CONFIG_METHOD_AUTO; connection = nm_device_get_connection (device); g_assert (connection); s_ip6 = nm_connection_get_setting_ip6_config (connection); if (s_ip6) - method = nm_setting_ip6_config_get_method (s_ip6); + method = nm_setting_ip_config_get_method (s_ip6); /* Indicate that a critical protocol is about to start */ if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0 || @@ -2933,7 +2863,7 @@ ip4_config_pre_commit (NMDevice *device, NMIP4Config *config) /* MTU override */ mtu = nm_setting_wireless_get_mtu (s_wifi); if (mtu) - nm_ip4_config_set_mtu (config, mtu); + nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER); } static gboolean @@ -2984,17 +2914,14 @@ handle_ip_config_timeout (NMDeviceWifi *self, */ if (!may_fail && is_static_wep (connection)) { /* Activation failed, we must have bad encryption key */ - nm_log_warn (LOGD_DEVICE | LOGD_WIFI, - "Activation (%s/wireless): could not get IP configuration for " - "connection '%s'.", - nm_device_get_iface (NM_DEVICE (self)), - nm_connection_get_id (connection)); + _LOGW (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) could not get IP configuration for connection '%s'.", + nm_connection_get_id (connection)); ret = handle_auth_or_fail (self, NULL, TRUE); if (ret == NM_ACT_STAGE_RETURN_POSTPONE) { - nm_log_info (LOGD_DEVICE | LOGD_WIFI, - "Activation (%s/wireless): asking for new secrets", - nm_device_get_iface (NM_DEVICE (self))); + _LOGI (LOGD_DEVICE | LOGD_WIFI, + "Activation: (wifi) asking for new secrets"); } else { *reason = NM_DEVICE_STATE_REASON_NO_SECRETS; } @@ -3008,60 +2935,60 @@ handle_ip_config_timeout (NMDeviceWifi *self, static NMActStageReturn -act_stage4_ip4_config_timeout (NMDevice *dev, NMDeviceStateReason *reason) +act_stage4_ip4_config_timeout (NMDevice *device, NMDeviceStateReason *reason) { NMConnection *connection; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; gboolean may_fail = FALSE, chain_up = FALSE; NMActStageReturn ret; - connection = nm_device_get_connection (dev); + connection = nm_device_get_connection (device); g_assert (connection); s_ip4 = nm_connection_get_setting_ip4_config (connection); - may_fail = nm_setting_ip4_config_get_may_fail (s_ip4); + may_fail = nm_setting_ip_config_get_may_fail (s_ip4); - ret = handle_ip_config_timeout (NM_DEVICE_WIFI (dev), connection, may_fail, &chain_up, reason); + ret = handle_ip_config_timeout (NM_DEVICE_WIFI (device), connection, may_fail, &chain_up, reason); if (chain_up) - ret = NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage4_ip4_config_timeout (dev, reason); + ret = NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage4_ip4_config_timeout (device, reason); return ret; } static NMActStageReturn -act_stage4_ip6_config_timeout (NMDevice *dev, NMDeviceStateReason *reason) +act_stage4_ip6_config_timeout (NMDevice *device, NMDeviceStateReason *reason) { NMConnection *connection; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip6; gboolean may_fail = FALSE, chain_up = FALSE; NMActStageReturn ret; - connection = nm_device_get_connection (dev); + connection = nm_device_get_connection (device); g_assert (connection); s_ip6 = nm_connection_get_setting_ip6_config (connection); - may_fail = nm_setting_ip6_config_get_may_fail (s_ip6); + may_fail = nm_setting_ip_config_get_may_fail (s_ip6); - ret = handle_ip_config_timeout (NM_DEVICE_WIFI (dev), connection, may_fail, &chain_up, reason); + ret = handle_ip_config_timeout (NM_DEVICE_WIFI (device), connection, may_fail, &chain_up, reason); if (chain_up) - ret = NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage4_ip6_config_timeout (dev, reason); + ret = NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage4_ip6_config_timeout (device, reason); return ret; } static void -activation_success_handler (NMDevice *dev) +activation_success_handler (NMDevice *device) { - NMDeviceWifi *self = NM_DEVICE_WIFI (dev); + NMDeviceWifi *self = NM_DEVICE_WIFI (device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - int ifindex = nm_device_get_ifindex (dev); + int ifindex = nm_device_get_ifindex (device); NMAccessPoint *ap; - struct ether_addr bssid = { {0x0, 0x0, 0x0, 0x0, 0x0, 0x0} }; + guint8 bssid[ETH_ALEN] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; NMAccessPoint *tmp_ap = NULL; NMActRequest *req; NMConnection *connection; - req = nm_device_get_act_request (dev); + req = nm_device_get_act_request (device); g_assert (req); connection = nm_act_request_get_connection (req); @@ -3087,9 +3014,12 @@ activation_success_handler (NMDevice *dev) * But if activation was successful, the card will know the BSSID. Grab * the BSSID off the card and fill in the BSSID of the activation AP. */ - nm_platform_wifi_get_bssid (ifindex, &bssid); - if (!nm_ethernet_address_is_valid (nm_ap_get_address (ap))) - nm_ap_set_address (ap, &bssid); + nm_platform_wifi_get_bssid (ifindex, bssid); + if (!nm_ap_get_address (ap)) { + char *bssid_str = nm_utils_hwaddr_ntoa (bssid, ETH_ALEN); + nm_ap_set_address (ap, bssid_str); + g_free (bssid_str); + } if (!nm_ap_get_freq (ap)) nm_ap_set_freq (ap, nm_platform_wifi_get_frequency (ifindex)); if (!nm_ap_get_max_bitrate (ap)) @@ -3103,9 +3033,11 @@ activation_success_handler (NMDevice *dev) * instead. */ - /* If the better match was a hidden AP, update it's SSID */ - if (!ssid || nm_utils_is_empty_ssid (ssid->data, ssid->len)) - nm_ap_set_ssid (tmp_ap, nm_ap_get_ssid (ap)); + /* If the better match was a hidden AP, update its SSID */ + if (!ssid || nm_utils_is_empty_ssid (ssid->data, ssid->len)) { + ssid = nm_ap_get_ssid (ap); + nm_ap_set_ssid (tmp_ap, ssid->data, ssid->len); + } nm_active_connection_set_specific_object (NM_ACTIVE_CONNECTION (req), nm_ap_get_dbus_path (tmp_ap)); @@ -3130,18 +3062,18 @@ done: } static void -activation_failure_handler (NMDevice *dev) +activation_failure_handler (NMDevice *device) { NMConnection *connection; - connection = nm_device_get_connection (dev); + connection = nm_device_get_connection (device); g_assert (connection); /* Clear wireless secrets tries on failure */ g_object_set_data (G_OBJECT (connection), WIRELESS_SECRETS_TRIES, NULL); /* Clear any critical protocol notification in the wifi stack */ - nm_platform_wifi_indicate_addressing_running (nm_device_get_ifindex (dev), FALSE); + nm_platform_wifi_indicate_addressing_running (nm_device_get_ifindex (device), FALSE); } static void @@ -3225,15 +3157,12 @@ set_enabled (NMDevice *device, gboolean enabled) priv->enabled = enabled; - nm_log_dbg (LOGD_WIFI, "(%s): device now %s", - nm_device_get_iface (NM_DEVICE (device)), - enabled ? "enabled" : "disabled"); + _LOGD (LOGD_WIFI, "device now %s", enabled ? "enabled" : "disabled"); state = nm_device_get_state (NM_DEVICE (self)); if (state < NM_DEVICE_STATE_UNAVAILABLE) { - nm_log_dbg (LOGD_WIFI, "(%s): %s blocked by UNMANAGED state", - enabled ? "enable" : "disable", - nm_device_get_iface (NM_DEVICE (device))); + _LOGD (LOGD_WIFI, "(%s): device blocked by UNMANAGED state", + enabled ? "enable" : "disable"); return; } @@ -3241,11 +3170,10 @@ set_enabled (NMDevice *device, gboolean enabled) gboolean no_firmware = FALSE; if (state != NM_DEVICE_STATE_UNAVAILABLE) - nm_log_warn (LOGD_CORE, "not in expected unavailable state!"); + _LOGW (LOGD_CORE, "not in expected unavailable state!"); if (!nm_device_bring_up (NM_DEVICE (self), TRUE, &no_firmware)) { - nm_log_dbg (LOGD_WIFI, "(%s): enable blocked by failure to bring device up", - nm_device_get_iface (NM_DEVICE (device))); + _LOGD (LOGD_WIFI, "enable blocked by failure to bring device up"); if (no_firmware) nm_device_set_firmware_missing (NM_DEVICE (device), TRUE); @@ -3261,8 +3189,7 @@ set_enabled (NMDevice *device, gboolean enabled) supplicant_interface_release (self); supplicant_interface_acquire (self); - nm_log_dbg (LOGD_WIFI, "(%s): enable waiting on supplicant state", - nm_device_get_iface (NM_DEVICE (device))); + _LOGD (LOGD_WIFI, "enable waiting on supplicant state"); } else { nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_UNAVAILABLE, @@ -3321,6 +3248,18 @@ dispose (GObject *object) } static void +finalize (GObject *object) +{ + NMDeviceWifi *self = NM_DEVICE_WIFI (object); + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); + + g_free (priv->perm_hw_addr); + g_free (priv->initial_hw_addr); + + G_OBJECT_CLASS (nm_device_wifi_parent_class)->finalize (object); +} + +static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { @@ -3331,7 +3270,7 @@ get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_PERM_HW_ADDRESS: - g_value_take_string (value, nm_utils_hwaddr_ntoa (&priv->perm_hw_addr, ARPHRD_ETHER)); + g_value_set_string (value, priv->perm_hw_addr); break; case PROP_MODE: g_value_set_uint (value, priv->mode); @@ -3387,6 +3326,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) object_class->get_property = get_property; object_class->set_property = set_property; object_class->dispose = dispose; + object_class->finalize = finalize; parent_class->bring_up = bring_up; parent_class->update_permanent_hw_address = update_permanent_hw_address; @@ -3413,57 +3353,56 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) klass->scanning_allowed = scanning_allowed; /* Properties */ - g_object_class_install_property (object_class, PROP_PERM_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS, - "Permanent MAC Address", - "Permanent hardware MAC address", - NULL, - G_PARAM_READABLE)); - - g_object_class_install_property (object_class, PROP_MODE, - g_param_spec_uint (NM_DEVICE_WIFI_MODE, - "Mode", - "Mode", - NM_802_11_MODE_UNKNOWN, - NM_802_11_MODE_AP, - NM_802_11_MODE_INFRA, - G_PARAM_READABLE)); - - g_object_class_install_property (object_class, PROP_BITRATE, - g_param_spec_uint (NM_DEVICE_WIFI_BITRATE, - "Bitrate", - "Bitrate", - 0, G_MAXUINT32, 0, - G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_PERM_HW_ADDRESS, + g_param_spec_string (NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_MODE, + g_param_spec_uint (NM_DEVICE_WIFI_MODE, "", "", + NM_802_11_MODE_UNKNOWN, + NM_802_11_MODE_AP, + NM_802_11_MODE_INFRA, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_BITRATE, + g_param_spec_uint (NM_DEVICE_WIFI_BITRATE, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_ACCESS_POINTS, - g_param_spec_boxed (NM_DEVICE_WIFI_ACCESS_POINTS, - "Access points", - "Access points", + g_param_spec_boxed (NM_DEVICE_WIFI_ACCESS_POINTS, "", "", DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, - G_PARAM_READABLE)); - - g_object_class_install_property (object_class, PROP_ACTIVE_ACCESS_POINT, - g_param_spec_boxed (NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT, - "Active access point", - "Currently active access point", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE)); - - g_object_class_install_property (object_class, PROP_CAPABILITIES, - g_param_spec_uint (NM_DEVICE_WIFI_CAPABILITIES, - "Wireless Capabilities", - "Wireless Capabilities", - 0, G_MAXUINT32, NM_WIFI_DEVICE_CAP_NONE, - G_PARAM_READABLE)); - - g_object_class_install_property (object_class, PROP_SCANNING, - g_param_spec_boolean (NM_DEVICE_WIFI_SCANNING, - "Scanning", - "Scanning", - FALSE, - G_PARAM_READABLE)); + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_ACTIVE_ACCESS_POINT, + g_param_spec_boxed (NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT, "", "", + DBUS_TYPE_G_OBJECT_PATH, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_CAPABILITIES, + g_param_spec_uint (NM_DEVICE_WIFI_CAPABILITIES, "", "", + 0, G_MAXUINT32, NM_WIFI_DEVICE_CAP_NONE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_SCANNING, + g_param_spec_boolean (NM_DEVICE_WIFI_SCANNING, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); /* Signals */ signals[ACCESS_POINT_ADDED] = @@ -3495,8 +3434,6 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), G_TYPE_FROM_CLASS (klass), &dbus_glib_nm_device_wifi_object_info); - - dbus_g_error_domain_register (NM_WIFI_ERROR, NULL, NM_TYPE_WIFI_ERROR); } |