blob: e7754225ac9160ed11f54e4711ea949a03af123f [file] [log] [blame]
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001/*
2 * wpa_supplicant - DPP
3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
Roshan Pius3a1667e2018-07-03 15:17:14 -07004 * Copyright (c) 2018, 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
56static struct dpp_configurator *
57dpp_configurator_get_id(struct wpa_supplicant *wpa_s, unsigned int id)
58{
59 struct dpp_configurator *conf;
60
61 dl_list_for_each(conf, &wpa_s->dpp_configurator,
62 struct dpp_configurator, list) {
63 if (conf->id == id)
64 return conf;
65 }
66 return NULL;
67}
68
69
70static unsigned int wpas_dpp_next_id(struct wpa_supplicant *wpa_s)
71{
72 struct dpp_bootstrap_info *bi;
73 unsigned int max_id = 0;
74
75 dl_list_for_each(bi, &wpa_s->dpp_bootstrap, struct dpp_bootstrap_info,
76 list) {
77 if (bi->id > max_id)
78 max_id = bi->id;
79 }
80 return max_id + 1;
81}
82
83
84/**
85 * wpas_dpp_qr_code - Parse and add DPP bootstrapping info from a QR Code
86 * @wpa_s: Pointer to wpa_supplicant data
87 * @cmd: DPP URI read from a QR Code
88 * Returns: Identifier of the stored info or -1 on failure
89 */
90int wpas_dpp_qr_code(struct wpa_supplicant *wpa_s, const char *cmd)
91{
92 struct dpp_bootstrap_info *bi;
93 struct dpp_authentication *auth = wpa_s->dpp_auth;
94
95 bi = dpp_parse_qr_code(cmd);
96 if (!bi)
97 return -1;
98
99 bi->id = wpas_dpp_next_id(wpa_s);
100 dl_list_add(&wpa_s->dpp_bootstrap, &bi->list);
101
102 if (auth && auth->response_pending &&
103 dpp_notify_new_qr_code(auth, bi) == 1) {
104 wpa_printf(MSG_DEBUG,
105 "DPP: Sending out pending authentication response");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700106 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
107 " freq=%u type=%d",
108 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
109 DPP_PA_AUTHENTICATION_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700110 offchannel_send_action(wpa_s, auth->curr_freq,
111 auth->peer_mac_addr, wpa_s->own_addr,
112 broadcast,
113 wpabuf_head(auth->resp_msg),
114 wpabuf_len(auth->resp_msg),
115 500, wpas_dpp_tx_status, 0);
116 }
117
118 return bi->id;
119}
120
121
122static char * get_param(const char *cmd, const char *param)
123{
124 const char *pos, *end;
125 char *val;
126 size_t len;
127
128 pos = os_strstr(cmd, param);
129 if (!pos)
130 return NULL;
131
132 pos += os_strlen(param);
133 end = os_strchr(pos, ' ');
134 if (end)
135 len = end - pos;
136 else
137 len = os_strlen(pos);
138 val = os_malloc(len + 1);
139 if (!val)
140 return NULL;
141 os_memcpy(val, pos, len);
142 val[len] = '\0';
143 return val;
144}
145
146
147int wpas_dpp_bootstrap_gen(struct wpa_supplicant *wpa_s, const char *cmd)
148{
149 char *chan = NULL, *mac = NULL, *info = NULL, *pk = NULL, *curve = NULL;
150 char *key = NULL;
151 u8 *privkey = NULL;
152 size_t privkey_len = 0;
153 size_t len;
154 int ret = -1;
155 struct dpp_bootstrap_info *bi;
156
157 bi = os_zalloc(sizeof(*bi));
158 if (!bi)
159 goto fail;
160
161 if (os_strstr(cmd, "type=qrcode"))
162 bi->type = DPP_BOOTSTRAP_QR_CODE;
163 else if (os_strstr(cmd, "type=pkex"))
164 bi->type = DPP_BOOTSTRAP_PKEX;
165 else
166 goto fail;
167
168 chan = get_param(cmd, " chan=");
169 mac = get_param(cmd, " mac=");
170 info = get_param(cmd, " info=");
171 curve = get_param(cmd, " curve=");
172 key = get_param(cmd, " key=");
173
174 if (key) {
175 privkey_len = os_strlen(key) / 2;
176 privkey = os_malloc(privkey_len);
177 if (!privkey ||
178 hexstr2bin(key, privkey, privkey_len) < 0)
179 goto fail;
180 }
181
182 pk = dpp_keygen(bi, curve, privkey, privkey_len);
183 if (!pk)
184 goto fail;
185
186 len = 4; /* "DPP:" */
187 if (chan) {
188 if (dpp_parse_uri_chan_list(bi, chan) < 0)
189 goto fail;
190 len += 3 + os_strlen(chan); /* C:...; */
191 }
192 if (mac) {
193 if (dpp_parse_uri_mac(bi, mac) < 0)
194 goto fail;
195 len += 3 + os_strlen(mac); /* M:...; */
196 }
197 if (info) {
198 if (dpp_parse_uri_info(bi, info) < 0)
199 goto fail;
200 len += 3 + os_strlen(info); /* I:...; */
201 }
202 len += 4 + os_strlen(pk);
203 bi->uri = os_malloc(len + 1);
204 if (!bi->uri)
205 goto fail;
206 os_snprintf(bi->uri, len + 1, "DPP:%s%s%s%s%s%s%s%s%sK:%s;;",
207 chan ? "C:" : "", chan ? chan : "", chan ? ";" : "",
208 mac ? "M:" : "", mac ? mac : "", mac ? ";" : "",
209 info ? "I:" : "", info ? info : "", info ? ";" : "",
210 pk);
211 bi->id = wpas_dpp_next_id(wpa_s);
212 dl_list_add(&wpa_s->dpp_bootstrap, &bi->list);
213 ret = bi->id;
214 bi = NULL;
215fail:
216 os_free(curve);
217 os_free(pk);
218 os_free(chan);
219 os_free(mac);
220 os_free(info);
221 str_clear_free(key);
222 bin_clear_free(privkey, privkey_len);
223 dpp_bootstrap_info_free(bi);
224 return ret;
225}
226
227
228static struct dpp_bootstrap_info *
229dpp_bootstrap_get_id(struct wpa_supplicant *wpa_s, unsigned int id)
230{
231 struct dpp_bootstrap_info *bi;
232
233 dl_list_for_each(bi, &wpa_s->dpp_bootstrap, struct dpp_bootstrap_info,
234 list) {
235 if (bi->id == id)
236 return bi;
237 }
238 return NULL;
239}
240
241
242static int dpp_bootstrap_del(struct wpa_supplicant *wpa_s, unsigned int id)
243{
244 struct dpp_bootstrap_info *bi, *tmp;
245 int found = 0;
246
247 dl_list_for_each_safe(bi, tmp, &wpa_s->dpp_bootstrap,
248 struct dpp_bootstrap_info, list) {
249 if (id && bi->id != id)
250 continue;
251 found = 1;
252 dl_list_del(&bi->list);
253 dpp_bootstrap_info_free(bi);
254 }
255
256 if (id == 0)
257 return 0; /* flush succeeds regardless of entries found */
258 return found ? 0 : -1;
259}
260
261
262int wpas_dpp_bootstrap_remove(struct wpa_supplicant *wpa_s, const char *id)
263{
264 unsigned int id_val;
265
266 if (os_strcmp(id, "*") == 0) {
267 id_val = 0;
268 } else {
269 id_val = atoi(id);
270 if (id_val == 0)
271 return -1;
272 }
273
274 return dpp_bootstrap_del(wpa_s, id_val);
275}
276
277
278const char * wpas_dpp_bootstrap_get_uri(struct wpa_supplicant *wpa_s,
279 unsigned int id)
280{
281 struct dpp_bootstrap_info *bi;
282
283 bi = dpp_bootstrap_get_id(wpa_s, id);
284 if (!bi)
285 return NULL;
286 return bi->uri;
287}
288
289
290int wpas_dpp_bootstrap_info(struct wpa_supplicant *wpa_s, int id,
291 char *reply, int reply_size)
292{
293 struct dpp_bootstrap_info *bi;
294
295 bi = dpp_bootstrap_get_id(wpa_s, id);
296 if (!bi)
297 return -1;
298 return os_snprintf(reply, reply_size, "type=%s\n"
299 "mac_addr=" MACSTR "\n"
300 "info=%s\n"
301 "num_freq=%u\n"
302 "curve=%s\n",
303 dpp_bootstrap_type_txt(bi->type),
304 MAC2STR(bi->mac_addr),
305 bi->info ? bi->info : "",
306 bi->num_freq,
307 bi->curve->name);
308}
309
310
Roshan Pius3a1667e2018-07-03 15:17:14 -0700311static void wpas_dpp_auth_resp_retry_timeout(void *eloop_ctx, void *timeout_ctx)
312{
313 struct wpa_supplicant *wpa_s = eloop_ctx;
314 struct dpp_authentication *auth = wpa_s->dpp_auth;
315
316 if (!auth || !auth->resp_msg)
317 return;
318
319 wpa_printf(MSG_DEBUG,
320 "DPP: Retry Authentication Response after timeout");
321 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
322 " freq=%u type=%d",
323 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
324 DPP_PA_AUTHENTICATION_RESP);
325 offchannel_send_action(wpa_s, auth->curr_freq, auth->peer_mac_addr,
326 wpa_s->own_addr, broadcast,
327 wpabuf_head(auth->resp_msg),
328 wpabuf_len(auth->resp_msg),
329 500, wpas_dpp_tx_status, 0);
330}
331
332
333static void wpas_dpp_auth_resp_retry(struct wpa_supplicant *wpa_s)
334{
335 struct dpp_authentication *auth = wpa_s->dpp_auth;
336 unsigned int wait_time, max_tries;
337
338 if (!auth || !auth->resp_msg)
339 return;
340
341 if (wpa_s->dpp_resp_max_tries)
342 max_tries = wpa_s->dpp_resp_max_tries;
343 else
344 max_tries = 5;
345 auth->auth_resp_tries++;
346 if (auth->auth_resp_tries >= max_tries) {
347 wpa_printf(MSG_INFO, "DPP: No confirm received from initiator - stopping exchange");
348 offchannel_send_action_done(wpa_s);
349 dpp_auth_deinit(wpa_s->dpp_auth);
350 wpa_s->dpp_auth = NULL;
351 return;
352 }
353
354 if (wpa_s->dpp_resp_retry_time)
355 wait_time = wpa_s->dpp_resp_retry_time;
356 else
357 wait_time = 1000;
358 wpa_printf(MSG_DEBUG,
359 "DPP: Schedule retransmission of Authentication Response frame in %u ms",
360 wait_time);
361 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
362 eloop_register_timeout(wait_time / 1000,
363 (wait_time % 1000) * 1000,
364 wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
365}
366
367
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700368static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
369 unsigned int freq, const u8 *dst,
370 const u8 *src, const u8 *bssid,
371 const u8 *data, size_t data_len,
372 enum offchannel_send_action_result result)
373{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700374 const char *res_txt;
375 struct dpp_authentication *auth = wpa_s->dpp_auth;
376
377 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
378 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
379 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700380 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
Roshan Pius3a1667e2018-07-03 15:17:14 -0700381 " result=%s", freq, MAC2STR(dst), res_txt);
382 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
383 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700384
385 if (!wpa_s->dpp_auth) {
386 wpa_printf(MSG_DEBUG,
387 "DPP: Ignore TX status since there is no ongoing authentication exchange");
388 return;
389 }
390
391 if (wpa_s->dpp_auth->remove_on_tx_status) {
392 wpa_printf(MSG_DEBUG,
393 "DPP: Terminate authentication exchange due to an earlier error");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700394 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700395 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700396 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
397 NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700398 offchannel_send_action_done(wpa_s);
399 dpp_auth_deinit(wpa_s->dpp_auth);
400 wpa_s->dpp_auth = NULL;
401 return;
402 }
403
404 if (wpa_s->dpp_auth_ok_on_ack)
405 wpas_dpp_auth_success(wpa_s, 1);
406
407 if (!is_broadcast_ether_addr(dst) &&
408 result != OFFCHANNEL_SEND_ACTION_SUCCESS) {
409 wpa_printf(MSG_DEBUG,
410 "DPP: Unicast DPP Action frame was not ACKed");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700411 if (auth->waiting_auth_resp) {
412 /* In case of DPP Authentication Request frame, move to
413 * the next channel immediately. */
414 offchannel_send_action_done(wpa_s);
415 wpas_dpp_auth_init_next(wpa_s);
416 return;
417 }
418 if (auth->waiting_auth_conf) {
419 wpas_dpp_auth_resp_retry(wpa_s);
420 return;
421 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700422 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700423
424 if (!is_broadcast_ether_addr(dst) && auth->waiting_auth_resp &&
425 result == OFFCHANNEL_SEND_ACTION_SUCCESS) {
426 /* Allow timeout handling to stop iteration if no response is
427 * received from a peer that has ACKed a request. */
428 auth->auth_req_ack = 1;
429 }
430
431 if (!wpa_s->dpp_auth_ok_on_ack && wpa_s->dpp_auth->neg_freq > 0 &&
432 wpa_s->dpp_auth->curr_freq != wpa_s->dpp_auth->neg_freq) {
433 wpa_printf(MSG_DEBUG,
434 "DPP: Move from curr_freq %u MHz to neg_freq %u MHz for response",
435 wpa_s->dpp_auth->curr_freq,
436 wpa_s->dpp_auth->neg_freq);
437 offchannel_send_action_done(wpa_s);
438 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->neg_freq);
439 }
440
441 if (wpa_s->dpp_auth_ok_on_ack)
442 wpa_s->dpp_auth_ok_on_ack = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700443}
444
445
446static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx)
447{
448 struct wpa_supplicant *wpa_s = eloop_ctx;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700449 struct dpp_authentication *auth = wpa_s->dpp_auth;
450 unsigned int freq;
451 struct os_reltime now, diff;
452 unsigned int wait_time, diff_ms;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700453
Roshan Pius3a1667e2018-07-03 15:17:14 -0700454 if (!auth || !auth->waiting_auth_resp)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700455 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700456
457 wait_time = wpa_s->dpp_resp_wait_time ?
458 wpa_s->dpp_resp_wait_time : 2000;
459 os_get_reltime(&now);
460 os_reltime_sub(&now, &wpa_s->dpp_last_init, &diff);
461 diff_ms = diff.sec * 1000 + diff.usec / 1000;
462 wpa_printf(MSG_DEBUG,
463 "DPP: Reply wait timeout - wait_time=%u diff_ms=%u",
464 wait_time, diff_ms);
465
466 if (auth->auth_req_ack && diff_ms >= wait_time) {
467 /* Peer ACK'ed Authentication Request frame, but did not reply
468 * with Authentication Response frame within two seconds. */
469 wpa_printf(MSG_INFO,
470 "DPP: No response received from responder - stopping initiation attempt");
471 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
Hai Shalom59532852018-12-07 10:32:58 -0800472 wpas_notify_dpp_timeout(wpa_s->ifname);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700473 offchannel_send_action_done(wpa_s);
474 wpas_dpp_listen_stop(wpa_s);
475 dpp_auth_deinit(auth);
476 wpa_s->dpp_auth = NULL;
477 return;
478 }
479
480 if (diff_ms >= wait_time) {
481 /* Authentication Request frame was not ACK'ed and no reply
482 * was receiving within two seconds. */
483 wpa_printf(MSG_DEBUG,
484 "DPP: Continue Initiator channel iteration");
485 offchannel_send_action_done(wpa_s);
486 wpas_dpp_listen_stop(wpa_s);
487 wpas_dpp_auth_init_next(wpa_s);
488 return;
489 }
490
491 /* Driver did not support 2000 ms long wait_time with TX command, so
492 * schedule listen operation to continue waiting for the response.
493 *
494 * DPP listen operations continue until stopped, so simply schedule a
495 * new call to this function at the point when the two second reply
496 * wait has expired. */
497 wait_time -= diff_ms;
498
499 freq = auth->curr_freq;
500 if (auth->neg_freq > 0)
501 freq = auth->neg_freq;
502 wpa_printf(MSG_DEBUG,
503 "DPP: Continue reply wait on channel %u MHz for %u ms",
504 freq, wait_time);
505 wpa_s->dpp_in_response_listen = 1;
506 wpas_dpp_listen_start(wpa_s, freq);
507
508 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
509 wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700510}
511
512
513static void wpas_dpp_set_testing_options(struct wpa_supplicant *wpa_s,
514 struct dpp_authentication *auth)
515{
516#ifdef CONFIG_TESTING_OPTIONS
517 if (wpa_s->dpp_config_obj_override)
518 auth->config_obj_override =
519 os_strdup(wpa_s->dpp_config_obj_override);
520 if (wpa_s->dpp_discovery_override)
521 auth->discovery_override =
522 os_strdup(wpa_s->dpp_discovery_override);
523 if (wpa_s->dpp_groups_override)
524 auth->groups_override =
525 os_strdup(wpa_s->dpp_groups_override);
526 auth->ignore_netaccesskey_mismatch =
527 wpa_s->dpp_ignore_netaccesskey_mismatch;
528#endif /* CONFIG_TESTING_OPTIONS */
529}
530
531
532static void wpas_dpp_set_configurator(struct wpa_supplicant *wpa_s,
533 struct dpp_authentication *auth,
534 const char *cmd)
535{
536 const char *pos, *end;
537 struct dpp_configuration *conf_sta = NULL, *conf_ap = NULL;
538 struct dpp_configurator *conf = NULL;
539 u8 ssid[32] = { "test" };
540 size_t ssid_len = 4;
541 char pass[64] = { };
542 size_t pass_len = 0;
543 u8 psk[PMK_LEN];
544 int psk_set = 0;
Hai Shalomce48b4a2018-09-05 11:41:35 -0700545 char *group_id = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700546
547 if (!cmd)
548 return;
549
550 wpa_printf(MSG_DEBUG, "DPP: Set configurator parameters: %s", cmd);
551 pos = os_strstr(cmd, " ssid=");
552 if (pos) {
553 pos += 6;
554 end = os_strchr(pos, ' ');
555 ssid_len = end ? (size_t) (end - pos) : os_strlen(pos);
556 ssid_len /= 2;
557 if (ssid_len > sizeof(ssid) ||
558 hexstr2bin(pos, ssid, ssid_len) < 0)
559 goto fail;
560 }
561
562 pos = os_strstr(cmd, " pass=");
563 if (pos) {
564 pos += 6;
565 end = os_strchr(pos, ' ');
566 pass_len = end ? (size_t) (end - pos) : os_strlen(pos);
567 pass_len /= 2;
568 if (pass_len > sizeof(pass) - 1 || pass_len < 8 ||
569 hexstr2bin(pos, (u8 *) pass, pass_len) < 0)
570 goto fail;
571 }
572
573 pos = os_strstr(cmd, " psk=");
574 if (pos) {
575 pos += 5;
576 if (hexstr2bin(pos, psk, PMK_LEN) < 0)
577 goto fail;
578 psk_set = 1;
579 }
580
Hai Shalomce48b4a2018-09-05 11:41:35 -0700581 pos = os_strstr(cmd, " group_id=");
582 if (pos) {
583 size_t group_id_len;
584
585 pos += 10;
586 end = os_strchr(pos, ' ');
587 group_id_len = end ? (size_t) (end - pos) : os_strlen(pos);
588 group_id = os_malloc(group_id_len + 1);
589 if (!group_id)
590 goto fail;
591 os_memcpy(group_id, pos, group_id_len);
592 group_id[group_id_len] = '\0';
593 }
594
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700595 if (os_strstr(cmd, " conf=sta-")) {
596 conf_sta = os_zalloc(sizeof(struct dpp_configuration));
597 if (!conf_sta)
598 goto fail;
599 os_memcpy(conf_sta->ssid, ssid, ssid_len);
600 conf_sta->ssid_len = ssid_len;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700601 if (os_strstr(cmd, " conf=sta-psk") ||
602 os_strstr(cmd, " conf=sta-sae") ||
603 os_strstr(cmd, " conf=sta-psk-sae")) {
604 if (os_strstr(cmd, " conf=sta-psk-sae"))
605 conf_sta->akm = DPP_AKM_PSK_SAE;
606 else if (os_strstr(cmd, " conf=sta-sae"))
607 conf_sta->akm = DPP_AKM_SAE;
608 else
609 conf_sta->akm = DPP_AKM_PSK;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700610 if (psk_set) {
611 os_memcpy(conf_sta->psk, psk, PMK_LEN);
612 } else {
613 conf_sta->passphrase = os_strdup(pass);
614 if (!conf_sta->passphrase)
615 goto fail;
616 }
617 } else if (os_strstr(cmd, " conf=sta-dpp")) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700618 conf_sta->akm = DPP_AKM_DPP;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700619 } else {
620 goto fail;
621 }
Hai Shalomce48b4a2018-09-05 11:41:35 -0700622 if (os_strstr(cmd, " group_id=")) {
623 conf_sta->group_id = group_id;
624 group_id = NULL;
625 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700626 }
627
628 if (os_strstr(cmd, " conf=ap-")) {
629 conf_ap = os_zalloc(sizeof(struct dpp_configuration));
630 if (!conf_ap)
631 goto fail;
632 os_memcpy(conf_ap->ssid, ssid, ssid_len);
633 conf_ap->ssid_len = ssid_len;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700634 if (os_strstr(cmd, " conf=ap-psk") ||
635 os_strstr(cmd, " conf=ap-sae") ||
636 os_strstr(cmd, " conf=ap-psk-sae")) {
637 if (os_strstr(cmd, " conf=ap-psk-sae"))
638 conf_ap->akm = DPP_AKM_PSK_SAE;
639 else if (os_strstr(cmd, " conf=ap-sae"))
640 conf_ap->akm = DPP_AKM_SAE;
641 else
642 conf_ap->akm = DPP_AKM_PSK;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700643 if (psk_set) {
644 os_memcpy(conf_ap->psk, psk, PMK_LEN);
645 } else {
646 conf_ap->passphrase = os_strdup(pass);
647 if (!conf_ap->passphrase)
648 goto fail;
649 }
650 } else if (os_strstr(cmd, " conf=ap-dpp")) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700651 conf_ap->akm = DPP_AKM_DPP;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700652 } else {
653 goto fail;
654 }
Hai Shalomce48b4a2018-09-05 11:41:35 -0700655 if (os_strstr(cmd, " group_id=")) {
656 conf_ap->group_id = group_id;
657 group_id = NULL;
658 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700659 }
660
661 pos = os_strstr(cmd, " expiry=");
662 if (pos) {
663 long int val;
664
665 pos += 8;
666 val = strtol(pos, NULL, 0);
667 if (val <= 0)
668 goto fail;
669 if (conf_sta)
670 conf_sta->netaccesskey_expiry = val;
671 if (conf_ap)
672 conf_ap->netaccesskey_expiry = val;
673 }
674
675 pos = os_strstr(cmd, " configurator=");
676 if (pos) {
677 pos += 14;
678 conf = dpp_configurator_get_id(wpa_s, atoi(pos));
679 if (!conf) {
680 wpa_printf(MSG_INFO,
681 "DPP: Could not find the specified configurator");
682 goto fail;
683 }
684 }
685 auth->conf_sta = conf_sta;
686 auth->conf_ap = conf_ap;
687 auth->conf = conf;
Hai Shalomce48b4a2018-09-05 11:41:35 -0700688 os_free(group_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700689 return;
690
691fail:
692 wpa_printf(MSG_DEBUG, "DPP: Failed to set configurator parameters");
693 dpp_configuration_free(conf_sta);
694 dpp_configuration_free(conf_ap);
Hai Shalomce48b4a2018-09-05 11:41:35 -0700695 os_free(group_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700696}
697
698
Roshan Pius3a1667e2018-07-03 15:17:14 -0700699static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx)
700{
701 struct wpa_supplicant *wpa_s = eloop_ctx;
702
703 if (!wpa_s->dpp_auth)
704 return;
705 wpa_printf(MSG_DEBUG, "DPP: Retry initiation after timeout");
706 wpas_dpp_auth_init_next(wpa_s);
707}
708
709
710static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s)
711{
712 struct dpp_authentication *auth = wpa_s->dpp_auth;
713 const u8 *dst;
714 unsigned int wait_time, max_wait_time, freq, max_tries, used;
715 struct os_reltime now, diff;
716
717 wpa_s->dpp_in_response_listen = 0;
718 if (!auth)
719 return -1;
720
721 if (auth->freq_idx == 0)
722 os_get_reltime(&wpa_s->dpp_init_iter_start);
723
724 if (auth->freq_idx >= auth->num_freq) {
725 auth->num_freq_iters++;
726 if (wpa_s->dpp_init_max_tries)
727 max_tries = wpa_s->dpp_init_max_tries;
728 else
729 max_tries = 5;
730 if (auth->num_freq_iters >= max_tries || auth->auth_req_ack) {
731 wpa_printf(MSG_INFO,
732 "DPP: No response received from responder - stopping initiation attempt");
733 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
734 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout,
735 wpa_s, NULL);
736 offchannel_send_action_done(wpa_s);
737 dpp_auth_deinit(wpa_s->dpp_auth);
738 wpa_s->dpp_auth = NULL;
739 return -1;
740 }
741 auth->freq_idx = 0;
742 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
743 if (wpa_s->dpp_init_retry_time)
744 wait_time = wpa_s->dpp_init_retry_time;
745 else
746 wait_time = 10000;
747 os_get_reltime(&now);
748 os_reltime_sub(&now, &wpa_s->dpp_init_iter_start, &diff);
749 used = diff.sec * 1000 + diff.usec / 1000;
750 if (used > wait_time)
751 wait_time = 0;
752 else
753 wait_time -= used;
754 wpa_printf(MSG_DEBUG, "DPP: Next init attempt in %u ms",
755 wait_time);
756 eloop_register_timeout(wait_time / 1000,
757 (wait_time % 1000) * 1000,
758 wpas_dpp_init_timeout, wpa_s,
759 NULL);
760 return 0;
761 }
762 freq = auth->freq[auth->freq_idx++];
763 auth->curr_freq = freq;
764
765 if (is_zero_ether_addr(auth->peer_bi->mac_addr))
766 dst = broadcast;
767 else
768 dst = auth->peer_bi->mac_addr;
769 wpa_s->dpp_auth_ok_on_ack = 0;
770 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
771 wait_time = wpa_s->max_remain_on_chan;
772 max_wait_time = wpa_s->dpp_resp_wait_time ?
773 wpa_s->dpp_resp_wait_time : 2000;
774 if (wait_time > max_wait_time)
775 wait_time = max_wait_time;
776 wait_time += 10; /* give the driver some extra time to complete */
777 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
778 wpas_dpp_reply_wait_timeout,
779 wpa_s, NULL);
780 wait_time -= 10;
781 if (auth->neg_freq > 0 && freq != auth->neg_freq) {
782 wpa_printf(MSG_DEBUG,
783 "DPP: Initiate on %u MHz and move to neg_freq %u MHz for response",
784 freq, auth->neg_freq);
785 }
786 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
787 MAC2STR(dst), freq, DPP_PA_AUTHENTICATION_REQ);
788 auth->auth_req_ack = 0;
789 os_get_reltime(&wpa_s->dpp_last_init);
790 return offchannel_send_action(wpa_s, freq, dst,
791 wpa_s->own_addr, broadcast,
792 wpabuf_head(auth->req_msg),
793 wpabuf_len(auth->req_msg),
794 wait_time, wpas_dpp_tx_status, 0);
795}
796
797
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700798int wpas_dpp_auth_init(struct wpa_supplicant *wpa_s, const char *cmd)
799{
800 const char *pos;
801 struct dpp_bootstrap_info *peer_bi, *own_bi = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700802 u8 allowed_roles = DPP_CAPAB_CONFIGURATOR;
803 unsigned int neg_freq = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700804
805 wpa_s->dpp_gas_client = 0;
806
807 pos = os_strstr(cmd, " peer=");
808 if (!pos)
809 return -1;
810 pos += 6;
811 peer_bi = dpp_bootstrap_get_id(wpa_s, atoi(pos));
812 if (!peer_bi) {
813 wpa_printf(MSG_INFO,
814 "DPP: Could not find bootstrapping info for the identified peer");
815 return -1;
816 }
817
818 pos = os_strstr(cmd, " own=");
819 if (pos) {
820 pos += 5;
821 own_bi = dpp_bootstrap_get_id(wpa_s, atoi(pos));
822 if (!own_bi) {
823 wpa_printf(MSG_INFO,
824 "DPP: Could not find bootstrapping info for the identified local entry");
825 return -1;
826 }
827
828 if (peer_bi->curve != own_bi->curve) {
829 wpa_printf(MSG_INFO,
830 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
831 peer_bi->curve->name, own_bi->curve->name);
832 return -1;
833 }
834 }
835
836 pos = os_strstr(cmd, " role=");
837 if (pos) {
838 pos += 6;
839 if (os_strncmp(pos, "configurator", 12) == 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700840 allowed_roles = DPP_CAPAB_CONFIGURATOR;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700841 else if (os_strncmp(pos, "enrollee", 8) == 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700842 allowed_roles = DPP_CAPAB_ENROLLEE;
843 else if (os_strncmp(pos, "either", 6) == 0)
844 allowed_roles = DPP_CAPAB_CONFIGURATOR |
845 DPP_CAPAB_ENROLLEE;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700846 else
847 goto fail;
848 }
849
850 pos = os_strstr(cmd, " netrole=");
851 if (pos) {
852 pos += 9;
853 wpa_s->dpp_netrole_ap = os_strncmp(pos, "ap", 2) == 0;
854 }
855
Roshan Pius3a1667e2018-07-03 15:17:14 -0700856 pos = os_strstr(cmd, " neg_freq=");
857 if (pos)
858 neg_freq = atoi(pos + 10);
859
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700860 if (wpa_s->dpp_auth) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700861 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700862 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700863 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s,
864 NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700865 offchannel_send_action_done(wpa_s);
866 dpp_auth_deinit(wpa_s->dpp_auth);
867 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700868 wpa_s->dpp_auth = dpp_auth_init(wpa_s, peer_bi, own_bi, allowed_roles,
869 neg_freq,
870 wpa_s->hw.modes, wpa_s->hw.num_modes);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700871 if (!wpa_s->dpp_auth)
872 goto fail;
873 wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
874 wpas_dpp_set_configurator(wpa_s, wpa_s->dpp_auth, cmd);
875
Roshan Pius3a1667e2018-07-03 15:17:14 -0700876 wpa_s->dpp_auth->neg_freq = neg_freq;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700877
Roshan Pius3a1667e2018-07-03 15:17:14 -0700878 if (!is_zero_ether_addr(peer_bi->mac_addr))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700879 os_memcpy(wpa_s->dpp_auth->peer_mac_addr, peer_bi->mac_addr,
880 ETH_ALEN);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700881
Roshan Pius3a1667e2018-07-03 15:17:14 -0700882 return wpas_dpp_auth_init_next(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700883fail:
884 return -1;
885}
886
887
888struct wpas_dpp_listen_work {
889 unsigned int freq;
890 unsigned int duration;
891 struct wpabuf *probe_resp_ie;
892};
893
894
895static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work *lwork)
896{
897 if (!lwork)
898 return;
899 os_free(lwork);
900}
901
902
903static void wpas_dpp_listen_work_done(struct wpa_supplicant *wpa_s)
904{
905 struct wpas_dpp_listen_work *lwork;
906
907 if (!wpa_s->dpp_listen_work)
908 return;
909
910 lwork = wpa_s->dpp_listen_work->ctx;
911 wpas_dpp_listen_work_free(lwork);
912 radio_work_done(wpa_s->dpp_listen_work);
913 wpa_s->dpp_listen_work = NULL;
914}
915
916
917static void dpp_start_listen_cb(struct wpa_radio_work *work, int deinit)
918{
919 struct wpa_supplicant *wpa_s = work->wpa_s;
920 struct wpas_dpp_listen_work *lwork = work->ctx;
921
922 if (deinit) {
923 if (work->started) {
924 wpa_s->dpp_listen_work = NULL;
925 wpas_dpp_listen_stop(wpa_s);
926 }
927 wpas_dpp_listen_work_free(lwork);
928 return;
929 }
930
931 wpa_s->dpp_listen_work = work;
932
933 wpa_s->dpp_pending_listen_freq = lwork->freq;
934
935 if (wpa_drv_remain_on_channel(wpa_s, lwork->freq,
936 wpa_s->max_remain_on_chan) < 0) {
937 wpa_printf(MSG_DEBUG,
938 "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
939 lwork->freq);
940 wpas_dpp_listen_work_done(wpa_s);
941 wpa_s->dpp_pending_listen_freq = 0;
942 return;
943 }
944 wpa_s->off_channel_freq = 0;
945 wpa_s->roc_waiting_drv_freq = lwork->freq;
946}
947
948
949static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
950 unsigned int freq)
951{
952 struct wpas_dpp_listen_work *lwork;
953
954 if (wpa_s->dpp_listen_work) {
955 wpa_printf(MSG_DEBUG,
956 "DPP: Reject start_listen since dpp_listen_work already exists");
957 return -1;
958 }
959
960 if (wpa_s->dpp_listen_freq)
961 wpas_dpp_listen_stop(wpa_s);
962 wpa_s->dpp_listen_freq = freq;
963
964 lwork = os_zalloc(sizeof(*lwork));
965 if (!lwork)
966 return -1;
967 lwork->freq = freq;
968
969 if (radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb,
970 lwork) < 0) {
971 wpas_dpp_listen_work_free(lwork);
972 return -1;
973 }
974
975 return 0;
976}
977
978
979int wpas_dpp_listen(struct wpa_supplicant *wpa_s, const char *cmd)
980{
981 int freq;
982
983 freq = atoi(cmd);
984 if (freq <= 0)
985 return -1;
986
987 if (os_strstr(cmd, " role=configurator"))
988 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR;
989 else if (os_strstr(cmd, " role=enrollee"))
990 wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
991 else
992 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
993 DPP_CAPAB_ENROLLEE;
994 wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
995 wpa_s->dpp_netrole_ap = os_strstr(cmd, " netrole=ap") != NULL;
996 if (wpa_s->dpp_listen_freq == (unsigned int) freq) {
997 wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz",
998 freq);
999 return 0;
1000 }
1001
1002 return wpas_dpp_listen_start(wpa_s, freq);
1003}
1004
1005
1006void wpas_dpp_listen_stop(struct wpa_supplicant *wpa_s)
1007{
Roshan Pius3a1667e2018-07-03 15:17:14 -07001008 wpa_s->dpp_in_response_listen = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001009 if (!wpa_s->dpp_listen_freq)
1010 return;
1011
1012 wpa_printf(MSG_DEBUG, "DPP: Stop listen on %u MHz",
1013 wpa_s->dpp_listen_freq);
1014 wpa_drv_cancel_remain_on_channel(wpa_s);
1015 wpa_s->dpp_listen_freq = 0;
1016 wpas_dpp_listen_work_done(wpa_s);
1017}
1018
1019
1020void wpas_dpp_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
1021 unsigned int freq)
1022{
1023 if (!wpa_s->dpp_listen_freq && !wpa_s->dpp_pending_listen_freq)
1024 return;
1025
1026 wpa_printf(MSG_DEBUG,
1027 "DPP: remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d roc_waiting_drv_freq=%d freq=%u)",
1028 wpa_s->off_channel_freq, wpa_s->dpp_pending_listen_freq,
1029 wpa_s->roc_waiting_drv_freq, freq);
1030 if (wpa_s->off_channel_freq &&
1031 wpa_s->off_channel_freq == wpa_s->dpp_pending_listen_freq) {
1032 wpa_printf(MSG_DEBUG, "DPP: Listen on %u MHz started", freq);
1033 wpa_s->dpp_pending_listen_freq = 0;
1034 } else {
1035 wpa_printf(MSG_DEBUG,
1036 "DPP: Ignore remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d freq=%u)",
1037 wpa_s->off_channel_freq,
1038 wpa_s->dpp_pending_listen_freq, freq);
1039 }
1040}
1041
1042
1043void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
1044 unsigned int freq)
1045{
1046 wpas_dpp_listen_work_done(wpa_s);
1047
Roshan Pius3a1667e2018-07-03 15:17:14 -07001048 if (wpa_s->dpp_auth && wpa_s->dpp_in_response_listen) {
1049 unsigned int new_freq;
1050
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001051 /* Continue listen with a new remain-on-channel */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001052 if (wpa_s->dpp_auth->neg_freq > 0)
1053 new_freq = wpa_s->dpp_auth->neg_freq;
1054 else
1055 new_freq = wpa_s->dpp_auth->curr_freq;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001056 wpa_printf(MSG_DEBUG,
1057 "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
Roshan Pius3a1667e2018-07-03 15:17:14 -07001058 new_freq);
1059 wpas_dpp_listen_start(wpa_s, new_freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001060 return;
1061 }
1062
1063 if (wpa_s->dpp_listen_freq) {
1064 /* Continue listen with a new remain-on-channel */
1065 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_listen_freq);
1066 }
1067}
1068
1069
1070static void wpas_dpp_rx_auth_req(struct wpa_supplicant *wpa_s, const u8 *src,
1071 const u8 *hdr, const u8 *buf, size_t len,
1072 unsigned int freq)
1073{
Roshan Pius3a1667e2018-07-03 15:17:14 -07001074 const u8 *r_bootstrap, *i_bootstrap;
1075 u16 r_bootstrap_len, i_bootstrap_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001076 struct dpp_bootstrap_info *bi, *own_bi = NULL, *peer_bi = NULL;
1077
1078 wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR,
1079 MAC2STR(src));
1080
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001081 r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
1082 &r_bootstrap_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001083 if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
1084 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1085 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001086 return;
1087 }
1088 wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
1089 r_bootstrap, r_bootstrap_len);
1090
1091 i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH,
1092 &i_bootstrap_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001093 if (!i_bootstrap || i_bootstrap_len != SHA256_MAC_LEN) {
1094 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1095 "Missing or invalid required Initiator Bootstrapping Key Hash attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001096 return;
1097 }
1098 wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash",
1099 i_bootstrap, i_bootstrap_len);
1100
1101 /* Try to find own and peer bootstrapping key matches based on the
1102 * received hash values */
1103 dl_list_for_each(bi, &wpa_s->dpp_bootstrap, struct dpp_bootstrap_info,
1104 list) {
1105 if (!own_bi && bi->own &&
1106 os_memcmp(bi->pubkey_hash, r_bootstrap,
1107 SHA256_MAC_LEN) == 0) {
1108 wpa_printf(MSG_DEBUG,
1109 "DPP: Found matching own bootstrapping information");
1110 own_bi = bi;
1111 }
1112
1113 if (!peer_bi && !bi->own &&
1114 os_memcmp(bi->pubkey_hash, i_bootstrap,
1115 SHA256_MAC_LEN) == 0) {
1116 wpa_printf(MSG_DEBUG,
1117 "DPP: Found matching peer bootstrapping information");
1118 peer_bi = bi;
1119 }
1120
1121 if (own_bi && peer_bi)
1122 break;
1123 }
1124
1125 if (!own_bi) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001126 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1127 "No matching own bootstrapping key found - ignore message");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001128 return;
1129 }
1130
1131 if (wpa_s->dpp_auth) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001132 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1133 "Already in DPP authentication exchange - ignore new one");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001134 return;
1135 }
1136
1137 wpa_s->dpp_gas_client = 0;
1138 wpa_s->dpp_auth_ok_on_ack = 0;
1139 wpa_s->dpp_auth = dpp_auth_req_rx(wpa_s, wpa_s->dpp_allowed_roles,
1140 wpa_s->dpp_qr_mutual,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001141 peer_bi, own_bi, freq, hdr, buf, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001142 if (!wpa_s->dpp_auth) {
1143 wpa_printf(MSG_DEBUG, "DPP: No response generated");
Hai Shalom59532852018-12-07 10:32:58 -08001144 wpas_notify_dpp_auth_failure(wpa_s->ifname);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001145 return;
1146 }
1147 wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
1148 wpas_dpp_set_configurator(wpa_s, wpa_s->dpp_auth,
1149 wpa_s->dpp_configurator_params);
1150 os_memcpy(wpa_s->dpp_auth->peer_mac_addr, src, ETH_ALEN);
1151
Roshan Pius3a1667e2018-07-03 15:17:14 -07001152 if (wpa_s->dpp_listen_freq &&
1153 wpa_s->dpp_listen_freq != wpa_s->dpp_auth->curr_freq) {
1154 wpa_printf(MSG_DEBUG,
1155 "DPP: Stop listen on %u MHz to allow response on the request %u MHz",
1156 wpa_s->dpp_listen_freq, wpa_s->dpp_auth->curr_freq);
1157 wpas_dpp_listen_stop(wpa_s);
1158 }
1159
1160 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1161 MAC2STR(src), wpa_s->dpp_auth->curr_freq,
1162 DPP_PA_AUTHENTICATION_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001163 offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq,
1164 src, wpa_s->own_addr, broadcast,
1165 wpabuf_head(wpa_s->dpp_auth->resp_msg),
1166 wpabuf_len(wpa_s->dpp_auth->resp_msg),
1167 500, wpas_dpp_tx_status, 0);
1168}
1169
1170
1171static void wpas_dpp_start_gas_server(struct wpa_supplicant *wpa_s)
1172{
1173 /* TODO: stop wait and start ROC */
1174}
1175
1176
1177static struct wpa_ssid * wpas_dpp_add_network(struct wpa_supplicant *wpa_s,
1178 struct dpp_authentication *auth)
1179{
1180 struct wpa_ssid *ssid;
1181
1182 ssid = wpa_config_add_network(wpa_s->conf);
1183 if (!ssid)
1184 return NULL;
1185 wpas_notify_network_added(wpa_s, ssid);
1186 wpa_config_set_network_defaults(ssid);
1187 ssid->disabled = 1;
1188
1189 ssid->ssid = os_malloc(auth->ssid_len);
1190 if (!ssid->ssid)
1191 goto fail;
1192 os_memcpy(ssid->ssid, auth->ssid, auth->ssid_len);
1193 ssid->ssid_len = auth->ssid_len;
1194
1195 if (auth->connector) {
1196 ssid->key_mgmt = WPA_KEY_MGMT_DPP;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001197 ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001198 ssid->dpp_connector = os_strdup(auth->connector);
1199 if (!ssid->dpp_connector)
1200 goto fail;
1201 }
1202
1203 if (auth->c_sign_key) {
1204 ssid->dpp_csign = os_malloc(wpabuf_len(auth->c_sign_key));
1205 if (!ssid->dpp_csign)
1206 goto fail;
1207 os_memcpy(ssid->dpp_csign, wpabuf_head(auth->c_sign_key),
1208 wpabuf_len(auth->c_sign_key));
1209 ssid->dpp_csign_len = wpabuf_len(auth->c_sign_key);
1210 }
1211
1212 if (auth->net_access_key) {
1213 ssid->dpp_netaccesskey =
1214 os_malloc(wpabuf_len(auth->net_access_key));
1215 if (!ssid->dpp_netaccesskey)
1216 goto fail;
1217 os_memcpy(ssid->dpp_netaccesskey,
1218 wpabuf_head(auth->net_access_key),
1219 wpabuf_len(auth->net_access_key));
1220 ssid->dpp_netaccesskey_len = wpabuf_len(auth->net_access_key);
1221 ssid->dpp_netaccesskey_expiry = auth->net_access_key_expiry;
1222 }
1223
1224 if (!auth->connector) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001225 ssid->key_mgmt = 0;
1226 if (auth->akm == DPP_AKM_PSK || auth->akm == DPP_AKM_PSK_SAE)
1227 ssid->key_mgmt |= WPA_KEY_MGMT_PSK |
1228 WPA_KEY_MGMT_PSK_SHA256 | WPA_KEY_MGMT_FT_PSK;
1229 if (auth->akm == DPP_AKM_SAE || auth->akm == DPP_AKM_PSK_SAE)
1230 ssid->key_mgmt |= WPA_KEY_MGMT_SAE |
1231 WPA_KEY_MGMT_FT_SAE;
1232 ssid->ieee80211w = MGMT_FRAME_PROTECTION_OPTIONAL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001233 if (auth->passphrase[0]) {
1234 if (wpa_config_set_quoted(ssid, "psk",
1235 auth->passphrase) < 0)
1236 goto fail;
1237 wpa_config_update_psk(ssid);
1238 ssid->export_keys = 1;
1239 } else {
1240 ssid->psk_set = auth->psk_set;
1241 os_memcpy(ssid->psk, auth->psk, PMK_LEN);
1242 }
1243 }
1244
1245 return ssid;
1246fail:
1247 wpas_notify_network_removed(wpa_s, ssid);
1248 wpa_config_remove_network(wpa_s->conf, ssid->id);
1249 return NULL;
1250}
1251
1252
1253static void wpas_dpp_process_config(struct wpa_supplicant *wpa_s,
1254 struct dpp_authentication *auth)
1255{
1256 struct wpa_ssid *ssid;
1257
1258 if (wpa_s->conf->dpp_config_processing < 1)
1259 return;
1260
1261 ssid = wpas_dpp_add_network(wpa_s, auth);
1262 if (!ssid)
1263 return;
1264
1265 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_NETWORK_ID "%d", ssid->id);
Hai Shalom59532852018-12-07 10:32:58 -08001266
1267 wpas_notify_dpp_config_received(wpa_s->ifname, ssid);
1268
1269 if (wpa_s->conf->dpp_config_processing < 2) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001270 return;
Hai Shalom59532852018-12-07 10:32:58 -08001271 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001272
1273 wpa_printf(MSG_DEBUG, "DPP: Trying to connect to the new network");
1274 ssid->disabled = 0;
1275 wpa_s->disconnected = 0;
1276 wpa_s->reassociate = 1;
1277 wpa_s->scan_runs = 0;
1278 wpa_s->normal_scans = 0;
1279 wpa_supplicant_cancel_sched_scan(wpa_s);
1280 wpa_supplicant_req_scan(wpa_s, 0, 0);
1281}
1282
1283
1284static void wpas_dpp_handle_config_obj(struct wpa_supplicant *wpa_s,
1285 struct dpp_authentication *auth)
1286{
1287 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
1288 if (auth->ssid_len)
1289 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s",
1290 wpa_ssid_txt(auth->ssid, auth->ssid_len));
1291 if (auth->connector) {
1292 /* TODO: Save the Connector and consider using a command
1293 * to fetch the value instead of sending an event with
1294 * it. The Connector could end up being larger than what
1295 * most clients are ready to receive as an event
1296 * message. */
1297 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONNECTOR "%s",
1298 auth->connector);
1299 }
1300 if (auth->c_sign_key) {
1301 char *hex;
1302 size_t hexlen;
1303
1304 hexlen = 2 * wpabuf_len(auth->c_sign_key) + 1;
1305 hex = os_malloc(hexlen);
1306 if (hex) {
1307 wpa_snprintf_hex(hex, hexlen,
1308 wpabuf_head(auth->c_sign_key),
1309 wpabuf_len(auth->c_sign_key));
1310 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_C_SIGN_KEY "%s",
1311 hex);
1312 os_free(hex);
1313 }
1314 }
1315 if (auth->net_access_key) {
1316 char *hex;
1317 size_t hexlen;
1318
1319 hexlen = 2 * wpabuf_len(auth->net_access_key) + 1;
1320 hex = os_malloc(hexlen);
1321 if (hex) {
1322 wpa_snprintf_hex(hex, hexlen,
1323 wpabuf_head(auth->net_access_key),
1324 wpabuf_len(auth->net_access_key));
1325 if (auth->net_access_key_expiry)
1326 wpa_msg(wpa_s, MSG_INFO,
1327 DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex,
1328 (long unsigned)
1329 auth->net_access_key_expiry);
1330 else
1331 wpa_msg(wpa_s, MSG_INFO,
1332 DPP_EVENT_NET_ACCESS_KEY "%s", hex);
1333 os_free(hex);
1334 }
1335 }
1336
1337 wpas_dpp_process_config(wpa_s, auth);
1338}
1339
1340
1341static void wpas_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token,
1342 enum gas_query_result result,
1343 const struct wpabuf *adv_proto,
1344 const struct wpabuf *resp, u16 status_code)
1345{
1346 struct wpa_supplicant *wpa_s = ctx;
1347 const u8 *pos;
1348 struct dpp_authentication *auth = wpa_s->dpp_auth;
1349
Roshan Pius3a1667e2018-07-03 15:17:14 -07001350 wpa_s->dpp_gas_dialog_token = -1;
1351
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001352 if (!auth || !auth->auth_success) {
1353 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
1354 return;
1355 }
1356 if (!resp || status_code != WLAN_STATUS_SUCCESS) {
1357 wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed");
1358 goto fail;
1359 }
1360
1361 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto",
1362 adv_proto);
1363 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)",
1364 resp);
1365
1366 if (wpabuf_len(adv_proto) != 10 ||
1367 !(pos = wpabuf_head(adv_proto)) ||
1368 pos[0] != WLAN_EID_ADV_PROTO ||
1369 pos[1] != 8 ||
1370 pos[3] != WLAN_EID_VENDOR_SPECIFIC ||
1371 pos[4] != 5 ||
1372 WPA_GET_BE24(&pos[5]) != OUI_WFA ||
1373 pos[8] != 0x1a ||
1374 pos[9] != 1) {
1375 wpa_printf(MSG_DEBUG,
1376 "DPP: Not a DPP Advertisement Protocol ID");
1377 goto fail;
1378 }
1379
1380 if (dpp_conf_resp_rx(auth, resp) < 0) {
1381 wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed");
1382 goto fail;
1383 }
1384
1385 wpas_dpp_handle_config_obj(wpa_s, auth);
1386 dpp_auth_deinit(wpa_s->dpp_auth);
1387 wpa_s->dpp_auth = NULL;
1388 return;
1389
1390fail:
1391 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom59532852018-12-07 10:32:58 -08001392 wpas_notify_dpp_configuration_failure(wpa_s->ifname);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001393 dpp_auth_deinit(wpa_s->dpp_auth);
1394 wpa_s->dpp_auth = NULL;
1395}
1396
1397
1398static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
1399{
1400 struct dpp_authentication *auth = wpa_s->dpp_auth;
1401 struct wpabuf *buf, *conf_req;
1402 char json[100];
1403 int res;
1404
1405 wpa_s->dpp_gas_client = 1;
1406 os_snprintf(json, sizeof(json),
1407 "{\"name\":\"Test\","
1408 "\"wi-fi_tech\":\"infra\","
1409 "\"netRole\":\"%s\"}",
1410 wpa_s->dpp_netrole_ap ? "ap" : "sta");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001411#ifdef CONFIG_TESTING_OPTIONS
1412 if (dpp_test == DPP_TEST_INVALID_CONFIG_ATTR_OBJ_CONF_REQ) {
1413 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Config Attr");
1414 json[29] = 'k'; /* replace "infra" with "knfra" */
1415 }
1416#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001417 wpa_printf(MSG_DEBUG, "DPP: GAS Config Attributes: %s", json);
1418
1419 offchannel_send_action_done(wpa_s);
1420 wpas_dpp_listen_stop(wpa_s);
1421
1422 conf_req = dpp_build_conf_req(auth, json);
1423 if (!conf_req) {
1424 wpa_printf(MSG_DEBUG,
1425 "DPP: No configuration request data available");
1426 return;
1427 }
1428
1429 buf = gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req));
1430 if (!buf) {
1431 wpabuf_free(conf_req);
1432 return;
1433 }
1434
1435 /* Advertisement Protocol IE */
1436 wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO);
1437 wpabuf_put_u8(buf, 8); /* Length */
1438 wpabuf_put_u8(buf, 0x7f);
1439 wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
1440 wpabuf_put_u8(buf, 5);
1441 wpabuf_put_be24(buf, OUI_WFA);
1442 wpabuf_put_u8(buf, DPP_OUI_TYPE);
1443 wpabuf_put_u8(buf, 0x01);
1444
1445 /* GAS Query */
1446 wpabuf_put_le16(buf, wpabuf_len(conf_req));
1447 wpabuf_put_buf(buf, conf_req);
1448 wpabuf_free(conf_req);
1449
1450 wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
1451 MAC2STR(auth->peer_mac_addr), auth->curr_freq);
1452
1453 res = gas_query_req(wpa_s->gas, auth->peer_mac_addr, auth->curr_freq,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001454 1, buf, wpas_dpp_gas_resp_cb, wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001455 if (res < 0) {
1456 wpa_msg(wpa_s, MSG_DEBUG, "GAS: Failed to send Query Request");
1457 wpabuf_free(buf);
1458 } else {
1459 wpa_printf(MSG_DEBUG,
1460 "DPP: GAS query started with dialog token %u", res);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001461 wpa_s->dpp_gas_dialog_token = res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001462 }
1463}
1464
1465
1466static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator)
1467{
1468 wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded");
1469 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d", initiator);
Hai Shalom59532852018-12-07 10:32:58 -08001470 wpas_notify_dpp_auth_success(wpa_s->ifname);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001471#ifdef CONFIG_TESTING_OPTIONS
1472 if (dpp_test == DPP_TEST_STOP_AT_AUTH_CONF) {
1473 wpa_printf(MSG_INFO,
1474 "DPP: TESTING - stop at Authentication Confirm");
1475 if (wpa_s->dpp_auth->configurator) {
1476 /* Prevent GAS response */
1477 wpa_s->dpp_auth->auth_success = 0;
1478 }
1479 return;
1480 }
1481#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001482
1483 if (wpa_s->dpp_auth->configurator)
1484 wpas_dpp_start_gas_server(wpa_s);
1485 else
1486 wpas_dpp_start_gas_client(wpa_s);
1487}
1488
1489
1490static void wpas_dpp_rx_auth_resp(struct wpa_supplicant *wpa_s, const u8 *src,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001491 const u8 *hdr, const u8 *buf, size_t len,
1492 unsigned int freq)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001493{
1494 struct dpp_authentication *auth = wpa_s->dpp_auth;
1495 struct wpabuf *msg;
1496
Roshan Pius3a1667e2018-07-03 15:17:14 -07001497 wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR
1498 " (freq %u MHz)", MAC2STR(src), freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001499
1500 if (!auth) {
1501 wpa_printf(MSG_DEBUG,
1502 "DPP: No DPP Authentication in progress - drop");
1503 return;
1504 }
1505
1506 if (!is_zero_ether_addr(auth->peer_mac_addr) &&
1507 os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1508 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1509 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1510 return;
1511 }
1512
1513 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
1514
Roshan Pius3a1667e2018-07-03 15:17:14 -07001515 if (auth->curr_freq != freq && auth->neg_freq == freq) {
1516 wpa_printf(MSG_DEBUG,
1517 "DPP: Responder accepted request for different negotiation channel");
1518 auth->curr_freq = freq;
1519 }
1520
1521 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001522 msg = dpp_auth_resp_rx(auth, hdr, buf, len);
1523 if (!msg) {
1524 if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) {
1525 wpa_printf(MSG_DEBUG,
1526 "DPP: Start wait for full response");
Hai Shalom59532852018-12-07 10:32:58 -08001527 wpas_notify_dpp_resp_pending(wpa_s->ifname);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001528 offchannel_send_action_done(wpa_s);
1529 wpas_dpp_listen_start(wpa_s, auth->curr_freq);
1530 return;
1531 }
1532 wpa_printf(MSG_DEBUG, "DPP: No confirm generated");
Hai Shalom59532852018-12-07 10:32:58 -08001533 wpas_notify_dpp_auth_failure(wpa_s->ifname);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001534 return;
1535 }
1536 os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
1537
Roshan Pius3a1667e2018-07-03 15:17:14 -07001538 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1539 MAC2STR(src), auth->curr_freq, DPP_PA_AUTHENTICATION_CONF);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001540 offchannel_send_action(wpa_s, auth->curr_freq,
1541 src, wpa_s->own_addr, broadcast,
1542 wpabuf_head(msg), wpabuf_len(msg),
1543 500, wpas_dpp_tx_status, 0);
1544 wpabuf_free(msg);
1545 wpa_s->dpp_auth_ok_on_ack = 1;
1546}
1547
1548
1549static void wpas_dpp_rx_auth_conf(struct wpa_supplicant *wpa_s, const u8 *src,
1550 const u8 *hdr, const u8 *buf, size_t len)
1551{
1552 struct dpp_authentication *auth = wpa_s->dpp_auth;
1553
1554 wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR,
1555 MAC2STR(src));
1556
1557 if (!auth) {
1558 wpa_printf(MSG_DEBUG,
1559 "DPP: No DPP Authentication in progress - drop");
1560 return;
1561 }
1562
1563 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1564 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1565 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1566 return;
1567 }
1568
1569 if (dpp_auth_conf_rx(auth, hdr, buf, len) < 0) {
1570 wpa_printf(MSG_DEBUG, "DPP: Authentication failed");
Hai Shalom59532852018-12-07 10:32:58 -08001571 wpas_notify_dpp_auth_failure(wpa_s->ifname);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001572 return;
1573 }
1574
1575 wpas_dpp_auth_success(wpa_s, 0);
1576}
1577
1578
1579static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant *wpa_s,
1580 const u8 *src,
1581 const u8 *buf, size_t len)
1582{
1583 struct wpa_ssid *ssid;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001584 const u8 *connector, *trans_id, *status;
1585 u16 connector_len, trans_id_len, status_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001586 struct dpp_introduction intro;
1587 struct rsn_pmksa_cache_entry *entry;
1588 struct os_time now;
1589 struct os_reltime rnow;
1590 os_time_t expiry;
1591 unsigned int seconds;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001592 enum dpp_status_error res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001593
1594 wpa_printf(MSG_DEBUG, "DPP: Peer Discovery Response from " MACSTR,
1595 MAC2STR(src));
1596 if (is_zero_ether_addr(wpa_s->dpp_intro_bssid) ||
1597 os_memcmp(src, wpa_s->dpp_intro_bssid, ETH_ALEN) != 0) {
1598 wpa_printf(MSG_DEBUG, "DPP: Not waiting for response from "
1599 MACSTR " - drop", MAC2STR(src));
1600 return;
1601 }
1602 offchannel_send_action_done(wpa_s);
1603
1604 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1605 if (ssid == wpa_s->dpp_intro_network)
1606 break;
1607 }
1608 if (!ssid || !ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1609 !ssid->dpp_csign) {
1610 wpa_printf(MSG_DEBUG,
1611 "DPP: Profile not found for network introduction");
1612 return;
1613 }
1614
1615 trans_id = dpp_get_attr(buf, len, DPP_ATTR_TRANSACTION_ID,
1616 &trans_id_len);
1617 if (!trans_id || trans_id_len != 1) {
1618 wpa_printf(MSG_DEBUG,
1619 "DPP: Peer did not include Transaction ID");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001620 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1621 " fail=missing_transaction_id", MAC2STR(src));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001622 goto fail;
1623 }
1624 if (trans_id[0] != TRANSACTION_ID) {
1625 wpa_printf(MSG_DEBUG,
1626 "DPP: Ignore frame with unexpected Transaction ID %u",
1627 trans_id[0]);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001628 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1629 " fail=transaction_id_mismatch", MAC2STR(src));
1630 goto fail;
1631 }
1632
1633 status = dpp_get_attr(buf, len, DPP_ATTR_STATUS, &status_len);
1634 if (!status || status_len != 1) {
1635 wpa_printf(MSG_DEBUG, "DPP: Peer did not include Status");
1636 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1637 " fail=missing_status", MAC2STR(src));
1638 goto fail;
1639 }
1640 if (status[0] != DPP_STATUS_OK) {
1641 wpa_printf(MSG_DEBUG,
1642 "DPP: Peer rejected network introduction: Status %u",
1643 status[0]);
1644 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1645 " status=%u", MAC2STR(src), status[0]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001646 goto fail;
1647 }
1648
1649 connector = dpp_get_attr(buf, len, DPP_ATTR_CONNECTOR, &connector_len);
1650 if (!connector) {
1651 wpa_printf(MSG_DEBUG,
1652 "DPP: Peer did not include its Connector");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001653 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1654 " fail=missing_connector", MAC2STR(src));
1655 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001656 }
1657
Roshan Pius3a1667e2018-07-03 15:17:14 -07001658 res = dpp_peer_intro(&intro, ssid->dpp_connector,
1659 ssid->dpp_netaccesskey,
1660 ssid->dpp_netaccesskey_len,
1661 ssid->dpp_csign,
1662 ssid->dpp_csign_len,
1663 connector, connector_len, &expiry);
1664 if (res != DPP_STATUS_OK) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001665 wpa_printf(MSG_INFO,
1666 "DPP: Network Introduction protocol resulted in failure");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001667 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1668 " fail=peer_connector_validation_failed", MAC2STR(src));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001669 goto fail;
1670 }
1671
1672 entry = os_zalloc(sizeof(*entry));
1673 if (!entry)
1674 goto fail;
1675 os_memcpy(entry->aa, src, ETH_ALEN);
1676 os_memcpy(entry->pmkid, intro.pmkid, PMKID_LEN);
1677 os_memcpy(entry->pmk, intro.pmk, intro.pmk_len);
1678 entry->pmk_len = intro.pmk_len;
1679 entry->akmp = WPA_KEY_MGMT_DPP;
1680 if (expiry) {
1681 os_get_time(&now);
1682 seconds = expiry - now.sec;
1683 } else {
1684 seconds = 86400 * 7;
1685 }
1686 os_get_reltime(&rnow);
1687 entry->expiration = rnow.sec + seconds;
1688 entry->reauth_time = rnow.sec + seconds;
1689 entry->network_ctx = ssid;
1690 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
1691
Roshan Pius3a1667e2018-07-03 15:17:14 -07001692 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
1693 " status=%u", MAC2STR(src), status[0]);
1694
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001695 wpa_printf(MSG_DEBUG,
1696 "DPP: Try connection again after successful network introduction");
1697 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
1698 wpa_supplicant_cancel_sched_scan(wpa_s);
1699 wpa_supplicant_req_scan(wpa_s, 0, 0);
1700 }
1701fail:
1702 os_memset(&intro, 0, sizeof(intro));
1703}
1704
1705
Roshan Pius3a1667e2018-07-03 15:17:14 -07001706static int wpas_dpp_allow_ir(struct wpa_supplicant *wpa_s, unsigned int freq)
1707{
1708 int i, j;
1709
1710 if (!wpa_s->hw.modes)
1711 return -1;
1712
1713 for (i = 0; i < wpa_s->hw.num_modes; i++) {
1714 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
1715
1716 for (j = 0; j < mode->num_channels; j++) {
1717 struct hostapd_channel_data *chan = &mode->channels[j];
1718
1719 if (chan->freq != (int) freq)
1720 continue;
1721
1722 if (chan->flag & (HOSTAPD_CHAN_DISABLED |
1723 HOSTAPD_CHAN_NO_IR |
1724 HOSTAPD_CHAN_RADAR))
1725 continue;
1726
1727 return 1;
1728 }
1729 }
1730
1731 wpa_printf(MSG_DEBUG,
1732 "DPP: Frequency %u MHz not supported or does not allow PKEX initiation in the current channel list",
1733 freq);
1734
1735 return 0;
1736}
1737
1738
1739static int wpas_dpp_pkex_next_channel(struct wpa_supplicant *wpa_s,
1740 struct dpp_pkex *pkex)
1741{
1742 if (pkex->freq == 2437)
1743 pkex->freq = 5745;
1744 else if (pkex->freq == 5745)
1745 pkex->freq = 5220;
1746 else if (pkex->freq == 5220)
1747 pkex->freq = 60480;
1748 else
1749 return -1; /* no more channels to try */
1750
1751 if (wpas_dpp_allow_ir(wpa_s, pkex->freq) == 1) {
1752 wpa_printf(MSG_DEBUG, "DPP: Try to initiate on %u MHz",
1753 pkex->freq);
1754 return 0;
1755 }
1756
1757 /* Could not use this channel - try the next one */
1758 return wpas_dpp_pkex_next_channel(wpa_s, pkex);
1759}
1760
1761
1762static void wpas_dpp_pkex_retry_timeout(void *eloop_ctx, void *timeout_ctx)
1763{
1764 struct wpa_supplicant *wpa_s = eloop_ctx;
1765 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1766
1767 if (!pkex || !pkex->exchange_req)
1768 return;
1769 if (pkex->exch_req_tries >= 5) {
1770 if (wpas_dpp_pkex_next_channel(wpa_s, pkex) < 0) {
1771 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
1772 "No response from PKEX peer");
1773 dpp_pkex_free(pkex);
1774 wpa_s->dpp_pkex = NULL;
1775 return;
1776 }
1777 pkex->exch_req_tries = 0;
1778 }
1779
1780 pkex->exch_req_tries++;
1781 wpa_printf(MSG_DEBUG, "DPP: Retransmit PKEX Exchange Request (try %u)",
1782 pkex->exch_req_tries);
1783 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1784 MAC2STR(broadcast), pkex->freq, DPP_PA_PKEX_EXCHANGE_REQ);
1785 offchannel_send_action(wpa_s, pkex->freq, broadcast,
1786 wpa_s->own_addr, broadcast,
1787 wpabuf_head(pkex->exchange_req),
1788 wpabuf_len(pkex->exchange_req),
1789 pkex->exch_req_wait_time,
1790 wpas_dpp_tx_pkex_status, 0);
1791}
1792
1793
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001794static void
1795wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s,
1796 unsigned int freq, const u8 *dst,
1797 const u8 *src, const u8 *bssid,
1798 const u8 *data, size_t data_len,
1799 enum offchannel_send_action_result result)
1800{
Roshan Pius3a1667e2018-07-03 15:17:14 -07001801 const char *res_txt;
1802 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1803
1804 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
1805 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
1806 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001807 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
1808 " result=%s (PKEX)",
Roshan Pius3a1667e2018-07-03 15:17:14 -07001809 freq, MAC2STR(dst), res_txt);
1810 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
1811 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
1812
1813 if (!pkex) {
1814 wpa_printf(MSG_DEBUG,
1815 "DPP: Ignore TX status since there is no ongoing PKEX exchange");
1816 return;
1817 }
1818
1819 if (pkex->failed) {
1820 wpa_printf(MSG_DEBUG,
1821 "DPP: Terminate PKEX exchange due to an earlier error");
1822 if (pkex->t > pkex->own_bi->pkex_t)
1823 pkex->own_bi->pkex_t = pkex->t;
1824 dpp_pkex_free(pkex);
1825 wpa_s->dpp_pkex = NULL;
1826 return;
1827 }
1828
1829 if (pkex->exch_req_wait_time && pkex->exchange_req) {
1830 /* Wait for PKEX Exchange Response frame and retry request if
1831 * no response is seen. */
1832 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
1833 eloop_register_timeout(pkex->exch_req_wait_time / 1000,
1834 (pkex->exch_req_wait_time % 1000) * 1000,
1835 wpas_dpp_pkex_retry_timeout, wpa_s,
1836 NULL);
1837 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001838}
1839
1840
1841static void
1842wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant *wpa_s, const u8 *src,
1843 const u8 *buf, size_t len, unsigned int freq)
1844{
1845 struct wpabuf *msg;
1846 unsigned int wait_time;
1847
1848 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Request from " MACSTR,
1849 MAC2STR(src));
1850
1851 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1852 * values here */
1853
1854 if (!wpa_s->dpp_pkex_code || !wpa_s->dpp_pkex_bi) {
1855 wpa_printf(MSG_DEBUG,
1856 "DPP: No PKEX code configured - ignore request");
1857 return;
1858 }
1859
1860 if (wpa_s->dpp_pkex) {
1861 /* TODO: Support parallel operations */
1862 wpa_printf(MSG_DEBUG,
1863 "DPP: Already in PKEX session - ignore new request");
1864 return;
1865 }
1866
Roshan Pius3a1667e2018-07-03 15:17:14 -07001867 wpa_s->dpp_pkex = dpp_pkex_rx_exchange_req(wpa_s, wpa_s->dpp_pkex_bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001868 wpa_s->own_addr, src,
1869 wpa_s->dpp_pkex_identifier,
1870 wpa_s->dpp_pkex_code,
1871 buf, len);
1872 if (!wpa_s->dpp_pkex) {
1873 wpa_printf(MSG_DEBUG,
1874 "DPP: Failed to process the request - ignore it");
1875 return;
1876 }
1877
1878 msg = wpa_s->dpp_pkex->exchange_resp;
1879 wait_time = wpa_s->max_remain_on_chan;
1880 if (wait_time > 2000)
1881 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001882 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1883 MAC2STR(src), freq, DPP_PA_PKEX_EXCHANGE_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001884 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
1885 broadcast,
1886 wpabuf_head(msg), wpabuf_len(msg),
1887 wait_time, wpas_dpp_tx_pkex_status, 0);
1888}
1889
1890
1891static void
1892wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant *wpa_s, const u8 *src,
1893 const u8 *buf, size_t len, unsigned int freq)
1894{
1895 struct wpabuf *msg;
1896 unsigned int wait_time;
1897
1898 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Response from " MACSTR,
1899 MAC2STR(src));
1900
1901 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1902 * values here */
1903
1904 if (!wpa_s->dpp_pkex || !wpa_s->dpp_pkex->initiator ||
1905 wpa_s->dpp_pkex->exchange_done) {
1906 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1907 return;
1908 }
1909
Roshan Pius3a1667e2018-07-03 15:17:14 -07001910 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
1911 wpa_s->dpp_pkex->exch_req_wait_time = 0;
1912
1913 msg = dpp_pkex_rx_exchange_resp(wpa_s->dpp_pkex, src, buf, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001914 if (!msg) {
1915 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
1916 return;
1917 }
1918
1919 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Request to " MACSTR,
1920 MAC2STR(src));
1921
1922 wait_time = wpa_s->max_remain_on_chan;
1923 if (wait_time > 2000)
1924 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001925 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
1926 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_REQ);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001927 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
1928 broadcast,
1929 wpabuf_head(msg), wpabuf_len(msg),
1930 wait_time, wpas_dpp_tx_pkex_status, 0);
1931 wpabuf_free(msg);
1932}
1933
1934
Roshan Pius3a1667e2018-07-03 15:17:14 -07001935static struct dpp_bootstrap_info *
1936wpas_dpp_pkex_finish(struct wpa_supplicant *wpa_s, const u8 *peer,
1937 unsigned int freq)
1938{
1939 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
1940 struct dpp_bootstrap_info *bi;
1941
1942 bi = os_zalloc(sizeof(*bi));
1943 if (!bi)
1944 return NULL;
1945 bi->id = wpas_dpp_next_id(wpa_s);
1946 bi->type = DPP_BOOTSTRAP_PKEX;
1947 os_memcpy(bi->mac_addr, peer, ETH_ALEN);
1948 bi->num_freq = 1;
1949 bi->freq[0] = freq;
1950 bi->curve = pkex->own_bi->curve;
1951 bi->pubkey = pkex->peer_bootstrap_key;
1952 pkex->peer_bootstrap_key = NULL;
1953 dpp_pkex_free(pkex);
1954 wpa_s->dpp_pkex = NULL;
1955 if (dpp_bootstrap_key_hash(bi) < 0) {
1956 dpp_bootstrap_info_free(bi);
1957 return NULL;
1958 }
1959 dl_list_add(&wpa_s->dpp_bootstrap, &bi->list);
1960 return bi;
1961}
1962
1963
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001964static void
1965wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant *wpa_s, const u8 *src,
1966 const u8 *hdr, const u8 *buf, size_t len,
1967 unsigned int freq)
1968{
1969 struct wpabuf *msg;
1970 unsigned int wait_time;
1971 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001972
1973 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Request from " MACSTR,
1974 MAC2STR(src));
1975
1976 if (!pkex || pkex->initiator || !pkex->exchange_done) {
1977 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1978 return;
1979 }
1980
1981 msg = dpp_pkex_rx_commit_reveal_req(pkex, hdr, buf, len);
1982 if (!msg) {
1983 wpa_printf(MSG_DEBUG, "DPP: Failed to process the request");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001984 if (pkex->failed) {
1985 wpa_printf(MSG_DEBUG, "DPP: Terminate PKEX exchange");
1986 if (pkex->t > pkex->own_bi->pkex_t)
1987 pkex->own_bi->pkex_t = pkex->t;
1988 dpp_pkex_free(wpa_s->dpp_pkex);
1989 wpa_s->dpp_pkex = NULL;
1990 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001991 return;
1992 }
1993
1994 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Response to "
1995 MACSTR, MAC2STR(src));
1996
1997 wait_time = wpa_s->max_remain_on_chan;
1998 if (wait_time > 2000)
1999 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002000 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2001 MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002002 offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
2003 broadcast,
2004 wpabuf_head(msg), wpabuf_len(msg),
2005 wait_time, wpas_dpp_tx_pkex_status, 0);
2006 wpabuf_free(msg);
2007
Roshan Pius3a1667e2018-07-03 15:17:14 -07002008 wpas_dpp_pkex_finish(wpa_s, src, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002009}
2010
2011
2012static void
2013wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant *wpa_s, const u8 *src,
2014 const u8 *hdr, const u8 *buf, size_t len,
2015 unsigned int freq)
2016{
2017 int res;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002018 struct dpp_bootstrap_info *bi;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002019 struct dpp_pkex *pkex = wpa_s->dpp_pkex;
2020 char cmd[500];
2021
2022 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Response from " MACSTR,
2023 MAC2STR(src));
2024
2025 if (!pkex || !pkex->initiator || !pkex->exchange_done) {
2026 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
2027 return;
2028 }
2029
2030 res = dpp_pkex_rx_commit_reveal_resp(pkex, hdr, buf, len);
2031 if (res < 0) {
2032 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
2033 return;
2034 }
2035
Roshan Pius3a1667e2018-07-03 15:17:14 -07002036 bi = wpas_dpp_pkex_finish(wpa_s, src, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002037 if (!bi)
2038 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002039
2040 os_snprintf(cmd, sizeof(cmd), " peer=%u %s",
2041 bi->id,
2042 wpa_s->dpp_pkex_auth_cmd ? wpa_s->dpp_pkex_auth_cmd : "");
2043 wpa_printf(MSG_DEBUG,
2044 "DPP: Start authentication after PKEX with parameters: %s",
2045 cmd);
2046 if (wpas_dpp_auth_init(wpa_s, cmd) < 0) {
2047 wpa_printf(MSG_DEBUG,
2048 "DPP: Authentication initialization failed");
2049 return;
2050 }
2051}
2052
2053
2054void wpas_dpp_rx_action(struct wpa_supplicant *wpa_s, const u8 *src,
2055 const u8 *buf, size_t len, unsigned int freq)
2056{
2057 u8 crypto_suite;
2058 enum dpp_public_action_frame_type type;
2059 const u8 *hdr;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002060 unsigned int pkex_t;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002061
2062 if (len < DPP_HDR_LEN)
2063 return;
2064 if (WPA_GET_BE24(buf) != OUI_WFA || buf[3] != DPP_OUI_TYPE)
2065 return;
2066 hdr = buf;
2067 buf += 4;
2068 len -= 4;
2069 crypto_suite = *buf++;
2070 type = *buf++;
2071 len -= 2;
2072
2073 wpa_printf(MSG_DEBUG,
2074 "DPP: Received DPP Public Action frame crypto suite %u type %d from "
2075 MACSTR " freq=%u",
2076 crypto_suite, type, MAC2STR(src), freq);
2077 if (crypto_suite != 1) {
2078 wpa_printf(MSG_DEBUG, "DPP: Unsupported crypto suite %u",
2079 crypto_suite);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002080 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
2081 " freq=%u type=%d ignore=unsupported-crypto-suite",
2082 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002083 return;
2084 }
2085 wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002086 if (dpp_check_attrs(buf, len) < 0) {
2087 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
2088 " freq=%u type=%d ignore=invalid-attributes",
2089 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002090 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002091 }
2092 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR " freq=%u type=%d",
2093 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002094
2095 switch (type) {
2096 case DPP_PA_AUTHENTICATION_REQ:
2097 wpas_dpp_rx_auth_req(wpa_s, src, hdr, buf, len, freq);
2098 break;
2099 case DPP_PA_AUTHENTICATION_RESP:
Roshan Pius3a1667e2018-07-03 15:17:14 -07002100 wpas_dpp_rx_auth_resp(wpa_s, src, hdr, buf, len, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002101 break;
2102 case DPP_PA_AUTHENTICATION_CONF:
2103 wpas_dpp_rx_auth_conf(wpa_s, src, hdr, buf, len);
2104 break;
2105 case DPP_PA_PEER_DISCOVERY_RESP:
2106 wpas_dpp_rx_peer_disc_resp(wpa_s, src, buf, len);
2107 break;
2108 case DPP_PA_PKEX_EXCHANGE_REQ:
2109 wpas_dpp_rx_pkex_exchange_req(wpa_s, src, buf, len, freq);
2110 break;
2111 case DPP_PA_PKEX_EXCHANGE_RESP:
2112 wpas_dpp_rx_pkex_exchange_resp(wpa_s, src, buf, len, freq);
2113 break;
2114 case DPP_PA_PKEX_COMMIT_REVEAL_REQ:
2115 wpas_dpp_rx_pkex_commit_reveal_req(wpa_s, src, hdr, buf, len,
2116 freq);
2117 break;
2118 case DPP_PA_PKEX_COMMIT_REVEAL_RESP:
2119 wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s, src, hdr, buf, len,
2120 freq);
2121 break;
2122 default:
2123 wpa_printf(MSG_DEBUG,
2124 "DPP: Ignored unsupported frame subtype %d", type);
2125 break;
2126 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002127
2128 if (wpa_s->dpp_pkex)
2129 pkex_t = wpa_s->dpp_pkex->t;
2130 else if (wpa_s->dpp_pkex_bi)
2131 pkex_t = wpa_s->dpp_pkex_bi->pkex_t;
2132 else
2133 pkex_t = 0;
2134 if (pkex_t >= PKEX_COUNTER_T_LIMIT) {
2135 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_PKEX_T_LIMIT "id=0");
2136 wpas_dpp_pkex_remove(wpa_s, "*");
2137 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002138}
2139
2140
2141static struct wpabuf *
2142wpas_dpp_gas_req_handler(void *ctx, const u8 *sa, const u8 *query,
2143 size_t query_len)
2144{
2145 struct wpa_supplicant *wpa_s = ctx;
2146 struct dpp_authentication *auth = wpa_s->dpp_auth;
2147 struct wpabuf *resp;
2148
2149 wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR,
2150 MAC2STR(sa));
2151 if (!auth || !auth->auth_success ||
2152 os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) {
2153 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
2154 return NULL;
2155 }
2156 wpa_hexdump(MSG_DEBUG,
2157 "DPP: Received Configuration Request (GAS Query Request)",
2158 query, query_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002159 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_REQ_RX "src=" MACSTR,
2160 MAC2STR(sa));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002161 resp = dpp_conf_req_rx(auth, query, query_len);
Hai Shalom59532852018-12-07 10:32:58 -08002162 if (!resp) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002163 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom59532852018-12-07 10:32:58 -08002164 wpas_notify_dpp_configuration_failure(wpa_s->ifname);
2165 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002166 auth->conf_resp = resp;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002167 return resp;
2168}
2169
2170
2171static void
2172wpas_dpp_gas_status_handler(void *ctx, struct wpabuf *resp, int ok)
2173{
2174 struct wpa_supplicant *wpa_s = ctx;
2175 struct dpp_authentication *auth = wpa_s->dpp_auth;
2176
2177 if (!auth) {
2178 wpabuf_free(resp);
2179 return;
2180 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002181 if (auth->conf_resp != resp) {
2182 wpa_printf(MSG_DEBUG,
2183 "DPP: Ignore GAS status report (ok=%d) for unknown response",
2184 ok);
2185 wpabuf_free(resp);
2186 return;
2187 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002188
2189 wpa_printf(MSG_DEBUG, "DPP: Configuration exchange completed (ok=%d)",
2190 ok);
2191 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002192 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002193 offchannel_send_action_done(wpa_s);
2194 wpas_dpp_listen_stop(wpa_s);
Hai Shalom59532852018-12-07 10:32:58 -08002195 if (ok) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002196 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
Hai Shalom59532852018-12-07 10:32:58 -08002197 wpas_notify_dpp_config_sent(wpa_s->ifname);
2198 }
2199 else {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002200 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
Hai Shalom59532852018-12-07 10:32:58 -08002201 wpas_notify_dpp_configuration_failure(wpa_s->ifname);
2202 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002203 dpp_auth_deinit(wpa_s->dpp_auth);
2204 wpa_s->dpp_auth = NULL;
2205 wpabuf_free(resp);
2206}
2207
2208
2209static unsigned int wpas_dpp_next_configurator_id(struct wpa_supplicant *wpa_s)
2210{
2211 struct dpp_configurator *conf;
2212 unsigned int max_id = 0;
2213
2214 dl_list_for_each(conf, &wpa_s->dpp_configurator,
2215 struct dpp_configurator, list) {
2216 if (conf->id > max_id)
2217 max_id = conf->id;
2218 }
2219 return max_id + 1;
2220}
2221
2222
2223int wpas_dpp_configurator_add(struct wpa_supplicant *wpa_s, const char *cmd)
2224{
2225 char *curve = NULL;
2226 char *key = NULL;
2227 u8 *privkey = NULL;
2228 size_t privkey_len = 0;
2229 int ret = -1;
2230 struct dpp_configurator *conf = NULL;
2231
2232 curve = get_param(cmd, " curve=");
2233 key = get_param(cmd, " key=");
2234
2235 if (key) {
2236 privkey_len = os_strlen(key) / 2;
2237 privkey = os_malloc(privkey_len);
2238 if (!privkey ||
2239 hexstr2bin(key, privkey, privkey_len) < 0)
2240 goto fail;
2241 }
2242
2243 conf = dpp_keygen_configurator(curve, privkey, privkey_len);
2244 if (!conf)
2245 goto fail;
2246
2247 conf->id = wpas_dpp_next_configurator_id(wpa_s);
2248 dl_list_add(&wpa_s->dpp_configurator, &conf->list);
2249 ret = conf->id;
2250 conf = NULL;
2251fail:
2252 os_free(curve);
2253 str_clear_free(key);
2254 bin_clear_free(privkey, privkey_len);
2255 dpp_configurator_free(conf);
2256 return ret;
2257}
2258
2259
2260static int dpp_configurator_del(struct wpa_supplicant *wpa_s, unsigned int id)
2261{
2262 struct dpp_configurator *conf, *tmp;
2263 int found = 0;
2264
2265 dl_list_for_each_safe(conf, tmp, &wpa_s->dpp_configurator,
2266 struct dpp_configurator, list) {
2267 if (id && conf->id != id)
2268 continue;
2269 found = 1;
2270 dl_list_del(&conf->list);
2271 dpp_configurator_free(conf);
2272 }
2273
2274 if (id == 0)
2275 return 0; /* flush succeeds regardless of entries found */
2276 return found ? 0 : -1;
2277}
2278
2279
2280int wpas_dpp_configurator_remove(struct wpa_supplicant *wpa_s, const char *id)
2281{
2282 unsigned int id_val;
2283
2284 if (os_strcmp(id, "*") == 0) {
2285 id_val = 0;
2286 } else {
2287 id_val = atoi(id);
2288 if (id_val == 0)
2289 return -1;
2290 }
2291
2292 return dpp_configurator_del(wpa_s, id_val);
2293}
2294
2295
2296int wpas_dpp_configurator_sign(struct wpa_supplicant *wpa_s, const char *cmd)
2297{
2298 struct dpp_authentication *auth;
2299 int ret = -1;
2300 char *curve = NULL;
2301
2302 auth = os_zalloc(sizeof(*auth));
2303 if (!auth)
2304 return -1;
2305
2306 curve = get_param(cmd, " curve=");
2307 wpas_dpp_set_configurator(wpa_s, auth, cmd);
2308
Roshan Pius3a1667e2018-07-03 15:17:14 -07002309 if (dpp_configurator_own_config(auth, curve, 0) == 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002310 wpas_dpp_handle_config_obj(wpa_s, auth);
2311 ret = 0;
2312 }
2313
2314 dpp_auth_deinit(auth);
2315 os_free(curve);
2316
2317 return ret;
2318}
2319
2320
Roshan Pius3a1667e2018-07-03 15:17:14 -07002321int wpas_dpp_configurator_get_key(struct wpa_supplicant *wpa_s, unsigned int id,
2322 char *buf, size_t buflen)
2323{
2324 struct dpp_configurator *conf;
2325
2326 conf = dpp_configurator_get_id(wpa_s, id);
2327 if (!conf)
2328 return -1;
2329
2330 return dpp_configurator_get_key(conf, buf, buflen);
2331}
2332
2333
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002334static void
2335wpas_dpp_tx_introduction_status(struct wpa_supplicant *wpa_s,
2336 unsigned int freq, const u8 *dst,
2337 const u8 *src, const u8 *bssid,
2338 const u8 *data, size_t data_len,
2339 enum offchannel_send_action_result result)
2340{
Roshan Pius3a1667e2018-07-03 15:17:14 -07002341 const char *res_txt;
2342
2343 res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
2344 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
2345 "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002346 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
2347 " result=%s (DPP Peer Discovery Request)",
Roshan Pius3a1667e2018-07-03 15:17:14 -07002348 freq, MAC2STR(dst), res_txt);
2349 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
2350 " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002351 /* TODO: Time out wait for response more quickly in error cases? */
2352}
2353
2354
2355int wpas_dpp_check_connect(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2356 struct wpa_bss *bss)
2357{
2358 struct os_time now;
2359 struct wpabuf *msg;
2360 unsigned int wait_time;
2361
2362 if (!(ssid->key_mgmt & WPA_KEY_MGMT_DPP) || !bss)
2363 return 0; /* Not using DPP AKM - continue */
2364 if (wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid))
2365 return 0; /* PMKSA exists for DPP AKM - continue */
2366
2367 if (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
2368 !ssid->dpp_csign) {
2369 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
2370 "missing %s",
2371 !ssid->dpp_connector ? "Connector" :
2372 (!ssid->dpp_netaccesskey ? "netAccessKey" :
2373 "C-sign-key"));
2374 return -1;
2375 }
2376
2377 os_get_time(&now);
2378
2379 if (ssid->dpp_netaccesskey_expiry &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07002380 (os_time_t) ssid->dpp_netaccesskey_expiry < now.sec) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002381 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
2382 "netAccessKey expired");
2383 return -1;
2384 }
2385
2386 wpa_printf(MSG_DEBUG,
2387 "DPP: Starting network introduction protocol to derive PMKSA for "
2388 MACSTR, MAC2STR(bss->bssid));
2389
2390 msg = dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ,
2391 5 + 4 + os_strlen(ssid->dpp_connector));
2392 if (!msg)
2393 return -1;
2394
Roshan Pius3a1667e2018-07-03 15:17:14 -07002395#ifdef CONFIG_TESTING_OPTIONS
2396 if (dpp_test == DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ) {
2397 wpa_printf(MSG_INFO, "DPP: TESTING - no Transaction ID");
2398 goto skip_trans_id;
2399 }
2400 if (dpp_test == DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ) {
2401 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Transaction ID");
2402 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
2403 wpabuf_put_le16(msg, 0);
2404 goto skip_trans_id;
2405 }
2406#endif /* CONFIG_TESTING_OPTIONS */
2407
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002408 /* Transaction ID */
2409 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
2410 wpabuf_put_le16(msg, 1);
2411 wpabuf_put_u8(msg, TRANSACTION_ID);
2412
Roshan Pius3a1667e2018-07-03 15:17:14 -07002413#ifdef CONFIG_TESTING_OPTIONS
2414skip_trans_id:
2415 if (dpp_test == DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ) {
2416 wpa_printf(MSG_INFO, "DPP: TESTING - no Connector");
2417 goto skip_connector;
2418 }
2419 if (dpp_test == DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ) {
2420 char *connector;
2421
2422 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Connector");
2423 connector = dpp_corrupt_connector_signature(
2424 ssid->dpp_connector);
2425 if (!connector) {
2426 wpabuf_free(msg);
2427 return -1;
2428 }
2429 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
2430 wpabuf_put_le16(msg, os_strlen(connector));
2431 wpabuf_put_str(msg, connector);
2432 os_free(connector);
2433 goto skip_connector;
2434 }
2435#endif /* CONFIG_TESTING_OPTIONS */
2436
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002437 /* DPP Connector */
2438 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
2439 wpabuf_put_le16(msg, os_strlen(ssid->dpp_connector));
2440 wpabuf_put_str(msg, ssid->dpp_connector);
2441
Roshan Pius3a1667e2018-07-03 15:17:14 -07002442#ifdef CONFIG_TESTING_OPTIONS
2443skip_connector:
2444#endif /* CONFIG_TESTING_OPTIONS */
2445
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002446 /* TODO: Timeout on AP response */
2447 wait_time = wpa_s->max_remain_on_chan;
2448 if (wait_time > 2000)
2449 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002450 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
2451 MAC2STR(bss->bssid), bss->freq, DPP_PA_PEER_DISCOVERY_REQ);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002452 offchannel_send_action(wpa_s, bss->freq, bss->bssid, wpa_s->own_addr,
2453 broadcast,
2454 wpabuf_head(msg), wpabuf_len(msg),
2455 wait_time, wpas_dpp_tx_introduction_status, 0);
2456 wpabuf_free(msg);
2457
2458 /* Request this connection attempt to terminate - new one will be
2459 * started when network introduction protocol completes */
2460 os_memcpy(wpa_s->dpp_intro_bssid, bss->bssid, ETH_ALEN);
2461 wpa_s->dpp_intro_network = ssid;
2462 return 1;
2463}
2464
2465
2466int wpas_dpp_pkex_add(struct wpa_supplicant *wpa_s, const char *cmd)
2467{
2468 struct dpp_bootstrap_info *own_bi;
2469 const char *pos, *end;
2470 unsigned int wait_time;
2471
2472 pos = os_strstr(cmd, " own=");
2473 if (!pos)
2474 return -1;
2475 pos += 5;
2476 own_bi = dpp_bootstrap_get_id(wpa_s, atoi(pos));
2477 if (!own_bi) {
2478 wpa_printf(MSG_DEBUG,
2479 "DPP: Identified bootstrap info not found");
2480 return -1;
2481 }
2482 if (own_bi->type != DPP_BOOTSTRAP_PKEX) {
2483 wpa_printf(MSG_DEBUG,
2484 "DPP: Identified bootstrap info not for PKEX");
2485 return -1;
2486 }
2487 wpa_s->dpp_pkex_bi = own_bi;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002488 own_bi->pkex_t = 0; /* clear pending errors on new code */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002489
2490 os_free(wpa_s->dpp_pkex_identifier);
2491 wpa_s->dpp_pkex_identifier = NULL;
2492 pos = os_strstr(cmd, " identifier=");
2493 if (pos) {
2494 pos += 12;
2495 end = os_strchr(pos, ' ');
2496 if (!end)
2497 return -1;
2498 wpa_s->dpp_pkex_identifier = os_malloc(end - pos + 1);
2499 if (!wpa_s->dpp_pkex_identifier)
2500 return -1;
2501 os_memcpy(wpa_s->dpp_pkex_identifier, pos, end - pos);
2502 wpa_s->dpp_pkex_identifier[end - pos] = '\0';
2503 }
2504
2505 pos = os_strstr(cmd, " code=");
2506 if (!pos)
2507 return -1;
2508 os_free(wpa_s->dpp_pkex_code);
2509 wpa_s->dpp_pkex_code = os_strdup(pos + 6);
2510 if (!wpa_s->dpp_pkex_code)
2511 return -1;
2512
2513 if (os_strstr(cmd, " init=1")) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002514 struct dpp_pkex *pkex;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002515 struct wpabuf *msg;
2516
2517 wpa_printf(MSG_DEBUG, "DPP: Initiating PKEX");
2518 dpp_pkex_free(wpa_s->dpp_pkex);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002519 wpa_s->dpp_pkex = dpp_pkex_init(wpa_s, own_bi, wpa_s->own_addr,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002520 wpa_s->dpp_pkex_identifier,
2521 wpa_s->dpp_pkex_code);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002522 pkex = wpa_s->dpp_pkex;
2523 if (!pkex)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002524 return -1;
2525
Roshan Pius3a1667e2018-07-03 15:17:14 -07002526 msg = pkex->exchange_req;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002527 wait_time = wpa_s->max_remain_on_chan;
2528 if (wait_time > 2000)
2529 wait_time = 2000;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002530 pkex->freq = 2437;
2531 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
2532 " freq=%u type=%d",
2533 MAC2STR(broadcast), pkex->freq,
2534 DPP_PA_PKEX_EXCHANGE_REQ);
2535 offchannel_send_action(wpa_s, pkex->freq, broadcast,
2536 wpa_s->own_addr, broadcast,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002537 wpabuf_head(msg), wpabuf_len(msg),
2538 wait_time, wpas_dpp_tx_pkex_status, 0);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002539 if (wait_time == 0)
2540 wait_time = 2000;
2541 pkex->exch_req_wait_time = wait_time;
2542 pkex->exch_req_tries = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002543 }
2544
2545 /* TODO: Support multiple PKEX info entries */
2546
2547 os_free(wpa_s->dpp_pkex_auth_cmd);
2548 wpa_s->dpp_pkex_auth_cmd = os_strdup(cmd);
2549
2550 return 1;
2551}
2552
2553
2554int wpas_dpp_pkex_remove(struct wpa_supplicant *wpa_s, const char *id)
2555{
2556 unsigned int id_val;
2557
2558 if (os_strcmp(id, "*") == 0) {
2559 id_val = 0;
2560 } else {
2561 id_val = atoi(id);
2562 if (id_val == 0)
2563 return -1;
2564 }
2565
2566 if ((id_val != 0 && id_val != 1) || !wpa_s->dpp_pkex_code)
2567 return -1;
2568
2569 /* TODO: Support multiple PKEX entries */
2570 os_free(wpa_s->dpp_pkex_code);
2571 wpa_s->dpp_pkex_code = NULL;
2572 os_free(wpa_s->dpp_pkex_identifier);
2573 wpa_s->dpp_pkex_identifier = NULL;
2574 os_free(wpa_s->dpp_pkex_auth_cmd);
2575 wpa_s->dpp_pkex_auth_cmd = NULL;
2576 wpa_s->dpp_pkex_bi = NULL;
2577 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
2578 dpp_pkex_free(wpa_s->dpp_pkex);
2579 wpa_s->dpp_pkex = NULL;
2580 return 0;
2581}
2582
2583
Roshan Pius3a1667e2018-07-03 15:17:14 -07002584void wpas_dpp_stop(struct wpa_supplicant *wpa_s)
2585{
2586 dpp_auth_deinit(wpa_s->dpp_auth);
2587 wpa_s->dpp_auth = NULL;
2588 dpp_pkex_free(wpa_s->dpp_pkex);
2589 wpa_s->dpp_pkex = NULL;
2590 if (wpa_s->dpp_gas_client && wpa_s->dpp_gas_dialog_token >= 0)
2591 gas_query_stop(wpa_s->gas, wpa_s->dpp_gas_dialog_token);
2592}
2593
2594
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002595int wpas_dpp_init(struct wpa_supplicant *wpa_s)
2596{
2597 u8 adv_proto_id[7];
2598
2599 adv_proto_id[0] = WLAN_EID_VENDOR_SPECIFIC;
2600 adv_proto_id[1] = 5;
2601 WPA_PUT_BE24(&adv_proto_id[2], OUI_WFA);
2602 adv_proto_id[5] = DPP_OUI_TYPE;
2603 adv_proto_id[6] = 0x01;
2604
2605 if (gas_server_register(wpa_s->gas_server, adv_proto_id,
2606 sizeof(adv_proto_id), wpas_dpp_gas_req_handler,
2607 wpas_dpp_gas_status_handler, wpa_s) < 0)
2608 return -1;
2609 dl_list_init(&wpa_s->dpp_bootstrap);
2610 dl_list_init(&wpa_s->dpp_configurator);
2611 wpa_s->dpp_init_done = 1;
2612 return 0;
2613}
2614
2615
2616void wpas_dpp_deinit(struct wpa_supplicant *wpa_s)
2617{
2618#ifdef CONFIG_TESTING_OPTIONS
2619 os_free(wpa_s->dpp_config_obj_override);
2620 wpa_s->dpp_config_obj_override = NULL;
2621 os_free(wpa_s->dpp_discovery_override);
2622 wpa_s->dpp_discovery_override = NULL;
2623 os_free(wpa_s->dpp_groups_override);
2624 wpa_s->dpp_groups_override = NULL;
2625 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
2626#endif /* CONFIG_TESTING_OPTIONS */
2627 if (!wpa_s->dpp_init_done)
2628 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002629 eloop_cancel_timeout(wpas_dpp_pkex_retry_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002630 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002631 eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
2632 eloop_cancel_timeout(wpas_dpp_auth_resp_retry_timeout, wpa_s, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002633 offchannel_send_action_done(wpa_s);
2634 wpas_dpp_listen_stop(wpa_s);
2635 dpp_bootstrap_del(wpa_s, 0);
2636 dpp_configurator_del(wpa_s, 0);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002637 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002638 wpas_dpp_pkex_remove(wpa_s, "*");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002639 os_memset(wpa_s->dpp_intro_bssid, 0, ETH_ALEN);
2640 os_free(wpa_s->dpp_configurator_params);
2641 wpa_s->dpp_configurator_params = NULL;
2642}