[Bugfix][API-1012][wifi] fix misreport service abnormal, fix fail call lynq_get_interface_ip for ap before ap start

Change-Id: Ie17b1eb750d05d5758b9dfbd10ce4af02f80664e
diff --git a/lib/liblynq-wifi6/libwifi6.c b/lib/liblynq-wifi6/libwifi6.c
index 2bfbd1e..368ae4f 100755
--- a/lib/liblynq-wifi6/libwifi6.c
+++ b/lib/liblynq-wifi6/libwifi6.c
@@ -170,10 +170,41 @@
     return system(str_cmd);
 }
 
+static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len);
+
+static const char * inner_get_ap_interface_name()
+{
+    char * p;
+    char cmd[128]={0};
+
+    sprintf(cmd, "%s %d", get_interface_name_script, LYNQ_WIFI_INTERFACE_1);
+    if (0 != exec_cmd(cmd, s_ap_iterface_name, sizeof(s_ap_iterface_name)) || s_ap_iterface_name[0] == '\0')
+    {
+        memset(s_ap_iterface_name, 0, sizeof (s_ap_iterface_name));
+        return NULL;
+    }
+    p = strchr(s_ap_iterface_name, ' ');
+    if (NULL != p)
+    {
+        *p = '\0';
+    }
+    p = strchr(s_ap_iterface_name, '\n');
+    if (NULL != p)
+    {
+        *p = '\0';
+    }
+    if (s_ap_iterface_name[0] == '\0')
+    {
+        return NULL;
+    }
+
+    return s_ap_iterface_name;
+}
+
 static void check_tether_and_notify()
 {
     RLOGD("check_tether_and_notify called");
-    if (s_ap_iterface_name[0] != '\0' && 0 == system_call_v("ifconfig | grep %s", s_ap_iterface_name))
+    if (inner_get_ap_interface_name() == NULL || 0 == system_call_v("ifconfig | grep %s", s_ap_iterface_name))
     {
         return;
     }
@@ -279,8 +310,6 @@
     }while (0)
 
 
-static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len);
-
 static int check_connection(struct wpa_ctrl * wpa_ctrl)
 {
     size_t reply_len = MAX_RET;
@@ -1886,9 +1915,9 @@
 
     CHECK_WPA_CTRL(CTRL_AP);
 
-    sprintf(LYNQ_WIFI_CMD, "%s %d", get_interface_name_script, LYNQ_WIFI_INTERFACE_1);
-    if (0 != exec_cmd(LYNQ_WIFI_CMD, s_ap_iterface_name, sizeof(s_ap_iterface_name)) || s_ap_iterface_name[0] == '\0')
+    if (inner_get_ap_interface_name() == NULL)
     {
+        RLOGE("lynq_wifi_ap_start get ap name fail");
         return -1;
     }
 
@@ -1898,8 +1927,6 @@
     sprintf(LYNQ_WIFI_CMD,"SELECT_NETWORK %d",AP_NETWORK_0);
     DO_OK_FAIL_REQUEST(LYNQ_WIFI_CMD);
 
-    check_tether_and_notify();
-
     ret = system_call_v("%s %s", start_stop_ap_script, "start");
     if (ret != 0)
     {
@@ -1907,6 +1934,8 @@
         return -1;
     }
 
+    check_tether_and_notify();
+
     return 0;
 }
 
@@ -3159,7 +3188,11 @@
 
     CHECK_WPA_CTRL(CTRL_STA);
 
-//    system(clean_last_re); // youchen @ 2023-04-14 temp delete ,next time to fix the orginal bug
+    if (g_sta_scan_finish_flag == 1 && s_sta_status == INNER_STA_STATUS_INIT) // temp add
+    {
+        RLOGD("tmp clear scanlist");
+        system(clean_last_re);
+    }
     g_sta_scan_finish_flag = 0;
     DO_REQUEST(lynq_scan_cmd);
     if (reply_len >=9 && memcmp(cmd_reply, "FAIL-BUSY", 9) == 0 )
@@ -3431,7 +3464,12 @@
 
     if (idx == 1)
     {
-       ifaName = s_ap_iterface_name;
+       ifaName = inner_get_ap_interface_name();
+       if (ifaName == NULL)
+       {
+           RLOGE("[lynq_get_interface_ip] ap name get fail");
+           return -1;
+       }
     }
     else if (idx != 0)
     {
@@ -3740,7 +3778,7 @@
     nmax = 6;
     ncheckcount = nidlecount = 0;
 
-    if (s_ap_iterface_name[0] == '\0')
+    if (inner_get_ap_interface_name() == NULL)
     {
         RLOGE("------gbw thread run\n");
         return;