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