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