• 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 /* TODO
16  *
17  * Make it to new WiFi API
18  * */
19 #pragma once
20 
21 #include <stdint.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /**
28  * @brief WLAN SSID and passphrase definition
29  */
30 #define WLAN_SCAN_SSID_MAX      2  /* max # of SSIDs */
31 #define WLAN_SSID_MAX_LEN       32
32 #define WLAN_PASSPHRASE_MIN_LEN 8
33 #define WLAN_PASSPHRASE_MAX_LEN 63
34 #define WLAN_PSK_HEX_LEN        32
35 #define WLAN_PSK_HEX_STR_LEN    64 /* two characters per octet of PSK */
36 
37 /**
38  * @brief WLAN WEP key length definition
39  */
40 #define WLAN_WEP40_KEY_LEN      5  /* 5-byte  (40-bit)  */
41 #define WLAN_WEP104_KEY_LEN     13 /* 13-byte (104-bit) */
42 #define WLAN_WEP128_KEY_LEN     16 /* 16-byte (128-bit), unsupported */
43 #define WLAN_WEP_KEY_MAX_LEN    WLAN_WEP128_KEY_LEN
44 
45 #define WLAN_MAC_LEN		6
46 
47 /**
48  * @brief Wlan ssid definition
49  */
50 typedef struct wlan_ssid {
51 	uint8_t ssid[WLAN_SSID_MAX_LEN];
52 	uint8_t ssid_len;
53 } wlan_ssid_t;
54 
55 /**
56  * @brief Wlan station configuration field definition
57  */
58 typedef enum wlan_sta_field {
59 	WLAN_STA_FIELD_SSID = 0,
60 	WLAN_STA_FIELD_BSSID,
61 	WLAN_STA_FIELD_PSK,
62 	WLAN_STA_FIELD_WEP_KEY0,
63 	WLAN_STA_FIELD_WEP_KEY1,
64 	WLAN_STA_FIELD_WEP_KEY2,
65 	WLAN_STA_FIELD_WEP_KEY3,
66 	WLAN_STA_FIELD_WEP_KEY_INDEX,
67 	WLAN_STA_FIELD_KEY_MGMT,
68 	WLAN_STA_FIELD_PAIRWISE_CIPHER,
69 	WLAN_STA_FIELD_GROUP_CIPHER,
70 	WLAN_STA_FIELD_PROTO,
71 	WLAN_STA_FIELD_AUTH_ALG,
72 	WLAN_STA_FIELD_WPA_PTK_REKEY,
73 	WLAN_STA_FIELD_SCAN_SSID,
74 	WLAN_STA_FIELD_FREQ,	/* only used in fast connect */
75 	WLAN_STA_FIELD_SAE_GROUPS,
76 	WLAN_STA_FIELD_MFP,
77 	WLAN_STA_FIELD_EAP,
78 	WLAN_STA_FIELD_IDENTITY,
79 	WLAN_STA_FIELD_CA_CERT,
80 	WLAN_STA_FIELD_CLIENT_CERT,
81 	WLAN_STA_FIELD_PRIVATE_KEY,
82 	WLAN_STA_FIELD_PRIVATE_KEY_PASSWD,
83 	WLAN_STA_FIELD_PHASE1,
84 
85 	/* for debug */
86 	WLAN_STA_FIELD_DEBUG_LEVEL,
87 	WLAN_STA_FIELD_DEBUG_SHOW_KEYS,
88 
89 	WLAN_STA_FIELD_NUM,
90 } wlan_sta_field_t;
91 
92 /**
93  * @brief Wlan station configuration definition
94  */
95 typedef struct wlan_sta_config {
96 	wlan_sta_field_t field;
97 #ifdef CONFIG_WPA_SUPPLICANT_MULTI_NETWORK
98 	int id;	/* network id */
99 #endif
100 
101 	union {
102 		/**
103 		 * Network name
104 		 */
105 		wlan_ssid_t ssid;
106 
107 		/**
108 		 * bssid - BSSID
109 		 *
110 		 * If set, this network block is used only when associating with the AP
111 		 * using the configured BSSID
112 		 */
113 		uint8_t bssid[WLAN_MAC_LEN];
114 
115 		/**
116 		 * fast_connect_freq
117 		 */
118 		int channel;
119 
120 		/**
121 		 * WPA preshared key in one of the optional formats:
122 		 *   - an ASCII string of passphrase, length is [8, 63]
123 		 *   - a hex string of PSK (two characters per octet of PSK), length is 64
124 		 */
125 		char psk[65];
126 
127 		/**
128 		 * WEP key in one of the optional formats:
129 		 *   - an ASCII string with double quotation, length is {5, 13}
130 		 *   - a hex string (two characters per octet), length is {10, 26}
131 		 */
132 		char wep_key[WLAN_WEP_KEY_MAX_LEN * 2 + 1];
133 
134 		/**
135 		 * Default key index for TX frames using WEP
136 		 */
137 		int wep_tx_keyidx;
138 
139 		/**
140 		 * Bitfield of allowed key management protocols
141 		 *
142 		 * WPA_KEY_MGMT_*
143 		 */
144 		int key_mgmt;
145 
146 		/**
147 		 * Bitfield of allowed pairwise ciphers
148 		 *
149 		 * WPA_CIPHER_*
150 		 */
151 		int pairwise_cipher;
152 
153 		/**
154 		 * Bitfield of allowed group ciphers
155 		 *
156 		 * WPA_CIPHER_*
157 		 */
158 		int group_cipher;
159 
160 		/**
161 		 * Bitfield of allowed protocols
162 		 *
163 		 * WPA_PROTO_*
164 		 */
165 		int proto;
166 
167 		/**
168 		 * Bitfield of allowed authentication algorithms
169 		 *
170 		 * WPA_AUTH_ALG_*
171 		 */
172 		int auth_alg;
173 
174 		/**
175 		 * Maximum lifetime for PTK in seconds
176 		 *
177 		 * This value can be used to enforce rekeying of PTK to
178 		 * mitigate some attacks against TKIP deficiencies.
179 		 */
180 		int wpa_ptk_rekey;
181 
182 		/**
183 		 * Scan this SSID with Probe Requests
184 		 *
185 		 * scan_ssid can be used to scan for APs using hidden SSIDs.
186 		 */
187 		int scan_ssid;
188 
189 
190 		int sae_groups[16];
191 
192 		int ieee80211w;
193 
194 		int debug_level;
195 		int debug_show_keys;
196 
197 		/* EAP related */
198 		char eap[64];
199 		char identity[64];
200 		char ca_cert[64];
201 		char client_cert[64];
202 		char private_key[64];
203 		char private_key_passwd[64];
204 		char phase1[64];		/* phase1 config */
205 	} u;
206 } wlan_sta_config_t;
207 
208 /**
209  * @brief Wlan station connection state definition
210  */
211 typedef enum wlan_sta_states {
212 	WLAN_STA_STATE_DISCONNECTED = 0,
213 	WLAN_STA_STATE_CONNECTED = 1,
214 } wlan_sta_states_t;
215 
216 /**
217  * @brief Wlan AP information definition
218  */
219 typedef struct wlan_sta_ap {
220 	wlan_ssid_t	ssid;
221 	uint8_t		bssid[6];
222 	uint8_t		channel;
223 	uint16_t	beacon_int;
224 	int		freq;
225 	int		rssi;
226 	int		level;
227 	int		wpa_flags;
228 	int		wpa_cipher;
229 	int		wpa_key_mgmt;
230 	int		wpa2_cipher;
231 	int		wpa2_key_mgmt;
232 } wlan_sta_ap_t;
233 
234 /**
235  * @brief Wlan station scan parameters definition
236  */
237 typedef struct wlan_sta_scan_param {
238 	uint8_t scan_only;    /* do scan only */
239 	uint8_t scan_passive; /* passive scan */
240 	uint8_t scan_ssid;    /* Scan SSID of configured network with Probe Requests */
241 	uint8_t num_ssids;
242 	wlan_ssid_t ssids[WLAN_SCAN_SSID_MAX];
243 } wlan_sta_scan_param_t;
244 
245 /**
246  * @brief Wlan station scan results definition
247  */
248 typedef struct wlan_sta_scan_results {
249 	wlan_sta_ap_t *ap;
250 	int size;
251 	int num;
252 } wlan_sta_scan_results_t;
253 
254 /**
255  * @brief Wlan station bss infomation definition
256  */
257 typedef struct wlan_sta_bss_info {
258 	uint8_t *bss;
259 	uint32_t size;
260 } wlan_sta_bss_info_t;
261 
262 /**
263  * @brief Parameter of generating WPA PSK based on passphrase and SSID
264  */
265 typedef struct wlan_gen_psk_param {
266 	uint8_t ssid[WLAN_SSID_MAX_LEN];
267 	uint8_t ssid_len;
268 	char passphrase[WLAN_PASSPHRASE_MAX_LEN + 1];
269 	uint8_t psk[WLAN_PSK_HEX_LEN]; /* out */
270 } wlan_gen_psk_param_t;
271 
272 /**
273  * @brief Wlan WPS pin definition
274  */
275 typedef struct wlan_sta_wps_pin {
276 	char pin[9];
277 } wlan_sta_wps_pin_t;
278 
279 /**
280  * @brief Wlan auto reconnect definition
281  *
282  * count     auto reconnect retry count, 0 for no restrict
283  * timeout   auto reconnect timeout, 0 for no restrict
284  * disable_reconnect_when_disconnect  disable reconnect when disconnect by AP if current
285  *           state is connect with AP.
286  */
287 typedef struct wlan_auto_reconnect {
288 	int max_count;
289 	int timeout;
290 	bool disable_reconnect_when_disconnect;
291 } wlan_auto_reconnect_t;
292 
293 /**
294  * @brief Wlan AP configuration field definition
295  */
296 typedef enum wlan_ap_field {
297 	WLAN_AP_FIELD_SSID = 0,
298 	WLAN_AP_FIELD_PSK,
299 	WLAN_AP_FIELD_KEY_MGMT,
300 	WLAN_AP_FIELD_WPA_CIPHER,
301 	WLAN_AP_FIELD_RSN_CIPHER,
302 	WLAN_AP_FIELD_PROTO,
303 	WLAN_AP_FIELD_AUTH_ALG,
304 	WLAN_AP_FIELD_GROUP_REKEY,
305 	WLAN_AP_FIELD_STRICT_REKEY,
306 	WLAN_AP_FIELD_GMK_REKEY,
307 	WLAN_AP_FIELD_PTK_REKEY,
308 	WLAN_AP_FIELD_HW_MODE,
309 	WLAN_AP_FIELD_IEEE80211N,
310 	WLAN_AP_FIELD_CHANNEL,
311 	WLAN_AP_FIELD_BEACON_INT,
312 	WLAN_AP_FIELD_DTIM,
313 	WLAN_AP_FIELD_MAX_NUM_STA,
314 
315 	WLAN_AP_FIELD_NUM,
316 } wlan_ap_field_t;
317 
318 /**
319  * @brief Wlan AP hardware mode definition
320  */
321 typedef enum wlan_ap_hw_mode {
322 	WLAN_AP_HW_MODE_IEEE80211B = 0,
323 	WLAN_AP_HW_MODE_IEEE80211G,
324 	WLAN_AP_HW_MODE_IEEE80211A,
325 	WLAN_AP_HW_MODE_IEEE80211AD,
326 
327 	WLAN_AP_HW_MODE_NUM,
328 } wlan_ap_hw_mode_t;
329 
330 /**
331  * @brief Wlan AP configuration definition
332  */
333 typedef struct wlan_ap_config {
334 	wlan_ap_field_t field;
335 
336 	union {
337 		/**
338 		 * Network name
339 		 */
340 		wlan_ssid_t ssid;
341 
342 		/**
343 		 * WPA preshared key in one of the optional formats:
344 		 *   - an ASCII string of passphrase, length is [8, 63]
345 		 *   - a hex string of PSK (two characters per octet of PSK), length is 64
346 		 */
347 		uint8_t psk[65];
348 
349 		/**
350 		 * Bitfield of allowed key management protocols
351 		 *
352 		 * WPA_KEY_MGMT_*
353 		 */
354 		int key_mgmt;
355 
356 		/**
357 		 * Bitfield of allowed WPA pairwise ciphers
358 		 *
359 		 * WPA_CIPHER_*
360 		 */
361 		int wpa_cipher;
362 
363 		/**
364 		 * Bitfield of allowed RSN pairwise ciphers
365 		 *
366 		 * WPA_CIPHER_*
367 		 */
368 		int rsn_cipher;
369 
370 		/**
371 		 * Bitfield of allowed protocols
372 		 *
373 		 * WPA_PROTO_*
374 		 */
375 		int proto;
376 
377 		/**
378 		 * Bitfield of allowed authentication algorithms
379 		 *
380 		 * WPA_AUTH_ALG_*
381 		 */
382 		int auth_alg;
383 
384 		/**
385 		 * Maximum lifetime for GTK in seconds
386 		 */
387 		int group_rekey;
388 
389 		/**
390 		 * Rekey GTK when any STA that possesses the current GTK is
391 		 * leaving the BSS
392 		 */
393 		int strict_rekey;
394 
395 		/**
396 		 * Maximum lifetime for GMK in seconds
397 		 */
398 		int gmk_rekey;
399 
400 		/**
401 		 * Maximum lifetime for PTK in seconds
402 		 */
403 		int ptk_rekey;
404 
405 		/**
406 		 * Hardware mode
407 		 */
408 		wlan_ap_hw_mode_t hw_mode;
409 
410 		/**
411 		 * IEEE802.11n mode
412 		 */
413 		int ieee80211n;
414 
415 		/**
416 		 * RF channel
417 		 */
418 		uint8_t channel;
419 
420 		/**
421 		 * MIB defines range as 1..65535, but very small values
422 		 * cause problems with the current implementation.
423 		 * Since it is unlikely that this small numbers are
424 		 * useful in real life scenarios, do not allow beacon
425 		 * period to be set below 15 TU.
426 		 */
427 		uint16_t beacon_int;
428 
429 		/**
430 		 * Delivery traffic indication message
431 		 */
432 		int dtim;
433 
434 		/**
435 		 * Maximum number of STAs in station table
436 		 */
437 		int max_num_sta;
438 	} u;
439 } wlan_ap_config_t;
440 
441 struct wlan_p2p_connect_param {
442 	uint8_t addr[6];
443 	int method;
444 	int intent;
445 };
446 
447 /* TODO - we shoul finally remove the INTERNAL event, all WiFi events are
448  * from supplicant and are public.
449  * */
450 enum {
451 	WIFI_INTERNAL_EVENT_STA_CONNECTED = 0,
452 	WIFI_INTERNAL_EVENT_STA_DISCONNECTED,
453 	WIFI_INTERNAL_EVENT_MAX,
454 };
455 
456 enum {
457 	WIFI_CAPA_ID_HT_EN= 0,
458 	WIFI_CAPA_ID_VHT_EN,
459 	WIFI_CAPA_ID_HE_EN,
460 	WIFI_CAPA_ID_TX_AMPDU_EN,
461 	WIFI_CAPA_ID_RX_AMPDU_EN,
462 	WIFI_CAPA_ID_HE_MCS,
463 	WIFI_CAPA_ID_MAX,
464 };
465 
466 
467 #ifdef __cplusplus
468 }
469 #endif
470 
471