]> git.ipfire.org Git - thirdparty/hostap.git/blob - wpa_supplicant/dpp_supplicant.c
DPP: Add bandSupport JSON array into config request
[thirdparty/hostap.git] / wpa_supplicant / dpp_supplicant.c
1 /*
2 * wpa_supplicant - DPP
3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
4 * Copyright (c) 2018-2019, The Linux Foundation
5 *
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
8 */
9
10 #include "utils/includes.h"
11
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"
21 #include "config.h"
22 #include "driver_i.h"
23 #include "offchannel.h"
24 #include "gas_query.h"
25 #include "bss.h"
26 #include "scan.h"
27 #include "notify.h"
28 #include "dpp_supplicant.h"
29
30
31 static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
32 unsigned int freq);
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);
42 static void
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);
48
49 static const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
50
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;
54
55
56 /**
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
61 */
62 int wpas_dpp_qr_code(struct wpa_supplicant *wpa_s, const char *cmd)
63 {
64 struct dpp_bootstrap_info *bi;
65 struct dpp_authentication *auth = wpa_s->dpp_auth;
66
67 bi = dpp_add_qr_code(wpa_s->dpp, cmd);
68 if (!bi)
69 return -1;
70
71 if (auth && auth->response_pending &&
72 dpp_notify_new_qr_code(auth, bi) == 1) {
73 wpa_printf(MSG_DEBUG,
74 "DPP: Sending out pending authentication response");
75 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
76 " freq=%u type=%d",
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,
81 broadcast,
82 wpabuf_head(auth->resp_msg),
83 wpabuf_len(auth->resp_msg),
84 500, wpas_dpp_tx_status, 0);
85 }
86
87 return bi->id;
88 }
89
90
91 static void wpas_dpp_auth_resp_retry_timeout(void *eloop_ctx, void *timeout_ctx)
92 {
93 struct wpa_supplicant *wpa_s = eloop_ctx;
94 struct dpp_authentication *auth = wpa_s->dpp_auth;
95
96 if (!auth || !auth->resp_msg)
97 return;
98
99 wpa_printf(MSG_DEBUG,
100 "DPP: Retry Authentication Response after timeout");
101 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
102 " freq=%u type=%d",
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);
110 }
111
112
113 static void wpas_dpp_auth_resp_retry(struct wpa_supplicant *wpa_s)
114 {
115 struct dpp_authentication *auth = wpa_s->dpp_auth;
116 unsigned int wait_time, max_tries;
117
118 if (!auth || !auth->resp_msg)
119 return;
120
121 if (wpa_s->dpp_resp_max_tries)
122 max_tries = wpa_s->dpp_resp_max_tries;
123 else
124 max_tries = 5;
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;
131 return;
132 }
133
134 if (wpa_s->dpp_resp_retry_time)
135 wait_time = wpa_s->dpp_resp_retry_time;
136 else
137 wait_time = 1000;
138 wpa_printf(MSG_DEBUG,
139 "DPP: Schedule retransmission of Authentication Response frame in %u ms",
140 wait_time);
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);
145 }
146
147
148 static void wpas_dpp_try_to_connect(struct wpa_supplicant *wpa_s)
149 {
150 wpa_printf(MSG_DEBUG, "DPP: Trying to connect to the new network");
151 wpa_s->suitable_network = 0;
152 wpa_s->no_suitable_network = 0;
153 wpa_s->disconnected = 0;
154 wpa_s->reassociate = 1;
155 wpa_s->scan_runs = 0;
156 wpa_s->normal_scans = 0;
157 wpa_supplicant_cancel_sched_scan(wpa_s);
158 wpa_supplicant_req_scan(wpa_s, 0, 0);
159 }
160
161
162 #ifdef CONFIG_DPP2
163
164 static void wpas_dpp_conn_status_result_timeout(void *eloop_ctx,
165 void *timeout_ctx)
166 {
167 struct wpa_supplicant *wpa_s = eloop_ctx;
168 struct dpp_authentication *auth = wpa_s->dpp_auth;
169 enum dpp_status_error result;
170
171 if (!auth || !auth->conn_status_requested)
172 return;
173
174 wpa_printf(MSG_DEBUG,
175 "DPP: Connection timeout - report Connection Status Result");
176 if (wpa_s->suitable_network)
177 result = DPP_STATUS_AUTH_FAILURE;
178 else if (wpa_s->no_suitable_network)
179 result = DPP_STATUS_NO_AP;
180 else
181 result = 255; /* What to report here for unexpected state? */
182 wpas_dpp_send_conn_status_result(wpa_s, result);
183 }
184
185
186 static char * wpas_dpp_scan_channel_list(struct wpa_supplicant *wpa_s)
187 {
188 char *str, *end, *pos;
189 size_t len;
190 unsigned int i;
191 u8 last_op_class = 0;
192 int res;
193
194 if (!wpa_s->last_scan_freqs || !wpa_s->num_last_scan_freqs)
195 return NULL;
196
197 len = wpa_s->num_last_scan_freqs * 8;
198 str = os_zalloc(len);
199 if (!str)
200 return NULL;
201 end = str + len;
202 pos = str;
203
204 for (i = 0; i < wpa_s->num_last_scan_freqs; i++) {
205 enum hostapd_hw_mode mode;
206 u8 op_class, channel;
207
208 mode = ieee80211_freq_to_channel_ext(wpa_s->last_scan_freqs[i],
209 0, 0, &op_class, &channel);
210 if (mode == NUM_HOSTAPD_MODES)
211 continue;
212 if (op_class == last_op_class)
213 res = os_snprintf(pos, end - pos, ",%d", channel);
214 else
215 res = os_snprintf(pos, end - pos, "%s%d/%d",
216 pos == str ? "" : ",",
217 op_class, channel);
218 if (os_snprintf_error(end - pos, res)) {
219 *pos = '\0';
220 break;
221 }
222 pos += res;
223 last_op_class = op_class;
224 }
225
226 if (pos == str) {
227 os_free(str);
228 str = NULL;
229 }
230 return str;
231 }
232
233
234 void wpas_dpp_send_conn_status_result(struct wpa_supplicant *wpa_s,
235 enum dpp_status_error result)
236 {
237 struct wpabuf *msg;
238 const char *channel_list = NULL;
239 char *channel_list_buf = NULL;
240 struct wpa_ssid *ssid = wpa_s->current_ssid;
241 struct dpp_authentication *auth = wpa_s->dpp_auth;
242
243 eloop_cancel_timeout(wpas_dpp_conn_status_result_timeout, wpa_s, NULL);
244
245 if (!auth || !auth->conn_status_requested)
246 return;
247 auth->conn_status_requested = 0;
248 wpa_printf(MSG_DEBUG, "DPP: Report connection status result %d",
249 result);
250
251 if (result == DPP_STATUS_NO_AP) {
252 channel_list_buf = wpas_dpp_scan_channel_list(wpa_s);
253 channel_list = channel_list_buf;
254 }
255
256 msg = dpp_build_conn_status_result(auth, result,
257 ssid ? ssid->ssid :
258 wpa_s->dpp_last_ssid,
259 ssid ? ssid->ssid_len :
260 wpa_s->dpp_last_ssid_len,
261 channel_list);
262 os_free(channel_list_buf);
263 if (!msg) {
264 dpp_auth_deinit(wpa_s->dpp_auth);
265 wpa_s->dpp_auth = NULL;
266 return;
267 }
268
269 wpa_msg(wpa_s, MSG_INFO,
270 DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
271 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
272 DPP_PA_CONNECTION_STATUS_RESULT);
273 offchannel_send_action(wpa_s, auth->curr_freq,
274 auth->peer_mac_addr, wpa_s->own_addr, broadcast,
275 wpabuf_head(msg), wpabuf_len(msg),
276 500, wpas_dpp_tx_status, 0);
277 wpabuf_free(msg);
278
279 /* This exchange will be terminated in the TX status handler */
280 auth->remove_on_tx_status = 1;
281
282 return;
283 }
284
285
286 void wpas_dpp_connected(struct wpa_supplicant *wpa_s)
287 {
288 struct dpp_authentication *auth = wpa_s->dpp_auth;
289
290 if (auth && auth->conn_status_requested)
291 wpas_dpp_send_conn_status_result(wpa_s, DPP_STATUS_OK);
292 }
293
294 #endif /* CONFIG_DPP2 */
295
296
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)
302 {
303 const char *res_txt;
304 struct dpp_authentication *auth = wpa_s->dpp_auth;
305
306 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
307 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
308 "FAILED");
309 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
310 " result=%s", freq, MAC2STR(dst), res_txt);
311 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
312 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
313
314 if (!wpa_s->dpp_auth) {
315 wpa_printf(MSG_DEBUG,
316 "DPP: Ignore TX status since there is no ongoing authentication exchange");
317 return;
318 }
319
320 #ifdef CONFIG_DPP2
321 if (auth->connect_on_tx_status) {
322 auth->connect_on_tx_status = 0;
323 wpa_printf(MSG_DEBUG,
324 "DPP: Try to connect after completed configuration result");
325 wpas_dpp_try_to_connect(wpa_s);
326 if (auth->conn_status_requested) {
327 wpa_printf(MSG_DEBUG,
328 "DPP: Start 15 second timeout for reporting connection status result");
329 eloop_cancel_timeout(
330 wpas_dpp_conn_status_result_timeout,
331 wpa_s, NULL);
332 eloop_register_timeout(
333 15, 0, wpas_dpp_conn_status_result_timeout,
334 wpa_s, NULL);
335 } else {
336 dpp_auth_deinit(wpa_s->dpp_auth);
337 wpa_s->dpp_auth = NULL;
338 }
339 return;
340 }
341 #endif /* CONFIG_DPP2 */
342
343 if (wpa_s->dpp_auth->remove_on_tx_status) {
344 wpa_printf(MSG_DEBUG,
345 "DPP: Terminate authentication exchange due to a request to do so on TX status");
346 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
347 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
348 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
349 NULL);
350 offchannel_send_action_done(wpa_s);
351 dpp_auth_deinit(wpa_s->dpp_auth);
352 wpa_s->dpp_auth = NULL;
353 return;
354 }
355
356 if (wpa_s->dpp_auth_ok_on_ack)
357 wpas_dpp_auth_success(wpa_s, 1);
358
359 if (!is_broadcast_ether_addr(dst) &&
360 result != OFFCHANNEL_SEND_ACTION_SUCCESS) {
361 wpa_printf(MSG_DEBUG,
362 "DPP: Unicast DPP Action frame was not ACKed");
363 if (auth->waiting_auth_resp) {
364 /* In case of DPP Authentication Request frame, move to
365 * the next channel immediately. */
366 offchannel_send_action_done(wpa_s);
367 wpas_dpp_auth_init_next(wpa_s);
368 return;
369 }
370 if (auth->waiting_auth_conf) {
371 wpas_dpp_auth_resp_retry(wpa_s);
372 return;
373 }
374 }
375
376 if (!is_broadcast_ether_addr(dst) && auth->waiting_auth_resp &&
377 result == OFFCHANNEL_SEND_ACTION_SUCCESS) {
378 /* Allow timeout handling to stop iteration if no response is
379 * received from a peer that has ACKed a request. */
380 auth->auth_req_ack = 1;
381 }
382
383 if (!wpa_s->dpp_auth_ok_on_ack && wpa_s->dpp_auth->neg_freq > 0 &&
384 wpa_s->dpp_auth->curr_freq != wpa_s->dpp_auth->neg_freq) {
385 wpa_printf(MSG_DEBUG,
386 "DPP: Move from curr_freq %u MHz to neg_freq %u MHz for response",
387 wpa_s->dpp_auth->curr_freq,
388 wpa_s->dpp_auth->neg_freq);
389 offchannel_send_action_done(wpa_s);
390 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->neg_freq);
391 }
392
393 if (wpa_s->dpp_auth_ok_on_ack)
394 wpa_s->dpp_auth_ok_on_ack = 0;
395 }
396
397
398 static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx)
399 {
400 struct wpa_supplicant *wpa_s = eloop_ctx;
401 struct dpp_authentication *auth = wpa_s->dpp_auth;
402 unsigned int freq;
403 struct os_reltime now, diff;
404 unsigned int wait_time, diff_ms;
405
406 if (!auth || !auth->waiting_auth_resp)
407 return;
408
409 wait_time = wpa_s->dpp_resp_wait_time ?
410 wpa_s->dpp_resp_wait_time : 2000;
411 os_get_reltime(&now);
412 os_reltime_sub(&now, &wpa_s->dpp_last_init, &diff);
413 diff_ms = diff.sec * 1000 + diff.usec / 1000;
414 wpa_printf(MSG_DEBUG,
415 "DPP: Reply wait timeout - wait_time=%u diff_ms=%u",
416 wait_time, diff_ms);
417
418 if (auth->auth_req_ack && diff_ms >= wait_time) {
419 /* Peer ACK'ed Authentication Request frame, but did not reply
420 * with Authentication Response frame within two seconds. */
421 wpa_printf(MSG_INFO,
422 "DPP: No response received from responder - stopping initiation attempt");
423 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
424 offchannel_send_action_done(wpa_s);
425 wpas_dpp_listen_stop(wpa_s);
426 dpp_auth_deinit(auth);
427 wpa_s->dpp_auth = NULL;
428 return;
429 }
430
431 if (diff_ms >= wait_time) {
432 /* Authentication Request frame was not ACK'ed and no reply
433 * was receiving within two seconds. */
434 wpa_printf(MSG_DEBUG,
435 "DPP: Continue Initiator channel iteration");
436 offchannel_send_action_done(wpa_s);
437 wpas_dpp_listen_stop(wpa_s);
438 wpas_dpp_auth_init_next(wpa_s);
439 return;
440 }
441
442 /* Driver did not support 2000 ms long wait_time with TX command, so
443 * schedule listen operation to continue waiting for the response.
444 *
445 * DPP listen operations continue until stopped, so simply schedule a
446 * new call to this function at the point when the two second reply
447 * wait has expired. */
448 wait_time -= diff_ms;
449
450 freq = auth->curr_freq;
451 if (auth->neg_freq > 0)
452 freq = auth->neg_freq;
453 wpa_printf(MSG_DEBUG,
454 "DPP: Continue reply wait on channel %u MHz for %u ms",
455 freq, wait_time);
456 wpa_s->dpp_in_response_listen = 1;
457 wpas_dpp_listen_start(wpa_s, freq);
458
459 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
460 wpas_dpp_reply_wait_timeout, wpa_s, NULL);
461 }
462
463
464 static void wpas_dpp_set_testing_options(struct wpa_supplicant *wpa_s,
465 struct dpp_authentication *auth)
466 {
467 #ifdef CONFIG_TESTING_OPTIONS
468 if (wpa_s->dpp_config_obj_override)
469 auth->config_obj_override =
470 os_strdup(wpa_s->dpp_config_obj_override);
471 if (wpa_s->dpp_discovery_override)
472 auth->discovery_override =
473 os_strdup(wpa_s->dpp_discovery_override);
474 if (wpa_s->dpp_groups_override)
475 auth->groups_override =
476 os_strdup(wpa_s->dpp_groups_override);
477 auth->ignore_netaccesskey_mismatch =
478 wpa_s->dpp_ignore_netaccesskey_mismatch;
479 #endif /* CONFIG_TESTING_OPTIONS */
480 }
481
482
483 static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx)
484 {
485 struct wpa_supplicant *wpa_s = eloop_ctx;
486
487 if (!wpa_s->dpp_auth)
488 return;
489 wpa_printf(MSG_DEBUG, "DPP: Retry initiation after timeout");
490 wpas_dpp_auth_init_next(wpa_s);
491 }
492
493
494 static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s)
495 {
496 struct dpp_authentication *auth = wpa_s->dpp_auth;
497 const u8 *dst;
498 unsigned int wait_time, max_wait_time, freq, max_tries, used;
499 struct os_reltime now, diff;
500
501 wpa_s->dpp_in_response_listen = 0;
502 if (!auth)
503 return -1;
504
505 if (auth->freq_idx == 0)
506 os_get_reltime(&wpa_s->dpp_init_iter_start);
507
508 if (auth->freq_idx >= auth->num_freq) {
509 auth->num_freq_iters++;
510 if (wpa_s->dpp_init_max_tries)
511 max_tries = wpa_s->dpp_init_max_tries;
512 else
513 max_tries = 5;
514 if (auth->num_freq_iters >= max_tries || auth->auth_req_ack) {
515 wpa_printf(MSG_INFO,
516 "DPP: No response received from responder - stopping initiation attempt");
517 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
518 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout,
519 wpa_s, NULL);
520 offchannel_send_action_done(wpa_s);
521 dpp_auth_deinit(wpa_s->dpp_auth);
522 wpa_s->dpp_auth = NULL;
523 return -1;
524 }
525 auth->freq_idx = 0;
526 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
527 if (wpa_s->dpp_init_retry_time)
528 wait_time = wpa_s->dpp_init_retry_time;
529 else
530 wait_time = 10000;
531 os_get_reltime(&now);
532 os_reltime_sub(&now, &wpa_s->dpp_init_iter_start, &diff);
533 used = diff.sec * 1000 + diff.usec / 1000;
534 if (used > wait_time)
535 wait_time = 0;
536 else
537 wait_time -= used;
538 wpa_printf(MSG_DEBUG, "DPP: Next init attempt in %u ms",
539 wait_time);
540 eloop_register_timeout(wait_time / 1000,
541 (wait_time % 1000) * 1000,
542 wpas_dpp_init_timeout, wpa_s,
543 NULL);
544 return 0;
545 }
546 freq = auth->freq[auth->freq_idx++];
547 auth->curr_freq = freq;
548
549 if (is_zero_ether_addr(auth->peer_bi->mac_addr))
550 dst = broadcast;
551 else
552 dst = auth->peer_bi->mac_addr;
553 wpa_s->dpp_auth_ok_on_ack = 0;
554 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
555 wait_time = wpa_s->max_remain_on_chan;
556 max_wait_time = wpa_s->dpp_resp_wait_time ?
557 wpa_s->dpp_resp_wait_time : 2000;
558 if (wait_time > max_wait_time)
559 wait_time = max_wait_time;
560 wait_time += 10; /* give the driver some extra time to complete */
561 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
562 wpas_dpp_reply_wait_timeout,
563 wpa_s, NULL);
564 wait_time -= 10;
565 if (auth->neg_freq > 0 && freq != auth->neg_freq) {
566 wpa_printf(MSG_DEBUG,
567 "DPP: Initiate on %u MHz and move to neg_freq %u MHz for response",
568 freq, auth->neg_freq);
569 }
570 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
571 MAC2STR(dst), freq, DPP_PA_AUTHENTICATION_REQ);
572 auth->auth_req_ack = 0;
573 os_get_reltime(&wpa_s->dpp_last_init);
574 return offchannel_send_action(wpa_s, freq, dst,
575 wpa_s->own_addr, broadcast,
576 wpabuf_head(auth->req_msg),
577 wpabuf_len(auth->req_msg),
578 wait_time, wpas_dpp_tx_status, 0);
579 }
580
581
582 int wpas_dpp_auth_init(struct wpa_supplicant *wpa_s, const char *cmd)
583 {
584 const char *pos;
585 struct dpp_bootstrap_info *peer_bi, *own_bi = NULL;
586 struct dpp_authentication *auth;
587 u8 allowed_roles = DPP_CAPAB_CONFIGURATOR;
588 unsigned int neg_freq = 0;
589 int tcp = 0;
590 #ifdef CONFIG_DPP2
591 int tcp_port = DPP_TCP_PORT;
592 struct hostapd_ip_addr ipaddr;
593 char *addr;
594 #endif /* CONFIG_DPP2 */
595
596 wpa_s->dpp_gas_client = 0;
597
598 pos = os_strstr(cmd, " peer=");
599 if (!pos)
600 return -1;
601 pos += 6;
602 peer_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
603 if (!peer_bi) {
604 wpa_printf(MSG_INFO,
605 "DPP: Could not find bootstrapping info for the identified peer");
606 return -1;
607 }
608
609 #ifdef CONFIG_DPP2
610 pos = os_strstr(cmd, " tcp_port=");
611 if (pos) {
612 pos += 10;
613 tcp_port = atoi(pos);
614 }
615
616 addr = get_param(cmd, " tcp_addr=");
617 if (addr) {
618 int res;
619
620 res = hostapd_parse_ip_addr(addr, &ipaddr);
621 os_free(addr);
622 if (res)
623 return -1;
624 tcp = 1;
625 }
626 #endif /* CONFIG_DPP2 */
627
628 pos = os_strstr(cmd, " own=");
629 if (pos) {
630 pos += 5;
631 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
632 if (!own_bi) {
633 wpa_printf(MSG_INFO,
634 "DPP: Could not find bootstrapping info for the identified local entry");
635 return -1;
636 }
637
638 if (peer_bi->curve != own_bi->curve) {
639 wpa_printf(MSG_INFO,
640 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
641 peer_bi->curve->name, own_bi->curve->name);
642 return -1;
643 }
644 }
645
646 pos = os_strstr(cmd, " role=");
647 if (pos) {
648 pos += 6;
649 if (os_strncmp(pos, "configurator", 12) == 0)
650 allowed_roles = DPP_CAPAB_CONFIGURATOR;
651 else if (os_strncmp(pos, "enrollee", 8) == 0)
652 allowed_roles = DPP_CAPAB_ENROLLEE;
653 else if (os_strncmp(pos, "either", 6) == 0)
654 allowed_roles = DPP_CAPAB_CONFIGURATOR |
655 DPP_CAPAB_ENROLLEE;
656 else
657 goto fail;
658 }
659
660 pos = os_strstr(cmd, " netrole=");
661 if (pos) {
662 pos += 9;
663 wpa_s->dpp_netrole_ap = os_strncmp(pos, "ap", 2) == 0;
664 }
665
666 pos = os_strstr(cmd, " neg_freq=");
667 if (pos)
668 neg_freq = atoi(pos + 10);
669
670 if (!tcp && wpa_s->dpp_auth) {
671 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
672 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
673 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
674 NULL);
675 offchannel_send_action_done(wpa_s);
676 dpp_auth_deinit(wpa_s->dpp_auth);
677 wpa_s->dpp_auth = NULL;
678 }
679
680 auth = dpp_auth_init(wpa_s, peer_bi, own_bi, allowed_roles, neg_freq,
681 wpa_s->hw.modes, wpa_s->hw.num_modes);
682 if (!auth)
683 goto fail;
684 wpas_dpp_set_testing_options(wpa_s, auth);
685 if (dpp_set_configurator(wpa_s->dpp, wpa_s, auth, cmd) < 0) {
686 dpp_auth_deinit(auth);
687 goto fail;
688 }
689
690 auth->neg_freq = neg_freq;
691
692 if (!is_zero_ether_addr(peer_bi->mac_addr))
693 os_memcpy(auth->peer_mac_addr, peer_bi->mac_addr, ETH_ALEN);
694
695 #ifdef CONFIG_DPP2
696 if (tcp)
697 return dpp_tcp_init(wpa_s->dpp, auth, &ipaddr, tcp_port);
698 #endif /* CONFIG_DPP2 */
699
700 wpa_s->dpp_auth = auth;
701 return wpas_dpp_auth_init_next(wpa_s);
702 fail:
703 return -1;
704 }
705
706
707 struct wpas_dpp_listen_work {
708 unsigned int freq;
709 unsigned int duration;
710 struct wpabuf *probe_resp_ie;
711 };
712
713
714 static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work *lwork)
715 {
716 if (!lwork)
717 return;
718 os_free(lwork);
719 }
720
721
722 static void wpas_dpp_listen_work_done(struct wpa_supplicant *wpa_s)
723 {
724 struct wpas_dpp_listen_work *lwork;
725
726 if (!wpa_s->dpp_listen_work)
727 return;
728
729 lwork = wpa_s->dpp_listen_work->ctx;
730 wpas_dpp_listen_work_free(lwork);
731 radio_work_done(wpa_s->dpp_listen_work);
732 wpa_s->dpp_listen_work = NULL;
733 }
734
735
736 static void dpp_start_listen_cb(struct wpa_radio_work *work, int deinit)
737 {
738 struct wpa_supplicant *wpa_s = work->wpa_s;
739 struct wpas_dpp_listen_work *lwork = work->ctx;
740
741 if (deinit) {
742 if (work->started) {
743 wpa_s->dpp_listen_work = NULL;
744 wpas_dpp_listen_stop(wpa_s);
745 }
746 wpas_dpp_listen_work_free(lwork);
747 return;
748 }
749
750 wpa_s->dpp_listen_work = work;
751
752 wpa_s->dpp_pending_listen_freq = lwork->freq;
753
754 if (wpa_drv_remain_on_channel(wpa_s, lwork->freq,
755 wpa_s->max_remain_on_chan) < 0) {
756 wpa_printf(MSG_DEBUG,
757 "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
758 lwork->freq);
759 wpa_s->dpp_listen_freq = 0;
760 wpas_dpp_listen_work_done(wpa_s);
761 wpa_s->dpp_pending_listen_freq = 0;
762 return;
763 }
764 wpa_s->off_channel_freq = 0;
765 wpa_s->roc_waiting_drv_freq = lwork->freq;
766 }
767
768
769 static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
770 unsigned int freq)
771 {
772 struct wpas_dpp_listen_work *lwork;
773
774 if (wpa_s->dpp_listen_work) {
775 wpa_printf(MSG_DEBUG,
776 "DPP: Reject start_listen since dpp_listen_work already exists");
777 return -1;
778 }
779
780 if (wpa_s->dpp_listen_freq)
781 wpas_dpp_listen_stop(wpa_s);
782 wpa_s->dpp_listen_freq = freq;
783
784 lwork = os_zalloc(sizeof(*lwork));
785 if (!lwork)
786 return -1;
787 lwork->freq = freq;
788
789 if (radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb,
790 lwork) < 0) {
791 wpas_dpp_listen_work_free(lwork);
792 return -1;
793 }
794
795 return 0;
796 }
797
798
799 int wpas_dpp_listen(struct wpa_supplicant *wpa_s, const char *cmd)
800 {
801 int freq;
802
803 freq = atoi(cmd);
804 if (freq <= 0)
805 return -1;
806
807 if (os_strstr(cmd, " role=configurator"))
808 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR;
809 else if (os_strstr(cmd, " role=enrollee"))
810 wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
811 else
812 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
813 DPP_CAPAB_ENROLLEE;
814 wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
815 wpa_s->dpp_netrole_ap = os_strstr(cmd, " netrole=ap") != NULL;
816 if (wpa_s->dpp_listen_freq == (unsigned int) freq) {
817 wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz",
818 freq);
819 return 0;
820 }
821
822 return wpas_dpp_listen_start(wpa_s, freq);
823 }
824
825
826 void wpas_dpp_listen_stop(struct wpa_supplicant *wpa_s)
827 {
828 wpa_s->dpp_in_response_listen = 0;
829 if (!wpa_s->dpp_listen_freq)
830 return;
831
832 wpa_printf(MSG_DEBUG, "DPP: Stop listen on %u MHz",
833 wpa_s->dpp_listen_freq);
834 wpa_drv_cancel_remain_on_channel(wpa_s);
835 wpa_s->dpp_listen_freq = 0;
836 wpas_dpp_listen_work_done(wpa_s);
837 }
838
839
840 void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
841 unsigned int freq)
842 {
843 wpas_dpp_listen_work_done(wpa_s);
844
845 if (wpa_s->dpp_auth && wpa_s->dpp_in_response_listen) {
846 unsigned int new_freq;
847
848 /* Continue listen with a new remain-on-channel */
849 if (wpa_s->dpp_auth->neg_freq > 0)
850 new_freq = wpa_s->dpp_auth->neg_freq;
851 else
852 new_freq = wpa_s->dpp_auth->curr_freq;
853 wpa_printf(MSG_DEBUG,
854 "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
855 new_freq);
856 wpas_dpp_listen_start(wpa_s, new_freq);
857 return;
858 }
859
860 if (wpa_s->dpp_listen_freq) {
861 /* Continue listen with a new remain-on-channel */
862 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_listen_freq);
863 }
864 }
865
866
867 static void wpas_dpp_rx_auth_req(struct wpa_supplicant *wpa_s, const u8 *src,
868 const u8 *hdr, const u8 *buf, size_t len,
869 unsigned int freq)
870 {
871 const u8 *r_bootstrap, *i_bootstrap;
872 u16 r_bootstrap_len, i_bootstrap_len;
873 struct dpp_bootstrap_info *own_bi = NULL, *peer_bi = NULL;
874
875 if (!wpa_s->dpp)
876 return;
877
878 wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR,
879 MAC2STR(src));
880
881 r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
882 &r_bootstrap_len);
883 if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
884 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
885 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
886 return;
887 }
888 wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
889 r_bootstrap, r_bootstrap_len);
890
891 i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH,
892 &i_bootstrap_len);
893 if (!i_bootstrap || i_bootstrap_len != SHA256_MAC_LEN) {
894 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
895 "Missing or invalid required Initiator Bootstrapping Key Hash attribute");
896 return;
897 }
898 wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash",
899 i_bootstrap, i_bootstrap_len);
900
901 /* Try to find own and peer bootstrapping key matches based on the
902 * received hash values */
903 dpp_bootstrap_find_pair(wpa_s->dpp, i_bootstrap, r_bootstrap,
904 &own_bi, &peer_bi);
905 if (!own_bi) {
906 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
907 "No matching own bootstrapping key found - ignore message");
908 return;
909 }
910
911 if (wpa_s->dpp_auth) {
912 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
913 "Already in DPP authentication exchange - ignore new one");
914 return;
915 }
916
917 wpa_s->dpp_gas_client = 0;
918 wpa_s->dpp_auth_ok_on_ack = 0;
919 wpa_s->dpp_auth = dpp_auth_req_rx(wpa_s, wpa_s->dpp_allowed_roles,
920 wpa_s->dpp_qr_mutual,
921 peer_bi, own_bi, freq, hdr, buf, len);
922 if (!wpa_s->dpp_auth) {
923 wpa_printf(MSG_DEBUG, "DPP: No response generated");
924 return;
925 }
926 wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
927 if (dpp_set_configurator(wpa_s->dpp, wpa_s, wpa_s->dpp_auth,
928 wpa_s->dpp_configurator_params) < 0) {
929 dpp_auth_deinit(wpa_s->dpp_auth);
930 wpa_s->dpp_auth = NULL;
931 return;
932 }
933 os_memcpy(wpa_s->dpp_auth->peer_mac_addr, src, ETH_ALEN);
934
935 if (wpa_s->dpp_listen_freq &&
936 wpa_s->dpp_listen_freq != wpa_s->dpp_auth->curr_freq) {
937 wpa_printf(MSG_DEBUG,
938 "DPP: Stop listen on %u MHz to allow response on the request %u MHz",
939 wpa_s->dpp_listen_freq, wpa_s->dpp_auth->curr_freq);
940 wpas_dpp_listen_stop(wpa_s);
941 }
942
943 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
944 MAC2STR(src), wpa_s->dpp_auth->curr_freq,
945 DPP_PA_AUTHENTICATION_RESP);
946 offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq,
947 src, wpa_s->own_addr, broadcast,
948 wpabuf_head(wpa_s->dpp_auth->resp_msg),
949 wpabuf_len(wpa_s->dpp_auth->resp_msg),
950 500, wpas_dpp_tx_status, 0);
951 }
952
953
954 static void wpas_dpp_start_gas_server(struct wpa_supplicant *wpa_s)
955 {
956 /* TODO: stop wait and start ROC */
957 }
958
959
960 static struct wpa_ssid * wpas_dpp_add_network(struct wpa_supplicant *wpa_s,
961 struct dpp_authentication *auth)
962 {
963 struct wpa_ssid *ssid;
964
965 #ifdef CONFIG_DPP2
966 if (auth->akm == DPP_AKM_SAE) {
967 #ifdef CONFIG_SAE
968 struct wpa_driver_capa capa;
969 int res;
970
971 res = wpa_drv_get_capa(wpa_s, &capa);
972 if (res == 0 &&
973 !(capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) &&
974 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
975 wpa_printf(MSG_DEBUG,
976 "DPP: SAE not supported by the driver");
977 return NULL;
978 }
979 #else /* CONFIG_SAE */
980 wpa_printf(MSG_DEBUG, "DPP: SAE not supported in the build");
981 return NULL;
982 #endif /* CONFIG_SAE */
983 }
984 #endif /* CONFIG_DPP2 */
985
986 ssid = wpa_config_add_network(wpa_s->conf);
987 if (!ssid)
988 return NULL;
989 wpas_notify_network_added(wpa_s, ssid);
990 wpa_config_set_network_defaults(ssid);
991 ssid->disabled = 1;
992
993 ssid->ssid = os_malloc(auth->ssid_len);
994 if (!ssid->ssid)
995 goto fail;
996 os_memcpy(ssid->ssid, auth->ssid, auth->ssid_len);
997 ssid->ssid_len = auth->ssid_len;
998
999 if (auth->connector) {
1000 ssid->key_mgmt = WPA_KEY_MGMT_DPP;
1001 ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED;
1002 ssid->dpp_connector = os_strdup(auth->connector);
1003 if (!ssid->dpp_connector)
1004 goto fail;
1005 }
1006
1007 if (auth->c_sign_key) {
1008 ssid->dpp_csign = os_malloc(wpabuf_len(auth->c_sign_key));
1009 if (!ssid->dpp_csign)
1010 goto fail;
1011 os_memcpy(ssid->dpp_csign, wpabuf_head(auth->c_sign_key),
1012 wpabuf_len(auth->c_sign_key));
1013 ssid->dpp_csign_len = wpabuf_len(auth->c_sign_key);
1014 }
1015
1016 if (auth->net_access_key) {
1017 ssid->dpp_netaccesskey =
1018 os_malloc(wpabuf_len(auth->net_access_key));
1019 if (!ssid->dpp_netaccesskey)
1020 goto fail;
1021 os_memcpy(ssid->dpp_netaccesskey,
1022 wpabuf_head(auth->net_access_key),
1023 wpabuf_len(auth->net_access_key));
1024 ssid->dpp_netaccesskey_len = wpabuf_len(auth->net_access_key);
1025 ssid->dpp_netaccesskey_expiry = auth->net_access_key_expiry;
1026 }
1027
1028 if (!auth->connector || dpp_akm_psk(auth->akm) ||
1029 dpp_akm_sae(auth->akm)) {
1030 if (!auth->connector)
1031 ssid->key_mgmt = 0;
1032 if (dpp_akm_psk(auth->akm))
1033 ssid->key_mgmt |= WPA_KEY_MGMT_PSK |
1034 WPA_KEY_MGMT_PSK_SHA256 | WPA_KEY_MGMT_FT_PSK;
1035 if (dpp_akm_sae(auth->akm))
1036 ssid->key_mgmt |= WPA_KEY_MGMT_SAE |
1037 WPA_KEY_MGMT_FT_SAE;
1038 ssid->ieee80211w = MGMT_FRAME_PROTECTION_OPTIONAL;
1039 if (auth->passphrase[0]) {
1040 if (wpa_config_set_quoted(ssid, "psk",
1041 auth->passphrase) < 0)
1042 goto fail;
1043 wpa_config_update_psk(ssid);
1044 ssid->export_keys = 1;
1045 } else {
1046 ssid->psk_set = auth->psk_set;
1047 os_memcpy(ssid->psk, auth->psk, PMK_LEN);
1048 }
1049 }
1050
1051 os_memcpy(wpa_s->dpp_last_ssid, auth->ssid, auth->ssid_len);
1052 wpa_s->dpp_last_ssid_len = auth->ssid_len;
1053
1054 return ssid;
1055 fail:
1056 wpas_notify_network_removed(wpa_s, ssid);
1057 wpa_config_remove_network(wpa_s->conf, ssid->id);
1058 return NULL;
1059 }
1060
1061
1062 static int wpas_dpp_process_config(struct wpa_supplicant *wpa_s,
1063 struct dpp_authentication *auth)
1064 {
1065 struct wpa_ssid *ssid;
1066
1067 if (wpa_s->conf->dpp_config_processing < 1)
1068 return 0;
1069
1070 ssid = wpas_dpp_add_network(wpa_s, auth);
1071 if (!ssid)
1072 return -1;
1073
1074 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_NETWORK_ID "%d", ssid->id);
1075 if (wpa_s->conf->dpp_config_processing == 2)
1076 ssid->disabled = 0;
1077
1078 #ifndef CONFIG_NO_CONFIG_WRITE
1079 if (wpa_s->conf->update_config &&
1080 wpa_config_write(wpa_s->confname, wpa_s->conf))
1081 wpa_printf(MSG_DEBUG, "DPP: Failed to update configuration");
1082 #endif /* CONFIG_NO_CONFIG_WRITE */
1083
1084 if (wpa_s->conf->dpp_config_processing < 2)
1085 return 0;
1086
1087 #ifdef CONFIG_DPP2
1088 if (auth->peer_version >= 2) {
1089 wpa_printf(MSG_DEBUG,
1090 "DPP: Postpone connection attempt to wait for completion of DPP Configuration Result");
1091 auth->connect_on_tx_status = 1;
1092 return 0;
1093 }
1094 #endif /* CONFIG_DPP2 */
1095
1096 wpas_dpp_try_to_connect(wpa_s);
1097 return 0;
1098 }
1099
1100
1101 static int wpas_dpp_handle_config_obj(struct wpa_supplicant *wpa_s,
1102 struct dpp_authentication *auth)
1103 {
1104 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
1105 if (auth->ssid_len)
1106 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s",
1107 wpa_ssid_txt(auth->ssid, auth->ssid_len));
1108 if (auth->connector) {
1109 /* TODO: Save the Connector and consider using a command
1110 * to fetch the value instead of sending an event with
1111 * it. The Connector could end up being larger than what
1112 * most clients are ready to receive as an event
1113 * message. */
1114 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONNECTOR "%s",
1115 auth->connector);
1116 }
1117 if (auth->c_sign_key) {
1118 char *hex;
1119 size_t hexlen;
1120
1121 hexlen = 2 * wpabuf_len(auth->c_sign_key) + 1;
1122 hex = os_malloc(hexlen);
1123 if (hex) {
1124 wpa_snprintf_hex(hex, hexlen,
1125 wpabuf_head(auth->c_sign_key),
1126 wpabuf_len(auth->c_sign_key));
1127 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_C_SIGN_KEY "%s",
1128 hex);
1129 os_free(hex);
1130 }
1131 }
1132 if (auth->net_access_key) {
1133 char *hex;
1134 size_t hexlen;
1135
1136 hexlen = 2 * wpabuf_len(auth->net_access_key) + 1;
1137 hex = os_malloc(hexlen);
1138 if (hex) {
1139 wpa_snprintf_hex(hex, hexlen,
1140 wpabuf_head(auth->net_access_key),
1141 wpabuf_len(auth->net_access_key));
1142 if (auth->net_access_key_expiry)
1143 wpa_msg(wpa_s, MSG_INFO,
1144 DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex,
1145 (long unsigned)
1146 auth->net_access_key_expiry);
1147 else
1148 wpa_msg(wpa_s, MSG_INFO,
1149 DPP_EVENT_NET_ACCESS_KEY "%s", hex);
1150 os_free(hex);
1151 }
1152 }
1153
1154 return wpas_dpp_process_config(wpa_s, auth);
1155 }
1156
1157
1158 static void wpas_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token,
1159 enum gas_query_result result,
1160 const struct wpabuf *adv_proto,
1161 const struct wpabuf *resp, u16 status_code)
1162 {
1163 struct wpa_supplicant *wpa_s = ctx;
1164 const u8 *pos;
1165 struct dpp_authentication *auth = wpa_s->dpp_auth;
1166 int res;
1167 enum dpp_status_error status = DPP_STATUS_CONFIG_REJECTED;
1168
1169 wpa_s->dpp_gas_dialog_token = -1;
1170
1171 if (!auth || !auth->auth_success) {
1172 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
1173 return;
1174 }
1175 if (result != GAS_QUERY_SUCCESS ||
1176 !resp || status_code != WLAN_STATUS_SUCCESS) {
1177 wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed");
1178 goto fail;
1179 }
1180
1181 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto",
1182 adv_proto);
1183 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)",
1184 resp);
1185
1186 if (wpabuf_len(adv_proto) != 10 ||
1187 !(pos = wpabuf_head(adv_proto)) ||
1188 pos[0] != WLAN_EID_ADV_PROTO ||
1189 pos[1] != 8 ||
1190 pos[3] != WLAN_EID_VENDOR_SPECIFIC ||
1191 pos[4] != 5 ||
1192 WPA_GET_BE24(&pos[5]) != OUI_WFA ||
1193 pos[8] != 0x1a ||
1194 pos[9] != 1) {
1195 wpa_printf(MSG_DEBUG,
1196 "DPP: Not a DPP Advertisement Protocol ID");
1197 goto fail;
1198 }
1199
1200 if (dpp_conf_resp_rx(auth, resp) < 0) {
1201 wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed");
1202 goto fail;
1203 }
1204
1205 res = wpas_dpp_handle_config_obj(wpa_s, auth);
1206 if (res < 0)
1207 goto fail;
1208
1209 status = DPP_STATUS_OK;
1210 #ifdef CONFIG_TESTING_OPTIONS
1211 if (dpp_test == DPP_TEST_REJECT_CONFIG) {
1212 wpa_printf(MSG_INFO, "DPP: TESTING - Reject Config Object");
1213 status = DPP_STATUS_CONFIG_REJECTED;
1214 }
1215 #endif /* CONFIG_TESTING_OPTIONS */
1216 fail:
1217 if (status != DPP_STATUS_OK)
1218 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1219 #ifdef CONFIG_DPP2
1220 if (auth->peer_version >= 2 &&
1221 auth->conf_resp_status == DPP_STATUS_OK) {
1222 struct wpabuf *msg;
1223
1224 wpa_printf(MSG_DEBUG, "DPP: Send DPP Configuration Result");
1225 msg = dpp_build_conf_result(auth, status);
1226 if (!msg)
1227 goto fail2;
1228
1229 wpa_msg(wpa_s, MSG_INFO,
1230 DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1231 MAC2STR(addr), auth->curr_freq,
1232 DPP_PA_CONFIGURATION_RESULT);
1233 offchannel_send_action(wpa_s, auth->curr_freq,
1234 addr, wpa_s->own_addr, broadcast,
1235 wpabuf_head(msg),
1236 wpabuf_len(msg),
1237 500, wpas_dpp_tx_status, 0);
1238 wpabuf_free(msg);
1239
1240 /* This exchange will be terminated in the TX status handler */
1241 return;
1242 }
1243 fail2:
1244 #endif /* CONFIG_DPP2 */
1245 dpp_auth_deinit(wpa_s->dpp_auth);
1246 wpa_s->dpp_auth = NULL;
1247 }
1248
1249
1250 static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
1251 {
1252 struct dpp_authentication *auth = wpa_s->dpp_auth;
1253 struct wpabuf *buf;
1254 int res;
1255 int *supp_op_classes;
1256
1257 wpa_s->dpp_gas_client = 1;
1258 offchannel_send_action_done(wpa_s);
1259 wpas_dpp_listen_stop(wpa_s);
1260
1261 supp_op_classes = wpas_supp_op_classes(wpa_s);
1262 buf = dpp_build_conf_req_helper(auth, wpa_s->conf->dpp_name,
1263 wpa_s->dpp_netrole_ap,
1264 wpa_s->conf->dpp_mud_url,
1265 supp_op_classes);
1266 os_free(supp_op_classes);
1267 if (!buf) {
1268 wpa_printf(MSG_DEBUG,
1269 "DPP: No configuration request data available");
1270 return;
1271 }
1272
1273 wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
1274 MAC2STR(auth->peer_mac_addr), auth->curr_freq);
1275
1276 res = gas_query_req(wpa_s->gas, auth->peer_mac_addr, auth->curr_freq,
1277 1, buf, wpas_dpp_gas_resp_cb, wpa_s);
1278 if (res < 0) {
1279 wpa_msg(wpa_s, MSG_DEBUG, "GAS: Failed to send Query Request");
1280 wpabuf_free(buf);
1281 } else {
1282 wpa_printf(MSG_DEBUG,
1283 "DPP: GAS query started with dialog token %u", res);
1284 wpa_s->dpp_gas_dialog_token = res;
1285 }
1286 }
1287
1288
1289 static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator)
1290 {
1291 wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded");
1292 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d", initiator);
1293 #ifdef CONFIG_TESTING_OPTIONS
1294 if (dpp_test == DPP_TEST_STOP_AT_AUTH_CONF) {
1295 wpa_printf(MSG_INFO,
1296 "DPP: TESTING - stop at Authentication Confirm");
1297 if (wpa_s->dpp_auth->configurator) {
1298 /* Prevent GAS response */
1299 wpa_s->dpp_auth->auth_success = 0;
1300 }
1301 return;
1302 }
1303 #endif /* CONFIG_TESTING_OPTIONS */
1304
1305 if (wpa_s->dpp_auth->configurator)
1306 wpas_dpp_start_gas_server(wpa_s);
1307 else
1308 wpas_dpp_start_gas_client(wpa_s);
1309 }
1310
1311
1312 static void wpas_dpp_rx_auth_resp(struct wpa_supplicant *wpa_s, const u8 *src,
1313 const u8 *hdr, const u8 *buf, size_t len,
1314 unsigned int freq)
1315 {
1316 struct dpp_authentication *auth = wpa_s->dpp_auth;
1317 struct wpabuf *msg;
1318
1319 wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR
1320 " (freq %u MHz)", MAC2STR(src), freq);
1321
1322 if (!auth) {
1323 wpa_printf(MSG_DEBUG,
1324 "DPP: No DPP Authentication in progress - drop");
1325 return;
1326 }
1327
1328 if (!is_zero_ether_addr(auth->peer_mac_addr) &&
1329 os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1330 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1331 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1332 return;
1333 }
1334
1335 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
1336
1337 if (auth->curr_freq != freq && auth->neg_freq == freq) {
1338 wpa_printf(MSG_DEBUG,
1339 "DPP: Responder accepted request for different negotiation channel");
1340 auth->curr_freq = freq;
1341 }
1342
1343 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
1344 msg = dpp_auth_resp_rx(auth, hdr, buf, len);
1345 if (!msg) {
1346 if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) {
1347 wpa_printf(MSG_DEBUG,
1348 "DPP: Start wait for full response");
1349 offchannel_send_action_done(wpa_s);
1350 wpas_dpp_listen_start(wpa_s, auth->curr_freq);
1351 return;
1352 }
1353 wpa_printf(MSG_DEBUG, "DPP: No confirm generated");
1354 return;
1355 }
1356 os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
1357
1358 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1359 MAC2STR(src), auth->curr_freq, DPP_PA_AUTHENTICATION_CONF);
1360 offchannel_send_action(wpa_s, auth->curr_freq,
1361 src, wpa_s->own_addr, broadcast,
1362 wpabuf_head(msg), wpabuf_len(msg),
1363 500, wpas_dpp_tx_status, 0);
1364 wpabuf_free(msg);
1365 wpa_s->dpp_auth_ok_on_ack = 1;
1366 }
1367
1368
1369 static void wpas_dpp_rx_auth_conf(struct wpa_supplicant *wpa_s, const u8 *src,
1370 const u8 *hdr, const u8 *buf, size_t len)
1371 {
1372 struct dpp_authentication *auth = wpa_s->dpp_auth;
1373
1374 wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR,
1375 MAC2STR(src));
1376
1377 if (!auth) {
1378 wpa_printf(MSG_DEBUG,
1379 "DPP: No DPP Authentication in progress - drop");
1380 return;
1381 }
1382
1383 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1384 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1385 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1386 return;
1387 }
1388
1389 if (dpp_auth_conf_rx(auth, hdr, buf, len) < 0) {
1390 wpa_printf(MSG_DEBUG, "DPP: Authentication failed");
1391 return;
1392 }
1393
1394 wpas_dpp_auth_success(wpa_s, 0);
1395 }
1396
1397
1398 #ifdef CONFIG_DPP2
1399
1400 static void wpas_dpp_config_result_wait_timeout(void *eloop_ctx,
1401 void *timeout_ctx)
1402 {
1403 struct wpa_supplicant *wpa_s = eloop_ctx;
1404 struct dpp_authentication *auth = wpa_s->dpp_auth;
1405
1406 if (!auth || !auth->waiting_conf_result)
1407 return;
1408
1409 wpa_printf(MSG_DEBUG,
1410 "DPP: Timeout while waiting for Configuration Result");
1411 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1412 dpp_auth_deinit(auth);
1413 wpa_s->dpp_auth = NULL;
1414 }
1415
1416
1417 static void wpas_dpp_conn_status_result_wait_timeout(void *eloop_ctx,
1418 void *timeout_ctx)
1419 {
1420 struct wpa_supplicant *wpa_s = eloop_ctx;
1421 struct dpp_authentication *auth = wpa_s->dpp_auth;
1422
1423 if (!auth || !auth->waiting_conn_status_result)
1424 return;
1425
1426 wpa_printf(MSG_DEBUG,
1427 "DPP: Timeout while waiting for Connection Status Result");
1428 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONN_STATUS_RESULT "timeout");
1429 wpas_dpp_listen_stop(wpa_s);
1430 dpp_auth_deinit(auth);
1431 wpa_s->dpp_auth = NULL;
1432 }
1433
1434
1435 static void wpas_dpp_rx_conf_result(struct wpa_supplicant *wpa_s, const u8 *src,
1436 const u8 *hdr, const u8 *buf, size_t len)
1437 {
1438 struct dpp_authentication *auth = wpa_s->dpp_auth;
1439 enum dpp_status_error status;
1440
1441 wpa_printf(MSG_DEBUG, "DPP: Configuration Result from " MACSTR,
1442 MAC2STR(src));
1443
1444 if (!auth || !auth->waiting_conf_result) {
1445 wpa_printf(MSG_DEBUG,
1446 "DPP: No DPP Configuration waiting for result - drop");
1447 return;
1448 }
1449
1450 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1451 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1452 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1453 return;
1454 }
1455
1456 status = dpp_conf_result_rx(auth, hdr, buf, len);
1457
1458 if (status == DPP_STATUS_OK && auth->send_conn_status) {
1459 wpa_msg(wpa_s, MSG_INFO,
1460 DPP_EVENT_CONF_SENT "wait_conn_status=1");
1461 wpa_printf(MSG_DEBUG, "DPP: Wait for Connection Status Result");
1462 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout,
1463 wpa_s, NULL);
1464 auth->waiting_conn_status_result = 1;
1465 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout,
1466 wpa_s, NULL);
1467 eloop_register_timeout(16, 0,
1468 wpas_dpp_conn_status_result_wait_timeout,
1469 wpa_s, NULL);
1470 offchannel_send_action_done(wpa_s);
1471 wpas_dpp_listen_start(wpa_s, auth->neg_freq ? auth->neg_freq :
1472 auth->curr_freq);
1473 return;
1474 }
1475 offchannel_send_action_done(wpa_s);
1476 wpas_dpp_listen_stop(wpa_s);
1477 if (status == DPP_STATUS_OK)
1478 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
1479 else
1480 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1481 dpp_auth_deinit(auth);
1482 wpa_s->dpp_auth = NULL;
1483 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL);
1484 }
1485
1486
1487 static void wpas_dpp_rx_conn_status_result(struct wpa_supplicant *wpa_s,
1488 const u8 *src, const u8 *hdr,
1489 const u8 *buf, size_t len)
1490 {
1491 struct dpp_authentication *auth = wpa_s->dpp_auth;
1492 enum dpp_status_error status;
1493 u8 ssid[SSID_MAX_LEN];
1494 size_t ssid_len = 0;
1495 char *channel_list = NULL;
1496
1497 wpa_printf(MSG_DEBUG, "DPP: Connection Status Result");
1498
1499 if (!auth || !auth->waiting_conn_status_result) {
1500 wpa_printf(MSG_DEBUG,
1501 "DPP: No DPP Configuration waiting for connection status result - drop");
1502 return;
1503 }
1504
1505 status = dpp_conn_status_result_rx(auth, hdr, buf, len,
1506 ssid, &ssid_len, &channel_list);
1507 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONN_STATUS_RESULT
1508 "result=%d ssid=%s channel_list=%s",
1509 status, wpa_ssid_txt(ssid, ssid_len),
1510 channel_list ? channel_list : "N/A");
1511 os_free(channel_list);
1512 offchannel_send_action_done(wpa_s);
1513 wpas_dpp_listen_stop(wpa_s);
1514 dpp_auth_deinit(auth);
1515 wpa_s->dpp_auth = NULL;
1516 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout,
1517 wpa_s, NULL);
1518 }
1519
1520
1521 static int wpas_dpp_process_conf_obj(void *ctx,
1522 struct dpp_authentication *auth)
1523 {
1524 struct wpa_supplicant *wpa_s = ctx;
1525
1526 return wpas_dpp_handle_config_obj(wpa_s, auth);
1527 }
1528
1529 #endif /* CONFIG_DPP2 */
1530
1531
1532 static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant *wpa_s,
1533 const u8 *src,
1534 const u8 *buf, size_t len)
1535 {
1536 struct wpa_ssid *ssid;
1537 const u8 *connector, *trans_id, *status;
1538 u16 connector_len, trans_id_len, status_len;
1539 struct dpp_introduction intro;
1540 struct rsn_pmksa_cache_entry *entry;
1541 struct os_time now;
1542 struct os_reltime rnow;
1543 os_time_t expiry;
1544 unsigned int seconds;
1545 enum dpp_status_error res;
1546
1547 wpa_printf(MSG_DEBUG, "DPP: Peer Discovery Response from " MACSTR,
1548 MAC2STR(src));
1549 if (is_zero_ether_addr(wpa_s->dpp_intro_bssid) ||
1550 os_memcmp(src, wpa_s->dpp_intro_bssid, ETH_ALEN) != 0) {
1551 wpa_printf(MSG_DEBUG, "DPP: Not waiting for response from "
1552 MACSTR " - drop", MAC2STR(src));
1553 return;
1554 }
1555 offchannel_send_action_done(wpa_s);
1556
1557 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1558 if (ssid == wpa_s->dpp_intro_network)
1559 break;
1560 }
1561 if (!ssid || !ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1562 !ssid->dpp_csign) {
1563 wpa_printf(MSG_DEBUG,
1564 "DPP: Profile not found for network introduction");
1565 return;
1566 }
1567
1568 trans_id = dpp_get_attr(buf, len, DPP_ATTR_TRANSACTION_ID,
1569 &trans_id_len);
1570 if (!trans_id || trans_id_len != 1) {
1571 wpa_printf(MSG_DEBUG,
1572 "DPP: Peer did not include Transaction ID");
1573 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1574 " fail=missing_transaction_id", MAC2STR(src));
1575 goto fail;
1576 }
1577 if (trans_id[0] != TRANSACTION_ID) {
1578 wpa_printf(MSG_DEBUG,
1579 "DPP: Ignore frame with unexpected Transaction ID %u",
1580 trans_id[0]);
1581 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1582 " fail=transaction_id_mismatch", MAC2STR(src));
1583 goto fail;
1584 }
1585
1586 status = dpp_get_attr(buf, len, DPP_ATTR_STATUS, &status_len);
1587 if (!status || status_len != 1) {
1588 wpa_printf(MSG_DEBUG, "DPP: Peer did not include Status");
1589 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1590 " fail=missing_status", MAC2STR(src));
1591 goto fail;
1592 }
1593 if (status[0] != DPP_STATUS_OK) {
1594 wpa_printf(MSG_DEBUG,
1595 "DPP: Peer rejected network introduction: Status %u",
1596 status[0]);
1597 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1598 " status=%u", MAC2STR(src), status[0]);
1599 #ifdef CONFIG_DPP2
1600 wpas_dpp_send_conn_status_result(wpa_s, status[0]);
1601 #endif /* CONFIG_DPP2 */
1602 goto fail;
1603 }
1604
1605 connector = dpp_get_attr(buf, len, DPP_ATTR_CONNECTOR, &connector_len);
1606 if (!connector) {
1607 wpa_printf(MSG_DEBUG,
1608 "DPP: Peer did not include its Connector");
1609 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1610 " fail=missing_connector", MAC2STR(src));
1611 goto fail;
1612 }
1613
1614 res = dpp_peer_intro(&intro, ssid->dpp_connector,
1615 ssid->dpp_netaccesskey,
1616 ssid->dpp_netaccesskey_len,
1617 ssid->dpp_csign,
1618 ssid->dpp_csign_len,
1619 connector, connector_len, &expiry);
1620 if (res != DPP_STATUS_OK) {
1621 wpa_printf(MSG_INFO,
1622 "DPP: Network Introduction protocol resulted in failure");
1623 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1624 " fail=peer_connector_validation_failed", MAC2STR(src));
1625 #ifdef CONFIG_DPP2
1626 wpas_dpp_send_conn_status_result(wpa_s, res);
1627 #endif /* CONFIG_DPP2 */
1628 goto fail;
1629 }
1630
1631 entry = os_zalloc(sizeof(*entry));
1632 if (!entry)
1633 goto fail;
1634 os_memcpy(entry->aa, src, ETH_ALEN);
1635 os_memcpy(entry->pmkid, intro.pmkid, PMKID_LEN);
1636 os_memcpy(entry->pmk, intro.pmk, intro.pmk_len);
1637 entry->pmk_len = intro.pmk_len;
1638 entry->akmp = WPA_KEY_MGMT_DPP;
1639 if (expiry) {
1640 os_get_time(&now);
1641 seconds = expiry - now.sec;
1642 } else {
1643 seconds = 86400 * 7;
1644 }
1645 os_get_reltime(&rnow);
1646 entry->expiration = rnow.sec + seconds;
1647 entry->reauth_time = rnow.sec + seconds;
1648 entry->network_ctx = ssid;
1649 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
1650
1651 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1652 " status=%u", MAC2STR(src), status[0]);
1653
1654 wpa_printf(MSG_DEBUG,
1655 "DPP: Try connection again after successful network introduction");
1656 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
1657 wpa_supplicant_cancel_sched_scan(wpa_s);
1658 wpa_supplicant_req_scan(wpa_s, 0, 0);
1659 }
1660 fail:
1661 os_memset(&intro, 0, sizeof(intro));
1662 }
1663
1664
1665 static int wpas_dpp_allow_ir(struct wpa_supplicant *wpa_s, unsigned int freq)
1666 {
1667 int i, j;
1668
1669 if (!wpa_s->hw.modes)
1670 return -1;
1671
1672 for (i = 0; i < wpa_s->hw.num_modes; i++) {
1673 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
1674
1675 for (j = 0; j < mode->num_channels; j++) {
1676 struct hostapd_channel_data *chan = &mode->channels[j];
1677
1678 if (chan->freq != (int) freq)
1679 continue;
1680
1681 if (chan->flag & (HOSTAPD_CHAN_DISABLED |
1682 HOSTAPD_CHAN_NO_IR |
1683 HOSTAPD_CHAN_RADAR))
1684 continue;
1685
1686 return 1;
1687 }
1688 }
1689
1690 wpa_printf(MSG_DEBUG,
1691 "DPP: Frequency %u MHz not supported or does not allow PKEX initiation in the current channel list",
1692 freq);
1693
1694 return 0;
1695 }
1696
1697
1698 static int wpas_dpp_pkex_next_channel(struct wpa_supplicant *wpa_s,
1699 struct dpp_pkex *pkex)
1700 {
1701 if (pkex->freq == 2437)
1702 pkex->freq = 5745;
1703 else if (pkex->freq == 5745)
1704 pkex->freq = 5220;
1705 else if (pkex->freq == 5220)
1706 pkex->freq = 60480;
1707 else
1708 return -1; /* no more channels to try */
1709
1710 if (wpas_dpp_allow_ir(wpa_s, pkex->freq) == 1) {
1711 wpa_printf(MSG_DEBUG, "DPP: Try to initiate on %u MHz",
1712 pkex->freq);
1713 return 0;
1714 }
1715
1716 /* Could not use this channel - try the next one */
1717 return wpas_dpp_pkex_next_channel(wpa_s, pkex);
1718 }
1719
1720
1721 static void wpas_dpp_pkex_retry_timeout(void *eloop_ctx, void *timeout_ctx)
1722 {
1723 struct wpa_supplicant *wpa_s = eloop_ctx;
1724 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1725
1726 if (!pkex || !pkex->exchange_req)
1727 return;
1728 if (pkex->exch_req_tries >= 5) {
1729 if (wpas_dpp_pkex_next_channel(wpa_s, pkex) < 0) {
1730 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1731 "No response from PKEX peer");
1732 dpp_pkex_free(pkex);
1733 wpa_s->dpp_pkex = NULL;
1734 return;
1735 }
1736 pkex->exch_req_tries = 0;
1737 }
1738
1739 pkex->exch_req_tries++;
1740 wpa_printf(MSG_DEBUG, "DPP: Retransmit PKEX Exchange Request (try %u)",
1741 pkex->exch_req_tries);
1742 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1743 MAC2STR(broadcast), pkex->freq, DPP_PA_PKEX_EXCHANGE_REQ);
1744 offchannel_send_action(wpa_s, pkex->freq, broadcast,
1745 wpa_s->own_addr, broadcast,
1746 wpabuf_head(pkex->exchange_req),
1747 wpabuf_len(pkex->exchange_req),
1748 pkex->exch_req_wait_time,
1749 wpas_dpp_tx_pkex_status, 0);
1750 }
1751
1752
1753 static void
1754 wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s,
1755 unsigned int freq, const u8 *dst,
1756 const u8 *src, const u8 *bssid,
1757 const u8 *data, size_t data_len,
1758 enum offchannel_send_action_result result)
1759 {
1760 const char *res_txt;
1761 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1762
1763 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
1764 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
1765 "FAILED");
1766 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
1767 " result=%s (PKEX)",
1768 freq, MAC2STR(dst), res_txt);
1769 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
1770 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
1771
1772 if (!pkex) {
1773 wpa_printf(MSG_DEBUG,
1774 "DPP: Ignore TX status since there is no ongoing PKEX exchange");
1775 return;
1776 }
1777
1778 if (pkex->failed) {
1779 wpa_printf(MSG_DEBUG,
1780 "DPP: Terminate PKEX exchange due to an earlier error");
1781 if (pkex->t > pkex->own_bi->pkex_t)
1782 pkex->own_bi->pkex_t = pkex->t;
1783 dpp_pkex_free(pkex);
1784 wpa_s->dpp_pkex = NULL;
1785 return;
1786 }
1787
1788 if (pkex->exch_req_wait_time && pkex->exchange_req) {
1789 /* Wait for PKEX Exchange Response frame and retry request if
1790 * no response is seen. */
1791 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
1792 eloop_register_timeout(pkex->exch_req_wait_time / 1000,
1793 (pkex->exch_req_wait_time % 1000) * 1000,
1794 wpas_dpp_pkex_retry_timeout, wpa_s,
1795 NULL);
1796 }
1797 }
1798
1799
1800 static void
1801 wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant *wpa_s, const u8 *src,
1802 const u8 *buf, size_t len, unsigned int freq)
1803 {
1804 struct wpabuf *msg;
1805 unsigned int wait_time;
1806
1807 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Request from " MACSTR,
1808 MAC2STR(src));
1809
1810 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1811 * values here */
1812
1813 if (!wpa_s->dpp_pkex_code || !wpa_s->dpp_pkex_bi) {
1814 wpa_printf(MSG_DEBUG,
1815 "DPP: No PKEX code configured - ignore request");
1816 return;
1817 }
1818
1819 if (wpa_s->dpp_pkex) {
1820 /* TODO: Support parallel operations */
1821 wpa_printf(MSG_DEBUG,
1822 "DPP: Already in PKEX session - ignore new request");
1823 return;
1824 }
1825
1826 wpa_s->dpp_pkex = dpp_pkex_rx_exchange_req(wpa_s, wpa_s->dpp_pkex_bi,
1827 wpa_s->own_addr, src,
1828 wpa_s->dpp_pkex_identifier,
1829 wpa_s->dpp_pkex_code,
1830 buf, len);
1831 if (!wpa_s->dpp_pkex) {
1832 wpa_printf(MSG_DEBUG,
1833 "DPP: Failed to process the request - ignore it");
1834 return;
1835 }
1836
1837 msg = wpa_s->dpp_pkex->exchange_resp;
1838 wait_time = wpa_s->max_remain_on_chan;
1839 if (wait_time > 2000)
1840 wait_time = 2000;
1841 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1842 MAC2STR(src), freq, DPP_PA_PKEX_EXCHANGE_RESP);
1843 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
1844 broadcast,
1845 wpabuf_head(msg), wpabuf_len(msg),
1846 wait_time, wpas_dpp_tx_pkex_status, 0);
1847 }
1848
1849
1850 static void
1851 wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant *wpa_s, const u8 *src,
1852 const u8 *buf, size_t len, unsigned int freq)
1853 {
1854 struct wpabuf *msg;
1855 unsigned int wait_time;
1856
1857 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Response from " MACSTR,
1858 MAC2STR(src));
1859
1860 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1861 * values here */
1862
1863 if (!wpa_s->dpp_pkex || !wpa_s->dpp_pkex->initiator ||
1864 wpa_s->dpp_pkex->exchange_done) {
1865 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1866 return;
1867 }
1868
1869 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
1870 wpa_s->dpp_pkex->exch_req_wait_time = 0;
1871
1872 msg = dpp_pkex_rx_exchange_resp(wpa_s->dpp_pkex, src, buf, len);
1873 if (!msg) {
1874 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
1875 return;
1876 }
1877
1878 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Request to " MACSTR,
1879 MAC2STR(src));
1880
1881 wait_time = wpa_s->max_remain_on_chan;
1882 if (wait_time > 2000)
1883 wait_time = 2000;
1884 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1885 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_REQ);
1886 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
1887 broadcast,
1888 wpabuf_head(msg), wpabuf_len(msg),
1889 wait_time, wpas_dpp_tx_pkex_status, 0);
1890 wpabuf_free(msg);
1891 }
1892
1893
1894 static struct dpp_bootstrap_info *
1895 wpas_dpp_pkex_finish(struct wpa_supplicant *wpa_s, const u8 *peer,
1896 unsigned int freq)
1897 {
1898 struct dpp_bootstrap_info *bi;
1899
1900 bi = dpp_pkex_finish(wpa_s->dpp, wpa_s->dpp_pkex, peer, freq);
1901 if (!bi)
1902 return NULL;
1903 wpa_s->dpp_pkex = NULL;
1904 return bi;
1905 }
1906
1907
1908 static void
1909 wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant *wpa_s, const u8 *src,
1910 const u8 *hdr, const u8 *buf, size_t len,
1911 unsigned int freq)
1912 {
1913 struct wpabuf *msg;
1914 unsigned int wait_time;
1915 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1916
1917 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Request from " MACSTR,
1918 MAC2STR(src));
1919
1920 if (!pkex || pkex->initiator || !pkex->exchange_done) {
1921 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1922 return;
1923 }
1924
1925 msg = dpp_pkex_rx_commit_reveal_req(pkex, hdr, buf, len);
1926 if (!msg) {
1927 wpa_printf(MSG_DEBUG, "DPP: Failed to process the request");
1928 if (pkex->failed) {
1929 wpa_printf(MSG_DEBUG, "DPP: Terminate PKEX exchange");
1930 if (pkex->t > pkex->own_bi->pkex_t)
1931 pkex->own_bi->pkex_t = pkex->t;
1932 dpp_pkex_free(wpa_s->dpp_pkex);
1933 wpa_s->dpp_pkex = NULL;
1934 }
1935 return;
1936 }
1937
1938 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Response to "
1939 MACSTR, MAC2STR(src));
1940
1941 wait_time = wpa_s->max_remain_on_chan;
1942 if (wait_time > 2000)
1943 wait_time = 2000;
1944 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1945 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_RESP);
1946 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
1947 broadcast,
1948 wpabuf_head(msg), wpabuf_len(msg),
1949 wait_time, wpas_dpp_tx_pkex_status, 0);
1950 wpabuf_free(msg);
1951
1952 wpas_dpp_pkex_finish(wpa_s, src, freq);
1953 }
1954
1955
1956 static void
1957 wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant *wpa_s, const u8 *src,
1958 const u8 *hdr, const u8 *buf, size_t len,
1959 unsigned int freq)
1960 {
1961 int res;
1962 struct dpp_bootstrap_info *bi;
1963 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1964 char cmd[500];
1965
1966 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Response from " MACSTR,
1967 MAC2STR(src));
1968
1969 if (!pkex || !pkex->initiator || !pkex->exchange_done) {
1970 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1971 return;
1972 }
1973
1974 res = dpp_pkex_rx_commit_reveal_resp(pkex, hdr, buf, len);
1975 if (res < 0) {
1976 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
1977 return;
1978 }
1979
1980 bi = wpas_dpp_pkex_finish(wpa_s, src, freq);
1981 if (!bi)
1982 return;
1983
1984 os_snprintf(cmd, sizeof(cmd), " peer=%u %s",
1985 bi->id,
1986 wpa_s->dpp_pkex_auth_cmd ? wpa_s->dpp_pkex_auth_cmd : "");
1987 wpa_printf(MSG_DEBUG,
1988 "DPP: Start authentication after PKEX with parameters: %s",
1989 cmd);
1990 if (wpas_dpp_auth_init(wpa_s, cmd) < 0) {
1991 wpa_printf(MSG_DEBUG,
1992 "DPP: Authentication initialization failed");
1993 return;
1994 }
1995 }
1996
1997
1998 void wpas_dpp_rx_action(struct wpa_supplicant *wpa_s, const u8 *src,
1999 const u8 *buf, size_t len, unsigned int freq)
2000 {
2001 u8 crypto_suite;
2002 enum dpp_public_action_frame_type type;
2003 const u8 *hdr;
2004 unsigned int pkex_t;
2005
2006 if (len < DPP_HDR_LEN)
2007 return;
2008 if (WPA_GET_BE24(buf) != OUI_WFA || buf[3] != DPP_OUI_TYPE)
2009 return;
2010 hdr = buf;
2011 buf += 4;
2012 len -= 4;
2013 crypto_suite = *buf++;
2014 type = *buf++;
2015 len -= 2;
2016
2017 wpa_printf(MSG_DEBUG,
2018 "DPP: Received DPP Public Action frame crypto suite %u type %d from "
2019 MACSTR " freq=%u",
2020 crypto_suite, type, MAC2STR(src), freq);
2021 if (crypto_suite != 1) {
2022 wpa_printf(MSG_DEBUG, "DPP: Unsupported crypto suite %u",
2023 crypto_suite);
2024 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
2025 " freq=%u type=%d ignore=unsupported-crypto-suite",
2026 MAC2STR(src), freq, type);
2027 return;
2028 }
2029 wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len);
2030 if (dpp_check_attrs(buf, len) < 0) {
2031 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
2032 " freq=%u type=%d ignore=invalid-attributes",
2033 MAC2STR(src), freq, type);
2034 return;
2035 }
2036 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR " freq=%u type=%d",
2037 MAC2STR(src), freq, type);
2038
2039 switch (type) {
2040 case DPP_PA_AUTHENTICATION_REQ:
2041 wpas_dpp_rx_auth_req(wpa_s, src, hdr, buf, len, freq);
2042 break;
2043 case DPP_PA_AUTHENTICATION_RESP:
2044 wpas_dpp_rx_auth_resp(wpa_s, src, hdr, buf, len, freq);
2045 break;
2046 case DPP_PA_AUTHENTICATION_CONF:
2047 wpas_dpp_rx_auth_conf(wpa_s, src, hdr, buf, len);
2048 break;
2049 case DPP_PA_PEER_DISCOVERY_RESP:
2050 wpas_dpp_rx_peer_disc_resp(wpa_s, src, buf, len);
2051 break;
2052 case DPP_PA_PKEX_EXCHANGE_REQ:
2053 wpas_dpp_rx_pkex_exchange_req(wpa_s, src, buf, len, freq);
2054 break;
2055 case DPP_PA_PKEX_EXCHANGE_RESP:
2056 wpas_dpp_rx_pkex_exchange_resp(wpa_s, src, buf, len, freq);
2057 break;
2058 case DPP_PA_PKEX_COMMIT_REVEAL_REQ:
2059 wpas_dpp_rx_pkex_commit_reveal_req(wpa_s, src, hdr, buf, len,
2060 freq);
2061 break;
2062 case DPP_PA_PKEX_COMMIT_REVEAL_RESP:
2063 wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s, src, hdr, buf, len,
2064 freq);
2065 break;
2066 #ifdef CONFIG_DPP2
2067 case DPP_PA_CONFIGURATION_RESULT:
2068 wpas_dpp_rx_conf_result(wpa_s, src, hdr, buf, len);
2069 break;
2070 case DPP_PA_CONNECTION_STATUS_RESULT:
2071 wpas_dpp_rx_conn_status_result(wpa_s, src, hdr, buf, len);
2072 break;
2073 #endif /* CONFIG_DPP2 */
2074 default:
2075 wpa_printf(MSG_DEBUG,
2076 "DPP: Ignored unsupported frame subtype %d", type);
2077 break;
2078 }
2079
2080 if (wpa_s->dpp_pkex)
2081 pkex_t = wpa_s->dpp_pkex->t;
2082 else if (wpa_s->dpp_pkex_bi)
2083 pkex_t = wpa_s->dpp_pkex_bi->pkex_t;
2084 else
2085 pkex_t = 0;
2086 if (pkex_t >= PKEX_COUNTER_T_LIMIT) {
2087 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_PKEX_T_LIMIT "id=0");
2088 wpas_dpp_pkex_remove(wpa_s, "*");
2089 }
2090 }
2091
2092
2093 static struct wpabuf *
2094 wpas_dpp_gas_req_handler(void *ctx, const u8 *sa, const u8 *query,
2095 size_t query_len)
2096 {
2097 struct wpa_supplicant *wpa_s = ctx;
2098 struct dpp_authentication *auth = wpa_s->dpp_auth;
2099 struct wpabuf *resp;
2100
2101 wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR,
2102 MAC2STR(sa));
2103 if (!auth || !auth->auth_success ||
2104 os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) {
2105 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
2106 return NULL;
2107 }
2108
2109 if (wpa_s->dpp_auth_ok_on_ack && auth->configurator) {
2110 wpa_printf(MSG_DEBUG,
2111 "DPP: Have not received ACK for Auth Confirm yet - assume it was received based on this GAS request");
2112 /* wpas_dpp_auth_success() would normally have been called from
2113 * TX status handler, but since there was no such handler call
2114 * yet, simply send out the event message and proceed with
2115 * exchange. */
2116 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=1");
2117 wpa_s->dpp_auth_ok_on_ack = 0;
2118 }
2119
2120 wpa_hexdump(MSG_DEBUG,
2121 "DPP: Received Configuration Request (GAS Query Request)",
2122 query, query_len);
2123 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_REQ_RX "src=" MACSTR,
2124 MAC2STR(sa));
2125 resp = dpp_conf_req_rx(auth, query, query_len);
2126 if (!resp)
2127 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
2128 auth->conf_resp = resp;
2129 return resp;
2130 }
2131
2132
2133 static void
2134 wpas_dpp_gas_status_handler(void *ctx, struct wpabuf *resp, int ok)
2135 {
2136 struct wpa_supplicant *wpa_s = ctx;
2137 struct dpp_authentication *auth = wpa_s->dpp_auth;
2138
2139 if (!auth) {
2140 wpabuf_free(resp);
2141 return;
2142 }
2143 if (auth->conf_resp != resp) {
2144 wpa_printf(MSG_DEBUG,
2145 "DPP: Ignore GAS status report (ok=%d) for unknown response",
2146 ok);
2147 wpabuf_free(resp);
2148 return;
2149 }
2150
2151 wpa_printf(MSG_DEBUG, "DPP: Configuration exchange completed (ok=%d)",
2152 ok);
2153 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
2154 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
2155 #ifdef CONFIG_DPP2
2156 if (ok && auth->peer_version >= 2 &&
2157 auth->conf_resp_status == DPP_STATUS_OK) {
2158 wpa_printf(MSG_DEBUG, "DPP: Wait for Configuration Result");
2159 auth->waiting_conf_result = 1;
2160 auth->conf_resp = NULL;
2161 wpabuf_free(resp);
2162 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout,
2163 wpa_s, NULL);
2164 eloop_register_timeout(2, 0,
2165 wpas_dpp_config_result_wait_timeout,
2166 wpa_s, NULL);
2167 return;
2168 }
2169 #endif /* CONFIG_DPP2 */
2170 offchannel_send_action_done(wpa_s);
2171 wpas_dpp_listen_stop(wpa_s);
2172 if (ok)
2173 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
2174 else
2175 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
2176 dpp_auth_deinit(wpa_s->dpp_auth);
2177 wpa_s->dpp_auth = NULL;
2178 wpabuf_free(resp);
2179 }
2180
2181
2182 int wpas_dpp_configurator_sign(struct wpa_supplicant *wpa_s, const char *cmd)
2183 {
2184 struct dpp_authentication *auth;
2185 int ret = -1;
2186 char *curve = NULL;
2187
2188 auth = os_zalloc(sizeof(*auth));
2189 if (!auth)
2190 return -1;
2191
2192 curve = get_param(cmd, " curve=");
2193 wpas_dpp_set_testing_options(wpa_s, auth);
2194 if (dpp_set_configurator(wpa_s->dpp, wpa_s, auth, cmd) == 0 &&
2195 dpp_configurator_own_config(auth, curve, 0) == 0)
2196 ret = wpas_dpp_handle_config_obj(wpa_s, auth);
2197
2198 dpp_auth_deinit(auth);
2199 os_free(curve);
2200
2201 return ret;
2202 }
2203
2204
2205 static void
2206 wpas_dpp_tx_introduction_status(struct wpa_supplicant *wpa_s,
2207 unsigned int freq, const u8 *dst,
2208 const u8 *src, const u8 *bssid,
2209 const u8 *data, size_t data_len,
2210 enum offchannel_send_action_result result)
2211 {
2212 const char *res_txt;
2213
2214 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
2215 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
2216 "FAILED");
2217 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
2218 " result=%s (DPP Peer Discovery Request)",
2219 freq, MAC2STR(dst), res_txt);
2220 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
2221 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
2222 /* TODO: Time out wait for response more quickly in error cases? */
2223 }
2224
2225
2226 int wpas_dpp_check_connect(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2227 struct wpa_bss *bss)
2228 {
2229 struct os_time now;
2230 struct wpabuf *msg;
2231 unsigned int wait_time;
2232 const u8 *rsn;
2233 struct wpa_ie_data ied;
2234
2235 if (!(ssid->key_mgmt & WPA_KEY_MGMT_DPP) || !bss)
2236 return 0; /* Not using DPP AKM - continue */
2237 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2238 if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ied) == 0 &&
2239 !(ied.key_mgmt & WPA_KEY_MGMT_DPP))
2240 return 0; /* AP does not support DPP AKM - continue */
2241 if (wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid))
2242 return 0; /* PMKSA exists for DPP AKM - continue */
2243
2244 if (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
2245 !ssid->dpp_csign) {
2246 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
2247 "missing %s",
2248 !ssid->dpp_connector ? "Connector" :
2249 (!ssid->dpp_netaccesskey ? "netAccessKey" :
2250 "C-sign-key"));
2251 return -1;
2252 }
2253
2254 os_get_time(&now);
2255
2256 if (ssid->dpp_netaccesskey_expiry &&
2257 (os_time_t) ssid->dpp_netaccesskey_expiry < now.sec) {
2258 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
2259 "netAccessKey expired");
2260 return -1;
2261 }
2262
2263 wpa_printf(MSG_DEBUG,
2264 "DPP: Starting network introduction protocol to derive PMKSA for "
2265 MACSTR, MAC2STR(bss->bssid));
2266
2267 msg = dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ,
2268 5 + 4 + os_strlen(ssid->dpp_connector));
2269 if (!msg)
2270 return -1;
2271
2272 #ifdef CONFIG_TESTING_OPTIONS
2273 if (dpp_test == DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ) {
2274 wpa_printf(MSG_INFO, "DPP: TESTING - no Transaction ID");
2275 goto skip_trans_id;
2276 }
2277 if (dpp_test == DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ) {
2278 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Transaction ID");
2279 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
2280 wpabuf_put_le16(msg, 0);
2281 goto skip_trans_id;
2282 }
2283 #endif /* CONFIG_TESTING_OPTIONS */
2284
2285 /* Transaction ID */
2286 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
2287 wpabuf_put_le16(msg, 1);
2288 wpabuf_put_u8(msg, TRANSACTION_ID);
2289
2290 #ifdef CONFIG_TESTING_OPTIONS
2291 skip_trans_id:
2292 if (dpp_test == DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ) {
2293 wpa_printf(MSG_INFO, "DPP: TESTING - no Connector");
2294 goto skip_connector;
2295 }
2296 if (dpp_test == DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ) {
2297 char *connector;
2298
2299 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Connector");
2300 connector = dpp_corrupt_connector_signature(
2301 ssid->dpp_connector);
2302 if (!connector) {
2303 wpabuf_free(msg);
2304 return -1;
2305 }
2306 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
2307 wpabuf_put_le16(msg, os_strlen(connector));
2308 wpabuf_put_str(msg, connector);
2309 os_free(connector);
2310 goto skip_connector;
2311 }
2312 #endif /* CONFIG_TESTING_OPTIONS */
2313
2314 /* DPP Connector */
2315 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
2316 wpabuf_put_le16(msg, os_strlen(ssid->dpp_connector));
2317 wpabuf_put_str(msg, ssid->dpp_connector);
2318
2319 #ifdef CONFIG_TESTING_OPTIONS
2320 skip_connector:
2321 #endif /* CONFIG_TESTING_OPTIONS */
2322
2323 /* TODO: Timeout on AP response */
2324 wait_time = wpa_s->max_remain_on_chan;
2325 if (wait_time > 2000)
2326 wait_time = 2000;
2327 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2328 MAC2STR(bss->bssid), bss->freq, DPP_PA_PEER_DISCOVERY_REQ);
2329 offchannel_send_action(wpa_s, bss->freq, bss->bssid, wpa_s->own_addr,
2330 broadcast,
2331 wpabuf_head(msg), wpabuf_len(msg),
2332 wait_time, wpas_dpp_tx_introduction_status, 0);
2333 wpabuf_free(msg);
2334
2335 /* Request this connection attempt to terminate - new one will be
2336 * started when network introduction protocol completes */
2337 os_memcpy(wpa_s->dpp_intro_bssid, bss->bssid, ETH_ALEN);
2338 wpa_s->dpp_intro_network = ssid;
2339 return 1;
2340 }
2341
2342
2343 int wpas_dpp_pkex_add(struct wpa_supplicant *wpa_s, const char *cmd)
2344 {
2345 struct dpp_bootstrap_info *own_bi;
2346 const char *pos, *end;
2347 unsigned int wait_time;
2348
2349 pos = os_strstr(cmd, " own=");
2350 if (!pos)
2351 return -1;
2352 pos += 5;
2353 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
2354 if (!own_bi) {
2355 wpa_printf(MSG_DEBUG,
2356 "DPP: Identified bootstrap info not found");
2357 return -1;
2358 }
2359 if (own_bi->type != DPP_BOOTSTRAP_PKEX) {
2360 wpa_printf(MSG_DEBUG,
2361 "DPP: Identified bootstrap info not for PKEX");
2362 return -1;
2363 }
2364 wpa_s->dpp_pkex_bi = own_bi;
2365 own_bi->pkex_t = 0; /* clear pending errors on new code */
2366
2367 os_free(wpa_s->dpp_pkex_identifier);
2368 wpa_s->dpp_pkex_identifier = NULL;
2369 pos = os_strstr(cmd, " identifier=");
2370 if (pos) {
2371 pos += 12;
2372 end = os_strchr(pos, ' ');
2373 if (!end)
2374 return -1;
2375 wpa_s->dpp_pkex_identifier = os_malloc(end - pos + 1);
2376 if (!wpa_s->dpp_pkex_identifier)
2377 return -1;
2378 os_memcpy(wpa_s->dpp_pkex_identifier, pos, end - pos);
2379 wpa_s->dpp_pkex_identifier[end - pos] = '\0';
2380 }
2381
2382 pos = os_strstr(cmd, " code=");
2383 if (!pos)
2384 return -1;
2385 os_free(wpa_s->dpp_pkex_code);
2386 wpa_s->dpp_pkex_code = os_strdup(pos + 6);
2387 if (!wpa_s->dpp_pkex_code)
2388 return -1;
2389
2390 if (os_strstr(cmd, " init=1")) {
2391 struct dpp_pkex *pkex;
2392 struct wpabuf *msg;
2393
2394 wpa_printf(MSG_DEBUG, "DPP: Initiating PKEX");
2395 dpp_pkex_free(wpa_s->dpp_pkex);
2396 wpa_s->dpp_pkex = dpp_pkex_init(wpa_s, own_bi, wpa_s->own_addr,
2397 wpa_s->dpp_pkex_identifier,
2398 wpa_s->dpp_pkex_code);
2399 pkex = wpa_s->dpp_pkex;
2400 if (!pkex)
2401 return -1;
2402
2403 msg = pkex->exchange_req;
2404 wait_time = wpa_s->max_remain_on_chan;
2405 if (wait_time > 2000)
2406 wait_time = 2000;
2407 pkex->freq = 2437;
2408 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
2409 " freq=%u type=%d",
2410 MAC2STR(broadcast), pkex->freq,
2411 DPP_PA_PKEX_EXCHANGE_REQ);
2412 offchannel_send_action(wpa_s, pkex->freq, broadcast,
2413 wpa_s->own_addr, broadcast,
2414 wpabuf_head(msg), wpabuf_len(msg),
2415 wait_time, wpas_dpp_tx_pkex_status, 0);
2416 if (wait_time == 0)
2417 wait_time = 2000;
2418 pkex->exch_req_wait_time = wait_time;
2419 pkex->exch_req_tries = 1;
2420 }
2421
2422 /* TODO: Support multiple PKEX info entries */
2423
2424 os_free(wpa_s->dpp_pkex_auth_cmd);
2425 wpa_s->dpp_pkex_auth_cmd = os_strdup(cmd);
2426
2427 return 1;
2428 }
2429
2430
2431 int wpas_dpp_pkex_remove(struct wpa_supplicant *wpa_s, const char *id)
2432 {
2433 unsigned int id_val;
2434
2435 if (os_strcmp(id, "*") == 0) {
2436 id_val = 0;
2437 } else {
2438 id_val = atoi(id);
2439 if (id_val == 0)
2440 return -1;
2441 }
2442
2443 if ((id_val != 0 && id_val != 1) || !wpa_s->dpp_pkex_code)
2444 return -1;
2445
2446 /* TODO: Support multiple PKEX entries */
2447 os_free(wpa_s->dpp_pkex_code);
2448 wpa_s->dpp_pkex_code = NULL;
2449 os_free(wpa_s->dpp_pkex_identifier);
2450 wpa_s->dpp_pkex_identifier = NULL;
2451 os_free(wpa_s->dpp_pkex_auth_cmd);
2452 wpa_s->dpp_pkex_auth_cmd = NULL;
2453 wpa_s->dpp_pkex_bi = NULL;
2454 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
2455 dpp_pkex_free(wpa_s->dpp_pkex);
2456 wpa_s->dpp_pkex = NULL;
2457 return 0;
2458 }
2459
2460
2461 void wpas_dpp_stop(struct wpa_supplicant *wpa_s)
2462 {
2463 dpp_auth_deinit(wpa_s->dpp_auth);
2464 wpa_s->dpp_auth = NULL;
2465 dpp_pkex_free(wpa_s->dpp_pkex);
2466 wpa_s->dpp_pkex = NULL;
2467 if (wpa_s->dpp_gas_client && wpa_s->dpp_gas_dialog_token >= 0)
2468 gas_query_stop(wpa_s->gas, wpa_s->dpp_gas_dialog_token);
2469 }
2470
2471
2472 int wpas_dpp_init(struct wpa_supplicant *wpa_s)
2473 {
2474 struct dpp_global_config config;
2475 u8 adv_proto_id[7];
2476
2477 adv_proto_id[0] = WLAN_EID_VENDOR_SPECIFIC;
2478 adv_proto_id[1] = 5;
2479 WPA_PUT_BE24(&adv_proto_id[2], OUI_WFA);
2480 adv_proto_id[5] = DPP_OUI_TYPE;
2481 adv_proto_id[6] = 0x01;
2482
2483 if (gas_server_register(wpa_s->gas_server, adv_proto_id,
2484 sizeof(adv_proto_id), wpas_dpp_gas_req_handler,
2485 wpas_dpp_gas_status_handler, wpa_s) < 0)
2486 return -1;
2487
2488 os_memset(&config, 0, sizeof(config));
2489 config.msg_ctx = wpa_s;
2490 config.cb_ctx = wpa_s;
2491 #ifdef CONFIG_DPP2
2492 config.process_conf_obj = wpas_dpp_process_conf_obj;
2493 #endif /* CONFIG_DPP2 */
2494 wpa_s->dpp = dpp_global_init(&config);
2495 return wpa_s->dpp ? 0 : -1;
2496 }
2497
2498
2499 void wpas_dpp_deinit(struct wpa_supplicant *wpa_s)
2500 {
2501 #ifdef CONFIG_TESTING_OPTIONS
2502 os_free(wpa_s->dpp_config_obj_override);
2503 wpa_s->dpp_config_obj_override = NULL;
2504 os_free(wpa_s->dpp_discovery_override);
2505 wpa_s->dpp_discovery_override = NULL;
2506 os_free(wpa_s->dpp_groups_override);
2507 wpa_s->dpp_groups_override = NULL;
2508 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
2509 #endif /* CONFIG_TESTING_OPTIONS */
2510 if (!wpa_s->dpp)
2511 return;
2512 dpp_global_clear(wpa_s->dpp);
2513 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
2514 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
2515 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
2516 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
2517 #ifdef CONFIG_DPP2
2518 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL);
2519 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout,
2520 wpa_s, NULL);
2521 eloop_cancel_timeout(wpas_dpp_conn_status_result_timeout, wpa_s, NULL);
2522 dpp_pfs_free(wpa_s->dpp_pfs);
2523 wpa_s->dpp_pfs = NULL;
2524 #endif /* CONFIG_DPP2 */
2525 offchannel_send_action_done(wpa_s);
2526 wpas_dpp_listen_stop(wpa_s);
2527 wpas_dpp_stop(wpa_s);
2528 wpas_dpp_pkex_remove(wpa_s, "*");
2529 os_memset(wpa_s->dpp_intro_bssid, 0, ETH_ALEN);
2530 os_free(wpa_s->dpp_configurator_params);
2531 wpa_s->dpp_configurator_params = NULL;
2532 }
2533
2534
2535 #ifdef CONFIG_DPP2
2536 int wpas_dpp_controller_start(struct wpa_supplicant *wpa_s, const char *cmd)
2537 {
2538 struct dpp_controller_config config;
2539 const char *pos;
2540
2541 os_memset(&config, 0, sizeof(config));
2542 if (cmd) {
2543 pos = os_strstr(cmd, " tcp_port=");
2544 if (pos) {
2545 pos += 10;
2546 config.tcp_port = atoi(pos);
2547 }
2548 }
2549 config.configurator_params = wpa_s->dpp_configurator_params;
2550 return dpp_controller_start(wpa_s->dpp, &config);
2551 }
2552 #endif /* CONFIG_DPP2 */