[Bugfix] add delay in wifi_enable,set quiet when grep

Change-Id: I9e77debd0fdbbe7c706290745914981d67af5cf3
diff --git a/lib/liblynq-wifi6/libwifi6.c b/lib/liblynq-wifi6/libwifi6.c
index 3672fc7..102d130 100755
--- a/lib/liblynq-wifi6/libwifi6.c
+++ b/lib/liblynq-wifi6/libwifi6.c
@@ -38,10 +38,12 @@
 
 pthread_t g_ap_watcher_pid = 0;
 volatile int g_ap_watcher_stop_flag = 0;
+volatile int g_ap_watcher_started_flag = 0;
 
 pthread_t g_sta_watcher_pid = 0;
 volatile int g_sta_watcher_stop_flag = 0;
 volatile int g_sta_scan_finish_flag = 0;
+volatile int g_sta_watcher_started_flag = 0;
 
 void * g_ap_callback_priv = NULL;
 AP_CALLBACK_FUNC_PTR g_ap_callback_func = NULL;
@@ -136,6 +138,7 @@
             }
 
             wpa_ctrl_attach(lynq_wpa_ctrl);
+            g_ap_watcher_started_flag = 1;
         }
 
         if ( 0 == wpa_ctrl_pending(lynq_wpa_ctrl)) {
@@ -179,6 +182,7 @@
             }
 
             wpa_ctrl_attach(lynq_wpa_ctrl);
+            g_sta_watcher_started_flag = 1;
         }
 
         if ( 0 == wpa_ctrl_pending(lynq_wpa_ctrl)) {
@@ -248,7 +252,7 @@
     }
 
     for (i=0; i<10; i++) {
-        if (system("connmanctl technologies | grep \"/net/connman/technology/wifi\"") == 0) {
+        if (system("connmanctl technologies | grep -q \"/net/connman/technology/wifi\"") == 0) {
             break;
         }
         usleep(300*1000);
@@ -258,11 +262,13 @@
         return -1;
     }
 
-    if (0 != system("ifconfig | grep ap0")) {
-        printf("enable wifi\n");
+    if (0 != system("ifconfig | grep -q ap0")) {
         system("connmanctl enable wifi");
+        usleep(300*1000);
         system("wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=wlan0 DRIVER interface_create ap0");
+        usleep(300*1000);
         system("connmanctl tether wifi on lynq 1qaz@WSX#$%^");
+        usleep(300*1000);
     }
 
     if (g_ap_watcher_pid == 0 ) {
@@ -279,6 +285,13 @@
         }
     }
 
+    for (i=0; i<10; i++) {
+        usleep(300*1000);
+        if (g_ap_watcher_started_flag == 1 && g_sta_watcher_started_flag == 1) {
+            break;
+        }
+    }
+
     return ret;
 }
 
@@ -329,7 +342,7 @@
         return -1;
     }
 
-    printf("reply len %d, %08x\n", reply_len, (int)out_put);
+//    printf("reply len %d, %08x\n", reply_len, (int)out_put);
     memcpy(out_put, cmd_reply, reply_len + 1);
     return 0;
 }
@@ -1028,7 +1041,7 @@
         }
     }
     else {
-        if (inner_get_param(CTRL_AP, AP_NETWORK_0, "key_mgmt", lynq_proto_str) != 0) {
+        if (inner_get_param(CTRL_AP, AP_NETWORK_0, "proto", lynq_proto_str) != 0) {
             *auth = LYNQ_WIFI_AUTH_WPA_PSK;
         }
         else if (memcmp(lynq_proto_str, "RSN", 3) == 0) {
@@ -1043,7 +1056,6 @@
 }
 
 
-
 int lynq_wifi_ap_start(lynq_wifi_index_e idx)
 {
     char LYNQ_WIFI_CMD[128]={0};
@@ -1671,7 +1683,7 @@
 
     system("connmanctl enable wifi");
 
-    if (system("ifconfig | grep wlan0") != 0) {
+    if (system("ifconfig | grep -q wlan0") != 0) {
         return -1;
     }