From eda600136ecca0d4cc9cffefb90dc7d96df6cd2c Mon Sep 17 00:00:00 2001
From: hyunuktak <hyunuk.tak@samsung.com>
Date: Tue, 23 Jan 2018 16:08:42 +0900
Subject: [PATCH 01/16] Fixed uninitialized scalar variable

Change-Id: Ia285faae7af652612fadbe95f0863bc315d429a6
---
 src/service.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/service.c b/src/service.c
index d0543ae5..9f6df41e 100755
--- a/src/service.c
+++ b/src/service.c
@@ -4096,6 +4096,7 @@ int __connman_service_set_passphrase(struct connman_service *service,
 	/* The encrypted passphrase is used here
 	 * and validation is done by net-config before being encrypted.
 	 */
+	err = 0;
 	if (service->security != CONNMAN_SERVICE_SECURITY_PSK &&
 			service->security != CONNMAN_SERVICE_SECURITY_RSN &&
 			service->security != CONNMAN_SERVICE_SECURITY_WEP)
-- 
2.34.1


From 63d4f774d04c381000e45e7490bc838da9b36027 Mon Sep 17 00:00:00 2001
From: Jaehyun Kim <jeik01.kim@samsung.com>
Date: Tue, 20 Feb 2018 15:37:40 +0900
Subject: [PATCH 02/16] Added new dbus method to support bssid based connection

Change-Id: I95d2a56c1d26db06cbdb5c85dc0e2b33b3c10da3
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
---
 gsupplicant/gsupplicant.h |  2 ++
 gsupplicant/supplicant.c  | 32 +++++++++++++++-------
 plugins/wifi.c            | 15 +++++++++--
 src/connman.h             | 11 ++++++++
 src/technology.c          | 57 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 106 insertions(+), 11 deletions(-)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 46d065bf..0476ff66 100755
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -173,6 +173,8 @@ struct _GSupplicantSSID {
 	int ignore_broadcast_ssid;
 #if defined TIZEN_EXT
 	unsigned char *bssid;
+	unsigned int bssid_for_connect_len;
+	unsigned char bssid_for_connect[6];
 #endif
 };
 
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 724520e0..9b7a9349 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -4815,7 +4815,8 @@ static void interface_select_network_params(DBusMessageIter *iter,
 	dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
 					&interface->network_path);
 #if defined TIZEN_EXT
-	dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &ssid->freq);
+	if (!ssid->bssid_for_connect_len)
+		dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &ssid->freq);
 #endif
 }
 
@@ -4842,14 +4843,20 @@ static void interface_add_network_result(const char *error,
 
 #if defined TIZEN_EXT
 	SUPPLICANT_DBG(".Interface.SelectNetworkFreq");
-#endif
+	GSupplicantSSID *ssid = data->ssid;
 
-#if defined TIZEN_EXT
-	supplicant_dbus_method_call(data->interface->path,
-			SUPPLICANT_INTERFACE ".Interface", "SelectNetworkFreq",
-			interface_select_network_params,
-			interface_select_network_result, data,
-			interface);
+	if (!ssid->bssid_for_connect_len)
+		supplicant_dbus_method_call(data->interface->path,
+				SUPPLICANT_INTERFACE ".Interface", "SelectNetworkFreq",
+				interface_select_network_params,
+				interface_select_network_result, data,
+				interface);
+	else
+		supplicant_dbus_method_call(data->interface->path,
+				SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
+				interface_select_network_params,
+				interface_select_network_result, data,
+				interface);
 #else
 	supplicant_dbus_method_call(data->interface->path,
 			SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
@@ -5401,9 +5408,16 @@ static void interface_add_network_params(DBusMessageIter *iter, void *user_data)
 			supplicant_dbus_dict_close(iter, &dict);
 			return;
 		}
-		snprintf(bssid, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
+
+		if (ssid->bssid_for_connect_len)
+			snprintf(bssid, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
+					ssid->bssid_for_connect[0], ssid->bssid_for_connect[1], ssid->bssid_for_connect[2],
+					ssid->bssid_for_connect[3], ssid->bssid_for_connect[4], ssid->bssid_for_connect[5]);
+		else
+			snprintf(bssid, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
 					ssid->bssid[0], ssid->bssid[1], ssid->bssid[2],
 					ssid->bssid[3], ssid->bssid[4], ssid->bssid[5]);
+
 		supplicant_dbus_dict_append_basic(&dict, "bssid",
 					DBUS_TYPE_STRING, &bssid);
 		g_free(bssid);
diff --git a/plugins/wifi.c b/plugins/wifi.c
index c66f838c..3d7636ce 100755
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -2393,6 +2393,8 @@ static void connect_callback(int result, GSupplicantInterface *interface,
 	DBG("network %p result %d", network, result);
 
 #if defined TIZEN_EXT
+	set_connman_bssid(RESET_BSSID, NULL);
+
 	for (list = iface_list; list; list = list->next) {
 		wifi = list->data;
 
@@ -2500,7 +2502,16 @@ static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
 	ssid->bssid = connman_network_get_bssid(network);
 #endif
 #if defined TIZEN_EXT
-	ssid->freq = connman_network_get_frequency(network);
+	if (set_connman_bssid(CHECK_BSSID, NULL) == 6) {
+		ssid->bssid_for_connect_len = 6;
+		set_connman_bssid(GET_BSSID, (char *)ssid->bssid_for_connect);
+		DBG("BSSID : %02x:%02x:%02x:%02x:%02x:%02x",
+			ssid->bssid_for_connect[0], ssid->bssid_for_connect[1],
+			ssid->bssid_for_connect[2], ssid->bssid_for_connect[3],
+			ssid->bssid_for_connect[4], ssid->bssid_for_connect[5]);
+	} else {
+		ssid->freq = connman_network_get_frequency(network);
+	}
 #endif
 
 	if (connman_setting_get_bool("BackgroundScanning"))
@@ -2803,7 +2814,7 @@ static bool handle_wps_completion(GSupplicantInterface *interface,
 			 return true;
 		 }
 
-		 ret = send_encryption_request(passphrase, passphrase);
+		 ret = send_encryption_request(passphrase, network);
 
 		 g_free(passphrase);
 
diff --git a/src/connman.h b/src/connman.h
index 4125463b..a5977b88 100755
--- a/src/connman.h
+++ b/src/connman.h
@@ -564,6 +564,17 @@ void __connman_technology_remove_interface(enum connman_service_type type,
 void __connman_technology_notify_regdom_by_device(struct connman_device *device,
 						int result, const char *alpha2);
 
+#if defined TIZEN_EXT
+enum bssid_type {
+	CHECK_BSSID = 0,
+	GET_BSSID   = 1,
+	SET_BSSID   = 2,
+	RESET_BSSID = 3,
+};
+
+int set_connman_bssid(enum bssid_type mode, char *bssid);
+#endif
+
 #include <connman/device.h>
 
 int __connman_device_init(const char *device, const char *nodevice);
diff --git a/src/technology.c b/src/technology.c
index 5aea9f4f..5d5b70f0 100755
--- a/src/technology.c
+++ b/src/technology.c
@@ -25,6 +25,9 @@
 
 #include <errno.h>
 #include <string.h>
+#if defined TIZEN_EXT
+#include <stdio.h>
+#endif
 
 #include <gdbus.h>
 
@@ -876,6 +879,49 @@ make_reply:
 	return reply;
 }
 
+#if defined TIZEN_EXT
+int set_connman_bssid(enum bssid_type mode, char *bssid)
+{
+	static unsigned char bssid_for_connect[6];
+	static int bssid_len;
+
+	DBG("mode : %d", mode);
+
+	if (mode == CHECK_BSSID) {
+		return bssid_len;
+	}
+
+	if (mode == GET_BSSID && bssid) {
+		memcpy(bssid, bssid_for_connect, 6);
+		return bssid_len;
+	}
+
+	if (mode == RESET_BSSID) {
+		bssid_len = 0;
+		return bssid_len;
+	}
+
+	if (mode != SET_BSSID || !bssid) {
+		DBG("Invalid parameter");
+		return 0;
+	}
+
+	bssid_len = sscanf(bssid, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
+		&bssid_for_connect[0], &bssid_for_connect[1], &bssid_for_connect[2],
+		&bssid_for_connect[3], &bssid_for_connect[4], &bssid_for_connect[5]);
+	if (bssid_len != 6) {
+		DBG("Incorrect BSSID format. bssid_len = %d", bssid_len);
+		bssid_len = 0;
+	}
+
+	DBG("SET BSSID len : %d, BSSID : %02x:%02x:%02x:%02x:%02x:%02x", bssid_len,
+		bssid_for_connect[0], bssid_for_connect[1], bssid_for_connect[2],
+		bssid_for_connect[3], bssid_for_connect[4], bssid_for_connect[5]);
+
+	return bssid_len;
+}
+#endif
+
 static DBusMessage *set_property(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
@@ -1023,6 +1069,17 @@ static DBusMessage *set_property(DBusConnection *conn,
 		dbus_message_iter_get_basic(&value, &enable);
 
 		return set_powered(technology, msg, enable);
+#if defined TIZEN_EXT
+	} else if (g_str_equal(name, "SetBSSID")) {
+		char *key;
+
+		if (type != DBUS_TYPE_STRING)
+			return __connman_error_invalid_arguments(msg);
+
+		dbus_message_iter_get_basic(&value, &key);
+		DBG("BSSID %s", key);
+		set_connman_bssid(SET_BSSID, key);
+#endif
 	} else
 		return __connman_error_invalid_property(msg);
 
-- 
2.34.1


From ca78e0cbb13bbd69de43f9a5d3f05d9ce51f58d1 Mon Sep 17 00:00:00 2001
From: Niraj Kumar Goit <niraj.g@samsung.com>
Date: Thu, 15 Feb 2018 16:49:26 +0530
Subject: [PATCH 03/16] [connman]Added support of EAP-FAST,EAP-PWD and
 EAP-AKA'.

Change-Id: Ibb75ff2c2e54c8d3d53f3b184502647918bf7e24
igned-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
---
 gsupplicant/gsupplicant.h | 12 +++++++++++
 gsupplicant/supplicant.c  | 43 +++++++++++++++++++++++++++++++++++++--
 plugins/wifi.c            | 29 ++++++++++++++++++++++++--
 src/network.c             |  4 ++++
 src/service.c             | 20 +++++++++++++++++-
 5 files changed, 103 insertions(+), 5 deletions(-)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 0476ff66..ead619c4 100755
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -108,6 +108,15 @@ typedef enum {
 #endif
 } GSupplicantSecurity;
 
+#if defined TIZEN_EXT
+typedef enum {
+	G_SUPPLICANT_EAP_KEYMGMT_NONE,
+	G_SUPPLICANT_EAP_KEYMGMT_FT,
+	G_SUPPLICANT_EAP_KEYMGMT_CCKM,
+	G_SUPPLICANT_EAP_KEYMGMT_OKC,
+} GSupplicantEapKeymgmt;
+#endif
+
 typedef enum {
 	G_SUPPLICANT_STATE_UNKNOWN,
 	G_SUPPLICANT_STATE_DISABLED,
@@ -175,6 +184,9 @@ struct _GSupplicantSSID {
 	unsigned char *bssid;
 	unsigned int bssid_for_connect_len;
 	unsigned char bssid_for_connect[6];
+	GSupplicantEapKeymgmt eap_keymgmt;
+	const char *phase1;
+	const char *pac_file;
 #endif
 };
 
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 9b7a9349..92efbc9c 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -5131,6 +5131,33 @@ static void add_network_security_aka_sim(DBusMessageIter *dict,
 			DBUS_TYPE_STRING,
 			&ssid->passphrase);
 }
+
+static void add_network_security_fast(DBusMessageIter *dict,
+		GSupplicantSSID *ssid)
+{
+	/*
+	 * For FAST, we at least need:
+	 *              id / password
+	 *              phase1 (provisiong information)
+	 *              pac_file
+	 */
+
+	/* Allow provisioing both authenticated and unauthenticated */
+	const char *phase1 = "fast_provisioning=2";
+	supplicant_dbus_dict_append_basic(dict, "phase1",
+			DBUS_TYPE_STRING,
+			&phase1);
+
+	SUPPLICANT_DBG("pac_file [%s]", ssid->pac_file);
+	if(ssid->pac_file)
+		supplicant_dbus_dict_append_basic(dict, "pac_file",
+				DBUS_TYPE_STRING,
+				&ssid->pac_file);
+
+	supplicant_dbus_dict_append_basic(dict, "password",
+			DBUS_TYPE_STRING,
+			&ssid->passphrase);
+}
 #endif
 
 static void add_network_security_eap(DBusMessageIter *dict,
@@ -5157,8 +5184,20 @@ static void add_network_security_eap(DBusMessageIter *dict,
 
 #if defined TIZEN_EXT
 	} else if (g_strcmp0(ssid->eap, "sim") == 0 ||
-			g_strcmp0(ssid->eap, "aka") == 0) {
+			g_strcmp0(ssid->eap, "aka") == 0 ||
+			g_strcmp0(ssid->eap, "aka'") == 0) {
 		add_network_security_aka_sim(dict, ssid);
+	} else if (g_strcmp0(ssid->eap, "pwd") == 0) {
+		if(!ssid->passphrase)
+			return;
+		supplicant_dbus_dict_append_basic(dict, "password",
+				DBUS_TYPE_STRING,
+				&ssid->passphrase);
+	} else if (g_strcmp0(ssid->eap, "fast") == 0){
+		if (!ssid->identity || !ssid->passphrase)
+			return;
+
+		add_network_security_fast(dict, ssid);
 #endif
 	} else
 		return;
@@ -5738,7 +5777,7 @@ int g_supplicant_interface_connect(GSupplicantInterface *interface,
 			network_remove(intf_data);
 		} else
 #if defined TIZEN_EXT
-			if (ssid->passphrase && g_strcmp0(ssid->passphrase, "") != 0) {
+			if (ssid->passphrase && g_strcmp0(ssid->passphrase, "") != 0 && !ssid->eap) {
 				ret = send_decryption_request(ssid->passphrase, data);
 				if (ret < 0)
 					SUPPLICANT_DBG("Decryption request failed %d", ret);
diff --git a/plugins/wifi.c b/plugins/wifi.c
index 3d7636ce..ebbd6b83 100755
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -74,6 +74,10 @@
 #define ASSOC_STATUS_NO_CLIENT 17
 #define LOAD_SHAPING_MAX_RETRIES 3
 
+#if defined TIZEN_EXT
+#define WIFI_EAP_FAST_PAC_FILE		"/var/lib/wifi/wifi.pac"	/* path of Pac file for EAP-FAST */
+#endif
+
 static struct connman_technology *wifi_technology = NULL;
 static struct connman_technology *p2p_technology = NULL;
 
@@ -2442,6 +2446,21 @@ static GSupplicantSecurity network_security(const char *security)
 	return G_SUPPLICANT_SECURITY_UNKNOWN;
 }
 
+#if defined TIZEN_EXT
+static GSupplicantEapKeymgmt network_eap_keymgmt(const char *security)
+{
+	if (security == NULL)
+		return G_SUPPLICANT_EAP_KEYMGMT_NONE;
+
+	if (g_str_equal(security, "FT") == TRUE)
+		return G_SUPPLICANT_EAP_KEYMGMT_FT;
+	else if (g_str_equal(security, "CCKM") == TRUE)
+		return G_SUPPLICANT_EAP_KEYMGMT_CCKM;
+
+	return G_SUPPLICANT_EAP_KEYMGMT_NONE;
+}
+#endif
+
 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
 {
 	const char *security;
@@ -2500,8 +2519,14 @@ static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
 
 #if defined TIZEN_EXT
 	ssid->bssid = connman_network_get_bssid(network);
-#endif
-#if defined TIZEN_EXT
+
+	ssid->eap_keymgmt = network_eap_keymgmt(
+			connman_network_get_string(network, "WiFi.KeymgmtType"));
+	ssid->phase1 = connman_network_get_string(network, "WiFi.Phase1");
+
+	if(g_strcmp0(ssid->eap, "fast") == 0)
+		ssid->pac_file = g_strdup(WIFI_EAP_FAST_PAC_FILE);
+
 	if (set_connman_bssid(CHECK_BSSID, NULL) == 6) {
 		ssid->bssid_for_connect_len = 6;
 		set_connman_bssid(GET_BSSID, (char *)ssid->bssid_for_connect);
diff --git a/src/network.c b/src/network.c
index cf74b6d5..0e3d4b34 100755
--- a/src/network.c
+++ b/src/network.c
@@ -115,6 +115,10 @@ struct connman_network {
 		int disconnect_reason;
 		int assoc_status_code;
 		GSList *vsie_list;
+		/*
+		* Only for EAP-FAST
+		*/
+		char *phase1;
 #endif
 	} wifi;
 
diff --git a/src/service.c b/src/service.c
index 9510def8..c3bdc0e5 100755
--- a/src/service.c
+++ b/src/service.c
@@ -167,6 +167,10 @@ struct connman_service {
 	char *keymgmt_type;
 	int disconnect_reason;
 	int assoc_status_code;
+	/*
+	 * Only for EAP-FAST
+	 */
+	char *phase1;
 #endif
 #ifdef TIZEN_EXT
 	enum connman_dnsconfig_method dns_config_method_ipv4;
@@ -7945,6 +7949,17 @@ static void prepare_8021x(struct connman_service *service)
 	if (service->phase2)
 		connman_network_set_string(service->network, "WiFi.Phase2",
 							service->phase2);
+
+#if defined TIZEN_EXT
+	if (service->keymgmt_type)
+		connman_network_set_string(service->network, "WiFi.KeymgmtType",
+							service->keymgmt_type);
+
+	DBG("service->phase1 : %s", service->phase1);
+	if (service->phase1)
+		connman_network_set_string(service->network, "WiFi.Phase1",
+							service->phase1);
+#endif
 }
 
 static int service_connect(struct connman_service *service)
@@ -8032,7 +8047,10 @@ static int service_connect(struct connman_service *service)
 			DBG("service eap: %s", service->eap);
 			if (g_str_equal(service->eap, "tls") ||
 				g_str_equal(service->eap, "sim") ||
-				g_str_equal(service->eap, "aka"))
+				g_str_equal(service->eap, "aka") ||
+				g_str_equal(service->eap, "aka'") ||
+				g_str_equal(service->eap, "pwd") ||
+				g_str_equal(service->eap, "fast"))
 				break;
 #else
 			/*
-- 
2.34.1


From ef389a7b9279d9e7c2a677041ef87f5d7dad605a Mon Sep 17 00:00:00 2001
From: hyunuktak <hyunuk.tak@samsung.com>
Date: Fri, 23 Mar 2018 10:27:16 +0900
Subject: [PATCH 04/16] Fix a coverity for logically dead code

Change-Id: I649ed8bbf277611324934db7895d7a8c0cb25ec8
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
---
 plugins/wifi.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index ebbd6b83..3135484b 100755
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -3729,11 +3729,6 @@ static void peer_changed(GSupplicantPeer *peer, GSupplicantPeerState state)
 	struct connman_peer *connman_peer;
 	const char *identifier;
 
-#if defined TIZEN_EXT
-	if (!wifi)
-		return;
-#endif
-
 	identifier = g_supplicant_peer_get_identifier(peer);
 
 	DBG("ident: %s", identifier);
-- 
2.34.1


From 1ba0554641742c75d9f8d0eacd5bb3bd14d32f36 Mon Sep 17 00:00:00 2001
From: taesub kim <taesub.kim@samsung.com>
Date: Mon, 2 Apr 2018 17:36:12 +0900
Subject: [PATCH 05/16] Added dbus/cynara policy

Change-Id: I82192eb00243dd45e64e37e806d7c7e90fa3fac2
Signed-off-by: Taesub Kim <taesub.kim@samsung.com>
---
 vpn/vpn-dbus.conf | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/vpn/vpn-dbus.conf b/vpn/vpn-dbus.conf
index 7b7b6d19..8ebfc6b6 100755
--- a/vpn/vpn-dbus.conf
+++ b/vpn/vpn-dbus.conf
@@ -1,20 +1,22 @@
 <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
  "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
 <busconfig>
-    <policy user="root">
-        <allow own="net.connman.vpn"/>
-        <allow send_destination="net.connman.vpn"/>
+	<policy user="root">
+		<allow own="net.connman.vpn"/>
+		<allow send_destination="net.connman.vpn"/>
 		<allow send_interface="net.connman.vpn.Agent"/>
-    </policy>
-    <policy user="network_fw">
-        <allow own="net.connman.vpn"/>
-        <allow send_destination="net.connman.vpn"/>
+	</policy>
+	<policy user="network_fw">
+		<allow own="net.connman.vpn"/>
+		<allow send_destination="net.connman.vpn"/>
 		<allow send_interface="net.connman.vpn.Agent"/>
-    </policy>
-    <policy at_console="true">
-        <allow send_destination="net.connman.vpn"/>
-    </policy>
-    <policy context="default">
-        <deny send_destination="net.connman.vpn"/>
-    </policy>
+	</policy>
+	<policy at_console="true">
+		<allow send_destination="net.connman.vpn"/>
+	</policy>
+	<policy context="default">
+		<deny own="net.connman.vpn"/>
+		<deny send_destination="net.connman.vpn"/>
+		<deny send_interface="net.connman.vpn.Agent"/>
+	</policy>
 </busconfig>
-- 
2.34.1


From 4d78ef9b291362ba956e0706f30f3cb552fca725 Mon Sep 17 00:00:00 2001
From: hyunuktak <hyunuk.tak@samsung.com>
Date: Tue, 3 Apr 2018 13:36:36 +0900
Subject: [PATCH 06/16] Fixed a coverity for resource leak

Change-Id: I990f3c1d314580546c4dfa4716d1a2e535bcd491
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
---
 src/rtnl.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/rtnl.c b/src/rtnl.c
index 35ae0a96..ac29f313 100755
--- a/src/rtnl.c
+++ b/src/rtnl.c
@@ -159,6 +159,7 @@ static void read_uevent(struct interface_data *interface)
 	if (__connman_rtnl_is_cellular_device(name)) {
 		interface->service_type = CONNMAN_SERVICE_TYPE_CELLULAR;
 		interface->device_type = CONNMAN_DEVICE_TYPE_CELLULAR;
+		g_free(name);
 		return;
 	}
 #endif
-- 
2.34.1


From 22367513ced9ff5921eb6b1dd7b65c5d108b2a99 Mon Sep 17 00:00:00 2001
From: Niraj Kumar Goit <niraj.g@samsung.com>
Date: Thu, 5 Apr 2018 11:57:15 +0530
Subject: [PATCH 07/16] Add SSID and Frequency mixed scan.

Change-Id: I6ca91a5f073c11712a936844589aa72c27c0145e
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
---
 include/technology.h | 13 ++++++++++++
 plugins/wifi.c       | 49 ++++++++++++++++++++++++++++++++++++++++++--
 src/technology.c     | 49 +++++++++++++++++++++++++++++++++++++-------
 3 files changed, 102 insertions(+), 9 deletions(-)

diff --git a/include/technology.h b/include/technology.h
index 55bb3dd5..73cd8e7a 100755
--- a/include/technology.h
+++ b/include/technology.h
@@ -34,6 +34,19 @@ extern "C" {
  * @short_description: Functions for handling technology details
  */
 
+#if defined TIZEN_EXT
+typedef enum {
+	CONNMAN_MULTI_SCAN_SSID = 0x01,
+	CONNMAN_MULTI_SCAN_FREQ,
+	CONNMAN_MULTI_SCAN_SSID_FREQ,
+} connman_multi_scan_type_e;
+
+typedef struct {
+	char str[128];
+	gboolean flag;
+} connman_multi_scan_ap_s;
+#endif
+
 struct connman_technology;
 
 int connman_technology_tethering_add_station(enum connman_service_type type,
diff --git a/plugins/wifi.c b/plugins/wifi.c
index 3135484b..a9ffad05 100755
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -2075,7 +2075,7 @@ static int wifi_specific_scan(enum connman_service_type type,
 		return -EALREADY;
 
 	DBG("scan_type: %d", scan_type);
-	if (scan_type == 1) { /* ssid based scan */
+	if (scan_type == CONNMAN_MULTI_SCAN_SSID) { /* ssid based scan */
 		scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
 		if (!scan_params) {
 			DBG("Failed to allocate memory.");
@@ -2101,7 +2101,7 @@ static int wifi_specific_scan(enum connman_service_type type,
 		}
 		scan_params->num_ssids = count;
 
-	} else if (scan_type == 2) { /* frequency based scan */
+	} else if (scan_type == CONNMAN_MULTI_SCAN_FREQ) { /* frequency based scan */
 
 		scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
 		if (!scan_params) {
@@ -2129,6 +2129,51 @@ static int wifi_specific_scan(enum connman_service_type type,
 		}
 		scan_params->num_freqs = count;
 
+	} else if (scan_type == CONNMAN_MULTI_SCAN_SSID_FREQ) { /* SSID & Frequency mixed scan */
+		int freq_count, ap_count;
+		scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
+		if (!scan_params) {
+			DBG("Failed to allocate memory.");
+			return -ENOMEM;
+		}
+
+		guint size = g_slist_length(specific_scan_list);
+
+		scan_params->freqs = g_try_new0(uint16_t, size/2);
+		if (!scan_params->freqs) {
+			DBG("Failed to allocate memory.");
+			g_free(scan_params);
+			return -ENOMEM;
+		}
+
+		ap_count = freq_count = 0;
+		for (list = specific_scan_list; list; list = list->next) {
+			if (((connman_multi_scan_ap_s *)list->data)->flag == true) { /** ssid */
+				ssid = ((connman_multi_scan_ap_s *)list->data)->str;
+				int ssid_len = strlen(ssid);
+
+				scan_ssid = g_try_new0(struct scan_ssid, 1);
+				if (!scan_ssid) {
+					DBG("Failed to allocate memory.");
+					g_supplicant_free_scan_params(scan_params);
+					return -ENOMEM;
+				}
+
+				memcpy(scan_ssid->ssid, ssid, (ssid_len + 1));
+				DBG("scan ssid %s len: %d", scan_ssid->ssid, ssid_len);
+				scan_ssid->ssid_len = ssid_len;
+				scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
+				ap_count++;
+
+			} else { /* freq */
+				freq = atoi(((connman_multi_scan_ap_s *)list->data)->str);
+				scan_params->freqs[freq_count] = freq;
+				DBG("scan_params->freqs[%d]: %d", freq_count, scan_params->freqs[freq_count]);
+				freq_count++;
+			}
+		}
+		scan_params->num_ssids = ap_count;
+		scan_params->num_freqs = freq_count;
 	} else {
 		DBG("Invalid scan");
 		return -EINVAL;
diff --git a/src/technology.c b/src/technology.c
index 5d5b70f0..57ab8e14 100755
--- a/src/technology.c
+++ b/src/technology.c
@@ -27,6 +27,7 @@
 #include <string.h>
 #if defined TIZEN_EXT
 #include <stdio.h>
+#include <stdlib.h>
 #endif
 
 #include <gdbus.h>
@@ -1280,7 +1281,7 @@ static DBusMessage *specific_scan(DBusConnection *conn, DBusMessage *msg, void *
 	GSList *specific_scan_list = NULL;
 	int scan_type = 0;
 	const char *name = NULL;
-	unsigned int freq = 0;
+	const char *freq = NULL;
 	DBusMessageIter iter, dict;
 	int err;
 
@@ -1321,20 +1322,53 @@ static DBusMessage *specific_scan(DBusConnection *conn, DBusMessage *msg, void *
 				return __connman_error_invalid_arguments(msg);
 			}
 
-			scan_type = 1; /* SSID based scan */
+			scan_type = CONNMAN_MULTI_SCAN_SSID; /* SSID based scan */
 			dbus_message_iter_get_basic(&value2, &name);
 			DBG("name %s", name);
 			specific_scan_list = g_slist_append(specific_scan_list, g_strdup(name));
 		} else if (g_str_equal(key, "Frequency")) {
-			if (type != DBUS_TYPE_UINT16) {
+			if (type != DBUS_TYPE_STRING) {
+				g_slist_free_full(specific_scan_list, g_free);
+				return __connman_error_invalid_arguments(msg);
+			}
+
+			scan_type = CONNMAN_MULTI_SCAN_FREQ; /* Frequency based scan */
+			dbus_message_iter_get_basic(&value2, &freq);
+			DBG("freq %s", freq);
+			specific_scan_list = g_slist_append(specific_scan_list, GINT_TO_POINTER(atoi(freq)));
+		} else if (g_str_equal(key, "SSID_Mixed")) {
+			if (type != DBUS_TYPE_STRING) {
+				g_slist_free_full(specific_scan_list, g_free);
+				return __connman_error_invalid_arguments(msg);
+			}
+
+			scan_type = CONNMAN_MULTI_SCAN_SSID_FREQ; /* SSID & Frequency mixed scan */
+			dbus_message_iter_get_basic(&value2, &name);
+
+			connman_multi_scan_ap_s *ap = (connman_multi_scan_ap_s*)g_try_malloc0(sizeof(connman_multi_scan_ap_s));
+			if (ap) {
+				g_strlcpy(ap->str, name, strlen(name) + 1);
+				ap->flag = true;
+				specific_scan_list = g_slist_append(specific_scan_list, ap);
+			} else
+				DBG("Failed to allocate memory");
+
+		} else if (g_str_equal(key, "Frequency_Mixed")) {
+			if (type != DBUS_TYPE_STRING) {
 				g_slist_free_full(specific_scan_list, g_free);
 				return __connman_error_invalid_arguments(msg);
 			}
 
-			scan_type = 2; /* Frequency based scan */
+			scan_type = CONNMAN_MULTI_SCAN_SSID_FREQ; /* SSID & Frequency mixed scan */
 			dbus_message_iter_get_basic(&value2, &freq);
-			DBG("freq %d", freq);
-			specific_scan_list = g_slist_append(specific_scan_list, GINT_TO_POINTER(freq));
+
+			connman_multi_scan_ap_s *ap = (connman_multi_scan_ap_s*)g_try_malloc0(sizeof(connman_multi_scan_ap_s));
+			if (ap) {
+				g_strlcpy(ap->str, freq, strlen(freq) + 1);
+				ap->flag = false;
+				specific_scan_list = g_slist_append(specific_scan_list, ap);
+			} else
+				DBG("Failed to allocate memory");
 		}
 		dbus_message_iter_next(&dict);
 	}
@@ -1356,7 +1390,8 @@ static DBusMessage *specific_scan(DBusConnection *conn, DBusMessage *msg, void *
 	technology->scan_pending =
 		g_slist_prepend(technology->scan_pending, msg);
 
-	if (scan_type == 1) {
+	if (scan_type == CONNMAN_MULTI_SCAN_SSID ||
+			scan_type == CONNMAN_MULTI_SCAN_SSID_FREQ) {
 		g_slist_free_full(specific_scan_list, g_free);
 		scan_type = 0;
 	}
-- 
2.34.1


From dce2054780e8142aebe5a7d11c4751040437f7ec Mon Sep 17 00:00:00 2001
From: Mayank Haarit <mayank.h@samsung.com>
Date: Wed, 18 Apr 2018 19:59:49 +0530
Subject: [PATCH 08/16] Added logic to get country code of APs

It also includes parsing country code from IEs received from the supplicant

Change-Id: Iea5f8b2ea7cc8fefe07591cc4d636d27b015d427
Signed-off-by: Mayank Haarit <mayank.h@samsung.com>
---
 gsupplicant/gsupplicant.h |  2 ++
 gsupplicant/supplicant.c  | 23 +++++++++++++++++++++++
 include/network.h         |  3 +++
 plugins/wifi.c            |  6 ++++++
 src/connman.h             |  3 +++
 src/network.c             | 24 ++++++++++++++++++++++++
 src/service.c             | 10 ++++++++++
 7 files changed, 71 insertions(+)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index ead619c4..0a28dbfb 100755
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -397,6 +397,8 @@ const char *g_supplicant_network_get_identity(GSupplicantNetwork *network);
 const char *g_supplicant_network_get_phase2(GSupplicantNetwork *network);
 unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network);
 void *g_supplicant_network_get_wifi_vsie(GSupplicantNetwork *network);
+const unsigned char *g_supplicant_network_get_countrycode(GSupplicantNetwork
+							  *network);
 #endif
 
 struct _GSupplicantCallbacks {
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 92efbc9c..fbfa6c7f 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -44,6 +44,10 @@
 #define IEEE80211_CAP_IBSS	0x0002
 #define IEEE80211_CAP_PRIVACY	0x0010
 
+#if defined TIZEN_EXT
+#define COUNTRY_CODE_LENGTH	2
+#endif
+
 #define BSS_UNKNOWN_STRENGTH    -90
 
 static DBusConnection *connection;
@@ -223,6 +227,7 @@ struct g_supplicant_bss {
 	dbus_bool_t ft_ieee8021x;
 	GSList *vsie_list;
 	dbus_bool_t hs20;
+	unsigned char country_code[COUNTRY_CODE_LENGTH];
 #endif
 	unsigned int wps_capabilities;
 };
@@ -250,6 +255,7 @@ struct _GSupplicantNetwork {
 	char *phase2;
 	unsigned int keymgmt;
 	GSList *vsie_list;
+	unsigned char country_code[COUNTRY_CODE_LENGTH];
 #endif
 };
 
@@ -1408,6 +1414,15 @@ unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network)
 
 	return network->keymgmt;
 }
+
+const unsigned char *g_supplicant_network_get_countrycode(GSupplicantNetwork
+							  *network)
+{
+	if (!network)
+		return NULL;
+
+	return network->country_code;
+}
 #endif
 
 const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
@@ -1876,6 +1891,7 @@ static int add_or_replace_bss_to_network(struct g_supplicant_bss *bss)
 	}
 
 	network->isHS20AP = bss->hs20;
+	memcpy(network->country_code, bss->country_code, COUNTRY_CODE_LENGTH);
 #endif
 
 	SUPPLICANT_DBG("New network %s created", network->name);
@@ -2079,6 +2095,7 @@ static void bss_process_ies(DBusMessageIter *iter, void *user_data)
 #define WPS_CONFIGURED    0x02
 #if defined TIZEN_EXT
 #define VENDOR_SPECIFIC_INFO 0xDD
+#define WLAN_EID_COUNTRY 7
 #endif
 
 	dbus_message_iter_recurse(iter, &array);
@@ -2089,6 +2106,7 @@ static void bss_process_ies(DBusMessageIter *iter, void *user_data)
 
 	bss->wps_capabilities = 0;
 	bss->keymgmt = 0;
+	memset(bss->country_code, 0, COUNTRY_CODE_LENGTH);
 
 	for (ie_end = ie + ie_len; ie < ie_end && ie + ie[1] + 1 <= ie_end;
 							ie += ie[1] + 2) {
@@ -2108,6 +2126,11 @@ static void bss_process_ies(DBusMessageIter *iter, void *user_data)
 				SUPPLICANT_DBG("Failed to allocate memory");
 			continue;
 		}
+
+		if(ie[0] == WLAN_EID_COUNTRY && ie[1] >= 2) {
+			memcpy(bss->country_code, ie+2, COUNTRY_CODE_LENGTH);
+			continue;
+		}
 #endif
 		if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN ||
 			memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0)
diff --git a/include/network.h b/include/network.h
index baf1c01d..63c4e44d 100755
--- a/include/network.h
+++ b/include/network.h
@@ -157,6 +157,9 @@ int connman_network_get_disconnect_reason(struct connman_network *network);
 int connman_network_get_assoc_status_code(struct connman_network *network);
 int connman_network_set_assoc_status_code(struct connman_network *network,
 				int assoc_status_code);
+int connman_network_set_countrycode(struct connman_network *network, const
+				    unsigned char *country_code);
+unsigned char *connman_network_get_countrycode(struct connman_network *network);
 #endif
 
 int connman_network_set_name(struct connman_network *network,
diff --git a/plugins/wifi.c b/plugins/wifi.c
index a9ffad05..91732bd0 100755
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -3417,6 +3417,7 @@ static void network_added(GSupplicantNetwork *supplicant_network)
 
 #if defined TIZEN_EXT
 	GSList *vsie_list = NULL;
+	const unsigned char *country_code;
 #endif
 
 	mode = g_supplicant_network_get_mode(supplicant_network);
@@ -3472,6 +3473,8 @@ static void network_added(GSupplicantNetwork *supplicant_network)
 		connman_network_set_vsie_list(network, vsie_list);
 	else
 		DBG("vsie_list is NULL");
+	country_code = g_supplicant_network_get_countrycode(supplicant_network);
+	connman_network_set_countrycode(network, country_code);
 #endif
 	connman_network_set_string(network, "WiFi.Security", security);
 	connman_network_set_strength(network,
@@ -3593,6 +3596,7 @@ static void network_changed(GSupplicantNetwork *network, const char *property)
 	unsigned int maxrate;
 	uint16_t frequency;
 	bool wps;
+	const unsigned char *country_code;
 #endif
 
 	interface = g_supplicant_network_get_interface(network);
@@ -3625,6 +3629,8 @@ static void network_changed(GSupplicantNetwork *network, const char *property)
 	connman_network_set_maxrate(connman_network, maxrate);
 	connman_network_set_frequency(connman_network, frequency);
 	connman_network_set_bool(connman_network, "WiFi.WPS", wps);
+	country_code = g_supplicant_network_get_countrycode(network);
+	connman_network_set_countrycode(connman_network, country_code);
 #endif
 }
 
diff --git a/src/connman.h b/src/connman.h
index a5977b88..d1069b93 100755
--- a/src/connman.h
+++ b/src/connman.h
@@ -24,6 +24,9 @@
 #include <glib.h>
 
 #define CONNMAN_API_SUBJECT_TO_CHANGE
+#if defined TIZEN_EXT
+#define WIFI_COUNTRY_CODE_LEN 2
+#endif
 
 #include <connman/dbus.h>
 
diff --git a/src/network.c b/src/network.c
index 0e3d4b34..eb2d0391 100755
--- a/src/network.c
+++ b/src/network.c
@@ -119,6 +119,7 @@ struct connman_network {
 		* Only for EAP-FAST
 		*/
 		char *phase1;
+		unsigned char country_code[WIFI_COUNTRY_CODE_LEN];
 #endif
 	} wifi;
 
@@ -2076,6 +2077,29 @@ int connman_network_get_assoc_status_code(struct connman_network *network)
 
 	return network->wifi.assoc_status_code;
 }
+
+int connman_network_set_countrycode(struct connman_network *network,
+				    const unsigned char *country_code)
+{
+	int i = 0;
+
+	if (country_code == NULL)
+		return -EINVAL;
+
+	DBG("network %p Country Code %02x:%02x",network,
+	    country_code[0],country_code[1]);
+
+	for (; i < WIFI_COUNTRY_CODE_LEN; i++)
+		network->wifi.country_code[i] = country_code[i];
+
+	return 0;
+}
+
+unsigned char *connman_network_get_countrycode(struct connman_network *network)
+{
+	return (unsigned char *)network->wifi.country_code;
+}
+
 #endif
 
 int connman_network_set_nameservers(struct connman_network *network,
diff --git a/src/service.c b/src/service.c
index c3bdc0e5..b533dcd0 100755
--- a/src/service.c
+++ b/src/service.c
@@ -3230,6 +3230,9 @@ static void append_wifi_ext_info(DBusMessageIter *dict,
 	const char *enc_mode;
 	const char *str;
 	gboolean passpoint;
+	char country_code_buff[WIFI_COUNTRY_CODE_LEN + 1] = {0,};
+	char *country_code_str = country_code_buff;
+	unsigned char *country_code;
 
 	ssid = connman_network_get_blob(network, "WiFi.SSID", &ssid_len);
 	bssid = connman_network_get_bssid(network);
@@ -3238,11 +3241,16 @@ static void append_wifi_ext_info(DBusMessageIter *dict,
 	enc_mode = connman_network_get_enc_mode(network);
 	passpoint = connman_network_get_bool(network, "WiFi.HS20AP");
 	keymgmt = connman_network_get_keymgmt(network);
+	country_code = connman_network_get_countrycode(network);
 
 	snprintf(bssid_str, WIFI_BSSID_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
 				bssid[0], bssid[1], bssid[2],
 				bssid[3], bssid[4], bssid[5]);
 
+	snprintf(country_code_str, (WIFI_COUNTRY_CODE_LEN + 1), "%c%c",
+		 country_code[0], country_code[1]);
+
+
 	connman_dbus_dict_append_fixed_array(dict, "SSID",
 					DBUS_TYPE_BYTE, &ssid, ssid_len);
 	connman_dbus_dict_append_basic(dict, "BSSID",
@@ -3257,6 +3265,8 @@ static void append_wifi_ext_info(DBusMessageIter *dict,
 					DBUS_TYPE_BOOLEAN, &passpoint);
 	connman_dbus_dict_append_basic(dict, "Keymgmt",
 					DBUS_TYPE_UINT32, &keymgmt);
+	connman_dbus_dict_append_basic(dict, "Country", DBUS_TYPE_STRING,
+				       &country_code_str);
 
 	str = connman_network_get_string(network, "WiFi.Security");
 	if (str != NULL && g_str_equal(str, "ieee8021x") == TRUE) {
-- 
2.34.1


From 6c73f51b34fa18a1a9b4582f0e1dfcaee8f2fa5e Mon Sep 17 00:00:00 2001
From: Mayank Haarit <mayank.h@samsung.com>
Date: Fri, 20 Apr 2018 20:57:32 +0530
Subject: [PATCH 09/16] Add BSSID , signal strength and frequency list of the
 APs

This patch sends the list of BSSID, signal strength and
frequency of an APs having same SSID and Security type.

Change-Id: I368d37de310687ca173418dfad91fae7082b2357
Signed-off-by: Mayank Haarit <mayank.h@samsung.com>
---
 gsupplicant/gsupplicant.h |  1 +
 gsupplicant/supplicant.c  | 48 +++++++++++++++++++++++++++++++++++++++
 include/network.h         | 11 +++++++++
 plugins/wifi.c            |  5 ++++
 src/network.c             | 14 ++++++++++++
 src/service.c             | 32 +++++++++++++++++++++++++-
 6 files changed, 110 insertions(+), 1 deletion(-)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 0a28dbfb..3dff2b46 100755
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -399,6 +399,7 @@ unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network);
 void *g_supplicant_network_get_wifi_vsie(GSupplicantNetwork *network);
 const unsigned char *g_supplicant_network_get_countrycode(GSupplicantNetwork
 							  *network);
+void *g_supplicant_network_get_bssid_list(GSupplicantNetwork *network);
 #endif
 
 struct _GSupplicantCallbacks {
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index fbfa6c7f..c154a0ea 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -321,6 +321,14 @@ struct interface_scan_data {
 	void *user_data;
 };
 
+#if defined TIZEN_EXT
+struct g_connman_bssids {
+	char bssid[18];
+	uint16_t strength;
+	uint16_t frequency;
+};
+#endif
+
 static int network_remove(struct interface_data *data);
 
 static inline void debug(const char *format, ...)
@@ -1595,6 +1603,46 @@ void *g_supplicant_network_get_wifi_vsie(GSupplicantNetwork *network)
 
 	return vsie_list;
 }
+
+static void update_bssid_list(gpointer key, gpointer value, gpointer user_data)
+{
+	struct g_supplicant_bss *bss = value;
+	struct g_connman_bssids *bssids = NULL;
+	char buff[18];
+	GSList **list = (GSList **)user_data;
+
+	bssids = (struct g_connman_bssids *)g_try_malloc0(sizeof(struct g_connman_bssids));
+
+	if (bssids) {
+		g_snprintf(buff, 18, "%02x:%02x:%02x:%02x:%02x:%02x",
+				bss->bssid[0], bss->bssid[1], bss->bssid[2], bss->bssid[3],
+				bss->bssid[4], bss->bssid[5]);
+
+		memcpy(bssids->bssid, buff, 18);
+		bssids->bssid[17] = '\0';
+		bssids->strength = bss->signal;
+		bssids->strength += 120;
+
+		if (bssids->strength > 100)
+			bssids->strength = 100;
+
+		bssids->frequency = bss->frequency;
+		*list = g_slist_append(*list, bssids);
+	} else
+		SUPPLICANT_DBG("Failed to allocate memory");
+}
+
+void *g_supplicant_network_get_bssid_list(GSupplicantNetwork *network)
+{
+	GSList *bssid_list = NULL;
+
+	if (g_hash_table_size(network->bss_table) < 1)
+		return NULL;
+
+	g_hash_table_foreach(network->bss_table, update_bssid_list, &bssid_list);
+
+	return bssid_list;
+}
 #endif
 
 static void merge_network(GSupplicantNetwork *network)
diff --git a/include/network.h b/include/network.h
index 63c4e44d..98fa7d7a 100755
--- a/include/network.h
+++ b/include/network.h
@@ -62,6 +62,14 @@ enum connman_network_error {
 
 };
 
+#if defined TIZEN_EXT
+struct connman_bssids {
+	char bssid[18];
+	uint16_t strength;
+	uint16_t frequency;
+};
+#endif
+
 #define CONNMAN_NETWORK_PRIORITY_LOW      -100
 #define CONNMAN_NETWORK_PRIORITY_DEFAULT     0
 #define CONNMAN_NETWORK_PRIORITY_HIGH      100
@@ -160,6 +168,9 @@ int connman_network_set_assoc_status_code(struct connman_network *network,
 int connman_network_set_countrycode(struct connman_network *network, const
 				    unsigned char *country_code);
 unsigned char *connman_network_get_countrycode(struct connman_network *network);
+int connman_network_set_bssid_list(struct connman_network *network,
+					GSList *bssids);
+void *connman_network_get_bssid_list(struct connman_network *network);
 #endif
 
 int connman_network_set_name(struct connman_network *network,
diff --git a/plugins/wifi.c b/plugins/wifi.c
index 91732bd0..aad3b2cc 100755
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -3509,6 +3509,8 @@ static void network_added(GSupplicantNetwork *supplicant_network)
 			g_supplicant_network_get_keymgmt(supplicant_network));
 	connman_network_set_bool(network, "WiFi.HS20AP",
 			g_supplicant_network_is_hs20AP(supplicant_network));
+	connman_network_set_bssid_list(network,
+			(GSList *)g_supplicant_network_get_bssid_list(supplicant_network));
 #endif
 	connman_network_set_available(network, true);
 	connman_network_set_string(network, "WiFi.Mode", mode);
@@ -3597,6 +3599,7 @@ static void network_changed(GSupplicantNetwork *network, const char *property)
 	uint16_t frequency;
 	bool wps;
 	const unsigned char *country_code;
+	GSList *bssid_list;
 #endif
 
 	interface = g_supplicant_network_get_interface(network);
@@ -3631,6 +3634,8 @@ static void network_changed(GSupplicantNetwork *network, const char *property)
 	connman_network_set_bool(connman_network, "WiFi.WPS", wps);
 	country_code = g_supplicant_network_get_countrycode(network);
 	connman_network_set_countrycode(connman_network, country_code);
+	bssid_list = (GSList *)g_supplicant_network_get_bssid_list(network);
+	connman_network_set_bssid_list(connman_network, bssid_list);
 #endif
 }
 
diff --git a/src/network.c b/src/network.c
index eb2d0391..c5b5c974 100755
--- a/src/network.c
+++ b/src/network.c
@@ -120,6 +120,7 @@ struct connman_network {
 		*/
 		char *phase1;
 		unsigned char country_code[WIFI_COUNTRY_CODE_LEN];
+		GSList *bssid_list;
 #endif
 	} wifi;
 
@@ -985,6 +986,7 @@ static void network_destruct(struct connman_network *network)
 	g_free(network->wifi.pin_wps);
 #if defined TIZEN_EXT
 	g_slist_free_full(network->wifi.vsie_list, g_free);
+	g_slist_free_full(network->wifi.bssid_list, g_free);
 #endif
 	g_free(network->path);
 	g_free(network->group);
@@ -2100,6 +2102,18 @@ unsigned char *connman_network_get_countrycode(struct connman_network *network)
 	return (unsigned char *)network->wifi.country_code;
 }
 
+int connman_network_set_bssid_list(struct connman_network *network,
+					GSList *bssids)
+{
+	network->wifi.bssid_list = bssids;
+
+	return 0;
+}
+
+void *connman_network_get_bssid_list(struct connman_network *network)
+{
+	return network->wifi.bssid_list;
+}
 #endif
 
 int connman_network_set_nameservers(struct connman_network *network,
diff --git a/src/service.c b/src/service.c
index b533dcd0..b0424618 100755
--- a/src/service.c
+++ b/src/service.c
@@ -3303,6 +3303,33 @@ static void append_wifi_ext_info(DBusMessageIter *dict,
 					DBUS_TYPE_STRING, &str);
 	}
 }
+
+static void append_bssid_info(DBusMessageIter *iter, void *user_data)
+{
+        GSList *bssid_list = NULL;
+	struct connman_network *network = user_data;
+        struct connman_bssids *bssids;
+        char bssid_buf[18] = {0,};
+        char *bssid_str = bssid_buf;
+
+        bssid_list = (GSList *)connman_network_get_bssid_list(network);
+        if(bssid_list) {
+                GSList *list;
+                for (list = bssid_list; list; list = list->next) {
+                        bssids = (struct connman_bssids *)list->data;
+                        memcpy(bssid_str, bssids->bssid, 18);
+
+			connman_dbus_dict_append_basic(iter, "BSSID",
+                                        DBUS_TYPE_STRING, &bssid_str);
+
+                        connman_dbus_dict_append_basic(iter, "Strength",
+                                        DBUS_TYPE_UINT16, &bssids->strength);
+
+                        connman_dbus_dict_append_basic(iter, "Frequency",
+                                        DBUS_TYPE_UINT16, &bssids->frequency);
+                }
+        }
+}
 #endif
 
 static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
@@ -3406,8 +3433,11 @@ static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
 		break;
 	case CONNMAN_SERVICE_TYPE_WIFI:
 #if defined TIZEN_EXT
-		if (service->network != NULL)
+		if (service->network != NULL) {
 			append_wifi_ext_info(dict, service->network);
+			connman_dbus_dict_append_dict(dict, "BSSID.List",
+					append_bssid_info, service->network);
+		}
 
 		connman_dbus_dict_append_dict(dict, "Ethernet",
 						append_ethernet, service);
-- 
2.34.1


From dee0b094d657dc9aa96d7f771fa2e0ee5de1942c Mon Sep 17 00:00:00 2001
From: Saurav Babu <saurav.babu@samsung.com>
Date: Fri, 18 May 2018 11:24:45 +0530
Subject: [PATCH 10/16] gsupplicant: Fixed crash issue when network exists in
 supplicant

In some cases interface->network_path exists but
interface->network_info.ssid is NULL which leads to crash with below
backtrace:
Program received signal SIGSEGV, Segmentation fault.
0xb6b0d184 in memcmp () from /lib/libc.so.6
(gdb) bt
 #0  0xb6b0d184 in memcmp () from /lib/libc.so.6
 #1  0xb6eb5530 in compare_network_parameters (ssid=0xb85aec20,
interface=0xb85a1710) at gsupplicant/supplicant.c:445
 #2  g_supplicant_interface_connect (interface=0xb85a1710,
ssid=0xb85aec20, callback=0xb6eab039 <connect_callback>,
user_data=0xb859cbb0) at gsupplicant/supplicant.c:5839
 #3  0xb6ecc000 in __connman_network_connect (network=0xb859cbb0) at
src/network.c:1711
 #4  0xb6edaabe in service_connect (service=0xb85a6558) at
src/service.c:8143
 #5  __connman_service_connect (service=service@entry=0xb85a6558,
reason=reason@entry=CONNMAN_SERVICE_CONNECT_REASON_USER) at
src/service.c:8203
 #6  0xb6edc148 in connect_service (conn=<optimized out>, msg=0xb85d3b80,
user_data=0xb85a6558) at src/service.c:5570
 #7  0xb6f1653e in process_message
(connection=connection@entry=0xb859b600,
message=message@entry=0xb85d3b80,
iface_user_data=iface_user_data@entry=0xb85a6558, method=<optimized
out>, method=<optimized out>) at gdbus/object.c:259
 #8  0xb6f167be in generic_message (connection=0xb859b600,
message=0xb85d3b80, user_data=<optimized out>) at gdbus/object.c:1071
 #9  0xb6d126b0 in ?? () from /lib/libdbus-1.so.3
 #10 0xb6d014a8 in dbus_connection_dispatch () from /lib/libdbus-1.so.3
 #11 0xb6f144f2 in message_dispatch (data=0xb859b600) at
gdbus/mainloop.c:76
 #12 0xb6d898e8 in g_main_dispatch (context=0xb8599808) at gmain.c:3234
 #13 g_main_context_dispatch (context=context@entry=0xb8599808) at
gmain.c:3887
 #14 0xb6d89c78 in g_main_context_iterate (context=0xb8599808,
block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at
gmain.c:3960
 #15 0xb6d89fd8 in g_main_loop_run (loop=0xb85999a8) at gmain.c:4156
 #16 0xb6e9f352 in main (argc=<optimized out>, argv=<optimized out>) at
src/main.c:851

Change-Id: I9ed4c69d31389bd7aa0c8ab250d92c45cdab7507
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
---
 gsupplicant/supplicant.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index c154a0ea..4a78cee2 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -437,6 +437,11 @@ static GSupplicantState string2state(const char *state)
 static bool compare_network_parameters(GSupplicantInterface *interface,
 				GSupplicantSSID *ssid)
 {
+#if defined TIZEN_EXT
+	if (!interface->network_info.ssid)
+		return FALSE;
+#endif
+
 	if (memcmp(interface->network_info.ssid, ssid->ssid, ssid->ssid_len))
 		return FALSE;
 
@@ -5905,6 +5910,15 @@ static void network_remove_result(const char *error,
 		connect_data->ssid = data->ssid;
 		connect_data->user_data = data->user_data;
 
+#if defined TIZEN_EXT
+		int ret;
+		if (data->ssid->passphrase && g_strcmp0(data->ssid->passphrase, "") != 0
+			&& !data->ssid->eap) {
+			ret = send_decryption_request(data->ssid->passphrase, connect_data);
+			if (ret < 0)
+				SUPPLICANT_DBG("Decryption request failed %d", ret);
+		} else
+#endif
 		supplicant_dbus_method_call(data->interface->path,
 			SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
 			interface_add_network_params,
-- 
2.34.1


From 5d9d3391d8d6f853b47c208499e8b760170120ae Mon Sep 17 00:00:00 2001
From: Saurav Babu <saurav.babu@samsung.com>
Date: Mon, 21 May 2018 15:16:26 +0530
Subject: [PATCH 11/16] Don't remove network when
 G_SUPPLICANT_STATE_DISCONNECTED is received

In case of WPS PBC connection without SSID, sometimes few attempts fail
and on subsequent retries connection is established successfully. If we
remove network when disconnection is received for the first time from
wpa_supplicant then future retries doesn't take place and WPS connection
without SSID always fails

Change-Id: I2a5754c5e4a442e3305befdea3a94a6c728ef817
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
---
 gsupplicant/gsupplicant.h |  3 ---
 gsupplicant/supplicant.c  | 23 -----------------------
 plugins/wifi.c            | 24 ------------------------
 3 files changed, 50 deletions(-)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 3dff2b46..b0984b8c 100755
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -310,9 +310,6 @@ int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
 					GSupplicantInterfaceCallback callback,
 							void *user_data);
 
-#if defined TIZEN_EXT
-int g_supplicant_interface_remove_network(GSupplicantInterface *interface);
-#endif
 int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
 							unsigned int ap_scan);
 
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 4a78cee2..a403c202 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -6509,29 +6509,6 @@ int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
 	return -EINPROGRESS;
 }
 
-#if defined TIZEN_EXT
-int g_supplicant_interface_remove_network(GSupplicantInterface *interface)
-{
-	struct interface_data *data;
-
-	SUPPLICANT_DBG("");
-
-	if (interface == NULL)
-		return -EINVAL;
-
-	if (system_available == FALSE)
-		return -EFAULT;
-
-	data = dbus_malloc0(sizeof(*data));
-	if (data == NULL)
-		return -ENOMEM;
-
-	data->interface = interface;
-
-	return network_remove(data);
-}
-#endif
-
 static const char *g_supplicant_rule0 = "type=signal,"
 					"path=" DBUS_PATH_DBUS ","
 					"sender=" DBUS_SERVICE_DBUS ","
diff --git a/plugins/wifi.c b/plugins/wifi.c
index aad3b2cc..c471accf 100755
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -3138,13 +3138,6 @@ static void interface_state(GSupplicantInterface *interface)
 		}
 
 #if defined TIZEN_EXT
-		int err;
-
-		err = g_supplicant_interface_remove_network(wifi->interface);
-		if (err < 0)
-			DBG("Failed to remove network(%d)", err);
-
-
 		/* Some of Wi-Fi networks are not comply Wi-Fi specification.
 		 * Retry association until its retry count is expired */
 		if (handle_wifi_assoc_retry(network, wifi) == true) {
@@ -3157,23 +3150,6 @@ static void interface_state(GSupplicantInterface *interface)
 			DBG("Set disconnect reason code(%d)", wifi->disconnect_code);
 			connman_network_set_disconnect_reason(network, wifi->disconnect_code);
 		}
-
-		/* To avoid unnecessary repeated association in wpa_supplicant,
-		 * "RemoveNetwork" should be made when Wi-Fi is disconnected */
-		if (wps != true && wifi->network && wifi->disconnecting == false) {
-			wifi->disconnecting = true;
-			err = g_supplicant_interface_disconnect(wifi->interface,
-							disconnect_callback, wifi->network);
-			if (err < 0)
-				wifi->disconnecting = false;
-
-		connman_network_set_connected(network, false);
-		connman_network_set_associating(network, false);
-
-		start_autoscan(device);
-
-		break;
-		}
 #endif
 
 		connman_network_set_connected(network, false);
-- 
2.34.1


From 3a843d0d6419f18bd972b0fb57541da194bd37c8 Mon Sep 17 00:00:00 2001
From: Saurav Babu <saurav.babu@samsung.com>
Date: Wed, 23 May 2018 17:20:59 +0530
Subject: [PATCH 12/16] gsupplicant: Fixed crash issue

Change-Id: I568ffb360881ed78ac3c119c458220829d582d56
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
---
 gsupplicant/supplicant.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index a403c202..23fa2366 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -1596,6 +1596,8 @@ void *g_supplicant_network_get_wifi_vsie(GSupplicantNetwork *network)
 		unsigned char *vsie = NULL;
 		for (list = network->vsie_list; list; list = list->next) {
 			unsigned char *ie = (unsigned char *)list->data;
+			if (ie == NULL)
+				continue;
 			vsie = (unsigned char *)g_try_malloc0(ie[1]+2);	// tag number size(1), tag length size(1)
 
 			if (vsie) {
@@ -2181,8 +2183,11 @@ static void bss_process_ies(DBusMessageIter *iter, void *user_data)
 		}
 
 		if(ie[0] == WLAN_EID_COUNTRY && ie[1] >= 2) {
-			memcpy(bss->country_code, ie+2, COUNTRY_CODE_LENGTH);
-			continue;
+			/* Add country code only if it is a valid alphabet */
+			if (ie[2] >= 65 && ie[2] <= 90 && ie[3] >= 65 && ie[3] <= 90) {
+				memcpy(bss->country_code, ie+2, COUNTRY_CODE_LENGTH);
+				continue;
+			}
 		}
 #endif
 		if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN ||
-- 
2.34.1


From 146f8947c8f8e7c16802d8a653ab0e01e09b4a01 Mon Sep 17 00:00:00 2001
From: Jaehyun Kim <jeik01.kim@samsung.com>
Date: Wed, 23 May 2018 21:47:34 +0900
Subject: [PATCH 13/16] gsupplicant: Fixed resource leak

Change-Id: I423a3e680e528a36f98db5bdc2f68db15e707015
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
---
 gsupplicant/supplicant.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 23fa2366..49d391fe 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -5920,8 +5920,12 @@ static void network_remove_result(const char *error,
 		if (data->ssid->passphrase && g_strcmp0(data->ssid->passphrase, "") != 0
 			&& !data->ssid->eap) {
 			ret = send_decryption_request(data->ssid->passphrase, connect_data);
-			if (ret < 0)
+			if (ret < 0) {
 				SUPPLICANT_DBG("Decryption request failed %d", ret);
+				g_free(connect_data->ssid);
+				g_free(connect_data->path);
+				dbus_free(connect_data);
+			}
 		} else
 #endif
 		supplicant_dbus_method_call(data->interface->path,
-- 
2.34.1


From ea06d6f89f3860358c26de964e935c51718489b4 Mon Sep 17 00:00:00 2001
From: Saurav Babu <saurav.babu@samsung.com>
Date: Thu, 24 May 2018 12:01:54 +0530
Subject: [PATCH 14/16] Fixed various memory leaks

Below are few of the valgrind outputs:
==2694== 7,484 (576 direct, 6,908 indirect) bytes in 72 blocks are definitely lost in loss record 196 of 197
==2694==    at 0x48458A4: malloc (vg_replace_malloc.c:299)
==2694==    by 0x48C11B3: g_malloc (gmem.c:94)
==2694==    by 0x48DA4A3: g_slice_alloc (gslice.c:1025)
==2694==    by 0x48DBA13: g_slist_append (gslist.c:213)
==2694==    by 0x12EF29: g_supplicant_network_get_wifi_vsie(supplicant.c:1605)
==2694==    by 0x127097: network_added (wifi.c:3447)
==2694==    by 0x12A41D: callback_network_added (supplicant.c:624)
==2694==    by 0x12A41D: add_or_replace_bss_to_network(supplicant.c:1967)
==2694==    by 0x12B9C9: interface_bss_added_with_keys(supplicant.c:2457)
==2694==    by 0x12B9C9: signal_bss_added (supplicant.c:3106)
==2694==    by 0x12AF1D: g_supplicant_filter (supplicant.c:4045)
==2694==    by 0x49904EB: dbus_connection_dispatch (in/usr/lib/libdbus-1.so.3.14.6)
==2694==    by 0x18E921: message_dispatch (mainloop.c:76)
==2694==    by 0x48BB8E7: g_main_dispatch (gmain.c:3234)
==2694==    by 0x48BB8E7: g_main_context_dispatch (gmain.c:3887)

==2694== 1,980 (304 direct, 1,676 indirect) bytes in 38 blocks are definitely lost in loss record 187 of 197
==2694==    at 0x48458A4: malloc (vg_replace_malloc.c:299)
==2694==    by 0x48C11B3: g_malloc (gmem.c:94)
==2694==    by 0x48DA4A3: g_slice_alloc (gslice.c:1025)
==2694==    by 0x48DBA13: g_slist_append (gslist.c:213)
==2694==    by 0x128D3F: update_bssid_list (supplicant.c:1637)
==2694==    by 0x48A989F: g_hash_table_foreach (ghash.c:1610)
==2694==    by 0x12EF91: g_supplicant_network_get_bssid_list(supplicant.c:1649)
==2694==    by 0x127177: network_added (wifi.c:3489)
==2694==    by 0x1294D5: callback_network_added (supplicant.c:624)
==2694==    by 0x1294D5: scan_network_update (supplicant.c:2810)
==2694==    by 0x130151: supplicant_dbus_array_foreach (dbus.c:106)
==2694==    by 0x1298E3: scan_bss_data (supplicant.c:2824)
==2694==    by 0x130071: property_get_reply (dbus.c:273)

==2694== 28 bytes in 2 blocks are definitely lost in loss record 87 of 197
==2694==    at 0x48458A4: malloc (vg_replace_malloc.c:299)
==2694==    by 0x48C11B3: g_malloc (gmem.c:94)
==2694==    by 0x48DBF03: g_strdup (gstrfuncs.c:363)
==2694==    by 0x12A65B: merge_network (supplicant.c:1737)
==2694==    by 0x12A7D9: network_property (supplicant.c:1758)
==2694==    by 0x12A7D9: interface_network_added (supplicant.c:1808)
==2694==    by 0x12AF1D: g_supplicant_filter (supplicant.c:4045)
==2694==    by 0x49904EB: dbus_connection_dispatch (in /usr/lib/libdbus-1.so.3.14.6)
==2694==    by 0x18E921: message_dispatch (mainloop.c:76)
==2694==    by 0x48BB8E7: g_main_dispatch (gmain.c:3234)
==2694==    by 0x48BB8E7: g_main_context_dispatch (gmain.c:3887)
==2694==    by 0x48BBC77: g_main_context_iterate.isra.30 (gmain.c:3960)
==2694==    by 0x48BBFD7: g_main_loop_run (gmain.c:4156)
==2694==    by 0x119391: main (main.c:851)

Change-Id: I3d86724c44b1593e5444a65eb7519bc150e50ee5
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
---
 gsupplicant/supplicant.c | 10 +++++-----
 src/network.c            |  2 ++
 src/service.c            | 10 ++++++++--
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 49d391fe..5fedf023 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -1657,7 +1657,6 @@ static void merge_network(GSupplicantNetwork *network)
 	GString *str;
 	const char *ssid, *mode, *key_mgmt;
 #if defined TIZEN_EXT
-	GSupplicantInterface *interface;
 	const char *isHS20AP;
 	const char *eap, *identity, *phase2;
 #endif
@@ -1672,7 +1671,6 @@ static void merge_network(GSupplicantNetwork *network)
 	eap = g_hash_table_lookup(network->config_table, "eap");
 	identity = g_hash_table_lookup(network->config_table, "identity");
 	phase2 = g_hash_table_lookup(network->config_table, "phase2");
-	interface = network->interface;
 #endif
 
 	SUPPLICANT_DBG("ssid %s mode %s", ssid, mode);
@@ -1731,11 +1729,9 @@ static void merge_network(GSupplicantNetwork *network)
 	} else
 		network->isHS20AP = 0;
 
-	if (interface)
-		interface->network_path = g_strdup(network->path);
-
 	network->group = g_strdup(group);
 	callback_network_merged(network);
+	g_free(network->group);
 #endif
 
 	g_free(group);
@@ -4918,6 +4914,10 @@ static void interface_add_network_result(const char *error,
 
 	SUPPLICANT_DBG("PATH: %s", path);
 
+#if defined TIZEN_EXT
+	if (interface->network_path)
+		g_free(interface->network_path);
+#endif
 	interface->network_path = g_strdup(path);
 
 	store_network_information(interface, data->ssid);
diff --git a/src/network.c b/src/network.c
index c5b5c974..e189955c 100755
--- a/src/network.c
+++ b/src/network.c
@@ -2105,6 +2105,7 @@ unsigned char *connman_network_get_countrycode(struct connman_network *network)
 int connman_network_set_bssid_list(struct connman_network *network,
 					GSList *bssids)
 {
+	g_slist_free_full(network->wifi.bssid_list, g_free);
 	network->wifi.bssid_list = bssids;
 
 	return 0;
@@ -2439,6 +2440,7 @@ bool connman_network_get_bool(struct connman_network *network,
  */
 void connman_network_set_vsie_list(struct connman_network *network, GSList *vsie_list)
 {
+	g_slist_free_full(network->wifi.vsie_list, g_free);
 	network->wifi.vsie_list = vsie_list;
 }
 
diff --git a/src/service.c b/src/service.c
index b0424618..cf8ccaac 100755
--- a/src/service.c
+++ b/src/service.c
@@ -786,11 +786,17 @@ static int service_load(struct connman_service *service)
 
 	dns_method = g_key_file_get_string(keyfile, service->identifier,
 			"Nameservers.IPv4method", NULL);
-	service->dns_config_method_ipv4 = __connman_dnsconfig_string2method(dns_method);
+	if (dns_method) {
+		service->dns_config_method_ipv4 = __connman_dnsconfig_string2method(dns_method);
+		g_free(dns_method);
+	}
 
 	dns_method = g_key_file_get_string(keyfile, service->identifier,
 			"Nameservers.IPv6method", NULL);
-	service->dns_config_method_ipv6 = __connman_dnsconfig_string2method(dns_method);
+	if (dns_method) {
+		service->dns_config_method_ipv6 = __connman_dnsconfig_string2method(dns_method);
+		g_free(dns_method);
+	}
 #endif
 
 	service->timeservers_config = g_key_file_get_string_list(keyfile,
-- 
2.34.1


From 522b6f5340a56e3431cb5aa82fef864aa45a7a32 Mon Sep 17 00:00:00 2001
From: Saurav Babu <saurav.babu@samsung.com>
Date: Wed, 30 May 2018 12:36:40 +0530
Subject: [PATCH 15/16] gsupplicant: Fixed invalid read issue

==1071== Invalid read of size 4
==1071==    at 0x48DBB00: g_slist_length (gslist.c:856)
==1071==    by 0x12A3C7: add_or_replace_bss_to_network (supplicant.c:1930)
==1071==    by 0x12BB4D: signal_bss_changed (supplicant.c:3194)
==1071==    by 0x12AFD1: g_supplicant_filter (supplicant.c:4038)
==1071==    by 0x4998A17: dbus_connection_dispatch (dbus-connection.c:4808)
==1071==    by 0x18E931: message_dispatch (mainloop.c:76)
==1071==    by 0x48BB8E7: g_main_dispatch (gmain.c:3234)
==1071==    by 0x48BB8E7: g_main_context_dispatch (gmain.c:3887)
==1071==    by 0x48BBC77: g_main_context_iterate.isra.30 (gmain.c:3960)
==1071==    by 0x48BBFD7: g_main_loop_run (gmain.c:4156)
==1071==    by 0x119389: main (main.c:851)
==1071==  Address 0x4e800a4 is 4 bytes inside a block of size 8 free'd
==1071==    at 0x4846EC8: free (vg_replace_malloc.c:530)
==1071==    by 0x48DB10F: g_slice_free_chain_with_offset (gslice.c:1232)
==1071==    by 0x12A03F: remove_bss (supplicant.c:841)
==1071==    by 0x48A858F: g_hash_table_remove_all_nodes.part.0 (ghash.c:548)
==1071==    by 0x48A95B7: g_hash_table_remove_all_nodes (ghash.c:1428)
==1071==    by 0x48A95B7: g_hash_table_remove_all (ghash.c:1431)
==1071==    by 0x48A964B: g_hash_table_destroy (ghash.c:1124)
==1071==    by 0x12A8E5: remove_network (supplicant.c:814)
==1071==    by 0x48A8A3F: g_hash_table_remove_internal (ghash.c:1360)
==1071==    by 0x12BB47: signal_bss_changed (supplicant.c:3192)
==1071==    by 0x12AFD1: g_supplicant_filter (supplicant.c:4038)
==1071==    by 0x4998A17: dbus_connection_dispatch (dbus-connection.c:4808)
==1071==    by 0x18E931: message_dispatch (mainloop.c:76)
==1071==  Block was alloc'd at
==1071==    at 0x48458A4: malloc (vg_replace_malloc.c:299)
==1071==    by 0x48C11B3: g_malloc (gmem.c:94)
==1071==    by 0x48DA4A3: g_slice_alloc (gslice.c:1025)
==1071==    by 0x48DB4AF: g_slist_prepend (gslist.c:254)
==1071==    by 0x12C7D7: bss_process_ies (supplicant.c:2176)
==1071==    by 0x12C7D7: bss_property (supplicant.c:2388)
==1071==    by 0x1301FF: supplicant_dbus_property_foreach (dbus.c:145)
==1071==    by 0x1302A1: property_get_all_reply (dbus.c:184)
==1071==    by 0x498FABB: complete_pending_call_and_unlock (dbus-connection.c:2340)
==1071==    by 0x49981BF: dbus_connection_dispatch (dbus-connection.c:4757)
==1071==    by 0x18E931: message_dispatch (mainloop.c:76)
==1071==    by 0x48BB8E7: g_main_dispatch (gmain.c:3234)
==1071==    by 0x48BB8E7: g_main_context_dispatch (gmain.c:3887)
==1071==    by 0x48BBC77: g_main_context_iterate.isra.30 (gmain.c:3960)

==1679== Invalid read of size 4
==1679==    at 0x484D358: memmove (vg_replace_strmem.c:1258)
==1679==    by 0x49D8307: memmove (string3.h:59)
==1679==    by 0x49D8307: copy.isra.3 (dbus-string.c:1219)
==1679==    by 0x49D209F: marshal_1_octets_array (dbus-marshal-basic.c:868)
==1679==    by 0x49D209F: _dbus_marshal_write_fixed_multi (dbus-marshal-basic.c:1041)
==1679==    by 0x49A4A3B: _dbus_type_writer_write_fixed_multi (dbus-marshal-recursive.c:2681)
==1679==    by 0x13088D: supplicant_dbus_property_append_fixed_array (dbus.c:611)
==1679==    by 0x12E775: supplicant_dbus_dict_append_fixed_array (dbus.h:121)
==1679==    by 0x12E775: interface_add_network_params (supplicant.c:5518)
==1679==    by 0x1306FB: supplicant_dbus_method_call (dbus.c:515)
==1679==    by 0x12AF05: decryption_request_reply (supplicant.c:5713)
==1679==    by 0x498FABB: complete_pending_call_and_unlock (dbus-connection.c:2340)
==1679==    by 0x49981BF: dbus_connection_dispatch (dbus-connection.c:4757)
==1679==    by 0x18E931: message_dispatch (mainloop.c:76)
==1679==    by 0x48BB8E7: g_main_dispatch (gmain.c:3234)
==1679==    by 0x48BB8E7: g_main_context_dispatch (gmain.c:3887)

Change-Id: I53652b06891fa8465e9dd425f425210ebc67ee9f
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
---
 gsupplicant/gsupplicant.h |  4 ++++
 gsupplicant/supplicant.c  | 12 ++++++++++++
 plugins/wifi.c            | 17 +++++++++++++++++
 3 files changed, 33 insertions(+)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index b0984b8c..648ee572 100755
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -154,7 +154,11 @@ enum GSupplicantAPHiddenSSID {
 };
 
 struct _GSupplicantSSID {
+#if defined TIZEN_EXT
+	void *ssid;
+#else
 	const void *ssid;
+#endif
 	unsigned int ssid_len;
 	unsigned int scan_ssid;
 	GSupplicantMode mode;
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 5fedf023..c5c83f33 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -3187,6 +3187,9 @@ static void signal_bss_changed(const char *path, DBusMessageIter *iter)
 
 		memcpy(new_bss, bss, sizeof(struct g_supplicant_bss));
 		new_bss->path = g_strdup(bss->path);
+#if defined TIZEN_EXT
+		new_bss->vsie_list = NULL;
+#endif
 
 		g_hash_table_remove(interface->network_table, network->group);
 
@@ -4876,6 +4879,9 @@ static void interface_select_network_result(const char *error,
 	if (data->callback)
 		data->callback(err, data->interface, data->user_data);
 
+#if defined TIZEN_EXT
+	g_free(data->ssid->ssid);
+#endif
 	g_free(data->ssid);
 	dbus_free(data);
 }
@@ -4961,6 +4967,9 @@ error:
 	}
 
 	g_free(data->path);
+#if defined TIZEN_EXT
+	g_free(data->ssid->ssid);
+#endif
 	g_free(data->ssid);
 	g_free(data);
 }
@@ -5716,6 +5725,9 @@ done:
 		SUPPLICANT_DBG("AddNetwork failed %d", ret);
 		callback_assoc_failed(decrypt_request_data.data->user_data);
 		g_free(data->path);
+#if defined TIZEN_EXT
+		g_free(data->ssid->ssid);
+#endif
 		g_free(data->ssid);
 		dbus_free(data);
 	}
diff --git a/plugins/wifi.c b/plugins/wifi.c
index c471accf..6103dc8c 100755
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -2509,11 +2509,21 @@ static GSupplicantEapKeymgmt network_eap_keymgmt(const char *security)
 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
 {
 	const char *security;
+#if defined TIZEN_EXT
+	const void *ssid_data;
+#endif
 
 	memset(ssid, 0, sizeof(*ssid));
 	ssid->mode = G_SUPPLICANT_MODE_INFRA;
+#if defined TIZEN_EXT
+	ssid_data = connman_network_get_blob(network, "WiFi.SSID",
+						&ssid->ssid_len);
+	ssid->ssid = g_try_malloc0(ssid->ssid_len);
+	memcpy(ssid->ssid, ssid_data, ssid->ssid_len);
+#else
 	ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
 						&ssid->ssid_len);
+#endif
 	ssid->scan_ssid = 1;
 	security = connman_network_get_string(network, "WiFi.Security");
 	ssid->security = network_security(security);
@@ -2614,6 +2624,9 @@ static int network_connect(struct connman_network *network)
 
 	if (wifi->disconnecting) {
 		wifi->pending_network = network;
+#if defined TIZEN_EXT
+		g_free(ssid->ssid);
+#endif
 		g_free(ssid);
 	} else {
 		wifi->network = connman_network_ref(network);
@@ -4038,7 +4051,11 @@ static GSupplicantSSID *ssid_ap_init(const char *ssid,
 		return NULL;
 
 	ap->mode = G_SUPPLICANT_MODE_MASTER;
+#if defined TIZEN_EXT
+	ap->ssid = (void *) ssid;
+#else
 	ap->ssid = ssid;
+#endif
 	ap->ssid_len = strlen(ssid);
 	ap->scan_ssid = 0;
 	ap->freq = 2412;
-- 
2.34.1


From 1ccc890efb354343041512b2e25d673c1d00e235 Mon Sep 17 00:00:00 2001
From: Saurav Babu <saurav.babu@samsung.com>
Date: Tue, 5 Jun 2018 12:57:31 +0530
Subject: [PATCH 16/16] telephony: Fixed memory leak

Valgrind reported memory leak with below backtrace
==3471== 1,934 (80 direct, 1,854 indirect) bytes in 2 blocks are
definitely lost in loss record 190 of 194
==3471==    at 0x484801C: calloc (vg_replace_malloc.c:711)
==3471==    by 0x49D687B: dbus_malloc0 (dbus-memory.c:572)
==3471==    by 0x49BB9A3: _dbus_pending_call_new_unlocked (dbus-pending-call.c:124)
==3471==    by 0x4995963: dbus_connection_send_with_reply (dbus-connection.c:3449)
==3471==    by 0x135D8D: __dbus_request.constprop.8 (telephony.c:396)
==3471==    by 0x135E6D: __request_get_services (telephony.c:477)
==3471==    by 0x136F19: __add_modem (telephony.c:802)
==3471==    by 0x13732F: __response_get_modems (telephony.c:464)
==3471==    by 0x498FABB: complete_pending_call_and_unlock (dbus-connection.c:2340)
==3471==    by 0x49981BF: dbus_connection_dispatch (dbus-connection.c:4757)
==3471==    by 0x18E815: message_dispatch (mainloop.c:72)
==3471==    by 0x48BB8E7: g_main_dispatch (gmain.c:3234)
==3471==    by 0x48BB8E7: g_main_context_dispatch (gmain.c:3887

When dbus response is received then we should unref memory allocated by
libdbus

Change-Id: I81c514506f0df42e537d63382b2eb2ebc51c58c8
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
---
 plugins/telephony.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/plugins/telephony.c b/plugins/telephony.c
index 2b4c5a4a..2954c183 100755
--- a/plugins/telephony.c
+++ b/plugins/telephony.c
@@ -390,8 +390,10 @@ static int __dbus_request(const char *path, const char *interface,
 	ok = dbus_message_append_args_valist(message, type, va);
 	va_end(va);
 
-	if (!ok)
+	if (!ok) {
+		dbus_message_unref(message);
 		return -ENOMEM;
+	}
 
 	if (dbus_connection_send_with_reply(connection, message,
 						&call, TIMEOUT) == FALSE) {
@@ -489,10 +491,6 @@ static void __response_get_services(DBusPendingCall *call, void *user_data)
 	struct telephony_modem *modem;
 
 	modem = g_hash_table_lookup(modem_hash, path);
-	if (modem == NULL)
-		return;
-	if (modem->device == NULL)
-		return;
 
 	DBG("");
 
@@ -506,6 +504,9 @@ static void __response_get_services(DBusPendingCall *call, void *user_data)
 		goto done;
 	}
 
+	if (modem == NULL || modem->device == NULL)
+		goto done;
+
 	DBG("message signature (%s)", dbus_message_get_signature(reply));
 
 	if (dbus_message_iter_init(reply, &args) == FALSE)
-- 
2.34.1