1 /*
2  * WPA Supplicant - Common definitions
3  * Copyright (c) 2004-2015, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #ifndef DEFS_H
10 #define DEFS_H
11 
12 #ifdef FALSE
13 #undef FALSE
14 #endif
15 #ifdef TRUE
16 #undef TRUE
17 #endif
18 typedef enum { FALSE = 0, TRUE = 1 } Boolean;
19 
20 #define WPA_CIPHER_NONE                 BIT(0)
21 #define WPA_CIPHER_WEP40                BIT(7)
22 #define WPA_CIPHER_WEP104               BIT(8)
23 #define WPA_CIPHER_TKIP                 BIT(1)
24 #define WPA_CIPHER_CCMP                 BIT(3)
25 #define WPA_CIPHER_AES_128_CMAC         BIT(5)
26 #define WPA_CIPHER_SMS4                 BIT(10)
27 #define WPA_CIPHER_GCMP                 BIT(11)
28 #define WPA_CIPHER_GCMP_256             BIT(12)
29 #define WPA_CIPHER_BIP_GMAC_128         BIT(13)
30 #define WPA_CIPHER_BIP_GMAC_256         BIT(14)
31 
32 #define WPA_KEY_MGMT_IEEE8021X BIT(0)
33 #define WPA_KEY_MGMT_PSK BIT(1)
34 #define WPA_KEY_MGMT_NONE BIT(2)
35 #define WPA_KEY_MGMT_IEEE8021X_NO_WPA BIT(3)
36 #define WPA_KEY_MGMT_WPA_NONE BIT(4)
37 #define WPA_KEY_MGMT_FT_IEEE8021X BIT(5)
38 #define WPA_KEY_MGMT_FT_PSK BIT(6)
39 #define WPA_KEY_MGMT_IEEE8021X_SHA256 BIT(7)
40 #define WPA_KEY_MGMT_PSK_SHA256 BIT(8)
41 #define WPA_KEY_MGMT_WPS BIT(9)
42 #define WPA_KEY_MGMT_SAE BIT(10)
43 #define WPA_KEY_MGMT_FT_SAE BIT(11)
44 #define WPA_KEY_MGMT_WAPI_PSK BIT(12)
45 #define WPA_KEY_MGMT_WAPI_CERT BIT(13)
46 #define WPA_KEY_MGMT_CCKM BIT(14)
47 #define WPA_KEY_MGMT_OSEN BIT(15)
48 #define WPA_KEY_MGMT_IEEE8021X_SUITE_B BIT(16)
49 #define WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 BIT(17)
50 #define WPA_KEY_MGMT_OWE BIT(22)
51 #define WPA_KEY_MGMT_DPP BIT(23)
52 
wpa_key_mgmt_wpa_ieee8021x(int akm)53 static inline int wpa_key_mgmt_wpa_ieee8021x(int akm)
54 {
55 #ifdef CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT
56 	return !!(akm & (WPA_KEY_MGMT_IEEE8021X |
57 			 WPA_KEY_MGMT_FT_IEEE8021X |
58 			 WPA_KEY_MGMT_CCKM |
59 			 WPA_KEY_MGMT_OSEN |
60 			 WPA_KEY_MGMT_IEEE8021X_SHA256 |
61 			 WPA_KEY_MGMT_IEEE8021X_SUITE_B |
62 			 WPA_KEY_MGMT_IEEE8021X_SUITE_B_192));
63 #else
64         return 0;
65 #endif
66 }
67 
wpa_key_mgmt_wpa_psk(int akm)68 static inline int wpa_key_mgmt_wpa_psk(int akm)
69 {
70 	return !!(akm & (WPA_KEY_MGMT_PSK |
71 			 WPA_KEY_MGMT_FT_PSK |
72 			 WPA_KEY_MGMT_PSK_SHA256 |
73 			 WPA_KEY_MGMT_SAE |
74 			 WPA_KEY_MGMT_FT_SAE));
75 }
76 
wpa_key_mgmt_ft(int akm)77 static inline int wpa_key_mgmt_ft(int akm)
78 {
79 	return !!(akm & (WPA_KEY_MGMT_FT_PSK |
80 			 WPA_KEY_MGMT_FT_IEEE8021X |
81 			 WPA_KEY_MGMT_FT_SAE));
82 }
83 
wpa_key_mgmt_sae(int akm)84 static inline int wpa_key_mgmt_sae(int akm)
85 {
86 	return !!(akm & (WPA_KEY_MGMT_SAE |
87 			 WPA_KEY_MGMT_FT_SAE));
88 }
89 
wpa_key_mgmt_sha256(int akm)90 static inline int wpa_key_mgmt_sha256(int akm)
91 {
92 	return !!(akm & (WPA_KEY_MGMT_PSK_SHA256 |
93 			 WPA_KEY_MGMT_IEEE8021X_SHA256 |
94 			 WPA_KEY_MGMT_OSEN |
95 			 WPA_KEY_MGMT_SAE |
96 			 WPA_KEY_MGMT_IEEE8021X_SUITE_B |
97 			 WPA_KEY_MGMT_OWE));
98 }
99 
wpa_key_mgmt_sha384(int akm)100 static inline int wpa_key_mgmt_sha384(int akm)
101 {
102 	return !!(akm & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192);
103 }
104 
wpa_key_mgmt_suite_b(int akm)105 static inline int wpa_key_mgmt_suite_b(int akm)
106 {
107 	return !!(akm & (WPA_KEY_MGMT_IEEE8021X_SUITE_B |
108 			 WPA_KEY_MGMT_IEEE8021X_SUITE_B_192));
109 }
110 
wpa_key_mgmt_owe(int akm)111 static inline int wpa_key_mgmt_owe(int akm)
112 {
113 	return akm == WPA_KEY_MGMT_OWE;
114 }
115 
wpa_key_mgmt_wpa(int akm)116 static inline int wpa_key_mgmt_wpa(int akm)
117 {
118 	return wpa_key_mgmt_wpa_ieee8021x(akm) ||
119 		wpa_key_mgmt_wpa_psk(akm) ||
120 		wpa_key_mgmt_sae(akm) ||
121 		wpa_key_mgmt_owe(akm);
122 }
123 
wpa_key_mgmt_wpa_any(int akm)124 static inline int wpa_key_mgmt_wpa_any(int akm)
125 {
126 	return wpa_key_mgmt_wpa(akm) || (akm & WPA_KEY_MGMT_WPA_NONE);
127 }
128 
wpa_key_mgmt_cckm(int akm)129 static inline int wpa_key_mgmt_cckm(int akm)
130 {
131 	return akm == WPA_KEY_MGMT_CCKM;
132 }
133 
134 #ifdef ESP_SUPPLICANT
wpa_key_mgmt_supports_caching(int akm)135 static inline int wpa_key_mgmt_supports_caching(int akm)
136 {
137         return wpa_key_mgmt_wpa_ieee8021x(akm) ||
138 		wpa_key_mgmt_sae(akm) ||
139 		wpa_key_mgmt_owe(akm);
140 }
141 #endif
142 
143 #define WPA_PROTO_WPA BIT(0)
144 #define WPA_PROTO_RSN BIT(1)
145 #define WPA_PROTO_WAPI BIT(2)
146 #define WPA_PROTO_OSEN BIT(3)
147 
148 #define WPA_AUTH_ALG_OPEN BIT(0)
149 #define WPA_AUTH_ALG_SHARED BIT(1)
150 #define WPA_AUTH_ALG_LEAP BIT(2)
151 #define WPA_AUTH_ALG_FT BIT(3)
152 #define WPA_AUTH_ALG_SAE BIT(4)
153 
154 
155 enum wifi_key_alg {
156 	ALG_WEP,
157 	ALG_TKIP,
158 	ALG_CCMP,
159 	ALG_AES_CMAC,
160 };
161 
162 /**
163  * enum wpa_cipher - Cipher suites
164  */
165 enum wpa_cipher {
166 	CIPHER_NONE,
167 	CIPHER_WEP40,
168 	CIPHER_TKIP,
169 	CIPHER_CCMP,
170 	CIPHER_WEP104,
171 	CIPHER_SMS4,
172 	CIPHER_GCMP_256,
173 };
174 
175 /**
176  * enum wpa_key_mgmt - Key management suites
177  */
178 enum wpa_key_mgmt {
179 	KEY_MGMT_802_1X,
180 	KEY_MGMT_PSK,
181 	KEY_MGMT_NONE,
182 	KEY_MGMT_802_1X_NO_WPA,
183 	KEY_MGMT_WPA_NONE,
184 	KEY_MGMT_FT_802_1X,
185 	KEY_MGMT_FT_PSK,
186 	KEY_MGMT_802_1X_SHA256,
187 	KEY_MGMT_PSK_SHA256,
188 	KEY_MGMT_WPS
189 };
190 
191 /**
192  * enum wpa_states - wpa_supplicant state
193  *
194  * These enumeration values are used to indicate the current wpa_supplicant
195  * state (wpa_s->wpa_state). The current state can be retrieved with
196  * wpa_supplicant_get_state() function and the state can be changed by calling
197  * wpa_supplicant_set_state(). In WPA state machine (wpa.c and preauth.c), the
198  * wrapper functions wpa_sm_get_state() and wpa_sm_set_state() should be used
199  * to access the state variable.
200  */
201 enum wpa_states {
202 	/**
203 	 * WPA_DISCONNECTED - Disconnected state
204 	 *
205 	 * This state indicates that client is not associated, but is likely to
206 	 * start looking for an access point. This state is entered when a
207 	 * connection is lost.
208 	 */
209 	WPA_DISCONNECTED,
210 
211 	/**
212 	 * WPA_INTERFACE_DISABLED - Interface disabled
213 	 *
214 	 * This state is entered if the network interface is disabled, e.g.,
215 	 * due to rfkill. wpa_supplicant refuses any new operations that would
216 	 * use the radio until the interface has been enabled.
217 	 */
218 	WPA_INTERFACE_DISABLED,
219 
220 	/**
221 	 * WPA_INACTIVE - Inactive state (wpa_supplicant disabled)
222 	 *
223 	 * This state is entered if there are no enabled networks in the
224 	 * configuration. wpa_supplicant is not trying to associate with a new
225 	 * network and external interaction (e.g., ctrl_iface call to add or
226 	 * enable a network) is needed to start association.
227 	 */
228 	WPA_INACTIVE,
229 
230 	/**
231 	 * WPA_SCANNING - Scanning for a network
232 	 *
233 	 * This state is entered when wpa_supplicant starts scanning for a
234 	 * network.
235 	 */
236 	WPA_SCANNING,
237 
238 	/**
239 	 * WPA_AUTHENTICATING - Trying to authenticate with a BSS/SSID
240 	 *
241 	 * This state is entered when wpa_supplicant has found a suitable BSS
242 	 * to authenticate with and the driver is configured to try to
243 	 * authenticate with this BSS. This state is used only with drivers
244 	 * that use wpa_supplicant as the SME.
245 	 */
246 	WPA_AUTHENTICATING,
247 
248 	/**
249 	 * WPA_ASSOCIATING - Trying to associate with a BSS/SSID
250 	 *
251 	 * This state is entered when wpa_supplicant has found a suitable BSS
252 	 * to associate with and the driver is configured to try to associate
253 	 * with this BSS in ap_scan=1 mode. When using ap_scan=2 mode, this
254 	 * state is entered when the driver is configured to try to associate
255 	 * with a network using the configured SSID and security policy.
256 	 */
257 	WPA_ASSOCIATING,
258 
259 	/**
260 	 * WPA_ASSOCIATED - Association completed
261 	 *
262 	 * This state is entered when the driver reports that association has
263 	 * been successfully completed with an AP. If IEEE 802.1X is used
264 	 * (with or without WPA/WPA2), wpa_supplicant remains in this state
265 	 * until the IEEE 802.1X/EAPOL authentication has been completed.
266 	 */
267 	WPA_ASSOCIATED,
268 
269 	/**
270 	 * WPA_4WAY_HANDSHAKE - WPA 4-Way Key Handshake in progress
271 	 *
272 	 * This state is entered when WPA/WPA2 4-Way Handshake is started. In
273 	 * case of WPA-PSK, this happens when receiving the first EAPOL-Key
274 	 * frame after association. In case of WPA-EAP, this state is entered
275 	 * when the IEEE 802.1X/EAPOL authentication has been completed.
276 	 */
277 	WPA_FIRST_HALF_4WAY_HANDSHAKE,
278 
279 	WPA_LAST_HALF_4WAY_HANDSHAKE,
280 
281 	/**
282 	 * WPA_GROUP_HANDSHAKE - WPA Group Key Handshake in progress
283 	 *
284 	 * This state is entered when 4-Way Key Handshake has been completed
285 	 * (i.e., when the supplicant sends out message 4/4) and when Group
286 	 * Key rekeying is started by the AP (i.e., when supplicant receives
287 	 * message 1/2).
288 	 */
289 	WPA_GROUP_HANDSHAKE,
290 
291 	/**
292 	 * WPA_COMPLETED - All authentication completed
293 	 *
294 	 * This state is entered when the full authentication process is
295 	 * completed. In case of WPA2, this happens when the 4-Way Handshake is
296 	 * successfully completed. With WPA, this state is entered after the
297 	 * Group Key Handshake; with IEEE 802.1X (non-WPA) connection is
298 	 * completed after dynamic keys are received (or if not used, after
299 	 * the EAP authentication has been completed). With static WEP keys and
300 	 * plaintext connections, this state is entered when an association
301 	 * has been completed.
302 	 *
303 	 * This state indicates that the supplicant has completed its
304 	 * processing for the association phase and that data connection is
305 	 * fully configured.
306 	 */
307 	WPA_COMPLETED,
308 
309 	WPA_MIC_FAILURE,                         // first mic_error event occur
310 
311 	WPA_TKIP_COUNTERMEASURES  //in countermeasure period that stop connect with ap in 60 sec
312 };
313 
314 #define MLME_SETPROTECTION_PROTECT_TYPE_NONE 0
315 #define MLME_SETPROTECTION_PROTECT_TYPE_RX 1
316 #define MLME_SETPROTECTION_PROTECT_TYPE_TX 2
317 #define MLME_SETPROTECTION_PROTECT_TYPE_RX_TX 3
318 
319 #define MLME_SETPROTECTION_KEY_TYPE_GROUP 0
320 #define MLME_SETPROTECTION_KEY_TYPE_PAIRWISE 1
321 
322 /**
323  * enum mfp_options - Management frame protection (IEEE 802.11w) options
324  */
325 enum mfp_options {
326 	NO_MGMT_FRAME_PROTECTION = 0,
327 	MGMT_FRAME_PROTECTION_OPTIONAL = 1,
328 	MGMT_FRAME_PROTECTION_REQUIRED = 2,
329 };
330 #define MGMT_FRAME_PROTECTION_DEFAULT 3
331 
332 /**
333  * enum hostapd_hw_mode - Hardware mode
334  */
335 enum hostapd_hw_mode {
336 	HOSTAPD_MODE_IEEE80211B,
337 	HOSTAPD_MODE_IEEE80211G,
338 	HOSTAPD_MODE_IEEE80211A,
339 	HOSTAPD_MODE_IEEE80211AD,
340 	HOSTAPD_MODE_IEEE80211ANY,
341 	NUM_HOSTAPD_MODES
342 };
343 
344 /**
345  * enum wpa_ctrl_req_type - Control interface request types
346  */
347 enum wpa_ctrl_req_type {
348 	WPA_CTRL_REQ_UNKNOWN,
349 	WPA_CTRL_REQ_EAP_IDENTITY,
350 	WPA_CTRL_REQ_EAP_PASSWORD,
351 	WPA_CTRL_REQ_EAP_NEW_PASSWORD,
352 	WPA_CTRL_REQ_EAP_PIN,
353 	WPA_CTRL_REQ_EAP_OTP,
354 	WPA_CTRL_REQ_EAP_PASSPHRASE,
355 	WPA_CTRL_REQ_SIM,
356 	WPA_CTRL_REQ_PSK_PASSPHRASE,
357 	NUM_WPA_CTRL_REQS
358 };
359 
360 /* Maximum number of EAP methods to store for EAP server user information */
361 #define EAP_MAX_METHODS 8
362 
363 enum mesh_plink_state {
364 	PLINK_LISTEN = 1,
365 	PLINK_OPEN_SENT,
366 	PLINK_OPEN_RCVD,
367 	PLINK_CNF_RCVD,
368 	PLINK_ESTAB,
369 	PLINK_HOLDING,
370 	PLINK_BLOCKED,
371 };
372 
373 enum set_band {
374 	WPA_SETBAND_AUTO,
375 	WPA_SETBAND_5G,
376 	WPA_SETBAND_2G
377 };
378 
379 enum sae_pwe {
380     SAE_PWE_HUNT_AND_PECK = 0,
381     SAE_PWE_HASH_TO_ELEMENT = 1,
382     SAE_PWE_BOTH = 2,
383     SAE_PWE_FORCE_HUNT_AND_PECK = 3,
384     SAE_PWE_NOT_SET = 4,
385 };
386 
387 #endif /* DEFS_H */
388