blob: 110f5c03e0ddbbb71e02ea031a3957116cf9c795 [file] [log] [blame]
/**
* @file : gsw_wifi_interface_sdk.h
* @brief : wifi abstract_sdk
* @date : 2022-08-14
* @author : zhaohua
* @version : v1.0
* @copyright Copyright (c) 2022 www.gosuncn.com
*/
#ifndef __GSW_WIFI_INTERFACE_SDK_H__
#define __GSW_WIFI_INTERFACE_SDK_H__
#include "gsw_hal_errcode.h"
#define GSW_WIFI_AP_DEVICE_NUM 8 /**< ap device max num */
#define GSW_WIFI_STA_REMEMBER_HOST_NUM 50 /**< sta save ap max num */
#define GSW_WIFI_STA_SCANLIST_NUM 100 /**< sta scan list max num */
/**
* @brief ap callback event type
*/
typedef enum {
GSW_WIFI_STATUS_DISCONNECT = 0, /**< sta disconnect */
GSW_WIFI_STATUS_CONNECT, /**< sta connect */
} gsw_wifi_ap_status_e;
/**
* @brief sta callback event type
*/
typedef enum {
GSW_WIFI_STA_STATUS_DISCONNECT = 0, /**< sta disconnect */
GSW_WIFI_STA_STATUS_CONNECT, /**< sta connect */
GSW_WIFI_STA_STATUS_SCAN_RESULT, /**< sta scan finish */
} gsw_wifi_sta_status_e;
/**
* @brief wifi ability type
*/
typedef enum {
WIFI_MODE_ABILITY_NOWLAN = 1, /**< no wlan */
WIFI_MODE_ABILITY_STA_ONLY = 2, /**< sta only */
WIFI_MODE_ABILITY_AP_ONLY = 3, /**< ap only */
WIFI_MODE_ABILITY_APANDSTA = 4, /**< ap and sta */
} wifi_mode_ability_e;
/**
* @brief ap bandwidth type
*/
typedef enum {
GSW_WIFI_BANDWIDTH_HT10 = 0, /**< 10Mhz */
GSW_WIFI_BANDWIDTH_HT20, /**< 20Mhz */
GSW_WIFI_BANDWIDTH_HT40, /**< 40Mhz */
GSW_WIFI_BANDWIDTH_HT80, /**< 80Mhz */
} gsw_wifi_bandwidth_type_e;
/**
* @brief authentication type
*/
typedef enum {
GSW_WIFI_AUTH_OPEN = 0, /**< OPEN */
GSW_WIFI_AUTH_WEP, /**< WEP */
GSW_WIFI_AUTH_WPA_PSK, /**< WPA_PSK */
GSW_WIFI_AUTH_WPA2_PSK, /**< WPA2_PSK */
GSW_WIFI_AUTH_WPA3_PSK, /**< WPA3_PSK */
} gsw_wifi_auth_e;
/**
* @brief ap state
*/
typedef enum {
GSW_WIFI_AP_STATUS_DISABLE = 0, /**< not running */
GSW_WIFI_AP_STATUS_ENABLE, /**< running */
} gsw_wifi_ap_run_status_e;
/**
* @brief sta state
*/
typedef enum {
GSW_WIFI_STA_STATUS_DISABLE = 0, /**< not running */
GSW_WIFI_STA_STATUS_ENABLE, /**< running */
} gsw_wifi_sta_run_status_e;
/**
* @brief wifi interface idx
*/
typedef enum {
GSW_WIFI_INTERFACE_0 = 0, /**< STA */
GSW_WIFI_INTERFACE_1, /**< AP */
}gsw_wifi_index_e;
/**
* @brief band type
*/
typedef enum {
GSW_WIFI_2G_band = 1, /**< 2.4G */
GSW_WIFI_5G_band, /**< 5G */
GSW_WIFI_2_and_5G_band, /**< 2.4G and 5G */
} gsw_wifi_band_e;
/**
* @brief sta mode dns info
*/
typedef struct gsw_sta_dns_info
{
char dnsp[46]; //Primary DNS server address
char dnss[46]; //Secondary DNS server address
} gsw_sta_dns_info_s;
/**
* @brief ap info
*/
typedef struct gsw_ap_info
{
char ap_ip[32]; /**< IP Addr */
char ap_mac[32]; /**< IP Addr */
char ap_ssid[32]; /**< ssid */
char psw[64]; /**< password */
gsw_wifi_auth_e auth; /**< authentication */
gsw_wifi_band_e band; /**< band */
} gsw_ap_info_s;
typedef struct gsw_ap_detail_info
{
struct gsw_ap_info base_info; /**< ap info */
gsw_wifi_ap_run_status_e status; /**< ap run state */
int rssi; /**< rssi[0~199] */
} gsw_ap_detail_info_s;
/**
* @brief device info
*/
typedef struct gsw_device_info
{
char sta_ip[32]; /**< IP Addr */
char sta_mac[32]; /**< IP Addr */
char hostname[32]; /**< device name */
gsw_wifi_ap_status_e status; /**< connect state */
} gsw_device_info_s;
typedef struct gsw_saved_ap_info
{
struct gsw_ap_info base_info;
} gsw_saved_ap_info_s;
/**
* @brief error code of sta connect fail
* current only support errcode 1,2
*/
typedef enum
{
GSW_REASON_IP_NOT_ACCESS = 0, /**< IP connect not access */
GSW_REASON_UNSPECIFIED = 1, /**< Unspecified reason */
GSW_REASON_PREV_AUTH_NOT_VALID = 2, /**< Previous authentication no longer valid */
GSW_REASON_DEAUTH_LEAVING = 3, /**< Deauthenticated because sending STA is leaving (or has left) IBSS or ESS */
GSW_REASON_DISASSOC_DUE_TO_INACTIVITY = 4, /**< Disassociated due to inactivity */
GSW_REASON_DISASSOC_AP_BUSY = 5, /**< Disassociated because AP is unable to handle all currently associated STA */
GSW_REASON_CLASS2_FRAME_FROM_NONAUTH_STA = 6, /**< Class 2 frame received from nonauthenticated STA */
GSW_REASON_CLASS3_FRAME_FROM_NONASSOC_STA = 7, /**< Class 3 frame received from nonassociated STA */
GSW_REASON_DISASSOC_STA_HAS_LEFT = 8, /**< Disassociated because sending STA is leaving (or has left) BSS */
GSW_REASON_STA_REQ_ASSOC_WITHOUT_AUTH = 9, /**< STA requesting (re)association is not authenticated with responding STA */
GSW_REASON_PWR_CAPABILITY_NOT_VALID = 10, /**< Disassociated because the information in the Power Capability element is unacceptable */
GSW_REASON_SUPPORTED_CHANNEL_NOT_VALID = 11, /**< Disassociated because the information in the Supported Channels is unacceptable */
GSW_REASON_BSS_TRANSITION_DISASSOC = 12, /**< Disassociated due to BSS Transition Management */
GSW_REASON_INVALID_IE = 13, /**< Invalid element, i.e., an element defined in this standard for which the content
does not meet the specifications in Clause 8 */
GSW_REASON_MICHAEL_MIC_FAILURE = 14, /**< Message integrity code (MIC) failure */
GSW_REASON_4WAY_HANDSHAKE_TIMEOUT = 15, /**< 4-Way Handshake timeout */
GSW_REASON_GROUP_KEY_UPDATE_TIMEOUT = 16, /**< Group Key Handshake timeout */
GSW_REASON_IE_IN_4WAY_DIFFERS = 17, /**< Element in 4-Way handshake different from (Re)Association
Request/Probe Response/Beacon frame */
GSW_REASON_GROUP_CIPHER_NOT_VALID = 18, /**< Invalid group cipher */
GSW_REASON_PAIRWISE_CIPHER_NOT_VALID = 19, /**< Invalid pairwise cipher */
GSW_REASON_AKMP_NOT_VALID = 20, /**< Invalid AKMP */
GSW_REASON_UNSUPPORTED_RSN_IE_VERSION = 21, /**< Unsupproted RSNE version */
GSW_REASON_INVALID_RSN_IE_CAPAB = 22, /**< Invalid RSNE capabilities */
GSW_REASON_IEEE_802_1X_AUTH_FAILED = 23, /**< IEEE 802.1X authentication failed */
GSW_REASON_CIPHER_SUITE_REJECTED = 24, /**< Cipher suite rejected because of the security policy */
GSW_REASON_TDLS_TEARDOWN_UNREACHABLE = 25, /**< TDLS direct-link teardown due to TDLS peer STA unreachable via the TDLS direct link */
GSW_REASON_TDLS_TEARDOWN_UNSPECIFIED = 26, /**< TDLS direct-link teardown for unspecified reason */
GSW_REASON_SSP_REQUESTED_DISASSOC = 27, /**< Disassocited because session terminated by SSP request */
GSW_REASON_NO_SSP_ROAMING_AGREEMENT = 28, /**< Disassocited because of lack of SSP roaming agreement */
GSW_REASON_BAD_CIPHER_OR_AKM = 29, /**< Requested service rejected because of SSP cipher suite or AKM requirment */
GSW_REASON_NOT_AUTHORIZED_THIS_LOCATION = 30, /**< requested service not authorized in this location */
GSW_REASON_SERVICE_CHANGE_PRECLUDES_TS = 31, /**< TS deleted because QoS AP lacks sufficient bandwidth for
this QoS STA due to a change in BSS service characteristics or operational mode
(e.g., an HT BSS change from 40 MHz channel to 20 MHz channel) */
GSW_REASON_UNSPECIFIED_QOS_REASON = 32, /**< Disassocited for unspecified QoS-related reason */
GSW_REASON_NOT_ENOUGH_BANDWIDTH = 33, /**< Disassocited because QoS AP lacks sufficient bandwidth for this QoS STA */
GSW_REASON_DISASSOC_LOW_ACK = 34, /**< Disassociated because excessive number of frames need to be acknowledged,
but are not acknowledged due to AP transmissions and/or poor channel conditions */
GSW_REASON_EXCEEDED_TXOP = 35, /**< Disassociated because STA is transmitting outside the limits of its TXOPs */
GSW_REASON_STA_LEAVING = 36, /**< Requested from peer STA as the STA is leaving the BSS (or resetting) */
GSW_REASON_END_TS_BA_DLS = 37, /**< Requested from peer STA as it does not want to use the mechanism */
GSW_REASON_UNKNOWN_TS_BA = 38, /**< Requested from peer STA as the STA received frames using
the mechanism for which a setup is required */
GSW_REASON_TIMEOUT = 39, /**< Requested from peer STA due to timeout */
GSW_REASON_PEERKEY_MISMATCH = 45, /**< Peer STA does not support the requested cipher suite */
GSW_REASON_AUTHORIZED_ACCESS_LIMIT_REACHED = 46, /**< In a DLS Teardown frame: The teardown was initiated by the DLS peer in
a disassociation frame: disassociated because authorized access limit reached*/
GSW_REASON_EXTERNAL_SERVICE_REQUIREMENTS = 47, /**< In a DLS Teardown frame: The teardown was initiated by the AP
In a disassociation frame: disassociated due to external service requirments */
GSW_REASON_INVALID_FT_ACTION_FRAME_COUNT = 48, /**< Invalid FT action frame count */
GSW_REASON_INVALID_PMKID = 49, /**< Invalid pairwise master key identifier (PMKI) */
GSW_REASON_INVALID_MDE = 50, /**< Invalid MDE */
GSW_REASON_INVALID_FTE = 51, /**< Invalid FTE */
GSW_REASON_MESH_PEERING_CANCELLED = 52, /**< SME cancels the mesh peering instance with the reason
other than reaching the maximum number of peer mesh STAs */
GSW_REASON_MESH_MAX_PEERS = 53, /**< The mesh STA has reached the supported maximum number of peer mesh STAs */
GSW_REASON_MESH_CONFIG_POLICY_VIOLATION = 54, /**< The received information violates the Mesh Configuration policy configured in the mesh STA profile */
GSW_REASON_MESH_CLOSE_RCVD = 55, /**< The mesh STA has received a Mesh Peering Close message requesting to close the mesh peering*/
GSW_REASON_MESH_MAX_RETRIES = 56, /**< the mesh STA has resent dot11MeshMaxRetries Mesh Peering Open messages
without receiveing a Mesh Peering Confirm messa*/
GSW_REASON_MESH_CONFIRM_TIMEOU = 57, /**< The confirm Timer for the mesh peering instance times out */
GSW_REASON_MESH_INVALID_GTK = 58, /**< The mesh STA fails to unwrap the GTK or the values in the wrapped contents do not match */
GSW_REASON_MESH_INCONSISTENT_PARAMS = 59, /**< The mesh STA receives inconsistent information about the mesh parameters
between mesh peering management frames */
GSW_REASON_MESH_INVALID_SECURITY_CAP = 60, /**< The mesh STA fails the authenticated mesh peering exchange because due to failure
in selecting either in the pairwise ciphersuite or group ciphersuite*/
GSW_REASON_MESH_PATH_ERROR_NO_PROXY_INFO = 61, /**< The mesh STA does not have proxy information for this external destination */
GSW_REASON_MESH_PATH_ERROR_NO_FORWARDING_INFO = 62, /**< The mesh STA does not have forwarding infromation for this destination */
GSW_REASON_MESH_PATH_ERROR_DEST_UNREACHABLE = 63, /**< The mesh STA determines that the link to the next hop of an active path in
its forwarding information is no longer usable */
GSW_REASON_MAC_ADDRESS_ALREADY_EXISTS_IN_MBSS = 64, /**< The deauthentication frame was sent because the MAC address
of the STA already exists in the mesh BSS.Scc10.3.6 */
GSW_REASON_MESH_CHANNEL_SWITCH_REGULATORY_REQ = 65, /**< The mesh STA performs channel switch to meet regulatory requirments */
GSW_REASON_MESH_CHANNEL_SWITCH_UNSPECIFIED = 66, /**< The mesh STA performs channel switch with unspecified reason */
GSW_REASON_LOW_SECURITY = 67, /**< Low level of network security */
} error_number_e;
typedef struct gsw_scan_info
{
char mac[32]; /**< MAC addr */
char ssid[33]; /**< ssid */
gsw_wifi_band_e band; /**< band */
gsw_wifi_auth_e auth; /**< authentication */
int rssi; /**< rssi */
} gsw_scan_info_s;
/**
* @brief modem sdk wifi service init
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_sdk_interface_init(void);
/**
* @brief load wifi driver
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_enable(void);
/**
* @brief uninstall wifi driver
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_disable(void);
/**
* @brief start ap mode
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_start(void);
/**
* @brief stop ap mode
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_stop(void);
/**
* @brief restart ap
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_restart(void);
int gsw_wifi_stop_ap(wifi_mode_ability_e mode_ability);
/**
* @brief set ap ssid
* @param [in] ssid ssid
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_ssid_set(char *ssid);
/**
* @brief get ap ssid
* @param [out] ssid ssid
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_ssid_get(char *ssid);
/**
* @brief set ap frequency
* @param [in] gsw_wifi_frequency 1 is 2.4G,2 is 5G
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_frequency_set(int gsw_wifi_frequency);
/**
* @brief get ap frequency
* @param [out] gsw_wifi_frequency 1 is 2.4G,2 is 5G
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_frequency_get(int *gsw_wifi_frequency);
/**
* @brief set ap bandwidth
* @param [in] bandwidth bandwidth
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_bandwidth_set(gsw_wifi_bandwidth_type_e bandwidth);
/**
* @brief get ap bandwidth
* @param [out] bandwidth bandwidth
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_bandwidth_get(gsw_wifi_bandwidth_type_e *bandwidth);
/**
* @brief set ap channel
* @param [in] channel channel
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_channel_set(int channel);
/**
* @brief get ap channel
* @param [out] channel channel
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_channel_get(int *channel);
/**
* @brief set ap authentication
* @param [in] auth authentication
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_auth_set(gsw_wifi_auth_e auth);
/**
* @brief get ap authentication
* @param [out] auth authentication
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_auth_get(gsw_wifi_auth_e *auth);
/**
* @brief set ap password
* @param [in] password password
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_password_set(char *password);
/**
* @brief get ap password
* @param [out] password password
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_ap_password_get(char *password);
/**
* @brief get ap run state
* @param [out] ap_status ap run state
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_get_ap_status(gsw_wifi_ap_run_status_e *ap_status);
/**
* @brief get sta run state
* @param [out] sta_status sta run state
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_get_sta_status(gsw_wifi_sta_run_status_e *sta_status);
/**
* @brief start sta mode
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_sta_start(void);
/**
* @brief stop sta mode
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_sta_stop(void);
int gsw_wifi_stop_sta(wifi_mode_ability_e mode_ability);
/**
* @brief obtain the ssid of the ap currently connected to the sta
* @param [out] sta_ssid ssid
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_get_sta_ssid(char *sta_ssid);
/**
* @brief obtain the authentication of the ap currently connected to the sta
* @param [out] auth authentication
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_get_sta_auth(gsw_wifi_auth_e *auth);
/**
* @brief connect to target ap
* @param [in] ssid the ssid of the target ap
* @param [in] auth the authentication of the target ap
* @param [in] password the password of the target ap
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_sta_connect(char *ssid, gsw_wifi_auth_e auth, char *password);
/**
* @brief disconnect the currently connected ap
* @param [in] ssid the ssid of the target ap
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_sta_disconnect(char *ssid);
/**
* @brief delete remembered ap
* @param [in] ssid the ssid of the target ap
* @param [in] auth the authentication of the target ap
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_sta_forget_ap(char *ssid, gsw_wifi_auth_e auth);
/**
* @brief sta start scan
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_sta_start_scan(void);
/**
* @brief get interface ip addr
* @param [in] idx interface idx
* @param [out] ip interface ip addr
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_get_interface_ip(gsw_wifi_index_e idx, char *ip);
/**
* @brief get interface mac addr
* @param [in] idx interface idx
* @param [out] mac interface mac addr
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_get_interface_mac(gsw_wifi_index_e idx, char *mac);
/**
* @brief obtain the mac of the ap currently connected to the sta
* @param [out] mac ap mac addr
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_get_connect_ap_mac(char *mac);
/**
* @brief obtain the rssi of the ap currently connected to the sta
* @param [out] rssi ap rssi
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_get_connect_ap_rssi(int *rssi);
/**
* @brief obtain the band of the ap currently connected to the sta
* @param [out] band the ap band
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_get_connect_ap_band(gsw_wifi_band_e *band);
/**
* @brief obtain the ip of the ap currently connected to the sta
* @param [out] ip the ap ip
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_get_connect_ap_ip(char *ip);
/**
* @brief get the currently connectable AP with the best signal strength
* @param [out] info the ap info
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_get_sta_available_ap(gsw_ap_detail_info_s *info);
/**
* @brief get ap device list
* @param [in] len the size of the param[device_list]
* @param [out] ap_info the ap info
* @param [out] device_list the device list
* @param [out] dev_len the device num
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_get_ap_device_list(gsw_ap_info_s *ap_info, gsw_device_info_s *device_list, int len, int *dev_len);
/**
* @brief get the saved ap list
* @param [in] len the size of the param[list]
* @param [out] list the saved ap list
* @param [out] list_len the list num
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_get_sta_saved_ap(gsw_saved_ap_info_s *list, int len, int *list_len);
/**
* @brief get the sta scan list
* @param [in] len the size of the param[list]
* @param [out] list the scan list
* @param [out] list_len the list num
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_get_scan_list(gsw_scan_info_s *list, int len, int *list_len);
typedef void(*GSW_AP_CALLBACK_FUNC_PTR)(void *arg, gsw_wifi_ap_status_e status);
/**
* @brief register ap event notification function
* @param [in] arg as gsw_cb function parameter, can be NULL
* @param [in] gsw_cb callback
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_reg_ap_event_callback(void *arg, GSW_AP_CALLBACK_FUNC_PTR gsw_cb);
/**
* @brief unregister ap callback function
* @param [in] arg reserved parameter, can be NULL
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_unreg_ap_event_callback(void *arg);
typedef void(*GSW_STA_CALLBACK_FUNC_PTR)(void *arg, gsw_wifi_sta_status_e status, error_number_e number, gsw_sta_dns_info_s* dns_info);
/**
* @brief register sta event notification function
* @param [in] arg as gsw_cb function parameter, can be NULL
* @param [in] gsw_cb callback
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_reg_sta_event_callback(void *arg, GSW_STA_CALLBACK_FUNC_PTR gsw_cb);
/**
* @brief unregister sta callback function
* @param [in] arg reserved parameters, can be NULL
* @retval 0: success
* @retval other: fail
*/
int gsw_wifi_unreg_sta_event_callback(void *arg);
#endif