]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * hostapd / Station table | |
f2c56602 | 3 | * Copyright (c) 2002-2013, 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" |
6fc6879b | 19 | #include "hostapd.h" |
6fc6879b JM |
20 | #include "accounting.h" |
21 | #include "ieee802_1x.h" | |
22 | #include "ieee802_11.h" | |
f2a14be7 | 23 | #include "ieee802_11_auth.h" |
6226e38d JM |
24 | #include "wpa_auth.h" |
25 | #include "preauth_auth.h" | |
26 | #include "ap_config.h" | |
6fc6879b | 27 | #include "beacon.h" |
6226e38d | 28 | #include "ap_mlme.h" |
6fc6879b | 29 | #include "vlan_init.h" |
aefb53bd | 30 | #include "p2p_hostapd.h" |
cee7d66b | 31 | #include "ap_drv_ops.h" |
dca30c3f | 32 | #include "gas_serv.h" |
97596f8e | 33 | #include "wnm_ap.h" |
6226e38d | 34 | #include "sta_info.h" |
6fc6879b | 35 | |
53f3d6f3 FF |
36 | static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd, |
37 | struct sta_info *sta); | |
6fc6879b | 38 | static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx); |
97596f8e | 39 | static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx); |
4dc03726 JM |
40 | static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx); |
41 | static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx); | |
5d22a1d5 | 42 | #ifdef CONFIG_IEEE80211W |
93b76319 | 43 | static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx); |
5d22a1d5 | 44 | #endif /* CONFIG_IEEE80211W */ |
4dc03726 | 45 | static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta); |
6fc6879b JM |
46 | |
47 | int ap_for_each_sta(struct hostapd_data *hapd, | |
48 | int (*cb)(struct hostapd_data *hapd, struct sta_info *sta, | |
49 | void *ctx), | |
50 | void *ctx) | |
51 | { | |
52 | struct sta_info *sta; | |
53 | ||
54 | for (sta = hapd->sta_list; sta; sta = sta->next) { | |
55 | if (cb(hapd, sta, ctx)) | |
56 | return 1; | |
57 | } | |
58 | ||
59 | return 0; | |
60 | } | |
61 | ||
62 | ||
63 | struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta) | |
64 | { | |
65 | struct sta_info *s; | |
66 | ||
67 | s = hapd->sta_hash[STA_HASH(sta)]; | |
68 | while (s != NULL && os_memcmp(s->addr, sta, 6) != 0) | |
69 | s = s->hnext; | |
70 | return s; | |
71 | } | |
72 | ||
73 | ||
f2c56602 JM |
74 | #ifdef CONFIG_P2P |
75 | struct sta_info * ap_get_sta_p2p(struct hostapd_data *hapd, const u8 *addr) | |
76 | { | |
77 | struct sta_info *sta; | |
78 | ||
79 | for (sta = hapd->sta_list; sta; sta = sta->next) { | |
80 | const u8 *p2p_dev_addr; | |
81 | ||
82 | if (sta->p2p_ie == NULL) | |
83 | continue; | |
84 | ||
85 | p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie); | |
86 | if (p2p_dev_addr == NULL) | |
87 | continue; | |
88 | ||
89 | if (os_memcmp(p2p_dev_addr, addr, ETH_ALEN) == 0) | |
90 | return sta; | |
91 | } | |
92 | ||
93 | return NULL; | |
94 | } | |
95 | #endif /* CONFIG_P2P */ | |
96 | ||
97 | ||
6fc6879b JM |
98 | static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta) |
99 | { | |
100 | struct sta_info *tmp; | |
101 | ||
102 | if (hapd->sta_list == sta) { | |
103 | hapd->sta_list = sta->next; | |
104 | return; | |
105 | } | |
106 | ||
107 | tmp = hapd->sta_list; | |
108 | while (tmp != NULL && tmp->next != sta) | |
109 | tmp = tmp->next; | |
110 | if (tmp == NULL) { | |
111 | wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from " | |
112 | "list.", MAC2STR(sta->addr)); | |
113 | } else | |
114 | tmp->next = sta->next; | |
115 | } | |
116 | ||
117 | ||
118 | void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta) | |
119 | { | |
120 | sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)]; | |
121 | hapd->sta_hash[STA_HASH(sta->addr)] = sta; | |
122 | } | |
123 | ||
124 | ||
125 | static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta) | |
126 | { | |
127 | struct sta_info *s; | |
128 | ||
129 | s = hapd->sta_hash[STA_HASH(sta->addr)]; | |
130 | if (s == NULL) return; | |
131 | if (os_memcmp(s->addr, sta->addr, 6) == 0) { | |
132 | hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext; | |
133 | return; | |
134 | } | |
135 | ||
136 | while (s->hnext != NULL && | |
137 | os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0) | |
138 | s = s->hnext; | |
139 | if (s->hnext != NULL) | |
140 | s->hnext = s->hnext->hnext; | |
141 | else | |
142 | wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR | |
143 | " from hash table", MAC2STR(sta->addr)); | |
144 | } | |
145 | ||
146 | ||
147 | void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta) | |
148 | { | |
149 | int set_beacon = 0; | |
150 | ||
151 | accounting_sta_stop(hapd, sta); | |
152 | ||
6905dcb1 JB |
153 | /* just in case */ |
154 | ap_sta_set_authorized(hapd, sta, 0); | |
155 | ||
39f42d11 | 156 | if (sta->flags & WLAN_STA_WDS) |
69dd2967 | 157 | hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0); |
53f3d6f3 | 158 | |
354c903f MB |
159 | if (!hapd->iface->driver_ap_teardown && |
160 | !(sta->flags & WLAN_STA_PREAUTH)) | |
51e2a27a | 161 | hostapd_drv_sta_remove(hapd, sta->addr); |
6fc6879b JM |
162 | |
163 | ap_sta_hash_del(hapd, sta); | |
164 | ap_sta_list_del(hapd, sta); | |
165 | ||
166 | if (sta->aid > 0) | |
2991469c JM |
167 | hapd->sta_aid[(sta->aid - 1) / 32] &= |
168 | ~BIT((sta->aid - 1) % 32); | |
6fc6879b JM |
169 | |
170 | hapd->num_sta--; | |
171 | if (sta->nonerp_set) { | |
172 | sta->nonerp_set = 0; | |
173 | hapd->iface->num_sta_non_erp--; | |
174 | if (hapd->iface->num_sta_non_erp == 0) | |
175 | set_beacon++; | |
176 | } | |
177 | ||
178 | if (sta->no_short_slot_time_set) { | |
179 | sta->no_short_slot_time_set = 0; | |
180 | hapd->iface->num_sta_no_short_slot_time--; | |
181 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G | |
182 | && hapd->iface->num_sta_no_short_slot_time == 0) | |
183 | set_beacon++; | |
184 | } | |
185 | ||
186 | if (sta->no_short_preamble_set) { | |
187 | sta->no_short_preamble_set = 0; | |
188 | hapd->iface->num_sta_no_short_preamble--; | |
189 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G | |
190 | && hapd->iface->num_sta_no_short_preamble == 0) | |
191 | set_beacon++; | |
192 | } | |
193 | ||
e8ff1e59 JM |
194 | if (sta->no_ht_gf_set) { |
195 | sta->no_ht_gf_set = 0; | |
196 | hapd->iface->num_sta_ht_no_gf--; | |
197 | } | |
198 | ||
199 | if (sta->no_ht_set) { | |
200 | sta->no_ht_set = 0; | |
de9289c8 | 201 | hapd->iface->num_sta_no_ht--; |
e8ff1e59 JM |
202 | } |
203 | ||
204 | if (sta->ht_20mhz_set) { | |
205 | sta->ht_20mhz_set = 0; | |
206 | hapd->iface->num_sta_ht_20mhz--; | |
207 | } | |
de9289c8 | 208 | |
aefb53bd JM |
209 | #ifdef CONFIG_P2P |
210 | if (sta->no_p2p_set) { | |
211 | sta->no_p2p_set = 0; | |
212 | hapd->num_sta_no_p2p--; | |
213 | if (hapd->num_sta_no_p2p == 0) | |
214 | hostapd_p2p_non_p2p_sta_disconnected(hapd); | |
215 | } | |
216 | #endif /* CONFIG_P2P */ | |
217 | ||
d45354be | 218 | #if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N) |
de9289c8 JM |
219 | if (hostapd_ht_operation_update(hapd->iface) > 0) |
220 | set_beacon++; | |
d45354be | 221 | #endif /* NEED_AP_MLME && CONFIG_IEEE80211N */ |
de9289c8 | 222 | |
6fc6879b JM |
223 | if (set_beacon) |
224 | ieee802_11_set_beacons(hapd->iface); | |
225 | ||
42ca9845 JM |
226 | wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR, |
227 | __func__, MAC2STR(sta->addr)); | |
6fc6879b JM |
228 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
229 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); | |
97596f8e | 230 | eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta); |
4dc03726 JM |
231 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
232 | eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta); | |
6fc6879b JM |
233 | |
234 | ieee802_1x_free_station(sta); | |
235 | wpa_auth_sta_deinit(sta->wpa_sm); | |
236 | rsn_preauth_free_station(hapd, sta); | |
74784010 | 237 | #ifndef CONFIG_NO_RADIUS |
ded22b53 HS |
238 | if (hapd->radius) |
239 | radius_client_flush_auth(hapd->radius, sta->addr); | |
74784010 | 240 | #endif /* CONFIG_NO_RADIUS */ |
6fc6879b JM |
241 | |
242 | os_free(sta->last_assoc_req); | |
243 | os_free(sta->challenge); | |
5d22a1d5 JM |
244 | |
245 | #ifdef CONFIG_IEEE80211W | |
93b76319 JM |
246 | os_free(sta->sa_query_trans_id); |
247 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); | |
5d22a1d5 JM |
248 | #endif /* CONFIG_IEEE80211W */ |
249 | ||
8ccbe415 JM |
250 | #ifdef CONFIG_P2P |
251 | p2p_group_notif_disassoc(hapd->p2p_group, sta->addr); | |
252 | #endif /* CONFIG_P2P */ | |
253 | ||
dca30c3f JK |
254 | #ifdef CONFIG_INTERWORKING |
255 | if (sta->gas_dialog) { | |
256 | int i; | |
257 | for (i = 0; i < GAS_DIALOG_MAX; i++) | |
258 | gas_serv_dialog_clear(&sta->gas_dialog[i]); | |
259 | os_free(sta->gas_dialog); | |
260 | } | |
261 | #endif /* CONFIG_INTERWORKING */ | |
262 | ||
eb76b7e3 | 263 | wpabuf_free(sta->wps_ie); |
b305c684 | 264 | wpabuf_free(sta->p2p_ie); |
f403dcd6 | 265 | wpabuf_free(sta->hs20_ie); |
eb76b7e3 | 266 | |
df84268a | 267 | os_free(sta->ht_capabilities); |
cc14091e | 268 | os_free(sta->vht_capabilities); |
f2a14be7 | 269 | hostapd_free_psk_list(sta->psk); |
2092597f MB |
270 | os_free(sta->identity); |
271 | os_free(sta->radius_cui); | |
6ca0853d | 272 | os_free(sta->remediation_url); |
8e1146d9 | 273 | wpabuf_free(sta->hs20_deauth_req); |
97596f8e | 274 | os_free(sta->hs20_session_info_url); |
df84268a | 275 | |
98efcc41 | 276 | #ifdef CONFIG_SAE |
a46d72d7 | 277 | sae_clear_data(sta->sae); |
98efcc41 JM |
278 | os_free(sta->sae); |
279 | #endif /* CONFIG_SAE */ | |
280 | ||
6fc6879b JM |
281 | os_free(sta); |
282 | } | |
283 | ||
284 | ||
285 | void hostapd_free_stas(struct hostapd_data *hapd) | |
286 | { | |
287 | struct sta_info *sta, *prev; | |
288 | ||
289 | sta = hapd->sta_list; | |
290 | ||
291 | while (sta) { | |
292 | prev = sta; | |
293 | if (sta->flags & WLAN_STA_AUTH) { | |
294 | mlme_deauthenticate_indication( | |
295 | hapd, sta, WLAN_REASON_UNSPECIFIED); | |
296 | } | |
297 | sta = sta->next; | |
298 | wpa_printf(MSG_DEBUG, "Removing station " MACSTR, | |
299 | MAC2STR(prev->addr)); | |
300 | ap_free_sta(hapd, prev); | |
301 | } | |
302 | } | |
303 | ||
304 | ||
1c6e69cc JM |
305 | /** |
306 | * ap_handle_timer - Per STA timer handler | |
307 | * @eloop_ctx: struct hostapd_data * | |
308 | * @timeout_ctx: struct sta_info * | |
309 | * | |
310 | * This function is called to check station activity and to remove inactive | |
311 | * stations. | |
312 | */ | |
6fc6879b JM |
313 | void ap_handle_timer(void *eloop_ctx, void *timeout_ctx) |
314 | { | |
315 | struct hostapd_data *hapd = eloop_ctx; | |
316 | struct sta_info *sta = timeout_ctx; | |
317 | unsigned long next_time = 0; | |
d5b559b6 | 318 | int reason; |
6fc6879b | 319 | |
42ca9845 JM |
320 | wpa_printf(MSG_DEBUG, "%s: " MACSTR " flags=0x%x timeout_next=%d", |
321 | __func__, MAC2STR(sta->addr), sta->flags, | |
322 | sta->timeout_next); | |
6fc6879b JM |
323 | if (sta->timeout_next == STA_REMOVE) { |
324 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
325 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " | |
326 | "local deauth request"); | |
327 | ap_free_sta(hapd, sta); | |
328 | return; | |
329 | } | |
330 | ||
331 | if ((sta->flags & WLAN_STA_ASSOC) && | |
332 | (sta->timeout_next == STA_NULLFUNC || | |
333 | sta->timeout_next == STA_DISASSOC)) { | |
334 | int inactive_sec; | |
ce28e279 BG |
335 | /* |
336 | * Add random value to timeout so that we don't end up bouncing | |
337 | * all stations at the same time if we have lots of associated | |
338 | * stations that are idle (but keep re-associating). | |
339 | */ | |
340 | int fuzz = os_random() % 20; | |
51e2a27a | 341 | inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr); |
6fc6879b | 342 | if (inactive_sec == -1) { |
3ec1e902 JM |
343 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
344 | "Check inactivity: Could not " | |
d5674791 | 345 | "get station info from kernel driver for " |
24d75245 | 346 | MACSTR, MAC2STR(sta->addr)); |
d5674791 JM |
347 | /* |
348 | * The driver may not support this functionality. | |
349 | * Anyway, try again after the next inactivity timeout, | |
350 | * but do not disconnect the station now. | |
351 | */ | |
ce28e279 | 352 | next_time = hapd->conf->ap_max_inactivity + fuzz; |
6fc6879b JM |
353 | } else if (inactive_sec < hapd->conf->ap_max_inactivity && |
354 | sta->flags & WLAN_STA_ASSOC) { | |
355 | /* station activity detected; reset timeout state */ | |
3ec1e902 JM |
356 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
357 | "Station " MACSTR " has been active %is ago", | |
24d75245 | 358 | MAC2STR(sta->addr), inactive_sec); |
6fc6879b | 359 | sta->timeout_next = STA_NULLFUNC; |
ce28e279 | 360 | next_time = hapd->conf->ap_max_inactivity + fuzz - |
6fc6879b | 361 | inactive_sec; |
24d75245 | 362 | } else { |
3ec1e902 JM |
363 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
364 | "Station " MACSTR " has been " | |
24d75245 BG |
365 | "inactive too long: %d sec, max allowed: %d", |
366 | MAC2STR(sta->addr), inactive_sec, | |
367 | hapd->conf->ap_max_inactivity); | |
ef01fa7b YAP |
368 | |
369 | if (hapd->conf->skip_inactivity_poll) | |
370 | sta->timeout_next = STA_DISASSOC; | |
6fc6879b JM |
371 | } |
372 | } | |
373 | ||
374 | if ((sta->flags & WLAN_STA_ASSOC) && | |
375 | sta->timeout_next == STA_DISASSOC && | |
ef01fa7b YAP |
376 | !(sta->flags & WLAN_STA_PENDING_POLL) && |
377 | !hapd->conf->skip_inactivity_poll) { | |
3ec1e902 JM |
378 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR |
379 | " has ACKed data poll", MAC2STR(sta->addr)); | |
6fc6879b JM |
380 | /* data nullfunc frame poll did not produce TX errors; assume |
381 | * station ACKed it */ | |
382 | sta->timeout_next = STA_NULLFUNC; | |
383 | next_time = hapd->conf->ap_max_inactivity; | |
384 | } | |
385 | ||
386 | if (next_time) { | |
42ca9845 JM |
387 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
388 | "for " MACSTR " (%lu seconds)", | |
389 | __func__, MAC2STR(sta->addr), next_time); | |
6fc6879b JM |
390 | eloop_register_timeout(next_time, 0, ap_handle_timer, hapd, |
391 | sta); | |
392 | return; | |
393 | } | |
394 | ||
395 | if (sta->timeout_next == STA_NULLFUNC && | |
396 | (sta->flags & WLAN_STA_ASSOC)) { | |
bcf24348 | 397 | wpa_printf(MSG_DEBUG, " Polling STA"); |
6fc6879b | 398 | sta->flags |= WLAN_STA_PENDING_POLL; |
bcf24348 JB |
399 | hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr, |
400 | sta->flags & WLAN_STA_WMM); | |
6fc6879b JM |
401 | } else if (sta->timeout_next != STA_REMOVE) { |
402 | int deauth = sta->timeout_next == STA_DEAUTH; | |
403 | ||
afcc9ea1 BG |
404 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, |
405 | "Timeout, sending %s info to STA " MACSTR, | |
406 | deauth ? "deauthentication" : "disassociation", | |
407 | MAC2STR(sta->addr)); | |
6fc6879b JM |
408 | |
409 | if (deauth) { | |
51e2a27a JM |
410 | hostapd_drv_sta_deauth( |
411 | hapd, sta->addr, | |
412 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
6fc6879b | 413 | } else { |
d5b559b6 KP |
414 | reason = (sta->timeout_next == STA_DISASSOC) ? |
415 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY : | |
416 | WLAN_REASON_PREV_AUTH_NOT_VALID; | |
417 | ||
418 | hostapd_drv_sta_disassoc(hapd, sta->addr, reason); | |
6fc6879b JM |
419 | } |
420 | } | |
421 | ||
422 | switch (sta->timeout_next) { | |
423 | case STA_NULLFUNC: | |
424 | sta->timeout_next = STA_DISASSOC; | |
42ca9845 JM |
425 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
426 | "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)", | |
427 | __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY); | |
6fc6879b JM |
428 | eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer, |
429 | hapd, sta); | |
430 | break; | |
431 | case STA_DISASSOC: | |
d5b559b6 | 432 | case STA_DISASSOC_FROM_CLI: |
ae055af4 | 433 | ap_sta_set_authorized(hapd, sta, 0); |
6fc6879b JM |
434 | sta->flags &= ~WLAN_STA_ASSOC; |
435 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
436 | if (!sta->acct_terminate_cause) | |
437 | sta->acct_terminate_cause = | |
438 | RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT; | |
439 | accounting_sta_stop(hapd, sta); | |
440 | ieee802_1x_free_station(sta); | |
441 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
442 | HOSTAPD_LEVEL_INFO, "disassociated due to " | |
443 | "inactivity"); | |
d5b559b6 KP |
444 | reason = (sta->timeout_next == STA_DISASSOC) ? |
445 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY : | |
446 | WLAN_REASON_PREV_AUTH_NOT_VALID; | |
6fc6879b | 447 | sta->timeout_next = STA_DEAUTH; |
42ca9845 JM |
448 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
449 | "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)", | |
450 | __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY); | |
6fc6879b JM |
451 | eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer, |
452 | hapd, sta); | |
d5b559b6 | 453 | mlme_disassociate_indication(hapd, sta, reason); |
6fc6879b JM |
454 | break; |
455 | case STA_DEAUTH: | |
456 | case STA_REMOVE: | |
457 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
458 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " | |
afcc9ea1 | 459 | "inactivity (timer DEAUTH/REMOVE)"); |
6fc6879b JM |
460 | if (!sta->acct_terminate_cause) |
461 | sta->acct_terminate_cause = | |
462 | RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT; | |
463 | mlme_deauthenticate_indication( | |
464 | hapd, sta, | |
465 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
466 | ap_free_sta(hapd, sta); | |
467 | break; | |
468 | } | |
469 | } | |
470 | ||
471 | ||
472 | static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx) | |
473 | { | |
474 | struct hostapd_data *hapd = eloop_ctx; | |
475 | struct sta_info *sta = timeout_ctx; | |
476 | u8 addr[ETH_ALEN]; | |
477 | ||
dca30c3f JK |
478 | if (!(sta->flags & WLAN_STA_AUTH)) { |
479 | if (sta->flags & WLAN_STA_GAS) { | |
480 | wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA " | |
481 | "entry " MACSTR, MAC2STR(sta->addr)); | |
482 | ap_free_sta(hapd, sta); | |
483 | } | |
6fc6879b | 484 | return; |
dca30c3f | 485 | } |
6fc6879b JM |
486 | |
487 | mlme_deauthenticate_indication(hapd, sta, | |
488 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
489 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
490 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " | |
491 | "session timeout"); | |
492 | sta->acct_terminate_cause = | |
493 | RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT; | |
494 | os_memcpy(addr, sta->addr, ETH_ALEN); | |
495 | ap_free_sta(hapd, sta); | |
51e2a27a | 496 | hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID); |
6fc6879b JM |
497 | } |
498 | ||
499 | ||
91f9e607 KP |
500 | void ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta, |
501 | u32 session_timeout) | |
502 | { | |
503 | if (eloop_replenish_timeout(session_timeout, 0, | |
a09ffd5f | 504 | ap_handle_session_timer, hapd, sta) == 1) { |
91f9e607 KP |
505 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
506 | HOSTAPD_LEVEL_DEBUG, "setting session timeout " | |
507 | "to %d seconds", session_timeout); | |
508 | } | |
509 | } | |
510 | ||
511 | ||
6fc6879b JM |
512 | void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta, |
513 | u32 session_timeout) | |
514 | { | |
515 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
516 | HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d " | |
517 | "seconds", session_timeout); | |
518 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); | |
519 | eloop_register_timeout(session_timeout, 0, ap_handle_session_timer, | |
520 | hapd, sta); | |
521 | } | |
522 | ||
523 | ||
524 | void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta) | |
525 | { | |
526 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); | |
527 | } | |
528 | ||
529 | ||
97596f8e JM |
530 | static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx) |
531 | { | |
532 | #ifdef CONFIG_WNM | |
533 | struct hostapd_data *hapd = eloop_ctx; | |
534 | struct sta_info *sta = timeout_ctx; | |
535 | ||
536 | wpa_printf(MSG_DEBUG, "WNM: Session warning time reached for " MACSTR, | |
537 | MAC2STR(sta->addr)); | |
538 | if (sta->hs20_session_info_url == NULL) | |
539 | return; | |
540 | ||
541 | wnm_send_ess_disassoc_imminent(hapd, sta, sta->hs20_session_info_url, | |
542 | sta->hs20_disassoc_timer); | |
543 | #endif /* CONFIG_WNM */ | |
544 | } | |
545 | ||
546 | ||
547 | void ap_sta_session_warning_timeout(struct hostapd_data *hapd, | |
548 | struct sta_info *sta, int warning_time) | |
549 | { | |
550 | eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta); | |
551 | eloop_register_timeout(warning_time, 0, ap_handle_session_warning_timer, | |
552 | hapd, sta); | |
553 | } | |
554 | ||
555 | ||
6fc6879b JM |
556 | struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr) |
557 | { | |
558 | struct sta_info *sta; | |
559 | ||
560 | sta = ap_get_sta(hapd, addr); | |
561 | if (sta) | |
562 | return sta; | |
563 | ||
564 | wpa_printf(MSG_DEBUG, " New STA"); | |
565 | if (hapd->num_sta >= hapd->conf->max_num_sta) { | |
566 | /* FIX: might try to remove some old STAs first? */ | |
567 | wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)", | |
568 | hapd->num_sta, hapd->conf->max_num_sta); | |
569 | return NULL; | |
570 | } | |
571 | ||
572 | sta = os_zalloc(sizeof(struct sta_info)); | |
573 | if (sta == NULL) { | |
574 | wpa_printf(MSG_ERROR, "malloc failed"); | |
575 | return NULL; | |
576 | } | |
5843e1c9 | 577 | sta->acct_interim_interval = hapd->conf->acct_interim_interval; |
8b248611 | 578 | accounting_sta_get_id(hapd, sta); |
6fc6879b | 579 | |
336167c8 MSS |
580 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) { |
581 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " | |
582 | "for " MACSTR " (%d seconds - ap_max_inactivity)", | |
583 | __func__, MAC2STR(addr), | |
584 | hapd->conf->ap_max_inactivity); | |
585 | eloop_register_timeout(hapd->conf->ap_max_inactivity, 0, | |
586 | ap_handle_timer, hapd, sta); | |
587 | } | |
588 | ||
6fc6879b | 589 | /* initialize STA info data */ |
6fc6879b JM |
590 | os_memcpy(sta->addr, addr, ETH_ALEN); |
591 | sta->next = hapd->sta_list; | |
592 | hapd->sta_list = sta; | |
593 | hapd->num_sta++; | |
594 | ap_sta_hash_add(hapd, sta); | |
595 | sta->ssid = &hapd->conf->ssid; | |
53f3d6f3 | 596 | ap_sta_remove_in_other_bss(hapd, sta); |
6fc6879b JM |
597 | |
598 | return sta; | |
599 | } | |
600 | ||
601 | ||
602 | static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta) | |
603 | { | |
604 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
605 | ||
606 | wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver", | |
607 | MAC2STR(sta->addr)); | |
51e2a27a | 608 | if (hostapd_drv_sta_remove(hapd, sta->addr) && |
6fc6879b JM |
609 | sta->flags & WLAN_STA_ASSOC) { |
610 | wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR | |
611 | " from kernel driver.", MAC2STR(sta->addr)); | |
612 | return -1; | |
613 | } | |
614 | return 0; | |
615 | } | |
616 | ||
617 | ||
53f3d6f3 FF |
618 | static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd, |
619 | struct sta_info *sta) | |
6fc6879b JM |
620 | { |
621 | struct hostapd_iface *iface = hapd->iface; | |
622 | size_t i; | |
623 | ||
624 | for (i = 0; i < iface->num_bss; i++) { | |
625 | struct hostapd_data *bss = iface->bss[i]; | |
626 | struct sta_info *sta2; | |
627 | /* bss should always be set during operation, but it may be | |
628 | * NULL during reconfiguration. Assume the STA is not | |
629 | * associated to another BSS in that case to avoid NULL pointer | |
630 | * dereferences. */ | |
631 | if (bss == hapd || bss == NULL) | |
632 | continue; | |
633 | sta2 = ap_get_sta(bss, sta->addr); | |
53f3d6f3 FF |
634 | if (!sta2) |
635 | continue; | |
6fc6879b | 636 | |
53f3d6f3 FF |
637 | ap_sta_disconnect(bss, sta2, sta2->addr, |
638 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
639 | } | |
6fc6879b JM |
640 | } |
641 | ||
642 | ||
4dc03726 JM |
643 | static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx) |
644 | { | |
645 | struct hostapd_data *hapd = eloop_ctx; | |
646 | struct sta_info *sta = timeout_ctx; | |
647 | ||
648 | ap_sta_remove(hapd, sta); | |
649 | mlme_disassociate_indication(hapd, sta, sta->disassoc_reason); | |
650 | } | |
651 | ||
652 | ||
6fc6879b JM |
653 | void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta, |
654 | u16 reason) | |
655 | { | |
656 | wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR, | |
657 | hapd->conf->iface, MAC2STR(sta->addr)); | |
ba873c12 | 658 | sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); |
4dc03726 | 659 | ap_sta_set_authorized(hapd, sta, 0); |
6fc6879b | 660 | sta->timeout_next = STA_DEAUTH; |
42ca9845 JM |
661 | wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " |
662 | "for " MACSTR " (%d seconds - " | |
663 | "AP_MAX_INACTIVITY_AFTER_DISASSOC)", | |
664 | __func__, MAC2STR(sta->addr), | |
665 | AP_MAX_INACTIVITY_AFTER_DISASSOC); | |
6fc6879b JM |
666 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
667 | eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0, | |
668 | ap_handle_timer, hapd, sta); | |
669 | accounting_sta_stop(hapd, sta); | |
670 | ieee802_1x_free_station(sta); | |
671 | ||
4dc03726 | 672 | sta->disassoc_reason = reason; |
cc28ad8c | 673 | sta->flags |= WLAN_STA_PENDING_DISASSOC_CB; |
4dc03726 JM |
674 | eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta); |
675 | eloop_register_timeout(hapd->iface->drv_flags & | |
676 | WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0, | |
677 | ap_sta_disassoc_cb_timeout, hapd, sta); | |
678 | } | |
679 | ||
680 | ||
681 | static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx) | |
682 | { | |
683 | struct hostapd_data *hapd = eloop_ctx; | |
684 | struct sta_info *sta = timeout_ctx; | |
685 | ||
686 | ap_sta_remove(hapd, sta); | |
687 | mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason); | |
6fc6879b JM |
688 | } |
689 | ||
690 | ||
691 | void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta, | |
692 | u16 reason) | |
693 | { | |
694 | wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR, | |
695 | hapd->conf->iface, MAC2STR(sta->addr)); | |
696 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); | |
4dc03726 | 697 | ap_sta_set_authorized(hapd, sta, 0); |
6fc6879b | 698 | sta->timeout_next = STA_REMOVE; |
42ca9845 JM |
699 | wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " |
700 | "for " MACSTR " (%d seconds - " | |
701 | "AP_MAX_INACTIVITY_AFTER_DEAUTH)", | |
702 | __func__, MAC2STR(sta->addr), | |
703 | AP_MAX_INACTIVITY_AFTER_DEAUTH); | |
6fc6879b JM |
704 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
705 | eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0, | |
706 | ap_handle_timer, hapd, sta); | |
707 | accounting_sta_stop(hapd, sta); | |
708 | ieee802_1x_free_station(sta); | |
709 | ||
4dc03726 | 710 | sta->deauth_reason = reason; |
cc28ad8c | 711 | sta->flags |= WLAN_STA_PENDING_DEAUTH_CB; |
4dc03726 JM |
712 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
713 | eloop_register_timeout(hapd->iface->drv_flags & | |
714 | WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0, | |
715 | ap_sta_deauth_cb_timeout, hapd, sta); | |
6fc6879b JM |
716 | } |
717 | ||
718 | ||
4c374cde AS |
719 | #ifdef CONFIG_WPS |
720 | int ap_sta_wps_cancel(struct hostapd_data *hapd, | |
721 | struct sta_info *sta, void *ctx) | |
722 | { | |
723 | if (sta && (sta->flags & WLAN_STA_WPS)) { | |
724 | ap_sta_deauthenticate(hapd, sta, | |
725 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
726 | wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR, | |
727 | __func__, MAC2STR(sta->addr)); | |
728 | return 1; | |
729 | } | |
730 | ||
731 | return 0; | |
732 | } | |
733 | #endif /* CONFIG_WPS */ | |
734 | ||
735 | ||
6fc6879b JM |
736 | int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta, |
737 | int old_vlanid) | |
738 | { | |
30b32314 | 739 | #ifndef CONFIG_NO_VLAN |
6fc6879b JM |
740 | const char *iface; |
741 | struct hostapd_vlan *vlan = NULL; | |
4254100d | 742 | int ret; |
6fc6879b JM |
743 | |
744 | /* | |
745 | * Do not proceed furthur if the vlan id remains same. We do not want | |
746 | * duplicate dynamic vlan entries. | |
747 | */ | |
748 | if (sta->vlan_id == old_vlanid) | |
749 | return 0; | |
750 | ||
751 | /* | |
752 | * During 1x reauth, if the vlan id changes, then remove the old id and | |
753 | * proceed furthur to add the new one. | |
754 | */ | |
755 | if (old_vlanid > 0) | |
756 | vlan_remove_dynamic(hapd, old_vlanid); | |
757 | ||
758 | iface = hapd->conf->iface; | |
759 | if (sta->ssid->vlan[0]) | |
760 | iface = sta->ssid->vlan; | |
761 | ||
762 | if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED) | |
763 | sta->vlan_id = 0; | |
764 | else if (sta->vlan_id > 0) { | |
c2db79f2 | 765 | struct hostapd_vlan *wildcard_vlan = NULL; |
6fc6879b JM |
766 | vlan = hapd->conf->vlan; |
767 | while (vlan) { | |
c2db79f2 | 768 | if (vlan->vlan_id == sta->vlan_id) |
6fc6879b | 769 | break; |
c2db79f2 MB |
770 | if (vlan->vlan_id == VLAN_ID_WILDCARD) |
771 | wildcard_vlan = vlan; | |
6fc6879b JM |
772 | vlan = vlan->next; |
773 | } | |
c2db79f2 MB |
774 | if (!vlan) |
775 | vlan = wildcard_vlan; | |
776 | if (vlan) | |
777 | iface = vlan->ifname; | |
6fc6879b JM |
778 | } |
779 | ||
780 | if (sta->vlan_id > 0 && vlan == NULL) { | |
781 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
782 | HOSTAPD_LEVEL_DEBUG, "could not find VLAN for " | |
783 | "binding station to (vlan_id=%d)", | |
784 | sta->vlan_id); | |
785 | return -1; | |
786 | } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) { | |
787 | vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id); | |
788 | if (vlan == NULL) { | |
789 | hostapd_logger(hapd, sta->addr, | |
790 | HOSTAPD_MODULE_IEEE80211, | |
791 | HOSTAPD_LEVEL_DEBUG, "could not add " | |
792 | "dynamic VLAN interface for vlan_id=%d", | |
793 | sta->vlan_id); | |
794 | return -1; | |
795 | } | |
796 | ||
797 | iface = vlan->ifname; | |
798 | if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) { | |
799 | hostapd_logger(hapd, sta->addr, | |
800 | HOSTAPD_MODULE_IEEE80211, | |
801 | HOSTAPD_LEVEL_DEBUG, "could not " | |
802 | "configure encryption for dynamic VLAN " | |
803 | "interface for vlan_id=%d", | |
804 | sta->vlan_id); | |
805 | } | |
806 | ||
807 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
808 | HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN " | |
809 | "interface '%s'", iface); | |
810 | } else if (vlan && vlan->vlan_id == sta->vlan_id) { | |
811 | if (sta->vlan_id > 0) { | |
812 | vlan->dynamic_vlan++; | |
813 | hostapd_logger(hapd, sta->addr, | |
814 | HOSTAPD_MODULE_IEEE80211, | |
815 | HOSTAPD_LEVEL_DEBUG, "updated existing " | |
816 | "dynamic VLAN interface '%s'", iface); | |
817 | } | |
818 | ||
819 | /* | |
820 | * Update encryption configuration for statically generated | |
821 | * VLAN interface. This is only used for static WEP | |
822 | * configuration for the case where hostapd did not yet know | |
823 | * which keys are to be used when the interface was added. | |
824 | */ | |
825 | if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) { | |
826 | hostapd_logger(hapd, sta->addr, | |
827 | HOSTAPD_MODULE_IEEE80211, | |
828 | HOSTAPD_LEVEL_DEBUG, "could not " | |
829 | "configure encryption for VLAN " | |
830 | "interface for vlan_id=%d", | |
831 | sta->vlan_id); | |
832 | } | |
833 | } | |
834 | ||
835 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
836 | HOSTAPD_LEVEL_DEBUG, "binding station to interface " | |
837 | "'%s'", iface); | |
838 | ||
839 | if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0) | |
840 | wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA"); | |
841 | ||
51e2a27a | 842 | ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id); |
4254100d JM |
843 | if (ret < 0) { |
844 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
845 | HOSTAPD_LEVEL_DEBUG, "could not bind the STA " | |
846 | "entry to vlan_id=%d", sta->vlan_id); | |
847 | } | |
848 | return ret; | |
30b32314 JM |
849 | #else /* CONFIG_NO_VLAN */ |
850 | return 0; | |
851 | #endif /* CONFIG_NO_VLAN */ | |
6fc6879b | 852 | } |
5d22a1d5 JM |
853 | |
854 | ||
855 | #ifdef CONFIG_IEEE80211W | |
856 | ||
45c94154 | 857 | int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta) |
5d22a1d5 | 858 | { |
45c94154 | 859 | u32 tu; |
10e694a6 JB |
860 | struct os_reltime now, passed; |
861 | os_get_reltime(&now); | |
862 | os_reltime_sub(&now, &sta->sa_query_start, &passed); | |
45c94154 JM |
863 | tu = (passed.sec * 1000000 + passed.usec) / 1024; |
864 | if (hapd->conf->assoc_sa_query_max_timeout < tu) { | |
865 | hostapd_logger(hapd, sta->addr, | |
866 | HOSTAPD_MODULE_IEEE80211, | |
5d22a1d5 | 867 | HOSTAPD_LEVEL_DEBUG, |
93b76319 JM |
868 | "association SA Query timed out"); |
869 | sta->sa_query_timed_out = 1; | |
870 | os_free(sta->sa_query_trans_id); | |
871 | sta->sa_query_trans_id = NULL; | |
872 | sta->sa_query_count = 0; | |
45c94154 JM |
873 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); |
874 | return 1; | |
5d22a1d5 JM |
875 | } |
876 | ||
45c94154 JM |
877 | return 0; |
878 | } | |
879 | ||
880 | ||
881 | static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx) | |
882 | { | |
883 | struct hostapd_data *hapd = eloop_ctx; | |
884 | struct sta_info *sta = timeout_ctx; | |
885 | unsigned int timeout, sec, usec; | |
886 | u8 *trans_id, *nbuf; | |
887 | ||
888 | if (sta->sa_query_count > 0 && | |
889 | ap_check_sa_query_timeout(hapd, sta)) | |
890 | return; | |
891 | ||
067ffa26 JM |
892 | nbuf = os_realloc_array(sta->sa_query_trans_id, |
893 | sta->sa_query_count + 1, | |
894 | WLAN_SA_QUERY_TR_ID_LEN); | |
5d22a1d5 JM |
895 | if (nbuf == NULL) |
896 | return; | |
45c94154 JM |
897 | if (sta->sa_query_count == 0) { |
898 | /* Starting a new SA Query procedure */ | |
10e694a6 | 899 | os_get_reltime(&sta->sa_query_start); |
45c94154 | 900 | } |
93b76319 JM |
901 | trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN; |
902 | sta->sa_query_trans_id = nbuf; | |
903 | sta->sa_query_count++; | |
5d22a1d5 | 904 | |
93b76319 | 905 | os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN); |
5d22a1d5 | 906 | |
45c94154 JM |
907 | timeout = hapd->conf->assoc_sa_query_retry_timeout; |
908 | sec = ((timeout / 1000) * 1024) / 1000; | |
909 | usec = (timeout % 1000) * 1024; | |
910 | eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta); | |
911 | ||
5d22a1d5 JM |
912 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
913 | HOSTAPD_LEVEL_DEBUG, | |
93b76319 | 914 | "association SA Query attempt %d", sta->sa_query_count); |
5d22a1d5 | 915 | |
93b76319 | 916 | ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id); |
5d22a1d5 JM |
917 | } |
918 | ||
919 | ||
93b76319 | 920 | void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta) |
5d22a1d5 | 921 | { |
93b76319 | 922 | ap_sa_query_timer(hapd, sta); |
5d22a1d5 JM |
923 | } |
924 | ||
925 | ||
93b76319 | 926 | void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta) |
5d22a1d5 | 927 | { |
93b76319 JM |
928 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); |
929 | os_free(sta->sa_query_trans_id); | |
930 | sta->sa_query_trans_id = NULL; | |
931 | sta->sa_query_count = 0; | |
5d22a1d5 JM |
932 | } |
933 | ||
934 | #endif /* CONFIG_IEEE80211W */ | |
45cefa0b JM |
935 | |
936 | ||
6905dcb1 JB |
937 | void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta, |
938 | int authorized) | |
939 | { | |
10cc6c88 | 940 | const u8 *dev_addr = NULL; |
7793c959 | 941 | char buf[100]; |
c2d76aa6 MH |
942 | #ifdef CONFIG_P2P |
943 | u8 addr[ETH_ALEN]; | |
25ef8529 | 944 | u8 ip_addr_buf[4]; |
c2d76aa6 MH |
945 | #endif /* CONFIG_P2P */ |
946 | ||
6905dcb1 JB |
947 | if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED)) |
948 | return; | |
949 | ||
ae055af4 | 950 | #ifdef CONFIG_P2P |
c2d76aa6 MH |
951 | if (hapd->p2p_group == NULL) { |
952 | if (sta->p2p_ie != NULL && | |
953 | p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0) | |
954 | dev_addr = addr; | |
955 | } else | |
956 | dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr); | |
ae055af4 | 957 | #endif /* CONFIG_P2P */ |
10cc6c88 | 958 | |
7793c959 JM |
959 | if (dev_addr) |
960 | os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR, | |
961 | MAC2STR(sta->addr), MAC2STR(dev_addr)); | |
962 | else | |
963 | os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr)); | |
964 | ||
10cc6c88 | 965 | if (authorized) { |
25ef8529 JM |
966 | char ip_addr[100]; |
967 | ip_addr[0] = '\0'; | |
968 | #ifdef CONFIG_P2P | |
969 | if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) { | |
970 | os_snprintf(ip_addr, sizeof(ip_addr), | |
971 | " ip_addr=%u.%u.%u.%u", | |
972 | ip_addr_buf[0], ip_addr_buf[1], | |
973 | ip_addr_buf[2], ip_addr_buf[3]); | |
974 | } | |
975 | #endif /* CONFIG_P2P */ | |
976 | ||
977 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s", | |
978 | buf, ip_addr); | |
7793c959 | 979 | |
8a5e75f6 | 980 | if (hapd->msg_ctx_parent && |
7793c959 | 981 | hapd->msg_ctx_parent != hapd->msg_ctx) |
c4bf83a7 | 982 | wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO, |
25ef8529 JM |
983 | AP_STA_CONNECTED "%s%s", |
984 | buf, ip_addr); | |
ae055af4 | 985 | |
6905dcb1 | 986 | sta->flags |= WLAN_STA_AUTHORIZED; |
ae055af4 | 987 | } else { |
7793c959 JM |
988 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf); |
989 | ||
8a5e75f6 | 990 | if (hapd->msg_ctx_parent && |
7793c959 | 991 | hapd->msg_ctx_parent != hapd->msg_ctx) |
c4bf83a7 JM |
992 | wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO, |
993 | AP_STA_DISCONNECTED "%s", buf); | |
7793c959 | 994 | |
6905dcb1 | 995 | sta->flags &= ~WLAN_STA_AUTHORIZED; |
ae055af4 | 996 | } |
0661eed2 JB |
997 | |
998 | if (hapd->sta_authorized_cb) | |
999 | hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx, | |
fbdcfd57 | 1000 | sta->addr, authorized, dev_addr); |
6905dcb1 JB |
1001 | } |
1002 | ||
1003 | ||
45cefa0b JM |
1004 | void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta, |
1005 | const u8 *addr, u16 reason) | |
1006 | { | |
1007 | ||
1008 | if (sta == NULL && addr) | |
1009 | sta = ap_get_sta(hapd, addr); | |
1010 | ||
1011 | if (addr) | |
51e2a27a | 1012 | hostapd_drv_sta_deauth(hapd, addr, reason); |
45cefa0b JM |
1013 | |
1014 | if (sta == NULL) | |
1015 | return; | |
6905dcb1 | 1016 | ap_sta_set_authorized(hapd, sta, 0); |
ceb997f3 JM |
1017 | wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH); |
1018 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
6905dcb1 | 1019 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); |
42ca9845 JM |
1020 | wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " |
1021 | "for " MACSTR " (%d seconds - " | |
1022 | "AP_MAX_INACTIVITY_AFTER_DEAUTH)", | |
1023 | __func__, MAC2STR(sta->addr), | |
1024 | AP_MAX_INACTIVITY_AFTER_DEAUTH); | |
45cefa0b | 1025 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
4dc03726 JM |
1026 | eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0, |
1027 | ap_handle_timer, hapd, sta); | |
45cefa0b | 1028 | sta->timeout_next = STA_REMOVE; |
4dc03726 JM |
1029 | |
1030 | sta->deauth_reason = reason; | |
cc28ad8c | 1031 | sta->flags |= WLAN_STA_PENDING_DEAUTH_CB; |
4dc03726 JM |
1032 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
1033 | eloop_register_timeout(hapd->iface->drv_flags & | |
1034 | WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0, | |
1035 | ap_sta_deauth_cb_timeout, hapd, sta); | |
1036 | } | |
1037 | ||
1038 | ||
1039 | void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta) | |
1040 | { | |
cc28ad8c JM |
1041 | if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) { |
1042 | wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame"); | |
1043 | return; | |
1044 | } | |
1045 | sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB; | |
4dc03726 JM |
1046 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
1047 | ap_sta_deauth_cb_timeout(hapd, sta); | |
1048 | } | |
1049 | ||
1050 | ||
1051 | void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta) | |
1052 | { | |
cc28ad8c JM |
1053 | if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) { |
1054 | wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame"); | |
1055 | return; | |
1056 | } | |
1057 | sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB; | |
1058 | eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta); | |
1059 | ap_sta_disassoc_cb_timeout(hapd, sta); | |
45cefa0b | 1060 | } |
b76f4c27 JM |
1061 | |
1062 | ||
1063 | int ap_sta_flags_txt(u32 flags, char *buf, size_t buflen) | |
1064 | { | |
1065 | int res; | |
1066 | ||
1067 | buf[0] = '\0'; | |
1068 | res = os_snprintf(buf, buflen, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", | |
1069 | (flags & WLAN_STA_AUTH ? "[AUTH]" : ""), | |
1070 | (flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""), | |
1071 | (flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : ""), | |
1072 | (flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" : | |
1073 | ""), | |
1074 | (flags & WLAN_STA_SHORT_PREAMBLE ? | |
1075 | "[SHORT_PREAMBLE]" : ""), | |
1076 | (flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""), | |
1077 | (flags & WLAN_STA_WMM ? "[WMM]" : ""), | |
1078 | (flags & WLAN_STA_MFP ? "[MFP]" : ""), | |
1079 | (flags & WLAN_STA_WPS ? "[WPS]" : ""), | |
1080 | (flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""), | |
1081 | (flags & WLAN_STA_WDS ? "[WDS]" : ""), | |
1082 | (flags & WLAN_STA_NONERP ? "[NonERP]" : ""), | |
1083 | (flags & WLAN_STA_WPS2 ? "[WPS2]" : ""), | |
1084 | (flags & WLAN_STA_GAS ? "[GAS]" : ""), | |
1085 | (flags & WLAN_STA_VHT ? "[VHT]" : ""), | |
1086 | (flags & WLAN_STA_WNM_SLEEP_MODE ? | |
1087 | "[WNM_SLEEP_MODE]" : "")); | |
1088 | ||
1089 | return res; | |
1090 | } |