]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * hostapd / Station table | |
bdee6fce | 3 | * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi> |
6fc6879b JM |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License version 2 as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * Alternatively, this software may be distributed under the terms of BSD | |
10 | * license. | |
11 | * | |
12 | * See README and COPYING for more details. | |
13 | */ | |
14 | ||
6226e38d | 15 | #include "utils/includes.h" |
6fc6879b | 16 | |
6226e38d JM |
17 | #include "utils/common.h" |
18 | #include "utils/eloop.h" | |
81f4f619 | 19 | #include "common/ieee802_11_defs.h" |
bdee6fce JM |
20 | #include "radius/radius.h" |
21 | #include "radius/radius_client.h" | |
22 | #include "drivers/driver.h" | |
8ccbe415 | 23 | #include "p2p/p2p.h" |
6fc6879b | 24 | #include "hostapd.h" |
6fc6879b JM |
25 | #include "accounting.h" |
26 | #include "ieee802_1x.h" | |
27 | #include "ieee802_11.h" | |
6226e38d JM |
28 | #include "wpa_auth.h" |
29 | #include "preauth_auth.h" | |
30 | #include "ap_config.h" | |
6fc6879b | 31 | #include "beacon.h" |
6226e38d | 32 | #include "ap_mlme.h" |
6fc6879b | 33 | #include "vlan_init.h" |
aefb53bd | 34 | #include "p2p_hostapd.h" |
cee7d66b | 35 | #include "ap_drv_ops.h" |
6226e38d | 36 | #include "sta_info.h" |
6fc6879b | 37 | |
53f3d6f3 FF |
38 | static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd, |
39 | struct sta_info *sta); | |
6fc6879b | 40 | static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx); |
5d22a1d5 | 41 | #ifdef CONFIG_IEEE80211W |
93b76319 | 42 | static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx); |
5d22a1d5 | 43 | #endif /* CONFIG_IEEE80211W */ |
6fc6879b JM |
44 | |
45 | int ap_for_each_sta(struct hostapd_data *hapd, | |
46 | int (*cb)(struct hostapd_data *hapd, struct sta_info *sta, | |
47 | void *ctx), | |
48 | void *ctx) | |
49 | { | |
50 | struct sta_info *sta; | |
51 | ||
52 | for (sta = hapd->sta_list; sta; sta = sta->next) { | |
53 | if (cb(hapd, sta, ctx)) | |
54 | return 1; | |
55 | } | |
56 | ||
57 | return 0; | |
58 | } | |
59 | ||
60 | ||
61 | struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta) | |
62 | { | |
63 | struct sta_info *s; | |
64 | ||
65 | s = hapd->sta_hash[STA_HASH(sta)]; | |
66 | while (s != NULL && os_memcmp(s->addr, sta, 6) != 0) | |
67 | s = s->hnext; | |
68 | return s; | |
69 | } | |
70 | ||
71 | ||
72 | static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta) | |
73 | { | |
74 | struct sta_info *tmp; | |
75 | ||
76 | if (hapd->sta_list == sta) { | |
77 | hapd->sta_list = sta->next; | |
78 | return; | |
79 | } | |
80 | ||
81 | tmp = hapd->sta_list; | |
82 | while (tmp != NULL && tmp->next != sta) | |
83 | tmp = tmp->next; | |
84 | if (tmp == NULL) { | |
85 | wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from " | |
86 | "list.", MAC2STR(sta->addr)); | |
87 | } else | |
88 | tmp->next = sta->next; | |
89 | } | |
90 | ||
91 | ||
92 | void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta) | |
93 | { | |
94 | sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)]; | |
95 | hapd->sta_hash[STA_HASH(sta->addr)] = sta; | |
96 | } | |
97 | ||
98 | ||
99 | static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta) | |
100 | { | |
101 | struct sta_info *s; | |
102 | ||
103 | s = hapd->sta_hash[STA_HASH(sta->addr)]; | |
104 | if (s == NULL) return; | |
105 | if (os_memcmp(s->addr, sta->addr, 6) == 0) { | |
106 | hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext; | |
107 | return; | |
108 | } | |
109 | ||
110 | while (s->hnext != NULL && | |
111 | os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0) | |
112 | s = s->hnext; | |
113 | if (s->hnext != NULL) | |
114 | s->hnext = s->hnext->hnext; | |
115 | else | |
116 | wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR | |
117 | " from hash table", MAC2STR(sta->addr)); | |
118 | } | |
119 | ||
120 | ||
121 | void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta) | |
122 | { | |
123 | int set_beacon = 0; | |
124 | ||
125 | accounting_sta_stop(hapd, sta); | |
126 | ||
6905dcb1 JB |
127 | /* just in case */ |
128 | ap_sta_set_authorized(hapd, sta, 0); | |
129 | ||
39f42d11 | 130 | if (sta->flags & WLAN_STA_WDS) |
0e8a96a9 | 131 | hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 0); |
53f3d6f3 FF |
132 | |
133 | if (!(sta->flags & WLAN_STA_PREAUTH)) | |
51e2a27a | 134 | hostapd_drv_sta_remove(hapd, sta->addr); |
6fc6879b JM |
135 | |
136 | ap_sta_hash_del(hapd, sta); | |
137 | ap_sta_list_del(hapd, sta); | |
138 | ||
139 | if (sta->aid > 0) | |
2991469c JM |
140 | hapd->sta_aid[(sta->aid - 1) / 32] &= |
141 | ~BIT((sta->aid - 1) % 32); | |
6fc6879b JM |
142 | |
143 | hapd->num_sta--; | |
144 | if (sta->nonerp_set) { | |
145 | sta->nonerp_set = 0; | |
146 | hapd->iface->num_sta_non_erp--; | |
147 | if (hapd->iface->num_sta_non_erp == 0) | |
148 | set_beacon++; | |
149 | } | |
150 | ||
151 | if (sta->no_short_slot_time_set) { | |
152 | sta->no_short_slot_time_set = 0; | |
153 | hapd->iface->num_sta_no_short_slot_time--; | |
154 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G | |
155 | && hapd->iface->num_sta_no_short_slot_time == 0) | |
156 | set_beacon++; | |
157 | } | |
158 | ||
159 | if (sta->no_short_preamble_set) { | |
160 | sta->no_short_preamble_set = 0; | |
161 | hapd->iface->num_sta_no_short_preamble--; | |
162 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G | |
163 | && hapd->iface->num_sta_no_short_preamble == 0) | |
164 | set_beacon++; | |
165 | } | |
166 | ||
e8ff1e59 JM |
167 | if (sta->no_ht_gf_set) { |
168 | sta->no_ht_gf_set = 0; | |
169 | hapd->iface->num_sta_ht_no_gf--; | |
170 | } | |
171 | ||
172 | if (sta->no_ht_set) { | |
173 | sta->no_ht_set = 0; | |
de9289c8 | 174 | hapd->iface->num_sta_no_ht--; |
e8ff1e59 JM |
175 | } |
176 | ||
177 | if (sta->ht_20mhz_set) { | |
178 | sta->ht_20mhz_set = 0; | |
179 | hapd->iface->num_sta_ht_20mhz--; | |
180 | } | |
de9289c8 | 181 | |
aefb53bd JM |
182 | #ifdef CONFIG_P2P |
183 | if (sta->no_p2p_set) { | |
184 | sta->no_p2p_set = 0; | |
185 | hapd->num_sta_no_p2p--; | |
186 | if (hapd->num_sta_no_p2p == 0) | |
187 | hostapd_p2p_non_p2p_sta_disconnected(hapd); | |
188 | } | |
189 | #endif /* CONFIG_P2P */ | |
190 | ||
d45354be | 191 | #if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N) |
de9289c8 JM |
192 | if (hostapd_ht_operation_update(hapd->iface) > 0) |
193 | set_beacon++; | |
d45354be | 194 | #endif /* NEED_AP_MLME && CONFIG_IEEE80211N */ |
de9289c8 | 195 | |
6fc6879b JM |
196 | if (set_beacon) |
197 | ieee802_11_set_beacons(hapd->iface); | |
198 | ||
199 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); | |
200 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); | |
201 | ||
202 | ieee802_1x_free_station(sta); | |
203 | wpa_auth_sta_deinit(sta->wpa_sm); | |
204 | rsn_preauth_free_station(hapd, sta); | |
74784010 | 205 | #ifndef CONFIG_NO_RADIUS |
6fc6879b | 206 | radius_client_flush_auth(hapd->radius, sta->addr); |
74784010 | 207 | #endif /* CONFIG_NO_RADIUS */ |
6fc6879b JM |
208 | |
209 | os_free(sta->last_assoc_req); | |
210 | os_free(sta->challenge); | |
5d22a1d5 JM |
211 | |
212 | #ifdef CONFIG_IEEE80211W | |
93b76319 JM |
213 | os_free(sta->sa_query_trans_id); |
214 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); | |
5d22a1d5 JM |
215 | #endif /* CONFIG_IEEE80211W */ |
216 | ||
8ccbe415 JM |
217 | #ifdef CONFIG_P2P |
218 | p2p_group_notif_disassoc(hapd->p2p_group, sta->addr); | |
219 | #endif /* CONFIG_P2P */ | |
220 | ||
eb76b7e3 | 221 | wpabuf_free(sta->wps_ie); |
b305c684 | 222 | wpabuf_free(sta->p2p_ie); |
eb76b7e3 | 223 | |
df84268a JM |
224 | os_free(sta->ht_capabilities); |
225 | ||
6fc6879b JM |
226 | os_free(sta); |
227 | } | |
228 | ||
229 | ||
230 | void hostapd_free_stas(struct hostapd_data *hapd) | |
231 | { | |
232 | struct sta_info *sta, *prev; | |
233 | ||
234 | sta = hapd->sta_list; | |
235 | ||
236 | while (sta) { | |
237 | prev = sta; | |
238 | if (sta->flags & WLAN_STA_AUTH) { | |
239 | mlme_deauthenticate_indication( | |
240 | hapd, sta, WLAN_REASON_UNSPECIFIED); | |
241 | } | |
242 | sta = sta->next; | |
243 | wpa_printf(MSG_DEBUG, "Removing station " MACSTR, | |
244 | MAC2STR(prev->addr)); | |
245 | ap_free_sta(hapd, prev); | |
246 | } | |
247 | } | |
248 | ||
249 | ||
1c6e69cc JM |
250 | /** |
251 | * ap_handle_timer - Per STA timer handler | |
252 | * @eloop_ctx: struct hostapd_data * | |
253 | * @timeout_ctx: struct sta_info * | |
254 | * | |
255 | * This function is called to check station activity and to remove inactive | |
256 | * stations. | |
257 | */ | |
6fc6879b JM |
258 | void ap_handle_timer(void *eloop_ctx, void *timeout_ctx) |
259 | { | |
260 | struct hostapd_data *hapd = eloop_ctx; | |
261 | struct sta_info *sta = timeout_ctx; | |
262 | unsigned long next_time = 0; | |
263 | ||
264 | if (sta->timeout_next == STA_REMOVE) { | |
265 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
266 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " | |
267 | "local deauth request"); | |
268 | ap_free_sta(hapd, sta); | |
269 | return; | |
270 | } | |
271 | ||
272 | if ((sta->flags & WLAN_STA_ASSOC) && | |
273 | (sta->timeout_next == STA_NULLFUNC || | |
274 | sta->timeout_next == STA_DISASSOC)) { | |
275 | int inactive_sec; | |
276 | wpa_printf(MSG_DEBUG, "Checking STA " MACSTR " inactivity:", | |
277 | MAC2STR(sta->addr)); | |
51e2a27a | 278 | inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr); |
6fc6879b JM |
279 | if (inactive_sec == -1) { |
280 | wpa_printf(MSG_DEBUG, "Could not get station info " | |
281 | "from kernel driver for " MACSTR ".", | |
282 | MAC2STR(sta->addr)); | |
283 | } else if (inactive_sec < hapd->conf->ap_max_inactivity && | |
284 | sta->flags & WLAN_STA_ASSOC) { | |
285 | /* station activity detected; reset timeout state */ | |
286 | wpa_printf(MSG_DEBUG, " Station has been active"); | |
287 | sta->timeout_next = STA_NULLFUNC; | |
288 | next_time = hapd->conf->ap_max_inactivity - | |
289 | inactive_sec; | |
290 | } | |
291 | } | |
292 | ||
293 | if ((sta->flags & WLAN_STA_ASSOC) && | |
294 | sta->timeout_next == STA_DISASSOC && | |
295 | !(sta->flags & WLAN_STA_PENDING_POLL)) { | |
296 | wpa_printf(MSG_DEBUG, " Station has ACKed data poll"); | |
297 | /* data nullfunc frame poll did not produce TX errors; assume | |
298 | * station ACKed it */ | |
299 | sta->timeout_next = STA_NULLFUNC; | |
300 | next_time = hapd->conf->ap_max_inactivity; | |
301 | } | |
302 | ||
303 | if (next_time) { | |
304 | eloop_register_timeout(next_time, 0, ap_handle_timer, hapd, | |
305 | sta); | |
306 | return; | |
307 | } | |
308 | ||
309 | if (sta->timeout_next == STA_NULLFUNC && | |
310 | (sta->flags & WLAN_STA_ASSOC)) { | |
08230317 | 311 | #ifndef CONFIG_NATIVE_WINDOWS |
6fc6879b JM |
312 | /* send data frame to poll STA and check whether this frame |
313 | * is ACKed */ | |
314 | struct ieee80211_hdr hdr; | |
315 | ||
316 | wpa_printf(MSG_DEBUG, " Polling STA with data frame"); | |
317 | sta->flags |= WLAN_STA_PENDING_POLL; | |
318 | ||
6fc6879b | 319 | os_memset(&hdr, 0, sizeof(hdr)); |
1e145265 JM |
320 | if (hapd->driver && |
321 | os_strcmp(hapd->driver->name, "hostap") == 0) { | |
322 | /* | |
323 | * WLAN_FC_STYPE_NULLFUNC would be more appropriate, | |
324 | * but it is apparently not retried so TX Exc events | |
325 | * are not received for it. | |
326 | */ | |
327 | hdr.frame_control = | |
328 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
329 | WLAN_FC_STYPE_DATA); | |
330 | } else { | |
331 | hdr.frame_control = | |
332 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
333 | WLAN_FC_STYPE_NULLFUNC); | |
334 | } | |
335 | ||
6fc6879b JM |
336 | hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
337 | os_memcpy(hdr.IEEE80211_DA_FROMDS, sta->addr, ETH_ALEN); | |
338 | os_memcpy(hdr.IEEE80211_BSSID_FROMDS, hapd->own_addr, | |
339 | ETH_ALEN); | |
340 | os_memcpy(hdr.IEEE80211_SA_FROMDS, hapd->own_addr, ETH_ALEN); | |
341 | ||
cee7d66b | 342 | if (hostapd_drv_send_mlme(hapd, &hdr, sizeof(hdr)) < 0) |
6fc6879b JM |
343 | perror("ap_handle_timer: send"); |
344 | #endif /* CONFIG_NATIVE_WINDOWS */ | |
345 | } else if (sta->timeout_next != STA_REMOVE) { | |
346 | int deauth = sta->timeout_next == STA_DEAUTH; | |
347 | ||
348 | wpa_printf(MSG_DEBUG, "Sending %s info to STA " MACSTR, | |
349 | deauth ? "deauthentication" : "disassociation", | |
350 | MAC2STR(sta->addr)); | |
351 | ||
352 | if (deauth) { | |
51e2a27a JM |
353 | hostapd_drv_sta_deauth( |
354 | hapd, sta->addr, | |
355 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
6fc6879b | 356 | } else { |
51e2a27a | 357 | hostapd_drv_sta_disassoc( |
6fc6879b JM |
358 | hapd, sta->addr, |
359 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); | |
360 | } | |
361 | } | |
362 | ||
363 | switch (sta->timeout_next) { | |
364 | case STA_NULLFUNC: | |
365 | sta->timeout_next = STA_DISASSOC; | |
366 | eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer, | |
367 | hapd, sta); | |
368 | break; | |
369 | case STA_DISASSOC: | |
370 | sta->flags &= ~WLAN_STA_ASSOC; | |
371 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
372 | if (!sta->acct_terminate_cause) | |
373 | sta->acct_terminate_cause = | |
374 | RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT; | |
375 | accounting_sta_stop(hapd, sta); | |
376 | ieee802_1x_free_station(sta); | |
377 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
378 | HOSTAPD_LEVEL_INFO, "disassociated due to " | |
379 | "inactivity"); | |
380 | sta->timeout_next = STA_DEAUTH; | |
381 | eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer, | |
382 | hapd, sta); | |
383 | mlme_disassociate_indication( | |
384 | hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); | |
385 | break; | |
386 | case STA_DEAUTH: | |
387 | case STA_REMOVE: | |
388 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
389 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " | |
390 | "inactivity"); | |
391 | if (!sta->acct_terminate_cause) | |
392 | sta->acct_terminate_cause = | |
393 | RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT; | |
394 | mlme_deauthenticate_indication( | |
395 | hapd, sta, | |
396 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
397 | ap_free_sta(hapd, sta); | |
398 | break; | |
399 | } | |
400 | } | |
401 | ||
402 | ||
403 | static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx) | |
404 | { | |
405 | struct hostapd_data *hapd = eloop_ctx; | |
406 | struct sta_info *sta = timeout_ctx; | |
407 | u8 addr[ETH_ALEN]; | |
408 | ||
409 | if (!(sta->flags & WLAN_STA_AUTH)) | |
410 | return; | |
411 | ||
412 | mlme_deauthenticate_indication(hapd, sta, | |
413 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
414 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
415 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " | |
416 | "session timeout"); | |
417 | sta->acct_terminate_cause = | |
418 | RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT; | |
419 | os_memcpy(addr, sta->addr, ETH_ALEN); | |
420 | ap_free_sta(hapd, sta); | |
51e2a27a | 421 | hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID); |
6fc6879b JM |
422 | } |
423 | ||
424 | ||
425 | void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta, | |
426 | u32 session_timeout) | |
427 | { | |
428 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
429 | HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d " | |
430 | "seconds", session_timeout); | |
431 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); | |
432 | eloop_register_timeout(session_timeout, 0, ap_handle_session_timer, | |
433 | hapd, sta); | |
434 | } | |
435 | ||
436 | ||
437 | void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta) | |
438 | { | |
439 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); | |
440 | } | |
441 | ||
442 | ||
443 | struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr) | |
444 | { | |
445 | struct sta_info *sta; | |
446 | ||
447 | sta = ap_get_sta(hapd, addr); | |
448 | if (sta) | |
449 | return sta; | |
450 | ||
451 | wpa_printf(MSG_DEBUG, " New STA"); | |
452 | if (hapd->num_sta >= hapd->conf->max_num_sta) { | |
453 | /* FIX: might try to remove some old STAs first? */ | |
454 | wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)", | |
455 | hapd->num_sta, hapd->conf->max_num_sta); | |
456 | return NULL; | |
457 | } | |
458 | ||
459 | sta = os_zalloc(sizeof(struct sta_info)); | |
460 | if (sta == NULL) { | |
461 | wpa_printf(MSG_ERROR, "malloc failed"); | |
462 | return NULL; | |
463 | } | |
5843e1c9 | 464 | sta->acct_interim_interval = hapd->conf->acct_interim_interval; |
6fc6879b JM |
465 | |
466 | /* initialize STA info data */ | |
467 | eloop_register_timeout(hapd->conf->ap_max_inactivity, 0, | |
468 | ap_handle_timer, hapd, sta); | |
469 | os_memcpy(sta->addr, addr, ETH_ALEN); | |
470 | sta->next = hapd->sta_list; | |
471 | hapd->sta_list = sta; | |
472 | hapd->num_sta++; | |
473 | ap_sta_hash_add(hapd, sta); | |
474 | sta->ssid = &hapd->conf->ssid; | |
53f3d6f3 | 475 | ap_sta_remove_in_other_bss(hapd, sta); |
6fc6879b JM |
476 | |
477 | return sta; | |
478 | } | |
479 | ||
480 | ||
481 | static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta) | |
482 | { | |
483 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
484 | ||
485 | wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver", | |
486 | MAC2STR(sta->addr)); | |
51e2a27a | 487 | if (hostapd_drv_sta_remove(hapd, sta->addr) && |
6fc6879b JM |
488 | sta->flags & WLAN_STA_ASSOC) { |
489 | wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR | |
490 | " from kernel driver.", MAC2STR(sta->addr)); | |
491 | return -1; | |
492 | } | |
493 | return 0; | |
494 | } | |
495 | ||
496 | ||
53f3d6f3 FF |
497 | static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd, |
498 | struct sta_info *sta) | |
6fc6879b JM |
499 | { |
500 | struct hostapd_iface *iface = hapd->iface; | |
501 | size_t i; | |
502 | ||
503 | for (i = 0; i < iface->num_bss; i++) { | |
504 | struct hostapd_data *bss = iface->bss[i]; | |
505 | struct sta_info *sta2; | |
506 | /* bss should always be set during operation, but it may be | |
507 | * NULL during reconfiguration. Assume the STA is not | |
508 | * associated to another BSS in that case to avoid NULL pointer | |
509 | * dereferences. */ | |
510 | if (bss == hapd || bss == NULL) | |
511 | continue; | |
512 | sta2 = ap_get_sta(bss, sta->addr); | |
53f3d6f3 FF |
513 | if (!sta2) |
514 | continue; | |
6fc6879b | 515 | |
53f3d6f3 FF |
516 | ap_sta_disconnect(bss, sta2, sta2->addr, |
517 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
518 | } | |
6fc6879b JM |
519 | } |
520 | ||
521 | ||
522 | void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta, | |
523 | u16 reason) | |
524 | { | |
525 | wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR, | |
526 | hapd->conf->iface, MAC2STR(sta->addr)); | |
527 | sta->flags &= ~WLAN_STA_ASSOC; | |
53f3d6f3 | 528 | ap_sta_remove(hapd, sta); |
6fc6879b JM |
529 | sta->timeout_next = STA_DEAUTH; |
530 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); | |
531 | eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0, | |
532 | ap_handle_timer, hapd, sta); | |
533 | accounting_sta_stop(hapd, sta); | |
534 | ieee802_1x_free_station(sta); | |
535 | ||
536 | mlme_disassociate_indication(hapd, sta, reason); | |
537 | } | |
538 | ||
539 | ||
540 | void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta, | |
541 | u16 reason) | |
542 | { | |
543 | wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR, | |
544 | hapd->conf->iface, MAC2STR(sta->addr)); | |
545 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); | |
53f3d6f3 | 546 | ap_sta_remove(hapd, sta); |
6fc6879b JM |
547 | sta->timeout_next = STA_REMOVE; |
548 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); | |
549 | eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0, | |
550 | ap_handle_timer, hapd, sta); | |
551 | accounting_sta_stop(hapd, sta); | |
552 | ieee802_1x_free_station(sta); | |
553 | ||
554 | mlme_deauthenticate_indication(hapd, sta, reason); | |
555 | } | |
556 | ||
557 | ||
558 | int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta, | |
559 | int old_vlanid) | |
560 | { | |
30b32314 | 561 | #ifndef CONFIG_NO_VLAN |
6fc6879b JM |
562 | const char *iface; |
563 | struct hostapd_vlan *vlan = NULL; | |
4254100d | 564 | int ret; |
6fc6879b JM |
565 | |
566 | /* | |
567 | * Do not proceed furthur if the vlan id remains same. We do not want | |
568 | * duplicate dynamic vlan entries. | |
569 | */ | |
570 | if (sta->vlan_id == old_vlanid) | |
571 | return 0; | |
572 | ||
573 | /* | |
574 | * During 1x reauth, if the vlan id changes, then remove the old id and | |
575 | * proceed furthur to add the new one. | |
576 | */ | |
577 | if (old_vlanid > 0) | |
578 | vlan_remove_dynamic(hapd, old_vlanid); | |
579 | ||
580 | iface = hapd->conf->iface; | |
581 | if (sta->ssid->vlan[0]) | |
582 | iface = sta->ssid->vlan; | |
583 | ||
584 | if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED) | |
585 | sta->vlan_id = 0; | |
586 | else if (sta->vlan_id > 0) { | |
587 | vlan = hapd->conf->vlan; | |
588 | while (vlan) { | |
589 | if (vlan->vlan_id == sta->vlan_id || | |
590 | vlan->vlan_id == VLAN_ID_WILDCARD) { | |
591 | iface = vlan->ifname; | |
592 | break; | |
593 | } | |
594 | vlan = vlan->next; | |
595 | } | |
596 | } | |
597 | ||
598 | if (sta->vlan_id > 0 && vlan == NULL) { | |
599 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
600 | HOSTAPD_LEVEL_DEBUG, "could not find VLAN for " | |
601 | "binding station to (vlan_id=%d)", | |
602 | sta->vlan_id); | |
603 | return -1; | |
604 | } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) { | |
605 | vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id); | |
606 | if (vlan == NULL) { | |
607 | hostapd_logger(hapd, sta->addr, | |
608 | HOSTAPD_MODULE_IEEE80211, | |
609 | HOSTAPD_LEVEL_DEBUG, "could not add " | |
610 | "dynamic VLAN interface for vlan_id=%d", | |
611 | sta->vlan_id); | |
612 | return -1; | |
613 | } | |
614 | ||
615 | iface = vlan->ifname; | |
616 | if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) { | |
617 | hostapd_logger(hapd, sta->addr, | |
618 | HOSTAPD_MODULE_IEEE80211, | |
619 | HOSTAPD_LEVEL_DEBUG, "could not " | |
620 | "configure encryption for dynamic VLAN " | |
621 | "interface for vlan_id=%d", | |
622 | sta->vlan_id); | |
623 | } | |
624 | ||
625 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
626 | HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN " | |
627 | "interface '%s'", iface); | |
628 | } else if (vlan && vlan->vlan_id == sta->vlan_id) { | |
629 | if (sta->vlan_id > 0) { | |
630 | vlan->dynamic_vlan++; | |
631 | hostapd_logger(hapd, sta->addr, | |
632 | HOSTAPD_MODULE_IEEE80211, | |
633 | HOSTAPD_LEVEL_DEBUG, "updated existing " | |
634 | "dynamic VLAN interface '%s'", iface); | |
635 | } | |
636 | ||
637 | /* | |
638 | * Update encryption configuration for statically generated | |
639 | * VLAN interface. This is only used for static WEP | |
640 | * configuration for the case where hostapd did not yet know | |
641 | * which keys are to be used when the interface was added. | |
642 | */ | |
643 | if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) { | |
644 | hostapd_logger(hapd, sta->addr, | |
645 | HOSTAPD_MODULE_IEEE80211, | |
646 | HOSTAPD_LEVEL_DEBUG, "could not " | |
647 | "configure encryption for VLAN " | |
648 | "interface for vlan_id=%d", | |
649 | sta->vlan_id); | |
650 | } | |
651 | } | |
652 | ||
653 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
654 | HOSTAPD_LEVEL_DEBUG, "binding station to interface " | |
655 | "'%s'", iface); | |
656 | ||
657 | if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0) | |
658 | wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA"); | |
659 | ||
51e2a27a | 660 | ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id); |
4254100d JM |
661 | if (ret < 0) { |
662 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
663 | HOSTAPD_LEVEL_DEBUG, "could not bind the STA " | |
664 | "entry to vlan_id=%d", sta->vlan_id); | |
665 | } | |
666 | return ret; | |
30b32314 JM |
667 | #else /* CONFIG_NO_VLAN */ |
668 | return 0; | |
669 | #endif /* CONFIG_NO_VLAN */ | |
6fc6879b | 670 | } |
5d22a1d5 JM |
671 | |
672 | ||
673 | #ifdef CONFIG_IEEE80211W | |
674 | ||
45c94154 | 675 | int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta) |
5d22a1d5 | 676 | { |
45c94154 JM |
677 | u32 tu; |
678 | struct os_time now, passed; | |
679 | os_get_time(&now); | |
680 | os_time_sub(&now, &sta->sa_query_start, &passed); | |
681 | tu = (passed.sec * 1000000 + passed.usec) / 1024; | |
682 | if (hapd->conf->assoc_sa_query_max_timeout < tu) { | |
683 | hostapd_logger(hapd, sta->addr, | |
684 | HOSTAPD_MODULE_IEEE80211, | |
5d22a1d5 | 685 | HOSTAPD_LEVEL_DEBUG, |
93b76319 JM |
686 | "association SA Query timed out"); |
687 | sta->sa_query_timed_out = 1; | |
688 | os_free(sta->sa_query_trans_id); | |
689 | sta->sa_query_trans_id = NULL; | |
690 | sta->sa_query_count = 0; | |
45c94154 JM |
691 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); |
692 | return 1; | |
5d22a1d5 JM |
693 | } |
694 | ||
45c94154 JM |
695 | return 0; |
696 | } | |
697 | ||
698 | ||
699 | static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx) | |
700 | { | |
701 | struct hostapd_data *hapd = eloop_ctx; | |
702 | struct sta_info *sta = timeout_ctx; | |
703 | unsigned int timeout, sec, usec; | |
704 | u8 *trans_id, *nbuf; | |
705 | ||
706 | if (sta->sa_query_count > 0 && | |
707 | ap_check_sa_query_timeout(hapd, sta)) | |
708 | return; | |
709 | ||
93b76319 JM |
710 | nbuf = os_realloc(sta->sa_query_trans_id, |
711 | (sta->sa_query_count + 1) * WLAN_SA_QUERY_TR_ID_LEN); | |
5d22a1d5 JM |
712 | if (nbuf == NULL) |
713 | return; | |
45c94154 JM |
714 | if (sta->sa_query_count == 0) { |
715 | /* Starting a new SA Query procedure */ | |
716 | os_get_time(&sta->sa_query_start); | |
717 | } | |
93b76319 JM |
718 | trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN; |
719 | sta->sa_query_trans_id = nbuf; | |
720 | sta->sa_query_count++; | |
5d22a1d5 | 721 | |
93b76319 | 722 | os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN); |
5d22a1d5 | 723 | |
45c94154 JM |
724 | timeout = hapd->conf->assoc_sa_query_retry_timeout; |
725 | sec = ((timeout / 1000) * 1024) / 1000; | |
726 | usec = (timeout % 1000) * 1024; | |
727 | eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta); | |
728 | ||
5d22a1d5 JM |
729 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
730 | HOSTAPD_LEVEL_DEBUG, | |
93b76319 | 731 | "association SA Query attempt %d", sta->sa_query_count); |
5d22a1d5 | 732 | |
fe6bdb77 | 733 | #ifdef NEED_AP_MLME |
93b76319 | 734 | ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id); |
fe6bdb77 | 735 | #endif /* NEED_AP_MLME */ |
5d22a1d5 JM |
736 | } |
737 | ||
738 | ||
93b76319 | 739 | void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta) |
5d22a1d5 | 740 | { |
93b76319 | 741 | ap_sa_query_timer(hapd, sta); |
5d22a1d5 JM |
742 | } |
743 | ||
744 | ||
93b76319 | 745 | void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta) |
5d22a1d5 | 746 | { |
93b76319 JM |
747 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); |
748 | os_free(sta->sa_query_trans_id); | |
749 | sta->sa_query_trans_id = NULL; | |
750 | sta->sa_query_count = 0; | |
5d22a1d5 JM |
751 | } |
752 | ||
753 | #endif /* CONFIG_IEEE80211W */ | |
45cefa0b JM |
754 | |
755 | ||
6905dcb1 JB |
756 | void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta, |
757 | int authorized) | |
758 | { | |
759 | if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED)) | |
760 | return; | |
761 | ||
762 | if (authorized) | |
763 | sta->flags |= WLAN_STA_AUTHORIZED; | |
764 | else | |
765 | sta->flags &= ~WLAN_STA_AUTHORIZED; | |
0661eed2 JB |
766 | |
767 | if (hapd->sta_authorized_cb) | |
768 | hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx, | |
769 | sta->addr, authorized); | |
6905dcb1 JB |
770 | } |
771 | ||
772 | ||
45cefa0b JM |
773 | void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta, |
774 | const u8 *addr, u16 reason) | |
775 | { | |
776 | ||
777 | if (sta == NULL && addr) | |
778 | sta = ap_get_sta(hapd, addr); | |
779 | ||
780 | if (addr) | |
51e2a27a | 781 | hostapd_drv_sta_deauth(hapd, addr, reason); |
45cefa0b JM |
782 | |
783 | if (sta == NULL) | |
784 | return; | |
6905dcb1 JB |
785 | ap_sta_set_authorized(hapd, sta, 0); |
786 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); | |
45cefa0b JM |
787 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
788 | eloop_register_timeout(0, 0, ap_handle_timer, hapd, sta); | |
789 | sta->timeout_next = STA_REMOVE; | |
790 | } |