3 * Copyright (c) 2011-2013, Qualcomm Atheros, Inc.
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"
13 #include "common/ieee802_11_common.h"
14 #include "common/wpa_ctrl.h"
15 #include "common/ocv.h"
16 #include "rsn_supp/wpa.h"
18 #include "wpa_supplicant_i.h"
21 #include "ctrl_iface.h"
25 #include "hs20_supplicant.h"
27 #define MAX_TFS_IE_LEN 1024
28 #define WNM_MAX_NEIGHBOR_REPORT 10
30 #define WNM_SCAN_RESULT_AGE 2 /* 2 seconds */
32 /* get the TFS IE from driver */
33 static int ieee80211_11_get_tfs_ie(struct wpa_supplicant
*wpa_s
, u8
*buf
,
34 u16
*buf_len
, enum wnm_oper oper
)
36 wpa_printf(MSG_DEBUG
, "%s: TFS get operation %d", __func__
, oper
);
38 return wpa_drv_wnm_oper(wpa_s
, oper
, wpa_s
->bssid
, buf
, buf_len
);
42 /* set the TFS IE to driver */
43 static int ieee80211_11_set_tfs_ie(struct wpa_supplicant
*wpa_s
,
44 const u8
*addr
, const u8
*buf
, u16 buf_len
,
49 wpa_printf(MSG_DEBUG
, "%s: TFS set operation %d", __func__
, oper
);
51 return wpa_drv_wnm_oper(wpa_s
, oper
, addr
, (u8
*) buf
, &len
);
55 /* MLME-SLEEPMODE.request */
56 int ieee802_11_send_wnmsleep_req(struct wpa_supplicant
*wpa_s
,
57 u8 action
, u16 intval
, struct wpabuf
*tfs_req
)
59 struct ieee80211_mgmt
*mgmt
;
62 struct wnm_sleep_element
*wnmsleep_ie
;
63 u8
*wnmtfs_ie
, *oci_ie
;
64 u8 wnmsleep_ie_len
, oci_ie_len
;
65 u16 wnmtfs_ie_len
; /* possibly multiple IE(s) */
66 enum wnm_oper tfs_oper
= action
== 0 ? WNM_SLEEP_TFS_REQ_IE_ADD
:
67 WNM_SLEEP_TFS_REQ_IE_NONE
;
69 wpa_printf(MSG_DEBUG
, "WNM: Request to send WNM-Sleep Mode Request "
70 "action=%s to " MACSTR
,
71 action
== 0 ? "enter" : "exit",
72 MAC2STR(wpa_s
->bssid
));
74 /* WNM-Sleep Mode IE */
75 wnmsleep_ie_len
= sizeof(struct wnm_sleep_element
);
76 wnmsleep_ie
= os_zalloc(sizeof(struct wnm_sleep_element
));
77 if (wnmsleep_ie
== NULL
)
79 wnmsleep_ie
->eid
= WLAN_EID_WNMSLEEP
;
80 wnmsleep_ie
->len
= wnmsleep_ie_len
- 2;
81 wnmsleep_ie
->action_type
= action
;
82 wnmsleep_ie
->status
= WNM_STATUS_SLEEP_ACCEPT
;
83 wnmsleep_ie
->intval
= host_to_le16(intval
);
84 wpa_hexdump(MSG_DEBUG
, "WNM: WNM-Sleep Mode element",
85 (u8
*) wnmsleep_ie
, wnmsleep_ie_len
);
89 wnmtfs_ie_len
= wpabuf_len(tfs_req
);
90 wnmtfs_ie
= os_memdup(wpabuf_head(tfs_req
), wnmtfs_ie_len
);
91 if (wnmtfs_ie
== NULL
) {
96 wnmtfs_ie
= os_zalloc(MAX_TFS_IE_LEN
);
97 if (wnmtfs_ie
== NULL
) {
101 if (ieee80211_11_get_tfs_ie(wpa_s
, wnmtfs_ie
, &wnmtfs_ie_len
,
108 wpa_hexdump(MSG_DEBUG
, "WNM: TFS Request element",
109 (u8
*) wnmtfs_ie
, wnmtfs_ie_len
);
114 if (action
== WNM_SLEEP_MODE_EXIT
&& wpa_sm_ocv_enabled(wpa_s
->wpa
)) {
115 struct wpa_channel_info ci
;
117 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
118 wpa_printf(MSG_WARNING
,
119 "Failed to get channel info for OCI element in WNM-Sleep Mode frame");
120 os_free(wnmsleep_ie
);
125 oci_ie_len
= OCV_OCI_EXTENDED_LEN
;
126 oci_ie
= os_zalloc(oci_ie_len
);
128 wpa_printf(MSG_WARNING
,
129 "Failed to allocate buffer for for OCI element in WNM-Sleep Mode frame");
130 os_free(wnmsleep_ie
);
135 if (ocv_insert_extended_oci(&ci
, oci_ie
) < 0) {
136 os_free(wnmsleep_ie
);
142 #endif /* CONFIG_OCV */
144 mgmt
= os_zalloc(sizeof(*mgmt
) + wnmsleep_ie_len
+ wnmtfs_ie_len
+
147 wpa_printf(MSG_DEBUG
, "MLME: Failed to allocate buffer for "
148 "WNM-Sleep Request action frame");
149 os_free(wnmsleep_ie
);
154 os_memcpy(mgmt
->da
, wpa_s
->bssid
, ETH_ALEN
);
155 os_memcpy(mgmt
->sa
, wpa_s
->own_addr
, ETH_ALEN
);
156 os_memcpy(mgmt
->bssid
, wpa_s
->bssid
, ETH_ALEN
);
157 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
158 WLAN_FC_STYPE_ACTION
);
159 mgmt
->u
.action
.category
= WLAN_ACTION_WNM
;
160 mgmt
->u
.action
.u
.wnm_sleep_req
.action
= WNM_SLEEP_MODE_REQ
;
161 mgmt
->u
.action
.u
.wnm_sleep_req
.dialogtoken
= 1;
162 os_memcpy(mgmt
->u
.action
.u
.wnm_sleep_req
.variable
, wnmsleep_ie
,
164 /* copy TFS IE here */
165 if (wnmtfs_ie_len
> 0) {
166 os_memcpy(mgmt
->u
.action
.u
.wnm_sleep_req
.variable
+
167 wnmsleep_ie_len
, wnmtfs_ie
, wnmtfs_ie_len
);
171 /* copy OCV OCI here */
172 if (oci_ie_len
> 0) {
173 os_memcpy(mgmt
->u
.action
.u
.wnm_sleep_req
.variable
+
174 wnmsleep_ie_len
+ wnmtfs_ie_len
, oci_ie
, oci_ie_len
);
176 #endif /* CONFIG_OCV */
178 len
= 1 + sizeof(mgmt
->u
.action
.u
.wnm_sleep_req
) + wnmsleep_ie_len
+
179 wnmtfs_ie_len
+ oci_ie_len
;
181 res
= wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
182 wpa_s
->own_addr
, wpa_s
->bssid
,
183 &mgmt
->u
.action
.category
, len
, 0);
185 wpa_printf(MSG_DEBUG
, "Failed to send WNM-Sleep Request "
186 "(action=%d, intval=%d)", action
, intval
);
188 wpa_s
->wnmsleep_used
= 1;
190 os_free(wnmsleep_ie
);
199 static void wnm_sleep_mode_enter_success(struct wpa_supplicant
*wpa_s
,
200 const u8
*tfsresp_ie_start
,
201 const u8
*tfsresp_ie_end
)
203 wpa_drv_wnm_oper(wpa_s
, WNM_SLEEP_ENTER_CONFIRM
,
204 wpa_s
->bssid
, NULL
, NULL
);
205 /* remove GTK/IGTK ?? */
207 /* set the TFS Resp IE(s) */
208 if (tfsresp_ie_start
&& tfsresp_ie_end
&&
209 tfsresp_ie_end
- tfsresp_ie_start
>= 0) {
211 tfsresp_ie_len
= (tfsresp_ie_end
+ tfsresp_ie_end
[1] + 2) -
213 wpa_printf(MSG_DEBUG
, "TFS Resp IE(s) found");
214 /* pass the TFS Resp IE(s) to driver for processing */
215 if (ieee80211_11_set_tfs_ie(wpa_s
, wpa_s
->bssid
,
218 WNM_SLEEP_TFS_RESP_IE_SET
))
219 wpa_printf(MSG_DEBUG
, "WNM: Fail to set TFS Resp IE");
224 static void wnm_sleep_mode_exit_success(struct wpa_supplicant
*wpa_s
,
225 const u8
*frm
, u16 key_len_total
)
230 wpa_drv_wnm_oper(wpa_s
, WNM_SLEEP_EXIT_CONFIRM
, wpa_s
->bssid
,
233 /* Install GTK/IGTK */
235 /* point to key data field */
236 ptr
= (u8
*) frm
+ 1 + 2;
237 end
= ptr
+ key_len_total
;
238 wpa_hexdump_key(MSG_DEBUG
, "WNM: Key Data", ptr
, key_len_total
);
240 if (key_len_total
&& !wpa_sm_pmf_enabled(wpa_s
->wpa
)) {
241 wpa_msg(wpa_s
, MSG_INFO
,
242 "WNM: Ignore Key Data in WNM-Sleep Mode Response - PMF not enabled");
246 while (end
- ptr
> 1) {
247 if (2 + ptr
[1] > end
- ptr
) {
248 wpa_printf(MSG_DEBUG
, "WNM: Invalid Key Data element "
251 wpa_hexdump(MSG_DEBUG
, "WNM: Remaining data",
256 if (*ptr
== WNM_SLEEP_SUBELEM_GTK
) {
257 if (ptr
[1] < 11 + 5) {
258 wpa_printf(MSG_DEBUG
, "WNM: Too short GTK "
262 gtk_len
= *(ptr
+ 4);
263 if (ptr
[1] < 11 + gtk_len
||
264 gtk_len
< 5 || gtk_len
> 32) {
265 wpa_printf(MSG_DEBUG
, "WNM: Invalid GTK "
269 wpa_wnmsleep_install_key(
271 WNM_SLEEP_SUBELEM_GTK
,
274 } else if (*ptr
== WNM_SLEEP_SUBELEM_IGTK
) {
275 if (ptr
[1] < 2 + 6 + WPA_IGTK_LEN
) {
276 wpa_printf(MSG_DEBUG
, "WNM: Too short IGTK "
280 wpa_wnmsleep_install_key(wpa_s
->wpa
,
281 WNM_SLEEP_SUBELEM_IGTK
, ptr
);
282 ptr
+= 10 + WPA_IGTK_LEN
;
284 break; /* skip the loop */
289 static void ieee802_11_rx_wnmsleep_resp(struct wpa_supplicant
*wpa_s
,
290 const u8
*frm
, int len
)
293 * Action [1] | Dialog Token [1] | Key Data Len [2] | Key Data |
294 * WNM-Sleep Mode IE | TFS Response IE
296 const u8
*pos
= frm
; /* point to payload after the action field */
298 struct wnm_sleep_element
*wnmsleep_ie
= NULL
;
299 /* multiple TFS Resp IE (assuming consecutive) */
300 const u8
*tfsresp_ie_start
= NULL
;
301 const u8
*tfsresp_ie_end
= NULL
;
303 const u8
*oci_ie
= NULL
;
305 #endif /* CONFIG_OCV */
308 if (!wpa_s
->wnmsleep_used
) {
309 wpa_printf(MSG_DEBUG
,
310 "WNM: Ignore WNM-Sleep Mode Response frame since WNM-Sleep Mode operation has not been requested");
316 key_len_total
= WPA_GET_LE16(frm
+ 1);
318 wpa_printf(MSG_DEBUG
, "WNM-Sleep Mode Response token=%u key_len_total=%d",
319 frm
[0], key_len_total
);
321 if (key_len_total
> left
) {
322 wpa_printf(MSG_INFO
, "WNM: Too short frame for Key Data field");
325 pos
+= 3 + key_len_total
;
326 while (pos
- frm
+ 1 < len
) {
327 u8 ie_len
= *(pos
+ 1);
328 if (2 + ie_len
> frm
+ len
- pos
) {
329 wpa_printf(MSG_INFO
, "WNM: Invalid IE len %u", ie_len
);
332 wpa_hexdump(MSG_DEBUG
, "WNM: Element", pos
, 2 + ie_len
);
333 if (*pos
== WLAN_EID_WNMSLEEP
&& ie_len
>= 4)
334 wnmsleep_ie
= (struct wnm_sleep_element
*) pos
;
335 else if (*pos
== WLAN_EID_TFS_RESP
) {
336 if (!tfsresp_ie_start
)
337 tfsresp_ie_start
= pos
;
338 tfsresp_ie_end
= pos
;
340 } else if (*pos
== WLAN_EID_EXTENSION
&& ie_len
>= 1 &&
341 pos
[2] == WLAN_EID_EXT_OCV_OCI
) {
343 oci_ie_len
= ie_len
- 1;
344 #endif /* CONFIG_OCV */
346 wpa_printf(MSG_DEBUG
, "EID %d not recognized", *pos
);
351 wpa_printf(MSG_DEBUG
, "No WNM-Sleep IE found");
356 if (wnmsleep_ie
->action_type
== WNM_SLEEP_MODE_EXIT
&&
357 wpa_sm_ocv_enabled(wpa_s
->wpa
)) {
358 struct wpa_channel_info ci
;
360 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
361 wpa_msg(wpa_s
, MSG_WARNING
,
362 "Failed to get channel info to validate received OCI in WNM-Sleep Mode frame");
366 if (ocv_verify_tx_params(oci_ie
, oci_ie_len
, &ci
,
367 channel_width_to_int(ci
.chanwidth
),
369 wpa_msg(wpa_s
, MSG_WARNING
, "WNM: %s", ocv_errorstr
);
373 #endif /* CONFIG_OCV */
375 wpa_s
->wnmsleep_used
= 0;
377 if (wnmsleep_ie
->status
== WNM_STATUS_SLEEP_ACCEPT
||
378 wnmsleep_ie
->status
== WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE
) {
379 wpa_printf(MSG_DEBUG
, "Successfully recv WNM-Sleep Response "
380 "frame (action=%d, intval=%d)",
381 wnmsleep_ie
->action_type
, wnmsleep_ie
->intval
);
382 if (wnmsleep_ie
->action_type
== WNM_SLEEP_MODE_ENTER
) {
383 wnm_sleep_mode_enter_success(wpa_s
, tfsresp_ie_start
,
385 } else if (wnmsleep_ie
->action_type
== WNM_SLEEP_MODE_EXIT
) {
386 wnm_sleep_mode_exit_success(wpa_s
, frm
, key_len_total
);
389 wpa_printf(MSG_DEBUG
, "Reject recv WNM-Sleep Response frame "
390 "(action=%d, intval=%d)",
391 wnmsleep_ie
->action_type
, wnmsleep_ie
->intval
);
392 if (wnmsleep_ie
->action_type
== WNM_SLEEP_MODE_ENTER
)
393 wpa_drv_wnm_oper(wpa_s
, WNM_SLEEP_ENTER_FAIL
,
394 wpa_s
->bssid
, NULL
, NULL
);
395 else if (wnmsleep_ie
->action_type
== WNM_SLEEP_MODE_EXIT
)
396 wpa_drv_wnm_oper(wpa_s
, WNM_SLEEP_EXIT_FAIL
,
397 wpa_s
->bssid
, NULL
, NULL
);
402 void wnm_deallocate_memory(struct wpa_supplicant
*wpa_s
)
406 for (i
= 0; i
< wpa_s
->wnm_num_neighbor_report
; i
++) {
407 os_free(wpa_s
->wnm_neighbor_report_elements
[i
].meas_pilot
);
408 os_free(wpa_s
->wnm_neighbor_report_elements
[i
].mul_bssid
);
411 wpa_s
->wnm_num_neighbor_report
= 0;
412 os_free(wpa_s
->wnm_neighbor_report_elements
);
413 wpa_s
->wnm_neighbor_report_elements
= NULL
;
415 wpabuf_free(wpa_s
->coloc_intf_elems
);
416 wpa_s
->coloc_intf_elems
= NULL
;
420 static void wnm_parse_neighbor_report_elem(struct neighbor_report
*rep
,
421 u8 id
, u8 elen
, const u8
*pos
)
424 case WNM_NEIGHBOR_TSF
:
426 wpa_printf(MSG_DEBUG
, "WNM: Too short TSF");
429 rep
->tsf_offset
= WPA_GET_LE16(pos
);
430 rep
->beacon_int
= WPA_GET_LE16(pos
+ 2);
431 rep
->tsf_present
= 1;
433 case WNM_NEIGHBOR_CONDENSED_COUNTRY_STRING
:
435 wpa_printf(MSG_DEBUG
, "WNM: Too short condensed "
439 os_memcpy(rep
->country
, pos
, 2);
440 rep
->country_present
= 1;
442 case WNM_NEIGHBOR_BSS_TRANSITION_CANDIDATE
:
444 wpa_printf(MSG_DEBUG
, "WNM: Too short BSS transition "
448 rep
->preference
= pos
[0];
449 rep
->preference_present
= 1;
451 case WNM_NEIGHBOR_BSS_TERMINATION_DURATION
:
453 wpa_printf(MSG_DEBUG
,
454 "WNM: Too short BSS termination duration");
457 rep
->bss_term_tsf
= WPA_GET_LE64(pos
);
458 rep
->bss_term_dur
= WPA_GET_LE16(pos
+ 8);
459 rep
->bss_term_present
= 1;
461 case WNM_NEIGHBOR_BEARING
:
463 wpa_printf(MSG_DEBUG
, "WNM: Too short neighbor "
467 rep
->bearing
= WPA_GET_LE16(pos
);
468 rep
->distance
= WPA_GET_LE32(pos
+ 2);
469 rep
->rel_height
= WPA_GET_LE16(pos
+ 2 + 4);
470 rep
->bearing_present
= 1;
472 case WNM_NEIGHBOR_MEASUREMENT_PILOT
:
474 wpa_printf(MSG_DEBUG
, "WNM: Too short measurement "
478 os_free(rep
->meas_pilot
);
479 rep
->meas_pilot
= os_zalloc(sizeof(struct measurement_pilot
));
480 if (rep
->meas_pilot
== NULL
)
482 rep
->meas_pilot
->measurement_pilot
= pos
[0];
483 rep
->meas_pilot
->subelem_len
= elen
- 1;
484 os_memcpy(rep
->meas_pilot
->subelems
, pos
+ 1, elen
- 1);
486 case WNM_NEIGHBOR_RRM_ENABLED_CAPABILITIES
:
488 wpa_printf(MSG_DEBUG
, "WNM: Too short RRM enabled "
492 os_memcpy(rep
->rm_capab
, pos
, 5);
493 rep
->rm_capab_present
= 1;
495 case WNM_NEIGHBOR_MULTIPLE_BSSID
:
497 wpa_printf(MSG_DEBUG
, "WNM: Too short multiple BSSID");
500 os_free(rep
->mul_bssid
);
501 rep
->mul_bssid
= os_zalloc(sizeof(struct multiple_bssid
));
502 if (rep
->mul_bssid
== NULL
)
504 rep
->mul_bssid
->max_bssid_indicator
= pos
[0];
505 rep
->mul_bssid
->subelem_len
= elen
- 1;
506 os_memcpy(rep
->mul_bssid
->subelems
, pos
+ 1, elen
- 1);
512 static int wnm_nei_get_chan(struct wpa_supplicant
*wpa_s
, u8 op_class
, u8 chan
)
514 struct wpa_bss
*bss
= wpa_s
->current_bss
;
515 const char *country
= NULL
;
519 const u8
*elem
= wpa_bss_get_ie(bss
, WLAN_EID_COUNTRY
);
521 if (elem
&& elem
[1] >= 2)
522 country
= (const char *) (elem
+ 2);
525 freq
= ieee80211_chan_to_freq(country
, op_class
, chan
);
526 if (freq
<= 0 && op_class
== 0) {
528 * Some APs do not advertise correct operating class
529 * information. Try to determine the most likely operating
530 * frequency based on the channel number.
532 if (chan
>= 1 && chan
<= 13)
533 freq
= 2407 + chan
* 5;
536 else if (chan
>= 36 && chan
<= 169)
537 freq
= 5000 + chan
* 5;
543 static void wnm_parse_neighbor_report(struct wpa_supplicant
*wpa_s
,
544 const u8
*pos
, u8 len
,
545 struct neighbor_report
*rep
)
550 wpa_printf(MSG_DEBUG
, "WNM: Too short neighbor report");
554 os_memcpy(rep
->bssid
, pos
, ETH_ALEN
);
555 rep
->bssid_info
= WPA_GET_LE32(pos
+ ETH_ALEN
);
556 rep
->regulatory_class
= *(pos
+ 10);
557 rep
->channel_number
= *(pos
+ 11);
558 rep
->phy_type
= *(pos
+ 12);
568 wpa_printf(MSG_DEBUG
, "WNM: Subelement id=%u len=%u", id
, elen
);
571 wpa_printf(MSG_DEBUG
,
572 "WNM: Truncated neighbor report subelement");
575 wnm_parse_neighbor_report_elem(rep
, id
, elen
, pos
);
580 rep
->freq
= wnm_nei_get_chan(wpa_s
, rep
->regulatory_class
,
581 rep
->channel_number
);
585 static void wnm_clear_acceptable(struct wpa_supplicant
*wpa_s
)
589 for (i
= 0; i
< wpa_s
->wnm_num_neighbor_report
; i
++)
590 wpa_s
->wnm_neighbor_report_elements
[i
].acceptable
= 0;
594 static struct wpa_bss
* get_first_acceptable(struct wpa_supplicant
*wpa_s
)
597 struct neighbor_report
*nei
;
599 for (i
= 0; i
< wpa_s
->wnm_num_neighbor_report
; i
++) {
600 nei
= &wpa_s
->wnm_neighbor_report_elements
[i
];
602 return wpa_bss_get_bssid(wpa_s
, nei
->bssid
);
610 static struct wpa_bss
*
611 get_mbo_transition_candidate(struct wpa_supplicant
*wpa_s
,
612 enum mbo_transition_reject_reason
*reason
)
614 struct wpa_bss
*target
= NULL
;
615 struct wpa_bss_trans_info params
;
616 struct wpa_bss_candidate_info
*info
= NULL
;
617 struct neighbor_report
*nei
= wpa_s
->wnm_neighbor_report_elements
;
618 u8
*first_candidate_bssid
= NULL
, *pos
;
621 params
.mbo_transition_reason
= wpa_s
->wnm_mbo_transition_reason
;
622 params
.n_candidates
= 0;
623 params
.bssid
= os_calloc(wpa_s
->wnm_num_neighbor_report
, ETH_ALEN
);
628 for (i
= 0; i
< wpa_s
->wnm_num_neighbor_report
; nei
++, i
++) {
630 first_candidate_bssid
= nei
->bssid
;
631 if (!nei
->acceptable
)
633 os_memcpy(pos
, nei
->bssid
, ETH_ALEN
);
635 params
.n_candidates
++;
638 if (!params
.n_candidates
)
641 info
= wpa_drv_get_bss_trans_status(wpa_s
, ¶ms
);
643 /* If failed to get candidate BSS transition status from driver,
644 * get the first acceptable candidate from wpa_supplicant.
646 target
= wpa_bss_get_bssid(wpa_s
, params
.bssid
);
650 /* Get the first acceptable candidate from driver */
651 for (i
= 0; i
< info
->num
; i
++) {
652 if (info
->candidates
[i
].is_accept
) {
653 target
= wpa_bss_get_bssid(wpa_s
,
654 info
->candidates
[i
].bssid
);
659 /* If Disassociation Imminent is set and driver rejects all the
660 * candidate select first acceptable candidate which has
661 * rssi > disassoc_imminent_rssi_threshold
663 if (wpa_s
->wnm_mode
& WNM_BSS_TM_REQ_DISASSOC_IMMINENT
) {
664 for (i
= 0; i
< info
->num
; i
++) {
665 target
= wpa_bss_get_bssid(wpa_s
,
666 info
->candidates
[i
].bssid
);
669 wpa_s
->conf
->disassoc_imminent_rssi_threshold
))
675 /* While sending BTM reject use reason code of the first candidate
676 * received in BTM request frame
679 for (i
= 0; i
< info
->num
; i
++) {
680 if (first_candidate_bssid
&&
681 os_memcmp(first_candidate_bssid
,
682 info
->candidates
[i
].bssid
, ETH_ALEN
) == 0)
684 *reason
= info
->candidates
[i
].reject_reason
;
693 os_free(params
.bssid
);
695 os_free(info
->candidates
);
700 #endif /* CONFIG_MBO */
703 static struct wpa_bss
*
704 compare_scan_neighbor_results(struct wpa_supplicant
*wpa_s
, os_time_t age_secs
,
705 enum mbo_transition_reject_reason
*reason
)
708 struct wpa_bss
*bss
= wpa_s
->current_bss
;
709 struct wpa_bss
*target
;
714 wpa_printf(MSG_DEBUG
, "WNM: Current BSS " MACSTR
" RSSI %d",
715 MAC2STR(wpa_s
->bssid
), bss
->level
);
717 wnm_clear_acceptable(wpa_s
);
719 for (i
= 0; i
< wpa_s
->wnm_num_neighbor_report
; i
++) {
720 struct neighbor_report
*nei
;
722 nei
= &wpa_s
->wnm_neighbor_report_elements
[i
];
723 if (nei
->preference_present
&& nei
->preference
== 0) {
724 wpa_printf(MSG_DEBUG
, "Skip excluded BSS " MACSTR
,
725 MAC2STR(nei
->bssid
));
729 target
= wpa_bss_get_bssid(wpa_s
, nei
->bssid
);
731 wpa_printf(MSG_DEBUG
, "Candidate BSS " MACSTR
732 " (pref %d) not found in scan results",
734 nei
->preference_present
? nei
->preference
:
740 struct os_reltime now
;
742 if (os_get_reltime(&now
) == 0 &&
743 os_reltime_expired(&now
, &target
->last_update
,
745 wpa_printf(MSG_DEBUG
,
746 "Candidate BSS is more than %ld seconds old",
752 if (bss
->ssid_len
!= target
->ssid_len
||
753 os_memcmp(bss
->ssid
, target
->ssid
, bss
->ssid_len
) != 0) {
755 * TODO: Could consider allowing transition to another
756 * ESS if PMF was enabled for the association.
758 wpa_printf(MSG_DEBUG
, "Candidate BSS " MACSTR
759 " (pref %d) in different ESS",
761 nei
->preference_present
? nei
->preference
:
766 if (wpa_s
->current_ssid
&&
767 !wpa_scan_res_match(wpa_s
, 0, target
, wpa_s
->current_ssid
,
769 wpa_printf(MSG_DEBUG
, "Candidate BSS " MACSTR
770 " (pref %d) does not match the current network profile",
772 nei
->preference_present
? nei
->preference
:
777 if (wpa_is_bss_tmp_disallowed(wpa_s
, target
)) {
778 wpa_printf(MSG_DEBUG
,
779 "MBO: Candidate BSS " MACSTR
780 " retry delay is not over yet",
781 MAC2STR(nei
->bssid
));
785 if (target
->level
< bss
->level
&& target
->level
< -80) {
786 wpa_printf(MSG_DEBUG
, "Candidate BSS " MACSTR
787 " (pref %d) does not have sufficient signal level (%d)",
789 nei
->preference_present
? nei
->preference
:
799 if (wpa_s
->wnm_mbo_trans_reason_present
)
800 target
= get_mbo_transition_candidate(wpa_s
, reason
);
802 target
= get_first_acceptable(wpa_s
);
803 #else /* CONFIG_MBO */
804 target
= get_first_acceptable(wpa_s
);
805 #endif /* CONFIG_MBO */
808 wpa_printf(MSG_DEBUG
,
809 "WNM: Found an acceptable preferred transition candidate BSS "
811 MAC2STR(target
->bssid
), target
->level
);
818 static int wpa_bss_ies_eq(struct wpa_bss
*a
, struct wpa_bss
*b
, u8 eid
)
820 const u8
*ie_a
, *ie_b
;
825 ie_a
= wpa_bss_get_ie(a
, eid
);
826 ie_b
= wpa_bss_get_ie(b
, eid
);
828 if (!ie_a
|| !ie_b
|| ie_a
[1] != ie_b
[1])
831 return os_memcmp(ie_a
, ie_b
, ie_a
[1]) == 0;
835 static u32
wnm_get_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
)
839 info
|= NEI_REP_BSSID_INFO_AP_UNKNOWN_REACH
;
842 * Leave the security and key scope bits unset to indicate that the
843 * security information is not available.
846 if (bss
->caps
& WLAN_CAPABILITY_SPECTRUM_MGMT
)
847 info
|= NEI_REP_BSSID_INFO_SPECTRUM_MGMT
;
848 if (bss
->caps
& WLAN_CAPABILITY_QOS
)
849 info
|= NEI_REP_BSSID_INFO_QOS
;
850 if (bss
->caps
& WLAN_CAPABILITY_APSD
)
851 info
|= NEI_REP_BSSID_INFO_APSD
;
852 if (bss
->caps
& WLAN_CAPABILITY_RADIO_MEASUREMENT
)
853 info
|= NEI_REP_BSSID_INFO_RM
;
854 if (bss
->caps
& WLAN_CAPABILITY_DELAYED_BLOCK_ACK
)
855 info
|= NEI_REP_BSSID_INFO_DELAYED_BA
;
856 if (bss
->caps
& WLAN_CAPABILITY_IMM_BLOCK_ACK
)
857 info
|= NEI_REP_BSSID_INFO_IMM_BA
;
858 if (wpa_bss_ies_eq(bss
, wpa_s
->current_bss
, WLAN_EID_MOBILITY_DOMAIN
))
859 info
|= NEI_REP_BSSID_INFO_MOBILITY_DOMAIN
;
860 if (wpa_bss_ies_eq(bss
, wpa_s
->current_bss
, WLAN_EID_HT_CAP
))
861 info
|= NEI_REP_BSSID_INFO_HT
;
867 static int wnm_add_nei_rep(struct wpabuf
**buf
, const u8
*bssid
,
868 u32 bss_info
, u8 op_class
, u8 chan
, u8 phy_type
,
871 if (wpabuf_len(*buf
) + 18 >
872 IEEE80211_MAX_MMPDU_SIZE
- IEEE80211_HDRLEN
) {
873 wpa_printf(MSG_DEBUG
,
874 "WNM: No room in frame for Neighbor Report element");
878 if (wpabuf_resize(buf
, 18) < 0) {
879 wpa_printf(MSG_DEBUG
,
880 "WNM: Failed to allocate memory for Neighbor Report element");
884 wpabuf_put_u8(*buf
, WLAN_EID_NEIGHBOR_REPORT
);
885 /* length: 13 for basic neighbor report + 3 for preference subelement */
886 wpabuf_put_u8(*buf
, 16);
887 wpabuf_put_data(*buf
, bssid
, ETH_ALEN
);
888 wpabuf_put_le32(*buf
, bss_info
);
889 wpabuf_put_u8(*buf
, op_class
);
890 wpabuf_put_u8(*buf
, chan
);
891 wpabuf_put_u8(*buf
, phy_type
);
892 wpabuf_put_u8(*buf
, WNM_NEIGHBOR_BSS_TRANSITION_CANDIDATE
);
893 wpabuf_put_u8(*buf
, 1);
894 wpabuf_put_u8(*buf
, pref
);
899 static int wnm_nei_rep_add_bss(struct wpa_supplicant
*wpa_s
,
900 struct wpa_bss
*bss
, struct wpabuf
**buf
,
905 int sec_chan
= 0, vht
= 0;
906 enum phy_type phy_type
;
908 struct ieee80211_ht_operation
*ht_oper
= NULL
;
909 struct ieee80211_vht_operation
*vht_oper
= NULL
;
911 ie
= wpa_bss_get_ie(bss
, WLAN_EID_HT_OPERATION
);
912 if (ie
&& ie
[1] >= 2) {
913 ht_oper
= (struct ieee80211_ht_operation
*) (ie
+ 2);
915 if (ht_oper
->ht_param
& HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE
)
917 else if (ht_oper
->ht_param
&
918 HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW
)
922 ie
= wpa_bss_get_ie(bss
, WLAN_EID_VHT_OPERATION
);
923 if (ie
&& ie
[1] >= 1) {
924 vht_oper
= (struct ieee80211_vht_operation
*) (ie
+ 2);
926 if (vht_oper
->vht_op_info_chwidth
== CHANWIDTH_80MHZ
||
927 vht_oper
->vht_op_info_chwidth
== CHANWIDTH_160MHZ
||
928 vht_oper
->vht_op_info_chwidth
== CHANWIDTH_80P80MHZ
)
929 vht
= vht_oper
->vht_op_info_chwidth
;
932 if (ieee80211_freq_to_channel_ext(bss
->freq
, sec_chan
, vht
, &op_class
,
933 &chan
) == NUM_HOSTAPD_MODES
) {
934 wpa_printf(MSG_DEBUG
,
935 "WNM: Cannot determine operating class and channel");
939 phy_type
= ieee80211_get_phy_type(bss
->freq
, (ht_oper
!= NULL
),
941 if (phy_type
== PHY_TYPE_UNSPECIFIED
) {
942 wpa_printf(MSG_DEBUG
,
943 "WNM: Cannot determine BSS phy type for Neighbor Report");
947 info
= wnm_get_bss_info(wpa_s
, bss
);
949 return wnm_add_nei_rep(buf
, bss
->bssid
, info
, op_class
, chan
, phy_type
,
954 static void wnm_add_cand_list(struct wpa_supplicant
*wpa_s
, struct wpabuf
**buf
)
956 unsigned int i
, pref
= 255;
957 struct os_reltime now
;
958 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
964 * TODO: Define when scan results are no longer valid for the candidate
967 os_get_reltime(&now
);
968 if (os_reltime_expired(&now
, &wpa_s
->last_scan
, 10))
971 wpa_printf(MSG_DEBUG
,
972 "WNM: Add candidate list to BSS Transition Management Response frame");
973 for (i
= 0; i
< wpa_s
->last_scan_res_used
&& pref
; i
++) {
974 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
977 if (wpa_scan_res_match(wpa_s
, i
, bss
, ssid
, 1, 0)) {
978 res
= wnm_nei_rep_add_bss(wpa_s
, bss
, buf
, pref
--);
980 continue; /* could not build entry for BSS */
982 break; /* no more room for candidates */
988 wpa_hexdump_buf(MSG_DEBUG
,
989 "WNM: BSS Transition Management Response candidate list",
994 #define BTM_RESP_MIN_SIZE 5 + ETH_ALEN
996 static void wnm_send_bss_transition_mgmt_resp(
997 struct wpa_supplicant
*wpa_s
, u8 dialog_token
,
998 enum bss_trans_mgmt_status_code status
,
999 enum mbo_transition_reject_reason reason
,
1000 u8 delay
, const u8
*target_bssid
)
1005 wpa_printf(MSG_DEBUG
,
1006 "WNM: Send BSS Transition Management Response to " MACSTR
1007 " dialog_token=%u status=%u reason=%u delay=%d",
1008 MAC2STR(wpa_s
->bssid
), dialog_token
, status
, reason
, delay
);
1009 if (!wpa_s
->current_bss
) {
1010 wpa_printf(MSG_DEBUG
,
1011 "WNM: Current BSS not known - drop response");
1015 buf
= wpabuf_alloc(BTM_RESP_MIN_SIZE
);
1017 wpa_printf(MSG_DEBUG
,
1018 "WNM: Failed to allocate memory for BTM response");
1022 wpa_s
->bss_tm_status
= status
;
1023 wpas_notify_bss_tm_status(wpa_s
);
1025 wpabuf_put_u8(buf
, WLAN_ACTION_WNM
);
1026 wpabuf_put_u8(buf
, WNM_BSS_TRANS_MGMT_RESP
);
1027 wpabuf_put_u8(buf
, dialog_token
);
1028 wpabuf_put_u8(buf
, status
);
1029 wpabuf_put_u8(buf
, delay
);
1031 wpabuf_put_data(buf
, target_bssid
, ETH_ALEN
);
1032 } else if (status
== WNM_BSS_TM_ACCEPT
) {
1034 * P802.11-REVmc clarifies that the Target BSSID field is always
1035 * present when status code is zero, so use a fake value here if
1036 * no BSSID is yet known.
1038 wpabuf_put_data(buf
, "\0\0\0\0\0\0", ETH_ALEN
);
1041 if (status
== WNM_BSS_TM_ACCEPT
)
1042 wnm_add_cand_list(wpa_s
, &buf
);
1045 if (status
!= WNM_BSS_TM_ACCEPT
&&
1046 wpa_bss_get_vendor_ie(wpa_s
->current_bss
, MBO_IE_VENDOR_TYPE
)) {
1050 ret
= wpas_mbo_ie_bss_trans_reject(wpa_s
, mbo
, sizeof(mbo
),
1053 if (wpabuf_resize(&buf
, ret
) < 0) {
1055 wpa_printf(MSG_DEBUG
,
1056 "WNM: Failed to allocate memory for MBO IE");
1060 wpabuf_put_data(buf
, mbo
, ret
);
1063 #endif /* CONFIG_MBO */
1065 res
= wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
1066 wpa_s
->own_addr
, wpa_s
->bssid
,
1067 wpabuf_head_u8(buf
), wpabuf_len(buf
), 0);
1069 wpa_printf(MSG_DEBUG
,
1070 "WNM: Failed to send BSS Transition Management Response");
1077 static void wnm_bss_tm_connect(struct wpa_supplicant
*wpa_s
,
1078 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
1081 wpa_dbg(wpa_s
, MSG_DEBUG
,
1082 "WNM: Transition to BSS " MACSTR
1083 " based on BSS Transition Management Request (old BSSID "
1084 MACSTR
" after_new_scan=%d)",
1085 MAC2STR(bss
->bssid
), MAC2STR(wpa_s
->bssid
), after_new_scan
);
1087 /* Send the BSS Management Response - Accept */
1088 if (wpa_s
->wnm_reply
) {
1089 wpa_s
->wnm_reply
= 0;
1090 wpa_printf(MSG_DEBUG
,
1091 "WNM: Sending successful BSS Transition Management Response");
1092 wnm_send_bss_transition_mgmt_resp(
1093 wpa_s
, wpa_s
->wnm_dialog_token
, WNM_BSS_TM_ACCEPT
,
1094 MBO_TRANSITION_REJECT_REASON_UNSPECIFIED
, 0,
1098 if (bss
== wpa_s
->current_bss
) {
1099 wpa_printf(MSG_DEBUG
,
1100 "WNM: Already associated with the preferred candidate");
1101 wnm_deallocate_memory(wpa_s
);
1105 wpa_s
->reassociate
= 1;
1106 wpa_printf(MSG_DEBUG
, "WNM: Issuing connect");
1107 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
1108 wnm_deallocate_memory(wpa_s
);
1112 int wnm_scan_process(struct wpa_supplicant
*wpa_s
, int reply_on_fail
)
1114 struct wpa_bss
*bss
;
1115 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1116 enum bss_trans_mgmt_status_code status
= WNM_BSS_TM_REJECT_UNSPECIFIED
;
1117 enum mbo_transition_reject_reason reason
=
1118 MBO_TRANSITION_REJECT_REASON_UNSPECIFIED
;
1120 if (!wpa_s
->wnm_neighbor_report_elements
)
1123 wpa_dbg(wpa_s
, MSG_DEBUG
,
1124 "WNM: Process scan results for BSS Transition Management");
1125 if (os_reltime_before(&wpa_s
->wnm_cand_valid_until
,
1126 &wpa_s
->scan_trigger_time
)) {
1127 wpa_printf(MSG_DEBUG
, "WNM: Previously stored BSS transition candidate list is not valid anymore - drop it");
1128 wnm_deallocate_memory(wpa_s
);
1132 if (!wpa_s
->current_bss
||
1133 os_memcmp(wpa_s
->wnm_cand_from_bss
, wpa_s
->current_bss
->bssid
,
1135 wpa_printf(MSG_DEBUG
, "WNM: Stored BSS transition candidate list not from the current BSS - ignore it");
1139 /* Compare the Neighbor Report and scan results */
1140 bss
= compare_scan_neighbor_results(wpa_s
, 0, &reason
);
1142 wpa_printf(MSG_DEBUG
, "WNM: No BSS transition candidate match found");
1143 status
= WNM_BSS_TM_REJECT_NO_SUITABLE_CANDIDATES
;
1144 goto send_bss_resp_fail
;
1147 /* Associate to the network */
1148 wnm_bss_tm_connect(wpa_s
, bss
, ssid
, 1);
1155 /* Send reject response for all the failures */
1157 if (wpa_s
->wnm_reply
) {
1158 wpa_s
->wnm_reply
= 0;
1159 wnm_send_bss_transition_mgmt_resp(wpa_s
,
1160 wpa_s
->wnm_dialog_token
,
1161 status
, reason
, 0, NULL
);
1163 wnm_deallocate_memory(wpa_s
);
1169 static int cand_pref_compar(const void *a
, const void *b
)
1171 const struct neighbor_report
*aa
= a
;
1172 const struct neighbor_report
*bb
= b
;
1174 if (!aa
->preference_present
&& !bb
->preference_present
)
1176 if (!aa
->preference_present
)
1178 if (!bb
->preference_present
)
1180 if (bb
->preference
> aa
->preference
)
1182 if (bb
->preference
< aa
->preference
)
1188 static void wnm_sort_cand_list(struct wpa_supplicant
*wpa_s
)
1190 if (!wpa_s
->wnm_neighbor_report_elements
)
1192 qsort(wpa_s
->wnm_neighbor_report_elements
,
1193 wpa_s
->wnm_num_neighbor_report
, sizeof(struct neighbor_report
),
1198 static void wnm_dump_cand_list(struct wpa_supplicant
*wpa_s
)
1202 wpa_printf(MSG_DEBUG
, "WNM: BSS Transition Candidate List");
1203 if (!wpa_s
->wnm_neighbor_report_elements
)
1205 for (i
= 0; i
< wpa_s
->wnm_num_neighbor_report
; i
++) {
1206 struct neighbor_report
*nei
;
1208 nei
= &wpa_s
->wnm_neighbor_report_elements
[i
];
1209 wpa_printf(MSG_DEBUG
, "%u: " MACSTR
1210 " info=0x%x op_class=%u chan=%u phy=%u pref=%d freq=%d",
1211 i
, MAC2STR(nei
->bssid
), nei
->bssid_info
,
1212 nei
->regulatory_class
,
1213 nei
->channel_number
, nei
->phy_type
,
1214 nei
->preference_present
? nei
->preference
: -1,
1220 static int chan_supported(struct wpa_supplicant
*wpa_s
, int freq
)
1224 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
1225 struct hostapd_hw_modes
*mode
= &wpa_s
->hw
.modes
[i
];
1228 for (j
= 0; j
< mode
->num_channels
; j
++) {
1229 struct hostapd_channel_data
*chan
;
1231 chan
= &mode
->channels
[j
];
1232 if (chan
->freq
== freq
&&
1233 !(chan
->flag
& HOSTAPD_CHAN_DISABLED
))
1242 static void wnm_set_scan_freqs(struct wpa_supplicant
*wpa_s
)
1248 if (!wpa_s
->wnm_neighbor_report_elements
)
1251 if (wpa_s
->hw
.modes
== NULL
)
1254 os_free(wpa_s
->next_scan_freqs
);
1255 wpa_s
->next_scan_freqs
= NULL
;
1257 freqs
= os_calloc(wpa_s
->wnm_num_neighbor_report
+ 1, sizeof(int));
1261 for (i
= 0; i
< wpa_s
->wnm_num_neighbor_report
; i
++) {
1262 struct neighbor_report
*nei
;
1264 nei
= &wpa_s
->wnm_neighbor_report_elements
[i
];
1265 if (nei
->freq
<= 0) {
1266 wpa_printf(MSG_DEBUG
,
1267 "WNM: Unknown neighbor operating frequency for "
1268 MACSTR
" - scan all channels",
1269 MAC2STR(nei
->bssid
));
1273 if (chan_supported(wpa_s
, nei
->freq
))
1274 add_freq(freqs
, &num_freqs
, nei
->freq
);
1277 if (num_freqs
== 0) {
1282 wpa_printf(MSG_DEBUG
,
1283 "WNM: Scan %d frequencies based on transition candidate list",
1285 wpa_s
->next_scan_freqs
= freqs
;
1289 static int wnm_fetch_scan_results(struct wpa_supplicant
*wpa_s
)
1291 struct wpa_scan_results
*scan_res
;
1292 struct wpa_bss
*bss
;
1293 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1297 wpa_dbg(wpa_s
, MSG_DEBUG
,
1298 "WNM: Fetch current scan results from the driver for checking transition candidates");
1299 scan_res
= wpa_drv_get_scan_results2(wpa_s
);
1301 wpa_dbg(wpa_s
, MSG_DEBUG
, "WNM: Failed to get scan results");
1305 if (scan_res
->fetch_time
.sec
== 0)
1306 os_get_reltime(&scan_res
->fetch_time
);
1308 filter_scan_res(wpa_s
, scan_res
);
1310 for (i
= 0; i
< wpa_s
->wnm_num_neighbor_report
; i
++) {
1311 struct neighbor_report
*nei
;
1313 nei
= &wpa_s
->wnm_neighbor_report_elements
[i
];
1314 if (nei
->preference_present
&& nei
->preference
== 0)
1317 for (j
= 0; j
< scan_res
->num
; j
++) {
1318 struct wpa_scan_res
*res
;
1321 res
= scan_res
->res
[j
];
1322 if (os_memcmp(nei
->bssid
, res
->bssid
, ETH_ALEN
) != 0 ||
1323 res
->age
> WNM_SCAN_RESULT_AGE
* 1000)
1325 bss
= wpa_s
->current_bss
;
1326 ssid_ie
= wpa_scan_get_ie(res
, WLAN_EID_SSID
);
1327 if (bss
&& ssid_ie
&&
1328 (bss
->ssid_len
!= ssid_ie
[1] ||
1329 os_memcmp(bss
->ssid
, ssid_ie
+ 2,
1330 bss
->ssid_len
) != 0))
1333 /* Potential candidate found */
1336 scan_est_throughput(wpa_s
, res
);
1337 wpa_bss_update_scan_res(wpa_s
, res
,
1338 &scan_res
->fetch_time
);
1342 wpa_scan_results_free(scan_res
);
1344 wpa_dbg(wpa_s
, MSG_DEBUG
,
1345 "WNM: No transition candidate matches existing scan results");
1349 bss
= compare_scan_neighbor_results(wpa_s
, WNM_SCAN_RESULT_AGE
, NULL
);
1351 wpa_dbg(wpa_s
, MSG_DEBUG
,
1352 "WNM: Comparison of scan results against transition candidates did not find matches");
1356 /* Associate to the network */
1357 wnm_bss_tm_connect(wpa_s
, bss
, ssid
, 0);
1362 static void ieee802_11_rx_bss_trans_mgmt_req(struct wpa_supplicant
*wpa_s
,
1363 const u8
*pos
, const u8
*end
,
1366 unsigned int beacon_int
;
1370 #endif /* CONFIG_MBO */
1372 if (wpa_s
->disable_mbo_oce
|| wpa_s
->conf
->disable_btm
)
1379 wpa_s
->wnm_mbo_trans_reason_present
= 0;
1380 wpa_s
->wnm_mbo_transition_reason
= 0;
1381 #endif /* CONFIG_MBO */
1383 if (wpa_s
->current_bss
)
1384 beacon_int
= wpa_s
->current_bss
->beacon_int
;
1386 beacon_int
= 100; /* best guess */
1388 wpa_s
->wnm_dialog_token
= pos
[0];
1389 wpa_s
->wnm_mode
= pos
[1];
1390 wpa_s
->wnm_dissoc_timer
= WPA_GET_LE16(pos
+ 2);
1392 wpa_s
->wnm_reply
= reply
;
1394 wpa_printf(MSG_DEBUG
, "WNM: BSS Transition Management Request: "
1395 "dialog_token=%u request_mode=0x%x "
1396 "disassoc_timer=%u validity_interval=%u",
1397 wpa_s
->wnm_dialog_token
, wpa_s
->wnm_mode
,
1398 wpa_s
->wnm_dissoc_timer
, valid_int
);
1400 #if defined(CONFIG_MBO) && defined(CONFIG_TESTING_OPTIONS)
1401 if (wpa_s
->reject_btm_req_reason
) {
1402 wpa_printf(MSG_INFO
,
1403 "WNM: Testing - reject BSS Transition Management Request: reject_btm_req_reason=%d",
1404 wpa_s
->reject_btm_req_reason
);
1405 wnm_send_bss_transition_mgmt_resp(
1406 wpa_s
, wpa_s
->wnm_dialog_token
,
1407 wpa_s
->reject_btm_req_reason
,
1408 MBO_TRANSITION_REJECT_REASON_UNSPECIFIED
, 0, NULL
);
1411 #endif /* CONFIG_MBO && CONFIG_TESTING_OPTIONS */
1415 if (wpa_s
->wnm_mode
& WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED
) {
1416 if (end
- pos
< 12) {
1417 wpa_printf(MSG_DEBUG
, "WNM: Too short BSS TM Request");
1420 os_memcpy(wpa_s
->wnm_bss_termination_duration
, pos
, 12);
1421 pos
+= 12; /* BSS Termination Duration */
1424 if (wpa_s
->wnm_mode
& WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT
) {
1427 if (end
- pos
< 1 || 1 + pos
[0] > end
- pos
) {
1428 wpa_printf(MSG_DEBUG
, "WNM: Invalid BSS Transition "
1429 "Management Request (URL)");
1432 os_memcpy(url
, pos
+ 1, pos
[0]);
1436 wpa_msg(wpa_s
, MSG_INFO
, ESS_DISASSOC_IMMINENT
"%d %u %s",
1437 wpa_sm_pmf_enabled(wpa_s
->wpa
),
1438 wpa_s
->wnm_dissoc_timer
* beacon_int
* 128 / 125, url
);
1441 if (wpa_s
->wnm_mode
& WNM_BSS_TM_REQ_DISASSOC_IMMINENT
) {
1442 wpa_msg(wpa_s
, MSG_INFO
, "WNM: Disassociation Imminent - "
1443 "Disassociation Timer %u", wpa_s
->wnm_dissoc_timer
);
1444 if (wpa_s
->wnm_dissoc_timer
&& !wpa_s
->scanning
) {
1445 /* TODO: mark current BSS less preferred for
1447 wpa_printf(MSG_DEBUG
, "Trying to find another BSS");
1448 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1453 vendor
= get_ie(pos
, end
- pos
, WLAN_EID_VENDOR_SPECIFIC
);
1455 wpas_mbo_ie_trans_req(wpa_s
, vendor
+ 2, vendor
[1]);
1456 #endif /* CONFIG_MBO */
1458 if (wpa_s
->wnm_mode
& WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED
) {
1459 unsigned int valid_ms
;
1461 wpa_msg(wpa_s
, MSG_INFO
, "WNM: Preferred List Available");
1462 wnm_deallocate_memory(wpa_s
);
1463 wpa_s
->wnm_neighbor_report_elements
= os_calloc(
1464 WNM_MAX_NEIGHBOR_REPORT
,
1465 sizeof(struct neighbor_report
));
1466 if (wpa_s
->wnm_neighbor_report_elements
== NULL
)
1469 while (end
- pos
>= 2 &&
1470 wpa_s
->wnm_num_neighbor_report
< WNM_MAX_NEIGHBOR_REPORT
)
1475 wpa_printf(MSG_DEBUG
, "WNM: Neighbor report tag %u",
1477 if (len
> end
- pos
) {
1478 wpa_printf(MSG_DEBUG
, "WNM: Truncated request");
1481 if (tag
== WLAN_EID_NEIGHBOR_REPORT
) {
1482 struct neighbor_report
*rep
;
1483 rep
= &wpa_s
->wnm_neighbor_report_elements
[
1484 wpa_s
->wnm_num_neighbor_report
];
1485 wnm_parse_neighbor_report(wpa_s
, pos
, len
, rep
);
1486 wpa_s
->wnm_num_neighbor_report
++;
1488 if (wpa_s
->wnm_mbo_trans_reason_present
&&
1489 wpa_s
->wnm_num_neighbor_report
== 1) {
1491 wpa_printf(MSG_DEBUG
,
1492 "WNM: First transition candidate is "
1493 MACSTR
, MAC2STR(rep
->bssid
));
1495 #endif /* CONFIG_MBO */
1501 if (!wpa_s
->wnm_num_neighbor_report
) {
1502 wpa_printf(MSG_DEBUG
,
1503 "WNM: Candidate list included bit is set, but no candidates found");
1504 wnm_send_bss_transition_mgmt_resp(
1505 wpa_s
, wpa_s
->wnm_dialog_token
,
1506 WNM_BSS_TM_REJECT_NO_SUITABLE_CANDIDATES
,
1507 MBO_TRANSITION_REJECT_REASON_UNSPECIFIED
, 0,
1512 wnm_sort_cand_list(wpa_s
);
1513 wnm_dump_cand_list(wpa_s
);
1514 valid_ms
= valid_int
* beacon_int
* 128 / 125;
1515 wpa_printf(MSG_DEBUG
, "WNM: Candidate list valid for %u ms",
1517 os_get_reltime(&wpa_s
->wnm_cand_valid_until
);
1518 wpa_s
->wnm_cand_valid_until
.sec
+= valid_ms
/ 1000;
1519 wpa_s
->wnm_cand_valid_until
.usec
+= (valid_ms
% 1000) * 1000;
1520 wpa_s
->wnm_cand_valid_until
.sec
+=
1521 wpa_s
->wnm_cand_valid_until
.usec
/ 1000000;
1522 wpa_s
->wnm_cand_valid_until
.usec
%= 1000000;
1523 os_memcpy(wpa_s
->wnm_cand_from_bss
, wpa_s
->bssid
, ETH_ALEN
);
1526 * Fetch the latest scan results from the kernel and check for
1527 * candidates based on those results first. This can help in
1528 * finding more up-to-date information should the driver has
1529 * done some internal scanning operations after the last scan
1530 * result update in wpa_supplicant.
1532 if (wnm_fetch_scan_results(wpa_s
) > 0)
1536 * Try to use previously received scan results, if they are
1537 * recent enough to use for a connection.
1539 if (wpa_s
->last_scan_res_used
> 0) {
1540 struct os_reltime now
;
1542 os_get_reltime(&now
);
1543 if (!os_reltime_expired(&now
, &wpa_s
->last_scan
, 10)) {
1544 wpa_printf(MSG_DEBUG
,
1545 "WNM: Try to use recent scan results");
1546 if (wnm_scan_process(wpa_s
, 0) > 0)
1548 wpa_printf(MSG_DEBUG
,
1549 "WNM: No match in previous scan results - try a new scan");
1553 wnm_set_scan_freqs(wpa_s
);
1554 if (wpa_s
->wnm_num_neighbor_report
== 1) {
1555 os_memcpy(wpa_s
->next_scan_bssid
,
1556 wpa_s
->wnm_neighbor_report_elements
[0].bssid
,
1558 wpa_printf(MSG_DEBUG
,
1559 "WNM: Scan only for a specific BSSID since there is only a single candidate "
1560 MACSTR
, MAC2STR(wpa_s
->next_scan_bssid
));
1562 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1564 enum bss_trans_mgmt_status_code status
;
1565 if (wpa_s
->wnm_mode
& WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT
)
1566 status
= WNM_BSS_TM_ACCEPT
;
1568 wpa_msg(wpa_s
, MSG_INFO
, "WNM: BSS Transition Management Request did not include candidates");
1569 status
= WNM_BSS_TM_REJECT_UNSPECIFIED
;
1571 wnm_send_bss_transition_mgmt_resp(
1572 wpa_s
, wpa_s
->wnm_dialog_token
, status
,
1573 MBO_TRANSITION_REJECT_REASON_UNSPECIFIED
, 0, NULL
);
1578 #define BTM_QUERY_MIN_SIZE 4
1580 int wnm_send_bss_transition_mgmt_query(struct wpa_supplicant
*wpa_s
,
1582 const char *btm_candidates
,
1588 wpa_printf(MSG_DEBUG
, "WNM: Send BSS Transition Management Query to "
1589 MACSTR
" query_reason=%u%s",
1590 MAC2STR(wpa_s
->bssid
), query_reason
,
1591 cand_list
? " candidate list" : "");
1593 buf
= wpabuf_alloc(BTM_QUERY_MIN_SIZE
);
1597 wpabuf_put_u8(buf
, WLAN_ACTION_WNM
);
1598 wpabuf_put_u8(buf
, WNM_BSS_TRANS_MGMT_QUERY
);
1599 wpabuf_put_u8(buf
, 1);
1600 wpabuf_put_u8(buf
, query_reason
);
1603 wnm_add_cand_list(wpa_s
, &buf
);
1605 if (btm_candidates
) {
1606 const size_t max_len
= 1000;
1608 ret
= wpabuf_resize(&buf
, max_len
);
1614 ret
= ieee802_11_parse_candidate_list(btm_candidates
,
1622 wpabuf_put(buf
, ret
);
1625 ret
= wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
1626 wpa_s
->own_addr
, wpa_s
->bssid
,
1627 wpabuf_head_u8(buf
), wpabuf_len(buf
), 0);
1634 static void ieee802_11_rx_wnm_notif_req_wfa(struct wpa_supplicant
*wpa_s
,
1635 const u8
*sa
, const u8
*data
,
1638 const u8
*pos
, *end
, *next
;
1644 while (end
- pos
> 1) {
1647 wpa_printf(MSG_DEBUG
, "WNM: WFA subelement %u len %u",
1649 if (ie_len
> end
- pos
) {
1650 wpa_printf(MSG_DEBUG
, "WNM: Not enough room for "
1654 next
= pos
+ ie_len
;
1659 wpa_printf(MSG_DEBUG
, "WNM: Subelement OUI %06x type %u",
1660 WPA_GET_BE24(pos
), pos
[3]);
1663 if (ie
== WLAN_EID_VENDOR_SPECIFIC
&& ie_len
>= 5 &&
1664 WPA_GET_BE24(pos
) == OUI_WFA
&&
1665 pos
[3] == HS20_WNM_SUB_REM_NEEDED
) {
1666 /* Subscription Remediation subelement */
1672 wpa_printf(MSG_DEBUG
, "WNM: Subscription Remediation "
1674 ie_end
= pos
+ ie_len
;
1678 wpa_printf(MSG_DEBUG
, "WNM: No Server URL included");
1682 if (url_len
+ 1 > ie_end
- pos
) {
1683 wpa_printf(MSG_DEBUG
, "WNM: Not enough room for Server URL (len=%u) and Server Method (left %d)",
1685 (int) (ie_end
- pos
));
1688 url
= os_malloc(url_len
+ 1);
1691 os_memcpy(url
, pos
, url_len
);
1692 url
[url_len
] = '\0';
1693 osu_method
= pos
[url_len
];
1695 hs20_rx_subscription_remediation(wpa_s
, url
,
1702 if (ie
== WLAN_EID_VENDOR_SPECIFIC
&& ie_len
>= 8 &&
1703 WPA_GET_BE24(pos
) == OUI_WFA
&&
1704 pos
[3] == HS20_WNM_DEAUTH_IMMINENT_NOTICE
) {
1711 ie_end
= pos
+ ie_len
;
1714 reauth_delay
= WPA_GET_LE16(pos
);
1717 wpa_printf(MSG_DEBUG
, "WNM: HS 2.0 Deauthentication "
1718 "Imminent - Reason Code %u "
1719 "Re-Auth Delay %u URL Length %u",
1720 code
, reauth_delay
, url_len
);
1721 if (url_len
> ie_end
- pos
)
1723 url
= os_malloc(url_len
+ 1);
1726 os_memcpy(url
, pos
, url_len
);
1727 url
[url_len
] = '\0';
1728 hs20_rx_deauth_imminent_notice(wpa_s
, code
,
1735 if (ie
== WLAN_EID_VENDOR_SPECIFIC
&& ie_len
>= 5 &&
1736 WPA_GET_BE24(pos
) == OUI_WFA
&&
1737 pos
[3] == HS20_WNM_T_C_ACCEPTANCE
) {
1742 ie_end
= pos
+ ie_len
;
1745 wpa_printf(MSG_DEBUG
,
1746 "WNM: HS 2.0 Terms and Conditions Acceptance (URL Length %u)",
1748 if (url_len
> ie_end
- pos
)
1750 url
= os_malloc(url_len
+ 1);
1753 os_memcpy(url
, pos
, url_len
);
1754 url
[url_len
] = '\0';
1755 hs20_rx_t_c_acceptance(wpa_s
, url
);
1760 #endif /* CONFIG_HS20 */
1767 static void ieee802_11_rx_wnm_notif_req(struct wpa_supplicant
*wpa_s
,
1768 const u8
*sa
, const u8
*frm
, int len
)
1770 const u8
*pos
, *end
;
1771 u8 dialog_token
, type
;
1773 /* Dialog Token [1] | Type [1] | Subelements */
1775 if (len
< 2 || sa
== NULL
)
1779 dialog_token
= *pos
++;
1782 wpa_dbg(wpa_s
, MSG_DEBUG
, "WNM: Received WNM-Notification Request "
1783 "(dialog_token %u type %u sa " MACSTR
")",
1784 dialog_token
, type
, MAC2STR(sa
));
1785 wpa_hexdump(MSG_DEBUG
, "WNM-Notification Request subelements",
1788 if (wpa_s
->wpa_state
!= WPA_COMPLETED
||
1789 os_memcmp(sa
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
1790 wpa_dbg(wpa_s
, MSG_DEBUG
, "WNM: WNM-Notification frame not "
1791 "from our AP - ignore it");
1797 ieee802_11_rx_wnm_notif_req_wfa(wpa_s
, sa
, pos
, end
- pos
);
1800 wpa_dbg(wpa_s
, MSG_DEBUG
, "WNM: Ignore unknown "
1801 "WNM-Notification type %u", type
);
1807 static void ieee802_11_rx_wnm_coloc_intf_req(struct wpa_supplicant
*wpa_s
,
1808 const u8
*sa
, const u8
*frm
,
1811 u8 dialog_token
, req_info
, auto_report
, timeout
;
1813 if (!wpa_s
->conf
->coloc_intf_reporting
)
1816 /* Dialog Token [1] | Request Info [1] */
1820 dialog_token
= frm
[0];
1822 auto_report
= req_info
& 0x03;
1823 timeout
= req_info
>> 2;
1825 wpa_dbg(wpa_s
, MSG_DEBUG
,
1826 "WNM: Received Collocated Interference Request (dialog_token %u auto_report %u timeout %u sa " MACSTR
")",
1827 dialog_token
, auto_report
, timeout
, MAC2STR(sa
));
1829 if (dialog_token
== 0)
1830 return; /* only nonzero values are used for request */
1832 if (wpa_s
->wpa_state
!= WPA_COMPLETED
||
1833 os_memcmp(sa
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
1834 wpa_dbg(wpa_s
, MSG_DEBUG
,
1835 "WNM: Collocated Interference Request frame not from current AP - ignore it");
1839 wpa_msg(wpa_s
, MSG_INFO
, COLOC_INTF_REQ
"%u %u %u",
1840 dialog_token
, auto_report
, timeout
);
1841 wpa_s
->coloc_intf_dialog_token
= dialog_token
;
1842 wpa_s
->coloc_intf_auto_report
= auto_report
;
1843 wpa_s
->coloc_intf_timeout
= timeout
;
1847 void ieee802_11_rx_wnm_action(struct wpa_supplicant
*wpa_s
,
1848 const struct ieee80211_mgmt
*mgmt
, size_t len
)
1850 const u8
*pos
, *end
;
1853 if (len
< IEEE80211_HDRLEN
+ 2)
1856 pos
= ((const u8
*) mgmt
) + IEEE80211_HDRLEN
+ 1;
1858 end
= ((const u8
*) mgmt
) + len
;
1860 wpa_printf(MSG_DEBUG
, "WNM: RX action %u from " MACSTR
,
1861 act
, MAC2STR(mgmt
->sa
));
1862 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
||
1863 os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
1864 wpa_printf(MSG_DEBUG
, "WNM: Ignore unexpected WNM Action "
1870 case WNM_BSS_TRANS_MGMT_REQ
:
1871 ieee802_11_rx_bss_trans_mgmt_req(wpa_s
, pos
, end
,
1872 !(mgmt
->da
[0] & 0x01));
1874 case WNM_SLEEP_MODE_RESP
:
1875 ieee802_11_rx_wnmsleep_resp(wpa_s
, pos
, end
- pos
);
1877 case WNM_NOTIFICATION_REQ
:
1878 ieee802_11_rx_wnm_notif_req(wpa_s
, mgmt
->sa
, pos
, end
- pos
);
1880 case WNM_COLLOCATED_INTERFERENCE_REQ
:
1881 ieee802_11_rx_wnm_coloc_intf_req(wpa_s
, mgmt
->sa
, pos
,
1885 wpa_printf(MSG_ERROR
, "WNM: Unknown request");
1891 int wnm_send_coloc_intf_report(struct wpa_supplicant
*wpa_s
, u8 dialog_token
,
1892 const struct wpabuf
*elems
)
1897 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
|| !elems
)
1900 wpa_printf(MSG_DEBUG
, "WNM: Send Collocated Interference Report to "
1901 MACSTR
" (dialog token %u)",
1902 MAC2STR(wpa_s
->bssid
), dialog_token
);
1904 buf
= wpabuf_alloc(3 + wpabuf_len(elems
));
1908 wpabuf_put_u8(buf
, WLAN_ACTION_WNM
);
1909 wpabuf_put_u8(buf
, WNM_COLLOCATED_INTERFERENCE_REPORT
);
1910 wpabuf_put_u8(buf
, dialog_token
);
1911 wpabuf_put_buf(buf
, elems
);
1913 ret
= wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
1914 wpa_s
->own_addr
, wpa_s
->bssid
,
1915 wpabuf_head_u8(buf
), wpabuf_len(buf
), 0);
1921 void wnm_set_coloc_intf_elems(struct wpa_supplicant
*wpa_s
,
1922 struct wpabuf
*elems
)
1924 wpabuf_free(wpa_s
->coloc_intf_elems
);
1925 if (elems
&& wpabuf_len(elems
) == 0) {
1929 wpa_s
->coloc_intf_elems
= elems
;
1931 if (wpa_s
->conf
->coloc_intf_reporting
&& wpa_s
->coloc_intf_elems
&&
1932 wpa_s
->coloc_intf_dialog_token
&&
1933 (wpa_s
->coloc_intf_auto_report
== 1 ||
1934 wpa_s
->coloc_intf_auto_report
== 3)) {
1935 /* TODO: Check that there has not been less than
1936 * wpa_s->coloc_intf_timeout * 200 TU from the last report.
1938 wnm_send_coloc_intf_report(wpa_s
,
1939 wpa_s
->coloc_intf_dialog_token
,
1940 wpa_s
->coloc_intf_elems
);
1945 void wnm_clear_coloc_intf_reporting(struct wpa_supplicant
*wpa_s
)
1948 wpa_s
->coloc_intf_dialog_token
= 0;
1949 wpa_s
->coloc_intf_auto_report
= 0;
1950 #endif /* CONFIG_WNM */