2 * hostapd / IEEE 802.11 Management
3 * Copyright (c) 2002-2010, 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.
15 #include "utils/includes.h"
17 #include "utils/common.h"
18 #include "common/ieee802_11_defs.h"
21 #include "ap_config.h"
22 #include "ap_drv_ops.h"
23 #include "ieee802_11.h"
26 #ifdef CONFIG_IEEE80211W
28 u8 * hostapd_eid_assoc_comeback_time(struct hostapd_data *hapd,
29 struct sta_info *sta, u8 *eid)
33 struct os_time now, passed;
35 *pos++ = WLAN_EID_TIMEOUT_INTERVAL;
37 *pos++ = WLAN_TIMEOUT_ASSOC_COMEBACK;
39 os_time_sub(&now, &sta->sa_query_start, &passed);
40 tu = (passed.sec * 1000000 + passed.usec) / 1024;
41 if (hapd->conf->assoc_sa_query_max_timeout > tu)
42 timeout = hapd->conf->assoc_sa_query_max_timeout - tu;
45 if (timeout < hapd->conf->assoc_sa_query_max_timeout)
46 timeout++; /* add some extra time for local timers */
47 WPA_PUT_LE32(pos, timeout);
54 /* MLME-SAQuery.request */
55 void ieee802_11_send_sa_query_req(struct hostapd_data *hapd,
56 const u8 *addr, const u8 *trans_id)
58 struct ieee80211_mgmt mgmt;
61 wpa_printf(MSG_DEBUG, "IEEE 802.11: Sending SA Query Request to "
62 MACSTR, MAC2STR(addr));
63 wpa_hexdump(MSG_DEBUG, "IEEE 802.11: SA Query Transaction ID",
64 trans_id, WLAN_SA_QUERY_TR_ID_LEN);
66 os_memset(&mgmt, 0, sizeof(mgmt));
67 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
68 WLAN_FC_STYPE_ACTION);
69 os_memcpy(mgmt.da, addr, ETH_ALEN);
70 os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
71 os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
72 mgmt.u.action.category = WLAN_ACTION_SA_QUERY;
73 mgmt.u.action.u.sa_query_req.action = WLAN_SA_QUERY_REQUEST;
74 os_memcpy(mgmt.u.action.u.sa_query_req.trans_id, trans_id,
75 WLAN_SA_QUERY_TR_ID_LEN);
76 end = mgmt.u.action.u.sa_query_req.trans_id + WLAN_SA_QUERY_TR_ID_LEN;
77 if (hostapd_drv_send_mlme(hapd, &mgmt, end - (u8 *) &mgmt) < 0)
78 perror("ieee802_11_send_sa_query_req: send");
82 void ieee802_11_send_sa_query_resp(struct hostapd_data *hapd,
83 const u8 *sa, const u8 *trans_id)
86 struct ieee80211_mgmt resp;
89 wpa_printf(MSG_DEBUG, "IEEE 802.11: Received SA Query Request from "
91 wpa_hexdump(MSG_DEBUG, "IEEE 802.11: SA Query Transaction ID",
92 trans_id, WLAN_SA_QUERY_TR_ID_LEN);
94 sta = ap_get_sta(hapd, sa);
95 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
96 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignore SA Query Request "
97 "from unassociated STA " MACSTR, MAC2STR(sa));
101 wpa_printf(MSG_DEBUG, "IEEE 802.11: Sending SA Query Response to "
102 MACSTR, MAC2STR(sa));
104 os_memset(&resp, 0, sizeof(resp));
105 resp.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
106 WLAN_FC_STYPE_ACTION);
107 os_memcpy(resp.da, sa, ETH_ALEN);
108 os_memcpy(resp.sa, hapd->own_addr, ETH_ALEN);
109 os_memcpy(resp.bssid, hapd->own_addr, ETH_ALEN);
110 resp.u.action.category = WLAN_ACTION_SA_QUERY;
111 resp.u.action.u.sa_query_req.action = WLAN_SA_QUERY_RESPONSE;
112 os_memcpy(resp.u.action.u.sa_query_req.trans_id, trans_id,
113 WLAN_SA_QUERY_TR_ID_LEN);
114 end = resp.u.action.u.sa_query_req.trans_id + WLAN_SA_QUERY_TR_ID_LEN;
115 if (hostapd_drv_send_mlme(hapd, &resp, end - (u8 *) &resp) < 0)
116 perror("ieee80211_mgmt_sa_query_request: send");
120 void ieee802_11_sa_query_action(struct hostapd_data *hapd, const u8 *sa,
121 const u8 action_type, const u8 *trans_id)
123 struct sta_info *sta;
126 if (action_type == WLAN_SA_QUERY_REQUEST) {
127 ieee802_11_send_sa_query_resp(hapd, sa, trans_id);
131 if (action_type != WLAN_SA_QUERY_RESPONSE) {
132 wpa_printf(MSG_DEBUG, "IEEE 802.11: Unexpected SA Query "
133 "Action %d", action_type);
137 wpa_printf(MSG_DEBUG, "IEEE 802.11: Received SA Query Response from "
138 MACSTR, MAC2STR(sa));
139 wpa_hexdump(MSG_DEBUG, "IEEE 802.11: SA Query Transaction ID",
140 trans_id, WLAN_SA_QUERY_TR_ID_LEN);
142 /* MLME-SAQuery.confirm */
144 sta = ap_get_sta(hapd, sa);
145 if (sta == NULL || sta->sa_query_trans_id == NULL) {
146 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching STA with "
147 "pending SA Query request found");
151 for (i = 0; i < sta->sa_query_count; i++) {
152 if (os_memcmp(sta->sa_query_trans_id +
153 i * WLAN_SA_QUERY_TR_ID_LEN,
154 trans_id, WLAN_SA_QUERY_TR_ID_LEN) == 0)
158 if (i >= sta->sa_query_count) {
159 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching SA Query "
160 "transaction identifier found");
164 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
166 "Reply to pending SA Query received");
167 ap_sta_stop_sa_query(hapd, sta);
170 #endif /* CONFIG_IEEE80211W */
173 u8 * hostapd_eid_ext_capab(struct hostapd_data *hapd, u8 *eid)
178 if (hapd->conf->tdls & (TDLS_PROHIBIT | TDLS_PROHIBIT_CHAN_SWITCH))
180 if (len < 4 && hapd->conf->interworking)
185 *pos++ = WLAN_EID_EXT_CAPAB;
192 if (hapd->conf->time_advertisement == 2)
193 *pos |= 0x08; /* Bit 27 - UTC TSF Offset */
194 if (hapd->conf->interworking)
195 *pos |= 0x80; /* Bit 31 - Interworking */
201 if (hapd->conf->tdls & TDLS_PROHIBIT)
202 *pos |= 0x40; /* Bit 38 - TDLS Prohibited */
203 if (hapd->conf->tdls & TDLS_PROHIBIT_CHAN_SWITCH)
204 *pos |= 0x80; /* Bit 39 - TDLS Channel Switching Prohibited */
211 u8 * hostapd_eid_interworking(struct hostapd_data *hapd, u8 *eid)
214 #ifdef CONFIG_INTERWORKING
217 if (!hapd->conf->interworking)
220 *pos++ = WLAN_EID_INTERWORKING;
223 *pos = hapd->conf->access_network_type;
224 if (hapd->conf->internet)
225 *pos |= INTERWORKING_ANO_INTERNET;
226 if (hapd->conf->asra)
227 *pos |= INTERWORKING_ANO_ASRA;
229 *pos |= INTERWORKING_ANO_ESR;
230 if (hapd->conf->uesa)
231 *pos |= INTERWORKING_ANO_UESA;
234 if (hapd->conf->venue_info_set) {
235 *pos++ = hapd->conf->venue_group;
236 *pos++ = hapd->conf->venue_type;
239 if (!is_zero_ether_addr(hapd->conf->hessid)) {
240 os_memcpy(pos, hapd->conf->hessid, ETH_ALEN);
244 *len = pos - len - 1;
245 #endif /* CONFIG_INTERWORKING */
251 u8 * hostapd_eid_adv_proto(struct hostapd_data *hapd, u8 *eid)
254 #ifdef CONFIG_INTERWORKING
256 /* TODO: Separate configuration for ANQP? */
257 if (!hapd->conf->interworking)
260 *pos++ = WLAN_EID_ADV_PROTO;
262 *pos++ = 0; /* Query Response Length Limit | PAME-BI */
263 *pos++ = ACCESS_NETWORK_QUERY_PROTOCOL;
264 #endif /* CONFIG_INTERWORKING */
270 u8 * hostapd_eid_roaming_consortium(struct hostapd_data *hapd, u8 *eid)
273 #ifdef CONFIG_INTERWORKING
275 unsigned int i, count;
277 if (!hapd->conf->interworking ||
278 hapd->conf->roaming_consortium == NULL ||
279 hapd->conf->roaming_consortium_count == 0)
282 *pos++ = WLAN_EID_ROAMING_CONSORTIUM;
285 /* Number of ANQP OIs (in addition to the max 3 listed here) */
286 if (hapd->conf->roaming_consortium_count > 3 + 255)
288 else if (hapd->conf->roaming_consortium_count > 3)
289 *pos++ = hapd->conf->roaming_consortium_count - 3;
293 /* OU #1 and #2 Lengths */
294 *pos = hapd->conf->roaming_consortium[0].len;
295 if (hapd->conf->roaming_consortium_count > 1)
296 *pos |= hapd->conf->roaming_consortium[1].len << 4;
299 if (hapd->conf->roaming_consortium_count > 3)
302 count = hapd->conf->roaming_consortium_count;
304 for (i = 0; i < count; i++) {
305 os_memcpy(pos, hapd->conf->roaming_consortium[i].oi,
306 hapd->conf->roaming_consortium[i].len);
307 pos += hapd->conf->roaming_consortium[i].len;
310 *len = pos - len - 1;
311 #endif /* CONFIG_INTERWORKING */
317 u8 * hostapd_eid_time_adv(struct hostapd_data *hapd, u8 *eid)
319 if (hapd->conf->time_advertisement != 2)
322 if (hapd->time_adv == NULL &&
323 hostapd_update_time_adv(hapd) < 0)
326 os_memcpy(eid, wpabuf_head(hapd->time_adv),
327 wpabuf_len(hapd->time_adv));
328 eid += wpabuf_len(hapd->time_adv);
334 u8 * hostapd_eid_time_zone(struct hostapd_data *hapd, u8 *eid)
338 if (hapd->conf->time_advertisement != 2)
341 len = os_strlen(hapd->conf->time_zone);
343 *eid++ = WLAN_EID_TIME_ZONE;
345 os_memcpy(eid, hapd->conf->time_zone, len);
352 int hostapd_update_time_adv(struct hostapd_data *hapd)
354 const int elen = 2 + 1 + 10 + 5 + 1;
359 if (hapd->conf->time_advertisement != 2)
362 if (os_get_time(&t) < 0 || os_gmtime(t.sec, &tm) < 0)
365 if (!hapd->time_adv) {
366 hapd->time_adv = wpabuf_alloc(elen);
367 if (hapd->time_adv == NULL)
369 pos = wpabuf_put(hapd->time_adv, elen);
371 pos = wpabuf_mhead_u8(hapd->time_adv);
373 *pos++ = WLAN_EID_TIME_ADVERTISEMENT;
374 *pos++ = 1 + 10 + 5 + 1;
376 *pos++ = 2; /* UTC time at which the TSF timer is 0 */
378 /* Time Value at TSF 0 */
379 /* FIX: need to calculate this based on the current TSF value */
380 WPA_PUT_LE16(pos, tm.year); /* Year */
382 *pos++ = tm.month; /* Month */
383 *pos++ = tm.day; /* Day of month */
384 *pos++ = tm.hour; /* Hours */
385 *pos++ = tm.min; /* Minutes */
386 *pos++ = tm.sec; /* Seconds */
387 WPA_PUT_LE16(pos, 0); /* Milliseconds (not used) */
389 *pos++ = 0; /* Reserved */
392 /* TODO: fill in an estimate on the error */
399 *pos++ = hapd->time_update_counter++;