From 6ee7e22acb873a1c90ae08ec426cf835044c546b Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 16 Apr 2015 10:59:04 -0500 Subject: [PATCH 01/11] wifi: make nm_ap_dump() print on one line --- src/devices/wifi/nm-device-wifi.c | 4 +-- src/devices/wifi/nm-wifi-ap.c | 51 ++++++++++++++++++++++--------- src/devices/wifi/nm-wifi-ap.h | 4 ++- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index d98dd7d06..c56595fcf 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -1034,7 +1034,7 @@ ap_list_dump (NMDeviceWifi *self) _LOGD (LOGD_WIFI_SCAN, "Current AP list:"); sorted = get_sorted_ap_list (self); for (iter = sorted; iter; iter = iter->next) - nm_ap_dump (NM_AP (iter->data), "List AP: "); + nm_ap_dump (NM_AP (iter->data), "List AP: ", nm_device_get_iface (NM_DEVICE (self))); g_slist_free (sorted); _LOGD (LOGD_WIFI_SCAN, "Current AP list: done"); } @@ -1640,7 +1640,7 @@ supplicant_iface_new_bss_cb (NMSupplicantInterface *iface, ap = nm_ap_new_from_properties (object_path, properties); if (ap) { - nm_ap_dump (ap, "New AP: "); + nm_ap_dump (ap, "New AP: ", nm_device_get_iface (NM_DEVICE (self))); /* Add the AP to the device's AP list */ merge_scanned_ap (self, ap, object_path, properties); diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index 56d7cbfd6..1867583a0 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -711,28 +711,51 @@ error: return NULL; } +static char +mode_to_char (NMAccessPoint *self) +{ + NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (self); + + if (priv->mode == NM_802_11_MODE_ADHOC) + return '*'; + if (priv->hotspot) + return '#'; + if (priv->fake) + return '-'; + return ' '; +} + void -nm_ap_dump (NMAccessPoint *ap, const char *prefix) +nm_ap_dump (NMAccessPoint *self, + const char *prefix, + const char *ifname) { NMAccessPointPrivate *priv; + const char *supplicant_id = "-"; + guint32 chan; - g_return_if_fail (NM_IS_AP (ap)); + g_return_if_fail (NM_IS_AP (self)); - priv = NM_AP_GET_PRIVATE (ap); + priv = NM_AP_GET_PRIVATE (self); + chan = nm_utils_wifi_freq_to_channel (priv->freq); + if (priv->supplicant_path) + supplicant_id = strrchr (priv->supplicant_path, '/'); - nm_log_dbg (LOGD_WIFI_SCAN, "%s'%s' (%p)", + nm_log_dbg (LOGD_WIFI_SCAN, "%s[%s%c] %-32s[%s%u %s%u%% %c W:%04X R:%04X] [%3u] %s%s", prefix, + str_if_set (priv->address, "(none)"), + mode_to_char (self), priv->ssid ? nm_utils_escape_ssid (priv->ssid->data, priv->ssid->len) : "(none)", - ap); - nm_log_dbg (LOGD_WIFI_SCAN, " BSSID %s", str_if_set (priv->address, "(none)")); - nm_log_dbg (LOGD_WIFI_SCAN, " mode %d", priv->mode); - nm_log_dbg (LOGD_WIFI_SCAN, " flags 0x%X", priv->flags); - nm_log_dbg (LOGD_WIFI_SCAN, " wpa flags 0x%X", priv->wpa_flags); - nm_log_dbg (LOGD_WIFI_SCAN, " rsn flags 0x%X", priv->rsn_flags); - nm_log_dbg (LOGD_WIFI_SCAN, " quality %d", priv->strength); - nm_log_dbg (LOGD_WIFI_SCAN, " frequency %d", priv->freq); - nm_log_dbg (LOGD_WIFI_SCAN, " max rate %d", priv->max_bitrate); - nm_log_dbg (LOGD_WIFI_SCAN, " last-seen %d", (int) priv->last_seen); + chan > 99 ? "" : (chan > 9 ? " " : " "), + chan, + priv->strength < 100 ? " " : "", + priv->strength, + priv->flags & NM_802_11_AP_FLAGS_PRIVACY ? 'P' : ' ', + priv->wpa_flags & 0xFFFF, + priv->rsn_flags & 0xFFFF, + priv->last_seen > 0 ? (nm_utils_get_monotonic_timestamp_s () - priv->last_seen) : -1, + ifname, + supplicant_id); } const char * diff --git a/src/devices/wifi/nm-wifi-ap.h b/src/devices/wifi/nm-wifi-ap.h index 2bdb02350..cbea3e307 100644 --- a/src/devices/wifi/nm-wifi-ap.h +++ b/src/devices/wifi/nm-wifi-ap.h @@ -118,6 +118,8 @@ gboolean nm_ap_complete_connection (NMAccessPoint *self, NMAccessPoint * nm_ap_match_in_hash (NMAccessPoint *find_ap, GHashTable *hash); -void nm_ap_dump (NMAccessPoint *ap, const char *prefix); +void nm_ap_dump (NMAccessPoint *self, + const char *prefix, + const char *ifname); #endif /* __NETWORKMANAGER_ACCESS_POINT_H__ */ From be370859ef2fd781a8ad0a479a8cd1f02751323b Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 16 Apr 2015 11:21:47 -0500 Subject: [PATCH 02/11] wifi: condense AP list dump log message Remove the trailing message, and indicate when the last scan took place and when the next one will happen. --- src/devices/wifi/nm-device-wifi.c | 39 +++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index c56595fcf..513bd8719 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -127,6 +127,7 @@ struct _NMDeviceWifiPrivate { guint32 rate; gboolean enabled; /* rfkilled or not */ + gint32 last_scan; gint32 scheduled_scan_time; guint8 scan_interval; /* seconds */ guint pending_scan_id; @@ -1021,24 +1022,6 @@ get_sorted_ap_list (NMDeviceWifi *self) return g_slist_sort (sorted, (GCompareFunc) ap_id_compare); } -static void -ap_list_dump (NMDeviceWifi *self) -{ - GSList *sorted, *iter; - - g_return_if_fail (NM_IS_DEVICE_WIFI (self)); - - if (!nm_logging_enabled (LOGL_DEBUG, LOGD_WIFI_SCAN)) - return; - - _LOGD (LOGD_WIFI_SCAN, "Current AP list:"); - sorted = get_sorted_ap_list (self); - for (iter = sorted; iter; iter = iter->next) - nm_ap_dump (NM_AP (iter->data), "List AP: ", nm_device_get_iface (NM_DEVICE (self))); - g_slist_free (sorted); - _LOGD (LOGD_WIFI_SCAN, "Current AP list: done"); -} - static gboolean impl_device_get_access_points (NMDeviceWifi *self, GPtrArray **aps, @@ -1434,6 +1417,7 @@ supplicant_iface_scan_done_cb (NMSupplicantInterface *iface, _LOGD (LOGD_WIFI_SCAN, "scan %s", success ? "successful" : "failed"); + priv->last_scan = nm_utils_get_monotonic_timestamp_s (); schedule_scan (self, success); /* Ensure that old APs get removed, which otherwise only @@ -1452,6 +1436,25 @@ supplicant_iface_scan_done_cb (NMSupplicantInterface *iface, * */ +static void +ap_list_dump (NMDeviceWifi *self) +{ + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); + GSList *sorted, *iter; + + if (!nm_logging_enabled (LOGL_DEBUG, LOGD_WIFI_SCAN)) + return; + + _LOGD (LOGD_WIFI_SCAN, "APs: [now:%u last:%u next:%u]", + nm_utils_get_monotonic_timestamp_s (), + priv->last_scan, + priv->scheduled_scan_time); + sorted = get_sorted_ap_list (self); + for (iter = sorted; iter; iter = iter->next) + nm_ap_dump (NM_AP (iter->data), " ", nm_device_get_iface (NM_DEVICE (self))); + g_slist_free (sorted); +} + #define WPAS_REMOVED_TAG "supplicant-removed" static void From 910c62d8c7ee052db4cdc992350c36ed5d8bd138 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 16 Apr 2015 12:05:05 -0500 Subject: [PATCH 03/11] wifi: follow supplicant's scan list instead of managing AP lifetime internally Instead of tricky logic to merge APs and age them, just tell the supplicant what our aging parameters are, and rely on it to handle removal from the list. Notable behavioral changes are: * APs will now be removed when they haven't been seen for two consecutive scans in which they would have been included. This means that when the scan interval is short, out-of-range APs will be removed much more quickly than the previous 360 seconds. * APs now live at most 250 seconds (twice our longest scan interval) instead of the previous 360 seconds. * The problem with wpa_supplicant < 2.3 not notifying that a BSS has been seen in the scan if none of its properties actually changed is now avoided, because an AP is only removed when the supplicant removes it In general these changes should make the scan list more responsive, at the cost of slightly more instability in the list due to the unreliability of WiFi scanning. But it also removes a layer of complexity and abstraction from NetworkManager, pushing the scan results list closer to that which the hardware reports. --- src/devices/wifi/nm-device-wifi.c | 259 +++++------------- src/devices/wifi/nm-wifi-ap.c | 63 ----- src/devices/wifi/nm-wifi-ap.h | 2 - .../nm-supplicant-interface.c | 24 ++ 4 files changed, 99 insertions(+), 249 deletions(-) diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 513bd8719..1922f9424 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -131,7 +131,7 @@ struct _NMDeviceWifiPrivate { gint32 scheduled_scan_time; guint8 scan_interval; /* seconds */ guint pending_scan_id; - guint scanlist_cull_id; + guint ap_dump_id; gboolean requested_scan; NMSupplicantManager *sup_mgr; @@ -189,8 +189,6 @@ static void supplicant_iface_notify_current_bss (NMSupplicantInterface *iface, GParamSpec *pspec, NMDeviceWifi *self); -static void schedule_scanlist_cull (NMDeviceWifi *self); - static gboolean request_wireless_scan (gpointer user_data); static void emit_ap_added_removed (NMDeviceWifi *self, @@ -305,10 +303,7 @@ supplicant_interface_release (NMDeviceWifi *self) _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); - priv->scanlist_cull_id = 0; - } + nm_clear_g_source (&priv->ap_dump_id); if (priv->sup_iface) { remove_supplicant_interface_error_handler (self); @@ -1420,11 +1415,6 @@ supplicant_iface_scan_done_cb (NMSupplicantInterface *iface, priv->last_scan = nm_utils_get_monotonic_timestamp_s (); schedule_scan (self, success); - /* Ensure that old APs get removed, which otherwise only - * happens when there are new BSSes. - */ - schedule_scanlist_cull (self); - if (priv->requested_scan) { priv->requested_scan = FALSE; nm_device_remove_pending_action (NM_DEVICE (self), "scan", TRUE); @@ -1436,15 +1426,14 @@ supplicant_iface_scan_done_cb (NMSupplicantInterface *iface, * */ -static void -ap_list_dump (NMDeviceWifi *self) +static gboolean +ap_list_dump (gpointer user_data) { + NMDeviceWifi *self = NM_DEVICE_WIFI (user_data); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); GSList *sorted, *iter; - if (!nm_logging_enabled (LOGL_DEBUG, LOGD_WIFI_SCAN)) - return; - + priv->ap_dump_id = 0; _LOGD (LOGD_WIFI_SCAN, "APs: [now:%u last:%u next:%u]", nm_utils_get_monotonic_timestamp_s (), priv->last_scan, @@ -1453,9 +1442,19 @@ ap_list_dump (NMDeviceWifi *self) for (iter = sorted; iter; iter = iter->next) nm_ap_dump (NM_AP (iter->data), " ", nm_device_get_iface (NM_DEVICE (self))); g_slist_free (sorted); + return G_SOURCE_REMOVE; } -#define WPAS_REMOVED_TAG "supplicant-removed" +static void +schedule_ap_list_dump (NMDeviceWifi *self) +{ + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); + + if (!nm_logging_enabled (LOGL_DEBUG, LOGD_WIFI_SCAN)) + return; + nm_clear_g_source (&priv->ap_dump_id); + priv->ap_dump_id = g_timeout_add_seconds (1, ap_list_dump, self); +} static void try_fill_ssid_for_hidden_ap (NMAccessPoint *ap) @@ -1489,137 +1488,6 @@ try_fill_ssid_for_hidden_ap (NMAccessPoint *ap) } } -static void -merge_scanned_ap (NMDeviceWifi *self, - NMAccessPoint *merge_ap, - const char *supplicant_path, - GVariant *properties) -{ - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - NMAccessPoint *found_ap = NULL; - const GByteArray *ssid; - const char *bssid; - - /* Let the manager try to fill in the SSID from seen-bssids lists */ - bssid = nm_ap_get_address (merge_ap); - ssid = nm_ap_get_ssid (merge_ap); - if (!ssid || nm_utils_is_empty_ssid (ssid->data, ssid->len)) { - /* Try to fill the SSID from the AP database */ - try_fill_ssid_for_hidden_ap (merge_ap); - - 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 */ - _LOGD (LOGD_WIFI_SCAN, "matched hidden AP %s => '%s'", - str_if_set (bssid, "(none)"), nm_utils_escape_ssid (ssid->data, ssid->len)); - } else { - /* Didn't have an entry for this AP in the database */ - _LOGD (LOGD_WIFI_SCAN, "failed to match hidden AP %s", - str_if_set (bssid, "(none)")); - } - } - - found_ap = get_ap_by_supplicant_path (self, supplicant_path); - if (!found_ap) - found_ap = nm_ap_match_in_hash (merge_ap, priv->aps); - if (found_ap) { - _LOGD (LOGD_WIFI_SCAN, "merging AP '%s' %s (%p) with existing (%p)", - ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)", - str_if_set (bssid, "(none)"), - merge_ap, - found_ap); - - nm_ap_update_from_properties (found_ap, supplicant_path, properties); - nm_ap_set_fake (found_ap, FALSE); - g_object_set_data (G_OBJECT (found_ap), WPAS_REMOVED_TAG, NULL); - } else { - /* New entry in the list */ - _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); - nm_ap_export_to_dbus (merge_ap); - g_hash_table_insert (priv->aps, (gpointer) nm_ap_get_dbus_path (merge_ap), merge_ap); - emit_ap_added_removed (self, ACCESS_POINT_ADDED, merge_ap, TRUE); - } -} - -static gboolean -cull_scan_list (NMDeviceWifi *self) -{ - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - gint32 now = nm_utils_get_monotonic_timestamp_s (); - guint32 removed = 0, total = 0; - GHashTableIter iter; - NMAccessPoint *ap; - - priv->scanlist_cull_id = 0; - - _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. - */ - g_hash_table_iter_init (&iter, priv->aps); - while (g_hash_table_iter_next (&iter, NULL, (gpointer) &ap)) { - const guint prune_interval_s = SCAN_INTERVAL_MAX * 3; - gint32 last_seen; - - /* Don't cull the associated AP or manually created APs */ - if (ap == priv->current_ap) - continue; - g_assert (!nm_ap_get_fake (ap)); /* only the current_ap can be fake */ - - /* Don't cull APs still known to the supplicant. Since the supplicant - * doesn't yet emit property updates for "last seen" we have to rely - * on changing signal strength for updating "last seen". But if the - * AP's strength doesn't change we won't get any updates for the AP, - * and we'll end up here even if the AP was still found by the - * supplicant in the last scan. - */ - if ( nm_ap_get_supplicant_path (ap) - && g_object_get_data (G_OBJECT (ap), WPAS_REMOVED_TAG) == NULL) - continue; - - last_seen = nm_ap_get_last_seen (ap); - if (!last_seen || last_seen + prune_interval_s < now) { - const GByteArray *ssid = nm_ap_get_ssid (ap); - - _LOGD (LOGD_WIFI_SCAN, - " removing %s (%s%s%s)", - str_if_set (nm_ap_get_address (ap), "(none)"), - ssid ? "'" : "", - ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)", - ssid ? "'" : ""); - emit_ap_added_removed (self, ACCESS_POINT_REMOVED, ap, FALSE); - g_hash_table_iter_remove (&iter); - removed++; - } - } - - _LOGD (LOGD_WIFI_SCAN, "removed %d APs (of %d)", - removed, total); - - ap_list_dump (self); - - if(removed > 0) - nm_device_recheck_available_connections (NM_DEVICE (self)); - - return FALSE; -} - -static void -schedule_scanlist_cull (NMDeviceWifi *self) -{ - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - - /* Cull the scan list after the last request for it has come in */ - if (priv->scanlist_cull_id) - g_source_remove (priv->scanlist_cull_id); - priv->scanlist_cull_id = g_timeout_add_seconds (4, (GSourceFunc) cull_scan_list, self); -} - static void supplicant_iface_new_bss_cb (NMSupplicantInterface *iface, const char *object_path, @@ -1629,6 +1497,9 @@ supplicant_iface_new_bss_cb (NMSupplicantInterface *iface, NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); NMDeviceState state; NMAccessPoint *ap; + NMAccessPoint *found_ap = NULL; + const GByteArray *ssid; + const char *bssid; g_return_if_fail (self != NULL); g_return_if_fail (properties != NULL); @@ -1642,23 +1513,52 @@ supplicant_iface_new_bss_cb (NMSupplicantInterface *iface, return; ap = nm_ap_new_from_properties (object_path, properties); - if (ap) { - nm_ap_dump (ap, "New AP: ", nm_device_get_iface (NM_DEVICE (self))); - - /* Add the AP to the device's AP list */ - merge_scanned_ap (self, ap, object_path, properties); - g_object_unref (ap); - - /* Update the current AP if the supplicant notified a current BSS change - * before it sent the current BSS's scan result. - */ - if (g_strcmp0 (nm_supplicant_interface_get_current_bss (iface), object_path) == 0) - supplicant_iface_notify_current_bss (priv->sup_iface, NULL, self); - } else + if (!ap) { _LOGW (LOGD_WIFI_SCAN, "invalid AP properties received"); + return; + } - /* Remove outdated access points */ - schedule_scanlist_cull (self); + /* Let the manager try to fill in the SSID from seen-bssids lists */ + bssid = nm_ap_get_address (ap); + ssid = nm_ap_get_ssid (ap); + if (!ssid || nm_utils_is_empty_ssid (ssid->data, ssid->len)) { + /* Try to fill the SSID from the AP database */ + try_fill_ssid_for_hidden_ap (ap); + + ssid = nm_ap_get_ssid (ap); + if (ssid && (nm_utils_is_empty_ssid (ssid->data, ssid->len) == FALSE)) { + /* Yay, matched it, no longer treat as hidden */ + _LOGD (LOGD_WIFI_SCAN, "matched hidden AP %s => '%s'", + str_if_set (bssid, "(none)"), nm_utils_escape_ssid (ssid->data, ssid->len)); + } else { + /* Didn't have an entry for this AP in the database */ + _LOGD (LOGD_WIFI_SCAN, "failed to match hidden AP %s", + str_if_set (bssid, "(none)")); + } + } + + found_ap = get_ap_by_supplicant_path (self, object_path); + if (found_ap) { + nm_ap_dump (ap, "updated ", nm_device_get_iface (NM_DEVICE (self))); + nm_ap_update_from_properties (found_ap, object_path, properties); + } else { + nm_ap_dump (ap, "added ", nm_device_get_iface (NM_DEVICE (self))); + nm_ap_export_to_dbus (ap); + g_hash_table_insert (priv->aps, + (gpointer) nm_ap_get_dbus_path (ap), + g_object_ref (ap)); + emit_ap_added_removed (self, ACCESS_POINT_ADDED, ap, TRUE); + } + + g_object_unref (ap); + + /* Update the current AP if the supplicant notified a current BSS change + * before it sent the current BSS's scan result. + */ + if (g_strcmp0 (nm_supplicant_interface_get_current_bss (iface), object_path) == 0) + supplicant_iface_notify_current_bss (priv->sup_iface, NULL, self); + + schedule_ap_list_dump (self); } static void @@ -1679,13 +1579,12 @@ supplicant_iface_bss_updated_cb (NMSupplicantInterface *iface, if (state <= NM_DEVICE_STATE_UNAVAILABLE) return; - /* Update the AP's last-seen property */ ap = get_ap_by_supplicant_path (self, object_path); - if (ap) + if (ap) { + nm_ap_dump (ap, "updated ", nm_device_get_iface (NM_DEVICE (self))); nm_ap_update_from_properties (ap, object_path, properties); - - /* Remove outdated access points */ - schedule_scanlist_cull (self); + schedule_ap_list_dump (self); + } } static void @@ -1693,27 +1592,19 @@ supplicant_iface_bss_removed_cb (NMSupplicantInterface *iface, const char *object_path, NMDeviceWifi *self) { + NMDeviceWifiPrivate *priv; NMAccessPoint *ap; g_return_if_fail (self != NULL); g_return_if_fail (object_path != NULL); + priv = NM_DEVICE_WIFI_GET_PRIVATE (self); ap = get_ap_by_supplicant_path (self, object_path); - if (ap) { - gint32 now = nm_utils_get_monotonic_timestamp_s (); - gint32 last_seen = nm_ap_get_last_seen (ap); - - /* We don't know when the supplicant last saw the AP's beacons, - * it could be two minutes or it could be 2 seconds. Because the - * supplicant doesn't send property change notifications if the - * AP's other properties don't change, our last-seen time may be - * much older the supplicant's, and the AP would be immediately - * removed from the list on the next cleanup. So update the - * last-seen time to ensure the AP sticks around for at least - * one more periodic scan. - */ - nm_ap_set_last_seen (ap, MAX (last_seen, now - SCAN_INTERVAL_MAX)); - g_object_set_data (G_OBJECT (ap), WPAS_REMOVED_TAG, GUINT_TO_POINTER (TRUE)); + if (ap && ap != priv->current_ap) { + nm_ap_dump (ap, "removed ", nm_device_get_iface (NM_DEVICE (self))); + emit_ap_added_removed (self, ACCESS_POINT_REMOVED, ap, TRUE); + g_hash_table_remove (priv->aps, nm_ap_get_dbus_path (ap)); + schedule_ap_list_dump (self); } } diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index 1867583a0..5068e66e9 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -1219,66 +1219,3 @@ nm_ap_complete_connection (NMAccessPoint *self, error); } -NMAccessPoint * -nm_ap_match_in_hash (NMAccessPoint *find_ap, GHashTable *hash) -{ - GHashTableIter iter; - NMAccessPoint *list_ap, *band_match = NULL; - - g_return_val_if_fail (find_ap != NULL, NULL); - - g_hash_table_iter_init (&iter, hash); - while (g_hash_table_iter_next (&iter, NULL, (gpointer) &list_ap)) { - const GByteArray * list_ssid = nm_ap_get_ssid (list_ap); - const char * list_addr = nm_ap_get_address (list_ap); - const guint32 list_freq = nm_ap_get_freq (list_ap); - - const GByteArray * find_ssid = nm_ap_get_ssid (find_ap); - const char * find_addr = nm_ap_get_address (find_ap); - const guint32 find_freq = nm_ap_get_freq (find_ap); - - /* SSID match; if both APs are hiding their SSIDs, - * let matching continue on BSSID and other properties - */ - if ( (!list_ssid && find_ssid) - || (list_ssid && !find_ssid)) - continue; - if ( list_ssid - && find_ssid - && !nm_utils_same_ssid (list_ssid->data, list_ssid->len, - find_ssid->data, find_ssid->len, - TRUE)) - continue; - - /* BSSID match */ - if ( nm_ethernet_address_is_valid (list_addr, -1) - && !nm_utils_hwaddr_matches (list_addr, -1, find_addr, -1)) - continue; - - /* mode match */ - if (nm_ap_get_mode (list_ap) != nm_ap_get_mode (find_ap)) - continue; - - /* AP flags */ - if (nm_ap_get_flags (list_ap) != nm_ap_get_flags (find_ap)) - continue; - - if (nm_ap_get_wpa_flags (list_ap) != nm_ap_get_wpa_flags (find_ap)) - continue; - - if (nm_ap_get_rsn_flags (list_ap) != nm_ap_get_rsn_flags (find_ap)) - continue; - - if (list_freq != find_freq) { - /* Must be last check to ensure all other properties match */ - if (freq_to_band (list_freq) == freq_to_band (find_freq)) - band_match = list_ap; - continue; - } - - return list_ap; - } - - return band_match; -} - diff --git a/src/devices/wifi/nm-wifi-ap.h b/src/devices/wifi/nm-wifi-ap.h index cbea3e307..f316a7ae1 100644 --- a/src/devices/wifi/nm-wifi-ap.h +++ b/src/devices/wifi/nm-wifi-ap.h @@ -116,8 +116,6 @@ gboolean nm_ap_complete_connection (NMAccessPoint *self, gboolean lock_bssid, GError **error); -NMAccessPoint * nm_ap_match_in_hash (NMAccessPoint *find_ap, GHashTable *hash); - void nm_ap_dump (NMAccessPoint *self, const char *prefix, const char *ifname); diff --git a/src/supplicant-manager/nm-supplicant-interface.c b/src/supplicant-manager/nm-supplicant-interface.c index 9c044308b..4731ad7d7 100644 --- a/src/supplicant-manager/nm-supplicant-interface.c +++ b/src/supplicant-manager/nm-supplicant-interface.c @@ -645,6 +645,30 @@ on_iface_proxy_acquired (GDBusProxy *proxy, GAsyncResult *result, gpointer user_ _nm_dbus_signal_connect (priv->iface_proxy, "NetworkRequest", G_VARIANT_TYPE ("(oss)"), G_CALLBACK (wpas_iface_network_request), self); + /* Scan result aging parameters */ + g_dbus_proxy_call (priv->iface_proxy, + "org.freedesktop.DBus.Properties.Set", + g_variant_new ("(ssv)", + WPAS_DBUS_IFACE_INTERFACE, + "BSSExpireAge", + g_variant_new_uint32 (250)), + G_DBUS_CALL_FLAGS_NONE, + -1, + priv->init_cancellable, + NULL, + NULL); + g_dbus_proxy_call (priv->iface_proxy, + "org.freedesktop.DBus.Properties.Set", + g_variant_new ("(ssv)", + WPAS_DBUS_IFACE_INTERFACE, + "BSSExpireCount", + g_variant_new_uint32 (2)), + G_DBUS_CALL_FLAGS_NONE, + -1, + priv->init_cancellable, + NULL, + NULL); + /* Check whether NetworkReply and AP mode are supported */ priv->ready_count = 1; g_dbus_proxy_call (priv->iface_proxy, From e482f853f65d7959e2856d386d1fc55fe999bdf9 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 20 Apr 2015 10:18:32 -0500 Subject: [PATCH 04/11] wifi: remove supplicant-forgotten current AP from list on disconnect NM never removes the current AP from the AP list, to prevent NM from indicating that it's connected, but to nothing. But the supplicant can remove that AP from its list at any time (out of range, turned off, etc), leading to a priv->current_ap that is no longer known to the supplicant but still exists in the NM AP list. Since the supplicant has forgotten it, NM will never receive a removal signal for it. To ensure that a supplicant-forgotten priv->current_ap is removed from the NM AP list when priv->current_ap is cleared or changed, mark any AP removed by the supplicant as 'fake'. It will then always be removed in set_current_ap() and not linger in the AP list forever like a zombie. --- src/devices/wifi/nm-device-wifi.c | 19 ++++++++++++++----- src/devices/wifi/nm-wifi-ap.c | 3 +++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 1922f9424..cc4db6662 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -1600,11 +1600,20 @@ supplicant_iface_bss_removed_cb (NMSupplicantInterface *iface, priv = NM_DEVICE_WIFI_GET_PRIVATE (self); ap = get_ap_by_supplicant_path (self, object_path); - if (ap && ap != priv->current_ap) { - nm_ap_dump (ap, "removed ", nm_device_get_iface (NM_DEVICE (self))); - emit_ap_added_removed (self, ACCESS_POINT_REMOVED, ap, TRUE); - g_hash_table_remove (priv->aps, nm_ap_get_dbus_path (ap)); - schedule_ap_list_dump (self); + if (ap) { + if (ap == priv->current_ap) { + /* The current AP cannot be removed (to prevent NM indicating that + * it is connected, but to nothing), but it must be removed later + * when the current AP is changed or cleared. Set 'fake' to + * indicate that this AP is now unknown to the supplicant. + */ + nm_ap_set_fake (ap, TRUE); + } else { + nm_ap_dump (ap, "removed ", nm_device_get_iface (NM_DEVICE (self))); + emit_ap_added_removed (self, ACCESS_POINT_REMOVED, ap, TRUE); + g_hash_table_remove (priv->aps, nm_ap_get_dbus_path (ap)); + schedule_ap_list_dump (self); + } } } diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index 5068e66e9..c4dad39a2 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -388,6 +388,7 @@ nm_ap_update_from_properties (NMAccessPoint *ap, const char *supplicant_path, GVariant *properties) { + NMAccessPointPrivate *priv; char *addr; const guint8 *bytes; GVariant *v; @@ -399,6 +400,7 @@ nm_ap_update_from_properties (NMAccessPoint *ap, g_return_if_fail (ap != NULL); g_return_if_fail (properties != NULL); + priv = NM_AP_GET_PRIVATE (ap); g_object_freeze_notify (G_OBJECT (ap)); @@ -475,6 +477,7 @@ nm_ap_update_from_properties (NMAccessPoint *ap, nm_ap_set_supplicant_path (ap, supplicant_path); nm_ap_set_last_seen (ap, nm_utils_get_monotonic_timestamp_s ()); + priv->fake = FALSE; g_object_thaw_notify (G_OBJECT (ap)); } From ea9ae4cd76db9d2191bf1d06485af9901a73e52d Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 20 Apr 2015 10:38:34 -0500 Subject: [PATCH 05/11] wifi: move NMAccessPoint GObject stuff to the bottom --- src/devices/wifi/nm-wifi-ap.c | 519 +++++++++++++++++----------------- 1 file changed, 256 insertions(+), 263 deletions(-) diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index c4dad39a2..b4a04719a 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -84,266 +84,7 @@ enum { LAST_PROP }; -static void -nm_ap_init (NMAccessPoint *ap) -{ - NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (ap); - - priv->dbus_path = NULL; - priv->mode = NM_802_11_MODE_INFRA; - priv->flags = NM_802_11_AP_FLAGS_NONE; - priv->wpa_flags = NM_802_11_AP_SEC_NONE; - priv->rsn_flags = NM_802_11_AP_SEC_NONE; -} - -static void -finalize (GObject *object) -{ - NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (object); - - g_free (priv->dbus_path); - g_free (priv->supplicant_path); - if (priv->ssid) - g_byte_array_free (priv->ssid, TRUE); - g_free (priv->address); - - G_OBJECT_CLASS (nm_ap_parent_class)->finalize (object); -} - -static void -set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) -{ - NMAccessPoint *ap = NM_AP (object); - GByteArray *ssid; - - switch (prop_id) { - case PROP_FLAGS: - nm_ap_set_flags (ap, g_value_get_uint (value)); - break; - case PROP_WPA_FLAGS: - nm_ap_set_wpa_flags (ap, g_value_get_uint (value)); - break; - case PROP_RSN_FLAGS: - nm_ap_set_rsn_flags (ap, g_value_get_uint (value)); - break; - case PROP_SSID: - ssid = g_value_get_boxed (value); - if (ssid) - nm_ap_set_ssid (ap, ssid->data, ssid->len); - else - nm_ap_set_ssid (ap, NULL, 0); - break; - case PROP_FREQUENCY: - nm_ap_set_freq (ap, g_value_get_uint (value)); - break; - case PROP_MODE: - nm_ap_set_mode (ap, g_value_get_uint (value)); - break; - case PROP_MAX_BITRATE: - nm_ap_set_max_bitrate (ap, g_value_get_uint (value)); - break; - case PROP_STRENGTH: - nm_ap_set_strength (ap, g_value_get_schar (value)); - break; - case PROP_HW_ADDRESS: - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (object); - GArray * ssid; - int len; - int i; - - switch (prop_id) { - case PROP_FLAGS: - g_value_set_uint (value, priv->flags); - break; - case PROP_WPA_FLAGS: - g_value_set_uint (value, priv->wpa_flags); - break; - case PROP_RSN_FLAGS: - g_value_set_uint (value, priv->rsn_flags); - break; - case PROP_SSID: - len = priv->ssid ? priv->ssid->len : 0; - ssid = g_array_sized_new (FALSE, TRUE, sizeof (unsigned char), len); - for (i = 0; i < len; i++) - g_array_append_val (ssid, priv->ssid->data[i]); - g_value_set_boxed (value, ssid); - g_array_free (ssid, TRUE); - break; - case PROP_FREQUENCY: - g_value_set_uint (value, priv->freq); - break; - case PROP_HW_ADDRESS: - g_value_set_string (value, priv->address); - break; - case PROP_MODE: - g_value_set_uint (value, priv->mode); - break; - case PROP_MAX_BITRATE: - g_value_set_uint (value, priv->max_bitrate); - break; - case PROP_STRENGTH: - g_value_set_schar (value, priv->strength); - break; - case PROP_LAST_SEEN: - g_value_set_int (value, - priv->last_seen > 0 - ? (gint) nm_utils_monotonic_timestamp_as_boottime (priv->last_seen, NM_UTILS_NS_PER_SECOND) - : -1); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -nm_ap_class_init (NMAccessPointClass *ap_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (ap_class); - const NM80211ApSecurityFlags all_sec_flags = NM_802_11_AP_SEC_NONE - | NM_802_11_AP_SEC_PAIR_WEP40 - | NM_802_11_AP_SEC_PAIR_WEP104 - | NM_802_11_AP_SEC_PAIR_TKIP - | NM_802_11_AP_SEC_PAIR_CCMP - | NM_802_11_AP_SEC_GROUP_WEP40 - | NM_802_11_AP_SEC_GROUP_WEP104 - | NM_802_11_AP_SEC_GROUP_TKIP - | NM_802_11_AP_SEC_GROUP_CCMP - | NM_802_11_AP_SEC_KEY_MGMT_PSK - | NM_802_11_AP_SEC_KEY_MGMT_802_1X; - - g_type_class_add_private (ap_class, sizeof (NMAccessPointPrivate)); - - /* virtual methods */ - object_class->set_property = set_property; - object_class->get_property = get_property; - object_class->finalize = finalize; - - /* properties */ - g_object_class_install_property - (object_class, PROP_FLAGS, - g_param_spec_uint (NM_AP_FLAGS, "", "", - NM_802_11_AP_FLAGS_NONE, - NM_802_11_AP_FLAGS_PRIVACY, - NM_802_11_AP_FLAGS_NONE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property - (object_class, PROP_WPA_FLAGS, - g_param_spec_uint (NM_AP_WPA_FLAGS, "", "", - NM_802_11_AP_SEC_NONE, - all_sec_flags, - NM_802_11_AP_SEC_NONE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property - (object_class, PROP_RSN_FLAGS, - g_param_spec_uint (NM_AP_RSN_FLAGS, "", "", - NM_802_11_AP_SEC_NONE, - all_sec_flags, - NM_802_11_AP_SEC_NONE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property - (object_class, PROP_SSID, - g_param_spec_boxed (NM_AP_SSID, "", "", - DBUS_TYPE_G_UCHAR_ARRAY, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property - (object_class, PROP_FREQUENCY, - g_param_spec_uint (NM_AP_FREQUENCY, "", "", - 0, 10000, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_AP_HW_ADDRESS, "", "", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property - (object_class, PROP_MODE, - g_param_spec_uint (NM_AP_MODE, "", "", - NM_802_11_MODE_ADHOC, NM_802_11_MODE_INFRA, NM_802_11_MODE_INFRA, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property - (object_class, PROP_MAX_BITRATE, - g_param_spec_uint (NM_AP_MAX_BITRATE, "", "", - 0, G_MAXUINT16, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property - (object_class, PROP_STRENGTH, - g_param_spec_char (NM_AP_STRENGTH, "", "", - G_MININT8, G_MAXINT8, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property - (object_class, PROP_LAST_SEEN, - g_param_spec_int (NM_AP_LAST_SEEN, "", "", - -1, G_MAXINT, -1, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (ap_class), - &dbus_glib_nm_access_point_object_info); -} - -void -nm_ap_export_to_dbus (NMAccessPoint *ap) -{ - NMAccessPointPrivate *priv; - static guint32 counter = 0; - - g_return_if_fail (NM_IS_AP (ap)); - - priv = NM_AP_GET_PRIVATE (ap); - - if (priv->dbus_path) { - nm_log_err (LOGD_CORE, "Tried to export AP %s twice.", priv->dbus_path); - return; - } - - priv->id = counter++; - priv->dbus_path = g_strdup_printf (NM_DBUS_PATH_ACCESS_POINT "/%d", priv->id); - nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->dbus_path, ap); -} - -/* - * nm_ap_new - * - * Create a new, blank user access point info structure - * - */ -static NMAccessPoint * -nm_ap_new (void) -{ - return (NMAccessPoint *) g_object_new (NM_TYPE_AP, NULL); -} +/*****************************************************************/ static NM80211ApSecurityFlags security_from_vardict (GVariant *security) @@ -493,8 +234,7 @@ nm_ap_new_from_properties (const char *supplicant_path, GVariant *properties) g_return_val_if_fail (supplicant_path != NULL, NULL); g_return_val_if_fail (properties != NULL, NULL); - ap = nm_ap_new (); - + ap = (NMAccessPoint *) g_object_new (NM_TYPE_AP, NULL); nm_ap_update_from_properties (ap, supplicant_path, properties); /* ignore APs with invalid BSSIDs */ @@ -606,7 +346,7 @@ nm_ap_new_fake_from_connection (NMConnection *connection) g_return_val_if_fail (ssid != NULL, NULL); g_return_val_if_fail (g_bytes_get_size (ssid) > 0, NULL); - ap = nm_ap_new (); + ap = (NMAccessPoint *) g_object_new (NM_TYPE_AP, NULL); nm_ap_set_fake (ap, TRUE); nm_ap_set_ssid (ap, g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); @@ -1222,3 +962,256 @@ nm_ap_complete_connection (NMAccessPoint *self, error); } +/*****************************************************************/ + +void +nm_ap_export_to_dbus (NMAccessPoint *ap) +{ + NMAccessPointPrivate *priv; + static guint32 counter = 0; + + g_return_if_fail (NM_IS_AP (ap)); + + priv = NM_AP_GET_PRIVATE (ap); + + if (priv->dbus_path) { + nm_log_err (LOGD_CORE, "Tried to export AP %s twice.", priv->dbus_path); + return; + } + + priv->id = counter++; + priv->dbus_path = g_strdup_printf (NM_DBUS_PATH_ACCESS_POINT "/%d", priv->id); + nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->dbus_path, ap); +} + +static void +nm_ap_init (NMAccessPoint *ap) +{ + NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (ap); + + priv->dbus_path = NULL; + priv->mode = NM_802_11_MODE_INFRA; + priv->flags = NM_802_11_AP_FLAGS_NONE; + priv->wpa_flags = NM_802_11_AP_SEC_NONE; + priv->rsn_flags = NM_802_11_AP_SEC_NONE; +} + +static void +finalize (GObject *object) +{ + NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (object); + + g_free (priv->dbus_path); + g_free (priv->supplicant_path); + if (priv->ssid) + g_byte_array_free (priv->ssid, TRUE); + g_free (priv->address); + + G_OBJECT_CLASS (nm_ap_parent_class)->finalize (object); +} + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + NMAccessPoint *ap = NM_AP (object); + GByteArray *ssid; + + switch (prop_id) { + case PROP_FLAGS: + nm_ap_set_flags (ap, g_value_get_uint (value)); + break; + case PROP_WPA_FLAGS: + nm_ap_set_wpa_flags (ap, g_value_get_uint (value)); + break; + case PROP_RSN_FLAGS: + nm_ap_set_rsn_flags (ap, g_value_get_uint (value)); + break; + case PROP_SSID: + ssid = g_value_get_boxed (value); + if (ssid) + nm_ap_set_ssid (ap, ssid->data, ssid->len); + else + nm_ap_set_ssid (ap, NULL, 0); + break; + case PROP_FREQUENCY: + nm_ap_set_freq (ap, g_value_get_uint (value)); + break; + case PROP_MODE: + nm_ap_set_mode (ap, g_value_get_uint (value)); + break; + case PROP_MAX_BITRATE: + nm_ap_set_max_bitrate (ap, g_value_get_uint (value)); + break; + case PROP_STRENGTH: + nm_ap_set_strength (ap, g_value_get_schar (value)); + break; + case PROP_HW_ADDRESS: + break; + case PROP_LAST_SEEN: + nm_ap_set_last_seen (ap, g_value_get_int (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (object); + GArray * ssid; + int len; + int i; + + switch (prop_id) { + case PROP_FLAGS: + g_value_set_uint (value, priv->flags); + break; + case PROP_WPA_FLAGS: + g_value_set_uint (value, priv->wpa_flags); + break; + case PROP_RSN_FLAGS: + g_value_set_uint (value, priv->rsn_flags); + break; + case PROP_SSID: + len = priv->ssid ? priv->ssid->len : 0; + ssid = g_array_sized_new (FALSE, TRUE, sizeof (unsigned char), len); + for (i = 0; i < len; i++) + g_array_append_val (ssid, priv->ssid->data[i]); + g_value_set_boxed (value, ssid); + g_array_free (ssid, TRUE); + break; + case PROP_FREQUENCY: + g_value_set_uint (value, priv->freq); + break; + case PROP_HW_ADDRESS: + g_value_set_string (value, priv->address); + break; + case PROP_MODE: + g_value_set_uint (value, priv->mode); + break; + case PROP_MAX_BITRATE: + g_value_set_uint (value, priv->max_bitrate); + break; + case PROP_STRENGTH: + g_value_set_schar (value, priv->strength); + break; + case PROP_LAST_SEEN: + g_value_set_int (value, + priv->last_seen > 0 + ? (gint) nm_utils_monotonic_timestamp_as_boottime (priv->last_seen, NM_UTILS_NS_PER_SECOND) + : -1); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +nm_ap_class_init (NMAccessPointClass *ap_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (ap_class); + const NM80211ApSecurityFlags all_sec_flags = NM_802_11_AP_SEC_NONE + | NM_802_11_AP_SEC_PAIR_WEP40 + | NM_802_11_AP_SEC_PAIR_WEP104 + | NM_802_11_AP_SEC_PAIR_TKIP + | NM_802_11_AP_SEC_PAIR_CCMP + | NM_802_11_AP_SEC_GROUP_WEP40 + | NM_802_11_AP_SEC_GROUP_WEP104 + | NM_802_11_AP_SEC_GROUP_TKIP + | NM_802_11_AP_SEC_GROUP_CCMP + | NM_802_11_AP_SEC_KEY_MGMT_PSK + | NM_802_11_AP_SEC_KEY_MGMT_802_1X; + + g_type_class_add_private (ap_class, sizeof (NMAccessPointPrivate)); + + /* virtual methods */ + object_class->set_property = set_property; + object_class->get_property = get_property; + object_class->finalize = finalize; + + /* properties */ + g_object_class_install_property + (object_class, PROP_FLAGS, + g_param_spec_uint (NM_AP_FLAGS, "", "", + NM_802_11_AP_FLAGS_NONE, + NM_802_11_AP_FLAGS_PRIVACY, + NM_802_11_AP_FLAGS_NONE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_WPA_FLAGS, + g_param_spec_uint (NM_AP_WPA_FLAGS, "", "", + NM_802_11_AP_SEC_NONE, + all_sec_flags, + NM_802_11_AP_SEC_NONE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_RSN_FLAGS, + g_param_spec_uint (NM_AP_RSN_FLAGS, "", "", + NM_802_11_AP_SEC_NONE, + all_sec_flags, + NM_802_11_AP_SEC_NONE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_SSID, + g_param_spec_boxed (NM_AP_SSID, "", "", + DBUS_TYPE_G_UCHAR_ARRAY, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_FREQUENCY, + g_param_spec_uint (NM_AP_FREQUENCY, "", "", + 0, 10000, 0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_HW_ADDRESS, + g_param_spec_string (NM_AP_HW_ADDRESS, "", "", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_MODE, + g_param_spec_uint (NM_AP_MODE, "", "", + NM_802_11_MODE_ADHOC, NM_802_11_MODE_INFRA, NM_802_11_MODE_INFRA, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_MAX_BITRATE, + g_param_spec_uint (NM_AP_MAX_BITRATE, "", "", + 0, G_MAXUINT16, 0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_STRENGTH, + g_param_spec_char (NM_AP_STRENGTH, "", "", + G_MININT8, G_MAXINT8, 0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_LAST_SEEN, + g_param_spec_int (NM_AP_LAST_SEEN, "", "", + -1, G_MAXINT, -1, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), + G_TYPE_FROM_CLASS (ap_class), + &dbus_glib_nm_access_point_object_info); +} + From 13c77b09eb293696c7a4a68241bb9d0f89df3eb5 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 20 Apr 2015 10:42:10 -0500 Subject: [PATCH 06/11] wifi: move NMAccessPoint getters/setters to top Allows us to remove some no longer used prototypes from the headers. Remove some pointless comments at the same time. --- src/devices/wifi/nm-wifi-ap.c | 681 ++++++++++++++++------------------ 1 file changed, 327 insertions(+), 354 deletions(-) diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index b4a04719a..4338ff8c9 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -84,6 +84,333 @@ enum { LAST_PROP }; +/*****************************************************************/ + +const char * +nm_ap_get_supplicant_path (NMAccessPoint *ap) +{ + g_return_val_if_fail (NM_IS_AP (ap), NULL); + + return NM_AP_GET_PRIVATE (ap)->supplicant_path; +} + +void +nm_ap_set_supplicant_path (NMAccessPoint *ap, const char *path) +{ + g_return_if_fail (NM_IS_AP (ap)); + g_return_if_fail (path != NULL); + + g_free (NM_AP_GET_PRIVATE (ap)->supplicant_path); + NM_AP_GET_PRIVATE (ap)->supplicant_path = g_strdup (path); +} + +const char * +nm_ap_get_dbus_path (NMAccessPoint *ap) +{ + g_return_val_if_fail (NM_IS_AP (ap), NULL); + + return NM_AP_GET_PRIVATE (ap)->dbus_path; +} + +guint32 +nm_ap_get_id (NMAccessPoint *ap) +{ + g_return_val_if_fail (NM_IS_AP (ap), 0); + + return NM_AP_GET_PRIVATE (ap)->id; +} + +const GByteArray * nm_ap_get_ssid (const NMAccessPoint *ap) +{ + g_return_val_if_fail (NM_IS_AP (ap), NULL); + + return NM_AP_GET_PRIVATE (ap)->ssid; +} + +void +nm_ap_set_ssid (NMAccessPoint *ap, const guint8 *ssid, gsize len) +{ + NMAccessPointPrivate *priv; + + g_return_if_fail (NM_IS_AP (ap)); + g_return_if_fail (ssid == NULL || len > 0); + + priv = NM_AP_GET_PRIVATE (ap); + + /* same SSID */ + if ((ssid && priv->ssid) && (len == priv->ssid->len)) { + if (!memcmp (ssid, priv->ssid->data, len)) + return; + } + + if (priv->ssid) { + g_byte_array_free (priv->ssid, TRUE); + priv->ssid = NULL; + } + + if (ssid) { + priv->ssid = g_byte_array_new (); + g_byte_array_append (priv->ssid, ssid, len); + } + + g_object_notify (G_OBJECT (ap), NM_AP_SSID); +} + +NM80211ApFlags +nm_ap_get_flags (NMAccessPoint *ap) +{ + g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_AP_FLAGS_NONE); + + return NM_AP_GET_PRIVATE (ap)->flags; +} + + +void +nm_ap_set_flags (NMAccessPoint *ap, NM80211ApFlags flags) +{ + NMAccessPointPrivate *priv; + + g_return_if_fail (NM_IS_AP (ap)); + + priv = NM_AP_GET_PRIVATE (ap); + + if (priv->flags != flags) { + priv->flags = flags; + g_object_notify (G_OBJECT (ap), NM_AP_FLAGS); + } +} + +NM80211ApSecurityFlags +nm_ap_get_wpa_flags (NMAccessPoint *ap) +{ + g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_AP_SEC_NONE); + + return NM_AP_GET_PRIVATE (ap)->wpa_flags; +} + + +void +nm_ap_set_wpa_flags (NMAccessPoint *ap, NM80211ApSecurityFlags flags) +{ + NMAccessPointPrivate *priv; + + g_return_if_fail (NM_IS_AP (ap)); + + priv = NM_AP_GET_PRIVATE (ap); + if (priv->wpa_flags != flags) { + priv->wpa_flags = flags; + g_object_notify (G_OBJECT (ap), NM_AP_WPA_FLAGS); + } +} + +NM80211ApSecurityFlags +nm_ap_get_rsn_flags (NMAccessPoint *ap) +{ + g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_AP_SEC_NONE); + + return NM_AP_GET_PRIVATE (ap)->rsn_flags; +} + + +void +nm_ap_set_rsn_flags (NMAccessPoint *ap, NM80211ApSecurityFlags flags) +{ + NMAccessPointPrivate *priv; + + g_return_if_fail (NM_IS_AP (ap)); + + priv = NM_AP_GET_PRIVATE (ap); + if (priv->rsn_flags != flags) { + priv->rsn_flags = flags; + g_object_notify (G_OBJECT (ap), NM_AP_RSN_FLAGS); + } +} + +const char * +nm_ap_get_address (const NMAccessPoint *ap) +{ + g_return_val_if_fail (NM_IS_AP (ap), NULL); + + return NM_AP_GET_PRIVATE (ap)->address; +} + +void +nm_ap_set_address (NMAccessPoint *ap, const char *addr) +{ + NMAccessPointPrivate *priv; + + g_return_if_fail (NM_IS_AP (ap)); + g_return_if_fail (addr != NULL); + g_return_if_fail (nm_utils_hwaddr_valid (addr, ETH_ALEN)); + + priv = NM_AP_GET_PRIVATE (ap); + + if (!priv->address || !nm_utils_hwaddr_matches (addr, -1, priv->address, -1)) { + g_free (priv->address); + priv->address = g_strdup (addr); + g_object_notify (G_OBJECT (ap), NM_AP_HW_ADDRESS); + } +} + +NM80211Mode +nm_ap_get_mode (NMAccessPoint *ap) +{ + NM80211Mode mode; + + g_return_val_if_fail (NM_IS_AP (ap), -1); + + g_object_get (ap, NM_AP_MODE, &mode, NULL); + + return mode; +} + +void +nm_ap_set_mode (NMAccessPoint *ap, const NM80211Mode mode) +{ + NMAccessPointPrivate *priv; + + g_return_if_fail (NM_IS_AP (ap)); + g_return_if_fail ( mode == NM_802_11_MODE_ADHOC + || mode == NM_802_11_MODE_INFRA); + + priv = NM_AP_GET_PRIVATE (ap); + + if (priv->mode != mode) { + priv->mode = mode; + g_object_notify (G_OBJECT (ap), NM_AP_MODE); + } +} + +gboolean +nm_ap_is_hotspot (NMAccessPoint *ap) +{ + g_return_val_if_fail (NM_IS_AP (ap), FALSE); + + return NM_AP_GET_PRIVATE (ap)->hotspot; +} + +gint8 +nm_ap_get_strength (NMAccessPoint *ap) +{ + gint8 strength; + + g_return_val_if_fail (NM_IS_AP (ap), 0); + + g_object_get (ap, NM_AP_STRENGTH, &strength, NULL); + + return strength; +} + +void +nm_ap_set_strength (NMAccessPoint *ap, const gint8 strength) +{ + NMAccessPointPrivate *priv; + + g_return_if_fail (NM_IS_AP (ap)); + + priv = NM_AP_GET_PRIVATE (ap); + + if (priv->strength != strength) { + priv->strength = strength; + g_object_notify (G_OBJECT (ap), NM_AP_STRENGTH); + } +} + +guint32 +nm_ap_get_freq (NMAccessPoint *ap) +{ + guint32 freq; + + g_return_val_if_fail (NM_IS_AP (ap), 0); + + g_object_get (ap, NM_AP_FREQUENCY, &freq, NULL); + + return freq; +} + +void +nm_ap_set_freq (NMAccessPoint *ap, + const guint32 freq) +{ + NMAccessPointPrivate *priv; + + g_return_if_fail (NM_IS_AP (ap)); + + priv = NM_AP_GET_PRIVATE (ap); + + if (priv->freq != freq) { + priv->freq = freq; + g_object_notify (G_OBJECT (ap), NM_AP_FREQUENCY); + } +} + +guint32 +nm_ap_get_max_bitrate (NMAccessPoint *ap) +{ + guint32 rate; + + g_return_val_if_fail (NM_IS_AP (ap), 0); + + g_object_get (ap, NM_AP_MAX_BITRATE, &rate, NULL); + + return rate; +} + +void +nm_ap_set_max_bitrate (NMAccessPoint *ap, guint32 bitrate) +{ + NMAccessPointPrivate *priv; + + g_return_if_fail (NM_IS_AP (ap)); + + priv = NM_AP_GET_PRIVATE (ap); + + if (priv->max_bitrate != bitrate) { + priv->max_bitrate = bitrate; + g_object_notify (G_OBJECT (ap), NM_AP_MAX_BITRATE); + } +} + +gboolean +nm_ap_get_fake (const NMAccessPoint *ap) +{ + g_return_val_if_fail (NM_IS_AP (ap), FALSE); + + return NM_AP_GET_PRIVATE (ap)->fake; +} + +void +nm_ap_set_fake (NMAccessPoint *ap, gboolean fake) +{ + g_return_if_fail (NM_IS_AP (ap)); + + NM_AP_GET_PRIVATE (ap)->fake = fake; +} + +gint32 +nm_ap_get_last_seen (const NMAccessPoint *ap) +{ + g_return_val_if_fail (NM_IS_AP (ap), FALSE); + + return NM_AP_GET_PRIVATE (ap)->last_seen; +} + +void +nm_ap_set_last_seen (NMAccessPoint *ap, gint32 last_seen) +{ + NMAccessPointPrivate *priv; + + g_return_if_fail (NM_IS_AP (ap)); + + priv = NM_AP_GET_PRIVATE (ap); + + if (priv->last_seen != last_seen) { + priv->last_seen = last_seen; + g_object_notify (G_OBJECT (ap), NM_AP_LAST_SEEN); + } +} + + /*****************************************************************/ static NM80211ApSecurityFlags @@ -501,360 +828,6 @@ nm_ap_dump (NMAccessPoint *self, supplicant_id); } -const char * -nm_ap_get_dbus_path (NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), NULL); - - return NM_AP_GET_PRIVATE (ap)->dbus_path; -} - -const char * -nm_ap_get_supplicant_path (NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), NULL); - - return NM_AP_GET_PRIVATE (ap)->supplicant_path; -} - -guint32 -nm_ap_get_id (NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), 0); - - return NM_AP_GET_PRIVATE (ap)->id; -} - -void -nm_ap_set_supplicant_path (NMAccessPoint *ap, const char *path) -{ - g_return_if_fail (NM_IS_AP (ap)); - g_return_if_fail (path != NULL); - - g_free (NM_AP_GET_PRIVATE (ap)->supplicant_path); - NM_AP_GET_PRIVATE (ap)->supplicant_path = g_strdup (path); -} - -/* - * Get/set functions for ssid - * - */ -const GByteArray * nm_ap_get_ssid (const NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), NULL); - - return NM_AP_GET_PRIVATE (ap)->ssid; -} - -void -nm_ap_set_ssid (NMAccessPoint *ap, const guint8 *ssid, gsize len) -{ - NMAccessPointPrivate *priv; - - g_return_if_fail (NM_IS_AP (ap)); - g_return_if_fail (ssid == NULL || len > 0); - - priv = NM_AP_GET_PRIVATE (ap); - - /* same SSID */ - if ((ssid && priv->ssid) && (len == priv->ssid->len)) { - if (!memcmp (ssid, priv->ssid->data, len)) - return; - } - - if (priv->ssid) { - g_byte_array_free (priv->ssid, TRUE); - priv->ssid = NULL; - } - - if (ssid) { - priv->ssid = g_byte_array_new (); - g_byte_array_append (priv->ssid, ssid, len); - } - - g_object_notify (G_OBJECT (ap), NM_AP_SSID); -} - - -NM80211ApFlags -nm_ap_get_flags (NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_AP_FLAGS_NONE); - - return NM_AP_GET_PRIVATE (ap)->flags; -} - - -void -nm_ap_set_flags (NMAccessPoint *ap, NM80211ApFlags flags) -{ - NMAccessPointPrivate *priv; - - g_return_if_fail (NM_IS_AP (ap)); - - priv = NM_AP_GET_PRIVATE (ap); - - if (priv->flags != flags) { - priv->flags = flags; - g_object_notify (G_OBJECT (ap), NM_AP_FLAGS); - } -} - -NM80211ApSecurityFlags -nm_ap_get_wpa_flags (NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_AP_SEC_NONE); - - return NM_AP_GET_PRIVATE (ap)->wpa_flags; -} - - -void -nm_ap_set_wpa_flags (NMAccessPoint *ap, NM80211ApSecurityFlags flags) -{ - NMAccessPointPrivate *priv; - - g_return_if_fail (NM_IS_AP (ap)); - - priv = NM_AP_GET_PRIVATE (ap); - if (priv->wpa_flags != flags) { - priv->wpa_flags = flags; - g_object_notify (G_OBJECT (ap), NM_AP_WPA_FLAGS); - } -} - -NM80211ApSecurityFlags -nm_ap_get_rsn_flags (NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_AP_SEC_NONE); - - return NM_AP_GET_PRIVATE (ap)->rsn_flags; -} - - -void -nm_ap_set_rsn_flags (NMAccessPoint *ap, NM80211ApSecurityFlags flags) -{ - NMAccessPointPrivate *priv; - - g_return_if_fail (NM_IS_AP (ap)); - - priv = NM_AP_GET_PRIVATE (ap); - if (priv->rsn_flags != flags) { - priv->rsn_flags = flags; - g_object_notify (G_OBJECT (ap), NM_AP_RSN_FLAGS); - } -} - -/* - * Get/set functions for address - * - */ -const char * -nm_ap_get_address (const NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), NULL); - - return NM_AP_GET_PRIVATE (ap)->address; -} - -void -nm_ap_set_address (NMAccessPoint *ap, const char *addr) -{ - NMAccessPointPrivate *priv; - - g_return_if_fail (NM_IS_AP (ap)); - g_return_if_fail (addr != NULL); - g_return_if_fail (nm_utils_hwaddr_valid (addr, ETH_ALEN)); - - priv = NM_AP_GET_PRIVATE (ap); - - if (!priv->address || !nm_utils_hwaddr_matches (addr, -1, priv->address, -1)) { - g_free (priv->address); - priv->address = g_strdup (addr); - g_object_notify (G_OBJECT (ap), NM_AP_HW_ADDRESS); - } -} - - -/* - * Get/set functions for mode (ie Ad-Hoc, Infrastructure, etc) - * - */ -NM80211Mode nm_ap_get_mode (NMAccessPoint *ap) -{ - NM80211Mode mode; - - g_return_val_if_fail (NM_IS_AP (ap), -1); - - g_object_get (ap, NM_AP_MODE, &mode, NULL); - - return mode; -} - -void nm_ap_set_mode (NMAccessPoint *ap, const NM80211Mode mode) -{ - NMAccessPointPrivate *priv; - - g_return_if_fail (NM_IS_AP (ap)); - g_return_if_fail ( mode == NM_802_11_MODE_ADHOC - || mode == NM_802_11_MODE_INFRA); - - priv = NM_AP_GET_PRIVATE (ap); - - if (priv->mode != mode) { - priv->mode = mode; - g_object_notify (G_OBJECT (ap), NM_AP_MODE); - } -} - -gboolean -nm_ap_is_hotspot (NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), FALSE); - - return NM_AP_GET_PRIVATE (ap)->hotspot; -} - -/* - * Get/set functions for strength - * - */ -gint8 nm_ap_get_strength (NMAccessPoint *ap) -{ - gint8 strength; - - g_return_val_if_fail (NM_IS_AP (ap), 0); - - g_object_get (ap, NM_AP_STRENGTH, &strength, NULL); - - return strength; -} - -void nm_ap_set_strength (NMAccessPoint *ap, const gint8 strength) -{ - NMAccessPointPrivate *priv; - - g_return_if_fail (NM_IS_AP (ap)); - - priv = NM_AP_GET_PRIVATE (ap); - - if (priv->strength != strength) { - priv->strength = strength; - g_object_notify (G_OBJECT (ap), NM_AP_STRENGTH); - } -} - - -/* - * Get/set functions for frequency - * - */ -guint32 -nm_ap_get_freq (NMAccessPoint *ap) -{ - guint32 freq; - - g_return_val_if_fail (NM_IS_AP (ap), 0); - - g_object_get (ap, NM_AP_FREQUENCY, &freq, NULL); - - return freq; -} - -void -nm_ap_set_freq (NMAccessPoint *ap, - const guint32 freq) -{ - NMAccessPointPrivate *priv; - - g_return_if_fail (NM_IS_AP (ap)); - - priv = NM_AP_GET_PRIVATE (ap); - - if (priv->freq != freq) { - priv->freq = freq; - g_object_notify (G_OBJECT (ap), NM_AP_FREQUENCY); - } -} - - -/* - * Get/set functions for max bitrate (in kbit/s) - * - */ -guint32 nm_ap_get_max_bitrate (NMAccessPoint *ap) -{ - guint32 rate; - - g_return_val_if_fail (NM_IS_AP (ap), 0); - - g_object_get (ap, NM_AP_MAX_BITRATE, &rate, NULL); - - return rate; -} - -void -nm_ap_set_max_bitrate (NMAccessPoint *ap, guint32 bitrate) -{ - NMAccessPointPrivate *priv; - - g_return_if_fail (NM_IS_AP (ap)); - - priv = NM_AP_GET_PRIVATE (ap); - - if (priv->max_bitrate != bitrate) { - priv->max_bitrate = bitrate; - g_object_notify (G_OBJECT (ap), NM_AP_MAX_BITRATE); - } -} - -/* - * Get/Set functions to indicate that an access point is 'fake', ie whether - * or not it was created from scan results - */ -gboolean nm_ap_get_fake (const NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), FALSE); - - return NM_AP_GET_PRIVATE (ap)->fake; -} - -void nm_ap_set_fake (NMAccessPoint *ap, gboolean fake) -{ - g_return_if_fail (NM_IS_AP (ap)); - - NM_AP_GET_PRIVATE (ap)->fake = fake; -} - -/* - * Get/Set functions for how long ago the AP was last seen in a scan. - * APs older than a certain date are dropped from the list. - * - */ -gint32 -nm_ap_get_last_seen (const NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), 0); - - return NM_AP_GET_PRIVATE (ap)->last_seen; -} - -void -nm_ap_set_last_seen (NMAccessPoint *ap, gint32 last_seen) -{ - NMAccessPointPrivate *priv; - - g_return_if_fail (NM_IS_AP (ap)); - - priv = NM_AP_GET_PRIVATE (ap); - - if (priv->last_seen != last_seen) { - priv->last_seen = last_seen; - g_object_notify (G_OBJECT (ap), NM_AP_LAST_SEEN); - } -} - static guint freq_to_band (guint32 freq) { From 8cd2353cd96b7f8e38424cfa9e98312570494635 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 20 Apr 2015 11:03:11 -0500 Subject: [PATCH 07/11] wifi: make internal functions static or remove them Convert internal-only getters to priv-> at their point of usage, and make internal-only setters static. --- src/devices/wifi/nm-wifi-ap.c | 99 ++++++++++------------------------- src/devices/wifi/nm-wifi-ap.h | 17 ------ 2 files changed, 27 insertions(+), 89 deletions(-) diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index 4338ff8c9..3c4b2a3b6 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -94,16 +94,6 @@ nm_ap_get_supplicant_path (NMAccessPoint *ap) return NM_AP_GET_PRIVATE (ap)->supplicant_path; } -void -nm_ap_set_supplicant_path (NMAccessPoint *ap, const char *path) -{ - g_return_if_fail (NM_IS_AP (ap)); - g_return_if_fail (path != NULL); - - g_free (NM_AP_GET_PRIVATE (ap)->supplicant_path); - NM_AP_GET_PRIVATE (ap)->supplicant_path = g_strdup (path); -} - const char * nm_ap_get_dbus_path (NMAccessPoint *ap) { @@ -156,16 +146,7 @@ nm_ap_set_ssid (NMAccessPoint *ap, const guint8 *ssid, gsize len) g_object_notify (G_OBJECT (ap), NM_AP_SSID); } -NM80211ApFlags -nm_ap_get_flags (NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_AP_FLAGS_NONE); - - return NM_AP_GET_PRIVATE (ap)->flags; -} - - -void +static void nm_ap_set_flags (NMAccessPoint *ap, NM80211ApFlags flags) { NMAccessPointPrivate *priv; @@ -180,16 +161,7 @@ nm_ap_set_flags (NMAccessPoint *ap, NM80211ApFlags flags) } } -NM80211ApSecurityFlags -nm_ap_get_wpa_flags (NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_AP_SEC_NONE); - - return NM_AP_GET_PRIVATE (ap)->wpa_flags; -} - - -void +static void nm_ap_set_wpa_flags (NMAccessPoint *ap, NM80211ApSecurityFlags flags) { NMAccessPointPrivate *priv; @@ -203,16 +175,7 @@ nm_ap_set_wpa_flags (NMAccessPoint *ap, NM80211ApSecurityFlags flags) } } -NM80211ApSecurityFlags -nm_ap_get_rsn_flags (NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_AP_SEC_NONE); - - return NM_AP_GET_PRIVATE (ap)->rsn_flags; -} - - -void +static void nm_ap_set_rsn_flags (NMAccessPoint *ap, NM80211ApSecurityFlags flags) { NMAccessPointPrivate *priv; @@ -264,7 +227,7 @@ nm_ap_get_mode (NMAccessPoint *ap) return mode; } -void +static void nm_ap_set_mode (NMAccessPoint *ap, const NM80211Mode mode) { NMAccessPointPrivate *priv; @@ -387,15 +350,7 @@ nm_ap_set_fake (NMAccessPoint *ap, gboolean fake) NM_AP_GET_PRIVATE (ap)->fake = fake; } -gint32 -nm_ap_get_last_seen (const NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), FALSE); - - return NM_AP_GET_PRIVATE (ap)->last_seen; -} - -void +static void nm_ap_set_last_seen (NMAccessPoint *ap, gint32 last_seen) { NMAccessPointPrivate *priv; @@ -410,7 +365,6 @@ nm_ap_set_last_seen (NMAccessPoint *ap, gint32 last_seen) } } - /*****************************************************************/ static NM80211ApSecurityFlags @@ -473,7 +427,7 @@ nm_ap_update_from_properties (NMAccessPoint *ap, g_object_freeze_notify (G_OBJECT (ap)); if (g_variant_lookup (properties, "Privacy", "b", &b) && b) - nm_ap_set_flags (ap, nm_ap_get_flags (ap) | NM_802_11_AP_FLAGS_PRIVACY); + nm_ap_set_flags (ap, priv->flags | NM_802_11_AP_FLAGS_PRIVACY); if (g_variant_lookup (properties, "Mode", "&s", &s)) { if (!g_strcmp0 (s, "infrastructure")) @@ -531,18 +485,18 @@ nm_ap_update_from_properties (NMAccessPoint *ap, v = g_variant_lookup_value (properties, "WPA", G_VARIANT_TYPE_VARDICT); if (v) { - nm_ap_set_wpa_flags (ap, nm_ap_get_wpa_flags (ap) | security_from_vardict (v)); + nm_ap_set_wpa_flags (ap, priv->wpa_flags | security_from_vardict (v)); g_variant_unref (v); } v = g_variant_lookup_value (properties, "RSN", G_VARIANT_TYPE_VARDICT); if (v) { - nm_ap_set_rsn_flags (ap, nm_ap_get_rsn_flags (ap) | security_from_vardict (v)); + nm_ap_set_rsn_flags (ap, priv->rsn_flags | security_from_vardict (v)); g_variant_unref (v); } - if (!nm_ap_get_supplicant_path (ap)) - nm_ap_set_supplicant_path (ap, supplicant_path); + if (!priv->supplicant_path) + priv->supplicant_path = g_strdup (supplicant_path); nm_ap_set_last_seen (ap, nm_utils_get_monotonic_timestamp_s ()); priv->fake = FALSE; @@ -597,6 +551,7 @@ has_proto (NMSettingWirelessSecurity *sec, const char *proto) static void add_pair_ciphers (NMAccessPoint *ap, NMSettingWirelessSecurity *sec) { + NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (ap); guint32 num = nm_setting_wireless_security_get_num_pairwise (sec); NM80211ApSecurityFlags flags = NM_802_11_AP_SEC_NONE; guint32 i; @@ -616,14 +571,15 @@ add_pair_ciphers (NMAccessPoint *ap, NMSettingWirelessSecurity *sec) } if (has_proto (sec, PROTO_WPA)) - nm_ap_set_wpa_flags (ap, nm_ap_get_wpa_flags (ap) | flags); + nm_ap_set_wpa_flags (ap, priv->wpa_flags | flags); if (has_proto (sec, PROTO_RSN)) - nm_ap_set_rsn_flags (ap, nm_ap_get_rsn_flags (ap) | flags); + nm_ap_set_rsn_flags (ap, priv->rsn_flags | flags); } static void add_group_ciphers (NMAccessPoint *ap, NMSettingWirelessSecurity *sec) { + NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (ap); guint32 num = nm_setting_wireless_security_get_num_groups (sec); NM80211ApSecurityFlags flags = NM_802_11_AP_SEC_NONE; guint32 i; @@ -647,15 +603,16 @@ add_group_ciphers (NMAccessPoint *ap, NMSettingWirelessSecurity *sec) } if (has_proto (sec, PROTO_WPA)) - nm_ap_set_wpa_flags (ap, nm_ap_get_wpa_flags (ap) | flags); + nm_ap_set_wpa_flags (ap, priv->wpa_flags | flags); if (has_proto (sec, PROTO_RSN)) - nm_ap_set_rsn_flags (ap, nm_ap_get_rsn_flags (ap) | flags); + nm_ap_set_rsn_flags (ap, priv->rsn_flags | flags); } NMAccessPoint * nm_ap_new_fake_from_connection (NMConnection *connection) { NMAccessPoint *ap; + NMAccessPointPrivate *priv; NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wireless_sec; GBytes *ssid; @@ -674,7 +631,8 @@ nm_ap_new_fake_from_connection (NMConnection *connection) g_return_val_if_fail (g_bytes_get_size (ssid) > 0, NULL); ap = (NMAccessPoint *) g_object_new (NM_TYPE_AP, NULL); - nm_ap_set_fake (ap, TRUE); + priv = NM_AP_GET_PRIVATE (ap); + priv->fake = TRUE; nm_ap_set_ssid (ap, g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); // FIXME: bssid too? @@ -714,7 +672,7 @@ nm_ap_new_fake_from_connection (NMConnection *connection) key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wireless_sec); /* Everything below here uses encryption */ - nm_ap_set_flags (ap, nm_ap_get_flags (ap) | NM_802_11_AP_FLAGS_PRIVACY); + nm_ap_set_flags (ap, priv->flags | NM_802_11_AP_FLAGS_PRIVACY); /* Static & Dynamic WEP */ if (!strcmp (key_mgmt, "none") || !strcmp (key_mgmt, "ieee8021x")) @@ -724,13 +682,11 @@ nm_ap_new_fake_from_connection (NMConnection *connection) eap = !strcmp (key_mgmt, "wpa-eap"); if (psk || eap) { if (has_proto (s_wireless_sec, PROTO_WPA)) { - flags = nm_ap_get_wpa_flags (ap); - flags |= eap ? NM_802_11_AP_SEC_KEY_MGMT_802_1X : NM_802_11_AP_SEC_KEY_MGMT_PSK; + flags = priv->wpa_flags | (eap ? NM_802_11_AP_SEC_KEY_MGMT_802_1X : NM_802_11_AP_SEC_KEY_MGMT_PSK); nm_ap_set_wpa_flags (ap, flags); } if (has_proto (s_wireless_sec, PROTO_RSN)) { - flags = nm_ap_get_rsn_flags (ap); - flags |= eap ? NM_802_11_AP_SEC_KEY_MGMT_802_1X : NM_802_11_AP_SEC_KEY_MGMT_PSK; + flags = priv->rsn_flags | (eap ? NM_802_11_AP_SEC_KEY_MGMT_802_1X : NM_802_11_AP_SEC_KEY_MGMT_PSK); nm_ap_set_rsn_flags (ap, flags); } @@ -743,8 +699,7 @@ nm_ap_new_fake_from_connection (NMConnection *connection) * group=TKIP/CCMP (but not both). */ - flags = nm_ap_get_wpa_flags (ap); - flags |= NM_802_11_AP_SEC_KEY_MGMT_PSK; + flags = priv->wpa_flags | NM_802_11_AP_SEC_KEY_MGMT_PSK; /* Clear ciphers; pairwise must be unset anyway, and group gets set below */ flags &= ~( NM_802_11_AP_SEC_PAIR_WEP40 @@ -908,10 +863,10 @@ nm_ap_check_compatible (NMAccessPoint *self, return nm_setting_wireless_ap_security_compatible (s_wireless, s_wireless_sec, - nm_ap_get_flags (self), - nm_ap_get_wpa_flags (self), - nm_ap_get_rsn_flags (self), - nm_ap_get_mode (self)); + priv->flags, + priv->wpa_flags, + priv->rsn_flags, + priv->mode); } gboolean diff --git a/src/devices/wifi/nm-wifi-ap.h b/src/devices/wifi/nm-wifi-ap.h index f316a7ae1..2e7d74a77 100644 --- a/src/devices/wifi/nm-wifi-ap.h +++ b/src/devices/wifi/nm-wifi-ap.h @@ -66,30 +66,16 @@ void nm_ap_update_from_properties (NMAccessPoint *ap, GVariant *properties); const char *nm_ap_get_dbus_path (NMAccessPoint *ap); - const char *nm_ap_get_supplicant_path (NMAccessPoint *ap); -void nm_ap_set_supplicant_path (NMAccessPoint *ap, - const char *path); - guint32 nm_ap_get_id (NMAccessPoint *ap); const GByteArray *nm_ap_get_ssid (const NMAccessPoint * ap); void nm_ap_set_ssid (NMAccessPoint * ap, const guint8 * ssid, gsize len); -NM80211ApFlags nm_ap_get_flags (NMAccessPoint *ap); -void nm_ap_set_flags (NMAccessPoint *ap, NM80211ApFlags flags); - -NM80211ApSecurityFlags nm_ap_get_wpa_flags (NMAccessPoint *ap); -void nm_ap_set_wpa_flags (NMAccessPoint *ap, NM80211ApSecurityFlags flags); - -NM80211ApSecurityFlags nm_ap_get_rsn_flags (NMAccessPoint *ap); -void nm_ap_set_rsn_flags (NMAccessPoint *ap, NM80211ApSecurityFlags flags); - const char *nm_ap_get_address (const NMAccessPoint *ap); void nm_ap_set_address (NMAccessPoint *ap, const char *addr); NM80211Mode nm_ap_get_mode (NMAccessPoint *ap); -void nm_ap_set_mode (NMAccessPoint *ap, const NM80211Mode mode); gboolean nm_ap_is_hotspot (NMAccessPoint *ap); @@ -105,9 +91,6 @@ void nm_ap_set_max_bitrate (NMAccessPoint *ap, guint32 bitrate); gboolean nm_ap_get_fake (const NMAccessPoint *ap); void nm_ap_set_fake (NMAccessPoint *ap, gboolean fake); -gint32 nm_ap_get_last_seen (const NMAccessPoint *ap); -void nm_ap_set_last_seen (NMAccessPoint *ap, gint32 last_seen); - gboolean nm_ap_check_compatible (NMAccessPoint *self, NMConnection *connection); From 7202449b472b73dfc9c6262e0fb50c3a691e987f Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 20 Apr 2015 11:04:05 -0500 Subject: [PATCH 08/11] wifi: beautify spacing in nm-wifi-ap.h --- src/devices/wifi/nm-wifi-ap.h | 81 +++++++++++++++++------------------ 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/devices/wifi/nm-wifi-ap.h b/src/devices/wifi/nm-wifi-ap.h index 2e7d74a77..dfc5acee3 100644 --- a/src/devices/wifi/nm-wifi-ap.h +++ b/src/devices/wifi/nm-wifi-ap.h @@ -56,51 +56,50 @@ typedef struct { GType nm_ap_get_type (void); -NMAccessPoint * nm_ap_new_from_properties (const char *supplicant_path, - GVariant *properties); -NMAccessPoint * nm_ap_new_fake_from_connection (NMConnection *connection); -void nm_ap_export_to_dbus (NMAccessPoint *ap); +NMAccessPoint * nm_ap_new_from_properties (const char *supplicant_path, + GVariant *properties); +NMAccessPoint * nm_ap_new_fake_from_connection (NMConnection *connection); +void nm_ap_export_to_dbus (NMAccessPoint *ap); -void nm_ap_update_from_properties (NMAccessPoint *ap, - const char *supplicant_path, - GVariant *properties); +void nm_ap_update_from_properties (NMAccessPoint *ap, + const char *supplicant_path, + GVariant *properties); -const char *nm_ap_get_dbus_path (NMAccessPoint *ap); -const char *nm_ap_get_supplicant_path (NMAccessPoint *ap); -guint32 nm_ap_get_id (NMAccessPoint *ap); +gboolean nm_ap_check_compatible (NMAccessPoint *self, + NMConnection *connection); -const GByteArray *nm_ap_get_ssid (const NMAccessPoint * ap); -void nm_ap_set_ssid (NMAccessPoint * ap, const guint8 * ssid, gsize len); +gboolean nm_ap_complete_connection (NMAccessPoint *self, + NMConnection *connection, + gboolean lock_bssid, + GError **error); -const char *nm_ap_get_address (const NMAccessPoint *ap); -void nm_ap_set_address (NMAccessPoint *ap, const char *addr); +const char * nm_ap_get_dbus_path (NMAccessPoint *ap); +const char * nm_ap_get_supplicant_path (NMAccessPoint *ap); +guint32 nm_ap_get_id (NMAccessPoint *ap); +const GByteArray *nm_ap_get_ssid (const NMAccessPoint *ap); +void nm_ap_set_ssid (NMAccessPoint *ap, + const guint8 *ssid, + gsize len); +const char * nm_ap_get_address (const NMAccessPoint *ap); +void nm_ap_set_address (NMAccessPoint *ap, + const char *addr); +NM80211Mode nm_ap_get_mode (NMAccessPoint *ap); +gboolean nm_ap_is_hotspot (NMAccessPoint *ap); +gint8 nm_ap_get_strength (NMAccessPoint *ap); +void nm_ap_set_strength (NMAccessPoint *ap, + gint8 strength); +guint32 nm_ap_get_freq (NMAccessPoint *ap); +void nm_ap_set_freq (NMAccessPoint *ap, + guint32 freq); +guint32 nm_ap_get_max_bitrate (NMAccessPoint *ap); +void nm_ap_set_max_bitrate (NMAccessPoint *ap, + guint32 bitrate); +gboolean nm_ap_get_fake (const NMAccessPoint *ap); +void nm_ap_set_fake (NMAccessPoint *ap, + gboolean fake); -NM80211Mode nm_ap_get_mode (NMAccessPoint *ap); - -gboolean nm_ap_is_hotspot (NMAccessPoint *ap); - -gint8 nm_ap_get_strength (NMAccessPoint *ap); -void nm_ap_set_strength (NMAccessPoint *ap, gint8 strength); - -guint32 nm_ap_get_freq (NMAccessPoint *ap); -void nm_ap_set_freq (NMAccessPoint *ap, guint32 freq); - -guint32 nm_ap_get_max_bitrate (NMAccessPoint *ap); -void nm_ap_set_max_bitrate (NMAccessPoint *ap, guint32 bitrate); - -gboolean nm_ap_get_fake (const NMAccessPoint *ap); -void nm_ap_set_fake (NMAccessPoint *ap, gboolean fake); - -gboolean nm_ap_check_compatible (NMAccessPoint *self, - NMConnection *connection); - -gboolean nm_ap_complete_connection (NMAccessPoint *self, - NMConnection *connection, - gboolean lock_bssid, - GError **error); - -void nm_ap_dump (NMAccessPoint *self, - const char *prefix, - const char *ifname); +void nm_ap_dump (NMAccessPoint *self, + const char *prefix, + const char *ifname); #endif /* __NETWORKMANAGER_ACCESS_POINT_H__ */ From a646514fb6f472a7ca9562260c3e6383c299e128 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 20 Apr 2015 11:07:44 -0500 Subject: [PATCH 09/11] wifi: remove unused NMAccessPoint set_property() code Properties are never set at construct time through GValues, but later through helpers. --- src/devices/wifi/nm-wifi-ap.c | 70 ++++++----------------------------- 1 file changed, 11 insertions(+), 59 deletions(-) diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index 3c4b2a3b6..220558c0c 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -922,6 +922,7 @@ nm_ap_init (NMAccessPoint *ap) priv->flags = NM_802_11_AP_FLAGS_NONE; priv->wpa_flags = NM_802_11_AP_SEC_NONE; priv->rsn_flags = NM_802_11_AP_SEC_NONE; + priv->last_seen = -1; } static void @@ -942,47 +943,7 @@ static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMAccessPoint *ap = NM_AP (object); - GByteArray *ssid; - - switch (prop_id) { - case PROP_FLAGS: - nm_ap_set_flags (ap, g_value_get_uint (value)); - break; - case PROP_WPA_FLAGS: - nm_ap_set_wpa_flags (ap, g_value_get_uint (value)); - break; - case PROP_RSN_FLAGS: - nm_ap_set_rsn_flags (ap, g_value_get_uint (value)); - break; - case PROP_SSID: - ssid = g_value_get_boxed (value); - if (ssid) - nm_ap_set_ssid (ap, ssid->data, ssid->len); - else - nm_ap_set_ssid (ap, NULL, 0); - break; - case PROP_FREQUENCY: - nm_ap_set_freq (ap, g_value_get_uint (value)); - break; - case PROP_MODE: - nm_ap_set_mode (ap, g_value_get_uint (value)); - break; - case PROP_MAX_BITRATE: - nm_ap_set_max_bitrate (ap, g_value_get_uint (value)); - break; - case PROP_STRENGTH: - nm_ap_set_strength (ap, g_value_get_schar (value)); - break; - case PROP_HW_ADDRESS: - break; - case PROP_LAST_SEEN: - nm_ap_set_last_seen (ap, g_value_get_int (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } static void @@ -1069,8 +1030,7 @@ nm_ap_class_init (NMAccessPointClass *ap_class) NM_802_11_AP_FLAGS_NONE, NM_802_11_AP_FLAGS_PRIVACY, NM_802_11_AP_FLAGS_NONE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_WPA_FLAGS, @@ -1078,8 +1038,7 @@ nm_ap_class_init (NMAccessPointClass *ap_class) NM_802_11_AP_SEC_NONE, all_sec_flags, NM_802_11_AP_SEC_NONE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_RSN_FLAGS, @@ -1087,50 +1046,43 @@ nm_ap_class_init (NMAccessPointClass *ap_class) NM_802_11_AP_SEC_NONE, all_sec_flags, NM_802_11_AP_SEC_NONE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_SSID, g_param_spec_boxed (NM_AP_SSID, "", "", DBUS_TYPE_G_UCHAR_ARRAY, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_FREQUENCY, g_param_spec_uint (NM_AP_FREQUENCY, "", "", 0, 10000, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_HW_ADDRESS, g_param_spec_string (NM_AP_HW_ADDRESS, "", "", NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_MODE, g_param_spec_uint (NM_AP_MODE, "", "", NM_802_11_MODE_ADHOC, NM_802_11_MODE_INFRA, NM_802_11_MODE_INFRA, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_MAX_BITRATE, g_param_spec_uint (NM_AP_MAX_BITRATE, "", "", 0, G_MAXUINT16, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_STRENGTH, g_param_spec_char (NM_AP_STRENGTH, "", "", G_MININT8, G_MAXINT8, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_LAST_SEEN, From 2028ef2c829f1544ad1cd5f40dd0a552f16fcc19 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 20 Apr 2015 11:11:56 -0500 Subject: [PATCH 10/11] wifi: remove anachronistic NMAccessPoint getter pattern Just use priv. --- src/devices/wifi/nm-wifi-ap.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index 220558c0c..ea4ec2a8d 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -218,13 +218,9 @@ nm_ap_set_address (NMAccessPoint *ap, const char *addr) NM80211Mode nm_ap_get_mode (NMAccessPoint *ap) { - NM80211Mode mode; + g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_MODE_UNKNOWN); - g_return_val_if_fail (NM_IS_AP (ap), -1); - - g_object_get (ap, NM_AP_MODE, &mode, NULL); - - return mode; + return NM_AP_GET_PRIVATE (ap)->mode; } static void @@ -255,13 +251,9 @@ nm_ap_is_hotspot (NMAccessPoint *ap) gint8 nm_ap_get_strength (NMAccessPoint *ap) { - gint8 strength; - g_return_val_if_fail (NM_IS_AP (ap), 0); - g_object_get (ap, NM_AP_STRENGTH, &strength, NULL); - - return strength; + return NM_AP_GET_PRIVATE (ap)->strength; } void @@ -282,13 +274,9 @@ nm_ap_set_strength (NMAccessPoint *ap, const gint8 strength) guint32 nm_ap_get_freq (NMAccessPoint *ap) { - guint32 freq; - g_return_val_if_fail (NM_IS_AP (ap), 0); - g_object_get (ap, NM_AP_FREQUENCY, &freq, NULL); - - return freq; + return NM_AP_GET_PRIVATE (ap)->freq; } void @@ -310,13 +298,9 @@ nm_ap_set_freq (NMAccessPoint *ap, guint32 nm_ap_get_max_bitrate (NMAccessPoint *ap) { - guint32 rate; - g_return_val_if_fail (NM_IS_AP (ap), 0); - g_object_get (ap, NM_AP_MAX_BITRATE, &rate, NULL); - - return rate; + return NM_AP_GET_PRIVATE (ap)->max_bitrate; } void From 1fcc9690d1f20345beb3024d16f2558a2f8ff97d Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 30 Apr 2015 09:56:55 -0500 Subject: [PATCH 11/11] platform: remove unused wifi_utils_get_ssid() --- src/platform/nm-linux-platform.c | 11 --------- src/platform/nm-platform.c | 11 --------- src/platform/nm-platform.h | 1 - src/platform/wifi/wifi-utils-nl80211.c | 19 ---------------- src/platform/wifi/wifi-utils-private.h | 3 --- src/platform/wifi/wifi-utils-wext.c | 31 -------------------------- src/platform/wifi/wifi-utils.c | 7 ------ src/platform/wifi/wifi-utils.h | 3 --- 8 files changed, 86 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 6f2c2287a..0ef684d97 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -3444,16 +3444,6 @@ wifi_get_bssid (NMPlatform *platform, int ifindex, guint8 *bssid) return wifi_utils_get_bssid (wifi_data, bssid); } -static GByteArray * -wifi_get_ssid (NMPlatform *platform, int ifindex) -{ - WifiData *wifi_data = wifi_get_wifi_data (platform, ifindex); - - if (!wifi_data) - return NULL; - return wifi_utils_get_ssid (wifi_data); -} - static guint32 wifi_get_frequency (NMPlatform *platform, int ifindex) { @@ -4722,7 +4712,6 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass) platform_class->wifi_get_capabilities = wifi_get_capabilities; platform_class->wifi_get_bssid = wifi_get_bssid; - platform_class->wifi_get_ssid = wifi_get_ssid; platform_class->wifi_get_frequency = wifi_get_frequency; platform_class->wifi_get_quality = wifi_get_quality; platform_class->wifi_get_rate = wifi_get_rate; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index f98277ba2..844ad32cd 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1556,17 +1556,6 @@ nm_platform_wifi_get_bssid (NMPlatform *self, int ifindex, guint8 *bssid) return klass->wifi_get_bssid (self, ifindex, bssid); } -GByteArray * -nm_platform_wifi_get_ssid (NMPlatform *self, int ifindex) -{ - _CHECK_SELF (self, klass, NULL); - reset_error (self); - - g_return_val_if_fail (ifindex > 0, NULL); - - return klass->wifi_get_ssid (self, ifindex); -} - guint32 nm_platform_wifi_get_frequency (NMPlatform *self, int ifindex) { diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 6f0224c5b..1de8747a5 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -590,7 +590,6 @@ gboolean nm_platform_gre_get_properties (NMPlatform *self, int ifindex, gboolean nm_platform_wifi_get_capabilities (NMPlatform *self, int ifindex, NMDeviceWifiCapabilities *caps); gboolean nm_platform_wifi_get_bssid (NMPlatform *self, int ifindex, guint8 *bssid); -GByteArray *nm_platform_wifi_get_ssid (NMPlatform *self, int ifindex); guint32 nm_platform_wifi_get_frequency (NMPlatform *self, int ifindex); int nm_platform_wifi_get_quality (NMPlatform *self, int ifindex); guint32 nm_platform_wifi_get_rate (NMPlatform *self, int ifindex); diff --git a/src/platform/wifi/wifi-utils-nl80211.c b/src/platform/wifi/wifi-utils-nl80211.c index 8ca5dd1c7..2a52de5c1 100644 --- a/src/platform/wifi/wifi-utils-nl80211.c +++ b/src/platform/wifi/wifi-utils-nl80211.c @@ -442,24 +442,6 @@ wifi_nl80211_find_freq (WifiData *data, const guint32 *freqs) return 0; } -static GByteArray * -wifi_nl80211_get_ssid (WifiData *data) -{ - WifiDataNl80211 *nl80211 = (WifiDataNl80211 *) data; - GByteArray *array = NULL; - struct nl80211_bss_info bss_info; - - nl80211_get_bss_info (nl80211, &bss_info); - - if (bss_info.valid) { - array = g_byte_array_sized_new (bss_info.ssid_len); - g_byte_array_append (array, (const guint8 *) bss_info.ssid, - bss_info.ssid_len); - } - - return array; -} - static gboolean wifi_nl80211_get_bssid (WifiData *data, guint8 *out_bssid) { @@ -874,7 +856,6 @@ wifi_nl80211_init (const char *iface, int ifindex) nl80211->parent.set_powersave = wifi_nl80211_set_powersave; nl80211->parent.get_freq = wifi_nl80211_get_freq; nl80211->parent.find_freq = wifi_nl80211_find_freq; - nl80211->parent.get_ssid = wifi_nl80211_get_ssid; nl80211->parent.get_bssid = wifi_nl80211_get_bssid; nl80211->parent.get_rate = wifi_nl80211_get_rate; nl80211->parent.get_qual = wifi_nl80211_get_qual; diff --git a/src/platform/wifi/wifi-utils-private.h b/src/platform/wifi/wifi-utils-private.h index 9d9af6924..c334a8284 100644 --- a/src/platform/wifi/wifi-utils-private.h +++ b/src/platform/wifi/wifi-utils-private.h @@ -44,9 +44,6 @@ struct WifiData { /* Return first supported frequency in the zero-terminated list */ guint32 (*find_freq) (WifiData *data, const guint32 *freqs); - /* If SSID is empty/blank (zero-length or all \0s) return NULL */ - GByteArray * (*get_ssid) (WifiData *data); - /* Return current bitrate in Kbps */ guint32 (*get_rate) (WifiData *data); diff --git a/src/platform/wifi/wifi-utils-wext.c b/src/platform/wifi/wifi-utils-wext.c index f4301ef29..e58b72bc4 100644 --- a/src/platform/wifi/wifi-utils-wext.c +++ b/src/platform/wifi/wifi-utils-wext.c @@ -223,36 +223,6 @@ wifi_wext_find_freq (WifiData *data, const guint32 *freqs) return 0; } -static GByteArray * -wifi_wext_get_ssid (WifiData *data) -{ - WifiDataWext *wext = (WifiDataWext *) data; - struct iwreq wrq; - char ssid[IW_ESSID_MAX_SIZE + 2]; - guint32 len; - GByteArray *array = NULL; - - memset (ssid, 0, sizeof (ssid)); - wrq.u.essid.pointer = (caddr_t) &ssid; - wrq.u.essid.length = sizeof (ssid); - wrq.u.essid.flags = 0; - strncpy (wrq.ifr_name, wext->parent.iface, IFNAMSIZ); - - if (ioctl (wext->fd, SIOCGIWESSID, &wrq) < 0) { - nm_log_err (LOGD_HW | LOGD_WIFI, "(%s): couldn't get SSID: %d", - wext->parent.iface, errno); - return NULL; - } - - len = wrq.u.essid.length; - if (nm_utils_is_empty_ssid ((guint8 *) ssid, len) == FALSE) { - array = g_byte_array_sized_new (len); - g_byte_array_append (array, (const guint8 *) ssid, len); - } - - return array; -} - static gboolean wifi_wext_get_bssid (WifiData *data, guint8 *out_bssid) { @@ -601,7 +571,6 @@ wifi_wext_init (const char *iface, int ifindex, gboolean check_scan) wext->parent.set_powersave = wifi_wext_set_powersave; wext->parent.get_freq = wifi_wext_get_freq; wext->parent.find_freq = wifi_wext_find_freq; - wext->parent.get_ssid = wifi_wext_get_ssid; wext->parent.get_bssid = wifi_wext_get_bssid; wext->parent.get_rate = wifi_wext_get_rate; wext->parent.get_qual = wifi_wext_get_qual; diff --git a/src/platform/wifi/wifi-utils.c b/src/platform/wifi/wifi-utils.c index d6dbc3645..69c8cbc95 100644 --- a/src/platform/wifi/wifi-utils.c +++ b/src/platform/wifi/wifi-utils.c @@ -121,13 +121,6 @@ wifi_utils_find_freq (WifiData *data, const guint32 *freqs) return data->find_freq (data, freqs); } -GByteArray * -wifi_utils_get_ssid (WifiData *data) -{ - g_return_val_if_fail (data != NULL, NULL); - return data->get_ssid (data); -} - gboolean wifi_utils_get_bssid (WifiData *data, guint8 *out_bssid) { diff --git a/src/platform/wifi/wifi-utils.h b/src/platform/wifi/wifi-utils.h index ad4d14196..a2830dcd7 100644 --- a/src/platform/wifi/wifi-utils.h +++ b/src/platform/wifi/wifi-utils.h @@ -48,9 +48,6 @@ guint32 wifi_utils_get_freq (WifiData *data); * Frequencies are specified in MHz. */ guint32 wifi_utils_find_freq (WifiData *data, const guint32 *freqs); -/* Caller must free returned byte array */ -GByteArray *wifi_utils_get_ssid (WifiData *data); - /* out_bssid must be ETH_ALEN bytes */ gboolean wifi_utils_get_bssid (WifiData *data, guint8 *out_bssid);