2 * hostapd / IEEE 802.11 Management
3 * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "common/ieee802_11_defs.h"
15 #include "ap_config.h"
16 #include "ap_drv_ops.h"
17 #include "ieee802_11.h"
20 #ifdef CONFIG_IEEE80211W
22 u8 * hostapd_eid_assoc_comeback_time(struct hostapd_data *hapd,
23 struct sta_info *sta, u8 *eid)
27 struct os_reltime now, passed;
29 *pos++ = WLAN_EID_TIMEOUT_INTERVAL;
31 *pos++ = WLAN_TIMEOUT_ASSOC_COMEBACK;
33 os_reltime_sub(&now, &sta->sa_query_start, &passed);
34 tu = (passed.sec * 1000000 + passed.usec) / 1024;
35 if (hapd->conf->assoc_sa_query_max_timeout > tu)
36 timeout = hapd->conf->assoc_sa_query_max_timeout - tu;
39 if (timeout < hapd->conf->assoc_sa_query_max_timeout)
40 timeout++; /* add some extra time for local timers */
41 WPA_PUT_LE32(pos, timeout);
48 /* MLME-SAQuery.request */
49 void ieee802_11_send_sa_query_req(struct hostapd_data *hapd,
50 const u8 *addr, const u8 *trans_id)
52 struct ieee80211_mgmt mgmt;
55 wpa_printf(MSG_DEBUG, "IEEE 802.11: Sending SA Query Request to "
56 MACSTR, MAC2STR(addr));
57 wpa_hexdump(MSG_DEBUG, "IEEE 802.11: SA Query Transaction ID",
58 trans_id, WLAN_SA_QUERY_TR_ID_LEN);
60 os_memset(&mgmt, 0, sizeof(mgmt));
61 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
62 WLAN_FC_STYPE_ACTION);
63 os_memcpy(mgmt.da, addr, ETH_ALEN);
64 os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
65 os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
66 mgmt.u.action.category = WLAN_ACTION_SA_QUERY;
67 mgmt.u.action.u.sa_query_req.action = WLAN_SA_QUERY_REQUEST;
68 os_memcpy(mgmt.u.action.u.sa_query_req.trans_id, trans_id,
69 WLAN_SA_QUERY_TR_ID_LEN);
70 end = mgmt.u.action.u.sa_query_req.trans_id + WLAN_SA_QUERY_TR_ID_LEN;
71 if (hostapd_drv_send_mlme(hapd, &mgmt, end - (u8 *) &mgmt, 0) < 0)
72 wpa_printf(MSG_INFO, "ieee802_11_send_sa_query_req: send failed");
76 static void ieee802_11_send_sa_query_resp(struct hostapd_data *hapd,
77 const u8 *sa, const u8 *trans_id)
80 struct ieee80211_mgmt resp;
83 wpa_printf(MSG_DEBUG, "IEEE 802.11: Received SA Query Request from "
85 wpa_hexdump(MSG_DEBUG, "IEEE 802.11: SA Query Transaction ID",
86 trans_id, WLAN_SA_QUERY_TR_ID_LEN);
88 sta = ap_get_sta(hapd, sa);
89 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
90 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignore SA Query Request "
91 "from unassociated STA " MACSTR, MAC2STR(sa));
95 wpa_printf(MSG_DEBUG, "IEEE 802.11: Sending SA Query Response to "
98 os_memset(&resp, 0, sizeof(resp));
99 resp.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
100 WLAN_FC_STYPE_ACTION);
101 os_memcpy(resp.da, sa, ETH_ALEN);
102 os_memcpy(resp.sa, hapd->own_addr, ETH_ALEN);
103 os_memcpy(resp.bssid, hapd->own_addr, ETH_ALEN);
104 resp.u.action.category = WLAN_ACTION_SA_QUERY;
105 resp.u.action.u.sa_query_req.action = WLAN_SA_QUERY_RESPONSE;
106 os_memcpy(resp.u.action.u.sa_query_req.trans_id, trans_id,
107 WLAN_SA_QUERY_TR_ID_LEN);
108 end = resp.u.action.u.sa_query_req.trans_id + WLAN_SA_QUERY_TR_ID_LEN;
109 if (hostapd_drv_send_mlme(hapd, &resp, end - (u8 *) &resp, 0) < 0)
110 wpa_printf(MSG_INFO, "ieee80211_mgmt_sa_query_request: send failed");
114 void ieee802_11_sa_query_action(struct hostapd_data *hapd, const u8 *sa,
115 const u8 action_type, const u8 *trans_id)
117 struct sta_info *sta;
120 if (action_type == WLAN_SA_QUERY_REQUEST) {
121 ieee802_11_send_sa_query_resp(hapd, sa, trans_id);
125 if (action_type != WLAN_SA_QUERY_RESPONSE) {
126 wpa_printf(MSG_DEBUG, "IEEE 802.11: Unexpected SA Query "
127 "Action %d", action_type);
131 wpa_printf(MSG_DEBUG, "IEEE 802.11: Received SA Query Response from "
132 MACSTR, MAC2STR(sa));
133 wpa_hexdump(MSG_DEBUG, "IEEE 802.11: SA Query Transaction ID",
134 trans_id, WLAN_SA_QUERY_TR_ID_LEN);
136 /* MLME-SAQuery.confirm */
138 sta = ap_get_sta(hapd, sa);
139 if (sta == NULL || sta->sa_query_trans_id == NULL) {
140 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching STA with "
141 "pending SA Query request found");
145 for (i = 0; i < sta->sa_query_count; i++) {
146 if (os_memcmp(sta->sa_query_trans_id +
147 i * WLAN_SA_QUERY_TR_ID_LEN,
148 trans_id, WLAN_SA_QUERY_TR_ID_LEN) == 0)
152 if (i >= sta->sa_query_count) {
153 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching SA Query "
154 "transaction identifier found");
158 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
160 "Reply to pending SA Query received");
161 ap_sta_stop_sa_query(hapd, sta);
164 #endif /* CONFIG_IEEE80211W */
167 static void hostapd_ext_capab_byte(struct hostapd_data *hapd, u8 *pos, int idx)
172 case 0: /* Bits 0-7 */
173 if (hapd->iconf->obss_interval)
174 *pos |= 0x01; /* Bit 0 - Coexistence management */
175 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)
176 *pos |= 0x04; /* Bit 2 - Extended Channel Switching */
178 case 1: /* Bits 8-15 */
179 if (hapd->conf->proxy_arp)
180 *pos |= 0x10; /* Bit 12 - Proxy ARP */
181 if (hapd->conf->coloc_intf_reporting) {
182 /* Bit 13 - Collocated Interference Reporting */
186 case 2: /* Bits 16-23 */
187 if (hapd->conf->wnm_sleep_mode)
188 *pos |= 0x02; /* Bit 17 - WNM-Sleep Mode */
189 if (hapd->conf->bss_transition)
190 *pos |= 0x08; /* Bit 19 - BSS Transition */
192 case 3: /* Bits 24-31 */
194 *pos |= 0x02; /* Bit 25 - SSID List */
195 #endif /* CONFIG_WNM_AP */
196 if (hapd->conf->time_advertisement == 2)
197 *pos |= 0x08; /* Bit 27 - UTC TSF Offset */
198 if (hapd->conf->interworking)
199 *pos |= 0x80; /* Bit 31 - Interworking */
201 case 4: /* Bits 32-39 */
202 if (hapd->conf->qos_map_set_len)
203 *pos |= 0x01; /* Bit 32 - QoS Map */
204 if (hapd->conf->tdls & TDLS_PROHIBIT)
205 *pos |= 0x40; /* Bit 38 - TDLS Prohibited */
206 if (hapd->conf->tdls & TDLS_PROHIBIT_CHAN_SWITCH) {
207 /* Bit 39 - TDLS Channel Switching Prohibited */
211 case 5: /* Bits 40-47 */
213 if (hapd->conf->hs20)
214 *pos |= 0x40; /* Bit 46 - WNM-Notification */
215 #endif /* CONFIG_HS20 */
217 if (hapd->conf->mbo_enabled)
218 *pos |= 0x40; /* Bit 46 - WNM-Notification */
219 #endif /* CONFIG_MBO */
221 case 6: /* Bits 48-55 */
222 if (hapd->conf->ssid.utf8_ssid)
223 *pos |= 0x01; /* Bit 48 - UTF-8 SSID */
225 case 7: /* Bits 56-63 */
227 case 8: /* Bits 64-71 */
228 if (hapd->conf->ftm_responder)
229 *pos |= 0x40; /* Bit 70 - FTM responder */
230 if (hapd->conf->ftm_initiator)
231 *pos |= 0x80; /* Bit 71 - FTM initiator */
233 case 9: /* Bits 72-79 */
235 if ((hapd->conf->wpa & WPA_PROTO_RSN) &&
236 wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt))
238 #endif /* CONFIG_FILS */
244 u8 * hostapd_eid_ext_capab(struct hostapd_data *hapd, u8 *eid)
249 if (hapd->conf->tdls & (TDLS_PROHIBIT | TDLS_PROHIBIT_CHAN_SWITCH))
251 if (len < 4 && hapd->conf->interworking)
253 if (len < 3 && hapd->conf->wnm_sleep_mode)
255 if (len < 1 && hapd->iconf->obss_interval)
257 if (len < 7 && hapd->conf->ssid.utf8_ssid)
260 (hapd->conf->ftm_initiator || hapd->conf->ftm_responder))
265 #endif /* CONFIG_WNM_AP */
267 if (hapd->conf->hs20 && len < 6)
269 #endif /* CONFIG_HS20 */
271 if (hapd->conf->mbo_enabled && len < 6)
273 #endif /* CONFIG_MBO */
275 if ((!(hapd->conf->wpa & WPA_PROTO_RSN) ||
276 !wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt)) && len < 10)
278 #endif /* CONFIG_FILS */
279 if (len < hapd->iface->extended_capa_len)
280 len = hapd->iface->extended_capa_len;
284 *pos++ = WLAN_EID_EXT_CAPAB;
286 for (i = 0; i < len; i++, pos++) {
287 hostapd_ext_capab_byte(hapd, pos, i);
289 if (i < hapd->iface->extended_capa_len) {
290 *pos &= ~hapd->iface->extended_capa_mask[i];
291 *pos |= hapd->iface->extended_capa[i];
295 while (len > 0 && eid[1 + len] == 0) {
302 return eid + 2 + len;
306 u8 * hostapd_eid_qos_map_set(struct hostapd_data *hapd, u8 *eid)
309 u8 len = hapd->conf->qos_map_set_len;
314 *pos++ = WLAN_EID_QOS_MAP_SET;
316 os_memcpy(pos, hapd->conf->qos_map_set, len);
323 u8 * hostapd_eid_interworking(struct hostapd_data *hapd, u8 *eid)
326 #ifdef CONFIG_INTERWORKING
329 if (!hapd->conf->interworking)
332 *pos++ = WLAN_EID_INTERWORKING;
335 *pos = hapd->conf->access_network_type;
336 if (hapd->conf->internet)
337 *pos |= INTERWORKING_ANO_INTERNET;
338 if (hapd->conf->asra)
339 *pos |= INTERWORKING_ANO_ASRA;
341 *pos |= INTERWORKING_ANO_ESR;
342 if (hapd->conf->uesa)
343 *pos |= INTERWORKING_ANO_UESA;
346 if (hapd->conf->venue_info_set) {
347 *pos++ = hapd->conf->venue_group;
348 *pos++ = hapd->conf->venue_type;
351 if (!is_zero_ether_addr(hapd->conf->hessid)) {
352 os_memcpy(pos, hapd->conf->hessid, ETH_ALEN);
356 *len = pos - len - 1;
357 #endif /* CONFIG_INTERWORKING */
363 u8 * hostapd_eid_adv_proto(struct hostapd_data *hapd, u8 *eid)
366 #ifdef CONFIG_INTERWORKING
368 /* TODO: Separate configuration for ANQP? */
369 if (!hapd->conf->interworking)
372 *pos++ = WLAN_EID_ADV_PROTO;
374 *pos++ = 0x7F; /* Query Response Length Limit | PAME-BI */
375 *pos++ = ACCESS_NETWORK_QUERY_PROTOCOL;
376 #endif /* CONFIG_INTERWORKING */
382 u8 * hostapd_eid_roaming_consortium(struct hostapd_data *hapd, u8 *eid)
385 #ifdef CONFIG_INTERWORKING
387 unsigned int i, count;
389 if (!hapd->conf->interworking ||
390 hapd->conf->roaming_consortium == NULL ||
391 hapd->conf->roaming_consortium_count == 0)
394 *pos++ = WLAN_EID_ROAMING_CONSORTIUM;
397 /* Number of ANQP OIs (in addition to the max 3 listed here) */
398 if (hapd->conf->roaming_consortium_count > 3 + 255)
400 else if (hapd->conf->roaming_consortium_count > 3)
401 *pos++ = hapd->conf->roaming_consortium_count - 3;
405 /* OU #1 and #2 Lengths */
406 *pos = hapd->conf->roaming_consortium[0].len;
407 if (hapd->conf->roaming_consortium_count > 1)
408 *pos |= hapd->conf->roaming_consortium[1].len << 4;
411 if (hapd->conf->roaming_consortium_count > 3)
414 count = hapd->conf->roaming_consortium_count;
416 for (i = 0; i < count; i++) {
417 os_memcpy(pos, hapd->conf->roaming_consortium[i].oi,
418 hapd->conf->roaming_consortium[i].len);
419 pos += hapd->conf->roaming_consortium[i].len;
422 *len = pos - len - 1;
423 #endif /* CONFIG_INTERWORKING */
429 u8 * hostapd_eid_time_adv(struct hostapd_data *hapd, u8 *eid)
431 if (hapd->conf->time_advertisement != 2)
434 if (hapd->time_adv == NULL &&
435 hostapd_update_time_adv(hapd) < 0)
438 if (hapd->time_adv == NULL)
441 os_memcpy(eid, wpabuf_head(hapd->time_adv),
442 wpabuf_len(hapd->time_adv));
443 eid += wpabuf_len(hapd->time_adv);
449 u8 * hostapd_eid_time_zone(struct hostapd_data *hapd, u8 *eid)
453 if (hapd->conf->time_advertisement != 2 || !hapd->conf->time_zone)
456 len = os_strlen(hapd->conf->time_zone);
458 *eid++ = WLAN_EID_TIME_ZONE;
460 os_memcpy(eid, hapd->conf->time_zone, len);
467 int hostapd_update_time_adv(struct hostapd_data *hapd)
469 const int elen = 2 + 1 + 10 + 5 + 1;
474 if (hapd->conf->time_advertisement != 2)
477 if (os_get_time(&t) < 0 || os_gmtime(t.sec, &tm) < 0)
480 if (!hapd->time_adv) {
481 hapd->time_adv = wpabuf_alloc(elen);
482 if (hapd->time_adv == NULL)
484 pos = wpabuf_put(hapd->time_adv, elen);
486 pos = wpabuf_mhead_u8(hapd->time_adv);
488 *pos++ = WLAN_EID_TIME_ADVERTISEMENT;
489 *pos++ = 1 + 10 + 5 + 1;
491 *pos++ = 2; /* UTC time at which the TSF timer is 0 */
493 /* Time Value at TSF 0 */
494 /* FIX: need to calculate this based on the current TSF value */
495 WPA_PUT_LE16(pos, tm.year); /* Year */
497 *pos++ = tm.month; /* Month */
498 *pos++ = tm.day; /* Day of month */
499 *pos++ = tm.hour; /* Hours */
500 *pos++ = tm.min; /* Minutes */
501 *pos++ = tm.sec; /* Seconds */
502 WPA_PUT_LE16(pos, 0); /* Milliseconds (not used) */
504 *pos++ = 0; /* Reserved */
507 /* TODO: fill in an estimate on the error */
514 *pos++ = hapd->time_update_counter++;
520 u8 * hostapd_eid_bss_max_idle_period(struct hostapd_data *hapd, u8 *eid)
525 if (hapd->conf->ap_max_inactivity > 0) {
527 *pos++ = WLAN_EID_BSS_MAX_IDLE_PERIOD;
529 val = hapd->conf->ap_max_inactivity;
538 WPA_PUT_LE16(pos, val);
540 *pos++ = 0x00; /* TODO: Protected Keep-Alive Required */
542 #endif /* CONFIG_WNM_AP */
550 u8 * hostapd_eid_mbo(struct hostapd_data *hapd, u8 *eid, size_t len)
552 u8 mbo[9], *mbo_pos = mbo;
555 if (!hapd->conf->mbo_enabled &&
556 !OCE_STA_CFON_ENABLED(hapd) && !OCE_AP_ENABLED(hapd))
559 if (hapd->conf->mbo_enabled) {
560 *mbo_pos++ = MBO_ATTR_ID_AP_CAPA_IND;
562 /* Not Cellular aware */
566 if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
567 *mbo_pos++ = MBO_ATTR_ID_ASSOC_DISALLOW;
569 *mbo_pos++ = hapd->mbo_assoc_disallow;
572 if (OCE_STA_CFON_ENABLED(hapd) || OCE_AP_ENABLED(hapd)) {
576 if (OCE_STA_CFON_ENABLED(hapd) && !OCE_AP_ENABLED(hapd))
577 ctrl |= OCE_IS_STA_CFON;
579 *mbo_pos++ = OCE_ATTR_ID_CAPA_IND;
584 pos += mbo_add_ie(pos, len, mbo, mbo_pos - mbo);
590 u8 hostapd_mbo_ie_len(struct hostapd_data *hapd)
594 if (!hapd->conf->mbo_enabled &&
595 !OCE_STA_CFON_ENABLED(hapd) && !OCE_AP_ENABLED(hapd))
599 * MBO IE header (6) + Capability Indication attribute (3) +
600 * Association Disallowed attribute (3) = 12
603 if (hapd->conf->mbo_enabled)
604 len += 3 + (hapd->mbo_assoc_disallow ? 3 : 0);
606 /* OCE capability indication attribute (3) */
607 if (OCE_STA_CFON_ENABLED(hapd) || OCE_AP_ENABLED(hapd))
613 #endif /* CONFIG_MBO */
617 static int hostapd_eid_owe_trans_enabled(struct hostapd_data *hapd)
619 return hapd->conf->owe_transition_ssid_len > 0 &&
620 !is_zero_ether_addr(hapd->conf->owe_transition_bssid);
622 #endif /* CONFIG_OWE */
625 size_t hostapd_eid_owe_trans_len(struct hostapd_data *hapd)
628 if (!hostapd_eid_owe_trans_enabled(hapd))
630 return 6 + ETH_ALEN + 1 + hapd->conf->owe_transition_ssid_len;
631 #else /* CONFIG_OWE */
633 #endif /* CONFIG_OWE */
637 u8 * hostapd_eid_owe_trans(struct hostapd_data *hapd, u8 *eid,
644 if (hapd->conf->owe_transition_ifname[0] &&
645 !hostapd_eid_owe_trans_enabled(hapd))
646 hostapd_owe_trans_get_info(hapd);
648 if (!hostapd_eid_owe_trans_enabled(hapd))
651 elen = hostapd_eid_owe_trans_len(hapd);
653 wpa_printf(MSG_DEBUG,
654 "OWE: Not enough room in the buffer for OWE IE");
658 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
660 WPA_PUT_BE24(pos, OUI_WFA);
662 *pos++ = OWE_OUI_TYPE;
663 os_memcpy(pos, hapd->conf->owe_transition_bssid, ETH_ALEN);
665 *pos++ = hapd->conf->owe_transition_ssid_len;
666 os_memcpy(pos, hapd->conf->owe_transition_ssid,
667 hapd->conf->owe_transition_ssid_len);
668 pos += hapd->conf->owe_transition_ssid_len;
671 #else /* CONFIG_OWE */
673 #endif /* CONFIG_OWE */
677 void ap_copy_sta_supp_op_classes(struct sta_info *sta,
678 const u8 *supp_op_classes,
679 size_t supp_op_classes_len)
681 if (!supp_op_classes)
683 os_free(sta->supp_op_classes);
684 sta->supp_op_classes = os_malloc(1 + supp_op_classes_len);
685 if (!sta->supp_op_classes)
688 sta->supp_op_classes[0] = supp_op_classes_len;
689 os_memcpy(sta->supp_op_classes + 1, supp_op_classes,
690 supp_op_classes_len);
694 u8 * hostapd_eid_fils_indic(struct hostapd_data *hapd, u8 *eid, int hessid)
701 struct fils_realm *realm;
703 if (!(hapd->conf->wpa & WPA_PROTO_RSN) ||
704 !wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt))
707 realms = dl_list_len(&hapd->conf->fils_realms);
709 realms = 7; /* 3 bit count field limits this to max 7 */
711 *pos++ = WLAN_EID_FILS_INDICATION;
713 /* TODO: B0..B2: Number of Public Key Identifiers */
714 if (hapd->conf->erp_domain) {
715 /* B3..B5: Number of Realm Identifiers */
716 fils_info |= realms << 3;
718 /* TODO: B6: FILS IP Address Configuration */
719 if (hapd->conf->fils_cache_id_set)
721 if (hessid && !is_zero_ether_addr(hapd->conf->hessid))
722 fils_info |= BIT(8); /* HESSID Included */
723 /* FILS Shared Key Authentication without PFS Supported */
725 if (hapd->conf->fils_dh_group) {
726 /* FILS Shared Key Authentication with PFS Supported */
727 fils_info |= BIT(10);
729 /* TODO: B11: FILS Public Key Authentication Supported */
730 /* B12..B15: Reserved */
731 WPA_PUT_LE16(pos, fils_info);
733 if (hapd->conf->fils_cache_id_set) {
734 os_memcpy(pos, hapd->conf->fils_cache_id, FILS_CACHE_ID_LEN);
735 pos += FILS_CACHE_ID_LEN;
737 if (hessid && !is_zero_ether_addr(hapd->conf->hessid)) {
738 os_memcpy(pos, hapd->conf->hessid, ETH_ALEN);
742 dl_list_for_each(realm, &hapd->conf->fils_realms, struct fils_realm,
747 os_memcpy(pos, realm->hash, 2);
750 *len = pos - len - 1;
751 #endif /* CONFIG_FILS */