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