[][MAC80211[WiFi6][hostapd][Fix wds AP interface adding issue]

[Description]
Fix wds AP interface adding issue.

This patch is from wifi7.
(https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/7743343)

[Release-log]
N/A

Change-Id: If2573114d016d8db73cecddf90931fabb6aa20a7
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/8348525
diff --git a/autobuild_mac80211_release/package/network/services/hostapd/patches/mtk-0047-hostapd-mtk-Check-the-bridge-after-ioctl-SIOCBRADDIF_new.patch b/autobuild_mac80211_release/package/network/services/hostapd/patches/mtk-0047-hostapd-mtk-Check-the-bridge-after-ioctl-SIOCBRADDIF_new.patch
new file mode 100644
index 0000000..1937640
--- /dev/null
+++ b/autobuild_mac80211_release/package/network/services/hostapd/patches/mtk-0047-hostapd-mtk-Check-the-bridge-after-ioctl-SIOCBRADDIF_new.patch
@@ -0,0 +1,55 @@
+From 99159b174eb245a7162fe38900971cdff017cf75 Mon Sep 17 00:00:00 2001
+From: Michael Lee <michael-cy.lee@mediatek.com>
+Date: Thu, 13 Jul 2023 13:14:26 +0800
+Subject: [PATCH] hostapd: mtk: Check the bridge after ioctl SIOCBRADDIF failed
+
+If ioctl returns EBUSY on command SIOCBRADDIF, the interface might
+already be bridged by others, and linux_br_add_if should not indicate an
+error in the case.
+
+This patch checks whether the interface is correctly brigded when ioctl
+returns EBUSY.
+
+Signed-off-by: Michael Lee <michael-cy.lee@mediatek.com>
+---
+ src/drivers/linux_ioctl.c | 16 ++++++++++++++--
+ 1 file changed, 14 insertions(+), 2 deletions(-)
+
+diff --git a/src/drivers/linux_ioctl.c b/src/drivers/linux_ioctl.c
+index 7edb9df..b8c1af2 100644
+--- a/src/drivers/linux_ioctl.c
++++ b/src/drivers/linux_ioctl.c
+@@ -150,7 +150,8 @@ int linux_br_del(int sock, const char *brname)
+ int linux_br_add_if(int sock, const char *brname, const char *ifname)
+ {
+ 	struct ifreq ifr;
+-	int ifindex;
++	int ifindex, ret;
++	char in_br[IFNAMSIZ];
+ 
+ 	ifindex = if_nametoindex(ifname);
+ 	if (ifindex == 0)
+@@ -164,8 +165,19 @@ int linux_br_add_if(int sock, const char *brname, const char *ifname)
+ 
+ 		wpa_printf(MSG_DEBUG, "Could not add interface %s into bridge "
+ 			   "%s: %s", ifname, brname, strerror(errno));
++
++		/* If ioctl returns -EBUSY when adding interface into bridge,
++		 * the interface might already be added by netifd, so here we
++		 * check whether the interface is currently on the right
++		 * bridge. */
++		if(errno == EBUSY && linux_br_get(in_br, ifname) == 0 &&
++	           os_strcmp(in_br, brname) == 0)
++			ret = 0;
++		else
++			ret = -1;
++
+ 		errno = saved_errno;
+-		return -1;
++		return ret;
+ 	}
+ 
+ 	return 0;
+-- 
+2.25.1
+