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