blob: 6dfa2e5034ef9efc1d7ff319f4c014e6bdfabc68 [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;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700122 own_bi->nfc_negotiated = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700123
124 pos = os_strstr(cmd, " uri=");
125 if (!pos)
126 return -1;
127 pos += 5;
128 peer_bi = dpp_add_nfc_uri(wpa_s->dpp, pos);
129 if (!peer_bi) {
130 wpa_printf(MSG_INFO,
131 "DPP: Failed to parse URI from NFC Handover Request");
132 return -1;
133 }
134
135 if (dpp_nfc_update_bi(own_bi, peer_bi) < 0)
136 return -1;
137
138 return peer_bi->id;
139}
140
141
142int wpas_dpp_nfc_handover_sel(struct wpa_supplicant *wpa_s, const char *cmd)
143{
144 const char *pos;
145 struct dpp_bootstrap_info *peer_bi, *own_bi;
146
147 pos = os_strstr(cmd, " own=");
148 if (!pos)
149 return -1;
150 pos += 5;
151 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
152 if (!own_bi)
153 return -1;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700154 own_bi->nfc_negotiated = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700155
156 pos = os_strstr(cmd, " uri=");
157 if (!pos)
158 return -1;
159 pos += 5;
160 peer_bi = dpp_add_nfc_uri(wpa_s->dpp, pos);
161 if (!peer_bi) {
162 wpa_printf(MSG_INFO,
163 "DPP: Failed to parse URI from NFC Handover Select");
164 return -1;
165 }
166
167 if (peer_bi->curve != own_bi->curve) {
168 wpa_printf(MSG_INFO,
169 "DPP: Peer (NFC Handover Selector) used different curve");
170 return -1;
171 }
172
173 return peer_bi->id;
174}
175
176
Roshan Pius3a1667e2018-07-03 15:17:14 -0700177static void wpas_dpp_auth_resp_retry_timeout(void *eloop_ctx, void *timeout_ctx)
178{
179 struct wpa_supplicant *wpa_s = eloop_ctx;
180 struct dpp_authentication *auth = wpa_s->dpp_auth;
181
182 if (!auth || !auth->resp_msg)
183 return;
184
185 wpa_printf(MSG_DEBUG,
186 "DPP: Retry Authentication Response after timeout");
187 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
188 " freq=%u type=%d",
189 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
190 DPP_PA_AUTHENTICATION_RESP);
191 offchannel_send_action(wpa_s, auth->curr_freq, auth->peer_mac_addr,
192 wpa_s->own_addr, broadcast,
193 wpabuf_head(auth->resp_msg),
194 wpabuf_len(auth->resp_msg),
195 500, wpas_dpp_tx_status, 0);
196}
197
198
199static void wpas_dpp_auth_resp_retry(struct wpa_supplicant *wpa_s)
200{
201 struct dpp_authentication *auth = wpa_s->dpp_auth;
202 unsigned int wait_time, max_tries;
203
204 if (!auth || !auth->resp_msg)
205 return;
206
207 if (wpa_s->dpp_resp_max_tries)
208 max_tries = wpa_s->dpp_resp_max_tries;
209 else
210 max_tries = 5;
211 auth->auth_resp_tries++;
212 if (auth->auth_resp_tries >= max_tries) {
213 wpa_printf(MSG_INFO, "DPP: No confirm received from initiator - stopping exchange");
214 offchannel_send_action_done(wpa_s);
215 dpp_auth_deinit(wpa_s->dpp_auth);
216 wpa_s->dpp_auth = NULL;
217 return;
218 }
219
220 if (wpa_s->dpp_resp_retry_time)
221 wait_time = wpa_s->dpp_resp_retry_time;
222 else
223 wait_time = 1000;
224 wpa_printf(MSG_DEBUG,
225 "DPP: Schedule retransmission of Authentication Response frame in %u ms",
226 wait_time);
227 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
228 eloop_register_timeout(wait_time / 1000,
229 (wait_time % 1000) * 1000,
230 wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
231}
232
233
Hai Shalom021b0b52019-04-10 11:17:58 -0700234static void wpas_dpp_try_to_connect(struct wpa_supplicant *wpa_s)
235{
236 wpa_printf(MSG_DEBUG, "DPP: Trying to connect to the new network");
Hai Shalomc3565922019-10-28 11:58:20 -0700237 wpa_s->suitable_network = 0;
238 wpa_s->no_suitable_network = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700239 wpa_s->disconnected = 0;
240 wpa_s->reassociate = 1;
241 wpa_s->scan_runs = 0;
242 wpa_s->normal_scans = 0;
243 wpa_supplicant_cancel_sched_scan(wpa_s);
244 wpa_supplicant_req_scan(wpa_s, 0, 0);
245}
246
247
Hai Shalomc3565922019-10-28 11:58:20 -0700248#ifdef CONFIG_DPP2
249
250static void wpas_dpp_conn_status_result_timeout(void *eloop_ctx,
251 void *timeout_ctx)
252{
253 struct wpa_supplicant *wpa_s = eloop_ctx;
254 struct dpp_authentication *auth = wpa_s->dpp_auth;
255 enum dpp_status_error result;
256
257 if (!auth || !auth->conn_status_requested)
258 return;
259
260 wpa_printf(MSG_DEBUG,
261 "DPP: Connection timeout - report Connection Status Result");
262 if (wpa_s->suitable_network)
263 result = DPP_STATUS_AUTH_FAILURE;
264 else if (wpa_s->no_suitable_network)
265 result = DPP_STATUS_NO_AP;
266 else
267 result = 255; /* What to report here for unexpected state? */
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800268 if (wpa_s->wpa_state == WPA_SCANNING)
269 wpas_abort_ongoing_scan(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700270 wpas_dpp_send_conn_status_result(wpa_s, result);
271}
272
273
274static char * wpas_dpp_scan_channel_list(struct wpa_supplicant *wpa_s)
275{
276 char *str, *end, *pos;
277 size_t len;
278 unsigned int i;
279 u8 last_op_class = 0;
280 int res;
281
282 if (!wpa_s->last_scan_freqs || !wpa_s->num_last_scan_freqs)
283 return NULL;
284
285 len = wpa_s->num_last_scan_freqs * 8;
286 str = os_zalloc(len);
287 if (!str)
288 return NULL;
289 end = str + len;
290 pos = str;
291
292 for (i = 0; i < wpa_s->num_last_scan_freqs; i++) {
293 enum hostapd_hw_mode mode;
294 u8 op_class, channel;
295
296 mode = ieee80211_freq_to_channel_ext(wpa_s->last_scan_freqs[i],
297 0, 0, &op_class, &channel);
298 if (mode == NUM_HOSTAPD_MODES)
299 continue;
300 if (op_class == last_op_class)
301 res = os_snprintf(pos, end - pos, ",%d", channel);
302 else
303 res = os_snprintf(pos, end - pos, "%s%d/%d",
304 pos == str ? "" : ",",
305 op_class, channel);
306 if (os_snprintf_error(end - pos, res)) {
307 *pos = '\0';
308 break;
309 }
310 pos += res;
311 last_op_class = op_class;
312 }
313
314 if (pos == str) {
315 os_free(str);
316 str = NULL;
317 }
318 return str;
319}
320
321
322void wpas_dpp_send_conn_status_result(struct wpa_supplicant *wpa_s,
323 enum dpp_status_error result)
324{
325 struct wpabuf *msg;
326 const char *channel_list = NULL;
327 char *channel_list_buf = NULL;
328 struct wpa_ssid *ssid = wpa_s->current_ssid;
329 struct dpp_authentication *auth = wpa_s->dpp_auth;
330
331 eloop_cancel_timeout(wpas_dpp_conn_status_result_timeout, wpa_s, NULL);
332
333 if (!auth || !auth->conn_status_requested)
334 return;
335 auth->conn_status_requested = 0;
336 wpa_printf(MSG_DEBUG, "DPP: Report connection status result %d",
337 result);
338
339 if (result == DPP_STATUS_NO_AP) {
340 channel_list_buf = wpas_dpp_scan_channel_list(wpa_s);
341 channel_list = channel_list_buf;
342 }
343
344 msg = dpp_build_conn_status_result(auth, result,
345 ssid ? ssid->ssid :
346 wpa_s->dpp_last_ssid,
347 ssid ? ssid->ssid_len :
348 wpa_s->dpp_last_ssid_len,
349 channel_list);
350 os_free(channel_list_buf);
351 if (!msg) {
352 dpp_auth_deinit(wpa_s->dpp_auth);
353 wpa_s->dpp_auth = NULL;
354 return;
355 }
356
357 wpa_msg(wpa_s, MSG_INFO,
358 DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
359 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
360 DPP_PA_CONNECTION_STATUS_RESULT);
361 offchannel_send_action(wpa_s, auth->curr_freq,
362 auth->peer_mac_addr, wpa_s->own_addr, broadcast,
363 wpabuf_head(msg), wpabuf_len(msg),
364 500, wpas_dpp_tx_status, 0);
365 wpabuf_free(msg);
366
367 /* This exchange will be terminated in the TX status handler */
368 auth->remove_on_tx_status = 1;
369
370 return;
371}
372
373
374void wpas_dpp_connected(struct wpa_supplicant *wpa_s)
375{
376 struct dpp_authentication *auth = wpa_s->dpp_auth;
377
378 if (auth && auth->conn_status_requested)
379 wpas_dpp_send_conn_status_result(wpa_s, DPP_STATUS_OK);
380}
381
382#endif /* CONFIG_DPP2 */
383
384
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700385static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
386 unsigned int freq, const u8 *dst,
387 const u8 *src, const u8 *bssid,
388 const u8 *data, size_t data_len,
389 enum offchannel_send_action_result result)
390{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700391 const char *res_txt;
392 struct dpp_authentication *auth = wpa_s->dpp_auth;
393
394 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
395 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
396 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700397 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
Roshan Pius3a1667e2018-07-03 15:17:14 -0700398 " result=%s", freq, MAC2STR(dst), res_txt);
399 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
400 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700401
402 if (!wpa_s->dpp_auth) {
403 wpa_printf(MSG_DEBUG,
404 "DPP: Ignore TX status since there is no ongoing authentication exchange");
405 return;
406 }
407
Hai Shalom021b0b52019-04-10 11:17:58 -0700408#ifdef CONFIG_DPP2
409 if (auth->connect_on_tx_status) {
Hai Shalomc3565922019-10-28 11:58:20 -0700410 auth->connect_on_tx_status = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700411 wpa_printf(MSG_DEBUG,
412 "DPP: Try to connect after completed configuration result");
413 wpas_dpp_try_to_connect(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700414 if (auth->conn_status_requested) {
415 wpa_printf(MSG_DEBUG,
416 "DPP: Start 15 second timeout for reporting connection status result");
417 eloop_cancel_timeout(
418 wpas_dpp_conn_status_result_timeout,
419 wpa_s, NULL);
420 eloop_register_timeout(
421 15, 0, wpas_dpp_conn_status_result_timeout,
422 wpa_s, NULL);
423 } else {
424 dpp_auth_deinit(wpa_s->dpp_auth);
425 wpa_s->dpp_auth = NULL;
426 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700427 return;
428 }
429#endif /* CONFIG_DPP2 */
430
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700431 if (wpa_s->dpp_auth->remove_on_tx_status) {
432 wpa_printf(MSG_DEBUG,
Hai Shalomc3565922019-10-28 11:58:20 -0700433 "DPP: Terminate authentication exchange due to a request to do so on TX status");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700434 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700435 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700436 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
437 NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700438 offchannel_send_action_done(wpa_s);
439 dpp_auth_deinit(wpa_s->dpp_auth);
440 wpa_s->dpp_auth = NULL;
441 return;
442 }
443
444 if (wpa_s->dpp_auth_ok_on_ack)
445 wpas_dpp_auth_success(wpa_s, 1);
446
447 if (!is_broadcast_ether_addr(dst) &&
448 result != OFFCHANNEL_SEND_ACTION_SUCCESS) {
449 wpa_printf(MSG_DEBUG,
450 "DPP: Unicast DPP Action frame was not ACKed");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700451 if (auth->waiting_auth_resp) {
452 /* In case of DPP Authentication Request frame, move to
453 * the next channel immediately. */
454 offchannel_send_action_done(wpa_s);
455 wpas_dpp_auth_init_next(wpa_s);
456 return;
457 }
458 if (auth->waiting_auth_conf) {
459 wpas_dpp_auth_resp_retry(wpa_s);
460 return;
461 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700462 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700463
464 if (!is_broadcast_ether_addr(dst) && auth->waiting_auth_resp &&
465 result == OFFCHANNEL_SEND_ACTION_SUCCESS) {
466 /* Allow timeout handling to stop iteration if no response is
467 * received from a peer that has ACKed a request. */
468 auth->auth_req_ack = 1;
469 }
470
471 if (!wpa_s->dpp_auth_ok_on_ack && wpa_s->dpp_auth->neg_freq > 0 &&
472 wpa_s->dpp_auth->curr_freq != wpa_s->dpp_auth->neg_freq) {
473 wpa_printf(MSG_DEBUG,
474 "DPP: Move from curr_freq %u MHz to neg_freq %u MHz for response",
475 wpa_s->dpp_auth->curr_freq,
476 wpa_s->dpp_auth->neg_freq);
477 offchannel_send_action_done(wpa_s);
478 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->neg_freq);
479 }
480
481 if (wpa_s->dpp_auth_ok_on_ack)
482 wpa_s->dpp_auth_ok_on_ack = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700483}
484
485
486static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx)
487{
488 struct wpa_supplicant *wpa_s = eloop_ctx;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700489 struct dpp_authentication *auth = wpa_s->dpp_auth;
490 unsigned int freq;
491 struct os_reltime now, diff;
492 unsigned int wait_time, diff_ms;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700493
Roshan Pius3a1667e2018-07-03 15:17:14 -0700494 if (!auth || !auth->waiting_auth_resp)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700495 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700496
497 wait_time = wpa_s->dpp_resp_wait_time ?
498 wpa_s->dpp_resp_wait_time : 2000;
499 os_get_reltime(&now);
500 os_reltime_sub(&now, &wpa_s->dpp_last_init, &diff);
501 diff_ms = diff.sec * 1000 + diff.usec / 1000;
502 wpa_printf(MSG_DEBUG,
503 "DPP: Reply wait timeout - wait_time=%u diff_ms=%u",
504 wait_time, diff_ms);
505
506 if (auth->auth_req_ack && diff_ms >= wait_time) {
507 /* Peer ACK'ed Authentication Request frame, but did not reply
508 * with Authentication Response frame within two seconds. */
509 wpa_printf(MSG_INFO,
510 "DPP: No response received from responder - stopping initiation attempt");
511 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -0800512 wpas_notify_dpp_timeout(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700513 offchannel_send_action_done(wpa_s);
514 wpas_dpp_listen_stop(wpa_s);
515 dpp_auth_deinit(auth);
516 wpa_s->dpp_auth = NULL;
517 return;
518 }
519
520 if (diff_ms >= wait_time) {
521 /* Authentication Request frame was not ACK'ed and no reply
522 * was receiving within two seconds. */
523 wpa_printf(MSG_DEBUG,
524 "DPP: Continue Initiator channel iteration");
525 offchannel_send_action_done(wpa_s);
526 wpas_dpp_listen_stop(wpa_s);
527 wpas_dpp_auth_init_next(wpa_s);
528 return;
529 }
530
531 /* Driver did not support 2000 ms long wait_time with TX command, so
532 * schedule listen operation to continue waiting for the response.
533 *
534 * DPP listen operations continue until stopped, so simply schedule a
535 * new call to this function at the point when the two second reply
536 * wait has expired. */
537 wait_time -= diff_ms;
538
539 freq = auth->curr_freq;
540 if (auth->neg_freq > 0)
541 freq = auth->neg_freq;
542 wpa_printf(MSG_DEBUG,
543 "DPP: Continue reply wait on channel %u MHz for %u ms",
544 freq, wait_time);
545 wpa_s->dpp_in_response_listen = 1;
546 wpas_dpp_listen_start(wpa_s, freq);
547
548 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
549 wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700550}
551
552
553static void wpas_dpp_set_testing_options(struct wpa_supplicant *wpa_s,
554 struct dpp_authentication *auth)
555{
556#ifdef CONFIG_TESTING_OPTIONS
557 if (wpa_s->dpp_config_obj_override)
558 auth->config_obj_override =
559 os_strdup(wpa_s->dpp_config_obj_override);
560 if (wpa_s->dpp_discovery_override)
561 auth->discovery_override =
562 os_strdup(wpa_s->dpp_discovery_override);
563 if (wpa_s->dpp_groups_override)
564 auth->groups_override =
565 os_strdup(wpa_s->dpp_groups_override);
566 auth->ignore_netaccesskey_mismatch =
567 wpa_s->dpp_ignore_netaccesskey_mismatch;
568#endif /* CONFIG_TESTING_OPTIONS */
569}
570
571
Roshan Pius3a1667e2018-07-03 15:17:14 -0700572static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx)
573{
574 struct wpa_supplicant *wpa_s = eloop_ctx;
575
576 if (!wpa_s->dpp_auth)
577 return;
578 wpa_printf(MSG_DEBUG, "DPP: Retry initiation after timeout");
579 wpas_dpp_auth_init_next(wpa_s);
580}
581
582
583static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s)
584{
585 struct dpp_authentication *auth = wpa_s->dpp_auth;
586 const u8 *dst;
587 unsigned int wait_time, max_wait_time, freq, max_tries, used;
588 struct os_reltime now, diff;
589
590 wpa_s->dpp_in_response_listen = 0;
591 if (!auth)
592 return -1;
593
594 if (auth->freq_idx == 0)
595 os_get_reltime(&wpa_s->dpp_init_iter_start);
596
597 if (auth->freq_idx >= auth->num_freq) {
598 auth->num_freq_iters++;
599 if (wpa_s->dpp_init_max_tries)
600 max_tries = wpa_s->dpp_init_max_tries;
601 else
602 max_tries = 5;
603 if (auth->num_freq_iters >= max_tries || auth->auth_req_ack) {
604 wpa_printf(MSG_INFO,
605 "DPP: No response received from responder - stopping initiation attempt");
606 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -0800607 wpas_notify_dpp_timeout(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700608 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout,
609 wpa_s, NULL);
610 offchannel_send_action_done(wpa_s);
611 dpp_auth_deinit(wpa_s->dpp_auth);
612 wpa_s->dpp_auth = NULL;
613 return -1;
614 }
615 auth->freq_idx = 0;
616 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
617 if (wpa_s->dpp_init_retry_time)
618 wait_time = wpa_s->dpp_init_retry_time;
619 else
620 wait_time = 10000;
621 os_get_reltime(&now);
622 os_reltime_sub(&now, &wpa_s->dpp_init_iter_start, &diff);
623 used = diff.sec * 1000 + diff.usec / 1000;
624 if (used > wait_time)
625 wait_time = 0;
626 else
627 wait_time -= used;
628 wpa_printf(MSG_DEBUG, "DPP: Next init attempt in %u ms",
629 wait_time);
630 eloop_register_timeout(wait_time / 1000,
631 (wait_time % 1000) * 1000,
632 wpas_dpp_init_timeout, wpa_s,
633 NULL);
634 return 0;
635 }
636 freq = auth->freq[auth->freq_idx++];
637 auth->curr_freq = freq;
638
639 if (is_zero_ether_addr(auth->peer_bi->mac_addr))
640 dst = broadcast;
641 else
642 dst = auth->peer_bi->mac_addr;
643 wpa_s->dpp_auth_ok_on_ack = 0;
644 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
645 wait_time = wpa_s->max_remain_on_chan;
646 max_wait_time = wpa_s->dpp_resp_wait_time ?
647 wpa_s->dpp_resp_wait_time : 2000;
648 if (wait_time > max_wait_time)
649 wait_time = max_wait_time;
650 wait_time += 10; /* give the driver some extra time to complete */
651 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
652 wpas_dpp_reply_wait_timeout,
653 wpa_s, NULL);
654 wait_time -= 10;
655 if (auth->neg_freq > 0 && freq != auth->neg_freq) {
656 wpa_printf(MSG_DEBUG,
657 "DPP: Initiate on %u MHz and move to neg_freq %u MHz for response",
658 freq, auth->neg_freq);
659 }
660 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
661 MAC2STR(dst), freq, DPP_PA_AUTHENTICATION_REQ);
662 auth->auth_req_ack = 0;
663 os_get_reltime(&wpa_s->dpp_last_init);
664 return offchannel_send_action(wpa_s, freq, dst,
665 wpa_s->own_addr, broadcast,
666 wpabuf_head(auth->req_msg),
667 wpabuf_len(auth->req_msg),
668 wait_time, wpas_dpp_tx_status, 0);
669}
670
671
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700672int wpas_dpp_auth_init(struct wpa_supplicant *wpa_s, const char *cmd)
673{
674 const char *pos;
675 struct dpp_bootstrap_info *peer_bi, *own_bi = NULL;
Hai Shalom81f62d82019-07-22 12:10:00 -0700676 struct dpp_authentication *auth;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700677 u8 allowed_roles = DPP_CAPAB_CONFIGURATOR;
678 unsigned int neg_freq = 0;
Hai Shalom81f62d82019-07-22 12:10:00 -0700679 int tcp = 0;
680#ifdef CONFIG_DPP2
681 int tcp_port = DPP_TCP_PORT;
682 struct hostapd_ip_addr ipaddr;
683 char *addr;
684#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700685
686 wpa_s->dpp_gas_client = 0;
687
688 pos = os_strstr(cmd, " peer=");
689 if (!pos)
690 return -1;
691 pos += 6;
Hai Shalom021b0b52019-04-10 11:17:58 -0700692 peer_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700693 if (!peer_bi) {
694 wpa_printf(MSG_INFO,
695 "DPP: Could not find bootstrapping info for the identified peer");
696 return -1;
697 }
698
Hai Shalom81f62d82019-07-22 12:10:00 -0700699#ifdef CONFIG_DPP2
700 pos = os_strstr(cmd, " tcp_port=");
701 if (pos) {
702 pos += 10;
703 tcp_port = atoi(pos);
704 }
705
706 addr = get_param(cmd, " tcp_addr=");
707 if (addr) {
708 int res;
709
710 res = hostapd_parse_ip_addr(addr, &ipaddr);
711 os_free(addr);
712 if (res)
713 return -1;
714 tcp = 1;
715 }
716#endif /* CONFIG_DPP2 */
717
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700718 pos = os_strstr(cmd, " own=");
719 if (pos) {
720 pos += 5;
Hai Shalom021b0b52019-04-10 11:17:58 -0700721 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700722 if (!own_bi) {
723 wpa_printf(MSG_INFO,
724 "DPP: Could not find bootstrapping info for the identified local entry");
725 return -1;
726 }
727
728 if (peer_bi->curve != own_bi->curve) {
729 wpa_printf(MSG_INFO,
730 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
731 peer_bi->curve->name, own_bi->curve->name);
732 return -1;
733 }
734 }
735
736 pos = os_strstr(cmd, " role=");
737 if (pos) {
738 pos += 6;
739 if (os_strncmp(pos, "configurator", 12) == 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700740 allowed_roles = DPP_CAPAB_CONFIGURATOR;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700741 else if (os_strncmp(pos, "enrollee", 8) == 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700742 allowed_roles = DPP_CAPAB_ENROLLEE;
743 else if (os_strncmp(pos, "either", 6) == 0)
744 allowed_roles = DPP_CAPAB_CONFIGURATOR |
745 DPP_CAPAB_ENROLLEE;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700746 else
747 goto fail;
748 }
749
750 pos = os_strstr(cmd, " netrole=");
751 if (pos) {
752 pos += 9;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800753 if (os_strncmp(pos, "ap", 2) == 0)
754 wpa_s->dpp_netrole = DPP_NETROLE_AP;
755 else if (os_strncmp(pos, "configurator", 12) == 0)
756 wpa_s->dpp_netrole = DPP_NETROLE_CONFIGURATOR;
757 else
758 wpa_s->dpp_netrole = DPP_NETROLE_STA;
Hai Shalomfdcde762020-04-02 11:19:20 -0700759 } else {
760 wpa_s->dpp_netrole = DPP_NETROLE_STA;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700761 }
762
Roshan Pius3a1667e2018-07-03 15:17:14 -0700763 pos = os_strstr(cmd, " neg_freq=");
764 if (pos)
765 neg_freq = atoi(pos + 10);
766
Hai Shalom81f62d82019-07-22 12:10:00 -0700767 if (!tcp && wpa_s->dpp_auth) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700768 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700769 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700770 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
771 NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700772 offchannel_send_action_done(wpa_s);
773 dpp_auth_deinit(wpa_s->dpp_auth);
Hai Shalom74f70d42019-02-11 14:42:39 -0800774 wpa_s->dpp_auth = NULL;
Hai Shalom81f62d82019-07-22 12:10:00 -0700775 }
776
Hai Shalomfdcde762020-04-02 11:19:20 -0700777 auth = dpp_auth_init(wpa_s->dpp, wpa_s, peer_bi, own_bi, allowed_roles,
778 neg_freq, wpa_s->hw.modes, wpa_s->hw.num_modes);
Hai Shalom81f62d82019-07-22 12:10:00 -0700779 if (!auth)
780 goto fail;
781 wpas_dpp_set_testing_options(wpa_s, auth);
Hai Shalomfdcde762020-04-02 11:19:20 -0700782 if (dpp_set_configurator(auth, cmd) < 0) {
Hai Shalom81f62d82019-07-22 12:10:00 -0700783 dpp_auth_deinit(auth);
Hai Shalom74f70d42019-02-11 14:42:39 -0800784 goto fail;
785 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700786
Hai Shalom81f62d82019-07-22 12:10:00 -0700787 auth->neg_freq = neg_freq;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700788
Roshan Pius3a1667e2018-07-03 15:17:14 -0700789 if (!is_zero_ether_addr(peer_bi->mac_addr))
Hai Shalom81f62d82019-07-22 12:10:00 -0700790 os_memcpy(auth->peer_mac_addr, peer_bi->mac_addr, ETH_ALEN);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700791
Hai Shalom81f62d82019-07-22 12:10:00 -0700792#ifdef CONFIG_DPP2
793 if (tcp)
794 return dpp_tcp_init(wpa_s->dpp, auth, &ipaddr, tcp_port);
795#endif /* CONFIG_DPP2 */
796
797 wpa_s->dpp_auth = auth;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700798 return wpas_dpp_auth_init_next(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700799fail:
800 return -1;
801}
802
803
804struct wpas_dpp_listen_work {
805 unsigned int freq;
806 unsigned int duration;
807 struct wpabuf *probe_resp_ie;
808};
809
810
811static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work *lwork)
812{
813 if (!lwork)
814 return;
815 os_free(lwork);
816}
817
818
819static void wpas_dpp_listen_work_done(struct wpa_supplicant *wpa_s)
820{
821 struct wpas_dpp_listen_work *lwork;
822
823 if (!wpa_s->dpp_listen_work)
824 return;
825
826 lwork = wpa_s->dpp_listen_work->ctx;
827 wpas_dpp_listen_work_free(lwork);
828 radio_work_done(wpa_s->dpp_listen_work);
829 wpa_s->dpp_listen_work = NULL;
830}
831
832
833static void dpp_start_listen_cb(struct wpa_radio_work *work, int deinit)
834{
835 struct wpa_supplicant *wpa_s = work->wpa_s;
836 struct wpas_dpp_listen_work *lwork = work->ctx;
837
838 if (deinit) {
839 if (work->started) {
840 wpa_s->dpp_listen_work = NULL;
841 wpas_dpp_listen_stop(wpa_s);
842 }
843 wpas_dpp_listen_work_free(lwork);
844 return;
845 }
846
847 wpa_s->dpp_listen_work = work;
848
849 wpa_s->dpp_pending_listen_freq = lwork->freq;
850
851 if (wpa_drv_remain_on_channel(wpa_s, lwork->freq,
852 wpa_s->max_remain_on_chan) < 0) {
853 wpa_printf(MSG_DEBUG,
854 "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
855 lwork->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -0800856 wpa_s->dpp_listen_freq = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700857 wpas_dpp_listen_work_done(wpa_s);
858 wpa_s->dpp_pending_listen_freq = 0;
859 return;
860 }
861 wpa_s->off_channel_freq = 0;
862 wpa_s->roc_waiting_drv_freq = lwork->freq;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700863 wpa_drv_dpp_listen(wpa_s, true);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700864}
865
866
867static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
868 unsigned int freq)
869{
870 struct wpas_dpp_listen_work *lwork;
871
872 if (wpa_s->dpp_listen_work) {
873 wpa_printf(MSG_DEBUG,
874 "DPP: Reject start_listen since dpp_listen_work already exists");
875 return -1;
876 }
877
878 if (wpa_s->dpp_listen_freq)
879 wpas_dpp_listen_stop(wpa_s);
880 wpa_s->dpp_listen_freq = freq;
881
882 lwork = os_zalloc(sizeof(*lwork));
883 if (!lwork)
884 return -1;
885 lwork->freq = freq;
886
887 if (radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb,
888 lwork) < 0) {
889 wpas_dpp_listen_work_free(lwork);
890 return -1;
891 }
892
893 return 0;
894}
895
896
897int wpas_dpp_listen(struct wpa_supplicant *wpa_s, const char *cmd)
898{
899 int freq;
900
901 freq = atoi(cmd);
902 if (freq <= 0)
903 return -1;
904
905 if (os_strstr(cmd, " role=configurator"))
906 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR;
907 else if (os_strstr(cmd, " role=enrollee"))
908 wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
909 else
910 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
911 DPP_CAPAB_ENROLLEE;
912 wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800913 if (os_strstr(cmd, " netrole=ap"))
914 wpa_s->dpp_netrole = DPP_NETROLE_AP;
915 else if (os_strstr(cmd, " netrole=configurator"))
916 wpa_s->dpp_netrole = DPP_NETROLE_CONFIGURATOR;
917 else
918 wpa_s->dpp_netrole = DPP_NETROLE_STA;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700919 if (wpa_s->dpp_listen_freq == (unsigned int) freq) {
920 wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz",
921 freq);
922 return 0;
923 }
924
925 return wpas_dpp_listen_start(wpa_s, freq);
926}
927
928
929void wpas_dpp_listen_stop(struct wpa_supplicant *wpa_s)
930{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700931 wpa_s->dpp_in_response_listen = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700932 if (!wpa_s->dpp_listen_freq)
933 return;
934
935 wpa_printf(MSG_DEBUG, "DPP: Stop listen on %u MHz",
936 wpa_s->dpp_listen_freq);
937 wpa_drv_cancel_remain_on_channel(wpa_s);
Hai Shalomb755a2a2020-04-23 21:49:02 -0700938 wpa_drv_dpp_listen(wpa_s, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700939 wpa_s->dpp_listen_freq = 0;
940 wpas_dpp_listen_work_done(wpa_s);
941}
942
943
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700944void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
945 unsigned int freq)
946{
947 wpas_dpp_listen_work_done(wpa_s);
948
Roshan Pius3a1667e2018-07-03 15:17:14 -0700949 if (wpa_s->dpp_auth && wpa_s->dpp_in_response_listen) {
950 unsigned int new_freq;
951
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700952 /* Continue listen with a new remain-on-channel */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700953 if (wpa_s->dpp_auth->neg_freq > 0)
954 new_freq = wpa_s->dpp_auth->neg_freq;
955 else
956 new_freq = wpa_s->dpp_auth->curr_freq;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700957 wpa_printf(MSG_DEBUG,
958 "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
Roshan Pius3a1667e2018-07-03 15:17:14 -0700959 new_freq);
960 wpas_dpp_listen_start(wpa_s, new_freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700961 return;
962 }
963
964 if (wpa_s->dpp_listen_freq) {
965 /* Continue listen with a new remain-on-channel */
966 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_listen_freq);
967 }
968}
969
970
971static void wpas_dpp_rx_auth_req(struct wpa_supplicant *wpa_s, const u8 *src,
972 const u8 *hdr, const u8 *buf, size_t len,
973 unsigned int freq)
974{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700975 const u8 *r_bootstrap, *i_bootstrap;
976 u16 r_bootstrap_len, i_bootstrap_len;
Hai Shalom021b0b52019-04-10 11:17:58 -0700977 struct dpp_bootstrap_info *own_bi = NULL, *peer_bi = NULL;
978
979 if (!wpa_s->dpp)
980 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700981
982 wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR,
983 MAC2STR(src));
984
Hai Shalomfdcde762020-04-02 11:19:20 -0700985#ifdef CONFIG_DPP2
986 wpas_dpp_chirp_stop(wpa_s);
987#endif /* CONFIG_DPP2 */
988
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700989 r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
990 &r_bootstrap_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700991 if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
992 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
993 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700994 return;
995 }
996 wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
997 r_bootstrap, r_bootstrap_len);
998
999 i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH,
1000 &i_bootstrap_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001001 if (!i_bootstrap || i_bootstrap_len != SHA256_MAC_LEN) {
1002 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1003 "Missing or invalid required Initiator Bootstrapping Key Hash attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001004 return;
1005 }
1006 wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash",
1007 i_bootstrap, i_bootstrap_len);
1008
1009 /* Try to find own and peer bootstrapping key matches based on the
1010 * received hash values */
Hai Shalom021b0b52019-04-10 11:17:58 -07001011 dpp_bootstrap_find_pair(wpa_s->dpp, i_bootstrap, r_bootstrap,
1012 &own_bi, &peer_bi);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001013 if (!own_bi) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001014 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1015 "No matching own bootstrapping key found - ignore message");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001016 return;
1017 }
1018
1019 if (wpa_s->dpp_auth) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001020 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1021 "Already in DPP authentication exchange - ignore new one");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001022 return;
1023 }
1024
1025 wpa_s->dpp_gas_client = 0;
1026 wpa_s->dpp_auth_ok_on_ack = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07001027 wpa_s->dpp_auth = dpp_auth_req_rx(wpa_s->dpp, wpa_s,
1028 wpa_s->dpp_allowed_roles,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001029 wpa_s->dpp_qr_mutual,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001030 peer_bi, own_bi, freq, hdr, buf, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001031 if (!wpa_s->dpp_auth) {
1032 wpa_printf(MSG_DEBUG, "DPP: No response generated");
1033 return;
1034 }
1035 wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
Hai Shalomfdcde762020-04-02 11:19:20 -07001036 if (dpp_set_configurator(wpa_s->dpp_auth,
Hai Shalom021b0b52019-04-10 11:17:58 -07001037 wpa_s->dpp_configurator_params) < 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08001038 dpp_auth_deinit(wpa_s->dpp_auth);
1039 wpa_s->dpp_auth = NULL;
1040 return;
1041 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001042 os_memcpy(wpa_s->dpp_auth->peer_mac_addr, src, ETH_ALEN);
1043
Roshan Pius3a1667e2018-07-03 15:17:14 -07001044 if (wpa_s->dpp_listen_freq &&
1045 wpa_s->dpp_listen_freq != wpa_s->dpp_auth->curr_freq) {
1046 wpa_printf(MSG_DEBUG,
1047 "DPP: Stop listen on %u MHz to allow response on the request %u MHz",
1048 wpa_s->dpp_listen_freq, wpa_s->dpp_auth->curr_freq);
1049 wpas_dpp_listen_stop(wpa_s);
1050 }
1051
1052 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1053 MAC2STR(src), wpa_s->dpp_auth->curr_freq,
1054 DPP_PA_AUTHENTICATION_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001055 offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq,
1056 src, wpa_s->own_addr, broadcast,
1057 wpabuf_head(wpa_s->dpp_auth->resp_msg),
1058 wpabuf_len(wpa_s->dpp_auth->resp_msg),
1059 500, wpas_dpp_tx_status, 0);
1060}
1061
1062
1063static void wpas_dpp_start_gas_server(struct wpa_supplicant *wpa_s)
1064{
1065 /* TODO: stop wait and start ROC */
1066}
1067
1068
1069static struct wpa_ssid * wpas_dpp_add_network(struct wpa_supplicant *wpa_s,
Hai Shalomc3565922019-10-28 11:58:20 -07001070 struct dpp_authentication *auth,
1071 struct dpp_config_obj *conf)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001072{
1073 struct wpa_ssid *ssid;
1074
Hai Shalom021b0b52019-04-10 11:17:58 -07001075#ifdef CONFIG_DPP2
Hai Shalomc3565922019-10-28 11:58:20 -07001076 if (conf->akm == DPP_AKM_SAE) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001077#ifdef CONFIG_SAE
1078 struct wpa_driver_capa capa;
1079 int res;
1080
1081 res = wpa_drv_get_capa(wpa_s, &capa);
1082 if (res == 0 &&
1083 !(capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) &&
1084 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
1085 wpa_printf(MSG_DEBUG,
1086 "DPP: SAE not supported by the driver");
1087 return NULL;
1088 }
1089#else /* CONFIG_SAE */
1090 wpa_printf(MSG_DEBUG, "DPP: SAE not supported in the build");
1091 return NULL;
1092#endif /* CONFIG_SAE */
1093 }
1094#endif /* CONFIG_DPP2 */
1095
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001096 ssid = wpa_config_add_network(wpa_s->conf);
1097 if (!ssid)
1098 return NULL;
1099 wpas_notify_network_added(wpa_s, ssid);
1100 wpa_config_set_network_defaults(ssid);
1101 ssid->disabled = 1;
1102
Hai Shalomc3565922019-10-28 11:58:20 -07001103 ssid->ssid = os_malloc(conf->ssid_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001104 if (!ssid->ssid)
1105 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07001106 os_memcpy(ssid->ssid, conf->ssid, conf->ssid_len);
1107 ssid->ssid_len = conf->ssid_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001108
Hai Shalomc3565922019-10-28 11:58:20 -07001109 if (conf->connector) {
Hai Shalomfdcde762020-04-02 11:19:20 -07001110 if (dpp_akm_dpp(conf->akm)) {
1111 ssid->key_mgmt = WPA_KEY_MGMT_DPP;
1112 ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED;
1113 }
Hai Shalomc3565922019-10-28 11:58:20 -07001114 ssid->dpp_connector = os_strdup(conf->connector);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001115 if (!ssid->dpp_connector)
1116 goto fail;
1117 }
1118
Hai Shalomc3565922019-10-28 11:58:20 -07001119 if (conf->c_sign_key) {
1120 ssid->dpp_csign = os_malloc(wpabuf_len(conf->c_sign_key));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001121 if (!ssid->dpp_csign)
1122 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07001123 os_memcpy(ssid->dpp_csign, wpabuf_head(conf->c_sign_key),
1124 wpabuf_len(conf->c_sign_key));
1125 ssid->dpp_csign_len = wpabuf_len(conf->c_sign_key);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001126 }
1127
1128 if (auth->net_access_key) {
1129 ssid->dpp_netaccesskey =
1130 os_malloc(wpabuf_len(auth->net_access_key));
1131 if (!ssid->dpp_netaccesskey)
1132 goto fail;
1133 os_memcpy(ssid->dpp_netaccesskey,
1134 wpabuf_head(auth->net_access_key),
1135 wpabuf_len(auth->net_access_key));
1136 ssid->dpp_netaccesskey_len = wpabuf_len(auth->net_access_key);
1137 ssid->dpp_netaccesskey_expiry = auth->net_access_key_expiry;
1138 }
1139
Hai Shalomc3565922019-10-28 11:58:20 -07001140 if (!conf->connector || dpp_akm_psk(conf->akm) ||
1141 dpp_akm_sae(conf->akm)) {
Hai Shalomfdcde762020-04-02 11:19:20 -07001142 if (!conf->connector || !dpp_akm_dpp(conf->akm))
Hai Shalom021b0b52019-04-10 11:17:58 -07001143 ssid->key_mgmt = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07001144 if (dpp_akm_psk(conf->akm))
Roshan Pius3a1667e2018-07-03 15:17:14 -07001145 ssid->key_mgmt |= WPA_KEY_MGMT_PSK |
1146 WPA_KEY_MGMT_PSK_SHA256 | WPA_KEY_MGMT_FT_PSK;
Hai Shalomc3565922019-10-28 11:58:20 -07001147 if (dpp_akm_sae(conf->akm))
Roshan Pius3a1667e2018-07-03 15:17:14 -07001148 ssid->key_mgmt |= WPA_KEY_MGMT_SAE |
1149 WPA_KEY_MGMT_FT_SAE;
1150 ssid->ieee80211w = MGMT_FRAME_PROTECTION_OPTIONAL;
Hai Shalomc3565922019-10-28 11:58:20 -07001151 if (conf->passphrase[0]) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001152 if (wpa_config_set_quoted(ssid, "psk",
Hai Shalomc3565922019-10-28 11:58:20 -07001153 conf->passphrase) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001154 goto fail;
1155 wpa_config_update_psk(ssid);
1156 ssid->export_keys = 1;
1157 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07001158 ssid->psk_set = conf->psk_set;
1159 os_memcpy(ssid->psk, conf->psk, PMK_LEN);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001160 }
1161 }
1162
Hai Shalomc3565922019-10-28 11:58:20 -07001163 os_memcpy(wpa_s->dpp_last_ssid, conf->ssid, conf->ssid_len);
1164 wpa_s->dpp_last_ssid_len = conf->ssid_len;
1165
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001166 return ssid;
1167fail:
1168 wpas_notify_network_removed(wpa_s, ssid);
1169 wpa_config_remove_network(wpa_s->conf, ssid->id);
1170 return NULL;
1171}
1172
1173
Hai Shalom021b0b52019-04-10 11:17:58 -07001174static int wpas_dpp_process_config(struct wpa_supplicant *wpa_s,
Hai Shalomc3565922019-10-28 11:58:20 -07001175 struct dpp_authentication *auth,
1176 struct dpp_config_obj *conf)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001177{
1178 struct wpa_ssid *ssid;
1179
1180 if (wpa_s->conf->dpp_config_processing < 1)
Hai Shalom021b0b52019-04-10 11:17:58 -07001181 return 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001182
Hai Shalomc3565922019-10-28 11:58:20 -07001183 ssid = wpas_dpp_add_network(wpa_s, auth, conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001184 if (!ssid)
Hai Shalom021b0b52019-04-10 11:17:58 -07001185 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001186
1187 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_NETWORK_ID "%d", ssid->id);
Hai Shalom59532852018-12-07 10:32:58 -08001188
Hai Shalom706f99b2019-01-08 16:23:37 -08001189 wpas_notify_dpp_config_received(wpa_s, ssid);
Hai Shalom59532852018-12-07 10:32:58 -08001190
Hai Shalom021b0b52019-04-10 11:17:58 -07001191 if (wpa_s->conf->dpp_config_processing == 2)
1192 ssid->disabled = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001193
Hai Shalom021b0b52019-04-10 11:17:58 -07001194#ifndef CONFIG_NO_CONFIG_WRITE
1195 if (wpa_s->conf->update_config &&
1196 wpa_config_write(wpa_s->confname, wpa_s->conf))
1197 wpa_printf(MSG_DEBUG, "DPP: Failed to update configuration");
1198#endif /* CONFIG_NO_CONFIG_WRITE */
1199
Hai Shalomc3565922019-10-28 11:58:20 -07001200 return 0;
1201}
1202
1203
1204static void wpas_dpp_post_process_config(struct wpa_supplicant *wpa_s,
1205 struct dpp_authentication *auth)
1206{
Hai Shalom021b0b52019-04-10 11:17:58 -07001207 if (wpa_s->conf->dpp_config_processing < 2)
Hai Shalomc3565922019-10-28 11:58:20 -07001208 return;
Hai Shalom021b0b52019-04-10 11:17:58 -07001209
1210#ifdef CONFIG_DPP2
1211 if (auth->peer_version >= 2) {
1212 wpa_printf(MSG_DEBUG,
1213 "DPP: Postpone connection attempt to wait for completion of DPP Configuration Result");
1214 auth->connect_on_tx_status = 1;
Hai Shalomc3565922019-10-28 11:58:20 -07001215 return;
Hai Shalom021b0b52019-04-10 11:17:58 -07001216 }
1217#endif /* CONFIG_DPP2 */
1218
1219 wpas_dpp_try_to_connect(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001220}
1221
1222
Hai Shalom021b0b52019-04-10 11:17:58 -07001223static int wpas_dpp_handle_config_obj(struct wpa_supplicant *wpa_s,
Hai Shalomc3565922019-10-28 11:58:20 -07001224 struct dpp_authentication *auth,
1225 struct dpp_config_obj *conf)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001226{
1227 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
Hai Shalomc3565922019-10-28 11:58:20 -07001228 if (conf->ssid_len)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001229 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s",
Hai Shalomc3565922019-10-28 11:58:20 -07001230 wpa_ssid_txt(conf->ssid, conf->ssid_len));
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001231 if (conf->ssid_charset)
1232 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID_CHARSET "%d",
1233 conf->ssid_charset);
Hai Shalomc3565922019-10-28 11:58:20 -07001234 if (conf->connector) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001235 /* TODO: Save the Connector and consider using a command
1236 * to fetch the value instead of sending an event with
1237 * it. The Connector could end up being larger than what
1238 * most clients are ready to receive as an event
1239 * message. */
1240 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONNECTOR "%s",
Hai Shalomc3565922019-10-28 11:58:20 -07001241 conf->connector);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001242 }
Hai Shalomc3565922019-10-28 11:58:20 -07001243 if (conf->c_sign_key) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001244 char *hex;
1245 size_t hexlen;
1246
Hai Shalomc3565922019-10-28 11:58:20 -07001247 hexlen = 2 * wpabuf_len(conf->c_sign_key) + 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001248 hex = os_malloc(hexlen);
1249 if (hex) {
1250 wpa_snprintf_hex(hex, hexlen,
Hai Shalomc3565922019-10-28 11:58:20 -07001251 wpabuf_head(conf->c_sign_key),
1252 wpabuf_len(conf->c_sign_key));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001253 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_C_SIGN_KEY "%s",
1254 hex);
1255 os_free(hex);
1256 }
1257 }
1258 if (auth->net_access_key) {
1259 char *hex;
1260 size_t hexlen;
1261
1262 hexlen = 2 * wpabuf_len(auth->net_access_key) + 1;
1263 hex = os_malloc(hexlen);
1264 if (hex) {
1265 wpa_snprintf_hex(hex, hexlen,
1266 wpabuf_head(auth->net_access_key),
1267 wpabuf_len(auth->net_access_key));
1268 if (auth->net_access_key_expiry)
1269 wpa_msg(wpa_s, MSG_INFO,
1270 DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex,
1271 (long unsigned)
1272 auth->net_access_key_expiry);
1273 else
1274 wpa_msg(wpa_s, MSG_INFO,
1275 DPP_EVENT_NET_ACCESS_KEY "%s", hex);
1276 os_free(hex);
1277 }
1278 }
1279
Hai Shalomc3565922019-10-28 11:58:20 -07001280 return wpas_dpp_process_config(wpa_s, auth, conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001281}
1282
1283
Hai Shalomfdcde762020-04-02 11:19:20 -07001284static int wpas_dpp_handle_key_pkg(struct wpa_supplicant *wpa_s,
1285 struct dpp_asymmetric_key *key)
1286{
1287#ifdef CONFIG_DPP2
1288 int res;
1289
1290 if (!key)
1291 return 0;
1292
1293 wpa_printf(MSG_DEBUG, "DPP: Received Configurator backup");
1294 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
1295
1296 while (key) {
1297 res = dpp_configurator_from_backup(wpa_s->dpp, key);
1298 if (res < 0)
1299 return -1;
1300 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFIGURATOR_ID "%d",
1301 res);
1302 key = key->next;
1303 }
1304#endif /* CONFIG_DPP2 */
1305
1306 return 0;
1307}
1308
1309
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001310static void wpas_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token,
1311 enum gas_query_result result,
1312 const struct wpabuf *adv_proto,
1313 const struct wpabuf *resp, u16 status_code)
1314{
1315 struct wpa_supplicant *wpa_s = ctx;
1316 const u8 *pos;
1317 struct dpp_authentication *auth = wpa_s->dpp_auth;
Hai Shalom021b0b52019-04-10 11:17:58 -07001318 int res;
1319 enum dpp_status_error status = DPP_STATUS_CONFIG_REJECTED;
Hai Shalomc3565922019-10-28 11:58:20 -07001320 unsigned int i;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001321
Roshan Pius3a1667e2018-07-03 15:17:14 -07001322 wpa_s->dpp_gas_dialog_token = -1;
1323
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001324 if (!auth || !auth->auth_success) {
1325 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
1326 return;
1327 }
Hai Shalom74f70d42019-02-11 14:42:39 -08001328 if (result != GAS_QUERY_SUCCESS ||
1329 !resp || status_code != WLAN_STATUS_SUCCESS) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001330 wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed");
1331 goto fail;
1332 }
1333
1334 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto",
1335 adv_proto);
1336 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)",
1337 resp);
1338
1339 if (wpabuf_len(adv_proto) != 10 ||
1340 !(pos = wpabuf_head(adv_proto)) ||
1341 pos[0] != WLAN_EID_ADV_PROTO ||
1342 pos[1] != 8 ||
1343 pos[3] != WLAN_EID_VENDOR_SPECIFIC ||
1344 pos[4] != 5 ||
1345 WPA_GET_BE24(&pos[5]) != OUI_WFA ||
1346 pos[8] != 0x1a ||
1347 pos[9] != 1) {
1348 wpa_printf(MSG_DEBUG,
1349 "DPP: Not a DPP Advertisement Protocol ID");
1350 goto fail;
1351 }
1352
1353 if (dpp_conf_resp_rx(auth, resp) < 0) {
1354 wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed");
1355 goto fail;
1356 }
1357
Hai Shalomc3565922019-10-28 11:58:20 -07001358 for (i = 0; i < auth->num_conf_obj; i++) {
1359 res = wpas_dpp_handle_config_obj(wpa_s, auth,
1360 &auth->conf_obj[i]);
1361 if (res < 0)
1362 goto fail;
1363 }
1364 if (auth->num_conf_obj)
1365 wpas_dpp_post_process_config(wpa_s, auth);
Hai Shalomfdcde762020-04-02 11:19:20 -07001366 if (wpas_dpp_handle_key_pkg(wpa_s, auth->conf_key_pkg) < 0)
1367 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001368
Hai Shalom021b0b52019-04-10 11:17:58 -07001369 status = DPP_STATUS_OK;
1370#ifdef CONFIG_TESTING_OPTIONS
1371 if (dpp_test == DPP_TEST_REJECT_CONFIG) {
1372 wpa_printf(MSG_INFO, "DPP: TESTING - Reject Config Object");
1373 status = DPP_STATUS_CONFIG_REJECTED;
1374 }
1375#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001376fail:
Hai Shalom021b0b52019-04-10 11:17:58 -07001377 if (status != DPP_STATUS_OK) {
1378 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1379 wpas_notify_dpp_configuration_failure(wpa_s);
1380 }
1381#ifdef CONFIG_DPP2
1382 if (auth->peer_version >= 2 &&
1383 auth->conf_resp_status == DPP_STATUS_OK) {
1384 struct wpabuf *msg;
1385
1386 wpa_printf(MSG_DEBUG, "DPP: Send DPP Configuration Result");
1387 msg = dpp_build_conf_result(auth, status);
1388 if (!msg)
1389 goto fail2;
1390
1391 wpa_msg(wpa_s, MSG_INFO,
1392 DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1393 MAC2STR(addr), auth->curr_freq,
1394 DPP_PA_CONFIGURATION_RESULT);
1395 offchannel_send_action(wpa_s, auth->curr_freq,
1396 addr, wpa_s->own_addr, broadcast,
1397 wpabuf_head(msg),
1398 wpabuf_len(msg),
1399 500, wpas_dpp_tx_status, 0);
1400 wpabuf_free(msg);
1401
1402 /* This exchange will be terminated in the TX status handler */
1403 return;
1404 }
1405fail2:
1406#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001407 dpp_auth_deinit(wpa_s->dpp_auth);
1408 wpa_s->dpp_auth = NULL;
1409}
1410
1411
1412static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
1413{
1414 struct dpp_authentication *auth = wpa_s->dpp_auth;
Hai Shalom021b0b52019-04-10 11:17:58 -07001415 struct wpabuf *buf;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001416 int res;
Hai Shalomc3565922019-10-28 11:58:20 -07001417 int *supp_op_classes;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001418
1419 wpa_s->dpp_gas_client = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001420 offchannel_send_action_done(wpa_s);
1421 wpas_dpp_listen_stop(wpa_s);
1422
Hai Shalomc3565922019-10-28 11:58:20 -07001423 supp_op_classes = wpas_supp_op_classes(wpa_s);
1424 buf = dpp_build_conf_req_helper(auth, wpa_s->conf->dpp_name,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001425 wpa_s->dpp_netrole,
Hai Shalomc3565922019-10-28 11:58:20 -07001426 wpa_s->conf->dpp_mud_url,
1427 supp_op_classes);
1428 os_free(supp_op_classes);
Hai Shalom021b0b52019-04-10 11:17:58 -07001429 if (!buf) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001430 wpa_printf(MSG_DEBUG,
1431 "DPP: No configuration request data available");
1432 return;
1433 }
1434
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001435 wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
1436 MAC2STR(auth->peer_mac_addr), auth->curr_freq);
1437
1438 res = gas_query_req(wpa_s->gas, auth->peer_mac_addr, auth->curr_freq,
Hai Shalomb755a2a2020-04-23 21:49:02 -07001439 1, 1, buf, wpas_dpp_gas_resp_cb, wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001440 if (res < 0) {
1441 wpa_msg(wpa_s, MSG_DEBUG, "GAS: Failed to send Query Request");
1442 wpabuf_free(buf);
1443 } else {
1444 wpa_printf(MSG_DEBUG,
1445 "DPP: GAS query started with dialog token %u", res);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001446 wpa_s->dpp_gas_dialog_token = res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001447 }
1448}
1449
1450
1451static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator)
1452{
1453 wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded");
1454 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d", initiator);
Hai Shalom706f99b2019-01-08 16:23:37 -08001455 wpas_notify_dpp_auth_success(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001456#ifdef CONFIG_TESTING_OPTIONS
1457 if (dpp_test == DPP_TEST_STOP_AT_AUTH_CONF) {
1458 wpa_printf(MSG_INFO,
1459 "DPP: TESTING - stop at Authentication Confirm");
1460 if (wpa_s->dpp_auth->configurator) {
1461 /* Prevent GAS response */
1462 wpa_s->dpp_auth->auth_success = 0;
1463 }
1464 return;
1465 }
1466#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001467
1468 if (wpa_s->dpp_auth->configurator)
1469 wpas_dpp_start_gas_server(wpa_s);
1470 else
1471 wpas_dpp_start_gas_client(wpa_s);
1472}
1473
1474
1475static void wpas_dpp_rx_auth_resp(struct wpa_supplicant *wpa_s, const u8 *src,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001476 const u8 *hdr, const u8 *buf, size_t len,
1477 unsigned int freq)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001478{
1479 struct dpp_authentication *auth = wpa_s->dpp_auth;
1480 struct wpabuf *msg;
1481
Roshan Pius3a1667e2018-07-03 15:17:14 -07001482 wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR
1483 " (freq %u MHz)", MAC2STR(src), freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001484
1485 if (!auth) {
1486 wpa_printf(MSG_DEBUG,
1487 "DPP: No DPP Authentication in progress - drop");
1488 return;
1489 }
1490
1491 if (!is_zero_ether_addr(auth->peer_mac_addr) &&
1492 os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1493 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1494 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1495 return;
1496 }
1497
1498 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
1499
Roshan Pius3a1667e2018-07-03 15:17:14 -07001500 if (auth->curr_freq != freq && auth->neg_freq == freq) {
1501 wpa_printf(MSG_DEBUG,
1502 "DPP: Responder accepted request for different negotiation channel");
1503 auth->curr_freq = freq;
1504 }
1505
1506 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001507 msg = dpp_auth_resp_rx(auth, hdr, buf, len);
1508 if (!msg) {
1509 if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) {
1510 wpa_printf(MSG_DEBUG,
1511 "DPP: Start wait for full response");
Hai Shalom706f99b2019-01-08 16:23:37 -08001512 wpas_notify_dpp_resp_pending(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001513 offchannel_send_action_done(wpa_s);
1514 wpas_dpp_listen_start(wpa_s, auth->curr_freq);
1515 return;
1516 }
1517 wpa_printf(MSG_DEBUG, "DPP: No confirm generated");
1518 return;
1519 }
1520 os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
1521
Roshan Pius3a1667e2018-07-03 15:17:14 -07001522 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1523 MAC2STR(src), auth->curr_freq, DPP_PA_AUTHENTICATION_CONF);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001524 offchannel_send_action(wpa_s, auth->curr_freq,
1525 src, wpa_s->own_addr, broadcast,
1526 wpabuf_head(msg), wpabuf_len(msg),
1527 500, wpas_dpp_tx_status, 0);
1528 wpabuf_free(msg);
1529 wpa_s->dpp_auth_ok_on_ack = 1;
1530}
1531
1532
1533static void wpas_dpp_rx_auth_conf(struct wpa_supplicant *wpa_s, const u8 *src,
1534 const u8 *hdr, const u8 *buf, size_t len)
1535{
1536 struct dpp_authentication *auth = wpa_s->dpp_auth;
1537
1538 wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR,
1539 MAC2STR(src));
1540
1541 if (!auth) {
1542 wpa_printf(MSG_DEBUG,
1543 "DPP: No DPP Authentication in progress - drop");
1544 return;
1545 }
1546
1547 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1548 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1549 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1550 return;
1551 }
1552
1553 if (dpp_auth_conf_rx(auth, hdr, buf, len) < 0) {
1554 wpa_printf(MSG_DEBUG, "DPP: Authentication failed");
Hai Shalom706f99b2019-01-08 16:23:37 -08001555 wpas_notify_dpp_auth_failure(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001556 return;
1557 }
1558
1559 wpas_dpp_auth_success(wpa_s, 0);
1560}
1561
1562
Hai Shalom021b0b52019-04-10 11:17:58 -07001563#ifdef CONFIG_DPP2
1564
1565static void wpas_dpp_config_result_wait_timeout(void *eloop_ctx,
1566 void *timeout_ctx)
1567{
1568 struct wpa_supplicant *wpa_s = eloop_ctx;
1569 struct dpp_authentication *auth = wpa_s->dpp_auth;
1570
1571 if (!auth || !auth->waiting_conf_result)
1572 return;
1573
1574 wpa_printf(MSG_DEBUG,
1575 "DPP: Timeout while waiting for Configuration Result");
1576 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom06768112019-12-04 15:49:43 -08001577 wpas_notify_dpp_configuration_failure(wpa_s);
Hai Shalom021b0b52019-04-10 11:17:58 -07001578 dpp_auth_deinit(auth);
1579 wpa_s->dpp_auth = NULL;
1580}
1581
1582
Hai Shalomc3565922019-10-28 11:58:20 -07001583static void wpas_dpp_conn_status_result_wait_timeout(void *eloop_ctx,
1584 void *timeout_ctx)
1585{
1586 struct wpa_supplicant *wpa_s = eloop_ctx;
1587 struct dpp_authentication *auth = wpa_s->dpp_auth;
1588
1589 if (!auth || !auth->waiting_conn_status_result)
1590 return;
1591
1592 wpa_printf(MSG_DEBUG,
1593 "DPP: Timeout while waiting for Connection Status Result");
1594 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONN_STATUS_RESULT "timeout");
Hai Shalom06768112019-12-04 15:49:43 -08001595 wpas_notify_dpp_timeout(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07001596 wpas_dpp_listen_stop(wpa_s);
1597 dpp_auth_deinit(auth);
1598 wpa_s->dpp_auth = NULL;
1599}
1600
1601
Hai Shalom021b0b52019-04-10 11:17:58 -07001602static void wpas_dpp_rx_conf_result(struct wpa_supplicant *wpa_s, const u8 *src,
1603 const u8 *hdr, const u8 *buf, size_t len)
1604{
1605 struct dpp_authentication *auth = wpa_s->dpp_auth;
1606 enum dpp_status_error status;
1607
1608 wpa_printf(MSG_DEBUG, "DPP: Configuration Result from " MACSTR,
1609 MAC2STR(src));
1610
1611 if (!auth || !auth->waiting_conf_result) {
1612 wpa_printf(MSG_DEBUG,
1613 "DPP: No DPP Configuration waiting for result - drop");
1614 return;
1615 }
1616
1617 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1618 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1619 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1620 return;
1621 }
1622
1623 status = dpp_conf_result_rx(auth, hdr, buf, len);
1624
Hai Shalomc3565922019-10-28 11:58:20 -07001625 if (status == DPP_STATUS_OK && auth->send_conn_status) {
1626 wpa_msg(wpa_s, MSG_INFO,
1627 DPP_EVENT_CONF_SENT "wait_conn_status=1");
1628 wpa_printf(MSG_DEBUG, "DPP: Wait for Connection Status Result");
Hai Shalom06768112019-12-04 15:49:43 -08001629 wpas_notify_dpp_config_accepted(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07001630 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout,
1631 wpa_s, NULL);
1632 auth->waiting_conn_status_result = 1;
1633 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout,
1634 wpa_s, NULL);
1635 eloop_register_timeout(16, 0,
1636 wpas_dpp_conn_status_result_wait_timeout,
1637 wpa_s, NULL);
1638 offchannel_send_action_done(wpa_s);
1639 wpas_dpp_listen_start(wpa_s, auth->neg_freq ? auth->neg_freq :
1640 auth->curr_freq);
1641 return;
1642 }
Hai Shalom021b0b52019-04-10 11:17:58 -07001643 offchannel_send_action_done(wpa_s);
1644 wpas_dpp_listen_stop(wpa_s);
Hai Shalome4073332019-11-05 16:20:12 -08001645 if (status == DPP_STATUS_OK) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001646 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
Hai Shalome4073332019-11-05 16:20:12 -08001647 wpas_notify_dpp_config_sent(wpa_s);
1648 }
1649 else {
Hai Shalom021b0b52019-04-10 11:17:58 -07001650 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom06768112019-12-04 15:49:43 -08001651 wpas_notify_dpp_config_rejected(wpa_s);
Hai Shalome4073332019-11-05 16:20:12 -08001652 }
Hai Shalom021b0b52019-04-10 11:17:58 -07001653 dpp_auth_deinit(auth);
1654 wpa_s->dpp_auth = NULL;
1655 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL);
1656}
1657
Hai Shalom81f62d82019-07-22 12:10:00 -07001658
Hai Shalomc3565922019-10-28 11:58:20 -07001659static void wpas_dpp_rx_conn_status_result(struct wpa_supplicant *wpa_s,
1660 const u8 *src, const u8 *hdr,
1661 const u8 *buf, size_t len)
1662{
1663 struct dpp_authentication *auth = wpa_s->dpp_auth;
1664 enum dpp_status_error status;
1665 u8 ssid[SSID_MAX_LEN];
1666 size_t ssid_len = 0;
1667 char *channel_list = NULL;
1668
1669 wpa_printf(MSG_DEBUG, "DPP: Connection Status Result");
1670
1671 if (!auth || !auth->waiting_conn_status_result) {
1672 wpa_printf(MSG_DEBUG,
1673 "DPP: No DPP Configuration waiting for connection status result - drop");
1674 return;
1675 }
1676
1677 status = dpp_conn_status_result_rx(auth, hdr, buf, len,
1678 ssid, &ssid_len, &channel_list);
1679 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONN_STATUS_RESULT
1680 "result=%d ssid=%s channel_list=%s",
1681 status, wpa_ssid_txt(ssid, ssid_len),
1682 channel_list ? channel_list : "N/A");
Hai Shalom06768112019-12-04 15:49:43 -08001683 wpas_notify_dpp_conn_status(wpa_s, status, wpa_ssid_txt(ssid, ssid_len),
1684 channel_list, auth->band_list, auth->band_list_size);
Hai Shalomc3565922019-10-28 11:58:20 -07001685 os_free(channel_list);
1686 offchannel_send_action_done(wpa_s);
1687 wpas_dpp_listen_stop(wpa_s);
1688 dpp_auth_deinit(auth);
1689 wpa_s->dpp_auth = NULL;
1690 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout,
1691 wpa_s, NULL);
1692}
1693
1694
Hai Shalom81f62d82019-07-22 12:10:00 -07001695static int wpas_dpp_process_conf_obj(void *ctx,
1696 struct dpp_authentication *auth)
1697{
1698 struct wpa_supplicant *wpa_s = ctx;
Hai Shalomc3565922019-10-28 11:58:20 -07001699 unsigned int i;
1700 int res = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -07001701
Hai Shalomc3565922019-10-28 11:58:20 -07001702 for (i = 0; i < auth->num_conf_obj; i++) {
1703 res = wpas_dpp_handle_config_obj(wpa_s, auth,
1704 &auth->conf_obj[i]);
1705 if (res)
1706 break;
1707 }
1708 if (!res)
1709 wpas_dpp_post_process_config(wpa_s, auth);
1710
1711 return res;
Hai Shalom81f62d82019-07-22 12:10:00 -07001712}
1713
Hai Shalomfdcde762020-04-02 11:19:20 -07001714
1715static void wpas_dpp_remove_bi(void *ctx, struct dpp_bootstrap_info *bi)
1716{
1717 struct wpa_supplicant *wpa_s = ctx;
1718
1719 if (bi == wpa_s->dpp_chirp_bi)
1720 wpas_dpp_chirp_stop(wpa_s);
1721}
1722
1723
1724static void
1725wpas_dpp_rx_presence_announcement(struct wpa_supplicant *wpa_s, const u8 *src,
1726 const u8 *hdr, const u8 *buf, size_t len,
1727 unsigned int freq)
1728{
1729 const u8 *r_bootstrap;
1730 u16 r_bootstrap_len;
1731 struct dpp_bootstrap_info *peer_bi;
1732 struct dpp_authentication *auth;
1733
1734 if (!wpa_s->dpp)
1735 return;
1736
1737 if (wpa_s->dpp_auth) {
1738 wpa_printf(MSG_DEBUG,
1739 "DPP: Ignore Presence Announcement during ongoing Authentication");
1740 return;
1741 }
1742
1743 wpa_printf(MSG_DEBUG, "DPP: Presence Announcement from " MACSTR,
1744 MAC2STR(src));
1745
1746 r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
1747 &r_bootstrap_len);
1748 if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
1749 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1750 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
1751 return;
1752 }
1753 wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
1754 r_bootstrap, r_bootstrap_len);
1755 peer_bi = dpp_bootstrap_find_chirp(wpa_s->dpp, r_bootstrap);
1756 if (!peer_bi) {
1757 wpa_printf(MSG_DEBUG,
1758 "DPP: No matching bootstrapping information found");
1759 return;
1760 }
1761
1762 auth = dpp_auth_init(wpa_s->dpp, wpa_s, peer_bi, NULL,
1763 DPP_CAPAB_CONFIGURATOR, freq, NULL, 0);
1764 if (!auth)
1765 return;
1766 wpas_dpp_set_testing_options(wpa_s, auth);
1767 if (dpp_set_configurator(auth, wpa_s->dpp_configurator_params) < 0) {
1768 dpp_auth_deinit(auth);
1769 return;
1770 }
1771
1772 auth->neg_freq = freq;
1773
1774 if (!is_zero_ether_addr(peer_bi->mac_addr))
1775 os_memcpy(auth->peer_mac_addr, peer_bi->mac_addr, ETH_ALEN);
1776
1777 wpa_s->dpp_auth = auth;
1778 if (wpas_dpp_auth_init_next(wpa_s) < 0) {
1779 dpp_auth_deinit(wpa_s->dpp_auth);
1780 wpa_s->dpp_auth = NULL;
1781 }
1782}
1783
Hai Shalom021b0b52019-04-10 11:17:58 -07001784#endif /* CONFIG_DPP2 */
1785
1786
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001787static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant *wpa_s,
1788 const u8 *src,
1789 const u8 *buf, size_t len)
1790{
1791 struct wpa_ssid *ssid;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001792 const u8 *connector, *trans_id, *status;
1793 u16 connector_len, trans_id_len, status_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001794 struct dpp_introduction intro;
1795 struct rsn_pmksa_cache_entry *entry;
1796 struct os_time now;
1797 struct os_reltime rnow;
1798 os_time_t expiry;
1799 unsigned int seconds;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001800 enum dpp_status_error res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001801
1802 wpa_printf(MSG_DEBUG, "DPP: Peer Discovery Response from " MACSTR,
1803 MAC2STR(src));
1804 if (is_zero_ether_addr(wpa_s->dpp_intro_bssid) ||
1805 os_memcmp(src, wpa_s->dpp_intro_bssid, ETH_ALEN) != 0) {
1806 wpa_printf(MSG_DEBUG, "DPP: Not waiting for response from "
1807 MACSTR " - drop", MAC2STR(src));
1808 return;
1809 }
1810 offchannel_send_action_done(wpa_s);
1811
1812 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1813 if (ssid == wpa_s->dpp_intro_network)
1814 break;
1815 }
1816 if (!ssid || !ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1817 !ssid->dpp_csign) {
1818 wpa_printf(MSG_DEBUG,
1819 "DPP: Profile not found for network introduction");
1820 return;
1821 }
1822
1823 trans_id = dpp_get_attr(buf, len, DPP_ATTR_TRANSACTION_ID,
1824 &trans_id_len);
1825 if (!trans_id || trans_id_len != 1) {
1826 wpa_printf(MSG_DEBUG,
1827 "DPP: Peer did not include Transaction ID");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001828 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1829 " fail=missing_transaction_id", MAC2STR(src));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001830 goto fail;
1831 }
1832 if (trans_id[0] != TRANSACTION_ID) {
1833 wpa_printf(MSG_DEBUG,
1834 "DPP: Ignore frame with unexpected Transaction ID %u",
1835 trans_id[0]);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001836 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1837 " fail=transaction_id_mismatch", MAC2STR(src));
1838 goto fail;
1839 }
1840
1841 status = dpp_get_attr(buf, len, DPP_ATTR_STATUS, &status_len);
1842 if (!status || status_len != 1) {
1843 wpa_printf(MSG_DEBUG, "DPP: Peer did not include Status");
1844 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1845 " fail=missing_status", MAC2STR(src));
1846 goto fail;
1847 }
1848 if (status[0] != DPP_STATUS_OK) {
1849 wpa_printf(MSG_DEBUG,
1850 "DPP: Peer rejected network introduction: Status %u",
1851 status[0]);
1852 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1853 " status=%u", MAC2STR(src), status[0]);
Hai Shalomc3565922019-10-28 11:58:20 -07001854#ifdef CONFIG_DPP2
1855 wpas_dpp_send_conn_status_result(wpa_s, status[0]);
1856#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001857 goto fail;
1858 }
1859
1860 connector = dpp_get_attr(buf, len, DPP_ATTR_CONNECTOR, &connector_len);
1861 if (!connector) {
1862 wpa_printf(MSG_DEBUG,
1863 "DPP: Peer did not include its Connector");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001864 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1865 " fail=missing_connector", MAC2STR(src));
1866 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001867 }
1868
Roshan Pius3a1667e2018-07-03 15:17:14 -07001869 res = dpp_peer_intro(&intro, ssid->dpp_connector,
1870 ssid->dpp_netaccesskey,
1871 ssid->dpp_netaccesskey_len,
1872 ssid->dpp_csign,
1873 ssid->dpp_csign_len,
1874 connector, connector_len, &expiry);
1875 if (res != DPP_STATUS_OK) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001876 wpa_printf(MSG_INFO,
1877 "DPP: Network Introduction protocol resulted in failure");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001878 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1879 " fail=peer_connector_validation_failed", MAC2STR(src));
Hai Shalomc3565922019-10-28 11:58:20 -07001880#ifdef CONFIG_DPP2
1881 wpas_dpp_send_conn_status_result(wpa_s, res);
1882#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001883 goto fail;
1884 }
1885
1886 entry = os_zalloc(sizeof(*entry));
1887 if (!entry)
1888 goto fail;
1889 os_memcpy(entry->aa, src, ETH_ALEN);
1890 os_memcpy(entry->pmkid, intro.pmkid, PMKID_LEN);
1891 os_memcpy(entry->pmk, intro.pmk, intro.pmk_len);
1892 entry->pmk_len = intro.pmk_len;
1893 entry->akmp = WPA_KEY_MGMT_DPP;
1894 if (expiry) {
1895 os_get_time(&now);
1896 seconds = expiry - now.sec;
1897 } else {
1898 seconds = 86400 * 7;
1899 }
1900 os_get_reltime(&rnow);
1901 entry->expiration = rnow.sec + seconds;
1902 entry->reauth_time = rnow.sec + seconds;
1903 entry->network_ctx = ssid;
1904 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
1905
Roshan Pius3a1667e2018-07-03 15:17:14 -07001906 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1907 " status=%u", MAC2STR(src), status[0]);
1908
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001909 wpa_printf(MSG_DEBUG,
1910 "DPP: Try connection again after successful network introduction");
1911 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
1912 wpa_supplicant_cancel_sched_scan(wpa_s);
1913 wpa_supplicant_req_scan(wpa_s, 0, 0);
1914 }
1915fail:
1916 os_memset(&intro, 0, sizeof(intro));
1917}
1918
1919
Roshan Pius3a1667e2018-07-03 15:17:14 -07001920static int wpas_dpp_allow_ir(struct wpa_supplicant *wpa_s, unsigned int freq)
1921{
1922 int i, j;
1923
1924 if (!wpa_s->hw.modes)
1925 return -1;
1926
1927 for (i = 0; i < wpa_s->hw.num_modes; i++) {
1928 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
1929
1930 for (j = 0; j < mode->num_channels; j++) {
1931 struct hostapd_channel_data *chan = &mode->channels[j];
1932
1933 if (chan->freq != (int) freq)
1934 continue;
1935
1936 if (chan->flag & (HOSTAPD_CHAN_DISABLED |
1937 HOSTAPD_CHAN_NO_IR |
1938 HOSTAPD_CHAN_RADAR))
1939 continue;
1940
1941 return 1;
1942 }
1943 }
1944
1945 wpa_printf(MSG_DEBUG,
1946 "DPP: Frequency %u MHz not supported or does not allow PKEX initiation in the current channel list",
1947 freq);
1948
1949 return 0;
1950}
1951
1952
1953static int wpas_dpp_pkex_next_channel(struct wpa_supplicant *wpa_s,
1954 struct dpp_pkex *pkex)
1955{
1956 if (pkex->freq == 2437)
1957 pkex->freq = 5745;
1958 else if (pkex->freq == 5745)
1959 pkex->freq = 5220;
1960 else if (pkex->freq == 5220)
1961 pkex->freq = 60480;
1962 else
1963 return -1; /* no more channels to try */
1964
1965 if (wpas_dpp_allow_ir(wpa_s, pkex->freq) == 1) {
1966 wpa_printf(MSG_DEBUG, "DPP: Try to initiate on %u MHz",
1967 pkex->freq);
1968 return 0;
1969 }
1970
1971 /* Could not use this channel - try the next one */
1972 return wpas_dpp_pkex_next_channel(wpa_s, pkex);
1973}
1974
1975
1976static void wpas_dpp_pkex_retry_timeout(void *eloop_ctx, void *timeout_ctx)
1977{
1978 struct wpa_supplicant *wpa_s = eloop_ctx;
1979 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1980
1981 if (!pkex || !pkex->exchange_req)
1982 return;
1983 if (pkex->exch_req_tries >= 5) {
1984 if (wpas_dpp_pkex_next_channel(wpa_s, pkex) < 0) {
1985 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1986 "No response from PKEX peer");
1987 dpp_pkex_free(pkex);
1988 wpa_s->dpp_pkex = NULL;
1989 return;
1990 }
1991 pkex->exch_req_tries = 0;
1992 }
1993
1994 pkex->exch_req_tries++;
1995 wpa_printf(MSG_DEBUG, "DPP: Retransmit PKEX Exchange Request (try %u)",
1996 pkex->exch_req_tries);
1997 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1998 MAC2STR(broadcast), pkex->freq, DPP_PA_PKEX_EXCHANGE_REQ);
1999 offchannel_send_action(wpa_s, pkex->freq, broadcast,
2000 wpa_s->own_addr, broadcast,
2001 wpabuf_head(pkex->exchange_req),
2002 wpabuf_len(pkex->exchange_req),
2003 pkex->exch_req_wait_time,
2004 wpas_dpp_tx_pkex_status, 0);
2005}
2006
2007
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002008static void
2009wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s,
2010 unsigned int freq, const u8 *dst,
2011 const u8 *src, const u8 *bssid,
2012 const u8 *data, size_t data_len,
2013 enum offchannel_send_action_result result)
2014{
Roshan Pius3a1667e2018-07-03 15:17:14 -07002015 const char *res_txt;
2016 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
2017
2018 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
2019 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
2020 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002021 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
2022 " result=%s (PKEX)",
Roshan Pius3a1667e2018-07-03 15:17:14 -07002023 freq, MAC2STR(dst), res_txt);
2024 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
2025 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
2026
2027 if (!pkex) {
2028 wpa_printf(MSG_DEBUG,
2029 "DPP: Ignore TX status since there is no ongoing PKEX exchange");
2030 return;
2031 }
2032
2033 if (pkex->failed) {
2034 wpa_printf(MSG_DEBUG,
2035 "DPP: Terminate PKEX exchange due to an earlier error");
2036 if (pkex->t > pkex->own_bi->pkex_t)
2037 pkex->own_bi->pkex_t = pkex->t;
2038 dpp_pkex_free(pkex);
2039 wpa_s->dpp_pkex = NULL;
2040 return;
2041 }
2042
2043 if (pkex->exch_req_wait_time && pkex->exchange_req) {
2044 /* Wait for PKEX Exchange Response frame and retry request if
2045 * no response is seen. */
2046 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
2047 eloop_register_timeout(pkex->exch_req_wait_time / 1000,
2048 (pkex->exch_req_wait_time % 1000) * 1000,
2049 wpas_dpp_pkex_retry_timeout, wpa_s,
2050 NULL);
2051 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002052}
2053
2054
2055static void
2056wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant *wpa_s, const u8 *src,
2057 const u8 *buf, size_t len, unsigned int freq)
2058{
2059 struct wpabuf *msg;
2060 unsigned int wait_time;
2061
2062 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Request from " MACSTR,
2063 MAC2STR(src));
2064
2065 /* TODO: Support multiple PKEX codes by iterating over all the enabled
2066 * values here */
2067
2068 if (!wpa_s->dpp_pkex_code || !wpa_s->dpp_pkex_bi) {
2069 wpa_printf(MSG_DEBUG,
2070 "DPP: No PKEX code configured - ignore request");
2071 return;
2072 }
2073
2074 if (wpa_s->dpp_pkex) {
2075 /* TODO: Support parallel operations */
2076 wpa_printf(MSG_DEBUG,
2077 "DPP: Already in PKEX session - ignore new request");
2078 return;
2079 }
2080
Roshan Pius3a1667e2018-07-03 15:17:14 -07002081 wpa_s->dpp_pkex = dpp_pkex_rx_exchange_req(wpa_s, wpa_s->dpp_pkex_bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002082 wpa_s->own_addr, src,
2083 wpa_s->dpp_pkex_identifier,
2084 wpa_s->dpp_pkex_code,
2085 buf, len);
2086 if (!wpa_s->dpp_pkex) {
2087 wpa_printf(MSG_DEBUG,
2088 "DPP: Failed to process the request - ignore it");
2089 return;
2090 }
2091
2092 msg = wpa_s->dpp_pkex->exchange_resp;
2093 wait_time = wpa_s->max_remain_on_chan;
2094 if (wait_time > 2000)
2095 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002096 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2097 MAC2STR(src), freq, DPP_PA_PKEX_EXCHANGE_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002098 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
2099 broadcast,
2100 wpabuf_head(msg), wpabuf_len(msg),
2101 wait_time, wpas_dpp_tx_pkex_status, 0);
2102}
2103
2104
2105static void
2106wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant *wpa_s, const u8 *src,
2107 const u8 *buf, size_t len, unsigned int freq)
2108{
2109 struct wpabuf *msg;
2110 unsigned int wait_time;
2111
2112 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Response from " MACSTR,
2113 MAC2STR(src));
2114
2115 /* TODO: Support multiple PKEX codes by iterating over all the enabled
2116 * values here */
2117
2118 if (!wpa_s->dpp_pkex || !wpa_s->dpp_pkex->initiator ||
2119 wpa_s->dpp_pkex->exchange_done) {
2120 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
2121 return;
2122 }
2123
Roshan Pius3a1667e2018-07-03 15:17:14 -07002124 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
2125 wpa_s->dpp_pkex->exch_req_wait_time = 0;
2126
2127 msg = dpp_pkex_rx_exchange_resp(wpa_s->dpp_pkex, src, buf, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002128 if (!msg) {
2129 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
2130 return;
2131 }
2132
2133 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Request to " MACSTR,
2134 MAC2STR(src));
2135
2136 wait_time = wpa_s->max_remain_on_chan;
2137 if (wait_time > 2000)
2138 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002139 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2140 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_REQ);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002141 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
2142 broadcast,
2143 wpabuf_head(msg), wpabuf_len(msg),
2144 wait_time, wpas_dpp_tx_pkex_status, 0);
2145 wpabuf_free(msg);
2146}
2147
2148
Roshan Pius3a1667e2018-07-03 15:17:14 -07002149static struct dpp_bootstrap_info *
2150wpas_dpp_pkex_finish(struct wpa_supplicant *wpa_s, const u8 *peer,
2151 unsigned int freq)
2152{
Roshan Pius3a1667e2018-07-03 15:17:14 -07002153 struct dpp_bootstrap_info *bi;
2154
Hai Shalom021b0b52019-04-10 11:17:58 -07002155 bi = dpp_pkex_finish(wpa_s->dpp, wpa_s->dpp_pkex, peer, freq);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002156 if (!bi)
2157 return NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002158 wpa_s->dpp_pkex = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002159 return bi;
2160}
2161
2162
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002163static void
2164wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant *wpa_s, const u8 *src,
2165 const u8 *hdr, const u8 *buf, size_t len,
2166 unsigned int freq)
2167{
2168 struct wpabuf *msg;
2169 unsigned int wait_time;
2170 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002171
2172 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Request from " MACSTR,
2173 MAC2STR(src));
2174
2175 if (!pkex || pkex->initiator || !pkex->exchange_done) {
2176 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
2177 return;
2178 }
2179
2180 msg = dpp_pkex_rx_commit_reveal_req(pkex, hdr, buf, len);
2181 if (!msg) {
2182 wpa_printf(MSG_DEBUG, "DPP: Failed to process the request");
Roshan Pius3a1667e2018-07-03 15:17:14 -07002183 if (pkex->failed) {
2184 wpa_printf(MSG_DEBUG, "DPP: Terminate PKEX exchange");
2185 if (pkex->t > pkex->own_bi->pkex_t)
2186 pkex->own_bi->pkex_t = pkex->t;
2187 dpp_pkex_free(wpa_s->dpp_pkex);
2188 wpa_s->dpp_pkex = NULL;
2189 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002190 return;
2191 }
2192
2193 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Response to "
2194 MACSTR, MAC2STR(src));
2195
2196 wait_time = wpa_s->max_remain_on_chan;
2197 if (wait_time > 2000)
2198 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002199 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2200 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002201 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
2202 broadcast,
2203 wpabuf_head(msg), wpabuf_len(msg),
2204 wait_time, wpas_dpp_tx_pkex_status, 0);
2205 wpabuf_free(msg);
2206
Roshan Pius3a1667e2018-07-03 15:17:14 -07002207 wpas_dpp_pkex_finish(wpa_s, src, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002208}
2209
2210
2211static void
2212wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant *wpa_s, const u8 *src,
2213 const u8 *hdr, const u8 *buf, size_t len,
2214 unsigned int freq)
2215{
2216 int res;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002217 struct dpp_bootstrap_info *bi;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002218 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
2219 char cmd[500];
2220
2221 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Response from " MACSTR,
2222 MAC2STR(src));
2223
2224 if (!pkex || !pkex->initiator || !pkex->exchange_done) {
2225 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
2226 return;
2227 }
2228
2229 res = dpp_pkex_rx_commit_reveal_resp(pkex, hdr, buf, len);
2230 if (res < 0) {
2231 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
2232 return;
2233 }
2234
Roshan Pius3a1667e2018-07-03 15:17:14 -07002235 bi = wpas_dpp_pkex_finish(wpa_s, src, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002236 if (!bi)
2237 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002238
2239 os_snprintf(cmd, sizeof(cmd), " peer=%u %s",
2240 bi->id,
2241 wpa_s->dpp_pkex_auth_cmd ? wpa_s->dpp_pkex_auth_cmd : "");
2242 wpa_printf(MSG_DEBUG,
2243 "DPP: Start authentication after PKEX with parameters: %s",
2244 cmd);
2245 if (wpas_dpp_auth_init(wpa_s, cmd) < 0) {
2246 wpa_printf(MSG_DEBUG,
2247 "DPP: Authentication initialization failed");
Hai Shalomfdcde762020-04-02 11:19:20 -07002248 offchannel_send_action_done(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002249 return;
2250 }
2251}
2252
2253
2254void wpas_dpp_rx_action(struct wpa_supplicant *wpa_s, const u8 *src,
2255 const u8 *buf, size_t len, unsigned int freq)
2256{
2257 u8 crypto_suite;
2258 enum dpp_public_action_frame_type type;
2259 const u8 *hdr;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002260 unsigned int pkex_t;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002261
2262 if (len < DPP_HDR_LEN)
2263 return;
2264 if (WPA_GET_BE24(buf) != OUI_WFA || buf[3] != DPP_OUI_TYPE)
2265 return;
2266 hdr = buf;
2267 buf += 4;
2268 len -= 4;
2269 crypto_suite = *buf++;
2270 type = *buf++;
2271 len -= 2;
2272
2273 wpa_printf(MSG_DEBUG,
2274 "DPP: Received DPP Public Action frame crypto suite %u type %d from "
2275 MACSTR " freq=%u",
2276 crypto_suite, type, MAC2STR(src), freq);
2277 if (crypto_suite != 1) {
2278 wpa_printf(MSG_DEBUG, "DPP: Unsupported crypto suite %u",
2279 crypto_suite);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002280 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
2281 " freq=%u type=%d ignore=unsupported-crypto-suite",
2282 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002283 return;
2284 }
2285 wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002286 if (dpp_check_attrs(buf, len) < 0) {
2287 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
2288 " freq=%u type=%d ignore=invalid-attributes",
2289 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002290 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002291 }
2292 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR " freq=%u type=%d",
2293 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002294
2295 switch (type) {
2296 case DPP_PA_AUTHENTICATION_REQ:
2297 wpas_dpp_rx_auth_req(wpa_s, src, hdr, buf, len, freq);
2298 break;
2299 case DPP_PA_AUTHENTICATION_RESP:
Roshan Pius3a1667e2018-07-03 15:17:14 -07002300 wpas_dpp_rx_auth_resp(wpa_s, src, hdr, buf, len, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002301 break;
2302 case DPP_PA_AUTHENTICATION_CONF:
2303 wpas_dpp_rx_auth_conf(wpa_s, src, hdr, buf, len);
2304 break;
2305 case DPP_PA_PEER_DISCOVERY_RESP:
2306 wpas_dpp_rx_peer_disc_resp(wpa_s, src, buf, len);
2307 break;
2308 case DPP_PA_PKEX_EXCHANGE_REQ:
2309 wpas_dpp_rx_pkex_exchange_req(wpa_s, src, buf, len, freq);
2310 break;
2311 case DPP_PA_PKEX_EXCHANGE_RESP:
2312 wpas_dpp_rx_pkex_exchange_resp(wpa_s, src, buf, len, freq);
2313 break;
2314 case DPP_PA_PKEX_COMMIT_REVEAL_REQ:
2315 wpas_dpp_rx_pkex_commit_reveal_req(wpa_s, src, hdr, buf, len,
2316 freq);
2317 break;
2318 case DPP_PA_PKEX_COMMIT_REVEAL_RESP:
2319 wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s, src, hdr, buf, len,
2320 freq);
2321 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07002322#ifdef CONFIG_DPP2
2323 case DPP_PA_CONFIGURATION_RESULT:
2324 wpas_dpp_rx_conf_result(wpa_s, src, hdr, buf, len);
2325 break;
Hai Shalomc3565922019-10-28 11:58:20 -07002326 case DPP_PA_CONNECTION_STATUS_RESULT:
2327 wpas_dpp_rx_conn_status_result(wpa_s, src, hdr, buf, len);
2328 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07002329 case DPP_PA_PRESENCE_ANNOUNCEMENT:
2330 wpas_dpp_rx_presence_announcement(wpa_s, src, hdr, buf, len,
2331 freq);
2332 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07002333#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002334 default:
2335 wpa_printf(MSG_DEBUG,
2336 "DPP: Ignored unsupported frame subtype %d", type);
2337 break;
2338 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002339
2340 if (wpa_s->dpp_pkex)
2341 pkex_t = wpa_s->dpp_pkex->t;
2342 else if (wpa_s->dpp_pkex_bi)
2343 pkex_t = wpa_s->dpp_pkex_bi->pkex_t;
2344 else
2345 pkex_t = 0;
2346 if (pkex_t >= PKEX_COUNTER_T_LIMIT) {
2347 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_PKEX_T_LIMIT "id=0");
2348 wpas_dpp_pkex_remove(wpa_s, "*");
2349 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002350}
2351
2352
2353static struct wpabuf *
2354wpas_dpp_gas_req_handler(void *ctx, const u8 *sa, const u8 *query,
2355 size_t query_len)
2356{
2357 struct wpa_supplicant *wpa_s = ctx;
2358 struct dpp_authentication *auth = wpa_s->dpp_auth;
2359 struct wpabuf *resp;
2360
2361 wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR,
2362 MAC2STR(sa));
2363 if (!auth || !auth->auth_success ||
2364 os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) {
2365 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
2366 return NULL;
2367 }
Hai Shalomc3565922019-10-28 11:58:20 -07002368
2369 if (wpa_s->dpp_auth_ok_on_ack && auth->configurator) {
2370 wpa_printf(MSG_DEBUG,
2371 "DPP: Have not received ACK for Auth Confirm yet - assume it was received based on this GAS request");
2372 /* wpas_dpp_auth_success() would normally have been called from
2373 * TX status handler, but since there was no such handler call
2374 * yet, simply send out the event message and proceed with
2375 * exchange. */
2376 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=1");
2377 wpa_s->dpp_auth_ok_on_ack = 0;
2378 }
2379
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002380 wpa_hexdump(MSG_DEBUG,
2381 "DPP: Received Configuration Request (GAS Query Request)",
2382 query, query_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002383 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_REQ_RX "src=" MACSTR,
2384 MAC2STR(sa));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002385 resp = dpp_conf_req_rx(auth, query, query_len);
Hai Shalom59532852018-12-07 10:32:58 -08002386 if (!resp) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002387 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -08002388 wpas_notify_dpp_configuration_failure(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08002389 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002390 auth->conf_resp = resp;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002391 return resp;
2392}
2393
2394
2395static void
2396wpas_dpp_gas_status_handler(void *ctx, struct wpabuf *resp, int ok)
2397{
2398 struct wpa_supplicant *wpa_s = ctx;
2399 struct dpp_authentication *auth = wpa_s->dpp_auth;
2400
2401 if (!auth) {
2402 wpabuf_free(resp);
2403 return;
2404 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002405 if (auth->conf_resp != resp) {
2406 wpa_printf(MSG_DEBUG,
2407 "DPP: Ignore GAS status report (ok=%d) for unknown response",
2408 ok);
2409 wpabuf_free(resp);
2410 return;
2411 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002412
2413 wpa_printf(MSG_DEBUG, "DPP: Configuration exchange completed (ok=%d)",
2414 ok);
2415 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002416 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07002417#ifdef CONFIG_DPP2
2418 if (ok && auth->peer_version >= 2 &&
2419 auth->conf_resp_status == DPP_STATUS_OK) {
2420 wpa_printf(MSG_DEBUG, "DPP: Wait for Configuration Result");
Hai Shalom06768112019-12-04 15:49:43 -08002421 wpas_notify_dpp_config_sent_wait_response(wpa_s);
Hai Shalom021b0b52019-04-10 11:17:58 -07002422 auth->waiting_conf_result = 1;
2423 auth->conf_resp = NULL;
2424 wpabuf_free(resp);
2425 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout,
2426 wpa_s, NULL);
2427 eloop_register_timeout(2, 0,
2428 wpas_dpp_config_result_wait_timeout,
2429 wpa_s, NULL);
2430 return;
2431 }
2432#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002433 offchannel_send_action_done(wpa_s);
2434 wpas_dpp_listen_stop(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08002435 if (ok) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002436 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
Hai Shalom706f99b2019-01-08 16:23:37 -08002437 wpas_notify_dpp_config_sent(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08002438 }
2439 else {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002440 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -08002441 wpas_notify_dpp_configuration_failure(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08002442 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002443 dpp_auth_deinit(wpa_s->dpp_auth);
2444 wpa_s->dpp_auth = NULL;
2445 wpabuf_free(resp);
2446}
2447
2448
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002449int wpas_dpp_configurator_sign(struct wpa_supplicant *wpa_s, const char *cmd)
2450{
2451 struct dpp_authentication *auth;
2452 int ret = -1;
2453 char *curve = NULL;
2454
Hai Shalomfdcde762020-04-02 11:19:20 -07002455 auth = dpp_alloc_auth(wpa_s->dpp, wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002456 if (!auth)
2457 return -1;
2458
2459 curve = get_param(cmd, " curve=");
Hai Shalom74f70d42019-02-11 14:42:39 -08002460 wpas_dpp_set_testing_options(wpa_s, auth);
Hai Shalomfdcde762020-04-02 11:19:20 -07002461 if (dpp_set_configurator(auth, cmd) == 0 &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002462 dpp_configurator_own_config(auth, curve, 0) == 0)
Hai Shalomc3565922019-10-28 11:58:20 -07002463 ret = wpas_dpp_handle_config_obj(wpa_s, auth,
2464 &auth->conf_obj[0]);
2465 if (!ret)
2466 wpas_dpp_post_process_config(wpa_s, auth);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002467
2468 dpp_auth_deinit(auth);
2469 os_free(curve);
2470
2471 return ret;
2472}
2473
2474
2475static void
2476wpas_dpp_tx_introduction_status(struct wpa_supplicant *wpa_s,
2477 unsigned int freq, const u8 *dst,
2478 const u8 *src, const u8 *bssid,
2479 const u8 *data, size_t data_len,
2480 enum offchannel_send_action_result result)
2481{
Roshan Pius3a1667e2018-07-03 15:17:14 -07002482 const char *res_txt;
2483
2484 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
2485 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
2486 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002487 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
2488 " result=%s (DPP Peer Discovery Request)",
Roshan Pius3a1667e2018-07-03 15:17:14 -07002489 freq, MAC2STR(dst), res_txt);
2490 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
2491 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002492 /* TODO: Time out wait for response more quickly in error cases? */
2493}
2494
2495
2496int wpas_dpp_check_connect(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2497 struct wpa_bss *bss)
2498{
2499 struct os_time now;
2500 struct wpabuf *msg;
2501 unsigned int wait_time;
Hai Shalom021b0b52019-04-10 11:17:58 -07002502 const u8 *rsn;
2503 struct wpa_ie_data ied;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002504
2505 if (!(ssid->key_mgmt & WPA_KEY_MGMT_DPP) || !bss)
2506 return 0; /* Not using DPP AKM - continue */
Hai Shalom021b0b52019-04-10 11:17:58 -07002507 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2508 if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ied) == 0 &&
2509 !(ied.key_mgmt & WPA_KEY_MGMT_DPP))
2510 return 0; /* AP does not support DPP AKM - continue */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002511 if (wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid))
2512 return 0; /* PMKSA exists for DPP AKM - continue */
2513
2514 if (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
2515 !ssid->dpp_csign) {
2516 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
2517 "missing %s",
2518 !ssid->dpp_connector ? "Connector" :
2519 (!ssid->dpp_netaccesskey ? "netAccessKey" :
2520 "C-sign-key"));
2521 return -1;
2522 }
2523
2524 os_get_time(&now);
2525
2526 if (ssid->dpp_netaccesskey_expiry &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07002527 (os_time_t) ssid->dpp_netaccesskey_expiry < now.sec) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002528 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
2529 "netAccessKey expired");
2530 return -1;
2531 }
2532
2533 wpa_printf(MSG_DEBUG,
2534 "DPP: Starting network introduction protocol to derive PMKSA for "
2535 MACSTR, MAC2STR(bss->bssid));
2536
2537 msg = dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ,
2538 5 + 4 + os_strlen(ssid->dpp_connector));
2539 if (!msg)
2540 return -1;
2541
Roshan Pius3a1667e2018-07-03 15:17:14 -07002542#ifdef CONFIG_TESTING_OPTIONS
2543 if (dpp_test == DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ) {
2544 wpa_printf(MSG_INFO, "DPP: TESTING - no Transaction ID");
2545 goto skip_trans_id;
2546 }
2547 if (dpp_test == DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ) {
2548 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Transaction ID");
2549 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
2550 wpabuf_put_le16(msg, 0);
2551 goto skip_trans_id;
2552 }
2553#endif /* CONFIG_TESTING_OPTIONS */
2554
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002555 /* Transaction ID */
2556 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
2557 wpabuf_put_le16(msg, 1);
2558 wpabuf_put_u8(msg, TRANSACTION_ID);
2559
Roshan Pius3a1667e2018-07-03 15:17:14 -07002560#ifdef CONFIG_TESTING_OPTIONS
2561skip_trans_id:
2562 if (dpp_test == DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ) {
2563 wpa_printf(MSG_INFO, "DPP: TESTING - no Connector");
2564 goto skip_connector;
2565 }
2566 if (dpp_test == DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ) {
2567 char *connector;
2568
2569 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Connector");
2570 connector = dpp_corrupt_connector_signature(
2571 ssid->dpp_connector);
2572 if (!connector) {
2573 wpabuf_free(msg);
2574 return -1;
2575 }
2576 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
2577 wpabuf_put_le16(msg, os_strlen(connector));
2578 wpabuf_put_str(msg, connector);
2579 os_free(connector);
2580 goto skip_connector;
2581 }
2582#endif /* CONFIG_TESTING_OPTIONS */
2583
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002584 /* DPP Connector */
2585 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
2586 wpabuf_put_le16(msg, os_strlen(ssid->dpp_connector));
2587 wpabuf_put_str(msg, ssid->dpp_connector);
2588
Roshan Pius3a1667e2018-07-03 15:17:14 -07002589#ifdef CONFIG_TESTING_OPTIONS
2590skip_connector:
2591#endif /* CONFIG_TESTING_OPTIONS */
2592
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002593 /* TODO: Timeout on AP response */
2594 wait_time = wpa_s->max_remain_on_chan;
2595 if (wait_time > 2000)
2596 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002597 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2598 MAC2STR(bss->bssid), bss->freq, DPP_PA_PEER_DISCOVERY_REQ);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002599 offchannel_send_action(wpa_s, bss->freq, bss->bssid, wpa_s->own_addr,
2600 broadcast,
2601 wpabuf_head(msg), wpabuf_len(msg),
2602 wait_time, wpas_dpp_tx_introduction_status, 0);
2603 wpabuf_free(msg);
2604
2605 /* Request this connection attempt to terminate - new one will be
2606 * started when network introduction protocol completes */
2607 os_memcpy(wpa_s->dpp_intro_bssid, bss->bssid, ETH_ALEN);
2608 wpa_s->dpp_intro_network = ssid;
2609 return 1;
2610}
2611
2612
2613int wpas_dpp_pkex_add(struct wpa_supplicant *wpa_s, const char *cmd)
2614{
2615 struct dpp_bootstrap_info *own_bi;
2616 const char *pos, *end;
2617 unsigned int wait_time;
2618
2619 pos = os_strstr(cmd, " own=");
2620 if (!pos)
2621 return -1;
2622 pos += 5;
Hai Shalom021b0b52019-04-10 11:17:58 -07002623 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002624 if (!own_bi) {
2625 wpa_printf(MSG_DEBUG,
2626 "DPP: Identified bootstrap info not found");
2627 return -1;
2628 }
2629 if (own_bi->type != DPP_BOOTSTRAP_PKEX) {
2630 wpa_printf(MSG_DEBUG,
2631 "DPP: Identified bootstrap info not for PKEX");
2632 return -1;
2633 }
2634 wpa_s->dpp_pkex_bi = own_bi;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002635 own_bi->pkex_t = 0; /* clear pending errors on new code */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002636
2637 os_free(wpa_s->dpp_pkex_identifier);
2638 wpa_s->dpp_pkex_identifier = NULL;
2639 pos = os_strstr(cmd, " identifier=");
2640 if (pos) {
2641 pos += 12;
2642 end = os_strchr(pos, ' ');
2643 if (!end)
2644 return -1;
2645 wpa_s->dpp_pkex_identifier = os_malloc(end - pos + 1);
2646 if (!wpa_s->dpp_pkex_identifier)
2647 return -1;
2648 os_memcpy(wpa_s->dpp_pkex_identifier, pos, end - pos);
2649 wpa_s->dpp_pkex_identifier[end - pos] = '\0';
2650 }
2651
2652 pos = os_strstr(cmd, " code=");
2653 if (!pos)
2654 return -1;
2655 os_free(wpa_s->dpp_pkex_code);
2656 wpa_s->dpp_pkex_code = os_strdup(pos + 6);
2657 if (!wpa_s->dpp_pkex_code)
2658 return -1;
2659
2660 if (os_strstr(cmd, " init=1")) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002661 struct dpp_pkex *pkex;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002662 struct wpabuf *msg;
2663
2664 wpa_printf(MSG_DEBUG, "DPP: Initiating PKEX");
2665 dpp_pkex_free(wpa_s->dpp_pkex);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002666 wpa_s->dpp_pkex = dpp_pkex_init(wpa_s, own_bi, wpa_s->own_addr,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002667 wpa_s->dpp_pkex_identifier,
2668 wpa_s->dpp_pkex_code);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002669 pkex = wpa_s->dpp_pkex;
2670 if (!pkex)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002671 return -1;
2672
Roshan Pius3a1667e2018-07-03 15:17:14 -07002673 msg = pkex->exchange_req;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002674 wait_time = wpa_s->max_remain_on_chan;
2675 if (wait_time > 2000)
2676 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002677 pkex->freq = 2437;
2678 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
2679 " freq=%u type=%d",
2680 MAC2STR(broadcast), pkex->freq,
2681 DPP_PA_PKEX_EXCHANGE_REQ);
2682 offchannel_send_action(wpa_s, pkex->freq, broadcast,
2683 wpa_s->own_addr, broadcast,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002684 wpabuf_head(msg), wpabuf_len(msg),
2685 wait_time, wpas_dpp_tx_pkex_status, 0);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002686 if (wait_time == 0)
2687 wait_time = 2000;
2688 pkex->exch_req_wait_time = wait_time;
2689 pkex->exch_req_tries = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002690 }
2691
2692 /* TODO: Support multiple PKEX info entries */
2693
2694 os_free(wpa_s->dpp_pkex_auth_cmd);
2695 wpa_s->dpp_pkex_auth_cmd = os_strdup(cmd);
2696
2697 return 1;
2698}
2699
2700
2701int wpas_dpp_pkex_remove(struct wpa_supplicant *wpa_s, const char *id)
2702{
2703 unsigned int id_val;
2704
2705 if (os_strcmp(id, "*") == 0) {
2706 id_val = 0;
2707 } else {
2708 id_val = atoi(id);
2709 if (id_val == 0)
2710 return -1;
2711 }
2712
2713 if ((id_val != 0 && id_val != 1) || !wpa_s->dpp_pkex_code)
2714 return -1;
2715
2716 /* TODO: Support multiple PKEX entries */
2717 os_free(wpa_s->dpp_pkex_code);
2718 wpa_s->dpp_pkex_code = NULL;
2719 os_free(wpa_s->dpp_pkex_identifier);
2720 wpa_s->dpp_pkex_identifier = NULL;
2721 os_free(wpa_s->dpp_pkex_auth_cmd);
2722 wpa_s->dpp_pkex_auth_cmd = NULL;
2723 wpa_s->dpp_pkex_bi = NULL;
2724 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
2725 dpp_pkex_free(wpa_s->dpp_pkex);
2726 wpa_s->dpp_pkex = NULL;
2727 return 0;
2728}
2729
2730
Roshan Pius3a1667e2018-07-03 15:17:14 -07002731void wpas_dpp_stop(struct wpa_supplicant *wpa_s)
2732{
Hai Shalomfdcde762020-04-02 11:19:20 -07002733 if (wpa_s->dpp_auth || wpa_s->dpp_pkex)
2734 offchannel_send_action_done(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002735 dpp_auth_deinit(wpa_s->dpp_auth);
2736 wpa_s->dpp_auth = NULL;
2737 dpp_pkex_free(wpa_s->dpp_pkex);
2738 wpa_s->dpp_pkex = NULL;
2739 if (wpa_s->dpp_gas_client && wpa_s->dpp_gas_dialog_token >= 0)
2740 gas_query_stop(wpa_s->gas, wpa_s->dpp_gas_dialog_token);
2741}
2742
2743
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002744int wpas_dpp_init(struct wpa_supplicant *wpa_s)
2745{
Hai Shalom81f62d82019-07-22 12:10:00 -07002746 struct dpp_global_config config;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002747 u8 adv_proto_id[7];
2748
2749 adv_proto_id[0] = WLAN_EID_VENDOR_SPECIFIC;
2750 adv_proto_id[1] = 5;
2751 WPA_PUT_BE24(&adv_proto_id[2], OUI_WFA);
2752 adv_proto_id[5] = DPP_OUI_TYPE;
2753 adv_proto_id[6] = 0x01;
2754
2755 if (gas_server_register(wpa_s->gas_server, adv_proto_id,
2756 sizeof(adv_proto_id), wpas_dpp_gas_req_handler,
2757 wpas_dpp_gas_status_handler, wpa_s) < 0)
2758 return -1;
Hai Shalom81f62d82019-07-22 12:10:00 -07002759
2760 os_memset(&config, 0, sizeof(config));
2761 config.msg_ctx = wpa_s;
2762 config.cb_ctx = wpa_s;
2763#ifdef CONFIG_DPP2
2764 config.process_conf_obj = wpas_dpp_process_conf_obj;
Hai Shalomfdcde762020-04-02 11:19:20 -07002765 config.remove_bi = wpas_dpp_remove_bi;
Hai Shalom81f62d82019-07-22 12:10:00 -07002766#endif /* CONFIG_DPP2 */
2767 wpa_s->dpp = dpp_global_init(&config);
Hai Shalom021b0b52019-04-10 11:17:58 -07002768 return wpa_s->dpp ? 0 : -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002769}
2770
2771
2772void wpas_dpp_deinit(struct wpa_supplicant *wpa_s)
2773{
2774#ifdef CONFIG_TESTING_OPTIONS
2775 os_free(wpa_s->dpp_config_obj_override);
2776 wpa_s->dpp_config_obj_override = NULL;
2777 os_free(wpa_s->dpp_discovery_override);
2778 wpa_s->dpp_discovery_override = NULL;
2779 os_free(wpa_s->dpp_groups_override);
2780 wpa_s->dpp_groups_override = NULL;
2781 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
2782#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalom021b0b52019-04-10 11:17:58 -07002783 if (!wpa_s->dpp)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002784 return;
Hai Shalom021b0b52019-04-10 11:17:58 -07002785 dpp_global_clear(wpa_s->dpp);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002786 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002787 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002788 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
2789 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07002790#ifdef CONFIG_DPP2
2791 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL);
Hai Shalomc3565922019-10-28 11:58:20 -07002792 eloop_cancel_timeout(wpas_dpp_conn_status_result_wait_timeout,
2793 wpa_s, NULL);
2794 eloop_cancel_timeout(wpas_dpp_conn_status_result_timeout, wpa_s, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07002795 dpp_pfs_free(wpa_s->dpp_pfs);
2796 wpa_s->dpp_pfs = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07002797 wpas_dpp_chirp_stop(wpa_s);
Hai Shalom021b0b52019-04-10 11:17:58 -07002798#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002799 offchannel_send_action_done(wpa_s);
2800 wpas_dpp_listen_stop(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002801 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002802 wpas_dpp_pkex_remove(wpa_s, "*");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002803 os_memset(wpa_s->dpp_intro_bssid, 0, ETH_ALEN);
2804 os_free(wpa_s->dpp_configurator_params);
2805 wpa_s->dpp_configurator_params = NULL;
2806}
Hai Shalom81f62d82019-07-22 12:10:00 -07002807
2808
2809#ifdef CONFIG_DPP2
Hai Shalomfdcde762020-04-02 11:19:20 -07002810
Hai Shalom81f62d82019-07-22 12:10:00 -07002811int wpas_dpp_controller_start(struct wpa_supplicant *wpa_s, const char *cmd)
2812{
2813 struct dpp_controller_config config;
2814 const char *pos;
2815
2816 os_memset(&config, 0, sizeof(config));
2817 if (cmd) {
2818 pos = os_strstr(cmd, " tcp_port=");
2819 if (pos) {
2820 pos += 10;
2821 config.tcp_port = atoi(pos);
2822 }
2823 }
2824 config.configurator_params = wpa_s->dpp_configurator_params;
2825 return dpp_controller_start(wpa_s->dpp, &config);
2826}
Hai Shalomfdcde762020-04-02 11:19:20 -07002827
2828
2829static void wpas_dpp_chirp_next(void *eloop_ctx, void *timeout_ctx);
2830
2831static void wpas_dpp_chirp_timeout(void *eloop_ctx, void *timeout_ctx)
2832{
2833 struct wpa_supplicant *wpa_s = eloop_ctx;
2834
2835 wpa_printf(MSG_DEBUG, "DPP: No chirp response received");
2836 offchannel_send_action_done(wpa_s);
2837 wpas_dpp_chirp_next(wpa_s, NULL);
2838}
2839
2840
2841static void wpas_dpp_chirp_tx_status(struct wpa_supplicant *wpa_s,
2842 unsigned int freq, const u8 *dst,
2843 const u8 *src, const u8 *bssid,
2844 const u8 *data, size_t data_len,
2845 enum offchannel_send_action_result result)
2846{
2847 if (result == OFFCHANNEL_SEND_ACTION_FAILED) {
2848 wpa_printf(MSG_DEBUG, "DPP: Failed to send chirp on %d MHz",
2849 wpa_s->dpp_chirp_freq);
2850 if (eloop_register_timeout(0, 0, wpas_dpp_chirp_next,
2851 wpa_s, NULL) < 0)
2852 wpas_dpp_chirp_stop(wpa_s);
2853 return;
2854 }
2855
2856 wpa_printf(MSG_DEBUG, "DPP: Chirp send completed - wait for response");
2857 if (eloop_register_timeout(2, 0, wpas_dpp_chirp_timeout,
2858 wpa_s, NULL) < 0)
2859 wpas_dpp_chirp_stop(wpa_s);
2860}
2861
2862
2863static void wpas_dpp_chirp_start(struct wpa_supplicant *wpa_s)
2864{
2865 wpa_printf(MSG_DEBUG, "DPP: Chirp on %d MHz", wpa_s->dpp_chirp_freq);
2866 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2867 MAC2STR(broadcast), wpa_s->dpp_chirp_freq,
2868 DPP_PA_PRESENCE_ANNOUNCEMENT);
2869 if (offchannel_send_action(
2870 wpa_s, wpa_s->dpp_chirp_freq, broadcast,
2871 wpa_s->own_addr, broadcast,
2872 wpabuf_head(wpa_s->dpp_presence_announcement),
2873 wpabuf_len(wpa_s->dpp_presence_announcement),
2874 2000, wpas_dpp_chirp_tx_status, 0) < 0)
2875 wpas_dpp_chirp_stop(wpa_s);
2876}
2877
2878
2879static void wpas_dpp_chirp_scan_res_handler(struct wpa_supplicant *wpa_s,
2880 struct wpa_scan_results *scan_res)
2881{
2882 struct dpp_bootstrap_info *bi = wpa_s->dpp_chirp_bi;
2883 unsigned int i;
2884 struct hostapd_hw_modes *mode;
2885 int c;
2886 struct wpa_bss *bss;
2887
2888 if (!bi)
2889 return;
2890
2891 wpa_s->dpp_chirp_scan_done = 1;
2892
2893 os_free(wpa_s->dpp_chirp_freqs);
2894 wpa_s->dpp_chirp_freqs = NULL;
2895
2896 /* Channels from own bootstrapping info */
2897 for (i = 0; i < bi->num_freq; i++)
2898 int_array_add_unique(&wpa_s->dpp_chirp_freqs, bi->freq[i]);
2899
2900 /* Preferred chirping channels */
2901 int_array_add_unique(&wpa_s->dpp_chirp_freqs, 2437);
2902
2903 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes,
2904 HOSTAPD_MODE_IEEE80211A, 0);
2905 if (mode) {
2906 int chan44 = 0, chan149 = 0;
2907
2908 for (c = 0; c < mode->num_channels; c++) {
2909 struct hostapd_channel_data *chan = &mode->channels[c];
2910
2911 if (chan->flag & (HOSTAPD_CHAN_DISABLED |
2912 HOSTAPD_CHAN_RADAR))
2913 continue;
2914 if (chan->freq == 5220)
2915 chan44 = 1;
2916 if (chan->freq == 5745)
2917 chan149 = 1;
2918 }
2919 if (chan149)
2920 int_array_add_unique(&wpa_s->dpp_chirp_freqs, 5745);
2921 else if (chan44)
2922 int_array_add_unique(&wpa_s->dpp_chirp_freqs, 5220);
2923 }
2924
2925 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes,
2926 HOSTAPD_MODE_IEEE80211AD, 0);
2927 if (mode) {
2928 for (c = 0; c < mode->num_channels; c++) {
2929 struct hostapd_channel_data *chan = &mode->channels[c];
2930
2931 if ((chan->flag & (HOSTAPD_CHAN_DISABLED |
2932 HOSTAPD_CHAN_RADAR)) ||
2933 chan->freq != 60480)
2934 continue;
2935 int_array_add_unique(&wpa_s->dpp_chirp_freqs, 60480);
2936 break;
2937 }
2938 }
2939
2940 /* Add channels from scan results for APs that advertise Configurator
2941 * Connectivity element */
2942 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
2943 if (wpa_bss_get_vendor_ie(bss, DPP_CC_IE_VENDOR_TYPE))
2944 int_array_add_unique(&wpa_s->dpp_chirp_freqs,
2945 bss->freq);
2946 }
2947
2948 if (!wpa_s->dpp_chirp_freqs ||
2949 eloop_register_timeout(0, 0, wpas_dpp_chirp_next, wpa_s, NULL) < 0)
2950 wpas_dpp_chirp_stop(wpa_s);
2951}
2952
2953
2954static void wpas_dpp_chirp_next(void *eloop_ctx, void *timeout_ctx)
2955{
2956 struct wpa_supplicant *wpa_s = eloop_ctx;
2957 int i;
2958
2959 if (wpa_s->dpp_chirp_listen)
2960 wpas_dpp_listen_stop(wpa_s);
2961
2962 if (wpa_s->dpp_chirp_freq == 0) {
2963 if (wpa_s->dpp_chirp_round % 4 == 0 &&
2964 !wpa_s->dpp_chirp_scan_done) {
2965 wpa_printf(MSG_DEBUG,
2966 "DPP: Update channel list for chirping");
2967 wpa_s->scan_req = MANUAL_SCAN_REQ;
2968 wpa_s->scan_res_handler =
2969 wpas_dpp_chirp_scan_res_handler;
2970 wpa_supplicant_req_scan(wpa_s, 0, 0);
2971 return;
2972 }
2973 wpa_s->dpp_chirp_freq = wpa_s->dpp_chirp_freqs[0];
2974 wpa_s->dpp_chirp_round++;
2975 wpa_printf(MSG_DEBUG, "DPP: Start chirping round %d",
2976 wpa_s->dpp_chirp_round);
2977 } else {
2978 for (i = 0; wpa_s->dpp_chirp_freqs[i]; i++)
2979 if (wpa_s->dpp_chirp_freqs[i] == wpa_s->dpp_chirp_freq)
2980 break;
2981 if (!wpa_s->dpp_chirp_freqs[i]) {
2982 wpa_printf(MSG_DEBUG,
2983 "DPP: Previous chirp freq %d not found",
2984 wpa_s->dpp_chirp_freq);
2985 return;
2986 }
2987 i++;
2988 if (wpa_s->dpp_chirp_freqs[i]) {
2989 wpa_s->dpp_chirp_freq = wpa_s->dpp_chirp_freqs[i];
2990 } else {
2991 wpa_s->dpp_chirp_iter--;
2992 if (wpa_s->dpp_chirp_iter <= 0) {
2993 wpa_printf(MSG_DEBUG,
2994 "DPP: Chirping iterations completed");
2995 wpas_dpp_chirp_stop(wpa_s);
2996 return;
2997 }
2998 wpa_s->dpp_chirp_freq = 0;
2999 wpa_s->dpp_chirp_scan_done = 0;
3000 if (eloop_register_timeout(30, 0, wpas_dpp_chirp_next,
3001 wpa_s, NULL) < 0) {
3002 wpas_dpp_chirp_stop(wpa_s);
3003 return;
3004 }
3005 if (wpa_s->dpp_chirp_listen) {
3006 wpa_printf(MSG_DEBUG,
3007 "DPP: Listen on %d MHz during chirp 30 second wait",
3008 wpa_s->dpp_chirp_listen);
3009 wpas_dpp_listen_start(wpa_s,
3010 wpa_s->dpp_chirp_listen);
3011 } else {
3012 wpa_printf(MSG_DEBUG,
3013 "DPP: Wait 30 seconds before starting the next chirping round");
3014 }
3015 return;
3016 }
3017 }
3018
3019 wpas_dpp_chirp_start(wpa_s);
3020}
3021
3022
3023int wpas_dpp_chirp(struct wpa_supplicant *wpa_s, const char *cmd)
3024{
3025 const char *pos;
3026 int iter = 1, listen_freq = 0;
3027 struct dpp_bootstrap_info *bi;
3028
3029 pos = os_strstr(cmd, " own=");
3030 if (!pos)
3031 return -1;
3032 pos += 5;
3033 bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
3034 if (!bi) {
3035 wpa_printf(MSG_DEBUG,
3036 "DPP: Identified bootstrap info not found");
3037 return -1;
3038 }
3039
3040 pos = os_strstr(cmd, " iter=");
3041 if (pos) {
3042 iter = atoi(pos + 6);
3043 if (iter <= 0)
3044 return -1;
3045 }
3046
3047 pos = os_strstr(cmd, " listen=");
3048 if (pos) {
3049 listen_freq = atoi(pos + 8);
3050 if (iter <= 0)
3051 return -1;
3052 }
3053
3054 wpas_dpp_chirp_stop(wpa_s);
3055 wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
3056 wpa_s->dpp_qr_mutual = 0;
3057 wpa_s->dpp_chirp_bi = bi;
3058 wpa_s->dpp_presence_announcement = dpp_build_presence_announcement(bi);
3059 if (!wpa_s->dpp_presence_announcement)
3060 return -1;
3061 wpa_s->dpp_chirp_iter = iter;
3062 wpa_s->dpp_chirp_round = 0;
3063 wpa_s->dpp_chirp_scan_done = 0;
3064 wpa_s->dpp_chirp_listen = listen_freq;
3065
3066 return eloop_register_timeout(0, 0, wpas_dpp_chirp_next, wpa_s, NULL);
3067}
3068
3069
3070void wpas_dpp_chirp_stop(struct wpa_supplicant *wpa_s)
3071{
3072 if (wpa_s->dpp_presence_announcement) {
3073 offchannel_send_action_done(wpa_s);
3074 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CHIRP_STOPPED);
3075 }
3076 wpa_s->dpp_chirp_bi = NULL;
3077 wpabuf_free(wpa_s->dpp_presence_announcement);
3078 wpa_s->dpp_presence_announcement = NULL;
3079 if (wpa_s->dpp_chirp_listen)
3080 wpas_dpp_listen_stop(wpa_s);
3081 wpa_s->dpp_chirp_listen = 0;
3082 wpa_s->dpp_chirp_freq = 0;
3083 os_free(wpa_s->dpp_chirp_freqs);
3084 wpa_s->dpp_chirp_freqs = NULL;
3085 eloop_cancel_timeout(wpas_dpp_chirp_next, wpa_s, NULL);
3086 eloop_cancel_timeout(wpas_dpp_chirp_timeout, wpa_s, NULL);
3087 if (wpa_s->scan_res_handler == wpas_dpp_chirp_scan_res_handler) {
3088 wpas_abort_ongoing_scan(wpa_s);
3089 wpa_s->scan_res_handler = NULL;
3090 }
3091}
3092
Hai Shalom81f62d82019-07-22 12:10:00 -07003093#endif /* CONFIG_DPP2 */