mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-06-02 08:38:19 +02:00
wifi: use GBytes for ssids scan list
Use GBytes instead of GBytesArray. GBytes is immutable and can be shared. It is also the type that we natively get from nm_setting_wireless_get_ssid(). This way we avoid some conversions.
This commit is contained in:
parent
f5792881a0
commit
ced0dd2e4a
3 changed files with 27 additions and 34 deletions
|
|
@ -1083,7 +1083,6 @@ static GPtrArray *
|
|||
ssids_options_to_ptrarray (GVariant *value, GError **error)
|
||||
{
|
||||
GPtrArray *ssids = NULL;
|
||||
GByteArray *ssid_array;
|
||||
GVariant *v;
|
||||
const guint8 *bytes;
|
||||
gsize len;
|
||||
|
|
@ -1099,7 +1098,7 @@ ssids_options_to_ptrarray (GVariant *value, GError **error)
|
|||
}
|
||||
|
||||
if (num_ssids) {
|
||||
ssids = g_ptr_array_new_full (num_ssids, (GDestroyNotify) g_byte_array_unref);
|
||||
ssids = g_ptr_array_new_full (num_ssids, (GDestroyNotify) g_bytes_unref);
|
||||
for (i = 0; i < num_ssids; i++) {
|
||||
v = g_variant_get_child_value (value, i);
|
||||
bytes = g_variant_get_fixed_array (v, &len, sizeof (guint8));
|
||||
|
|
@ -1112,9 +1111,7 @@ ssids_options_to_ptrarray (GVariant *value, GError **error)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ssid_array = g_byte_array_new ();
|
||||
g_byte_array_append (ssid_array, bytes, len);
|
||||
g_ptr_array_add (ssids, ssid_array);
|
||||
g_ptr_array_add (ssids, g_bytes_new (bytes, len));
|
||||
}
|
||||
}
|
||||
return ssids;
|
||||
|
|
@ -1305,7 +1302,7 @@ build_hidden_probe_list (NMDeviceWifi *self)
|
|||
gs_free NMSettingsConnection **connections = NULL;
|
||||
guint i, len;
|
||||
GPtrArray *ssids = NULL;
|
||||
static GByteArray *nullssid = NULL;
|
||||
static GBytes *nullssid = NULL;
|
||||
|
||||
/* Need at least two: wildcard SSID and one or more hidden SSIDs */
|
||||
if (max_scan_ssids < 2)
|
||||
|
|
@ -1320,30 +1317,23 @@ build_hidden_probe_list (NMDeviceWifi *self)
|
|||
|
||||
g_qsort_with_data (connections, len, sizeof (NMSettingsConnection *), nm_settings_connection_cmp_timestamp_p_with_data, NULL);
|
||||
|
||||
ssids = g_ptr_array_new_full (max_scan_ssids, (GDestroyNotify) g_byte_array_unref);
|
||||
ssids = g_ptr_array_new_full (max_scan_ssids, (GDestroyNotify) g_bytes_unref);
|
||||
|
||||
/* Add wildcard SSID using a static wildcard SSID used for every scan */
|
||||
if (G_UNLIKELY (nullssid == NULL))
|
||||
nullssid = g_byte_array_new ();
|
||||
g_ptr_array_add (ssids, g_byte_array_ref (nullssid));
|
||||
nullssid = g_bytes_new_static ("", 0);
|
||||
g_ptr_array_add (ssids, g_bytes_ref (nullssid));
|
||||
|
||||
for (i = 0; connections[i]; i++) {
|
||||
NMSettingWireless *s_wifi;
|
||||
GBytes *ssid;
|
||||
GByteArray *ssid_array;
|
||||
|
||||
if (i >= max_scan_ssids - 1)
|
||||
break;
|
||||
|
||||
s_wifi = (NMSettingWireless *) nm_connection_get_setting_wireless (NM_CONNECTION (connections[i]));
|
||||
g_assert (s_wifi);
|
||||
ssid = nm_setting_wireless_get_ssid (s_wifi);
|
||||
g_assert (ssid);
|
||||
ssid_array = g_byte_array_new ();
|
||||
g_byte_array_append (ssid_array,
|
||||
g_bytes_get_data (ssid, NULL),
|
||||
g_bytes_get_size (ssid));
|
||||
g_ptr_array_add (ssids, ssid_array);
|
||||
g_ptr_array_add (ssids, g_bytes_ref (ssid));
|
||||
}
|
||||
|
||||
return ssids;
|
||||
|
|
@ -1370,24 +1360,22 @@ request_wireless_scan (NMDeviceWifi *self,
|
|||
|
||||
_LOGD (LOGD_WIFI, "wifi-scan: scanning requested");
|
||||
|
||||
if (!ssids) {
|
||||
if (!ssids)
|
||||
ssids = hidden_ssids = build_hidden_probe_list (self);
|
||||
}
|
||||
|
||||
if (_LOGD_ENABLED (LOGD_WIFI)) {
|
||||
if (ssids) {
|
||||
const GByteArray *ssid;
|
||||
guint i;
|
||||
char *foo;
|
||||
|
||||
for (i = 0; i < ssids->len; i++) {
|
||||
ssid = g_ptr_array_index (ssids, i);
|
||||
foo = ssid->len > 0
|
||||
? nm_utils_ssid_to_utf8 (ssid->data, ssid->len)
|
||||
: NULL;
|
||||
gs_free char *foo = NULL;
|
||||
const guint8 *p;
|
||||
gsize l;
|
||||
|
||||
p = g_bytes_get_data (ssids->pdata[i], &l);
|
||||
foo = l > 0 ? nm_utils_ssid_to_utf8 (p, l) : NULL;
|
||||
_LOGD (LOGD_WIFI, "wifi-scan: (%u) probe scanning SSID %s%s%s",
|
||||
i, NM_PRINT_FMT_QUOTED (foo, "\"", foo, "\"", "*any*"));
|
||||
g_free (foo);
|
||||
}
|
||||
} else
|
||||
_LOGD (LOGD_WIFI, "wifi-scan: no SSIDs to probe scan");
|
||||
|
|
@ -1395,7 +1383,9 @@ request_wireless_scan (NMDeviceWifi *self,
|
|||
|
||||
_hw_addr_set_scanning (self, FALSE);
|
||||
|
||||
nm_supplicant_interface_request_scan (priv->sup_iface, ssids);
|
||||
nm_supplicant_interface_request_scan (priv->sup_iface,
|
||||
ssids ? (GBytes *const*) ssids->pdata : NULL,
|
||||
ssids ? ssids->len : 0u);
|
||||
request_started = TRUE;
|
||||
} else
|
||||
_LOGD (LOGD_WIFI, "wifi-scan: scanning requested but not allowed at this time");
|
||||
|
|
|
|||
|
|
@ -1789,7 +1789,9 @@ scan_request_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data)
|
|||
}
|
||||
|
||||
void
|
||||
nm_supplicant_interface_request_scan (NMSupplicantInterface *self, const GPtrArray *ssids)
|
||||
nm_supplicant_interface_request_scan (NMSupplicantInterface *self,
|
||||
GBytes *const*ssids,
|
||||
guint ssids_len)
|
||||
{
|
||||
NMSupplicantInterfacePrivate *priv;
|
||||
GVariantBuilder builder;
|
||||
|
|
@ -1803,15 +1805,14 @@ nm_supplicant_interface_request_scan (NMSupplicantInterface *self, const GPtrArr
|
|||
g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
|
||||
g_variant_builder_add (&builder, "{sv}", "Type", g_variant_new_string ("active"));
|
||||
g_variant_builder_add (&builder, "{sv}", "AllowRoam", g_variant_new_boolean (FALSE));
|
||||
if (ssids) {
|
||||
if (ssids_len > 0) {
|
||||
GVariantBuilder ssids_builder;
|
||||
|
||||
g_variant_builder_init (&ssids_builder, G_VARIANT_TYPE_BYTESTRING_ARRAY);
|
||||
for (i = 0; i < ssids->len; i++) {
|
||||
GByteArray *ssid = g_ptr_array_index (ssids, i);
|
||||
for (i = 0; i < ssids_len; i++) {
|
||||
nm_assert (ssids[i]);
|
||||
g_variant_builder_add (&ssids_builder, "@ay",
|
||||
g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
|
||||
ssid->data, ssid->len, 1));
|
||||
nm_utils_gbytes_to_variant_ay (ssids[i]));
|
||||
}
|
||||
g_variant_builder_add (&builder, "{sv}", "SSIDs", g_variant_builder_end (&ssids_builder));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,9 @@ void nm_supplicant_interface_disconnect (NMSupplicantInterface * iface);
|
|||
|
||||
const char *nm_supplicant_interface_get_object_path (NMSupplicantInterface * iface);
|
||||
|
||||
void nm_supplicant_interface_request_scan (NMSupplicantInterface * self, const GPtrArray *ssids);
|
||||
void nm_supplicant_interface_request_scan (NMSupplicantInterface *self,
|
||||
GBytes *const*ssids,
|
||||
guint ssids_len);
|
||||
|
||||
NMSupplicantInterfaceState nm_supplicant_interface_get_state (NMSupplicantInterface * self);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue