blob: 8ea68352c79f0933b16280d3a78df3f4f0fa2a60 [file] [log] [blame]
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "liblog/lynq_deflog.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "sc_tel_types.h"
#include "sc_wifi.h"
#include "lynq-qser-wifi.h"
static lynq_wifi_event_handle wifi_event_handle = NULL;
static lynq_wifi_event_handle_sta wifi_event_handle_sta = NULL;
static void *global_arg = NULL;
static lynq_wifi_event_s global_event;
/********************************************************************
* @brief: lynq_to_sc_auth_mode, The encryption mode of wifi is changed from api to platform
* @return :sc_wifi_auth_e, all
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
static sc_wifi_auth_e lynq_to_sc_auth_mode(lynq_wifi_auth_e auth_mode)
{
sc_wifi_auth_e type;
switch (auth_mode)
{
case LYNQ_WIFI_AUTH_OPEN:
type = SC_WIFI_AUTH_OPEN;
break;
case LYNQ_WIFI_AUTH_WPA2_PSK:
type = SC_WIFI_AUTH_WPA2_PSK;
break;
case LYNQ_WIFI_AUTH_WPA_WPA2_PSK_BOTH:
type = SC_WIFI_AUTH_WPA_WPA2_PSK_BOTH;
break;
case LYNQ_WIFI_AUTH_WPA3_PSK:
type = SC_WIFI_AUTH_WPA3_PSK;
break;
case LYNQ_WIFI_AUTH_WPA2_WPA3_PSK_BOTH:
type = SC_WIFI_AUTH_WPA2_WPA3_PSK_BOTH;
break;
default:
type = SC_WIFI_AUTH_MIN;
break;
}
return type;
}
/********************************************************************
* @brief: sc_to_lynq_auth_mode, The wifi protocol moves from platform to api
* @return :lynq_wifi_auth_e, all
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
static lynq_wifi_auth_e sc_to_lynq_auth_mode(sc_wifi_auth_e auth_mode)
{
lynq_wifi_auth_e type;
switch (auth_mode)
{
case SC_WIFI_AUTH_OPEN:
type = LYNQ_WIFI_AUTH_OPEN;
break;
case SC_WIFI_AUTH_WPA2_PSK:
type = LYNQ_WIFI_AUTH_WPA2_PSK;
break;
case SC_WIFI_AUTH_WPA_WPA2_PSK_BOTH:
type = LYNQ_WIFI_AUTH_WPA_WPA2_PSK_BOTH;
break;
case SC_WIFI_AUTH_WPA3_PSK:
type = LYNQ_WIFI_AUTH_WPA3_PSK;
break;
case SC_WIFI_AUTH_WPA2_WPA3_PSK_BOTH:
type = LYNQ_WIFI_AUTH_WPA2_WPA3_PSK_BOTH;
break;
default:
type = LYNQ_WIFI_AUTH_MIN;
break;
}
return type;
}
/********************************************************************
* @brief: lynq_to_sc_mode, The wifi protocol is transferred from api to platform
* @return :sc_wifi_ap_mode_type_e, all
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
static sc_wifi_ap_mode_type_e lynq_to_sc_mode(lynq_wifi_mode_type_e mode)
{
sc_wifi_ap_mode_type_e type;
switch (mode)
{
case LYNQ_WIFI_MODE_80211BGN:
type = SC_WIFI_AP_MODE_80211BGN;
break;
case LYNQ_WIFI_MODE_80211BGNAX_2G:
type = SC_WIFI_AP_MODE_80211BGNAX_2G;
break;
case LYNQ_WIFI_MODE_80211AN:
type = SC_WIFI_AP_MODE_80211AN;
break;
case LYNQ_WIFI_MODE_80211ANAC:
type = SC_WIFI_AP_MODE_80211ANAC;
break;
case LYNQ_WIFI_MODE_80211ANACAX_5G:
type = SC_WIFI_AP_MODE_80211ANACAX_5G;
break;
default:
type = SC_WIFI_AP_MODE_MIN;
break;
}
return type;
}
/********************************************************************
* @brief: sc_to_lynq_mode, The encryption mode of wifi is changed from platform to api
* @return :lynq_wifi_mode_type_e, all
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
static lynq_wifi_mode_type_e sc_to_lynq_mode(sc_wifi_ap_mode_type_e mode)
{
lynq_wifi_mode_type_e type;
switch (mode)
{
case SC_WIFI_AP_MODE_80211BGN:
type = LYNQ_WIFI_MODE_80211BGN;
break;
case SC_WIFI_AP_MODE_80211BGNAX_2G:
type = LYNQ_WIFI_MODE_80211BGNAX_2G;
break;
case SC_WIFI_AP_MODE_80211AN:
type = LYNQ_WIFI_MODE_80211AN;
break;
case SC_WIFI_AP_MODE_80211ANAC:
type = LYNQ_WIFI_MODE_80211ANAC;
break;
case SC_WIFI_AP_MODE_80211ANACAX_5G:
type = LYNQ_WIFI_MODE_80211ANACAX_5G;
break;
default:
type = LYNQ_WIFI_MODE_MIN;
break;
}
return type;
}
/********************************************************************
* @brief: lynq_user_status, wifi startup callback
* @return : NA
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
static void lynq_user_status(sc_wifi_enable_status_e pre_status, sc_wifi_enable_status_e status)
{
LYINFLOG("%s:%d,%d\n", __func__, pre_status, status);
}
/********************************************************************
* @brief: lynq_user_wifi_service_error, wifi service status callback
* @return : NA
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
static void lynq_user_wifi_service_error(int error)
{
LYINFLOG("%s: %d\n", __func__, error);
}
/********************************************************************
* @brief: lynq_user_ap_status, wifi Obtains the ap status callback
* @return : NA
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
static void lynq_user_ap_status(sc_wifi_ap_index_e index, sc_wifi_ap_status_e pre_status, sc_wifi_ap_status_t *p_msg)
{
if(wifi_event_handle != NULL && global_arg != NULL)
{
global_event.idx = (lynq_wifi_ap_index_e)index;
global_event.status = (lynq_wifi_status_e)pre_status;
wifi_event_handle(&global_event, global_arg);
}
else{
LYINFLOG("%s:%d,%d,%s,%d\n", __func__, index, pre_status, p_msg->ifname, p_msg->status);
}
}
/********************************************************************
* @brief: lynq_user_ap_sta_conn_status, wifi as ap is sta information callback
* @return : NA
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
static void lynq_user_ap_sta_conn_status(sc_wifi_ap_index_e index, sc_wifi_sta_connect_status_t *p_msg)
{
if(wifi_event_handle != NULL && global_arg != NULL)
{
global_event.idx = (lynq_wifi_ap_index_e)index;
global_event.ap_sta_info.connected = p_msg->is_connected;
strncpy(global_event.ap_sta_info.mac, p_msg->macaddr,
sizeof(global_event.ap_sta_info.mac) <= sizeof(p_msg->macaddr) ? sizeof(global_event.ap_sta_info.mac):sizeof(p_msg->macaddr));
wifi_event_handle(&global_event, global_arg);
}
else{
LYINFLOG("%s:%d,%d,%s\n", __func__, index, p_msg->is_connected, p_msg->macaddr);
}
}
/********************************************************************
* @brief: print_sta_status, wifi gets the status callback in sta mode
* @return : NA
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
static void print_sta_status(sc_wifi_sta_status_t *p_msg)
{
LYINFLOG("%s: %d, %s, %s, %d, %d\n", __func__, p_msg->status, p_msg->ifname, p_msg->ap_bssid,
p_msg->signal_level, p_msg->reason_code);
if (p_msg->has_addr == 1) {
char addrtxt[48] = {0};
inet_ntop(AF_INET, &p_msg->addr, addrtxt, sizeof(addrtxt));
LYINFLOG("%s : addr inet_ntop: %s\n", __func__, addrtxt);
LYINFLOG("%s : addr: %08X\n", __func__, p_msg->addr.s_addr);
}
if (p_msg->has_addr6 == 1) {
char addrtxt[48] = {0};
inet_ntop(AF_INET6, &p_msg->addr6, addrtxt, sizeof(addrtxt));
LYINFLOG("%s : addr6 inet_ntop: %s\n", __func__, addrtxt);
LYINFLOG("%s : addr6: %02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X\n",__func__,
p_msg->addr6.s6_addr[0], p_msg->addr6.s6_addr[1], p_msg->addr6.s6_addr[2], p_msg->addr6.s6_addr[3],
p_msg->addr6.s6_addr[4], p_msg->addr6.s6_addr[5], p_msg->addr6.s6_addr[6], p_msg->addr6.s6_addr[7],
p_msg->addr6.s6_addr[8], p_msg->addr6.s6_addr[9], p_msg->addr6.s6_addr[10], p_msg->addr6.s6_addr[11],
p_msg->addr6.s6_addr[12], p_msg->addr6.s6_addr[13], p_msg->addr6.s6_addr[14], p_msg->addr6.s6_addr[15]);
}
LYINFLOG("%s : sta_status end\n",__func__);
}
/********************************************************************
* @brief: lynq_user_sta_status_ind, wifi gets the status callback in sta mode
* @return : NA
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
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);
}
/********************************************************************
* @brief: lynq_user_sta_scan_result_ind, wifi gets the callback of sta mode traversing the hotspot
* @return : NA
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
static void lynq_user_sta_scan_result_ind(sc_wifi_sta_scan_list_t *p_msg)
{
int i = 0;
LYINFLOG("%s : user_sta_scan_result_ind_cb:%d\n", __func__, p_msg->cnt);
if (p_msg->cnt <= 0)
{
return;
}
if (wifi_event_handle_sta != NULL)
{
lynq_wifi_sta_scan_list_t event;
event.cnt = p_msg->cnt;
for (i = 0; i < event.cnt; i++)
{
strncpy(event.info[i].essid, p_msg->info[i].essid, sizeof(p_msg->info[i].essid));
strncpy(event.info[i].bssid, p_msg->info[i].bssid, sizeof(p_msg->info[i].bssid));
event.info[i].auth = sc_to_lynq_auth_mode(p_msg->info[i].auth);
event.info[i].cipher = (lynq_wifi_auth_wpa_psk_e)p_msg->info[i].cipher;
event.info[i].channel = p_msg->info[i].channel;
event.info[i].signal_level = p_msg->info[i].signal_level;
}
wifi_event_handle_sta(&event);
}
else
{
for (i = 0; i < p_msg->cnt; i++)
{
LYINFLOG("%s : ap[%d]:%s,%d,%d,%d,%s,%d\n", __func__, i, p_msg->info[i].essid, sc_to_lynq_auth_mode(p_msg->info[i].auth),
p_msg->info[i].cipher, p_msg->info[i].channel, p_msg->info[i].bssid, p_msg->info[i].signal_level);
}
}
}
/********************************************************************
* @brief: qser_wifi_work_mode_set, 2.4g or 5g working mode Settings
* @param type [IN]: lynq_wifi_work_mode_e, 2.4G or 5G working mode Settings
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_work_mode_set(lynq_wifi_work_mode_e type)
{
int ret = -1;
ret = sc_wifi_work_mode_set((sc_wifi_work_mode_e)type);
if (0 != ret)
{
LYERRLOG("[%s ] work_mode ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ]\n", __func__);
return 0;
}
/********************************************************************
* @brief: qser_wifi_register_handle, Register callback functions
* @param event_handle [IN]: lynq_wifi_event_handle, Register the ap event callback function
* @param event_handle_sta [IN]: Register sta's event callback function
* @param arg [IN]: void *, Not currently used, but cannot pass a null pointer
* @return :int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_register_handle(lynq_wifi_event_handle event_handle, lynq_wifi_event_handle_sta event_handle_sta, void *arg)
{
if((event_handle == NULL && event_handle_sta == NULL) || arg == NULL)
{
LYERRLOG("[%s ] NUll pointer event_handle = 0x%p arg = 0x%p\n", __func__, event_handle, arg);
return -1;
}
wifi_event_handle_sta = event_handle_sta;
wifi_event_handle = event_handle;
global_arg = arg;
return 0;
}
/********************************************************************
* @brief: qser_wifi_enable, Enable WiFi function
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_enable(void)
{
int ret = -1;
ret = sc_wifi_init();
if (0 != ret)
{
LYERRLOG("[%s ] init wifi ret = %d fail\n", __func__,ret);
return ret;
}
//wifi
ret = sc_wifi_set_enable_status_ind_cb(lynq_user_status);
if (0 != ret)
{
LYERRLOG("[%s ] Request lynq_user_status ret = %d fail\n", __func__,ret);
return ret;
}
//ap
ret = sc_wifi_ap_set_status_ind_cb(lynq_user_ap_status);
if (0 != ret)
{
LYERRLOG("[%s ] Request lynq_user_ap_status ret = %d fail\n", __func__,ret);
return ret;
}
ret = sc_wifi_set_ap_sta_connect_ind_cb(lynq_user_ap_sta_conn_status);
if (0 != ret)
{
LYERRLOG("[%s ] Request lynq_user_ap_sta_conn_status ret = %d fail\n", __func__,ret);
return ret;
}
//sta
ret = sc_wifi_sta_set_status_ind_cb(lynq_user_sta_status_ind);
if (0 != ret)
{
LYERRLOG("[%s ] Request lynq_user_sta_status_ind ret = %d fail\n", __func__,ret);
return ret;
}
ret = sc_wifi_sta_set_scan_result_ind_cb(lynq_user_sta_scan_result_ind);
if (0 != ret)
{
LYERRLOG("[%s ] Request lynq_user_sta_scan_result_ind ret = %d fail\n", __func__,ret);
return ret;
}
//proxy
ret = sc_wifi_set_service_error_cb(lynq_user_wifi_service_error);
if (0 != ret)
{
LYERRLOG("[%s ] Request lynq_user_wifi_service_error ret = %d fail\n", __func__,ret);
return ret;
}
ret = sc_wifi_enable();
if (0 != ret)
{
LYERRLOG("[%s ] enable wifi ret = %d fail\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ]\n", __func__);
return 0;
}
/********************************************************************
* @brief: qser_wifi_disable, Turn off WiFi
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_disable(void)
{
int ret = -1;
ret = sc_wifi_disable();
if (0 != ret)
{
LYERRLOG("[%s ] disable ret = %d\n", __func__,ret);
return ret;
}
ret = sc_wifi_uninit();
if (0 != ret)
{
LYERRLOG("[%s ] uninit ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ]\n", __func__);
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_ssid_set, Set the name of the ssid of 2.4G or 5G
* @param idx [IN]: int, Set 2.4G or 5G
* @param ssid [IN]: const char *, Set the ssid name
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_ssid_set(lynq_wifi_ap_index_e idx, const char *ssid)
{
int ret = -1;
if (ssid == NULL)
{
LYERRLOG("[%s ] Null pointer ssid = 0x%p \n", __func__, ssid);
return ret;
}
ret = sc_wifi_ap_ssid_set((sc_wifi_ap_index_e)idx, ssid);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d ssid = %s \n", __func__, idx, ssid);
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_ssid_get, Get the name of the ssid of 2.4G or 5G
* @param idx [IN]: int, Set 2.4G or 5G
* @param ssid [OUT]: char *, Get the ssid name
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_ssid_get(lynq_wifi_ap_index_e idx, char *ssid)
{
int ret = -1;
sc_wifi_ap_param_t param = {0};
ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d ssid = %s \n", __func__, idx, param.ssid);
strncpy(ssid, param.ssid, sizeof(param.ssid) - 1);
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_ssid_hide_set, Set whether the ssid of 2.4G or 5G is hidden
* @param idx [IN]: int, Set 2.4G or 5G
* @param hide [IN]: bool, Set whether the ssid is hidden
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_ssid_hide_set(lynq_wifi_ap_index_e idx, bool hide)
{
int ret = -1;
ret = sc_wifi_ap_ssid_hidden_set((sc_wifi_ap_index_e)idx, (int)hide);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d hide = %d \n", __func__, idx, hide);
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_ssid_hide_get, Get whether the ssid of 2.4G or 5G is hidden
* @param idx [IN]: int, Set 2.4G or 5G
* @param hide [OUT]: bool *, Get whether the ssid is hidden
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_ssid_hide_get(lynq_wifi_ap_index_e idx, bool *hide)
{
int ret = -1;
sc_wifi_ap_param_t param = {0};
if (hide == NULL)
{
LYERRLOG("[%s ] Null pointer hide = 0x%p \n", __func__, hide);
return ret;
}
ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d ssid_hide = %d \n", __func__, idx, param.ssid_hide);
*hide = (bool)param.ssid_hide;
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_mode_set, Set the working protocol mode of 2.4G or 5G
* @param idx [IN]: int, Set 2.4G or 5G
* @param mode [IN]: lynq_wifi_mode_type_e, Set the working protocol mode
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_mode_set(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e mode)
{
int ret = -1;
ret = sc_wifi_ap_mode_set((sc_wifi_ap_index_e)idx, lynq_to_sc_mode(mode));
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d mode = %d \n", __func__, idx, mode);
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_mode_get, Get the working protocol mode of 2.4G or 5G
* @param idx [IN]: int, Set 2.4G or 5G
* @param mode [OUT]: lynq_wifi_mode_type_e *, Get the working protocol mode
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_mode_get(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e *mode)
{
int ret = -1;
sc_wifi_ap_param_t param = {0};
if (mode == NULL)
{
LYERRLOG("[%s ] Null pointer mode = 0x%p \n", __func__, mode);
return ret;
}
ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d mode = %d \n", __func__, idx, param.mode);
*mode = sc_to_lynq_mode(param.mode);
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_bandwidth_set, Set the bandwidth of 2.4G or 5G
* @param idx [IN]: int, Set 2.4G or 5G
* @param bandwidth [IN]: lynq_wifi_bandwidth_type_e, Set the bandwidth
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_bandwidth_set(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e bandwidth)
{
int ret = -1;
ret = sc_wifi_ap_bandwidth_set((sc_wifi_ap_index_e)idx, (sc_wifi_bandwidth_e)bandwidth);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d bandwidth = %d \n", __func__, idx, bandwidth);
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_bandwidth_get, Get the bandwidth of 2.4G or 5G
* @param idx [IN]: int, Set 2.4G or 5G
* @param bandwidth [OUT]: lynq_wifi_bandwidth_type_e *, Get the bandwidth
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_bandwidth_get(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e *bandwidth)
{
int ret = -1;
sc_wifi_ap_param_t param = {0};
if (bandwidth == NULL)
{
LYERRLOG("[%s ] Null pointer bandwidth = 0x%p \n", __func__, bandwidth);
return ret;
}
ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d bandwidth = %d \n", __func__, idx, param.bandwidth);
*bandwidth = (lynq_wifi_bandwidth_type_e)param.bandwidth;
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_channel_set, Set the channel for 2.4G or 5G
* @param idx [IN]: int, Set 2.4G or 5G
* @param country_code [IN]: const char *, Set country code
* @param channel [IN]: int, Set the channel
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_channel_set(lynq_wifi_ap_index_e idx, const char *country_code, int channel)
{
int ret = -1;
if (country_code == NULL)
{
LYERRLOG("[%s ] Null pointer country_code = 0x%p \n", __func__, country_code);
return ret;
}
ret = sc_wifi_ap_cc_ch_set((sc_wifi_ap_index_e)idx, country_code, channel);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d country_code = %s channel = %d\n", __func__, idx, country_code, channel);
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_channel_get, Get the channel for 2.4G or 5G
* @param idx [IN]: int, Set 2.4G or 5G
* @param country_code [OUT]: char *, Get country code
* @param channel [OUT]: int *, Get the channel
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_channel_get(lynq_wifi_ap_index_e idx, char *country_code, int *channel)
{
int ret = -1;
sc_wifi_ap_param_t param = {0};
if (country_code == NULL || channel == NULL)
{
LYERRLOG("[%s ] Null pointer country_code = 0x%p channel = 0x%p\n", __func__, country_code, channel);
return ret;
}
ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d country_code = %s channel = %d\n", __func__, idx, param.countrycode, param.channel);
strncpy(country_code, param.countrycode, sizeof(param.countrycode) - 1);
*channel = param.channel;
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_auth_set, Set the security authentication mode and password of 2.4G or 5G
* @param idx [IN]: int, Set 2.4G or 5G
* @param auth_mode [IN]: lynq_wifi_auth_e, Set the security authentication mode
* @param auth_passwd [IN]: const char *, Set password
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_auth_set(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e auth_mode, const char *auth_passwd)
{
int ret = -1;
if (auth_passwd == NULL)
{
LYERRLOG("[%s ] Null pointer auth_passwd = 0x%p\n", __func__, auth_passwd);
return ret;
}
sc_wifi_ap_auth_t auth;
auth.auth = lynq_to_sc_auth_mode(auth_mode);
strncpy(auth.passwd, auth_passwd, sizeof(auth.passwd) - 1);
ret = sc_wifi_ap_auth_set((sc_wifi_ap_index_e)idx, &auth);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d auth_mode = %d auth_passwd = %s\n", __func__, idx, auth_mode, "******");
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_auth_get, Get the security authentication mode and password of 2.4G or 5G
* @param idx [IN]: int, Set 2.4G or 5G
* @param auth_mode [OUT]: lynq_wifi_auth_e *, Get the security authentication mode
* @param auth_passwd [OUT]: char *, Get password
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_auth_get(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e *auth_mode, char *auth_passwd)
{
int ret = -1;
sc_wifi_ap_param_t param = {0};
if (auth_mode == NULL || auth_passwd == NULL)
{
LYERRLOG("[%s ] Null pointer auth_mode = 0x%p auth_passwd = 0x%p\n", __func__, auth_mode, auth_passwd);
return ret;
}
ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d auth_mode = %d auth_passwd = %s \n", __func__, idx, param.auth.auth, param.auth.passwd);
strncpy(auth_passwd, param.auth.passwd, sizeof(param.auth.passwd) - 1);
*auth_mode = sc_to_lynq_auth_mode(param.auth.auth);
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_max_sta_set, Set the maximum number of STAs for 2.4G or 5G
* @param idx [IN]: int, Set 2.4G or 5G
* @param max_sta_num [IN]: int, Set the maximum number
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_max_sta_set(lynq_wifi_ap_index_e idx, int max_sta_num)
{
int ret = -1;
ret = sc_wifi_ap_max_sta_num_set((sc_wifi_ap_index_e)idx, max_sta_num);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d max_sta_num = %d \n", __func__, idx, max_sta_num);
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_max_sta_get, Get the maximum number of STAs for 2.4G or 5G
* @param idx [IN]: int, Set 2.4G or 5G
* @param max_sta_num [OUT]: int *, Get the maximum number
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_max_sta_get(lynq_wifi_ap_index_e idx, int *max_sta_num)
{
int ret = -1;
sc_wifi_ap_param_t param = {0};
if (max_sta_num == NULL)
{
LYERRLOG("[%s ] Null pointer max_sta_num = 0x%p\n", __func__,max_sta_num);
return ret;
}
ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d max_sta_num = %d \n", __func__, idx, param.max_sta_num);
*max_sta_num = param.max_sta_num;
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_start, Set the ap mode of 2.4G or 5G to enable
* @param idx [IN]: int, Set 2.4G or 5G
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_start(lynq_wifi_ap_index_e idx)
{
int ret = -1;
ret = sc_wifi_ap_start((sc_wifi_ap_index_e)idx);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d \n", __func__, idx);
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_stop, Disable ap mode for 2.4G or 5G
* @param idx [IN]: int, Set 2.4G or 5G
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_stop(lynq_wifi_ap_index_e idx)
{
int ret = -1;
ret = sc_wifi_ap_stop((sc_wifi_ap_index_e)idx);
if (0 != ret)
{
LYERRLOG("[%s ] ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d \n", __func__, idx);
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_restart, Set the ap mode of 2.4G or 5G to restart
* @param idx [IN]: int, Set 2.4G or 5G
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_ap_restart(lynq_wifi_ap_index_e idx)
{
int ret = -1;
ret = sc_wifi_ap_stop((sc_wifi_ap_index_e)idx);
if (0 != ret)
{
LYERRLOG("[%s ] stop ret = %d\n", __func__,ret);
return ret;
}
ret = sc_wifi_ap_start((sc_wifi_ap_index_e)idx);
if (0 != ret)
{
LYERRLOG("[%s ] start ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d \n", __func__, idx);
return 0;
}
/********************************************************************
* @brief: qser_wifi_sta_param_set, Set the ssid and password that you need to connect to the access point
* @param lynq_stat [IN]: sc_wifi_sta_param_t *, Set parameters such as ssid and password that you want to connect to the access point
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_sta_param_set(lynq_wifi_sta_param_t *lynq_stat)
{
int ret = -1;
sc_wifi_sta_param_t stat = {0};
stat.auth = lynq_to_sc_auth_mode(lynq_stat->auth);
stat.pairwise = (sc_wifi_auth_wpa_psk_e )lynq_stat->pairwise;
strncpy(stat.ssid, lynq_stat->ssid, sizeof(stat.ssid));
strncpy(stat.passwd, lynq_stat->passwd, sizeof(stat.passwd));
ret = sc_wifi_sta_param_set(&stat);
if (0 != ret)
{
LYERRLOG("[%s ] sta_param_set ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] ret = %d \n", __func__, ret);
return 0;
}
/********************************************************************
* @brief: qser_wifi_sta_param_get, Get the ssid and password that you need to connect to the access point
* @param lynq_stat [OUT]: sc_wifi_sta_param_t *, Get parameters such as ssid and password that you want to connect to the access point
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_sta_param_get(lynq_wifi_sta_param_t *lynq_stat)
{
int ret = -1;
sc_wifi_sta_param_t stat = {0};
ret = sc_wifi_sta_param_get(&stat);
if (0 != ret)
{
LYERRLOG("[%s ] sta_param_get ret = %d\n", __func__,ret);
return ret;
}
lynq_stat->auth = sc_to_lynq_auth_mode(stat.auth);
lynq_stat->pairwise = (lynq_wifi_auth_wpa_psk_e )stat.pairwise;
strncpy(lynq_stat->ssid, stat.ssid, sizeof(stat.ssid));
strncpy(lynq_stat->passwd, stat.passwd, sizeof(stat.passwd));
LYINFLOG("[%s ] ret = %d \n", __func__, ret);
return 0;
}
/********************************************************************
* @brief: qser_wifi_sta_start_scan, Scan for ap nodes and return them through callback
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_sta_start_scan(void)
{
int ret = -1;
ret = sc_wifi_sta_start_scan();
if (0 != ret)
{
LYERRLOG("[%s ] scan ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] ret = %d \n", __func__, ret);
return 0;
}
/********************************************************************
* @brief: qser_wifi_sta_start, To enable sta mode, you need to enable ap mode first
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_sta_start(void)
{
int ret = -1;
ret = sc_wifi_sta_start();
if (0 != ret)
{
LYERRLOG("[%s ] sta_start ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] ret = %d \n", __func__, ret);
return 0;
}
/********************************************************************
* @brief: qser_wifi_sta_stop, To disable sta mode.
* @return : int, If equal to 0 succeeds, others fail
* @todo: NA
* @see: NA
* @warning: NA
*********************************************************************/
int qser_wifi_sta_stop(void)
{
int ret = -1;
ret = sc_wifi_sta_stop();
if (0 != ret)
{
LYERRLOG("[%s ] sta_stop ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] ret = %d \n", __func__, ret);
return 0;
}
DEFINE_LYNQ_LIB_LOG(LYNQ_WIFI)
#ifdef __cplusplus
}
#endif