[Feature][T106][task-view-121]The wifi connection is stable

	Only Configure: Yes
	Affected branch: master
	Affected module: wifi
	Is it affected on both ZXIC and MTK:only ZXIC
	Self-test: Yes
	Doc Update:Yes

Change-Id: I2998f42de65879d092b9f109b973d557d4adcf3d
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/lynq-qser-wifi.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/lynq-qser-wifi.cpp
index 2b23394..c444199 100644
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/lynq-qser-wifi.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/lynq-qser-wifi.cpp
@@ -7,6 +7,7 @@
 extern "C" {
 #endif
 
+#include <cfg_api.h>
 #include "sc_tel_types.h"
 #include "sc_wifi.h"
 #include "lynq-qser-wifi.h"
@@ -152,6 +153,43 @@
 }
 
 /********************************************************************
+* @brief: sc_to_lynq_sta_status, sc_wifi_sta_status_t to lynq_wifi_sta_status_t
+* @return :int, all
+* @todo: NA
+* @see: NA
+* @warning: NA
+*********************************************************************/
+static int sc_to_lynq_sta_status(sc_wifi_sta_status_t *stat, lynq_wifi_sta_status_t *status_stat)
+{
+    status_stat->status = (lynq_wifi_sta_status_e)stat->status;
+    status_stat->signal_level = stat->signal_level;
+    status_stat->has_addr = stat->has_addr;
+    status_stat->has_addr6 = stat->has_addr6;
+    status_stat->reason_code = (lynq_wifi_reason_code_e)stat->reason_code;
+    strncpy(status_stat->ifname, stat->ifname, sizeof(stat->ifname) - 1);
+    strncpy(status_stat->ap_bssid, stat->ap_bssid, sizeof(stat->ap_bssid) - 1);
+    if (status_stat->has_addr == 1)
+    {
+        strncpy(status_stat->addr.addr, stat->addr.addr, sizeof(status_stat->addr.addr) - 1);
+        strncpy(status_stat->addr.netmask, stat->addr.netmask, sizeof(status_stat->addr.netmask) - 1);
+        status_stat->addr.subnet_bits = stat->addr.subnet_bits;
+        strncpy(status_stat->addr.gateway, stat->addr.gateway, sizeof(status_stat->addr.gateway) - 1);
+        strncpy(status_stat->addr.dnsp, stat->addr.dnsp, sizeof(status_stat->addr.dnsp) - 1);
+        strncpy(status_stat->addr.dnss, stat->addr.dnss, sizeof(status_stat->addr.dnss) - 1);
+    }
+    if (status_stat->has_addr6 == 1)
+    {
+        strncpy(status_stat->addr6.addr, stat->addr6.addr, sizeof(status_stat->addr6.addr) - 1);
+        strncpy(status_stat->addr6.prefix, stat->addr6.prefix, sizeof(status_stat->addr6.prefix) - 1);
+        status_stat->addr6.prefix_bits = stat->addr6.prefix_bits;
+        strncpy(status_stat->addr6.gateway, stat->addr6.gateway, sizeof(status_stat->addr6.gateway) - 1);
+        strncpy(status_stat->addr6.dnsp, stat->addr6.dnsp, sizeof(status_stat->addr6.dnsp) - 1);
+        strncpy(status_stat->addr6.dnss, stat->addr6.dnss, sizeof(status_stat->addr6.dnss) - 1);
+    }
+    return 0;
+}
+
+/********************************************************************
 * @brief: lynq_user_status, wifi startup callback
 * @return : NA
 * @todo: NA
@@ -191,10 +229,7 @@
         {
             return;
         }
-        if (*(int *)global_arg != LYNQ_WIFI_EVENT_AP_STATION)
-        {
-            LYINFLOG("%s:%d,%d,%s,%d\n", __func__, index, pre_status, p_msg->ifname, p_msg->status);
-        }
+        LYINFLOG("%s:%d,%d,%s,%d\n", __func__, index, pre_status, p_msg->ifname, p_msg->status);
         event.id = LYNQ_WIFI_EVENT_AP_STATION;
         event.status = (lynq_wifi_status_e)pre_status;
         wifi_event_handle(&event, global_arg);
@@ -219,7 +254,7 @@
     int ret = sc_wifi_get_hostname_by_mac(p_msg->macaddr, hostname, sizeof(hostname));
     if (ret == 0)
     {
-        printf("[wifi_demo]sta ip not assigned, try again later!\n");
+        LYINFLOG("sta ip not assigned, try again later!\n");
     }
     if (wifi_event_handle != NULL && global_arg != NULL)
     {
@@ -227,11 +262,8 @@
         {
             return;
         }
-        if (*(int *)global_arg != LYNQ_WIFI_EVENT_STA_STATUS)
-        {
-            LYINFLOG("%s:%d,%d,%s,%s\n", __func__, index, p_msg->is_connected, p_msg->macaddr, hostname);
-        }
-        event.id = LYNQ_WIFI_EVENT_STA_STATUS;
+        LYINFLOG("%s:%d,%d,%s,%s\n", __func__, index, p_msg->is_connected, p_msg->macaddr, hostname);
+        event.id = LYNQ_WIFI_EVENT_AP_STA_STATUS;
         event.ap_sta_info.connected = p_msg->is_connected;
         strncpy(event.ap_sta_info.mac, p_msg->macaddr,
                 sizeof(event.ap_sta_info.mac) <= sizeof(p_msg->macaddr) ? sizeof(event.ap_sta_info.mac) : sizeof(p_msg->macaddr));
@@ -282,8 +314,30 @@
 static void lynq_user_sta_status_ind(sc_wifi_sta_status_e pre_status, 
   sc_wifi_sta_status_t *p_msg)
 {	 
-	 LYINFLOG("%s : user_sta_status_ind_cb pre:%d, cur:%d\n", __func__, pre_status, p_msg->status);
-	 print_sta_status(p_msg);
+    if (wifi_event_handle != NULL && global_arg != NULL)
+    {
+        lynq_wifi_event_s event;
+        if (*(int *)global_arg == LYNQ_WIFI_EVENT_DISABLE_STATUS)
+        {
+            return;
+        }
+        LYINFLOG("%s : user_sta_status_ind_cb pre:%d, cur:%d\n", __func__, pre_status, p_msg->status);
+        event.id = LYNQ_WIFI_EVENT_STA_STATUS;
+        if(p_msg->status == SC_WIFI_STA_STATUS_CONNECTED)
+            event.sta_status = LYNQ_WIFI_STATION_CONNECTED;
+        else if(p_msg->status == SC_WIFI_STA_STATUS_DISCONNECTED)
+            event.sta_status = LYNQ_WIFI_STATION_DISCONNECTED;
+        else
+            event.sta_status = LYNQ_WIFI_STATION_DISABLE;
+        sc_to_lynq_sta_status(p_msg, &event.sta_status_all);
+        event.sta_status_all.sta_status = event.sta_status;
+        wifi_event_handle(&event, global_arg);
+    }
+    else
+    {
+        print_sta_status(p_msg);
+    }
+	 
 }
 
 /********************************************************************
@@ -420,6 +474,13 @@
 *********************************************************************/
 int qser_wifi_enable(void)
 {
+    char wifiAvailable[8] = {0};
+    sc_cfg_get("wifiAvailable", wifiAvailable, sizeof(wifiAvailable));
+    if (!strcmp(wifiAvailable, "0"))
+    {
+        LYERRLOG("[%s ] wifiAvailable has been set to 0. If WiFi is used, set 1 to enable it\n", __func__);
+        return -1;
+    }
     int ret = -1;
     ret = sc_wifi_init();
     if (0 != ret)
@@ -1023,7 +1084,7 @@
         return ret;
     }
     lynq_arrays->array_len = 32;
-    ret = ret = sc_wifi_lanhost_get_list(array, &lynq_arrays->array_len);
+    ret = sc_wifi_lanhost_get_list(array, &lynq_arrays->array_len);
     if (0 != ret)
     {
         LYERRLOG("[%s ] ret = %d\n", __func__, ret);
@@ -1222,31 +1283,7 @@
         return ret;
     }
     print_sta_status(&stat);
-    status_stat->status = (lynq_wifi_sta_status_e)stat.status;
-    status_stat->signal_level = stat.signal_level;
-    status_stat->has_addr = stat.has_addr;
-    status_stat->has_addr6 = stat.has_addr6;
-    status_stat->reason_code = (lynq_wifi_reason_code_e)stat.reason_code;
-    strncpy(status_stat->ifname, stat.ifname, sizeof(stat.ifname) - 1);
-    strncpy(status_stat->ap_bssid, stat.ap_bssid, sizeof(stat.ap_bssid) - 1);
-    if (status_stat->has_addr == 1)
-    {
-        strncpy(status_stat->addr.addr, stat.addr.addr, sizeof(status_stat->addr.addr) - 1);
-        strncpy(status_stat->addr.netmask, stat.addr.netmask, sizeof(status_stat->addr.netmask) - 1);
-        status_stat->addr.subnet_bits = stat.addr.subnet_bits;
-        strncpy(status_stat->addr.gateway, stat.addr.gateway, sizeof(status_stat->addr.gateway) - 1);
-        strncpy(status_stat->addr.dnsp, stat.addr.dnsp, sizeof(status_stat->addr.dnsp) - 1);
-        strncpy(status_stat->addr.dnss, stat.addr.dnss, sizeof(status_stat->addr.dnss) - 1);
-    }
-    if (status_stat->has_addr6 == 1)
-    {
-        strncpy(status_stat->addr6.addr, stat.addr6.addr, sizeof(status_stat->addr6.addr) - 1);
-        strncpy(status_stat->addr6.prefix, stat.addr6.prefix, sizeof(status_stat->addr6.prefix) - 1);
-        status_stat->addr6.prefix_bits = stat.addr6.prefix_bits;
-        strncpy(status_stat->addr6.gateway, stat.addr6.gateway, sizeof(status_stat->addr6.gateway) - 1);
-        strncpy(status_stat->addr6.dnsp, stat.addr6.dnsp, sizeof(status_stat->addr6.dnsp) - 1);
-        strncpy(status_stat->addr6.dnss, stat.addr6.dnss, sizeof(status_stat->addr6.dnss) - 1);
-    }
+    sc_to_lynq_sta_status(&stat, status_stat);
     LYINFLOG("[%s ] ret = %d \n", __func__, ret);
     return 0;
 }