blob: 8a9e444cc43d97cf4ce9adf680ea1bbb1f3bfd84 [file] [log] [blame]
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001/*
2 * wpa_supplicant - DPP
3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
Hai Shalom021b0b52019-04-10 11:17:58 -07004 * Copyright (c) 2018-2019, 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"
14#include "common/dpp.h"
15#include "common/gas.h"
16#include "common/gas_server.h"
17#include "rsn_supp/wpa.h"
18#include "rsn_supp/pmksa_cache.h"
19#include "wpa_supplicant_i.h"
20#include "config.h"
21#include "driver_i.h"
22#include "offchannel.h"
23#include "gas_query.h"
24#include "bss.h"
25#include "scan.h"
26#include "notify.h"
27#include "dpp_supplicant.h"
Hai Shalom59532852018-12-07 10:32:58 -080028#include "hidl.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070029
30
31static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
32 unsigned int freq);
33static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx);
34static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator);
35static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
36 unsigned int freq, const u8 *dst,
37 const u8 *src, const u8 *bssid,
38 const u8 *data, size_t data_len,
39 enum offchannel_send_action_result result);
Roshan Pius3a1667e2018-07-03 15:17:14 -070040static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx);
41static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s);
42static void
43wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s,
44 unsigned int freq, const u8 *dst,
45 const u8 *src, const u8 *bssid,
46 const u8 *data, size_t data_len,
47 enum offchannel_send_action_result result);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070048
49static const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
50
51/* Use a hardcoded Transaction ID 1 in Peer Discovery frames since there is only
52 * a single transaction in progress at any point in time. */
53static const u8 TRANSACTION_ID = 1;
54
55
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070056/**
57 * wpas_dpp_qr_code - Parse and add DPP bootstrapping info from a QR Code
58 * @wpa_s: Pointer to wpa_supplicant data
59 * @cmd: DPP URI read from a QR Code
60 * Returns: Identifier of the stored info or -1 on failure
61 */
62int wpas_dpp_qr_code(struct wpa_supplicant *wpa_s, const char *cmd)
63{
64 struct dpp_bootstrap_info *bi;
65 struct dpp_authentication *auth = wpa_s->dpp_auth;
66
Hai Shalom021b0b52019-04-10 11:17:58 -070067 bi = dpp_add_qr_code(wpa_s->dpp, cmd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070068 if (!bi)
69 return -1;
70
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070071 if (auth && auth->response_pending &&
72 dpp_notify_new_qr_code(auth, bi) == 1) {
73 wpa_printf(MSG_DEBUG,
74 "DPP: Sending out pending authentication response");
Roshan Pius3a1667e2018-07-03 15:17:14 -070075 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
76 " freq=%u type=%d",
77 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
78 DPP_PA_AUTHENTICATION_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070079 offchannel_send_action(wpa_s, auth->curr_freq,
80 auth->peer_mac_addr, wpa_s->own_addr,
81 broadcast,
82 wpabuf_head(auth->resp_msg),
83 wpabuf_len(auth->resp_msg),
84 500, wpas_dpp_tx_status, 0);
85 }
86
87 return bi->id;
88}
89
90
Roshan Pius3a1667e2018-07-03 15:17:14 -070091static void wpas_dpp_auth_resp_retry_timeout(void *eloop_ctx, void *timeout_ctx)
92{
93 struct wpa_supplicant *wpa_s = eloop_ctx;
94 struct dpp_authentication *auth = wpa_s->dpp_auth;
95
96 if (!auth || !auth->resp_msg)
97 return;
98
99 wpa_printf(MSG_DEBUG,
100 "DPP: Retry Authentication Response after timeout");
101 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
102 " freq=%u type=%d",
103 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
104 DPP_PA_AUTHENTICATION_RESP);
105 offchannel_send_action(wpa_s, auth->curr_freq, auth->peer_mac_addr,
106 wpa_s->own_addr, broadcast,
107 wpabuf_head(auth->resp_msg),
108 wpabuf_len(auth->resp_msg),
109 500, wpas_dpp_tx_status, 0);
110}
111
112
113static void wpas_dpp_auth_resp_retry(struct wpa_supplicant *wpa_s)
114{
115 struct dpp_authentication *auth = wpa_s->dpp_auth;
116 unsigned int wait_time, max_tries;
117
118 if (!auth || !auth->resp_msg)
119 return;
120
121 if (wpa_s->dpp_resp_max_tries)
122 max_tries = wpa_s->dpp_resp_max_tries;
123 else
124 max_tries = 5;
125 auth->auth_resp_tries++;
126 if (auth->auth_resp_tries >= max_tries) {
127 wpa_printf(MSG_INFO, "DPP: No confirm received from initiator - stopping exchange");
128 offchannel_send_action_done(wpa_s);
129 dpp_auth_deinit(wpa_s->dpp_auth);
130 wpa_s->dpp_auth = NULL;
131 return;
132 }
133
134 if (wpa_s->dpp_resp_retry_time)
135 wait_time = wpa_s->dpp_resp_retry_time;
136 else
137 wait_time = 1000;
138 wpa_printf(MSG_DEBUG,
139 "DPP: Schedule retransmission of Authentication Response frame in %u ms",
140 wait_time);
141 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
142 eloop_register_timeout(wait_time / 1000,
143 (wait_time % 1000) * 1000,
144 wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
145}
146
147
Hai Shalom021b0b52019-04-10 11:17:58 -0700148static void wpas_dpp_try_to_connect(struct wpa_supplicant *wpa_s)
149{
150 wpa_printf(MSG_DEBUG, "DPP: Trying to connect to the new network");
151 wpa_s->disconnected = 0;
152 wpa_s->reassociate = 1;
153 wpa_s->scan_runs = 0;
154 wpa_s->normal_scans = 0;
155 wpa_supplicant_cancel_sched_scan(wpa_s);
156 wpa_supplicant_req_scan(wpa_s, 0, 0);
157}
158
159
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700160static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
161 unsigned int freq, const u8 *dst,
162 const u8 *src, const u8 *bssid,
163 const u8 *data, size_t data_len,
164 enum offchannel_send_action_result result)
165{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700166 const char *res_txt;
167 struct dpp_authentication *auth = wpa_s->dpp_auth;
168
169 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
170 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
171 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700172 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
Roshan Pius3a1667e2018-07-03 15:17:14 -0700173 " result=%s", freq, MAC2STR(dst), res_txt);
174 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
175 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700176
177 if (!wpa_s->dpp_auth) {
178 wpa_printf(MSG_DEBUG,
179 "DPP: Ignore TX status since there is no ongoing authentication exchange");
180 return;
181 }
182
Hai Shalom021b0b52019-04-10 11:17:58 -0700183#ifdef CONFIG_DPP2
184 if (auth->connect_on_tx_status) {
185 wpa_printf(MSG_DEBUG,
186 "DPP: Try to connect after completed configuration result");
187 wpas_dpp_try_to_connect(wpa_s);
188 dpp_auth_deinit(wpa_s->dpp_auth);
189 wpa_s->dpp_auth = NULL;
190 return;
191 }
192#endif /* CONFIG_DPP2 */
193
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700194 if (wpa_s->dpp_auth->remove_on_tx_status) {
195 wpa_printf(MSG_DEBUG,
196 "DPP: Terminate authentication exchange due to an earlier error");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700197 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700198 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700199 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
200 NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700201 offchannel_send_action_done(wpa_s);
202 dpp_auth_deinit(wpa_s->dpp_auth);
203 wpa_s->dpp_auth = NULL;
204 return;
205 }
206
207 if (wpa_s->dpp_auth_ok_on_ack)
208 wpas_dpp_auth_success(wpa_s, 1);
209
210 if (!is_broadcast_ether_addr(dst) &&
211 result != OFFCHANNEL_SEND_ACTION_SUCCESS) {
212 wpa_printf(MSG_DEBUG,
213 "DPP: Unicast DPP Action frame was not ACKed");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700214 if (auth->waiting_auth_resp) {
215 /* In case of DPP Authentication Request frame, move to
216 * the next channel immediately. */
217 offchannel_send_action_done(wpa_s);
218 wpas_dpp_auth_init_next(wpa_s);
219 return;
220 }
221 if (auth->waiting_auth_conf) {
222 wpas_dpp_auth_resp_retry(wpa_s);
223 return;
224 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700225 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700226
227 if (!is_broadcast_ether_addr(dst) && auth->waiting_auth_resp &&
228 result == OFFCHANNEL_SEND_ACTION_SUCCESS) {
229 /* Allow timeout handling to stop iteration if no response is
230 * received from a peer that has ACKed a request. */
231 auth->auth_req_ack = 1;
232 }
233
234 if (!wpa_s->dpp_auth_ok_on_ack && wpa_s->dpp_auth->neg_freq > 0 &&
235 wpa_s->dpp_auth->curr_freq != wpa_s->dpp_auth->neg_freq) {
236 wpa_printf(MSG_DEBUG,
237 "DPP: Move from curr_freq %u MHz to neg_freq %u MHz for response",
238 wpa_s->dpp_auth->curr_freq,
239 wpa_s->dpp_auth->neg_freq);
240 offchannel_send_action_done(wpa_s);
241 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->neg_freq);
242 }
243
244 if (wpa_s->dpp_auth_ok_on_ack)
245 wpa_s->dpp_auth_ok_on_ack = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700246}
247
248
249static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx)
250{
251 struct wpa_supplicant *wpa_s = eloop_ctx;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700252 struct dpp_authentication *auth = wpa_s->dpp_auth;
253 unsigned int freq;
254 struct os_reltime now, diff;
255 unsigned int wait_time, diff_ms;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700256
Roshan Pius3a1667e2018-07-03 15:17:14 -0700257 if (!auth || !auth->waiting_auth_resp)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700258 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700259
260 wait_time = wpa_s->dpp_resp_wait_time ?
261 wpa_s->dpp_resp_wait_time : 2000;
262 os_get_reltime(&now);
263 os_reltime_sub(&now, &wpa_s->dpp_last_init, &diff);
264 diff_ms = diff.sec * 1000 + diff.usec / 1000;
265 wpa_printf(MSG_DEBUG,
266 "DPP: Reply wait timeout - wait_time=%u diff_ms=%u",
267 wait_time, diff_ms);
268
269 if (auth->auth_req_ack && diff_ms >= wait_time) {
270 /* Peer ACK'ed Authentication Request frame, but did not reply
271 * with Authentication Response frame within two seconds. */
272 wpa_printf(MSG_INFO,
273 "DPP: No response received from responder - stopping initiation attempt");
274 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -0800275 wpas_notify_dpp_timeout(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700276 offchannel_send_action_done(wpa_s);
277 wpas_dpp_listen_stop(wpa_s);
278 dpp_auth_deinit(auth);
279 wpa_s->dpp_auth = NULL;
280 return;
281 }
282
283 if (diff_ms >= wait_time) {
284 /* Authentication Request frame was not ACK'ed and no reply
285 * was receiving within two seconds. */
286 wpa_printf(MSG_DEBUG,
287 "DPP: Continue Initiator channel iteration");
288 offchannel_send_action_done(wpa_s);
289 wpas_dpp_listen_stop(wpa_s);
290 wpas_dpp_auth_init_next(wpa_s);
291 return;
292 }
293
294 /* Driver did not support 2000 ms long wait_time with TX command, so
295 * schedule listen operation to continue waiting for the response.
296 *
297 * DPP listen operations continue until stopped, so simply schedule a
298 * new call to this function at the point when the two second reply
299 * wait has expired. */
300 wait_time -= diff_ms;
301
302 freq = auth->curr_freq;
303 if (auth->neg_freq > 0)
304 freq = auth->neg_freq;
305 wpa_printf(MSG_DEBUG,
306 "DPP: Continue reply wait on channel %u MHz for %u ms",
307 freq, wait_time);
308 wpa_s->dpp_in_response_listen = 1;
309 wpas_dpp_listen_start(wpa_s, freq);
310
311 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
312 wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700313}
314
315
316static void wpas_dpp_set_testing_options(struct wpa_supplicant *wpa_s,
317 struct dpp_authentication *auth)
318{
319#ifdef CONFIG_TESTING_OPTIONS
320 if (wpa_s->dpp_config_obj_override)
321 auth->config_obj_override =
322 os_strdup(wpa_s->dpp_config_obj_override);
323 if (wpa_s->dpp_discovery_override)
324 auth->discovery_override =
325 os_strdup(wpa_s->dpp_discovery_override);
326 if (wpa_s->dpp_groups_override)
327 auth->groups_override =
328 os_strdup(wpa_s->dpp_groups_override);
329 auth->ignore_netaccesskey_mismatch =
330 wpa_s->dpp_ignore_netaccesskey_mismatch;
331#endif /* CONFIG_TESTING_OPTIONS */
332}
333
334
Roshan Pius3a1667e2018-07-03 15:17:14 -0700335static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx)
336{
337 struct wpa_supplicant *wpa_s = eloop_ctx;
338
339 if (!wpa_s->dpp_auth)
340 return;
341 wpa_printf(MSG_DEBUG, "DPP: Retry initiation after timeout");
342 wpas_dpp_auth_init_next(wpa_s);
343}
344
345
346static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s)
347{
348 struct dpp_authentication *auth = wpa_s->dpp_auth;
349 const u8 *dst;
350 unsigned int wait_time, max_wait_time, freq, max_tries, used;
351 struct os_reltime now, diff;
352
353 wpa_s->dpp_in_response_listen = 0;
354 if (!auth)
355 return -1;
356
357 if (auth->freq_idx == 0)
358 os_get_reltime(&wpa_s->dpp_init_iter_start);
359
360 if (auth->freq_idx >= auth->num_freq) {
361 auth->num_freq_iters++;
362 if (wpa_s->dpp_init_max_tries)
363 max_tries = wpa_s->dpp_init_max_tries;
364 else
365 max_tries = 5;
366 if (auth->num_freq_iters >= max_tries || auth->auth_req_ack) {
367 wpa_printf(MSG_INFO,
368 "DPP: No response received from responder - stopping initiation attempt");
369 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -0800370 wpas_notify_dpp_timeout(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700371 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout,
372 wpa_s, NULL);
373 offchannel_send_action_done(wpa_s);
374 dpp_auth_deinit(wpa_s->dpp_auth);
375 wpa_s->dpp_auth = NULL;
376 return -1;
377 }
378 auth->freq_idx = 0;
379 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
380 if (wpa_s->dpp_init_retry_time)
381 wait_time = wpa_s->dpp_init_retry_time;
382 else
383 wait_time = 10000;
384 os_get_reltime(&now);
385 os_reltime_sub(&now, &wpa_s->dpp_init_iter_start, &diff);
386 used = diff.sec * 1000 + diff.usec / 1000;
387 if (used > wait_time)
388 wait_time = 0;
389 else
390 wait_time -= used;
391 wpa_printf(MSG_DEBUG, "DPP: Next init attempt in %u ms",
392 wait_time);
393 eloop_register_timeout(wait_time / 1000,
394 (wait_time % 1000) * 1000,
395 wpas_dpp_init_timeout, wpa_s,
396 NULL);
397 return 0;
398 }
399 freq = auth->freq[auth->freq_idx++];
400 auth->curr_freq = freq;
401
402 if (is_zero_ether_addr(auth->peer_bi->mac_addr))
403 dst = broadcast;
404 else
405 dst = auth->peer_bi->mac_addr;
406 wpa_s->dpp_auth_ok_on_ack = 0;
407 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
408 wait_time = wpa_s->max_remain_on_chan;
409 max_wait_time = wpa_s->dpp_resp_wait_time ?
410 wpa_s->dpp_resp_wait_time : 2000;
411 if (wait_time > max_wait_time)
412 wait_time = max_wait_time;
413 wait_time += 10; /* give the driver some extra time to complete */
414 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
415 wpas_dpp_reply_wait_timeout,
416 wpa_s, NULL);
417 wait_time -= 10;
418 if (auth->neg_freq > 0 && freq != auth->neg_freq) {
419 wpa_printf(MSG_DEBUG,
420 "DPP: Initiate on %u MHz and move to neg_freq %u MHz for response",
421 freq, auth->neg_freq);
422 }
423 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
424 MAC2STR(dst), freq, DPP_PA_AUTHENTICATION_REQ);
425 auth->auth_req_ack = 0;
426 os_get_reltime(&wpa_s->dpp_last_init);
427 return offchannel_send_action(wpa_s, freq, dst,
428 wpa_s->own_addr, broadcast,
429 wpabuf_head(auth->req_msg),
430 wpabuf_len(auth->req_msg),
431 wait_time, wpas_dpp_tx_status, 0);
432}
433
434
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700435int wpas_dpp_auth_init(struct wpa_supplicant *wpa_s, const char *cmd)
436{
437 const char *pos;
438 struct dpp_bootstrap_info *peer_bi, *own_bi = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700439 u8 allowed_roles = DPP_CAPAB_CONFIGURATOR;
440 unsigned int neg_freq = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700441
442 wpa_s->dpp_gas_client = 0;
443
444 pos = os_strstr(cmd, " peer=");
445 if (!pos)
446 return -1;
447 pos += 6;
Hai Shalom021b0b52019-04-10 11:17:58 -0700448 peer_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700449 if (!peer_bi) {
450 wpa_printf(MSG_INFO,
451 "DPP: Could not find bootstrapping info for the identified peer");
452 return -1;
453 }
454
455 pos = os_strstr(cmd, " own=");
456 if (pos) {
457 pos += 5;
Hai Shalom021b0b52019-04-10 11:17:58 -0700458 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700459 if (!own_bi) {
460 wpa_printf(MSG_INFO,
461 "DPP: Could not find bootstrapping info for the identified local entry");
462 return -1;
463 }
464
465 if (peer_bi->curve != own_bi->curve) {
466 wpa_printf(MSG_INFO,
467 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
468 peer_bi->curve->name, own_bi->curve->name);
469 return -1;
470 }
471 }
472
473 pos = os_strstr(cmd, " role=");
474 if (pos) {
475 pos += 6;
476 if (os_strncmp(pos, "configurator", 12) == 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700477 allowed_roles = DPP_CAPAB_CONFIGURATOR;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700478 else if (os_strncmp(pos, "enrollee", 8) == 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700479 allowed_roles = DPP_CAPAB_ENROLLEE;
480 else if (os_strncmp(pos, "either", 6) == 0)
481 allowed_roles = DPP_CAPAB_CONFIGURATOR |
482 DPP_CAPAB_ENROLLEE;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700483 else
484 goto fail;
485 }
486
487 pos = os_strstr(cmd, " netrole=");
488 if (pos) {
489 pos += 9;
490 wpa_s->dpp_netrole_ap = os_strncmp(pos, "ap", 2) == 0;
491 }
492
Roshan Pius3a1667e2018-07-03 15:17:14 -0700493 pos = os_strstr(cmd, " neg_freq=");
494 if (pos)
495 neg_freq = atoi(pos + 10);
496
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700497 if (wpa_s->dpp_auth) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700498 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700499 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700500 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
501 NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700502 offchannel_send_action_done(wpa_s);
503 dpp_auth_deinit(wpa_s->dpp_auth);
504 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700505 wpa_s->dpp_auth = dpp_auth_init(wpa_s, peer_bi, own_bi, allowed_roles,
506 neg_freq,
507 wpa_s->hw.modes, wpa_s->hw.num_modes);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700508 if (!wpa_s->dpp_auth)
509 goto fail;
510 wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
Hai Shalom021b0b52019-04-10 11:17:58 -0700511 if (dpp_set_configurator(wpa_s->dpp, wpa_s, wpa_s->dpp_auth, cmd) < 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -0800512 dpp_auth_deinit(wpa_s->dpp_auth);
513 wpa_s->dpp_auth = NULL;
514 goto fail;
515 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700516
Roshan Pius3a1667e2018-07-03 15:17:14 -0700517 wpa_s->dpp_auth->neg_freq = neg_freq;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700518
Roshan Pius3a1667e2018-07-03 15:17:14 -0700519 if (!is_zero_ether_addr(peer_bi->mac_addr))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700520 os_memcpy(wpa_s->dpp_auth->peer_mac_addr, peer_bi->mac_addr,
521 ETH_ALEN);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700522
Roshan Pius3a1667e2018-07-03 15:17:14 -0700523 return wpas_dpp_auth_init_next(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700524fail:
525 return -1;
526}
527
528
529struct wpas_dpp_listen_work {
530 unsigned int freq;
531 unsigned int duration;
532 struct wpabuf *probe_resp_ie;
533};
534
535
536static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work *lwork)
537{
538 if (!lwork)
539 return;
540 os_free(lwork);
541}
542
543
544static void wpas_dpp_listen_work_done(struct wpa_supplicant *wpa_s)
545{
546 struct wpas_dpp_listen_work *lwork;
547
548 if (!wpa_s->dpp_listen_work)
549 return;
550
551 lwork = wpa_s->dpp_listen_work->ctx;
552 wpas_dpp_listen_work_free(lwork);
553 radio_work_done(wpa_s->dpp_listen_work);
554 wpa_s->dpp_listen_work = NULL;
555}
556
557
558static void dpp_start_listen_cb(struct wpa_radio_work *work, int deinit)
559{
560 struct wpa_supplicant *wpa_s = work->wpa_s;
561 struct wpas_dpp_listen_work *lwork = work->ctx;
562
563 if (deinit) {
564 if (work->started) {
565 wpa_s->dpp_listen_work = NULL;
566 wpas_dpp_listen_stop(wpa_s);
567 }
568 wpas_dpp_listen_work_free(lwork);
569 return;
570 }
571
572 wpa_s->dpp_listen_work = work;
573
574 wpa_s->dpp_pending_listen_freq = lwork->freq;
575
576 if (wpa_drv_remain_on_channel(wpa_s, lwork->freq,
577 wpa_s->max_remain_on_chan) < 0) {
578 wpa_printf(MSG_DEBUG,
579 "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
580 lwork->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -0800581 wpa_s->dpp_listen_freq = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700582 wpas_dpp_listen_work_done(wpa_s);
583 wpa_s->dpp_pending_listen_freq = 0;
584 return;
585 }
586 wpa_s->off_channel_freq = 0;
587 wpa_s->roc_waiting_drv_freq = lwork->freq;
588}
589
590
591static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
592 unsigned int freq)
593{
594 struct wpas_dpp_listen_work *lwork;
595
596 if (wpa_s->dpp_listen_work) {
597 wpa_printf(MSG_DEBUG,
598 "DPP: Reject start_listen since dpp_listen_work already exists");
599 return -1;
600 }
601
602 if (wpa_s->dpp_listen_freq)
603 wpas_dpp_listen_stop(wpa_s);
604 wpa_s->dpp_listen_freq = freq;
605
606 lwork = os_zalloc(sizeof(*lwork));
607 if (!lwork)
608 return -1;
609 lwork->freq = freq;
610
611 if (radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb,
612 lwork) < 0) {
613 wpas_dpp_listen_work_free(lwork);
614 return -1;
615 }
616
617 return 0;
618}
619
620
621int wpas_dpp_listen(struct wpa_supplicant *wpa_s, const char *cmd)
622{
623 int freq;
624
625 freq = atoi(cmd);
626 if (freq <= 0)
627 return -1;
628
629 if (os_strstr(cmd, " role=configurator"))
630 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR;
631 else if (os_strstr(cmd, " role=enrollee"))
632 wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
633 else
634 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
635 DPP_CAPAB_ENROLLEE;
636 wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
637 wpa_s->dpp_netrole_ap = os_strstr(cmd, " netrole=ap") != NULL;
638 if (wpa_s->dpp_listen_freq == (unsigned int) freq) {
639 wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz",
640 freq);
641 return 0;
642 }
643
644 return wpas_dpp_listen_start(wpa_s, freq);
645}
646
647
648void wpas_dpp_listen_stop(struct wpa_supplicant *wpa_s)
649{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700650 wpa_s->dpp_in_response_listen = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700651 if (!wpa_s->dpp_listen_freq)
652 return;
653
654 wpa_printf(MSG_DEBUG, "DPP: Stop listen on %u MHz",
655 wpa_s->dpp_listen_freq);
656 wpa_drv_cancel_remain_on_channel(wpa_s);
657 wpa_s->dpp_listen_freq = 0;
658 wpas_dpp_listen_work_done(wpa_s);
659}
660
661
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700662void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
663 unsigned int freq)
664{
665 wpas_dpp_listen_work_done(wpa_s);
666
Roshan Pius3a1667e2018-07-03 15:17:14 -0700667 if (wpa_s->dpp_auth && wpa_s->dpp_in_response_listen) {
668 unsigned int new_freq;
669
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700670 /* Continue listen with a new remain-on-channel */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700671 if (wpa_s->dpp_auth->neg_freq > 0)
672 new_freq = wpa_s->dpp_auth->neg_freq;
673 else
674 new_freq = wpa_s->dpp_auth->curr_freq;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700675 wpa_printf(MSG_DEBUG,
676 "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
Roshan Pius3a1667e2018-07-03 15:17:14 -0700677 new_freq);
678 wpas_dpp_listen_start(wpa_s, new_freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700679 return;
680 }
681
682 if (wpa_s->dpp_listen_freq) {
683 /* Continue listen with a new remain-on-channel */
684 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_listen_freq);
685 }
686}
687
688
689static void wpas_dpp_rx_auth_req(struct wpa_supplicant *wpa_s, const u8 *src,
690 const u8 *hdr, const u8 *buf, size_t len,
691 unsigned int freq)
692{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700693 const u8 *r_bootstrap, *i_bootstrap;
694 u16 r_bootstrap_len, i_bootstrap_len;
Hai Shalom021b0b52019-04-10 11:17:58 -0700695 struct dpp_bootstrap_info *own_bi = NULL, *peer_bi = NULL;
696
697 if (!wpa_s->dpp)
698 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700699
700 wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR,
701 MAC2STR(src));
702
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700703 r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
704 &r_bootstrap_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700705 if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
706 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
707 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700708 return;
709 }
710 wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
711 r_bootstrap, r_bootstrap_len);
712
713 i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH,
714 &i_bootstrap_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700715 if (!i_bootstrap || i_bootstrap_len != SHA256_MAC_LEN) {
716 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
717 "Missing or invalid required Initiator Bootstrapping Key Hash attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700718 return;
719 }
720 wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash",
721 i_bootstrap, i_bootstrap_len);
722
723 /* Try to find own and peer bootstrapping key matches based on the
724 * received hash values */
Hai Shalom021b0b52019-04-10 11:17:58 -0700725 dpp_bootstrap_find_pair(wpa_s->dpp, i_bootstrap, r_bootstrap,
726 &own_bi, &peer_bi);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700727 if (!own_bi) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700728 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
729 "No matching own bootstrapping key found - ignore message");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700730 return;
731 }
732
733 if (wpa_s->dpp_auth) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700734 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
735 "Already in DPP authentication exchange - ignore new one");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700736 return;
737 }
738
739 wpa_s->dpp_gas_client = 0;
740 wpa_s->dpp_auth_ok_on_ack = 0;
741 wpa_s->dpp_auth = dpp_auth_req_rx(wpa_s, wpa_s->dpp_allowed_roles,
742 wpa_s->dpp_qr_mutual,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700743 peer_bi, own_bi, freq, hdr, buf, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700744 if (!wpa_s->dpp_auth) {
745 wpa_printf(MSG_DEBUG, "DPP: No response generated");
746 return;
747 }
748 wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
Hai Shalom021b0b52019-04-10 11:17:58 -0700749 if (dpp_set_configurator(wpa_s->dpp, wpa_s, wpa_s->dpp_auth,
750 wpa_s->dpp_configurator_params) < 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -0800751 dpp_auth_deinit(wpa_s->dpp_auth);
752 wpa_s->dpp_auth = NULL;
753 return;
754 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700755 os_memcpy(wpa_s->dpp_auth->peer_mac_addr, src, ETH_ALEN);
756
Roshan Pius3a1667e2018-07-03 15:17:14 -0700757 if (wpa_s->dpp_listen_freq &&
758 wpa_s->dpp_listen_freq != wpa_s->dpp_auth->curr_freq) {
759 wpa_printf(MSG_DEBUG,
760 "DPP: Stop listen on %u MHz to allow response on the request %u MHz",
761 wpa_s->dpp_listen_freq, wpa_s->dpp_auth->curr_freq);
762 wpas_dpp_listen_stop(wpa_s);
763 }
764
765 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
766 MAC2STR(src), wpa_s->dpp_auth->curr_freq,
767 DPP_PA_AUTHENTICATION_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700768 offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq,
769 src, wpa_s->own_addr, broadcast,
770 wpabuf_head(wpa_s->dpp_auth->resp_msg),
771 wpabuf_len(wpa_s->dpp_auth->resp_msg),
772 500, wpas_dpp_tx_status, 0);
773}
774
775
776static void wpas_dpp_start_gas_server(struct wpa_supplicant *wpa_s)
777{
778 /* TODO: stop wait and start ROC */
779}
780
781
782static struct wpa_ssid * wpas_dpp_add_network(struct wpa_supplicant *wpa_s,
783 struct dpp_authentication *auth)
784{
785 struct wpa_ssid *ssid;
786
Hai Shalom021b0b52019-04-10 11:17:58 -0700787#ifdef CONFIG_DPP2
788 if (auth->akm == DPP_AKM_SAE) {
789#ifdef CONFIG_SAE
790 struct wpa_driver_capa capa;
791 int res;
792
793 res = wpa_drv_get_capa(wpa_s, &capa);
794 if (res == 0 &&
795 !(capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) &&
796 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
797 wpa_printf(MSG_DEBUG,
798 "DPP: SAE not supported by the driver");
799 return NULL;
800 }
801#else /* CONFIG_SAE */
802 wpa_printf(MSG_DEBUG, "DPP: SAE not supported in the build");
803 return NULL;
804#endif /* CONFIG_SAE */
805 }
806#endif /* CONFIG_DPP2 */
807
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700808 ssid = wpa_config_add_network(wpa_s->conf);
809 if (!ssid)
810 return NULL;
811 wpas_notify_network_added(wpa_s, ssid);
812 wpa_config_set_network_defaults(ssid);
813 ssid->disabled = 1;
814
815 ssid->ssid = os_malloc(auth->ssid_len);
816 if (!ssid->ssid)
817 goto fail;
818 os_memcpy(ssid->ssid, auth->ssid, auth->ssid_len);
819 ssid->ssid_len = auth->ssid_len;
820
821 if (auth->connector) {
822 ssid->key_mgmt = WPA_KEY_MGMT_DPP;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700823 ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700824 ssid->dpp_connector = os_strdup(auth->connector);
825 if (!ssid->dpp_connector)
826 goto fail;
827 }
828
829 if (auth->c_sign_key) {
830 ssid->dpp_csign = os_malloc(wpabuf_len(auth->c_sign_key));
831 if (!ssid->dpp_csign)
832 goto fail;
833 os_memcpy(ssid->dpp_csign, wpabuf_head(auth->c_sign_key),
834 wpabuf_len(auth->c_sign_key));
835 ssid->dpp_csign_len = wpabuf_len(auth->c_sign_key);
836 }
837
838 if (auth->net_access_key) {
839 ssid->dpp_netaccesskey =
840 os_malloc(wpabuf_len(auth->net_access_key));
841 if (!ssid->dpp_netaccesskey)
842 goto fail;
843 os_memcpy(ssid->dpp_netaccesskey,
844 wpabuf_head(auth->net_access_key),
845 wpabuf_len(auth->net_access_key));
846 ssid->dpp_netaccesskey_len = wpabuf_len(auth->net_access_key);
847 ssid->dpp_netaccesskey_expiry = auth->net_access_key_expiry;
848 }
849
Hai Shalom021b0b52019-04-10 11:17:58 -0700850 if (!auth->connector || dpp_akm_psk(auth->akm) ||
851 dpp_akm_sae(auth->akm)) {
852 if (!auth->connector)
853 ssid->key_mgmt = 0;
854 if (dpp_akm_psk(auth->akm))
Roshan Pius3a1667e2018-07-03 15:17:14 -0700855 ssid->key_mgmt |= WPA_KEY_MGMT_PSK |
856 WPA_KEY_MGMT_PSK_SHA256 | WPA_KEY_MGMT_FT_PSK;
Hai Shalom021b0b52019-04-10 11:17:58 -0700857 if (dpp_akm_sae(auth->akm))
Roshan Pius3a1667e2018-07-03 15:17:14 -0700858 ssid->key_mgmt |= WPA_KEY_MGMT_SAE |
859 WPA_KEY_MGMT_FT_SAE;
860 ssid->ieee80211w = MGMT_FRAME_PROTECTION_OPTIONAL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700861 if (auth->passphrase[0]) {
862 if (wpa_config_set_quoted(ssid, "psk",
863 auth->passphrase) < 0)
864 goto fail;
865 wpa_config_update_psk(ssid);
866 ssid->export_keys = 1;
867 } else {
868 ssid->psk_set = auth->psk_set;
869 os_memcpy(ssid->psk, auth->psk, PMK_LEN);
870 }
871 }
872
873 return ssid;
874fail:
875 wpas_notify_network_removed(wpa_s, ssid);
876 wpa_config_remove_network(wpa_s->conf, ssid->id);
877 return NULL;
878}
879
880
Hai Shalom021b0b52019-04-10 11:17:58 -0700881static int wpas_dpp_process_config(struct wpa_supplicant *wpa_s,
882 struct dpp_authentication *auth)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700883{
884 struct wpa_ssid *ssid;
885
886 if (wpa_s->conf->dpp_config_processing < 1)
Hai Shalom021b0b52019-04-10 11:17:58 -0700887 return 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700888
889 ssid = wpas_dpp_add_network(wpa_s, auth);
890 if (!ssid)
Hai Shalom021b0b52019-04-10 11:17:58 -0700891 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700892
893 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_NETWORK_ID "%d", ssid->id);
Hai Shalom59532852018-12-07 10:32:58 -0800894
Hai Shalom706f99b2019-01-08 16:23:37 -0800895 wpas_notify_dpp_config_received(wpa_s, ssid);
Hai Shalom59532852018-12-07 10:32:58 -0800896
Hai Shalom021b0b52019-04-10 11:17:58 -0700897 if (wpa_s->conf->dpp_config_processing == 2)
898 ssid->disabled = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700899
Hai Shalom021b0b52019-04-10 11:17:58 -0700900#ifndef CONFIG_NO_CONFIG_WRITE
901 if (wpa_s->conf->update_config &&
902 wpa_config_write(wpa_s->confname, wpa_s->conf))
903 wpa_printf(MSG_DEBUG, "DPP: Failed to update configuration");
904#endif /* CONFIG_NO_CONFIG_WRITE */
905
906 if (wpa_s->conf->dpp_config_processing < 2)
907 return 0;
908
909#ifdef CONFIG_DPP2
910 if (auth->peer_version >= 2) {
911 wpa_printf(MSG_DEBUG,
912 "DPP: Postpone connection attempt to wait for completion of DPP Configuration Result");
913 auth->connect_on_tx_status = 1;
914 return 0;
915 }
916#endif /* CONFIG_DPP2 */
917
918 wpas_dpp_try_to_connect(wpa_s);
919 return 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700920}
921
922
Hai Shalom021b0b52019-04-10 11:17:58 -0700923static int wpas_dpp_handle_config_obj(struct wpa_supplicant *wpa_s,
924 struct dpp_authentication *auth)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700925{
926 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
927 if (auth->ssid_len)
928 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s",
929 wpa_ssid_txt(auth->ssid, auth->ssid_len));
930 if (auth->connector) {
931 /* TODO: Save the Connector and consider using a command
932 * to fetch the value instead of sending an event with
933 * it. The Connector could end up being larger than what
934 * most clients are ready to receive as an event
935 * message. */
936 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONNECTOR "%s",
937 auth->connector);
938 }
939 if (auth->c_sign_key) {
940 char *hex;
941 size_t hexlen;
942
943 hexlen = 2 * wpabuf_len(auth->c_sign_key) + 1;
944 hex = os_malloc(hexlen);
945 if (hex) {
946 wpa_snprintf_hex(hex, hexlen,
947 wpabuf_head(auth->c_sign_key),
948 wpabuf_len(auth->c_sign_key));
949 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_C_SIGN_KEY "%s",
950 hex);
951 os_free(hex);
952 }
953 }
954 if (auth->net_access_key) {
955 char *hex;
956 size_t hexlen;
957
958 hexlen = 2 * wpabuf_len(auth->net_access_key) + 1;
959 hex = os_malloc(hexlen);
960 if (hex) {
961 wpa_snprintf_hex(hex, hexlen,
962 wpabuf_head(auth->net_access_key),
963 wpabuf_len(auth->net_access_key));
964 if (auth->net_access_key_expiry)
965 wpa_msg(wpa_s, MSG_INFO,
966 DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex,
967 (long unsigned)
968 auth->net_access_key_expiry);
969 else
970 wpa_msg(wpa_s, MSG_INFO,
971 DPP_EVENT_NET_ACCESS_KEY "%s", hex);
972 os_free(hex);
973 }
974 }
975
Hai Shalom021b0b52019-04-10 11:17:58 -0700976 return wpas_dpp_process_config(wpa_s, auth);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700977}
978
979
980static void wpas_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token,
981 enum gas_query_result result,
982 const struct wpabuf *adv_proto,
983 const struct wpabuf *resp, u16 status_code)
984{
985 struct wpa_supplicant *wpa_s = ctx;
986 const u8 *pos;
987 struct dpp_authentication *auth = wpa_s->dpp_auth;
Hai Shalom021b0b52019-04-10 11:17:58 -0700988 int res;
989 enum dpp_status_error status = DPP_STATUS_CONFIG_REJECTED;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700990
Roshan Pius3a1667e2018-07-03 15:17:14 -0700991 wpa_s->dpp_gas_dialog_token = -1;
992
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700993 if (!auth || !auth->auth_success) {
994 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
995 return;
996 }
Hai Shalom74f70d42019-02-11 14:42:39 -0800997 if (result != GAS_QUERY_SUCCESS ||
998 !resp || status_code != WLAN_STATUS_SUCCESS) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700999 wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed");
1000 goto fail;
1001 }
1002
1003 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto",
1004 adv_proto);
1005 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)",
1006 resp);
1007
1008 if (wpabuf_len(adv_proto) != 10 ||
1009 !(pos = wpabuf_head(adv_proto)) ||
1010 pos[0] != WLAN_EID_ADV_PROTO ||
1011 pos[1] != 8 ||
1012 pos[3] != WLAN_EID_VENDOR_SPECIFIC ||
1013 pos[4] != 5 ||
1014 WPA_GET_BE24(&pos[5]) != OUI_WFA ||
1015 pos[8] != 0x1a ||
1016 pos[9] != 1) {
1017 wpa_printf(MSG_DEBUG,
1018 "DPP: Not a DPP Advertisement Protocol ID");
1019 goto fail;
1020 }
1021
1022 if (dpp_conf_resp_rx(auth, resp) < 0) {
1023 wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed");
1024 goto fail;
1025 }
1026
Hai Shalom021b0b52019-04-10 11:17:58 -07001027 res = wpas_dpp_handle_config_obj(wpa_s, auth);
1028 if (res < 0)
1029 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001030
Hai Shalom021b0b52019-04-10 11:17:58 -07001031 status = DPP_STATUS_OK;
1032#ifdef CONFIG_TESTING_OPTIONS
1033 if (dpp_test == DPP_TEST_REJECT_CONFIG) {
1034 wpa_printf(MSG_INFO, "DPP: TESTING - Reject Config Object");
1035 status = DPP_STATUS_CONFIG_REJECTED;
1036 }
1037#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001038fail:
Hai Shalom021b0b52019-04-10 11:17:58 -07001039 if (status != DPP_STATUS_OK) {
1040 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1041 wpas_notify_dpp_configuration_failure(wpa_s);
1042 }
1043#ifdef CONFIG_DPP2
1044 if (auth->peer_version >= 2 &&
1045 auth->conf_resp_status == DPP_STATUS_OK) {
1046 struct wpabuf *msg;
1047
1048 wpa_printf(MSG_DEBUG, "DPP: Send DPP Configuration Result");
1049 msg = dpp_build_conf_result(auth, status);
1050 if (!msg)
1051 goto fail2;
1052
1053 wpa_msg(wpa_s, MSG_INFO,
1054 DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1055 MAC2STR(addr), auth->curr_freq,
1056 DPP_PA_CONFIGURATION_RESULT);
1057 offchannel_send_action(wpa_s, auth->curr_freq,
1058 addr, wpa_s->own_addr, broadcast,
1059 wpabuf_head(msg),
1060 wpabuf_len(msg),
1061 500, wpas_dpp_tx_status, 0);
1062 wpabuf_free(msg);
1063
1064 /* This exchange will be terminated in the TX status handler */
1065 return;
1066 }
1067fail2:
1068#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001069 dpp_auth_deinit(wpa_s->dpp_auth);
1070 wpa_s->dpp_auth = NULL;
1071}
1072
1073
1074static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
1075{
1076 struct dpp_authentication *auth = wpa_s->dpp_auth;
Hai Shalom021b0b52019-04-10 11:17:58 -07001077 struct wpabuf *buf;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001078 char json[100];
1079 int res;
1080
1081 wpa_s->dpp_gas_client = 1;
1082 os_snprintf(json, sizeof(json),
1083 "{\"name\":\"Test\","
1084 "\"wi-fi_tech\":\"infra\","
1085 "\"netRole\":\"%s\"}",
1086 wpa_s->dpp_netrole_ap ? "ap" : "sta");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001087#ifdef CONFIG_TESTING_OPTIONS
1088 if (dpp_test == DPP_TEST_INVALID_CONFIG_ATTR_OBJ_CONF_REQ) {
1089 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Config Attr");
1090 json[29] = 'k'; /* replace "infra" with "knfra" */
1091 }
1092#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001093 wpa_printf(MSG_DEBUG, "DPP: GAS Config Attributes: %s", json);
1094
1095 offchannel_send_action_done(wpa_s);
1096 wpas_dpp_listen_stop(wpa_s);
1097
Hai Shalom021b0b52019-04-10 11:17:58 -07001098 buf = dpp_build_conf_req(auth, json);
1099 if (!buf) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001100 wpa_printf(MSG_DEBUG,
1101 "DPP: No configuration request data available");
1102 return;
1103 }
1104
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001105 wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
1106 MAC2STR(auth->peer_mac_addr), auth->curr_freq);
1107
1108 res = gas_query_req(wpa_s->gas, auth->peer_mac_addr, auth->curr_freq,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001109 1, buf, wpas_dpp_gas_resp_cb, wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001110 if (res < 0) {
1111 wpa_msg(wpa_s, MSG_DEBUG, "GAS: Failed to send Query Request");
1112 wpabuf_free(buf);
1113 } else {
1114 wpa_printf(MSG_DEBUG,
1115 "DPP: GAS query started with dialog token %u", res);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001116 wpa_s->dpp_gas_dialog_token = res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001117 }
1118}
1119
1120
1121static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator)
1122{
1123 wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded");
1124 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d", initiator);
Hai Shalom706f99b2019-01-08 16:23:37 -08001125 wpas_notify_dpp_auth_success(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001126#ifdef CONFIG_TESTING_OPTIONS
1127 if (dpp_test == DPP_TEST_STOP_AT_AUTH_CONF) {
1128 wpa_printf(MSG_INFO,
1129 "DPP: TESTING - stop at Authentication Confirm");
1130 if (wpa_s->dpp_auth->configurator) {
1131 /* Prevent GAS response */
1132 wpa_s->dpp_auth->auth_success = 0;
1133 }
1134 return;
1135 }
1136#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001137
1138 if (wpa_s->dpp_auth->configurator)
1139 wpas_dpp_start_gas_server(wpa_s);
1140 else
1141 wpas_dpp_start_gas_client(wpa_s);
1142}
1143
1144
1145static void wpas_dpp_rx_auth_resp(struct wpa_supplicant *wpa_s, const u8 *src,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001146 const u8 *hdr, const u8 *buf, size_t len,
1147 unsigned int freq)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001148{
1149 struct dpp_authentication *auth = wpa_s->dpp_auth;
1150 struct wpabuf *msg;
1151
Roshan Pius3a1667e2018-07-03 15:17:14 -07001152 wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR
1153 " (freq %u MHz)", MAC2STR(src), freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001154
1155 if (!auth) {
1156 wpa_printf(MSG_DEBUG,
1157 "DPP: No DPP Authentication in progress - drop");
1158 return;
1159 }
1160
1161 if (!is_zero_ether_addr(auth->peer_mac_addr) &&
1162 os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1163 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1164 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1165 return;
1166 }
1167
1168 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
1169
Roshan Pius3a1667e2018-07-03 15:17:14 -07001170 if (auth->curr_freq != freq && auth->neg_freq == freq) {
1171 wpa_printf(MSG_DEBUG,
1172 "DPP: Responder accepted request for different negotiation channel");
1173 auth->curr_freq = freq;
1174 }
1175
1176 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001177 msg = dpp_auth_resp_rx(auth, hdr, buf, len);
1178 if (!msg) {
1179 if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) {
1180 wpa_printf(MSG_DEBUG,
1181 "DPP: Start wait for full response");
Hai Shalom706f99b2019-01-08 16:23:37 -08001182 wpas_notify_dpp_resp_pending(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001183 offchannel_send_action_done(wpa_s);
1184 wpas_dpp_listen_start(wpa_s, auth->curr_freq);
1185 return;
1186 }
1187 wpa_printf(MSG_DEBUG, "DPP: No confirm generated");
1188 return;
1189 }
1190 os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
1191
Roshan Pius3a1667e2018-07-03 15:17:14 -07001192 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1193 MAC2STR(src), auth->curr_freq, DPP_PA_AUTHENTICATION_CONF);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001194 offchannel_send_action(wpa_s, auth->curr_freq,
1195 src, wpa_s->own_addr, broadcast,
1196 wpabuf_head(msg), wpabuf_len(msg),
1197 500, wpas_dpp_tx_status, 0);
1198 wpabuf_free(msg);
1199 wpa_s->dpp_auth_ok_on_ack = 1;
1200}
1201
1202
1203static void wpas_dpp_rx_auth_conf(struct wpa_supplicant *wpa_s, const u8 *src,
1204 const u8 *hdr, const u8 *buf, size_t len)
1205{
1206 struct dpp_authentication *auth = wpa_s->dpp_auth;
1207
1208 wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR,
1209 MAC2STR(src));
1210
1211 if (!auth) {
1212 wpa_printf(MSG_DEBUG,
1213 "DPP: No DPP Authentication in progress - drop");
1214 return;
1215 }
1216
1217 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1218 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1219 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1220 return;
1221 }
1222
1223 if (dpp_auth_conf_rx(auth, hdr, buf, len) < 0) {
1224 wpa_printf(MSG_DEBUG, "DPP: Authentication failed");
Hai Shalom706f99b2019-01-08 16:23:37 -08001225 wpas_notify_dpp_auth_failure(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001226 return;
1227 }
1228
1229 wpas_dpp_auth_success(wpa_s, 0);
1230}
1231
1232
Hai Shalom021b0b52019-04-10 11:17:58 -07001233#ifdef CONFIG_DPP2
1234
1235static void wpas_dpp_config_result_wait_timeout(void *eloop_ctx,
1236 void *timeout_ctx)
1237{
1238 struct wpa_supplicant *wpa_s = eloop_ctx;
1239 struct dpp_authentication *auth = wpa_s->dpp_auth;
1240
1241 if (!auth || !auth->waiting_conf_result)
1242 return;
1243
1244 wpa_printf(MSG_DEBUG,
1245 "DPP: Timeout while waiting for Configuration Result");
1246 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1247 dpp_auth_deinit(auth);
1248 wpa_s->dpp_auth = NULL;
1249}
1250
1251
1252static void wpas_dpp_rx_conf_result(struct wpa_supplicant *wpa_s, const u8 *src,
1253 const u8 *hdr, const u8 *buf, size_t len)
1254{
1255 struct dpp_authentication *auth = wpa_s->dpp_auth;
1256 enum dpp_status_error status;
1257
1258 wpa_printf(MSG_DEBUG, "DPP: Configuration Result from " MACSTR,
1259 MAC2STR(src));
1260
1261 if (!auth || !auth->waiting_conf_result) {
1262 wpa_printf(MSG_DEBUG,
1263 "DPP: No DPP Configuration waiting for result - drop");
1264 return;
1265 }
1266
1267 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1268 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1269 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1270 return;
1271 }
1272
1273 status = dpp_conf_result_rx(auth, hdr, buf, len);
1274
1275 offchannel_send_action_done(wpa_s);
1276 wpas_dpp_listen_stop(wpa_s);
1277 if (status == DPP_STATUS_OK)
1278 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
1279 else
1280 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1281 dpp_auth_deinit(auth);
1282 wpa_s->dpp_auth = NULL;
1283 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL);
1284}
1285
1286#endif /* CONFIG_DPP2 */
1287
1288
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001289static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant *wpa_s,
1290 const u8 *src,
1291 const u8 *buf, size_t len)
1292{
1293 struct wpa_ssid *ssid;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001294 const u8 *connector, *trans_id, *status;
1295 u16 connector_len, trans_id_len, status_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001296 struct dpp_introduction intro;
1297 struct rsn_pmksa_cache_entry *entry;
1298 struct os_time now;
1299 struct os_reltime rnow;
1300 os_time_t expiry;
1301 unsigned int seconds;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001302 enum dpp_status_error res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001303
1304 wpa_printf(MSG_DEBUG, "DPP: Peer Discovery Response from " MACSTR,
1305 MAC2STR(src));
1306 if (is_zero_ether_addr(wpa_s->dpp_intro_bssid) ||
1307 os_memcmp(src, wpa_s->dpp_intro_bssid, ETH_ALEN) != 0) {
1308 wpa_printf(MSG_DEBUG, "DPP: Not waiting for response from "
1309 MACSTR " - drop", MAC2STR(src));
1310 return;
1311 }
1312 offchannel_send_action_done(wpa_s);
1313
1314 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1315 if (ssid == wpa_s->dpp_intro_network)
1316 break;
1317 }
1318 if (!ssid || !ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1319 !ssid->dpp_csign) {
1320 wpa_printf(MSG_DEBUG,
1321 "DPP: Profile not found for network introduction");
1322 return;
1323 }
1324
1325 trans_id = dpp_get_attr(buf, len, DPP_ATTR_TRANSACTION_ID,
1326 &trans_id_len);
1327 if (!trans_id || trans_id_len != 1) {
1328 wpa_printf(MSG_DEBUG,
1329 "DPP: Peer did not include Transaction ID");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001330 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1331 " fail=missing_transaction_id", MAC2STR(src));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001332 goto fail;
1333 }
1334 if (trans_id[0] != TRANSACTION_ID) {
1335 wpa_printf(MSG_DEBUG,
1336 "DPP: Ignore frame with unexpected Transaction ID %u",
1337 trans_id[0]);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001338 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1339 " fail=transaction_id_mismatch", MAC2STR(src));
1340 goto fail;
1341 }
1342
1343 status = dpp_get_attr(buf, len, DPP_ATTR_STATUS, &status_len);
1344 if (!status || status_len != 1) {
1345 wpa_printf(MSG_DEBUG, "DPP: Peer did not include Status");
1346 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1347 " fail=missing_status", MAC2STR(src));
1348 goto fail;
1349 }
1350 if (status[0] != DPP_STATUS_OK) {
1351 wpa_printf(MSG_DEBUG,
1352 "DPP: Peer rejected network introduction: Status %u",
1353 status[0]);
1354 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1355 " status=%u", MAC2STR(src), status[0]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001356 goto fail;
1357 }
1358
1359 connector = dpp_get_attr(buf, len, DPP_ATTR_CONNECTOR, &connector_len);
1360 if (!connector) {
1361 wpa_printf(MSG_DEBUG,
1362 "DPP: Peer did not include its Connector");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001363 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1364 " fail=missing_connector", MAC2STR(src));
1365 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001366 }
1367
Roshan Pius3a1667e2018-07-03 15:17:14 -07001368 res = dpp_peer_intro(&intro, ssid->dpp_connector,
1369 ssid->dpp_netaccesskey,
1370 ssid->dpp_netaccesskey_len,
1371 ssid->dpp_csign,
1372 ssid->dpp_csign_len,
1373 connector, connector_len, &expiry);
1374 if (res != DPP_STATUS_OK) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001375 wpa_printf(MSG_INFO,
1376 "DPP: Network Introduction protocol resulted in failure");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001377 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1378 " fail=peer_connector_validation_failed", MAC2STR(src));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001379 goto fail;
1380 }
1381
1382 entry = os_zalloc(sizeof(*entry));
1383 if (!entry)
1384 goto fail;
1385 os_memcpy(entry->aa, src, ETH_ALEN);
1386 os_memcpy(entry->pmkid, intro.pmkid, PMKID_LEN);
1387 os_memcpy(entry->pmk, intro.pmk, intro.pmk_len);
1388 entry->pmk_len = intro.pmk_len;
1389 entry->akmp = WPA_KEY_MGMT_DPP;
1390 if (expiry) {
1391 os_get_time(&now);
1392 seconds = expiry - now.sec;
1393 } else {
1394 seconds = 86400 * 7;
1395 }
1396 os_get_reltime(&rnow);
1397 entry->expiration = rnow.sec + seconds;
1398 entry->reauth_time = rnow.sec + seconds;
1399 entry->network_ctx = ssid;
1400 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
1401
Roshan Pius3a1667e2018-07-03 15:17:14 -07001402 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1403 " status=%u", MAC2STR(src), status[0]);
1404
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001405 wpa_printf(MSG_DEBUG,
1406 "DPP: Try connection again after successful network introduction");
1407 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
1408 wpa_supplicant_cancel_sched_scan(wpa_s);
1409 wpa_supplicant_req_scan(wpa_s, 0, 0);
1410 }
1411fail:
1412 os_memset(&intro, 0, sizeof(intro));
1413}
1414
1415
Roshan Pius3a1667e2018-07-03 15:17:14 -07001416static int wpas_dpp_allow_ir(struct wpa_supplicant *wpa_s, unsigned int freq)
1417{
1418 int i, j;
1419
1420 if (!wpa_s->hw.modes)
1421 return -1;
1422
1423 for (i = 0; i < wpa_s->hw.num_modes; i++) {
1424 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
1425
1426 for (j = 0; j < mode->num_channels; j++) {
1427 struct hostapd_channel_data *chan = &mode->channels[j];
1428
1429 if (chan->freq != (int) freq)
1430 continue;
1431
1432 if (chan->flag & (HOSTAPD_CHAN_DISABLED |
1433 HOSTAPD_CHAN_NO_IR |
1434 HOSTAPD_CHAN_RADAR))
1435 continue;
1436
1437 return 1;
1438 }
1439 }
1440
1441 wpa_printf(MSG_DEBUG,
1442 "DPP: Frequency %u MHz not supported or does not allow PKEX initiation in the current channel list",
1443 freq);
1444
1445 return 0;
1446}
1447
1448
1449static int wpas_dpp_pkex_next_channel(struct wpa_supplicant *wpa_s,
1450 struct dpp_pkex *pkex)
1451{
1452 if (pkex->freq == 2437)
1453 pkex->freq = 5745;
1454 else if (pkex->freq == 5745)
1455 pkex->freq = 5220;
1456 else if (pkex->freq == 5220)
1457 pkex->freq = 60480;
1458 else
1459 return -1; /* no more channels to try */
1460
1461 if (wpas_dpp_allow_ir(wpa_s, pkex->freq) == 1) {
1462 wpa_printf(MSG_DEBUG, "DPP: Try to initiate on %u MHz",
1463 pkex->freq);
1464 return 0;
1465 }
1466
1467 /* Could not use this channel - try the next one */
1468 return wpas_dpp_pkex_next_channel(wpa_s, pkex);
1469}
1470
1471
1472static void wpas_dpp_pkex_retry_timeout(void *eloop_ctx, void *timeout_ctx)
1473{
1474 struct wpa_supplicant *wpa_s = eloop_ctx;
1475 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1476
1477 if (!pkex || !pkex->exchange_req)
1478 return;
1479 if (pkex->exch_req_tries >= 5) {
1480 if (wpas_dpp_pkex_next_channel(wpa_s, pkex) < 0) {
1481 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1482 "No response from PKEX peer");
1483 dpp_pkex_free(pkex);
1484 wpa_s->dpp_pkex = NULL;
1485 return;
1486 }
1487 pkex->exch_req_tries = 0;
1488 }
1489
1490 pkex->exch_req_tries++;
1491 wpa_printf(MSG_DEBUG, "DPP: Retransmit PKEX Exchange Request (try %u)",
1492 pkex->exch_req_tries);
1493 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1494 MAC2STR(broadcast), pkex->freq, DPP_PA_PKEX_EXCHANGE_REQ);
1495 offchannel_send_action(wpa_s, pkex->freq, broadcast,
1496 wpa_s->own_addr, broadcast,
1497 wpabuf_head(pkex->exchange_req),
1498 wpabuf_len(pkex->exchange_req),
1499 pkex->exch_req_wait_time,
1500 wpas_dpp_tx_pkex_status, 0);
1501}
1502
1503
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001504static void
1505wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s,
1506 unsigned int freq, const u8 *dst,
1507 const u8 *src, const u8 *bssid,
1508 const u8 *data, size_t data_len,
1509 enum offchannel_send_action_result result)
1510{
Roshan Pius3a1667e2018-07-03 15:17:14 -07001511 const char *res_txt;
1512 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1513
1514 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
1515 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
1516 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001517 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
1518 " result=%s (PKEX)",
Roshan Pius3a1667e2018-07-03 15:17:14 -07001519 freq, MAC2STR(dst), res_txt);
1520 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
1521 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
1522
1523 if (!pkex) {
1524 wpa_printf(MSG_DEBUG,
1525 "DPP: Ignore TX status since there is no ongoing PKEX exchange");
1526 return;
1527 }
1528
1529 if (pkex->failed) {
1530 wpa_printf(MSG_DEBUG,
1531 "DPP: Terminate PKEX exchange due to an earlier error");
1532 if (pkex->t > pkex->own_bi->pkex_t)
1533 pkex->own_bi->pkex_t = pkex->t;
1534 dpp_pkex_free(pkex);
1535 wpa_s->dpp_pkex = NULL;
1536 return;
1537 }
1538
1539 if (pkex->exch_req_wait_time && pkex->exchange_req) {
1540 /* Wait for PKEX Exchange Response frame and retry request if
1541 * no response is seen. */
1542 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
1543 eloop_register_timeout(pkex->exch_req_wait_time / 1000,
1544 (pkex->exch_req_wait_time % 1000) * 1000,
1545 wpas_dpp_pkex_retry_timeout, wpa_s,
1546 NULL);
1547 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001548}
1549
1550
1551static void
1552wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant *wpa_s, const u8 *src,
1553 const u8 *buf, size_t len, unsigned int freq)
1554{
1555 struct wpabuf *msg;
1556 unsigned int wait_time;
1557
1558 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Request from " MACSTR,
1559 MAC2STR(src));
1560
1561 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1562 * values here */
1563
1564 if (!wpa_s->dpp_pkex_code || !wpa_s->dpp_pkex_bi) {
1565 wpa_printf(MSG_DEBUG,
1566 "DPP: No PKEX code configured - ignore request");
1567 return;
1568 }
1569
1570 if (wpa_s->dpp_pkex) {
1571 /* TODO: Support parallel operations */
1572 wpa_printf(MSG_DEBUG,
1573 "DPP: Already in PKEX session - ignore new request");
1574 return;
1575 }
1576
Roshan Pius3a1667e2018-07-03 15:17:14 -07001577 wpa_s->dpp_pkex = dpp_pkex_rx_exchange_req(wpa_s, wpa_s->dpp_pkex_bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001578 wpa_s->own_addr, src,
1579 wpa_s->dpp_pkex_identifier,
1580 wpa_s->dpp_pkex_code,
1581 buf, len);
1582 if (!wpa_s->dpp_pkex) {
1583 wpa_printf(MSG_DEBUG,
1584 "DPP: Failed to process the request - ignore it");
1585 return;
1586 }
1587
1588 msg = wpa_s->dpp_pkex->exchange_resp;
1589 wait_time = wpa_s->max_remain_on_chan;
1590 if (wait_time > 2000)
1591 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001592 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1593 MAC2STR(src), freq, DPP_PA_PKEX_EXCHANGE_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001594 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
1595 broadcast,
1596 wpabuf_head(msg), wpabuf_len(msg),
1597 wait_time, wpas_dpp_tx_pkex_status, 0);
1598}
1599
1600
1601static void
1602wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant *wpa_s, const u8 *src,
1603 const u8 *buf, size_t len, unsigned int freq)
1604{
1605 struct wpabuf *msg;
1606 unsigned int wait_time;
1607
1608 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Response from " MACSTR,
1609 MAC2STR(src));
1610
1611 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1612 * values here */
1613
1614 if (!wpa_s->dpp_pkex || !wpa_s->dpp_pkex->initiator ||
1615 wpa_s->dpp_pkex->exchange_done) {
1616 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1617 return;
1618 }
1619
Roshan Pius3a1667e2018-07-03 15:17:14 -07001620 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
1621 wpa_s->dpp_pkex->exch_req_wait_time = 0;
1622
1623 msg = dpp_pkex_rx_exchange_resp(wpa_s->dpp_pkex, src, buf, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001624 if (!msg) {
1625 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
1626 return;
1627 }
1628
1629 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Request to " MACSTR,
1630 MAC2STR(src));
1631
1632 wait_time = wpa_s->max_remain_on_chan;
1633 if (wait_time > 2000)
1634 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001635 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1636 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_REQ);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001637 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
1638 broadcast,
1639 wpabuf_head(msg), wpabuf_len(msg),
1640 wait_time, wpas_dpp_tx_pkex_status, 0);
1641 wpabuf_free(msg);
1642}
1643
1644
Roshan Pius3a1667e2018-07-03 15:17:14 -07001645static struct dpp_bootstrap_info *
1646wpas_dpp_pkex_finish(struct wpa_supplicant *wpa_s, const u8 *peer,
1647 unsigned int freq)
1648{
Roshan Pius3a1667e2018-07-03 15:17:14 -07001649 struct dpp_bootstrap_info *bi;
1650
Hai Shalom021b0b52019-04-10 11:17:58 -07001651 bi = dpp_pkex_finish(wpa_s->dpp, wpa_s->dpp_pkex, peer, freq);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001652 if (!bi)
1653 return NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001654 wpa_s->dpp_pkex = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001655 return bi;
1656}
1657
1658
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001659static void
1660wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant *wpa_s, const u8 *src,
1661 const u8 *hdr, const u8 *buf, size_t len,
1662 unsigned int freq)
1663{
1664 struct wpabuf *msg;
1665 unsigned int wait_time;
1666 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001667
1668 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Request from " MACSTR,
1669 MAC2STR(src));
1670
1671 if (!pkex || pkex->initiator || !pkex->exchange_done) {
1672 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1673 return;
1674 }
1675
1676 msg = dpp_pkex_rx_commit_reveal_req(pkex, hdr, buf, len);
1677 if (!msg) {
1678 wpa_printf(MSG_DEBUG, "DPP: Failed to process the request");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001679 if (pkex->failed) {
1680 wpa_printf(MSG_DEBUG, "DPP: Terminate PKEX exchange");
1681 if (pkex->t > pkex->own_bi->pkex_t)
1682 pkex->own_bi->pkex_t = pkex->t;
1683 dpp_pkex_free(wpa_s->dpp_pkex);
1684 wpa_s->dpp_pkex = NULL;
1685 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001686 return;
1687 }
1688
1689 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Response to "
1690 MACSTR, MAC2STR(src));
1691
1692 wait_time = wpa_s->max_remain_on_chan;
1693 if (wait_time > 2000)
1694 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001695 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1696 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001697 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
1698 broadcast,
1699 wpabuf_head(msg), wpabuf_len(msg),
1700 wait_time, wpas_dpp_tx_pkex_status, 0);
1701 wpabuf_free(msg);
1702
Roshan Pius3a1667e2018-07-03 15:17:14 -07001703 wpas_dpp_pkex_finish(wpa_s, src, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001704}
1705
1706
1707static void
1708wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant *wpa_s, const u8 *src,
1709 const u8 *hdr, const u8 *buf, size_t len,
1710 unsigned int freq)
1711{
1712 int res;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001713 struct dpp_bootstrap_info *bi;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001714 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1715 char cmd[500];
1716
1717 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Response from " MACSTR,
1718 MAC2STR(src));
1719
1720 if (!pkex || !pkex->initiator || !pkex->exchange_done) {
1721 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1722 return;
1723 }
1724
1725 res = dpp_pkex_rx_commit_reveal_resp(pkex, hdr, buf, len);
1726 if (res < 0) {
1727 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
1728 return;
1729 }
1730
Roshan Pius3a1667e2018-07-03 15:17:14 -07001731 bi = wpas_dpp_pkex_finish(wpa_s, src, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001732 if (!bi)
1733 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001734
1735 os_snprintf(cmd, sizeof(cmd), " peer=%u %s",
1736 bi->id,
1737 wpa_s->dpp_pkex_auth_cmd ? wpa_s->dpp_pkex_auth_cmd : "");
1738 wpa_printf(MSG_DEBUG,
1739 "DPP: Start authentication after PKEX with parameters: %s",
1740 cmd);
1741 if (wpas_dpp_auth_init(wpa_s, cmd) < 0) {
1742 wpa_printf(MSG_DEBUG,
1743 "DPP: Authentication initialization failed");
1744 return;
1745 }
1746}
1747
1748
1749void wpas_dpp_rx_action(struct wpa_supplicant *wpa_s, const u8 *src,
1750 const u8 *buf, size_t len, unsigned int freq)
1751{
1752 u8 crypto_suite;
1753 enum dpp_public_action_frame_type type;
1754 const u8 *hdr;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001755 unsigned int pkex_t;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001756
1757 if (len < DPP_HDR_LEN)
1758 return;
1759 if (WPA_GET_BE24(buf) != OUI_WFA || buf[3] != DPP_OUI_TYPE)
1760 return;
1761 hdr = buf;
1762 buf += 4;
1763 len -= 4;
1764 crypto_suite = *buf++;
1765 type = *buf++;
1766 len -= 2;
1767
1768 wpa_printf(MSG_DEBUG,
1769 "DPP: Received DPP Public Action frame crypto suite %u type %d from "
1770 MACSTR " freq=%u",
1771 crypto_suite, type, MAC2STR(src), freq);
1772 if (crypto_suite != 1) {
1773 wpa_printf(MSG_DEBUG, "DPP: Unsupported crypto suite %u",
1774 crypto_suite);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001775 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
1776 " freq=%u type=%d ignore=unsupported-crypto-suite",
1777 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001778 return;
1779 }
1780 wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001781 if (dpp_check_attrs(buf, len) < 0) {
1782 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
1783 " freq=%u type=%d ignore=invalid-attributes",
1784 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001785 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001786 }
1787 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR " freq=%u type=%d",
1788 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001789
1790 switch (type) {
1791 case DPP_PA_AUTHENTICATION_REQ:
1792 wpas_dpp_rx_auth_req(wpa_s, src, hdr, buf, len, freq);
1793 break;
1794 case DPP_PA_AUTHENTICATION_RESP:
Roshan Pius3a1667e2018-07-03 15:17:14 -07001795 wpas_dpp_rx_auth_resp(wpa_s, src, hdr, buf, len, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001796 break;
1797 case DPP_PA_AUTHENTICATION_CONF:
1798 wpas_dpp_rx_auth_conf(wpa_s, src, hdr, buf, len);
1799 break;
1800 case DPP_PA_PEER_DISCOVERY_RESP:
1801 wpas_dpp_rx_peer_disc_resp(wpa_s, src, buf, len);
1802 break;
1803 case DPP_PA_PKEX_EXCHANGE_REQ:
1804 wpas_dpp_rx_pkex_exchange_req(wpa_s, src, buf, len, freq);
1805 break;
1806 case DPP_PA_PKEX_EXCHANGE_RESP:
1807 wpas_dpp_rx_pkex_exchange_resp(wpa_s, src, buf, len, freq);
1808 break;
1809 case DPP_PA_PKEX_COMMIT_REVEAL_REQ:
1810 wpas_dpp_rx_pkex_commit_reveal_req(wpa_s, src, hdr, buf, len,
1811 freq);
1812 break;
1813 case DPP_PA_PKEX_COMMIT_REVEAL_RESP:
1814 wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s, src, hdr, buf, len,
1815 freq);
1816 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07001817#ifdef CONFIG_DPP2
1818 case DPP_PA_CONFIGURATION_RESULT:
1819 wpas_dpp_rx_conf_result(wpa_s, src, hdr, buf, len);
1820 break;
1821#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001822 default:
1823 wpa_printf(MSG_DEBUG,
1824 "DPP: Ignored unsupported frame subtype %d", type);
1825 break;
1826 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001827
1828 if (wpa_s->dpp_pkex)
1829 pkex_t = wpa_s->dpp_pkex->t;
1830 else if (wpa_s->dpp_pkex_bi)
1831 pkex_t = wpa_s->dpp_pkex_bi->pkex_t;
1832 else
1833 pkex_t = 0;
1834 if (pkex_t >= PKEX_COUNTER_T_LIMIT) {
1835 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_PKEX_T_LIMIT "id=0");
1836 wpas_dpp_pkex_remove(wpa_s, "*");
1837 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001838}
1839
1840
1841static struct wpabuf *
1842wpas_dpp_gas_req_handler(void *ctx, const u8 *sa, const u8 *query,
1843 size_t query_len)
1844{
1845 struct wpa_supplicant *wpa_s = ctx;
1846 struct dpp_authentication *auth = wpa_s->dpp_auth;
1847 struct wpabuf *resp;
1848
1849 wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR,
1850 MAC2STR(sa));
1851 if (!auth || !auth->auth_success ||
1852 os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) {
1853 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
1854 return NULL;
1855 }
1856 wpa_hexdump(MSG_DEBUG,
1857 "DPP: Received Configuration Request (GAS Query Request)",
1858 query, query_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001859 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_REQ_RX "src=" MACSTR,
1860 MAC2STR(sa));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001861 resp = dpp_conf_req_rx(auth, query, query_len);
Hai Shalom59532852018-12-07 10:32:58 -08001862 if (!resp) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001863 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -08001864 wpas_notify_dpp_configuration_failure(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08001865 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001866 auth->conf_resp = resp;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001867 return resp;
1868}
1869
1870
1871static void
1872wpas_dpp_gas_status_handler(void *ctx, struct wpabuf *resp, int ok)
1873{
1874 struct wpa_supplicant *wpa_s = ctx;
1875 struct dpp_authentication *auth = wpa_s->dpp_auth;
1876
1877 if (!auth) {
1878 wpabuf_free(resp);
1879 return;
1880 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001881 if (auth->conf_resp != resp) {
1882 wpa_printf(MSG_DEBUG,
1883 "DPP: Ignore GAS status report (ok=%d) for unknown response",
1884 ok);
1885 wpabuf_free(resp);
1886 return;
1887 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001888
1889 wpa_printf(MSG_DEBUG, "DPP: Configuration exchange completed (ok=%d)",
1890 ok);
1891 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001892 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07001893#ifdef CONFIG_DPP2
1894 if (ok && auth->peer_version >= 2 &&
1895 auth->conf_resp_status == DPP_STATUS_OK) {
1896 wpa_printf(MSG_DEBUG, "DPP: Wait for Configuration Result");
1897 auth->waiting_conf_result = 1;
1898 auth->conf_resp = NULL;
1899 wpabuf_free(resp);
1900 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout,
1901 wpa_s, NULL);
1902 eloop_register_timeout(2, 0,
1903 wpas_dpp_config_result_wait_timeout,
1904 wpa_s, NULL);
1905 return;
1906 }
1907#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001908 offchannel_send_action_done(wpa_s);
1909 wpas_dpp_listen_stop(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08001910 if (ok) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001911 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
Hai Shalom706f99b2019-01-08 16:23:37 -08001912 wpas_notify_dpp_config_sent(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08001913 }
1914 else {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001915 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -08001916 wpas_notify_dpp_configuration_failure(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08001917 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001918 dpp_auth_deinit(wpa_s->dpp_auth);
1919 wpa_s->dpp_auth = NULL;
1920 wpabuf_free(resp);
1921}
1922
1923
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001924int wpas_dpp_configurator_sign(struct wpa_supplicant *wpa_s, const char *cmd)
1925{
1926 struct dpp_authentication *auth;
1927 int ret = -1;
1928 char *curve = NULL;
1929
1930 auth = os_zalloc(sizeof(*auth));
1931 if (!auth)
1932 return -1;
1933
1934 curve = get_param(cmd, " curve=");
Hai Shalom74f70d42019-02-11 14:42:39 -08001935 wpas_dpp_set_testing_options(wpa_s, auth);
Hai Shalom021b0b52019-04-10 11:17:58 -07001936 if (dpp_set_configurator(wpa_s->dpp, wpa_s, auth, cmd) == 0 &&
1937 dpp_configurator_own_config(auth, curve, 0) == 0)
1938 ret = wpas_dpp_handle_config_obj(wpa_s, auth);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001939
1940 dpp_auth_deinit(auth);
1941 os_free(curve);
1942
1943 return ret;
1944}
1945
1946
1947static void
1948wpas_dpp_tx_introduction_status(struct wpa_supplicant *wpa_s,
1949 unsigned int freq, const u8 *dst,
1950 const u8 *src, const u8 *bssid,
1951 const u8 *data, size_t data_len,
1952 enum offchannel_send_action_result result)
1953{
Roshan Pius3a1667e2018-07-03 15:17:14 -07001954 const char *res_txt;
1955
1956 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
1957 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
1958 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001959 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
1960 " result=%s (DPP Peer Discovery Request)",
Roshan Pius3a1667e2018-07-03 15:17:14 -07001961 freq, MAC2STR(dst), res_txt);
1962 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
1963 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001964 /* TODO: Time out wait for response more quickly in error cases? */
1965}
1966
1967
1968int wpas_dpp_check_connect(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1969 struct wpa_bss *bss)
1970{
1971 struct os_time now;
1972 struct wpabuf *msg;
1973 unsigned int wait_time;
Hai Shalom021b0b52019-04-10 11:17:58 -07001974 const u8 *rsn;
1975 struct wpa_ie_data ied;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001976
1977 if (!(ssid->key_mgmt & WPA_KEY_MGMT_DPP) || !bss)
1978 return 0; /* Not using DPP AKM - continue */
Hai Shalom021b0b52019-04-10 11:17:58 -07001979 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1980 if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ied) == 0 &&
1981 !(ied.key_mgmt & WPA_KEY_MGMT_DPP))
1982 return 0; /* AP does not support DPP AKM - continue */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001983 if (wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid))
1984 return 0; /* PMKSA exists for DPP AKM - continue */
1985
1986 if (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1987 !ssid->dpp_csign) {
1988 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
1989 "missing %s",
1990 !ssid->dpp_connector ? "Connector" :
1991 (!ssid->dpp_netaccesskey ? "netAccessKey" :
1992 "C-sign-key"));
1993 return -1;
1994 }
1995
1996 os_get_time(&now);
1997
1998 if (ssid->dpp_netaccesskey_expiry &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07001999 (os_time_t) ssid->dpp_netaccesskey_expiry < now.sec) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002000 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
2001 "netAccessKey expired");
2002 return -1;
2003 }
2004
2005 wpa_printf(MSG_DEBUG,
2006 "DPP: Starting network introduction protocol to derive PMKSA for "
2007 MACSTR, MAC2STR(bss->bssid));
2008
2009 msg = dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ,
2010 5 + 4 + os_strlen(ssid->dpp_connector));
2011 if (!msg)
2012 return -1;
2013
Roshan Pius3a1667e2018-07-03 15:17:14 -07002014#ifdef CONFIG_TESTING_OPTIONS
2015 if (dpp_test == DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ) {
2016 wpa_printf(MSG_INFO, "DPP: TESTING - no Transaction ID");
2017 goto skip_trans_id;
2018 }
2019 if (dpp_test == DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ) {
2020 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Transaction ID");
2021 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
2022 wpabuf_put_le16(msg, 0);
2023 goto skip_trans_id;
2024 }
2025#endif /* CONFIG_TESTING_OPTIONS */
2026
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002027 /* Transaction ID */
2028 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
2029 wpabuf_put_le16(msg, 1);
2030 wpabuf_put_u8(msg, TRANSACTION_ID);
2031
Roshan Pius3a1667e2018-07-03 15:17:14 -07002032#ifdef CONFIG_TESTING_OPTIONS
2033skip_trans_id:
2034 if (dpp_test == DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ) {
2035 wpa_printf(MSG_INFO, "DPP: TESTING - no Connector");
2036 goto skip_connector;
2037 }
2038 if (dpp_test == DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ) {
2039 char *connector;
2040
2041 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Connector");
2042 connector = dpp_corrupt_connector_signature(
2043 ssid->dpp_connector);
2044 if (!connector) {
2045 wpabuf_free(msg);
2046 return -1;
2047 }
2048 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
2049 wpabuf_put_le16(msg, os_strlen(connector));
2050 wpabuf_put_str(msg, connector);
2051 os_free(connector);
2052 goto skip_connector;
2053 }
2054#endif /* CONFIG_TESTING_OPTIONS */
2055
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002056 /* DPP Connector */
2057 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
2058 wpabuf_put_le16(msg, os_strlen(ssid->dpp_connector));
2059 wpabuf_put_str(msg, ssid->dpp_connector);
2060
Roshan Pius3a1667e2018-07-03 15:17:14 -07002061#ifdef CONFIG_TESTING_OPTIONS
2062skip_connector:
2063#endif /* CONFIG_TESTING_OPTIONS */
2064
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002065 /* TODO: Timeout on AP response */
2066 wait_time = wpa_s->max_remain_on_chan;
2067 if (wait_time > 2000)
2068 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002069 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2070 MAC2STR(bss->bssid), bss->freq, DPP_PA_PEER_DISCOVERY_REQ);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002071 offchannel_send_action(wpa_s, bss->freq, bss->bssid, wpa_s->own_addr,
2072 broadcast,
2073 wpabuf_head(msg), wpabuf_len(msg),
2074 wait_time, wpas_dpp_tx_introduction_status, 0);
2075 wpabuf_free(msg);
2076
2077 /* Request this connection attempt to terminate - new one will be
2078 * started when network introduction protocol completes */
2079 os_memcpy(wpa_s->dpp_intro_bssid, bss->bssid, ETH_ALEN);
2080 wpa_s->dpp_intro_network = ssid;
2081 return 1;
2082}
2083
2084
2085int wpas_dpp_pkex_add(struct wpa_supplicant *wpa_s, const char *cmd)
2086{
2087 struct dpp_bootstrap_info *own_bi;
2088 const char *pos, *end;
2089 unsigned int wait_time;
2090
2091 pos = os_strstr(cmd, " own=");
2092 if (!pos)
2093 return -1;
2094 pos += 5;
Hai Shalom021b0b52019-04-10 11:17:58 -07002095 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002096 if (!own_bi) {
2097 wpa_printf(MSG_DEBUG,
2098 "DPP: Identified bootstrap info not found");
2099 return -1;
2100 }
2101 if (own_bi->type != DPP_BOOTSTRAP_PKEX) {
2102 wpa_printf(MSG_DEBUG,
2103 "DPP: Identified bootstrap info not for PKEX");
2104 return -1;
2105 }
2106 wpa_s->dpp_pkex_bi = own_bi;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002107 own_bi->pkex_t = 0; /* clear pending errors on new code */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002108
2109 os_free(wpa_s->dpp_pkex_identifier);
2110 wpa_s->dpp_pkex_identifier = NULL;
2111 pos = os_strstr(cmd, " identifier=");
2112 if (pos) {
2113 pos += 12;
2114 end = os_strchr(pos, ' ');
2115 if (!end)
2116 return -1;
2117 wpa_s->dpp_pkex_identifier = os_malloc(end - pos + 1);
2118 if (!wpa_s->dpp_pkex_identifier)
2119 return -1;
2120 os_memcpy(wpa_s->dpp_pkex_identifier, pos, end - pos);
2121 wpa_s->dpp_pkex_identifier[end - pos] = '\0';
2122 }
2123
2124 pos = os_strstr(cmd, " code=");
2125 if (!pos)
2126 return -1;
2127 os_free(wpa_s->dpp_pkex_code);
2128 wpa_s->dpp_pkex_code = os_strdup(pos + 6);
2129 if (!wpa_s->dpp_pkex_code)
2130 return -1;
2131
2132 if (os_strstr(cmd, " init=1")) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002133 struct dpp_pkex *pkex;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002134 struct wpabuf *msg;
2135
2136 wpa_printf(MSG_DEBUG, "DPP: Initiating PKEX");
2137 dpp_pkex_free(wpa_s->dpp_pkex);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002138 wpa_s->dpp_pkex = dpp_pkex_init(wpa_s, own_bi, wpa_s->own_addr,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002139 wpa_s->dpp_pkex_identifier,
2140 wpa_s->dpp_pkex_code);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002141 pkex = wpa_s->dpp_pkex;
2142 if (!pkex)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002143 return -1;
2144
Roshan Pius3a1667e2018-07-03 15:17:14 -07002145 msg = pkex->exchange_req;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002146 wait_time = wpa_s->max_remain_on_chan;
2147 if (wait_time > 2000)
2148 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002149 pkex->freq = 2437;
2150 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
2151 " freq=%u type=%d",
2152 MAC2STR(broadcast), pkex->freq,
2153 DPP_PA_PKEX_EXCHANGE_REQ);
2154 offchannel_send_action(wpa_s, pkex->freq, broadcast,
2155 wpa_s->own_addr, broadcast,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002156 wpabuf_head(msg), wpabuf_len(msg),
2157 wait_time, wpas_dpp_tx_pkex_status, 0);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002158 if (wait_time == 0)
2159 wait_time = 2000;
2160 pkex->exch_req_wait_time = wait_time;
2161 pkex->exch_req_tries = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002162 }
2163
2164 /* TODO: Support multiple PKEX info entries */
2165
2166 os_free(wpa_s->dpp_pkex_auth_cmd);
2167 wpa_s->dpp_pkex_auth_cmd = os_strdup(cmd);
2168
2169 return 1;
2170}
2171
2172
2173int wpas_dpp_pkex_remove(struct wpa_supplicant *wpa_s, const char *id)
2174{
2175 unsigned int id_val;
2176
2177 if (os_strcmp(id, "*") == 0) {
2178 id_val = 0;
2179 } else {
2180 id_val = atoi(id);
2181 if (id_val == 0)
2182 return -1;
2183 }
2184
2185 if ((id_val != 0 && id_val != 1) || !wpa_s->dpp_pkex_code)
2186 return -1;
2187
2188 /* TODO: Support multiple PKEX entries */
2189 os_free(wpa_s->dpp_pkex_code);
2190 wpa_s->dpp_pkex_code = NULL;
2191 os_free(wpa_s->dpp_pkex_identifier);
2192 wpa_s->dpp_pkex_identifier = NULL;
2193 os_free(wpa_s->dpp_pkex_auth_cmd);
2194 wpa_s->dpp_pkex_auth_cmd = NULL;
2195 wpa_s->dpp_pkex_bi = NULL;
2196 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
2197 dpp_pkex_free(wpa_s->dpp_pkex);
2198 wpa_s->dpp_pkex = NULL;
2199 return 0;
2200}
2201
2202
Roshan Pius3a1667e2018-07-03 15:17:14 -07002203void wpas_dpp_stop(struct wpa_supplicant *wpa_s)
2204{
2205 dpp_auth_deinit(wpa_s->dpp_auth);
2206 wpa_s->dpp_auth = NULL;
2207 dpp_pkex_free(wpa_s->dpp_pkex);
2208 wpa_s->dpp_pkex = NULL;
2209 if (wpa_s->dpp_gas_client && wpa_s->dpp_gas_dialog_token >= 0)
2210 gas_query_stop(wpa_s->gas, wpa_s->dpp_gas_dialog_token);
2211}
2212
2213
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002214int wpas_dpp_init(struct wpa_supplicant *wpa_s)
2215{
2216 u8 adv_proto_id[7];
2217
2218 adv_proto_id[0] = WLAN_EID_VENDOR_SPECIFIC;
2219 adv_proto_id[1] = 5;
2220 WPA_PUT_BE24(&adv_proto_id[2], OUI_WFA);
2221 adv_proto_id[5] = DPP_OUI_TYPE;
2222 adv_proto_id[6] = 0x01;
2223
2224 if (gas_server_register(wpa_s->gas_server, adv_proto_id,
2225 sizeof(adv_proto_id), wpas_dpp_gas_req_handler,
2226 wpas_dpp_gas_status_handler, wpa_s) < 0)
2227 return -1;
Hai Shalom021b0b52019-04-10 11:17:58 -07002228 wpa_s->dpp = dpp_global_init();
2229 return wpa_s->dpp ? 0 : -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002230}
2231
2232
2233void wpas_dpp_deinit(struct wpa_supplicant *wpa_s)
2234{
2235#ifdef CONFIG_TESTING_OPTIONS
2236 os_free(wpa_s->dpp_config_obj_override);
2237 wpa_s->dpp_config_obj_override = NULL;
2238 os_free(wpa_s->dpp_discovery_override);
2239 wpa_s->dpp_discovery_override = NULL;
2240 os_free(wpa_s->dpp_groups_override);
2241 wpa_s->dpp_groups_override = NULL;
2242 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
2243#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalom021b0b52019-04-10 11:17:58 -07002244 if (!wpa_s->dpp)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002245 return;
Hai Shalom021b0b52019-04-10 11:17:58 -07002246 dpp_global_clear(wpa_s->dpp);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002247 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002248 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002249 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
2250 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07002251#ifdef CONFIG_DPP2
2252 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL);
2253 dpp_pfs_free(wpa_s->dpp_pfs);
2254 wpa_s->dpp_pfs = NULL;
2255#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002256 offchannel_send_action_done(wpa_s);
2257 wpas_dpp_listen_stop(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002258 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002259 wpas_dpp_pkex_remove(wpa_s, "*");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002260 os_memset(wpa_s->dpp_intro_bssid, 0, ETH_ALEN);
2261 os_free(wpa_s->dpp_configurator_params);
2262 wpa_s->dpp_configurator_params = NULL;
2263}