[BugFix][API-1651]add check dnsmasq status active & retry

Affected branch:MR3.0-xx && GSW3.0

Affected module:wifi

Is it addected on both ZXIC and MTK: only MTK

Self-test: YES

Doc Update: No

Change-Id: I97eab60734ff3a87313c9d90edb5bc3da5c28a95
diff --git a/IC_src/mtk/lib/liblynq-wifi6/libwifi6.c b/IC_src/mtk/lib/liblynq-wifi6/libwifi6.c
index 5323831..5b48a80 100755
--- a/IC_src/mtk/lib/liblynq-wifi6/libwifi6.c
+++ b/IC_src/mtk/lib/liblynq-wifi6/libwifi6.c
@@ -90,6 +90,7 @@
 const char * start_stop_sta_script = "/etc/wg870/scripts/start_stop_sta.sh";
 const char * start_stop_ap_script = "/etc/wg870/scripts/start_stop_ap.sh";
 const char * sta_status_change_script = "/etc/wg870/scripts/sta_status_change.sh";
+const char * check_dnsmasq_dhcp_status = "/etc/wg870/scripts/check_dnsmasq_dhcp_status.sh";
 
 static char s_ap_iterface_name[64] = {0};
 
@@ -523,6 +524,10 @@
     return 1;
 }
 
+static void check_dnsmasq_dhcp(void)
+{
+    system_call_v("%s", check_dnsmasq_dhcp_status);
+}
 static inline void inner_notify_ap_msg(lynq_wifi_ap_status_s status)
 {
     pthread_mutex_lock(&s_ap_callback_mutex);
@@ -586,6 +591,7 @@
             else if (strstr(msg_notify, "AP-STA-CONNECTED") != NULL)
             {
                 inner_notify_ap_msg(LYNQ_WIFI_STATUS_CONNECT);
+                check_dnsmasq_dhcp();
                 if (g_gbw_enabled == 1 && g_gbw_mac != NULL)
                 {
                     RLOGD("conect %d, %s ,%s\n", g_gbw_enabled, g_gbw_mac, strstr(msg_notify, (const char*)g_gbw_mac));
diff --git a/IC_src/mtk/lib/liblynq-wifi6/scripts/check_dnsmasq_dhcp_status.sh b/IC_src/mtk/lib/liblynq-wifi6/scripts/check_dnsmasq_dhcp_status.sh
new file mode 100755
index 0000000..3a63fe9
--- /dev/null
+++ b/IC_src/mtk/lib/liblynq-wifi6/scripts/check_dnsmasq_dhcp_status.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+conf_file="/run/wg870/dnsmasq.conf"
+
+ps -eo "%p %a" | grep "/usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid" | grep -v grep
+
+if [ $? != 0 ]; then
+    /usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid -7 /run/wg870/dnsmasq.d --local-service -C $conf_file -r /run/wg870 --dhcp-broadcast
+fi
+exit 0
diff --git a/IC_src/mtk/lib/liblynq-wifi6/scripts/start_stop_ap.sh b/IC_src/mtk/lib/liblynq-wifi6/scripts/start_stop_ap.sh
index 441a0ee..78f0110 100755
--- a/IC_src/mtk/lib/liblynq-wifi6/scripts/start_stop_ap.sh
+++ b/IC_src/mtk/lib/liblynq-wifi6/scripts/start_stop_ap.sh
@@ -22,17 +22,31 @@
 	echo "dhcp-leasefile=/run/wg870/ap0.lease" >> $conf_file
 	ps -eo "%p %a" | grep "/usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid" | grep -v grep 
 	if [ $? != 0 ]; then
-		/usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid -7 /run/wg870/dnsmasq.d --local-service -C $conf_file -r /run/wg870 --dhcp-broadcast
+	    /usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid -7 /run/wg870/dnsmasq.d --local-service -C $conf_file -r /run/wg870 --dhcp-broadcast
+	    ps -eo "%p %a" | grep "/usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid" | grep -v grep
+	    if [ $? != 0 ]; then
+	        /usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid -7 /run/wg870/dnsmasq.d --local-service -C $conf_file -r /run/wg870 --dhcp-broadcast
+	        if [ $? != 0 ]; then
+			echo "$(date)[LYNQ_WIFI] retry start dnsmasq failed,please check dnsmasq status" >> /var/log/syslog.log
+		fi
+	    fi
 	fi
 
 elif [ "$1" == "stop" ]; then
-	ps -eo "%p %a" | grep "/usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid" | grep -v grep | awk '{print "kill "$1}' | sh
-	ifconfig ap0 down
-	if [ $? != 0 ]; then
-		exit 1
-	fi
+        ps -eo "%p %a" | grep "/usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid" | grep -v grep | awk '{print "kill "$1}' | sh
+        ps -eo "%p %a" | grep "/usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid" | grep -v grep
+        if [ $? == 0 ]; then
+            ps -eo "%p %a" | grep "/usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid" | grep -v grep | awk '{print "kill -9 "$1}' | sh
+            if [ $? != 0 ]; then
+                echo "$(date)[LYNQ_WIFI] retry stop dnsmasq failed,please check dnsmasq status" >> /var/log/syslog.log
+            fi
+        fi
+        ifconfig ap0 down
+        if [ $? != 0 ]; then
+            exit 1
+        fi
 else
-	exit 2
+    exit 2
 fi
 
 exit 0