wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
wpa_i.h
Go to the documentation of this file.
1 
5 #ifndef WPA_I_H
6 #define WPA_I_H
7 
8 #include "utils/list.h"
9 
10 struct wpa_peerkey;
11 struct wpa_tdls_peer;
12 struct wpa_eapol_key;
13 
18 struct wpa_sm {
19  u8 pmk[PMK_LEN];
20  size_t pmk_len;
21  struct wpa_ptk ptk, tptk;
22  int ptk_set, tptk_set;
23  unsigned int msg_3_of_4_ok:1;
24  u8 snonce[WPA_NONCE_LEN];
25  u8 anonce[WPA_NONCE_LEN]; /* ANonce from the last 1/4 msg */
26  int renew_snonce;
27  u8 rx_replay_counter[WPA_REPLAY_COUNTER_LEN];
28  int rx_replay_counter_set;
29  u8 request_counter[WPA_REPLAY_COUNTER_LEN];
30 
31  struct eapol_sm *eapol; /* EAPOL state machine from upper level code */
32 
33  struct rsn_pmksa_cache *pmksa; /* PMKSA cache */
34  struct rsn_pmksa_cache_entry *cur_pmksa; /* current PMKSA entry */
35  struct dl_list pmksa_candidates;
36 
37  struct l2_packet_data *l2_preauth;
38  struct l2_packet_data *l2_preauth_br;
39  struct l2_packet_data *l2_tdls;
40  u8 preauth_bssid[ETH_ALEN]; /* current RSN pre-auth peer or
41  * 00:00:00:00:00:00 if no pre-auth is
42  * in progress */
43  struct eapol_sm *preauth_eapol;
44 
45  struct wpa_sm_ctx *ctx;
46 
47  void *scard_ctx; /* context for smartcard callbacks */
48  int fast_reauth; /* whether EAP fast re-authentication is enabled */
49 
50  void *network_ctx;
51  int peerkey_enabled;
52  int allowed_pairwise_cipher; /* bitfield of WPA_CIPHER_* */
53  int proactive_key_caching;
54  int eap_workaround;
55  void *eap_conf_ctx;
56  u8 ssid[32];
57  size_t ssid_len;
58  int wpa_ptk_rekey;
59  int p2p;
60 
61  u8 own_addr[ETH_ALEN];
62  const char *ifname;
63  const char *bridge_ifname;
64  u8 bssid[ETH_ALEN];
65 
66  unsigned int dot11RSNAConfigPMKLifetime;
67  unsigned int dot11RSNAConfigPMKReauthThreshold;
68  unsigned int dot11RSNAConfigSATimeout;
69 
70  unsigned int dot11RSNA4WayHandshakeFailures;
71 
72  /* Selected configuration (based on Beacon/ProbeResp WPA IE) */
73  unsigned int proto;
74  unsigned int pairwise_cipher;
75  unsigned int group_cipher;
76  unsigned int key_mgmt;
77  unsigned int mgmt_group_cipher;
78 
79  int rsn_enabled; /* Whether RSN is enabled in configuration */
80  int mfp; /* 0 = disabled, 1 = optional, 2 = mandatory */
81 
82  u8 *assoc_wpa_ie; /* Own WPA/RSN IE from (Re)AssocReq */
83  size_t assoc_wpa_ie_len;
84  u8 *ap_wpa_ie, *ap_rsn_ie;
85  size_t ap_wpa_ie_len, ap_rsn_ie_len;
86 
87 #ifdef CONFIG_PEERKEY
88  struct wpa_peerkey *peerkey;
89 #endif /* CONFIG_PEERKEY */
90 #ifdef CONFIG_TDLS
91  struct wpa_tdls_peer *tdls;
92  int tdls_prohibited;
93  int tdls_chan_switch_prohibited;
94  int tdls_disabled;
95 
96  /* The driver supports TDLS */
97  int tdls_supported;
98 
99  /*
100  * The driver requires explicit discovery/setup/teardown frames sent
101  * to it via tdls_mgmt.
102  */
103  int tdls_external_setup;
104 
105  /* The driver supports TDLS channel switching */
106  int tdls_chan_switch;
107 #endif /* CONFIG_TDLS */
108 
109 #ifdef CONFIG_IEEE80211R
110  u8 xxkey[PMK_LEN]; /* PSK or the second 256 bits of MSK */
111  size_t xxkey_len;
112  u8 pmk_r0[PMK_LEN];
113  u8 pmk_r0_name[WPA_PMK_NAME_LEN];
114  u8 pmk_r1[PMK_LEN];
115  u8 pmk_r1_name[WPA_PMK_NAME_LEN];
116  u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
117  u8 r0kh_id[FT_R0KH_ID_MAX_LEN];
118  size_t r0kh_id_len;
119  u8 r1kh_id[FT_R1KH_ID_LEN];
120  int ft_completed;
121  int over_the_ds_in_progress;
122  u8 target_ap[ETH_ALEN]; /* over-the-DS target AP */
123  int set_ptk_after_assoc;
124  u8 mdie_ft_capab; /* FT Capability and Policy from target AP MDIE */
125  u8 *assoc_resp_ies; /* MDIE and FTIE from (Re)Association Response */
126  size_t assoc_resp_ies_len;
127 #endif /* CONFIG_IEEE80211R */
128 
129 #ifdef CONFIG_P2P
130  u8 p2p_ip_addr[3 * 4];
131 #endif /* CONFIG_P2P */
132 };
133 
134 
135 static inline void wpa_sm_set_state(struct wpa_sm *sm, enum wpa_states state)
136 {
137  WPA_ASSERT(sm->ctx->set_state);
138  sm->ctx->set_state(sm->ctx->ctx, state);
139 }
140 
141 static inline enum wpa_states wpa_sm_get_state(struct wpa_sm *sm)
142 {
143  WPA_ASSERT(sm->ctx->get_state);
144  return sm->ctx->get_state(sm->ctx->ctx);
145 }
146 
147 static inline void wpa_sm_deauthenticate(struct wpa_sm *sm, int reason_code)
148 {
149  WPA_ASSERT(sm->ctx->deauthenticate);
150  sm->ctx->deauthenticate(sm->ctx->ctx, reason_code);
151 }
152 
153 static inline int wpa_sm_set_key(struct wpa_sm *sm, enum wpa_alg alg,
154  const u8 *addr, int key_idx, int set_tx,
155  const u8 *seq, size_t seq_len,
156  const u8 *key, size_t key_len)
157 {
158  WPA_ASSERT(sm->ctx->set_key);
159  return sm->ctx->set_key(sm->ctx->ctx, alg, addr, key_idx, set_tx,
160  seq, seq_len, key, key_len);
161 }
162 
163 static inline void * wpa_sm_get_network_ctx(struct wpa_sm *sm)
164 {
165  WPA_ASSERT(sm->ctx->get_network_ctx);
166  return sm->ctx->get_network_ctx(sm->ctx->ctx);
167 }
168 
169 static inline int wpa_sm_get_bssid(struct wpa_sm *sm, u8 *bssid)
170 {
171  WPA_ASSERT(sm->ctx->get_bssid);
172  return sm->ctx->get_bssid(sm->ctx->ctx, bssid);
173 }
174 
175 static inline int wpa_sm_ether_send(struct wpa_sm *sm, const u8 *dest,
176  u16 proto, const u8 *buf, size_t len)
177 {
178  WPA_ASSERT(sm->ctx->ether_send);
179  return sm->ctx->ether_send(sm->ctx->ctx, dest, proto, buf, len);
180 }
181 
182 static inline int wpa_sm_get_beacon_ie(struct wpa_sm *sm)
183 {
184  WPA_ASSERT(sm->ctx->get_beacon_ie);
185  return sm->ctx->get_beacon_ie(sm->ctx->ctx);
186 }
187 
188 static inline void wpa_sm_cancel_auth_timeout(struct wpa_sm *sm)
189 {
190  WPA_ASSERT(sm->ctx->cancel_auth_timeout);
191  sm->ctx->cancel_auth_timeout(sm->ctx->ctx);
192 }
193 
194 static inline u8 * wpa_sm_alloc_eapol(struct wpa_sm *sm, u8 type,
195  const void *data, u16 data_len,
196  size_t *msg_len, void **data_pos)
197 {
198  WPA_ASSERT(sm->ctx->alloc_eapol);
199  return sm->ctx->alloc_eapol(sm->ctx->ctx, type, data, data_len,
200  msg_len, data_pos);
201 }
202 
203 static inline int wpa_sm_add_pmkid(struct wpa_sm *sm, const u8 *bssid,
204  const u8 *pmkid)
205 {
206  WPA_ASSERT(sm->ctx->add_pmkid);
207  return sm->ctx->add_pmkid(sm->ctx->ctx, bssid, pmkid);
208 }
209 
210 static inline int wpa_sm_remove_pmkid(struct wpa_sm *sm, const u8 *bssid,
211  const u8 *pmkid)
212 {
213  WPA_ASSERT(sm->ctx->remove_pmkid);
214  return sm->ctx->remove_pmkid(sm->ctx->ctx, bssid, pmkid);
215 }
216 
217 static inline int wpa_sm_mlme_setprotection(struct wpa_sm *sm, const u8 *addr,
218  int protect_type, int key_type)
219 {
220  WPA_ASSERT(sm->ctx->mlme_setprotection);
221  return sm->ctx->mlme_setprotection(sm->ctx->ctx, addr, protect_type,
222  key_type);
223 }
224 
225 static inline int wpa_sm_update_ft_ies(struct wpa_sm *sm, const u8 *md,
226  const u8 *ies, size_t ies_len)
227 {
228  if (sm->ctx->update_ft_ies)
229  return sm->ctx->update_ft_ies(sm->ctx->ctx, md, ies, ies_len);
230  return -1;
231 }
232 
233 static inline int wpa_sm_send_ft_action(struct wpa_sm *sm, u8 action,
234  const u8 *target_ap,
235  const u8 *ies, size_t ies_len)
236 {
237  if (sm->ctx->send_ft_action)
238  return sm->ctx->send_ft_action(sm->ctx->ctx, action, target_ap,
239  ies, ies_len);
240  return -1;
241 }
242 
243 static inline int wpa_sm_mark_authenticated(struct wpa_sm *sm,
244  const u8 *target_ap)
245 {
246  if (sm->ctx->mark_authenticated)
247  return sm->ctx->mark_authenticated(sm->ctx->ctx, target_ap);
248  return -1;
249 }
250 
251 static inline void wpa_sm_set_rekey_offload(struct wpa_sm *sm)
252 {
253  if (!sm->ctx->set_rekey_offload)
254  return;
255  sm->ctx->set_rekey_offload(sm->ctx->ctx, sm->ptk.kek, sm->ptk.kek_len,
256  sm->ptk.kck, sm->ptk.kck_len,
257  sm->rx_replay_counter);
258 }
259 
260 #ifdef CONFIG_TDLS
261 static inline int wpa_sm_tdls_get_capa(struct wpa_sm *sm,
262  int *tdls_supported,
263  int *tdls_ext_setup,
264  int *tdls_chan_switch)
265 {
266  if (sm->ctx->tdls_get_capa)
267  return sm->ctx->tdls_get_capa(sm->ctx->ctx, tdls_supported,
268  tdls_ext_setup, tdls_chan_switch);
269  return -1;
270 }
271 
272 static inline int wpa_sm_send_tdls_mgmt(struct wpa_sm *sm, const u8 *dst,
273  u8 action_code, u8 dialog_token,
274  u16 status_code, u32 peer_capab,
275  int initiator, const u8 *buf,
276  size_t len)
277 {
278  if (sm->ctx->send_tdls_mgmt)
279  return sm->ctx->send_tdls_mgmt(sm->ctx->ctx, dst, action_code,
280  dialog_token, status_code,
281  peer_capab, initiator, buf,
282  len);
283  return -1;
284 }
285 
286 static inline int wpa_sm_tdls_oper(struct wpa_sm *sm, int oper,
287  const u8 *peer)
288 {
289  if (sm->ctx->tdls_oper)
290  return sm->ctx->tdls_oper(sm->ctx->ctx, oper, peer);
291  return -1;
292 }
293 
294 static inline int
295 wpa_sm_tdls_peer_addset(struct wpa_sm *sm, const u8 *addr, int add,
296  u16 aid, u16 capability, const u8 *supp_rates,
297  size_t supp_rates_len,
298  const struct ieee80211_ht_capabilities *ht_capab,
299  const struct ieee80211_vht_capabilities *vht_capab,
300  u8 qosinfo, int wmm, const u8 *ext_capab,
301  size_t ext_capab_len, const u8 *supp_channels,
302  size_t supp_channels_len, const u8 *supp_oper_classes,
303  size_t supp_oper_classes_len)
304 {
305  if (sm->ctx->tdls_peer_addset)
306  return sm->ctx->tdls_peer_addset(sm->ctx->ctx, addr, add,
307  aid, capability, supp_rates,
308  supp_rates_len, ht_capab,
309  vht_capab, qosinfo, wmm,
310  ext_capab, ext_capab_len,
311  supp_channels,
312  supp_channels_len,
313  supp_oper_classes,
314  supp_oper_classes_len);
315  return -1;
316 }
317 
318 static inline int
319 wpa_sm_tdls_enable_channel_switch(struct wpa_sm *sm, const u8 *addr,
320  u8 oper_class,
321  const struct hostapd_freq_params *freq_params)
322 {
323  if (sm->ctx->tdls_enable_channel_switch)
324  return sm->ctx->tdls_enable_channel_switch(sm->ctx->ctx, addr,
325  oper_class,
326  freq_params);
327  return -1;
328 }
329 
330 static inline int
331 wpa_sm_tdls_disable_channel_switch(struct wpa_sm *sm, const u8 *addr)
332 {
333  if (sm->ctx->tdls_disable_channel_switch)
334  return sm->ctx->tdls_disable_channel_switch(sm->ctx->ctx, addr);
335  return -1;
336 }
337 #endif /* CONFIG_TDLS */
338 
339 static inline int wpa_sm_key_mgmt_set_pmk(struct wpa_sm *sm,
340  const u8 *pmk, size_t pmk_len)
341 {
342  if (!sm->proactive_key_caching)
343  return 0;
344  if (!sm->ctx->key_mgmt_set_pmk)
345  return -1;
346  return sm->ctx->key_mgmt_set_pmk(sm->ctx->ctx, pmk, pmk_len);
347 }
348 
349 void wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck, size_t kck_len,
350  int ver, const u8 *dest, u16 proto,
351  u8 *msg, size_t msg_len, u8 *key_mic);
352 int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst,
353  const struct wpa_eapol_key *key,
354  int ver, const u8 *nonce,
355  const u8 *wpa_ie, size_t wpa_ie_len,
356  struct wpa_ptk *ptk);
357 int wpa_supplicant_send_4_of_4(struct wpa_sm *sm, const unsigned char *dst,
358  const struct wpa_eapol_key *key,
359  u16 ver, u16 key_info,
360  struct wpa_ptk *ptk);
361 
362 int wpa_derive_ptk_ft(struct wpa_sm *sm, const unsigned char *src_addr,
363  const struct wpa_eapol_key *key, struct wpa_ptk *ptk);
364 
365 void wpa_tdls_assoc(struct wpa_sm *sm);
366 void wpa_tdls_disassoc(struct wpa_sm *sm);
367 
368 #endif /* WPA_I_H */
int wpa_supplicant_send_4_of_4(struct wpa_sm *sm, const unsigned char *dst, const struct wpa_eapol_key *key, u16 ver, u16 key_info, struct wpa_ptk *ptk)
Send message 4 of WPA/RSN 4-Way Handshake.
Definition: wpa.c:1087
int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst, const struct wpa_eapol_key *key, int ver, const u8 *nonce, const u8 *wpa_ie, size_t wpa_ie_len, struct wpa_ptk *ptk)
Send message 2 of WPA/RSN 4-Way Handshake.
Definition: wpa.c:319
void wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck, size_t kck_len, int ver, const u8 *dest, u16 proto, u8 *msg, size_t msg_len, u8 *key_mic)
Send WPA/RSN EAPOL-Key message.
Definition: wpa.c:34
Definition: ieee802_11_defs.h:634
Definition: pmksa_cache_auth.c:20
Definition: wpa.h:18
wpa_states
wpa_supplicant state
Definition: defs.h:161
Definition: ieee802_11_defs.h:668
Definition: l2_packet_freebsd.c:32
Definition: wpa_common.h:166
WPA Pairwise Transient Key IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy.
Definition: wpa_common.h:205
Doubly-linked list.
Doubly-linked list.
Definition: list.h:12
PMKSA cache entry.
Definition: pmksa_cache_auth.h:14
Definition: peerkey.h:9
Internal data for EAPOL state machines.
Definition: eapol_supp_sm.c:28
Channel parameters.
Definition: driver.h:510
Internal WPA state machine data.
Definition: wpa_i.h:18
Definition: tdls.c:91