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) {
95 "DPP: Sending out pending authentication response");
96 offchannel_send_action(wpa_s
, auth
->curr_freq
,
97 auth
->peer_mac_addr
, wpa_s
->own_addr
,
99 wpabuf_head(auth
->resp_msg
),
100 wpabuf_len(auth
->resp_msg
),
101 500, wpas_dpp_tx_status
, 0);
108 static char * get_param(const char *cmd
, const char *param
)
110 const char *pos
, *end
;
114 pos
= os_strstr(cmd
, param
);
118 pos
+= os_strlen(param
);
119 end
= os_strchr(pos
, ' ');
123 len
= os_strlen(pos
);
124 val
= os_malloc(len
+ 1);
127 os_memcpy(val
, pos
, len
);
133 int wpas_dpp_bootstrap_gen(struct wpa_supplicant
*wpa_s
, const char *cmd
)
135 char *chan
= NULL
, *mac
= NULL
, *info
= NULL
, *pk
= NULL
, *curve
= NULL
;
138 size_t privkey_len
= 0;
141 struct dpp_bootstrap_info
*bi
;
143 bi
= os_zalloc(sizeof(*bi
));
147 if (os_strstr(cmd
, "type=qrcode"))
148 bi
->type
= DPP_BOOTSTRAP_QR_CODE
;
149 else if (os_strstr(cmd
, "type=pkex"))
150 bi
->type
= DPP_BOOTSTRAP_PKEX
;
154 chan
= get_param(cmd
, " chan=");
155 mac
= get_param(cmd
, " mac=");
156 info
= get_param(cmd
, " info=");
157 curve
= get_param(cmd
, " curve=");
158 key
= get_param(cmd
, " key=");
161 privkey_len
= os_strlen(key
) / 2;
162 privkey
= os_malloc(privkey_len
);
164 hexstr2bin(key
, privkey
, privkey_len
) < 0)
168 pk
= dpp_keygen(bi
, curve
, privkey
, privkey_len
);
172 len
= 4; /* "DPP:" */
174 if (dpp_parse_uri_chan_list(bi
, chan
) < 0)
176 len
+= 3 + os_strlen(chan
); /* C:...; */
179 if (dpp_parse_uri_mac(bi
, mac
) < 0)
181 len
+= 3 + os_strlen(mac
); /* M:...; */
184 if (dpp_parse_uri_info(bi
, info
) < 0)
186 len
+= 3 + os_strlen(info
); /* I:...; */
188 len
+= 4 + os_strlen(pk
);
189 bi
->uri
= os_malloc(len
+ 1);
192 os_snprintf(bi
->uri
, len
+ 1, "DPP:%s%s%s%s%s%s%s%s%sK:%s;;",
193 chan
? "C:" : "", chan
? chan
: "", chan
? ";" : "",
194 mac
? "M:" : "", mac
? mac
: "", mac
? ";" : "",
195 info
? "I:" : "", info
? info
: "", info
? ";" : "",
197 bi
->id
= wpas_dpp_next_id(wpa_s
);
198 dl_list_add(&wpa_s
->dpp_bootstrap
, &bi
->list
);
208 bin_clear_free(privkey
, privkey_len
);
209 dpp_bootstrap_info_free(bi
);
214 static struct dpp_bootstrap_info
*
215 dpp_bootstrap_get_id(struct wpa_supplicant
*wpa_s
, unsigned int id
)
217 struct dpp_bootstrap_info
*bi
;
219 dl_list_for_each(bi
, &wpa_s
->dpp_bootstrap
, struct dpp_bootstrap_info
,
228 static int dpp_bootstrap_del(struct wpa_supplicant
*wpa_s
, unsigned int id
)
230 struct dpp_bootstrap_info
*bi
, *tmp
;
233 dl_list_for_each_safe(bi
, tmp
, &wpa_s
->dpp_bootstrap
,
234 struct dpp_bootstrap_info
, list
) {
235 if (id
&& bi
->id
!= id
)
238 dl_list_del(&bi
->list
);
239 dpp_bootstrap_info_free(bi
);
243 return 0; /* flush succeeds regardless of entries found */
244 return found
? 0 : -1;
248 int wpas_dpp_bootstrap_remove(struct wpa_supplicant
*wpa_s
, const char *id
)
252 if (os_strcmp(id
, "*") == 0) {
260 return dpp_bootstrap_del(wpa_s
, id_val
);
264 const char * wpas_dpp_bootstrap_get_uri(struct wpa_supplicant
*wpa_s
,
267 struct dpp_bootstrap_info
*bi
;
269 bi
= dpp_bootstrap_get_id(wpa_s
, id
);
276 int wpas_dpp_bootstrap_info(struct wpa_supplicant
*wpa_s
, int id
,
277 char *reply
, int reply_size
)
279 struct dpp_bootstrap_info
*bi
;
281 bi
= dpp_bootstrap_get_id(wpa_s
, id
);
284 return os_snprintf(reply
, reply_size
, "type=%s\n"
285 "mac_addr=" MACSTR
"\n"
289 dpp_bootstrap_type_txt(bi
->type
),
290 MAC2STR(bi
->mac_addr
),
291 bi
->info
? bi
->info
: "",
297 static void wpas_dpp_tx_status(struct wpa_supplicant
*wpa_s
,
298 unsigned int freq
, const u8
*dst
,
299 const u8
*src
, const u8
*bssid
,
300 const u8
*data
, size_t data_len
,
301 enum offchannel_send_action_result result
)
303 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
306 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
307 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
310 if (!wpa_s
->dpp_auth
) {
311 wpa_printf(MSG_DEBUG
,
312 "DPP: Ignore TX status since there is no ongoing authentication exchange");
316 if (wpa_s
->dpp_auth
->remove_on_tx_status
) {
317 wpa_printf(MSG_DEBUG
,
318 "DPP: Terminate authentication exchange due to an earlier error");
319 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
320 offchannel_send_action_done(wpa_s
);
321 dpp_auth_deinit(wpa_s
->dpp_auth
);
322 wpa_s
->dpp_auth
= NULL
;
326 if (wpa_s
->dpp_auth_ok_on_ack
)
327 wpas_dpp_auth_success(wpa_s
, 1);
329 if (!is_broadcast_ether_addr(dst
) &&
330 result
!= OFFCHANNEL_SEND_ACTION_SUCCESS
) {
331 wpa_printf(MSG_DEBUG
,
332 "DPP: Unicast DPP Action frame was not ACKed");
333 /* TODO: In case of DPP Authentication Request frame, move to
334 * the next channel immediately */
339 static void wpas_dpp_reply_wait_timeout(void *eloop_ctx
, void *timeout_ctx
)
341 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
343 if (!wpa_s
->dpp_auth
)
345 wpa_printf(MSG_DEBUG
, "DPP: Continue reply wait on channel %u MHz",
346 wpa_s
->dpp_auth
->curr_freq
);
347 wpas_dpp_listen_start(wpa_s
, wpa_s
->dpp_auth
->curr_freq
);
351 static void wpas_dpp_set_testing_options(struct wpa_supplicant
*wpa_s
,
352 struct dpp_authentication
*auth
)
354 #ifdef CONFIG_TESTING_OPTIONS
355 if (wpa_s
->dpp_config_obj_override
)
356 auth
->config_obj_override
=
357 os_strdup(wpa_s
->dpp_config_obj_override
);
358 if (wpa_s
->dpp_discovery_override
)
359 auth
->discovery_override
=
360 os_strdup(wpa_s
->dpp_discovery_override
);
361 if (wpa_s
->dpp_groups_override
)
362 auth
->groups_override
=
363 os_strdup(wpa_s
->dpp_groups_override
);
364 auth
->ignore_netaccesskey_mismatch
=
365 wpa_s
->dpp_ignore_netaccesskey_mismatch
;
366 #endif /* CONFIG_TESTING_OPTIONS */
370 static void wpas_dpp_set_configurator(struct wpa_supplicant
*wpa_s
,
371 struct dpp_authentication
*auth
,
374 const char *pos
, *end
;
375 struct dpp_configuration
*conf_sta
= NULL
, *conf_ap
= NULL
;
376 struct dpp_configurator
*conf
= NULL
;
377 u8 ssid
[32] = { "test" };
387 wpa_printf(MSG_DEBUG
, "DPP: Set configurator parameters: %s", cmd
);
388 pos
= os_strstr(cmd
, " ssid=");
391 end
= os_strchr(pos
, ' ');
392 ssid_len
= end
? (size_t) (end
- pos
) : os_strlen(pos
);
394 if (ssid_len
> sizeof(ssid
) ||
395 hexstr2bin(pos
, ssid
, ssid_len
) < 0)
399 pos
= os_strstr(cmd
, " pass=");
402 end
= os_strchr(pos
, ' ');
403 pass_len
= end
? (size_t) (end
- pos
) : os_strlen(pos
);
405 if (pass_len
> sizeof(pass
) - 1 || pass_len
< 8 ||
406 hexstr2bin(pos
, (u8
*) pass
, pass_len
) < 0)
410 pos
= os_strstr(cmd
, " psk=");
413 if (hexstr2bin(pos
, psk
, PMK_LEN
) < 0)
418 if (os_strstr(cmd
, " conf=sta-")) {
419 conf_sta
= os_zalloc(sizeof(struct dpp_configuration
));
422 os_memcpy(conf_sta
->ssid
, ssid
, ssid_len
);
423 conf_sta
->ssid_len
= ssid_len
;
424 if (os_strstr(cmd
, " conf=sta-psk")) {
427 os_memcpy(conf_sta
->psk
, psk
, PMK_LEN
);
429 conf_sta
->passphrase
= os_strdup(pass
);
430 if (!conf_sta
->passphrase
)
433 } else if (os_strstr(cmd
, " conf=sta-dpp")) {
440 if (os_strstr(cmd
, " conf=ap-")) {
441 conf_ap
= os_zalloc(sizeof(struct dpp_configuration
));
444 os_memcpy(conf_ap
->ssid
, ssid
, ssid_len
);
445 conf_ap
->ssid_len
= ssid_len
;
446 if (os_strstr(cmd
, " conf=ap-psk")) {
449 os_memcpy(conf_ap
->psk
, psk
, PMK_LEN
);
451 conf_ap
->passphrase
= os_strdup(pass
);
452 if (!conf_ap
->passphrase
)
455 } else if (os_strstr(cmd
, " conf=ap-dpp")) {
462 pos
= os_strstr(cmd
, " expiry=");
467 val
= strtol(pos
, NULL
, 0);
471 conf_sta
->netaccesskey_expiry
= val
;
473 conf_ap
->netaccesskey_expiry
= val
;
476 pos
= os_strstr(cmd
, " configurator=");
479 conf
= dpp_configurator_get_id(wpa_s
, atoi(pos
));
482 "DPP: Could not find the specified configurator");
486 auth
->conf_sta
= conf_sta
;
487 auth
->conf_ap
= conf_ap
;
492 wpa_printf(MSG_DEBUG
, "DPP: Failed to set configurator parameters");
493 dpp_configuration_free(conf_sta
);
494 dpp_configuration_free(conf_ap
);
498 int wpas_dpp_auth_init(struct wpa_supplicant
*wpa_s
, const char *cmd
)
501 struct dpp_bootstrap_info
*peer_bi
, *own_bi
= NULL
;
504 int configurator
= 1;
505 unsigned int wait_time
;
507 wpa_s
->dpp_gas_client
= 0;
509 pos
= os_strstr(cmd
, " peer=");
513 peer_bi
= dpp_bootstrap_get_id(wpa_s
, atoi(pos
));
516 "DPP: Could not find bootstrapping info for the identified peer");
520 pos
= os_strstr(cmd
, " own=");
523 own_bi
= dpp_bootstrap_get_id(wpa_s
, atoi(pos
));
526 "DPP: Could not find bootstrapping info for the identified local entry");
530 if (peer_bi
->curve
!= own_bi
->curve
) {
532 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
533 peer_bi
->curve
->name
, own_bi
->curve
->name
);
538 pos
= os_strstr(cmd
, " role=");
541 if (os_strncmp(pos
, "configurator", 12) == 0)
543 else if (os_strncmp(pos
, "enrollee", 8) == 0)
549 pos
= os_strstr(cmd
, " netrole=");
552 wpa_s
->dpp_netrole_ap
= os_strncmp(pos
, "ap", 2) == 0;
555 if (wpa_s
->dpp_auth
) {
556 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
557 offchannel_send_action_done(wpa_s
);
558 dpp_auth_deinit(wpa_s
->dpp_auth
);
560 wpa_s
->dpp_auth
= dpp_auth_init(wpa_s
, peer_bi
, own_bi
, configurator
);
561 if (!wpa_s
->dpp_auth
)
563 wpas_dpp_set_testing_options(wpa_s
, wpa_s
->dpp_auth
);
564 wpas_dpp_set_configurator(wpa_s
, wpa_s
->dpp_auth
, cmd
);
566 /* TODO: Support iteration over all frequencies and filtering of
567 * frequencies based on locally enabled channels that allow initiation
568 * of transmission. */
569 if (peer_bi
->num_freq
> 0)
570 wpa_s
->dpp_auth
->curr_freq
= peer_bi
->freq
[0];
572 wpa_s
->dpp_auth
->curr_freq
= 2412;
574 if (is_zero_ether_addr(peer_bi
->mac_addr
)) {
577 dst
= peer_bi
->mac_addr
;
578 os_memcpy(wpa_s
->dpp_auth
->peer_mac_addr
, peer_bi
->mac_addr
,
581 wpa_s
->dpp_auth_ok_on_ack
= 0;
582 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
583 wait_time
= wpa_s
->max_remain_on_chan
;
584 if (wait_time
> 2000)
586 eloop_register_timeout(wait_time
/ 1000, (wait_time
% 1000) * 1000,
587 wpas_dpp_reply_wait_timeout
,
589 res
= offchannel_send_action(wpa_s
, wpa_s
->dpp_auth
->curr_freq
,
590 dst
, wpa_s
->own_addr
, broadcast
,
591 wpabuf_head(wpa_s
->dpp_auth
->req_msg
),
592 wpabuf_len(wpa_s
->dpp_auth
->req_msg
),
593 wait_time
, wpas_dpp_tx_status
, 0);
601 struct wpas_dpp_listen_work
{
603 unsigned int duration
;
604 struct wpabuf
*probe_resp_ie
;
608 static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work
*lwork
)
616 static void wpas_dpp_listen_work_done(struct wpa_supplicant
*wpa_s
)
618 struct wpas_dpp_listen_work
*lwork
;
620 if (!wpa_s
->dpp_listen_work
)
623 lwork
= wpa_s
->dpp_listen_work
->ctx
;
624 wpas_dpp_listen_work_free(lwork
);
625 radio_work_done(wpa_s
->dpp_listen_work
);
626 wpa_s
->dpp_listen_work
= NULL
;
630 static void dpp_start_listen_cb(struct wpa_radio_work
*work
, int deinit
)
632 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
633 struct wpas_dpp_listen_work
*lwork
= work
->ctx
;
637 wpa_s
->dpp_listen_work
= NULL
;
638 wpas_dpp_listen_stop(wpa_s
);
640 wpas_dpp_listen_work_free(lwork
);
644 wpa_s
->dpp_listen_work
= work
;
646 wpa_s
->dpp_pending_listen_freq
= lwork
->freq
;
648 if (wpa_drv_remain_on_channel(wpa_s
, lwork
->freq
,
649 wpa_s
->max_remain_on_chan
) < 0) {
650 wpa_printf(MSG_DEBUG
,
651 "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
653 wpas_dpp_listen_work_done(wpa_s
);
654 wpa_s
->dpp_pending_listen_freq
= 0;
657 wpa_s
->off_channel_freq
= 0;
658 wpa_s
->roc_waiting_drv_freq
= lwork
->freq
;
662 static int wpas_dpp_listen_start(struct wpa_supplicant
*wpa_s
,
665 struct wpas_dpp_listen_work
*lwork
;
667 if (wpa_s
->dpp_listen_work
) {
668 wpa_printf(MSG_DEBUG
,
669 "DPP: Reject start_listen since dpp_listen_work already exists");
673 if (wpa_s
->dpp_listen_freq
)
674 wpas_dpp_listen_stop(wpa_s
);
675 wpa_s
->dpp_listen_freq
= freq
;
677 lwork
= os_zalloc(sizeof(*lwork
));
682 if (radio_add_work(wpa_s
, freq
, "dpp-listen", 0, dpp_start_listen_cb
,
684 wpas_dpp_listen_work_free(lwork
);
692 int wpas_dpp_listen(struct wpa_supplicant
*wpa_s
, const char *cmd
)
700 if (os_strstr(cmd
, " role=configurator"))
701 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_CONFIGURATOR
;
702 else if (os_strstr(cmd
, " role=enrollee"))
703 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_ENROLLEE
;
705 wpa_s
->dpp_allowed_roles
= DPP_CAPAB_CONFIGURATOR
|
707 wpa_s
->dpp_qr_mutual
= os_strstr(cmd
, " qr=mutual") != NULL
;
708 wpa_s
->dpp_netrole_ap
= os_strstr(cmd
, " netrole=ap") != NULL
;
709 if (wpa_s
->dpp_listen_freq
== (unsigned int) freq
) {
710 wpa_printf(MSG_DEBUG
, "DPP: Already listening on %u MHz",
715 return wpas_dpp_listen_start(wpa_s
, freq
);
719 void wpas_dpp_listen_stop(struct wpa_supplicant
*wpa_s
)
721 if (!wpa_s
->dpp_listen_freq
)
724 wpa_printf(MSG_DEBUG
, "DPP: Stop listen on %u MHz",
725 wpa_s
->dpp_listen_freq
);
726 wpa_drv_cancel_remain_on_channel(wpa_s
);
727 wpa_s
->dpp_listen_freq
= 0;
728 wpas_dpp_listen_work_done(wpa_s
);
732 void wpas_dpp_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
735 if (!wpa_s
->dpp_listen_freq
&& !wpa_s
->dpp_pending_listen_freq
)
738 wpa_printf(MSG_DEBUG
,
739 "DPP: remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d roc_waiting_drv_freq=%d freq=%u)",
740 wpa_s
->off_channel_freq
, wpa_s
->dpp_pending_listen_freq
,
741 wpa_s
->roc_waiting_drv_freq
, freq
);
742 if (wpa_s
->off_channel_freq
&&
743 wpa_s
->off_channel_freq
== wpa_s
->dpp_pending_listen_freq
) {
744 wpa_printf(MSG_DEBUG
, "DPP: Listen on %u MHz started", freq
);
745 wpa_s
->dpp_pending_listen_freq
= 0;
747 wpa_printf(MSG_DEBUG
,
748 "DPP: Ignore remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d freq=%u)",
749 wpa_s
->off_channel_freq
,
750 wpa_s
->dpp_pending_listen_freq
, freq
);
755 void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
758 wpas_dpp_listen_work_done(wpa_s
);
760 if (wpa_s
->dpp_auth
&& !wpa_s
->dpp_gas_client
) {
761 /* Continue listen with a new remain-on-channel */
762 wpa_printf(MSG_DEBUG
,
763 "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
764 wpa_s
->dpp_auth
->curr_freq
);
765 wpas_dpp_listen_start(wpa_s
, wpa_s
->dpp_auth
->curr_freq
);
769 if (wpa_s
->dpp_listen_freq
) {
770 /* Continue listen with a new remain-on-channel */
771 wpas_dpp_listen_start(wpa_s
, wpa_s
->dpp_listen_freq
);
776 static void wpas_dpp_rx_auth_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
777 const u8
*hdr
, const u8
*buf
, size_t len
,
780 const u8
*r_bootstrap
, *i_bootstrap
, *wrapped_data
;
781 u16 r_bootstrap_len
, i_bootstrap_len
, wrapped_data_len
;
782 struct dpp_bootstrap_info
*bi
, *own_bi
= NULL
, *peer_bi
= NULL
;
784 wpa_printf(MSG_DEBUG
, "DPP: Authentication Request from " MACSTR
,
787 wrapped_data
= dpp_get_attr(buf
, len
, DPP_ATTR_WRAPPED_DATA
,
790 wpa_printf(MSG_DEBUG
,
791 "DPP: Missing required Wrapped data attribute");
794 wpa_hexdump(MSG_MSGDUMP
, "DPP: Wrapped data",
795 wrapped_data
, wrapped_data_len
);
797 r_bootstrap
= dpp_get_attr(buf
, len
, DPP_ATTR_R_BOOTSTRAP_KEY_HASH
,
799 if (!r_bootstrap
|| r_bootstrap
> wrapped_data
||
800 r_bootstrap_len
!= SHA256_MAC_LEN
) {
801 wpa_printf(MSG_DEBUG
,
802 "DPP: Missing or invalid required Responder Bootstrapping Key Hash attribute");
805 wpa_hexdump(MSG_MSGDUMP
, "DPP: Responder Bootstrapping Key Hash",
806 r_bootstrap
, r_bootstrap_len
);
808 i_bootstrap
= dpp_get_attr(buf
, len
, DPP_ATTR_I_BOOTSTRAP_KEY_HASH
,
810 if (!i_bootstrap
|| i_bootstrap
> wrapped_data
||
811 i_bootstrap_len
!= SHA256_MAC_LEN
) {
812 wpa_printf(MSG_DEBUG
,
813 "DPP: Missing or invalid required Initiator Bootstrapping Key Hash attribute");
816 wpa_hexdump(MSG_MSGDUMP
, "DPP: Initiator Bootstrapping Key Hash",
817 i_bootstrap
, i_bootstrap_len
);
819 /* Try to find own and peer bootstrapping key matches based on the
820 * received hash values */
821 dl_list_for_each(bi
, &wpa_s
->dpp_bootstrap
, struct dpp_bootstrap_info
,
823 if (!own_bi
&& bi
->own
&&
824 os_memcmp(bi
->pubkey_hash
, r_bootstrap
,
825 SHA256_MAC_LEN
) == 0) {
826 wpa_printf(MSG_DEBUG
,
827 "DPP: Found matching own bootstrapping information");
831 if (!peer_bi
&& !bi
->own
&&
832 os_memcmp(bi
->pubkey_hash
, i_bootstrap
,
833 SHA256_MAC_LEN
) == 0) {
834 wpa_printf(MSG_DEBUG
,
835 "DPP: Found matching peer bootstrapping information");
839 if (own_bi
&& peer_bi
)
844 wpa_printf(MSG_DEBUG
,
845 "DPP: No matching own bootstrapping key found - ignore message");
849 if (wpa_s
->dpp_auth
) {
850 wpa_printf(MSG_DEBUG
,
851 "DPP: Already in DPP authentication exchange - ignore new one");
855 wpa_s
->dpp_gas_client
= 0;
856 wpa_s
->dpp_auth_ok_on_ack
= 0;
857 wpa_s
->dpp_auth
= dpp_auth_req_rx(wpa_s
, wpa_s
->dpp_allowed_roles
,
858 wpa_s
->dpp_qr_mutual
,
859 peer_bi
, own_bi
, freq
, hdr
, buf
,
860 wrapped_data
, wrapped_data_len
);
861 if (!wpa_s
->dpp_auth
) {
862 wpa_printf(MSG_DEBUG
, "DPP: No response generated");
865 wpas_dpp_set_testing_options(wpa_s
, wpa_s
->dpp_auth
);
866 wpas_dpp_set_configurator(wpa_s
, wpa_s
->dpp_auth
,
867 wpa_s
->dpp_configurator_params
);
868 os_memcpy(wpa_s
->dpp_auth
->peer_mac_addr
, src
, ETH_ALEN
);
870 offchannel_send_action(wpa_s
, wpa_s
->dpp_auth
->curr_freq
,
871 src
, wpa_s
->own_addr
, broadcast
,
872 wpabuf_head(wpa_s
->dpp_auth
->resp_msg
),
873 wpabuf_len(wpa_s
->dpp_auth
->resp_msg
),
874 500, wpas_dpp_tx_status
, 0);
878 static void wpas_dpp_start_gas_server(struct wpa_supplicant
*wpa_s
)
880 /* TODO: stop wait and start ROC */
884 static struct wpa_ssid
* wpas_dpp_add_network(struct wpa_supplicant
*wpa_s
,
885 struct dpp_authentication
*auth
)
887 struct wpa_ssid
*ssid
;
889 ssid
= wpa_config_add_network(wpa_s
->conf
);
892 wpas_notify_network_added(wpa_s
, ssid
);
893 wpa_config_set_network_defaults(ssid
);
896 ssid
->ssid
= os_malloc(auth
->ssid_len
);
899 os_memcpy(ssid
->ssid
, auth
->ssid
, auth
->ssid_len
);
900 ssid
->ssid_len
= auth
->ssid_len
;
902 if (auth
->connector
) {
903 ssid
->key_mgmt
= WPA_KEY_MGMT_DPP
;
904 ssid
->dpp_connector
= os_strdup(auth
->connector
);
905 if (!ssid
->dpp_connector
)
909 if (auth
->c_sign_key
) {
910 ssid
->dpp_csign
= os_malloc(wpabuf_len(auth
->c_sign_key
));
911 if (!ssid
->dpp_csign
)
913 os_memcpy(ssid
->dpp_csign
, wpabuf_head(auth
->c_sign_key
),
914 wpabuf_len(auth
->c_sign_key
));
915 ssid
->dpp_csign_len
= wpabuf_len(auth
->c_sign_key
);
918 if (auth
->net_access_key
) {
919 ssid
->dpp_netaccesskey
=
920 os_malloc(wpabuf_len(auth
->net_access_key
));
921 if (!ssid
->dpp_netaccesskey
)
923 os_memcpy(ssid
->dpp_netaccesskey
,
924 wpabuf_head(auth
->net_access_key
),
925 wpabuf_len(auth
->net_access_key
));
926 ssid
->dpp_netaccesskey_len
= wpabuf_len(auth
->net_access_key
);
927 ssid
->dpp_netaccesskey_expiry
= auth
->net_access_key_expiry
;
930 if (!auth
->connector
) {
931 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
932 if (auth
->passphrase
[0]) {
933 if (wpa_config_set_quoted(ssid
, "psk",
934 auth
->passphrase
) < 0)
936 wpa_config_update_psk(ssid
);
937 ssid
->export_keys
= 1;
939 ssid
->psk_set
= auth
->psk_set
;
940 os_memcpy(ssid
->psk
, auth
->psk
, PMK_LEN
);
946 wpas_notify_network_removed(wpa_s
, ssid
);
947 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
952 static void wpas_dpp_process_config(struct wpa_supplicant
*wpa_s
,
953 struct dpp_authentication
*auth
)
955 struct wpa_ssid
*ssid
;
957 if (wpa_s
->conf
->dpp_config_processing
< 1)
960 ssid
= wpas_dpp_add_network(wpa_s
, auth
);
964 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_NETWORK_ID
"%d", ssid
->id
);
965 if (wpa_s
->conf
->dpp_config_processing
< 2)
968 wpa_printf(MSG_DEBUG
, "DPP: Trying to connect to the new network");
970 wpa_s
->disconnected
= 0;
971 wpa_s
->reassociate
= 1;
972 wpa_s
->scan_runs
= 0;
973 wpa_s
->normal_scans
= 0;
974 wpa_supplicant_cancel_sched_scan(wpa_s
);
975 wpa_supplicant_req_scan(wpa_s
, 0, 0);
979 static void wpas_dpp_handle_config_obj(struct wpa_supplicant
*wpa_s
,
980 struct dpp_authentication
*auth
)
982 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_RECEIVED
);
984 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONFOBJ_SSID
"%s",
985 wpa_ssid_txt(auth
->ssid
, auth
->ssid_len
));
986 if (auth
->connector
) {
987 /* TODO: Save the Connector and consider using a command
988 * to fetch the value instead of sending an event with
989 * it. The Connector could end up being larger than what
990 * most clients are ready to receive as an event
992 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONNECTOR
"%s",
995 if (auth
->c_sign_key
) {
999 hexlen
= 2 * wpabuf_len(auth
->c_sign_key
) + 1;
1000 hex
= os_malloc(hexlen
);
1002 wpa_snprintf_hex(hex
, hexlen
,
1003 wpabuf_head(auth
->c_sign_key
),
1004 wpabuf_len(auth
->c_sign_key
));
1005 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_C_SIGN_KEY
"%s",
1010 if (auth
->net_access_key
) {
1014 hexlen
= 2 * wpabuf_len(auth
->net_access_key
) + 1;
1015 hex
= os_malloc(hexlen
);
1017 wpa_snprintf_hex(hex
, hexlen
,
1018 wpabuf_head(auth
->net_access_key
),
1019 wpabuf_len(auth
->net_access_key
));
1020 if (auth
->net_access_key_expiry
)
1021 wpa_msg(wpa_s
, MSG_INFO
,
1022 DPP_EVENT_NET_ACCESS_KEY
"%s %lu", hex
,
1024 auth
->net_access_key_expiry
);
1026 wpa_msg(wpa_s
, MSG_INFO
,
1027 DPP_EVENT_NET_ACCESS_KEY
"%s", hex
);
1032 wpas_dpp_process_config(wpa_s
, auth
);
1036 static void wpas_dpp_gas_resp_cb(void *ctx
, const u8
*addr
, u8 dialog_token
,
1037 enum gas_query_result result
,
1038 const struct wpabuf
*adv_proto
,
1039 const struct wpabuf
*resp
, u16 status_code
)
1041 struct wpa_supplicant
*wpa_s
= ctx
;
1043 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1045 if (!auth
|| !auth
->auth_success
) {
1046 wpa_printf(MSG_DEBUG
, "DPP: No matching exchange in progress");
1049 if (!resp
|| status_code
!= WLAN_STATUS_SUCCESS
) {
1050 wpa_printf(MSG_DEBUG
, "DPP: GAS query did not succeed");
1054 wpa_hexdump_buf(MSG_DEBUG
, "DPP: Configuration Response adv_proto",
1056 wpa_hexdump_buf(MSG_DEBUG
, "DPP: Configuration Response (GAS response)",
1059 if (wpabuf_len(adv_proto
) != 10 ||
1060 !(pos
= wpabuf_head(adv_proto
)) ||
1061 pos
[0] != WLAN_EID_ADV_PROTO
||
1063 pos
[3] != WLAN_EID_VENDOR_SPECIFIC
||
1065 WPA_GET_BE24(&pos
[5]) != OUI_WFA
||
1068 wpa_printf(MSG_DEBUG
,
1069 "DPP: Not a DPP Advertisement Protocol ID");
1073 if (dpp_conf_resp_rx(auth
, resp
) < 0) {
1074 wpa_printf(MSG_DEBUG
, "DPP: Configuration attempt failed");
1078 wpas_dpp_handle_config_obj(wpa_s
, auth
);
1079 dpp_auth_deinit(wpa_s
->dpp_auth
);
1080 wpa_s
->dpp_auth
= NULL
;
1084 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1085 dpp_auth_deinit(wpa_s
->dpp_auth
);
1086 wpa_s
->dpp_auth
= NULL
;
1090 static void wpas_dpp_start_gas_client(struct wpa_supplicant
*wpa_s
)
1092 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1093 struct wpabuf
*buf
, *conf_req
;
1097 wpa_s
->dpp_gas_client
= 1;
1098 os_snprintf(json
, sizeof(json
),
1099 "{\"name\":\"Test\","
1100 "\"wi-fi_tech\":\"infra\","
1101 "\"netRole\":\"%s\"}",
1102 wpa_s
->dpp_netrole_ap
? "ap" : "sta");
1103 wpa_printf(MSG_DEBUG
, "DPP: GAS Config Attributes: %s", json
);
1105 offchannel_send_action_done(wpa_s
);
1106 wpas_dpp_listen_stop(wpa_s
);
1108 conf_req
= dpp_build_conf_req(auth
, json
);
1110 wpa_printf(MSG_DEBUG
,
1111 "DPP: No configuration request data available");
1115 buf
= gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req
));
1117 wpabuf_free(conf_req
);
1121 /* Advertisement Protocol IE */
1122 wpabuf_put_u8(buf
, WLAN_EID_ADV_PROTO
);
1123 wpabuf_put_u8(buf
, 8); /* Length */
1124 wpabuf_put_u8(buf
, 0x7f);
1125 wpabuf_put_u8(buf
, WLAN_EID_VENDOR_SPECIFIC
);
1126 wpabuf_put_u8(buf
, 5);
1127 wpabuf_put_be24(buf
, OUI_WFA
);
1128 wpabuf_put_u8(buf
, DPP_OUI_TYPE
);
1129 wpabuf_put_u8(buf
, 0x01);
1132 wpabuf_put_le16(buf
, wpabuf_len(conf_req
));
1133 wpabuf_put_buf(buf
, conf_req
);
1134 wpabuf_free(conf_req
);
1136 wpa_printf(MSG_DEBUG
, "DPP: GAS request to " MACSTR
" (freq %u MHz)",
1137 MAC2STR(auth
->peer_mac_addr
), auth
->curr_freq
);
1139 res
= gas_query_req(wpa_s
->gas
, auth
->peer_mac_addr
, auth
->curr_freq
,
1140 buf
, wpas_dpp_gas_resp_cb
, wpa_s
);
1142 wpa_msg(wpa_s
, MSG_DEBUG
, "GAS: Failed to send Query Request");
1145 wpa_printf(MSG_DEBUG
,
1146 "DPP: GAS query started with dialog token %u", res
);
1151 static void wpas_dpp_auth_success(struct wpa_supplicant
*wpa_s
, int initiator
)
1153 wpa_printf(MSG_DEBUG
, "DPP: Authentication succeeded");
1154 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_AUTH_SUCCESS
"init=%d", initiator
);
1156 if (wpa_s
->dpp_auth
->configurator
)
1157 wpas_dpp_start_gas_server(wpa_s
);
1159 wpas_dpp_start_gas_client(wpa_s
);
1163 static void wpas_dpp_rx_auth_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1164 const u8
*hdr
, const u8
*buf
, size_t len
)
1166 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1169 wpa_printf(MSG_DEBUG
, "DPP: Authentication Response from " MACSTR
,
1173 wpa_printf(MSG_DEBUG
,
1174 "DPP: No DPP Authentication in progress - drop");
1178 if (!is_zero_ether_addr(auth
->peer_mac_addr
) &&
1179 os_memcmp(src
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1180 wpa_printf(MSG_DEBUG
, "DPP: MAC address mismatch (expected "
1181 MACSTR
") - drop", MAC2STR(auth
->peer_mac_addr
));
1185 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
1187 msg
= dpp_auth_resp_rx(auth
, hdr
, buf
, len
);
1189 if (auth
->auth_resp_status
== DPP_STATUS_RESPONSE_PENDING
) {
1190 wpa_printf(MSG_DEBUG
,
1191 "DPP: Start wait for full response");
1192 offchannel_send_action_done(wpa_s
);
1193 wpas_dpp_listen_start(wpa_s
, auth
->curr_freq
);
1196 wpa_printf(MSG_DEBUG
, "DPP: No confirm generated");
1199 os_memcpy(auth
->peer_mac_addr
, src
, ETH_ALEN
);
1201 offchannel_send_action(wpa_s
, auth
->curr_freq
,
1202 src
, wpa_s
->own_addr
, broadcast
,
1203 wpabuf_head(msg
), wpabuf_len(msg
),
1204 500, wpas_dpp_tx_status
, 0);
1206 wpa_s
->dpp_auth_ok_on_ack
= 1;
1210 static void wpas_dpp_rx_auth_conf(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1211 const u8
*hdr
, const u8
*buf
, size_t len
)
1213 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1215 wpa_printf(MSG_DEBUG
, "DPP: Authentication Confirmation from " MACSTR
,
1219 wpa_printf(MSG_DEBUG
,
1220 "DPP: No DPP Authentication in progress - drop");
1224 if (os_memcmp(src
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1225 wpa_printf(MSG_DEBUG
, "DPP: MAC address mismatch (expected "
1226 MACSTR
") - drop", MAC2STR(auth
->peer_mac_addr
));
1230 if (dpp_auth_conf_rx(auth
, hdr
, buf
, len
) < 0) {
1231 wpa_printf(MSG_DEBUG
, "DPP: Authentication failed");
1235 wpas_dpp_auth_success(wpa_s
, 0);
1239 static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant
*wpa_s
,
1241 const u8
*buf
, size_t len
)
1243 struct wpa_ssid
*ssid
;
1244 const u8
*connector
, *trans_id
;
1245 u16 connector_len
, trans_id_len
;
1246 struct dpp_introduction intro
;
1247 struct rsn_pmksa_cache_entry
*entry
;
1249 struct os_reltime rnow
;
1251 unsigned int seconds
;
1253 wpa_printf(MSG_DEBUG
, "DPP: Peer Discovery Response from " MACSTR
,
1255 if (is_zero_ether_addr(wpa_s
->dpp_intro_bssid
) ||
1256 os_memcmp(src
, wpa_s
->dpp_intro_bssid
, ETH_ALEN
) != 0) {
1257 wpa_printf(MSG_DEBUG
, "DPP: Not waiting for response from "
1258 MACSTR
" - drop", MAC2STR(src
));
1261 offchannel_send_action_done(wpa_s
);
1263 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1264 if (ssid
== wpa_s
->dpp_intro_network
)
1267 if (!ssid
|| !ssid
->dpp_connector
|| !ssid
->dpp_netaccesskey
||
1269 wpa_printf(MSG_DEBUG
,
1270 "DPP: Profile not found for network introduction");
1274 trans_id
= dpp_get_attr(buf
, len
, DPP_ATTR_TRANSACTION_ID
,
1276 if (!trans_id
|| trans_id_len
!= 1) {
1277 wpa_printf(MSG_DEBUG
,
1278 "DPP: Peer did not include Transaction ID");
1281 if (trans_id
[0] != TRANSACTION_ID
) {
1282 wpa_printf(MSG_DEBUG
,
1283 "DPP: Ignore frame with unexpected Transaction ID %u",
1288 connector
= dpp_get_attr(buf
, len
, DPP_ATTR_CONNECTOR
, &connector_len
);
1290 wpa_printf(MSG_DEBUG
,
1291 "DPP: Peer did not include its Connector");
1295 if (dpp_peer_intro(&intro
, ssid
->dpp_connector
,
1296 ssid
->dpp_netaccesskey
,
1297 ssid
->dpp_netaccesskey_len
,
1299 ssid
->dpp_csign_len
,
1300 connector
, connector_len
, &expiry
) < 0) {
1301 wpa_printf(MSG_INFO
,
1302 "DPP: Network Introduction protocol resulted in failure");
1306 entry
= os_zalloc(sizeof(*entry
));
1309 os_memcpy(entry
->aa
, src
, ETH_ALEN
);
1310 os_memcpy(entry
->pmkid
, intro
.pmkid
, PMKID_LEN
);
1311 os_memcpy(entry
->pmk
, intro
.pmk
, intro
.pmk_len
);
1312 entry
->pmk_len
= intro
.pmk_len
;
1313 entry
->akmp
= WPA_KEY_MGMT_DPP
;
1316 seconds
= expiry
- now
.sec
;
1318 seconds
= 86400 * 7;
1320 os_get_reltime(&rnow
);
1321 entry
->expiration
= rnow
.sec
+ seconds
;
1322 entry
->reauth_time
= rnow
.sec
+ seconds
;
1323 entry
->network_ctx
= ssid
;
1324 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
1326 wpa_printf(MSG_DEBUG
,
1327 "DPP: Try connection again after successful network introduction");
1328 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
1329 wpa_supplicant_cancel_sched_scan(wpa_s
);
1330 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1333 os_memset(&intro
, 0, sizeof(intro
));
1338 wpas_dpp_tx_pkex_status(struct wpa_supplicant
*wpa_s
,
1339 unsigned int freq
, const u8
*dst
,
1340 const u8
*src
, const u8
*bssid
,
1341 const u8
*data
, size_t data_len
,
1342 enum offchannel_send_action_result result
)
1344 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
1345 " result=%s (PKEX)",
1347 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
1348 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
1350 /* TODO: Time out wait for response more quickly in error cases? */
1355 wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1356 const u8
*buf
, size_t len
, unsigned int freq
)
1359 unsigned int wait_time
;
1361 wpa_printf(MSG_DEBUG
, "DPP: PKEX Exchange Request from " MACSTR
,
1364 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1367 if (!wpa_s
->dpp_pkex_code
|| !wpa_s
->dpp_pkex_bi
) {
1368 wpa_printf(MSG_DEBUG
,
1369 "DPP: No PKEX code configured - ignore request");
1373 if (wpa_s
->dpp_pkex
) {
1374 /* TODO: Support parallel operations */
1375 wpa_printf(MSG_DEBUG
,
1376 "DPP: Already in PKEX session - ignore new request");
1380 wpa_s
->dpp_pkex
= dpp_pkex_rx_exchange_req(wpa_s
->dpp_pkex_bi
,
1381 wpa_s
->own_addr
, src
,
1382 wpa_s
->dpp_pkex_identifier
,
1383 wpa_s
->dpp_pkex_code
,
1385 if (!wpa_s
->dpp_pkex
) {
1386 wpa_printf(MSG_DEBUG
,
1387 "DPP: Failed to process the request - ignore it");
1391 msg
= wpa_s
->dpp_pkex
->exchange_resp
;
1392 wait_time
= wpa_s
->max_remain_on_chan
;
1393 if (wait_time
> 2000)
1395 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
1397 wpabuf_head(msg
), wpabuf_len(msg
),
1398 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1403 wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1404 const u8
*buf
, size_t len
, unsigned int freq
)
1407 unsigned int wait_time
;
1409 wpa_printf(MSG_DEBUG
, "DPP: PKEX Exchange Response from " MACSTR
,
1412 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1415 if (!wpa_s
->dpp_pkex
|| !wpa_s
->dpp_pkex
->initiator
||
1416 wpa_s
->dpp_pkex
->exchange_done
) {
1417 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
1421 os_memcpy(wpa_s
->dpp_pkex
->peer_mac
, src
, ETH_ALEN
);
1422 msg
= dpp_pkex_rx_exchange_resp(wpa_s
->dpp_pkex
, buf
, len
);
1424 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the response");
1428 wpa_printf(MSG_DEBUG
, "DPP: Send PKEX Commit-Reveal Request to " MACSTR
,
1431 wait_time
= wpa_s
->max_remain_on_chan
;
1432 if (wait_time
> 2000)
1434 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
1436 wpabuf_head(msg
), wpabuf_len(msg
),
1437 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1443 wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1444 const u8
*buf
, size_t len
, unsigned int freq
)
1447 unsigned int wait_time
;
1448 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1449 struct dpp_bootstrap_info
*bi
;
1451 wpa_printf(MSG_DEBUG
, "DPP: PKEX Commit-Reveal Request from " MACSTR
,
1454 if (!pkex
|| pkex
->initiator
|| !pkex
->exchange_done
) {
1455 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
1459 msg
= dpp_pkex_rx_commit_reveal_req(pkex
, buf
, len
);
1461 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the request");
1465 wpa_printf(MSG_DEBUG
, "DPP: Send PKEX Commit-Reveal Response to "
1466 MACSTR
, MAC2STR(src
));
1468 wait_time
= wpa_s
->max_remain_on_chan
;
1469 if (wait_time
> 2000)
1471 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
1473 wpabuf_head(msg
), wpabuf_len(msg
),
1474 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1477 bi
= os_zalloc(sizeof(*bi
));
1480 bi
->id
= wpas_dpp_next_id(wpa_s
);
1481 bi
->type
= DPP_BOOTSTRAP_PKEX
;
1482 os_memcpy(bi
->mac_addr
, src
, ETH_ALEN
);
1485 bi
->curve
= pkex
->own_bi
->curve
;
1486 bi
->pubkey
= pkex
->peer_bootstrap_key
;
1487 pkex
->peer_bootstrap_key
= NULL
;
1488 dpp_pkex_free(pkex
);
1489 wpa_s
->dpp_pkex
= NULL
;
1490 if (dpp_bootstrap_key_hash(bi
) < 0) {
1491 dpp_bootstrap_info_free(bi
);
1494 dl_list_add(&wpa_s
->dpp_bootstrap
, &bi
->list
);
1499 wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1500 const u8
*buf
, size_t len
,
1504 struct dpp_bootstrap_info
*bi
, *own_bi
;
1505 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1508 wpa_printf(MSG_DEBUG
, "DPP: PKEX Commit-Reveal Response from " MACSTR
,
1511 if (!pkex
|| !pkex
->initiator
|| !pkex
->exchange_done
) {
1512 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
1516 res
= dpp_pkex_rx_commit_reveal_resp(pkex
, buf
, len
);
1518 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the response");
1522 own_bi
= pkex
->own_bi
;
1524 bi
= os_zalloc(sizeof(*bi
));
1527 bi
->id
= wpas_dpp_next_id(wpa_s
);
1528 bi
->type
= DPP_BOOTSTRAP_PKEX
;
1529 os_memcpy(bi
->mac_addr
, src
, ETH_ALEN
);
1532 bi
->curve
= own_bi
->curve
;
1533 bi
->pubkey
= pkex
->peer_bootstrap_key
;
1534 pkex
->peer_bootstrap_key
= NULL
;
1535 dpp_pkex_free(pkex
);
1536 wpa_s
->dpp_pkex
= NULL
;
1537 if (dpp_bootstrap_key_hash(bi
) < 0) {
1538 dpp_bootstrap_info_free(bi
);
1541 dl_list_add(&wpa_s
->dpp_bootstrap
, &bi
->list
);
1543 os_snprintf(cmd
, sizeof(cmd
), " peer=%u %s",
1545 wpa_s
->dpp_pkex_auth_cmd
? wpa_s
->dpp_pkex_auth_cmd
: "");
1546 wpa_printf(MSG_DEBUG
,
1547 "DPP: Start authentication after PKEX with parameters: %s",
1549 if (wpas_dpp_auth_init(wpa_s
, cmd
) < 0) {
1550 wpa_printf(MSG_DEBUG
,
1551 "DPP: Authentication initialization failed");
1557 void wpas_dpp_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1558 const u8
*buf
, size_t len
, unsigned int freq
)
1561 enum dpp_public_action_frame_type type
;
1564 if (len
< DPP_HDR_LEN
)
1566 if (WPA_GET_BE24(buf
) != OUI_WFA
|| buf
[3] != DPP_OUI_TYPE
)
1571 crypto_suite
= *buf
++;
1575 wpa_printf(MSG_DEBUG
,
1576 "DPP: Received DPP Public Action frame crypto suite %u type %d from "
1578 crypto_suite
, type
, MAC2STR(src
), freq
);
1579 if (crypto_suite
!= 1) {
1580 wpa_printf(MSG_DEBUG
, "DPP: Unsupported crypto suite %u",
1584 wpa_hexdump(MSG_MSGDUMP
, "DPP: Received message attributes", buf
, len
);
1585 if (dpp_check_attrs(buf
, len
) < 0)
1589 case DPP_PA_AUTHENTICATION_REQ
:
1590 wpas_dpp_rx_auth_req(wpa_s
, src
, hdr
, buf
, len
, freq
);
1592 case DPP_PA_AUTHENTICATION_RESP
:
1593 wpas_dpp_rx_auth_resp(wpa_s
, src
, hdr
, buf
, len
);
1595 case DPP_PA_AUTHENTICATION_CONF
:
1596 wpas_dpp_rx_auth_conf(wpa_s
, src
, hdr
, buf
, len
);
1598 case DPP_PA_PEER_DISCOVERY_RESP
:
1599 wpas_dpp_rx_peer_disc_resp(wpa_s
, src
, buf
, len
);
1601 case DPP_PA_PKEX_EXCHANGE_REQ
:
1602 wpas_dpp_rx_pkex_exchange_req(wpa_s
, src
, buf
, len
, freq
);
1604 case DPP_PA_PKEX_EXCHANGE_RESP
:
1605 wpas_dpp_rx_pkex_exchange_resp(wpa_s
, src
, buf
, len
, freq
);
1607 case DPP_PA_PKEX_COMMIT_REVEAL_REQ
:
1608 wpas_dpp_rx_pkex_commit_reveal_req(wpa_s
, src
, buf
, len
, freq
);
1610 case DPP_PA_PKEX_COMMIT_REVEAL_RESP
:
1611 wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s
, src
, buf
, len
, freq
);
1614 wpa_printf(MSG_DEBUG
,
1615 "DPP: Ignored unsupported frame subtype %d", type
);
1621 static struct wpabuf
*
1622 wpas_dpp_gas_req_handler(void *ctx
, const u8
*sa
, const u8
*query
,
1625 struct wpa_supplicant
*wpa_s
= ctx
;
1626 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1627 struct wpabuf
*resp
;
1629 wpa_printf(MSG_DEBUG
, "DPP: GAS request from " MACSTR
,
1631 if (!auth
|| !auth
->auth_success
||
1632 os_memcmp(sa
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1633 wpa_printf(MSG_DEBUG
, "DPP: No matching exchange in progress");
1636 wpa_hexdump(MSG_DEBUG
,
1637 "DPP: Received Configuration Request (GAS Query Request)",
1639 resp
= dpp_conf_req_rx(auth
, query
, query_len
);
1641 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1647 wpas_dpp_gas_status_handler(void *ctx
, struct wpabuf
*resp
, int ok
)
1649 struct wpa_supplicant
*wpa_s
= ctx
;
1650 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1657 wpa_printf(MSG_DEBUG
, "DPP: Configuration exchange completed (ok=%d)",
1659 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
1660 offchannel_send_action_done(wpa_s
);
1661 wpas_dpp_listen_stop(wpa_s
);
1663 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_SENT
);
1665 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1666 dpp_auth_deinit(wpa_s
->dpp_auth
);
1667 wpa_s
->dpp_auth
= NULL
;
1672 static unsigned int wpas_dpp_next_configurator_id(struct wpa_supplicant
*wpa_s
)
1674 struct dpp_configurator
*conf
;
1675 unsigned int max_id
= 0;
1677 dl_list_for_each(conf
, &wpa_s
->dpp_configurator
,
1678 struct dpp_configurator
, list
) {
1679 if (conf
->id
> max_id
)
1686 int wpas_dpp_configurator_add(struct wpa_supplicant
*wpa_s
, const char *cmd
)
1691 size_t privkey_len
= 0;
1693 struct dpp_configurator
*conf
= NULL
;
1695 curve
= get_param(cmd
, " curve=");
1696 key
= get_param(cmd
, " key=");
1699 privkey_len
= os_strlen(key
) / 2;
1700 privkey
= os_malloc(privkey_len
);
1702 hexstr2bin(key
, privkey
, privkey_len
) < 0)
1706 conf
= dpp_keygen_configurator(curve
, privkey
, privkey_len
);
1710 conf
->id
= wpas_dpp_next_configurator_id(wpa_s
);
1711 dl_list_add(&wpa_s
->dpp_configurator
, &conf
->list
);
1716 str_clear_free(key
);
1717 bin_clear_free(privkey
, privkey_len
);
1718 dpp_configurator_free(conf
);
1723 static int dpp_configurator_del(struct wpa_supplicant
*wpa_s
, unsigned int id
)
1725 struct dpp_configurator
*conf
, *tmp
;
1728 dl_list_for_each_safe(conf
, tmp
, &wpa_s
->dpp_configurator
,
1729 struct dpp_configurator
, list
) {
1730 if (id
&& conf
->id
!= id
)
1733 dl_list_del(&conf
->list
);
1734 dpp_configurator_free(conf
);
1738 return 0; /* flush succeeds regardless of entries found */
1739 return found
? 0 : -1;
1743 int wpas_dpp_configurator_remove(struct wpa_supplicant
*wpa_s
, const char *id
)
1745 unsigned int id_val
;
1747 if (os_strcmp(id
, "*") == 0) {
1755 return dpp_configurator_del(wpa_s
, id_val
);
1759 int wpas_dpp_configurator_sign(struct wpa_supplicant
*wpa_s
, const char *cmd
)
1761 struct dpp_authentication
*auth
;
1765 auth
= os_zalloc(sizeof(*auth
));
1769 curve
= get_param(cmd
, " curve=");
1770 wpas_dpp_set_configurator(wpa_s
, auth
, cmd
);
1772 if (dpp_configurator_own_config(auth
, curve
) == 0) {
1773 wpas_dpp_handle_config_obj(wpa_s
, auth
);
1777 dpp_auth_deinit(auth
);
1785 wpas_dpp_tx_introduction_status(struct wpa_supplicant
*wpa_s
,
1786 unsigned int freq
, const u8
*dst
,
1787 const u8
*src
, const u8
*bssid
,
1788 const u8
*data
, size_t data_len
,
1789 enum offchannel_send_action_result result
)
1791 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
1792 " result=%s (DPP Peer Discovery Request)",
1794 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
1795 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
1797 /* TODO: Time out wait for response more quickly in error cases? */
1801 int wpas_dpp_check_connect(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
1802 struct wpa_bss
*bss
)
1806 unsigned int wait_time
;
1808 if (!(ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) || !bss
)
1809 return 0; /* Not using DPP AKM - continue */
1810 if (wpa_sm_pmksa_exists(wpa_s
->wpa
, bss
->bssid
, ssid
))
1811 return 0; /* PMKSA exists for DPP AKM - continue */
1813 if (!ssid
->dpp_connector
|| !ssid
->dpp_netaccesskey
||
1815 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_MISSING_CONNECTOR
1817 !ssid
->dpp_connector
? "Connector" :
1818 (!ssid
->dpp_netaccesskey
? "netAccessKey" :
1825 if (ssid
->dpp_netaccesskey_expiry
&&
1826 ssid
->dpp_netaccesskey_expiry
< now
.sec
) {
1827 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_MISSING_CONNECTOR
1828 "netAccessKey expired");
1832 wpa_printf(MSG_DEBUG
,
1833 "DPP: Starting network introduction protocol to derive PMKSA for "
1834 MACSTR
, MAC2STR(bss
->bssid
));
1836 msg
= dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ
,
1837 5 + 4 + os_strlen(ssid
->dpp_connector
));
1841 /* Transaction ID */
1842 wpabuf_put_le16(msg
, DPP_ATTR_TRANSACTION_ID
);
1843 wpabuf_put_le16(msg
, 1);
1844 wpabuf_put_u8(msg
, TRANSACTION_ID
);
1847 wpabuf_put_le16(msg
, DPP_ATTR_CONNECTOR
);
1848 wpabuf_put_le16(msg
, os_strlen(ssid
->dpp_connector
));
1849 wpabuf_put_str(msg
, ssid
->dpp_connector
);
1851 /* TODO: Timeout on AP response */
1852 wait_time
= wpa_s
->max_remain_on_chan
;
1853 if (wait_time
> 2000)
1855 offchannel_send_action(wpa_s
, bss
->freq
, bss
->bssid
, wpa_s
->own_addr
,
1857 wpabuf_head(msg
), wpabuf_len(msg
),
1858 wait_time
, wpas_dpp_tx_introduction_status
, 0);
1861 /* Request this connection attempt to terminate - new one will be
1862 * started when network introduction protocol completes */
1863 os_memcpy(wpa_s
->dpp_intro_bssid
, bss
->bssid
, ETH_ALEN
);
1864 wpa_s
->dpp_intro_network
= ssid
;
1869 int wpas_dpp_pkex_add(struct wpa_supplicant
*wpa_s
, const char *cmd
)
1871 struct dpp_bootstrap_info
*own_bi
;
1872 const char *pos
, *end
;
1873 unsigned int wait_time
;
1875 pos
= os_strstr(cmd
, " own=");
1879 own_bi
= dpp_bootstrap_get_id(wpa_s
, atoi(pos
));
1881 wpa_printf(MSG_DEBUG
,
1882 "DPP: Identified bootstrap info not found");
1885 if (own_bi
->type
!= DPP_BOOTSTRAP_PKEX
) {
1886 wpa_printf(MSG_DEBUG
,
1887 "DPP: Identified bootstrap info not for PKEX");
1890 wpa_s
->dpp_pkex_bi
= own_bi
;
1892 os_free(wpa_s
->dpp_pkex_identifier
);
1893 wpa_s
->dpp_pkex_identifier
= NULL
;
1894 pos
= os_strstr(cmd
, " identifier=");
1897 end
= os_strchr(pos
, ' ');
1900 wpa_s
->dpp_pkex_identifier
= os_malloc(end
- pos
+ 1);
1901 if (!wpa_s
->dpp_pkex_identifier
)
1903 os_memcpy(wpa_s
->dpp_pkex_identifier
, pos
, end
- pos
);
1904 wpa_s
->dpp_pkex_identifier
[end
- pos
] = '\0';
1907 pos
= os_strstr(cmd
, " code=");
1910 os_free(wpa_s
->dpp_pkex_code
);
1911 wpa_s
->dpp_pkex_code
= os_strdup(pos
+ 6);
1912 if (!wpa_s
->dpp_pkex_code
)
1915 if (os_strstr(cmd
, " init=1")) {
1918 wpa_printf(MSG_DEBUG
, "DPP: Initiating PKEX");
1919 dpp_pkex_free(wpa_s
->dpp_pkex
);
1920 wpa_s
->dpp_pkex
= dpp_pkex_init(own_bi
, wpa_s
->own_addr
,
1921 wpa_s
->dpp_pkex_identifier
,
1922 wpa_s
->dpp_pkex_code
);
1923 if (!wpa_s
->dpp_pkex
)
1926 msg
= wpa_s
->dpp_pkex
->exchange_req
;
1927 wait_time
= wpa_s
->max_remain_on_chan
;
1928 if (wait_time
> 2000)
1930 /* TODO: Which channel to use? */
1931 offchannel_send_action(wpa_s
, 2437, broadcast
, wpa_s
->own_addr
,
1933 wpabuf_head(msg
), wpabuf_len(msg
),
1934 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1937 /* TODO: Support multiple PKEX info entries */
1939 os_free(wpa_s
->dpp_pkex_auth_cmd
);
1940 wpa_s
->dpp_pkex_auth_cmd
= os_strdup(cmd
);
1946 int wpas_dpp_pkex_remove(struct wpa_supplicant
*wpa_s
, const char *id
)
1948 unsigned int id_val
;
1950 if (os_strcmp(id
, "*") == 0) {
1958 if ((id_val
!= 0 && id_val
!= 1) || !wpa_s
->dpp_pkex_code
)
1961 /* TODO: Support multiple PKEX entries */
1962 os_free(wpa_s
->dpp_pkex_code
);
1963 wpa_s
->dpp_pkex_code
= NULL
;
1964 os_free(wpa_s
->dpp_pkex_identifier
);
1965 wpa_s
->dpp_pkex_identifier
= NULL
;
1966 os_free(wpa_s
->dpp_pkex_auth_cmd
);
1967 wpa_s
->dpp_pkex_auth_cmd
= NULL
;
1968 wpa_s
->dpp_pkex_bi
= NULL
;
1969 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
1970 dpp_pkex_free(wpa_s
->dpp_pkex
);
1971 wpa_s
->dpp_pkex
= NULL
;
1976 int wpas_dpp_init(struct wpa_supplicant
*wpa_s
)
1980 adv_proto_id
[0] = WLAN_EID_VENDOR_SPECIFIC
;
1981 adv_proto_id
[1] = 5;
1982 WPA_PUT_BE24(&adv_proto_id
[2], OUI_WFA
);
1983 adv_proto_id
[5] = DPP_OUI_TYPE
;
1984 adv_proto_id
[6] = 0x01;
1986 if (gas_server_register(wpa_s
->gas_server
, adv_proto_id
,
1987 sizeof(adv_proto_id
), wpas_dpp_gas_req_handler
,
1988 wpas_dpp_gas_status_handler
, wpa_s
) < 0)
1990 dl_list_init(&wpa_s
->dpp_bootstrap
);
1991 dl_list_init(&wpa_s
->dpp_configurator
);
1992 wpa_s
->dpp_init_done
= 1;
1997 void wpas_dpp_deinit(struct wpa_supplicant
*wpa_s
)
1999 #ifdef CONFIG_TESTING_OPTIONS
2000 os_free(wpa_s
->dpp_config_obj_override
);
2001 wpa_s
->dpp_config_obj_override
= NULL
;
2002 os_free(wpa_s
->dpp_discovery_override
);
2003 wpa_s
->dpp_discovery_override
= NULL
;
2004 os_free(wpa_s
->dpp_groups_override
);
2005 wpa_s
->dpp_groups_override
= NULL
;
2006 wpa_s
->dpp_ignore_netaccesskey_mismatch
= 0;
2007 #endif /* CONFIG_TESTING_OPTIONS */
2008 if (!wpa_s
->dpp_init_done
)
2010 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
2011 offchannel_send_action_done(wpa_s
);
2012 wpas_dpp_listen_stop(wpa_s
);
2013 dpp_bootstrap_del(wpa_s
, 0);
2014 dpp_configurator_del(wpa_s
, 0);
2015 dpp_auth_deinit(wpa_s
->dpp_auth
);
2016 wpa_s
->dpp_auth
= NULL
;
2017 wpas_dpp_pkex_remove(wpa_s
, "*");
2018 wpa_s
->dpp_pkex
= NULL
;
2019 os_memset(wpa_s
->dpp_intro_bssid
, 0, ETH_ALEN
);
2020 os_free(wpa_s
->dpp_configurator_params
);
2021 wpa_s
->dpp_configurator_params
= NULL
;