From cbe8b9901f9cc254cbaa1ec1cee1c52af8f828bf Mon Sep 17 00:00:00 2001
From: Peter Oh <peter.oh@bowerswilkins.com>
Date: Thu, 12 Apr 2018 02:49:00 -0700
Subject: [PATCH 03/15] mesh: relocate RSN init function

RSN init function should work together with mesh join
when it's used. Since mesh join could be called at different stage
if DFS channel is used, relocate the function to mesh join.
It is still the same call flows of mesh join before this changes
if non-DFS channels are used, hence no side effect will occur.

Signed-off-by: Peter Oh <peter.oh@bowerswilkins.com>
---
 wpa_supplicant/mesh.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

--- a/wpa_supplicant/mesh.c
+++ b/wpa_supplicant/mesh.c
@@ -333,9 +333,6 @@ static int wpa_supplicant_mesh_init(stru
 		return -1;
 	}
 
-	if (wpas_mesh_init_rsn(wpa_s))
-		goto out_free;
-
 	wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf);
 
 	return 0;
@@ -381,6 +378,12 @@ void wpas_join_mesh(struct wpa_supplican
 	struct wpa_ssid *ssid = wpa_s->current_ssid;
 	int ret = 0;
 
+	if (wpas_mesh_init_rsn(wpa_s)) {
+		wpa_printf(MSG_ERROR, "Init RSN failed. Deinit mesh...");
+		wpa_supplicant_mesh_deinit(wpa_s);
+		return;
+	}
+
 	if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) {
 		wpa_s->pairwise_cipher = wpa_s->mesh_rsn->pairwise_cipher;
 		wpa_s->group_cipher = wpa_s->mesh_rsn->group_cipher;
