Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * wpa_supplicant - DPP |
| 3 | * Copyright (c) 2017, Qualcomm Atheros, Inc. |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4 | * Copyright (c) 2018-2020, The Linux Foundation |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5 | * |
| 6 | * This software may be distributed under the terms of the BSD license. |
| 7 | * See README for more details. |
| 8 | */ |
| 9 | |
| 10 | #include "utils/includes.h" |
| 11 | |
| 12 | #include "utils/common.h" |
| 13 | #include "utils/eloop.h" |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 14 | #include "utils/ip_addr.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 15 | #include "common/dpp.h" |
| 16 | #include "common/gas.h" |
| 17 | #include "common/gas_server.h" |
| 18 | #include "rsn_supp/wpa.h" |
| 19 | #include "rsn_supp/pmksa_cache.h" |
| 20 | #include "wpa_supplicant_i.h" |
| 21 | #include "config.h" |
| 22 | #include "driver_i.h" |
| 23 | #include "offchannel.h" |
| 24 | #include "gas_query.h" |
| 25 | #include "bss.h" |
| 26 | #include "scan.h" |
| 27 | #include "notify.h" |
| 28 | #include "dpp_supplicant.h" |
Hai Shalom | 5953285 | 2018-12-07 10:32:58 -0800 | [diff] [blame] | 29 | #include "hidl.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 30 | |
| 31 | |
| 32 | static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s, |
| 33 | unsigned int freq); |
| 34 | static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx); |
| 35 | static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator); |
| 36 | static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s, |
| 37 | unsigned int freq, const u8 *dst, |
| 38 | const u8 *src, const u8 *bssid, |
| 39 | const u8 *data, size_t data_len, |
| 40 | enum offchannel_send_action_result result); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 41 | static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx); |
| 42 | static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s); |
| 43 | static void |
| 44 | wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s, |
| 45 | unsigned int freq, const u8 *dst, |
| 46 | const u8 *src, const u8 *bssid, |
| 47 | const u8 *data, size_t data_len, |
| 48 | enum offchannel_send_action_result result); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 49 | |
| 50 | static const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
| 51 | |
| 52 | /* Use a hardcoded Transaction ID 1 in Peer Discovery frames since there is only |
| 53 | * a single transaction in progress at any point in time. */ |
| 54 | static const u8 TRANSACTION_ID = 1; |
| 55 | |
| 56 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 57 | /** |
| 58 | * wpas_dpp_qr_code - Parse and add DPP bootstrapping info from a QR Code |
| 59 | * @wpa_s: Pointer to wpa_supplicant data |
| 60 | * @cmd: DPP URI read from a QR Code |
| 61 | * Returns: Identifier of the stored info or -1 on failure |
| 62 | */ |
| 63 | int wpas_dpp_qr_code(struct wpa_supplicant *wpa_s, const char *cmd) |
| 64 | { |
| 65 | struct dpp_bootstrap_info *bi; |
| 66 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 67 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 68 | bi = dpp_add_qr_code(wpa_s->dpp, cmd); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 69 | if (!bi) |
| 70 | return -1; |
| 71 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 72 | if (auth && auth->response_pending && |
| 73 | dpp_notify_new_qr_code(auth, bi) == 1) { |
| 74 | wpa_printf(MSG_DEBUG, |
| 75 | "DPP: Sending out pending authentication response"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 76 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR |
| 77 | " freq=%u type=%d", |
| 78 | MAC2STR(auth->peer_mac_addr), auth->curr_freq, |
| 79 | DPP_PA_AUTHENTICATION_RESP); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 80 | offchannel_send_action(wpa_s, auth->curr_freq, |
| 81 | auth->peer_mac_addr, wpa_s->own_addr, |
| 82 | broadcast, |
| 83 | wpabuf_head(auth->resp_msg), |
| 84 | wpabuf_len(auth->resp_msg), |
| 85 | 500, wpas_dpp_tx_status, 0); |
| 86 | } |
| 87 | |
| 88 | return bi->id; |
| 89 | } |
| 90 | |
| 91 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 92 | /** |
| 93 | * wpas_dpp_nfc_uri - Parse and add DPP bootstrapping info from NFC Tag (URI) |
| 94 | * @wpa_s: Pointer to wpa_supplicant data |
| 95 | * @cmd: DPP URI read from a NFC Tag (URI NDEF message) |
| 96 | * Returns: Identifier of the stored info or -1 on failure |
| 97 | */ |
| 98 | int wpas_dpp_nfc_uri(struct wpa_supplicant *wpa_s, const char *cmd) |
| 99 | { |
| 100 | struct dpp_bootstrap_info *bi; |
| 101 | |
| 102 | bi = dpp_add_nfc_uri(wpa_s->dpp, cmd); |
| 103 | if (!bi) |
| 104 | return -1; |
| 105 | |
| 106 | return bi->id; |
| 107 | } |
| 108 | |
| 109 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 110 | int wpas_dpp_nfc_handover_req(struct wpa_supplicant *wpa_s, const char *cmd) |
| 111 | { |
| 112 | const char *pos; |
| 113 | struct dpp_bootstrap_info *peer_bi, *own_bi; |
| 114 | |
| 115 | pos = os_strstr(cmd, " own="); |
| 116 | if (!pos) |
| 117 | return -1; |
| 118 | pos += 5; |
| 119 | own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos)); |
| 120 | if (!own_bi) |
| 121 | return -1; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 122 | own_bi->nfc_negotiated = 1; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 123 | |
| 124 | pos = os_strstr(cmd, " uri="); |
| 125 | if (!pos) |
| 126 | return -1; |
| 127 | pos += 5; |
| 128 | peer_bi = dpp_add_nfc_uri(wpa_s->dpp, pos); |
| 129 | if (!peer_bi) { |
| 130 | wpa_printf(MSG_INFO, |
| 131 | "DPP: Failed to parse URI from NFC Handover Request"); |
| 132 | return -1; |
| 133 | } |
| 134 | |
| 135 | if (dpp_nfc_update_bi(own_bi, peer_bi) < 0) |
| 136 | return -1; |
| 137 | |
| 138 | return peer_bi->id; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | int wpas_dpp_nfc_handover_sel(struct wpa_supplicant *wpa_s, const char *cmd) |
| 143 | { |
| 144 | const char *pos; |
| 145 | struct dpp_bootstrap_info *peer_bi, *own_bi; |
| 146 | |
| 147 | pos = os_strstr(cmd, " own="); |
| 148 | if (!pos) |
| 149 | return -1; |
| 150 | pos += 5; |
| 151 | own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos)); |
| 152 | if (!own_bi) |
| 153 | return -1; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 154 | own_bi->nfc_negotiated = 1; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 155 | |
| 156 | pos = os_strstr(cmd, " uri="); |
| 157 | if (!pos) |
| 158 | return -1; |
| 159 | pos += 5; |
| 160 | peer_bi = dpp_add_nfc_uri(wpa_s->dpp, pos); |
| 161 | if (!peer_bi) { |
| 162 | wpa_printf(MSG_INFO, |
| 163 | "DPP: Failed to parse URI from NFC Handover Select"); |
| 164 | return -1; |
| 165 | } |
| 166 | |
| 167 | if (peer_bi->curve != own_bi->curve) { |
| 168 | wpa_printf(MSG_INFO, |
| 169 | "DPP: Peer (NFC Handover Selector) used different curve"); |
| 170 | return -1; |
| 171 | } |
| 172 | |
| 173 | return peer_bi->id; |
| 174 | } |
| 175 | |
| 176 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 177 | static void wpas_dpp_auth_resp_retry_timeout(void *eloop_ctx, void *timeout_ctx) |
| 178 | { |
| 179 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 180 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 181 | |
| 182 | if (!auth || !auth->resp_msg) |
| 183 | return; |
| 184 | |
| 185 | wpa_printf(MSG_DEBUG, |
| 186 | "DPP: Retry Authentication Response after timeout"); |
| 187 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR |
| 188 | " freq=%u type=%d", |
| 189 | MAC2STR(auth->peer_mac_addr), auth->curr_freq, |
| 190 | DPP_PA_AUTHENTICATION_RESP); |
| 191 | offchannel_send_action(wpa_s, auth->curr_freq, auth->peer_mac_addr, |
| 192 | wpa_s->own_addr, broadcast, |
| 193 | wpabuf_head(auth->resp_msg), |
| 194 | wpabuf_len(auth->resp_msg), |
| 195 | 500, wpas_dpp_tx_status, 0); |
| 196 | } |
| 197 | |
| 198 | |
| 199 | static void wpas_dpp_auth_resp_retry(struct wpa_supplicant *wpa_s) |
| 200 | { |
| 201 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 202 | unsigned int wait_time, max_tries; |
| 203 | |
| 204 | if (!auth || !auth->resp_msg) |
| 205 | return; |
| 206 | |
| 207 | if (wpa_s->dpp_resp_max_tries) |
| 208 | max_tries = wpa_s->dpp_resp_max_tries; |
| 209 | else |
| 210 | max_tries = 5; |
| 211 | auth->auth_resp_tries++; |
| 212 | if (auth->auth_resp_tries >= max_tries) { |
| 213 | wpa_printf(MSG_INFO, "DPP: No confirm received from initiator - stopping exchange"); |
| 214 | offchannel_send_action_done(wpa_s); |
| 215 | dpp_auth_deinit(wpa_s->dpp_auth); |
| 216 | wpa_s->dpp_auth = NULL; |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | if (wpa_s->dpp_resp_retry_time) |
| 221 | wait_time = wpa_s->dpp_resp_retry_time; |
| 222 | else |
| 223 | wait_time = 1000; |
| 224 | wpa_printf(MSG_DEBUG, |
| 225 | "DPP: Schedule retransmission of Authentication Response frame in %u ms", |
| 226 | wait_time); |
| 227 | eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL); |
| 228 | eloop_register_timeout(wait_time / 1000, |
| 229 | (wait_time % 1000) * 1000, |
| 230 | wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL); |
| 231 | } |
| 232 | |
| 233 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 234 | static void wpas_dpp_try_to_connect(struct wpa_supplicant *wpa_s) |
| 235 | { |
| 236 | wpa_printf(MSG_DEBUG, "DPP: Trying to connect to the new network"); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 237 | wpa_s->suitable_network = 0; |
| 238 | wpa_s->no_suitable_network = 0; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 239 | wpa_s->disconnected = 0; |
| 240 | wpa_s->reassociate = 1; |
| 241 | wpa_s->scan_runs = 0; |
| 242 | wpa_s->normal_scans = 0; |
| 243 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 244 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 245 | } |
| 246 | |
| 247 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 248 | #ifdef CONFIG_DPP2 |
| 249 | |
| 250 | static void wpas_dpp_conn_status_result_timeout(void *eloop_ctx, |
| 251 | void *timeout_ctx) |
| 252 | { |
| 253 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 254 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 255 | enum dpp_status_error result; |
| 256 | |
| 257 | if (!auth || !auth->conn_status_requested) |
| 258 | return; |
| 259 | |
| 260 | wpa_printf(MSG_DEBUG, |
| 261 | "DPP: Connection timeout - report Connection Status Result"); |
| 262 | if (wpa_s->suitable_network) |
| 263 | result = DPP_STATUS_AUTH_FAILURE; |
| 264 | else if (wpa_s->no_suitable_network) |
| 265 | result = DPP_STATUS_NO_AP; |
| 266 | else |
| 267 | result = 255; /* What to report here for unexpected state? */ |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 268 | if (wpa_s->wpa_state == WPA_SCANNING) |
| 269 | wpas_abort_ongoing_scan(wpa_s); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 270 | wpas_dpp_send_conn_status_result(wpa_s, result); |
| 271 | } |
| 272 | |
| 273 | |
| 274 | static char * wpas_dpp_scan_channel_list(struct wpa_supplicant *wpa_s) |
| 275 | { |
| 276 | char *str, *end, *pos; |
| 277 | size_t len; |
| 278 | unsigned int i; |
| 279 | u8 last_op_class = 0; |
| 280 | int res; |
| 281 | |
| 282 | if (!wpa_s->last_scan_freqs || !wpa_s->num_last_scan_freqs) |
| 283 | return NULL; |
| 284 | |
| 285 | len = wpa_s->num_last_scan_freqs * 8; |
| 286 | str = os_zalloc(len); |
| 287 | if (!str) |
| 288 | return NULL; |
| 289 | end = str + len; |
| 290 | pos = str; |
| 291 | |
| 292 | for (i = 0; i < wpa_s->num_last_scan_freqs; i++) { |
| 293 | enum hostapd_hw_mode mode; |
| 294 | u8 op_class, channel; |
| 295 | |
| 296 | mode = ieee80211_freq_to_channel_ext(wpa_s->last_scan_freqs[i], |
| 297 | 0, 0, &op_class, &channel); |
| 298 | if (mode == NUM_HOSTAPD_MODES) |
| 299 | continue; |
| 300 | if (op_class == last_op_class) |
| 301 | res = os_snprintf(pos, end - pos, ",%d", channel); |
| 302 | else |
| 303 | res = os_snprintf(pos, end - pos, "%s%d/%d", |
| 304 | pos == str ? "" : ",", |
| 305 | op_class, channel); |
| 306 | if (os_snprintf_error(end - pos, res)) { |
| 307 | *pos = '\0'; |
| 308 | break; |
| 309 | } |
| 310 | pos += res; |
| 311 | last_op_class = op_class; |
| 312 | } |
| 313 | |
| 314 | if (pos == str) { |
| 315 | os_free(str); |
| 316 | str = NULL; |
| 317 | } |
| 318 | return str; |
| 319 | } |
| 320 | |
| 321 | |
| 322 | void wpas_dpp_send_conn_status_result(struct wpa_supplicant *wpa_s, |
| 323 | enum dpp_status_error result) |
| 324 | { |
| 325 | struct wpabuf *msg; |
| 326 | const char *channel_list = NULL; |
| 327 | char *channel_list_buf = NULL; |
| 328 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 329 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 330 | |
| 331 | eloop_cancel_timeout(wpas_dpp_conn_status_result_timeout, wpa_s, NULL); |
| 332 | |
| 333 | if (!auth || !auth->conn_status_requested) |
| 334 | return; |
| 335 | auth->conn_status_requested = 0; |
| 336 | wpa_printf(MSG_DEBUG, "DPP: Report connection status result %d", |
| 337 | result); |
| 338 | |
| 339 | if (result == DPP_STATUS_NO_AP) { |
| 340 | channel_list_buf = wpas_dpp_scan_channel_list(wpa_s); |
| 341 | channel_list = channel_list_buf; |
| 342 | } |
| 343 | |
| 344 | msg = dpp_build_conn_status_result(auth, result, |
| 345 | ssid ? ssid->ssid : |
| 346 | wpa_s->dpp_last_ssid, |
| 347 | ssid ? ssid->ssid_len : |
| 348 | wpa_s->dpp_last_ssid_len, |
| 349 | channel_list); |
| 350 | os_free(channel_list_buf); |
| 351 | if (!msg) { |
| 352 | dpp_auth_deinit(wpa_s->dpp_auth); |
| 353 | wpa_s->dpp_auth = NULL; |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | wpa_msg(wpa_s, MSG_INFO, |
| 358 | DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d", |
| 359 | MAC2STR(auth->peer_mac_addr), auth->curr_freq, |
| 360 | DPP_PA_CONNECTION_STATUS_RESULT); |
| 361 | offchannel_send_action(wpa_s, auth->curr_freq, |
| 362 | auth->peer_mac_addr, wpa_s->own_addr, broadcast, |
| 363 | wpabuf_head(msg), wpabuf_len(msg), |
| 364 | 500, wpas_dpp_tx_status, 0); |
| 365 | wpabuf_free(msg); |
| 366 | |
| 367 | /* This exchange will be terminated in the TX status handler */ |
| 368 | auth->remove_on_tx_status = 1; |
| 369 | |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | |
| 374 | void wpas_dpp_connected(struct wpa_supplicant *wpa_s) |
| 375 | { |
| 376 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 377 | |
| 378 | if (auth && auth->conn_status_requested) |
| 379 | wpas_dpp_send_conn_status_result(wpa_s, DPP_STATUS_OK); |
| 380 | } |
| 381 | |
| 382 | #endif /* CONFIG_DPP2 */ |
| 383 | |
| 384 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 385 | static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s, |
| 386 | unsigned int freq, const u8 *dst, |
| 387 | const u8 *src, const u8 *bssid, |
| 388 | const u8 *data, size_t data_len, |
| 389 | enum offchannel_send_action_result result) |
| 390 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 391 | const char *res_txt; |
| 392 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 393 | |
| 394 | res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" : |
| 395 | (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" : |
| 396 | "FAILED"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 397 | wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 398 | " result=%s", freq, MAC2STR(dst), res_txt); |
| 399 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR |
| 400 | " freq=%u result=%s", MAC2STR(dst), freq, res_txt); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 401 | |
| 402 | if (!wpa_s->dpp_auth) { |
| 403 | wpa_printf(MSG_DEBUG, |
| 404 | "DPP: Ignore TX status since there is no ongoing authentication exchange"); |
| 405 | return; |
| 406 | } |
| 407 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 408 | #ifdef CONFIG_DPP2 |
| 409 | if (auth->connect_on_tx_status) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 410 | auth->connect_on_tx_status = 0; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 411 | wpa_printf(MSG_DEBUG, |
| 412 | "DPP: Try to connect after completed configuration result"); |
| 413 | wpas_dpp_try_to_connect(wpa_s); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 414 | if (auth->conn_status_requested) { |
| 415 | wpa_printf(MSG_DEBUG, |
| 416 | "DPP: Start 15 second timeout for reporting connection status result"); |
| 417 | eloop_cancel_timeout( |
| 418 | wpas_dpp_conn_status_result_timeout, |
| 419 | wpa_s, NULL); |
| 420 | eloop_register_timeout( |
| 421 | 15, 0, wpas_dpp_conn_status_result_timeout, |
| 422 | wpa_s, NULL); |
| 423 | } else { |
| 424 | dpp_auth_deinit(wpa_s->dpp_auth); |
| 425 | wpa_s->dpp_auth = NULL; |
| 426 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 427 | return; |
| 428 | } |
| 429 | #endif /* CONFIG_DPP2 */ |
| 430 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 431 | if (wpa_s->dpp_auth->remove_on_tx_status) { |
| 432 | wpa_printf(MSG_DEBUG, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 433 | "DPP: Terminate authentication exchange due to a request to do so on TX status"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 434 | eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 435 | eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 436 | eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, |
| 437 | NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 438 | offchannel_send_action_done(wpa_s); |
| 439 | dpp_auth_deinit(wpa_s->dpp_auth); |
| 440 | wpa_s->dpp_auth = NULL; |
| 441 | return; |
| 442 | } |
| 443 | |
| 444 | if (wpa_s->dpp_auth_ok_on_ack) |
| 445 | wpas_dpp_auth_success(wpa_s, 1); |
| 446 | |
| 447 | if (!is_broadcast_ether_addr(dst) && |
| 448 | result != OFFCHANNEL_SEND_ACTION_SUCCESS) { |
| 449 | wpa_printf(MSG_DEBUG, |
| 450 | "DPP: Unicast DPP Action frame was not ACKed"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 451 | if (auth->waiting_auth_resp) { |
| 452 | /* In case of DPP Authentication Request frame, move to |
| 453 | * the next channel immediately. */ |
| 454 | offchannel_send_action_done(wpa_s); |
| 455 | wpas_dpp_auth_init_next(wpa_s); |
| 456 | return; |
| 457 | } |
| 458 | if (auth->waiting_auth_conf) { |
| 459 | wpas_dpp_auth_resp_retry(wpa_s); |
| 460 | return; |
| 461 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 462 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 463 | |
| 464 | if (!is_broadcast_ether_addr(dst) && auth->waiting_auth_resp && |
| 465 | result == OFFCHANNEL_SEND_ACTION_SUCCESS) { |
| 466 | /* Allow timeout handling to stop iteration if no response is |
| 467 | * received from a peer that has ACKed a request. */ |
| 468 | auth->auth_req_ack = 1; |
| 469 | } |
| 470 | |
| 471 | if (!wpa_s->dpp_auth_ok_on_ack && wpa_s->dpp_auth->neg_freq > 0 && |
| 472 | wpa_s->dpp_auth->curr_freq != wpa_s->dpp_auth->neg_freq) { |
| 473 | wpa_printf(MSG_DEBUG, |
| 474 | "DPP: Move from curr_freq %u MHz to neg_freq %u MHz for response", |
| 475 | wpa_s->dpp_auth->curr_freq, |
| 476 | wpa_s->dpp_auth->neg_freq); |
| 477 | offchannel_send_action_done(wpa_s); |
| 478 | wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->neg_freq); |
| 479 | } |
| 480 | |
| 481 | if (wpa_s->dpp_auth_ok_on_ack) |
| 482 | wpa_s->dpp_auth_ok_on_ack = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | |
| 486 | static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx) |
| 487 | { |
| 488 | struct wpa_supplicant *wpa_s = eloop_ctx; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 489 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 490 | unsigned int freq; |
| 491 | struct os_reltime now, diff; |
| 492 | unsigned int wait_time, diff_ms; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 493 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 494 | if (!auth || !auth->waiting_auth_resp) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 495 | return; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 496 | |
| 497 | wait_time = wpa_s->dpp_resp_wait_time ? |
| 498 | wpa_s->dpp_resp_wait_time : 2000; |
| 499 | os_get_reltime(&now); |
| 500 | os_reltime_sub(&now, &wpa_s->dpp_last_init, &diff); |
| 501 | diff_ms = diff.sec * 1000 + diff.usec / 1000; |
| 502 | wpa_printf(MSG_DEBUG, |
| 503 | "DPP: Reply wait timeout - wait_time=%u diff_ms=%u", |
| 504 | wait_time, diff_ms); |
| 505 | |
| 506 | if (auth->auth_req_ack && diff_ms >= wait_time) { |
| 507 | /* Peer ACK'ed Authentication Request frame, but did not reply |
| 508 | * with Authentication Response frame within two seconds. */ |
| 509 | wpa_printf(MSG_INFO, |
| 510 | "DPP: No response received from responder - stopping initiation attempt"); |
| 511 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED); |
Hai Shalom | 706f99b | 2019-01-08 16:23:37 -0800 | [diff] [blame] | 512 | wpas_notify_dpp_timeout(wpa_s); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 513 | offchannel_send_action_done(wpa_s); |
| 514 | wpas_dpp_listen_stop(wpa_s); |
| 515 | dpp_auth_deinit(auth); |
| 516 | wpa_s->dpp_auth = NULL; |
| 517 | return; |
| 518 | } |
| 519 | |
| 520 | if (diff_ms >= wait_time) { |
| 521 | /* Authentication Request frame was not ACK'ed and no reply |
| 522 | * was receiving within two seconds. */ |
| 523 | wpa_printf(MSG_DEBUG, |
| 524 | "DPP: Continue Initiator channel iteration"); |
| 525 | offchannel_send_action_done(wpa_s); |
| 526 | wpas_dpp_listen_stop(wpa_s); |
| 527 | wpas_dpp_auth_init_next(wpa_s); |
| 528 | return; |
| 529 | } |
| 530 | |
| 531 | /* Driver did not support 2000 ms long wait_time with TX command, so |
| 532 | * schedule listen operation to continue waiting for the response. |
| 533 | * |
| 534 | * DPP listen operations continue until stopped, so simply schedule a |
| 535 | * new call to this function at the point when the two second reply |
| 536 | * wait has expired. */ |
| 537 | wait_time -= diff_ms; |
| 538 | |
| 539 | freq = auth->curr_freq; |
| 540 | if (auth->neg_freq > 0) |
| 541 | freq = auth->neg_freq; |
| 542 | wpa_printf(MSG_DEBUG, |
| 543 | "DPP: Continue reply wait on channel %u MHz for %u ms", |
| 544 | freq, wait_time); |
| 545 | wpa_s->dpp_in_response_listen = 1; |
| 546 | wpas_dpp_listen_start(wpa_s, freq); |
| 547 | |
| 548 | eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000, |
| 549 | wpas_dpp_reply_wait_timeout, wpa_s, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | |
| 553 | static void wpas_dpp_set_testing_options(struct wpa_supplicant *wpa_s, |
| 554 | struct dpp_authentication *auth) |
| 555 | { |
| 556 | #ifdef CONFIG_TESTING_OPTIONS |
| 557 | if (wpa_s->dpp_config_obj_override) |
| 558 | auth->config_obj_override = |
| 559 | os_strdup(wpa_s->dpp_config_obj_override); |
| 560 | if (wpa_s->dpp_discovery_override) |
| 561 | auth->discovery_override = |
| 562 | os_strdup(wpa_s->dpp_discovery_override); |
| 563 | if (wpa_s->dpp_groups_override) |
| 564 | auth->groups_override = |
| 565 | os_strdup(wpa_s->dpp_groups_override); |
| 566 | auth->ignore_netaccesskey_mismatch = |
| 567 | wpa_s->dpp_ignore_netaccesskey_mismatch; |
| 568 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 569 | } |
| 570 | |
| 571 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 572 | static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx) |
| 573 | { |
| 574 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 575 | |
| 576 | if (!wpa_s->dpp_auth) |
| 577 | return; |
| 578 | wpa_printf(MSG_DEBUG, "DPP: Retry initiation after timeout"); |
| 579 | wpas_dpp_auth_init_next(wpa_s); |
| 580 | } |
| 581 | |
| 582 | |
| 583 | static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s) |
| 584 | { |
| 585 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 586 | const u8 *dst; |
| 587 | unsigned int wait_time, max_wait_time, freq, max_tries, used; |
| 588 | struct os_reltime now, diff; |
| 589 | |
| 590 | wpa_s->dpp_in_response_listen = 0; |
| 591 | if (!auth) |
| 592 | return -1; |
| 593 | |
| 594 | if (auth->freq_idx == 0) |
| 595 | os_get_reltime(&wpa_s->dpp_init_iter_start); |
| 596 | |
| 597 | if (auth->freq_idx >= auth->num_freq) { |
| 598 | auth->num_freq_iters++; |
| 599 | if (wpa_s->dpp_init_max_tries) |
| 600 | max_tries = wpa_s->dpp_init_max_tries; |
| 601 | else |
| 602 | max_tries = 5; |
| 603 | if (auth->num_freq_iters >= max_tries || auth->auth_req_ack) { |
| 604 | wpa_printf(MSG_INFO, |
| 605 | "DPP: No response received from responder - stopping initiation attempt"); |
| 606 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED); |
Hai Shalom | 706f99b | 2019-01-08 16:23:37 -0800 | [diff] [blame] | 607 | wpas_notify_dpp_timeout(wpa_s); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 608 | eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, |
| 609 | wpa_s, NULL); |
| 610 | offchannel_send_action_done(wpa_s); |
| 611 | dpp_auth_deinit(wpa_s->dpp_auth); |
| 612 | wpa_s->dpp_auth = NULL; |
| 613 | return -1; |
| 614 | } |
| 615 | auth->freq_idx = 0; |
| 616 | eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL); |
| 617 | if (wpa_s->dpp_init_retry_time) |
| 618 | wait_time = wpa_s->dpp_init_retry_time; |
| 619 | else |
| 620 | wait_time = 10000; |
| 621 | os_get_reltime(&now); |
| 622 | os_reltime_sub(&now, &wpa_s->dpp_init_iter_start, &diff); |
| 623 | used = diff.sec * 1000 + diff.usec / 1000; |
| 624 | if (used > wait_time) |
| 625 | wait_time = 0; |
| 626 | else |
| 627 | wait_time -= used; |
| 628 | wpa_printf(MSG_DEBUG, "DPP: Next init attempt in %u ms", |
| 629 | wait_time); |
| 630 | eloop_register_timeout(wait_time / 1000, |
| 631 | (wait_time % 1000) * 1000, |
| 632 | wpas_dpp_init_timeout, wpa_s, |
| 633 | NULL); |
| 634 | return 0; |
| 635 | } |
| 636 | freq = auth->freq[auth->freq_idx++]; |
| 637 | auth->curr_freq = freq; |
| 638 | |
| 639 | if (is_zero_ether_addr(auth->peer_bi->mac_addr)) |
| 640 | dst = broadcast; |
| 641 | else |
| 642 | dst = auth->peer_bi->mac_addr; |
| 643 | wpa_s->dpp_auth_ok_on_ack = 0; |
| 644 | eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL); |
| 645 | wait_time = wpa_s->max_remain_on_chan; |
| 646 | max_wait_time = wpa_s->dpp_resp_wait_time ? |
| 647 | wpa_s->dpp_resp_wait_time : 2000; |
| 648 | if (wait_time > max_wait_time) |
| 649 | wait_time = max_wait_time; |
| 650 | wait_time += 10; /* give the driver some extra time to complete */ |
| 651 | eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000, |
| 652 | wpas_dpp_reply_wait_timeout, |
| 653 | wpa_s, NULL); |
| 654 | wait_time -= 10; |
| 655 | if (auth->neg_freq > 0 && freq != auth->neg_freq) { |
| 656 | wpa_printf(MSG_DEBUG, |
| 657 | "DPP: Initiate on %u MHz and move to neg_freq %u MHz for response", |
| 658 | freq, auth->neg_freq); |
| 659 | } |
| 660 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d", |
| 661 | MAC2STR(dst), freq, DPP_PA_AUTHENTICATION_REQ); |
| 662 | auth->auth_req_ack = 0; |
| 663 | os_get_reltime(&wpa_s->dpp_last_init); |
| 664 | return offchannel_send_action(wpa_s, freq, dst, |
| 665 | wpa_s->own_addr, broadcast, |
| 666 | wpabuf_head(auth->req_msg), |
| 667 | wpabuf_len(auth->req_msg), |
| 668 | wait_time, wpas_dpp_tx_status, 0); |
| 669 | } |
| 670 | |
| 671 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 672 | int wpas_dpp_auth_init(struct wpa_supplicant *wpa_s, const char *cmd) |
| 673 | { |
| 674 | const char *pos; |
| 675 | struct dpp_bootstrap_info *peer_bi, *own_bi = NULL; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 676 | struct dpp_authentication *auth; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 677 | u8 allowed_roles = DPP_CAPAB_CONFIGURATOR; |
| 678 | unsigned int neg_freq = 0; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 679 | int tcp = 0; |
| 680 | #ifdef CONFIG_DPP2 |
| 681 | int tcp_port = DPP_TCP_PORT; |
| 682 | struct hostapd_ip_addr ipaddr; |
| 683 | char *addr; |
| 684 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 685 | |
| 686 | wpa_s->dpp_gas_client = 0; |
| 687 | |
| 688 | pos = os_strstr(cmd, " peer="); |
| 689 | if (!pos) |
| 690 | return -1; |
| 691 | pos += 6; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 692 | peer_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 693 | if (!peer_bi) { |
| 694 | wpa_printf(MSG_INFO, |
| 695 | "DPP: Could not find bootstrapping info for the identified peer"); |
| 696 | return -1; |
| 697 | } |
| 698 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 699 | #ifdef CONFIG_DPP2 |
| 700 | pos = os_strstr(cmd, " tcp_port="); |
| 701 | if (pos) { |
| 702 | pos += 10; |
| 703 | tcp_port = atoi(pos); |
| 704 | } |
| 705 | |
| 706 | addr = get_param(cmd, " tcp_addr="); |
| 707 | if (addr) { |
| 708 | int res; |
| 709 | |
| 710 | res = hostapd_parse_ip_addr(addr, &ipaddr); |
| 711 | os_free(addr); |
| 712 | if (res) |
| 713 | return -1; |
| 714 | tcp = 1; |
| 715 | } |
| 716 | #endif /* CONFIG_DPP2 */ |
| 717 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 718 | pos = os_strstr(cmd, " own="); |
| 719 | if (pos) { |
| 720 | pos += 5; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 721 | own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 722 | if (!own_bi) { |
| 723 | wpa_printf(MSG_INFO, |
| 724 | "DPP: Could not find bootstrapping info for the identified local entry"); |
| 725 | return -1; |
| 726 | } |
| 727 | |
| 728 | if (peer_bi->curve != own_bi->curve) { |
| 729 | wpa_printf(MSG_INFO, |
| 730 | "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)", |
| 731 | peer_bi->curve->name, own_bi->curve->name); |
| 732 | return -1; |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | pos = os_strstr(cmd, " role="); |
| 737 | if (pos) { |
| 738 | pos += 6; |
| 739 | if (os_strncmp(pos, "configurator", 12) == 0) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 740 | allowed_roles = DPP_CAPAB_CONFIGURATOR; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 741 | else if (os_strncmp(pos, "enrollee", 8) == 0) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 742 | allowed_roles = DPP_CAPAB_ENROLLEE; |
| 743 | else if (os_strncmp(pos, "either", 6) == 0) |
| 744 | allowed_roles = DPP_CAPAB_CONFIGURATOR | |
| 745 | DPP_CAPAB_ENROLLEE; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 746 | else |
| 747 | goto fail; |
| 748 | } |
| 749 | |
| 750 | pos = os_strstr(cmd, " netrole="); |
| 751 | if (pos) { |
| 752 | pos += 9; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 753 | if (os_strncmp(pos, "ap", 2) == 0) |
| 754 | wpa_s->dpp_netrole = DPP_NETROLE_AP; |
| 755 | else if (os_strncmp(pos, "configurator", 12) == 0) |
| 756 | wpa_s->dpp_netrole = DPP_NETROLE_CONFIGURATOR; |
| 757 | else |
| 758 | wpa_s->dpp_netrole = DPP_NETROLE_STA; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 759 | } else { |
| 760 | wpa_s->dpp_netrole = DPP_NETROLE_STA; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 763 | pos = os_strstr(cmd, " neg_freq="); |
| 764 | if (pos) |
| 765 | neg_freq = atoi(pos + 10); |
| 766 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 767 | if (!tcp && wpa_s->dpp_auth) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 768 | eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 769 | eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 770 | eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, |
| 771 | NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 772 | offchannel_send_action_done(wpa_s); |
| 773 | dpp_auth_deinit(wpa_s->dpp_auth); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 774 | wpa_s->dpp_auth = NULL; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 777 | auth = dpp_auth_init(wpa_s->dpp, wpa_s, peer_bi, own_bi, allowed_roles, |
| 778 | neg_freq, wpa_s->hw.modes, wpa_s->hw.num_modes); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 779 | if (!auth) |
| 780 | goto fail; |
| 781 | wpas_dpp_set_testing_options(wpa_s, auth); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 782 | if (dpp_set_configurator(auth, cmd) < 0) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 783 | dpp_auth_deinit(auth); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 784 | goto fail; |
| 785 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 786 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 787 | auth->neg_freq = neg_freq; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 788 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 789 | if (!is_zero_ether_addr(peer_bi->mac_addr)) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 790 | os_memcpy(auth->peer_mac_addr, peer_bi->mac_addr, ETH_ALEN); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 791 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 792 | #ifdef CONFIG_DPP2 |
| 793 | if (tcp) |
| 794 | return dpp_tcp_init(wpa_s->dpp, auth, &ipaddr, tcp_port); |
| 795 | #endif /* CONFIG_DPP2 */ |
| 796 | |
| 797 | wpa_s->dpp_auth = auth; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 798 | return wpas_dpp_auth_init_next(wpa_s); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 799 | fail: |
| 800 | return -1; |
| 801 | } |
| 802 | |
| 803 | |
| 804 | struct wpas_dpp_listen_work { |
| 805 | unsigned int freq; |
| 806 | unsigned int duration; |
| 807 | struct wpabuf *probe_resp_ie; |
| 808 | }; |
| 809 | |
| 810 | |
| 811 | static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work *lwork) |
| 812 | { |
| 813 | if (!lwork) |
| 814 | return; |
| 815 | os_free(lwork); |
| 816 | } |
| 817 | |
| 818 | |
| 819 | static void wpas_dpp_listen_work_done(struct wpa_supplicant *wpa_s) |
| 820 | { |
| 821 | struct wpas_dpp_listen_work *lwork; |
| 822 | |
| 823 | if (!wpa_s->dpp_listen_work) |
| 824 | return; |
| 825 | |
| 826 | lwork = wpa_s->dpp_listen_work->ctx; |
| 827 | wpas_dpp_listen_work_free(lwork); |
| 828 | radio_work_done(wpa_s->dpp_listen_work); |
| 829 | wpa_s->dpp_listen_work = NULL; |
| 830 | } |
| 831 | |
| 832 | |
| 833 | static void dpp_start_listen_cb(struct wpa_radio_work *work, int deinit) |
| 834 | { |
| 835 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 836 | struct wpas_dpp_listen_work *lwork = work->ctx; |
| 837 | |
| 838 | if (deinit) { |
| 839 | if (work->started) { |
| 840 | wpa_s->dpp_listen_work = NULL; |
| 841 | wpas_dpp_listen_stop(wpa_s); |
| 842 | } |
| 843 | wpas_dpp_listen_work_free(lwork); |
| 844 | return; |
| 845 | } |
| 846 | |
| 847 | wpa_s->dpp_listen_work = work; |
| 848 | |
| 849 | wpa_s->dpp_pending_listen_freq = lwork->freq; |
| 850 | |
| 851 | if (wpa_drv_remain_on_channel(wpa_s, lwork->freq, |
| 852 | wpa_s->max_remain_on_chan) < 0) { |
| 853 | wpa_printf(MSG_DEBUG, |
| 854 | "DPP: Failed to request the driver to remain on channel (%u MHz) for listen", |
| 855 | lwork->freq); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 856 | wpa_s->dpp_listen_freq = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 857 | wpas_dpp_listen_work_done(wpa_s); |
| 858 | wpa_s->dpp_pending_listen_freq = 0; |
| 859 | return; |
| 860 | } |
| 861 | wpa_s->off_channel_freq = 0; |
| 862 | wpa_s->roc_waiting_drv_freq = lwork->freq; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 863 | wpa_drv_dpp_listen(wpa_s, true); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | |
| 867 | static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s, |
| 868 | unsigned int freq) |
| 869 | { |
| 870 | struct wpas_dpp_listen_work *lwork; |
| 871 | |
| 872 | if (wpa_s->dpp_listen_work) { |
| 873 | wpa_printf(MSG_DEBUG, |
| 874 | "DPP: Reject start_listen since dpp_listen_work already exists"); |
| 875 | return -1; |
| 876 | } |
| 877 | |
| 878 | if (wpa_s->dpp_listen_freq) |
| 879 | wpas_dpp_listen_stop(wpa_s); |
| 880 | wpa_s->dpp_listen_freq = freq; |
| 881 | |
| 882 | lwork = os_zalloc(sizeof(*lwork)); |
| 883 | if (!lwork) |
| 884 | return -1; |
| 885 | lwork->freq = freq; |
| 886 | |
| 887 | if (radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb, |
| 888 | lwork) < 0) { |
| 889 | wpas_dpp_listen_work_free(lwork); |
| 890 | return -1; |
| 891 | } |
| 892 | |
| 893 | return 0; |
| 894 | } |
| 895 | |
| 896 | |
| 897 | int wpas_dpp_listen(struct wpa_supplicant *wpa_s, const char *cmd) |
| 898 | { |
| 899 | int freq; |
| 900 | |
| 901 | freq = atoi(cmd); |
| 902 | if (freq <= 0) |
| 903 | return -1; |
| 904 | |
| 905 | if (os_strstr(cmd, " role=configurator")) |
| 906 | wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR; |
| 907 | else if (os_strstr(cmd, " role=enrollee")) |
| 908 | wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE; |
| 909 | else |
| 910 | wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR | |
| 911 | DPP_CAPAB_ENROLLEE; |
| 912 | wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 913 | if (os_strstr(cmd, " netrole=ap")) |
| 914 | wpa_s->dpp_netrole = DPP_NETROLE_AP; |
| 915 | else if (os_strstr(cmd, " netrole=configurator")) |
| 916 | wpa_s->dpp_netrole = DPP_NETROLE_CONFIGURATOR; |
| 917 | else |
| 918 | wpa_s->dpp_netrole = DPP_NETROLE_STA; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 919 | if (wpa_s->dpp_listen_freq == (unsigned int) freq) { |
| 920 | wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz", |
| 921 | freq); |
| 922 | return 0; |
| 923 | } |
| 924 | |
| 925 | return wpas_dpp_listen_start(wpa_s, freq); |
| 926 | } |
| 927 | |
| 928 | |
| 929 | void wpas_dpp_listen_stop(struct wpa_supplicant *wpa_s) |
| 930 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 931 | wpa_s->dpp_in_response_listen = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 932 | if (!wpa_s->dpp_listen_freq) |
| 933 | return; |
| 934 | |
| 935 | wpa_printf(MSG_DEBUG, "DPP: Stop listen on %u MHz", |
| 936 | wpa_s->dpp_listen_freq); |
| 937 | wpa_drv_cancel_remain_on_channel(wpa_s); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 938 | wpa_drv_dpp_listen(wpa_s, false); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 939 | wpa_s->dpp_listen_freq = 0; |
| 940 | wpas_dpp_listen_work_done(wpa_s); |
| 941 | } |
| 942 | |
| 943 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 944 | void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s, |
| 945 | unsigned int freq) |
| 946 | { |
| 947 | wpas_dpp_listen_work_done(wpa_s); |
| 948 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 949 | if (wpa_s->dpp_auth && wpa_s->dpp_in_response_listen) { |
| 950 | unsigned int new_freq; |
| 951 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 952 | /* Continue listen with a new remain-on-channel */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 953 | if (wpa_s->dpp_auth->neg_freq > 0) |
| 954 | new_freq = wpa_s->dpp_auth->neg_freq; |
| 955 | else |
| 956 | new_freq = wpa_s->dpp_auth->curr_freq; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 957 | wpa_printf(MSG_DEBUG, |
| 958 | "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session", |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 959 | new_freq); |
| 960 | wpas_dpp_listen_start(wpa_s, new_freq); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 961 | return; |
| 962 | } |
| 963 | |
| 964 | if (wpa_s->dpp_listen_freq) { |
| 965 | /* Continue listen with a new remain-on-channel */ |
| 966 | wpas_dpp_listen_start(wpa_s, wpa_s->dpp_listen_freq); |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | |
| 971 | static void wpas_dpp_rx_auth_req(struct wpa_supplicant *wpa_s, const u8 *src, |
| 972 | const u8 *hdr, const u8 *buf, size_t len, |
| 973 | unsigned int freq) |
| 974 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 975 | const u8 *r_bootstrap, *i_bootstrap; |
| 976 | u16 r_bootstrap_len, i_bootstrap_len; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 977 | struct dpp_bootstrap_info *own_bi = NULL, *peer_bi = NULL; |
| 978 | |
| 979 | if (!wpa_s->dpp) |
| 980 | return; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 981 | |
| 982 | wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR, |
| 983 | MAC2STR(src)); |
| 984 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 985 | #ifdef CONFIG_DPP2 |
| 986 | wpas_dpp_chirp_stop(wpa_s); |
| 987 | #endif /* CONFIG_DPP2 */ |
| 988 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 989 | r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH, |
| 990 | &r_bootstrap_len); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 991 | if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) { |
| 992 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL |
| 993 | "Missing or invalid required Responder Bootstrapping Key Hash attribute"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 994 | return; |
| 995 | } |
| 996 | wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash", |
| 997 | r_bootstrap, r_bootstrap_len); |
| 998 | |
| 999 | i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH, |
| 1000 | &i_bootstrap_len); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1001 | if (!i_bootstrap || i_bootstrap_len != SHA256_MAC_LEN) { |
| 1002 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL |
| 1003 | "Missing or invalid required Initiator Bootstrapping Key Hash attribute"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1004 | return; |
| 1005 | } |
| 1006 | wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash", |
| 1007 | i_bootstrap, i_bootstrap_len); |
| 1008 | |
| 1009 | /* Try to find own and peer bootstrapping key matches based on the |
| 1010 | * received hash values */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1011 | dpp_bootstrap_find_pair(wpa_s->dpp, i_bootstrap, r_bootstrap, |
| 1012 | &own_bi, &peer_bi); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1013 | if (!own_bi) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1014 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL |
| 1015 | "No matching own bootstrapping key found - ignore message"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1016 | return; |
| 1017 | } |
| 1018 | |
| 1019 | if (wpa_s->dpp_auth) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1020 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL |
| 1021 | "Already in DPP authentication exchange - ignore new one"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1022 | return; |
| 1023 | } |
| 1024 | |
| 1025 | wpa_s->dpp_gas_client = 0; |
| 1026 | wpa_s->dpp_auth_ok_on_ack = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1027 | wpa_s->dpp_auth = dpp_auth_req_rx(wpa_s->dpp, wpa_s, |
| 1028 | wpa_s->dpp_allowed_roles, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1029 | wpa_s->dpp_qr_mutual, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1030 | peer_bi, own_bi, freq, hdr, buf, len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1031 | if (!wpa_s->dpp_auth) { |
| 1032 | wpa_printf(MSG_DEBUG, "DPP: No response generated"); |
| 1033 | return; |
| 1034 | } |
| 1035 | wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1036 | if (dpp_set_configurator(wpa_s->dpp_auth, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1037 | wpa_s->dpp_configurator_params) < 0) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1038 | dpp_auth_deinit(wpa_s->dpp_auth); |
| 1039 | wpa_s->dpp_auth = NULL; |
| 1040 | return; |
| 1041 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1042 | os_memcpy(wpa_s->dpp_auth->peer_mac_addr, src, ETH_ALEN); |
| 1043 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1044 | if (wpa_s->dpp_listen_freq && |
| 1045 | wpa_s->dpp_listen_freq != wpa_s->dpp_auth->curr_freq) { |
| 1046 | wpa_printf(MSG_DEBUG, |
| 1047 | "DPP: Stop listen on %u MHz to allow response on the request %u MHz", |
| 1048 | wpa_s->dpp_listen_freq, wpa_s->dpp_auth->curr_freq); |
| 1049 | wpas_dpp_listen_stop(wpa_s); |
| 1050 | } |
| 1051 | |
| 1052 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d", |
| 1053 | MAC2STR(src), wpa_s->dpp_auth->curr_freq, |
| 1054 | DPP_PA_AUTHENTICATION_RESP); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1055 | offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq, |
| 1056 | src, wpa_s->own_addr, broadcast, |
| 1057 | wpabuf_head(wpa_s->dpp_auth->resp_msg), |
| 1058 | wpabuf_len(wpa_s->dpp_auth->resp_msg), |
| 1059 | 500, wpas_dpp_tx_status, 0); |
| 1060 | } |
| 1061 | |
| 1062 | |
| 1063 | static void wpas_dpp_start_gas_server(struct wpa_supplicant *wpa_s) |
| 1064 | { |
| 1065 | /* TODO: stop wait and start ROC */ |
| 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | static struct wpa_ssid * wpas_dpp_add_network(struct wpa_supplicant *wpa_s, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1070 | struct dpp_authentication *auth, |
| 1071 | struct dpp_config_obj *conf) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1072 | { |
| 1073 | struct wpa_ssid *ssid; |
| 1074 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1075 | #ifdef CONFIG_DPP2 |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1076 | if (conf->akm == DPP_AKM_SAE) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1077 | #ifdef CONFIG_SAE |
| 1078 | struct wpa_driver_capa capa; |
| 1079 | int res; |
| 1080 | |
| 1081 | res = wpa_drv_get_capa(wpa_s, &capa); |
| 1082 | if (res == 0 && |
| 1083 | !(capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) && |
| 1084 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) { |
| 1085 | wpa_printf(MSG_DEBUG, |
| 1086 | "DPP: SAE not supported by the driver"); |
| 1087 | return NULL; |
| 1088 | } |
| 1089 | #else /* CONFIG_SAE */ |
| 1090 | wpa_printf(MSG_DEBUG, "DPP: SAE not supported in the build"); |
| 1091 | return NULL; |
| 1092 | #endif /* CONFIG_SAE */ |
| 1093 | } |
| 1094 | #endif /* CONFIG_DPP2 */ |
| 1095 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1096 | ssid = wpa_config_add_network(wpa_s->conf); |
| 1097 | if (!ssid) |
| 1098 | return NULL; |
| 1099 | wpas_notify_network_added(wpa_s, ssid); |
| 1100 | wpa_config_set_network_defaults(ssid); |
| 1101 | ssid->disabled = 1; |
| 1102 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1103 | ssid->ssid = os_malloc(conf->ssid_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1104 | if (!ssid->ssid) |
| 1105 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1106 | os_memcpy(ssid->ssid, conf->ssid, conf->ssid_len); |
| 1107 | ssid->ssid_len = conf->ssid_len; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1108 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1109 | if (conf->connector) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1110 | if (dpp_akm_dpp(conf->akm)) { |
| 1111 | ssid->key_mgmt = WPA_KEY_MGMT_DPP; |
| 1112 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED; |
| 1113 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1114 | ssid->dpp_connector = os_strdup(conf->connector); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1115 | if (!ssid->dpp_connector) |
| 1116 | goto fail; |
| 1117 | } |
| 1118 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1119 | if (conf->c_sign_key) { |
| 1120 | ssid->dpp_csign = os_malloc(wpabuf_len(conf->c_sign_key)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1121 | if (!ssid->dpp_csign) |
| 1122 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1123 | os_memcpy(ssid->dpp_csign, wpabuf_head(conf->c_sign_key), |
| 1124 | wpabuf_len(conf->c_sign_key)); |
| 1125 | ssid->dpp_csign_len = wpabuf_len(conf->c_sign_key); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | if (auth->net_access_key) { |
| 1129 | ssid->dpp_netaccesskey = |
| 1130 | os_malloc(wpabuf_len(auth->net_access_key)); |
| 1131 | if (!ssid->dpp_netaccesskey) |
| 1132 | goto fail; |
| 1133 | os_memcpy(ssid->dpp_netaccesskey, |
| 1134 | wpabuf_head(auth->net_access_key), |
| 1135 | wpabuf_len(auth->net_access_key)); |
| 1136 | ssid->dpp_netaccesskey_len = wpabuf_len(auth->net_access_key); |
| 1137 | ssid->dpp_netaccesskey_expiry = auth->net_access_key_expiry; |
| 1138 | } |
| 1139 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1140 | if (!conf->connector || dpp_akm_psk(conf->akm) || |
| 1141 | dpp_akm_sae(conf->akm)) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1142 | if (!conf->connector || !dpp_akm_dpp(conf->akm)) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1143 | ssid->key_mgmt = 0; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1144 | if (dpp_akm_psk(conf->akm)) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1145 | ssid->key_mgmt |= WPA_KEY_MGMT_PSK | |
| 1146 | WPA_KEY_MGMT_PSK_SHA256 | WPA_KEY_MGMT_FT_PSK; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1147 | if (dpp_akm_sae(conf->akm)) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1148 | ssid->key_mgmt |= WPA_KEY_MGMT_SAE | |
| 1149 | WPA_KEY_MGMT_FT_SAE; |
| 1150 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_OPTIONAL; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1151 | if (conf->passphrase[0]) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1152 | if (wpa_config_set_quoted(ssid, "psk", |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1153 | conf->passphrase) < 0) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1154 | goto fail; |
| 1155 | wpa_config_update_psk(ssid); |
| 1156 | ssid->export_keys = 1; |
| 1157 | } else { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1158 | ssid->psk_set = conf->psk_set; |
| 1159 | os_memcpy(ssid->psk, conf->psk, PMK_LEN); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1163 | os_memcpy(wpa_s->dpp_last_ssid, conf->ssid, conf->ssid_len); |
| 1164 | wpa_s->dpp_last_ssid_len = conf->ssid_len; |
| 1165 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1166 | return ssid; |
| 1167 | fail: |
| 1168 | wpas_notify_network_removed(wpa_s, ssid); |
| 1169 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 1170 | return NULL; |
| 1171 | } |
| 1172 | |
| 1173 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1174 | static int wpas_dpp_process_config(struct wpa_supplicant *wpa_s, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1175 | struct dpp_authentication *auth, |
| 1176 | struct dpp_config_obj *conf) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1177 | { |
| 1178 | struct wpa_ssid *ssid; |
| 1179 | |
| 1180 | if (wpa_s->conf->dpp_config_processing < 1) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1181 | return 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1182 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1183 | ssid = wpas_dpp_add_network(wpa_s, auth, conf); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1184 | if (!ssid) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1185 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1186 | |
| 1187 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_NETWORK_ID "%d", ssid->id); |
Hai Shalom | 5953285 | 2018-12-07 10:32:58 -0800 | [diff] [blame] | 1188 | |
Hai Shalom | 706f99b | 2019-01-08 16:23:37 -0800 | [diff] [blame] | 1189 | wpas_notify_dpp_config_received(wpa_s, ssid); |
Hai Shalom | 5953285 | 2018-12-07 10:32:58 -0800 | [diff] [blame] | 1190 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1191 | if (wpa_s->conf->dpp_config_processing == 2) |
| 1192 | ssid->disabled = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1193 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1194 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 1195 | if (wpa_s->conf->update_config && |
| 1196 | wpa_config_write(wpa_s->confname, wpa_s->conf)) |
| 1197 | wpa_printf(MSG_DEBUG, "DPP: Failed to update configuration"); |
| 1198 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 1199 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1200 | return 0; |
| 1201 | } |
| 1202 | |
| 1203 | |
| 1204 | static void wpas_dpp_post_process_config(struct wpa_supplicant *wpa_s, |
| 1205 | struct dpp_authentication *auth) |
| 1206 | { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1207 | if (wpa_s->conf->dpp_config_processing < 2) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1208 | return; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1209 | |
| 1210 | #ifdef CONFIG_DPP2 |
| 1211 | if (auth->peer_version >= 2) { |
| 1212 | wpa_printf(MSG_DEBUG, |
| 1213 | "DPP: Postpone connection attempt to wait for completion of DPP Configuration Result"); |
| 1214 | auth->connect_on_tx_status = 1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1215 | return; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1216 | } |
| 1217 | #endif /* CONFIG_DPP2 */ |
| 1218 | |
| 1219 | wpas_dpp_try_to_connect(wpa_s); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1223 | static int wpas_dpp_handle_config_obj(struct wpa_supplicant *wpa_s, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1224 | struct dpp_authentication *auth, |
| 1225 | struct dpp_config_obj *conf) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1226 | { |
| 1227 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1228 | if (conf->ssid_len) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1229 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s", |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1230 | wpa_ssid_txt(conf->ssid, conf->ssid_len)); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1231 | if (conf->ssid_charset) |
| 1232 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID_CHARSET "%d", |
| 1233 | conf->ssid_charset); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1234 | if (conf->connector) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1235 | /* TODO: Save the Connector and consider using a command |
| 1236 | * to fetch the value instead of sending an event with |
| 1237 | * it. The Connector could end up being larger than what |
| 1238 | * most clients are ready to receive as an event |
| 1239 | * message. */ |
| 1240 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONNECTOR "%s", |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1241 | conf->connector); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1242 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1243 | if (conf->c_sign_key) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1244 | char *hex; |
| 1245 | size_t hexlen; |
| 1246 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1247 | hexlen = 2 * wpabuf_len(conf->c_sign_key) + 1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1248 | hex = os_malloc(hexlen); |
| 1249 | if (hex) { |
| 1250 | wpa_snprintf_hex(hex, hexlen, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1251 | wpabuf_head(conf->c_sign_key), |
| 1252 | wpabuf_len(conf->c_sign_key)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1253 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_C_SIGN_KEY "%s", |
| 1254 | hex); |
| 1255 | os_free(hex); |
| 1256 | } |
| 1257 | } |
| 1258 | if (auth->net_access_key) { |
| 1259 | char *hex; |
| 1260 | size_t hexlen; |
| 1261 | |
| 1262 | hexlen = 2 * wpabuf_len(auth->net_access_key) + 1; |
| 1263 | hex = os_malloc(hexlen); |
| 1264 | if (hex) { |
| 1265 | wpa_snprintf_hex(hex, hexlen, |
| 1266 | wpabuf_head(auth->net_access_key), |
| 1267 | wpabuf_len(auth->net_access_key)); |
| 1268 | if (auth->net_access_key_expiry) |
| 1269 | wpa_msg(wpa_s, MSG_INFO, |
| 1270 | DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex, |
| 1271 | (long unsigned) |
| 1272 | auth->net_access_key_expiry); |
| 1273 | else |
| 1274 | wpa_msg(wpa_s, MSG_INFO, |
| 1275 | DPP_EVENT_NET_ACCESS_KEY "%s", hex); |
| 1276 | os_free(hex); |
| 1277 | } |
| 1278 | } |
| 1279 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1280 | return wpas_dpp_process_config(wpa_s, auth, conf); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1284 | static int wpas_dpp_handle_key_pkg(struct wpa_supplicant *wpa_s, |
| 1285 | struct dpp_asymmetric_key *key) |
| 1286 | { |
| 1287 | #ifdef CONFIG_DPP2 |
| 1288 | int res; |
| 1289 | |
| 1290 | if (!key) |
| 1291 | return 0; |
| 1292 | |
| 1293 | wpa_printf(MSG_DEBUG, "DPP: Received Configurator backup"); |
| 1294 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED); |
| 1295 | |
| 1296 | while (key) { |
| 1297 | res = dpp_configurator_from_backup(wpa_s->dpp, key); |
| 1298 | if (res < 0) |
| 1299 | return -1; |
| 1300 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFIGURATOR_ID "%d", |
| 1301 | res); |
| 1302 | key = key->next; |
| 1303 | } |
| 1304 | #endif /* CONFIG_DPP2 */ |
| 1305 | |
| 1306 | return 0; |
| 1307 | } |
| 1308 | |
| 1309 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1310 | static void wpas_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token, |
| 1311 | enum gas_query_result result, |
| 1312 | const struct wpabuf *adv_proto, |
| 1313 | const struct wpabuf *resp, u16 status_code) |
| 1314 | { |
| 1315 | struct wpa_supplicant *wpa_s = ctx; |
| 1316 | const u8 *pos; |
| 1317 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1318 | int res; |
| 1319 | enum dpp_status_error status = DPP_STATUS_CONFIG_REJECTED; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1320 | unsigned int i; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1321 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1322 | wpa_s->dpp_gas_dialog_token = -1; |
| 1323 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1324 | if (!auth || !auth->auth_success) { |
| 1325 | wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress"); |
| 1326 | return; |
| 1327 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1328 | if (result != GAS_QUERY_SUCCESS || |
| 1329 | !resp || status_code != WLAN_STATUS_SUCCESS) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1330 | wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed"); |
| 1331 | goto fail; |
| 1332 | } |
| 1333 | |
| 1334 | wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto", |
| 1335 | adv_proto); |
| 1336 | wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)", |
| 1337 | resp); |
| 1338 | |
| 1339 | if (wpabuf_len(adv_proto) != 10 || |
| 1340 | !(pos = wpabuf_head(adv_proto)) || |
| 1341 | pos[0] != WLAN_EID_ADV_PROTO || |
| 1342 | pos[1] != 8 || |
| 1343 | pos[3] != WLAN_EID_VENDOR_SPECIFIC || |
| 1344 | pos[4] != 5 || |
| 1345 | WPA_GET_BE24(&pos[5]) != OUI_WFA || |
| 1346 | pos[8] != 0x1a || |
| 1347 | pos[9] != 1) { |
| 1348 | wpa_printf(MSG_DEBUG, |
| 1349 | "DPP: Not a DPP Advertisement Protocol ID"); |
| 1350 | goto fail; |
| 1351 | } |
| 1352 | |
| 1353 | if (dpp_conf_resp_rx(auth, resp) < 0) { |
| 1354 | wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed"); |
| 1355 | goto fail; |
| 1356 | } |
| 1357 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1358 | for (i = 0; i < auth->num_conf_obj; i++) { |
| 1359 | res = wpas_dpp_handle_config_obj(wpa_s, auth, |
| 1360 | &auth->conf_obj[i]); |
| 1361 | if (res < 0) |
| 1362 | goto fail; |
| 1363 | } |
| 1364 | if (auth->num_conf_obj) |
| 1365 | wpas_dpp_post_process_config(wpa_s, auth); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1366 | if (wpas_dpp_handle_key_pkg(wpa_s, auth->conf_key_pkg) < 0) |
| 1367 | goto fail; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1368 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1369 | status = DPP_STATUS_OK; |
| 1370 | #ifdef CONFIG_TESTING_OPTIONS |
| 1371 | if (dpp_test == DPP_TEST_REJECT_CONFIG) { |
| 1372 | wpa_printf(MSG_INFO, "DPP: TESTING - Reject Config Object"); |
| 1373 | status = DPP_STATUS_CONFIG_REJECTED; |
| 1374 | } |
| 1375 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1376 | fail: |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1377 | if (status != DPP_STATUS_OK) { |
| 1378 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED); |
| 1379 | wpas_notify_dpp_configuration_failure(wpa_s); |
| 1380 | } |
| 1381 | #ifdef CONFIG_DPP2 |
| 1382 | if (auth->peer_version >= 2 && |
| 1383 | auth->conf_resp_status == DPP_STATUS_OK) { |
| 1384 | struct wpabuf *msg; |
| 1385 | |
| 1386 | wpa_printf(MSG_DEBUG, "DPP: Send DPP Configuration Result"); |
| 1387 | msg = dpp_build_conf_result(auth, status); |
| 1388 | if (!msg) |
| 1389 | goto fail2; |
| 1390 | |
| 1391 | wpa_msg(wpa_s, MSG_INFO, |
| 1392 | DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d", |
| 1393 | MAC2STR(addr), auth->curr_freq, |
| 1394 | DPP_PA_CONFIGURATION_RESULT); |
| 1395 | offchannel_send_action(wpa_s, auth->curr_freq, |
| 1396 | addr, wpa_s->own_addr, broadcast, |
| 1397 | wpabuf_head(msg), |
| 1398 | wpabuf_len(msg), |
| 1399 | 500, wpas_dpp_tx_status, 0); |
| 1400 | wpabuf_free(msg); |
| 1401 | |
| 1402 | /* This exchange will be terminated in the TX status handler */ |
| 1403 | return; |
| 1404 | } |
| 1405 | fail2: |
| 1406 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1407 | dpp_auth_deinit(wpa_s->dpp_auth); |
| 1408 | wpa_s->dpp_auth = NULL; |
| 1409 | } |
| 1410 | |
| 1411 | |
| 1412 | static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s) |
| 1413 | { |
| 1414 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1415 | struct wpabuf *buf; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1416 | int res; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1417 | int *supp_op_classes; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1418 | |
| 1419 | wpa_s->dpp_gas_client = 1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1420 | offchannel_send_action_done(wpa_s); |
| 1421 | wpas_dpp_listen_stop(wpa_s); |
| 1422 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1423 | supp_op_classes = wpas_supp_op_classes(wpa_s); |
| 1424 | buf = dpp_build_conf_req_helper(auth, wpa_s->conf->dpp_name, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1425 | wpa_s->dpp_netrole, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1426 | wpa_s->conf->dpp_mud_url, |
| 1427 | supp_op_classes); |
| 1428 | os_free(supp_op_classes); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1429 | if (!buf) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1430 | wpa_printf(MSG_DEBUG, |
| 1431 | "DPP: No configuration request data available"); |
| 1432 | return; |
| 1433 | } |
| 1434 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1435 | wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)", |
| 1436 | MAC2STR(auth->peer_mac_addr), auth->curr_freq); |
| 1437 | |
| 1438 | res = gas_query_req(wpa_s->gas, auth->peer_mac_addr, auth->curr_freq, |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 1439 | 1, 1, buf, wpas_dpp_gas_resp_cb, wpa_s); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1440 | if (res < 0) { |
| 1441 | wpa_msg(wpa_s, MSG_DEBUG, "GAS: Failed to send Query Request"); |
| 1442 | wpabuf_free(buf); |
| 1443 | } else { |
| 1444 | wpa_printf(MSG_DEBUG, |
| 1445 | "DPP: GAS query started with dialog token %u", res); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1446 | wpa_s->dpp_gas_dialog_token = res; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1447 | } |
| 1448 | } |
| 1449 | |
| 1450 | |
| 1451 | static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator) |
| 1452 | { |
| 1453 | wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded"); |
| 1454 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d", initiator); |
Hai Shalom | 706f99b | 2019-01-08 16:23:37 -0800 | [diff] [blame] | 1455 | wpas_notify_dpp_auth_success(wpa_s); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1456 | #ifdef CONFIG_TESTING_OPTIONS |
| 1457 | if (dpp_test == DPP_TEST_STOP_AT_AUTH_CONF) { |
| 1458 | wpa_printf(MSG_INFO, |
| 1459 | "DPP: TESTING - stop at Authentication Confirm"); |
| 1460 | if (wpa_s->dpp_auth->configurator) { |
| 1461 | /* Prevent GAS response */ |
| 1462 | wpa_s->dpp_auth->auth_success = 0; |
| 1463 | } |
| 1464 | return; |
| 1465 | } |
| 1466 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1467 | |
| 1468 | if (wpa_s->dpp_auth->configurator) |
| 1469 | wpas_dpp_start_gas_server(wpa_s); |
| 1470 | else |
| 1471 | wpas_dpp_start_gas_client(wpa_s); |
| 1472 | } |
| 1473 | |
| 1474 | |
| 1475 | static void wpas_dpp_rx_auth_resp(struct wpa_supplicant *wpa_s, const u8 *src, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1476 | const u8 *hdr, const u8 *buf, size_t len, |
| 1477 | unsigned int freq) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1478 | { |
| 1479 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 1480 | struct wpabuf *msg; |
| 1481 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1482 | wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR |
| 1483 | " (freq %u MHz)", MAC2STR(src), freq); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1484 | |
| 1485 | if (!auth) { |
| 1486 | wpa_printf(MSG_DEBUG, |
| 1487 | "DPP: No DPP Authentication in progress - drop"); |
| 1488 | return; |
| 1489 | } |
| 1490 | |
| 1491 | if (!is_zero_ether_addr(auth->peer_mac_addr) && |
| 1492 | os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) { |
| 1493 | wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected " |
| 1494 | MACSTR ") - drop", MAC2STR(auth->peer_mac_addr)); |
| 1495 | return; |
| 1496 | } |
| 1497 | |
| 1498 | eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL); |
| 1499 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1500 | if (auth->curr_freq != freq && auth->neg_freq == freq) { |
| 1501 | wpa_printf(MSG_DEBUG, |
| 1502 | "DPP: Responder accepted request for different negotiation channel"); |
| 1503 | auth->curr_freq = freq; |
| 1504 | } |
| 1505 | |
| 1506 | eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1507 | msg = dpp_auth_resp_rx(auth, hdr, buf, len); |
| 1508 | if (!msg) { |
| 1509 | if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) { |
| 1510 | wpa_printf(MSG_DEBUG, |
| 1511 | "DPP: Start wait for full response"); |
Hai Shalom | 706f99b | 2019-01-08 16:23:37 -0800 | [diff] [blame] | 1512 | wpas_notify_dpp_resp_pending(wpa_s); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1513 | offchannel_send_action_done(wpa_s); |
| 1514 | wpas_dpp_listen_start(wpa_s, auth->curr_freq); |
| 1515 | return; |
| 1516 | } |
| 1517 | wpa_printf(MSG_DEBUG, "DPP: No confirm generated"); |
| 1518 | return; |
| 1519 | } |
| 1520 | os_memcpy(auth->peer_mac_addr, src, ETH_ALEN); |
| 1521 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1522 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d", |
| 1523 | MAC2STR(src), auth->curr_freq, DPP_PA_AUTHENTICATION_CONF); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1524 | offchannel_send_action(wpa_s, auth->curr_freq, |
| 1525 | src, wpa_s->own_addr, broadcast, |
| 1526 | wpabuf_head(msg), wpabuf_len(msg), |
| 1527 | 500, wpas_dpp_tx_status, 0); |
| 1528 | wpabuf_free(msg); |
| 1529 | wpa_s->dpp_auth_ok_on_ack = 1; |
| 1530 | } |
| 1531 | |
| 1532 | |
| 1533 | static void wpas_dpp_rx_auth_conf(struct wpa_supplicant *wpa_s, const u8 *src, |
| 1534 | const u8 *hdr, const u8 *buf, size_t len) |
| 1535 | { |
| 1536 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 1537 | |
| 1538 | wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR, |
| 1539 | MAC2STR(src)); |
| 1540 | |
| 1541 | if (!auth) { |
| 1542 | wpa_printf(MSG_DEBUG, |
| 1543 | "DPP: No DPP Authentication in progress - drop"); |
| 1544 | return; |
| 1545 | } |
| 1546 | |
| 1547 | if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) { |
| 1548 | wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected " |
| 1549 | MACSTR ") - drop", MAC2STR(auth->peer_mac_addr)); |
| 1550 | return; |
| 1551 | } |
| 1552 | |
| 1553 | if (dpp_auth_conf_rx(auth, hdr, buf, len) < 0) { |
| 1554 | wpa_printf(MSG_DEBUG, "DPP: Authentication failed"); |
Hai Shalom | 706f99b | 2019-01-08 16:23:37 -0800 | [diff] [blame] | 1555 | wpas_notify_dpp_auth_failure(wpa_s); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1556 | return; |
| 1557 | } |
| 1558 | |
| 1559 | wpas_dpp_auth_success(wpa_s, 0); |
| 1560 | } |
| 1561 | |
| 1562 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1563 | #ifdef CONFIG_DPP2 |
| 1564 | |
| 1565 | static void wpas_dpp_config_result_wait_timeout(void *eloop_ctx, |
| 1566 | void *timeout_ctx) |
| 1567 | { |
| 1568 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 1569 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 1570 | |
| 1571 | if (!auth || !auth->waiting_conf_result) |
| 1572 | return; |
| 1573 | |
| 1574 | wpa_printf(MSG_DEBUG, |
| 1575 | "DPP: Timeout while waiting for Configuration Result"); |
| 1576 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED); |
Hai Shalom | 0676811 | 2019-12-04 15:49:43 -0800 | [diff] [blame] | 1577 | wpas_notify_dpp_configuration_failure(wpa_s); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1578 | dpp_auth_deinit(auth); |
| 1579 | wpa_s->dpp_auth = NULL; |
| 1580 | } |
| 1581 | |
| 1582 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1583 | static void wpas_dpp_conn_status_result_wait_timeout(void *eloop_ctx, |
| 1584 | void *timeout_ctx) |
| 1585 | { |
| 1586 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 1587 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 1588 | |
| 1589 | if (!auth || !auth->waiting_conn_status_result) |
| 1590 | return; |
| 1591 | |
| 1592 | wpa_printf(MSG_DEBUG, |
| 1593 | "DPP: Timeout while waiting for Connection Status Result"); |
| 1594 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONN_STATUS_RESULT "timeout"); |
Hai Shalom | 0676811 | 2019-12-04 15:49:43 -0800 | [diff] [blame] | 1595 | wpas_notify_dpp_timeout(wpa_s); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1596 | wpas_dpp_listen_stop(wpa_s); |
| 1597 | dpp_auth_deinit(auth); |
| 1598 | wpa_s->dpp_auth = NULL; |
| 1599 | } |
| 1600 | |
| 1601 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1602 | static void wpas_dpp_rx_conf_result(struct wpa_supplicant *wpa_s, const u8 *src, |
| 1603 | const u8 *hdr, const u8 *buf, size_t len) |
| 1604 | { |
| 1605 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 1606 | enum dpp_status_error status; |
| 1607 | |
| 1608 | wpa_printf(MSG_DEBUG, "DPP: Configuration Result from " MACSTR, |
| 1609 | MAC2STR(src)); |
| 1610 | |
| 1611 | if (!auth || !auth->waiting_conf_result) { |
| 1612 | wpa_printf(MSG_DEBUG, |
| 1613 | "DPP: No DPP Configuration waiting for result - drop"); |
| 1614 | return; |
| 1615 | } |
| 1616 | |
| 1617 | if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) { |
| 1618 | wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected " |
| 1619 | MACSTR ") - drop", MAC2STR(auth->peer_mac_addr)); |
| 1620 | return; |
| 1621 | } |
| 1622 | |
| 1623 | status = dpp_conf_result_rx(auth, hdr, buf, len); |
| 1624 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1625 | if (status == DPP_STATUS_OK && auth->send_conn_status) { |
| 1626 | wpa_msg(wpa_s, MSG_INFO, |
| 1627 | DPP_EVENT_CONF_SENT "wait_conn_status=1"); |
| 1628 | wpa_printf(MSG_DEBUG, "DPP: Wait for Connection Status Result"); |
Hai Shalom | 0676811 | 2019-12-04 15:49:43 -0800 | [diff] [blame] | 1629 | wpas_notify_dpp_config_accepted(wpa_s); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1630 | eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, |
| 1631 | wpa_s, NULL); |
| 1632 | auth->waiting_conn_status_result = 1; |
| 1633 | eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout, |
| 1634 | wpa_s, NULL); |
| 1635 | eloop_register_timeout(16, 0, |
| 1636 | wpas_dpp_conn_status_result_wait_timeout, |
| 1637 | wpa_s, NULL); |
| 1638 | offchannel_send_action_done(wpa_s); |
| 1639 | wpas_dpp_listen_start(wpa_s, auth->neg_freq ? auth->neg_freq : |
| 1640 | auth->curr_freq); |
| 1641 | return; |
| 1642 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1643 | offchannel_send_action_done(wpa_s); |
| 1644 | wpas_dpp_listen_stop(wpa_s); |
Hai Shalom | e407333 | 2019-11-05 16:20:12 -0800 | [diff] [blame] | 1645 | if (status == DPP_STATUS_OK) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1646 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT); |
Hai Shalom | e407333 | 2019-11-05 16:20:12 -0800 | [diff] [blame] | 1647 | wpas_notify_dpp_config_sent(wpa_s); |
| 1648 | } |
| 1649 | else { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1650 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED); |
Hai Shalom | 0676811 | 2019-12-04 15:49:43 -0800 | [diff] [blame] | 1651 | wpas_notify_dpp_config_rejected(wpa_s); |
Hai Shalom | e407333 | 2019-11-05 16:20:12 -0800 | [diff] [blame] | 1652 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1653 | dpp_auth_deinit(auth); |
| 1654 | wpa_s->dpp_auth = NULL; |
| 1655 | eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL); |
| 1656 | } |
| 1657 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1658 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1659 | static void wpas_dpp_rx_conn_status_result(struct wpa_supplicant *wpa_s, |
| 1660 | const u8 *src, const u8 *hdr, |
| 1661 | const u8 *buf, size_t len) |
| 1662 | { |
| 1663 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 1664 | enum dpp_status_error status; |
| 1665 | u8 ssid[SSID_MAX_LEN]; |
| 1666 | size_t ssid_len = 0; |
| 1667 | char *channel_list = NULL; |
| 1668 | |
| 1669 | wpa_printf(MSG_DEBUG, "DPP: Connection Status Result"); |
| 1670 | |
| 1671 | if (!auth || !auth->waiting_conn_status_result) { |
| 1672 | wpa_printf(MSG_DEBUG, |
| 1673 | "DPP: No DPP Configuration waiting for connection status result - drop"); |
| 1674 | return; |
| 1675 | } |
| 1676 | |
| 1677 | status = dpp_conn_status_result_rx(auth, hdr, buf, len, |
| 1678 | ssid, &ssid_len, &channel_list); |
| 1679 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONN_STATUS_RESULT |
| 1680 | "result=%d ssid=%s channel_list=%s", |
| 1681 | status, wpa_ssid_txt(ssid, ssid_len), |
| 1682 | channel_list ? channel_list : "N/A"); |
Hai Shalom | 0676811 | 2019-12-04 15:49:43 -0800 | [diff] [blame] | 1683 | wpas_notify_dpp_conn_status(wpa_s, status, wpa_ssid_txt(ssid, ssid_len), |
| 1684 | channel_list, auth->band_list, auth->band_list_size); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1685 | os_free(channel_list); |
| 1686 | offchannel_send_action_done(wpa_s); |
| 1687 | wpas_dpp_listen_stop(wpa_s); |
| 1688 | dpp_auth_deinit(auth); |
| 1689 | wpa_s->dpp_auth = NULL; |
| 1690 | eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout, |
| 1691 | wpa_s, NULL); |
| 1692 | } |
| 1693 | |
| 1694 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1695 | static int wpas_dpp_process_conf_obj(void *ctx, |
| 1696 | struct dpp_authentication *auth) |
| 1697 | { |
| 1698 | struct wpa_supplicant *wpa_s = ctx; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1699 | unsigned int i; |
| 1700 | int res = -1; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1701 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1702 | for (i = 0; i < auth->num_conf_obj; i++) { |
| 1703 | res = wpas_dpp_handle_config_obj(wpa_s, auth, |
| 1704 | &auth->conf_obj[i]); |
| 1705 | if (res) |
| 1706 | break; |
| 1707 | } |
| 1708 | if (!res) |
| 1709 | wpas_dpp_post_process_config(wpa_s, auth); |
| 1710 | |
| 1711 | return res; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1714 | |
| 1715 | static void wpas_dpp_remove_bi(void *ctx, struct dpp_bootstrap_info *bi) |
| 1716 | { |
| 1717 | struct wpa_supplicant *wpa_s = ctx; |
| 1718 | |
| 1719 | if (bi == wpa_s->dpp_chirp_bi) |
| 1720 | wpas_dpp_chirp_stop(wpa_s); |
| 1721 | } |
| 1722 | |
| 1723 | |
| 1724 | static void |
| 1725 | wpas_dpp_rx_presence_announcement(struct wpa_supplicant *wpa_s, const u8 *src, |
| 1726 | const u8 *hdr, const u8 *buf, size_t len, |
| 1727 | unsigned int freq) |
| 1728 | { |
| 1729 | const u8 *r_bootstrap; |
| 1730 | u16 r_bootstrap_len; |
| 1731 | struct dpp_bootstrap_info *peer_bi; |
| 1732 | struct dpp_authentication *auth; |
| 1733 | |
| 1734 | if (!wpa_s->dpp) |
| 1735 | return; |
| 1736 | |
| 1737 | if (wpa_s->dpp_auth) { |
| 1738 | wpa_printf(MSG_DEBUG, |
| 1739 | "DPP: Ignore Presence Announcement during ongoing Authentication"); |
| 1740 | return; |
| 1741 | } |
| 1742 | |
| 1743 | wpa_printf(MSG_DEBUG, "DPP: Presence Announcement from " MACSTR, |
| 1744 | MAC2STR(src)); |
| 1745 | |
| 1746 | r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH, |
| 1747 | &r_bootstrap_len); |
| 1748 | if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) { |
| 1749 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL |
| 1750 | "Missing or invalid required Responder Bootstrapping Key Hash attribute"); |
| 1751 | return; |
| 1752 | } |
| 1753 | wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash", |
| 1754 | r_bootstrap, r_bootstrap_len); |
| 1755 | peer_bi = dpp_bootstrap_find_chirp(wpa_s->dpp, r_bootstrap); |
| 1756 | if (!peer_bi) { |
| 1757 | wpa_printf(MSG_DEBUG, |
| 1758 | "DPP: No matching bootstrapping information found"); |
| 1759 | return; |
| 1760 | } |
| 1761 | |
| 1762 | auth = dpp_auth_init(wpa_s->dpp, wpa_s, peer_bi, NULL, |
| 1763 | DPP_CAPAB_CONFIGURATOR, freq, NULL, 0); |
| 1764 | if (!auth) |
| 1765 | return; |
| 1766 | wpas_dpp_set_testing_options(wpa_s, auth); |
| 1767 | if (dpp_set_configurator(auth, wpa_s->dpp_configurator_params) < 0) { |
| 1768 | dpp_auth_deinit(auth); |
| 1769 | return; |
| 1770 | } |
| 1771 | |
| 1772 | auth->neg_freq = freq; |
| 1773 | |
| 1774 | if (!is_zero_ether_addr(peer_bi->mac_addr)) |
| 1775 | os_memcpy(auth->peer_mac_addr, peer_bi->mac_addr, ETH_ALEN); |
| 1776 | |
| 1777 | wpa_s->dpp_auth = auth; |
| 1778 | if (wpas_dpp_auth_init_next(wpa_s) < 0) { |
| 1779 | dpp_auth_deinit(wpa_s->dpp_auth); |
| 1780 | wpa_s->dpp_auth = NULL; |
| 1781 | } |
| 1782 | } |
| 1783 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1784 | #endif /* CONFIG_DPP2 */ |
| 1785 | |
| 1786 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1787 | static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant *wpa_s, |
| 1788 | const u8 *src, |
| 1789 | const u8 *buf, size_t len) |
| 1790 | { |
| 1791 | struct wpa_ssid *ssid; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1792 | const u8 *connector, *trans_id, *status; |
| 1793 | u16 connector_len, trans_id_len, status_len; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1794 | struct dpp_introduction intro; |
| 1795 | struct rsn_pmksa_cache_entry *entry; |
| 1796 | struct os_time now; |
| 1797 | struct os_reltime rnow; |
| 1798 | os_time_t expiry; |
| 1799 | unsigned int seconds; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1800 | enum dpp_status_error res; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1801 | |
| 1802 | wpa_printf(MSG_DEBUG, "DPP: Peer Discovery Response from " MACSTR, |
| 1803 | MAC2STR(src)); |
| 1804 | if (is_zero_ether_addr(wpa_s->dpp_intro_bssid) || |
| 1805 | os_memcmp(src, wpa_s->dpp_intro_bssid, ETH_ALEN) != 0) { |
| 1806 | wpa_printf(MSG_DEBUG, "DPP: Not waiting for response from " |
| 1807 | MACSTR " - drop", MAC2STR(src)); |
| 1808 | return; |
| 1809 | } |
| 1810 | offchannel_send_action_done(wpa_s); |
| 1811 | |
| 1812 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 1813 | if (ssid == wpa_s->dpp_intro_network) |
| 1814 | break; |
| 1815 | } |
| 1816 | if (!ssid || !ssid->dpp_connector || !ssid->dpp_netaccesskey || |
| 1817 | !ssid->dpp_csign) { |
| 1818 | wpa_printf(MSG_DEBUG, |
| 1819 | "DPP: Profile not found for network introduction"); |
| 1820 | return; |
| 1821 | } |
| 1822 | |
| 1823 | trans_id = dpp_get_attr(buf, len, DPP_ATTR_TRANSACTION_ID, |
| 1824 | &trans_id_len); |
| 1825 | if (!trans_id || trans_id_len != 1) { |
| 1826 | wpa_printf(MSG_DEBUG, |
| 1827 | "DPP: Peer did not include Transaction ID"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1828 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR |
| 1829 | " fail=missing_transaction_id", MAC2STR(src)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1830 | goto fail; |
| 1831 | } |
| 1832 | if (trans_id[0] != TRANSACTION_ID) { |
| 1833 | wpa_printf(MSG_DEBUG, |
| 1834 | "DPP: Ignore frame with unexpected Transaction ID %u", |
| 1835 | trans_id[0]); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1836 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR |
| 1837 | " fail=transaction_id_mismatch", MAC2STR(src)); |
| 1838 | goto fail; |
| 1839 | } |
| 1840 | |
| 1841 | status = dpp_get_attr(buf, len, DPP_ATTR_STATUS, &status_len); |
| 1842 | if (!status || status_len != 1) { |
| 1843 | wpa_printf(MSG_DEBUG, "DPP: Peer did not include Status"); |
| 1844 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR |
| 1845 | " fail=missing_status", MAC2STR(src)); |
| 1846 | goto fail; |
| 1847 | } |
| 1848 | if (status[0] != DPP_STATUS_OK) { |
| 1849 | wpa_printf(MSG_DEBUG, |
| 1850 | "DPP: Peer rejected network introduction: Status %u", |
| 1851 | status[0]); |
| 1852 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR |
| 1853 | " status=%u", MAC2STR(src), status[0]); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1854 | #ifdef CONFIG_DPP2 |
| 1855 | wpas_dpp_send_conn_status_result(wpa_s, status[0]); |
| 1856 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1857 | goto fail; |
| 1858 | } |
| 1859 | |
| 1860 | connector = dpp_get_attr(buf, len, DPP_ATTR_CONNECTOR, &connector_len); |
| 1861 | if (!connector) { |
| 1862 | wpa_printf(MSG_DEBUG, |
| 1863 | "DPP: Peer did not include its Connector"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1864 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR |
| 1865 | " fail=missing_connector", MAC2STR(src)); |
| 1866 | goto fail; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1869 | res = dpp_peer_intro(&intro, ssid->dpp_connector, |
| 1870 | ssid->dpp_netaccesskey, |
| 1871 | ssid->dpp_netaccesskey_len, |
| 1872 | ssid->dpp_csign, |
| 1873 | ssid->dpp_csign_len, |
| 1874 | connector, connector_len, &expiry); |
| 1875 | if (res != DPP_STATUS_OK) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1876 | wpa_printf(MSG_INFO, |
| 1877 | "DPP: Network Introduction protocol resulted in failure"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1878 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR |
| 1879 | " fail=peer_connector_validation_failed", MAC2STR(src)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1880 | #ifdef CONFIG_DPP2 |
| 1881 | wpas_dpp_send_conn_status_result(wpa_s, res); |
| 1882 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1883 | goto fail; |
| 1884 | } |
| 1885 | |
| 1886 | entry = os_zalloc(sizeof(*entry)); |
| 1887 | if (!entry) |
| 1888 | goto fail; |
| 1889 | os_memcpy(entry->aa, src, ETH_ALEN); |
| 1890 | os_memcpy(entry->pmkid, intro.pmkid, PMKID_LEN); |
| 1891 | os_memcpy(entry->pmk, intro.pmk, intro.pmk_len); |
| 1892 | entry->pmk_len = intro.pmk_len; |
| 1893 | entry->akmp = WPA_KEY_MGMT_DPP; |
| 1894 | if (expiry) { |
| 1895 | os_get_time(&now); |
| 1896 | seconds = expiry - now.sec; |
| 1897 | } else { |
| 1898 | seconds = 86400 * 7; |
| 1899 | } |
| 1900 | os_get_reltime(&rnow); |
| 1901 | entry->expiration = rnow.sec + seconds; |
| 1902 | entry->reauth_time = rnow.sec + seconds; |
| 1903 | entry->network_ctx = ssid; |
| 1904 | wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry); |
| 1905 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1906 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR |
| 1907 | " status=%u", MAC2STR(src), status[0]); |
| 1908 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1909 | wpa_printf(MSG_DEBUG, |
| 1910 | "DPP: Try connection again after successful network introduction"); |
| 1911 | if (wpa_supplicant_fast_associate(wpa_s) != 1) { |
| 1912 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 1913 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 1914 | } |
| 1915 | fail: |
| 1916 | os_memset(&intro, 0, sizeof(intro)); |
| 1917 | } |
| 1918 | |
| 1919 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1920 | static int wpas_dpp_allow_ir(struct wpa_supplicant *wpa_s, unsigned int freq) |
| 1921 | { |
| 1922 | int i, j; |
| 1923 | |
| 1924 | if (!wpa_s->hw.modes) |
| 1925 | return -1; |
| 1926 | |
| 1927 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 1928 | struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i]; |
| 1929 | |
| 1930 | for (j = 0; j < mode->num_channels; j++) { |
| 1931 | struct hostapd_channel_data *chan = &mode->channels[j]; |
| 1932 | |
| 1933 | if (chan->freq != (int) freq) |
| 1934 | continue; |
| 1935 | |
| 1936 | if (chan->flag & (HOSTAPD_CHAN_DISABLED | |
| 1937 | HOSTAPD_CHAN_NO_IR | |
| 1938 | HOSTAPD_CHAN_RADAR)) |
| 1939 | continue; |
| 1940 | |
| 1941 | return 1; |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | wpa_printf(MSG_DEBUG, |
| 1946 | "DPP: Frequency %u MHz not supported or does not allow PKEX initiation in the current channel list", |
| 1947 | freq); |
| 1948 | |
| 1949 | return 0; |
| 1950 | } |
| 1951 | |
| 1952 | |
| 1953 | static int wpas_dpp_pkex_next_channel(struct wpa_supplicant *wpa_s, |
| 1954 | struct dpp_pkex *pkex) |
| 1955 | { |
| 1956 | if (pkex->freq == 2437) |
| 1957 | pkex->freq = 5745; |
| 1958 | else if (pkex->freq == 5745) |
| 1959 | pkex->freq = 5220; |
| 1960 | else if (pkex->freq == 5220) |
| 1961 | pkex->freq = 60480; |
| 1962 | else |
| 1963 | return -1; /* no more channels to try */ |
| 1964 | |
| 1965 | if (wpas_dpp_allow_ir(wpa_s, pkex->freq) == 1) { |
| 1966 | wpa_printf(MSG_DEBUG, "DPP: Try to initiate on %u MHz", |
| 1967 | pkex->freq); |
| 1968 | return 0; |
| 1969 | } |
| 1970 | |
| 1971 | /* Could not use this channel - try the next one */ |
| 1972 | return wpas_dpp_pkex_next_channel(wpa_s, pkex); |
| 1973 | } |
| 1974 | |
| 1975 | |
| 1976 | static void wpas_dpp_pkex_retry_timeout(void *eloop_ctx, void *timeout_ctx) |
| 1977 | { |
| 1978 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 1979 | struct dpp_pkex *pkex = wpa_s->dpp_pkex; |
| 1980 | |
| 1981 | if (!pkex || !pkex->exchange_req) |
| 1982 | return; |
| 1983 | if (pkex->exch_req_tries >= 5) { |
| 1984 | if (wpas_dpp_pkex_next_channel(wpa_s, pkex) < 0) { |
| 1985 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL |
| 1986 | "No response from PKEX peer"); |
| 1987 | dpp_pkex_free(pkex); |
| 1988 | wpa_s->dpp_pkex = NULL; |
| 1989 | return; |
| 1990 | } |
| 1991 | pkex->exch_req_tries = 0; |
| 1992 | } |
| 1993 | |
| 1994 | pkex->exch_req_tries++; |
| 1995 | wpa_printf(MSG_DEBUG, "DPP: Retransmit PKEX Exchange Request (try %u)", |
| 1996 | pkex->exch_req_tries); |
| 1997 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d", |
| 1998 | MAC2STR(broadcast), pkex->freq, DPP_PA_PKEX_EXCHANGE_REQ); |
| 1999 | offchannel_send_action(wpa_s, pkex->freq, broadcast, |
| 2000 | wpa_s->own_addr, broadcast, |
| 2001 | wpabuf_head(pkex->exchange_req), |
| 2002 | wpabuf_len(pkex->exchange_req), |
| 2003 | pkex->exch_req_wait_time, |
| 2004 | wpas_dpp_tx_pkex_status, 0); |
| 2005 | } |
| 2006 | |
| 2007 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2008 | static void |
| 2009 | wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s, |
| 2010 | unsigned int freq, const u8 *dst, |
| 2011 | const u8 *src, const u8 *bssid, |
| 2012 | const u8 *data, size_t data_len, |
| 2013 | enum offchannel_send_action_result result) |
| 2014 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2015 | const char *res_txt; |
| 2016 | struct dpp_pkex *pkex = wpa_s->dpp_pkex; |
| 2017 | |
| 2018 | res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" : |
| 2019 | (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" : |
| 2020 | "FAILED"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2021 | wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR |
| 2022 | " result=%s (PKEX)", |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2023 | freq, MAC2STR(dst), res_txt); |
| 2024 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR |
| 2025 | " freq=%u result=%s", MAC2STR(dst), freq, res_txt); |
| 2026 | |
| 2027 | if (!pkex) { |
| 2028 | wpa_printf(MSG_DEBUG, |
| 2029 | "DPP: Ignore TX status since there is no ongoing PKEX exchange"); |
| 2030 | return; |
| 2031 | } |
| 2032 | |
| 2033 | if (pkex->failed) { |
| 2034 | wpa_printf(MSG_DEBUG, |
| 2035 | "DPP: Terminate PKEX exchange due to an earlier error"); |
| 2036 | if (pkex->t > pkex->own_bi->pkex_t) |
| 2037 | pkex->own_bi->pkex_t = pkex->t; |
| 2038 | dpp_pkex_free(pkex); |
| 2039 | wpa_s->dpp_pkex = NULL; |
| 2040 | return; |
| 2041 | } |
| 2042 | |
| 2043 | if (pkex->exch_req_wait_time && pkex->exchange_req) { |
| 2044 | /* Wait for PKEX Exchange Response frame and retry request if |
| 2045 | * no response is seen. */ |
| 2046 | eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL); |
| 2047 | eloop_register_timeout(pkex->exch_req_wait_time / 1000, |
| 2048 | (pkex->exch_req_wait_time % 1000) * 1000, |
| 2049 | wpas_dpp_pkex_retry_timeout, wpa_s, |
| 2050 | NULL); |
| 2051 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
| 2054 | |
| 2055 | static void |
| 2056 | wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant *wpa_s, const u8 *src, |
| 2057 | const u8 *buf, size_t len, unsigned int freq) |
| 2058 | { |
| 2059 | struct wpabuf *msg; |
| 2060 | unsigned int wait_time; |
| 2061 | |
| 2062 | wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Request from " MACSTR, |
| 2063 | MAC2STR(src)); |
| 2064 | |
| 2065 | /* TODO: Support multiple PKEX codes by iterating over all the enabled |
| 2066 | * values here */ |
| 2067 | |
| 2068 | if (!wpa_s->dpp_pkex_code || !wpa_s->dpp_pkex_bi) { |
| 2069 | wpa_printf(MSG_DEBUG, |
| 2070 | "DPP: No PKEX code configured - ignore request"); |
| 2071 | return; |
| 2072 | } |
| 2073 | |
| 2074 | if (wpa_s->dpp_pkex) { |
| 2075 | /* TODO: Support parallel operations */ |
| 2076 | wpa_printf(MSG_DEBUG, |
| 2077 | "DPP: Already in PKEX session - ignore new request"); |
| 2078 | return; |
| 2079 | } |
| 2080 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2081 | wpa_s->dpp_pkex = dpp_pkex_rx_exchange_req(wpa_s, wpa_s->dpp_pkex_bi, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2082 | wpa_s->own_addr, src, |
| 2083 | wpa_s->dpp_pkex_identifier, |
| 2084 | wpa_s->dpp_pkex_code, |
| 2085 | buf, len); |
| 2086 | if (!wpa_s->dpp_pkex) { |
| 2087 | wpa_printf(MSG_DEBUG, |
| 2088 | "DPP: Failed to process the request - ignore it"); |
| 2089 | return; |
| 2090 | } |
| 2091 | |
| 2092 | msg = wpa_s->dpp_pkex->exchange_resp; |
| 2093 | wait_time = wpa_s->max_remain_on_chan; |
| 2094 | if (wait_time > 2000) |
| 2095 | wait_time = 2000; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2096 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d", |
| 2097 | MAC2STR(src), freq, DPP_PA_PKEX_EXCHANGE_RESP); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2098 | offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr, |
| 2099 | broadcast, |
| 2100 | wpabuf_head(msg), wpabuf_len(msg), |
| 2101 | wait_time, wpas_dpp_tx_pkex_status, 0); |
| 2102 | } |
| 2103 | |
| 2104 | |
| 2105 | static void |
| 2106 | wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant *wpa_s, const u8 *src, |
| 2107 | const u8 *buf, size_t len, unsigned int freq) |
| 2108 | { |
| 2109 | struct wpabuf *msg; |
| 2110 | unsigned int wait_time; |
| 2111 | |
| 2112 | wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Response from " MACSTR, |
| 2113 | MAC2STR(src)); |
| 2114 | |
| 2115 | /* TODO: Support multiple PKEX codes by iterating over all the enabled |
| 2116 | * values here */ |
| 2117 | |
| 2118 | if (!wpa_s->dpp_pkex || !wpa_s->dpp_pkex->initiator || |
| 2119 | wpa_s->dpp_pkex->exchange_done) { |
| 2120 | wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session"); |
| 2121 | return; |
| 2122 | } |
| 2123 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2124 | eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL); |
| 2125 | wpa_s->dpp_pkex->exch_req_wait_time = 0; |
| 2126 | |
| 2127 | msg = dpp_pkex_rx_exchange_resp(wpa_s->dpp_pkex, src, buf, len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2128 | if (!msg) { |
| 2129 | wpa_printf(MSG_DEBUG, "DPP: Failed to process the response"); |
| 2130 | return; |
| 2131 | } |
| 2132 | |
| 2133 | wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Request to " MACSTR, |
| 2134 | MAC2STR(src)); |
| 2135 | |
| 2136 | wait_time = wpa_s->max_remain_on_chan; |
| 2137 | if (wait_time > 2000) |
| 2138 | wait_time = 2000; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2139 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d", |
| 2140 | MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_REQ); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2141 | offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr, |
| 2142 | broadcast, |
| 2143 | wpabuf_head(msg), wpabuf_len(msg), |
| 2144 | wait_time, wpas_dpp_tx_pkex_status, 0); |
| 2145 | wpabuf_free(msg); |
| 2146 | } |
| 2147 | |
| 2148 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2149 | static struct dpp_bootstrap_info * |
| 2150 | wpas_dpp_pkex_finish(struct wpa_supplicant *wpa_s, const u8 *peer, |
| 2151 | unsigned int freq) |
| 2152 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2153 | struct dpp_bootstrap_info *bi; |
| 2154 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2155 | bi = dpp_pkex_finish(wpa_s->dpp, wpa_s->dpp_pkex, peer, freq); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2156 | if (!bi) |
| 2157 | return NULL; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2158 | wpa_s->dpp_pkex = NULL; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2159 | return bi; |
| 2160 | } |
| 2161 | |
| 2162 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2163 | static void |
| 2164 | wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant *wpa_s, const u8 *src, |
| 2165 | const u8 *hdr, const u8 *buf, size_t len, |
| 2166 | unsigned int freq) |
| 2167 | { |
| 2168 | struct wpabuf *msg; |
| 2169 | unsigned int wait_time; |
| 2170 | struct dpp_pkex *pkex = wpa_s->dpp_pkex; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2171 | |
| 2172 | wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Request from " MACSTR, |
| 2173 | MAC2STR(src)); |
| 2174 | |
| 2175 | if (!pkex || pkex->initiator || !pkex->exchange_done) { |
| 2176 | wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session"); |
| 2177 | return; |
| 2178 | } |
| 2179 | |
| 2180 | msg = dpp_pkex_rx_commit_reveal_req(pkex, hdr, buf, len); |
| 2181 | if (!msg) { |
| 2182 | wpa_printf(MSG_DEBUG, "DPP: Failed to process the request"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2183 | if (pkex->failed) { |
| 2184 | wpa_printf(MSG_DEBUG, "DPP: Terminate PKEX exchange"); |
| 2185 | if (pkex->t > pkex->own_bi->pkex_t) |
| 2186 | pkex->own_bi->pkex_t = pkex->t; |
| 2187 | dpp_pkex_free(wpa_s->dpp_pkex); |
| 2188 | wpa_s->dpp_pkex = NULL; |
| 2189 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2190 | return; |
| 2191 | } |
| 2192 | |
| 2193 | wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Response to " |
| 2194 | MACSTR, MAC2STR(src)); |
| 2195 | |
| 2196 | wait_time = wpa_s->max_remain_on_chan; |
| 2197 | if (wait_time > 2000) |
| 2198 | wait_time = 2000; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2199 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d", |
| 2200 | MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_RESP); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2201 | offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr, |
| 2202 | broadcast, |
| 2203 | wpabuf_head(msg), wpabuf_len(msg), |
| 2204 | wait_time, wpas_dpp_tx_pkex_status, 0); |
| 2205 | wpabuf_free(msg); |
| 2206 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2207 | wpas_dpp_pkex_finish(wpa_s, src, freq); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | |
| 2211 | static void |
| 2212 | wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant *wpa_s, const u8 *src, |
| 2213 | const u8 *hdr, const u8 *buf, size_t len, |
| 2214 | unsigned int freq) |
| 2215 | { |
| 2216 | int res; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2217 | struct dpp_bootstrap_info *bi; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2218 | struct dpp_pkex *pkex = wpa_s->dpp_pkex; |
| 2219 | char cmd[500]; |
| 2220 | |
| 2221 | wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Response from " MACSTR, |
| 2222 | MAC2STR(src)); |
| 2223 | |
| 2224 | if (!pkex || !pkex->initiator || !pkex->exchange_done) { |
| 2225 | wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session"); |
| 2226 | return; |
| 2227 | } |
| 2228 | |
| 2229 | res = dpp_pkex_rx_commit_reveal_resp(pkex, hdr, buf, len); |
| 2230 | if (res < 0) { |
| 2231 | wpa_printf(MSG_DEBUG, "DPP: Failed to process the response"); |
| 2232 | return; |
| 2233 | } |
| 2234 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2235 | bi = wpas_dpp_pkex_finish(wpa_s, src, freq); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2236 | if (!bi) |
| 2237 | return; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2238 | |
| 2239 | os_snprintf(cmd, sizeof(cmd), " peer=%u %s", |
| 2240 | bi->id, |
| 2241 | wpa_s->dpp_pkex_auth_cmd ? wpa_s->dpp_pkex_auth_cmd : ""); |
| 2242 | wpa_printf(MSG_DEBUG, |
| 2243 | "DPP: Start authentication after PKEX with parameters: %s", |
| 2244 | cmd); |
| 2245 | if (wpas_dpp_auth_init(wpa_s, cmd) < 0) { |
| 2246 | wpa_printf(MSG_DEBUG, |
| 2247 | "DPP: Authentication initialization failed"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2248 | offchannel_send_action_done(wpa_s); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2249 | return; |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | |
| 2254 | void wpas_dpp_rx_action(struct wpa_supplicant *wpa_s, const u8 *src, |
| 2255 | const u8 *buf, size_t len, unsigned int freq) |
| 2256 | { |
| 2257 | u8 crypto_suite; |
| 2258 | enum dpp_public_action_frame_type type; |
| 2259 | const u8 *hdr; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2260 | unsigned int pkex_t; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2261 | |
| 2262 | if (len < DPP_HDR_LEN) |
| 2263 | return; |
| 2264 | if (WPA_GET_BE24(buf) != OUI_WFA || buf[3] != DPP_OUI_TYPE) |
| 2265 | return; |
| 2266 | hdr = buf; |
| 2267 | buf += 4; |
| 2268 | len -= 4; |
| 2269 | crypto_suite = *buf++; |
| 2270 | type = *buf++; |
| 2271 | len -= 2; |
| 2272 | |
| 2273 | wpa_printf(MSG_DEBUG, |
| 2274 | "DPP: Received DPP Public Action frame crypto suite %u type %d from " |
| 2275 | MACSTR " freq=%u", |
| 2276 | crypto_suite, type, MAC2STR(src), freq); |
| 2277 | if (crypto_suite != 1) { |
| 2278 | wpa_printf(MSG_DEBUG, "DPP: Unsupported crypto suite %u", |
| 2279 | crypto_suite); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2280 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR |
| 2281 | " freq=%u type=%d ignore=unsupported-crypto-suite", |
| 2282 | MAC2STR(src), freq, type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2283 | return; |
| 2284 | } |
| 2285 | wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2286 | if (dpp_check_attrs(buf, len) < 0) { |
| 2287 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR |
| 2288 | " freq=%u type=%d ignore=invalid-attributes", |
| 2289 | MAC2STR(src), freq, type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2290 | return; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2291 | } |
| 2292 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR " freq=%u type=%d", |
| 2293 | MAC2STR(src), freq, type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2294 | |
| 2295 | switch (type) { |
| 2296 | case DPP_PA_AUTHENTICATION_REQ: |
| 2297 | wpas_dpp_rx_auth_req(wpa_s, src, hdr, buf, len, freq); |
| 2298 | break; |
| 2299 | case DPP_PA_AUTHENTICATION_RESP: |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2300 | wpas_dpp_rx_auth_resp(wpa_s, src, hdr, buf, len, freq); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2301 | break; |
| 2302 | case DPP_PA_AUTHENTICATION_CONF: |
| 2303 | wpas_dpp_rx_auth_conf(wpa_s, src, hdr, buf, len); |
| 2304 | break; |
| 2305 | case DPP_PA_PEER_DISCOVERY_RESP: |
| 2306 | wpas_dpp_rx_peer_disc_resp(wpa_s, src, buf, len); |
| 2307 | break; |
| 2308 | case DPP_PA_PKEX_EXCHANGE_REQ: |
| 2309 | wpas_dpp_rx_pkex_exchange_req(wpa_s, src, buf, len, freq); |
| 2310 | break; |
| 2311 | case DPP_PA_PKEX_EXCHANGE_RESP: |
| 2312 | wpas_dpp_rx_pkex_exchange_resp(wpa_s, src, buf, len, freq); |
| 2313 | break; |
| 2314 | case DPP_PA_PKEX_COMMIT_REVEAL_REQ: |
| 2315 | wpas_dpp_rx_pkex_commit_reveal_req(wpa_s, src, hdr, buf, len, |
| 2316 | freq); |
| 2317 | break; |
| 2318 | case DPP_PA_PKEX_COMMIT_REVEAL_RESP: |
| 2319 | wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s, src, hdr, buf, len, |
| 2320 | freq); |
| 2321 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2322 | #ifdef CONFIG_DPP2 |
| 2323 | case DPP_PA_CONFIGURATION_RESULT: |
| 2324 | wpas_dpp_rx_conf_result(wpa_s, src, hdr, buf, len); |
| 2325 | break; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2326 | case DPP_PA_CONNECTION_STATUS_RESULT: |
| 2327 | wpas_dpp_rx_conn_status_result(wpa_s, src, hdr, buf, len); |
| 2328 | break; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2329 | case DPP_PA_PRESENCE_ANNOUNCEMENT: |
| 2330 | wpas_dpp_rx_presence_announcement(wpa_s, src, hdr, buf, len, |
| 2331 | freq); |
| 2332 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2333 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2334 | default: |
| 2335 | wpa_printf(MSG_DEBUG, |
| 2336 | "DPP: Ignored unsupported frame subtype %d", type); |
| 2337 | break; |
| 2338 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2339 | |
| 2340 | if (wpa_s->dpp_pkex) |
| 2341 | pkex_t = wpa_s->dpp_pkex->t; |
| 2342 | else if (wpa_s->dpp_pkex_bi) |
| 2343 | pkex_t = wpa_s->dpp_pkex_bi->pkex_t; |
| 2344 | else |
| 2345 | pkex_t = 0; |
| 2346 | if (pkex_t >= PKEX_COUNTER_T_LIMIT) { |
| 2347 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_PKEX_T_LIMIT "id=0"); |
| 2348 | wpas_dpp_pkex_remove(wpa_s, "*"); |
| 2349 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | |
| 2353 | static struct wpabuf * |
| 2354 | wpas_dpp_gas_req_handler(void *ctx, const u8 *sa, const u8 *query, |
| 2355 | size_t query_len) |
| 2356 | { |
| 2357 | struct wpa_supplicant *wpa_s = ctx; |
| 2358 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 2359 | struct wpabuf *resp; |
| 2360 | |
| 2361 | wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR, |
| 2362 | MAC2STR(sa)); |
| 2363 | if (!auth || !auth->auth_success || |
| 2364 | os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) { |
| 2365 | wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress"); |
| 2366 | return NULL; |
| 2367 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2368 | |
| 2369 | if (wpa_s->dpp_auth_ok_on_ack && auth->configurator) { |
| 2370 | wpa_printf(MSG_DEBUG, |
| 2371 | "DPP: Have not received ACK for Auth Confirm yet - assume it was received based on this GAS request"); |
| 2372 | /* wpas_dpp_auth_success() would normally have been called from |
| 2373 | * TX status handler, but since there was no such handler call |
| 2374 | * yet, simply send out the event message and proceed with |
| 2375 | * exchange. */ |
| 2376 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=1"); |
| 2377 | wpa_s->dpp_auth_ok_on_ack = 0; |
| 2378 | } |
| 2379 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2380 | wpa_hexdump(MSG_DEBUG, |
| 2381 | "DPP: Received Configuration Request (GAS Query Request)", |
| 2382 | query, query_len); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2383 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_REQ_RX "src=" MACSTR, |
| 2384 | MAC2STR(sa)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2385 | resp = dpp_conf_req_rx(auth, query, query_len); |
Hai Shalom | 5953285 | 2018-12-07 10:32:58 -0800 | [diff] [blame] | 2386 | if (!resp) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2387 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED); |
Hai Shalom | 706f99b | 2019-01-08 16:23:37 -0800 | [diff] [blame] | 2388 | wpas_notify_dpp_configuration_failure(wpa_s); |
Hai Shalom | 5953285 | 2018-12-07 10:32:58 -0800 | [diff] [blame] | 2389 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2390 | auth->conf_resp = resp; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2391 | return resp; |
| 2392 | } |
| 2393 | |
| 2394 | |
| 2395 | static void |
| 2396 | wpas_dpp_gas_status_handler(void *ctx, struct wpabuf *resp, int ok) |
| 2397 | { |
| 2398 | struct wpa_supplicant *wpa_s = ctx; |
| 2399 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
| 2400 | |
| 2401 | if (!auth) { |
| 2402 | wpabuf_free(resp); |
| 2403 | return; |
| 2404 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2405 | if (auth->conf_resp != resp) { |
| 2406 | wpa_printf(MSG_DEBUG, |
| 2407 | "DPP: Ignore GAS status report (ok=%d) for unknown response", |
| 2408 | ok); |
| 2409 | wpabuf_free(resp); |
| 2410 | return; |
| 2411 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2412 | |
| 2413 | wpa_printf(MSG_DEBUG, "DPP: Configuration exchange completed (ok=%d)", |
| 2414 | ok); |
| 2415 | eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2416 | eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2417 | #ifdef CONFIG_DPP2 |
| 2418 | if (ok && auth->peer_version >= 2 && |
| 2419 | auth->conf_resp_status == DPP_STATUS_OK) { |
| 2420 | wpa_printf(MSG_DEBUG, "DPP: Wait for Configuration Result"); |
Hai Shalom | 0676811 | 2019-12-04 15:49:43 -0800 | [diff] [blame] | 2421 | wpas_notify_dpp_config_sent_wait_response(wpa_s); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2422 | auth->waiting_conf_result = 1; |
| 2423 | auth->conf_resp = NULL; |
| 2424 | wpabuf_free(resp); |
| 2425 | eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, |
| 2426 | wpa_s, NULL); |
| 2427 | eloop_register_timeout(2, 0, |
| 2428 | wpas_dpp_config_result_wait_timeout, |
| 2429 | wpa_s, NULL); |
| 2430 | return; |
| 2431 | } |
| 2432 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2433 | offchannel_send_action_done(wpa_s); |
| 2434 | wpas_dpp_listen_stop(wpa_s); |
Hai Shalom | 5953285 | 2018-12-07 10:32:58 -0800 | [diff] [blame] | 2435 | if (ok) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2436 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT); |
Hai Shalom | 706f99b | 2019-01-08 16:23:37 -0800 | [diff] [blame] | 2437 | wpas_notify_dpp_config_sent(wpa_s); |
Hai Shalom | 5953285 | 2018-12-07 10:32:58 -0800 | [diff] [blame] | 2438 | } |
| 2439 | else { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2440 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED); |
Hai Shalom | 706f99b | 2019-01-08 16:23:37 -0800 | [diff] [blame] | 2441 | wpas_notify_dpp_configuration_failure(wpa_s); |
Hai Shalom | 5953285 | 2018-12-07 10:32:58 -0800 | [diff] [blame] | 2442 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2443 | dpp_auth_deinit(wpa_s->dpp_auth); |
| 2444 | wpa_s->dpp_auth = NULL; |
| 2445 | wpabuf_free(resp); |
| 2446 | } |
| 2447 | |
| 2448 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2449 | int wpas_dpp_configurator_sign(struct wpa_supplicant *wpa_s, const char *cmd) |
| 2450 | { |
| 2451 | struct dpp_authentication *auth; |
| 2452 | int ret = -1; |
| 2453 | char *curve = NULL; |
| 2454 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2455 | auth = dpp_alloc_auth(wpa_s->dpp, wpa_s); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2456 | if (!auth) |
| 2457 | return -1; |
| 2458 | |
| 2459 | curve = get_param(cmd, " curve="); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2460 | wpas_dpp_set_testing_options(wpa_s, auth); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2461 | if (dpp_set_configurator(auth, cmd) == 0 && |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2462 | dpp_configurator_own_config(auth, curve, 0) == 0) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2463 | ret = wpas_dpp_handle_config_obj(wpa_s, auth, |
| 2464 | &auth->conf_obj[0]); |
| 2465 | if (!ret) |
| 2466 | wpas_dpp_post_process_config(wpa_s, auth); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2467 | |
| 2468 | dpp_auth_deinit(auth); |
| 2469 | os_free(curve); |
| 2470 | |
| 2471 | return ret; |
| 2472 | } |
| 2473 | |
| 2474 | |
| 2475 | static void |
| 2476 | wpas_dpp_tx_introduction_status(struct wpa_supplicant *wpa_s, |
| 2477 | unsigned int freq, const u8 *dst, |
| 2478 | const u8 *src, const u8 *bssid, |
| 2479 | const u8 *data, size_t data_len, |
| 2480 | enum offchannel_send_action_result result) |
| 2481 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2482 | const char *res_txt; |
| 2483 | |
| 2484 | res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" : |
| 2485 | (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" : |
| 2486 | "FAILED"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2487 | wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR |
| 2488 | " result=%s (DPP Peer Discovery Request)", |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2489 | freq, MAC2STR(dst), res_txt); |
| 2490 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR |
| 2491 | " freq=%u result=%s", MAC2STR(dst), freq, res_txt); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2492 | /* TODO: Time out wait for response more quickly in error cases? */ |
| 2493 | } |
| 2494 | |
| 2495 | |
| 2496 | int wpas_dpp_check_connect(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 2497 | struct wpa_bss *bss) |
| 2498 | { |
| 2499 | struct os_time now; |
| 2500 | struct wpabuf *msg; |
| 2501 | unsigned int wait_time; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2502 | const u8 *rsn; |
| 2503 | struct wpa_ie_data ied; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2504 | |
| 2505 | if (!(ssid->key_mgmt & WPA_KEY_MGMT_DPP) || !bss) |
| 2506 | return 0; /* Not using DPP AKM - continue */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2507 | rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 2508 | if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ied) == 0 && |
| 2509 | !(ied.key_mgmt & WPA_KEY_MGMT_DPP)) |
| 2510 | return 0; /* AP does not support DPP AKM - continue */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2511 | if (wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid)) |
| 2512 | return 0; /* PMKSA exists for DPP AKM - continue */ |
| 2513 | |
| 2514 | if (!ssid->dpp_connector || !ssid->dpp_netaccesskey || |
| 2515 | !ssid->dpp_csign) { |
| 2516 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR |
| 2517 | "missing %s", |
| 2518 | !ssid->dpp_connector ? "Connector" : |
| 2519 | (!ssid->dpp_netaccesskey ? "netAccessKey" : |
| 2520 | "C-sign-key")); |
| 2521 | return -1; |
| 2522 | } |
| 2523 | |
| 2524 | os_get_time(&now); |
| 2525 | |
| 2526 | if (ssid->dpp_netaccesskey_expiry && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2527 | (os_time_t) ssid->dpp_netaccesskey_expiry < now.sec) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2528 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR |
| 2529 | "netAccessKey expired"); |
| 2530 | return -1; |
| 2531 | } |
| 2532 | |
| 2533 | wpa_printf(MSG_DEBUG, |
| 2534 | "DPP: Starting network introduction protocol to derive PMKSA for " |
| 2535 | MACSTR, MAC2STR(bss->bssid)); |
| 2536 | |
| 2537 | msg = dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ, |
| 2538 | 5 + 4 + os_strlen(ssid->dpp_connector)); |
| 2539 | if (!msg) |
| 2540 | return -1; |
| 2541 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2542 | #ifdef CONFIG_TESTING_OPTIONS |
| 2543 | if (dpp_test == DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ) { |
| 2544 | wpa_printf(MSG_INFO, "DPP: TESTING - no Transaction ID"); |
| 2545 | goto skip_trans_id; |
| 2546 | } |
| 2547 | if (dpp_test == DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ) { |
| 2548 | wpa_printf(MSG_INFO, "DPP: TESTING - invalid Transaction ID"); |
| 2549 | wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID); |
| 2550 | wpabuf_put_le16(msg, 0); |
| 2551 | goto skip_trans_id; |
| 2552 | } |
| 2553 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2554 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2555 | /* Transaction ID */ |
| 2556 | wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID); |
| 2557 | wpabuf_put_le16(msg, 1); |
| 2558 | wpabuf_put_u8(msg, TRANSACTION_ID); |
| 2559 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2560 | #ifdef CONFIG_TESTING_OPTIONS |
| 2561 | skip_trans_id: |
| 2562 | if (dpp_test == DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ) { |
| 2563 | wpa_printf(MSG_INFO, "DPP: TESTING - no Connector"); |
| 2564 | goto skip_connector; |
| 2565 | } |
| 2566 | if (dpp_test == DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ) { |
| 2567 | char *connector; |
| 2568 | |
| 2569 | wpa_printf(MSG_INFO, "DPP: TESTING - invalid Connector"); |
| 2570 | connector = dpp_corrupt_connector_signature( |
| 2571 | ssid->dpp_connector); |
| 2572 | if (!connector) { |
| 2573 | wpabuf_free(msg); |
| 2574 | return -1; |
| 2575 | } |
| 2576 | wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR); |
| 2577 | wpabuf_put_le16(msg, os_strlen(connector)); |
| 2578 | wpabuf_put_str(msg, connector); |
| 2579 | os_free(connector); |
| 2580 | goto skip_connector; |
| 2581 | } |
| 2582 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2583 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2584 | /* DPP Connector */ |
| 2585 | wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR); |
| 2586 | wpabuf_put_le16(msg, os_strlen(ssid->dpp_connector)); |
| 2587 | wpabuf_put_str(msg, ssid->dpp_connector); |
| 2588 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2589 | #ifdef CONFIG_TESTING_OPTIONS |
| 2590 | skip_connector: |
| 2591 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2592 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2593 | /* TODO: Timeout on AP response */ |
| 2594 | wait_time = wpa_s->max_remain_on_chan; |
| 2595 | if (wait_time > 2000) |
| 2596 | wait_time = 2000; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2597 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d", |
| 2598 | MAC2STR(bss->bssid), bss->freq, DPP_PA_PEER_DISCOVERY_REQ); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2599 | offchannel_send_action(wpa_s, bss->freq, bss->bssid, wpa_s->own_addr, |
| 2600 | broadcast, |
| 2601 | wpabuf_head(msg), wpabuf_len(msg), |
| 2602 | wait_time, wpas_dpp_tx_introduction_status, 0); |
| 2603 | wpabuf_free(msg); |
| 2604 | |
| 2605 | /* Request this connection attempt to terminate - new one will be |
| 2606 | * started when network introduction protocol completes */ |
| 2607 | os_memcpy(wpa_s->dpp_intro_bssid, bss->bssid, ETH_ALEN); |
| 2608 | wpa_s->dpp_intro_network = ssid; |
| 2609 | return 1; |
| 2610 | } |
| 2611 | |
| 2612 | |
| 2613 | int wpas_dpp_pkex_add(struct wpa_supplicant *wpa_s, const char *cmd) |
| 2614 | { |
| 2615 | struct dpp_bootstrap_info *own_bi; |
| 2616 | const char *pos, *end; |
| 2617 | unsigned int wait_time; |
| 2618 | |
| 2619 | pos = os_strstr(cmd, " own="); |
| 2620 | if (!pos) |
| 2621 | return -1; |
| 2622 | pos += 5; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2623 | own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2624 | if (!own_bi) { |
| 2625 | wpa_printf(MSG_DEBUG, |
| 2626 | "DPP: Identified bootstrap info not found"); |
| 2627 | return -1; |
| 2628 | } |
| 2629 | if (own_bi->type != DPP_BOOTSTRAP_PKEX) { |
| 2630 | wpa_printf(MSG_DEBUG, |
| 2631 | "DPP: Identified bootstrap info not for PKEX"); |
| 2632 | return -1; |
| 2633 | } |
| 2634 | wpa_s->dpp_pkex_bi = own_bi; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2635 | own_bi->pkex_t = 0; /* clear pending errors on new code */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2636 | |
| 2637 | os_free(wpa_s->dpp_pkex_identifier); |
| 2638 | wpa_s->dpp_pkex_identifier = NULL; |
| 2639 | pos = os_strstr(cmd, " identifier="); |
| 2640 | if (pos) { |
| 2641 | pos += 12; |
| 2642 | end = os_strchr(pos, ' '); |
| 2643 | if (!end) |
| 2644 | return -1; |
| 2645 | wpa_s->dpp_pkex_identifier = os_malloc(end - pos + 1); |
| 2646 | if (!wpa_s->dpp_pkex_identifier) |
| 2647 | return -1; |
| 2648 | os_memcpy(wpa_s->dpp_pkex_identifier, pos, end - pos); |
| 2649 | wpa_s->dpp_pkex_identifier[end - pos] = '\0'; |
| 2650 | } |
| 2651 | |
| 2652 | pos = os_strstr(cmd, " code="); |
| 2653 | if (!pos) |
| 2654 | return -1; |
| 2655 | os_free(wpa_s->dpp_pkex_code); |
| 2656 | wpa_s->dpp_pkex_code = os_strdup(pos + 6); |
| 2657 | if (!wpa_s->dpp_pkex_code) |
| 2658 | return -1; |
| 2659 | |
| 2660 | if (os_strstr(cmd, " init=1")) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2661 | struct dpp_pkex *pkex; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2662 | struct wpabuf *msg; |
| 2663 | |
| 2664 | wpa_printf(MSG_DEBUG, "DPP: Initiating PKEX"); |
| 2665 | dpp_pkex_free(wpa_s->dpp_pkex); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2666 | wpa_s->dpp_pkex = dpp_pkex_init(wpa_s, own_bi, wpa_s->own_addr, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2667 | wpa_s->dpp_pkex_identifier, |
| 2668 | wpa_s->dpp_pkex_code); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2669 | pkex = wpa_s->dpp_pkex; |
| 2670 | if (!pkex) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2671 | return -1; |
| 2672 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2673 | msg = pkex->exchange_req; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2674 | wait_time = wpa_s->max_remain_on_chan; |
| 2675 | if (wait_time > 2000) |
| 2676 | wait_time = 2000; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2677 | pkex->freq = 2437; |
| 2678 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR |
| 2679 | " freq=%u type=%d", |
| 2680 | MAC2STR(broadcast), pkex->freq, |
| 2681 | DPP_PA_PKEX_EXCHANGE_REQ); |
| 2682 | offchannel_send_action(wpa_s, pkex->freq, broadcast, |
| 2683 | wpa_s->own_addr, broadcast, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2684 | wpabuf_head(msg), wpabuf_len(msg), |
| 2685 | wait_time, wpas_dpp_tx_pkex_status, 0); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2686 | if (wait_time == 0) |
| 2687 | wait_time = 2000; |
| 2688 | pkex->exch_req_wait_time = wait_time; |
| 2689 | pkex->exch_req_tries = 1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | /* TODO: Support multiple PKEX info entries */ |
| 2693 | |
| 2694 | os_free(wpa_s->dpp_pkex_auth_cmd); |
| 2695 | wpa_s->dpp_pkex_auth_cmd = os_strdup(cmd); |
| 2696 | |
| 2697 | return 1; |
| 2698 | } |
| 2699 | |
| 2700 | |
| 2701 | int wpas_dpp_pkex_remove(struct wpa_supplicant *wpa_s, const char *id) |
| 2702 | { |
| 2703 | unsigned int id_val; |
| 2704 | |
| 2705 | if (os_strcmp(id, "*") == 0) { |
| 2706 | id_val = 0; |
| 2707 | } else { |
| 2708 | id_val = atoi(id); |
| 2709 | if (id_val == 0) |
| 2710 | return -1; |
| 2711 | } |
| 2712 | |
| 2713 | if ((id_val != 0 && id_val != 1) || !wpa_s->dpp_pkex_code) |
| 2714 | return -1; |
| 2715 | |
| 2716 | /* TODO: Support multiple PKEX entries */ |
| 2717 | os_free(wpa_s->dpp_pkex_code); |
| 2718 | wpa_s->dpp_pkex_code = NULL; |
| 2719 | os_free(wpa_s->dpp_pkex_identifier); |
| 2720 | wpa_s->dpp_pkex_identifier = NULL; |
| 2721 | os_free(wpa_s->dpp_pkex_auth_cmd); |
| 2722 | wpa_s->dpp_pkex_auth_cmd = NULL; |
| 2723 | wpa_s->dpp_pkex_bi = NULL; |
| 2724 | /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */ |
| 2725 | dpp_pkex_free(wpa_s->dpp_pkex); |
| 2726 | wpa_s->dpp_pkex = NULL; |
| 2727 | return 0; |
| 2728 | } |
| 2729 | |
| 2730 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2731 | void wpas_dpp_stop(struct wpa_supplicant *wpa_s) |
| 2732 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2733 | if (wpa_s->dpp_auth || wpa_s->dpp_pkex) |
| 2734 | offchannel_send_action_done(wpa_s); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2735 | dpp_auth_deinit(wpa_s->dpp_auth); |
| 2736 | wpa_s->dpp_auth = NULL; |
| 2737 | dpp_pkex_free(wpa_s->dpp_pkex); |
| 2738 | wpa_s->dpp_pkex = NULL; |
| 2739 | if (wpa_s->dpp_gas_client && wpa_s->dpp_gas_dialog_token >= 0) |
| 2740 | gas_query_stop(wpa_s->gas, wpa_s->dpp_gas_dialog_token); |
| 2741 | } |
| 2742 | |
| 2743 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2744 | int wpas_dpp_init(struct wpa_supplicant *wpa_s) |
| 2745 | { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2746 | struct dpp_global_config config; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2747 | u8 adv_proto_id[7]; |
| 2748 | |
| 2749 | adv_proto_id[0] = WLAN_EID_VENDOR_SPECIFIC; |
| 2750 | adv_proto_id[1] = 5; |
| 2751 | WPA_PUT_BE24(&adv_proto_id[2], OUI_WFA); |
| 2752 | adv_proto_id[5] = DPP_OUI_TYPE; |
| 2753 | adv_proto_id[6] = 0x01; |
| 2754 | |
| 2755 | if (gas_server_register(wpa_s->gas_server, adv_proto_id, |
| 2756 | sizeof(adv_proto_id), wpas_dpp_gas_req_handler, |
| 2757 | wpas_dpp_gas_status_handler, wpa_s) < 0) |
| 2758 | return -1; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2759 | |
| 2760 | os_memset(&config, 0, sizeof(config)); |
| 2761 | config.msg_ctx = wpa_s; |
| 2762 | config.cb_ctx = wpa_s; |
| 2763 | #ifdef CONFIG_DPP2 |
| 2764 | config.process_conf_obj = wpas_dpp_process_conf_obj; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2765 | config.remove_bi = wpas_dpp_remove_bi; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2766 | #endif /* CONFIG_DPP2 */ |
| 2767 | wpa_s->dpp = dpp_global_init(&config); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2768 | return wpa_s->dpp ? 0 : -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | |
| 2772 | void wpas_dpp_deinit(struct wpa_supplicant *wpa_s) |
| 2773 | { |
| 2774 | #ifdef CONFIG_TESTING_OPTIONS |
| 2775 | os_free(wpa_s->dpp_config_obj_override); |
| 2776 | wpa_s->dpp_config_obj_override = NULL; |
| 2777 | os_free(wpa_s->dpp_discovery_override); |
| 2778 | wpa_s->dpp_discovery_override = NULL; |
| 2779 | os_free(wpa_s->dpp_groups_override); |
| 2780 | wpa_s->dpp_groups_override = NULL; |
| 2781 | wpa_s->dpp_ignore_netaccesskey_mismatch = 0; |
| 2782 | #endif /* CONFIG_TESTING_OPTIONS */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2783 | if (!wpa_s->dpp) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2784 | return; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2785 | dpp_global_clear(wpa_s->dpp); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2786 | eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2787 | eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2788 | eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL); |
| 2789 | eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2790 | #ifdef CONFIG_DPP2 |
| 2791 | eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2792 | eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout, |
| 2793 | wpa_s, NULL); |
| 2794 | eloop_cancel_timeout(wpas_dpp_conn_status_result_timeout, wpa_s, NULL); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2795 | dpp_pfs_free(wpa_s->dpp_pfs); |
| 2796 | wpa_s->dpp_pfs = NULL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2797 | wpas_dpp_chirp_stop(wpa_s); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2798 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2799 | offchannel_send_action_done(wpa_s); |
| 2800 | wpas_dpp_listen_stop(wpa_s); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2801 | wpas_dpp_stop(wpa_s); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2802 | wpas_dpp_pkex_remove(wpa_s, "*"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2803 | os_memset(wpa_s->dpp_intro_bssid, 0, ETH_ALEN); |
| 2804 | os_free(wpa_s->dpp_configurator_params); |
| 2805 | wpa_s->dpp_configurator_params = NULL; |
| 2806 | } |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2807 | |
| 2808 | |
| 2809 | #ifdef CONFIG_DPP2 |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2810 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2811 | int wpas_dpp_controller_start(struct wpa_supplicant *wpa_s, const char *cmd) |
| 2812 | { |
| 2813 | struct dpp_controller_config config; |
| 2814 | const char *pos; |
| 2815 | |
| 2816 | os_memset(&config, 0, sizeof(config)); |
| 2817 | if (cmd) { |
| 2818 | pos = os_strstr(cmd, " tcp_port="); |
| 2819 | if (pos) { |
| 2820 | pos += 10; |
| 2821 | config.tcp_port = atoi(pos); |
| 2822 | } |
| 2823 | } |
| 2824 | config.configurator_params = wpa_s->dpp_configurator_params; |
| 2825 | return dpp_controller_start(wpa_s->dpp, &config); |
| 2826 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2827 | |
| 2828 | |
| 2829 | static void wpas_dpp_chirp_next(void *eloop_ctx, void *timeout_ctx); |
| 2830 | |
| 2831 | static void wpas_dpp_chirp_timeout(void *eloop_ctx, void *timeout_ctx) |
| 2832 | { |
| 2833 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 2834 | |
| 2835 | wpa_printf(MSG_DEBUG, "DPP: No chirp response received"); |
| 2836 | offchannel_send_action_done(wpa_s); |
| 2837 | wpas_dpp_chirp_next(wpa_s, NULL); |
| 2838 | } |
| 2839 | |
| 2840 | |
| 2841 | static void wpas_dpp_chirp_tx_status(struct wpa_supplicant *wpa_s, |
| 2842 | unsigned int freq, const u8 *dst, |
| 2843 | const u8 *src, const u8 *bssid, |
| 2844 | const u8 *data, size_t data_len, |
| 2845 | enum offchannel_send_action_result result) |
| 2846 | { |
| 2847 | if (result == OFFCHANNEL_SEND_ACTION_FAILED) { |
| 2848 | wpa_printf(MSG_DEBUG, "DPP: Failed to send chirp on %d MHz", |
| 2849 | wpa_s->dpp_chirp_freq); |
| 2850 | if (eloop_register_timeout(0, 0, wpas_dpp_chirp_next, |
| 2851 | wpa_s, NULL) < 0) |
| 2852 | wpas_dpp_chirp_stop(wpa_s); |
| 2853 | return; |
| 2854 | } |
| 2855 | |
| 2856 | wpa_printf(MSG_DEBUG, "DPP: Chirp send completed - wait for response"); |
| 2857 | if (eloop_register_timeout(2, 0, wpas_dpp_chirp_timeout, |
| 2858 | wpa_s, NULL) < 0) |
| 2859 | wpas_dpp_chirp_stop(wpa_s); |
| 2860 | } |
| 2861 | |
| 2862 | |
| 2863 | static void wpas_dpp_chirp_start(struct wpa_supplicant *wpa_s) |
| 2864 | { |
| 2865 | wpa_printf(MSG_DEBUG, "DPP: Chirp on %d MHz", wpa_s->dpp_chirp_freq); |
| 2866 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d", |
| 2867 | MAC2STR(broadcast), wpa_s->dpp_chirp_freq, |
| 2868 | DPP_PA_PRESENCE_ANNOUNCEMENT); |
| 2869 | if (offchannel_send_action( |
| 2870 | wpa_s, wpa_s->dpp_chirp_freq, broadcast, |
| 2871 | wpa_s->own_addr, broadcast, |
| 2872 | wpabuf_head(wpa_s->dpp_presence_announcement), |
| 2873 | wpabuf_len(wpa_s->dpp_presence_announcement), |
| 2874 | 2000, wpas_dpp_chirp_tx_status, 0) < 0) |
| 2875 | wpas_dpp_chirp_stop(wpa_s); |
| 2876 | } |
| 2877 | |
| 2878 | |
| 2879 | static void wpas_dpp_chirp_scan_res_handler(struct wpa_supplicant *wpa_s, |
| 2880 | struct wpa_scan_results *scan_res) |
| 2881 | { |
| 2882 | struct dpp_bootstrap_info *bi = wpa_s->dpp_chirp_bi; |
| 2883 | unsigned int i; |
| 2884 | struct hostapd_hw_modes *mode; |
| 2885 | int c; |
| 2886 | struct wpa_bss *bss; |
| 2887 | |
| 2888 | if (!bi) |
| 2889 | return; |
| 2890 | |
| 2891 | wpa_s->dpp_chirp_scan_done = 1; |
| 2892 | |
| 2893 | os_free(wpa_s->dpp_chirp_freqs); |
| 2894 | wpa_s->dpp_chirp_freqs = NULL; |
| 2895 | |
| 2896 | /* Channels from own bootstrapping info */ |
| 2897 | for (i = 0; i < bi->num_freq; i++) |
| 2898 | int_array_add_unique(&wpa_s->dpp_chirp_freqs, bi->freq[i]); |
| 2899 | |
| 2900 | /* Preferred chirping channels */ |
| 2901 | int_array_add_unique(&wpa_s->dpp_chirp_freqs, 2437); |
| 2902 | |
| 2903 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
| 2904 | HOSTAPD_MODE_IEEE80211A, 0); |
| 2905 | if (mode) { |
| 2906 | int chan44 = 0, chan149 = 0; |
| 2907 | |
| 2908 | for (c = 0; c < mode->num_channels; c++) { |
| 2909 | struct hostapd_channel_data *chan = &mode->channels[c]; |
| 2910 | |
| 2911 | if (chan->flag & (HOSTAPD_CHAN_DISABLED | |
| 2912 | HOSTAPD_CHAN_RADAR)) |
| 2913 | continue; |
| 2914 | if (chan->freq == 5220) |
| 2915 | chan44 = 1; |
| 2916 | if (chan->freq == 5745) |
| 2917 | chan149 = 1; |
| 2918 | } |
| 2919 | if (chan149) |
| 2920 | int_array_add_unique(&wpa_s->dpp_chirp_freqs, 5745); |
| 2921 | else if (chan44) |
| 2922 | int_array_add_unique(&wpa_s->dpp_chirp_freqs, 5220); |
| 2923 | } |
| 2924 | |
| 2925 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
| 2926 | HOSTAPD_MODE_IEEE80211AD, 0); |
| 2927 | if (mode) { |
| 2928 | for (c = 0; c < mode->num_channels; c++) { |
| 2929 | struct hostapd_channel_data *chan = &mode->channels[c]; |
| 2930 | |
| 2931 | if ((chan->flag & (HOSTAPD_CHAN_DISABLED | |
| 2932 | HOSTAPD_CHAN_RADAR)) || |
| 2933 | chan->freq != 60480) |
| 2934 | continue; |
| 2935 | int_array_add_unique(&wpa_s->dpp_chirp_freqs, 60480); |
| 2936 | break; |
| 2937 | } |
| 2938 | } |
| 2939 | |
| 2940 | /* Add channels from scan results for APs that advertise Configurator |
| 2941 | * Connectivity element */ |
| 2942 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 2943 | if (wpa_bss_get_vendor_ie(bss, DPP_CC_IE_VENDOR_TYPE)) |
| 2944 | int_array_add_unique(&wpa_s->dpp_chirp_freqs, |
| 2945 | bss->freq); |
| 2946 | } |
| 2947 | |
| 2948 | if (!wpa_s->dpp_chirp_freqs || |
| 2949 | eloop_register_timeout(0, 0, wpas_dpp_chirp_next, wpa_s, NULL) < 0) |
| 2950 | wpas_dpp_chirp_stop(wpa_s); |
| 2951 | } |
| 2952 | |
| 2953 | |
| 2954 | static void wpas_dpp_chirp_next(void *eloop_ctx, void *timeout_ctx) |
| 2955 | { |
| 2956 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 2957 | int i; |
| 2958 | |
| 2959 | if (wpa_s->dpp_chirp_listen) |
| 2960 | wpas_dpp_listen_stop(wpa_s); |
| 2961 | |
| 2962 | if (wpa_s->dpp_chirp_freq == 0) { |
| 2963 | if (wpa_s->dpp_chirp_round % 4 == 0 && |
| 2964 | !wpa_s->dpp_chirp_scan_done) { |
| 2965 | wpa_printf(MSG_DEBUG, |
| 2966 | "DPP: Update channel list for chirping"); |
| 2967 | wpa_s->scan_req = MANUAL_SCAN_REQ; |
| 2968 | wpa_s->scan_res_handler = |
| 2969 | wpas_dpp_chirp_scan_res_handler; |
| 2970 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 2971 | return; |
| 2972 | } |
| 2973 | wpa_s->dpp_chirp_freq = wpa_s->dpp_chirp_freqs[0]; |
| 2974 | wpa_s->dpp_chirp_round++; |
| 2975 | wpa_printf(MSG_DEBUG, "DPP: Start chirping round %d", |
| 2976 | wpa_s->dpp_chirp_round); |
| 2977 | } else { |
| 2978 | for (i = 0; wpa_s->dpp_chirp_freqs[i]; i++) |
| 2979 | if (wpa_s->dpp_chirp_freqs[i] == wpa_s->dpp_chirp_freq) |
| 2980 | break; |
| 2981 | if (!wpa_s->dpp_chirp_freqs[i]) { |
| 2982 | wpa_printf(MSG_DEBUG, |
| 2983 | "DPP: Previous chirp freq %d not found", |
| 2984 | wpa_s->dpp_chirp_freq); |
| 2985 | return; |
| 2986 | } |
| 2987 | i++; |
| 2988 | if (wpa_s->dpp_chirp_freqs[i]) { |
| 2989 | wpa_s->dpp_chirp_freq = wpa_s->dpp_chirp_freqs[i]; |
| 2990 | } else { |
| 2991 | wpa_s->dpp_chirp_iter--; |
| 2992 | if (wpa_s->dpp_chirp_iter <= 0) { |
| 2993 | wpa_printf(MSG_DEBUG, |
| 2994 | "DPP: Chirping iterations completed"); |
| 2995 | wpas_dpp_chirp_stop(wpa_s); |
| 2996 | return; |
| 2997 | } |
| 2998 | wpa_s->dpp_chirp_freq = 0; |
| 2999 | wpa_s->dpp_chirp_scan_done = 0; |
| 3000 | if (eloop_register_timeout(30, 0, wpas_dpp_chirp_next, |
| 3001 | wpa_s, NULL) < 0) { |
| 3002 | wpas_dpp_chirp_stop(wpa_s); |
| 3003 | return; |
| 3004 | } |
| 3005 | if (wpa_s->dpp_chirp_listen) { |
| 3006 | wpa_printf(MSG_DEBUG, |
| 3007 | "DPP: Listen on %d MHz during chirp 30 second wait", |
| 3008 | wpa_s->dpp_chirp_listen); |
| 3009 | wpas_dpp_listen_start(wpa_s, |
| 3010 | wpa_s->dpp_chirp_listen); |
| 3011 | } else { |
| 3012 | wpa_printf(MSG_DEBUG, |
| 3013 | "DPP: Wait 30 seconds before starting the next chirping round"); |
| 3014 | } |
| 3015 | return; |
| 3016 | } |
| 3017 | } |
| 3018 | |
| 3019 | wpas_dpp_chirp_start(wpa_s); |
| 3020 | } |
| 3021 | |
| 3022 | |
| 3023 | int wpas_dpp_chirp(struct wpa_supplicant *wpa_s, const char *cmd) |
| 3024 | { |
| 3025 | const char *pos; |
| 3026 | int iter = 1, listen_freq = 0; |
| 3027 | struct dpp_bootstrap_info *bi; |
| 3028 | |
| 3029 | pos = os_strstr(cmd, " own="); |
| 3030 | if (!pos) |
| 3031 | return -1; |
| 3032 | pos += 5; |
| 3033 | bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos)); |
| 3034 | if (!bi) { |
| 3035 | wpa_printf(MSG_DEBUG, |
| 3036 | "DPP: Identified bootstrap info not found"); |
| 3037 | return -1; |
| 3038 | } |
| 3039 | |
| 3040 | pos = os_strstr(cmd, " iter="); |
| 3041 | if (pos) { |
| 3042 | iter = atoi(pos + 6); |
| 3043 | if (iter <= 0) |
| 3044 | return -1; |
| 3045 | } |
| 3046 | |
| 3047 | pos = os_strstr(cmd, " listen="); |
| 3048 | if (pos) { |
| 3049 | listen_freq = atoi(pos + 8); |
| 3050 | if (iter <= 0) |
| 3051 | return -1; |
| 3052 | } |
| 3053 | |
| 3054 | wpas_dpp_chirp_stop(wpa_s); |
| 3055 | wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE; |
| 3056 | wpa_s->dpp_qr_mutual = 0; |
| 3057 | wpa_s->dpp_chirp_bi = bi; |
| 3058 | wpa_s->dpp_presence_announcement = dpp_build_presence_announcement(bi); |
| 3059 | if (!wpa_s->dpp_presence_announcement) |
| 3060 | return -1; |
| 3061 | wpa_s->dpp_chirp_iter = iter; |
| 3062 | wpa_s->dpp_chirp_round = 0; |
| 3063 | wpa_s->dpp_chirp_scan_done = 0; |
| 3064 | wpa_s->dpp_chirp_listen = listen_freq; |
| 3065 | |
| 3066 | return eloop_register_timeout(0, 0, wpas_dpp_chirp_next, wpa_s, NULL); |
| 3067 | } |
| 3068 | |
| 3069 | |
| 3070 | void wpas_dpp_chirp_stop(struct wpa_supplicant *wpa_s) |
| 3071 | { |
| 3072 | if (wpa_s->dpp_presence_announcement) { |
| 3073 | offchannel_send_action_done(wpa_s); |
| 3074 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CHIRP_STOPPED); |
| 3075 | } |
| 3076 | wpa_s->dpp_chirp_bi = NULL; |
| 3077 | wpabuf_free(wpa_s->dpp_presence_announcement); |
| 3078 | wpa_s->dpp_presence_announcement = NULL; |
| 3079 | if (wpa_s->dpp_chirp_listen) |
| 3080 | wpas_dpp_listen_stop(wpa_s); |
| 3081 | wpa_s->dpp_chirp_listen = 0; |
| 3082 | wpa_s->dpp_chirp_freq = 0; |
| 3083 | os_free(wpa_s->dpp_chirp_freqs); |
| 3084 | wpa_s->dpp_chirp_freqs = NULL; |
| 3085 | eloop_cancel_timeout(wpas_dpp_chirp_next, wpa_s, NULL); |
| 3086 | eloop_cancel_timeout(wpas_dpp_chirp_timeout, wpa_s, NULL); |
| 3087 | if (wpa_s->scan_res_handler == wpas_dpp_chirp_scan_res_handler) { |
| 3088 | wpas_abort_ongoing_scan(wpa_s); |
| 3089 | wpa_s->scan_res_handler = NULL; |
| 3090 | } |
| 3091 | } |
| 3092 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3093 | #endif /* CONFIG_DPP2 */ |