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 | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 421 | void wnm_deallocate_memory(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 | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 434 | wpabuf_free(wpa_s->coloc_intf_elems); |
| 435 | wpa_s->coloc_intf_elems = NULL; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | |
| 439 | static void wnm_parse_neighbor_report_elem(struct neighbor_report *rep, |
| 440 | u8 id, u8 elen, const u8 *pos) |
| 441 | { |
| 442 | switch (id) { |
| 443 | case WNM_NEIGHBOR_TSF: |
| 444 | if (elen < 2 + 2) { |
| 445 | wpa_printf(MSG_DEBUG, "WNM: Too short TSF"); |
| 446 | break; |
| 447 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 448 | rep->tsf_offset = WPA_GET_LE16(pos); |
| 449 | rep->beacon_int = WPA_GET_LE16(pos + 2); |
| 450 | rep->tsf_present = 1; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 451 | break; |
| 452 | case WNM_NEIGHBOR_CONDENSED_COUNTRY_STRING: |
| 453 | if (elen < 2) { |
| 454 | wpa_printf(MSG_DEBUG, "WNM: Too short condensed " |
| 455 | "country string"); |
| 456 | break; |
| 457 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 458 | os_memcpy(rep->country, pos, 2); |
| 459 | rep->country_present = 1; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 460 | break; |
| 461 | case WNM_NEIGHBOR_BSS_TRANSITION_CANDIDATE: |
| 462 | if (elen < 1) { |
| 463 | wpa_printf(MSG_DEBUG, "WNM: Too short BSS transition " |
| 464 | "candidate"); |
| 465 | break; |
| 466 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 467 | rep->preference = pos[0]; |
| 468 | rep->preference_present = 1; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 469 | break; |
| 470 | case WNM_NEIGHBOR_BSS_TERMINATION_DURATION: |
Hai Shalom | cb95c3f | 2019-02-04 12:53:10 -0800 | [diff] [blame] | 471 | if (elen < 10) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 472 | wpa_printf(MSG_DEBUG, |
| 473 | "WNM: Too short BSS termination duration"); |
Hai Shalom | cb95c3f | 2019-02-04 12:53:10 -0800 | [diff] [blame] | 474 | break; |
| 475 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 476 | rep->bss_term_tsf = WPA_GET_LE64(pos); |
| 477 | rep->bss_term_dur = WPA_GET_LE16(pos + 8); |
| 478 | rep->bss_term_present = 1; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 479 | break; |
| 480 | case WNM_NEIGHBOR_BEARING: |
| 481 | if (elen < 8) { |
| 482 | wpa_printf(MSG_DEBUG, "WNM: Too short neighbor " |
| 483 | "bearing"); |
| 484 | break; |
| 485 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 486 | rep->bearing = WPA_GET_LE16(pos); |
| 487 | rep->distance = WPA_GET_LE32(pos + 2); |
| 488 | rep->rel_height = WPA_GET_LE16(pos + 2 + 4); |
| 489 | rep->bearing_present = 1; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 490 | break; |
| 491 | case WNM_NEIGHBOR_MEASUREMENT_PILOT: |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 492 | if (elen < 1) { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 493 | wpa_printf(MSG_DEBUG, "WNM: Too short measurement " |
| 494 | "pilot"); |
| 495 | break; |
| 496 | } |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 497 | os_free(rep->meas_pilot); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 498 | rep->meas_pilot = os_zalloc(sizeof(struct measurement_pilot)); |
| 499 | if (rep->meas_pilot == NULL) |
| 500 | break; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 501 | rep->meas_pilot->measurement_pilot = pos[0]; |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 502 | rep->meas_pilot->subelem_len = elen - 1; |
| 503 | os_memcpy(rep->meas_pilot->subelems, pos + 1, elen - 1); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 504 | break; |
| 505 | case WNM_NEIGHBOR_RRM_ENABLED_CAPABILITIES: |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 506 | if (elen < 5) { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 507 | wpa_printf(MSG_DEBUG, "WNM: Too short RRM enabled " |
| 508 | "capabilities"); |
| 509 | break; |
| 510 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 511 | os_memcpy(rep->rm_capab, pos, 5); |
| 512 | rep->rm_capab_present = 1; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 513 | break; |
| 514 | case WNM_NEIGHBOR_MULTIPLE_BSSID: |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 515 | if (elen < 1) { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 516 | wpa_printf(MSG_DEBUG, "WNM: Too short multiple BSSID"); |
| 517 | break; |
| 518 | } |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 519 | os_free(rep->mul_bssid); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 520 | rep->mul_bssid = os_zalloc(sizeof(struct multiple_bssid)); |
| 521 | if (rep->mul_bssid == NULL) |
| 522 | break; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 523 | rep->mul_bssid->max_bssid_indicator = pos[0]; |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 524 | rep->mul_bssid->subelem_len = elen - 1; |
| 525 | os_memcpy(rep->mul_bssid->subelems, pos + 1, elen - 1); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 526 | break; |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 527 | default: |
| 528 | wpa_printf(MSG_DEBUG, |
| 529 | "WNM: Unsupported neighbor report subelement id %u", |
| 530 | id); |
| 531 | break; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | |
| 535 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 536 | static int wnm_nei_get_chan(struct wpa_supplicant *wpa_s, u8 op_class, u8 chan) |
| 537 | { |
| 538 | struct wpa_bss *bss = wpa_s->current_bss; |
| 539 | const char *country = NULL; |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 540 | int freq; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 541 | |
| 542 | if (bss) { |
| 543 | const u8 *elem = wpa_bss_get_ie(bss, WLAN_EID_COUNTRY); |
| 544 | |
| 545 | if (elem && elem[1] >= 2) |
| 546 | country = (const char *) (elem + 2); |
| 547 | } |
| 548 | |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 549 | freq = ieee80211_chan_to_freq(country, op_class, chan); |
| 550 | if (freq <= 0 && op_class == 0) { |
| 551 | /* |
| 552 | * Some APs do not advertise correct operating class |
| 553 | * information. Try to determine the most likely operating |
| 554 | * frequency based on the channel number. |
| 555 | */ |
| 556 | if (chan >= 1 && chan <= 13) |
| 557 | freq = 2407 + chan * 5; |
| 558 | else if (chan == 14) |
| 559 | freq = 2484; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 560 | else if (chan >= 36 && chan <= 177) |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 561 | freq = 5000 + chan * 5; |
| 562 | } |
| 563 | return freq; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 567 | static void wnm_parse_neighbor_report(struct wpa_supplicant *wpa_s, |
| 568 | const u8 *pos, u8 len, |
| 569 | struct neighbor_report *rep) |
| 570 | { |
| 571 | u8 left = len; |
| 572 | |
| 573 | if (left < 13) { |
| 574 | wpa_printf(MSG_DEBUG, "WNM: Too short neighbor report"); |
| 575 | return; |
| 576 | } |
| 577 | |
| 578 | os_memcpy(rep->bssid, pos, ETH_ALEN); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 579 | rep->bssid_info = WPA_GET_LE32(pos + ETH_ALEN); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 580 | rep->regulatory_class = *(pos + 10); |
| 581 | rep->channel_number = *(pos + 11); |
| 582 | rep->phy_type = *(pos + 12); |
| 583 | |
| 584 | pos += 13; |
| 585 | left -= 13; |
| 586 | |
| 587 | while (left >= 2) { |
| 588 | u8 id, elen; |
| 589 | |
| 590 | id = *pos++; |
| 591 | elen = *pos++; |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 592 | wpa_printf(MSG_DEBUG, "WNM: Subelement id=%u len=%u", id, elen); |
| 593 | left -= 2; |
| 594 | if (elen > left) { |
| 595 | wpa_printf(MSG_DEBUG, |
| 596 | "WNM: Truncated neighbor report subelement"); |
| 597 | break; |
| 598 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 599 | wnm_parse_neighbor_report_elem(rep, id, elen, pos); |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 600 | left -= elen; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 601 | pos += elen; |
| 602 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 603 | |
| 604 | rep->freq = wnm_nei_get_chan(wpa_s, rep->regulatory_class, |
| 605 | rep->channel_number); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 609 | static void wnm_clear_acceptable(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 610 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 611 | unsigned int i; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 612 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 613 | for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) |
| 614 | wpa_s->wnm_neighbor_report_elements[i].acceptable = 0; |
| 615 | } |
| 616 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 617 | #ifdef CONFIG_MBO |
| 618 | static struct wpa_bss * |
| 619 | get_mbo_transition_candidate(struct wpa_supplicant *wpa_s, |
| 620 | enum mbo_transition_reject_reason *reason) |
| 621 | { |
| 622 | struct wpa_bss *target = NULL; |
| 623 | struct wpa_bss_trans_info params; |
| 624 | struct wpa_bss_candidate_info *info = NULL; |
| 625 | struct neighbor_report *nei = wpa_s->wnm_neighbor_report_elements; |
| 626 | u8 *first_candidate_bssid = NULL, *pos; |
| 627 | unsigned int i; |
| 628 | |
| 629 | params.mbo_transition_reason = wpa_s->wnm_mbo_transition_reason; |
| 630 | params.n_candidates = 0; |
| 631 | params.bssid = os_calloc(wpa_s->wnm_num_neighbor_report, ETH_ALEN); |
| 632 | if (!params.bssid) |
| 633 | return NULL; |
| 634 | |
| 635 | pos = params.bssid; |
| 636 | for (i = 0; i < wpa_s->wnm_num_neighbor_report; nei++, i++) { |
| 637 | if (nei->is_first) |
| 638 | first_candidate_bssid = nei->bssid; |
| 639 | if (!nei->acceptable) |
| 640 | continue; |
| 641 | os_memcpy(pos, nei->bssid, ETH_ALEN); |
| 642 | pos += ETH_ALEN; |
| 643 | params.n_candidates++; |
| 644 | } |
| 645 | |
| 646 | if (!params.n_candidates) |
| 647 | goto end; |
| 648 | |
| 649 | info = wpa_drv_get_bss_trans_status(wpa_s, ¶ms); |
| 650 | if (!info) { |
| 651 | /* If failed to get candidate BSS transition status from driver, |
| 652 | * get the first acceptable candidate from wpa_supplicant. |
| 653 | */ |
| 654 | target = wpa_bss_get_bssid(wpa_s, params.bssid); |
| 655 | goto end; |
| 656 | } |
| 657 | |
| 658 | /* Get the first acceptable candidate from driver */ |
| 659 | for (i = 0; i < info->num; i++) { |
| 660 | if (info->candidates[i].is_accept) { |
| 661 | target = wpa_bss_get_bssid(wpa_s, |
| 662 | info->candidates[i].bssid); |
| 663 | goto end; |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | /* If Disassociation Imminent is set and driver rejects all the |
| 668 | * candidate select first acceptable candidate which has |
| 669 | * rssi > disassoc_imminent_rssi_threshold |
| 670 | */ |
| 671 | if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_DISASSOC_IMMINENT) { |
| 672 | for (i = 0; i < info->num; i++) { |
| 673 | target = wpa_bss_get_bssid(wpa_s, |
| 674 | info->candidates[i].bssid); |
| 675 | if (target && |
| 676 | (target->level < |
| 677 | wpa_s->conf->disassoc_imminent_rssi_threshold)) |
| 678 | continue; |
| 679 | goto end; |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | /* While sending BTM reject use reason code of the first candidate |
| 684 | * received in BTM request frame |
| 685 | */ |
| 686 | if (reason) { |
| 687 | for (i = 0; i < info->num; i++) { |
| 688 | if (first_candidate_bssid && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 689 | ether_addr_equal(first_candidate_bssid, |
| 690 | info->candidates[i].bssid)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 691 | *reason = info->candidates[i].reject_reason; |
| 692 | break; |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | target = NULL; |
| 698 | |
| 699 | end: |
| 700 | os_free(params.bssid); |
| 701 | if (info) { |
| 702 | os_free(info->candidates); |
| 703 | os_free(info); |
| 704 | } |
| 705 | return target; |
| 706 | } |
| 707 | #endif /* CONFIG_MBO */ |
| 708 | |
| 709 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 710 | static struct wpa_bss * find_better_target(struct wpa_bss *a, |
| 711 | struct wpa_bss *b) |
| 712 | { |
| 713 | if (!a) |
| 714 | return b; |
| 715 | if (!b) |
| 716 | return a; |
| 717 | |
| 718 | if (a->est_throughput > b->est_throughput) { |
| 719 | wpa_printf(MSG_DEBUG, "WNM: A is better: " MACSTR |
| 720 | " est-tput: %d B: " MACSTR " est-tput: %d", |
| 721 | MAC2STR(a->bssid), a->est_throughput, |
| 722 | MAC2STR(b->bssid), b->est_throughput); |
| 723 | return a; |
| 724 | } |
| 725 | |
| 726 | wpa_printf(MSG_DEBUG, "WNM: B is better, A: " MACSTR |
| 727 | " est-tput: %d B: " MACSTR " est-tput: %d", |
| 728 | MAC2STR(a->bssid), a->est_throughput, |
| 729 | MAC2STR(b->bssid), b->est_throughput); |
| 730 | return b; |
| 731 | } |
| 732 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 733 | static struct wpa_bss * |
| 734 | compare_scan_neighbor_results(struct wpa_supplicant *wpa_s, os_time_t age_secs, |
| 735 | enum mbo_transition_reject_reason *reason) |
| 736 | { |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 737 | u8 i; |
| 738 | struct wpa_bss *bss = wpa_s->current_bss; |
| 739 | struct wpa_bss *target; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 740 | struct wpa_bss *best_target = NULL; |
| 741 | struct wpa_bss *bss_in_list = NULL; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 742 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 743 | if (!bss) |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 744 | return NULL; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 745 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 746 | wpa_printf(MSG_DEBUG, "WNM: Current BSS " MACSTR " RSSI %d", |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 747 | MAC2STR(wpa_s->bssid), bss->level); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 748 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 749 | wnm_clear_acceptable(wpa_s); |
| 750 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 751 | for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) { |
| 752 | struct neighbor_report *nei; |
| 753 | |
| 754 | nei = &wpa_s->wnm_neighbor_report_elements[i]; |
| 755 | if (nei->preference_present && nei->preference == 0) { |
| 756 | wpa_printf(MSG_DEBUG, "Skip excluded BSS " MACSTR, |
| 757 | MAC2STR(nei->bssid)); |
| 758 | continue; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 759 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 760 | |
| 761 | target = wpa_bss_get_bssid(wpa_s, nei->bssid); |
| 762 | if (!target) { |
| 763 | wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR |
| 764 | " (pref %d) not found in scan results", |
| 765 | MAC2STR(nei->bssid), |
| 766 | nei->preference_present ? nei->preference : |
| 767 | -1); |
| 768 | continue; |
| 769 | } |
| 770 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 771 | if (age_secs) { |
| 772 | struct os_reltime now; |
| 773 | |
| 774 | if (os_get_reltime(&now) == 0 && |
| 775 | os_reltime_expired(&now, &target->last_update, |
| 776 | age_secs)) { |
| 777 | wpa_printf(MSG_DEBUG, |
| 778 | "Candidate BSS is more than %ld seconds old", |
| 779 | age_secs); |
| 780 | continue; |
| 781 | } |
| 782 | } |
| 783 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 784 | if (bss->ssid_len != target->ssid_len || |
| 785 | os_memcmp(bss->ssid, target->ssid, bss->ssid_len) != 0) { |
| 786 | /* |
| 787 | * TODO: Could consider allowing transition to another |
| 788 | * ESS if PMF was enabled for the association. |
| 789 | */ |
| 790 | wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR |
| 791 | " (pref %d) in different ESS", |
| 792 | MAC2STR(nei->bssid), |
| 793 | nei->preference_present ? nei->preference : |
| 794 | -1); |
| 795 | continue; |
| 796 | } |
| 797 | |
| 798 | if (wpa_s->current_ssid && |
| 799 | !wpa_scan_res_match(wpa_s, 0, target, wpa_s->current_ssid, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 800 | 1, 0)) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 801 | wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR |
| 802 | " (pref %d) does not match the current network profile", |
| 803 | MAC2STR(nei->bssid), |
| 804 | nei->preference_present ? nei->preference : |
| 805 | -1); |
| 806 | continue; |
| 807 | } |
| 808 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 809 | if (wpa_is_bss_tmp_disallowed(wpa_s, target)) { |
| 810 | wpa_printf(MSG_DEBUG, |
| 811 | "MBO: Candidate BSS " MACSTR |
| 812 | " retry delay is not over yet", |
| 813 | MAC2STR(nei->bssid)); |
| 814 | continue; |
| 815 | } |
| 816 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 817 | if (target->level < bss->level && target->level < -80) { |
| 818 | wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR |
| 819 | " (pref %d) does not have sufficient signal level (%d)", |
| 820 | MAC2STR(nei->bssid), |
| 821 | nei->preference_present ? nei->preference : |
| 822 | -1, |
| 823 | target->level); |
| 824 | continue; |
| 825 | } |
| 826 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 827 | nei->acceptable = 1; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 828 | |
| 829 | best_target = find_better_target(target, best_target); |
| 830 | if (target == bss) |
| 831 | bss_in_list = bss; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | #ifdef CONFIG_MBO |
| 835 | if (wpa_s->wnm_mbo_trans_reason_present) |
| 836 | target = get_mbo_transition_candidate(wpa_s, reason); |
| 837 | else |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 838 | target = best_target; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 839 | #else /* CONFIG_MBO */ |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 840 | target = best_target; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 841 | #endif /* CONFIG_MBO */ |
| 842 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 843 | if (!target) |
| 844 | return NULL; |
| 845 | |
| 846 | wpa_printf(MSG_DEBUG, |
| 847 | "WNM: Found an acceptable preferred transition candidate BSS " |
| 848 | MACSTR " (RSSI %d, tput: %d bss-tput: %d)", |
| 849 | MAC2STR(target->bssid), target->level, |
| 850 | target->est_throughput, bss->est_throughput); |
| 851 | |
| 852 | if (!bss_in_list) |
| 853 | return target; |
| 854 | |
| 855 | if ((!target->est_throughput && !bss_in_list->est_throughput) || |
| 856 | (target->est_throughput > bss_in_list->est_throughput && |
| 857 | target->est_throughput - bss_in_list->est_throughput > |
| 858 | bss_in_list->est_throughput >> 4)) { |
| 859 | /* It is more than 100/16 percent better, so switch. */ |
| 860 | return target; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 863 | wpa_printf(MSG_DEBUG, |
| 864 | "WNM: Stay with our current BSS, not enough change in estimated throughput to switch"); |
| 865 | return bss_in_list; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 869 | static int wpa_bss_ies_eq(struct wpa_bss *a, struct wpa_bss *b, u8 eid) |
| 870 | { |
| 871 | const u8 *ie_a, *ie_b; |
| 872 | |
| 873 | if (!a || !b) |
| 874 | return 0; |
| 875 | |
| 876 | ie_a = wpa_bss_get_ie(a, eid); |
| 877 | ie_b = wpa_bss_get_ie(b, eid); |
| 878 | |
| 879 | if (!ie_a || !ie_b || ie_a[1] != ie_b[1]) |
| 880 | return 0; |
| 881 | |
| 882 | return os_memcmp(ie_a, ie_b, ie_a[1]) == 0; |
| 883 | } |
| 884 | |
| 885 | |
| 886 | static u32 wnm_get_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
| 887 | { |
| 888 | u32 info = 0; |
| 889 | |
| 890 | info |= NEI_REP_BSSID_INFO_AP_UNKNOWN_REACH; |
| 891 | |
| 892 | /* |
| 893 | * Leave the security and key scope bits unset to indicate that the |
| 894 | * security information is not available. |
| 895 | */ |
| 896 | |
| 897 | if (bss->caps & WLAN_CAPABILITY_SPECTRUM_MGMT) |
| 898 | info |= NEI_REP_BSSID_INFO_SPECTRUM_MGMT; |
| 899 | if (bss->caps & WLAN_CAPABILITY_QOS) |
| 900 | info |= NEI_REP_BSSID_INFO_QOS; |
| 901 | if (bss->caps & WLAN_CAPABILITY_APSD) |
| 902 | info |= NEI_REP_BSSID_INFO_APSD; |
| 903 | if (bss->caps & WLAN_CAPABILITY_RADIO_MEASUREMENT) |
| 904 | info |= NEI_REP_BSSID_INFO_RM; |
| 905 | if (bss->caps & WLAN_CAPABILITY_DELAYED_BLOCK_ACK) |
| 906 | info |= NEI_REP_BSSID_INFO_DELAYED_BA; |
| 907 | if (bss->caps & WLAN_CAPABILITY_IMM_BLOCK_ACK) |
| 908 | info |= NEI_REP_BSSID_INFO_IMM_BA; |
| 909 | if (wpa_bss_ies_eq(bss, wpa_s->current_bss, WLAN_EID_MOBILITY_DOMAIN)) |
| 910 | info |= NEI_REP_BSSID_INFO_MOBILITY_DOMAIN; |
| 911 | if (wpa_bss_ies_eq(bss, wpa_s->current_bss, WLAN_EID_HT_CAP)) |
| 912 | info |= NEI_REP_BSSID_INFO_HT; |
| 913 | |
| 914 | return info; |
| 915 | } |
| 916 | |
| 917 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 918 | static int wnm_add_nei_rep(struct wpabuf **buf, const u8 *bssid, |
| 919 | u32 bss_info, u8 op_class, u8 chan, u8 phy_type, |
| 920 | u8 pref) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 921 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 922 | if (wpabuf_len(*buf) + 18 > |
| 923 | IEEE80211_MAX_MMPDU_SIZE - IEEE80211_HDRLEN) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 924 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 925 | "WNM: No room in frame for Neighbor Report element"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 926 | return -1; |
| 927 | } |
| 928 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 929 | if (wpabuf_resize(buf, 18) < 0) { |
| 930 | wpa_printf(MSG_DEBUG, |
| 931 | "WNM: Failed to allocate memory for Neighbor Report element"); |
| 932 | return -1; |
| 933 | } |
| 934 | |
| 935 | wpabuf_put_u8(*buf, WLAN_EID_NEIGHBOR_REPORT); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 936 | /* length: 13 for basic neighbor report + 3 for preference subelement */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 937 | wpabuf_put_u8(*buf, 16); |
| 938 | wpabuf_put_data(*buf, bssid, ETH_ALEN); |
| 939 | wpabuf_put_le32(*buf, bss_info); |
| 940 | wpabuf_put_u8(*buf, op_class); |
| 941 | wpabuf_put_u8(*buf, chan); |
| 942 | wpabuf_put_u8(*buf, phy_type); |
| 943 | wpabuf_put_u8(*buf, WNM_NEIGHBOR_BSS_TRANSITION_CANDIDATE); |
| 944 | wpabuf_put_u8(*buf, 1); |
| 945 | wpabuf_put_u8(*buf, pref); |
| 946 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | |
| 950 | static int wnm_nei_rep_add_bss(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 951 | struct wpa_bss *bss, struct wpabuf **buf, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 952 | u8 pref) |
| 953 | { |
| 954 | const u8 *ie; |
| 955 | u8 op_class, chan; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 956 | int sec_chan = 0; |
| 957 | enum oper_chan_width vht = CONF_OPER_CHWIDTH_USE_HT; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 958 | enum phy_type phy_type; |
| 959 | u32 info; |
| 960 | struct ieee80211_ht_operation *ht_oper = NULL; |
| 961 | struct ieee80211_vht_operation *vht_oper = NULL; |
| 962 | |
| 963 | ie = wpa_bss_get_ie(bss, WLAN_EID_HT_OPERATION); |
| 964 | if (ie && ie[1] >= 2) { |
| 965 | ht_oper = (struct ieee80211_ht_operation *) (ie + 2); |
| 966 | |
| 967 | if (ht_oper->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE) |
| 968 | sec_chan = 1; |
| 969 | else if (ht_oper->ht_param & |
| 970 | HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW) |
| 971 | sec_chan = -1; |
| 972 | } |
| 973 | |
| 974 | ie = wpa_bss_get_ie(bss, WLAN_EID_VHT_OPERATION); |
| 975 | if (ie && ie[1] >= 1) { |
| 976 | vht_oper = (struct ieee80211_vht_operation *) (ie + 2); |
| 977 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 978 | if (vht_oper->vht_op_info_chwidth == CHANWIDTH_80MHZ || |
| 979 | vht_oper->vht_op_info_chwidth == CHANWIDTH_160MHZ || |
| 980 | vht_oper->vht_op_info_chwidth == CHANWIDTH_80P80MHZ) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 981 | vht = vht_oper->vht_op_info_chwidth; |
| 982 | } |
| 983 | |
| 984 | if (ieee80211_freq_to_channel_ext(bss->freq, sec_chan, vht, &op_class, |
| 985 | &chan) == NUM_HOSTAPD_MODES) { |
| 986 | wpa_printf(MSG_DEBUG, |
| 987 | "WNM: Cannot determine operating class and channel"); |
| 988 | return -2; |
| 989 | } |
| 990 | |
| 991 | phy_type = ieee80211_get_phy_type(bss->freq, (ht_oper != NULL), |
| 992 | (vht_oper != NULL)); |
| 993 | if (phy_type == PHY_TYPE_UNSPECIFIED) { |
| 994 | wpa_printf(MSG_DEBUG, |
| 995 | "WNM: Cannot determine BSS phy type for Neighbor Report"); |
| 996 | return -2; |
| 997 | } |
| 998 | |
| 999 | info = wnm_get_bss_info(wpa_s, bss); |
| 1000 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1001 | return wnm_add_nei_rep(buf, bss->bssid, info, op_class, chan, phy_type, |
| 1002 | pref); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1006 | 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] | 1007 | { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1008 | unsigned int i, pref = 255; |
| 1009 | struct os_reltime now; |
| 1010 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 1011 | |
| 1012 | if (!ssid) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1013 | return; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1014 | |
| 1015 | /* |
| 1016 | * TODO: Define when scan results are no longer valid for the candidate |
| 1017 | * list. |
| 1018 | */ |
| 1019 | os_get_reltime(&now); |
| 1020 | if (os_reltime_expired(&now, &wpa_s->last_scan, 10)) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1021 | return; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1022 | |
| 1023 | wpa_printf(MSG_DEBUG, |
| 1024 | "WNM: Add candidate list to BSS Transition Management Response frame"); |
| 1025 | for (i = 0; i < wpa_s->last_scan_res_used && pref; i++) { |
| 1026 | struct wpa_bss *bss = wpa_s->last_scan_res[i]; |
| 1027 | int res; |
| 1028 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1029 | if (wpa_scan_res_match(wpa_s, i, bss, ssid, 1, 0)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1030 | res = wnm_nei_rep_add_bss(wpa_s, bss, buf, pref--); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1031 | if (res == -2) |
| 1032 | continue; /* could not build entry for BSS */ |
| 1033 | if (res < 0) |
| 1034 | break; /* no more room for candidates */ |
| 1035 | if (pref == 1) |
| 1036 | break; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1037 | } |
| 1038 | } |
| 1039 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1040 | wpa_hexdump_buf(MSG_DEBUG, |
| 1041 | "WNM: BSS Transition Management Response candidate list", |
| 1042 | *buf); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1046 | #define BTM_RESP_MIN_SIZE 5 + ETH_ALEN |
| 1047 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1048 | static void wnm_send_bss_transition_mgmt_resp( |
| 1049 | struct wpa_supplicant *wpa_s, u8 dialog_token, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1050 | enum bss_trans_mgmt_status_code status, |
| 1051 | enum mbo_transition_reject_reason reason, |
| 1052 | u8 delay, const u8 *target_bssid) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1053 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1054 | struct wpabuf *buf; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1055 | int res; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1056 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1057 | wpa_printf(MSG_DEBUG, |
| 1058 | "WNM: Send BSS Transition Management Response to " MACSTR |
| 1059 | " dialog_token=%u status=%u reason=%u delay=%d", |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1060 | MAC2STR(wpa_s->bssid), dialog_token, status, reason, delay); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1061 | if (!wpa_s->current_bss) { |
| 1062 | wpa_printf(MSG_DEBUG, |
| 1063 | "WNM: Current BSS not known - drop response"); |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1064 | return; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1065 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1066 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1067 | buf = wpabuf_alloc(BTM_RESP_MIN_SIZE); |
| 1068 | if (!buf) { |
| 1069 | wpa_printf(MSG_DEBUG, |
| 1070 | "WNM: Failed to allocate memory for BTM response"); |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1071 | return; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1074 | wpa_s->bss_tm_status = status; |
| 1075 | wpas_notify_bss_tm_status(wpa_s); |
| 1076 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1077 | wpabuf_put_u8(buf, WLAN_ACTION_WNM); |
| 1078 | wpabuf_put_u8(buf, WNM_BSS_TRANS_MGMT_RESP); |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1079 | wpabuf_put_u8(buf, dialog_token); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1080 | wpabuf_put_u8(buf, status); |
| 1081 | wpabuf_put_u8(buf, delay); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1082 | if (target_bssid) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1083 | wpabuf_put_data(buf, target_bssid, ETH_ALEN); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1084 | } else if (status == WNM_BSS_TM_ACCEPT) { |
| 1085 | /* |
| 1086 | * P802.11-REVmc clarifies that the Target BSSID field is always |
| 1087 | * present when status code is zero, so use a fake value here if |
| 1088 | * no BSSID is yet known. |
| 1089 | */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1090 | wpabuf_put_data(buf, "\0\0\0\0\0\0", ETH_ALEN); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1091 | } |
| 1092 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1093 | if (status == WNM_BSS_TM_ACCEPT && !wpa_s->wnm_link_removal) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1094 | wnm_add_cand_list(wpa_s, &buf); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1095 | |
| 1096 | #ifdef CONFIG_MBO |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1097 | if (status != WNM_BSS_TM_ACCEPT && |
| 1098 | wpa_bss_get_vendor_ie(wpa_s->current_bss, MBO_IE_VENDOR_TYPE)) { |
| 1099 | u8 mbo[10]; |
| 1100 | size_t ret; |
| 1101 | |
| 1102 | ret = wpas_mbo_ie_bss_trans_reject(wpa_s, mbo, sizeof(mbo), |
| 1103 | reason); |
| 1104 | if (ret) { |
| 1105 | if (wpabuf_resize(&buf, ret) < 0) { |
| 1106 | wpabuf_free(buf); |
| 1107 | wpa_printf(MSG_DEBUG, |
| 1108 | "WNM: Failed to allocate memory for MBO IE"); |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1109 | return; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | wpabuf_put_data(buf, mbo, ret); |
| 1113 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1114 | } |
| 1115 | #endif /* CONFIG_MBO */ |
| 1116 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1117 | res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 1118 | wpa_s->own_addr, wpa_s->bssid, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1119 | wpabuf_head_u8(buf), wpabuf_len(buf), 0); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1120 | if (res < 0) { |
| 1121 | wpa_printf(MSG_DEBUG, |
| 1122 | "WNM: Failed to send BSS Transition Management Response"); |
| 1123 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1124 | |
| 1125 | wpabuf_free(buf); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1129 | static void wnm_bss_tm_connect(struct wpa_supplicant *wpa_s, |
| 1130 | struct wpa_bss *bss, struct wpa_ssid *ssid, |
| 1131 | int after_new_scan) |
| 1132 | { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1133 | struct wpa_radio_work *already_connecting; |
| 1134 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1135 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1136 | "WNM: Transition to BSS " MACSTR |
| 1137 | " based on BSS Transition Management Request (old BSSID " |
| 1138 | MACSTR " after_new_scan=%d)", |
| 1139 | MAC2STR(bss->bssid), MAC2STR(wpa_s->bssid), after_new_scan); |
| 1140 | |
| 1141 | /* Send the BSS Management Response - Accept */ |
| 1142 | if (wpa_s->wnm_reply) { |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1143 | wpa_s->wnm_reply = 0; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1144 | wpa_printf(MSG_DEBUG, |
| 1145 | "WNM: Sending successful BSS Transition Management Response"); |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1146 | wnm_send_bss_transition_mgmt_resp( |
| 1147 | wpa_s, wpa_s->wnm_dialog_token, WNM_BSS_TM_ACCEPT, |
| 1148 | MBO_TRANSITION_REJECT_REASON_UNSPECIFIED, 0, |
| 1149 | bss->bssid); |
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 | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1155 | wnm_deallocate_memory(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; |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1171 | wnm_deallocate_memory(wpa_s); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1175 | int wnm_scan_process(struct wpa_supplicant *wpa_s, int reply_on_fail) |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1176 | { |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1177 | struct wpa_bss *bss; |
| 1178 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 1179 | enum bss_trans_mgmt_status_code status = WNM_BSS_TM_REJECT_UNSPECIFIED; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1180 | enum mbo_transition_reject_reason reason = |
| 1181 | MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1182 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1183 | if (!wpa_s->wnm_neighbor_report_elements) |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1184 | return 0; |
| 1185 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1186 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1187 | "WNM: Process scan results for BSS Transition Management"); |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1188 | if (os_reltime_before(&wpa_s->wnm_cand_valid_until, |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1189 | &wpa_s->scan_trigger_time)) { |
| 1190 | wpa_printf(MSG_DEBUG, "WNM: Previously stored BSS transition candidate list is not valid anymore - drop it"); |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1191 | wnm_deallocate_memory(wpa_s); |
| 1192 | return 0; |
| 1193 | } |
| 1194 | |
| 1195 | if (!wpa_s->current_bss || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1196 | !ether_addr_equal(wpa_s->wnm_cand_from_bss, |
| 1197 | wpa_s->current_bss->bssid)) { |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1198 | wpa_printf(MSG_DEBUG, "WNM: Stored BSS transition candidate list not from the current BSS - ignore it"); |
| 1199 | return 0; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | /* Compare the Neighbor Report and scan results */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1203 | bss = compare_scan_neighbor_results(wpa_s, 0, &reason); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1204 | if (!bss) { |
| 1205 | wpa_printf(MSG_DEBUG, "WNM: No BSS transition candidate match found"); |
| 1206 | status = WNM_BSS_TM_REJECT_NO_SUITABLE_CANDIDATES; |
| 1207 | goto send_bss_resp_fail; |
| 1208 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1209 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1210 | /* Associate to the network */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1211 | wnm_bss_tm_connect(wpa_s, bss, ssid, 1); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1212 | return 1; |
| 1213 | |
| 1214 | send_bss_resp_fail: |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1215 | if (!reply_on_fail) |
| 1216 | return 0; |
| 1217 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1218 | /* Send reject response for all the failures */ |
| 1219 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1220 | if (wpa_s->wnm_reply) { |
| 1221 | wpa_s->wnm_reply = 0; |
| 1222 | wnm_send_bss_transition_mgmt_resp(wpa_s, |
| 1223 | wpa_s->wnm_dialog_token, |
| 1224 | status, reason, 0, NULL); |
| 1225 | } |
| 1226 | wnm_deallocate_memory(wpa_s); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1227 | |
| 1228 | return 0; |
| 1229 | } |
| 1230 | |
| 1231 | |
| 1232 | static int cand_pref_compar(const void *a, const void *b) |
| 1233 | { |
| 1234 | const struct neighbor_report *aa = a; |
| 1235 | const struct neighbor_report *bb = b; |
| 1236 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1237 | if (aa->disassoc_imminent && !bb->disassoc_imminent) |
| 1238 | return 1; |
| 1239 | if (bb->disassoc_imminent && !aa->disassoc_imminent) |
| 1240 | return -1; |
| 1241 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1242 | if (!aa->preference_present && !bb->preference_present) |
| 1243 | return 0; |
| 1244 | if (!aa->preference_present) |
| 1245 | return 1; |
| 1246 | if (!bb->preference_present) |
| 1247 | return -1; |
| 1248 | if (bb->preference > aa->preference) |
| 1249 | return 1; |
| 1250 | if (bb->preference < aa->preference) |
| 1251 | return -1; |
| 1252 | return 0; |
| 1253 | } |
| 1254 | |
| 1255 | |
| 1256 | static void wnm_sort_cand_list(struct wpa_supplicant *wpa_s) |
| 1257 | { |
| 1258 | if (!wpa_s->wnm_neighbor_report_elements) |
| 1259 | return; |
| 1260 | qsort(wpa_s->wnm_neighbor_report_elements, |
| 1261 | wpa_s->wnm_num_neighbor_report, sizeof(struct neighbor_report), |
| 1262 | cand_pref_compar); |
| 1263 | } |
| 1264 | |
| 1265 | |
| 1266 | static void wnm_dump_cand_list(struct wpa_supplicant *wpa_s) |
| 1267 | { |
| 1268 | unsigned int i; |
| 1269 | |
| 1270 | wpa_printf(MSG_DEBUG, "WNM: BSS Transition Candidate List"); |
| 1271 | if (!wpa_s->wnm_neighbor_report_elements) |
| 1272 | return; |
| 1273 | for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) { |
| 1274 | struct neighbor_report *nei; |
| 1275 | |
| 1276 | nei = &wpa_s->wnm_neighbor_report_elements[i]; |
| 1277 | wpa_printf(MSG_DEBUG, "%u: " MACSTR |
| 1278 | " info=0x%x op_class=%u chan=%u phy=%u pref=%d freq=%d", |
| 1279 | i, MAC2STR(nei->bssid), nei->bssid_info, |
| 1280 | nei->regulatory_class, |
| 1281 | nei->channel_number, nei->phy_type, |
| 1282 | nei->preference_present ? nei->preference : -1, |
| 1283 | nei->freq); |
| 1284 | } |
| 1285 | } |
| 1286 | |
| 1287 | |
| 1288 | static int chan_supported(struct wpa_supplicant *wpa_s, int freq) |
| 1289 | { |
| 1290 | unsigned int i; |
| 1291 | |
| 1292 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 1293 | struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i]; |
| 1294 | int j; |
| 1295 | |
| 1296 | for (j = 0; j < mode->num_channels; j++) { |
| 1297 | struct hostapd_channel_data *chan; |
| 1298 | |
| 1299 | chan = &mode->channels[j]; |
| 1300 | if (chan->freq == freq && |
| 1301 | !(chan->flag & HOSTAPD_CHAN_DISABLED)) |
| 1302 | return 1; |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | return 0; |
| 1307 | } |
| 1308 | |
| 1309 | |
| 1310 | static void wnm_set_scan_freqs(struct wpa_supplicant *wpa_s) |
| 1311 | { |
| 1312 | int *freqs; |
| 1313 | int num_freqs = 0; |
| 1314 | unsigned int i; |
| 1315 | |
| 1316 | if (!wpa_s->wnm_neighbor_report_elements) |
| 1317 | return; |
| 1318 | |
| 1319 | if (wpa_s->hw.modes == NULL) |
| 1320 | return; |
| 1321 | |
| 1322 | os_free(wpa_s->next_scan_freqs); |
| 1323 | wpa_s->next_scan_freqs = NULL; |
| 1324 | |
| 1325 | freqs = os_calloc(wpa_s->wnm_num_neighbor_report + 1, sizeof(int)); |
| 1326 | if (freqs == NULL) |
| 1327 | return; |
| 1328 | |
| 1329 | for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) { |
| 1330 | struct neighbor_report *nei; |
| 1331 | |
| 1332 | nei = &wpa_s->wnm_neighbor_report_elements[i]; |
| 1333 | if (nei->freq <= 0) { |
| 1334 | wpa_printf(MSG_DEBUG, |
| 1335 | "WNM: Unknown neighbor operating frequency for " |
| 1336 | MACSTR " - scan all channels", |
| 1337 | MAC2STR(nei->bssid)); |
| 1338 | os_free(freqs); |
| 1339 | return; |
| 1340 | } |
| 1341 | if (chan_supported(wpa_s, nei->freq)) |
| 1342 | add_freq(freqs, &num_freqs, nei->freq); |
| 1343 | } |
| 1344 | |
| 1345 | if (num_freqs == 0) { |
| 1346 | os_free(freqs); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1347 | return; |
| 1348 | } |
| 1349 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1350 | wpa_printf(MSG_DEBUG, |
| 1351 | "WNM: Scan %d frequencies based on transition candidate list", |
| 1352 | num_freqs); |
| 1353 | wpa_s->next_scan_freqs = freqs; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1357 | static int wnm_fetch_scan_results(struct wpa_supplicant *wpa_s) |
| 1358 | { |
| 1359 | struct wpa_scan_results *scan_res; |
| 1360 | struct wpa_bss *bss; |
| 1361 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 1362 | u8 i, found = 0; |
| 1363 | size_t j; |
| 1364 | |
| 1365 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1366 | "WNM: Fetch current scan results from the driver for checking transition candidates"); |
| 1367 | scan_res = wpa_drv_get_scan_results2(wpa_s); |
| 1368 | if (!scan_res) { |
| 1369 | wpa_dbg(wpa_s, MSG_DEBUG, "WNM: Failed to get scan results"); |
| 1370 | return 0; |
| 1371 | } |
| 1372 | |
| 1373 | if (scan_res->fetch_time.sec == 0) |
| 1374 | os_get_reltime(&scan_res->fetch_time); |
| 1375 | |
| 1376 | filter_scan_res(wpa_s, scan_res); |
| 1377 | |
| 1378 | for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) { |
| 1379 | struct neighbor_report *nei; |
| 1380 | |
| 1381 | nei = &wpa_s->wnm_neighbor_report_elements[i]; |
| 1382 | if (nei->preference_present && nei->preference == 0) |
| 1383 | continue; |
| 1384 | |
| 1385 | for (j = 0; j < scan_res->num; j++) { |
| 1386 | struct wpa_scan_res *res; |
| 1387 | const u8 *ssid_ie; |
| 1388 | |
| 1389 | res = scan_res->res[j]; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1390 | if (!ether_addr_equal(nei->bssid, res->bssid) || |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1391 | res->age > WNM_SCAN_RESULT_AGE * 1000) |
| 1392 | continue; |
| 1393 | bss = wpa_s->current_bss; |
| 1394 | ssid_ie = wpa_scan_get_ie(res, WLAN_EID_SSID); |
| 1395 | if (bss && ssid_ie && ssid_ie[1] && |
| 1396 | (bss->ssid_len != ssid_ie[1] || |
| 1397 | os_memcmp(bss->ssid, ssid_ie + 2, |
| 1398 | bss->ssid_len) != 0)) |
| 1399 | continue; /* Skip entries for other ESSs */ |
| 1400 | |
| 1401 | /* Potential candidate found */ |
| 1402 | found = 1; |
| 1403 | scan_snr(res); |
| 1404 | scan_est_throughput(wpa_s, res); |
| 1405 | wpa_bss_update_scan_res(wpa_s, res, |
| 1406 | &scan_res->fetch_time); |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | wpa_scan_results_free(scan_res); |
| 1411 | if (!found) { |
| 1412 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1413 | "WNM: No transition candidate matches existing scan results"); |
| 1414 | return 0; |
| 1415 | } |
| 1416 | |
| 1417 | bss = compare_scan_neighbor_results(wpa_s, WNM_SCAN_RESULT_AGE, NULL); |
| 1418 | if (!bss) { |
| 1419 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1420 | "WNM: Comparison of scan results against transition candidates did not find matches"); |
| 1421 | return 0; |
| 1422 | } |
| 1423 | |
| 1424 | /* Associate to the network */ |
| 1425 | wnm_bss_tm_connect(wpa_s, bss, ssid, 0); |
| 1426 | return 1; |
| 1427 | } |
| 1428 | |
| 1429 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1430 | static void ieee802_11_rx_bss_trans_mgmt_req(struct wpa_supplicant *wpa_s, |
| 1431 | const u8 *pos, const u8 *end, |
| 1432 | int reply) |
| 1433 | { |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1434 | unsigned int beacon_int; |
| 1435 | u8 valid_int; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1436 | #ifdef CONFIG_MBO |
| 1437 | const u8 *vendor; |
| 1438 | #endif /* CONFIG_MBO */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1439 | bool disassoc_imminent; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1440 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1441 | if (wpa_s->disable_mbo_oce || wpa_s->conf->disable_btm) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1442 | return; |
| 1443 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1444 | if (end - pos < 5) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1445 | return; |
| 1446 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1447 | #ifdef CONFIG_MBO |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1448 | wpa_s->wnm_mbo_trans_reason_present = 0; |
| 1449 | wpa_s->wnm_mbo_transition_reason = 0; |
Sunil Ravi | 4018d71 | 2019-12-06 18:01:21 -0800 | [diff] [blame] | 1450 | wpa_s->wnm_mbo_cell_pref_present = 0; |
| 1451 | wpa_s->wnm_mbo_cell_preference = 0; |
| 1452 | wpa_s->wnm_mbo_assoc_retry_delay_present = 0; |
| 1453 | wpa_s->wnm_mbo_assoc_retry_delay_sec = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1454 | #endif /* CONFIG_MBO */ |
| 1455 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1456 | if (wpa_s->current_bss) |
| 1457 | beacon_int = wpa_s->current_bss->beacon_int; |
| 1458 | else |
| 1459 | beacon_int = 100; /* best guess */ |
| 1460 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1461 | wpa_s->wnm_dialog_token = pos[0]; |
| 1462 | wpa_s->wnm_mode = pos[1]; |
| 1463 | wpa_s->wnm_dissoc_timer = WPA_GET_LE16(pos + 2); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1464 | wpa_s->wnm_link_removal = false; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1465 | valid_int = pos[4]; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1466 | wpa_s->wnm_reply = reply; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1467 | |
| 1468 | wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Request: " |
| 1469 | "dialog_token=%u request_mode=0x%x " |
| 1470 | "disassoc_timer=%u validity_interval=%u", |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1471 | wpa_s->wnm_dialog_token, wpa_s->wnm_mode, |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1472 | wpa_s->wnm_dissoc_timer, valid_int); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1473 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 1474 | #if defined(CONFIG_MBO) && defined(CONFIG_TESTING_OPTIONS) |
| 1475 | if (wpa_s->reject_btm_req_reason) { |
| 1476 | wpa_printf(MSG_INFO, |
| 1477 | "WNM: Testing - reject BSS Transition Management Request: reject_btm_req_reason=%d", |
| 1478 | wpa_s->reject_btm_req_reason); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1479 | wnm_send_bss_transition_mgmt_resp( |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1480 | wpa_s, wpa_s->wnm_dialog_token, |
| 1481 | wpa_s->reject_btm_req_reason, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1482 | MBO_TRANSITION_REJECT_REASON_UNSPECIFIED, 0, NULL); |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 1483 | return; |
| 1484 | } |
| 1485 | #endif /* CONFIG_MBO && CONFIG_TESTING_OPTIONS */ |
| 1486 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1487 | pos += 5; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1488 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1489 | if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1490 | if (end - pos < 12) { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1491 | wpa_printf(MSG_DEBUG, "WNM: Too short BSS TM Request"); |
| 1492 | return; |
| 1493 | } |
| 1494 | os_memcpy(wpa_s->wnm_bss_termination_duration, pos, 12); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1495 | pos += 12; /* BSS Termination Duration */ |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1498 | if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1499 | char url[256]; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1500 | u8 url_len; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1501 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1502 | if (end - pos < 1) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1503 | wpa_printf(MSG_DEBUG, "WNM: Invalid BSS Transition " |
| 1504 | "Management Request (URL)"); |
| 1505 | return; |
| 1506 | } |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1507 | url_len = *pos++; |
| 1508 | if (url_len > end - pos) { |
| 1509 | wpa_printf(MSG_DEBUG, |
| 1510 | "WNM: Invalid BSS Transition Management Request (URL truncated)"); |
| 1511 | return; |
| 1512 | } |
| 1513 | os_memcpy(url, pos, url_len); |
| 1514 | url[url_len] = '\0'; |
| 1515 | pos += url_len; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1516 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1517 | wpa_msg(wpa_s, MSG_INFO, ESS_DISASSOC_IMMINENT "%d %u %s", |
| 1518 | wpa_sm_pmf_enabled(wpa_s->wpa), |
| 1519 | wpa_s->wnm_dissoc_timer * beacon_int * 128 / 125, url); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1520 | } |
| 1521 | |
Dennis Jeon | e2cb56b | 2020-10-23 21:23:01 +0900 | [diff] [blame] | 1522 | #ifdef CONFIG_MBO |
| 1523 | vendor = get_ie(pos, end - pos, WLAN_EID_VENDOR_SPECIFIC); |
| 1524 | if (vendor) { |
| 1525 | wpas_mbo_ie_trans_req(wpa_s, vendor + 2, vendor[1]); |
Dennis Jeon | e2cb56b | 2020-10-23 21:23:01 +0900 | [diff] [blame] | 1526 | } |
| 1527 | #endif /* CONFIG_MBO */ |
Sunil Ravi | 84bb3e1 | 2021-06-10 09:52:05 -0700 | [diff] [blame] | 1528 | if (wpa_s->conf->btm_offload) { |
| 1529 | wpa_printf(MSG_INFO, |
| 1530 | "WNM: BTM offload enabled. Notify status and return"); |
| 1531 | wpa_s->bss_tm_status = WNM_BSS_TM_ACCEPT; |
| 1532 | wpas_notify_bss_tm_status(wpa_s); |
| 1533 | return; |
| 1534 | } |
Dennis Jeon | e2cb56b | 2020-10-23 21:23:01 +0900 | [diff] [blame] | 1535 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1536 | disassoc_imminent = wpa_s->wnm_mode & WNM_BSS_TM_REQ_DISASSOC_IMMINENT; |
| 1537 | |
| 1538 | /* |
| 1539 | * Based on IEEE P802.11be/D5.0, when a station is a non-AP MLD with |
| 1540 | * more than one affiliated link, the Link Removal Imminent field is |
| 1541 | * set to 1, and the BSS Termination Included field is set to 1, only |
| 1542 | * one of the links is removed and the other links remain associated. |
| 1543 | * Ignore the Disassociation Imminent field in such a case. |
| 1544 | */ |
| 1545 | if (disassoc_imminent && |
| 1546 | (wpa_s->valid_links & (wpa_s->valid_links - 1)) != 0 && |
| 1547 | (wpa_s->wnm_mode & WNM_BSS_TM_REQ_LINK_REMOVAL_IMMINENT) && |
| 1548 | (wpa_s->wnm_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED)) { |
| 1549 | wpa_printf(MSG_INFO, |
| 1550 | "WNM: BTM request for a single MLO link - ignore disassociation imminent since other links remain associated"); |
| 1551 | disassoc_imminent = false; |
| 1552 | wpa_s->wnm_link_removal = true; |
| 1553 | } |
| 1554 | |
| 1555 | if (disassoc_imminent) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1556 | wpa_msg(wpa_s, MSG_INFO, "WNM: Disassociation Imminent - " |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1557 | "Disassociation Timer %u", wpa_s->wnm_dissoc_timer); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1558 | if (wpa_s->wnm_dissoc_timer && !wpa_s->scanning && |
| 1559 | (!wpa_s->current_ssid || !wpa_s->current_ssid->bssid_set)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1560 | wpa_printf(MSG_DEBUG, "Trying to find another BSS"); |
| 1561 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 1562 | } |
| 1563 | } |
| 1564 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1565 | 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] | 1566 | unsigned int valid_ms; |
| 1567 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1568 | wpa_msg(wpa_s, MSG_INFO, "WNM: Preferred List Available"); |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1569 | wnm_deallocate_memory(wpa_s); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1570 | wpa_s->wnm_neighbor_report_elements = os_calloc( |
| 1571 | WNM_MAX_NEIGHBOR_REPORT, |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1572 | sizeof(struct neighbor_report)); |
| 1573 | if (wpa_s->wnm_neighbor_report_elements == NULL) |
| 1574 | return; |
| 1575 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1576 | while (end - pos >= 2 && |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1577 | wpa_s->wnm_num_neighbor_report < WNM_MAX_NEIGHBOR_REPORT) |
| 1578 | { |
| 1579 | u8 tag = *pos++; |
| 1580 | u8 len = *pos++; |
| 1581 | |
| 1582 | wpa_printf(MSG_DEBUG, "WNM: Neighbor report tag %u", |
| 1583 | tag); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1584 | if (len > end - pos) { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1585 | wpa_printf(MSG_DEBUG, "WNM: Truncated request"); |
| 1586 | return; |
| 1587 | } |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 1588 | if (tag == WLAN_EID_NEIGHBOR_REPORT) { |
| 1589 | struct neighbor_report *rep; |
| 1590 | rep = &wpa_s->wnm_neighbor_report_elements[ |
| 1591 | wpa_s->wnm_num_neighbor_report]; |
| 1592 | wnm_parse_neighbor_report(wpa_s, pos, len, rep); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1593 | if ((wpa_s->wnm_mode & |
| 1594 | WNM_BSS_TM_REQ_DISASSOC_IMMINENT) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1595 | ether_addr_equal(rep->bssid, wpa_s->bssid)) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1596 | rep->disassoc_imminent = 1; |
| 1597 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1598 | wpa_s->wnm_num_neighbor_report++; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1599 | #ifdef CONFIG_MBO |
| 1600 | if (wpa_s->wnm_mbo_trans_reason_present && |
| 1601 | wpa_s->wnm_num_neighbor_report == 1) { |
| 1602 | rep->is_first = 1; |
| 1603 | wpa_printf(MSG_DEBUG, |
| 1604 | "WNM: First transition candidate is " |
| 1605 | MACSTR, MAC2STR(rep->bssid)); |
| 1606 | } |
| 1607 | #endif /* CONFIG_MBO */ |
Dmitry Shmidt | f940fbd | 2014-04-10 10:23:13 -0700 | [diff] [blame] | 1608 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1609 | |
| 1610 | pos += len; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1611 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1612 | |
| 1613 | if (!wpa_s->wnm_num_neighbor_report) { |
| 1614 | wpa_printf(MSG_DEBUG, |
| 1615 | "WNM: Candidate list included bit is set, but no candidates found"); |
| 1616 | wnm_send_bss_transition_mgmt_resp( |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1617 | wpa_s, wpa_s->wnm_dialog_token, |
| 1618 | WNM_BSS_TM_REJECT_NO_SUITABLE_CANDIDATES, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1619 | MBO_TRANSITION_REJECT_REASON_UNSPECIFIED, 0, |
| 1620 | NULL); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1621 | return; |
| 1622 | } |
| 1623 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1624 | if (wpa_s->current_ssid && wpa_s->current_ssid->bssid_set) { |
| 1625 | wpa_printf(MSG_DEBUG, |
| 1626 | "WNM: Configuration prevents roaming (BSSID set)"); |
| 1627 | wnm_send_bss_transition_mgmt_resp( |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1628 | wpa_s, wpa_s->wnm_dialog_token, |
| 1629 | WNM_BSS_TM_REJECT_NO_SUITABLE_CANDIDATES, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1630 | MBO_TRANSITION_REJECT_REASON_UNSPECIFIED, 0, |
| 1631 | NULL); |
| 1632 | return; |
| 1633 | } |
| 1634 | |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1635 | wnm_sort_cand_list(wpa_s); |
| 1636 | wnm_dump_cand_list(wpa_s); |
| 1637 | valid_ms = valid_int * beacon_int * 128 / 125; |
| 1638 | wpa_printf(MSG_DEBUG, "WNM: Candidate list valid for %u ms", |
| 1639 | valid_ms); |
| 1640 | os_get_reltime(&wpa_s->wnm_cand_valid_until); |
| 1641 | wpa_s->wnm_cand_valid_until.sec += valid_ms / 1000; |
| 1642 | wpa_s->wnm_cand_valid_until.usec += (valid_ms % 1000) * 1000; |
| 1643 | wpa_s->wnm_cand_valid_until.sec += |
| 1644 | wpa_s->wnm_cand_valid_until.usec / 1000000; |
| 1645 | wpa_s->wnm_cand_valid_until.usec %= 1000000; |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1646 | os_memcpy(wpa_s->wnm_cand_from_bss, wpa_s->bssid, ETH_ALEN); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1647 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1648 | /* |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1649 | * Fetch the latest scan results from the kernel and check for |
| 1650 | * candidates based on those results first. This can help in |
| 1651 | * finding more up-to-date information should the driver has |
| 1652 | * done some internal scanning operations after the last scan |
| 1653 | * result update in wpa_supplicant. |
| 1654 | */ |
| 1655 | if (wnm_fetch_scan_results(wpa_s) > 0) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1656 | return; |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1657 | |
| 1658 | /* |
| 1659 | * Try to use previously received scan results, if they are |
| 1660 | * recent enough to use for a connection. |
| 1661 | */ |
| 1662 | if (wpa_s->last_scan_res_used > 0) { |
| 1663 | struct os_reltime now; |
| 1664 | |
| 1665 | os_get_reltime(&now); |
| 1666 | if (!os_reltime_expired(&now, &wpa_s->last_scan, 10)) { |
| 1667 | wpa_printf(MSG_DEBUG, |
| 1668 | "WNM: Try to use recent scan results"); |
| 1669 | if (wnm_scan_process(wpa_s, 0) > 0) |
| 1670 | return; |
| 1671 | wpa_printf(MSG_DEBUG, |
| 1672 | "WNM: No match in previous scan results - try a new scan"); |
| 1673 | } |
| 1674 | } |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1675 | |
| 1676 | wnm_set_scan_freqs(wpa_s); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1677 | if (wpa_s->wnm_num_neighbor_report == 1) { |
| 1678 | os_memcpy(wpa_s->next_scan_bssid, |
| 1679 | wpa_s->wnm_neighbor_report_elements[0].bssid, |
| 1680 | ETH_ALEN); |
| 1681 | wpa_printf(MSG_DEBUG, |
| 1682 | "WNM: Scan only for a specific BSSID since there is only a single candidate " |
| 1683 | MACSTR, MAC2STR(wpa_s->next_scan_bssid)); |
| 1684 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1685 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 1686 | } else if (reply) { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1687 | enum bss_trans_mgmt_status_code status; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1688 | |
| 1689 | if ((wpa_s->wnm_mode & WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT) || |
| 1690 | wpa_s->wnm_link_removal) |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1691 | status = WNM_BSS_TM_ACCEPT; |
| 1692 | else { |
| 1693 | wpa_msg(wpa_s, MSG_INFO, "WNM: BSS Transition Management Request did not include candidates"); |
| 1694 | status = WNM_BSS_TM_REJECT_UNSPECIFIED; |
| 1695 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1696 | wnm_send_bss_transition_mgmt_resp( |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1697 | wpa_s, wpa_s->wnm_dialog_token, status, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1698 | MBO_TRANSITION_REJECT_REASON_UNSPECIFIED, 0, NULL); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1703 | #define BTM_QUERY_MIN_SIZE 4 |
| 1704 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1705 | int wnm_send_bss_transition_mgmt_query(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1706 | u8 query_reason, |
| 1707 | const char *btm_candidates, |
| 1708 | int cand_list) |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1709 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1710 | struct wpabuf *buf; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1711 | int ret; |
| 1712 | |
| 1713 | wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Query to " |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1714 | MACSTR " query_reason=%u%s", |
| 1715 | MAC2STR(wpa_s->bssid), query_reason, |
| 1716 | cand_list ? " candidate list" : ""); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1717 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1718 | buf = wpabuf_alloc(BTM_QUERY_MIN_SIZE); |
| 1719 | if (!buf) |
| 1720 | return -1; |
| 1721 | |
| 1722 | wpabuf_put_u8(buf, WLAN_ACTION_WNM); |
| 1723 | wpabuf_put_u8(buf, WNM_BSS_TRANS_MGMT_QUERY); |
| 1724 | wpabuf_put_u8(buf, 1); |
| 1725 | wpabuf_put_u8(buf, query_reason); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1726 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1727 | if (cand_list) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1728 | wnm_add_cand_list(wpa_s, &buf); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1729 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1730 | if (btm_candidates) { |
| 1731 | const size_t max_len = 1000; |
| 1732 | |
| 1733 | ret = wpabuf_resize(&buf, max_len); |
| 1734 | if (ret < 0) { |
| 1735 | wpabuf_free(buf); |
| 1736 | return ret; |
| 1737 | } |
| 1738 | |
| 1739 | ret = ieee802_11_parse_candidate_list(btm_candidates, |
| 1740 | wpabuf_put(buf, 0), |
| 1741 | max_len); |
| 1742 | if (ret < 0) { |
| 1743 | wpabuf_free(buf); |
| 1744 | return ret; |
| 1745 | } |
| 1746 | |
| 1747 | wpabuf_put(buf, ret); |
| 1748 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1749 | |
| 1750 | ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 1751 | wpa_s->own_addr, wpa_s->bssid, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1752 | wpabuf_head_u8(buf), wpabuf_len(buf), 0); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1753 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1754 | wpabuf_free(buf); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1755 | return ret; |
| 1756 | } |
| 1757 | |
| 1758 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1759 | static void ieee802_11_rx_wnm_notif_req_wfa(struct wpa_supplicant *wpa_s, |
| 1760 | const u8 *sa, const u8 *data, |
| 1761 | int len) |
| 1762 | { |
| 1763 | const u8 *pos, *end, *next; |
| 1764 | u8 ie, ie_len; |
| 1765 | |
| 1766 | pos = data; |
| 1767 | end = data + len; |
| 1768 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1769 | while (end - pos > 1) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1770 | ie = *pos++; |
| 1771 | ie_len = *pos++; |
| 1772 | wpa_printf(MSG_DEBUG, "WNM: WFA subelement %u len %u", |
| 1773 | ie, ie_len); |
| 1774 | if (ie_len > end - pos) { |
| 1775 | wpa_printf(MSG_DEBUG, "WNM: Not enough room for " |
| 1776 | "subelement"); |
| 1777 | break; |
| 1778 | } |
| 1779 | next = pos + ie_len; |
| 1780 | if (ie_len < 4) { |
| 1781 | pos = next; |
| 1782 | continue; |
| 1783 | } |
| 1784 | wpa_printf(MSG_DEBUG, "WNM: Subelement OUI %06x type %u", |
| 1785 | WPA_GET_BE24(pos), pos[3]); |
| 1786 | |
| 1787 | #ifdef CONFIG_HS20 |
| 1788 | if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 5 && |
| 1789 | WPA_GET_BE24(pos) == OUI_WFA && |
| 1790 | pos[3] == HS20_WNM_SUB_REM_NEEDED) { |
| 1791 | /* Subscription Remediation subelement */ |
| 1792 | const u8 *ie_end; |
| 1793 | u8 url_len; |
| 1794 | char *url; |
| 1795 | u8 osu_method; |
| 1796 | |
| 1797 | wpa_printf(MSG_DEBUG, "WNM: Subscription Remediation " |
| 1798 | "subelement"); |
| 1799 | ie_end = pos + ie_len; |
| 1800 | pos += 4; |
| 1801 | url_len = *pos++; |
| 1802 | if (url_len == 0) { |
| 1803 | wpa_printf(MSG_DEBUG, "WNM: No Server URL included"); |
| 1804 | url = NULL; |
| 1805 | osu_method = 1; |
| 1806 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1807 | if (url_len + 1 > ie_end - pos) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1808 | wpa_printf(MSG_DEBUG, "WNM: Not enough room for Server URL (len=%u) and Server Method (left %d)", |
| 1809 | url_len, |
| 1810 | (int) (ie_end - pos)); |
| 1811 | break; |
| 1812 | } |
| 1813 | url = os_malloc(url_len + 1); |
| 1814 | if (url == NULL) |
| 1815 | break; |
| 1816 | os_memcpy(url, pos, url_len); |
| 1817 | url[url_len] = '\0'; |
| 1818 | osu_method = pos[url_len]; |
| 1819 | } |
| 1820 | hs20_rx_subscription_remediation(wpa_s, url, |
| 1821 | osu_method); |
| 1822 | os_free(url); |
| 1823 | pos = next; |
| 1824 | continue; |
| 1825 | } |
| 1826 | |
| 1827 | if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 8 && |
| 1828 | WPA_GET_BE24(pos) == OUI_WFA && |
| 1829 | pos[3] == HS20_WNM_DEAUTH_IMMINENT_NOTICE) { |
| 1830 | const u8 *ie_end; |
| 1831 | u8 url_len; |
| 1832 | char *url; |
| 1833 | u8 code; |
| 1834 | u16 reauth_delay; |
| 1835 | |
| 1836 | ie_end = pos + ie_len; |
| 1837 | pos += 4; |
| 1838 | code = *pos++; |
| 1839 | reauth_delay = WPA_GET_LE16(pos); |
| 1840 | pos += 2; |
| 1841 | url_len = *pos++; |
| 1842 | wpa_printf(MSG_DEBUG, "WNM: HS 2.0 Deauthentication " |
| 1843 | "Imminent - Reason Code %u " |
| 1844 | "Re-Auth Delay %u URL Length %u", |
| 1845 | code, reauth_delay, url_len); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1846 | if (url_len > ie_end - pos) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1847 | break; |
| 1848 | url = os_malloc(url_len + 1); |
| 1849 | if (url == NULL) |
| 1850 | break; |
| 1851 | os_memcpy(url, pos, url_len); |
| 1852 | url[url_len] = '\0'; |
| 1853 | hs20_rx_deauth_imminent_notice(wpa_s, code, |
| 1854 | reauth_delay, url); |
| 1855 | os_free(url); |
| 1856 | pos = next; |
| 1857 | continue; |
| 1858 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1859 | |
| 1860 | if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 5 && |
| 1861 | WPA_GET_BE24(pos) == OUI_WFA && |
| 1862 | pos[3] == HS20_WNM_T_C_ACCEPTANCE) { |
| 1863 | const u8 *ie_end; |
| 1864 | u8 url_len; |
| 1865 | char *url; |
| 1866 | |
| 1867 | ie_end = pos + ie_len; |
| 1868 | pos += 4; |
| 1869 | url_len = *pos++; |
| 1870 | wpa_printf(MSG_DEBUG, |
| 1871 | "WNM: HS 2.0 Terms and Conditions Acceptance (URL Length %u)", |
| 1872 | url_len); |
| 1873 | if (url_len > ie_end - pos) |
| 1874 | break; |
| 1875 | url = os_malloc(url_len + 1); |
| 1876 | if (!url) |
| 1877 | break; |
| 1878 | os_memcpy(url, pos, url_len); |
| 1879 | url[url_len] = '\0'; |
| 1880 | hs20_rx_t_c_acceptance(wpa_s, url); |
| 1881 | os_free(url); |
| 1882 | pos = next; |
| 1883 | continue; |
| 1884 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1885 | #endif /* CONFIG_HS20 */ |
| 1886 | |
| 1887 | pos = next; |
| 1888 | } |
| 1889 | } |
| 1890 | |
| 1891 | |
| 1892 | static void ieee802_11_rx_wnm_notif_req(struct wpa_supplicant *wpa_s, |
| 1893 | const u8 *sa, const u8 *frm, int len) |
| 1894 | { |
| 1895 | const u8 *pos, *end; |
| 1896 | u8 dialog_token, type; |
| 1897 | |
| 1898 | /* Dialog Token [1] | Type [1] | Subelements */ |
| 1899 | |
| 1900 | if (len < 2 || sa == NULL) |
| 1901 | return; |
| 1902 | end = frm + len; |
| 1903 | pos = frm; |
| 1904 | dialog_token = *pos++; |
| 1905 | type = *pos++; |
| 1906 | |
| 1907 | wpa_dbg(wpa_s, MSG_DEBUG, "WNM: Received WNM-Notification Request " |
| 1908 | "(dialog_token %u type %u sa " MACSTR ")", |
| 1909 | dialog_token, type, MAC2STR(sa)); |
| 1910 | wpa_hexdump(MSG_DEBUG, "WNM-Notification Request subelements", |
| 1911 | pos, end - pos); |
| 1912 | |
| 1913 | if (wpa_s->wpa_state != WPA_COMPLETED || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1914 | (!ether_addr_equal(sa, wpa_s->bssid) && |
| 1915 | (!wpa_s->valid_links || |
| 1916 | !ether_addr_equal(sa, wpa_s->ap_mld_addr)))) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1917 | wpa_dbg(wpa_s, MSG_DEBUG, "WNM: WNM-Notification frame not " |
| 1918 | "from our AP - ignore it"); |
| 1919 | return; |
| 1920 | } |
| 1921 | |
| 1922 | switch (type) { |
| 1923 | case 1: |
| 1924 | ieee802_11_rx_wnm_notif_req_wfa(wpa_s, sa, pos, end - pos); |
| 1925 | break; |
| 1926 | default: |
| 1927 | wpa_dbg(wpa_s, MSG_DEBUG, "WNM: Ignore unknown " |
| 1928 | "WNM-Notification type %u", type); |
| 1929 | break; |
| 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1934 | static void ieee802_11_rx_wnm_coloc_intf_req(struct wpa_supplicant *wpa_s, |
| 1935 | const u8 *sa, const u8 *frm, |
| 1936 | int len) |
| 1937 | { |
| 1938 | u8 dialog_token, req_info, auto_report, timeout; |
| 1939 | |
| 1940 | if (!wpa_s->conf->coloc_intf_reporting) |
| 1941 | return; |
| 1942 | |
| 1943 | /* Dialog Token [1] | Request Info [1] */ |
| 1944 | |
| 1945 | if (len < 2) |
| 1946 | return; |
| 1947 | dialog_token = frm[0]; |
| 1948 | req_info = frm[1]; |
| 1949 | auto_report = req_info & 0x03; |
| 1950 | timeout = req_info >> 2; |
| 1951 | |
| 1952 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1953 | "WNM: Received Collocated Interference Request (dialog_token %u auto_report %u timeout %u sa " MACSTR ")", |
| 1954 | dialog_token, auto_report, timeout, MAC2STR(sa)); |
| 1955 | |
| 1956 | if (dialog_token == 0) |
| 1957 | return; /* only nonzero values are used for request */ |
| 1958 | |
| 1959 | if (wpa_s->wpa_state != WPA_COMPLETED || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1960 | (!ether_addr_equal(sa, wpa_s->bssid) && |
| 1961 | (!wpa_s->valid_links || |
| 1962 | !ether_addr_equal(sa, wpa_s->ap_mld_addr)))) { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1963 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1964 | "WNM: Collocated Interference Request frame not from current AP - ignore it"); |
| 1965 | return; |
| 1966 | } |
| 1967 | |
| 1968 | wpa_msg(wpa_s, MSG_INFO, COLOC_INTF_REQ "%u %u %u", |
| 1969 | dialog_token, auto_report, timeout); |
| 1970 | wpa_s->coloc_intf_dialog_token = dialog_token; |
| 1971 | wpa_s->coloc_intf_auto_report = auto_report; |
| 1972 | wpa_s->coloc_intf_timeout = timeout; |
| 1973 | } |
| 1974 | |
| 1975 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1976 | void ieee802_11_rx_wnm_action(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1977 | const struct ieee80211_mgmt *mgmt, size_t len) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1978 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1979 | const u8 *pos, *end; |
| 1980 | u8 act; |
| 1981 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1982 | if (len < IEEE80211_HDRLEN + 2) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1983 | return; |
| 1984 | |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 1985 | pos = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1986 | act = *pos++; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1987 | end = ((const u8 *) mgmt) + len; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1988 | |
| 1989 | wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1990 | act, MAC2STR(mgmt->sa)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1991 | if (wpa_s->wpa_state < WPA_ASSOCIATED || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1992 | (!ether_addr_equal(mgmt->sa, wpa_s->bssid) && |
| 1993 | (!wpa_s->valid_links || |
| 1994 | !ether_addr_equal(mgmt->sa, wpa_s->ap_mld_addr)))) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1995 | wpa_printf(MSG_DEBUG, "WNM: Ignore unexpected WNM Action " |
| 1996 | "frame"); |
| 1997 | return; |
| 1998 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1999 | |
| 2000 | switch (act) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2001 | case WNM_BSS_TRANS_MGMT_REQ: |
| 2002 | ieee802_11_rx_bss_trans_mgmt_req(wpa_s, pos, end, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2003 | !(mgmt->da[0] & 0x01)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2004 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2005 | case WNM_SLEEP_MODE_RESP: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2006 | ieee802_11_rx_wnmsleep_resp(wpa_s, pos, end - pos); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2007 | break; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2008 | case WNM_NOTIFICATION_REQ: |
| 2009 | ieee802_11_rx_wnm_notif_req(wpa_s, mgmt->sa, pos, end - pos); |
| 2010 | break; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2011 | case WNM_COLLOCATED_INTERFERENCE_REQ: |
| 2012 | ieee802_11_rx_wnm_coloc_intf_req(wpa_s, mgmt->sa, pos, |
| 2013 | end - pos); |
| 2014 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2015 | default: |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 2016 | wpa_printf(MSG_ERROR, "WNM: Unknown request"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2017 | break; |
| 2018 | } |
| 2019 | } |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2020 | |
| 2021 | |
| 2022 | int wnm_send_coloc_intf_report(struct wpa_supplicant *wpa_s, u8 dialog_token, |
| 2023 | const struct wpabuf *elems) |
| 2024 | { |
| 2025 | struct wpabuf *buf; |
| 2026 | int ret; |
| 2027 | |
| 2028 | if (wpa_s->wpa_state < WPA_ASSOCIATED || !elems) |
| 2029 | return -1; |
| 2030 | |
| 2031 | wpa_printf(MSG_DEBUG, "WNM: Send Collocated Interference Report to " |
| 2032 | MACSTR " (dialog token %u)", |
| 2033 | MAC2STR(wpa_s->bssid), dialog_token); |
| 2034 | |
| 2035 | buf = wpabuf_alloc(3 + wpabuf_len(elems)); |
| 2036 | if (!buf) |
| 2037 | return -1; |
| 2038 | |
| 2039 | wpabuf_put_u8(buf, WLAN_ACTION_WNM); |
| 2040 | wpabuf_put_u8(buf, WNM_COLLOCATED_INTERFERENCE_REPORT); |
| 2041 | wpabuf_put_u8(buf, dialog_token); |
| 2042 | wpabuf_put_buf(buf, elems); |
| 2043 | |
| 2044 | ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 2045 | wpa_s->own_addr, wpa_s->bssid, |
| 2046 | wpabuf_head_u8(buf), wpabuf_len(buf), 0); |
| 2047 | wpabuf_free(buf); |
| 2048 | return ret; |
| 2049 | } |
| 2050 | |
| 2051 | |
| 2052 | void wnm_set_coloc_intf_elems(struct wpa_supplicant *wpa_s, |
| 2053 | struct wpabuf *elems) |
| 2054 | { |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 2055 | wpabuf_free(wpa_s->coloc_intf_elems); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2056 | if (elems && wpabuf_len(elems) == 0) { |
| 2057 | wpabuf_free(elems); |
| 2058 | elems = NULL; |
| 2059 | } |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 2060 | wpa_s->coloc_intf_elems = elems; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2061 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 2062 | if (wpa_s->conf->coloc_intf_reporting && wpa_s->coloc_intf_elems && |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2063 | wpa_s->coloc_intf_dialog_token && |
| 2064 | (wpa_s->coloc_intf_auto_report == 1 || |
| 2065 | wpa_s->coloc_intf_auto_report == 3)) { |
| 2066 | /* TODO: Check that there has not been less than |
| 2067 | * wpa_s->coloc_intf_timeout * 200 TU from the last report. |
| 2068 | */ |
| 2069 | wnm_send_coloc_intf_report(wpa_s, |
| 2070 | wpa_s->coloc_intf_dialog_token, |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 2071 | wpa_s->coloc_intf_elems); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2072 | } |
| 2073 | } |
| 2074 | |
| 2075 | |
| 2076 | void wnm_clear_coloc_intf_reporting(struct wpa_supplicant *wpa_s) |
| 2077 | { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2078 | wpa_s->coloc_intf_dialog_token = 0; |
| 2079 | wpa_s->coloc_intf_auto_report = 0; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2080 | } |
| 2081 | |
| 2082 | |
| 2083 | bool wnm_is_bss_excluded(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
| 2084 | { |
| 2085 | unsigned int i; |
| 2086 | |
| 2087 | if (!(wpa_s->wnm_mode & WNM_BSS_TM_REQ_DISASSOC_IMMINENT)) |
| 2088 | return false; |
| 2089 | |
| 2090 | /* |
| 2091 | * In case disassociation imminent is set, do no try to use a BSS to |
| 2092 | * which we are connected. |
| 2093 | */ |
| 2094 | |
| 2095 | if (wpa_s->current_bss && |
| 2096 | ether_addr_equal(wpa_s->current_bss->bssid, bss->bssid)) { |
| 2097 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2098 | "WNM: Disassociation imminent: current BSS"); |
| 2099 | return true; |
| 2100 | } |
| 2101 | |
| 2102 | if (!wpa_s->valid_links) |
| 2103 | return false; |
| 2104 | |
| 2105 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 2106 | if (!(wpa_s->valid_links & BIT(i))) |
| 2107 | continue; |
| 2108 | |
| 2109 | if (ether_addr_equal(wpa_s->links[i].bssid, bss->bssid)) { |
| 2110 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2111 | "WNM: MLD: Disassociation imminent: current link"); |
| 2112 | return true; |
| 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | return false; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2117 | } |