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