diff --git a/mbtk/liblynq_lib_rilv2/lynq_wifi.c b/mbtk/liblynq_lib_rilv2/lynq_wifi.c
new file mode 100755
index 0000000..a2b08b7
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_wifi.c
@@ -0,0 +1,1103 @@
+#include "sta_cli.h"
+#include "lynq_wifi.h"
+#include "mbtk_log.h"
+#include "mbtk_wifi_ap.h"
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+
+#define STA_BUF_SIZE 2048
+#define PATH_MAX_LEN 64
+#define DEF_INTERFACE "wlan0"
+static lynq_wifi_event_handle_sta g_event_handle_sta_cb = NULL;
+static lynq_wifi_status_e g_ap_status = LYNQ_WIFI_AP_STATUS_NONE;
+
+
+
+int qser_wifi_enable(void)
+{
+    static char sta_cli_buf[STA_BUF_SIZE] = "OPEN";
+    char reply[STA_BUF_SIZE];
+    if(sta_cli_cmd_parse(sta_cli_buf, reply, STA_BUF_SIZE))
+    {
+        if(strlen(reply) > 0)
+        {
+             LOGE("reply data(%s).\n",reply);
+        }
+        else
+        {
+            LOGE("No reply data(%s).\n",sta_cli_buf);
+            return LYNQ_ERR_FAIL;
+		}
+    }
+    else
+    {
+        LOGE("Parse cmd fail.\n");
+        return LYNQ_ERR_FAIL;
+    }
+
+    g_ap_status = LYNQ_WIFI_AP_STATUS_ENABLING;
+    return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_disable(void)
+{
+    static char sta_cli_buf[STA_BUF_SIZE] = "CLOSE";
+    char reply[STA_BUF_SIZE];
+    if(sta_cli_cmd_parse(sta_cli_buf, reply, STA_BUF_SIZE)){
+        if(strlen(reply) > 0)
+        {
+           LOGE("reply data(%s).\n",reply);
+        }
+        else
+        {
+           LOGE("No reply data(%s).\n",sta_cli_buf);
+           return LYNQ_ERR_FAIL;
+		}
+    }
+    else
+    {
+        LOGE("Parse cmd fail.\n");
+        return LYNQ_ERR_FAIL;
+    }
+
+    g_ap_status = LYNQ_WIFI_AP_STATUS_IDLE;
+    return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_work_mode_set(lynq_wifi_work_mode_e type)
+{
+    int ret = 0;
+     if(LYNQ_WIFI_WORK_MODE_AP0 == type)
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "hw_mode", "g");
+    }
+    else
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "hw_mode", "a");
+    }
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_work_mode_get(lynq_wifi_work_mode_e *type)
+{
+    int ret = 0;
+    char value[SETTING_VALUE_MAX_LEN] = {0};
+
+    if(NULL == type)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+    
+    ret = mbtk_wifi_get_setting(SETTING_FILE, "hw_mode", value, SETTING_VALUE_MAX_LEN);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    if('g' == value[0])
+    {
+        *type = LYNQ_WIFI_AP_INDEX_AP0;
+    }
+    else
+    {
+        *type = LYNQ_WIFI_AP_INDEX_AP1;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_get_status(lynq_wifi_ap_index_e idx, lynq_wifi_ap_status_t* ap_stat)
+{
+    if(NULL == ap_stat)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    int ret = mbtk_wifi_get_setting(SETTING_FILE, "ssid", ap_stat->bssid, SETTING_VALUE_MAX_LEN);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    ap_stat->status = g_ap_status;
+    memcpy(ap_stat->ifname, DEF_INTERFACE, strlen(DEF_INTERFACE));
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_acl_set(lynq_wifi_ap_index_e idx, lynq_wifi_mac_acl_rule_e acl_rule, char *mac_list)
+{
+    int ret = 0;
+    char path[PATH_MAX_LEN] = {0};
+    
+    if(NULL == mac_list)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    if(LYNQ_WIFI_MAC_ACL_RULE_WHITE_LIST == acl_rule)
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "macaddr_acl", "1");
+        memcpy(path, ACL_ACCEPT_FILE, strlen(ACL_ACCEPT_FILE));
+        
+    }
+    else if(LYNQ_WIFI_MAC_ACL_RULE_BLACK_LIST == acl_rule)
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "macaddr_acl", "0");
+        memcpy(path, ACL_DENY_FILE, strlen(ACL_DENY_FILE));
+    }
+    else
+    {
+        LOGE("qser_wifi_ap_acl_set LYNQ_WIFI_MAC_ACL_RULE_NONE");
+        return LYNQ_ERR_SUCCESS;
+    }
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    ret = mbtk_wifi_set_file(path, mac_list);
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_acl_get(lynq_wifi_ap_index_e idx, lynq_wifi_mac_acl_rule_e *acl_rule, char *mac_list)
+{
+    int ret = 0;
+    char value[SETTING_VALUE_MAX_LEN] = {0};
+    char path[PATH_MAX_LEN] = {0};
+
+    if(NULL == acl_rule || NULL == mac_list)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    ret = mbtk_wifi_get_setting(SETTING_FILE, "macaddr_acl", value, SETTING_LINE_MAX_LEN);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    if('1' == value[0])
+    {
+        *acl_rule = LYNQ_WIFI_MAC_ACL_RULE_WHITE_LIST;
+        memcpy(path, ACL_ACCEPT_FILE, strlen(ACL_ACCEPT_FILE));
+    }
+    else if('0' == value[0])
+    {
+        *acl_rule = LYNQ_WIFI_MAC_ACL_RULE_BLACK_LIST;
+        memcpy(path, ACL_DENY_FILE, strlen(ACL_DENY_FILE));
+    }
+    else
+    {
+        *acl_rule = LYNQ_WIFI_MAC_ACL_RULE_NONE;
+        LOGE("qser_wifi_ap_acl_get LYNQ_WIFI_MAC_ACL_RULE_NONE");
+        return LYNQ_ERR_SUCCESS;
+    }
+
+    ret = mbtk_wifi_get_file(path, mac_list, SETTING_LINE_MAX_LEN);
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_ssid_set(lynq_wifi_ap_index_e idx, const char *ssid)
+{
+    int ret = 0;
+     
+    if(NULL == ssid)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+     
+    ret = mbtk_wifi_set_setting(SETTING_FILE, "ssid", ssid);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_ssid_get(lynq_wifi_ap_index_e idx, char *ssid)
+{
+    int ret = 0;
+
+    if(NULL == ssid)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+    
+    ret = mbtk_wifi_get_setting(SETTING_FILE, "ssid", ssid, SETTING_VALUE_MAX_LEN);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_ssid_hide_set(lynq_wifi_ap_index_e idx,bool hide)
+{
+    int ret = 0;
+    if(true == hide)
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "ignore_broadcast_ssid", "0");
+    }
+    else
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "ignore_broadcast_ssid", "1");
+    }
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+    
+    return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_ssid_hide_get(lynq_wifi_ap_index_e idx,bool* hide)
+{
+    int ret = 0;
+    char value[SETTING_VALUE_MAX_LEN] = {0};
+
+    if(NULL == hide)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    ret = mbtk_wifi_get_setting(SETTING_FILE, "ignore_broadcast_ssid", value, SETTING_VALUE_MAX_LEN);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    if('0' == value[0])
+    {
+        *hide = true;
+    }
+    else
+    {
+        *hide = false;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_mode_set(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e mode)
+{
+    int ret = 0;
+    if(LYNQ_WIFI_MODE_80211B == mode)
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211b", "1");
+    }
+    else if(LYNQ_WIFI_MODE_80211BG == mode)
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211bg", "1");
+    }
+    else if(LYNQ_WIFI_MODE_80211BGN == mode)
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211bgn", "1");
+    }
+    else if(LYNQ_WIFI_MODE_80211A == mode)
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211a", "1");
+    }
+    else if(LYNQ_WIFI_MODE_80211AN == mode)
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211an", "1");
+    }
+    else if(LYNQ_WIFI_MODE_80211AC == mode)
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211ac", "1");
+    }
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_mode_get(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e* mode)
+{
+    int ret = 0;
+    char value[SETTING_VALUE_MAX_LEN] = {0};
+
+    if(NULL == mode)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    ret = mbtk_wifi_get_setting(SETTING_FILE, "ieee80211b", value, SETTING_VALUE_MAX_LEN);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    if('1' == value[0])
+    {
+        *mode = LYNQ_WIFI_MODE_80211B;
+    }
+
+    memset(value, 0, SETTING_VALUE_MAX_LEN);
+    ret = mbtk_wifi_get_setting(SETTING_FILE, "ieee80211bg", value, SETTING_VALUE_MAX_LEN);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    if('1' == value[0])
+    {
+        *mode = LYNQ_WIFI_MODE_80211BG;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_bandwidth_set(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e bandwidth)
+{
+    int ret = 0;
+    if(LYNQ_WIFI_BANDWIDTH_HT20 == bandwidth)
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "vht_oper_chwidth", "0");
+    }
+    else if(LYNQ_WIFI_BANDWIDTH_HT40 == bandwidth)
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "vht_oper_chwidth", "1");
+    }
+    else if(LYNQ_WIFI_BANDWIDTH_HT80 == bandwidth)
+    {
+        ret = mbtk_wifi_set_setting(SETTING_FILE, "vht_oper_chwidth", "2");
+    }
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+
+}
+
+int qser_wifi_ap_bandwidth_get(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e *bandwidth)
+{
+    int ret = 0;
+    char value[SETTING_VALUE_MAX_LEN] = {0};
+
+    if(NULL == bandwidth)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    ret = mbtk_wifi_get_setting(SETTING_FILE, "vht_oper_chwidth", value, SETTING_VALUE_MAX_LEN);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    if('0' == value[0])
+    {
+        *bandwidth = LYNQ_WIFI_BANDWIDTH_HT20;
+    }
+    else if ('1' == value[0])
+    {
+        *bandwidth = LYNQ_WIFI_BANDWIDTH_HT40;
+    }
+    else if ('2' == value[0])
+    {
+        *bandwidth = LYNQ_WIFI_BANDWIDTH_HT80;
+    }
+
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_channel_set(lynq_wifi_ap_index_e idx,const char* country_code, int channel)
+{
+    int ret = 0;
+    char value[SETTING_VALUE_MAX_LEN] = {0};
+
+    if(NULL == country_code)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    ret = mbtk_wifi_set_setting(SETTING_FILE, "country_code", country_code);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    sprintf(value, "%d", channel);
+    ret = mbtk_wifi_set_setting(SETTING_FILE, "channel", value);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_channel_get(lynq_wifi_ap_index_e idx,char* country_code, int* channel)
+{
+    int ret = 0;
+    char value[SETTING_VALUE_MAX_LEN] = {0};
+
+    if(NULL == country_code || NULL ==channel)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    ret = mbtk_wifi_get_setting(SETTING_FILE, "country_code", country_code, SETTING_VALUE_MAX_LEN);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    ret = mbtk_wifi_get_setting(SETTING_FILE, "channel", value, SETTING_VALUE_MAX_LEN);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+    
+    *channel = atoi(value);
+    return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_auth_set(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e auth_mode, const char * auth_passwd)
+{
+    int ret = 0;
+
+    if(NULL == auth_passwd)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    ret = mbtk_wifi_set_setting(SETTING_FILE, "wpa", "2");
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+    
+    ret = mbtk_wifi_set_setting(SETTING_FILE, "wpa_key_mgmt", "WPA-PSK");
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+    
+    ret = mbtk_wifi_set_setting(SETTING_FILE, "wpa_passphrase", auth_passwd);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+
+}
+
+int qser_wifi_ap_auth_get(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e *auth_mode, char * auth_passwd)
+{
+    int ret = 0;
+
+    if(NULL == auth_mode || NULL == auth_passwd)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    ret = mbtk_wifi_get_setting(SETTING_FILE, "wpa_passphrase", auth_passwd, SETTING_VALUE_MAX_LEN);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_auth_get_s(lynq_wifi_ap_index_e idx, lynq_wifi_ap_auth_t* auth_mode)
+{
+    int ret = 0;
+
+    if(NULL == auth_mode)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    ret = mbtk_wifi_get_setting(SETTING_FILE, "wpa_passphrase", auth_mode->passwd, SETTING_VALUE_MAX_LEN);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_max_sta_set(lynq_wifi_ap_index_e idx, int max_sta_num)
+{
+    int ret = 0;
+    char value[SETTING_VALUE_MAX_LEN] = {0};
+
+    sprintf(value, "%d", max_sta_num);
+    ret = mbtk_wifi_set_setting(SETTING_FILE, "max_num_sta", value);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_max_sta_get(lynq_wifi_ap_index_e idx, int* max_sta_num)
+{
+    int ret = 0;
+    char value[SETTING_VALUE_MAX_LEN] = {0};
+
+    if(NULL == max_sta_num)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    ret = mbtk_wifi_get_setting(SETTING_FILE, "max_num_sta", value, SETTING_VALUE_MAX_LEN);
+
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+    
+    *max_sta_num = atoi(value);
+
+    return LYNQ_ERR_SUCCESS;
+
+}
+
+
+
+int qser_wifi_lanhost_get_list(lynq_lanhost_ts* lynq_arrays)
+{
+    if(NULL == lynq_arrays)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    if(0 > mbtk_wifi_get_dhcp((mbtk_lanhost_ts*)lynq_arrays))
+    {
+        LOGE("qser wifi get lanhost fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+
+    if(0 > mbkt_wifi_get_uptime((mbtk_lanhost_ts*)lynq_arrays))
+    {
+        LOGE("qser wifi get lanhost fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_get_ap_pkt_stats(lynq_wifi_ap_index_e idx, lynq_wifi_pkt_stats_t *pkt_stat)
+{
+    if(NULL == pkt_stat)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    if(0 > mbtk_wifi_get_pkt((mbtk_wifi_pkt_stats_t*)pkt_stat))
+    {
+        LOGE("qser wifi get pkt fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_start(lynq_wifi_ap_index_e idx)
+{
+    int ret = 0;
+
+    if(LYNQ_WIFI_AP_INDEX_AP0 == idx)
+    {
+         ret = qser_wifi_work_mode_set(LYNQ_WIFI_AP_INDEX_AP0);
+    }
+    else
+    {
+        ret = qser_wifi_work_mode_set(LYNQ_WIFI_AP_INDEX_AP1);
+    }
+    LOGI("qser_wifi_ap_start set hw_mode ret:%d\n", ret);
+    if(0 > ret)
+    {
+        LOGE("qser wifi fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+   if(0 > mbtk_wifi_ap_start())
+    {
+        return LYNQ_ERR_FAIL;
+    }
+    
+
+     g_ap_status = LYNQ_WIFI_AP_STATUS_ENABLED;
+     return LYNQ_ERR_SUCCESS;   
+}
+
+int qser_wifi_ap_stop(lynq_wifi_ap_index_e idx)
+{
+    if(0 > mbtk_wifi_ap_stop())
+    {
+        return LYNQ_ERR_FAIL;
+    }
+
+    g_ap_status = LYNQ_WIFI_AP_STATUS_DISABLING;
+    return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_restart(lynq_wifi_ap_index_e idx)
+{
+    if(0 > mbtk_wifi_ap_stop())
+    {
+        return LYNQ_ERR_FAIL;
+    }
+
+    if(0 > mbtk_wifi_ap_start())
+    {
+        return LYNQ_ERR_FAIL;
+    }
+
+   return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_register_handle(lynq_wifi_event_handle event_handle, lynq_wifi_event_handle_sta event_handle_sta, void *arg)
+{
+    if(NULL != event_handle_sta)
+    {
+        g_event_handle_sta_cb = event_handle_sta;
+       
+    }
+    else
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+   
+    return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_sta_param_set(lynq_wifi_sta_param_t *param_stat)
+{
+    if(NULL == param_stat)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+    
+    sta_cli_ssid_set(param_stat->ssid);
+    sta_cli_psk_set(param_stat->passwd);
+    return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_sta_param_get(lynq_wifi_sta_param_t *param_stat)
+{
+    int len = 0;
+
+    if(NULL == param_stat)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+    
+    sta_cli_ssid_get(param_stat->ssid);
+    len = strlen(param_stat->ssid);
+    param_stat->ssid[len - 1] = '\0';
+    sta_cli_psk_get(param_stat->passwd);
+    len = strlen(param_stat->passwd);
+    param_stat->passwd[len - 1] = '\0';
+    
+    LOGE("ssid: %s, passwd: %s", param_stat->ssid, param_stat->passwd);
+    
+    return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_sta_start(void)
+{
+    char reply[STA_BUF_SIZE];
+
+    if(sta_cli_cmd_parse("ADD_NETWORK", reply, STA_BUF_SIZE))
+    {
+		if(strlen(reply) > 0)
+		{
+           LOGE("reply data(%s).\n",reply);
+		}else
+        {
+			LOGE("No reply data\n");
+		}
+    }
+    else
+    {
+        LOGE("Parse cmd fail.\n");
+    }
+
+
+    if(sta_cli_cmd_parse("SELECT_NETWORK", reply, STA_BUF_SIZE))
+    {
+		if(strlen(reply) > 0)
+		{
+           LOGE("reply data(%s).\n",reply);
+		}else
+        {
+			LOGE("No reply data\n");
+		}
+    }
+    else
+    {
+        LOGE("Parse cmd fail.\n");
+    }
+
+      if(sta_cli_cmd_parse("ENABLE_NETWORK", reply, STA_BUF_SIZE))
+    {
+		if(strlen(reply) > 0)
+		{
+           LOGE("reply data(%s).\n",reply);
+		}else
+        {
+			LOGE("No reply data\n");
+		}
+    }
+    else
+    {
+        LOGE("Parse cmd fail.\n");
+    }
+
+    if(0 > system("udhcpc -i wlan0"))
+    {
+        return LYNQ_ERR_FAIL;
+    }
+
+    
+    return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_sta_stop(void)
+{
+    char reply[STA_BUF_SIZE];
+
+    if(sta_cli_cmd_parse("DISABLE_NETWORK", reply, STA_BUF_SIZE))
+    {
+		if(strlen(reply) > 0)
+		{
+           LOGE("reply data(%s).\n",reply);
+		}else
+        {
+			LOGE("No reply data\n");
+		}
+    }
+    else
+    {
+        LOGE("Parse cmd fail.\n");
+    }
+
+      if(sta_cli_cmd_parse("REMOVE_NETWORK", reply, STA_BUF_SIZE))
+    {
+		if(strlen(reply) > 0)
+		{
+           LOGE("reply data(%s).\n",reply);
+		}else
+        {
+			LOGE("No reply data\n");
+		}
+    }
+    else
+    {
+        LOGE("Parse cmd fail.\n");
+    }
+    
+   return LYNQ_ERR_SUCCESS;
+}
+
+int  qser_wifi_sta_get_status(lynq_wifi_sta_status_t *status_stat)
+{
+    char reply[STA_BUF_SIZE];
+    int i = 0, j = 0;
+    int status_flag = 0;
+
+    if(NULL == status_stat)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+      if(sta_cli_cmd_parse("STATUS", reply, STA_BUF_SIZE))
+    {
+		if(strlen(reply) > 0)
+		{
+           LOGE("reply data(%s).\n",reply);
+		}else
+        {
+			LOGE("No reply data\n");
+		}
+    }
+    else
+    {
+        LOGE("Parse cmd fail.\n");
+    }
+
+    
+    for(i = 0; i < strlen(reply); i++)
+    {
+        if(',' == reply[i])
+        {
+            j = 0;
+            status_flag++;
+            continue;
+        }
+
+        if(0 == status_flag)
+        {
+            status_stat->status = 4;
+            j++;
+        }
+        else if(1 == status_flag)
+        {
+            status_stat->ap_bssid[j] = reply[i];
+            j++;
+        }
+        else if(2 == status_flag)
+        {
+            status_stat->ifname[j] = reply[i];
+            j++;
+        }
+        else if(8 == status_flag)
+        {
+            status_stat->has_addr = '1';
+            status_stat->addr[0].addr[j] = reply[i];
+            j++;
+        }
+      
+
+     
+    }
+    LOGE("state:%d, ap_bssid:%s, ifname:%s, has_addr:%c, addr:%s\n", status_stat->status, status_stat->ap_bssid, status_stat->ifname, status_stat->has_addr, 
+                status_stat->addr[0].addr);
+
+    return LYNQ_ERR_SUCCESS;
+    
+}
+
+
+int qser_wifi_get_sta_pkt_stats(lynq_wifi_pkt_stats_t *pkt_stat)
+{
+    if(NULL == pkt_stat)
+    {
+        LOGE("qser wifi ptr is null");
+        return LYNQ_ERR_BADPARAM;
+    }
+
+    if(0 > mbtk_wifi_get_pkt((mbtk_wifi_pkt_stats_t*)pkt_stat))
+    {
+        LOGE("qser wifi get pkt fail");
+        return LYNQ_ERR_FAIL;
+    }
+
+    return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_sta_start_scan(void)
+{
+    char reply[STA_BUF_SIZE] = {0};
+    lynq_wifi_sta_scan_list_t scan_list = {0};
+    int i = 0, j = 0;
+    int status_flag = 0;
+
+    if(sta_cli_cmd_parse("SCAN", reply, STA_BUF_SIZE))
+    {
+		if(strlen(reply) > 0)
+		{
+           LOGE("reply data(%s).\n",reply);
+		}else
+        {
+			LOGE("No reply data\n");
+		}
+    }
+    else
+    {
+        LOGE("Parse cmd fail.\n");
+    }
+
+
+
+    scan_list.cnt = 1;
+    
+    for(i = 0; i < strlen(reply); i++)
+    {
+        if(',' == reply[i])
+        {
+            j = 0;
+            status_flag++;
+            continue;
+        }
+
+        if(0 == status_flag)
+        {
+            scan_list.info[0].bssid[j] = reply[i];
+            j++;
+        }
+        else if(1 == status_flag)
+        {
+            //scan_list.info[0].bssid = reply[i];
+            j++;
+        }
+        else if(2 == status_flag)
+        {
+            //scan_list.info[0].signal = atoi(reply[i]);
+            j++;
+        }
+        else if(4 == status_flag)
+        {
+            scan_list.info[0].essid[j] = reply[i];
+            j++;
+        }
+      
+
+     
+    }
+
+
+    
+    g_event_handle_sta_cb(&scan_list);
+    return LYNQ_ERR_SUCCESS;
+}
+
+/*
+ void lynq_wifi_event_handle_demo(lynq_wifi_event_s *event, void *arg)
+ {
+    if(event->id == LYNQ_WIFI_EVENT_AP_STATION)
+        LOGE("[lynq-wifi-demo] %s:event-id = %d- %d\n", __func__, event->id, event->status);
+    else if(event->id == LYNQ_WIFI_EVENT_AP_STA_STATUS)
+        LOGE("[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)
+        LOGE("[lynq-wifi-demo] %s:event-id = %d- %d\n", __func__, event->id, event->status);
+    else
+    return;
+ }
+ */
+ 
+ void lynq_wifi_event_handle_sta_demo(lynq_wifi_sta_scan_list_t *event)
+ {
+     int i = 0;
+     if(NULL == event)
+    {
+        LOGE("qser wifi ptr is null");
+        return;
+    }
+
+     for (i = 0; i < event->cnt; i++)
+     {
+         LOGE("[lynq-wifi-demo] %s : ap[%d]:%s,%d,%d,%d,%s,%d,%d,%d\n", __func__, i,
+         event->info[i].essid, event->info[i].auth,
+         event->info[i].cipher, event->info[i].channel, event->info[i].bssid,
+         event->info[i].signal_level,event->info[i].frequency,event->info[i].signal);
+     }
+ }
+
+
+
+
