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