]>
Commit | Line | Data |
---|---|---|
b5b969e9 JM |
1 | /* |
2 | * hostapd / Callback functions for driver wrappers | |
3 | * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi> | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License version 2 as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * Alternatively, this software may be distributed under the terms of BSD | |
10 | * license. | |
11 | * | |
12 | * See README and COPYING for more details. | |
13 | */ | |
14 | ||
6226e38d | 15 | #include "utils/includes.h" |
b5b969e9 | 16 | |
6226e38d | 17 | #include "utils/common.h" |
b5b969e9 | 18 | #include "radius/radius.h" |
6e6e8c31 | 19 | #include "drivers/driver.h" |
81f4f619 | 20 | #include "common/ieee802_11_defs.h" |
c41a1095 | 21 | #include "common/ieee802_11_common.h" |
9a3cb18d | 22 | #include "common/wpa_ctrl.h" |
bbb921da | 23 | #include "crypto/random.h" |
ef796391 | 24 | #include "p2p/p2p.h" |
54f489be | 25 | #include "wps/wps.h" |
6226e38d JM |
26 | #include "hostapd.h" |
27 | #include "ieee802_11.h" | |
28 | #include "sta_info.h" | |
29 | #include "accounting.h" | |
30 | #include "tkip_countermeasures.h" | |
31 | #include "iapp.h" | |
32 | #include "ieee802_1x.h" | |
33 | #include "wpa_auth.h" | |
34 | #include "wmm.h" | |
35 | #include "wps_hostapd.h" | |
51e2a27a | 36 | #include "ap_drv_ops.h" |
8b06c1ed | 37 | #include "ap_config.h" |
b5b969e9 JM |
38 | |
39 | ||
b5b969e9 | 40 | int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr, |
39b08b5f | 41 | const u8 *ie, size_t ielen, int reassoc) |
b5b969e9 JM |
42 | { |
43 | struct sta_info *sta; | |
44 | int new_assoc, res; | |
c41a1095 | 45 | struct ieee802_11_elems elems; |
b305c684 JM |
46 | #ifdef CONFIG_P2P |
47 | const u8 *all_ies = ie; | |
48 | size_t all_ies_len = ielen; | |
49 | #endif /* CONFIG_P2P */ | |
b5b969e9 | 50 | |
68532a9c JM |
51 | if (addr == NULL) { |
52 | /* | |
53 | * This could potentially happen with unexpected event from the | |
54 | * driver wrapper. This was seen at least in one case where the | |
55 | * driver ended up being set to station mode while hostapd was | |
56 | * running, so better make sure we stop processing such an | |
57 | * event here. | |
58 | */ | |
59 | wpa_printf(MSG_DEBUG, "hostapd_notif_assoc: Skip event with " | |
60 | "no address"); | |
61 | return -1; | |
62 | } | |
bbb921da | 63 | random_add_randomness(addr, ETH_ALEN); |
68532a9c | 64 | |
b5b969e9 JM |
65 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, |
66 | HOSTAPD_LEVEL_INFO, "associated"); | |
67 | ||
c41a1095 JM |
68 | ieee802_11_parse_elems(ie, ielen, &elems, 0); |
69 | if (elems.wps_ie) { | |
70 | ie = elems.wps_ie - 2; | |
71 | ielen = elems.wps_ie_len + 2; | |
72 | wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq"); | |
73 | } else if (elems.rsn_ie) { | |
74 | ie = elems.rsn_ie - 2; | |
75 | ielen = elems.rsn_ie_len + 2; | |
76 | wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq"); | |
77 | } else if (elems.wpa_ie) { | |
78 | ie = elems.wpa_ie - 2; | |
79 | ielen = elems.wpa_ie_len + 2; | |
80 | wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq"); | |
81 | } else { | |
82 | ie = NULL; | |
83 | ielen = 0; | |
84 | wpa_printf(MSG_DEBUG, "STA did not include WPS/RSN/WPA IE in " | |
85 | "(Re)AssocReq"); | |
86 | } | |
87 | ||
b5b969e9 JM |
88 | sta = ap_get_sta(hapd, addr); |
89 | if (sta) { | |
90 | accounting_sta_stop(hapd, sta); | |
91 | } else { | |
92 | sta = ap_sta_add(hapd, addr); | |
93 | if (sta == NULL) | |
94 | return -1; | |
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); | |
101 | sta->p2p_ie = ieee802_11_vendor_ie_concat(all_ies, all_ies_len, | |
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) { | |
355d36a7 | 151 | int resp; |
b5b969e9 JM |
152 | wpa_printf(MSG_DEBUG, "WPA/RSN information element " |
153 | "rejected? (res %u)", res); | |
154 | wpa_hexdump(MSG_DEBUG, "IE", ie, ielen); | |
355d36a7 AT |
155 | if (res == WPA_INVALID_GROUP) |
156 | resp = WLAN_REASON_GROUP_CIPHER_NOT_VALID; | |
157 | else if (res == WPA_INVALID_PAIRWISE) | |
158 | resp = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID; | |
159 | else if (res == WPA_INVALID_AKMP) | |
160 | resp = WLAN_REASON_AKMP_NOT_VALID; | |
161 | #ifdef CONFIG_IEEE80211W | |
162 | else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) | |
163 | resp = WLAN_REASON_INVALID_IE; | |
164 | else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) | |
165 | resp = WLAN_REASON_GROUP_CIPHER_NOT_VALID; | |
166 | #endif /* CONFIG_IEEE80211W */ | |
167 | else | |
168 | resp = WLAN_REASON_INVALID_IE; | |
51e2a27a | 169 | hostapd_drv_sta_disassoc(hapd, sta->addr, resp); |
355d36a7 | 170 | ap_free_sta(hapd, sta); |
b5b969e9 JM |
171 | return -1; |
172 | } | |
a9aca28b | 173 | } else if (hapd->conf->wps_state) { |
633d4469 | 174 | #ifdef CONFIG_WPS |
17f6b900 JM |
175 | struct wpabuf *wps; |
176 | wps = ieee802_11_vendor_ie_concat(ie, ielen, | |
177 | WPS_IE_VENDOR_TYPE); | |
54f489be | 178 | #ifdef CONFIG_WPS_STRICT |
6e432d3f | 179 | if (ie) { |
6e432d3f JM |
180 | if (wps && wps_validate_assoc_req(wps) < 0) { |
181 | hostapd_drv_sta_disassoc( | |
182 | hapd, sta->addr, | |
183 | WLAN_REASON_INVALID_IE); | |
184 | ap_free_sta(hapd, sta); | |
185 | wpabuf_free(wps); | |
186 | return -1; | |
187 | } | |
54f489be | 188 | wpabuf_free(wps); |
54f489be | 189 | } |
54f489be | 190 | #endif /* CONFIG_WPS_STRICT */ |
a9aca28b JM |
191 | if (ie && ielen > 4 && ie[0] == 0xdd && ie[1] >= 4 && |
192 | os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) { | |
193 | sta->flags |= WLAN_STA_WPS; | |
17f6b900 JM |
194 | if (wps && wps_is_20(wps)) { |
195 | wpa_printf(MSG_DEBUG, "WPS: STA supports " | |
196 | "WPS 2.0"); | |
197 | sta->flags |= WLAN_STA_WPS2; | |
198 | } | |
a9aca28b JM |
199 | } else |
200 | sta->flags |= WLAN_STA_MAYBE_WPS; | |
17f6b900 | 201 | wpabuf_free(wps); |
633d4469 | 202 | #endif /* CONFIG_WPS */ |
b5b969e9 | 203 | } |
633d4469 | 204 | #ifdef CONFIG_WPS |
b5b969e9 | 205 | skip_wpa_check: |
633d4469 | 206 | #endif /* CONFIG_WPS */ |
b5b969e9 JM |
207 | |
208 | new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0; | |
209 | sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC; | |
210 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC); | |
211 | ||
212 | hostapd_new_assoc_sta(hapd, sta, !new_assoc); | |
213 | ||
214 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); | |
215 | ||
ef796391 | 216 | #ifdef CONFIG_P2P |
3f4ce13f JM |
217 | p2p_group_notif_assoc(hapd->p2p_group, sta->addr, |
218 | all_ies, all_ies_len); | |
ef796391 JM |
219 | #endif /* CONFIG_P2P */ |
220 | ||
b5b969e9 JM |
221 | return 0; |
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 | ||
252 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); | |
9a3cb18d JM |
253 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED MACSTR, |
254 | MAC2STR(sta->addr)); | |
b5b969e9 JM |
255 | wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC); |
256 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; | |
257 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
258 | ap_free_sta(hapd, sta); | |
259 | } | |
260 | ||
261 | ||
0d7e5a3a JB |
262 | void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr) |
263 | { | |
264 | struct sta_info *sta = ap_get_sta(hapd, addr); | |
265 | ||
266 | if (!sta || !hapd->conf->disassoc_low_ack) | |
267 | return; | |
268 | ||
269 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, | |
270 | HOSTAPD_LEVEL_INFO, "disconnected due to excessive " | |
271 | "missing ACKs"); | |
272 | hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK); | |
273 | if (sta) | |
274 | ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK); | |
275 | } | |
276 | ||
277 | ||
04a85e44 JM |
278 | int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da, |
279 | const u8 *bssid, const u8 *ie, size_t ie_len) | |
e67b55fb JM |
280 | { |
281 | size_t i; | |
282 | int ret = 0; | |
283 | ||
b211f3eb JM |
284 | if (sa == NULL || ie == NULL) |
285 | return -1; | |
286 | ||
287 | random_add_randomness(sa, ETH_ALEN); | |
e67b55fb JM |
288 | for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) { |
289 | if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, | |
04a85e44 | 290 | sa, da, bssid, ie, ie_len) > 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 JM |
302 | |
303 | static const u8 * get_hdr_bssid(const struct ieee80211_hdr *hdr, size_t len) | |
304 | { | |
305 | u16 fc, type, stype; | |
306 | ||
307 | /* | |
308 | * PS-Poll frames are 16 bytes. All other frames are | |
309 | * 24 bytes or longer. | |
310 | */ | |
311 | if (len < 16) | |
312 | return NULL; | |
313 | ||
314 | fc = le_to_host16(hdr->frame_control); | |
315 | type = WLAN_FC_GET_TYPE(fc); | |
316 | stype = WLAN_FC_GET_STYPE(fc); | |
317 | ||
318 | switch (type) { | |
319 | case WLAN_FC_TYPE_DATA: | |
320 | if (len < 24) | |
321 | return NULL; | |
322 | switch (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) { | |
fbbfcbac | 323 | case WLAN_FC_FROMDS | WLAN_FC_TODS: |
f8b1f695 JM |
324 | case WLAN_FC_TODS: |
325 | return hdr->addr1; | |
326 | case WLAN_FC_FROMDS: | |
327 | return hdr->addr2; | |
328 | default: | |
329 | return NULL; | |
330 | } | |
331 | case WLAN_FC_TYPE_CTRL: | |
332 | if (stype != WLAN_FC_STYPE_PSPOLL) | |
333 | return NULL; | |
334 | return hdr->addr1; | |
335 | case WLAN_FC_TYPE_MGMT: | |
336 | return hdr->addr3; | |
337 | default: | |
338 | return NULL; | |
339 | } | |
340 | } | |
341 | ||
342 | ||
343 | #define HAPD_BROADCAST ((struct hostapd_data *) -1) | |
344 | ||
345 | static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface, | |
346 | const u8 *bssid) | |
347 | { | |
348 | size_t i; | |
349 | ||
350 | if (bssid == NULL) | |
351 | return NULL; | |
352 | if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff && | |
353 | bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff) | |
354 | return HAPD_BROADCAST; | |
355 | ||
356 | for (i = 0; i < iface->num_bss; i++) { | |
357 | if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0) | |
358 | return iface->bss[i]; | |
359 | } | |
360 | ||
361 | return NULL; | |
362 | } | |
363 | ||
364 | ||
365 | static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd, | |
0d9fc3d8 | 366 | const u8 *frame, size_t len) |
f8b1f695 | 367 | { |
0d9fc3d8 | 368 | const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *) frame; |
fbbfcbac | 369 | u16 fc = le_to_host16(hdr->frame_control); |
f8b1f695 JM |
370 | hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len)); |
371 | if (hapd == NULL || hapd == HAPD_BROADCAST) | |
372 | return; | |
373 | ||
fbbfcbac FF |
374 | ieee802_11_rx_from_unknown(hapd, hdr->addr2, |
375 | (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) == | |
376 | (WLAN_FC_TODS | WLAN_FC_FROMDS)); | |
f8b1f695 JM |
377 | } |
378 | ||
379 | ||
2a8b7416 | 380 | static void hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt) |
b5b969e9 | 381 | { |
4b9841d3 | 382 | struct hostapd_iface *iface = hapd->iface; |
b57e086c | 383 | const struct ieee80211_hdr *hdr; |
4b9841d3 | 384 | const u8 *bssid; |
2a8b7416 | 385 | struct hostapd_frame_info fi; |
4b9841d3 | 386 | |
2a8b7416 JM |
387 | hdr = (const struct ieee80211_hdr *) rx_mgmt->frame; |
388 | bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len); | |
4b9841d3 JM |
389 | if (bssid == NULL) |
390 | return; | |
391 | ||
392 | hapd = get_hapd_bssid(iface, bssid); | |
393 | if (hapd == NULL) { | |
394 | u16 fc; | |
395 | fc = le_to_host16(hdr->frame_control); | |
396 | ||
397 | /* | |
398 | * Drop frames to unknown BSSIDs except for Beacon frames which | |
399 | * could be used to update neighbor information. | |
400 | */ | |
401 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
402 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) | |
403 | hapd = iface->bss[0]; | |
404 | else | |
405 | return; | |
406 | } | |
407 | ||
2a8b7416 JM |
408 | os_memset(&fi, 0, sizeof(fi)); |
409 | fi.datarate = rx_mgmt->datarate; | |
410 | fi.ssi_signal = rx_mgmt->ssi_signal; | |
411 | ||
4b9841d3 JM |
412 | if (hapd == HAPD_BROADCAST) { |
413 | size_t i; | |
414 | for (i = 0; i < iface->num_bss; i++) | |
2a8b7416 JM |
415 | ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame, |
416 | rx_mgmt->frame_len, &fi); | |
4b9841d3 | 417 | } else |
2a8b7416 | 418 | ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len, &fi); |
bbb921da JM |
419 | |
420 | random_add_randomness(&fi, sizeof(fi)); | |
b5b969e9 JM |
421 | } |
422 | ||
423 | ||
9e2704c3 JM |
424 | static void hostapd_rx_action(struct hostapd_data *hapd, |
425 | struct rx_action *rx_action) | |
426 | { | |
427 | struct rx_mgmt rx_mgmt; | |
428 | u8 *buf; | |
429 | struct ieee80211_hdr *hdr; | |
430 | ||
431 | wpa_printf(MSG_DEBUG, "EVENT_RX_ACTION DA=" MACSTR " SA=" MACSTR | |
432 | " BSSID=" MACSTR " category=%u", | |
433 | MAC2STR(rx_action->da), MAC2STR(rx_action->sa), | |
434 | MAC2STR(rx_action->bssid), rx_action->category); | |
435 | wpa_hexdump(MSG_MSGDUMP, "Received action frame contents", | |
436 | rx_action->data, rx_action->len); | |
437 | ||
438 | buf = os_zalloc(24 + 1 + rx_action->len); | |
439 | if (buf == NULL) | |
440 | return; | |
441 | hdr = (struct ieee80211_hdr *) buf; | |
442 | hdr->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
443 | WLAN_FC_STYPE_ACTION); | |
444 | if (rx_action->category == WLAN_ACTION_SA_QUERY) { | |
445 | /* | |
446 | * Assume frame was protected; it would have been dropped if | |
447 | * not. | |
448 | */ | |
449 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
450 | } | |
451 | os_memcpy(hdr->addr1, rx_action->da, ETH_ALEN); | |
452 | os_memcpy(hdr->addr2, rx_action->sa, ETH_ALEN); | |
453 | os_memcpy(hdr->addr3, rx_action->bssid, ETH_ALEN); | |
454 | buf[24] = rx_action->category; | |
455 | os_memcpy(buf + 24 + 1, rx_action->data, rx_action->len); | |
456 | os_memset(&rx_mgmt, 0, sizeof(rx_mgmt)); | |
457 | rx_mgmt.frame = buf; | |
458 | rx_mgmt.frame_len = 24 + 1 + rx_action->len; | |
459 | hostapd_mgmt_rx(hapd, &rx_mgmt); | |
460 | os_free(buf); | |
461 | } | |
462 | ||
463 | ||
f8b1f695 JM |
464 | static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf, |
465 | size_t len, u16 stype, int ok) | |
b5b969e9 | 466 | { |
4b9841d3 JM |
467 | struct ieee80211_hdr *hdr; |
468 | hdr = (struct ieee80211_hdr *) buf; | |
469 | hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len)); | |
470 | if (hapd == NULL || hapd == HAPD_BROADCAST) | |
471 | return; | |
b5b969e9 JM |
472 | ieee802_11_mgmt_cb(hapd, buf, len, stype, ok); |
473 | } | |
f82ef4d8 | 474 | |
f8b1f695 | 475 | #endif /* NEED_AP_MLME */ |
ad1e68e6 JM |
476 | |
477 | ||
a8e0505b JM |
478 | static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr) |
479 | { | |
480 | struct sta_info *sta = ap_get_sta(hapd, addr); | |
481 | if (sta) | |
482 | return 0; | |
483 | ||
484 | wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR | |
485 | " - adding a new STA", MAC2STR(addr)); | |
486 | sta = ap_sta_add(hapd, addr); | |
487 | if (sta) { | |
488 | hostapd_new_assoc_sta(hapd, sta, 0); | |
489 | } else { | |
490 | wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR, | |
491 | MAC2STR(addr)); | |
492 | return -1; | |
493 | } | |
494 | ||
495 | return 0; | |
496 | } | |
497 | ||
498 | ||
499 | static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src, | |
500 | const u8 *data, size_t data_len) | |
501 | { | |
502 | struct hostapd_iface *iface = hapd->iface; | |
503 | size_t j; | |
504 | ||
505 | for (j = 0; j < iface->num_bss; j++) { | |
506 | if (ap_get_sta(iface->bss[j], src)) { | |
507 | hapd = iface->bss[j]; | |
508 | break; | |
509 | } | |
510 | } | |
511 | ||
512 | ieee802_1x_receive(hapd, src, data, data_len); | |
513 | } | |
514 | ||
515 | ||
9646a8ab | 516 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
ad1e68e6 JM |
517 | union wpa_event_data *data) |
518 | { | |
519 | struct hostapd_data *hapd = ctx; | |
520 | ||
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; | |
555 | case EVENT_RX_FROM_UNKNOWN: | |
0d9fc3d8 | 556 | hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.frame, |
f8b1f695 JM |
557 | data->rx_from_unknown.len); |
558 | break; | |
559 | case EVENT_RX_MGMT: | |
2a8b7416 | 560 | hostapd_mgmt_rx(hapd, &data->rx_mgmt); |
f8b1f695 JM |
561 | break; |
562 | #endif /* NEED_AP_MLME */ | |
a0e0d3bb | 563 | case EVENT_RX_PROBE_REQ: |
b211f3eb JM |
564 | if (data->rx_probe_req.sa == NULL || |
565 | data->rx_probe_req.ie == NULL) | |
566 | break; | |
a0e0d3bb | 567 | hostapd_probe_req_rx(hapd, data->rx_probe_req.sa, |
04a85e44 JM |
568 | data->rx_probe_req.da, |
569 | data->rx_probe_req.bssid, | |
a0e0d3bb JM |
570 | data->rx_probe_req.ie, |
571 | data->rx_probe_req.ie_len); | |
572 | break; | |
a70a5d6d | 573 | case EVENT_NEW_STA: |
a8e0505b JM |
574 | hostapd_event_new_sta(hapd, data->new_sta.addr); |
575 | break; | |
576 | case EVENT_EAPOL_RX: | |
577 | hostapd_event_eapol_rx(hapd, data->eapol_rx.src, | |
578 | data->eapol_rx.data, | |
579 | data->eapol_rx.data_len); | |
580 | break; | |
1d041bec JM |
581 | case EVENT_ASSOC: |
582 | hostapd_notif_assoc(hapd, data->assoc_info.addr, | |
583 | data->assoc_info.req_ies, | |
39b08b5f SP |
584 | data->assoc_info.req_ies_len, |
585 | data->assoc_info.reassoc); | |
1d041bec JM |
586 | break; |
587 | case EVENT_DISASSOC: | |
588 | if (data) | |
589 | hostapd_notif_disassoc(hapd, data->disassoc_info.addr); | |
590 | break; | |
591 | case EVENT_DEAUTH: | |
592 | if (data) | |
593 | hostapd_notif_disassoc(hapd, data->deauth_info.addr); | |
594 | break; | |
0d7e5a3a JB |
595 | case EVENT_STATION_LOW_ACK: |
596 | if (!data) | |
597 | break; | |
598 | hostapd_event_sta_low_ack(hapd, data->low_ack.addr); | |
599 | break; | |
7cc7307d | 600 | #ifdef NEED_AP_MLME |
9e2704c3 JM |
601 | case EVENT_RX_ACTION: |
602 | if (data->rx_action.da == NULL || data->rx_action.sa == NULL || | |
603 | data->rx_action.bssid == NULL) | |
604 | break; | |
605 | hostapd_rx_action(hapd, &data->rx_action); | |
606 | break; | |
7cc7307d | 607 | #endif /* NEED_AP_MLME */ |
ad1e68e6 JM |
608 | default: |
609 | wpa_printf(MSG_DEBUG, "Unknown event %d", event); | |
610 | break; | |
611 | } | |
612 | } | |
f8b1f695 JM |
613 | |
614 | #endif /* HOSTAPD */ |