Home | History | Annotate | Line # | Download | only in ap
      1 /*
      2  * hostapd - IEEE 802.11i-2004 / WPA Authenticator: Internal definitions
      3  * Copyright (c) 2004-2015, Jouni Malinen <j (at) 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 WPA_AUTH_I_H
     10 #define WPA_AUTH_I_H
     11 
     12 #include "utils/list.h"
     13 
     14 /* max(dot11RSNAConfigGroupUpdateCount,dot11RSNAConfigPairwiseUpdateCount) */
     15 #define RSNA_MAX_EAPOL_RETRIES 4
     16 
     17 struct wpa_group;
     18 
     19 struct wpa_state_machine {
     20 	struct wpa_authenticator *wpa_auth;
     21 	struct wpa_group *group;
     22 
     23 	u8 addr[ETH_ALEN];
     24 	u8 p2p_dev_addr[ETH_ALEN];
     25 	u16 auth_alg;
     26 
     27 	enum {
     28 		WPA_PTK_INITIALIZE, WPA_PTK_DISCONNECT, WPA_PTK_DISCONNECTED,
     29 		WPA_PTK_AUTHENTICATION, WPA_PTK_AUTHENTICATION2,
     30 		WPA_PTK_INITPMK, WPA_PTK_INITPSK, WPA_PTK_PTKSTART,
     31 		WPA_PTK_PTKCALCNEGOTIATING, WPA_PTK_PTKCALCNEGOTIATING2,
     32 		WPA_PTK_PTKINITNEGOTIATING, WPA_PTK_PTKINITDONE
     33 	} wpa_ptk_state;
     34 
     35 	enum {
     36 		WPA_PTK_GROUP_IDLE = 0,
     37 		WPA_PTK_GROUP_REKEYNEGOTIATING,
     38 		WPA_PTK_GROUP_REKEYESTABLISHED,
     39 		WPA_PTK_GROUP_KEYERROR
     40 	} wpa_ptk_group_state;
     41 
     42 	bool Init;
     43 	bool DeauthenticationRequest;
     44 	bool AuthenticationRequest;
     45 	bool ReAuthenticationRequest;
     46 	bool Disconnect;
     47 	u16 disconnect_reason; /* specific reason code to use with Disconnect */
     48 	u32 TimeoutCtr;
     49 	u32 GTimeoutCtr;
     50 	bool TimeoutEvt;
     51 	bool EAPOLKeyReceived;
     52 	bool EAPOLKeyPairwise;
     53 	bool EAPOLKeyRequest;
     54 	bool MICVerified;
     55 	bool GUpdateStationKeys;
     56 	u8 ANonce[WPA_NONCE_LEN];
     57 	u8 SNonce[WPA_NONCE_LEN];
     58 	u8 alt_SNonce[WPA_NONCE_LEN];
     59 	u8 alt_replay_counter[WPA_REPLAY_COUNTER_LEN];
     60 	u8 PMK[PMK_LEN_MAX];
     61 	unsigned int pmk_len;
     62 	u8 pmkid[PMKID_LEN]; /* valid if pmkid_set == 1 */
     63 	struct wpa_ptk PTK;
     64 	u8 keyidx_active;
     65 	bool use_ext_key_id;
     66 	bool PTK_valid;
     67 	bool pairwise_set;
     68 	bool tk_already_set;
     69 	int keycount;
     70 	bool Pair;
     71 	struct wpa_key_replay_counter {
     72 		u8 counter[WPA_REPLAY_COUNTER_LEN];
     73 		bool valid;
     74 	} key_replay[RSNA_MAX_EAPOL_RETRIES],
     75 		prev_key_replay[RSNA_MAX_EAPOL_RETRIES];
     76 	bool PInitAKeys; /* WPA only, not in IEEE 802.11i */
     77 	bool PTKRequest; /* not in IEEE 802.11i state machine */
     78 	bool has_GTK;
     79 	bool PtkGroupInit; /* init request for PTK Group state machine */
     80 
     81 	u8 *last_rx_eapol_key; /* starting from IEEE 802.1X header */
     82 	size_t last_rx_eapol_key_len;
     83 
     84 	unsigned int changed:1;
     85 	unsigned int in_step_loop:1;
     86 	unsigned int pending_deinit:1;
     87 	unsigned int started:1;
     88 	unsigned int mgmt_frame_prot:1;
     89 	unsigned int mfpr:1;
     90 	unsigned int rx_eapol_key_secure:1;
     91 	unsigned int update_snonce:1;
     92 	unsigned int alt_snonce_valid:1;
     93 	unsigned int waiting_radius_psk:1;
     94 #ifdef CONFIG_IEEE80211R_AP
     95 	unsigned int ft_completed:1;
     96 	unsigned int pmk_r1_name_valid:1;
     97 #endif /* CONFIG_IEEE80211R_AP */
     98 	unsigned int is_wnmsleep:1;
     99 	unsigned int pmkid_set:1;
    100 
    101 	unsigned int ptkstart_without_success;
    102 
    103 #ifdef CONFIG_OCV
    104 	int ocv_enabled;
    105 #endif /* CONFIG_OCV */
    106 
    107 	u8 req_replay_counter[WPA_REPLAY_COUNTER_LEN];
    108 	int req_replay_counter_used;
    109 
    110 	u8 *wpa_ie;
    111 	size_t wpa_ie_len;
    112 	u8 *rsnxe;
    113 	size_t rsnxe_len;
    114 
    115 	enum {
    116 		WPA_VERSION_NO_WPA = 0 /* WPA not used */,
    117 		WPA_VERSION_WPA = 1 /* WPA / IEEE 802.11i/D3.0 */,
    118 		WPA_VERSION_WPA2 = 2 /* WPA2 / IEEE 802.11i */
    119 	} wpa;
    120 	int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */
    121 	int wpa_key_mgmt; /* the selected WPA_KEY_MGMT_* */
    122 	struct rsn_pmksa_cache_entry *pmksa;
    123 
    124 	u32 dot11RSNAStatsTKIPLocalMICFailures;
    125 	u32 dot11RSNAStatsTKIPRemoteMICFailures;
    126 
    127 #ifdef CONFIG_IEEE80211R_AP
    128 	u8 xxkey[PMK_LEN_MAX]; /* PSK or the second 256 bits of MSK, or the
    129 				* first 384 bits of MSK */
    130 	size_t xxkey_len;
    131 	u8 pmk_r1[PMK_LEN_MAX];
    132 	unsigned int pmk_r1_len;
    133 	u8 pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name derived from FT Auth
    134 					   * Request */
    135 	u8 r0kh_id[FT_R0KH_ID_MAX_LEN]; /* R0KH-ID from FT Auth Request */
    136 	size_t r0kh_id_len;
    137 	u8 *assoc_resp_ftie;
    138 
    139 	void (*ft_pending_cb)(void *ctx, const u8 *dst,
    140 			      u16 auth_transaction, u16 status,
    141 			      const u8 *ies, size_t ies_len);
    142 	void *ft_pending_cb_ctx;
    143 	struct wpabuf *ft_pending_req_ies;
    144 	u8 ft_pending_pull_nonce[FT_RRB_NONCE_LEN];
    145 	u8 ft_pending_auth_transaction;
    146 	u8 ft_pending_current_ap[ETH_ALEN];
    147 	int ft_pending_pull_left_retries;
    148 #endif /* CONFIG_IEEE80211R_AP */
    149 
    150 	int pending_1_of_4_timeout;
    151 
    152 #ifdef CONFIG_P2P
    153 	u8 ip_addr[4];
    154 	unsigned int ip_addr_bit;
    155 #endif /* CONFIG_P2P */
    156 
    157 #ifdef CONFIG_FILS
    158 	u8 fils_key_auth_sta[FILS_MAX_KEY_AUTH_LEN];
    159 	u8 fils_key_auth_ap[FILS_MAX_KEY_AUTH_LEN];
    160 	size_t fils_key_auth_len;
    161 	unsigned int fils_completed:1;
    162 #endif /* CONFIG_FILS */
    163 
    164 #ifdef CONFIG_DPP2
    165 	struct wpabuf *dpp_z;
    166 #endif /* CONFIG_DPP2 */
    167 
    168 #ifdef CONFIG_TESTING_OPTIONS
    169 	void (*eapol_status_cb)(void *ctx1, void *ctx2);
    170 	void *eapol_status_cb_ctx1;
    171 	void *eapol_status_cb_ctx2;
    172 #endif /* CONFIG_TESTING_OPTIONS */
    173 
    174 #ifdef CONFIG_IEEE80211BE
    175 	u8 peer_mld_addr[ETH_ALEN];
    176 	s8 mld_assoc_link_id;
    177 	u8 n_mld_affiliated_links;
    178 
    179 	struct mld_link {
    180 		bool valid;
    181 		u8 peer_addr[ETH_ALEN];
    182 
    183 		struct wpa_authenticator *wpa_auth;
    184 	} mld_links[MAX_NUM_MLD_LINKS];
    185 #endif /* CONFIG_IEEE80211BE */
    186 
    187 	bool ssid_protection;
    188 };
    189 
    190 
    191 /* per group key state machine data */
    192 struct wpa_group {
    193 	struct wpa_group *next;
    194 	int vlan_id;
    195 
    196 	bool GInit;
    197 	int GKeyDoneStations;
    198 	bool GTKReKey;
    199 	int GTK_len;
    200 	int GN, GM;
    201 	bool GTKAuthenticator;
    202 	u8 Counter[WPA_NONCE_LEN];
    203 
    204 	enum {
    205 		WPA_GROUP_GTK_INIT = 0,
    206 		WPA_GROUP_SETKEYS, WPA_GROUP_SETKEYSDONE,
    207 		WPA_GROUP_FATAL_FAILURE
    208 	} wpa_group_state;
    209 
    210 	u8 GMK[WPA_GMK_LEN];
    211 	u8 GTK[2][WPA_GTK_MAX_LEN];
    212 	u8 GNonce[WPA_NONCE_LEN];
    213 	bool changed;
    214 	bool first_sta_seen;
    215 	bool reject_4way_hs_for_entropy;
    216 	u8 IGTK[2][WPA_IGTK_MAX_LEN];
    217 	u8 BIGTK[2][WPA_IGTK_MAX_LEN];
    218 	int GN_igtk, GM_igtk;
    219 	int GN_bigtk, GM_bigtk;
    220 	bool bigtk_set;
    221 	bool bigtk_configured;
    222 	/* Number of references except those in struct wpa_group->next */
    223 	unsigned int references;
    224 	unsigned int num_setup_iface;
    225 };
    226 
    227 
    228 struct wpa_ft_pmk_cache;
    229 
    230 /* per authenticator data */
    231 struct wpa_authenticator {
    232 	struct wpa_group *group;
    233 
    234 	unsigned int dot11RSNAStatsTKIPRemoteMICFailures;
    235 	u32 dot11RSNAAuthenticationSuiteSelected;
    236 	u32 dot11RSNAPairwiseCipherSelected;
    237 	u32 dot11RSNAGroupCipherSelected;
    238 	u8 dot11RSNAPMKIDUsed[PMKID_LEN];
    239 	u32 dot11RSNAAuthenticationSuiteRequested; /* FIX: update */
    240 	u32 dot11RSNAPairwiseCipherRequested; /* FIX: update */
    241 	u32 dot11RSNAGroupCipherRequested; /* FIX: update */
    242 	unsigned int dot11RSNATKIPCounterMeasuresInvoked;
    243 	unsigned int dot11RSNA4WayHandshakeFailures;
    244 
    245 	struct wpa_auth_config conf;
    246 	const struct wpa_auth_callbacks *cb;
    247 	void *cb_ctx;
    248 
    249 	u8 *wpa_ie;
    250 	size_t wpa_ie_len;
    251 
    252 	u8 addr[ETH_ALEN];
    253 
    254 	struct rsn_pmksa_cache *pmksa;
    255 	struct wpa_ft_pmk_cache *ft_pmk_cache;
    256 
    257 	bool non_tx_beacon_prot;
    258 
    259 #ifdef CONFIG_P2P
    260 	struct bitfield *ip_pool;
    261 #endif /* CONFIG_P2P */
    262 
    263 #ifdef CONFIG_IEEE80211BE
    264 	bool is_ml;
    265 	u8 mld_addr[ETH_ALEN];
    266 	u8 link_id;
    267 	bool primary_auth;
    268 #endif /* CONFIG_IEEE80211BE */
    269 };
    270 
    271 
    272 #ifdef CONFIG_IEEE80211R_AP
    273 
    274 #define FT_REMOTE_SEQ_BACKLOG 16
    275 struct ft_remote_seq_rx {
    276 	u32 dom;
    277 	struct os_reltime time_offset; /* local time - offset = remote time */
    278 
    279 	/* accepted sequence numbers: (offset ... offset + 0x40000000]
    280 	 *   (except those in last)
    281 	 * dropped sequence numbers: (offset - 0x40000000 ... offset]
    282 	 * all others trigger SEQ_REQ message (except first message)
    283 	 */
    284 	u32 last[FT_REMOTE_SEQ_BACKLOG];
    285 	unsigned int num_last;
    286 	u32 offsetidx;
    287 
    288 	struct dl_list queue; /* send nonces + rrb msgs awaiting seq resp */
    289 };
    290 
    291 struct ft_remote_seq_tx {
    292 	u32 dom; /* non zero if initialized */
    293 	u32 seq;
    294 };
    295 
    296 struct ft_remote_seq {
    297 	struct ft_remote_seq_rx rx;
    298 	struct ft_remote_seq_tx tx;
    299 };
    300 
    301 #endif /* CONFIG_IEEE80211R_AP */
    302 
    303 
    304 int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len,
    305 		     const u8 *pmkid);
    306 int wpa_write_rsnxe(struct wpa_auth_config *conf, u8 *buf, size_t len);
    307 void wpa_auth_logger(struct wpa_authenticator *wpa_auth, const u8 *addr,
    308 		     logger_level level, const char *txt);
    309 void wpa_auth_vlogger(struct wpa_authenticator *wpa_auth, const u8 *addr,
    310 		      logger_level level, const char *fmt, ...)
    311 	PRINTF_FORMAT(4, 5);
    312 void __wpa_send_eapol(struct wpa_authenticator *wpa_auth,
    313 		      struct wpa_state_machine *sm, int key_info,
    314 		      const u8 *key_rsc, const u8 *nonce,
    315 		      const u8 *kde, size_t kde_len,
    316 		      int keyidx, int encr, int force_version);
    317 int wpa_auth_for_each_sta(struct wpa_authenticator *wpa_auth,
    318 			  int (*cb)(struct wpa_state_machine *sm, void *ctx),
    319 			  void *cb_ctx);
    320 int wpa_auth_for_each_auth(struct wpa_authenticator *wpa_auth,
    321 			   int (*cb)(struct wpa_authenticator *a, void *ctx),
    322 			   void *cb_ctx);
    323 void wpa_auth_store_ptksa(struct wpa_authenticator *wpa_auth,
    324 			  const u8 *addr, int cipher,
    325 			  u32 life_time, const struct wpa_ptk *ptk);
    326 
    327 #ifdef CONFIG_IEEE80211R_AP
    328 int wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len);
    329 int wpa_write_ftie(struct wpa_auth_config *conf, int key_mgmt, size_t key_len,
    330 		   const u8 *r0kh_id, size_t r0kh_id_len,
    331 		   const u8 *anonce, const u8 *snonce,
    332 		   u8 *buf, size_t len, const u8 *subelem,
    333 		   size_t subelem_len, int rsnxe_used);
    334 int wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, struct wpa_ptk *ptk,
    335 			   u8 *pmk_r0, u8 *pmk_r1, u8 *pmk_r0_name,
    336 			   size_t *key_len, size_t kdk_len);
    337 void wpa_auth_ft_store_keys(struct wpa_state_machine *sm, const u8 *pmk_r0,
    338 			    const u8 *pmk_r1, const u8 *pmk_r0_name,
    339 			    size_t key_len);
    340 struct wpa_ft_pmk_cache * wpa_ft_pmk_cache_init(void);
    341 void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache *cache);
    342 void wpa_ft_install_ptk(struct wpa_state_machine *sm, int retry);
    343 int wpa_ft_store_pmk_fils(struct wpa_state_machine *sm, const u8 *pmk_r0,
    344 			  const u8 *pmk_r0_name);
    345 #endif /* CONFIG_IEEE80211R_AP */
    346 
    347 #endif /* WPA_AUTH_I_H */
    348