[Bugfix][API-599][wifi]reset commit 20471cf for python test wifi api

Change-Id: I7e66970d864ce567c386149b02a62661735ad7d2
diff --git a/lib/liblynq-wifi6/libwifi6.c b/lib/liblynq-wifi6/libwifi6.c
index c60a6d4..03fc67a 100755
--- a/lib/liblynq-wifi6/libwifi6.c
+++ b/lib/liblynq-wifi6/libwifi6.c
@@ -60,14 +60,7 @@
 const char * state_scan_result = "CTRL-EVENT-SCAN-RESULTS";
 const char * STATE_COMPLETED = "COMPLETED";
 
-struct local_wpa_ctrl{
-    struct wpa_ctrl *ctrl;
-    pthread_mutex_t mutex;
-};
-
-static pthread_mutex_t s_check_wpa_ctrl_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-static struct local_wpa_ctrl * g_lynq_wpa_ctrl[2] = {0};
+static struct wpa_ctrl * g_lynq_wpa_ctrl[2] = {0};
 
 
 typedef struct __curr_status_info {
@@ -76,48 +69,6 @@
     int net_no;
 }curr_status_info;
 
-static int local_wpa_ctrl_request(struct local_wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
-                            char *reply, size_t *reply_len,
-                                  void (*msg_cb)(char *msg, size_t len))
-{
-    int ret;
-    if (ctrl->ctrl == NULL) {
-        printf("local_wpa_ctrl_request ctrl is null\n");
-        return -1;
-    }
-    pthread_mutex_lock(&ctrl->mutex);
-    ret = wpa_ctrl_request(ctrl->ctrl, cmd, cmd_len, reply, reply_len, msg_cb);
-    pthread_mutex_unlock(&ctrl->mutex);
-    return ret;
-}
-
-static struct local_wpa_ctrl * inner_get_wpa_ctrl(int index) {
-    int repeat_cnt;
-    struct local_wpa_ctrl *lynq_wpa_ctrl = NULL;
-    pthread_mutex_lock(&s_check_wpa_ctrl_mutex);
-    for (repeat_cnt = 0; repeat_cnt < 5 && NULL == g_lynq_wpa_ctrl[index]; repeat_cnt++) {
-        pthread_mutex_unlock(&s_check_wpa_ctrl_mutex);
-//        printf("wait enable finish\n");
-        usleep(500 * 1000);
-        pthread_mutex_lock(&s_check_wpa_ctrl_mutex);
-    }
-    if (NULL == g_lynq_wpa_ctrl[index]) {
-        goto out_addr;
-    }
-    if (NULL == g_lynq_wpa_ctrl[index]->ctrl) {
-        g_lynq_wpa_ctrl[index]->ctrl = wpa_ctrl_open(CTRL_PATH[index]);
-        if (NULL == g_lynq_wpa_ctrl[index]->ctrl) {
-            printf("wpa_ctrl_open fail\n");
-            goto out_addr;
-        }
-        pthread_mutex_init(&g_lynq_wpa_ctrl[index]->mutex, NULL);
-    }
-    lynq_wpa_ctrl = g_lynq_wpa_ctrl[index];
-out_addr:
-    pthread_mutex_unlock(&s_check_wpa_ctrl_mutex);
-    return lynq_wpa_ctrl;
-}
-
 #define PRINT_AND_RETURN_VALUE(str,value) \
 {\
     perror((str));\
@@ -135,17 +86,23 @@
 #define CHECK_WPA_CTRL(index) int ret = 0;\
     size_t reply_len = MAX_RET; \
     char cmd_reply[MAX_RET]={0}; \
-    struct local_wpa_ctrl *lynq_wpa_ctrl = NULL; \
+    struct wpa_ctrl *lynq_wpa_ctrl = NULL; \
     do{ \
-        lynq_wpa_ctrl = inner_get_wpa_ctrl(index); \
-        if (NULL == lynq_wpa_ctrl) return -1; \
+        if (NULL == g_lynq_wpa_ctrl[index]) { \
+            g_lynq_wpa_ctrl[index] = wpa_ctrl_open(CTRL_PATH[index]); \
+            if (NULL == g_lynq_wpa_ctrl[index]) { \
+                printf("wpa_ctrl_open fail\n"); \
+                return -1; \
+            } \
+        } \
+        lynq_wpa_ctrl = g_lynq_wpa_ctrl[index]; \
     }while(0)
 
 #define DO_REQUEST(cmd_str) do { \
         reply_len = MAX_RET;\
         cmd_reply[0] = '\0'; \
-        printf("to call 3 [%s]\n", cmd_str);  \
-        ret = local_wpa_ctrl_request(lynq_wpa_ctrl, cmd_str, strlen(cmd_str), cmd_reply, &reply_len, NULL); \
+        printf("to call [%s]\n", cmd_str);  \
+        ret = wpa_ctrl_request(lynq_wpa_ctrl, cmd_str, strlen(cmd_str), cmd_reply, &reply_len, NULL); \
         if (ret != 0) { \
             printf("call "#cmd_str" fail %d\n", ret); \
             return ret; \
@@ -287,13 +244,6 @@
 {
     int ret = 0;
     int i;
-
-    pthread_mutex_lock(&s_check_wpa_ctrl_mutex);
-
-    if (g_lynq_wpa_ctrl[0] != NULL && g_lynq_wpa_ctrl[1] != NULL) {
-        goto out_enable;
-    }
-
     const char * cmd_check_service =
             "state=`systemctl is-active wg870_drv_insmod.service`\n"
             "[ \"\"$state == \"active\" ] && exit 0\n"
@@ -305,8 +255,7 @@
     ret = system(cmd_check_service);
     if (ret != 0) {
         printf("service state %d\n", ret);
-        ret = -1;
-        goto out_enable;
+        return -1;
     }
 
     for (i=0; i<10; i++) {
@@ -317,8 +266,7 @@
     }
 
     if (i >= 10) {
-        ret = -1;
-        goto out_enable;
+        return -1;
     }
 
     //@todo delete add temp check for socket avilable start (20220606)
@@ -332,8 +280,7 @@
 
     if (i >= 60)
     {
-        ret = -1;
-        goto out_enable;
+        return -1;
     }
     //@todo delete add temp check for socket avilable end (20220606)
 
@@ -351,16 +298,14 @@
     if (g_ap_watcher_pid == 0 ) {
         ret=pthread_create(&g_ap_watcher_pid,NULL,APWatcherThreadProc,NULL);
         if(ret<0){
-            ret = -1;
-            goto out_enable;
+            return -1;
         }
     }
 
     if (g_sta_watcher_pid == 0 ) {
         ret=pthread_create(&g_sta_watcher_pid,NULL,STAWatcherThreadProc,NULL);
         if(ret<0){
-            ret = -1;
-            goto out_enable;
+            return -1;
         }
     }
 
@@ -371,16 +316,11 @@
         }
     }
 
-    g_lynq_wpa_ctrl[0] = malloc(sizeof (struct local_wpa_ctrl));
-    g_lynq_wpa_ctrl[1] = malloc(sizeof (struct local_wpa_ctrl));
- out_enable:
-    pthread_mutex_unlock(&s_check_wpa_ctrl_mutex);
     return ret;
 }
 
 int lynq_wifi_disable(void)
 {
-    pthread_mutex_lock(&s_check_wpa_ctrl_mutex);
     g_ap_watcher_stop_flag = 1;
     g_sta_watcher_stop_flag = 1;
     if (g_ap_watcher_pid != 0)
@@ -396,7 +336,6 @@
     g_lynq_wpa_ctrl[0] = NULL;
     g_lynq_wpa_ctrl[1] = NULL;
     system("systemctl stop wg870_drv_insmod.service");
-    pthread_mutex_unlock(&s_check_wpa_ctrl_mutex);
 	return 0;
 }
 
@@ -1487,7 +1426,6 @@
     }
 
     if (index >= len || NULL == p || network_len <= 0) {
-        printf("index:%d-%d, %p, network_len:%d\n", index, len, p, network_len);
         return -1;
     }
 
@@ -1985,7 +1923,7 @@
         sprintf(lynq_next_sta_cmd, "STA-NEXT %s", split_lines[0]);
         reply_len = MAX_RET;
         cmd_reply[0] = '\0';
-        ret = local_wpa_ctrl_request(lynq_wpa_ctrl, lynq_next_sta_cmd, strlen(lynq_next_sta_cmd), cmd_reply, &reply_len, NULL);
+        ret = wpa_ctrl_request(lynq_wpa_ctrl, lynq_next_sta_cmd, strlen(lynq_next_sta_cmd), cmd_reply, &reply_len, NULL);
         if (ret != 0 || memcmp(cmd_reply, "FAIL", 4) == 0) {
             printf("run %s fail \n", lynq_next_sta_cmd);
             break;
@@ -2276,7 +2214,7 @@
 //        reply_len = MAX_RET;
 //        cmd_reply[0] = '\0';
 //        printf("to call [%s]\n", cmd_str);
-//        ret = local_wpa_ctrl_request(s_lynq_wpa_ctrl, cmd_str, strlen(cmd_str), cmd_reply, &reply_len, NULL);
+//        ret = wpa_ctrl_request(s_lynq_wpa_ctrl, cmd_str, strlen(cmd_str), cmd_reply, &reply_len, NULL);
 //        if (ret != 0) {
 //            printf("call ##cmd_str fail %d\n", ret);
 //            return ret;