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