blob: 2d0c6364e6b161a918b39235317a90dd0804bf4e [file] [log] [blame]
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001/*
2 * wpa_supplicant - DPP
3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
Hai Shalomfdcde762020-04-02 11:19:20 -07004 * Copyright (c) 2018-2020, The Linux Foundation
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005 *
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"
Hai Shalom81f62d82019-07-22 12:10:00 -070014#include "utils/ip_addr.h"
Hai Shalom899fcc72020-10-19 14:38:18 -070015#include "utils/base64.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070016#include "common/dpp.h"
17#include "common/gas.h"
18#include "common/gas_server.h"
19#include "rsn_supp/wpa.h"
20#include "rsn_supp/pmksa_cache.h"
21#include "wpa_supplicant_i.h"
22#include "config.h"
23#include "driver_i.h"
24#include "offchannel.h"
25#include "gas_query.h"
26#include "bss.h"
27#include "scan.h"
28#include "notify.h"
29#include "dpp_supplicant.h"
Hai Shalom59532852018-12-07 10:32:58 -080030#include "hidl.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070031
32
33static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
34 unsigned int freq);
35static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx);
36static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator);
37static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
38 unsigned int freq, const u8 *dst,
39 const u8 *src, const u8 *bssid,
40 const u8 *data, size_t data_len,
41 enum offchannel_send_action_result result);
Roshan Pius3a1667e2018-07-03 15:17:14 -070042static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx);
43static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s);
44static void
45wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s,
46 unsigned int freq, const u8 *dst,
47 const u8 *src, const u8 *bssid,
48 const u8 *data, size_t data_len,
49 enum offchannel_send_action_result result);
Hai Shalom4fbc08f2020-05-18 12:37:00 -070050#ifdef CONFIG_DPP2
51static void wpas_dpp_reconfig_reply_wait_timeout(void *eloop_ctx,
52 void *timeout_ctx);
Hai Shalom899fcc72020-10-19 14:38:18 -070053static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s);
54static int wpas_dpp_process_conf_obj(void *ctx,
55 struct dpp_authentication *auth);
Hai Shalom4fbc08f2020-05-18 12:37:00 -070056#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070057
58static const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
59
60/* Use a hardcoded Transaction ID 1 in Peer Discovery frames since there is only
61 * a single transaction in progress at any point in time. */
62static const u8 TRANSACTION_ID = 1;
63
64
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070065/**
66 * wpas_dpp_qr_code - Parse and add DPP bootstrapping info from a QR Code
67 * @wpa_s: Pointer to wpa_supplicant data
68 * @cmd: DPP URI read from a QR Code
69 * Returns: Identifier of the stored info or -1 on failure
70 */
71int wpas_dpp_qr_code(struct wpa_supplicant *wpa_s, const char *cmd)
72{
73 struct dpp_bootstrap_info *bi;
74 struct dpp_authentication *auth = wpa_s->dpp_auth;
75
Hai Shalom021b0b52019-04-10 11:17:58 -070076 bi = dpp_add_qr_code(wpa_s->dpp, cmd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070077 if (!bi)
78 return -1;
79
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070080 if (auth && auth->response_pending &&
81 dpp_notify_new_qr_code(auth, bi) == 1) {
82 wpa_printf(MSG_DEBUG,
83 "DPP: Sending out pending authentication response");
Roshan Pius3a1667e2018-07-03 15:17:14 -070084 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
85 " freq=%u type=%d",
86 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
87 DPP_PA_AUTHENTICATION_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070088 offchannel_send_action(wpa_s, auth->curr_freq,
89 auth->peer_mac_addr, wpa_s->own_addr,
90 broadcast,
91 wpabuf_head(auth->resp_msg),
92 wpabuf_len(auth->resp_msg),
93 500, wpas_dpp_tx_status, 0);
94 }
95
Hai Shalom899fcc72020-10-19 14:38:18 -070096#ifdef CONFIG_DPP2
97 dpp_controller_new_qr_code(wpa_s->dpp, bi);
98#endif /* CONFIG_DPP2 */
99
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700100 return bi->id;
101}
102
103
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800104/**
105 * wpas_dpp_nfc_uri - Parse and add DPP bootstrapping info from NFC Tag (URI)
106 * @wpa_s: Pointer to wpa_supplicant data
107 * @cmd: DPP URI read from a NFC Tag (URI NDEF message)
108 * Returns: Identifier of the stored info or -1 on failure
109 */
110int wpas_dpp_nfc_uri(struct wpa_supplicant *wpa_s, const char *cmd)
111{
112 struct dpp_bootstrap_info *bi;
113
114 bi = dpp_add_nfc_uri(wpa_s->dpp, cmd);
115 if (!bi)
116 return -1;
117
118 return bi->id;
119}
120
121
Hai Shalomfdcde762020-04-02 11:19:20 -0700122int wpas_dpp_nfc_handover_req(struct wpa_supplicant *wpa_s, const char *cmd)
123{
124 const char *pos;
125 struct dpp_bootstrap_info *peer_bi, *own_bi;
126
127 pos = os_strstr(cmd, " own=");
128 if (!pos)
129 return -1;
130 pos += 5;
131 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
132 if (!own_bi)
133 return -1;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700134 own_bi->nfc_negotiated = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700135
136 pos = os_strstr(cmd, " uri=");
137 if (!pos)
138 return -1;
139 pos += 5;
140 peer_bi = dpp_add_nfc_uri(wpa_s->dpp, pos);
141 if (!peer_bi) {
142 wpa_printf(MSG_INFO,
143 "DPP: Failed to parse URI from NFC Handover Request");
144 return -1;
145 }
146
147 if (dpp_nfc_update_bi(own_bi, peer_bi) < 0)
148 return -1;
149
150 return peer_bi->id;
151}
152
153
154int wpas_dpp_nfc_handover_sel(struct wpa_supplicant *wpa_s, const char *cmd)
155{
156 const char *pos;
157 struct dpp_bootstrap_info *peer_bi, *own_bi;
158
159 pos = os_strstr(cmd, " own=");
160 if (!pos)
161 return -1;
162 pos += 5;
163 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
164 if (!own_bi)
165 return -1;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700166 own_bi->nfc_negotiated = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700167
168 pos = os_strstr(cmd, " uri=");
169 if (!pos)
170 return -1;
171 pos += 5;
172 peer_bi = dpp_add_nfc_uri(wpa_s->dpp, pos);
173 if (!peer_bi) {
174 wpa_printf(MSG_INFO,
175 "DPP: Failed to parse URI from NFC Handover Select");
176 return -1;
177 }
178
179 if (peer_bi->curve != own_bi->curve) {
180 wpa_printf(MSG_INFO,
181 "DPP: Peer (NFC Handover Selector) used different curve");
182 return -1;
183 }
184
185 return peer_bi->id;
186}
187
188
Roshan Pius3a1667e2018-07-03 15:17:14 -0700189static void wpas_dpp_auth_resp_retry_timeout(void *eloop_ctx, void *timeout_ctx)
190{
191 struct wpa_supplicant *wpa_s = eloop_ctx;
192 struct dpp_authentication *auth = wpa_s->dpp_auth;
193
194 if (!auth || !auth->resp_msg)
195 return;
196
197 wpa_printf(MSG_DEBUG,
198 "DPP: Retry Authentication Response after timeout");
199 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
200 " freq=%u type=%d",
201 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
202 DPP_PA_AUTHENTICATION_RESP);
203 offchannel_send_action(wpa_s, auth->curr_freq, auth->peer_mac_addr,
204 wpa_s->own_addr, broadcast,
205 wpabuf_head(auth->resp_msg),
206 wpabuf_len(auth->resp_msg),
207 500, wpas_dpp_tx_status, 0);
208}
209
210
211static void wpas_dpp_auth_resp_retry(struct wpa_supplicant *wpa_s)
212{
213 struct dpp_authentication *auth = wpa_s->dpp_auth;
214 unsigned int wait_time, max_tries;
215
216 if (!auth || !auth->resp_msg)
217 return;
218
219 if (wpa_s->dpp_resp_max_tries)
220 max_tries = wpa_s->dpp_resp_max_tries;
221 else
222 max_tries = 5;
223 auth->auth_resp_tries++;
224 if (auth->auth_resp_tries >= max_tries) {
225 wpa_printf(MSG_INFO, "DPP: No confirm received from initiator - stopping exchange");
226 offchannel_send_action_done(wpa_s);
227 dpp_auth_deinit(wpa_s->dpp_auth);
228 wpa_s->dpp_auth = NULL;
229 return;
230 }
231
232 if (wpa_s->dpp_resp_retry_time)
233 wait_time = wpa_s->dpp_resp_retry_time;
234 else
235 wait_time = 1000;
236 wpa_printf(MSG_DEBUG,
237 "DPP: Schedule retransmission of Authentication Response frame in %u ms",
238 wait_time);
239 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
240 eloop_register_timeout(wait_time / 1000,
241 (wait_time % 1000) * 1000,
242 wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
243}
244
245
Hai Shalom021b0b52019-04-10 11:17:58 -0700246static void wpas_dpp_try_to_connect(struct wpa_supplicant *wpa_s)
247{
248 wpa_printf(MSG_DEBUG, "DPP: Trying to connect to the new network");
Hai Shalomc3565922019-10-28 11:58:20 -0700249 wpa_s->suitable_network = 0;
250 wpa_s->no_suitable_network = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700251 wpa_s->disconnected = 0;
252 wpa_s->reassociate = 1;
253 wpa_s->scan_runs = 0;
254 wpa_s->normal_scans = 0;
255 wpa_supplicant_cancel_sched_scan(wpa_s);
256 wpa_supplicant_req_scan(wpa_s, 0, 0);
257}
258
259
Hai Shalomc3565922019-10-28 11:58:20 -0700260#ifdef CONFIG_DPP2
261
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700262static void wpas_dpp_stop_listen_for_tx(struct wpa_supplicant *wpa_s,
263 unsigned int freq,
264 unsigned int wait_time)
265{
266 struct os_reltime now, res;
267 unsigned int remaining;
268
269 if (!wpa_s->dpp_listen_freq)
270 return;
271
272 os_get_reltime(&now);
273 if (os_reltime_before(&now, &wpa_s->dpp_listen_end)) {
274 os_reltime_sub(&wpa_s->dpp_listen_end, &now, &res);
275 remaining = res.sec * 1000 + res.usec / 1000;
276 } else {
277 remaining = 0;
278 }
279 if (wpa_s->dpp_listen_freq == freq && remaining > wait_time)
280 return;
281
282 wpa_printf(MSG_DEBUG,
283 "DPP: Stop listen on %u MHz ending in %u ms to allow immediate TX on %u MHz for %u ms",
284 wpa_s->dpp_listen_freq, remaining, freq, wait_time);
285 wpas_dpp_listen_stop(wpa_s);
286
287 /* TODO: Restart listen in some cases after TX? */
288}
289
290
Hai Shalomc3565922019-10-28 11:58:20 -0700291static void wpas_dpp_conn_status_result_timeout(void *eloop_ctx,
292 void *timeout_ctx)
293{
294 struct wpa_supplicant *wpa_s = eloop_ctx;
295 struct dpp_authentication *auth = wpa_s->dpp_auth;
296 enum dpp_status_error result;
297
298 if (!auth || !auth->conn_status_requested)
299 return;
300
301 wpa_printf(MSG_DEBUG,
302 "DPP: Connection timeout - report Connection Status Result");
303 if (wpa_s->suitable_network)
304 result = DPP_STATUS_AUTH_FAILURE;
305 else if (wpa_s->no_suitable_network)
306 result = DPP_STATUS_NO_AP;
307 else
308 result = 255; /* What to report here for unexpected state? */
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800309 if (wpa_s->wpa_state == WPA_SCANNING)
310 wpas_abort_ongoing_scan(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700311 wpas_dpp_send_conn_status_result(wpa_s, result);
312}
313
314
315static char * wpas_dpp_scan_channel_list(struct wpa_supplicant *wpa_s)
316{
317 char *str, *end, *pos;
318 size_t len;
319 unsigned int i;
320 u8 last_op_class = 0;
321 int res;
322
323 if (!wpa_s->last_scan_freqs || !wpa_s->num_last_scan_freqs)
324 return NULL;
325
326 len = wpa_s->num_last_scan_freqs * 8;
327 str = os_zalloc(len);
328 if (!str)
329 return NULL;
330 end = str + len;
331 pos = str;
332
333 for (i = 0; i < wpa_s->num_last_scan_freqs; i++) {
334 enum hostapd_hw_mode mode;
335 u8 op_class, channel;
336
337 mode = ieee80211_freq_to_channel_ext(wpa_s->last_scan_freqs[i],
338 0, 0, &op_class, &channel);
339 if (mode == NUM_HOSTAPD_MODES)
340 continue;
341 if (op_class == last_op_class)
342 res = os_snprintf(pos, end - pos, ",%d", channel);
343 else
344 res = os_snprintf(pos, end - pos, "%s%d/%d",
345 pos == str ? "" : ",",
346 op_class, channel);
347 if (os_snprintf_error(end - pos, res)) {
348 *pos = '\0';
349 break;
350 }
351 pos += res;
352 last_op_class = op_class;
353 }
354
355 if (pos == str) {
356 os_free(str);
357 str = NULL;
358 }
359 return str;
360}
361
362
363void wpas_dpp_send_conn_status_result(struct wpa_supplicant *wpa_s,
364 enum dpp_status_error result)
365{
366 struct wpabuf *msg;
367 const char *channel_list = NULL;
368 char *channel_list_buf = NULL;
369 struct wpa_ssid *ssid = wpa_s->current_ssid;
370 struct dpp_authentication *auth = wpa_s->dpp_auth;
371
372 eloop_cancel_timeout(wpas_dpp_conn_status_result_timeout, wpa_s, NULL);
373
374 if (!auth || !auth->conn_status_requested)
375 return;
376 auth->conn_status_requested = 0;
377 wpa_printf(MSG_DEBUG, "DPP: Report connection status result %d",
378 result);
379
380 if (result == DPP_STATUS_NO_AP) {
381 channel_list_buf = wpas_dpp_scan_channel_list(wpa_s);
382 channel_list = channel_list_buf;
383 }
384
385 msg = dpp_build_conn_status_result(auth, result,
386 ssid ? ssid->ssid :
387 wpa_s->dpp_last_ssid,
388 ssid ? ssid->ssid_len :
389 wpa_s->dpp_last_ssid_len,
390 channel_list);
391 os_free(channel_list_buf);
392 if (!msg) {
393 dpp_auth_deinit(wpa_s->dpp_auth);
394 wpa_s->dpp_auth = NULL;
395 return;
396 }
397
398 wpa_msg(wpa_s, MSG_INFO,
399 DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
400 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
401 DPP_PA_CONNECTION_STATUS_RESULT);
402 offchannel_send_action(wpa_s, auth->curr_freq,
403 auth->peer_mac_addr, wpa_s->own_addr, broadcast,
404 wpabuf_head(msg), wpabuf_len(msg),
405 500, wpas_dpp_tx_status, 0);
406 wpabuf_free(msg);
407
408 /* This exchange will be terminated in the TX status handler */
409 auth->remove_on_tx_status = 1;
410
411 return;
412}
413
414
415void wpas_dpp_connected(struct wpa_supplicant *wpa_s)
416{
417 struct dpp_authentication *auth = wpa_s->dpp_auth;
418
419 if (auth && auth->conn_status_requested)
420 wpas_dpp_send_conn_status_result(wpa_s, DPP_STATUS_OK);
421}
422
423#endif /* CONFIG_DPP2 */
424
425
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700426static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
427 unsigned int freq, const u8 *dst,
428 const u8 *src, const u8 *bssid,
429 const u8 *data, size_t data_len,
430 enum offchannel_send_action_result result)
431{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700432 const char *res_txt;
433 struct dpp_authentication *auth = wpa_s->dpp_auth;
434
435 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
436 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
437 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700438 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
Roshan Pius3a1667e2018-07-03 15:17:14 -0700439 " result=%s", freq, MAC2STR(dst), res_txt);
440 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
441 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700442
443 if (!wpa_s->dpp_auth) {
444 wpa_printf(MSG_DEBUG,
445 "DPP: Ignore TX status since there is no ongoing authentication exchange");
446 return;
447 }
448
Hai Shalom021b0b52019-04-10 11:17:58 -0700449#ifdef CONFIG_DPP2
450 if (auth->connect_on_tx_status) {
Hai Shalomc3565922019-10-28 11:58:20 -0700451 auth->connect_on_tx_status = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700452 wpa_printf(MSG_DEBUG,
453 "DPP: Try to connect after completed configuration result");
454 wpas_dpp_try_to_connect(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700455 if (auth->conn_status_requested) {
456 wpa_printf(MSG_DEBUG,
457 "DPP: Start 15 second timeout for reporting connection status result");
458 eloop_cancel_timeout(
459 wpas_dpp_conn_status_result_timeout,
460 wpa_s, NULL);
461 eloop_register_timeout(
462 15, 0, wpas_dpp_conn_status_result_timeout,
463 wpa_s, NULL);
464 } else {
465 dpp_auth_deinit(wpa_s->dpp_auth);
466 wpa_s->dpp_auth = NULL;
467 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700468 return;
469 }
470#endif /* CONFIG_DPP2 */
471
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700472 if (wpa_s->dpp_auth->remove_on_tx_status) {
473 wpa_printf(MSG_DEBUG,
Hai Shalomc3565922019-10-28 11:58:20 -0700474 "DPP: Terminate authentication exchange due to a request to do so on TX status");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700475 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700476 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700477 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
478 NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700479#ifdef CONFIG_DPP2
480 eloop_cancel_timeout(wpas_dpp_reconfig_reply_wait_timeout,
481 wpa_s, NULL);
482#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700483 offchannel_send_action_done(wpa_s);
484 dpp_auth_deinit(wpa_s->dpp_auth);
485 wpa_s->dpp_auth = NULL;
486 return;
487 }
488
489 if (wpa_s->dpp_auth_ok_on_ack)
490 wpas_dpp_auth_success(wpa_s, 1);
491
492 if (!is_broadcast_ether_addr(dst) &&
493 result != OFFCHANNEL_SEND_ACTION_SUCCESS) {
494 wpa_printf(MSG_DEBUG,
495 "DPP: Unicast DPP Action frame was not ACKed");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700496 if (auth->waiting_auth_resp) {
497 /* In case of DPP Authentication Request frame, move to
498 * the next channel immediately. */
499 offchannel_send_action_done(wpa_s);
500 wpas_dpp_auth_init_next(wpa_s);
501 return;
502 }
503 if (auth->waiting_auth_conf) {
504 wpas_dpp_auth_resp_retry(wpa_s);
505 return;
506 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700507 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700508
509 if (!is_broadcast_ether_addr(dst) && auth->waiting_auth_resp &&
510 result == OFFCHANNEL_SEND_ACTION_SUCCESS) {
511 /* Allow timeout handling to stop iteration if no response is
512 * received from a peer that has ACKed a request. */
513 auth->auth_req_ack = 1;
514 }
515
516 if (!wpa_s->dpp_auth_ok_on_ack && wpa_s->dpp_auth->neg_freq > 0 &&
517 wpa_s->dpp_auth->curr_freq != wpa_s->dpp_auth->neg_freq) {
518 wpa_printf(MSG_DEBUG,
519 "DPP: Move from curr_freq %u MHz to neg_freq %u MHz for response",
520 wpa_s->dpp_auth->curr_freq,
521 wpa_s->dpp_auth->neg_freq);
522 offchannel_send_action_done(wpa_s);
523 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->neg_freq);
524 }
525
526 if (wpa_s->dpp_auth_ok_on_ack)
527 wpa_s->dpp_auth_ok_on_ack = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700528}
529
530
531static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx)
532{
533 struct wpa_supplicant *wpa_s = eloop_ctx;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700534 struct dpp_authentication *auth = wpa_s->dpp_auth;
535 unsigned int freq;
536 struct os_reltime now, diff;
537 unsigned int wait_time, diff_ms;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700538
Roshan Pius3a1667e2018-07-03 15:17:14 -0700539 if (!auth || !auth->waiting_auth_resp)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700540 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700541
542 wait_time = wpa_s->dpp_resp_wait_time ?
543 wpa_s->dpp_resp_wait_time : 2000;
544 os_get_reltime(&now);
545 os_reltime_sub(&now, &wpa_s->dpp_last_init, &diff);
546 diff_ms = diff.sec * 1000 + diff.usec / 1000;
547 wpa_printf(MSG_DEBUG,
548 "DPP: Reply wait timeout - wait_time=%u diff_ms=%u",
549 wait_time, diff_ms);
550
551 if (auth->auth_req_ack && diff_ms >= wait_time) {
552 /* Peer ACK'ed Authentication Request frame, but did not reply
553 * with Authentication Response frame within two seconds. */
554 wpa_printf(MSG_INFO,
555 "DPP: No response received from responder - stopping initiation attempt");
556 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -0800557 wpas_notify_dpp_timeout(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700558 offchannel_send_action_done(wpa_s);
559 wpas_dpp_listen_stop(wpa_s);
560 dpp_auth_deinit(auth);
561 wpa_s->dpp_auth = NULL;
562 return;
563 }
564
565 if (diff_ms >= wait_time) {
566 /* Authentication Request frame was not ACK'ed and no reply
567 * was receiving within two seconds. */
568 wpa_printf(MSG_DEBUG,
569 "DPP: Continue Initiator channel iteration");
570 offchannel_send_action_done(wpa_s);
571 wpas_dpp_listen_stop(wpa_s);
572 wpas_dpp_auth_init_next(wpa_s);
573 return;
574 }
575
576 /* Driver did not support 2000 ms long wait_time with TX command, so
577 * schedule listen operation to continue waiting for the response.
578 *
579 * DPP listen operations continue until stopped, so simply schedule a
580 * new call to this function at the point when the two second reply
581 * wait has expired. */
582 wait_time -= diff_ms;
583
584 freq = auth->curr_freq;
585 if (auth->neg_freq > 0)
586 freq = auth->neg_freq;
587 wpa_printf(MSG_DEBUG,
588 "DPP: Continue reply wait on channel %u MHz for %u ms",
589 freq, wait_time);
590 wpa_s->dpp_in_response_listen = 1;
591 wpas_dpp_listen_start(wpa_s, freq);
592
593 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
594 wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700595}
596
597
598static void wpas_dpp_set_testing_options(struct wpa_supplicant *wpa_s,
599 struct dpp_authentication *auth)
600{
601#ifdef CONFIG_TESTING_OPTIONS
602 if (wpa_s->dpp_config_obj_override)
603 auth->config_obj_override =
604 os_strdup(wpa_s->dpp_config_obj_override);
605 if (wpa_s->dpp_discovery_override)
606 auth->discovery_override =
607 os_strdup(wpa_s->dpp_discovery_override);
608 if (wpa_s->dpp_groups_override)
609 auth->groups_override =
610 os_strdup(wpa_s->dpp_groups_override);
611 auth->ignore_netaccesskey_mismatch =
612 wpa_s->dpp_ignore_netaccesskey_mismatch;
613#endif /* CONFIG_TESTING_OPTIONS */
614}
615
616
Roshan Pius3a1667e2018-07-03 15:17:14 -0700617static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx)
618{
619 struct wpa_supplicant *wpa_s = eloop_ctx;
620
621 if (!wpa_s->dpp_auth)
622 return;
623 wpa_printf(MSG_DEBUG, "DPP: Retry initiation after timeout");
624 wpas_dpp_auth_init_next(wpa_s);
625}
626
627
628static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s)
629{
630 struct dpp_authentication *auth = wpa_s->dpp_auth;
631 const u8 *dst;
632 unsigned int wait_time, max_wait_time, freq, max_tries, used;
633 struct os_reltime now, diff;
634
635 wpa_s->dpp_in_response_listen = 0;
636 if (!auth)
637 return -1;
638
639 if (auth->freq_idx == 0)
640 os_get_reltime(&wpa_s->dpp_init_iter_start);
641
642 if (auth->freq_idx >= auth->num_freq) {
643 auth->num_freq_iters++;
644 if (wpa_s->dpp_init_max_tries)
645 max_tries = wpa_s->dpp_init_max_tries;
646 else
647 max_tries = 5;
648 if (auth->num_freq_iters >= max_tries || auth->auth_req_ack) {
649 wpa_printf(MSG_INFO,
650 "DPP: No response received from responder - stopping initiation attempt");
651 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -0800652 wpas_notify_dpp_timeout(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700653 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout,
654 wpa_s, NULL);
655 offchannel_send_action_done(wpa_s);
656 dpp_auth_deinit(wpa_s->dpp_auth);
657 wpa_s->dpp_auth = NULL;
658 return -1;
659 }
660 auth->freq_idx = 0;
661 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
662 if (wpa_s->dpp_init_retry_time)
663 wait_time = wpa_s->dpp_init_retry_time;
664 else
665 wait_time = 10000;
666 os_get_reltime(&now);
667 os_reltime_sub(&now, &wpa_s->dpp_init_iter_start, &diff);
668 used = diff.sec * 1000 + diff.usec / 1000;
669 if (used > wait_time)
670 wait_time = 0;
671 else
672 wait_time -= used;
673 wpa_printf(MSG_DEBUG, "DPP: Next init attempt in %u ms",
674 wait_time);
675 eloop_register_timeout(wait_time / 1000,
676 (wait_time % 1000) * 1000,
677 wpas_dpp_init_timeout, wpa_s,
678 NULL);
679 return 0;
680 }
681 freq = auth->freq[auth->freq_idx++];
682 auth->curr_freq = freq;
683
684 if (is_zero_ether_addr(auth->peer_bi->mac_addr))
685 dst = broadcast;
686 else
687 dst = auth->peer_bi->mac_addr;
688 wpa_s->dpp_auth_ok_on_ack = 0;
689 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
690 wait_time = wpa_s->max_remain_on_chan;
691 max_wait_time = wpa_s->dpp_resp_wait_time ?
692 wpa_s->dpp_resp_wait_time : 2000;
693 if (wait_time > max_wait_time)
694 wait_time = max_wait_time;
695 wait_time += 10; /* give the driver some extra time to complete */
696 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
697 wpas_dpp_reply_wait_timeout,
698 wpa_s, NULL);
699 wait_time -= 10;
700 if (auth->neg_freq > 0 && freq != auth->neg_freq) {
701 wpa_printf(MSG_DEBUG,
702 "DPP: Initiate on %u MHz and move to neg_freq %u MHz for response",
703 freq, auth->neg_freq);
704 }
705 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
706 MAC2STR(dst), freq, DPP_PA_AUTHENTICATION_REQ);
707 auth->auth_req_ack = 0;
708 os_get_reltime(&wpa_s->dpp_last_init);
709 return offchannel_send_action(wpa_s, freq, dst,
710 wpa_s->own_addr, broadcast,
711 wpabuf_head(auth->req_msg),
712 wpabuf_len(auth->req_msg),
713 wait_time, wpas_dpp_tx_status, 0);
714}
715
716
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700717int wpas_dpp_auth_init(struct wpa_supplicant *wpa_s, const char *cmd)
718{
719 const char *pos;
720 struct dpp_bootstrap_info *peer_bi, *own_bi = NULL;
Hai Shalom81f62d82019-07-22 12:10:00 -0700721 struct dpp_authentication *auth;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700722 u8 allowed_roles = DPP_CAPAB_CONFIGURATOR;
723 unsigned int neg_freq = 0;
Hai Shalom81f62d82019-07-22 12:10:00 -0700724 int tcp = 0;
725#ifdef CONFIG_DPP2
726 int tcp_port = DPP_TCP_PORT;
727 struct hostapd_ip_addr ipaddr;
728 char *addr;
729#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700730
731 wpa_s->dpp_gas_client = 0;
732
733 pos = os_strstr(cmd, " peer=");
734 if (!pos)
735 return -1;
736 pos += 6;
Hai Shalom021b0b52019-04-10 11:17:58 -0700737 peer_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700738 if (!peer_bi) {
739 wpa_printf(MSG_INFO,
740 "DPP: Could not find bootstrapping info for the identified peer");
741 return -1;
742 }
743
Hai Shalom81f62d82019-07-22 12:10:00 -0700744#ifdef CONFIG_DPP2
745 pos = os_strstr(cmd, " tcp_port=");
746 if (pos) {
747 pos += 10;
748 tcp_port = atoi(pos);
749 }
750
751 addr = get_param(cmd, " tcp_addr=");
752 if (addr) {
753 int res;
754
755 res = hostapd_parse_ip_addr(addr, &ipaddr);
756 os_free(addr);
757 if (res)
758 return -1;
759 tcp = 1;
760 }
761#endif /* CONFIG_DPP2 */
762
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700763 pos = os_strstr(cmd, " own=");
764 if (pos) {
765 pos += 5;
Hai Shalom021b0b52019-04-10 11:17:58 -0700766 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700767 if (!own_bi) {
768 wpa_printf(MSG_INFO,
769 "DPP: Could not find bootstrapping info for the identified local entry");
770 return -1;
771 }
772
773 if (peer_bi->curve != own_bi->curve) {
774 wpa_printf(MSG_INFO,
775 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
776 peer_bi->curve->name, own_bi->curve->name);
777 return -1;
778 }
779 }
780
781 pos = os_strstr(cmd, " role=");
782 if (pos) {
783 pos += 6;
784 if (os_strncmp(pos, "configurator", 12) == 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700785 allowed_roles = DPP_CAPAB_CONFIGURATOR;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700786 else if (os_strncmp(pos, "enrollee", 8) == 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700787 allowed_roles = DPP_CAPAB_ENROLLEE;
788 else if (os_strncmp(pos, "either", 6) == 0)
789 allowed_roles = DPP_CAPAB_CONFIGURATOR |
790 DPP_CAPAB_ENROLLEE;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700791 else
792 goto fail;
793 }
794
795 pos = os_strstr(cmd, " netrole=");
796 if (pos) {
797 pos += 9;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800798 if (os_strncmp(pos, "ap", 2) == 0)
799 wpa_s->dpp_netrole = DPP_NETROLE_AP;
800 else if (os_strncmp(pos, "configurator", 12) == 0)
801 wpa_s->dpp_netrole = DPP_NETROLE_CONFIGURATOR;
802 else
803 wpa_s->dpp_netrole = DPP_NETROLE_STA;
Hai Shalomfdcde762020-04-02 11:19:20 -0700804 } else {
805 wpa_s->dpp_netrole = DPP_NETROLE_STA;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700806 }
807
Roshan Pius3a1667e2018-07-03 15:17:14 -0700808 pos = os_strstr(cmd, " neg_freq=");
809 if (pos)
810 neg_freq = atoi(pos + 10);
811
Hai Shalom81f62d82019-07-22 12:10:00 -0700812 if (!tcp && wpa_s->dpp_auth) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700813 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700814 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700815 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
816 NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700817#ifdef CONFIG_DPP2
818 eloop_cancel_timeout(wpas_dpp_reconfig_reply_wait_timeout,
819 wpa_s, NULL);
820#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700821 offchannel_send_action_done(wpa_s);
822 dpp_auth_deinit(wpa_s->dpp_auth);
Hai Shalom74f70d42019-02-11 14:42:39 -0800823 wpa_s->dpp_auth = NULL;
Hai Shalom81f62d82019-07-22 12:10:00 -0700824 }
825
Hai Shalomfdcde762020-04-02 11:19:20 -0700826 auth = dpp_auth_init(wpa_s->dpp, wpa_s, peer_bi, own_bi, allowed_roles,
827 neg_freq, wpa_s->hw.modes, wpa_s->hw.num_modes);
Hai Shalom81f62d82019-07-22 12:10:00 -0700828 if (!auth)
829 goto fail;
830 wpas_dpp_set_testing_options(wpa_s, auth);
Hai Shalomfdcde762020-04-02 11:19:20 -0700831 if (dpp_set_configurator(auth, cmd) < 0) {
Hai Shalom81f62d82019-07-22 12:10:00 -0700832 dpp_auth_deinit(auth);
Hai Shalom74f70d42019-02-11 14:42:39 -0800833 goto fail;
834 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700835
Hai Shalom81f62d82019-07-22 12:10:00 -0700836 auth->neg_freq = neg_freq;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700837
Roshan Pius3a1667e2018-07-03 15:17:14 -0700838 if (!is_zero_ether_addr(peer_bi->mac_addr))
Hai Shalom81f62d82019-07-22 12:10:00 -0700839 os_memcpy(auth->peer_mac_addr, peer_bi->mac_addr, ETH_ALEN);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700840
Hai Shalom81f62d82019-07-22 12:10:00 -0700841#ifdef CONFIG_DPP2
842 if (tcp)
Hai Shalom899fcc72020-10-19 14:38:18 -0700843 return dpp_tcp_init(wpa_s->dpp, auth, &ipaddr, tcp_port,
844 wpa_s->conf->dpp_name, DPP_NETROLE_STA,
845 wpa_s, wpa_s, wpas_dpp_process_conf_obj);
Hai Shalom81f62d82019-07-22 12:10:00 -0700846#endif /* CONFIG_DPP2 */
847
848 wpa_s->dpp_auth = auth;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700849 return wpas_dpp_auth_init_next(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700850fail:
851 return -1;
852}
853
854
855struct wpas_dpp_listen_work {
856 unsigned int freq;
857 unsigned int duration;
858 struct wpabuf *probe_resp_ie;
859};
860
861
862static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work *lwork)
863{
864 if (!lwork)
865 return;
866 os_free(lwork);
867}
868
869
870static void wpas_dpp_listen_work_done(struct wpa_supplicant *wpa_s)
871{
872 struct wpas_dpp_listen_work *lwork;
873
874 if (!wpa_s->dpp_listen_work)
875 return;
876
877 lwork = wpa_s->dpp_listen_work->ctx;
878 wpas_dpp_listen_work_free(lwork);
879 radio_work_done(wpa_s->dpp_listen_work);
880 wpa_s->dpp_listen_work = NULL;
881}
882
883
884static void dpp_start_listen_cb(struct wpa_radio_work *work, int deinit)
885{
886 struct wpa_supplicant *wpa_s = work->wpa_s;
887 struct wpas_dpp_listen_work *lwork = work->ctx;
888
889 if (deinit) {
890 if (work->started) {
891 wpa_s->dpp_listen_work = NULL;
892 wpas_dpp_listen_stop(wpa_s);
893 }
894 wpas_dpp_listen_work_free(lwork);
895 return;
896 }
897
898 wpa_s->dpp_listen_work = work;
899
900 wpa_s->dpp_pending_listen_freq = lwork->freq;
901
902 if (wpa_drv_remain_on_channel(wpa_s, lwork->freq,
903 wpa_s->max_remain_on_chan) < 0) {
904 wpa_printf(MSG_DEBUG,
905 "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
906 lwork->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -0800907 wpa_s->dpp_listen_freq = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700908 wpas_dpp_listen_work_done(wpa_s);
909 wpa_s->dpp_pending_listen_freq = 0;
910 return;
911 }
912 wpa_s->off_channel_freq = 0;
913 wpa_s->roc_waiting_drv_freq = lwork->freq;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700914 wpa_drv_dpp_listen(wpa_s, true);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700915}
916
917
918static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
919 unsigned int freq)
920{
921 struct wpas_dpp_listen_work *lwork;
922
923 if (wpa_s->dpp_listen_work) {
924 wpa_printf(MSG_DEBUG,
925 "DPP: Reject start_listen since dpp_listen_work already exists");
926 return -1;
927 }
928
929 if (wpa_s->dpp_listen_freq)
930 wpas_dpp_listen_stop(wpa_s);
931 wpa_s->dpp_listen_freq = freq;
932
933 lwork = os_zalloc(sizeof(*lwork));
934 if (!lwork)
935 return -1;
936 lwork->freq = freq;
937
938 if (radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb,
939 lwork) < 0) {
940 wpas_dpp_listen_work_free(lwork);
941 return -1;
942 }
943
944 return 0;
945}
946
947
948int wpas_dpp_listen(struct wpa_supplicant *wpa_s, const char *cmd)
949{
950 int freq;
951
952 freq = atoi(cmd);
953 if (freq <= 0)
954 return -1;
955
956 if (os_strstr(cmd, " role=configurator"))
957 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR;
958 else if (os_strstr(cmd, " role=enrollee"))
959 wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
960 else
961 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
962 DPP_CAPAB_ENROLLEE;
963 wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800964 if (os_strstr(cmd, " netrole=ap"))
965 wpa_s->dpp_netrole = DPP_NETROLE_AP;
966 else if (os_strstr(cmd, " netrole=configurator"))
967 wpa_s->dpp_netrole = DPP_NETROLE_CONFIGURATOR;
968 else
969 wpa_s->dpp_netrole = DPP_NETROLE_STA;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700970 if (wpa_s->dpp_listen_freq == (unsigned int) freq) {
971 wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz",
972 freq);
973 return 0;
974 }
975
976 return wpas_dpp_listen_start(wpa_s, freq);
977}
978
979
980void wpas_dpp_listen_stop(struct wpa_supplicant *wpa_s)
981{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700982 wpa_s->dpp_in_response_listen = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700983 if (!wpa_s->dpp_listen_freq)
984 return;
985
986 wpa_printf(MSG_DEBUG, "DPP: Stop listen on %u MHz",
987 wpa_s->dpp_listen_freq);
988 wpa_drv_cancel_remain_on_channel(wpa_s);
Hai Shalomb755a2a2020-04-23 21:49:02 -0700989 wpa_drv_dpp_listen(wpa_s, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700990 wpa_s->dpp_listen_freq = 0;
991 wpas_dpp_listen_work_done(wpa_s);
992}
993
994
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700995void wpas_dpp_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
996 unsigned int freq, unsigned int duration)
997{
998 if (wpa_s->dpp_listen_freq != freq)
999 return;
1000
1001 wpa_printf(MSG_DEBUG,
1002 "DPP: Remain-on-channel started for listen on %u MHz for %u ms",
1003 freq, duration);
1004 os_get_reltime(&wpa_s->dpp_listen_end);
1005 wpa_s->dpp_listen_end.usec += duration * 1000;
1006 while (wpa_s->dpp_listen_end.usec >= 1000000) {
1007 wpa_s->dpp_listen_end.sec++;
1008 wpa_s->dpp_listen_end.usec -= 1000000;
1009 }
1010}
1011
1012
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001013void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
1014 unsigned int freq)
1015{
1016 wpas_dpp_listen_work_done(wpa_s);
1017
Roshan Pius3a1667e2018-07-03 15:17:14 -07001018 if (wpa_s->dpp_auth && wpa_s->dpp_in_response_listen) {
1019 unsigned int new_freq;
1020
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001021 /* Continue listen with a new remain-on-channel */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001022 if (wpa_s->dpp_auth->neg_freq > 0)
1023 new_freq = wpa_s->dpp_auth->neg_freq;
1024 else
1025 new_freq = wpa_s->dpp_auth->curr_freq;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001026 wpa_printf(MSG_DEBUG,
1027 "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
Roshan Pius3a1667e2018-07-03 15:17:14 -07001028 new_freq);
1029 wpas_dpp_listen_start(wpa_s, new_freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001030 return;
1031 }
1032
1033 if (wpa_s->dpp_listen_freq) {
1034 /* Continue listen with a new remain-on-channel */
1035 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_listen_freq);
1036 }
1037}
1038
1039
1040static void wpas_dpp_rx_auth_req(struct wpa_supplicant *wpa_s, const u8 *src,
1041 const u8 *hdr, const u8 *buf, size_t len,
1042 unsigned int freq)
1043{
Roshan Pius3a1667e2018-07-03 15:17:14 -07001044 const u8 *r_bootstrap, *i_bootstrap;
1045 u16 r_bootstrap_len, i_bootstrap_len;
Hai Shalom021b0b52019-04-10 11:17:58 -07001046 struct dpp_bootstrap_info *own_bi = NULL, *peer_bi = NULL;
1047
1048 if (!wpa_s->dpp)
1049 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001050
1051 wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR,
1052 MAC2STR(src));
1053
Hai Shalomfdcde762020-04-02 11:19:20 -07001054#ifdef CONFIG_DPP2
1055 wpas_dpp_chirp_stop(wpa_s);
1056#endif /* CONFIG_DPP2 */
1057
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001058 r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
1059 &r_bootstrap_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001060 if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
1061 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1062 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001063 return;
1064 }
1065 wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
1066 r_bootstrap, r_bootstrap_len);
1067
1068 i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH,
1069 &i_bootstrap_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001070 if (!i_bootstrap || i_bootstrap_len != SHA256_MAC_LEN) {
1071 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1072 "Missing or invalid required Initiator Bootstrapping Key Hash attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001073 return;
1074 }
1075 wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash",
1076 i_bootstrap, i_bootstrap_len);
1077
1078 /* Try to find own and peer bootstrapping key matches based on the
1079 * received hash values */
Hai Shalom021b0b52019-04-10 11:17:58 -07001080 dpp_bootstrap_find_pair(wpa_s->dpp, i_bootstrap, r_bootstrap,
1081 &own_bi, &peer_bi);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001082 if (!own_bi) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001083 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1084 "No matching own bootstrapping key found - ignore message");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001085 return;
1086 }
1087
1088 if (wpa_s->dpp_auth) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001089 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1090 "Already in DPP authentication exchange - ignore new one");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001091 return;
1092 }
1093
1094 wpa_s->dpp_gas_client = 0;
1095 wpa_s->dpp_auth_ok_on_ack = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07001096 wpa_s->dpp_auth = dpp_auth_req_rx(wpa_s->dpp, wpa_s,
1097 wpa_s->dpp_allowed_roles,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001098 wpa_s->dpp_qr_mutual,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001099 peer_bi, own_bi, freq, hdr, buf, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001100 if (!wpa_s->dpp_auth) {
1101 wpa_printf(MSG_DEBUG, "DPP: No response generated");
1102 return;
1103 }
1104 wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
Hai Shalomfdcde762020-04-02 11:19:20 -07001105 if (dpp_set_configurator(wpa_s->dpp_auth,
Hai Shalom021b0b52019-04-10 11:17:58 -07001106 wpa_s->dpp_configurator_params) < 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08001107 dpp_auth_deinit(wpa_s->dpp_auth);
1108 wpa_s->dpp_auth = NULL;
1109 return;
1110 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001111 os_memcpy(wpa_s->dpp_auth->peer_mac_addr, src, ETH_ALEN);
1112
Roshan Pius3a1667e2018-07-03 15:17:14 -07001113 if (wpa_s->dpp_listen_freq &&
1114 wpa_s->dpp_listen_freq != wpa_s->dpp_auth->curr_freq) {
1115 wpa_printf(MSG_DEBUG,
1116 "DPP: Stop listen on %u MHz to allow response on the request %u MHz",
1117 wpa_s->dpp_listen_freq, wpa_s->dpp_auth->curr_freq);
1118 wpas_dpp_listen_stop(wpa_s);
1119 }
1120
1121 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1122 MAC2STR(src), wpa_s->dpp_auth->curr_freq,
1123 DPP_PA_AUTHENTICATION_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001124 offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq,
1125 src, wpa_s->own_addr, broadcast,
1126 wpabuf_head(wpa_s->dpp_auth->resp_msg),
1127 wpabuf_len(wpa_s->dpp_auth->resp_msg),
1128 500, wpas_dpp_tx_status, 0);
1129}
1130
1131
1132static void wpas_dpp_start_gas_server(struct wpa_supplicant *wpa_s)
1133{
1134 /* TODO: stop wait and start ROC */
1135}
1136
1137
1138static struct wpa_ssid * wpas_dpp_add_network(struct wpa_supplicant *wpa_s,
Hai Shalomc3565922019-10-28 11:58:20 -07001139 struct dpp_authentication *auth,
1140 struct dpp_config_obj *conf)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001141{
1142 struct wpa_ssid *ssid;
1143
Hai Shalom021b0b52019-04-10 11:17:58 -07001144#ifdef CONFIG_DPP2
Hai Shalomc3565922019-10-28 11:58:20 -07001145 if (conf->akm == DPP_AKM_SAE) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001146#ifdef CONFIG_SAE
1147 struct wpa_driver_capa capa;
1148 int res;
1149
1150 res = wpa_drv_get_capa(wpa_s, &capa);
1151 if (res == 0 &&
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001152 !(capa.key_mgmt_iftype[WPA_IF_STATION] &
1153 WPA_DRIVER_CAPA_KEY_MGMT_SAE) &&
Hai Shalom021b0b52019-04-10 11:17:58 -07001154 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
1155 wpa_printf(MSG_DEBUG,
1156 "DPP: SAE not supported by the driver");
1157 return NULL;
1158 }
1159#else /* CONFIG_SAE */
1160 wpa_printf(MSG_DEBUG, "DPP: SAE not supported in the build");
1161 return NULL;
1162#endif /* CONFIG_SAE */
1163 }
1164#endif /* CONFIG_DPP2 */
1165
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001166 ssid = wpa_config_add_network(wpa_s->conf);
1167 if (!ssid)
1168 return NULL;
1169 wpas_notify_network_added(wpa_s, ssid);
1170 wpa_config_set_network_defaults(ssid);
1171 ssid->disabled = 1;
1172
Hai Shalomc3565922019-10-28 11:58:20 -07001173 ssid->ssid = os_malloc(conf->ssid_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001174 if (!ssid->ssid)
1175 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07001176 os_memcpy(ssid->ssid, conf->ssid, conf->ssid_len);
1177 ssid->ssid_len = conf->ssid_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001178
Hai Shalomc3565922019-10-28 11:58:20 -07001179 if (conf->connector) {
Hai Shalomfdcde762020-04-02 11:19:20 -07001180 if (dpp_akm_dpp(conf->akm)) {
1181 ssid->key_mgmt = WPA_KEY_MGMT_DPP;
1182 ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED;
1183 }
Hai Shalomc3565922019-10-28 11:58:20 -07001184 ssid->dpp_connector = os_strdup(conf->connector);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001185 if (!ssid->dpp_connector)
1186 goto fail;
1187 }
1188
Hai Shalomc3565922019-10-28 11:58:20 -07001189 if (conf->c_sign_key) {
1190 ssid->dpp_csign = os_malloc(wpabuf_len(conf->c_sign_key));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001191 if (!ssid->dpp_csign)
1192 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07001193 os_memcpy(ssid->dpp_csign, wpabuf_head(conf->c_sign_key),
1194 wpabuf_len(conf->c_sign_key));
1195 ssid->dpp_csign_len = wpabuf_len(conf->c_sign_key);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001196 }
1197
Hai Shalom899fcc72020-10-19 14:38:18 -07001198 if (conf->pp_key) {
1199 ssid->dpp_pp_key = os_malloc(wpabuf_len(conf->pp_key));
1200 if (!ssid->dpp_pp_key)
1201 goto fail;
1202 os_memcpy(ssid->dpp_pp_key, wpabuf_head(conf->pp_key),
1203 wpabuf_len(conf->pp_key));
1204 ssid->dpp_pp_key_len = wpabuf_len(conf->pp_key);
1205 }
1206
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001207 if (auth->net_access_key) {
1208 ssid->dpp_netaccesskey =
1209 os_malloc(wpabuf_len(auth->net_access_key));
1210 if (!ssid->dpp_netaccesskey)
1211 goto fail;
1212 os_memcpy(ssid->dpp_netaccesskey,
1213 wpabuf_head(auth->net_access_key),
1214 wpabuf_len(auth->net_access_key));
1215 ssid->dpp_netaccesskey_len = wpabuf_len(auth->net_access_key);
1216 ssid->dpp_netaccesskey_expiry = auth->net_access_key_expiry;
1217 }
1218
Hai Shalomc3565922019-10-28 11:58:20 -07001219 if (!conf->connector || dpp_akm_psk(conf->akm) ||
1220 dpp_akm_sae(conf->akm)) {
Hai Shalomfdcde762020-04-02 11:19:20 -07001221 if (!conf->connector || !dpp_akm_dpp(conf->akm))
Hai Shalom021b0b52019-04-10 11:17:58 -07001222 ssid->key_mgmt = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07001223 if (dpp_akm_psk(conf->akm))
Roshan Pius3a1667e2018-07-03 15:17:14 -07001224 ssid->key_mgmt |= WPA_KEY_MGMT_PSK |
1225 WPA_KEY_MGMT_PSK_SHA256 | WPA_KEY_MGMT_FT_PSK;
Hai Shalomc3565922019-10-28 11:58:20 -07001226 if (dpp_akm_sae(conf->akm))
Roshan Pius3a1667e2018-07-03 15:17:14 -07001227 ssid->key_mgmt |= WPA_KEY_MGMT_SAE |
1228 WPA_KEY_MGMT_FT_SAE;
1229 ssid->ieee80211w = MGMT_FRAME_PROTECTION_OPTIONAL;
Hai Shalomc3565922019-10-28 11:58:20 -07001230 if (conf->passphrase[0]) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001231 if (wpa_config_set_quoted(ssid, "psk",
Hai Shalomc3565922019-10-28 11:58:20 -07001232 conf->passphrase) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001233 goto fail;
1234 wpa_config_update_psk(ssid);
1235 ssid->export_keys = 1;
1236 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07001237 ssid->psk_set = conf->psk_set;
1238 os_memcpy(ssid->psk, conf->psk, PMK_LEN);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001239 }
1240 }
1241
Hai Shalom899fcc72020-10-19 14:38:18 -07001242#if defined(CONFIG_DPP2) && defined(IEEE8021X_EAPOL)
1243 if (conf->akm == DPP_AKM_DOT1X) {
1244 int i;
1245 char name[100], blobname[128];
1246 struct wpa_config_blob *blob;
1247
1248 ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X |
1249 WPA_KEY_MGMT_IEEE8021X_SHA256 |
1250 WPA_KEY_MGMT_IEEE8021X_SHA256;
1251 ssid->ieee80211w = MGMT_FRAME_PROTECTION_OPTIONAL;
1252
1253 if (conf->cacert) {
1254 /* caCert is DER-encoded X.509v3 certificate for the
1255 * server certificate if that is different from the
1256 * trust root included in certBag. */
1257 /* TODO: ssid->eap.cert.ca_cert */
1258 }
1259
1260 if (conf->certs) {
1261 for (i = 0; ; i++) {
1262 os_snprintf(name, sizeof(name), "dpp-certs-%d",
1263 i);
1264 if (!wpa_config_get_blob(wpa_s->conf, name))
1265 break;
1266 }
1267
1268 blob = os_zalloc(sizeof(*blob));
1269 if (!blob)
1270 goto fail;
1271 blob->len = wpabuf_len(conf->certs);
1272 blob->name = os_strdup(name);
1273 blob->data = os_malloc(blob->len);
1274 if (!blob->name || !blob->data) {
1275 wpa_config_free_blob(blob);
1276 goto fail;
1277 }
1278 os_memcpy(blob->data, wpabuf_head(conf->certs),
1279 blob->len);
1280 os_snprintf(blobname, sizeof(blobname), "blob://%s",
1281 name);
1282 wpa_config_set_blob(wpa_s->conf, blob);
1283 wpa_printf(MSG_DEBUG, "DPP: Added certificate blob %s",
1284 name);
1285 ssid->eap.cert.client_cert = os_strdup(blobname);
1286 if (!ssid->eap.cert.client_cert)
1287 goto fail;
1288
1289 /* TODO: ssid->eap.identity from own certificate */
1290 if (wpa_config_set(ssid, "identity", "\"dpp-ent\"",
1291 0) < 0)
1292 goto fail;
1293 }
1294
1295 if (auth->priv_key) {
1296 for (i = 0; ; i++) {
1297 os_snprintf(name, sizeof(name), "dpp-key-%d",
1298 i);
1299 if (!wpa_config_get_blob(wpa_s->conf, name))
1300 break;
1301 }
1302
1303 blob = os_zalloc(sizeof(*blob));
1304 if (!blob)
1305 goto fail;
1306 blob->len = wpabuf_len(auth->priv_key);
1307 blob->name = os_strdup(name);
1308 blob->data = os_malloc(blob->len);
1309 if (!blob->name || !blob->data) {
1310 wpa_config_free_blob(blob);
1311 goto fail;
1312 }
1313 os_memcpy(blob->data, wpabuf_head(auth->priv_key),
1314 blob->len);
1315 os_snprintf(blobname, sizeof(blobname), "blob://%s",
1316 name);
1317 wpa_config_set_blob(wpa_s->conf, blob);
1318 wpa_printf(MSG_DEBUG, "DPP: Added private key blob %s",
1319 name);
1320 ssid->eap.cert.private_key = os_strdup(blobname);
1321 if (!ssid->eap.cert.private_key)
1322 goto fail;
1323 }
1324
1325 if (conf->server_name) {
1326 ssid->eap.cert.domain_suffix_match =
1327 os_strdup(conf->server_name);
1328 if (!ssid->eap.cert.domain_suffix_match)
1329 goto fail;
1330 }
1331
1332 /* TODO: Use entCreds::eapMethods */
1333 if (wpa_config_set(ssid, "eap", "TLS", 0) < 0)
1334 goto fail;
1335 }
1336#endif /* CONFIG_DPP2 && IEEE8021X_EAPOL */
1337
Hai Shalomc3565922019-10-28 11:58:20 -07001338 os_memcpy(wpa_s->dpp_last_ssid, conf->ssid, conf->ssid_len);
1339 wpa_s->dpp_last_ssid_len = conf->ssid_len;
1340
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001341 return ssid;
1342fail:
1343 wpas_notify_network_removed(wpa_s, ssid);
1344 wpa_config_remove_network(wpa_s->conf, ssid->id);
1345 return NULL;
1346}
1347
1348
Hai Shalom021b0b52019-04-10 11:17:58 -07001349static int wpas_dpp_process_config(struct wpa_supplicant *wpa_s,
Hai Shalomc3565922019-10-28 11:58:20 -07001350 struct dpp_authentication *auth,
1351 struct dpp_config_obj *conf)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001352{
1353 struct wpa_ssid *ssid;
1354
1355 if (wpa_s->conf->dpp_config_processing < 1)
Hai Shalom021b0b52019-04-10 11:17:58 -07001356 return 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001357
Hai Shalomc3565922019-10-28 11:58:20 -07001358 ssid = wpas_dpp_add_network(wpa_s, auth, conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001359 if (!ssid)
Hai Shalom021b0b52019-04-10 11:17:58 -07001360 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001361
1362 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_NETWORK_ID "%d", ssid->id);
Hai Shalom59532852018-12-07 10:32:58 -08001363
Hai Shalom706f99b2019-01-08 16:23:37 -08001364 wpas_notify_dpp_config_received(wpa_s, ssid);
Hai Shalom59532852018-12-07 10:32:58 -08001365
Hai Shalom021b0b52019-04-10 11:17:58 -07001366 if (wpa_s->conf->dpp_config_processing == 2)
1367 ssid->disabled = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001368
Hai Shalom021b0b52019-04-10 11:17:58 -07001369#ifndef CONFIG_NO_CONFIG_WRITE
1370 if (wpa_s->conf->update_config &&
1371 wpa_config_write(wpa_s->confname, wpa_s->conf))
1372 wpa_printf(MSG_DEBUG, "DPP: Failed to update configuration");
1373#endif /* CONFIG_NO_CONFIG_WRITE */
1374
Hai Shalomc3565922019-10-28 11:58:20 -07001375 return 0;
1376}
1377
1378
1379static void wpas_dpp_post_process_config(struct wpa_supplicant *wpa_s,
1380 struct dpp_authentication *auth)
1381{
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001382#ifdef CONFIG_DPP2
1383 if (auth->reconfig && wpa_s->dpp_reconfig_ssid &&
1384 wpa_config_get_network(wpa_s->conf, wpa_s->dpp_reconfig_ssid_id) ==
1385 wpa_s->dpp_reconfig_ssid) {
1386 wpa_printf(MSG_DEBUG,
1387 "DPP: Remove reconfigured network profile");
1388 wpas_notify_network_removed(wpa_s, wpa_s->dpp_reconfig_ssid);
1389 wpa_config_remove_network(wpa_s->conf,
1390 wpa_s->dpp_reconfig_ssid_id);
1391 wpa_s->dpp_reconfig_ssid = NULL;
1392 wpa_s->dpp_reconfig_ssid_id = -1;
1393 }
1394#endif /* CONFIG_DPP2 */
1395
Hai Shalom021b0b52019-04-10 11:17:58 -07001396 if (wpa_s->conf->dpp_config_processing < 2)
Hai Shalomc3565922019-10-28 11:58:20 -07001397 return;
Hai Shalom021b0b52019-04-10 11:17:58 -07001398
1399#ifdef CONFIG_DPP2
1400 if (auth->peer_version >= 2) {
1401 wpa_printf(MSG_DEBUG,
1402 "DPP: Postpone connection attempt to wait for completion of DPP Configuration Result");
1403 auth->connect_on_tx_status = 1;
Hai Shalomc3565922019-10-28 11:58:20 -07001404 return;
Hai Shalom021b0b52019-04-10 11:17:58 -07001405 }
1406#endif /* CONFIG_DPP2 */
1407
1408 wpas_dpp_try_to_connect(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001409}
1410
1411
Hai Shalom021b0b52019-04-10 11:17:58 -07001412static int wpas_dpp_handle_config_obj(struct wpa_supplicant *wpa_s,
Hai Shalomc3565922019-10-28 11:58:20 -07001413 struct dpp_authentication *auth,
1414 struct dpp_config_obj *conf)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001415{
1416 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
Hai Shalomc3565922019-10-28 11:58:20 -07001417 if (conf->ssid_len)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001418 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s",
Hai Shalomc3565922019-10-28 11:58:20 -07001419 wpa_ssid_txt(conf->ssid, conf->ssid_len));
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001420 if (conf->ssid_charset)
1421 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID_CHARSET "%d",
1422 conf->ssid_charset);
Hai Shalomc3565922019-10-28 11:58:20 -07001423 if (conf->connector) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001424 /* TODO: Save the Connector and consider using a command
1425 * to fetch the value instead of sending an event with
1426 * it. The Connector could end up being larger than what
1427 * most clients are ready to receive as an event
1428 * message. */
1429 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONNECTOR "%s",
Hai Shalomc3565922019-10-28 11:58:20 -07001430 conf->connector);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001431 }
Hai Shalomc3565922019-10-28 11:58:20 -07001432 if (conf->c_sign_key) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001433 char *hex;
1434 size_t hexlen;
1435
Hai Shalomc3565922019-10-28 11:58:20 -07001436 hexlen = 2 * wpabuf_len(conf->c_sign_key) + 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001437 hex = os_malloc(hexlen);
1438 if (hex) {
1439 wpa_snprintf_hex(hex, hexlen,
Hai Shalomc3565922019-10-28 11:58:20 -07001440 wpabuf_head(conf->c_sign_key),
1441 wpabuf_len(conf->c_sign_key));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001442 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_C_SIGN_KEY "%s",
1443 hex);
1444 os_free(hex);
1445 }
1446 }
Hai Shalom899fcc72020-10-19 14:38:18 -07001447 if (conf->pp_key) {
1448 char *hex;
1449 size_t hexlen;
1450
1451 hexlen = 2 * wpabuf_len(conf->pp_key) + 1;
1452 hex = os_malloc(hexlen);
1453 if (hex) {
1454 wpa_snprintf_hex(hex, hexlen,
1455 wpabuf_head(conf->pp_key),
1456 wpabuf_len(conf->pp_key));
1457 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_PP_KEY "%s", hex);
1458 os_free(hex);
1459 }
1460 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001461 if (auth->net_access_key) {
1462 char *hex;
1463 size_t hexlen;
1464
1465 hexlen = 2 * wpabuf_len(auth->net_access_key) + 1;
1466 hex = os_malloc(hexlen);
1467 if (hex) {
1468 wpa_snprintf_hex(hex, hexlen,
1469 wpabuf_head(auth->net_access_key),
1470 wpabuf_len(auth->net_access_key));
1471 if (auth->net_access_key_expiry)
1472 wpa_msg(wpa_s, MSG_INFO,
1473 DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex,
1474 (long unsigned)
1475 auth->net_access_key_expiry);
1476 else
1477 wpa_msg(wpa_s, MSG_INFO,
1478 DPP_EVENT_NET_ACCESS_KEY "%s", hex);
1479 os_free(hex);
1480 }
1481 }
1482
Hai Shalom899fcc72020-10-19 14:38:18 -07001483#ifdef CONFIG_DPP2
1484 if (conf->certbag) {
1485 char *b64;
1486
1487 b64 = base64_encode_no_lf(wpabuf_head(conf->certbag),
1488 wpabuf_len(conf->certbag), NULL);
1489 if (b64)
1490 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CERTBAG "%s", b64);
1491 os_free(b64);
1492 }
1493
1494 if (conf->cacert) {
1495 char *b64;
1496
1497 b64 = base64_encode_no_lf(wpabuf_head(conf->cacert),
1498 wpabuf_len(conf->cacert), NULL);
1499 if (b64)
1500 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CACERT "%s", b64);
1501 os_free(b64);
1502 }
1503
1504 if (conf->server_name)
1505 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_SERVER_NAME "%s",
1506 conf->server_name);
1507#endif /* CONFIG_DPP2 */
1508
Hai Shalomc3565922019-10-28 11:58:20 -07001509 return wpas_dpp_process_config(wpa_s, auth, conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001510}
1511
1512
Hai Shalomfdcde762020-04-02 11:19:20 -07001513static int wpas_dpp_handle_key_pkg(struct wpa_supplicant *wpa_s,
1514 struct dpp_asymmetric_key *key)
1515{
1516#ifdef CONFIG_DPP2
1517 int res;
1518
1519 if (!key)
1520 return 0;
1521
1522 wpa_printf(MSG_DEBUG, "DPP: Received Configurator backup");
1523 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
Hai Shalom899fcc72020-10-19 14:38:18 -07001524 wpa_s->dpp_conf_backup_received = true;
Hai Shalomfdcde762020-04-02 11:19:20 -07001525
1526 while (key) {
1527 res = dpp_configurator_from_backup(wpa_s->dpp, key);
1528 if (res < 0)
1529 return -1;
1530 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFIGURATOR_ID "%d",
1531 res);
1532 key = key->next;
1533 }
1534#endif /* CONFIG_DPP2 */
1535
1536 return 0;
1537}
1538
1539
Hai Shalom899fcc72020-10-19 14:38:18 -07001540#ifdef CONFIG_DPP2
1541static void wpas_dpp_build_csr(void *eloop_ctx, void *timeout_ctx)
1542{
1543 struct wpa_supplicant *wpa_s = eloop_ctx;
1544 struct dpp_authentication *auth = wpa_s->dpp_auth;
1545
1546 if (!auth || !auth->csrattrs)
1547 return;
1548
1549 wpa_printf(MSG_DEBUG, "DPP: Build CSR");
1550 wpabuf_free(auth->csr);
1551 /* TODO: Additional information needed for CSR based on csrAttrs */
1552 auth->csr = dpp_build_csr(auth, wpa_s->conf->dpp_name ?
1553 wpa_s->conf->dpp_name : "Test");
1554 if (!auth->csr) {
1555 dpp_auth_deinit(wpa_s->dpp_auth);
1556 wpa_s->dpp_auth = NULL;
1557 return;
1558 }
1559
1560 wpas_dpp_start_gas_client(wpa_s);
1561}
1562#endif /* CONFIG_DPP2 */
1563
1564
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001565static void wpas_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token,
1566 enum gas_query_result result,
1567 const struct wpabuf *adv_proto,
1568 const struct wpabuf *resp, u16 status_code)
1569{
1570 struct wpa_supplicant *wpa_s = ctx;
1571 const u8 *pos;
1572 struct dpp_authentication *auth = wpa_s->dpp_auth;
Hai Shalom021b0b52019-04-10 11:17:58 -07001573 int res;
1574 enum dpp_status_error status = DPP_STATUS_CONFIG_REJECTED;
Hai Shalomc3565922019-10-28 11:58:20 -07001575 unsigned int i;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001576
Roshan Pius3a1667e2018-07-03 15:17:14 -07001577 wpa_s->dpp_gas_dialog_token = -1;
1578
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001579 if (!auth || (!auth->auth_success && !auth->reconfig_success) ||
1580 os_memcmp(addr, auth->peer_mac_addr, ETH_ALEN) != 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001581 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
1582 return;
1583 }
Hai Shalom74f70d42019-02-11 14:42:39 -08001584 if (result != GAS_QUERY_SUCCESS ||
1585 !resp || status_code != WLAN_STATUS_SUCCESS) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001586 wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed");
1587 goto fail;
1588 }
1589
1590 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto",
1591 adv_proto);
1592 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)",
1593 resp);
1594
1595 if (wpabuf_len(adv_proto) != 10 ||
1596 !(pos = wpabuf_head(adv_proto)) ||
1597 pos[0] != WLAN_EID_ADV_PROTO ||
1598 pos[1] != 8 ||
1599 pos[3] != WLAN_EID_VENDOR_SPECIFIC ||
1600 pos[4] != 5 ||
1601 WPA_GET_BE24(&pos[5]) != OUI_WFA ||
1602 pos[8] != 0x1a ||
1603 pos[9] != 1) {
1604 wpa_printf(MSG_DEBUG,
1605 "DPP: Not a DPP Advertisement Protocol ID");
1606 goto fail;
1607 }
1608
Hai Shalom899fcc72020-10-19 14:38:18 -07001609 res = dpp_conf_resp_rx(auth, resp);
1610#ifdef CONFIG_DPP2
1611 if (res == -2) {
1612 wpa_printf(MSG_DEBUG, "DPP: CSR needed");
1613 eloop_register_timeout(0, 0, wpas_dpp_build_csr, wpa_s, NULL);
1614 return;
1615 }
1616#endif /* CONFIG_DPP2 */
1617 if (res < 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001618 wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed");
1619 goto fail;
1620 }
1621
Hai Shalom899fcc72020-10-19 14:38:18 -07001622 wpa_s->dpp_conf_backup_received = false;
Hai Shalomc3565922019-10-28 11:58:20 -07001623 for (i = 0; i < auth->num_conf_obj; i++) {
1624 res = wpas_dpp_handle_config_obj(wpa_s, auth,
1625 &auth->conf_obj[i]);
1626 if (res < 0)
1627 goto fail;
1628 }
1629 if (auth->num_conf_obj)
1630 wpas_dpp_post_process_config(wpa_s, auth);
Hai Shalomfdcde762020-04-02 11:19:20 -07001631 if (wpas_dpp_handle_key_pkg(wpa_s, auth->conf_key_pkg) < 0)
1632 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001633
Hai Shalom021b0b52019-04-10 11:17:58 -07001634 status = DPP_STATUS_OK;
1635#ifdef CONFIG_TESTING_OPTIONS
1636 if (dpp_test == DPP_TEST_REJECT_CONFIG) {
1637 wpa_printf(MSG_INFO, "DPP: TESTING - Reject Config Object");
1638 status = DPP_STATUS_CONFIG_REJECTED;
1639 }
1640#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001641fail:
Hai Shalom021b0b52019-04-10 11:17:58 -07001642 if (status != DPP_STATUS_OK) {
1643 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1644 wpas_notify_dpp_configuration_failure(wpa_s);
1645 }
1646#ifdef CONFIG_DPP2
1647 if (auth->peer_version >= 2 &&
1648 auth->conf_resp_status == DPP_STATUS_OK) {
1649 struct wpabuf *msg;
1650
1651 wpa_printf(MSG_DEBUG, "DPP: Send DPP Configuration Result");
1652 msg = dpp_build_conf_result(auth, status);
1653 if (!msg)
1654 goto fail2;
1655
1656 wpa_msg(wpa_s, MSG_INFO,
1657 DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1658 MAC2STR(addr), auth->curr_freq,
1659 DPP_PA_CONFIGURATION_RESULT);
1660 offchannel_send_action(wpa_s, auth->curr_freq,
1661 addr, wpa_s->own_addr, broadcast,
1662 wpabuf_head(msg),
1663 wpabuf_len(msg),
1664 500, wpas_dpp_tx_status, 0);
1665 wpabuf_free(msg);
1666
1667 /* This exchange will be terminated in the TX status handler */
Hai Shalom899fcc72020-10-19 14:38:18 -07001668 if (wpa_s->conf->dpp_config_processing < 2 ||
1669 wpa_s->dpp_conf_backup_received)
1670 auth->remove_on_tx_status = 1;
Hai Shalom021b0b52019-04-10 11:17:58 -07001671 return;
1672 }
1673fail2:
1674#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001675 dpp_auth_deinit(wpa_s->dpp_auth);
1676 wpa_s->dpp_auth = NULL;
1677}
1678
1679
1680static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
1681{
1682 struct dpp_authentication *auth = wpa_s->dpp_auth;
Hai Shalom021b0b52019-04-10 11:17:58 -07001683 struct wpabuf *buf;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001684 int res;
Hai Shalomc3565922019-10-28 11:58:20 -07001685 int *supp_op_classes;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001686
1687 wpa_s->dpp_gas_client = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001688 offchannel_send_action_done(wpa_s);
1689 wpas_dpp_listen_stop(wpa_s);
1690
Hai Shalomc3565922019-10-28 11:58:20 -07001691 supp_op_classes = wpas_supp_op_classes(wpa_s);
1692 buf = dpp_build_conf_req_helper(auth, wpa_s->conf->dpp_name,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001693 wpa_s->dpp_netrole,
Hai Shalomc3565922019-10-28 11:58:20 -07001694 wpa_s->conf->dpp_mud_url,
1695 supp_op_classes);
1696 os_free(supp_op_classes);
Hai Shalom021b0b52019-04-10 11:17:58 -07001697 if (!buf) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001698 wpa_printf(MSG_DEBUG,
1699 "DPP: No configuration request data available");
1700 return;
1701 }
1702
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001703 wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
1704 MAC2STR(auth->peer_mac_addr), auth->curr_freq);
1705
1706 res = gas_query_req(wpa_s->gas, auth->peer_mac_addr, auth->curr_freq,
Hai Shalomb755a2a2020-04-23 21:49:02 -07001707 1, 1, buf, wpas_dpp_gas_resp_cb, wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001708 if (res < 0) {
1709 wpa_msg(wpa_s, MSG_DEBUG, "GAS: Failed to send Query Request");
1710 wpabuf_free(buf);
1711 } else {
1712 wpa_printf(MSG_DEBUG,
1713 "DPP: GAS query started with dialog token %u", res);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001714 wpa_s->dpp_gas_dialog_token = res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001715 }
1716}
1717
1718
1719static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator)
1720{
1721 wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded");
1722 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d", initiator);
Hai Shalom706f99b2019-01-08 16:23:37 -08001723 wpas_notify_dpp_auth_success(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001724#ifdef CONFIG_TESTING_OPTIONS
1725 if (dpp_test == DPP_TEST_STOP_AT_AUTH_CONF) {
1726 wpa_printf(MSG_INFO,
1727 "DPP: TESTING - stop at Authentication Confirm");
1728 if (wpa_s->dpp_auth->configurator) {
1729 /* Prevent GAS response */
1730 wpa_s->dpp_auth->auth_success = 0;
1731 }
1732 return;
1733 }
1734#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001735
1736 if (wpa_s->dpp_auth->configurator)
1737 wpas_dpp_start_gas_server(wpa_s);
1738 else
1739 wpas_dpp_start_gas_client(wpa_s);
1740}
1741
1742
1743static void wpas_dpp_rx_auth_resp(struct wpa_supplicant *wpa_s, const u8 *src,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001744 const u8 *hdr, const u8 *buf, size_t len,
1745 unsigned int freq)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001746{
1747 struct dpp_authentication *auth = wpa_s->dpp_auth;
1748 struct wpabuf *msg;
1749
Roshan Pius3a1667e2018-07-03 15:17:14 -07001750 wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR
1751 " (freq %u MHz)", MAC2STR(src), freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001752
1753 if (!auth) {
1754 wpa_printf(MSG_DEBUG,
1755 "DPP: No DPP Authentication in progress - drop");
1756 return;
1757 }
1758
1759 if (!is_zero_ether_addr(auth->peer_mac_addr) &&
1760 os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1761 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1762 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1763 return;
1764 }
1765
1766 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
1767
Roshan Pius3a1667e2018-07-03 15:17:14 -07001768 if (auth->curr_freq != freq && auth->neg_freq == freq) {
1769 wpa_printf(MSG_DEBUG,
1770 "DPP: Responder accepted request for different negotiation channel");
1771 auth->curr_freq = freq;
1772 }
1773
1774 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001775 msg = dpp_auth_resp_rx(auth, hdr, buf, len);
1776 if (!msg) {
1777 if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) {
1778 wpa_printf(MSG_DEBUG,
1779 "DPP: Start wait for full response");
Hai Shalom706f99b2019-01-08 16:23:37 -08001780 wpas_notify_dpp_resp_pending(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001781 offchannel_send_action_done(wpa_s);
1782 wpas_dpp_listen_start(wpa_s, auth->curr_freq);
1783 return;
1784 }
1785 wpa_printf(MSG_DEBUG, "DPP: No confirm generated");
1786 return;
1787 }
1788 os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
1789
Roshan Pius3a1667e2018-07-03 15:17:14 -07001790 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1791 MAC2STR(src), auth->curr_freq, DPP_PA_AUTHENTICATION_CONF);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001792 offchannel_send_action(wpa_s, auth->curr_freq,
1793 src, wpa_s->own_addr, broadcast,
1794 wpabuf_head(msg), wpabuf_len(msg),
1795 500, wpas_dpp_tx_status, 0);
1796 wpabuf_free(msg);
1797 wpa_s->dpp_auth_ok_on_ack = 1;
1798}
1799
1800
1801static void wpas_dpp_rx_auth_conf(struct wpa_supplicant *wpa_s, const u8 *src,
1802 const u8 *hdr, const u8 *buf, size_t len)
1803{
1804 struct dpp_authentication *auth = wpa_s->dpp_auth;
1805
1806 wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR,
1807 MAC2STR(src));
1808
1809 if (!auth) {
1810 wpa_printf(MSG_DEBUG,
1811 "DPP: No DPP Authentication in progress - drop");
1812 return;
1813 }
1814
1815 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1816 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1817 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1818 return;
1819 }
1820
1821 if (dpp_auth_conf_rx(auth, hdr, buf, len) < 0) {
1822 wpa_printf(MSG_DEBUG, "DPP: Authentication failed");
Hai Shalom706f99b2019-01-08 16:23:37 -08001823 wpas_notify_dpp_auth_failure(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001824 return;
1825 }
1826
1827 wpas_dpp_auth_success(wpa_s, 0);
1828}
1829
1830
Hai Shalom021b0b52019-04-10 11:17:58 -07001831#ifdef CONFIG_DPP2
1832
1833static void wpas_dpp_config_result_wait_timeout(void *eloop_ctx,
1834 void *timeout_ctx)
1835{
1836 struct wpa_supplicant *wpa_s = eloop_ctx;
1837 struct dpp_authentication *auth = wpa_s->dpp_auth;
1838
1839 if (!auth || !auth->waiting_conf_result)
1840 return;
1841
1842 wpa_printf(MSG_DEBUG,
1843 "DPP: Timeout while waiting for Configuration Result");
1844 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom06768112019-12-04 15:49:43 -08001845 wpas_notify_dpp_configuration_failure(wpa_s);
Hai Shalom021b0b52019-04-10 11:17:58 -07001846 dpp_auth_deinit(auth);
1847 wpa_s->dpp_auth = NULL;
1848}
1849
1850
Hai Shalomc3565922019-10-28 11:58:20 -07001851static void wpas_dpp_conn_status_result_wait_timeout(void *eloop_ctx,
1852 void *timeout_ctx)
1853{
1854 struct wpa_supplicant *wpa_s = eloop_ctx;
1855 struct dpp_authentication *auth = wpa_s->dpp_auth;
1856
1857 if (!auth || !auth->waiting_conn_status_result)
1858 return;
1859
1860 wpa_printf(MSG_DEBUG,
1861 "DPP: Timeout while waiting for Connection Status Result");
1862 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONN_STATUS_RESULT "timeout");
Hai Shalom06768112019-12-04 15:49:43 -08001863 wpas_notify_dpp_timeout(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07001864 wpas_dpp_listen_stop(wpa_s);
1865 dpp_auth_deinit(auth);
1866 wpa_s->dpp_auth = NULL;
1867}
1868
1869
Hai Shalom021b0b52019-04-10 11:17:58 -07001870static void wpas_dpp_rx_conf_result(struct wpa_supplicant *wpa_s, const u8 *src,
1871 const u8 *hdr, const u8 *buf, size_t len)
1872{
1873 struct dpp_authentication *auth = wpa_s->dpp_auth;
1874 enum dpp_status_error status;
1875
1876 wpa_printf(MSG_DEBUG, "DPP: Configuration Result from " MACSTR,
1877 MAC2STR(src));
1878
1879 if (!auth || !auth->waiting_conf_result) {
1880 wpa_printf(MSG_DEBUG,
1881 "DPP: No DPP Configuration waiting for result - drop");
1882 return;
1883 }
1884
1885 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1886 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1887 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1888 return;
1889 }
1890
1891 status = dpp_conf_result_rx(auth, hdr, buf, len);
1892
Hai Shalomc3565922019-10-28 11:58:20 -07001893 if (status == DPP_STATUS_OK && auth->send_conn_status) {
1894 wpa_msg(wpa_s, MSG_INFO,
1895 DPP_EVENT_CONF_SENT "wait_conn_status=1");
1896 wpa_printf(MSG_DEBUG, "DPP: Wait for Connection Status Result");
Hai Shalom06768112019-12-04 15:49:43 -08001897 wpas_notify_dpp_config_accepted(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07001898 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout,
1899 wpa_s, NULL);
1900 auth->waiting_conn_status_result = 1;
1901 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout,
1902 wpa_s, NULL);
1903 eloop_register_timeout(16, 0,
1904 wpas_dpp_conn_status_result_wait_timeout,
1905 wpa_s, NULL);
1906 offchannel_send_action_done(wpa_s);
1907 wpas_dpp_listen_start(wpa_s, auth->neg_freq ? auth->neg_freq :
1908 auth->curr_freq);
1909 return;
1910 }
Hai Shalom021b0b52019-04-10 11:17:58 -07001911 offchannel_send_action_done(wpa_s);
1912 wpas_dpp_listen_stop(wpa_s);
Hai Shalome4073332019-11-05 16:20:12 -08001913 if (status == DPP_STATUS_OK) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001914 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
Hai Shalome4073332019-11-05 16:20:12 -08001915 wpas_notify_dpp_config_sent(wpa_s);
1916 }
1917 else {
Hai Shalom021b0b52019-04-10 11:17:58 -07001918 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom06768112019-12-04 15:49:43 -08001919 wpas_notify_dpp_config_rejected(wpa_s);
Hai Shalome4073332019-11-05 16:20:12 -08001920 }
Hai Shalom021b0b52019-04-10 11:17:58 -07001921 dpp_auth_deinit(auth);
1922 wpa_s->dpp_auth = NULL;
1923 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL);
1924}
1925
Hai Shalom81f62d82019-07-22 12:10:00 -07001926
Hai Shalomc3565922019-10-28 11:58:20 -07001927static void wpas_dpp_rx_conn_status_result(struct wpa_supplicant *wpa_s,
1928 const u8 *src, const u8 *hdr,
1929 const u8 *buf, size_t len)
1930{
1931 struct dpp_authentication *auth = wpa_s->dpp_auth;
1932 enum dpp_status_error status;
1933 u8 ssid[SSID_MAX_LEN];
1934 size_t ssid_len = 0;
1935 char *channel_list = NULL;
1936
1937 wpa_printf(MSG_DEBUG, "DPP: Connection Status Result");
1938
1939 if (!auth || !auth->waiting_conn_status_result) {
1940 wpa_printf(MSG_DEBUG,
1941 "DPP: No DPP Configuration waiting for connection status result - drop");
1942 return;
1943 }
1944
1945 status = dpp_conn_status_result_rx(auth, hdr, buf, len,
1946 ssid, &ssid_len, &channel_list);
1947 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONN_STATUS_RESULT
1948 "result=%d ssid=%s channel_list=%s",
1949 status, wpa_ssid_txt(ssid, ssid_len),
1950 channel_list ? channel_list : "N/A");
Hai Shalom06768112019-12-04 15:49:43 -08001951 wpas_notify_dpp_conn_status(wpa_s, status, wpa_ssid_txt(ssid, ssid_len),
1952 channel_list, auth->band_list, auth->band_list_size);
Hai Shalomc3565922019-10-28 11:58:20 -07001953 os_free(channel_list);
1954 offchannel_send_action_done(wpa_s);
1955 wpas_dpp_listen_stop(wpa_s);
1956 dpp_auth_deinit(auth);
1957 wpa_s->dpp_auth = NULL;
1958 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout,
1959 wpa_s, NULL);
1960}
1961
1962
Hai Shalom81f62d82019-07-22 12:10:00 -07001963static int wpas_dpp_process_conf_obj(void *ctx,
1964 struct dpp_authentication *auth)
1965{
1966 struct wpa_supplicant *wpa_s = ctx;
Hai Shalomc3565922019-10-28 11:58:20 -07001967 unsigned int i;
1968 int res = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -07001969
Hai Shalomc3565922019-10-28 11:58:20 -07001970 for (i = 0; i < auth->num_conf_obj; i++) {
1971 res = wpas_dpp_handle_config_obj(wpa_s, auth,
1972 &auth->conf_obj[i]);
1973 if (res)
1974 break;
1975 }
1976 if (!res)
1977 wpas_dpp_post_process_config(wpa_s, auth);
1978
1979 return res;
Hai Shalom81f62d82019-07-22 12:10:00 -07001980}
1981
Hai Shalomfdcde762020-04-02 11:19:20 -07001982
1983static void wpas_dpp_remove_bi(void *ctx, struct dpp_bootstrap_info *bi)
1984{
1985 struct wpa_supplicant *wpa_s = ctx;
1986
1987 if (bi == wpa_s->dpp_chirp_bi)
1988 wpas_dpp_chirp_stop(wpa_s);
1989}
1990
1991
1992static void
1993wpas_dpp_rx_presence_announcement(struct wpa_supplicant *wpa_s, const u8 *src,
1994 const u8 *hdr, const u8 *buf, size_t len,
1995 unsigned int freq)
1996{
1997 const u8 *r_bootstrap;
1998 u16 r_bootstrap_len;
1999 struct dpp_bootstrap_info *peer_bi;
2000 struct dpp_authentication *auth;
2001
2002 if (!wpa_s->dpp)
2003 return;
2004
2005 if (wpa_s->dpp_auth) {
2006 wpa_printf(MSG_DEBUG,
2007 "DPP: Ignore Presence Announcement during ongoing Authentication");
2008 return;
2009 }
2010
2011 wpa_printf(MSG_DEBUG, "DPP: Presence Announcement from " MACSTR,
2012 MAC2STR(src));
2013
2014 r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
2015 &r_bootstrap_len);
2016 if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
2017 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
2018 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
2019 return;
2020 }
2021 wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
2022 r_bootstrap, r_bootstrap_len);
2023 peer_bi = dpp_bootstrap_find_chirp(wpa_s->dpp, r_bootstrap);
Hai Shalom899fcc72020-10-19 14:38:18 -07002024 dpp_notify_chirp_received(wpa_s, peer_bi ? (int) peer_bi->id : -1, src,
2025 freq, r_bootstrap);
Hai Shalomfdcde762020-04-02 11:19:20 -07002026 if (!peer_bi) {
2027 wpa_printf(MSG_DEBUG,
2028 "DPP: No matching bootstrapping information found");
2029 return;
2030 }
2031
2032 auth = dpp_auth_init(wpa_s->dpp, wpa_s, peer_bi, NULL,
2033 DPP_CAPAB_CONFIGURATOR, freq, NULL, 0);
2034 if (!auth)
2035 return;
2036 wpas_dpp_set_testing_options(wpa_s, auth);
2037 if (dpp_set_configurator(auth, wpa_s->dpp_configurator_params) < 0) {
2038 dpp_auth_deinit(auth);
2039 return;
2040 }
2041
2042 auth->neg_freq = freq;
2043
2044 if (!is_zero_ether_addr(peer_bi->mac_addr))
2045 os_memcpy(auth->peer_mac_addr, peer_bi->mac_addr, ETH_ALEN);
2046
2047 wpa_s->dpp_auth = auth;
2048 if (wpas_dpp_auth_init_next(wpa_s) < 0) {
2049 dpp_auth_deinit(wpa_s->dpp_auth);
2050 wpa_s->dpp_auth = NULL;
2051 }
2052}
2053
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002054
2055static void wpas_dpp_reconfig_reply_wait_timeout(void *eloop_ctx,
2056 void *timeout_ctx)
2057{
2058 struct wpa_supplicant *wpa_s = eloop_ctx;
2059 struct dpp_authentication *auth = wpa_s->dpp_auth;
2060
2061 if (!auth)
2062 return;
2063
2064 wpa_printf(MSG_DEBUG, "DPP: Reconfig Reply wait timeout");
2065 offchannel_send_action_done(wpa_s);
2066 wpas_dpp_listen_stop(wpa_s);
2067 dpp_auth_deinit(auth);
2068 wpa_s->dpp_auth = NULL;
2069}
2070
2071
2072static void
2073wpas_dpp_rx_reconfig_announcement(struct wpa_supplicant *wpa_s, const u8 *src,
2074 const u8 *hdr, const u8 *buf, size_t len,
2075 unsigned int freq)
2076{
Hai Shalom899fcc72020-10-19 14:38:18 -07002077 const u8 *csign_hash, *fcgroup, *a_nonce, *e_id;
2078 u16 csign_hash_len, fcgroup_len, a_nonce_len, e_id_len;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002079 struct dpp_configurator *conf;
2080 struct dpp_authentication *auth;
2081 unsigned int wait_time, max_wait_time;
Hai Shalom899fcc72020-10-19 14:38:18 -07002082 u16 group;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002083
2084 if (!wpa_s->dpp)
2085 return;
2086
2087 if (wpa_s->dpp_auth) {
2088 wpa_printf(MSG_DEBUG,
2089 "DPP: Ignore Reconfig Announcement during ongoing Authentication");
2090 return;
2091 }
2092
2093 wpa_printf(MSG_DEBUG, "DPP: Reconfig Announcement from " MACSTR,
2094 MAC2STR(src));
2095
2096 csign_hash = dpp_get_attr(buf, len, DPP_ATTR_C_SIGN_KEY_HASH,
2097 &csign_hash_len);
2098 if (!csign_hash || csign_hash_len != SHA256_MAC_LEN) {
2099 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
2100 "Missing or invalid required Configurator C-sign key Hash attribute");
2101 return;
2102 }
2103 wpa_hexdump(MSG_MSGDUMP, "DPP: Configurator C-sign key Hash (kid)",
2104 csign_hash, csign_hash_len);
2105 conf = dpp_configurator_find_kid(wpa_s->dpp, csign_hash);
2106 if (!conf) {
2107 wpa_printf(MSG_DEBUG,
2108 "DPP: No matching Configurator information found");
2109 return;
2110 }
2111
Hai Shalom899fcc72020-10-19 14:38:18 -07002112 fcgroup = dpp_get_attr(buf, len, DPP_ATTR_FINITE_CYCLIC_GROUP,
2113 &fcgroup_len);
2114 if (!fcgroup || fcgroup_len != 2) {
2115 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
2116 "Missing or invalid required Finite Cyclic Group attribute");
2117 return;
2118 }
2119 group = WPA_GET_LE16(fcgroup);
2120 wpa_printf(MSG_DEBUG, "DPP: Enrollee finite cyclic group: %u", group);
2121
2122 a_nonce = dpp_get_attr(buf, len, DPP_ATTR_A_NONCE, &a_nonce_len);
2123 e_id = dpp_get_attr(buf, len, DPP_ATTR_E_PRIME_ID, &e_id_len);
2124
2125 auth = dpp_reconfig_init(wpa_s->dpp, wpa_s, conf, freq, group,
2126 a_nonce, a_nonce_len, e_id, e_id_len);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002127 if (!auth)
2128 return;
2129 wpas_dpp_set_testing_options(wpa_s, auth);
2130 if (dpp_set_configurator(auth, wpa_s->dpp_configurator_params) < 0) {
2131 dpp_auth_deinit(auth);
2132 return;
2133 }
2134
2135 os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
2136 wpa_s->dpp_auth = auth;
2137
2138 wpa_s->dpp_in_response_listen = 0;
2139 wpa_s->dpp_auth_ok_on_ack = 0;
2140 wait_time = wpa_s->max_remain_on_chan;
2141 max_wait_time = wpa_s->dpp_resp_wait_time ?
2142 wpa_s->dpp_resp_wait_time : 2000;
2143 if (wait_time > max_wait_time)
2144 wait_time = max_wait_time;
2145 wait_time += 10; /* give the driver some extra time to complete */
2146 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
2147 wpas_dpp_reconfig_reply_wait_timeout,
2148 wpa_s, NULL);
2149 wait_time -= 10;
2150
2151 wpas_dpp_stop_listen_for_tx(wpa_s, freq, wait_time);
2152
2153 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2154 MAC2STR(src), freq, DPP_PA_RECONFIG_AUTH_REQ);
2155 if (offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr, broadcast,
2156 wpabuf_head(auth->reconfig_req_msg),
2157 wpabuf_len(auth->reconfig_req_msg),
2158 wait_time, wpas_dpp_tx_status, 0) < 0) {
2159 dpp_auth_deinit(wpa_s->dpp_auth);
2160 wpa_s->dpp_auth = NULL;
2161 }
2162}
2163
2164
2165static void
2166wpas_dpp_rx_reconfig_auth_req(struct wpa_supplicant *wpa_s, const u8 *src,
2167 const u8 *hdr, const u8 *buf, size_t len,
2168 unsigned int freq)
2169{
2170 struct wpa_ssid *ssid;
2171 struct dpp_authentication *auth;
2172
2173 wpa_printf(MSG_DEBUG, "DPP: Reconfig Authentication Request from "
2174 MACSTR, MAC2STR(src));
2175
Hai Shalom899fcc72020-10-19 14:38:18 -07002176 if (!wpa_s->dpp)
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002177 return;
Hai Shalom899fcc72020-10-19 14:38:18 -07002178 if (wpa_s->dpp_auth) {
2179 wpa_printf(MSG_DEBUG,
2180 "DPP: Not ready for reconfiguration - pending authentication exchange in progress");
2181 return;
2182 }
2183 if (!wpa_s->dpp_reconfig_ssid) {
2184 wpa_printf(MSG_DEBUG,
2185 "DPP: Not ready for reconfiguration - not requested");
2186 return;
2187 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002188 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
2189 if (ssid == wpa_s->dpp_reconfig_ssid &&
2190 ssid->id == wpa_s->dpp_reconfig_ssid_id)
2191 break;
2192 }
2193 if (!ssid || !ssid->dpp_connector || !ssid->dpp_netaccesskey ||
Hai Shalom899fcc72020-10-19 14:38:18 -07002194 !ssid->dpp_csign) {
2195 wpa_printf(MSG_DEBUG,
2196 "DPP: Not ready for reconfiguration - no matching network profile with Connector found");
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002197 return;
Hai Shalom899fcc72020-10-19 14:38:18 -07002198 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002199
2200 auth = dpp_reconfig_auth_req_rx(wpa_s->dpp, wpa_s, ssid->dpp_connector,
2201 ssid->dpp_netaccesskey,
2202 ssid->dpp_netaccesskey_len,
2203 ssid->dpp_csign, ssid->dpp_csign_len,
2204 freq, hdr, buf, len);
2205 if (!auth)
2206 return;
2207 os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
2208 wpa_s->dpp_auth = auth;
2209
2210 wpas_dpp_chirp_stop(wpa_s);
2211
2212 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2213 MAC2STR(src), freq, DPP_PA_RECONFIG_AUTH_RESP);
2214 if (offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr, broadcast,
2215 wpabuf_head(auth->reconfig_resp_msg),
2216 wpabuf_len(auth->reconfig_resp_msg),
2217 500, wpas_dpp_tx_status, 0) < 0) {
2218 dpp_auth_deinit(wpa_s->dpp_auth);
2219 wpa_s->dpp_auth = NULL;
2220 }
2221}
2222
2223
2224static void
2225wpas_dpp_rx_reconfig_auth_resp(struct wpa_supplicant *wpa_s, const u8 *src,
2226 const u8 *hdr, const u8 *buf, size_t len,
2227 unsigned int freq)
2228{
2229 struct dpp_authentication *auth = wpa_s->dpp_auth;
2230 struct wpabuf *conf;
2231
2232 wpa_printf(MSG_DEBUG, "DPP: Reconfig Authentication Response from "
2233 MACSTR, MAC2STR(src));
2234
2235 if (!auth || !auth->reconfig || !auth->configurator) {
2236 wpa_printf(MSG_DEBUG,
2237 "DPP: No DPP Reconfig Authentication in progress - drop");
2238 return;
2239 }
2240
2241 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
2242 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
2243 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
2244 return;
2245 }
2246
2247 conf = dpp_reconfig_auth_resp_rx(auth, hdr, buf, len);
2248 if (!conf)
2249 return;
2250
2251 eloop_cancel_timeout(wpas_dpp_reconfig_reply_wait_timeout, wpa_s, NULL);
2252
2253 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2254 MAC2STR(src), freq, DPP_PA_RECONFIG_AUTH_CONF);
2255 if (offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr, broadcast,
2256 wpabuf_head(conf), wpabuf_len(conf),
2257 500, wpas_dpp_tx_status, 0) < 0) {
2258 wpabuf_free(conf);
2259 dpp_auth_deinit(wpa_s->dpp_auth);
2260 wpa_s->dpp_auth = NULL;
2261 return;
2262 }
2263 wpabuf_free(conf);
2264
2265 wpas_dpp_start_gas_server(wpa_s);
2266}
2267
2268
2269static void
2270wpas_dpp_rx_reconfig_auth_conf(struct wpa_supplicant *wpa_s, const u8 *src,
2271 const u8 *hdr, const u8 *buf, size_t len,
2272 unsigned int freq)
2273{
2274 struct dpp_authentication *auth = wpa_s->dpp_auth;
2275
2276 wpa_printf(MSG_DEBUG, "DPP: Reconfig Authentication Confirm from "
2277 MACSTR, MAC2STR(src));
2278
2279 if (!auth || !auth->reconfig || auth->configurator) {
2280 wpa_printf(MSG_DEBUG,
2281 "DPP: No DPP Reconfig Authentication in progress - drop");
2282 return;
2283 }
2284
2285 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
2286 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
2287 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
2288 return;
2289 }
2290
2291 if (dpp_reconfig_auth_conf_rx(auth, hdr, buf, len) < 0)
2292 return;
2293
2294 wpas_dpp_start_gas_client(wpa_s);
2295}
2296
Hai Shalom021b0b52019-04-10 11:17:58 -07002297#endif /* CONFIG_DPP2 */
2298
2299
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002300static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant *wpa_s,
2301 const u8 *src,
2302 const u8 *buf, size_t len)
2303{
2304 struct wpa_ssid *ssid;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002305 const u8 *connector, *trans_id, *status;
2306 u16 connector_len, trans_id_len, status_len;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002307#ifdef CONFIG_DPP2
2308 const u8 *version;
2309 u16 version_len;
2310#endif /* CONFIG_DPP2 */
2311 u8 peer_version = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002312 struct dpp_introduction intro;
2313 struct rsn_pmksa_cache_entry *entry;
2314 struct os_time now;
2315 struct os_reltime rnow;
2316 os_time_t expiry;
2317 unsigned int seconds;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002318 enum dpp_status_error res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002319
2320 wpa_printf(MSG_DEBUG, "DPP: Peer Discovery Response from " MACSTR,
2321 MAC2STR(src));
2322 if (is_zero_ether_addr(wpa_s->dpp_intro_bssid) ||
2323 os_memcmp(src, wpa_s->dpp_intro_bssid, ETH_ALEN) != 0) {
2324 wpa_printf(MSG_DEBUG, "DPP: Not waiting for response from "
2325 MACSTR " - drop", MAC2STR(src));
2326 return;
2327 }
2328 offchannel_send_action_done(wpa_s);
2329
2330 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
2331 if (ssid == wpa_s->dpp_intro_network)
2332 break;
2333 }
2334 if (!ssid || !ssid->dpp_connector || !ssid->dpp_netaccesskey ||
2335 !ssid->dpp_csign) {
2336 wpa_printf(MSG_DEBUG,
2337 "DPP: Profile not found for network introduction");
2338 return;
2339 }
2340
2341 trans_id = dpp_get_attr(buf, len, DPP_ATTR_TRANSACTION_ID,
2342 &trans_id_len);
2343 if (!trans_id || trans_id_len != 1) {
2344 wpa_printf(MSG_DEBUG,
2345 "DPP: Peer did not include Transaction ID");
Roshan Pius3a1667e2018-07-03 15:17:14 -07002346 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
2347 " fail=missing_transaction_id", MAC2STR(src));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002348 goto fail;
2349 }
2350 if (trans_id[0] != TRANSACTION_ID) {
2351 wpa_printf(MSG_DEBUG,
2352 "DPP: Ignore frame with unexpected Transaction ID %u",
2353 trans_id[0]);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002354 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
2355 " fail=transaction_id_mismatch", MAC2STR(src));
2356 goto fail;
2357 }
2358
2359 status = dpp_get_attr(buf, len, DPP_ATTR_STATUS, &status_len);
2360 if (!status || status_len != 1) {
2361 wpa_printf(MSG_DEBUG, "DPP: Peer did not include Status");
2362 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
2363 " fail=missing_status", MAC2STR(src));
2364 goto fail;
2365 }
2366 if (status[0] != DPP_STATUS_OK) {
2367 wpa_printf(MSG_DEBUG,
2368 "DPP: Peer rejected network introduction: Status %u",
2369 status[0]);
2370 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
2371 " status=%u", MAC2STR(src), status[0]);
Hai Shalomc3565922019-10-28 11:58:20 -07002372#ifdef CONFIG_DPP2
2373 wpas_dpp_send_conn_status_result(wpa_s, status[0]);
2374#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002375 goto fail;
2376 }
2377
2378 connector = dpp_get_attr(buf, len, DPP_ATTR_CONNECTOR, &connector_len);
2379 if (!connector) {
2380 wpa_printf(MSG_DEBUG,
2381 "DPP: Peer did not include its Connector");
Roshan Pius3a1667e2018-07-03 15:17:14 -07002382 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
2383 " fail=missing_connector", MAC2STR(src));
2384 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002385 }
2386
Roshan Pius3a1667e2018-07-03 15:17:14 -07002387 res = dpp_peer_intro(&intro, ssid->dpp_connector,
2388 ssid->dpp_netaccesskey,
2389 ssid->dpp_netaccesskey_len,
2390 ssid->dpp_csign,
2391 ssid->dpp_csign_len,
2392 connector, connector_len, &expiry);
2393 if (res != DPP_STATUS_OK) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002394 wpa_printf(MSG_INFO,
2395 "DPP: Network Introduction protocol resulted in failure");
Roshan Pius3a1667e2018-07-03 15:17:14 -07002396 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
2397 " fail=peer_connector_validation_failed", MAC2STR(src));
Hai Shalomc3565922019-10-28 11:58:20 -07002398#ifdef CONFIG_DPP2
2399 wpas_dpp_send_conn_status_result(wpa_s, res);
2400#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002401 goto fail;
2402 }
2403
2404 entry = os_zalloc(sizeof(*entry));
2405 if (!entry)
2406 goto fail;
2407 os_memcpy(entry->aa, src, ETH_ALEN);
2408 os_memcpy(entry->pmkid, intro.pmkid, PMKID_LEN);
2409 os_memcpy(entry->pmk, intro.pmk, intro.pmk_len);
2410 entry->pmk_len = intro.pmk_len;
2411 entry->akmp = WPA_KEY_MGMT_DPP;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002412#ifdef CONFIG_DPP2
2413 version = dpp_get_attr(buf, len, DPP_ATTR_PROTOCOL_VERSION,
2414 &version_len);
2415 if (version && version_len >= 1)
2416 peer_version = version[0];
2417 entry->dpp_pfs = peer_version >= 2;
2418#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002419 if (expiry) {
2420 os_get_time(&now);
2421 seconds = expiry - now.sec;
2422 } else {
2423 seconds = 86400 * 7;
2424 }
2425 os_get_reltime(&rnow);
2426 entry->expiration = rnow.sec + seconds;
2427 entry->reauth_time = rnow.sec + seconds;
2428 entry->network_ctx = ssid;
2429 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
2430
Roshan Pius3a1667e2018-07-03 15:17:14 -07002431 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002432 " status=%u version=%u", MAC2STR(src), status[0], peer_version);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002433
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002434 wpa_printf(MSG_DEBUG,
2435 "DPP: Try connection again after successful network introduction");
2436 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
2437 wpa_supplicant_cancel_sched_scan(wpa_s);
2438 wpa_supplicant_req_scan(wpa_s, 0, 0);
2439 }
2440fail:
2441 os_memset(&intro, 0, sizeof(intro));
2442}
2443
2444
Roshan Pius3a1667e2018-07-03 15:17:14 -07002445static int wpas_dpp_allow_ir(struct wpa_supplicant *wpa_s, unsigned int freq)
2446{
2447 int i, j;
2448
2449 if (!wpa_s->hw.modes)
2450 return -1;
2451
2452 for (i = 0; i < wpa_s->hw.num_modes; i++) {
2453 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
2454
2455 for (j = 0; j < mode->num_channels; j++) {
2456 struct hostapd_channel_data *chan = &mode->channels[j];
2457
2458 if (chan->freq != (int) freq)
2459 continue;
2460
2461 if (chan->flag & (HOSTAPD_CHAN_DISABLED |
2462 HOSTAPD_CHAN_NO_IR |
2463 HOSTAPD_CHAN_RADAR))
2464 continue;
2465
2466 return 1;
2467 }
2468 }
2469
2470 wpa_printf(MSG_DEBUG,
2471 "DPP: Frequency %u MHz not supported or does not allow PKEX initiation in the current channel list",
2472 freq);
2473
2474 return 0;
2475}
2476
2477
2478static int wpas_dpp_pkex_next_channel(struct wpa_supplicant *wpa_s,
2479 struct dpp_pkex *pkex)
2480{
2481 if (pkex->freq == 2437)
2482 pkex->freq = 5745;
2483 else if (pkex->freq == 5745)
2484 pkex->freq = 5220;
2485 else if (pkex->freq == 5220)
2486 pkex->freq = 60480;
2487 else
2488 return -1; /* no more channels to try */
2489
2490 if (wpas_dpp_allow_ir(wpa_s, pkex->freq) == 1) {
2491 wpa_printf(MSG_DEBUG, "DPP: Try to initiate on %u MHz",
2492 pkex->freq);
2493 return 0;
2494 }
2495
2496 /* Could not use this channel - try the next one */
2497 return wpas_dpp_pkex_next_channel(wpa_s, pkex);
2498}
2499
2500
2501static void wpas_dpp_pkex_retry_timeout(void *eloop_ctx, void *timeout_ctx)
2502{
2503 struct wpa_supplicant *wpa_s = eloop_ctx;
2504 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
2505
2506 if (!pkex || !pkex->exchange_req)
2507 return;
2508 if (pkex->exch_req_tries >= 5) {
2509 if (wpas_dpp_pkex_next_channel(wpa_s, pkex) < 0) {
2510 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
2511 "No response from PKEX peer");
2512 dpp_pkex_free(pkex);
2513 wpa_s->dpp_pkex = NULL;
2514 return;
2515 }
2516 pkex->exch_req_tries = 0;
2517 }
2518
2519 pkex->exch_req_tries++;
2520 wpa_printf(MSG_DEBUG, "DPP: Retransmit PKEX Exchange Request (try %u)",
2521 pkex->exch_req_tries);
2522 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2523 MAC2STR(broadcast), pkex->freq, DPP_PA_PKEX_EXCHANGE_REQ);
2524 offchannel_send_action(wpa_s, pkex->freq, broadcast,
2525 wpa_s->own_addr, broadcast,
2526 wpabuf_head(pkex->exchange_req),
2527 wpabuf_len(pkex->exchange_req),
2528 pkex->exch_req_wait_time,
2529 wpas_dpp_tx_pkex_status, 0);
2530}
2531
2532
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002533static void
2534wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s,
2535 unsigned int freq, const u8 *dst,
2536 const u8 *src, const u8 *bssid,
2537 const u8 *data, size_t data_len,
2538 enum offchannel_send_action_result result)
2539{
Roshan Pius3a1667e2018-07-03 15:17:14 -07002540 const char *res_txt;
2541 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
2542
2543 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
2544 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
2545 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002546 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
2547 " result=%s (PKEX)",
Roshan Pius3a1667e2018-07-03 15:17:14 -07002548 freq, MAC2STR(dst), res_txt);
2549 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
2550 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
2551
2552 if (!pkex) {
2553 wpa_printf(MSG_DEBUG,
2554 "DPP: Ignore TX status since there is no ongoing PKEX exchange");
2555 return;
2556 }
2557
2558 if (pkex->failed) {
2559 wpa_printf(MSG_DEBUG,
2560 "DPP: Terminate PKEX exchange due to an earlier error");
2561 if (pkex->t > pkex->own_bi->pkex_t)
2562 pkex->own_bi->pkex_t = pkex->t;
2563 dpp_pkex_free(pkex);
2564 wpa_s->dpp_pkex = NULL;
2565 return;
2566 }
2567
2568 if (pkex->exch_req_wait_time && pkex->exchange_req) {
2569 /* Wait for PKEX Exchange Response frame and retry request if
2570 * no response is seen. */
2571 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
2572 eloop_register_timeout(pkex->exch_req_wait_time / 1000,
2573 (pkex->exch_req_wait_time % 1000) * 1000,
2574 wpas_dpp_pkex_retry_timeout, wpa_s,
2575 NULL);
2576 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002577}
2578
2579
2580static void
2581wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant *wpa_s, const u8 *src,
2582 const u8 *buf, size_t len, unsigned int freq)
2583{
2584 struct wpabuf *msg;
2585 unsigned int wait_time;
2586
2587 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Request from " MACSTR,
2588 MAC2STR(src));
2589
2590 /* TODO: Support multiple PKEX codes by iterating over all the enabled
2591 * values here */
2592
2593 if (!wpa_s->dpp_pkex_code || !wpa_s->dpp_pkex_bi) {
2594 wpa_printf(MSG_DEBUG,
2595 "DPP: No PKEX code configured - ignore request");
2596 return;
2597 }
2598
2599 if (wpa_s->dpp_pkex) {
2600 /* TODO: Support parallel operations */
2601 wpa_printf(MSG_DEBUG,
2602 "DPP: Already in PKEX session - ignore new request");
2603 return;
2604 }
2605
Roshan Pius3a1667e2018-07-03 15:17:14 -07002606 wpa_s->dpp_pkex = dpp_pkex_rx_exchange_req(wpa_s, wpa_s->dpp_pkex_bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002607 wpa_s->own_addr, src,
2608 wpa_s->dpp_pkex_identifier,
2609 wpa_s->dpp_pkex_code,
2610 buf, len);
2611 if (!wpa_s->dpp_pkex) {
2612 wpa_printf(MSG_DEBUG,
2613 "DPP: Failed to process the request - ignore it");
2614 return;
2615 }
2616
2617 msg = wpa_s->dpp_pkex->exchange_resp;
2618 wait_time = wpa_s->max_remain_on_chan;
2619 if (wait_time > 2000)
2620 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002621 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2622 MAC2STR(src), freq, DPP_PA_PKEX_EXCHANGE_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002623 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
2624 broadcast,
2625 wpabuf_head(msg), wpabuf_len(msg),
2626 wait_time, wpas_dpp_tx_pkex_status, 0);
2627}
2628
2629
2630static void
2631wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant *wpa_s, const u8 *src,
2632 const u8 *buf, size_t len, unsigned int freq)
2633{
2634 struct wpabuf *msg;
2635 unsigned int wait_time;
2636
2637 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Response from " MACSTR,
2638 MAC2STR(src));
2639
2640 /* TODO: Support multiple PKEX codes by iterating over all the enabled
2641 * values here */
2642
2643 if (!wpa_s->dpp_pkex || !wpa_s->dpp_pkex->initiator ||
2644 wpa_s->dpp_pkex->exchange_done) {
2645 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
2646 return;
2647 }
2648
Roshan Pius3a1667e2018-07-03 15:17:14 -07002649 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
2650 wpa_s->dpp_pkex->exch_req_wait_time = 0;
2651
2652 msg = dpp_pkex_rx_exchange_resp(wpa_s->dpp_pkex, src, buf, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002653 if (!msg) {
2654 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
2655 return;
2656 }
2657
2658 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Request to " MACSTR,
2659 MAC2STR(src));
2660
2661 wait_time = wpa_s->max_remain_on_chan;
2662 if (wait_time > 2000)
2663 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002664 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2665 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_REQ);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002666 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
2667 broadcast,
2668 wpabuf_head(msg), wpabuf_len(msg),
2669 wait_time, wpas_dpp_tx_pkex_status, 0);
2670 wpabuf_free(msg);
2671}
2672
2673
Roshan Pius3a1667e2018-07-03 15:17:14 -07002674static struct dpp_bootstrap_info *
2675wpas_dpp_pkex_finish(struct wpa_supplicant *wpa_s, const u8 *peer,
2676 unsigned int freq)
2677{
Roshan Pius3a1667e2018-07-03 15:17:14 -07002678 struct dpp_bootstrap_info *bi;
2679
Hai Shalom021b0b52019-04-10 11:17:58 -07002680 bi = dpp_pkex_finish(wpa_s->dpp, wpa_s->dpp_pkex, peer, freq);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002681 if (!bi)
2682 return NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002683 wpa_s->dpp_pkex = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002684 return bi;
2685}
2686
2687
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002688static void
2689wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant *wpa_s, const u8 *src,
2690 const u8 *hdr, const u8 *buf, size_t len,
2691 unsigned int freq)
2692{
2693 struct wpabuf *msg;
2694 unsigned int wait_time;
2695 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002696
2697 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Request from " MACSTR,
2698 MAC2STR(src));
2699
2700 if (!pkex || pkex->initiator || !pkex->exchange_done) {
2701 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
2702 return;
2703 }
2704
2705 msg = dpp_pkex_rx_commit_reveal_req(pkex, hdr, buf, len);
2706 if (!msg) {
2707 wpa_printf(MSG_DEBUG, "DPP: Failed to process the request");
Roshan Pius3a1667e2018-07-03 15:17:14 -07002708 if (pkex->failed) {
2709 wpa_printf(MSG_DEBUG, "DPP: Terminate PKEX exchange");
2710 if (pkex->t > pkex->own_bi->pkex_t)
2711 pkex->own_bi->pkex_t = pkex->t;
2712 dpp_pkex_free(wpa_s->dpp_pkex);
2713 wpa_s->dpp_pkex = NULL;
2714 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002715 return;
2716 }
2717
2718 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Response to "
2719 MACSTR, MAC2STR(src));
2720
2721 wait_time = wpa_s->max_remain_on_chan;
2722 if (wait_time > 2000)
2723 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002724 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2725 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002726 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
2727 broadcast,
2728 wpabuf_head(msg), wpabuf_len(msg),
2729 wait_time, wpas_dpp_tx_pkex_status, 0);
2730 wpabuf_free(msg);
2731
Roshan Pius3a1667e2018-07-03 15:17:14 -07002732 wpas_dpp_pkex_finish(wpa_s, src, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002733}
2734
2735
2736static void
2737wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant *wpa_s, const u8 *src,
2738 const u8 *hdr, const u8 *buf, size_t len,
2739 unsigned int freq)
2740{
2741 int res;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002742 struct dpp_bootstrap_info *bi;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002743 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
2744 char cmd[500];
2745
2746 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Response from " MACSTR,
2747 MAC2STR(src));
2748
2749 if (!pkex || !pkex->initiator || !pkex->exchange_done) {
2750 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
2751 return;
2752 }
2753
2754 res = dpp_pkex_rx_commit_reveal_resp(pkex, hdr, buf, len);
2755 if (res < 0) {
2756 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
2757 return;
2758 }
2759
Roshan Pius3a1667e2018-07-03 15:17:14 -07002760 bi = wpas_dpp_pkex_finish(wpa_s, src, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002761 if (!bi)
2762 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002763
2764 os_snprintf(cmd, sizeof(cmd), " peer=%u %s",
2765 bi->id,
2766 wpa_s->dpp_pkex_auth_cmd ? wpa_s->dpp_pkex_auth_cmd : "");
2767 wpa_printf(MSG_DEBUG,
2768 "DPP: Start authentication after PKEX with parameters: %s",
2769 cmd);
2770 if (wpas_dpp_auth_init(wpa_s, cmd) < 0) {
2771 wpa_printf(MSG_DEBUG,
2772 "DPP: Authentication initialization failed");
Hai Shalomfdcde762020-04-02 11:19:20 -07002773 offchannel_send_action_done(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002774 return;
2775 }
2776}
2777
2778
2779void wpas_dpp_rx_action(struct wpa_supplicant *wpa_s, const u8 *src,
2780 const u8 *buf, size_t len, unsigned int freq)
2781{
2782 u8 crypto_suite;
2783 enum dpp_public_action_frame_type type;
2784 const u8 *hdr;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002785 unsigned int pkex_t;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002786
2787 if (len < DPP_HDR_LEN)
2788 return;
2789 if (WPA_GET_BE24(buf) != OUI_WFA || buf[3] != DPP_OUI_TYPE)
2790 return;
2791 hdr = buf;
2792 buf += 4;
2793 len -= 4;
2794 crypto_suite = *buf++;
2795 type = *buf++;
2796 len -= 2;
2797
2798 wpa_printf(MSG_DEBUG,
2799 "DPP: Received DPP Public Action frame crypto suite %u type %d from "
2800 MACSTR " freq=%u",
2801 crypto_suite, type, MAC2STR(src), freq);
2802 if (crypto_suite != 1) {
2803 wpa_printf(MSG_DEBUG, "DPP: Unsupported crypto suite %u",
2804 crypto_suite);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002805 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
2806 " freq=%u type=%d ignore=unsupported-crypto-suite",
2807 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002808 return;
2809 }
2810 wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002811 if (dpp_check_attrs(buf, len) < 0) {
2812 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
2813 " freq=%u type=%d ignore=invalid-attributes",
2814 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002815 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002816 }
2817 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR " freq=%u type=%d",
2818 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002819
2820 switch (type) {
2821 case DPP_PA_AUTHENTICATION_REQ:
2822 wpas_dpp_rx_auth_req(wpa_s, src, hdr, buf, len, freq);
2823 break;
2824 case DPP_PA_AUTHENTICATION_RESP:
Roshan Pius3a1667e2018-07-03 15:17:14 -07002825 wpas_dpp_rx_auth_resp(wpa_s, src, hdr, buf, len, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002826 break;
2827 case DPP_PA_AUTHENTICATION_CONF:
2828 wpas_dpp_rx_auth_conf(wpa_s, src, hdr, buf, len);
2829 break;
2830 case DPP_PA_PEER_DISCOVERY_RESP:
2831 wpas_dpp_rx_peer_disc_resp(wpa_s, src, buf, len);
2832 break;
2833 case DPP_PA_PKEX_EXCHANGE_REQ:
2834 wpas_dpp_rx_pkex_exchange_req(wpa_s, src, buf, len, freq);
2835 break;
2836 case DPP_PA_PKEX_EXCHANGE_RESP:
2837 wpas_dpp_rx_pkex_exchange_resp(wpa_s, src, buf, len, freq);
2838 break;
2839 case DPP_PA_PKEX_COMMIT_REVEAL_REQ:
2840 wpas_dpp_rx_pkex_commit_reveal_req(wpa_s, src, hdr, buf, len,
2841 freq);
2842 break;
2843 case DPP_PA_PKEX_COMMIT_REVEAL_RESP:
2844 wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s, src, hdr, buf, len,
2845 freq);
2846 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07002847#ifdef CONFIG_DPP2
2848 case DPP_PA_CONFIGURATION_RESULT:
2849 wpas_dpp_rx_conf_result(wpa_s, src, hdr, buf, len);
2850 break;
Hai Shalomc3565922019-10-28 11:58:20 -07002851 case DPP_PA_CONNECTION_STATUS_RESULT:
2852 wpas_dpp_rx_conn_status_result(wpa_s, src, hdr, buf, len);
2853 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07002854 case DPP_PA_PRESENCE_ANNOUNCEMENT:
2855 wpas_dpp_rx_presence_announcement(wpa_s, src, hdr, buf, len,
2856 freq);
2857 break;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002858 case DPP_PA_RECONFIG_ANNOUNCEMENT:
2859 wpas_dpp_rx_reconfig_announcement(wpa_s, src, hdr, buf, len,
2860 freq);
2861 break;
2862 case DPP_PA_RECONFIG_AUTH_REQ:
2863 wpas_dpp_rx_reconfig_auth_req(wpa_s, src, hdr, buf, len, freq);
2864 break;
2865 case DPP_PA_RECONFIG_AUTH_RESP:
2866 wpas_dpp_rx_reconfig_auth_resp(wpa_s, src, hdr, buf, len, freq);
2867 break;
2868 case DPP_PA_RECONFIG_AUTH_CONF:
2869 wpas_dpp_rx_reconfig_auth_conf(wpa_s, src, hdr, buf, len, freq);
2870 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07002871#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002872 default:
2873 wpa_printf(MSG_DEBUG,
2874 "DPP: Ignored unsupported frame subtype %d", type);
2875 break;
2876 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002877
2878 if (wpa_s->dpp_pkex)
2879 pkex_t = wpa_s->dpp_pkex->t;
2880 else if (wpa_s->dpp_pkex_bi)
2881 pkex_t = wpa_s->dpp_pkex_bi->pkex_t;
2882 else
2883 pkex_t = 0;
2884 if (pkex_t >= PKEX_COUNTER_T_LIMIT) {
2885 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_PKEX_T_LIMIT "id=0");
2886 wpas_dpp_pkex_remove(wpa_s, "*");
2887 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002888}
2889
2890
2891static struct wpabuf *
Hai Shalom899fcc72020-10-19 14:38:18 -07002892wpas_dpp_gas_req_handler(void *ctx, void *resp_ctx, const u8 *sa,
2893 const u8 *query, size_t query_len, u16 *comeback_delay)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002894{
2895 struct wpa_supplicant *wpa_s = ctx;
2896 struct dpp_authentication *auth = wpa_s->dpp_auth;
2897 struct wpabuf *resp;
2898
2899 wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR,
2900 MAC2STR(sa));
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002901 if (!auth || (!auth->auth_success && !auth->reconfig_success) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002902 os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) {
2903 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
2904 return NULL;
2905 }
Hai Shalomc3565922019-10-28 11:58:20 -07002906
2907 if (wpa_s->dpp_auth_ok_on_ack && auth->configurator) {
2908 wpa_printf(MSG_DEBUG,
2909 "DPP: Have not received ACK for Auth Confirm yet - assume it was received based on this GAS request");
2910 /* wpas_dpp_auth_success() would normally have been called from
2911 * TX status handler, but since there was no such handler call
2912 * yet, simply send out the event message and proceed with
2913 * exchange. */
2914 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=1");
2915 wpa_s->dpp_auth_ok_on_ack = 0;
2916 }
2917
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002918 wpa_hexdump(MSG_DEBUG,
2919 "DPP: Received Configuration Request (GAS Query Request)",
2920 query, query_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002921 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_REQ_RX "src=" MACSTR,
2922 MAC2STR(sa));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002923 resp = dpp_conf_req_rx(auth, query, query_len);
Hai Shalom899fcc72020-10-19 14:38:18 -07002924
2925#ifdef CONFIG_DPP2
2926 if (!resp && auth->waiting_cert) {
2927 wpa_printf(MSG_DEBUG, "DPP: Certificate not yet ready");
2928 auth->cert_resp_ctx = resp_ctx;
2929 *comeback_delay = 500;
2930 return NULL;
2931 }
2932#endif /* CONFIG_DPP2 */
2933
Hai Shalom59532852018-12-07 10:32:58 -08002934 if (!resp) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002935 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -08002936 wpas_notify_dpp_configuration_failure(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08002937 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002938 auth->conf_resp = resp;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002939 return resp;
2940}
2941
2942
2943static void
2944wpas_dpp_gas_status_handler(void *ctx, struct wpabuf *resp, int ok)
2945{
2946 struct wpa_supplicant *wpa_s = ctx;
2947 struct dpp_authentication *auth = wpa_s->dpp_auth;
2948
2949 if (!auth) {
2950 wpabuf_free(resp);
2951 return;
2952 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002953 if (auth->conf_resp != resp) {
2954 wpa_printf(MSG_DEBUG,
2955 "DPP: Ignore GAS status report (ok=%d) for unknown response",
2956 ok);
2957 wpabuf_free(resp);
2958 return;
2959 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002960
Hai Shalom899fcc72020-10-19 14:38:18 -07002961#ifdef CONFIG_DPP2
2962 if (auth->waiting_csr && ok) {
2963 wpa_printf(MSG_DEBUG, "DPP: Waiting for CSR");
2964 wpabuf_free(resp);
2965 return;
2966 }
2967#endif /* CONFIG_DPP2 */
2968
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002969 wpa_printf(MSG_DEBUG, "DPP: Configuration exchange completed (ok=%d)",
2970 ok);
2971 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002972 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07002973#ifdef CONFIG_DPP2
2974 if (ok && auth->peer_version >= 2 &&
2975 auth->conf_resp_status == DPP_STATUS_OK) {
2976 wpa_printf(MSG_DEBUG, "DPP: Wait for Configuration Result");
Hai Shalom06768112019-12-04 15:49:43 -08002977 wpas_notify_dpp_config_sent_wait_response(wpa_s);
Hai Shalom021b0b52019-04-10 11:17:58 -07002978 auth->waiting_conf_result = 1;
2979 auth->conf_resp = NULL;
2980 wpabuf_free(resp);
2981 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout,
2982 wpa_s, NULL);
2983 eloop_register_timeout(2, 0,
2984 wpas_dpp_config_result_wait_timeout,
2985 wpa_s, NULL);
2986 return;
2987 }
2988#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002989 offchannel_send_action_done(wpa_s);
2990 wpas_dpp_listen_stop(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08002991 if (ok) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002992 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
Hai Shalom706f99b2019-01-08 16:23:37 -08002993 wpas_notify_dpp_config_sent(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08002994 }
2995 else {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002996 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -08002997 wpas_notify_dpp_configuration_failure(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08002998 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002999 dpp_auth_deinit(wpa_s->dpp_auth);
3000 wpa_s->dpp_auth = NULL;
3001 wpabuf_free(resp);
3002}
3003
3004
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003005int wpas_dpp_configurator_sign(struct wpa_supplicant *wpa_s, const char *cmd)
3006{
3007 struct dpp_authentication *auth;
3008 int ret = -1;
3009 char *curve = NULL;
3010
Hai Shalomfdcde762020-04-02 11:19:20 -07003011 auth = dpp_alloc_auth(wpa_s->dpp, wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003012 if (!auth)
3013 return -1;
3014
3015 curve = get_param(cmd, " curve=");
Hai Shalom74f70d42019-02-11 14:42:39 -08003016 wpas_dpp_set_testing_options(wpa_s, auth);
Hai Shalomfdcde762020-04-02 11:19:20 -07003017 if (dpp_set_configurator(auth, cmd) == 0 &&
Hai Shalom021b0b52019-04-10 11:17:58 -07003018 dpp_configurator_own_config(auth, curve, 0) == 0)
Hai Shalomc3565922019-10-28 11:58:20 -07003019 ret = wpas_dpp_handle_config_obj(wpa_s, auth,
3020 &auth->conf_obj[0]);
3021 if (!ret)
3022 wpas_dpp_post_process_config(wpa_s, auth);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003023
3024 dpp_auth_deinit(auth);
3025 os_free(curve);
3026
3027 return ret;
3028}
3029
3030
3031static void
3032wpas_dpp_tx_introduction_status(struct wpa_supplicant *wpa_s,
3033 unsigned int freq, const u8 *dst,
3034 const u8 *src, const u8 *bssid,
3035 const u8 *data, size_t data_len,
3036 enum offchannel_send_action_result result)
3037{
Roshan Pius3a1667e2018-07-03 15:17:14 -07003038 const char *res_txt;
3039
3040 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
3041 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
3042 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003043 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
3044 " result=%s (DPP Peer Discovery Request)",
Roshan Pius3a1667e2018-07-03 15:17:14 -07003045 freq, MAC2STR(dst), res_txt);
3046 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
3047 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003048 /* TODO: Time out wait for response more quickly in error cases? */
3049}
3050
3051
3052int wpas_dpp_check_connect(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3053 struct wpa_bss *bss)
3054{
3055 struct os_time now;
3056 struct wpabuf *msg;
3057 unsigned int wait_time;
Hai Shalom021b0b52019-04-10 11:17:58 -07003058 const u8 *rsn;
3059 struct wpa_ie_data ied;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003060 size_t len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003061
3062 if (!(ssid->key_mgmt & WPA_KEY_MGMT_DPP) || !bss)
3063 return 0; /* Not using DPP AKM - continue */
Hai Shalom021b0b52019-04-10 11:17:58 -07003064 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3065 if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ied) == 0 &&
3066 !(ied.key_mgmt & WPA_KEY_MGMT_DPP))
3067 return 0; /* AP does not support DPP AKM - continue */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003068 if (wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid))
3069 return 0; /* PMKSA exists for DPP AKM - continue */
3070
3071 if (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
3072 !ssid->dpp_csign) {
3073 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
3074 "missing %s",
3075 !ssid->dpp_connector ? "Connector" :
3076 (!ssid->dpp_netaccesskey ? "netAccessKey" :
3077 "C-sign-key"));
3078 return -1;
3079 }
3080
3081 os_get_time(&now);
3082
3083 if (ssid->dpp_netaccesskey_expiry &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07003084 (os_time_t) ssid->dpp_netaccesskey_expiry < now.sec) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003085 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
3086 "netAccessKey expired");
3087 return -1;
3088 }
3089
3090 wpa_printf(MSG_DEBUG,
3091 "DPP: Starting network introduction protocol to derive PMKSA for "
3092 MACSTR, MAC2STR(bss->bssid));
3093
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003094 len = 5 + 4 + os_strlen(ssid->dpp_connector);
3095#ifdef CONFIG_DPP2
3096 len += 5;
3097#endif /* CONFIG_DPP2 */
3098 msg = dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003099 if (!msg)
3100 return -1;
3101
Roshan Pius3a1667e2018-07-03 15:17:14 -07003102#ifdef CONFIG_TESTING_OPTIONS
3103 if (dpp_test == DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ) {
3104 wpa_printf(MSG_INFO, "DPP: TESTING - no Transaction ID");
3105 goto skip_trans_id;
3106 }
3107 if (dpp_test == DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ) {
3108 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Transaction ID");
3109 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
3110 wpabuf_put_le16(msg, 0);
3111 goto skip_trans_id;
3112 }
3113#endif /* CONFIG_TESTING_OPTIONS */
3114
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003115 /* Transaction ID */
3116 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
3117 wpabuf_put_le16(msg, 1);
3118 wpabuf_put_u8(msg, TRANSACTION_ID);
3119
Roshan Pius3a1667e2018-07-03 15:17:14 -07003120#ifdef CONFIG_TESTING_OPTIONS
3121skip_trans_id:
3122 if (dpp_test == DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ) {
3123 wpa_printf(MSG_INFO, "DPP: TESTING - no Connector");
3124 goto skip_connector;
3125 }
3126 if (dpp_test == DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ) {
3127 char *connector;
3128
3129 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Connector");
3130 connector = dpp_corrupt_connector_signature(
3131 ssid->dpp_connector);
3132 if (!connector) {
3133 wpabuf_free(msg);
3134 return -1;
3135 }
3136 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
3137 wpabuf_put_le16(msg, os_strlen(connector));
3138 wpabuf_put_str(msg, connector);
3139 os_free(connector);
3140 goto skip_connector;
3141 }
3142#endif /* CONFIG_TESTING_OPTIONS */
3143
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003144 /* DPP Connector */
3145 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
3146 wpabuf_put_le16(msg, os_strlen(ssid->dpp_connector));
3147 wpabuf_put_str(msg, ssid->dpp_connector);
3148
Roshan Pius3a1667e2018-07-03 15:17:14 -07003149#ifdef CONFIG_TESTING_OPTIONS
3150skip_connector:
3151#endif /* CONFIG_TESTING_OPTIONS */
3152
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003153#ifdef CONFIG_DPP2
3154 if (DPP_VERSION > 1) {
3155 /* Protocol Version */
3156 wpabuf_put_le16(msg, DPP_ATTR_PROTOCOL_VERSION);
3157 wpabuf_put_le16(msg, 1);
3158 wpabuf_put_u8(msg, DPP_VERSION);
3159 }
3160#endif /* CONFIG_DPP2 */
3161
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003162 /* TODO: Timeout on AP response */
3163 wait_time = wpa_s->max_remain_on_chan;
3164 if (wait_time > 2000)
3165 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003166 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
3167 MAC2STR(bss->bssid), bss->freq, DPP_PA_PEER_DISCOVERY_REQ);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003168 offchannel_send_action(wpa_s, bss->freq, bss->bssid, wpa_s->own_addr,
3169 broadcast,
3170 wpabuf_head(msg), wpabuf_len(msg),
3171 wait_time, wpas_dpp_tx_introduction_status, 0);
3172 wpabuf_free(msg);
3173
3174 /* Request this connection attempt to terminate - new one will be
3175 * started when network introduction protocol completes */
3176 os_memcpy(wpa_s->dpp_intro_bssid, bss->bssid, ETH_ALEN);
3177 wpa_s->dpp_intro_network = ssid;
3178 return 1;
3179}
3180
3181
3182int wpas_dpp_pkex_add(struct wpa_supplicant *wpa_s, const char *cmd)
3183{
3184 struct dpp_bootstrap_info *own_bi;
3185 const char *pos, *end;
3186 unsigned int wait_time;
3187
3188 pos = os_strstr(cmd, " own=");
3189 if (!pos)
3190 return -1;
3191 pos += 5;
Hai Shalom021b0b52019-04-10 11:17:58 -07003192 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003193 if (!own_bi) {
3194 wpa_printf(MSG_DEBUG,
3195 "DPP: Identified bootstrap info not found");
3196 return -1;
3197 }
3198 if (own_bi->type != DPP_BOOTSTRAP_PKEX) {
3199 wpa_printf(MSG_DEBUG,
3200 "DPP: Identified bootstrap info not for PKEX");
3201 return -1;
3202 }
3203 wpa_s->dpp_pkex_bi = own_bi;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003204 own_bi->pkex_t = 0; /* clear pending errors on new code */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003205
3206 os_free(wpa_s->dpp_pkex_identifier);
3207 wpa_s->dpp_pkex_identifier = NULL;
3208 pos = os_strstr(cmd, " identifier=");
3209 if (pos) {
3210 pos += 12;
3211 end = os_strchr(pos, ' ');
3212 if (!end)
3213 return -1;
3214 wpa_s->dpp_pkex_identifier = os_malloc(end - pos + 1);
3215 if (!wpa_s->dpp_pkex_identifier)
3216 return -1;
3217 os_memcpy(wpa_s->dpp_pkex_identifier, pos, end - pos);
3218 wpa_s->dpp_pkex_identifier[end - pos] = '\0';
3219 }
3220
3221 pos = os_strstr(cmd, " code=");
3222 if (!pos)
3223 return -1;
3224 os_free(wpa_s->dpp_pkex_code);
3225 wpa_s->dpp_pkex_code = os_strdup(pos + 6);
3226 if (!wpa_s->dpp_pkex_code)
3227 return -1;
3228
3229 if (os_strstr(cmd, " init=1")) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003230 struct dpp_pkex *pkex;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003231 struct wpabuf *msg;
3232
3233 wpa_printf(MSG_DEBUG, "DPP: Initiating PKEX");
3234 dpp_pkex_free(wpa_s->dpp_pkex);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003235 wpa_s->dpp_pkex = dpp_pkex_init(wpa_s, own_bi, wpa_s->own_addr,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003236 wpa_s->dpp_pkex_identifier,
3237 wpa_s->dpp_pkex_code);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003238 pkex = wpa_s->dpp_pkex;
3239 if (!pkex)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003240 return -1;
3241
Roshan Pius3a1667e2018-07-03 15:17:14 -07003242 msg = pkex->exchange_req;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003243 wait_time = wpa_s->max_remain_on_chan;
3244 if (wait_time > 2000)
3245 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003246 pkex->freq = 2437;
3247 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
3248 " freq=%u type=%d",
3249 MAC2STR(broadcast), pkex->freq,
3250 DPP_PA_PKEX_EXCHANGE_REQ);
3251 offchannel_send_action(wpa_s, pkex->freq, broadcast,
3252 wpa_s->own_addr, broadcast,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003253 wpabuf_head(msg), wpabuf_len(msg),
3254 wait_time, wpas_dpp_tx_pkex_status, 0);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003255 if (wait_time == 0)
3256 wait_time = 2000;
3257 pkex->exch_req_wait_time = wait_time;
3258 pkex->exch_req_tries = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003259 }
3260
3261 /* TODO: Support multiple PKEX info entries */
3262
3263 os_free(wpa_s->dpp_pkex_auth_cmd);
3264 wpa_s->dpp_pkex_auth_cmd = os_strdup(cmd);
3265
3266 return 1;
3267}
3268
3269
3270int wpas_dpp_pkex_remove(struct wpa_supplicant *wpa_s, const char *id)
3271{
3272 unsigned int id_val;
3273
3274 if (os_strcmp(id, "*") == 0) {
3275 id_val = 0;
3276 } else {
3277 id_val = atoi(id);
3278 if (id_val == 0)
3279 return -1;
3280 }
3281
3282 if ((id_val != 0 && id_val != 1) || !wpa_s->dpp_pkex_code)
3283 return -1;
3284
3285 /* TODO: Support multiple PKEX entries */
3286 os_free(wpa_s->dpp_pkex_code);
3287 wpa_s->dpp_pkex_code = NULL;
3288 os_free(wpa_s->dpp_pkex_identifier);
3289 wpa_s->dpp_pkex_identifier = NULL;
3290 os_free(wpa_s->dpp_pkex_auth_cmd);
3291 wpa_s->dpp_pkex_auth_cmd = NULL;
3292 wpa_s->dpp_pkex_bi = NULL;
3293 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
3294 dpp_pkex_free(wpa_s->dpp_pkex);
3295 wpa_s->dpp_pkex = NULL;
3296 return 0;
3297}
3298
3299
Roshan Pius3a1667e2018-07-03 15:17:14 -07003300void wpas_dpp_stop(struct wpa_supplicant *wpa_s)
3301{
Hai Shalomfdcde762020-04-02 11:19:20 -07003302 if (wpa_s->dpp_auth || wpa_s->dpp_pkex)
3303 offchannel_send_action_done(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003304 dpp_auth_deinit(wpa_s->dpp_auth);
3305 wpa_s->dpp_auth = NULL;
3306 dpp_pkex_free(wpa_s->dpp_pkex);
3307 wpa_s->dpp_pkex = NULL;
3308 if (wpa_s->dpp_gas_client && wpa_s->dpp_gas_dialog_token >= 0)
3309 gas_query_stop(wpa_s->gas, wpa_s->dpp_gas_dialog_token);
3310}
3311
3312
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003313int wpas_dpp_init(struct wpa_supplicant *wpa_s)
3314{
Hai Shalom81f62d82019-07-22 12:10:00 -07003315 struct dpp_global_config config;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003316 u8 adv_proto_id[7];
3317
3318 adv_proto_id[0] = WLAN_EID_VENDOR_SPECIFIC;
3319 adv_proto_id[1] = 5;
3320 WPA_PUT_BE24(&adv_proto_id[2], OUI_WFA);
3321 adv_proto_id[5] = DPP_OUI_TYPE;
3322 adv_proto_id[6] = 0x01;
3323
3324 if (gas_server_register(wpa_s->gas_server, adv_proto_id,
3325 sizeof(adv_proto_id), wpas_dpp_gas_req_handler,
3326 wpas_dpp_gas_status_handler, wpa_s) < 0)
3327 return -1;
Hai Shalom81f62d82019-07-22 12:10:00 -07003328
3329 os_memset(&config, 0, sizeof(config));
Hai Shalom81f62d82019-07-22 12:10:00 -07003330 config.cb_ctx = wpa_s;
3331#ifdef CONFIG_DPP2
Hai Shalomfdcde762020-04-02 11:19:20 -07003332 config.remove_bi = wpas_dpp_remove_bi;
Hai Shalom81f62d82019-07-22 12:10:00 -07003333#endif /* CONFIG_DPP2 */
3334 wpa_s->dpp = dpp_global_init(&config);
Hai Shalom021b0b52019-04-10 11:17:58 -07003335 return wpa_s->dpp ? 0 : -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003336}
3337
3338
3339void wpas_dpp_deinit(struct wpa_supplicant *wpa_s)
3340{
3341#ifdef CONFIG_TESTING_OPTIONS
3342 os_free(wpa_s->dpp_config_obj_override);
3343 wpa_s->dpp_config_obj_override = NULL;
3344 os_free(wpa_s->dpp_discovery_override);
3345 wpa_s->dpp_discovery_override = NULL;
3346 os_free(wpa_s->dpp_groups_override);
3347 wpa_s->dpp_groups_override = NULL;
3348 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
3349#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalom021b0b52019-04-10 11:17:58 -07003350 if (!wpa_s->dpp)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003351 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003352 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003353 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003354 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
3355 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07003356#ifdef CONFIG_DPP2
3357 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL);
Hai Shalomc3565922019-10-28 11:58:20 -07003358 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout,
3359 wpa_s, NULL);
3360 eloop_cancel_timeout(wpas_dpp_conn_status_result_timeout, wpa_s, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003361 eloop_cancel_timeout(wpas_dpp_reconfig_reply_wait_timeout,
3362 wpa_s, NULL);
Hai Shalom899fcc72020-10-19 14:38:18 -07003363 eloop_cancel_timeout(wpas_dpp_build_csr, wpa_s, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07003364 dpp_pfs_free(wpa_s->dpp_pfs);
3365 wpa_s->dpp_pfs = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07003366 wpas_dpp_chirp_stop(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -07003367 dpp_free_reconfig_id(wpa_s->dpp_reconfig_id);
3368 wpa_s->dpp_reconfig_id = NULL;
Hai Shalom021b0b52019-04-10 11:17:58 -07003369#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003370 offchannel_send_action_done(wpa_s);
3371 wpas_dpp_listen_stop(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003372 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003373 wpas_dpp_pkex_remove(wpa_s, "*");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003374 os_memset(wpa_s->dpp_intro_bssid, 0, ETH_ALEN);
3375 os_free(wpa_s->dpp_configurator_params);
3376 wpa_s->dpp_configurator_params = NULL;
Hai Shalom899fcc72020-10-19 14:38:18 -07003377 dpp_global_clear(wpa_s->dpp);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003378}
Hai Shalom81f62d82019-07-22 12:10:00 -07003379
3380
3381#ifdef CONFIG_DPP2
Hai Shalomfdcde762020-04-02 11:19:20 -07003382
Hai Shalom81f62d82019-07-22 12:10:00 -07003383int wpas_dpp_controller_start(struct wpa_supplicant *wpa_s, const char *cmd)
3384{
3385 struct dpp_controller_config config;
3386 const char *pos;
3387
3388 os_memset(&config, 0, sizeof(config));
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003389 config.allowed_roles = DPP_CAPAB_ENROLLEE | DPP_CAPAB_CONFIGURATOR;
Hai Shalom899fcc72020-10-19 14:38:18 -07003390 config.netrole = DPP_NETROLE_STA;
3391 config.msg_ctx = wpa_s;
3392 config.cb_ctx = wpa_s;
3393 config.process_conf_obj = wpas_dpp_process_conf_obj;
Hai Shalom81f62d82019-07-22 12:10:00 -07003394 if (cmd) {
3395 pos = os_strstr(cmd, " tcp_port=");
3396 if (pos) {
3397 pos += 10;
3398 config.tcp_port = atoi(pos);
3399 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003400
3401 pos = os_strstr(cmd, " role=");
3402 if (pos) {
3403 pos += 6;
3404 if (os_strncmp(pos, "configurator", 12) == 0)
3405 config.allowed_roles = DPP_CAPAB_CONFIGURATOR;
3406 else if (os_strncmp(pos, "enrollee", 8) == 0)
3407 config.allowed_roles = DPP_CAPAB_ENROLLEE;
3408 else if (os_strncmp(pos, "either", 6) == 0)
3409 config.allowed_roles = DPP_CAPAB_CONFIGURATOR |
3410 DPP_CAPAB_ENROLLEE;
3411 else
3412 return -1;
3413 }
Hai Shalom899fcc72020-10-19 14:38:18 -07003414
3415 config.qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
Hai Shalom81f62d82019-07-22 12:10:00 -07003416 }
3417 config.configurator_params = wpa_s->dpp_configurator_params;
3418 return dpp_controller_start(wpa_s->dpp, &config);
3419}
Hai Shalomfdcde762020-04-02 11:19:20 -07003420
3421
3422static void wpas_dpp_chirp_next(void *eloop_ctx, void *timeout_ctx);
3423
3424static void wpas_dpp_chirp_timeout(void *eloop_ctx, void *timeout_ctx)
3425{
3426 struct wpa_supplicant *wpa_s = eloop_ctx;
3427
3428 wpa_printf(MSG_DEBUG, "DPP: No chirp response received");
3429 offchannel_send_action_done(wpa_s);
3430 wpas_dpp_chirp_next(wpa_s, NULL);
3431}
3432
3433
3434static void wpas_dpp_chirp_tx_status(struct wpa_supplicant *wpa_s,
3435 unsigned int freq, const u8 *dst,
3436 const u8 *src, const u8 *bssid,
3437 const u8 *data, size_t data_len,
3438 enum offchannel_send_action_result result)
3439{
3440 if (result == OFFCHANNEL_SEND_ACTION_FAILED) {
3441 wpa_printf(MSG_DEBUG, "DPP: Failed to send chirp on %d MHz",
3442 wpa_s->dpp_chirp_freq);
3443 if (eloop_register_timeout(0, 0, wpas_dpp_chirp_next,
3444 wpa_s, NULL) < 0)
3445 wpas_dpp_chirp_stop(wpa_s);
3446 return;
3447 }
3448
3449 wpa_printf(MSG_DEBUG, "DPP: Chirp send completed - wait for response");
3450 if (eloop_register_timeout(2, 0, wpas_dpp_chirp_timeout,
3451 wpa_s, NULL) < 0)
3452 wpas_dpp_chirp_stop(wpa_s);
3453}
3454
3455
3456static void wpas_dpp_chirp_start(struct wpa_supplicant *wpa_s)
3457{
Hai Shalom899fcc72020-10-19 14:38:18 -07003458 struct wpabuf *msg, *announce = NULL;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003459 int type;
3460
3461 msg = wpa_s->dpp_presence_announcement;
3462 type = DPP_PA_PRESENCE_ANNOUNCEMENT;
3463 if (!msg) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003464 struct wpa_ssid *ssid = wpa_s->dpp_reconfig_ssid;
3465
3466 if (ssid && wpa_s->dpp_reconfig_id &&
3467 wpa_config_get_network(wpa_s->conf,
3468 wpa_s->dpp_reconfig_ssid_id) ==
3469 ssid) {
3470 announce = dpp_build_reconfig_announcement(
3471 ssid->dpp_csign,
3472 ssid->dpp_csign_len,
3473 ssid->dpp_netaccesskey,
3474 ssid->dpp_netaccesskey_len,
3475 wpa_s->dpp_reconfig_id);
3476 msg = announce;
3477 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003478 if (!msg)
3479 return;
3480 type = DPP_PA_RECONFIG_ANNOUNCEMENT;
3481 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003482 wpa_printf(MSG_DEBUG, "DPP: Chirp on %d MHz", wpa_s->dpp_chirp_freq);
3483 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003484 MAC2STR(broadcast), wpa_s->dpp_chirp_freq, type);
Hai Shalomfdcde762020-04-02 11:19:20 -07003485 if (offchannel_send_action(
3486 wpa_s, wpa_s->dpp_chirp_freq, broadcast,
3487 wpa_s->own_addr, broadcast,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003488 wpabuf_head(msg), wpabuf_len(msg),
Hai Shalomfdcde762020-04-02 11:19:20 -07003489 2000, wpas_dpp_chirp_tx_status, 0) < 0)
3490 wpas_dpp_chirp_stop(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -07003491
3492 wpabuf_free(announce);
Hai Shalomfdcde762020-04-02 11:19:20 -07003493}
3494
3495
3496static void wpas_dpp_chirp_scan_res_handler(struct wpa_supplicant *wpa_s,
3497 struct wpa_scan_results *scan_res)
3498{
3499 struct dpp_bootstrap_info *bi = wpa_s->dpp_chirp_bi;
3500 unsigned int i;
3501 struct hostapd_hw_modes *mode;
3502 int c;
3503 struct wpa_bss *bss;
Hai Shalom899fcc72020-10-19 14:38:18 -07003504 bool chan6;
Hai Shalomfdcde762020-04-02 11:19:20 -07003505
Hai Shalom899fcc72020-10-19 14:38:18 -07003506 if (!bi && !wpa_s->dpp_reconfig_ssid)
Hai Shalomfdcde762020-04-02 11:19:20 -07003507 return;
3508
3509 wpa_s->dpp_chirp_scan_done = 1;
3510
3511 os_free(wpa_s->dpp_chirp_freqs);
3512 wpa_s->dpp_chirp_freqs = NULL;
3513
3514 /* Channels from own bootstrapping info */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003515 if (bi) {
3516 for (i = 0; i < bi->num_freq; i++)
3517 int_array_add_unique(&wpa_s->dpp_chirp_freqs,
3518 bi->freq[i]);
3519 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003520
3521 /* Preferred chirping channels */
Hai Shalom899fcc72020-10-19 14:38:18 -07003522 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes,
3523 HOSTAPD_MODE_IEEE80211G, 0);
3524 chan6 = mode == NULL;
3525 if (mode) {
3526 for (c = 0; c < mode->num_channels; c++) {
3527 struct hostapd_channel_data *chan = &mode->channels[c];
3528
3529 if ((chan->flag & HOSTAPD_CHAN_DISABLED) ||
3530 chan->freq != 2437)
3531 continue;
3532 chan6 = true;
3533 break;
3534 }
3535 }
3536 if (chan6)
3537 int_array_add_unique(&wpa_s->dpp_chirp_freqs, 2437);
Hai Shalomfdcde762020-04-02 11:19:20 -07003538
3539 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes,
3540 HOSTAPD_MODE_IEEE80211A, 0);
3541 if (mode) {
3542 int chan44 = 0, chan149 = 0;
3543
3544 for (c = 0; c < mode->num_channels; c++) {
3545 struct hostapd_channel_data *chan = &mode->channels[c];
3546
3547 if (chan->flag & (HOSTAPD_CHAN_DISABLED |
3548 HOSTAPD_CHAN_RADAR))
3549 continue;
3550 if (chan->freq == 5220)
3551 chan44 = 1;
3552 if (chan->freq == 5745)
3553 chan149 = 1;
3554 }
3555 if (chan149)
3556 int_array_add_unique(&wpa_s->dpp_chirp_freqs, 5745);
3557 else if (chan44)
3558 int_array_add_unique(&wpa_s->dpp_chirp_freqs, 5220);
3559 }
3560
3561 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes,
3562 HOSTAPD_MODE_IEEE80211AD, 0);
3563 if (mode) {
3564 for (c = 0; c < mode->num_channels; c++) {
3565 struct hostapd_channel_data *chan = &mode->channels[c];
3566
3567 if ((chan->flag & (HOSTAPD_CHAN_DISABLED |
3568 HOSTAPD_CHAN_RADAR)) ||
3569 chan->freq != 60480)
3570 continue;
3571 int_array_add_unique(&wpa_s->dpp_chirp_freqs, 60480);
3572 break;
3573 }
3574 }
3575
3576 /* Add channels from scan results for APs that advertise Configurator
3577 * Connectivity element */
3578 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
3579 if (wpa_bss_get_vendor_ie(bss, DPP_CC_IE_VENDOR_TYPE))
3580 int_array_add_unique(&wpa_s->dpp_chirp_freqs,
3581 bss->freq);
3582 }
3583
3584 if (!wpa_s->dpp_chirp_freqs ||
3585 eloop_register_timeout(0, 0, wpas_dpp_chirp_next, wpa_s, NULL) < 0)
3586 wpas_dpp_chirp_stop(wpa_s);
3587}
3588
3589
3590static void wpas_dpp_chirp_next(void *eloop_ctx, void *timeout_ctx)
3591{
3592 struct wpa_supplicant *wpa_s = eloop_ctx;
3593 int i;
3594
3595 if (wpa_s->dpp_chirp_listen)
3596 wpas_dpp_listen_stop(wpa_s);
3597
3598 if (wpa_s->dpp_chirp_freq == 0) {
3599 if (wpa_s->dpp_chirp_round % 4 == 0 &&
3600 !wpa_s->dpp_chirp_scan_done) {
3601 wpa_printf(MSG_DEBUG,
3602 "DPP: Update channel list for chirping");
3603 wpa_s->scan_req = MANUAL_SCAN_REQ;
3604 wpa_s->scan_res_handler =
3605 wpas_dpp_chirp_scan_res_handler;
3606 wpa_supplicant_req_scan(wpa_s, 0, 0);
3607 return;
3608 }
3609 wpa_s->dpp_chirp_freq = wpa_s->dpp_chirp_freqs[0];
3610 wpa_s->dpp_chirp_round++;
3611 wpa_printf(MSG_DEBUG, "DPP: Start chirping round %d",
3612 wpa_s->dpp_chirp_round);
3613 } else {
3614 for (i = 0; wpa_s->dpp_chirp_freqs[i]; i++)
3615 if (wpa_s->dpp_chirp_freqs[i] == wpa_s->dpp_chirp_freq)
3616 break;
3617 if (!wpa_s->dpp_chirp_freqs[i]) {
3618 wpa_printf(MSG_DEBUG,
3619 "DPP: Previous chirp freq %d not found",
3620 wpa_s->dpp_chirp_freq);
3621 return;
3622 }
3623 i++;
3624 if (wpa_s->dpp_chirp_freqs[i]) {
3625 wpa_s->dpp_chirp_freq = wpa_s->dpp_chirp_freqs[i];
3626 } else {
3627 wpa_s->dpp_chirp_iter--;
3628 if (wpa_s->dpp_chirp_iter <= 0) {
3629 wpa_printf(MSG_DEBUG,
3630 "DPP: Chirping iterations completed");
3631 wpas_dpp_chirp_stop(wpa_s);
3632 return;
3633 }
3634 wpa_s->dpp_chirp_freq = 0;
3635 wpa_s->dpp_chirp_scan_done = 0;
3636 if (eloop_register_timeout(30, 0, wpas_dpp_chirp_next,
3637 wpa_s, NULL) < 0) {
3638 wpas_dpp_chirp_stop(wpa_s);
3639 return;
3640 }
3641 if (wpa_s->dpp_chirp_listen) {
3642 wpa_printf(MSG_DEBUG,
3643 "DPP: Listen on %d MHz during chirp 30 second wait",
3644 wpa_s->dpp_chirp_listen);
3645 wpas_dpp_listen_start(wpa_s,
3646 wpa_s->dpp_chirp_listen);
3647 } else {
3648 wpa_printf(MSG_DEBUG,
3649 "DPP: Wait 30 seconds before starting the next chirping round");
3650 }
3651 return;
3652 }
3653 }
3654
3655 wpas_dpp_chirp_start(wpa_s);
3656}
3657
3658
3659int wpas_dpp_chirp(struct wpa_supplicant *wpa_s, const char *cmd)
3660{
3661 const char *pos;
3662 int iter = 1, listen_freq = 0;
3663 struct dpp_bootstrap_info *bi;
3664
3665 pos = os_strstr(cmd, " own=");
3666 if (!pos)
3667 return -1;
3668 pos += 5;
3669 bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
3670 if (!bi) {
3671 wpa_printf(MSG_DEBUG,
3672 "DPP: Identified bootstrap info not found");
3673 return -1;
3674 }
3675
3676 pos = os_strstr(cmd, " iter=");
3677 if (pos) {
3678 iter = atoi(pos + 6);
3679 if (iter <= 0)
3680 return -1;
3681 }
3682
3683 pos = os_strstr(cmd, " listen=");
3684 if (pos) {
3685 listen_freq = atoi(pos + 8);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003686 if (listen_freq <= 0)
Hai Shalomfdcde762020-04-02 11:19:20 -07003687 return -1;
3688 }
3689
3690 wpas_dpp_chirp_stop(wpa_s);
3691 wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
3692 wpa_s->dpp_qr_mutual = 0;
3693 wpa_s->dpp_chirp_bi = bi;
3694 wpa_s->dpp_presence_announcement = dpp_build_presence_announcement(bi);
3695 if (!wpa_s->dpp_presence_announcement)
3696 return -1;
3697 wpa_s->dpp_chirp_iter = iter;
3698 wpa_s->dpp_chirp_round = 0;
3699 wpa_s->dpp_chirp_scan_done = 0;
3700 wpa_s->dpp_chirp_listen = listen_freq;
3701
3702 return eloop_register_timeout(0, 0, wpas_dpp_chirp_next, wpa_s, NULL);
3703}
3704
3705
3706void wpas_dpp_chirp_stop(struct wpa_supplicant *wpa_s)
3707{
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003708 if (wpa_s->dpp_presence_announcement ||
Hai Shalom899fcc72020-10-19 14:38:18 -07003709 wpa_s->dpp_reconfig_ssid) {
Hai Shalomfdcde762020-04-02 11:19:20 -07003710 offchannel_send_action_done(wpa_s);
3711 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CHIRP_STOPPED);
3712 }
3713 wpa_s->dpp_chirp_bi = NULL;
3714 wpabuf_free(wpa_s->dpp_presence_announcement);
3715 wpa_s->dpp_presence_announcement = NULL;
3716 if (wpa_s->dpp_chirp_listen)
3717 wpas_dpp_listen_stop(wpa_s);
3718 wpa_s->dpp_chirp_listen = 0;
3719 wpa_s->dpp_chirp_freq = 0;
3720 os_free(wpa_s->dpp_chirp_freqs);
3721 wpa_s->dpp_chirp_freqs = NULL;
3722 eloop_cancel_timeout(wpas_dpp_chirp_next, wpa_s, NULL);
3723 eloop_cancel_timeout(wpas_dpp_chirp_timeout, wpa_s, NULL);
3724 if (wpa_s->scan_res_handler == wpas_dpp_chirp_scan_res_handler) {
3725 wpas_abort_ongoing_scan(wpa_s);
3726 wpa_s->scan_res_handler = NULL;
3727 }
3728}
3729
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003730
Hai Shalom899fcc72020-10-19 14:38:18 -07003731int wpas_dpp_reconfig(struct wpa_supplicant *wpa_s, const char *cmd)
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003732{
Hai Shalom899fcc72020-10-19 14:38:18 -07003733 struct wpa_ssid *ssid;
3734 int iter = 1;
3735 const char *pos;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003736
Hai Shalom899fcc72020-10-19 14:38:18 -07003737 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
3738 if (!ssid || !ssid->dpp_connector || !ssid->dpp_netaccesskey ||
3739 !ssid->dpp_csign) {
3740 wpa_printf(MSG_DEBUG,
3741 "DPP: Not a valid network profile for reconfiguration");
3742 return -1;
3743 }
3744
3745 pos = os_strstr(cmd, " iter=");
3746 if (pos) {
3747 iter = atoi(pos + 6);
3748 if (iter <= 0)
3749 return -1;
3750 }
3751
3752 if (wpa_s->dpp_auth) {
3753 wpa_printf(MSG_DEBUG,
3754 "DPP: Not ready to start reconfiguration - pending authentication exchange in progress");
3755 return -1;
3756 }
3757
3758 dpp_free_reconfig_id(wpa_s->dpp_reconfig_id);
3759 wpa_s->dpp_reconfig_id = dpp_gen_reconfig_id(ssid->dpp_csign,
3760 ssid->dpp_csign_len,
3761 ssid->dpp_pp_key,
3762 ssid->dpp_pp_key_len);
3763 if (!wpa_s->dpp_reconfig_id) {
3764 wpa_printf(MSG_DEBUG,
3765 "DPP: Failed to generate E-id for reconfiguration");
3766 return -1;
3767 }
3768 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3769 wpa_printf(MSG_DEBUG, "DPP: Disconnect for reconfiguration");
3770 wpa_s->own_disconnect_req = 1;
3771 wpa_supplicant_deauthenticate(
3772 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3773 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003774 wpas_dpp_chirp_stop(wpa_s);
3775 wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
3776 wpa_s->dpp_qr_mutual = 0;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003777 wpa_s->dpp_reconfig_ssid = ssid;
3778 wpa_s->dpp_reconfig_ssid_id = ssid->id;
Hai Shalom899fcc72020-10-19 14:38:18 -07003779 wpa_s->dpp_chirp_iter = iter;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003780 wpa_s->dpp_chirp_round = 0;
3781 wpa_s->dpp_chirp_scan_done = 0;
3782 wpa_s->dpp_chirp_listen = 0;
3783
3784 return eloop_register_timeout(0, 0, wpas_dpp_chirp_next, wpa_s, NULL);
3785}
3786
Hai Shalom899fcc72020-10-19 14:38:18 -07003787
3788static int wpas_dpp_build_conf_resp(struct wpa_supplicant *wpa_s,
3789 struct dpp_authentication *auth, bool tcp)
3790{
3791 struct wpabuf *resp;
3792
3793 resp = dpp_build_conf_resp(auth, auth->e_nonce, auth->curve->nonce_len,
3794 auth->e_netrole, true);
3795 if (!resp)
3796 return -1;
3797
3798 if (tcp) {
3799 auth->conf_resp_tcp = resp;
3800 return 0;
3801 }
3802
3803 if (gas_server_set_resp(wpa_s->gas_server, auth->cert_resp_ctx,
3804 resp) < 0) {
3805 wpa_printf(MSG_DEBUG,
3806 "DPP: Could not find pending GAS response");
3807 wpabuf_free(resp);
3808 return -1;
3809 }
3810 auth->conf_resp = resp;
3811 return 0;
3812}
3813
3814
3815int wpas_dpp_ca_set(struct wpa_supplicant *wpa_s, const char *cmd)
3816{
3817 int peer = -1;
3818 const char *pos, *value;
3819 struct dpp_authentication *auth = wpa_s->dpp_auth;
3820 u8 *bin;
3821 size_t bin_len;
3822 struct wpabuf *buf;
3823 bool tcp = false;
3824
3825 pos = os_strstr(cmd, " peer=");
3826 if (pos) {
3827 peer = atoi(pos + 6);
3828 if (!auth || !auth->waiting_cert ||
3829 (auth->peer_bi &&
3830 (unsigned int) peer != auth->peer_bi->id)) {
3831 auth = dpp_controller_get_auth(wpa_s->dpp, peer);
3832 tcp = true;
3833 }
3834 }
3835
3836 if (!auth || !auth->waiting_cert) {
3837 wpa_printf(MSG_DEBUG,
3838 "DPP: No authentication exchange waiting for certificate information");
3839 return -1;
3840 }
3841
3842 if (peer >= 0 &&
3843 (!auth->peer_bi ||
3844 (unsigned int) peer != auth->peer_bi->id) &&
3845 (!auth->tmp_peer_bi ||
3846 (unsigned int) peer != auth->tmp_peer_bi->id)) {
3847 wpa_printf(MSG_DEBUG, "DPP: Peer mismatch");
3848 return -1;
3849 }
3850
3851 pos = os_strstr(cmd, " value=");
3852 if (!pos)
3853 return -1;
3854 value = pos + 7;
3855
3856 pos = os_strstr(cmd, " name=");
3857 if (!pos)
3858 return -1;
3859 pos += 6;
3860
3861 if (os_strncmp(pos, "status ", 7) == 0) {
3862 auth->force_conf_resp_status = atoi(value);
3863 return wpas_dpp_build_conf_resp(wpa_s, auth, tcp);
3864 }
3865
3866 if (os_strncmp(pos, "trustedEapServerName ", 21) == 0) {
3867 os_free(auth->trusted_eap_server_name);
3868 auth->trusted_eap_server_name = os_strdup(value);
3869 return auth->trusted_eap_server_name ? 0 : -1;
3870 }
3871
3872 bin = base64_decode(value, os_strlen(value), &bin_len);
3873 if (!bin)
3874 return -1;
3875 buf = wpabuf_alloc_copy(bin, bin_len);
3876 os_free(bin);
3877
3878 if (os_strncmp(pos, "caCert ", 7) == 0) {
3879 wpabuf_free(auth->cacert);
3880 auth->cacert = buf;
3881 return 0;
3882 }
3883
3884 if (os_strncmp(pos, "certBag ", 8) == 0) {
3885 wpabuf_free(auth->certbag);
3886 auth->certbag = buf;
3887 return wpas_dpp_build_conf_resp(wpa_s, auth, tcp);
3888 }
3889
3890 wpabuf_free(buf);
3891 return -1;
3892}
3893
Hai Shalom81f62d82019-07-22 12:10:00 -07003894#endif /* CONFIG_DPP2 */