blob: a2b08b7f72af3a9e4ee29e9d9c3c606b795b5ca4 [file] [log] [blame]
#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);
}
}