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