mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 17:10:21 +01:00
wifi: use a hash table to track access points
This commit is contained in:
parent
6596ceee14
commit
6b8df2035e
3 changed files with 154 additions and 156 deletions
|
|
@ -116,14 +116,12 @@ enum {
|
|||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
struct _NMDeviceWifiPrivate {
|
||||
gboolean disposed;
|
||||
|
||||
char * perm_hw_addr; /* Permanent MAC address */
|
||||
char * initial_hw_addr; /* Initial MAC address (as seen when NM starts) */
|
||||
|
||||
gint8 invalid_strength_counter;
|
||||
|
||||
GSList * ap_list;
|
||||
GHashTable * aps;
|
||||
NMAccessPoint * current_ap;
|
||||
guint32 rate;
|
||||
gboolean enabled; /* rfkilled or not */
|
||||
|
|
@ -189,7 +187,10 @@ static void schedule_scanlist_cull (NMDeviceWifi *self);
|
|||
|
||||
static gboolean request_wireless_scan (gpointer user_data);
|
||||
|
||||
static void remove_access_point (NMDeviceWifi *device, NMAccessPoint *ap);
|
||||
static void emit_ap_added_removed (NMDeviceWifi *self,
|
||||
guint signum,
|
||||
NMAccessPoint *ap,
|
||||
gboolean recheck_available_connections);
|
||||
|
||||
static void remove_supplicant_interface_error_handler (NMDeviceWifi *self);
|
||||
|
||||
|
|
@ -315,31 +316,23 @@ supplicant_interface_release (NMDeviceWifi *self)
|
|||
static NMAccessPoint *
|
||||
get_ap_by_path (NMDeviceWifi *self, const char *path)
|
||||
{
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
GSList *iter;
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
return g_hash_table_lookup (NM_DEVICE_WIFI_GET_PRIVATE (self)->aps, path);
|
||||
|
||||
if (!path)
|
||||
return NULL;
|
||||
|
||||
for (iter = priv->ap_list; iter; iter = g_slist_next (iter)) {
|
||||
if (g_strcmp0 (path, nm_ap_get_dbus_path (NM_AP (iter->data))) == 0)
|
||||
return NM_AP (iter->data);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static NMAccessPoint *
|
||||
get_ap_by_supplicant_path (NMDeviceWifi *self, const char *path)
|
||||
{
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
GSList *iter;
|
||||
GHashTableIter iter;
|
||||
NMAccessPoint *ap;
|
||||
|
||||
if (!path)
|
||||
return NULL;
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
|
||||
for (iter = priv->ap_list; iter; iter = g_slist_next (iter)) {
|
||||
if (g_strcmp0 (path, nm_ap_get_supplicant_path (NM_AP (iter->data))) == 0)
|
||||
return NM_AP (iter->data);
|
||||
g_hash_table_iter_init (&iter, NM_DEVICE_WIFI_GET_PRIVATE (self)->aps);
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &ap)) {
|
||||
if (g_strcmp0 (path, nm_ap_get_supplicant_path (ap)) == 0)
|
||||
return ap;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -353,7 +346,6 @@ find_active_ap (NMDeviceWifi *self,
|
|||
int ifindex = nm_device_get_ifindex (NM_DEVICE (self));
|
||||
guint8 bssid[ETH_ALEN];
|
||||
GByteArray *ssid;
|
||||
GSList *iter;
|
||||
int i = 0;
|
||||
NMAccessPoint *match_nofreq = NULL, *active_ap = NULL;
|
||||
gboolean found_a_band = FALSE;
|
||||
|
|
@ -382,11 +374,14 @@ find_active_ap (NMDeviceWifi *self,
|
|||
* and therefore it won't get matched the first time around.
|
||||
*/
|
||||
while (i++ < (match_hidden ? 2 : 1)) {
|
||||
GHashTableIter iter;
|
||||
NMAccessPoint *ap;
|
||||
|
||||
_LOGT (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);
|
||||
g_hash_table_iter_init (&iter, priv->aps);
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &ap)) {
|
||||
const char *ap_bssid = nm_ap_get_address (ap);
|
||||
const GByteArray *ap_ssid = nm_ap_get_ssid (ap);
|
||||
NM80211Mode apmode;
|
||||
|
|
@ -521,13 +516,6 @@ set_current_ap (NMDeviceWifi *self, NMAccessPoint *new_ap, gboolean recheck_avai
|
|||
if (new_ap) {
|
||||
priv->current_ap = g_object_ref (new_ap);
|
||||
|
||||
/* Move the current AP to the front of the scan list. Since we
|
||||
* do a lot of searches looking for the current AP, it saves
|
||||
* time to have it in front.
|
||||
*/
|
||||
priv->ap_list = g_slist_remove (priv->ap_list, new_ap);
|
||||
priv->ap_list = g_slist_prepend (priv->ap_list, new_ap);
|
||||
|
||||
/* Update seen BSSIDs cache */
|
||||
update_seen_bssids_cache (self, priv->current_ap);
|
||||
} else
|
||||
|
|
@ -537,7 +525,8 @@ set_current_ap (NMDeviceWifi *self, NMAccessPoint *new_ap, gboolean recheck_avai
|
|||
NM80211Mode mode = nm_ap_get_mode (old_ap);
|
||||
|
||||
if (force_remove_old_ap || mode == NM_802_11_MODE_ADHOC || mode == NM_802_11_MODE_AP || nm_ap_get_fake (old_ap)) {
|
||||
remove_access_point (self, old_ap);
|
||||
emit_ap_added_removed (self, ACCESS_POINT_REMOVED, old_ap, FALSE);
|
||||
g_hash_table_remove (priv->aps, nm_ap_get_dbus_path (old_ap));
|
||||
if (recheck_available_connections)
|
||||
nm_device_recheck_available_connections (NM_DEVICE (self));
|
||||
}
|
||||
|
|
@ -674,33 +663,21 @@ emit_ap_added_removed (NMDeviceWifi *self,
|
|||
nm_device_recheck_available_connections (NM_DEVICE (self));
|
||||
}
|
||||
|
||||
static void
|
||||
remove_access_point (NMDeviceWifi *device,
|
||||
NMAccessPoint *ap)
|
||||
{
|
||||
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
|
||||
g_return_if_fail (ap);
|
||||
g_return_if_fail (ap != priv->current_ap);
|
||||
g_return_if_fail (g_slist_find (priv->ap_list, ap));
|
||||
|
||||
priv->ap_list = g_slist_remove (priv->ap_list, ap);
|
||||
emit_ap_added_removed (self, ACCESS_POINT_REMOVED, ap, FALSE);
|
||||
g_object_unref (ap);
|
||||
}
|
||||
|
||||
static void
|
||||
remove_all_aps (NMDeviceWifi *self)
|
||||
{
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
GHashTableIter iter;
|
||||
NMAccessPoint *ap;
|
||||
|
||||
if (priv->ap_list) {
|
||||
if (g_hash_table_size (priv->aps)) {
|
||||
set_current_ap (self, NULL, FALSE, FALSE);
|
||||
|
||||
while (priv->ap_list)
|
||||
remove_access_point (self, NM_AP (priv->ap_list->data));
|
||||
|
||||
g_hash_table_iter_init (&iter, priv->aps);
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &ap)) {
|
||||
emit_ap_added_removed (self, ACCESS_POINT_REMOVED, ap, FALSE);
|
||||
g_hash_table_iter_remove (&iter);
|
||||
}
|
||||
nm_device_recheck_available_connections (NM_DEVICE (self));
|
||||
}
|
||||
}
|
||||
|
|
@ -862,6 +839,28 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static NMAccessPoint *
|
||||
find_first_compatible_ap (NMDeviceWifi *self,
|
||||
NMConnection *connection,
|
||||
gboolean allow_unstable_order)
|
||||
{
|
||||
GHashTableIter iter;
|
||||
NMAccessPoint *ap;
|
||||
NMAccessPoint *cand_ap = NULL;
|
||||
|
||||
g_return_val_if_fail (connection != NULL, NULL);
|
||||
|
||||
g_hash_table_iter_init (&iter, NM_DEVICE_WIFI_GET_PRIVATE (self)->aps);
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &ap)) {
|
||||
if (!nm_ap_check_compatible (ap, connection))
|
||||
continue;
|
||||
if (allow_unstable_order)
|
||||
return ap;
|
||||
if (!cand_ap || (nm_ap_get_id (cand_ap) < nm_ap_get_id (ap)))
|
||||
cand_ap = ap;
|
||||
}
|
||||
return cand_ap;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_connection_available (NMDevice *device,
|
||||
|
|
@ -869,10 +868,8 @@ check_connection_available (NMDevice *device,
|
|||
NMDeviceCheckConAvailableFlags flags,
|
||||
const char *specific_object)
|
||||
{
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
|
||||
NMSettingWireless *s_wifi;
|
||||
const char *mode;
|
||||
GSList *ap_iter = NULL;
|
||||
|
||||
s_wifi = nm_connection_get_setting_wireless (connection);
|
||||
g_return_val_if_fail (s_wifi, FALSE);
|
||||
|
|
@ -906,13 +903,8 @@ check_connection_available (NMDevice *device,
|
|||
if (nm_setting_wireless_get_hidden (s_wifi) || NM_FLAGS_HAS (flags, _NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST_IGNORE_AP))
|
||||
return TRUE;
|
||||
|
||||
/* check if its visible */
|
||||
for (ap_iter = priv->ap_list; ap_iter; ap_iter = g_slist_next (ap_iter)) {
|
||||
if (nm_ap_check_compatible (NM_AP (ap_iter->data), connection))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
/* check at least one AP is compatible with this connection */
|
||||
return !!find_first_compatible_ap (NM_DEVICE_WIFI (device), connection, TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -969,7 +961,6 @@ complete_connection (NMDevice *device,
|
|||
const GByteArray *ssid = NULL;
|
||||
GByteArray *tmp_ssid = NULL;
|
||||
GBytes *setting_ssid = NULL;
|
||||
GSList *iter;
|
||||
gboolean hidden = FALSE;
|
||||
|
||||
s_wifi = nm_connection_get_setting_wireless (connection);
|
||||
|
|
@ -996,12 +987,7 @@ complete_connection (NMDevice *device,
|
|||
}
|
||||
|
||||
/* Find a compatible AP in the scan list */
|
||||
for (iter = priv->ap_list; iter; iter = g_slist_next (iter)) {
|
||||
if (nm_ap_check_compatible (NM_AP (iter->data), connection)) {
|
||||
ap = NM_AP (iter->data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ap = find_first_compatible_ap (self, connection, FALSE);
|
||||
|
||||
/* If we still don't have an AP, then the WiFI settings needs to be
|
||||
* fully specified by the client. Might not be able to find an AP
|
||||
|
|
@ -1162,8 +1148,7 @@ can_auto_connect (NMDevice *device,
|
|||
char **specific_object)
|
||||
{
|
||||
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
GSList *ap_iter;
|
||||
NMAccessPoint *ap;
|
||||
const char *method = NULL;
|
||||
guint64 timestamp = 0;
|
||||
|
||||
|
|
@ -1184,33 +1169,53 @@ can_auto_connect (NMDevice *device,
|
|||
if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
|
||||
return TRUE;
|
||||
|
||||
for (ap_iter = priv->ap_list; ap_iter; ap_iter = g_slist_next (ap_iter)) {
|
||||
NMAccessPoint *ap = NM_AP (ap_iter->data);
|
||||
|
||||
if (nm_ap_check_compatible (ap, connection)) {
|
||||
/* All good; connection is usable */
|
||||
*specific_object = (char *) nm_ap_get_dbus_path (ap);
|
||||
return TRUE;
|
||||
}
|
||||
ap = find_first_compatible_ap (self, connection, FALSE);
|
||||
if (ap) {
|
||||
/* All good; connection is usable */
|
||||
*specific_object = (char *) nm_ap_get_dbus_path (ap);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gint
|
||||
ap_id_compare (NMAccessPoint *a, NMAccessPoint *b)
|
||||
{
|
||||
guint32 a_id = nm_ap_get_id (a);
|
||||
guint32 b_id = nm_ap_get_id (b);
|
||||
|
||||
return a_id < b_id ? -1 : (a_id == b_id ? 0 : 1);
|
||||
}
|
||||
|
||||
static GSList *
|
||||
get_sorted_ap_list (NMDeviceWifi *self)
|
||||
{
|
||||
GSList *sorted = NULL;
|
||||
GHashTableIter iter;
|
||||
NMAccessPoint *ap;
|
||||
|
||||
g_hash_table_iter_init (&iter, NM_DEVICE_WIFI_GET_PRIVATE (self)->aps);
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &ap))
|
||||
sorted = g_slist_prepend (sorted, ap);
|
||||
return g_slist_sort (sorted, (GCompareFunc) ap_id_compare);
|
||||
}
|
||||
|
||||
static void
|
||||
ap_list_dump (NMDeviceWifi *self)
|
||||
{
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
GSList * elt;
|
||||
int i = 0;
|
||||
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:");
|
||||
for (elt = priv->ap_list; elt; elt = g_slist_next (elt), i++) {
|
||||
NMAccessPoint * ap = NM_AP (elt->data);
|
||||
nm_ap_dump (ap, "List AP: ");
|
||||
}
|
||||
sorted = get_sorted_ap_list (self);
|
||||
for (iter = sorted; iter; iter = iter->next)
|
||||
nm_ap_dump (NM_AP (iter->data), "List AP: ");
|
||||
g_slist_free (sorted);
|
||||
_LOGD (LOGD_WIFI_SCAN, "Current AP list: done");
|
||||
}
|
||||
|
||||
|
|
@ -1219,16 +1224,17 @@ impl_device_get_access_points (NMDeviceWifi *self,
|
|||
GPtrArray **aps,
|
||||
GError **err)
|
||||
{
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
GSList *elt;
|
||||
GSList *sorted, *iter;
|
||||
|
||||
*aps = g_ptr_array_new ();
|
||||
for (elt = priv->ap_list; elt; elt = g_slist_next (elt)) {
|
||||
NMAccessPoint *ap = NM_AP (elt->data);
|
||||
sorted = get_sorted_ap_list (self);
|
||||
for (iter = sorted; iter; iter = iter->next) {
|
||||
NMAccessPoint *ap = NM_AP (iter->data);
|
||||
|
||||
if (nm_ap_get_ssid (ap))
|
||||
g_ptr_array_add (*aps, g_strdup (nm_ap_get_dbus_path (ap)));
|
||||
}
|
||||
g_slist_free (sorted);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -1237,12 +1243,13 @@ impl_device_get_all_access_points (NMDeviceWifi *self,
|
|||
GPtrArray **aps,
|
||||
GError **err)
|
||||
{
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
GSList *elt;
|
||||
GSList *sorted, *iter;
|
||||
|
||||
*aps = g_ptr_array_new ();
|
||||
for (elt = priv->ap_list; elt; elt = g_slist_next (elt))
|
||||
g_ptr_array_add (*aps, g_strdup (nm_ap_get_dbus_path (NM_AP (elt->data))));
|
||||
sorted = get_sorted_ap_list (self);
|
||||
for (iter = sorted; iter; iter = iter->next)
|
||||
g_ptr_array_add (*aps, g_strdup (nm_ap_get_dbus_path (NM_AP (iter->data))));
|
||||
g_slist_free (sorted);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -1710,7 +1717,7 @@ merge_scanned_ap (NMDeviceWifi *self,
|
|||
|
||||
found_ap = get_ap_by_supplicant_path (self, nm_ap_get_supplicant_path (merge_ap));
|
||||
if (!found_ap)
|
||||
found_ap = nm_ap_match_in_list (merge_ap, priv->ap_list, strict_match);
|
||||
found_ap = nm_ap_match_in_hash (merge_ap, priv->aps, strict_match);
|
||||
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)",
|
||||
|
|
@ -1740,8 +1747,8 @@ merge_scanned_ap (NMDeviceWifi *self,
|
|||
str_if_set (bssid, "(none)"), merge_ap);
|
||||
|
||||
g_object_ref (merge_ap);
|
||||
priv->ap_list = g_slist_prepend (priv->ap_list, 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1751,9 +1758,9 @@ cull_scan_list (NMDeviceWifi *self)
|
|||
{
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
gint32 now = nm_utils_get_monotonic_timestamp_s ();
|
||||
GSList *outdated_list = NULL;
|
||||
GSList *elt;
|
||||
guint32 removed = 0, total = 0;
|
||||
GHashTableIter iter;
|
||||
NMAccessPoint *ap;
|
||||
|
||||
priv->scanlist_cull_id = 0;
|
||||
|
||||
|
|
@ -1762,8 +1769,8 @@ cull_scan_list (NMDeviceWifi *self)
|
|||
/* Walk the access point list and remove any access points older than
|
||||
* three times the inactive scan interval.
|
||||
*/
|
||||
for (elt = priv->ap_list; elt; elt = g_slist_next (elt), total++) {
|
||||
NMAccessPoint *ap = elt->data;
|
||||
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;
|
||||
|
||||
|
|
@ -1784,28 +1791,21 @@ cull_scan_list (NMDeviceWifi *self)
|
|||
continue;
|
||||
|
||||
last_seen = nm_ap_get_last_seen (ap);
|
||||
if (!last_seen || last_seen + prune_interval_s < now)
|
||||
outdated_list = g_slist_prepend (outdated_list, 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++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove outdated APs */
|
||||
for (elt = outdated_list; elt; elt = g_slist_next (elt)) {
|
||||
NMAccessPoint *outdated_ap = NM_AP (elt->data);
|
||||
const GByteArray *ssid;
|
||||
|
||||
ssid = nm_ap_get_ssid (outdated_ap);
|
||||
_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);
|
||||
|
||||
_LOGD (LOGD_WIFI_SCAN, "removed %d APs (of %d)",
|
||||
removed, total);
|
||||
|
||||
|
|
@ -2573,7 +2573,6 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
|
|||
NMConnection *connection;
|
||||
NMSettingWireless *s_wireless;
|
||||
const char *cloned_mac;
|
||||
GSList *iter;
|
||||
const char *mode;
|
||||
const char *ap_path;
|
||||
|
||||
|
|
@ -2620,21 +2619,12 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
|
|||
|
||||
/* AP mode never uses a specific object or existing scanned AP */
|
||||
if (priv->mode != NM_802_11_MODE_AP) {
|
||||
|
||||
ap_path = nm_active_connection_get_specific_object (NM_ACTIVE_CONNECTION (req));
|
||||
ap = ap_path ? get_ap_by_path (self, ap_path) : NULL;
|
||||
if (ap)
|
||||
goto done;
|
||||
|
||||
/* Find a compatible AP in the scan list */
|
||||
for (iter = priv->ap_list; iter; iter = g_slist_next (iter)) {
|
||||
NMAccessPoint *candidate = NM_AP (iter->data);
|
||||
|
||||
if (nm_ap_check_compatible (candidate, connection)) {
|
||||
ap = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ap = find_first_compatible_ap (self, connection, FALSE);
|
||||
}
|
||||
|
||||
if (ap) {
|
||||
|
|
@ -2656,8 +2646,8 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
|
|||
else if (nm_ap_is_hotspot (ap))
|
||||
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);
|
||||
g_hash_table_insert (priv->aps, (gpointer) nm_ap_get_dbus_path (ap), ap);
|
||||
g_object_freeze_notify (G_OBJECT (self));
|
||||
set_current_ap (self, ap, FALSE, FALSE);
|
||||
emit_ap_added_removed (self, ACCESS_POINT_ADDED, ap, TRUE);
|
||||
|
|
@ -3223,7 +3213,10 @@ nm_device_wifi_new (NMPlatformLink *platform_device)
|
|||
static void
|
||||
nm_device_wifi_init (NMDeviceWifi *self)
|
||||
{
|
||||
NM_DEVICE_WIFI_GET_PRIVATE (self)->mode = NM_802_11_MODE_INFRA;
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
|
||||
priv->mode = NM_802_11_MODE_INFRA;
|
||||
priv->aps = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -3232,13 +3225,6 @@ dispose (GObject *object)
|
|||
NMDeviceWifi *self = NM_DEVICE_WIFI (object);
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
|
||||
if (priv->disposed) {
|
||||
G_OBJECT_CLASS (nm_device_wifi_parent_class)->dispose (object);
|
||||
return;
|
||||
}
|
||||
|
||||
priv->disposed = TRUE;
|
||||
|
||||
if (priv->periodic_source_id) {
|
||||
g_source_remove (priv->periodic_source_id);
|
||||
priv->periodic_source_id = 0;
|
||||
|
|
@ -3262,6 +3248,7 @@ finalize (GObject *object)
|
|||
|
||||
g_free (priv->perm_hw_addr);
|
||||
g_free (priv->initial_hw_addr);
|
||||
g_clear_pointer (&priv->aps, g_hash_table_unref);
|
||||
|
||||
G_OBJECT_CLASS (nm_device_wifi_parent_class)->finalize (object);
|
||||
}
|
||||
|
|
@ -3272,8 +3259,9 @@ get_property (GObject *object, guint prop_id,
|
|||
{
|
||||
NMDeviceWifi *device = NM_DEVICE_WIFI (object);
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
|
||||
GHashTableIter iter;
|
||||
const char *dbus_path;
|
||||
GPtrArray *array;
|
||||
GSList *iter;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_PERM_HW_ADDRESS:
|
||||
|
|
@ -3289,9 +3277,10 @@ get_property (GObject *object, guint prop_id,
|
|||
g_value_set_uint (value, priv->capabilities);
|
||||
break;
|
||||
case PROP_ACCESS_POINTS:
|
||||
array = g_ptr_array_sized_new (4);
|
||||
for (iter = priv->ap_list; iter; iter = g_slist_next (iter))
|
||||
g_ptr_array_add (array, g_strdup (nm_ap_get_dbus_path (NM_AP (iter->data))));
|
||||
array = g_ptr_array_sized_new (g_hash_table_size (priv->aps));
|
||||
g_hash_table_iter_init (&iter, priv->aps);
|
||||
while (g_hash_table_iter_next (&iter, (gpointer) &dbus_path, NULL))
|
||||
g_ptr_array_add (array, g_strdup (dbus_path));
|
||||
g_value_take_boxed (value, array);
|
||||
break;
|
||||
case PROP_ACTIVE_ACCESS_POINT:
|
||||
|
|
@ -3313,11 +3302,7 @@ static void
|
|||
set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ typedef struct
|
|||
{
|
||||
char *dbus_path;
|
||||
char *supplicant_path; /* D-Bus object path of this AP from wpa_supplicant */
|
||||
guint32 id; /* ID for stable sorting of APs */
|
||||
|
||||
/* Scanned or cached values */
|
||||
GByteArray * ssid;
|
||||
|
|
@ -314,7 +315,8 @@ nm_ap_export_to_dbus (NMAccessPoint *ap)
|
|||
return;
|
||||
}
|
||||
|
||||
priv->dbus_path = g_strdup_printf (NM_DBUS_PATH_ACCESS_POINT "/%d", counter++);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -723,6 +725,14 @@ nm_ap_get_supplicant_path (NMAccessPoint *ap)
|
|||
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)
|
||||
{
|
||||
|
|
@ -1186,16 +1196,17 @@ capabilities_compatible (NM80211ApSecurityFlags a_flags, NM80211ApSecurityFlags
|
|||
}
|
||||
|
||||
NMAccessPoint *
|
||||
nm_ap_match_in_list (NMAccessPoint *find_ap,
|
||||
GSList *ap_list,
|
||||
nm_ap_match_in_hash (NMAccessPoint *find_ap,
|
||||
GHashTable *hash,
|
||||
gboolean strict_match)
|
||||
{
|
||||
GSList *iter;
|
||||
GHashTableIter iter;
|
||||
NMAccessPoint *list_ap;
|
||||
|
||||
g_return_val_if_fail (find_ap != NULL, NULL);
|
||||
|
||||
for (iter = ap_list; iter; iter = g_slist_next (iter)) {
|
||||
NMAccessPoint * list_ap = NM_AP (iter->data);
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ 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);
|
||||
|
||||
|
|
@ -112,8 +114,8 @@ gboolean nm_ap_complete_connection (NMAccessPoint *self,
|
|||
gboolean lock_bssid,
|
||||
GError **error);
|
||||
|
||||
NMAccessPoint * nm_ap_match_in_list (NMAccessPoint *find_ap,
|
||||
GSList *ap_list,
|
||||
NMAccessPoint * nm_ap_match_in_hash (NMAccessPoint *find_ap,
|
||||
GHashTable *hash,
|
||||
gboolean strict_match);
|
||||
|
||||
void nm_ap_dump (NMAccessPoint *ap, const char *prefix);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue