• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 #include <common/bk_include.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 /**
23  * @brief WiFi APIs Version 1 (Old WiFi API)
24  * @addtogroup bk_api_wifi_v1 Old WiFi API group
25  * @{
26  */
27 
28 /**
29  * @brief WLAN encryption type
30  * @defgroup bk_api_wifi_v1_enum enum
31  * @ingroup bk_api_wifi_v1
32  * @{
33  */
34 enum {
35 	WLAN_ENC_OPEN,  /**< No encryption */
36 	WLAN_ENC_WEP,   /**< WiFi encryption algorithmn is WEP */
37 	WLAN_ENC_CCMP,  /**< WiFi encryption algorithmn is CCMP */
38 	WLAN_ENC_TKIP,  /**< WiFi encryption algorithmn is TKIP */
39 };
40 
41 #define WiFi_Interface  wlanInterfaceTypedef /**< WiFi interface */
42 
43 #define DHCP_DISABLE  (0)   /**< Disable DHCP service. */
44 #define DHCP_CLIENT   (1)   /**< Enable DHCP client which get IP address from DHCP server automatically */
45 #define DHCP_SERVER   (2)   /**< Enable DHCP server, needs assign a static address as local address. */
46 
47 typedef enum _wifi_dis_reason
48 {
49 	UNSUPPORT_ENCRYPT = 0, /**< Unsupport encrypt algorithmn */
50 	WRONG_PASSPHRASE,      /**< WiFi disconnect because configured wrong password */
51 	DEAUTHENTICATION,      /**< WiFi disconnect because of receiving deauth frame */
52 	DISASSOCIATION,        /**< WiFi disconnect because of receiving disassociation frame */
53 	AP_MISSING,            /**< WiFi disconnect because AP is missing, eg. AP is powered off etc */
54 	WLAN_DISCONNECT,       /**< WiFi is disconnected by application */
55 } WIFI_DISCONN_REASON;         /**< WiFi reason code */
56 
57 typedef enum
58 {
59 	BK_SOFT_AP,  /**< Act as an access point, and other station can connect, 4 stations Max*/
60 	BK_STATION,   /**< Act as a station which can connect to an access point*/
61 	BK_P2P
62 } wlanInterfaceTypedef;
63 
64 enum bk_wlan_sec_type_e
65 {
66 	BK_SECURITY_TYPE_NONE,        /**< Open system. */
67 	BK_SECURITY_TYPE_WEP,         /**< Wired Equivalent Privacy. WEP security. */
68 	BK_SECURITY_TYPE_WPA_TKIP,    /**< WPA /w TKIP */
69 	BK_SECURITY_TYPE_WPA_AES,     /**< WPA /w AES */
70 	BK_SECURITY_TYPE_WPA2_TKIP,   /**< WPA2 /w TKIP */
71 	BK_SECURITY_TYPE_WPA2_AES,    /**< WPA2 /w AES */
72 	BK_SECURITY_TYPE_WPA2_MIXED,  /**< WPA2 /w AES or TKIP */
73 	BK_SECURITY_TYPE_WPA3_SAE,    /**< WPA3 SAE */
74 	BK_SECURITY_TYPE_WPA3_WPA2_MIXED, /**< WPA3 SAE or WPA2 AES */
75 	BK_SECURITY_TYPE_EAP,         /**< EAP */
76 	BK_SECURITY_TYPE_OWE,         /**< OWE */
77 	BK_SECURITY_TYPE_AUTO,        /**< It is used when calling @ref bk_wlan_start_sta_adv, _BK_ read security type from scan result. */
78 };
79 
80 enum
81 {
82 	WLAN_RX_BEACON,    /**< receive beacon packet */
83 	WLAN_RX_PROBE_REQ, /**< receive probe request packet */
84 	WLAN_RX_PROBE_RES, /**< receive probe response packet */
85 	WLAN_RX_ACTION,    /**< receive action packet */
86 	WLAN_RX_MANAGEMENT,/**< receive ALL management packet */
87 	WLAN_RX_DATA,      /**< receive ALL data packet */
88 	WLAN_RX_MCAST_DATA,/**< receive ALL multicast and broadcast packet */
89 	WLAN_RX_ALL,       /**< receive ALL 802.11 packet */
90 };
91 
92 typedef uint8_t wlan_sec_type_t;  /**< WiFi security type */
93 
94 #define MONITOR_FILTER_MUL_BRD_CAST     (1U << 0) /**< Multicast frame filter bit */
95 #define MONITOR_FILTER_DUPL_FRM         (1U << 1) /**< Duplicated frame filter bit */
96 
97 /**
98  * @}
99  */
100 
101 /**
102  * @brief WLAN encryption type
103  * @defgroup bk_api_wifi_v1_typedef struct
104  * @ingroup bk_api_wifi_v1 struct
105  * @{
106  */
107 
108 typedef struct _wifi_link_info
109 {
110 	uint8_t bssid[6];           /**< BSSID of link */
111 	int16_t rssi;               /**< RSSI of link */
112 	uint32_t data_rate;         /**< Data rate TODO */
113 	WIFI_DISCONN_REASON reason; /**< Disconnect reason TODO */
114 } WIFI_LINK_INFO_T;
115 
116 /**
117  *  @brief  wlan local IP information structure definition.
118  */
119 typedef struct
120 {
121 	uint8_t dhcp;       /**< DHCP mode: @ref DHCP_DISABLE, @ref DHCP_CLIENT, @ref DHCP_SERVER.*/
122 	char    ip[16];     /**< Local IP address on the target wlan interface: @ref wlanInterfaceTypedef.*/
123 	char    gate[16];   /**< Router IP address on the target wlan interface: @ref wlanInterfaceTypedef.*/
124 	char    mask[16];   /**< Netmask on the target wlan interface: @ref wlanInterfaceTypedef.*/
125 	char    dns[16];    /**< DNS server IP address.*/
126 	char    mac[16];    /**< MAC address, example: "C89346112233".*/
127 	char    broadcastip[16]; /**< Broadcast IP address */
128 } IPStatusTypedef;
129 
130 /**
131  *  @brief  Scan result using normal scan.
132  */
133 typedef  struct  _ScanResult
134 {
135 	char ApNum;       /**< The number of access points found in scanning. */
136 	struct _ApList
137 	{
138 		char ssid[33];  /**< The SSID of an access point. */
139 		char ApPower;   /**< Signal strength, min:0, max:100. */
140 	} *ApList;
141 } ScanResult;
142 
143 /**
144  *      @brief  Scan result using advanced scan.
145  */
146 typedef  struct  _ScanResult_adv
147 {
148 	char ApNum;       /**< The number of access points found in scanning.*/
149 	struct ApListStruct
150 	{
151 		char ssid[33];    /**< The SSID of an access point.*/
152 		char ApPower;     /**< Signal strength, min:0, max:100*/
153 		uint8_t bssid[6]; /**< The BSSID of an access point.*/
154 		char channel;     /**< The RF frequency, 1-13*/
155 		wlan_sec_type_t security;       /**< Security type, see wlan_sec_type_t */
156 	} *ApList;  /**< AP list found by scan */
157 } ScanResult_adv;
158 
159 /**
160  * @brief  The info of the APs found by scan.
161  *
162  * The WiFi driver scans the APs by parsing the received beacon or probe response of
163  * the AP and all following info are came from the beacon or probe response.
164  */
165 typedef struct sta_scan_res
166 {
167 	UINT8 bssid[6];    /**< The BSSID of AP */
168 	char ssid[32];     /**< The SSID of AP */
169 	char on_channel;   /**< Indicate whether the channel in DS IE is valid 2.4G channel */
170 	char channel;      /**< The channel of AP */
171 	UINT16 beacon_int; /**< Beacon interval of AP */
172 	UINT16 caps;       /**< Capability IE of AP */
173 	int level;         /**< RSSI of the received frame */
174 	int security;      /**< Encryption algorithm of AP */
175 	UINT8 tsf[8];      /**< TSF value in beacon or probe response */
176 	UINT32 ie_len;     /**< IE length of beacon or probe response */
177 	/* Followed by ie_len of IE data */
178 } SCAN_RST_ITEM_T, *SCAN_RST_ITEM_PTR;
179 
180 /**
181  *  @brief  Input network paras, used in bk_wlan_start function.
182  */
183 typedef struct _network_InitTypeDef_st
184 {
185 	char wifi_mode;               /**< WiFi mode, BK_SOFT_AP or BK_STATION */
186 	char wifi_ssid[33];           /**< For station, it's SSID of the AP to be connected, for AP, it's the SSID of our AP */
187 	char wifi_key[65];            /**< Security key of the wlan needs to be connected, ignored in an open system.*/
188 	char local_ip_addr[16];       /**< Static IP configuration, Local IP address. */
189 	char net_mask[16];            /**< Static IP configuration, Netmask. */
190 	char gateway_ip_addr[16];     /**< Static IP configuration, Router IP address. */
191 	char dns_server_ip_addr[16];  /**< Static IP configuration, DNS server IP address. */
192 	char dhcp_mode;               /**< DHCP mode, @ref DHCP_DISABLE, @ref DHCP_CLIENT and @ref DHCP_SERVER. */
193 	char wifi_bssid[6];           /**< For station, it's the BSSID of AP to be connected, for AP, it's BSSID of our AP */
194 	char reserved[26];            /**< Reserved */
195 	int  wifi_retry_interval;     /**< Retry interval if an error is occured when connecting an access point,
196 						time unit is millisecond. */
197 } network_InitTypeDef_st;
198 
199 /**
200  *  @brief  Advanced precise wlan parameters, used in @ref network_InitTypeDef_adv_st.
201  */
202 typedef struct
203 {
204 	char    ssid[32];    /**< SSID of the wlan that needs to be connected. Example: "SSID String". */
205 	char    bssid[6];    /**< BSSID of the wlan needs to be connected. Example: {0xC8 0x93 0x46 0x11 0x22 0x33}. */
206 	uint8_t channel;     /**< Wlan's RF frequency, channel 0-13. 1-13 means a fixed channel
207                             that can speed up a connection procedure, 0 is not a fixed input
208                             means all channels are possible*/
209 	wlan_sec_type_t security; /**< Security type of AP */
210 } apinfo_adv_t;
211 
212 /**
213  *  @brief  Input network precise paras in bk_wlan_start_sta_adv function.
214  */
215 typedef struct _network_InitTypeDef_adv_st
216 {
217 	apinfo_adv_t ap_info;         /**< @ref apinfo_adv_t. */
218 	char  key[64];                /**< Security key or PMK of the wlan. */
219 	int   key_len;                /**< The length of the key. */
220 	char  local_ip_addr[16];      /**< Static IP configuration, Local IP address. */
221 	char  net_mask[16];           /**< Static IP configuration, Netmask. */
222 	char  gateway_ip_addr[16];    /**< Static IP configuration, Router IP address. */
223 	char  dns_server_ip_addr[16]; /**< Static IP configuration, DNS server IP address. */
224 	char  dhcp_mode;              /**< DHCP mode, @ref DHCP_DISABLE, @ref DHCP_CLIENT and @ref DHCP_SERVER. */
225 	char  reserved[32];           /**< reserved */
226 	int   wifi_retry_interval;    /**< Retry interval if an error is occured when connecting an access point,
227 					time unit is millisecond. */
228 } network_InitTypeDef_adv_st;
229 
230 typedef struct _network_InitTypeDef_ap_st
231 {
232 	char wifi_ssid[32];           /**< SSID of AP */
233 	char wifi_key[64];            /**< key of AP */
234 	uint8_t channel;              /**< Channel of AP */
235 	wlan_sec_type_t security;     /**< Security type of AP */
236 	uint8_t ssid_hidden;          /**< Whether the AP is hidden */
237 	uint8_t max_con;              /**< Max number of stations allowed to connect in, TODO? */
238 	char local_ip_addr[16];       /**< IP of AP */
239 	char net_mask[16];            /**< Network mask of AP */
240 	char gateway_ip_addr[16];     /**< Gateway IP of AP */
241 	char dns_server_ip_addr[16];  /**< DNS server IP of AP */
242 	char dhcp_mode;               /**< DHCP mode */
243 	char reserved[32];            /**< Reserved */
244 	int  wifi_retry_interval;     /**< For STA only */
245 } network_InitTypeDef_ap_st;
246 
247 /**
248  *  @brief  Current link status in station mode.
249  */
250 typedef struct _linkStatus_t
251 {
252 	int conn_state;         /**< The link to wlan is established or not, 0: disconnected, 1: connected. */
253 	int wifi_strength;      /**< Signal strength of the current connected AP */
254 	uint8_t  ssid[32];      /**< SSID of the current connected wlan */
255 	uint8_t  bssid[6];      /**< BSSID of the current connected wlan */
256 	int      channel;       /**< Channel of the current connected wlan */
257 	wlan_sec_type_t security; /**< Security type of WiFi link */
258 } LinkStatusTypeDef;
259 
260 typedef struct
261 {
262         int8_t rssi; /**< RSSI of WiFi link, generally it's the RSSI of the received WiFi frame */
263 } wifi_link_info_t;
264 
265 /*same with RL_BSSID_INFO_T{}*/
266 struct wlan_fast_connect_info
267 {
268 	uint8_t ssid[33]; /**< SSID of AP */
269 	uint8_t bssid[6]; /**< BSSID of AP */
270 	uint8_t security; /**< Security of AP */
271 	uint8_t channel;  /**< Channel of AP */
272 	uint8_t psk[65];  /**< PSK of AP */
273 	uint8_t pwd[65];  /**< password of AP */
274 	uint8_t ip_addr[4];
275 	uint8_t netmask[4];
276 	uint8_t gw[4];
277 	uint8_t dns1[4];
278 };
279 
280 typedef struct vif_addcfg_st {
281 	char *ssid;   /**< SSID of VIF */
282 	char *key;    /**< Key of VIF */
283 	char *name;   /**< Name of VIF, can be "sta" or "softap" */
284 	u8 wlan_role; /**< Role of VIF, can be BK_SOFT_AP or BK_STATION */
285 	u8 adv;       /**< Only for station role, indicate whether connect the AP with advance method */
286 } VIF_ADDCFG_ST, *VIF_ADDCFG_PTR;
287 
288 
289 /**
290  * @}
291  */
292 
293 /**
294  * @}
295  */
296 
297 #ifdef __cplusplus
298 }
299 #endif
300