]> git.ipfire.org Git - thirdparty/hostap.git/blame - wpa_supplicant/dpp_supplicant.c
DPP: Configuration exchange
[thirdparty/hostap.git] / wpa_supplicant / dpp_supplicant.c
CommitLineData
be27e185
JM
1/*
2 * wpa_supplicant - DPP
3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
30d27b04 12#include "utils/eloop.h"
be27e185 13#include "common/dpp.h"
461d39af
JM
14#include "common/gas.h"
15#include "common/gas_server.h"
be27e185 16#include "wpa_supplicant_i.h"
30d27b04
JM
17#include "driver_i.h"
18#include "offchannel.h"
461d39af 19#include "gas_query.h"
be27e185
JM
20#include "dpp_supplicant.h"
21
22
30d27b04
JM
23static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
24 unsigned int freq);
461d39af
JM
25static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx);
26static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator);
30d27b04
JM
27static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
28 unsigned int freq, const u8 *dst,
29 const u8 *src, const u8 *bssid,
30 const u8 *data, size_t data_len,
31 enum offchannel_send_action_result result);
32
33static const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
34
35
461d39af
JM
36static struct dpp_configurator *
37dpp_configurator_get_id(struct wpa_supplicant *wpa_s, unsigned int id)
38{
39 struct dpp_configurator *conf;
40
41 dl_list_for_each(conf, &wpa_s->dpp_configurator,
42 struct dpp_configurator, list) {
43 if (conf->id == id)
44 return conf;
45 }
46 return NULL;
47}
48
49
be27e185
JM
50static unsigned int wpas_dpp_next_id(struct wpa_supplicant *wpa_s)
51{
52 struct dpp_bootstrap_info *bi;
53 unsigned int max_id = 0;
54
55 dl_list_for_each(bi, &wpa_s->dpp_bootstrap, struct dpp_bootstrap_info,
56 list) {
57 if (bi->id > max_id)
58 max_id = bi->id;
59 }
60 return max_id + 1;
61}
62
63
64/**
65 * wpas_dpp_qr_code - Parse and add DPP bootstrapping info from a QR Code
66 * @wpa_s: Pointer to wpa_supplicant data
67 * @cmd: DPP URI read from a QR Code
68 * Returns: Identifier of the stored info or -1 on failure
69 */
70int wpas_dpp_qr_code(struct wpa_supplicant *wpa_s, const char *cmd)
71{
72 struct dpp_bootstrap_info *bi;
30d27b04 73 struct dpp_authentication *auth = wpa_s->dpp_auth;
be27e185
JM
74
75 bi = dpp_parse_qr_code(cmd);
76 if (!bi)
77 return -1;
78
79 bi->id = wpas_dpp_next_id(wpa_s);
80 dl_list_add(&wpa_s->dpp_bootstrap, &bi->list);
81
30d27b04
JM
82 if (auth && auth->response_pending &&
83 dpp_notify_new_qr_code(auth, bi) == 1) {
84 struct wpabuf *msg;
85
86 wpa_printf(MSG_DEBUG,
87 "DPP: Sending out pending authentication response");
88 msg = dpp_alloc_msg(DPP_PA_AUTHENTICATION_RESP,
89 wpabuf_len(auth->resp_attr));
90 if (!msg)
91 goto out;
92 wpabuf_put_buf(msg, wpa_s->dpp_auth->resp_attr);
93
94 offchannel_send_action(wpa_s, auth->curr_freq,
95 auth->peer_mac_addr, wpa_s->own_addr,
96 broadcast,
97 wpabuf_head(msg), wpabuf_len(msg),
98 500, wpas_dpp_tx_status, 0);
99 wpabuf_free(msg);
100 }
101
102out:
be27e185
JM
103 return bi->id;
104}
105
106
107static char * get_param(const char *cmd, const char *param)
108{
109 const char *pos, *end;
110 char *val;
111 size_t len;
112
113 pos = os_strstr(cmd, param);
114 if (!pos)
115 return NULL;
116
117 pos += os_strlen(param);
118 end = os_strchr(pos, ' ');
119 if (end)
120 len = end - pos;
121 else
122 len = os_strlen(pos);
123 val = os_malloc(len + 1);
124 if (!val)
125 return NULL;
126 os_memcpy(val, pos, len);
127 val[len] = '\0';
128 return val;
129}
130
131
132int wpas_dpp_bootstrap_gen(struct wpa_supplicant *wpa_s, const char *cmd)
133{
134 char *chan = NULL, *mac = NULL, *info = NULL, *pk = NULL, *curve = NULL;
135 char *key = NULL;
136 u8 *privkey = NULL;
137 size_t privkey_len = 0;
138 size_t len;
139 int ret = -1;
140 struct dpp_bootstrap_info *bi;
141
142 bi = os_zalloc(sizeof(*bi));
143 if (!bi)
144 goto fail;
145
146 if (os_strstr(cmd, "type=qrcode"))
147 bi->type = DPP_BOOTSTRAP_QR_CODE;
148 else
149 goto fail;
150
151 chan = get_param(cmd, " chan=");
152 mac = get_param(cmd, " mac=");
153 info = get_param(cmd, " info=");
154 curve = get_param(cmd, " curve=");
155 key = get_param(cmd, " key=");
156
157 if (key) {
158 privkey_len = os_strlen(key) / 2;
159 privkey = os_malloc(privkey_len);
160 if (!privkey ||
161 hexstr2bin(key, privkey, privkey_len) < 0)
162 goto fail;
163 }
164
165 pk = dpp_keygen(bi, curve, privkey, privkey_len);
166 if (!pk)
167 goto fail;
168
169 len = 4; /* "DPP:" */
170 if (chan) {
171 if (dpp_parse_uri_chan_list(bi, chan) < 0)
172 goto fail;
173 len += 3 + os_strlen(chan); /* C:...; */
174 }
175 if (mac) {
176 if (dpp_parse_uri_mac(bi, mac) < 0)
177 goto fail;
178 len += 3 + os_strlen(mac); /* M:...; */
179 }
180 if (info) {
181 if (dpp_parse_uri_info(bi, info) < 0)
182 goto fail;
183 len += 3 + os_strlen(info); /* I:...; */
184 }
185 len += 4 + os_strlen(pk);
186 bi->uri = os_malloc(len + 1);
187 if (!bi->uri)
188 goto fail;
189 os_snprintf(bi->uri, len + 1, "DPP:%s%s%s%s%s%s%s%s%sK:%s;;",
190 chan ? "C:" : "", chan ? chan : "", chan ? ";" : "",
191 mac ? "M:" : "", mac ? mac : "", mac ? ";" : "",
192 info ? "I:" : "", info ? info : "", info ? ";" : "",
193 pk);
194 bi->id = wpas_dpp_next_id(wpa_s);
195 dl_list_add(&wpa_s->dpp_bootstrap, &bi->list);
196 ret = bi->id;
197 bi = NULL;
198fail:
199 os_free(curve);
200 os_free(pk);
201 os_free(chan);
202 os_free(mac);
203 os_free(info);
204 str_clear_free(key);
205 bin_clear_free(privkey, privkey_len);
206 dpp_bootstrap_info_free(bi);
207 return ret;
208}
209
210
211static struct dpp_bootstrap_info *
212dpp_bootstrap_get_id(struct wpa_supplicant *wpa_s, unsigned int id)
213{
214 struct dpp_bootstrap_info *bi;
215
216 dl_list_for_each(bi, &wpa_s->dpp_bootstrap, struct dpp_bootstrap_info,
217 list) {
218 if (bi->id == id)
219 return bi;
220 }
221 return NULL;
222}
223
224
225static int dpp_bootstrap_del(struct wpa_supplicant *wpa_s, unsigned int id)
226{
227 struct dpp_bootstrap_info *bi, *tmp;
228 int found = 0;
229
230 dl_list_for_each_safe(bi, tmp, &wpa_s->dpp_bootstrap,
231 struct dpp_bootstrap_info, list) {
232 if (id && bi->id != id)
233 continue;
234 found = 1;
235 dl_list_del(&bi->list);
236 dpp_bootstrap_info_free(bi);
237 }
238
239 if (id == 0)
240 return 0; /* flush succeeds regardless of entries found */
241 return found ? 0 : -1;
242}
243
244
245int wpas_dpp_bootstrap_remove(struct wpa_supplicant *wpa_s, const char *id)
246{
247 unsigned int id_val;
248
249 if (os_strcmp(id, "*") == 0) {
250 id_val = 0;
251 } else {
252 id_val = atoi(id);
253 if (id_val == 0)
254 return -1;
255 }
256
257 return dpp_bootstrap_del(wpa_s, id_val);
258}
259
260
261const char * wpas_dpp_bootstrap_get_uri(struct wpa_supplicant *wpa_s,
262 unsigned int id)
263{
264 struct dpp_bootstrap_info *bi;
265
266 bi = dpp_bootstrap_get_id(wpa_s, id);
267 if (!bi)
268 return NULL;
269 return bi->uri;
270}
271
272
30d27b04
JM
273static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
274 unsigned int freq, const u8 *dst,
275 const u8 *src, const u8 *bssid,
276 const u8 *data, size_t data_len,
277 enum offchannel_send_action_result result)
278{
279 wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
280 " result=%s",
281 freq, MAC2STR(dst),
282 result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
283 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
284 "FAILED"));
285
286 if (!wpa_s->dpp_auth) {
287 wpa_printf(MSG_DEBUG,
288 "DPP: Ignore TX status since there is no ongoing authentication exchange");
289 return;
290 }
291
292 if (wpa_s->dpp_auth->remove_on_tx_status) {
293 wpa_printf(MSG_DEBUG,
294 "DPP: Terminate authentication exchange due to an earlier error");
461d39af
JM
295 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
296 offchannel_send_action_done(wpa_s);
30d27b04
JM
297 dpp_auth_deinit(wpa_s->dpp_auth);
298 wpa_s->dpp_auth = NULL;
299 return;
300 }
301
461d39af
JM
302 if (wpa_s->dpp_auth_ok_on_ack)
303 wpas_dpp_auth_success(wpa_s, 1);
304
30d27b04
JM
305 if (!is_broadcast_ether_addr(dst) &&
306 result != OFFCHANNEL_SEND_ACTION_SUCCESS) {
307 wpa_printf(MSG_DEBUG,
308 "DPP: Unicast DPP Action frame was not ACKed");
309 /* TODO: In case of DPP Authentication Request frame, move to
310 * the next channel immediately */
311 }
312}
313
314
315static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx)
316{
317 struct wpa_supplicant *wpa_s = eloop_ctx;
318
319 if (!wpa_s->dpp_auth)
320 return;
321 wpa_printf(MSG_DEBUG, "DPP: Continue reply wait on channel %u MHz",
322 wpa_s->dpp_auth->curr_freq);
323 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->curr_freq);
324}
325
326
461d39af
JM
327static void wpas_dpp_set_testing_options(struct wpa_supplicant *wpa_s,
328 struct dpp_authentication *auth)
329{
330#ifdef CONFIG_TESTING_OPTIONS
331 if (wpa_s->dpp_config_obj_override)
332 auth->config_obj_override =
333 os_strdup(wpa_s->dpp_config_obj_override);
334 if (wpa_s->dpp_discovery_override)
335 auth->discovery_override =
336 os_strdup(wpa_s->dpp_discovery_override);
337 if (wpa_s->dpp_groups_override)
338 auth->groups_override =
339 os_strdup(wpa_s->dpp_groups_override);
340 if (wpa_s->dpp_devices_override)
341 auth->devices_override =
342 os_strdup(wpa_s->dpp_devices_override);
343 auth->ignore_netaccesskey_mismatch =
344 wpa_s->dpp_ignore_netaccesskey_mismatch;
345#endif /* CONFIG_TESTING_OPTIONS */
346}
347
348
30d27b04
JM
349int wpas_dpp_auth_init(struct wpa_supplicant *wpa_s, const char *cmd)
350{
351 const char *pos;
352 struct dpp_bootstrap_info *peer_bi, *own_bi = NULL;
353 struct wpabuf *msg;
354 const u8 *dst;
355 int res;
356 int configurator = 1;
357 unsigned int wait_time;
461d39af
JM
358 struct dpp_configuration *conf_sta = NULL, *conf_ap = NULL;
359 struct dpp_configurator *conf = NULL;
360
361 wpa_s->dpp_gas_client = 0;
30d27b04
JM
362
363 pos = os_strstr(cmd, " peer=");
364 if (!pos)
365 return -1;
366 pos += 6;
367 peer_bi = dpp_bootstrap_get_id(wpa_s, atoi(pos));
368 if (!peer_bi) {
369 wpa_printf(MSG_INFO,
370 "DPP: Could not find bootstrapping info for the identified peer");
371 return -1;
372 }
373
374 pos = os_strstr(cmd, " own=");
375 if (pos) {
376 pos += 5;
377 own_bi = dpp_bootstrap_get_id(wpa_s, atoi(pos));
378 if (!own_bi) {
379 wpa_printf(MSG_INFO,
380 "DPP: Could not find bootstrapping info for the identified local entry");
381 return -1;
382 }
383
384 if (peer_bi->curve != own_bi->curve) {
385 wpa_printf(MSG_INFO,
386 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
387 peer_bi->curve->name, own_bi->curve->name);
388 return -1;
389 }
390 }
391
392 pos = os_strstr(cmd, " role=");
393 if (pos) {
394 pos += 6;
395 if (os_strncmp(pos, "configurator", 12) == 0)
396 configurator = 1;
397 else if (os_strncmp(pos, "enrollee", 8) == 0)
398 configurator = 0;
399 else
461d39af
JM
400 goto fail;
401 }
402
403 pos = os_strstr(cmd, " netrole=");
404 if (pos) {
405 pos += 9;
406 wpa_s->dpp_netrole_ap = os_strncmp(pos, "ap", 2) == 0;
407 }
408
409 if (os_strstr(cmd, " conf=sta-")) {
410 conf_sta = os_zalloc(sizeof(struct dpp_configuration));
411 if (!conf_sta)
412 goto fail;
413 /* TODO: Configuration of network parameters from upper layers
414 */
415 os_memcpy(conf_sta->ssid, "test", 4);
416 conf_sta->ssid_len = 4;
417 if (os_strstr(cmd, " conf=sta-psk")) {
418 conf_sta->dpp = 0;
419 conf_sta->passphrase = os_strdup("secret passphrase");
420 if (!conf_sta->passphrase)
421 goto fail;
422 } else if (os_strstr(cmd, " conf=sta-dpp")) {
423 conf_sta->dpp = 1;
424 } else {
425 goto fail;
426 }
427 }
428
429 if (os_strstr(cmd, " conf=ap-")) {
430 conf_ap = os_zalloc(sizeof(struct dpp_configuration));
431 if (!conf_ap)
432 goto fail;
433 /* TODO: Configuration of network parameters from upper layers
434 */
435 os_memcpy(conf_ap->ssid, "test", 4);
436 conf_ap->ssid_len = 4;
437 if (os_strstr(cmd, " conf=ap-psk")) {
438 conf_ap->dpp = 0;
439 conf_ap->passphrase = os_strdup("secret passphrase");
440 if (!conf_ap->passphrase)
441 goto fail;
442 } else if (os_strstr(cmd, " conf=ap-dpp")) {
443 conf_ap->dpp = 1;
444 } else {
445 goto fail;
446 }
447 }
448
449 pos = os_strstr(cmd, " expiry=");
450 if (pos) {
451 long int val;
452
453 pos += 8;
454 val = strtol(pos, NULL, 0);
455 if (val <= 0)
456 goto fail;
457 if (conf_sta)
458 conf_sta->netaccesskey_expiry = val;
459 if (conf_ap)
460 conf_ap->netaccesskey_expiry = val;
461 }
462
463 pos = os_strstr(cmd, " configurator=");
464 if (pos) {
465 pos += 14;
466 conf = dpp_configurator_get_id(wpa_s, atoi(pos));
467 if (!conf) {
468 wpa_printf(MSG_INFO,
469 "DPP: Could not find the specified configurator");
470 goto fail;
471 }
30d27b04
JM
472 }
473
474 if (wpa_s->dpp_auth) {
475 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
476 offchannel_send_action_done(wpa_s);
477 dpp_auth_deinit(wpa_s->dpp_auth);
478 }
479 wpa_s->dpp_auth = dpp_auth_init(wpa_s, peer_bi, own_bi, configurator);
480 if (!wpa_s->dpp_auth)
461d39af
JM
481 goto fail;
482 wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
483 wpa_s->dpp_auth->conf_sta = conf_sta;
484 wpa_s->dpp_auth->conf_ap = conf_ap;
485 wpa_s->dpp_auth->conf = conf;
30d27b04
JM
486
487 /* TODO: Support iteration over all frequencies and filtering of
488 * frequencies based on locally enabled channels that allow initiation
489 * of transmission. */
490 if (peer_bi->num_freq > 0)
491 wpa_s->dpp_auth->curr_freq = peer_bi->freq[0];
492 else
493 wpa_s->dpp_auth->curr_freq = 2412;
494
495 msg = dpp_alloc_msg(DPP_PA_AUTHENTICATION_REQ,
496 wpabuf_len(wpa_s->dpp_auth->req_attr));
497 if (!msg)
498 return -1;
499 wpabuf_put_buf(msg, wpa_s->dpp_auth->req_attr);
500
501 if (is_zero_ether_addr(peer_bi->mac_addr)) {
502 dst = broadcast;
503 } else {
504 dst = peer_bi->mac_addr;
505 os_memcpy(wpa_s->dpp_auth->peer_mac_addr, peer_bi->mac_addr,
506 ETH_ALEN);
507 }
461d39af 508 wpa_s->dpp_auth_ok_on_ack = 0;
30d27b04
JM
509 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
510 wait_time = wpa_s->max_remain_on_chan;
511 if (wait_time > 2000)
512 wait_time = 2000;
513 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
514 wpas_dpp_reply_wait_timeout,
515 wpa_s, NULL);
516 res = offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq,
517 dst, wpa_s->own_addr, broadcast,
518 wpabuf_head(msg), wpabuf_len(msg),
519 wait_time, wpas_dpp_tx_status, 0);
520 wpabuf_free(msg);
521
522 return res;
461d39af
JM
523fail:
524 dpp_configuration_free(conf_sta);
525 dpp_configuration_free(conf_ap);
526 return -1;
30d27b04
JM
527}
528
529
530struct wpas_dpp_listen_work {
531 unsigned int freq;
532 unsigned int duration;
533 struct wpabuf *probe_resp_ie;
534};
535
536
537static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work *lwork)
538{
539 if (!lwork)
540 return;
541 os_free(lwork);
542}
543
544
545static void wpas_dpp_listen_work_done(struct wpa_supplicant *wpa_s)
546{
547 struct wpas_dpp_listen_work *lwork;
548
549 if (!wpa_s->dpp_listen_work)
550 return;
551
552 lwork = wpa_s->dpp_listen_work->ctx;
553 wpas_dpp_listen_work_free(lwork);
554 radio_work_done(wpa_s->dpp_listen_work);
555 wpa_s->dpp_listen_work = NULL;
556}
557
558
559static void dpp_start_listen_cb(struct wpa_radio_work *work, int deinit)
560{
561 struct wpa_supplicant *wpa_s = work->wpa_s;
562 struct wpas_dpp_listen_work *lwork = work->ctx;
563
564 if (deinit) {
565 if (work->started) {
566 wpa_s->dpp_listen_work = NULL;
567 wpas_dpp_listen_stop(wpa_s);
568 }
569 wpas_dpp_listen_work_free(lwork);
570 return;
571 }
572
573 wpa_s->dpp_listen_work = work;
574
575 wpa_s->dpp_pending_listen_freq = lwork->freq;
576
577 if (wpa_drv_remain_on_channel(wpa_s, lwork->freq,
578 wpa_s->max_remain_on_chan) < 0) {
579 wpa_printf(MSG_DEBUG,
580 "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
581 lwork->freq);
582 wpas_dpp_listen_work_done(wpa_s);
583 wpa_s->dpp_pending_listen_freq = 0;
584 return;
585 }
586 wpa_s->off_channel_freq = 0;
587 wpa_s->roc_waiting_drv_freq = lwork->freq;
588}
589
590
591static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
592 unsigned int freq)
593{
594 struct wpas_dpp_listen_work *lwork;
595
596 if (wpa_s->dpp_listen_work) {
597 wpa_printf(MSG_DEBUG,
598 "DPP: Reject start_listen since dpp_listen_work already exists");
599 return -1;
600 }
601
602 if (wpa_s->dpp_listen_freq)
603 wpas_dpp_listen_stop(wpa_s);
604 wpa_s->dpp_listen_freq = freq;
605
606 lwork = os_zalloc(sizeof(*lwork));
607 if (!lwork)
608 return -1;
609 lwork->freq = freq;
610
611 if (radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb,
612 lwork) < 0) {
613 wpas_dpp_listen_work_free(lwork);
614 return -1;
615 }
616
617 return 0;
618}
619
620
621int wpas_dpp_listen(struct wpa_supplicant *wpa_s, const char *cmd)
622{
623 int freq;
624
625 freq = atoi(cmd);
626 if (freq <= 0)
627 return -1;
628
629 if (os_strstr(cmd, " role=configurator"))
630 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR;
631 else if (os_strstr(cmd, " role=enrollee"))
632 wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
633 else
634 wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
635 DPP_CAPAB_ENROLLEE;
636 wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
461d39af 637 wpa_s->dpp_netrole_ap = os_strstr(cmd, " netrole=ap") != NULL;
30d27b04
JM
638 if (wpa_s->dpp_listen_freq == (unsigned int) freq) {
639 wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz",
640 freq);
641 return 0;
642 }
643
644 return wpas_dpp_listen_start(wpa_s, freq);
645}
646
647
648void wpas_dpp_listen_stop(struct wpa_supplicant *wpa_s)
649{
650 if (!wpa_s->dpp_listen_freq)
651 return;
652
653 wpa_printf(MSG_DEBUG, "DPP: Stop listen on %u MHz",
654 wpa_s->dpp_listen_freq);
655 wpa_drv_cancel_remain_on_channel(wpa_s);
656 wpa_s->dpp_listen_freq = 0;
657 wpas_dpp_listen_work_done(wpa_s);
658}
659
660
661void wpas_dpp_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
662 unsigned int freq)
663{
664 if (!wpa_s->dpp_listen_freq && !wpa_s->dpp_pending_listen_freq)
665 return;
666
667 wpa_printf(MSG_DEBUG,
668 "DPP: remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d roc_waiting_drv_freq=%d freq=%u)",
669 wpa_s->off_channel_freq, wpa_s->dpp_pending_listen_freq,
670 wpa_s->roc_waiting_drv_freq, freq);
671 if (wpa_s->off_channel_freq &&
672 wpa_s->off_channel_freq == wpa_s->dpp_pending_listen_freq) {
673 wpa_printf(MSG_DEBUG, "DPP: Listen on %u MHz started", freq);
674 wpa_s->dpp_pending_listen_freq = 0;
675 } else {
676 wpa_printf(MSG_DEBUG,
677 "DPP: Ignore remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d freq=%u)",
678 wpa_s->off_channel_freq,
679 wpa_s->dpp_pending_listen_freq, freq);
680 }
681}
682
683
684void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
685 unsigned int freq)
686{
687 wpas_dpp_listen_work_done(wpa_s);
688
461d39af 689 if (wpa_s->dpp_auth && !wpa_s->dpp_gas_client) {
30d27b04
JM
690 /* Continue listen with a new remain-on-channel */
691 wpa_printf(MSG_DEBUG,
692 "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
693 wpa_s->dpp_auth->curr_freq);
694 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->curr_freq);
695 return;
696 }
697
698 if (wpa_s->dpp_listen_freq) {
699 /* Continue listen with a new remain-on-channel */
700 wpas_dpp_listen_start(wpa_s, wpa_s->dpp_listen_freq);
701 }
702}
703
704
705static void wpas_dpp_rx_auth_req(struct wpa_supplicant *wpa_s, const u8 *src,
706 const u8 *buf, size_t len, unsigned int freq)
707{
708 const u8 *r_bootstrap, *i_bootstrap, *wrapped_data;
709 u16 r_bootstrap_len, i_bootstrap_len, wrapped_data_len;
710 struct dpp_bootstrap_info *bi, *own_bi = NULL, *peer_bi = NULL;
711 struct wpabuf *msg;
712
713 wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR,
714 MAC2STR(src));
715
716 wrapped_data = dpp_get_attr(buf, len, DPP_ATTR_WRAPPED_DATA,
717 &wrapped_data_len);
718 if (!wrapped_data) {
719 wpa_printf(MSG_DEBUG,
720 "DPP: Missing required Wrapped data attribute");
721 return;
722 }
723 wpa_hexdump(MSG_MSGDUMP, "DPP: Wrapped data",
724 wrapped_data, wrapped_data_len);
725
726 r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
727 &r_bootstrap_len);
728 if (!r_bootstrap || r_bootstrap > wrapped_data ||
729 r_bootstrap_len != SHA256_MAC_LEN) {
730 wpa_printf(MSG_DEBUG,
731 "DPP: Missing or invalid required Responder Bootstrapping Key Hash attribute");
732 return;
733 }
734 wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
735 r_bootstrap, r_bootstrap_len);
736
737 i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH,
738 &i_bootstrap_len);
739 if (!i_bootstrap || i_bootstrap > wrapped_data ||
740 i_bootstrap_len != SHA256_MAC_LEN) {
741 wpa_printf(MSG_DEBUG,
742 "DPP: Missing or invalid required Initiator Bootstrapping Key Hash attribute");
743 return;
744 }
745 wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash",
746 i_bootstrap, i_bootstrap_len);
747
748 /* Try to find own and peer bootstrapping key matches based on the
749 * received hash values */
750 dl_list_for_each(bi, &wpa_s->dpp_bootstrap, struct dpp_bootstrap_info,
751 list) {
752 if (!own_bi && bi->own &&
753 os_memcmp(bi->pubkey_hash, r_bootstrap,
754 SHA256_MAC_LEN) == 0) {
755 wpa_printf(MSG_DEBUG,
756 "DPP: Found matching own bootstrapping information");
757 own_bi = bi;
758 }
759
760 if (!peer_bi && !bi->own &&
761 os_memcmp(bi->pubkey_hash, i_bootstrap,
762 SHA256_MAC_LEN) == 0) {
763 wpa_printf(MSG_DEBUG,
764 "DPP: Found matching peer bootstrapping information");
765 peer_bi = bi;
766 }
767
768 if (own_bi && peer_bi)
769 break;
770 }
771
772 if (!own_bi) {
773 wpa_printf(MSG_DEBUG,
774 "DPP: No matching own bootstrapping key found - ignore message");
775 return;
776 }
777
778 if (wpa_s->dpp_auth) {
779 wpa_printf(MSG_DEBUG,
780 "DPP: Already in DPP authentication exchange - ignore new one");
781 return;
782 }
783
461d39af
JM
784 wpa_s->dpp_gas_client = 0;
785 wpa_s->dpp_auth_ok_on_ack = 0;
30d27b04
JM
786 wpa_s->dpp_auth = dpp_auth_req_rx(wpa_s, wpa_s->dpp_allowed_roles,
787 wpa_s->dpp_qr_mutual,
788 peer_bi, own_bi, freq, buf,
789 wrapped_data, wrapped_data_len);
790 if (!wpa_s->dpp_auth) {
791 wpa_printf(MSG_DEBUG, "DPP: No response generated");
792 return;
793 }
461d39af 794 wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
30d27b04
JM
795 os_memcpy(wpa_s->dpp_auth->peer_mac_addr, src, ETH_ALEN);
796
797 msg = dpp_alloc_msg(DPP_PA_AUTHENTICATION_RESP,
798 wpabuf_len(wpa_s->dpp_auth->resp_attr));
799 if (!msg)
800 return;
801 wpabuf_put_buf(msg, wpa_s->dpp_auth->resp_attr);
802
803 offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq,
804 src, wpa_s->own_addr, broadcast,
805 wpabuf_head(msg), wpabuf_len(msg),
806 500, wpas_dpp_tx_status, 0);
807 wpabuf_free(msg);
808}
809
810
461d39af
JM
811static void wpas_dpp_start_gas_server(struct wpa_supplicant *wpa_s)
812{
813 /* TODO: stop wait and start ROC */
814}
815
816
817static void wpas_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token,
818 enum gas_query_result result,
819 const struct wpabuf *adv_proto,
820 const struct wpabuf *resp, u16 status_code)
821{
822 struct wpa_supplicant *wpa_s = ctx;
823 const u8 *pos;
824 struct dpp_authentication *auth = wpa_s->dpp_auth;
825
826 if (!auth || !auth->auth_success) {
827 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
828 return;
829 }
830 if (!resp || status_code != WLAN_STATUS_SUCCESS) {
831 wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed");
832 goto fail;
833 }
834
835 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto",
836 adv_proto);
837 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)",
838 resp);
839
840 if (wpabuf_len(adv_proto) != 10 ||
841 !(pos = wpabuf_head(adv_proto)) ||
842 pos[0] != WLAN_EID_ADV_PROTO ||
843 pos[1] != 8 ||
844 pos[3] != WLAN_EID_VENDOR_SPECIFIC ||
845 pos[4] != 5 ||
846 WPA_GET_BE24(&pos[5]) != OUI_WFA ||
847 pos[8] != 0x1a ||
848 pos[9] != 1) {
849 wpa_printf(MSG_DEBUG,
850 "DPP: Not a DPP Advertisement Protocol ID");
851 goto fail;
852 }
853
854 if (dpp_conf_resp_rx(auth, resp) < 0) {
855 wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed");
856 goto fail;
857 }
858
859 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
860 if (auth->ssid_len)
861 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s",
862 wpa_ssid_txt(auth->ssid, auth->ssid_len));
863 if (auth->connector) {
864 /* TODO: Save the Connector and consider using a command
865 * to fetch the value instead of sending an event with
866 * it. The Connector could end up being larger than what
867 * most clients are ready to receive as an event
868 * message. */
869 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONNECTOR "%s",
870 auth->connector);
871 }
872 if (auth->c_sign_key) {
873 char *hex;
874 size_t hexlen;
875
876 hexlen = 2 * wpabuf_len(auth->c_sign_key) + 1;
877 hex = os_malloc(hexlen);
878 if (hex) {
879 wpa_snprintf_hex(hex, hexlen,
880 wpabuf_head(auth->c_sign_key),
881 wpabuf_len(auth->c_sign_key));
882 if (auth->c_sign_key_expiry)
883 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_C_SIGN_KEY
884 "%s %lu", hex,
885 (long unsigned)
886 auth->c_sign_key_expiry);
887 else
888 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_C_SIGN_KEY
889 "%s", hex);
890 os_free(hex);
891 }
892 }
893 if (auth->net_access_key) {
894 char *hex;
895 size_t hexlen;
896
897 hexlen = 2 * wpabuf_len(auth->net_access_key) + 1;
898 hex = os_malloc(hexlen);
899 if (hex) {
900 wpa_snprintf_hex(hex, hexlen,
901 wpabuf_head(auth->net_access_key),
902 wpabuf_len(auth->net_access_key));
903 if (auth->net_access_key_expiry)
904 wpa_msg(wpa_s, MSG_INFO,
905 DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex,
906 (long unsigned)
907 auth->net_access_key_expiry);
908 else
909 wpa_msg(wpa_s, MSG_INFO,
910 DPP_EVENT_NET_ACCESS_KEY "%s", hex);
911 os_free(hex);
912 }
913 }
914 dpp_auth_deinit(wpa_s->dpp_auth);
915 wpa_s->dpp_auth = NULL;
916 return;
917
918fail:
919 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
920 dpp_auth_deinit(wpa_s->dpp_auth);
921 wpa_s->dpp_auth = NULL;
922}
923
924
925static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
926{
927 struct dpp_authentication *auth = wpa_s->dpp_auth;
928 struct wpabuf *buf, *conf_req;
929 char json[100];
930 int res;
931
932 wpa_s->dpp_gas_client = 1;
933 os_snprintf(json, sizeof(json),
934 "{\"name\":\"Test\","
935 "\"wi-fi_tech\":\"infra\","
936 "\"netRole\":\"%s\"}",
937 wpa_s->dpp_netrole_ap ? "ap" : "sta");
938 wpa_printf(MSG_DEBUG, "DPP: GAS Config Attributes: %s", json);
939
940 offchannel_send_action_done(wpa_s);
941 wpas_dpp_listen_stop(wpa_s);
942
943 conf_req = dpp_build_conf_req(auth, json);
944 if (!conf_req) {
945 wpa_printf(MSG_DEBUG,
946 "DPP: No configuration request data available");
947 return;
948 }
949
950 buf = gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req));
951 if (!buf) {
952 wpabuf_free(conf_req);
953 return;
954 }
955
956 /* Advertisement Protocol IE */
957 wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO);
958 wpabuf_put_u8(buf, 8); /* Length */
959 wpabuf_put_u8(buf, 0x7f);
960 wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
961 wpabuf_put_u8(buf, 5);
962 wpabuf_put_be24(buf, OUI_WFA);
963 wpabuf_put_u8(buf, DPP_OUI_TYPE);
964 wpabuf_put_u8(buf, 0x01);
965
966 /* GAS Query */
967 wpabuf_put_le16(buf, wpabuf_len(conf_req));
968 wpabuf_put_buf(buf, conf_req);
969 wpabuf_free(conf_req);
970
971 wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
972 MAC2STR(auth->peer_mac_addr), auth->curr_freq);
973
974 res = gas_query_req(wpa_s->gas, auth->peer_mac_addr, auth->curr_freq,
975 buf, wpas_dpp_gas_resp_cb, wpa_s);
976 if (res < 0) {
977 wpa_msg(wpa_s, MSG_DEBUG, "GAS: Failed to send Query Request");
978 wpabuf_free(buf);
979 } else {
980 wpa_printf(MSG_DEBUG,
981 "DPP: GAS query started with dialog token %u", res);
982 }
983}
984
985
986static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator)
987{
988 wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded");
989 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d", initiator);
990
991 if (wpa_s->dpp_auth->configurator)
992 wpas_dpp_start_gas_server(wpa_s);
993 else
994 wpas_dpp_start_gas_client(wpa_s);
995}
996
997
30d27b04
JM
998static void wpas_dpp_rx_auth_resp(struct wpa_supplicant *wpa_s, const u8 *src,
999 const u8 *buf, size_t len)
1000{
1001 struct dpp_authentication *auth = wpa_s->dpp_auth;
1002 struct wpabuf *msg, *attr;
1003
1004 wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR,
1005 MAC2STR(src));
1006
1007 if (!auth) {
1008 wpa_printf(MSG_DEBUG,
1009 "DPP: No DPP Authentication in progress - drop");
1010 return;
1011 }
1012
1013 if (!is_zero_ether_addr(auth->peer_mac_addr) &&
1014 os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1015 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1016 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1017 return;
1018 }
1019
1020 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
1021
1022 attr = dpp_auth_resp_rx(auth, buf, len);
1023 if (!attr) {
1024 if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) {
1025 wpa_printf(MSG_DEBUG,
1026 "DPP: Start wait for full response");
1027 offchannel_send_action_done(wpa_s);
1028 wpas_dpp_listen_start(wpa_s, auth->curr_freq);
1029 return;
1030 }
1031 wpa_printf(MSG_DEBUG, "DPP: No confirm generated");
1032 return;
1033 }
1034 os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
1035
1036 msg = dpp_alloc_msg(DPP_PA_AUTHENTICATION_CONF, wpabuf_len(attr));
1037 if (!msg) {
1038 wpabuf_free(attr);
1039 return;
1040 }
1041 wpabuf_put_buf(msg, attr);
1042 wpabuf_free(attr);
1043
1044 offchannel_send_action(wpa_s, auth->curr_freq,
1045 src, wpa_s->own_addr, broadcast,
1046 wpabuf_head(msg), wpabuf_len(msg),
1047 500, wpas_dpp_tx_status, 0);
1048 wpabuf_free(msg);
461d39af 1049 wpa_s->dpp_auth_ok_on_ack = 1;
30d27b04
JM
1050}
1051
1052
1053static void wpas_dpp_rx_auth_conf(struct wpa_supplicant *wpa_s, const u8 *src,
1054 const u8 *buf, size_t len)
1055{
1056 struct dpp_authentication *auth = wpa_s->dpp_auth;
1057
1058 wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR,
1059 MAC2STR(src));
1060
1061 if (!auth) {
1062 wpa_printf(MSG_DEBUG,
1063 "DPP: No DPP Authentication in progress - drop");
1064 return;
1065 }
1066
1067 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
1068 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
1069 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
1070 return;
1071 }
1072
1073 if (dpp_auth_conf_rx(auth, buf, len) < 0) {
1074 wpa_printf(MSG_DEBUG, "DPP: Authentication failed");
1075 return;
1076 }
1077
461d39af 1078 wpas_dpp_auth_success(wpa_s, 0);
30d27b04
JM
1079}
1080
1081
1082void wpas_dpp_rx_action(struct wpa_supplicant *wpa_s, const u8 *src,
1083 const u8 *buf, size_t len, unsigned int freq)
1084{
1085 enum dpp_public_action_frame_type type;
1086
1087 if (len < 1)
1088 return;
1089 type = buf[0];
1090 buf++;
1091 len--;
1092
1093 wpa_printf(MSG_DEBUG,
1094 "DPP: Received DPP Public Action frame type %d from "
1095 MACSTR " freq=%u",
1096 type, MAC2STR(src), freq);
1097 wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len);
1098 if (dpp_check_attrs(buf, len) < 0)
1099 return;
1100
1101 switch (type) {
1102 case DPP_PA_AUTHENTICATION_REQ:
1103 wpas_dpp_rx_auth_req(wpa_s, src, buf, len, freq);
1104 break;
1105 case DPP_PA_AUTHENTICATION_RESP:
1106 wpas_dpp_rx_auth_resp(wpa_s, src, buf, len);
1107 break;
1108 case DPP_PA_AUTHENTICATION_CONF:
1109 wpas_dpp_rx_auth_conf(wpa_s, src, buf, len);
1110 break;
1111 default:
1112 wpa_printf(MSG_DEBUG,
1113 "DPP: Ignored unsupported frame subtype %d", type);
1114 break;
1115 }
1116}
1117
1118
461d39af
JM
1119static struct wpabuf *
1120wpas_dpp_gas_req_handler(void *ctx, const u8 *sa, const u8 *query,
1121 size_t query_len)
1122{
1123 struct wpa_supplicant *wpa_s = ctx;
1124 struct dpp_authentication *auth = wpa_s->dpp_auth;
1125 struct wpabuf *resp;
1126
1127 wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR,
1128 MAC2STR(sa));
1129 if (!auth || !auth->auth_success ||
1130 os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) {
1131 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
1132 return NULL;
1133 }
1134 wpa_hexdump(MSG_DEBUG,
1135 "DPP: Received Configuration Request (GAS Query Request)",
1136 query, query_len);
1137 resp = dpp_conf_req_rx(auth, query, query_len);
1138 if (!resp)
1139 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1140 return resp;
1141}
1142
1143
1144static void
1145wpas_dpp_gas_status_handler(void *ctx, struct wpabuf *resp, int ok)
1146{
1147 struct wpa_supplicant *wpa_s = ctx;
1148 struct dpp_authentication *auth = wpa_s->dpp_auth;
1149
1150 if (!auth) {
1151 wpabuf_free(resp);
1152 return;
1153 }
1154
1155 wpa_printf(MSG_DEBUG, "DPP: Configuration exchange completed (ok=%d)",
1156 ok);
1157 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
1158 offchannel_send_action_done(wpa_s);
1159 wpas_dpp_listen_stop(wpa_s);
1160 if (ok)
1161 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
1162 else
1163 wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
1164 dpp_auth_deinit(wpa_s->dpp_auth);
1165 wpa_s->dpp_auth = NULL;
1166 wpabuf_free(resp);
1167}
1168
1169
1170static unsigned int wpas_dpp_next_configurator_id(struct wpa_supplicant *wpa_s)
1171{
1172 struct dpp_configurator *conf;
1173 unsigned int max_id = 0;
1174
1175 dl_list_for_each(conf, &wpa_s->dpp_configurator,
1176 struct dpp_configurator, list) {
1177 if (conf->id > max_id)
1178 max_id = conf->id;
1179 }
1180 return max_id + 1;
1181}
1182
1183
1184int wpas_dpp_configurator_add(struct wpa_supplicant *wpa_s, const char *cmd)
1185{
1186 char *expiry = NULL, *curve = NULL;
1187 char *key = NULL;
1188 u8 *privkey = NULL;
1189 size_t privkey_len = 0;
1190 int ret = -1;
1191 struct dpp_configurator *conf = NULL;
1192
1193 expiry = get_param(cmd, " expiry=");
1194 curve = get_param(cmd, " curve=");
1195 key = get_param(cmd, " key=");
1196
1197 if (key) {
1198 privkey_len = os_strlen(key) / 2;
1199 privkey = os_malloc(privkey_len);
1200 if (!privkey ||
1201 hexstr2bin(key, privkey, privkey_len) < 0)
1202 goto fail;
1203 }
1204
1205 conf = dpp_keygen_configurator(curve, privkey, privkey_len);
1206 if (!conf)
1207 goto fail;
1208
1209 if (expiry) {
1210 long int val;
1211
1212 val = strtol(expiry, NULL, 0);
1213 if (val <= 0)
1214 goto fail;
1215 conf->csign_expiry = val;
1216 }
1217
1218 conf->id = wpas_dpp_next_configurator_id(wpa_s);
1219 dl_list_add(&wpa_s->dpp_configurator, &conf->list);
1220 ret = conf->id;
1221 conf = NULL;
1222fail:
1223 os_free(curve);
1224 os_free(expiry);
1225 str_clear_free(key);
1226 bin_clear_free(privkey, privkey_len);
1227 dpp_configurator_free(conf);
1228 return ret;
1229}
1230
1231
1232static int dpp_configurator_del(struct wpa_supplicant *wpa_s, unsigned int id)
1233{
1234 struct dpp_configurator *conf, *tmp;
1235 int found = 0;
1236
1237 dl_list_for_each_safe(conf, tmp, &wpa_s->dpp_configurator,
1238 struct dpp_configurator, list) {
1239 if (id && conf->id != id)
1240 continue;
1241 found = 1;
1242 dl_list_del(&conf->list);
1243 dpp_configurator_free(conf);
1244 }
1245
1246 if (id == 0)
1247 return 0; /* flush succeeds regardless of entries found */
1248 return found ? 0 : -1;
1249}
1250
1251
1252int wpas_dpp_configurator_remove(struct wpa_supplicant *wpa_s, const char *id)
1253{
1254 unsigned int id_val;
1255
1256 if (os_strcmp(id, "*") == 0) {
1257 id_val = 0;
1258 } else {
1259 id_val = atoi(id);
1260 if (id_val == 0)
1261 return -1;
1262 }
1263
1264 return dpp_configurator_del(wpa_s, id_val);
1265}
1266
1267
be27e185
JM
1268int wpas_dpp_init(struct wpa_supplicant *wpa_s)
1269{
461d39af
JM
1270 u8 adv_proto_id[7];
1271
1272 adv_proto_id[0] = WLAN_EID_VENDOR_SPECIFIC;
1273 adv_proto_id[1] = 5;
1274 WPA_PUT_BE24(&adv_proto_id[2], OUI_WFA);
1275 adv_proto_id[5] = DPP_OUI_TYPE;
1276 adv_proto_id[6] = 0x01;
1277
1278 if (gas_server_register(wpa_s->gas_server, adv_proto_id,
1279 sizeof(adv_proto_id), wpas_dpp_gas_req_handler,
1280 wpas_dpp_gas_status_handler, wpa_s) < 0)
1281 return -1;
be27e185 1282 dl_list_init(&wpa_s->dpp_bootstrap);
461d39af 1283 dl_list_init(&wpa_s->dpp_configurator);
be27e185
JM
1284 wpa_s->dpp_init_done = 1;
1285 return 0;
1286}
1287
1288
1289void wpas_dpp_deinit(struct wpa_supplicant *wpa_s)
1290{
461d39af
JM
1291#ifdef CONFIG_TESTING_OPTIONS
1292 os_free(wpa_s->dpp_config_obj_override);
1293 wpa_s->dpp_config_obj_override = NULL;
1294 os_free(wpa_s->dpp_discovery_override);
1295 wpa_s->dpp_discovery_override = NULL;
1296 os_free(wpa_s->dpp_groups_override);
1297 wpa_s->dpp_groups_override = NULL;
1298 os_free(wpa_s->dpp_devices_override);
1299 wpa_s->dpp_devices_override = NULL;
1300 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
1301#endif /* CONFIG_TESTING_OPTIONS */
be27e185
JM
1302 if (!wpa_s->dpp_init_done)
1303 return;
30d27b04
JM
1304 eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
1305 offchannel_send_action_done(wpa_s);
1306 wpas_dpp_listen_stop(wpa_s);
be27e185 1307 dpp_bootstrap_del(wpa_s, 0);
461d39af 1308 dpp_configurator_del(wpa_s, 0);
30d27b04
JM
1309 dpp_auth_deinit(wpa_s->dpp_auth);
1310 wpa_s->dpp_auth = NULL;
be27e185 1311}