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
*hdr
, const u8
*buf
, size_t len
,
1448 unsigned int wait_time
;
1449 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1450 struct dpp_bootstrap_info
*bi
;
1452 wpa_printf(MSG_DEBUG
, "DPP: PKEX Commit-Reveal Request from " MACSTR
,
1455 if (!pkex
|| pkex
->initiator
|| !pkex
->exchange_done
) {
1456 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
1460 msg
= dpp_pkex_rx_commit_reveal_req(pkex
, hdr
, buf
, len
);
1462 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the request");
1466 wpa_printf(MSG_DEBUG
, "DPP: Send PKEX Commit-Reveal Response to "
1467 MACSTR
, MAC2STR(src
));
1469 wait_time
= wpa_s
->max_remain_on_chan
;
1470 if (wait_time
> 2000)
1472 offchannel_send_action(wpa_s
, freq
, src
, wpa_s
->own_addr
,
1474 wpabuf_head(msg
), wpabuf_len(msg
),
1475 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1478 bi
= os_zalloc(sizeof(*bi
));
1481 bi
->id
= wpas_dpp_next_id(wpa_s
);
1482 bi
->type
= DPP_BOOTSTRAP_PKEX
;
1483 os_memcpy(bi
->mac_addr
, src
, ETH_ALEN
);
1486 bi
->curve
= pkex
->own_bi
->curve
;
1487 bi
->pubkey
= pkex
->peer_bootstrap_key
;
1488 pkex
->peer_bootstrap_key
= NULL
;
1489 dpp_pkex_free(pkex
);
1490 wpa_s
->dpp_pkex
= NULL
;
1491 if (dpp_bootstrap_key_hash(bi
) < 0) {
1492 dpp_bootstrap_info_free(bi
);
1495 dl_list_add(&wpa_s
->dpp_bootstrap
, &bi
->list
);
1500 wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1501 const u8
*hdr
, const u8
*buf
, size_t len
,
1505 struct dpp_bootstrap_info
*bi
, *own_bi
;
1506 struct dpp_pkex
*pkex
= wpa_s
->dpp_pkex
;
1509 wpa_printf(MSG_DEBUG
, "DPP: PKEX Commit-Reveal Response from " MACSTR
,
1512 if (!pkex
|| !pkex
->initiator
|| !pkex
->exchange_done
) {
1513 wpa_printf(MSG_DEBUG
, "DPP: No matching PKEX session");
1517 res
= dpp_pkex_rx_commit_reveal_resp(pkex
, hdr
, buf
, len
);
1519 wpa_printf(MSG_DEBUG
, "DPP: Failed to process the response");
1523 own_bi
= pkex
->own_bi
;
1525 bi
= os_zalloc(sizeof(*bi
));
1528 bi
->id
= wpas_dpp_next_id(wpa_s
);
1529 bi
->type
= DPP_BOOTSTRAP_PKEX
;
1530 os_memcpy(bi
->mac_addr
, src
, ETH_ALEN
);
1533 bi
->curve
= own_bi
->curve
;
1534 bi
->pubkey
= pkex
->peer_bootstrap_key
;
1535 pkex
->peer_bootstrap_key
= NULL
;
1536 dpp_pkex_free(pkex
);
1537 wpa_s
->dpp_pkex
= NULL
;
1538 if (dpp_bootstrap_key_hash(bi
) < 0) {
1539 dpp_bootstrap_info_free(bi
);
1542 dl_list_add(&wpa_s
->dpp_bootstrap
, &bi
->list
);
1544 os_snprintf(cmd
, sizeof(cmd
), " peer=%u %s",
1546 wpa_s
->dpp_pkex_auth_cmd
? wpa_s
->dpp_pkex_auth_cmd
: "");
1547 wpa_printf(MSG_DEBUG
,
1548 "DPP: Start authentication after PKEX with parameters: %s",
1550 if (wpas_dpp_auth_init(wpa_s
, cmd
) < 0) {
1551 wpa_printf(MSG_DEBUG
,
1552 "DPP: Authentication initialization failed");
1558 void wpas_dpp_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*src
,
1559 const u8
*buf
, size_t len
, unsigned int freq
)
1562 enum dpp_public_action_frame_type type
;
1565 if (len
< DPP_HDR_LEN
)
1567 if (WPA_GET_BE24(buf
) != OUI_WFA
|| buf
[3] != DPP_OUI_TYPE
)
1572 crypto_suite
= *buf
++;
1576 wpa_printf(MSG_DEBUG
,
1577 "DPP: Received DPP Public Action frame crypto suite %u type %d from "
1579 crypto_suite
, type
, MAC2STR(src
), freq
);
1580 if (crypto_suite
!= 1) {
1581 wpa_printf(MSG_DEBUG
, "DPP: Unsupported crypto suite %u",
1585 wpa_hexdump(MSG_MSGDUMP
, "DPP: Received message attributes", buf
, len
);
1586 if (dpp_check_attrs(buf
, len
) < 0)
1590 case DPP_PA_AUTHENTICATION_REQ
:
1591 wpas_dpp_rx_auth_req(wpa_s
, src
, hdr
, buf
, len
, freq
);
1593 case DPP_PA_AUTHENTICATION_RESP
:
1594 wpas_dpp_rx_auth_resp(wpa_s
, src
, hdr
, buf
, len
);
1596 case DPP_PA_AUTHENTICATION_CONF
:
1597 wpas_dpp_rx_auth_conf(wpa_s
, src
, hdr
, buf
, len
);
1599 case DPP_PA_PEER_DISCOVERY_RESP
:
1600 wpas_dpp_rx_peer_disc_resp(wpa_s
, src
, buf
, len
);
1602 case DPP_PA_PKEX_EXCHANGE_REQ
:
1603 wpas_dpp_rx_pkex_exchange_req(wpa_s
, src
, buf
, len
, freq
);
1605 case DPP_PA_PKEX_EXCHANGE_RESP
:
1606 wpas_dpp_rx_pkex_exchange_resp(wpa_s
, src
, buf
, len
, freq
);
1608 case DPP_PA_PKEX_COMMIT_REVEAL_REQ
:
1609 wpas_dpp_rx_pkex_commit_reveal_req(wpa_s
, src
, hdr
, buf
, len
,
1612 case DPP_PA_PKEX_COMMIT_REVEAL_RESP
:
1613 wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s
, src
, hdr
, buf
, len
,
1617 wpa_printf(MSG_DEBUG
,
1618 "DPP: Ignored unsupported frame subtype %d", type
);
1624 static struct wpabuf
*
1625 wpas_dpp_gas_req_handler(void *ctx
, const u8
*sa
, const u8
*query
,
1628 struct wpa_supplicant
*wpa_s
= ctx
;
1629 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1630 struct wpabuf
*resp
;
1632 wpa_printf(MSG_DEBUG
, "DPP: GAS request from " MACSTR
,
1634 if (!auth
|| !auth
->auth_success
||
1635 os_memcmp(sa
, auth
->peer_mac_addr
, ETH_ALEN
) != 0) {
1636 wpa_printf(MSG_DEBUG
, "DPP: No matching exchange in progress");
1639 wpa_hexdump(MSG_DEBUG
,
1640 "DPP: Received Configuration Request (GAS Query Request)",
1642 resp
= dpp_conf_req_rx(auth
, query
, query_len
);
1644 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1650 wpas_dpp_gas_status_handler(void *ctx
, struct wpabuf
*resp
, int ok
)
1652 struct wpa_supplicant
*wpa_s
= ctx
;
1653 struct dpp_authentication
*auth
= wpa_s
->dpp_auth
;
1660 wpa_printf(MSG_DEBUG
, "DPP: Configuration exchange completed (ok=%d)",
1662 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
1663 offchannel_send_action_done(wpa_s
);
1664 wpas_dpp_listen_stop(wpa_s
);
1666 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_SENT
);
1668 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_CONF_FAILED
);
1669 dpp_auth_deinit(wpa_s
->dpp_auth
);
1670 wpa_s
->dpp_auth
= NULL
;
1675 static unsigned int wpas_dpp_next_configurator_id(struct wpa_supplicant
*wpa_s
)
1677 struct dpp_configurator
*conf
;
1678 unsigned int max_id
= 0;
1680 dl_list_for_each(conf
, &wpa_s
->dpp_configurator
,
1681 struct dpp_configurator
, list
) {
1682 if (conf
->id
> max_id
)
1689 int wpas_dpp_configurator_add(struct wpa_supplicant
*wpa_s
, const char *cmd
)
1694 size_t privkey_len
= 0;
1696 struct dpp_configurator
*conf
= NULL
;
1698 curve
= get_param(cmd
, " curve=");
1699 key
= get_param(cmd
, " key=");
1702 privkey_len
= os_strlen(key
) / 2;
1703 privkey
= os_malloc(privkey_len
);
1705 hexstr2bin(key
, privkey
, privkey_len
) < 0)
1709 conf
= dpp_keygen_configurator(curve
, privkey
, privkey_len
);
1713 conf
->id
= wpas_dpp_next_configurator_id(wpa_s
);
1714 dl_list_add(&wpa_s
->dpp_configurator
, &conf
->list
);
1719 str_clear_free(key
);
1720 bin_clear_free(privkey
, privkey_len
);
1721 dpp_configurator_free(conf
);
1726 static int dpp_configurator_del(struct wpa_supplicant
*wpa_s
, unsigned int id
)
1728 struct dpp_configurator
*conf
, *tmp
;
1731 dl_list_for_each_safe(conf
, tmp
, &wpa_s
->dpp_configurator
,
1732 struct dpp_configurator
, list
) {
1733 if (id
&& conf
->id
!= id
)
1736 dl_list_del(&conf
->list
);
1737 dpp_configurator_free(conf
);
1741 return 0; /* flush succeeds regardless of entries found */
1742 return found
? 0 : -1;
1746 int wpas_dpp_configurator_remove(struct wpa_supplicant
*wpa_s
, const char *id
)
1748 unsigned int id_val
;
1750 if (os_strcmp(id
, "*") == 0) {
1758 return dpp_configurator_del(wpa_s
, id_val
);
1762 int wpas_dpp_configurator_sign(struct wpa_supplicant
*wpa_s
, const char *cmd
)
1764 struct dpp_authentication
*auth
;
1768 auth
= os_zalloc(sizeof(*auth
));
1772 curve
= get_param(cmd
, " curve=");
1773 wpas_dpp_set_configurator(wpa_s
, auth
, cmd
);
1775 if (dpp_configurator_own_config(auth
, curve
) == 0) {
1776 wpas_dpp_handle_config_obj(wpa_s
, auth
);
1780 dpp_auth_deinit(auth
);
1788 wpas_dpp_tx_introduction_status(struct wpa_supplicant
*wpa_s
,
1789 unsigned int freq
, const u8
*dst
,
1790 const u8
*src
, const u8
*bssid
,
1791 const u8
*data
, size_t data_len
,
1792 enum offchannel_send_action_result result
)
1794 wpa_printf(MSG_DEBUG
, "DPP: TX status: freq=%u dst=" MACSTR
1795 " result=%s (DPP Peer Discovery Request)",
1797 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
1798 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
1800 /* TODO: Time out wait for response more quickly in error cases? */
1804 int wpas_dpp_check_connect(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
1805 struct wpa_bss
*bss
)
1809 unsigned int wait_time
;
1811 if (!(ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) || !bss
)
1812 return 0; /* Not using DPP AKM - continue */
1813 if (wpa_sm_pmksa_exists(wpa_s
->wpa
, bss
->bssid
, ssid
))
1814 return 0; /* PMKSA exists for DPP AKM - continue */
1816 if (!ssid
->dpp_connector
|| !ssid
->dpp_netaccesskey
||
1818 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_MISSING_CONNECTOR
1820 !ssid
->dpp_connector
? "Connector" :
1821 (!ssid
->dpp_netaccesskey
? "netAccessKey" :
1828 if (ssid
->dpp_netaccesskey_expiry
&&
1829 ssid
->dpp_netaccesskey_expiry
< now
.sec
) {
1830 wpa_msg(wpa_s
, MSG_INFO
, DPP_EVENT_MISSING_CONNECTOR
1831 "netAccessKey expired");
1835 wpa_printf(MSG_DEBUG
,
1836 "DPP: Starting network introduction protocol to derive PMKSA for "
1837 MACSTR
, MAC2STR(bss
->bssid
));
1839 msg
= dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ
,
1840 5 + 4 + os_strlen(ssid
->dpp_connector
));
1844 /* Transaction ID */
1845 wpabuf_put_le16(msg
, DPP_ATTR_TRANSACTION_ID
);
1846 wpabuf_put_le16(msg
, 1);
1847 wpabuf_put_u8(msg
, TRANSACTION_ID
);
1850 wpabuf_put_le16(msg
, DPP_ATTR_CONNECTOR
);
1851 wpabuf_put_le16(msg
, os_strlen(ssid
->dpp_connector
));
1852 wpabuf_put_str(msg
, ssid
->dpp_connector
);
1854 /* TODO: Timeout on AP response */
1855 wait_time
= wpa_s
->max_remain_on_chan
;
1856 if (wait_time
> 2000)
1858 offchannel_send_action(wpa_s
, bss
->freq
, bss
->bssid
, wpa_s
->own_addr
,
1860 wpabuf_head(msg
), wpabuf_len(msg
),
1861 wait_time
, wpas_dpp_tx_introduction_status
, 0);
1864 /* Request this connection attempt to terminate - new one will be
1865 * started when network introduction protocol completes */
1866 os_memcpy(wpa_s
->dpp_intro_bssid
, bss
->bssid
, ETH_ALEN
);
1867 wpa_s
->dpp_intro_network
= ssid
;
1872 int wpas_dpp_pkex_add(struct wpa_supplicant
*wpa_s
, const char *cmd
)
1874 struct dpp_bootstrap_info
*own_bi
;
1875 const char *pos
, *end
;
1876 unsigned int wait_time
;
1878 pos
= os_strstr(cmd
, " own=");
1882 own_bi
= dpp_bootstrap_get_id(wpa_s
, atoi(pos
));
1884 wpa_printf(MSG_DEBUG
,
1885 "DPP: Identified bootstrap info not found");
1888 if (own_bi
->type
!= DPP_BOOTSTRAP_PKEX
) {
1889 wpa_printf(MSG_DEBUG
,
1890 "DPP: Identified bootstrap info not for PKEX");
1893 wpa_s
->dpp_pkex_bi
= own_bi
;
1895 os_free(wpa_s
->dpp_pkex_identifier
);
1896 wpa_s
->dpp_pkex_identifier
= NULL
;
1897 pos
= os_strstr(cmd
, " identifier=");
1900 end
= os_strchr(pos
, ' ');
1903 wpa_s
->dpp_pkex_identifier
= os_malloc(end
- pos
+ 1);
1904 if (!wpa_s
->dpp_pkex_identifier
)
1906 os_memcpy(wpa_s
->dpp_pkex_identifier
, pos
, end
- pos
);
1907 wpa_s
->dpp_pkex_identifier
[end
- pos
] = '\0';
1910 pos
= os_strstr(cmd
, " code=");
1913 os_free(wpa_s
->dpp_pkex_code
);
1914 wpa_s
->dpp_pkex_code
= os_strdup(pos
+ 6);
1915 if (!wpa_s
->dpp_pkex_code
)
1918 if (os_strstr(cmd
, " init=1")) {
1921 wpa_printf(MSG_DEBUG
, "DPP: Initiating PKEX");
1922 dpp_pkex_free(wpa_s
->dpp_pkex
);
1923 wpa_s
->dpp_pkex
= dpp_pkex_init(own_bi
, wpa_s
->own_addr
,
1924 wpa_s
->dpp_pkex_identifier
,
1925 wpa_s
->dpp_pkex_code
);
1926 if (!wpa_s
->dpp_pkex
)
1929 msg
= wpa_s
->dpp_pkex
->exchange_req
;
1930 wait_time
= wpa_s
->max_remain_on_chan
;
1931 if (wait_time
> 2000)
1933 /* TODO: Which channel to use? */
1934 offchannel_send_action(wpa_s
, 2437, broadcast
, wpa_s
->own_addr
,
1936 wpabuf_head(msg
), wpabuf_len(msg
),
1937 wait_time
, wpas_dpp_tx_pkex_status
, 0);
1940 /* TODO: Support multiple PKEX info entries */
1942 os_free(wpa_s
->dpp_pkex_auth_cmd
);
1943 wpa_s
->dpp_pkex_auth_cmd
= os_strdup(cmd
);
1949 int wpas_dpp_pkex_remove(struct wpa_supplicant
*wpa_s
, const char *id
)
1951 unsigned int id_val
;
1953 if (os_strcmp(id
, "*") == 0) {
1961 if ((id_val
!= 0 && id_val
!= 1) || !wpa_s
->dpp_pkex_code
)
1964 /* TODO: Support multiple PKEX entries */
1965 os_free(wpa_s
->dpp_pkex_code
);
1966 wpa_s
->dpp_pkex_code
= NULL
;
1967 os_free(wpa_s
->dpp_pkex_identifier
);
1968 wpa_s
->dpp_pkex_identifier
= NULL
;
1969 os_free(wpa_s
->dpp_pkex_auth_cmd
);
1970 wpa_s
->dpp_pkex_auth_cmd
= NULL
;
1971 wpa_s
->dpp_pkex_bi
= NULL
;
1972 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
1973 dpp_pkex_free(wpa_s
->dpp_pkex
);
1974 wpa_s
->dpp_pkex
= NULL
;
1979 int wpas_dpp_init(struct wpa_supplicant
*wpa_s
)
1983 adv_proto_id
[0] = WLAN_EID_VENDOR_SPECIFIC
;
1984 adv_proto_id
[1] = 5;
1985 WPA_PUT_BE24(&adv_proto_id
[2], OUI_WFA
);
1986 adv_proto_id
[5] = DPP_OUI_TYPE
;
1987 adv_proto_id
[6] = 0x01;
1989 if (gas_server_register(wpa_s
->gas_server
, adv_proto_id
,
1990 sizeof(adv_proto_id
), wpas_dpp_gas_req_handler
,
1991 wpas_dpp_gas_status_handler
, wpa_s
) < 0)
1993 dl_list_init(&wpa_s
->dpp_bootstrap
);
1994 dl_list_init(&wpa_s
->dpp_configurator
);
1995 wpa_s
->dpp_init_done
= 1;
2000 void wpas_dpp_deinit(struct wpa_supplicant
*wpa_s
)
2002 #ifdef CONFIG_TESTING_OPTIONS
2003 os_free(wpa_s
->dpp_config_obj_override
);
2004 wpa_s
->dpp_config_obj_override
= NULL
;
2005 os_free(wpa_s
->dpp_discovery_override
);
2006 wpa_s
->dpp_discovery_override
= NULL
;
2007 os_free(wpa_s
->dpp_groups_override
);
2008 wpa_s
->dpp_groups_override
= NULL
;
2009 wpa_s
->dpp_ignore_netaccesskey_mismatch
= 0;
2010 #endif /* CONFIG_TESTING_OPTIONS */
2011 if (!wpa_s
->dpp_init_done
)
2013 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout
, wpa_s
, NULL
);
2014 offchannel_send_action_done(wpa_s
);
2015 wpas_dpp_listen_stop(wpa_s
);
2016 dpp_bootstrap_del(wpa_s
, 0);
2017 dpp_configurator_del(wpa_s
, 0);
2018 dpp_auth_deinit(wpa_s
->dpp_auth
);
2019 wpa_s
->dpp_auth
= NULL
;
2020 wpas_dpp_pkex_remove(wpa_s
, "*");
2021 wpa_s
->dpp_pkex
= NULL
;
2022 os_memset(wpa_s
->dpp_intro_bssid
, 0, ETH_ALEN
);
2023 os_free(wpa_s
->dpp_configurator_params
);
2024 wpa_s
->dpp_configurator_params
= NULL
;