wifi: don't use GBytesArray for NMWifiAP's ssid
GBytes makes more sense, because it's immutable. Also, since at other places we use GBytes, having different types is combersome and requires needless conversions. Also: - avoid nm_utils_escape_ssid() instead of _nm_utils_ssid_to_string(). We use nm_utils_escape_ssid() when we want to log the SSID. However, it does not escape newlines, which is bad. - also no longer use nm_utils_same_ssid(). Since it no longer treated trailing NUL special, it is not different from g_bytes_equal(). - also, don't use nm_utils_ssid_to_utf8() for logging anymore. For logging, _nm_utils_ssid_escape_utf8safe() is better because it is loss-less escaping which can be unambigously reverted.
This commit is contained in:
@@ -328,6 +328,13 @@ gboolean _nm_dbus_error_has_name (GError *error,
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
char *_nm_utils_ssid_to_string_arr (const guint8 *ssid, gsize len);
|
||||
char *_nm_utils_ssid_to_string (GBytes *ssid);
|
||||
char *_nm_utils_ssid_to_utf8 (GBytes *ssid);
|
||||
gboolean _nm_utils_is_empty_ssid (GBytes *ssid);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
gboolean _nm_vpn_plugin_info_check_file (const char *filename,
|
||||
gboolean check_absolute,
|
||||
gboolean do_validate_filename,
|
||||
|
@@ -336,6 +336,18 @@ nm_utils_ssid_to_utf8 (const guint8 *ssid, gsize len)
|
||||
return converted;
|
||||
}
|
||||
|
||||
char *
|
||||
_nm_utils_ssid_to_utf8 (GBytes *ssid)
|
||||
{
|
||||
const guint8 *p;
|
||||
gsize l;
|
||||
|
||||
g_return_val_if_fail (ssid, NULL);
|
||||
|
||||
p = g_bytes_get_data (ssid, &l);
|
||||
return nm_utils_ssid_to_utf8 (p, l);
|
||||
}
|
||||
|
||||
/* Shamelessly ripped from the Linux kernel ieee80211 stack */
|
||||
/**
|
||||
* nm_utils_is_empty_ssid:
|
||||
@@ -363,6 +375,18 @@ nm_utils_is_empty_ssid (const guint8 *ssid, gsize len)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_nm_utils_is_empty_ssid (GBytes *ssid)
|
||||
{
|
||||
const guint8 *p;
|
||||
gsize l;
|
||||
|
||||
g_return_val_if_fail (ssid, FALSE);
|
||||
|
||||
p = g_bytes_get_data (ssid, &l);
|
||||
return nm_utils_is_empty_ssid (p, l);
|
||||
}
|
||||
|
||||
#define ESSID_MAX_SIZE 32
|
||||
|
||||
/**
|
||||
@@ -404,6 +428,37 @@ nm_utils_escape_ssid (const guint8 *ssid, gsize len)
|
||||
return escaped;
|
||||
}
|
||||
|
||||
char *
|
||||
_nm_utils_ssid_to_string_arr (const guint8 *ssid, gsize len)
|
||||
{
|
||||
char *s_copy;
|
||||
const char *s_cnst;
|
||||
|
||||
if (len == 0)
|
||||
return g_strdup ("(empty)");
|
||||
|
||||
s_cnst = nm_utils_buf_utf8safe_escape (ssid, len, NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL, &s_copy);
|
||||
nm_assert (s_cnst);
|
||||
|
||||
if (nm_utils_is_empty_ssid (ssid, len))
|
||||
return g_strdup_printf ("\"%s\" (hidden)", s_cnst);
|
||||
|
||||
return g_strdup_printf ("\"%s\"", s_cnst);
|
||||
}
|
||||
|
||||
char *
|
||||
_nm_utils_ssid_to_string (GBytes *ssid)
|
||||
{
|
||||
gconstpointer p;
|
||||
gsize l;
|
||||
|
||||
if (!ssid)
|
||||
return g_strdup ("(none)");
|
||||
|
||||
p = g_bytes_get_data (ssid, &l);
|
||||
return _nm_utils_ssid_to_string_arr (p, l);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_same_ssid:
|
||||
* @ssid1: (array length=len1): the first SSID to compare
|
||||
|
@@ -473,7 +473,7 @@ is_connection_known_network (NMConnection *connection)
|
||||
{
|
||||
NMSettingWireless *s_wireless;
|
||||
GBytes *ssid;
|
||||
gs_free char *str_ssid = NULL;
|
||||
gs_free char *ssid_utf8 = NULL;
|
||||
|
||||
s_wireless = nm_connection_get_setting_wireless (connection);
|
||||
if (!s_wireless)
|
||||
@@ -483,11 +483,9 @@ is_connection_known_network (NMConnection *connection)
|
||||
if (!ssid)
|
||||
return FALSE;
|
||||
|
||||
str_ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL),
|
||||
g_bytes_get_size (ssid));
|
||||
|
||||
ssid_utf8 = _nm_utils_ssid_to_utf8 (ssid);
|
||||
return nm_iwd_manager_is_known_network (nm_iwd_manager_get (),
|
||||
str_ssid,
|
||||
ssid_utf8,
|
||||
get_connection_iwd_security (connection));
|
||||
}
|
||||
|
||||
@@ -637,10 +635,9 @@ complete_connection (NMDevice *device,
|
||||
NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE (self);
|
||||
NMSettingWireless *s_wifi;
|
||||
const char *setting_mac;
|
||||
char *str_ssid = NULL;
|
||||
gs_free char *ssid_utf8 = NULL;
|
||||
NMWifiAP *ap;
|
||||
const GByteArray *ssid = NULL;
|
||||
GByteArray *tmp_ssid = NULL;
|
||||
GBytes *ssid;
|
||||
GBytes *setting_ssid = NULL;
|
||||
const char *perm_hw_addr;
|
||||
const char *mode;
|
||||
@@ -704,8 +701,7 @@ complete_connection (NMDevice *device,
|
||||
}
|
||||
|
||||
ssid = nm_wifi_ap_get_ssid (ap);
|
||||
|
||||
if (ssid == NULL) {
|
||||
if (!ssid) {
|
||||
g_set_error_literal (error,
|
||||
NM_DEVICE_ERROR,
|
||||
NM_DEVICE_ERROR_INVALID_CONNECTION,
|
||||
@@ -716,25 +712,18 @@ complete_connection (NMDevice *device,
|
||||
if (!nm_wifi_ap_complete_connection (ap,
|
||||
connection,
|
||||
nm_wifi_utils_is_manf_default_ssid (ssid),
|
||||
error)) {
|
||||
if (tmp_ssid)
|
||||
g_byte_array_unref (tmp_ssid);
|
||||
error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
str_ssid = nm_utils_ssid_to_utf8 (ssid->data, ssid->len);
|
||||
|
||||
ssid_utf8 = _nm_utils_ssid_to_utf8 (ssid);
|
||||
nm_utils_complete_generic (nm_device_get_platform (device),
|
||||
connection,
|
||||
NM_SETTING_WIRELESS_SETTING_NAME,
|
||||
existing_connections,
|
||||
str_ssid,
|
||||
str_ssid,
|
||||
ssid_utf8,
|
||||
ssid_utf8,
|
||||
NULL,
|
||||
TRUE);
|
||||
g_free (str_ssid);
|
||||
if (tmp_ssid)
|
||||
g_byte_array_unref (tmp_ssid);
|
||||
|
||||
/* 8021x networks can only be used if they've been provisioned on the IWD side and
|
||||
* thus are Known Networks.
|
||||
@@ -1251,7 +1240,7 @@ network_connect_cb (GObject *source, GAsyncResult *res, gpointer user_data)
|
||||
NMConnection *connection;
|
||||
NMSettingWireless *s_wifi;
|
||||
GBytes *ssid;
|
||||
gs_free char *str_ssid = NULL;
|
||||
gs_free char *ssid_utf8 = NULL;
|
||||
|
||||
if (!_nm_dbus_proxy_call_finish (G_DBUS_PROXY (source), res,
|
||||
G_VARIANT_TYPE ("()"),
|
||||
@@ -1303,15 +1292,14 @@ network_connect_cb (GObject *source, GAsyncResult *res, gpointer user_data)
|
||||
if (!ssid)
|
||||
goto failed;
|
||||
|
||||
str_ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL),
|
||||
g_bytes_get_size (ssid));
|
||||
ssid_utf8 = _nm_utils_ssid_to_utf8 (ssid);
|
||||
|
||||
_LOGI (LOGD_DEVICE | LOGD_WIFI,
|
||||
"Activation: (wifi) Stage 2 of 5 (Device Configure) successful. Connected to '%s'.",
|
||||
str_ssid);
|
||||
ssid_utf8);
|
||||
nm_device_activate_schedule_stage3_ip_config_start (device);
|
||||
|
||||
nm_iwd_manager_network_connected (nm_iwd_manager_get (), str_ssid,
|
||||
nm_iwd_manager_network_connected (nm_iwd_manager_get (), ssid_utf8,
|
||||
get_connection_iwd_security (connection));
|
||||
|
||||
return;
|
||||
|
@@ -761,10 +761,9 @@ complete_connection (NMDevice *device,
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
NMSettingWireless *s_wifi;
|
||||
const char *setting_mac;
|
||||
char *str_ssid = NULL;
|
||||
gs_free char *ssid_utf8 = NULL;
|
||||
NMWifiAP *ap;
|
||||
const GByteArray *ssid = NULL;
|
||||
GByteArray *tmp_ssid = NULL;
|
||||
GBytes *ssid = NULL;
|
||||
GBytes *setting_ssid = NULL;
|
||||
gboolean hidden = FALSE;
|
||||
const char *perm_hw_addr;
|
||||
@@ -836,19 +835,14 @@ complete_connection (NMDevice *device,
|
||||
|
||||
if (ap)
|
||||
ssid = nm_wifi_ap_get_ssid (ap);
|
||||
|
||||
if (ssid == NULL) {
|
||||
/* The AP must be hidden. Connecting to a WiFi AP requires the SSID
|
||||
* as part of the initial handshake, so check the connection details
|
||||
* for the SSID. The AP object will still be used for encryption
|
||||
* settings and such.
|
||||
*/
|
||||
setting_ssid = nm_setting_wireless_get_ssid (s_wifi);
|
||||
if (setting_ssid) {
|
||||
ssid = tmp_ssid = g_byte_array_new ();
|
||||
g_byte_array_append (tmp_ssid,
|
||||
g_bytes_get_data (setting_ssid, NULL),
|
||||
g_bytes_get_size (setting_ssid));
|
||||
}
|
||||
ssid = nm_setting_wireless_get_ssid (s_wifi);
|
||||
}
|
||||
|
||||
if (ssid == NULL) {
|
||||
@@ -871,11 +865,8 @@ complete_connection (NMDevice *device,
|
||||
if (!nm_wifi_ap_complete_connection (ap,
|
||||
connection,
|
||||
nm_wifi_utils_is_manf_default_ssid (ssid),
|
||||
error)) {
|
||||
if (tmp_ssid)
|
||||
g_byte_array_unref (tmp_ssid);
|
||||
error))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* The kernel doesn't support Ad-Hoc WPA connections well at this time,
|
||||
@@ -888,24 +879,18 @@ complete_connection (NMDevice *device,
|
||||
NM_CONNECTION_ERROR_INVALID_SETTING,
|
||||
_("WPA Ad-Hoc disabled due to kernel bugs"));
|
||||
g_prefix_error (error, "%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
|
||||
if (tmp_ssid)
|
||||
g_byte_array_unref (tmp_ssid);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
str_ssid = nm_utils_ssid_to_utf8 (ssid->data, ssid->len);
|
||||
|
||||
ssid_utf8 = _nm_utils_ssid_to_utf8 (ssid);
|
||||
nm_utils_complete_generic (nm_device_get_platform (device),
|
||||
connection,
|
||||
NM_SETTING_WIRELESS_SETTING_NAME,
|
||||
existing_connections,
|
||||
str_ssid,
|
||||
str_ssid,
|
||||
ssid_utf8,
|
||||
ssid_utf8,
|
||||
NULL,
|
||||
TRUE);
|
||||
g_free (str_ssid);
|
||||
if (tmp_ssid)
|
||||
g_byte_array_unref (tmp_ssid);
|
||||
|
||||
if (hidden)
|
||||
g_object_set (s_wifi, NM_SETTING_WIRELESS_HIDDEN, TRUE, NULL);
|
||||
@@ -1368,14 +1353,14 @@ request_wireless_scan (NMDeviceWifi *self,
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < ssids->len; i++) {
|
||||
gs_free char *foo = NULL;
|
||||
const guint8 *p;
|
||||
gsize l;
|
||||
gs_free char *ssid_str = NULL;
|
||||
GBytes *ssid = ssids->pdata[i];
|
||||
|
||||
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*"));
|
||||
ssid_str = g_bytes_get_size (ssid) > 0
|
||||
? _nm_utils_ssid_to_string (ssid)
|
||||
: NULL;
|
||||
_LOGD (LOGD_WIFI, "wifi-scan: (%u) probe scanning SSID %s",
|
||||
i, ssid_str ?: "*any*");
|
||||
}
|
||||
} else
|
||||
_LOGD (LOGD_WIFI, "wifi-scan: no SSIDs to probe scan");
|
||||
@@ -1550,7 +1535,7 @@ supplicant_iface_bss_updated_cb (NMSupplicantInterface *iface,
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
NMDeviceState state;
|
||||
NMWifiAP *found_ap = NULL;
|
||||
const GByteArray *ssid;
|
||||
GBytes *ssid;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (properties != NULL);
|
||||
@@ -1579,15 +1564,19 @@ supplicant_iface_bss_updated_cb (NMSupplicantInterface *iface,
|
||||
|
||||
/* Let the manager try to fill in the SSID from seen-bssids lists */
|
||||
ssid = nm_wifi_ap_get_ssid (ap);
|
||||
if (!ssid || nm_utils_is_empty_ssid (ssid->data, ssid->len)) {
|
||||
if (!ssid || _nm_utils_is_empty_ssid (ssid)) {
|
||||
/* Try to fill the SSID from the AP database */
|
||||
try_fill_ssid_for_hidden_ap (self, ap);
|
||||
|
||||
ssid = nm_wifi_ap_get_ssid (ap);
|
||||
if (ssid && (nm_utils_is_empty_ssid (ssid->data, ssid->len) == FALSE)) {
|
||||
if ( ssid
|
||||
&& !_nm_utils_is_empty_ssid (ssid)) {
|
||||
gs_free char *s = NULL;
|
||||
|
||||
/* Yay, matched it, no longer treat as hidden */
|
||||
_LOGD (LOGD_WIFI, "matched hidden AP %s => '%s'",
|
||||
nm_wifi_ap_get_address (ap), nm_utils_escape_ssid (ssid->data, ssid->len));
|
||||
_LOGD (LOGD_WIFI, "matched hidden AP %s => %s",
|
||||
nm_wifi_ap_get_address (ap),
|
||||
(s = _nm_utils_ssid_to_string (ssid)));
|
||||
} else {
|
||||
/* Didn't have an entry for this AP in the database */
|
||||
_LOGD (LOGD_WIFI, "failed to match hidden AP %s",
|
||||
@@ -2044,6 +2033,7 @@ supplicant_iface_state_cb (NMSupplicantInterface *iface,
|
||||
NMConnection *connection;
|
||||
NMSettingWireless *s_wifi;
|
||||
GBytes *ssid;
|
||||
gs_free char *ssid_str = NULL;
|
||||
|
||||
connection = nm_device_get_applied_connection (NM_DEVICE (self));
|
||||
g_return_if_fail (connection);
|
||||
@@ -2055,11 +2045,11 @@ supplicant_iface_state_cb (NMSupplicantInterface *iface,
|
||||
g_return_if_fail (ssid);
|
||||
|
||||
_LOGI (LOGD_DEVICE | LOGD_WIFI,
|
||||
"Activation: (wifi) Stage 2 of 5 (Device Configure) successful. %s '%s'.",
|
||||
priv->mode == NM_802_11_MODE_AP ? "Started Wi-Fi Hotspot" :
|
||||
"Connected to wireless network",
|
||||
ssid ? nm_utils_escape_ssid (g_bytes_get_data (ssid, NULL),
|
||||
g_bytes_get_size (ssid)) : "(none)");
|
||||
"Activation: (wifi) Stage 2 of 5 (Device Configure) successful. %s %s",
|
||||
priv->mode == NM_802_11_MODE_AP
|
||||
? "Started Wi-Fi Hotspot"
|
||||
: "Connected to wireless network",
|
||||
(ssid_str = _nm_utils_ssid_to_string (ssid)));
|
||||
nm_device_activate_schedule_stage3_ip_config_start (device);
|
||||
} else if (devstate == NM_DEVICE_STATE_ACTIVATED)
|
||||
periodic_update (self);
|
||||
@@ -2167,9 +2157,11 @@ supplicant_iface_notify_current_bss (NMSupplicantInterface *iface,
|
||||
|
||||
if (new_ap != priv->current_ap) {
|
||||
const char *new_bssid = NULL;
|
||||
const GByteArray *new_ssid = NULL;
|
||||
GBytes *new_ssid = NULL;
|
||||
const char *old_bssid = NULL;
|
||||
const GByteArray *old_ssid = NULL;
|
||||
GBytes *old_ssid = NULL;
|
||||
gs_free char *new_ssid_s = NULL;
|
||||
gs_free char *old_ssid_s = NULL;
|
||||
|
||||
/* Don't ever replace a "fake" current AP if we don't know about the
|
||||
* supplicant's current BSS yet. It'll get replaced when we receive
|
||||
@@ -2190,9 +2182,9 @@ supplicant_iface_notify_current_bss (NMSupplicantInterface *iface,
|
||||
|
||||
_LOGD (LOGD_WIFI, "roamed from BSSID %s (%s) to %s (%s)",
|
||||
old_bssid ?: "(none)",
|
||||
old_ssid ? nm_utils_escape_ssid (old_ssid->data, old_ssid->len) : "(none)",
|
||||
(old_ssid_s = _nm_utils_ssid_to_string (old_ssid)),
|
||||
new_bssid ?: "(none)",
|
||||
new_ssid ? nm_utils_escape_ssid (new_ssid->data, new_ssid->len) : "(none)");
|
||||
(new_ssid_s = _nm_utils_ssid_to_string (new_ssid)));
|
||||
|
||||
set_current_ap (self, new_ap, TRUE);
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ struct _NMWifiAPPrivate {
|
||||
char *supplicant_path; /* D-Bus object path of this AP from wpa_supplicant */
|
||||
|
||||
/* Scanned or cached values */
|
||||
GByteArray * ssid;
|
||||
GBytes * ssid;
|
||||
char * address;
|
||||
NM80211Mode mode;
|
||||
guint8 strength;
|
||||
@@ -95,7 +95,7 @@ nm_wifi_ap_get_supplicant_path (NMWifiAP *ap)
|
||||
return NM_WIFI_AP_GET_PRIVATE (ap)->supplicant_path;
|
||||
}
|
||||
|
||||
const GByteArray *
|
||||
GBytes *
|
||||
nm_wifi_ap_get_ssid (const NMWifiAP *ap)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_WIFI_AP (ap), NULL);
|
||||
@@ -103,18 +103,6 @@ nm_wifi_ap_get_ssid (const NMWifiAP *ap)
|
||||
return NM_WIFI_AP_GET_PRIVATE (ap)->ssid;
|
||||
}
|
||||
|
||||
static GVariant *
|
||||
nm_wifi_ap_get_ssid_as_variant (const NMWifiAP *self)
|
||||
{
|
||||
const NMWifiAPPrivate *priv = NM_WIFI_AP_GET_PRIVATE (self);
|
||||
|
||||
if (priv->ssid) {
|
||||
return g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
|
||||
priv->ssid->data, priv->ssid->len, 1);
|
||||
} else
|
||||
return g_variant_new_array (G_VARIANT_TYPE_BYTE, NULL, 0);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_wifi_ap_set_ssid (NMWifiAP *ap, const guint8 *ssid, gsize len)
|
||||
{
|
||||
@@ -126,20 +114,22 @@ nm_wifi_ap_set_ssid (NMWifiAP *ap, const guint8 *ssid, gsize len)
|
||||
priv = NM_WIFI_AP_GET_PRIVATE (ap);
|
||||
|
||||
/* same SSID */
|
||||
if ((ssid && priv->ssid) && (len == priv->ssid->len)) {
|
||||
if (!memcmp (ssid, priv->ssid->data, len))
|
||||
if (priv->ssid) {
|
||||
const guint8 *p;
|
||||
gsize l;
|
||||
|
||||
p = g_bytes_get_data (priv->ssid, &l);
|
||||
if ( l == len
|
||||
&& !memcmp (p, ssid, len))
|
||||
return FALSE;
|
||||
} else {
|
||||
if (len == 0)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
nm_clear_pointer (&priv->ssid, g_bytes_unref);
|
||||
if (len > 0)
|
||||
priv->ssid = g_bytes_new (ssid, len);
|
||||
|
||||
_notify (ap, PROP_SSID);
|
||||
return TRUE;
|
||||
@@ -961,7 +951,7 @@ nm_wifi_ap_to_string (const NMWifiAP *self,
|
||||
const char *supplicant_id = "-";
|
||||
const char *export_path;
|
||||
guint32 chan;
|
||||
char b1[200];
|
||||
gs_free char *ssid_to_free = NULL;
|
||||
|
||||
g_return_val_if_fail (NM_IS_WIFI_AP (self), NULL);
|
||||
|
||||
@@ -977,10 +967,9 @@ nm_wifi_ap_to_string (const NMWifiAP *self,
|
||||
export_path = "/";
|
||||
|
||||
g_snprintf (str_buf, buf_len,
|
||||
"%17s %-32s [ %c %3u %3u%% %c W:%04X R:%04X ] %3us sup:%s [nm:%s]",
|
||||
"%17s %-35s [ %c %3u %3u%% %c W:%04X R:%04X ] %3us sup:%s [nm:%s]",
|
||||
priv->address ?: "(none)",
|
||||
nm_sprintf_buf (b1, "%s%s%s",
|
||||
NM_PRINT_FMT_QUOTED (priv->ssid, "\"", nm_utils_escape_ssid (priv->ssid->data, priv->ssid->len), "\"", "(none)")),
|
||||
(ssid_to_free = _nm_utils_ssid_to_string (priv->ssid)),
|
||||
(priv->mode == NM_802_11_MODE_ADHOC
|
||||
? '*'
|
||||
: (priv->hotspot
|
||||
@@ -1032,15 +1021,12 @@ nm_wifi_ap_check_compatible (NMWifiAP *self,
|
||||
return FALSE;
|
||||
|
||||
ssid = nm_setting_wireless_get_ssid (s_wireless);
|
||||
if ( (ssid && !priv->ssid)
|
||||
|| (priv->ssid && !ssid))
|
||||
return FALSE;
|
||||
|
||||
if ( ssid && priv->ssid &&
|
||||
!nm_utils_same_ssid (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid),
|
||||
priv->ssid->data, priv->ssid->len,
|
||||
FALSE))
|
||||
return FALSE;
|
||||
if (ssid != priv->ssid) {
|
||||
if (!ssid || !priv->ssid)
|
||||
return FALSE;
|
||||
if (!g_bytes_equal (ssid, priv->ssid))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bssid = nm_setting_wireless_get_bssid (s_wireless);
|
||||
if (bssid && (!priv->address || !nm_utils_hwaddr_matches (bssid, -1, priv->address, -1)))
|
||||
@@ -1126,7 +1112,8 @@ get_property (GObject *object, guint prop_id,
|
||||
g_value_set_uint (value, priv->rsn_flags);
|
||||
break;
|
||||
case PROP_SSID:
|
||||
g_value_take_variant (value, nm_wifi_ap_get_ssid_as_variant (self));
|
||||
g_value_take_variant (value,
|
||||
nm_utils_gbytes_to_variant_ay (priv->ssid));
|
||||
break;
|
||||
case PROP_FREQUENCY:
|
||||
g_value_set_uint (value, priv->freq);
|
||||
@@ -1334,7 +1321,7 @@ finalize (GObject *object)
|
||||
|
||||
g_free (priv->supplicant_path);
|
||||
if (priv->ssid)
|
||||
g_byte_array_free (priv->ssid, TRUE);
|
||||
g_bytes_unref (priv->ssid);
|
||||
g_free (priv->address);
|
||||
|
||||
G_OBJECT_CLASS (nm_wifi_ap_parent_class)->finalize (object);
|
||||
|
@@ -72,7 +72,7 @@ gboolean nm_wifi_ap_complete_connection (NMWifiAP *self,
|
||||
GError **error);
|
||||
|
||||
const char * nm_wifi_ap_get_supplicant_path (NMWifiAP *ap);
|
||||
const GByteArray *nm_wifi_ap_get_ssid (const NMWifiAP *ap);
|
||||
GBytes *nm_wifi_ap_get_ssid (const NMWifiAP *ap);
|
||||
gboolean nm_wifi_ap_set_ssid (NMWifiAP *ap,
|
||||
const guint8 *ssid,
|
||||
gsize len);
|
||||
|
@@ -525,7 +525,7 @@ verify_adhoc (NMSettingWirelessSecurity *s_wsec,
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_wifi_utils_complete_connection (const GByteArray *ap_ssid,
|
||||
nm_wifi_utils_complete_connection (GBytes *ap_ssid,
|
||||
const char *bssid,
|
||||
NM80211Mode ap_mode,
|
||||
guint32 ap_flags,
|
||||
@@ -538,7 +538,7 @@ nm_wifi_utils_complete_connection (const GByteArray *ap_ssid,
|
||||
NMSettingWireless *s_wifi;
|
||||
NMSettingWirelessSecurity *s_wsec;
|
||||
NMSetting8021x *s_8021x;
|
||||
GBytes *ssid, *ap_ssid_bytes;
|
||||
GBytes *ssid;
|
||||
const char *mode, *key_mgmt, *auth_alg, *leap_username;
|
||||
gboolean adhoc = FALSE;
|
||||
|
||||
@@ -548,20 +548,17 @@ nm_wifi_utils_complete_connection (const GByteArray *ap_ssid,
|
||||
s_8021x = nm_connection_get_setting_802_1x (connection);
|
||||
|
||||
/* Fill in missing SSID */
|
||||
ap_ssid_bytes = ap_ssid ? g_bytes_new (ap_ssid->data, ap_ssid->len) : NULL;
|
||||
ssid = nm_setting_wireless_get_ssid (s_wifi);
|
||||
if (!ssid)
|
||||
g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_SSID, ap_ssid_bytes, NULL);
|
||||
else if (!ap_ssid_bytes || !g_bytes_equal (ssid, ap_ssid_bytes)) {
|
||||
g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_SSID, ap_ssid, NULL);
|
||||
else if (!ap_ssid || !g_bytes_equal (ssid, ap_ssid)) {
|
||||
g_set_error_literal (error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
||||
_("connection does not match access point"));
|
||||
g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID);
|
||||
g_bytes_unref (ap_ssid_bytes);
|
||||
return FALSE;
|
||||
}
|
||||
g_bytes_unref (ap_ssid_bytes);
|
||||
|
||||
if (lock_bssid && !nm_setting_wireless_get_bssid (s_wifi))
|
||||
g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_BSSID, bssid, NULL);
|
||||
@@ -783,8 +780,10 @@ nm_wifi_utils_level_to_quality (int val)
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_wifi_utils_is_manf_default_ssid (const GByteArray *ssid)
|
||||
nm_wifi_utils_is_manf_default_ssid (GBytes *ssid)
|
||||
{
|
||||
const guint8 *ssid_p;
|
||||
gsize ssid_l;
|
||||
int i;
|
||||
/*
|
||||
* List of manufacturer default SSIDs that are often unchanged by users.
|
||||
@@ -806,9 +805,11 @@ nm_wifi_utils_is_manf_default_ssid (const GByteArray *ssid)
|
||||
"TURBONETT",
|
||||
};
|
||||
|
||||
ssid_p = g_bytes_get_data (ssid, &ssid_l);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (manf_defaults); i++) {
|
||||
if (ssid->len == strlen (manf_defaults[i])) {
|
||||
if (memcmp (manf_defaults[i], ssid->data, ssid->len) == 0)
|
||||
if (ssid_l == strlen (manf_defaults[i])) {
|
||||
if (memcmp (manf_defaults[i], ssid_p, ssid_l) == 0)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include "nm-setting-wireless-security.h"
|
||||
#include "nm-setting-8021x.h"
|
||||
|
||||
gboolean nm_wifi_utils_complete_connection (const GByteArray *ssid,
|
||||
gboolean nm_wifi_utils_complete_connection (GBytes *ssid,
|
||||
const char *bssid,
|
||||
NM80211Mode mode,
|
||||
guint32 flags,
|
||||
@@ -39,6 +39,6 @@ gboolean nm_wifi_utils_complete_connection (const GByteArray *ssid,
|
||||
|
||||
guint32 nm_wifi_utils_level_to_quality (int val);
|
||||
|
||||
gboolean nm_wifi_utils_is_manf_default_ssid (const GByteArray *ssid);
|
||||
gboolean nm_wifi_utils_is_manf_default_ssid (GBytes *ssid);
|
||||
|
||||
#endif /* __NM_WIFI_UTILS_H__ */
|
||||
|
@@ -74,8 +74,7 @@ complete_connection (const char *ssid,
|
||||
NMConnection *src,
|
||||
GError **error)
|
||||
{
|
||||
GByteArray *tmp;
|
||||
gboolean success;
|
||||
gs_unref_bytes GBytes *ssid_b = NULL;
|
||||
NMSettingWireless *s_wifi;
|
||||
|
||||
/* Add a wifi setting if one doesn't exist */
|
||||
@@ -85,20 +84,17 @@ complete_connection (const char *ssid,
|
||||
nm_connection_add_setting (src, NM_SETTING (s_wifi));
|
||||
}
|
||||
|
||||
tmp = g_byte_array_sized_new (strlen (ssid));
|
||||
g_byte_array_append (tmp, (const guint8 *) ssid, strlen (ssid));
|
||||
ssid_b = g_bytes_new (ssid, strlen (ssid));
|
||||
|
||||
success = nm_wifi_utils_complete_connection (tmp,
|
||||
bssid,
|
||||
mode,
|
||||
flags,
|
||||
wpa_flags,
|
||||
rsn_flags,
|
||||
src,
|
||||
lock_bssid,
|
||||
error);
|
||||
g_byte_array_free (tmp, TRUE);
|
||||
return success;
|
||||
return nm_wifi_utils_complete_connection (ssid_b,
|
||||
bssid,
|
||||
mode,
|
||||
flags,
|
||||
wpa_flags,
|
||||
rsn_flags,
|
||||
src,
|
||||
lock_bssid,
|
||||
error);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
@@ -41,6 +41,7 @@
|
||||
#include "nm-wifi-utils-private.h"
|
||||
#include "nm-utils.h"
|
||||
#include "platform/nm-platform-utils.h"
|
||||
#include "nm-core-internal.h"
|
||||
|
||||
typedef struct {
|
||||
NMWifiUtils parent;
|
||||
@@ -506,11 +507,13 @@ wifi_wext_set_mesh_ssid (NMWifiUtils *data, const guint8 *ssid, gsize len)
|
||||
return TRUE;
|
||||
|
||||
if (errno != ENODEV) {
|
||||
gs_free char *ssid_str = NULL;
|
||||
|
||||
errsv = errno;
|
||||
_LOGE (LOGD_PLATFORM | LOGD_WIFI | LOGD_OLPC,
|
||||
"(%s): error setting SSID to '%s': %s",
|
||||
ifname,
|
||||
ssid ? nm_utils_escape_ssid (ssid, len) : "(null)",
|
||||
(ssid_str = _nm_utils_ssid_to_string_arr (ssid, len)),
|
||||
strerror (errsv));
|
||||
}
|
||||
|
||||
|
@@ -4013,7 +4013,7 @@ wireless_connection_from_ifcfg (const char *file,
|
||||
NMSetting8021x *s_8021x = NULL;
|
||||
GBytes *ssid;
|
||||
NMSetting *security_setting = NULL;
|
||||
char *printable_ssid = NULL;
|
||||
gs_free char *ssid_utf8 = NULL;
|
||||
const char *mode;
|
||||
gboolean adhoc = FALSE;
|
||||
GError *local = NULL;
|
||||
@@ -4033,12 +4033,6 @@ wireless_connection_from_ifcfg (const char *file,
|
||||
nm_connection_add_setting (connection, wireless_setting);
|
||||
|
||||
ssid = nm_setting_wireless_get_ssid (NM_SETTING_WIRELESS (wireless_setting));
|
||||
if (ssid) {
|
||||
printable_ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL),
|
||||
g_bytes_get_size (ssid));
|
||||
} else
|
||||
printable_ssid = g_strdup ("unmanaged");
|
||||
|
||||
mode = nm_setting_wireless_get_mode (NM_SETTING_WIRELESS (wireless_setting));
|
||||
if (mode && !strcmp (mode, "adhoc"))
|
||||
adhoc = TRUE;
|
||||
@@ -4046,7 +4040,6 @@ wireless_connection_from_ifcfg (const char *file,
|
||||
/* Wireless security */
|
||||
security_setting = make_wireless_security_setting (ifcfg, file, ssid, adhoc, &s_8021x, &local);
|
||||
if (local) {
|
||||
g_free (printable_ssid);
|
||||
g_object_unref (connection);
|
||||
g_propagate_error (error, local);
|
||||
return NULL;
|
||||
@@ -4057,11 +4050,16 @@ wireless_connection_from_ifcfg (const char *file,
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_8021x));
|
||||
}
|
||||
|
||||
if (ssid)
|
||||
ssid_utf8 = _nm_utils_ssid_to_utf8 (ssid);
|
||||
|
||||
/* Connection */
|
||||
con_setting = make_connection_setting (file, ifcfg,
|
||||
con_setting = make_connection_setting (file,
|
||||
ifcfg,
|
||||
NM_SETTING_WIRELESS_SETTING_NAME,
|
||||
printable_ssid, NULL);
|
||||
g_free (printable_ssid);
|
||||
nm_str_not_empty (ssid_utf8) ?: "unmanaged",
|
||||
NULL);
|
||||
|
||||
if (!con_setting) {
|
||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
||||
"Failed to create connection setting.");
|
||||
|
Reference in New Issue
Block a user