diff options
author | Thomas Haller <thaller@redhat.com> | 2019-08-22 08:25:39 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-08-28 16:27:00 +0200 |
commit | 81816ebffab800ed7207bf51049c8b9c932c1b44 (patch) | |
tree | 64e7a0dd4c807900eed5250ec5db43f1f01d583d | |
parent | 1f7e0f1d1f642db7a45a90cadbc3f2a2bda47fa2 (diff) | |
download | NetworkManager-81816ebffab800ed7207bf51049c8b9c932c1b44.tar.gz |
device/wifi: various cleanup in act_stage1_prepare()
The only change in behavior is in act_stage1_prepare().
That changes compared to before that we also set the specific
object path if it was already set (and we looked up the AP by
specific object to start with).
Also, for existing APs that we found with nm_wifi_aps_find_first_compatible(),
it changes the order of calling set_current_ap() before nm_active_connection_set_specific_object().
That should not make a different though. I anyway wonder why we even bother to
set the specific object on the AC. Maybe that should be revisited.
-rw-r--r-- | src/devices/wifi/nm-device-wifi.c | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 4fa3f18a45..a587348c89 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -411,7 +411,9 @@ set_current_ap (NMDeviceWifi *self, NMWifiAP *new_ap, gboolean recheck_available NM80211Mode mode = nm_wifi_ap_get_mode (old_ap); /* Remove any AP from the internal list if it was created by NM or isn't known to the supplicant */ - if (mode == NM_802_11_MODE_ADHOC || mode == NM_802_11_MODE_AP || nm_wifi_ap_get_fake (old_ap)) + if ( NM_IN_SET (mode, NM_802_11_MODE_ADHOC, + NM_802_11_MODE_AP) + || nm_wifi_ap_get_fake (old_ap)) ap_add_remove (self, FALSE, old_ap, recheck_available_connections); g_object_unref (old_ap); } @@ -1229,7 +1231,8 @@ scanning_prohibited (NMDeviceWifi *self, gboolean periodic) /* Don't scan when a an AP or Ad-Hoc connection is active as it will * disrupt connected clients or peers. */ - if (priv->mode == NM_802_11_MODE_ADHOC || priv->mode == NM_802_11_MODE_AP) + if (NM_IN_SET (priv->mode, NM_802_11_MODE_ADHOC, + NM_802_11_MODE_AP)) return TRUE; switch (nm_device_get_state (NM_DEVICE (self))) { @@ -2409,9 +2412,9 @@ supplicant_connection_timeout_cb (gpointer user_data) connection = nm_act_request_get_applied_connection (req); g_assert (connection); - if ( priv->mode == NM_802_11_MODE_ADHOC - || priv->mode == NM_802_11_MODE_MESH - || priv->mode == NM_802_11_MODE_AP) { + if (NM_IN_SET (priv->mode, NM_802_11_MODE_ADHOC, + NM_802_11_MODE_MESH, + NM_802_11_MODE_AP)) { /* In Ad-Hoc and AP modes there's nothing to check the encryption key * (if any), so supplicant timeouts here are almost certainly the wifi * driver being really stupid. @@ -2619,6 +2622,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason) NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); NMActStageReturn ret; NMWifiAP *ap = NULL; + gs_unref_object NMWifiAP *ap_fake = NULL; NMActRequest *req; NMConnection *connection; NMSettingWireless *s_wireless; @@ -2662,44 +2666,39 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason) return NM_ACT_STAGE_RETURN_FAILURE; /* AP and Mesh modes never use a specific object or existing scanned AP */ - if (priv->mode != NM_802_11_MODE_AP && priv->mode != NM_802_11_MODE_MESH) { + if (!NM_IN_SET (priv->mode, NM_802_11_MODE_AP, + NM_802_11_MODE_MESH)) { ap_path = nm_active_connection_get_specific_object (NM_ACTIVE_CONNECTION (req)); - ap = ap_path ? nm_wifi_ap_lookup_for_device (NM_DEVICE (self), ap_path) : NULL; - if (ap) - goto done; - - ap = nm_wifi_aps_find_first_compatible (&priv->aps_lst_head, connection); + ap = ap_path + ? nm_wifi_ap_lookup_for_device (NM_DEVICE (self), ap_path) + : NULL; } + if (!ap) + ap = nm_wifi_aps_find_first_compatible (&priv->aps_lst_head, connection); - if (ap) { - nm_active_connection_set_specific_object (NM_ACTIVE_CONNECTION (req), - nm_dbus_object_get_path (NM_DBUS_OBJECT (ap))); - goto done; - } + if (!ap) { + /* If the user is trying to connect to an AP that NM doesn't yet know about + * (hidden network or something), starting a Hotspot or joining a Mesh, + * create a fake APfrom the security settings in the connection. This "fake" + * AP gets used until the real one is found in the scan list (Ad-Hoc or Hidden), + * or until the device is deactivated (Hotspot). + */ + ap_fake = nm_wifi_ap_new_fake_from_connection (connection); + if (!ap_fake) + g_return_val_if_reached (NM_ACT_STAGE_RETURN_FAILURE); - /* If the user is trying to connect to an AP that NM doesn't yet know about - * (hidden network or something), starting a Hotspot or joining a Mesh, - * create a fake APfrom the security settings in the connection. This "fake" - * AP gets used until the real one is found in the scan list (Ad-Hoc or Hidden), - * or until the device is deactivated (Hotspot). - */ - ap = nm_wifi_ap_new_fake_from_connection (connection); - g_return_val_if_fail (ap != NULL, NM_ACT_STAGE_RETURN_FAILURE); + if (nm_wifi_ap_is_hotspot (ap_fake)) + nm_wifi_ap_set_address (ap_fake, nm_device_get_hw_address (device)); - if (nm_wifi_ap_is_hotspot (ap)) - nm_wifi_ap_set_address (ap, nm_device_get_hw_address (device)); + g_object_freeze_notify (G_OBJECT (self)); + ap_add_remove (self, TRUE, ap_fake, TRUE); + g_object_thaw_notify (G_OBJECT (self)); + ap = ap_fake; + } - g_object_freeze_notify (G_OBJECT (self)); - ap_add_remove (self, TRUE, ap, TRUE); - g_object_thaw_notify (G_OBJECT (self)); set_current_ap (self, ap, FALSE); nm_active_connection_set_specific_object (NM_ACTIVE_CONNECTION (req), nm_dbus_object_get_path (NM_DBUS_OBJECT (ap))); - g_object_unref (ap); - return NM_ACT_STAGE_RETURN_SUCCESS; - -done: - set_current_ap (self, ap, TRUE); return NM_ACT_STAGE_RETURN_SUCCESS; } @@ -2834,8 +2833,8 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) * if the user didn't specify one and we didn't find an AP that matched * the connection, just pick a frequency the device supports. */ - if ( ap_mode == NM_802_11_MODE_ADHOC - || ap_mode == NM_802_11_MODE_MESH + if ( NM_IN_SET (ap_mode, NM_802_11_MODE_ADHOC, + NM_802_11_MODE_MESH) || nm_wifi_ap_is_hotspot (ap)) ensure_hotspot_frequency (self, s_wireless, ap); |