blob: 30ef5db19908a54a4836c2ad2e0e98560e6964f2 [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"
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
Roshan Pius3a1667e2018-07-03 15:17:14 -070092static void wpas_dpp_auth_resp_retry_timeout(void *eloop_ctx, void *timeout_ctx)
93{
94 struct wpa_supplicant *wpa_s = eloop_ctx;
95 struct dpp_authentication *auth = wpa_s->dpp_auth;
96
97 if (!auth || !auth->resp_msg)
98 return;
99
100 wpa_printf(MSG_DEBUG,
101 "DPP: Retry Authentication Response after timeout");
102 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
103 " freq=%u type=%d",
104 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
105 DPP_PA_AUTHENTICATION_RESP);
106 offchannel_send_action(wpa_s, auth->curr_freq, auth->peer_mac_addr,
107 wpa_s->own_addr, broadcast,
108 wpabuf_head(auth->resp_msg),
109 wpabuf_len(auth->resp_msg),
110 500, wpas_dpp_tx_status, 0);
111}
112
113
114static void wpas_dpp_auth_resp_retry(struct wpa_supplicant *wpa_s)
115{
116 struct dpp_authentication *auth = wpa_s->dpp_auth;
117 unsigned int wait_time, max_tries;
118
119 if (!auth || !auth->resp_msg)
120 return;
121
122 if (wpa_s->dpp_resp_max_tries)
123 max_tries = wpa_s->dpp_resp_max_tries;
124 else
125 max_tries = 5;
126 auth->auth_resp_tries++;
127 if (auth->auth_resp_tries >= max_tries) {
128 wpa_printf(MSG_INFO, "DPP: No confirm received from initiator - stopping exchange");
129 offchannel_send_action_done(wpa_s);
130 dpp_auth_deinit(wpa_s->dpp_auth);
131 wpa_s->dpp_auth = NULL;
132 return;
133 }
134
135 if (wpa_s->dpp_resp_retry_time)
136 wait_time = wpa_s->dpp_resp_retry_time;
137 else
138 wait_time = 1000;
139 wpa_printf(MSG_DEBUG,
140 "DPP: Schedule retransmission of Authentication Response frame in %u ms",
141 wait_time);
142 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
143 eloop_register_timeout(wait_time / 1000,
144 (wait_time % 1000) * 1000,
145 wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
146}
147
148
Hai Shalom021b0b52019-04-10 11:17:58 -0700149static void wpas_dpp_try_to_connect(struct wpa_supplicant *wpa_s)
150{
151 wpa_printf(MSG_DEBUG, "DPP: Trying to connect to the new network");
152 wpa_s->disconnected = 0;
153 wpa_s->reassociate = 1;
154 wpa_s->scan_runs = 0;
155 wpa_s->normal_scans = 0;
156 wpa_supplicant_cancel_sched_scan(wpa_s);
157 wpa_supplicant_req_scan(wpa_s, 0, 0);
158}
159
160
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700161static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
162 unsigned int freq, const u8 *dst,
163 const u8 *src, const u8 *bssid,
164 const u8 *data, size_t data_len,
165 enum offchannel_send_action_result result)
166{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700167 const char *res_txt;
168 struct dpp_authentication *auth = wpa_s->dpp_auth;
169
170 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
171 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
172 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700173 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
Roshan Pius3a1667e2018-07-03 15:17:14 -0700174 " result=%s", freq, MAC2STR(dst), res_txt);
175 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
176 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700177
178 if (!wpa_s->dpp_auth) {
179 wpa_printf(MSG_DEBUG,
180 "DPP: Ignore TX status since there is no ongoing authentication exchange");
181 return;
182 }
183
Hai Shalom021b0b52019-04-10 11:17:58 -0700184#ifdef CONFIG_DPP2
185 if (auth->connect_on_tx_status) {
186 wpa_printf(MSG_DEBUG,
187 "DPP: Try to connect after completed configuration result");
188 wpas_dpp_try_to_connect(wpa_s);
189 dpp_auth_deinit(wpa_s->dpp_auth);
190 wpa_s->dpp_auth = NULL;
191 return;
192 }
193#endif /* CONFIG_DPP2 */
194
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700195 if (wpa_s->dpp_auth->remove_on_tx_status) {
196 wpa_printf(MSG_DEBUG,
197 "DPP: Terminate authentication exchange due to an earlier error");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700198 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700199 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700200 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
201 NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700202 offchannel_send_action_done(wpa_s);
203 dpp_auth_deinit(wpa_s->dpp_auth);
204 wpa_s->dpp_auth = NULL;
205 return;
206 }
207
208 if (wpa_s->dpp_auth_ok_on_ack)
209 wpas_dpp_auth_success(wpa_s, 1);
210
211 if (!is_broadcast_ether_addr(dst) &&
212 result != OFFCHANNEL_SEND_ACTION_SUCCESS) {
213 wpa_printf(MSG_DEBUG,
214 "DPP: Unicast DPP Action frame was not ACKed");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700215 if (auth->waiting_auth_resp) {
216 /* In case of DPP Authentication Request frame, move to
217 * the next channel immediately. */
218 offchannel_send_action_done(wpa_s);
219 wpas_dpp_auth_init_next(wpa_s);
220 return;
221 }
222 if (auth->waiting_auth_conf) {
223 wpas_dpp_auth_resp_retry(wpa_s);
224 return;
225 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700226 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700227
228 if (!is_broadcast_ether_addr(dst) && auth->waiting_auth_resp &&
229 result == OFFCHANNEL_SEND_ACTION_SUCCESS) {
230 /* Allow timeout handling to stop iteration if no response is
231 * received from a peer that has ACKed a request. */
232 auth->auth_req_ack = 1;
233 }
234
235 if (!wpa_s->dpp_auth_ok_on_ack && wpa_s->dpp_auth->neg_freq > 0 &&
236 wpa_s->dpp_auth->curr_freq != wpa_s->dpp_auth->neg_freq) {
237 wpa_printf(MSG_DEBUG,
238 "DPP: Move from curr_freq %u MHz to neg_freq %u MHz for response",
239 wpa_s->dpp_auth->curr_freq,
240 wpa_s->dpp_auth->neg_freq);
241 offchannel_send_action_done(wpa_s);
242 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->neg_freq);
243 }
244
245 if (wpa_s->dpp_auth_ok_on_ack)
246 wpa_s->dpp_auth_ok_on_ack = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700247}
248
249
250static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx)
251{
252 struct wpa_supplicant *wpa_s = eloop_ctx;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700253 struct dpp_authentication *auth = wpa_s->dpp_auth;
254 unsigned int freq;
255 struct os_reltime now, diff;
256 unsigned int wait_time, diff_ms;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700257
Roshan Pius3a1667e2018-07-03 15:17:14 -0700258 if (!auth || !auth->waiting_auth_resp)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700259 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700260
261 wait_time = wpa_s->dpp_resp_wait_time ?
262 wpa_s->dpp_resp_wait_time : 2000;
263 os_get_reltime(&now);
264 os_reltime_sub(&now, &wpa_s->dpp_last_init, &diff);
265 diff_ms = diff.sec * 1000 + diff.usec / 1000;
266 wpa_printf(MSG_DEBUG,
267 "DPP: Reply wait timeout - wait_time=%u diff_ms=%u",
268 wait_time, diff_ms);
269
270 if (auth->auth_req_ack && diff_ms >= wait_time) {
271 /* Peer ACK'ed Authentication Request frame, but did not reply
272 * with Authentication Response frame within two seconds. */
273 wpa_printf(MSG_INFO,
274 "DPP: No response received from responder - stopping initiation attempt");
275 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -0800276 wpas_notify_dpp_timeout(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700277 offchannel_send_action_done(wpa_s);
278 wpas_dpp_listen_stop(wpa_s);
279 dpp_auth_deinit(auth);
280 wpa_s->dpp_auth = NULL;
281 return;
282 }
283
284 if (diff_ms >= wait_time) {
285 /* Authentication Request frame was not ACK'ed and no reply
286 * was receiving within two seconds. */
287 wpa_printf(MSG_DEBUG,
288 "DPP: Continue Initiator channel iteration");
289 offchannel_send_action_done(wpa_s);
290 wpas_dpp_listen_stop(wpa_s);
291 wpas_dpp_auth_init_next(wpa_s);
292 return;
293 }
294
295 /* Driver did not support 2000 ms long wait_time with TX command, so
296 * schedule listen operation to continue waiting for the response.
297 *
298 * DPP listen operations continue until stopped, so simply schedule a
299 * new call to this function at the point when the two second reply
300 * wait has expired. */
301 wait_time -= diff_ms;
302
303 freq = auth->curr_freq;
304 if (auth->neg_freq > 0)
305 freq = auth->neg_freq;
306 wpa_printf(MSG_DEBUG,
307 "DPP: Continue reply wait on channel %u MHz for %u ms",
308 freq, wait_time);
309 wpa_s->dpp_in_response_listen = 1;
310 wpas_dpp_listen_start(wpa_s, freq);
311
312 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
313 wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700314}
315
316
317static void wpas_dpp_set_testing_options(struct wpa_supplicant *wpa_s,
318 struct dpp_authentication *auth)
319{
320#ifdef CONFIG_TESTING_OPTIONS
321 if (wpa_s->dpp_config_obj_override)
322 auth->config_obj_override =
323 os_strdup(wpa_s->dpp_config_obj_override);
324 if (wpa_s->dpp_discovery_override)
325 auth->discovery_override =
326 os_strdup(wpa_s->dpp_discovery_override);
327 if (wpa_s->dpp_groups_override)
328 auth->groups_override =
329 os_strdup(wpa_s->dpp_groups_override);
330 auth->ignore_netaccesskey_mismatch =
331 wpa_s->dpp_ignore_netaccesskey_mismatch;
332#endif /* CONFIG_TESTING_OPTIONS */
333}
334
335
Roshan Pius3a1667e2018-07-03 15:17:14 -0700336static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx)
337{
338 struct wpa_supplicant *wpa_s = eloop_ctx;
339
340 if (!wpa_s->dpp_auth)
341 return;
342 wpa_printf(MSG_DEBUG, "DPP: Retry initiation after timeout");
343 wpas_dpp_auth_init_next(wpa_s);
344}
345
346
347static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s)
348{
349 struct dpp_authentication *auth = wpa_s->dpp_auth;
350 const u8 *dst;
351 unsigned int wait_time, max_wait_time, freq, max_tries, used;
352 struct os_reltime now, diff;
353
354 wpa_s->dpp_in_response_listen = 0;
355 if (!auth)
356 return -1;
357
358 if (auth->freq_idx == 0)
359 os_get_reltime(&wpa_s->dpp_init_iter_start);
360
361 if (auth->freq_idx >= auth->num_freq) {
362 auth->num_freq_iters++;
363 if (wpa_s->dpp_init_max_tries)
364 max_tries = wpa_s->dpp_init_max_tries;
365 else
366 max_tries = 5;
367 if (auth->num_freq_iters >= max_tries || auth->auth_req_ack) {
368 wpa_printf(MSG_INFO,
369 "DPP: No response received from responder - stopping initiation attempt");
370 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -0800371 wpas_notify_dpp_timeout(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700372 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout,
373 wpa_s, NULL);
374 offchannel_send_action_done(wpa_s);
375 dpp_auth_deinit(wpa_s->dpp_auth);
376 wpa_s->dpp_auth = NULL;
377 return -1;
378 }
379 auth->freq_idx = 0;
380 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
381 if (wpa_s->dpp_init_retry_time)
382 wait_time = wpa_s->dpp_init_retry_time;
383 else
384 wait_time = 10000;
385 os_get_reltime(&now);
386 os_reltime_sub(&now, &wpa_s->dpp_init_iter_start, &diff);
387 used = diff.sec * 1000 + diff.usec / 1000;
388 if (used > wait_time)
389 wait_time = 0;
390 else
391 wait_time -= used;
392 wpa_printf(MSG_DEBUG, "DPP: Next init attempt in %u ms",
393 wait_time);
394 eloop_register_timeout(wait_time / 1000,
395 (wait_time % 1000) * 1000,
396 wpas_dpp_init_timeout, wpa_s,
397 NULL);
398 return 0;
399 }
400 freq = auth->freq[auth->freq_idx++];
401 auth->curr_freq = freq;
402
403 if (is_zero_ether_addr(auth->peer_bi->mac_addr))
404 dst = broadcast;
405 else
406 dst = auth->peer_bi->mac_addr;
407 wpa_s->dpp_auth_ok_on_ack = 0;
408 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
409 wait_time = wpa_s->max_remain_on_chan;
410 max_wait_time = wpa_s->dpp_resp_wait_time ?
411 wpa_s->dpp_resp_wait_time : 2000;
412 if (wait_time > max_wait_time)
413 wait_time = max_wait_time;
414 wait_time += 10; /* give the driver some extra time to complete */
415 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
416 wpas_dpp_reply_wait_timeout,
417 wpa_s, NULL);
418 wait_time -= 10;
419 if (auth->neg_freq > 0 && freq != auth->neg_freq) {
420 wpa_printf(MSG_DEBUG,
421 "DPP: Initiate on %u MHz and move to neg_freq %u MHz for response",
422 freq, auth->neg_freq);
423 }
424 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
425 MAC2STR(dst), freq, DPP_PA_AUTHENTICATION_REQ);
426 auth->auth_req_ack = 0;
427 os_get_reltime(&wpa_s->dpp_last_init);
428 return offchannel_send_action(wpa_s, freq, dst,
429 wpa_s->own_addr, broadcast,
430 wpabuf_head(auth->req_msg),
431 wpabuf_len(auth->req_msg),
432 wait_time, wpas_dpp_tx_status, 0);
433}
434
435
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700436int wpas_dpp_auth_init(struct wpa_supplicant *wpa_s, const char *cmd)
437{
438 const char *pos;
439 struct dpp_bootstrap_info *peer_bi, *own_bi = NULL;
Hai Shalom81f62d82019-07-22 12:10:00 -0700440 struct dpp_authentication *auth;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700441 u8 allowed_roles = DPP_CAPAB_CONFIGURATOR;
442 unsigned int neg_freq = 0;
Hai Shalom81f62d82019-07-22 12:10:00 -0700443 int tcp = 0;
444#ifdef CONFIG_DPP2
445 int tcp_port = DPP_TCP_PORT;
446 struct hostapd_ip_addr ipaddr;
447 char *addr;
448#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700449
450 wpa_s->dpp_gas_client = 0;
451
452 pos = os_strstr(cmd, " peer=");
453 if (!pos)
454 return -1;
455 pos += 6;
Hai Shalom021b0b52019-04-10 11:17:58 -0700456 peer_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700457 if (!peer_bi) {
458 wpa_printf(MSG_INFO,
459 "DPP: Could not find bootstrapping info for the identified peer");
460 return -1;
461 }
462
Hai Shalom81f62d82019-07-22 12:10:00 -0700463#ifdef CONFIG_DPP2
464 pos = os_strstr(cmd, " tcp_port=");
465 if (pos) {
466 pos += 10;
467 tcp_port = atoi(pos);
468 }
469
470 addr = get_param(cmd, " tcp_addr=");
471 if (addr) {
472 int res;
473
474 res = hostapd_parse_ip_addr(addr, &ipaddr);
475 os_free(addr);
476 if (res)
477 return -1;
478 tcp = 1;
479 }
480#endif /* CONFIG_DPP2 */
481
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700482 pos = os_strstr(cmd, " own=");
483 if (pos) {
484 pos += 5;
Hai Shalom021b0b52019-04-10 11:17:58 -0700485 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700486 if (!own_bi) {
487 wpa_printf(MSG_INFO,
488 "DPP: Could not find bootstrapping info for the identified local entry");
489 return -1;
490 }
491
492 if (peer_bi->curve != own_bi->curve) {
493 wpa_printf(MSG_INFO,
494 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
495 peer_bi->curve->name, own_bi->curve->name);
496 return -1;
497 }
498 }
499
500 pos = os_strstr(cmd, " role=");
501 if (pos) {
502 pos += 6;
503 if (os_strncmp(pos, "configurator", 12) == 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700504 allowed_roles = DPP_CAPAB_CONFIGURATOR;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700505 else if (os_strncmp(pos, "enrollee", 8) == 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700506 allowed_roles = DPP_CAPAB_ENROLLEE;
507 else if (os_strncmp(pos, "either", 6) == 0)
508 allowed_roles = DPP_CAPAB_CONFIGURATOR |
509 DPP_CAPAB_ENROLLEE;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700510 else
511 goto fail;
512 }
513
514 pos = os_strstr(cmd, " netrole=");
515 if (pos) {
516 pos += 9;
517 wpa_s->dpp_netrole_ap = os_strncmp(pos, "ap", 2) == 0;
518 }
519
Roshan Pius3a1667e2018-07-03 15:17:14 -0700520 pos = os_strstr(cmd, " neg_freq=");
521 if (pos)
522 neg_freq = atoi(pos + 10);
523
Hai Shalom81f62d82019-07-22 12:10:00 -0700524 if (!tcp && wpa_s->dpp_auth) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700525 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700526 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700527 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
528 NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700529 offchannel_send_action_done(wpa_s);
530 dpp_auth_deinit(wpa_s->dpp_auth);
Hai Shalom74f70d42019-02-11 14:42:39 -0800531 wpa_s->dpp_auth = NULL;
Hai Shalom81f62d82019-07-22 12:10:00 -0700532 }
533
534 auth = dpp_auth_init(wpa_s, peer_bi, own_bi, allowed_roles, neg_freq,
535 wpa_s->hw.modes, wpa_s->hw.num_modes);
536 if (!auth)
537 goto fail;
538 wpas_dpp_set_testing_options(wpa_s, auth);
539 if (dpp_set_configurator(wpa_s->dpp, wpa_s, auth, cmd) < 0) {
540 dpp_auth_deinit(auth);
Hai Shalom74f70d42019-02-11 14:42:39 -0800541 goto fail;
542 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700543
Hai Shalom81f62d82019-07-22 12:10:00 -0700544 auth->neg_freq = neg_freq;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700545
Roshan Pius3a1667e2018-07-03 15:17:14 -0700546 if (!is_zero_ether_addr(peer_bi->mac_addr))
Hai Shalom81f62d82019-07-22 12:10:00 -0700547 os_memcpy(auth->peer_mac_addr, peer_bi->mac_addr, ETH_ALEN);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700548
Hai Shalom81f62d82019-07-22 12:10:00 -0700549#ifdef CONFIG_DPP2
550 if (tcp)
551 return dpp_tcp_init(wpa_s->dpp, auth, &ipaddr, tcp_port);
552#endif /* CONFIG_DPP2 */
553
554 wpa_s->dpp_auth = auth;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700555 return wpas_dpp_auth_init_next(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700556fail:
557 return -1;
558}
559
560
561struct wpas_dpp_listen_work {
562 unsigned int freq;
563 unsigned int duration;
564 struct wpabuf *probe_resp_ie;
565};
566
567
568static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work *lwork)
569{
570 if (!lwork)
571 return;
572 os_free(lwork);
573}
574
575
576static void wpas_dpp_listen_work_done(struct wpa_supplicant *wpa_s)
577{
578 struct wpas_dpp_listen_work *lwork;
579
580 if (!wpa_s->dpp_listen_work)
581 return;
582
583 lwork = wpa_s->dpp_listen_work->ctx;
584 wpas_dpp_listen_work_free(lwork);
585 radio_work_done(wpa_s->dpp_listen_work);
586 wpa_s->dpp_listen_work = NULL;
587}
588
589
590static void dpp_start_listen_cb(struct wpa_radio_work *work, int deinit)
591{
592 struct wpa_supplicant *wpa_s = work->wpa_s;
593 struct wpas_dpp_listen_work *lwork = work->ctx;
594
595 if (deinit) {
596 if (work->started) {
597 wpa_s->dpp_listen_work = NULL;
598 wpas_dpp_listen_stop(wpa_s);
599 }
600 wpas_dpp_listen_work_free(lwork);
601 return;
602 }
603
604 wpa_s->dpp_listen_work = work;
605
606 wpa_s->dpp_pending_listen_freq = lwork->freq;
607
608 if (wpa_drv_remain_on_channel(wpa_s, lwork->freq,
609 wpa_s->max_remain_on_chan) < 0) {
610 wpa_printf(MSG_DEBUG,
611 "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
612 lwork->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -0800613 wpa_s->dpp_listen_freq = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700614 wpas_dpp_listen_work_done(wpa_s);
615 wpa_s->dpp_pending_listen_freq = 0;
616 return;
617 }
618 wpa_s->off_channel_freq = 0;
619 wpa_s->roc_waiting_drv_freq = lwork->freq;
620}
621
622
623static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
624 unsigned int freq)
625{
626 struct wpas_dpp_listen_work *lwork;
627
628 if (wpa_s->dpp_listen_work) {
629 wpa_printf(MSG_DEBUG,
630 "DPP: Reject start_listen since dpp_listen_work already exists");
631 return -1;
632 }
633
634 if (wpa_s->dpp_listen_freq)
635 wpas_dpp_listen_stop(wpa_s);
636 wpa_s->dpp_listen_freq = freq;
637
638 lwork = os_zalloc(sizeof(*lwork));
639 if (!lwork)
640 return -1;
641 lwork->freq = freq;
642
643 if (radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb,
644 lwork) < 0) {
645 wpas_dpp_listen_work_free(lwork);
646 return -1;
647 }
648
649 return 0;
650}
651
652
653int wpas_dpp_listen(struct wpa_supplicant *wpa_s, const char *cmd)
654{
655 int freq;
656
657 freq = atoi(cmd);
658 if (freq <= 0)
659 return -1;
660
661 if (os_strstr(cmd, " role=configurator"))
662 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR;
663 else if (os_strstr(cmd, " role=enrollee"))
664 wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
665 else
666 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
667 DPP_CAPAB_ENROLLEE;
668 wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
669 wpa_s->dpp_netrole_ap = os_strstr(cmd, " netrole=ap") != NULL;
670 if (wpa_s->dpp_listen_freq == (unsigned int) freq) {
671 wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz",
672 freq);
673 return 0;
674 }
675
676 return wpas_dpp_listen_start(wpa_s, freq);
677}
678
679
680void wpas_dpp_listen_stop(struct wpa_supplicant *wpa_s)
681{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700682 wpa_s->dpp_in_response_listen = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700683 if (!wpa_s->dpp_listen_freq)
684 return;
685
686 wpa_printf(MSG_DEBUG, "DPP: Stop listen on %u MHz",
687 wpa_s->dpp_listen_freq);
688 wpa_drv_cancel_remain_on_channel(wpa_s);
689 wpa_s->dpp_listen_freq = 0;
690 wpas_dpp_listen_work_done(wpa_s);
691}
692
693
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700694void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
695 unsigned int freq)
696{
697 wpas_dpp_listen_work_done(wpa_s);
698
Roshan Pius3a1667e2018-07-03 15:17:14 -0700699 if (wpa_s->dpp_auth && wpa_s->dpp_in_response_listen) {
700 unsigned int new_freq;
701
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700702 /* Continue listen with a new remain-on-channel */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700703 if (wpa_s->dpp_auth->neg_freq > 0)
704 new_freq = wpa_s->dpp_auth->neg_freq;
705 else
706 new_freq = wpa_s->dpp_auth->curr_freq;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700707 wpa_printf(MSG_DEBUG,
708 "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
Roshan Pius3a1667e2018-07-03 15:17:14 -0700709 new_freq);
710 wpas_dpp_listen_start(wpa_s, new_freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700711 return;
712 }
713
714 if (wpa_s->dpp_listen_freq) {
715 /* Continue listen with a new remain-on-channel */
716 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_listen_freq);
717 }
718}
719
720
721static void wpas_dpp_rx_auth_req(struct wpa_supplicant *wpa_s, const u8 *src,
722 const u8 *hdr, const u8 *buf, size_t len,
723 unsigned int freq)
724{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700725 const u8 *r_bootstrap, *i_bootstrap;
726 u16 r_bootstrap_len, i_bootstrap_len;
Hai Shalom021b0b52019-04-10 11:17:58 -0700727 struct dpp_bootstrap_info *own_bi = NULL, *peer_bi = NULL;
728
729 if (!wpa_s->dpp)
730 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700731
732 wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR,
733 MAC2STR(src));
734
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700735 r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
736 &r_bootstrap_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700737 if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
738 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
739 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700740 return;
741 }
742 wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
743 r_bootstrap, r_bootstrap_len);
744
745 i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH,
746 &i_bootstrap_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700747 if (!i_bootstrap || i_bootstrap_len != SHA256_MAC_LEN) {
748 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
749 "Missing or invalid required Initiator Bootstrapping Key Hash attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700750 return;
751 }
752 wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash",
753 i_bootstrap, i_bootstrap_len);
754
755 /* Try to find own and peer bootstrapping key matches based on the
756 * received hash values */
Hai Shalom021b0b52019-04-10 11:17:58 -0700757 dpp_bootstrap_find_pair(wpa_s->dpp, i_bootstrap, r_bootstrap,
758 &own_bi, &peer_bi);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700759 if (!own_bi) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700760 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
761 "No matching own bootstrapping key found - ignore message");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700762 return;
763 }
764
765 if (wpa_s->dpp_auth) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700766 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
767 "Already in DPP authentication exchange - ignore new one");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700768 return;
769 }
770
771 wpa_s->dpp_gas_client = 0;
772 wpa_s->dpp_auth_ok_on_ack = 0;
773 wpa_s->dpp_auth = dpp_auth_req_rx(wpa_s, wpa_s->dpp_allowed_roles,
774 wpa_s->dpp_qr_mutual,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700775 peer_bi, own_bi, freq, hdr, buf, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700776 if (!wpa_s->dpp_auth) {
777 wpa_printf(MSG_DEBUG, "DPP: No response generated");
778 return;
779 }
780 wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
Hai Shalom021b0b52019-04-10 11:17:58 -0700781 if (dpp_set_configurator(wpa_s->dpp, wpa_s, wpa_s->dpp_auth,
782 wpa_s->dpp_configurator_params) < 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -0800783 dpp_auth_deinit(wpa_s->dpp_auth);
784 wpa_s->dpp_auth = NULL;
785 return;
786 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700787 os_memcpy(wpa_s->dpp_auth->peer_mac_addr, src, ETH_ALEN);
788
Roshan Pius3a1667e2018-07-03 15:17:14 -0700789 if (wpa_s->dpp_listen_freq &&
790 wpa_s->dpp_listen_freq != wpa_s->dpp_auth->curr_freq) {
791 wpa_printf(MSG_DEBUG,
792 "DPP: Stop listen on %u MHz to allow response on the request %u MHz",
793 wpa_s->dpp_listen_freq, wpa_s->dpp_auth->curr_freq);
794 wpas_dpp_listen_stop(wpa_s);
795 }
796
797 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
798 MAC2STR(src), wpa_s->dpp_auth->curr_freq,
799 DPP_PA_AUTHENTICATION_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700800 offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq,
801 src, wpa_s->own_addr, broadcast,
802 wpabuf_head(wpa_s->dpp_auth->resp_msg),
803 wpabuf_len(wpa_s->dpp_auth->resp_msg),
804 500, wpas_dpp_tx_status, 0);
805}
806
807
808static void wpas_dpp_start_gas_server(struct wpa_supplicant *wpa_s)
809{
810 /* TODO: stop wait and start ROC */
811}
812
813
814static struct wpa_ssid * wpas_dpp_add_network(struct wpa_supplicant *wpa_s,
815 struct dpp_authentication *auth)
816{
817 struct wpa_ssid *ssid;
818
Hai Shalom021b0b52019-04-10 11:17:58 -0700819#ifdef CONFIG_DPP2
820 if (auth->akm == DPP_AKM_SAE) {
821#ifdef CONFIG_SAE
822 struct wpa_driver_capa capa;
823 int res;
824
825 res = wpa_drv_get_capa(wpa_s, &capa);
826 if (res == 0 &&
827 !(capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) &&
828 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
829 wpa_printf(MSG_DEBUG,
830 "DPP: SAE not supported by the driver");
831 return NULL;
832 }
833#else /* CONFIG_SAE */
834 wpa_printf(MSG_DEBUG, "DPP: SAE not supported in the build");
835 return NULL;
836#endif /* CONFIG_SAE */
837 }
838#endif /* CONFIG_DPP2 */
839
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700840 ssid = wpa_config_add_network(wpa_s->conf);
841 if (!ssid)
842 return NULL;
843 wpas_notify_network_added(wpa_s, ssid);
844 wpa_config_set_network_defaults(ssid);
845 ssid->disabled = 1;
846
847 ssid->ssid = os_malloc(auth->ssid_len);
848 if (!ssid->ssid)
849 goto fail;
850 os_memcpy(ssid->ssid, auth->ssid, auth->ssid_len);
851 ssid->ssid_len = auth->ssid_len;
852
853 if (auth->connector) {
854 ssid->key_mgmt = WPA_KEY_MGMT_DPP;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700855 ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700856 ssid->dpp_connector = os_strdup(auth->connector);
857 if (!ssid->dpp_connector)
858 goto fail;
859 }
860
861 if (auth->c_sign_key) {
862 ssid->dpp_csign = os_malloc(wpabuf_len(auth->c_sign_key));
863 if (!ssid->dpp_csign)
864 goto fail;
865 os_memcpy(ssid->dpp_csign, wpabuf_head(auth->c_sign_key),
866 wpabuf_len(auth->c_sign_key));
867 ssid->dpp_csign_len = wpabuf_len(auth->c_sign_key);
868 }
869
870 if (auth->net_access_key) {
871 ssid->dpp_netaccesskey =
872 os_malloc(wpabuf_len(auth->net_access_key));
873 if (!ssid->dpp_netaccesskey)
874 goto fail;
875 os_memcpy(ssid->dpp_netaccesskey,
876 wpabuf_head(auth->net_access_key),
877 wpabuf_len(auth->net_access_key));
878 ssid->dpp_netaccesskey_len = wpabuf_len(auth->net_access_key);
879 ssid->dpp_netaccesskey_expiry = auth->net_access_key_expiry;
880 }
881
Hai Shalom021b0b52019-04-10 11:17:58 -0700882 if (!auth->connector || dpp_akm_psk(auth->akm) ||
883 dpp_akm_sae(auth->akm)) {
884 if (!auth->connector)
885 ssid->key_mgmt = 0;
886 if (dpp_akm_psk(auth->akm))
Roshan Pius3a1667e2018-07-03 15:17:14 -0700887 ssid->key_mgmt |= WPA_KEY_MGMT_PSK |
888 WPA_KEY_MGMT_PSK_SHA256 | WPA_KEY_MGMT_FT_PSK;
Hai Shalom021b0b52019-04-10 11:17:58 -0700889 if (dpp_akm_sae(auth->akm))
Roshan Pius3a1667e2018-07-03 15:17:14 -0700890 ssid->key_mgmt |= WPA_KEY_MGMT_SAE |
891 WPA_KEY_MGMT_FT_SAE;
892 ssid->ieee80211w = MGMT_FRAME_PROTECTION_OPTIONAL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700893 if (auth->passphrase[0]) {
894 if (wpa_config_set_quoted(ssid, "psk",
895 auth->passphrase) < 0)
896 goto fail;
897 wpa_config_update_psk(ssid);
898 ssid->export_keys = 1;
899 } else {
900 ssid->psk_set = auth->psk_set;
901 os_memcpy(ssid->psk, auth->psk, PMK_LEN);
902 }
903 }
904
905 return ssid;
906fail:
907 wpas_notify_network_removed(wpa_s, ssid);
908 wpa_config_remove_network(wpa_s->conf, ssid->id);
909 return NULL;
910}
911
912
Hai Shalom021b0b52019-04-10 11:17:58 -0700913static int wpas_dpp_process_config(struct wpa_supplicant *wpa_s,
914 struct dpp_authentication *auth)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700915{
916 struct wpa_ssid *ssid;
917
918 if (wpa_s->conf->dpp_config_processing < 1)
Hai Shalom021b0b52019-04-10 11:17:58 -0700919 return 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700920
921 ssid = wpas_dpp_add_network(wpa_s, auth);
922 if (!ssid)
Hai Shalom021b0b52019-04-10 11:17:58 -0700923 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700924
925 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_NETWORK_ID "%d", ssid->id);
Hai Shalom59532852018-12-07 10:32:58 -0800926
Hai Shalom706f99b2019-01-08 16:23:37 -0800927 wpas_notify_dpp_config_received(wpa_s, ssid);
Hai Shalom59532852018-12-07 10:32:58 -0800928
Hai Shalom021b0b52019-04-10 11:17:58 -0700929 if (wpa_s->conf->dpp_config_processing == 2)
930 ssid->disabled = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700931
Hai Shalom021b0b52019-04-10 11:17:58 -0700932#ifndef CONFIG_NO_CONFIG_WRITE
933 if (wpa_s->conf->update_config &&
934 wpa_config_write(wpa_s->confname, wpa_s->conf))
935 wpa_printf(MSG_DEBUG, "DPP: Failed to update configuration");
936#endif /* CONFIG_NO_CONFIG_WRITE */
937
938 if (wpa_s->conf->dpp_config_processing < 2)
939 return 0;
940
941#ifdef CONFIG_DPP2
942 if (auth->peer_version >= 2) {
943 wpa_printf(MSG_DEBUG,
944 "DPP: Postpone connection attempt to wait for completion of DPP Configuration Result");
945 auth->connect_on_tx_status = 1;
946 return 0;
947 }
948#endif /* CONFIG_DPP2 */
949
950 wpas_dpp_try_to_connect(wpa_s);
951 return 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700952}
953
954
Hai Shalom021b0b52019-04-10 11:17:58 -0700955static int wpas_dpp_handle_config_obj(struct wpa_supplicant *wpa_s,
956 struct dpp_authentication *auth)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700957{
958 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
959 if (auth->ssid_len)
960 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s",
961 wpa_ssid_txt(auth->ssid, auth->ssid_len));
962 if (auth->connector) {
963 /* TODO: Save the Connector and consider using a command
964 * to fetch the value instead of sending an event with
965 * it. The Connector could end up being larger than what
966 * most clients are ready to receive as an event
967 * message. */
968 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONNECTOR "%s",
969 auth->connector);
970 }
971 if (auth->c_sign_key) {
972 char *hex;
973 size_t hexlen;
974
975 hexlen = 2 * wpabuf_len(auth->c_sign_key) + 1;
976 hex = os_malloc(hexlen);
977 if (hex) {
978 wpa_snprintf_hex(hex, hexlen,
979 wpabuf_head(auth->c_sign_key),
980 wpabuf_len(auth->c_sign_key));
981 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_C_SIGN_KEY "%s",
982 hex);
983 os_free(hex);
984 }
985 }
986 if (auth->net_access_key) {
987 char *hex;
988 size_t hexlen;
989
990 hexlen = 2 * wpabuf_len(auth->net_access_key) + 1;
991 hex = os_malloc(hexlen);
992 if (hex) {
993 wpa_snprintf_hex(hex, hexlen,
994 wpabuf_head(auth->net_access_key),
995 wpabuf_len(auth->net_access_key));
996 if (auth->net_access_key_expiry)
997 wpa_msg(wpa_s, MSG_INFO,
998 DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex,
999 (long unsigned)
1000 auth->net_access_key_expiry);
1001 else
1002 wpa_msg(wpa_s, MSG_INFO,
1003 DPP_EVENT_NET_ACCESS_KEY "%s", hex);
1004 os_free(hex);
1005 }
1006 }
1007
Hai Shalom021b0b52019-04-10 11:17:58 -07001008 return wpas_dpp_process_config(wpa_s, auth);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001009}
1010
1011
1012static void wpas_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token,
1013 enum gas_query_result result,
1014 const struct wpabuf *adv_proto,
1015 const struct wpabuf *resp, u16 status_code)
1016{
1017 struct wpa_supplicant *wpa_s = ctx;
1018 const u8 *pos;
1019 struct dpp_authentication *auth = wpa_s->dpp_auth;
Hai Shalom021b0b52019-04-10 11:17:58 -07001020 int res;
1021 enum dpp_status_error status = DPP_STATUS_CONFIG_REJECTED;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001022
Roshan Pius3a1667e2018-07-03 15:17:14 -07001023 wpa_s->dpp_gas_dialog_token = -1;
1024
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001025 if (!auth || !auth->auth_success) {
1026 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
1027 return;
1028 }
Hai Shalom74f70d42019-02-11 14:42:39 -08001029 if (result != GAS_QUERY_SUCCESS ||
1030 !resp || status_code != WLAN_STATUS_SUCCESS) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001031 wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed");
1032 goto fail;
1033 }
1034
1035 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto",
1036 adv_proto);
1037 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)",
1038 resp);
1039
1040 if (wpabuf_len(adv_proto) != 10 ||
1041 !(pos = wpabuf_head(adv_proto)) ||
1042 pos[0] != WLAN_EID_ADV_PROTO ||
1043 pos[1] != 8 ||
1044 pos[3] != WLAN_EID_VENDOR_SPECIFIC ||
1045 pos[4] != 5 ||
1046 WPA_GET_BE24(&pos[5]) != OUI_WFA ||
1047 pos[8] != 0x1a ||
1048 pos[9] != 1) {
1049 wpa_printf(MSG_DEBUG,
1050 "DPP: Not a DPP Advertisement Protocol ID");
1051 goto fail;
1052 }
1053
1054 if (dpp_conf_resp_rx(auth, resp) < 0) {
1055 wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed");
1056 goto fail;
1057 }
1058
Hai Shalom021b0b52019-04-10 11:17:58 -07001059 res = wpas_dpp_handle_config_obj(wpa_s, auth);
1060 if (res < 0)
1061 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001062
Hai Shalom021b0b52019-04-10 11:17:58 -07001063 status = DPP_STATUS_OK;
1064#ifdef CONFIG_TESTING_OPTIONS
1065 if (dpp_test == DPP_TEST_REJECT_CONFIG) {
1066 wpa_printf(MSG_INFO, "DPP: TESTING - Reject Config Object");
1067 status = DPP_STATUS_CONFIG_REJECTED;
1068 }
1069#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001070fail:
Hai Shalom021b0b52019-04-10 11:17:58 -07001071 if (status != DPP_STATUS_OK) {
1072 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1073 wpas_notify_dpp_configuration_failure(wpa_s);
1074 }
1075#ifdef CONFIG_DPP2
1076 if (auth->peer_version >= 2 &&
1077 auth->conf_resp_status == DPP_STATUS_OK) {
1078 struct wpabuf *msg;
1079
1080 wpa_printf(MSG_DEBUG, "DPP: Send DPP Configuration Result");
1081 msg = dpp_build_conf_result(auth, status);
1082 if (!msg)
1083 goto fail2;
1084
1085 wpa_msg(wpa_s, MSG_INFO,
1086 DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1087 MAC2STR(addr), auth->curr_freq,
1088 DPP_PA_CONFIGURATION_RESULT);
1089 offchannel_send_action(wpa_s, auth->curr_freq,
1090 addr, wpa_s->own_addr, broadcast,
1091 wpabuf_head(msg),
1092 wpabuf_len(msg),
1093 500, wpas_dpp_tx_status, 0);
1094 wpabuf_free(msg);
1095
1096 /* This exchange will be terminated in the TX status handler */
1097 return;
1098 }
1099fail2:
1100#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001101 dpp_auth_deinit(wpa_s->dpp_auth);
1102 wpa_s->dpp_auth = NULL;
1103}
1104
1105
1106static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
1107{
1108 struct dpp_authentication *auth = wpa_s->dpp_auth;
Hai Shalom021b0b52019-04-10 11:17:58 -07001109 struct wpabuf *buf;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001110 char json[100];
1111 int res;
1112
1113 wpa_s->dpp_gas_client = 1;
1114 os_snprintf(json, sizeof(json),
1115 "{\"name\":\"Test\","
1116 "\"wi-fi_tech\":\"infra\","
1117 "\"netRole\":\"%s\"}",
1118 wpa_s->dpp_netrole_ap ? "ap" : "sta");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001119#ifdef CONFIG_TESTING_OPTIONS
1120 if (dpp_test == DPP_TEST_INVALID_CONFIG_ATTR_OBJ_CONF_REQ) {
1121 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Config Attr");
1122 json[29] = 'k'; /* replace "infra" with "knfra" */
1123 }
1124#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001125 wpa_printf(MSG_DEBUG, "DPP: GAS Config Attributes: %s", json);
1126
1127 offchannel_send_action_done(wpa_s);
1128 wpas_dpp_listen_stop(wpa_s);
1129
Hai Shalom021b0b52019-04-10 11:17:58 -07001130 buf = dpp_build_conf_req(auth, json);
1131 if (!buf) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001132 wpa_printf(MSG_DEBUG,
1133 "DPP: No configuration request data available");
1134 return;
1135 }
1136
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001137 wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
1138 MAC2STR(auth->peer_mac_addr), auth->curr_freq);
1139
1140 res = gas_query_req(wpa_s->gas, auth->peer_mac_addr, auth->curr_freq,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001141 1, buf, wpas_dpp_gas_resp_cb, wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001142 if (res < 0) {
1143 wpa_msg(wpa_s, MSG_DEBUG, "GAS: Failed to send Query Request");
1144 wpabuf_free(buf);
1145 } else {
1146 wpa_printf(MSG_DEBUG,
1147 "DPP: GAS query started with dialog token %u", res);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001148 wpa_s->dpp_gas_dialog_token = res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001149 }
1150}
1151
1152
1153static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator)
1154{
1155 wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded");
1156 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d", initiator);
Hai Shalom706f99b2019-01-08 16:23:37 -08001157 wpas_notify_dpp_auth_success(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001158#ifdef CONFIG_TESTING_OPTIONS
1159 if (dpp_test == DPP_TEST_STOP_AT_AUTH_CONF) {
1160 wpa_printf(MSG_INFO,
1161 "DPP: TESTING - stop at Authentication Confirm");
1162 if (wpa_s->dpp_auth->configurator) {
1163 /* Prevent GAS response */
1164 wpa_s->dpp_auth->auth_success = 0;
1165 }
1166 return;
1167 }
1168#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001169
1170 if (wpa_s->dpp_auth->configurator)
1171 wpas_dpp_start_gas_server(wpa_s);
1172 else
1173 wpas_dpp_start_gas_client(wpa_s);
1174}
1175
1176
1177static void wpas_dpp_rx_auth_resp(struct wpa_supplicant *wpa_s, const u8 *src,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001178 const u8 *hdr, const u8 *buf, size_t len,
1179 unsigned int freq)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001180{
1181 struct dpp_authentication *auth = wpa_s->dpp_auth;
1182 struct wpabuf *msg;
1183
Roshan Pius3a1667e2018-07-03 15:17:14 -07001184 wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR
1185 " (freq %u MHz)", MAC2STR(src), freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001186
1187 if (!auth) {
1188 wpa_printf(MSG_DEBUG,
1189 "DPP: No DPP Authentication in progress - drop");
1190 return;
1191 }
1192
1193 if (!is_zero_ether_addr(auth->peer_mac_addr) &&
1194 os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1195 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1196 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1197 return;
1198 }
1199
1200 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
1201
Roshan Pius3a1667e2018-07-03 15:17:14 -07001202 if (auth->curr_freq != freq && auth->neg_freq == freq) {
1203 wpa_printf(MSG_DEBUG,
1204 "DPP: Responder accepted request for different negotiation channel");
1205 auth->curr_freq = freq;
1206 }
1207
1208 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001209 msg = dpp_auth_resp_rx(auth, hdr, buf, len);
1210 if (!msg) {
1211 if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) {
1212 wpa_printf(MSG_DEBUG,
1213 "DPP: Start wait for full response");
Hai Shalom706f99b2019-01-08 16:23:37 -08001214 wpas_notify_dpp_resp_pending(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001215 offchannel_send_action_done(wpa_s);
1216 wpas_dpp_listen_start(wpa_s, auth->curr_freq);
1217 return;
1218 }
1219 wpa_printf(MSG_DEBUG, "DPP: No confirm generated");
1220 return;
1221 }
1222 os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
1223
Roshan Pius3a1667e2018-07-03 15:17:14 -07001224 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1225 MAC2STR(src), auth->curr_freq, DPP_PA_AUTHENTICATION_CONF);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001226 offchannel_send_action(wpa_s, auth->curr_freq,
1227 src, wpa_s->own_addr, broadcast,
1228 wpabuf_head(msg), wpabuf_len(msg),
1229 500, wpas_dpp_tx_status, 0);
1230 wpabuf_free(msg);
1231 wpa_s->dpp_auth_ok_on_ack = 1;
1232}
1233
1234
1235static void wpas_dpp_rx_auth_conf(struct wpa_supplicant *wpa_s, const u8 *src,
1236 const u8 *hdr, const u8 *buf, size_t len)
1237{
1238 struct dpp_authentication *auth = wpa_s->dpp_auth;
1239
1240 wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR,
1241 MAC2STR(src));
1242
1243 if (!auth) {
1244 wpa_printf(MSG_DEBUG,
1245 "DPP: No DPP Authentication in progress - drop");
1246 return;
1247 }
1248
1249 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1250 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1251 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1252 return;
1253 }
1254
1255 if (dpp_auth_conf_rx(auth, hdr, buf, len) < 0) {
1256 wpa_printf(MSG_DEBUG, "DPP: Authentication failed");
Hai Shalom706f99b2019-01-08 16:23:37 -08001257 wpas_notify_dpp_auth_failure(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001258 return;
1259 }
1260
1261 wpas_dpp_auth_success(wpa_s, 0);
1262}
1263
1264
Hai Shalom021b0b52019-04-10 11:17:58 -07001265#ifdef CONFIG_DPP2
1266
1267static void wpas_dpp_config_result_wait_timeout(void *eloop_ctx,
1268 void *timeout_ctx)
1269{
1270 struct wpa_supplicant *wpa_s = eloop_ctx;
1271 struct dpp_authentication *auth = wpa_s->dpp_auth;
1272
1273 if (!auth || !auth->waiting_conf_result)
1274 return;
1275
1276 wpa_printf(MSG_DEBUG,
1277 "DPP: Timeout while waiting for Configuration Result");
1278 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1279 dpp_auth_deinit(auth);
1280 wpa_s->dpp_auth = NULL;
1281}
1282
1283
1284static void wpas_dpp_rx_conf_result(struct wpa_supplicant *wpa_s, const u8 *src,
1285 const u8 *hdr, const u8 *buf, size_t len)
1286{
1287 struct dpp_authentication *auth = wpa_s->dpp_auth;
1288 enum dpp_status_error status;
1289
1290 wpa_printf(MSG_DEBUG, "DPP: Configuration Result from " MACSTR,
1291 MAC2STR(src));
1292
1293 if (!auth || !auth->waiting_conf_result) {
1294 wpa_printf(MSG_DEBUG,
1295 "DPP: No DPP Configuration waiting for result - drop");
1296 return;
1297 }
1298
1299 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1300 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1301 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1302 return;
1303 }
1304
1305 status = dpp_conf_result_rx(auth, hdr, buf, len);
1306
1307 offchannel_send_action_done(wpa_s);
1308 wpas_dpp_listen_stop(wpa_s);
1309 if (status == DPP_STATUS_OK)
1310 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
1311 else
1312 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1313 dpp_auth_deinit(auth);
1314 wpa_s->dpp_auth = NULL;
1315 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL);
1316}
1317
Hai Shalom81f62d82019-07-22 12:10:00 -07001318
1319static int wpas_dpp_process_conf_obj(void *ctx,
1320 struct dpp_authentication *auth)
1321{
1322 struct wpa_supplicant *wpa_s = ctx;
1323
1324 return wpas_dpp_handle_config_obj(wpa_s, auth);
1325}
1326
Hai Shalom021b0b52019-04-10 11:17:58 -07001327#endif /* CONFIG_DPP2 */
1328
1329
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001330static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant *wpa_s,
1331 const u8 *src,
1332 const u8 *buf, size_t len)
1333{
1334 struct wpa_ssid *ssid;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001335 const u8 *connector, *trans_id, *status;
1336 u16 connector_len, trans_id_len, status_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001337 struct dpp_introduction intro;
1338 struct rsn_pmksa_cache_entry *entry;
1339 struct os_time now;
1340 struct os_reltime rnow;
1341 os_time_t expiry;
1342 unsigned int seconds;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001343 enum dpp_status_error res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001344
1345 wpa_printf(MSG_DEBUG, "DPP: Peer Discovery Response from " MACSTR,
1346 MAC2STR(src));
1347 if (is_zero_ether_addr(wpa_s->dpp_intro_bssid) ||
1348 os_memcmp(src, wpa_s->dpp_intro_bssid, ETH_ALEN) != 0) {
1349 wpa_printf(MSG_DEBUG, "DPP: Not waiting for response from "
1350 MACSTR " - drop", MAC2STR(src));
1351 return;
1352 }
1353 offchannel_send_action_done(wpa_s);
1354
1355 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1356 if (ssid == wpa_s->dpp_intro_network)
1357 break;
1358 }
1359 if (!ssid || !ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1360 !ssid->dpp_csign) {
1361 wpa_printf(MSG_DEBUG,
1362 "DPP: Profile not found for network introduction");
1363 return;
1364 }
1365
1366 trans_id = dpp_get_attr(buf, len, DPP_ATTR_TRANSACTION_ID,
1367 &trans_id_len);
1368 if (!trans_id || trans_id_len != 1) {
1369 wpa_printf(MSG_DEBUG,
1370 "DPP: Peer did not include Transaction ID");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001371 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1372 " fail=missing_transaction_id", MAC2STR(src));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001373 goto fail;
1374 }
1375 if (trans_id[0] != TRANSACTION_ID) {
1376 wpa_printf(MSG_DEBUG,
1377 "DPP: Ignore frame with unexpected Transaction ID %u",
1378 trans_id[0]);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001379 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1380 " fail=transaction_id_mismatch", MAC2STR(src));
1381 goto fail;
1382 }
1383
1384 status = dpp_get_attr(buf, len, DPP_ATTR_STATUS, &status_len);
1385 if (!status || status_len != 1) {
1386 wpa_printf(MSG_DEBUG, "DPP: Peer did not include Status");
1387 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1388 " fail=missing_status", MAC2STR(src));
1389 goto fail;
1390 }
1391 if (status[0] != DPP_STATUS_OK) {
1392 wpa_printf(MSG_DEBUG,
1393 "DPP: Peer rejected network introduction: Status %u",
1394 status[0]);
1395 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1396 " status=%u", MAC2STR(src), status[0]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001397 goto fail;
1398 }
1399
1400 connector = dpp_get_attr(buf, len, DPP_ATTR_CONNECTOR, &connector_len);
1401 if (!connector) {
1402 wpa_printf(MSG_DEBUG,
1403 "DPP: Peer did not include its Connector");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001404 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1405 " fail=missing_connector", MAC2STR(src));
1406 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001407 }
1408
Roshan Pius3a1667e2018-07-03 15:17:14 -07001409 res = dpp_peer_intro(&intro, ssid->dpp_connector,
1410 ssid->dpp_netaccesskey,
1411 ssid->dpp_netaccesskey_len,
1412 ssid->dpp_csign,
1413 ssid->dpp_csign_len,
1414 connector, connector_len, &expiry);
1415 if (res != DPP_STATUS_OK) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001416 wpa_printf(MSG_INFO,
1417 "DPP: Network Introduction protocol resulted in failure");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001418 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1419 " fail=peer_connector_validation_failed", MAC2STR(src));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001420 goto fail;
1421 }
1422
1423 entry = os_zalloc(sizeof(*entry));
1424 if (!entry)
1425 goto fail;
1426 os_memcpy(entry->aa, src, ETH_ALEN);
1427 os_memcpy(entry->pmkid, intro.pmkid, PMKID_LEN);
1428 os_memcpy(entry->pmk, intro.pmk, intro.pmk_len);
1429 entry->pmk_len = intro.pmk_len;
1430 entry->akmp = WPA_KEY_MGMT_DPP;
1431 if (expiry) {
1432 os_get_time(&now);
1433 seconds = expiry - now.sec;
1434 } else {
1435 seconds = 86400 * 7;
1436 }
1437 os_get_reltime(&rnow);
1438 entry->expiration = rnow.sec + seconds;
1439 entry->reauth_time = rnow.sec + seconds;
1440 entry->network_ctx = ssid;
1441 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
1442
Roshan Pius3a1667e2018-07-03 15:17:14 -07001443 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1444 " status=%u", MAC2STR(src), status[0]);
1445
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001446 wpa_printf(MSG_DEBUG,
1447 "DPP: Try connection again after successful network introduction");
1448 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
1449 wpa_supplicant_cancel_sched_scan(wpa_s);
1450 wpa_supplicant_req_scan(wpa_s, 0, 0);
1451 }
1452fail:
1453 os_memset(&intro, 0, sizeof(intro));
1454}
1455
1456
Roshan Pius3a1667e2018-07-03 15:17:14 -07001457static int wpas_dpp_allow_ir(struct wpa_supplicant *wpa_s, unsigned int freq)
1458{
1459 int i, j;
1460
1461 if (!wpa_s->hw.modes)
1462 return -1;
1463
1464 for (i = 0; i < wpa_s->hw.num_modes; i++) {
1465 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
1466
1467 for (j = 0; j < mode->num_channels; j++) {
1468 struct hostapd_channel_data *chan = &mode->channels[j];
1469
1470 if (chan->freq != (int) freq)
1471 continue;
1472
1473 if (chan->flag & (HOSTAPD_CHAN_DISABLED |
1474 HOSTAPD_CHAN_NO_IR |
1475 HOSTAPD_CHAN_RADAR))
1476 continue;
1477
1478 return 1;
1479 }
1480 }
1481
1482 wpa_printf(MSG_DEBUG,
1483 "DPP: Frequency %u MHz not supported or does not allow PKEX initiation in the current channel list",
1484 freq);
1485
1486 return 0;
1487}
1488
1489
1490static int wpas_dpp_pkex_next_channel(struct wpa_supplicant *wpa_s,
1491 struct dpp_pkex *pkex)
1492{
1493 if (pkex->freq == 2437)
1494 pkex->freq = 5745;
1495 else if (pkex->freq == 5745)
1496 pkex->freq = 5220;
1497 else if (pkex->freq == 5220)
1498 pkex->freq = 60480;
1499 else
1500 return -1; /* no more channels to try */
1501
1502 if (wpas_dpp_allow_ir(wpa_s, pkex->freq) == 1) {
1503 wpa_printf(MSG_DEBUG, "DPP: Try to initiate on %u MHz",
1504 pkex->freq);
1505 return 0;
1506 }
1507
1508 /* Could not use this channel - try the next one */
1509 return wpas_dpp_pkex_next_channel(wpa_s, pkex);
1510}
1511
1512
1513static void wpas_dpp_pkex_retry_timeout(void *eloop_ctx, void *timeout_ctx)
1514{
1515 struct wpa_supplicant *wpa_s = eloop_ctx;
1516 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1517
1518 if (!pkex || !pkex->exchange_req)
1519 return;
1520 if (pkex->exch_req_tries >= 5) {
1521 if (wpas_dpp_pkex_next_channel(wpa_s, pkex) < 0) {
1522 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1523 "No response from PKEX peer");
1524 dpp_pkex_free(pkex);
1525 wpa_s->dpp_pkex = NULL;
1526 return;
1527 }
1528 pkex->exch_req_tries = 0;
1529 }
1530
1531 pkex->exch_req_tries++;
1532 wpa_printf(MSG_DEBUG, "DPP: Retransmit PKEX Exchange Request (try %u)",
1533 pkex->exch_req_tries);
1534 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1535 MAC2STR(broadcast), pkex->freq, DPP_PA_PKEX_EXCHANGE_REQ);
1536 offchannel_send_action(wpa_s, pkex->freq, broadcast,
1537 wpa_s->own_addr, broadcast,
1538 wpabuf_head(pkex->exchange_req),
1539 wpabuf_len(pkex->exchange_req),
1540 pkex->exch_req_wait_time,
1541 wpas_dpp_tx_pkex_status, 0);
1542}
1543
1544
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001545static void
1546wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s,
1547 unsigned int freq, const u8 *dst,
1548 const u8 *src, const u8 *bssid,
1549 const u8 *data, size_t data_len,
1550 enum offchannel_send_action_result result)
1551{
Roshan Pius3a1667e2018-07-03 15:17:14 -07001552 const char *res_txt;
1553 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1554
1555 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
1556 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
1557 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001558 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
1559 " result=%s (PKEX)",
Roshan Pius3a1667e2018-07-03 15:17:14 -07001560 freq, MAC2STR(dst), res_txt);
1561 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
1562 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
1563
1564 if (!pkex) {
1565 wpa_printf(MSG_DEBUG,
1566 "DPP: Ignore TX status since there is no ongoing PKEX exchange");
1567 return;
1568 }
1569
1570 if (pkex->failed) {
1571 wpa_printf(MSG_DEBUG,
1572 "DPP: Terminate PKEX exchange due to an earlier error");
1573 if (pkex->t > pkex->own_bi->pkex_t)
1574 pkex->own_bi->pkex_t = pkex->t;
1575 dpp_pkex_free(pkex);
1576 wpa_s->dpp_pkex = NULL;
1577 return;
1578 }
1579
1580 if (pkex->exch_req_wait_time && pkex->exchange_req) {
1581 /* Wait for PKEX Exchange Response frame and retry request if
1582 * no response is seen. */
1583 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
1584 eloop_register_timeout(pkex->exch_req_wait_time / 1000,
1585 (pkex->exch_req_wait_time % 1000) * 1000,
1586 wpas_dpp_pkex_retry_timeout, wpa_s,
1587 NULL);
1588 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001589}
1590
1591
1592static void
1593wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant *wpa_s, const u8 *src,
1594 const u8 *buf, size_t len, unsigned int freq)
1595{
1596 struct wpabuf *msg;
1597 unsigned int wait_time;
1598
1599 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Request from " MACSTR,
1600 MAC2STR(src));
1601
1602 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1603 * values here */
1604
1605 if (!wpa_s->dpp_pkex_code || !wpa_s->dpp_pkex_bi) {
1606 wpa_printf(MSG_DEBUG,
1607 "DPP: No PKEX code configured - ignore request");
1608 return;
1609 }
1610
1611 if (wpa_s->dpp_pkex) {
1612 /* TODO: Support parallel operations */
1613 wpa_printf(MSG_DEBUG,
1614 "DPP: Already in PKEX session - ignore new request");
1615 return;
1616 }
1617
Roshan Pius3a1667e2018-07-03 15:17:14 -07001618 wpa_s->dpp_pkex = dpp_pkex_rx_exchange_req(wpa_s, wpa_s->dpp_pkex_bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001619 wpa_s->own_addr, src,
1620 wpa_s->dpp_pkex_identifier,
1621 wpa_s->dpp_pkex_code,
1622 buf, len);
1623 if (!wpa_s->dpp_pkex) {
1624 wpa_printf(MSG_DEBUG,
1625 "DPP: Failed to process the request - ignore it");
1626 return;
1627 }
1628
1629 msg = wpa_s->dpp_pkex->exchange_resp;
1630 wait_time = wpa_s->max_remain_on_chan;
1631 if (wait_time > 2000)
1632 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001633 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1634 MAC2STR(src), freq, DPP_PA_PKEX_EXCHANGE_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001635 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
1636 broadcast,
1637 wpabuf_head(msg), wpabuf_len(msg),
1638 wait_time, wpas_dpp_tx_pkex_status, 0);
1639}
1640
1641
1642static void
1643wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant *wpa_s, const u8 *src,
1644 const u8 *buf, size_t len, unsigned int freq)
1645{
1646 struct wpabuf *msg;
1647 unsigned int wait_time;
1648
1649 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Response from " MACSTR,
1650 MAC2STR(src));
1651
1652 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1653 * values here */
1654
1655 if (!wpa_s->dpp_pkex || !wpa_s->dpp_pkex->initiator ||
1656 wpa_s->dpp_pkex->exchange_done) {
1657 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1658 return;
1659 }
1660
Roshan Pius3a1667e2018-07-03 15:17:14 -07001661 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
1662 wpa_s->dpp_pkex->exch_req_wait_time = 0;
1663
1664 msg = dpp_pkex_rx_exchange_resp(wpa_s->dpp_pkex, src, buf, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001665 if (!msg) {
1666 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
1667 return;
1668 }
1669
1670 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Request to " MACSTR,
1671 MAC2STR(src));
1672
1673 wait_time = wpa_s->max_remain_on_chan;
1674 if (wait_time > 2000)
1675 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001676 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1677 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_REQ);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001678 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
1679 broadcast,
1680 wpabuf_head(msg), wpabuf_len(msg),
1681 wait_time, wpas_dpp_tx_pkex_status, 0);
1682 wpabuf_free(msg);
1683}
1684
1685
Roshan Pius3a1667e2018-07-03 15:17:14 -07001686static struct dpp_bootstrap_info *
1687wpas_dpp_pkex_finish(struct wpa_supplicant *wpa_s, const u8 *peer,
1688 unsigned int freq)
1689{
Roshan Pius3a1667e2018-07-03 15:17:14 -07001690 struct dpp_bootstrap_info *bi;
1691
Hai Shalom021b0b52019-04-10 11:17:58 -07001692 bi = dpp_pkex_finish(wpa_s->dpp, wpa_s->dpp_pkex, peer, freq);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001693 if (!bi)
1694 return NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001695 wpa_s->dpp_pkex = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001696 return bi;
1697}
1698
1699
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001700static void
1701wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant *wpa_s, const u8 *src,
1702 const u8 *hdr, const u8 *buf, size_t len,
1703 unsigned int freq)
1704{
1705 struct wpabuf *msg;
1706 unsigned int wait_time;
1707 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001708
1709 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Request from " MACSTR,
1710 MAC2STR(src));
1711
1712 if (!pkex || pkex->initiator || !pkex->exchange_done) {
1713 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1714 return;
1715 }
1716
1717 msg = dpp_pkex_rx_commit_reveal_req(pkex, hdr, buf, len);
1718 if (!msg) {
1719 wpa_printf(MSG_DEBUG, "DPP: Failed to process the request");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001720 if (pkex->failed) {
1721 wpa_printf(MSG_DEBUG, "DPP: Terminate PKEX exchange");
1722 if (pkex->t > pkex->own_bi->pkex_t)
1723 pkex->own_bi->pkex_t = pkex->t;
1724 dpp_pkex_free(wpa_s->dpp_pkex);
1725 wpa_s->dpp_pkex = NULL;
1726 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001727 return;
1728 }
1729
1730 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Response to "
1731 MACSTR, MAC2STR(src));
1732
1733 wait_time = wpa_s->max_remain_on_chan;
1734 if (wait_time > 2000)
1735 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001736 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1737 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001738 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
1739 broadcast,
1740 wpabuf_head(msg), wpabuf_len(msg),
1741 wait_time, wpas_dpp_tx_pkex_status, 0);
1742 wpabuf_free(msg);
1743
Roshan Pius3a1667e2018-07-03 15:17:14 -07001744 wpas_dpp_pkex_finish(wpa_s, src, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001745}
1746
1747
1748static void
1749wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant *wpa_s, const u8 *src,
1750 const u8 *hdr, const u8 *buf, size_t len,
1751 unsigned int freq)
1752{
1753 int res;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001754 struct dpp_bootstrap_info *bi;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001755 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1756 char cmd[500];
1757
1758 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Response from " MACSTR,
1759 MAC2STR(src));
1760
1761 if (!pkex || !pkex->initiator || !pkex->exchange_done) {
1762 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1763 return;
1764 }
1765
1766 res = dpp_pkex_rx_commit_reveal_resp(pkex, hdr, buf, len);
1767 if (res < 0) {
1768 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
1769 return;
1770 }
1771
Roshan Pius3a1667e2018-07-03 15:17:14 -07001772 bi = wpas_dpp_pkex_finish(wpa_s, src, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001773 if (!bi)
1774 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001775
1776 os_snprintf(cmd, sizeof(cmd), " peer=%u %s",
1777 bi->id,
1778 wpa_s->dpp_pkex_auth_cmd ? wpa_s->dpp_pkex_auth_cmd : "");
1779 wpa_printf(MSG_DEBUG,
1780 "DPP: Start authentication after PKEX with parameters: %s",
1781 cmd);
1782 if (wpas_dpp_auth_init(wpa_s, cmd) < 0) {
1783 wpa_printf(MSG_DEBUG,
1784 "DPP: Authentication initialization failed");
1785 return;
1786 }
1787}
1788
1789
1790void wpas_dpp_rx_action(struct wpa_supplicant *wpa_s, const u8 *src,
1791 const u8 *buf, size_t len, unsigned int freq)
1792{
1793 u8 crypto_suite;
1794 enum dpp_public_action_frame_type type;
1795 const u8 *hdr;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001796 unsigned int pkex_t;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001797
1798 if (len < DPP_HDR_LEN)
1799 return;
1800 if (WPA_GET_BE24(buf) != OUI_WFA || buf[3] != DPP_OUI_TYPE)
1801 return;
1802 hdr = buf;
1803 buf += 4;
1804 len -= 4;
1805 crypto_suite = *buf++;
1806 type = *buf++;
1807 len -= 2;
1808
1809 wpa_printf(MSG_DEBUG,
1810 "DPP: Received DPP Public Action frame crypto suite %u type %d from "
1811 MACSTR " freq=%u",
1812 crypto_suite, type, MAC2STR(src), freq);
1813 if (crypto_suite != 1) {
1814 wpa_printf(MSG_DEBUG, "DPP: Unsupported crypto suite %u",
1815 crypto_suite);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001816 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
1817 " freq=%u type=%d ignore=unsupported-crypto-suite",
1818 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001819 return;
1820 }
1821 wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001822 if (dpp_check_attrs(buf, len) < 0) {
1823 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
1824 " freq=%u type=%d ignore=invalid-attributes",
1825 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001826 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001827 }
1828 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR " freq=%u type=%d",
1829 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001830
1831 switch (type) {
1832 case DPP_PA_AUTHENTICATION_REQ:
1833 wpas_dpp_rx_auth_req(wpa_s, src, hdr, buf, len, freq);
1834 break;
1835 case DPP_PA_AUTHENTICATION_RESP:
Roshan Pius3a1667e2018-07-03 15:17:14 -07001836 wpas_dpp_rx_auth_resp(wpa_s, src, hdr, buf, len, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001837 break;
1838 case DPP_PA_AUTHENTICATION_CONF:
1839 wpas_dpp_rx_auth_conf(wpa_s, src, hdr, buf, len);
1840 break;
1841 case DPP_PA_PEER_DISCOVERY_RESP:
1842 wpas_dpp_rx_peer_disc_resp(wpa_s, src, buf, len);
1843 break;
1844 case DPP_PA_PKEX_EXCHANGE_REQ:
1845 wpas_dpp_rx_pkex_exchange_req(wpa_s, src, buf, len, freq);
1846 break;
1847 case DPP_PA_PKEX_EXCHANGE_RESP:
1848 wpas_dpp_rx_pkex_exchange_resp(wpa_s, src, buf, len, freq);
1849 break;
1850 case DPP_PA_PKEX_COMMIT_REVEAL_REQ:
1851 wpas_dpp_rx_pkex_commit_reveal_req(wpa_s, src, hdr, buf, len,
1852 freq);
1853 break;
1854 case DPP_PA_PKEX_COMMIT_REVEAL_RESP:
1855 wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s, src, hdr, buf, len,
1856 freq);
1857 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07001858#ifdef CONFIG_DPP2
1859 case DPP_PA_CONFIGURATION_RESULT:
1860 wpas_dpp_rx_conf_result(wpa_s, src, hdr, buf, len);
1861 break;
1862#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001863 default:
1864 wpa_printf(MSG_DEBUG,
1865 "DPP: Ignored unsupported frame subtype %d", type);
1866 break;
1867 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001868
1869 if (wpa_s->dpp_pkex)
1870 pkex_t = wpa_s->dpp_pkex->t;
1871 else if (wpa_s->dpp_pkex_bi)
1872 pkex_t = wpa_s->dpp_pkex_bi->pkex_t;
1873 else
1874 pkex_t = 0;
1875 if (pkex_t >= PKEX_COUNTER_T_LIMIT) {
1876 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_PKEX_T_LIMIT "id=0");
1877 wpas_dpp_pkex_remove(wpa_s, "*");
1878 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001879}
1880
1881
1882static struct wpabuf *
1883wpas_dpp_gas_req_handler(void *ctx, const u8 *sa, const u8 *query,
1884 size_t query_len)
1885{
1886 struct wpa_supplicant *wpa_s = ctx;
1887 struct dpp_authentication *auth = wpa_s->dpp_auth;
1888 struct wpabuf *resp;
1889
1890 wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR,
1891 MAC2STR(sa));
1892 if (!auth || !auth->auth_success ||
1893 os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) {
1894 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
1895 return NULL;
1896 }
1897 wpa_hexdump(MSG_DEBUG,
1898 "DPP: Received Configuration Request (GAS Query Request)",
1899 query, query_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001900 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_REQ_RX "src=" MACSTR,
1901 MAC2STR(sa));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001902 resp = dpp_conf_req_rx(auth, query, query_len);
Hai Shalom59532852018-12-07 10:32:58 -08001903 if (!resp) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001904 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -08001905 wpas_notify_dpp_configuration_failure(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08001906 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001907 auth->conf_resp = resp;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001908 return resp;
1909}
1910
1911
1912static void
1913wpas_dpp_gas_status_handler(void *ctx, struct wpabuf *resp, int ok)
1914{
1915 struct wpa_supplicant *wpa_s = ctx;
1916 struct dpp_authentication *auth = wpa_s->dpp_auth;
1917
1918 if (!auth) {
1919 wpabuf_free(resp);
1920 return;
1921 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001922 if (auth->conf_resp != resp) {
1923 wpa_printf(MSG_DEBUG,
1924 "DPP: Ignore GAS status report (ok=%d) for unknown response",
1925 ok);
1926 wpabuf_free(resp);
1927 return;
1928 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001929
1930 wpa_printf(MSG_DEBUG, "DPP: Configuration exchange completed (ok=%d)",
1931 ok);
1932 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001933 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07001934#ifdef CONFIG_DPP2
1935 if (ok && auth->peer_version >= 2 &&
1936 auth->conf_resp_status == DPP_STATUS_OK) {
1937 wpa_printf(MSG_DEBUG, "DPP: Wait for Configuration Result");
1938 auth->waiting_conf_result = 1;
1939 auth->conf_resp = NULL;
1940 wpabuf_free(resp);
1941 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout,
1942 wpa_s, NULL);
1943 eloop_register_timeout(2, 0,
1944 wpas_dpp_config_result_wait_timeout,
1945 wpa_s, NULL);
1946 return;
1947 }
1948#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001949 offchannel_send_action_done(wpa_s);
1950 wpas_dpp_listen_stop(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08001951 if (ok) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001952 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
Hai Shalom706f99b2019-01-08 16:23:37 -08001953 wpas_notify_dpp_config_sent(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08001954 }
1955 else {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001956 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom706f99b2019-01-08 16:23:37 -08001957 wpas_notify_dpp_configuration_failure(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08001958 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001959 dpp_auth_deinit(wpa_s->dpp_auth);
1960 wpa_s->dpp_auth = NULL;
1961 wpabuf_free(resp);
1962}
1963
1964
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001965int wpas_dpp_configurator_sign(struct wpa_supplicant *wpa_s, const char *cmd)
1966{
1967 struct dpp_authentication *auth;
1968 int ret = -1;
1969 char *curve = NULL;
1970
1971 auth = os_zalloc(sizeof(*auth));
1972 if (!auth)
1973 return -1;
1974
1975 curve = get_param(cmd, " curve=");
Hai Shalom74f70d42019-02-11 14:42:39 -08001976 wpas_dpp_set_testing_options(wpa_s, auth);
Hai Shalom021b0b52019-04-10 11:17:58 -07001977 if (dpp_set_configurator(wpa_s->dpp, wpa_s, auth, cmd) == 0 &&
1978 dpp_configurator_own_config(auth, curve, 0) == 0)
1979 ret = wpas_dpp_handle_config_obj(wpa_s, auth);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001980
1981 dpp_auth_deinit(auth);
1982 os_free(curve);
1983
1984 return ret;
1985}
1986
1987
1988static void
1989wpas_dpp_tx_introduction_status(struct wpa_supplicant *wpa_s,
1990 unsigned int freq, const u8 *dst,
1991 const u8 *src, const u8 *bssid,
1992 const u8 *data, size_t data_len,
1993 enum offchannel_send_action_result result)
1994{
Roshan Pius3a1667e2018-07-03 15:17:14 -07001995 const char *res_txt;
1996
1997 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
1998 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
1999 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002000 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
2001 " result=%s (DPP Peer Discovery Request)",
Roshan Pius3a1667e2018-07-03 15:17:14 -07002002 freq, MAC2STR(dst), res_txt);
2003 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
2004 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002005 /* TODO: Time out wait for response more quickly in error cases? */
2006}
2007
2008
2009int wpas_dpp_check_connect(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2010 struct wpa_bss *bss)
2011{
2012 struct os_time now;
2013 struct wpabuf *msg;
2014 unsigned int wait_time;
Hai Shalom021b0b52019-04-10 11:17:58 -07002015 const u8 *rsn;
2016 struct wpa_ie_data ied;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002017
2018 if (!(ssid->key_mgmt & WPA_KEY_MGMT_DPP) || !bss)
2019 return 0; /* Not using DPP AKM - continue */
Hai Shalom021b0b52019-04-10 11:17:58 -07002020 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2021 if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ied) == 0 &&
2022 !(ied.key_mgmt & WPA_KEY_MGMT_DPP))
2023 return 0; /* AP does not support DPP AKM - continue */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002024 if (wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid))
2025 return 0; /* PMKSA exists for DPP AKM - continue */
2026
2027 if (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
2028 !ssid->dpp_csign) {
2029 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
2030 "missing %s",
2031 !ssid->dpp_connector ? "Connector" :
2032 (!ssid->dpp_netaccesskey ? "netAccessKey" :
2033 "C-sign-key"));
2034 return -1;
2035 }
2036
2037 os_get_time(&now);
2038
2039 if (ssid->dpp_netaccesskey_expiry &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07002040 (os_time_t) ssid->dpp_netaccesskey_expiry < now.sec) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002041 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
2042 "netAccessKey expired");
2043 return -1;
2044 }
2045
2046 wpa_printf(MSG_DEBUG,
2047 "DPP: Starting network introduction protocol to derive PMKSA for "
2048 MACSTR, MAC2STR(bss->bssid));
2049
2050 msg = dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ,
2051 5 + 4 + os_strlen(ssid->dpp_connector));
2052 if (!msg)
2053 return -1;
2054
Roshan Pius3a1667e2018-07-03 15:17:14 -07002055#ifdef CONFIG_TESTING_OPTIONS
2056 if (dpp_test == DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ) {
2057 wpa_printf(MSG_INFO, "DPP: TESTING - no Transaction ID");
2058 goto skip_trans_id;
2059 }
2060 if (dpp_test == DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ) {
2061 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Transaction ID");
2062 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
2063 wpabuf_put_le16(msg, 0);
2064 goto skip_trans_id;
2065 }
2066#endif /* CONFIG_TESTING_OPTIONS */
2067
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002068 /* Transaction ID */
2069 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
2070 wpabuf_put_le16(msg, 1);
2071 wpabuf_put_u8(msg, TRANSACTION_ID);
2072
Roshan Pius3a1667e2018-07-03 15:17:14 -07002073#ifdef CONFIG_TESTING_OPTIONS
2074skip_trans_id:
2075 if (dpp_test == DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ) {
2076 wpa_printf(MSG_INFO, "DPP: TESTING - no Connector");
2077 goto skip_connector;
2078 }
2079 if (dpp_test == DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ) {
2080 char *connector;
2081
2082 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Connector");
2083 connector = dpp_corrupt_connector_signature(
2084 ssid->dpp_connector);
2085 if (!connector) {
2086 wpabuf_free(msg);
2087 return -1;
2088 }
2089 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
2090 wpabuf_put_le16(msg, os_strlen(connector));
2091 wpabuf_put_str(msg, connector);
2092 os_free(connector);
2093 goto skip_connector;
2094 }
2095#endif /* CONFIG_TESTING_OPTIONS */
2096
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002097 /* DPP Connector */
2098 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
2099 wpabuf_put_le16(msg, os_strlen(ssid->dpp_connector));
2100 wpabuf_put_str(msg, ssid->dpp_connector);
2101
Roshan Pius3a1667e2018-07-03 15:17:14 -07002102#ifdef CONFIG_TESTING_OPTIONS
2103skip_connector:
2104#endif /* CONFIG_TESTING_OPTIONS */
2105
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002106 /* TODO: Timeout on AP response */
2107 wait_time = wpa_s->max_remain_on_chan;
2108 if (wait_time > 2000)
2109 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002110 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2111 MAC2STR(bss->bssid), bss->freq, DPP_PA_PEER_DISCOVERY_REQ);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002112 offchannel_send_action(wpa_s, bss->freq, bss->bssid, wpa_s->own_addr,
2113 broadcast,
2114 wpabuf_head(msg), wpabuf_len(msg),
2115 wait_time, wpas_dpp_tx_introduction_status, 0);
2116 wpabuf_free(msg);
2117
2118 /* Request this connection attempt to terminate - new one will be
2119 * started when network introduction protocol completes */
2120 os_memcpy(wpa_s->dpp_intro_bssid, bss->bssid, ETH_ALEN);
2121 wpa_s->dpp_intro_network = ssid;
2122 return 1;
2123}
2124
2125
2126int wpas_dpp_pkex_add(struct wpa_supplicant *wpa_s, const char *cmd)
2127{
2128 struct dpp_bootstrap_info *own_bi;
2129 const char *pos, *end;
2130 unsigned int wait_time;
2131
2132 pos = os_strstr(cmd, " own=");
2133 if (!pos)
2134 return -1;
2135 pos += 5;
Hai Shalom021b0b52019-04-10 11:17:58 -07002136 own_bi = dpp_bootstrap_get_id(wpa_s->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002137 if (!own_bi) {
2138 wpa_printf(MSG_DEBUG,
2139 "DPP: Identified bootstrap info not found");
2140 return -1;
2141 }
2142 if (own_bi->type != DPP_BOOTSTRAP_PKEX) {
2143 wpa_printf(MSG_DEBUG,
2144 "DPP: Identified bootstrap info not for PKEX");
2145 return -1;
2146 }
2147 wpa_s->dpp_pkex_bi = own_bi;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002148 own_bi->pkex_t = 0; /* clear pending errors on new code */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002149
2150 os_free(wpa_s->dpp_pkex_identifier);
2151 wpa_s->dpp_pkex_identifier = NULL;
2152 pos = os_strstr(cmd, " identifier=");
2153 if (pos) {
2154 pos += 12;
2155 end = os_strchr(pos, ' ');
2156 if (!end)
2157 return -1;
2158 wpa_s->dpp_pkex_identifier = os_malloc(end - pos + 1);
2159 if (!wpa_s->dpp_pkex_identifier)
2160 return -1;
2161 os_memcpy(wpa_s->dpp_pkex_identifier, pos, end - pos);
2162 wpa_s->dpp_pkex_identifier[end - pos] = '\0';
2163 }
2164
2165 pos = os_strstr(cmd, " code=");
2166 if (!pos)
2167 return -1;
2168 os_free(wpa_s->dpp_pkex_code);
2169 wpa_s->dpp_pkex_code = os_strdup(pos + 6);
2170 if (!wpa_s->dpp_pkex_code)
2171 return -1;
2172
2173 if (os_strstr(cmd, " init=1")) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002174 struct dpp_pkex *pkex;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002175 struct wpabuf *msg;
2176
2177 wpa_printf(MSG_DEBUG, "DPP: Initiating PKEX");
2178 dpp_pkex_free(wpa_s->dpp_pkex);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002179 wpa_s->dpp_pkex = dpp_pkex_init(wpa_s, own_bi, wpa_s->own_addr,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002180 wpa_s->dpp_pkex_identifier,
2181 wpa_s->dpp_pkex_code);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002182 pkex = wpa_s->dpp_pkex;
2183 if (!pkex)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002184 return -1;
2185
Roshan Pius3a1667e2018-07-03 15:17:14 -07002186 msg = pkex->exchange_req;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002187 wait_time = wpa_s->max_remain_on_chan;
2188 if (wait_time > 2000)
2189 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002190 pkex->freq = 2437;
2191 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
2192 " freq=%u type=%d",
2193 MAC2STR(broadcast), pkex->freq,
2194 DPP_PA_PKEX_EXCHANGE_REQ);
2195 offchannel_send_action(wpa_s, pkex->freq, broadcast,
2196 wpa_s->own_addr, broadcast,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002197 wpabuf_head(msg), wpabuf_len(msg),
2198 wait_time, wpas_dpp_tx_pkex_status, 0);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002199 if (wait_time == 0)
2200 wait_time = 2000;
2201 pkex->exch_req_wait_time = wait_time;
2202 pkex->exch_req_tries = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002203 }
2204
2205 /* TODO: Support multiple PKEX info entries */
2206
2207 os_free(wpa_s->dpp_pkex_auth_cmd);
2208 wpa_s->dpp_pkex_auth_cmd = os_strdup(cmd);
2209
2210 return 1;
2211}
2212
2213
2214int wpas_dpp_pkex_remove(struct wpa_supplicant *wpa_s, const char *id)
2215{
2216 unsigned int id_val;
2217
2218 if (os_strcmp(id, "*") == 0) {
2219 id_val = 0;
2220 } else {
2221 id_val = atoi(id);
2222 if (id_val == 0)
2223 return -1;
2224 }
2225
2226 if ((id_val != 0 && id_val != 1) || !wpa_s->dpp_pkex_code)
2227 return -1;
2228
2229 /* TODO: Support multiple PKEX entries */
2230 os_free(wpa_s->dpp_pkex_code);
2231 wpa_s->dpp_pkex_code = NULL;
2232 os_free(wpa_s->dpp_pkex_identifier);
2233 wpa_s->dpp_pkex_identifier = NULL;
2234 os_free(wpa_s->dpp_pkex_auth_cmd);
2235 wpa_s->dpp_pkex_auth_cmd = NULL;
2236 wpa_s->dpp_pkex_bi = NULL;
2237 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
2238 dpp_pkex_free(wpa_s->dpp_pkex);
2239 wpa_s->dpp_pkex = NULL;
2240 return 0;
2241}
2242
2243
Roshan Pius3a1667e2018-07-03 15:17:14 -07002244void wpas_dpp_stop(struct wpa_supplicant *wpa_s)
2245{
2246 dpp_auth_deinit(wpa_s->dpp_auth);
2247 wpa_s->dpp_auth = NULL;
2248 dpp_pkex_free(wpa_s->dpp_pkex);
2249 wpa_s->dpp_pkex = NULL;
2250 if (wpa_s->dpp_gas_client && wpa_s->dpp_gas_dialog_token >= 0)
2251 gas_query_stop(wpa_s->gas, wpa_s->dpp_gas_dialog_token);
2252}
2253
2254
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002255int wpas_dpp_init(struct wpa_supplicant *wpa_s)
2256{
Hai Shalom81f62d82019-07-22 12:10:00 -07002257 struct dpp_global_config config;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002258 u8 adv_proto_id[7];
2259
2260 adv_proto_id[0] = WLAN_EID_VENDOR_SPECIFIC;
2261 adv_proto_id[1] = 5;
2262 WPA_PUT_BE24(&adv_proto_id[2], OUI_WFA);
2263 adv_proto_id[5] = DPP_OUI_TYPE;
2264 adv_proto_id[6] = 0x01;
2265
2266 if (gas_server_register(wpa_s->gas_server, adv_proto_id,
2267 sizeof(adv_proto_id), wpas_dpp_gas_req_handler,
2268 wpas_dpp_gas_status_handler, wpa_s) < 0)
2269 return -1;
Hai Shalom81f62d82019-07-22 12:10:00 -07002270
2271 os_memset(&config, 0, sizeof(config));
2272 config.msg_ctx = wpa_s;
2273 config.cb_ctx = wpa_s;
2274#ifdef CONFIG_DPP2
2275 config.process_conf_obj = wpas_dpp_process_conf_obj;
2276#endif /* CONFIG_DPP2 */
2277 wpa_s->dpp = dpp_global_init(&config);
Hai Shalom021b0b52019-04-10 11:17:58 -07002278 return wpa_s->dpp ? 0 : -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002279}
2280
2281
2282void wpas_dpp_deinit(struct wpa_supplicant *wpa_s)
2283{
2284#ifdef CONFIG_TESTING_OPTIONS
2285 os_free(wpa_s->dpp_config_obj_override);
2286 wpa_s->dpp_config_obj_override = NULL;
2287 os_free(wpa_s->dpp_discovery_override);
2288 wpa_s->dpp_discovery_override = NULL;
2289 os_free(wpa_s->dpp_groups_override);
2290 wpa_s->dpp_groups_override = NULL;
2291 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
2292#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalom021b0b52019-04-10 11:17:58 -07002293 if (!wpa_s->dpp)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002294 return;
Hai Shalom021b0b52019-04-10 11:17:58 -07002295 dpp_global_clear(wpa_s->dpp);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002296 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002297 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002298 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
2299 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07002300#ifdef CONFIG_DPP2
2301 eloop_cancel_timeout(wpas_dpp_config_result_wait_timeout, wpa_s, NULL);
2302 dpp_pfs_free(wpa_s->dpp_pfs);
2303 wpa_s->dpp_pfs = NULL;
2304#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002305 offchannel_send_action_done(wpa_s);
2306 wpas_dpp_listen_stop(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002307 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002308 wpas_dpp_pkex_remove(wpa_s, "*");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002309 os_memset(wpa_s->dpp_intro_bssid, 0, ETH_ALEN);
2310 os_free(wpa_s->dpp_configurator_params);
2311 wpa_s->dpp_configurator_params = NULL;
2312}
Hai Shalom81f62d82019-07-22 12:10:00 -07002313
2314
2315#ifdef CONFIG_DPP2
2316int wpas_dpp_controller_start(struct wpa_supplicant *wpa_s, const char *cmd)
2317{
2318 struct dpp_controller_config config;
2319 const char *pos;
2320
2321 os_memset(&config, 0, sizeof(config));
2322 if (cmd) {
2323 pos = os_strstr(cmd, " tcp_port=");
2324 if (pos) {
2325 pos += 10;
2326 config.tcp_port = atoi(pos);
2327 }
2328 }
2329 config.configurator_params = wpa_s->dpp_configurator_params;
2330 return dpp_controller_start(wpa_s->dpp, &config);
2331}
2332#endif /* CONFIG_DPP2 */