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