blob: 912f4c4a7d8e5bcef663065b4a857d47695ab176 [file] [log] [blame]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001/*
2 * wpa_supplicant - WNM
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07003 * Copyright (c) 2011-2013, Qualcomm Atheros, Inc.
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004 *
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 Shmidtfb45fd52015-01-05 13:08:17 -080013#include "common/ieee802_11_common.h"
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -070014#include "common/wpa_ctrl.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070015#include "rsn_supp/wpa.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070016#include "config.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080017#include "wpa_supplicant_i.h"
18#include "driver_i.h"
19#include "scan.h"
Dmitry Shmidt44c95782013-05-17 09:51:35 -070020#include "ctrl_iface.h"
21#include "bss.h"
22#include "wnm_sta.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080023#include "hs20_supplicant.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070024
25#define MAX_TFS_IE_LEN 1024
Dmitry Shmidt44c95782013-05-17 09:51:35 -070026#define WNM_MAX_NEIGHBOR_REPORT 10
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070027
Dmitry Shmidt849734c2016-05-27 09:59:01 -070028#define WNM_SCAN_RESULT_AGE 2 /* 2 seconds */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070029
30/* get the TFS IE from driver */
31static int ieee80211_11_get_tfs_ie(struct wpa_supplicant *wpa_s, u8 *buf,
32 u16 *buf_len, enum wnm_oper oper)
33{
34 wpa_printf(MSG_DEBUG, "%s: TFS get operation %d", __func__, oper);
35
36 return wpa_drv_wnm_oper(wpa_s, oper, wpa_s->bssid, buf, buf_len);
37}
38
39
40/* set the TFS IE to driver */
41static int ieee80211_11_set_tfs_ie(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080042 const u8 *addr, const u8 *buf, u16 buf_len,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070043 enum wnm_oper oper)
44{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080045 u16 len = buf_len;
46
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070047 wpa_printf(MSG_DEBUG, "%s: TFS set operation %d", __func__, oper);
48
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080049 return wpa_drv_wnm_oper(wpa_s, oper, addr, (u8 *) buf, &len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070050}
51
52
53/* MLME-SLEEPMODE.request */
54int ieee802_11_send_wnmsleep_req(struct wpa_supplicant *wpa_s,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080055 u8 action, u16 intval, struct wpabuf *tfs_req)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070056{
57 struct ieee80211_mgmt *mgmt;
58 int res;
59 size_t len;
60 struct wnm_sleep_element *wnmsleep_ie;
61 u8 *wnmtfs_ie;
62 u8 wnmsleep_ie_len;
63 u16 wnmtfs_ie_len; /* possibly multiple IE(s) */
64 enum wnm_oper tfs_oper = action == 0 ? WNM_SLEEP_TFS_REQ_IE_ADD :
65 WNM_SLEEP_TFS_REQ_IE_NONE;
66
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080067 wpa_printf(MSG_DEBUG, "WNM: Request to send WNM-Sleep Mode Request "
68 "action=%s to " MACSTR,
69 action == 0 ? "enter" : "exit",
70 MAC2STR(wpa_s->bssid));
71
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070072 /* WNM-Sleep Mode IE */
73 wnmsleep_ie_len = sizeof(struct wnm_sleep_element);
74 wnmsleep_ie = os_zalloc(sizeof(struct wnm_sleep_element));
75 if (wnmsleep_ie == NULL)
76 return -1;
77 wnmsleep_ie->eid = WLAN_EID_WNMSLEEP;
78 wnmsleep_ie->len = wnmsleep_ie_len - 2;
79 wnmsleep_ie->action_type = action;
80 wnmsleep_ie->status = WNM_STATUS_SLEEP_ACCEPT;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080081 wnmsleep_ie->intval = host_to_le16(intval);
82 wpa_hexdump(MSG_DEBUG, "WNM: WNM-Sleep Mode element",
83 (u8 *) wnmsleep_ie, wnmsleep_ie_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070084
85 /* TFS IE(s) */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080086 if (tfs_req) {
87 wnmtfs_ie_len = wpabuf_len(tfs_req);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070088 wnmtfs_ie = os_memdup(wpabuf_head(tfs_req), wnmtfs_ie_len);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080089 if (wnmtfs_ie == NULL) {
90 os_free(wnmsleep_ie);
91 return -1;
92 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080093 } else {
94 wnmtfs_ie = os_zalloc(MAX_TFS_IE_LEN);
95 if (wnmtfs_ie == NULL) {
96 os_free(wnmsleep_ie);
97 return -1;
98 }
99 if (ieee80211_11_get_tfs_ie(wpa_s, wnmtfs_ie, &wnmtfs_ie_len,
100 tfs_oper)) {
101 wnmtfs_ie_len = 0;
102 os_free(wnmtfs_ie);
103 wnmtfs_ie = NULL;
104 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700105 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800106 wpa_hexdump(MSG_DEBUG, "WNM: TFS Request element",
107 (u8 *) wnmtfs_ie, wnmtfs_ie_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700108
109 mgmt = os_zalloc(sizeof(*mgmt) + wnmsleep_ie_len + wnmtfs_ie_len);
110 if (mgmt == NULL) {
111 wpa_printf(MSG_DEBUG, "MLME: Failed to allocate buffer for "
112 "WNM-Sleep Request action frame");
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800113 os_free(wnmsleep_ie);
114 os_free(wnmtfs_ie);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700115 return -1;
116 }
117
118 os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
119 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
120 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
121 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
122 WLAN_FC_STYPE_ACTION);
123 mgmt->u.action.category = WLAN_ACTION_WNM;
124 mgmt->u.action.u.wnm_sleep_req.action = WNM_SLEEP_MODE_REQ;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800125 mgmt->u.action.u.wnm_sleep_req.dialogtoken = 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700126 os_memcpy(mgmt->u.action.u.wnm_sleep_req.variable, wnmsleep_ie,
127 wnmsleep_ie_len);
128 /* copy TFS IE here */
129 if (wnmtfs_ie_len > 0) {
130 os_memcpy(mgmt->u.action.u.wnm_sleep_req.variable +
131 wnmsleep_ie_len, wnmtfs_ie, wnmtfs_ie_len);
132 }
133
134 len = 1 + sizeof(mgmt->u.action.u.wnm_sleep_req) + wnmsleep_ie_len +
135 wnmtfs_ie_len;
136
137 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
138 wpa_s->own_addr, wpa_s->bssid,
139 &mgmt->u.action.category, len, 0);
140 if (res < 0)
141 wpa_printf(MSG_DEBUG, "Failed to send WNM-Sleep Request "
142 "(action=%d, intval=%d)", action, intval);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800143 else
144 wpa_s->wnmsleep_used = 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700145
146 os_free(wnmsleep_ie);
147 os_free(wnmtfs_ie);
148 os_free(mgmt);
149
150 return res;
151}
152
153
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800154static void wnm_sleep_mode_enter_success(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800155 const u8 *tfsresp_ie_start,
156 const u8 *tfsresp_ie_end)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800157{
158 wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_ENTER_CONFIRM,
159 wpa_s->bssid, NULL, NULL);
160 /* remove GTK/IGTK ?? */
161
162 /* set the TFS Resp IE(s) */
163 if (tfsresp_ie_start && tfsresp_ie_end &&
164 tfsresp_ie_end - tfsresp_ie_start >= 0) {
165 u16 tfsresp_ie_len;
166 tfsresp_ie_len = (tfsresp_ie_end + tfsresp_ie_end[1] + 2) -
167 tfsresp_ie_start;
168 wpa_printf(MSG_DEBUG, "TFS Resp IE(s) found");
169 /* pass the TFS Resp IE(s) to driver for processing */
170 if (ieee80211_11_set_tfs_ie(wpa_s, wpa_s->bssid,
171 tfsresp_ie_start,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800172 tfsresp_ie_len,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800173 WNM_SLEEP_TFS_RESP_IE_SET))
174 wpa_printf(MSG_DEBUG, "WNM: Fail to set TFS Resp IE");
175 }
176}
177
178
179static void wnm_sleep_mode_exit_success(struct wpa_supplicant *wpa_s,
180 const u8 *frm, u16 key_len_total)
181{
182 u8 *ptr, *end;
183 u8 gtk_len;
184
185 wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_EXIT_CONFIRM, wpa_s->bssid,
186 NULL, NULL);
187
188 /* Install GTK/IGTK */
189
190 /* point to key data field */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800191 ptr = (u8 *) frm + 1 + 2;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800192 end = ptr + key_len_total;
193 wpa_hexdump_key(MSG_DEBUG, "WNM: Key Data", ptr, key_len_total);
194
Jouni Malinen17de68d2015-11-09 15:25:41 -0800195 if (key_len_total && !wpa_sm_pmf_enabled(wpa_s->wpa)) {
196 wpa_msg(wpa_s, MSG_INFO,
197 "WNM: Ignore Key Data in WNM-Sleep Mode Response - PMF not enabled");
198 return;
199 }
200
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800201 while (end - ptr > 1) {
202 if (2 + ptr[1] > end - ptr) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800203 wpa_printf(MSG_DEBUG, "WNM: Invalid Key Data element "
204 "length");
205 if (end > ptr) {
206 wpa_hexdump(MSG_DEBUG, "WNM: Remaining data",
207 ptr, end - ptr);
208 }
209 break;
210 }
211 if (*ptr == WNM_SLEEP_SUBELEM_GTK) {
212 if (ptr[1] < 11 + 5) {
213 wpa_printf(MSG_DEBUG, "WNM: Too short GTK "
214 "subelem");
215 break;
216 }
217 gtk_len = *(ptr + 4);
218 if (ptr[1] < 11 + gtk_len ||
219 gtk_len < 5 || gtk_len > 32) {
220 wpa_printf(MSG_DEBUG, "WNM: Invalid GTK "
221 "subelem");
222 break;
223 }
224 wpa_wnmsleep_install_key(
225 wpa_s->wpa,
226 WNM_SLEEP_SUBELEM_GTK,
227 ptr);
228 ptr += 13 + gtk_len;
229#ifdef CONFIG_IEEE80211W
230 } else if (*ptr == WNM_SLEEP_SUBELEM_IGTK) {
231 if (ptr[1] < 2 + 6 + WPA_IGTK_LEN) {
232 wpa_printf(MSG_DEBUG, "WNM: Too short IGTK "
233 "subelem");
234 break;
235 }
236 wpa_wnmsleep_install_key(wpa_s->wpa,
237 WNM_SLEEP_SUBELEM_IGTK, ptr);
238 ptr += 10 + WPA_IGTK_LEN;
239#endif /* CONFIG_IEEE80211W */
240 } else
241 break; /* skip the loop */
242 }
243}
244
245
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700246static void ieee802_11_rx_wnmsleep_resp(struct wpa_supplicant *wpa_s,
247 const u8 *frm, int len)
248{
249 /*
Dmitry Shmidt21de2142014-04-08 10:50:52 -0700250 * Action [1] | Dialog Token [1] | Key Data Len [2] | Key Data |
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700251 * WNM-Sleep Mode IE | TFS Response IE
252 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800253 const u8 *pos = frm; /* point to payload after the action field */
Dmitry Shmidt21de2142014-04-08 10:50:52 -0700254 u16 key_len_total;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700255 struct wnm_sleep_element *wnmsleep_ie = NULL;
256 /* multiple TFS Resp IE (assuming consecutive) */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800257 const u8 *tfsresp_ie_start = NULL;
258 const u8 *tfsresp_ie_end = NULL;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800259 size_t left;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700260
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800261 if (!wpa_s->wnmsleep_used) {
262 wpa_printf(MSG_DEBUG,
Jouni Malinen90bfa452017-09-22 11:25:02 +0300263 "WNM: Ignore WNM-Sleep Mode Response frame since WNM-Sleep Mode operation has not been requested");
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800264 return;
265 }
266
Dmitry Shmidt21de2142014-04-08 10:50:52 -0700267 if (len < 3)
268 return;
269 key_len_total = WPA_GET_LE16(frm + 1);
270
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800271 wpa_printf(MSG_DEBUG, "WNM-Sleep Mode Response token=%u key_len_total=%d",
272 frm[0], key_len_total);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800273 left = len - 3;
274 if (key_len_total > left) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800275 wpa_printf(MSG_INFO, "WNM: Too short frame for Key Data field");
276 return;
277 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800278 pos += 3 + key_len_total;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800279 while (pos - frm + 1 < len) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700280 u8 ie_len = *(pos + 1);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800281 if (2 + ie_len > frm + len - pos) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800282 wpa_printf(MSG_INFO, "WNM: Invalid IE len %u", ie_len);
283 break;
284 }
285 wpa_hexdump(MSG_DEBUG, "WNM: Element", pos, 2 + ie_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800286 if (*pos == WLAN_EID_WNMSLEEP && ie_len >= 4)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700287 wnmsleep_ie = (struct wnm_sleep_element *) pos;
288 else if (*pos == WLAN_EID_TFS_RESP) {
289 if (!tfsresp_ie_start)
290 tfsresp_ie_start = pos;
291 tfsresp_ie_end = pos;
292 } else
293 wpa_printf(MSG_DEBUG, "EID %d not recognized", *pos);
294 pos += ie_len + 2;
295 }
296
297 if (!wnmsleep_ie) {
298 wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found");
299 return;
300 }
301
Jouni Malinen90bfa452017-09-22 11:25:02 +0300302 wpa_s->wnmsleep_used = 0;
303
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800304 if (wnmsleep_ie->status == WNM_STATUS_SLEEP_ACCEPT ||
305 wnmsleep_ie->status == WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700306 wpa_printf(MSG_DEBUG, "Successfully recv WNM-Sleep Response "
307 "frame (action=%d, intval=%d)",
308 wnmsleep_ie->action_type, wnmsleep_ie->intval);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800309 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER) {
310 wnm_sleep_mode_enter_success(wpa_s, tfsresp_ie_start,
311 tfsresp_ie_end);
312 } else if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) {
313 wnm_sleep_mode_exit_success(wpa_s, frm, key_len_total);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700314 }
315 } else {
316 wpa_printf(MSG_DEBUG, "Reject recv WNM-Sleep Response frame "
317 "(action=%d, intval=%d)",
318 wnmsleep_ie->action_type, wnmsleep_ie->intval);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800319 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700320 wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_ENTER_FAIL,
321 wpa_s->bssid, NULL, NULL);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800322 else if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700323 wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_EXIT_FAIL,
324 wpa_s->bssid, NULL, NULL);
325 }
326}
327
328
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700329void wnm_deallocate_memory(struct wpa_supplicant *wpa_s)
330{
331 int i;
332
333 for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700334 os_free(wpa_s->wnm_neighbor_report_elements[i].meas_pilot);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700335 os_free(wpa_s->wnm_neighbor_report_elements[i].mul_bssid);
336 }
337
Dmitry Shmidt21de2142014-04-08 10:50:52 -0700338 wpa_s->wnm_num_neighbor_report = 0;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700339 os_free(wpa_s->wnm_neighbor_report_elements);
340 wpa_s->wnm_neighbor_report_elements = NULL;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800341
342 wpabuf_free(wpa_s->coloc_intf_elems);
343 wpa_s->coloc_intf_elems = NULL;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700344}
345
346
347static void wnm_parse_neighbor_report_elem(struct neighbor_report *rep,
348 u8 id, u8 elen, const u8 *pos)
349{
350 switch (id) {
351 case WNM_NEIGHBOR_TSF:
352 if (elen < 2 + 2) {
353 wpa_printf(MSG_DEBUG, "WNM: Too short TSF");
354 break;
355 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800356 rep->tsf_offset = WPA_GET_LE16(pos);
357 rep->beacon_int = WPA_GET_LE16(pos + 2);
358 rep->tsf_present = 1;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700359 break;
360 case WNM_NEIGHBOR_CONDENSED_COUNTRY_STRING:
361 if (elen < 2) {
362 wpa_printf(MSG_DEBUG, "WNM: Too short condensed "
363 "country string");
364 break;
365 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800366 os_memcpy(rep->country, pos, 2);
367 rep->country_present = 1;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700368 break;
369 case WNM_NEIGHBOR_BSS_TRANSITION_CANDIDATE:
370 if (elen < 1) {
371 wpa_printf(MSG_DEBUG, "WNM: Too short BSS transition "
372 "candidate");
373 break;
374 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800375 rep->preference = pos[0];
376 rep->preference_present = 1;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700377 break;
378 case WNM_NEIGHBOR_BSS_TERMINATION_DURATION:
Hai Shalomcb95c3f2019-02-04 12:53:10 -0800379 if (elen < 10) {
380 wpa_printf(MSG_DEBUG, "WNM: Too short bss_term_tsf");
381 break;
382 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800383 rep->bss_term_tsf = WPA_GET_LE64(pos);
384 rep->bss_term_dur = WPA_GET_LE16(pos + 8);
385 rep->bss_term_present = 1;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700386 break;
387 case WNM_NEIGHBOR_BEARING:
388 if (elen < 8) {
389 wpa_printf(MSG_DEBUG, "WNM: Too short neighbor "
390 "bearing");
391 break;
392 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800393 rep->bearing = WPA_GET_LE16(pos);
394 rep->distance = WPA_GET_LE32(pos + 2);
395 rep->rel_height = WPA_GET_LE16(pos + 2 + 4);
396 rep->bearing_present = 1;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700397 break;
398 case WNM_NEIGHBOR_MEASUREMENT_PILOT:
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700399 if (elen < 1) {
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700400 wpa_printf(MSG_DEBUG, "WNM: Too short measurement "
401 "pilot");
402 break;
403 }
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700404 os_free(rep->meas_pilot);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700405 rep->meas_pilot = os_zalloc(sizeof(struct measurement_pilot));
406 if (rep->meas_pilot == NULL)
407 break;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700408 rep->meas_pilot->measurement_pilot = pos[0];
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700409 rep->meas_pilot->subelem_len = elen - 1;
410 os_memcpy(rep->meas_pilot->subelems, pos + 1, elen - 1);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700411 break;
412 case WNM_NEIGHBOR_RRM_ENABLED_CAPABILITIES:
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700413 if (elen < 5) {
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700414 wpa_printf(MSG_DEBUG, "WNM: Too short RRM enabled "
415 "capabilities");
416 break;
417 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800418 os_memcpy(rep->rm_capab, pos, 5);
419 rep->rm_capab_present = 1;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700420 break;
421 case WNM_NEIGHBOR_MULTIPLE_BSSID:
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700422 if (elen < 1) {
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700423 wpa_printf(MSG_DEBUG, "WNM: Too short multiple BSSID");
424 break;
425 }
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700426 os_free(rep->mul_bssid);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700427 rep->mul_bssid = os_zalloc(sizeof(struct multiple_bssid));
428 if (rep->mul_bssid == NULL)
429 break;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700430 rep->mul_bssid->max_bssid_indicator = pos[0];
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700431 rep->mul_bssid->subelem_len = elen - 1;
432 os_memcpy(rep->mul_bssid->subelems, pos + 1, elen - 1);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700433 break;
434 }
435}
436
437
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800438static int wnm_nei_get_chan(struct wpa_supplicant *wpa_s, u8 op_class, u8 chan)
439{
440 struct wpa_bss *bss = wpa_s->current_bss;
441 const char *country = NULL;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800442 int freq;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800443
444 if (bss) {
445 const u8 *elem = wpa_bss_get_ie(bss, WLAN_EID_COUNTRY);
446
447 if (elem && elem[1] >= 2)
448 country = (const char *) (elem + 2);
449 }
450
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800451 freq = ieee80211_chan_to_freq(country, op_class, chan);
452 if (freq <= 0 && op_class == 0) {
453 /*
454 * Some APs do not advertise correct operating class
455 * information. Try to determine the most likely operating
456 * frequency based on the channel number.
457 */
458 if (chan >= 1 && chan <= 13)
459 freq = 2407 + chan * 5;
460 else if (chan == 14)
461 freq = 2484;
462 else if (chan >= 36 && chan <= 169)
463 freq = 5000 + chan * 5;
464 }
465 return freq;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800466}
467
468
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700469static void wnm_parse_neighbor_report(struct wpa_supplicant *wpa_s,
470 const u8 *pos, u8 len,
471 struct neighbor_report *rep)
472{
473 u8 left = len;
474
475 if (left < 13) {
476 wpa_printf(MSG_DEBUG, "WNM: Too short neighbor report");
477 return;
478 }
479
480 os_memcpy(rep->bssid, pos, ETH_ALEN);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800481 rep->bssid_info = WPA_GET_LE32(pos + ETH_ALEN);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700482 rep->regulatory_class = *(pos + 10);
483 rep->channel_number = *(pos + 11);
484 rep->phy_type = *(pos + 12);
485
486 pos += 13;
487 left -= 13;
488
489 while (left >= 2) {
490 u8 id, elen;
491
492 id = *pos++;
493 elen = *pos++;
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700494 wpa_printf(MSG_DEBUG, "WNM: Subelement id=%u len=%u", id, elen);
495 left -= 2;
496 if (elen > left) {
497 wpa_printf(MSG_DEBUG,
498 "WNM: Truncated neighbor report subelement");
499 break;
500 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700501 wnm_parse_neighbor_report_elem(rep, id, elen, pos);
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700502 left -= elen;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700503 pos += elen;
504 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800505
506 rep->freq = wnm_nei_get_chan(wpa_s, rep->regulatory_class,
507 rep->channel_number);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700508}
509
510
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700511static void wnm_clear_acceptable(struct wpa_supplicant *wpa_s)
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700512{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700513 unsigned int i;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700514
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700515 for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++)
516 wpa_s->wnm_neighbor_report_elements[i].acceptable = 0;
517}
518
519
520static struct wpa_bss * get_first_acceptable(struct wpa_supplicant *wpa_s)
521{
522 unsigned int i;
523 struct neighbor_report *nei;
524
525 for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
526 nei = &wpa_s->wnm_neighbor_report_elements[i];
527 if (nei->acceptable)
528 return wpa_bss_get_bssid(wpa_s, nei->bssid);
529 }
530
531 return NULL;
532}
533
534
535#ifdef CONFIG_MBO
536static struct wpa_bss *
537get_mbo_transition_candidate(struct wpa_supplicant *wpa_s,
538 enum mbo_transition_reject_reason *reason)
539{
540 struct wpa_bss *target = NULL;
541 struct wpa_bss_trans_info params;
542 struct wpa_bss_candidate_info *info = NULL;
543 struct neighbor_report *nei = wpa_s->wnm_neighbor_report_elements;
544 u8 *first_candidate_bssid = NULL, *pos;
545 unsigned int i;
546
547 params.mbo_transition_reason = wpa_s->wnm_mbo_transition_reason;
548 params.n_candidates = 0;
549 params.bssid = os_calloc(wpa_s->wnm_num_neighbor_report, ETH_ALEN);
550 if (!params.bssid)
551 return NULL;
552
553 pos = params.bssid;
554 for (i = 0; i < wpa_s->wnm_num_neighbor_report; nei++, i++) {
555 if (nei->is_first)
556 first_candidate_bssid = nei->bssid;
557 if (!nei->acceptable)
558 continue;
559 os_memcpy(pos, nei->bssid, ETH_ALEN);
560 pos += ETH_ALEN;
561 params.n_candidates++;
562 }
563
564 if (!params.n_candidates)
565 goto end;
566
567 info = wpa_drv_get_bss_trans_status(wpa_s, &params);
568 if (!info) {
569 /* If failed to get candidate BSS transition status from driver,
570 * get the first acceptable candidate from wpa_supplicant.
571 */
572 target = wpa_bss_get_bssid(wpa_s, params.bssid);
573 goto end;
574 }
575
576 /* Get the first acceptable candidate from driver */
577 for (i = 0; i < info->num; i++) {
578 if (info->candidates[i].is_accept) {
579 target = wpa_bss_get_bssid(wpa_s,
580 info->candidates[i].bssid);
581 goto end;
582 }
583 }
584
585 /* If Disassociation Imminent is set and driver rejects all the
586 * candidate select first acceptable candidate which has
587 * rssi > disassoc_imminent_rssi_threshold
588 */
589 if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_DISASSOC_IMMINENT) {
590 for (i = 0; i < info->num; i++) {
591 target = wpa_bss_get_bssid(wpa_s,
592 info->candidates[i].bssid);
593 if (target &&
594 (target->level <
595 wpa_s->conf->disassoc_imminent_rssi_threshold))
596 continue;
597 goto end;
598 }
599 }
600
601 /* While sending BTM reject use reason code of the first candidate
602 * received in BTM request frame
603 */
604 if (reason) {
605 for (i = 0; i < info->num; i++) {
606 if (first_candidate_bssid &&
607 os_memcmp(first_candidate_bssid,
608 info->candidates[i].bssid, ETH_ALEN) == 0)
609 {
610 *reason = info->candidates[i].reject_reason;
611 break;
612 }
613 }
614 }
615
616 target = NULL;
617
618end:
619 os_free(params.bssid);
620 if (info) {
621 os_free(info->candidates);
622 os_free(info);
623 }
624 return target;
625}
626#endif /* CONFIG_MBO */
627
628
629static struct wpa_bss *
630compare_scan_neighbor_results(struct wpa_supplicant *wpa_s, os_time_t age_secs,
631 enum mbo_transition_reject_reason *reason)
632{
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800633 u8 i;
634 struct wpa_bss *bss = wpa_s->current_bss;
635 struct wpa_bss *target;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700636
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800637 if (!bss)
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -0700638 return NULL;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700639
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800640 wpa_printf(MSG_DEBUG, "WNM: Current BSS " MACSTR " RSSI %d",
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800641 MAC2STR(wpa_s->bssid), bss->level);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800642
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700643 wnm_clear_acceptable(wpa_s);
644
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800645 for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
646 struct neighbor_report *nei;
647
648 nei = &wpa_s->wnm_neighbor_report_elements[i];
649 if (nei->preference_present && nei->preference == 0) {
650 wpa_printf(MSG_DEBUG, "Skip excluded BSS " MACSTR,
651 MAC2STR(nei->bssid));
652 continue;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700653 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800654
655 target = wpa_bss_get_bssid(wpa_s, nei->bssid);
656 if (!target) {
657 wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR
658 " (pref %d) not found in scan results",
659 MAC2STR(nei->bssid),
660 nei->preference_present ? nei->preference :
661 -1);
662 continue;
663 }
664
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700665 if (age_secs) {
666 struct os_reltime now;
667
668 if (os_get_reltime(&now) == 0 &&
669 os_reltime_expired(&now, &target->last_update,
670 age_secs)) {
671 wpa_printf(MSG_DEBUG,
672 "Candidate BSS is more than %ld seconds old",
673 age_secs);
674 continue;
675 }
676 }
677
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800678 if (bss->ssid_len != target->ssid_len ||
679 os_memcmp(bss->ssid, target->ssid, bss->ssid_len) != 0) {
680 /*
681 * TODO: Could consider allowing transition to another
682 * ESS if PMF was enabled for the association.
683 */
684 wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR
685 " (pref %d) in different ESS",
686 MAC2STR(nei->bssid),
687 nei->preference_present ? nei->preference :
688 -1);
689 continue;
690 }
691
Dmitry Shmidte4663042016-04-04 10:07:49 -0700692 if (wpa_s->current_ssid &&
693 !wpa_scan_res_match(wpa_s, 0, target, wpa_s->current_ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800694 1, 0)) {
Dmitry Shmidte4663042016-04-04 10:07:49 -0700695 wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR
696 " (pref %d) does not match the current network profile",
697 MAC2STR(nei->bssid),
698 nei->preference_present ? nei->preference :
699 -1);
700 continue;
701 }
702
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800703 if (wpa_is_bss_tmp_disallowed(wpa_s, target->bssid)) {
704 wpa_printf(MSG_DEBUG,
705 "MBO: Candidate BSS " MACSTR
706 " retry delay is not over yet",
707 MAC2STR(nei->bssid));
708 continue;
709 }
710
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800711 if (target->level < bss->level && target->level < -80) {
712 wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR
713 " (pref %d) does not have sufficient signal level (%d)",
714 MAC2STR(nei->bssid),
715 nei->preference_present ? nei->preference :
716 -1,
717 target->level);
718 continue;
719 }
720
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700721 nei->acceptable = 1;
722 }
723
724#ifdef CONFIG_MBO
725 if (wpa_s->wnm_mbo_trans_reason_present)
726 target = get_mbo_transition_candidate(wpa_s, reason);
727 else
728 target = get_first_acceptable(wpa_s);
729#else /* CONFIG_MBO */
730 target = get_first_acceptable(wpa_s);
731#endif /* CONFIG_MBO */
732
733 if (target) {
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800734 wpa_printf(MSG_DEBUG,
735 "WNM: Found an acceptable preferred transition candidate BSS "
736 MACSTR " (RSSI %d)",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700737 MAC2STR(target->bssid), target->level);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700738 }
739
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700740 return target;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700741}
742
743
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800744static int wpa_bss_ies_eq(struct wpa_bss *a, struct wpa_bss *b, u8 eid)
745{
746 const u8 *ie_a, *ie_b;
747
748 if (!a || !b)
749 return 0;
750
751 ie_a = wpa_bss_get_ie(a, eid);
752 ie_b = wpa_bss_get_ie(b, eid);
753
754 if (!ie_a || !ie_b || ie_a[1] != ie_b[1])
755 return 0;
756
757 return os_memcmp(ie_a, ie_b, ie_a[1]) == 0;
758}
759
760
761static u32 wnm_get_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
762{
763 u32 info = 0;
764
765 info |= NEI_REP_BSSID_INFO_AP_UNKNOWN_REACH;
766
767 /*
768 * Leave the security and key scope bits unset to indicate that the
769 * security information is not available.
770 */
771
772 if (bss->caps & WLAN_CAPABILITY_SPECTRUM_MGMT)
773 info |= NEI_REP_BSSID_INFO_SPECTRUM_MGMT;
774 if (bss->caps & WLAN_CAPABILITY_QOS)
775 info |= NEI_REP_BSSID_INFO_QOS;
776 if (bss->caps & WLAN_CAPABILITY_APSD)
777 info |= NEI_REP_BSSID_INFO_APSD;
778 if (bss->caps & WLAN_CAPABILITY_RADIO_MEASUREMENT)
779 info |= NEI_REP_BSSID_INFO_RM;
780 if (bss->caps & WLAN_CAPABILITY_DELAYED_BLOCK_ACK)
781 info |= NEI_REP_BSSID_INFO_DELAYED_BA;
782 if (bss->caps & WLAN_CAPABILITY_IMM_BLOCK_ACK)
783 info |= NEI_REP_BSSID_INFO_IMM_BA;
784 if (wpa_bss_ies_eq(bss, wpa_s->current_bss, WLAN_EID_MOBILITY_DOMAIN))
785 info |= NEI_REP_BSSID_INFO_MOBILITY_DOMAIN;
786 if (wpa_bss_ies_eq(bss, wpa_s->current_bss, WLAN_EID_HT_CAP))
787 info |= NEI_REP_BSSID_INFO_HT;
788
789 return info;
790}
791
792
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700793static int wnm_add_nei_rep(struct wpabuf **buf, const u8 *bssid,
794 u32 bss_info, u8 op_class, u8 chan, u8 phy_type,
795 u8 pref)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800796{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700797 if (wpabuf_len(*buf) + 18 >
798 IEEE80211_MAX_MMPDU_SIZE - IEEE80211_HDRLEN) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800799 wpa_printf(MSG_DEBUG,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700800 "WNM: No room in frame for Neighbor Report element");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800801 return -1;
802 }
803
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700804 if (wpabuf_resize(buf, 18) < 0) {
805 wpa_printf(MSG_DEBUG,
806 "WNM: Failed to allocate memory for Neighbor Report element");
807 return -1;
808 }
809
810 wpabuf_put_u8(*buf, WLAN_EID_NEIGHBOR_REPORT);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800811 /* length: 13 for basic neighbor report + 3 for preference subelement */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700812 wpabuf_put_u8(*buf, 16);
813 wpabuf_put_data(*buf, bssid, ETH_ALEN);
814 wpabuf_put_le32(*buf, bss_info);
815 wpabuf_put_u8(*buf, op_class);
816 wpabuf_put_u8(*buf, chan);
817 wpabuf_put_u8(*buf, phy_type);
818 wpabuf_put_u8(*buf, WNM_NEIGHBOR_BSS_TRANSITION_CANDIDATE);
819 wpabuf_put_u8(*buf, 1);
820 wpabuf_put_u8(*buf, pref);
821 return 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800822}
823
824
825static int wnm_nei_rep_add_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700826 struct wpa_bss *bss, struct wpabuf **buf,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800827 u8 pref)
828{
829 const u8 *ie;
830 u8 op_class, chan;
831 int sec_chan = 0, vht = 0;
832 enum phy_type phy_type;
833 u32 info;
834 struct ieee80211_ht_operation *ht_oper = NULL;
835 struct ieee80211_vht_operation *vht_oper = NULL;
836
837 ie = wpa_bss_get_ie(bss, WLAN_EID_HT_OPERATION);
838 if (ie && ie[1] >= 2) {
839 ht_oper = (struct ieee80211_ht_operation *) (ie + 2);
840
841 if (ht_oper->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
842 sec_chan = 1;
843 else if (ht_oper->ht_param &
844 HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
845 sec_chan = -1;
846 }
847
848 ie = wpa_bss_get_ie(bss, WLAN_EID_VHT_OPERATION);
849 if (ie && ie[1] >= 1) {
850 vht_oper = (struct ieee80211_vht_operation *) (ie + 2);
851
852 if (vht_oper->vht_op_info_chwidth == VHT_CHANWIDTH_80MHZ ||
853 vht_oper->vht_op_info_chwidth == VHT_CHANWIDTH_160MHZ ||
854 vht_oper->vht_op_info_chwidth == VHT_CHANWIDTH_80P80MHZ)
855 vht = vht_oper->vht_op_info_chwidth;
856 }
857
858 if (ieee80211_freq_to_channel_ext(bss->freq, sec_chan, vht, &op_class,
859 &chan) == NUM_HOSTAPD_MODES) {
860 wpa_printf(MSG_DEBUG,
861 "WNM: Cannot determine operating class and channel");
862 return -2;
863 }
864
865 phy_type = ieee80211_get_phy_type(bss->freq, (ht_oper != NULL),
866 (vht_oper != NULL));
867 if (phy_type == PHY_TYPE_UNSPECIFIED) {
868 wpa_printf(MSG_DEBUG,
869 "WNM: Cannot determine BSS phy type for Neighbor Report");
870 return -2;
871 }
872
873 info = wnm_get_bss_info(wpa_s, bss);
874
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700875 return wnm_add_nei_rep(buf, bss->bssid, info, op_class, chan, phy_type,
876 pref);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800877}
878
879
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700880static void wnm_add_cand_list(struct wpa_supplicant *wpa_s, struct wpabuf **buf)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800881{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800882 unsigned int i, pref = 255;
883 struct os_reltime now;
884 struct wpa_ssid *ssid = wpa_s->current_ssid;
885
886 if (!ssid)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700887 return;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800888
889 /*
890 * TODO: Define when scan results are no longer valid for the candidate
891 * list.
892 */
893 os_get_reltime(&now);
894 if (os_reltime_expired(&now, &wpa_s->last_scan, 10))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700895 return;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800896
897 wpa_printf(MSG_DEBUG,
898 "WNM: Add candidate list to BSS Transition Management Response frame");
899 for (i = 0; i < wpa_s->last_scan_res_used && pref; i++) {
900 struct wpa_bss *bss = wpa_s->last_scan_res[i];
901 int res;
902
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800903 if (wpa_scan_res_match(wpa_s, i, bss, ssid, 1, 0)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700904 res = wnm_nei_rep_add_bss(wpa_s, bss, buf, pref--);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800905 if (res == -2)
906 continue; /* could not build entry for BSS */
907 if (res < 0)
908 break; /* no more room for candidates */
909 if (pref == 1)
910 break;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800911 }
912 }
913
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700914 wpa_hexdump_buf(MSG_DEBUG,
915 "WNM: BSS Transition Management Response candidate list",
916 *buf);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800917}
918
919
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700920#define BTM_RESP_MIN_SIZE 5 + ETH_ALEN
921
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -0700922static void wnm_send_bss_transition_mgmt_resp(
923 struct wpa_supplicant *wpa_s, u8 dialog_token,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700924 enum bss_trans_mgmt_status_code status,
925 enum mbo_transition_reject_reason reason,
926 u8 delay, const u8 *target_bssid)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800927{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700928 struct wpabuf *buf;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800929 int res;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800930
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700931 wpa_printf(MSG_DEBUG,
932 "WNM: Send BSS Transition Management Response to " MACSTR
933 " dialog_token=%u status=%u reason=%u delay=%d",
934 MAC2STR(wpa_s->bssid), dialog_token, status, reason, delay);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800935 if (!wpa_s->current_bss) {
936 wpa_printf(MSG_DEBUG,
937 "WNM: Current BSS not known - drop response");
938 return;
939 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800940
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700941 buf = wpabuf_alloc(BTM_RESP_MIN_SIZE);
942 if (!buf) {
943 wpa_printf(MSG_DEBUG,
944 "WNM: Failed to allocate memory for BTM response");
945 return;
946 }
947
948 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
949 wpabuf_put_u8(buf, WNM_BSS_TRANS_MGMT_RESP);
950 wpabuf_put_u8(buf, dialog_token);
951 wpabuf_put_u8(buf, status);
952 wpabuf_put_u8(buf, delay);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800953 if (target_bssid) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700954 wpabuf_put_data(buf, target_bssid, ETH_ALEN);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800955 } else if (status == WNM_BSS_TM_ACCEPT) {
956 /*
957 * P802.11-REVmc clarifies that the Target BSSID field is always
958 * present when status code is zero, so use a fake value here if
959 * no BSSID is yet known.
960 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700961 wpabuf_put_data(buf, "\0\0\0\0\0\0", ETH_ALEN);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800962 }
963
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800964 if (status == WNM_BSS_TM_ACCEPT)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700965 wnm_add_cand_list(wpa_s, &buf);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800966
967#ifdef CONFIG_MBO
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700968 if (status != WNM_BSS_TM_ACCEPT &&
969 wpa_bss_get_vendor_ie(wpa_s->current_bss, MBO_IE_VENDOR_TYPE)) {
970 u8 mbo[10];
971 size_t ret;
972
973 ret = wpas_mbo_ie_bss_trans_reject(wpa_s, mbo, sizeof(mbo),
974 reason);
975 if (ret) {
976 if (wpabuf_resize(&buf, ret) < 0) {
977 wpabuf_free(buf);
978 wpa_printf(MSG_DEBUG,
979 "WNM: Failed to allocate memory for MBO IE");
980 return;
981 }
982
983 wpabuf_put_data(buf, mbo, ret);
984 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800985 }
986#endif /* CONFIG_MBO */
987
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800988 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
989 wpa_s->own_addr, wpa_s->bssid,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700990 wpabuf_head_u8(buf), wpabuf_len(buf), 0);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800991 if (res < 0) {
992 wpa_printf(MSG_DEBUG,
993 "WNM: Failed to send BSS Transition Management Response");
994 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700995
996 wpabuf_free(buf);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800997}
998
999
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001000static void wnm_bss_tm_connect(struct wpa_supplicant *wpa_s,
1001 struct wpa_bss *bss, struct wpa_ssid *ssid,
1002 int after_new_scan)
1003{
1004 wpa_dbg(wpa_s, MSG_DEBUG,
1005 "WNM: Transition to BSS " MACSTR
1006 " based on BSS Transition Management Request (old BSSID "
1007 MACSTR " after_new_scan=%d)",
1008 MAC2STR(bss->bssid), MAC2STR(wpa_s->bssid), after_new_scan);
1009
1010 /* Send the BSS Management Response - Accept */
1011 if (wpa_s->wnm_reply) {
1012 wpa_s->wnm_reply = 0;
1013 wpa_printf(MSG_DEBUG,
1014 "WNM: Sending successful BSS Transition Management Response");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001015 wnm_send_bss_transition_mgmt_resp(
1016 wpa_s, wpa_s->wnm_dialog_token, WNM_BSS_TM_ACCEPT,
1017 MBO_TRANSITION_REJECT_REASON_UNSPECIFIED, 0,
1018 bss->bssid);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001019 }
1020
1021 if (bss == wpa_s->current_bss) {
1022 wpa_printf(MSG_DEBUG,
1023 "WNM: Already associated with the preferred candidate");
1024 wnm_deallocate_memory(wpa_s);
1025 return;
1026 }
1027
1028 wpa_s->reassociate = 1;
1029 wpa_printf(MSG_DEBUG, "WNM: Issuing connect");
1030 wpa_supplicant_connect(wpa_s, bss, ssid);
1031 wnm_deallocate_memory(wpa_s);
1032}
1033
1034
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001035int wnm_scan_process(struct wpa_supplicant *wpa_s, int reply_on_fail)
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001036{
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001037 struct wpa_bss *bss;
1038 struct wpa_ssid *ssid = wpa_s->current_ssid;
1039 enum bss_trans_mgmt_status_code status = WNM_BSS_TM_REJECT_UNSPECIFIED;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001040 enum mbo_transition_reject_reason reason =
1041 MBO_TRANSITION_REJECT_REASON_UNSPECIFIED;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001042
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001043 if (!wpa_s->wnm_neighbor_report_elements)
1044 return 0;
1045
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001046 wpa_dbg(wpa_s, MSG_DEBUG,
1047 "WNM: Process scan results for BSS Transition Management");
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001048 if (os_reltime_before(&wpa_s->wnm_cand_valid_until,
1049 &wpa_s->scan_trigger_time)) {
1050 wpa_printf(MSG_DEBUG, "WNM: Previously stored BSS transition candidate list is not valid anymore - drop it");
1051 wnm_deallocate_memory(wpa_s);
1052 return 0;
1053 }
1054
1055 if (!wpa_s->current_bss ||
1056 os_memcmp(wpa_s->wnm_cand_from_bss, wpa_s->current_bss->bssid,
1057 ETH_ALEN) != 0) {
1058 wpa_printf(MSG_DEBUG, "WNM: Stored BSS transition candidate list not from the current BSS - ignore it");
1059 return 0;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001060 }
1061
1062 /* Compare the Neighbor Report and scan results */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001063 bss = compare_scan_neighbor_results(wpa_s, 0, &reason);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001064 if (!bss) {
1065 wpa_printf(MSG_DEBUG, "WNM: No BSS transition candidate match found");
1066 status = WNM_BSS_TM_REJECT_NO_SUITABLE_CANDIDATES;
1067 goto send_bss_resp_fail;
1068 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001069
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001070 /* Associate to the network */
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001071 wnm_bss_tm_connect(wpa_s, bss, ssid, 1);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001072 return 1;
1073
1074send_bss_resp_fail:
1075 if (!reply_on_fail)
1076 return 0;
1077
1078 /* Send reject response for all the failures */
1079
1080 if (wpa_s->wnm_reply) {
1081 wpa_s->wnm_reply = 0;
1082 wnm_send_bss_transition_mgmt_resp(wpa_s,
1083 wpa_s->wnm_dialog_token,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001084 status, reason, 0, NULL);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001085 }
1086 wnm_deallocate_memory(wpa_s);
1087
1088 return 0;
1089}
1090
1091
1092static int cand_pref_compar(const void *a, const void *b)
1093{
1094 const struct neighbor_report *aa = a;
1095 const struct neighbor_report *bb = b;
1096
1097 if (!aa->preference_present && !bb->preference_present)
1098 return 0;
1099 if (!aa->preference_present)
1100 return 1;
1101 if (!bb->preference_present)
1102 return -1;
1103 if (bb->preference > aa->preference)
1104 return 1;
1105 if (bb->preference < aa->preference)
1106 return -1;
1107 return 0;
1108}
1109
1110
1111static void wnm_sort_cand_list(struct wpa_supplicant *wpa_s)
1112{
1113 if (!wpa_s->wnm_neighbor_report_elements)
1114 return;
1115 qsort(wpa_s->wnm_neighbor_report_elements,
1116 wpa_s->wnm_num_neighbor_report, sizeof(struct neighbor_report),
1117 cand_pref_compar);
1118}
1119
1120
1121static void wnm_dump_cand_list(struct wpa_supplicant *wpa_s)
1122{
1123 unsigned int i;
1124
1125 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Candidate List");
1126 if (!wpa_s->wnm_neighbor_report_elements)
1127 return;
1128 for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
1129 struct neighbor_report *nei;
1130
1131 nei = &wpa_s->wnm_neighbor_report_elements[i];
1132 wpa_printf(MSG_DEBUG, "%u: " MACSTR
1133 " info=0x%x op_class=%u chan=%u phy=%u pref=%d freq=%d",
1134 i, MAC2STR(nei->bssid), nei->bssid_info,
1135 nei->regulatory_class,
1136 nei->channel_number, nei->phy_type,
1137 nei->preference_present ? nei->preference : -1,
1138 nei->freq);
1139 }
1140}
1141
1142
1143static int chan_supported(struct wpa_supplicant *wpa_s, int freq)
1144{
1145 unsigned int i;
1146
1147 for (i = 0; i < wpa_s->hw.num_modes; i++) {
1148 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
1149 int j;
1150
1151 for (j = 0; j < mode->num_channels; j++) {
1152 struct hostapd_channel_data *chan;
1153
1154 chan = &mode->channels[j];
1155 if (chan->freq == freq &&
1156 !(chan->flag & HOSTAPD_CHAN_DISABLED))
1157 return 1;
1158 }
1159 }
1160
1161 return 0;
1162}
1163
1164
1165static void wnm_set_scan_freqs(struct wpa_supplicant *wpa_s)
1166{
1167 int *freqs;
1168 int num_freqs = 0;
1169 unsigned int i;
1170
1171 if (!wpa_s->wnm_neighbor_report_elements)
1172 return;
1173
1174 if (wpa_s->hw.modes == NULL)
1175 return;
1176
1177 os_free(wpa_s->next_scan_freqs);
1178 wpa_s->next_scan_freqs = NULL;
1179
1180 freqs = os_calloc(wpa_s->wnm_num_neighbor_report + 1, sizeof(int));
1181 if (freqs == NULL)
1182 return;
1183
1184 for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
1185 struct neighbor_report *nei;
1186
1187 nei = &wpa_s->wnm_neighbor_report_elements[i];
1188 if (nei->freq <= 0) {
1189 wpa_printf(MSG_DEBUG,
1190 "WNM: Unknown neighbor operating frequency for "
1191 MACSTR " - scan all channels",
1192 MAC2STR(nei->bssid));
1193 os_free(freqs);
1194 return;
1195 }
1196 if (chan_supported(wpa_s, nei->freq))
1197 add_freq(freqs, &num_freqs, nei->freq);
1198 }
1199
1200 if (num_freqs == 0) {
1201 os_free(freqs);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001202 return;
1203 }
1204
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001205 wpa_printf(MSG_DEBUG,
1206 "WNM: Scan %d frequencies based on transition candidate list",
1207 num_freqs);
1208 wpa_s->next_scan_freqs = freqs;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001209}
1210
1211
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001212static int wnm_fetch_scan_results(struct wpa_supplicant *wpa_s)
1213{
1214 struct wpa_scan_results *scan_res;
1215 struct wpa_bss *bss;
1216 struct wpa_ssid *ssid = wpa_s->current_ssid;
1217 u8 i, found = 0;
1218 size_t j;
1219
1220 wpa_dbg(wpa_s, MSG_DEBUG,
1221 "WNM: Fetch current scan results from the driver for checking transition candidates");
1222 scan_res = wpa_drv_get_scan_results2(wpa_s);
1223 if (!scan_res) {
1224 wpa_dbg(wpa_s, MSG_DEBUG, "WNM: Failed to get scan results");
1225 return 0;
1226 }
1227
1228 if (scan_res->fetch_time.sec == 0)
1229 os_get_reltime(&scan_res->fetch_time);
1230
1231 filter_scan_res(wpa_s, scan_res);
1232
1233 for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
1234 struct neighbor_report *nei;
1235
1236 nei = &wpa_s->wnm_neighbor_report_elements[i];
1237 if (nei->preference_present && nei->preference == 0)
1238 continue;
1239
1240 for (j = 0; j < scan_res->num; j++) {
1241 struct wpa_scan_res *res;
1242 const u8 *ssid_ie;
1243
1244 res = scan_res->res[j];
1245 if (os_memcmp(nei->bssid, res->bssid, ETH_ALEN) != 0 ||
1246 res->age > WNM_SCAN_RESULT_AGE * 1000)
1247 continue;
1248 bss = wpa_s->current_bss;
1249 ssid_ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
1250 if (bss && ssid_ie &&
1251 (bss->ssid_len != ssid_ie[1] ||
1252 os_memcmp(bss->ssid, ssid_ie + 2,
1253 bss->ssid_len) != 0))
1254 continue;
1255
1256 /* Potential candidate found */
1257 found = 1;
1258 scan_snr(res);
1259 scan_est_throughput(wpa_s, res);
1260 wpa_bss_update_scan_res(wpa_s, res,
1261 &scan_res->fetch_time);
1262 }
1263 }
1264
1265 wpa_scan_results_free(scan_res);
1266 if (!found) {
1267 wpa_dbg(wpa_s, MSG_DEBUG,
1268 "WNM: No transition candidate matches existing scan results");
1269 return 0;
1270 }
1271
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001272 bss = compare_scan_neighbor_results(wpa_s, WNM_SCAN_RESULT_AGE, NULL);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001273 if (!bss) {
1274 wpa_dbg(wpa_s, MSG_DEBUG,
1275 "WNM: Comparison of scan results against transition candidates did not find matches");
1276 return 0;
1277 }
1278
1279 /* Associate to the network */
1280 wnm_bss_tm_connect(wpa_s, bss, ssid, 0);
1281 return 1;
1282}
1283
1284
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001285static void ieee802_11_rx_bss_trans_mgmt_req(struct wpa_supplicant *wpa_s,
1286 const u8 *pos, const u8 *end,
1287 int reply)
1288{
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001289 unsigned int beacon_int;
1290 u8 valid_int;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001291#ifdef CONFIG_MBO
1292 const u8 *vendor;
1293#endif /* CONFIG_MBO */
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001294
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001295 if (end - pos < 5)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001296 return;
1297
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001298#ifdef CONFIG_MBO
1299 wpa_s->wnm_mbo_trans_reason_present = 0;
1300 wpa_s->wnm_mbo_transition_reason = 0;
1301#endif /* CONFIG_MBO */
1302
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001303 if (wpa_s->current_bss)
1304 beacon_int = wpa_s->current_bss->beacon_int;
1305 else
1306 beacon_int = 100; /* best guess */
1307
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001308 wpa_s->wnm_dialog_token = pos[0];
1309 wpa_s->wnm_mode = pos[1];
1310 wpa_s->wnm_dissoc_timer = WPA_GET_LE16(pos + 2);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001311 valid_int = pos[4];
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001312 wpa_s->wnm_reply = reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001313
1314 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Request: "
1315 "dialog_token=%u request_mode=0x%x "
1316 "disassoc_timer=%u validity_interval=%u",
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001317 wpa_s->wnm_dialog_token, wpa_s->wnm_mode,
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001318 wpa_s->wnm_dissoc_timer, valid_int);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001319
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001320#if defined(CONFIG_MBO) && defined(CONFIG_TESTING_OPTIONS)
1321 if (wpa_s->reject_btm_req_reason) {
1322 wpa_printf(MSG_INFO,
1323 "WNM: Testing - reject BSS Transition Management Request: reject_btm_req_reason=%d",
1324 wpa_s->reject_btm_req_reason);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001325 wnm_send_bss_transition_mgmt_resp(
1326 wpa_s, wpa_s->wnm_dialog_token,
1327 wpa_s->reject_btm_req_reason,
1328 MBO_TRANSITION_REJECT_REASON_UNSPECIFIED, 0, NULL);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001329 return;
1330 }
1331#endif /* CONFIG_MBO && CONFIG_TESTING_OPTIONS */
1332
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001333 pos += 5;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001334
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001335 if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001336 if (end - pos < 12) {
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001337 wpa_printf(MSG_DEBUG, "WNM: Too short BSS TM Request");
1338 return;
1339 }
1340 os_memcpy(wpa_s->wnm_bss_termination_duration, pos, 12);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001341 pos += 12; /* BSS Termination Duration */
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001342 }
1343
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001344 if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001345 char url[256];
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001346
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001347 if (end - pos < 1 || 1 + pos[0] > end - pos) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001348 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS Transition "
1349 "Management Request (URL)");
1350 return;
1351 }
1352 os_memcpy(url, pos + 1, pos[0]);
1353 url[pos[0]] = '\0';
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001354 pos += 1 + pos[0];
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001355
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001356 wpa_msg(wpa_s, MSG_INFO, ESS_DISASSOC_IMMINENT "%d %u %s",
1357 wpa_sm_pmf_enabled(wpa_s->wpa),
1358 wpa_s->wnm_dissoc_timer * beacon_int * 128 / 125, url);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001359 }
1360
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001361 if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_DISASSOC_IMMINENT) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001362 wpa_msg(wpa_s, MSG_INFO, "WNM: Disassociation Imminent - "
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001363 "Disassociation Timer %u", wpa_s->wnm_dissoc_timer);
1364 if (wpa_s->wnm_dissoc_timer && !wpa_s->scanning) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001365 /* TODO: mark current BSS less preferred for
1366 * selection */
1367 wpa_printf(MSG_DEBUG, "Trying to find another BSS");
1368 wpa_supplicant_req_scan(wpa_s, 0, 0);
1369 }
1370 }
1371
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001372#ifdef CONFIG_MBO
1373 vendor = get_ie(pos, end - pos, WLAN_EID_VENDOR_SPECIFIC);
1374 if (vendor)
1375 wpas_mbo_ie_trans_req(wpa_s, vendor + 2, vendor[1]);
1376#endif /* CONFIG_MBO */
1377
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001378 if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED) {
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001379 unsigned int valid_ms;
1380
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001381 wpa_msg(wpa_s, MSG_INFO, "WNM: Preferred List Available");
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001382 wnm_deallocate_memory(wpa_s);
1383 wpa_s->wnm_neighbor_report_elements = os_calloc(
1384 WNM_MAX_NEIGHBOR_REPORT,
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001385 sizeof(struct neighbor_report));
1386 if (wpa_s->wnm_neighbor_report_elements == NULL)
1387 return;
1388
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001389 while (end - pos >= 2 &&
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001390 wpa_s->wnm_num_neighbor_report < WNM_MAX_NEIGHBOR_REPORT)
1391 {
1392 u8 tag = *pos++;
1393 u8 len = *pos++;
1394
1395 wpa_printf(MSG_DEBUG, "WNM: Neighbor report tag %u",
1396 tag);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001397 if (len > end - pos) {
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001398 wpa_printf(MSG_DEBUG, "WNM: Truncated request");
1399 return;
1400 }
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -07001401 if (tag == WLAN_EID_NEIGHBOR_REPORT) {
1402 struct neighbor_report *rep;
1403 rep = &wpa_s->wnm_neighbor_report_elements[
1404 wpa_s->wnm_num_neighbor_report];
1405 wnm_parse_neighbor_report(wpa_s, pos, len, rep);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001406 wpa_s->wnm_num_neighbor_report++;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001407#ifdef CONFIG_MBO
1408 if (wpa_s->wnm_mbo_trans_reason_present &&
1409 wpa_s->wnm_num_neighbor_report == 1) {
1410 rep->is_first = 1;
1411 wpa_printf(MSG_DEBUG,
1412 "WNM: First transition candidate is "
1413 MACSTR, MAC2STR(rep->bssid));
1414 }
1415#endif /* CONFIG_MBO */
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -07001416 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001417
1418 pos += len;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001419 }
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001420
1421 if (!wpa_s->wnm_num_neighbor_report) {
1422 wpa_printf(MSG_DEBUG,
1423 "WNM: Candidate list included bit is set, but no candidates found");
1424 wnm_send_bss_transition_mgmt_resp(
1425 wpa_s, wpa_s->wnm_dialog_token,
1426 WNM_BSS_TM_REJECT_NO_SUITABLE_CANDIDATES,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001427 MBO_TRANSITION_REJECT_REASON_UNSPECIFIED, 0,
1428 NULL);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001429 return;
1430 }
1431
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001432 wnm_sort_cand_list(wpa_s);
1433 wnm_dump_cand_list(wpa_s);
1434 valid_ms = valid_int * beacon_int * 128 / 125;
1435 wpa_printf(MSG_DEBUG, "WNM: Candidate list valid for %u ms",
1436 valid_ms);
1437 os_get_reltime(&wpa_s->wnm_cand_valid_until);
1438 wpa_s->wnm_cand_valid_until.sec += valid_ms / 1000;
1439 wpa_s->wnm_cand_valid_until.usec += (valid_ms % 1000) * 1000;
1440 wpa_s->wnm_cand_valid_until.sec +=
1441 wpa_s->wnm_cand_valid_until.usec / 1000000;
1442 wpa_s->wnm_cand_valid_until.usec %= 1000000;
1443 os_memcpy(wpa_s->wnm_cand_from_bss, wpa_s->bssid, ETH_ALEN);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001444
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001445 /*
1446 * Fetch the latest scan results from the kernel and check for
1447 * candidates based on those results first. This can help in
1448 * finding more up-to-date information should the driver has
1449 * done some internal scanning operations after the last scan
1450 * result update in wpa_supplicant.
1451 */
1452 if (wnm_fetch_scan_results(wpa_s) > 0)
1453 return;
1454
1455 /*
1456 * Try to use previously received scan results, if they are
1457 * recent enough to use for a connection.
1458 */
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001459 if (wpa_s->last_scan_res_used > 0) {
1460 struct os_reltime now;
1461
1462 os_get_reltime(&now);
1463 if (!os_reltime_expired(&now, &wpa_s->last_scan, 10)) {
1464 wpa_printf(MSG_DEBUG,
1465 "WNM: Try to use recent scan results");
1466 if (wnm_scan_process(wpa_s, 0) > 0)
1467 return;
1468 wpa_printf(MSG_DEBUG,
1469 "WNM: No match in previous scan results - try a new scan");
1470 }
1471 }
1472
1473 wnm_set_scan_freqs(wpa_s);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001474 if (wpa_s->wnm_num_neighbor_report == 1) {
1475 os_memcpy(wpa_s->next_scan_bssid,
1476 wpa_s->wnm_neighbor_report_elements[0].bssid,
1477 ETH_ALEN);
1478 wpa_printf(MSG_DEBUG,
1479 "WNM: Scan only for a specific BSSID since there is only a single candidate "
1480 MACSTR, MAC2STR(wpa_s->next_scan_bssid));
1481 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001482 wpa_supplicant_req_scan(wpa_s, 0, 0);
1483 } else if (reply) {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001484 enum bss_trans_mgmt_status_code status;
1485 if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT)
1486 status = WNM_BSS_TM_ACCEPT;
1487 else {
1488 wpa_msg(wpa_s, MSG_INFO, "WNM: BSS Transition Management Request did not include candidates");
1489 status = WNM_BSS_TM_REJECT_UNSPECIFIED;
1490 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001491 wnm_send_bss_transition_mgmt_resp(
1492 wpa_s, wpa_s->wnm_dialog_token, status,
1493 MBO_TRANSITION_REJECT_REASON_UNSPECIFIED, 0, NULL);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001494 }
1495}
1496
1497
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001498#define BTM_QUERY_MIN_SIZE 4
1499
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001500int wnm_send_bss_transition_mgmt_query(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001501 u8 query_reason,
1502 const char *btm_candidates,
1503 int cand_list)
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001504{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001505 struct wpabuf *buf;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001506 int ret;
1507
1508 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Query to "
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001509 MACSTR " query_reason=%u%s",
1510 MAC2STR(wpa_s->bssid), query_reason,
1511 cand_list ? " candidate list" : "");
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001512
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001513 buf = wpabuf_alloc(BTM_QUERY_MIN_SIZE);
1514 if (!buf)
1515 return -1;
1516
1517 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
1518 wpabuf_put_u8(buf, WNM_BSS_TRANS_MGMT_QUERY);
1519 wpabuf_put_u8(buf, 1);
1520 wpabuf_put_u8(buf, query_reason);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001521
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001522 if (cand_list)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001523 wnm_add_cand_list(wpa_s, &buf);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001524
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001525 if (btm_candidates) {
1526 const size_t max_len = 1000;
1527
1528 ret = wpabuf_resize(&buf, max_len);
1529 if (ret < 0) {
1530 wpabuf_free(buf);
1531 return ret;
1532 }
1533
1534 ret = ieee802_11_parse_candidate_list(btm_candidates,
1535 wpabuf_put(buf, 0),
1536 max_len);
1537 if (ret < 0) {
1538 wpabuf_free(buf);
1539 return ret;
1540 }
1541
1542 wpabuf_put(buf, ret);
1543 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001544
1545 ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
1546 wpa_s->own_addr, wpa_s->bssid,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001547 wpabuf_head_u8(buf), wpabuf_len(buf), 0);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001548
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001549 wpabuf_free(buf);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001550 return ret;
1551}
1552
1553
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001554static void ieee802_11_rx_wnm_notif_req_wfa(struct wpa_supplicant *wpa_s,
1555 const u8 *sa, const u8 *data,
1556 int len)
1557{
1558 const u8 *pos, *end, *next;
1559 u8 ie, ie_len;
1560
1561 pos = data;
1562 end = data + len;
1563
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001564 while (end - pos > 1) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001565 ie = *pos++;
1566 ie_len = *pos++;
1567 wpa_printf(MSG_DEBUG, "WNM: WFA subelement %u len %u",
1568 ie, ie_len);
1569 if (ie_len > end - pos) {
1570 wpa_printf(MSG_DEBUG, "WNM: Not enough room for "
1571 "subelement");
1572 break;
1573 }
1574 next = pos + ie_len;
1575 if (ie_len < 4) {
1576 pos = next;
1577 continue;
1578 }
1579 wpa_printf(MSG_DEBUG, "WNM: Subelement OUI %06x type %u",
1580 WPA_GET_BE24(pos), pos[3]);
1581
1582#ifdef CONFIG_HS20
1583 if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 5 &&
1584 WPA_GET_BE24(pos) == OUI_WFA &&
1585 pos[3] == HS20_WNM_SUB_REM_NEEDED) {
1586 /* Subscription Remediation subelement */
1587 const u8 *ie_end;
1588 u8 url_len;
1589 char *url;
1590 u8 osu_method;
1591
1592 wpa_printf(MSG_DEBUG, "WNM: Subscription Remediation "
1593 "subelement");
1594 ie_end = pos + ie_len;
1595 pos += 4;
1596 url_len = *pos++;
1597 if (url_len == 0) {
1598 wpa_printf(MSG_DEBUG, "WNM: No Server URL included");
1599 url = NULL;
1600 osu_method = 1;
1601 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001602 if (url_len + 1 > ie_end - pos) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001603 wpa_printf(MSG_DEBUG, "WNM: Not enough room for Server URL (len=%u) and Server Method (left %d)",
1604 url_len,
1605 (int) (ie_end - pos));
1606 break;
1607 }
1608 url = os_malloc(url_len + 1);
1609 if (url == NULL)
1610 break;
1611 os_memcpy(url, pos, url_len);
1612 url[url_len] = '\0';
1613 osu_method = pos[url_len];
1614 }
1615 hs20_rx_subscription_remediation(wpa_s, url,
1616 osu_method);
1617 os_free(url);
1618 pos = next;
1619 continue;
1620 }
1621
1622 if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 8 &&
1623 WPA_GET_BE24(pos) == OUI_WFA &&
1624 pos[3] == HS20_WNM_DEAUTH_IMMINENT_NOTICE) {
1625 const u8 *ie_end;
1626 u8 url_len;
1627 char *url;
1628 u8 code;
1629 u16 reauth_delay;
1630
1631 ie_end = pos + ie_len;
1632 pos += 4;
1633 code = *pos++;
1634 reauth_delay = WPA_GET_LE16(pos);
1635 pos += 2;
1636 url_len = *pos++;
1637 wpa_printf(MSG_DEBUG, "WNM: HS 2.0 Deauthentication "
1638 "Imminent - Reason Code %u "
1639 "Re-Auth Delay %u URL Length %u",
1640 code, reauth_delay, url_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001641 if (url_len > ie_end - pos)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001642 break;
1643 url = os_malloc(url_len + 1);
1644 if (url == NULL)
1645 break;
1646 os_memcpy(url, pos, url_len);
1647 url[url_len] = '\0';
1648 hs20_rx_deauth_imminent_notice(wpa_s, code,
1649 reauth_delay, url);
1650 os_free(url);
1651 pos = next;
1652 continue;
1653 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001654
1655 if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 5 &&
1656 WPA_GET_BE24(pos) == OUI_WFA &&
1657 pos[3] == HS20_WNM_T_C_ACCEPTANCE) {
1658 const u8 *ie_end;
1659 u8 url_len;
1660 char *url;
1661
1662 ie_end = pos + ie_len;
1663 pos += 4;
1664 url_len = *pos++;
1665 wpa_printf(MSG_DEBUG,
1666 "WNM: HS 2.0 Terms and Conditions Acceptance (URL Length %u)",
1667 url_len);
1668 if (url_len > ie_end - pos)
1669 break;
1670 url = os_malloc(url_len + 1);
1671 if (!url)
1672 break;
1673 os_memcpy(url, pos, url_len);
1674 url[url_len] = '\0';
1675 hs20_rx_t_c_acceptance(wpa_s, url);
1676 os_free(url);
1677 pos = next;
1678 continue;
1679 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001680#endif /* CONFIG_HS20 */
1681
1682 pos = next;
1683 }
1684}
1685
1686
1687static void ieee802_11_rx_wnm_notif_req(struct wpa_supplicant *wpa_s,
1688 const u8 *sa, const u8 *frm, int len)
1689{
1690 const u8 *pos, *end;
1691 u8 dialog_token, type;
1692
1693 /* Dialog Token [1] | Type [1] | Subelements */
1694
1695 if (len < 2 || sa == NULL)
1696 return;
1697 end = frm + len;
1698 pos = frm;
1699 dialog_token = *pos++;
1700 type = *pos++;
1701
1702 wpa_dbg(wpa_s, MSG_DEBUG, "WNM: Received WNM-Notification Request "
1703 "(dialog_token %u type %u sa " MACSTR ")",
1704 dialog_token, type, MAC2STR(sa));
1705 wpa_hexdump(MSG_DEBUG, "WNM-Notification Request subelements",
1706 pos, end - pos);
1707
1708 if (wpa_s->wpa_state != WPA_COMPLETED ||
1709 os_memcmp(sa, wpa_s->bssid, ETH_ALEN) != 0) {
1710 wpa_dbg(wpa_s, MSG_DEBUG, "WNM: WNM-Notification frame not "
1711 "from our AP - ignore it");
1712 return;
1713 }
1714
1715 switch (type) {
1716 case 1:
1717 ieee802_11_rx_wnm_notif_req_wfa(wpa_s, sa, pos, end - pos);
1718 break;
1719 default:
1720 wpa_dbg(wpa_s, MSG_DEBUG, "WNM: Ignore unknown "
1721 "WNM-Notification type %u", type);
1722 break;
1723 }
1724}
1725
1726
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001727static void ieee802_11_rx_wnm_coloc_intf_req(struct wpa_supplicant *wpa_s,
1728 const u8 *sa, const u8 *frm,
1729 int len)
1730{
1731 u8 dialog_token, req_info, auto_report, timeout;
1732
1733 if (!wpa_s->conf->coloc_intf_reporting)
1734 return;
1735
1736 /* Dialog Token [1] | Request Info [1] */
1737
1738 if (len < 2)
1739 return;
1740 dialog_token = frm[0];
1741 req_info = frm[1];
1742 auto_report = req_info & 0x03;
1743 timeout = req_info >> 2;
1744
1745 wpa_dbg(wpa_s, MSG_DEBUG,
1746 "WNM: Received Collocated Interference Request (dialog_token %u auto_report %u timeout %u sa " MACSTR ")",
1747 dialog_token, auto_report, timeout, MAC2STR(sa));
1748
1749 if (dialog_token == 0)
1750 return; /* only nonzero values are used for request */
1751
1752 if (wpa_s->wpa_state != WPA_COMPLETED ||
1753 os_memcmp(sa, wpa_s->bssid, ETH_ALEN) != 0) {
1754 wpa_dbg(wpa_s, MSG_DEBUG,
1755 "WNM: Collocated Interference Request frame not from current AP - ignore it");
1756 return;
1757 }
1758
1759 wpa_msg(wpa_s, MSG_INFO, COLOC_INTF_REQ "%u %u %u",
1760 dialog_token, auto_report, timeout);
1761 wpa_s->coloc_intf_dialog_token = dialog_token;
1762 wpa_s->coloc_intf_auto_report = auto_report;
1763 wpa_s->coloc_intf_timeout = timeout;
1764}
1765
1766
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001767void ieee802_11_rx_wnm_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001768 const struct ieee80211_mgmt *mgmt, size_t len)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001769{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001770 const u8 *pos, *end;
1771 u8 act;
1772
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001773 if (len < IEEE80211_HDRLEN + 2)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001774 return;
1775
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07001776 pos = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001777 act = *pos++;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001778 end = ((const u8 *) mgmt) + len;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001779
1780 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001781 act, MAC2STR(mgmt->sa));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001782 if (wpa_s->wpa_state < WPA_ASSOCIATED ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001783 os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001784 wpa_printf(MSG_DEBUG, "WNM: Ignore unexpected WNM Action "
1785 "frame");
1786 return;
1787 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001788
1789 switch (act) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001790 case WNM_BSS_TRANS_MGMT_REQ:
1791 ieee802_11_rx_bss_trans_mgmt_req(wpa_s, pos, end,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001792 !(mgmt->da[0] & 0x01));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001793 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001794 case WNM_SLEEP_MODE_RESP:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001795 ieee802_11_rx_wnmsleep_resp(wpa_s, pos, end - pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001796 break;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001797 case WNM_NOTIFICATION_REQ:
1798 ieee802_11_rx_wnm_notif_req(wpa_s, mgmt->sa, pos, end - pos);
1799 break;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001800 case WNM_COLLOCATED_INTERFERENCE_REQ:
1801 ieee802_11_rx_wnm_coloc_intf_req(wpa_s, mgmt->sa, pos,
1802 end - pos);
1803 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001804 default:
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001805 wpa_printf(MSG_ERROR, "WNM: Unknown request");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001806 break;
1807 }
1808}
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001809
1810
1811int wnm_send_coloc_intf_report(struct wpa_supplicant *wpa_s, u8 dialog_token,
1812 const struct wpabuf *elems)
1813{
1814 struct wpabuf *buf;
1815 int ret;
1816
1817 if (wpa_s->wpa_state < WPA_ASSOCIATED || !elems)
1818 return -1;
1819
1820 wpa_printf(MSG_DEBUG, "WNM: Send Collocated Interference Report to "
1821 MACSTR " (dialog token %u)",
1822 MAC2STR(wpa_s->bssid), dialog_token);
1823
1824 buf = wpabuf_alloc(3 + wpabuf_len(elems));
1825 if (!buf)
1826 return -1;
1827
1828 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
1829 wpabuf_put_u8(buf, WNM_COLLOCATED_INTERFERENCE_REPORT);
1830 wpabuf_put_u8(buf, dialog_token);
1831 wpabuf_put_buf(buf, elems);
1832
1833 ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
1834 wpa_s->own_addr, wpa_s->bssid,
1835 wpabuf_head_u8(buf), wpabuf_len(buf), 0);
1836 wpabuf_free(buf);
1837 return ret;
1838}
1839
1840
1841void wnm_set_coloc_intf_elems(struct wpa_supplicant *wpa_s,
1842 struct wpabuf *elems)
1843{
1844 wpabuf_free(wpa_s->coloc_intf_elems);
1845 if (elems && wpabuf_len(elems) == 0) {
1846 wpabuf_free(elems);
1847 elems = NULL;
1848 }
1849 wpa_s->coloc_intf_elems = elems;
1850
1851 if (wpa_s->conf->coloc_intf_reporting && wpa_s->coloc_intf_elems &&
1852 wpa_s->coloc_intf_dialog_token &&
1853 (wpa_s->coloc_intf_auto_report == 1 ||
1854 wpa_s->coloc_intf_auto_report == 3)) {
1855 /* TODO: Check that there has not been less than
1856 * wpa_s->coloc_intf_timeout * 200 TU from the last report.
1857 */
1858 wnm_send_coloc_intf_report(wpa_s,
1859 wpa_s->coloc_intf_dialog_token,
1860 wpa_s->coloc_intf_elems);
1861 }
1862}
1863
1864
1865void wnm_clear_coloc_intf_reporting(struct wpa_supplicant *wpa_s)
1866{
1867#ifdef CONFIG_WNM
1868 wpa_s->coloc_intf_dialog_token = 0;
1869 wpa_s->coloc_intf_auto_report = 0;
1870#endif /* CONFIG_WNM */
1871}