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" };
396 wpa_printf(MSG_DEBUG
, "DPP: Set configurator parameters: %s", cmd
);
397 pos
= os_strstr(cmd
, " ssid=");
400 end
= os_strchr(pos
, ' ');
401 ssid_len
= end
? (size_t) (end
- pos
) : os_strlen(pos
);
403 if (ssid_len
> sizeof(ssid
) ||
404 hexstr2bin(pos
, ssid
, ssid_len
) < 0)
408 pos
= os_strstr(cmd
, " pass=");
411 end
= os_strchr(pos
, ' ');
412 pass_len
= end
? (size_t) (end
- pos
) : os_strlen(pos
);
414 if (pass_len
> sizeof(pass
) - 1 || pass_len
< 8 ||
415 hexstr2bin(pos
, (u8
*) pass
, pass_len
) < 0)
419 pos
= os_strstr(cmd
, " psk=");
422 if (hexstr2bin(pos
, psk
, PMK_LEN
) < 0)
427 if (os_strstr(cmd
, " conf=sta-")) {
428 conf_sta
= os_zalloc(sizeof(struct dpp_configuration
));
431 os_memcpy(conf_sta
->ssid
, ssid
, ssid_len
);
432 conf_sta
->ssid_len
= ssid_len
;
433 if (os_strstr(cmd
, " conf=sta-psk")) {
436 os_memcpy(conf_sta
->psk
, psk
, PMK_LEN
);
438 conf_sta
->passphrase
= os_strdup(pass
);
439 if (!conf_sta
->passphrase
)
442 } else if (os_strstr(cmd
, " conf=sta-dpp")) {
449 if (os_strstr(cmd
, " conf=ap-")) {
450 conf_ap
= os_zalloc(sizeof(struct dpp_configuration
));
453 os_memcpy(conf_ap
->ssid
, ssid
, ssid_len
);
454 conf_ap
->ssid_len
= ssid_len
;
455 if (os_strstr(cmd
, " conf=ap-psk")) {
458 os_memcpy(conf_ap
->psk
, psk
, PMK_LEN
);
460 conf_ap
->passphrase
= os_strdup(pass
);
461 if (!conf_ap
->passphrase
)
464 } else if (os_strstr(cmd
, " conf=ap-dpp")) {
471 pos
= os_strstr(cmd
, " expiry=");
476 val
= strtol(pos
, NULL
, 0);
480 conf_sta
->netaccesskey_expiry
= val
;
482 conf_ap
->netaccesskey_expiry
= val
;
485 pos
= os_strstr(cmd
, " configurator=");
488 conf
= dpp_configurator_get_id(wpa_s
, atoi(pos
));
491 "DPP: Could not find the specified configurator");
495 auth
->conf_sta
= conf_sta
;
496 auth
->conf_ap
= conf_ap
;
501 wpa_printf(MSG_DEBUG
, "DPP: Failed to set configurator parameters");
502 dpp_configuration_free(conf_sta
);
503 dpp_configuration_free(conf_ap
);
507 int wpas_dpp_auth_init(struct wpa_supplicant
*wpa_s
, const char *cmd
)
510 struct dpp_bootstrap_info
*peer_bi
, *own_bi
= NULL
;
514 int configurator
= 1;
515 unsigned int wait_time
;
517 wpa_s
->dpp_gas_client
= 0;
519 pos
= os_strstr(cmd
, " peer=");
523 peer_bi
= dpp_bootstrap_get_id(wpa_s
, atoi(pos
));
526 "DPP: Could not find bootstrapping info for the identified peer");
530 pos
= os_strstr(cmd
, " own=");
533 own_bi
= dpp_bootstrap_get_id(wpa_s
, atoi(pos
));
536 "DPP: Could not find bootstrapping info for the identified local entry");
540 if (peer_bi
->curve
!= own_bi
->curve
) {
542 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
543 peer_bi
->curve
->name
, own_bi
->curve
->name
);
548 pos
= os_strstr(cmd
, " role=");
551 if (os_strncmp(pos
, "configurator", 12) == 0)
553 else if (os_strncmp(pos
, "enrollee", 8) == 0)
559 pos
= os_strstr(cmd
, " netrole=");
562 wpa_s
->dpp_netrole_ap
= os_strncmp(pos
, "ap", 2) == 0;
565 if (wpa_s
->dpp_auth
) {
566 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
567 offchannel_send_action_done(wpa_s
);
568 dpp_auth_deinit(wpa_s
->dpp_auth
);
570 wpa_s
->dpp_auth
= dpp_auth_init(wpa_s
, peer_bi
, own_bi
, configurator
);
571 if (!wpa_s
->dpp_auth
)
573 wpas_dpp_set_testing_options(wpa_s
, wpa_s
->dpp_auth
);
574 wpas_dpp_set_configurator(wpa_s
, wpa_s
->dpp_auth
, cmd
);
576 /* TODO: Support iteration over all frequencies and filtering of
577 * frequencies based on locally enabled channels that allow initiation
578 * of transmission. */
579 if (peer_bi
->num_freq
> 0)
580 wpa_s
->dpp_auth
->curr_freq
= peer_bi
->freq
[0];
582 wpa_s
->dpp_auth
->curr_freq
= 2412;
584 msg
= dpp_alloc_msg(DPP_PA_AUTHENTICATION_REQ
,
585 wpabuf_len(wpa_s
->dpp_auth
->req_attr
));
588 wpabuf_put_buf(msg
, wpa_s
->dpp_auth
->req_attr
);
590 if (is_zero_ether_addr(peer_bi
->mac_addr
)) {
593 dst
= peer_bi
->mac_addr
;
594 os_memcpy(wpa_s
->dpp_auth
->peer_mac_addr
, peer_bi
->mac_addr
,
597 wpa_s
->dpp_auth_ok_on_ack
= 0;
598 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
599 wait_time
= wpa_s
->max_remain_on_chan
;
600 if (wait_time
> 2000)
602 eloop_register_timeout(wait_time
/ 1000, (wait_time
% 1000) * 1000,
603 wpas_dpp_reply_wait_timeout
,
605 res
= offchannel_send_action(wpa_s
, wpa_s
->dpp_auth
->curr_freq
,
606 dst
, wpa_s
->own_addr
, broadcast
,
607 wpabuf_head(msg
), wpabuf_len(msg
),
608 wait_time
, wpas_dpp_tx_status
, 0);
617 struct wpas_dpp_listen_work
{
619 unsigned int duration
;
620 struct wpabuf
*probe_resp_ie
;
624 static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work
*lwork
)
632 static void wpas_dpp_listen_work_done(struct wpa_supplicant
*wpa_s
)
634 struct wpas_dpp_listen_work
*lwork
;
636 if (!wpa_s
->dpp_listen_work
)
639 lwork
= wpa_s
->dpp_listen_work
->ctx
;
640 wpas_dpp_listen_work_free(lwork
);
641 radio_work_done(wpa_s
->dpp_listen_work
);
642 wpa_s
->dpp_listen_work
= NULL
;
646 static void dpp_start_listen_cb(struct wpa_radio_work
*work
, int deinit
)
648 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
649 struct wpas_dpp_listen_work
*lwork
= work
->ctx
;
653 wpa_s
->dpp_listen_work
= NULL
;
654 wpas_dpp_listen_stop(wpa_s
);
656 wpas_dpp_listen_work_free(lwork
);
660 wpa_s
->dpp_listen_work
= work
;
662 wpa_s
->dpp_pending_listen_freq
= lwork
->freq
;
664 if (wpa_drv_remain_on_channel(wpa_s
, lwork
->freq
,
665 wpa_s
->max_remain_on_chan
) < 0) {
666 wpa_printf(MSG_DEBUG
,
667 "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
669 wpas_dpp_listen_work_done(wpa_s
);
670 wpa_s
->dpp_pending_listen_freq
= 0;
673 wpa_s
->off_channel_freq
= 0;
674 wpa_s
->roc_waiting_drv_freq
= lwork
->freq
;
678 static int wpas_dpp_listen_start(struct wpa_supplicant
*wpa_s
,
681 struct wpas_dpp_listen_work
*lwork
;
683 if (wpa_s
->dpp_listen_work
) {
684 wpa_printf(MSG_DEBUG
,
685 "DPP: Reject start_listen since dpp_listen_work already exists");
689 if (wpa_s
->dpp_listen_freq
)
690 wpas_dpp_listen_stop(wpa_s
);
691 wpa_s
->dpp_listen_freq
= freq
;
693 lwork
= os_zalloc(sizeof(*lwork
));
698 if (radio_add_work(wpa_s
, freq
, "dpp-listen", 0, dpp_start_listen_cb
,
700 wpas_dpp_listen_work_free(lwork
);
708 int wpas_dpp_listen(struct wpa_supplicant
*wpa_s
, const char *cmd
)
716 if (os_strstr(cmd
, " role=configurator"))
717 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_CONFIGURATOR
;
718 else if (os_strstr(cmd
, " role=enrollee"))
719 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_ENROLLEE
;
721 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_CONFIGURATOR
|
723 wpa_s
->dpp_qr_mutual
= os_strstr(cmd
, " qr=mutual") != NULL
;
724 wpa_s
->dpp_netrole_ap
= os_strstr(cmd
, " netrole=ap") != NULL
;
725 if (wpa_s
->dpp_listen_freq
== (unsigned int) freq
) {
726 wpa_printf(MSG_DEBUG
, "DPP: Already listening on %u MHz",
731 return wpas_dpp_listen_start(wpa_s
, freq
);
735 void wpas_dpp_listen_stop(struct wpa_supplicant
*wpa_s
)
737 if (!wpa_s
->dpp_listen_freq
)
740 wpa_printf(MSG_DEBUG
, "DPP: Stop listen on %u MHz",
741 wpa_s
->dpp_listen_freq
);
742 wpa_drv_cancel_remain_on_channel(wpa_s
);
743 wpa_s
->dpp_listen_freq
= 0;
744 wpas_dpp_listen_work_done(wpa_s
);
748 void wpas_dpp_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
751 if (!wpa_s
->dpp_listen_freq
&& !wpa_s
->dpp_pending_listen_freq
)
754 wpa_printf(MSG_DEBUG
,
755 "DPP: remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d roc_waiting_drv_freq=%d freq=%u)",
756 wpa_s
->off_channel_freq
, wpa_s
->dpp_pending_listen_freq
,
757 wpa_s
->roc_waiting_drv_freq
, freq
);
758 if (wpa_s
->off_channel_freq
&&
759 wpa_s
->off_channel_freq
== wpa_s
->dpp_pending_listen_freq
) {
760 wpa_printf(MSG_DEBUG
, "DPP: Listen on %u MHz started", freq
);
761 wpa_s
->dpp_pending_listen_freq
= 0;
763 wpa_printf(MSG_DEBUG
,
764 "DPP: Ignore remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d freq=%u)",
765 wpa_s
->off_channel_freq
,
766 wpa_s
->dpp_pending_listen_freq
, freq
);
771 void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
774 wpas_dpp_listen_work_done(wpa_s
);
776 if (wpa_s
->dpp_auth
&& !wpa_s
->dpp_gas_client
) {
777 /* Continue listen with a new remain-on-channel */
778 wpa_printf(MSG_DEBUG
,
779 "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
780 wpa_s
->dpp_auth
->curr_freq
);
781 wpas_dpp_listen_start(wpa_s
, wpa_s
->dpp_auth
->curr_freq
);
785 if (wpa_s
->dpp_listen_freq
) {
786 /* Continue listen with a new remain-on-channel */
787 wpas_dpp_listen_start(wpa_s
, wpa_s
->dpp_listen_freq
);
792 static void wpas_dpp_rx_auth_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
793 const u8
*buf
, size_t len
, unsigned int freq
)
795 const u8
*r_bootstrap
, *i_bootstrap
, *wrapped_data
;
796 u16 r_bootstrap_len
, i_bootstrap_len
, wrapped_data_len
;
797 struct dpp_bootstrap_info
*bi
, *own_bi
= NULL
, *peer_bi
= NULL
;
800 wpa_printf(MSG_DEBUG
, "DPP: Authentication Request from " MACSTR
,
803 wrapped_data
= dpp_get_attr(buf
, len
, DPP_ATTR_WRAPPED_DATA
,
806 wpa_printf(MSG_DEBUG
,
807 "DPP: Missing required Wrapped data attribute");
810 wpa_hexdump(MSG_MSGDUMP
, "DPP: Wrapped data",
811 wrapped_data
, wrapped_data_len
);
813 r_bootstrap
= dpp_get_attr(buf
, len
, DPP_ATTR_R_BOOTSTRAP_KEY_HASH
,
815 if (!r_bootstrap
|| r_bootstrap
> wrapped_data
||
816 r_bootstrap_len
!= SHA256_MAC_LEN
) {
817 wpa_printf(MSG_DEBUG
,
818 "DPP: Missing or invalid required Responder Bootstrapping Key Hash attribute");
821 wpa_hexdump(MSG_MSGDUMP
, "DPP: Responder Bootstrapping Key Hash",
822 r_bootstrap
, r_bootstrap_len
);
824 i_bootstrap
= dpp_get_attr(buf
, len
, DPP_ATTR_I_BOOTSTRAP_KEY_HASH
,
826 if (!i_bootstrap
|| i_bootstrap
> wrapped_data
||
827 i_bootstrap_len
!= SHA256_MAC_LEN
) {
828 wpa_printf(MSG_DEBUG
,
829 "DPP: Missing or invalid required Initiator Bootstrapping Key Hash attribute");
832 wpa_hexdump(MSG_MSGDUMP
, "DPP: Initiator Bootstrapping Key Hash",
833 i_bootstrap
, i_bootstrap_len
);
835 /* Try to find own and peer bootstrapping key matches based on the
836 * received hash values */
837 dl_list_for_each(bi
, &wpa_s
->dpp_bootstrap
, struct dpp_bootstrap_info
,
839 if (!own_bi
&& bi
->own
&&
840 os_memcmp(bi
->pubkey_hash
, r_bootstrap
,
841 SHA256_MAC_LEN
) == 0) {
842 wpa_printf(MSG_DEBUG
,
843 "DPP: Found matching own bootstrapping information");
847 if (!peer_bi
&& !bi
->own
&&
848 os_memcmp(bi
->pubkey_hash
, i_bootstrap
,
849 SHA256_MAC_LEN
) == 0) {
850 wpa_printf(MSG_DEBUG
,
851 "DPP: Found matching peer bootstrapping information");
855 if (own_bi
&& peer_bi
)
860 wpa_printf(MSG_DEBUG
,
861 "DPP: No matching own bootstrapping key found - ignore message");
865 if (wpa_s
->dpp_auth
) {
866 wpa_printf(MSG_DEBUG
,
867 "DPP: Already in DPP authentication exchange - ignore new one");
871 wpa_s
->dpp_gas_client
= 0;
872 wpa_s
->dpp_auth_ok_on_ack
= 0;
873 wpa_s
->dpp_auth
= dpp_auth_req_rx(wpa_s
, wpa_s
->dpp_allowed_roles
,
874 wpa_s
->dpp_qr_mutual
,
875 peer_bi
, own_bi
, freq
, buf
,
876 wrapped_data
, wrapped_data_len
);
877 if (!wpa_s
->dpp_auth
) {
878 wpa_printf(MSG_DEBUG
, "DPP: No response generated");
881 wpas_dpp_set_testing_options(wpa_s
, wpa_s
->dpp_auth
);
882 wpas_dpp_set_configurator(wpa_s
, wpa_s
->dpp_auth
,
883 wpa_s
->dpp_configurator_params
);
884 os_memcpy(wpa_s
->dpp_auth
->peer_mac_addr
, src
, ETH_ALEN
);
886 msg
= dpp_alloc_msg(DPP_PA_AUTHENTICATION_RESP
,
887 wpabuf_len(wpa_s
->dpp_auth
->resp_attr
));
890 wpabuf_put_buf(msg
, wpa_s
->dpp_auth
->resp_attr
);
892 offchannel_send_action(wpa_s
, wpa_s
->dpp_auth
->curr_freq
,
893 src
, wpa_s
->own_addr
, broadcast
,
894 wpabuf_head(msg
), wpabuf_len(msg
),
895 500, wpas_dpp_tx_status
, 0);
900 static void wpas_dpp_start_gas_server(struct wpa_supplicant
*wpa_s
)
902 /* TODO: stop wait and start ROC */
906 static struct wpa_ssid
* wpas_dpp_add_network(struct wpa_supplicant
*wpa_s
,
907 struct dpp_authentication
*auth
)
909 struct wpa_ssid
*ssid
;
911 ssid
= wpa_config_add_network(wpa_s
->conf
);
914 wpas_notify_network_added(wpa_s
, ssid
);
915 wpa_config_set_network_defaults(ssid
);
918 ssid
->ssid
= os_malloc(auth
->ssid_len
);
921 os_memcpy(ssid
->ssid
, auth
->ssid
, auth
->ssid_len
);
922 ssid
->ssid_len
= auth
->ssid_len
;
924 if (auth
->connector
) {
925 ssid
->key_mgmt
= WPA_KEY_MGMT_DPP
;
926 ssid
->dpp_connector
= os_strdup(auth
->connector
);
927 if (!ssid
->dpp_connector
)
931 if (auth
->c_sign_key
) {
932 ssid
->dpp_csign
= os_malloc(wpabuf_len(auth
->c_sign_key
));
933 if (!ssid
->dpp_csign
)
935 os_memcpy(ssid
->dpp_csign
, wpabuf_head(auth
->c_sign_key
),
936 wpabuf_len(auth
->c_sign_key
));
937 ssid
->dpp_csign_len
= wpabuf_len(auth
->c_sign_key
);
940 if (auth
->net_access_key
) {
941 ssid
->dpp_netaccesskey
=
942 os_malloc(wpabuf_len(auth
->net_access_key
));
943 if (!ssid
->dpp_netaccesskey
)
945 os_memcpy(ssid
->dpp_netaccesskey
,
946 wpabuf_head(auth
->net_access_key
),
947 wpabuf_len(auth
->net_access_key
));
948 ssid
->dpp_netaccesskey_len
= wpabuf_len(auth
->net_access_key
);
949 ssid
->dpp_netaccesskey_expiry
= auth
->net_access_key_expiry
;
952 if (!auth
->connector
) {
953 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
954 if (auth
->passphrase
[0]) {
955 if (wpa_config_set_quoted(ssid
, "psk",
956 auth
->passphrase
) < 0)
958 wpa_config_update_psk(ssid
);
959 ssid
->export_keys
= 1;
961 ssid
->psk_set
= auth
->psk_set
;
962 os_memcpy(ssid
->psk
, auth
->psk
, PMK_LEN
);
968 wpas_notify_network_removed(wpa_s
, ssid
);
969 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
974 static void wpas_dpp_process_config(struct wpa_supplicant
*wpa_s
,
975 struct dpp_authentication
*auth
)
977 struct wpa_ssid
*ssid
;
979 if (wpa_s
->conf
->dpp_config_processing
< 1)
982 ssid
= wpas_dpp_add_network(wpa_s
, auth
);
986 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_NETWORK_ID
"%d", ssid
->id
);
987 if (wpa_s
->conf
->dpp_config_processing
< 2)
990 wpa_printf(MSG_DEBUG
, "DPP: Trying to connect to the new network");
992 wpa_s
->disconnected
= 0;
993 wpa_s
->reassociate
= 1;
994 wpa_s
->scan_runs
= 0;
995 wpa_s
->normal_scans
= 0;
996 wpa_supplicant_cancel_sched_scan(wpa_s
);
997 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1001 static void wpas_dpp_handle_config_obj(struct wpa_supplicant
*wpa_s
,
1002 struct dpp_authentication
*auth
)
1004 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_RECEIVED
);
1006 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONFOBJ_SSID
"%s",
1007 wpa_ssid_txt(auth
->ssid
, auth
->ssid_len
));
1008 if (auth
->connector
) {
1009 /* TODO: Save the Connector and consider using a command
1010 * to fetch the value instead of sending an event with
1011 * it. The Connector could end up being larger than what
1012 * most clients are ready to receive as an event
1014 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONNECTOR
"%s",
1017 if (auth
->c_sign_key
) {
1021 hexlen
= 2 * wpabuf_len(auth
->c_sign_key
) + 1;
1022 hex
= os_malloc(hexlen
);
1024 wpa_snprintf_hex(hex
, hexlen
,
1025 wpabuf_head(auth
->c_sign_key
),
1026 wpabuf_len(auth
->c_sign_key
));
1027 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_C_SIGN_KEY
"%s",
1032 if (auth
->net_access_key
) {
1036 hexlen
= 2 * wpabuf_len(auth
->net_access_key
) + 1;
1037 hex
= os_malloc(hexlen
);
1039 wpa_snprintf_hex(hex
, hexlen
,
1040 wpabuf_head(auth
->net_access_key
),
1041 wpabuf_len(auth
->net_access_key
));
1042 if (auth
->net_access_key_expiry
)
1043 wpa_msg(wpa_s
, MSG_INFO
,
1044 DPP_EVENT_NET_ACCESS_KEY
"%s %lu", hex
,
1046 auth
->net_access_key_expiry
);
1048 wpa_msg(wpa_s
, MSG_INFO
,
1049 DPP_EVENT_NET_ACCESS_KEY
"%s", hex
);
1054 wpas_dpp_process_config(wpa_s
, auth
);
1058 static void wpas_dpp_gas_resp_cb(void *ctx
, const u8
*addr
, u8 dialog_token
,
1059 enum gas_query_result result
,
1060 const struct wpabuf
*adv_proto
,
1061 const struct wpabuf
*resp
, u16 status_code
)
1063 struct wpa_supplicant
*wpa_s
= ctx
;
1065 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1067 if (!auth
|| !auth
->auth_success
) {
1068 wpa_printf(MSG_DEBUG
, "DPP: No matching exchange in progress");
1071 if (!resp
|| status_code
!= WLAN_STATUS_SUCCESS
) {
1072 wpa_printf(MSG_DEBUG
, "DPP: GAS query did not succeed");
1076 wpa_hexdump_buf(MSG_DEBUG
, "DPP: Configuration Response adv_proto",
1078 wpa_hexdump_buf(MSG_DEBUG
, "DPP: Configuration Response (GAS response)",
1081 if (wpabuf_len(adv_proto
) != 10 ||
1082 !(pos
= wpabuf_head(adv_proto
)) ||
1083 pos
[0] != WLAN_EID_ADV_PROTO
||
1085 pos
[3] != WLAN_EID_VENDOR_SPECIFIC
||
1087 WPA_GET_BE24(&pos
[5]) != OUI_WFA
||
1090 wpa_printf(MSG_DEBUG
,
1091 "DPP: Not a DPP Advertisement Protocol ID");
1095 if (dpp_conf_resp_rx(auth
, resp
) < 0) {
1096 wpa_printf(MSG_DEBUG
, "DPP: Configuration attempt failed");
1100 wpas_dpp_handle_config_obj(wpa_s
, auth
);
1101 dpp_auth_deinit(wpa_s
->dpp_auth
);
1102 wpa_s
->dpp_auth
= NULL
;
1106 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1107 dpp_auth_deinit(wpa_s
->dpp_auth
);
1108 wpa_s
->dpp_auth
= NULL
;
1112 static void wpas_dpp_start_gas_client(struct wpa_supplicant
*wpa_s
)
1114 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1115 struct wpabuf
*buf
, *conf_req
;
1119 wpa_s
->dpp_gas_client
= 1;
1120 os_snprintf(json
, sizeof(json
),
1121 "{\"name\":\"Test\","
1122 "\"wi-fi_tech\":\"infra\","
1123 "\"netRole\":\"%s\"}",
1124 wpa_s
->dpp_netrole_ap
? "ap" : "sta");
1125 wpa_printf(MSG_DEBUG
, "DPP: GAS Config Attributes: %s", json
);
1127 offchannel_send_action_done(wpa_s
);
1128 wpas_dpp_listen_stop(wpa_s
);
1130 conf_req
= dpp_build_conf_req(auth
, json
);
1132 wpa_printf(MSG_DEBUG
,
1133 "DPP: No configuration request data available");
1137 buf
= gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req
));
1139 wpabuf_free(conf_req
);
1143 /* Advertisement Protocol IE */
1144 wpabuf_put_u8(buf
, WLAN_EID_ADV_PROTO
);
1145 wpabuf_put_u8(buf
, 8); /* Length */
1146 wpabuf_put_u8(buf
, 0x7f);
1147 wpabuf_put_u8(buf
, WLAN_EID_VENDOR_SPECIFIC
);
1148 wpabuf_put_u8(buf
, 5);
1149 wpabuf_put_be24(buf
, OUI_WFA
);
1150 wpabuf_put_u8(buf
, DPP_OUI_TYPE
);
1151 wpabuf_put_u8(buf
, 0x01);
1154 wpabuf_put_le16(buf
, wpabuf_len(conf_req
));
1155 wpabuf_put_buf(buf
, conf_req
);
1156 wpabuf_free(conf_req
);
1158 wpa_printf(MSG_DEBUG
, "DPP: GAS request to " MACSTR
" (freq %u MHz)",
1159 MAC2STR(auth
->peer_mac_addr
), auth
->curr_freq
);
1161 res
= gas_query_req(wpa_s
->gas
, auth
->peer_mac_addr
, auth
->curr_freq
,
1162 buf
, wpas_dpp_gas_resp_cb
, wpa_s
);
1164 wpa_msg(wpa_s
, MSG_DEBUG
, "GAS: Failed to send Query Request");
1167 wpa_printf(MSG_DEBUG
,
1168 "DPP: GAS query started with dialog token %u", res
);
1173 static void wpas_dpp_auth_success(struct wpa_supplicant
*wpa_s
, int initiator
)
1175 wpa_printf(MSG_DEBUG
, "DPP: Authentication succeeded");
1176 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_AUTH_SUCCESS
"init=%d", initiator
);
1178 if (wpa_s
->dpp_auth
->configurator
)
1179 wpas_dpp_start_gas_server(wpa_s
);
1181 wpas_dpp_start_gas_client(wpa_s
);
1185 static void wpas_dpp_rx_auth_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1186 const u8
*buf
, size_t len
)
1188 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1189 struct wpabuf
*msg
, *attr
;
1191 wpa_printf(MSG_DEBUG
, "DPP: Authentication Response from " MACSTR
,
1195 wpa_printf(MSG_DEBUG
,
1196 "DPP: No DPP Authentication in progress - drop");
1200 if (!is_zero_ether_addr(auth
->peer_mac_addr
) &&
1201 os_memcmp(src
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1202 wpa_printf(MSG_DEBUG
, "DPP: MAC address mismatch (expected "
1203 MACSTR
") - drop", MAC2STR(auth
->peer_mac_addr
));
1207 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
1209 attr
= dpp_auth_resp_rx(auth
, buf
, len
);
1211 if (auth
->auth_resp_status
== DPP_STATUS_RESPONSE_PENDING
) {
1212 wpa_printf(MSG_DEBUG
,
1213 "DPP: Start wait for full response");
1214 offchannel_send_action_done(wpa_s
);
1215 wpas_dpp_listen_start(wpa_s
, auth
->curr_freq
);
1218 wpa_printf(MSG_DEBUG
, "DPP: No confirm generated");
1221 os_memcpy(auth
->peer_mac_addr
, src
, ETH_ALEN
);
1223 msg
= dpp_alloc_msg(DPP_PA_AUTHENTICATION_CONF
, wpabuf_len(attr
));
1228 wpabuf_put_buf(msg
, attr
);
1231 offchannel_send_action(wpa_s
, auth
->curr_freq
,
1232 src
, wpa_s
->own_addr
, broadcast
,
1233 wpabuf_head(msg
), wpabuf_len(msg
),
1234 500, wpas_dpp_tx_status
, 0);
1236 wpa_s
->dpp_auth_ok_on_ack
= 1;
1240 static void wpas_dpp_rx_auth_conf(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1241 const u8
*buf
, size_t len
)
1243 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1245 wpa_printf(MSG_DEBUG
, "DPP: Authentication Confirmation from " MACSTR
,
1249 wpa_printf(MSG_DEBUG
,
1250 "DPP: No DPP Authentication in progress - drop");
1254 if (os_memcmp(src
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1255 wpa_printf(MSG_DEBUG
, "DPP: MAC address mismatch (expected "
1256 MACSTR
") - drop", MAC2STR(auth
->peer_mac_addr
));
1260 if (dpp_auth_conf_rx(auth
, buf
, len
) < 0) {
1261 wpa_printf(MSG_DEBUG
, "DPP: Authentication failed");
1265 wpas_dpp_auth_success(wpa_s
, 0);
1269 static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant
*wpa_s
,
1271 const u8
*buf
, size_t len
)
1273 struct wpa_ssid
*ssid
;
1274 const u8
*connector
, *trans_id
;
1275 u16 connector_len
, trans_id_len
;
1276 struct dpp_introduction intro
;
1277 struct rsn_pmksa_cache_entry
*entry
;
1279 struct os_reltime rnow
;
1281 unsigned int seconds
;
1283 wpa_printf(MSG_DEBUG
, "DPP: Peer Discovery Response from " MACSTR
,
1285 if (is_zero_ether_addr(wpa_s
->dpp_intro_bssid
) ||
1286 os_memcmp(src
, wpa_s
->dpp_intro_bssid
, ETH_ALEN
) != 0) {
1287 wpa_printf(MSG_DEBUG
, "DPP: Not waiting for response from "
1288 MACSTR
" - drop", MAC2STR(src
));
1291 offchannel_send_action_done(wpa_s
);
1293 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1294 if (ssid
== wpa_s
->dpp_intro_network
)
1297 if (!ssid
|| !ssid
->dpp_connector
|| !ssid
->dpp_netaccesskey
||
1299 wpa_printf(MSG_DEBUG
,
1300 "DPP: Profile not found for network introduction");
1304 trans_id
= dpp_get_attr(buf
, len
, DPP_ATTR_TRANSACTION_ID
,
1306 if (!trans_id
|| trans_id_len
!= 1) {
1307 wpa_printf(MSG_DEBUG
,
1308 "DPP: Peer did not include Transaction ID");
1311 if (trans_id
[0] != TRANSACTION_ID
) {
1312 wpa_printf(MSG_DEBUG
,
1313 "DPP: Ignore frame with unexpected Transaction ID %u",
1318 connector
= dpp_get_attr(buf
, len
, DPP_ATTR_CONNECTOR
, &connector_len
);
1320 wpa_printf(MSG_DEBUG
,
1321 "DPP: Peer did not include its Connector");
1325 if (dpp_peer_intro(&intro
, ssid
->dpp_connector
,
1326 ssid
->dpp_netaccesskey
,
1327 ssid
->dpp_netaccesskey_len
,
1329 ssid
->dpp_csign_len
,
1330 connector
, connector_len
, &expiry
) < 0) {
1331 wpa_printf(MSG_INFO
,
1332 "DPP: Network Introduction protocol resulted in failure");
1336 entry
= os_zalloc(sizeof(*entry
));
1339 os_memcpy(entry
->aa
, src
, ETH_ALEN
);
1340 os_memcpy(entry
->pmkid
, intro
.pmkid
, PMKID_LEN
);
1341 os_memcpy(entry
->pmk
, intro
.pmk
, intro
.pmk_len
);
1342 entry
->pmk_len
= intro
.pmk_len
;
1343 entry
->akmp
= WPA_KEY_MGMT_DPP
;
1346 seconds
= expiry
- now
.sec
;
1348 seconds
= 86400 * 7;
1350 os_get_reltime(&rnow
);
1351 entry
->expiration
= rnow
.sec
+ seconds
;
1352 entry
->reauth_time
= rnow
.sec
+ seconds
;
1353 entry
->network_ctx
= ssid
;
1354 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
1356 wpa_printf(MSG_DEBUG
,
1357 "DPP: Try connection again after successful network introduction");
1358 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
1359 wpa_supplicant_cancel_sched_scan(wpa_s
);
1360 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1363 os_memset(&intro
, 0, sizeof(intro
));
1368 wpas_dpp_tx_pkex_status(struct wpa_supplicant
*wpa_s
,
1369 unsigned int freq
, const u8
*dst
,
1370 const u8
*src
, const u8
*bssid
,
1371 const u8
*data
, size_t data_len
,
1372 enum offchannel_send_action_result result
)
1374 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
1375 " result=%s (PKEX)",
1377 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
1378 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
1380 /* TODO: Time out wait for response more quickly in error cases? */
1385 wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1386 const u8
*buf
, size_t len
, unsigned int freq
)
1389 unsigned int wait_time
;
1391 wpa_printf(MSG_DEBUG
, "DPP: PKEX Exchange Request from " MACSTR
,
1394 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1397 if (!wpa_s
->dpp_pkex_code
|| !wpa_s
->dpp_pkex_bi
) {
1398 wpa_printf(MSG_DEBUG
,
1399 "DPP: No PKEX code configured - ignore request");
1403 if (wpa_s
->dpp_pkex
) {
1404 /* TODO: Support parallel operations */
1405 wpa_printf(MSG_DEBUG
,
1406 "DPP: Already in PKEX session - ignore new request");
1410 wpa_s
->dpp_pkex
= dpp_pkex_rx_exchange_req(wpa_s
->dpp_pkex_bi
,
1411 wpa_s
->own_addr
, src
,
1412 wpa_s
->dpp_pkex_identifier
,
1413 wpa_s
->dpp_pkex_code
,
1415 if (!wpa_s
->dpp_pkex
) {
1416 wpa_printf(MSG_DEBUG
,
1417 "DPP: Failed to process the request - ignore it");
1421 msg
= wpa_s
->dpp_pkex
->exchange_resp
;
1422 wait_time
= wpa_s
->max_remain_on_chan
;
1423 if (wait_time
> 2000)
1425 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
1427 wpabuf_head(msg
), wpabuf_len(msg
),
1428 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1433 wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1434 const u8
*buf
, size_t len
, unsigned int freq
)
1437 unsigned int wait_time
;
1439 wpa_printf(MSG_DEBUG
, "DPP: PKEX Exchange Response from " MACSTR
,
1442 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1445 if (!wpa_s
->dpp_pkex
|| !wpa_s
->dpp_pkex
->initiator
||
1446 wpa_s
->dpp_pkex
->exchange_done
) {
1447 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
1451 os_memcpy(wpa_s
->dpp_pkex
->peer_mac
, src
, ETH_ALEN
);
1452 msg
= dpp_pkex_rx_exchange_resp(wpa_s
->dpp_pkex
, buf
, len
);
1454 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the response");
1458 wpa_printf(MSG_DEBUG
, "DPP: Send PKEX Commit-Reveal Request to " MACSTR
,
1461 wait_time
= wpa_s
->max_remain_on_chan
;
1462 if (wait_time
> 2000)
1464 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
1466 wpabuf_head(msg
), wpabuf_len(msg
),
1467 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1473 wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1474 const u8
*buf
, size_t len
, unsigned int freq
)
1477 unsigned int wait_time
;
1478 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1479 struct dpp_bootstrap_info
*bi
;
1481 wpa_printf(MSG_DEBUG
, "DPP: PKEX Commit-Reveal Request from " MACSTR
,
1484 if (!pkex
|| pkex
->initiator
|| !pkex
->exchange_done
) {
1485 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
1489 msg
= dpp_pkex_rx_commit_reveal_req(pkex
, buf
, len
);
1491 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the request");
1495 wpa_printf(MSG_DEBUG
, "DPP: Send PKEX Commit-Reveal Response to "
1496 MACSTR
, MAC2STR(src
));
1498 wait_time
= wpa_s
->max_remain_on_chan
;
1499 if (wait_time
> 2000)
1501 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
1503 wpabuf_head(msg
), wpabuf_len(msg
),
1504 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1507 bi
= os_zalloc(sizeof(*bi
));
1510 bi
->id
= wpas_dpp_next_id(wpa_s
);
1511 bi
->type
= DPP_BOOTSTRAP_PKEX
;
1512 os_memcpy(bi
->mac_addr
, src
, ETH_ALEN
);
1515 bi
->curve
= pkex
->own_bi
->curve
;
1516 bi
->pubkey
= pkex
->peer_bootstrap_key
;
1517 pkex
->peer_bootstrap_key
= NULL
;
1518 dpp_pkex_free(pkex
);
1519 wpa_s
->dpp_pkex
= NULL
;
1520 if (dpp_bootstrap_key_hash(bi
) < 0) {
1521 dpp_bootstrap_info_free(bi
);
1524 dl_list_add(&wpa_s
->dpp_bootstrap
, &bi
->list
);
1529 wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1530 const u8
*buf
, size_t len
,
1534 struct dpp_bootstrap_info
*bi
, *own_bi
;
1535 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1538 wpa_printf(MSG_DEBUG
, "DPP: PKEX Commit-Reveal Response from " MACSTR
,
1541 if (!pkex
|| !pkex
->initiator
|| !pkex
->exchange_done
) {
1542 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
1546 res
= dpp_pkex_rx_commit_reveal_resp(pkex
, buf
, len
);
1548 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the response");
1552 own_bi
= pkex
->own_bi
;
1554 bi
= os_zalloc(sizeof(*bi
));
1557 bi
->id
= wpas_dpp_next_id(wpa_s
);
1558 bi
->type
= DPP_BOOTSTRAP_PKEX
;
1559 os_memcpy(bi
->mac_addr
, src
, ETH_ALEN
);
1562 bi
->curve
= own_bi
->curve
;
1563 bi
->pubkey
= pkex
->peer_bootstrap_key
;
1564 pkex
->peer_bootstrap_key
= NULL
;
1565 dpp_pkex_free(pkex
);
1566 wpa_s
->dpp_pkex
= NULL
;
1567 if (dpp_bootstrap_key_hash(bi
) < 0) {
1568 dpp_bootstrap_info_free(bi
);
1571 dl_list_add(&wpa_s
->dpp_bootstrap
, &bi
->list
);
1573 os_snprintf(cmd
, sizeof(cmd
), " peer=%u %s",
1575 wpa_s
->dpp_pkex_auth_cmd
? wpa_s
->dpp_pkex_auth_cmd
: "");
1576 wpa_printf(MSG_DEBUG
,
1577 "DPP: Start authentication after PKEX with parameters: %s",
1579 if (wpas_dpp_auth_init(wpa_s
, cmd
) < 0) {
1580 wpa_printf(MSG_DEBUG
,
1581 "DPP: Authentication initialization failed");
1587 void wpas_dpp_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1588 const u8
*buf
, size_t len
, unsigned int freq
)
1591 enum dpp_public_action_frame_type type
;
1595 crypto_suite
= *buf
++;
1599 wpa_printf(MSG_DEBUG
,
1600 "DPP: Received DPP Public Action frame crypto suite %u type %d from "
1602 crypto_suite
, type
, MAC2STR(src
), freq
);
1603 if (crypto_suite
!= 1) {
1604 wpa_printf(MSG_DEBUG
, "DPP: Unsupported crypto suite %u",
1608 wpa_hexdump(MSG_MSGDUMP
, "DPP: Received message attributes", buf
, len
);
1609 if (dpp_check_attrs(buf
, len
) < 0)
1613 case DPP_PA_AUTHENTICATION_REQ
:
1614 wpas_dpp_rx_auth_req(wpa_s
, src
, buf
, len
, freq
);
1616 case DPP_PA_AUTHENTICATION_RESP
:
1617 wpas_dpp_rx_auth_resp(wpa_s
, src
, buf
, len
);
1619 case DPP_PA_AUTHENTICATION_CONF
:
1620 wpas_dpp_rx_auth_conf(wpa_s
, src
, buf
, len
);
1622 case DPP_PA_PEER_DISCOVERY_RESP
:
1623 wpas_dpp_rx_peer_disc_resp(wpa_s
, src
, buf
, len
);
1625 case DPP_PA_PKEX_EXCHANGE_REQ
:
1626 wpas_dpp_rx_pkex_exchange_req(wpa_s
, src
, buf
, len
, freq
);
1628 case DPP_PA_PKEX_EXCHANGE_RESP
:
1629 wpas_dpp_rx_pkex_exchange_resp(wpa_s
, src
, buf
, len
, freq
);
1631 case DPP_PA_PKEX_COMMIT_REVEAL_REQ
:
1632 wpas_dpp_rx_pkex_commit_reveal_req(wpa_s
, src
, buf
, len
, freq
);
1634 case DPP_PA_PKEX_COMMIT_REVEAL_RESP
:
1635 wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s
, src
, buf
, len
, freq
);
1638 wpa_printf(MSG_DEBUG
,
1639 "DPP: Ignored unsupported frame subtype %d", type
);
1645 static struct wpabuf
*
1646 wpas_dpp_gas_req_handler(void *ctx
, const u8
*sa
, const u8
*query
,
1649 struct wpa_supplicant
*wpa_s
= ctx
;
1650 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1651 struct wpabuf
*resp
;
1653 wpa_printf(MSG_DEBUG
, "DPP: GAS request from " MACSTR
,
1655 if (!auth
|| !auth
->auth_success
||
1656 os_memcmp(sa
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1657 wpa_printf(MSG_DEBUG
, "DPP: No matching exchange in progress");
1660 wpa_hexdump(MSG_DEBUG
,
1661 "DPP: Received Configuration Request (GAS Query Request)",
1663 resp
= dpp_conf_req_rx(auth
, query
, query_len
);
1665 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1671 wpas_dpp_gas_status_handler(void *ctx
, struct wpabuf
*resp
, int ok
)
1673 struct wpa_supplicant
*wpa_s
= ctx
;
1674 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1681 wpa_printf(MSG_DEBUG
, "DPP: Configuration exchange completed (ok=%d)",
1683 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
1684 offchannel_send_action_done(wpa_s
);
1685 wpas_dpp_listen_stop(wpa_s
);
1687 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_SENT
);
1689 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1690 dpp_auth_deinit(wpa_s
->dpp_auth
);
1691 wpa_s
->dpp_auth
= NULL
;
1696 static unsigned int wpas_dpp_next_configurator_id(struct wpa_supplicant
*wpa_s
)
1698 struct dpp_configurator
*conf
;
1699 unsigned int max_id
= 0;
1701 dl_list_for_each(conf
, &wpa_s
->dpp_configurator
,
1702 struct dpp_configurator
, list
) {
1703 if (conf
->id
> max_id
)
1710 int wpas_dpp_configurator_add(struct wpa_supplicant
*wpa_s
, const char *cmd
)
1715 size_t privkey_len
= 0;
1717 struct dpp_configurator
*conf
= NULL
;
1719 curve
= get_param(cmd
, " curve=");
1720 key
= get_param(cmd
, " key=");
1723 privkey_len
= os_strlen(key
) / 2;
1724 privkey
= os_malloc(privkey_len
);
1726 hexstr2bin(key
, privkey
, privkey_len
) < 0)
1730 conf
= dpp_keygen_configurator(curve
, privkey
, privkey_len
);
1734 conf
->id
= wpas_dpp_next_configurator_id(wpa_s
);
1735 dl_list_add(&wpa_s
->dpp_configurator
, &conf
->list
);
1740 str_clear_free(key
);
1741 bin_clear_free(privkey
, privkey_len
);
1742 dpp_configurator_free(conf
);
1747 static int dpp_configurator_del(struct wpa_supplicant
*wpa_s
, unsigned int id
)
1749 struct dpp_configurator
*conf
, *tmp
;
1752 dl_list_for_each_safe(conf
, tmp
, &wpa_s
->dpp_configurator
,
1753 struct dpp_configurator
, list
) {
1754 if (id
&& conf
->id
!= id
)
1757 dl_list_del(&conf
->list
);
1758 dpp_configurator_free(conf
);
1762 return 0; /* flush succeeds regardless of entries found */
1763 return found
? 0 : -1;
1767 int wpas_dpp_configurator_remove(struct wpa_supplicant
*wpa_s
, const char *id
)
1769 unsigned int id_val
;
1771 if (os_strcmp(id
, "*") == 0) {
1779 return dpp_configurator_del(wpa_s
, id_val
);
1783 int wpas_dpp_configurator_sign(struct wpa_supplicant
*wpa_s
, const char *cmd
)
1785 struct dpp_authentication
*auth
;
1789 auth
= os_zalloc(sizeof(*auth
));
1793 curve
= get_param(cmd
, " curve=");
1794 wpas_dpp_set_configurator(wpa_s
, auth
, cmd
);
1796 if (dpp_configurator_own_config(auth
, curve
) == 0) {
1797 wpas_dpp_handle_config_obj(wpa_s
, auth
);
1801 dpp_auth_deinit(auth
);
1809 wpas_dpp_tx_introduction_status(struct wpa_supplicant
*wpa_s
,
1810 unsigned int freq
, const u8
*dst
,
1811 const u8
*src
, const u8
*bssid
,
1812 const u8
*data
, size_t data_len
,
1813 enum offchannel_send_action_result result
)
1815 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
1816 " result=%s (DPP Peer Discovery Request)",
1818 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
1819 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
1821 /* TODO: Time out wait for response more quickly in error cases? */
1825 int wpas_dpp_check_connect(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
1826 struct wpa_bss
*bss
)
1830 unsigned int wait_time
;
1832 if (!(ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) || !bss
)
1833 return 0; /* Not using DPP AKM - continue */
1834 if (wpa_sm_pmksa_exists(wpa_s
->wpa
, bss
->bssid
, ssid
))
1835 return 0; /* PMKSA exists for DPP AKM - continue */
1837 if (!ssid
->dpp_connector
|| !ssid
->dpp_netaccesskey
||
1839 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_MISSING_CONNECTOR
1841 !ssid
->dpp_connector
? "Connector" :
1842 (!ssid
->dpp_netaccesskey
? "netAccessKey" :
1849 if (ssid
->dpp_netaccesskey_expiry
&&
1850 ssid
->dpp_netaccesskey_expiry
< now
.sec
) {
1851 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_MISSING_CONNECTOR
1852 "netAccessKey expired");
1856 wpa_printf(MSG_DEBUG
,
1857 "DPP: Starting network introduction protocol to derive PMKSA for "
1858 MACSTR
, MAC2STR(bss
->bssid
));
1860 msg
= dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ
,
1861 5 + 4 + os_strlen(ssid
->dpp_connector
));
1865 /* Transaction ID */
1866 wpabuf_put_le16(msg
, DPP_ATTR_TRANSACTION_ID
);
1867 wpabuf_put_le16(msg
, 1);
1868 wpabuf_put_u8(msg
, TRANSACTION_ID
);
1871 wpabuf_put_le16(msg
, DPP_ATTR_CONNECTOR
);
1872 wpabuf_put_le16(msg
, os_strlen(ssid
->dpp_connector
));
1873 wpabuf_put_str(msg
, ssid
->dpp_connector
);
1875 /* TODO: Timeout on AP response */
1876 wait_time
= wpa_s
->max_remain_on_chan
;
1877 if (wait_time
> 2000)
1879 offchannel_send_action(wpa_s
, bss
->freq
, bss
->bssid
, wpa_s
->own_addr
,
1881 wpabuf_head(msg
), wpabuf_len(msg
),
1882 wait_time
, wpas_dpp_tx_introduction_status
, 0);
1885 /* Request this connection attempt to terminate - new one will be
1886 * started when network introduction protocol completes */
1887 os_memcpy(wpa_s
->dpp_intro_bssid
, bss
->bssid
, ETH_ALEN
);
1888 wpa_s
->dpp_intro_network
= ssid
;
1893 int wpas_dpp_pkex_add(struct wpa_supplicant
*wpa_s
, const char *cmd
)
1895 struct dpp_bootstrap_info
*own_bi
;
1896 const char *pos
, *end
;
1897 unsigned int wait_time
;
1899 pos
= os_strstr(cmd
, " own=");
1903 own_bi
= dpp_bootstrap_get_id(wpa_s
, atoi(pos
));
1905 wpa_printf(MSG_DEBUG
,
1906 "DPP: Identified bootstrap info not found");
1909 if (own_bi
->type
!= DPP_BOOTSTRAP_PKEX
) {
1910 wpa_printf(MSG_DEBUG
,
1911 "DPP: Identified bootstrap info not for PKEX");
1914 wpa_s
->dpp_pkex_bi
= own_bi
;
1916 os_free(wpa_s
->dpp_pkex_identifier
);
1917 wpa_s
->dpp_pkex_identifier
= NULL
;
1918 pos
= os_strstr(cmd
, " identifier=");
1921 end
= os_strchr(pos
, ' ');
1924 wpa_s
->dpp_pkex_identifier
= os_malloc(end
- pos
+ 1);
1925 if (!wpa_s
->dpp_pkex_identifier
)
1927 os_memcpy(wpa_s
->dpp_pkex_identifier
, pos
, end
- pos
);
1928 wpa_s
->dpp_pkex_identifier
[end
- pos
] = '\0';
1931 pos
= os_strstr(cmd
, " code=");
1934 os_free(wpa_s
->dpp_pkex_code
);
1935 wpa_s
->dpp_pkex_code
= os_strdup(pos
+ 6);
1936 if (!wpa_s
->dpp_pkex_code
)
1939 if (os_strstr(cmd
, " init=1")) {
1942 wpa_printf(MSG_DEBUG
, "DPP: Initiating PKEX");
1943 dpp_pkex_free(wpa_s
->dpp_pkex
);
1944 wpa_s
->dpp_pkex
= dpp_pkex_init(own_bi
, wpa_s
->own_addr
,
1945 wpa_s
->dpp_pkex_identifier
,
1946 wpa_s
->dpp_pkex_code
);
1947 if (!wpa_s
->dpp_pkex
)
1950 msg
= wpa_s
->dpp_pkex
->exchange_req
;
1951 wait_time
= wpa_s
->max_remain_on_chan
;
1952 if (wait_time
> 2000)
1954 /* TODO: Which channel to use? */
1955 offchannel_send_action(wpa_s
, 2437, broadcast
, wpa_s
->own_addr
,
1957 wpabuf_head(msg
), wpabuf_len(msg
),
1958 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1961 /* TODO: Support multiple PKEX info entries */
1963 os_free(wpa_s
->dpp_pkex_auth_cmd
);
1964 wpa_s
->dpp_pkex_auth_cmd
= os_strdup(cmd
);
1970 int wpas_dpp_pkex_remove(struct wpa_supplicant
*wpa_s
, const char *id
)
1972 unsigned int id_val
;
1974 if (os_strcmp(id
, "*") == 0) {
1982 if ((id_val
!= 0 && id_val
!= 1) || !wpa_s
->dpp_pkex_code
)
1985 /* TODO: Support multiple PKEX entries */
1986 os_free(wpa_s
->dpp_pkex_code
);
1987 wpa_s
->dpp_pkex_code
= NULL
;
1988 os_free(wpa_s
->dpp_pkex_identifier
);
1989 wpa_s
->dpp_pkex_identifier
= NULL
;
1990 os_free(wpa_s
->dpp_pkex_auth_cmd
);
1991 wpa_s
->dpp_pkex_auth_cmd
= NULL
;
1992 wpa_s
->dpp_pkex_bi
= NULL
;
1993 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
1994 dpp_pkex_free(wpa_s
->dpp_pkex
);
1995 wpa_s
->dpp_pkex
= NULL
;
2000 int wpas_dpp_init(struct wpa_supplicant
*wpa_s
)
2004 adv_proto_id
[0] = WLAN_EID_VENDOR_SPECIFIC
;
2005 adv_proto_id
[1] = 5;
2006 WPA_PUT_BE24(&adv_proto_id
[2], OUI_WFA
);
2007 adv_proto_id
[5] = DPP_OUI_TYPE
;
2008 adv_proto_id
[6] = 0x01;
2010 if (gas_server_register(wpa_s
->gas_server
, adv_proto_id
,
2011 sizeof(adv_proto_id
), wpas_dpp_gas_req_handler
,
2012 wpas_dpp_gas_status_handler
, wpa_s
) < 0)
2014 dl_list_init(&wpa_s
->dpp_bootstrap
);
2015 dl_list_init(&wpa_s
->dpp_configurator
);
2016 wpa_s
->dpp_init_done
= 1;
2021 void wpas_dpp_deinit(struct wpa_supplicant
*wpa_s
)
2023 #ifdef CONFIG_TESTING_OPTIONS
2024 os_free(wpa_s
->dpp_config_obj_override
);
2025 wpa_s
->dpp_config_obj_override
= NULL
;
2026 os_free(wpa_s
->dpp_discovery_override
);
2027 wpa_s
->dpp_discovery_override
= NULL
;
2028 os_free(wpa_s
->dpp_groups_override
);
2029 wpa_s
->dpp_groups_override
= NULL
;
2030 wpa_s
->dpp_ignore_netaccesskey_mismatch
= 0;
2031 #endif /* CONFIG_TESTING_OPTIONS */
2032 if (!wpa_s
->dpp_init_done
)
2034 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
2035 offchannel_send_action_done(wpa_s
);
2036 wpas_dpp_listen_stop(wpa_s
);
2037 dpp_bootstrap_del(wpa_s
, 0);
2038 dpp_configurator_del(wpa_s
, 0);
2039 dpp_auth_deinit(wpa_s
->dpp_auth
);
2040 wpa_s
->dpp_auth
= NULL
;
2041 wpas_dpp_pkex_remove(wpa_s
, "*");
2042 wpa_s
->dpp_pkex
= NULL
;
2043 os_memset(wpa_s
->dpp_intro_bssid
, 0, ETH_ALEN
);
2044 os_free(wpa_s
->dpp_configurator_params
);
2045 wpa_s
->dpp_configurator_params
= NULL
;