3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/dpp.h"
14 #include "common/gas.h"
15 #include "common/gas_server.h"
16 #include "rsn_supp/wpa.h"
17 #include "rsn_supp/pmksa_cache.h"
18 #include "wpa_supplicant_i.h"
21 #include "offchannel.h"
22 #include "gas_query.h"
26 #include "dpp_supplicant.h"
29 static int wpas_dpp_listen_start(struct wpa_supplicant
*wpa_s
,
31 static void wpas_dpp_reply_wait_timeout(void *eloop_ctx
, void *timeout_ctx
);
32 static void wpas_dpp_auth_success(struct wpa_supplicant
*wpa_s
, int initiator
);
33 static void wpas_dpp_tx_status(struct wpa_supplicant
*wpa_s
,
34 unsigned int freq
, const u8
*dst
,
35 const u8
*src
, const u8
*bssid
,
36 const u8
*data
, size_t data_len
,
37 enum offchannel_send_action_result result
);
38 static void wpas_dpp_init_timeout(void *eloop_ctx
, void *timeout_ctx
);
39 static int wpas_dpp_auth_init_next(struct wpa_supplicant
*wpa_s
);
41 wpas_dpp_tx_pkex_status(struct wpa_supplicant
*wpa_s
,
42 unsigned int freq
, const u8
*dst
,
43 const u8
*src
, const u8
*bssid
,
44 const u8
*data
, size_t data_len
,
45 enum offchannel_send_action_result result
);
47 static const u8 broadcast
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
49 /* Use a hardcoded Transaction ID 1 in Peer Discovery frames since there is only
50 * a single transaction in progress at any point in time. */
51 static const u8 TRANSACTION_ID
= 1;
54 static struct dpp_configurator
*
55 dpp_configurator_get_id(struct wpa_supplicant
*wpa_s
, unsigned int id
)
57 struct dpp_configurator
*conf
;
59 dl_list_for_each(conf
, &wpa_s
->dpp_configurator
,
60 struct dpp_configurator
, list
) {
68 static unsigned int wpas_dpp_next_id(struct wpa_supplicant
*wpa_s
)
70 struct dpp_bootstrap_info
*bi
;
71 unsigned int max_id
= 0;
73 dl_list_for_each(bi
, &wpa_s
->dpp_bootstrap
, struct dpp_bootstrap_info
,
83 * wpas_dpp_qr_code - Parse and add DPP bootstrapping info from a QR Code
84 * @wpa_s: Pointer to wpa_supplicant data
85 * @cmd: DPP URI read from a QR Code
86 * Returns: Identifier of the stored info or -1 on failure
88 int wpas_dpp_qr_code(struct wpa_supplicant
*wpa_s
, const char *cmd
)
90 struct dpp_bootstrap_info
*bi
;
91 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
93 bi
= dpp_parse_qr_code(cmd
);
97 bi
->id
= wpas_dpp_next_id(wpa_s
);
98 dl_list_add(&wpa_s
->dpp_bootstrap
, &bi
->list
);
100 if (auth
&& auth
->response_pending
&&
101 dpp_notify_new_qr_code(auth
, bi
) == 1) {
102 wpa_printf(MSG_DEBUG
,
103 "DPP: Sending out pending authentication response");
104 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
106 MAC2STR(auth
->peer_mac_addr
), auth
->curr_freq
,
107 DPP_PA_AUTHENTICATION_RESP
);
108 offchannel_send_action(wpa_s
, auth
->curr_freq
,
109 auth
->peer_mac_addr
, wpa_s
->own_addr
,
111 wpabuf_head(auth
->resp_msg
),
112 wpabuf_len(auth
->resp_msg
),
113 500, wpas_dpp_tx_status
, 0);
120 static char * get_param(const char *cmd
, const char *param
)
122 const char *pos
, *end
;
126 pos
= os_strstr(cmd
, param
);
130 pos
+= os_strlen(param
);
131 end
= os_strchr(pos
, ' ');
135 len
= os_strlen(pos
);
136 val
= os_malloc(len
+ 1);
139 os_memcpy(val
, pos
, len
);
145 int wpas_dpp_bootstrap_gen(struct wpa_supplicant
*wpa_s
, const char *cmd
)
147 char *chan
= NULL
, *mac
= NULL
, *info
= NULL
, *pk
= NULL
, *curve
= NULL
;
150 size_t privkey_len
= 0;
153 struct dpp_bootstrap_info
*bi
;
155 bi
= os_zalloc(sizeof(*bi
));
159 if (os_strstr(cmd
, "type=qrcode"))
160 bi
->type
= DPP_BOOTSTRAP_QR_CODE
;
161 else if (os_strstr(cmd
, "type=pkex"))
162 bi
->type
= DPP_BOOTSTRAP_PKEX
;
166 chan
= get_param(cmd
, " chan=");
167 mac
= get_param(cmd
, " mac=");
168 info
= get_param(cmd
, " info=");
169 curve
= get_param(cmd
, " curve=");
170 key
= get_param(cmd
, " key=");
173 privkey_len
= os_strlen(key
) / 2;
174 privkey
= os_malloc(privkey_len
);
176 hexstr2bin(key
, privkey
, privkey_len
) < 0)
180 pk
= dpp_keygen(bi
, curve
, privkey
, privkey_len
);
184 len
= 4; /* "DPP:" */
186 if (dpp_parse_uri_chan_list(bi
, chan
) < 0)
188 len
+= 3 + os_strlen(chan
); /* C:...; */
191 if (dpp_parse_uri_mac(bi
, mac
) < 0)
193 len
+= 3 + os_strlen(mac
); /* M:...; */
196 if (dpp_parse_uri_info(bi
, info
) < 0)
198 len
+= 3 + os_strlen(info
); /* I:...; */
200 len
+= 4 + os_strlen(pk
);
201 bi
->uri
= os_malloc(len
+ 1);
204 os_snprintf(bi
->uri
, len
+ 1, "DPP:%s%s%s%s%s%s%s%s%sK:%s;;",
205 chan
? "C:" : "", chan
? chan
: "", chan
? ";" : "",
206 mac
? "M:" : "", mac
? mac
: "", mac
? ";" : "",
207 info
? "I:" : "", info
? info
: "", info
? ";" : "",
209 bi
->id
= wpas_dpp_next_id(wpa_s
);
210 dl_list_add(&wpa_s
->dpp_bootstrap
, &bi
->list
);
220 bin_clear_free(privkey
, privkey_len
);
221 dpp_bootstrap_info_free(bi
);
226 static struct dpp_bootstrap_info
*
227 dpp_bootstrap_get_id(struct wpa_supplicant
*wpa_s
, unsigned int id
)
229 struct dpp_bootstrap_info
*bi
;
231 dl_list_for_each(bi
, &wpa_s
->dpp_bootstrap
, struct dpp_bootstrap_info
,
240 static int dpp_bootstrap_del(struct wpa_supplicant
*wpa_s
, unsigned int id
)
242 struct dpp_bootstrap_info
*bi
, *tmp
;
245 dl_list_for_each_safe(bi
, tmp
, &wpa_s
->dpp_bootstrap
,
246 struct dpp_bootstrap_info
, list
) {
247 if (id
&& bi
->id
!= id
)
250 dl_list_del(&bi
->list
);
251 dpp_bootstrap_info_free(bi
);
255 return 0; /* flush succeeds regardless of entries found */
256 return found
? 0 : -1;
260 int wpas_dpp_bootstrap_remove(struct wpa_supplicant
*wpa_s
, const char *id
)
264 if (os_strcmp(id
, "*") == 0) {
272 return dpp_bootstrap_del(wpa_s
, id_val
);
276 const char * wpas_dpp_bootstrap_get_uri(struct wpa_supplicant
*wpa_s
,
279 struct dpp_bootstrap_info
*bi
;
281 bi
= dpp_bootstrap_get_id(wpa_s
, id
);
288 int wpas_dpp_bootstrap_info(struct wpa_supplicant
*wpa_s
, int id
,
289 char *reply
, int reply_size
)
291 struct dpp_bootstrap_info
*bi
;
293 bi
= dpp_bootstrap_get_id(wpa_s
, id
);
296 return os_snprintf(reply
, reply_size
, "type=%s\n"
297 "mac_addr=" MACSTR
"\n"
301 dpp_bootstrap_type_txt(bi
->type
),
302 MAC2STR(bi
->mac_addr
),
303 bi
->info
? bi
->info
: "",
309 static void wpas_dpp_auth_resp_retry_timeout(void *eloop_ctx
, void *timeout_ctx
)
311 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
312 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
314 if (!auth
|| !auth
->resp_msg
)
317 wpa_printf(MSG_DEBUG
,
318 "DPP: Retry Authentication Response after timeout");
319 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
321 MAC2STR(auth
->peer_mac_addr
), auth
->curr_freq
,
322 DPP_PA_AUTHENTICATION_RESP
);
323 offchannel_send_action(wpa_s
, auth
->curr_freq
, auth
->peer_mac_addr
,
324 wpa_s
->own_addr
, broadcast
,
325 wpabuf_head(auth
->resp_msg
),
326 wpabuf_len(auth
->resp_msg
),
327 500, wpas_dpp_tx_status
, 0);
331 static void wpas_dpp_auth_resp_retry(struct wpa_supplicant
*wpa_s
)
333 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
334 unsigned int wait_time
, max_tries
;
336 if (!auth
|| !auth
->resp_msg
)
339 if (wpa_s
->dpp_resp_max_tries
)
340 max_tries
= wpa_s
->dpp_resp_max_tries
;
343 auth
->auth_resp_tries
++;
344 if (auth
->auth_resp_tries
>= max_tries
) {
345 wpa_printf(MSG_INFO
, "DPP: No confirm received from initiator - stopping exchange");
346 offchannel_send_action_done(wpa_s
);
347 dpp_auth_deinit(wpa_s
->dpp_auth
);
348 wpa_s
->dpp_auth
= NULL
;
352 if (wpa_s
->dpp_resp_retry_time
)
353 wait_time
= wpa_s
->dpp_resp_retry_time
;
356 wpa_printf(MSG_DEBUG
,
357 "DPP: Schedule retransmission of Authentication Response frame in %u ms",
359 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout
, wpa_s
, NULL
);
360 eloop_register_timeout(wait_time
/ 1000,
361 (wait_time
% 1000) * 1000,
362 wpas_dpp_auth_resp_retry_timeout
, wpa_s
, NULL
);
366 static void wpas_dpp_tx_status(struct wpa_supplicant
*wpa_s
,
367 unsigned int freq
, const u8
*dst
,
368 const u8
*src
, const u8
*bssid
,
369 const u8
*data
, size_t data_len
,
370 enum offchannel_send_action_result result
)
373 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
375 res_txt
= result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
376 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
378 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
379 " result=%s", freq
, MAC2STR(dst
), res_txt
);
380 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX_STATUS
"dst=" MACSTR
381 " freq=%u result=%s", MAC2STR(dst
), freq
, res_txt
);
383 if (!wpa_s
->dpp_auth
) {
384 wpa_printf(MSG_DEBUG
,
385 "DPP: Ignore TX status since there is no ongoing authentication exchange");
389 if (wpa_s
->dpp_auth
->remove_on_tx_status
) {
390 wpa_printf(MSG_DEBUG
,
391 "DPP: Terminate authentication exchange due to an earlier error");
392 eloop_cancel_timeout(wpas_dpp_init_timeout
, wpa_s
, NULL
);
393 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
394 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout
, wpa_s
,
396 offchannel_send_action_done(wpa_s
);
397 dpp_auth_deinit(wpa_s
->dpp_auth
);
398 wpa_s
->dpp_auth
= NULL
;
402 if (wpa_s
->dpp_auth_ok_on_ack
)
403 wpas_dpp_auth_success(wpa_s
, 1);
405 if (!is_broadcast_ether_addr(dst
) &&
406 result
!= OFFCHANNEL_SEND_ACTION_SUCCESS
) {
407 wpa_printf(MSG_DEBUG
,
408 "DPP: Unicast DPP Action frame was not ACKed");
409 if (auth
->waiting_auth_resp
) {
410 /* In case of DPP Authentication Request frame, move to
411 * the next channel immediately. */
412 offchannel_send_action_done(wpa_s
);
413 wpas_dpp_auth_init_next(wpa_s
);
416 if (auth
->waiting_auth_conf
) {
417 wpas_dpp_auth_resp_retry(wpa_s
);
422 if (!wpa_s
->dpp_auth_ok_on_ack
&& wpa_s
->dpp_auth
->neg_freq
> 0 &&
423 wpa_s
->dpp_auth
->curr_freq
!= wpa_s
->dpp_auth
->neg_freq
) {
424 wpa_printf(MSG_DEBUG
,
425 "DPP: Move from curr_freq %u MHz to neg_freq %u MHz for response",
426 wpa_s
->dpp_auth
->curr_freq
,
427 wpa_s
->dpp_auth
->neg_freq
);
428 offchannel_send_action_done(wpa_s
);
429 wpas_dpp_listen_start(wpa_s
, wpa_s
->dpp_auth
->neg_freq
);
434 static void wpas_dpp_reply_wait_timeout(void *eloop_ctx
, void *timeout_ctx
)
436 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
438 struct os_reltime now
;
440 if (!wpa_s
->dpp_auth
)
443 if (wpa_s
->dpp_auth
->waiting_auth_resp
) {
444 unsigned int wait_time
;
446 wait_time
= wpa_s
->dpp_resp_wait_time
?
447 wpa_s
->dpp_resp_wait_time
: 2;
448 os_get_reltime(&now
);
449 if (os_reltime_expired(&now
, &wpa_s
->dpp_last_init
,
451 offchannel_send_action_done(wpa_s
);
452 wpas_dpp_auth_init_next(wpa_s
);
457 freq
= wpa_s
->dpp_auth
->curr_freq
;
458 if (wpa_s
->dpp_auth
->neg_freq
> 0)
459 freq
= wpa_s
->dpp_auth
->neg_freq
;
460 wpa_printf(MSG_DEBUG
, "DPP: Continue reply wait on channel %u MHz",
462 wpas_dpp_listen_start(wpa_s
, freq
);
466 static void wpas_dpp_set_testing_options(struct wpa_supplicant
*wpa_s
,
467 struct dpp_authentication
*auth
)
469 #ifdef CONFIG_TESTING_OPTIONS
470 if (wpa_s
->dpp_config_obj_override
)
471 auth
->config_obj_override
=
472 os_strdup(wpa_s
->dpp_config_obj_override
);
473 if (wpa_s
->dpp_discovery_override
)
474 auth
->discovery_override
=
475 os_strdup(wpa_s
->dpp_discovery_override
);
476 if (wpa_s
->dpp_groups_override
)
477 auth
->groups_override
=
478 os_strdup(wpa_s
->dpp_groups_override
);
479 auth
->ignore_netaccesskey_mismatch
=
480 wpa_s
->dpp_ignore_netaccesskey_mismatch
;
481 #endif /* CONFIG_TESTING_OPTIONS */
485 static void wpas_dpp_set_configurator(struct wpa_supplicant
*wpa_s
,
486 struct dpp_authentication
*auth
,
489 const char *pos
, *end
;
490 struct dpp_configuration
*conf_sta
= NULL
, *conf_ap
= NULL
;
491 struct dpp_configurator
*conf
= NULL
;
492 u8 ssid
[32] = { "test" };
502 wpa_printf(MSG_DEBUG
, "DPP: Set configurator parameters: %s", cmd
);
503 pos
= os_strstr(cmd
, " ssid=");
506 end
= os_strchr(pos
, ' ');
507 ssid_len
= end
? (size_t) (end
- pos
) : os_strlen(pos
);
509 if (ssid_len
> sizeof(ssid
) ||
510 hexstr2bin(pos
, ssid
, ssid_len
) < 0)
514 pos
= os_strstr(cmd
, " pass=");
517 end
= os_strchr(pos
, ' ');
518 pass_len
= end
? (size_t) (end
- pos
) : os_strlen(pos
);
520 if (pass_len
> sizeof(pass
) - 1 || pass_len
< 8 ||
521 hexstr2bin(pos
, (u8
*) pass
, pass_len
) < 0)
525 pos
= os_strstr(cmd
, " psk=");
528 if (hexstr2bin(pos
, psk
, PMK_LEN
) < 0)
533 if (os_strstr(cmd
, " conf=sta-")) {
534 conf_sta
= os_zalloc(sizeof(struct dpp_configuration
));
537 os_memcpy(conf_sta
->ssid
, ssid
, ssid_len
);
538 conf_sta
->ssid_len
= ssid_len
;
539 if (os_strstr(cmd
, " conf=sta-psk")) {
542 os_memcpy(conf_sta
->psk
, psk
, PMK_LEN
);
544 conf_sta
->passphrase
= os_strdup(pass
);
545 if (!conf_sta
->passphrase
)
548 } else if (os_strstr(cmd
, " conf=sta-dpp")) {
555 if (os_strstr(cmd
, " conf=ap-")) {
556 conf_ap
= os_zalloc(sizeof(struct dpp_configuration
));
559 os_memcpy(conf_ap
->ssid
, ssid
, ssid_len
);
560 conf_ap
->ssid_len
= ssid_len
;
561 if (os_strstr(cmd
, " conf=ap-psk")) {
564 os_memcpy(conf_ap
->psk
, psk
, PMK_LEN
);
566 conf_ap
->passphrase
= os_strdup(pass
);
567 if (!conf_ap
->passphrase
)
570 } else if (os_strstr(cmd
, " conf=ap-dpp")) {
577 pos
= os_strstr(cmd
, " expiry=");
582 val
= strtol(pos
, NULL
, 0);
586 conf_sta
->netaccesskey_expiry
= val
;
588 conf_ap
->netaccesskey_expiry
= val
;
591 pos
= os_strstr(cmd
, " configurator=");
594 conf
= dpp_configurator_get_id(wpa_s
, atoi(pos
));
597 "DPP: Could not find the specified configurator");
601 auth
->conf_sta
= conf_sta
;
602 auth
->conf_ap
= conf_ap
;
607 wpa_printf(MSG_DEBUG
, "DPP: Failed to set configurator parameters");
608 dpp_configuration_free(conf_sta
);
609 dpp_configuration_free(conf_ap
);
613 static void wpas_dpp_init_timeout(void *eloop_ctx
, void *timeout_ctx
)
615 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
617 if (!wpa_s
->dpp_auth
)
619 wpa_printf(MSG_DEBUG
, "DPP: Retry initiation after timeout");
620 wpas_dpp_auth_init_next(wpa_s
);
624 static int wpas_dpp_auth_init_next(struct wpa_supplicant
*wpa_s
)
626 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
628 unsigned int wait_time
, freq
, max_tries
;
632 if (auth
->freq_idx
>= auth
->num_freq
) {
633 auth
->num_freq_iters
++;
634 if (wpa_s
->dpp_init_max_tries
)
635 max_tries
= wpa_s
->dpp_init_max_tries
;
638 if (auth
->num_freq_iters
>= max_tries
) {
640 "DPP: No response received from responder - stopping initiation attempt");
641 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_AUTH_INIT_FAILED
);
642 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
,
644 offchannel_send_action_done(wpa_s
);
645 dpp_auth_deinit(wpa_s
->dpp_auth
);
646 wpa_s
->dpp_auth
= NULL
;
650 eloop_cancel_timeout(wpas_dpp_init_timeout
, wpa_s
, NULL
);
651 if (wpa_s
->dpp_init_retry_time
)
652 wait_time
= wpa_s
->dpp_init_retry_time
;
655 eloop_register_timeout(wait_time
/ 1000,
656 (wait_time
% 1000) * 1000,
657 wpas_dpp_init_timeout
, wpa_s
,
661 freq
= auth
->freq
[auth
->freq_idx
++];
662 auth
->curr_freq
= freq
;
664 if (is_zero_ether_addr(auth
->peer_bi
->mac_addr
))
667 dst
= auth
->peer_bi
->mac_addr
;
668 wpa_s
->dpp_auth_ok_on_ack
= 0;
669 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
670 wait_time
= wpa_s
->max_remain_on_chan
;
671 if (wait_time
> 2000)
673 eloop_register_timeout(wait_time
/ 1000, (wait_time
% 1000) * 1000,
674 wpas_dpp_reply_wait_timeout
,
676 if (auth
->neg_freq
> 0 && freq
!= auth
->neg_freq
) {
677 wpa_printf(MSG_DEBUG
,
678 "DPP: Initiate on %u MHz and move to neg_freq %u MHz for response",
679 freq
, auth
->neg_freq
);
681 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
682 MAC2STR(dst
), freq
, DPP_PA_AUTHENTICATION_REQ
);
683 os_get_reltime(&wpa_s
->dpp_last_init
);
684 return offchannel_send_action(wpa_s
, freq
, dst
,
685 wpa_s
->own_addr
, broadcast
,
686 wpabuf_head(auth
->req_msg
),
687 wpabuf_len(auth
->req_msg
),
688 wait_time
, wpas_dpp_tx_status
, 0);
692 int wpas_dpp_auth_init(struct wpa_supplicant
*wpa_s
, const char *cmd
)
695 struct dpp_bootstrap_info
*peer_bi
, *own_bi
= NULL
;
696 u8 allowed_roles
= DPP_CAPAB_CONFIGURATOR
;
697 unsigned int neg_freq
= 0;
699 wpa_s
->dpp_gas_client
= 0;
701 pos
= os_strstr(cmd
, " peer=");
705 peer_bi
= dpp_bootstrap_get_id(wpa_s
, atoi(pos
));
708 "DPP: Could not find bootstrapping info for the identified peer");
712 pos
= os_strstr(cmd
, " own=");
715 own_bi
= dpp_bootstrap_get_id(wpa_s
, atoi(pos
));
718 "DPP: Could not find bootstrapping info for the identified local entry");
722 if (peer_bi
->curve
!= own_bi
->curve
) {
724 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
725 peer_bi
->curve
->name
, own_bi
->curve
->name
);
730 pos
= os_strstr(cmd
, " role=");
733 if (os_strncmp(pos
, "configurator", 12) == 0)
734 allowed_roles
= DPP_CAPAB_CONFIGURATOR
;
735 else if (os_strncmp(pos
, "enrollee", 8) == 0)
736 allowed_roles
= DPP_CAPAB_ENROLLEE
;
737 else if (os_strncmp(pos
, "either", 6) == 0)
738 allowed_roles
= DPP_CAPAB_CONFIGURATOR
|
744 pos
= os_strstr(cmd
, " netrole=");
747 wpa_s
->dpp_netrole_ap
= os_strncmp(pos
, "ap", 2) == 0;
750 pos
= os_strstr(cmd
, " neg_freq=");
752 neg_freq
= atoi(pos
+ 10);
754 if (wpa_s
->dpp_auth
) {
755 eloop_cancel_timeout(wpas_dpp_init_timeout
, wpa_s
, NULL
);
756 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
757 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout
, wpa_s
,
759 offchannel_send_action_done(wpa_s
);
760 dpp_auth_deinit(wpa_s
->dpp_auth
);
762 wpa_s
->dpp_auth
= dpp_auth_init(wpa_s
, peer_bi
, own_bi
, allowed_roles
,
764 wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
);
765 if (!wpa_s
->dpp_auth
)
767 wpas_dpp_set_testing_options(wpa_s
, wpa_s
->dpp_auth
);
768 wpas_dpp_set_configurator(wpa_s
, wpa_s
->dpp_auth
, cmd
);
770 wpa_s
->dpp_auth
->neg_freq
= neg_freq
;
772 if (!is_zero_ether_addr(peer_bi
->mac_addr
))
773 os_memcpy(wpa_s
->dpp_auth
->peer_mac_addr
, peer_bi
->mac_addr
,
776 return wpas_dpp_auth_init_next(wpa_s
);
782 struct wpas_dpp_listen_work
{
784 unsigned int duration
;
785 struct wpabuf
*probe_resp_ie
;
789 static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work
*lwork
)
797 static void wpas_dpp_listen_work_done(struct wpa_supplicant
*wpa_s
)
799 struct wpas_dpp_listen_work
*lwork
;
801 if (!wpa_s
->dpp_listen_work
)
804 lwork
= wpa_s
->dpp_listen_work
->ctx
;
805 wpas_dpp_listen_work_free(lwork
);
806 radio_work_done(wpa_s
->dpp_listen_work
);
807 wpa_s
->dpp_listen_work
= NULL
;
811 static void dpp_start_listen_cb(struct wpa_radio_work
*work
, int deinit
)
813 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
814 struct wpas_dpp_listen_work
*lwork
= work
->ctx
;
818 wpa_s
->dpp_listen_work
= NULL
;
819 wpas_dpp_listen_stop(wpa_s
);
821 wpas_dpp_listen_work_free(lwork
);
825 wpa_s
->dpp_listen_work
= work
;
827 wpa_s
->dpp_pending_listen_freq
= lwork
->freq
;
829 if (wpa_drv_remain_on_channel(wpa_s
, lwork
->freq
,
830 wpa_s
->max_remain_on_chan
) < 0) {
831 wpa_printf(MSG_DEBUG
,
832 "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
834 wpas_dpp_listen_work_done(wpa_s
);
835 wpa_s
->dpp_pending_listen_freq
= 0;
838 wpa_s
->off_channel_freq
= 0;
839 wpa_s
->roc_waiting_drv_freq
= lwork
->freq
;
843 static int wpas_dpp_listen_start(struct wpa_supplicant
*wpa_s
,
846 struct wpas_dpp_listen_work
*lwork
;
848 if (wpa_s
->dpp_listen_work
) {
849 wpa_printf(MSG_DEBUG
,
850 "DPP: Reject start_listen since dpp_listen_work already exists");
854 if (wpa_s
->dpp_listen_freq
)
855 wpas_dpp_listen_stop(wpa_s
);
856 wpa_s
->dpp_listen_freq
= freq
;
858 lwork
= os_zalloc(sizeof(*lwork
));
863 if (radio_add_work(wpa_s
, freq
, "dpp-listen", 0, dpp_start_listen_cb
,
865 wpas_dpp_listen_work_free(lwork
);
873 int wpas_dpp_listen(struct wpa_supplicant
*wpa_s
, const char *cmd
)
881 if (os_strstr(cmd
, " role=configurator"))
882 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_CONFIGURATOR
;
883 else if (os_strstr(cmd
, " role=enrollee"))
884 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_ENROLLEE
;
886 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_CONFIGURATOR
|
888 wpa_s
->dpp_qr_mutual
= os_strstr(cmd
, " qr=mutual") != NULL
;
889 wpa_s
->dpp_netrole_ap
= os_strstr(cmd
, " netrole=ap") != NULL
;
890 if (wpa_s
->dpp_listen_freq
== (unsigned int) freq
) {
891 wpa_printf(MSG_DEBUG
, "DPP: Already listening on %u MHz",
896 return wpas_dpp_listen_start(wpa_s
, freq
);
900 void wpas_dpp_listen_stop(struct wpa_supplicant
*wpa_s
)
902 if (!wpa_s
->dpp_listen_freq
)
905 wpa_printf(MSG_DEBUG
, "DPP: Stop listen on %u MHz",
906 wpa_s
->dpp_listen_freq
);
907 wpa_drv_cancel_remain_on_channel(wpa_s
);
908 wpa_s
->dpp_listen_freq
= 0;
909 wpas_dpp_listen_work_done(wpa_s
);
913 void wpas_dpp_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
916 if (!wpa_s
->dpp_listen_freq
&& !wpa_s
->dpp_pending_listen_freq
)
919 wpa_printf(MSG_DEBUG
,
920 "DPP: remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d roc_waiting_drv_freq=%d freq=%u)",
921 wpa_s
->off_channel_freq
, wpa_s
->dpp_pending_listen_freq
,
922 wpa_s
->roc_waiting_drv_freq
, freq
);
923 if (wpa_s
->off_channel_freq
&&
924 wpa_s
->off_channel_freq
== wpa_s
->dpp_pending_listen_freq
) {
925 wpa_printf(MSG_DEBUG
, "DPP: Listen on %u MHz started", freq
);
926 wpa_s
->dpp_pending_listen_freq
= 0;
928 wpa_printf(MSG_DEBUG
,
929 "DPP: Ignore remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d freq=%u)",
930 wpa_s
->off_channel_freq
,
931 wpa_s
->dpp_pending_listen_freq
, freq
);
936 void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
939 wpas_dpp_listen_work_done(wpa_s
);
941 if (wpa_s
->dpp_auth
&& !wpa_s
->dpp_gas_client
) {
942 /* Continue listen with a new remain-on-channel */
943 wpa_printf(MSG_DEBUG
,
944 "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
945 wpa_s
->dpp_auth
->curr_freq
);
946 wpas_dpp_listen_start(wpa_s
, wpa_s
->dpp_auth
->curr_freq
);
950 if (wpa_s
->dpp_listen_freq
) {
951 /* Continue listen with a new remain-on-channel */
952 wpas_dpp_listen_start(wpa_s
, wpa_s
->dpp_listen_freq
);
957 static void wpas_dpp_rx_auth_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
958 const u8
*hdr
, const u8
*buf
, size_t len
,
961 const u8
*r_bootstrap
, *i_bootstrap
;
962 u16 r_bootstrap_len
, i_bootstrap_len
;
963 struct dpp_bootstrap_info
*bi
, *own_bi
= NULL
, *peer_bi
= NULL
;
965 wpa_printf(MSG_DEBUG
, "DPP: Authentication Request from " MACSTR
,
968 r_bootstrap
= dpp_get_attr(buf
, len
, DPP_ATTR_R_BOOTSTRAP_KEY_HASH
,
970 if (!r_bootstrap
|| r_bootstrap_len
!= SHA256_MAC_LEN
) {
971 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_FAIL
972 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
975 wpa_hexdump(MSG_MSGDUMP
, "DPP: Responder Bootstrapping Key Hash",
976 r_bootstrap
, r_bootstrap_len
);
978 i_bootstrap
= dpp_get_attr(buf
, len
, DPP_ATTR_I_BOOTSTRAP_KEY_HASH
,
980 if (!i_bootstrap
|| i_bootstrap_len
!= SHA256_MAC_LEN
) {
981 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_FAIL
982 "Missing or invalid required Initiator Bootstrapping Key Hash attribute");
985 wpa_hexdump(MSG_MSGDUMP
, "DPP: Initiator Bootstrapping Key Hash",
986 i_bootstrap
, i_bootstrap_len
);
988 /* Try to find own and peer bootstrapping key matches based on the
989 * received hash values */
990 dl_list_for_each(bi
, &wpa_s
->dpp_bootstrap
, struct dpp_bootstrap_info
,
992 if (!own_bi
&& bi
->own
&&
993 os_memcmp(bi
->pubkey_hash
, r_bootstrap
,
994 SHA256_MAC_LEN
) == 0) {
995 wpa_printf(MSG_DEBUG
,
996 "DPP: Found matching own bootstrapping information");
1000 if (!peer_bi
&& !bi
->own
&&
1001 os_memcmp(bi
->pubkey_hash
, i_bootstrap
,
1002 SHA256_MAC_LEN
) == 0) {
1003 wpa_printf(MSG_DEBUG
,
1004 "DPP: Found matching peer bootstrapping information");
1008 if (own_bi
&& peer_bi
)
1013 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_FAIL
1014 "No matching own bootstrapping key found - ignore message");
1018 if (wpa_s
->dpp_auth
) {
1019 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_FAIL
1020 "Already in DPP authentication exchange - ignore new one");
1024 wpa_s
->dpp_gas_client
= 0;
1025 wpa_s
->dpp_auth_ok_on_ack
= 0;
1026 wpa_s
->dpp_auth
= dpp_auth_req_rx(wpa_s
, wpa_s
->dpp_allowed_roles
,
1027 wpa_s
->dpp_qr_mutual
,
1028 peer_bi
, own_bi
, freq
, hdr
, buf
, len
);
1029 if (!wpa_s
->dpp_auth
) {
1030 wpa_printf(MSG_DEBUG
, "DPP: No response generated");
1033 wpas_dpp_set_testing_options(wpa_s
, wpa_s
->dpp_auth
);
1034 wpas_dpp_set_configurator(wpa_s
, wpa_s
->dpp_auth
,
1035 wpa_s
->dpp_configurator_params
);
1036 os_memcpy(wpa_s
->dpp_auth
->peer_mac_addr
, src
, ETH_ALEN
);
1038 if (wpa_s
->dpp_listen_freq
&&
1039 wpa_s
->dpp_listen_freq
!= wpa_s
->dpp_auth
->curr_freq
) {
1040 wpa_printf(MSG_DEBUG
,
1041 "DPP: Stop listen on %u MHz to allow response on the request %u MHz",
1042 wpa_s
->dpp_listen_freq
, wpa_s
->dpp_auth
->curr_freq
);
1043 wpas_dpp_listen_stop(wpa_s
);
1046 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
1047 MAC2STR(src
), wpa_s
->dpp_auth
->curr_freq
,
1048 DPP_PA_AUTHENTICATION_RESP
);
1049 offchannel_send_action(wpa_s
, wpa_s
->dpp_auth
->curr_freq
,
1050 src
, wpa_s
->own_addr
, broadcast
,
1051 wpabuf_head(wpa_s
->dpp_auth
->resp_msg
),
1052 wpabuf_len(wpa_s
->dpp_auth
->resp_msg
),
1053 500, wpas_dpp_tx_status
, 0);
1057 static void wpas_dpp_start_gas_server(struct wpa_supplicant
*wpa_s
)
1059 /* TODO: stop wait and start ROC */
1063 static struct wpa_ssid
* wpas_dpp_add_network(struct wpa_supplicant
*wpa_s
,
1064 struct dpp_authentication
*auth
)
1066 struct wpa_ssid
*ssid
;
1068 ssid
= wpa_config_add_network(wpa_s
->conf
);
1071 wpas_notify_network_added(wpa_s
, ssid
);
1072 wpa_config_set_network_defaults(ssid
);
1075 ssid
->ssid
= os_malloc(auth
->ssid_len
);
1078 os_memcpy(ssid
->ssid
, auth
->ssid
, auth
->ssid_len
);
1079 ssid
->ssid_len
= auth
->ssid_len
;
1081 if (auth
->connector
) {
1082 ssid
->key_mgmt
= WPA_KEY_MGMT_DPP
;
1083 ssid
->ieee80211w
= 1;
1084 ssid
->dpp_connector
= os_strdup(auth
->connector
);
1085 if (!ssid
->dpp_connector
)
1089 if (auth
->c_sign_key
) {
1090 ssid
->dpp_csign
= os_malloc(wpabuf_len(auth
->c_sign_key
));
1091 if (!ssid
->dpp_csign
)
1093 os_memcpy(ssid
->dpp_csign
, wpabuf_head(auth
->c_sign_key
),
1094 wpabuf_len(auth
->c_sign_key
));
1095 ssid
->dpp_csign_len
= wpabuf_len(auth
->c_sign_key
);
1098 if (auth
->net_access_key
) {
1099 ssid
->dpp_netaccesskey
=
1100 os_malloc(wpabuf_len(auth
->net_access_key
));
1101 if (!ssid
->dpp_netaccesskey
)
1103 os_memcpy(ssid
->dpp_netaccesskey
,
1104 wpabuf_head(auth
->net_access_key
),
1105 wpabuf_len(auth
->net_access_key
));
1106 ssid
->dpp_netaccesskey_len
= wpabuf_len(auth
->net_access_key
);
1107 ssid
->dpp_netaccesskey_expiry
= auth
->net_access_key_expiry
;
1110 if (!auth
->connector
) {
1111 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_PSK_SHA256
;
1112 ssid
->ieee80211w
= 1;
1113 if (auth
->passphrase
[0]) {
1114 if (wpa_config_set_quoted(ssid
, "psk",
1115 auth
->passphrase
) < 0)
1117 wpa_config_update_psk(ssid
);
1118 ssid
->export_keys
= 1;
1120 ssid
->psk_set
= auth
->psk_set
;
1121 os_memcpy(ssid
->psk
, auth
->psk
, PMK_LEN
);
1127 wpas_notify_network_removed(wpa_s
, ssid
);
1128 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
1133 static void wpas_dpp_process_config(struct wpa_supplicant
*wpa_s
,
1134 struct dpp_authentication
*auth
)
1136 struct wpa_ssid
*ssid
;
1138 if (wpa_s
->conf
->dpp_config_processing
< 1)
1141 ssid
= wpas_dpp_add_network(wpa_s
, auth
);
1145 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_NETWORK_ID
"%d", ssid
->id
);
1146 if (wpa_s
->conf
->dpp_config_processing
< 2)
1149 wpa_printf(MSG_DEBUG
, "DPP: Trying to connect to the new network");
1151 wpa_s
->disconnected
= 0;
1152 wpa_s
->reassociate
= 1;
1153 wpa_s
->scan_runs
= 0;
1154 wpa_s
->normal_scans
= 0;
1155 wpa_supplicant_cancel_sched_scan(wpa_s
);
1156 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1160 static void wpas_dpp_handle_config_obj(struct wpa_supplicant
*wpa_s
,
1161 struct dpp_authentication
*auth
)
1163 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_RECEIVED
);
1165 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONFOBJ_SSID
"%s",
1166 wpa_ssid_txt(auth
->ssid
, auth
->ssid_len
));
1167 if (auth
->connector
) {
1168 /* TODO: Save the Connector and consider using a command
1169 * to fetch the value instead of sending an event with
1170 * it. The Connector could end up being larger than what
1171 * most clients are ready to receive as an event
1173 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONNECTOR
"%s",
1176 if (auth
->c_sign_key
) {
1180 hexlen
= 2 * wpabuf_len(auth
->c_sign_key
) + 1;
1181 hex
= os_malloc(hexlen
);
1183 wpa_snprintf_hex(hex
, hexlen
,
1184 wpabuf_head(auth
->c_sign_key
),
1185 wpabuf_len(auth
->c_sign_key
));
1186 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_C_SIGN_KEY
"%s",
1191 if (auth
->net_access_key
) {
1195 hexlen
= 2 * wpabuf_len(auth
->net_access_key
) + 1;
1196 hex
= os_malloc(hexlen
);
1198 wpa_snprintf_hex(hex
, hexlen
,
1199 wpabuf_head(auth
->net_access_key
),
1200 wpabuf_len(auth
->net_access_key
));
1201 if (auth
->net_access_key_expiry
)
1202 wpa_msg(wpa_s
, MSG_INFO
,
1203 DPP_EVENT_NET_ACCESS_KEY
"%s %lu", hex
,
1205 auth
->net_access_key_expiry
);
1207 wpa_msg(wpa_s
, MSG_INFO
,
1208 DPP_EVENT_NET_ACCESS_KEY
"%s", hex
);
1213 wpas_dpp_process_config(wpa_s
, auth
);
1217 static void wpas_dpp_gas_resp_cb(void *ctx
, const u8
*addr
, u8 dialog_token
,
1218 enum gas_query_result result
,
1219 const struct wpabuf
*adv_proto
,
1220 const struct wpabuf
*resp
, u16 status_code
)
1222 struct wpa_supplicant
*wpa_s
= ctx
;
1224 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1226 if (!auth
|| !auth
->auth_success
) {
1227 wpa_printf(MSG_DEBUG
, "DPP: No matching exchange in progress");
1230 if (!resp
|| status_code
!= WLAN_STATUS_SUCCESS
) {
1231 wpa_printf(MSG_DEBUG
, "DPP: GAS query did not succeed");
1235 wpa_hexdump_buf(MSG_DEBUG
, "DPP: Configuration Response adv_proto",
1237 wpa_hexdump_buf(MSG_DEBUG
, "DPP: Configuration Response (GAS response)",
1240 if (wpabuf_len(adv_proto
) != 10 ||
1241 !(pos
= wpabuf_head(adv_proto
)) ||
1242 pos
[0] != WLAN_EID_ADV_PROTO
||
1244 pos
[3] != WLAN_EID_VENDOR_SPECIFIC
||
1246 WPA_GET_BE24(&pos
[5]) != OUI_WFA
||
1249 wpa_printf(MSG_DEBUG
,
1250 "DPP: Not a DPP Advertisement Protocol ID");
1254 if (dpp_conf_resp_rx(auth
, resp
) < 0) {
1255 wpa_printf(MSG_DEBUG
, "DPP: Configuration attempt failed");
1259 wpas_dpp_handle_config_obj(wpa_s
, auth
);
1260 dpp_auth_deinit(wpa_s
->dpp_auth
);
1261 wpa_s
->dpp_auth
= NULL
;
1265 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1266 dpp_auth_deinit(wpa_s
->dpp_auth
);
1267 wpa_s
->dpp_auth
= NULL
;
1271 static void wpas_dpp_start_gas_client(struct wpa_supplicant
*wpa_s
)
1273 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1274 struct wpabuf
*buf
, *conf_req
;
1278 wpa_s
->dpp_gas_client
= 1;
1279 os_snprintf(json
, sizeof(json
),
1280 "{\"name\":\"Test\","
1281 "\"wi-fi_tech\":\"infra\","
1282 "\"netRole\":\"%s\"}",
1283 wpa_s
->dpp_netrole_ap
? "ap" : "sta");
1284 #ifdef CONFIG_TESTING_OPTIONS
1285 if (dpp_test
== DPP_TEST_INVALID_CONFIG_ATTR_OBJ_CONF_REQ
) {
1286 wpa_printf(MSG_INFO
, "DPP: TESTING - invalid Config Attr");
1287 json
[29] = 'k'; /* replace "infra" with "knfra" */
1289 #endif /* CONFIG_TESTING_OPTIONS */
1290 wpa_printf(MSG_DEBUG
, "DPP: GAS Config Attributes: %s", json
);
1292 offchannel_send_action_done(wpa_s
);
1293 wpas_dpp_listen_stop(wpa_s
);
1295 conf_req
= dpp_build_conf_req(auth
, json
);
1297 wpa_printf(MSG_DEBUG
,
1298 "DPP: No configuration request data available");
1302 buf
= gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req
));
1304 wpabuf_free(conf_req
);
1308 /* Advertisement Protocol IE */
1309 wpabuf_put_u8(buf
, WLAN_EID_ADV_PROTO
);
1310 wpabuf_put_u8(buf
, 8); /* Length */
1311 wpabuf_put_u8(buf
, 0x7f);
1312 wpabuf_put_u8(buf
, WLAN_EID_VENDOR_SPECIFIC
);
1313 wpabuf_put_u8(buf
, 5);
1314 wpabuf_put_be24(buf
, OUI_WFA
);
1315 wpabuf_put_u8(buf
, DPP_OUI_TYPE
);
1316 wpabuf_put_u8(buf
, 0x01);
1319 wpabuf_put_le16(buf
, wpabuf_len(conf_req
));
1320 wpabuf_put_buf(buf
, conf_req
);
1321 wpabuf_free(conf_req
);
1323 wpa_printf(MSG_DEBUG
, "DPP: GAS request to " MACSTR
" (freq %u MHz)",
1324 MAC2STR(auth
->peer_mac_addr
), auth
->curr_freq
);
1326 res
= gas_query_req(wpa_s
->gas
, auth
->peer_mac_addr
, auth
->curr_freq
,
1327 buf
, wpas_dpp_gas_resp_cb
, wpa_s
);
1329 wpa_msg(wpa_s
, MSG_DEBUG
, "GAS: Failed to send Query Request");
1332 wpa_printf(MSG_DEBUG
,
1333 "DPP: GAS query started with dialog token %u", res
);
1338 static void wpas_dpp_auth_success(struct wpa_supplicant
*wpa_s
, int initiator
)
1340 wpa_printf(MSG_DEBUG
, "DPP: Authentication succeeded");
1341 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_AUTH_SUCCESS
"init=%d", initiator
);
1343 if (wpa_s
->dpp_auth
->configurator
)
1344 wpas_dpp_start_gas_server(wpa_s
);
1346 wpas_dpp_start_gas_client(wpa_s
);
1350 static void wpas_dpp_rx_auth_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1351 const u8
*hdr
, const u8
*buf
, size_t len
,
1354 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1357 wpa_printf(MSG_DEBUG
, "DPP: Authentication Response from " MACSTR
1358 " (freq %u MHz)", MAC2STR(src
), freq
);
1361 wpa_printf(MSG_DEBUG
,
1362 "DPP: No DPP Authentication in progress - drop");
1366 if (!is_zero_ether_addr(auth
->peer_mac_addr
) &&
1367 os_memcmp(src
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1368 wpa_printf(MSG_DEBUG
, "DPP: MAC address mismatch (expected "
1369 MACSTR
") - drop", MAC2STR(auth
->peer_mac_addr
));
1373 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
1375 if (auth
->curr_freq
!= freq
&& auth
->neg_freq
== freq
) {
1376 wpa_printf(MSG_DEBUG
,
1377 "DPP: Responder accepted request for different negotiation channel");
1378 auth
->curr_freq
= freq
;
1381 eloop_cancel_timeout(wpas_dpp_init_timeout
, wpa_s
, NULL
);
1382 msg
= dpp_auth_resp_rx(auth
, hdr
, buf
, len
);
1384 if (auth
->auth_resp_status
== DPP_STATUS_RESPONSE_PENDING
) {
1385 wpa_printf(MSG_DEBUG
,
1386 "DPP: Start wait for full response");
1387 offchannel_send_action_done(wpa_s
);
1388 wpas_dpp_listen_start(wpa_s
, auth
->curr_freq
);
1391 wpa_printf(MSG_DEBUG
, "DPP: No confirm generated");
1394 os_memcpy(auth
->peer_mac_addr
, src
, ETH_ALEN
);
1396 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
1397 MAC2STR(src
), auth
->curr_freq
, DPP_PA_AUTHENTICATION_CONF
);
1398 offchannel_send_action(wpa_s
, auth
->curr_freq
,
1399 src
, wpa_s
->own_addr
, broadcast
,
1400 wpabuf_head(msg
), wpabuf_len(msg
),
1401 500, wpas_dpp_tx_status
, 0);
1403 wpa_s
->dpp_auth_ok_on_ack
= 1;
1407 static void wpas_dpp_rx_auth_conf(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1408 const u8
*hdr
, const u8
*buf
, size_t len
)
1410 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1412 wpa_printf(MSG_DEBUG
, "DPP: Authentication Confirmation from " MACSTR
,
1416 wpa_printf(MSG_DEBUG
,
1417 "DPP: No DPP Authentication in progress - drop");
1421 if (os_memcmp(src
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1422 wpa_printf(MSG_DEBUG
, "DPP: MAC address mismatch (expected "
1423 MACSTR
") - drop", MAC2STR(auth
->peer_mac_addr
));
1427 if (dpp_auth_conf_rx(auth
, hdr
, buf
, len
) < 0) {
1428 wpa_printf(MSG_DEBUG
, "DPP: Authentication failed");
1432 wpas_dpp_auth_success(wpa_s
, 0);
1436 static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant
*wpa_s
,
1438 const u8
*buf
, size_t len
)
1440 struct wpa_ssid
*ssid
;
1441 const u8
*connector
, *trans_id
, *status
;
1442 u16 connector_len
, trans_id_len
, status_len
;
1443 struct dpp_introduction intro
;
1444 struct rsn_pmksa_cache_entry
*entry
;
1446 struct os_reltime rnow
;
1448 unsigned int seconds
;
1449 enum dpp_status_error res
;
1451 wpa_printf(MSG_DEBUG
, "DPP: Peer Discovery Response from " MACSTR
,
1453 if (is_zero_ether_addr(wpa_s
->dpp_intro_bssid
) ||
1454 os_memcmp(src
, wpa_s
->dpp_intro_bssid
, ETH_ALEN
) != 0) {
1455 wpa_printf(MSG_DEBUG
, "DPP: Not waiting for response from "
1456 MACSTR
" - drop", MAC2STR(src
));
1459 offchannel_send_action_done(wpa_s
);
1461 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1462 if (ssid
== wpa_s
->dpp_intro_network
)
1465 if (!ssid
|| !ssid
->dpp_connector
|| !ssid
->dpp_netaccesskey
||
1467 wpa_printf(MSG_DEBUG
,
1468 "DPP: Profile not found for network introduction");
1472 trans_id
= dpp_get_attr(buf
, len
, DPP_ATTR_TRANSACTION_ID
,
1474 if (!trans_id
|| trans_id_len
!= 1) {
1475 wpa_printf(MSG_DEBUG
,
1476 "DPP: Peer did not include Transaction ID");
1477 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_INTRO
"peer=" MACSTR
1478 " fail=missing_transaction_id", MAC2STR(src
));
1481 if (trans_id
[0] != TRANSACTION_ID
) {
1482 wpa_printf(MSG_DEBUG
,
1483 "DPP: Ignore frame with unexpected Transaction ID %u",
1485 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_INTRO
"peer=" MACSTR
1486 " fail=transaction_id_mismatch", MAC2STR(src
));
1490 status
= dpp_get_attr(buf
, len
, DPP_ATTR_STATUS
, &status_len
);
1491 if (!status
|| status_len
!= 1) {
1492 wpa_printf(MSG_DEBUG
, "DPP: Peer did not include Status");
1493 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_INTRO
"peer=" MACSTR
1494 " fail=missing_status", MAC2STR(src
));
1497 if (status
[0] != DPP_STATUS_OK
) {
1498 wpa_printf(MSG_DEBUG
,
1499 "DPP: Peer rejected network introduction: Status %u",
1501 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_INTRO
"peer=" MACSTR
1502 " status=%u", MAC2STR(src
), status
[0]);
1506 connector
= dpp_get_attr(buf
, len
, DPP_ATTR_CONNECTOR
, &connector_len
);
1508 wpa_printf(MSG_DEBUG
,
1509 "DPP: Peer did not include its Connector");
1510 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_INTRO
"peer=" MACSTR
1511 " fail=missing_connector", MAC2STR(src
));
1515 res
= dpp_peer_intro(&intro
, ssid
->dpp_connector
,
1516 ssid
->dpp_netaccesskey
,
1517 ssid
->dpp_netaccesskey_len
,
1519 ssid
->dpp_csign_len
,
1520 connector
, connector_len
, &expiry
);
1521 if (res
!= DPP_STATUS_OK
) {
1522 wpa_printf(MSG_INFO
,
1523 "DPP: Network Introduction protocol resulted in failure");
1524 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_INTRO
"peer=" MACSTR
1525 " fail=peer_connector_validation_failed", MAC2STR(src
));
1529 entry
= os_zalloc(sizeof(*entry
));
1532 os_memcpy(entry
->aa
, src
, ETH_ALEN
);
1533 os_memcpy(entry
->pmkid
, intro
.pmkid
, PMKID_LEN
);
1534 os_memcpy(entry
->pmk
, intro
.pmk
, intro
.pmk_len
);
1535 entry
->pmk_len
= intro
.pmk_len
;
1536 entry
->akmp
= WPA_KEY_MGMT_DPP
;
1539 seconds
= expiry
- now
.sec
;
1541 seconds
= 86400 * 7;
1543 os_get_reltime(&rnow
);
1544 entry
->expiration
= rnow
.sec
+ seconds
;
1545 entry
->reauth_time
= rnow
.sec
+ seconds
;
1546 entry
->network_ctx
= ssid
;
1547 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
1549 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_INTRO
"peer=" MACSTR
1550 " status=%u", MAC2STR(src
), status
[0]);
1552 wpa_printf(MSG_DEBUG
,
1553 "DPP: Try connection again after successful network introduction");
1554 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
1555 wpa_supplicant_cancel_sched_scan(wpa_s
);
1556 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1559 os_memset(&intro
, 0, sizeof(intro
));
1563 static void wpas_dpp_pkex_retry_timeout(void *eloop_ctx
, void *timeout_ctx
)
1565 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1566 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1568 if (!pkex
|| !pkex
->exchange_req
)
1570 if (pkex
->exch_req_tries
>= 5) {
1571 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_FAIL
1572 "No response from PKEX peer");
1573 dpp_pkex_free(pkex
);
1574 wpa_s
->dpp_pkex
= NULL
;
1578 pkex
->exch_req_tries
++;
1579 wpa_printf(MSG_DEBUG
, "DPP: Retransmit PKEX Exchange Request (try %u)",
1580 pkex
->exch_req_tries
);
1581 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
1582 MAC2STR(broadcast
), pkex
->freq
, DPP_PA_PKEX_EXCHANGE_REQ
);
1583 offchannel_send_action(wpa_s
, pkex
->freq
, broadcast
,
1584 wpa_s
->own_addr
, broadcast
,
1585 wpabuf_head(pkex
->exchange_req
),
1586 wpabuf_len(pkex
->exchange_req
),
1587 pkex
->exch_req_wait_time
,
1588 wpas_dpp_tx_pkex_status
, 0);
1593 wpas_dpp_tx_pkex_status(struct wpa_supplicant
*wpa_s
,
1594 unsigned int freq
, const u8
*dst
,
1595 const u8
*src
, const u8
*bssid
,
1596 const u8
*data
, size_t data_len
,
1597 enum offchannel_send_action_result result
)
1599 const char *res_txt
;
1600 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1602 res_txt
= result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
1603 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
1605 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
1606 " result=%s (PKEX)",
1607 freq
, MAC2STR(dst
), res_txt
);
1608 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX_STATUS
"dst=" MACSTR
1609 " freq=%u result=%s", MAC2STR(dst
), freq
, res_txt
);
1612 wpa_printf(MSG_DEBUG
,
1613 "DPP: Ignore TX status since there is no ongoing PKEX exchange");
1618 wpa_printf(MSG_DEBUG
,
1619 "DPP: Terminate PKEX exchange due to an earlier error");
1620 if (pkex
->t
> pkex
->own_bi
->pkex_t
)
1621 pkex
->own_bi
->pkex_t
= pkex
->t
;
1622 dpp_pkex_free(pkex
);
1623 wpa_s
->dpp_pkex
= NULL
;
1627 if (pkex
->exch_req_wait_time
&& pkex
->exchange_req
) {
1628 /* Wait for PKEX Exchange Response frame and retry request if
1629 * no response is seen. */
1630 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout
, wpa_s
, NULL
);
1631 eloop_register_timeout(pkex
->exch_req_wait_time
/ 1000,
1632 (pkex
->exch_req_wait_time
% 1000) * 1000,
1633 wpas_dpp_pkex_retry_timeout
, wpa_s
,
1640 wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1641 const u8
*buf
, size_t len
, unsigned int freq
)
1644 unsigned int wait_time
;
1646 wpa_printf(MSG_DEBUG
, "DPP: PKEX Exchange Request from " MACSTR
,
1649 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1652 if (!wpa_s
->dpp_pkex_code
|| !wpa_s
->dpp_pkex_bi
) {
1653 wpa_printf(MSG_DEBUG
,
1654 "DPP: No PKEX code configured - ignore request");
1658 if (wpa_s
->dpp_pkex
) {
1659 /* TODO: Support parallel operations */
1660 wpa_printf(MSG_DEBUG
,
1661 "DPP: Already in PKEX session - ignore new request");
1665 wpa_s
->dpp_pkex
= dpp_pkex_rx_exchange_req(wpa_s
, wpa_s
->dpp_pkex_bi
,
1666 wpa_s
->own_addr
, src
,
1667 wpa_s
->dpp_pkex_identifier
,
1668 wpa_s
->dpp_pkex_code
,
1670 if (!wpa_s
->dpp_pkex
) {
1671 wpa_printf(MSG_DEBUG
,
1672 "DPP: Failed to process the request - ignore it");
1676 msg
= wpa_s
->dpp_pkex
->exchange_resp
;
1677 wait_time
= wpa_s
->max_remain_on_chan
;
1678 if (wait_time
> 2000)
1680 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
1681 MAC2STR(src
), freq
, DPP_PA_PKEX_EXCHANGE_RESP
);
1682 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
1684 wpabuf_head(msg
), wpabuf_len(msg
),
1685 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1690 wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1691 const u8
*buf
, size_t len
, unsigned int freq
)
1694 unsigned int wait_time
;
1696 wpa_printf(MSG_DEBUG
, "DPP: PKEX Exchange Response from " MACSTR
,
1699 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1702 if (!wpa_s
->dpp_pkex
|| !wpa_s
->dpp_pkex
->initiator
||
1703 wpa_s
->dpp_pkex
->exchange_done
) {
1704 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
1708 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout
, wpa_s
, NULL
);
1709 wpa_s
->dpp_pkex
->exch_req_wait_time
= 0;
1711 os_memcpy(wpa_s
->dpp_pkex
->peer_mac
, src
, ETH_ALEN
);
1712 msg
= dpp_pkex_rx_exchange_resp(wpa_s
->dpp_pkex
, buf
, len
);
1714 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the response");
1718 wpa_printf(MSG_DEBUG
, "DPP: Send PKEX Commit-Reveal Request to " MACSTR
,
1721 wait_time
= wpa_s
->max_remain_on_chan
;
1722 if (wait_time
> 2000)
1724 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
1725 MAC2STR(src
), freq
, DPP_PA_PKEX_COMMIT_REVEAL_REQ
);
1726 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
1728 wpabuf_head(msg
), wpabuf_len(msg
),
1729 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1734 static struct dpp_bootstrap_info
*
1735 wpas_dpp_pkex_finish(struct wpa_supplicant
*wpa_s
, const u8
*peer
,
1738 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1739 struct dpp_bootstrap_info
*bi
;
1741 bi
= os_zalloc(sizeof(*bi
));
1744 bi
->id
= wpas_dpp_next_id(wpa_s
);
1745 bi
->type
= DPP_BOOTSTRAP_PKEX
;
1746 os_memcpy(bi
->mac_addr
, peer
, ETH_ALEN
);
1749 bi
->curve
= pkex
->own_bi
->curve
;
1750 bi
->pubkey
= pkex
->peer_bootstrap_key
;
1751 pkex
->peer_bootstrap_key
= NULL
;
1752 dpp_pkex_free(pkex
);
1753 wpa_s
->dpp_pkex
= NULL
;
1754 if (dpp_bootstrap_key_hash(bi
) < 0) {
1755 dpp_bootstrap_info_free(bi
);
1758 dl_list_add(&wpa_s
->dpp_bootstrap
, &bi
->list
);
1764 wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1765 const u8
*hdr
, const u8
*buf
, size_t len
,
1769 unsigned int wait_time
;
1770 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1772 wpa_printf(MSG_DEBUG
, "DPP: PKEX Commit-Reveal Request from " MACSTR
,
1775 if (!pkex
|| pkex
->initiator
|| !pkex
->exchange_done
) {
1776 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
1780 msg
= dpp_pkex_rx_commit_reveal_req(pkex
, hdr
, buf
, len
);
1782 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the request");
1784 wpa_printf(MSG_DEBUG
, "DPP: Terminate PKEX exchange");
1785 if (pkex
->t
> pkex
->own_bi
->pkex_t
)
1786 pkex
->own_bi
->pkex_t
= pkex
->t
;
1787 dpp_pkex_free(wpa_s
->dpp_pkex
);
1788 wpa_s
->dpp_pkex
= NULL
;
1793 wpa_printf(MSG_DEBUG
, "DPP: Send PKEX Commit-Reveal Response to "
1794 MACSTR
, MAC2STR(src
));
1796 wait_time
= wpa_s
->max_remain_on_chan
;
1797 if (wait_time
> 2000)
1799 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
1800 MAC2STR(src
), freq
, DPP_PA_PKEX_COMMIT_REVEAL_RESP
);
1801 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
1803 wpabuf_head(msg
), wpabuf_len(msg
),
1804 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1807 wpas_dpp_pkex_finish(wpa_s
, src
, freq
);
1812 wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1813 const u8
*hdr
, const u8
*buf
, size_t len
,
1817 struct dpp_bootstrap_info
*bi
;
1818 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1821 wpa_printf(MSG_DEBUG
, "DPP: PKEX Commit-Reveal Response from " MACSTR
,
1824 if (!pkex
|| !pkex
->initiator
|| !pkex
->exchange_done
) {
1825 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
1829 res
= dpp_pkex_rx_commit_reveal_resp(pkex
, hdr
, buf
, len
);
1831 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the response");
1835 bi
= wpas_dpp_pkex_finish(wpa_s
, src
, freq
);
1839 os_snprintf(cmd
, sizeof(cmd
), " peer=%u %s",
1841 wpa_s
->dpp_pkex_auth_cmd
? wpa_s
->dpp_pkex_auth_cmd
: "");
1842 wpa_printf(MSG_DEBUG
,
1843 "DPP: Start authentication after PKEX with parameters: %s",
1845 if (wpas_dpp_auth_init(wpa_s
, cmd
) < 0) {
1846 wpa_printf(MSG_DEBUG
,
1847 "DPP: Authentication initialization failed");
1853 void wpas_dpp_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1854 const u8
*buf
, size_t len
, unsigned int freq
)
1857 enum dpp_public_action_frame_type type
;
1859 unsigned int pkex_t
;
1861 if (len
< DPP_HDR_LEN
)
1863 if (WPA_GET_BE24(buf
) != OUI_WFA
|| buf
[3] != DPP_OUI_TYPE
)
1868 crypto_suite
= *buf
++;
1872 wpa_printf(MSG_DEBUG
,
1873 "DPP: Received DPP Public Action frame crypto suite %u type %d from "
1875 crypto_suite
, type
, MAC2STR(src
), freq
);
1876 if (crypto_suite
!= 1) {
1877 wpa_printf(MSG_DEBUG
, "DPP: Unsupported crypto suite %u",
1879 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_RX
"src=" MACSTR
1880 " freq=%u type=%d ignore=unsupported-crypto-suite",
1881 MAC2STR(src
), freq
, type
);
1884 wpa_hexdump(MSG_MSGDUMP
, "DPP: Received message attributes", buf
, len
);
1885 if (dpp_check_attrs(buf
, len
) < 0) {
1886 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_RX
"src=" MACSTR
1887 " freq=%u type=%d ignore=invalid-attributes",
1888 MAC2STR(src
), freq
, type
);
1891 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_RX
"src=" MACSTR
" freq=%u type=%d",
1892 MAC2STR(src
), freq
, type
);
1895 case DPP_PA_AUTHENTICATION_REQ
:
1896 wpas_dpp_rx_auth_req(wpa_s
, src
, hdr
, buf
, len
, freq
);
1898 case DPP_PA_AUTHENTICATION_RESP
:
1899 wpas_dpp_rx_auth_resp(wpa_s
, src
, hdr
, buf
, len
, freq
);
1901 case DPP_PA_AUTHENTICATION_CONF
:
1902 wpas_dpp_rx_auth_conf(wpa_s
, src
, hdr
, buf
, len
);
1904 case DPP_PA_PEER_DISCOVERY_RESP
:
1905 wpas_dpp_rx_peer_disc_resp(wpa_s
, src
, buf
, len
);
1907 case DPP_PA_PKEX_EXCHANGE_REQ
:
1908 wpas_dpp_rx_pkex_exchange_req(wpa_s
, src
, buf
, len
, freq
);
1910 case DPP_PA_PKEX_EXCHANGE_RESP
:
1911 wpas_dpp_rx_pkex_exchange_resp(wpa_s
, src
, buf
, len
, freq
);
1913 case DPP_PA_PKEX_COMMIT_REVEAL_REQ
:
1914 wpas_dpp_rx_pkex_commit_reveal_req(wpa_s
, src
, hdr
, buf
, len
,
1917 case DPP_PA_PKEX_COMMIT_REVEAL_RESP
:
1918 wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s
, src
, hdr
, buf
, len
,
1922 wpa_printf(MSG_DEBUG
,
1923 "DPP: Ignored unsupported frame subtype %d", type
);
1927 if (wpa_s
->dpp_pkex
)
1928 pkex_t
= wpa_s
->dpp_pkex
->t
;
1929 else if (wpa_s
->dpp_pkex_bi
)
1930 pkex_t
= wpa_s
->dpp_pkex_bi
->pkex_t
;
1933 if (pkex_t
>= PKEX_COUNTER_T_LIMIT
) {
1934 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_PKEX_T_LIMIT
"id=0");
1935 wpas_dpp_pkex_remove(wpa_s
, "*");
1940 static struct wpabuf
*
1941 wpas_dpp_gas_req_handler(void *ctx
, const u8
*sa
, const u8
*query
,
1944 struct wpa_supplicant
*wpa_s
= ctx
;
1945 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1946 struct wpabuf
*resp
;
1948 wpa_printf(MSG_DEBUG
, "DPP: GAS request from " MACSTR
,
1950 if (!auth
|| !auth
->auth_success
||
1951 os_memcmp(sa
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1952 wpa_printf(MSG_DEBUG
, "DPP: No matching exchange in progress");
1955 wpa_hexdump(MSG_DEBUG
,
1956 "DPP: Received Configuration Request (GAS Query Request)",
1958 resp
= dpp_conf_req_rx(auth
, query
, query_len
);
1960 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1966 wpas_dpp_gas_status_handler(void *ctx
, struct wpabuf
*resp
, int ok
)
1968 struct wpa_supplicant
*wpa_s
= ctx
;
1969 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1976 wpa_printf(MSG_DEBUG
, "DPP: Configuration exchange completed (ok=%d)",
1978 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
1979 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout
, wpa_s
, NULL
);
1980 offchannel_send_action_done(wpa_s
);
1981 wpas_dpp_listen_stop(wpa_s
);
1983 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_SENT
);
1985 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1986 dpp_auth_deinit(wpa_s
->dpp_auth
);
1987 wpa_s
->dpp_auth
= NULL
;
1992 static unsigned int wpas_dpp_next_configurator_id(struct wpa_supplicant
*wpa_s
)
1994 struct dpp_configurator
*conf
;
1995 unsigned int max_id
= 0;
1997 dl_list_for_each(conf
, &wpa_s
->dpp_configurator
,
1998 struct dpp_configurator
, list
) {
1999 if (conf
->id
> max_id
)
2006 int wpas_dpp_configurator_add(struct wpa_supplicant
*wpa_s
, const char *cmd
)
2011 size_t privkey_len
= 0;
2013 struct dpp_configurator
*conf
= NULL
;
2015 curve
= get_param(cmd
, " curve=");
2016 key
= get_param(cmd
, " key=");
2019 privkey_len
= os_strlen(key
) / 2;
2020 privkey
= os_malloc(privkey_len
);
2022 hexstr2bin(key
, privkey
, privkey_len
) < 0)
2026 conf
= dpp_keygen_configurator(curve
, privkey
, privkey_len
);
2030 conf
->id
= wpas_dpp_next_configurator_id(wpa_s
);
2031 dl_list_add(&wpa_s
->dpp_configurator
, &conf
->list
);
2036 str_clear_free(key
);
2037 bin_clear_free(privkey
, privkey_len
);
2038 dpp_configurator_free(conf
);
2043 static int dpp_configurator_del(struct wpa_supplicant
*wpa_s
, unsigned int id
)
2045 struct dpp_configurator
*conf
, *tmp
;
2048 dl_list_for_each_safe(conf
, tmp
, &wpa_s
->dpp_configurator
,
2049 struct dpp_configurator
, list
) {
2050 if (id
&& conf
->id
!= id
)
2053 dl_list_del(&conf
->list
);
2054 dpp_configurator_free(conf
);
2058 return 0; /* flush succeeds regardless of entries found */
2059 return found
? 0 : -1;
2063 int wpas_dpp_configurator_remove(struct wpa_supplicant
*wpa_s
, const char *id
)
2065 unsigned int id_val
;
2067 if (os_strcmp(id
, "*") == 0) {
2075 return dpp_configurator_del(wpa_s
, id_val
);
2079 int wpas_dpp_configurator_sign(struct wpa_supplicant
*wpa_s
, const char *cmd
)
2081 struct dpp_authentication
*auth
;
2085 auth
= os_zalloc(sizeof(*auth
));
2089 curve
= get_param(cmd
, " curve=");
2090 wpas_dpp_set_configurator(wpa_s
, auth
, cmd
);
2092 if (dpp_configurator_own_config(auth
, curve
) == 0) {
2093 wpas_dpp_handle_config_obj(wpa_s
, auth
);
2097 dpp_auth_deinit(auth
);
2105 wpas_dpp_tx_introduction_status(struct wpa_supplicant
*wpa_s
,
2106 unsigned int freq
, const u8
*dst
,
2107 const u8
*src
, const u8
*bssid
,
2108 const u8
*data
, size_t data_len
,
2109 enum offchannel_send_action_result result
)
2111 const char *res_txt
;
2113 res_txt
= result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
2114 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
2116 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
2117 " result=%s (DPP Peer Discovery Request)",
2118 freq
, MAC2STR(dst
), res_txt
);
2119 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX_STATUS
"dst=" MACSTR
2120 " freq=%u result=%s", MAC2STR(dst
), freq
, res_txt
);
2121 /* TODO: Time out wait for response more quickly in error cases? */
2125 int wpas_dpp_check_connect(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
2126 struct wpa_bss
*bss
)
2130 unsigned int wait_time
;
2132 if (!(ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) || !bss
)
2133 return 0; /* Not using DPP AKM - continue */
2134 if (wpa_sm_pmksa_exists(wpa_s
->wpa
, bss
->bssid
, ssid
))
2135 return 0; /* PMKSA exists for DPP AKM - continue */
2137 if (!ssid
->dpp_connector
|| !ssid
->dpp_netaccesskey
||
2139 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_MISSING_CONNECTOR
2141 !ssid
->dpp_connector
? "Connector" :
2142 (!ssid
->dpp_netaccesskey
? "netAccessKey" :
2149 if (ssid
->dpp_netaccesskey_expiry
&&
2150 ssid
->dpp_netaccesskey_expiry
< now
.sec
) {
2151 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_MISSING_CONNECTOR
2152 "netAccessKey expired");
2156 wpa_printf(MSG_DEBUG
,
2157 "DPP: Starting network introduction protocol to derive PMKSA for "
2158 MACSTR
, MAC2STR(bss
->bssid
));
2160 msg
= dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ
,
2161 5 + 4 + os_strlen(ssid
->dpp_connector
));
2165 #ifdef CONFIG_TESTING_OPTIONS
2166 if (dpp_test
== DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ
) {
2167 wpa_printf(MSG_INFO
, "DPP: TESTING - no Transaction ID");
2170 #endif /* CONFIG_TESTING_OPTIONS */
2172 /* Transaction ID */
2173 wpabuf_put_le16(msg
, DPP_ATTR_TRANSACTION_ID
);
2174 wpabuf_put_le16(msg
, 1);
2175 wpabuf_put_u8(msg
, TRANSACTION_ID
);
2177 #ifdef CONFIG_TESTING_OPTIONS
2179 if (dpp_test
== DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ
) {
2180 wpa_printf(MSG_INFO
, "DPP: TESTING - no Connector");
2181 goto skip_connector
;
2183 if (dpp_test
== DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ
) {
2186 wpa_printf(MSG_INFO
, "DPP: TESTING - invalid Connector");
2187 connector
= dpp_corrupt_connector_signature(
2188 ssid
->dpp_connector
);
2193 wpabuf_put_le16(msg
, DPP_ATTR_CONNECTOR
);
2194 wpabuf_put_le16(msg
, os_strlen(connector
));
2195 wpabuf_put_str(msg
, connector
);
2197 goto skip_connector
;
2199 #endif /* CONFIG_TESTING_OPTIONS */
2202 wpabuf_put_le16(msg
, DPP_ATTR_CONNECTOR
);
2203 wpabuf_put_le16(msg
, os_strlen(ssid
->dpp_connector
));
2204 wpabuf_put_str(msg
, ssid
->dpp_connector
);
2206 #ifdef CONFIG_TESTING_OPTIONS
2208 #endif /* CONFIG_TESTING_OPTIONS */
2210 /* TODO: Timeout on AP response */
2211 wait_time
= wpa_s
->max_remain_on_chan
;
2212 if (wait_time
> 2000)
2214 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
" freq=%u type=%d",
2215 MAC2STR(bss
->bssid
), bss
->freq
, DPP_PA_PEER_DISCOVERY_REQ
);
2216 offchannel_send_action(wpa_s
, bss
->freq
, bss
->bssid
, wpa_s
->own_addr
,
2218 wpabuf_head(msg
), wpabuf_len(msg
),
2219 wait_time
, wpas_dpp_tx_introduction_status
, 0);
2222 /* Request this connection attempt to terminate - new one will be
2223 * started when network introduction protocol completes */
2224 os_memcpy(wpa_s
->dpp_intro_bssid
, bss
->bssid
, ETH_ALEN
);
2225 wpa_s
->dpp_intro_network
= ssid
;
2230 int wpas_dpp_pkex_add(struct wpa_supplicant
*wpa_s
, const char *cmd
)
2232 struct dpp_bootstrap_info
*own_bi
;
2233 const char *pos
, *end
;
2234 unsigned int wait_time
;
2236 pos
= os_strstr(cmd
, " own=");
2240 own_bi
= dpp_bootstrap_get_id(wpa_s
, atoi(pos
));
2242 wpa_printf(MSG_DEBUG
,
2243 "DPP: Identified bootstrap info not found");
2246 if (own_bi
->type
!= DPP_BOOTSTRAP_PKEX
) {
2247 wpa_printf(MSG_DEBUG
,
2248 "DPP: Identified bootstrap info not for PKEX");
2251 wpa_s
->dpp_pkex_bi
= own_bi
;
2252 own_bi
->pkex_t
= 0; /* clear pending errors on new code */
2254 os_free(wpa_s
->dpp_pkex_identifier
);
2255 wpa_s
->dpp_pkex_identifier
= NULL
;
2256 pos
= os_strstr(cmd
, " identifier=");
2259 end
= os_strchr(pos
, ' ');
2262 wpa_s
->dpp_pkex_identifier
= os_malloc(end
- pos
+ 1);
2263 if (!wpa_s
->dpp_pkex_identifier
)
2265 os_memcpy(wpa_s
->dpp_pkex_identifier
, pos
, end
- pos
);
2266 wpa_s
->dpp_pkex_identifier
[end
- pos
] = '\0';
2269 pos
= os_strstr(cmd
, " code=");
2272 os_free(wpa_s
->dpp_pkex_code
);
2273 wpa_s
->dpp_pkex_code
= os_strdup(pos
+ 6);
2274 if (!wpa_s
->dpp_pkex_code
)
2277 if (os_strstr(cmd
, " init=1")) {
2278 struct dpp_pkex
*pkex
;
2281 wpa_printf(MSG_DEBUG
, "DPP: Initiating PKEX");
2282 dpp_pkex_free(wpa_s
->dpp_pkex
);
2283 wpa_s
->dpp_pkex
= dpp_pkex_init(wpa_s
, own_bi
, wpa_s
->own_addr
,
2284 wpa_s
->dpp_pkex_identifier
,
2285 wpa_s
->dpp_pkex_code
);
2286 pkex
= wpa_s
->dpp_pkex
;
2290 msg
= pkex
->exchange_req
;
2291 wait_time
= wpa_s
->max_remain_on_chan
;
2292 if (wait_time
> 2000)
2294 /* TODO: Support for 5 GHz channels */
2296 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_TX
"dst=" MACSTR
2298 MAC2STR(broadcast
), pkex
->freq
,
2299 DPP_PA_PKEX_EXCHANGE_REQ
);
2300 offchannel_send_action(wpa_s
, pkex
->freq
, broadcast
,
2301 wpa_s
->own_addr
, broadcast
,
2302 wpabuf_head(msg
), wpabuf_len(msg
),
2303 wait_time
, wpas_dpp_tx_pkex_status
, 0);
2306 pkex
->exch_req_wait_time
= wait_time
;
2307 pkex
->exch_req_tries
= 1;
2310 /* TODO: Support multiple PKEX info entries */
2312 os_free(wpa_s
->dpp_pkex_auth_cmd
);
2313 wpa_s
->dpp_pkex_auth_cmd
= os_strdup(cmd
);
2319 int wpas_dpp_pkex_remove(struct wpa_supplicant
*wpa_s
, const char *id
)
2321 unsigned int id_val
;
2323 if (os_strcmp(id
, "*") == 0) {
2331 if ((id_val
!= 0 && id_val
!= 1) || !wpa_s
->dpp_pkex_code
)
2334 /* TODO: Support multiple PKEX entries */
2335 os_free(wpa_s
->dpp_pkex_code
);
2336 wpa_s
->dpp_pkex_code
= NULL
;
2337 os_free(wpa_s
->dpp_pkex_identifier
);
2338 wpa_s
->dpp_pkex_identifier
= NULL
;
2339 os_free(wpa_s
->dpp_pkex_auth_cmd
);
2340 wpa_s
->dpp_pkex_auth_cmd
= NULL
;
2341 wpa_s
->dpp_pkex_bi
= NULL
;
2342 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
2343 dpp_pkex_free(wpa_s
->dpp_pkex
);
2344 wpa_s
->dpp_pkex
= NULL
;
2349 void wpas_dpp_stop(struct wpa_supplicant
*wpa_s
)
2351 dpp_auth_deinit(wpa_s
->dpp_auth
);
2352 wpa_s
->dpp_auth
= NULL
;
2356 int wpas_dpp_init(struct wpa_supplicant
*wpa_s
)
2360 adv_proto_id
[0] = WLAN_EID_VENDOR_SPECIFIC
;
2361 adv_proto_id
[1] = 5;
2362 WPA_PUT_BE24(&adv_proto_id
[2], OUI_WFA
);
2363 adv_proto_id
[5] = DPP_OUI_TYPE
;
2364 adv_proto_id
[6] = 0x01;
2366 if (gas_server_register(wpa_s
->gas_server
, adv_proto_id
,
2367 sizeof(adv_proto_id
), wpas_dpp_gas_req_handler
,
2368 wpas_dpp_gas_status_handler
, wpa_s
) < 0)
2370 dl_list_init(&wpa_s
->dpp_bootstrap
);
2371 dl_list_init(&wpa_s
->dpp_configurator
);
2372 wpa_s
->dpp_init_done
= 1;
2377 void wpas_dpp_deinit(struct wpa_supplicant
*wpa_s
)
2379 #ifdef CONFIG_TESTING_OPTIONS
2380 os_free(wpa_s
->dpp_config_obj_override
);
2381 wpa_s
->dpp_config_obj_override
= NULL
;
2382 os_free(wpa_s
->dpp_discovery_override
);
2383 wpa_s
->dpp_discovery_override
= NULL
;
2384 os_free(wpa_s
->dpp_groups_override
);
2385 wpa_s
->dpp_groups_override
= NULL
;
2386 wpa_s
->dpp_ignore_netaccesskey_mismatch
= 0;
2387 #endif /* CONFIG_TESTING_OPTIONS */
2388 if (!wpa_s
->dpp_init_done
)
2390 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout
, wpa_s
, NULL
);
2391 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
2392 eloop_cancel_timeout(wpas_dpp_init_timeout
, wpa_s
, NULL
);
2393 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout
, wpa_s
, NULL
);
2394 offchannel_send_action_done(wpa_s
);
2395 wpas_dpp_listen_stop(wpa_s
);
2396 dpp_bootstrap_del(wpa_s
, 0);
2397 dpp_configurator_del(wpa_s
, 0);
2398 dpp_auth_deinit(wpa_s
->dpp_auth
);
2399 wpa_s
->dpp_auth
= NULL
;
2400 wpas_dpp_pkex_remove(wpa_s
, "*");
2401 wpa_s
->dpp_pkex
= NULL
;
2402 os_memset(wpa_s
->dpp_intro_bssid
, 0, ETH_ALEN
);
2403 os_free(wpa_s
->dpp_configurator_params
);
2404 wpa_s
->dpp_configurator_params
= NULL
;