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