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