Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * wpa_supplicant - WNM |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3 | * Copyright (c) 2011-2013, Qualcomm Atheros, Inc. |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 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" |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13 | #include "common/ieee802_11_common.h" |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 14 | #include "common/wpa_ctrl.h" |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 15 | #include "common/ocv.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 16 | #include "rsn_supp/wpa.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 17 | #include "config.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 18 | #include "wpa_supplicant_i.h" |
| 19 | #include "driver_i.h" |
| 20 | #include "scan.h" |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 21 | #include "ctrl_iface.h" |
| 22 | #include "bss.h" |
| 23 | #include "wnm_sta.h" |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 24 | #include "notify.h" |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 25 | #include "hs20_supplicant.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 26 | |
| 27 | #define MAX_TFS_IE_LEN 1024 |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 28 | #define WNM_MAX_NEIGHBOR_REPORT 10 |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 29 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 30 | #define WNM_SCAN_RESULT_AGE 2 /* 2 seconds */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 31 | |
| 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) |
| 35 | { |
| 36 | wpa_printf(MSG_DEBUG, "%s: TFS get operation %d", __func__, oper); |
| 37 | |
| 38 | return wpa_drv_wnm_oper(wpa_s, oper, wpa_s->bssid, buf, buf_len); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | /* set the TFS IE to driver */ |
| 43 | static int ieee80211_11_set_tfs_ie(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 44 | const u8 *addr, const u8 *buf, u16 buf_len, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 45 | enum wnm_oper oper) |
| 46 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 47 | u16 len = buf_len; |
| 48 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 49 | wpa_printf(MSG_DEBUG, "%s: TFS set operation %d", __func__, oper); |
| 50 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 51 | return wpa_drv_wnm_oper(wpa_s, oper, addr, (u8 *) buf, &len); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | |
| 55 | /* MLME-SLEEPMODE.request */ |
| 56 | int ieee802_11_send_wnmsleep_req(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 57 | u8 action, u16 intval, struct wpabuf *tfs_req) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 58 | { |
| 59 | struct ieee80211_mgmt *mgmt; |
| 60 | int res; |
| 61 | size_t len; |
| 62 | struct wnm_sleep_element *wnmsleep_ie; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 63 | u8 *wnmtfs_ie, *oci_ie; |
| 64 | u8 wnmsleep_ie_len, oci_ie_len; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 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; |
| 68 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 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)); |
| 73 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 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) |
| 78 | return -1; |
| 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; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 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); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 86 | |
| 87 | /* TFS IE(s) */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 88 | if (tfs_req) { |
| 89 | wnmtfs_ie_len = wpabuf_len(tfs_req); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 90 | wnmtfs_ie = os_memdup(wpabuf_head(tfs_req), wnmtfs_ie_len); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 91 | if (wnmtfs_ie == NULL) { |
| 92 | os_free(wnmsleep_ie); |
| 93 | return -1; |
| 94 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 95 | } else { |
| 96 | wnmtfs_ie = os_zalloc(MAX_TFS_IE_LEN); |
| 97 | if (wnmtfs_ie == NULL) { |
| 98 | os_free(wnmsleep_ie); |
| 99 | return -1; |
| 100 | } |
| 101 | if (ieee80211_11_get_tfs_ie(wpa_s, wnmtfs_ie, &wnmtfs_ie_len, |
| 102 | tfs_oper)) { |
| 103 | wnmtfs_ie_len = 0; |
| 104 | os_free(wnmtfs_ie); |
| 105 | wnmtfs_ie = NULL; |
| 106 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 107 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 108 | wpa_hexdump(MSG_DEBUG, "WNM: TFS Request element", |
| 109 | (u8 *) wnmtfs_ie, wnmtfs_ie_len); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 110 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 111 | oci_ie = NULL; |
| 112 | oci_ie_len = 0; |
| 113 | #ifdef CONFIG_OCV |
| 114 | if (action == WNM_SLEEP_MODE_EXIT && wpa_sm_ocv_enabled(wpa_s->wpa)) { |
| 115 | struct wpa_channel_info ci; |
| 116 | |
| 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); |
| 121 | os_free(wnmtfs_ie); |
| 122 | return -1; |
| 123 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 124 | #ifdef CONFIG_TESTING_OPTIONS |
| 125 | if (wpa_s->oci_freq_override_wnm_sleep) { |
| 126 | wpa_printf(MSG_INFO, |
| 127 | "TEST: Override OCI KDE frequency %d -> %d MHz", |
| 128 | ci.frequency, |
| 129 | wpa_s->oci_freq_override_wnm_sleep); |
| 130 | ci.frequency = wpa_s->oci_freq_override_wnm_sleep; |
| 131 | } |
| 132 | #endif /* CONFIG_TESTING_OPTIONS */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 133 | |
| 134 | oci_ie_len = OCV_OCI_EXTENDED_LEN; |
| 135 | oci_ie = os_zalloc(oci_ie_len); |
| 136 | if (!oci_ie) { |
| 137 | wpa_printf(MSG_WARNING, |
| 138 | "Failed to allocate buffer for for OCI element in WNM-Sleep Mode frame"); |
| 139 | os_free(wnmsleep_ie); |
| 140 | os_free(wnmtfs_ie); |
| 141 | return -1; |
| 142 | } |
| 143 | |
| 144 | if (ocv_insert_extended_oci(&ci, oci_ie) < 0) { |
| 145 | os_free(wnmsleep_ie); |
| 146 | os_free(wnmtfs_ie); |
| 147 | os_free(oci_ie); |
| 148 | return -1; |
| 149 | } |
| 150 | } |
| 151 | #endif /* CONFIG_OCV */ |
| 152 | |
| 153 | mgmt = os_zalloc(sizeof(*mgmt) + wnmsleep_ie_len + wnmtfs_ie_len + |
| 154 | oci_ie_len); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 155 | if (mgmt == NULL) { |
| 156 | wpa_printf(MSG_DEBUG, "MLME: Failed to allocate buffer for " |
| 157 | "WNM-Sleep Request action frame"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 158 | os_free(wnmsleep_ie); |
| 159 | os_free(wnmtfs_ie); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 160 | return -1; |
| 161 | } |
| 162 | |
| 163 | os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN); |
| 164 | os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN); |
| 165 | os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN); |
| 166 | mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 167 | WLAN_FC_STYPE_ACTION); |
| 168 | mgmt->u.action.category = WLAN_ACTION_WNM; |
| 169 | mgmt->u.action.u.wnm_sleep_req.action = WNM_SLEEP_MODE_REQ; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 170 | mgmt->u.action.u.wnm_sleep_req.dialogtoken = 1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 171 | os_memcpy(mgmt->u.action.u.wnm_sleep_req.variable, wnmsleep_ie, |
| 172 | wnmsleep_ie_len); |
| 173 | /* copy TFS IE here */ |
| 174 | if (wnmtfs_ie_len > 0) { |
| 175 | os_memcpy(mgmt->u.action.u.wnm_sleep_req.variable + |
| 176 | wnmsleep_ie_len, wnmtfs_ie, wnmtfs_ie_len); |
| 177 | } |
| 178 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 179 | #ifdef CONFIG_OCV |
| 180 | /* copy OCV OCI here */ |
| 181 | if (oci_ie_len > 0) { |
| 182 | os_memcpy(mgmt->u.action.u.wnm_sleep_req.variable + |
| 183 | wnmsleep_ie_len + wnmtfs_ie_len, oci_ie, oci_ie_len); |
| 184 | } |
| 185 | #endif /* CONFIG_OCV */ |
| 186 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 187 | len = 1 + sizeof(mgmt->u.action.u.wnm_sleep_req) + wnmsleep_ie_len + |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 188 | wnmtfs_ie_len + oci_ie_len; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 189 | |
| 190 | res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 191 | wpa_s->own_addr, wpa_s->bssid, |
| 192 | &mgmt->u.action.category, len, 0); |
| 193 | if (res < 0) |
| 194 | wpa_printf(MSG_DEBUG, "Failed to send WNM-Sleep Request " |
| 195 | "(action=%d, intval=%d)", action, intval); |
Dmitry Shmidt | b70d0bb | 2015-11-16 10:43:06 -0800 | [diff] [blame] | 196 | else |
| 197 | wpa_s->wnmsleep_used = 1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 198 | |
| 199 | os_free(wnmsleep_ie); |
| 200 | os_free(wnmtfs_ie); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 201 | os_free(oci_ie); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 202 | os_free(mgmt); |
| 203 | |
| 204 | return res; |
| 205 | } |
| 206 | |
| 207 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 208 | static void wnm_sleep_mode_enter_success(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 209 | const u8 *tfsresp_ie_start, |
| 210 | const u8 *tfsresp_ie_end) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 211 | { |
| 212 | wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_ENTER_CONFIRM, |
| 213 | wpa_s->bssid, NULL, NULL); |
| 214 | /* remove GTK/IGTK ?? */ |
| 215 | |
| 216 | /* set the TFS Resp IE(s) */ |
| 217 | if (tfsresp_ie_start && tfsresp_ie_end && |
| 218 | tfsresp_ie_end - tfsresp_ie_start >= 0) { |
| 219 | u16 tfsresp_ie_len; |
| 220 | tfsresp_ie_len = (tfsresp_ie_end + tfsresp_ie_end[1] + 2) - |
| 221 | tfsresp_ie_start; |
| 222 | wpa_printf(MSG_DEBUG, "TFS Resp IE(s) found"); |
| 223 | /* pass the TFS Resp IE(s) to driver for processing */ |
| 224 | if (ieee80211_11_set_tfs_ie(wpa_s, wpa_s->bssid, |
| 225 | tfsresp_ie_start, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 226 | tfsresp_ie_len, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 227 | WNM_SLEEP_TFS_RESP_IE_SET)) |
| 228 | wpa_printf(MSG_DEBUG, "WNM: Fail to set TFS Resp IE"); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | |
| 233 | static void wnm_sleep_mode_exit_success(struct wpa_supplicant *wpa_s, |
| 234 | const u8 *frm, u16 key_len_total) |
| 235 | { |
| 236 | u8 *ptr, *end; |
| 237 | u8 gtk_len; |
| 238 | |
| 239 | wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_EXIT_CONFIRM, wpa_s->bssid, |
| 240 | NULL, NULL); |
| 241 | |
| 242 | /* Install GTK/IGTK */ |
| 243 | |
| 244 | /* point to key data field */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 245 | ptr = (u8 *) frm + 1 + 2; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 246 | end = ptr + key_len_total; |
| 247 | wpa_hexdump_key(MSG_DEBUG, "WNM: Key Data", ptr, key_len_total); |
| 248 | |
Jouni Malinen | 17de68d | 2015-11-09 15:25:41 -0800 | [diff] [blame] | 249 | if (key_len_total && !wpa_sm_pmf_enabled(wpa_s->wpa)) { |
| 250 | wpa_msg(wpa_s, MSG_INFO, |
| 251 | "WNM: Ignore Key Data in WNM-Sleep Mode Response - PMF not enabled"); |
| 252 | return; |
| 253 | } |
| 254 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 255 | while (end - ptr > 1) { |
| 256 | if (2 + ptr[1] > end - ptr) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 257 | wpa_printf(MSG_DEBUG, "WNM: Invalid Key Data element " |
| 258 | "length"); |
| 259 | if (end > ptr) { |
| 260 | wpa_hexdump(MSG_DEBUG, "WNM: Remaining data", |
| 261 | ptr, end - ptr); |
| 262 | } |
| 263 | break; |
| 264 | } |
| 265 | if (*ptr == WNM_SLEEP_SUBELEM_GTK) { |
| 266 | if (ptr[1] < 11 + 5) { |
| 267 | wpa_printf(MSG_DEBUG, "WNM: Too short GTK " |
| 268 | "subelem"); |
| 269 | break; |
| 270 | } |
| 271 | gtk_len = *(ptr + 4); |
| 272 | if (ptr[1] < 11 + gtk_len || |
| 273 | gtk_len < 5 || gtk_len > 32) { |
| 274 | wpa_printf(MSG_DEBUG, "WNM: Invalid GTK " |
| 275 | "subelem"); |
| 276 | break; |
| 277 | } |
| 278 | wpa_wnmsleep_install_key( |
| 279 | wpa_s->wpa, |
| 280 | WNM_SLEEP_SUBELEM_GTK, |
| 281 | ptr); |
| 282 | ptr += 13 + gtk_len; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 283 | } else if (*ptr == WNM_SLEEP_SUBELEM_IGTK) { |
| 284 | if (ptr[1] < 2 + 6 + WPA_IGTK_LEN) { |
| 285 | wpa_printf(MSG_DEBUG, "WNM: Too short IGTK " |
| 286 | "subelem"); |
| 287 | break; |
| 288 | } |
| 289 | wpa_wnmsleep_install_key(wpa_s->wpa, |
| 290 | WNM_SLEEP_SUBELEM_IGTK, ptr); |
| 291 | ptr += 10 + WPA_IGTK_LEN; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 292 | } else if (*ptr == WNM_SLEEP_SUBELEM_BIGTK) { |
| 293 | if (ptr[1] < 2 + 6 + WPA_BIGTK_LEN) { |
| 294 | wpa_printf(MSG_DEBUG, |
| 295 | "WNM: Too short BIGTK subelem"); |
| 296 | break; |
| 297 | } |
| 298 | wpa_wnmsleep_install_key(wpa_s->wpa, |
| 299 | WNM_SLEEP_SUBELEM_BIGTK, ptr); |
| 300 | ptr += 10 + WPA_BIGTK_LEN; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 301 | } else |
| 302 | break; /* skip the loop */ |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 307 | static void ieee802_11_rx_wnmsleep_resp(struct wpa_supplicant *wpa_s, |
| 308 | const u8 *frm, int len) |
| 309 | { |
| 310 | /* |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 311 | * Action [1] | Dialog Token [1] | Key Data Len [2] | Key Data | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 312 | * WNM-Sleep Mode IE | TFS Response IE |
| 313 | */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 314 | const u8 *pos = frm; /* point to payload after the action field */ |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 315 | u16 key_len_total; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 316 | struct wnm_sleep_element *wnmsleep_ie = NULL; |
| 317 | /* multiple TFS Resp IE (assuming consecutive) */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 318 | const u8 *tfsresp_ie_start = NULL; |
| 319 | const u8 *tfsresp_ie_end = NULL; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 320 | #ifdef CONFIG_OCV |
| 321 | const u8 *oci_ie = NULL; |
| 322 | u8 oci_ie_len = 0; |
| 323 | #endif /* CONFIG_OCV */ |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 324 | size_t left; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 325 | |
Dmitry Shmidt | b70d0bb | 2015-11-16 10:43:06 -0800 | [diff] [blame] | 326 | if (!wpa_s->wnmsleep_used) { |
| 327 | wpa_printf(MSG_DEBUG, |
Jouni Malinen | 90bfa45 | 2017-09-22 11:25:02 +0300 | [diff] [blame] | 328 | "WNM: Ignore WNM-Sleep Mode Response frame since WNM-Sleep Mode operation has not been requested"); |
Dmitry Shmidt | b70d0bb | 2015-11-16 10:43:06 -0800 | [diff] [blame] | 329 | return; |
| 330 | } |
| 331 | |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 332 | if (len < 3) |
| 333 | return; |
| 334 | key_len_total = WPA_GET_LE16(frm + 1); |
| 335 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 336 | wpa_printf(MSG_DEBUG, "WNM-Sleep Mode Response token=%u key_len_total=%d", |
| 337 | frm[0], key_len_total); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 338 | left = len - 3; |
| 339 | if (key_len_total > left) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 340 | wpa_printf(MSG_INFO, "WNM: Too short frame for Key Data field"); |
| 341 | return; |
| 342 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 343 | pos += 3 + key_len_total; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 344 | while (pos - frm + 1 < len) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 345 | u8 ie_len = *(pos + 1); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 346 | if (2 + ie_len > frm + len - pos) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 347 | wpa_printf(MSG_INFO, "WNM: Invalid IE len %u", ie_len); |
| 348 | break; |
| 349 | } |
| 350 | wpa_hexdump(MSG_DEBUG, "WNM: Element", pos, 2 + ie_len); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 351 | if (*pos == WLAN_EID_WNMSLEEP && ie_len >= 4) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 352 | wnmsleep_ie = (struct wnm_sleep_element *) pos; |
| 353 | else if (*pos == WLAN_EID_TFS_RESP) { |
| 354 | if (!tfsresp_ie_start) |
| 355 | tfsresp_ie_start = pos; |
| 356 | tfsresp_ie_end = pos; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 357 | #ifdef CONFIG_OCV |
| 358 | } else if (*pos == WLAN_EID_EXTENSION && ie_len >= 1 && |
| 359 | pos[2] == WLAN_EID_EXT_OCV_OCI) { |
| 360 | oci_ie = pos + 3; |
| 361 | oci_ie_len = ie_len - 1; |
| 362 | #endif /* CONFIG_OCV */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 363 | } else |
| 364 | wpa_printf(MSG_DEBUG, "EID %d not recognized", *pos); |
| 365 | pos += ie_len + 2; |
| 366 | } |
| 367 | |
| 368 | if (!wnmsleep_ie) { |
| 369 | wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found"); |
| 370 | return; |
| 371 | } |
| 372 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 373 | #ifdef CONFIG_OCV |
| 374 | if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT && |
| 375 | wpa_sm_ocv_enabled(wpa_s->wpa)) { |
| 376 | struct wpa_channel_info ci; |
| 377 | |
| 378 | if (wpa_drv_channel_info(wpa_s, &ci) != 0) { |
| 379 | wpa_msg(wpa_s, MSG_WARNING, |
| 380 | "Failed to get channel info to validate received OCI in WNM-Sleep Mode frame"); |
| 381 | return; |
| 382 | } |
| 383 | |
| 384 | if (ocv_verify_tx_params(oci_ie, oci_ie_len, &ci, |
| 385 | channel_width_to_int(ci.chanwidth), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 386 | ci.seg1_idx) != OCI_SUCCESS) { |
| 387 | wpa_msg(wpa_s, MSG_WARNING, "WNM: OCV failed: %s", |
| 388 | ocv_errorstr); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 389 | return; |
| 390 | } |
| 391 | } |
| 392 | #endif /* CONFIG_OCV */ |
| 393 | |
Jouni Malinen | 90bfa45 | 2017-09-22 11:25:02 +0300 | [diff] [blame] | 394 | wpa_s->wnmsleep_used = 0; |
| 395 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 396 | if (wnmsleep_ie->status == WNM_STATUS_SLEEP_ACCEPT || |
| 397 | wnmsleep_ie->status == WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 398 | wpa_printf(MSG_DEBUG, "Successfully recv WNM-Sleep Response " |
| 399 | "frame (action=%d, intval=%d)", |
| 400 | wnmsleep_ie->action_type, wnmsleep_ie->intval); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 401 | if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER) { |
| 402 | wnm_sleep_mode_enter_success(wpa_s, tfsresp_ie_start, |
| 403 | tfsresp_ie_end); |
| 404 | } else if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) { |
| 405 | wnm_sleep_mode_exit_success(wpa_s, frm, key_len_total); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 406 | } |
| 407 | } else { |
| 408 | wpa_printf(MSG_DEBUG, "Reject recv WNM-Sleep Response frame " |
| 409 | "(action=%d, intval=%d)", |
| 410 | wnmsleep_ie->action_type, wnmsleep_ie->intval); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 411 | if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 412 | wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_ENTER_FAIL, |
| 413 | wpa_s->bssid, NULL, NULL); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 414 | else if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 415 | wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_EXIT_FAIL, |
| 416 | wpa_s->bssid, NULL, NULL); |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 421 | void wnm_btm_reset(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 422 | { |
| 423 | int i; |
| 424 | |
| 425 | for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 426 | os_free(wpa_s->wnm_neighbor_report_elements[i].meas_pilot); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 427 | os_free(wpa_s->wnm_neighbor_report_elements[i].mul_bssid); |
| 428 | } |
| 429 | |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 430 | wpa_s->wnm_num_neighbor_report = 0; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 431 | os_free(wpa_s->wnm_neighbor_report_elements); |
| 432 | wpa_s->wnm_neighbor_report_elements = NULL; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 433 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 434 | wpa_s->wnm_cand_valid_until.sec = 0; |
| 435 | wpa_s->wnm_cand_valid_until.usec = 0; |
| 436 | |
| 437 | wpa_s->wnm_mode = 0; |
| 438 | wpa_s->wnm_dialog_token = 0; |
| 439 | wpa_s->wnm_reply = 0; |
| 440 | |
| 441 | #ifdef CONFIG_MBO |
| 442 | wpa_s->wnm_mbo_trans_reason_present = 0; |
| 443 | wpa_s->wnm_mbo_transition_reason = 0; |
| 444 | #endif /* CONFIG_MBO */ |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | |
| 448 | static void wnm_parse_neighbor_report_elem(struct neighbor_report *rep, |
| 449 | u8 id, u8 elen, const u8 *pos) |
| 450 | { |
| 451 | switch (id) { |
| 452 | case WNM_NEIGHBOR_TSF: |
| 453 | if (elen < 2 + 2) { |
| 454 | wpa_printf(MSG_DEBUG, "WNM: Too short TSF"); |
| 455 | break; |
| 456 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 457 | rep->tsf_offset = WPA_GET_LE16(pos); |
| 458 | rep->beacon_int = WPA_GET_LE16(pos + 2); |
| 459 | rep->tsf_present = 1; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 460 | break; |
| 461 | case WNM_NEIGHBOR_CONDENSED_COUNTRY_STRING: |
| 462 | if (elen < 2) { |
| 463 | wpa_printf(MSG_DEBUG, "WNM: Too short condensed " |
| 464 | "country string"); |
| 465 | break; |
| 466 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 467 | os_memcpy(rep->country, pos, 2); |
| 468 | rep->country_present = 1; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 469 | break; |
| 470 | case WNM_NEIGHBOR_BSS_TRANSITION_CANDIDATE: |
| 471 | if (elen < 1) { |
| 472 | wpa_printf(MSG_DEBUG, "WNM: Too short BSS transition " |
| 473 | "candidate"); |
| 474 | break; |
| 475 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 476 | rep->preference = pos[0]; |
| 477 | rep->preference_present = 1; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 478 | break; |
| 479 | case WNM_NEIGHBOR_BSS_TERMINATION_DURATION: |
Hai Shalom | cb95c3f | 2019-02-04 12:53:10 -0800 | [diff] [blame] | 480 | if (elen < 10) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 481 | wpa_printf(MSG_DEBUG, |
| 482 | "WNM: Too short BSS termination duration"); |
Hai Shalom | cb95c3f | 2019-02-04 12:53:10 -0800 | [diff] [blame] | 483 | break; |
| 484 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 485 | rep->bss_term_tsf = WPA_GET_LE64(pos); |
| 486 | rep->bss_term_dur = WPA_GET_LE16(pos + 8); |
| 487 | rep->bss_term_present = 1; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 488 | break; |
| 489 | case WNM_NEIGHBOR_BEARING: |
| 490 | if (elen < 8) { |
| 491 | wpa_printf(MSG_DEBUG, "WNM: Too short neighbor " |
| 492 | "bearing"); |
| 493 | break; |
| 494 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 495 | rep->bearing = WPA_GET_LE16(pos); |
| 496 | rep->distance = WPA_GET_LE32(pos + 2); |
| 497 | rep->rel_height = WPA_GET_LE16(pos + 2 + 4); |
| 498 | rep->bearing_present = 1; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 499 | break; |
| 500 | case WNM_NEIGHBOR_MEASUREMENT_PILOT: |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 501 | if (elen < 1) { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 502 | wpa_printf(MSG_DEBUG, "WNM: Too short measurement " |
| 503 | "pilot"); |
| 504 | break; |
| 505 | } |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 506 | os_free(rep->meas_pilot); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 507 | rep->meas_pilot = os_zalloc(sizeof(struct measurement_pilot)); |
| 508 | if (rep->meas_pilot == NULL) |
| 509 | break; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 510 | rep->meas_pilot->measurement_pilot = pos[0]; |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 511 | rep->meas_pilot->subelem_len = elen - 1; |
| 512 | os_memcpy(rep->meas_pilot->subelems, pos + 1, elen - 1); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 513 | break; |
| 514 | case WNM_NEIGHBOR_RRM_ENABLED_CAPABILITIES: |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 515 | if (elen < 5) { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 516 | wpa_printf(MSG_DEBUG, "WNM: Too short RRM enabled " |
| 517 | "capabilities"); |
| 518 | break; |
| 519 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 520 | os_memcpy(rep->rm_capab, pos, 5); |
| 521 | rep->rm_capab_present = 1; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 522 | break; |
| 523 | case WNM_NEIGHBOR_MULTIPLE_BSSID: |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 524 | if (elen < 1) { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 525 | wpa_printf(MSG_DEBUG, "WNM: Too short multiple BSSID"); |
| 526 | break; |
| 527 | } |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 528 | os_free(rep->mul_bssid); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 529 | rep->mul_bssid = os_zalloc(sizeof(struct multiple_bssid)); |
| 530 | if (rep->mul_bssid == NULL) |
| 531 | break; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 532 | rep->mul_bssid->max_bssid_indicator = pos[0]; |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 533 | rep->mul_bssid->subelem_len = elen - 1; |
| 534 | os_memcpy(rep->mul_bssid->subelems, pos + 1, elen - 1); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 535 | break; |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 536 | default: |
| 537 | wpa_printf(MSG_DEBUG, |
| 538 | "WNM: Unsupported neighbor report subelement id %u", |
| 539 | id); |
| 540 | break; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
| 544 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 545 | static int wnm_nei_get_chan(struct wpa_supplicant *wpa_s, u8 op_class, u8 chan) |
| 546 | { |
| 547 | struct wpa_bss *bss = wpa_s->current_bss; |
| 548 | const char *country = NULL; |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 549 | int freq; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 550 | |
| 551 | if (bss) { |
| 552 | const u8 *elem = wpa_bss_get_ie(bss, WLAN_EID_COUNTRY); |
| 553 | |
| 554 | if (elem && elem[1] >= 2) |
| 555 | country = (const char *) (elem + 2); |
| 556 | } |
| 557 | |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 558 | freq = ieee80211_chan_to_freq(country, op_class, chan); |
| 559 | if (freq <= 0 && op_class == 0) { |
| 560 | /* |
| 561 | * Some APs do not advertise correct operating class |
| 562 | * information. Try to determine the most likely operating |
| 563 | * frequency based on the channel number. |
| 564 | */ |
| 565 | if (chan >= 1 && chan <= 13) |
| 566 | freq = 2407 + chan * 5; |
| 567 | else if (chan == 14) |
| 568 | freq = 2484; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 569 | else if (chan >= 36 && chan <= 177) |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 570 | freq = 5000 + chan * 5; |
| 571 | } |
| 572 | return freq; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 576 | static void wnm_parse_neighbor_report(struct wpa_supplicant *wpa_s, |
| 577 | const u8 *pos, u8 len, |
| 578 | struct neighbor_report *rep) |
| 579 | { |
| 580 | u8 left = len; |
| 581 | |
| 582 | if (left < 13) { |
| 583 | wpa_printf(MSG_DEBUG, "WNM: Too short neighbor report"); |
| 584 | return; |
| 585 | } |
| 586 | |
| 587 | os_memcpy(rep->bssid, pos, ETH_ALEN); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 588 | rep->bssid_info = WPA_GET_LE32(pos + ETH_ALEN); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 589 | rep->regulatory_class = *(pos + 10); |
| 590 | rep->channel_number = *(pos + 11); |
| 591 | rep->phy_type = *(pos + 12); |
| 592 | |
| 593 | pos += 13; |
| 594 | left -= 13; |
| 595 | |
| 596 | while (left >= 2) { |
| 597 | u8 id, elen; |
| 598 | |
| 599 | id = *pos++; |
| 600 | elen = *pos++; |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 601 | wpa_printf(MSG_DEBUG, "WNM: Subelement id=%u len=%u", id, elen); |
| 602 | left -= 2; |
| 603 | if (elen > left) { |
| 604 | wpa_printf(MSG_DEBUG, |
| 605 | "WNM: Truncated neighbor report subelement"); |
| 606 | break; |
| 607 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 608 | wnm_parse_neighbor_report_elem(rep, id, elen, pos); |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 609 | left -= elen; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 610 | pos += elen; |
| 611 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 612 | |
| 613 | rep->freq = wnm_nei_get_chan(wpa_s, rep->regulatory_class, |
| 614 | rep->channel_number); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 618 | static void wnm_clear_acceptable(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 619 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 620 | unsigned int i; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 621 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 622 | for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) |
| 623 | wpa_s->wnm_neighbor_report_elements[i].acceptable = 0; |
| 624 | } |
| 625 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 626 | #ifdef CONFIG_MBO |
| 627 | static struct wpa_bss * |
| 628 | get_mbo_transition_candidate(struct wpa_supplicant *wpa_s, |
| 629 | enum mbo_transition_reject_reason *reason) |
| 630 | { |
| 631 | struct wpa_bss *target = NULL; |
| 632 | struct wpa_bss_trans_info params; |
| 633 | struct wpa_bss_candidate_info *info = NULL; |
| 634 | struct neighbor_report *nei = wpa_s->wnm_neighbor_report_elements; |
| 635 | u8 *first_candidate_bssid = NULL, *pos; |
| 636 | unsigned int i; |
| 637 | |
| 638 | params.mbo_transition_reason = wpa_s->wnm_mbo_transition_reason; |
| 639 | params.n_candidates = 0; |
| 640 | params.bssid = os_calloc(wpa_s->wnm_num_neighbor_report, ETH_ALEN); |
| 641 | if (!params.bssid) |
| 642 | return NULL; |
| 643 | |
| 644 | pos = params.bssid; |
| 645 | for (i = 0; i < wpa_s->wnm_num_neighbor_report; nei++, i++) { |
| 646 | if (nei->is_first) |
| 647 | first_candidate_bssid = nei->bssid; |
| 648 | if (!nei->acceptable) |
| 649 | continue; |
| 650 | os_memcpy(pos, nei->bssid, ETH_ALEN); |
| 651 | pos += ETH_ALEN; |
| 652 | params.n_candidates++; |
| 653 | } |
| 654 | |
| 655 | if (!params.n_candidates) |
| 656 | goto end; |
| 657 | |
| 658 | info = wpa_drv_get_bss_trans_status(wpa_s, ¶ms); |
| 659 | if (!info) { |
| 660 | /* If failed to get candidate BSS transition status from driver, |
| 661 | * get the first acceptable candidate from wpa_supplicant. |
| 662 | */ |
| 663 | target = wpa_bss_get_bssid(wpa_s, params.bssid); |
| 664 | goto end; |
| 665 | } |
| 666 | |
| 667 | /* Get the first acceptable candidate from driver */ |
| 668 | for (i = 0; i < info->num; i++) { |
| 669 | if (info->candidates[i].is_accept) { |
| 670 | target = wpa_bss_get_bssid(wpa_s, |
| 671 | info->candidates[i].bssid); |
| 672 | goto end; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | /* If Disassociation Imminent is set and driver rejects all the |
| 677 | * candidate select first acceptable candidate which has |
| 678 | * rssi > disassoc_imminent_rssi_threshold |
| 679 | */ |
| 680 | if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_DISASSOC_IMMINENT) { |
| 681 | for (i = 0; i < info->num; i++) { |
| 682 | target = wpa_bss_get_bssid(wpa_s, |
| 683 | info->candidates[i].bssid); |
| 684 | if (target && |
| 685 | (target->level < |
| 686 | wpa_s->conf->disassoc_imminent_rssi_threshold)) |
| 687 | continue; |
| 688 | goto end; |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | /* While sending BTM reject use reason code of the first candidate |
| 693 | * received in BTM request frame |
| 694 | */ |
| 695 | if (reason) { |
| 696 | for (i = 0; i < info->num; i++) { |
| 697 | if (first_candidate_bssid && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 698 | ether_addr_equal(first_candidate_bssid, |
| 699 | info->candidates[i].bssid)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 700 | *reason = info->candidates[i].reject_reason; |
| 701 | break; |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | target = NULL; |
| 707 | |
| 708 | end: |
| 709 | os_free(params.bssid); |
| 710 | if (info) { |
| 711 | os_free(info->candidates); |
| 712 | os_free(info); |
| 713 | } |
| 714 | return target; |
| 715 | } |
| 716 | #endif /* CONFIG_MBO */ |
| 717 | |
| 718 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 719 | static struct wpa_bss * find_better_target(struct wpa_bss *a, |
| 720 | struct wpa_bss *b) |
| 721 | { |
| 722 | if (!a) |
| 723 | return b; |
| 724 | if (!b) |
| 725 | return a; |
| 726 | |
| 727 | if (a->est_throughput > b->est_throughput) { |
| 728 | wpa_printf(MSG_DEBUG, "WNM: A is better: " MACSTR |
| 729 | " est-tput: %d B: " MACSTR " est-tput: %d", |
| 730 | MAC2STR(a->bssid), a->est_throughput, |
| 731 | MAC2STR(b->bssid), b->est_throughput); |
| 732 | return a; |
| 733 | } |
| 734 | |
| 735 | wpa_printf(MSG_DEBUG, "WNM: B is better, A: " MACSTR |
| 736 | " est-tput: %d B: " MACSTR " est-tput: %d", |
| 737 | MAC2STR(a->bssid), a->est_throughput, |
| 738 | MAC2STR(b->bssid), b->est_throughput); |
| 739 | return b; |
| 740 | } |
| 741 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 742 | static struct wpa_bss * |
| 743 | compare_scan_neighbor_results(struct wpa_supplicant *wpa_s, os_time_t age_secs, |
| 744 | enum mbo_transition_reject_reason *reason) |
| 745 | { |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 746 | u8 i; |
| 747 | struct wpa_bss *bss = wpa_s->current_bss; |
| 748 | struct wpa_bss *target; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 749 | struct wpa_bss *best_target = NULL; |
| 750 | struct wpa_bss *bss_in_list = NULL; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 751 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 752 | if (!bss) |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 753 | return NULL; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 754 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 755 | wpa_printf(MSG_DEBUG, "WNM: Current BSS " MACSTR " RSSI %d", |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 756 | MAC2STR(wpa_s->bssid), bss->level); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 757 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 758 | wnm_clear_acceptable(wpa_s); |
| 759 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 760 | for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) { |
| 761 | struct neighbor_report *nei; |
| 762 | |
| 763 | nei = &wpa_s->wnm_neighbor_report_elements[i]; |
| 764 | if (nei->preference_present && nei->preference == 0) { |
| 765 | wpa_printf(MSG_DEBUG, "Skip excluded BSS " MACSTR, |
| 766 | MAC2STR(nei->bssid)); |
| 767 | continue; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 768 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 769 | |
| 770 | target = wpa_bss_get_bssid(wpa_s, nei->bssid); |
| 771 | if (!target) { |
| 772 | wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR |
| 773 | " (pref %d) not found in scan results", |
| 774 | MAC2STR(nei->bssid), |
| 775 | nei->preference_present ? nei->preference : |
| 776 | -1); |
| 777 | continue; |
| 778 | } |
| 779 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 780 | if (age_secs) { |
| 781 | struct os_reltime now; |
| 782 | |
| 783 | if (os_get_reltime(&now) == 0 && |
| 784 | os_reltime_expired(&now, &target->last_update, |
| 785 | age_secs)) { |
| 786 | wpa_printf(MSG_DEBUG, |
| 787 | "Candidate BSS is more than %ld seconds old", |
| 788 | age_secs); |
| 789 | continue; |
| 790 | } |
| 791 | } |
| 792 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 793 | /* |
| 794 | * TODO: Could consider allowing transition to another ESS if |
| 795 | * PMF was enabled for the association. |
| 796 | */ |
| 797 | if (!wpa_scan_res_match(wpa_s, 0, target, wpa_s->current_ssid, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 798 | 1, 0)) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 799 | wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR |
| 800 | " (pref %d) does not match the current network profile", |
| 801 | MAC2STR(nei->bssid), |
| 802 | nei->preference_present ? nei->preference : |
| 803 | -1); |
| 804 | continue; |
| 805 | } |
| 806 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 807 | if (target->level < bss->level && target->level < -80) { |
| 808 | wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR |
| 809 | " (pref %d) does not have sufficient signal level (%d)", |
| 810 | MAC2STR(nei->bssid), |
| 811 | nei->preference_present ? nei->preference : |
| 812 | -1, |
| 813 | target->level); |
| 814 | continue; |
| 815 | } |
| 816 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 817 | nei->acceptable = 1; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 818 | |
| 819 | best_target = find_better_target(target, best_target); |
| 820 | if (target == bss) |
| 821 | bss_in_list = bss; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | #ifdef CONFIG_MBO |
| 825 | if (wpa_s->wnm_mbo_trans_reason_present) |
| 826 | target = get_mbo_transition_candidate(wpa_s, reason); |
| 827 | else |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 828 | target = best_target; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 829 | #else /* CONFIG_MBO */ |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 830 | target = best_target; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 831 | #endif /* CONFIG_MBO */ |
| 832 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 833 | if (!target) |
| 834 | return NULL; |
| 835 | |
| 836 | wpa_printf(MSG_DEBUG, |
| 837 | "WNM: Found an acceptable preferred transition candidate BSS " |
| 838 | MACSTR " (RSSI %d, tput: %d bss-tput: %d)", |
| 839 | MAC2STR(target->bssid), target->level, |
| 840 | target->est_throughput, bss->est_throughput); |
| 841 | |
| 842 | if (!bss_in_list) |
| 843 | return target; |
| 844 | |
| 845 | if ((!target->est_throughput && !bss_in_list->est_throughput) || |
| 846 | (target->est_throughput > bss_in_list->est_throughput && |
| 847 | target->est_throughput - bss_in_list->est_throughput > |
| 848 | bss_in_list->est_throughput >> 4)) { |
| 849 | /* It is more than 100/16 percent better, so switch. */ |
| 850 | return target; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 851 | } |
| 852 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 853 | wpa_printf(MSG_DEBUG, |
| 854 | "WNM: Stay with our current BSS, not enough change in estimated throughput to switch"); |
| 855 | return bss_in_list; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 859 | static int wpa_bss_ies_eq(struct wpa_bss *a, struct wpa_bss *b, u8 eid) |
| 860 | { |
| 861 | const u8 *ie_a, *ie_b; |
| 862 | |
| 863 | if (!a || !b) |
| 864 | return 0; |
| 865 | |
| 866 | ie_a = wpa_bss_get_ie(a, eid); |
| 867 | ie_b = wpa_bss_get_ie(b, eid); |
| 868 | |
| 869 | if (!ie_a || !ie_b || ie_a[1] != ie_b[1]) |
| 870 | return 0; |
| 871 | |
| 872 | return os_memcmp(ie_a, ie_b, ie_a[1]) == 0; |
| 873 | } |
| 874 | |
| 875 | |
| 876 | static u32 wnm_get_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
| 877 | { |
| 878 | u32 info = 0; |
| 879 | |
| 880 | info |= NEI_REP_BSSID_INFO_AP_UNKNOWN_REACH; |
| 881 | |
| 882 | /* |
| 883 | * Leave the security and key scope bits unset to indicate that the |
| 884 | * security information is not available. |
| 885 | */ |
| 886 | |
| 887 | if (bss->caps & WLAN_CAPABILITY_SPECTRUM_MGMT) |
| 888 | info |= NEI_REP_BSSID_INFO_SPECTRUM_MGMT; |
| 889 | if (bss->caps & WLAN_CAPABILITY_QOS) |
| 890 | info |= NEI_REP_BSSID_INFO_QOS; |
| 891 | if (bss->caps & WLAN_CAPABILITY_APSD) |
| 892 | info |= NEI_REP_BSSID_INFO_APSD; |
| 893 | if (bss->caps & WLAN_CAPABILITY_RADIO_MEASUREMENT) |
| 894 | info |= NEI_REP_BSSID_INFO_RM; |
| 895 | if (bss->caps & WLAN_CAPABILITY_DELAYED_BLOCK_ACK) |
| 896 | info |= NEI_REP_BSSID_INFO_DELAYED_BA; |
| 897 | if (bss->caps & WLAN_CAPABILITY_IMM_BLOCK_ACK) |
| 898 | info |= NEI_REP_BSSID_INFO_IMM_BA; |
| 899 | if (wpa_bss_ies_eq(bss, wpa_s->current_bss, WLAN_EID_MOBILITY_DOMAIN)) |
| 900 | info |= NEI_REP_BSSID_INFO_MOBILITY_DOMAIN; |
| 901 | if (wpa_bss_ies_eq(bss, wpa_s->current_bss, WLAN_EID_HT_CAP)) |
| 902 | info |= NEI_REP_BSSID_INFO_HT; |
| 903 | |
| 904 | return info; |
| 905 | } |
| 906 | |
| 907 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 908 | static int wnm_add_nei_rep(struct wpabuf **buf, const u8 *bssid, |
| 909 | u32 bss_info, u8 op_class, u8 chan, u8 phy_type, |
| 910 | u8 pref) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 911 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 912 | if (wpabuf_len(*buf) + 18 > |
| 913 | IEEE80211_MAX_MMPDU_SIZE - IEEE80211_HDRLEN) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 914 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 915 | "WNM: No room in frame for Neighbor Report element"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 916 | return -1; |
| 917 | } |
| 918 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 919 | if (wpabuf_resize(buf, 18) < 0) { |
| 920 | wpa_printf(MSG_DEBUG, |
| 921 | "WNM: Failed to allocate memory for Neighbor Report element"); |
| 922 | return -1; |
| 923 | } |
| 924 | |
| 925 | wpabuf_put_u8(*buf, WLAN_EID_NEIGHBOR_REPORT); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 926 | /* length: 13 for basic neighbor report + 3 for preference subelement */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 927 | wpabuf_put_u8(*buf, 16); |
| 928 | wpabuf_put_data(*buf, bssid, ETH_ALEN); |
| 929 | wpabuf_put_le32(*buf, bss_info); |
| 930 | wpabuf_put_u8(*buf, op_class); |
| 931 | wpabuf_put_u8(*buf, chan); |
| 932 | wpabuf_put_u8(*buf, phy_type); |
| 933 | wpabuf_put_u8(*buf, WNM_NEIGHBOR_BSS_TRANSITION_CANDIDATE); |
| 934 | wpabuf_put_u8(*buf, 1); |
| 935 | wpabuf_put_u8(*buf, pref); |
| 936 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | |
| 940 | static int wnm_nei_rep_add_bss(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 941 | struct wpa_bss *bss, struct wpabuf **buf, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 942 | u8 pref) |
| 943 | { |
| 944 | const u8 *ie; |
| 945 | u8 op_class, chan; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 946 | int sec_chan = 0; |
| 947 | enum oper_chan_width vht = CONF_OPER_CHWIDTH_USE_HT; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 948 | enum phy_type phy_type; |
| 949 | u32 info; |
| 950 | struct ieee80211_ht_operation *ht_oper = NULL; |
| 951 | struct ieee80211_vht_operation *vht_oper = NULL; |
| 952 | |
| 953 | ie = wpa_bss_get_ie(bss, WLAN_EID_HT_OPERATION); |
| 954 | if (ie && ie[1] >= 2) { |
| 955 | ht_oper = (struct ieee80211_ht_operation *) (ie + 2); |
| 956 | |
| 957 | if (ht_oper->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE) |
| 958 | sec_chan = 1; |
| 959 | else if (ht_oper->ht_param & |
| 960 | HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW) |
| 961 | sec_chan = -1; |
| 962 | } |
| 963 | |
| 964 | ie = wpa_bss_get_ie(bss, WLAN_EID_VHT_OPERATION); |
| 965 | if (ie && ie[1] >= 1) { |
| 966 | vht_oper = (struct ieee80211_vht_operation *) (ie + 2); |
| 967 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 968 | if (vht_oper->vht_op_info_chwidth == CHANWIDTH_80MHZ || |
| 969 | vht_oper->vht_op_info_chwidth == CHANWIDTH_160MHZ || |
| 970 | vht_oper->vht_op_info_chwidth == CHANWIDTH_80P80MHZ) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 971 | vht = vht_oper->vht_op_info_chwidth; |
| 972 | } |
| 973 | |
| 974 | if (ieee80211_freq_to_channel_ext(bss->freq, sec_chan, vht, &op_class, |
| 975 | &chan) == NUM_HOSTAPD_MODES) { |
| 976 | wpa_printf(MSG_DEBUG, |
| 977 | "WNM: Cannot determine operating class and channel"); |
| 978 | return -2; |
| 979 | } |
| 980 | |
| 981 | phy_type = ieee80211_get_phy_type(bss->freq, (ht_oper != NULL), |
| 982 | (vht_oper != NULL)); |
| 983 | if (phy_type == PHY_TYPE_UNSPECIFIED) { |
| 984 | wpa_printf(MSG_DEBUG, |
| 985 | "WNM: Cannot determine BSS phy type for Neighbor Report"); |
| 986 | return -2; |
| 987 | } |
| 988 | |
| 989 | info = wnm_get_bss_info(wpa_s, bss); |
| 990 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 991 | return wnm_add_nei_rep(buf, bss->bssid, info, op_class, chan, phy_type, |
| 992 | pref); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 996 | static void wnm_add_cand_list(struct wpa_supplicant *wpa_s, struct wpabuf **buf) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 997 | { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 998 | unsigned int i, pref = 255; |
| 999 | struct os_reltime now; |
| 1000 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 1001 | |
| 1002 | if (!ssid) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1003 | return; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1004 | |
| 1005 | /* |
| 1006 | * TODO: Define when scan results are no longer valid for the candidate |
| 1007 | * list. |
| 1008 | */ |
| 1009 | os_get_reltime(&now); |
| 1010 | if (os_reltime_expired(&now, &wpa_s->last_scan, 10)) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1011 | return; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1012 | |
| 1013 | wpa_printf(MSG_DEBUG, |
| 1014 | "WNM: Add candidate list to BSS Transition Management Response frame"); |
| 1015 | for (i = 0; i < wpa_s->last_scan_res_used && pref; i++) { |
| 1016 | struct wpa_bss *bss = wpa_s->last_scan_res[i]; |
| 1017 | int res; |
| 1018 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1019 | if (wpa_scan_res_match(wpa_s, i, bss, ssid, 1, 0)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1020 | res = wnm_nei_rep_add_bss(wpa_s, bss, buf, pref--); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1021 | if (res == -2) |
| 1022 | continue; /* could not build entry for BSS */ |
| 1023 | if (res < 0) |
| 1024 | break; /* no more room for candidates */ |
| 1025 | if (pref == 1) |
| 1026 | break; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1030 | wpa_hexdump_buf(MSG_DEBUG, |
| 1031 | "WNM: BSS Transition Management Response candidate list", |
| 1032 | *buf); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1036 | #define BTM_RESP_MIN_SIZE 5 + ETH_ALEN |
| 1037 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1038 | static int wnm_send_bss_transition_mgmt_resp( |
| 1039 | struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1040 | enum bss_trans_mgmt_status_code status, |
| 1041 | enum mbo_transition_reject_reason reason, |
| 1042 | u8 delay, const u8 *target_bssid) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1043 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1044 | struct wpabuf *buf; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1045 | int res; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1046 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1047 | wpa_s->wnm_reply = 0; |
| 1048 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1049 | wpa_printf(MSG_DEBUG, |
| 1050 | "WNM: Send BSS Transition Management Response to " MACSTR |
| 1051 | " dialog_token=%u status=%u reason=%u delay=%d", |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1052 | MAC2STR(wpa_s->bssid), wpa_s->wnm_dialog_token, status, |
| 1053 | reason, delay); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1054 | if (!wpa_s->current_bss) { |
| 1055 | wpa_printf(MSG_DEBUG, |
| 1056 | "WNM: Current BSS not known - drop response"); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1057 | return -1; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1058 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1059 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1060 | buf = wpabuf_alloc(BTM_RESP_MIN_SIZE); |
| 1061 | if (!buf) { |
| 1062 | wpa_printf(MSG_DEBUG, |
| 1063 | "WNM: Failed to allocate memory for BTM response"); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1064 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1067 | wpa_s->bss_tm_status = status; |
| 1068 | wpas_notify_bss_tm_status(wpa_s); |
| 1069 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1070 | wpabuf_put_u8(buf, WLAN_ACTION_WNM); |
| 1071 | wpabuf_put_u8(buf, WNM_BSS_TRANS_MGMT_RESP); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1072 | wpabuf_put_u8(buf, wpa_s->wnm_dialog_token); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1073 | wpabuf_put_u8(buf, status); |
| 1074 | wpabuf_put_u8(buf, delay); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1075 | if (target_bssid) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1076 | wpabuf_put_data(buf, target_bssid, ETH_ALEN); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1077 | } else if (status == WNM_BSS_TM_ACCEPT) { |
| 1078 | /* |
| 1079 | * P802.11-REVmc clarifies that the Target BSSID field is always |
| 1080 | * present when status code is zero, so use a fake value here if |
| 1081 | * no BSSID is yet known. |
| 1082 | */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1083 | wpabuf_put_data(buf, "\0\0\0\0\0\0", ETH_ALEN); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1084 | } |
| 1085 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1086 | if (status == WNM_BSS_TM_ACCEPT && target_bssid) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1087 | wnm_add_cand_list(wpa_s, &buf); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1088 | |
| 1089 | #ifdef CONFIG_MBO |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1090 | if (status != WNM_BSS_TM_ACCEPT && |
| 1091 | wpa_bss_get_vendor_ie(wpa_s->current_bss, MBO_IE_VENDOR_TYPE)) { |
| 1092 | u8 mbo[10]; |
| 1093 | size_t ret; |
| 1094 | |
| 1095 | ret = wpas_mbo_ie_bss_trans_reject(wpa_s, mbo, sizeof(mbo), |
| 1096 | reason); |
| 1097 | if (ret) { |
| 1098 | if (wpabuf_resize(&buf, ret) < 0) { |
| 1099 | wpabuf_free(buf); |
| 1100 | wpa_printf(MSG_DEBUG, |
| 1101 | "WNM: Failed to allocate memory for MBO IE"); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1102 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | wpabuf_put_data(buf, mbo, ret); |
| 1106 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1107 | } |
| 1108 | #endif /* CONFIG_MBO */ |
| 1109 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1110 | res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 1111 | wpa_s->own_addr, wpa_s->bssid, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1112 | wpabuf_head_u8(buf), wpabuf_len(buf), 0); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1113 | if (res < 0) { |
| 1114 | wpa_printf(MSG_DEBUG, |
| 1115 | "WNM: Failed to send BSS Transition Management Response"); |
| 1116 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1117 | |
| 1118 | wpabuf_free(buf); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1119 | |
| 1120 | return res; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1124 | static void wnm_bss_tm_connect(struct wpa_supplicant *wpa_s, |
| 1125 | struct wpa_bss *bss, struct wpa_ssid *ssid, |
| 1126 | int after_new_scan) |
| 1127 | { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1128 | struct wpa_radio_work *already_connecting; |
| 1129 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1130 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1131 | "WNM: Transition to BSS " MACSTR |
| 1132 | " based on BSS Transition Management Request (old BSSID " |
| 1133 | MACSTR " after_new_scan=%d)", |
| 1134 | MAC2STR(bss->bssid), MAC2STR(wpa_s->bssid), after_new_scan); |
| 1135 | |
| 1136 | /* Send the BSS Management Response - Accept */ |
| 1137 | if (wpa_s->wnm_reply) { |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1138 | wpa_s->wnm_target_bss = bss; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1139 | wpa_printf(MSG_DEBUG, |
| 1140 | "WNM: Sending successful BSS Transition Management Response"); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1141 | |
| 1142 | /* This function will be called again from the TX handler to |
| 1143 | * start the actual reassociation after this response has been |
| 1144 | * delivered to the current AP. */ |
| 1145 | if (wnm_send_bss_transition_mgmt_resp( |
| 1146 | wpa_s, WNM_BSS_TM_ACCEPT, |
| 1147 | MBO_TRANSITION_REJECT_REASON_UNSPECIFIED, 0, |
| 1148 | bss->bssid) >= 0) |
| 1149 | return; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | if (bss == wpa_s->current_bss) { |
| 1153 | wpa_printf(MSG_DEBUG, |
| 1154 | "WNM: Already associated with the preferred candidate"); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1155 | wnm_btm_reset(wpa_s); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1156 | return; |
| 1157 | } |
| 1158 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1159 | already_connecting = radio_work_pending(wpa_s, "sme-connect"); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1160 | wpa_s->reassociate = 1; |
| 1161 | wpa_printf(MSG_DEBUG, "WNM: Issuing connect"); |
| 1162 | wpa_supplicant_connect(wpa_s, bss, ssid); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1163 | |
| 1164 | /* |
| 1165 | * Indicate that a BSS transition is in progress so scan results that |
| 1166 | * come in before the 'sme-connect' radio work gets executed do not |
| 1167 | * override the original connection attempt. |
| 1168 | */ |
| 1169 | if (!already_connecting && radio_work_pending(wpa_s, "sme-connect")) |
| 1170 | wpa_s->bss_trans_mgmt_in_progress = true; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1174 | int wnm_scan_process(struct wpa_supplicant *wpa_s, bool pre_scan_check) |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1175 | { |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1176 | struct wpa_bss *bss; |
| 1177 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 1178 | enum bss_trans_mgmt_status_code status = WNM_BSS_TM_REJECT_UNSPECIFIED; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1179 | enum mbo_transition_reject_reason reason = |
| 1180 | MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1181 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1182 | if (!wpa_s->wnm_dialog_token) |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1183 | return 0; |
| 1184 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1185 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1186 | "WNM: Process scan results for BSS Transition Management"); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1187 | if (!pre_scan_check && |
| 1188 | os_reltime_initialized(&wpa_s->wnm_cand_valid_until) && |
| 1189 | os_reltime_before(&wpa_s->wnm_cand_valid_until, |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1190 | &wpa_s->scan_trigger_time)) { |
| 1191 | wpa_printf(MSG_DEBUG, "WNM: Previously stored BSS transition candidate list is not valid anymore - drop it"); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1192 | goto send_bss_resp_fail; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | /* Compare the Neighbor Report and scan results */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1196 | bss = compare_scan_neighbor_results(wpa_s, 0, &reason); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1197 | |
| 1198 | /* |
| 1199 | * If this is a pre-scan check, returning 0 will trigger a scan and |
| 1200 | * another call. In that case, reject "bad" candidates in the hope of |
| 1201 | * finding a better candidate after scanning. |
| 1202 | * |
| 1203 | * Use a simple heuristic to check whether the selection is reasonable |
| 1204 | * or a scan is a good idea. For that, we need to have found a |
| 1205 | * candidate BSS (which might be the current one), it is up-to-date, |
| 1206 | * and we don't want to immediately roam back again. |
| 1207 | */ |
| 1208 | if (pre_scan_check) { |
| 1209 | struct os_reltime age; |
| 1210 | |
| 1211 | if (!bss) |
| 1212 | return 0; |
| 1213 | |
| 1214 | os_reltime_age(&bss->last_update, &age); |
| 1215 | if (age.sec >= 10) |
| 1216 | return 0; |
| 1217 | |
| 1218 | #ifndef CONFIG_NO_ROAMING |
| 1219 | if (wpa_s->current_bss && bss != wpa_s->current_bss && |
| 1220 | wpa_supplicant_need_to_roam_within_ess(wpa_s, |
| 1221 | wpa_s->current_bss, |
| 1222 | bss)) |
| 1223 | return 0; |
| 1224 | #endif /* CONFIG_NO_ROAMING */ |
| 1225 | } |
| 1226 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1227 | if (!bss) { |
| 1228 | wpa_printf(MSG_DEBUG, "WNM: No BSS transition candidate match found"); |
| 1229 | status = WNM_BSS_TM_REJECT_NO_SUITABLE_CANDIDATES; |
| 1230 | goto send_bss_resp_fail; |
| 1231 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1232 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1233 | /* Associate to the network */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1234 | wnm_bss_tm_connect(wpa_s, bss, ssid, 1); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1235 | return 1; |
| 1236 | |
| 1237 | send_bss_resp_fail: |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1238 | /* Send reject response for all the failures */ |
| 1239 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1240 | if (wpa_s->wnm_reply) |
| 1241 | wnm_send_bss_transition_mgmt_resp(wpa_s, status, reason, |
| 1242 | 0, NULL); |
| 1243 | |
| 1244 | wnm_btm_reset(wpa_s); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1245 | |
| 1246 | return 0; |
| 1247 | } |
| 1248 | |
| 1249 | |
| 1250 | static int cand_pref_compar(const void *a, const void *b) |
| 1251 | { |
| 1252 | const struct neighbor_report *aa = a; |
| 1253 | const struct neighbor_report *bb = b; |
| 1254 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1255 | if (aa->disassoc_imminent && !bb->disassoc_imminent) |
| 1256 | return 1; |
| 1257 | if (bb->disassoc_imminent && !aa->disassoc_imminent) |
| 1258 | return -1; |
| 1259 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1260 | if (!aa->preference_present && !bb->preference_present) |
| 1261 | return 0; |
| 1262 | if (!aa->preference_present) |
| 1263 | return 1; |
| 1264 | if (!bb->preference_present) |
| 1265 | return -1; |
| 1266 | if (bb->preference > aa->preference) |
| 1267 | return 1; |
| 1268 | if (bb->preference < aa->preference) |
| 1269 | return -1; |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
| 1273 | |
| 1274 | static void wnm_sort_cand_list(struct wpa_supplicant *wpa_s) |
| 1275 | { |
| 1276 | if (!wpa_s->wnm_neighbor_report_elements) |
| 1277 | return; |
| 1278 | qsort(wpa_s->wnm_neighbor_report_elements, |
| 1279 | wpa_s->wnm_num_neighbor_report, sizeof(struct neighbor_report), |
| 1280 | cand_pref_compar); |
| 1281 | } |
| 1282 | |
| 1283 | |
| 1284 | static void wnm_dump_cand_list(struct wpa_supplicant *wpa_s) |
| 1285 | { |
| 1286 | unsigned int i; |
| 1287 | |
| 1288 | wpa_printf(MSG_DEBUG, "WNM: BSS Transition Candidate List"); |
| 1289 | if (!wpa_s->wnm_neighbor_report_elements) |
| 1290 | return; |
| 1291 | for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) { |
| 1292 | struct neighbor_report *nei; |
| 1293 | |
| 1294 | nei = &wpa_s->wnm_neighbor_report_elements[i]; |
| 1295 | wpa_printf(MSG_DEBUG, "%u: " MACSTR |
| 1296 | " info=0x%x op_class=%u chan=%u phy=%u pref=%d freq=%d", |
| 1297 | i, MAC2STR(nei->bssid), nei->bssid_info, |
| 1298 | nei->regulatory_class, |
| 1299 | nei->channel_number, nei->phy_type, |
| 1300 | nei->preference_present ? nei->preference : -1, |
| 1301 | nei->freq); |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | |
| 1306 | static int chan_supported(struct wpa_supplicant *wpa_s, int freq) |
| 1307 | { |
| 1308 | unsigned int i; |
| 1309 | |
| 1310 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 1311 | struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i]; |
| 1312 | int j; |
| 1313 | |
| 1314 | for (j = 0; j < mode->num_channels; j++) { |
| 1315 | struct hostapd_channel_data *chan; |
| 1316 | |
| 1317 | chan = &mode->channels[j]; |
| 1318 | if (chan->freq == freq && |
| 1319 | !(chan->flag & HOSTAPD_CHAN_DISABLED)) |
| 1320 | return 1; |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | return 0; |
| 1325 | } |
| 1326 | |
| 1327 | |
| 1328 | static void wnm_set_scan_freqs(struct wpa_supplicant *wpa_s) |
| 1329 | { |
| 1330 | int *freqs; |
| 1331 | int num_freqs = 0; |
| 1332 | unsigned int i; |
| 1333 | |
| 1334 | if (!wpa_s->wnm_neighbor_report_elements) |
| 1335 | return; |
| 1336 | |
| 1337 | if (wpa_s->hw.modes == NULL) |
| 1338 | return; |
| 1339 | |
| 1340 | os_free(wpa_s->next_scan_freqs); |
| 1341 | wpa_s->next_scan_freqs = NULL; |
| 1342 | |
| 1343 | freqs = os_calloc(wpa_s->wnm_num_neighbor_report + 1, sizeof(int)); |
| 1344 | if (freqs == NULL) |
| 1345 | return; |
| 1346 | |
| 1347 | for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) { |
| 1348 | struct neighbor_report *nei; |
| 1349 | |
| 1350 | nei = &wpa_s->wnm_neighbor_report_elements[i]; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1351 | |
| 1352 | if (nei->preference_present && nei->preference == 0) |
| 1353 | continue; |
| 1354 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1355 | if (nei->freq <= 0) { |
| 1356 | wpa_printf(MSG_DEBUG, |
| 1357 | "WNM: Unknown neighbor operating frequency for " |
| 1358 | MACSTR " - scan all channels", |
| 1359 | MAC2STR(nei->bssid)); |
| 1360 | os_free(freqs); |
| 1361 | return; |
| 1362 | } |
| 1363 | if (chan_supported(wpa_s, nei->freq)) |
| 1364 | add_freq(freqs, &num_freqs, nei->freq); |
| 1365 | } |
| 1366 | |
| 1367 | if (num_freqs == 0) { |
| 1368 | os_free(freqs); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1369 | return; |
| 1370 | } |
| 1371 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1372 | wpa_printf(MSG_DEBUG, |
| 1373 | "WNM: Scan %d frequencies based on transition candidate list", |
| 1374 | num_freqs); |
| 1375 | wpa_s->next_scan_freqs = freqs; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1379 | static void ieee802_11_rx_bss_trans_mgmt_req(struct wpa_supplicant *wpa_s, |
| 1380 | const u8 *pos, const u8 *end, |
| 1381 | int reply) |
| 1382 | { |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1383 | unsigned int beacon_int; |
| 1384 | u8 valid_int; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1385 | #ifdef CONFIG_MBO |
| 1386 | const u8 *vendor; |
| 1387 | #endif /* CONFIG_MBO */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1388 | bool disassoc_imminent; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1389 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1390 | if (wpa_s->disable_mbo_oce || wpa_s->conf->disable_btm) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1391 | return; |
| 1392 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1393 | if (end - pos < 5) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1394 | return; |
| 1395 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1396 | #ifdef CONFIG_MBO |
Sunil Ravi | 4018d71 | 2019-12-06 18:01:21 -0800 | [diff] [blame] | 1397 | wpa_s->wnm_mbo_cell_pref_present = 0; |
| 1398 | wpa_s->wnm_mbo_cell_preference = 0; |
| 1399 | wpa_s->wnm_mbo_assoc_retry_delay_present = 0; |
| 1400 | wpa_s->wnm_mbo_assoc_retry_delay_sec = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1401 | #endif /* CONFIG_MBO */ |
| 1402 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1403 | if (wpa_s->current_bss) |
| 1404 | beacon_int = wpa_s->current_bss->beacon_int; |
| 1405 | else |
| 1406 | beacon_int = 100; /* best guess */ |
| 1407 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1408 | wnm_btm_reset(wpa_s); |
| 1409 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1410 | wpa_s->wnm_dialog_token = pos[0]; |
| 1411 | wpa_s->wnm_mode = pos[1]; |
| 1412 | wpa_s->wnm_dissoc_timer = WPA_GET_LE16(pos + 2); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1413 | wpa_s->wnm_link_removal = false; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1414 | valid_int = pos[4]; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1415 | wpa_s->wnm_reply = reply; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1416 | |
| 1417 | wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Request: " |
| 1418 | "dialog_token=%u request_mode=0x%x " |
| 1419 | "disassoc_timer=%u validity_interval=%u", |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1420 | wpa_s->wnm_dialog_token, wpa_s->wnm_mode, |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1421 | wpa_s->wnm_dissoc_timer, valid_int); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1422 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 1423 | #if defined(CONFIG_MBO) && defined(CONFIG_TESTING_OPTIONS) |
| 1424 | if (wpa_s->reject_btm_req_reason) { |
| 1425 | wpa_printf(MSG_INFO, |
| 1426 | "WNM: Testing - reject BSS Transition Management Request: reject_btm_req_reason=%d", |
| 1427 | wpa_s->reject_btm_req_reason); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1428 | wnm_send_bss_transition_mgmt_resp( |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1429 | wpa_s, wpa_s->reject_btm_req_reason, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1430 | MBO_TRANSITION_REJECT_REASON_UNSPECIFIED, 0, NULL); |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 1431 | return; |
| 1432 | } |
| 1433 | #endif /* CONFIG_MBO && CONFIG_TESTING_OPTIONS */ |
| 1434 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1435 | pos += 5; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1436 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1437 | if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1438 | if (end - pos < 12) { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1439 | wpa_printf(MSG_DEBUG, "WNM: Too short BSS TM Request"); |
| 1440 | return; |
| 1441 | } |
| 1442 | os_memcpy(wpa_s->wnm_bss_termination_duration, pos, 12); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1443 | pos += 12; /* BSS Termination Duration */ |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1446 | if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1447 | char url[256]; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1448 | u8 url_len; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1449 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1450 | if (end - pos < 1) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1451 | wpa_printf(MSG_DEBUG, "WNM: Invalid BSS Transition " |
| 1452 | "Management Request (URL)"); |
| 1453 | return; |
| 1454 | } |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1455 | url_len = *pos++; |
| 1456 | if (url_len > end - pos) { |
| 1457 | wpa_printf(MSG_DEBUG, |
| 1458 | "WNM: Invalid BSS Transition Management Request (URL truncated)"); |
| 1459 | return; |
| 1460 | } |
| 1461 | os_memcpy(url, pos, url_len); |
| 1462 | url[url_len] = '\0'; |
| 1463 | pos += url_len; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1464 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1465 | wpa_msg(wpa_s, MSG_INFO, ESS_DISASSOC_IMMINENT "%d %u %s", |
| 1466 | wpa_sm_pmf_enabled(wpa_s->wpa), |
| 1467 | wpa_s->wnm_dissoc_timer * beacon_int * 128 / 125, url); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1468 | } |
| 1469 | |
Dennis Jeon | e2cb56b | 2020-10-23 21:23:01 +0900 | [diff] [blame] | 1470 | #ifdef CONFIG_MBO |
| 1471 | vendor = get_ie(pos, end - pos, WLAN_EID_VENDOR_SPECIFIC); |
| 1472 | if (vendor) { |
| 1473 | wpas_mbo_ie_trans_req(wpa_s, vendor + 2, vendor[1]); |
Dennis Jeon | e2cb56b | 2020-10-23 21:23:01 +0900 | [diff] [blame] | 1474 | } |
| 1475 | #endif /* CONFIG_MBO */ |
Sunil Ravi | 84bb3e1 | 2021-06-10 09:52:05 -0700 | [diff] [blame] | 1476 | if (wpa_s->conf->btm_offload) { |
| 1477 | wpa_printf(MSG_INFO, |
| 1478 | "WNM: BTM offload enabled. Notify status and return"); |
| 1479 | wpa_s->bss_tm_status = WNM_BSS_TM_ACCEPT; |
| 1480 | wpas_notify_bss_tm_status(wpa_s); |
| 1481 | return; |
| 1482 | } |
Dennis Jeon | e2cb56b | 2020-10-23 21:23:01 +0900 | [diff] [blame] | 1483 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1484 | disassoc_imminent = wpa_s->wnm_mode & WNM_BSS_TM_REQ_DISASSOC_IMMINENT; |
| 1485 | |
| 1486 | /* |
| 1487 | * Based on IEEE P802.11be/D5.0, when a station is a non-AP MLD with |
| 1488 | * more than one affiliated link, the Link Removal Imminent field is |
| 1489 | * set to 1, and the BSS Termination Included field is set to 1, only |
| 1490 | * one of the links is removed and the other links remain associated. |
| 1491 | * Ignore the Disassociation Imminent field in such a case. |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1492 | * |
| 1493 | * TODO: We should check if the AP has more than one link. |
| 1494 | * TODO: We should pass the RX link and use that |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1495 | */ |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1496 | if (disassoc_imminent && wpa_s->valid_links && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1497 | (wpa_s->wnm_mode & WNM_BSS_TM_REQ_LINK_REMOVAL_IMMINENT) && |
| 1498 | (wpa_s->wnm_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED)) { |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1499 | /* If we still have a link, then just accept the request */ |
| 1500 | if (wpa_s->valid_links & (wpa_s->valid_links - 1)) { |
| 1501 | wpa_printf(MSG_INFO, |
| 1502 | "WNM: BTM request for a single MLO link - ignore disassociation imminent since other links remain associated"); |
| 1503 | disassoc_imminent = false; |
| 1504 | |
| 1505 | wnm_send_bss_transition_mgmt_resp( |
| 1506 | wpa_s, WNM_BSS_TM_ACCEPT, 0, 0, NULL); |
| 1507 | |
| 1508 | return; |
| 1509 | } |
| 1510 | |
| 1511 | /* The last link is being removed (which must be the assoc link) |
| 1512 | */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1513 | wpa_s->wnm_link_removal = true; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1514 | os_memcpy(wpa_s->wnm_dissoc_addr, |
| 1515 | wpa_s->links[wpa_s->mlo_assoc_link_id].bssid, |
| 1516 | ETH_ALEN); |
| 1517 | } else { |
| 1518 | os_memcpy(wpa_s->wnm_dissoc_addr, wpa_s->valid_links ? |
| 1519 | wpa_s->ap_mld_addr : wpa_s->bssid, ETH_ALEN); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | if (disassoc_imminent) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1523 | wpa_msg(wpa_s, MSG_INFO, "WNM: Disassociation Imminent - " |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1524 | "Disassociation Timer %u", wpa_s->wnm_dissoc_timer); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1525 | if (wpa_s->wnm_dissoc_timer && !wpa_s->scanning && |
| 1526 | (!wpa_s->current_ssid || !wpa_s->current_ssid->bssid_set)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1527 | wpa_printf(MSG_DEBUG, "Trying to find another BSS"); |
| 1528 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 1529 | } |
| 1530 | } |
| 1531 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1532 | if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED) { |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1533 | unsigned int valid_ms; |
| 1534 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1535 | wpa_msg(wpa_s, MSG_INFO, "WNM: Preferred List Available"); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1536 | wpa_s->wnm_neighbor_report_elements = os_calloc( |
| 1537 | WNM_MAX_NEIGHBOR_REPORT, |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1538 | sizeof(struct neighbor_report)); |
| 1539 | if (wpa_s->wnm_neighbor_report_elements == NULL) |
| 1540 | return; |
| 1541 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1542 | while (end - pos >= 2 && |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1543 | wpa_s->wnm_num_neighbor_report < WNM_MAX_NEIGHBOR_REPORT) |
| 1544 | { |
| 1545 | u8 tag = *pos++; |
| 1546 | u8 len = *pos++; |
| 1547 | |
| 1548 | wpa_printf(MSG_DEBUG, "WNM: Neighbor report tag %u", |
| 1549 | tag); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1550 | if (len > end - pos) { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1551 | wpa_printf(MSG_DEBUG, "WNM: Truncated request"); |
| 1552 | return; |
| 1553 | } |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 1554 | if (tag == WLAN_EID_NEIGHBOR_REPORT) { |
| 1555 | struct neighbor_report *rep; |
| 1556 | rep = &wpa_s->wnm_neighbor_report_elements[ |
| 1557 | wpa_s->wnm_num_neighbor_report]; |
| 1558 | wnm_parse_neighbor_report(wpa_s, pos, len, rep); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1559 | if ((wpa_s->wnm_mode & |
| 1560 | WNM_BSS_TM_REQ_DISASSOC_IMMINENT) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1561 | ether_addr_equal(rep->bssid, wpa_s->bssid)) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1562 | rep->disassoc_imminent = 1; |
| 1563 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1564 | wpa_s->wnm_num_neighbor_report++; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1565 | #ifdef CONFIG_MBO |
| 1566 | if (wpa_s->wnm_mbo_trans_reason_present && |
| 1567 | wpa_s->wnm_num_neighbor_report == 1) { |
| 1568 | rep->is_first = 1; |
| 1569 | wpa_printf(MSG_DEBUG, |
| 1570 | "WNM: First transition candidate is " |
| 1571 | MACSTR, MAC2STR(rep->bssid)); |
| 1572 | } |
| 1573 | #endif /* CONFIG_MBO */ |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 1574 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1575 | |
| 1576 | pos += len; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1577 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1578 | |
| 1579 | if (!wpa_s->wnm_num_neighbor_report) { |
| 1580 | wpa_printf(MSG_DEBUG, |
| 1581 | "WNM: Candidate list included bit is set, but no candidates found"); |
| 1582 | wnm_send_bss_transition_mgmt_resp( |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1583 | wpa_s, WNM_BSS_TM_REJECT_NO_SUITABLE_CANDIDATES, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1584 | MBO_TRANSITION_REJECT_REASON_UNSPECIFIED, 0, |
| 1585 | NULL); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1586 | return; |
| 1587 | } |
| 1588 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1589 | if (wpa_s->current_ssid && wpa_s->current_ssid->bssid_set) { |
| 1590 | wpa_printf(MSG_DEBUG, |
| 1591 | "WNM: Configuration prevents roaming (BSSID set)"); |
| 1592 | wnm_send_bss_transition_mgmt_resp( |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1593 | wpa_s, WNM_BSS_TM_REJECT_NO_SUITABLE_CANDIDATES, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1594 | MBO_TRANSITION_REJECT_REASON_UNSPECIFIED, 0, |
| 1595 | NULL); |
| 1596 | return; |
| 1597 | } |
| 1598 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1599 | wnm_sort_cand_list(wpa_s); |
| 1600 | wnm_dump_cand_list(wpa_s); |
| 1601 | valid_ms = valid_int * beacon_int * 128 / 125; |
| 1602 | wpa_printf(MSG_DEBUG, "WNM: Candidate list valid for %u ms", |
| 1603 | valid_ms); |
| 1604 | os_get_reltime(&wpa_s->wnm_cand_valid_until); |
| 1605 | wpa_s->wnm_cand_valid_until.sec += valid_ms / 1000; |
| 1606 | wpa_s->wnm_cand_valid_until.usec += (valid_ms % 1000) * 1000; |
| 1607 | wpa_s->wnm_cand_valid_until.sec += |
| 1608 | wpa_s->wnm_cand_valid_until.usec / 1000000; |
| 1609 | wpa_s->wnm_cand_valid_until.usec %= 1000000; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1610 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1611 | /* |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1612 | * Try fetching the latest scan results from the kernel. |
| 1613 | * This can help in finding more up-to-date information should |
| 1614 | * the driver have done some internal scanning operations after |
| 1615 | * the last scan result update in wpa_supplicant. |
| 1616 | * |
| 1617 | * It is not a new scan, this does not update the last_scan |
| 1618 | * timestamp nor will it expire old BSSs. |
| 1619 | */ |
| 1620 | wpa_supplicant_update_scan_results(wpa_s, NULL); |
| 1621 | if (wnm_scan_process(wpa_s, true) > 0) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1622 | return; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1623 | wpa_printf(MSG_DEBUG, |
| 1624 | "WNM: No valid match in previous scan results - try a new scan"); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1625 | |
| 1626 | wnm_set_scan_freqs(wpa_s); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1627 | if (wpa_s->wnm_num_neighbor_report == 1) { |
| 1628 | os_memcpy(wpa_s->next_scan_bssid, |
| 1629 | wpa_s->wnm_neighbor_report_elements[0].bssid, |
| 1630 | ETH_ALEN); |
| 1631 | wpa_printf(MSG_DEBUG, |
| 1632 | "WNM: Scan only for a specific BSSID since there is only a single candidate " |
| 1633 | MACSTR, MAC2STR(wpa_s->next_scan_bssid)); |
| 1634 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1635 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 1636 | } else if (reply) { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1637 | enum bss_trans_mgmt_status_code status; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1638 | |
| 1639 | if ((wpa_s->wnm_mode & WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT) || |
| 1640 | wpa_s->wnm_link_removal) |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1641 | status = WNM_BSS_TM_ACCEPT; |
| 1642 | else { |
| 1643 | wpa_msg(wpa_s, MSG_INFO, "WNM: BSS Transition Management Request did not include candidates"); |
| 1644 | status = WNM_BSS_TM_REJECT_UNSPECIFIED; |
| 1645 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1646 | wnm_send_bss_transition_mgmt_resp( |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1647 | wpa_s, status, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1648 | MBO_TRANSITION_REJECT_REASON_UNSPECIFIED, 0, NULL); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1653 | int wnm_btm_resp_tx_status(struct wpa_supplicant *wpa_s, const u8 *data, |
| 1654 | size_t data_len) |
| 1655 | { |
| 1656 | const struct ieee80211_mgmt *frame = |
| 1657 | (const struct ieee80211_mgmt *) data; |
| 1658 | |
| 1659 | if (data_len < |
| 1660 | IEEE80211_HDRLEN + sizeof(frame->u.action.u.bss_tm_resp) || |
| 1661 | frame->u.action.category != WLAN_ACTION_WNM || |
| 1662 | frame->u.action.u.bss_tm_resp.action != WNM_BSS_TRANS_MGMT_RESP || |
| 1663 | frame->u.action.u.bss_tm_resp.status_code != WNM_BSS_TM_ACCEPT) |
| 1664 | return -1; |
| 1665 | |
| 1666 | /* |
| 1667 | * If disassoc imminent bit was set in the request, the response may |
| 1668 | * indicate accept even if no candidate was found, so bail out here. |
| 1669 | */ |
| 1670 | if (!wpa_s->wnm_target_bss) { |
| 1671 | wpa_printf(MSG_DEBUG, "WNM: Target BSS is not set"); |
| 1672 | return 0; |
| 1673 | } |
| 1674 | |
| 1675 | if (!wpa_s->current_ssid) |
| 1676 | return 0; |
| 1677 | |
| 1678 | wnm_bss_tm_connect(wpa_s, wpa_s->wnm_target_bss, wpa_s->current_ssid, |
| 1679 | 0); |
| 1680 | |
| 1681 | wpa_s->wnm_target_bss = NULL; |
| 1682 | return 0; |
| 1683 | } |
| 1684 | |
| 1685 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1686 | #define BTM_QUERY_MIN_SIZE 4 |
| 1687 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1688 | int wnm_send_bss_transition_mgmt_query(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1689 | u8 query_reason, |
| 1690 | const char *btm_candidates, |
| 1691 | int cand_list) |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1692 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1693 | struct wpabuf *buf; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1694 | int ret; |
| 1695 | |
| 1696 | wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Query to " |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1697 | MACSTR " query_reason=%u%s", |
| 1698 | MAC2STR(wpa_s->bssid), query_reason, |
| 1699 | cand_list ? " candidate list" : ""); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1700 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1701 | buf = wpabuf_alloc(BTM_QUERY_MIN_SIZE); |
| 1702 | if (!buf) |
| 1703 | return -1; |
| 1704 | |
| 1705 | wpabuf_put_u8(buf, WLAN_ACTION_WNM); |
| 1706 | wpabuf_put_u8(buf, WNM_BSS_TRANS_MGMT_QUERY); |
| 1707 | wpabuf_put_u8(buf, 1); |
| 1708 | wpabuf_put_u8(buf, query_reason); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1709 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1710 | if (cand_list) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1711 | wnm_add_cand_list(wpa_s, &buf); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1712 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1713 | if (btm_candidates) { |
| 1714 | const size_t max_len = 1000; |
| 1715 | |
| 1716 | ret = wpabuf_resize(&buf, max_len); |
| 1717 | if (ret < 0) { |
| 1718 | wpabuf_free(buf); |
| 1719 | return ret; |
| 1720 | } |
| 1721 | |
| 1722 | ret = ieee802_11_parse_candidate_list(btm_candidates, |
| 1723 | wpabuf_put(buf, 0), |
| 1724 | max_len); |
| 1725 | if (ret < 0) { |
| 1726 | wpabuf_free(buf); |
| 1727 | return ret; |
| 1728 | } |
| 1729 | |
| 1730 | wpabuf_put(buf, ret); |
| 1731 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1732 | |
| 1733 | ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 1734 | wpa_s->own_addr, wpa_s->bssid, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1735 | wpabuf_head_u8(buf), wpabuf_len(buf), 0); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1736 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1737 | wpabuf_free(buf); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1738 | return ret; |
| 1739 | } |
| 1740 | |
| 1741 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1742 | static void ieee802_11_rx_wnm_notif_req_wfa(struct wpa_supplicant *wpa_s, |
| 1743 | const u8 *sa, const u8 *data, |
| 1744 | int len) |
| 1745 | { |
| 1746 | const u8 *pos, *end, *next; |
| 1747 | u8 ie, ie_len; |
| 1748 | |
| 1749 | pos = data; |
| 1750 | end = data + len; |
| 1751 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1752 | while (end - pos > 1) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1753 | ie = *pos++; |
| 1754 | ie_len = *pos++; |
| 1755 | wpa_printf(MSG_DEBUG, "WNM: WFA subelement %u len %u", |
| 1756 | ie, ie_len); |
| 1757 | if (ie_len > end - pos) { |
| 1758 | wpa_printf(MSG_DEBUG, "WNM: Not enough room for " |
| 1759 | "subelement"); |
| 1760 | break; |
| 1761 | } |
| 1762 | next = pos + ie_len; |
| 1763 | if (ie_len < 4) { |
| 1764 | pos = next; |
| 1765 | continue; |
| 1766 | } |
| 1767 | wpa_printf(MSG_DEBUG, "WNM: Subelement OUI %06x type %u", |
| 1768 | WPA_GET_BE24(pos), pos[3]); |
| 1769 | |
| 1770 | #ifdef CONFIG_HS20 |
| 1771 | if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 5 && |
| 1772 | WPA_GET_BE24(pos) == OUI_WFA && |
| 1773 | pos[3] == HS20_WNM_SUB_REM_NEEDED) { |
| 1774 | /* Subscription Remediation subelement */ |
| 1775 | const u8 *ie_end; |
| 1776 | u8 url_len; |
| 1777 | char *url; |
| 1778 | u8 osu_method; |
| 1779 | |
| 1780 | wpa_printf(MSG_DEBUG, "WNM: Subscription Remediation " |
| 1781 | "subelement"); |
| 1782 | ie_end = pos + ie_len; |
| 1783 | pos += 4; |
| 1784 | url_len = *pos++; |
| 1785 | if (url_len == 0) { |
| 1786 | wpa_printf(MSG_DEBUG, "WNM: No Server URL included"); |
| 1787 | url = NULL; |
| 1788 | osu_method = 1; |
| 1789 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1790 | if (url_len + 1 > ie_end - pos) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1791 | wpa_printf(MSG_DEBUG, "WNM: Not enough room for Server URL (len=%u) and Server Method (left %d)", |
| 1792 | url_len, |
| 1793 | (int) (ie_end - pos)); |
| 1794 | break; |
| 1795 | } |
| 1796 | url = os_malloc(url_len + 1); |
| 1797 | if (url == NULL) |
| 1798 | break; |
| 1799 | os_memcpy(url, pos, url_len); |
| 1800 | url[url_len] = '\0'; |
| 1801 | osu_method = pos[url_len]; |
| 1802 | } |
| 1803 | hs20_rx_subscription_remediation(wpa_s, url, |
| 1804 | osu_method); |
| 1805 | os_free(url); |
| 1806 | pos = next; |
| 1807 | continue; |
| 1808 | } |
| 1809 | |
| 1810 | if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 8 && |
| 1811 | WPA_GET_BE24(pos) == OUI_WFA && |
| 1812 | pos[3] == HS20_WNM_DEAUTH_IMMINENT_NOTICE) { |
| 1813 | const u8 *ie_end; |
| 1814 | u8 url_len; |
| 1815 | char *url; |
| 1816 | u8 code; |
| 1817 | u16 reauth_delay; |
| 1818 | |
| 1819 | ie_end = pos + ie_len; |
| 1820 | pos += 4; |
| 1821 | code = *pos++; |
| 1822 | reauth_delay = WPA_GET_LE16(pos); |
| 1823 | pos += 2; |
| 1824 | url_len = *pos++; |
| 1825 | wpa_printf(MSG_DEBUG, "WNM: HS 2.0 Deauthentication " |
| 1826 | "Imminent - Reason Code %u " |
| 1827 | "Re-Auth Delay %u URL Length %u", |
| 1828 | code, reauth_delay, url_len); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1829 | if (url_len > ie_end - pos) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1830 | break; |
| 1831 | url = os_malloc(url_len + 1); |
| 1832 | if (url == NULL) |
| 1833 | break; |
| 1834 | os_memcpy(url, pos, url_len); |
| 1835 | url[url_len] = '\0'; |
| 1836 | hs20_rx_deauth_imminent_notice(wpa_s, code, |
| 1837 | reauth_delay, url); |
| 1838 | os_free(url); |
| 1839 | pos = next; |
| 1840 | continue; |
| 1841 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1842 | |
| 1843 | if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 5 && |
| 1844 | WPA_GET_BE24(pos) == OUI_WFA && |
| 1845 | pos[3] == HS20_WNM_T_C_ACCEPTANCE) { |
| 1846 | const u8 *ie_end; |
| 1847 | u8 url_len; |
| 1848 | char *url; |
| 1849 | |
| 1850 | ie_end = pos + ie_len; |
| 1851 | pos += 4; |
| 1852 | url_len = *pos++; |
| 1853 | wpa_printf(MSG_DEBUG, |
| 1854 | "WNM: HS 2.0 Terms and Conditions Acceptance (URL Length %u)", |
| 1855 | url_len); |
| 1856 | if (url_len > ie_end - pos) |
| 1857 | break; |
| 1858 | url = os_malloc(url_len + 1); |
| 1859 | if (!url) |
| 1860 | break; |
| 1861 | os_memcpy(url, pos, url_len); |
| 1862 | url[url_len] = '\0'; |
| 1863 | hs20_rx_t_c_acceptance(wpa_s, url); |
| 1864 | os_free(url); |
| 1865 | pos = next; |
| 1866 | continue; |
| 1867 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1868 | #endif /* CONFIG_HS20 */ |
| 1869 | |
| 1870 | pos = next; |
| 1871 | } |
| 1872 | } |
| 1873 | |
| 1874 | |
| 1875 | static void ieee802_11_rx_wnm_notif_req(struct wpa_supplicant *wpa_s, |
| 1876 | const u8 *sa, const u8 *frm, int len) |
| 1877 | { |
| 1878 | const u8 *pos, *end; |
| 1879 | u8 dialog_token, type; |
| 1880 | |
| 1881 | /* Dialog Token [1] | Type [1] | Subelements */ |
| 1882 | |
| 1883 | if (len < 2 || sa == NULL) |
| 1884 | return; |
| 1885 | end = frm + len; |
| 1886 | pos = frm; |
| 1887 | dialog_token = *pos++; |
| 1888 | type = *pos++; |
| 1889 | |
| 1890 | wpa_dbg(wpa_s, MSG_DEBUG, "WNM: Received WNM-Notification Request " |
| 1891 | "(dialog_token %u type %u sa " MACSTR ")", |
| 1892 | dialog_token, type, MAC2STR(sa)); |
| 1893 | wpa_hexdump(MSG_DEBUG, "WNM-Notification Request subelements", |
| 1894 | pos, end - pos); |
| 1895 | |
| 1896 | if (wpa_s->wpa_state != WPA_COMPLETED || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1897 | (!ether_addr_equal(sa, wpa_s->bssid) && |
| 1898 | (!wpa_s->valid_links || |
| 1899 | !ether_addr_equal(sa, wpa_s->ap_mld_addr)))) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1900 | wpa_dbg(wpa_s, MSG_DEBUG, "WNM: WNM-Notification frame not " |
| 1901 | "from our AP - ignore it"); |
| 1902 | return; |
| 1903 | } |
| 1904 | |
| 1905 | switch (type) { |
| 1906 | case 1: |
| 1907 | ieee802_11_rx_wnm_notif_req_wfa(wpa_s, sa, pos, end - pos); |
| 1908 | break; |
| 1909 | default: |
| 1910 | wpa_dbg(wpa_s, MSG_DEBUG, "WNM: Ignore unknown " |
| 1911 | "WNM-Notification type %u", type); |
| 1912 | break; |
| 1913 | } |
| 1914 | } |
| 1915 | |
| 1916 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1917 | static void ieee802_11_rx_wnm_coloc_intf_req(struct wpa_supplicant *wpa_s, |
| 1918 | const u8 *sa, const u8 *frm, |
| 1919 | int len) |
| 1920 | { |
| 1921 | u8 dialog_token, req_info, auto_report, timeout; |
| 1922 | |
| 1923 | if (!wpa_s->conf->coloc_intf_reporting) |
| 1924 | return; |
| 1925 | |
| 1926 | /* Dialog Token [1] | Request Info [1] */ |
| 1927 | |
| 1928 | if (len < 2) |
| 1929 | return; |
| 1930 | dialog_token = frm[0]; |
| 1931 | req_info = frm[1]; |
| 1932 | auto_report = req_info & 0x03; |
| 1933 | timeout = req_info >> 2; |
| 1934 | |
| 1935 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1936 | "WNM: Received Collocated Interference Request (dialog_token %u auto_report %u timeout %u sa " MACSTR ")", |
| 1937 | dialog_token, auto_report, timeout, MAC2STR(sa)); |
| 1938 | |
| 1939 | if (dialog_token == 0) |
| 1940 | return; /* only nonzero values are used for request */ |
| 1941 | |
| 1942 | if (wpa_s->wpa_state != WPA_COMPLETED || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1943 | (!ether_addr_equal(sa, wpa_s->bssid) && |
| 1944 | (!wpa_s->valid_links || |
| 1945 | !ether_addr_equal(sa, wpa_s->ap_mld_addr)))) { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1946 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1947 | "WNM: Collocated Interference Request frame not from current AP - ignore it"); |
| 1948 | return; |
| 1949 | } |
| 1950 | |
| 1951 | wpa_msg(wpa_s, MSG_INFO, COLOC_INTF_REQ "%u %u %u", |
| 1952 | dialog_token, auto_report, timeout); |
| 1953 | wpa_s->coloc_intf_dialog_token = dialog_token; |
| 1954 | wpa_s->coloc_intf_auto_report = auto_report; |
| 1955 | wpa_s->coloc_intf_timeout = timeout; |
| 1956 | } |
| 1957 | |
| 1958 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1959 | void ieee802_11_rx_wnm_action(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1960 | const struct ieee80211_mgmt *mgmt, size_t len) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1961 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1962 | const u8 *pos, *end; |
| 1963 | u8 act; |
| 1964 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1965 | if (len < IEEE80211_HDRLEN + 2) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1966 | return; |
| 1967 | |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 1968 | pos = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1969 | act = *pos++; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1970 | end = ((const u8 *) mgmt) + len; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1971 | |
| 1972 | wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1973 | act, MAC2STR(mgmt->sa)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1974 | if (wpa_s->wpa_state < WPA_ASSOCIATED || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1975 | (!ether_addr_equal(mgmt->sa, wpa_s->bssid) && |
| 1976 | (!wpa_s->valid_links || |
| 1977 | !ether_addr_equal(mgmt->sa, wpa_s->ap_mld_addr)))) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1978 | wpa_printf(MSG_DEBUG, "WNM: Ignore unexpected WNM Action " |
| 1979 | "frame"); |
| 1980 | return; |
| 1981 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1982 | |
| 1983 | switch (act) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1984 | case WNM_BSS_TRANS_MGMT_REQ: |
| 1985 | ieee802_11_rx_bss_trans_mgmt_req(wpa_s, pos, end, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1986 | !(mgmt->da[0] & 0x01)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1987 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1988 | case WNM_SLEEP_MODE_RESP: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1989 | ieee802_11_rx_wnmsleep_resp(wpa_s, pos, end - pos); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1990 | break; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1991 | case WNM_NOTIFICATION_REQ: |
| 1992 | ieee802_11_rx_wnm_notif_req(wpa_s, mgmt->sa, pos, end - pos); |
| 1993 | break; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1994 | case WNM_COLLOCATED_INTERFERENCE_REQ: |
| 1995 | ieee802_11_rx_wnm_coloc_intf_req(wpa_s, mgmt->sa, pos, |
| 1996 | end - pos); |
| 1997 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1998 | default: |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1999 | wpa_printf(MSG_ERROR, "WNM: Unknown request"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2000 | break; |
| 2001 | } |
| 2002 | } |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2003 | |
| 2004 | |
| 2005 | int wnm_send_coloc_intf_report(struct wpa_supplicant *wpa_s, u8 dialog_token, |
| 2006 | const struct wpabuf *elems) |
| 2007 | { |
| 2008 | struct wpabuf *buf; |
| 2009 | int ret; |
| 2010 | |
| 2011 | if (wpa_s->wpa_state < WPA_ASSOCIATED || !elems) |
| 2012 | return -1; |
| 2013 | |
| 2014 | wpa_printf(MSG_DEBUG, "WNM: Send Collocated Interference Report to " |
| 2015 | MACSTR " (dialog token %u)", |
| 2016 | MAC2STR(wpa_s->bssid), dialog_token); |
| 2017 | |
| 2018 | buf = wpabuf_alloc(3 + wpabuf_len(elems)); |
| 2019 | if (!buf) |
| 2020 | return -1; |
| 2021 | |
| 2022 | wpabuf_put_u8(buf, WLAN_ACTION_WNM); |
| 2023 | wpabuf_put_u8(buf, WNM_COLLOCATED_INTERFERENCE_REPORT); |
| 2024 | wpabuf_put_u8(buf, dialog_token); |
| 2025 | wpabuf_put_buf(buf, elems); |
| 2026 | |
| 2027 | ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 2028 | wpa_s->own_addr, wpa_s->bssid, |
| 2029 | wpabuf_head_u8(buf), wpabuf_len(buf), 0); |
| 2030 | wpabuf_free(buf); |
| 2031 | return ret; |
| 2032 | } |
| 2033 | |
| 2034 | |
| 2035 | void wnm_set_coloc_intf_elems(struct wpa_supplicant *wpa_s, |
| 2036 | struct wpabuf *elems) |
| 2037 | { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2038 | if (elems && wpabuf_len(elems) == 0) { |
| 2039 | wpabuf_free(elems); |
| 2040 | elems = NULL; |
| 2041 | } |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2042 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2043 | /* NOTE: The elements are not stored as they are only send out once */ |
| 2044 | |
| 2045 | if (wpa_s->conf->coloc_intf_reporting && elems && |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2046 | wpa_s->coloc_intf_dialog_token && |
| 2047 | (wpa_s->coloc_intf_auto_report == 1 || |
| 2048 | wpa_s->coloc_intf_auto_report == 3)) { |
| 2049 | /* TODO: Check that there has not been less than |
| 2050 | * wpa_s->coloc_intf_timeout * 200 TU from the last report. |
| 2051 | */ |
| 2052 | wnm_send_coloc_intf_report(wpa_s, |
| 2053 | wpa_s->coloc_intf_dialog_token, |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2054 | elems); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2055 | } |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2056 | |
| 2057 | wpabuf_free(elems); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | |
| 2061 | void wnm_clear_coloc_intf_reporting(struct wpa_supplicant *wpa_s) |
| 2062 | { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2063 | wpa_s->coloc_intf_dialog_token = 0; |
| 2064 | wpa_s->coloc_intf_auto_report = 0; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | |
| 2068 | bool wnm_is_bss_excluded(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
| 2069 | { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2070 | if (!(wpa_s->wnm_mode & WNM_BSS_TM_REQ_DISASSOC_IMMINENT)) |
| 2071 | return false; |
| 2072 | |
| 2073 | /* |
| 2074 | * In case disassociation imminent is set, do no try to use a BSS to |
| 2075 | * which we are connected. |
| 2076 | */ |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2077 | if (wpa_s->wnm_link_removal || |
| 2078 | !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO) || |
| 2079 | is_zero_ether_addr(bss->mld_addr)) { |
| 2080 | if (ether_addr_equal(bss->bssid, wpa_s->wnm_dissoc_addr)) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2081 | return true; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2082 | } else { |
| 2083 | if (ether_addr_equal(bss->mld_addr, wpa_s->wnm_dissoc_addr)) |
| 2084 | return true; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | return false; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2088 | } |