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