blob: c75ab47cb753f168389c70b15b027701bc8817ac [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"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070015#include "common/dpp.h"
16#include "common/gas.h"
17#include "common/gas_server.h"
18#include "rsn_supp/wpa.h"
19#include "rsn_supp/pmksa_cache.h"
20#include "wpa_supplicant_i.h"
21#include "config.h"
22#include "driver_i.h"
23#include "offchannel.h"
24#include "gas_query.h"
25#include "bss.h"
26#include "scan.h"
27#include "notify.h"
28#include "dpp_supplicant.h"
Hai Shalom59532852018-12-07 10:32:58 -080029#include "hidl.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070030
31
32static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
33 unsigned int freq);
34static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx);
35static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator);
36static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
37 unsigned int freq, const u8 *dst,
38 const u8 *src, const u8 *bssid,
39 const u8 *data, size_t data_len,
40 enum offchannel_send_action_result result);
Roshan Pius3a1667e2018-07-03 15:17:14 -070041static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx);
42static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s);
43static void
44wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s,
45 unsigned int freq, const u8 *dst,
46 const u8 *src, const u8 *bssid,
47 const u8 *data, size_t data_len,
48 enum offchannel_send_action_result result);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070049
50static const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
51
52/* Use a hardcoded Transaction ID 1 in Peer Discovery frames since there is only
53 * a single transaction in progress at any point in time. */
54static const u8 TRANSACTION_ID = 1;
55
56
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070057/**
58 * wpas_dpp_qr_code - Parse and add DPP bootstrapping info from a QR Code
59 * @wpa_s: Pointer to wpa_supplicant data
60 * @cmd: DPP URI read from a QR Code
61 * Returns: Identifier of the stored info or -1 on failure
62 */
63int wpas_dpp_qr_code(struct wpa_supplicant *wpa_s, const char *cmd)
64{
65 struct dpp_bootstrap_info *bi;
66 struct dpp_authentication *auth = wpa_s->dpp_auth;
67
Hai Shalom021b0b52019-04-10 11:17:58 -070068 bi = dpp_add_qr_code(wpa_s->dpp, cmd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070069 if (!bi)
70 return -1;
71
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070072 if (auth && auth->response_pending &&
73 dpp_notify_new_qr_code(auth, bi) == 1) {
74 wpa_printf(MSG_DEBUG,
75 "DPP: Sending out pending authentication response");
Roshan Pius3a1667e2018-07-03 15:17:14 -070076 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
77 " freq=%u type=%d",
78 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
79 DPP_PA_AUTHENTICATION_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070080 offchannel_send_action(wpa_s, auth->curr_freq,
81 auth->peer_mac_addr, wpa_s->own_addr,
82 broadcast,
83 wpabuf_head(auth->resp_msg),
84 wpabuf_len(auth->resp_msg),
85 500, wpas_dpp_tx_status, 0);
86 }
87
88 return bi->id;
89}
90
91
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080092/**
93 * wpas_dpp_nfc_uri - Parse and add DPP bootstrapping info from NFC Tag (URI)
94 * @wpa_s: Pointer to wpa_supplicant data
95 * @cmd: DPP URI read from a NFC Tag (URI NDEF message)
96 * Returns: Identifier of the stored info or -1 on failure
97 */
98int wpas_dpp_nfc_uri(struct wpa_supplicant *wpa_s, const char *cmd)
99{
100 struct dpp_bootstrap_info *bi;
101
102 bi = dpp_add_nfc_uri(wpa_s->dpp, cmd);
103 if (!bi)
104 return -1;
105
106 return bi->id;
107}
108
109
Hai Shalomfdcde762020-04-02 11:19:20 -0700110int wpas_dpp_nfc_handover_req(struct wpa_supplicant *wpa_s, const char *cmd)
111{
112 const char *pos;
113 struct dpp_bootstrap_info *peer_bi, *own_bi;
114
115 pos = os_strstr(cmd, " own=");
116 if (!pos)
117 return -1;
118 pos += 5;
119 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
120 if (!own_bi)
121 return -1;
122
123 pos = os_strstr(cmd, " uri=");
124 if (!pos)
125 return -1;
126 pos += 5;
127 peer_bi = dpp_add_nfc_uri(wpa_s->dpp, pos);
128 if (!peer_bi) {
129 wpa_printf(MSG_INFO,
130 "DPP: Failed to parse URI from NFC Handover Request");
131 return -1;
132 }
133
134 if (dpp_nfc_update_bi(own_bi, peer_bi) < 0)
135 return -1;
136
137 return peer_bi->id;
138}
139
140
141int wpas_dpp_nfc_handover_sel(struct wpa_supplicant *wpa_s, const char *cmd)
142{
143 const char *pos;
144 struct dpp_bootstrap_info *peer_bi, *own_bi;
145
146 pos = os_strstr(cmd, " own=");
147 if (!pos)
148 return -1;
149 pos += 5;
150 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
151 if (!own_bi)
152 return -1;
153
154 pos = os_strstr(cmd, " uri=");
155 if (!pos)
156 return -1;
157 pos += 5;
158 peer_bi = dpp_add_nfc_uri(wpa_s->dpp, pos);
159 if (!peer_bi) {
160 wpa_printf(MSG_INFO,
161 "DPP: Failed to parse URI from NFC Handover Select");
162 return -1;
163 }
164
165 if (peer_bi->curve != own_bi->curve) {
166 wpa_printf(MSG_INFO,
167 "DPP: Peer (NFC Handover Selector) used different curve");
168 return -1;
169 }
170
171 return peer_bi->id;
172}
173
174
Roshan Pius3a1667e2018-07-03 15:17:14 -0700175static void wpas_dpp_auth_resp_retry_timeout(void *eloop_ctx, void *timeout_ctx)
176{
177 struct wpa_supplicant *wpa_s = eloop_ctx;
178 struct dpp_authentication *auth = wpa_s->dpp_auth;
179
180 if (!auth || !auth->resp_msg)
181 return;
182
183 wpa_printf(MSG_DEBUG,
184 "DPP: Retry Authentication Response after timeout");
185 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
186 " freq=%u type=%d",
187 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
188 DPP_PA_AUTHENTICATION_RESP);
189 offchannel_send_action(wpa_s, auth->curr_freq, auth->peer_mac_addr,
190 wpa_s->own_addr, broadcast,
191 wpabuf_head(auth->resp_msg),
192 wpabuf_len(auth->resp_msg),
193 500, wpas_dpp_tx_status, 0);
194}
195
196
197static void wpas_dpp_auth_resp_retry(struct wpa_supplicant *wpa_s)
198{
199 struct dpp_authentication *auth = wpa_s->dpp_auth;
200 unsigned int wait_time, max_tries;
201
202 if (!auth || !auth->resp_msg)
203 return;
204
205 if (wpa_s->dpp_resp_max_tries)
206 max_tries = wpa_s->dpp_resp_max_tries;
207 else
208 max_tries = 5;
209 auth->auth_resp_tries++;
210 if (auth->auth_resp_tries >= max_tries) {
211 wpa_printf(MSG_INFO, "DPP: No confirm received from initiator - stopping exchange");
212 offchannel_send_action_done(wpa_s);
213 dpp_auth_deinit(wpa_s->dpp_auth);
214 wpa_s->dpp_auth = NULL;
215 return;
216 }
217
218 if (wpa_s->dpp_resp_retry_time)
219 wait_time = wpa_s->dpp_resp_retry_time;
220 else
221 wait_time = 1000;
222 wpa_printf(MSG_DEBUG,
223 "DPP: Schedule retransmission of Authentication Response frame in %u ms",
224 wait_time);
225 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
226 eloop_register_timeout(wait_time / 1000,
227 (wait_time % 1000) * 1000,
228 wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
229}
230
231
Hai Shalom021b0b52019-04-10 11:17:58 -0700232static void wpas_dpp_try_to_connect(struct wpa_supplicant *wpa_s)
233{
234 wpa_printf(MSG_DEBUG, "DPP: Trying to connect to the new network");
Hai Shalomc3565922019-10-28 11:58:20 -0700235 wpa_s->suitable_network = 0;
236 wpa_s->no_suitable_network = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700237 wpa_s->disconnected = 0;
238 wpa_s->reassociate = 1;
239 wpa_s->scan_runs = 0;
240 wpa_s->normal_scans = 0;
241 wpa_supplicant_cancel_sched_scan(wpa_s);
242 wpa_supplicant_req_scan(wpa_s, 0, 0);
243}
244
245
Hai Shalomc3565922019-10-28 11:58:20 -0700246#ifdef CONFIG_DPP2
247
248static void wpas_dpp_conn_status_result_timeout(void *eloop_ctx,
249 void *timeout_ctx)
250{
251 struct wpa_supplicant *wpa_s = eloop_ctx;
252 struct dpp_authentication *auth = wpa_s->dpp_auth;
253 enum dpp_status_error result;
254
255 if (!auth || !auth->conn_status_requested)
256 return;
257
258 wpa_printf(MSG_DEBUG,
259 "DPP: Connection timeout - report Connection Status Result");
260 if (wpa_s->suitable_network)
261 result = DPP_STATUS_AUTH_FAILURE;
262 else if (wpa_s->no_suitable_network)
263 result = DPP_STATUS_NO_AP;
264 else
265 result = 255; /* What to report here for unexpected state? */
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800266 if (wpa_s->wpa_state == WPA_SCANNING)
267 wpas_abort_ongoing_scan(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700268 wpas_dpp_send_conn_status_result(wpa_s, result);
269}
270
271
272static char * wpas_dpp_scan_channel_list(struct wpa_supplicant *wpa_s)
273{
274 char *str, *end, *pos;
275 size_t len;
276 unsigned int i;
277 u8 last_op_class = 0;
278 int res;
279
280 if (!wpa_s->last_scan_freqs || !wpa_s->num_last_scan_freqs)
281 return NULL;
282
283 len = wpa_s->num_last_scan_freqs * 8;
284 str = os_zalloc(len);
285 if (!str)
286 return NULL;
287 end = str + len;
288 pos = str;
289
290 for (i = 0; i < wpa_s->num_last_scan_freqs; i++) {
291 enum hostapd_hw_mode mode;
292 u8 op_class, channel;
293
294 mode = ieee80211_freq_to_channel_ext(wpa_s->last_scan_freqs[i],
295 0, 0, &op_class, &channel);
296 if (mode == NUM_HOSTAPD_MODES)
297 continue;
298 if (op_class == last_op_class)
299 res = os_snprintf(pos, end - pos, ",%d", channel);
300 else
301 res = os_snprintf(pos, end - pos, "%s%d/%d",
302 pos == str ? "" : ",",
303 op_class, channel);
304 if (os_snprintf_error(end - pos, res)) {
305 *pos = '\0';
306 break;
307 }
308 pos += res;
309 last_op_class = op_class;
310 }
311
312 if (pos == str) {
313 os_free(str);
314 str = NULL;
315 }
316 return str;
317}
318
319
320void wpas_dpp_send_conn_status_result(struct wpa_supplicant *wpa_s,
321 enum dpp_status_error result)
322{
323 struct wpabuf *msg;
324 const char *channel_list = NULL;
325 char *channel_list_buf = NULL;
326 struct wpa_ssid *ssid = wpa_s->current_ssid;
327 struct dpp_authentication *auth = wpa_s->dpp_auth;
328
329 eloop_cancel_timeout(wpas_dpp_conn_status_result_timeout, wpa_s, NULL);
330
331 if (!auth || !auth->conn_status_requested)
332 return;
333 auth->conn_status_requested = 0;
334 wpa_printf(MSG_DEBUG, "DPP: Report connection status result %d",
335 result);
336
337 if (result == DPP_STATUS_NO_AP) {
338 channel_list_buf = wpas_dpp_scan_channel_list(wpa_s);
339 channel_list = channel_list_buf;
340 }
341
342 msg = dpp_build_conn_status_result(auth, result,
343 ssid ? ssid->ssid :
344 wpa_s->dpp_last_ssid,
345 ssid ? ssid->ssid_len :
346 wpa_s->dpp_last_ssid_len,
347 channel_list);
348 os_free(channel_list_buf);
349 if (!msg) {
350 dpp_auth_deinit(wpa_s->dpp_auth);
351 wpa_s->dpp_auth = NULL;
352 return;
353 }
354
355 wpa_msg(wpa_s, MSG_INFO,
356 DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
357 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
358 DPP_PA_CONNECTION_STATUS_RESULT);
359 offchannel_send_action(wpa_s, auth->curr_freq,
360 auth->peer_mac_addr, wpa_s->own_addr, broadcast,
361 wpabuf_head(msg), wpabuf_len(msg),
362 500, wpas_dpp_tx_status, 0);
363 wpabuf_free(msg);
364
365 /* This exchange will be terminated in the TX status handler */
366 auth->remove_on_tx_status = 1;
367
368 return;
369}
370
371
372void wpas_dpp_connected(struct wpa_supplicant *wpa_s)
373{
374 struct dpp_authentication *auth = wpa_s->dpp_auth;
375
376 if (auth && auth->conn_status_requested)
377 wpas_dpp_send_conn_status_result(wpa_s, DPP_STATUS_OK);
378}
379
380#endif /* CONFIG_DPP2 */
381
382
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700383static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
384 unsigned int freq, const u8 *dst,
385 const u8 *src, const u8 *bssid,
386 const u8 *data, size_t data_len,
387 enum offchannel_send_action_result result)
388{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700389 const char *res_txt;
390 struct dpp_authentication *auth = wpa_s->dpp_auth;
391
392 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
393 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
394 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700395 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
Roshan Pius3a1667e2018-07-03 15:17:14 -0700396 " result=%s", freq, MAC2STR(dst), res_txt);
397 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
398 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700399
400 if (!wpa_s->dpp_auth) {
401 wpa_printf(MSG_DEBUG,
402 "DPP: Ignore TX status since there is no ongoing authentication exchange");
403 return;
404 }
405
Hai Shalom021b0b52019-04-10 11:17:58 -0700406#ifdef CONFIG_DPP2
407 if (auth->connect_on_tx_status) {
Hai Shalomc3565922019-10-28 11:58:20 -0700408 auth->connect_on_tx_status = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700409 wpa_printf(MSG_DEBUG,
410 "DPP: Try to connect after completed configuration result");
411 wpas_dpp_try_to_connect(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700412 if (auth->conn_status_requested) {
413 wpa_printf(MSG_DEBUG,
414 "DPP: Start 15 second timeout for reporting connection status result");
415 eloop_cancel_timeout(
416 wpas_dpp_conn_status_result_timeout,
417 wpa_s, NULL);
418 eloop_register_timeout(
419 15, 0, wpas_dpp_conn_status_result_timeout,
420 wpa_s, NULL);
421 } else {
422 dpp_auth_deinit(wpa_s->dpp_auth);
423 wpa_s->dpp_auth = NULL;
424 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700425 return;
426 }
427#endif /* CONFIG_DPP2 */
428
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700429 if (wpa_s->dpp_auth->remove_on_tx_status) {
430 wpa_printf(MSG_DEBUG,
Hai Shalomc3565922019-10-28 11:58:20 -0700431 "DPP: Terminate authentication exchange due to a request to do so on TX status");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700432 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700433 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700434 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
435 NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700436 offchannel_send_action_done(wpa_s);
437 dpp_auth_deinit(wpa_s->dpp_auth);
438 wpa_s->dpp_auth = NULL;
439 return;
440 }
441
442 if (wpa_s->dpp_auth_ok_on_ack)
443 wpas_dpp_auth_success(wpa_s, 1);
444
445 if (!is_broadcast_ether_addr(dst) &&
446 result != OFFCHANNEL_SEND_ACTION_SUCCESS) {
447 wpa_printf(MSG_DEBUG,
448 "DPP: Unicast DPP Action frame was not ACKed");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700449 if (auth->waiting_auth_resp) {
450 /* In case of DPP Authentication Request frame, move to
451 * the next channel immediately. */
452 offchannel_send_action_done(wpa_s);
453 wpas_dpp_auth_init_next(wpa_s);
454 return;
455 }
456 if (auth->waiting_auth_conf) {
457 wpas_dpp_auth_resp_retry(wpa_s);
458 return;
459 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700460 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700461
462 if (!is_broadcast_ether_addr(dst) && auth->waiting_auth_resp &&
463 result == OFFCHANNEL_SEND_ACTION_SUCCESS) {
464 /* Allow timeout handling to stop iteration if no response is
465 * received from a peer that has ACKed a request. */
466 auth->auth_req_ack = 1;
467 }
468
469 if (!wpa_s->dpp_auth_ok_on_ack && wpa_s->dpp_auth->neg_freq > 0 &&
470 wpa_s->dpp_auth->curr_freq != wpa_s->dpp_auth->neg_freq) {
471 wpa_printf(MSG_DEBUG,
472 "DPP: Move from curr_freq %u MHz to neg_freq %u MHz for response",
473 wpa_s->dpp_auth->curr_freq,
474 wpa_s->dpp_auth->neg_freq);
475 offchannel_send_action_done(wpa_s);
476 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->neg_freq);
477 }
478
479 if (wpa_s->dpp_auth_ok_on_ack)
480 wpa_s->dpp_auth_ok_on_ack = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700481}
482
483
484static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx)
485{
486 struct wpa_supplicant *wpa_s = eloop_ctx;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700487 struct dpp_authentication *auth = wpa_s->dpp_auth;
488 unsigned int freq;
489 struct os_reltime now, diff;
490 unsigned int wait_time, diff_ms;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700491
Roshan Pius3a1667e2018-07-03 15:17:14 -0700492 if (!auth || !auth->waiting_auth_resp)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700493 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700494
495 wait_time = wpa_s->dpp_resp_wait_time ?
496 wpa_s->dpp_resp_wait_time : 2000;
497 os_get_reltime(&now);
498 os_reltime_sub(&now, &wpa_s->dpp_last_init, &diff);
499 diff_ms = diff.sec * 1000 + diff.usec / 1000;
500 wpa_printf(MSG_DEBUG,
501 "DPP: Reply wait timeout - wait_time=%u diff_ms=%u",
502 wait_time, diff_ms);
503
504 if (auth->auth_req_ack && diff_ms >= wait_time) {
505 /* Peer ACK'ed Authentication Request frame, but did not reply
506 * with Authentication Response frame within two seconds. */
507 wpa_printf(MSG_INFO,
508 "DPP: No response received from responder - stopping initiation attempt");
509 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -0800510 wpas_notify_dpp_timeout(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700511 offchannel_send_action_done(wpa_s);
512 wpas_dpp_listen_stop(wpa_s);
513 dpp_auth_deinit(auth);
514 wpa_s->dpp_auth = NULL;
515 return;
516 }
517
518 if (diff_ms >= wait_time) {
519 /* Authentication Request frame was not ACK'ed and no reply
520 * was receiving within two seconds. */
521 wpa_printf(MSG_DEBUG,
522 "DPP: Continue Initiator channel iteration");
523 offchannel_send_action_done(wpa_s);
524 wpas_dpp_listen_stop(wpa_s);
525 wpas_dpp_auth_init_next(wpa_s);
526 return;
527 }
528
529 /* Driver did not support 2000 ms long wait_time with TX command, so
530 * schedule listen operation to continue waiting for the response.
531 *
532 * DPP listen operations continue until stopped, so simply schedule a
533 * new call to this function at the point when the two second reply
534 * wait has expired. */
535 wait_time -= diff_ms;
536
537 freq = auth->curr_freq;
538 if (auth->neg_freq > 0)
539 freq = auth->neg_freq;
540 wpa_printf(MSG_DEBUG,
541 "DPP: Continue reply wait on channel %u MHz for %u ms",
542 freq, wait_time);
543 wpa_s->dpp_in_response_listen = 1;
544 wpas_dpp_listen_start(wpa_s, freq);
545
546 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
547 wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700548}
549
550
551static void wpas_dpp_set_testing_options(struct wpa_supplicant *wpa_s,
552 struct dpp_authentication *auth)
553{
554#ifdef CONFIG_TESTING_OPTIONS
555 if (wpa_s->dpp_config_obj_override)
556 auth->config_obj_override =
557 os_strdup(wpa_s->dpp_config_obj_override);
558 if (wpa_s->dpp_discovery_override)
559 auth->discovery_override =
560 os_strdup(wpa_s->dpp_discovery_override);
561 if (wpa_s->dpp_groups_override)
562 auth->groups_override =
563 os_strdup(wpa_s->dpp_groups_override);
564 auth->ignore_netaccesskey_mismatch =
565 wpa_s->dpp_ignore_netaccesskey_mismatch;
566#endif /* CONFIG_TESTING_OPTIONS */
567}
568
569
Roshan Pius3a1667e2018-07-03 15:17:14 -0700570static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx)
571{
572 struct wpa_supplicant *wpa_s = eloop_ctx;
573
574 if (!wpa_s->dpp_auth)
575 return;
576 wpa_printf(MSG_DEBUG, "DPP: Retry initiation after timeout");
577 wpas_dpp_auth_init_next(wpa_s);
578}
579
580
581static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s)
582{
583 struct dpp_authentication *auth = wpa_s->dpp_auth;
584 const u8 *dst;
585 unsigned int wait_time, max_wait_time, freq, max_tries, used;
586 struct os_reltime now, diff;
587
588 wpa_s->dpp_in_response_listen = 0;
589 if (!auth)
590 return -1;
591
592 if (auth->freq_idx == 0)
593 os_get_reltime(&wpa_s->dpp_init_iter_start);
594
595 if (auth->freq_idx >= auth->num_freq) {
596 auth->num_freq_iters++;
597 if (wpa_s->dpp_init_max_tries)
598 max_tries = wpa_s->dpp_init_max_tries;
599 else
600 max_tries = 5;
601 if (auth->num_freq_iters >= max_tries || auth->auth_req_ack) {
602 wpa_printf(MSG_INFO,
603 "DPP: No response received from responder - stopping initiation attempt");
604 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -0800605 wpas_notify_dpp_timeout(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700606 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout,
607 wpa_s, NULL);
608 offchannel_send_action_done(wpa_s);
609 dpp_auth_deinit(wpa_s->dpp_auth);
610 wpa_s->dpp_auth = NULL;
611 return -1;
612 }
613 auth->freq_idx = 0;
614 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
615 if (wpa_s->dpp_init_retry_time)
616 wait_time = wpa_s->dpp_init_retry_time;
617 else
618 wait_time = 10000;
619 os_get_reltime(&now);
620 os_reltime_sub(&now, &wpa_s->dpp_init_iter_start, &diff);
621 used = diff.sec * 1000 + diff.usec / 1000;
622 if (used > wait_time)
623 wait_time = 0;
624 else
625 wait_time -= used;
626 wpa_printf(MSG_DEBUG, "DPP: Next init attempt in %u ms",
627 wait_time);
628 eloop_register_timeout(wait_time / 1000,
629 (wait_time % 1000) * 1000,
630 wpas_dpp_init_timeout, wpa_s,
631 NULL);
632 return 0;
633 }
634 freq = auth->freq[auth->freq_idx++];
635 auth->curr_freq = freq;
636
637 if (is_zero_ether_addr(auth->peer_bi->mac_addr))
638 dst = broadcast;
639 else
640 dst = auth->peer_bi->mac_addr;
641 wpa_s->dpp_auth_ok_on_ack = 0;
642 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
643 wait_time = wpa_s->max_remain_on_chan;
644 max_wait_time = wpa_s->dpp_resp_wait_time ?
645 wpa_s->dpp_resp_wait_time : 2000;
646 if (wait_time > max_wait_time)
647 wait_time = max_wait_time;
648 wait_time += 10; /* give the driver some extra time to complete */
649 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
650 wpas_dpp_reply_wait_timeout,
651 wpa_s, NULL);
652 wait_time -= 10;
653 if (auth->neg_freq > 0 && freq != auth->neg_freq) {
654 wpa_printf(MSG_DEBUG,
655 "DPP: Initiate on %u MHz and move to neg_freq %u MHz for response",
656 freq, auth->neg_freq);
657 }
658 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
659 MAC2STR(dst), freq, DPP_PA_AUTHENTICATION_REQ);
660 auth->auth_req_ack = 0;
661 os_get_reltime(&wpa_s->dpp_last_init);
662 return offchannel_send_action(wpa_s, freq, dst,
663 wpa_s->own_addr, broadcast,
664 wpabuf_head(auth->req_msg),
665 wpabuf_len(auth->req_msg),
666 wait_time, wpas_dpp_tx_status, 0);
667}
668
669
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700670int wpas_dpp_auth_init(struct wpa_supplicant *wpa_s, const char *cmd)
671{
672 const char *pos;
673 struct dpp_bootstrap_info *peer_bi, *own_bi = NULL;
Hai Shalom81f62d82019-07-22 12:10:00 -0700674 struct dpp_authentication *auth;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700675 u8 allowed_roles = DPP_CAPAB_CONFIGURATOR;
676 unsigned int neg_freq = 0;
Hai Shalom81f62d82019-07-22 12:10:00 -0700677 int tcp = 0;
678#ifdef CONFIG_DPP2
679 int tcp_port = DPP_TCP_PORT;
680 struct hostapd_ip_addr ipaddr;
681 char *addr;
682#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700683
684 wpa_s->dpp_gas_client = 0;
685
686 pos = os_strstr(cmd, " peer=");
687 if (!pos)
688 return -1;
689 pos += 6;
Hai Shalom021b0b52019-04-10 11:17:58 -0700690 peer_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700691 if (!peer_bi) {
692 wpa_printf(MSG_INFO,
693 "DPP: Could not find bootstrapping info for the identified peer");
694 return -1;
695 }
696
Hai Shalom81f62d82019-07-22 12:10:00 -0700697#ifdef CONFIG_DPP2
698 pos = os_strstr(cmd, " tcp_port=");
699 if (pos) {
700 pos += 10;
701 tcp_port = atoi(pos);
702 }
703
704 addr = get_param(cmd, " tcp_addr=");
705 if (addr) {
706 int res;
707
708 res = hostapd_parse_ip_addr(addr, &ipaddr);
709 os_free(addr);
710 if (res)
711 return -1;
712 tcp = 1;
713 }
714#endif /* CONFIG_DPP2 */
715
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700716 pos = os_strstr(cmd, " own=");
717 if (pos) {
718 pos += 5;
Hai Shalom021b0b52019-04-10 11:17:58 -0700719 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700720 if (!own_bi) {
721 wpa_printf(MSG_INFO,
722 "DPP: Could not find bootstrapping info for the identified local entry");
723 return -1;
724 }
725
726 if (peer_bi->curve != own_bi->curve) {
727 wpa_printf(MSG_INFO,
728 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
729 peer_bi->curve->name, own_bi->curve->name);
730 return -1;
731 }
732 }
733
734 pos = os_strstr(cmd, " role=");
735 if (pos) {
736 pos += 6;
737 if (os_strncmp(pos, "configurator", 12) == 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700738 allowed_roles = DPP_CAPAB_CONFIGURATOR;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700739 else if (os_strncmp(pos, "enrollee", 8) == 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700740 allowed_roles = DPP_CAPAB_ENROLLEE;
741 else if (os_strncmp(pos, "either", 6) == 0)
742 allowed_roles = DPP_CAPAB_CONFIGURATOR |
743 DPP_CAPAB_ENROLLEE;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700744 else
745 goto fail;
746 }
747
748 pos = os_strstr(cmd, " netrole=");
749 if (pos) {
750 pos += 9;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800751 if (os_strncmp(pos, "ap", 2) == 0)
752 wpa_s->dpp_netrole = DPP_NETROLE_AP;
753 else if (os_strncmp(pos, "configurator", 12) == 0)
754 wpa_s->dpp_netrole = DPP_NETROLE_CONFIGURATOR;
755 else
756 wpa_s->dpp_netrole = DPP_NETROLE_STA;
Hai Shalomfdcde762020-04-02 11:19:20 -0700757 } else {
758 wpa_s->dpp_netrole = DPP_NETROLE_STA;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700759 }
760
Roshan Pius3a1667e2018-07-03 15:17:14 -0700761 pos = os_strstr(cmd, " neg_freq=");
762 if (pos)
763 neg_freq = atoi(pos + 10);
764
Hai Shalom81f62d82019-07-22 12:10:00 -0700765 if (!tcp && wpa_s->dpp_auth) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700766 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700767 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700768 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
769 NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700770 offchannel_send_action_done(wpa_s);
771 dpp_auth_deinit(wpa_s->dpp_auth);
Hai Shalom74f70d42019-02-11 14:42:39 -0800772 wpa_s->dpp_auth = NULL;
Hai Shalom81f62d82019-07-22 12:10:00 -0700773 }
774
Hai Shalomfdcde762020-04-02 11:19:20 -0700775 auth = dpp_auth_init(wpa_s->dpp, wpa_s, peer_bi, own_bi, allowed_roles,
776 neg_freq, wpa_s->hw.modes, wpa_s->hw.num_modes);
Hai Shalom81f62d82019-07-22 12:10:00 -0700777 if (!auth)
778 goto fail;
779 wpas_dpp_set_testing_options(wpa_s, auth);
Hai Shalomfdcde762020-04-02 11:19:20 -0700780 if (dpp_set_configurator(auth, cmd) < 0) {
Hai Shalom81f62d82019-07-22 12:10:00 -0700781 dpp_auth_deinit(auth);
Hai Shalom74f70d42019-02-11 14:42:39 -0800782 goto fail;
783 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700784
Hai Shalom81f62d82019-07-22 12:10:00 -0700785 auth->neg_freq = neg_freq;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700786
Roshan Pius3a1667e2018-07-03 15:17:14 -0700787 if (!is_zero_ether_addr(peer_bi->mac_addr))
Hai Shalom81f62d82019-07-22 12:10:00 -0700788 os_memcpy(auth->peer_mac_addr, peer_bi->mac_addr, ETH_ALEN);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700789
Hai Shalom81f62d82019-07-22 12:10:00 -0700790#ifdef CONFIG_DPP2
791 if (tcp)
792 return dpp_tcp_init(wpa_s->dpp, auth, &ipaddr, tcp_port);
793#endif /* CONFIG_DPP2 */
794
795 wpa_s->dpp_auth = auth;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700796 return wpas_dpp_auth_init_next(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700797fail:
798 return -1;
799}
800
801
802struct wpas_dpp_listen_work {
803 unsigned int freq;
804 unsigned int duration;
805 struct wpabuf *probe_resp_ie;
806};
807
808
809static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work *lwork)
810{
811 if (!lwork)
812 return;
813 os_free(lwork);
814}
815
816
817static void wpas_dpp_listen_work_done(struct wpa_supplicant *wpa_s)
818{
819 struct wpas_dpp_listen_work *lwork;
820
821 if (!wpa_s->dpp_listen_work)
822 return;
823
824 lwork = wpa_s->dpp_listen_work->ctx;
825 wpas_dpp_listen_work_free(lwork);
826 radio_work_done(wpa_s->dpp_listen_work);
827 wpa_s->dpp_listen_work = NULL;
828}
829
830
831static void dpp_start_listen_cb(struct wpa_radio_work *work, int deinit)
832{
833 struct wpa_supplicant *wpa_s = work->wpa_s;
834 struct wpas_dpp_listen_work *lwork = work->ctx;
835
836 if (deinit) {
837 if (work->started) {
838 wpa_s->dpp_listen_work = NULL;
839 wpas_dpp_listen_stop(wpa_s);
840 }
841 wpas_dpp_listen_work_free(lwork);
842 return;
843 }
844
845 wpa_s->dpp_listen_work = work;
846
847 wpa_s->dpp_pending_listen_freq = lwork->freq;
848
849 if (wpa_drv_remain_on_channel(wpa_s, lwork->freq,
850 wpa_s->max_remain_on_chan) < 0) {
851 wpa_printf(MSG_DEBUG,
852 "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
853 lwork->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -0800854 wpa_s->dpp_listen_freq = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700855 wpas_dpp_listen_work_done(wpa_s);
856 wpa_s->dpp_pending_listen_freq = 0;
857 return;
858 }
859 wpa_s->off_channel_freq = 0;
860 wpa_s->roc_waiting_drv_freq = lwork->freq;
861}
862
863
864static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
865 unsigned int freq)
866{
867 struct wpas_dpp_listen_work *lwork;
868
869 if (wpa_s->dpp_listen_work) {
870 wpa_printf(MSG_DEBUG,
871 "DPP: Reject start_listen since dpp_listen_work already exists");
872 return -1;
873 }
874
875 if (wpa_s->dpp_listen_freq)
876 wpas_dpp_listen_stop(wpa_s);
877 wpa_s->dpp_listen_freq = freq;
878
879 lwork = os_zalloc(sizeof(*lwork));
880 if (!lwork)
881 return -1;
882 lwork->freq = freq;
883
884 if (radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb,
885 lwork) < 0) {
886 wpas_dpp_listen_work_free(lwork);
887 return -1;
888 }
889
890 return 0;
891}
892
893
894int wpas_dpp_listen(struct wpa_supplicant *wpa_s, const char *cmd)
895{
896 int freq;
897
898 freq = atoi(cmd);
899 if (freq <= 0)
900 return -1;
901
902 if (os_strstr(cmd, " role=configurator"))
903 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR;
904 else if (os_strstr(cmd, " role=enrollee"))
905 wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
906 else
907 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
908 DPP_CAPAB_ENROLLEE;
909 wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800910 if (os_strstr(cmd, " netrole=ap"))
911 wpa_s->dpp_netrole = DPP_NETROLE_AP;
912 else if (os_strstr(cmd, " netrole=configurator"))
913 wpa_s->dpp_netrole = DPP_NETROLE_CONFIGURATOR;
914 else
915 wpa_s->dpp_netrole = DPP_NETROLE_STA;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700916 if (wpa_s->dpp_listen_freq == (unsigned int) freq) {
917 wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz",
918 freq);
919 return 0;
920 }
921
922 return wpas_dpp_listen_start(wpa_s, freq);
923}
924
925
926void wpas_dpp_listen_stop(struct wpa_supplicant *wpa_s)
927{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700928 wpa_s->dpp_in_response_listen = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700929 if (!wpa_s->dpp_listen_freq)
930 return;
931
932 wpa_printf(MSG_DEBUG, "DPP: Stop listen on %u MHz",
933 wpa_s->dpp_listen_freq);
934 wpa_drv_cancel_remain_on_channel(wpa_s);
935 wpa_s->dpp_listen_freq = 0;
936 wpas_dpp_listen_work_done(wpa_s);
937}
938
939
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700940void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
941 unsigned int freq)
942{
943 wpas_dpp_listen_work_done(wpa_s);
944
Roshan Pius3a1667e2018-07-03 15:17:14 -0700945 if (wpa_s->dpp_auth && wpa_s->dpp_in_response_listen) {
946 unsigned int new_freq;
947
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700948 /* Continue listen with a new remain-on-channel */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700949 if (wpa_s->dpp_auth->neg_freq > 0)
950 new_freq = wpa_s->dpp_auth->neg_freq;
951 else
952 new_freq = wpa_s->dpp_auth->curr_freq;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700953 wpa_printf(MSG_DEBUG,
954 "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
Roshan Pius3a1667e2018-07-03 15:17:14 -0700955 new_freq);
956 wpas_dpp_listen_start(wpa_s, new_freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700957 return;
958 }
959
960 if (wpa_s->dpp_listen_freq) {
961 /* Continue listen with a new remain-on-channel */
962 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_listen_freq);
963 }
964}
965
966
967static void wpas_dpp_rx_auth_req(struct wpa_supplicant *wpa_s, const u8 *src,
968 const u8 *hdr, const u8 *buf, size_t len,
969 unsigned int freq)
970{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700971 const u8 *r_bootstrap, *i_bootstrap;
972 u16 r_bootstrap_len, i_bootstrap_len;
Hai Shalom021b0b52019-04-10 11:17:58 -0700973 struct dpp_bootstrap_info *own_bi = NULL, *peer_bi = NULL;
974
975 if (!wpa_s->dpp)
976 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700977
978 wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR,
979 MAC2STR(src));
980
Hai Shalomfdcde762020-04-02 11:19:20 -0700981#ifdef CONFIG_DPP2
982 wpas_dpp_chirp_stop(wpa_s);
983#endif /* CONFIG_DPP2 */
984
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700985 r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
986 &r_bootstrap_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700987 if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
988 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
989 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700990 return;
991 }
992 wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
993 r_bootstrap, r_bootstrap_len);
994
995 i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH,
996 &i_bootstrap_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700997 if (!i_bootstrap || i_bootstrap_len != SHA256_MAC_LEN) {
998 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
999 "Missing or invalid required Initiator Bootstrapping Key Hash attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001000 return;
1001 }
1002 wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash",
1003 i_bootstrap, i_bootstrap_len);
1004
1005 /* Try to find own and peer bootstrapping key matches based on the
1006 * received hash values */
Hai Shalom021b0b52019-04-10 11:17:58 -07001007 dpp_bootstrap_find_pair(wpa_s->dpp, i_bootstrap, r_bootstrap,
1008 &own_bi, &peer_bi);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001009 if (!own_bi) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001010 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1011 "No matching own bootstrapping key found - ignore message");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001012 return;
1013 }
1014
1015 if (wpa_s->dpp_auth) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001016 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1017 "Already in DPP authentication exchange - ignore new one");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001018 return;
1019 }
1020
1021 wpa_s->dpp_gas_client = 0;
1022 wpa_s->dpp_auth_ok_on_ack = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07001023 wpa_s->dpp_auth = dpp_auth_req_rx(wpa_s->dpp, wpa_s,
1024 wpa_s->dpp_allowed_roles,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001025 wpa_s->dpp_qr_mutual,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001026 peer_bi, own_bi, freq, hdr, buf, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001027 if (!wpa_s->dpp_auth) {
1028 wpa_printf(MSG_DEBUG, "DPP: No response generated");
1029 return;
1030 }
1031 wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
Hai Shalomfdcde762020-04-02 11:19:20 -07001032 if (dpp_set_configurator(wpa_s->dpp_auth,
Hai Shalom021b0b52019-04-10 11:17:58 -07001033 wpa_s->dpp_configurator_params) < 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08001034 dpp_auth_deinit(wpa_s->dpp_auth);
1035 wpa_s->dpp_auth = NULL;
1036 return;
1037 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001038 os_memcpy(wpa_s->dpp_auth->peer_mac_addr, src, ETH_ALEN);
1039
Roshan Pius3a1667e2018-07-03 15:17:14 -07001040 if (wpa_s->dpp_listen_freq &&
1041 wpa_s->dpp_listen_freq != wpa_s->dpp_auth->curr_freq) {
1042 wpa_printf(MSG_DEBUG,
1043 "DPP: Stop listen on %u MHz to allow response on the request %u MHz",
1044 wpa_s->dpp_listen_freq, wpa_s->dpp_auth->curr_freq);
1045 wpas_dpp_listen_stop(wpa_s);
1046 }
1047
1048 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1049 MAC2STR(src), wpa_s->dpp_auth->curr_freq,
1050 DPP_PA_AUTHENTICATION_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001051 offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq,
1052 src, wpa_s->own_addr, broadcast,
1053 wpabuf_head(wpa_s->dpp_auth->resp_msg),
1054 wpabuf_len(wpa_s->dpp_auth->resp_msg),
1055 500, wpas_dpp_tx_status, 0);
1056}
1057
1058
1059static void wpas_dpp_start_gas_server(struct wpa_supplicant *wpa_s)
1060{
1061 /* TODO: stop wait and start ROC */
1062}
1063
1064
1065static struct wpa_ssid * wpas_dpp_add_network(struct wpa_supplicant *wpa_s,
Hai Shalomc3565922019-10-28 11:58:20 -07001066 struct dpp_authentication *auth,
1067 struct dpp_config_obj *conf)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001068{
1069 struct wpa_ssid *ssid;
1070
Hai Shalom021b0b52019-04-10 11:17:58 -07001071#ifdef CONFIG_DPP2
Hai Shalomc3565922019-10-28 11:58:20 -07001072 if (conf->akm == DPP_AKM_SAE) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001073#ifdef CONFIG_SAE
1074 struct wpa_driver_capa capa;
1075 int res;
1076
1077 res = wpa_drv_get_capa(wpa_s, &capa);
1078 if (res == 0 &&
1079 !(capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) &&
1080 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
1081 wpa_printf(MSG_DEBUG,
1082 "DPP: SAE not supported by the driver");
1083 return NULL;
1084 }
1085#else /* CONFIG_SAE */
1086 wpa_printf(MSG_DEBUG, "DPP: SAE not supported in the build");
1087 return NULL;
1088#endif /* CONFIG_SAE */
1089 }
1090#endif /* CONFIG_DPP2 */
1091
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001092 ssid = wpa_config_add_network(wpa_s->conf);
1093 if (!ssid)
1094 return NULL;
1095 wpas_notify_network_added(wpa_s, ssid);
1096 wpa_config_set_network_defaults(ssid);
1097 ssid->disabled = 1;
1098
Hai Shalomc3565922019-10-28 11:58:20 -07001099 ssid->ssid = os_malloc(conf->ssid_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001100 if (!ssid->ssid)
1101 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07001102 os_memcpy(ssid->ssid, conf->ssid, conf->ssid_len);
1103 ssid->ssid_len = conf->ssid_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001104
Hai Shalomc3565922019-10-28 11:58:20 -07001105 if (conf->connector) {
Hai Shalomfdcde762020-04-02 11:19:20 -07001106 if (dpp_akm_dpp(conf->akm)) {
1107 ssid->key_mgmt = WPA_KEY_MGMT_DPP;
1108 ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED;
1109 }
Hai Shalomc3565922019-10-28 11:58:20 -07001110 ssid->dpp_connector = os_strdup(conf->connector);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001111 if (!ssid->dpp_connector)
1112 goto fail;
1113 }
1114
Hai Shalomc3565922019-10-28 11:58:20 -07001115 if (conf->c_sign_key) {
1116 ssid->dpp_csign = os_malloc(wpabuf_len(conf->c_sign_key));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001117 if (!ssid->dpp_csign)
1118 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07001119 os_memcpy(ssid->dpp_csign, wpabuf_head(conf->c_sign_key),
1120 wpabuf_len(conf->c_sign_key));
1121 ssid->dpp_csign_len = wpabuf_len(conf->c_sign_key);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001122 }
1123
1124 if (auth->net_access_key) {
1125 ssid->dpp_netaccesskey =
1126 os_malloc(wpabuf_len(auth->net_access_key));
1127 if (!ssid->dpp_netaccesskey)
1128 goto fail;
1129 os_memcpy(ssid->dpp_netaccesskey,
1130 wpabuf_head(auth->net_access_key),
1131 wpabuf_len(auth->net_access_key));
1132 ssid->dpp_netaccesskey_len = wpabuf_len(auth->net_access_key);
1133 ssid->dpp_netaccesskey_expiry = auth->net_access_key_expiry;
1134 }
1135
Hai Shalomc3565922019-10-28 11:58:20 -07001136 if (!conf->connector || dpp_akm_psk(conf->akm) ||
1137 dpp_akm_sae(conf->akm)) {
Hai Shalomfdcde762020-04-02 11:19:20 -07001138 if (!conf->connector || !dpp_akm_dpp(conf->akm))
Hai Shalom021b0b52019-04-10 11:17:58 -07001139 ssid->key_mgmt = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07001140 if (dpp_akm_psk(conf->akm))
Roshan Pius3a1667e2018-07-03 15:17:14 -07001141 ssid->key_mgmt |= WPA_KEY_MGMT_PSK |
1142 WPA_KEY_MGMT_PSK_SHA256 | WPA_KEY_MGMT_FT_PSK;
Hai Shalomc3565922019-10-28 11:58:20 -07001143 if (dpp_akm_sae(conf->akm))
Roshan Pius3a1667e2018-07-03 15:17:14 -07001144 ssid->key_mgmt |= WPA_KEY_MGMT_SAE |
1145 WPA_KEY_MGMT_FT_SAE;
1146 ssid->ieee80211w = MGMT_FRAME_PROTECTION_OPTIONAL;
Hai Shalomc3565922019-10-28 11:58:20 -07001147 if (conf->passphrase[0]) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001148 if (wpa_config_set_quoted(ssid, "psk",
Hai Shalomc3565922019-10-28 11:58:20 -07001149 conf->passphrase) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001150 goto fail;
1151 wpa_config_update_psk(ssid);
1152 ssid->export_keys = 1;
1153 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07001154 ssid->psk_set = conf->psk_set;
1155 os_memcpy(ssid->psk, conf->psk, PMK_LEN);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001156 }
1157 }
1158
Hai Shalomc3565922019-10-28 11:58:20 -07001159 os_memcpy(wpa_s->dpp_last_ssid, conf->ssid, conf->ssid_len);
1160 wpa_s->dpp_last_ssid_len = conf->ssid_len;
1161
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001162 return ssid;
1163fail:
1164 wpas_notify_network_removed(wpa_s, ssid);
1165 wpa_config_remove_network(wpa_s->conf, ssid->id);
1166 return NULL;
1167}
1168
1169
Hai Shalom021b0b52019-04-10 11:17:58 -07001170static int wpas_dpp_process_config(struct wpa_supplicant *wpa_s,
Hai Shalomc3565922019-10-28 11:58:20 -07001171 struct dpp_authentication *auth,
1172 struct dpp_config_obj *conf)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001173{
1174 struct wpa_ssid *ssid;
1175
1176 if (wpa_s->conf->dpp_config_processing < 1)
Hai Shalom021b0b52019-04-10 11:17:58 -07001177 return 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001178
Hai Shalomc3565922019-10-28 11:58:20 -07001179 ssid = wpas_dpp_add_network(wpa_s, auth, conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001180 if (!ssid)
Hai Shalom021b0b52019-04-10 11:17:58 -07001181 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001182
1183 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_NETWORK_ID "%d", ssid->id);
Hai Shalom59532852018-12-07 10:32:58 -08001184
Hai Shalom706f99b2019-01-08 16:23:37 -08001185 wpas_notify_dpp_config_received(wpa_s, ssid);
Hai Shalom59532852018-12-07 10:32:58 -08001186
Hai Shalom021b0b52019-04-10 11:17:58 -07001187 if (wpa_s->conf->dpp_config_processing == 2)
1188 ssid->disabled = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001189
Hai Shalom021b0b52019-04-10 11:17:58 -07001190#ifndef CONFIG_NO_CONFIG_WRITE
1191 if (wpa_s->conf->update_config &&
1192 wpa_config_write(wpa_s->confname, wpa_s->conf))
1193 wpa_printf(MSG_DEBUG, "DPP: Failed to update configuration");
1194#endif /* CONFIG_NO_CONFIG_WRITE */
1195
Hai Shalomc3565922019-10-28 11:58:20 -07001196 return 0;
1197}
1198
1199
1200static void wpas_dpp_post_process_config(struct wpa_supplicant *wpa_s,
1201 struct dpp_authentication *auth)
1202{
Hai Shalom021b0b52019-04-10 11:17:58 -07001203 if (wpa_s->conf->dpp_config_processing < 2)
Hai Shalomc3565922019-10-28 11:58:20 -07001204 return;
Hai Shalom021b0b52019-04-10 11:17:58 -07001205
1206#ifdef CONFIG_DPP2
1207 if (auth->peer_version >= 2) {
1208 wpa_printf(MSG_DEBUG,
1209 "DPP: Postpone connection attempt to wait for completion of DPP Configuration Result");
1210 auth->connect_on_tx_status = 1;
Hai Shalomc3565922019-10-28 11:58:20 -07001211 return;
Hai Shalom021b0b52019-04-10 11:17:58 -07001212 }
1213#endif /* CONFIG_DPP2 */
1214
1215 wpas_dpp_try_to_connect(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001216}
1217
1218
Hai Shalom021b0b52019-04-10 11:17:58 -07001219static int wpas_dpp_handle_config_obj(struct wpa_supplicant *wpa_s,
Hai Shalomc3565922019-10-28 11:58:20 -07001220 struct dpp_authentication *auth,
1221 struct dpp_config_obj *conf)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001222{
1223 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
Hai Shalomc3565922019-10-28 11:58:20 -07001224 if (conf->ssid_len)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001225 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s",
Hai Shalomc3565922019-10-28 11:58:20 -07001226 wpa_ssid_txt(conf->ssid, conf->ssid_len));
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001227 if (conf->ssid_charset)
1228 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID_CHARSET "%d",
1229 conf->ssid_charset);
Hai Shalomc3565922019-10-28 11:58:20 -07001230 if (conf->connector) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001231 /* TODO: Save the Connector and consider using a command
1232 * to fetch the value instead of sending an event with
1233 * it. The Connector could end up being larger than what
1234 * most clients are ready to receive as an event
1235 * message. */
1236 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONNECTOR "%s",
Hai Shalomc3565922019-10-28 11:58:20 -07001237 conf->connector);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001238 }
Hai Shalomc3565922019-10-28 11:58:20 -07001239 if (conf->c_sign_key) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001240 char *hex;
1241 size_t hexlen;
1242
Hai Shalomc3565922019-10-28 11:58:20 -07001243 hexlen = 2 * wpabuf_len(conf->c_sign_key) + 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001244 hex = os_malloc(hexlen);
1245 if (hex) {
1246 wpa_snprintf_hex(hex, hexlen,
Hai Shalomc3565922019-10-28 11:58:20 -07001247 wpabuf_head(conf->c_sign_key),
1248 wpabuf_len(conf->c_sign_key));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001249 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_C_SIGN_KEY "%s",
1250 hex);
1251 os_free(hex);
1252 }
1253 }
1254 if (auth->net_access_key) {
1255 char *hex;
1256 size_t hexlen;
1257
1258 hexlen = 2 * wpabuf_len(auth->net_access_key) + 1;
1259 hex = os_malloc(hexlen);
1260 if (hex) {
1261 wpa_snprintf_hex(hex, hexlen,
1262 wpabuf_head(auth->net_access_key),
1263 wpabuf_len(auth->net_access_key));
1264 if (auth->net_access_key_expiry)
1265 wpa_msg(wpa_s, MSG_INFO,
1266 DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex,
1267 (long unsigned)
1268 auth->net_access_key_expiry);
1269 else
1270 wpa_msg(wpa_s, MSG_INFO,
1271 DPP_EVENT_NET_ACCESS_KEY "%s", hex);
1272 os_free(hex);
1273 }
1274 }
1275
Hai Shalomc3565922019-10-28 11:58:20 -07001276 return wpas_dpp_process_config(wpa_s, auth, conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001277}
1278
1279
Hai Shalomfdcde762020-04-02 11:19:20 -07001280static int wpas_dpp_handle_key_pkg(struct wpa_supplicant *wpa_s,
1281 struct dpp_asymmetric_key *key)
1282{
1283#ifdef CONFIG_DPP2
1284 int res;
1285
1286 if (!key)
1287 return 0;
1288
1289 wpa_printf(MSG_DEBUG, "DPP: Received Configurator backup");
1290 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
1291
1292 while (key) {
1293 res = dpp_configurator_from_backup(wpa_s->dpp, key);
1294 if (res < 0)
1295 return -1;
1296 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFIGURATOR_ID "%d",
1297 res);
1298 key = key->next;
1299 }
1300#endif /* CONFIG_DPP2 */
1301
1302 return 0;
1303}
1304
1305
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001306static void wpas_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token,
1307 enum gas_query_result result,
1308 const struct wpabuf *adv_proto,
1309 const struct wpabuf *resp, u16 status_code)
1310{
1311 struct wpa_supplicant *wpa_s = ctx;
1312 const u8 *pos;
1313 struct dpp_authentication *auth = wpa_s->dpp_auth;
Hai Shalom021b0b52019-04-10 11:17:58 -07001314 int res;
1315 enum dpp_status_error status = DPP_STATUS_CONFIG_REJECTED;
Hai Shalomc3565922019-10-28 11:58:20 -07001316 unsigned int i;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001317
Roshan Pius3a1667e2018-07-03 15:17:14 -07001318 wpa_s->dpp_gas_dialog_token = -1;
1319
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001320 if (!auth || !auth->auth_success) {
1321 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
1322 return;
1323 }
Hai Shalom74f70d42019-02-11 14:42:39 -08001324 if (result != GAS_QUERY_SUCCESS ||
1325 !resp || status_code != WLAN_STATUS_SUCCESS) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001326 wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed");
1327 goto fail;
1328 }
1329
1330 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto",
1331 adv_proto);
1332 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)",
1333 resp);
1334
1335 if (wpabuf_len(adv_proto) != 10 ||
1336 !(pos = wpabuf_head(adv_proto)) ||
1337 pos[0] != WLAN_EID_ADV_PROTO ||
1338 pos[1] != 8 ||
1339 pos[3] != WLAN_EID_VENDOR_SPECIFIC ||
1340 pos[4] != 5 ||
1341 WPA_GET_BE24(&pos[5]) != OUI_WFA ||
1342 pos[8] != 0x1a ||
1343 pos[9] != 1) {
1344 wpa_printf(MSG_DEBUG,
1345 "DPP: Not a DPP Advertisement Protocol ID");
1346 goto fail;
1347 }
1348
1349 if (dpp_conf_resp_rx(auth, resp) < 0) {
1350 wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed");
1351 goto fail;
1352 }
1353
Hai Shalomc3565922019-10-28 11:58:20 -07001354 for (i = 0; i < auth->num_conf_obj; i++) {
1355 res = wpas_dpp_handle_config_obj(wpa_s, auth,
1356 &auth->conf_obj[i]);
1357 if (res < 0)
1358 goto fail;
1359 }
1360 if (auth->num_conf_obj)
1361 wpas_dpp_post_process_config(wpa_s, auth);
Hai Shalomfdcde762020-04-02 11:19:20 -07001362 if (wpas_dpp_handle_key_pkg(wpa_s, auth->conf_key_pkg) < 0)
1363 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001364
Hai Shalom021b0b52019-04-10 11:17:58 -07001365 status = DPP_STATUS_OK;
1366#ifdef CONFIG_TESTING_OPTIONS
1367 if (dpp_test == DPP_TEST_REJECT_CONFIG) {
1368 wpa_printf(MSG_INFO, "DPP: TESTING - Reject Config Object");
1369 status = DPP_STATUS_CONFIG_REJECTED;
1370 }
1371#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001372fail:
Hai Shalom021b0b52019-04-10 11:17:58 -07001373 if (status != DPP_STATUS_OK) {
1374 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1375 wpas_notify_dpp_configuration_failure(wpa_s);
1376 }
1377#ifdef CONFIG_DPP2
1378 if (auth->peer_version >= 2 &&
1379 auth->conf_resp_status == DPP_STATUS_OK) {
1380 struct wpabuf *msg;
1381
1382 wpa_printf(MSG_DEBUG, "DPP: Send DPP Configuration Result");
1383 msg = dpp_build_conf_result(auth, status);
1384 if (!msg)
1385 goto fail2;
1386
1387 wpa_msg(wpa_s, MSG_INFO,
1388 DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1389 MAC2STR(addr), auth->curr_freq,
1390 DPP_PA_CONFIGURATION_RESULT);
1391 offchannel_send_action(wpa_s, auth->curr_freq,
1392 addr, wpa_s->own_addr, broadcast,
1393 wpabuf_head(msg),
1394 wpabuf_len(msg),
1395 500, wpas_dpp_tx_status, 0);
1396 wpabuf_free(msg);
1397
1398 /* This exchange will be terminated in the TX status handler */
1399 return;
1400 }
1401fail2:
1402#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001403 dpp_auth_deinit(wpa_s->dpp_auth);
1404 wpa_s->dpp_auth = NULL;
1405}
1406
1407
1408static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
1409{
1410 struct dpp_authentication *auth = wpa_s->dpp_auth;
Hai Shalom021b0b52019-04-10 11:17:58 -07001411 struct wpabuf *buf;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001412 int res;
Hai Shalomc3565922019-10-28 11:58:20 -07001413 int *supp_op_classes;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001414
1415 wpa_s->dpp_gas_client = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001416 offchannel_send_action_done(wpa_s);
1417 wpas_dpp_listen_stop(wpa_s);
1418
Hai Shalomc3565922019-10-28 11:58:20 -07001419 supp_op_classes = wpas_supp_op_classes(wpa_s);
1420 buf = dpp_build_conf_req_helper(auth, wpa_s->conf->dpp_name,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001421 wpa_s->dpp_netrole,
Hai Shalomc3565922019-10-28 11:58:20 -07001422 wpa_s->conf->dpp_mud_url,
1423 supp_op_classes);
1424 os_free(supp_op_classes);
Hai Shalom021b0b52019-04-10 11:17:58 -07001425 if (!buf) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001426 wpa_printf(MSG_DEBUG,
1427 "DPP: No configuration request data available");
1428 return;
1429 }
1430
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001431 wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
1432 MAC2STR(auth->peer_mac_addr), auth->curr_freq);
1433
1434 res = gas_query_req(wpa_s->gas, auth->peer_mac_addr, auth->curr_freq,
Jeff Changa5ae4a72020-04-24 03:47:18 +00001435 1, buf, wpas_dpp_gas_resp_cb, wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001436 if (res < 0) {
1437 wpa_msg(wpa_s, MSG_DEBUG, "GAS: Failed to send Query Request");
1438 wpabuf_free(buf);
1439 } else {
1440 wpa_printf(MSG_DEBUG,
1441 "DPP: GAS query started with dialog token %u", res);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001442 wpa_s->dpp_gas_dialog_token = res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001443 }
1444}
1445
1446
1447static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator)
1448{
1449 wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded");
1450 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d", initiator);
Hai Shalom706f99b2019-01-08 16:23:37 -08001451 wpas_notify_dpp_auth_success(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001452#ifdef CONFIG_TESTING_OPTIONS
1453 if (dpp_test == DPP_TEST_STOP_AT_AUTH_CONF) {
1454 wpa_printf(MSG_INFO,
1455 "DPP: TESTING - stop at Authentication Confirm");
1456 if (wpa_s->dpp_auth->configurator) {
1457 /* Prevent GAS response */
1458 wpa_s->dpp_auth->auth_success = 0;
1459 }
1460 return;
1461 }
1462#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001463
1464 if (wpa_s->dpp_auth->configurator)
1465 wpas_dpp_start_gas_server(wpa_s);
1466 else
1467 wpas_dpp_start_gas_client(wpa_s);
1468}
1469
1470
1471static void wpas_dpp_rx_auth_resp(struct wpa_supplicant *wpa_s, const u8 *src,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001472 const u8 *hdr, const u8 *buf, size_t len,
1473 unsigned int freq)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001474{
1475 struct dpp_authentication *auth = wpa_s->dpp_auth;
1476 struct wpabuf *msg;
1477
Roshan Pius3a1667e2018-07-03 15:17:14 -07001478 wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR
1479 " (freq %u MHz)", MAC2STR(src), freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001480
1481 if (!auth) {
1482 wpa_printf(MSG_DEBUG,
1483 "DPP: No DPP Authentication in progress - drop");
1484 return;
1485 }
1486
1487 if (!is_zero_ether_addr(auth->peer_mac_addr) &&
1488 os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1489 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1490 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1491 return;
1492 }
1493
1494 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
1495
Roshan Pius3a1667e2018-07-03 15:17:14 -07001496 if (auth->curr_freq != freq && auth->neg_freq == freq) {
1497 wpa_printf(MSG_DEBUG,
1498 "DPP: Responder accepted request for different negotiation channel");
1499 auth->curr_freq = freq;
1500 }
1501
1502 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001503 msg = dpp_auth_resp_rx(auth, hdr, buf, len);
1504 if (!msg) {
1505 if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) {
1506 wpa_printf(MSG_DEBUG,
1507 "DPP: Start wait for full response");
Hai Shalom706f99b2019-01-08 16:23:37 -08001508 wpas_notify_dpp_resp_pending(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001509 offchannel_send_action_done(wpa_s);
1510 wpas_dpp_listen_start(wpa_s, auth->curr_freq);
1511 return;
1512 }
1513 wpa_printf(MSG_DEBUG, "DPP: No confirm generated");
1514 return;
1515 }
1516 os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
1517
Roshan Pius3a1667e2018-07-03 15:17:14 -07001518 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1519 MAC2STR(src), auth->curr_freq, DPP_PA_AUTHENTICATION_CONF);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001520 offchannel_send_action(wpa_s, auth->curr_freq,
1521 src, wpa_s->own_addr, broadcast,
1522 wpabuf_head(msg), wpabuf_len(msg),
1523 500, wpas_dpp_tx_status, 0);
1524 wpabuf_free(msg);
1525 wpa_s->dpp_auth_ok_on_ack = 1;
1526}
1527
1528
1529static void wpas_dpp_rx_auth_conf(struct wpa_supplicant *wpa_s, const u8 *src,
1530 const u8 *hdr, const u8 *buf, size_t len)
1531{
1532 struct dpp_authentication *auth = wpa_s->dpp_auth;
1533
1534 wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR,
1535 MAC2STR(src));
1536
1537 if (!auth) {
1538 wpa_printf(MSG_DEBUG,
1539 "DPP: No DPP Authentication in progress - drop");
1540 return;
1541 }
1542
1543 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1544 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1545 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1546 return;
1547 }
1548
1549 if (dpp_auth_conf_rx(auth, hdr, buf, len) < 0) {
1550 wpa_printf(MSG_DEBUG, "DPP: Authentication failed");
Hai Shalom706f99b2019-01-08 16:23:37 -08001551 wpas_notify_dpp_auth_failure(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001552 return;
1553 }
1554
1555 wpas_dpp_auth_success(wpa_s, 0);
1556}
1557
1558
Hai Shalom021b0b52019-04-10 11:17:58 -07001559#ifdef CONFIG_DPP2
1560
1561static void wpas_dpp_config_result_wait_timeout(void *eloop_ctx,
1562 void *timeout_ctx)
1563{
1564 struct wpa_supplicant *wpa_s = eloop_ctx;
1565 struct dpp_authentication *auth = wpa_s->dpp_auth;
1566
1567 if (!auth || !auth->waiting_conf_result)
1568 return;
1569
1570 wpa_printf(MSG_DEBUG,
1571 "DPP: Timeout while waiting for Configuration Result");
1572 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom06768112019-12-04 15:49:43 -08001573 wpas_notify_dpp_configuration_failure(wpa_s);
Hai Shalom021b0b52019-04-10 11:17:58 -07001574 dpp_auth_deinit(auth);
1575 wpa_s->dpp_auth = NULL;
1576}
1577
1578
Hai Shalomc3565922019-10-28 11:58:20 -07001579static void wpas_dpp_conn_status_result_wait_timeout(void *eloop_ctx,
1580 void *timeout_ctx)
1581{
1582 struct wpa_supplicant *wpa_s = eloop_ctx;
1583 struct dpp_authentication *auth = wpa_s->dpp_auth;
1584
1585 if (!auth || !auth->waiting_conn_status_result)
1586 return;
1587
1588 wpa_printf(MSG_DEBUG,
1589 "DPP: Timeout while waiting for Connection Status Result");
1590 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONN_STATUS_RESULT "timeout");
Hai Shalom06768112019-12-04 15:49:43 -08001591 wpas_notify_dpp_timeout(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07001592 wpas_dpp_listen_stop(wpa_s);
1593 dpp_auth_deinit(auth);
1594 wpa_s->dpp_auth = NULL;
1595}
1596
1597
Hai Shalom021b0b52019-04-10 11:17:58 -07001598static void wpas_dpp_rx_conf_result(struct wpa_supplicant *wpa_s, const u8 *src,
1599 const u8 *hdr, const u8 *buf, size_t len)
1600{
1601 struct dpp_authentication *auth = wpa_s->dpp_auth;
1602 enum dpp_status_error status;
1603
1604 wpa_printf(MSG_DEBUG, "DPP: Configuration Result from " MACSTR,
1605 MAC2STR(src));
1606
1607 if (!auth || !auth->waiting_conf_result) {
1608 wpa_printf(MSG_DEBUG,
1609 "DPP: No DPP Configuration waiting for result - drop");
1610 return;
1611 }
1612
1613 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1614 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1615 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1616 return;
1617 }
1618
1619 status = dpp_conf_result_rx(auth, hdr, buf, len);
1620
Hai Shalomc3565922019-10-28 11:58:20 -07001621 if (status == DPP_STATUS_OK && auth->send_conn_status) {
1622 wpa_msg(wpa_s, MSG_INFO,
1623 DPP_EVENT_CONF_SENT "wait_conn_status=1");
1624 wpa_printf(MSG_DEBUG, "DPP: Wait for Connection Status Result");
Hai Shalom06768112019-12-04 15:49:43 -08001625 wpas_notify_dpp_config_accepted(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07001626 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout,
1627 wpa_s, NULL);
1628 auth->waiting_conn_status_result = 1;
1629 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout,
1630 wpa_s, NULL);
1631 eloop_register_timeout(16, 0,
1632 wpas_dpp_conn_status_result_wait_timeout,
1633 wpa_s, NULL);
1634 offchannel_send_action_done(wpa_s);
1635 wpas_dpp_listen_start(wpa_s, auth->neg_freq ? auth->neg_freq :
1636 auth->curr_freq);
1637 return;
1638 }
Hai Shalom021b0b52019-04-10 11:17:58 -07001639 offchannel_send_action_done(wpa_s);
1640 wpas_dpp_listen_stop(wpa_s);
Hai Shalome4073332019-11-05 16:20:12 -08001641 if (status == DPP_STATUS_OK) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001642 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
Hai Shalome4073332019-11-05 16:20:12 -08001643 wpas_notify_dpp_config_sent(wpa_s);
1644 }
1645 else {
Hai Shalom021b0b52019-04-10 11:17:58 -07001646 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom06768112019-12-04 15:49:43 -08001647 wpas_notify_dpp_config_rejected(wpa_s);
Hai Shalome4073332019-11-05 16:20:12 -08001648 }
Hai Shalom021b0b52019-04-10 11:17:58 -07001649 dpp_auth_deinit(auth);
1650 wpa_s->dpp_auth = NULL;
1651 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL);
1652}
1653
Hai Shalom81f62d82019-07-22 12:10:00 -07001654
Hai Shalomc3565922019-10-28 11:58:20 -07001655static void wpas_dpp_rx_conn_status_result(struct wpa_supplicant *wpa_s,
1656 const u8 *src, const u8 *hdr,
1657 const u8 *buf, size_t len)
1658{
1659 struct dpp_authentication *auth = wpa_s->dpp_auth;
1660 enum dpp_status_error status;
1661 u8 ssid[SSID_MAX_LEN];
1662 size_t ssid_len = 0;
1663 char *channel_list = NULL;
1664
1665 wpa_printf(MSG_DEBUG, "DPP: Connection Status Result");
1666
1667 if (!auth || !auth->waiting_conn_status_result) {
1668 wpa_printf(MSG_DEBUG,
1669 "DPP: No DPP Configuration waiting for connection status result - drop");
1670 return;
1671 }
1672
1673 status = dpp_conn_status_result_rx(auth, hdr, buf, len,
1674 ssid, &ssid_len, &channel_list);
1675 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONN_STATUS_RESULT
1676 "result=%d ssid=%s channel_list=%s",
1677 status, wpa_ssid_txt(ssid, ssid_len),
1678 channel_list ? channel_list : "N/A");
Hai Shalom06768112019-12-04 15:49:43 -08001679 wpas_notify_dpp_conn_status(wpa_s, status, wpa_ssid_txt(ssid, ssid_len),
1680 channel_list, auth->band_list, auth->band_list_size);
Hai Shalomc3565922019-10-28 11:58:20 -07001681 os_free(channel_list);
1682 offchannel_send_action_done(wpa_s);
1683 wpas_dpp_listen_stop(wpa_s);
1684 dpp_auth_deinit(auth);
1685 wpa_s->dpp_auth = NULL;
1686 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout,
1687 wpa_s, NULL);
1688}
1689
1690
Hai Shalom81f62d82019-07-22 12:10:00 -07001691static int wpas_dpp_process_conf_obj(void *ctx,
1692 struct dpp_authentication *auth)
1693{
1694 struct wpa_supplicant *wpa_s = ctx;
Hai Shalomc3565922019-10-28 11:58:20 -07001695 unsigned int i;
1696 int res = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -07001697
Hai Shalomc3565922019-10-28 11:58:20 -07001698 for (i = 0; i < auth->num_conf_obj; i++) {
1699 res = wpas_dpp_handle_config_obj(wpa_s, auth,
1700 &auth->conf_obj[i]);
1701 if (res)
1702 break;
1703 }
1704 if (!res)
1705 wpas_dpp_post_process_config(wpa_s, auth);
1706
1707 return res;
Hai Shalom81f62d82019-07-22 12:10:00 -07001708}
1709
Hai Shalomfdcde762020-04-02 11:19:20 -07001710
1711static void wpas_dpp_remove_bi(void *ctx, struct dpp_bootstrap_info *bi)
1712{
1713 struct wpa_supplicant *wpa_s = ctx;
1714
1715 if (bi == wpa_s->dpp_chirp_bi)
1716 wpas_dpp_chirp_stop(wpa_s);
1717}
1718
1719
1720static void
1721wpas_dpp_rx_presence_announcement(struct wpa_supplicant *wpa_s, const u8 *src,
1722 const u8 *hdr, const u8 *buf, size_t len,
1723 unsigned int freq)
1724{
1725 const u8 *r_bootstrap;
1726 u16 r_bootstrap_len;
1727 struct dpp_bootstrap_info *peer_bi;
1728 struct dpp_authentication *auth;
1729
1730 if (!wpa_s->dpp)
1731 return;
1732
1733 if (wpa_s->dpp_auth) {
1734 wpa_printf(MSG_DEBUG,
1735 "DPP: Ignore Presence Announcement during ongoing Authentication");
1736 return;
1737 }
1738
1739 wpa_printf(MSG_DEBUG, "DPP: Presence Announcement from " MACSTR,
1740 MAC2STR(src));
1741
1742 r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
1743 &r_bootstrap_len);
1744 if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
1745 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1746 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
1747 return;
1748 }
1749 wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
1750 r_bootstrap, r_bootstrap_len);
1751 peer_bi = dpp_bootstrap_find_chirp(wpa_s->dpp, r_bootstrap);
1752 if (!peer_bi) {
1753 wpa_printf(MSG_DEBUG,
1754 "DPP: No matching bootstrapping information found");
1755 return;
1756 }
1757
1758 auth = dpp_auth_init(wpa_s->dpp, wpa_s, peer_bi, NULL,
1759 DPP_CAPAB_CONFIGURATOR, freq, NULL, 0);
1760 if (!auth)
1761 return;
1762 wpas_dpp_set_testing_options(wpa_s, auth);
1763 if (dpp_set_configurator(auth, wpa_s->dpp_configurator_params) < 0) {
1764 dpp_auth_deinit(auth);
1765 return;
1766 }
1767
1768 auth->neg_freq = freq;
1769
1770 if (!is_zero_ether_addr(peer_bi->mac_addr))
1771 os_memcpy(auth->peer_mac_addr, peer_bi->mac_addr, ETH_ALEN);
1772
1773 wpa_s->dpp_auth = auth;
1774 if (wpas_dpp_auth_init_next(wpa_s) < 0) {
1775 dpp_auth_deinit(wpa_s->dpp_auth);
1776 wpa_s->dpp_auth = NULL;
1777 }
1778}
1779
Hai Shalom021b0b52019-04-10 11:17:58 -07001780#endif /* CONFIG_DPP2 */
1781
1782
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001783static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant *wpa_s,
1784 const u8 *src,
1785 const u8 *buf, size_t len)
1786{
1787 struct wpa_ssid *ssid;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001788 const u8 *connector, *trans_id, *status;
1789 u16 connector_len, trans_id_len, status_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001790 struct dpp_introduction intro;
1791 struct rsn_pmksa_cache_entry *entry;
1792 struct os_time now;
1793 struct os_reltime rnow;
1794 os_time_t expiry;
1795 unsigned int seconds;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001796 enum dpp_status_error res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001797
1798 wpa_printf(MSG_DEBUG, "DPP: Peer Discovery Response from " MACSTR,
1799 MAC2STR(src));
1800 if (is_zero_ether_addr(wpa_s->dpp_intro_bssid) ||
1801 os_memcmp(src, wpa_s->dpp_intro_bssid, ETH_ALEN) != 0) {
1802 wpa_printf(MSG_DEBUG, "DPP: Not waiting for response from "
1803 MACSTR " - drop", MAC2STR(src));
1804 return;
1805 }
1806 offchannel_send_action_done(wpa_s);
1807
1808 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1809 if (ssid == wpa_s->dpp_intro_network)
1810 break;
1811 }
1812 if (!ssid || !ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1813 !ssid->dpp_csign) {
1814 wpa_printf(MSG_DEBUG,
1815 "DPP: Profile not found for network introduction");
1816 return;
1817 }
1818
1819 trans_id = dpp_get_attr(buf, len, DPP_ATTR_TRANSACTION_ID,
1820 &trans_id_len);
1821 if (!trans_id || trans_id_len != 1) {
1822 wpa_printf(MSG_DEBUG,
1823 "DPP: Peer did not include Transaction ID");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001824 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1825 " fail=missing_transaction_id", MAC2STR(src));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001826 goto fail;
1827 }
1828 if (trans_id[0] != TRANSACTION_ID) {
1829 wpa_printf(MSG_DEBUG,
1830 "DPP: Ignore frame with unexpected Transaction ID %u",
1831 trans_id[0]);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001832 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1833 " fail=transaction_id_mismatch", MAC2STR(src));
1834 goto fail;
1835 }
1836
1837 status = dpp_get_attr(buf, len, DPP_ATTR_STATUS, &status_len);
1838 if (!status || status_len != 1) {
1839 wpa_printf(MSG_DEBUG, "DPP: Peer did not include Status");
1840 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1841 " fail=missing_status", MAC2STR(src));
1842 goto fail;
1843 }
1844 if (status[0] != DPP_STATUS_OK) {
1845 wpa_printf(MSG_DEBUG,
1846 "DPP: Peer rejected network introduction: Status %u",
1847 status[0]);
1848 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1849 " status=%u", MAC2STR(src), status[0]);
Hai Shalomc3565922019-10-28 11:58:20 -07001850#ifdef CONFIG_DPP2
1851 wpas_dpp_send_conn_status_result(wpa_s, status[0]);
1852#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001853 goto fail;
1854 }
1855
1856 connector = dpp_get_attr(buf, len, DPP_ATTR_CONNECTOR, &connector_len);
1857 if (!connector) {
1858 wpa_printf(MSG_DEBUG,
1859 "DPP: Peer did not include its Connector");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001860 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1861 " fail=missing_connector", MAC2STR(src));
1862 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001863 }
1864
Roshan Pius3a1667e2018-07-03 15:17:14 -07001865 res = dpp_peer_intro(&intro, ssid->dpp_connector,
1866 ssid->dpp_netaccesskey,
1867 ssid->dpp_netaccesskey_len,
1868 ssid->dpp_csign,
1869 ssid->dpp_csign_len,
1870 connector, connector_len, &expiry);
1871 if (res != DPP_STATUS_OK) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001872 wpa_printf(MSG_INFO,
1873 "DPP: Network Introduction protocol resulted in failure");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001874 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1875 " fail=peer_connector_validation_failed", MAC2STR(src));
Hai Shalomc3565922019-10-28 11:58:20 -07001876#ifdef CONFIG_DPP2
1877 wpas_dpp_send_conn_status_result(wpa_s, res);
1878#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001879 goto fail;
1880 }
1881
1882 entry = os_zalloc(sizeof(*entry));
1883 if (!entry)
1884 goto fail;
1885 os_memcpy(entry->aa, src, ETH_ALEN);
1886 os_memcpy(entry->pmkid, intro.pmkid, PMKID_LEN);
1887 os_memcpy(entry->pmk, intro.pmk, intro.pmk_len);
1888 entry->pmk_len = intro.pmk_len;
1889 entry->akmp = WPA_KEY_MGMT_DPP;
1890 if (expiry) {
1891 os_get_time(&now);
1892 seconds = expiry - now.sec;
1893 } else {
1894 seconds = 86400 * 7;
1895 }
1896 os_get_reltime(&rnow);
1897 entry->expiration = rnow.sec + seconds;
1898 entry->reauth_time = rnow.sec + seconds;
1899 entry->network_ctx = ssid;
1900 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
1901
Roshan Pius3a1667e2018-07-03 15:17:14 -07001902 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1903 " status=%u", MAC2STR(src), status[0]);
1904
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001905 wpa_printf(MSG_DEBUG,
1906 "DPP: Try connection again after successful network introduction");
1907 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
1908 wpa_supplicant_cancel_sched_scan(wpa_s);
1909 wpa_supplicant_req_scan(wpa_s, 0, 0);
1910 }
1911fail:
1912 os_memset(&intro, 0, sizeof(intro));
1913}
1914
1915
Roshan Pius3a1667e2018-07-03 15:17:14 -07001916static int wpas_dpp_allow_ir(struct wpa_supplicant *wpa_s, unsigned int freq)
1917{
1918 int i, j;
1919
1920 if (!wpa_s->hw.modes)
1921 return -1;
1922
1923 for (i = 0; i < wpa_s->hw.num_modes; i++) {
1924 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
1925
1926 for (j = 0; j < mode->num_channels; j++) {
1927 struct hostapd_channel_data *chan = &mode->channels[j];
1928
1929 if (chan->freq != (int) freq)
1930 continue;
1931
1932 if (chan->flag & (HOSTAPD_CHAN_DISABLED |
1933 HOSTAPD_CHAN_NO_IR |
1934 HOSTAPD_CHAN_RADAR))
1935 continue;
1936
1937 return 1;
1938 }
1939 }
1940
1941 wpa_printf(MSG_DEBUG,
1942 "DPP: Frequency %u MHz not supported or does not allow PKEX initiation in the current channel list",
1943 freq);
1944
1945 return 0;
1946}
1947
1948
1949static int wpas_dpp_pkex_next_channel(struct wpa_supplicant *wpa_s,
1950 struct dpp_pkex *pkex)
1951{
1952 if (pkex->freq == 2437)
1953 pkex->freq = 5745;
1954 else if (pkex->freq == 5745)
1955 pkex->freq = 5220;
1956 else if (pkex->freq == 5220)
1957 pkex->freq = 60480;
1958 else
1959 return -1; /* no more channels to try */
1960
1961 if (wpas_dpp_allow_ir(wpa_s, pkex->freq) == 1) {
1962 wpa_printf(MSG_DEBUG, "DPP: Try to initiate on %u MHz",
1963 pkex->freq);
1964 return 0;
1965 }
1966
1967 /* Could not use this channel - try the next one */
1968 return wpas_dpp_pkex_next_channel(wpa_s, pkex);
1969}
1970
1971
1972static void wpas_dpp_pkex_retry_timeout(void *eloop_ctx, void *timeout_ctx)
1973{
1974 struct wpa_supplicant *wpa_s = eloop_ctx;
1975 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1976
1977 if (!pkex || !pkex->exchange_req)
1978 return;
1979 if (pkex->exch_req_tries >= 5) {
1980 if (wpas_dpp_pkex_next_channel(wpa_s, pkex) < 0) {
1981 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1982 "No response from PKEX peer");
1983 dpp_pkex_free(pkex);
1984 wpa_s->dpp_pkex = NULL;
1985 return;
1986 }
1987 pkex->exch_req_tries = 0;
1988 }
1989
1990 pkex->exch_req_tries++;
1991 wpa_printf(MSG_DEBUG, "DPP: Retransmit PKEX Exchange Request (try %u)",
1992 pkex->exch_req_tries);
1993 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1994 MAC2STR(broadcast), pkex->freq, DPP_PA_PKEX_EXCHANGE_REQ);
1995 offchannel_send_action(wpa_s, pkex->freq, broadcast,
1996 wpa_s->own_addr, broadcast,
1997 wpabuf_head(pkex->exchange_req),
1998 wpabuf_len(pkex->exchange_req),
1999 pkex->exch_req_wait_time,
2000 wpas_dpp_tx_pkex_status, 0);
2001}
2002
2003
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002004static void
2005wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s,
2006 unsigned int freq, const u8 *dst,
2007 const u8 *src, const u8 *bssid,
2008 const u8 *data, size_t data_len,
2009 enum offchannel_send_action_result result)
2010{
Roshan Pius3a1667e2018-07-03 15:17:14 -07002011 const char *res_txt;
2012 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
2013
2014 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
2015 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
2016 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002017 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
2018 " result=%s (PKEX)",
Roshan Pius3a1667e2018-07-03 15:17:14 -07002019 freq, MAC2STR(dst), res_txt);
2020 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
2021 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
2022
2023 if (!pkex) {
2024 wpa_printf(MSG_DEBUG,
2025 "DPP: Ignore TX status since there is no ongoing PKEX exchange");
2026 return;
2027 }
2028
2029 if (pkex->failed) {
2030 wpa_printf(MSG_DEBUG,
2031 "DPP: Terminate PKEX exchange due to an earlier error");
2032 if (pkex->t > pkex->own_bi->pkex_t)
2033 pkex->own_bi->pkex_t = pkex->t;
2034 dpp_pkex_free(pkex);
2035 wpa_s->dpp_pkex = NULL;
2036 return;
2037 }
2038
2039 if (pkex->exch_req_wait_time && pkex->exchange_req) {
2040 /* Wait for PKEX Exchange Response frame and retry request if
2041 * no response is seen. */
2042 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
2043 eloop_register_timeout(pkex->exch_req_wait_time / 1000,
2044 (pkex->exch_req_wait_time % 1000) * 1000,
2045 wpas_dpp_pkex_retry_timeout, wpa_s,
2046 NULL);
2047 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002048}
2049
2050
2051static void
2052wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant *wpa_s, const u8 *src,
2053 const u8 *buf, size_t len, unsigned int freq)
2054{
2055 struct wpabuf *msg;
2056 unsigned int wait_time;
2057
2058 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Request from " MACSTR,
2059 MAC2STR(src));
2060
2061 /* TODO: Support multiple PKEX codes by iterating over all the enabled
2062 * values here */
2063
2064 if (!wpa_s->dpp_pkex_code || !wpa_s->dpp_pkex_bi) {
2065 wpa_printf(MSG_DEBUG,
2066 "DPP: No PKEX code configured - ignore request");
2067 return;
2068 }
2069
2070 if (wpa_s->dpp_pkex) {
2071 /* TODO: Support parallel operations */
2072 wpa_printf(MSG_DEBUG,
2073 "DPP: Already in PKEX session - ignore new request");
2074 return;
2075 }
2076
Roshan Pius3a1667e2018-07-03 15:17:14 -07002077 wpa_s->dpp_pkex = dpp_pkex_rx_exchange_req(wpa_s, wpa_s->dpp_pkex_bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002078 wpa_s->own_addr, src,
2079 wpa_s->dpp_pkex_identifier,
2080 wpa_s->dpp_pkex_code,
2081 buf, len);
2082 if (!wpa_s->dpp_pkex) {
2083 wpa_printf(MSG_DEBUG,
2084 "DPP: Failed to process the request - ignore it");
2085 return;
2086 }
2087
2088 msg = wpa_s->dpp_pkex->exchange_resp;
2089 wait_time = wpa_s->max_remain_on_chan;
2090 if (wait_time > 2000)
2091 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002092 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2093 MAC2STR(src), freq, DPP_PA_PKEX_EXCHANGE_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002094 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
2095 broadcast,
2096 wpabuf_head(msg), wpabuf_len(msg),
2097 wait_time, wpas_dpp_tx_pkex_status, 0);
2098}
2099
2100
2101static void
2102wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant *wpa_s, const u8 *src,
2103 const u8 *buf, size_t len, unsigned int freq)
2104{
2105 struct wpabuf *msg;
2106 unsigned int wait_time;
2107
2108 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Response from " MACSTR,
2109 MAC2STR(src));
2110
2111 /* TODO: Support multiple PKEX codes by iterating over all the enabled
2112 * values here */
2113
2114 if (!wpa_s->dpp_pkex || !wpa_s->dpp_pkex->initiator ||
2115 wpa_s->dpp_pkex->exchange_done) {
2116 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
2117 return;
2118 }
2119
Roshan Pius3a1667e2018-07-03 15:17:14 -07002120 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
2121 wpa_s->dpp_pkex->exch_req_wait_time = 0;
2122
2123 msg = dpp_pkex_rx_exchange_resp(wpa_s->dpp_pkex, src, buf, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002124 if (!msg) {
2125 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
2126 return;
2127 }
2128
2129 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Request to " MACSTR,
2130 MAC2STR(src));
2131
2132 wait_time = wpa_s->max_remain_on_chan;
2133 if (wait_time > 2000)
2134 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002135 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2136 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_REQ);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002137 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
2138 broadcast,
2139 wpabuf_head(msg), wpabuf_len(msg),
2140 wait_time, wpas_dpp_tx_pkex_status, 0);
2141 wpabuf_free(msg);
2142}
2143
2144
Roshan Pius3a1667e2018-07-03 15:17:14 -07002145static struct dpp_bootstrap_info *
2146wpas_dpp_pkex_finish(struct wpa_supplicant *wpa_s, const u8 *peer,
2147 unsigned int freq)
2148{
Roshan Pius3a1667e2018-07-03 15:17:14 -07002149 struct dpp_bootstrap_info *bi;
2150
Hai Shalom021b0b52019-04-10 11:17:58 -07002151 bi = dpp_pkex_finish(wpa_s->dpp, wpa_s->dpp_pkex, peer, freq);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002152 if (!bi)
2153 return NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002154 wpa_s->dpp_pkex = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002155 return bi;
2156}
2157
2158
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002159static void
2160wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant *wpa_s, const u8 *src,
2161 const u8 *hdr, const u8 *buf, size_t len,
2162 unsigned int freq)
2163{
2164 struct wpabuf *msg;
2165 unsigned int wait_time;
2166 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002167
2168 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Request from " MACSTR,
2169 MAC2STR(src));
2170
2171 if (!pkex || pkex->initiator || !pkex->exchange_done) {
2172 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
2173 return;
2174 }
2175
2176 msg = dpp_pkex_rx_commit_reveal_req(pkex, hdr, buf, len);
2177 if (!msg) {
2178 wpa_printf(MSG_DEBUG, "DPP: Failed to process the request");
Roshan Pius3a1667e2018-07-03 15:17:14 -07002179 if (pkex->failed) {
2180 wpa_printf(MSG_DEBUG, "DPP: Terminate PKEX exchange");
2181 if (pkex->t > pkex->own_bi->pkex_t)
2182 pkex->own_bi->pkex_t = pkex->t;
2183 dpp_pkex_free(wpa_s->dpp_pkex);
2184 wpa_s->dpp_pkex = NULL;
2185 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002186 return;
2187 }
2188
2189 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Response to "
2190 MACSTR, MAC2STR(src));
2191
2192 wait_time = wpa_s->max_remain_on_chan;
2193 if (wait_time > 2000)
2194 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002195 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2196 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002197 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
2198 broadcast,
2199 wpabuf_head(msg), wpabuf_len(msg),
2200 wait_time, wpas_dpp_tx_pkex_status, 0);
2201 wpabuf_free(msg);
2202
Roshan Pius3a1667e2018-07-03 15:17:14 -07002203 wpas_dpp_pkex_finish(wpa_s, src, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002204}
2205
2206
2207static void
2208wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant *wpa_s, const u8 *src,
2209 const u8 *hdr, const u8 *buf, size_t len,
2210 unsigned int freq)
2211{
2212 int res;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002213 struct dpp_bootstrap_info *bi;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002214 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
2215 char cmd[500];
2216
2217 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Response from " MACSTR,
2218 MAC2STR(src));
2219
2220 if (!pkex || !pkex->initiator || !pkex->exchange_done) {
2221 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
2222 return;
2223 }
2224
2225 res = dpp_pkex_rx_commit_reveal_resp(pkex, hdr, buf, len);
2226 if (res < 0) {
2227 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
2228 return;
2229 }
2230
Roshan Pius3a1667e2018-07-03 15:17:14 -07002231 bi = wpas_dpp_pkex_finish(wpa_s, src, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002232 if (!bi)
2233 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002234
2235 os_snprintf(cmd, sizeof(cmd), " peer=%u %s",
2236 bi->id,
2237 wpa_s->dpp_pkex_auth_cmd ? wpa_s->dpp_pkex_auth_cmd : "");
2238 wpa_printf(MSG_DEBUG,
2239 "DPP: Start authentication after PKEX with parameters: %s",
2240 cmd);
2241 if (wpas_dpp_auth_init(wpa_s, cmd) < 0) {
2242 wpa_printf(MSG_DEBUG,
2243 "DPP: Authentication initialization failed");
Hai Shalomfdcde762020-04-02 11:19:20 -07002244 offchannel_send_action_done(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002245 return;
2246 }
2247}
2248
2249
2250void wpas_dpp_rx_action(struct wpa_supplicant *wpa_s, const u8 *src,
2251 const u8 *buf, size_t len, unsigned int freq)
2252{
2253 u8 crypto_suite;
2254 enum dpp_public_action_frame_type type;
2255 const u8 *hdr;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002256 unsigned int pkex_t;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002257
2258 if (len < DPP_HDR_LEN)
2259 return;
2260 if (WPA_GET_BE24(buf) != OUI_WFA || buf[3] != DPP_OUI_TYPE)
2261 return;
2262 hdr = buf;
2263 buf += 4;
2264 len -= 4;
2265 crypto_suite = *buf++;
2266 type = *buf++;
2267 len -= 2;
2268
2269 wpa_printf(MSG_DEBUG,
2270 "DPP: Received DPP Public Action frame crypto suite %u type %d from "
2271 MACSTR " freq=%u",
2272 crypto_suite, type, MAC2STR(src), freq);
2273 if (crypto_suite != 1) {
2274 wpa_printf(MSG_DEBUG, "DPP: Unsupported crypto suite %u",
2275 crypto_suite);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002276 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
2277 " freq=%u type=%d ignore=unsupported-crypto-suite",
2278 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002279 return;
2280 }
2281 wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002282 if (dpp_check_attrs(buf, len) < 0) {
2283 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
2284 " freq=%u type=%d ignore=invalid-attributes",
2285 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002286 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002287 }
2288 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR " freq=%u type=%d",
2289 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002290
2291 switch (type) {
2292 case DPP_PA_AUTHENTICATION_REQ:
2293 wpas_dpp_rx_auth_req(wpa_s, src, hdr, buf, len, freq);
2294 break;
2295 case DPP_PA_AUTHENTICATION_RESP:
Roshan Pius3a1667e2018-07-03 15:17:14 -07002296 wpas_dpp_rx_auth_resp(wpa_s, src, hdr, buf, len, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002297 break;
2298 case DPP_PA_AUTHENTICATION_CONF:
2299 wpas_dpp_rx_auth_conf(wpa_s, src, hdr, buf, len);
2300 break;
2301 case DPP_PA_PEER_DISCOVERY_RESP:
2302 wpas_dpp_rx_peer_disc_resp(wpa_s, src, buf, len);
2303 break;
2304 case DPP_PA_PKEX_EXCHANGE_REQ:
2305 wpas_dpp_rx_pkex_exchange_req(wpa_s, src, buf, len, freq);
2306 break;
2307 case DPP_PA_PKEX_EXCHANGE_RESP:
2308 wpas_dpp_rx_pkex_exchange_resp(wpa_s, src, buf, len, freq);
2309 break;
2310 case DPP_PA_PKEX_COMMIT_REVEAL_REQ:
2311 wpas_dpp_rx_pkex_commit_reveal_req(wpa_s, src, hdr, buf, len,
2312 freq);
2313 break;
2314 case DPP_PA_PKEX_COMMIT_REVEAL_RESP:
2315 wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s, src, hdr, buf, len,
2316 freq);
2317 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07002318#ifdef CONFIG_DPP2
2319 case DPP_PA_CONFIGURATION_RESULT:
2320 wpas_dpp_rx_conf_result(wpa_s, src, hdr, buf, len);
2321 break;
Hai Shalomc3565922019-10-28 11:58:20 -07002322 case DPP_PA_CONNECTION_STATUS_RESULT:
2323 wpas_dpp_rx_conn_status_result(wpa_s, src, hdr, buf, len);
2324 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07002325 case DPP_PA_PRESENCE_ANNOUNCEMENT:
2326 wpas_dpp_rx_presence_announcement(wpa_s, src, hdr, buf, len,
2327 freq);
2328 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07002329#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002330 default:
2331 wpa_printf(MSG_DEBUG,
2332 "DPP: Ignored unsupported frame subtype %d", type);
2333 break;
2334 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002335
2336 if (wpa_s->dpp_pkex)
2337 pkex_t = wpa_s->dpp_pkex->t;
2338 else if (wpa_s->dpp_pkex_bi)
2339 pkex_t = wpa_s->dpp_pkex_bi->pkex_t;
2340 else
2341 pkex_t = 0;
2342 if (pkex_t >= PKEX_COUNTER_T_LIMIT) {
2343 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_PKEX_T_LIMIT "id=0");
2344 wpas_dpp_pkex_remove(wpa_s, "*");
2345 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002346}
2347
2348
2349static struct wpabuf *
2350wpas_dpp_gas_req_handler(void *ctx, const u8 *sa, const u8 *query,
2351 size_t query_len)
2352{
2353 struct wpa_supplicant *wpa_s = ctx;
2354 struct dpp_authentication *auth = wpa_s->dpp_auth;
2355 struct wpabuf *resp;
2356
2357 wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR,
2358 MAC2STR(sa));
2359 if (!auth || !auth->auth_success ||
2360 os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) {
2361 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
2362 return NULL;
2363 }
Hai Shalomc3565922019-10-28 11:58:20 -07002364
2365 if (wpa_s->dpp_auth_ok_on_ack && auth->configurator) {
2366 wpa_printf(MSG_DEBUG,
2367 "DPP: Have not received ACK for Auth Confirm yet - assume it was received based on this GAS request");
2368 /* wpas_dpp_auth_success() would normally have been called from
2369 * TX status handler, but since there was no such handler call
2370 * yet, simply send out the event message and proceed with
2371 * exchange. */
2372 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=1");
2373 wpa_s->dpp_auth_ok_on_ack = 0;
2374 }
2375
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002376 wpa_hexdump(MSG_DEBUG,
2377 "DPP: Received Configuration Request (GAS Query Request)",
2378 query, query_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002379 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_REQ_RX "src=" MACSTR,
2380 MAC2STR(sa));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002381 resp = dpp_conf_req_rx(auth, query, query_len);
Hai Shalom59532852018-12-07 10:32:58 -08002382 if (!resp) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002383 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -08002384 wpas_notify_dpp_configuration_failure(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08002385 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002386 auth->conf_resp = resp;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002387 return resp;
2388}
2389
2390
2391static void
2392wpas_dpp_gas_status_handler(void *ctx, struct wpabuf *resp, int ok)
2393{
2394 struct wpa_supplicant *wpa_s = ctx;
2395 struct dpp_authentication *auth = wpa_s->dpp_auth;
2396
2397 if (!auth) {
2398 wpabuf_free(resp);
2399 return;
2400 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002401 if (auth->conf_resp != resp) {
2402 wpa_printf(MSG_DEBUG,
2403 "DPP: Ignore GAS status report (ok=%d) for unknown response",
2404 ok);
2405 wpabuf_free(resp);
2406 return;
2407 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002408
2409 wpa_printf(MSG_DEBUG, "DPP: Configuration exchange completed (ok=%d)",
2410 ok);
2411 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002412 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07002413#ifdef CONFIG_DPP2
2414 if (ok && auth->peer_version >= 2 &&
2415 auth->conf_resp_status == DPP_STATUS_OK) {
2416 wpa_printf(MSG_DEBUG, "DPP: Wait for Configuration Result");
Hai Shalom06768112019-12-04 15:49:43 -08002417 wpas_notify_dpp_config_sent_wait_response(wpa_s);
Hai Shalom021b0b52019-04-10 11:17:58 -07002418 auth->waiting_conf_result = 1;
2419 auth->conf_resp = NULL;
2420 wpabuf_free(resp);
2421 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout,
2422 wpa_s, NULL);
2423 eloop_register_timeout(2, 0,
2424 wpas_dpp_config_result_wait_timeout,
2425 wpa_s, NULL);
2426 return;
2427 }
2428#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002429 offchannel_send_action_done(wpa_s);
2430 wpas_dpp_listen_stop(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08002431 if (ok) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002432 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
Hai Shalom706f99b2019-01-08 16:23:37 -08002433 wpas_notify_dpp_config_sent(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08002434 }
2435 else {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002436 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -08002437 wpas_notify_dpp_configuration_failure(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08002438 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002439 dpp_auth_deinit(wpa_s->dpp_auth);
2440 wpa_s->dpp_auth = NULL;
2441 wpabuf_free(resp);
2442}
2443
2444
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002445int wpas_dpp_configurator_sign(struct wpa_supplicant *wpa_s, const char *cmd)
2446{
2447 struct dpp_authentication *auth;
2448 int ret = -1;
2449 char *curve = NULL;
2450
Hai Shalomfdcde762020-04-02 11:19:20 -07002451 auth = dpp_alloc_auth(wpa_s->dpp, wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002452 if (!auth)
2453 return -1;
2454
2455 curve = get_param(cmd, " curve=");
Hai Shalom74f70d42019-02-11 14:42:39 -08002456 wpas_dpp_set_testing_options(wpa_s, auth);
Hai Shalomfdcde762020-04-02 11:19:20 -07002457 if (dpp_set_configurator(auth, cmd) == 0 &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002458 dpp_configurator_own_config(auth, curve, 0) == 0)
Hai Shalomc3565922019-10-28 11:58:20 -07002459 ret = wpas_dpp_handle_config_obj(wpa_s, auth,
2460 &auth->conf_obj[0]);
2461 if (!ret)
2462 wpas_dpp_post_process_config(wpa_s, auth);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002463
2464 dpp_auth_deinit(auth);
2465 os_free(curve);
2466
2467 return ret;
2468}
2469
2470
2471static void
2472wpas_dpp_tx_introduction_status(struct wpa_supplicant *wpa_s,
2473 unsigned int freq, const u8 *dst,
2474 const u8 *src, const u8 *bssid,
2475 const u8 *data, size_t data_len,
2476 enum offchannel_send_action_result result)
2477{
Roshan Pius3a1667e2018-07-03 15:17:14 -07002478 const char *res_txt;
2479
2480 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
2481 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
2482 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002483 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
2484 " result=%s (DPP Peer Discovery Request)",
Roshan Pius3a1667e2018-07-03 15:17:14 -07002485 freq, MAC2STR(dst), res_txt);
2486 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
2487 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002488 /* TODO: Time out wait for response more quickly in error cases? */
2489}
2490
2491
2492int wpas_dpp_check_connect(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2493 struct wpa_bss *bss)
2494{
2495 struct os_time now;
2496 struct wpabuf *msg;
2497 unsigned int wait_time;
Hai Shalom021b0b52019-04-10 11:17:58 -07002498 const u8 *rsn;
2499 struct wpa_ie_data ied;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002500
2501 if (!(ssid->key_mgmt & WPA_KEY_MGMT_DPP) || !bss)
2502 return 0; /* Not using DPP AKM - continue */
Hai Shalom021b0b52019-04-10 11:17:58 -07002503 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2504 if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ied) == 0 &&
2505 !(ied.key_mgmt & WPA_KEY_MGMT_DPP))
2506 return 0; /* AP does not support DPP AKM - continue */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002507 if (wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid))
2508 return 0; /* PMKSA exists for DPP AKM - continue */
2509
2510 if (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
2511 !ssid->dpp_csign) {
2512 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
2513 "missing %s",
2514 !ssid->dpp_connector ? "Connector" :
2515 (!ssid->dpp_netaccesskey ? "netAccessKey" :
2516 "C-sign-key"));
2517 return -1;
2518 }
2519
2520 os_get_time(&now);
2521
2522 if (ssid->dpp_netaccesskey_expiry &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07002523 (os_time_t) ssid->dpp_netaccesskey_expiry < now.sec) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002524 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
2525 "netAccessKey expired");
2526 return -1;
2527 }
2528
2529 wpa_printf(MSG_DEBUG,
2530 "DPP: Starting network introduction protocol to derive PMKSA for "
2531 MACSTR, MAC2STR(bss->bssid));
2532
2533 msg = dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ,
2534 5 + 4 + os_strlen(ssid->dpp_connector));
2535 if (!msg)
2536 return -1;
2537
Roshan Pius3a1667e2018-07-03 15:17:14 -07002538#ifdef CONFIG_TESTING_OPTIONS
2539 if (dpp_test == DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ) {
2540 wpa_printf(MSG_INFO, "DPP: TESTING - no Transaction ID");
2541 goto skip_trans_id;
2542 }
2543 if (dpp_test == DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ) {
2544 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Transaction ID");
2545 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
2546 wpabuf_put_le16(msg, 0);
2547 goto skip_trans_id;
2548 }
2549#endif /* CONFIG_TESTING_OPTIONS */
2550
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002551 /* Transaction ID */
2552 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
2553 wpabuf_put_le16(msg, 1);
2554 wpabuf_put_u8(msg, TRANSACTION_ID);
2555
Roshan Pius3a1667e2018-07-03 15:17:14 -07002556#ifdef CONFIG_TESTING_OPTIONS
2557skip_trans_id:
2558 if (dpp_test == DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ) {
2559 wpa_printf(MSG_INFO, "DPP: TESTING - no Connector");
2560 goto skip_connector;
2561 }
2562 if (dpp_test == DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ) {
2563 char *connector;
2564
2565 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Connector");
2566 connector = dpp_corrupt_connector_signature(
2567 ssid->dpp_connector);
2568 if (!connector) {
2569 wpabuf_free(msg);
2570 return -1;
2571 }
2572 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
2573 wpabuf_put_le16(msg, os_strlen(connector));
2574 wpabuf_put_str(msg, connector);
2575 os_free(connector);
2576 goto skip_connector;
2577 }
2578#endif /* CONFIG_TESTING_OPTIONS */
2579
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002580 /* DPP Connector */
2581 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
2582 wpabuf_put_le16(msg, os_strlen(ssid->dpp_connector));
2583 wpabuf_put_str(msg, ssid->dpp_connector);
2584
Roshan Pius3a1667e2018-07-03 15:17:14 -07002585#ifdef CONFIG_TESTING_OPTIONS
2586skip_connector:
2587#endif /* CONFIG_TESTING_OPTIONS */
2588
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002589 /* TODO: Timeout on AP response */
2590 wait_time = wpa_s->max_remain_on_chan;
2591 if (wait_time > 2000)
2592 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002593 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2594 MAC2STR(bss->bssid), bss->freq, DPP_PA_PEER_DISCOVERY_REQ);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002595 offchannel_send_action(wpa_s, bss->freq, bss->bssid, wpa_s->own_addr,
2596 broadcast,
2597 wpabuf_head(msg), wpabuf_len(msg),
2598 wait_time, wpas_dpp_tx_introduction_status, 0);
2599 wpabuf_free(msg);
2600
2601 /* Request this connection attempt to terminate - new one will be
2602 * started when network introduction protocol completes */
2603 os_memcpy(wpa_s->dpp_intro_bssid, bss->bssid, ETH_ALEN);
2604 wpa_s->dpp_intro_network = ssid;
2605 return 1;
2606}
2607
2608
2609int wpas_dpp_pkex_add(struct wpa_supplicant *wpa_s, const char *cmd)
2610{
2611 struct dpp_bootstrap_info *own_bi;
2612 const char *pos, *end;
2613 unsigned int wait_time;
2614
2615 pos = os_strstr(cmd, " own=");
2616 if (!pos)
2617 return -1;
2618 pos += 5;
Hai Shalom021b0b52019-04-10 11:17:58 -07002619 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002620 if (!own_bi) {
2621 wpa_printf(MSG_DEBUG,
2622 "DPP: Identified bootstrap info not found");
2623 return -1;
2624 }
2625 if (own_bi->type != DPP_BOOTSTRAP_PKEX) {
2626 wpa_printf(MSG_DEBUG,
2627 "DPP: Identified bootstrap info not for PKEX");
2628 return -1;
2629 }
2630 wpa_s->dpp_pkex_bi = own_bi;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002631 own_bi->pkex_t = 0; /* clear pending errors on new code */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002632
2633 os_free(wpa_s->dpp_pkex_identifier);
2634 wpa_s->dpp_pkex_identifier = NULL;
2635 pos = os_strstr(cmd, " identifier=");
2636 if (pos) {
2637 pos += 12;
2638 end = os_strchr(pos, ' ');
2639 if (!end)
2640 return -1;
2641 wpa_s->dpp_pkex_identifier = os_malloc(end - pos + 1);
2642 if (!wpa_s->dpp_pkex_identifier)
2643 return -1;
2644 os_memcpy(wpa_s->dpp_pkex_identifier, pos, end - pos);
2645 wpa_s->dpp_pkex_identifier[end - pos] = '\0';
2646 }
2647
2648 pos = os_strstr(cmd, " code=");
2649 if (!pos)
2650 return -1;
2651 os_free(wpa_s->dpp_pkex_code);
2652 wpa_s->dpp_pkex_code = os_strdup(pos + 6);
2653 if (!wpa_s->dpp_pkex_code)
2654 return -1;
2655
2656 if (os_strstr(cmd, " init=1")) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002657 struct dpp_pkex *pkex;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002658 struct wpabuf *msg;
2659
2660 wpa_printf(MSG_DEBUG, "DPP: Initiating PKEX");
2661 dpp_pkex_free(wpa_s->dpp_pkex);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002662 wpa_s->dpp_pkex = dpp_pkex_init(wpa_s, own_bi, wpa_s->own_addr,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002663 wpa_s->dpp_pkex_identifier,
2664 wpa_s->dpp_pkex_code);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002665 pkex = wpa_s->dpp_pkex;
2666 if (!pkex)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002667 return -1;
2668
Roshan Pius3a1667e2018-07-03 15:17:14 -07002669 msg = pkex->exchange_req;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002670 wait_time = wpa_s->max_remain_on_chan;
2671 if (wait_time > 2000)
2672 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002673 pkex->freq = 2437;
2674 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
2675 " freq=%u type=%d",
2676 MAC2STR(broadcast), pkex->freq,
2677 DPP_PA_PKEX_EXCHANGE_REQ);
2678 offchannel_send_action(wpa_s, pkex->freq, broadcast,
2679 wpa_s->own_addr, broadcast,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002680 wpabuf_head(msg), wpabuf_len(msg),
2681 wait_time, wpas_dpp_tx_pkex_status, 0);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002682 if (wait_time == 0)
2683 wait_time = 2000;
2684 pkex->exch_req_wait_time = wait_time;
2685 pkex->exch_req_tries = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002686 }
2687
2688 /* TODO: Support multiple PKEX info entries */
2689
2690 os_free(wpa_s->dpp_pkex_auth_cmd);
2691 wpa_s->dpp_pkex_auth_cmd = os_strdup(cmd);
2692
2693 return 1;
2694}
2695
2696
2697int wpas_dpp_pkex_remove(struct wpa_supplicant *wpa_s, const char *id)
2698{
2699 unsigned int id_val;
2700
2701 if (os_strcmp(id, "*") == 0) {
2702 id_val = 0;
2703 } else {
2704 id_val = atoi(id);
2705 if (id_val == 0)
2706 return -1;
2707 }
2708
2709 if ((id_val != 0 && id_val != 1) || !wpa_s->dpp_pkex_code)
2710 return -1;
2711
2712 /* TODO: Support multiple PKEX entries */
2713 os_free(wpa_s->dpp_pkex_code);
2714 wpa_s->dpp_pkex_code = NULL;
2715 os_free(wpa_s->dpp_pkex_identifier);
2716 wpa_s->dpp_pkex_identifier = NULL;
2717 os_free(wpa_s->dpp_pkex_auth_cmd);
2718 wpa_s->dpp_pkex_auth_cmd = NULL;
2719 wpa_s->dpp_pkex_bi = NULL;
2720 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
2721 dpp_pkex_free(wpa_s->dpp_pkex);
2722 wpa_s->dpp_pkex = NULL;
2723 return 0;
2724}
2725
2726
Roshan Pius3a1667e2018-07-03 15:17:14 -07002727void wpas_dpp_stop(struct wpa_supplicant *wpa_s)
2728{
Hai Shalomfdcde762020-04-02 11:19:20 -07002729 if (wpa_s->dpp_auth || wpa_s->dpp_pkex)
2730 offchannel_send_action_done(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002731 dpp_auth_deinit(wpa_s->dpp_auth);
2732 wpa_s->dpp_auth = NULL;
2733 dpp_pkex_free(wpa_s->dpp_pkex);
2734 wpa_s->dpp_pkex = NULL;
2735 if (wpa_s->dpp_gas_client && wpa_s->dpp_gas_dialog_token >= 0)
2736 gas_query_stop(wpa_s->gas, wpa_s->dpp_gas_dialog_token);
2737}
2738
2739
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002740int wpas_dpp_init(struct wpa_supplicant *wpa_s)
2741{
Hai Shalom81f62d82019-07-22 12:10:00 -07002742 struct dpp_global_config config;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002743 u8 adv_proto_id[7];
2744
2745 adv_proto_id[0] = WLAN_EID_VENDOR_SPECIFIC;
2746 adv_proto_id[1] = 5;
2747 WPA_PUT_BE24(&adv_proto_id[2], OUI_WFA);
2748 adv_proto_id[5] = DPP_OUI_TYPE;
2749 adv_proto_id[6] = 0x01;
2750
2751 if (gas_server_register(wpa_s->gas_server, adv_proto_id,
2752 sizeof(adv_proto_id), wpas_dpp_gas_req_handler,
2753 wpas_dpp_gas_status_handler, wpa_s) < 0)
2754 return -1;
Hai Shalom81f62d82019-07-22 12:10:00 -07002755
2756 os_memset(&config, 0, sizeof(config));
2757 config.msg_ctx = wpa_s;
2758 config.cb_ctx = wpa_s;
2759#ifdef CONFIG_DPP2
2760 config.process_conf_obj = wpas_dpp_process_conf_obj;
Hai Shalomfdcde762020-04-02 11:19:20 -07002761 config.remove_bi = wpas_dpp_remove_bi;
Hai Shalom81f62d82019-07-22 12:10:00 -07002762#endif /* CONFIG_DPP2 */
2763 wpa_s->dpp = dpp_global_init(&config);
Hai Shalom021b0b52019-04-10 11:17:58 -07002764 return wpa_s->dpp ? 0 : -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002765}
2766
2767
2768void wpas_dpp_deinit(struct wpa_supplicant *wpa_s)
2769{
2770#ifdef CONFIG_TESTING_OPTIONS
2771 os_free(wpa_s->dpp_config_obj_override);
2772 wpa_s->dpp_config_obj_override = NULL;
2773 os_free(wpa_s->dpp_discovery_override);
2774 wpa_s->dpp_discovery_override = NULL;
2775 os_free(wpa_s->dpp_groups_override);
2776 wpa_s->dpp_groups_override = NULL;
2777 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
2778#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalom021b0b52019-04-10 11:17:58 -07002779 if (!wpa_s->dpp)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002780 return;
Hai Shalom021b0b52019-04-10 11:17:58 -07002781 dpp_global_clear(wpa_s->dpp);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002782 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002783 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002784 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
2785 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07002786#ifdef CONFIG_DPP2
2787 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL);
Hai Shalomc3565922019-10-28 11:58:20 -07002788 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout,
2789 wpa_s, NULL);
2790 eloop_cancel_timeout(wpas_dpp_conn_status_result_timeout, wpa_s, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07002791 dpp_pfs_free(wpa_s->dpp_pfs);
2792 wpa_s->dpp_pfs = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07002793 wpas_dpp_chirp_stop(wpa_s);
Hai Shalom021b0b52019-04-10 11:17:58 -07002794#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002795 offchannel_send_action_done(wpa_s);
2796 wpas_dpp_listen_stop(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002797 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002798 wpas_dpp_pkex_remove(wpa_s, "*");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002799 os_memset(wpa_s->dpp_intro_bssid, 0, ETH_ALEN);
2800 os_free(wpa_s->dpp_configurator_params);
2801 wpa_s->dpp_configurator_params = NULL;
2802}
Hai Shalom81f62d82019-07-22 12:10:00 -07002803
2804
2805#ifdef CONFIG_DPP2
Hai Shalomfdcde762020-04-02 11:19:20 -07002806
Hai Shalom81f62d82019-07-22 12:10:00 -07002807int wpas_dpp_controller_start(struct wpa_supplicant *wpa_s, const char *cmd)
2808{
2809 struct dpp_controller_config config;
2810 const char *pos;
2811
2812 os_memset(&config, 0, sizeof(config));
2813 if (cmd) {
2814 pos = os_strstr(cmd, " tcp_port=");
2815 if (pos) {
2816 pos += 10;
2817 config.tcp_port = atoi(pos);
2818 }
2819 }
2820 config.configurator_params = wpa_s->dpp_configurator_params;
2821 return dpp_controller_start(wpa_s->dpp, &config);
2822}
Hai Shalomfdcde762020-04-02 11:19:20 -07002823
2824
2825static void wpas_dpp_chirp_next(void *eloop_ctx, void *timeout_ctx);
2826
2827static void wpas_dpp_chirp_timeout(void *eloop_ctx, void *timeout_ctx)
2828{
2829 struct wpa_supplicant *wpa_s = eloop_ctx;
2830
2831 wpa_printf(MSG_DEBUG, "DPP: No chirp response received");
2832 offchannel_send_action_done(wpa_s);
2833 wpas_dpp_chirp_next(wpa_s, NULL);
2834}
2835
2836
2837static void wpas_dpp_chirp_tx_status(struct wpa_supplicant *wpa_s,
2838 unsigned int freq, const u8 *dst,
2839 const u8 *src, const u8 *bssid,
2840 const u8 *data, size_t data_len,
2841 enum offchannel_send_action_result result)
2842{
2843 if (result == OFFCHANNEL_SEND_ACTION_FAILED) {
2844 wpa_printf(MSG_DEBUG, "DPP: Failed to send chirp on %d MHz",
2845 wpa_s->dpp_chirp_freq);
2846 if (eloop_register_timeout(0, 0, wpas_dpp_chirp_next,
2847 wpa_s, NULL) < 0)
2848 wpas_dpp_chirp_stop(wpa_s);
2849 return;
2850 }
2851
2852 wpa_printf(MSG_DEBUG, "DPP: Chirp send completed - wait for response");
2853 if (eloop_register_timeout(2, 0, wpas_dpp_chirp_timeout,
2854 wpa_s, NULL) < 0)
2855 wpas_dpp_chirp_stop(wpa_s);
2856}
2857
2858
2859static void wpas_dpp_chirp_start(struct wpa_supplicant *wpa_s)
2860{
2861 wpa_printf(MSG_DEBUG, "DPP: Chirp on %d MHz", wpa_s->dpp_chirp_freq);
2862 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2863 MAC2STR(broadcast), wpa_s->dpp_chirp_freq,
2864 DPP_PA_PRESENCE_ANNOUNCEMENT);
2865 if (offchannel_send_action(
2866 wpa_s, wpa_s->dpp_chirp_freq, broadcast,
2867 wpa_s->own_addr, broadcast,
2868 wpabuf_head(wpa_s->dpp_presence_announcement),
2869 wpabuf_len(wpa_s->dpp_presence_announcement),
2870 2000, wpas_dpp_chirp_tx_status, 0) < 0)
2871 wpas_dpp_chirp_stop(wpa_s);
2872}
2873
2874
2875static void wpas_dpp_chirp_scan_res_handler(struct wpa_supplicant *wpa_s,
2876 struct wpa_scan_results *scan_res)
2877{
2878 struct dpp_bootstrap_info *bi = wpa_s->dpp_chirp_bi;
2879 unsigned int i;
2880 struct hostapd_hw_modes *mode;
2881 int c;
2882 struct wpa_bss *bss;
2883
2884 if (!bi)
2885 return;
2886
2887 wpa_s->dpp_chirp_scan_done = 1;
2888
2889 os_free(wpa_s->dpp_chirp_freqs);
2890 wpa_s->dpp_chirp_freqs = NULL;
2891
2892 /* Channels from own bootstrapping info */
2893 for (i = 0; i < bi->num_freq; i++)
2894 int_array_add_unique(&wpa_s->dpp_chirp_freqs, bi->freq[i]);
2895
2896 /* Preferred chirping channels */
2897 int_array_add_unique(&wpa_s->dpp_chirp_freqs, 2437);
2898
2899 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes,
2900 HOSTAPD_MODE_IEEE80211A, 0);
2901 if (mode) {
2902 int chan44 = 0, chan149 = 0;
2903
2904 for (c = 0; c < mode->num_channels; c++) {
2905 struct hostapd_channel_data *chan = &mode->channels[c];
2906
2907 if (chan->flag & (HOSTAPD_CHAN_DISABLED |
2908 HOSTAPD_CHAN_RADAR))
2909 continue;
2910 if (chan->freq == 5220)
2911 chan44 = 1;
2912 if (chan->freq == 5745)
2913 chan149 = 1;
2914 }
2915 if (chan149)
2916 int_array_add_unique(&wpa_s->dpp_chirp_freqs, 5745);
2917 else if (chan44)
2918 int_array_add_unique(&wpa_s->dpp_chirp_freqs, 5220);
2919 }
2920
2921 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes,
2922 HOSTAPD_MODE_IEEE80211AD, 0);
2923 if (mode) {
2924 for (c = 0; c < mode->num_channels; c++) {
2925 struct hostapd_channel_data *chan = &mode->channels[c];
2926
2927 if ((chan->flag & (HOSTAPD_CHAN_DISABLED |
2928 HOSTAPD_CHAN_RADAR)) ||
2929 chan->freq != 60480)
2930 continue;
2931 int_array_add_unique(&wpa_s->dpp_chirp_freqs, 60480);
2932 break;
2933 }
2934 }
2935
2936 /* Add channels from scan results for APs that advertise Configurator
2937 * Connectivity element */
2938 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
2939 if (wpa_bss_get_vendor_ie(bss, DPP_CC_IE_VENDOR_TYPE))
2940 int_array_add_unique(&wpa_s->dpp_chirp_freqs,
2941 bss->freq);
2942 }
2943
2944 if (!wpa_s->dpp_chirp_freqs ||
2945 eloop_register_timeout(0, 0, wpas_dpp_chirp_next, wpa_s, NULL) < 0)
2946 wpas_dpp_chirp_stop(wpa_s);
2947}
2948
2949
2950static void wpas_dpp_chirp_next(void *eloop_ctx, void *timeout_ctx)
2951{
2952 struct wpa_supplicant *wpa_s = eloop_ctx;
2953 int i;
2954
2955 if (wpa_s->dpp_chirp_listen)
2956 wpas_dpp_listen_stop(wpa_s);
2957
2958 if (wpa_s->dpp_chirp_freq == 0) {
2959 if (wpa_s->dpp_chirp_round % 4 == 0 &&
2960 !wpa_s->dpp_chirp_scan_done) {
2961 wpa_printf(MSG_DEBUG,
2962 "DPP: Update channel list for chirping");
2963 wpa_s->scan_req = MANUAL_SCAN_REQ;
2964 wpa_s->scan_res_handler =
2965 wpas_dpp_chirp_scan_res_handler;
2966 wpa_supplicant_req_scan(wpa_s, 0, 0);
2967 return;
2968 }
2969 wpa_s->dpp_chirp_freq = wpa_s->dpp_chirp_freqs[0];
2970 wpa_s->dpp_chirp_round++;
2971 wpa_printf(MSG_DEBUG, "DPP: Start chirping round %d",
2972 wpa_s->dpp_chirp_round);
2973 } else {
2974 for (i = 0; wpa_s->dpp_chirp_freqs[i]; i++)
2975 if (wpa_s->dpp_chirp_freqs[i] == wpa_s->dpp_chirp_freq)
2976 break;
2977 if (!wpa_s->dpp_chirp_freqs[i]) {
2978 wpa_printf(MSG_DEBUG,
2979 "DPP: Previous chirp freq %d not found",
2980 wpa_s->dpp_chirp_freq);
2981 return;
2982 }
2983 i++;
2984 if (wpa_s->dpp_chirp_freqs[i]) {
2985 wpa_s->dpp_chirp_freq = wpa_s->dpp_chirp_freqs[i];
2986 } else {
2987 wpa_s->dpp_chirp_iter--;
2988 if (wpa_s->dpp_chirp_iter <= 0) {
2989 wpa_printf(MSG_DEBUG,
2990 "DPP: Chirping iterations completed");
2991 wpas_dpp_chirp_stop(wpa_s);
2992 return;
2993 }
2994 wpa_s->dpp_chirp_freq = 0;
2995 wpa_s->dpp_chirp_scan_done = 0;
2996 if (eloop_register_timeout(30, 0, wpas_dpp_chirp_next,
2997 wpa_s, NULL) < 0) {
2998 wpas_dpp_chirp_stop(wpa_s);
2999 return;
3000 }
3001 if (wpa_s->dpp_chirp_listen) {
3002 wpa_printf(MSG_DEBUG,
3003 "DPP: Listen on %d MHz during chirp 30 second wait",
3004 wpa_s->dpp_chirp_listen);
3005 wpas_dpp_listen_start(wpa_s,
3006 wpa_s->dpp_chirp_listen);
3007 } else {
3008 wpa_printf(MSG_DEBUG,
3009 "DPP: Wait 30 seconds before starting the next chirping round");
3010 }
3011 return;
3012 }
3013 }
3014
3015 wpas_dpp_chirp_start(wpa_s);
3016}
3017
3018
3019int wpas_dpp_chirp(struct wpa_supplicant *wpa_s, const char *cmd)
3020{
3021 const char *pos;
3022 int iter = 1, listen_freq = 0;
3023 struct dpp_bootstrap_info *bi;
3024
3025 pos = os_strstr(cmd, " own=");
3026 if (!pos)
3027 return -1;
3028 pos += 5;
3029 bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
3030 if (!bi) {
3031 wpa_printf(MSG_DEBUG,
3032 "DPP: Identified bootstrap info not found");
3033 return -1;
3034 }
3035
3036 pos = os_strstr(cmd, " iter=");
3037 if (pos) {
3038 iter = atoi(pos + 6);
3039 if (iter <= 0)
3040 return -1;
3041 }
3042
3043 pos = os_strstr(cmd, " listen=");
3044 if (pos) {
3045 listen_freq = atoi(pos + 8);
3046 if (iter <= 0)
3047 return -1;
3048 }
3049
3050 wpas_dpp_chirp_stop(wpa_s);
3051 wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
3052 wpa_s->dpp_qr_mutual = 0;
3053 wpa_s->dpp_chirp_bi = bi;
3054 wpa_s->dpp_presence_announcement = dpp_build_presence_announcement(bi);
3055 if (!wpa_s->dpp_presence_announcement)
3056 return -1;
3057 wpa_s->dpp_chirp_iter = iter;
3058 wpa_s->dpp_chirp_round = 0;
3059 wpa_s->dpp_chirp_scan_done = 0;
3060 wpa_s->dpp_chirp_listen = listen_freq;
3061
3062 return eloop_register_timeout(0, 0, wpas_dpp_chirp_next, wpa_s, NULL);
3063}
3064
3065
3066void wpas_dpp_chirp_stop(struct wpa_supplicant *wpa_s)
3067{
3068 if (wpa_s->dpp_presence_announcement) {
3069 offchannel_send_action_done(wpa_s);
3070 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CHIRP_STOPPED);
3071 }
3072 wpa_s->dpp_chirp_bi = NULL;
3073 wpabuf_free(wpa_s->dpp_presence_announcement);
3074 wpa_s->dpp_presence_announcement = NULL;
3075 if (wpa_s->dpp_chirp_listen)
3076 wpas_dpp_listen_stop(wpa_s);
3077 wpa_s->dpp_chirp_listen = 0;
3078 wpa_s->dpp_chirp_freq = 0;
3079 os_free(wpa_s->dpp_chirp_freqs);
3080 wpa_s->dpp_chirp_freqs = NULL;
3081 eloop_cancel_timeout(wpas_dpp_chirp_next, wpa_s, NULL);
3082 eloop_cancel_timeout(wpas_dpp_chirp_timeout, wpa_s, NULL);
3083 if (wpa_s->scan_res_handler == wpas_dpp_chirp_scan_res_handler) {
3084 wpas_abort_ongoing_scan(wpa_s);
3085 wpa_s->scan_res_handler = NULL;
3086 }
3087}
3088
Hai Shalom81f62d82019-07-22 12:10:00 -07003089#endif /* CONFIG_DPP2 */