static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMSettingWireless *setting = NM_SETTING_WIRELESS (object); switch (prop_id) { case PROP_SSID: g_value_set_boxed (value, nm_setting_wireless_get_ssid (setting)); break; case PROP_MODE: g_value_set_string (value, nm_setting_wireless_get_mode (setting)); break; case PROP_BAND: g_value_set_string (value, nm_setting_wireless_get_band (setting)); break; case PROP_CHANNEL: g_value_set_uint (value, nm_setting_wireless_get_channel (setting)); break; case PROP_BSSID: g_value_set_boxed (value, nm_setting_wireless_get_bssid (setting)); break; case PROP_RATE: g_value_set_uint (value, nm_setting_wireless_get_rate (setting)); break; case PROP_TX_POWER: g_value_set_uint (value, nm_setting_wireless_get_tx_power (setting)); break; case PROP_MAC_ADDRESS: g_value_set_boxed (value, nm_setting_wireless_get_mac_address (setting)); break; case PROP_CLONED_MAC_ADDRESS: g_value_set_boxed (value, nm_setting_wireless_get_cloned_mac_address (setting)); break; case PROP_MAC_ADDRESS_BLACKLIST: g_value_set_boxed (value, nm_setting_wireless_get_mac_address_blacklist (setting)); break; case PROP_MTU: g_value_set_uint (value, nm_setting_wireless_get_mtu (setting)); break; case PROP_SEEN_BSSIDS: g_value_set_boxed (value, NM_SETTING_WIRELESS_GET_PRIVATE (setting)->seen_bssids); break; case PROP_SEC: g_value_set_string (value, NM_SETTING_WIRELESS_GET_PRIVATE (setting)->security); break; case PROP_HIDDEN: g_value_set_boolean (value, nm_setting_wireless_get_hidden (setting)); break; case PROP_POWERSAVE: g_value_set_uint (value, nm_setting_wireless_get_powersave (setting)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void connect_wifi_page (CEPageWifi *page) { NMSettingConnection *sc; GtkWidget *widget; const GByteArray *ssid; gchar *utf8_ssid; GPtrArray *bssid_array; gchar **bssid_list; const GByteArray *s_bssid; gchar *s_bssid_str; gchar **mac_list; const GByteArray *s_mac; gchar *s_mac_str; gint i; widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "entry_ssid")); ssid = nm_setting_wireless_get_ssid (page->setting); if (ssid) utf8_ssid = nm_utils_ssid_to_utf8 (ssid); else utf8_ssid = g_strdup (""); gtk_entry_set_text (GTK_ENTRY (widget), utf8_ssid); g_free (utf8_ssid); g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_bssid")); bssid_array = g_ptr_array_new (); for (i = 0; i < nm_setting_wireless_get_num_seen_bssids (page->setting); i++) { g_ptr_array_add (bssid_array, g_strdup (nm_setting_wireless_get_seen_bssid (page->setting, i))); } g_ptr_array_add (bssid_array, NULL); bssid_list = (gchar **) g_ptr_array_free (bssid_array, FALSE); s_bssid = nm_setting_wireless_get_bssid (page->setting); s_bssid_str = s_bssid ? nm_utils_hwaddr_ntoa (s_bssid->data, ARPHRD_ETHER) : NULL; ce_page_setup_mac_combo (GTK_COMBO_BOX_TEXT (widget), s_bssid_str, bssid_list); g_free (s_bssid_str); g_strfreev (bssid_list); g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_mac")); mac_list = ce_page_get_mac_list (CE_PAGE (page)->client, NM_TYPE_DEVICE_WIFI, NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS); s_mac = nm_setting_wireless_get_mac_address (page->setting); s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_ETHER) : NULL; ce_page_setup_mac_combo (GTK_COMBO_BOX_TEXT (widget), s_mac_str, mac_list); g_free (s_mac_str); g_strfreev (mac_list); g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "entry_cloned_mac")); ce_page_mac_to_entry (nm_setting_wireless_get_cloned_mac_address (page->setting), ARPHRD_ETHER, GTK_ENTRY (widget)); g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_connect_check")); sc = nm_connection_get_setting_connection (CE_PAGE (page)->connection); g_object_bind_property (sc, "autoconnect", widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); g_signal_connect_swapped (widget, "toggled", G_CALLBACK (ce_page_changed), page); widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "all_user_check")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), nm_setting_connection_get_num_permissions (sc) == 0); g_signal_connect (widget, "toggled", G_CALLBACK (all_user_changed), page); g_signal_connect_swapped (widget, "toggled", G_CALLBACK (ce_page_changed), page); widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_zone")); firewall_ui_setup (sc, widget, CE_PAGE (page)->cancellable); g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); }
gboolean nm_supplicant_config_add_setting_wireless (NMSupplicantConfig * self, NMSettingWireless * setting, guint32 fixed_freq, GError **error) { NMSupplicantConfigPrivate *priv; gboolean is_adhoc, is_ap; const char *mode, *band; guint32 channel; GBytes *ssid; const char *bssid; g_return_val_if_fail (NM_IS_SUPPLICANT_CONFIG (self), FALSE); g_return_val_if_fail (setting != NULL, FALSE); g_return_val_if_fail (!error || !*error, FALSE); priv = NM_SUPPLICANT_CONFIG_GET_PRIVATE (self); mode = nm_setting_wireless_get_mode (setting); is_adhoc = (mode && !strcmp (mode, "adhoc")) ? TRUE : FALSE; is_ap = (mode && !strcmp (mode, "ap")) ? TRUE : FALSE; if (is_adhoc || is_ap) priv->ap_scan = 2; else priv->ap_scan = 1; ssid = nm_setting_wireless_get_ssid (setting); if (!nm_supplicant_config_add_option (self, "ssid", (char *) g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid), FALSE, error)) return FALSE; if (is_adhoc) { if (!nm_supplicant_config_add_option (self, "mode", "1", -1, FALSE, error)) return FALSE; } if (is_ap) { if (!nm_supplicant_config_add_option (self, "mode", "2", -1, FALSE, error)) return FALSE; } if ((is_adhoc || is_ap) && fixed_freq) { gs_free char *str_freq = NULL; str_freq = g_strdup_printf ("%u", fixed_freq); if (!nm_supplicant_config_add_option (self, "frequency", str_freq, -1, FALSE, error)) return FALSE; } /* Except for Ad-Hoc and Hotspot, request that the driver probe for the * specific SSID we want to associate with. */ if (!(is_adhoc || is_ap)) { if (!nm_supplicant_config_add_option (self, "scan_ssid", "1", -1, FALSE, error)) return FALSE; } bssid = nm_setting_wireless_get_bssid (setting); if (bssid) { if (!nm_supplicant_config_add_option (self, "bssid", bssid, strlen (bssid), FALSE, error)) return FALSE; } band = nm_setting_wireless_get_band (setting); channel = nm_setting_wireless_get_channel (setting); if (band) { if (channel) { guint32 freq; gs_free char *str_freq = NULL; freq = nm_utils_wifi_channel_to_freq (channel, band); str_freq = g_strdup_printf ("%u", freq); if (!nm_supplicant_config_add_option (self, "freq_list", str_freq, -1, FALSE, error)) return FALSE; } else { const char *freqs = NULL; if (!strcmp (band, "a")) freqs = wifi_freqs_to_string (FALSE); else if (!strcmp (band, "bg")) freqs = wifi_freqs_to_string (TRUE); if (freqs && !nm_supplicant_config_add_option (self, "freq_list", freqs, strlen (freqs), FALSE, error)) return FALSE; } } return TRUE; }
static void populate_ui (CEPageWifi *self) { CEPageWifiPrivate *priv = CE_PAGE_WIFI_GET_PRIVATE (self); NMSettingWireless *setting = priv->setting; GBytes *ssid; const char *mode; const char *band; int band_idx = 0; int rate_def; int tx_power_def; int mtu_def; char *utf8_ssid; const char *s_ifname, *s_mac, *s_bssid; GPtrArray *bssid_array; char **bssid_list; guint32 idx; rate_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRELESS_RATE); g_signal_connect (priv->rate, "output", G_CALLBACK (ce_spin_output_with_automatic), GINT_TO_POINTER (rate_def)); g_signal_connect_swapped (priv->rate, "value-changed", G_CALLBACK (ce_page_changed), self); tx_power_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRELESS_TX_POWER); g_signal_connect (priv->tx_power, "output", G_CALLBACK (ce_spin_output_with_automatic), GINT_TO_POINTER (tx_power_def)); g_signal_connect_swapped (priv->tx_power, "value-changed", G_CALLBACK (ce_page_changed), self); mtu_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRELESS_MTU); g_signal_connect (priv->mtu, "output", G_CALLBACK (ce_spin_output_with_automatic), GINT_TO_POINTER (mtu_def)); g_signal_connect_swapped (priv->mtu, "value-changed", G_CALLBACK (ce_page_changed), self); ssid = nm_setting_wireless_get_ssid (setting); mode = nm_setting_wireless_get_mode (setting); band = nm_setting_wireless_get_band (setting); if (ssid) utf8_ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); else utf8_ssid = g_strdup (""); gtk_entry_set_text (priv->ssid, utf8_ssid); g_signal_connect_swapped (priv->ssid, "changed", G_CALLBACK (ce_page_changed), self); g_free (utf8_ssid); /* Default to Infrastructure */ gtk_combo_box_set_active (priv->mode, 0); if (!g_strcmp0 (mode, "ap")) gtk_combo_box_set_active (priv->mode, 1); if (!g_strcmp0 (mode, "adhoc")) gtk_combo_box_set_active (priv->mode, 2); mode_combo_changed_cb (priv->mode, self); g_signal_connect (priv->mode, "changed", G_CALLBACK (mode_combo_changed_cb), self); g_signal_connect (priv->channel, "output", G_CALLBACK (channel_spin_output_cb), self); g_signal_connect (priv->channel, "input", G_CALLBACK (channel_spin_input_cb), self); gtk_widget_set_sensitive (GTK_WIDGET (priv->channel), FALSE); if (band) { if (!strcmp (band, "a")) { band_idx = 1; gtk_widget_set_sensitive (GTK_WIDGET (priv->channel), TRUE); } else if (!strcmp (band, "bg")) { band_idx = 2; gtk_widget_set_sensitive (GTK_WIDGET (priv->channel), TRUE); } } gtk_combo_box_set_active (priv->band, band_idx); g_signal_connect (priv->band, "changed", G_CALLBACK (band_value_changed_cb), self); /* Update the channel _after_ the band has been set so that it gets * the right values */ priv->last_channel = nm_setting_wireless_get_channel (setting); gtk_spin_button_set_value (priv->channel, (gdouble) priv->last_channel); g_signal_connect_swapped (priv->channel, "value-changed", G_CALLBACK (ce_page_changed), self); /* BSSID */ bssid_array = g_ptr_array_new (); for (idx = 0; idx < nm_setting_wireless_get_num_seen_bssids (setting); idx++) g_ptr_array_add (bssid_array, g_strdup (nm_setting_wireless_get_seen_bssid (setting, idx))); g_ptr_array_add (bssid_array, NULL); bssid_list = (char **) g_ptr_array_free (bssid_array, FALSE); s_bssid = nm_setting_wireless_get_bssid (setting); ce_page_setup_mac_combo (CE_PAGE (self), GTK_COMBO_BOX (priv->bssid), s_bssid, bssid_list); g_strfreev (bssid_list); g_signal_connect_swapped (priv->bssid, "changed", G_CALLBACK (ce_page_changed), self); /* Device MAC address */ s_ifname = nm_connection_get_interface_name (CE_PAGE (self)->connection); s_mac = nm_setting_wireless_get_mac_address (setting); ce_page_setup_device_combo (CE_PAGE (self), GTK_COMBO_BOX (priv->device_combo), NM_TYPE_DEVICE_WIFI, s_ifname, s_mac, NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS, TRUE); g_signal_connect_swapped (priv->device_combo, "changed", G_CALLBACK (ce_page_changed), self); /* Cloned MAC address */ s_mac = nm_setting_wireless_get_cloned_mac_address (setting); if (s_mac) gtk_entry_set_text (priv->cloned_mac, s_mac); g_signal_connect_swapped (priv->cloned_mac, "changed", G_CALLBACK (ce_page_changed), self); gtk_spin_button_set_value (priv->rate, (gdouble) nm_setting_wireless_get_rate (setting)); gtk_spin_button_set_value (priv->tx_power, (gdouble) nm_setting_wireless_get_tx_power (setting)); gtk_spin_button_set_value (priv->mtu, (gdouble) nm_setting_wireless_get_mtu (setting)); }
gboolean nm_supplicant_config_add_setting_wireless (NMSupplicantConfig * self, NMSettingWireless * setting, guint32 fixed_freq) { NMSupplicantConfigPrivate *priv; gboolean is_adhoc, is_ap; const char *mode, *band; GBytes *ssid; const char *bssid; g_return_val_if_fail (NM_IS_SUPPLICANT_CONFIG (self), FALSE); g_return_val_if_fail (setting != NULL, FALSE); priv = NM_SUPPLICANT_CONFIG_GET_PRIVATE (self); mode = nm_setting_wireless_get_mode (setting); is_adhoc = (mode && !strcmp (mode, "adhoc")) ? TRUE : FALSE; is_ap = (mode && !strcmp (mode, "ap")) ? TRUE : FALSE; if (is_adhoc || is_ap) priv->ap_scan = 2; else priv->ap_scan = 1; ssid = nm_setting_wireless_get_ssid (setting); if (!nm_supplicant_config_add_option (self, "ssid", (char *) g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid), FALSE)) { nm_log_warn (LOGD_SUPPLICANT, "Error adding SSID to supplicant config."); return FALSE; } if (is_adhoc) { if (!nm_supplicant_config_add_option (self, "mode", "1", -1, FALSE)) { nm_log_warn (LOGD_SUPPLICANT, "Error adding mode=1 (adhoc) to supplicant config."); return FALSE; } } if (is_ap) { if (!nm_supplicant_config_add_option (self, "mode", "2", -1, FALSE)) { nm_log_warn (LOGD_SUPPLICANT, "Error adding mode=2 (ap) to supplicant config."); return FALSE; } } if ((is_adhoc || is_ap) && fixed_freq) { char *str_freq; str_freq = g_strdup_printf ("%u", fixed_freq); if (!nm_supplicant_config_add_option (self, "frequency", str_freq, -1, FALSE)) { g_free (str_freq); nm_log_warn (LOGD_SUPPLICANT, "Error adding Ad-Hoc/AP frequency to supplicant config."); return FALSE; } g_free (str_freq); } /* Except for Ad-Hoc and Hotspot, request that the driver probe for the * specific SSID we want to associate with. */ if (!(is_adhoc || is_ap)) { if (!nm_supplicant_config_add_option (self, "scan_ssid", "1", -1, FALSE)) return FALSE; } bssid = nm_setting_wireless_get_bssid (setting); if (bssid) { if (!nm_supplicant_config_add_option (self, "bssid", bssid, strlen (bssid), FALSE)) { nm_log_warn (LOGD_SUPPLICANT, "Error adding BSSID to supplicant config."); return FALSE; } } band = nm_setting_wireless_get_band (setting); if (band) { const char *freqs = NULL; if (!strcmp (band, "a")) freqs = FIVE_GHZ_FREQS; else if (!strcmp (band, "bg")) freqs = TWO_GHZ_FREQS; if (freqs && !nm_supplicant_config_add_option (self, "freq_list", freqs, strlen (freqs), FALSE)) { nm_log_warn (LOGD_SUPPLICANT, "Error adding frequency list/band to supplicant config."); return FALSE; } } // FIXME: channel config item return TRUE; }
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)); }
gboolean nm_ap_utils_complete_connection (const GByteArray *ap_ssid, const guint8 ap_bssid[ETH_ALEN], NM80211Mode ap_mode, guint32 ap_flags, guint32 ap_wpa_flags, guint32 ap_rsn_flags, NMConnection *connection, gboolean lock_bssid, GError **error) { NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; const GByteArray *ssid; const char *mode, *key_mgmt, *auth_alg, *leap_username; gboolean adhoc = FALSE; s_wifi = nm_connection_get_setting_wireless (connection); g_assert (s_wifi); s_wsec = nm_connection_get_setting_wireless_security (connection); s_8021x = nm_connection_get_setting_802_1x (connection); /* Fill in missing SSID */ ssid = nm_setting_wireless_get_ssid (s_wifi); if (!ssid) g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_SSID, ap_ssid, NULL); else if ( ssid->len != ap_ssid->len || memcmp (ssid->data, ap_ssid->data, ssid->len)) { g_set_error_literal (error, NM_SETTING_WIRELESS_ERROR, NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY, "Setting SSID did not match AP SSID"); return FALSE; } if (lock_bssid && !nm_setting_wireless_get_bssid (s_wifi)) { GByteArray *bssid; bssid = g_byte_array_sized_new (ETH_ALEN); g_byte_array_append (bssid, ap_bssid, ETH_ALEN); g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_BSSID, bssid, NULL); g_byte_array_free (bssid, TRUE); } /* And mode */ mode = nm_setting_wireless_get_mode (s_wifi); if (mode) { gboolean valid = FALSE; /* Make sure the supplied mode matches the AP's */ if (!strcmp (mode, NM_SETTING_WIRELESS_MODE_INFRA)) { if (ap_mode == NM_802_11_MODE_INFRA) valid = TRUE; } else if (!strcmp (mode, NM_SETTING_WIRELESS_MODE_ADHOC)) { if (ap_mode == NM_802_11_MODE_ADHOC) valid = TRUE; adhoc = TRUE; } if (valid == FALSE) { g_set_error (error, NM_SETTING_WIRELESS_ERROR, NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY, NM_SETTING_WIRELESS_MODE); return FALSE; } } else { mode = NM_SETTING_WIRELESS_MODE_INFRA; if (ap_mode == NM_802_11_MODE_ADHOC) { mode = NM_SETTING_WIRELESS_MODE_ADHOC; adhoc = TRUE; } g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_MODE, mode, NULL); } /* Security */ /* Open */ if ( !(ap_flags & NM_802_11_AP_FLAGS_PRIVACY) && (ap_wpa_flags == NM_802_11_AP_SEC_NONE) && (ap_rsn_flags == NM_802_11_AP_SEC_NONE)) { /* Make sure the connection doesn't specify security */ if (nm_setting_wireless_get_security (s_wifi) || s_wsec || s_8021x) { g_set_error_literal (error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, "AP is unencrypted but setting specifies security"); return FALSE; } return TRUE; } /* Everything else requires security */ g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); if (!s_wsec) { s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); } key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wsec); auth_alg = nm_setting_wireless_security_get_auth_alg (s_wsec); leap_username = nm_setting_wireless_security_get_leap_username (s_wsec); /* Ad-Hoc checks */ if (!verify_adhoc (s_wsec, s_8021x, adhoc, error)) return FALSE; /* Static WEP, Dynamic WEP, or LEAP */ if ( (ap_flags & NM_802_11_AP_FLAGS_PRIVACY) && (ap_wpa_flags == NM_802_11_AP_SEC_NONE) && (ap_rsn_flags == NM_802_11_AP_SEC_NONE)) { const char *tag = "WEP"; gboolean is_dynamic_wep = FALSE; if (!verify_leap (s_wsec, s_8021x, adhoc, error)) return FALSE; if (leap_username) { tag = "LEAP"; } else { /* Static or Dynamic WEP */ if (!verify_dynamic_wep (s_wsec, s_8021x, adhoc, error)) return FALSE; if (s_8021x || (key_mgmt && !strcmp (key_mgmt, "ieee8021x"))) { is_dynamic_wep = TRUE; tag = "Dynamic WEP"; } } /* Nothing WPA-related can be set */ if (!verify_no_wpa (s_wsec, tag, error)) return FALSE; if (leap_username) { /* LEAP */ g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "leap", NULL); } else if (is_dynamic_wep) { /* Dynamic WEP */ g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", NULL); nm_setting_wireless_security_add_pairwise (s_wsec, "wep40"); nm_setting_wireless_security_add_pairwise (s_wsec, "wep104"); nm_setting_wireless_security_add_group (s_wsec, "wep40"); nm_setting_wireless_security_add_group (s_wsec, "wep104"); if (s_8021x) { /* Dynamic WEP requires a valid 802.1x setting since we can't * autocomplete 802.1x. */ if (!nm_setting_verify (NM_SETTING (s_8021x), NULL, error)) return FALSE; } } else { /* Static WEP */ g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL); } return TRUE; } /* WPA/RSN */ g_assert (ap_wpa_flags || ap_rsn_flags); /* Ensure key management is valid for WPA */ if ((key_mgmt && !strcmp (key_mgmt, "ieee8021x")) || leap_username) { g_set_error_literal (error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, "WPA incompatible with non-EAP (original) LEAP or Dynamic WEP"); return FALSE; } /* 'shared' auth incompatible with any type of WPA */ if (auth_alg && strcmp (auth_alg, "open")) { g_set_error_literal (error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, "WPA incompatible with Shared Key authentication"); return FALSE; } if (!verify_no_wep (s_wsec, "WPA", error)) return FALSE; if (!verify_wpa_psk (s_wsec, s_8021x, adhoc, ap_wpa_flags, ap_rsn_flags, error)) return FALSE; if (!adhoc && !verify_wpa_eap (s_wsec, s_8021x, ap_wpa_flags, ap_rsn_flags, error)) return FALSE; if (adhoc) { g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-none", NULL); /* Ad-Hoc does not support RSN/WPA2 */ nm_setting_wireless_security_add_proto (s_wsec, "wpa"); nm_setting_wireless_security_add_pairwise (s_wsec, "none"); nm_setting_wireless_security_add_group (s_wsec, "tkip"); } else if (s_8021x) { g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", NULL); /* Leave proto/pairwise/group as client set them; if they are unset the * supplicant will figure out the best combination at connect time. */ /* 802.1x also requires the client to completely fill in the 8021x * setting. Since there's so much configuration required for it, there's * no way it can be automatically completed. */ } else if ( (key_mgmt && !strcmp (key_mgmt, "wpa-psk")) || (ap_wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK) || (ap_rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK)) { g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", NULL); /* Leave proto/pairwise/group as client set them; if they are unset the * supplicant will figure out the best combination at connect time. */ } else { g_set_error_literal (error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, "Failed to determine AP security information"); return FALSE; } return TRUE; }
static void populate_ui (CEPageWireless *self) { CEPageWirelessPrivate *priv = CE_PAGE_WIRELESS_GET_PRIVATE (self); NMSettingWireless *setting = priv->setting; const GByteArray *ssid = NULL; const char *mode = NULL; const char *band = NULL; int band_idx = 0; int rate_def; int tx_power_def; int mtu_def; char *utf8_ssid; rate_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRELESS_RATE); g_signal_connect (priv->rate, "output", G_CALLBACK (ce_spin_output_with_default), GINT_TO_POINTER (rate_def)); g_signal_connect_swapped (priv->rate, "value-changed", G_CALLBACK (ce_page_changed), self); tx_power_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRELESS_TX_POWER); g_signal_connect (priv->tx_power, "output", G_CALLBACK (ce_spin_output_with_default), GINT_TO_POINTER (tx_power_def)); g_signal_connect_swapped (priv->tx_power, "value-changed", G_CALLBACK (ce_page_changed), self); mtu_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRELESS_MTU); g_signal_connect (priv->mtu, "output", G_CALLBACK (ce_spin_output_with_default), GINT_TO_POINTER (mtu_def)); g_signal_connect_swapped (priv->mtu, "value-changed", G_CALLBACK (ce_page_changed), self); g_object_get (setting, NM_SETTING_WIRELESS_SSID, &ssid, NM_SETTING_WIRELESS_MODE, &mode, NM_SETTING_WIRELESS_BAND, &band, NULL); if (ssid) utf8_ssid = nm_utils_ssid_to_utf8 ((const char *) ssid->data, ssid->len); else utf8_ssid = g_strdup (""); gtk_entry_set_text (priv->ssid, utf8_ssid); g_signal_connect_swapped (priv->ssid, "changed", G_CALLBACK (ce_page_changed), self); g_free (utf8_ssid); /* Default to Infrastructure */ gtk_combo_box_set_active (priv->mode, 0); if (mode && !strcmp (mode, "adhoc")) gtk_combo_box_set_active (priv->mode, 1); g_signal_connect_swapped (priv->mode, "changed", G_CALLBACK (ce_page_changed), self); g_signal_connect (priv->channel, "output", G_CALLBACK (channel_spin_output_cb), self); g_signal_connect (priv->channel, "input", G_CALLBACK (channel_spin_input_cb), self); gtk_widget_set_sensitive (GTK_WIDGET (priv->channel), FALSE); if (band) { if (!strcmp (band ? band : "", "a")) { band_idx = 1; gtk_widget_set_sensitive (GTK_WIDGET (priv->channel), TRUE); } else if (!strcmp (band ? band : "", "bg")) { band_idx = 2; gtk_widget_set_sensitive (GTK_WIDGET (priv->channel), TRUE); } } gtk_combo_box_set_active (priv->band, band_idx); g_signal_connect (priv->band, "changed", G_CALLBACK (band_value_changed_cb), self); /* Update the channel _after_ the band has been set so that it gets * the right values */ priv->last_channel = nm_setting_wireless_get_channel (setting); gtk_spin_button_set_value (priv->channel, (gdouble) priv->last_channel); g_signal_connect_swapped (priv->channel, "value-changed", G_CALLBACK (ce_page_changed), self); /* BSSID */ ce_page_mac_to_entry (nm_setting_wireless_get_bssid (setting), priv->bssid); g_signal_connect_swapped (priv->bssid, "changed", G_CALLBACK (ce_page_changed), self); /* MAC address */ ce_page_mac_to_entry (nm_setting_wireless_get_mac_address (setting), priv->mac); g_signal_connect_swapped (priv->mac, "changed", G_CALLBACK (ce_page_changed), self); gtk_spin_button_set_value (priv->rate, (gdouble) nm_setting_wireless_get_rate (setting)); gtk_spin_button_set_value (priv->tx_power, (gdouble) nm_setting_wireless_get_tx_power (setting)); gtk_spin_button_set_value (priv->mtu, (gdouble) nm_setting_wireless_get_mtu (setting)); }
/** * 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; }