]>
Commit | Line | Data |
---|---|---|
b5b969e9 JM |
1 | /* |
2 | * hostapd / Callback functions for driver wrappers | |
3 | * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi> | |
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" |
b5b969e9 | 12 | #include "radius/radius.h" |
6e6e8c31 | 13 | #include "drivers/driver.h" |
81f4f619 | 14 | #include "common/ieee802_11_defs.h" |
c41a1095 | 15 | #include "common/ieee802_11_common.h" |
bbb921da | 16 | #include "crypto/random.h" |
ef796391 | 17 | #include "p2p/p2p.h" |
54f489be | 18 | #include "wps/wps.h" |
6226e38d JM |
19 | #include "hostapd.h" |
20 | #include "ieee802_11.h" | |
21 | #include "sta_info.h" | |
22 | #include "accounting.h" | |
23 | #include "tkip_countermeasures.h" | |
6226e38d JM |
24 | #include "ieee802_1x.h" |
25 | #include "wpa_auth.h" | |
6226e38d | 26 | #include "wps_hostapd.h" |
51e2a27a | 27 | #include "ap_drv_ops.h" |
8b06c1ed | 28 | #include "ap_config.h" |
b5b969e9 JM |
29 | |
30 | ||
b5b969e9 | 31 | int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr, |
2bb20281 | 32 | const u8 *req_ies, size_t req_ies_len, int reassoc) |
b5b969e9 JM |
33 | { |
34 | struct sta_info *sta; | |
35 | int new_assoc, res; | |
c41a1095 | 36 | struct ieee802_11_elems elems; |
2bb20281 JM |
37 | const u8 *ie; |
38 | size_t ielen; | |
08a74e6a | 39 | u16 reason = WLAN_REASON_UNSPECIFIED; |
b5b969e9 | 40 | |
68532a9c JM |
41 | if (addr == NULL) { |
42 | /* | |
43 | * This could potentially happen with unexpected event from the | |
44 | * driver wrapper. This was seen at least in one case where the | |
45 | * driver ended up being set to station mode while hostapd was | |
46 | * running, so better make sure we stop processing such an | |
47 | * event here. | |
48 | */ | |
49 | wpa_printf(MSG_DEBUG, "hostapd_notif_assoc: Skip event with " | |
50 | "no address"); | |
51 | return -1; | |
52 | } | |
bbb921da | 53 | random_add_randomness(addr, ETH_ALEN); |
68532a9c | 54 | |
b5b969e9 JM |
55 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, |
56 | HOSTAPD_LEVEL_INFO, "associated"); | |
57 | ||
2bb20281 | 58 | ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0); |
c41a1095 JM |
59 | if (elems.wps_ie) { |
60 | ie = elems.wps_ie - 2; | |
61 | ielen = elems.wps_ie_len + 2; | |
62 | wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq"); | |
63 | } else if (elems.rsn_ie) { | |
64 | ie = elems.rsn_ie - 2; | |
65 | ielen = elems.rsn_ie_len + 2; | |
66 | wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq"); | |
67 | } else if (elems.wpa_ie) { | |
68 | ie = elems.wpa_ie - 2; | |
69 | ielen = elems.wpa_ie_len + 2; | |
70 | wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq"); | |
71 | } else { | |
72 | ie = NULL; | |
73 | ielen = 0; | |
74 | wpa_printf(MSG_DEBUG, "STA did not include WPS/RSN/WPA IE in " | |
75 | "(Re)AssocReq"); | |
76 | } | |
77 | ||
b5b969e9 JM |
78 | sta = ap_get_sta(hapd, addr); |
79 | if (sta) { | |
80 | accounting_sta_stop(hapd, sta); | |
c72bd6d4 JM |
81 | |
82 | /* | |
83 | * Make sure that the previously registered inactivity timer | |
84 | * will not remove the STA immediately. | |
85 | */ | |
86 | sta->timeout_next = STA_NULLFUNC; | |
b5b969e9 JM |
87 | } else { |
88 | sta = ap_sta_add(hapd, addr); | |
8bd0fc0e JM |
89 | if (sta == NULL) { |
90 | hostapd_drv_sta_disassoc(hapd, addr, | |
91 | WLAN_REASON_DISASSOC_AP_BUSY); | |
b5b969e9 | 92 | return -1; |
8bd0fc0e | 93 | } |
b5b969e9 | 94 | } |
17f6b900 | 95 | sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2); |
b5b969e9 | 96 | |
b305c684 JM |
97 | #ifdef CONFIG_P2P |
98 | if (elems.p2p) { | |
99 | wpabuf_free(sta->p2p_ie); | |
2bb20281 | 100 | sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len, |
b305c684 JM |
101 | P2P_IE_VENDOR_TYPE); |
102 | } | |
103 | #endif /* CONFIG_P2P */ | |
104 | ||
b5b969e9 JM |
105 | if (hapd->conf->wpa) { |
106 | if (ie == NULL || ielen == 0) { | |
633d4469 | 107 | #ifdef CONFIG_WPS |
b5b969e9 JM |
108 | if (hapd->conf->wps_state) { |
109 | wpa_printf(MSG_DEBUG, "STA did not include " | |
110 | "WPA/RSN IE in (Re)Association " | |
111 | "Request - possible WPS use"); | |
112 | sta->flags |= WLAN_STA_MAYBE_WPS; | |
113 | goto skip_wpa_check; | |
114 | } | |
633d4469 | 115 | #endif /* CONFIG_WPS */ |
b5b969e9 JM |
116 | |
117 | wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA"); | |
118 | return -1; | |
119 | } | |
633d4469 | 120 | #ifdef CONFIG_WPS |
b5b969e9 JM |
121 | if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 && |
122 | os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) { | |
17f6b900 | 123 | struct wpabuf *wps; |
b5b969e9 | 124 | sta->flags |= WLAN_STA_WPS; |
17f6b900 JM |
125 | wps = ieee802_11_vendor_ie_concat(ie, ielen, |
126 | WPS_IE_VENDOR_TYPE); | |
127 | if (wps) { | |
128 | if (wps_is_20(wps)) { | |
129 | wpa_printf(MSG_DEBUG, "WPS: STA " | |
130 | "supports WPS 2.0"); | |
131 | sta->flags |= WLAN_STA_WPS2; | |
132 | } | |
133 | wpabuf_free(wps); | |
134 | } | |
b5b969e9 JM |
135 | goto skip_wpa_check; |
136 | } | |
633d4469 | 137 | #endif /* CONFIG_WPS */ |
b5b969e9 JM |
138 | |
139 | if (sta->wpa_sm == NULL) | |
140 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, | |
141 | sta->addr); | |
142 | if (sta->wpa_sm == NULL) { | |
143 | wpa_printf(MSG_ERROR, "Failed to initialize WPA state " | |
144 | "machine"); | |
145 | return -1; | |
146 | } | |
147 | res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, | |
148 | ie, ielen, NULL, 0); | |
149 | if (res != WPA_IE_OK) { | |
150 | wpa_printf(MSG_DEBUG, "WPA/RSN information element " | |
151 | "rejected? (res %u)", res); | |
152 | wpa_hexdump(MSG_DEBUG, "IE", ie, ielen); | |
355d36a7 | 153 | if (res == WPA_INVALID_GROUP) |
08a74e6a | 154 | reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID; |
355d36a7 | 155 | else if (res == WPA_INVALID_PAIRWISE) |
08a74e6a | 156 | reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID; |
355d36a7 | 157 | else if (res == WPA_INVALID_AKMP) |
08a74e6a | 158 | reason = WLAN_REASON_AKMP_NOT_VALID; |
355d36a7 AT |
159 | #ifdef CONFIG_IEEE80211W |
160 | else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) | |
08a74e6a | 161 | reason = WLAN_REASON_INVALID_IE; |
355d36a7 | 162 | else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) |
08a74e6a | 163 | reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID; |
355d36a7 AT |
164 | #endif /* CONFIG_IEEE80211W */ |
165 | else | |
08a74e6a JM |
166 | reason = WLAN_REASON_INVALID_IE; |
167 | goto fail; | |
b5b969e9 | 168 | } |
a9aca28b | 169 | } else if (hapd->conf->wps_state) { |
633d4469 | 170 | #ifdef CONFIG_WPS |
17f6b900 | 171 | struct wpabuf *wps; |
2bb20281 JM |
172 | if (req_ies) |
173 | wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len, | |
fa15d405 JM |
174 | WPS_IE_VENDOR_TYPE); |
175 | else | |
176 | wps = NULL; | |
54f489be | 177 | #ifdef CONFIG_WPS_STRICT |
fa15d405 | 178 | if (wps && wps_validate_assoc_req(wps) < 0) { |
08a74e6a | 179 | reason = WLAN_REASON_INVALID_IE; |
fa15d405 | 180 | wpabuf_free(wps); |
08a74e6a | 181 | goto fail; |
54f489be | 182 | } |
54f489be | 183 | #endif /* CONFIG_WPS_STRICT */ |
fa15d405 | 184 | if (wps) { |
a9aca28b | 185 | sta->flags |= WLAN_STA_WPS; |
fa15d405 | 186 | if (wps_is_20(wps)) { |
17f6b900 JM |
187 | wpa_printf(MSG_DEBUG, "WPS: STA supports " |
188 | "WPS 2.0"); | |
189 | sta->flags |= WLAN_STA_WPS2; | |
190 | } | |
a9aca28b JM |
191 | } else |
192 | sta->flags |= WLAN_STA_MAYBE_WPS; | |
17f6b900 | 193 | wpabuf_free(wps); |
633d4469 | 194 | #endif /* CONFIG_WPS */ |
b5b969e9 | 195 | } |
633d4469 | 196 | #ifdef CONFIG_WPS |
b5b969e9 | 197 | skip_wpa_check: |
633d4469 | 198 | #endif /* CONFIG_WPS */ |
b5b969e9 JM |
199 | |
200 | new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0; | |
201 | sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC; | |
202 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC); | |
203 | ||
204 | hostapd_new_assoc_sta(hapd, sta, !new_assoc); | |
205 | ||
206 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); | |
207 | ||
ef796391 | 208 | #ifdef CONFIG_P2P |
99c01af9 JM |
209 | if (req_ies) { |
210 | p2p_group_notif_assoc(hapd->p2p_group, sta->addr, | |
211 | req_ies, req_ies_len); | |
212 | } | |
ef796391 JM |
213 | #endif /* CONFIG_P2P */ |
214 | ||
b5b969e9 | 215 | return 0; |
08a74e6a JM |
216 | |
217 | fail: | |
218 | hostapd_drv_sta_disassoc(hapd, sta->addr, reason); | |
219 | ap_free_sta(hapd, sta); | |
220 | return -1; | |
b5b969e9 JM |
221 | } |
222 | ||
223 | ||
224 | void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr) | |
225 | { | |
226 | struct sta_info *sta; | |
227 | ||
83e843e8 JM |
228 | if (addr == NULL) { |
229 | /* | |
230 | * This could potentially happen with unexpected event from the | |
231 | * driver wrapper. This was seen at least in one case where the | |
232 | * driver ended up reporting a station mode event while hostapd | |
233 | * was running, so better make sure we stop processing such an | |
234 | * event here. | |
235 | */ | |
236 | wpa_printf(MSG_DEBUG, "hostapd_notif_disassoc: Skip event " | |
237 | "with no address"); | |
1f4c7b6b | 238 | return; |
83e843e8 JM |
239 | } |
240 | ||
b5b969e9 JM |
241 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, |
242 | HOSTAPD_LEVEL_INFO, "disassociated"); | |
243 | ||
244 | sta = ap_get_sta(hapd, addr); | |
245 | if (sta == NULL) { | |
246 | wpa_printf(MSG_DEBUG, "Disassociation notification for " | |
247 | "unknown STA " MACSTR, MAC2STR(addr)); | |
248 | return; | |
249 | } | |
250 | ||
ae055af4 | 251 | ap_sta_set_authorized(hapd, sta, 0); |
b5b969e9 JM |
252 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); |
253 | wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC); | |
254 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; | |
255 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
256 | ap_free_sta(hapd, sta); | |
257 | } | |
258 | ||
259 | ||
0d7e5a3a JB |
260 | void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr) |
261 | { | |
262 | struct sta_info *sta = ap_get_sta(hapd, addr); | |
263 | ||
264 | if (!sta || !hapd->conf->disassoc_low_ack) | |
265 | return; | |
266 | ||
267 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, | |
268 | HOSTAPD_LEVEL_INFO, "disconnected due to excessive " | |
269 | "missing ACKs"); | |
270 | hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK); | |
271 | if (sta) | |
272 | ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK); | |
273 | } | |
274 | ||
275 | ||
04a85e44 | 276 | int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da, |
baf513d6 JB |
277 | const u8 *bssid, const u8 *ie, size_t ie_len, |
278 | int ssi_signal) | |
e67b55fb JM |
279 | { |
280 | size_t i; | |
281 | int ret = 0; | |
282 | ||
b211f3eb JM |
283 | if (sa == NULL || ie == NULL) |
284 | return -1; | |
285 | ||
286 | random_add_randomness(sa, ETH_ALEN); | |
e67b55fb JM |
287 | for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) { |
288 | if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, | |
baf513d6 JB |
289 | sa, da, bssid, ie, ie_len, |
290 | ssi_signal) > 0) { | |
e67b55fb JM |
291 | ret = 1; |
292 | break; | |
293 | } | |
294 | } | |
295 | return ret; | |
296 | } | |
297 | ||
298 | ||
f8b1f695 JM |
299 | #ifdef HOSTAPD |
300 | ||
fe6bdb77 | 301 | #ifdef NEED_AP_MLME |
f8b1f695 | 302 | |
f8b1f695 JM |
303 | #define HAPD_BROADCAST ((struct hostapd_data *) -1) |
304 | ||
305 | static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface, | |
306 | const u8 *bssid) | |
307 | { | |
308 | size_t i; | |
309 | ||
310 | if (bssid == NULL) | |
311 | return NULL; | |
312 | if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff && | |
313 | bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff) | |
314 | return HAPD_BROADCAST; | |
315 | ||
316 | for (i = 0; i < iface->num_bss; i++) { | |
317 | if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0) | |
318 | return iface->bss[i]; | |
319 | } | |
320 | ||
321 | return NULL; | |
322 | } | |
323 | ||
324 | ||
325 | static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd, | |
9b90955e JB |
326 | const u8 *bssid, const u8 *addr, |
327 | int wds) | |
f8b1f695 | 328 | { |
9b90955e | 329 | hapd = get_hapd_bssid(hapd->iface, bssid); |
f8b1f695 JM |
330 | if (hapd == NULL || hapd == HAPD_BROADCAST) |
331 | return; | |
332 | ||
9b90955e | 333 | ieee802_11_rx_from_unknown(hapd, addr, wds); |
f8b1f695 JM |
334 | } |
335 | ||
336 | ||
2a8b7416 | 337 | static void hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt) |
b5b969e9 | 338 | { |
4b9841d3 | 339 | struct hostapd_iface *iface = hapd->iface; |
b57e086c | 340 | const struct ieee80211_hdr *hdr; |
4b9841d3 | 341 | const u8 *bssid; |
2a8b7416 | 342 | struct hostapd_frame_info fi; |
4b9841d3 | 343 | |
2a8b7416 JM |
344 | hdr = (const struct ieee80211_hdr *) rx_mgmt->frame; |
345 | bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len); | |
4b9841d3 JM |
346 | if (bssid == NULL) |
347 | return; | |
348 | ||
349 | hapd = get_hapd_bssid(iface, bssid); | |
350 | if (hapd == NULL) { | |
351 | u16 fc; | |
352 | fc = le_to_host16(hdr->frame_control); | |
353 | ||
354 | /* | |
355 | * Drop frames to unknown BSSIDs except for Beacon frames which | |
356 | * could be used to update neighbor information. | |
357 | */ | |
358 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
359 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) | |
360 | hapd = iface->bss[0]; | |
361 | else | |
362 | return; | |
363 | } | |
364 | ||
2a8b7416 JM |
365 | os_memset(&fi, 0, sizeof(fi)); |
366 | fi.datarate = rx_mgmt->datarate; | |
367 | fi.ssi_signal = rx_mgmt->ssi_signal; | |
368 | ||
4b9841d3 JM |
369 | if (hapd == HAPD_BROADCAST) { |
370 | size_t i; | |
371 | for (i = 0; i < iface->num_bss; i++) | |
2a8b7416 JM |
372 | ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame, |
373 | rx_mgmt->frame_len, &fi); | |
4b9841d3 | 374 | } else |
2a8b7416 | 375 | ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len, &fi); |
bbb921da JM |
376 | |
377 | random_add_randomness(&fi, sizeof(fi)); | |
b5b969e9 JM |
378 | } |
379 | ||
380 | ||
9e2704c3 JM |
381 | static void hostapd_rx_action(struct hostapd_data *hapd, |
382 | struct rx_action *rx_action) | |
383 | { | |
384 | struct rx_mgmt rx_mgmt; | |
385 | u8 *buf; | |
386 | struct ieee80211_hdr *hdr; | |
387 | ||
388 | wpa_printf(MSG_DEBUG, "EVENT_RX_ACTION DA=" MACSTR " SA=" MACSTR | |
389 | " BSSID=" MACSTR " category=%u", | |
390 | MAC2STR(rx_action->da), MAC2STR(rx_action->sa), | |
391 | MAC2STR(rx_action->bssid), rx_action->category); | |
392 | wpa_hexdump(MSG_MSGDUMP, "Received action frame contents", | |
393 | rx_action->data, rx_action->len); | |
394 | ||
395 | buf = os_zalloc(24 + 1 + rx_action->len); | |
396 | if (buf == NULL) | |
397 | return; | |
398 | hdr = (struct ieee80211_hdr *) buf; | |
399 | hdr->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
400 | WLAN_FC_STYPE_ACTION); | |
401 | if (rx_action->category == WLAN_ACTION_SA_QUERY) { | |
402 | /* | |
403 | * Assume frame was protected; it would have been dropped if | |
404 | * not. | |
405 | */ | |
406 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
407 | } | |
408 | os_memcpy(hdr->addr1, rx_action->da, ETH_ALEN); | |
409 | os_memcpy(hdr->addr2, rx_action->sa, ETH_ALEN); | |
410 | os_memcpy(hdr->addr3, rx_action->bssid, ETH_ALEN); | |
411 | buf[24] = rx_action->category; | |
412 | os_memcpy(buf + 24 + 1, rx_action->data, rx_action->len); | |
413 | os_memset(&rx_mgmt, 0, sizeof(rx_mgmt)); | |
414 | rx_mgmt.frame = buf; | |
415 | rx_mgmt.frame_len = 24 + 1 + rx_action->len; | |
416 | hostapd_mgmt_rx(hapd, &rx_mgmt); | |
417 | os_free(buf); | |
418 | } | |
419 | ||
420 | ||
f8b1f695 JM |
421 | static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf, |
422 | size_t len, u16 stype, int ok) | |
b5b969e9 | 423 | { |
4b9841d3 JM |
424 | struct ieee80211_hdr *hdr; |
425 | hdr = (struct ieee80211_hdr *) buf; | |
426 | hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len)); | |
427 | if (hapd == NULL || hapd == HAPD_BROADCAST) | |
428 | return; | |
b5b969e9 JM |
429 | ieee802_11_mgmt_cb(hapd, buf, len, stype, ok); |
430 | } | |
f82ef4d8 | 431 | |
f8b1f695 | 432 | #endif /* NEED_AP_MLME */ |
ad1e68e6 JM |
433 | |
434 | ||
a8e0505b JM |
435 | static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr) |
436 | { | |
437 | struct sta_info *sta = ap_get_sta(hapd, addr); | |
438 | if (sta) | |
439 | return 0; | |
440 | ||
441 | wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR | |
442 | " - adding a new STA", MAC2STR(addr)); | |
443 | sta = ap_sta_add(hapd, addr); | |
444 | if (sta) { | |
445 | hostapd_new_assoc_sta(hapd, sta, 0); | |
446 | } else { | |
447 | wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR, | |
448 | MAC2STR(addr)); | |
449 | return -1; | |
450 | } | |
451 | ||
452 | return 0; | |
453 | } | |
454 | ||
455 | ||
456 | static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src, | |
457 | const u8 *data, size_t data_len) | |
458 | { | |
459 | struct hostapd_iface *iface = hapd->iface; | |
460 | size_t j; | |
461 | ||
462 | for (j = 0; j < iface->num_bss; j++) { | |
463 | if (ap_get_sta(iface->bss[j], src)) { | |
464 | hapd = iface->bss[j]; | |
465 | break; | |
466 | } | |
467 | } | |
468 | ||
469 | ieee802_1x_receive(hapd, src, data, data_len); | |
470 | } | |
471 | ||
472 | ||
9646a8ab | 473 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
ad1e68e6 JM |
474 | union wpa_event_data *data) |
475 | { | |
476 | struct hostapd_data *hapd = ctx; | |
74781dfc JM |
477 | #ifndef CONFIG_NO_STDOUT_DEBUG |
478 | int level = MSG_DEBUG; | |
ad1e68e6 | 479 | |
74781dfc JM |
480 | if (event == EVENT_RX_MGMT && data && data->rx_mgmt.frame && |
481 | data->rx_mgmt.frame_len >= 24) { | |
482 | const struct ieee80211_hdr *hdr; | |
483 | u16 fc; | |
484 | hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; | |
485 | fc = le_to_host16(hdr->frame_control); | |
486 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
487 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) | |
488 | level = MSG_EXCESSIVE; | |
489 | } | |
490 | ||
491 | wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received", | |
e26cd1a1 | 492 | event_to_string(event), event); |
74781dfc | 493 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
e26cd1a1 | 494 | |
ad1e68e6 JM |
495 | switch (event) { |
496 | case EVENT_MICHAEL_MIC_FAILURE: | |
497 | michael_mic_failure(hapd, data->michael_mic_failure.src, 1); | |
498 | break; | |
499 | case EVENT_SCAN_RESULTS: | |
500 | if (hapd->iface->scan_cb) | |
501 | hapd->iface->scan_cb(hapd->iface); | |
502 | break; | |
08fd8c15 | 503 | #ifdef CONFIG_IEEE80211R |
f2dab64e | 504 | case EVENT_FT_RRB_RX: |
08fd8c15 JM |
505 | wpa_ft_rrb_rx(hapd->wpa_auth, data->ft_rrb_rx.src, |
506 | data->ft_rrb_rx.data, data->ft_rrb_rx.data_len); | |
507 | break; | |
508 | #endif /* CONFIG_IEEE80211R */ | |
fcf0f87d | 509 | case EVENT_WPS_BUTTON_PUSHED: |
d601247c | 510 | hostapd_wps_button_pushed(hapd, NULL); |
fcf0f87d | 511 | break; |
f8b1f695 JM |
512 | #ifdef NEED_AP_MLME |
513 | case EVENT_TX_STATUS: | |
514 | switch (data->tx_status.type) { | |
515 | case WLAN_FC_TYPE_MGMT: | |
516 | hostapd_mgmt_tx_cb(hapd, data->tx_status.data, | |
517 | data->tx_status.data_len, | |
518 | data->tx_status.stype, | |
519 | data->tx_status.ack); | |
520 | break; | |
521 | case WLAN_FC_TYPE_DATA: | |
522 | hostapd_tx_status(hapd, data->tx_status.dst, | |
523 | data->tx_status.data, | |
524 | data->tx_status.data_len, | |
525 | data->tx_status.ack); | |
526 | break; | |
527 | } | |
528 | break; | |
dd840f79 JB |
529 | case EVENT_EAPOL_TX_STATUS: |
530 | hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst, | |
531 | data->eapol_tx_status.data, | |
532 | data->eapol_tx_status.data_len, | |
533 | data->eapol_tx_status.ack); | |
534 | break; | |
bcf24348 JB |
535 | case EVENT_DRIVER_CLIENT_POLL_OK: |
536 | hostapd_client_poll_ok(hapd, data->client_poll.addr); | |
537 | break; | |
f8b1f695 | 538 | case EVENT_RX_FROM_UNKNOWN: |
9b90955e JB |
539 | hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid, |
540 | data->rx_from_unknown.addr, | |
541 | data->rx_from_unknown.wds); | |
f8b1f695 JM |
542 | break; |
543 | case EVENT_RX_MGMT: | |
2a8b7416 | 544 | hostapd_mgmt_rx(hapd, &data->rx_mgmt); |
f8b1f695 JM |
545 | break; |
546 | #endif /* NEED_AP_MLME */ | |
a0e0d3bb | 547 | case EVENT_RX_PROBE_REQ: |
b211f3eb JM |
548 | if (data->rx_probe_req.sa == NULL || |
549 | data->rx_probe_req.ie == NULL) | |
550 | break; | |
a0e0d3bb | 551 | hostapd_probe_req_rx(hapd, data->rx_probe_req.sa, |
04a85e44 JM |
552 | data->rx_probe_req.da, |
553 | data->rx_probe_req.bssid, | |
a0e0d3bb | 554 | data->rx_probe_req.ie, |
baf513d6 JB |
555 | data->rx_probe_req.ie_len, |
556 | data->rx_probe_req.ssi_signal); | |
a0e0d3bb | 557 | break; |
a70a5d6d | 558 | case EVENT_NEW_STA: |
a8e0505b JM |
559 | hostapd_event_new_sta(hapd, data->new_sta.addr); |
560 | break; | |
561 | case EVENT_EAPOL_RX: | |
562 | hostapd_event_eapol_rx(hapd, data->eapol_rx.src, | |
563 | data->eapol_rx.data, | |
564 | data->eapol_rx.data_len); | |
565 | break; | |
1d041bec JM |
566 | case EVENT_ASSOC: |
567 | hostapd_notif_assoc(hapd, data->assoc_info.addr, | |
568 | data->assoc_info.req_ies, | |
39b08b5f SP |
569 | data->assoc_info.req_ies_len, |
570 | data->assoc_info.reassoc); | |
1d041bec JM |
571 | break; |
572 | case EVENT_DISASSOC: | |
573 | if (data) | |
574 | hostapd_notif_disassoc(hapd, data->disassoc_info.addr); | |
575 | break; | |
576 | case EVENT_DEAUTH: | |
577 | if (data) | |
578 | hostapd_notif_disassoc(hapd, data->deauth_info.addr); | |
579 | break; | |
0d7e5a3a JB |
580 | case EVENT_STATION_LOW_ACK: |
581 | if (!data) | |
582 | break; | |
583 | hostapd_event_sta_low_ack(hapd, data->low_ack.addr); | |
584 | break; | |
7cc7307d | 585 | #ifdef NEED_AP_MLME |
9e2704c3 JM |
586 | case EVENT_RX_ACTION: |
587 | if (data->rx_action.da == NULL || data->rx_action.sa == NULL || | |
588 | data->rx_action.bssid == NULL) | |
589 | break; | |
590 | hostapd_rx_action(hapd, &data->rx_action); | |
591 | break; | |
7cc7307d | 592 | #endif /* NEED_AP_MLME */ |
ad1e68e6 JM |
593 | default: |
594 | wpa_printf(MSG_DEBUG, "Unknown event %d", event); | |
595 | break; | |
596 | } | |
597 | } | |
f8b1f695 JM |
598 | |
599 | #endif /* HOSTAPD */ |