blob: 91f1112891a080275641f7bd38c0e1b89f619c56 [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"
/********************************************************************
* @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 : %d ret = %d\n", __func__,ret);
return ret;
}
ret = sc_wifi_enable();
if (0 != ret)
{
LYERRLOG("[%s ] enable : %d ret = %d\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 : %d ret = %d\n", __func__,ret);
return ret;
}
ret = sc_wifi_uninit();
if (0 != ret)
{
LYERRLOG("[%s ] uninit: %d 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 wlan0 or wlan1
* @param idx [IN]: int, Set wlan0 or wlan1
* @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 wlan0 or wlan1
* @param idx [IN]: int, Set wlan0 or wlan1
* @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_mode_set, Set the working protocol mode of wlan0 or wlan1
* @param idx [IN]: int, Set wlan0 or wlan1
* @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;
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;
default:
type = SC_WIFI_AP_MODE_MIN;
break;
}
ret = sc_wifi_ap_mode_set((sc_wifi_ap_index_e)idx, type);
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 wlan0 or wlan1
* @param idx [IN]: int, Set wlan0 or wlan1
* @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);
lynq_wifi_mode_type_e type;
switch(param.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;
default:
type = LYNQ_WIFI_MODE_MIN;
break;
}
*mode = type;
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_bandwidth_set, Set the bandwidth of wlan0 or wlan1
* @param idx [IN]: int, Set wlan0 or wlan1
* @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 wlan0 or wlan1
* @param idx [IN]: int, Set wlan0 or wlan1
* @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 wlan0 or wlan1
* @param idx [IN]: int, Set wlan0 or wlan1
* @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 wlan0 or wlan1
* @param idx [IN]: int, Set wlan0 or wlan1
* @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 wlan0 or wlan1
* @param idx [IN]: int, Set wlan0 or wlan1
* @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;
sc_wifi_auth_e type;
if (auth_passwd == NULL)
{
LYERRLOG("[%s ] Null pointer auth_passwd = 0x%p\n", __func__, auth_passwd);
return ret;
}
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;
}
sc_wifi_ap_auth_t auth;
auth.auth = (sc_wifi_auth_e)type;
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, auth_passwd);
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_auth_get, Get the security authentication mode and password of wlan0 or wlan1
* @param idx [IN]: int, Set wlan0 or wlan1
* @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);
lynq_wifi_auth_e type;
switch (param.auth.auth)
{
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;
}
*auth_mode = type;
return 0;
}
/********************************************************************
* @brief: qser_wifi_ap_max_sta_set, Set the maximum number of STAs for wlan0 or wlan1
* @param idx [IN]: int, Set wlan0 or wlan1
* @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 wlan0 or wlan1
* @param idx [IN]: int, Set wlan0 or wlan1
* @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 wlan0 or wlan1 to enable
* @param idx [IN]: int, Set wlan0 or wlan1
* @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 wlan0 or wlan1
* @param idx [IN]: int, Set wlan0 or wlan1
* @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 wlan0 or wlan1 to restart
* @param idx [IN]: int, Set wlan0 or wlan1
* @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: %d ret = %d\n", __func__,ret);
return ret;
}
ret = sc_wifi_ap_start((sc_wifi_ap_index_e)idx);
if (0 != ret)
{
LYERRLOG("[%s ] start: %d ret = %d\n", __func__,ret);
return ret;
}
LYINFLOG("[%s ] idx = %d \n", __func__, idx);
return 0;
}
DEFINE_LYNQ_LIB_LOG(LYNQ_WIFI)
#ifdef __cplusplus
}
#endif