2 * hostapd / Callback functions for driver wrappers
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
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.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
19 #include "ieee802_11.h"
20 #include "radius/radius.h"
22 #include "accounting.h"
23 #include "tkip_countermeasures.h"
24 #include "ieee802_1x.h"
31 struct hostapd_data
*hapd
;
35 static int prune_associations(struct hostapd_iface
*iface
, void *ctx
)
37 struct prune_data
*data
= ctx
;
38 struct sta_info
*osta
;
39 struct hostapd_data
*ohapd
;
42 for (j
= 0; j
< iface
->num_bss
; j
++) {
43 ohapd
= iface
->bss
[j
];
44 if (ohapd
== data
->hapd
)
46 osta
= ap_get_sta(ohapd
, data
->addr
);
50 ap_sta_disassociate(ohapd
, osta
, WLAN_REASON_UNSPECIFIED
);
57 * hostapd_prune_associations - Remove extraneous associations
58 * @hapd: Pointer to BSS data for the most recent association
59 * @sta: Pointer to the associated STA data
61 * This function looks through all radios and BSS's for previous
62 * (stale) associations of STA. If any are found they are removed.
64 static void hostapd_prune_associations(struct hostapd_data
*hapd
,
67 struct prune_data data
;
69 data
.addr
= sta
->addr
;
70 hostapd_for_each_interface(prune_associations
, &data
);
75 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
76 * @hapd: Pointer to BSS data
77 * @sta: Pointer to the associated STA data
78 * @reassoc: 1 to indicate this was a re-association; 0 = first association
80 * This function will be called whenever a station associates with the AP. It
81 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
82 * from driver_*.c for drivers that take care of management frames (IEEE 802.11
83 * authentication and association) internally.
85 void hostapd_new_assoc_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
88 if (hapd
->tkip_countermeasures
) {
89 hostapd_sta_deauth(hapd
, sta
->addr
,
90 WLAN_REASON_MICHAEL_MIC_FAILURE
);
94 hostapd_prune_associations(hapd
, sta
);
96 /* IEEE 802.11F (IAPP) */
97 if (hapd
->conf
->ieee802_11f
)
98 iapp_new_station(hapd
->iapp
, sta
);
100 /* Start accounting here, if IEEE 802.1X and WPA are not used.
101 * IEEE 802.1X/WPA code will start accounting after the station has
102 * been authorized. */
103 if (!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
)
104 accounting_sta_start(hapd
, sta
);
106 hostapd_wmm_sta_config(hapd
, sta
);
108 /* Start IEEE 802.1X authentication process for new stations */
109 ieee802_1x_new_station(hapd
, sta
);
111 if (sta
->auth_alg
!= WLAN_AUTH_FT
&&
112 !(sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
)))
113 wpa_auth_sm_event(sta
->wpa_sm
, WPA_REAUTH
);
115 wpa_auth_sta_associated(hapd
->wpa_auth
, sta
->wpa_sm
);
119 void hostapd_tx_status(struct hostapd_data
*hapd
, const u8
*addr
,
120 const u8
*buf
, size_t len
, int ack
)
122 struct sta_info
*sta
;
124 sta
= ap_get_sta(hapd
, addr
);
125 if (sta
&& sta
->flags
& WLAN_STA_PENDING_POLL
) {
126 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" %s pending "
127 "activity poll", MAC2STR(sta
->addr
),
128 ack
? "ACKed" : "did not ACK");
130 sta
->flags
&= ~WLAN_STA_PENDING_POLL
;
133 ieee802_1x_tx_status(hapd
, sta
, buf
, len
, ack
);
137 void hostapd_rx_from_unknown_sta(struct hostapd_data
*hapd
, const u8
*addr
)
139 struct sta_info
*sta
;
141 sta
= ap_get_sta(hapd
, addr
);
142 if (!sta
|| !(sta
->flags
& WLAN_STA_ASSOC
)) {
143 wpa_printf(MSG_DEBUG
, "Data/PS-poll frame from not associated "
144 "STA " MACSTR
, MAC2STR(addr
));
145 if (sta
&& (sta
->flags
& WLAN_STA_AUTH
))
146 hostapd_sta_disassoc(
148 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
152 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
157 int hostapd_notif_assoc(struct hostapd_data
*hapd
, const u8
*addr
,
158 const u8
*ie
, size_t ielen
)
160 struct sta_info
*sta
;
163 hostapd_logger(hapd
, addr
, HOSTAPD_MODULE_IEEE80211
,
164 HOSTAPD_LEVEL_INFO
, "associated");
166 sta
= ap_get_sta(hapd
, addr
);
168 accounting_sta_stop(hapd
, sta
);
170 sta
= ap_sta_add(hapd
, addr
);
174 sta
->flags
&= ~(WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
);
176 if (hapd
->conf
->wpa
) {
177 if (ie
== NULL
|| ielen
== 0) {
178 if (hapd
->conf
->wps_state
) {
179 wpa_printf(MSG_DEBUG
, "STA did not include "
180 "WPA/RSN IE in (Re)Association "
181 "Request - possible WPS use");
182 sta
->flags
|= WLAN_STA_MAYBE_WPS
;
186 wpa_printf(MSG_DEBUG
, "No WPA/RSN IE from STA");
189 if (hapd
->conf
->wps_state
&& ie
[0] == 0xdd && ie
[1] >= 4 &&
190 os_memcmp(ie
+ 2, "\x00\x50\xf2\x04", 4) == 0) {
191 sta
->flags
|= WLAN_STA_WPS
;
195 if (sta
->wpa_sm
== NULL
)
196 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
198 if (sta
->wpa_sm
== NULL
) {
199 wpa_printf(MSG_ERROR
, "Failed to initialize WPA state "
203 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
205 if (res
!= WPA_IE_OK
) {
206 wpa_printf(MSG_DEBUG
, "WPA/RSN information element "
207 "rejected? (res %u)", res
);
208 wpa_hexdump(MSG_DEBUG
, "IE", ie
, ielen
);
211 } else if (hapd
->conf
->wps_state
) {
212 if (ie
&& ielen
> 4 && ie
[0] == 0xdd && ie
[1] >= 4 &&
213 os_memcmp(ie
+ 2, "\x00\x50\xf2\x04", 4) == 0) {
214 sta
->flags
|= WLAN_STA_WPS
;
216 sta
->flags
|= WLAN_STA_MAYBE_WPS
;
220 new_assoc
= (sta
->flags
& WLAN_STA_ASSOC
) == 0;
221 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
222 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC
);
224 hostapd_new_assoc_sta(hapd
, sta
, !new_assoc
);
226 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 1);
232 void hostapd_notif_disassoc(struct hostapd_data
*hapd
, const u8
*addr
)
234 struct sta_info
*sta
;
236 hostapd_logger(hapd
, addr
, HOSTAPD_MODULE_IEEE80211
,
237 HOSTAPD_LEVEL_INFO
, "disassociated");
239 sta
= ap_get_sta(hapd
, addr
);
241 wpa_printf(MSG_DEBUG
, "Disassociation notification for "
242 "unknown STA " MACSTR
, MAC2STR(addr
));
246 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
);
247 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DISASSOC
);
248 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
249 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
250 ap_free_sta(hapd
, sta
);
254 void hostapd_eapol_receive(struct hostapd_data
*hapd
, const u8
*sa
,
255 const u8
*buf
, size_t len
)
257 ieee802_1x_receive(hapd
, sa
, buf
, len
);
262 void hostapd_mgmt_rx(struct hostapd_data
*hapd
, u8
*buf
, size_t len
,
263 u16 stype
, struct hostapd_frame_info
*fi
)
265 ieee802_11_mgmt(hapd
, buf
, len
, stype
, fi
);
269 void hostapd_mgmt_tx_cb(struct hostapd_data
*hapd
, u8
*buf
, size_t len
,
272 ieee802_11_mgmt_cb(hapd
, buf
, len
, stype
, ok
);
274 #endif /* NEED_MLME */
277 void hostapd_michael_mic_failure(struct hostapd_data
*hapd
, const u8
*addr
)
279 michael_mic_failure(hapd
, addr
, 1);
283 struct hostapd_data
* hostapd_sta_get_bss(struct hostapd_data
*hapd
,
286 struct hostapd_iface
*iface
= hapd
->iface
;
289 for (j
= 0; j
< iface
->num_bss
; j
++) {
290 hapd
= iface
->bss
[j
];
291 if (ap_get_sta(hapd
, addr
))