]> git.ipfire.org Git - thirdparty/hostap.git/blob - src/ap/ieee802_11_shared.c
HE: Add TWT responder extended capabilities field
[thirdparty/hostap.git] / src / ap / ieee802_11_shared.c
1 /*
2 * hostapd / IEEE 802.11 Management
3 * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include "utils/includes.h"
10
11 #include "utils/common.h"
12 #include "common/ieee802_11_defs.h"
13 #include "common/ocv.h"
14 #include "hostapd.h"
15 #include "sta_info.h"
16 #include "ap_config.h"
17 #include "ap_drv_ops.h"
18 #include "wpa_auth.h"
19 #include "ieee802_11.h"
20
21
22 u8 * hostapd_eid_assoc_comeback_time(struct hostapd_data *hapd,
23 struct sta_info *sta, u8 *eid)
24 {
25 u8 *pos = eid;
26 u32 timeout, tu;
27 struct os_reltime now, passed;
28
29 *pos++ = WLAN_EID_TIMEOUT_INTERVAL;
30 *pos++ = 5;
31 *pos++ = WLAN_TIMEOUT_ASSOC_COMEBACK;
32 os_get_reltime(&now);
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;
37 else
38 timeout = 0;
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);
42 pos += 4;
43
44 return pos;
45 }
46
47
48 /* MLME-SAQuery.request */
49 void ieee802_11_send_sa_query_req(struct hostapd_data *hapd,
50 const u8 *addr, const u8 *trans_id)
51 {
52 #ifdef CONFIG_OCV
53 struct sta_info *sta;
54 #endif /* CONFIG_OCV */
55 struct ieee80211_mgmt *mgmt;
56 u8 *oci_ie = NULL;
57 u8 oci_ie_len = 0;
58 u8 *end;
59
60 wpa_printf(MSG_DEBUG, "IEEE 802.11: Sending SA Query Request to "
61 MACSTR, MAC2STR(addr));
62 wpa_hexdump(MSG_DEBUG, "IEEE 802.11: SA Query Transaction ID",
63 trans_id, WLAN_SA_QUERY_TR_ID_LEN);
64
65 #ifdef CONFIG_OCV
66 sta = ap_get_sta(hapd, addr);
67 if (sta && wpa_auth_uses_ocv(sta->wpa_sm)) {
68 struct wpa_channel_info ci;
69
70 if (hostapd_drv_channel_info(hapd, &ci) != 0) {
71 wpa_printf(MSG_WARNING,
72 "Failed to get channel info for OCI element in SA Query Request");
73 return;
74 }
75
76 oci_ie_len = OCV_OCI_EXTENDED_LEN;
77 oci_ie = os_zalloc(oci_ie_len);
78 if (!oci_ie) {
79 wpa_printf(MSG_WARNING,
80 "Failed to allocate buffer for OCI element in SA Query Request");
81 return;
82 }
83
84 if (ocv_insert_extended_oci(&ci, oci_ie) < 0) {
85 os_free(oci_ie);
86 return;
87 }
88 }
89 #endif /* CONFIG_OCV */
90
91 mgmt = os_zalloc(sizeof(*mgmt) + oci_ie_len);
92 if (!mgmt) {
93 wpa_printf(MSG_DEBUG,
94 "Failed to allocate buffer for SA Query Response frame");
95 os_free(oci_ie);
96 return;
97 }
98
99 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
100 WLAN_FC_STYPE_ACTION);
101 os_memcpy(mgmt->da, addr, ETH_ALEN);
102 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
103 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
104 mgmt->u.action.category = WLAN_ACTION_SA_QUERY;
105 mgmt->u.action.u.sa_query_req.action = WLAN_SA_QUERY_REQUEST;
106 os_memcpy(mgmt->u.action.u.sa_query_req.trans_id, trans_id,
107 WLAN_SA_QUERY_TR_ID_LEN);
108 end = mgmt->u.action.u.sa_query_req.variable;
109 #ifdef CONFIG_OCV
110 if (oci_ie_len > 0) {
111 os_memcpy(end, oci_ie, oci_ie_len);
112 end += oci_ie_len;
113 }
114 #endif /* CONFIG_OCV */
115 if (hostapd_drv_send_mlme(hapd, mgmt, end - (u8 *) mgmt, 0, NULL, 0, 0)
116 < 0)
117 wpa_printf(MSG_INFO, "ieee802_11_send_sa_query_req: send failed");
118
119 os_free(mgmt);
120 os_free(oci_ie);
121 }
122
123
124 static void ieee802_11_send_sa_query_resp(struct hostapd_data *hapd,
125 const u8 *sa, const u8 *trans_id)
126 {
127 struct sta_info *sta;
128 struct ieee80211_mgmt *resp;
129 u8 *oci_ie = NULL;
130 u8 oci_ie_len = 0;
131 u8 *end;
132
133 wpa_printf(MSG_DEBUG, "IEEE 802.11: Received SA Query Request from "
134 MACSTR, MAC2STR(sa));
135 wpa_hexdump(MSG_DEBUG, "IEEE 802.11: SA Query Transaction ID",
136 trans_id, WLAN_SA_QUERY_TR_ID_LEN);
137
138 sta = ap_get_sta(hapd, sa);
139 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
140 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignore SA Query Request "
141 "from unassociated STA " MACSTR, MAC2STR(sa));
142 return;
143 }
144
145 #ifdef CONFIG_OCV
146 if (wpa_auth_uses_ocv(sta->wpa_sm)) {
147 struct wpa_channel_info ci;
148
149 if (hostapd_drv_channel_info(hapd, &ci) != 0) {
150 wpa_printf(MSG_WARNING,
151 "Failed to get channel info for OCI element in SA Query Response");
152 return;
153 }
154
155 oci_ie_len = OCV_OCI_EXTENDED_LEN;
156 oci_ie = os_zalloc(oci_ie_len);
157 if (!oci_ie) {
158 wpa_printf(MSG_WARNING,
159 "Failed to allocate buffer for for OCI element in SA Query Response");
160 return;
161 }
162
163 if (ocv_insert_extended_oci(&ci, oci_ie) < 0) {
164 os_free(oci_ie);
165 return;
166 }
167 }
168 #endif /* CONFIG_OCV */
169
170 resp = os_zalloc(sizeof(*resp) + oci_ie_len);
171 if (!resp) {
172 wpa_printf(MSG_DEBUG,
173 "Failed to allocate buffer for SA Query Response frame");
174 os_free(oci_ie);
175 return;
176 }
177
178 wpa_printf(MSG_DEBUG, "IEEE 802.11: Sending SA Query Response to "
179 MACSTR, MAC2STR(sa));
180
181 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
182 WLAN_FC_STYPE_ACTION);
183 os_memcpy(resp->da, sa, ETH_ALEN);
184 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
185 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
186 resp->u.action.category = WLAN_ACTION_SA_QUERY;
187 resp->u.action.u.sa_query_req.action = WLAN_SA_QUERY_RESPONSE;
188 os_memcpy(resp->u.action.u.sa_query_req.trans_id, trans_id,
189 WLAN_SA_QUERY_TR_ID_LEN);
190 end = resp->u.action.u.sa_query_req.variable;
191 #ifdef CONFIG_OCV
192 if (oci_ie_len > 0) {
193 os_memcpy(end, oci_ie, oci_ie_len);
194 end += oci_ie_len;
195 }
196 #endif /* CONFIG_OCV */
197 if (hostapd_drv_send_mlme(hapd, resp, end - (u8 *) resp, 0, NULL, 0, 0)
198 < 0)
199 wpa_printf(MSG_INFO, "ieee80211_mgmt_sa_query_request: send failed");
200
201 os_free(resp);
202 os_free(oci_ie);
203 }
204
205
206 void ieee802_11_sa_query_action(struct hostapd_data *hapd,
207 const struct ieee80211_mgmt *mgmt,
208 size_t len)
209 {
210 struct sta_info *sta;
211 int i;
212 const u8 *sa = mgmt->sa;
213 const u8 action_type = mgmt->u.action.u.sa_query_resp.action;
214 const u8 *trans_id = mgmt->u.action.u.sa_query_resp.trans_id;
215
216 if (((const u8 *) mgmt) + len <
217 mgmt->u.action.u.sa_query_resp.variable) {
218 wpa_printf(MSG_DEBUG,
219 "IEEE 802.11: Too short SA Query Action frame (len=%lu)",
220 (unsigned long) len);
221 return;
222 }
223
224 sta = ap_get_sta(hapd, sa);
225
226 #ifdef CONFIG_OCV
227 if (sta && wpa_auth_uses_ocv(sta->wpa_sm)) {
228 struct ieee802_11_elems elems;
229 struct wpa_channel_info ci;
230 int tx_chanwidth;
231 int tx_seg1_idx;
232 size_t ies_len;
233 const u8 *ies;
234
235 ies = mgmt->u.action.u.sa_query_resp.variable;
236 ies_len = len - (ies - (u8 *) mgmt);
237 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) ==
238 ParseFailed) {
239 wpa_printf(MSG_DEBUG,
240 "SA Query: Failed to parse elements");
241 return;
242 }
243
244 if (hostapd_drv_channel_info(hapd, &ci) != 0) {
245 wpa_printf(MSG_WARNING,
246 "Failed to get channel info to validate received OCI in SA Query Action frame");
247 return;
248 }
249
250 if (get_sta_tx_parameters(sta->wpa_sm,
251 channel_width_to_int(ci.chanwidth),
252 ci.seg1_idx, &tx_chanwidth,
253 &tx_seg1_idx) < 0)
254 return;
255
256 if (ocv_verify_tx_params(elems.oci, elems.oci_len, &ci,
257 tx_chanwidth, tx_seg1_idx) != 0) {
258 wpa_printf(MSG_WARNING, "%s", ocv_errorstr);
259 return;
260 }
261 }
262 #endif /* CONFIG_OCV */
263
264 if (action_type == WLAN_SA_QUERY_REQUEST) {
265 ieee802_11_send_sa_query_resp(hapd, sa, trans_id);
266 return;
267 }
268
269 if (action_type != WLAN_SA_QUERY_RESPONSE) {
270 wpa_printf(MSG_DEBUG, "IEEE 802.11: Unexpected SA Query "
271 "Action %d", action_type);
272 return;
273 }
274
275 wpa_printf(MSG_DEBUG, "IEEE 802.11: Received SA Query Response from "
276 MACSTR, MAC2STR(sa));
277 wpa_hexdump(MSG_DEBUG, "IEEE 802.11: SA Query Transaction ID",
278 trans_id, WLAN_SA_QUERY_TR_ID_LEN);
279
280 /* MLME-SAQuery.confirm */
281
282 if (sta == NULL || sta->sa_query_trans_id == NULL) {
283 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching STA with "
284 "pending SA Query request found");
285 return;
286 }
287
288 for (i = 0; i < sta->sa_query_count; i++) {
289 if (os_memcmp(sta->sa_query_trans_id +
290 i * WLAN_SA_QUERY_TR_ID_LEN,
291 trans_id, WLAN_SA_QUERY_TR_ID_LEN) == 0)
292 break;
293 }
294
295 if (i >= sta->sa_query_count) {
296 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching SA Query "
297 "transaction identifier found");
298 return;
299 }
300
301 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
302 HOSTAPD_LEVEL_DEBUG,
303 "Reply to pending SA Query received");
304 ap_sta_stop_sa_query(hapd, sta);
305 }
306
307
308 static void hostapd_ext_capab_byte(struct hostapd_data *hapd, u8 *pos, int idx)
309 {
310 *pos = 0x00;
311
312 switch (idx) {
313 case 0: /* Bits 0-7 */
314 if (hapd->iconf->obss_interval)
315 *pos |= 0x01; /* Bit 0 - Coexistence management */
316 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)
317 *pos |= 0x04; /* Bit 2 - Extended Channel Switching */
318 break;
319 case 1: /* Bits 8-15 */
320 if (hapd->conf->proxy_arp)
321 *pos |= 0x10; /* Bit 12 - Proxy ARP */
322 if (hapd->conf->coloc_intf_reporting) {
323 /* Bit 13 - Collocated Interference Reporting */
324 *pos |= 0x20;
325 }
326 break;
327 case 2: /* Bits 16-23 */
328 if (hapd->conf->wnm_sleep_mode)
329 *pos |= 0x02; /* Bit 17 - WNM-Sleep Mode */
330 if (hapd->conf->bss_transition)
331 *pos |= 0x08; /* Bit 19 - BSS Transition */
332 break;
333 case 3: /* Bits 24-31 */
334 #ifdef CONFIG_WNM_AP
335 *pos |= 0x02; /* Bit 25 - SSID List */
336 #endif /* CONFIG_WNM_AP */
337 if (hapd->conf->time_advertisement == 2)
338 *pos |= 0x08; /* Bit 27 - UTC TSF Offset */
339 if (hapd->conf->interworking)
340 *pos |= 0x80; /* Bit 31 - Interworking */
341 break;
342 case 4: /* Bits 32-39 */
343 if (hapd->conf->qos_map_set_len)
344 *pos |= 0x01; /* Bit 32 - QoS Map */
345 if (hapd->conf->tdls & TDLS_PROHIBIT)
346 *pos |= 0x40; /* Bit 38 - TDLS Prohibited */
347 if (hapd->conf->tdls & TDLS_PROHIBIT_CHAN_SWITCH) {
348 /* Bit 39 - TDLS Channel Switching Prohibited */
349 *pos |= 0x80;
350 }
351 break;
352 case 5: /* Bits 40-47 */
353 #ifdef CONFIG_HS20
354 if (hapd->conf->hs20)
355 *pos |= 0x40; /* Bit 46 - WNM-Notification */
356 #endif /* CONFIG_HS20 */
357 #ifdef CONFIG_MBO
358 if (hapd->conf->mbo_enabled)
359 *pos |= 0x40; /* Bit 46 - WNM-Notification */
360 #endif /* CONFIG_MBO */
361 break;
362 case 6: /* Bits 48-55 */
363 if (hapd->conf->ssid.utf8_ssid)
364 *pos |= 0x01; /* Bit 48 - UTF-8 SSID */
365 break;
366 case 7: /* Bits 56-63 */
367 break;
368 case 8: /* Bits 64-71 */
369 if (hapd->conf->ftm_responder)
370 *pos |= 0x40; /* Bit 70 - FTM responder */
371 if (hapd->conf->ftm_initiator)
372 *pos |= 0x80; /* Bit 71 - FTM initiator */
373 break;
374 case 9: /* Bits 72-79 */
375 #ifdef CONFIG_FILS
376 if ((hapd->conf->wpa & WPA_PROTO_RSN) &&
377 wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt))
378 *pos |= 0x01;
379 #endif /* CONFIG_FILS */
380 #ifdef CONFIG_IEEE80211AX
381 if (hapd->iconf->ieee80211ax &&
382 hostapd_get_he_twt_responder(hapd, IEEE80211_MODE_AP))
383 *pos |= 0x40; /* Bit 78 - TWT responder */
384 #endif /* CONFIG_IEEE80211AX */
385 break;
386 case 10: /* Bits 80-87 */
387 #ifdef CONFIG_SAE
388 if (hapd->conf->wpa &&
389 wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt)) {
390 int in_use = hostapd_sae_pw_id_in_use(hapd->conf);
391
392 if (in_use)
393 *pos |= 0x02; /* Bit 81 - SAE Password
394 * Identifiers In Use */
395 if (in_use == 2)
396 *pos |= 0x04; /* Bit 82 - SAE Password
397 * Identifiers Used Exclusively */
398 }
399 #endif /* CONFIG_SAE */
400 break;
401 }
402 }
403
404
405 u8 * hostapd_eid_ext_capab(struct hostapd_data *hapd, u8 *eid)
406 {
407 u8 *pos = eid;
408 u8 len = 0, i;
409
410 if (hapd->conf->qos_map_set_len ||
411 (hapd->conf->tdls & (TDLS_PROHIBIT | TDLS_PROHIBIT_CHAN_SWITCH)))
412 len = 5;
413 if (len < 4 &&
414 (hapd->conf->time_advertisement == 2 || hapd->conf->interworking))
415 len = 4;
416 if (len < 3 &&
417 (hapd->conf->wnm_sleep_mode || hapd->conf->bss_transition))
418 len = 3;
419 if (len < 1 &&
420 (hapd->iconf->obss_interval ||
421 (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)))
422 len = 1;
423 if (len < 2 &&
424 (hapd->conf->proxy_arp || hapd->conf->coloc_intf_reporting))
425 len = 2;
426 if (len < 7 && hapd->conf->ssid.utf8_ssid)
427 len = 7;
428 if (len < 9 &&
429 (hapd->conf->ftm_initiator || hapd->conf->ftm_responder))
430 len = 9;
431 #ifdef CONFIG_WNM_AP
432 if (len < 4)
433 len = 4;
434 #endif /* CONFIG_WNM_AP */
435 #ifdef CONFIG_HS20
436 if (hapd->conf->hs20 && len < 6)
437 len = 6;
438 #endif /* CONFIG_HS20 */
439 #ifdef CONFIG_MBO
440 if (hapd->conf->mbo_enabled && len < 6)
441 len = 6;
442 #endif /* CONFIG_MBO */
443 #ifdef CONFIG_FILS
444 if ((!(hapd->conf->wpa & WPA_PROTO_RSN) ||
445 !wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt)) && len < 10)
446 len = 10;
447 #endif /* CONFIG_FILS */
448 #ifdef CONFIG_IEEE80211AX
449 if (len < 10 && hapd->iconf->ieee80211ax &&
450 hostapd_get_he_twt_responder(hapd, IEEE80211_MODE_AP))
451 len = 10;
452 #endif /* CONFIG_IEEE80211AX */
453 #ifdef CONFIG_SAE
454 if (len < 11 && hapd->conf->wpa &&
455 wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
456 hostapd_sae_pw_id_in_use(hapd->conf))
457 len = 11;
458 #endif /* CONFIG_SAE */
459 if (len < hapd->iface->extended_capa_len)
460 len = hapd->iface->extended_capa_len;
461 if (len == 0)
462 return eid;
463
464 *pos++ = WLAN_EID_EXT_CAPAB;
465 *pos++ = len;
466 for (i = 0; i < len; i++, pos++) {
467 hostapd_ext_capab_byte(hapd, pos, i);
468
469 if (i < hapd->iface->extended_capa_len) {
470 *pos &= ~hapd->iface->extended_capa_mask[i];
471 *pos |= hapd->iface->extended_capa[i];
472 }
473 }
474
475 while (len > 0 && eid[1 + len] == 0) {
476 len--;
477 eid[1] = len;
478 }
479 if (len == 0)
480 return eid;
481
482 return eid + 2 + len;
483 }
484
485
486 u8 * hostapd_eid_qos_map_set(struct hostapd_data *hapd, u8 *eid)
487 {
488 u8 *pos = eid;
489 u8 len = hapd->conf->qos_map_set_len;
490
491 if (!len)
492 return eid;
493
494 *pos++ = WLAN_EID_QOS_MAP_SET;
495 *pos++ = len;
496 os_memcpy(pos, hapd->conf->qos_map_set, len);
497 pos += len;
498
499 return pos;
500 }
501
502
503 u8 * hostapd_eid_interworking(struct hostapd_data *hapd, u8 *eid)
504 {
505 u8 *pos = eid;
506 #ifdef CONFIG_INTERWORKING
507 u8 *len;
508
509 if (!hapd->conf->interworking)
510 return eid;
511
512 *pos++ = WLAN_EID_INTERWORKING;
513 len = pos++;
514
515 *pos = hapd->conf->access_network_type;
516 if (hapd->conf->internet)
517 *pos |= INTERWORKING_ANO_INTERNET;
518 if (hapd->conf->asra)
519 *pos |= INTERWORKING_ANO_ASRA;
520 if (hapd->conf->esr)
521 *pos |= INTERWORKING_ANO_ESR;
522 if (hapd->conf->uesa)
523 *pos |= INTERWORKING_ANO_UESA;
524 pos++;
525
526 if (hapd->conf->venue_info_set) {
527 *pos++ = hapd->conf->venue_group;
528 *pos++ = hapd->conf->venue_type;
529 }
530
531 if (!is_zero_ether_addr(hapd->conf->hessid)) {
532 os_memcpy(pos, hapd->conf->hessid, ETH_ALEN);
533 pos += ETH_ALEN;
534 }
535
536 *len = pos - len - 1;
537 #endif /* CONFIG_INTERWORKING */
538
539 return pos;
540 }
541
542
543 u8 * hostapd_eid_adv_proto(struct hostapd_data *hapd, u8 *eid)
544 {
545 u8 *pos = eid;
546 #ifdef CONFIG_INTERWORKING
547
548 /* TODO: Separate configuration for ANQP? */
549 if (!hapd->conf->interworking)
550 return eid;
551
552 *pos++ = WLAN_EID_ADV_PROTO;
553 *pos++ = 2;
554 *pos++ = 0x7F; /* Query Response Length Limit | PAME-BI */
555 *pos++ = ACCESS_NETWORK_QUERY_PROTOCOL;
556 #endif /* CONFIG_INTERWORKING */
557
558 return pos;
559 }
560
561
562 u8 * hostapd_eid_roaming_consortium(struct hostapd_data *hapd, u8 *eid)
563 {
564 u8 *pos = eid;
565 #ifdef CONFIG_INTERWORKING
566 u8 *len;
567 unsigned int i, count;
568
569 if (!hapd->conf->interworking ||
570 hapd->conf->roaming_consortium == NULL ||
571 hapd->conf->roaming_consortium_count == 0)
572 return eid;
573
574 *pos++ = WLAN_EID_ROAMING_CONSORTIUM;
575 len = pos++;
576
577 /* Number of ANQP OIs (in addition to the max 3 listed here) */
578 if (hapd->conf->roaming_consortium_count > 3 + 255)
579 *pos++ = 255;
580 else if (hapd->conf->roaming_consortium_count > 3)
581 *pos++ = hapd->conf->roaming_consortium_count - 3;
582 else
583 *pos++ = 0;
584
585 /* OU #1 and #2 Lengths */
586 *pos = hapd->conf->roaming_consortium[0].len;
587 if (hapd->conf->roaming_consortium_count > 1)
588 *pos |= hapd->conf->roaming_consortium[1].len << 4;
589 pos++;
590
591 if (hapd->conf->roaming_consortium_count > 3)
592 count = 3;
593 else
594 count = hapd->conf->roaming_consortium_count;
595
596 for (i = 0; i < count; i++) {
597 os_memcpy(pos, hapd->conf->roaming_consortium[i].oi,
598 hapd->conf->roaming_consortium[i].len);
599 pos += hapd->conf->roaming_consortium[i].len;
600 }
601
602 *len = pos - len - 1;
603 #endif /* CONFIG_INTERWORKING */
604
605 return pos;
606 }
607
608
609 u8 * hostapd_eid_time_adv(struct hostapd_data *hapd, u8 *eid)
610 {
611 if (hapd->conf->time_advertisement != 2)
612 return eid;
613
614 if (hapd->time_adv == NULL &&
615 hostapd_update_time_adv(hapd) < 0)
616 return eid;
617
618 if (hapd->time_adv == NULL)
619 return eid;
620
621 os_memcpy(eid, wpabuf_head(hapd->time_adv),
622 wpabuf_len(hapd->time_adv));
623 eid += wpabuf_len(hapd->time_adv);
624
625 return eid;
626 }
627
628
629 u8 * hostapd_eid_time_zone(struct hostapd_data *hapd, u8 *eid)
630 {
631 size_t len;
632
633 if (hapd->conf->time_advertisement != 2 || !hapd->conf->time_zone)
634 return eid;
635
636 len = os_strlen(hapd->conf->time_zone);
637
638 *eid++ = WLAN_EID_TIME_ZONE;
639 *eid++ = len;
640 os_memcpy(eid, hapd->conf->time_zone, len);
641 eid += len;
642
643 return eid;
644 }
645
646
647 int hostapd_update_time_adv(struct hostapd_data *hapd)
648 {
649 const int elen = 2 + 1 + 10 + 5 + 1;
650 struct os_time t;
651 struct os_tm tm;
652 u8 *pos;
653
654 if (hapd->conf->time_advertisement != 2)
655 return 0;
656
657 if (os_get_time(&t) < 0 || os_gmtime(t.sec, &tm) < 0)
658 return -1;
659
660 if (!hapd->time_adv) {
661 hapd->time_adv = wpabuf_alloc(elen);
662 if (hapd->time_adv == NULL)
663 return -1;
664 pos = wpabuf_put(hapd->time_adv, elen);
665 } else
666 pos = wpabuf_mhead_u8(hapd->time_adv);
667
668 *pos++ = WLAN_EID_TIME_ADVERTISEMENT;
669 *pos++ = 1 + 10 + 5 + 1;
670
671 *pos++ = 2; /* UTC time at which the TSF timer is 0 */
672
673 /* Time Value at TSF 0 */
674 /* FIX: need to calculate this based on the current TSF value */
675 WPA_PUT_LE16(pos, tm.year); /* Year */
676 pos += 2;
677 *pos++ = tm.month; /* Month */
678 *pos++ = tm.day; /* Day of month */
679 *pos++ = tm.hour; /* Hours */
680 *pos++ = tm.min; /* Minutes */
681 *pos++ = tm.sec; /* Seconds */
682 WPA_PUT_LE16(pos, 0); /* Milliseconds (not used) */
683 pos += 2;
684 *pos++ = 0; /* Reserved */
685
686 /* Time Error */
687 /* TODO: fill in an estimate on the error */
688 *pos++ = 0;
689 *pos++ = 0;
690 *pos++ = 0;
691 *pos++ = 0;
692 *pos++ = 0;
693
694 *pos++ = hapd->time_update_counter++;
695
696 return 0;
697 }
698
699
700 u8 * hostapd_eid_bss_max_idle_period(struct hostapd_data *hapd, u8 *eid)
701 {
702 u8 *pos = eid;
703
704 #ifdef CONFIG_WNM_AP
705 if (hapd->conf->ap_max_inactivity > 0) {
706 unsigned int val;
707 *pos++ = WLAN_EID_BSS_MAX_IDLE_PERIOD;
708 *pos++ = 3;
709 val = hapd->conf->ap_max_inactivity;
710 if (val > 68000)
711 val = 68000;
712 val *= 1000;
713 val /= 1024;
714 if (val == 0)
715 val = 1;
716 if (val > 65535)
717 val = 65535;
718 WPA_PUT_LE16(pos, val);
719 pos += 2;
720 *pos++ = 0x00; /* TODO: Protected Keep-Alive Required */
721 }
722 #endif /* CONFIG_WNM_AP */
723
724 return pos;
725 }
726
727
728 #ifdef CONFIG_MBO
729
730 u8 * hostapd_eid_mbo_rssi_assoc_rej(struct hostapd_data *hapd, u8 *eid,
731 size_t len, int delta)
732 {
733 u8 mbo[4];
734
735 mbo[0] = OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT;
736 mbo[1] = 2;
737 /* Delta RSSI */
738 mbo[2] = delta;
739 /* Retry delay */
740 mbo[3] = hapd->iconf->rssi_reject_assoc_timeout;
741
742 return eid + mbo_add_ie(eid, len, mbo, 4);
743 }
744
745
746 u8 * hostapd_eid_mbo(struct hostapd_data *hapd, u8 *eid, size_t len)
747 {
748 u8 mbo[9], *mbo_pos = mbo;
749 u8 *pos = eid;
750
751 if (!hapd->conf->mbo_enabled &&
752 !OCE_STA_CFON_ENABLED(hapd) && !OCE_AP_ENABLED(hapd))
753 return eid;
754
755 if (hapd->conf->mbo_enabled) {
756 *mbo_pos++ = MBO_ATTR_ID_AP_CAPA_IND;
757 *mbo_pos++ = 1;
758 /* Not Cellular aware */
759 *mbo_pos++ = 0;
760 }
761
762 if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
763 *mbo_pos++ = MBO_ATTR_ID_ASSOC_DISALLOW;
764 *mbo_pos++ = 1;
765 *mbo_pos++ = hapd->mbo_assoc_disallow;
766 }
767
768 if (OCE_STA_CFON_ENABLED(hapd) || OCE_AP_ENABLED(hapd)) {
769 u8 ctrl;
770
771 ctrl = OCE_RELEASE;
772 if (OCE_STA_CFON_ENABLED(hapd) && !OCE_AP_ENABLED(hapd))
773 ctrl |= OCE_IS_STA_CFON;
774
775 *mbo_pos++ = OCE_ATTR_ID_CAPA_IND;
776 *mbo_pos++ = 1;
777 *mbo_pos++ = ctrl;
778 }
779
780 pos += mbo_add_ie(pos, len, mbo, mbo_pos - mbo);
781
782 return pos;
783 }
784
785
786 u8 hostapd_mbo_ie_len(struct hostapd_data *hapd)
787 {
788 u8 len;
789
790 if (!hapd->conf->mbo_enabled &&
791 !OCE_STA_CFON_ENABLED(hapd) && !OCE_AP_ENABLED(hapd))
792 return 0;
793
794 /*
795 * MBO IE header (6) + Capability Indication attribute (3) +
796 * Association Disallowed attribute (3) = 12
797 */
798 len = 6;
799 if (hapd->conf->mbo_enabled)
800 len += 3 + (hapd->mbo_assoc_disallow ? 3 : 0);
801
802 /* OCE capability indication attribute (3) */
803 if (OCE_STA_CFON_ENABLED(hapd) || OCE_AP_ENABLED(hapd))
804 len += 3;
805
806 return len;
807 }
808
809 #endif /* CONFIG_MBO */
810
811
812 #ifdef CONFIG_OWE
813 static int hostapd_eid_owe_trans_enabled(struct hostapd_data *hapd)
814 {
815 return hapd->conf->owe_transition_ssid_len > 0 &&
816 !is_zero_ether_addr(hapd->conf->owe_transition_bssid);
817 }
818 #endif /* CONFIG_OWE */
819
820
821 size_t hostapd_eid_owe_trans_len(struct hostapd_data *hapd)
822 {
823 #ifdef CONFIG_OWE
824 if (!hostapd_eid_owe_trans_enabled(hapd))
825 return 0;
826 return 6 + ETH_ALEN + 1 + hapd->conf->owe_transition_ssid_len;
827 #else /* CONFIG_OWE */
828 return 0;
829 #endif /* CONFIG_OWE */
830 }
831
832
833 u8 * hostapd_eid_owe_trans(struct hostapd_data *hapd, u8 *eid,
834 size_t len)
835 {
836 #ifdef CONFIG_OWE
837 u8 *pos = eid;
838 size_t elen;
839
840 if (hapd->conf->owe_transition_ifname[0] &&
841 !hostapd_eid_owe_trans_enabled(hapd))
842 hostapd_owe_trans_get_info(hapd);
843
844 if (!hostapd_eid_owe_trans_enabled(hapd))
845 return pos;
846
847 elen = hostapd_eid_owe_trans_len(hapd);
848 if (len < elen) {
849 wpa_printf(MSG_DEBUG,
850 "OWE: Not enough room in the buffer for OWE IE");
851 return pos;
852 }
853
854 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
855 *pos++ = elen - 2;
856 WPA_PUT_BE24(pos, OUI_WFA);
857 pos += 3;
858 *pos++ = OWE_OUI_TYPE;
859 os_memcpy(pos, hapd->conf->owe_transition_bssid, ETH_ALEN);
860 pos += ETH_ALEN;
861 *pos++ = hapd->conf->owe_transition_ssid_len;
862 os_memcpy(pos, hapd->conf->owe_transition_ssid,
863 hapd->conf->owe_transition_ssid_len);
864 pos += hapd->conf->owe_transition_ssid_len;
865
866 return pos;
867 #else /* CONFIG_OWE */
868 return eid;
869 #endif /* CONFIG_OWE */
870 }
871
872
873 void ap_copy_sta_supp_op_classes(struct sta_info *sta,
874 const u8 *supp_op_classes,
875 size_t supp_op_classes_len)
876 {
877 if (!supp_op_classes)
878 return;
879 os_free(sta->supp_op_classes);
880 sta->supp_op_classes = os_malloc(1 + supp_op_classes_len);
881 if (!sta->supp_op_classes)
882 return;
883
884 sta->supp_op_classes[0] = supp_op_classes_len;
885 os_memcpy(sta->supp_op_classes + 1, supp_op_classes,
886 supp_op_classes_len);
887 }
888
889
890 u8 * hostapd_eid_fils_indic(struct hostapd_data *hapd, u8 *eid, int hessid)
891 {
892 u8 *pos = eid;
893 #ifdef CONFIG_FILS
894 u8 *len;
895 u16 fils_info = 0;
896 size_t realms;
897 struct fils_realm *realm;
898
899 if (!(hapd->conf->wpa & WPA_PROTO_RSN) ||
900 !wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt))
901 return pos;
902
903 realms = dl_list_len(&hapd->conf->fils_realms);
904 if (realms > 7)
905 realms = 7; /* 3 bit count field limits this to max 7 */
906
907 *pos++ = WLAN_EID_FILS_INDICATION;
908 len = pos++;
909 /* TODO: B0..B2: Number of Public Key Identifiers */
910 if (hapd->conf->erp_domain) {
911 /* B3..B5: Number of Realm Identifiers */
912 fils_info |= realms << 3;
913 }
914 /* TODO: B6: FILS IP Address Configuration */
915 if (hapd->conf->fils_cache_id_set)
916 fils_info |= BIT(7);
917 if (hessid && !is_zero_ether_addr(hapd->conf->hessid))
918 fils_info |= BIT(8); /* HESSID Included */
919 /* FILS Shared Key Authentication without PFS Supported */
920 fils_info |= BIT(9);
921 if (hapd->conf->fils_dh_group) {
922 /* FILS Shared Key Authentication with PFS Supported */
923 fils_info |= BIT(10);
924 }
925 /* TODO: B11: FILS Public Key Authentication Supported */
926 /* B12..B15: Reserved */
927 WPA_PUT_LE16(pos, fils_info);
928 pos += 2;
929 if (hapd->conf->fils_cache_id_set) {
930 os_memcpy(pos, hapd->conf->fils_cache_id, FILS_CACHE_ID_LEN);
931 pos += FILS_CACHE_ID_LEN;
932 }
933 if (hessid && !is_zero_ether_addr(hapd->conf->hessid)) {
934 os_memcpy(pos, hapd->conf->hessid, ETH_ALEN);
935 pos += ETH_ALEN;
936 }
937
938 dl_list_for_each(realm, &hapd->conf->fils_realms, struct fils_realm,
939 list) {
940 if (realms == 0)
941 break;
942 realms--;
943 os_memcpy(pos, realm->hash, 2);
944 pos += 2;
945 }
946 *len = pos - len - 1;
947 #endif /* CONFIG_FILS */
948
949 return pos;
950 }
951
952
953 #ifdef CONFIG_OCV
954 int get_tx_parameters(struct sta_info *sta, int ap_max_chanwidth,
955 int ap_seg1_idx, int *bandwidth, int *seg1_idx)
956 {
957 int ht_40mhz = 0;
958 int vht_80p80 = 0;
959 int requested_bw;
960
961 if (sta->ht_capabilities)
962 ht_40mhz = !!(sta->ht_capabilities->ht_capabilities_info &
963 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET);
964
965 if (sta->vht_operation) {
966 struct ieee80211_vht_operation *oper = sta->vht_operation;
967
968 /*
969 * If a VHT Operation element was present, use it to determine
970 * the supported channel bandwidth.
971 */
972 if (oper->vht_op_info_chwidth == 0) {
973 requested_bw = ht_40mhz ? 40 : 20;
974 } else if (oper->vht_op_info_chan_center_freq_seg1_idx == 0) {
975 requested_bw = 80;
976 } else {
977 int diff;
978
979 requested_bw = 160;
980 diff = abs((int)
981 oper->vht_op_info_chan_center_freq_seg0_idx -
982 (int)
983 oper->vht_op_info_chan_center_freq_seg1_idx);
984 vht_80p80 = oper->vht_op_info_chan_center_freq_seg1_idx
985 != 0 && diff > 16;
986 }
987 } else if (sta->vht_capabilities) {
988 struct ieee80211_vht_capabilities *capab;
989 int vht_chanwidth;
990
991 capab = sta->vht_capabilities;
992
993 /*
994 * If only the VHT Capabilities element is present (e.g., for
995 * normal clients), use it to determine the supported channel
996 * bandwidth.
997 */
998 vht_chanwidth = capab->vht_capabilities_info &
999 VHT_CAP_SUPP_CHAN_WIDTH_MASK;
1000 vht_80p80 = capab->vht_capabilities_info &
1001 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
1002
1003 /* TODO: Also take into account Extended NSS BW Support field */
1004 requested_bw = vht_chanwidth ? 160 : 80;
1005 } else {
1006 requested_bw = ht_40mhz ? 40 : 20;
1007 }
1008
1009 *bandwidth = requested_bw < ap_max_chanwidth ?
1010 requested_bw : ap_max_chanwidth;
1011
1012 *seg1_idx = 0;
1013 if (ap_seg1_idx && vht_80p80)
1014 *seg1_idx = ap_seg1_idx;
1015
1016 return 0;
1017 }
1018 #endif /* CONFIG_OCV */
1019
1020
1021 u8 * hostapd_eid_rsnxe(struct hostapd_data *hapd, u8 *eid, size_t len)
1022 {
1023 u8 *pos = eid;
1024
1025 if (!(hapd->conf->wpa & WPA_PROTO_RSN) ||
1026 !wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) ||
1027 (hapd->conf->sae_pwe != 1 && hapd->conf->sae_pwe != 2 &&
1028 !hostapd_sae_pw_id_in_use(hapd->conf)) ||
1029 hapd->conf->sae_pwe == 3 ||
1030 len < 3)
1031 return pos;
1032
1033 *pos++ = WLAN_EID_RSNX;
1034 *pos++ = 1;
1035 /* bits 0-3 = 0 since only one octet of Extended RSN Capabilities is
1036 * used for now */
1037 *pos++ = BIT(WLAN_RSNX_CAPAB_SAE_H2E);
1038
1039 return pos;
1040 }