Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * wpa_supplicant - MBO |
| 3 | * |
| 4 | * Copyright(c) 2015 Intel Deutschland GmbH |
| 5 | * Contact Information: |
| 6 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 7 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 8 | * |
| 9 | * This software may be distributed under the terms of the BSD license. |
| 10 | * See README for more details. |
| 11 | */ |
| 12 | |
| 13 | #include "utils/includes.h" |
| 14 | |
| 15 | #include "utils/common.h" |
| 16 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 17 | #include "common/gas.h" |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 18 | #include "rsn_supp/wpa.h" |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 19 | #include "config.h" |
| 20 | #include "wpa_supplicant_i.h" |
| 21 | #include "driver_i.h" |
| 22 | #include "bss.h" |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 23 | #include "scan.h" |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 24 | |
| 25 | /* type + length + oui + oui type */ |
| 26 | #define MBO_IE_HEADER 6 |
| 27 | |
| 28 | |
| 29 | static int wpas_mbo_validate_non_pref_chan(u8 oper_class, u8 chan, u8 reason) |
| 30 | { |
| 31 | if (reason > MBO_NON_PREF_CHAN_REASON_INT_INTERFERENCE) |
| 32 | return -1; |
| 33 | |
| 34 | /* Only checking the validity of the channel and oper_class */ |
| 35 | if (ieee80211_chan_to_freq(NULL, oper_class, chan) == -1) |
| 36 | return -1; |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 42 | const u8 * mbo_attr_from_mbo_ie(const u8 *mbo_ie, enum mbo_attr_id attr) |
| 43 | { |
| 44 | const u8 *mbo; |
| 45 | u8 ie_len = mbo_ie[1]; |
| 46 | |
| 47 | if (ie_len < MBO_IE_HEADER - 2) |
| 48 | return NULL; |
| 49 | mbo = mbo_ie + MBO_IE_HEADER; |
| 50 | |
| 51 | return get_ie(mbo, 2 + ie_len - MBO_IE_HEADER, attr); |
| 52 | } |
| 53 | |
| 54 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 55 | const u8 * mbo_get_attr_from_ies(const u8 *ies, size_t ies_len, |
| 56 | enum mbo_attr_id attr) |
| 57 | { |
| 58 | const u8 *mbo_ie; |
| 59 | |
| 60 | mbo_ie = get_vendor_ie(ies, ies_len, MBO_IE_VENDOR_TYPE); |
| 61 | if (!mbo_ie) |
| 62 | return NULL; |
| 63 | |
| 64 | return mbo_attr_from_mbo_ie(mbo_ie, attr); |
| 65 | } |
| 66 | |
| 67 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 68 | static const u8 * wpas_mbo_get_bss_attr(struct wpa_bss *bss, |
| 69 | enum mbo_attr_id attr, bool beacon) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 70 | { |
| 71 | const u8 *mbo, *end; |
| 72 | |
| 73 | if (!bss) |
| 74 | return NULL; |
| 75 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 76 | if (beacon) |
| 77 | mbo = wpa_bss_get_vendor_ie_beacon(bss, MBO_IE_VENDOR_TYPE); |
| 78 | else |
| 79 | mbo = wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 80 | if (!mbo) |
| 81 | return NULL; |
| 82 | |
| 83 | end = mbo + 2 + mbo[1]; |
| 84 | mbo += MBO_IE_HEADER; |
| 85 | |
| 86 | return get_ie(mbo, end - mbo, attr); |
| 87 | } |
| 88 | |
| 89 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 90 | const u8 * wpas_mbo_check_assoc_disallow(struct wpa_bss *bss) |
| 91 | { |
| 92 | const u8 *assoc_disallow; |
| 93 | |
| 94 | assoc_disallow = wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_ASSOC_DISALLOW, |
| 95 | bss->beacon_newer); |
| 96 | if (assoc_disallow && assoc_disallow[1] >= 1) |
| 97 | return assoc_disallow; |
| 98 | |
| 99 | return NULL; |
| 100 | } |
| 101 | |
| 102 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 103 | void wpas_mbo_check_pmf(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 104 | struct wpa_ssid *ssid) |
| 105 | { |
| 106 | const u8 *rsne, *mbo, *oce; |
| 107 | struct wpa_ie_data ie; |
| 108 | |
| 109 | wpa_s->disable_mbo_oce = 0; |
| 110 | if (!bss) |
| 111 | return; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 112 | mbo = wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND, false); |
| 113 | oce = wpas_mbo_get_bss_attr(bss, OCE_ATTR_ID_CAPA_IND, false); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 114 | if (!mbo && !oce) |
| 115 | return; |
| 116 | if (oce && oce[1] >= 1 && (oce[2] & OCE_IS_STA_CFON)) |
| 117 | return; /* STA-CFON is not required to enable PMF */ |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 118 | rsne = wpa_bss_get_rsne(wpa_s, bss, ssid, false); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 119 | if (!rsne || wpa_parse_wpa_ie(rsne, 2 + rsne[1], &ie) < 0) |
| 120 | return; /* AP is not using RSN */ |
| 121 | |
| 122 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) |
| 123 | wpa_s->disable_mbo_oce = 1; /* AP uses RSN without PMF */ |
| 124 | if (wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION) |
| 125 | wpa_s->disable_mbo_oce = 1; /* STA uses RSN without PMF */ |
| 126 | if (wpa_s->disable_mbo_oce) |
| 127 | wpa_printf(MSG_INFO, |
| 128 | "MBO: Disable MBO/OCE due to misbehaving AP not having enabled PMF"); |
| 129 | } |
| 130 | |
| 131 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 132 | static void wpas_mbo_non_pref_chan_attr_body(struct wpa_supplicant *wpa_s, |
| 133 | struct wpabuf *mbo, |
| 134 | u8 start, u8 end) |
| 135 | { |
| 136 | u8 i; |
| 137 | |
| 138 | wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].oper_class); |
| 139 | |
| 140 | for (i = start; i < end; i++) |
| 141 | wpabuf_put_u8(mbo, wpa_s->non_pref_chan[i].chan); |
| 142 | |
| 143 | wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].preference); |
| 144 | wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].reason); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 148 | static void wpas_mbo_non_pref_chan_attr_hdr(struct wpabuf *mbo, size_t size) |
| 149 | { |
| 150 | wpabuf_put_u8(mbo, MBO_ATTR_ID_NON_PREF_CHAN_REPORT); |
| 151 | wpabuf_put_u8(mbo, size); /* Length */ |
| 152 | } |
| 153 | |
| 154 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 155 | static void wpas_mbo_non_pref_chan_attr(struct wpa_supplicant *wpa_s, |
| 156 | struct wpabuf *mbo, u8 start, u8 end) |
| 157 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 158 | size_t size = end - start + 3; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 159 | |
| 160 | if (size + 2 > wpabuf_tailroom(mbo)) |
| 161 | return; |
| 162 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 163 | wpas_mbo_non_pref_chan_attr_hdr(mbo, size); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 164 | wpas_mbo_non_pref_chan_attr_body(wpa_s, mbo, start, end); |
| 165 | } |
| 166 | |
| 167 | |
| 168 | static void wpas_mbo_non_pref_chan_subelem_hdr(struct wpabuf *mbo, u8 len) |
| 169 | { |
| 170 | wpabuf_put_u8(mbo, WLAN_EID_VENDOR_SPECIFIC); |
| 171 | wpabuf_put_u8(mbo, len); /* Length */ |
| 172 | wpabuf_put_be24(mbo, OUI_WFA); |
| 173 | wpabuf_put_u8(mbo, MBO_ATTR_ID_NON_PREF_CHAN_REPORT); |
| 174 | } |
| 175 | |
| 176 | |
| 177 | static void wpas_mbo_non_pref_chan_subelement(struct wpa_supplicant *wpa_s, |
| 178 | struct wpabuf *mbo, u8 start, |
| 179 | u8 end) |
| 180 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 181 | size_t size = end - start + 7; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 182 | |
| 183 | if (size + 2 > wpabuf_tailroom(mbo)) |
| 184 | return; |
| 185 | |
| 186 | wpas_mbo_non_pref_chan_subelem_hdr(mbo, size); |
| 187 | wpas_mbo_non_pref_chan_attr_body(wpa_s, mbo, start, end); |
| 188 | } |
| 189 | |
| 190 | |
| 191 | static void wpas_mbo_non_pref_chan_attrs(struct wpa_supplicant *wpa_s, |
| 192 | struct wpabuf *mbo, int subelement) |
| 193 | { |
| 194 | u8 i, start = 0; |
| 195 | struct wpa_mbo_non_pref_channel *start_pref; |
| 196 | |
| 197 | if (!wpa_s->non_pref_chan || !wpa_s->non_pref_chan_num) { |
| 198 | if (subelement) |
| 199 | wpas_mbo_non_pref_chan_subelem_hdr(mbo, 4); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 200 | else |
| 201 | wpas_mbo_non_pref_chan_attr_hdr(mbo, 0); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 202 | return; |
| 203 | } |
| 204 | start_pref = &wpa_s->non_pref_chan[0]; |
| 205 | |
| 206 | for (i = 1; i <= wpa_s->non_pref_chan_num; i++) { |
| 207 | struct wpa_mbo_non_pref_channel *non_pref = NULL; |
| 208 | |
| 209 | if (i < wpa_s->non_pref_chan_num) |
| 210 | non_pref = &wpa_s->non_pref_chan[i]; |
| 211 | if (!non_pref || |
| 212 | non_pref->oper_class != start_pref->oper_class || |
| 213 | non_pref->reason != start_pref->reason || |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 214 | non_pref->preference != start_pref->preference) { |
| 215 | if (subelement) |
| 216 | wpas_mbo_non_pref_chan_subelement(wpa_s, mbo, |
| 217 | start, i); |
| 218 | else |
| 219 | wpas_mbo_non_pref_chan_attr(wpa_s, mbo, start, |
| 220 | i); |
| 221 | |
| 222 | if (!non_pref) |
| 223 | return; |
| 224 | |
| 225 | start = i; |
| 226 | start_pref = non_pref; |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 232 | int wpas_mbo_ie(struct wpa_supplicant *wpa_s, u8 *buf, size_t len, |
| 233 | int add_oce_capa) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 234 | { |
| 235 | struct wpabuf *mbo; |
| 236 | int res; |
| 237 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 238 | if (len < MBO_IE_HEADER + 3 + 7 + |
| 239 | ((wpa_s->enable_oce & OCE_STA) ? 3 : 0)) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 240 | return 0; |
| 241 | |
| 242 | /* Leave room for the MBO IE header */ |
| 243 | mbo = wpabuf_alloc(len - MBO_IE_HEADER); |
| 244 | if (!mbo) |
| 245 | return 0; |
| 246 | |
| 247 | /* Add non-preferred channels attribute */ |
| 248 | wpas_mbo_non_pref_chan_attrs(wpa_s, mbo, 0); |
| 249 | |
| 250 | /* |
| 251 | * Send cellular capabilities attribute even if AP does not advertise |
| 252 | * cellular capabilities. |
| 253 | */ |
| 254 | wpabuf_put_u8(mbo, MBO_ATTR_ID_CELL_DATA_CAPA); |
| 255 | wpabuf_put_u8(mbo, 1); |
| 256 | wpabuf_put_u8(mbo, wpa_s->conf->mbo_cell_capa); |
| 257 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 258 | /* Add OCE capability indication attribute if OCE is enabled */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 259 | if ((wpa_s->enable_oce & OCE_STA) && add_oce_capa) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 260 | wpabuf_put_u8(mbo, OCE_ATTR_ID_CAPA_IND); |
| 261 | wpabuf_put_u8(mbo, 1); |
| 262 | wpabuf_put_u8(mbo, OCE_RELEASE); |
| 263 | } |
| 264 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 265 | res = mbo_add_ie(buf, len, wpabuf_head_u8(mbo), wpabuf_len(mbo)); |
| 266 | if (!res) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 267 | wpa_printf(MSG_ERROR, "Failed to add MBO/OCE IE"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 268 | |
| 269 | wpabuf_free(mbo); |
| 270 | return res; |
| 271 | } |
| 272 | |
| 273 | |
| 274 | static void wpas_mbo_send_wnm_notification(struct wpa_supplicant *wpa_s, |
| 275 | const u8 *data, size_t len) |
| 276 | { |
| 277 | struct wpabuf *buf; |
| 278 | int res; |
| 279 | |
| 280 | /* |
| 281 | * Send WNM-Notification Request frame only in case of a change in |
| 282 | * non-preferred channels list during association, if the AP supports |
| 283 | * MBO. |
| 284 | */ |
| 285 | if (wpa_s->wpa_state != WPA_COMPLETED || !wpa_s->current_bss || |
| 286 | !wpa_bss_get_vendor_ie(wpa_s->current_bss, MBO_IE_VENDOR_TYPE)) |
| 287 | return; |
| 288 | |
| 289 | buf = wpabuf_alloc(4 + len); |
| 290 | if (!buf) |
| 291 | return; |
| 292 | |
| 293 | wpabuf_put_u8(buf, WLAN_ACTION_WNM); |
| 294 | wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ); |
| 295 | wpa_s->mbo_wnm_token++; |
| 296 | if (wpa_s->mbo_wnm_token == 0) |
| 297 | wpa_s->mbo_wnm_token++; |
| 298 | wpabuf_put_u8(buf, wpa_s->mbo_wnm_token); |
| 299 | wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC); /* Type */ |
| 300 | |
| 301 | wpabuf_put_data(buf, data, len); |
| 302 | |
| 303 | res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 304 | wpa_s->own_addr, wpa_s->bssid, |
| 305 | wpabuf_head(buf), wpabuf_len(buf), 0); |
| 306 | if (res < 0) |
| 307 | wpa_printf(MSG_DEBUG, |
| 308 | "Failed to send WNM-Notification Request frame with non-preferred channel list"); |
| 309 | |
| 310 | wpabuf_free(buf); |
| 311 | } |
| 312 | |
| 313 | |
| 314 | static void wpas_mbo_non_pref_chan_changed(struct wpa_supplicant *wpa_s) |
| 315 | { |
| 316 | struct wpabuf *buf; |
| 317 | |
| 318 | buf = wpabuf_alloc(512); |
| 319 | if (!buf) |
| 320 | return; |
| 321 | |
| 322 | wpas_mbo_non_pref_chan_attrs(wpa_s, buf, 1); |
| 323 | wpas_mbo_send_wnm_notification(wpa_s, wpabuf_head_u8(buf), |
| 324 | wpabuf_len(buf)); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 325 | wpas_update_mbo_connect_params(wpa_s); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 326 | wpabuf_free(buf); |
| 327 | } |
| 328 | |
| 329 | |
| 330 | static int wpa_non_pref_chan_is_eq(struct wpa_mbo_non_pref_channel *a, |
| 331 | struct wpa_mbo_non_pref_channel *b) |
| 332 | { |
| 333 | return a->oper_class == b->oper_class && a->chan == b->chan; |
| 334 | } |
| 335 | |
| 336 | |
| 337 | /* |
| 338 | * wpa_non_pref_chan_cmp - Compare two channels for sorting |
| 339 | * |
| 340 | * In MBO IE non-preferred channel subelement we can put many channels in an |
| 341 | * attribute if they are in the same operating class and have the same |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 342 | * preference and reason. To make it easy for the functions that build |
| 343 | * the IE attributes and WNM Request subelements, save the channels sorted |
| 344 | * by their oper_class and reason. |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 345 | */ |
| 346 | static int wpa_non_pref_chan_cmp(const void *_a, const void *_b) |
| 347 | { |
| 348 | const struct wpa_mbo_non_pref_channel *a = _a, *b = _b; |
| 349 | |
| 350 | if (a->oper_class != b->oper_class) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 351 | return (int) a->oper_class - (int) b->oper_class; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 352 | if (a->reason != b->reason) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 353 | return (int) a->reason - (int) b->reason; |
| 354 | return (int) a->preference - (int) b->preference; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | |
| 358 | int wpas_mbo_update_non_pref_chan(struct wpa_supplicant *wpa_s, |
| 359 | const char *non_pref_chan) |
| 360 | { |
| 361 | char *cmd, *token, *context = NULL; |
| 362 | struct wpa_mbo_non_pref_channel *chans = NULL, *tmp_chans; |
| 363 | size_t num = 0, size = 0; |
| 364 | unsigned i; |
| 365 | |
| 366 | wpa_printf(MSG_DEBUG, "MBO: Update non-preferred channels, non_pref_chan=%s", |
| 367 | non_pref_chan ? non_pref_chan : "N/A"); |
| 368 | |
| 369 | /* |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 370 | * The shortest channel configuration is 7 characters - 3 colons and |
| 371 | * 4 values. |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 372 | */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 373 | if (!non_pref_chan || os_strlen(non_pref_chan) < 7) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 374 | goto update; |
| 375 | |
| 376 | cmd = os_strdup(non_pref_chan); |
| 377 | if (!cmd) |
| 378 | return -1; |
| 379 | |
| 380 | while ((token = str_token(cmd, " ", &context))) { |
| 381 | struct wpa_mbo_non_pref_channel *chan; |
| 382 | int ret; |
| 383 | unsigned int _oper_class; |
| 384 | unsigned int _chan; |
| 385 | unsigned int _preference; |
| 386 | unsigned int _reason; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 387 | |
| 388 | if (num == size) { |
| 389 | size = size ? size * 2 : 1; |
| 390 | tmp_chans = os_realloc_array(chans, size, |
| 391 | sizeof(*chans)); |
| 392 | if (!tmp_chans) { |
| 393 | wpa_printf(MSG_ERROR, |
| 394 | "Couldn't reallocate non_pref_chan"); |
| 395 | goto fail; |
| 396 | } |
| 397 | chans = tmp_chans; |
| 398 | } |
| 399 | |
| 400 | chan = &chans[num]; |
| 401 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 402 | ret = sscanf(token, "%u:%u:%u:%u", &_oper_class, |
| 403 | &_chan, &_preference, &_reason); |
| 404 | if (ret != 4 || |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 405 | _oper_class > 255 || _chan > 255 || |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 406 | _preference > 255 || _reason > 65535 ) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 407 | wpa_printf(MSG_ERROR, "Invalid non-pref chan input %s", |
| 408 | token); |
| 409 | goto fail; |
| 410 | } |
| 411 | chan->oper_class = _oper_class; |
| 412 | chan->chan = _chan; |
| 413 | chan->preference = _preference; |
| 414 | chan->reason = _reason; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 415 | |
| 416 | if (wpas_mbo_validate_non_pref_chan(chan->oper_class, |
| 417 | chan->chan, chan->reason)) { |
| 418 | wpa_printf(MSG_ERROR, |
| 419 | "Invalid non_pref_chan: oper class %d chan %d reason %d", |
| 420 | chan->oper_class, chan->chan, chan->reason); |
| 421 | goto fail; |
| 422 | } |
| 423 | |
| 424 | for (i = 0; i < num; i++) |
| 425 | if (wpa_non_pref_chan_is_eq(chan, &chans[i])) |
| 426 | break; |
| 427 | if (i != num) { |
| 428 | wpa_printf(MSG_ERROR, |
| 429 | "oper class %d chan %d is duplicated", |
| 430 | chan->oper_class, chan->chan); |
| 431 | goto fail; |
| 432 | } |
| 433 | |
| 434 | num++; |
| 435 | } |
| 436 | |
| 437 | os_free(cmd); |
| 438 | |
| 439 | if (chans) { |
| 440 | qsort(chans, num, sizeof(struct wpa_mbo_non_pref_channel), |
| 441 | wpa_non_pref_chan_cmp); |
| 442 | } |
| 443 | |
| 444 | update: |
| 445 | os_free(wpa_s->non_pref_chan); |
| 446 | wpa_s->non_pref_chan = chans; |
| 447 | wpa_s->non_pref_chan_num = num; |
| 448 | wpas_mbo_non_pref_chan_changed(wpa_s); |
| 449 | |
| 450 | return 0; |
| 451 | |
| 452 | fail: |
| 453 | os_free(chans); |
| 454 | os_free(cmd); |
| 455 | return -1; |
| 456 | } |
| 457 | |
| 458 | |
| 459 | void wpas_mbo_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ie) |
| 460 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 461 | u8 *len; |
| 462 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 463 | wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 464 | len = wpabuf_put(ie, 1); |
| 465 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 466 | wpabuf_put_be24(ie, OUI_WFA); |
| 467 | wpabuf_put_u8(ie, MBO_OUI_TYPE); |
| 468 | |
| 469 | wpabuf_put_u8(ie, MBO_ATTR_ID_CELL_DATA_CAPA); |
| 470 | wpabuf_put_u8(ie, 1); |
| 471 | wpabuf_put_u8(ie, wpa_s->conf->mbo_cell_capa); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 472 | if (wpa_s->enable_oce & OCE_STA) { |
| 473 | wpabuf_put_u8(ie, OCE_ATTR_ID_CAPA_IND); |
| 474 | wpabuf_put_u8(ie, 1); |
| 475 | wpabuf_put_u8(ie, OCE_RELEASE); |
| 476 | } |
| 477 | *len = (u8 *) wpabuf_put(ie, 0) - len - 1; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 481 | void wpas_mbo_ie_trans_req(struct wpa_supplicant *wpa_s, const u8 *mbo_ie, |
| 482 | size_t len) |
| 483 | { |
Sunil Ravi | 4018d71 | 2019-12-06 18:01:21 -0800 | [diff] [blame] | 484 | const u8 *pos; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 485 | u8 id, elen; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 486 | |
| 487 | if (len <= 4 || WPA_GET_BE24(mbo_ie) != OUI_WFA || |
| 488 | mbo_ie[3] != MBO_OUI_TYPE) |
| 489 | return; |
| 490 | |
| 491 | pos = mbo_ie + 4; |
| 492 | len -= 4; |
| 493 | |
| 494 | while (len >= 2) { |
| 495 | id = *pos++; |
| 496 | elen = *pos++; |
| 497 | len -= 2; |
| 498 | |
| 499 | if (elen > len) |
| 500 | goto fail; |
| 501 | |
| 502 | switch (id) { |
| 503 | case MBO_ATTR_ID_CELL_DATA_PREF: |
| 504 | if (elen != 1) |
| 505 | goto fail; |
| 506 | |
| 507 | if (wpa_s->conf->mbo_cell_capa == |
Sunil Ravi | 4018d71 | 2019-12-06 18:01:21 -0800 | [diff] [blame] | 508 | MBO_CELL_CAPA_AVAILABLE) { |
| 509 | wpa_s->wnm_mbo_cell_pref_present = 1; |
| 510 | wpa_s->wnm_mbo_cell_preference = *pos; |
| 511 | } else { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 512 | wpa_printf(MSG_DEBUG, |
Sunil Ravi | 4018d71 | 2019-12-06 18:01:21 -0800 | [diff] [blame] | 513 | "MBO: Station does not support " |
| 514 | "Cellular data connection"); |
| 515 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 516 | break; |
| 517 | case MBO_ATTR_ID_TRANSITION_REASON: |
| 518 | if (elen != 1) |
| 519 | goto fail; |
| 520 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 521 | wpa_s->wnm_mbo_trans_reason_present = 1; |
| 522 | wpa_s->wnm_mbo_transition_reason = *pos; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 523 | break; |
| 524 | case MBO_ATTR_ID_ASSOC_RETRY_DELAY: |
| 525 | if (elen != 2) |
| 526 | goto fail; |
| 527 | |
| 528 | if (wpa_s->wnm_mode & |
| 529 | WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) { |
| 530 | wpa_printf(MSG_DEBUG, |
Sunil Ravi | 4018d71 | 2019-12-06 18:01:21 -0800 | [diff] [blame] | 531 | "MBO: Unexpected association retry delay, " |
| 532 | "BSS is terminating"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 533 | goto fail; |
| 534 | } else if (wpa_s->wnm_mode & |
| 535 | WNM_BSS_TM_REQ_DISASSOC_IMMINENT) { |
Sunil Ravi | 4018d71 | 2019-12-06 18:01:21 -0800 | [diff] [blame] | 536 | wpa_s->wnm_mbo_assoc_retry_delay_present = 1; |
| 537 | wpa_s->wnm_mbo_assoc_retry_delay_sec = WPA_GET_LE16(pos); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 538 | wpa_printf(MSG_DEBUG, |
| 539 | "MBO: Association retry delay: %u", |
Sunil Ravi | 4018d71 | 2019-12-06 18:01:21 -0800 | [diff] [blame] | 540 | wpa_s->wnm_mbo_assoc_retry_delay_sec); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 541 | } else { |
| 542 | wpa_printf(MSG_DEBUG, |
Sunil Ravi | 4018d71 | 2019-12-06 18:01:21 -0800 | [diff] [blame] | 543 | "MBO: Association retry delay attribute " |
| 544 | "not in disassoc imminent mode"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | break; |
| 548 | case MBO_ATTR_ID_AP_CAPA_IND: |
| 549 | case MBO_ATTR_ID_NON_PREF_CHAN_REPORT: |
| 550 | case MBO_ATTR_ID_CELL_DATA_CAPA: |
| 551 | case MBO_ATTR_ID_ASSOC_DISALLOW: |
| 552 | case MBO_ATTR_ID_TRANSITION_REJECT_REASON: |
| 553 | wpa_printf(MSG_DEBUG, |
| 554 | "MBO: Attribute %d should not be included in BTM Request frame", |
| 555 | id); |
| 556 | break; |
| 557 | default: |
| 558 | wpa_printf(MSG_DEBUG, "MBO: Unknown attribute id %u", |
| 559 | id); |
| 560 | return; |
| 561 | } |
| 562 | |
| 563 | pos += elen; |
| 564 | len -= elen; |
| 565 | } |
| 566 | |
Sunil Ravi | 4018d71 | 2019-12-06 18:01:21 -0800 | [diff] [blame] | 567 | if (wpa_s->wnm_mbo_cell_pref_present) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 568 | wpa_msg(wpa_s, MSG_INFO, MBO_CELL_PREFERENCE "preference=%u", |
Sunil Ravi | 4018d71 | 2019-12-06 18:01:21 -0800 | [diff] [blame] | 569 | wpa_s->wnm_mbo_cell_preference); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 570 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 571 | if (wpa_s->wnm_mbo_trans_reason_present) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 572 | wpa_msg(wpa_s, MSG_INFO, MBO_TRANSITION_REASON "reason=%u", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 573 | wpa_s->wnm_mbo_transition_reason); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 574 | |
Sunil Ravi | 4018d71 | 2019-12-06 18:01:21 -0800 | [diff] [blame] | 575 | if (wpa_s->wnm_mbo_assoc_retry_delay_sec && wpa_s->current_bss) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 576 | wpa_bss_tmp_disallow(wpa_s, wpa_s->current_bss->bssid, |
Sunil Ravi | 4018d71 | 2019-12-06 18:01:21 -0800 | [diff] [blame] | 577 | wpa_s->wnm_mbo_assoc_retry_delay_sec, 0); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 578 | |
| 579 | return; |
| 580 | fail: |
| 581 | wpa_printf(MSG_DEBUG, "MBO IE parsing failed (id=%u len=%u left=%zu)", |
| 582 | id, elen, len); |
| 583 | } |
| 584 | |
| 585 | |
| 586 | size_t wpas_mbo_ie_bss_trans_reject(struct wpa_supplicant *wpa_s, u8 *pos, |
| 587 | size_t len, |
| 588 | enum mbo_transition_reject_reason reason) |
| 589 | { |
| 590 | u8 reject_attr[3]; |
| 591 | |
| 592 | reject_attr[0] = MBO_ATTR_ID_TRANSITION_REJECT_REASON; |
| 593 | reject_attr[1] = 1; |
| 594 | reject_attr[2] = reason; |
| 595 | |
| 596 | return mbo_add_ie(pos, len, reject_attr, sizeof(reject_attr)); |
| 597 | } |
| 598 | |
| 599 | |
| 600 | void wpas_mbo_update_cell_capa(struct wpa_supplicant *wpa_s, u8 mbo_cell_capa) |
| 601 | { |
| 602 | u8 cell_capa[7]; |
| 603 | |
| 604 | if (wpa_s->conf->mbo_cell_capa == mbo_cell_capa) { |
| 605 | wpa_printf(MSG_DEBUG, |
| 606 | "MBO: Cellular capability already set to %u", |
| 607 | mbo_cell_capa); |
| 608 | return; |
| 609 | } |
| 610 | |
| 611 | wpa_s->conf->mbo_cell_capa = mbo_cell_capa; |
| 612 | |
| 613 | cell_capa[0] = WLAN_EID_VENDOR_SPECIFIC; |
| 614 | cell_capa[1] = 5; /* Length */ |
| 615 | WPA_PUT_BE24(cell_capa + 2, OUI_WFA); |
| 616 | cell_capa[5] = MBO_ATTR_ID_CELL_DATA_CAPA; |
| 617 | cell_capa[6] = mbo_cell_capa; |
| 618 | |
| 619 | wpas_mbo_send_wnm_notification(wpa_s, cell_capa, 7); |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 620 | wpa_supplicant_set_default_scan_ies(wpa_s); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 621 | wpas_update_mbo_connect_params(wpa_s); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 622 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 623 | |
| 624 | |
| 625 | struct wpabuf * mbo_build_anqp_buf(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 626 | struct wpa_bss *bss, u32 mbo_subtypes) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 627 | { |
| 628 | struct wpabuf *anqp_buf; |
| 629 | u8 *len_pos; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 630 | u8 i; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 631 | |
| 632 | if (!wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE)) { |
| 633 | wpa_printf(MSG_INFO, "MBO: " MACSTR |
| 634 | " does not support MBO - cannot request MBO ANQP elements from it", |
| 635 | MAC2STR(bss->bssid)); |
| 636 | return NULL; |
| 637 | } |
| 638 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 639 | /* Allocate size for the maximum case - all MBO subtypes are set */ |
| 640 | anqp_buf = wpabuf_alloc(9 + MAX_MBO_ANQP_SUBTYPE); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 641 | if (!anqp_buf) |
| 642 | return NULL; |
| 643 | |
| 644 | len_pos = gas_anqp_add_element(anqp_buf, ANQP_VENDOR_SPECIFIC); |
| 645 | wpabuf_put_be24(anqp_buf, OUI_WFA); |
| 646 | wpabuf_put_u8(anqp_buf, MBO_ANQP_OUI_TYPE); |
| 647 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 648 | wpabuf_put_u8(anqp_buf, MBO_ANQP_SUBTYPE_QUERY_LIST); |
| 649 | |
| 650 | /* The first valid MBO subtype is 1 */ |
| 651 | for (i = 1; i <= MAX_MBO_ANQP_SUBTYPE; i++) { |
| 652 | if (mbo_subtypes & BIT(i)) |
| 653 | wpabuf_put_u8(anqp_buf, i); |
| 654 | } |
| 655 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 656 | gas_anqp_set_element_len(anqp_buf, len_pos); |
| 657 | |
| 658 | return anqp_buf; |
| 659 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 660 | |
| 661 | |
| 662 | void mbo_parse_rx_anqp_resp(struct wpa_supplicant *wpa_s, |
| 663 | struct wpa_bss *bss, const u8 *sa, |
| 664 | const u8 *data, size_t slen) |
| 665 | { |
| 666 | const u8 *pos = data; |
| 667 | u8 subtype; |
| 668 | |
| 669 | if (slen < 1) |
| 670 | return; |
| 671 | |
| 672 | subtype = *pos++; |
| 673 | slen--; |
| 674 | |
| 675 | switch (subtype) { |
| 676 | case MBO_ANQP_SUBTYPE_CELL_CONN_PREF: |
| 677 | if (slen < 1) |
| 678 | break; |
| 679 | wpa_msg(wpa_s, MSG_INFO, RX_MBO_ANQP MACSTR |
| 680 | " cell_conn_pref=%u", MAC2STR(sa), *pos); |
| 681 | break; |
| 682 | default: |
| 683 | wpa_printf(MSG_DEBUG, "MBO: Unsupported ANQP subtype %u", |
| 684 | subtype); |
| 685 | break; |
| 686 | } |
| 687 | } |