[network-manager-applet/ap] editor: initial hotspot mode support



commit c6c9bf91436225bce502225ec46034a8217fc822
Author: Dan Williams <dcbw redhat com>
Date:   Mon Sep 17 22:47:21 2012 -0500

    editor: initial hotspot mode support

 src/connection-editor/ce-page-wifi.ui      |    3 +
 src/connection-editor/page-wifi-security.c |  105 +++++++++++++++++----------
 src/connection-editor/page-wifi-security.h |    2 +-
 src/connection-editor/page-wifi.c          |   46 +++++++++---
 src/wireless-security/wireless-security.c  |    9 +++
 src/wireless-security/wireless-security.h  |    3 +
 src/wireless-security/ws-dynamic-wep.c     |    1 +
 src/wireless-security/ws-leap.c            |    1 +
 src/wireless-security/ws-wpa-eap.c         |    1 +
 9 files changed, 120 insertions(+), 51 deletions(-)
---
diff --git a/src/connection-editor/ce-page-wifi.ui b/src/connection-editor/ce-page-wifi.ui
index 72df449..40c2fa9 100644
--- a/src/connection-editor/ce-page-wifi.ui
+++ b/src/connection-editor/ce-page-wifi.ui
@@ -55,6 +55,9 @@
       <row>
         <col id="0" translatable="yes">Ad-hoc</col>
       </row>
+      <row>
+        <col id="0" translatable="yes">Hotspot</col>
+      </row>
     </data>
   </object>
       <object class="GtkTable" id="WifiPage">
diff --git a/src/connection-editor/page-wifi-security.c b/src/connection-editor/page-wifi-security.c
index ee9af72..c77074d 100644
--- a/src/connection-editor/page-wifi-security.c
+++ b/src/connection-editor/page-wifi-security.c
@@ -46,6 +46,7 @@ G_DEFINE_TYPE (CEPageWifiSecurity, ce_page_wifi_security, CE_TYPE_PAGE)
 #define S_NAME_COLUMN   0
 #define S_SEC_COLUMN    1
 #define S_ADHOC_VALID_COLUMN  2
+#define S_HOTSPOT_VALID_COLUMN  3
 
 static gboolean
 find_proto (NMSettingWirelessSecurity *sec, const char *item)
@@ -181,7 +182,8 @@ add_security_item (CEPageWifiSecurity *self,
                    GtkListStore *model,
                    GtkTreeIter *iter,
                    const char *text,
-                   gboolean adhoc_valid)
+                   gboolean adhoc_valid,
+                   gboolean hotspot_valid)
 {
 	wireless_security_set_changed_notify (sec, stuff_changed_cb, self);
 	gtk_list_store_append (model, iter);
@@ -189,6 +191,7 @@ add_security_item (CEPageWifiSecurity *self,
 	                    S_NAME_COLUMN, text,
 	                    S_SEC_COLUMN, sec,
 	                    S_ADHOC_VALID_COLUMN, adhoc_valid,
+	                    S_HOTSPOT_VALID_COLUMN, hotspot_valid,
 	                    -1);
 	wireless_security_unref (sec);
 }
@@ -200,16 +203,48 @@ set_sensitive (GtkCellLayout *cell_layout,
                GtkTreeIter *iter,
                gpointer data)
 {
-	gboolean *adhoc = data;
-	gboolean sensitive = TRUE, adhoc_valid = TRUE;
+	NM80211Mode *mode = data;
+	gboolean sensitive = TRUE;
 
-	gtk_tree_model_get (tree_model, iter, S_ADHOC_VALID_COLUMN, &adhoc_valid, -1);
-	if (*adhoc && !adhoc_valid)
-		sensitive = FALSE;
+	if (*mode == NM_802_11_MODE_ADHOC)
+		gtk_tree_model_get (tree_model, iter, S_ADHOC_VALID_COLUMN, &sensitive, -1);
+	else if (*mode == NM_802_11_MODE_AP)
+		gtk_tree_model_get (tree_model, iter, S_HOTSPOT_VALID_COLUMN, &sensitive, -1);
 
 	g_object_set (cell, "sensitive", sensitive, NULL);
 }
 
+static gboolean
+security_valid (NMUtilsSecurityType sectype, NM80211Mode mode)
+{
+	guint32 dev_caps = 0;
+
+	/* Fake some device capabilities here since we don't know about the
+	 * NMDevice object to get the card's real capabilities.
+	 */
+	dev_caps =   NM_WIFI_DEVICE_CAP_CIPHER_WEP40
+	           | NM_WIFI_DEVICE_CAP_CIPHER_WEP104
+	           | NM_WIFI_DEVICE_CAP_CIPHER_TKIP
+	           | NM_WIFI_DEVICE_CAP_CIPHER_CCMP
+	           | NM_WIFI_DEVICE_CAP_WPA
+	           | NM_WIFI_DEVICE_CAP_RSN;
+
+	switch (mode) {
+	case NM_802_11_MODE_AP:
+		return nm_utils_ap_mode_security_valid (sectype, NM_WIFI_DEVICE_CAP_AP);
+		break;
+	case NM_802_11_MODE_ADHOC:
+	case NM_802_11_MODE_INFRA:
+	default:
+		return nm_utils_security_valid (sectype,
+		                                dev_caps,
+		                                FALSE,
+		                                (mode == NM_802_11_MODE_ADHOC),
+		                                0, 0, 0);
+	}
+	g_assert_not_reached ();
+}
+
 static void
 finish_setup (CEPageWifiSecurity *self, gpointer unused, GError *error, gpointer user_data)
 {
@@ -217,12 +252,10 @@ finish_setup (CEPageWifiSecurity *self, gpointer unused, GError *error, gpointer
 	NMSettingWireless *s_wireless;
 	NMSettingWirelessSecurity *s_wireless_sec;
 	NMConnection *connection = parent->connection;
-	gboolean is_adhoc = FALSE;
+	NM80211Mode mode = NM_802_11_MODE_INFRA;
 	GtkListStore *sec_model;
 	GtkTreeIter iter;
-	const char *mode;
 	const char *security;
-	guint32 dev_caps = 0;
 	NMUtilsSecurityType default_type = NMU_SEC_NONE;
 	int active = -1;
 	int item = 0;
@@ -237,17 +270,10 @@ finish_setup (CEPageWifiSecurity *self, gpointer unused, GError *error, gpointer
 
 	combo = GTK_COMBO_BOX (GTK_WIDGET (gtk_builder_get_object (parent->builder, "wifi_security_combo")));
 
-	dev_caps =   NM_WIFI_DEVICE_CAP_CIPHER_WEP40
-	           | NM_WIFI_DEVICE_CAP_CIPHER_WEP104
-	           | NM_WIFI_DEVICE_CAP_CIPHER_TKIP
-	           | NM_WIFI_DEVICE_CAP_CIPHER_CCMP
-	           | NM_WIFI_DEVICE_CAP_WPA
-	           | NM_WIFI_DEVICE_CAP_RSN;
-
-	mode = nm_setting_wireless_get_mode (s_wireless);
-	if (mode && !strcmp (mode, "adhoc"))
-		is_adhoc = TRUE;
-	self->adhoc = is_adhoc;
+	if (!g_strcmp0 (nm_setting_wireless_get_mode (s_wireless), "adhoc"))
+		mode = NM_802_11_MODE_ADHOC;
+	else if (!g_strcmp0 (nm_setting_wireless_get_mode (s_wireless), "ap"))
+		mode = NM_802_11_MODE_AP;
 
 	s_wireless_sec = nm_connection_get_setting_wireless_security (connection);
 
@@ -257,20 +283,21 @@ finish_setup (CEPageWifiSecurity *self, gpointer unused, GError *error, gpointer
 	if (s_wireless_sec)
 		default_type = get_default_type_for_security (s_wireless_sec);
 
-	sec_model = gtk_list_store_new (3, G_TYPE_STRING, wireless_security_get_g_type (), G_TYPE_BOOLEAN);
+	sec_model = gtk_list_store_new (4, G_TYPE_STRING, wireless_security_get_g_type (), G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
 
-	if (nm_utils_security_valid (NMU_SEC_NONE, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
+	if (security_valid (NMU_SEC_NONE, mode)) {
 		gtk_list_store_append (sec_model, &iter);
 		gtk_list_store_set (sec_model, &iter,
 		                    S_NAME_COLUMN, C_("Wi-Fi/Ethernet security", "None"),
 		                    S_ADHOC_VALID_COLUMN, TRUE,
+		                    S_HOTSPOT_VALID_COLUMN, TRUE,
 		                    -1);
 		if (default_type == NMU_SEC_NONE)
 			active = item;
 		item++;
 	}
 
-	if (nm_utils_security_valid (NMU_SEC_STATIC_WEP, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
+	if (security_valid (NMU_SEC_STATIC_WEP, mode)) {
 		WirelessSecurityWEPKey *ws_wep;
 		NMWepKeyType wep_type = NM_WEP_KEY_TYPE_KEY;
 
@@ -288,7 +315,7 @@ finish_setup (CEPageWifiSecurity *self, gpointer unused, GError *error, gpointer
 		if (ws_wep) {
 			add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
 			                   &iter, _("WEP 40/128-bit Key (Hex or ASCII)"),
-			                   TRUE);
+			                   TRUE, TRUE);
 			if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (wep_type == NM_WEP_KEY_TYPE_KEY))
 				active = item;
 			item++;
@@ -297,61 +324,59 @@ finish_setup (CEPageWifiSecurity *self, gpointer unused, GError *error, gpointer
 		ws_wep = ws_wep_key_new (connection, NM_WEP_KEY_TYPE_PASSPHRASE, FALSE, FALSE);
 		if (ws_wep) {
 			add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
-			                   &iter, _("WEP 128-bit Passphrase"), TRUE);
+			                   &iter, _("WEP 128-bit Passphrase"), TRUE, TRUE);
 			if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (wep_type == NM_WEP_KEY_TYPE_PASSPHRASE))
 				active = item;
 			item++;
 		}
 	}
 
-	if (nm_utils_security_valid (NMU_SEC_LEAP, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
+	if (security_valid (NMU_SEC_LEAP, mode)) {
 		WirelessSecurityLEAP *ws_leap;
 
 		ws_leap = ws_leap_new (connection, FALSE);
 		if (ws_leap) {
 			add_security_item (self, WIRELESS_SECURITY (ws_leap), sec_model,
-			                   &iter, _("LEAP"), FALSE);
+			                   &iter, _("LEAP"), FALSE, FALSE);
 			if ((active < 0) && (default_type == NMU_SEC_LEAP))
 				active = item;
 			item++;
 		}
 	}
 
-	if (nm_utils_security_valid (NMU_SEC_DYNAMIC_WEP, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
+	if (security_valid (NMU_SEC_DYNAMIC_WEP, mode)) {
 		WirelessSecurityDynamicWEP *ws_dynamic_wep;
 
 		ws_dynamic_wep = ws_dynamic_wep_new (connection, TRUE, FALSE);
 		if (ws_dynamic_wep) {
 			add_security_item (self, WIRELESS_SECURITY (ws_dynamic_wep), sec_model,
-			                   &iter, _("Dynamic WEP (802.1x)"), FALSE);
+			                   &iter, _("Dynamic WEP (802.1x)"), FALSE, FALSE);
 			if ((active < 0) && (default_type == NMU_SEC_DYNAMIC_WEP))
 				active = item;
 			item++;
 		}
 	}
 
-	if (   nm_utils_security_valid (NMU_SEC_WPA_PSK, dev_caps, FALSE, is_adhoc, 0, 0, 0)
-	    || nm_utils_security_valid (NMU_SEC_WPA2_PSK, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
+	if (security_valid (NMU_SEC_WPA_PSK, mode) || security_valid (NMU_SEC_WPA2_PSK, mode)) {
 		WirelessSecurityWPAPSK *ws_wpa_psk;
 
 		ws_wpa_psk = ws_wpa_psk_new (connection, FALSE);
 		if (ws_wpa_psk) {
 			add_security_item (self, WIRELESS_SECURITY (ws_wpa_psk), sec_model,
-			                   &iter, _("WPA & WPA2 Personal"), FALSE);
+			                   &iter, _("WPA & WPA2 Personal"), FALSE, TRUE);
 			if ((active < 0) && ((default_type == NMU_SEC_WPA_PSK) || (default_type == NMU_SEC_WPA2_PSK)))
 				active = item;
 			item++;
 		}
 	}
 
-	if (   nm_utils_security_valid (NMU_SEC_WPA_ENTERPRISE, dev_caps, FALSE, is_adhoc, 0, 0, 0)
-	    || nm_utils_security_valid (NMU_SEC_WPA2_ENTERPRISE, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
+	if (security_valid (NMU_SEC_WPA_ENTERPRISE, mode) || security_valid (NMU_SEC_WPA2_ENTERPRISE, mode)) {
 		WirelessSecurityWPAEAP *ws_wpa_eap;
 
 		ws_wpa_eap = ws_wpa_eap_new (connection, TRUE, FALSE);
 		if (ws_wpa_eap) {
 			add_security_item (self, WIRELESS_SECURITY (ws_wpa_eap), sec_model,
-			                   &iter, _("WPA & WPA2 Enterprise"), FALSE);
+			                   &iter, _("WPA & WPA2 Enterprise"), FALSE, FALSE);
 			if ((active < 0) && ((default_type == NMU_SEC_WPA_ENTERPRISE) || (default_type == NMU_SEC_WPA2_ENTERPRISE)))
 				active = item;
 			item++;
@@ -364,7 +389,7 @@ finish_setup (CEPageWifiSecurity *self, gpointer unused, GError *error, gpointer
 	renderer = gtk_cell_renderer_text_new ();
 	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
 	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, "text", S_NAME_COLUMN, NULL);
-	gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo), renderer, set_sensitive, &self->adhoc, NULL);
+	gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo), renderer, set_sensitive, &self->mode, NULL);
 
 	gtk_combo_box_set_active (combo, active < 0 ? 0 : (guint32) active);
 	g_object_unref (G_OBJECT (sec_model));
@@ -480,9 +505,11 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 	 */
 	mode = nm_setting_wireless_get_mode (s_wireless);
 	if (g_strcmp0 (mode, NM_SETTING_WIRELESS_MODE_ADHOC) == 0)
-		self->adhoc = TRUE;
+		self->mode = NM_802_11_MODE_ADHOC;
+	else if (g_strcmp0 (mode, NM_SETTING_WIRELESS_MODE_AP) == 0)
+		self->mode = NM_802_11_MODE_AP;
 	else
-		self->adhoc = FALSE;
+		self->mode = NM_802_11_MODE_INFRA;
 
 	sec = wireless_security_combo_get_active (self);
 	if (sec) {
@@ -500,7 +527,7 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 			valid = FALSE;
 		}
 
-		if (self->adhoc) {
+		if (self->mode == NM_802_11_MODE_ADHOC) {
 			if (!wireless_security_adhoc_compatible (sec)) {
 				g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "Security not compatible with Ad-Hoc mode");
 				valid = FALSE;
diff --git a/src/connection-editor/page-wifi-security.h b/src/connection-editor/page-wifi-security.h
index a0dd0ed..089a63c 100644
--- a/src/connection-editor/page-wifi-security.h
+++ b/src/connection-editor/page-wifi-security.h
@@ -46,7 +46,7 @@ typedef struct {
 	gboolean disposed;
 	GtkSizeGroup *group;
 	GtkComboBox *security_combo;
-	gboolean adhoc;
+	NM80211Mode mode;
 } CEPageWifiSecurity;
 
 typedef struct {
diff --git a/src/connection-editor/page-wifi.c b/src/connection-editor/page-wifi.c
index abab26c..1eee683 100644
--- a/src/connection-editor/page-wifi.c
+++ b/src/connection-editor/page-wifi.c
@@ -243,18 +243,22 @@ mode_combo_changed_cb (GtkComboBox *combo,
 	CEPageWifiPrivate *priv = CE_PAGE_WIFI_GET_PRIVATE (self);
 	CEPage *parent = CE_PAGE (self);
 	GtkWidget *widget;
-	gboolean show;
+	gboolean show_freq = FALSE;
+	gboolean show_bssid = FALSE;
 
  	switch (gtk_combo_box_get_active (GTK_COMBO_BOX (combo))) {
+	case 2: /* hotspot */
+		show_bssid = FALSE;
+		/* drop through */
  	case 1: /* adhoc */
-		show = TRUE;
+		show_freq = TRUE;
  		break;
  	default: /* infrastructure */
-		show = FALSE;
+		show_freq = FALSE;
  		break;
  	}
 
-	if (show) {
+	if (show_freq) {
 		widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wifi_band_label"));
 		gtk_widget_show (widget);
 		gtk_widget_show (GTK_WIDGET (priv->band));
@@ -271,11 +275,22 @@ mode_combo_changed_cb (GtkComboBox *combo,
 	}
 
 	widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wifi_band_label"));
-	gtk_widget_set_sensitive (GTK_WIDGET (widget), show);
-	gtk_widget_set_sensitive (GTK_WIDGET (priv->band), show);
+	gtk_widget_set_sensitive (GTK_WIDGET (widget), show_freq);
+	gtk_widget_set_sensitive (GTK_WIDGET (priv->band), show_freq);
 	widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wifi_channel_label"));
-	gtk_widget_set_sensitive (GTK_WIDGET (widget), show);
-	gtk_widget_set_sensitive (GTK_WIDGET (priv->channel), show);
+	gtk_widget_set_sensitive (GTK_WIDGET (widget), show_freq);
+	gtk_widget_set_sensitive (GTK_WIDGET (priv->channel), show_freq);
+
+	widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wifi_bssid_label"));
+	if (show_bssid) {
+		gtk_widget_show (widget);
+		gtk_widget_show (GTK_WIDGET (priv->bssid));
+	} else {
+		gtk_widget_hide (widget);
+		gtk_widget_hide (GTK_WIDGET (priv->bssid));
+	}
+	gtk_widget_set_sensitive (widget, show_bssid);
+	gtk_widget_set_sensitive (GTK_WIDGET (priv->bssid), show_bssid);
 
 	ce_page_changed (CE_PAGE (self));
 }
@@ -332,8 +347,10 @@ populate_ui (CEPageWifi *self)
 
 	/* Default to Infrastructure */
 	gtk_combo_box_set_active (priv->mode, 0);
-	if (mode && !strcmp (mode, "adhoc"))
+	if (!g_strcmp0 (mode, "adhoc"))
 		gtk_combo_box_set_active (priv->mode, 1);
+	if (!g_strcmp0 (mode, "ap"))
+		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_free (mode);
@@ -490,10 +507,17 @@ ui_to_setting (CEPageWifi *self)
 
 	ssid = ce_page_wifi_get_ssid (self);
 
-	if (gtk_combo_box_get_active (priv->mode) == 1)
+	switch (gtk_combo_box_get_active (priv->mode)) {
+	case 1:
 		mode = "adhoc";
-	else
+		break;
+	case 2:
+		mode = "ap";
+		break;
+	default:
 		mode = "infrastructure";
+		break;
+	}
 
 	switch (gtk_combo_box_get_active (priv->band)) {
 	case 1:
diff --git a/src/wireless-security/wireless-security.c b/src/wireless-security/wireless-security.c
index fc77777..5088474 100644
--- a/src/wireless-security/wireless-security.c
+++ b/src/wireless-security/wireless-security.c
@@ -198,6 +198,7 @@ wireless_security_init (gsize obj_size,
 	g_object_ref_sink (sec->ui_widget);
 
 	sec->adhoc_compatible = TRUE;
+	sec->hotspot_compatible = TRUE;
 
 	return sec;
 }
@@ -220,6 +221,14 @@ wireless_security_adhoc_compatible (WirelessSecurity *sec)
 	return sec->adhoc_compatible;
 }
 
+gboolean
+wireless_security_hotspot_compatible (WirelessSecurity *sec)
+{
+	g_return_val_if_fail (sec != NULL, FALSE);
+
+	return sec->hotspot_compatible;
+}
+
 void
 wireless_security_clear_ciphers (NMConnection *connection)
 {
diff --git a/src/wireless-security/wireless-security.h b/src/wireless-security/wireless-security.h
index eea98c3..2ea8e7f 100644
--- a/src/wireless-security/wireless-security.h
+++ b/src/wireless-security/wireless-security.h
@@ -48,6 +48,7 @@ struct _WirelessSecurity {
 	gpointer changed_notify_data;
 	const char *default_field;
 	gboolean adhoc_compatible;
+	gboolean hotspot_compatible;
 
 	WSAddToSizeGroupFunc add_to_size_group;
 	WSFillConnectionFunc fill_connection;
@@ -81,6 +82,8 @@ GtkWidget * wireless_security_nag_user (WirelessSecurity *sec);
 
 gboolean wireless_security_adhoc_compatible (WirelessSecurity *sec);
 
+gboolean wireless_security_hotspot_compatible (WirelessSecurity *sec);
+
 WirelessSecurity *wireless_security_ref (WirelessSecurity *sec);
 
 void wireless_security_unref (WirelessSecurity *sec);
diff --git a/src/wireless-security/ws-dynamic-wep.c b/src/wireless-security/ws-dynamic-wep.c
index 7d9ea3a..99a8f65 100644
--- a/src/wireless-security/ws-dynamic-wep.c
+++ b/src/wireless-security/ws-dynamic-wep.c
@@ -128,6 +128,7 @@ ws_dynamic_wep_new (NMConnection *connection,
 
 	parent->nag_user = nag_user;
 	parent->adhoc_compatible = FALSE;
+	parent->hotspot_compatible = FALSE;
 
 	widget = ws_802_1x_auth_combo_init (parent,
 	                                    "dynamic_wep_auth_combo",
diff --git a/src/wireless-security/ws-leap.c b/src/wireless-security/ws-leap.c
index 1f0fdaf..896574d 100644
--- a/src/wireless-security/ws-leap.c
+++ b/src/wireless-security/ws-leap.c
@@ -150,6 +150,7 @@ ws_leap_new (NMConnection *connection, gboolean secrets_only)
 	}
 
 	parent->adhoc_compatible = FALSE;
+	parent->hotspot_compatible = FALSE;
 	sec = (WirelessSecurityLEAP *) parent;
 
 	widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "leap_password_entry"));
diff --git a/src/wireless-security/ws-wpa-eap.c b/src/wireless-security/ws-wpa-eap.c
index d0dad00..a6c52e1 100644
--- a/src/wireless-security/ws-wpa-eap.c
+++ b/src/wireless-security/ws-wpa-eap.c
@@ -124,6 +124,7 @@ ws_wpa_eap_new (NMConnection *connection,
 
 	parent->nag_user = nag_user;
 	parent->adhoc_compatible = FALSE;
+	parent->hotspot_compatible = FALSE;
 
 	widget = ws_802_1x_auth_combo_init (parent,
 	                                    "wpa_eap_auth_combo",



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]