void 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 (self)); 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%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)", 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); }
gboolean nm_ap_check_compatible (NMAccessPoint *self, NMConnection *connection) { NMAccessPointPrivate *priv; NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wireless_sec; GBytes *ssid; const char *mode; const char *band; const char *bssid; guint32 channel; g_return_val_if_fail (NM_IS_AP (self), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); priv = NM_AP_GET_PRIVATE (self); s_wireless = nm_connection_get_setting_wireless (connection); if (s_wireless == NULL) 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, TRUE)) return FALSE; bssid = nm_setting_wireless_get_bssid (s_wireless); if (bssid && (!priv->address || !nm_utils_hwaddr_matches (bssid, -1, priv->address, -1))) return FALSE; mode = nm_setting_wireless_get_mode (s_wireless); if (mode) { if (!strcmp (mode, "infrastructure") && (priv->mode != NM_802_11_MODE_INFRA)) return FALSE; if (!strcmp (mode, "adhoc") && (priv->mode != NM_802_11_MODE_ADHOC)) return FALSE; if ( !strcmp (mode, "ap") && (priv->mode != NM_802_11_MODE_INFRA || priv->hotspot != TRUE)) return FALSE; } band = nm_setting_wireless_get_band (s_wireless); if (band) { guint ap_band = freq_to_band (priv->freq); if (!strcmp (band, "a") && ap_band != 5) return FALSE; else if (!strcmp (band, "bg") && ap_band != 2) return FALSE; } channel = nm_setting_wireless_get_channel (s_wireless); if (channel) { guint32 ap_chan = nm_utils_wifi_freq_to_channel (priv->freq); if (channel != ap_chan) return FALSE; } s_wireless_sec = nm_connection_get_setting_wireless_security (connection); return nm_setting_wireless_ap_security_compatible (s_wireless, s_wireless_sec, priv->flags, priv->wpa_flags, priv->rsn_flags, priv->mode); }
gboolean nm_ap_check_compatible (NMAccessPoint *self, NMConnection *connection) { NMAccessPointPrivate *priv; NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wireless_sec; const char *mode; const char *band; const GByteArray *bssid; guint32 channel; g_return_val_if_fail (NM_IS_AP (self), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); priv = NM_AP_GET_PRIVATE (self); s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS)); if (s_wireless == NULL) return FALSE; if (!nm_utils_same_ssid (nm_setting_wireless_get_ssid (s_wireless), priv->ssid, TRUE)) return FALSE; bssid = nm_setting_wireless_get_bssid (s_wireless); if (bssid && memcmp (bssid->data, &priv->address, ETH_ALEN)) return FALSE; mode = nm_setting_wireless_get_mode (s_wireless); if (mode) { if (!strcmp (mode, "infrastructure") && (priv->mode != NM_802_11_MODE_INFRA)) return FALSE; if (!strcmp (mode, "adhoc") && (priv->mode != NM_802_11_MODE_ADHOC)) return FALSE; } band = nm_setting_wireless_get_band (s_wireless); if (band) { if (!strcmp (band, "a")) { if (priv->freq < 4915 || priv->freq > 5825) return FALSE; } else if (!strcmp (band, "bg")) { if (priv->freq < 2412 || priv->freq > 2484) return FALSE; } } channel = nm_setting_wireless_get_channel (s_wireless); if (channel) { guint32 ap_chan = nm_utils_wifi_freq_to_channel (priv->freq); if (channel != ap_chan) return FALSE; } s_wireless_sec = (NMSettingWirelessSecurity *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY); 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)); }
/** * nm_access_point_connection_valid: * @ap: an #NMAccessPoint to validate @connection against * @connection: an #NMConnection to validate against @ap * * Validates a given connection against a given Wi-Fi access point to ensure that * the connection may be activated with that AP. The connection must match the * @ap's SSID, (if given) BSSID, and other attributes like security settings, * channel, band, etc. * * Returns: %TRUE if the connection may be activated with this Wi-Fi AP, * %FALSE if it cannot be. **/ gboolean nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection) { NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; const char *ctype, *ap_bssid_str; const GByteArray *setting_ssid; const GByteArray *ap_ssid; const GByteArray *setting_bssid; struct ether_addr *ap_bssid; const char *setting_mode; NM80211Mode ap_mode; const char *setting_band; guint32 ap_freq, setting_chan, ap_chan; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); ctype = nm_setting_connection_get_connection_type (s_con); if (strcmp (ctype, NM_SETTING_WIRELESS_SETTING_NAME) != 0) return FALSE; s_wifi = nm_connection_get_setting_wireless (connection); if (!s_wifi) return FALSE; /* SSID checks */ ap_ssid = nm_access_point_get_ssid (ap); g_warn_if_fail (ap_ssid != NULL); setting_ssid = nm_setting_wireless_get_ssid (s_wifi); if (!setting_ssid || !ap_ssid || (setting_ssid->len != ap_ssid->len)) return FALSE; if (memcmp (setting_ssid->data, ap_ssid->data, ap_ssid->len) != 0) return FALSE; /* BSSID checks */ ap_bssid_str = nm_access_point_get_bssid (ap); g_warn_if_fail (ap_bssid_str); setting_bssid = nm_setting_wireless_get_bssid (s_wifi); if (setting_bssid && ap_bssid_str) { g_assert (setting_bssid->len == ETH_ALEN); ap_bssid = ether_aton (ap_bssid_str); g_warn_if_fail (ap_bssid); if (ap_bssid) { if (memcmp (ap_bssid->ether_addr_octet, setting_bssid->data, ETH_ALEN) != 0) return FALSE; } } /* Mode */ ap_mode = nm_access_point_get_mode (ap); g_warn_if_fail (ap_mode != NM_802_11_MODE_UNKNOWN); setting_mode = nm_setting_wireless_get_mode (s_wifi); if (setting_mode && ap_mode) { if (!strcmp (setting_mode, "infrastructure") && (ap_mode != NM_802_11_MODE_INFRA)) return FALSE; if (!strcmp (setting_mode, "adhoc") && (ap_mode != NM_802_11_MODE_ADHOC)) return FALSE; /* Hotspot never matches against APs as it's a device-specific mode. */ if (!strcmp (setting_mode, "ap")) return FALSE; } /* Band and Channel/Frequency */ ap_freq = nm_access_point_get_frequency (ap); if (ap_freq) { setting_band = nm_setting_wireless_get_band (s_wifi); if (g_strcmp0 (setting_band, "a") == 0) { if (ap_freq < 4915 || ap_freq > 5825) return FALSE; } else if (g_strcmp0 (setting_band, "bg") == 0) { if (ap_freq < 2412 || ap_freq > 2484) return FALSE; } setting_chan = nm_setting_wireless_get_channel (s_wifi); if (setting_chan) { ap_chan = nm_utils_wifi_freq_to_channel (ap_freq); if (setting_chan != ap_chan) return FALSE; } } s_wsec = nm_connection_get_setting_wireless_security (connection); if (!nm_setting_wireless_ap_security_compatible (s_wifi, s_wsec, nm_access_point_get_flags (ap), nm_access_point_get_wpa_flags (ap), nm_access_point_get_rsn_flags (ap), ap_mode)) return FALSE; return TRUE; }