From: Nicolas Cavallari <cavallar@lri.fr>
Date: Fri, 20 May 2016 14:30:50 +0800
Subject: Allow to create and connect to Ad-Hoc RSN networks.

This follows changes to Network Manager, which now
supports WPA2/RSN in Ad-Hoc/IBSS mode.
---
 src/applet-dialogs.c                       |  2 --
 src/connection-editor/page-wifi-security.c |  9 ++-------
 src/libnm-gtk/nm-wifi-dialog.c             |  3 +--
 src/wireless-security/ws-wpa-psk.c         | 15 +++++++--------
 4 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/src/applet-dialogs.c b/src/applet-dialogs.c
index 3182430..fbd9290 100644
--- a/src/applet-dialogs.c
+++ b/src/applet-dialogs.c
@@ -225,8 +225,6 @@ create_info_label_security (NMConnection *connection)
 
 			if (!strcmp (key_mgmt, "none"))
 				label = g_strdup (_("WEP"));
-			else if (!strcmp (key_mgmt, "wpa-none"))
-				label = g_strdup (_("WPA/WPA2"));
 			else if (!strcmp (key_mgmt, "wpa-psk"))
 				label = g_strdup (_("WPA/WPA2"));
 			else
diff --git a/src/connection-editor/page-wifi-security.c b/src/connection-editor/page-wifi-security.c
index 19fd285..4304c5c 100644
--- a/src/connection-editor/page-wifi-security.c
+++ b/src/connection-editor/page-wifi-security.c
@@ -124,8 +124,7 @@ get_default_type_for_security (NMSettingWirelessSecurity *sec)
 		return NMU_SEC_DYNAMIC_WEP;
 	}
 
-	if (   !strcmp (key_mgmt, "wpa-none")
-	    || !strcmp (key_mgmt, "wpa-psk")) {
+	if (!strcmp (key_mgmt, "wpa-psk")) {
 		if (find_proto (sec, "rsn"))
 			return NMU_SEC_WPA2_PSK;
 		else if (find_proto (sec, "wpa"))
@@ -404,7 +403,7 @@ finish_setup (CEPageWifiSecurity *self, gpointer unused, GError *error, gpointer
 		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, TRUE);
+			                   &iter, _("WPA & WPA2 Personal"), TRUE, TRUE);
 			if ((active < 0) && ((default_type == NMU_SEC_WPA_PSK) || (default_type == NMU_SEC_WPA2_PSK)))
 				active = item;
 			item++;
@@ -536,10 +535,6 @@ ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error)
 	s_wireless = nm_connection_get_setting_wireless (connection);
 	g_assert (s_wireless);
 
-	/* Kernel Ad-Hoc WPA support is busted; it creates open networks.  Disable
-	 * WPA when Ad-Hoc is selected.  set_sensitive() will pick up priv->mode
-	 * and do the right thing.
-	 */
 	mode = nm_setting_wireless_get_mode (s_wireless);
 	if (g_strcmp0 (mode, NM_SETTING_WIRELESS_MODE_ADHOC) == 0)
 		priv->mode = NM_802_11_MODE_ADHOC;
diff --git a/src/libnm-gtk/nm-wifi-dialog.c b/src/libnm-gtk/nm-wifi-dialog.c
index 49e3ff5..5936a7c 100644
--- a/src/libnm-gtk/nm-wifi-dialog.c
+++ b/src/libnm-gtk/nm-wifi-dialog.c
@@ -716,8 +716,7 @@ get_default_type_for_security (NMSettingWirelessSecurity *sec,
 		return NMU_SEC_DYNAMIC_WEP;
 	}
 
-	if (   !strcmp (key_mgmt, "wpa-none")
-	    || !strcmp (key_mgmt, "wpa-psk")) {
+	if (!strcmp (key_mgmt, "wpa-psk")) {
 		if (!have_ap || (ap_flags & NM_802_11_AP_FLAGS_PRIVACY)) {
 			if (find_proto (sec, "rsn"))
 				return NMU_SEC_WPA2_PSK;
diff --git a/src/wireless-security/ws-wpa-psk.c b/src/wireless-security/ws-wpa-psk.c
index 0926859..1c545b2 100644
--- a/src/wireless-security/ws-wpa-psk.c
+++ b/src/wireless-security/ws-wpa-psk.c
@@ -146,14 +146,13 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection)
 	wireless_security_clear_ciphers (connection);
 	if (is_adhoc) {
 		/* Ad-Hoc settings as specified by the supplicant */
-		g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-none", NULL);
-		nm_setting_wireless_security_add_proto (s_wireless_sec, "wpa");
-		nm_setting_wireless_security_add_pairwise (s_wireless_sec, "none");
+		g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NULL);
+		nm_setting_wireless_security_add_proto (s_wireless_sec, "rsn");
 
-		/* Ad-hoc can only have _one_ group cipher... default to TKIP to be more
-		 * compatible for now.  Maybe we'll support selecting CCMP later.
-		 */
-		nm_setting_wireless_security_add_group (s_wireless_sec, "tkip");
+		/* The supplicant only supports CCMP with Ad-hoc RSN;
+		 * Selecting something else will make it use CCMP anyway. */
+		nm_setting_wireless_security_add_pairwise (s_wireless_sec, "ccmp");
+		nm_setting_wireless_security_add_group (s_wireless_sec, "ccmp");
 	} else {
 		g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NULL);
 
@@ -193,7 +192,7 @@ ws_wpa_psk_new (NMConnection *connection, gboolean secrets_only)
 	if (!parent)
 		return NULL;
 
-	parent->adhoc_compatible = FALSE;
+	parent->adhoc_compatible = TRUE;
 	sec = (WirelessSecurityWPAPSK *) parent;
 	sec->editing_connection = secrets_only ? FALSE : TRUE;
 	sec->password_flags_name = NM_SETTING_WIRELESS_SECURITY_PSK;
