Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * wpa_supplicant - WNM |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3 | * Copyright (c) 2011-2013, Qualcomm Atheros, Inc. |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4 | * |
| 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
| 7 | */ |
| 8 | |
| 9 | #include "utils/includes.h" |
| 10 | |
| 11 | #include "utils/common.h" |
| 12 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 13 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 14 | #include "rsn_supp/wpa.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 15 | #include "wpa_supplicant_i.h" |
| 16 | #include "driver_i.h" |
| 17 | #include "scan.h" |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 18 | #include "ctrl_iface.h" |
| 19 | #include "bss.h" |
| 20 | #include "wnm_sta.h" |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 21 | #include "hs20_supplicant.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 22 | |
| 23 | #define MAX_TFS_IE_LEN 1024 |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 24 | #define WNM_MAX_NEIGHBOR_REPORT 10 |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 25 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 26 | |
| 27 | /* get the TFS IE from driver */ |
| 28 | static int ieee80211_11_get_tfs_ie(struct wpa_supplicant *wpa_s, u8 *buf, |
| 29 | u16 *buf_len, enum wnm_oper oper) |
| 30 | { |
| 31 | wpa_printf(MSG_DEBUG, "%s: TFS get operation %d", __func__, oper); |
| 32 | |
| 33 | return wpa_drv_wnm_oper(wpa_s, oper, wpa_s->bssid, buf, buf_len); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | /* set the TFS IE to driver */ |
| 38 | static int ieee80211_11_set_tfs_ie(struct wpa_supplicant *wpa_s, |
| 39 | const u8 *addr, u8 *buf, u16 *buf_len, |
| 40 | enum wnm_oper oper) |
| 41 | { |
| 42 | wpa_printf(MSG_DEBUG, "%s: TFS set operation %d", __func__, oper); |
| 43 | |
| 44 | return wpa_drv_wnm_oper(wpa_s, oper, addr, buf, buf_len); |
| 45 | } |
| 46 | |
| 47 | |
| 48 | /* MLME-SLEEPMODE.request */ |
| 49 | int ieee802_11_send_wnmsleep_req(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 50 | u8 action, u16 intval, struct wpabuf *tfs_req) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 51 | { |
| 52 | struct ieee80211_mgmt *mgmt; |
| 53 | int res; |
| 54 | size_t len; |
| 55 | struct wnm_sleep_element *wnmsleep_ie; |
| 56 | u8 *wnmtfs_ie; |
| 57 | u8 wnmsleep_ie_len; |
| 58 | u16 wnmtfs_ie_len; /* possibly multiple IE(s) */ |
| 59 | enum wnm_oper tfs_oper = action == 0 ? WNM_SLEEP_TFS_REQ_IE_ADD : |
| 60 | WNM_SLEEP_TFS_REQ_IE_NONE; |
| 61 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 62 | wpa_printf(MSG_DEBUG, "WNM: Request to send WNM-Sleep Mode Request " |
| 63 | "action=%s to " MACSTR, |
| 64 | action == 0 ? "enter" : "exit", |
| 65 | MAC2STR(wpa_s->bssid)); |
| 66 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 67 | /* WNM-Sleep Mode IE */ |
| 68 | wnmsleep_ie_len = sizeof(struct wnm_sleep_element); |
| 69 | wnmsleep_ie = os_zalloc(sizeof(struct wnm_sleep_element)); |
| 70 | if (wnmsleep_ie == NULL) |
| 71 | return -1; |
| 72 | wnmsleep_ie->eid = WLAN_EID_WNMSLEEP; |
| 73 | wnmsleep_ie->len = wnmsleep_ie_len - 2; |
| 74 | wnmsleep_ie->action_type = action; |
| 75 | wnmsleep_ie->status = WNM_STATUS_SLEEP_ACCEPT; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 76 | wnmsleep_ie->intval = host_to_le16(intval); |
| 77 | wpa_hexdump(MSG_DEBUG, "WNM: WNM-Sleep Mode element", |
| 78 | (u8 *) wnmsleep_ie, wnmsleep_ie_len); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 79 | |
| 80 | /* TFS IE(s) */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 81 | if (tfs_req) { |
| 82 | wnmtfs_ie_len = wpabuf_len(tfs_req); |
| 83 | wnmtfs_ie = os_malloc(wnmtfs_ie_len); |
| 84 | if (wnmtfs_ie == NULL) { |
| 85 | os_free(wnmsleep_ie); |
| 86 | return -1; |
| 87 | } |
| 88 | os_memcpy(wnmtfs_ie, wpabuf_head(tfs_req), wnmtfs_ie_len); |
| 89 | } else { |
| 90 | wnmtfs_ie = os_zalloc(MAX_TFS_IE_LEN); |
| 91 | if (wnmtfs_ie == NULL) { |
| 92 | os_free(wnmsleep_ie); |
| 93 | return -1; |
| 94 | } |
| 95 | if (ieee80211_11_get_tfs_ie(wpa_s, wnmtfs_ie, &wnmtfs_ie_len, |
| 96 | tfs_oper)) { |
| 97 | wnmtfs_ie_len = 0; |
| 98 | os_free(wnmtfs_ie); |
| 99 | wnmtfs_ie = NULL; |
| 100 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 101 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 102 | wpa_hexdump(MSG_DEBUG, "WNM: TFS Request element", |
| 103 | (u8 *) wnmtfs_ie, wnmtfs_ie_len); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 104 | |
| 105 | mgmt = os_zalloc(sizeof(*mgmt) + wnmsleep_ie_len + wnmtfs_ie_len); |
| 106 | if (mgmt == NULL) { |
| 107 | wpa_printf(MSG_DEBUG, "MLME: Failed to allocate buffer for " |
| 108 | "WNM-Sleep Request action frame"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 109 | os_free(wnmsleep_ie); |
| 110 | os_free(wnmtfs_ie); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 111 | return -1; |
| 112 | } |
| 113 | |
| 114 | os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN); |
| 115 | os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN); |
| 116 | os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN); |
| 117 | mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 118 | WLAN_FC_STYPE_ACTION); |
| 119 | mgmt->u.action.category = WLAN_ACTION_WNM; |
| 120 | mgmt->u.action.u.wnm_sleep_req.action = WNM_SLEEP_MODE_REQ; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 121 | mgmt->u.action.u.wnm_sleep_req.dialogtoken = 1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 122 | os_memcpy(mgmt->u.action.u.wnm_sleep_req.variable, wnmsleep_ie, |
| 123 | wnmsleep_ie_len); |
| 124 | /* copy TFS IE here */ |
| 125 | if (wnmtfs_ie_len > 0) { |
| 126 | os_memcpy(mgmt->u.action.u.wnm_sleep_req.variable + |
| 127 | wnmsleep_ie_len, wnmtfs_ie, wnmtfs_ie_len); |
| 128 | } |
| 129 | |
| 130 | len = 1 + sizeof(mgmt->u.action.u.wnm_sleep_req) + wnmsleep_ie_len + |
| 131 | wnmtfs_ie_len; |
| 132 | |
| 133 | res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 134 | wpa_s->own_addr, wpa_s->bssid, |
| 135 | &mgmt->u.action.category, len, 0); |
| 136 | if (res < 0) |
| 137 | wpa_printf(MSG_DEBUG, "Failed to send WNM-Sleep Request " |
| 138 | "(action=%d, intval=%d)", action, intval); |
| 139 | |
| 140 | os_free(wnmsleep_ie); |
| 141 | os_free(wnmtfs_ie); |
| 142 | os_free(mgmt); |
| 143 | |
| 144 | return res; |
| 145 | } |
| 146 | |
| 147 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 148 | static void wnm_sleep_mode_enter_success(struct wpa_supplicant *wpa_s, |
| 149 | u8 *tfsresp_ie_start, |
| 150 | u8 *tfsresp_ie_end) |
| 151 | { |
| 152 | wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_ENTER_CONFIRM, |
| 153 | wpa_s->bssid, NULL, NULL); |
| 154 | /* remove GTK/IGTK ?? */ |
| 155 | |
| 156 | /* set the TFS Resp IE(s) */ |
| 157 | if (tfsresp_ie_start && tfsresp_ie_end && |
| 158 | tfsresp_ie_end - tfsresp_ie_start >= 0) { |
| 159 | u16 tfsresp_ie_len; |
| 160 | tfsresp_ie_len = (tfsresp_ie_end + tfsresp_ie_end[1] + 2) - |
| 161 | tfsresp_ie_start; |
| 162 | wpa_printf(MSG_DEBUG, "TFS Resp IE(s) found"); |
| 163 | /* pass the TFS Resp IE(s) to driver for processing */ |
| 164 | if (ieee80211_11_set_tfs_ie(wpa_s, wpa_s->bssid, |
| 165 | tfsresp_ie_start, |
| 166 | &tfsresp_ie_len, |
| 167 | WNM_SLEEP_TFS_RESP_IE_SET)) |
| 168 | wpa_printf(MSG_DEBUG, "WNM: Fail to set TFS Resp IE"); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | |
| 173 | static void wnm_sleep_mode_exit_success(struct wpa_supplicant *wpa_s, |
| 174 | const u8 *frm, u16 key_len_total) |
| 175 | { |
| 176 | u8 *ptr, *end; |
| 177 | u8 gtk_len; |
| 178 | |
| 179 | wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_EXIT_CONFIRM, wpa_s->bssid, |
| 180 | NULL, NULL); |
| 181 | |
| 182 | /* Install GTK/IGTK */ |
| 183 | |
| 184 | /* point to key data field */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 185 | ptr = (u8 *) frm + 1 + 2; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 186 | end = ptr + key_len_total; |
| 187 | wpa_hexdump_key(MSG_DEBUG, "WNM: Key Data", ptr, key_len_total); |
| 188 | |
| 189 | while (ptr + 1 < end) { |
| 190 | if (ptr + 2 + ptr[1] > end) { |
| 191 | wpa_printf(MSG_DEBUG, "WNM: Invalid Key Data element " |
| 192 | "length"); |
| 193 | if (end > ptr) { |
| 194 | wpa_hexdump(MSG_DEBUG, "WNM: Remaining data", |
| 195 | ptr, end - ptr); |
| 196 | } |
| 197 | break; |
| 198 | } |
| 199 | if (*ptr == WNM_SLEEP_SUBELEM_GTK) { |
| 200 | if (ptr[1] < 11 + 5) { |
| 201 | wpa_printf(MSG_DEBUG, "WNM: Too short GTK " |
| 202 | "subelem"); |
| 203 | break; |
| 204 | } |
| 205 | gtk_len = *(ptr + 4); |
| 206 | if (ptr[1] < 11 + gtk_len || |
| 207 | gtk_len < 5 || gtk_len > 32) { |
| 208 | wpa_printf(MSG_DEBUG, "WNM: Invalid GTK " |
| 209 | "subelem"); |
| 210 | break; |
| 211 | } |
| 212 | wpa_wnmsleep_install_key( |
| 213 | wpa_s->wpa, |
| 214 | WNM_SLEEP_SUBELEM_GTK, |
| 215 | ptr); |
| 216 | ptr += 13 + gtk_len; |
| 217 | #ifdef CONFIG_IEEE80211W |
| 218 | } else if (*ptr == WNM_SLEEP_SUBELEM_IGTK) { |
| 219 | if (ptr[1] < 2 + 6 + WPA_IGTK_LEN) { |
| 220 | wpa_printf(MSG_DEBUG, "WNM: Too short IGTK " |
| 221 | "subelem"); |
| 222 | break; |
| 223 | } |
| 224 | wpa_wnmsleep_install_key(wpa_s->wpa, |
| 225 | WNM_SLEEP_SUBELEM_IGTK, ptr); |
| 226 | ptr += 10 + WPA_IGTK_LEN; |
| 227 | #endif /* CONFIG_IEEE80211W */ |
| 228 | } else |
| 229 | break; /* skip the loop */ |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 234 | static void ieee802_11_rx_wnmsleep_resp(struct wpa_supplicant *wpa_s, |
| 235 | const u8 *frm, int len) |
| 236 | { |
| 237 | /* |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame^] | 238 | * Action [1] | Dialog Token [1] | Key Data Len [2] | Key Data | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 239 | * WNM-Sleep Mode IE | TFS Response IE |
| 240 | */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 241 | u8 *pos = (u8 *) frm; /* point to payload after the action field */ |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame^] | 242 | u16 key_len_total; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 243 | struct wnm_sleep_element *wnmsleep_ie = NULL; |
| 244 | /* multiple TFS Resp IE (assuming consecutive) */ |
| 245 | u8 *tfsresp_ie_start = NULL; |
| 246 | u8 *tfsresp_ie_end = NULL; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 247 | |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame^] | 248 | if (len < 3) |
| 249 | return; |
| 250 | key_len_total = WPA_GET_LE16(frm + 1); |
| 251 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 252 | wpa_printf(MSG_DEBUG, "WNM-Sleep Mode Response token=%u key_len_total=%d", |
| 253 | frm[0], key_len_total); |
| 254 | pos += 3 + key_len_total; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 255 | if (pos > frm + len) { |
| 256 | wpa_printf(MSG_INFO, "WNM: Too short frame for Key Data field"); |
| 257 | return; |
| 258 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 259 | while (pos - frm < len) { |
| 260 | u8 ie_len = *(pos + 1); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 261 | if (pos + 2 + ie_len > frm + len) { |
| 262 | wpa_printf(MSG_INFO, "WNM: Invalid IE len %u", ie_len); |
| 263 | break; |
| 264 | } |
| 265 | wpa_hexdump(MSG_DEBUG, "WNM: Element", pos, 2 + ie_len); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 266 | if (*pos == WLAN_EID_WNMSLEEP) |
| 267 | wnmsleep_ie = (struct wnm_sleep_element *) pos; |
| 268 | else if (*pos == WLAN_EID_TFS_RESP) { |
| 269 | if (!tfsresp_ie_start) |
| 270 | tfsresp_ie_start = pos; |
| 271 | tfsresp_ie_end = pos; |
| 272 | } else |
| 273 | wpa_printf(MSG_DEBUG, "EID %d not recognized", *pos); |
| 274 | pos += ie_len + 2; |
| 275 | } |
| 276 | |
| 277 | if (!wnmsleep_ie) { |
| 278 | wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found"); |
| 279 | return; |
| 280 | } |
| 281 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 282 | if (wnmsleep_ie->status == WNM_STATUS_SLEEP_ACCEPT || |
| 283 | wnmsleep_ie->status == WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 284 | wpa_printf(MSG_DEBUG, "Successfully recv WNM-Sleep Response " |
| 285 | "frame (action=%d, intval=%d)", |
| 286 | wnmsleep_ie->action_type, wnmsleep_ie->intval); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 287 | if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER) { |
| 288 | wnm_sleep_mode_enter_success(wpa_s, tfsresp_ie_start, |
| 289 | tfsresp_ie_end); |
| 290 | } else if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) { |
| 291 | wnm_sleep_mode_exit_success(wpa_s, frm, key_len_total); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 292 | } |
| 293 | } else { |
| 294 | wpa_printf(MSG_DEBUG, "Reject recv WNM-Sleep Response frame " |
| 295 | "(action=%d, intval=%d)", |
| 296 | wnmsleep_ie->action_type, wnmsleep_ie->intval); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 297 | if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 298 | wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_ENTER_FAIL, |
| 299 | wpa_s->bssid, NULL, NULL); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 300 | else if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 301 | wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_EXIT_FAIL, |
| 302 | wpa_s->bssid, NULL, NULL); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 307 | void wnm_deallocate_memory(struct wpa_supplicant *wpa_s) |
| 308 | { |
| 309 | int i; |
| 310 | |
| 311 | for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) { |
| 312 | os_free(wpa_s->wnm_neighbor_report_elements[i].tsf_info); |
| 313 | os_free(wpa_s->wnm_neighbor_report_elements[i].con_coun_str); |
| 314 | os_free(wpa_s->wnm_neighbor_report_elements[i].bss_tran_can); |
| 315 | os_free(wpa_s->wnm_neighbor_report_elements[i].bss_term_dur); |
| 316 | os_free(wpa_s->wnm_neighbor_report_elements[i].bearing); |
| 317 | os_free(wpa_s->wnm_neighbor_report_elements[i].meas_pilot); |
| 318 | os_free(wpa_s->wnm_neighbor_report_elements[i].rrm_cap); |
| 319 | os_free(wpa_s->wnm_neighbor_report_elements[i].mul_bssid); |
| 320 | } |
| 321 | |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame^] | 322 | wpa_s->wnm_num_neighbor_report = 0; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 323 | os_free(wpa_s->wnm_neighbor_report_elements); |
| 324 | wpa_s->wnm_neighbor_report_elements = NULL; |
| 325 | } |
| 326 | |
| 327 | |
| 328 | static void wnm_parse_neighbor_report_elem(struct neighbor_report *rep, |
| 329 | u8 id, u8 elen, const u8 *pos) |
| 330 | { |
| 331 | switch (id) { |
| 332 | case WNM_NEIGHBOR_TSF: |
| 333 | if (elen < 2 + 2) { |
| 334 | wpa_printf(MSG_DEBUG, "WNM: Too short TSF"); |
| 335 | break; |
| 336 | } |
| 337 | rep->tsf_info = os_zalloc(sizeof(struct tsf_info)); |
| 338 | if (rep->tsf_info == NULL) |
| 339 | break; |
| 340 | rep->tsf_info->present = 1; |
| 341 | os_memcpy(rep->tsf_info->tsf_offset, pos, 2); |
| 342 | os_memcpy(rep->tsf_info->beacon_interval, pos + 2, 2); |
| 343 | break; |
| 344 | case WNM_NEIGHBOR_CONDENSED_COUNTRY_STRING: |
| 345 | if (elen < 2) { |
| 346 | wpa_printf(MSG_DEBUG, "WNM: Too short condensed " |
| 347 | "country string"); |
| 348 | break; |
| 349 | } |
| 350 | rep->con_coun_str = |
| 351 | os_zalloc(sizeof(struct condensed_country_string)); |
| 352 | if (rep->con_coun_str == NULL) |
| 353 | break; |
| 354 | rep->con_coun_str->present = 1; |
| 355 | os_memcpy(rep->con_coun_str->country_string, pos, 2); |
| 356 | break; |
| 357 | case WNM_NEIGHBOR_BSS_TRANSITION_CANDIDATE: |
| 358 | if (elen < 1) { |
| 359 | wpa_printf(MSG_DEBUG, "WNM: Too short BSS transition " |
| 360 | "candidate"); |
| 361 | break; |
| 362 | } |
| 363 | rep->bss_tran_can = |
| 364 | os_zalloc(sizeof(struct bss_transition_candidate)); |
| 365 | if (rep->bss_tran_can == NULL) |
| 366 | break; |
| 367 | rep->bss_tran_can->present = 1; |
| 368 | rep->bss_tran_can->preference = pos[0]; |
| 369 | break; |
| 370 | case WNM_NEIGHBOR_BSS_TERMINATION_DURATION: |
| 371 | if (elen < 12) { |
| 372 | wpa_printf(MSG_DEBUG, "WNM: Too short BSS termination " |
| 373 | "duration"); |
| 374 | break; |
| 375 | } |
| 376 | rep->bss_term_dur = |
| 377 | os_zalloc(sizeof(struct bss_termination_duration)); |
| 378 | if (rep->bss_term_dur == NULL) |
| 379 | break; |
| 380 | rep->bss_term_dur->present = 1; |
| 381 | os_memcpy(rep->bss_term_dur->duration, pos, 12); |
| 382 | break; |
| 383 | case WNM_NEIGHBOR_BEARING: |
| 384 | if (elen < 8) { |
| 385 | wpa_printf(MSG_DEBUG, "WNM: Too short neighbor " |
| 386 | "bearing"); |
| 387 | break; |
| 388 | } |
| 389 | rep->bearing = os_zalloc(sizeof(struct bearing)); |
| 390 | if (rep->bearing == NULL) |
| 391 | break; |
| 392 | rep->bearing->present = 1; |
| 393 | os_memcpy(rep->bearing->bearing, pos, 8); |
| 394 | break; |
| 395 | case WNM_NEIGHBOR_MEASUREMENT_PILOT: |
| 396 | if (elen < 2) { |
| 397 | wpa_printf(MSG_DEBUG, "WNM: Too short measurement " |
| 398 | "pilot"); |
| 399 | break; |
| 400 | } |
| 401 | rep->meas_pilot = os_zalloc(sizeof(struct measurement_pilot)); |
| 402 | if (rep->meas_pilot == NULL) |
| 403 | break; |
| 404 | rep->meas_pilot->present = 1; |
| 405 | rep->meas_pilot->measurement_pilot = pos[0]; |
| 406 | rep->meas_pilot->num_vendor_specific = pos[1]; |
| 407 | os_memcpy(rep->meas_pilot->vendor_specific, pos + 2, elen - 2); |
| 408 | break; |
| 409 | case WNM_NEIGHBOR_RRM_ENABLED_CAPABILITIES: |
| 410 | if (elen < 4) { |
| 411 | wpa_printf(MSG_DEBUG, "WNM: Too short RRM enabled " |
| 412 | "capabilities"); |
| 413 | break; |
| 414 | } |
| 415 | rep->rrm_cap = |
| 416 | os_zalloc(sizeof(struct rrm_enabled_capabilities)); |
| 417 | if (rep->rrm_cap == NULL) |
| 418 | break; |
| 419 | rep->rrm_cap->present = 1; |
| 420 | os_memcpy(rep->rrm_cap->capabilities, pos, 4); |
| 421 | break; |
| 422 | case WNM_NEIGHBOR_MULTIPLE_BSSID: |
| 423 | if (elen < 2) { |
| 424 | wpa_printf(MSG_DEBUG, "WNM: Too short multiple BSSID"); |
| 425 | break; |
| 426 | } |
| 427 | rep->mul_bssid = os_zalloc(sizeof(struct multiple_bssid)); |
| 428 | if (rep->mul_bssid == NULL) |
| 429 | break; |
| 430 | rep->mul_bssid->present = 1; |
| 431 | rep->mul_bssid->max_bssid_indicator = pos[0]; |
| 432 | rep->mul_bssid->num_vendor_specific = pos[1]; |
| 433 | os_memcpy(rep->mul_bssid->vendor_specific, pos + 2, elen - 2); |
| 434 | break; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | |
| 439 | static void wnm_parse_neighbor_report(struct wpa_supplicant *wpa_s, |
| 440 | const u8 *pos, u8 len, |
| 441 | struct neighbor_report *rep) |
| 442 | { |
| 443 | u8 left = len; |
| 444 | |
| 445 | if (left < 13) { |
| 446 | wpa_printf(MSG_DEBUG, "WNM: Too short neighbor report"); |
| 447 | return; |
| 448 | } |
| 449 | |
| 450 | os_memcpy(rep->bssid, pos, ETH_ALEN); |
| 451 | os_memcpy(rep->bssid_information, pos + ETH_ALEN, 4); |
| 452 | rep->regulatory_class = *(pos + 10); |
| 453 | rep->channel_number = *(pos + 11); |
| 454 | rep->phy_type = *(pos + 12); |
| 455 | |
| 456 | pos += 13; |
| 457 | left -= 13; |
| 458 | |
| 459 | while (left >= 2) { |
| 460 | u8 id, elen; |
| 461 | |
| 462 | id = *pos++; |
| 463 | elen = *pos++; |
| 464 | wnm_parse_neighbor_report_elem(rep, id, elen, pos); |
| 465 | left -= 2 + elen; |
| 466 | pos += elen; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | |
| 471 | static int compare_scan_neighbor_results(struct wpa_supplicant *wpa_s, |
| 472 | struct wpa_scan_results *scan_res, |
| 473 | struct neighbor_report *neigh_rep, |
| 474 | u8 num_neigh_rep, u8 *bssid_to_connect) |
| 475 | { |
| 476 | |
| 477 | u8 i, j; |
| 478 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 479 | if (scan_res == NULL || num_neigh_rep == 0 || !wpa_s->current_bss) |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 480 | return 0; |
| 481 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 482 | wpa_printf(MSG_DEBUG, "WNM: Current BSS " MACSTR " RSSI %d", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 483 | MAC2STR(wpa_s->bssid), wpa_s->current_bss->level); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 484 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 485 | for (i = 0; i < num_neigh_rep; i++) { |
| 486 | for (j = 0; j < scan_res->num; j++) { |
| 487 | /* Check for a better RSSI AP */ |
| 488 | if (os_memcmp(scan_res->res[j]->bssid, |
| 489 | neigh_rep[i].bssid, ETH_ALEN) == 0 && |
| 490 | scan_res->res[j]->level > |
| 491 | wpa_s->current_bss->level) { |
| 492 | /* Got a BSSID with better RSSI value */ |
| 493 | os_memcpy(bssid_to_connect, neigh_rep[i].bssid, |
| 494 | ETH_ALEN); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 495 | wpa_printf(MSG_DEBUG, "Found a BSS " MACSTR |
| 496 | " with better scan RSSI %d", |
| 497 | MAC2STR(scan_res->res[j]->bssid), |
| 498 | scan_res->res[j]->level); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 499 | return 1; |
| 500 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 501 | wpa_printf(MSG_DEBUG, "scan_res[%d] " MACSTR |
| 502 | " RSSI %d", j, |
| 503 | MAC2STR(scan_res->res[j]->bssid), |
| 504 | scan_res->res[j]->level); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 512 | static void wnm_send_bss_transition_mgmt_resp( |
| 513 | struct wpa_supplicant *wpa_s, u8 dialog_token, |
| 514 | enum bss_trans_mgmt_status_code status, u8 delay, |
| 515 | const u8 *target_bssid) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 516 | { |
| 517 | u8 buf[1000], *pos; |
| 518 | struct ieee80211_mgmt *mgmt; |
| 519 | size_t len; |
| 520 | |
| 521 | wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Response " |
| 522 | "to " MACSTR " dialog_token=%u status=%u delay=%d", |
| 523 | MAC2STR(wpa_s->bssid), dialog_token, status, delay); |
| 524 | |
| 525 | mgmt = (struct ieee80211_mgmt *) buf; |
| 526 | os_memset(&buf, 0, sizeof(buf)); |
| 527 | os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN); |
| 528 | os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN); |
| 529 | os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN); |
| 530 | mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 531 | WLAN_FC_STYPE_ACTION); |
| 532 | mgmt->u.action.category = WLAN_ACTION_WNM; |
| 533 | mgmt->u.action.u.bss_tm_resp.action = WNM_BSS_TRANS_MGMT_RESP; |
| 534 | mgmt->u.action.u.bss_tm_resp.dialog_token = dialog_token; |
| 535 | mgmt->u.action.u.bss_tm_resp.status_code = status; |
| 536 | mgmt->u.action.u.bss_tm_resp.bss_termination_delay = delay; |
| 537 | pos = mgmt->u.action.u.bss_tm_resp.variable; |
| 538 | if (target_bssid) { |
| 539 | os_memcpy(pos, target_bssid, ETH_ALEN); |
| 540 | pos += ETH_ALEN; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 541 | } else if (status == WNM_BSS_TM_ACCEPT) { |
| 542 | /* |
| 543 | * P802.11-REVmc clarifies that the Target BSSID field is always |
| 544 | * present when status code is zero, so use a fake value here if |
| 545 | * no BSSID is yet known. |
| 546 | */ |
| 547 | os_memset(pos, 0, ETH_ALEN); |
| 548 | pos += ETH_ALEN; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | len = pos - (u8 *) &mgmt->u.action.category; |
| 552 | |
| 553 | wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 554 | wpa_s->own_addr, wpa_s->bssid, |
| 555 | &mgmt->u.action.category, len, 0); |
| 556 | } |
| 557 | |
| 558 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 559 | void wnm_scan_response(struct wpa_supplicant *wpa_s, |
| 560 | struct wpa_scan_results *scan_res) |
| 561 | { |
| 562 | u8 bssid[ETH_ALEN]; |
| 563 | |
| 564 | if (scan_res == NULL) { |
| 565 | wpa_printf(MSG_ERROR, "Scan result is NULL"); |
| 566 | goto send_bss_resp_fail; |
| 567 | } |
| 568 | |
| 569 | /* Compare the Neighbor Report and scan results */ |
| 570 | if (compare_scan_neighbor_results(wpa_s, scan_res, |
| 571 | wpa_s->wnm_neighbor_report_elements, |
| 572 | wpa_s->wnm_num_neighbor_report, |
| 573 | bssid) == 1) { |
| 574 | /* Associate to the network */ |
| 575 | struct wpa_bss *bss; |
| 576 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 577 | |
| 578 | bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 579 | if (!bss) { |
| 580 | wpa_printf(MSG_DEBUG, "WNM: Target AP not found from " |
| 581 | "BSS table"); |
| 582 | goto send_bss_resp_fail; |
| 583 | } |
| 584 | |
| 585 | /* Send the BSS Management Response - Accept */ |
| 586 | if (wpa_s->wnm_reply) { |
| 587 | wnm_send_bss_transition_mgmt_resp(wpa_s, |
| 588 | wpa_s->wnm_dialog_token, |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 589 | WNM_BSS_TM_ACCEPT, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 590 | 0, bssid); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | wpa_s->reassociate = 1; |
| 594 | wpa_supplicant_connect(wpa_s, bss, ssid); |
| 595 | wnm_deallocate_memory(wpa_s); |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | /* Send reject response for all the failures */ |
| 600 | send_bss_resp_fail: |
| 601 | wnm_deallocate_memory(wpa_s); |
| 602 | if (wpa_s->wnm_reply) { |
| 603 | wnm_send_bss_transition_mgmt_resp(wpa_s, |
| 604 | wpa_s->wnm_dialog_token, |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 605 | WNM_BSS_TM_REJECT_UNSPECIFIED, |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 606 | 0, NULL); |
| 607 | } |
| 608 | return; |
| 609 | } |
| 610 | |
| 611 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 612 | static void ieee802_11_rx_bss_trans_mgmt_req(struct wpa_supplicant *wpa_s, |
| 613 | const u8 *pos, const u8 *end, |
| 614 | int reply) |
| 615 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 616 | if (pos + 5 > end) |
| 617 | return; |
| 618 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 619 | wpa_s->wnm_dialog_token = pos[0]; |
| 620 | wpa_s->wnm_mode = pos[1]; |
| 621 | wpa_s->wnm_dissoc_timer = WPA_GET_LE16(pos + 2); |
| 622 | wpa_s->wnm_validity_interval = pos[4]; |
| 623 | wpa_s->wnm_reply = reply; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 624 | |
| 625 | wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Request: " |
| 626 | "dialog_token=%u request_mode=0x%x " |
| 627 | "disassoc_timer=%u validity_interval=%u", |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 628 | wpa_s->wnm_dialog_token, wpa_s->wnm_mode, |
| 629 | wpa_s->wnm_dissoc_timer, wpa_s->wnm_validity_interval); |
| 630 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 631 | pos += 5; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 632 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 633 | if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 634 | if (pos + 12 > end) { |
| 635 | wpa_printf(MSG_DEBUG, "WNM: Too short BSS TM Request"); |
| 636 | return; |
| 637 | } |
| 638 | os_memcpy(wpa_s->wnm_bss_termination_duration, pos, 12); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 639 | pos += 12; /* BSS Termination Duration */ |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 640 | } |
| 641 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 642 | if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 643 | char url[256]; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 644 | unsigned int beacon_int; |
| 645 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 646 | if (pos + 1 > end || pos + 1 + pos[0] > end) { |
| 647 | wpa_printf(MSG_DEBUG, "WNM: Invalid BSS Transition " |
| 648 | "Management Request (URL)"); |
| 649 | return; |
| 650 | } |
| 651 | os_memcpy(url, pos + 1, pos[0]); |
| 652 | url[pos[0]] = '\0'; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 653 | pos += 1 + pos[0]; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 654 | |
| 655 | if (wpa_s->current_bss) |
| 656 | beacon_int = wpa_s->current_bss->beacon_int; |
| 657 | else |
| 658 | beacon_int = 100; /* best guess */ |
| 659 | |
| 660 | wpa_msg(wpa_s, MSG_INFO, ESS_DISASSOC_IMMINENT "%d %u %s", |
| 661 | wpa_sm_pmf_enabled(wpa_s->wpa), |
| 662 | wpa_s->wnm_dissoc_timer * beacon_int * 128 / 125, url); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 663 | } |
| 664 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 665 | if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_DISASSOC_IMMINENT) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 666 | wpa_msg(wpa_s, MSG_INFO, "WNM: Disassociation Imminent - " |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 667 | "Disassociation Timer %u", wpa_s->wnm_dissoc_timer); |
| 668 | if (wpa_s->wnm_dissoc_timer && !wpa_s->scanning) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 669 | /* TODO: mark current BSS less preferred for |
| 670 | * selection */ |
| 671 | wpa_printf(MSG_DEBUG, "Trying to find another BSS"); |
| 672 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 673 | } |
| 674 | } |
| 675 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 676 | if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED) { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 677 | wpa_msg(wpa_s, MSG_INFO, "WNM: Preferred List Available"); |
| 678 | wpa_s->wnm_num_neighbor_report = 0; |
| 679 | os_free(wpa_s->wnm_neighbor_report_elements); |
| 680 | wpa_s->wnm_neighbor_report_elements = os_zalloc( |
| 681 | WNM_MAX_NEIGHBOR_REPORT * |
| 682 | sizeof(struct neighbor_report)); |
| 683 | if (wpa_s->wnm_neighbor_report_elements == NULL) |
| 684 | return; |
| 685 | |
| 686 | while (pos + 2 <= end && |
| 687 | wpa_s->wnm_num_neighbor_report < WNM_MAX_NEIGHBOR_REPORT) |
| 688 | { |
| 689 | u8 tag = *pos++; |
| 690 | u8 len = *pos++; |
| 691 | |
| 692 | wpa_printf(MSG_DEBUG, "WNM: Neighbor report tag %u", |
| 693 | tag); |
| 694 | if (pos + len > end) { |
| 695 | wpa_printf(MSG_DEBUG, "WNM: Truncated request"); |
| 696 | return; |
| 697 | } |
| 698 | wnm_parse_neighbor_report( |
| 699 | wpa_s, pos, len, |
| 700 | &wpa_s->wnm_neighbor_report_elements[ |
| 701 | wpa_s->wnm_num_neighbor_report]); |
| 702 | |
| 703 | pos += len; |
| 704 | wpa_s->wnm_num_neighbor_report++; |
| 705 | } |
| 706 | |
| 707 | wpa_s->scan_res_handler = wnm_scan_response; |
| 708 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 709 | } else if (reply) { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 710 | enum bss_trans_mgmt_status_code status; |
| 711 | if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT) |
| 712 | status = WNM_BSS_TM_ACCEPT; |
| 713 | else { |
| 714 | wpa_msg(wpa_s, MSG_INFO, "WNM: BSS Transition Management Request did not include candidates"); |
| 715 | status = WNM_BSS_TM_REJECT_UNSPECIFIED; |
| 716 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 717 | wnm_send_bss_transition_mgmt_resp(wpa_s, |
| 718 | wpa_s->wnm_dialog_token, |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 719 | status, 0, NULL); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | |
| 723 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 724 | int wnm_send_bss_transition_mgmt_query(struct wpa_supplicant *wpa_s, |
| 725 | u8 query_reason) |
| 726 | { |
| 727 | u8 buf[1000], *pos; |
| 728 | struct ieee80211_mgmt *mgmt; |
| 729 | size_t len; |
| 730 | int ret; |
| 731 | |
| 732 | wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Query to " |
| 733 | MACSTR " query_reason=%u", |
| 734 | MAC2STR(wpa_s->bssid), query_reason); |
| 735 | |
| 736 | mgmt = (struct ieee80211_mgmt *) buf; |
| 737 | os_memset(&buf, 0, sizeof(buf)); |
| 738 | os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN); |
| 739 | os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN); |
| 740 | os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN); |
| 741 | mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 742 | WLAN_FC_STYPE_ACTION); |
| 743 | mgmt->u.action.category = WLAN_ACTION_WNM; |
| 744 | mgmt->u.action.u.bss_tm_query.action = WNM_BSS_TRANS_MGMT_QUERY; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 745 | mgmt->u.action.u.bss_tm_query.dialog_token = 1; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 746 | mgmt->u.action.u.bss_tm_query.query_reason = query_reason; |
| 747 | pos = mgmt->u.action.u.bss_tm_query.variable; |
| 748 | |
| 749 | len = pos - (u8 *) &mgmt->u.action.category; |
| 750 | |
| 751 | ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 752 | wpa_s->own_addr, wpa_s->bssid, |
| 753 | &mgmt->u.action.category, len, 0); |
| 754 | |
| 755 | return ret; |
| 756 | } |
| 757 | |
| 758 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 759 | static void ieee802_11_rx_wnm_notif_req_wfa(struct wpa_supplicant *wpa_s, |
| 760 | const u8 *sa, const u8 *data, |
| 761 | int len) |
| 762 | { |
| 763 | const u8 *pos, *end, *next; |
| 764 | u8 ie, ie_len; |
| 765 | |
| 766 | pos = data; |
| 767 | end = data + len; |
| 768 | |
| 769 | while (pos + 1 < end) { |
| 770 | ie = *pos++; |
| 771 | ie_len = *pos++; |
| 772 | wpa_printf(MSG_DEBUG, "WNM: WFA subelement %u len %u", |
| 773 | ie, ie_len); |
| 774 | if (ie_len > end - pos) { |
| 775 | wpa_printf(MSG_DEBUG, "WNM: Not enough room for " |
| 776 | "subelement"); |
| 777 | break; |
| 778 | } |
| 779 | next = pos + ie_len; |
| 780 | if (ie_len < 4) { |
| 781 | pos = next; |
| 782 | continue; |
| 783 | } |
| 784 | wpa_printf(MSG_DEBUG, "WNM: Subelement OUI %06x type %u", |
| 785 | WPA_GET_BE24(pos), pos[3]); |
| 786 | |
| 787 | #ifdef CONFIG_HS20 |
| 788 | if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 5 && |
| 789 | WPA_GET_BE24(pos) == OUI_WFA && |
| 790 | pos[3] == HS20_WNM_SUB_REM_NEEDED) { |
| 791 | /* Subscription Remediation subelement */ |
| 792 | const u8 *ie_end; |
| 793 | u8 url_len; |
| 794 | char *url; |
| 795 | u8 osu_method; |
| 796 | |
| 797 | wpa_printf(MSG_DEBUG, "WNM: Subscription Remediation " |
| 798 | "subelement"); |
| 799 | ie_end = pos + ie_len; |
| 800 | pos += 4; |
| 801 | url_len = *pos++; |
| 802 | if (url_len == 0) { |
| 803 | wpa_printf(MSG_DEBUG, "WNM: No Server URL included"); |
| 804 | url = NULL; |
| 805 | osu_method = 1; |
| 806 | } else { |
| 807 | if (pos + url_len + 1 > ie_end) { |
| 808 | wpa_printf(MSG_DEBUG, "WNM: Not enough room for Server URL (len=%u) and Server Method (left %d)", |
| 809 | url_len, |
| 810 | (int) (ie_end - pos)); |
| 811 | break; |
| 812 | } |
| 813 | url = os_malloc(url_len + 1); |
| 814 | if (url == NULL) |
| 815 | break; |
| 816 | os_memcpy(url, pos, url_len); |
| 817 | url[url_len] = '\0'; |
| 818 | osu_method = pos[url_len]; |
| 819 | } |
| 820 | hs20_rx_subscription_remediation(wpa_s, url, |
| 821 | osu_method); |
| 822 | os_free(url); |
| 823 | pos = next; |
| 824 | continue; |
| 825 | } |
| 826 | |
| 827 | if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 8 && |
| 828 | WPA_GET_BE24(pos) == OUI_WFA && |
| 829 | pos[3] == HS20_WNM_DEAUTH_IMMINENT_NOTICE) { |
| 830 | const u8 *ie_end; |
| 831 | u8 url_len; |
| 832 | char *url; |
| 833 | u8 code; |
| 834 | u16 reauth_delay; |
| 835 | |
| 836 | ie_end = pos + ie_len; |
| 837 | pos += 4; |
| 838 | code = *pos++; |
| 839 | reauth_delay = WPA_GET_LE16(pos); |
| 840 | pos += 2; |
| 841 | url_len = *pos++; |
| 842 | wpa_printf(MSG_DEBUG, "WNM: HS 2.0 Deauthentication " |
| 843 | "Imminent - Reason Code %u " |
| 844 | "Re-Auth Delay %u URL Length %u", |
| 845 | code, reauth_delay, url_len); |
| 846 | if (pos + url_len > ie_end) |
| 847 | break; |
| 848 | url = os_malloc(url_len + 1); |
| 849 | if (url == NULL) |
| 850 | break; |
| 851 | os_memcpy(url, pos, url_len); |
| 852 | url[url_len] = '\0'; |
| 853 | hs20_rx_deauth_imminent_notice(wpa_s, code, |
| 854 | reauth_delay, url); |
| 855 | os_free(url); |
| 856 | pos = next; |
| 857 | continue; |
| 858 | } |
| 859 | #endif /* CONFIG_HS20 */ |
| 860 | |
| 861 | pos = next; |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | |
| 866 | static void ieee802_11_rx_wnm_notif_req(struct wpa_supplicant *wpa_s, |
| 867 | const u8 *sa, const u8 *frm, int len) |
| 868 | { |
| 869 | const u8 *pos, *end; |
| 870 | u8 dialog_token, type; |
| 871 | |
| 872 | /* Dialog Token [1] | Type [1] | Subelements */ |
| 873 | |
| 874 | if (len < 2 || sa == NULL) |
| 875 | return; |
| 876 | end = frm + len; |
| 877 | pos = frm; |
| 878 | dialog_token = *pos++; |
| 879 | type = *pos++; |
| 880 | |
| 881 | wpa_dbg(wpa_s, MSG_DEBUG, "WNM: Received WNM-Notification Request " |
| 882 | "(dialog_token %u type %u sa " MACSTR ")", |
| 883 | dialog_token, type, MAC2STR(sa)); |
| 884 | wpa_hexdump(MSG_DEBUG, "WNM-Notification Request subelements", |
| 885 | pos, end - pos); |
| 886 | |
| 887 | if (wpa_s->wpa_state != WPA_COMPLETED || |
| 888 | os_memcmp(sa, wpa_s->bssid, ETH_ALEN) != 0) { |
| 889 | wpa_dbg(wpa_s, MSG_DEBUG, "WNM: WNM-Notification frame not " |
| 890 | "from our AP - ignore it"); |
| 891 | return; |
| 892 | } |
| 893 | |
| 894 | switch (type) { |
| 895 | case 1: |
| 896 | ieee802_11_rx_wnm_notif_req_wfa(wpa_s, sa, pos, end - pos); |
| 897 | break; |
| 898 | default: |
| 899 | wpa_dbg(wpa_s, MSG_DEBUG, "WNM: Ignore unknown " |
| 900 | "WNM-Notification type %u", type); |
| 901 | break; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 906 | void ieee802_11_rx_wnm_action(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 907 | const struct ieee80211_mgmt *mgmt, size_t len) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 908 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 909 | const u8 *pos, *end; |
| 910 | u8 act; |
| 911 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 912 | if (len < IEEE80211_HDRLEN + 2) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 913 | return; |
| 914 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 915 | pos = &mgmt->u.action.category; |
| 916 | pos++; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 917 | act = *pos++; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 918 | end = ((const u8 *) mgmt) + len; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 919 | |
| 920 | wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 921 | act, MAC2STR(mgmt->sa)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 922 | if (wpa_s->wpa_state < WPA_ASSOCIATED || |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 923 | os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) != 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 924 | wpa_printf(MSG_DEBUG, "WNM: Ignore unexpected WNM Action " |
| 925 | "frame"); |
| 926 | return; |
| 927 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 928 | |
| 929 | switch (act) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 930 | case WNM_BSS_TRANS_MGMT_REQ: |
| 931 | ieee802_11_rx_bss_trans_mgmt_req(wpa_s, pos, end, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 932 | !(mgmt->da[0] & 0x01)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 933 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 934 | case WNM_SLEEP_MODE_RESP: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 935 | ieee802_11_rx_wnmsleep_resp(wpa_s, pos, end - pos); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 936 | break; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 937 | case WNM_NOTIFICATION_REQ: |
| 938 | ieee802_11_rx_wnm_notif_req(wpa_s, mgmt->sa, pos, end - pos); |
| 939 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 940 | default: |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 941 | wpa_printf(MSG_ERROR, "WNM: Unknown request"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 942 | break; |
| 943 | } |
| 944 | } |