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