3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
4 * Copyright (c) 2018-2019, The Linux Foundation
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
10 #include "utils/includes.h"
12 #include "utils/common.h"
13 #include "utils/eloop.h"
14 #include "utils/ip_addr.h"
15 #include "common/dpp.h"
16 #include "common/gas.h"
17 #include "common/gas_server.h"
18 #include "rsn_supp/wpa.h"
19 #include "rsn_supp/pmksa_cache.h"
20 #include "wpa_supplicant_i.h"
23 #include "offchannel.h"
24 #include "gas_query.h"
28 #include "dpp_supplicant.h"
31 static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
33 static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx);
34 static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator);
35 static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
36 unsigned int freq, const u8 *dst,
37 const u8 *src, const u8 *bssid,
38 const u8 *data, size_t data_len,
39 enum offchannel_send_action_result result);
40 static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx);
41 static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s);
43 wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s,
44 unsigned int freq, const u8 *dst,
45 const u8 *src, const u8 *bssid,
46 const u8 *data, size_t data_len,
47 enum offchannel_send_action_result result);
49 static const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
51 /* Use a hardcoded Transaction ID 1 in Peer Discovery frames since there is only
52 * a single transaction in progress at any point in time. */
53 static const u8 TRANSACTION_ID = 1;
57 * wpas_dpp_qr_code - Parse and add DPP bootstrapping info from a QR Code
58 * @wpa_s: Pointer to wpa_supplicant data
59 * @cmd: DPP URI read from a QR Code
60 * Returns: Identifier of the stored info or -1 on failure
62 int wpas_dpp_qr_code(struct wpa_supplicant *wpa_s, const char *cmd)
64 struct dpp_bootstrap_info *bi;
65 struct dpp_authentication *auth = wpa_s->dpp_auth;
67 bi = dpp_add_qr_code(wpa_s->dpp, cmd);
71 if (auth && auth->response_pending &&
72 dpp_notify_new_qr_code(auth, bi) == 1) {
74 "DPP: Sending out pending authentication response");
75 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
77 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
78 DPP_PA_AUTHENTICATION_RESP);
79 offchannel_send_action(wpa_s, auth->curr_freq,
80 auth->peer_mac_addr, wpa_s->own_addr,
82 wpabuf_head(auth->resp_msg),
83 wpabuf_len(auth->resp_msg),
84 500, wpas_dpp_tx_status, 0);
91 static void wpas_dpp_auth_resp_retry_timeout(void *eloop_ctx, void *timeout_ctx)
93 struct wpa_supplicant *wpa_s = eloop_ctx;
94 struct dpp_authentication *auth = wpa_s->dpp_auth;
96 if (!auth || !auth->resp_msg)
100 "DPP: Retry Authentication Response after timeout");
101 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
103 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
104 DPP_PA_AUTHENTICATION_RESP);
105 offchannel_send_action(wpa_s, auth->curr_freq, auth->peer_mac_addr,
106 wpa_s->own_addr, broadcast,
107 wpabuf_head(auth->resp_msg),
108 wpabuf_len(auth->resp_msg),
109 500, wpas_dpp_tx_status, 0);
113 static void wpas_dpp_auth_resp_retry(struct wpa_supplicant *wpa_s)
115 struct dpp_authentication *auth = wpa_s->dpp_auth;
116 unsigned int wait_time, max_tries;
118 if (!auth || !auth->resp_msg)
121 if (wpa_s->dpp_resp_max_tries)
122 max_tries = wpa_s->dpp_resp_max_tries;
125 auth->auth_resp_tries++;
126 if (auth->auth_resp_tries >= max_tries) {
127 wpa_printf(MSG_INFO, "DPP: No confirm received from initiator - stopping exchange");
128 offchannel_send_action_done(wpa_s);
129 dpp_auth_deinit(wpa_s->dpp_auth);
130 wpa_s->dpp_auth = NULL;
134 if (wpa_s->dpp_resp_retry_time)
135 wait_time = wpa_s->dpp_resp_retry_time;
138 wpa_printf(MSG_DEBUG,
139 "DPP: Schedule retransmission of Authentication Response frame in %u ms",
141 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
142 eloop_register_timeout(wait_time / 1000,
143 (wait_time % 1000) * 1000,
144 wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
148 static void wpas_dpp_try_to_connect(struct wpa_supplicant *wpa_s)
150 wpa_printf(MSG_DEBUG, "DPP: Trying to connect to the new network");
151 wpa_s->disconnected = 0;
152 wpa_s->reassociate = 1;
153 wpa_s->scan_runs = 0;
154 wpa_s->normal_scans = 0;
155 wpa_supplicant_cancel_sched_scan(wpa_s);
156 wpa_supplicant_req_scan(wpa_s, 0, 0);
160 static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
161 unsigned int freq, const u8 *dst,
162 const u8 *src, const u8 *bssid,
163 const u8 *data, size_t data_len,
164 enum offchannel_send_action_result result)
167 struct dpp_authentication *auth = wpa_s->dpp_auth;
169 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
170 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
172 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
173 " result=%s", freq, MAC2STR(dst), res_txt);
174 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
175 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
177 if (!wpa_s->dpp_auth) {
178 wpa_printf(MSG_DEBUG,
179 "DPP: Ignore TX status since there is no ongoing authentication exchange");
184 if (auth->connect_on_tx_status) {
185 wpa_printf(MSG_DEBUG,
186 "DPP: Try to connect after completed configuration result");
187 wpas_dpp_try_to_connect(wpa_s);
188 dpp_auth_deinit(wpa_s->dpp_auth);
189 wpa_s->dpp_auth = NULL;
192 #endif /* CONFIG_DPP2 */
194 if (wpa_s->dpp_auth->remove_on_tx_status) {
195 wpa_printf(MSG_DEBUG,
196 "DPP: Terminate authentication exchange due to an earlier error");
197 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
198 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
199 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
201 offchannel_send_action_done(wpa_s);
202 dpp_auth_deinit(wpa_s->dpp_auth);
203 wpa_s->dpp_auth = NULL;
207 if (wpa_s->dpp_auth_ok_on_ack)
208 wpas_dpp_auth_success(wpa_s, 1);
210 if (!is_broadcast_ether_addr(dst) &&
211 result != OFFCHANNEL_SEND_ACTION_SUCCESS) {
212 wpa_printf(MSG_DEBUG,
213 "DPP: Unicast DPP Action frame was not ACKed");
214 if (auth->waiting_auth_resp) {
215 /* In case of DPP Authentication Request frame, move to
216 * the next channel immediately. */
217 offchannel_send_action_done(wpa_s);
218 wpas_dpp_auth_init_next(wpa_s);
221 if (auth->waiting_auth_conf) {
222 wpas_dpp_auth_resp_retry(wpa_s);
227 if (!is_broadcast_ether_addr(dst) && auth->waiting_auth_resp &&
228 result == OFFCHANNEL_SEND_ACTION_SUCCESS) {
229 /* Allow timeout handling to stop iteration if no response is
230 * received from a peer that has ACKed a request. */
231 auth->auth_req_ack = 1;
234 if (!wpa_s->dpp_auth_ok_on_ack && wpa_s->dpp_auth->neg_freq > 0 &&
235 wpa_s->dpp_auth->curr_freq != wpa_s->dpp_auth->neg_freq) {
236 wpa_printf(MSG_DEBUG,
237 "DPP: Move from curr_freq %u MHz to neg_freq %u MHz for response",
238 wpa_s->dpp_auth->curr_freq,
239 wpa_s->dpp_auth->neg_freq);
240 offchannel_send_action_done(wpa_s);
241 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->neg_freq);
244 if (wpa_s->dpp_auth_ok_on_ack)
245 wpa_s->dpp_auth_ok_on_ack = 0;
249 static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx)
251 struct wpa_supplicant *wpa_s = eloop_ctx;
252 struct dpp_authentication *auth = wpa_s->dpp_auth;
254 struct os_reltime now, diff;
255 unsigned int wait_time, diff_ms;
257 if (!auth || !auth->waiting_auth_resp)
260 wait_time = wpa_s->dpp_resp_wait_time ?
261 wpa_s->dpp_resp_wait_time : 2000;
262 os_get_reltime(&now);
263 os_reltime_sub(&now, &wpa_s->dpp_last_init, &diff);
264 diff_ms = diff.sec * 1000 + diff.usec / 1000;
265 wpa_printf(MSG_DEBUG,
266 "DPP: Reply wait timeout - wait_time=%u diff_ms=%u",
269 if (auth->auth_req_ack && diff_ms >= wait_time) {
270 /* Peer ACK'ed Authentication Request frame, but did not reply
271 * with Authentication Response frame within two seconds. */
273 "DPP: No response received from responder - stopping initiation attempt");
274 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
275 offchannel_send_action_done(wpa_s);
276 wpas_dpp_listen_stop(wpa_s);
277 dpp_auth_deinit(auth);
278 wpa_s->dpp_auth = NULL;
282 if (diff_ms >= wait_time) {
283 /* Authentication Request frame was not ACK'ed and no reply
284 * was receiving within two seconds. */
285 wpa_printf(MSG_DEBUG,
286 "DPP: Continue Initiator channel iteration");
287 offchannel_send_action_done(wpa_s);
288 wpas_dpp_listen_stop(wpa_s);
289 wpas_dpp_auth_init_next(wpa_s);
293 /* Driver did not support 2000 ms long wait_time with TX command, so
294 * schedule listen operation to continue waiting for the response.
296 * DPP listen operations continue until stopped, so simply schedule a
297 * new call to this function at the point when the two second reply
298 * wait has expired. */
299 wait_time -= diff_ms;
301 freq = auth->curr_freq;
302 if (auth->neg_freq > 0)
303 freq = auth->neg_freq;
304 wpa_printf(MSG_DEBUG,
305 "DPP: Continue reply wait on channel %u MHz for %u ms",
307 wpa_s->dpp_in_response_listen = 1;
308 wpas_dpp_listen_start(wpa_s, freq);
310 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
311 wpas_dpp_reply_wait_timeout, wpa_s, NULL);
315 static void wpas_dpp_set_testing_options(struct wpa_supplicant *wpa_s,
316 struct dpp_authentication *auth)
318 #ifdef CONFIG_TESTING_OPTIONS
319 if (wpa_s->dpp_config_obj_override)
320 auth->config_obj_override =
321 os_strdup(wpa_s->dpp_config_obj_override);
322 if (wpa_s->dpp_discovery_override)
323 auth->discovery_override =
324 os_strdup(wpa_s->dpp_discovery_override);
325 if (wpa_s->dpp_groups_override)
326 auth->groups_override =
327 os_strdup(wpa_s->dpp_groups_override);
328 auth->ignore_netaccesskey_mismatch =
329 wpa_s->dpp_ignore_netaccesskey_mismatch;
330 #endif /* CONFIG_TESTING_OPTIONS */
334 static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx)
336 struct wpa_supplicant *wpa_s = eloop_ctx;
338 if (!wpa_s->dpp_auth)
340 wpa_printf(MSG_DEBUG, "DPP: Retry initiation after timeout");
341 wpas_dpp_auth_init_next(wpa_s);
345 static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s)
347 struct dpp_authentication *auth = wpa_s->dpp_auth;
349 unsigned int wait_time, max_wait_time, freq, max_tries, used;
350 struct os_reltime now, diff;
352 wpa_s->dpp_in_response_listen = 0;
356 if (auth->freq_idx == 0)
357 os_get_reltime(&wpa_s->dpp_init_iter_start);
359 if (auth->freq_idx >= auth->num_freq) {
360 auth->num_freq_iters++;
361 if (wpa_s->dpp_init_max_tries)
362 max_tries = wpa_s->dpp_init_max_tries;
365 if (auth->num_freq_iters >= max_tries || auth->auth_req_ack) {
367 "DPP: No response received from responder - stopping initiation attempt");
368 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
369 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout,
371 offchannel_send_action_done(wpa_s);
372 dpp_auth_deinit(wpa_s->dpp_auth);
373 wpa_s->dpp_auth = NULL;
377 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
378 if (wpa_s->dpp_init_retry_time)
379 wait_time = wpa_s->dpp_init_retry_time;
382 os_get_reltime(&now);
383 os_reltime_sub(&now, &wpa_s->dpp_init_iter_start, &diff);
384 used = diff.sec * 1000 + diff.usec / 1000;
385 if (used > wait_time)
389 wpa_printf(MSG_DEBUG, "DPP: Next init attempt in %u ms",
391 eloop_register_timeout(wait_time / 1000,
392 (wait_time % 1000) * 1000,
393 wpas_dpp_init_timeout, wpa_s,
397 freq = auth->freq[auth->freq_idx++];
398 auth->curr_freq = freq;
400 if (is_zero_ether_addr(auth->peer_bi->mac_addr))
403 dst = auth->peer_bi->mac_addr;
404 wpa_s->dpp_auth_ok_on_ack = 0;
405 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
406 wait_time = wpa_s->max_remain_on_chan;
407 max_wait_time = wpa_s->dpp_resp_wait_time ?
408 wpa_s->dpp_resp_wait_time : 2000;
409 if (wait_time > max_wait_time)
410 wait_time = max_wait_time;
411 wait_time += 10; /* give the driver some extra time to complete */
412 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
413 wpas_dpp_reply_wait_timeout,
416 if (auth->neg_freq > 0 && freq != auth->neg_freq) {
417 wpa_printf(MSG_DEBUG,
418 "DPP: Initiate on %u MHz and move to neg_freq %u MHz for response",
419 freq, auth->neg_freq);
421 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
422 MAC2STR(dst), freq, DPP_PA_AUTHENTICATION_REQ);
423 auth->auth_req_ack = 0;
424 os_get_reltime(&wpa_s->dpp_last_init);
425 return offchannel_send_action(wpa_s, freq, dst,
426 wpa_s->own_addr, broadcast,
427 wpabuf_head(auth->req_msg),
428 wpabuf_len(auth->req_msg),
429 wait_time, wpas_dpp_tx_status, 0);
433 int wpas_dpp_auth_init(struct wpa_supplicant *wpa_s, const char *cmd)
436 struct dpp_bootstrap_info *peer_bi, *own_bi = NULL;
437 struct dpp_authentication *auth;
438 u8 allowed_roles = DPP_CAPAB_CONFIGURATOR;
439 unsigned int neg_freq = 0;
442 int tcp_port = DPP_TCP_PORT;
443 struct hostapd_ip_addr ipaddr;
445 #endif /* CONFIG_DPP2 */
447 wpa_s->dpp_gas_client = 0;
449 pos = os_strstr(cmd, " peer=");
453 peer_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
456 "DPP: Could not find bootstrapping info for the identified peer");
461 pos = os_strstr(cmd, " tcp_port=");
464 tcp_port = atoi(pos);
467 addr = get_param(cmd, " tcp_addr=");
471 res = hostapd_parse_ip_addr(addr, &ipaddr);
477 #endif /* CONFIG_DPP2 */
479 pos = os_strstr(cmd, " own=");
482 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
485 "DPP: Could not find bootstrapping info for the identified local entry");
489 if (peer_bi->curve != own_bi->curve) {
491 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
492 peer_bi->curve->name, own_bi->curve->name);
497 pos = os_strstr(cmd, " role=");
500 if (os_strncmp(pos, "configurator", 12) == 0)
501 allowed_roles = DPP_CAPAB_CONFIGURATOR;
502 else if (os_strncmp(pos, "enrollee", 8) == 0)
503 allowed_roles = DPP_CAPAB_ENROLLEE;
504 else if (os_strncmp(pos, "either", 6) == 0)
505 allowed_roles = DPP_CAPAB_CONFIGURATOR |
511 pos = os_strstr(cmd, " netrole=");
514 wpa_s->dpp_netrole_ap = os_strncmp(pos, "ap", 2) == 0;
517 pos = os_strstr(cmd, " neg_freq=");
519 neg_freq = atoi(pos + 10);
521 if (!tcp && wpa_s->dpp_auth) {
522 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
523 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
524 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
526 offchannel_send_action_done(wpa_s);
527 dpp_auth_deinit(wpa_s->dpp_auth);
528 wpa_s->dpp_auth = NULL;
531 auth = dpp_auth_init(wpa_s, peer_bi, own_bi, allowed_roles, neg_freq,
532 wpa_s->hw.modes, wpa_s->hw.num_modes);
535 wpas_dpp_set_testing_options(wpa_s, auth);
536 if (dpp_set_configurator(wpa_s->dpp, wpa_s, auth, cmd) < 0) {
537 dpp_auth_deinit(auth);
541 auth->neg_freq = neg_freq;
543 if (!is_zero_ether_addr(peer_bi->mac_addr))
544 os_memcpy(auth->peer_mac_addr, peer_bi->mac_addr, ETH_ALEN);
548 return dpp_tcp_init(wpa_s->dpp, auth, &ipaddr, tcp_port);
549 #endif /* CONFIG_DPP2 */
551 wpa_s->dpp_auth = auth;
552 return wpas_dpp_auth_init_next(wpa_s);
558 struct wpas_dpp_listen_work {
560 unsigned int duration;
561 struct wpabuf *probe_resp_ie;
565 static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work *lwork)
573 static void wpas_dpp_listen_work_done(struct wpa_supplicant *wpa_s)
575 struct wpas_dpp_listen_work *lwork;
577 if (!wpa_s->dpp_listen_work)
580 lwork = wpa_s->dpp_listen_work->ctx;
581 wpas_dpp_listen_work_free(lwork);
582 radio_work_done(wpa_s->dpp_listen_work);
583 wpa_s->dpp_listen_work = NULL;
587 static void dpp_start_listen_cb(struct wpa_radio_work *work, int deinit)
589 struct wpa_supplicant *wpa_s = work->wpa_s;
590 struct wpas_dpp_listen_work *lwork = work->ctx;
594 wpa_s->dpp_listen_work = NULL;
595 wpas_dpp_listen_stop(wpa_s);
597 wpas_dpp_listen_work_free(lwork);
601 wpa_s->dpp_listen_work = work;
603 wpa_s->dpp_pending_listen_freq = lwork->freq;
605 if (wpa_drv_remain_on_channel(wpa_s, lwork->freq,
606 wpa_s->max_remain_on_chan) < 0) {
607 wpa_printf(MSG_DEBUG,
608 "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
610 wpa_s->dpp_listen_freq = 0;
611 wpas_dpp_listen_work_done(wpa_s);
612 wpa_s->dpp_pending_listen_freq = 0;
615 wpa_s->off_channel_freq = 0;
616 wpa_s->roc_waiting_drv_freq = lwork->freq;
620 static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
623 struct wpas_dpp_listen_work *lwork;
625 if (wpa_s->dpp_listen_work) {
626 wpa_printf(MSG_DEBUG,
627 "DPP: Reject start_listen since dpp_listen_work already exists");
631 if (wpa_s->dpp_listen_freq)
632 wpas_dpp_listen_stop(wpa_s);
633 wpa_s->dpp_listen_freq = freq;
635 lwork = os_zalloc(sizeof(*lwork));
640 if (radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb,
642 wpas_dpp_listen_work_free(lwork);
650 int wpas_dpp_listen(struct wpa_supplicant *wpa_s, const char *cmd)
658 if (os_strstr(cmd, " role=configurator"))
659 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR;
660 else if (os_strstr(cmd, " role=enrollee"))
661 wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
663 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
665 wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
666 wpa_s->dpp_netrole_ap = os_strstr(cmd, " netrole=ap") != NULL;
667 if (wpa_s->dpp_listen_freq == (unsigned int) freq) {
668 wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz",
673 return wpas_dpp_listen_start(wpa_s, freq);
677 void wpas_dpp_listen_stop(struct wpa_supplicant *wpa_s)
679 wpa_s->dpp_in_response_listen = 0;
680 if (!wpa_s->dpp_listen_freq)
683 wpa_printf(MSG_DEBUG, "DPP: Stop listen on %u MHz",
684 wpa_s->dpp_listen_freq);
685 wpa_drv_cancel_remain_on_channel(wpa_s);
686 wpa_s->dpp_listen_freq = 0;
687 wpas_dpp_listen_work_done(wpa_s);
691 void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
694 wpas_dpp_listen_work_done(wpa_s);
696 if (wpa_s->dpp_auth && wpa_s->dpp_in_response_listen) {
697 unsigned int new_freq;
699 /* Continue listen with a new remain-on-channel */
700 if (wpa_s->dpp_auth->neg_freq > 0)
701 new_freq = wpa_s->dpp_auth->neg_freq;
703 new_freq = wpa_s->dpp_auth->curr_freq;
704 wpa_printf(MSG_DEBUG,
705 "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
707 wpas_dpp_listen_start(wpa_s, new_freq);
711 if (wpa_s->dpp_listen_freq) {
712 /* Continue listen with a new remain-on-channel */
713 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_listen_freq);
718 static void wpas_dpp_rx_auth_req(struct wpa_supplicant *wpa_s, const u8 *src,
719 const u8 *hdr, const u8 *buf, size_t len,
722 const u8 *r_bootstrap, *i_bootstrap;
723 u16 r_bootstrap_len, i_bootstrap_len;
724 struct dpp_bootstrap_info *own_bi = NULL, *peer_bi = NULL;
729 wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR,
732 r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
734 if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
735 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
736 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
739 wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
740 r_bootstrap, r_bootstrap_len);
742 i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH,
744 if (!i_bootstrap || i_bootstrap_len != SHA256_MAC_LEN) {
745 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
746 "Missing or invalid required Initiator Bootstrapping Key Hash attribute");
749 wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash",
750 i_bootstrap, i_bootstrap_len);
752 /* Try to find own and peer bootstrapping key matches based on the
753 * received hash values */
754 dpp_bootstrap_find_pair(wpa_s->dpp, i_bootstrap, r_bootstrap,
757 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
758 "No matching own bootstrapping key found - ignore message");
762 if (wpa_s->dpp_auth) {
763 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
764 "Already in DPP authentication exchange - ignore new one");
768 wpa_s->dpp_gas_client = 0;
769 wpa_s->dpp_auth_ok_on_ack = 0;
770 wpa_s->dpp_auth = dpp_auth_req_rx(wpa_s, wpa_s->dpp_allowed_roles,
771 wpa_s->dpp_qr_mutual,
772 peer_bi, own_bi, freq, hdr, buf, len);
773 if (!wpa_s->dpp_auth) {
774 wpa_printf(MSG_DEBUG, "DPP: No response generated");
777 wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
778 if (dpp_set_configurator(wpa_s->dpp, wpa_s, wpa_s->dpp_auth,
779 wpa_s->dpp_configurator_params) < 0) {
780 dpp_auth_deinit(wpa_s->dpp_auth);
781 wpa_s->dpp_auth = NULL;
784 os_memcpy(wpa_s->dpp_auth->peer_mac_addr, src, ETH_ALEN);
786 if (wpa_s->dpp_listen_freq &&
787 wpa_s->dpp_listen_freq != wpa_s->dpp_auth->curr_freq) {
788 wpa_printf(MSG_DEBUG,
789 "DPP: Stop listen on %u MHz to allow response on the request %u MHz",
790 wpa_s->dpp_listen_freq, wpa_s->dpp_auth->curr_freq);
791 wpas_dpp_listen_stop(wpa_s);
794 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
795 MAC2STR(src), wpa_s->dpp_auth->curr_freq,
796 DPP_PA_AUTHENTICATION_RESP);
797 offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq,
798 src, wpa_s->own_addr, broadcast,
799 wpabuf_head(wpa_s->dpp_auth->resp_msg),
800 wpabuf_len(wpa_s->dpp_auth->resp_msg),
801 500, wpas_dpp_tx_status, 0);
805 static void wpas_dpp_start_gas_server(struct wpa_supplicant *wpa_s)
807 /* TODO: stop wait and start ROC */
811 static struct wpa_ssid * wpas_dpp_add_network(struct wpa_supplicant *wpa_s,
812 struct dpp_authentication *auth)
814 struct wpa_ssid *ssid;
817 if (auth->akm == DPP_AKM_SAE) {
819 struct wpa_driver_capa capa;
822 res = wpa_drv_get_capa(wpa_s, &capa);
824 !(capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) &&
825 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
826 wpa_printf(MSG_DEBUG,
827 "DPP: SAE not supported by the driver");
830 #else /* CONFIG_SAE */
831 wpa_printf(MSG_DEBUG, "DPP: SAE not supported in the build");
833 #endif /* CONFIG_SAE */
835 #endif /* CONFIG_DPP2 */
837 ssid = wpa_config_add_network(wpa_s->conf);
840 wpas_notify_network_added(wpa_s, ssid);
841 wpa_config_set_network_defaults(ssid);
844 ssid->ssid = os_malloc(auth->ssid_len);
847 os_memcpy(ssid->ssid, auth->ssid, auth->ssid_len);
848 ssid->ssid_len = auth->ssid_len;
850 if (auth->connector) {
851 ssid->key_mgmt = WPA_KEY_MGMT_DPP;
852 ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED;
853 ssid->dpp_connector = os_strdup(auth->connector);
854 if (!ssid->dpp_connector)
858 if (auth->c_sign_key) {
859 ssid->dpp_csign = os_malloc(wpabuf_len(auth->c_sign_key));
860 if (!ssid->dpp_csign)
862 os_memcpy(ssid->dpp_csign, wpabuf_head(auth->c_sign_key),
863 wpabuf_len(auth->c_sign_key));
864 ssid->dpp_csign_len = wpabuf_len(auth->c_sign_key);
867 if (auth->net_access_key) {
868 ssid->dpp_netaccesskey =
869 os_malloc(wpabuf_len(auth->net_access_key));
870 if (!ssid->dpp_netaccesskey)
872 os_memcpy(ssid->dpp_netaccesskey,
873 wpabuf_head(auth->net_access_key),
874 wpabuf_len(auth->net_access_key));
875 ssid->dpp_netaccesskey_len = wpabuf_len(auth->net_access_key);
876 ssid->dpp_netaccesskey_expiry = auth->net_access_key_expiry;
879 if (!auth->connector || dpp_akm_psk(auth->akm) ||
880 dpp_akm_sae(auth->akm)) {
881 if (!auth->connector)
883 if (dpp_akm_psk(auth->akm))
884 ssid->key_mgmt |= WPA_KEY_MGMT_PSK |
885 WPA_KEY_MGMT_PSK_SHA256 | WPA_KEY_MGMT_FT_PSK;
886 if (dpp_akm_sae(auth->akm))
887 ssid->key_mgmt |= WPA_KEY_MGMT_SAE |
889 ssid->ieee80211w = MGMT_FRAME_PROTECTION_OPTIONAL;
890 if (auth->passphrase[0]) {
891 if (wpa_config_set_quoted(ssid, "psk",
892 auth->passphrase) < 0)
894 wpa_config_update_psk(ssid);
895 ssid->export_keys = 1;
897 ssid->psk_set = auth->psk_set;
898 os_memcpy(ssid->psk, auth->psk, PMK_LEN);
904 wpas_notify_network_removed(wpa_s, ssid);
905 wpa_config_remove_network(wpa_s->conf, ssid->id);
910 static int wpas_dpp_process_config(struct wpa_supplicant *wpa_s,
911 struct dpp_authentication *auth)
913 struct wpa_ssid *ssid;
915 if (wpa_s->conf->dpp_config_processing < 1)
918 ssid = wpas_dpp_add_network(wpa_s, auth);
922 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_NETWORK_ID "%d", ssid->id);
923 if (wpa_s->conf->dpp_config_processing == 2)
926 #ifndef CONFIG_NO_CONFIG_WRITE
927 if (wpa_s->conf->update_config &&
928 wpa_config_write(wpa_s->confname, wpa_s->conf))
929 wpa_printf(MSG_DEBUG, "DPP: Failed to update configuration");
930 #endif /* CONFIG_NO_CONFIG_WRITE */
932 if (wpa_s->conf->dpp_config_processing < 2)
936 if (auth->peer_version >= 2) {
937 wpa_printf(MSG_DEBUG,
938 "DPP: Postpone connection attempt to wait for completion of DPP Configuration Result");
939 auth->connect_on_tx_status = 1;
942 #endif /* CONFIG_DPP2 */
944 wpas_dpp_try_to_connect(wpa_s);
949 static int wpas_dpp_handle_config_obj(struct wpa_supplicant *wpa_s,
950 struct dpp_authentication *auth)
952 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
954 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s",
955 wpa_ssid_txt(auth->ssid, auth->ssid_len));
956 if (auth->connector) {
957 /* TODO: Save the Connector and consider using a command
958 * to fetch the value instead of sending an event with
959 * it. The Connector could end up being larger than what
960 * most clients are ready to receive as an event
962 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONNECTOR "%s",
965 if (auth->c_sign_key) {
969 hexlen = 2 * wpabuf_len(auth->c_sign_key) + 1;
970 hex = os_malloc(hexlen);
972 wpa_snprintf_hex(hex, hexlen,
973 wpabuf_head(auth->c_sign_key),
974 wpabuf_len(auth->c_sign_key));
975 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_C_SIGN_KEY "%s",
980 if (auth->net_access_key) {
984 hexlen = 2 * wpabuf_len(auth->net_access_key) + 1;
985 hex = os_malloc(hexlen);
987 wpa_snprintf_hex(hex, hexlen,
988 wpabuf_head(auth->net_access_key),
989 wpabuf_len(auth->net_access_key));
990 if (auth->net_access_key_expiry)
991 wpa_msg(wpa_s, MSG_INFO,
992 DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex,
994 auth->net_access_key_expiry);
996 wpa_msg(wpa_s, MSG_INFO,
997 DPP_EVENT_NET_ACCESS_KEY "%s", hex);
1002 return wpas_dpp_process_config(wpa_s, auth);
1006 static void wpas_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token,
1007 enum gas_query_result result,
1008 const struct wpabuf *adv_proto,
1009 const struct wpabuf *resp, u16 status_code)
1011 struct wpa_supplicant *wpa_s = ctx;
1013 struct dpp_authentication *auth = wpa_s->dpp_auth;
1015 enum dpp_status_error status = DPP_STATUS_CONFIG_REJECTED;
1017 wpa_s->dpp_gas_dialog_token = -1;
1019 if (!auth || !auth->auth_success) {
1020 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
1023 if (result != GAS_QUERY_SUCCESS ||
1024 !resp || status_code != WLAN_STATUS_SUCCESS) {
1025 wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed");
1029 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto",
1031 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)",
1034 if (wpabuf_len(adv_proto) != 10 ||
1035 !(pos = wpabuf_head(adv_proto)) ||
1036 pos[0] != WLAN_EID_ADV_PROTO ||
1038 pos[3] != WLAN_EID_VENDOR_SPECIFIC ||
1040 WPA_GET_BE24(&pos[5]) != OUI_WFA ||
1043 wpa_printf(MSG_DEBUG,
1044 "DPP: Not a DPP Advertisement Protocol ID");
1048 if (dpp_conf_resp_rx(auth, resp) < 0) {
1049 wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed");
1053 res = wpas_dpp_handle_config_obj(wpa_s, auth);
1057 status = DPP_STATUS_OK;
1058 #ifdef CONFIG_TESTING_OPTIONS
1059 if (dpp_test == DPP_TEST_REJECT_CONFIG) {
1060 wpa_printf(MSG_INFO, "DPP: TESTING - Reject Config Object");
1061 status = DPP_STATUS_CONFIG_REJECTED;
1063 #endif /* CONFIG_TESTING_OPTIONS */
1065 if (status != DPP_STATUS_OK)
1066 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1068 if (auth->peer_version >= 2 &&
1069 auth->conf_resp_status == DPP_STATUS_OK) {
1072 wpa_printf(MSG_DEBUG, "DPP: Send DPP Configuration Result");
1073 msg = dpp_build_conf_result(auth, status);
1077 wpa_msg(wpa_s, MSG_INFO,
1078 DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1079 MAC2STR(addr), auth->curr_freq,
1080 DPP_PA_CONFIGURATION_RESULT);
1081 offchannel_send_action(wpa_s, auth->curr_freq,
1082 addr, wpa_s->own_addr, broadcast,
1085 500, wpas_dpp_tx_status, 0);
1088 /* This exchange will be terminated in the TX status handler */
1092 #endif /* CONFIG_DPP2 */
1093 dpp_auth_deinit(wpa_s->dpp_auth);
1094 wpa_s->dpp_auth = NULL;
1098 static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
1100 struct dpp_authentication *auth = wpa_s->dpp_auth;
1105 wpa_s->dpp_gas_client = 1;
1106 os_snprintf(json, sizeof(json),
1107 "{\"name\":\"Test\","
1108 "\"wi-fi_tech\":\"infra\","
1109 "\"netRole\":\"%s\"}",
1110 wpa_s->dpp_netrole_ap ? "ap" : "sta");
1111 #ifdef CONFIG_TESTING_OPTIONS
1112 if (dpp_test == DPP_TEST_INVALID_CONFIG_ATTR_OBJ_CONF_REQ) {
1113 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Config Attr");
1114 json[29] = 'k'; /* replace "infra" with "knfra" */
1116 #endif /* CONFIG_TESTING_OPTIONS */
1117 wpa_printf(MSG_DEBUG, "DPP: GAS Config Attributes: %s", json);
1119 offchannel_send_action_done(wpa_s);
1120 wpas_dpp_listen_stop(wpa_s);
1122 buf = dpp_build_conf_req(auth, json);
1124 wpa_printf(MSG_DEBUG,
1125 "DPP: No configuration request data available");
1129 wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
1130 MAC2STR(auth->peer_mac_addr), auth->curr_freq);
1132 res = gas_query_req(wpa_s->gas, auth->peer_mac_addr, auth->curr_freq,
1133 1, buf, wpas_dpp_gas_resp_cb, wpa_s);
1135 wpa_msg(wpa_s, MSG_DEBUG, "GAS: Failed to send Query Request");
1138 wpa_printf(MSG_DEBUG,
1139 "DPP: GAS query started with dialog token %u", res);
1140 wpa_s->dpp_gas_dialog_token = res;
1145 static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator)
1147 wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded");
1148 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d", initiator);
1149 #ifdef CONFIG_TESTING_OPTIONS
1150 if (dpp_test == DPP_TEST_STOP_AT_AUTH_CONF) {
1151 wpa_printf(MSG_INFO,
1152 "DPP: TESTING - stop at Authentication Confirm");
1153 if (wpa_s->dpp_auth->configurator) {
1154 /* Prevent GAS response */
1155 wpa_s->dpp_auth->auth_success = 0;
1159 #endif /* CONFIG_TESTING_OPTIONS */
1161 if (wpa_s->dpp_auth->configurator)
1162 wpas_dpp_start_gas_server(wpa_s);
1164 wpas_dpp_start_gas_client(wpa_s);
1168 static void wpas_dpp_rx_auth_resp(struct wpa_supplicant *wpa_s, const u8 *src,
1169 const u8 *hdr, const u8 *buf, size_t len,
1172 struct dpp_authentication *auth = wpa_s->dpp_auth;
1175 wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR
1176 " (freq %u MHz)", MAC2STR(src), freq);
1179 wpa_printf(MSG_DEBUG,
1180 "DPP: No DPP Authentication in progress - drop");
1184 if (!is_zero_ether_addr(auth->peer_mac_addr) &&
1185 os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1186 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1187 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1191 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
1193 if (auth->curr_freq != freq && auth->neg_freq == freq) {
1194 wpa_printf(MSG_DEBUG,
1195 "DPP: Responder accepted request for different negotiation channel");
1196 auth->curr_freq = freq;
1199 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
1200 msg = dpp_auth_resp_rx(auth, hdr, buf, len);
1202 if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) {
1203 wpa_printf(MSG_DEBUG,
1204 "DPP: Start wait for full response");
1205 offchannel_send_action_done(wpa_s);
1206 wpas_dpp_listen_start(wpa_s, auth->curr_freq);
1209 wpa_printf(MSG_DEBUG, "DPP: No confirm generated");
1212 os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
1214 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1215 MAC2STR(src), auth->curr_freq, DPP_PA_AUTHENTICATION_CONF);
1216 offchannel_send_action(wpa_s, auth->curr_freq,
1217 src, wpa_s->own_addr, broadcast,
1218 wpabuf_head(msg), wpabuf_len(msg),
1219 500, wpas_dpp_tx_status, 0);
1221 wpa_s->dpp_auth_ok_on_ack = 1;
1225 static void wpas_dpp_rx_auth_conf(struct wpa_supplicant *wpa_s, const u8 *src,
1226 const u8 *hdr, const u8 *buf, size_t len)
1228 struct dpp_authentication *auth = wpa_s->dpp_auth;
1230 wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR,
1234 wpa_printf(MSG_DEBUG,
1235 "DPP: No DPP Authentication in progress - drop");
1239 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1240 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1241 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1245 if (dpp_auth_conf_rx(auth, hdr, buf, len) < 0) {
1246 wpa_printf(MSG_DEBUG, "DPP: Authentication failed");
1250 wpas_dpp_auth_success(wpa_s, 0);
1256 static void wpas_dpp_config_result_wait_timeout(void *eloop_ctx,
1259 struct wpa_supplicant *wpa_s = eloop_ctx;
1260 struct dpp_authentication *auth = wpa_s->dpp_auth;
1262 if (!auth || !auth->waiting_conf_result)
1265 wpa_printf(MSG_DEBUG,
1266 "DPP: Timeout while waiting for Configuration Result");
1267 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1268 dpp_auth_deinit(auth);
1269 wpa_s->dpp_auth = NULL;
1273 static void wpas_dpp_rx_conf_result(struct wpa_supplicant *wpa_s, const u8 *src,
1274 const u8 *hdr, const u8 *buf, size_t len)
1276 struct dpp_authentication *auth = wpa_s->dpp_auth;
1277 enum dpp_status_error status;
1279 wpa_printf(MSG_DEBUG, "DPP: Configuration Result from " MACSTR,
1282 if (!auth || !auth->waiting_conf_result) {
1283 wpa_printf(MSG_DEBUG,
1284 "DPP: No DPP Configuration waiting for result - drop");
1288 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1289 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1290 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1294 status = dpp_conf_result_rx(auth, hdr, buf, len);
1296 offchannel_send_action_done(wpa_s);
1297 wpas_dpp_listen_stop(wpa_s);
1298 if (status == DPP_STATUS_OK)
1299 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
1301 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1302 dpp_auth_deinit(auth);
1303 wpa_s->dpp_auth = NULL;
1304 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL);
1308 static int wpas_dpp_process_conf_obj(void *ctx,
1309 struct dpp_authentication *auth)
1311 struct wpa_supplicant *wpa_s = ctx;
1313 return wpas_dpp_handle_config_obj(wpa_s, auth);
1316 #endif /* CONFIG_DPP2 */
1319 static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant *wpa_s,
1321 const u8 *buf, size_t len)
1323 struct wpa_ssid *ssid;
1324 const u8 *connector, *trans_id, *status;
1325 u16 connector_len, trans_id_len, status_len;
1326 struct dpp_introduction intro;
1327 struct rsn_pmksa_cache_entry *entry;
1329 struct os_reltime rnow;
1331 unsigned int seconds;
1332 enum dpp_status_error res;
1334 wpa_printf(MSG_DEBUG, "DPP: Peer Discovery Response from " MACSTR,
1336 if (is_zero_ether_addr(wpa_s->dpp_intro_bssid) ||
1337 os_memcmp(src, wpa_s->dpp_intro_bssid, ETH_ALEN) != 0) {
1338 wpa_printf(MSG_DEBUG, "DPP: Not waiting for response from "
1339 MACSTR " - drop", MAC2STR(src));
1342 offchannel_send_action_done(wpa_s);
1344 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1345 if (ssid == wpa_s->dpp_intro_network)
1348 if (!ssid || !ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1350 wpa_printf(MSG_DEBUG,
1351 "DPP: Profile not found for network introduction");
1355 trans_id = dpp_get_attr(buf, len, DPP_ATTR_TRANSACTION_ID,
1357 if (!trans_id || trans_id_len != 1) {
1358 wpa_printf(MSG_DEBUG,
1359 "DPP: Peer did not include Transaction ID");
1360 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1361 " fail=missing_transaction_id", MAC2STR(src));
1364 if (trans_id[0] != TRANSACTION_ID) {
1365 wpa_printf(MSG_DEBUG,
1366 "DPP: Ignore frame with unexpected Transaction ID %u",
1368 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1369 " fail=transaction_id_mismatch", MAC2STR(src));
1373 status = dpp_get_attr(buf, len, DPP_ATTR_STATUS, &status_len);
1374 if (!status || status_len != 1) {
1375 wpa_printf(MSG_DEBUG, "DPP: Peer did not include Status");
1376 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1377 " fail=missing_status", MAC2STR(src));
1380 if (status[0] != DPP_STATUS_OK) {
1381 wpa_printf(MSG_DEBUG,
1382 "DPP: Peer rejected network introduction: Status %u",
1384 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1385 " status=%u", MAC2STR(src), status[0]);
1389 connector = dpp_get_attr(buf, len, DPP_ATTR_CONNECTOR, &connector_len);
1391 wpa_printf(MSG_DEBUG,
1392 "DPP: Peer did not include its Connector");
1393 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1394 " fail=missing_connector", MAC2STR(src));
1398 res = dpp_peer_intro(&intro, ssid->dpp_connector,
1399 ssid->dpp_netaccesskey,
1400 ssid->dpp_netaccesskey_len,
1402 ssid->dpp_csign_len,
1403 connector, connector_len, &expiry);
1404 if (res != DPP_STATUS_OK) {
1405 wpa_printf(MSG_INFO,
1406 "DPP: Network Introduction protocol resulted in failure");
1407 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1408 " fail=peer_connector_validation_failed", MAC2STR(src));
1412 entry = os_zalloc(sizeof(*entry));
1415 os_memcpy(entry->aa, src, ETH_ALEN);
1416 os_memcpy(entry->pmkid, intro.pmkid, PMKID_LEN);
1417 os_memcpy(entry->pmk, intro.pmk, intro.pmk_len);
1418 entry->pmk_len = intro.pmk_len;
1419 entry->akmp = WPA_KEY_MGMT_DPP;
1422 seconds = expiry - now.sec;
1424 seconds = 86400 * 7;
1426 os_get_reltime(&rnow);
1427 entry->expiration = rnow.sec + seconds;
1428 entry->reauth_time = rnow.sec + seconds;
1429 entry->network_ctx = ssid;
1430 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
1432 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1433 " status=%u", MAC2STR(src), status[0]);
1435 wpa_printf(MSG_DEBUG,
1436 "DPP: Try connection again after successful network introduction");
1437 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
1438 wpa_supplicant_cancel_sched_scan(wpa_s);
1439 wpa_supplicant_req_scan(wpa_s, 0, 0);
1442 os_memset(&intro, 0, sizeof(intro));
1446 static int wpas_dpp_allow_ir(struct wpa_supplicant *wpa_s, unsigned int freq)
1450 if (!wpa_s->hw.modes)
1453 for (i = 0; i < wpa_s->hw.num_modes; i++) {
1454 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
1456 for (j = 0; j < mode->num_channels; j++) {
1457 struct hostapd_channel_data *chan = &mode->channels[j];
1459 if (chan->freq != (int) freq)
1462 if (chan->flag & (HOSTAPD_CHAN_DISABLED |
1463 HOSTAPD_CHAN_NO_IR |
1464 HOSTAPD_CHAN_RADAR))
1471 wpa_printf(MSG_DEBUG,
1472 "DPP: Frequency %u MHz not supported or does not allow PKEX initiation in the current channel list",
1479 static int wpas_dpp_pkex_next_channel(struct wpa_supplicant *wpa_s,
1480 struct dpp_pkex *pkex)
1482 if (pkex->freq == 2437)
1484 else if (pkex->freq == 5745)
1486 else if (pkex->freq == 5220)
1489 return -1; /* no more channels to try */
1491 if (wpas_dpp_allow_ir(wpa_s, pkex->freq) == 1) {
1492 wpa_printf(MSG_DEBUG, "DPP: Try to initiate on %u MHz",
1497 /* Could not use this channel - try the next one */
1498 return wpas_dpp_pkex_next_channel(wpa_s, pkex);
1502 static void wpas_dpp_pkex_retry_timeout(void *eloop_ctx, void *timeout_ctx)
1504 struct wpa_supplicant *wpa_s = eloop_ctx;
1505 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1507 if (!pkex || !pkex->exchange_req)
1509 if (pkex->exch_req_tries >= 5) {
1510 if (wpas_dpp_pkex_next_channel(wpa_s, pkex) < 0) {
1511 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1512 "No response from PKEX peer");
1513 dpp_pkex_free(pkex);
1514 wpa_s->dpp_pkex = NULL;
1517 pkex->exch_req_tries = 0;
1520 pkex->exch_req_tries++;
1521 wpa_printf(MSG_DEBUG, "DPP: Retransmit PKEX Exchange Request (try %u)",
1522 pkex->exch_req_tries);
1523 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1524 MAC2STR(broadcast), pkex->freq, DPP_PA_PKEX_EXCHANGE_REQ);
1525 offchannel_send_action(wpa_s, pkex->freq, broadcast,
1526 wpa_s->own_addr, broadcast,
1527 wpabuf_head(pkex->exchange_req),
1528 wpabuf_len(pkex->exchange_req),
1529 pkex->exch_req_wait_time,
1530 wpas_dpp_tx_pkex_status, 0);
1535 wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s,
1536 unsigned int freq, const u8 *dst,
1537 const u8 *src, const u8 *bssid,
1538 const u8 *data, size_t data_len,
1539 enum offchannel_send_action_result result)
1541 const char *res_txt;
1542 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1544 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
1545 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
1547 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
1548 " result=%s (PKEX)",
1549 freq, MAC2STR(dst), res_txt);
1550 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
1551 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
1554 wpa_printf(MSG_DEBUG,
1555 "DPP: Ignore TX status since there is no ongoing PKEX exchange");
1560 wpa_printf(MSG_DEBUG,
1561 "DPP: Terminate PKEX exchange due to an earlier error");
1562 if (pkex->t > pkex->own_bi->pkex_t)
1563 pkex->own_bi->pkex_t = pkex->t;
1564 dpp_pkex_free(pkex);
1565 wpa_s->dpp_pkex = NULL;
1569 if (pkex->exch_req_wait_time && pkex->exchange_req) {
1570 /* Wait for PKEX Exchange Response frame and retry request if
1571 * no response is seen. */
1572 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
1573 eloop_register_timeout(pkex->exch_req_wait_time / 1000,
1574 (pkex->exch_req_wait_time % 1000) * 1000,
1575 wpas_dpp_pkex_retry_timeout, wpa_s,
1582 wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant *wpa_s, const u8 *src,
1583 const u8 *buf, size_t len, unsigned int freq)
1586 unsigned int wait_time;
1588 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Request from " MACSTR,
1591 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1594 if (!wpa_s->dpp_pkex_code || !wpa_s->dpp_pkex_bi) {
1595 wpa_printf(MSG_DEBUG,
1596 "DPP: No PKEX code configured - ignore request");
1600 if (wpa_s->dpp_pkex) {
1601 /* TODO: Support parallel operations */
1602 wpa_printf(MSG_DEBUG,
1603 "DPP: Already in PKEX session - ignore new request");
1607 wpa_s->dpp_pkex = dpp_pkex_rx_exchange_req(wpa_s, wpa_s->dpp_pkex_bi,
1608 wpa_s->own_addr, src,
1609 wpa_s->dpp_pkex_identifier,
1610 wpa_s->dpp_pkex_code,
1612 if (!wpa_s->dpp_pkex) {
1613 wpa_printf(MSG_DEBUG,
1614 "DPP: Failed to process the request - ignore it");
1618 msg = wpa_s->dpp_pkex->exchange_resp;
1619 wait_time = wpa_s->max_remain_on_chan;
1620 if (wait_time > 2000)
1622 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1623 MAC2STR(src), freq, DPP_PA_PKEX_EXCHANGE_RESP);
1624 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
1626 wpabuf_head(msg), wpabuf_len(msg),
1627 wait_time, wpas_dpp_tx_pkex_status, 0);
1632 wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant *wpa_s, const u8 *src,
1633 const u8 *buf, size_t len, unsigned int freq)
1636 unsigned int wait_time;
1638 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Response from " MACSTR,
1641 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1644 if (!wpa_s->dpp_pkex || !wpa_s->dpp_pkex->initiator ||
1645 wpa_s->dpp_pkex->exchange_done) {
1646 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1650 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
1651 wpa_s->dpp_pkex->exch_req_wait_time = 0;
1653 msg = dpp_pkex_rx_exchange_resp(wpa_s->dpp_pkex, src, buf, len);
1655 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
1659 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Request to " MACSTR,
1662 wait_time = wpa_s->max_remain_on_chan;
1663 if (wait_time > 2000)
1665 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1666 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_REQ);
1667 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
1669 wpabuf_head(msg), wpabuf_len(msg),
1670 wait_time, wpas_dpp_tx_pkex_status, 0);
1675 static struct dpp_bootstrap_info *
1676 wpas_dpp_pkex_finish(struct wpa_supplicant *wpa_s, const u8 *peer,
1679 struct dpp_bootstrap_info *bi;
1681 bi = dpp_pkex_finish(wpa_s->dpp, wpa_s->dpp_pkex, peer, freq);
1684 wpa_s->dpp_pkex = NULL;
1690 wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant *wpa_s, const u8 *src,
1691 const u8 *hdr, const u8 *buf, size_t len,
1695 unsigned int wait_time;
1696 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1698 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Request from " MACSTR,
1701 if (!pkex || pkex->initiator || !pkex->exchange_done) {
1702 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1706 msg = dpp_pkex_rx_commit_reveal_req(pkex, hdr, buf, len);
1708 wpa_printf(MSG_DEBUG, "DPP: Failed to process the request");
1710 wpa_printf(MSG_DEBUG, "DPP: Terminate PKEX exchange");
1711 if (pkex->t > pkex->own_bi->pkex_t)
1712 pkex->own_bi->pkex_t = pkex->t;
1713 dpp_pkex_free(wpa_s->dpp_pkex);
1714 wpa_s->dpp_pkex = NULL;
1719 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Response to "
1720 MACSTR, MAC2STR(src));
1722 wait_time = wpa_s->max_remain_on_chan;
1723 if (wait_time > 2000)
1725 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1726 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_RESP);
1727 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
1729 wpabuf_head(msg), wpabuf_len(msg),
1730 wait_time, wpas_dpp_tx_pkex_status, 0);
1733 wpas_dpp_pkex_finish(wpa_s, src, freq);
1738 wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant *wpa_s, const u8 *src,
1739 const u8 *hdr, const u8 *buf, size_t len,
1743 struct dpp_bootstrap_info *bi;
1744 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1747 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Response from " MACSTR,
1750 if (!pkex || !pkex->initiator || !pkex->exchange_done) {
1751 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1755 res = dpp_pkex_rx_commit_reveal_resp(pkex, hdr, buf, len);
1757 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
1761 bi = wpas_dpp_pkex_finish(wpa_s, src, freq);
1765 os_snprintf(cmd, sizeof(cmd), " peer=%u %s",
1767 wpa_s->dpp_pkex_auth_cmd ? wpa_s->dpp_pkex_auth_cmd : "");
1768 wpa_printf(MSG_DEBUG,
1769 "DPP: Start authentication after PKEX with parameters: %s",
1771 if (wpas_dpp_auth_init(wpa_s, cmd) < 0) {
1772 wpa_printf(MSG_DEBUG,
1773 "DPP: Authentication initialization failed");
1779 void wpas_dpp_rx_action(struct wpa_supplicant *wpa_s, const u8 *src,
1780 const u8 *buf, size_t len, unsigned int freq)
1783 enum dpp_public_action_frame_type type;
1785 unsigned int pkex_t;
1787 if (len < DPP_HDR_LEN)
1789 if (WPA_GET_BE24(buf) != OUI_WFA || buf[3] != DPP_OUI_TYPE)
1794 crypto_suite = *buf++;
1798 wpa_printf(MSG_DEBUG,
1799 "DPP: Received DPP Public Action frame crypto suite %u type %d from "
1801 crypto_suite, type, MAC2STR(src), freq);
1802 if (crypto_suite != 1) {
1803 wpa_printf(MSG_DEBUG, "DPP: Unsupported crypto suite %u",
1805 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
1806 " freq=%u type=%d ignore=unsupported-crypto-suite",
1807 MAC2STR(src), freq, type);
1810 wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len);
1811 if (dpp_check_attrs(buf, len) < 0) {
1812 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
1813 " freq=%u type=%d ignore=invalid-attributes",
1814 MAC2STR(src), freq, type);
1817 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR " freq=%u type=%d",
1818 MAC2STR(src), freq, type);
1821 case DPP_PA_AUTHENTICATION_REQ:
1822 wpas_dpp_rx_auth_req(wpa_s, src, hdr, buf, len, freq);
1824 case DPP_PA_AUTHENTICATION_RESP:
1825 wpas_dpp_rx_auth_resp(wpa_s, src, hdr, buf, len, freq);
1827 case DPP_PA_AUTHENTICATION_CONF:
1828 wpas_dpp_rx_auth_conf(wpa_s, src, hdr, buf, len);
1830 case DPP_PA_PEER_DISCOVERY_RESP:
1831 wpas_dpp_rx_peer_disc_resp(wpa_s, src, buf, len);
1833 case DPP_PA_PKEX_EXCHANGE_REQ:
1834 wpas_dpp_rx_pkex_exchange_req(wpa_s, src, buf, len, freq);
1836 case DPP_PA_PKEX_EXCHANGE_RESP:
1837 wpas_dpp_rx_pkex_exchange_resp(wpa_s, src, buf, len, freq);
1839 case DPP_PA_PKEX_COMMIT_REVEAL_REQ:
1840 wpas_dpp_rx_pkex_commit_reveal_req(wpa_s, src, hdr, buf, len,
1843 case DPP_PA_PKEX_COMMIT_REVEAL_RESP:
1844 wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s, src, hdr, buf, len,
1848 case DPP_PA_CONFIGURATION_RESULT:
1849 wpas_dpp_rx_conf_result(wpa_s, src, hdr, buf, len);
1851 #endif /* CONFIG_DPP2 */
1853 wpa_printf(MSG_DEBUG,
1854 "DPP: Ignored unsupported frame subtype %d", type);
1858 if (wpa_s->dpp_pkex)
1859 pkex_t = wpa_s->dpp_pkex->t;
1860 else if (wpa_s->dpp_pkex_bi)
1861 pkex_t = wpa_s->dpp_pkex_bi->pkex_t;
1864 if (pkex_t >= PKEX_COUNTER_T_LIMIT) {
1865 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_PKEX_T_LIMIT "id=0");
1866 wpas_dpp_pkex_remove(wpa_s, "*");
1871 static struct wpabuf *
1872 wpas_dpp_gas_req_handler(void *ctx, const u8 *sa, const u8 *query,
1875 struct wpa_supplicant *wpa_s = ctx;
1876 struct dpp_authentication *auth = wpa_s->dpp_auth;
1877 struct wpabuf *resp;
1879 wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR,
1881 if (!auth || !auth->auth_success ||
1882 os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) {
1883 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
1887 if (wpa_s->dpp_auth_ok_on_ack && auth->configurator) {
1888 wpa_printf(MSG_DEBUG,
1889 "DPP: Have not received ACK for Auth Confirm yet - assume it was received based on this GAS request");
1890 /* wpas_dpp_auth_success() would normally have been called from
1891 * TX status handler, but since there was no such handler call
1892 * yet, simply send out the event message and proceed with
1894 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=1");
1895 wpa_s->dpp_auth_ok_on_ack = 0;
1898 wpa_hexdump(MSG_DEBUG,
1899 "DPP: Received Configuration Request (GAS Query Request)",
1901 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_REQ_RX "src=" MACSTR,
1903 resp = dpp_conf_req_rx(auth, query, query_len);
1905 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1906 auth->conf_resp = resp;
1912 wpas_dpp_gas_status_handler(void *ctx, struct wpabuf *resp, int ok)
1914 struct wpa_supplicant *wpa_s = ctx;
1915 struct dpp_authentication *auth = wpa_s->dpp_auth;
1921 if (auth->conf_resp != resp) {
1922 wpa_printf(MSG_DEBUG,
1923 "DPP: Ignore GAS status report (ok=%d) for unknown response",
1929 wpa_printf(MSG_DEBUG, "DPP: Configuration exchange completed (ok=%d)",
1931 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
1932 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
1934 if (ok && auth->peer_version >= 2 &&
1935 auth->conf_resp_status == DPP_STATUS_OK) {
1936 wpa_printf(MSG_DEBUG, "DPP: Wait for Configuration Result");
1937 auth->waiting_conf_result = 1;
1938 auth->conf_resp = NULL;
1940 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout,
1942 eloop_register_timeout(2, 0,
1943 wpas_dpp_config_result_wait_timeout,
1947 #endif /* CONFIG_DPP2 */
1948 offchannel_send_action_done(wpa_s);
1949 wpas_dpp_listen_stop(wpa_s);
1951 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
1953 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1954 dpp_auth_deinit(wpa_s->dpp_auth);
1955 wpa_s->dpp_auth = NULL;
1960 int wpas_dpp_configurator_sign(struct wpa_supplicant *wpa_s, const char *cmd)
1962 struct dpp_authentication *auth;
1966 auth = os_zalloc(sizeof(*auth));
1970 curve = get_param(cmd, " curve=");
1971 wpas_dpp_set_testing_options(wpa_s, auth);
1972 if (dpp_set_configurator(wpa_s->dpp, wpa_s, auth, cmd) == 0 &&
1973 dpp_configurator_own_config(auth, curve, 0) == 0)
1974 ret = wpas_dpp_handle_config_obj(wpa_s, auth);
1976 dpp_auth_deinit(auth);
1984 wpas_dpp_tx_introduction_status(struct wpa_supplicant *wpa_s,
1985 unsigned int freq, const u8 *dst,
1986 const u8 *src, const u8 *bssid,
1987 const u8 *data, size_t data_len,
1988 enum offchannel_send_action_result result)
1990 const char *res_txt;
1992 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
1993 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
1995 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
1996 " result=%s (DPP Peer Discovery Request)",
1997 freq, MAC2STR(dst), res_txt);
1998 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
1999 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
2000 /* TODO: Time out wait for response more quickly in error cases? */
2004 int wpas_dpp_check_connect(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2005 struct wpa_bss *bss)
2009 unsigned int wait_time;
2011 struct wpa_ie_data ied;
2013 if (!(ssid->key_mgmt & WPA_KEY_MGMT_DPP) || !bss)
2014 return 0; /* Not using DPP AKM - continue */
2015 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2016 if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ied) == 0 &&
2017 !(ied.key_mgmt & WPA_KEY_MGMT_DPP))
2018 return 0; /* AP does not support DPP AKM - continue */
2019 if (wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid))
2020 return 0; /* PMKSA exists for DPP AKM - continue */
2022 if (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
2024 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
2026 !ssid->dpp_connector ? "Connector" :
2027 (!ssid->dpp_netaccesskey ? "netAccessKey" :
2034 if (ssid->dpp_netaccesskey_expiry &&
2035 (os_time_t) ssid->dpp_netaccesskey_expiry < now.sec) {
2036 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
2037 "netAccessKey expired");
2041 wpa_printf(MSG_DEBUG,
2042 "DPP: Starting network introduction protocol to derive PMKSA for "
2043 MACSTR, MAC2STR(bss->bssid));
2045 msg = dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ,
2046 5 + 4 + os_strlen(ssid->dpp_connector));
2050 #ifdef CONFIG_TESTING_OPTIONS
2051 if (dpp_test == DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ) {
2052 wpa_printf(MSG_INFO, "DPP: TESTING - no Transaction ID");
2055 if (dpp_test == DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ) {
2056 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Transaction ID");
2057 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
2058 wpabuf_put_le16(msg, 0);
2061 #endif /* CONFIG_TESTING_OPTIONS */
2063 /* Transaction ID */
2064 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
2065 wpabuf_put_le16(msg, 1);
2066 wpabuf_put_u8(msg, TRANSACTION_ID);
2068 #ifdef CONFIG_TESTING_OPTIONS
2070 if (dpp_test == DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ) {
2071 wpa_printf(MSG_INFO, "DPP: TESTING - no Connector");
2072 goto skip_connector;
2074 if (dpp_test == DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ) {
2077 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Connector");
2078 connector = dpp_corrupt_connector_signature(
2079 ssid->dpp_connector);
2084 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
2085 wpabuf_put_le16(msg, os_strlen(connector));
2086 wpabuf_put_str(msg, connector);
2088 goto skip_connector;
2090 #endif /* CONFIG_TESTING_OPTIONS */
2093 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
2094 wpabuf_put_le16(msg, os_strlen(ssid->dpp_connector));
2095 wpabuf_put_str(msg, ssid->dpp_connector);
2097 #ifdef CONFIG_TESTING_OPTIONS
2099 #endif /* CONFIG_TESTING_OPTIONS */
2101 /* TODO: Timeout on AP response */
2102 wait_time = wpa_s->max_remain_on_chan;
2103 if (wait_time > 2000)
2105 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2106 MAC2STR(bss->bssid), bss->freq, DPP_PA_PEER_DISCOVERY_REQ);
2107 offchannel_send_action(wpa_s, bss->freq, bss->bssid, wpa_s->own_addr,
2109 wpabuf_head(msg), wpabuf_len(msg),
2110 wait_time, wpas_dpp_tx_introduction_status, 0);
2113 /* Request this connection attempt to terminate - new one will be
2114 * started when network introduction protocol completes */
2115 os_memcpy(wpa_s->dpp_intro_bssid, bss->bssid, ETH_ALEN);
2116 wpa_s->dpp_intro_network = ssid;
2121 int wpas_dpp_pkex_add(struct wpa_supplicant *wpa_s, const char *cmd)
2123 struct dpp_bootstrap_info *own_bi;
2124 const char *pos, *end;
2125 unsigned int wait_time;
2127 pos = os_strstr(cmd, " own=");
2131 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
2133 wpa_printf(MSG_DEBUG,
2134 "DPP: Identified bootstrap info not found");
2137 if (own_bi->type != DPP_BOOTSTRAP_PKEX) {
2138 wpa_printf(MSG_DEBUG,
2139 "DPP: Identified bootstrap info not for PKEX");
2142 wpa_s->dpp_pkex_bi = own_bi;
2143 own_bi->pkex_t = 0; /* clear pending errors on new code */
2145 os_free(wpa_s->dpp_pkex_identifier);
2146 wpa_s->dpp_pkex_identifier = NULL;
2147 pos = os_strstr(cmd, " identifier=");
2150 end = os_strchr(pos, ' ');
2153 wpa_s->dpp_pkex_identifier = os_malloc(end - pos + 1);
2154 if (!wpa_s->dpp_pkex_identifier)
2156 os_memcpy(wpa_s->dpp_pkex_identifier, pos, end - pos);
2157 wpa_s->dpp_pkex_identifier[end - pos] = '\0';
2160 pos = os_strstr(cmd, " code=");
2163 os_free(wpa_s->dpp_pkex_code);
2164 wpa_s->dpp_pkex_code = os_strdup(pos + 6);
2165 if (!wpa_s->dpp_pkex_code)
2168 if (os_strstr(cmd, " init=1")) {
2169 struct dpp_pkex *pkex;
2172 wpa_printf(MSG_DEBUG, "DPP: Initiating PKEX");
2173 dpp_pkex_free(wpa_s->dpp_pkex);
2174 wpa_s->dpp_pkex = dpp_pkex_init(wpa_s, own_bi, wpa_s->own_addr,
2175 wpa_s->dpp_pkex_identifier,
2176 wpa_s->dpp_pkex_code);
2177 pkex = wpa_s->dpp_pkex;
2181 msg = pkex->exchange_req;
2182 wait_time = wpa_s->max_remain_on_chan;
2183 if (wait_time > 2000)
2186 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
2188 MAC2STR(broadcast), pkex->freq,
2189 DPP_PA_PKEX_EXCHANGE_REQ);
2190 offchannel_send_action(wpa_s, pkex->freq, broadcast,
2191 wpa_s->own_addr, broadcast,
2192 wpabuf_head(msg), wpabuf_len(msg),
2193 wait_time, wpas_dpp_tx_pkex_status, 0);
2196 pkex->exch_req_wait_time = wait_time;
2197 pkex->exch_req_tries = 1;
2200 /* TODO: Support multiple PKEX info entries */
2202 os_free(wpa_s->dpp_pkex_auth_cmd);
2203 wpa_s->dpp_pkex_auth_cmd = os_strdup(cmd);
2209 int wpas_dpp_pkex_remove(struct wpa_supplicant *wpa_s, const char *id)
2211 unsigned int id_val;
2213 if (os_strcmp(id, "*") == 0) {
2221 if ((id_val != 0 && id_val != 1) || !wpa_s->dpp_pkex_code)
2224 /* TODO: Support multiple PKEX entries */
2225 os_free(wpa_s->dpp_pkex_code);
2226 wpa_s->dpp_pkex_code = NULL;
2227 os_free(wpa_s->dpp_pkex_identifier);
2228 wpa_s->dpp_pkex_identifier = NULL;
2229 os_free(wpa_s->dpp_pkex_auth_cmd);
2230 wpa_s->dpp_pkex_auth_cmd = NULL;
2231 wpa_s->dpp_pkex_bi = NULL;
2232 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
2233 dpp_pkex_free(wpa_s->dpp_pkex);
2234 wpa_s->dpp_pkex = NULL;
2239 void wpas_dpp_stop(struct wpa_supplicant *wpa_s)
2241 dpp_auth_deinit(wpa_s->dpp_auth);
2242 wpa_s->dpp_auth = NULL;
2243 dpp_pkex_free(wpa_s->dpp_pkex);
2244 wpa_s->dpp_pkex = NULL;
2245 if (wpa_s->dpp_gas_client && wpa_s->dpp_gas_dialog_token >= 0)
2246 gas_query_stop(wpa_s->gas, wpa_s->dpp_gas_dialog_token);
2250 int wpas_dpp_init(struct wpa_supplicant *wpa_s)
2252 struct dpp_global_config config;
2255 adv_proto_id[0] = WLAN_EID_VENDOR_SPECIFIC;
2256 adv_proto_id[1] = 5;
2257 WPA_PUT_BE24(&adv_proto_id[2], OUI_WFA);
2258 adv_proto_id[5] = DPP_OUI_TYPE;
2259 adv_proto_id[6] = 0x01;
2261 if (gas_server_register(wpa_s->gas_server, adv_proto_id,
2262 sizeof(adv_proto_id), wpas_dpp_gas_req_handler,
2263 wpas_dpp_gas_status_handler, wpa_s) < 0)
2266 os_memset(&config, 0, sizeof(config));
2267 config.msg_ctx = wpa_s;
2268 config.cb_ctx = wpa_s;
2270 config.process_conf_obj = wpas_dpp_process_conf_obj;
2271 #endif /* CONFIG_DPP2 */
2272 wpa_s->dpp = dpp_global_init(&config);
2273 return wpa_s->dpp ? 0 : -1;
2277 void wpas_dpp_deinit(struct wpa_supplicant *wpa_s)
2279 #ifdef CONFIG_TESTING_OPTIONS
2280 os_free(wpa_s->dpp_config_obj_override);
2281 wpa_s->dpp_config_obj_override = NULL;
2282 os_free(wpa_s->dpp_discovery_override);
2283 wpa_s->dpp_discovery_override = NULL;
2284 os_free(wpa_s->dpp_groups_override);
2285 wpa_s->dpp_groups_override = NULL;
2286 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
2287 #endif /* CONFIG_TESTING_OPTIONS */
2290 dpp_global_clear(wpa_s->dpp);
2291 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
2292 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
2293 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
2294 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
2296 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL);
2297 dpp_pfs_free(wpa_s->dpp_pfs);
2298 wpa_s->dpp_pfs = NULL;
2299 #endif /* CONFIG_DPP2 */
2300 offchannel_send_action_done(wpa_s);
2301 wpas_dpp_listen_stop(wpa_s);
2302 wpas_dpp_stop(wpa_s);
2303 wpas_dpp_pkex_remove(wpa_s, "*");
2304 os_memset(wpa_s->dpp_intro_bssid, 0, ETH_ALEN);
2305 os_free(wpa_s->dpp_configurator_params);
2306 wpa_s->dpp_configurator_params = NULL;
2311 int wpas_dpp_controller_start(struct wpa_supplicant *wpa_s, const char *cmd)
2313 struct dpp_controller_config config;
2316 os_memset(&config, 0, sizeof(config));
2318 pos = os_strstr(cmd, " tcp_port=");
2321 config.tcp_port = atoi(pos);
2324 config.configurator_params = wpa_s->dpp_configurator_params;
2325 return dpp_controller_start(wpa_s->dpp, &config);
2327 #endif /* CONFIG_DPP2 */