1 /*
2 * WPA Supplicant - Common definitions
3 * Copyright (c) 2004-2018, 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 #ifdef LOS_WPA_PATCH
21 #ifndef BIT
22 #define BIT(x) (1U << (x))
23 #endif
24 #endif /* LOS_WPA_PATCH */
25
26 #define WPA_CIPHER_NONE BIT(0)
27 #define WPA_CIPHER_WEP40 BIT(1)
28 #define WPA_CIPHER_WEP104 BIT(2)
29 #define WPA_CIPHER_TKIP BIT(3)
30 #define WPA_CIPHER_CCMP BIT(4)
31 #define WPA_CIPHER_AES_128_CMAC BIT(5)
32 #define WPA_CIPHER_GCMP BIT(6)
33 #define WPA_CIPHER_SMS4 BIT(7)
34 #define WPA_CIPHER_GCMP_256 BIT(8)
35 #define WPA_CIPHER_CCMP_256 BIT(9)
36 #define WPA_CIPHER_BIP_GMAC_128 BIT(11)
37 #define WPA_CIPHER_BIP_GMAC_256 BIT(12)
38 #define WPA_CIPHER_BIP_CMAC_256 BIT(13)
39 #define WPA_CIPHER_GTK_NOT_USED BIT(14)
40
41 #define WPA_KEY_MGMT_IEEE8021X BIT(0)
42 #define WPA_KEY_MGMT_PSK BIT(1)
43 #define WPA_KEY_MGMT_NONE BIT(2)
44 #define WPA_KEY_MGMT_IEEE8021X_NO_WPA BIT(3)
45 #define WPA_KEY_MGMT_WPA_NONE BIT(4)
46 #define WPA_KEY_MGMT_FT_IEEE8021X BIT(5)
47 #define WPA_KEY_MGMT_FT_PSK BIT(6)
48 #define WPA_KEY_MGMT_IEEE8021X_SHA256 BIT(7)
49 #define WPA_KEY_MGMT_PSK_SHA256 BIT(8)
50 #define WPA_KEY_MGMT_WPS BIT(9)
51 #define WPA_KEY_MGMT_SAE BIT(10)
52 #define WPA_KEY_MGMT_FT_SAE BIT(11)
53 #define WPA_KEY_MGMT_WAPI_PSK BIT(12)
54 #define WPA_KEY_MGMT_WAPI_CERT BIT(13)
55 #define WPA_KEY_MGMT_CCKM BIT(14)
56 #define WPA_KEY_MGMT_OSEN BIT(15)
57 #define WPA_KEY_MGMT_IEEE8021X_SUITE_B BIT(16)
58 #define WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 BIT(17)
59 #define WPA_KEY_MGMT_FILS_SHA256 BIT(18)
60 #define WPA_KEY_MGMT_FILS_SHA384 BIT(19)
61 #define WPA_KEY_MGMT_FT_FILS_SHA256 BIT(20)
62 #define WPA_KEY_MGMT_FT_FILS_SHA384 BIT(21)
63 #define WPA_KEY_MGMT_OWE BIT(22)
64 #define WPA_KEY_MGMT_DPP BIT(23)
65 #define WPA_KEY_MGMT_FT_IEEE8021X_SHA384 BIT(24)
66 #define WPA_KEY_MGMT_PASN BIT(25)
67
68
69 #define WPA_KEY_MGMT_FT (WPA_KEY_MGMT_FT_PSK | \
70 WPA_KEY_MGMT_FT_IEEE8021X | \
71 WPA_KEY_MGMT_FT_IEEE8021X_SHA384 | \
72 WPA_KEY_MGMT_FT_SAE | \
73 WPA_KEY_MGMT_FT_FILS_SHA256 | \
74 WPA_KEY_MGMT_FT_FILS_SHA384)
75
wpa_key_mgmt_wpa_ieee8021x(int akm)76 static inline int wpa_key_mgmt_wpa_ieee8021x(int akm)
77 {
78 return !!(akm & (WPA_KEY_MGMT_IEEE8021X |
79 WPA_KEY_MGMT_FT_IEEE8021X |
80 WPA_KEY_MGMT_FT_IEEE8021X_SHA384 |
81 WPA_KEY_MGMT_CCKM |
82 WPA_KEY_MGMT_OSEN |
83 WPA_KEY_MGMT_IEEE8021X_SHA256 |
84 WPA_KEY_MGMT_IEEE8021X_SUITE_B |
85 WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 |
86 WPA_KEY_MGMT_FILS_SHA256 |
87 WPA_KEY_MGMT_FILS_SHA384 |
88 WPA_KEY_MGMT_FT_FILS_SHA256 |
89 WPA_KEY_MGMT_FT_FILS_SHA384));
90 }
91
wpa_key_mgmt_wpa_psk_no_sae(int akm)92 static inline int wpa_key_mgmt_wpa_psk_no_sae(int akm)
93 {
94 return !!(akm & (WPA_KEY_MGMT_PSK |
95 WPA_KEY_MGMT_FT_PSK |
96 WPA_KEY_MGMT_PSK_SHA256));
97 }
98
wpa_key_mgmt_wpa_psk(int akm)99 static inline int wpa_key_mgmt_wpa_psk(int akm)
100 {
101 return !!(akm & (WPA_KEY_MGMT_PSK |
102 WPA_KEY_MGMT_FT_PSK |
103 WPA_KEY_MGMT_PSK_SHA256 |
104 WPA_KEY_MGMT_SAE |
105 WPA_KEY_MGMT_FT_SAE));
106 }
107
wpa_key_mgmt_ft(int akm)108 static inline int wpa_key_mgmt_ft(int akm)
109 {
110 return !!(akm & WPA_KEY_MGMT_FT);
111 }
112
wpa_key_mgmt_only_ft(int akm)113 static inline int wpa_key_mgmt_only_ft(int akm)
114 {
115 int ft = wpa_key_mgmt_ft(akm);
116 akm &= ~WPA_KEY_MGMT_FT;
117 return ft && !akm;
118 }
119
wpa_key_mgmt_ft_psk(int akm)120 static inline int wpa_key_mgmt_ft_psk(int akm)
121 {
122 return !!(akm & WPA_KEY_MGMT_FT_PSK);
123 }
124
wpa_key_mgmt_sae(int akm)125 static inline int wpa_key_mgmt_sae(int akm)
126 {
127 return !!(akm & (WPA_KEY_MGMT_SAE |
128 WPA_KEY_MGMT_FT_SAE));
129 }
130
wpa_key_mgmt_fils(int akm)131 static inline int wpa_key_mgmt_fils(int akm)
132 {
133 return !!(akm & (WPA_KEY_MGMT_FILS_SHA256 |
134 WPA_KEY_MGMT_FILS_SHA384 |
135 WPA_KEY_MGMT_FT_FILS_SHA256 |
136 WPA_KEY_MGMT_FT_FILS_SHA384));
137 }
138
wpa_key_mgmt_sha256(int akm)139 static inline int wpa_key_mgmt_sha256(int akm)
140 {
141 return !!(akm & (WPA_KEY_MGMT_PSK_SHA256 |
142 WPA_KEY_MGMT_IEEE8021X_SHA256 |
143 WPA_KEY_MGMT_SAE |
144 WPA_KEY_MGMT_FT_SAE |
145 WPA_KEY_MGMT_OSEN |
146 WPA_KEY_MGMT_IEEE8021X_SUITE_B |
147 WPA_KEY_MGMT_FILS_SHA256 |
148 WPA_KEY_MGMT_FT_FILS_SHA256));
149 }
150
wpa_key_mgmt_sha384(int akm)151 static inline int wpa_key_mgmt_sha384(int akm)
152 {
153 return !!(akm & (WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 |
154 WPA_KEY_MGMT_FT_IEEE8021X_SHA384 |
155 WPA_KEY_MGMT_FILS_SHA384 |
156 WPA_KEY_MGMT_FT_FILS_SHA384));
157 }
158
wpa_key_mgmt_suite_b(int akm)159 static inline int wpa_key_mgmt_suite_b(int akm)
160 {
161 return !!(akm & (WPA_KEY_MGMT_IEEE8021X_SUITE_B |
162 WPA_KEY_MGMT_IEEE8021X_SUITE_B_192));
163 }
164
wpa_key_mgmt_wpa(int akm)165 static inline int wpa_key_mgmt_wpa(int akm)
166 {
167 return wpa_key_mgmt_wpa_ieee8021x(akm) ||
168 wpa_key_mgmt_wpa_psk(akm) ||
169 wpa_key_mgmt_fils(akm) ||
170 wpa_key_mgmt_sae(akm) ||
171 akm == WPA_KEY_MGMT_OWE ||
172 akm == WPA_KEY_MGMT_DPP;
173 }
174
wpa_key_mgmt_wpa_any(int akm)175 static inline int wpa_key_mgmt_wpa_any(int akm)
176 {
177 return wpa_key_mgmt_wpa(akm) || (akm & WPA_KEY_MGMT_WPA_NONE);
178 }
179
wpa_key_mgmt_cckm(int akm)180 static inline int wpa_key_mgmt_cckm(int akm)
181 {
182 return akm == WPA_KEY_MGMT_CCKM;
183 }
184
185
186 #define WPA_PROTO_WPA BIT(0)
187 #define WPA_PROTO_RSN BIT(1)
188 #define WPA_PROTO_WAPI BIT(2)
189 #define WPA_PROTO_OSEN BIT(3)
190
191 #define WPA_AUTH_ALG_OPEN BIT(0)
192 #define WPA_AUTH_ALG_SHARED BIT(1)
193 #define WPA_AUTH_ALG_LEAP BIT(2)
194 #define WPA_AUTH_ALG_FT BIT(3)
195 #define WPA_AUTH_ALG_SAE BIT(4)
196 #define WPA_AUTH_ALG_FILS BIT(5)
197 #define WPA_AUTH_ALG_FILS_SK_PFS BIT(6)
198
wpa_auth_alg_fils(int alg)199 static inline int wpa_auth_alg_fils(int alg)
200 {
201 return !!(alg & (WPA_AUTH_ALG_FILS | WPA_AUTH_ALG_FILS_SK_PFS));
202 }
203
204 enum wpa_alg {
205 WPA_ALG_NONE,
206 WPA_ALG_WEP,
207 WPA_ALG_TKIP,
208 WPA_ALG_CCMP,
209 WPA_ALG_BIP_CMAC_128,
210 WPA_ALG_GCMP,
211 WPA_ALG_SMS4,
212 WPA_ALG_KRK,
213 WPA_ALG_GCMP_256,
214 WPA_ALG_CCMP_256,
215 WPA_ALG_BIP_GMAC_128,
216 WPA_ALG_BIP_GMAC_256,
217 WPA_ALG_BIP_CMAC_256
218 };
219
wpa_alg_bip(enum wpa_alg alg)220 static inline int wpa_alg_bip(enum wpa_alg alg)
221 {
222 return alg == WPA_ALG_BIP_CMAC_128 ||
223 alg == WPA_ALG_BIP_GMAC_128 ||
224 alg == WPA_ALG_BIP_GMAC_256 ||
225 alg == WPA_ALG_BIP_CMAC_256;
226 }
227
228 /**
229 * enum wpa_states - wpa_supplicant state
230 *
231 * These enumeration values are used to indicate the current wpa_supplicant
232 * state (wpa_s->wpa_state). The current state can be retrieved with
233 * wpa_supplicant_get_state() function and the state can be changed by calling
234 * wpa_supplicant_set_state(). In WPA state machine (wpa.c and preauth.c), the
235 * wrapper functions wpa_sm_get_state() and wpa_sm_set_state() should be used
236 * to access the state variable.
237 */
238 enum wpa_states {
239 /**
240 * WPA_DISCONNECTED - Disconnected state
241 *
242 * This state indicates that client is not associated, but is likely to
243 * start looking for an access point. This state is entered when a
244 * connection is lost.
245 */
246 WPA_DISCONNECTED,
247
248 /**
249 * WPA_INTERFACE_DISABLED - Interface disabled
250 *
251 * This state is entered if the network interface is disabled, e.g.,
252 * due to rfkill. wpa_supplicant refuses any new operations that would
253 * use the radio until the interface has been enabled.
254 */
255 WPA_INTERFACE_DISABLED,
256
257 /**
258 * WPA_INACTIVE - Inactive state (wpa_supplicant disabled)
259 *
260 * This state is entered if there are no enabled networks in the
261 * configuration. wpa_supplicant is not trying to associate with a new
262 * network and external interaction (e.g., ctrl_iface call to add or
263 * enable a network) is needed to start association.
264 */
265 WPA_INACTIVE,
266
267 /**
268 * WPA_SCANNING - Scanning for a network
269 *
270 * This state is entered when wpa_supplicant starts scanning for a
271 * network.
272 */
273 WPA_SCANNING,
274
275 /**
276 * WPA_AUTHENTICATING - Trying to authenticate with a BSS/SSID
277 *
278 * This state is entered when wpa_supplicant has found a suitable BSS
279 * to authenticate with and the driver is configured to try to
280 * authenticate with this BSS. This state is used only with drivers
281 * that use wpa_supplicant as the SME.
282 */
283 WPA_AUTHENTICATING,
284
285 /**
286 * WPA_ASSOCIATING - Trying to associate with a BSS/SSID
287 *
288 * This state is entered when wpa_supplicant has found a suitable BSS
289 * to associate with and the driver is configured to try to associate
290 * with this BSS in ap_scan=1 mode. When using ap_scan=2 mode, this
291 * state is entered when the driver is configured to try to associate
292 * with a network using the configured SSID and security policy.
293 */
294 WPA_ASSOCIATING,
295
296 /**
297 * WPA_ASSOCIATED - Association completed
298 *
299 * This state is entered when the driver reports that association has
300 * been successfully completed with an AP. If IEEE 802.1X is used
301 * (with or without WPA/WPA2), wpa_supplicant remains in this state
302 * until the IEEE 802.1X/EAPOL authentication has been completed.
303 */
304 WPA_ASSOCIATED,
305
306 /**
307 * WPA_4WAY_HANDSHAKE - WPA 4-Way Key Handshake in progress
308 *
309 * This state is entered when WPA/WPA2 4-Way Handshake is started. In
310 * case of WPA-PSK, this happens when receiving the first EAPOL-Key
311 * frame after association. In case of WPA-EAP, this state is entered
312 * when the IEEE 802.1X/EAPOL authentication has been completed.
313 */
314 WPA_4WAY_HANDSHAKE,
315
316 /**
317 * WPA_GROUP_HANDSHAKE - WPA Group Key Handshake in progress
318 *
319 * This state is entered when 4-Way Key Handshake has been completed
320 * (i.e., when the supplicant sends out message 4/4) and when Group
321 * Key rekeying is started by the AP (i.e., when supplicant receives
322 * message 1/2).
323 */
324 WPA_GROUP_HANDSHAKE,
325
326 /**
327 * WPA_COMPLETED - All authentication completed
328 *
329 * This state is entered when the full authentication process is
330 * completed. In case of WPA2, this happens when the 4-Way Handshake is
331 * successfully completed. With WPA, this state is entered after the
332 * Group Key Handshake; with IEEE 802.1X (non-WPA) connection is
333 * completed after dynamic keys are received (or if not used, after
334 * the EAP authentication has been completed). With static WEP keys and
335 * plaintext connections, this state is entered when an association
336 * has been completed.
337 *
338 * This state indicates that the supplicant has completed its
339 * processing for the association phase and that data connection is
340 * fully configured.
341 */
342 WPA_COMPLETED
343 };
344
345 #define MLME_SETPROTECTION_PROTECT_TYPE_NONE 0
346 #define MLME_SETPROTECTION_PROTECT_TYPE_RX 1
347 #define MLME_SETPROTECTION_PROTECT_TYPE_TX 2
348 #define MLME_SETPROTECTION_PROTECT_TYPE_RX_TX 3
349
350 #define MLME_SETPROTECTION_KEY_TYPE_GROUP 0
351 #define MLME_SETPROTECTION_KEY_TYPE_PAIRWISE 1
352
353
354 /**
355 * enum mfp_options - Management frame protection (IEEE 802.11w) options
356 */
357 enum mfp_options {
358 NO_MGMT_FRAME_PROTECTION = 0,
359 MGMT_FRAME_PROTECTION_OPTIONAL = 1,
360 MGMT_FRAME_PROTECTION_REQUIRED = 2,
361 };
362 #define MGMT_FRAME_PROTECTION_DEFAULT 3
363
364 /**
365 * enum hostapd_hw_mode - Hardware mode
366 */
367 enum hostapd_hw_mode {
368 HOSTAPD_MODE_IEEE80211B,
369 HOSTAPD_MODE_IEEE80211G,
370 HOSTAPD_MODE_IEEE80211A,
371 HOSTAPD_MODE_IEEE80211AD,
372 HOSTAPD_MODE_IEEE80211ANY,
373 NUM_HOSTAPD_MODES
374 };
375
376 /**
377 * enum wpa_ctrl_req_type - Control interface request types
378 */
379 enum wpa_ctrl_req_type {
380 WPA_CTRL_REQ_UNKNOWN,
381 WPA_CTRL_REQ_EAP_IDENTITY,
382 WPA_CTRL_REQ_EAP_PASSWORD,
383 WPA_CTRL_REQ_EAP_NEW_PASSWORD,
384 WPA_CTRL_REQ_EAP_PIN,
385 WPA_CTRL_REQ_EAP_OTP,
386 WPA_CTRL_REQ_EAP_PASSPHRASE,
387 WPA_CTRL_REQ_SIM,
388 WPA_CTRL_REQ_PSK_PASSPHRASE,
389 WPA_CTRL_REQ_EXT_CERT_CHECK,
390 NUM_WPA_CTRL_REQS
391 };
392
393 /* Maximum number of EAP methods to store for EAP server user information */
394 #define EAP_MAX_METHODS 8
395
396 enum mesh_plink_state {
397 PLINK_IDLE = 1,
398 PLINK_OPN_SNT,
399 PLINK_OPN_RCVD,
400 PLINK_CNF_RCVD,
401 PLINK_ESTAB,
402 PLINK_HOLDING,
403 PLINK_BLOCKED, /* not defined in the IEEE 802.11 standard */
404 };
405
406 enum set_band {
407 WPA_SETBAND_AUTO = 0,
408 WPA_SETBAND_5G = BIT(0),
409 WPA_SETBAND_2G = BIT(1),
410 WPA_SETBAND_6G = BIT(2),
411 };
412
413 enum wpa_radio_work_band {
414 BAND_2_4_GHZ = BIT(0),
415 BAND_5_GHZ = BIT(1),
416 BAND_60_GHZ = BIT(2),
417 };
418
419 enum beacon_rate_type {
420 BEACON_RATE_LEGACY,
421 BEACON_RATE_HT,
422 BEACON_RATE_VHT,
423 BEACON_RATE_HE
424 };
425
426 enum eap_proxy_sim_state {
427 SIM_STATE_ERROR,
428 };
429
430 #define OCE_STA BIT(0)
431 #define OCE_STA_CFON BIT(1)
432 #define OCE_AP BIT(2)
433
434 /* enum chan_width - Channel width definitions */
435 enum chan_width {
436 CHAN_WIDTH_20_NOHT,
437 CHAN_WIDTH_20,
438 CHAN_WIDTH_40,
439 CHAN_WIDTH_80,
440 CHAN_WIDTH_80P80,
441 CHAN_WIDTH_160,
442 CHAN_WIDTH_2160,
443 CHAN_WIDTH_4320,
444 CHAN_WIDTH_6480,
445 CHAN_WIDTH_8640,
446 CHAN_WIDTH_UNKNOWN
447 };
448
449 enum key_flag {
450 KEY_FLAG_MODIFY = BIT(0),
451 KEY_FLAG_DEFAULT = BIT(1),
452 KEY_FLAG_RX = BIT(2),
453 KEY_FLAG_TX = BIT(3),
454 KEY_FLAG_GROUP = BIT(4),
455 KEY_FLAG_PAIRWISE = BIT(5),
456 KEY_FLAG_PMK = BIT(6),
457 /* Used flag combinations */
458 KEY_FLAG_RX_TX = KEY_FLAG_RX | KEY_FLAG_TX,
459 KEY_FLAG_GROUP_RX_TX = KEY_FLAG_GROUP | KEY_FLAG_RX_TX,
460 KEY_FLAG_GROUP_RX_TX_DEFAULT = KEY_FLAG_GROUP_RX_TX |
461 KEY_FLAG_DEFAULT,
462 KEY_FLAG_GROUP_RX = KEY_FLAG_GROUP | KEY_FLAG_RX,
463 KEY_FLAG_GROUP_TX_DEFAULT = KEY_FLAG_GROUP | KEY_FLAG_TX |
464 KEY_FLAG_DEFAULT,
465 KEY_FLAG_PAIRWISE_RX_TX = KEY_FLAG_PAIRWISE | KEY_FLAG_RX_TX,
466 KEY_FLAG_PAIRWISE_RX = KEY_FLAG_PAIRWISE | KEY_FLAG_RX,
467 KEY_FLAG_PAIRWISE_RX_TX_MODIFY = KEY_FLAG_PAIRWISE_RX_TX |
468 KEY_FLAG_MODIFY,
469 /* Max allowed flags for each key type */
470 KEY_FLAG_PAIRWISE_MASK = KEY_FLAG_PAIRWISE_RX_TX_MODIFY,
471 KEY_FLAG_GROUP_MASK = KEY_FLAG_GROUP_RX_TX_DEFAULT,
472 KEY_FLAG_PMK_MASK = KEY_FLAG_PMK,
473 };
474
check_key_flag(enum key_flag key_flag)475 static inline int check_key_flag(enum key_flag key_flag)
476 {
477 return !!(!key_flag ||
478 ((key_flag & (KEY_FLAG_PAIRWISE | KEY_FLAG_MODIFY)) &&
479 (key_flag & ~KEY_FLAG_PAIRWISE_MASK)) ||
480 ((key_flag & KEY_FLAG_GROUP) &&
481 (key_flag & ~KEY_FLAG_GROUP_MASK)) ||
482 ((key_flag & KEY_FLAG_PMK) &&
483 (key_flag & ~KEY_FLAG_PMK_MASK)));
484 }
485
486 enum ptk0_rekey_handling {
487 PTK0_REKEY_ALLOW_ALWAYS,
488 PTK0_REKEY_ALLOW_LOCAL_OK,
489 PTK0_REKEY_ALLOW_NEVER
490 };
491
492 #endif /* DEFS_H */
493