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
);
39 static const u8 broadcast
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
41 /* Use a hardcoded Transaction ID 1 in Peer Discovery frames since there is only
42 * a single transaction in progress at any point in time. */
43 static const u8 TRANSACTION_ID
= 1;
46 static struct dpp_configurator
*
47 dpp_configurator_get_id(struct wpa_supplicant
*wpa_s
, unsigned int id
)
49 struct dpp_configurator
*conf
;
51 dl_list_for_each(conf
, &wpa_s
->dpp_configurator
,
52 struct dpp_configurator
, list
) {
60 static unsigned int wpas_dpp_next_id(struct wpa_supplicant
*wpa_s
)
62 struct dpp_bootstrap_info
*bi
;
63 unsigned int max_id
= 0;
65 dl_list_for_each(bi
, &wpa_s
->dpp_bootstrap
, struct dpp_bootstrap_info
,
75 * wpas_dpp_qr_code - Parse and add DPP bootstrapping info from a QR Code
76 * @wpa_s: Pointer to wpa_supplicant data
77 * @cmd: DPP URI read from a QR Code
78 * Returns: Identifier of the stored info or -1 on failure
80 int wpas_dpp_qr_code(struct wpa_supplicant
*wpa_s
, const char *cmd
)
82 struct dpp_bootstrap_info
*bi
;
83 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
85 bi
= dpp_parse_qr_code(cmd
);
89 bi
->id
= wpas_dpp_next_id(wpa_s
);
90 dl_list_add(&wpa_s
->dpp_bootstrap
, &bi
->list
);
92 if (auth
&& auth
->response_pending
&&
93 dpp_notify_new_qr_code(auth
, bi
) == 1) {
97 "DPP: Sending out pending authentication response");
98 msg
= dpp_alloc_msg(DPP_PA_AUTHENTICATION_RESP
,
99 wpabuf_len(auth
->resp_attr
));
102 wpabuf_put_buf(msg
, wpa_s
->dpp_auth
->resp_attr
);
104 offchannel_send_action(wpa_s
, auth
->curr_freq
,
105 auth
->peer_mac_addr
, wpa_s
->own_addr
,
107 wpabuf_head(msg
), wpabuf_len(msg
),
108 500, wpas_dpp_tx_status
, 0);
117 static char * get_param(const char *cmd
, const char *param
)
119 const char *pos
, *end
;
123 pos
= os_strstr(cmd
, param
);
127 pos
+= os_strlen(param
);
128 end
= os_strchr(pos
, ' ');
132 len
= os_strlen(pos
);
133 val
= os_malloc(len
+ 1);
136 os_memcpy(val
, pos
, len
);
142 int wpas_dpp_bootstrap_gen(struct wpa_supplicant
*wpa_s
, const char *cmd
)
144 char *chan
= NULL
, *mac
= NULL
, *info
= NULL
, *pk
= NULL
, *curve
= NULL
;
147 size_t privkey_len
= 0;
150 struct dpp_bootstrap_info
*bi
;
152 bi
= os_zalloc(sizeof(*bi
));
156 if (os_strstr(cmd
, "type=qrcode"))
157 bi
->type
= DPP_BOOTSTRAP_QR_CODE
;
158 else if (os_strstr(cmd
, "type=pkex"))
159 bi
->type
= DPP_BOOTSTRAP_PKEX
;
163 chan
= get_param(cmd
, " chan=");
164 mac
= get_param(cmd
, " mac=");
165 info
= get_param(cmd
, " info=");
166 curve
= get_param(cmd
, " curve=");
167 key
= get_param(cmd
, " key=");
170 privkey_len
= os_strlen(key
) / 2;
171 privkey
= os_malloc(privkey_len
);
173 hexstr2bin(key
, privkey
, privkey_len
) < 0)
177 pk
= dpp_keygen(bi
, curve
, privkey
, privkey_len
);
181 len
= 4; /* "DPP:" */
183 if (dpp_parse_uri_chan_list(bi
, chan
) < 0)
185 len
+= 3 + os_strlen(chan
); /* C:...; */
188 if (dpp_parse_uri_mac(bi
, mac
) < 0)
190 len
+= 3 + os_strlen(mac
); /* M:...; */
193 if (dpp_parse_uri_info(bi
, info
) < 0)
195 len
+= 3 + os_strlen(info
); /* I:...; */
197 len
+= 4 + os_strlen(pk
);
198 bi
->uri
= os_malloc(len
+ 1);
201 os_snprintf(bi
->uri
, len
+ 1, "DPP:%s%s%s%s%s%s%s%s%sK:%s;;",
202 chan
? "C:" : "", chan
? chan
: "", chan
? ";" : "",
203 mac
? "M:" : "", mac
? mac
: "", mac
? ";" : "",
204 info
? "I:" : "", info
? info
: "", info
? ";" : "",
206 bi
->id
= wpas_dpp_next_id(wpa_s
);
207 dl_list_add(&wpa_s
->dpp_bootstrap
, &bi
->list
);
217 bin_clear_free(privkey
, privkey_len
);
218 dpp_bootstrap_info_free(bi
);
223 static struct dpp_bootstrap_info
*
224 dpp_bootstrap_get_id(struct wpa_supplicant
*wpa_s
, unsigned int id
)
226 struct dpp_bootstrap_info
*bi
;
228 dl_list_for_each(bi
, &wpa_s
->dpp_bootstrap
, struct dpp_bootstrap_info
,
237 static int dpp_bootstrap_del(struct wpa_supplicant
*wpa_s
, unsigned int id
)
239 struct dpp_bootstrap_info
*bi
, *tmp
;
242 dl_list_for_each_safe(bi
, tmp
, &wpa_s
->dpp_bootstrap
,
243 struct dpp_bootstrap_info
, list
) {
244 if (id
&& bi
->id
!= id
)
247 dl_list_del(&bi
->list
);
248 dpp_bootstrap_info_free(bi
);
252 return 0; /* flush succeeds regardless of entries found */
253 return found
? 0 : -1;
257 int wpas_dpp_bootstrap_remove(struct wpa_supplicant
*wpa_s
, const char *id
)
261 if (os_strcmp(id
, "*") == 0) {
269 return dpp_bootstrap_del(wpa_s
, id_val
);
273 const char * wpas_dpp_bootstrap_get_uri(struct wpa_supplicant
*wpa_s
,
276 struct dpp_bootstrap_info
*bi
;
278 bi
= dpp_bootstrap_get_id(wpa_s
, id
);
285 int wpas_dpp_bootstrap_info(struct wpa_supplicant
*wpa_s
, int id
,
286 char *reply
, int reply_size
)
288 struct dpp_bootstrap_info
*bi
;
290 bi
= dpp_bootstrap_get_id(wpa_s
, id
);
293 return os_snprintf(reply
, reply_size
, "type=%s\n"
294 "mac_addr=" MACSTR
"\n"
298 dpp_bootstrap_type_txt(bi
->type
),
299 MAC2STR(bi
->mac_addr
),
300 bi
->info
? bi
->info
: "",
306 static void wpas_dpp_tx_status(struct wpa_supplicant
*wpa_s
,
307 unsigned int freq
, const u8
*dst
,
308 const u8
*src
, const u8
*bssid
,
309 const u8
*data
, size_t data_len
,
310 enum offchannel_send_action_result result
)
312 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
315 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
316 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
319 if (!wpa_s
->dpp_auth
) {
320 wpa_printf(MSG_DEBUG
,
321 "DPP: Ignore TX status since there is no ongoing authentication exchange");
325 if (wpa_s
->dpp_auth
->remove_on_tx_status
) {
326 wpa_printf(MSG_DEBUG
,
327 "DPP: Terminate authentication exchange due to an earlier error");
328 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
329 offchannel_send_action_done(wpa_s
);
330 dpp_auth_deinit(wpa_s
->dpp_auth
);
331 wpa_s
->dpp_auth
= NULL
;
335 if (wpa_s
->dpp_auth_ok_on_ack
)
336 wpas_dpp_auth_success(wpa_s
, 1);
338 if (!is_broadcast_ether_addr(dst
) &&
339 result
!= OFFCHANNEL_SEND_ACTION_SUCCESS
) {
340 wpa_printf(MSG_DEBUG
,
341 "DPP: Unicast DPP Action frame was not ACKed");
342 /* TODO: In case of DPP Authentication Request frame, move to
343 * the next channel immediately */
348 static void wpas_dpp_reply_wait_timeout(void *eloop_ctx
, void *timeout_ctx
)
350 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
352 if (!wpa_s
->dpp_auth
)
354 wpa_printf(MSG_DEBUG
, "DPP: Continue reply wait on channel %u MHz",
355 wpa_s
->dpp_auth
->curr_freq
);
356 wpas_dpp_listen_start(wpa_s
, wpa_s
->dpp_auth
->curr_freq
);
360 static void wpas_dpp_set_testing_options(struct wpa_supplicant
*wpa_s
,
361 struct dpp_authentication
*auth
)
363 #ifdef CONFIG_TESTING_OPTIONS
364 if (wpa_s
->dpp_config_obj_override
)
365 auth
->config_obj_override
=
366 os_strdup(wpa_s
->dpp_config_obj_override
);
367 if (wpa_s
->dpp_discovery_override
)
368 auth
->discovery_override
=
369 os_strdup(wpa_s
->dpp_discovery_override
);
370 if (wpa_s
->dpp_groups_override
)
371 auth
->groups_override
=
372 os_strdup(wpa_s
->dpp_groups_override
);
373 auth
->ignore_netaccesskey_mismatch
=
374 wpa_s
->dpp_ignore_netaccesskey_mismatch
;
375 #endif /* CONFIG_TESTING_OPTIONS */
379 static void wpas_dpp_set_configurator(struct wpa_supplicant
*wpa_s
,
380 struct dpp_authentication
*auth
,
383 const char *pos
, *end
;
384 struct dpp_configuration
*conf_sta
= NULL
, *conf_ap
= NULL
;
385 struct dpp_configurator
*conf
= NULL
;
386 u8 ssid
[32] = { "test" };
394 wpa_printf(MSG_DEBUG
, "DPP: Set configurator parameters: %s", cmd
);
395 pos
= os_strstr(cmd
, " ssid=");
398 end
= os_strchr(pos
, ' ');
399 ssid_len
= end
? (size_t) (end
- pos
) : os_strlen(pos
);
401 if (ssid_len
> sizeof(ssid
) ||
402 hexstr2bin(pos
, ssid
, ssid_len
) < 0)
406 pos
= os_strstr(cmd
, " pass=");
409 end
= os_strchr(pos
, ' ');
410 pass_len
= end
? (size_t) (end
- pos
) : os_strlen(pos
);
412 if (pass_len
> sizeof(pass
) - 1 || pass_len
< 8 ||
413 hexstr2bin(pos
, (u8
*) pass
, pass_len
) < 0)
417 if (os_strstr(cmd
, " conf=sta-")) {
418 conf_sta
= os_zalloc(sizeof(struct dpp_configuration
));
421 os_memcpy(conf_sta
->ssid
, ssid
, ssid_len
);
422 conf_sta
->ssid_len
= ssid_len
;
423 if (os_strstr(cmd
, " conf=sta-psk")) {
425 conf_sta
->passphrase
= os_strdup(pass
);
426 if (!conf_sta
->passphrase
)
428 } else if (os_strstr(cmd
, " conf=sta-dpp")) {
435 if (os_strstr(cmd
, " conf=ap-")) {
436 conf_ap
= os_zalloc(sizeof(struct dpp_configuration
));
439 os_memcpy(conf_ap
->ssid
, ssid
, ssid_len
);
440 conf_ap
->ssid_len
= ssid_len
;
441 if (os_strstr(cmd
, " conf=ap-psk")) {
443 conf_ap
->passphrase
= os_strdup(pass
);
444 if (!conf_ap
->passphrase
)
446 } else if (os_strstr(cmd
, " conf=ap-dpp")) {
453 pos
= os_strstr(cmd
, " expiry=");
458 val
= strtol(pos
, NULL
, 0);
462 conf_sta
->netaccesskey_expiry
= val
;
464 conf_ap
->netaccesskey_expiry
= val
;
467 pos
= os_strstr(cmd
, " configurator=");
470 conf
= dpp_configurator_get_id(wpa_s
, atoi(pos
));
473 "DPP: Could not find the specified configurator");
477 auth
->conf_sta
= conf_sta
;
478 auth
->conf_ap
= conf_ap
;
483 wpa_printf(MSG_DEBUG
, "DPP: Failed to set configurator parameters");
484 dpp_configuration_free(conf_sta
);
485 dpp_configuration_free(conf_ap
);
489 int wpas_dpp_auth_init(struct wpa_supplicant
*wpa_s
, const char *cmd
)
492 struct dpp_bootstrap_info
*peer_bi
, *own_bi
= NULL
;
496 int configurator
= 1;
497 unsigned int wait_time
;
499 wpa_s
->dpp_gas_client
= 0;
501 pos
= os_strstr(cmd
, " peer=");
505 peer_bi
= dpp_bootstrap_get_id(wpa_s
, atoi(pos
));
508 "DPP: Could not find bootstrapping info for the identified peer");
512 pos
= os_strstr(cmd
, " own=");
515 own_bi
= dpp_bootstrap_get_id(wpa_s
, atoi(pos
));
518 "DPP: Could not find bootstrapping info for the identified local entry");
522 if (peer_bi
->curve
!= own_bi
->curve
) {
524 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
525 peer_bi
->curve
->name
, own_bi
->curve
->name
);
530 pos
= os_strstr(cmd
, " role=");
533 if (os_strncmp(pos
, "configurator", 12) == 0)
535 else if (os_strncmp(pos
, "enrollee", 8) == 0)
541 pos
= os_strstr(cmd
, " netrole=");
544 wpa_s
->dpp_netrole_ap
= os_strncmp(pos
, "ap", 2) == 0;
547 if (wpa_s
->dpp_auth
) {
548 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
549 offchannel_send_action_done(wpa_s
);
550 dpp_auth_deinit(wpa_s
->dpp_auth
);
552 wpa_s
->dpp_auth
= dpp_auth_init(wpa_s
, peer_bi
, own_bi
, configurator
);
553 if (!wpa_s
->dpp_auth
)
555 wpas_dpp_set_testing_options(wpa_s
, wpa_s
->dpp_auth
);
556 wpas_dpp_set_configurator(wpa_s
, wpa_s
->dpp_auth
, cmd
);
558 /* TODO: Support iteration over all frequencies and filtering of
559 * frequencies based on locally enabled channels that allow initiation
560 * of transmission. */
561 if (peer_bi
->num_freq
> 0)
562 wpa_s
->dpp_auth
->curr_freq
= peer_bi
->freq
[0];
564 wpa_s
->dpp_auth
->curr_freq
= 2412;
566 msg
= dpp_alloc_msg(DPP_PA_AUTHENTICATION_REQ
,
567 wpabuf_len(wpa_s
->dpp_auth
->req_attr
));
570 wpabuf_put_buf(msg
, wpa_s
->dpp_auth
->req_attr
);
572 if (is_zero_ether_addr(peer_bi
->mac_addr
)) {
575 dst
= peer_bi
->mac_addr
;
576 os_memcpy(wpa_s
->dpp_auth
->peer_mac_addr
, peer_bi
->mac_addr
,
579 wpa_s
->dpp_auth_ok_on_ack
= 0;
580 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
581 wait_time
= wpa_s
->max_remain_on_chan
;
582 if (wait_time
> 2000)
584 eloop_register_timeout(wait_time
/ 1000, (wait_time
% 1000) * 1000,
585 wpas_dpp_reply_wait_timeout
,
587 res
= offchannel_send_action(wpa_s
, wpa_s
->dpp_auth
->curr_freq
,
588 dst
, wpa_s
->own_addr
, broadcast
,
589 wpabuf_head(msg
), wpabuf_len(msg
),
590 wait_time
, wpas_dpp_tx_status
, 0);
599 struct wpas_dpp_listen_work
{
601 unsigned int duration
;
602 struct wpabuf
*probe_resp_ie
;
606 static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work
*lwork
)
614 static void wpas_dpp_listen_work_done(struct wpa_supplicant
*wpa_s
)
616 struct wpas_dpp_listen_work
*lwork
;
618 if (!wpa_s
->dpp_listen_work
)
621 lwork
= wpa_s
->dpp_listen_work
->ctx
;
622 wpas_dpp_listen_work_free(lwork
);
623 radio_work_done(wpa_s
->dpp_listen_work
);
624 wpa_s
->dpp_listen_work
= NULL
;
628 static void dpp_start_listen_cb(struct wpa_radio_work
*work
, int deinit
)
630 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
631 struct wpas_dpp_listen_work
*lwork
= work
->ctx
;
635 wpa_s
->dpp_listen_work
= NULL
;
636 wpas_dpp_listen_stop(wpa_s
);
638 wpas_dpp_listen_work_free(lwork
);
642 wpa_s
->dpp_listen_work
= work
;
644 wpa_s
->dpp_pending_listen_freq
= lwork
->freq
;
646 if (wpa_drv_remain_on_channel(wpa_s
, lwork
->freq
,
647 wpa_s
->max_remain_on_chan
) < 0) {
648 wpa_printf(MSG_DEBUG
,
649 "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
651 wpas_dpp_listen_work_done(wpa_s
);
652 wpa_s
->dpp_pending_listen_freq
= 0;
655 wpa_s
->off_channel_freq
= 0;
656 wpa_s
->roc_waiting_drv_freq
= lwork
->freq
;
660 static int wpas_dpp_listen_start(struct wpa_supplicant
*wpa_s
,
663 struct wpas_dpp_listen_work
*lwork
;
665 if (wpa_s
->dpp_listen_work
) {
666 wpa_printf(MSG_DEBUG
,
667 "DPP: Reject start_listen since dpp_listen_work already exists");
671 if (wpa_s
->dpp_listen_freq
)
672 wpas_dpp_listen_stop(wpa_s
);
673 wpa_s
->dpp_listen_freq
= freq
;
675 lwork
= os_zalloc(sizeof(*lwork
));
680 if (radio_add_work(wpa_s
, freq
, "dpp-listen", 0, dpp_start_listen_cb
,
682 wpas_dpp_listen_work_free(lwork
);
690 int wpas_dpp_listen(struct wpa_supplicant
*wpa_s
, const char *cmd
)
698 if (os_strstr(cmd
, " role=configurator"))
699 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_CONFIGURATOR
;
700 else if (os_strstr(cmd
, " role=enrollee"))
701 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_ENROLLEE
;
703 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_CONFIGURATOR
|
705 wpa_s
->dpp_qr_mutual
= os_strstr(cmd
, " qr=mutual") != NULL
;
706 wpa_s
->dpp_netrole_ap
= os_strstr(cmd
, " netrole=ap") != NULL
;
707 if (wpa_s
->dpp_listen_freq
== (unsigned int) freq
) {
708 wpa_printf(MSG_DEBUG
, "DPP: Already listening on %u MHz",
713 return wpas_dpp_listen_start(wpa_s
, freq
);
717 void wpas_dpp_listen_stop(struct wpa_supplicant
*wpa_s
)
719 if (!wpa_s
->dpp_listen_freq
)
722 wpa_printf(MSG_DEBUG
, "DPP: Stop listen on %u MHz",
723 wpa_s
->dpp_listen_freq
);
724 wpa_drv_cancel_remain_on_channel(wpa_s
);
725 wpa_s
->dpp_listen_freq
= 0;
726 wpas_dpp_listen_work_done(wpa_s
);
730 void wpas_dpp_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
733 if (!wpa_s
->dpp_listen_freq
&& !wpa_s
->dpp_pending_listen_freq
)
736 wpa_printf(MSG_DEBUG
,
737 "DPP: remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d roc_waiting_drv_freq=%d freq=%u)",
738 wpa_s
->off_channel_freq
, wpa_s
->dpp_pending_listen_freq
,
739 wpa_s
->roc_waiting_drv_freq
, freq
);
740 if (wpa_s
->off_channel_freq
&&
741 wpa_s
->off_channel_freq
== wpa_s
->dpp_pending_listen_freq
) {
742 wpa_printf(MSG_DEBUG
, "DPP: Listen on %u MHz started", freq
);
743 wpa_s
->dpp_pending_listen_freq
= 0;
745 wpa_printf(MSG_DEBUG
,
746 "DPP: Ignore remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d freq=%u)",
747 wpa_s
->off_channel_freq
,
748 wpa_s
->dpp_pending_listen_freq
, freq
);
753 void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
756 wpas_dpp_listen_work_done(wpa_s
);
758 if (wpa_s
->dpp_auth
&& !wpa_s
->dpp_gas_client
) {
759 /* Continue listen with a new remain-on-channel */
760 wpa_printf(MSG_DEBUG
,
761 "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
762 wpa_s
->dpp_auth
->curr_freq
);
763 wpas_dpp_listen_start(wpa_s
, wpa_s
->dpp_auth
->curr_freq
);
767 if (wpa_s
->dpp_listen_freq
) {
768 /* Continue listen with a new remain-on-channel */
769 wpas_dpp_listen_start(wpa_s
, wpa_s
->dpp_listen_freq
);
774 static void wpas_dpp_rx_auth_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
775 const u8
*buf
, size_t len
, unsigned int freq
)
777 const u8
*r_bootstrap
, *i_bootstrap
, *wrapped_data
;
778 u16 r_bootstrap_len
, i_bootstrap_len
, wrapped_data_len
;
779 struct dpp_bootstrap_info
*bi
, *own_bi
= NULL
, *peer_bi
= NULL
;
782 wpa_printf(MSG_DEBUG
, "DPP: Authentication Request from " MACSTR
,
785 wrapped_data
= dpp_get_attr(buf
, len
, DPP_ATTR_WRAPPED_DATA
,
788 wpa_printf(MSG_DEBUG
,
789 "DPP: Missing required Wrapped data attribute");
792 wpa_hexdump(MSG_MSGDUMP
, "DPP: Wrapped data",
793 wrapped_data
, wrapped_data_len
);
795 r_bootstrap
= dpp_get_attr(buf
, len
, DPP_ATTR_R_BOOTSTRAP_KEY_HASH
,
797 if (!r_bootstrap
|| r_bootstrap
> wrapped_data
||
798 r_bootstrap_len
!= SHA256_MAC_LEN
) {
799 wpa_printf(MSG_DEBUG
,
800 "DPP: Missing or invalid required Responder Bootstrapping Key Hash attribute");
803 wpa_hexdump(MSG_MSGDUMP
, "DPP: Responder Bootstrapping Key Hash",
804 r_bootstrap
, r_bootstrap_len
);
806 i_bootstrap
= dpp_get_attr(buf
, len
, DPP_ATTR_I_BOOTSTRAP_KEY_HASH
,
808 if (!i_bootstrap
|| i_bootstrap
> wrapped_data
||
809 i_bootstrap_len
!= SHA256_MAC_LEN
) {
810 wpa_printf(MSG_DEBUG
,
811 "DPP: Missing or invalid required Initiator Bootstrapping Key Hash attribute");
814 wpa_hexdump(MSG_MSGDUMP
, "DPP: Initiator Bootstrapping Key Hash",
815 i_bootstrap
, i_bootstrap_len
);
817 /* Try to find own and peer bootstrapping key matches based on the
818 * received hash values */
819 dl_list_for_each(bi
, &wpa_s
->dpp_bootstrap
, struct dpp_bootstrap_info
,
821 if (!own_bi
&& bi
->own
&&
822 os_memcmp(bi
->pubkey_hash
, r_bootstrap
,
823 SHA256_MAC_LEN
) == 0) {
824 wpa_printf(MSG_DEBUG
,
825 "DPP: Found matching own bootstrapping information");
829 if (!peer_bi
&& !bi
->own
&&
830 os_memcmp(bi
->pubkey_hash
, i_bootstrap
,
831 SHA256_MAC_LEN
) == 0) {
832 wpa_printf(MSG_DEBUG
,
833 "DPP: Found matching peer bootstrapping information");
837 if (own_bi
&& peer_bi
)
842 wpa_printf(MSG_DEBUG
,
843 "DPP: No matching own bootstrapping key found - ignore message");
847 if (wpa_s
->dpp_auth
) {
848 wpa_printf(MSG_DEBUG
,
849 "DPP: Already in DPP authentication exchange - ignore new one");
853 wpa_s
->dpp_gas_client
= 0;
854 wpa_s
->dpp_auth_ok_on_ack
= 0;
855 wpa_s
->dpp_auth
= dpp_auth_req_rx(wpa_s
, wpa_s
->dpp_allowed_roles
,
856 wpa_s
->dpp_qr_mutual
,
857 peer_bi
, own_bi
, freq
, buf
,
858 wrapped_data
, wrapped_data_len
);
859 if (!wpa_s
->dpp_auth
) {
860 wpa_printf(MSG_DEBUG
, "DPP: No response generated");
863 wpas_dpp_set_testing_options(wpa_s
, wpa_s
->dpp_auth
);
864 wpas_dpp_set_configurator(wpa_s
, wpa_s
->dpp_auth
,
865 wpa_s
->dpp_configurator_params
);
866 os_memcpy(wpa_s
->dpp_auth
->peer_mac_addr
, src
, ETH_ALEN
);
868 msg
= dpp_alloc_msg(DPP_PA_AUTHENTICATION_RESP
,
869 wpabuf_len(wpa_s
->dpp_auth
->resp_attr
));
872 wpabuf_put_buf(msg
, wpa_s
->dpp_auth
->resp_attr
);
874 offchannel_send_action(wpa_s
, wpa_s
->dpp_auth
->curr_freq
,
875 src
, wpa_s
->own_addr
, broadcast
,
876 wpabuf_head(msg
), wpabuf_len(msg
),
877 500, wpas_dpp_tx_status
, 0);
882 static void wpas_dpp_start_gas_server(struct wpa_supplicant
*wpa_s
)
884 /* TODO: stop wait and start ROC */
888 static struct wpa_ssid
* wpas_dpp_add_network(struct wpa_supplicant
*wpa_s
,
889 struct dpp_authentication
*auth
)
891 struct wpa_ssid
*ssid
;
893 ssid
= wpa_config_add_network(wpa_s
->conf
);
896 wpas_notify_network_added(wpa_s
, ssid
);
897 wpa_config_set_network_defaults(ssid
);
900 ssid
->ssid
= os_malloc(auth
->ssid_len
);
903 os_memcpy(ssid
->ssid
, auth
->ssid
, auth
->ssid_len
);
904 ssid
->ssid_len
= auth
->ssid_len
;
906 if (auth
->connector
) {
907 ssid
->key_mgmt
= WPA_KEY_MGMT_DPP
;
908 ssid
->dpp_connector
= os_strdup(auth
->connector
);
909 if (!ssid
->dpp_connector
)
913 if (auth
->c_sign_key
) {
914 ssid
->dpp_csign
= os_malloc(wpabuf_len(auth
->c_sign_key
));
915 if (!ssid
->dpp_csign
)
917 os_memcpy(ssid
->dpp_csign
, wpabuf_head(auth
->c_sign_key
),
918 wpabuf_len(auth
->c_sign_key
));
919 ssid
->dpp_csign_len
= wpabuf_len(auth
->c_sign_key
);
920 ssid
->dpp_csign_expiry
= auth
->c_sign_key_expiry
;
923 if (auth
->net_access_key
) {
924 ssid
->dpp_netaccesskey
=
925 os_malloc(wpabuf_len(auth
->net_access_key
));
926 if (!ssid
->dpp_netaccesskey
)
928 os_memcpy(ssid
->dpp_netaccesskey
,
929 wpabuf_head(auth
->net_access_key
),
930 wpabuf_len(auth
->net_access_key
));
931 ssid
->dpp_netaccesskey_len
= wpabuf_len(auth
->net_access_key
);
932 ssid
->dpp_netaccesskey_expiry
= auth
->net_access_key_expiry
;
935 if (!auth
->connector
) {
936 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
937 if (auth
->passphrase
[0]) {
938 if (wpa_config_set_quoted(ssid
, "psk",
939 auth
->passphrase
) < 0)
941 wpa_config_update_psk(ssid
);
942 ssid
->export_keys
= 1;
944 ssid
->psk_set
= auth
->psk_set
;
945 os_memcpy(ssid
->psk
, auth
->psk
, PMK_LEN
);
951 wpas_notify_network_removed(wpa_s
, ssid
);
952 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
957 static void wpas_dpp_process_config(struct wpa_supplicant
*wpa_s
,
958 struct dpp_authentication
*auth
)
960 struct wpa_ssid
*ssid
;
962 if (wpa_s
->conf
->dpp_config_processing
< 1)
965 ssid
= wpas_dpp_add_network(wpa_s
, auth
);
969 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_NETWORK_ID
"%d", ssid
->id
);
970 if (wpa_s
->conf
->dpp_config_processing
< 2)
973 wpa_printf(MSG_DEBUG
, "DPP: Trying to connect to the new network");
975 wpa_s
->disconnected
= 0;
976 wpa_s
->reassociate
= 1;
977 wpa_s
->scan_runs
= 0;
978 wpa_s
->normal_scans
= 0;
979 wpa_supplicant_cancel_sched_scan(wpa_s
);
980 wpa_supplicant_req_scan(wpa_s
, 0, 0);
984 static void wpas_dpp_handle_config_obj(struct wpa_supplicant
*wpa_s
,
985 struct dpp_authentication
*auth
)
987 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_RECEIVED
);
989 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONFOBJ_SSID
"%s",
990 wpa_ssid_txt(auth
->ssid
, auth
->ssid_len
));
991 if (auth
->connector
) {
992 /* TODO: Save the Connector and consider using a command
993 * to fetch the value instead of sending an event with
994 * it. The Connector could end up being larger than what
995 * most clients are ready to receive as an event
997 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONNECTOR
"%s",
1000 if (auth
->c_sign_key
) {
1004 hexlen
= 2 * wpabuf_len(auth
->c_sign_key
) + 1;
1005 hex
= os_malloc(hexlen
);
1007 wpa_snprintf_hex(hex
, hexlen
,
1008 wpabuf_head(auth
->c_sign_key
),
1009 wpabuf_len(auth
->c_sign_key
));
1010 if (auth
->c_sign_key_expiry
)
1011 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_C_SIGN_KEY
1014 auth
->c_sign_key_expiry
);
1016 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_C_SIGN_KEY
1021 if (auth
->net_access_key
) {
1025 hexlen
= 2 * wpabuf_len(auth
->net_access_key
) + 1;
1026 hex
= os_malloc(hexlen
);
1028 wpa_snprintf_hex(hex
, hexlen
,
1029 wpabuf_head(auth
->net_access_key
),
1030 wpabuf_len(auth
->net_access_key
));
1031 if (auth
->net_access_key_expiry
)
1032 wpa_msg(wpa_s
, MSG_INFO
,
1033 DPP_EVENT_NET_ACCESS_KEY
"%s %lu", hex
,
1035 auth
->net_access_key_expiry
);
1037 wpa_msg(wpa_s
, MSG_INFO
,
1038 DPP_EVENT_NET_ACCESS_KEY
"%s", hex
);
1043 wpas_dpp_process_config(wpa_s
, auth
);
1047 static void wpas_dpp_gas_resp_cb(void *ctx
, const u8
*addr
, u8 dialog_token
,
1048 enum gas_query_result result
,
1049 const struct wpabuf
*adv_proto
,
1050 const struct wpabuf
*resp
, u16 status_code
)
1052 struct wpa_supplicant
*wpa_s
= ctx
;
1054 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1056 if (!auth
|| !auth
->auth_success
) {
1057 wpa_printf(MSG_DEBUG
, "DPP: No matching exchange in progress");
1060 if (!resp
|| status_code
!= WLAN_STATUS_SUCCESS
) {
1061 wpa_printf(MSG_DEBUG
, "DPP: GAS query did not succeed");
1065 wpa_hexdump_buf(MSG_DEBUG
, "DPP: Configuration Response adv_proto",
1067 wpa_hexdump_buf(MSG_DEBUG
, "DPP: Configuration Response (GAS response)",
1070 if (wpabuf_len(adv_proto
) != 10 ||
1071 !(pos
= wpabuf_head(adv_proto
)) ||
1072 pos
[0] != WLAN_EID_ADV_PROTO
||
1074 pos
[3] != WLAN_EID_VENDOR_SPECIFIC
||
1076 WPA_GET_BE24(&pos
[5]) != OUI_WFA
||
1079 wpa_printf(MSG_DEBUG
,
1080 "DPP: Not a DPP Advertisement Protocol ID");
1084 if (dpp_conf_resp_rx(auth
, resp
) < 0) {
1085 wpa_printf(MSG_DEBUG
, "DPP: Configuration attempt failed");
1089 wpas_dpp_handle_config_obj(wpa_s
, auth
);
1090 dpp_auth_deinit(wpa_s
->dpp_auth
);
1091 wpa_s
->dpp_auth
= NULL
;
1095 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1096 dpp_auth_deinit(wpa_s
->dpp_auth
);
1097 wpa_s
->dpp_auth
= NULL
;
1101 static void wpas_dpp_start_gas_client(struct wpa_supplicant
*wpa_s
)
1103 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1104 struct wpabuf
*buf
, *conf_req
;
1108 wpa_s
->dpp_gas_client
= 1;
1109 os_snprintf(json
, sizeof(json
),
1110 "{\"name\":\"Test\","
1111 "\"wi-fi_tech\":\"infra\","
1112 "\"netRole\":\"%s\"}",
1113 wpa_s
->dpp_netrole_ap
? "ap" : "sta");
1114 wpa_printf(MSG_DEBUG
, "DPP: GAS Config Attributes: %s", json
);
1116 offchannel_send_action_done(wpa_s
);
1117 wpas_dpp_listen_stop(wpa_s
);
1119 conf_req
= dpp_build_conf_req(auth
, json
);
1121 wpa_printf(MSG_DEBUG
,
1122 "DPP: No configuration request data available");
1126 buf
= gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req
));
1128 wpabuf_free(conf_req
);
1132 /* Advertisement Protocol IE */
1133 wpabuf_put_u8(buf
, WLAN_EID_ADV_PROTO
);
1134 wpabuf_put_u8(buf
, 8); /* Length */
1135 wpabuf_put_u8(buf
, 0x7f);
1136 wpabuf_put_u8(buf
, WLAN_EID_VENDOR_SPECIFIC
);
1137 wpabuf_put_u8(buf
, 5);
1138 wpabuf_put_be24(buf
, OUI_WFA
);
1139 wpabuf_put_u8(buf
, DPP_OUI_TYPE
);
1140 wpabuf_put_u8(buf
, 0x01);
1143 wpabuf_put_le16(buf
, wpabuf_len(conf_req
));
1144 wpabuf_put_buf(buf
, conf_req
);
1145 wpabuf_free(conf_req
);
1147 wpa_printf(MSG_DEBUG
, "DPP: GAS request to " MACSTR
" (freq %u MHz)",
1148 MAC2STR(auth
->peer_mac_addr
), auth
->curr_freq
);
1150 res
= gas_query_req(wpa_s
->gas
, auth
->peer_mac_addr
, auth
->curr_freq
,
1151 buf
, wpas_dpp_gas_resp_cb
, wpa_s
);
1153 wpa_msg(wpa_s
, MSG_DEBUG
, "GAS: Failed to send Query Request");
1156 wpa_printf(MSG_DEBUG
,
1157 "DPP: GAS query started with dialog token %u", res
);
1162 static void wpas_dpp_auth_success(struct wpa_supplicant
*wpa_s
, int initiator
)
1164 wpa_printf(MSG_DEBUG
, "DPP: Authentication succeeded");
1165 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_AUTH_SUCCESS
"init=%d", initiator
);
1167 if (wpa_s
->dpp_auth
->configurator
)
1168 wpas_dpp_start_gas_server(wpa_s
);
1170 wpas_dpp_start_gas_client(wpa_s
);
1174 static void wpas_dpp_rx_auth_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1175 const u8
*buf
, size_t len
)
1177 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1178 struct wpabuf
*msg
, *attr
;
1180 wpa_printf(MSG_DEBUG
, "DPP: Authentication Response from " MACSTR
,
1184 wpa_printf(MSG_DEBUG
,
1185 "DPP: No DPP Authentication in progress - drop");
1189 if (!is_zero_ether_addr(auth
->peer_mac_addr
) &&
1190 os_memcmp(src
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1191 wpa_printf(MSG_DEBUG
, "DPP: MAC address mismatch (expected "
1192 MACSTR
") - drop", MAC2STR(auth
->peer_mac_addr
));
1196 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
1198 attr
= dpp_auth_resp_rx(auth
, buf
, len
);
1200 if (auth
->auth_resp_status
== DPP_STATUS_RESPONSE_PENDING
) {
1201 wpa_printf(MSG_DEBUG
,
1202 "DPP: Start wait for full response");
1203 offchannel_send_action_done(wpa_s
);
1204 wpas_dpp_listen_start(wpa_s
, auth
->curr_freq
);
1207 wpa_printf(MSG_DEBUG
, "DPP: No confirm generated");
1210 os_memcpy(auth
->peer_mac_addr
, src
, ETH_ALEN
);
1212 msg
= dpp_alloc_msg(DPP_PA_AUTHENTICATION_CONF
, wpabuf_len(attr
));
1217 wpabuf_put_buf(msg
, attr
);
1220 offchannel_send_action(wpa_s
, auth
->curr_freq
,
1221 src
, wpa_s
->own_addr
, broadcast
,
1222 wpabuf_head(msg
), wpabuf_len(msg
),
1223 500, wpas_dpp_tx_status
, 0);
1225 wpa_s
->dpp_auth_ok_on_ack
= 1;
1229 static void wpas_dpp_rx_auth_conf(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1230 const u8
*buf
, size_t len
)
1232 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1234 wpa_printf(MSG_DEBUG
, "DPP: Authentication Confirmation from " MACSTR
,
1238 wpa_printf(MSG_DEBUG
,
1239 "DPP: No DPP Authentication in progress - drop");
1243 if (os_memcmp(src
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1244 wpa_printf(MSG_DEBUG
, "DPP: MAC address mismatch (expected "
1245 MACSTR
") - drop", MAC2STR(auth
->peer_mac_addr
));
1249 if (dpp_auth_conf_rx(auth
, buf
, len
) < 0) {
1250 wpa_printf(MSG_DEBUG
, "DPP: Authentication failed");
1254 wpas_dpp_auth_success(wpa_s
, 0);
1258 static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant
*wpa_s
,
1260 const u8
*buf
, size_t len
)
1262 struct wpa_ssid
*ssid
;
1263 const u8
*connector
, *trans_id
;
1264 u16 connector_len
, trans_id_len
;
1265 struct dpp_introduction intro
;
1266 struct rsn_pmksa_cache_entry
*entry
;
1268 struct os_reltime rnow
;
1270 unsigned int seconds
;
1272 wpa_printf(MSG_DEBUG
, "DPP: Peer Discovery Response from " MACSTR
,
1274 if (is_zero_ether_addr(wpa_s
->dpp_intro_bssid
) ||
1275 os_memcmp(src
, wpa_s
->dpp_intro_bssid
, ETH_ALEN
) != 0) {
1276 wpa_printf(MSG_DEBUG
, "DPP: Not waiting for response from "
1277 MACSTR
" - drop", MAC2STR(src
));
1280 offchannel_send_action_done(wpa_s
);
1282 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1283 if (ssid
== wpa_s
->dpp_intro_network
)
1286 if (!ssid
|| !ssid
->dpp_connector
|| !ssid
->dpp_netaccesskey
||
1288 wpa_printf(MSG_DEBUG
,
1289 "DPP: Profile not found for network introduction");
1293 trans_id
= dpp_get_attr(buf
, len
, DPP_ATTR_TRANSACTION_ID
,
1295 if (!trans_id
|| trans_id_len
!= 1) {
1296 wpa_printf(MSG_DEBUG
,
1297 "DPP: Peer did not include Transaction ID");
1300 if (trans_id
[0] != TRANSACTION_ID
) {
1301 wpa_printf(MSG_DEBUG
,
1302 "DPP: Ignore frame with unexpected Transaction ID %u",
1307 connector
= dpp_get_attr(buf
, len
, DPP_ATTR_CONNECTOR
, &connector_len
);
1309 wpa_printf(MSG_DEBUG
,
1310 "DPP: Peer did not include its Connector");
1314 if (dpp_peer_intro(&intro
, ssid
->dpp_connector
,
1315 ssid
->dpp_netaccesskey
,
1316 ssid
->dpp_netaccesskey_len
,
1318 ssid
->dpp_csign_len
,
1319 connector
, connector_len
, &expiry
) < 0) {
1320 wpa_printf(MSG_INFO
,
1321 "DPP: Network Introduction protocol resulted in failure");
1325 entry
= os_zalloc(sizeof(*entry
));
1328 os_memcpy(entry
->aa
, src
, ETH_ALEN
);
1329 os_memcpy(entry
->pmkid
, intro
.pmkid
, PMKID_LEN
);
1330 os_memcpy(entry
->pmk
, intro
.pmk
, intro
.pmk_len
);
1331 entry
->pmk_len
= intro
.pmk_len
;
1332 entry
->akmp
= WPA_KEY_MGMT_DPP
;
1333 if (!expiry
|| expiry
> ssid
->dpp_csign_expiry
)
1334 expiry
= ssid
->dpp_csign_expiry
;
1337 seconds
= expiry
- now
.sec
;
1339 seconds
= 86400 * 7;
1341 os_get_reltime(&rnow
);
1342 entry
->expiration
= rnow
.sec
+ seconds
;
1343 entry
->reauth_time
= rnow
.sec
+ seconds
;
1344 entry
->network_ctx
= ssid
;
1345 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
1347 wpa_printf(MSG_DEBUG
,
1348 "DPP: Try connection again after successful network introduction");
1349 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
1350 wpa_supplicant_cancel_sched_scan(wpa_s
);
1351 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1354 os_memset(&intro
, 0, sizeof(intro
));
1359 wpas_dpp_tx_pkex_status(struct wpa_supplicant
*wpa_s
,
1360 unsigned int freq
, const u8
*dst
,
1361 const u8
*src
, const u8
*bssid
,
1362 const u8
*data
, size_t data_len
,
1363 enum offchannel_send_action_result result
)
1365 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
1366 " result=%s (PKEX)",
1368 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
1369 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
1371 /* TODO: Time out wait for response more quickly in error cases? */
1376 wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1377 const u8
*buf
, size_t len
, unsigned int freq
)
1380 unsigned int wait_time
;
1382 wpa_printf(MSG_DEBUG
, "DPP: PKEX Exchange Request from " MACSTR
,
1385 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1388 if (!wpa_s
->dpp_pkex_code
|| !wpa_s
->dpp_pkex_bi
) {
1389 wpa_printf(MSG_DEBUG
,
1390 "DPP: No PKEX code configured - ignore request");
1394 if (wpa_s
->dpp_pkex
) {
1395 /* TODO: Support parallel operations */
1396 wpa_printf(MSG_DEBUG
,
1397 "DPP: Already in PKEX session - ignore new request");
1401 wpa_s
->dpp_pkex
= dpp_pkex_rx_exchange_req(wpa_s
->dpp_pkex_bi
,
1402 wpa_s
->own_addr
, src
,
1403 wpa_s
->dpp_pkex_identifier
,
1404 wpa_s
->dpp_pkex_code
,
1406 if (!wpa_s
->dpp_pkex
) {
1407 wpa_printf(MSG_DEBUG
,
1408 "DPP: Failed to process the request - ignore it");
1412 msg
= wpa_s
->dpp_pkex
->exchange_resp
;
1413 wait_time
= wpa_s
->max_remain_on_chan
;
1414 if (wait_time
> 2000)
1416 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
1418 wpabuf_head(msg
), wpabuf_len(msg
),
1419 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1424 wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1425 const u8
*buf
, size_t len
, unsigned int freq
)
1428 unsigned int wait_time
;
1430 wpa_printf(MSG_DEBUG
, "DPP: PKEX Exchange Response from " MACSTR
,
1433 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1436 if (!wpa_s
->dpp_pkex
|| !wpa_s
->dpp_pkex
->initiator
||
1437 wpa_s
->dpp_pkex
->exchange_done
) {
1438 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
1442 os_memcpy(wpa_s
->dpp_pkex
->peer_mac
, src
, ETH_ALEN
);
1443 msg
= dpp_pkex_rx_exchange_resp(wpa_s
->dpp_pkex
, buf
, len
);
1445 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the response");
1449 wpa_printf(MSG_DEBUG
, "DPP: Send PKEX Commit-Reveal Request to " MACSTR
,
1452 wait_time
= wpa_s
->max_remain_on_chan
;
1453 if (wait_time
> 2000)
1455 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
1457 wpabuf_head(msg
), wpabuf_len(msg
),
1458 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1464 wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1465 const u8
*buf
, size_t len
, unsigned int freq
)
1468 unsigned int wait_time
;
1469 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1470 struct dpp_bootstrap_info
*bi
;
1472 wpa_printf(MSG_DEBUG
, "DPP: PKEX Commit-Reveal Request from " MACSTR
,
1475 if (!pkex
|| pkex
->initiator
|| !pkex
->exchange_done
) {
1476 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
1480 msg
= dpp_pkex_rx_commit_reveal_req(pkex
, buf
, len
);
1482 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the request");
1486 wpa_printf(MSG_DEBUG
, "DPP: Send PKEX Commit-Reveal Response to "
1487 MACSTR
, MAC2STR(src
));
1489 wait_time
= wpa_s
->max_remain_on_chan
;
1490 if (wait_time
> 2000)
1492 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
1494 wpabuf_head(msg
), wpabuf_len(msg
),
1495 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1498 bi
= os_zalloc(sizeof(*bi
));
1501 bi
->id
= wpas_dpp_next_id(wpa_s
);
1502 bi
->type
= DPP_BOOTSTRAP_PKEX
;
1503 os_memcpy(bi
->mac_addr
, src
, ETH_ALEN
);
1506 bi
->curve
= pkex
->own_bi
->curve
;
1507 bi
->pubkey
= pkex
->peer_bootstrap_key
;
1508 pkex
->peer_bootstrap_key
= NULL
;
1509 dpp_pkex_free(pkex
);
1510 wpa_s
->dpp_pkex
= NULL
;
1511 if (dpp_bootstrap_key_hash(bi
) < 0) {
1512 dpp_bootstrap_info_free(bi
);
1515 dl_list_add(&wpa_s
->dpp_bootstrap
, &bi
->list
);
1520 wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1521 const u8
*buf
, size_t len
,
1525 struct dpp_bootstrap_info
*bi
, *own_bi
;
1526 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1529 wpa_printf(MSG_DEBUG
, "DPP: PKEX Commit-Reveal Response from " MACSTR
,
1532 if (!pkex
|| !pkex
->initiator
|| !pkex
->exchange_done
) {
1533 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
1537 res
= dpp_pkex_rx_commit_reveal_resp(pkex
, buf
, len
);
1539 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the response");
1543 own_bi
= pkex
->own_bi
;
1545 bi
= os_zalloc(sizeof(*bi
));
1548 bi
->id
= wpas_dpp_next_id(wpa_s
);
1549 bi
->type
= DPP_BOOTSTRAP_PKEX
;
1550 os_memcpy(bi
->mac_addr
, src
, ETH_ALEN
);
1553 bi
->curve
= own_bi
->curve
;
1554 bi
->pubkey
= pkex
->peer_bootstrap_key
;
1555 pkex
->peer_bootstrap_key
= NULL
;
1556 dpp_pkex_free(pkex
);
1557 wpa_s
->dpp_pkex
= NULL
;
1558 if (dpp_bootstrap_key_hash(bi
) < 0) {
1559 dpp_bootstrap_info_free(bi
);
1562 dl_list_add(&wpa_s
->dpp_bootstrap
, &bi
->list
);
1564 os_snprintf(cmd
, sizeof(cmd
), " peer=%u %s",
1566 wpa_s
->dpp_pkex_auth_cmd
? wpa_s
->dpp_pkex_auth_cmd
: "");
1567 wpa_printf(MSG_DEBUG
,
1568 "DPP: Start authentication after PKEX with parameters: %s",
1570 if (wpas_dpp_auth_init(wpa_s
, cmd
) < 0) {
1571 wpa_printf(MSG_DEBUG
,
1572 "DPP: Authentication initialization failed");
1578 void wpas_dpp_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1579 const u8
*buf
, size_t len
, unsigned int freq
)
1581 enum dpp_public_action_frame_type type
;
1589 wpa_printf(MSG_DEBUG
,
1590 "DPP: Received DPP Public Action frame type %d from "
1592 type
, MAC2STR(src
), freq
);
1593 wpa_hexdump(MSG_MSGDUMP
, "DPP: Received message attributes", buf
, len
);
1594 if (dpp_check_attrs(buf
, len
) < 0)
1598 case DPP_PA_AUTHENTICATION_REQ
:
1599 wpas_dpp_rx_auth_req(wpa_s
, src
, buf
, len
, freq
);
1601 case DPP_PA_AUTHENTICATION_RESP
:
1602 wpas_dpp_rx_auth_resp(wpa_s
, src
, buf
, len
);
1604 case DPP_PA_AUTHENTICATION_CONF
:
1605 wpas_dpp_rx_auth_conf(wpa_s
, src
, buf
, len
);
1607 case DPP_PA_PEER_DISCOVERY_RESP
:
1608 wpas_dpp_rx_peer_disc_resp(wpa_s
, src
, buf
, len
);
1610 case DPP_PA_PKEX_EXCHANGE_REQ
:
1611 wpas_dpp_rx_pkex_exchange_req(wpa_s
, src
, buf
, len
, freq
);
1613 case DPP_PA_PKEX_EXCHANGE_RESP
:
1614 wpas_dpp_rx_pkex_exchange_resp(wpa_s
, src
, buf
, len
, freq
);
1616 case DPP_PA_PKEX_COMMIT_REVEAL_REQ
:
1617 wpas_dpp_rx_pkex_commit_reveal_req(wpa_s
, src
, buf
, len
, freq
);
1619 case DPP_PA_PKEX_COMMIT_REVEAL_RESP
:
1620 wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s
, src
, buf
, len
, freq
);
1623 wpa_printf(MSG_DEBUG
,
1624 "DPP: Ignored unsupported frame subtype %d", type
);
1630 static struct wpabuf
*
1631 wpas_dpp_gas_req_handler(void *ctx
, const u8
*sa
, const u8
*query
,
1634 struct wpa_supplicant
*wpa_s
= ctx
;
1635 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1636 struct wpabuf
*resp
;
1638 wpa_printf(MSG_DEBUG
, "DPP: GAS request from " MACSTR
,
1640 if (!auth
|| !auth
->auth_success
||
1641 os_memcmp(sa
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1642 wpa_printf(MSG_DEBUG
, "DPP: No matching exchange in progress");
1645 wpa_hexdump(MSG_DEBUG
,
1646 "DPP: Received Configuration Request (GAS Query Request)",
1648 resp
= dpp_conf_req_rx(auth
, query
, query_len
);
1650 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1656 wpas_dpp_gas_status_handler(void *ctx
, struct wpabuf
*resp
, int ok
)
1658 struct wpa_supplicant
*wpa_s
= ctx
;
1659 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1666 wpa_printf(MSG_DEBUG
, "DPP: Configuration exchange completed (ok=%d)",
1668 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
1669 offchannel_send_action_done(wpa_s
);
1670 wpas_dpp_listen_stop(wpa_s
);
1672 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_SENT
);
1674 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1675 dpp_auth_deinit(wpa_s
->dpp_auth
);
1676 wpa_s
->dpp_auth
= NULL
;
1681 static unsigned int wpas_dpp_next_configurator_id(struct wpa_supplicant
*wpa_s
)
1683 struct dpp_configurator
*conf
;
1684 unsigned int max_id
= 0;
1686 dl_list_for_each(conf
, &wpa_s
->dpp_configurator
,
1687 struct dpp_configurator
, list
) {
1688 if (conf
->id
> max_id
)
1695 int wpas_dpp_configurator_add(struct wpa_supplicant
*wpa_s
, const char *cmd
)
1697 char *expiry
= NULL
, *curve
= NULL
;
1700 size_t privkey_len
= 0;
1702 struct dpp_configurator
*conf
= NULL
;
1704 expiry
= get_param(cmd
, " expiry=");
1705 curve
= get_param(cmd
, " curve=");
1706 key
= get_param(cmd
, " key=");
1709 privkey_len
= os_strlen(key
) / 2;
1710 privkey
= os_malloc(privkey_len
);
1712 hexstr2bin(key
, privkey
, privkey_len
) < 0)
1716 conf
= dpp_keygen_configurator(curve
, privkey
, privkey_len
);
1723 val
= strtol(expiry
, NULL
, 0);
1726 conf
->csign_expiry
= val
;
1729 conf
->id
= wpas_dpp_next_configurator_id(wpa_s
);
1730 dl_list_add(&wpa_s
->dpp_configurator
, &conf
->list
);
1736 str_clear_free(key
);
1737 bin_clear_free(privkey
, privkey_len
);
1738 dpp_configurator_free(conf
);
1743 static int dpp_configurator_del(struct wpa_supplicant
*wpa_s
, unsigned int id
)
1745 struct dpp_configurator
*conf
, *tmp
;
1748 dl_list_for_each_safe(conf
, tmp
, &wpa_s
->dpp_configurator
,
1749 struct dpp_configurator
, list
) {
1750 if (id
&& conf
->id
!= id
)
1753 dl_list_del(&conf
->list
);
1754 dpp_configurator_free(conf
);
1758 return 0; /* flush succeeds regardless of entries found */
1759 return found
? 0 : -1;
1763 int wpas_dpp_configurator_remove(struct wpa_supplicant
*wpa_s
, const char *id
)
1765 unsigned int id_val
;
1767 if (os_strcmp(id
, "*") == 0) {
1775 return dpp_configurator_del(wpa_s
, id_val
);
1779 int wpas_dpp_configurator_sign(struct wpa_supplicant
*wpa_s
, const char *cmd
)
1781 struct dpp_authentication
*auth
;
1785 auth
= os_zalloc(sizeof(*auth
));
1789 curve
= get_param(cmd
, " curve=");
1790 wpas_dpp_set_configurator(wpa_s
, auth
, cmd
);
1792 if (dpp_configurator_own_config(auth
, curve
) == 0) {
1793 wpas_dpp_handle_config_obj(wpa_s
, auth
);
1797 dpp_auth_deinit(auth
);
1805 wpas_dpp_tx_introduction_status(struct wpa_supplicant
*wpa_s
,
1806 unsigned int freq
, const u8
*dst
,
1807 const u8
*src
, const u8
*bssid
,
1808 const u8
*data
, size_t data_len
,
1809 enum offchannel_send_action_result result
)
1811 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
1812 " result=%s (DPP Peer Discovery Request)",
1814 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
1815 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
1817 /* TODO: Time out wait for response more quickly in error cases? */
1821 int wpas_dpp_check_connect(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
1822 struct wpa_bss
*bss
)
1826 unsigned int wait_time
;
1828 if (!(ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) || !bss
)
1829 return 0; /* Not using DPP AKM - continue */
1830 if (wpa_sm_pmksa_exists(wpa_s
->wpa
, bss
->bssid
, ssid
))
1831 return 0; /* PMKSA exists for DPP AKM - continue */
1833 if (!ssid
->dpp_connector
|| !ssid
->dpp_netaccesskey
||
1835 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_MISSING_CONNECTOR
1837 !ssid
->dpp_connector
? "Connector" :
1838 (!ssid
->dpp_netaccesskey
? "netAccessKey" :
1845 if (ssid
->dpp_csign_expiry
&& ssid
->dpp_csign_expiry
< now
.sec
) {
1846 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_MISSING_CONNECTOR
1847 "C-sign-key expired");
1851 if (ssid
->dpp_netaccesskey_expiry
&&
1852 ssid
->dpp_netaccesskey_expiry
< now
.sec
) {
1853 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_MISSING_CONNECTOR
1854 "netAccessKey expired");
1858 wpa_printf(MSG_DEBUG
,
1859 "DPP: Starting network introduction protocol to derive PMKSA for "
1860 MACSTR
, MAC2STR(bss
->bssid
));
1862 msg
= dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ
,
1863 5 + 4 + os_strlen(ssid
->dpp_connector
));
1867 /* Transaction ID */
1868 wpabuf_put_le16(msg
, DPP_ATTR_TRANSACTION_ID
);
1869 wpabuf_put_le16(msg
, 1);
1870 wpabuf_put_u8(msg
, TRANSACTION_ID
);
1873 wpabuf_put_le16(msg
, DPP_ATTR_CONNECTOR
);
1874 wpabuf_put_le16(msg
, os_strlen(ssid
->dpp_connector
));
1875 wpabuf_put_str(msg
, ssid
->dpp_connector
);
1877 /* TODO: Timeout on AP response */
1878 wait_time
= wpa_s
->max_remain_on_chan
;
1879 if (wait_time
> 2000)
1881 offchannel_send_action(wpa_s
, bss
->freq
, bss
->bssid
, wpa_s
->own_addr
,
1883 wpabuf_head(msg
), wpabuf_len(msg
),
1884 wait_time
, wpas_dpp_tx_introduction_status
, 0);
1887 /* Request this connection attempt to terminate - new one will be
1888 * started when network introduction protocol completes */
1889 os_memcpy(wpa_s
->dpp_intro_bssid
, bss
->bssid
, ETH_ALEN
);
1890 wpa_s
->dpp_intro_network
= ssid
;
1895 int wpas_dpp_pkex_add(struct wpa_supplicant
*wpa_s
, const char *cmd
)
1897 struct dpp_bootstrap_info
*own_bi
;
1898 const char *pos
, *end
;
1899 unsigned int wait_time
;
1901 pos
= os_strstr(cmd
, " own=");
1905 own_bi
= dpp_bootstrap_get_id(wpa_s
, atoi(pos
));
1907 wpa_printf(MSG_DEBUG
,
1908 "DPP: Identified bootstrap info not found");
1911 if (own_bi
->type
!= DPP_BOOTSTRAP_PKEX
) {
1912 wpa_printf(MSG_DEBUG
,
1913 "DPP: Identified bootstrap info not for PKEX");
1916 wpa_s
->dpp_pkex_bi
= own_bi
;
1918 os_free(wpa_s
->dpp_pkex_identifier
);
1919 wpa_s
->dpp_pkex_identifier
= NULL
;
1920 pos
= os_strstr(cmd
, " identifier=");
1923 end
= os_strchr(pos
, ' ');
1926 wpa_s
->dpp_pkex_identifier
= os_malloc(end
- pos
+ 1);
1927 if (!wpa_s
->dpp_pkex_identifier
)
1929 os_memcpy(wpa_s
->dpp_pkex_identifier
, pos
, end
- pos
);
1930 wpa_s
->dpp_pkex_identifier
[end
- pos
] = '\0';
1933 pos
= os_strstr(cmd
, " code=");
1936 os_free(wpa_s
->dpp_pkex_code
);
1937 wpa_s
->dpp_pkex_code
= os_strdup(pos
+ 6);
1938 if (!wpa_s
->dpp_pkex_code
)
1941 if (os_strstr(cmd
, " init=1")) {
1944 wpa_printf(MSG_DEBUG
, "DPP: Initiating PKEX");
1945 dpp_pkex_free(wpa_s
->dpp_pkex
);
1946 wpa_s
->dpp_pkex
= dpp_pkex_init(own_bi
, wpa_s
->own_addr
,
1947 wpa_s
->dpp_pkex_identifier
,
1948 wpa_s
->dpp_pkex_code
);
1949 if (!wpa_s
->dpp_pkex
)
1952 msg
= wpa_s
->dpp_pkex
->exchange_req
;
1953 wait_time
= wpa_s
->max_remain_on_chan
;
1954 if (wait_time
> 2000)
1956 /* TODO: Which channel to use? */
1957 offchannel_send_action(wpa_s
, 2437, broadcast
, wpa_s
->own_addr
,
1959 wpabuf_head(msg
), wpabuf_len(msg
),
1960 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1963 /* TODO: Support multiple PKEX info entries */
1965 os_free(wpa_s
->dpp_pkex_auth_cmd
);
1966 wpa_s
->dpp_pkex_auth_cmd
= os_strdup(cmd
);
1972 int wpas_dpp_pkex_remove(struct wpa_supplicant
*wpa_s
, const char *id
)
1974 unsigned int id_val
;
1976 if (os_strcmp(id
, "*") == 0) {
1984 if ((id_val
!= 0 && id_val
!= 1) || !wpa_s
->dpp_pkex_code
)
1987 /* TODO: Support multiple PKEX entries */
1988 os_free(wpa_s
->dpp_pkex_code
);
1989 wpa_s
->dpp_pkex_code
= NULL
;
1990 os_free(wpa_s
->dpp_pkex_identifier
);
1991 wpa_s
->dpp_pkex_identifier
= NULL
;
1992 os_free(wpa_s
->dpp_pkex_auth_cmd
);
1993 wpa_s
->dpp_pkex_auth_cmd
= NULL
;
1994 wpa_s
->dpp_pkex_bi
= NULL
;
1995 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
1996 dpp_pkex_free(wpa_s
->dpp_pkex
);
1997 wpa_s
->dpp_pkex
= NULL
;
2002 int wpas_dpp_init(struct wpa_supplicant
*wpa_s
)
2006 adv_proto_id
[0] = WLAN_EID_VENDOR_SPECIFIC
;
2007 adv_proto_id
[1] = 5;
2008 WPA_PUT_BE24(&adv_proto_id
[2], OUI_WFA
);
2009 adv_proto_id
[5] = DPP_OUI_TYPE
;
2010 adv_proto_id
[6] = 0x01;
2012 if (gas_server_register(wpa_s
->gas_server
, adv_proto_id
,
2013 sizeof(adv_proto_id
), wpas_dpp_gas_req_handler
,
2014 wpas_dpp_gas_status_handler
, wpa_s
) < 0)
2016 dl_list_init(&wpa_s
->dpp_bootstrap
);
2017 dl_list_init(&wpa_s
->dpp_configurator
);
2018 wpa_s
->dpp_init_done
= 1;
2023 void wpas_dpp_deinit(struct wpa_supplicant
*wpa_s
)
2025 #ifdef CONFIG_TESTING_OPTIONS
2026 os_free(wpa_s
->dpp_config_obj_override
);
2027 wpa_s
->dpp_config_obj_override
= NULL
;
2028 os_free(wpa_s
->dpp_discovery_override
);
2029 wpa_s
->dpp_discovery_override
= NULL
;
2030 os_free(wpa_s
->dpp_groups_override
);
2031 wpa_s
->dpp_groups_override
= NULL
;
2032 wpa_s
->dpp_ignore_netaccesskey_mismatch
= 0;
2033 #endif /* CONFIG_TESTING_OPTIONS */
2034 if (!wpa_s
->dpp_init_done
)
2036 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
2037 offchannel_send_action_done(wpa_s
);
2038 wpas_dpp_listen_stop(wpa_s
);
2039 dpp_bootstrap_del(wpa_s
, 0);
2040 dpp_configurator_del(wpa_s
, 0);
2041 dpp_auth_deinit(wpa_s
->dpp_auth
);
2042 wpa_s
->dpp_auth
= NULL
;
2043 wpas_dpp_pkex_remove(wpa_s
, "*");
2044 wpa_s
->dpp_pkex
= NULL
;
2045 os_memset(wpa_s
->dpp_intro_bssid
, 0, ETH_ALEN
);
2046 os_free(wpa_s
->dpp_configurator_params
);
2047 wpa_s
->dpp_configurator_params
= NULL
;