]>
Commit | Line | Data |
---|---|---|
b5b969e9 JM |
1 | /* |
2 | * hostapd / Callback functions for driver wrappers | |
94ddef3e | 3 | * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi> |
b5b969e9 | 4 | * |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
b5b969e9 JM |
7 | */ |
8 | ||
6226e38d | 9 | #include "utils/includes.h" |
b5b969e9 | 10 | |
6226e38d | 11 | #include "utils/common.h" |
9c47f6a2 | 12 | #include "utils/eloop.h" |
b5b969e9 | 13 | #include "radius/radius.h" |
6e6e8c31 | 14 | #include "drivers/driver.h" |
81f4f619 | 15 | #include "common/ieee802_11_defs.h" |
c41a1095 | 16 | #include "common/ieee802_11_common.h" |
3140803b | 17 | #include "common/wpa_ctrl.h" |
bbb921da | 18 | #include "crypto/random.h" |
ef796391 | 19 | #include "p2p/p2p.h" |
54f489be | 20 | #include "wps/wps.h" |
037378ff | 21 | #include "fst/fst.h" |
d32d94db | 22 | #include "wnm_ap.h" |
6226e38d JM |
23 | #include "hostapd.h" |
24 | #include "ieee802_11.h" | |
0603bcb7 | 25 | #include "ieee802_11_auth.h" |
6226e38d JM |
26 | #include "sta_info.h" |
27 | #include "accounting.h" | |
28 | #include "tkip_countermeasures.h" | |
6226e38d JM |
29 | #include "ieee802_1x.h" |
30 | #include "wpa_auth.h" | |
6226e38d | 31 | #include "wps_hostapd.h" |
51e2a27a | 32 | #include "ap_drv_ops.h" |
8b06c1ed | 33 | #include "ap_config.h" |
1b487b8b | 34 | #include "hw_features.h" |
e76da505 | 35 | #include "dfs.h" |
9c47f6a2 | 36 | #include "beacon.h" |
b5b969e9 JM |
37 | |
38 | ||
b5b969e9 | 39 | int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr, |
2bb20281 | 40 | const u8 *req_ies, size_t req_ies_len, int reassoc) |
b5b969e9 JM |
41 | { |
42 | struct sta_info *sta; | |
43 | int new_assoc, res; | |
c41a1095 | 44 | struct ieee802_11_elems elems; |
2bb20281 JM |
45 | const u8 *ie; |
46 | size_t ielen; | |
8659e333 | 47 | #if defined(CONFIG_IEEE80211R) || defined(CONFIG_IEEE80211W) |
88b32a99 SP |
48 | u8 buf[sizeof(struct ieee80211_mgmt) + 1024]; |
49 | u8 *p = buf; | |
8659e333 | 50 | #endif /* CONFIG_IEEE80211R || CONFIG_IEEE80211W */ |
08a74e6a | 51 | u16 reason = WLAN_REASON_UNSPECIFIED; |
88b32a99 | 52 | u16 status = WLAN_STATUS_SUCCESS; |
94ddef3e | 53 | const u8 *p2p_dev_addr = NULL; |
b5b969e9 | 54 | |
68532a9c JM |
55 | if (addr == NULL) { |
56 | /* | |
57 | * This could potentially happen with unexpected event from the | |
58 | * driver wrapper. This was seen at least in one case where the | |
59 | * driver ended up being set to station mode while hostapd was | |
60 | * running, so better make sure we stop processing such an | |
61 | * event here. | |
62 | */ | |
48b06c17 JM |
63 | wpa_printf(MSG_DEBUG, |
64 | "hostapd_notif_assoc: Skip event with no address"); | |
68532a9c JM |
65 | return -1; |
66 | } | |
bbb921da | 67 | random_add_randomness(addr, ETH_ALEN); |
68532a9c | 68 | |
b5b969e9 JM |
69 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, |
70 | HOSTAPD_LEVEL_INFO, "associated"); | |
71 | ||
2bb20281 | 72 | ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0); |
c41a1095 JM |
73 | if (elems.wps_ie) { |
74 | ie = elems.wps_ie - 2; | |
75 | ielen = elems.wps_ie_len + 2; | |
76 | wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq"); | |
77 | } else if (elems.rsn_ie) { | |
78 | ie = elems.rsn_ie - 2; | |
79 | ielen = elems.rsn_ie_len + 2; | |
80 | wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq"); | |
81 | } else if (elems.wpa_ie) { | |
82 | ie = elems.wpa_ie - 2; | |
83 | ielen = elems.wpa_ie_len + 2; | |
84 | wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq"); | |
a14896e8 JM |
85 | #ifdef CONFIG_HS20 |
86 | } else if (elems.osen) { | |
87 | ie = elems.osen - 2; | |
88 | ielen = elems.osen_len + 2; | |
89 | wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq"); | |
90 | #endif /* CONFIG_HS20 */ | |
c41a1095 JM |
91 | } else { |
92 | ie = NULL; | |
93 | ielen = 0; | |
48b06c17 JM |
94 | wpa_printf(MSG_DEBUG, |
95 | "STA did not include WPS/RSN/WPA IE in (Re)AssocReq"); | |
c41a1095 JM |
96 | } |
97 | ||
b5b969e9 JM |
98 | sta = ap_get_sta(hapd, addr); |
99 | if (sta) { | |
4331263b | 100 | ap_sta_no_session_timeout(hapd, sta); |
b5b969e9 | 101 | accounting_sta_stop(hapd, sta); |
c72bd6d4 JM |
102 | |
103 | /* | |
104 | * Make sure that the previously registered inactivity timer | |
105 | * will not remove the STA immediately. | |
106 | */ | |
107 | sta->timeout_next = STA_NULLFUNC; | |
b5b969e9 JM |
108 | } else { |
109 | sta = ap_sta_add(hapd, addr); | |
8bd0fc0e JM |
110 | if (sta == NULL) { |
111 | hostapd_drv_sta_disassoc(hapd, addr, | |
112 | WLAN_REASON_DISASSOC_AP_BUSY); | |
b5b969e9 | 113 | return -1; |
8bd0fc0e | 114 | } |
b5b969e9 | 115 | } |
17f6b900 | 116 | sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2); |
b5b969e9 | 117 | |
0603bcb7 AN |
118 | res = hostapd_check_acl(hapd, addr, NULL); |
119 | if (res != HOSTAPD_ACL_ACCEPT) { | |
120 | wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect", | |
121 | MAC2STR(addr)); | |
122 | reason = WLAN_REASON_UNSPECIFIED; | |
123 | goto fail; | |
124 | } | |
125 | ||
b305c684 JM |
126 | #ifdef CONFIG_P2P |
127 | if (elems.p2p) { | |
128 | wpabuf_free(sta->p2p_ie); | |
2bb20281 | 129 | sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len, |
b305c684 | 130 | P2P_IE_VENDOR_TYPE); |
94ddef3e JM |
131 | if (sta->p2p_ie) |
132 | p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie); | |
b305c684 JM |
133 | } |
134 | #endif /* CONFIG_P2P */ | |
135 | ||
9c47f6a2 PX |
136 | #ifdef CONFIG_IEEE80211N |
137 | #ifdef NEED_AP_MLME | |
138 | if (elems.ht_capabilities && | |
9c47f6a2 PX |
139 | (hapd->iface->conf->ht_capab & |
140 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) { | |
141 | struct ieee80211_ht_capabilities *ht_cap = | |
142 | (struct ieee80211_ht_capabilities *) | |
143 | elems.ht_capabilities; | |
144 | ||
145 | if (le_to_host16(ht_cap->ht_capabilities_info) & | |
146 | HT_CAP_INFO_40MHZ_INTOLERANT) | |
147 | ht40_intolerant_add(hapd->iface, sta); | |
148 | } | |
149 | #endif /* NEED_AP_MLME */ | |
150 | #endif /* CONFIG_IEEE80211N */ | |
151 | ||
c551700f KP |
152 | #ifdef CONFIG_INTERWORKING |
153 | if (elems.ext_capab && elems.ext_capab_len > 4) { | |
154 | if (elems.ext_capab[4] & 0x01) | |
155 | sta->qos_map_enabled = 1; | |
156 | } | |
157 | #endif /* CONFIG_INTERWORKING */ | |
158 | ||
f403dcd6 JM |
159 | #ifdef CONFIG_HS20 |
160 | wpabuf_free(sta->hs20_ie); | |
161 | if (elems.hs20 && elems.hs20_len > 4) { | |
162 | sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4, | |
163 | elems.hs20_len - 4); | |
164 | } else | |
165 | sta->hs20_ie = NULL; | |
166 | #endif /* CONFIG_HS20 */ | |
167 | ||
ae667c08 AN |
168 | #ifdef CONFIG_FST |
169 | wpabuf_free(sta->mb_ies); | |
170 | if (hapd->iface->fst) | |
171 | sta->mb_ies = mb_ies_by_info(&elems.mb_ies); | |
172 | else | |
173 | sta->mb_ies = NULL; | |
174 | #endif /* CONFIG_FST */ | |
175 | ||
b5b969e9 JM |
176 | if (hapd->conf->wpa) { |
177 | if (ie == NULL || ielen == 0) { | |
633d4469 | 178 | #ifdef CONFIG_WPS |
b5b969e9 | 179 | if (hapd->conf->wps_state) { |
48b06c17 JM |
180 | wpa_printf(MSG_DEBUG, |
181 | "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use"); | |
b5b969e9 JM |
182 | sta->flags |= WLAN_STA_MAYBE_WPS; |
183 | goto skip_wpa_check; | |
184 | } | |
633d4469 | 185 | #endif /* CONFIG_WPS */ |
b5b969e9 JM |
186 | |
187 | wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA"); | |
188 | return -1; | |
189 | } | |
633d4469 | 190 | #ifdef CONFIG_WPS |
b5b969e9 JM |
191 | if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 && |
192 | os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) { | |
17f6b900 | 193 | struct wpabuf *wps; |
48b06c17 | 194 | |
b5b969e9 | 195 | sta->flags |= WLAN_STA_WPS; |
17f6b900 JM |
196 | wps = ieee802_11_vendor_ie_concat(ie, ielen, |
197 | WPS_IE_VENDOR_TYPE); | |
198 | if (wps) { | |
199 | if (wps_is_20(wps)) { | |
48b06c17 JM |
200 | wpa_printf(MSG_DEBUG, |
201 | "WPS: STA supports WPS 2.0"); | |
17f6b900 JM |
202 | sta->flags |= WLAN_STA_WPS2; |
203 | } | |
204 | wpabuf_free(wps); | |
205 | } | |
b5b969e9 JM |
206 | goto skip_wpa_check; |
207 | } | |
633d4469 | 208 | #endif /* CONFIG_WPS */ |
b5b969e9 JM |
209 | |
210 | if (sta->wpa_sm == NULL) | |
211 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, | |
94ddef3e JM |
212 | sta->addr, |
213 | p2p_dev_addr); | |
b5b969e9 | 214 | if (sta->wpa_sm == NULL) { |
48b06c17 JM |
215 | wpa_printf(MSG_ERROR, |
216 | "Failed to initialize WPA state machine"); | |
b5b969e9 JM |
217 | return -1; |
218 | } | |
219 | res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, | |
88b32a99 SP |
220 | ie, ielen, |
221 | elems.mdie, elems.mdie_len); | |
b5b969e9 | 222 | if (res != WPA_IE_OK) { |
48b06c17 JM |
223 | wpa_printf(MSG_DEBUG, |
224 | "WPA/RSN information element rejected? (res %u)", | |
225 | res); | |
b5b969e9 | 226 | wpa_hexdump(MSG_DEBUG, "IE", ie, ielen); |
88b32a99 | 227 | if (res == WPA_INVALID_GROUP) { |
08a74e6a | 228 | reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID; |
88b32a99 SP |
229 | status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID; |
230 | } else if (res == WPA_INVALID_PAIRWISE) { | |
08a74e6a | 231 | reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID; |
88b32a99 SP |
232 | status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID; |
233 | } else if (res == WPA_INVALID_AKMP) { | |
08a74e6a | 234 | reason = WLAN_REASON_AKMP_NOT_VALID; |
88b32a99 SP |
235 | status = WLAN_STATUS_AKMP_NOT_VALID; |
236 | } | |
355d36a7 | 237 | #ifdef CONFIG_IEEE80211W |
88b32a99 | 238 | else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) { |
08a74e6a | 239 | reason = WLAN_REASON_INVALID_IE; |
88b32a99 SP |
240 | status = WLAN_STATUS_INVALID_IE; |
241 | } else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) { | |
08a74e6a | 242 | reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID; |
88b32a99 SP |
243 | status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID; |
244 | } | |
355d36a7 | 245 | #endif /* CONFIG_IEEE80211W */ |
88b32a99 | 246 | else { |
08a74e6a | 247 | reason = WLAN_REASON_INVALID_IE; |
88b32a99 SP |
248 | status = WLAN_STATUS_INVALID_IE; |
249 | } | |
08a74e6a | 250 | goto fail; |
b5b969e9 | 251 | } |
7d9c0cd3 MP |
252 | #ifdef CONFIG_IEEE80211W |
253 | if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out && | |
254 | sta->sa_query_count > 0) | |
255 | ap_check_sa_query_timeout(hapd, sta); | |
256 | if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out && | |
257 | (sta->auth_alg != WLAN_AUTH_FT)) { | |
258 | /* | |
259 | * STA has already been associated with MFP and SA | |
260 | * Query timeout has not been reached. Reject the | |
261 | * association attempt temporarily and start SA Query, | |
262 | * if one is not pending. | |
263 | */ | |
264 | ||
265 | if (sta->sa_query_count == 0) | |
266 | ap_sta_start_sa_query(hapd, sta); | |
267 | ||
7d9c0cd3 MP |
268 | status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY; |
269 | ||
270 | p = hostapd_eid_assoc_comeback_time(hapd, sta, p); | |
271 | ||
272 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, | |
273 | p - buf); | |
7d9c0cd3 MP |
274 | return 0; |
275 | } | |
276 | ||
277 | if (wpa_auth_uses_mfp(sta->wpa_sm)) | |
278 | sta->flags |= WLAN_STA_MFP; | |
279 | else | |
280 | sta->flags &= ~WLAN_STA_MFP; | |
281 | #endif /* CONFIG_IEEE80211W */ | |
282 | ||
88b32a99 SP |
283 | #ifdef CONFIG_IEEE80211R |
284 | if (sta->auth_alg == WLAN_AUTH_FT) { | |
285 | status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies, | |
286 | req_ies_len); | |
287 | if (status != WLAN_STATUS_SUCCESS) { | |
288 | if (status == WLAN_STATUS_INVALID_PMKID) | |
289 | reason = WLAN_REASON_INVALID_IE; | |
290 | if (status == WLAN_STATUS_INVALID_MDIE) | |
291 | reason = WLAN_REASON_INVALID_IE; | |
292 | if (status == WLAN_STATUS_INVALID_FTIE) | |
293 | reason = WLAN_REASON_INVALID_IE; | |
294 | goto fail; | |
295 | } | |
296 | } | |
297 | #endif /* CONFIG_IEEE80211R */ | |
a9aca28b | 298 | } else if (hapd->conf->wps_state) { |
633d4469 | 299 | #ifdef CONFIG_WPS |
17f6b900 | 300 | struct wpabuf *wps; |
48b06c17 | 301 | |
2bb20281 JM |
302 | if (req_ies) |
303 | wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len, | |
fa15d405 JM |
304 | WPS_IE_VENDOR_TYPE); |
305 | else | |
306 | wps = NULL; | |
54f489be | 307 | #ifdef CONFIG_WPS_STRICT |
fa15d405 | 308 | if (wps && wps_validate_assoc_req(wps) < 0) { |
08a74e6a | 309 | reason = WLAN_REASON_INVALID_IE; |
88b32a99 | 310 | status = WLAN_STATUS_INVALID_IE; |
fa15d405 | 311 | wpabuf_free(wps); |
08a74e6a | 312 | goto fail; |
54f489be | 313 | } |
54f489be | 314 | #endif /* CONFIG_WPS_STRICT */ |
fa15d405 | 315 | if (wps) { |
a9aca28b | 316 | sta->flags |= WLAN_STA_WPS; |
fa15d405 | 317 | if (wps_is_20(wps)) { |
48b06c17 JM |
318 | wpa_printf(MSG_DEBUG, |
319 | "WPS: STA supports WPS 2.0"); | |
17f6b900 JM |
320 | sta->flags |= WLAN_STA_WPS2; |
321 | } | |
a9aca28b JM |
322 | } else |
323 | sta->flags |= WLAN_STA_MAYBE_WPS; | |
17f6b900 | 324 | wpabuf_free(wps); |
633d4469 | 325 | #endif /* CONFIG_WPS */ |
a14896e8 JM |
326 | #ifdef CONFIG_HS20 |
327 | } else if (hapd->conf->osen) { | |
328 | if (elems.osen == NULL) { | |
329 | hostapd_logger( | |
330 | hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
331 | HOSTAPD_LEVEL_INFO, | |
332 | "No HS 2.0 OSEN element in association request"); | |
333 | return WLAN_STATUS_INVALID_IE; | |
334 | } | |
335 | ||
336 | wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association"); | |
337 | if (sta->wpa_sm == NULL) | |
338 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, | |
339 | sta->addr, NULL); | |
340 | if (sta->wpa_sm == NULL) { | |
48b06c17 JM |
341 | wpa_printf(MSG_WARNING, |
342 | "Failed to initialize WPA state machine"); | |
a14896e8 JM |
343 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
344 | } | |
345 | if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm, | |
346 | elems.osen - 2, elems.osen_len + 2) < 0) | |
347 | return WLAN_STATUS_INVALID_IE; | |
348 | #endif /* CONFIG_HS20 */ | |
b5b969e9 | 349 | } |
633d4469 | 350 | #ifdef CONFIG_WPS |
b5b969e9 | 351 | skip_wpa_check: |
633d4469 | 352 | #endif /* CONFIG_WPS */ |
b5b969e9 | 353 | |
88b32a99 SP |
354 | #ifdef CONFIG_IEEE80211R |
355 | p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf), | |
356 | sta->auth_alg, req_ies, req_ies_len); | |
357 | ||
358 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf); | |
e4474c1c DPS |
359 | |
360 | if (sta->auth_alg == WLAN_AUTH_FT) | |
361 | ap_sta_set_authorized(hapd, sta, 1); | |
88b32a99 SP |
362 | #else /* CONFIG_IEEE80211R */ |
363 | /* Keep compiler silent about unused variables */ | |
364 | if (status) { | |
365 | } | |
366 | #endif /* CONFIG_IEEE80211R */ | |
367 | ||
b5b969e9 JM |
368 | new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0; |
369 | sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC; | |
3578e665 | 370 | sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE; |
88b32a99 | 371 | |
e4474c1c DPS |
372 | hostapd_set_sta_flags(hapd, sta); |
373 | ||
88b32a99 SP |
374 | if (reassoc && (sta->auth_alg == WLAN_AUTH_FT)) |
375 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT); | |
376 | else | |
377 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC); | |
b5b969e9 JM |
378 | |
379 | hostapd_new_assoc_sta(hapd, sta, !new_assoc); | |
380 | ||
381 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); | |
382 | ||
ef796391 | 383 | #ifdef CONFIG_P2P |
99c01af9 JM |
384 | if (req_ies) { |
385 | p2p_group_notif_assoc(hapd->p2p_group, sta->addr, | |
386 | req_ies, req_ies_len); | |
387 | } | |
ef796391 JM |
388 | #endif /* CONFIG_P2P */ |
389 | ||
b5b969e9 | 390 | return 0; |
08a74e6a JM |
391 | |
392 | fail: | |
88b32a99 SP |
393 | #ifdef CONFIG_IEEE80211R |
394 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf); | |
395 | #endif /* CONFIG_IEEE80211R */ | |
08a74e6a JM |
396 | hostapd_drv_sta_disassoc(hapd, sta->addr, reason); |
397 | ap_free_sta(hapd, sta); | |
398 | return -1; | |
b5b969e9 JM |
399 | } |
400 | ||
401 | ||
402 | void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr) | |
403 | { | |
404 | struct sta_info *sta; | |
405 | ||
83e843e8 JM |
406 | if (addr == NULL) { |
407 | /* | |
408 | * This could potentially happen with unexpected event from the | |
409 | * driver wrapper. This was seen at least in one case where the | |
410 | * driver ended up reporting a station mode event while hostapd | |
411 | * was running, so better make sure we stop processing such an | |
412 | * event here. | |
413 | */ | |
48b06c17 JM |
414 | wpa_printf(MSG_DEBUG, |
415 | "hostapd_notif_disassoc: Skip event with no address"); | |
1f4c7b6b | 416 | return; |
83e843e8 JM |
417 | } |
418 | ||
b5b969e9 JM |
419 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, |
420 | HOSTAPD_LEVEL_INFO, "disassociated"); | |
421 | ||
422 | sta = ap_get_sta(hapd, addr); | |
423 | if (sta == NULL) { | |
48b06c17 JM |
424 | wpa_printf(MSG_DEBUG, |
425 | "Disassociation notification for unknown STA " | |
426 | MACSTR, MAC2STR(addr)); | |
b5b969e9 JM |
427 | return; |
428 | } | |
429 | ||
ae055af4 | 430 | ap_sta_set_authorized(hapd, sta, 0); |
b5b969e9 JM |
431 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); |
432 | wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC); | |
433 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; | |
434 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
435 | ap_free_sta(hapd, sta); | |
436 | } | |
437 | ||
438 | ||
0d7e5a3a JB |
439 | void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr) |
440 | { | |
441 | struct sta_info *sta = ap_get_sta(hapd, addr); | |
442 | ||
443 | if (!sta || !hapd->conf->disassoc_low_ack) | |
444 | return; | |
445 | ||
446 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, | |
48b06c17 JM |
447 | HOSTAPD_LEVEL_INFO, |
448 | "disconnected due to excessive missing ACKs"); | |
0d7e5a3a JB |
449 | hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK); |
450 | if (sta) | |
451 | ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK); | |
452 | } | |
453 | ||
454 | ||
1b487b8b | 455 | void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht, |
8d1fdde7 | 456 | int offset, int width, int cf1, int cf2) |
1b487b8b | 457 | { |
c7803a02 | 458 | #ifdef NEED_AP_MLME |
d308a44f LC |
459 | int channel, chwidth, is_dfs; |
460 | u8 seg0_idx = 0, seg1_idx = 0; | |
1b487b8b TP |
461 | |
462 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, | |
2f06bcb3 JM |
463 | HOSTAPD_LEVEL_INFO, |
464 | "driver had channel switch: freq=%d, ht=%d, offset=%d, width=%d (%s), cf1=%d, cf2=%d", | |
465 | freq, ht, offset, width, channel_width_to_string(width), | |
466 | cf1, cf2); | |
1b487b8b TP |
467 | |
468 | hapd->iface->freq = freq; | |
469 | ||
470 | channel = hostapd_hw_get_channel(hapd, freq); | |
471 | if (!channel) { | |
472 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, | |
48b06c17 JM |
473 | HOSTAPD_LEVEL_WARNING, |
474 | "driver switched to bad channel!"); | |
1b487b8b TP |
475 | return; |
476 | } | |
477 | ||
8d1fdde7 JD |
478 | switch (width) { |
479 | case CHAN_WIDTH_80: | |
480 | chwidth = VHT_CHANWIDTH_80MHZ; | |
481 | break; | |
482 | case CHAN_WIDTH_80P80: | |
483 | chwidth = VHT_CHANWIDTH_80P80MHZ; | |
484 | break; | |
485 | case CHAN_WIDTH_160: | |
486 | chwidth = VHT_CHANWIDTH_160MHZ; | |
487 | break; | |
488 | case CHAN_WIDTH_20_NOHT: | |
489 | case CHAN_WIDTH_20: | |
490 | case CHAN_WIDTH_40: | |
491 | default: | |
492 | chwidth = VHT_CHANWIDTH_USE_HT; | |
493 | break; | |
494 | } | |
495 | ||
496 | switch (hapd->iface->current_mode->mode) { | |
497 | case HOSTAPD_MODE_IEEE80211A: | |
498 | if (cf1 > 5000) | |
499 | seg0_idx = (cf1 - 5000) / 5; | |
500 | if (cf2 > 5000) | |
501 | seg1_idx = (cf2 - 5000) / 5; | |
502 | break; | |
503 | default: | |
d308a44f LC |
504 | ieee80211_freq_to_chan(cf1, &seg0_idx); |
505 | ieee80211_freq_to_chan(cf2, &seg1_idx); | |
8d1fdde7 JD |
506 | break; |
507 | } | |
508 | ||
1b487b8b TP |
509 | hapd->iconf->channel = channel; |
510 | hapd->iconf->ieee80211n = ht; | |
5de74818 JM |
511 | if (!ht) |
512 | hapd->iconf->ieee80211ac = 0; | |
1b487b8b | 513 | hapd->iconf->secondary_channel = offset; |
8d1fdde7 JD |
514 | hapd->iconf->vht_oper_chwidth = chwidth; |
515 | hapd->iconf->vht_oper_centr_freq_seg0_idx = seg0_idx; | |
516 | hapd->iconf->vht_oper_centr_freq_seg1_idx = seg1_idx; | |
bf281c12 | 517 | |
1e2aaffb AK |
518 | is_dfs = ieee80211_is_dfs(freq); |
519 | ||
6782b684 MK |
520 | if (hapd->csa_in_progress && |
521 | freq == hapd->cs_freq_params.freq) { | |
bf281c12 | 522 | hostapd_cleanup_cs_params(hapd); |
6782b684 | 523 | ieee802_11_set_beacon(hapd); |
bf281c12 | 524 | |
1e2aaffb AK |
525 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED |
526 | "freq=%d dfs=%d", freq, is_dfs); | |
527 | } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) { | |
528 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED | |
529 | "freq=%d dfs=%d", freq, is_dfs); | |
bf281c12 | 530 | } |
c7803a02 | 531 | #endif /* NEED_AP_MLME */ |
1b487b8b TP |
532 | } |
533 | ||
534 | ||
3140803b RM |
535 | void hostapd_event_connect_failed_reason(struct hostapd_data *hapd, |
536 | const u8 *addr, int reason_code) | |
537 | { | |
538 | switch (reason_code) { | |
539 | case MAX_CLIENT_REACHED: | |
540 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR, | |
541 | MAC2STR(addr)); | |
542 | break; | |
543 | case BLOCKED_CLIENT: | |
544 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR, | |
545 | MAC2STR(addr)); | |
546 | break; | |
547 | } | |
548 | } | |
549 | ||
550 | ||
16689c7c PX |
551 | #ifdef CONFIG_ACS |
552 | static void hostapd_acs_channel_selected(struct hostapd_data *hapd, | |
857d9422 | 553 | struct acs_selected_channels *acs_res) |
16689c7c | 554 | { |
3784c058 | 555 | int ret, i; |
16689c7c PX |
556 | |
557 | if (hapd->iconf->channel) { | |
558 | wpa_printf(MSG_INFO, "ACS: Channel was already set to %d", | |
559 | hapd->iconf->channel); | |
560 | return; | |
561 | } | |
562 | ||
3784c058 PX |
563 | if (!hapd->iface->current_mode) { |
564 | for (i = 0; i < hapd->iface->num_hw_features; i++) { | |
565 | struct hostapd_hw_modes *mode = | |
566 | &hapd->iface->hw_features[i]; | |
567 | ||
568 | if (mode->mode == acs_res->hw_mode) { | |
569 | hapd->iface->current_mode = mode; | |
570 | break; | |
571 | } | |
572 | } | |
573 | if (!hapd->iface->current_mode) { | |
574 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, | |
575 | HOSTAPD_LEVEL_WARNING, | |
576 | "driver selected to bad hw_mode"); | |
577 | return; | |
578 | } | |
579 | } | |
580 | ||
857d9422 | 581 | hapd->iface->freq = hostapd_hw_get_freq(hapd, acs_res->pri_channel); |
16689c7c | 582 | |
857d9422 | 583 | if (!acs_res->pri_channel) { |
16689c7c PX |
584 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
585 | HOSTAPD_LEVEL_WARNING, | |
586 | "driver switched to bad channel"); | |
587 | return; | |
588 | } | |
589 | ||
857d9422 MM |
590 | hapd->iconf->channel = acs_res->pri_channel; |
591 | hapd->iconf->acs = 1; | |
16689c7c | 592 | |
857d9422 | 593 | if (acs_res->sec_channel == 0) |
16689c7c | 594 | hapd->iconf->secondary_channel = 0; |
857d9422 | 595 | else if (acs_res->sec_channel < acs_res->pri_channel) |
16689c7c | 596 | hapd->iconf->secondary_channel = -1; |
857d9422 | 597 | else if (acs_res->sec_channel > acs_res->pri_channel) |
16689c7c PX |
598 | hapd->iconf->secondary_channel = 1; |
599 | else { | |
600 | wpa_printf(MSG_ERROR, "Invalid secondary channel!"); | |
601 | return; | |
602 | } | |
603 | ||
857d9422 MM |
604 | if (hapd->iface->conf->ieee80211ac) { |
605 | /* set defaults for backwards compatibility */ | |
606 | hapd->iconf->vht_oper_centr_freq_seg1_idx = 0; | |
607 | hapd->iconf->vht_oper_centr_freq_seg0_idx = 0; | |
608 | hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT; | |
609 | if (acs_res->ch_width == 80) { | |
610 | hapd->iconf->vht_oper_centr_freq_seg0_idx = | |
611 | acs_res->vht_seg0_center_ch; | |
612 | hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ; | |
613 | } else if (acs_res->ch_width == 160) { | |
614 | if (acs_res->vht_seg1_center_ch == 0) { | |
615 | hapd->iconf->vht_oper_centr_freq_seg0_idx = | |
616 | acs_res->vht_seg0_center_ch; | |
617 | hapd->iconf->vht_oper_chwidth = | |
618 | VHT_CHANWIDTH_160MHZ; | |
619 | } else { | |
620 | hapd->iconf->vht_oper_centr_freq_seg0_idx = | |
621 | acs_res->vht_seg0_center_ch; | |
622 | hapd->iconf->vht_oper_centr_freq_seg1_idx = | |
623 | acs_res->vht_seg1_center_ch; | |
624 | hapd->iconf->vht_oper_chwidth = | |
625 | VHT_CHANWIDTH_80P80MHZ; | |
626 | } | |
627 | } | |
628 | } | |
629 | ||
16689c7c PX |
630 | ret = hostapd_acs_completed(hapd->iface, 0); |
631 | if (ret) { | |
632 | wpa_printf(MSG_ERROR, | |
633 | "ACS: Possibly channel configuration is invalid"); | |
634 | } | |
635 | } | |
636 | #endif /* CONFIG_ACS */ | |
637 | ||
638 | ||
04a85e44 | 639 | int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da, |
baf513d6 JB |
640 | const u8 *bssid, const u8 *ie, size_t ie_len, |
641 | int ssi_signal) | |
e67b55fb JM |
642 | { |
643 | size_t i; | |
644 | int ret = 0; | |
645 | ||
b211f3eb JM |
646 | if (sa == NULL || ie == NULL) |
647 | return -1; | |
648 | ||
649 | random_add_randomness(sa, ETH_ALEN); | |
e67b55fb JM |
650 | for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) { |
651 | if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, | |
baf513d6 JB |
652 | sa, da, bssid, ie, ie_len, |
653 | ssi_signal) > 0) { | |
e67b55fb JM |
654 | ret = 1; |
655 | break; | |
656 | } | |
657 | } | |
658 | return ret; | |
659 | } | |
660 | ||
661 | ||
5c61a282 JM |
662 | #ifdef HOSTAPD |
663 | ||
88b32a99 SP |
664 | #ifdef CONFIG_IEEE80211R |
665 | static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst, | |
666 | const u8 *bssid, | |
667 | u16 auth_transaction, u16 status, | |
668 | const u8 *ies, size_t ies_len) | |
669 | { | |
670 | struct hostapd_data *hapd = ctx; | |
671 | struct sta_info *sta; | |
672 | ||
673 | sta = ap_get_sta(hapd, dst); | |
674 | if (sta == NULL) | |
675 | return; | |
676 | ||
677 | hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211, | |
678 | HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)"); | |
679 | sta->flags |= WLAN_STA_AUTH; | |
680 | ||
681 | hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len); | |
682 | } | |
683 | #endif /* CONFIG_IEEE80211R */ | |
684 | ||
685 | ||
88b32a99 SP |
686 | static void hostapd_notif_auth(struct hostapd_data *hapd, |
687 | struct auth_info *rx_auth) | |
688 | { | |
689 | struct sta_info *sta; | |
690 | u16 status = WLAN_STATUS_SUCCESS; | |
691 | u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN]; | |
692 | size_t resp_ies_len = 0; | |
693 | ||
694 | sta = ap_get_sta(hapd, rx_auth->peer); | |
695 | if (!sta) { | |
696 | sta = ap_sta_add(hapd, rx_auth->peer); | |
697 | if (sta == NULL) { | |
728d9717 | 698 | status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
88b32a99 SP |
699 | goto fail; |
700 | } | |
701 | } | |
702 | sta->flags &= ~WLAN_STA_PREAUTH; | |
703 | ieee802_1x_notify_pre_auth(sta->eapol_sm, 0); | |
704 | #ifdef CONFIG_IEEE80211R | |
705 | if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) { | |
706 | sta->auth_alg = WLAN_AUTH_FT; | |
707 | if (sta->wpa_sm == NULL) | |
708 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, | |
94ddef3e | 709 | sta->addr, NULL); |
88b32a99 | 710 | if (sta->wpa_sm == NULL) { |
48b06c17 JM |
711 | wpa_printf(MSG_DEBUG, |
712 | "FT: Failed to initialize WPA state machine"); | |
88b32a99 SP |
713 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
714 | goto fail; | |
715 | } | |
716 | wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid, | |
717 | rx_auth->auth_transaction, rx_auth->ies, | |
718 | rx_auth->ies_len, | |
719 | hostapd_notify_auth_ft_finish, hapd); | |
720 | return; | |
721 | } | |
722 | #endif /* CONFIG_IEEE80211R */ | |
723 | fail: | |
724 | hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1, | |
725 | status, resp_ies, resp_ies_len); | |
726 | } | |
727 | ||
728 | ||
729 | static void hostapd_action_rx(struct hostapd_data *hapd, | |
dbfb8e82 | 730 | struct rx_mgmt *drv_mgmt) |
88b32a99 | 731 | { |
dbfb8e82 | 732 | struct ieee80211_mgmt *mgmt; |
88b32a99 | 733 | struct sta_info *sta; |
dbfb8e82 JM |
734 | size_t plen __maybe_unused; |
735 | u16 fc; | |
736 | ||
737 | if (drv_mgmt->frame_len < 24 + 1) | |
738 | return; | |
739 | ||
740 | plen = drv_mgmt->frame_len - 24 - 1; | |
741 | ||
742 | mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame; | |
743 | fc = le_to_host16(mgmt->frame_control); | |
744 | if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) | |
745 | return; /* handled by the driver */ | |
88b32a99 | 746 | |
48b06c17 | 747 | wpa_printf(MSG_DEBUG, "RX_ACTION cat %d action plen %d", |
dbfb8e82 | 748 | mgmt->u.action.category, (int) plen); |
7d9c0cd3 | 749 | |
dbfb8e82 | 750 | sta = ap_get_sta(hapd, mgmt->sa); |
88b32a99 SP |
751 | if (sta == NULL) { |
752 | wpa_printf(MSG_DEBUG, "%s: station not found", __func__); | |
753 | return; | |
754 | } | |
755 | #ifdef CONFIG_IEEE80211R | |
dbfb8e82 JM |
756 | if (mgmt->u.action.category == WLAN_ACTION_FT) { |
757 | const u8 *payload = drv_mgmt->frame + 24 + 1; | |
48b06c17 | 758 | |
dbfb8e82 | 759 | wpa_ft_action_rx(sta->wpa_sm, payload, plen); |
88b32a99 SP |
760 | } |
761 | #endif /* CONFIG_IEEE80211R */ | |
7d9c0cd3 | 762 | #ifdef CONFIG_IEEE80211W |
dbfb8e82 JM |
763 | if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY && plen >= 4) { |
764 | ieee802_11_sa_query_action( | |
765 | hapd, mgmt->sa, | |
766 | mgmt->u.action.u.sa_query_resp.action, | |
767 | mgmt->u.action.u.sa_query_resp.trans_id); | |
7d9c0cd3 MP |
768 | } |
769 | #endif /* CONFIG_IEEE80211W */ | |
ad3872a3 | 770 | #ifdef CONFIG_WNM |
dbfb8e82 JM |
771 | if (mgmt->u.action.category == WLAN_ACTION_WNM) { |
772 | ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len); | |
d32d94db | 773 | } |
ad3872a3 | 774 | #endif /* CONFIG_WNM */ |
037378ff AN |
775 | #ifdef CONFIG_FST |
776 | if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) { | |
777 | fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len); | |
778 | return; | |
779 | } | |
780 | #endif /* CONFIG_FST */ | |
781 | ||
88b32a99 SP |
782 | } |
783 | ||
784 | ||
fe6bdb77 | 785 | #ifdef NEED_AP_MLME |
f8b1f695 | 786 | |
f8b1f695 JM |
787 | #define HAPD_BROADCAST ((struct hostapd_data *) -1) |
788 | ||
789 | static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface, | |
790 | const u8 *bssid) | |
791 | { | |
792 | size_t i; | |
793 | ||
794 | if (bssid == NULL) | |
795 | return NULL; | |
796 | if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff && | |
797 | bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff) | |
798 | return HAPD_BROADCAST; | |
799 | ||
800 | for (i = 0; i < iface->num_bss; i++) { | |
801 | if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0) | |
802 | return iface->bss[i]; | |
803 | } | |
804 | ||
805 | return NULL; | |
806 | } | |
807 | ||
808 | ||
809 | static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd, | |
9b90955e JB |
810 | const u8 *bssid, const u8 *addr, |
811 | int wds) | |
f8b1f695 | 812 | { |
9b90955e | 813 | hapd = get_hapd_bssid(hapd->iface, bssid); |
f8b1f695 JM |
814 | if (hapd == NULL || hapd == HAPD_BROADCAST) |
815 | return; | |
816 | ||
9b90955e | 817 | ieee802_11_rx_from_unknown(hapd, addr, wds); |
f8b1f695 JM |
818 | } |
819 | ||
820 | ||
912b34f0 | 821 | static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt) |
b5b969e9 | 822 | { |
4b9841d3 | 823 | struct hostapd_iface *iface = hapd->iface; |
b57e086c | 824 | const struct ieee80211_hdr *hdr; |
4b9841d3 | 825 | const u8 *bssid; |
2a8b7416 | 826 | struct hostapd_frame_info fi; |
912b34f0 | 827 | int ret; |
4b9841d3 | 828 | |
5f7e1c06 JM |
829 | #ifdef CONFIG_TESTING_OPTIONS |
830 | if (hapd->ext_mgmt_frame_handling) { | |
831 | size_t hex_len = 2 * rx_mgmt->frame_len + 1; | |
832 | char *hex = os_malloc(hex_len); | |
48b06c17 | 833 | |
5f7e1c06 JM |
834 | if (hex) { |
835 | wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame, | |
836 | rx_mgmt->frame_len); | |
837 | wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex); | |
838 | os_free(hex); | |
839 | } | |
840 | return 1; | |
841 | } | |
842 | #endif /* CONFIG_TESTING_OPTIONS */ | |
843 | ||
2a8b7416 JM |
844 | hdr = (const struct ieee80211_hdr *) rx_mgmt->frame; |
845 | bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len); | |
4b9841d3 | 846 | if (bssid == NULL) |
912b34f0 | 847 | return 0; |
4b9841d3 JM |
848 | |
849 | hapd = get_hapd_bssid(iface, bssid); | |
850 | if (hapd == NULL) { | |
48b06c17 | 851 | u16 fc = le_to_host16(hdr->frame_control); |
4b9841d3 JM |
852 | |
853 | /* | |
854 | * Drop frames to unknown BSSIDs except for Beacon frames which | |
855 | * could be used to update neighbor information. | |
856 | */ | |
857 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
858 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) | |
859 | hapd = iface->bss[0]; | |
860 | else | |
912b34f0 | 861 | return 0; |
4b9841d3 JM |
862 | } |
863 | ||
2a8b7416 JM |
864 | os_memset(&fi, 0, sizeof(fi)); |
865 | fi.datarate = rx_mgmt->datarate; | |
866 | fi.ssi_signal = rx_mgmt->ssi_signal; | |
867 | ||
4b9841d3 JM |
868 | if (hapd == HAPD_BROADCAST) { |
869 | size_t i; | |
48b06c17 | 870 | |
912b34f0 JM |
871 | ret = 0; |
872 | for (i = 0; i < iface->num_bss; i++) { | |
1d91f504 SW |
873 | /* if bss is set, driver will call this function for |
874 | * each bss individually. */ | |
875 | if (rx_mgmt->drv_priv && | |
876 | (iface->bss[i]->drv_priv != rx_mgmt->drv_priv)) | |
877 | continue; | |
878 | ||
912b34f0 JM |
879 | if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame, |
880 | rx_mgmt->frame_len, &fi) > 0) | |
881 | ret = 1; | |
882 | } | |
4b9841d3 | 883 | } else |
912b34f0 JM |
884 | ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len, |
885 | &fi); | |
bbb921da JM |
886 | |
887 | random_add_randomness(&fi, sizeof(fi)); | |
912b34f0 JM |
888 | |
889 | return ret; | |
b5b969e9 JM |
890 | } |
891 | ||
892 | ||
f8b1f695 JM |
893 | static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf, |
894 | size_t len, u16 stype, int ok) | |
b5b969e9 | 895 | { |
4b9841d3 | 896 | struct ieee80211_hdr *hdr; |
48b06c17 | 897 | |
4b9841d3 JM |
898 | hdr = (struct ieee80211_hdr *) buf; |
899 | hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len)); | |
900 | if (hapd == NULL || hapd == HAPD_BROADCAST) | |
901 | return; | |
b5b969e9 JM |
902 | ieee802_11_mgmt_cb(hapd, buf, len, stype, ok); |
903 | } | |
f82ef4d8 | 904 | |
f8b1f695 | 905 | #endif /* NEED_AP_MLME */ |
ad1e68e6 JM |
906 | |
907 | ||
a8e0505b JM |
908 | static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr) |
909 | { | |
910 | struct sta_info *sta = ap_get_sta(hapd, addr); | |
48b06c17 | 911 | |
a8e0505b JM |
912 | if (sta) |
913 | return 0; | |
914 | ||
915 | wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR | |
916 | " - adding a new STA", MAC2STR(addr)); | |
917 | sta = ap_sta_add(hapd, addr); | |
918 | if (sta) { | |
919 | hostapd_new_assoc_sta(hapd, sta, 0); | |
920 | } else { | |
921 | wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR, | |
922 | MAC2STR(addr)); | |
923 | return -1; | |
924 | } | |
925 | ||
926 | return 0; | |
927 | } | |
928 | ||
929 | ||
930 | static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src, | |
931 | const u8 *data, size_t data_len) | |
932 | { | |
933 | struct hostapd_iface *iface = hapd->iface; | |
f826635c | 934 | struct sta_info *sta; |
a8e0505b JM |
935 | size_t j; |
936 | ||
937 | for (j = 0; j < iface->num_bss; j++) { | |
48b06c17 JM |
938 | sta = ap_get_sta(iface->bss[j], src); |
939 | if (sta && sta->flags & WLAN_STA_ASSOC) { | |
940 | hapd = iface->bss[j]; | |
941 | break; | |
a8e0505b JM |
942 | } |
943 | } | |
944 | ||
945 | ieee802_1x_receive(hapd, src, data, data_len); | |
946 | } | |
947 | ||
948 | ||
0185007c MK |
949 | static struct hostapd_channel_data * hostapd_get_mode_channel( |
950 | struct hostapd_iface *iface, unsigned int freq) | |
951 | { | |
952 | int i; | |
953 | struct hostapd_channel_data *chan; | |
954 | ||
955 | for (i = 0; i < iface->current_mode->num_channels; i++) { | |
956 | chan = &iface->current_mode->channels[i]; | |
957 | if (!chan) | |
958 | return NULL; | |
959 | if ((unsigned int) chan->freq == freq) | |
960 | return chan; | |
961 | } | |
962 | ||
963 | return NULL; | |
964 | } | |
965 | ||
966 | ||
967 | static void hostapd_update_nf(struct hostapd_iface *iface, | |
968 | struct hostapd_channel_data *chan, | |
969 | struct freq_survey *survey) | |
970 | { | |
971 | if (!iface->chans_surveyed) { | |
972 | chan->min_nf = survey->nf; | |
973 | iface->lowest_nf = survey->nf; | |
974 | } else { | |
975 | if (dl_list_empty(&chan->survey_list)) | |
976 | chan->min_nf = survey->nf; | |
977 | else if (survey->nf < chan->min_nf) | |
978 | chan->min_nf = survey->nf; | |
979 | if (survey->nf < iface->lowest_nf) | |
980 | iface->lowest_nf = survey->nf; | |
981 | } | |
982 | } | |
983 | ||
984 | ||
ec8f36af KP |
985 | static void hostapd_single_channel_get_survey(struct hostapd_iface *iface, |
986 | struct survey_results *survey_res) | |
987 | { | |
988 | struct hostapd_channel_data *chan; | |
989 | struct freq_survey *survey; | |
990 | u64 divisor, dividend; | |
991 | ||
992 | survey = dl_list_first(&survey_res->survey_list, struct freq_survey, | |
993 | list); | |
994 | if (!survey || !survey->freq) | |
995 | return; | |
996 | ||
997 | chan = hostapd_get_mode_channel(iface, survey->freq); | |
998 | if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED) | |
999 | return; | |
1000 | ||
48b06c17 JM |
1001 | wpa_printf(MSG_DEBUG, |
1002 | "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)", | |
ec8f36af KP |
1003 | survey->freq, |
1004 | (unsigned long int) survey->channel_time, | |
1005 | (unsigned long int) survey->channel_time_busy); | |
1006 | ||
1007 | if (survey->channel_time > iface->last_channel_time && | |
1008 | survey->channel_time > survey->channel_time_busy) { | |
1009 | dividend = survey->channel_time_busy - | |
1010 | iface->last_channel_time_busy; | |
1011 | divisor = survey->channel_time - iface->last_channel_time; | |
1012 | ||
1013 | iface->channel_utilization = dividend * 255 / divisor; | |
1014 | wpa_printf(MSG_DEBUG, "Channel Utilization: %d", | |
1015 | iface->channel_utilization); | |
1016 | } | |
1017 | iface->last_channel_time = survey->channel_time; | |
1018 | iface->last_channel_time_busy = survey->channel_time_busy; | |
1019 | } | |
1020 | ||
1021 | ||
0185007c MK |
1022 | static void hostapd_event_get_survey(struct hostapd_data *hapd, |
1023 | struct survey_results *survey_results) | |
1024 | { | |
1025 | struct hostapd_iface *iface = hapd->iface; | |
1026 | struct freq_survey *survey, *tmp; | |
1027 | struct hostapd_channel_data *chan; | |
1028 | ||
1029 | if (dl_list_empty(&survey_results->survey_list)) { | |
1030 | wpa_printf(MSG_DEBUG, "No survey data received"); | |
1031 | return; | |
1032 | } | |
1033 | ||
ec8f36af KP |
1034 | if (survey_results->freq_filter) { |
1035 | hostapd_single_channel_get_survey(iface, survey_results); | |
1036 | return; | |
1037 | } | |
1038 | ||
0185007c MK |
1039 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
1040 | struct freq_survey, list) { | |
1041 | chan = hostapd_get_mode_channel(iface, survey->freq); | |
1042 | if (!chan) | |
1043 | continue; | |
1044 | if (chan->flag & HOSTAPD_CHAN_DISABLED) | |
1045 | continue; | |
1046 | ||
1047 | dl_list_del(&survey->list); | |
1048 | dl_list_add_tail(&chan->survey_list, &survey->list); | |
1049 | ||
1050 | hostapd_update_nf(iface, chan, survey); | |
1051 | ||
1052 | iface->chans_surveyed++; | |
1053 | } | |
1054 | } | |
1055 | ||
1056 | ||
e76da505 JD |
1057 | #ifdef NEED_AP_MLME |
1058 | ||
5841958f MK |
1059 | static void hostapd_event_iface_unavailable(struct hostapd_data *hapd) |
1060 | { | |
1061 | wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped", | |
1062 | hapd->conf->iface); | |
1063 | ||
1064 | if (hapd->csa_in_progress) { | |
1065 | wpa_printf(MSG_INFO, "CSA failed (%s was stopped)", | |
1066 | hapd->conf->iface); | |
1067 | hostapd_switch_channel_fallback(hapd->iface, | |
1068 | &hapd->cs_freq_params); | |
1069 | } | |
1070 | } | |
1071 | ||
1072 | ||
e76da505 JD |
1073 | static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd, |
1074 | struct dfs_event *radar) | |
1075 | { | |
e76da505 | 1076 | wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq); |
dc036d9e | 1077 | hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled, |
58b73e3d JD |
1078 | radar->chan_offset, radar->chan_width, |
1079 | radar->cf1, radar->cf2); | |
e76da505 JD |
1080 | } |
1081 | ||
1082 | ||
1083 | static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd, | |
1084 | struct dfs_event *radar) | |
1085 | { | |
1086 | wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq); | |
dc036d9e | 1087 | hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled, |
58b73e3d JD |
1088 | radar->chan_offset, radar->chan_width, |
1089 | radar->cf1, radar->cf2); | |
e76da505 JD |
1090 | } |
1091 | ||
1092 | ||
1093 | static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd, | |
1094 | struct dfs_event *radar) | |
1095 | { | |
1096 | wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq); | |
dc036d9e | 1097 | hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled, |
58b73e3d JD |
1098 | radar->chan_offset, radar->chan_width, |
1099 | radar->cf1, radar->cf2); | |
e76da505 JD |
1100 | } |
1101 | ||
1102 | ||
1103 | static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd, | |
1104 | struct dfs_event *radar) | |
1105 | { | |
1106 | wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq); | |
dc036d9e | 1107 | hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled, |
58b73e3d JD |
1108 | radar->chan_offset, radar->chan_width, |
1109 | radar->cf1, radar->cf2); | |
e76da505 JD |
1110 | } |
1111 | ||
c13578c3 AK |
1112 | |
1113 | static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd, | |
1114 | struct dfs_event *radar) | |
1115 | { | |
1116 | wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq); | |
1117 | hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled, | |
1118 | radar->chan_offset, radar->chan_width, | |
1119 | radar->cf1, radar->cf2); | |
1120 | } | |
1121 | ||
e76da505 JD |
1122 | #endif /* NEED_AP_MLME */ |
1123 | ||
1124 | ||
9646a8ab | 1125 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
ad1e68e6 JM |
1126 | union wpa_event_data *data) |
1127 | { | |
1128 | struct hostapd_data *hapd = ctx; | |
74781dfc JM |
1129 | #ifndef CONFIG_NO_STDOUT_DEBUG |
1130 | int level = MSG_DEBUG; | |
ad1e68e6 | 1131 | |
34caf71a | 1132 | if (event == EVENT_RX_MGMT && data->rx_mgmt.frame && |
74781dfc JM |
1133 | data->rx_mgmt.frame_len >= 24) { |
1134 | const struct ieee80211_hdr *hdr; | |
1135 | u16 fc; | |
48b06c17 | 1136 | |
74781dfc JM |
1137 | hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; |
1138 | fc = le_to_host16(hdr->frame_control); | |
1139 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
1140 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) | |
1141 | level = MSG_EXCESSIVE; | |
cc2ada86 JM |
1142 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
1143 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ) | |
1144 | level = MSG_EXCESSIVE; | |
74781dfc JM |
1145 | } |
1146 | ||
1147 | wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received", | |
e26cd1a1 | 1148 | event_to_string(event), event); |
74781dfc | 1149 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
e26cd1a1 | 1150 | |
ad1e68e6 JM |
1151 | switch (event) { |
1152 | case EVENT_MICHAEL_MIC_FAILURE: | |
1153 | michael_mic_failure(hapd, data->michael_mic_failure.src, 1); | |
1154 | break; | |
1155 | case EVENT_SCAN_RESULTS: | |
1156 | if (hapd->iface->scan_cb) | |
1157 | hapd->iface->scan_cb(hapd->iface); | |
1158 | break; | |
fcf0f87d | 1159 | case EVENT_WPS_BUTTON_PUSHED: |
d601247c | 1160 | hostapd_wps_button_pushed(hapd, NULL); |
fcf0f87d | 1161 | break; |
f8b1f695 JM |
1162 | #ifdef NEED_AP_MLME |
1163 | case EVENT_TX_STATUS: | |
1164 | switch (data->tx_status.type) { | |
1165 | case WLAN_FC_TYPE_MGMT: | |
1166 | hostapd_mgmt_tx_cb(hapd, data->tx_status.data, | |
1167 | data->tx_status.data_len, | |
1168 | data->tx_status.stype, | |
1169 | data->tx_status.ack); | |
1170 | break; | |
1171 | case WLAN_FC_TYPE_DATA: | |
1172 | hostapd_tx_status(hapd, data->tx_status.dst, | |
1173 | data->tx_status.data, | |
1174 | data->tx_status.data_len, | |
1175 | data->tx_status.ack); | |
1176 | break; | |
1177 | } | |
1178 | break; | |
dd840f79 JB |
1179 | case EVENT_EAPOL_TX_STATUS: |
1180 | hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst, | |
1181 | data->eapol_tx_status.data, | |
1182 | data->eapol_tx_status.data_len, | |
1183 | data->eapol_tx_status.ack); | |
1184 | break; | |
bcf24348 JB |
1185 | case EVENT_DRIVER_CLIENT_POLL_OK: |
1186 | hostapd_client_poll_ok(hapd, data->client_poll.addr); | |
1187 | break; | |
f8b1f695 | 1188 | case EVENT_RX_FROM_UNKNOWN: |
9b90955e JB |
1189 | hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid, |
1190 | data->rx_from_unknown.addr, | |
1191 | data->rx_from_unknown.wds); | |
f8b1f695 | 1192 | break; |
dbfb8e82 | 1193 | #endif /* NEED_AP_MLME */ |
f8b1f695 | 1194 | case EVENT_RX_MGMT: |
c0333c8d JM |
1195 | if (!data->rx_mgmt.frame) |
1196 | break; | |
dbfb8e82 JM |
1197 | #ifdef NEED_AP_MLME |
1198 | if (hostapd_mgmt_rx(hapd, &data->rx_mgmt) > 0) | |
1199 | break; | |
f8b1f695 | 1200 | #endif /* NEED_AP_MLME */ |
dbfb8e82 JM |
1201 | hostapd_action_rx(hapd, &data->rx_mgmt); |
1202 | break; | |
a0e0d3bb | 1203 | case EVENT_RX_PROBE_REQ: |
b211f3eb JM |
1204 | if (data->rx_probe_req.sa == NULL || |
1205 | data->rx_probe_req.ie == NULL) | |
1206 | break; | |
a0e0d3bb | 1207 | hostapd_probe_req_rx(hapd, data->rx_probe_req.sa, |
04a85e44 JM |
1208 | data->rx_probe_req.da, |
1209 | data->rx_probe_req.bssid, | |
a0e0d3bb | 1210 | data->rx_probe_req.ie, |
baf513d6 JB |
1211 | data->rx_probe_req.ie_len, |
1212 | data->rx_probe_req.ssi_signal); | |
a0e0d3bb | 1213 | break; |
a70a5d6d | 1214 | case EVENT_NEW_STA: |
a8e0505b JM |
1215 | hostapd_event_new_sta(hapd, data->new_sta.addr); |
1216 | break; | |
1217 | case EVENT_EAPOL_RX: | |
1218 | hostapd_event_eapol_rx(hapd, data->eapol_rx.src, | |
1219 | data->eapol_rx.data, | |
1220 | data->eapol_rx.data_len); | |
1221 | break; | |
1d041bec | 1222 | case EVENT_ASSOC: |
04a258e7 JM |
1223 | if (!data) |
1224 | return; | |
1d041bec JM |
1225 | hostapd_notif_assoc(hapd, data->assoc_info.addr, |
1226 | data->assoc_info.req_ies, | |
39b08b5f SP |
1227 | data->assoc_info.req_ies_len, |
1228 | data->assoc_info.reassoc); | |
1d041bec JM |
1229 | break; |
1230 | case EVENT_DISASSOC: | |
1231 | if (data) | |
1232 | hostapd_notif_disassoc(hapd, data->disassoc_info.addr); | |
1233 | break; | |
1234 | case EVENT_DEAUTH: | |
1235 | if (data) | |
1236 | hostapd_notif_disassoc(hapd, data->deauth_info.addr); | |
1237 | break; | |
0d7e5a3a JB |
1238 | case EVENT_STATION_LOW_ACK: |
1239 | if (!data) | |
1240 | break; | |
1241 | hostapd_event_sta_low_ack(hapd, data->low_ack.addr); | |
1242 | break; | |
88b32a99 SP |
1243 | case EVENT_AUTH: |
1244 | hostapd_notif_auth(hapd, &data->auth); | |
1245 | break; | |
1b487b8b TP |
1246 | case EVENT_CH_SWITCH: |
1247 | if (!data) | |
1248 | break; | |
1249 | hostapd_event_ch_switch(hapd, data->ch_switch.freq, | |
1250 | data->ch_switch.ht_enabled, | |
8d1fdde7 JD |
1251 | data->ch_switch.ch_offset, |
1252 | data->ch_switch.ch_width, | |
1253 | data->ch_switch.cf1, | |
1254 | data->ch_switch.cf2); | |
1b487b8b | 1255 | break; |
3140803b RM |
1256 | case EVENT_CONNECT_FAILED_REASON: |
1257 | if (!data) | |
1258 | break; | |
1259 | hostapd_event_connect_failed_reason( | |
1260 | hapd, data->connect_failed_reason.addr, | |
1261 | data->connect_failed_reason.code); | |
1262 | break; | |
0185007c MK |
1263 | case EVENT_SURVEY: |
1264 | hostapd_event_get_survey(hapd, &data->survey_results); | |
1265 | break; | |
e76da505 | 1266 | #ifdef NEED_AP_MLME |
5841958f MK |
1267 | case EVENT_INTERFACE_UNAVAILABLE: |
1268 | hostapd_event_iface_unavailable(hapd); | |
1269 | break; | |
e76da505 JD |
1270 | case EVENT_DFS_RADAR_DETECTED: |
1271 | if (!data) | |
1272 | break; | |
1273 | hostapd_event_dfs_radar_detected(hapd, &data->dfs_event); | |
1274 | break; | |
1275 | case EVENT_DFS_CAC_FINISHED: | |
1276 | if (!data) | |
1277 | break; | |
1278 | hostapd_event_dfs_cac_finished(hapd, &data->dfs_event); | |
1279 | break; | |
1280 | case EVENT_DFS_CAC_ABORTED: | |
1281 | if (!data) | |
1282 | break; | |
1283 | hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event); | |
1284 | break; | |
1285 | case EVENT_DFS_NOP_FINISHED: | |
1286 | if (!data) | |
1287 | break; | |
1288 | hostapd_event_dfs_nop_finished(hapd, &data->dfs_event); | |
1289 | break; | |
1290 | case EVENT_CHANNEL_LIST_CHANGED: | |
1291 | /* channel list changed (regulatory?), update channel list */ | |
1292 | /* TODO: check this. hostapd_get_hw_features() initializes | |
1293 | * too much stuff. */ | |
1294 | /* hostapd_get_hw_features(hapd->iface); */ | |
795baf77 AS |
1295 | hostapd_channel_list_updated( |
1296 | hapd->iface, data->channel_list_changed.initiator); | |
e76da505 | 1297 | break; |
c13578c3 AK |
1298 | case EVENT_DFS_CAC_STARTED: |
1299 | if (!data) | |
1300 | break; | |
1301 | hostapd_event_dfs_cac_started(hapd, &data->dfs_event); | |
1302 | break; | |
e76da505 | 1303 | #endif /* NEED_AP_MLME */ |
ab93fdeb JM |
1304 | case EVENT_INTERFACE_ENABLED: |
1305 | wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED); | |
f33c8606 JM |
1306 | if (hapd->disabled && hapd->started) { |
1307 | hapd->disabled = 0; | |
1308 | /* | |
1309 | * Try to re-enable interface if the driver stopped it | |
1310 | * when the interface got disabled. | |
1311 | */ | |
34782730 | 1312 | wpa_auth_reconfig_group_keys(hapd->wpa_auth); |
f33c8606 JM |
1313 | hapd->reenable_beacon = 1; |
1314 | ieee802_11_set_beacon(hapd); | |
1315 | } | |
ab93fdeb JM |
1316 | break; |
1317 | case EVENT_INTERFACE_DISABLED: | |
c165cb40 | 1318 | hostapd_free_stas(hapd); |
ab93fdeb | 1319 | wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED); |
f33c8606 | 1320 | hapd->disabled = 1; |
ab93fdeb | 1321 | break; |
16689c7c PX |
1322 | #ifdef CONFIG_ACS |
1323 | case EVENT_ACS_CHANNEL_SELECTED: | |
857d9422 MM |
1324 | hostapd_acs_channel_selected(hapd, |
1325 | &data->acs_selected_channels); | |
16689c7c PX |
1326 | break; |
1327 | #endif /* CONFIG_ACS */ | |
ad1e68e6 JM |
1328 | default: |
1329 | wpa_printf(MSG_DEBUG, "Unknown event %d", event); | |
1330 | break; | |
1331 | } | |
1332 | } | |
f8b1f695 JM |
1333 | |
1334 | #endif /* HOSTAPD */ |