Merge "[Bugfix][T106][task-view-57]Solve file handle may not right close"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-wifi-demo/files/lynq-wifi-demo.cpp b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-wifi-demo/files/lynq-wifi-demo.cpp
index 949c1f3..445f51f 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-wifi-demo/files/lynq-wifi-demo.cpp
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-wifi-demo/files/lynq-wifi-demo.cpp
@@ -12,16 +12,22 @@
 #include <time.h>
 #include <syslog.h>
 #include <pthread.h>
+#include <signal.h>
 
 #include <include/lynq-qser-autosuspend.h>
 #include <include/lynq-qser-wifi.h>
 
+static lynq_wifi_ap_index_e type;
+static int wifi_lock_num;
+
 void lynq_wifi_event_handle_demo(lynq_wifi_event_s *event, void *arg)
 {
     if(event->id == LYNQ_WIFI_EVENT_AP_STATION)
         printf("[lynq-wifi-demo]  %s:event-id = %d - %d\n", __func__, event->id, event->status);
-    else if(event->id == LYNQ_WIFI_EVENT_STA_STATUS)
+    else if(event->id == LYNQ_WIFI_EVENT_AP_STA_STATUS)
         printf("[lynq-wifi-demo]  %s:event-id = %d,%d,%s,%s\n", __func__, event->id, event->ap_sta_info.connected, event->ap_sta_info.mac,event->ap_sta_info.hostname);
+    if(event->id == LYNQ_WIFI_EVENT_STA_STATUS)
+        printf("[lynq-wifi-demo]  %s:event-id = %d - %d\n", __func__, event->id, event->status);
     else
         return;
 }
@@ -50,15 +56,27 @@
 	}
 }
 
+void signalHandler(int signum)
+{
+    qser_wifi_ap_stop(type); // Disable ap mode for 2.4G/5G
+    qser_wifi_disable();     // Turn off WiFi
+    int ret = qser_wakelock_unlock(wifi_lock_num);
+    if (ret != 0)
+    {
+        printf("wakelock unlock fail\n");
+        printf("ret=%d\n", ret);
+    }
+    ret = qser_wakelock_destroy(wifi_lock_num);
+    if (ret != 0)
+    {
+        printf("wakelock destroy fail\n");
+        printf("ret=%d\n", ret);
+    }
+    exit(signum);
+}
+
 int main(int argc, char *argv[])
 {
-    int num = qser_wakelock_create("wifi_lock", 10);
-    if(num < 0)
-    {
-        printf("wakelock create fail\n");
-        printf("num=%d\n", num);
-    }
-    lynq_wifi_ap_index_e type;
     if (strcmp(argv[0], "lynq-wifi-demo") == 0)
         type = LYNQ_WIFI_AP_INDEX_AP0; // 2.4G
     else
@@ -67,30 +85,40 @@
     {
         if (strcmp(argv[1], "0") == 0) //Turn off WiFi and uninstall
         {
-            qser_wifi_enable();      // enable wifi
+            int ret = qser_wifi_enable();      // enable wifi
+            if(ret != 0)
+                return -1;
+            wifi_lock_num = qser_wakelock_create("wifi_lock", 10);
+            if(wifi_lock_num < 0)
+            {
+                printf("wakelock create fail\n");
+                printf("wifi_lock_num=%d\n", wifi_lock_num);
+            }
             qser_wifi_ap_stop(type); // Disable ap mode for 2.4G/5G
             qser_wifi_disable();     // Turn off WiFi
-            int ret = qser_wakelock_unlock(num);
+            ret = qser_wakelock_unlock(wifi_lock_num);
             if(ret != 0)
             {
                 printf("wakelock unlock fail\n");
                 printf("ret=%d\n", ret);
             }
-            ret = qser_wakelock_destroy(num);
+            ret = qser_wakelock_destroy(wifi_lock_num);
             if(ret != 0)
             {
                 printf("wakelock destroy fail\n");
                 printf("ret=%d\n", ret);
             }
         }
-        else if (strcmp(argv[1], "1") == 0) //Load WiFi and turn on WiFi
+        else if (strcmp(argv[1], "1") == 0) //Set WiFi parameters
         {
             char pw[65] = {0};
             char mac_list[360] = {0};
             srand(time(NULL));
             sprintf(pw, "lynq123456");
             sprintf(mac_list, "AA:BB:CC:DD:EE:%d%d;AA:BB:CC:%d%d:EE:00;AA:BB:%d%d:DD:EE:00",rand()%10,rand()%10,rand()%10,rand()%10,rand()%10,rand()%10);
-            qser_wifi_enable(); // enable wifi
+            int ret = qser_wifi_enable(); // enable wifi
+            if(ret != 0)
+                return -1;
             if (type == LYNQ_WIFI_AP_INDEX_AP0)
                 qser_wifi_work_mode_set(LYNQ_WIFI_WORK_MODE_AP0); // Set 2.4G, and this function must be called after the qser_wifi_enable function
             else
@@ -111,13 +139,8 @@
                 qser_wifi_ap_mode_set(type, LYNQ_WIFI_MODE_80211ANACAX_5G);
             }
             qser_wifi_ap_auth_set(type, LYNQ_WIFI_AUTH_WPA2_PSK, pw); // Set the authentication of 2.4G/5G to wpa2 and the password to lynq123456
-            qser_wifi_ap_start(type);                                 // Set the ap mode of 2.4G/5G
-            int ret = qser_wakelock_lock(num);
-            if(ret != 0)
-            {
-                printf("wakelock lock fail\n");
-                printf("ret=%d\n", ret);
-            }
+            qser_wifi_disable();     // Turn off WiFi
+            
         }
         else if (strcmp(argv[1], "2") == 0) //Callback query that only covers WiFi as an ap
         {
@@ -136,7 +159,9 @@
             lynq_wifi_pkt_stats_t pkt_stat = {0};
             lynq_wifi_bandwidth_type_e bandwidth;
             int ret = -1;
-            qser_wifi_enable();                      // enable wifi
+            ret = qser_wifi_enable();                      // enable wifi
+            if(ret != 0)
+                return -1;
             ret = qser_wifi_ap_ssid_get(type, ssid); // Gets the ssid of 2.4G/5G
             printf("[lynq-wifi-demo]  ssid=%s ret = %d\n", ssid, ret);
             ret = qser_wifi_ap_ssid_hide_get(type, &hidden); // Gets whether the ssid state is hidden
@@ -171,13 +196,30 @@
             printf("[lynq-wifi-demo]ap_pkt_get rx[%llu, %llu, %llu, %llu] tx[%llu, %llu, %llu, %llu] ret=%d\n",
                    pkt_stat.rx_packets, pkt_stat.rx_bytes, pkt_stat.rx_errors, pkt_stat.rx_dropped,
                    pkt_stat.tx_packets, pkt_stat.tx_bytes, pkt_stat.tx_errors, pkt_stat.tx_dropped, ret);
+            qser_wifi_disable();     // Turn off WiFi
         }
         else if (strcmp(argv[1], "3") == 0) //Enable the callback query only when WiFi is used as an ap
         {
             int ret = -1;
-            int args = 3;       // enable ap_sta callback
-            qser_wifi_enable(); // enable wifi
+            int args = 0;       // enable callback
+            ret = qser_wifi_enable(); // enable wifi
+            if(ret != 0)
+                return -1;
+            wifi_lock_num = qser_wakelock_create("wifi_lock", 10);
+            if(wifi_lock_num < 0)
+            {
+                printf("wakelock create fail\n");
+                printf("wifi_lock_num=%d\n", wifi_lock_num);
+            }
+            qser_wifi_ap_start(type); // Set the ap mode of 2.4G/5G
             qser_wifi_register_handle(lynq_wifi_event_handle_demo, NULL, (void *)&args);
+            ret = qser_wakelock_lock(wifi_lock_num);
+            if(ret != 0)
+            {
+                printf("wakelock lock fail\n");
+                printf("ret=%d\n", ret);
+            }
+            signal(SIGINT, signalHandler);
             while (1)
             {
                 char cmdstr[128] = {0};
@@ -206,11 +248,19 @@
         else if (strcmp(argv[1], "4") == 0) //Overlay WiFi callback as ap and scan callback as sta
         {
             int ret = -1;
-            int args = 0; //enable ap_set and ap_sta callback
+            int args = 0; //enable callback
             char ssid[33] = {0};
             char cmdstr[128] = {0};
             lynq_wifi_sta_param_t stat = {0};
-            qser_wifi_enable(); // enable wifi
+            ret = qser_wifi_enable(); // enable wifi
+            if(ret != 0)
+                return -1;
+            wifi_lock_num = qser_wakelock_create("wifi_lock", 10);
+            if(wifi_lock_num < 0)
+            {
+                printf("wakelock create fail\n");
+                printf("wifi_lock_num=%d\n", wifi_lock_num);
+            }
             if (type == LYNQ_WIFI_AP_INDEX_AP0)
                 qser_wifi_work_mode_set(LYNQ_WIFI_WORK_MODE_AP0); // Set 2.4G, and this function must be called after the qser_wifi_enable function
             else
@@ -220,12 +270,13 @@
             qser_wifi_sta_start();
             qser_wifi_sta_start_scan(); // When this function is executed once, sta's scan is called once
             memset(cmdstr, 0, sizeof(cmdstr));
-            ret = qser_wakelock_lock(num);
+            ret = qser_wakelock_lock(wifi_lock_num);
             if(ret != 0)
             {
                 printf("wakelock lock fail\n");
                 printf("ret=%d\n", ret);
             }
+            signal(SIGINT, signalHandler);
             while (1)
             {
                 printf("[lynq-wifi-demo]Enter the ssid and password as shown in the following example:ssid auth paris pw ||sta_pkt_get ||sta_param_get || sta_scan ||sta_stop\n");
@@ -260,6 +311,19 @@
                     {
                         qser_wifi_sta_stop();
                         printf("[lynq-wifi-demo]end \n");
+                        qser_wifi_disable();     // Turn off WiFi
+                        int ret = qser_wakelock_unlock(wifi_lock_num);
+                        if(ret != 0)
+                        {
+                            printf("wakelock unlock fail\n");
+                            printf("ret=%d\n", ret);
+                        }
+                        ret = qser_wakelock_destroy(wifi_lock_num);
+                        if(ret != 0)
+                        {
+                            printf("wakelock destroy fail\n");
+                            printf("ret=%d\n", ret);
+                        }
                         break;
                     }
                     else
@@ -285,8 +349,8 @@
         printf("  [lynq-wifi-demo]4: sta mode to obtain access point information and set ssid and password and other information connection\n");
         printf("  [lynq-wifi-demo]3: Obtain sta data information in ap mode\n");
         printf("  [lynq-wifi-demo]2: View information such as ssid, password, and channel in ap mode\n");
-        printf("  [lynq-wifi-demo]1: initializes wifi and enables and sets ap mode\n");
-        printf("  [lynq-wifi-demo]0: indicates off.\n");
+        printf("  [lynq-wifi-demo]1: initializes wifi\n");
+        printf("  [lynq-wifi-demo]0: Turn off WiFi and turn off the lock\n");
         return 0;
     }
 
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/mbtk_gnss_internal.h b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/mbtk_gnss_internal.h
index 50cc58a..acd1c04 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/mbtk_gnss_internal.h
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/mbtk_gnss_internal.h
@@ -250,7 +250,7 @@
 
 #define MBTK_GNSS_DEV  "/dev/ttyS2"
 
-#define MBTK_UART_RECV_BUFFER_SIZE 1024
+#define MBTK_UART_RECV_BUFFER_SIZE 1024*1024
 #define MBTK_UART_SEND_BUFFER_MAX 128
 
 #define TRUE 1
@@ -349,6 +349,7 @@
 int lynq_gnss_get_device_info(uint32 h_gnss);
 int lynq_gnss_get_uart(uint32 h_gnss);
 int lynq_gnss_get_ap_data(void);
+int lynq_gnss_output_frq(int frequency);
 
 #ifdef __cplusplus
 }
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/lynq_qser_gnss.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/lynq_qser_gnss.cpp
index 1aed4db..73f176e 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/lynq_qser_gnss.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/lynq_qser_gnss.cpp
@@ -266,56 +266,22 @@
  *
  * @return     
  */
-static unsigned char save_configuration[] = {0xF1,0xD9,0x06,0x09,0x08,0x00,0x00,0x00,0x00,0x00,0x0F,0x00,0x00,0x00,0x26,0x37};
-static unsigned char one_frequency[] = {0xF1,0xD9,0x06,0x42,0x14,0x00,0x00,0x01,0x00,0x00,0xE8,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0xF6};
-static unsigned char two_frequency[] = {0xF1,0xD9,0x06,0x42,0x14,0x00,0x00,0x02,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC4,0x88};
-static unsigned char three_frequency[] = {0xF1,0xD9,0x06,0x42,0x14,0x00,0x00,0x05,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC7,0xC1};
+
 int qser_Gnss_Set_Frequency(uint32_t h_gnss, int frequency)
 {
     int ret;
-    int buf_lenth;
-    unsigned char *send_buf;
     if(!inited)
     {
         ALOGE("has not been initiated\n");
         return -1;
     }
-    struct mbtk_gnss_handle_t *gnss_handle = (struct mbtk_gnss_handle_t *)h_gnss;
-    switch(frequency)
-    {
-        case 1:
-        {
-            send_buf = one_frequency;
-            buf_lenth = sizeof(one_frequency);
-            break;
-        }
-        case 2:
-        {
-            send_buf = two_frequency;
-            buf_lenth = sizeof(two_frequency);
-            break;
-        }
-        case 5:
-        {
-            send_buf = three_frequency;
-            buf_lenth = sizeof(three_frequency);
-            break;
-        }
-        default:
-            return 0;
-    }
-    ret = write(gnss_handle->dev_fd, send_buf, buf_lenth);
+
+    ret = lynq_gnss_output_frq(frequency);
     if(ret < 0)
     {
         ALOGE("modify cmd send faild\n");
         return -1;
     }
-    ret = write(gnss_handle->dev_fd, save_configuration, sizeof(save_configuration));
-    if(ret < 0)
-    {
-        ALOGE("save configuration send faild\n");
-        return -1;
-    }
     return 0;
 }
 
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/mbtk_gnss.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/mbtk_gnss.cpp
index 5087a82..caf1a36 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/mbtk_gnss.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/mbtk_gnss.cpp
@@ -13,6 +13,8 @@
 #include <termios.h>
 #include <time.h>
 #include <sys/ioctl.h>
+#include <dirent.h>
+#include <sys/stat.h>
 #include <malloc.h>
 #include <sys/time.h>
 #include <liblog/lynq_deflog.h>
@@ -26,11 +28,14 @@
 
 #define _XOPEN_SOURCE
 #define NMEA_RMC "RMC"
+#define NEMA_LOG_FILE "/mnt/userdata/gnss.conf"
+
 extern long timezone;
 extern int g_gnss_sync_enable_flag;
 extern int g_gnss_sync_done;
 extern int event;
 extern int device_fd;
+
 typedef int (*sc_rtc_time_get_cb)(unsigned int src_id, unsigned long ulsec);
 extern int sc_rtc_timer_init(void);
 extern int sc_rtc_timer_uninit(void);
@@ -136,8 +141,20 @@
 static pthread_mutex_t loc_cond_mutex_r = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t loc_sync_cond = PTHREAD_COND_INITIALIZER;
 #endif
+
+const char *config_flags[] =
+{  
+    "debug.dbg2file",       //NMEA_LOG_FLAG,
+    "debug.filename",       //NMEA_LOG_NAME_FLAG,
+    "debug.filesize",       //NMEA_LOG_SIZE_FLAG,
+    "debug.filenum",        //NMEA_LOG_NUM_FLAG,
+    "debug.frequency"       //NMEA_OUTPUT_FREQ
+};
+#define NUM_CONFIG_FLAGS (sizeof(config_flags) / sizeof(config_flags[0]))
+int gnss_frq = 1;
 volatile int nmea_state = 0;
 volatile int nmea_reading = 0;
+
 static struct mbtk_gnss_cmd_msg_t mbtk_gnss_cmd_msg_map[] = {
 { 1,     "$OK",         NULL,                 0},
 { 2,     "$Fail",       NULL,                 0},
@@ -340,6 +357,124 @@
     return ret;
 }
 
+int lynq_gnss_output_frq(int frequency)
+{
+    char save_configuration[] = {0xF1,0xD9,0x06,0x09,0x08,0x00,0x00,0x00,0x00,0x00,0x0F,0x00,0x00,0x00,0x26,0x37};
+    char one_frequency[] = {0xF1,0xD9,0x06,0x42,0x14,0x00,0x00,0x01,0x62,0x00,0xE8,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xAA,0xDA};
+    char two_frequency[] = {0xF1,0xD9,0x06,0x42,0x14,0x00,0x00,0x02,0x62,0x00,0xF4,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xB5,0x8F};
+    char five_frequency[] = {0xF1,0xD9,0x06,0x42,0x14,0x00,0x00,0x05,0x62,0x00,0xC8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x8B,0xF9};
+    int ret;
+    int buf_length;
+    char *send_buf = NULL;
+    int fd = open(MBTK_GNSS_DEV, O_RDWR | O_NOCTTY | O_NDELAY);
+    if(fd < 0) {
+        ALOGE("open error\n");
+        return -1;
+    }
+    switch(frequency)
+    {
+        case 1:
+        {
+            send_buf = one_frequency;
+            buf_length = sizeof(one_frequency);
+            break;
+        }
+        case 2:
+        {
+            send_buf = two_frequency;
+            buf_length = sizeof(two_frequency);
+            break;
+        }
+        case 5:
+        {
+            send_buf = five_frequency;
+            buf_length = sizeof(five_frequency);
+            break;
+        }
+        default:
+        {
+            close(fd);
+            return -2;
+        }
+    }
+    ret = write(fd, send_buf, buf_length);
+    if(ret < 0)
+    {
+        ALOGE("modify cmd send faild\n");
+        close(fd);
+        return -1;
+    }
+    ret = write(fd, save_configuration, sizeof(save_configuration));
+    if(ret < 0)
+    {
+        ALOGE("save configuration send faild\n");
+        close(fd);
+        return -1;
+    }
+    usleep(100000);
+    close(fd);
+    return 0;
+}
+
+int lynq_gnss_configure_init()
+{
+    FILE *file;
+    char buffer[128];
+    char *configure_pointers[NUM_CONFIG_FLAGS] = {NULL};
+    
+    file = fopen(NEMA_LOG_FILE, "r");
+    if(file == NULL)
+    {
+        ALOGD("dont't need configure\n");
+        return -1;
+    }
+    while(fgets(buffer, 128, file) != NULL)
+    {
+        size_t len = strlen(buffer);
+        if(len > 0 && buffer[len-1] == '\n')
+        {
+            buffer[len-1] = '\0';
+        }
+        for(int i = 0; i < NUM_CONFIG_FLAGS; i++)
+        {
+            if(strncmp(buffer, config_flags[i], strlen(config_flags[i])) == 0)
+            {
+                if(configure_pointers[i] == NULL)
+                {
+                    configure_pointers[i] = strdup(buffer); // 复制到相应位置  
+                }
+                break; // 找到匹配后可以退出循环  
+            }
+        }
+    }
+    fclose(file);
+
+    if(configure_pointers[4] != NULL)
+    {
+        int ret;
+        gnss_frq = atoi(configure_pointers[4] + strlen(config_flags[4]) + 1);
+        ALOGD("gnss_frq = %d\n", gnss_frq);
+        ret = lynq_gnss_output_frq(gnss_frq);
+        {
+            if(ret < 0)
+            {
+                ALOGE("set gnss frq error\n");
+            }
+        }
+    }
+
+    for(int j = 0; j < NUM_CONFIG_FLAGS; j++)
+    {  
+        if(configure_pointers[j] != NULL)
+        {  
+            free(configure_pointers[j]); // 释放使用 strdup 分配的内存  
+        }  
+    }
+    
+    return 0;
+}
+
+
 static void get_gnss_agnss_state(int cmd, char *str, void *data)
 {
 
@@ -788,12 +923,9 @@
                 break;
             }
         }
-
         if (i > (256 - 2))
             continue;
-
         ret = ring_buffer_dequeue_arr(&gnss_handle->ring_buffer, tmp_arr, i + 1);
-
         if(ret > 0 && 0 == mbtk_gnss_handle->getap_status) {
             get_gnss_from_str(gnss_handle, tmp_arr, ret);
             memset(tmp_arr, 0, sizeof(tmp_arr));
@@ -819,15 +951,12 @@
 
     while(mbtk_gnss_handle->inited)
     {
-        while(mbtk_gnss_handle->getap_status){
-            // 在读AP_DATA星历时,不能输出NMEA
-            usleep(100000);
-        }
         if(nmea_state == 1)
         {
             nmea_reading = 1;
             ret = mopen_gnss_read(gnss_handle->dev_fd, buf, MBTK_UART_RECV_BUFFER_SIZE);
             nmea_reading = 0;
+
             if(ret > 0) {
                 ring_buffer_queue_arr(&gnss_handle->ring_buffer, buf, ret);
                 memset(buf, 0, sizeof(buf));
@@ -835,7 +964,7 @@
                 gnss_log("read error\n");
             }
         }
-        usleep(100000);
+        usleep(5000);
     }
 
     pthread_exit(NULL);
@@ -996,6 +1125,8 @@
     return 0;
 }
 
+
+
 int lynq_gnss_client_init(uint32 *ph_gnss)
 {
     int ret;
@@ -1018,9 +1149,7 @@
     }
     memset(mbtk_gnss_handle, 0, sizeof(struct mbtk_gnss_handle_t));
     memset(&mopen_gnss_device_info, 0, sizeof(mopen_gnss_device_info));
-    lynq_open_gps(0);
-
-    mbtk_gnss_handle->dev_fd = mopen_gnss_open(MBTK_GNSS_DEV, 0);
+    mbtk_gnss_handle->dev_fd = mopen_gnss_open(MBTK_GNSS_DEV, B115200);
     mbtk_gnss_handle->rb = (char*)malloc(MBTK_UART_RECV_BUFFER_SIZE);
     if(NULL == mbtk_gnss_handle->rb)
     {
@@ -1028,6 +1157,12 @@
         return -1;
     }
 
+    lynq_open_gps(1);
+    sleep(1);
+    lynq_gnss_configure_init();
+
+    lynq_open_gps(0);
+
     ring_buffer_init(&mbtk_gnss_handle->ring_buffer,
                      mbtk_gnss_handle->rb,
                      MBTK_UART_RECV_BUFFER_SIZE);
@@ -1386,8 +1521,8 @@
     }
     if(mbtk_http_session_start(http_handle, http_session))
     {
-    printf("mbtk_http_session_start() fail.\n");
-    return -4;
+        printf("mbtk_http_session_start() fail.\n");
+        return -4;
     }
     if(mbtk_http_handle_free(http_handle))
     {
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/include/lynq-qser-wifi.h b/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/include/lynq-qser-wifi.h
index 9f97c14..ff14d7a 100644
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/include/lynq-qser-wifi.h
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/include/lynq-qser-wifi.h
@@ -45,6 +45,7 @@
 	LYNQ_WIFI_EVENT_ENABLE_STATUS = 0,
 	LYNQ_WIFI_EVENT_DISABLE_STATUS,
 	LYNQ_WIFI_EVENT_AP_STATION,
+	LYNQ_WIFI_EVENT_AP_STA_STATUS,
 	LYNQ_WIFI_EVENT_STA_STATUS,
 	LYNQ_WIFI_EVENT_MAX,
 } lynq_wifi_event_type_e;
@@ -125,24 +126,6 @@
 	char bssid[18];
 }lynq_wifi_ap_status_t;
 
-typedef struct {
-	lynq_wifi_event_type_e id;
-	union {
-	    /* the LYNQ_WIFI_ENABLE_STATUS or LYNQ_WIFI_DISABLE_STATUS event */
-		lynq_wifi_status_e status;
-		struct {
-		    /* 
-		     * If connected is true, the station is connected wifi hotspot.
-		     * If connected is false, the station is disconnected wifi hotspot.
-		     */
-            int connected;
-            char mac[18]; //mac connected to WiFi device
-            char hostname[32]; //Name of the WiFi device
-		} ap_sta_info;
-		lynq_wifi_station_status_e sta_status;
-	};
-} lynq_wifi_event_s;
-
 typedef struct
 {
  	char ssid[33];
@@ -194,6 +177,7 @@
 
 typedef struct
 {
+	lynq_wifi_station_status_e sta_status;
 	lynq_wifi_sta_status_e status;
 	char ifname[32];
 	char ap_bssid[18]; //cur ap mac
@@ -250,6 +234,25 @@
     lynq_lanhost_t array[32];
 } lynq_lanhost_ts;
 
+typedef struct {
+	lynq_wifi_event_type_e id;
+	union {
+	    /* the LYNQ_WIFI_ENABLE_STATUS or LYNQ_WIFI_DISABLE_STATUS event */
+		lynq_wifi_status_e status;
+		struct {
+		    /* 
+		     * If connected is true, the station is connected wifi hotspot.
+		     * If connected is false, the station is disconnected wifi hotspot.
+		     */
+            int connected;
+            char mac[18]; //mac connected to WiFi device
+            char hostname[32]; //Name of the WiFi device
+		} ap_sta_info;
+		lynq_wifi_station_status_e sta_status;
+		lynq_wifi_sta_status_t sta_status_all;
+	};
+} lynq_wifi_event_s;
+
 typedef void (*lynq_wifi_event_handle)(lynq_wifi_event_s *event, void *arg);
 typedef void (*lynq_wifi_event_handle_sta)(lynq_wifi_sta_scan_list_t *event);
 
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;
 }
diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/zvnet/zvnet_dev.c b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/zvnet/zvnet_dev.c
index ffdba06..2a8fcc3 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/zvnet/zvnet_dev.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/zvnet/zvnet_dev.c
@@ -72,6 +72,10 @@
 module_param(g_wrap_num, int, 0644);

 unsigned int g_wrap_timeout = 10;

 module_param(g_wrap_timeout, int, 0644);

+/*jb.qi add for debug network package on 20240806 start*/

+unsigned int g_trace_limit = 0;

+module_param(g_trace_limit, int, 0644);

+/*jb.qi add for debug network package on 20240806 end*/

 #endif

 

 /*******************************************************************************

@@ -143,7 +147,19 @@
 		}

 	}

 }

+/*jb.qi add for debug network package on 20240806 start*/

+void zvnet_dump_packet(unsigned char * data, int len, int limit_len)

+{

+    int i = 0;

 

+    for(i = 0; i < len && i < limit_len; i=i+16)

+    {

+        printk("0x%04x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",i,

+            *(data+i),*(data+i+1),*(data+i+2),*(data+i+3),*(data+i+4),*(data+i+5),*(data+i+6),*(data+i+7),

+            *(data+i+8),*(data+i+9),*(data+i+10),*(data+i+11),*(data+i+12),*(data+i+13),*(data+i+14),*(data+i+15));

+    }

+}

+/*jb.qi add for debug network package on 20240806 end*/

 int zvnet_get_index_by_netdev(struct net_device *net)

 {

     int i;

@@ -288,6 +304,13 @@
 	/* make sure we initialize shinfo sequentially */

 	skb_reset_network_header(skb);

 	skb_set_kcov_handle(skb, kcov_common_handle());

+	/*jb.qi add for debug network package on 20240806 start*/

+	if(unlikely(g_trace_limit > 0)){

+        	printk("-%s-dump_packet-start-%d\n", skb->dev->name, skb->len);

+        	zvnet_dump_packet(skb->data, skb->len, g_trace_limit);

+        	printk("-%s-dump_packet-end-\n", skb->dev->name);

+        }

+	/*jb.qi add for debug network package on 20240806 end*/

 	return skb;

 }