3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
4 * Copyright (c) 2018-2020, The Linux Foundation
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
10 #include "utils/includes.h"
12 #include "utils/common.h"
13 #include "utils/eloop.h"
14 #include "utils/ip_addr.h"
15 #include "common/dpp.h"
16 #include "common/gas.h"
17 #include "common/gas_server.h"
18 #include "rsn_supp/wpa.h"
19 #include "rsn_supp/pmksa_cache.h"
20 #include "wpa_supplicant_i.h"
23 #include "offchannel.h"
24 #include "gas_query.h"
28 #include "dpp_supplicant.h"
31 static int wpas_dpp_listen_start(struct wpa_supplicant
*wpa_s
,
33 static void wpas_dpp_reply_wait_timeout(void *eloop_ctx
, void *timeout_ctx
);
34 static void wpas_dpp_auth_success(struct wpa_supplicant
*wpa_s
, int initiator
);
35 static void wpas_dpp_tx_status(struct wpa_supplicant
*wpa_s
,
36 unsigned int freq
, const u8
*dst
,
37 const u8
*src
, const u8
*bssid
,
38 const u8
*data
, size_t data_len
,
39 enum offchannel_send_action_result result
);
40 static void wpas_dpp_init_timeout(void *eloop_ctx
, void *timeout_ctx
);
41 static int wpas_dpp_auth_init_next(struct wpa_supplicant
*wpa_s
);
43 wpas_dpp_tx_pkex_status(struct wpa_supplicant
*wpa_s
,
44 unsigned int freq
, const u8
*dst
,
45 const u8
*src
, const u8
*bssid
,
46 const u8
*data
, size_t data_len
,
47 enum offchannel_send_action_result result
);
49 static const u8 broadcast
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
51 /* Use a hardcoded Transaction ID 1 in Peer Discovery frames since there is only
52 * a single transaction in progress at any point in time. */
53 static const u8 TRANSACTION_ID
= 1;
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
62 int wpas_dpp_qr_code(struct wpa_supplicant
*wpa_s
, const char *cmd
)
64 struct dpp_bootstrap_info
*bi
;
65 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
67 bi
= dpp_add_qr_code(wpa_s
->dpp
, cmd
);
71 if (auth
&& auth
->response_pending
&&
72 dpp_notify_new_qr_code(auth
, bi
) == 1) {
74 "DPP: Sending out pending authentication response");
75 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
77 MAC2STR(auth
->peer_mac_addr
), auth
->curr_freq
,
78 DPP_PA_AUTHENTICATION_RESP
);
79 offchannel_send_action(wpa_s
, auth
->curr_freq
,
80 auth
->peer_mac_addr
, wpa_s
->own_addr
,
82 wpabuf_head(auth
->resp_msg
),
83 wpabuf_len(auth
->resp_msg
),
84 500, wpas_dpp_tx_status
, 0);
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
97 int wpas_dpp_nfc_uri(struct wpa_supplicant
*wpa_s
, const char *cmd
)
99 struct dpp_bootstrap_info
*bi
;
101 bi
= dpp_add_nfc_uri(wpa_s
->dpp
, cmd
);
109 int wpas_dpp_nfc_handover_req(struct wpa_supplicant
*wpa_s
, const char *cmd
)
112 struct dpp_bootstrap_info
*peer_bi
, *own_bi
;
114 pos
= os_strstr(cmd
, " own=");
118 own_bi
= dpp_bootstrap_get_id(wpa_s
->dpp
, atoi(pos
));
122 pos
= os_strstr(cmd
, " uri=");
126 peer_bi
= dpp_add_nfc_uri(wpa_s
->dpp
, pos
);
129 "DPP: Failed to parse URI from NFC Handover Request");
133 if (dpp_nfc_update_bi(own_bi
, peer_bi
) < 0)
140 int wpas_dpp_nfc_handover_sel(struct wpa_supplicant
*wpa_s
, const char *cmd
)
143 struct dpp_bootstrap_info
*peer_bi
, *own_bi
;
145 pos
= os_strstr(cmd
, " own=");
149 own_bi
= dpp_bootstrap_get_id(wpa_s
->dpp
, atoi(pos
));
153 pos
= os_strstr(cmd
, " uri=");
157 peer_bi
= dpp_add_nfc_uri(wpa_s
->dpp
, pos
);
160 "DPP: Failed to parse URI from NFC Handover Select");
164 if (peer_bi
->curve
!= own_bi
->curve
) {
166 "DPP: Peer (NFC Handover Selector) used different curve");
174 static void wpas_dpp_auth_resp_retry_timeout(void *eloop_ctx
, void *timeout_ctx
)
176 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
177 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
179 if (!auth
|| !auth
->resp_msg
)
182 wpa_printf(MSG_DEBUG
,
183 "DPP: Retry Authentication Response after timeout");
184 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
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);
196 static void wpas_dpp_auth_resp_retry(struct wpa_supplicant
*wpa_s
)
198 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
199 unsigned int wait_time
, max_tries
;
201 if (!auth
|| !auth
->resp_msg
)
204 if (wpa_s
->dpp_resp_max_tries
)
205 max_tries
= wpa_s
->dpp_resp_max_tries
;
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
;
217 if (wpa_s
->dpp_resp_retry_time
)
218 wait_time
= wpa_s
->dpp_resp_retry_time
;
221 wpa_printf(MSG_DEBUG
,
222 "DPP: Schedule retransmission of Authentication Response frame in %u ms",
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
);
231 static void wpas_dpp_try_to_connect(struct wpa_supplicant
*wpa_s
)
233 wpa_printf(MSG_DEBUG
, "DPP: Trying to connect to the new network");
234 wpa_s
->suitable_network
= 0;
235 wpa_s
->no_suitable_network
= 0;
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);
247 static void wpas_dpp_conn_status_result_timeout(void *eloop_ctx
,
250 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
251 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
252 enum dpp_status_error result
;
254 if (!auth
|| !auth
->conn_status_requested
)
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
;
264 result
= 255; /* What to report here for unexpected state? */
265 if (wpa_s
->wpa_state
== WPA_SCANNING
)
266 wpas_abort_ongoing_scan(wpa_s
);
267 wpas_dpp_send_conn_status_result(wpa_s
, result
);
271 static char * wpas_dpp_scan_channel_list(struct wpa_supplicant
*wpa_s
)
273 char *str
, *end
, *pos
;
276 u8 last_op_class
= 0;
279 if (!wpa_s
->last_scan_freqs
|| !wpa_s
->num_last_scan_freqs
)
282 len
= wpa_s
->num_last_scan_freqs
* 8;
283 str
= os_zalloc(len
);
289 for (i
= 0; i
< wpa_s
->num_last_scan_freqs
; i
++) {
290 enum hostapd_hw_mode mode
;
291 u8 op_class
, channel
;
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
)
297 if (op_class
== last_op_class
)
298 res
= os_snprintf(pos
, end
- pos
, ",%d", channel
);
300 res
= os_snprintf(pos
, end
- pos
, "%s%d/%d",
301 pos
== str
? "" : ",",
303 if (os_snprintf_error(end
- pos
, res
)) {
308 last_op_class
= op_class
;
319 void wpas_dpp_send_conn_status_result(struct wpa_supplicant
*wpa_s
,
320 enum dpp_status_error result
)
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
;
328 eloop_cancel_timeout(wpas_dpp_conn_status_result_timeout
, wpa_s
, NULL
);
330 if (!auth
|| !auth
->conn_status_requested
)
332 auth
->conn_status_requested
= 0;
333 wpa_printf(MSG_DEBUG
, "DPP: Report connection status result %d",
336 if (result
== DPP_STATUS_NO_AP
) {
337 channel_list_buf
= wpas_dpp_scan_channel_list(wpa_s
);
338 channel_list
= channel_list_buf
;
341 msg
= dpp_build_conn_status_result(auth
, result
,
343 wpa_s
->dpp_last_ssid
,
344 ssid
? ssid
->ssid_len
:
345 wpa_s
->dpp_last_ssid_len
,
347 os_free(channel_list_buf
);
349 dpp_auth_deinit(wpa_s
->dpp_auth
);
350 wpa_s
->dpp_auth
= NULL
;
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);
364 /* This exchange will be terminated in the TX status handler */
365 auth
->remove_on_tx_status
= 1;
371 void wpas_dpp_connected(struct wpa_supplicant
*wpa_s
)
373 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
375 if (auth
&& auth
->conn_status_requested
)
376 wpas_dpp_send_conn_status_result(wpa_s
, DPP_STATUS_OK
);
379 #endif /* CONFIG_DPP2 */
382 static 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
)
389 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
391 res_txt
= result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
392 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
394 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
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
);
399 if (!wpa_s
->dpp_auth
) {
400 wpa_printf(MSG_DEBUG
,
401 "DPP: Ignore TX status since there is no ongoing authentication exchange");
406 if (auth
->connect_on_tx_status
) {
407 auth
->connect_on_tx_status
= 0;
408 wpa_printf(MSG_DEBUG
,
409 "DPP: Try to connect after completed configuration result");
410 wpas_dpp_try_to_connect(wpa_s
);
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
,
417 eloop_register_timeout(
418 15, 0, wpas_dpp_conn_status_result_timeout
,
421 dpp_auth_deinit(wpa_s
->dpp_auth
);
422 wpa_s
->dpp_auth
= NULL
;
426 #endif /* CONFIG_DPP2 */
428 if (wpa_s
->dpp_auth
->remove_on_tx_status
) {
429 wpa_printf(MSG_DEBUG
,
430 "DPP: Terminate authentication exchange due to a request to do so on TX status");
431 eloop_cancel_timeout(wpas_dpp_init_timeout
, wpa_s
, NULL
);
432 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
433 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout
, wpa_s
,
435 offchannel_send_action_done(wpa_s
);
436 dpp_auth_deinit(wpa_s
->dpp_auth
);
437 wpa_s
->dpp_auth
= NULL
;
441 if (wpa_s
->dpp_auth_ok_on_ack
)
442 wpas_dpp_auth_success(wpa_s
, 1);
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");
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
);
455 if (auth
->waiting_auth_conf
) {
456 wpas_dpp_auth_resp_retry(wpa_s
);
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;
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
);
478 if (wpa_s
->dpp_auth_ok_on_ack
)
479 wpa_s
->dpp_auth_ok_on_ack
= 0;
483 static void wpas_dpp_reply_wait_timeout(void *eloop_ctx
, void *timeout_ctx
)
485 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
486 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
488 struct os_reltime now
, diff
;
489 unsigned int wait_time
, diff_ms
;
491 if (!auth
|| !auth
->waiting_auth_resp
)
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",
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. */
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
);
510 wpas_dpp_listen_stop(wpa_s
);
511 dpp_auth_deinit(auth
);
512 wpa_s
->dpp_auth
= NULL
;
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
);
527 /* Driver did not support 2000 ms long wait_time with TX command, so
528 * schedule listen operation to continue waiting for the response.
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
;
535 freq
= auth
->curr_freq
;
536 if (auth
->neg_freq
> 0)
537 freq
= auth
->neg_freq
;
538 wpa_printf(MSG_DEBUG
,
539 "DPP: Continue reply wait on channel %u MHz for %u ms",
541 wpa_s
->dpp_in_response_listen
= 1;
542 wpas_dpp_listen_start(wpa_s
, freq
);
544 eloop_register_timeout(wait_time
/ 1000, (wait_time
% 1000) * 1000,
545 wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
549 static void wpas_dpp_set_testing_options(struct wpa_supplicant
*wpa_s
,
550 struct dpp_authentication
*auth
)
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
);
562 auth
->ignore_netaccesskey_mismatch
=
563 wpa_s
->dpp_ignore_netaccesskey_mismatch
;
564 #endif /* CONFIG_TESTING_OPTIONS */
568 static void wpas_dpp_init_timeout(void *eloop_ctx
, void *timeout_ctx
)
570 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
572 if (!wpa_s
->dpp_auth
)
574 wpa_printf(MSG_DEBUG
, "DPP: Retry initiation after timeout");
575 wpas_dpp_auth_init_next(wpa_s
);
579 static int wpas_dpp_auth_init_next(struct wpa_supplicant
*wpa_s
)
581 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
583 unsigned int wait_time
, max_wait_time
, freq
, max_tries
, used
;
584 struct os_reltime now
, diff
;
586 wpa_s
->dpp_in_response_listen
= 0;
590 if (auth
->freq_idx
== 0)
591 os_get_reltime(&wpa_s
->dpp_init_iter_start
);
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
;
599 if (auth
->num_freq_iters
>= max_tries
|| auth
->auth_req_ack
) {
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
,
605 offchannel_send_action_done(wpa_s
);
606 dpp_auth_deinit(wpa_s
->dpp_auth
);
607 wpa_s
->dpp_auth
= NULL
;
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
;
616 os_get_reltime(&now
);
617 os_reltime_sub(&now
, &wpa_s
->dpp_init_iter_start
, &diff
);
618 used
= diff
.sec
* 1000 + diff
.usec
/ 1000;
619 if (used
> wait_time
)
623 wpa_printf(MSG_DEBUG
, "DPP: Next init attempt in %u ms",
625 eloop_register_timeout(wait_time
/ 1000,
626 (wait_time
% 1000) * 1000,
627 wpas_dpp_init_timeout
, wpa_s
,
631 freq
= auth
->freq
[auth
->freq_idx
++];
632 auth
->curr_freq
= freq
;
634 if (is_zero_ether_addr(auth
->peer_bi
->mac_addr
))
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
;
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 */
646 eloop_register_timeout(wait_time
/ 1000, (wait_time
% 1000) * 1000,
647 wpas_dpp_reply_wait_timeout
,
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
);
655 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
656 MAC2STR(dst
), freq
, DPP_PA_AUTHENTICATION_REQ
);
657 auth
->auth_req_ack
= 0;
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);
667 int wpas_dpp_auth_init(struct wpa_supplicant
*wpa_s
, const char *cmd
)
670 struct dpp_bootstrap_info
*peer_bi
, *own_bi
= NULL
;
671 struct dpp_authentication
*auth
;
672 u8 allowed_roles
= DPP_CAPAB_CONFIGURATOR
;
673 unsigned int neg_freq
= 0;
676 int tcp_port
= DPP_TCP_PORT
;
677 struct hostapd_ip_addr ipaddr
;
679 #endif /* CONFIG_DPP2 */
681 wpa_s
->dpp_gas_client
= 0;
683 pos
= os_strstr(cmd
, " peer=");
687 peer_bi
= dpp_bootstrap_get_id(wpa_s
->dpp
, atoi(pos
));
690 "DPP: Could not find bootstrapping info for the identified peer");
695 pos
= os_strstr(cmd
, " tcp_port=");
698 tcp_port
= atoi(pos
);
701 addr
= get_param(cmd
, " tcp_addr=");
705 res
= hostapd_parse_ip_addr(addr
, &ipaddr
);
711 #endif /* CONFIG_DPP2 */
713 pos
= os_strstr(cmd
, " own=");
716 own_bi
= dpp_bootstrap_get_id(wpa_s
->dpp
, atoi(pos
));
719 "DPP: Could not find bootstrapping info for the identified local entry");
723 if (peer_bi
->curve
!= own_bi
->curve
) {
725 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
726 peer_bi
->curve
->name
, own_bi
->curve
->name
);
731 pos
= os_strstr(cmd
, " role=");
734 if (os_strncmp(pos
, "configurator", 12) == 0)
735 allowed_roles
= DPP_CAPAB_CONFIGURATOR
;
736 else if (os_strncmp(pos
, "enrollee", 8) == 0)
737 allowed_roles
= DPP_CAPAB_ENROLLEE
;
738 else if (os_strncmp(pos
, "either", 6) == 0)
739 allowed_roles
= DPP_CAPAB_CONFIGURATOR
|
745 pos
= os_strstr(cmd
, " netrole=");
748 if (os_strncmp(pos
, "ap", 2) == 0)
749 wpa_s
->dpp_netrole
= DPP_NETROLE_AP
;
750 else if (os_strncmp(pos
, "configurator", 12) == 0)
751 wpa_s
->dpp_netrole
= DPP_NETROLE_CONFIGURATOR
;
753 wpa_s
->dpp_netrole
= DPP_NETROLE_STA
;
755 wpa_s
->dpp_netrole
= DPP_NETROLE_STA
;
758 pos
= os_strstr(cmd
, " neg_freq=");
760 neg_freq
= atoi(pos
+ 10);
762 if (!tcp
&& wpa_s
->dpp_auth
) {
763 eloop_cancel_timeout(wpas_dpp_init_timeout
, wpa_s
, NULL
);
764 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
765 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout
, wpa_s
,
767 offchannel_send_action_done(wpa_s
);
768 dpp_auth_deinit(wpa_s
->dpp_auth
);
769 wpa_s
->dpp_auth
= NULL
;
772 auth
= dpp_auth_init(wpa_s
->dpp
, wpa_s
, peer_bi
, own_bi
, allowed_roles
,
773 neg_freq
, wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
);
776 wpas_dpp_set_testing_options(wpa_s
, auth
);
777 if (dpp_set_configurator(auth
, cmd
) < 0) {
778 dpp_auth_deinit(auth
);
782 auth
->neg_freq
= neg_freq
;
784 if (!is_zero_ether_addr(peer_bi
->mac_addr
))
785 os_memcpy(auth
->peer_mac_addr
, peer_bi
->mac_addr
, ETH_ALEN
);
789 return dpp_tcp_init(wpa_s
->dpp
, auth
, &ipaddr
, tcp_port
);
790 #endif /* CONFIG_DPP2 */
792 wpa_s
->dpp_auth
= auth
;
793 return wpas_dpp_auth_init_next(wpa_s
);
799 struct wpas_dpp_listen_work
{
801 unsigned int duration
;
802 struct wpabuf
*probe_resp_ie
;
806 static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work
*lwork
)
814 static void wpas_dpp_listen_work_done(struct wpa_supplicant
*wpa_s
)
816 struct wpas_dpp_listen_work
*lwork
;
818 if (!wpa_s
->dpp_listen_work
)
821 lwork
= wpa_s
->dpp_listen_work
->ctx
;
822 wpas_dpp_listen_work_free(lwork
);
823 radio_work_done(wpa_s
->dpp_listen_work
);
824 wpa_s
->dpp_listen_work
= NULL
;
828 static void dpp_start_listen_cb(struct wpa_radio_work
*work
, int deinit
)
830 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
831 struct wpas_dpp_listen_work
*lwork
= work
->ctx
;
835 wpa_s
->dpp_listen_work
= NULL
;
836 wpas_dpp_listen_stop(wpa_s
);
838 wpas_dpp_listen_work_free(lwork
);
842 wpa_s
->dpp_listen_work
= work
;
844 wpa_s
->dpp_pending_listen_freq
= lwork
->freq
;
846 if (wpa_drv_remain_on_channel(wpa_s
, lwork
->freq
,
847 wpa_s
->max_remain_on_chan
) < 0) {
848 wpa_printf(MSG_DEBUG
,
849 "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
851 wpa_s
->dpp_listen_freq
= 0;
852 wpas_dpp_listen_work_done(wpa_s
);
853 wpa_s
->dpp_pending_listen_freq
= 0;
856 wpa_s
->off_channel_freq
= 0;
857 wpa_s
->roc_waiting_drv_freq
= lwork
->freq
;
861 static int wpas_dpp_listen_start(struct wpa_supplicant
*wpa_s
,
864 struct wpas_dpp_listen_work
*lwork
;
866 if (wpa_s
->dpp_listen_work
) {
867 wpa_printf(MSG_DEBUG
,
868 "DPP: Reject start_listen since dpp_listen_work already exists");
872 if (wpa_s
->dpp_listen_freq
)
873 wpas_dpp_listen_stop(wpa_s
);
874 wpa_s
->dpp_listen_freq
= freq
;
876 lwork
= os_zalloc(sizeof(*lwork
));
881 if (radio_add_work(wpa_s
, freq
, "dpp-listen", 0, dpp_start_listen_cb
,
883 wpas_dpp_listen_work_free(lwork
);
891 int wpas_dpp_listen(struct wpa_supplicant
*wpa_s
, const char *cmd
)
899 if (os_strstr(cmd
, " role=configurator"))
900 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_CONFIGURATOR
;
901 else if (os_strstr(cmd
, " role=enrollee"))
902 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_ENROLLEE
;
904 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_CONFIGURATOR
|
906 wpa_s
->dpp_qr_mutual
= os_strstr(cmd
, " qr=mutual") != NULL
;
907 if (os_strstr(cmd
, " netrole=ap"))
908 wpa_s
->dpp_netrole
= DPP_NETROLE_AP
;
909 else if (os_strstr(cmd
, " netrole=configurator"))
910 wpa_s
->dpp_netrole
= DPP_NETROLE_CONFIGURATOR
;
912 wpa_s
->dpp_netrole
= DPP_NETROLE_STA
;
913 if (wpa_s
->dpp_listen_freq
== (unsigned int) freq
) {
914 wpa_printf(MSG_DEBUG
, "DPP: Already listening on %u MHz",
919 return wpas_dpp_listen_start(wpa_s
, freq
);
923 void wpas_dpp_listen_stop(struct wpa_supplicant
*wpa_s
)
925 wpa_s
->dpp_in_response_listen
= 0;
926 if (!wpa_s
->dpp_listen_freq
)
929 wpa_printf(MSG_DEBUG
, "DPP: Stop listen on %u MHz",
930 wpa_s
->dpp_listen_freq
);
931 wpa_drv_cancel_remain_on_channel(wpa_s
);
932 wpa_s
->dpp_listen_freq
= 0;
933 wpas_dpp_listen_work_done(wpa_s
);
937 void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
940 wpas_dpp_listen_work_done(wpa_s
);
942 if (wpa_s
->dpp_auth
&& wpa_s
->dpp_in_response_listen
) {
943 unsigned int new_freq
;
945 /* Continue listen with a new remain-on-channel */
946 if (wpa_s
->dpp_auth
->neg_freq
> 0)
947 new_freq
= wpa_s
->dpp_auth
->neg_freq
;
949 new_freq
= wpa_s
->dpp_auth
->curr_freq
;
950 wpa_printf(MSG_DEBUG
,
951 "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
953 wpas_dpp_listen_start(wpa_s
, new_freq
);
957 if (wpa_s
->dpp_listen_freq
) {
958 /* Continue listen with a new remain-on-channel */
959 wpas_dpp_listen_start(wpa_s
, wpa_s
->dpp_listen_freq
);
964 static void wpas_dpp_rx_auth_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
965 const u8
*hdr
, const u8
*buf
, size_t len
,
968 const u8
*r_bootstrap
, *i_bootstrap
;
969 u16 r_bootstrap_len
, i_bootstrap_len
;
970 struct dpp_bootstrap_info
*own_bi
= NULL
, *peer_bi
= NULL
;
975 wpa_printf(MSG_DEBUG
, "DPP: Authentication Request from " MACSTR
,
979 wpas_dpp_chirp_stop(wpa_s
);
980 #endif /* CONFIG_DPP2 */
982 r_bootstrap
= dpp_get_attr(buf
, len
, DPP_ATTR_R_BOOTSTRAP_KEY_HASH
,
984 if (!r_bootstrap
|| r_bootstrap_len
!= SHA256_MAC_LEN
) {
985 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_FAIL
986 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
989 wpa_hexdump(MSG_MSGDUMP
, "DPP: Responder Bootstrapping Key Hash",
990 r_bootstrap
, r_bootstrap_len
);
992 i_bootstrap
= dpp_get_attr(buf
, len
, DPP_ATTR_I_BOOTSTRAP_KEY_HASH
,
994 if (!i_bootstrap
|| i_bootstrap_len
!= SHA256_MAC_LEN
) {
995 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_FAIL
996 "Missing or invalid required Initiator Bootstrapping Key Hash attribute");
999 wpa_hexdump(MSG_MSGDUMP
, "DPP: Initiator Bootstrapping Key Hash",
1000 i_bootstrap
, i_bootstrap_len
);
1002 /* Try to find own and peer bootstrapping key matches based on the
1003 * received hash values */
1004 dpp_bootstrap_find_pair(wpa_s
->dpp
, i_bootstrap
, r_bootstrap
,
1007 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_FAIL
1008 "No matching own bootstrapping key found - ignore message");
1012 if (wpa_s
->dpp_auth
) {
1013 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_FAIL
1014 "Already in DPP authentication exchange - ignore new one");
1018 wpa_s
->dpp_gas_client
= 0;
1019 wpa_s
->dpp_auth_ok_on_ack
= 0;
1020 wpa_s
->dpp_auth
= dpp_auth_req_rx(wpa_s
->dpp
, wpa_s
,
1021 wpa_s
->dpp_allowed_roles
,
1022 wpa_s
->dpp_qr_mutual
,
1023 peer_bi
, own_bi
, freq
, hdr
, buf
, len
);
1024 if (!wpa_s
->dpp_auth
) {
1025 wpa_printf(MSG_DEBUG
, "DPP: No response generated");
1028 wpas_dpp_set_testing_options(wpa_s
, wpa_s
->dpp_auth
);
1029 if (dpp_set_configurator(wpa_s
->dpp_auth
,
1030 wpa_s
->dpp_configurator_params
) < 0) {
1031 dpp_auth_deinit(wpa_s
->dpp_auth
);
1032 wpa_s
->dpp_auth
= NULL
;
1035 os_memcpy(wpa_s
->dpp_auth
->peer_mac_addr
, src
, ETH_ALEN
);
1037 if (wpa_s
->dpp_listen_freq
&&
1038 wpa_s
->dpp_listen_freq
!= wpa_s
->dpp_auth
->curr_freq
) {
1039 wpa_printf(MSG_DEBUG
,
1040 "DPP: Stop listen on %u MHz to allow response on the request %u MHz",
1041 wpa_s
->dpp_listen_freq
, wpa_s
->dpp_auth
->curr_freq
);
1042 wpas_dpp_listen_stop(wpa_s
);
1045 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
1046 MAC2STR(src
), wpa_s
->dpp_auth
->curr_freq
,
1047 DPP_PA_AUTHENTICATION_RESP
);
1048 offchannel_send_action(wpa_s
, wpa_s
->dpp_auth
->curr_freq
,
1049 src
, wpa_s
->own_addr
, broadcast
,
1050 wpabuf_head(wpa_s
->dpp_auth
->resp_msg
),
1051 wpabuf_len(wpa_s
->dpp_auth
->resp_msg
),
1052 500, wpas_dpp_tx_status
, 0);
1056 static void wpas_dpp_start_gas_server(struct wpa_supplicant
*wpa_s
)
1058 /* TODO: stop wait and start ROC */
1062 static struct wpa_ssid
* wpas_dpp_add_network(struct wpa_supplicant
*wpa_s
,
1063 struct dpp_authentication
*auth
,
1064 struct dpp_config_obj
*conf
)
1066 struct wpa_ssid
*ssid
;
1069 if (conf
->akm
== DPP_AKM_SAE
) {
1071 struct wpa_driver_capa capa
;
1074 res
= wpa_drv_get_capa(wpa_s
, &capa
);
1076 !(capa
.key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SAE
) &&
1077 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
)) {
1078 wpa_printf(MSG_DEBUG
,
1079 "DPP: SAE not supported by the driver");
1082 #else /* CONFIG_SAE */
1083 wpa_printf(MSG_DEBUG
, "DPP: SAE not supported in the build");
1085 #endif /* CONFIG_SAE */
1087 #endif /* CONFIG_DPP2 */
1089 ssid
= wpa_config_add_network(wpa_s
->conf
);
1092 wpas_notify_network_added(wpa_s
, ssid
);
1093 wpa_config_set_network_defaults(ssid
);
1096 ssid
->ssid
= os_malloc(conf
->ssid_len
);
1099 os_memcpy(ssid
->ssid
, conf
->ssid
, conf
->ssid_len
);
1100 ssid
->ssid_len
= conf
->ssid_len
;
1102 if (conf
->connector
) {
1103 ssid
->key_mgmt
= WPA_KEY_MGMT_DPP
;
1104 ssid
->ieee80211w
= MGMT_FRAME_PROTECTION_REQUIRED
;
1105 ssid
->dpp_connector
= os_strdup(conf
->connector
);
1106 if (!ssid
->dpp_connector
)
1110 if (conf
->c_sign_key
) {
1111 ssid
->dpp_csign
= os_malloc(wpabuf_len(conf
->c_sign_key
));
1112 if (!ssid
->dpp_csign
)
1114 os_memcpy(ssid
->dpp_csign
, wpabuf_head(conf
->c_sign_key
),
1115 wpabuf_len(conf
->c_sign_key
));
1116 ssid
->dpp_csign_len
= wpabuf_len(conf
->c_sign_key
);
1119 if (auth
->net_access_key
) {
1120 ssid
->dpp_netaccesskey
=
1121 os_malloc(wpabuf_len(auth
->net_access_key
));
1122 if (!ssid
->dpp_netaccesskey
)
1124 os_memcpy(ssid
->dpp_netaccesskey
,
1125 wpabuf_head(auth
->net_access_key
),
1126 wpabuf_len(auth
->net_access_key
));
1127 ssid
->dpp_netaccesskey_len
= wpabuf_len(auth
->net_access_key
);
1128 ssid
->dpp_netaccesskey_expiry
= auth
->net_access_key_expiry
;
1131 if (!conf
->connector
|| dpp_akm_psk(conf
->akm
) ||
1132 dpp_akm_sae(conf
->akm
)) {
1133 if (!conf
->connector
)
1135 if (dpp_akm_psk(conf
->akm
))
1136 ssid
->key_mgmt
|= WPA_KEY_MGMT_PSK
|
1137 WPA_KEY_MGMT_PSK_SHA256
| WPA_KEY_MGMT_FT_PSK
;
1138 if (dpp_akm_sae(conf
->akm
))
1139 ssid
->key_mgmt
|= WPA_KEY_MGMT_SAE
|
1140 WPA_KEY_MGMT_FT_SAE
;
1141 ssid
->ieee80211w
= MGMT_FRAME_PROTECTION_OPTIONAL
;
1142 if (conf
->passphrase
[0]) {
1143 if (wpa_config_set_quoted(ssid
, "psk",
1144 conf
->passphrase
) < 0)
1146 wpa_config_update_psk(ssid
);
1147 ssid
->export_keys
= 1;
1149 ssid
->psk_set
= conf
->psk_set
;
1150 os_memcpy(ssid
->psk
, conf
->psk
, PMK_LEN
);
1154 os_memcpy(wpa_s
->dpp_last_ssid
, conf
->ssid
, conf
->ssid_len
);
1155 wpa_s
->dpp_last_ssid_len
= conf
->ssid_len
;
1159 wpas_notify_network_removed(wpa_s
, ssid
);
1160 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
1165 static int wpas_dpp_process_config(struct wpa_supplicant
*wpa_s
,
1166 struct dpp_authentication
*auth
,
1167 struct dpp_config_obj
*conf
)
1169 struct wpa_ssid
*ssid
;
1171 if (wpa_s
->conf
->dpp_config_processing
< 1)
1174 ssid
= wpas_dpp_add_network(wpa_s
, auth
, conf
);
1178 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_NETWORK_ID
"%d", ssid
->id
);
1179 if (wpa_s
->conf
->dpp_config_processing
== 2)
1182 #ifndef CONFIG_NO_CONFIG_WRITE
1183 if (wpa_s
->conf
->update_config
&&
1184 wpa_config_write(wpa_s
->confname
, wpa_s
->conf
))
1185 wpa_printf(MSG_DEBUG
, "DPP: Failed to update configuration");
1186 #endif /* CONFIG_NO_CONFIG_WRITE */
1192 static void wpas_dpp_post_process_config(struct wpa_supplicant
*wpa_s
,
1193 struct dpp_authentication
*auth
)
1195 if (wpa_s
->conf
->dpp_config_processing
< 2)
1199 if (auth
->peer_version
>= 2) {
1200 wpa_printf(MSG_DEBUG
,
1201 "DPP: Postpone connection attempt to wait for completion of DPP Configuration Result");
1202 auth
->connect_on_tx_status
= 1;
1205 #endif /* CONFIG_DPP2 */
1207 wpas_dpp_try_to_connect(wpa_s
);
1211 static int wpas_dpp_handle_config_obj(struct wpa_supplicant
*wpa_s
,
1212 struct dpp_authentication
*auth
,
1213 struct dpp_config_obj
*conf
)
1215 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_RECEIVED
);
1217 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONFOBJ_SSID
"%s",
1218 wpa_ssid_txt(conf
->ssid
, conf
->ssid_len
));
1219 if (conf
->ssid_charset
)
1220 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONFOBJ_SSID_CHARSET
"%d",
1221 conf
->ssid_charset
);
1222 if (conf
->connector
) {
1223 /* TODO: Save the Connector and consider using a command
1224 * to fetch the value instead of sending an event with
1225 * it. The Connector could end up being larger than what
1226 * most clients are ready to receive as an event
1228 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONNECTOR
"%s",
1231 if (conf
->c_sign_key
) {
1235 hexlen
= 2 * wpabuf_len(conf
->c_sign_key
) + 1;
1236 hex
= os_malloc(hexlen
);
1238 wpa_snprintf_hex(hex
, hexlen
,
1239 wpabuf_head(conf
->c_sign_key
),
1240 wpabuf_len(conf
->c_sign_key
));
1241 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_C_SIGN_KEY
"%s",
1246 if (auth
->net_access_key
) {
1250 hexlen
= 2 * wpabuf_len(auth
->net_access_key
) + 1;
1251 hex
= os_malloc(hexlen
);
1253 wpa_snprintf_hex(hex
, hexlen
,
1254 wpabuf_head(auth
->net_access_key
),
1255 wpabuf_len(auth
->net_access_key
));
1256 if (auth
->net_access_key_expiry
)
1257 wpa_msg(wpa_s
, MSG_INFO
,
1258 DPP_EVENT_NET_ACCESS_KEY
"%s %lu", hex
,
1260 auth
->net_access_key_expiry
);
1262 wpa_msg(wpa_s
, MSG_INFO
,
1263 DPP_EVENT_NET_ACCESS_KEY
"%s", hex
);
1268 return wpas_dpp_process_config(wpa_s
, auth
, conf
);
1272 static int wpas_dpp_handle_key_pkg(struct wpa_supplicant
*wpa_s
,
1273 struct dpp_asymmetric_key
*key
)
1281 wpa_printf(MSG_DEBUG
, "DPP: Received Configurator backup");
1282 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_RECEIVED
);
1285 res
= dpp_configurator_from_backup(wpa_s
->dpp
, key
);
1288 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONFIGURATOR_ID
"%d",
1292 #endif /* CONFIG_DPP2 */
1298 static void wpas_dpp_gas_resp_cb(void *ctx
, const u8
*addr
, u8 dialog_token
,
1299 enum gas_query_result result
,
1300 const struct wpabuf
*adv_proto
,
1301 const struct wpabuf
*resp
, u16 status_code
)
1303 struct wpa_supplicant
*wpa_s
= ctx
;
1305 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1307 enum dpp_status_error status
= DPP_STATUS_CONFIG_REJECTED
;
1310 wpa_s
->dpp_gas_dialog_token
= -1;
1312 if (!auth
|| !auth
->auth_success
) {
1313 wpa_printf(MSG_DEBUG
, "DPP: No matching exchange in progress");
1316 if (result
!= GAS_QUERY_SUCCESS
||
1317 !resp
|| status_code
!= WLAN_STATUS_SUCCESS
) {
1318 wpa_printf(MSG_DEBUG
, "DPP: GAS query did not succeed");
1322 wpa_hexdump_buf(MSG_DEBUG
, "DPP: Configuration Response adv_proto",
1324 wpa_hexdump_buf(MSG_DEBUG
, "DPP: Configuration Response (GAS response)",
1327 if (wpabuf_len(adv_proto
) != 10 ||
1328 !(pos
= wpabuf_head(adv_proto
)) ||
1329 pos
[0] != WLAN_EID_ADV_PROTO
||
1331 pos
[3] != WLAN_EID_VENDOR_SPECIFIC
||
1333 WPA_GET_BE24(&pos
[5]) != OUI_WFA
||
1336 wpa_printf(MSG_DEBUG
,
1337 "DPP: Not a DPP Advertisement Protocol ID");
1341 if (dpp_conf_resp_rx(auth
, resp
) < 0) {
1342 wpa_printf(MSG_DEBUG
, "DPP: Configuration attempt failed");
1346 for (i
= 0; i
< auth
->num_conf_obj
; i
++) {
1347 res
= wpas_dpp_handle_config_obj(wpa_s
, auth
,
1348 &auth
->conf_obj
[i
]);
1352 if (auth
->num_conf_obj
)
1353 wpas_dpp_post_process_config(wpa_s
, auth
);
1354 if (wpas_dpp_handle_key_pkg(wpa_s
, auth
->conf_key_pkg
) < 0)
1357 status
= DPP_STATUS_OK
;
1358 #ifdef CONFIG_TESTING_OPTIONS
1359 if (dpp_test
== DPP_TEST_REJECT_CONFIG
) {
1360 wpa_printf(MSG_INFO
, "DPP: TESTING - Reject Config Object");
1361 status
= DPP_STATUS_CONFIG_REJECTED
;
1363 #endif /* CONFIG_TESTING_OPTIONS */
1365 if (status
!= DPP_STATUS_OK
)
1366 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1368 if (auth
->peer_version
>= 2 &&
1369 auth
->conf_resp_status
== DPP_STATUS_OK
) {
1372 wpa_printf(MSG_DEBUG
, "DPP: Send DPP Configuration Result");
1373 msg
= dpp_build_conf_result(auth
, status
);
1377 wpa_msg(wpa_s
, MSG_INFO
,
1378 DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
1379 MAC2STR(addr
), auth
->curr_freq
,
1380 DPP_PA_CONFIGURATION_RESULT
);
1381 offchannel_send_action(wpa_s
, auth
->curr_freq
,
1382 addr
, wpa_s
->own_addr
, broadcast
,
1385 500, wpas_dpp_tx_status
, 0);
1388 /* This exchange will be terminated in the TX status handler */
1392 #endif /* CONFIG_DPP2 */
1393 dpp_auth_deinit(wpa_s
->dpp_auth
);
1394 wpa_s
->dpp_auth
= NULL
;
1398 static void wpas_dpp_start_gas_client(struct wpa_supplicant
*wpa_s
)
1400 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1403 int *supp_op_classes
;
1405 wpa_s
->dpp_gas_client
= 1;
1406 offchannel_send_action_done(wpa_s
);
1407 wpas_dpp_listen_stop(wpa_s
);
1409 supp_op_classes
= wpas_supp_op_classes(wpa_s
);
1410 buf
= dpp_build_conf_req_helper(auth
, wpa_s
->conf
->dpp_name
,
1412 wpa_s
->conf
->dpp_mud_url
,
1414 os_free(supp_op_classes
);
1416 wpa_printf(MSG_DEBUG
,
1417 "DPP: No configuration request data available");
1421 wpa_printf(MSG_DEBUG
, "DPP: GAS request to " MACSTR
" (freq %u MHz)",
1422 MAC2STR(auth
->peer_mac_addr
), auth
->curr_freq
);
1424 res
= gas_query_req(wpa_s
->gas
, auth
->peer_mac_addr
, auth
->curr_freq
,
1425 1, buf
, wpas_dpp_gas_resp_cb
, wpa_s
);
1427 wpa_msg(wpa_s
, MSG_DEBUG
, "GAS: Failed to send Query Request");
1430 wpa_printf(MSG_DEBUG
,
1431 "DPP: GAS query started with dialog token %u", res
);
1432 wpa_s
->dpp_gas_dialog_token
= res
;
1437 static void wpas_dpp_auth_success(struct wpa_supplicant
*wpa_s
, int initiator
)
1439 wpa_printf(MSG_DEBUG
, "DPP: Authentication succeeded");
1440 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_AUTH_SUCCESS
"init=%d", initiator
);
1441 #ifdef CONFIG_TESTING_OPTIONS
1442 if (dpp_test
== DPP_TEST_STOP_AT_AUTH_CONF
) {
1443 wpa_printf(MSG_INFO
,
1444 "DPP: TESTING - stop at Authentication Confirm");
1445 if (wpa_s
->dpp_auth
->configurator
) {
1446 /* Prevent GAS response */
1447 wpa_s
->dpp_auth
->auth_success
= 0;
1451 #endif /* CONFIG_TESTING_OPTIONS */
1453 if (wpa_s
->dpp_auth
->configurator
)
1454 wpas_dpp_start_gas_server(wpa_s
);
1456 wpas_dpp_start_gas_client(wpa_s
);
1460 static void wpas_dpp_rx_auth_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1461 const u8
*hdr
, const u8
*buf
, size_t len
,
1464 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1467 wpa_printf(MSG_DEBUG
, "DPP: Authentication Response from " MACSTR
1468 " (freq %u MHz)", MAC2STR(src
), freq
);
1471 wpa_printf(MSG_DEBUG
,
1472 "DPP: No DPP Authentication in progress - drop");
1476 if (!is_zero_ether_addr(auth
->peer_mac_addr
) &&
1477 os_memcmp(src
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1478 wpa_printf(MSG_DEBUG
, "DPP: MAC address mismatch (expected "
1479 MACSTR
") - drop", MAC2STR(auth
->peer_mac_addr
));
1483 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
1485 if (auth
->curr_freq
!= freq
&& auth
->neg_freq
== freq
) {
1486 wpa_printf(MSG_DEBUG
,
1487 "DPP: Responder accepted request for different negotiation channel");
1488 auth
->curr_freq
= freq
;
1491 eloop_cancel_timeout(wpas_dpp_init_timeout
, wpa_s
, NULL
);
1492 msg
= dpp_auth_resp_rx(auth
, hdr
, buf
, len
);
1494 if (auth
->auth_resp_status
== DPP_STATUS_RESPONSE_PENDING
) {
1495 wpa_printf(MSG_DEBUG
,
1496 "DPP: Start wait for full response");
1497 offchannel_send_action_done(wpa_s
);
1498 wpas_dpp_listen_start(wpa_s
, auth
->curr_freq
);
1501 wpa_printf(MSG_DEBUG
, "DPP: No confirm generated");
1504 os_memcpy(auth
->peer_mac_addr
, src
, ETH_ALEN
);
1506 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
1507 MAC2STR(src
), auth
->curr_freq
, DPP_PA_AUTHENTICATION_CONF
);
1508 offchannel_send_action(wpa_s
, auth
->curr_freq
,
1509 src
, wpa_s
->own_addr
, broadcast
,
1510 wpabuf_head(msg
), wpabuf_len(msg
),
1511 500, wpas_dpp_tx_status
, 0);
1513 wpa_s
->dpp_auth_ok_on_ack
= 1;
1517 static void wpas_dpp_rx_auth_conf(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1518 const u8
*hdr
, const u8
*buf
, size_t len
)
1520 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1522 wpa_printf(MSG_DEBUG
, "DPP: Authentication Confirmation from " MACSTR
,
1526 wpa_printf(MSG_DEBUG
,
1527 "DPP: No DPP Authentication in progress - drop");
1531 if (os_memcmp(src
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1532 wpa_printf(MSG_DEBUG
, "DPP: MAC address mismatch (expected "
1533 MACSTR
") - drop", MAC2STR(auth
->peer_mac_addr
));
1537 if (dpp_auth_conf_rx(auth
, hdr
, buf
, len
) < 0) {
1538 wpa_printf(MSG_DEBUG
, "DPP: Authentication failed");
1542 wpas_dpp_auth_success(wpa_s
, 0);
1548 static void wpas_dpp_config_result_wait_timeout(void *eloop_ctx
,
1551 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1552 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1554 if (!auth
|| !auth
->waiting_conf_result
)
1557 wpa_printf(MSG_DEBUG
,
1558 "DPP: Timeout while waiting for Configuration Result");
1559 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1560 dpp_auth_deinit(auth
);
1561 wpa_s
->dpp_auth
= NULL
;
1565 static void wpas_dpp_conn_status_result_wait_timeout(void *eloop_ctx
,
1568 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1569 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1571 if (!auth
|| !auth
->waiting_conn_status_result
)
1574 wpa_printf(MSG_DEBUG
,
1575 "DPP: Timeout while waiting for Connection Status Result");
1576 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONN_STATUS_RESULT
"timeout");
1577 wpas_dpp_listen_stop(wpa_s
);
1578 dpp_auth_deinit(auth
);
1579 wpa_s
->dpp_auth
= NULL
;
1583 static void wpas_dpp_rx_conf_result(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1584 const u8
*hdr
, const u8
*buf
, size_t len
)
1586 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1587 enum dpp_status_error status
;
1589 wpa_printf(MSG_DEBUG
, "DPP: Configuration Result from " MACSTR
,
1592 if (!auth
|| !auth
->waiting_conf_result
) {
1593 wpa_printf(MSG_DEBUG
,
1594 "DPP: No DPP Configuration waiting for result - drop");
1598 if (os_memcmp(src
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1599 wpa_printf(MSG_DEBUG
, "DPP: MAC address mismatch (expected "
1600 MACSTR
") - drop", MAC2STR(auth
->peer_mac_addr
));
1604 status
= dpp_conf_result_rx(auth
, hdr
, buf
, len
);
1606 if (status
== DPP_STATUS_OK
&& auth
->send_conn_status
) {
1607 wpa_msg(wpa_s
, MSG_INFO
,
1608 DPP_EVENT_CONF_SENT
"wait_conn_status=1");
1609 wpa_printf(MSG_DEBUG
, "DPP: Wait for Connection Status Result");
1610 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout
,
1612 auth
->waiting_conn_status_result
= 1;
1613 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout
,
1615 eloop_register_timeout(16, 0,
1616 wpas_dpp_conn_status_result_wait_timeout
,
1618 offchannel_send_action_done(wpa_s
);
1619 wpas_dpp_listen_start(wpa_s
, auth
->neg_freq
? auth
->neg_freq
:
1623 offchannel_send_action_done(wpa_s
);
1624 wpas_dpp_listen_stop(wpa_s
);
1625 if (status
== DPP_STATUS_OK
)
1626 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_SENT
);
1628 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1629 dpp_auth_deinit(auth
);
1630 wpa_s
->dpp_auth
= NULL
;
1631 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout
, wpa_s
, NULL
);
1635 static void wpas_dpp_rx_conn_status_result(struct wpa_supplicant
*wpa_s
,
1636 const u8
*src
, const u8
*hdr
,
1637 const u8
*buf
, size_t len
)
1639 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1640 enum dpp_status_error status
;
1641 u8 ssid
[SSID_MAX_LEN
];
1642 size_t ssid_len
= 0;
1643 char *channel_list
= NULL
;
1645 wpa_printf(MSG_DEBUG
, "DPP: Connection Status Result");
1647 if (!auth
|| !auth
->waiting_conn_status_result
) {
1648 wpa_printf(MSG_DEBUG
,
1649 "DPP: No DPP Configuration waiting for connection status result - drop");
1653 status
= dpp_conn_status_result_rx(auth
, hdr
, buf
, len
,
1654 ssid
, &ssid_len
, &channel_list
);
1655 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONN_STATUS_RESULT
1656 "result=%d ssid=%s channel_list=%s",
1657 status
, wpa_ssid_txt(ssid
, ssid_len
),
1658 channel_list
? channel_list
: "N/A");
1659 os_free(channel_list
);
1660 offchannel_send_action_done(wpa_s
);
1661 wpas_dpp_listen_stop(wpa_s
);
1662 dpp_auth_deinit(auth
);
1663 wpa_s
->dpp_auth
= NULL
;
1664 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout
,
1669 static int wpas_dpp_process_conf_obj(void *ctx
,
1670 struct dpp_authentication
*auth
)
1672 struct wpa_supplicant
*wpa_s
= ctx
;
1676 for (i
= 0; i
< auth
->num_conf_obj
; i
++) {
1677 res
= wpas_dpp_handle_config_obj(wpa_s
, auth
,
1678 &auth
->conf_obj
[i
]);
1683 wpas_dpp_post_process_config(wpa_s
, auth
);
1689 static void wpas_dpp_remove_bi(void *ctx
, struct dpp_bootstrap_info
*bi
)
1691 struct wpa_supplicant
*wpa_s
= ctx
;
1693 if (bi
== wpa_s
->dpp_chirp_bi
)
1694 wpas_dpp_chirp_stop(wpa_s
);
1699 wpas_dpp_rx_presence_announcement(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1700 const u8
*hdr
, const u8
*buf
, size_t len
,
1703 const u8
*r_bootstrap
;
1704 u16 r_bootstrap_len
;
1705 struct dpp_bootstrap_info
*peer_bi
;
1706 struct dpp_authentication
*auth
;
1711 if (wpa_s
->dpp_auth
) {
1712 wpa_printf(MSG_DEBUG
,
1713 "DPP: Ignore Presence Announcement during ongoing Authentication");
1717 wpa_printf(MSG_DEBUG
, "DPP: Presence Announcement from " MACSTR
,
1720 r_bootstrap
= dpp_get_attr(buf
, len
, DPP_ATTR_R_BOOTSTRAP_KEY_HASH
,
1722 if (!r_bootstrap
|| r_bootstrap_len
!= SHA256_MAC_LEN
) {
1723 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_FAIL
1724 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
1727 wpa_hexdump(MSG_MSGDUMP
, "DPP: Responder Bootstrapping Key Hash",
1728 r_bootstrap
, r_bootstrap_len
);
1729 peer_bi
= dpp_bootstrap_find_chirp(wpa_s
->dpp
, r_bootstrap
);
1731 wpa_printf(MSG_DEBUG
,
1732 "DPP: No matching bootstrapping information found");
1736 auth
= dpp_auth_init(wpa_s
->dpp
, wpa_s
, peer_bi
, NULL
,
1737 DPP_CAPAB_CONFIGURATOR
, freq
, NULL
, 0);
1740 wpas_dpp_set_testing_options(wpa_s
, auth
);
1741 if (dpp_set_configurator(auth
, wpa_s
->dpp_configurator_params
) < 0) {
1742 dpp_auth_deinit(auth
);
1746 auth
->neg_freq
= freq
;
1748 if (!is_zero_ether_addr(peer_bi
->mac_addr
))
1749 os_memcpy(auth
->peer_mac_addr
, peer_bi
->mac_addr
, ETH_ALEN
);
1751 wpa_s
->dpp_auth
= auth
;
1752 if (wpas_dpp_auth_init_next(wpa_s
) < 0) {
1753 dpp_auth_deinit(wpa_s
->dpp_auth
);
1754 wpa_s
->dpp_auth
= NULL
;
1758 #endif /* CONFIG_DPP2 */
1761 static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant
*wpa_s
,
1763 const u8
*buf
, size_t len
)
1765 struct wpa_ssid
*ssid
;
1766 const u8
*connector
, *trans_id
, *status
;
1767 u16 connector_len
, trans_id_len
, status_len
;
1768 struct dpp_introduction intro
;
1769 struct rsn_pmksa_cache_entry
*entry
;
1771 struct os_reltime rnow
;
1773 unsigned int seconds
;
1774 enum dpp_status_error res
;
1776 wpa_printf(MSG_DEBUG
, "DPP: Peer Discovery Response from " MACSTR
,
1778 if (is_zero_ether_addr(wpa_s
->dpp_intro_bssid
) ||
1779 os_memcmp(src
, wpa_s
->dpp_intro_bssid
, ETH_ALEN
) != 0) {
1780 wpa_printf(MSG_DEBUG
, "DPP: Not waiting for response from "
1781 MACSTR
" - drop", MAC2STR(src
));
1784 offchannel_send_action_done(wpa_s
);
1786 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1787 if (ssid
== wpa_s
->dpp_intro_network
)
1790 if (!ssid
|| !ssid
->dpp_connector
|| !ssid
->dpp_netaccesskey
||
1792 wpa_printf(MSG_DEBUG
,
1793 "DPP: Profile not found for network introduction");
1797 trans_id
= dpp_get_attr(buf
, len
, DPP_ATTR_TRANSACTION_ID
,
1799 if (!trans_id
|| trans_id_len
!= 1) {
1800 wpa_printf(MSG_DEBUG
,
1801 "DPP: Peer did not include Transaction ID");
1802 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_INTRO
"peer=" MACSTR
1803 " fail=missing_transaction_id", MAC2STR(src
));
1806 if (trans_id
[0] != TRANSACTION_ID
) {
1807 wpa_printf(MSG_DEBUG
,
1808 "DPP: Ignore frame with unexpected Transaction ID %u",
1810 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_INTRO
"peer=" MACSTR
1811 " fail=transaction_id_mismatch", MAC2STR(src
));
1815 status
= dpp_get_attr(buf
, len
, DPP_ATTR_STATUS
, &status_len
);
1816 if (!status
|| status_len
!= 1) {
1817 wpa_printf(MSG_DEBUG
, "DPP: Peer did not include Status");
1818 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_INTRO
"peer=" MACSTR
1819 " fail=missing_status", MAC2STR(src
));
1822 if (status
[0] != DPP_STATUS_OK
) {
1823 wpa_printf(MSG_DEBUG
,
1824 "DPP: Peer rejected network introduction: Status %u",
1826 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_INTRO
"peer=" MACSTR
1827 " status=%u", MAC2STR(src
), status
[0]);
1829 wpas_dpp_send_conn_status_result(wpa_s
, status
[0]);
1830 #endif /* CONFIG_DPP2 */
1834 connector
= dpp_get_attr(buf
, len
, DPP_ATTR_CONNECTOR
, &connector_len
);
1836 wpa_printf(MSG_DEBUG
,
1837 "DPP: Peer did not include its Connector");
1838 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_INTRO
"peer=" MACSTR
1839 " fail=missing_connector", MAC2STR(src
));
1843 res
= dpp_peer_intro(&intro
, ssid
->dpp_connector
,
1844 ssid
->dpp_netaccesskey
,
1845 ssid
->dpp_netaccesskey_len
,
1847 ssid
->dpp_csign_len
,
1848 connector
, connector_len
, &expiry
);
1849 if (res
!= DPP_STATUS_OK
) {
1850 wpa_printf(MSG_INFO
,
1851 "DPP: Network Introduction protocol resulted in failure");
1852 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_INTRO
"peer=" MACSTR
1853 " fail=peer_connector_validation_failed", MAC2STR(src
));
1855 wpas_dpp_send_conn_status_result(wpa_s
, res
);
1856 #endif /* CONFIG_DPP2 */
1860 entry
= os_zalloc(sizeof(*entry
));
1863 os_memcpy(entry
->aa
, src
, ETH_ALEN
);
1864 os_memcpy(entry
->pmkid
, intro
.pmkid
, PMKID_LEN
);
1865 os_memcpy(entry
->pmk
, intro
.pmk
, intro
.pmk_len
);
1866 entry
->pmk_len
= intro
.pmk_len
;
1867 entry
->akmp
= WPA_KEY_MGMT_DPP
;
1870 seconds
= expiry
- now
.sec
;
1872 seconds
= 86400 * 7;
1874 os_get_reltime(&rnow
);
1875 entry
->expiration
= rnow
.sec
+ seconds
;
1876 entry
->reauth_time
= rnow
.sec
+ seconds
;
1877 entry
->network_ctx
= ssid
;
1878 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
1880 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_INTRO
"peer=" MACSTR
1881 " status=%u", MAC2STR(src
), status
[0]);
1883 wpa_printf(MSG_DEBUG
,
1884 "DPP: Try connection again after successful network introduction");
1885 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
1886 wpa_supplicant_cancel_sched_scan(wpa_s
);
1887 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1890 os_memset(&intro
, 0, sizeof(intro
));
1894 static int wpas_dpp_allow_ir(struct wpa_supplicant
*wpa_s
, unsigned int freq
)
1898 if (!wpa_s
->hw
.modes
)
1901 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
1902 struct hostapd_hw_modes
*mode
= &wpa_s
->hw
.modes
[i
];
1904 for (j
= 0; j
< mode
->num_channels
; j
++) {
1905 struct hostapd_channel_data
*chan
= &mode
->channels
[j
];
1907 if (chan
->freq
!= (int) freq
)
1910 if (chan
->flag
& (HOSTAPD_CHAN_DISABLED
|
1911 HOSTAPD_CHAN_NO_IR
|
1912 HOSTAPD_CHAN_RADAR
))
1919 wpa_printf(MSG_DEBUG
,
1920 "DPP: Frequency %u MHz not supported or does not allow PKEX initiation in the current channel list",
1927 static int wpas_dpp_pkex_next_channel(struct wpa_supplicant
*wpa_s
,
1928 struct dpp_pkex
*pkex
)
1930 if (pkex
->freq
== 2437)
1932 else if (pkex
->freq
== 5745)
1934 else if (pkex
->freq
== 5220)
1937 return -1; /* no more channels to try */
1939 if (wpas_dpp_allow_ir(wpa_s
, pkex
->freq
) == 1) {
1940 wpa_printf(MSG_DEBUG
, "DPP: Try to initiate on %u MHz",
1945 /* Could not use this channel - try the next one */
1946 return wpas_dpp_pkex_next_channel(wpa_s
, pkex
);
1950 static void wpas_dpp_pkex_retry_timeout(void *eloop_ctx
, void *timeout_ctx
)
1952 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1953 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1955 if (!pkex
|| !pkex
->exchange_req
)
1957 if (pkex
->exch_req_tries
>= 5) {
1958 if (wpas_dpp_pkex_next_channel(wpa_s
, pkex
) < 0) {
1959 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_FAIL
1960 "No response from PKEX peer");
1961 dpp_pkex_free(pkex
);
1962 wpa_s
->dpp_pkex
= NULL
;
1965 pkex
->exch_req_tries
= 0;
1968 pkex
->exch_req_tries
++;
1969 wpa_printf(MSG_DEBUG
, "DPP: Retransmit PKEX Exchange Request (try %u)",
1970 pkex
->exch_req_tries
);
1971 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
1972 MAC2STR(broadcast
), pkex
->freq
, DPP_PA_PKEX_EXCHANGE_REQ
);
1973 offchannel_send_action(wpa_s
, pkex
->freq
, broadcast
,
1974 wpa_s
->own_addr
, broadcast
,
1975 wpabuf_head(pkex
->exchange_req
),
1976 wpabuf_len(pkex
->exchange_req
),
1977 pkex
->exch_req_wait_time
,
1978 wpas_dpp_tx_pkex_status
, 0);
1983 wpas_dpp_tx_pkex_status(struct wpa_supplicant
*wpa_s
,
1984 unsigned int freq
, const u8
*dst
,
1985 const u8
*src
, const u8
*bssid
,
1986 const u8
*data
, size_t data_len
,
1987 enum offchannel_send_action_result result
)
1989 const char *res_txt
;
1990 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1992 res_txt
= result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
1993 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
1995 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
1996 " result=%s (PKEX)",
1997 freq
, MAC2STR(dst
), res_txt
);
1998 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX_STATUS
"dst=" MACSTR
1999 " freq=%u result=%s", MAC2STR(dst
), freq
, res_txt
);
2002 wpa_printf(MSG_DEBUG
,
2003 "DPP: Ignore TX status since there is no ongoing PKEX exchange");
2008 wpa_printf(MSG_DEBUG
,
2009 "DPP: Terminate PKEX exchange due to an earlier error");
2010 if (pkex
->t
> pkex
->own_bi
->pkex_t
)
2011 pkex
->own_bi
->pkex_t
= pkex
->t
;
2012 dpp_pkex_free(pkex
);
2013 wpa_s
->dpp_pkex
= NULL
;
2017 if (pkex
->exch_req_wait_time
&& pkex
->exchange_req
) {
2018 /* Wait for PKEX Exchange Response frame and retry request if
2019 * no response is seen. */
2020 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout
, wpa_s
, NULL
);
2021 eloop_register_timeout(pkex
->exch_req_wait_time
/ 1000,
2022 (pkex
->exch_req_wait_time
% 1000) * 1000,
2023 wpas_dpp_pkex_retry_timeout
, wpa_s
,
2030 wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
2031 const u8
*buf
, size_t len
, unsigned int freq
)
2034 unsigned int wait_time
;
2036 wpa_printf(MSG_DEBUG
, "DPP: PKEX Exchange Request from " MACSTR
,
2039 /* TODO: Support multiple PKEX codes by iterating over all the enabled
2042 if (!wpa_s
->dpp_pkex_code
|| !wpa_s
->dpp_pkex_bi
) {
2043 wpa_printf(MSG_DEBUG
,
2044 "DPP: No PKEX code configured - ignore request");
2048 if (wpa_s
->dpp_pkex
) {
2049 /* TODO: Support parallel operations */
2050 wpa_printf(MSG_DEBUG
,
2051 "DPP: Already in PKEX session - ignore new request");
2055 wpa_s
->dpp_pkex
= dpp_pkex_rx_exchange_req(wpa_s
, wpa_s
->dpp_pkex_bi
,
2056 wpa_s
->own_addr
, src
,
2057 wpa_s
->dpp_pkex_identifier
,
2058 wpa_s
->dpp_pkex_code
,
2060 if (!wpa_s
->dpp_pkex
) {
2061 wpa_printf(MSG_DEBUG
,
2062 "DPP: Failed to process the request - ignore it");
2066 msg
= wpa_s
->dpp_pkex
->exchange_resp
;
2067 wait_time
= wpa_s
->max_remain_on_chan
;
2068 if (wait_time
> 2000)
2070 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
2071 MAC2STR(src
), freq
, DPP_PA_PKEX_EXCHANGE_RESP
);
2072 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
2074 wpabuf_head(msg
), wpabuf_len(msg
),
2075 wait_time
, wpas_dpp_tx_pkex_status
, 0);
2080 wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
2081 const u8
*buf
, size_t len
, unsigned int freq
)
2084 unsigned int wait_time
;
2086 wpa_printf(MSG_DEBUG
, "DPP: PKEX Exchange Response from " MACSTR
,
2089 /* TODO: Support multiple PKEX codes by iterating over all the enabled
2092 if (!wpa_s
->dpp_pkex
|| !wpa_s
->dpp_pkex
->initiator
||
2093 wpa_s
->dpp_pkex
->exchange_done
) {
2094 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
2098 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout
, wpa_s
, NULL
);
2099 wpa_s
->dpp_pkex
->exch_req_wait_time
= 0;
2101 msg
= dpp_pkex_rx_exchange_resp(wpa_s
->dpp_pkex
, src
, buf
, len
);
2103 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the response");
2107 wpa_printf(MSG_DEBUG
, "DPP: Send PKEX Commit-Reveal Request to " MACSTR
,
2110 wait_time
= wpa_s
->max_remain_on_chan
;
2111 if (wait_time
> 2000)
2113 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
2114 MAC2STR(src
), freq
, DPP_PA_PKEX_COMMIT_REVEAL_REQ
);
2115 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
2117 wpabuf_head(msg
), wpabuf_len(msg
),
2118 wait_time
, wpas_dpp_tx_pkex_status
, 0);
2123 static struct dpp_bootstrap_info
*
2124 wpas_dpp_pkex_finish(struct wpa_supplicant
*wpa_s
, const u8
*peer
,
2127 struct dpp_bootstrap_info
*bi
;
2129 bi
= dpp_pkex_finish(wpa_s
->dpp
, wpa_s
->dpp_pkex
, peer
, freq
);
2132 wpa_s
->dpp_pkex
= NULL
;
2138 wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
2139 const u8
*hdr
, const u8
*buf
, size_t len
,
2143 unsigned int wait_time
;
2144 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
2146 wpa_printf(MSG_DEBUG
, "DPP: PKEX Commit-Reveal Request from " MACSTR
,
2149 if (!pkex
|| pkex
->initiator
|| !pkex
->exchange_done
) {
2150 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
2154 msg
= dpp_pkex_rx_commit_reveal_req(pkex
, hdr
, buf
, len
);
2156 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the request");
2158 wpa_printf(MSG_DEBUG
, "DPP: Terminate PKEX exchange");
2159 if (pkex
->t
> pkex
->own_bi
->pkex_t
)
2160 pkex
->own_bi
->pkex_t
= pkex
->t
;
2161 dpp_pkex_free(wpa_s
->dpp_pkex
);
2162 wpa_s
->dpp_pkex
= NULL
;
2167 wpa_printf(MSG_DEBUG
, "DPP: Send PKEX Commit-Reveal Response to "
2168 MACSTR
, MAC2STR(src
));
2170 wait_time
= wpa_s
->max_remain_on_chan
;
2171 if (wait_time
> 2000)
2173 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
2174 MAC2STR(src
), freq
, DPP_PA_PKEX_COMMIT_REVEAL_RESP
);
2175 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
2177 wpabuf_head(msg
), wpabuf_len(msg
),
2178 wait_time
, wpas_dpp_tx_pkex_status
, 0);
2181 wpas_dpp_pkex_finish(wpa_s
, src
, freq
);
2186 wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
2187 const u8
*hdr
, const u8
*buf
, size_t len
,
2191 struct dpp_bootstrap_info
*bi
;
2192 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
2195 wpa_printf(MSG_DEBUG
, "DPP: PKEX Commit-Reveal Response from " MACSTR
,
2198 if (!pkex
|| !pkex
->initiator
|| !pkex
->exchange_done
) {
2199 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
2203 res
= dpp_pkex_rx_commit_reveal_resp(pkex
, hdr
, buf
, len
);
2205 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the response");
2209 bi
= wpas_dpp_pkex_finish(wpa_s
, src
, freq
);
2213 os_snprintf(cmd
, sizeof(cmd
), " peer=%u %s",
2215 wpa_s
->dpp_pkex_auth_cmd
? wpa_s
->dpp_pkex_auth_cmd
: "");
2216 wpa_printf(MSG_DEBUG
,
2217 "DPP: Start authentication after PKEX with parameters: %s",
2219 if (wpas_dpp_auth_init(wpa_s
, cmd
) < 0) {
2220 wpa_printf(MSG_DEBUG
,
2221 "DPP: Authentication initialization failed");
2222 offchannel_send_action_done(wpa_s
);
2228 void wpas_dpp_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*src
,
2229 const u8
*buf
, size_t len
, unsigned int freq
)
2232 enum dpp_public_action_frame_type type
;
2234 unsigned int pkex_t
;
2236 if (len
< DPP_HDR_LEN
)
2238 if (WPA_GET_BE24(buf
) != OUI_WFA
|| buf
[3] != DPP_OUI_TYPE
)
2243 crypto_suite
= *buf
++;
2247 wpa_printf(MSG_DEBUG
,
2248 "DPP: Received DPP Public Action frame crypto suite %u type %d from "
2250 crypto_suite
, type
, MAC2STR(src
), freq
);
2251 if (crypto_suite
!= 1) {
2252 wpa_printf(MSG_DEBUG
, "DPP: Unsupported crypto suite %u",
2254 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_RX
"src=" MACSTR
2255 " freq=%u type=%d ignore=unsupported-crypto-suite",
2256 MAC2STR(src
), freq
, type
);
2259 wpa_hexdump(MSG_MSGDUMP
, "DPP: Received message attributes", buf
, len
);
2260 if (dpp_check_attrs(buf
, len
) < 0) {
2261 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_RX
"src=" MACSTR
2262 " freq=%u type=%d ignore=invalid-attributes",
2263 MAC2STR(src
), freq
, type
);
2266 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_RX
"src=" MACSTR
" freq=%u type=%d",
2267 MAC2STR(src
), freq
, type
);
2270 case DPP_PA_AUTHENTICATION_REQ
:
2271 wpas_dpp_rx_auth_req(wpa_s
, src
, hdr
, buf
, len
, freq
);
2273 case DPP_PA_AUTHENTICATION_RESP
:
2274 wpas_dpp_rx_auth_resp(wpa_s
, src
, hdr
, buf
, len
, freq
);
2276 case DPP_PA_AUTHENTICATION_CONF
:
2277 wpas_dpp_rx_auth_conf(wpa_s
, src
, hdr
, buf
, len
);
2279 case DPP_PA_PEER_DISCOVERY_RESP
:
2280 wpas_dpp_rx_peer_disc_resp(wpa_s
, src
, buf
, len
);
2282 case DPP_PA_PKEX_EXCHANGE_REQ
:
2283 wpas_dpp_rx_pkex_exchange_req(wpa_s
, src
, buf
, len
, freq
);
2285 case DPP_PA_PKEX_EXCHANGE_RESP
:
2286 wpas_dpp_rx_pkex_exchange_resp(wpa_s
, src
, buf
, len
, freq
);
2288 case DPP_PA_PKEX_COMMIT_REVEAL_REQ
:
2289 wpas_dpp_rx_pkex_commit_reveal_req(wpa_s
, src
, hdr
, buf
, len
,
2292 case DPP_PA_PKEX_COMMIT_REVEAL_RESP
:
2293 wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s
, src
, hdr
, buf
, len
,
2297 case DPP_PA_CONFIGURATION_RESULT
:
2298 wpas_dpp_rx_conf_result(wpa_s
, src
, hdr
, buf
, len
);
2300 case DPP_PA_CONNECTION_STATUS_RESULT
:
2301 wpas_dpp_rx_conn_status_result(wpa_s
, src
, hdr
, buf
, len
);
2303 case DPP_PA_PRESENCE_ANNOUNCEMENT
:
2304 wpas_dpp_rx_presence_announcement(wpa_s
, src
, hdr
, buf
, len
,
2307 #endif /* CONFIG_DPP2 */
2309 wpa_printf(MSG_DEBUG
,
2310 "DPP: Ignored unsupported frame subtype %d", type
);
2314 if (wpa_s
->dpp_pkex
)
2315 pkex_t
= wpa_s
->dpp_pkex
->t
;
2316 else if (wpa_s
->dpp_pkex_bi
)
2317 pkex_t
= wpa_s
->dpp_pkex_bi
->pkex_t
;
2320 if (pkex_t
>= PKEX_COUNTER_T_LIMIT
) {
2321 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_PKEX_T_LIMIT
"id=0");
2322 wpas_dpp_pkex_remove(wpa_s
, "*");
2327 static struct wpabuf
*
2328 wpas_dpp_gas_req_handler(void *ctx
, const u8
*sa
, const u8
*query
,
2331 struct wpa_supplicant
*wpa_s
= ctx
;
2332 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
2333 struct wpabuf
*resp
;
2335 wpa_printf(MSG_DEBUG
, "DPP: GAS request from " MACSTR
,
2337 if (!auth
|| !auth
->auth_success
||
2338 os_memcmp(sa
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
2339 wpa_printf(MSG_DEBUG
, "DPP: No matching exchange in progress");
2343 if (wpa_s
->dpp_auth_ok_on_ack
&& auth
->configurator
) {
2344 wpa_printf(MSG_DEBUG
,
2345 "DPP: Have not received ACK for Auth Confirm yet - assume it was received based on this GAS request");
2346 /* wpas_dpp_auth_success() would normally have been called from
2347 * TX status handler, but since there was no such handler call
2348 * yet, simply send out the event message and proceed with
2350 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_AUTH_SUCCESS
"init=1");
2351 wpa_s
->dpp_auth_ok_on_ack
= 0;
2354 wpa_hexdump(MSG_DEBUG
,
2355 "DPP: Received Configuration Request (GAS Query Request)",
2357 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_REQ_RX
"src=" MACSTR
,
2359 resp
= dpp_conf_req_rx(auth
, query
, query_len
);
2361 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
2362 auth
->conf_resp
= resp
;
2368 wpas_dpp_gas_status_handler(void *ctx
, struct wpabuf
*resp
, int ok
)
2370 struct wpa_supplicant
*wpa_s
= ctx
;
2371 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
2377 if (auth
->conf_resp
!= resp
) {
2378 wpa_printf(MSG_DEBUG
,
2379 "DPP: Ignore GAS status report (ok=%d) for unknown response",
2385 wpa_printf(MSG_DEBUG
, "DPP: Configuration exchange completed (ok=%d)",
2387 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
2388 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout
, wpa_s
, NULL
);
2390 if (ok
&& auth
->peer_version
>= 2 &&
2391 auth
->conf_resp_status
== DPP_STATUS_OK
) {
2392 wpa_printf(MSG_DEBUG
, "DPP: Wait for Configuration Result");
2393 auth
->waiting_conf_result
= 1;
2394 auth
->conf_resp
= NULL
;
2396 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout
,
2398 eloop_register_timeout(2, 0,
2399 wpas_dpp_config_result_wait_timeout
,
2403 #endif /* CONFIG_DPP2 */
2404 offchannel_send_action_done(wpa_s
);
2405 wpas_dpp_listen_stop(wpa_s
);
2407 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_SENT
);
2409 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
2410 dpp_auth_deinit(wpa_s
->dpp_auth
);
2411 wpa_s
->dpp_auth
= NULL
;
2416 int wpas_dpp_configurator_sign(struct wpa_supplicant
*wpa_s
, const char *cmd
)
2418 struct dpp_authentication
*auth
;
2422 auth
= dpp_alloc_auth(wpa_s
->dpp
, wpa_s
);
2426 curve
= get_param(cmd
, " curve=");
2427 wpas_dpp_set_testing_options(wpa_s
, auth
);
2428 if (dpp_set_configurator(auth
, cmd
) == 0 &&
2429 dpp_configurator_own_config(auth
, curve
, 0) == 0)
2430 ret
= wpas_dpp_handle_config_obj(wpa_s
, auth
,
2431 &auth
->conf_obj
[0]);
2433 wpas_dpp_post_process_config(wpa_s
, auth
);
2435 dpp_auth_deinit(auth
);
2443 wpas_dpp_tx_introduction_status(struct wpa_supplicant
*wpa_s
,
2444 unsigned int freq
, const u8
*dst
,
2445 const u8
*src
, const u8
*bssid
,
2446 const u8
*data
, size_t data_len
,
2447 enum offchannel_send_action_result result
)
2449 const char *res_txt
;
2451 res_txt
= result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
2452 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
2454 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
2455 " result=%s (DPP Peer Discovery Request)",
2456 freq
, MAC2STR(dst
), res_txt
);
2457 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX_STATUS
"dst=" MACSTR
2458 " freq=%u result=%s", MAC2STR(dst
), freq
, res_txt
);
2459 /* TODO: Time out wait for response more quickly in error cases? */
2463 int wpas_dpp_check_connect(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
2464 struct wpa_bss
*bss
)
2468 unsigned int wait_time
;
2470 struct wpa_ie_data ied
;
2472 if (!(ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) || !bss
)
2473 return 0; /* Not using DPP AKM - continue */
2474 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2475 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ied
) == 0 &&
2476 !(ied
.key_mgmt
& WPA_KEY_MGMT_DPP
))
2477 return 0; /* AP does not support DPP AKM - continue */
2478 if (wpa_sm_pmksa_exists(wpa_s
->wpa
, bss
->bssid
, ssid
))
2479 return 0; /* PMKSA exists for DPP AKM - continue */
2481 if (!ssid
->dpp_connector
|| !ssid
->dpp_netaccesskey
||
2483 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_MISSING_CONNECTOR
2485 !ssid
->dpp_connector
? "Connector" :
2486 (!ssid
->dpp_netaccesskey
? "netAccessKey" :
2493 if (ssid
->dpp_netaccesskey_expiry
&&
2494 (os_time_t
) ssid
->dpp_netaccesskey_expiry
< now
.sec
) {
2495 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_MISSING_CONNECTOR
2496 "netAccessKey expired");
2500 wpa_printf(MSG_DEBUG
,
2501 "DPP: Starting network introduction protocol to derive PMKSA for "
2502 MACSTR
, MAC2STR(bss
->bssid
));
2504 msg
= dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ
,
2505 5 + 4 + os_strlen(ssid
->dpp_connector
));
2509 #ifdef CONFIG_TESTING_OPTIONS
2510 if (dpp_test
== DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ
) {
2511 wpa_printf(MSG_INFO
, "DPP: TESTING - no Transaction ID");
2514 if (dpp_test
== DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ
) {
2515 wpa_printf(MSG_INFO
, "DPP: TESTING - invalid Transaction ID");
2516 wpabuf_put_le16(msg
, DPP_ATTR_TRANSACTION_ID
);
2517 wpabuf_put_le16(msg
, 0);
2520 #endif /* CONFIG_TESTING_OPTIONS */
2522 /* Transaction ID */
2523 wpabuf_put_le16(msg
, DPP_ATTR_TRANSACTION_ID
);
2524 wpabuf_put_le16(msg
, 1);
2525 wpabuf_put_u8(msg
, TRANSACTION_ID
);
2527 #ifdef CONFIG_TESTING_OPTIONS
2529 if (dpp_test
== DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ
) {
2530 wpa_printf(MSG_INFO
, "DPP: TESTING - no Connector");
2531 goto skip_connector
;
2533 if (dpp_test
== DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ
) {
2536 wpa_printf(MSG_INFO
, "DPP: TESTING - invalid Connector");
2537 connector
= dpp_corrupt_connector_signature(
2538 ssid
->dpp_connector
);
2543 wpabuf_put_le16(msg
, DPP_ATTR_CONNECTOR
);
2544 wpabuf_put_le16(msg
, os_strlen(connector
));
2545 wpabuf_put_str(msg
, connector
);
2547 goto skip_connector
;
2549 #endif /* CONFIG_TESTING_OPTIONS */
2552 wpabuf_put_le16(msg
, DPP_ATTR_CONNECTOR
);
2553 wpabuf_put_le16(msg
, os_strlen(ssid
->dpp_connector
));
2554 wpabuf_put_str(msg
, ssid
->dpp_connector
);
2556 #ifdef CONFIG_TESTING_OPTIONS
2558 #endif /* CONFIG_TESTING_OPTIONS */
2560 /* TODO: Timeout on AP response */
2561 wait_time
= wpa_s
->max_remain_on_chan
;
2562 if (wait_time
> 2000)
2564 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
2565 MAC2STR(bss
->bssid
), bss
->freq
, DPP_PA_PEER_DISCOVERY_REQ
);
2566 offchannel_send_action(wpa_s
, bss
->freq
, bss
->bssid
, wpa_s
->own_addr
,
2568 wpabuf_head(msg
), wpabuf_len(msg
),
2569 wait_time
, wpas_dpp_tx_introduction_status
, 0);
2572 /* Request this connection attempt to terminate - new one will be
2573 * started when network introduction protocol completes */
2574 os_memcpy(wpa_s
->dpp_intro_bssid
, bss
->bssid
, ETH_ALEN
);
2575 wpa_s
->dpp_intro_network
= ssid
;
2580 int wpas_dpp_pkex_add(struct wpa_supplicant
*wpa_s
, const char *cmd
)
2582 struct dpp_bootstrap_info
*own_bi
;
2583 const char *pos
, *end
;
2584 unsigned int wait_time
;
2586 pos
= os_strstr(cmd
, " own=");
2590 own_bi
= dpp_bootstrap_get_id(wpa_s
->dpp
, atoi(pos
));
2592 wpa_printf(MSG_DEBUG
,
2593 "DPP: Identified bootstrap info not found");
2596 if (own_bi
->type
!= DPP_BOOTSTRAP_PKEX
) {
2597 wpa_printf(MSG_DEBUG
,
2598 "DPP: Identified bootstrap info not for PKEX");
2601 wpa_s
->dpp_pkex_bi
= own_bi
;
2602 own_bi
->pkex_t
= 0; /* clear pending errors on new code */
2604 os_free(wpa_s
->dpp_pkex_identifier
);
2605 wpa_s
->dpp_pkex_identifier
= NULL
;
2606 pos
= os_strstr(cmd
, " identifier=");
2609 end
= os_strchr(pos
, ' ');
2612 wpa_s
->dpp_pkex_identifier
= os_malloc(end
- pos
+ 1);
2613 if (!wpa_s
->dpp_pkex_identifier
)
2615 os_memcpy(wpa_s
->dpp_pkex_identifier
, pos
, end
- pos
);
2616 wpa_s
->dpp_pkex_identifier
[end
- pos
] = '\0';
2619 pos
= os_strstr(cmd
, " code=");
2622 os_free(wpa_s
->dpp_pkex_code
);
2623 wpa_s
->dpp_pkex_code
= os_strdup(pos
+ 6);
2624 if (!wpa_s
->dpp_pkex_code
)
2627 if (os_strstr(cmd
, " init=1")) {
2628 struct dpp_pkex
*pkex
;
2631 wpa_printf(MSG_DEBUG
, "DPP: Initiating PKEX");
2632 dpp_pkex_free(wpa_s
->dpp_pkex
);
2633 wpa_s
->dpp_pkex
= dpp_pkex_init(wpa_s
, own_bi
, wpa_s
->own_addr
,
2634 wpa_s
->dpp_pkex_identifier
,
2635 wpa_s
->dpp_pkex_code
);
2636 pkex
= wpa_s
->dpp_pkex
;
2640 msg
= pkex
->exchange_req
;
2641 wait_time
= wpa_s
->max_remain_on_chan
;
2642 if (wait_time
> 2000)
2645 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
2647 MAC2STR(broadcast
), pkex
->freq
,
2648 DPP_PA_PKEX_EXCHANGE_REQ
);
2649 offchannel_send_action(wpa_s
, pkex
->freq
, broadcast
,
2650 wpa_s
->own_addr
, broadcast
,
2651 wpabuf_head(msg
), wpabuf_len(msg
),
2652 wait_time
, wpas_dpp_tx_pkex_status
, 0);
2655 pkex
->exch_req_wait_time
= wait_time
;
2656 pkex
->exch_req_tries
= 1;
2659 /* TODO: Support multiple PKEX info entries */
2661 os_free(wpa_s
->dpp_pkex_auth_cmd
);
2662 wpa_s
->dpp_pkex_auth_cmd
= os_strdup(cmd
);
2668 int wpas_dpp_pkex_remove(struct wpa_supplicant
*wpa_s
, const char *id
)
2670 unsigned int id_val
;
2672 if (os_strcmp(id
, "*") == 0) {
2680 if ((id_val
!= 0 && id_val
!= 1) || !wpa_s
->dpp_pkex_code
)
2683 /* TODO: Support multiple PKEX entries */
2684 os_free(wpa_s
->dpp_pkex_code
);
2685 wpa_s
->dpp_pkex_code
= NULL
;
2686 os_free(wpa_s
->dpp_pkex_identifier
);
2687 wpa_s
->dpp_pkex_identifier
= NULL
;
2688 os_free(wpa_s
->dpp_pkex_auth_cmd
);
2689 wpa_s
->dpp_pkex_auth_cmd
= NULL
;
2690 wpa_s
->dpp_pkex_bi
= NULL
;
2691 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
2692 dpp_pkex_free(wpa_s
->dpp_pkex
);
2693 wpa_s
->dpp_pkex
= NULL
;
2698 void wpas_dpp_stop(struct wpa_supplicant
*wpa_s
)
2700 if (wpa_s
->dpp_auth
|| wpa_s
->dpp_pkex
)
2701 offchannel_send_action_done(wpa_s
);
2702 dpp_auth_deinit(wpa_s
->dpp_auth
);
2703 wpa_s
->dpp_auth
= NULL
;
2704 dpp_pkex_free(wpa_s
->dpp_pkex
);
2705 wpa_s
->dpp_pkex
= NULL
;
2706 if (wpa_s
->dpp_gas_client
&& wpa_s
->dpp_gas_dialog_token
>= 0)
2707 gas_query_stop(wpa_s
->gas
, wpa_s
->dpp_gas_dialog_token
);
2711 int wpas_dpp_init(struct wpa_supplicant
*wpa_s
)
2713 struct dpp_global_config config
;
2716 adv_proto_id
[0] = WLAN_EID_VENDOR_SPECIFIC
;
2717 adv_proto_id
[1] = 5;
2718 WPA_PUT_BE24(&adv_proto_id
[2], OUI_WFA
);
2719 adv_proto_id
[5] = DPP_OUI_TYPE
;
2720 adv_proto_id
[6] = 0x01;
2722 if (gas_server_register(wpa_s
->gas_server
, adv_proto_id
,
2723 sizeof(adv_proto_id
), wpas_dpp_gas_req_handler
,
2724 wpas_dpp_gas_status_handler
, wpa_s
) < 0)
2727 os_memset(&config
, 0, sizeof(config
));
2728 config
.msg_ctx
= wpa_s
;
2729 config
.cb_ctx
= wpa_s
;
2731 config
.process_conf_obj
= wpas_dpp_process_conf_obj
;
2732 config
.remove_bi
= wpas_dpp_remove_bi
;
2733 #endif /* CONFIG_DPP2 */
2734 wpa_s
->dpp
= dpp_global_init(&config
);
2735 return wpa_s
->dpp
? 0 : -1;
2739 void wpas_dpp_deinit(struct wpa_supplicant
*wpa_s
)
2741 #ifdef CONFIG_TESTING_OPTIONS
2742 os_free(wpa_s
->dpp_config_obj_override
);
2743 wpa_s
->dpp_config_obj_override
= NULL
;
2744 os_free(wpa_s
->dpp_discovery_override
);
2745 wpa_s
->dpp_discovery_override
= NULL
;
2746 os_free(wpa_s
->dpp_groups_override
);
2747 wpa_s
->dpp_groups_override
= NULL
;
2748 wpa_s
->dpp_ignore_netaccesskey_mismatch
= 0;
2749 #endif /* CONFIG_TESTING_OPTIONS */
2752 dpp_global_clear(wpa_s
->dpp
);
2753 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout
, wpa_s
, NULL
);
2754 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
2755 eloop_cancel_timeout(wpas_dpp_init_timeout
, wpa_s
, NULL
);
2756 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout
, wpa_s
, NULL
);
2758 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout
, wpa_s
, NULL
);
2759 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout
,
2761 eloop_cancel_timeout(wpas_dpp_conn_status_result_timeout
, wpa_s
, NULL
);
2762 dpp_pfs_free(wpa_s
->dpp_pfs
);
2763 wpa_s
->dpp_pfs
= NULL
;
2764 wpas_dpp_chirp_stop(wpa_s
);
2765 #endif /* CONFIG_DPP2 */
2766 offchannel_send_action_done(wpa_s
);
2767 wpas_dpp_listen_stop(wpa_s
);
2768 wpas_dpp_stop(wpa_s
);
2769 wpas_dpp_pkex_remove(wpa_s
, "*");
2770 os_memset(wpa_s
->dpp_intro_bssid
, 0, ETH_ALEN
);
2771 os_free(wpa_s
->dpp_configurator_params
);
2772 wpa_s
->dpp_configurator_params
= NULL
;
2778 int wpas_dpp_controller_start(struct wpa_supplicant
*wpa_s
, const char *cmd
)
2780 struct dpp_controller_config config
;
2783 os_memset(&config
, 0, sizeof(config
));
2785 pos
= os_strstr(cmd
, " tcp_port=");
2788 config
.tcp_port
= atoi(pos
);
2791 config
.configurator_params
= wpa_s
->dpp_configurator_params
;
2792 return dpp_controller_start(wpa_s
->dpp
, &config
);
2796 static void wpas_dpp_chirp_next(void *eloop_ctx
, void *timeout_ctx
);
2798 static void wpas_dpp_chirp_timeout(void *eloop_ctx
, void *timeout_ctx
)
2800 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2802 wpa_printf(MSG_DEBUG
, "DPP: No chirp response received");
2803 offchannel_send_action_done(wpa_s
);
2804 wpas_dpp_chirp_next(wpa_s
, NULL
);
2808 static void wpas_dpp_chirp_tx_status(struct wpa_supplicant
*wpa_s
,
2809 unsigned int freq
, const u8
*dst
,
2810 const u8
*src
, const u8
*bssid
,
2811 const u8
*data
, size_t data_len
,
2812 enum offchannel_send_action_result result
)
2814 if (result
== OFFCHANNEL_SEND_ACTION_FAILED
) {
2815 wpa_printf(MSG_DEBUG
, "DPP: Failed to send chirp on %d MHz",
2816 wpa_s
->dpp_chirp_freq
);
2817 if (eloop_register_timeout(0, 0, wpas_dpp_chirp_next
,
2819 wpas_dpp_chirp_stop(wpa_s
);
2823 wpa_printf(MSG_DEBUG
, "DPP: Chirp send completed - wait for response");
2824 if (eloop_register_timeout(2, 0, wpas_dpp_chirp_timeout
,
2826 wpas_dpp_chirp_stop(wpa_s
);
2830 static void wpas_dpp_chirp_start(struct wpa_supplicant
*wpa_s
)
2832 wpa_printf(MSG_DEBUG
, "DPP: Chirp on %d MHz", wpa_s
->dpp_chirp_freq
);
2833 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
2834 MAC2STR(broadcast
), wpa_s
->dpp_chirp_freq
,
2835 DPP_PA_PRESENCE_ANNOUNCEMENT
);
2836 if (offchannel_send_action(
2837 wpa_s
, wpa_s
->dpp_chirp_freq
, broadcast
,
2838 wpa_s
->own_addr
, broadcast
,
2839 wpabuf_head(wpa_s
->dpp_presence_announcement
),
2840 wpabuf_len(wpa_s
->dpp_presence_announcement
),
2841 2000, wpas_dpp_chirp_tx_status
, 0) < 0)
2842 wpas_dpp_chirp_stop(wpa_s
);
2846 static void wpas_dpp_chirp_scan_res_handler(struct wpa_supplicant
*wpa_s
,
2847 struct wpa_scan_results
*scan_res
)
2849 struct dpp_bootstrap_info
*bi
= wpa_s
->dpp_chirp_bi
;
2851 struct hostapd_hw_modes
*mode
;
2853 struct wpa_bss
*bss
;
2858 wpa_s
->dpp_chirp_scan_done
= 1;
2860 os_free(wpa_s
->dpp_chirp_freqs
);
2861 wpa_s
->dpp_chirp_freqs
= NULL
;
2863 /* Channels from own bootstrapping info */
2864 for (i
= 0; i
< bi
->num_freq
; i
++)
2865 int_array_add_unique(&wpa_s
->dpp_chirp_freqs
, bi
->freq
[i
]);
2867 /* Preferred chirping channels */
2868 int_array_add_unique(&wpa_s
->dpp_chirp_freqs
, 2437);
2870 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
,
2871 HOSTAPD_MODE_IEEE80211A
, 0);
2873 int chan44
= 0, chan149
= 0;
2875 for (c
= 0; c
< mode
->num_channels
; c
++) {
2876 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
2878 if (chan
->flag
& (HOSTAPD_CHAN_DISABLED
|
2879 HOSTAPD_CHAN_RADAR
))
2881 if (chan
->freq
== 5220)
2883 if (chan
->freq
== 5745)
2887 int_array_add_unique(&wpa_s
->dpp_chirp_freqs
, 5745);
2889 int_array_add_unique(&wpa_s
->dpp_chirp_freqs
, 5220);
2892 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
,
2893 HOSTAPD_MODE_IEEE80211AD
, 0);
2895 for (c
= 0; c
< mode
->num_channels
; c
++) {
2896 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
2898 if ((chan
->flag
& (HOSTAPD_CHAN_DISABLED
|
2899 HOSTAPD_CHAN_RADAR
)) ||
2900 chan
->freq
!= 60480)
2902 int_array_add_unique(&wpa_s
->dpp_chirp_freqs
, 60480);
2907 /* Add channels from scan results for APs that advertise Configurator
2908 * Connectivity element */
2909 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2910 if (wpa_bss_get_vendor_ie(bss
, DPP_CC_IE_VENDOR_TYPE
))
2911 int_array_add_unique(&wpa_s
->dpp_chirp_freqs
,
2915 if (!wpa_s
->dpp_chirp_freqs
||
2916 eloop_register_timeout(0, 0, wpas_dpp_chirp_next
, wpa_s
, NULL
) < 0)
2917 wpas_dpp_chirp_stop(wpa_s
);
2921 static void wpas_dpp_chirp_next(void *eloop_ctx
, void *timeout_ctx
)
2923 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2926 if (wpa_s
->dpp_chirp_listen
)
2927 wpas_dpp_listen_stop(wpa_s
);
2929 if (wpa_s
->dpp_chirp_freq
== 0) {
2930 if (wpa_s
->dpp_chirp_round
% 4 == 0 &&
2931 !wpa_s
->dpp_chirp_scan_done
) {
2932 wpa_printf(MSG_DEBUG
,
2933 "DPP: Update channel list for chirping");
2934 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
2935 wpa_s
->scan_res_handler
=
2936 wpas_dpp_chirp_scan_res_handler
;
2937 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2940 wpa_s
->dpp_chirp_freq
= wpa_s
->dpp_chirp_freqs
[0];
2941 wpa_s
->dpp_chirp_round
++;
2942 wpa_printf(MSG_DEBUG
, "DPP: Start chirping round %d",
2943 wpa_s
->dpp_chirp_round
);
2945 for (i
= 0; wpa_s
->dpp_chirp_freqs
[i
]; i
++)
2946 if (wpa_s
->dpp_chirp_freqs
[i
] == wpa_s
->dpp_chirp_freq
)
2948 if (!wpa_s
->dpp_chirp_freqs
[i
]) {
2949 wpa_printf(MSG_DEBUG
,
2950 "DPP: Previous chirp freq %d not found",
2951 wpa_s
->dpp_chirp_freq
);
2955 if (wpa_s
->dpp_chirp_freqs
[i
]) {
2956 wpa_s
->dpp_chirp_freq
= wpa_s
->dpp_chirp_freqs
[i
];
2958 wpa_s
->dpp_chirp_iter
--;
2959 if (wpa_s
->dpp_chirp_iter
<= 0) {
2960 wpa_printf(MSG_DEBUG
,
2961 "DPP: Chirping iterations completed");
2962 wpas_dpp_chirp_stop(wpa_s
);
2965 wpa_s
->dpp_chirp_freq
= 0;
2966 wpa_s
->dpp_chirp_scan_done
= 0;
2967 if (eloop_register_timeout(30, 0, wpas_dpp_chirp_next
,
2969 wpas_dpp_chirp_stop(wpa_s
);
2972 if (wpa_s
->dpp_chirp_listen
) {
2973 wpa_printf(MSG_DEBUG
,
2974 "DPP: Listen on %d MHz during chirp 30 second wait",
2975 wpa_s
->dpp_chirp_listen
);
2976 wpas_dpp_listen_start(wpa_s
,
2977 wpa_s
->dpp_chirp_listen
);
2979 wpa_printf(MSG_DEBUG
,
2980 "DPP: Wait 30 seconds before starting the next chirping round");
2986 wpas_dpp_chirp_start(wpa_s
);
2990 int wpas_dpp_chirp(struct wpa_supplicant
*wpa_s
, const char *cmd
)
2993 int iter
= 1, listen_freq
= 0;
2994 struct dpp_bootstrap_info
*bi
;
2996 pos
= os_strstr(cmd
, " own=");
3000 bi
= dpp_bootstrap_get_id(wpa_s
->dpp
, atoi(pos
));
3002 wpa_printf(MSG_DEBUG
,
3003 "DPP: Identified bootstrap info not found");
3007 pos
= os_strstr(cmd
, " iter=");
3009 iter
= atoi(pos
+ 6);
3014 pos
= os_strstr(cmd
, " listen=");
3016 listen_freq
= atoi(pos
+ 8);
3021 wpas_dpp_chirp_stop(wpa_s
);
3022 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_ENROLLEE
;
3023 wpa_s
->dpp_chirp_bi
= bi
;
3024 wpa_s
->dpp_presence_announcement
= dpp_build_presence_announcement(bi
);
3025 if (!wpa_s
->dpp_presence_announcement
)
3027 wpa_s
->dpp_chirp_iter
= iter
;
3028 wpa_s
->dpp_chirp_round
= 0;
3029 wpa_s
->dpp_chirp_scan_done
= 0;
3030 wpa_s
->dpp_chirp_listen
= listen_freq
;
3032 return eloop_register_timeout(0, 0, wpas_dpp_chirp_next
, wpa_s
, NULL
);
3036 void wpas_dpp_chirp_stop(struct wpa_supplicant
*wpa_s
)
3038 if (wpa_s
->dpp_presence_announcement
) {
3039 offchannel_send_action_done(wpa_s
);
3040 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CHIRP_STOPPED
);
3042 wpa_s
->dpp_chirp_bi
= NULL
;
3043 wpabuf_free(wpa_s
->dpp_presence_announcement
);
3044 wpa_s
->dpp_presence_announcement
= NULL
;
3045 if (wpa_s
->dpp_chirp_listen
)
3046 wpas_dpp_listen_stop(wpa_s
);
3047 wpa_s
->dpp_chirp_listen
= 0;
3048 wpa_s
->dpp_chirp_freq
= 0;
3049 os_free(wpa_s
->dpp_chirp_freqs
);
3050 wpa_s
->dpp_chirp_freqs
= NULL
;
3051 eloop_cancel_timeout(wpas_dpp_chirp_next
, wpa_s
, NULL
);
3052 eloop_cancel_timeout(wpas_dpp_chirp_timeout
, wpa_s
, NULL
);
3053 if (wpa_s
->scan_res_handler
== wpas_dpp_chirp_scan_res_handler
) {
3054 wpas_abort_ongoing_scan(wpa_s
);
3055 wpa_s
->scan_res_handler
= NULL
;
3059 #endif /* CONFIG_DPP2 */