blob: 7dc1909d4456c277e60bfc4b03b229f11b18fcb9 [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 Shmidta54fa5f2013-01-15 13:53:35 -080016#include "wpa_supplicant_i.h"
17#include "driver_i.h"
18#include "scan.h"
Dmitry Shmidt44c95782013-05-17 09:51:35 -070019#include "ctrl_iface.h"
20#include "bss.h"
21#include "wnm_sta.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080022#include "hs20_supplicant.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070023
24#define MAX_TFS_IE_LEN 1024
Dmitry Shmidt44c95782013-05-17 09:51:35 -070025#define WNM_MAX_NEIGHBOR_REPORT 10
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070026
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070027
28/* get the TFS IE from driver */
29static int ieee80211_11_get_tfs_ie(struct wpa_supplicant *wpa_s, u8 *buf,
30 u16 *buf_len, enum wnm_oper oper)
31{
32 wpa_printf(MSG_DEBUG, "%s: TFS get operation %d", __func__, oper);
33
34 return wpa_drv_wnm_oper(wpa_s, oper, wpa_s->bssid, buf, buf_len);
35}
36
37
38/* set the TFS IE to driver */
39static int ieee80211_11_set_tfs_ie(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080040 const u8 *addr, const u8 *buf, u16 buf_len,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070041 enum wnm_oper oper)
42{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080043 u16 len = buf_len;
44
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070045 wpa_printf(MSG_DEBUG, "%s: TFS set operation %d", __func__, oper);
46
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080047 return wpa_drv_wnm_oper(wpa_s, oper, addr, (u8 *) buf, &len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070048}
49
50
51/* MLME-SLEEPMODE.request */
52int ieee802_11_send_wnmsleep_req(struct wpa_supplicant *wpa_s,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080053 u8 action, u16 intval, struct wpabuf *tfs_req)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070054{
55 struct ieee80211_mgmt *mgmt;
56 int res;
57 size_t len;
58 struct wnm_sleep_element *wnmsleep_ie;
59 u8 *wnmtfs_ie;
60 u8 wnmsleep_ie_len;
61 u16 wnmtfs_ie_len; /* possibly multiple IE(s) */
62 enum wnm_oper tfs_oper = action == 0 ? WNM_SLEEP_TFS_REQ_IE_ADD :
63 WNM_SLEEP_TFS_REQ_IE_NONE;
64
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080065 wpa_printf(MSG_DEBUG, "WNM: Request to send WNM-Sleep Mode Request "
66 "action=%s to " MACSTR,
67 action == 0 ? "enter" : "exit",
68 MAC2STR(wpa_s->bssid));
69
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070070 /* WNM-Sleep Mode IE */
71 wnmsleep_ie_len = sizeof(struct wnm_sleep_element);
72 wnmsleep_ie = os_zalloc(sizeof(struct wnm_sleep_element));
73 if (wnmsleep_ie == NULL)
74 return -1;
75 wnmsleep_ie->eid = WLAN_EID_WNMSLEEP;
76 wnmsleep_ie->len = wnmsleep_ie_len - 2;
77 wnmsleep_ie->action_type = action;
78 wnmsleep_ie->status = WNM_STATUS_SLEEP_ACCEPT;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080079 wnmsleep_ie->intval = host_to_le16(intval);
80 wpa_hexdump(MSG_DEBUG, "WNM: WNM-Sleep Mode element",
81 (u8 *) wnmsleep_ie, wnmsleep_ie_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070082
83 /* TFS IE(s) */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080084 if (tfs_req) {
85 wnmtfs_ie_len = wpabuf_len(tfs_req);
86 wnmtfs_ie = os_malloc(wnmtfs_ie_len);
87 if (wnmtfs_ie == NULL) {
88 os_free(wnmsleep_ie);
89 return -1;
90 }
91 os_memcpy(wnmtfs_ie, wpabuf_head(tfs_req), wnmtfs_ie_len);
92 } else {
93 wnmtfs_ie = os_zalloc(MAX_TFS_IE_LEN);
94 if (wnmtfs_ie == NULL) {
95 os_free(wnmsleep_ie);
96 return -1;
97 }
98 if (ieee80211_11_get_tfs_ie(wpa_s, wnmtfs_ie, &wnmtfs_ie_len,
99 tfs_oper)) {
100 wnmtfs_ie_len = 0;
101 os_free(wnmtfs_ie);
102 wnmtfs_ie = NULL;
103 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700104 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800105 wpa_hexdump(MSG_DEBUG, "WNM: TFS Request element",
106 (u8 *) wnmtfs_ie, wnmtfs_ie_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700107
108 mgmt = os_zalloc(sizeof(*mgmt) + wnmsleep_ie_len + wnmtfs_ie_len);
109 if (mgmt == NULL) {
110 wpa_printf(MSG_DEBUG, "MLME: Failed to allocate buffer for "
111 "WNM-Sleep Request action frame");
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800112 os_free(wnmsleep_ie);
113 os_free(wnmtfs_ie);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700114 return -1;
115 }
116
117 os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
118 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
119 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
120 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
121 WLAN_FC_STYPE_ACTION);
122 mgmt->u.action.category = WLAN_ACTION_WNM;
123 mgmt->u.action.u.wnm_sleep_req.action = WNM_SLEEP_MODE_REQ;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800124 mgmt->u.action.u.wnm_sleep_req.dialogtoken = 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700125 os_memcpy(mgmt->u.action.u.wnm_sleep_req.variable, wnmsleep_ie,
126 wnmsleep_ie_len);
127 /* copy TFS IE here */
128 if (wnmtfs_ie_len > 0) {
129 os_memcpy(mgmt->u.action.u.wnm_sleep_req.variable +
130 wnmsleep_ie_len, wnmtfs_ie, wnmtfs_ie_len);
131 }
132
133 len = 1 + sizeof(mgmt->u.action.u.wnm_sleep_req) + wnmsleep_ie_len +
134 wnmtfs_ie_len;
135
136 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
137 wpa_s->own_addr, wpa_s->bssid,
138 &mgmt->u.action.category, len, 0);
139 if (res < 0)
140 wpa_printf(MSG_DEBUG, "Failed to send WNM-Sleep Request "
141 "(action=%d, intval=%d)", action, intval);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800142 else
143 wpa_s->wnmsleep_used = 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700144
145 os_free(wnmsleep_ie);
146 os_free(wnmtfs_ie);
147 os_free(mgmt);
148
149 return res;
150}
151
152
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800153static void wnm_sleep_mode_enter_success(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800154 const u8 *tfsresp_ie_start,
155 const u8 *tfsresp_ie_end)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800156{
157 wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_ENTER_CONFIRM,
158 wpa_s->bssid, NULL, NULL);
159 /* remove GTK/IGTK ?? */
160
161 /* set the TFS Resp IE(s) */
162 if (tfsresp_ie_start && tfsresp_ie_end &&
163 tfsresp_ie_end - tfsresp_ie_start >= 0) {
164 u16 tfsresp_ie_len;
165 tfsresp_ie_len = (tfsresp_ie_end + tfsresp_ie_end[1] + 2) -
166 tfsresp_ie_start;
167 wpa_printf(MSG_DEBUG, "TFS Resp IE(s) found");
168 /* pass the TFS Resp IE(s) to driver for processing */
169 if (ieee80211_11_set_tfs_ie(wpa_s, wpa_s->bssid,
170 tfsresp_ie_start,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800171 tfsresp_ie_len,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800172 WNM_SLEEP_TFS_RESP_IE_SET))
173 wpa_printf(MSG_DEBUG, "WNM: Fail to set TFS Resp IE");
174 }
175}
176
177
178static void wnm_sleep_mode_exit_success(struct wpa_supplicant *wpa_s,
179 const u8 *frm, u16 key_len_total)
180{
181 u8 *ptr, *end;
182 u8 gtk_len;
183
184 wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_EXIT_CONFIRM, wpa_s->bssid,
185 NULL, NULL);
186
187 /* Install GTK/IGTK */
188
189 /* point to key data field */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800190 ptr = (u8 *) frm + 1 + 2;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800191 end = ptr + key_len_total;
192 wpa_hexdump_key(MSG_DEBUG, "WNM: Key Data", ptr, key_len_total);
193
Jouni Malinen17de68d2015-11-09 15:25:41 -0800194 if (key_len_total && !wpa_sm_pmf_enabled(wpa_s->wpa)) {
195 wpa_msg(wpa_s, MSG_INFO,
196 "WNM: Ignore Key Data in WNM-Sleep Mode Response - PMF not enabled");
197 return;
198 }
199
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800200 while (end - ptr > 1) {
201 if (2 + ptr[1] > end - ptr) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800202 wpa_printf(MSG_DEBUG, "WNM: Invalid Key Data element "
203 "length");
204 if (end > ptr) {
205 wpa_hexdump(MSG_DEBUG, "WNM: Remaining data",
206 ptr, end - ptr);
207 }
208 break;
209 }
210 if (*ptr == WNM_SLEEP_SUBELEM_GTK) {
211 if (ptr[1] < 11 + 5) {
212 wpa_printf(MSG_DEBUG, "WNM: Too short GTK "
213 "subelem");
214 break;
215 }
216 gtk_len = *(ptr + 4);
217 if (ptr[1] < 11 + gtk_len ||
218 gtk_len < 5 || gtk_len > 32) {
219 wpa_printf(MSG_DEBUG, "WNM: Invalid GTK "
220 "subelem");
221 break;
222 }
223 wpa_wnmsleep_install_key(
224 wpa_s->wpa,
225 WNM_SLEEP_SUBELEM_GTK,
226 ptr);
227 ptr += 13 + gtk_len;
228#ifdef CONFIG_IEEE80211W
229 } else if (*ptr == WNM_SLEEP_SUBELEM_IGTK) {
230 if (ptr[1] < 2 + 6 + WPA_IGTK_LEN) {
231 wpa_printf(MSG_DEBUG, "WNM: Too short IGTK "
232 "subelem");
233 break;
234 }
235 wpa_wnmsleep_install_key(wpa_s->wpa,
236 WNM_SLEEP_SUBELEM_IGTK, ptr);
237 ptr += 10 + WPA_IGTK_LEN;
238#endif /* CONFIG_IEEE80211W */
239 } else
240 break; /* skip the loop */
241 }
242}
243
244
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700245static void ieee802_11_rx_wnmsleep_resp(struct wpa_supplicant *wpa_s,
246 const u8 *frm, int len)
247{
248 /*
Dmitry Shmidt21de2142014-04-08 10:50:52 -0700249 * Action [1] | Dialog Token [1] | Key Data Len [2] | Key Data |
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700250 * WNM-Sleep Mode IE | TFS Response IE
251 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800252 const u8 *pos = frm; /* point to payload after the action field */
Dmitry Shmidt21de2142014-04-08 10:50:52 -0700253 u16 key_len_total;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700254 struct wnm_sleep_element *wnmsleep_ie = NULL;
255 /* multiple TFS Resp IE (assuming consecutive) */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800256 const u8 *tfsresp_ie_start = NULL;
257 const u8 *tfsresp_ie_end = NULL;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800258 size_t left;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700259
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800260 if (!wpa_s->wnmsleep_used) {
261 wpa_printf(MSG_DEBUG,
Jouni Malinend6f9ad32017-09-22 11:25:02 +0300262 "WNM: Ignore WNM-Sleep Mode Response frame since WNM-Sleep Mode operation has not been requested");
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800263 return;
264 }
265
Dmitry Shmidt21de2142014-04-08 10:50:52 -0700266 if (len < 3)
267 return;
268 key_len_total = WPA_GET_LE16(frm + 1);
269
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800270 wpa_printf(MSG_DEBUG, "WNM-Sleep Mode Response token=%u key_len_total=%d",
271 frm[0], key_len_total);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800272 left = len - 3;
273 if (key_len_total > left) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800274 wpa_printf(MSG_INFO, "WNM: Too short frame for Key Data field");
275 return;
276 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800277 pos += 3 + key_len_total;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800278 while (pos - frm + 1 < len) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700279 u8 ie_len = *(pos + 1);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800280 if (2 + ie_len > frm + len - pos) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800281 wpa_printf(MSG_INFO, "WNM: Invalid IE len %u", ie_len);
282 break;
283 }
284 wpa_hexdump(MSG_DEBUG, "WNM: Element", pos, 2 + ie_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800285 if (*pos == WLAN_EID_WNMSLEEP && ie_len >= 4)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700286 wnmsleep_ie = (struct wnm_sleep_element *) pos;
287 else if (*pos == WLAN_EID_TFS_RESP) {
288 if (!tfsresp_ie_start)
289 tfsresp_ie_start = pos;
290 tfsresp_ie_end = pos;
291 } else
292 wpa_printf(MSG_DEBUG, "EID %d not recognized", *pos);
293 pos += ie_len + 2;
294 }
295
296 if (!wnmsleep_ie) {
297 wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found");
298 return;
299 }
300
Jouni Malinend6f9ad32017-09-22 11:25:02 +0300301 wpa_s->wnmsleep_used = 0;
302
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800303 if (wnmsleep_ie->status == WNM_STATUS_SLEEP_ACCEPT ||
304 wnmsleep_ie->status == WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700305 wpa_printf(MSG_DEBUG, "Successfully recv WNM-Sleep Response "
306 "frame (action=%d, intval=%d)",
307 wnmsleep_ie->action_type, wnmsleep_ie->intval);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800308 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER) {
309 wnm_sleep_mode_enter_success(wpa_s, tfsresp_ie_start,
310 tfsresp_ie_end);
311 } else if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) {
312 wnm_sleep_mode_exit_success(wpa_s, frm, key_len_total);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700313 }
314 } else {
315 wpa_printf(MSG_DEBUG, "Reject recv WNM-Sleep Response frame "
316 "(action=%d, intval=%d)",
317 wnmsleep_ie->action_type, wnmsleep_ie->intval);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800318 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700319 wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_ENTER_FAIL,
320 wpa_s->bssid, NULL, NULL);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800321 else if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700322 wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_EXIT_FAIL,
323 wpa_s->bssid, NULL, NULL);
324 }
325}
326
327
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700328void wnm_deallocate_memory(struct wpa_supplicant *wpa_s)
329{
330 int i;
331
332 for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700333 os_free(wpa_s->wnm_neighbor_report_elements[i].meas_pilot);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700334 os_free(wpa_s->wnm_neighbor_report_elements[i].mul_bssid);
335 }
336
Dmitry Shmidt21de2142014-04-08 10:50:52 -0700337 wpa_s->wnm_num_neighbor_report = 0;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700338 os_free(wpa_s->wnm_neighbor_report_elements);
339 wpa_s->wnm_neighbor_report_elements = NULL;
340}
341
342
343static void wnm_parse_neighbor_report_elem(struct neighbor_report *rep,
344 u8 id, u8 elen, const u8 *pos)
345{
346 switch (id) {
347 case WNM_NEIGHBOR_TSF:
348 if (elen < 2 + 2) {
349 wpa_printf(MSG_DEBUG, "WNM: Too short TSF");
350 break;
351 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800352 rep->tsf_offset = WPA_GET_LE16(pos);
353 rep->beacon_int = WPA_GET_LE16(pos + 2);
354 rep->tsf_present = 1;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700355 break;
356 case WNM_NEIGHBOR_CONDENSED_COUNTRY_STRING:
357 if (elen < 2) {
358 wpa_printf(MSG_DEBUG, "WNM: Too short condensed "
359 "country string");
360 break;
361 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800362 os_memcpy(rep->country, pos, 2);
363 rep->country_present = 1;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700364 break;
365 case WNM_NEIGHBOR_BSS_TRANSITION_CANDIDATE:
366 if (elen < 1) {
367 wpa_printf(MSG_DEBUG, "WNM: Too short BSS transition "
368 "candidate");
369 break;
370 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800371 rep->preference = pos[0];
372 rep->preference_present = 1;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700373 break;
374 case WNM_NEIGHBOR_BSS_TERMINATION_DURATION:
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800375 rep->bss_term_tsf = WPA_GET_LE64(pos);
376 rep->bss_term_dur = WPA_GET_LE16(pos + 8);
377 rep->bss_term_present = 1;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700378 break;
379 case WNM_NEIGHBOR_BEARING:
380 if (elen < 8) {
381 wpa_printf(MSG_DEBUG, "WNM: Too short neighbor "
382 "bearing");
383 break;
384 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800385 rep->bearing = WPA_GET_LE16(pos);
386 rep->distance = WPA_GET_LE32(pos + 2);
387 rep->rel_height = WPA_GET_LE16(pos + 2 + 4);
388 rep->bearing_present = 1;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700389 break;
390 case WNM_NEIGHBOR_MEASUREMENT_PILOT:
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700391 if (elen < 1) {
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700392 wpa_printf(MSG_DEBUG, "WNM: Too short measurement "
393 "pilot");
394 break;
395 }
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700396 os_free(rep->meas_pilot);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700397 rep->meas_pilot = os_zalloc(sizeof(struct measurement_pilot));
398 if (rep->meas_pilot == NULL)
399 break;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700400 rep->meas_pilot->measurement_pilot = pos[0];
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700401 rep->meas_pilot->subelem_len = elen - 1;
402 os_memcpy(rep->meas_pilot->subelems, pos + 1, elen - 1);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700403 break;
404 case WNM_NEIGHBOR_RRM_ENABLED_CAPABILITIES:
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700405 if (elen < 5) {
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700406 wpa_printf(MSG_DEBUG, "WNM: Too short RRM enabled "
407 "capabilities");
408 break;
409 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800410 os_memcpy(rep->rm_capab, pos, 5);
411 rep->rm_capab_present = 1;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700412 break;
413 case WNM_NEIGHBOR_MULTIPLE_BSSID:
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700414 if (elen < 1) {
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700415 wpa_printf(MSG_DEBUG, "WNM: Too short multiple BSSID");
416 break;
417 }
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700418 os_free(rep->mul_bssid);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700419 rep->mul_bssid = os_zalloc(sizeof(struct multiple_bssid));
420 if (rep->mul_bssid == NULL)
421 break;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700422 rep->mul_bssid->max_bssid_indicator = pos[0];
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700423 rep->mul_bssid->subelem_len = elen - 1;
424 os_memcpy(rep->mul_bssid->subelems, pos + 1, elen - 1);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700425 break;
426 }
427}
428
429
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800430static int wnm_nei_get_chan(struct wpa_supplicant *wpa_s, u8 op_class, u8 chan)
431{
432 struct wpa_bss *bss = wpa_s->current_bss;
433 const char *country = NULL;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800434 int freq;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800435
436 if (bss) {
437 const u8 *elem = wpa_bss_get_ie(bss, WLAN_EID_COUNTRY);
438
439 if (elem && elem[1] >= 2)
440 country = (const char *) (elem + 2);
441 }
442
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800443 freq = ieee80211_chan_to_freq(country, op_class, chan);
444 if (freq <= 0 && op_class == 0) {
445 /*
446 * Some APs do not advertise correct operating class
447 * information. Try to determine the most likely operating
448 * frequency based on the channel number.
449 */
450 if (chan >= 1 && chan <= 13)
451 freq = 2407 + chan * 5;
452 else if (chan == 14)
453 freq = 2484;
454 else if (chan >= 36 && chan <= 169)
455 freq = 5000 + chan * 5;
456 }
457 return freq;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800458}
459
460
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700461static void wnm_parse_neighbor_report(struct wpa_supplicant *wpa_s,
462 const u8 *pos, u8 len,
463 struct neighbor_report *rep)
464{
465 u8 left = len;
466
467 if (left < 13) {
468 wpa_printf(MSG_DEBUG, "WNM: Too short neighbor report");
469 return;
470 }
471
472 os_memcpy(rep->bssid, pos, ETH_ALEN);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800473 rep->bssid_info = WPA_GET_LE32(pos + ETH_ALEN);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700474 rep->regulatory_class = *(pos + 10);
475 rep->channel_number = *(pos + 11);
476 rep->phy_type = *(pos + 12);
477
478 pos += 13;
479 left -= 13;
480
481 while (left >= 2) {
482 u8 id, elen;
483
484 id = *pos++;
485 elen = *pos++;
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700486 wpa_printf(MSG_DEBUG, "WNM: Subelement id=%u len=%u", id, elen);
487 left -= 2;
488 if (elen > left) {
489 wpa_printf(MSG_DEBUG,
490 "WNM: Truncated neighbor report subelement");
491 break;
492 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700493 wnm_parse_neighbor_report_elem(rep, id, elen, pos);
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700494 left -= elen;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700495 pos += elen;
496 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800497
498 rep->freq = wnm_nei_get_chan(wpa_s, rep->regulatory_class,
499 rep->channel_number);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700500}
501
502
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800503static struct wpa_bss *
504compare_scan_neighbor_results(struct wpa_supplicant *wpa_s)
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700505{
506
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800507 u8 i;
508 struct wpa_bss *bss = wpa_s->current_bss;
509 struct wpa_bss *target;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700510
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800511 if (!bss)
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700512 return 0;
513
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800514 wpa_printf(MSG_DEBUG, "WNM: Current BSS " MACSTR " RSSI %d",
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800515 MAC2STR(wpa_s->bssid), bss->level);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800516
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800517 for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
518 struct neighbor_report *nei;
519
520 nei = &wpa_s->wnm_neighbor_report_elements[i];
521 if (nei->preference_present && nei->preference == 0) {
522 wpa_printf(MSG_DEBUG, "Skip excluded BSS " MACSTR,
523 MAC2STR(nei->bssid));
524 continue;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700525 }
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800526
527 target = wpa_bss_get_bssid(wpa_s, nei->bssid);
528 if (!target) {
529 wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR
530 " (pref %d) not found in scan results",
531 MAC2STR(nei->bssid),
532 nei->preference_present ? nei->preference :
533 -1);
534 continue;
535 }
536
537 if (bss->ssid_len != target->ssid_len ||
538 os_memcmp(bss->ssid, target->ssid, bss->ssid_len) != 0) {
539 /*
540 * TODO: Could consider allowing transition to another
541 * ESS if PMF was enabled for the association.
542 */
543 wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR
544 " (pref %d) in different ESS",
545 MAC2STR(nei->bssid),
546 nei->preference_present ? nei->preference :
547 -1);
548 continue;
549 }
550
Dmitry Shmidte4663042016-04-04 10:07:49 -0700551 if (wpa_s->current_ssid &&
552 !wpa_scan_res_match(wpa_s, 0, target, wpa_s->current_ssid,
553 1)) {
554 wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR
555 " (pref %d) does not match the current network profile",
556 MAC2STR(nei->bssid),
557 nei->preference_present ? nei->preference :
558 -1);
559 continue;
560 }
561
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800562 if (wpa_is_bss_tmp_disallowed(wpa_s, target->bssid)) {
563 wpa_printf(MSG_DEBUG,
564 "MBO: Candidate BSS " MACSTR
565 " retry delay is not over yet",
566 MAC2STR(nei->bssid));
567 continue;
568 }
569
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800570 if (target->level < bss->level && target->level < -80) {
571 wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR
572 " (pref %d) does not have sufficient signal level (%d)",
573 MAC2STR(nei->bssid),
574 nei->preference_present ? nei->preference :
575 -1,
576 target->level);
577 continue;
578 }
579
580 wpa_printf(MSG_DEBUG,
581 "WNM: Found an acceptable preferred transition candidate BSS "
582 MACSTR " (RSSI %d)",
583 MAC2STR(nei->bssid), target->level);
584 return target;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700585 }
586
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800587 return NULL;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700588}
589
590
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800591static int wpa_bss_ies_eq(struct wpa_bss *a, struct wpa_bss *b, u8 eid)
592{
593 const u8 *ie_a, *ie_b;
594
595 if (!a || !b)
596 return 0;
597
598 ie_a = wpa_bss_get_ie(a, eid);
599 ie_b = wpa_bss_get_ie(b, eid);
600
601 if (!ie_a || !ie_b || ie_a[1] != ie_b[1])
602 return 0;
603
604 return os_memcmp(ie_a, ie_b, ie_a[1]) == 0;
605}
606
607
608static u32 wnm_get_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
609{
610 u32 info = 0;
611
612 info |= NEI_REP_BSSID_INFO_AP_UNKNOWN_REACH;
613
614 /*
615 * Leave the security and key scope bits unset to indicate that the
616 * security information is not available.
617 */
618
619 if (bss->caps & WLAN_CAPABILITY_SPECTRUM_MGMT)
620 info |= NEI_REP_BSSID_INFO_SPECTRUM_MGMT;
621 if (bss->caps & WLAN_CAPABILITY_QOS)
622 info |= NEI_REP_BSSID_INFO_QOS;
623 if (bss->caps & WLAN_CAPABILITY_APSD)
624 info |= NEI_REP_BSSID_INFO_APSD;
625 if (bss->caps & WLAN_CAPABILITY_RADIO_MEASUREMENT)
626 info |= NEI_REP_BSSID_INFO_RM;
627 if (bss->caps & WLAN_CAPABILITY_DELAYED_BLOCK_ACK)
628 info |= NEI_REP_BSSID_INFO_DELAYED_BA;
629 if (bss->caps & WLAN_CAPABILITY_IMM_BLOCK_ACK)
630 info |= NEI_REP_BSSID_INFO_IMM_BA;
631 if (wpa_bss_ies_eq(bss, wpa_s->current_bss, WLAN_EID_MOBILITY_DOMAIN))
632 info |= NEI_REP_BSSID_INFO_MOBILITY_DOMAIN;
633 if (wpa_bss_ies_eq(bss, wpa_s->current_bss, WLAN_EID_HT_CAP))
634 info |= NEI_REP_BSSID_INFO_HT;
635
636 return info;
637}
638
639
640static int wnm_add_nei_rep(u8 *buf, size_t len, const u8 *bssid, u32 bss_info,
641 u8 op_class, u8 chan, u8 phy_type, u8 pref)
642{
643 u8 *pos = buf;
644
645 if (len < 18) {
646 wpa_printf(MSG_DEBUG,
647 "WNM: Not enough room for Neighbor Report element");
648 return -1;
649 }
650
651 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
652 /* length: 13 for basic neighbor report + 3 for preference subelement */
653 *pos++ = 16;
654 os_memcpy(pos, bssid, ETH_ALEN);
655 pos += ETH_ALEN;
656 WPA_PUT_LE32(pos, bss_info);
657 pos += 4;
658 *pos++ = op_class;
659 *pos++ = chan;
660 *pos++ = phy_type;
661 *pos++ = WNM_NEIGHBOR_BSS_TRANSITION_CANDIDATE;
662 *pos++ = 1;
663 *pos++ = pref;
664 return pos - buf;
665}
666
667
668static int wnm_nei_rep_add_bss(struct wpa_supplicant *wpa_s,
669 struct wpa_bss *bss, u8 *buf, size_t len,
670 u8 pref)
671{
672 const u8 *ie;
673 u8 op_class, chan;
674 int sec_chan = 0, vht = 0;
675 enum phy_type phy_type;
676 u32 info;
677 struct ieee80211_ht_operation *ht_oper = NULL;
678 struct ieee80211_vht_operation *vht_oper = NULL;
679
680 ie = wpa_bss_get_ie(bss, WLAN_EID_HT_OPERATION);
681 if (ie && ie[1] >= 2) {
682 ht_oper = (struct ieee80211_ht_operation *) (ie + 2);
683
684 if (ht_oper->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
685 sec_chan = 1;
686 else if (ht_oper->ht_param &
687 HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
688 sec_chan = -1;
689 }
690
691 ie = wpa_bss_get_ie(bss, WLAN_EID_VHT_OPERATION);
692 if (ie && ie[1] >= 1) {
693 vht_oper = (struct ieee80211_vht_operation *) (ie + 2);
694
695 if (vht_oper->vht_op_info_chwidth == VHT_CHANWIDTH_80MHZ ||
696 vht_oper->vht_op_info_chwidth == VHT_CHANWIDTH_160MHZ ||
697 vht_oper->vht_op_info_chwidth == VHT_CHANWIDTH_80P80MHZ)
698 vht = vht_oper->vht_op_info_chwidth;
699 }
700
701 if (ieee80211_freq_to_channel_ext(bss->freq, sec_chan, vht, &op_class,
702 &chan) == NUM_HOSTAPD_MODES) {
703 wpa_printf(MSG_DEBUG,
704 "WNM: Cannot determine operating class and channel");
705 return -2;
706 }
707
708 phy_type = ieee80211_get_phy_type(bss->freq, (ht_oper != NULL),
709 (vht_oper != NULL));
710 if (phy_type == PHY_TYPE_UNSPECIFIED) {
711 wpa_printf(MSG_DEBUG,
712 "WNM: Cannot determine BSS phy type for Neighbor Report");
713 return -2;
714 }
715
716 info = wnm_get_bss_info(wpa_s, bss);
717
718 return wnm_add_nei_rep(buf, len, bss->bssid, info, op_class, chan,
719 phy_type, pref);
720}
721
722
723static int wnm_add_cand_list(struct wpa_supplicant *wpa_s, u8 *buf, size_t len)
724{
725 u8 *pos = buf;
726 unsigned int i, pref = 255;
727 struct os_reltime now;
728 struct wpa_ssid *ssid = wpa_s->current_ssid;
729
730 if (!ssid)
731 return 0;
732
733 /*
734 * TODO: Define when scan results are no longer valid for the candidate
735 * list.
736 */
737 os_get_reltime(&now);
738 if (os_reltime_expired(&now, &wpa_s->last_scan, 10))
739 return 0;
740
741 wpa_printf(MSG_DEBUG,
742 "WNM: Add candidate list to BSS Transition Management Response frame");
743 for (i = 0; i < wpa_s->last_scan_res_used && pref; i++) {
744 struct wpa_bss *bss = wpa_s->last_scan_res[i];
745 int res;
746
747 if (wpa_scan_res_match(wpa_s, i, bss, ssid, 1)) {
748 res = wnm_nei_rep_add_bss(wpa_s, bss, pos, len, pref--);
749 if (res == -2)
750 continue; /* could not build entry for BSS */
751 if (res < 0)
752 break; /* no more room for candidates */
753 if (pref == 1)
754 break;
755
756 pos += res;
757 len -= res;
758 }
759 }
760
761 wpa_hexdump(MSG_DEBUG,
762 "WNM: BSS Transition Management Response candidate list",
763 buf, pos - buf);
764
765 return pos - buf;
766}
767
768
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -0700769static void wnm_send_bss_transition_mgmt_resp(
770 struct wpa_supplicant *wpa_s, u8 dialog_token,
771 enum bss_trans_mgmt_status_code status, u8 delay,
772 const u8 *target_bssid)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800773{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800774 u8 buf[2000], *pos;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800775 struct ieee80211_mgmt *mgmt;
776 size_t len;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800777 int res;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800778
779 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Response "
780 "to " MACSTR " dialog_token=%u status=%u delay=%d",
781 MAC2STR(wpa_s->bssid), dialog_token, status, delay);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800782 if (!wpa_s->current_bss) {
783 wpa_printf(MSG_DEBUG,
784 "WNM: Current BSS not known - drop response");
785 return;
786 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800787
788 mgmt = (struct ieee80211_mgmt *) buf;
789 os_memset(&buf, 0, sizeof(buf));
790 os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
791 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
792 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
793 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
794 WLAN_FC_STYPE_ACTION);
795 mgmt->u.action.category = WLAN_ACTION_WNM;
796 mgmt->u.action.u.bss_tm_resp.action = WNM_BSS_TRANS_MGMT_RESP;
797 mgmt->u.action.u.bss_tm_resp.dialog_token = dialog_token;
798 mgmt->u.action.u.bss_tm_resp.status_code = status;
799 mgmt->u.action.u.bss_tm_resp.bss_termination_delay = delay;
800 pos = mgmt->u.action.u.bss_tm_resp.variable;
801 if (target_bssid) {
802 os_memcpy(pos, target_bssid, ETH_ALEN);
803 pos += ETH_ALEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800804 } else if (status == WNM_BSS_TM_ACCEPT) {
805 /*
806 * P802.11-REVmc clarifies that the Target BSSID field is always
807 * present when status code is zero, so use a fake value here if
808 * no BSSID is yet known.
809 */
810 os_memset(pos, 0, ETH_ALEN);
811 pos += ETH_ALEN;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800812 }
813
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800814 if (status == WNM_BSS_TM_ACCEPT)
815 pos += wnm_add_cand_list(wpa_s, pos, buf + sizeof(buf) - pos);
816
817#ifdef CONFIG_MBO
818 if (status != WNM_BSS_TM_ACCEPT) {
819 pos += wpas_mbo_ie_bss_trans_reject(
820 wpa_s, pos, buf + sizeof(buf) - pos,
821 MBO_TRANSITION_REJECT_REASON_UNSPECIFIED);
822 }
823#endif /* CONFIG_MBO */
824
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800825 len = pos - (u8 *) &mgmt->u.action.category;
826
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800827 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
828 wpa_s->own_addr, wpa_s->bssid,
829 &mgmt->u.action.category, len, 0);
830 if (res < 0) {
831 wpa_printf(MSG_DEBUG,
832 "WNM: Failed to send BSS Transition Management Response");
833 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800834}
835
836
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800837int wnm_scan_process(struct wpa_supplicant *wpa_s, int reply_on_fail)
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700838{
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800839 struct wpa_bss *bss;
840 struct wpa_ssid *ssid = wpa_s->current_ssid;
841 enum bss_trans_mgmt_status_code status = WNM_BSS_TM_REJECT_UNSPECIFIED;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700842
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800843 if (!wpa_s->wnm_neighbor_report_elements)
844 return 0;
845
846 if (os_reltime_before(&wpa_s->wnm_cand_valid_until,
847 &wpa_s->scan_trigger_time)) {
848 wpa_printf(MSG_DEBUG, "WNM: Previously stored BSS transition candidate list is not valid anymore - drop it");
849 wnm_deallocate_memory(wpa_s);
850 return 0;
851 }
852
853 if (!wpa_s->current_bss ||
854 os_memcmp(wpa_s->wnm_cand_from_bss, wpa_s->current_bss->bssid,
855 ETH_ALEN) != 0) {
856 wpa_printf(MSG_DEBUG, "WNM: Stored BSS transition candidate list not from the current BSS - ignore it");
857 return 0;
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700858 }
859
860 /* Compare the Neighbor Report and scan results */
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800861 bss = compare_scan_neighbor_results(wpa_s);
862 if (!bss) {
863 wpa_printf(MSG_DEBUG, "WNM: No BSS transition candidate match found");
864 status = WNM_BSS_TM_REJECT_NO_SUITABLE_CANDIDATES;
865 goto send_bss_resp_fail;
866 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700867
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800868 /* Associate to the network */
869 /* Send the BSS Management Response - Accept */
870 if (wpa_s->wnm_reply) {
871 wpa_s->wnm_reply = 0;
872 wnm_send_bss_transition_mgmt_resp(wpa_s,
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700873 wpa_s->wnm_dialog_token,
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -0700874 WNM_BSS_TM_ACCEPT,
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800875 0, bss->bssid);
876 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700877
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800878 if (bss == wpa_s->current_bss) {
879 wpa_printf(MSG_DEBUG,
880 "WNM: Already associated with the preferred candidate");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800881 wnm_deallocate_memory(wpa_s);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800882 return 1;
883 }
884
885 wpa_s->reassociate = 1;
886 wpa_supplicant_connect(wpa_s, bss, ssid);
887 wnm_deallocate_memory(wpa_s);
888 return 1;
889
890send_bss_resp_fail:
891 if (!reply_on_fail)
892 return 0;
893
894 /* Send reject response for all the failures */
895
896 if (wpa_s->wnm_reply) {
897 wpa_s->wnm_reply = 0;
898 wnm_send_bss_transition_mgmt_resp(wpa_s,
899 wpa_s->wnm_dialog_token,
900 status, 0, NULL);
901 }
902 wnm_deallocate_memory(wpa_s);
903
904 return 0;
905}
906
907
908static int cand_pref_compar(const void *a, const void *b)
909{
910 const struct neighbor_report *aa = a;
911 const struct neighbor_report *bb = b;
912
913 if (!aa->preference_present && !bb->preference_present)
914 return 0;
915 if (!aa->preference_present)
916 return 1;
917 if (!bb->preference_present)
918 return -1;
919 if (bb->preference > aa->preference)
920 return 1;
921 if (bb->preference < aa->preference)
922 return -1;
923 return 0;
924}
925
926
927static void wnm_sort_cand_list(struct wpa_supplicant *wpa_s)
928{
929 if (!wpa_s->wnm_neighbor_report_elements)
930 return;
931 qsort(wpa_s->wnm_neighbor_report_elements,
932 wpa_s->wnm_num_neighbor_report, sizeof(struct neighbor_report),
933 cand_pref_compar);
934}
935
936
937static void wnm_dump_cand_list(struct wpa_supplicant *wpa_s)
938{
939 unsigned int i;
940
941 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Candidate List");
942 if (!wpa_s->wnm_neighbor_report_elements)
943 return;
944 for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
945 struct neighbor_report *nei;
946
947 nei = &wpa_s->wnm_neighbor_report_elements[i];
948 wpa_printf(MSG_DEBUG, "%u: " MACSTR
949 " info=0x%x op_class=%u chan=%u phy=%u pref=%d freq=%d",
950 i, MAC2STR(nei->bssid), nei->bssid_info,
951 nei->regulatory_class,
952 nei->channel_number, nei->phy_type,
953 nei->preference_present ? nei->preference : -1,
954 nei->freq);
955 }
956}
957
958
959static int chan_supported(struct wpa_supplicant *wpa_s, int freq)
960{
961 unsigned int i;
962
963 for (i = 0; i < wpa_s->hw.num_modes; i++) {
964 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
965 int j;
966
967 for (j = 0; j < mode->num_channels; j++) {
968 struct hostapd_channel_data *chan;
969
970 chan = &mode->channels[j];
971 if (chan->freq == freq &&
972 !(chan->flag & HOSTAPD_CHAN_DISABLED))
973 return 1;
974 }
975 }
976
977 return 0;
978}
979
980
981static void wnm_set_scan_freqs(struct wpa_supplicant *wpa_s)
982{
983 int *freqs;
984 int num_freqs = 0;
985 unsigned int i;
986
987 if (!wpa_s->wnm_neighbor_report_elements)
988 return;
989
990 if (wpa_s->hw.modes == NULL)
991 return;
992
993 os_free(wpa_s->next_scan_freqs);
994 wpa_s->next_scan_freqs = NULL;
995
996 freqs = os_calloc(wpa_s->wnm_num_neighbor_report + 1, sizeof(int));
997 if (freqs == NULL)
998 return;
999
1000 for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
1001 struct neighbor_report *nei;
1002
1003 nei = &wpa_s->wnm_neighbor_report_elements[i];
1004 if (nei->freq <= 0) {
1005 wpa_printf(MSG_DEBUG,
1006 "WNM: Unknown neighbor operating frequency for "
1007 MACSTR " - scan all channels",
1008 MAC2STR(nei->bssid));
1009 os_free(freqs);
1010 return;
1011 }
1012 if (chan_supported(wpa_s, nei->freq))
1013 add_freq(freqs, &num_freqs, nei->freq);
1014 }
1015
1016 if (num_freqs == 0) {
1017 os_free(freqs);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001018 return;
1019 }
1020
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001021 wpa_printf(MSG_DEBUG,
1022 "WNM: Scan %d frequencies based on transition candidate list",
1023 num_freqs);
1024 wpa_s->next_scan_freqs = freqs;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001025}
1026
1027
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001028static void ieee802_11_rx_bss_trans_mgmt_req(struct wpa_supplicant *wpa_s,
1029 const u8 *pos, const u8 *end,
1030 int reply)
1031{
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001032 unsigned int beacon_int;
1033 u8 valid_int;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001034#ifdef CONFIG_MBO
1035 const u8 *vendor;
1036#endif /* CONFIG_MBO */
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001037
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001038 if (end - pos < 5)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001039 return;
1040
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001041 if (wpa_s->current_bss)
1042 beacon_int = wpa_s->current_bss->beacon_int;
1043 else
1044 beacon_int = 100; /* best guess */
1045
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001046 wpa_s->wnm_dialog_token = pos[0];
1047 wpa_s->wnm_mode = pos[1];
1048 wpa_s->wnm_dissoc_timer = WPA_GET_LE16(pos + 2);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001049 valid_int = pos[4];
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001050 wpa_s->wnm_reply = reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001051
1052 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Request: "
1053 "dialog_token=%u request_mode=0x%x "
1054 "disassoc_timer=%u validity_interval=%u",
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001055 wpa_s->wnm_dialog_token, wpa_s->wnm_mode,
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001056 wpa_s->wnm_dissoc_timer, valid_int);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001057
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001058 pos += 5;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001059
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001060 if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001061 if (end - pos < 12) {
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001062 wpa_printf(MSG_DEBUG, "WNM: Too short BSS TM Request");
1063 return;
1064 }
1065 os_memcpy(wpa_s->wnm_bss_termination_duration, pos, 12);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001066 pos += 12; /* BSS Termination Duration */
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001067 }
1068
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001069 if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001070 char url[256];
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001071
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001072 if (end - pos < 1 || 1 + pos[0] > end - pos) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001073 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS Transition "
1074 "Management Request (URL)");
1075 return;
1076 }
1077 os_memcpy(url, pos + 1, pos[0]);
1078 url[pos[0]] = '\0';
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001079 pos += 1 + pos[0];
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001080
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001081 wpa_msg(wpa_s, MSG_INFO, ESS_DISASSOC_IMMINENT "%d %u %s",
1082 wpa_sm_pmf_enabled(wpa_s->wpa),
1083 wpa_s->wnm_dissoc_timer * beacon_int * 128 / 125, url);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001084 }
1085
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001086 if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_DISASSOC_IMMINENT) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001087 wpa_msg(wpa_s, MSG_INFO, "WNM: Disassociation Imminent - "
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001088 "Disassociation Timer %u", wpa_s->wnm_dissoc_timer);
1089 if (wpa_s->wnm_dissoc_timer && !wpa_s->scanning) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001090 /* TODO: mark current BSS less preferred for
1091 * selection */
1092 wpa_printf(MSG_DEBUG, "Trying to find another BSS");
1093 wpa_supplicant_req_scan(wpa_s, 0, 0);
1094 }
1095 }
1096
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001097#ifdef CONFIG_MBO
1098 vendor = get_ie(pos, end - pos, WLAN_EID_VENDOR_SPECIFIC);
1099 if (vendor)
1100 wpas_mbo_ie_trans_req(wpa_s, vendor + 2, vendor[1]);
1101#endif /* CONFIG_MBO */
1102
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001103 if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED) {
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001104 unsigned int valid_ms;
1105
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001106 wpa_msg(wpa_s, MSG_INFO, "WNM: Preferred List Available");
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001107 wnm_deallocate_memory(wpa_s);
1108 wpa_s->wnm_neighbor_report_elements = os_calloc(
1109 WNM_MAX_NEIGHBOR_REPORT,
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001110 sizeof(struct neighbor_report));
1111 if (wpa_s->wnm_neighbor_report_elements == NULL)
1112 return;
1113
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001114 while (end - pos >= 2 &&
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001115 wpa_s->wnm_num_neighbor_report < WNM_MAX_NEIGHBOR_REPORT)
1116 {
1117 u8 tag = *pos++;
1118 u8 len = *pos++;
1119
1120 wpa_printf(MSG_DEBUG, "WNM: Neighbor report tag %u",
1121 tag);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001122 if (len > end - pos) {
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001123 wpa_printf(MSG_DEBUG, "WNM: Truncated request");
1124 return;
1125 }
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -07001126 if (tag == WLAN_EID_NEIGHBOR_REPORT) {
1127 struct neighbor_report *rep;
1128 rep = &wpa_s->wnm_neighbor_report_elements[
1129 wpa_s->wnm_num_neighbor_report];
1130 wnm_parse_neighbor_report(wpa_s, pos, len, rep);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001131 wpa_s->wnm_num_neighbor_report++;
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -07001132 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001133
1134 pos += len;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001135 }
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001136
1137 if (!wpa_s->wnm_num_neighbor_report) {
1138 wpa_printf(MSG_DEBUG,
1139 "WNM: Candidate list included bit is set, but no candidates found");
1140 wnm_send_bss_transition_mgmt_resp(
1141 wpa_s, wpa_s->wnm_dialog_token,
1142 WNM_BSS_TM_REJECT_NO_SUITABLE_CANDIDATES,
1143 0, NULL);
1144 return;
1145 }
1146
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001147 wnm_sort_cand_list(wpa_s);
1148 wnm_dump_cand_list(wpa_s);
1149 valid_ms = valid_int * beacon_int * 128 / 125;
1150 wpa_printf(MSG_DEBUG, "WNM: Candidate list valid for %u ms",
1151 valid_ms);
1152 os_get_reltime(&wpa_s->wnm_cand_valid_until);
1153 wpa_s->wnm_cand_valid_until.sec += valid_ms / 1000;
1154 wpa_s->wnm_cand_valid_until.usec += (valid_ms % 1000) * 1000;
1155 wpa_s->wnm_cand_valid_until.sec +=
1156 wpa_s->wnm_cand_valid_until.usec / 1000000;
1157 wpa_s->wnm_cand_valid_until.usec %= 1000000;
1158 os_memcpy(wpa_s->wnm_cand_from_bss, wpa_s->bssid, ETH_ALEN);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001159
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001160 if (wpa_s->last_scan_res_used > 0) {
1161 struct os_reltime now;
1162
1163 os_get_reltime(&now);
1164 if (!os_reltime_expired(&now, &wpa_s->last_scan, 10)) {
1165 wpa_printf(MSG_DEBUG,
1166 "WNM: Try to use recent scan results");
1167 if (wnm_scan_process(wpa_s, 0) > 0)
1168 return;
1169 wpa_printf(MSG_DEBUG,
1170 "WNM: No match in previous scan results - try a new scan");
1171 }
1172 }
1173
1174 wnm_set_scan_freqs(wpa_s);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001175 if (wpa_s->wnm_num_neighbor_report == 1) {
1176 os_memcpy(wpa_s->next_scan_bssid,
1177 wpa_s->wnm_neighbor_report_elements[0].bssid,
1178 ETH_ALEN);
1179 wpa_printf(MSG_DEBUG,
1180 "WNM: Scan only for a specific BSSID since there is only a single candidate "
1181 MACSTR, MAC2STR(wpa_s->next_scan_bssid));
1182 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001183 wpa_supplicant_req_scan(wpa_s, 0, 0);
1184 } else if (reply) {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001185 enum bss_trans_mgmt_status_code status;
1186 if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT)
1187 status = WNM_BSS_TM_ACCEPT;
1188 else {
1189 wpa_msg(wpa_s, MSG_INFO, "WNM: BSS Transition Management Request did not include candidates");
1190 status = WNM_BSS_TM_REJECT_UNSPECIFIED;
1191 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001192 wnm_send_bss_transition_mgmt_resp(wpa_s,
1193 wpa_s->wnm_dialog_token,
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001194 status, 0, NULL);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001195 }
1196}
1197
1198
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001199int wnm_send_bss_transition_mgmt_query(struct wpa_supplicant *wpa_s,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001200 u8 query_reason, int cand_list)
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001201{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001202 u8 buf[2000], *pos;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001203 struct ieee80211_mgmt *mgmt;
1204 size_t len;
1205 int ret;
1206
1207 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Query to "
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001208 MACSTR " query_reason=%u%s",
1209 MAC2STR(wpa_s->bssid), query_reason,
1210 cand_list ? " candidate list" : "");
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001211
1212 mgmt = (struct ieee80211_mgmt *) buf;
1213 os_memset(&buf, 0, sizeof(buf));
1214 os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
1215 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
1216 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
1217 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1218 WLAN_FC_STYPE_ACTION);
1219 mgmt->u.action.category = WLAN_ACTION_WNM;
1220 mgmt->u.action.u.bss_tm_query.action = WNM_BSS_TRANS_MGMT_QUERY;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001221 mgmt->u.action.u.bss_tm_query.dialog_token = 1;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001222 mgmt->u.action.u.bss_tm_query.query_reason = query_reason;
1223 pos = mgmt->u.action.u.bss_tm_query.variable;
1224
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001225 if (cand_list)
1226 pos += wnm_add_cand_list(wpa_s, pos, buf + sizeof(buf) - pos);
1227
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001228 len = pos - (u8 *) &mgmt->u.action.category;
1229
1230 ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
1231 wpa_s->own_addr, wpa_s->bssid,
1232 &mgmt->u.action.category, len, 0);
1233
1234 return ret;
1235}
1236
1237
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001238static void ieee802_11_rx_wnm_notif_req_wfa(struct wpa_supplicant *wpa_s,
1239 const u8 *sa, const u8 *data,
1240 int len)
1241{
1242 const u8 *pos, *end, *next;
1243 u8 ie, ie_len;
1244
1245 pos = data;
1246 end = data + len;
1247
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001248 while (end - pos > 1) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001249 ie = *pos++;
1250 ie_len = *pos++;
1251 wpa_printf(MSG_DEBUG, "WNM: WFA subelement %u len %u",
1252 ie, ie_len);
1253 if (ie_len > end - pos) {
1254 wpa_printf(MSG_DEBUG, "WNM: Not enough room for "
1255 "subelement");
1256 break;
1257 }
1258 next = pos + ie_len;
1259 if (ie_len < 4) {
1260 pos = next;
1261 continue;
1262 }
1263 wpa_printf(MSG_DEBUG, "WNM: Subelement OUI %06x type %u",
1264 WPA_GET_BE24(pos), pos[3]);
1265
1266#ifdef CONFIG_HS20
1267 if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 5 &&
1268 WPA_GET_BE24(pos) == OUI_WFA &&
1269 pos[3] == HS20_WNM_SUB_REM_NEEDED) {
1270 /* Subscription Remediation subelement */
1271 const u8 *ie_end;
1272 u8 url_len;
1273 char *url;
1274 u8 osu_method;
1275
1276 wpa_printf(MSG_DEBUG, "WNM: Subscription Remediation "
1277 "subelement");
1278 ie_end = pos + ie_len;
1279 pos += 4;
1280 url_len = *pos++;
1281 if (url_len == 0) {
1282 wpa_printf(MSG_DEBUG, "WNM: No Server URL included");
1283 url = NULL;
1284 osu_method = 1;
1285 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001286 if (url_len + 1 > ie_end - pos) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001287 wpa_printf(MSG_DEBUG, "WNM: Not enough room for Server URL (len=%u) and Server Method (left %d)",
1288 url_len,
1289 (int) (ie_end - pos));
1290 break;
1291 }
1292 url = os_malloc(url_len + 1);
1293 if (url == NULL)
1294 break;
1295 os_memcpy(url, pos, url_len);
1296 url[url_len] = '\0';
1297 osu_method = pos[url_len];
1298 }
1299 hs20_rx_subscription_remediation(wpa_s, url,
1300 osu_method);
1301 os_free(url);
1302 pos = next;
1303 continue;
1304 }
1305
1306 if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 8 &&
1307 WPA_GET_BE24(pos) == OUI_WFA &&
1308 pos[3] == HS20_WNM_DEAUTH_IMMINENT_NOTICE) {
1309 const u8 *ie_end;
1310 u8 url_len;
1311 char *url;
1312 u8 code;
1313 u16 reauth_delay;
1314
1315 ie_end = pos + ie_len;
1316 pos += 4;
1317 code = *pos++;
1318 reauth_delay = WPA_GET_LE16(pos);
1319 pos += 2;
1320 url_len = *pos++;
1321 wpa_printf(MSG_DEBUG, "WNM: HS 2.0 Deauthentication "
1322 "Imminent - Reason Code %u "
1323 "Re-Auth Delay %u URL Length %u",
1324 code, reauth_delay, url_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001325 if (url_len > ie_end - pos)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001326 break;
1327 url = os_malloc(url_len + 1);
1328 if (url == NULL)
1329 break;
1330 os_memcpy(url, pos, url_len);
1331 url[url_len] = '\0';
1332 hs20_rx_deauth_imminent_notice(wpa_s, code,
1333 reauth_delay, url);
1334 os_free(url);
1335 pos = next;
1336 continue;
1337 }
1338#endif /* CONFIG_HS20 */
1339
1340 pos = next;
1341 }
1342}
1343
1344
1345static void ieee802_11_rx_wnm_notif_req(struct wpa_supplicant *wpa_s,
1346 const u8 *sa, const u8 *frm, int len)
1347{
1348 const u8 *pos, *end;
1349 u8 dialog_token, type;
1350
1351 /* Dialog Token [1] | Type [1] | Subelements */
1352
1353 if (len < 2 || sa == NULL)
1354 return;
1355 end = frm + len;
1356 pos = frm;
1357 dialog_token = *pos++;
1358 type = *pos++;
1359
1360 wpa_dbg(wpa_s, MSG_DEBUG, "WNM: Received WNM-Notification Request "
1361 "(dialog_token %u type %u sa " MACSTR ")",
1362 dialog_token, type, MAC2STR(sa));
1363 wpa_hexdump(MSG_DEBUG, "WNM-Notification Request subelements",
1364 pos, end - pos);
1365
1366 if (wpa_s->wpa_state != WPA_COMPLETED ||
1367 os_memcmp(sa, wpa_s->bssid, ETH_ALEN) != 0) {
1368 wpa_dbg(wpa_s, MSG_DEBUG, "WNM: WNM-Notification frame not "
1369 "from our AP - ignore it");
1370 return;
1371 }
1372
1373 switch (type) {
1374 case 1:
1375 ieee802_11_rx_wnm_notif_req_wfa(wpa_s, sa, pos, end - pos);
1376 break;
1377 default:
1378 wpa_dbg(wpa_s, MSG_DEBUG, "WNM: Ignore unknown "
1379 "WNM-Notification type %u", type);
1380 break;
1381 }
1382}
1383
1384
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001385void ieee802_11_rx_wnm_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001386 const struct ieee80211_mgmt *mgmt, size_t len)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001387{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001388 const u8 *pos, *end;
1389 u8 act;
1390
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001391 if (len < IEEE80211_HDRLEN + 2)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001392 return;
1393
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07001394 pos = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001395 act = *pos++;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001396 end = ((const u8 *) mgmt) + len;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001397
1398 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001399 act, MAC2STR(mgmt->sa));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001400 if (wpa_s->wpa_state < WPA_ASSOCIATED ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001401 os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001402 wpa_printf(MSG_DEBUG, "WNM: Ignore unexpected WNM Action "
1403 "frame");
1404 return;
1405 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001406
1407 switch (act) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001408 case WNM_BSS_TRANS_MGMT_REQ:
1409 ieee802_11_rx_bss_trans_mgmt_req(wpa_s, pos, end,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001410 !(mgmt->da[0] & 0x01));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001411 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001412 case WNM_SLEEP_MODE_RESP:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001413 ieee802_11_rx_wnmsleep_resp(wpa_s, pos, end - pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001414 break;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001415 case WNM_NOTIFICATION_REQ:
1416 ieee802_11_rx_wnm_notif_req(wpa_s, mgmt->sa, pos, end - pos);
1417 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001418 default:
Dmitry Shmidt44c95782013-05-17 09:51:35 -07001419 wpa_printf(MSG_ERROR, "WNM: Unknown request");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001420 break;
1421 }
1422}