[Feature] add connman patch to support sta+ap for wifi

Change-Id: I993122fc4443c6073aa8d0b7726c5e4b4f2eeb8f
diff --git a/meta/meta-mediatek-mt2735/recipes-connectivity/connman/connman/lynq_wifi_ap_sta.patch b/meta/meta-mediatek-mt2735/recipes-connectivity/connman/connman/lynq_wifi_ap_sta.patch
new file mode 100755
index 0000000..855cbf1
--- /dev/null
+++ b/meta/meta-mediatek-mt2735/recipes-connectivity/connman/connman/lynq_wifi_ap_sta.patch
@@ -0,0 +1,176 @@
+--- connman-1.35/plugins/wifi.c	2022-04-30 14:31:30.777805400 +0800
++++ connman-1.35/plugins/wifi_new.c	2022-05-12 17:54:35.727120400 +0800
+@@ -153,6 +153,7 @@
+ 	int servicing;
+ 	int disconnect_code;
+ 	int assoc_code;
++	bool interface_create_flag;
+ };
+ 
+ static GList *iface_list = NULL;
+@@ -784,6 +785,7 @@
+ 	else
+ 		iface_list = g_list_append(iface_list, wifi);
+ 
++	DBG("cy- device %p, wifi %p, %p", device, wifi, wifi->interface);
+ 	return 0;
+ }
+ 
+@@ -1471,13 +1473,13 @@
+ {
+ 	struct wifi_data *wifi = user_data;
+ 
+-	DBG("result %d ifname %s, wifi %p", result,
++	DBG("cy-result %d ifname %s, wifi %p, %s", result,
+ 				g_supplicant_interface_get_ifname(interface),
+-				wifi);
++				wifi, wifi->interface_create_flag ? "create" : "not create");
+ 
+-	if (result < 0 || !wifi)
++	if (result < 0 || !wifi || !wifi->interface_create_flag)
+ 		return;
+-
++	wifi->interface_create_flag = false;
+ 	wifi->interface = interface;
+ 	g_supplicant_interface_set_data(interface, wifi);
+ 
+@@ -1495,7 +1497,8 @@
+ 	const char *driver = connman_option_get_string("wifi");
+ 	int ret;
+ 
+-	DBG("device %p %p", device, wifi);
++	DBG("cy-device %p %p %p", device, wifi, wifi->interface);
++	wifi->interface_create_flag = false;
+ 
+ 	index = connman_device_get_index(device);
+ 	if (!wifi || index < 0)
+@@ -1505,6 +1508,13 @@
+ 		return -EINPROGRESS;
+ 
+ 	interface = connman_inet_ifname(index);
++	DBG("cy-interface name %s", interface);
++	if (strstr(interface, "ap") != NULL) {
++		wifi->interface_ready = true;
++		finalize_interface_creation(wifi);
++		return 0;
++	}
++	wifi->interface_create_flag = true;
+ 	ret = g_supplicant_interface_create(interface, driver, NULL,
+ 						interface_create_callback,
+ 							wifi);
+@@ -3103,21 +3113,21 @@
+ 		return NULL;
+ 
+ 	ap->mode = G_SUPPLICANT_MODE_MASTER;
+-	ap->ssid = ssid;
+-	ap->ssid_len = strlen(ssid);
+-	ap->scan_ssid = 0;
+-	ap->freq = 2412;
+-
+-	if (!passphrase || strlen(passphrase) == 0) {
+-		ap->security = G_SUPPLICANT_SECURITY_NONE;
+-		ap->passphrase = NULL;
+-	} else {
+-	       ap->security = G_SUPPLICANT_SECURITY_PSK;
+-	       ap->protocol = G_SUPPLICANT_PROTO_RSN;
+-	       ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
+-	       ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
+-	       ap->passphrase = passphrase;
+-	}
++	// ap->ssid = ssid;
++	// ap->ssid_len = strlen(ssid);
++	// ap->scan_ssid = 0;
++	// ap->freq = 2412;
++
++	// if (!passphrase || strlen(passphrase) == 0) {
++	// 	ap->security = G_SUPPLICANT_SECURITY_NONE;
++	// 	ap->passphrase = NULL;
++	// } else {
++	//        ap->security = G_SUPPLICANT_SECURITY_PSK;
++	//        ap->protocol = G_SUPPLICANT_PROTO_RSN;
++	//        ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
++	//        ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
++	//        ap->passphrase = passphrase;
++	// }
+ 
+ 	return ap;
+ }
+@@ -3179,8 +3189,8 @@
+ 	if (g_supplicant_interface_set_apscan(interface, 2) < 0)
+ 		connman_error("Failed to set interface ap_scan property");
+ 
+-	g_supplicant_interface_connect(interface, info->ssid,
+-						ap_start_callback, info);
++	// g_supplicant_interface_connect(interface, info->ssid,
++	// 					ap_start_callback, info);
+ }
+ 
+ static void sta_remove_callback(int result,
+@@ -3235,13 +3245,23 @@
+ 
+ 		interface = wifi->interface;
+ 
+-		if (!interface)
+-			continue;
++		if (!interface) {
++			DBG("cy- interface is null");
++			// continue;
++			ifname = g_strdup("ap0");
++		}
++		else {
+ 
+ 		ifname = g_supplicant_interface_get_ifname(wifi->interface);
+-		if (!ifname)
++		if (!ifname) {
++			DBG("cy- ifname is null");
+ 			continue;
++		}
+ 
++		DBG("cy-ifname is %s", ifname);
++ 		if (strstr(ifname, "ap") == NULL) {
++ 			continue;
++ 		}
+ 		if (wifi->ap_supported == WIFI_AP_NOT_SUPPORTED) {
+ 			DBG("%s does not support AP mode (detected)", ifname);
+ 			continue;
+@@ -3256,6 +3276,7 @@
+ 
+ 		if (wifi->network && available)
+ 			continue;
++		}
+ 
+ 		info = g_try_malloc0(sizeof(struct wifi_tethering_info));
+ 		if (!info)
+@@ -3288,9 +3309,11 @@
+ 		if (berr < 0)
+ 			goto failed;
+ 
+-		err = g_supplicant_interface_remove(interface,
+-						sta_remove_callback,
+-							info);
++		// err = g_supplicant_interface_remove(interface,
++		// 				sta_remove_callback,
++		// 					info);
++		sta_remove_callback(0, NULL, info);
++		err = 0;
+ 		if (err >= 0) {
+ 			DBG("tethering wifi %p ifname %s", wifi, ifname);
+ 			return 0;
+--- connman-1.35/gsupplicant/supplicant.c	2017-08-11 02:56:43.000000000 +0800
++++ connman-1.35/gsupplicant/supplicant_new.c	2022-05-12 15:36:33.433705200 +0800
+@@ -3869,6 +3869,15 @@
+ 					DBUS_TYPE_STRING, &data->bridge);
+ 
+ 	config_file = g_hash_table_lookup(config_file_table, data->ifname);
++	if (config_file == NULL) {
++		if (strstr(data->ifname, "ap") != NULL) {
++			config_file = "/data/wifi/wg870/wpa_supplicant_ap.conf";
++		}
++		else {
++			config_file = "/data/wifi/wg870/wpa_supplicant.conf";
++		}
++	}
++	
+ 	if (config_file) {
+ 		SUPPLICANT_DBG("[%s] ConfigFile %s", data->ifname, config_file);
+ 
diff --git a/meta/meta-mediatek-mt2735/recipes-connectivity/connman/connman_%.bbappend b/meta/meta-mediatek-mt2735/recipes-connectivity/connman/connman_%.bbappend
new file mode 100755
index 0000000..76c88a5
--- /dev/null
+++ b/meta/meta-mediatek-mt2735/recipes-connectivity/connman/connman_%.bbappend
@@ -0,0 +1,6 @@
+FILESEXTRAPATHS_append := ":${THISDIR}/${PN}"
+
+SRC_URI += "\
+            file://lynq_wifi_ap_sta.patch \
+            "
+