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