]>
Commit | Line | Data |
---|---|---|
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" | |
a0d5c56f JM |
16 | #include "rsn_supp/wpa.h" |
17 | #include "rsn_supp/pmksa_cache.h" | |
be27e185 | 18 | #include "wpa_supplicant_i.h" |
a0d5c56f | 19 | #include "config.h" |
30d27b04 JM |
20 | #include "driver_i.h" |
21 | #include "offchannel.h" | |
461d39af | 22 | #include "gas_query.h" |
a0d5c56f JM |
23 | #include "bss.h" |
24 | #include "scan.h" | |
8528994e | 25 | #include "notify.h" |
be27e185 JM |
26 | #include "dpp_supplicant.h" |
27 | ||
28 | ||
30d27b04 JM |
29 | static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s, |
30 | unsigned int freq); | |
461d39af JM |
31 | static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx); |
32 | static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator); | |
30d27b04 JM |
33 | static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s, |
34 | unsigned int freq, const u8 *dst, | |
35 | const u8 *src, const u8 *bssid, | |
36 | const u8 *data, size_t data_len, | |
37 | enum offchannel_send_action_result result); | |
38 | ||
39 | static const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
40 | ||
85fd8263 JM |
41 | /* Use a hardcoded Transaction ID 1 in Peer Discovery frames since there is only |
42 | * a single transaction in progress at any point in time. */ | |
43 | static const u8 TRANSACTION_ID = 1; | |
44 | ||
30d27b04 | 45 | |
461d39af JM |
46 | static struct dpp_configurator * |
47 | dpp_configurator_get_id(struct wpa_supplicant *wpa_s, unsigned int id) | |
48 | { | |
49 | struct dpp_configurator *conf; | |
50 | ||
51 | dl_list_for_each(conf, &wpa_s->dpp_configurator, | |
52 | struct dpp_configurator, list) { | |
53 | if (conf->id == id) | |
54 | return conf; | |
55 | } | |
56 | return NULL; | |
57 | } | |
58 | ||
59 | ||
be27e185 JM |
60 | static unsigned int wpas_dpp_next_id(struct wpa_supplicant *wpa_s) |
61 | { | |
62 | struct dpp_bootstrap_info *bi; | |
63 | unsigned int max_id = 0; | |
64 | ||
65 | dl_list_for_each(bi, &wpa_s->dpp_bootstrap, struct dpp_bootstrap_info, | |
66 | list) { | |
67 | if (bi->id > max_id) | |
68 | max_id = bi->id; | |
69 | } | |
70 | return max_id + 1; | |
71 | } | |
72 | ||
73 | ||
74 | /** | |
75 | * wpas_dpp_qr_code - Parse and add DPP bootstrapping info from a QR Code | |
76 | * @wpa_s: Pointer to wpa_supplicant data | |
77 | * @cmd: DPP URI read from a QR Code | |
78 | * Returns: Identifier of the stored info or -1 on failure | |
79 | */ | |
80 | int wpas_dpp_qr_code(struct wpa_supplicant *wpa_s, const char *cmd) | |
81 | { | |
82 | struct dpp_bootstrap_info *bi; | |
30d27b04 | 83 | struct dpp_authentication *auth = wpa_s->dpp_auth; |
be27e185 JM |
84 | |
85 | bi = dpp_parse_qr_code(cmd); | |
86 | if (!bi) | |
87 | return -1; | |
88 | ||
89 | bi->id = wpas_dpp_next_id(wpa_s); | |
90 | dl_list_add(&wpa_s->dpp_bootstrap, &bi->list); | |
91 | ||
30d27b04 JM |
92 | if (auth && auth->response_pending && |
93 | dpp_notify_new_qr_code(auth, bi) == 1) { | |
94 | struct wpabuf *msg; | |
95 | ||
96 | wpa_printf(MSG_DEBUG, | |
97 | "DPP: Sending out pending authentication response"); | |
98 | msg = dpp_alloc_msg(DPP_PA_AUTHENTICATION_RESP, | |
99 | wpabuf_len(auth->resp_attr)); | |
100 | if (!msg) | |
101 | goto out; | |
102 | wpabuf_put_buf(msg, wpa_s->dpp_auth->resp_attr); | |
103 | ||
104 | offchannel_send_action(wpa_s, auth->curr_freq, | |
105 | auth->peer_mac_addr, wpa_s->own_addr, | |
106 | broadcast, | |
107 | wpabuf_head(msg), wpabuf_len(msg), | |
108 | 500, wpas_dpp_tx_status, 0); | |
109 | wpabuf_free(msg); | |
110 | } | |
111 | ||
112 | out: | |
be27e185 JM |
113 | return bi->id; |
114 | } | |
115 | ||
116 | ||
117 | static char * get_param(const char *cmd, const char *param) | |
118 | { | |
119 | const char *pos, *end; | |
120 | char *val; | |
121 | size_t len; | |
122 | ||
123 | pos = os_strstr(cmd, param); | |
124 | if (!pos) | |
125 | return NULL; | |
126 | ||
127 | pos += os_strlen(param); | |
128 | end = os_strchr(pos, ' '); | |
129 | if (end) | |
130 | len = end - pos; | |
131 | else | |
132 | len = os_strlen(pos); | |
133 | val = os_malloc(len + 1); | |
134 | if (!val) | |
135 | return NULL; | |
136 | os_memcpy(val, pos, len); | |
137 | val[len] = '\0'; | |
138 | return val; | |
139 | } | |
140 | ||
141 | ||
142 | int wpas_dpp_bootstrap_gen(struct wpa_supplicant *wpa_s, const char *cmd) | |
143 | { | |
144 | char *chan = NULL, *mac = NULL, *info = NULL, *pk = NULL, *curve = NULL; | |
145 | char *key = NULL; | |
146 | u8 *privkey = NULL; | |
147 | size_t privkey_len = 0; | |
148 | size_t len; | |
149 | int ret = -1; | |
150 | struct dpp_bootstrap_info *bi; | |
151 | ||
152 | bi = os_zalloc(sizeof(*bi)); | |
153 | if (!bi) | |
154 | goto fail; | |
155 | ||
156 | if (os_strstr(cmd, "type=qrcode")) | |
157 | bi->type = DPP_BOOTSTRAP_QR_CODE; | |
500ed7f0 JM |
158 | else if (os_strstr(cmd, "type=pkex")) |
159 | bi->type = DPP_BOOTSTRAP_PKEX; | |
be27e185 JM |
160 | else |
161 | goto fail; | |
162 | ||
163 | chan = get_param(cmd, " chan="); | |
164 | mac = get_param(cmd, " mac="); | |
165 | info = get_param(cmd, " info="); | |
166 | curve = get_param(cmd, " curve="); | |
167 | key = get_param(cmd, " key="); | |
168 | ||
169 | if (key) { | |
170 | privkey_len = os_strlen(key) / 2; | |
171 | privkey = os_malloc(privkey_len); | |
172 | if (!privkey || | |
173 | hexstr2bin(key, privkey, privkey_len) < 0) | |
174 | goto fail; | |
175 | } | |
176 | ||
177 | pk = dpp_keygen(bi, curve, privkey, privkey_len); | |
178 | if (!pk) | |
179 | goto fail; | |
180 | ||
181 | len = 4; /* "DPP:" */ | |
182 | if (chan) { | |
183 | if (dpp_parse_uri_chan_list(bi, chan) < 0) | |
184 | goto fail; | |
185 | len += 3 + os_strlen(chan); /* C:...; */ | |
186 | } | |
187 | if (mac) { | |
188 | if (dpp_parse_uri_mac(bi, mac) < 0) | |
189 | goto fail; | |
190 | len += 3 + os_strlen(mac); /* M:...; */ | |
191 | } | |
192 | if (info) { | |
193 | if (dpp_parse_uri_info(bi, info) < 0) | |
194 | goto fail; | |
195 | len += 3 + os_strlen(info); /* I:...; */ | |
196 | } | |
197 | len += 4 + os_strlen(pk); | |
198 | bi->uri = os_malloc(len + 1); | |
199 | if (!bi->uri) | |
200 | goto fail; | |
201 | os_snprintf(bi->uri, len + 1, "DPP:%s%s%s%s%s%s%s%s%sK:%s;;", | |
202 | chan ? "C:" : "", chan ? chan : "", chan ? ";" : "", | |
203 | mac ? "M:" : "", mac ? mac : "", mac ? ";" : "", | |
204 | info ? "I:" : "", info ? info : "", info ? ";" : "", | |
205 | pk); | |
206 | bi->id = wpas_dpp_next_id(wpa_s); | |
207 | dl_list_add(&wpa_s->dpp_bootstrap, &bi->list); | |
208 | ret = bi->id; | |
209 | bi = NULL; | |
210 | fail: | |
211 | os_free(curve); | |
212 | os_free(pk); | |
213 | os_free(chan); | |
214 | os_free(mac); | |
215 | os_free(info); | |
216 | str_clear_free(key); | |
217 | bin_clear_free(privkey, privkey_len); | |
218 | dpp_bootstrap_info_free(bi); | |
219 | return ret; | |
220 | } | |
221 | ||
222 | ||
223 | static struct dpp_bootstrap_info * | |
224 | dpp_bootstrap_get_id(struct wpa_supplicant *wpa_s, unsigned int id) | |
225 | { | |
226 | struct dpp_bootstrap_info *bi; | |
227 | ||
228 | dl_list_for_each(bi, &wpa_s->dpp_bootstrap, struct dpp_bootstrap_info, | |
229 | list) { | |
230 | if (bi->id == id) | |
231 | return bi; | |
232 | } | |
233 | return NULL; | |
234 | } | |
235 | ||
236 | ||
237 | static int dpp_bootstrap_del(struct wpa_supplicant *wpa_s, unsigned int id) | |
238 | { | |
239 | struct dpp_bootstrap_info *bi, *tmp; | |
240 | int found = 0; | |
241 | ||
242 | dl_list_for_each_safe(bi, tmp, &wpa_s->dpp_bootstrap, | |
243 | struct dpp_bootstrap_info, list) { | |
244 | if (id && bi->id != id) | |
245 | continue; | |
246 | found = 1; | |
247 | dl_list_del(&bi->list); | |
248 | dpp_bootstrap_info_free(bi); | |
249 | } | |
250 | ||
251 | if (id == 0) | |
252 | return 0; /* flush succeeds regardless of entries found */ | |
253 | return found ? 0 : -1; | |
254 | } | |
255 | ||
256 | ||
257 | int wpas_dpp_bootstrap_remove(struct wpa_supplicant *wpa_s, const char *id) | |
258 | { | |
259 | unsigned int id_val; | |
260 | ||
261 | if (os_strcmp(id, "*") == 0) { | |
262 | id_val = 0; | |
263 | } else { | |
264 | id_val = atoi(id); | |
265 | if (id_val == 0) | |
266 | return -1; | |
267 | } | |
268 | ||
269 | return dpp_bootstrap_del(wpa_s, id_val); | |
270 | } | |
271 | ||
272 | ||
273 | const char * wpas_dpp_bootstrap_get_uri(struct wpa_supplicant *wpa_s, | |
274 | unsigned int id) | |
275 | { | |
276 | struct dpp_bootstrap_info *bi; | |
277 | ||
278 | bi = dpp_bootstrap_get_id(wpa_s, id); | |
279 | if (!bi) | |
280 | return NULL; | |
281 | return bi->uri; | |
282 | } | |
283 | ||
284 | ||
6a7182a9 JM |
285 | int wpas_dpp_bootstrap_info(struct wpa_supplicant *wpa_s, int id, |
286 | char *reply, int reply_size) | |
287 | { | |
288 | struct dpp_bootstrap_info *bi; | |
289 | ||
290 | bi = dpp_bootstrap_get_id(wpa_s, id); | |
291 | if (!bi) | |
292 | return -1; | |
293 | return os_snprintf(reply, reply_size, "type=%s\n" | |
294 | "mac_addr=" MACSTR "\n" | |
295 | "info=%s\n" | |
296 | "num_freq=%u\n" | |
297 | "curve=%s\n", | |
484788b8 | 298 | dpp_bootstrap_type_txt(bi->type), |
6a7182a9 JM |
299 | MAC2STR(bi->mac_addr), |
300 | bi->info ? bi->info : "", | |
301 | bi->num_freq, | |
302 | bi->curve->name); | |
303 | } | |
304 | ||
305 | ||
30d27b04 JM |
306 | static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s, |
307 | unsigned int freq, const u8 *dst, | |
308 | const u8 *src, const u8 *bssid, | |
309 | const u8 *data, size_t data_len, | |
310 | enum offchannel_send_action_result result) | |
311 | { | |
312 | wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR | |
313 | " result=%s", | |
314 | freq, MAC2STR(dst), | |
315 | result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" : | |
316 | (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" : | |
317 | "FAILED")); | |
318 | ||
319 | if (!wpa_s->dpp_auth) { | |
320 | wpa_printf(MSG_DEBUG, | |
321 | "DPP: Ignore TX status since there is no ongoing authentication exchange"); | |
322 | return; | |
323 | } | |
324 | ||
325 | if (wpa_s->dpp_auth->remove_on_tx_status) { | |
326 | wpa_printf(MSG_DEBUG, | |
327 | "DPP: Terminate authentication exchange due to an earlier error"); | |
461d39af JM |
328 | eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL); |
329 | offchannel_send_action_done(wpa_s); | |
30d27b04 JM |
330 | dpp_auth_deinit(wpa_s->dpp_auth); |
331 | wpa_s->dpp_auth = NULL; | |
332 | return; | |
333 | } | |
334 | ||
461d39af JM |
335 | if (wpa_s->dpp_auth_ok_on_ack) |
336 | wpas_dpp_auth_success(wpa_s, 1); | |
337 | ||
30d27b04 JM |
338 | if (!is_broadcast_ether_addr(dst) && |
339 | result != OFFCHANNEL_SEND_ACTION_SUCCESS) { | |
340 | wpa_printf(MSG_DEBUG, | |
341 | "DPP: Unicast DPP Action frame was not ACKed"); | |
342 | /* TODO: In case of DPP Authentication Request frame, move to | |
343 | * the next channel immediately */ | |
344 | } | |
345 | } | |
346 | ||
347 | ||
348 | static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx) | |
349 | { | |
350 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
351 | ||
352 | if (!wpa_s->dpp_auth) | |
353 | return; | |
354 | wpa_printf(MSG_DEBUG, "DPP: Continue reply wait on channel %u MHz", | |
355 | wpa_s->dpp_auth->curr_freq); | |
356 | wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->curr_freq); | |
357 | } | |
358 | ||
359 | ||
461d39af JM |
360 | static void wpas_dpp_set_testing_options(struct wpa_supplicant *wpa_s, |
361 | struct dpp_authentication *auth) | |
362 | { | |
363 | #ifdef CONFIG_TESTING_OPTIONS | |
364 | if (wpa_s->dpp_config_obj_override) | |
365 | auth->config_obj_override = | |
366 | os_strdup(wpa_s->dpp_config_obj_override); | |
367 | if (wpa_s->dpp_discovery_override) | |
368 | auth->discovery_override = | |
369 | os_strdup(wpa_s->dpp_discovery_override); | |
370 | if (wpa_s->dpp_groups_override) | |
371 | auth->groups_override = | |
372 | os_strdup(wpa_s->dpp_groups_override); | |
461d39af JM |
373 | auth->ignore_netaccesskey_mismatch = |
374 | wpa_s->dpp_ignore_netaccesskey_mismatch; | |
375 | #endif /* CONFIG_TESTING_OPTIONS */ | |
376 | } | |
377 | ||
378 | ||
b65b22d6 JM |
379 | static void wpas_dpp_set_configurator(struct wpa_supplicant *wpa_s, |
380 | struct dpp_authentication *auth, | |
381 | const char *cmd) | |
30d27b04 | 382 | { |
68cb6dce | 383 | const char *pos, *end; |
461d39af JM |
384 | struct dpp_configuration *conf_sta = NULL, *conf_ap = NULL; |
385 | struct dpp_configurator *conf = NULL; | |
68cb6dce JM |
386 | u8 ssid[32] = { "test" }; |
387 | size_t ssid_len = 4; | |
35f06421 JM |
388 | char pass[64] = { }; |
389 | size_t pass_len = 0; | |
5030d7d9 JM |
390 | u8 psk[PMK_LEN]; |
391 | int psk_set = 0; | |
461d39af | 392 | |
b65b22d6 JM |
393 | if (!cmd) |
394 | return; | |
461d39af | 395 | |
b65b22d6 | 396 | wpa_printf(MSG_DEBUG, "DPP: Set configurator parameters: %s", cmd); |
68cb6dce JM |
397 | pos = os_strstr(cmd, " ssid="); |
398 | if (pos) { | |
399 | pos += 6; | |
400 | end = os_strchr(pos, ' '); | |
401 | ssid_len = end ? (size_t) (end - pos) : os_strlen(pos); | |
402 | ssid_len /= 2; | |
403 | if (ssid_len > sizeof(ssid) || | |
404 | hexstr2bin(pos, ssid, ssid_len) < 0) | |
405 | goto fail; | |
406 | } | |
407 | ||
35f06421 JM |
408 | pos = os_strstr(cmd, " pass="); |
409 | if (pos) { | |
410 | pos += 6; | |
411 | end = os_strchr(pos, ' '); | |
412 | pass_len = end ? (size_t) (end - pos) : os_strlen(pos); | |
413 | pass_len /= 2; | |
414 | if (pass_len > sizeof(pass) - 1 || pass_len < 8 || | |
415 | hexstr2bin(pos, (u8 *) pass, pass_len) < 0) | |
416 | goto fail; | |
417 | } | |
418 | ||
5030d7d9 JM |
419 | pos = os_strstr(cmd, " psk="); |
420 | if (pos) { | |
421 | pos += 5; | |
422 | if (hexstr2bin(pos, psk, PMK_LEN) < 0) | |
423 | goto fail; | |
424 | psk_set = 1; | |
425 | } | |
426 | ||
461d39af JM |
427 | if (os_strstr(cmd, " conf=sta-")) { |
428 | conf_sta = os_zalloc(sizeof(struct dpp_configuration)); | |
429 | if (!conf_sta) | |
430 | goto fail; | |
68cb6dce JM |
431 | os_memcpy(conf_sta->ssid, ssid, ssid_len); |
432 | conf_sta->ssid_len = ssid_len; | |
461d39af JM |
433 | if (os_strstr(cmd, " conf=sta-psk")) { |
434 | conf_sta->dpp = 0; | |
5030d7d9 JM |
435 | if (psk_set) { |
436 | os_memcpy(conf_sta->psk, psk, PMK_LEN); | |
437 | } else { | |
438 | conf_sta->passphrase = os_strdup(pass); | |
439 | if (!conf_sta->passphrase) | |
440 | goto fail; | |
441 | } | |
461d39af JM |
442 | } else if (os_strstr(cmd, " conf=sta-dpp")) { |
443 | conf_sta->dpp = 1; | |
444 | } else { | |
445 | goto fail; | |
446 | } | |
447 | } | |
448 | ||
449 | if (os_strstr(cmd, " conf=ap-")) { | |
450 | conf_ap = os_zalloc(sizeof(struct dpp_configuration)); | |
451 | if (!conf_ap) | |
452 | goto fail; | |
68cb6dce JM |
453 | os_memcpy(conf_ap->ssid, ssid, ssid_len); |
454 | conf_ap->ssid_len = ssid_len; | |
461d39af JM |
455 | if (os_strstr(cmd, " conf=ap-psk")) { |
456 | conf_ap->dpp = 0; | |
5030d7d9 JM |
457 | if (psk_set) { |
458 | os_memcpy(conf_ap->psk, psk, PMK_LEN); | |
459 | } else { | |
460 | conf_ap->passphrase = os_strdup(pass); | |
461 | if (!conf_ap->passphrase) | |
462 | goto fail; | |
463 | } | |
461d39af JM |
464 | } else if (os_strstr(cmd, " conf=ap-dpp")) { |
465 | conf_ap->dpp = 1; | |
466 | } else { | |
467 | goto fail; | |
468 | } | |
469 | } | |
470 | ||
471 | pos = os_strstr(cmd, " expiry="); | |
472 | if (pos) { | |
473 | long int val; | |
474 | ||
475 | pos += 8; | |
476 | val = strtol(pos, NULL, 0); | |
477 | if (val <= 0) | |
478 | goto fail; | |
479 | if (conf_sta) | |
480 | conf_sta->netaccesskey_expiry = val; | |
481 | if (conf_ap) | |
482 | conf_ap->netaccesskey_expiry = val; | |
483 | } | |
484 | ||
485 | pos = os_strstr(cmd, " configurator="); | |
486 | if (pos) { | |
487 | pos += 14; | |
488 | conf = dpp_configurator_get_id(wpa_s, atoi(pos)); | |
489 | if (!conf) { | |
490 | wpa_printf(MSG_INFO, | |
491 | "DPP: Could not find the specified configurator"); | |
492 | goto fail; | |
493 | } | |
30d27b04 | 494 | } |
b65b22d6 JM |
495 | auth->conf_sta = conf_sta; |
496 | auth->conf_ap = conf_ap; | |
497 | auth->conf = conf; | |
498 | return; | |
499 | ||
500 | fail: | |
501 | wpa_printf(MSG_DEBUG, "DPP: Failed to set configurator parameters"); | |
502 | dpp_configuration_free(conf_sta); | |
503 | dpp_configuration_free(conf_ap); | |
504 | } | |
505 | ||
506 | ||
507 | int wpas_dpp_auth_init(struct wpa_supplicant *wpa_s, const char *cmd) | |
508 | { | |
509 | const char *pos; | |
510 | struct dpp_bootstrap_info *peer_bi, *own_bi = NULL; | |
511 | struct wpabuf *msg; | |
512 | const u8 *dst; | |
513 | int res; | |
514 | int configurator = 1; | |
515 | unsigned int wait_time; | |
516 | ||
517 | wpa_s->dpp_gas_client = 0; | |
518 | ||
519 | pos = os_strstr(cmd, " peer="); | |
520 | if (!pos) | |
521 | return -1; | |
522 | pos += 6; | |
523 | peer_bi = dpp_bootstrap_get_id(wpa_s, atoi(pos)); | |
524 | if (!peer_bi) { | |
525 | wpa_printf(MSG_INFO, | |
526 | "DPP: Could not find bootstrapping info for the identified peer"); | |
527 | return -1; | |
528 | } | |
529 | ||
530 | pos = os_strstr(cmd, " own="); | |
531 | if (pos) { | |
532 | pos += 5; | |
533 | own_bi = dpp_bootstrap_get_id(wpa_s, atoi(pos)); | |
534 | if (!own_bi) { | |
535 | wpa_printf(MSG_INFO, | |
536 | "DPP: Could not find bootstrapping info for the identified local entry"); | |
537 | return -1; | |
538 | } | |
539 | ||
540 | if (peer_bi->curve != own_bi->curve) { | |
541 | wpa_printf(MSG_INFO, | |
542 | "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)", | |
543 | peer_bi->curve->name, own_bi->curve->name); | |
544 | return -1; | |
545 | } | |
546 | } | |
547 | ||
548 | pos = os_strstr(cmd, " role="); | |
549 | if (pos) { | |
550 | pos += 6; | |
551 | if (os_strncmp(pos, "configurator", 12) == 0) | |
552 | configurator = 1; | |
553 | else if (os_strncmp(pos, "enrollee", 8) == 0) | |
554 | configurator = 0; | |
555 | else | |
556 | goto fail; | |
557 | } | |
558 | ||
559 | pos = os_strstr(cmd, " netrole="); | |
560 | if (pos) { | |
561 | pos += 9; | |
562 | wpa_s->dpp_netrole_ap = os_strncmp(pos, "ap", 2) == 0; | |
563 | } | |
30d27b04 JM |
564 | |
565 | if (wpa_s->dpp_auth) { | |
566 | eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL); | |
567 | offchannel_send_action_done(wpa_s); | |
568 | dpp_auth_deinit(wpa_s->dpp_auth); | |
569 | } | |
570 | wpa_s->dpp_auth = dpp_auth_init(wpa_s, peer_bi, own_bi, configurator); | |
571 | if (!wpa_s->dpp_auth) | |
461d39af JM |
572 | goto fail; |
573 | wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth); | |
b65b22d6 | 574 | wpas_dpp_set_configurator(wpa_s, wpa_s->dpp_auth, cmd); |
30d27b04 JM |
575 | |
576 | /* TODO: Support iteration over all frequencies and filtering of | |
577 | * frequencies based on locally enabled channels that allow initiation | |
578 | * of transmission. */ | |
579 | if (peer_bi->num_freq > 0) | |
580 | wpa_s->dpp_auth->curr_freq = peer_bi->freq[0]; | |
581 | else | |
582 | wpa_s->dpp_auth->curr_freq = 2412; | |
583 | ||
584 | msg = dpp_alloc_msg(DPP_PA_AUTHENTICATION_REQ, | |
585 | wpabuf_len(wpa_s->dpp_auth->req_attr)); | |
586 | if (!msg) | |
587 | return -1; | |
588 | wpabuf_put_buf(msg, wpa_s->dpp_auth->req_attr); | |
589 | ||
590 | if (is_zero_ether_addr(peer_bi->mac_addr)) { | |
591 | dst = broadcast; | |
592 | } else { | |
593 | dst = peer_bi->mac_addr; | |
594 | os_memcpy(wpa_s->dpp_auth->peer_mac_addr, peer_bi->mac_addr, | |
595 | ETH_ALEN); | |
596 | } | |
461d39af | 597 | wpa_s->dpp_auth_ok_on_ack = 0; |
30d27b04 JM |
598 | eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL); |
599 | wait_time = wpa_s->max_remain_on_chan; | |
600 | if (wait_time > 2000) | |
601 | wait_time = 2000; | |
602 | eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000, | |
603 | wpas_dpp_reply_wait_timeout, | |
604 | wpa_s, NULL); | |
605 | res = offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq, | |
606 | dst, wpa_s->own_addr, broadcast, | |
607 | wpabuf_head(msg), wpabuf_len(msg), | |
608 | wait_time, wpas_dpp_tx_status, 0); | |
609 | wpabuf_free(msg); | |
610 | ||
611 | return res; | |
461d39af | 612 | fail: |
461d39af | 613 | return -1; |
30d27b04 JM |
614 | } |
615 | ||
616 | ||
617 | struct wpas_dpp_listen_work { | |
618 | unsigned int freq; | |
619 | unsigned int duration; | |
620 | struct wpabuf *probe_resp_ie; | |
621 | }; | |
622 | ||
623 | ||
624 | static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work *lwork) | |
625 | { | |
626 | if (!lwork) | |
627 | return; | |
628 | os_free(lwork); | |
629 | } | |
630 | ||
631 | ||
632 | static void wpas_dpp_listen_work_done(struct wpa_supplicant *wpa_s) | |
633 | { | |
634 | struct wpas_dpp_listen_work *lwork; | |
635 | ||
636 | if (!wpa_s->dpp_listen_work) | |
637 | return; | |
638 | ||
639 | lwork = wpa_s->dpp_listen_work->ctx; | |
640 | wpas_dpp_listen_work_free(lwork); | |
641 | radio_work_done(wpa_s->dpp_listen_work); | |
642 | wpa_s->dpp_listen_work = NULL; | |
643 | } | |
644 | ||
645 | ||
646 | static void dpp_start_listen_cb(struct wpa_radio_work *work, int deinit) | |
647 | { | |
648 | struct wpa_supplicant *wpa_s = work->wpa_s; | |
649 | struct wpas_dpp_listen_work *lwork = work->ctx; | |
650 | ||
651 | if (deinit) { | |
652 | if (work->started) { | |
653 | wpa_s->dpp_listen_work = NULL; | |
654 | wpas_dpp_listen_stop(wpa_s); | |
655 | } | |
656 | wpas_dpp_listen_work_free(lwork); | |
657 | return; | |
658 | } | |
659 | ||
660 | wpa_s->dpp_listen_work = work; | |
661 | ||
662 | wpa_s->dpp_pending_listen_freq = lwork->freq; | |
663 | ||
664 | if (wpa_drv_remain_on_channel(wpa_s, lwork->freq, | |
665 | wpa_s->max_remain_on_chan) < 0) { | |
666 | wpa_printf(MSG_DEBUG, | |
667 | "DPP: Failed to request the driver to remain on channel (%u MHz) for listen", | |
668 | lwork->freq); | |
669 | wpas_dpp_listen_work_done(wpa_s); | |
670 | wpa_s->dpp_pending_listen_freq = 0; | |
671 | return; | |
672 | } | |
673 | wpa_s->off_channel_freq = 0; | |
674 | wpa_s->roc_waiting_drv_freq = lwork->freq; | |
675 | } | |
676 | ||
677 | ||
678 | static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s, | |
679 | unsigned int freq) | |
680 | { | |
681 | struct wpas_dpp_listen_work *lwork; | |
682 | ||
683 | if (wpa_s->dpp_listen_work) { | |
684 | wpa_printf(MSG_DEBUG, | |
685 | "DPP: Reject start_listen since dpp_listen_work already exists"); | |
686 | return -1; | |
687 | } | |
688 | ||
689 | if (wpa_s->dpp_listen_freq) | |
690 | wpas_dpp_listen_stop(wpa_s); | |
691 | wpa_s->dpp_listen_freq = freq; | |
692 | ||
693 | lwork = os_zalloc(sizeof(*lwork)); | |
694 | if (!lwork) | |
695 | return -1; | |
696 | lwork->freq = freq; | |
697 | ||
698 | if (radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb, | |
699 | lwork) < 0) { | |
700 | wpas_dpp_listen_work_free(lwork); | |
701 | return -1; | |
702 | } | |
703 | ||
704 | return 0; | |
705 | } | |
706 | ||
707 | ||
708 | int wpas_dpp_listen(struct wpa_supplicant *wpa_s, const char *cmd) | |
709 | { | |
710 | int freq; | |
711 | ||
712 | freq = atoi(cmd); | |
713 | if (freq <= 0) | |
714 | return -1; | |
715 | ||
716 | if (os_strstr(cmd, " role=configurator")) | |
717 | wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR; | |
718 | else if (os_strstr(cmd, " role=enrollee")) | |
719 | wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE; | |
720 | else | |
721 | wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR | | |
722 | DPP_CAPAB_ENROLLEE; | |
723 | wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL; | |
461d39af | 724 | wpa_s->dpp_netrole_ap = os_strstr(cmd, " netrole=ap") != NULL; |
30d27b04 JM |
725 | if (wpa_s->dpp_listen_freq == (unsigned int) freq) { |
726 | wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz", | |
727 | freq); | |
728 | return 0; | |
729 | } | |
730 | ||
731 | return wpas_dpp_listen_start(wpa_s, freq); | |
732 | } | |
733 | ||
734 | ||
735 | void wpas_dpp_listen_stop(struct wpa_supplicant *wpa_s) | |
736 | { | |
737 | if (!wpa_s->dpp_listen_freq) | |
738 | return; | |
739 | ||
740 | wpa_printf(MSG_DEBUG, "DPP: Stop listen on %u MHz", | |
741 | wpa_s->dpp_listen_freq); | |
742 | wpa_drv_cancel_remain_on_channel(wpa_s); | |
743 | wpa_s->dpp_listen_freq = 0; | |
744 | wpas_dpp_listen_work_done(wpa_s); | |
745 | } | |
746 | ||
747 | ||
748 | void wpas_dpp_remain_on_channel_cb(struct wpa_supplicant *wpa_s, | |
749 | unsigned int freq) | |
750 | { | |
751 | if (!wpa_s->dpp_listen_freq && !wpa_s->dpp_pending_listen_freq) | |
752 | return; | |
753 | ||
754 | wpa_printf(MSG_DEBUG, | |
755 | "DPP: remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d roc_waiting_drv_freq=%d freq=%u)", | |
756 | wpa_s->off_channel_freq, wpa_s->dpp_pending_listen_freq, | |
757 | wpa_s->roc_waiting_drv_freq, freq); | |
758 | if (wpa_s->off_channel_freq && | |
759 | wpa_s->off_channel_freq == wpa_s->dpp_pending_listen_freq) { | |
760 | wpa_printf(MSG_DEBUG, "DPP: Listen on %u MHz started", freq); | |
761 | wpa_s->dpp_pending_listen_freq = 0; | |
762 | } else { | |
763 | wpa_printf(MSG_DEBUG, | |
764 | "DPP: Ignore remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d freq=%u)", | |
765 | wpa_s->off_channel_freq, | |
766 | wpa_s->dpp_pending_listen_freq, freq); | |
767 | } | |
768 | } | |
769 | ||
770 | ||
771 | void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s, | |
772 | unsigned int freq) | |
773 | { | |
774 | wpas_dpp_listen_work_done(wpa_s); | |
775 | ||
461d39af | 776 | if (wpa_s->dpp_auth && !wpa_s->dpp_gas_client) { |
30d27b04 JM |
777 | /* Continue listen with a new remain-on-channel */ |
778 | wpa_printf(MSG_DEBUG, | |
779 | "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session", | |
780 | wpa_s->dpp_auth->curr_freq); | |
781 | wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->curr_freq); | |
782 | return; | |
783 | } | |
784 | ||
785 | if (wpa_s->dpp_listen_freq) { | |
786 | /* Continue listen with a new remain-on-channel */ | |
787 | wpas_dpp_listen_start(wpa_s, wpa_s->dpp_listen_freq); | |
788 | } | |
789 | } | |
790 | ||
791 | ||
792 | static void wpas_dpp_rx_auth_req(struct wpa_supplicant *wpa_s, const u8 *src, | |
793 | const u8 *buf, size_t len, unsigned int freq) | |
794 | { | |
795 | const u8 *r_bootstrap, *i_bootstrap, *wrapped_data; | |
796 | u16 r_bootstrap_len, i_bootstrap_len, wrapped_data_len; | |
797 | struct dpp_bootstrap_info *bi, *own_bi = NULL, *peer_bi = NULL; | |
798 | struct wpabuf *msg; | |
799 | ||
800 | wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR, | |
801 | MAC2STR(src)); | |
802 | ||
803 | wrapped_data = dpp_get_attr(buf, len, DPP_ATTR_WRAPPED_DATA, | |
804 | &wrapped_data_len); | |
805 | if (!wrapped_data) { | |
806 | wpa_printf(MSG_DEBUG, | |
807 | "DPP: Missing required Wrapped data attribute"); | |
808 | return; | |
809 | } | |
810 | wpa_hexdump(MSG_MSGDUMP, "DPP: Wrapped data", | |
811 | wrapped_data, wrapped_data_len); | |
812 | ||
813 | r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH, | |
814 | &r_bootstrap_len); | |
815 | if (!r_bootstrap || r_bootstrap > wrapped_data || | |
816 | r_bootstrap_len != SHA256_MAC_LEN) { | |
817 | wpa_printf(MSG_DEBUG, | |
818 | "DPP: Missing or invalid required Responder Bootstrapping Key Hash attribute"); | |
819 | return; | |
820 | } | |
821 | wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash", | |
822 | r_bootstrap, r_bootstrap_len); | |
823 | ||
824 | i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH, | |
825 | &i_bootstrap_len); | |
826 | if (!i_bootstrap || i_bootstrap > wrapped_data || | |
827 | i_bootstrap_len != SHA256_MAC_LEN) { | |
828 | wpa_printf(MSG_DEBUG, | |
829 | "DPP: Missing or invalid required Initiator Bootstrapping Key Hash attribute"); | |
830 | return; | |
831 | } | |
832 | wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash", | |
833 | i_bootstrap, i_bootstrap_len); | |
834 | ||
835 | /* Try to find own and peer bootstrapping key matches based on the | |
836 | * received hash values */ | |
837 | dl_list_for_each(bi, &wpa_s->dpp_bootstrap, struct dpp_bootstrap_info, | |
838 | list) { | |
839 | if (!own_bi && bi->own && | |
840 | os_memcmp(bi->pubkey_hash, r_bootstrap, | |
841 | SHA256_MAC_LEN) == 0) { | |
842 | wpa_printf(MSG_DEBUG, | |
843 | "DPP: Found matching own bootstrapping information"); | |
844 | own_bi = bi; | |
845 | } | |
846 | ||
847 | if (!peer_bi && !bi->own && | |
848 | os_memcmp(bi->pubkey_hash, i_bootstrap, | |
849 | SHA256_MAC_LEN) == 0) { | |
850 | wpa_printf(MSG_DEBUG, | |
851 | "DPP: Found matching peer bootstrapping information"); | |
852 | peer_bi = bi; | |
853 | } | |
854 | ||
855 | if (own_bi && peer_bi) | |
856 | break; | |
857 | } | |
858 | ||
859 | if (!own_bi) { | |
860 | wpa_printf(MSG_DEBUG, | |
861 | "DPP: No matching own bootstrapping key found - ignore message"); | |
862 | return; | |
863 | } | |
864 | ||
865 | if (wpa_s->dpp_auth) { | |
866 | wpa_printf(MSG_DEBUG, | |
867 | "DPP: Already in DPP authentication exchange - ignore new one"); | |
868 | return; | |
869 | } | |
870 | ||
461d39af JM |
871 | wpa_s->dpp_gas_client = 0; |
872 | wpa_s->dpp_auth_ok_on_ack = 0; | |
30d27b04 JM |
873 | wpa_s->dpp_auth = dpp_auth_req_rx(wpa_s, wpa_s->dpp_allowed_roles, |
874 | wpa_s->dpp_qr_mutual, | |
875 | peer_bi, own_bi, freq, buf, | |
876 | wrapped_data, wrapped_data_len); | |
877 | if (!wpa_s->dpp_auth) { | |
878 | wpa_printf(MSG_DEBUG, "DPP: No response generated"); | |
879 | return; | |
880 | } | |
461d39af | 881 | wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth); |
b65b22d6 JM |
882 | wpas_dpp_set_configurator(wpa_s, wpa_s->dpp_auth, |
883 | wpa_s->dpp_configurator_params); | |
30d27b04 JM |
884 | os_memcpy(wpa_s->dpp_auth->peer_mac_addr, src, ETH_ALEN); |
885 | ||
886 | msg = dpp_alloc_msg(DPP_PA_AUTHENTICATION_RESP, | |
887 | wpabuf_len(wpa_s->dpp_auth->resp_attr)); | |
888 | if (!msg) | |
889 | return; | |
890 | wpabuf_put_buf(msg, wpa_s->dpp_auth->resp_attr); | |
891 | ||
892 | offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq, | |
893 | src, wpa_s->own_addr, broadcast, | |
894 | wpabuf_head(msg), wpabuf_len(msg), | |
895 | 500, wpas_dpp_tx_status, 0); | |
896 | wpabuf_free(msg); | |
897 | } | |
898 | ||
899 | ||
461d39af JM |
900 | static void wpas_dpp_start_gas_server(struct wpa_supplicant *wpa_s) |
901 | { | |
902 | /* TODO: stop wait and start ROC */ | |
903 | } | |
904 | ||
905 | ||
8528994e JM |
906 | static struct wpa_ssid * wpas_dpp_add_network(struct wpa_supplicant *wpa_s, |
907 | struct dpp_authentication *auth) | |
908 | { | |
909 | struct wpa_ssid *ssid; | |
910 | ||
911 | ssid = wpa_config_add_network(wpa_s->conf); | |
912 | if (!ssid) | |
913 | return NULL; | |
914 | wpas_notify_network_added(wpa_s, ssid); | |
915 | wpa_config_set_network_defaults(ssid); | |
916 | ssid->disabled = 1; | |
917 | ||
918 | ssid->ssid = os_malloc(auth->ssid_len); | |
919 | if (!ssid->ssid) | |
920 | goto fail; | |
921 | os_memcpy(ssid->ssid, auth->ssid, auth->ssid_len); | |
922 | ssid->ssid_len = auth->ssid_len; | |
923 | ||
924 | if (auth->connector) { | |
925 | ssid->key_mgmt = WPA_KEY_MGMT_DPP; | |
926 | ssid->dpp_connector = os_strdup(auth->connector); | |
927 | if (!ssid->dpp_connector) | |
928 | goto fail; | |
929 | } | |
930 | ||
931 | if (auth->c_sign_key) { | |
932 | ssid->dpp_csign = os_malloc(wpabuf_len(auth->c_sign_key)); | |
933 | if (!ssid->dpp_csign) | |
934 | goto fail; | |
935 | os_memcpy(ssid->dpp_csign, wpabuf_head(auth->c_sign_key), | |
936 | wpabuf_len(auth->c_sign_key)); | |
937 | ssid->dpp_csign_len = wpabuf_len(auth->c_sign_key); | |
8528994e JM |
938 | } |
939 | ||
940 | if (auth->net_access_key) { | |
941 | ssid->dpp_netaccesskey = | |
942 | os_malloc(wpabuf_len(auth->net_access_key)); | |
943 | if (!ssid->dpp_netaccesskey) | |
944 | goto fail; | |
945 | os_memcpy(ssid->dpp_netaccesskey, | |
946 | wpabuf_head(auth->net_access_key), | |
947 | wpabuf_len(auth->net_access_key)); | |
948 | ssid->dpp_netaccesskey_len = wpabuf_len(auth->net_access_key); | |
949 | ssid->dpp_netaccesskey_expiry = auth->net_access_key_expiry; | |
950 | } | |
951 | ||
952 | if (!auth->connector) { | |
953 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; | |
954 | if (auth->passphrase[0]) { | |
955 | if (wpa_config_set_quoted(ssid, "psk", | |
956 | auth->passphrase) < 0) | |
957 | goto fail; | |
958 | wpa_config_update_psk(ssid); | |
959 | ssid->export_keys = 1; | |
960 | } else { | |
961 | ssid->psk_set = auth->psk_set; | |
962 | os_memcpy(ssid->psk, auth->psk, PMK_LEN); | |
963 | } | |
964 | } | |
965 | ||
966 | return ssid; | |
967 | fail: | |
968 | wpas_notify_network_removed(wpa_s, ssid); | |
969 | wpa_config_remove_network(wpa_s->conf, ssid->id); | |
970 | return NULL; | |
971 | } | |
972 | ||
973 | ||
974 | static void wpas_dpp_process_config(struct wpa_supplicant *wpa_s, | |
975 | struct dpp_authentication *auth) | |
976 | { | |
977 | struct wpa_ssid *ssid; | |
978 | ||
979 | if (wpa_s->conf->dpp_config_processing < 1) | |
980 | return; | |
981 | ||
982 | ssid = wpas_dpp_add_network(wpa_s, auth); | |
983 | if (!ssid) | |
984 | return; | |
985 | ||
986 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_NETWORK_ID "%d", ssid->id); | |
987 | if (wpa_s->conf->dpp_config_processing < 2) | |
988 | return; | |
989 | ||
990 | wpa_printf(MSG_DEBUG, "DPP: Trying to connect to the new network"); | |
991 | ssid->disabled = 0; | |
992 | wpa_s->disconnected = 0; | |
993 | wpa_s->reassociate = 1; | |
994 | wpa_s->scan_runs = 0; | |
995 | wpa_s->normal_scans = 0; | |
996 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
997 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
998 | } | |
999 | ||
1000 | ||
f522bb23 JM |
1001 | static void wpas_dpp_handle_config_obj(struct wpa_supplicant *wpa_s, |
1002 | struct dpp_authentication *auth) | |
461d39af | 1003 | { |
461d39af JM |
1004 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED); |
1005 | if (auth->ssid_len) | |
1006 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s", | |
1007 | wpa_ssid_txt(auth->ssid, auth->ssid_len)); | |
1008 | if (auth->connector) { | |
1009 | /* TODO: Save the Connector and consider using a command | |
1010 | * to fetch the value instead of sending an event with | |
1011 | * it. The Connector could end up being larger than what | |
1012 | * most clients are ready to receive as an event | |
1013 | * message. */ | |
1014 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONNECTOR "%s", | |
1015 | auth->connector); | |
1016 | } | |
1017 | if (auth->c_sign_key) { | |
1018 | char *hex; | |
1019 | size_t hexlen; | |
1020 | ||
1021 | hexlen = 2 * wpabuf_len(auth->c_sign_key) + 1; | |
1022 | hex = os_malloc(hexlen); | |
1023 | if (hex) { | |
1024 | wpa_snprintf_hex(hex, hexlen, | |
1025 | wpabuf_head(auth->c_sign_key), | |
1026 | wpabuf_len(auth->c_sign_key)); | |
c77e2ff0 JM |
1027 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_C_SIGN_KEY "%s", |
1028 | hex); | |
461d39af JM |
1029 | os_free(hex); |
1030 | } | |
1031 | } | |
1032 | if (auth->net_access_key) { | |
1033 | char *hex; | |
1034 | size_t hexlen; | |
1035 | ||
1036 | hexlen = 2 * wpabuf_len(auth->net_access_key) + 1; | |
1037 | hex = os_malloc(hexlen); | |
1038 | if (hex) { | |
1039 | wpa_snprintf_hex(hex, hexlen, | |
1040 | wpabuf_head(auth->net_access_key), | |
1041 | wpabuf_len(auth->net_access_key)); | |
1042 | if (auth->net_access_key_expiry) | |
1043 | wpa_msg(wpa_s, MSG_INFO, | |
1044 | DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex, | |
1045 | (long unsigned) | |
1046 | auth->net_access_key_expiry); | |
1047 | else | |
1048 | wpa_msg(wpa_s, MSG_INFO, | |
1049 | DPP_EVENT_NET_ACCESS_KEY "%s", hex); | |
1050 | os_free(hex); | |
1051 | } | |
1052 | } | |
8528994e JM |
1053 | |
1054 | wpas_dpp_process_config(wpa_s, auth); | |
f522bb23 JM |
1055 | } |
1056 | ||
1057 | ||
1058 | static void wpas_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token, | |
1059 | enum gas_query_result result, | |
1060 | const struct wpabuf *adv_proto, | |
1061 | const struct wpabuf *resp, u16 status_code) | |
1062 | { | |
1063 | struct wpa_supplicant *wpa_s = ctx; | |
1064 | const u8 *pos; | |
1065 | struct dpp_authentication *auth = wpa_s->dpp_auth; | |
1066 | ||
1067 | if (!auth || !auth->auth_success) { | |
1068 | wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress"); | |
1069 | return; | |
1070 | } | |
1071 | if (!resp || status_code != WLAN_STATUS_SUCCESS) { | |
1072 | wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed"); | |
1073 | goto fail; | |
1074 | } | |
1075 | ||
1076 | wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto", | |
1077 | adv_proto); | |
1078 | wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)", | |
1079 | resp); | |
1080 | ||
1081 | if (wpabuf_len(adv_proto) != 10 || | |
1082 | !(pos = wpabuf_head(adv_proto)) || | |
1083 | pos[0] != WLAN_EID_ADV_PROTO || | |
1084 | pos[1] != 8 || | |
1085 | pos[3] != WLAN_EID_VENDOR_SPECIFIC || | |
1086 | pos[4] != 5 || | |
1087 | WPA_GET_BE24(&pos[5]) != OUI_WFA || | |
1088 | pos[8] != 0x1a || | |
1089 | pos[9] != 1) { | |
1090 | wpa_printf(MSG_DEBUG, | |
1091 | "DPP: Not a DPP Advertisement Protocol ID"); | |
1092 | goto fail; | |
1093 | } | |
8528994e | 1094 | |
f522bb23 JM |
1095 | if (dpp_conf_resp_rx(auth, resp) < 0) { |
1096 | wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed"); | |
1097 | goto fail; | |
1098 | } | |
1099 | ||
1100 | wpas_dpp_handle_config_obj(wpa_s, auth); | |
461d39af JM |
1101 | dpp_auth_deinit(wpa_s->dpp_auth); |
1102 | wpa_s->dpp_auth = NULL; | |
1103 | return; | |
1104 | ||
1105 | fail: | |
1106 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED); | |
1107 | dpp_auth_deinit(wpa_s->dpp_auth); | |
1108 | wpa_s->dpp_auth = NULL; | |
1109 | } | |
1110 | ||
1111 | ||
1112 | static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s) | |
1113 | { | |
1114 | struct dpp_authentication *auth = wpa_s->dpp_auth; | |
1115 | struct wpabuf *buf, *conf_req; | |
1116 | char json[100]; | |
1117 | int res; | |
1118 | ||
1119 | wpa_s->dpp_gas_client = 1; | |
1120 | os_snprintf(json, sizeof(json), | |
1121 | "{\"name\":\"Test\"," | |
1122 | "\"wi-fi_tech\":\"infra\"," | |
1123 | "\"netRole\":\"%s\"}", | |
1124 | wpa_s->dpp_netrole_ap ? "ap" : "sta"); | |
1125 | wpa_printf(MSG_DEBUG, "DPP: GAS Config Attributes: %s", json); | |
1126 | ||
1127 | offchannel_send_action_done(wpa_s); | |
1128 | wpas_dpp_listen_stop(wpa_s); | |
1129 | ||
1130 | conf_req = dpp_build_conf_req(auth, json); | |
1131 | if (!conf_req) { | |
1132 | wpa_printf(MSG_DEBUG, | |
1133 | "DPP: No configuration request data available"); | |
1134 | return; | |
1135 | } | |
1136 | ||
1137 | buf = gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req)); | |
1138 | if (!buf) { | |
1139 | wpabuf_free(conf_req); | |
1140 | return; | |
1141 | } | |
1142 | ||
1143 | /* Advertisement Protocol IE */ | |
1144 | wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO); | |
1145 | wpabuf_put_u8(buf, 8); /* Length */ | |
1146 | wpabuf_put_u8(buf, 0x7f); | |
1147 | wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC); | |
1148 | wpabuf_put_u8(buf, 5); | |
1149 | wpabuf_put_be24(buf, OUI_WFA); | |
1150 | wpabuf_put_u8(buf, DPP_OUI_TYPE); | |
1151 | wpabuf_put_u8(buf, 0x01); | |
1152 | ||
1153 | /* GAS Query */ | |
1154 | wpabuf_put_le16(buf, wpabuf_len(conf_req)); | |
1155 | wpabuf_put_buf(buf, conf_req); | |
1156 | wpabuf_free(conf_req); | |
1157 | ||
1158 | wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)", | |
1159 | MAC2STR(auth->peer_mac_addr), auth->curr_freq); | |
1160 | ||
1161 | res = gas_query_req(wpa_s->gas, auth->peer_mac_addr, auth->curr_freq, | |
1162 | buf, wpas_dpp_gas_resp_cb, wpa_s); | |
1163 | if (res < 0) { | |
1164 | wpa_msg(wpa_s, MSG_DEBUG, "GAS: Failed to send Query Request"); | |
1165 | wpabuf_free(buf); | |
1166 | } else { | |
1167 | wpa_printf(MSG_DEBUG, | |
1168 | "DPP: GAS query started with dialog token %u", res); | |
1169 | } | |
1170 | } | |
1171 | ||
1172 | ||
1173 | static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator) | |
1174 | { | |
1175 | wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded"); | |
1176 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d", initiator); | |
1177 | ||
1178 | if (wpa_s->dpp_auth->configurator) | |
1179 | wpas_dpp_start_gas_server(wpa_s); | |
1180 | else | |
1181 | wpas_dpp_start_gas_client(wpa_s); | |
1182 | } | |
1183 | ||
1184 | ||
30d27b04 JM |
1185 | static void wpas_dpp_rx_auth_resp(struct wpa_supplicant *wpa_s, const u8 *src, |
1186 | const u8 *buf, size_t len) | |
1187 | { | |
1188 | struct dpp_authentication *auth = wpa_s->dpp_auth; | |
1189 | struct wpabuf *msg, *attr; | |
1190 | ||
1191 | wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR, | |
1192 | MAC2STR(src)); | |
1193 | ||
1194 | if (!auth) { | |
1195 | wpa_printf(MSG_DEBUG, | |
1196 | "DPP: No DPP Authentication in progress - drop"); | |
1197 | return; | |
1198 | } | |
1199 | ||
1200 | if (!is_zero_ether_addr(auth->peer_mac_addr) && | |
1201 | os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) { | |
1202 | wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected " | |
1203 | MACSTR ") - drop", MAC2STR(auth->peer_mac_addr)); | |
1204 | return; | |
1205 | } | |
1206 | ||
1207 | eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL); | |
1208 | ||
1209 | attr = dpp_auth_resp_rx(auth, buf, len); | |
1210 | if (!attr) { | |
1211 | if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) { | |
1212 | wpa_printf(MSG_DEBUG, | |
1213 | "DPP: Start wait for full response"); | |
1214 | offchannel_send_action_done(wpa_s); | |
1215 | wpas_dpp_listen_start(wpa_s, auth->curr_freq); | |
1216 | return; | |
1217 | } | |
1218 | wpa_printf(MSG_DEBUG, "DPP: No confirm generated"); | |
1219 | return; | |
1220 | } | |
1221 | os_memcpy(auth->peer_mac_addr, src, ETH_ALEN); | |
1222 | ||
1223 | msg = dpp_alloc_msg(DPP_PA_AUTHENTICATION_CONF, wpabuf_len(attr)); | |
1224 | if (!msg) { | |
1225 | wpabuf_free(attr); | |
1226 | return; | |
1227 | } | |
1228 | wpabuf_put_buf(msg, attr); | |
1229 | wpabuf_free(attr); | |
1230 | ||
1231 | offchannel_send_action(wpa_s, auth->curr_freq, | |
1232 | src, wpa_s->own_addr, broadcast, | |
1233 | wpabuf_head(msg), wpabuf_len(msg), | |
1234 | 500, wpas_dpp_tx_status, 0); | |
1235 | wpabuf_free(msg); | |
461d39af | 1236 | wpa_s->dpp_auth_ok_on_ack = 1; |
30d27b04 JM |
1237 | } |
1238 | ||
1239 | ||
1240 | static void wpas_dpp_rx_auth_conf(struct wpa_supplicant *wpa_s, const u8 *src, | |
1241 | const u8 *buf, size_t len) | |
1242 | { | |
1243 | struct dpp_authentication *auth = wpa_s->dpp_auth; | |
1244 | ||
1245 | wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR, | |
1246 | MAC2STR(src)); | |
1247 | ||
1248 | if (!auth) { | |
1249 | wpa_printf(MSG_DEBUG, | |
1250 | "DPP: No DPP Authentication in progress - drop"); | |
1251 | return; | |
1252 | } | |
1253 | ||
1254 | if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) { | |
1255 | wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected " | |
1256 | MACSTR ") - drop", MAC2STR(auth->peer_mac_addr)); | |
1257 | return; | |
1258 | } | |
1259 | ||
1260 | if (dpp_auth_conf_rx(auth, buf, len) < 0) { | |
1261 | wpa_printf(MSG_DEBUG, "DPP: Authentication failed"); | |
1262 | return; | |
1263 | } | |
1264 | ||
461d39af | 1265 | wpas_dpp_auth_success(wpa_s, 0); |
30d27b04 JM |
1266 | } |
1267 | ||
1268 | ||
a0d5c56f JM |
1269 | static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant *wpa_s, |
1270 | const u8 *src, | |
1271 | const u8 *buf, size_t len) | |
1272 | { | |
1273 | struct wpa_ssid *ssid; | |
85fd8263 JM |
1274 | const u8 *connector, *trans_id; |
1275 | u16 connector_len, trans_id_len; | |
a0d5c56f JM |
1276 | struct dpp_introduction intro; |
1277 | struct rsn_pmksa_cache_entry *entry; | |
787615b3 JM |
1278 | struct os_time now; |
1279 | struct os_reltime rnow; | |
1280 | os_time_t expiry; | |
1281 | unsigned int seconds; | |
a0d5c56f JM |
1282 | |
1283 | wpa_printf(MSG_DEBUG, "DPP: Peer Discovery Response from " MACSTR, | |
1284 | MAC2STR(src)); | |
1285 | if (is_zero_ether_addr(wpa_s->dpp_intro_bssid) || | |
1286 | os_memcmp(src, wpa_s->dpp_intro_bssid, ETH_ALEN) != 0) { | |
1287 | wpa_printf(MSG_DEBUG, "DPP: Not waiting for response from " | |
1288 | MACSTR " - drop", MAC2STR(src)); | |
1289 | return; | |
1290 | } | |
1291 | offchannel_send_action_done(wpa_s); | |
1292 | ||
1293 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { | |
1294 | if (ssid == wpa_s->dpp_intro_network) | |
1295 | break; | |
1296 | } | |
1297 | if (!ssid || !ssid->dpp_connector || !ssid->dpp_netaccesskey || | |
1298 | !ssid->dpp_csign) { | |
1299 | wpa_printf(MSG_DEBUG, | |
1300 | "DPP: Profile not found for network introduction"); | |
1301 | return; | |
1302 | } | |
1303 | ||
85fd8263 JM |
1304 | trans_id = dpp_get_attr(buf, len, DPP_ATTR_TRANSACTION_ID, |
1305 | &trans_id_len); | |
1306 | if (!trans_id || trans_id_len != 1) { | |
1307 | wpa_printf(MSG_DEBUG, | |
1308 | "DPP: Peer did not include Transaction ID"); | |
1309 | goto fail; | |
1310 | } | |
1311 | if (trans_id[0] != TRANSACTION_ID) { | |
1312 | wpa_printf(MSG_DEBUG, | |
1313 | "DPP: Ignore frame with unexpected Transaction ID %u", | |
1314 | trans_id[0]); | |
1315 | goto fail; | |
1316 | } | |
1317 | ||
a0d5c56f JM |
1318 | connector = dpp_get_attr(buf, len, DPP_ATTR_CONNECTOR, &connector_len); |
1319 | if (!connector) { | |
1320 | wpa_printf(MSG_DEBUG, | |
1321 | "DPP: Peer did not include its Connector"); | |
1322 | return; | |
1323 | } | |
1324 | ||
1325 | if (dpp_peer_intro(&intro, ssid->dpp_connector, | |
1326 | ssid->dpp_netaccesskey, | |
1327 | ssid->dpp_netaccesskey_len, | |
1328 | ssid->dpp_csign, | |
1329 | ssid->dpp_csign_len, | |
787615b3 | 1330 | connector, connector_len, &expiry) < 0) { |
a0d5c56f JM |
1331 | wpa_printf(MSG_INFO, |
1332 | "DPP: Network Introduction protocol resulted in failure"); | |
1333 | goto fail; | |
1334 | } | |
1335 | ||
a0d5c56f JM |
1336 | entry = os_zalloc(sizeof(*entry)); |
1337 | if (!entry) | |
1338 | goto fail; | |
1339 | os_memcpy(entry->aa, src, ETH_ALEN); | |
1340 | os_memcpy(entry->pmkid, intro.pmkid, PMKID_LEN); | |
1341 | os_memcpy(entry->pmk, intro.pmk, intro.pmk_len); | |
1342 | entry->pmk_len = intro.pmk_len; | |
1343 | entry->akmp = WPA_KEY_MGMT_DPP; | |
787615b3 JM |
1344 | if (expiry) { |
1345 | os_get_time(&now); | |
1346 | seconds = expiry - now.sec; | |
1347 | } else { | |
1348 | seconds = 86400 * 7; | |
1349 | } | |
1350 | os_get_reltime(&rnow); | |
1351 | entry->expiration = rnow.sec + seconds; | |
1352 | entry->reauth_time = rnow.sec + seconds; | |
a0d5c56f JM |
1353 | entry->network_ctx = ssid; |
1354 | wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry); | |
1355 | ||
1356 | wpa_printf(MSG_DEBUG, | |
1357 | "DPP: Try connection again after successful network introduction"); | |
1358 | if (wpa_supplicant_fast_associate(wpa_s) != 1) { | |
1359 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
1360 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
1361 | } | |
1362 | fail: | |
1363 | os_memset(&intro, 0, sizeof(intro)); | |
1364 | } | |
1365 | ||
1366 | ||
500ed7f0 JM |
1367 | static void |
1368 | wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s, | |
1369 | unsigned int freq, const u8 *dst, | |
1370 | const u8 *src, const u8 *bssid, | |
1371 | const u8 *data, size_t data_len, | |
1372 | enum offchannel_send_action_result result) | |
1373 | { | |
1374 | wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR | |
1375 | " result=%s (PKEX)", | |
1376 | freq, MAC2STR(dst), | |
1377 | result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" : | |
1378 | (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" : | |
1379 | "FAILED")); | |
1380 | /* TODO: Time out wait for response more quickly in error cases? */ | |
1381 | } | |
1382 | ||
1383 | ||
1384 | static void | |
1385 | wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant *wpa_s, const u8 *src, | |
1386 | const u8 *buf, size_t len, unsigned int freq) | |
1387 | { | |
1388 | struct wpabuf *msg; | |
1389 | unsigned int wait_time; | |
1390 | ||
1391 | wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Request from " MACSTR, | |
1392 | MAC2STR(src)); | |
1393 | ||
1394 | /* TODO: Support multiple PKEX codes by iterating over all the enabled | |
1395 | * values here */ | |
1396 | ||
1397 | if (!wpa_s->dpp_pkex_code || !wpa_s->dpp_pkex_bi) { | |
1398 | wpa_printf(MSG_DEBUG, | |
1399 | "DPP: No PKEX code configured - ignore request"); | |
1400 | return; | |
1401 | } | |
1402 | ||
1403 | if (wpa_s->dpp_pkex) { | |
1404 | /* TODO: Support parallel operations */ | |
1405 | wpa_printf(MSG_DEBUG, | |
1406 | "DPP: Already in PKEX session - ignore new request"); | |
1407 | return; | |
1408 | } | |
1409 | ||
1410 | wpa_s->dpp_pkex = dpp_pkex_rx_exchange_req(wpa_s->dpp_pkex_bi, | |
1411 | wpa_s->own_addr, src, | |
1412 | wpa_s->dpp_pkex_identifier, | |
1413 | wpa_s->dpp_pkex_code, | |
1414 | buf, len); | |
1415 | if (!wpa_s->dpp_pkex) { | |
1416 | wpa_printf(MSG_DEBUG, | |
1417 | "DPP: Failed to process the request - ignore it"); | |
1418 | return; | |
1419 | } | |
1420 | ||
1421 | msg = wpa_s->dpp_pkex->exchange_resp; | |
1422 | wait_time = wpa_s->max_remain_on_chan; | |
1423 | if (wait_time > 2000) | |
1424 | wait_time = 2000; | |
1425 | offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr, | |
1426 | broadcast, | |
1427 | wpabuf_head(msg), wpabuf_len(msg), | |
1428 | wait_time, wpas_dpp_tx_pkex_status, 0); | |
1429 | } | |
1430 | ||
1431 | ||
1432 | static void | |
1433 | wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant *wpa_s, const u8 *src, | |
1434 | const u8 *buf, size_t len, unsigned int freq) | |
1435 | { | |
1436 | struct wpabuf *msg; | |
1437 | unsigned int wait_time; | |
1438 | ||
1439 | wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Response from " MACSTR, | |
1440 | MAC2STR(src)); | |
1441 | ||
1442 | /* TODO: Support multiple PKEX codes by iterating over all the enabled | |
1443 | * values here */ | |
1444 | ||
1445 | if (!wpa_s->dpp_pkex || !wpa_s->dpp_pkex->initiator || | |
1446 | wpa_s->dpp_pkex->exchange_done) { | |
1447 | wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session"); | |
1448 | return; | |
1449 | } | |
1450 | ||
1451 | os_memcpy(wpa_s->dpp_pkex->peer_mac, src, ETH_ALEN); | |
1452 | msg = dpp_pkex_rx_exchange_resp(wpa_s->dpp_pkex, buf, len); | |
1453 | if (!msg) { | |
1454 | wpa_printf(MSG_DEBUG, "DPP: Failed to process the response"); | |
1455 | return; | |
1456 | } | |
1457 | ||
1458 | wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Request to " MACSTR, | |
1459 | MAC2STR(src)); | |
1460 | ||
1461 | wait_time = wpa_s->max_remain_on_chan; | |
1462 | if (wait_time > 2000) | |
1463 | wait_time = 2000; | |
1464 | offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr, | |
1465 | broadcast, | |
1466 | wpabuf_head(msg), wpabuf_len(msg), | |
1467 | wait_time, wpas_dpp_tx_pkex_status, 0); | |
1468 | wpabuf_free(msg); | |
1469 | } | |
1470 | ||
1471 | ||
1472 | static void | |
1473 | wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant *wpa_s, const u8 *src, | |
1474 | const u8 *buf, size_t len, unsigned int freq) | |
1475 | { | |
1476 | struct wpabuf *msg; | |
1477 | unsigned int wait_time; | |
1478 | struct dpp_pkex *pkex = wpa_s->dpp_pkex; | |
1479 | struct dpp_bootstrap_info *bi; | |
1480 | ||
1481 | wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Request from " MACSTR, | |
1482 | MAC2STR(src)); | |
1483 | ||
1484 | if (!pkex || pkex->initiator || !pkex->exchange_done) { | |
1485 | wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session"); | |
1486 | return; | |
1487 | } | |
1488 | ||
1489 | msg = dpp_pkex_rx_commit_reveal_req(pkex, buf, len); | |
1490 | if (!msg) { | |
1491 | wpa_printf(MSG_DEBUG, "DPP: Failed to process the request"); | |
1492 | return; | |
1493 | } | |
1494 | ||
1495 | wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Response to " | |
1496 | MACSTR, MAC2STR(src)); | |
1497 | ||
1498 | wait_time = wpa_s->max_remain_on_chan; | |
1499 | if (wait_time > 2000) | |
1500 | wait_time = 2000; | |
1501 | offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr, | |
1502 | broadcast, | |
1503 | wpabuf_head(msg), wpabuf_len(msg), | |
1504 | wait_time, wpas_dpp_tx_pkex_status, 0); | |
1505 | wpabuf_free(msg); | |
1506 | ||
1507 | bi = os_zalloc(sizeof(*bi)); | |
1508 | if (!bi) | |
1509 | return; | |
1510 | bi->id = wpas_dpp_next_id(wpa_s); | |
1511 | bi->type = DPP_BOOTSTRAP_PKEX; | |
1512 | os_memcpy(bi->mac_addr, src, ETH_ALEN); | |
1513 | bi->num_freq = 1; | |
1514 | bi->freq[0] = freq; | |
1515 | bi->curve = pkex->own_bi->curve; | |
1516 | bi->pubkey = pkex->peer_bootstrap_key; | |
1517 | pkex->peer_bootstrap_key = NULL; | |
1518 | dpp_pkex_free(pkex); | |
1519 | wpa_s->dpp_pkex = NULL; | |
1520 | if (dpp_bootstrap_key_hash(bi) < 0) { | |
1521 | dpp_bootstrap_info_free(bi); | |
1522 | return; | |
1523 | } | |
1524 | dl_list_add(&wpa_s->dpp_bootstrap, &bi->list); | |
1525 | } | |
1526 | ||
1527 | ||
1528 | static void | |
1529 | wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant *wpa_s, const u8 *src, | |
1530 | const u8 *buf, size_t len, | |
1531 | unsigned int freq) | |
1532 | { | |
1533 | int res; | |
1534 | struct dpp_bootstrap_info *bi, *own_bi; | |
1535 | struct dpp_pkex *pkex = wpa_s->dpp_pkex; | |
1536 | char cmd[500]; | |
1537 | ||
1538 | wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Response from " MACSTR, | |
1539 | MAC2STR(src)); | |
1540 | ||
1541 | if (!pkex || !pkex->initiator || !pkex->exchange_done) { | |
1542 | wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session"); | |
1543 | return; | |
1544 | } | |
1545 | ||
1546 | res = dpp_pkex_rx_commit_reveal_resp(pkex, buf, len); | |
1547 | if (res < 0) { | |
1548 | wpa_printf(MSG_DEBUG, "DPP: Failed to process the response"); | |
1549 | return; | |
1550 | } | |
1551 | ||
1552 | own_bi = pkex->own_bi; | |
1553 | ||
1554 | bi = os_zalloc(sizeof(*bi)); | |
1555 | if (!bi) | |
1556 | return; | |
1557 | bi->id = wpas_dpp_next_id(wpa_s); | |
1558 | bi->type = DPP_BOOTSTRAP_PKEX; | |
1559 | os_memcpy(bi->mac_addr, src, ETH_ALEN); | |
1560 | bi->num_freq = 1; | |
1561 | bi->freq[0] = freq; | |
1562 | bi->curve = own_bi->curve; | |
1563 | bi->pubkey = pkex->peer_bootstrap_key; | |
1564 | pkex->peer_bootstrap_key = NULL; | |
1565 | dpp_pkex_free(pkex); | |
1566 | wpa_s->dpp_pkex = NULL; | |
1567 | if (dpp_bootstrap_key_hash(bi) < 0) { | |
1568 | dpp_bootstrap_info_free(bi); | |
1569 | return; | |
1570 | } | |
1571 | dl_list_add(&wpa_s->dpp_bootstrap, &bi->list); | |
1572 | ||
1573 | os_snprintf(cmd, sizeof(cmd), " peer=%u %s", | |
1574 | bi->id, | |
1575 | wpa_s->dpp_pkex_auth_cmd ? wpa_s->dpp_pkex_auth_cmd : ""); | |
1576 | wpa_printf(MSG_DEBUG, | |
1577 | "DPP: Start authentication after PKEX with parameters: %s", | |
1578 | cmd); | |
1579 | if (wpas_dpp_auth_init(wpa_s, cmd) < 0) { | |
1580 | wpa_printf(MSG_DEBUG, | |
1581 | "DPP: Authentication initialization failed"); | |
1582 | return; | |
1583 | } | |
1584 | } | |
1585 | ||
1586 | ||
30d27b04 JM |
1587 | void wpas_dpp_rx_action(struct wpa_supplicant *wpa_s, const u8 *src, |
1588 | const u8 *buf, size_t len, unsigned int freq) | |
1589 | { | |
8c19ea3f | 1590 | u8 crypto_suite; |
30d27b04 JM |
1591 | enum dpp_public_action_frame_type type; |
1592 | ||
8c19ea3f | 1593 | if (len < 2) |
30d27b04 | 1594 | return; |
8c19ea3f JM |
1595 | crypto_suite = *buf++; |
1596 | type = *buf++; | |
1597 | len -= 2; | |
30d27b04 JM |
1598 | |
1599 | wpa_printf(MSG_DEBUG, | |
8c19ea3f | 1600 | "DPP: Received DPP Public Action frame crypto suite %u type %d from " |
30d27b04 | 1601 | MACSTR " freq=%u", |
8c19ea3f JM |
1602 | crypto_suite, type, MAC2STR(src), freq); |
1603 | if (crypto_suite != 1) { | |
1604 | wpa_printf(MSG_DEBUG, "DPP: Unsupported crypto suite %u", | |
1605 | crypto_suite); | |
1606 | return; | |
1607 | } | |
30d27b04 JM |
1608 | wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len); |
1609 | if (dpp_check_attrs(buf, len) < 0) | |
1610 | return; | |
1611 | ||
1612 | switch (type) { | |
1613 | case DPP_PA_AUTHENTICATION_REQ: | |
1614 | wpas_dpp_rx_auth_req(wpa_s, src, buf, len, freq); | |
1615 | break; | |
1616 | case DPP_PA_AUTHENTICATION_RESP: | |
1617 | wpas_dpp_rx_auth_resp(wpa_s, src, buf, len); | |
1618 | break; | |
1619 | case DPP_PA_AUTHENTICATION_CONF: | |
1620 | wpas_dpp_rx_auth_conf(wpa_s, src, buf, len); | |
1621 | break; | |
a0d5c56f JM |
1622 | case DPP_PA_PEER_DISCOVERY_RESP: |
1623 | wpas_dpp_rx_peer_disc_resp(wpa_s, src, buf, len); | |
1624 | break; | |
500ed7f0 JM |
1625 | case DPP_PA_PKEX_EXCHANGE_REQ: |
1626 | wpas_dpp_rx_pkex_exchange_req(wpa_s, src, buf, len, freq); | |
1627 | break; | |
1628 | case DPP_PA_PKEX_EXCHANGE_RESP: | |
1629 | wpas_dpp_rx_pkex_exchange_resp(wpa_s, src, buf, len, freq); | |
1630 | break; | |
1631 | case DPP_PA_PKEX_COMMIT_REVEAL_REQ: | |
1632 | wpas_dpp_rx_pkex_commit_reveal_req(wpa_s, src, buf, len, freq); | |
1633 | break; | |
1634 | case DPP_PA_PKEX_COMMIT_REVEAL_RESP: | |
1635 | wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s, src, buf, len, freq); | |
1636 | break; | |
30d27b04 JM |
1637 | default: |
1638 | wpa_printf(MSG_DEBUG, | |
1639 | "DPP: Ignored unsupported frame subtype %d", type); | |
1640 | break; | |
1641 | } | |
1642 | } | |
1643 | ||
1644 | ||
461d39af JM |
1645 | static struct wpabuf * |
1646 | wpas_dpp_gas_req_handler(void *ctx, const u8 *sa, const u8 *query, | |
1647 | size_t query_len) | |
1648 | { | |
1649 | struct wpa_supplicant *wpa_s = ctx; | |
1650 | struct dpp_authentication *auth = wpa_s->dpp_auth; | |
1651 | struct wpabuf *resp; | |
1652 | ||
1653 | wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR, | |
1654 | MAC2STR(sa)); | |
1655 | if (!auth || !auth->auth_success || | |
1656 | os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) { | |
1657 | wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress"); | |
1658 | return NULL; | |
1659 | } | |
1660 | wpa_hexdump(MSG_DEBUG, | |
1661 | "DPP: Received Configuration Request (GAS Query Request)", | |
1662 | query, query_len); | |
1663 | resp = dpp_conf_req_rx(auth, query, query_len); | |
1664 | if (!resp) | |
1665 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED); | |
1666 | return resp; | |
1667 | } | |
1668 | ||
1669 | ||
1670 | static void | |
1671 | wpas_dpp_gas_status_handler(void *ctx, struct wpabuf *resp, int ok) | |
1672 | { | |
1673 | struct wpa_supplicant *wpa_s = ctx; | |
1674 | struct dpp_authentication *auth = wpa_s->dpp_auth; | |
1675 | ||
1676 | if (!auth) { | |
1677 | wpabuf_free(resp); | |
1678 | return; | |
1679 | } | |
1680 | ||
1681 | wpa_printf(MSG_DEBUG, "DPP: Configuration exchange completed (ok=%d)", | |
1682 | ok); | |
1683 | eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL); | |
1684 | offchannel_send_action_done(wpa_s); | |
1685 | wpas_dpp_listen_stop(wpa_s); | |
1686 | if (ok) | |
1687 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT); | |
1688 | else | |
1689 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED); | |
1690 | dpp_auth_deinit(wpa_s->dpp_auth); | |
1691 | wpa_s->dpp_auth = NULL; | |
1692 | wpabuf_free(resp); | |
1693 | } | |
1694 | ||
1695 | ||
1696 | static unsigned int wpas_dpp_next_configurator_id(struct wpa_supplicant *wpa_s) | |
1697 | { | |
1698 | struct dpp_configurator *conf; | |
1699 | unsigned int max_id = 0; | |
1700 | ||
1701 | dl_list_for_each(conf, &wpa_s->dpp_configurator, | |
1702 | struct dpp_configurator, list) { | |
1703 | if (conf->id > max_id) | |
1704 | max_id = conf->id; | |
1705 | } | |
1706 | return max_id + 1; | |
1707 | } | |
1708 | ||
1709 | ||
1710 | int wpas_dpp_configurator_add(struct wpa_supplicant *wpa_s, const char *cmd) | |
1711 | { | |
c77e2ff0 | 1712 | char *curve = NULL; |
461d39af JM |
1713 | char *key = NULL; |
1714 | u8 *privkey = NULL; | |
1715 | size_t privkey_len = 0; | |
1716 | int ret = -1; | |
1717 | struct dpp_configurator *conf = NULL; | |
1718 | ||
461d39af JM |
1719 | curve = get_param(cmd, " curve="); |
1720 | key = get_param(cmd, " key="); | |
1721 | ||
1722 | if (key) { | |
1723 | privkey_len = os_strlen(key) / 2; | |
1724 | privkey = os_malloc(privkey_len); | |
1725 | if (!privkey || | |
1726 | hexstr2bin(key, privkey, privkey_len) < 0) | |
1727 | goto fail; | |
1728 | } | |
1729 | ||
1730 | conf = dpp_keygen_configurator(curve, privkey, privkey_len); | |
1731 | if (!conf) | |
1732 | goto fail; | |
1733 | ||
461d39af JM |
1734 | conf->id = wpas_dpp_next_configurator_id(wpa_s); |
1735 | dl_list_add(&wpa_s->dpp_configurator, &conf->list); | |
1736 | ret = conf->id; | |
1737 | conf = NULL; | |
1738 | fail: | |
1739 | os_free(curve); | |
461d39af JM |
1740 | str_clear_free(key); |
1741 | bin_clear_free(privkey, privkey_len); | |
1742 | dpp_configurator_free(conf); | |
1743 | return ret; | |
1744 | } | |
1745 | ||
1746 | ||
1747 | static int dpp_configurator_del(struct wpa_supplicant *wpa_s, unsigned int id) | |
1748 | { | |
1749 | struct dpp_configurator *conf, *tmp; | |
1750 | int found = 0; | |
1751 | ||
1752 | dl_list_for_each_safe(conf, tmp, &wpa_s->dpp_configurator, | |
1753 | struct dpp_configurator, list) { | |
1754 | if (id && conf->id != id) | |
1755 | continue; | |
1756 | found = 1; | |
1757 | dl_list_del(&conf->list); | |
1758 | dpp_configurator_free(conf); | |
1759 | } | |
1760 | ||
1761 | if (id == 0) | |
1762 | return 0; /* flush succeeds regardless of entries found */ | |
1763 | return found ? 0 : -1; | |
1764 | } | |
1765 | ||
1766 | ||
1767 | int wpas_dpp_configurator_remove(struct wpa_supplicant *wpa_s, const char *id) | |
1768 | { | |
1769 | unsigned int id_val; | |
1770 | ||
1771 | if (os_strcmp(id, "*") == 0) { | |
1772 | id_val = 0; | |
1773 | } else { | |
1774 | id_val = atoi(id); | |
1775 | if (id_val == 0) | |
1776 | return -1; | |
1777 | } | |
1778 | ||
1779 | return dpp_configurator_del(wpa_s, id_val); | |
1780 | } | |
1781 | ||
1782 | ||
f522bb23 JM |
1783 | int wpas_dpp_configurator_sign(struct wpa_supplicant *wpa_s, const char *cmd) |
1784 | { | |
1785 | struct dpp_authentication *auth; | |
1786 | int ret = -1; | |
1787 | char *curve = NULL; | |
1788 | ||
1789 | auth = os_zalloc(sizeof(*auth)); | |
1790 | if (!auth) | |
1791 | return -1; | |
1792 | ||
1793 | curve = get_param(cmd, " curve="); | |
1794 | wpas_dpp_set_configurator(wpa_s, auth, cmd); | |
1795 | ||
1796 | if (dpp_configurator_own_config(auth, curve) == 0) { | |
1797 | wpas_dpp_handle_config_obj(wpa_s, auth); | |
1798 | ret = 0; | |
1799 | } | |
1800 | ||
1801 | dpp_auth_deinit(auth); | |
1802 | os_free(curve); | |
1803 | ||
1804 | return ret; | |
1805 | } | |
1806 | ||
1807 | ||
a0d5c56f JM |
1808 | static void |
1809 | wpas_dpp_tx_introduction_status(struct wpa_supplicant *wpa_s, | |
1810 | unsigned int freq, const u8 *dst, | |
1811 | const u8 *src, const u8 *bssid, | |
1812 | const u8 *data, size_t data_len, | |
1813 | enum offchannel_send_action_result result) | |
1814 | { | |
1815 | wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR | |
1816 | " result=%s (DPP Peer Discovery Request)", | |
1817 | freq, MAC2STR(dst), | |
1818 | result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" : | |
1819 | (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" : | |
1820 | "FAILED")); | |
1821 | /* TODO: Time out wait for response more quickly in error cases? */ | |
1822 | } | |
1823 | ||
1824 | ||
1825 | int wpas_dpp_check_connect(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, | |
1826 | struct wpa_bss *bss) | |
1827 | { | |
1828 | struct os_time now; | |
1829 | struct wpabuf *msg; | |
1830 | unsigned int wait_time; | |
1831 | ||
1832 | if (!(ssid->key_mgmt & WPA_KEY_MGMT_DPP) || !bss) | |
1833 | return 0; /* Not using DPP AKM - continue */ | |
1834 | if (wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid)) | |
1835 | return 0; /* PMKSA exists for DPP AKM - continue */ | |
1836 | ||
1837 | if (!ssid->dpp_connector || !ssid->dpp_netaccesskey || | |
1838 | !ssid->dpp_csign) { | |
1839 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR | |
1840 | "missing %s", | |
1841 | !ssid->dpp_connector ? "Connector" : | |
1842 | (!ssid->dpp_netaccesskey ? "netAccessKey" : | |
1843 | "C-sign-key")); | |
1844 | return -1; | |
1845 | } | |
1846 | ||
1847 | os_get_time(&now); | |
1848 | ||
a0d5c56f JM |
1849 | if (ssid->dpp_netaccesskey_expiry && |
1850 | ssid->dpp_netaccesskey_expiry < now.sec) { | |
1851 | wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR | |
1852 | "netAccessKey expired"); | |
1853 | return -1; | |
1854 | } | |
1855 | ||
1856 | wpa_printf(MSG_DEBUG, | |
1857 | "DPP: Starting network introduction protocol to derive PMKSA for " | |
1858 | MACSTR, MAC2STR(bss->bssid)); | |
1859 | ||
1860 | msg = dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ, | |
85fd8263 | 1861 | 5 + 4 + os_strlen(ssid->dpp_connector)); |
a0d5c56f JM |
1862 | if (!msg) |
1863 | return -1; | |
1864 | ||
85fd8263 JM |
1865 | /* Transaction ID */ |
1866 | wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID); | |
1867 | wpabuf_put_le16(msg, 1); | |
1868 | wpabuf_put_u8(msg, TRANSACTION_ID); | |
1869 | ||
a0d5c56f JM |
1870 | /* DPP Connector */ |
1871 | wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR); | |
1872 | wpabuf_put_le16(msg, os_strlen(ssid->dpp_connector)); | |
1873 | wpabuf_put_str(msg, ssid->dpp_connector); | |
1874 | ||
1875 | /* TODO: Timeout on AP response */ | |
1876 | wait_time = wpa_s->max_remain_on_chan; | |
1877 | if (wait_time > 2000) | |
1878 | wait_time = 2000; | |
1879 | offchannel_send_action(wpa_s, bss->freq, bss->bssid, wpa_s->own_addr, | |
1880 | broadcast, | |
1881 | wpabuf_head(msg), wpabuf_len(msg), | |
1882 | wait_time, wpas_dpp_tx_introduction_status, 0); | |
1883 | wpabuf_free(msg); | |
1884 | ||
1885 | /* Request this connection attempt to terminate - new one will be | |
1886 | * started when network introduction protocol completes */ | |
1887 | os_memcpy(wpa_s->dpp_intro_bssid, bss->bssid, ETH_ALEN); | |
1888 | wpa_s->dpp_intro_network = ssid; | |
1889 | return 1; | |
1890 | } | |
1891 | ||
1892 | ||
500ed7f0 JM |
1893 | int wpas_dpp_pkex_add(struct wpa_supplicant *wpa_s, const char *cmd) |
1894 | { | |
1895 | struct dpp_bootstrap_info *own_bi; | |
1896 | const char *pos, *end; | |
1897 | unsigned int wait_time; | |
1898 | ||
1899 | pos = os_strstr(cmd, " own="); | |
1900 | if (!pos) | |
1901 | return -1; | |
1902 | pos += 5; | |
1903 | own_bi = dpp_bootstrap_get_id(wpa_s, atoi(pos)); | |
1904 | if (!own_bi) { | |
1905 | wpa_printf(MSG_DEBUG, | |
1906 | "DPP: Identified bootstrap info not found"); | |
1907 | return -1; | |
1908 | } | |
1909 | if (own_bi->type != DPP_BOOTSTRAP_PKEX) { | |
1910 | wpa_printf(MSG_DEBUG, | |
1911 | "DPP: Identified bootstrap info not for PKEX"); | |
1912 | return -1; | |
1913 | } | |
1914 | wpa_s->dpp_pkex_bi = own_bi; | |
1915 | ||
1916 | os_free(wpa_s->dpp_pkex_identifier); | |
1917 | wpa_s->dpp_pkex_identifier = NULL; | |
1918 | pos = os_strstr(cmd, " identifier="); | |
1919 | if (pos) { | |
1920 | pos += 12; | |
1921 | end = os_strchr(pos, ' '); | |
1922 | if (!end) | |
1923 | return -1; | |
1924 | wpa_s->dpp_pkex_identifier = os_malloc(end - pos + 1); | |
1925 | if (!wpa_s->dpp_pkex_identifier) | |
1926 | return -1; | |
1927 | os_memcpy(wpa_s->dpp_pkex_identifier, pos, end - pos); | |
1928 | wpa_s->dpp_pkex_identifier[end - pos] = '\0'; | |
1929 | } | |
1930 | ||
1931 | pos = os_strstr(cmd, " code="); | |
1932 | if (!pos) | |
1933 | return -1; | |
1934 | os_free(wpa_s->dpp_pkex_code); | |
1935 | wpa_s->dpp_pkex_code = os_strdup(pos + 6); | |
1936 | if (!wpa_s->dpp_pkex_code) | |
1937 | return -1; | |
1938 | ||
1939 | if (os_strstr(cmd, " init=1")) { | |
1940 | struct wpabuf *msg; | |
1941 | ||
1942 | wpa_printf(MSG_DEBUG, "DPP: Initiating PKEX"); | |
1943 | dpp_pkex_free(wpa_s->dpp_pkex); | |
1944 | wpa_s->dpp_pkex = dpp_pkex_init(own_bi, wpa_s->own_addr, | |
1945 | wpa_s->dpp_pkex_identifier, | |
1946 | wpa_s->dpp_pkex_code); | |
1947 | if (!wpa_s->dpp_pkex) | |
1948 | return -1; | |
1949 | ||
1950 | msg = wpa_s->dpp_pkex->exchange_req; | |
1951 | wait_time = wpa_s->max_remain_on_chan; | |
1952 | if (wait_time > 2000) | |
1953 | wait_time = 2000; | |
1954 | /* TODO: Which channel to use? */ | |
1955 | offchannel_send_action(wpa_s, 2437, broadcast, wpa_s->own_addr, | |
1956 | broadcast, | |
1957 | wpabuf_head(msg), wpabuf_len(msg), | |
1958 | wait_time, wpas_dpp_tx_pkex_status, 0); | |
1959 | } | |
1960 | ||
1961 | /* TODO: Support multiple PKEX info entries */ | |
1962 | ||
1963 | os_free(wpa_s->dpp_pkex_auth_cmd); | |
1964 | wpa_s->dpp_pkex_auth_cmd = os_strdup(cmd); | |
1965 | ||
1966 | return 1; | |
1967 | } | |
1968 | ||
1969 | ||
1970 | int wpas_dpp_pkex_remove(struct wpa_supplicant *wpa_s, const char *id) | |
1971 | { | |
1972 | unsigned int id_val; | |
1973 | ||
1974 | if (os_strcmp(id, "*") == 0) { | |
1975 | id_val = 0; | |
1976 | } else { | |
1977 | id_val = atoi(id); | |
1978 | if (id_val == 0) | |
1979 | return -1; | |
1980 | } | |
1981 | ||
1982 | if ((id_val != 0 && id_val != 1) || !wpa_s->dpp_pkex_code) | |
1983 | return -1; | |
1984 | ||
1985 | /* TODO: Support multiple PKEX entries */ | |
1986 | os_free(wpa_s->dpp_pkex_code); | |
1987 | wpa_s->dpp_pkex_code = NULL; | |
1988 | os_free(wpa_s->dpp_pkex_identifier); | |
1989 | wpa_s->dpp_pkex_identifier = NULL; | |
1990 | os_free(wpa_s->dpp_pkex_auth_cmd); | |
1991 | wpa_s->dpp_pkex_auth_cmd = NULL; | |
1992 | wpa_s->dpp_pkex_bi = NULL; | |
1993 | /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */ | |
1994 | dpp_pkex_free(wpa_s->dpp_pkex); | |
1995 | wpa_s->dpp_pkex = NULL; | |
1996 | return 0; | |
1997 | } | |
1998 | ||
1999 | ||
be27e185 JM |
2000 | int wpas_dpp_init(struct wpa_supplicant *wpa_s) |
2001 | { | |
461d39af JM |
2002 | u8 adv_proto_id[7]; |
2003 | ||
2004 | adv_proto_id[0] = WLAN_EID_VENDOR_SPECIFIC; | |
2005 | adv_proto_id[1] = 5; | |
2006 | WPA_PUT_BE24(&adv_proto_id[2], OUI_WFA); | |
2007 | adv_proto_id[5] = DPP_OUI_TYPE; | |
2008 | adv_proto_id[6] = 0x01; | |
2009 | ||
2010 | if (gas_server_register(wpa_s->gas_server, adv_proto_id, | |
2011 | sizeof(adv_proto_id), wpas_dpp_gas_req_handler, | |
2012 | wpas_dpp_gas_status_handler, wpa_s) < 0) | |
2013 | return -1; | |
be27e185 | 2014 | dl_list_init(&wpa_s->dpp_bootstrap); |
461d39af | 2015 | dl_list_init(&wpa_s->dpp_configurator); |
be27e185 JM |
2016 | wpa_s->dpp_init_done = 1; |
2017 | return 0; | |
2018 | } | |
2019 | ||
2020 | ||
2021 | void wpas_dpp_deinit(struct wpa_supplicant *wpa_s) | |
2022 | { | |
461d39af JM |
2023 | #ifdef CONFIG_TESTING_OPTIONS |
2024 | os_free(wpa_s->dpp_config_obj_override); | |
2025 | wpa_s->dpp_config_obj_override = NULL; | |
2026 | os_free(wpa_s->dpp_discovery_override); | |
2027 | wpa_s->dpp_discovery_override = NULL; | |
2028 | os_free(wpa_s->dpp_groups_override); | |
2029 | wpa_s->dpp_groups_override = NULL; | |
461d39af JM |
2030 | wpa_s->dpp_ignore_netaccesskey_mismatch = 0; |
2031 | #endif /* CONFIG_TESTING_OPTIONS */ | |
be27e185 JM |
2032 | if (!wpa_s->dpp_init_done) |
2033 | return; | |
30d27b04 JM |
2034 | eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL); |
2035 | offchannel_send_action_done(wpa_s); | |
2036 | wpas_dpp_listen_stop(wpa_s); | |
be27e185 | 2037 | dpp_bootstrap_del(wpa_s, 0); |
461d39af | 2038 | dpp_configurator_del(wpa_s, 0); |
30d27b04 JM |
2039 | dpp_auth_deinit(wpa_s->dpp_auth); |
2040 | wpa_s->dpp_auth = NULL; | |
500ed7f0 JM |
2041 | wpas_dpp_pkex_remove(wpa_s, "*"); |
2042 | wpa_s->dpp_pkex = NULL; | |
a0d5c56f | 2043 | os_memset(wpa_s->dpp_intro_bssid, 0, ETH_ALEN); |
b65b22d6 JM |
2044 | os_free(wpa_s->dpp_configurator_params); |
2045 | wpa_s->dpp_configurator_params = NULL; | |
be27e185 | 2046 | } |