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