]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * hostapd / Station table | |
0f5eb69f | 3 | * Copyright (c) 2002-2016, Jouni Malinen <j@w1.fi> |
6fc6879b | 4 | * |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
6fc6879b JM |
7 | */ |
8 | ||
6226e38d | 9 | #include "utils/includes.h" |
6fc6879b | 10 | |
6226e38d JM |
11 | #include "utils/common.h" |
12 | #include "utils/eloop.h" | |
81f4f619 | 13 | #include "common/ieee802_11_defs.h" |
6caaae1e | 14 | #include "common/wpa_ctrl.h" |
a46d72d7 | 15 | #include "common/sae.h" |
bdee6fce JM |
16 | #include "radius/radius.h" |
17 | #include "radius/radius_client.h" | |
8ccbe415 | 18 | #include "p2p/p2p.h" |
6959145b | 19 | #include "fst/fst.h" |
6fc6879b | 20 | #include "hostapd.h" |
6fc6879b JM |
21 | #include "accounting.h" |
22 | #include "ieee802_1x.h" | |
23 | #include "ieee802_11.h" | |
f2a14be7 | 24 | #include "ieee802_11_auth.h" |
6226e38d JM |
25 | #include "wpa_auth.h" |
26 | #include "preauth_auth.h" | |
27 | #include "ap_config.h" | |
6fc6879b | 28 | #include "beacon.h" |
6226e38d | 29 | #include "ap_mlme.h" |
6fc6879b | 30 | #include "vlan_init.h" |
aefb53bd | 31 | #include "p2p_hostapd.h" |
cee7d66b | 32 | #include "ap_drv_ops.h" |
dca30c3f | 33 | #include "gas_serv.h" |
97596f8e | 34 | #include "wnm_ap.h" |
ca911d61 | 35 | #include "mbo_ap.h" |
bd00c431 | 36 | #include "ndisc_snoop.h" |
6226e38d | 37 | #include "sta_info.h" |
1889af2e | 38 | #include "vlan.h" |
0f5eb69f | 39 | #include "wps_hostapd.h" |
6fc6879b | 40 | |
53f3d6f3 FF |
41 | static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd, |
42 | struct sta_info *sta); | |
6fc6879b | 43 | static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx); |
97596f8e | 44 | static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx); |
4dc03726 JM |
45 | static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx); |
46 | static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx); | |
5d22a1d5 | 47 | #ifdef CONFIG_IEEE80211W |
93b76319 | 48 | static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx); |
5d22a1d5 | 49 | #endif /* CONFIG_IEEE80211W */ |
4dc03726 | 50 | static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta); |
0f5eb69f | 51 | static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx); |
6fc6879b JM |
52 | |
53 | int ap_for_each_sta(struct hostapd_data *hapd, | |
54 | int (*cb)(struct hostapd_data *hapd, struct sta_info *sta, | |
55 | void *ctx), | |
56 | void *ctx) | |
57 | { | |
58 | struct sta_info *sta; | |
59 | ||
60 | for (sta = hapd->sta_list; sta; sta = sta->next) { | |
61 | if (cb(hapd, sta, ctx)) | |
62 | return 1; | |
63 | } | |
64 | ||
65 | return 0; | |
66 | } | |
67 | ||
68 | ||
69 | struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta) | |
70 | { | |
71 | struct sta_info *s; | |
72 | ||
73 | s = hapd->sta_hash[STA_HASH(sta)]; | |
74 | while (s != NULL && os_memcmp(s->addr, sta, 6) != 0) | |
75 | s = s->hnext; | |
76 | return s; | |
77 | } | |
78 | ||
79 | ||
f2c56602 JM |
80 | #ifdef CONFIG_P2P |
81 | struct sta_info * ap_get_sta_p2p(struct hostapd_data *hapd, const u8 *addr) | |
82 | { | |
83 | struct sta_info *sta; | |
84 | ||
85 | for (sta = hapd->sta_list; sta; sta = sta->next) { | |
86 | const u8 *p2p_dev_addr; | |
87 | ||
88 | if (sta->p2p_ie == NULL) | |
89 | continue; | |
90 | ||
91 | p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie); | |
92 | if (p2p_dev_addr == NULL) | |
93 | continue; | |
94 | ||
95 | if (os_memcmp(p2p_dev_addr, addr, ETH_ALEN) == 0) | |
96 | return sta; | |
97 | } | |
98 | ||
99 | return NULL; | |
100 | } | |
101 | #endif /* CONFIG_P2P */ | |
102 | ||
103 | ||
6fc6879b JM |
104 | static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta) |
105 | { | |
106 | struct sta_info *tmp; | |
107 | ||
108 | if (hapd->sta_list == sta) { | |
109 | hapd->sta_list = sta->next; | |
110 | return; | |
111 | } | |
112 | ||
113 | tmp = hapd->sta_list; | |
114 | while (tmp != NULL && tmp->next != sta) | |
115 | tmp = tmp->next; | |
116 | if (tmp == NULL) { | |
117 | wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from " | |
118 | "list.", MAC2STR(sta->addr)); | |
119 | } else | |
120 | tmp->next = sta->next; | |
121 | } | |
122 | ||
123 | ||
124 | void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta) | |
125 | { | |
126 | sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)]; | |
127 | hapd->sta_hash[STA_HASH(sta->addr)] = sta; | |
128 | } | |
129 | ||
130 | ||
131 | static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta) | |
132 | { | |
133 | struct sta_info *s; | |
134 | ||
135 | s = hapd->sta_hash[STA_HASH(sta->addr)]; | |
136 | if (s == NULL) return; | |
137 | if (os_memcmp(s->addr, sta->addr, 6) == 0) { | |
138 | hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext; | |
139 | return; | |
140 | } | |
141 | ||
142 | while (s->hnext != NULL && | |
143 | os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0) | |
144 | s = s->hnext; | |
145 | if (s->hnext != NULL) | |
146 | s->hnext = s->hnext->hnext; | |
147 | else | |
148 | wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR | |
149 | " from hash table", MAC2STR(sta->addr)); | |
150 | } | |
151 | ||
152 | ||
bd00c431 KP |
153 | void ap_sta_ip6addr_del(struct hostapd_data *hapd, struct sta_info *sta) |
154 | { | |
155 | sta_ip6addr_del(hapd, sta); | |
156 | } | |
157 | ||
158 | ||
6fc6879b JM |
159 | void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta) |
160 | { | |
161 | int set_beacon = 0; | |
162 | ||
163 | accounting_sta_stop(hapd, sta); | |
164 | ||
6905dcb1 JB |
165 | /* just in case */ |
166 | ap_sta_set_authorized(hapd, sta, 0); | |
167 | ||
39f42d11 | 168 | if (sta->flags & WLAN_STA_WDS) |
69dd2967 | 169 | hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0); |
53f3d6f3 | 170 | |
7d597d46 | 171 | if (sta->ipaddr) |
ed4ddb6d | 172 | hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr); |
bd00c431 | 173 | ap_sta_ip6addr_del(hapd, sta); |
7d597d46 | 174 | |
354c903f | 175 | if (!hapd->iface->driver_ap_teardown && |
bb598c3b | 176 | !(sta->flags & WLAN_STA_PREAUTH)) { |
51e2a27a | 177 | hostapd_drv_sta_remove(hapd, sta->addr); |
bb598c3b AB |
178 | sta->added_unassoc = 0; |
179 | } | |
6fc6879b JM |
180 | |
181 | ap_sta_hash_del(hapd, sta); | |
182 | ap_sta_list_del(hapd, sta); | |
183 | ||
184 | if (sta->aid > 0) | |
2991469c JM |
185 | hapd->sta_aid[(sta->aid - 1) / 32] &= |
186 | ~BIT((sta->aid - 1) % 32); | |
6fc6879b JM |
187 | |
188 | hapd->num_sta--; | |
189 | if (sta->nonerp_set) { | |
190 | sta->nonerp_set = 0; | |
191 | hapd->iface->num_sta_non_erp--; | |
192 | if (hapd->iface->num_sta_non_erp == 0) | |
193 | set_beacon++; | |
194 | } | |
195 | ||
196 | if (sta->no_short_slot_time_set) { | |
197 | sta->no_short_slot_time_set = 0; | |
198 | hapd->iface->num_sta_no_short_slot_time--; | |
199 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G | |
200 | && hapd->iface->num_sta_no_short_slot_time == 0) | |
201 | set_beacon++; | |
202 | } | |
203 | ||
204 | if (sta->no_short_preamble_set) { | |
205 | sta->no_short_preamble_set = 0; | |
206 | hapd->iface->num_sta_no_short_preamble--; | |
207 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G | |
208 | && hapd->iface->num_sta_no_short_preamble == 0) | |
209 | set_beacon++; | |
210 | } | |
211 | ||
e8ff1e59 JM |
212 | if (sta->no_ht_gf_set) { |
213 | sta->no_ht_gf_set = 0; | |
214 | hapd->iface->num_sta_ht_no_gf--; | |
215 | } | |
216 | ||
217 | if (sta->no_ht_set) { | |
218 | sta->no_ht_set = 0; | |
de9289c8 | 219 | hapd->iface->num_sta_no_ht--; |
e8ff1e59 JM |
220 | } |
221 | ||
222 | if (sta->ht_20mhz_set) { | |
223 | sta->ht_20mhz_set = 0; | |
224 | hapd->iface->num_sta_ht_20mhz--; | |
225 | } | |
de9289c8 | 226 | |
04059ab8 DG |
227 | #ifdef CONFIG_TAXONOMY |
228 | wpabuf_free(sta->probe_ie_taxonomy); | |
229 | sta->probe_ie_taxonomy = NULL; | |
230 | wpabuf_free(sta->assoc_ie_taxonomy); | |
231 | sta->assoc_ie_taxonomy = NULL; | |
232 | #endif /* CONFIG_TAXONOMY */ | |
233 | ||
9c47f6a2 PX |
234 | #ifdef CONFIG_IEEE80211N |
235 | ht40_intolerant_remove(hapd->iface, sta); | |
236 | #endif /* CONFIG_IEEE80211N */ | |
237 | ||
aefb53bd JM |
238 | #ifdef CONFIG_P2P |
239 | if (sta->no_p2p_set) { | |
240 | sta->no_p2p_set = 0; | |
241 | hapd->num_sta_no_p2p--; | |
242 | if (hapd->num_sta_no_p2p == 0) | |
243 | hostapd_p2p_non_p2p_sta_disconnected(hapd); | |
244 | } | |
245 | #endif /* CONFIG_P2P */ | |
246 | ||
d45354be | 247 | #if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N) |
de9289c8 JM |
248 | if (hostapd_ht_operation_update(hapd->iface) > 0) |
249 | set_beacon++; | |
d45354be | 250 | #endif /* NEED_AP_MLME && CONFIG_IEEE80211N */ |
de9289c8 | 251 | |
c596f3f0 CYY |
252 | #ifdef CONFIG_MESH |
253 | if (hapd->mesh_sta_free_cb) | |
9684c756 | 254 | hapd->mesh_sta_free_cb(hapd, sta); |
c596f3f0 CYY |
255 | #endif /* CONFIG_MESH */ |
256 | ||
6fc6879b JM |
257 | if (set_beacon) |
258 | ieee802_11_set_beacons(hapd->iface); | |
259 | ||
42ca9845 JM |
260 | wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR, |
261 | __func__, MAC2STR(sta->addr)); | |
6fc6879b JM |
262 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
263 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); | |
97596f8e | 264 | eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta); |
9e8fde21 | 265 | ap_sta_clear_disconnect_timeouts(hapd, sta); |
f3b8ad4d | 266 | sae_clear_retransmit_timer(hapd, sta); |
6fc6879b | 267 | |
d7c3347f | 268 | ieee802_1x_free_station(hapd, sta); |
6fc6879b JM |
269 | wpa_auth_sta_deinit(sta->wpa_sm); |
270 | rsn_preauth_free_station(hapd, sta); | |
74784010 | 271 | #ifndef CONFIG_NO_RADIUS |
ded22b53 HS |
272 | if (hapd->radius) |
273 | radius_client_flush_auth(hapd->radius, sta->addr); | |
74784010 | 274 | #endif /* CONFIG_NO_RADIUS */ |
6fc6879b | 275 | |
7cebc8e2 MB |
276 | #ifndef CONFIG_NO_VLAN |
277 | /* | |
278 | * sta->wpa_sm->group needs to be released before so that | |
279 | * vlan_remove_dynamic() can check that no stations are left on the | |
280 | * AP_VLAN netdev. | |
281 | */ | |
1889af2e MB |
282 | if (sta->vlan_id) |
283 | vlan_remove_dynamic(hapd, sta->vlan_id); | |
7cebc8e2 MB |
284 | if (sta->vlan_id_bound) { |
285 | /* | |
286 | * Need to remove the STA entry before potentially removing the | |
287 | * VLAN. | |
288 | */ | |
289 | if (hapd->iface->driver_ap_teardown && | |
bb598c3b | 290 | !(sta->flags & WLAN_STA_PREAUTH)) { |
7cebc8e2 | 291 | hostapd_drv_sta_remove(hapd, sta->addr); |
bb598c3b AB |
292 | sta->added_unassoc = 0; |
293 | } | |
7cebc8e2 MB |
294 | vlan_remove_dynamic(hapd, sta->vlan_id_bound); |
295 | } | |
296 | #endif /* CONFIG_NO_VLAN */ | |
297 | ||
6fc6879b | 298 | os_free(sta->challenge); |
5d22a1d5 JM |
299 | |
300 | #ifdef CONFIG_IEEE80211W | |
93b76319 JM |
301 | os_free(sta->sa_query_trans_id); |
302 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); | |
5d22a1d5 JM |
303 | #endif /* CONFIG_IEEE80211W */ |
304 | ||
8ccbe415 JM |
305 | #ifdef CONFIG_P2P |
306 | p2p_group_notif_disassoc(hapd->p2p_group, sta->addr); | |
307 | #endif /* CONFIG_P2P */ | |
308 | ||
dca30c3f JK |
309 | #ifdef CONFIG_INTERWORKING |
310 | if (sta->gas_dialog) { | |
311 | int i; | |
312 | for (i = 0; i < GAS_DIALOG_MAX; i++) | |
313 | gas_serv_dialog_clear(&sta->gas_dialog[i]); | |
314 | os_free(sta->gas_dialog); | |
315 | } | |
316 | #endif /* CONFIG_INTERWORKING */ | |
317 | ||
eb76b7e3 | 318 | wpabuf_free(sta->wps_ie); |
b305c684 | 319 | wpabuf_free(sta->p2p_ie); |
f403dcd6 | 320 | wpabuf_free(sta->hs20_ie); |
ae667c08 AN |
321 | #ifdef CONFIG_FST |
322 | wpabuf_free(sta->mb_ies); | |
323 | #endif /* CONFIG_FST */ | |
eb76b7e3 | 324 | |
df84268a | 325 | os_free(sta->ht_capabilities); |
cc14091e | 326 | os_free(sta->vht_capabilities); |
f2a14be7 | 327 | hostapd_free_psk_list(sta->psk); |
2092597f MB |
328 | os_free(sta->identity); |
329 | os_free(sta->radius_cui); | |
6ca0853d | 330 | os_free(sta->remediation_url); |
8e1146d9 | 331 | wpabuf_free(sta->hs20_deauth_req); |
97596f8e | 332 | os_free(sta->hs20_session_info_url); |
df84268a | 333 | |
98efcc41 | 334 | #ifdef CONFIG_SAE |
a46d72d7 | 335 | sae_clear_data(sta->sae); |
98efcc41 JM |
336 | os_free(sta->sae); |
337 | #endif /* CONFIG_SAE */ | |
338 | ||
ca911d61 | 339 | mbo_ap_sta_free(sta); |
adf0478e | 340 | os_free(sta->supp_op_classes); |
ca911d61 | 341 | |
6fc6879b JM |
342 | os_free(sta); |
343 | } | |
344 | ||
345 | ||
346 | void hostapd_free_stas(struct hostapd_data *hapd) | |
347 | { | |
348 | struct sta_info *sta, *prev; | |
349 | ||
350 | sta = hapd->sta_list; | |
351 | ||
352 | while (sta) { | |
353 | prev = sta; | |
354 | if (sta->flags & WLAN_STA_AUTH) { | |
355 | mlme_deauthenticate_indication( | |
356 | hapd, sta, WLAN_REASON_UNSPECIFIED); | |
357 | } | |
358 | sta = sta->next; | |
359 | wpa_printf(MSG_DEBUG, "Removing station " MACSTR, | |
360 | MAC2STR(prev->addr)); | |
361 | ap_free_sta(hapd, prev); | |
362 | } | |
363 | } | |
364 | ||
365 | ||
1c6e69cc JM |
366 | /** |
367 | * ap_handle_timer - Per STA timer handler | |
368 | * @eloop_ctx: struct hostapd_data * | |
369 | * @timeout_ctx: struct sta_info * | |
370 | * | |
371 | * This function is called to check station activity and to remove inactive | |
372 | * stations. | |
373 | */ | |
6fc6879b JM |
374 | void ap_handle_timer(void *eloop_ctx, void *timeout_ctx) |
375 | { | |
376 | struct hostapd_data *hapd = eloop_ctx; | |
377 | struct sta_info *sta = timeout_ctx; | |
378 | unsigned long next_time = 0; | |
d5b559b6 | 379 | int reason; |
6fc6879b | 380 | |
03269d55 JM |
381 | wpa_printf(MSG_DEBUG, "%s: %s: " MACSTR " flags=0x%x timeout_next=%d", |
382 | hapd->conf->iface, __func__, MAC2STR(sta->addr), sta->flags, | |
42ca9845 | 383 | sta->timeout_next); |
6fc6879b JM |
384 | if (sta->timeout_next == STA_REMOVE) { |
385 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
386 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " | |
387 | "local deauth request"); | |
388 | ap_free_sta(hapd, sta); | |
389 | return; | |
390 | } | |
391 | ||
392 | if ((sta->flags & WLAN_STA_ASSOC) && | |
393 | (sta->timeout_next == STA_NULLFUNC || | |
394 | sta->timeout_next == STA_DISASSOC)) { | |
395 | int inactive_sec; | |
ce28e279 BG |
396 | /* |
397 | * Add random value to timeout so that we don't end up bouncing | |
398 | * all stations at the same time if we have lots of associated | |
399 | * stations that are idle (but keep re-associating). | |
400 | */ | |
401 | int fuzz = os_random() % 20; | |
51e2a27a | 402 | inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr); |
6fc6879b | 403 | if (inactive_sec == -1) { |
3ec1e902 JM |
404 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
405 | "Check inactivity: Could not " | |
d5674791 | 406 | "get station info from kernel driver for " |
24d75245 | 407 | MACSTR, MAC2STR(sta->addr)); |
d5674791 JM |
408 | /* |
409 | * The driver may not support this functionality. | |
410 | * Anyway, try again after the next inactivity timeout, | |
411 | * but do not disconnect the station now. | |
412 | */ | |
ce28e279 | 413 | next_time = hapd->conf->ap_max_inactivity + fuzz; |
b9749bac MH |
414 | } else if (inactive_sec == -ENOENT) { |
415 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, | |
416 | "Station " MACSTR " has lost its driver entry", | |
417 | MAC2STR(sta->addr)); | |
418 | ||
47e5fbde PO |
419 | /* Avoid sending client probe on removed client */ |
420 | sta->timeout_next = STA_DISASSOC; | |
421 | goto skip_poll; | |
a114c723 | 422 | } else if (inactive_sec < hapd->conf->ap_max_inactivity) { |
6fc6879b | 423 | /* station activity detected; reset timeout state */ |
3ec1e902 JM |
424 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
425 | "Station " MACSTR " has been active %is ago", | |
24d75245 | 426 | MAC2STR(sta->addr), inactive_sec); |
6fc6879b | 427 | sta->timeout_next = STA_NULLFUNC; |
ce28e279 | 428 | next_time = hapd->conf->ap_max_inactivity + fuzz - |
6fc6879b | 429 | inactive_sec; |
24d75245 | 430 | } else { |
3ec1e902 JM |
431 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
432 | "Station " MACSTR " has been " | |
24d75245 BG |
433 | "inactive too long: %d sec, max allowed: %d", |
434 | MAC2STR(sta->addr), inactive_sec, | |
435 | hapd->conf->ap_max_inactivity); | |
ef01fa7b YAP |
436 | |
437 | if (hapd->conf->skip_inactivity_poll) | |
438 | sta->timeout_next = STA_DISASSOC; | |
6fc6879b JM |
439 | } |
440 | } | |
441 | ||
442 | if ((sta->flags & WLAN_STA_ASSOC) && | |
443 | sta->timeout_next == STA_DISASSOC && | |
ef01fa7b YAP |
444 | !(sta->flags & WLAN_STA_PENDING_POLL) && |
445 | !hapd->conf->skip_inactivity_poll) { | |
3ec1e902 JM |
446 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR |
447 | " has ACKed data poll", MAC2STR(sta->addr)); | |
6fc6879b JM |
448 | /* data nullfunc frame poll did not produce TX errors; assume |
449 | * station ACKed it */ | |
450 | sta->timeout_next = STA_NULLFUNC; | |
451 | next_time = hapd->conf->ap_max_inactivity; | |
452 | } | |
453 | ||
47e5fbde | 454 | skip_poll: |
6fc6879b | 455 | if (next_time) { |
42ca9845 JM |
456 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
457 | "for " MACSTR " (%lu seconds)", | |
458 | __func__, MAC2STR(sta->addr), next_time); | |
6fc6879b JM |
459 | eloop_register_timeout(next_time, 0, ap_handle_timer, hapd, |
460 | sta); | |
461 | return; | |
462 | } | |
463 | ||
464 | if (sta->timeout_next == STA_NULLFUNC && | |
465 | (sta->flags & WLAN_STA_ASSOC)) { | |
bcf24348 | 466 | wpa_printf(MSG_DEBUG, " Polling STA"); |
6fc6879b | 467 | sta->flags |= WLAN_STA_PENDING_POLL; |
bcf24348 JB |
468 | hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr, |
469 | sta->flags & WLAN_STA_WMM); | |
6fc6879b JM |
470 | } else if (sta->timeout_next != STA_REMOVE) { |
471 | int deauth = sta->timeout_next == STA_DEAUTH; | |
472 | ||
afcc9ea1 BG |
473 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, |
474 | "Timeout, sending %s info to STA " MACSTR, | |
475 | deauth ? "deauthentication" : "disassociation", | |
476 | MAC2STR(sta->addr)); | |
6fc6879b JM |
477 | |
478 | if (deauth) { | |
51e2a27a JM |
479 | hostapd_drv_sta_deauth( |
480 | hapd, sta->addr, | |
481 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
6fc6879b | 482 | } else { |
d5b559b6 KP |
483 | reason = (sta->timeout_next == STA_DISASSOC) ? |
484 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY : | |
485 | WLAN_REASON_PREV_AUTH_NOT_VALID; | |
486 | ||
487 | hostapd_drv_sta_disassoc(hapd, sta->addr, reason); | |
6fc6879b JM |
488 | } |
489 | } | |
490 | ||
491 | switch (sta->timeout_next) { | |
492 | case STA_NULLFUNC: | |
493 | sta->timeout_next = STA_DISASSOC; | |
42ca9845 JM |
494 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
495 | "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)", | |
496 | __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY); | |
6fc6879b JM |
497 | eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer, |
498 | hapd, sta); | |
499 | break; | |
500 | case STA_DISASSOC: | |
d5b559b6 | 501 | case STA_DISASSOC_FROM_CLI: |
ae055af4 | 502 | ap_sta_set_authorized(hapd, sta, 0); |
6fc6879b JM |
503 | sta->flags &= ~WLAN_STA_ASSOC; |
504 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
505 | if (!sta->acct_terminate_cause) | |
506 | sta->acct_terminate_cause = | |
507 | RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT; | |
508 | accounting_sta_stop(hapd, sta); | |
d7c3347f | 509 | ieee802_1x_free_station(hapd, sta); |
6fc6879b JM |
510 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
511 | HOSTAPD_LEVEL_INFO, "disassociated due to " | |
512 | "inactivity"); | |
d5b559b6 KP |
513 | reason = (sta->timeout_next == STA_DISASSOC) ? |
514 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY : | |
515 | WLAN_REASON_PREV_AUTH_NOT_VALID; | |
6fc6879b | 516 | sta->timeout_next = STA_DEAUTH; |
42ca9845 JM |
517 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
518 | "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)", | |
519 | __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY); | |
6fc6879b JM |
520 | eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer, |
521 | hapd, sta); | |
d5b559b6 | 522 | mlme_disassociate_indication(hapd, sta, reason); |
6fc6879b JM |
523 | break; |
524 | case STA_DEAUTH: | |
525 | case STA_REMOVE: | |
526 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
527 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " | |
afcc9ea1 | 528 | "inactivity (timer DEAUTH/REMOVE)"); |
6fc6879b JM |
529 | if (!sta->acct_terminate_cause) |
530 | sta->acct_terminate_cause = | |
531 | RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT; | |
532 | mlme_deauthenticate_indication( | |
533 | hapd, sta, | |
534 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
535 | ap_free_sta(hapd, sta); | |
536 | break; | |
537 | } | |
538 | } | |
539 | ||
540 | ||
541 | static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx) | |
542 | { | |
543 | struct hostapd_data *hapd = eloop_ctx; | |
544 | struct sta_info *sta = timeout_ctx; | |
6fc6879b | 545 | |
03269d55 JM |
546 | wpa_printf(MSG_DEBUG, "%s: Session timer for STA " MACSTR, |
547 | hapd->conf->iface, MAC2STR(sta->addr)); | |
dca30c3f JK |
548 | if (!(sta->flags & WLAN_STA_AUTH)) { |
549 | if (sta->flags & WLAN_STA_GAS) { | |
550 | wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA " | |
551 | "entry " MACSTR, MAC2STR(sta->addr)); | |
552 | ap_free_sta(hapd, sta); | |
553 | } | |
6fc6879b | 554 | return; |
dca30c3f | 555 | } |
6fc6879b | 556 | |
0ac38766 JM |
557 | hostapd_drv_sta_deauth(hapd, sta->addr, |
558 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
6fc6879b JM |
559 | mlme_deauthenticate_indication(hapd, sta, |
560 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
561 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
562 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " | |
563 | "session timeout"); | |
564 | sta->acct_terminate_cause = | |
565 | RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT; | |
6fc6879b | 566 | ap_free_sta(hapd, sta); |
6fc6879b JM |
567 | } |
568 | ||
569 | ||
91f9e607 KP |
570 | void ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta, |
571 | u32 session_timeout) | |
572 | { | |
573 | if (eloop_replenish_timeout(session_timeout, 0, | |
a09ffd5f | 574 | ap_handle_session_timer, hapd, sta) == 1) { |
91f9e607 KP |
575 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
576 | HOSTAPD_LEVEL_DEBUG, "setting session timeout " | |
577 | "to %d seconds", session_timeout); | |
578 | } | |
579 | } | |
580 | ||
581 | ||
6fc6879b JM |
582 | void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta, |
583 | u32 session_timeout) | |
584 | { | |
585 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
586 | HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d " | |
587 | "seconds", session_timeout); | |
588 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); | |
589 | eloop_register_timeout(session_timeout, 0, ap_handle_session_timer, | |
590 | hapd, sta); | |
591 | } | |
592 | ||
593 | ||
594 | void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta) | |
595 | { | |
596 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); | |
597 | } | |
598 | ||
599 | ||
97596f8e JM |
600 | static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx) |
601 | { | |
602 | #ifdef CONFIG_WNM | |
603 | struct hostapd_data *hapd = eloop_ctx; | |
604 | struct sta_info *sta = timeout_ctx; | |
605 | ||
03269d55 JM |
606 | wpa_printf(MSG_DEBUG, "%s: WNM: Session warning time reached for " |
607 | MACSTR, hapd->conf->iface, MAC2STR(sta->addr)); | |
97596f8e JM |
608 | if (sta->hs20_session_info_url == NULL) |
609 | return; | |
610 | ||
611 | wnm_send_ess_disassoc_imminent(hapd, sta, sta->hs20_session_info_url, | |
612 | sta->hs20_disassoc_timer); | |
613 | #endif /* CONFIG_WNM */ | |
614 | } | |
615 | ||
616 | ||
617 | void ap_sta_session_warning_timeout(struct hostapd_data *hapd, | |
618 | struct sta_info *sta, int warning_time) | |
619 | { | |
620 | eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta); | |
621 | eloop_register_timeout(warning_time, 0, ap_handle_session_warning_timer, | |
622 | hapd, sta); | |
623 | } | |
624 | ||
625 | ||
6fc6879b JM |
626 | struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr) |
627 | { | |
628 | struct sta_info *sta; | |
629 | ||
630 | sta = ap_get_sta(hapd, addr); | |
631 | if (sta) | |
632 | return sta; | |
633 | ||
634 | wpa_printf(MSG_DEBUG, " New STA"); | |
635 | if (hapd->num_sta >= hapd->conf->max_num_sta) { | |
636 | /* FIX: might try to remove some old STAs first? */ | |
637 | wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)", | |
638 | hapd->num_sta, hapd->conf->max_num_sta); | |
639 | return NULL; | |
640 | } | |
641 | ||
642 | sta = os_zalloc(sizeof(struct sta_info)); | |
643 | if (sta == NULL) { | |
644 | wpa_printf(MSG_ERROR, "malloc failed"); | |
645 | return NULL; | |
646 | } | |
5843e1c9 | 647 | sta->acct_interim_interval = hapd->conf->acct_interim_interval; |
d72a0053 NL |
648 | if (accounting_sta_get_id(hapd, sta) < 0) { |
649 | os_free(sta); | |
650 | return NULL; | |
651 | } | |
6fc6879b | 652 | |
336167c8 MSS |
653 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) { |
654 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " | |
655 | "for " MACSTR " (%d seconds - ap_max_inactivity)", | |
656 | __func__, MAC2STR(addr), | |
657 | hapd->conf->ap_max_inactivity); | |
658 | eloop_register_timeout(hapd->conf->ap_max_inactivity, 0, | |
659 | ap_handle_timer, hapd, sta); | |
660 | } | |
661 | ||
6fc6879b | 662 | /* initialize STA info data */ |
6fc6879b JM |
663 | os_memcpy(sta->addr, addr, ETH_ALEN); |
664 | sta->next = hapd->sta_list; | |
665 | hapd->sta_list = sta; | |
666 | hapd->num_sta++; | |
667 | ap_sta_hash_add(hapd, sta); | |
53f3d6f3 | 668 | ap_sta_remove_in_other_bss(hapd, sta); |
38cb0a2d | 669 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
bd00c431 | 670 | dl_list_init(&sta->ip6addr); |
6fc6879b | 671 | |
44281940 DG |
672 | #ifdef CONFIG_TAXONOMY |
673 | sta_track_claim_taxonomy_info(hapd->iface, addr, | |
674 | &sta->probe_ie_taxonomy); | |
675 | #endif /* CONFIG_TAXONOMY */ | |
676 | ||
6fc6879b JM |
677 | return sta; |
678 | } | |
679 | ||
680 | ||
681 | static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta) | |
682 | { | |
683 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
684 | ||
7d597d46 | 685 | if (sta->ipaddr) |
ed4ddb6d | 686 | hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr); |
bd00c431 | 687 | ap_sta_ip6addr_del(hapd, sta); |
7d597d46 | 688 | |
03269d55 JM |
689 | wpa_printf(MSG_DEBUG, "%s: Removing STA " MACSTR " from kernel driver", |
690 | hapd->conf->iface, MAC2STR(sta->addr)); | |
51e2a27a | 691 | if (hostapd_drv_sta_remove(hapd, sta->addr) && |
6fc6879b | 692 | sta->flags & WLAN_STA_ASSOC) { |
03269d55 JM |
693 | wpa_printf(MSG_DEBUG, "%s: Could not remove station " MACSTR |
694 | " from kernel driver", | |
695 | hapd->conf->iface, MAC2STR(sta->addr)); | |
6fc6879b JM |
696 | return -1; |
697 | } | |
bb598c3b | 698 | sta->added_unassoc = 0; |
6fc6879b JM |
699 | return 0; |
700 | } | |
701 | ||
702 | ||
53f3d6f3 FF |
703 | static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd, |
704 | struct sta_info *sta) | |
6fc6879b JM |
705 | { |
706 | struct hostapd_iface *iface = hapd->iface; | |
707 | size_t i; | |
708 | ||
709 | for (i = 0; i < iface->num_bss; i++) { | |
710 | struct hostapd_data *bss = iface->bss[i]; | |
711 | struct sta_info *sta2; | |
712 | /* bss should always be set during operation, but it may be | |
713 | * NULL during reconfiguration. Assume the STA is not | |
714 | * associated to another BSS in that case to avoid NULL pointer | |
715 | * dereferences. */ | |
716 | if (bss == hapd || bss == NULL) | |
717 | continue; | |
718 | sta2 = ap_get_sta(bss, sta->addr); | |
53f3d6f3 FF |
719 | if (!sta2) |
720 | continue; | |
6fc6879b | 721 | |
03269d55 JM |
722 | wpa_printf(MSG_DEBUG, "%s: disconnect old STA " MACSTR |
723 | " association from another BSS %s", | |
724 | hapd->conf->iface, MAC2STR(sta2->addr), | |
725 | bss->conf->iface); | |
53f3d6f3 FF |
726 | ap_sta_disconnect(bss, sta2, sta2->addr, |
727 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
728 | } | |
6fc6879b JM |
729 | } |
730 | ||
731 | ||
4dc03726 JM |
732 | static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx) |
733 | { | |
734 | struct hostapd_data *hapd = eloop_ctx; | |
735 | struct sta_info *sta = timeout_ctx; | |
736 | ||
03269d55 JM |
737 | wpa_printf(MSG_DEBUG, "%s: Disassociation callback for STA " MACSTR, |
738 | hapd->conf->iface, MAC2STR(sta->addr)); | |
4dc03726 JM |
739 | ap_sta_remove(hapd, sta); |
740 | mlme_disassociate_indication(hapd, sta, sta->disassoc_reason); | |
741 | } | |
742 | ||
743 | ||
6fc6879b JM |
744 | void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta, |
745 | u16 reason) | |
746 | { | |
747 | wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR, | |
748 | hapd->conf->iface, MAC2STR(sta->addr)); | |
38cb0a2d | 749 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
ba873c12 | 750 | sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); |
4dc03726 | 751 | ap_sta_set_authorized(hapd, sta, 0); |
6fc6879b | 752 | sta->timeout_next = STA_DEAUTH; |
42ca9845 JM |
753 | wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " |
754 | "for " MACSTR " (%d seconds - " | |
755 | "AP_MAX_INACTIVITY_AFTER_DISASSOC)", | |
756 | __func__, MAC2STR(sta->addr), | |
757 | AP_MAX_INACTIVITY_AFTER_DISASSOC); | |
6fc6879b JM |
758 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
759 | eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0, | |
760 | ap_handle_timer, hapd, sta); | |
761 | accounting_sta_stop(hapd, sta); | |
d7c3347f | 762 | ieee802_1x_free_station(hapd, sta); |
6fc6879b | 763 | |
4dc03726 | 764 | sta->disassoc_reason = reason; |
cc28ad8c | 765 | sta->flags |= WLAN_STA_PENDING_DISASSOC_CB; |
4dc03726 JM |
766 | eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta); |
767 | eloop_register_timeout(hapd->iface->drv_flags & | |
768 | WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0, | |
769 | ap_sta_disassoc_cb_timeout, hapd, sta); | |
770 | } | |
771 | ||
772 | ||
773 | static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx) | |
774 | { | |
775 | struct hostapd_data *hapd = eloop_ctx; | |
776 | struct sta_info *sta = timeout_ctx; | |
777 | ||
03269d55 JM |
778 | wpa_printf(MSG_DEBUG, "%s: Deauthentication callback for STA " MACSTR, |
779 | hapd->conf->iface, MAC2STR(sta->addr)); | |
4dc03726 JM |
780 | ap_sta_remove(hapd, sta); |
781 | mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason); | |
6fc6879b JM |
782 | } |
783 | ||
784 | ||
785 | void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta, | |
786 | u16 reason) | |
787 | { | |
788 | wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR, | |
789 | hapd->conf->iface, MAC2STR(sta->addr)); | |
38cb0a2d | 790 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
631739b3 | 791 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); |
4dc03726 | 792 | ap_sta_set_authorized(hapd, sta, 0); |
6fc6879b | 793 | sta->timeout_next = STA_REMOVE; |
42ca9845 JM |
794 | wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " |
795 | "for " MACSTR " (%d seconds - " | |
796 | "AP_MAX_INACTIVITY_AFTER_DEAUTH)", | |
797 | __func__, MAC2STR(sta->addr), | |
798 | AP_MAX_INACTIVITY_AFTER_DEAUTH); | |
6fc6879b JM |
799 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
800 | eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0, | |
801 | ap_handle_timer, hapd, sta); | |
802 | accounting_sta_stop(hapd, sta); | |
d7c3347f | 803 | ieee802_1x_free_station(hapd, sta); |
6fc6879b | 804 | |
4dc03726 | 805 | sta->deauth_reason = reason; |
cc28ad8c | 806 | sta->flags |= WLAN_STA_PENDING_DEAUTH_CB; |
4dc03726 JM |
807 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
808 | eloop_register_timeout(hapd->iface->drv_flags & | |
809 | WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0, | |
810 | ap_sta_deauth_cb_timeout, hapd, sta); | |
6fc6879b JM |
811 | } |
812 | ||
813 | ||
4c374cde AS |
814 | #ifdef CONFIG_WPS |
815 | int ap_sta_wps_cancel(struct hostapd_data *hapd, | |
816 | struct sta_info *sta, void *ctx) | |
817 | { | |
818 | if (sta && (sta->flags & WLAN_STA_WPS)) { | |
819 | ap_sta_deauthenticate(hapd, sta, | |
820 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
821 | wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR, | |
822 | __func__, MAC2STR(sta->addr)); | |
823 | return 1; | |
824 | } | |
825 | ||
826 | return 0; | |
827 | } | |
828 | #endif /* CONFIG_WPS */ | |
829 | ||
830 | ||
8e44c192 MB |
831 | static int ap_sta_get_free_vlan_id(struct hostapd_data *hapd) |
832 | { | |
833 | struct hostapd_vlan *vlan; | |
834 | int vlan_id = MAX_VLAN_ID + 2; | |
835 | ||
836 | retry: | |
837 | for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) { | |
838 | if (vlan->vlan_id == vlan_id) { | |
839 | vlan_id++; | |
840 | goto retry; | |
841 | } | |
842 | } | |
843 | return vlan_id; | |
844 | } | |
845 | ||
846 | ||
1889af2e MB |
847 | int ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta, |
848 | struct vlan_description *vlan_desc) | |
849 | { | |
850 | struct hostapd_vlan *vlan = NULL, *wildcard_vlan = NULL; | |
851 | int old_vlan_id, vlan_id = 0, ret = 0; | |
852 | ||
8e44c192 | 853 | if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED) |
1889af2e | 854 | vlan_desc = NULL; |
1889af2e | 855 | |
8e44c192 | 856 | /* Check if there is something to do */ |
8be640b7 MB |
857 | if (hapd->conf->ssid.per_sta_vif && !sta->vlan_id) { |
858 | /* This sta is lacking its own vif */ | |
859 | } else if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED && | |
860 | !hapd->conf->ssid.per_sta_vif && sta->vlan_id) { | |
861 | /* sta->vlan_id needs to be reset */ | |
862 | } else if (!vlan_compare(vlan_desc, sta->vlan_desc)) { | |
8e44c192 | 863 | return 0; /* nothing to change */ |
8be640b7 | 864 | } |
8e44c192 MB |
865 | |
866 | /* Now the real VLAN changed or the STA just needs its own vif */ | |
8be640b7 MB |
867 | if (hapd->conf->ssid.per_sta_vif) { |
868 | /* Assign a new vif, always */ | |
869 | /* find a free vlan_id sufficiently big */ | |
870 | vlan_id = ap_sta_get_free_vlan_id(hapd); | |
871 | /* Get wildcard VLAN */ | |
872 | for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) { | |
873 | if (vlan->vlan_id == VLAN_ID_WILDCARD) | |
874 | break; | |
875 | } | |
876 | if (!vlan) { | |
877 | hostapd_logger(hapd, sta->addr, | |
878 | HOSTAPD_MODULE_IEEE80211, | |
879 | HOSTAPD_LEVEL_DEBUG, | |
880 | "per_sta_vif missing wildcard"); | |
881 | vlan_id = 0; | |
882 | ret = -1; | |
883 | goto done; | |
884 | } | |
885 | } else if (vlan_desc && vlan_desc->notempty) { | |
1889af2e MB |
886 | for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) { |
887 | if (!vlan_compare(&vlan->vlan_desc, vlan_desc)) | |
888 | break; | |
889 | if (vlan->vlan_id == VLAN_ID_WILDCARD) | |
890 | wildcard_vlan = vlan; | |
891 | } | |
892 | if (vlan) { | |
893 | vlan_id = vlan->vlan_id; | |
894 | } else if (wildcard_vlan) { | |
895 | vlan = wildcard_vlan; | |
896 | vlan_id = vlan_desc->untagged; | |
8e44c192 MB |
897 | if (vlan_desc->tagged[0]) { |
898 | /* Tagged VLAN configuration */ | |
899 | vlan_id = ap_sta_get_free_vlan_id(hapd); | |
900 | } | |
1889af2e MB |
901 | } else { |
902 | hostapd_logger(hapd, sta->addr, | |
903 | HOSTAPD_MODULE_IEEE80211, | |
904 | HOSTAPD_LEVEL_DEBUG, | |
8e44c192 MB |
905 | "missing vlan and wildcard for vlan=%d%s", |
906 | vlan_desc->untagged, | |
907 | vlan_desc->tagged[0] ? "+" : ""); | |
1889af2e MB |
908 | vlan_id = 0; |
909 | ret = -1; | |
910 | goto done; | |
911 | } | |
912 | } | |
913 | ||
914 | if (vlan && vlan->vlan_id == VLAN_ID_WILDCARD) { | |
915 | vlan = vlan_add_dynamic(hapd, vlan, vlan_id, vlan_desc); | |
916 | if (vlan == NULL) { | |
917 | hostapd_logger(hapd, sta->addr, | |
918 | HOSTAPD_MODULE_IEEE80211, | |
919 | HOSTAPD_LEVEL_DEBUG, | |
8e44c192 | 920 | "could not add dynamic VLAN interface for vlan=%d%s", |
75cc211d JM |
921 | vlan_desc ? vlan_desc->untagged : -1, |
922 | (vlan_desc && vlan_desc->tagged[0]) ? | |
923 | "+" : ""); | |
1889af2e MB |
924 | vlan_id = 0; |
925 | ret = -1; | |
926 | goto done; | |
927 | } | |
928 | ||
929 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
930 | HOSTAPD_LEVEL_DEBUG, | |
931 | "added new dynamic VLAN interface '%s'", | |
932 | vlan->ifname); | |
933 | } else if (vlan && vlan->dynamic_vlan > 0) { | |
934 | vlan->dynamic_vlan++; | |
935 | hostapd_logger(hapd, sta->addr, | |
936 | HOSTAPD_MODULE_IEEE80211, | |
937 | HOSTAPD_LEVEL_DEBUG, | |
938 | "updated existing dynamic VLAN interface '%s'", | |
939 | vlan->ifname); | |
940 | } | |
941 | done: | |
942 | old_vlan_id = sta->vlan_id; | |
943 | sta->vlan_id = vlan_id; | |
944 | sta->vlan_desc = vlan ? &vlan->vlan_desc : NULL; | |
945 | ||
946 | if (vlan_id != old_vlan_id && old_vlan_id) | |
947 | vlan_remove_dynamic(hapd, old_vlan_id); | |
948 | ||
949 | return ret; | |
950 | } | |
951 | ||
952 | ||
c8e6beab | 953 | int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta) |
6fc6879b | 954 | { |
30b32314 | 955 | #ifndef CONFIG_NO_VLAN |
6fc6879b JM |
956 | const char *iface; |
957 | struct hostapd_vlan *vlan = NULL; | |
4254100d | 958 | int ret; |
c8e6beab | 959 | int old_vlanid = sta->vlan_id_bound; |
6fc6879b | 960 | |
6fc6879b | 961 | iface = hapd->conf->iface; |
f41ded6f JM |
962 | if (hapd->conf->ssid.vlan[0]) |
963 | iface = hapd->conf->ssid.vlan; | |
6fc6879b | 964 | |
1889af2e MB |
965 | if (sta->vlan_id > 0) { |
966 | for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) { | |
c2db79f2 | 967 | if (vlan->vlan_id == sta->vlan_id) |
6fc6879b | 968 | break; |
6fc6879b | 969 | } |
c2db79f2 MB |
970 | if (vlan) |
971 | iface = vlan->ifname; | |
6fc6879b JM |
972 | } |
973 | ||
c8e6beab MB |
974 | /* |
975 | * Do not increment ref counters if the VLAN ID remains same, but do | |
976 | * not skip hostapd_drv_set_sta_vlan() as hostapd_drv_sta_remove() might | |
977 | * have been called before. | |
978 | */ | |
979 | if (sta->vlan_id == old_vlanid) | |
980 | goto skip_counting; | |
981 | ||
6fc6879b JM |
982 | if (sta->vlan_id > 0 && vlan == NULL) { |
983 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
984 | HOSTAPD_LEVEL_DEBUG, "could not find VLAN for " | |
985 | "binding station to (vlan_id=%d)", | |
986 | sta->vlan_id); | |
2dd4f3ae JM |
987 | ret = -1; |
988 | goto done; | |
1889af2e | 989 | } else if (vlan && vlan->dynamic_vlan > 0) { |
41d62107 MB |
990 | vlan->dynamic_vlan++; |
991 | hostapd_logger(hapd, sta->addr, | |
992 | HOSTAPD_MODULE_IEEE80211, | |
993 | HOSTAPD_LEVEL_DEBUG, | |
994 | "updated existing dynamic VLAN interface '%s'", | |
995 | iface); | |
6fc6879b JM |
996 | } |
997 | ||
c8e6beab MB |
998 | /* ref counters have been increased, so mark the station */ |
999 | sta->vlan_id_bound = sta->vlan_id; | |
1000 | ||
1001 | skip_counting: | |
6fc6879b JM |
1002 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
1003 | HOSTAPD_LEVEL_DEBUG, "binding station to interface " | |
1004 | "'%s'", iface); | |
1005 | ||
1006 | if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0) | |
1007 | wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA"); | |
1008 | ||
51e2a27a | 1009 | ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id); |
4254100d JM |
1010 | if (ret < 0) { |
1011 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
1012 | HOSTAPD_LEVEL_DEBUG, "could not bind the STA " | |
1013 | "entry to vlan_id=%d", sta->vlan_id); | |
1014 | } | |
2dd4f3ae | 1015 | |
2dd4f3ae | 1016 | /* During 1x reauth, if the vlan id changes, then remove the old id. */ |
c8e6beab | 1017 | if (old_vlanid > 0 && old_vlanid != sta->vlan_id) |
2dd4f3ae | 1018 | vlan_remove_dynamic(hapd, old_vlanid); |
c8e6beab | 1019 | done: |
2dd4f3ae | 1020 | |
4254100d | 1021 | return ret; |
30b32314 JM |
1022 | #else /* CONFIG_NO_VLAN */ |
1023 | return 0; | |
1024 | #endif /* CONFIG_NO_VLAN */ | |
6fc6879b | 1025 | } |
5d22a1d5 JM |
1026 | |
1027 | ||
1028 | #ifdef CONFIG_IEEE80211W | |
1029 | ||
45c94154 | 1030 | int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta) |
5d22a1d5 | 1031 | { |
45c94154 | 1032 | u32 tu; |
10e694a6 JB |
1033 | struct os_reltime now, passed; |
1034 | os_get_reltime(&now); | |
1035 | os_reltime_sub(&now, &sta->sa_query_start, &passed); | |
45c94154 JM |
1036 | tu = (passed.sec * 1000000 + passed.usec) / 1024; |
1037 | if (hapd->conf->assoc_sa_query_max_timeout < tu) { | |
1038 | hostapd_logger(hapd, sta->addr, | |
1039 | HOSTAPD_MODULE_IEEE80211, | |
5d22a1d5 | 1040 | HOSTAPD_LEVEL_DEBUG, |
93b76319 JM |
1041 | "association SA Query timed out"); |
1042 | sta->sa_query_timed_out = 1; | |
1043 | os_free(sta->sa_query_trans_id); | |
1044 | sta->sa_query_trans_id = NULL; | |
1045 | sta->sa_query_count = 0; | |
45c94154 JM |
1046 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); |
1047 | return 1; | |
5d22a1d5 JM |
1048 | } |
1049 | ||
45c94154 JM |
1050 | return 0; |
1051 | } | |
1052 | ||
1053 | ||
1054 | static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx) | |
1055 | { | |
1056 | struct hostapd_data *hapd = eloop_ctx; | |
1057 | struct sta_info *sta = timeout_ctx; | |
1058 | unsigned int timeout, sec, usec; | |
1059 | u8 *trans_id, *nbuf; | |
1060 | ||
03269d55 JM |
1061 | wpa_printf(MSG_DEBUG, "%s: SA Query timer for STA " MACSTR |
1062 | " (count=%d)", | |
1063 | hapd->conf->iface, MAC2STR(sta->addr), sta->sa_query_count); | |
1064 | ||
45c94154 JM |
1065 | if (sta->sa_query_count > 0 && |
1066 | ap_check_sa_query_timeout(hapd, sta)) | |
1067 | return; | |
1068 | ||
067ffa26 JM |
1069 | nbuf = os_realloc_array(sta->sa_query_trans_id, |
1070 | sta->sa_query_count + 1, | |
1071 | WLAN_SA_QUERY_TR_ID_LEN); | |
5d22a1d5 JM |
1072 | if (nbuf == NULL) |
1073 | return; | |
45c94154 JM |
1074 | if (sta->sa_query_count == 0) { |
1075 | /* Starting a new SA Query procedure */ | |
10e694a6 | 1076 | os_get_reltime(&sta->sa_query_start); |
45c94154 | 1077 | } |
93b76319 JM |
1078 | trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN; |
1079 | sta->sa_query_trans_id = nbuf; | |
1080 | sta->sa_query_count++; | |
5d22a1d5 | 1081 | |
24661bba JM |
1082 | if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) { |
1083 | /* | |
1084 | * We don't really care which ID is used here, so simply | |
1085 | * hardcode this if the mostly theoretical os_get_random() | |
1086 | * failure happens. | |
1087 | */ | |
1088 | trans_id[0] = 0x12; | |
1089 | trans_id[1] = 0x34; | |
1090 | } | |
5d22a1d5 | 1091 | |
45c94154 JM |
1092 | timeout = hapd->conf->assoc_sa_query_retry_timeout; |
1093 | sec = ((timeout / 1000) * 1024) / 1000; | |
1094 | usec = (timeout % 1000) * 1024; | |
1095 | eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta); | |
1096 | ||
5d22a1d5 JM |
1097 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
1098 | HOSTAPD_LEVEL_DEBUG, | |
93b76319 | 1099 | "association SA Query attempt %d", sta->sa_query_count); |
5d22a1d5 | 1100 | |
93b76319 | 1101 | ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id); |
5d22a1d5 JM |
1102 | } |
1103 | ||
1104 | ||
93b76319 | 1105 | void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta) |
5d22a1d5 | 1106 | { |
93b76319 | 1107 | ap_sa_query_timer(hapd, sta); |
5d22a1d5 JM |
1108 | } |
1109 | ||
1110 | ||
93b76319 | 1111 | void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta) |
5d22a1d5 | 1112 | { |
93b76319 JM |
1113 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); |
1114 | os_free(sta->sa_query_trans_id); | |
1115 | sta->sa_query_trans_id = NULL; | |
1116 | sta->sa_query_count = 0; | |
5d22a1d5 JM |
1117 | } |
1118 | ||
1119 | #endif /* CONFIG_IEEE80211W */ | |
45cefa0b JM |
1120 | |
1121 | ||
6905dcb1 JB |
1122 | void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta, |
1123 | int authorized) | |
1124 | { | |
10cc6c88 | 1125 | const u8 *dev_addr = NULL; |
7793c959 | 1126 | char buf[100]; |
c2d76aa6 MH |
1127 | #ifdef CONFIG_P2P |
1128 | u8 addr[ETH_ALEN]; | |
25ef8529 | 1129 | u8 ip_addr_buf[4]; |
c2d76aa6 MH |
1130 | #endif /* CONFIG_P2P */ |
1131 | ||
6905dcb1 JB |
1132 | if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED)) |
1133 | return; | |
1134 | ||
61fc9048 SD |
1135 | if (authorized) |
1136 | sta->flags |= WLAN_STA_AUTHORIZED; | |
1137 | else | |
1138 | sta->flags &= ~WLAN_STA_AUTHORIZED; | |
1139 | ||
ae055af4 | 1140 | #ifdef CONFIG_P2P |
c2d76aa6 MH |
1141 | if (hapd->p2p_group == NULL) { |
1142 | if (sta->p2p_ie != NULL && | |
1143 | p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0) | |
1144 | dev_addr = addr; | |
1145 | } else | |
1146 | dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr); | |
10cc6c88 | 1147 | |
7793c959 JM |
1148 | if (dev_addr) |
1149 | os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR, | |
1150 | MAC2STR(sta->addr), MAC2STR(dev_addr)); | |
1151 | else | |
375f4a3b | 1152 | #endif /* CONFIG_P2P */ |
7793c959 JM |
1153 | os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr)); |
1154 | ||
61fc9048 SD |
1155 | if (hapd->sta_authorized_cb) |
1156 | hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx, | |
1157 | sta->addr, authorized, dev_addr); | |
1158 | ||
10cc6c88 | 1159 | if (authorized) { |
25ef8529 JM |
1160 | char ip_addr[100]; |
1161 | ip_addr[0] = '\0'; | |
1162 | #ifdef CONFIG_P2P | |
1163 | if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) { | |
1164 | os_snprintf(ip_addr, sizeof(ip_addr), | |
1165 | " ip_addr=%u.%u.%u.%u", | |
1166 | ip_addr_buf[0], ip_addr_buf[1], | |
1167 | ip_addr_buf[2], ip_addr_buf[3]); | |
1168 | } | |
1169 | #endif /* CONFIG_P2P */ | |
1170 | ||
1171 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s", | |
1172 | buf, ip_addr); | |
7793c959 | 1173 | |
8a5e75f6 | 1174 | if (hapd->msg_ctx_parent && |
7793c959 | 1175 | hapd->msg_ctx_parent != hapd->msg_ctx) |
c4bf83a7 | 1176 | wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO, |
25ef8529 JM |
1177 | AP_STA_CONNECTED "%s%s", |
1178 | buf, ip_addr); | |
ae055af4 | 1179 | } else { |
7793c959 JM |
1180 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf); |
1181 | ||
8a5e75f6 | 1182 | if (hapd->msg_ctx_parent && |
7793c959 | 1183 | hapd->msg_ctx_parent != hapd->msg_ctx) |
c4bf83a7 JM |
1184 | wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO, |
1185 | AP_STA_DISCONNECTED "%s", buf); | |
ae055af4 | 1186 | } |
6959145b AN |
1187 | |
1188 | #ifdef CONFIG_FST | |
1189 | if (hapd->iface->fst) { | |
1190 | if (authorized) | |
1191 | fst_notify_peer_connected(hapd->iface->fst, sta->addr); | |
1192 | else | |
1193 | fst_notify_peer_disconnected(hapd->iface->fst, | |
1194 | sta->addr); | |
1195 | } | |
1196 | #endif /* CONFIG_FST */ | |
6905dcb1 JB |
1197 | } |
1198 | ||
1199 | ||
45cefa0b JM |
1200 | void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta, |
1201 | const u8 *addr, u16 reason) | |
1202 | { | |
03269d55 JM |
1203 | if (sta) |
1204 | wpa_printf(MSG_DEBUG, "%s: %s STA " MACSTR " reason=%u", | |
1205 | hapd->conf->iface, __func__, MAC2STR(sta->addr), | |
1206 | reason); | |
1207 | else if (addr) | |
1208 | wpa_printf(MSG_DEBUG, "%s: %s addr " MACSTR " reason=%u", | |
1209 | hapd->conf->iface, __func__, MAC2STR(addr), | |
1210 | reason); | |
45cefa0b JM |
1211 | |
1212 | if (sta == NULL && addr) | |
1213 | sta = ap_get_sta(hapd, addr); | |
1214 | ||
1215 | if (addr) | |
51e2a27a | 1216 | hostapd_drv_sta_deauth(hapd, addr, reason); |
45cefa0b JM |
1217 | |
1218 | if (sta == NULL) | |
1219 | return; | |
6905dcb1 | 1220 | ap_sta_set_authorized(hapd, sta, 0); |
ceb997f3 JM |
1221 | wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH); |
1222 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
6905dcb1 | 1223 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); |
03269d55 | 1224 | wpa_printf(MSG_DEBUG, "%s: %s: reschedule ap_handle_timer timeout " |
42ca9845 JM |
1225 | "for " MACSTR " (%d seconds - " |
1226 | "AP_MAX_INACTIVITY_AFTER_DEAUTH)", | |
03269d55 | 1227 | hapd->conf->iface, __func__, MAC2STR(sta->addr), |
42ca9845 | 1228 | AP_MAX_INACTIVITY_AFTER_DEAUTH); |
45cefa0b | 1229 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
4dc03726 JM |
1230 | eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0, |
1231 | ap_handle_timer, hapd, sta); | |
45cefa0b | 1232 | sta->timeout_next = STA_REMOVE; |
4dc03726 JM |
1233 | |
1234 | sta->deauth_reason = reason; | |
cc28ad8c | 1235 | sta->flags |= WLAN_STA_PENDING_DEAUTH_CB; |
4dc03726 JM |
1236 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
1237 | eloop_register_timeout(hapd->iface->drv_flags & | |
1238 | WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0, | |
1239 | ap_sta_deauth_cb_timeout, hapd, sta); | |
1240 | } | |
1241 | ||
1242 | ||
1243 | void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta) | |
1244 | { | |
cc28ad8c JM |
1245 | if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) { |
1246 | wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame"); | |
1247 | return; | |
1248 | } | |
1249 | sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB; | |
4dc03726 JM |
1250 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
1251 | ap_sta_deauth_cb_timeout(hapd, sta); | |
1252 | } | |
1253 | ||
1254 | ||
1255 | void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta) | |
1256 | { | |
cc28ad8c JM |
1257 | if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) { |
1258 | wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame"); | |
1259 | return; | |
1260 | } | |
1261 | sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB; | |
1262 | eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta); | |
1263 | ap_sta_disassoc_cb_timeout(hapd, sta); | |
45cefa0b | 1264 | } |
b76f4c27 JM |
1265 | |
1266 | ||
9e8fde21 JM |
1267 | void ap_sta_clear_disconnect_timeouts(struct hostapd_data *hapd, |
1268 | struct sta_info *sta) | |
1269 | { | |
1270 | if (eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta) > 0) | |
1271 | wpa_printf(MSG_DEBUG, | |
1272 | "%s: Removed ap_sta_deauth_cb_timeout timeout for " | |
1273 | MACSTR, | |
1274 | hapd->conf->iface, MAC2STR(sta->addr)); | |
1275 | if (eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta) > 0) | |
1276 | wpa_printf(MSG_DEBUG, | |
1277 | "%s: Removed ap_sta_disassoc_cb_timeout timeout for " | |
1278 | MACSTR, | |
1279 | hapd->conf->iface, MAC2STR(sta->addr)); | |
0f5eb69f JM |
1280 | if (eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta) > 0) |
1281 | { | |
1282 | wpa_printf(MSG_DEBUG, | |
1283 | "%s: Removed ap_sta_delayed_1x_auth_fail_cb timeout for " | |
1284 | MACSTR, | |
1285 | hapd->conf->iface, MAC2STR(sta->addr)); | |
1286 | if (sta->flags & WLAN_STA_WPS) | |
1287 | hostapd_wps_eap_completed(hapd); | |
1288 | } | |
9e8fde21 JM |
1289 | } |
1290 | ||
1291 | ||
b76f4c27 JM |
1292 | int ap_sta_flags_txt(u32 flags, char *buf, size_t buflen) |
1293 | { | |
1294 | int res; | |
1295 | ||
1296 | buf[0] = '\0'; | |
e7d0e97b | 1297 | res = os_snprintf(buf, buflen, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", |
b76f4c27 JM |
1298 | (flags & WLAN_STA_AUTH ? "[AUTH]" : ""), |
1299 | (flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""), | |
1300 | (flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : ""), | |
1301 | (flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" : | |
1302 | ""), | |
1303 | (flags & WLAN_STA_SHORT_PREAMBLE ? | |
1304 | "[SHORT_PREAMBLE]" : ""), | |
1305 | (flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""), | |
1306 | (flags & WLAN_STA_WMM ? "[WMM]" : ""), | |
1307 | (flags & WLAN_STA_MFP ? "[MFP]" : ""), | |
1308 | (flags & WLAN_STA_WPS ? "[WPS]" : ""), | |
1309 | (flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""), | |
1310 | (flags & WLAN_STA_WDS ? "[WDS]" : ""), | |
1311 | (flags & WLAN_STA_NONERP ? "[NonERP]" : ""), | |
1312 | (flags & WLAN_STA_WPS2 ? "[WPS2]" : ""), | |
1313 | (flags & WLAN_STA_GAS ? "[GAS]" : ""), | |
1314 | (flags & WLAN_STA_VHT ? "[VHT]" : ""), | |
e7d0e97b | 1315 | (flags & WLAN_STA_VENDOR_VHT ? "[VENDOR_VHT]" : ""), |
b76f4c27 JM |
1316 | (flags & WLAN_STA_WNM_SLEEP_MODE ? |
1317 | "[WNM_SLEEP_MODE]" : "")); | |
aaadd727 JM |
1318 | if (os_snprintf_error(buflen, res)) |
1319 | res = -1; | |
b76f4c27 JM |
1320 | |
1321 | return res; | |
1322 | } | |
0f5eb69f JM |
1323 | |
1324 | ||
1325 | static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx) | |
1326 | { | |
1327 | struct hostapd_data *hapd = eloop_ctx; | |
1328 | struct sta_info *sta = timeout_ctx; | |
1329 | ||
1330 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, | |
1331 | "IEEE 802.1X: Scheduled disconnection of " MACSTR | |
1332 | " after EAP-Failure", MAC2STR(sta->addr)); | |
1333 | ||
1334 | ap_sta_disconnect(hapd, sta, sta->addr, | |
1335 | WLAN_REASON_IEEE_802_1X_AUTH_FAILED); | |
1336 | if (sta->flags & WLAN_STA_WPS) | |
1337 | hostapd_wps_eap_completed(hapd); | |
1338 | } | |
1339 | ||
1340 | ||
1341 | void ap_sta_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd, | |
1342 | struct sta_info *sta) | |
1343 | { | |
1344 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, | |
1345 | "IEEE 802.1X: Force disconnection of " MACSTR | |
1346 | " after EAP-Failure in 10 ms", MAC2STR(sta->addr)); | |
1347 | ||
1348 | /* | |
1349 | * Add a small sleep to increase likelihood of previously requested | |
1350 | * EAP-Failure TX getting out before this should the driver reorder | |
1351 | * operations. | |
1352 | */ | |
1353 | eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta); | |
1354 | eloop_register_timeout(0, 10000, ap_sta_delayed_1x_auth_fail_cb, | |
1355 | hapd, sta); | |
1356 | } | |
1357 | ||
1358 | ||
1359 | int ap_sta_pending_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd, | |
1360 | struct sta_info *sta) | |
1361 | { | |
1362 | return eloop_is_timeout_registered(ap_sta_delayed_1x_auth_fail_cb, | |
1363 | hapd, sta); | |
1364 | } |