blob: 085d42325b8a2348c1910ad08a663cbb5d415a4e [file] [log] [blame]
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001/*
2 * hostapd / DPP integration
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"
12#include "utils/eloop.h"
13#include "common/dpp.h"
14#include "common/gas.h"
15#include "common/wpa_ctrl.h"
16#include "hostapd.h"
17#include "ap_drv_ops.h"
18#include "gas_query_ap.h"
Hai Shalom81f62d82019-07-22 12:10:00 -070019#include "gas_serv.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070020#include "wpa_auth.h"
21#include "dpp_hostapd.h"
22
23
Roshan Pius3a1667e2018-07-03 15:17:14 -070024static void hostapd_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070025static void hostapd_dpp_auth_success(struct hostapd_data *hapd, int initiator);
Roshan Pius3a1667e2018-07-03 15:17:14 -070026static void hostapd_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx);
27static int hostapd_dpp_auth_init_next(struct hostapd_data *hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070028
29static const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
30
31
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070032/**
33 * hostapd_dpp_qr_code - Parse and add DPP bootstrapping info from a QR Code
34 * @hapd: Pointer to hostapd_data
35 * @cmd: DPP URI read from a QR Code
36 * Returns: Identifier of the stored info or -1 on failure
37 */
38int hostapd_dpp_qr_code(struct hostapd_data *hapd, const char *cmd)
39{
40 struct dpp_bootstrap_info *bi;
41 struct dpp_authentication *auth = hapd->dpp_auth;
42
Hai Shalom021b0b52019-04-10 11:17:58 -070043 bi = dpp_add_qr_code(hapd->iface->interfaces->dpp, cmd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070044 if (!bi)
45 return -1;
46
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070047 if (auth && auth->response_pending &&
48 dpp_notify_new_qr_code(auth, bi) == 1) {
49 wpa_printf(MSG_DEBUG,
50 "DPP: Sending out pending authentication response");
Roshan Pius3a1667e2018-07-03 15:17:14 -070051 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
52 " freq=%u type=%d",
53 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
54 DPP_PA_AUTHENTICATION_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070055 hostapd_drv_send_action(hapd, auth->curr_freq, 0,
56 auth->peer_mac_addr,
57 wpabuf_head(hapd->dpp_auth->resp_msg),
58 wpabuf_len(hapd->dpp_auth->resp_msg));
59 }
60
61 return bi->id;
62}
63
64
Roshan Pius3a1667e2018-07-03 15:17:14 -070065static void hostapd_dpp_auth_resp_retry_timeout(void *eloop_ctx,
66 void *timeout_ctx)
67{
68 struct hostapd_data *hapd = eloop_ctx;
69 struct dpp_authentication *auth = hapd->dpp_auth;
70
71 if (!auth || !auth->resp_msg)
72 return;
73
74 wpa_printf(MSG_DEBUG,
75 "DPP: Retry Authentication Response after timeout");
76 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
77 " freq=%u type=%d",
78 MAC2STR(auth->peer_mac_addr), auth->curr_freq,
79 DPP_PA_AUTHENTICATION_RESP);
80 hostapd_drv_send_action(hapd, auth->curr_freq, 500, auth->peer_mac_addr,
81 wpabuf_head(auth->resp_msg),
82 wpabuf_len(auth->resp_msg));
83}
84
85
86static void hostapd_dpp_auth_resp_retry(struct hostapd_data *hapd)
87{
88 struct dpp_authentication *auth = hapd->dpp_auth;
89 unsigned int wait_time, max_tries;
90
91 if (!auth || !auth->resp_msg)
92 return;
93
94 if (hapd->dpp_resp_max_tries)
95 max_tries = hapd->dpp_resp_max_tries;
96 else
97 max_tries = 5;
98 auth->auth_resp_tries++;
99 if (auth->auth_resp_tries >= max_tries) {
100 wpa_printf(MSG_INFO,
101 "DPP: No confirm received from initiator - stopping exchange");
102 hostapd_drv_send_action_cancel_wait(hapd);
103 dpp_auth_deinit(hapd->dpp_auth);
104 hapd->dpp_auth = NULL;
105 return;
106 }
107
108 if (hapd->dpp_resp_retry_time)
109 wait_time = hapd->dpp_resp_retry_time;
110 else
111 wait_time = 1000;
112 wpa_printf(MSG_DEBUG,
113 "DPP: Schedule retransmission of Authentication Response frame in %u ms",
114 wait_time);
115 eloop_cancel_timeout(hostapd_dpp_auth_resp_retry_timeout, hapd, NULL);
116 eloop_register_timeout(wait_time / 1000,
117 (wait_time % 1000) * 1000,
118 hostapd_dpp_auth_resp_retry_timeout, hapd, NULL);
119}
120
121
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700122void hostapd_dpp_tx_status(struct hostapd_data *hapd, const u8 *dst,
123 const u8 *data, size_t data_len, int ok)
124{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700125 struct dpp_authentication *auth = hapd->dpp_auth;
126
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700127 wpa_printf(MSG_DEBUG, "DPP: TX status: dst=" MACSTR " ok=%d",
128 MAC2STR(dst), ok);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700129 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
130 " result=%s", MAC2STR(dst), ok ? "SUCCESS" : "FAILED");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700131
132 if (!hapd->dpp_auth) {
133 wpa_printf(MSG_DEBUG,
134 "DPP: Ignore TX status since there is no ongoing authentication exchange");
135 return;
136 }
137
Hai Shalom021b0b52019-04-10 11:17:58 -0700138#ifdef CONFIG_DPP2
139 if (auth->connect_on_tx_status) {
140 wpa_printf(MSG_DEBUG,
141 "DPP: Complete exchange on configuration result");
142 dpp_auth_deinit(hapd->dpp_auth);
143 hapd->dpp_auth = NULL;
144 return;
145 }
146#endif /* CONFIG_DPP2 */
147
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700148 if (hapd->dpp_auth->remove_on_tx_status) {
149 wpa_printf(MSG_DEBUG,
150 "DPP: Terminate authentication exchange due to an earlier error");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700151 eloop_cancel_timeout(hostapd_dpp_init_timeout, hapd, NULL);
152 eloop_cancel_timeout(hostapd_dpp_reply_wait_timeout,
153 hapd, NULL);
154 eloop_cancel_timeout(hostapd_dpp_auth_resp_retry_timeout, hapd,
155 NULL);
156 hostapd_drv_send_action_cancel_wait(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700157 dpp_auth_deinit(hapd->dpp_auth);
158 hapd->dpp_auth = NULL;
159 return;
160 }
161
162 if (hapd->dpp_auth_ok_on_ack)
163 hostapd_dpp_auth_success(hapd, 1);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700164
165 if (!is_broadcast_ether_addr(dst) && !ok) {
166 wpa_printf(MSG_DEBUG,
167 "DPP: Unicast DPP Action frame was not ACKed");
168 if (auth->waiting_auth_resp) {
169 /* In case of DPP Authentication Request frame, move to
170 * the next channel immediately. */
171 hostapd_drv_send_action_cancel_wait(hapd);
172 hostapd_dpp_auth_init_next(hapd);
173 return;
174 }
175 if (auth->waiting_auth_conf) {
176 hostapd_dpp_auth_resp_retry(hapd);
177 return;
178 }
179 }
180
181 if (!is_broadcast_ether_addr(dst) && auth->waiting_auth_resp && ok) {
182 /* Allow timeout handling to stop iteration if no response is
183 * received from a peer that has ACKed a request. */
184 auth->auth_req_ack = 1;
185 }
186
187 if (!hapd->dpp_auth_ok_on_ack && hapd->dpp_auth->neg_freq > 0 &&
188 hapd->dpp_auth->curr_freq != hapd->dpp_auth->neg_freq) {
189 wpa_printf(MSG_DEBUG,
190 "DPP: Move from curr_freq %u MHz to neg_freq %u MHz for response",
191 hapd->dpp_auth->curr_freq,
192 hapd->dpp_auth->neg_freq);
193 hostapd_drv_send_action_cancel_wait(hapd);
194
195 if (hapd->dpp_auth->neg_freq !=
196 (unsigned int) hapd->iface->freq && hapd->iface->freq > 0) {
197 /* TODO: Listen operation on non-operating channel */
198 wpa_printf(MSG_INFO,
199 "DPP: Listen operation on non-operating channel (%d MHz) is not yet supported (operating channel: %d MHz)",
200 hapd->dpp_auth->neg_freq, hapd->iface->freq);
201 }
202 }
203
204 if (hapd->dpp_auth_ok_on_ack)
205 hapd->dpp_auth_ok_on_ack = 0;
206}
207
208
209static void hostapd_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx)
210{
211 struct hostapd_data *hapd = eloop_ctx;
212 struct dpp_authentication *auth = hapd->dpp_auth;
213 unsigned int freq;
214 struct os_reltime now, diff;
215 unsigned int wait_time, diff_ms;
216
217 if (!auth || !auth->waiting_auth_resp)
218 return;
219
220 wait_time = hapd->dpp_resp_wait_time ?
221 hapd->dpp_resp_wait_time : 2000;
222 os_get_reltime(&now);
223 os_reltime_sub(&now, &hapd->dpp_last_init, &diff);
224 diff_ms = diff.sec * 1000 + diff.usec / 1000;
225 wpa_printf(MSG_DEBUG,
226 "DPP: Reply wait timeout - wait_time=%u diff_ms=%u",
227 wait_time, diff_ms);
228
229 if (auth->auth_req_ack && diff_ms >= wait_time) {
230 /* Peer ACK'ed Authentication Request frame, but did not reply
231 * with Authentication Response frame within two seconds. */
232 wpa_printf(MSG_INFO,
233 "DPP: No response received from responder - stopping initiation attempt");
234 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
235 hostapd_drv_send_action_cancel_wait(hapd);
236 hostapd_dpp_listen_stop(hapd);
237 dpp_auth_deinit(auth);
238 hapd->dpp_auth = NULL;
239 return;
240 }
241
242 if (diff_ms >= wait_time) {
243 /* Authentication Request frame was not ACK'ed and no reply
244 * was receiving within two seconds. */
245 wpa_printf(MSG_DEBUG,
246 "DPP: Continue Initiator channel iteration");
247 hostapd_drv_send_action_cancel_wait(hapd);
248 hostapd_dpp_listen_stop(hapd);
249 hostapd_dpp_auth_init_next(hapd);
250 return;
251 }
252
253 /* Driver did not support 2000 ms long wait_time with TX command, so
254 * schedule listen operation to continue waiting for the response.
255 *
256 * DPP listen operations continue until stopped, so simply schedule a
257 * new call to this function at the point when the two second reply
258 * wait has expired. */
259 wait_time -= diff_ms;
260
261 freq = auth->curr_freq;
262 if (auth->neg_freq > 0)
263 freq = auth->neg_freq;
264 wpa_printf(MSG_DEBUG,
265 "DPP: Continue reply wait on channel %u MHz for %u ms",
266 freq, wait_time);
267 hapd->dpp_in_response_listen = 1;
268
269 if (freq != (unsigned int) hapd->iface->freq && hapd->iface->freq > 0) {
270 /* TODO: Listen operation on non-operating channel */
271 wpa_printf(MSG_INFO,
272 "DPP: Listen operation on non-operating channel (%d MHz) is not yet supported (operating channel: %d MHz)",
273 freq, hapd->iface->freq);
274 }
275
276 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
277 hostapd_dpp_reply_wait_timeout, hapd, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700278}
279
280
281static void hostapd_dpp_set_testing_options(struct hostapd_data *hapd,
282 struct dpp_authentication *auth)
283{
284#ifdef CONFIG_TESTING_OPTIONS
285 if (hapd->dpp_config_obj_override)
286 auth->config_obj_override =
287 os_strdup(hapd->dpp_config_obj_override);
288 if (hapd->dpp_discovery_override)
289 auth->discovery_override =
290 os_strdup(hapd->dpp_discovery_override);
291 if (hapd->dpp_groups_override)
292 auth->groups_override = os_strdup(hapd->dpp_groups_override);
293 auth->ignore_netaccesskey_mismatch =
294 hapd->dpp_ignore_netaccesskey_mismatch;
295#endif /* CONFIG_TESTING_OPTIONS */
296}
297
298
Roshan Pius3a1667e2018-07-03 15:17:14 -0700299static void hostapd_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx)
300{
301 struct hostapd_data *hapd = eloop_ctx;
302
303 if (!hapd->dpp_auth)
304 return;
305 wpa_printf(MSG_DEBUG, "DPP: Retry initiation after timeout");
306 hostapd_dpp_auth_init_next(hapd);
307}
308
309
310static int hostapd_dpp_auth_init_next(struct hostapd_data *hapd)
311{
312 struct dpp_authentication *auth = hapd->dpp_auth;
313 const u8 *dst;
314 unsigned int wait_time, max_wait_time, freq, max_tries, used;
315 struct os_reltime now, diff;
316
317 if (!auth)
318 return -1;
319
320 if (auth->freq_idx == 0)
321 os_get_reltime(&hapd->dpp_init_iter_start);
322
323 if (auth->freq_idx >= auth->num_freq) {
324 auth->num_freq_iters++;
325 if (hapd->dpp_init_max_tries)
326 max_tries = hapd->dpp_init_max_tries;
327 else
328 max_tries = 5;
329 if (auth->num_freq_iters >= max_tries || auth->auth_req_ack) {
330 wpa_printf(MSG_INFO,
331 "DPP: No response received from responder - stopping initiation attempt");
332 wpa_msg(hapd->msg_ctx, MSG_INFO,
333 DPP_EVENT_AUTH_INIT_FAILED);
334 eloop_cancel_timeout(hostapd_dpp_reply_wait_timeout,
335 hapd, NULL);
336 hostapd_drv_send_action_cancel_wait(hapd);
337 dpp_auth_deinit(hapd->dpp_auth);
338 hapd->dpp_auth = NULL;
339 return -1;
340 }
341 auth->freq_idx = 0;
342 eloop_cancel_timeout(hostapd_dpp_init_timeout, hapd, NULL);
343 if (hapd->dpp_init_retry_time)
344 wait_time = hapd->dpp_init_retry_time;
345 else
346 wait_time = 10000;
347 os_get_reltime(&now);
348 os_reltime_sub(&now, &hapd->dpp_init_iter_start, &diff);
349 used = diff.sec * 1000 + diff.usec / 1000;
350 if (used > wait_time)
351 wait_time = 0;
352 else
353 wait_time -= used;
354 wpa_printf(MSG_DEBUG, "DPP: Next init attempt in %u ms",
355 wait_time);
356 eloop_register_timeout(wait_time / 1000,
357 (wait_time % 1000) * 1000,
358 hostapd_dpp_init_timeout, hapd,
359 NULL);
360 return 0;
361 }
362 freq = auth->freq[auth->freq_idx++];
363 auth->curr_freq = freq;
364
365 if (is_zero_ether_addr(auth->peer_bi->mac_addr))
366 dst = broadcast;
367 else
368 dst = auth->peer_bi->mac_addr;
369 hapd->dpp_auth_ok_on_ack = 0;
370 eloop_cancel_timeout(hostapd_dpp_reply_wait_timeout, hapd, NULL);
371 wait_time = 2000; /* TODO: hapd->max_remain_on_chan; */
372 max_wait_time = hapd->dpp_resp_wait_time ?
373 hapd->dpp_resp_wait_time : 2000;
374 if (wait_time > max_wait_time)
375 wait_time = max_wait_time;
376 wait_time += 10; /* give the driver some extra time to complete */
377 eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
378 hostapd_dpp_reply_wait_timeout, hapd, NULL);
379 wait_time -= 10;
380 if (auth->neg_freq > 0 && freq != auth->neg_freq) {
381 wpa_printf(MSG_DEBUG,
382 "DPP: Initiate on %u MHz and move to neg_freq %u MHz for response",
383 freq, auth->neg_freq);
384 }
385 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
386 " freq=%u type=%d",
387 MAC2STR(dst), freq, DPP_PA_AUTHENTICATION_REQ);
388 auth->auth_req_ack = 0;
389 os_get_reltime(&hapd->dpp_last_init);
390 return hostapd_drv_send_action(hapd, freq, wait_time,
391 dst,
392 wpabuf_head(hapd->dpp_auth->req_msg),
393 wpabuf_len(hapd->dpp_auth->req_msg));
394}
395
396
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700397int hostapd_dpp_auth_init(struct hostapd_data *hapd, const char *cmd)
398{
399 const char *pos;
400 struct dpp_bootstrap_info *peer_bi, *own_bi = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700401 u8 allowed_roles = DPP_CAPAB_CONFIGURATOR;
402 unsigned int neg_freq = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700403
404 pos = os_strstr(cmd, " peer=");
405 if (!pos)
406 return -1;
407 pos += 6;
Hai Shalom021b0b52019-04-10 11:17:58 -0700408 peer_bi = dpp_bootstrap_get_id(hapd->iface->interfaces->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700409 if (!peer_bi) {
410 wpa_printf(MSG_INFO,
411 "DPP: Could not find bootstrapping info for the identified peer");
412 return -1;
413 }
414
415 pos = os_strstr(cmd, " own=");
416 if (pos) {
417 pos += 5;
Hai Shalom021b0b52019-04-10 11:17:58 -0700418 own_bi = dpp_bootstrap_get_id(hapd->iface->interfaces->dpp,
419 atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700420 if (!own_bi) {
421 wpa_printf(MSG_INFO,
422 "DPP: Could not find bootstrapping info for the identified local entry");
423 return -1;
424 }
425
426 if (peer_bi->curve != own_bi->curve) {
427 wpa_printf(MSG_INFO,
428 "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
429 peer_bi->curve->name, own_bi->curve->name);
430 return -1;
431 }
432 }
433
434 pos = os_strstr(cmd, " role=");
435 if (pos) {
436 pos += 6;
437 if (os_strncmp(pos, "configurator", 12) == 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700438 allowed_roles = DPP_CAPAB_CONFIGURATOR;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700439 else if (os_strncmp(pos, "enrollee", 8) == 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700440 allowed_roles = DPP_CAPAB_ENROLLEE;
441 else if (os_strncmp(pos, "either", 6) == 0)
442 allowed_roles = DPP_CAPAB_CONFIGURATOR |
443 DPP_CAPAB_ENROLLEE;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700444 else
445 goto fail;
446 }
447
Roshan Pius3a1667e2018-07-03 15:17:14 -0700448 pos = os_strstr(cmd, " neg_freq=");
449 if (pos)
450 neg_freq = atoi(pos + 10);
451
452 if (hapd->dpp_auth) {
453 eloop_cancel_timeout(hostapd_dpp_init_timeout, hapd, NULL);
454 eloop_cancel_timeout(hostapd_dpp_reply_wait_timeout,
455 hapd, NULL);
456 eloop_cancel_timeout(hostapd_dpp_auth_resp_retry_timeout, hapd,
457 NULL);
458 hostapd_drv_send_action_cancel_wait(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700459 dpp_auth_deinit(hapd->dpp_auth);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700460 }
461
462 hapd->dpp_auth = dpp_auth_init(hapd->msg_ctx, peer_bi, own_bi,
463 allowed_roles, neg_freq,
464 hapd->iface->hw_features,
465 hapd->iface->num_hw_features);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700466 if (!hapd->dpp_auth)
467 goto fail;
468 hostapd_dpp_set_testing_options(hapd, hapd->dpp_auth);
Hai Shalom021b0b52019-04-10 11:17:58 -0700469 if (dpp_set_configurator(hapd->iface->interfaces->dpp, hapd->msg_ctx,
470 hapd->dpp_auth, cmd) < 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -0800471 dpp_auth_deinit(hapd->dpp_auth);
472 hapd->dpp_auth = NULL;
473 goto fail;
474 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700475
Roshan Pius3a1667e2018-07-03 15:17:14 -0700476 hapd->dpp_auth->neg_freq = neg_freq;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700477
Roshan Pius3a1667e2018-07-03 15:17:14 -0700478 if (!is_zero_ether_addr(peer_bi->mac_addr))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700479 os_memcpy(hapd->dpp_auth->peer_mac_addr, peer_bi->mac_addr,
480 ETH_ALEN);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700481
Roshan Pius3a1667e2018-07-03 15:17:14 -0700482 return hostapd_dpp_auth_init_next(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700483fail:
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700484 return -1;
485}
486
487
Roshan Pius3a1667e2018-07-03 15:17:14 -0700488int hostapd_dpp_listen(struct hostapd_data *hapd, const char *cmd)
489{
490 int freq;
491
492 freq = atoi(cmd);
493 if (freq <= 0)
494 return -1;
495
496 if (os_strstr(cmd, " role=configurator"))
497 hapd->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR;
498 else if (os_strstr(cmd, " role=enrollee"))
499 hapd->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
500 else
501 hapd->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
502 DPP_CAPAB_ENROLLEE;
503 hapd->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
504
505 if (freq != hapd->iface->freq && hapd->iface->freq > 0) {
506 /* TODO: Listen operation on non-operating channel */
507 wpa_printf(MSG_INFO,
508 "DPP: Listen operation on non-operating channel (%d MHz) is not yet supported (operating channel: %d MHz)",
509 freq, hapd->iface->freq);
510 return -1;
511 }
512
513 return 0;
514}
515
516
517void hostapd_dpp_listen_stop(struct hostapd_data *hapd)
518{
519 /* TODO: Stop listen operation on non-operating channel */
520}
521
522
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700523static void hostapd_dpp_rx_auth_req(struct hostapd_data *hapd, const u8 *src,
524 const u8 *hdr, const u8 *buf, size_t len,
525 unsigned int freq)
526{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700527 const u8 *r_bootstrap, *i_bootstrap;
528 u16 r_bootstrap_len, i_bootstrap_len;
Hai Shalom021b0b52019-04-10 11:17:58 -0700529 struct dpp_bootstrap_info *own_bi = NULL, *peer_bi = NULL;
530
531 if (!hapd->iface->interfaces->dpp)
532 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700533
534 wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR,
535 MAC2STR(src));
536
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700537 r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
538 &r_bootstrap_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700539 if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
540 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_FAIL
541 "Missing or invalid required Responder Bootstrapping Key Hash attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700542 return;
543 }
544 wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
545 r_bootstrap, r_bootstrap_len);
546
547 i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH,
548 &i_bootstrap_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700549 if (!i_bootstrap || i_bootstrap_len != SHA256_MAC_LEN) {
550 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_FAIL
551 "Missing or invalid required Initiator Bootstrapping Key Hash attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700552 return;
553 }
554 wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash",
555 i_bootstrap, i_bootstrap_len);
556
557 /* Try to find own and peer bootstrapping key matches based on the
558 * received hash values */
Hai Shalom021b0b52019-04-10 11:17:58 -0700559 dpp_bootstrap_find_pair(hapd->iface->interfaces->dpp, i_bootstrap,
560 r_bootstrap, &own_bi, &peer_bi);
Hai Shalom81f62d82019-07-22 12:10:00 -0700561#ifdef CONFIG_DPP2
562 if (!own_bi) {
563 if (dpp_relay_rx_action(hapd->iface->interfaces->dpp,
564 src, hdr, buf, len, freq, i_bootstrap,
565 r_bootstrap) == 0)
566 return;
567 }
568#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700569 if (!own_bi) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700570 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_FAIL
571 "No matching own bootstrapping key found - ignore message");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700572 return;
573 }
574
575 if (hapd->dpp_auth) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700576 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_FAIL
577 "Already in DPP authentication exchange - ignore new one");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700578 return;
579 }
580
581 hapd->dpp_auth_ok_on_ack = 0;
582 hapd->dpp_auth = dpp_auth_req_rx(hapd->msg_ctx, hapd->dpp_allowed_roles,
583 hapd->dpp_qr_mutual,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700584 peer_bi, own_bi, freq, hdr, buf, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700585 if (!hapd->dpp_auth) {
586 wpa_printf(MSG_DEBUG, "DPP: No response generated");
587 return;
588 }
589 hostapd_dpp_set_testing_options(hapd, hapd->dpp_auth);
Hai Shalom021b0b52019-04-10 11:17:58 -0700590 if (dpp_set_configurator(hapd->iface->interfaces->dpp, hapd->msg_ctx,
591 hapd->dpp_auth,
592 hapd->dpp_configurator_params) < 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -0800593 dpp_auth_deinit(hapd->dpp_auth);
594 hapd->dpp_auth = NULL;
595 return;
596 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700597 os_memcpy(hapd->dpp_auth->peer_mac_addr, src, ETH_ALEN);
598
Roshan Pius3a1667e2018-07-03 15:17:14 -0700599 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
600 " freq=%u type=%d",
601 MAC2STR(src), hapd->dpp_auth->curr_freq,
602 DPP_PA_AUTHENTICATION_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700603 hostapd_drv_send_action(hapd, hapd->dpp_auth->curr_freq, 0,
604 src, wpabuf_head(hapd->dpp_auth->resp_msg),
605 wpabuf_len(hapd->dpp_auth->resp_msg));
606}
607
608
Roshan Pius3a1667e2018-07-03 15:17:14 -0700609static void hostapd_dpp_handle_config_obj(struct hostapd_data *hapd,
Hai Shalomc3565922019-10-28 11:58:20 -0700610 struct dpp_authentication *auth,
611 struct dpp_config_obj *conf)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700612{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700613 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700614 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONFOBJ_AKM "%s",
Hai Shalomc3565922019-10-28 11:58:20 -0700615 dpp_akm_str(conf->akm));
616 if (conf->ssid_len)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700617 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s",
Hai Shalomc3565922019-10-28 11:58:20 -0700618 wpa_ssid_txt(conf->ssid, conf->ssid_len));
619 if (conf->connector) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700620 /* TODO: Save the Connector and consider using a command
621 * to fetch the value instead of sending an event with
622 * it. The Connector could end up being larger than what
623 * most clients are ready to receive as an event
624 * message. */
625 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONNECTOR "%s",
Hai Shalomc3565922019-10-28 11:58:20 -0700626 conf->connector);
627 } else if (conf->passphrase[0]) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700628 char hex[64 * 2 + 1];
629
630 wpa_snprintf_hex(hex, sizeof(hex),
Hai Shalomc3565922019-10-28 11:58:20 -0700631 (const u8 *) conf->passphrase,
632 os_strlen(conf->passphrase));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700633 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONFOBJ_PASS "%s",
634 hex);
Hai Shalomc3565922019-10-28 11:58:20 -0700635 } else if (conf->psk_set) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700636 char hex[PMK_LEN * 2 + 1];
637
Hai Shalomc3565922019-10-28 11:58:20 -0700638 wpa_snprintf_hex(hex, sizeof(hex), conf->psk, PMK_LEN);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700639 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONFOBJ_PSK "%s",
640 hex);
641 }
Hai Shalomc3565922019-10-28 11:58:20 -0700642 if (conf->c_sign_key) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700643 char *hex;
644 size_t hexlen;
645
Hai Shalomc3565922019-10-28 11:58:20 -0700646 hexlen = 2 * wpabuf_len(conf->c_sign_key) + 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700647 hex = os_malloc(hexlen);
648 if (hex) {
649 wpa_snprintf_hex(hex, hexlen,
Hai Shalomc3565922019-10-28 11:58:20 -0700650 wpabuf_head(conf->c_sign_key),
651 wpabuf_len(conf->c_sign_key));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700652 wpa_msg(hapd->msg_ctx, MSG_INFO,
653 DPP_EVENT_C_SIGN_KEY "%s", hex);
654 os_free(hex);
655 }
656 }
657 if (auth->net_access_key) {
658 char *hex;
659 size_t hexlen;
660
661 hexlen = 2 * wpabuf_len(auth->net_access_key) + 1;
662 hex = os_malloc(hexlen);
663 if (hex) {
664 wpa_snprintf_hex(hex, hexlen,
665 wpabuf_head(auth->net_access_key),
666 wpabuf_len(auth->net_access_key));
667 if (auth->net_access_key_expiry)
668 wpa_msg(hapd->msg_ctx, MSG_INFO,
669 DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex,
670 (unsigned long)
671 auth->net_access_key_expiry);
672 else
673 wpa_msg(hapd->msg_ctx, MSG_INFO,
674 DPP_EVENT_NET_ACCESS_KEY "%s", hex);
675 os_free(hex);
676 }
677 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700678}
679
680
681static void hostapd_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token,
682 enum gas_query_ap_result result,
683 const struct wpabuf *adv_proto,
684 const struct wpabuf *resp, u16 status_code)
685{
686 struct hostapd_data *hapd = ctx;
687 const u8 *pos;
688 struct dpp_authentication *auth = hapd->dpp_auth;
Hai Shalom021b0b52019-04-10 11:17:58 -0700689 enum dpp_status_error status = DPP_STATUS_CONFIG_REJECTED;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700690
691 if (!auth || !auth->auth_success) {
692 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
693 return;
694 }
695 if (!resp || status_code != WLAN_STATUS_SUCCESS) {
696 wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed");
697 goto fail;
698 }
699
700 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto",
701 adv_proto);
702 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)",
703 resp);
704
705 if (wpabuf_len(adv_proto) != 10 ||
706 !(pos = wpabuf_head(adv_proto)) ||
707 pos[0] != WLAN_EID_ADV_PROTO ||
708 pos[1] != 8 ||
709 pos[3] != WLAN_EID_VENDOR_SPECIFIC ||
710 pos[4] != 5 ||
711 WPA_GET_BE24(&pos[5]) != OUI_WFA ||
712 pos[8] != 0x1a ||
713 pos[9] != 1) {
714 wpa_printf(MSG_DEBUG,
715 "DPP: Not a DPP Advertisement Protocol ID");
716 goto fail;
717 }
718
719 if (dpp_conf_resp_rx(auth, resp) < 0) {
720 wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed");
721 goto fail;
722 }
723
Hai Shalomc3565922019-10-28 11:58:20 -0700724 hostapd_dpp_handle_config_obj(hapd, auth, &auth->conf_obj[0]);
Hai Shalom021b0b52019-04-10 11:17:58 -0700725 status = DPP_STATUS_OK;
726#ifdef CONFIG_TESTING_OPTIONS
727 if (dpp_test == DPP_TEST_REJECT_CONFIG) {
728 wpa_printf(MSG_INFO, "DPP: TESTING - Reject Config Object");
729 status = DPP_STATUS_CONFIG_REJECTED;
730 }
731#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700732fail:
Hai Shalom021b0b52019-04-10 11:17:58 -0700733 if (status != DPP_STATUS_OK)
734 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONF_FAILED);
735#ifdef CONFIG_DPP2
736 if (auth->peer_version >= 2 &&
737 auth->conf_resp_status == DPP_STATUS_OK) {
738 struct wpabuf *msg;
739
740 wpa_printf(MSG_DEBUG, "DPP: Send DPP Configuration Result");
741 msg = dpp_build_conf_result(auth, status);
742 if (!msg)
743 goto fail2;
744
745 wpa_msg(hapd->msg_ctx, MSG_INFO,
746 DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
747 MAC2STR(addr), auth->curr_freq,
748 DPP_PA_CONFIGURATION_RESULT);
749 hostapd_drv_send_action(hapd, auth->curr_freq, 0,
750 addr, wpabuf_head(msg),
751 wpabuf_len(msg));
752 wpabuf_free(msg);
753
754 /* This exchange will be terminated in the TX status handler */
755 auth->connect_on_tx_status = 1;
756 return;
757 }
758fail2:
759#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700760 dpp_auth_deinit(hapd->dpp_auth);
761 hapd->dpp_auth = NULL;
762}
763
764
765static void hostapd_dpp_start_gas_client(struct hostapd_data *hapd)
766{
767 struct dpp_authentication *auth = hapd->dpp_auth;
Hai Shalom021b0b52019-04-10 11:17:58 -0700768 struct wpabuf *buf;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700769 int res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700770
Hai Shalomc3565922019-10-28 11:58:20 -0700771 buf = dpp_build_conf_req_helper(auth, hapd->conf->dpp_name, 1,
772 hapd->conf->dpp_mud_url, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -0700773 if (!buf) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700774 wpa_printf(MSG_DEBUG,
775 "DPP: No configuration request data available");
776 return;
777 }
778
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700779 wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
780 MAC2STR(auth->peer_mac_addr), auth->curr_freq);
781
782 res = gas_query_ap_req(hapd->gas, auth->peer_mac_addr, auth->curr_freq,
783 buf, hostapd_dpp_gas_resp_cb, hapd);
784 if (res < 0) {
785 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
786 "GAS: Failed to send Query Request");
787 wpabuf_free(buf);
788 } else {
789 wpa_printf(MSG_DEBUG,
790 "DPP: GAS query started with dialog token %u", res);
791 }
792}
793
794
795static void hostapd_dpp_auth_success(struct hostapd_data *hapd, int initiator)
796{
797 wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded");
798 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d",
799 initiator);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700800#ifdef CONFIG_TESTING_OPTIONS
801 if (dpp_test == DPP_TEST_STOP_AT_AUTH_CONF) {
802 wpa_printf(MSG_INFO,
803 "DPP: TESTING - stop at Authentication Confirm");
804 if (hapd->dpp_auth->configurator) {
805 /* Prevent GAS response */
806 hapd->dpp_auth->auth_success = 0;
807 }
808 return;
809 }
810#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700811
812 if (!hapd->dpp_auth->configurator)
813 hostapd_dpp_start_gas_client(hapd);
814}
815
816
817static void hostapd_dpp_rx_auth_resp(struct hostapd_data *hapd, const u8 *src,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700818 const u8 *hdr, const u8 *buf, size_t len,
819 unsigned int freq)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700820{
821 struct dpp_authentication *auth = hapd->dpp_auth;
822 struct wpabuf *msg;
823
824 wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR,
825 MAC2STR(src));
826
827 if (!auth) {
828 wpa_printf(MSG_DEBUG,
829 "DPP: No DPP Authentication in progress - drop");
830 return;
831 }
832
833 if (!is_zero_ether_addr(auth->peer_mac_addr) &&
834 os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
835 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
836 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
837 return;
838 }
839
Roshan Pius3a1667e2018-07-03 15:17:14 -0700840 eloop_cancel_timeout(hostapd_dpp_reply_wait_timeout, hapd, NULL);
841
842 if (auth->curr_freq != freq && auth->neg_freq == freq) {
843 wpa_printf(MSG_DEBUG,
844 "DPP: Responder accepted request for different negotiation channel");
845 auth->curr_freq = freq;
846 }
847
848 eloop_cancel_timeout(hostapd_dpp_init_timeout, hapd, NULL);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700849 msg = dpp_auth_resp_rx(auth, hdr, buf, len);
850 if (!msg) {
851 if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) {
852 wpa_printf(MSG_DEBUG, "DPP: Wait for full response");
853 return;
854 }
855 wpa_printf(MSG_DEBUG, "DPP: No confirm generated");
856 return;
857 }
858 os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
859
Roshan Pius3a1667e2018-07-03 15:17:14 -0700860 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
861 " freq=%u type=%d", MAC2STR(src), auth->curr_freq,
862 DPP_PA_AUTHENTICATION_CONF);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700863 hostapd_drv_send_action(hapd, auth->curr_freq, 0, src,
864 wpabuf_head(msg), wpabuf_len(msg));
865 wpabuf_free(msg);
866 hapd->dpp_auth_ok_on_ack = 1;
867}
868
869
870static void hostapd_dpp_rx_auth_conf(struct hostapd_data *hapd, const u8 *src,
871 const u8 *hdr, const u8 *buf, size_t len)
872{
873 struct dpp_authentication *auth = hapd->dpp_auth;
874
875 wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR,
876 MAC2STR(src));
877
878 if (!auth) {
879 wpa_printf(MSG_DEBUG,
880 "DPP: No DPP Authentication in progress - drop");
881 return;
882 }
883
884 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
885 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
886 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
887 return;
888 }
889
890 if (dpp_auth_conf_rx(auth, hdr, buf, len) < 0) {
891 wpa_printf(MSG_DEBUG, "DPP: Authentication failed");
892 return;
893 }
894
895 hostapd_dpp_auth_success(hapd, 0);
896}
897
898
Hai Shalom021b0b52019-04-10 11:17:58 -0700899#ifdef CONFIG_DPP2
900
901static void hostapd_dpp_config_result_wait_timeout(void *eloop_ctx,
902 void *timeout_ctx)
903{
904 struct hostapd_data *hapd = eloop_ctx;
905 struct dpp_authentication *auth = hapd->dpp_auth;
906
907 if (!auth || !auth->waiting_conf_result)
908 return;
909
910 wpa_printf(MSG_DEBUG,
911 "DPP: Timeout while waiting for Configuration Result");
912 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONF_FAILED);
913 dpp_auth_deinit(auth);
914 hapd->dpp_auth = NULL;
915}
916
917
Hai Shalomc3565922019-10-28 11:58:20 -0700918static void hostapd_dpp_conn_status_result_wait_timeout(void *eloop_ctx,
919 void *timeout_ctx)
920{
921 struct hostapd_data *hapd = eloop_ctx;
922 struct dpp_authentication *auth = hapd->dpp_auth;
923
924 if (!auth || !auth->waiting_conf_result)
925 return;
926
927 wpa_printf(MSG_DEBUG,
928 "DPP: Timeout while waiting for Connection Status Result");
929 wpa_msg(hapd->msg_ctx, MSG_INFO,
930 DPP_EVENT_CONN_STATUS_RESULT "timeout");
931 dpp_auth_deinit(auth);
932 hapd->dpp_auth = NULL;
933}
934
935
Hai Shalom021b0b52019-04-10 11:17:58 -0700936static void hostapd_dpp_rx_conf_result(struct hostapd_data *hapd, const u8 *src,
937 const u8 *hdr, const u8 *buf, size_t len)
938{
939 struct dpp_authentication *auth = hapd->dpp_auth;
940 enum dpp_status_error status;
941
942 wpa_printf(MSG_DEBUG, "DPP: Configuration Result from " MACSTR,
943 MAC2STR(src));
944
945 if (!auth || !auth->waiting_conf_result) {
946 wpa_printf(MSG_DEBUG,
947 "DPP: No DPP Configuration waiting for result - drop");
948 return;
949 }
950
951 if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
952 wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
953 MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
954 return;
955 }
956
957 status = dpp_conf_result_rx(auth, hdr, buf, len);
958
Hai Shalomc3565922019-10-28 11:58:20 -0700959 if (status == DPP_STATUS_OK && auth->send_conn_status) {
960 wpa_msg(hapd->msg_ctx, MSG_INFO,
961 DPP_EVENT_CONF_SENT "wait_conn_status=1");
962 wpa_printf(MSG_DEBUG, "DPP: Wait for Connection Status Result");
963 eloop_cancel_timeout(hostapd_dpp_config_result_wait_timeout,
964 hapd, NULL);
965 eloop_cancel_timeout(
966 hostapd_dpp_conn_status_result_wait_timeout,
967 hapd, NULL);
968 eloop_register_timeout(
969 16, 0, hostapd_dpp_conn_status_result_wait_timeout,
970 hapd, NULL);
971 return;
972 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700973 hostapd_drv_send_action_cancel_wait(hapd);
974 hostapd_dpp_listen_stop(hapd);
975 if (status == DPP_STATUS_OK)
976 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONF_SENT);
977 else
978 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONF_FAILED);
979 dpp_auth_deinit(auth);
980 hapd->dpp_auth = NULL;
981 eloop_cancel_timeout(hostapd_dpp_config_result_wait_timeout, hapd,
982 NULL);
983}
984
Hai Shalomc3565922019-10-28 11:58:20 -0700985
986static void hostapd_dpp_rx_conn_status_result(struct hostapd_data *hapd,
987 const u8 *src, const u8 *hdr,
988 const u8 *buf, size_t len)
989{
990 struct dpp_authentication *auth = hapd->dpp_auth;
991 enum dpp_status_error status;
992 u8 ssid[SSID_MAX_LEN];
993 size_t ssid_len = 0;
994 char *channel_list = NULL;
995
996 wpa_printf(MSG_DEBUG, "DPP: Connection Status Result");
997
998 if (!auth || !auth->waiting_conn_status_result) {
999 wpa_printf(MSG_DEBUG,
1000 "DPP: No DPP Configuration waiting for connection status result - drop");
1001 return;
1002 }
1003
1004 status = dpp_conn_status_result_rx(auth, hdr, buf, len,
1005 ssid, &ssid_len, &channel_list);
1006 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONN_STATUS_RESULT
1007 "result=%d ssid=%s channel_list=%s",
1008 status, wpa_ssid_txt(ssid, ssid_len),
1009 channel_list ? channel_list : "N/A");
1010 os_free(channel_list);
1011 hostapd_drv_send_action_cancel_wait(hapd);
1012 hostapd_dpp_listen_stop(hapd);
1013 dpp_auth_deinit(auth);
1014 hapd->dpp_auth = NULL;
1015 eloop_cancel_timeout(hostapd_dpp_conn_status_result_wait_timeout,
1016 hapd, NULL);
1017}
1018
1019
Hai Shalom021b0b52019-04-10 11:17:58 -07001020#endif /* CONFIG_DPP2 */
1021
1022
Roshan Pius3a1667e2018-07-03 15:17:14 -07001023static void hostapd_dpp_send_peer_disc_resp(struct hostapd_data *hapd,
1024 const u8 *src, unsigned int freq,
1025 u8 trans_id,
1026 enum dpp_status_error status)
1027{
1028 struct wpabuf *msg;
1029
1030 msg = dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_RESP,
1031 5 + 5 + 4 + os_strlen(hapd->conf->dpp_connector));
1032 if (!msg)
1033 return;
1034
1035#ifdef CONFIG_TESTING_OPTIONS
1036 if (dpp_test == DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_RESP) {
1037 wpa_printf(MSG_INFO, "DPP: TESTING - no Transaction ID");
1038 goto skip_trans_id;
1039 }
1040 if (dpp_test == DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_RESP) {
1041 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Transaction ID");
1042 trans_id ^= 0x01;
1043 }
1044#endif /* CONFIG_TESTING_OPTIONS */
1045
1046 /* Transaction ID */
1047 wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
1048 wpabuf_put_le16(msg, 1);
1049 wpabuf_put_u8(msg, trans_id);
1050
1051#ifdef CONFIG_TESTING_OPTIONS
1052skip_trans_id:
1053 if (dpp_test == DPP_TEST_NO_STATUS_PEER_DISC_RESP) {
1054 wpa_printf(MSG_INFO, "DPP: TESTING - no Status");
1055 goto skip_status;
1056 }
1057 if (dpp_test == DPP_TEST_INVALID_STATUS_PEER_DISC_RESP) {
1058 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Status");
1059 status = 254;
1060 }
1061#endif /* CONFIG_TESTING_OPTIONS */
1062
1063 /* DPP Status */
1064 wpabuf_put_le16(msg, DPP_ATTR_STATUS);
1065 wpabuf_put_le16(msg, 1);
1066 wpabuf_put_u8(msg, status);
1067
1068#ifdef CONFIG_TESTING_OPTIONS
1069skip_status:
1070 if (dpp_test == DPP_TEST_NO_CONNECTOR_PEER_DISC_RESP) {
1071 wpa_printf(MSG_INFO, "DPP: TESTING - no Connector");
1072 goto skip_connector;
1073 }
1074 if (status == DPP_STATUS_OK &&
1075 dpp_test == DPP_TEST_INVALID_CONNECTOR_PEER_DISC_RESP) {
1076 char *connector;
1077
1078 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Connector");
1079 connector = dpp_corrupt_connector_signature(
1080 hapd->conf->dpp_connector);
1081 if (!connector) {
1082 wpabuf_free(msg);
1083 return;
1084 }
1085 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
1086 wpabuf_put_le16(msg, os_strlen(connector));
1087 wpabuf_put_str(msg, connector);
1088 os_free(connector);
1089 goto skip_connector;
1090 }
1091#endif /* CONFIG_TESTING_OPTIONS */
1092
1093 /* DPP Connector */
1094 if (status == DPP_STATUS_OK) {
1095 wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
1096 wpabuf_put_le16(msg, os_strlen(hapd->conf->dpp_connector));
1097 wpabuf_put_str(msg, hapd->conf->dpp_connector);
1098 }
1099
1100#ifdef CONFIG_TESTING_OPTIONS
1101skip_connector:
1102#endif /* CONFIG_TESTING_OPTIONS */
1103
1104 wpa_printf(MSG_DEBUG, "DPP: Send Peer Discovery Response to " MACSTR
1105 " status=%d", MAC2STR(src), status);
1106 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
1107 " freq=%u type=%d status=%d", MAC2STR(src), freq,
1108 DPP_PA_PEER_DISCOVERY_RESP, status);
1109 hostapd_drv_send_action(hapd, freq, 0, src,
1110 wpabuf_head(msg), wpabuf_len(msg));
1111 wpabuf_free(msg);
1112}
1113
1114
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001115static void hostapd_dpp_rx_peer_disc_req(struct hostapd_data *hapd,
1116 const u8 *src,
1117 const u8 *buf, size_t len,
1118 unsigned int freq)
1119{
1120 const u8 *connector, *trans_id;
1121 u16 connector_len, trans_id_len;
1122 struct os_time now;
1123 struct dpp_introduction intro;
1124 os_time_t expire;
1125 int expiration;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001126 enum dpp_status_error res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001127
1128 wpa_printf(MSG_DEBUG, "DPP: Peer Discovery Request from " MACSTR,
1129 MAC2STR(src));
1130 if (!hapd->wpa_auth ||
1131 !(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) ||
1132 !(hapd->conf->wpa & WPA_PROTO_RSN)) {
1133 wpa_printf(MSG_DEBUG, "DPP: DPP AKM not in use");
1134 return;
1135 }
1136
1137 if (!hapd->conf->dpp_connector || !hapd->conf->dpp_netaccesskey ||
1138 !hapd->conf->dpp_csign) {
1139 wpa_printf(MSG_DEBUG, "DPP: No own Connector/keys set");
1140 return;
1141 }
1142
1143 os_get_time(&now);
1144
1145 if (hapd->conf->dpp_netaccesskey_expiry &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07001146 (os_time_t) hapd->conf->dpp_netaccesskey_expiry < now.sec) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001147 wpa_printf(MSG_INFO, "DPP: Own netAccessKey expired");
1148 return;
1149 }
1150
1151 trans_id = dpp_get_attr(buf, len, DPP_ATTR_TRANSACTION_ID,
1152 &trans_id_len);
1153 if (!trans_id || trans_id_len != 1) {
1154 wpa_printf(MSG_DEBUG,
1155 "DPP: Peer did not include Transaction ID");
1156 return;
1157 }
1158
1159 connector = dpp_get_attr(buf, len, DPP_ATTR_CONNECTOR, &connector_len);
1160 if (!connector) {
1161 wpa_printf(MSG_DEBUG,
1162 "DPP: Peer did not include its Connector");
1163 return;
1164 }
1165
Roshan Pius3a1667e2018-07-03 15:17:14 -07001166 res = dpp_peer_intro(&intro, hapd->conf->dpp_connector,
1167 wpabuf_head(hapd->conf->dpp_netaccesskey),
1168 wpabuf_len(hapd->conf->dpp_netaccesskey),
1169 wpabuf_head(hapd->conf->dpp_csign),
1170 wpabuf_len(hapd->conf->dpp_csign),
1171 connector, connector_len, &expire);
1172 if (res == 255) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001173 wpa_printf(MSG_INFO,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001174 "DPP: Network Introduction protocol resulted in internal failure (peer "
1175 MACSTR ")", MAC2STR(src));
1176 return;
1177 }
1178 if (res != DPP_STATUS_OK) {
1179 wpa_printf(MSG_INFO,
1180 "DPP: Network Introduction protocol resulted in failure (peer "
1181 MACSTR " status %d)", MAC2STR(src), res);
1182 hostapd_dpp_send_peer_disc_resp(hapd, src, freq, trans_id[0],
1183 res);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001184 return;
1185 }
1186
Roshan Pius3a1667e2018-07-03 15:17:14 -07001187 if (!expire || (os_time_t) hapd->conf->dpp_netaccesskey_expiry < expire)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001188 expire = hapd->conf->dpp_netaccesskey_expiry;
1189 if (expire)
1190 expiration = expire - now.sec;
1191 else
1192 expiration = 0;
1193
1194 if (wpa_auth_pmksa_add2(hapd->wpa_auth, src, intro.pmk, intro.pmk_len,
1195 intro.pmkid, expiration,
1196 WPA_KEY_MGMT_DPP) < 0) {
1197 wpa_printf(MSG_ERROR, "DPP: Failed to add PMKSA cache entry");
1198 return;
1199 }
1200
Roshan Pius3a1667e2018-07-03 15:17:14 -07001201 hostapd_dpp_send_peer_disc_resp(hapd, src, freq, trans_id[0],
1202 DPP_STATUS_OK);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001203}
1204
1205
1206static void
1207hostapd_dpp_rx_pkex_exchange_req(struct hostapd_data *hapd, const u8 *src,
1208 const u8 *buf, size_t len,
1209 unsigned int freq)
1210{
1211 struct wpabuf *msg;
1212
1213 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Request from " MACSTR,
1214 MAC2STR(src));
1215
1216 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1217 * values here */
1218
1219 if (!hapd->dpp_pkex_code || !hapd->dpp_pkex_bi) {
1220 wpa_printf(MSG_DEBUG,
1221 "DPP: No PKEX code configured - ignore request");
1222 return;
1223 }
1224
1225 if (hapd->dpp_pkex) {
1226 /* TODO: Support parallel operations */
1227 wpa_printf(MSG_DEBUG,
1228 "DPP: Already in PKEX session - ignore new request");
1229 return;
1230 }
1231
Roshan Pius3a1667e2018-07-03 15:17:14 -07001232 hapd->dpp_pkex = dpp_pkex_rx_exchange_req(hapd->msg_ctx,
1233 hapd->dpp_pkex_bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001234 hapd->own_addr, src,
1235 hapd->dpp_pkex_identifier,
1236 hapd->dpp_pkex_code,
1237 buf, len);
1238 if (!hapd->dpp_pkex) {
1239 wpa_printf(MSG_DEBUG,
1240 "DPP: Failed to process the request - ignore it");
1241 return;
1242 }
1243
1244 msg = hapd->dpp_pkex->exchange_resp;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001245 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
1246 " freq=%u type=%d", MAC2STR(src), freq,
1247 DPP_PA_PKEX_EXCHANGE_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001248 hostapd_drv_send_action(hapd, freq, 0, src,
1249 wpabuf_head(msg), wpabuf_len(msg));
Roshan Pius3a1667e2018-07-03 15:17:14 -07001250 if (hapd->dpp_pkex->failed) {
1251 wpa_printf(MSG_DEBUG,
1252 "DPP: Terminate PKEX exchange due to an earlier error");
1253 if (hapd->dpp_pkex->t > hapd->dpp_pkex->own_bi->pkex_t)
1254 hapd->dpp_pkex->own_bi->pkex_t = hapd->dpp_pkex->t;
1255 dpp_pkex_free(hapd->dpp_pkex);
1256 hapd->dpp_pkex = NULL;
1257 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001258}
1259
1260
1261static void
1262hostapd_dpp_rx_pkex_exchange_resp(struct hostapd_data *hapd, const u8 *src,
1263 const u8 *buf, size_t len, unsigned int freq)
1264{
1265 struct wpabuf *msg;
1266
1267 wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Response from " MACSTR,
1268 MAC2STR(src));
1269
1270 /* TODO: Support multiple PKEX codes by iterating over all the enabled
1271 * values here */
1272
1273 if (!hapd->dpp_pkex || !hapd->dpp_pkex->initiator ||
1274 hapd->dpp_pkex->exchange_done) {
1275 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1276 return;
1277 }
1278
Roshan Pius3a1667e2018-07-03 15:17:14 -07001279 msg = dpp_pkex_rx_exchange_resp(hapd->dpp_pkex, src, buf, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001280 if (!msg) {
1281 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
1282 return;
1283 }
1284
1285 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Request to " MACSTR,
1286 MAC2STR(src));
1287
Roshan Pius3a1667e2018-07-03 15:17:14 -07001288 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
1289 " freq=%u type=%d", MAC2STR(src), freq,
1290 DPP_PA_PKEX_COMMIT_REVEAL_REQ);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001291 hostapd_drv_send_action(hapd, freq, 0, src,
1292 wpabuf_head(msg), wpabuf_len(msg));
1293 wpabuf_free(msg);
1294}
1295
1296
1297static void
1298hostapd_dpp_rx_pkex_commit_reveal_req(struct hostapd_data *hapd, const u8 *src,
1299 const u8 *hdr, const u8 *buf, size_t len,
1300 unsigned int freq)
1301{
1302 struct wpabuf *msg;
1303 struct dpp_pkex *pkex = hapd->dpp_pkex;
1304 struct dpp_bootstrap_info *bi;
1305
1306 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Request from " MACSTR,
1307 MAC2STR(src));
1308
1309 if (!pkex || pkex->initiator || !pkex->exchange_done) {
1310 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1311 return;
1312 }
1313
1314 msg = dpp_pkex_rx_commit_reveal_req(pkex, hdr, buf, len);
1315 if (!msg) {
1316 wpa_printf(MSG_DEBUG, "DPP: Failed to process the request");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001317 if (hapd->dpp_pkex->failed) {
1318 wpa_printf(MSG_DEBUG, "DPP: Terminate PKEX exchange");
1319 if (hapd->dpp_pkex->t > hapd->dpp_pkex->own_bi->pkex_t)
1320 hapd->dpp_pkex->own_bi->pkex_t =
1321 hapd->dpp_pkex->t;
1322 dpp_pkex_free(hapd->dpp_pkex);
1323 hapd->dpp_pkex = NULL;
1324 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001325 return;
1326 }
1327
1328 wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Response to "
1329 MACSTR, MAC2STR(src));
1330
Roshan Pius3a1667e2018-07-03 15:17:14 -07001331 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
1332 " freq=%u type=%d", MAC2STR(src), freq,
1333 DPP_PA_PKEX_COMMIT_REVEAL_RESP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001334 hostapd_drv_send_action(hapd, freq, 0, src,
1335 wpabuf_head(msg), wpabuf_len(msg));
1336 wpabuf_free(msg);
1337
Hai Shalom021b0b52019-04-10 11:17:58 -07001338 bi = dpp_pkex_finish(hapd->iface->interfaces->dpp, pkex, src, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001339 if (!bi)
1340 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001341 hapd->dpp_pkex = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001342}
1343
1344
1345static void
1346hostapd_dpp_rx_pkex_commit_reveal_resp(struct hostapd_data *hapd, const u8 *src,
1347 const u8 *hdr, const u8 *buf, size_t len,
1348 unsigned int freq)
1349{
1350 int res;
Hai Shalom021b0b52019-04-10 11:17:58 -07001351 struct dpp_bootstrap_info *bi;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001352 struct dpp_pkex *pkex = hapd->dpp_pkex;
1353 char cmd[500];
1354
1355 wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Response from " MACSTR,
1356 MAC2STR(src));
1357
1358 if (!pkex || !pkex->initiator || !pkex->exchange_done) {
1359 wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
1360 return;
1361 }
1362
1363 res = dpp_pkex_rx_commit_reveal_resp(pkex, hdr, buf, len);
1364 if (res < 0) {
1365 wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
1366 return;
1367 }
1368
Hai Shalom021b0b52019-04-10 11:17:58 -07001369 bi = dpp_pkex_finish(hapd->iface->interfaces->dpp, pkex, src, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001370 if (!bi)
1371 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001372 hapd->dpp_pkex = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001373
1374 os_snprintf(cmd, sizeof(cmd), " peer=%u %s",
1375 bi->id,
1376 hapd->dpp_pkex_auth_cmd ? hapd->dpp_pkex_auth_cmd : "");
1377 wpa_printf(MSG_DEBUG,
1378 "DPP: Start authentication after PKEX with parameters: %s",
1379 cmd);
1380 if (hostapd_dpp_auth_init(hapd, cmd) < 0) {
1381 wpa_printf(MSG_DEBUG,
1382 "DPP: Authentication initialization failed");
1383 return;
1384 }
1385}
1386
1387
1388void hostapd_dpp_rx_action(struct hostapd_data *hapd, const u8 *src,
1389 const u8 *buf, size_t len, unsigned int freq)
1390{
1391 u8 crypto_suite;
1392 enum dpp_public_action_frame_type type;
1393 const u8 *hdr;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001394 unsigned int pkex_t;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001395
1396 if (len < DPP_HDR_LEN)
1397 return;
1398 if (WPA_GET_BE24(buf) != OUI_WFA || buf[3] != DPP_OUI_TYPE)
1399 return;
1400 hdr = buf;
1401 buf += 4;
1402 len -= 4;
1403 crypto_suite = *buf++;
1404 type = *buf++;
1405 len -= 2;
1406
1407 wpa_printf(MSG_DEBUG,
1408 "DPP: Received DPP Public Action frame crypto suite %u type %d from "
1409 MACSTR " freq=%u",
1410 crypto_suite, type, MAC2STR(src), freq);
1411 if (crypto_suite != 1) {
1412 wpa_printf(MSG_DEBUG, "DPP: Unsupported crypto suite %u",
1413 crypto_suite);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001414 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
1415 " freq=%u type=%d ignore=unsupported-crypto-suite",
1416 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001417 return;
1418 }
1419 wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001420 if (dpp_check_attrs(buf, len) < 0) {
1421 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
1422 " freq=%u type=%d ignore=invalid-attributes",
1423 MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001424 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001425 }
1426 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
1427 " freq=%u type=%d", MAC2STR(src), freq, type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001428
Hai Shalom81f62d82019-07-22 12:10:00 -07001429#ifdef CONFIG_DPP2
1430 if (dpp_relay_rx_action(hapd->iface->interfaces->dpp,
1431 src, hdr, buf, len, freq, NULL, NULL) == 0)
1432 return;
1433#endif /* CONFIG_DPP2 */
1434
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001435 switch (type) {
1436 case DPP_PA_AUTHENTICATION_REQ:
1437 hostapd_dpp_rx_auth_req(hapd, src, hdr, buf, len, freq);
1438 break;
1439 case DPP_PA_AUTHENTICATION_RESP:
Roshan Pius3a1667e2018-07-03 15:17:14 -07001440 hostapd_dpp_rx_auth_resp(hapd, src, hdr, buf, len, freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001441 break;
1442 case DPP_PA_AUTHENTICATION_CONF:
1443 hostapd_dpp_rx_auth_conf(hapd, src, hdr, buf, len);
1444 break;
1445 case DPP_PA_PEER_DISCOVERY_REQ:
1446 hostapd_dpp_rx_peer_disc_req(hapd, src, buf, len, freq);
1447 break;
1448 case DPP_PA_PKEX_EXCHANGE_REQ:
1449 hostapd_dpp_rx_pkex_exchange_req(hapd, src, buf, len, freq);
1450 break;
1451 case DPP_PA_PKEX_EXCHANGE_RESP:
1452 hostapd_dpp_rx_pkex_exchange_resp(hapd, src, buf, len, freq);
1453 break;
1454 case DPP_PA_PKEX_COMMIT_REVEAL_REQ:
1455 hostapd_dpp_rx_pkex_commit_reveal_req(hapd, src, hdr, buf, len,
1456 freq);
1457 break;
1458 case DPP_PA_PKEX_COMMIT_REVEAL_RESP:
1459 hostapd_dpp_rx_pkex_commit_reveal_resp(hapd, src, hdr, buf, len,
1460 freq);
1461 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07001462#ifdef CONFIG_DPP2
1463 case DPP_PA_CONFIGURATION_RESULT:
1464 hostapd_dpp_rx_conf_result(hapd, src, hdr, buf, len);
1465 break;
Hai Shalomc3565922019-10-28 11:58:20 -07001466 case DPP_PA_CONNECTION_STATUS_RESULT:
1467 hostapd_dpp_rx_conn_status_result(hapd, src, hdr, buf, len);
1468 break;
Hai Shalom021b0b52019-04-10 11:17:58 -07001469#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001470 default:
1471 wpa_printf(MSG_DEBUG,
1472 "DPP: Ignored unsupported frame subtype %d", type);
1473 break;
1474 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001475
1476 if (hapd->dpp_pkex)
1477 pkex_t = hapd->dpp_pkex->t;
1478 else if (hapd->dpp_pkex_bi)
1479 pkex_t = hapd->dpp_pkex_bi->pkex_t;
1480 else
1481 pkex_t = 0;
1482 if (pkex_t >= PKEX_COUNTER_T_LIMIT) {
1483 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_PKEX_T_LIMIT "id=0");
1484 hostapd_dpp_pkex_remove(hapd, "*");
1485 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001486}
1487
1488
1489struct wpabuf *
1490hostapd_dpp_gas_req_handler(struct hostapd_data *hapd, const u8 *sa,
Hai Shalom81f62d82019-07-22 12:10:00 -07001491 const u8 *query, size_t query_len,
1492 const u8 *data, size_t data_len)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001493{
1494 struct dpp_authentication *auth = hapd->dpp_auth;
1495 struct wpabuf *resp;
1496
1497 wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR, MAC2STR(sa));
1498 if (!auth || !auth->auth_success ||
1499 os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001500#ifdef CONFIG_DPP2
1501 if (dpp_relay_rx_gas_req(hapd->iface->interfaces->dpp, sa, data,
1502 data_len) == 0) {
1503 /* Response will be forwarded once received over TCP */
1504 return NULL;
1505 }
1506#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001507 wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
1508 return NULL;
1509 }
1510 wpa_hexdump(MSG_DEBUG,
1511 "DPP: Received Configuration Request (GAS Query Request)",
1512 query, query_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001513 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONF_REQ_RX "src=" MACSTR,
1514 MAC2STR(sa));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001515 resp = dpp_conf_req_rx(auth, query, query_len);
1516 if (!resp)
1517 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONF_FAILED);
1518 return resp;
1519}
1520
1521
Roshan Pius3a1667e2018-07-03 15:17:14 -07001522void hostapd_dpp_gas_status_handler(struct hostapd_data *hapd, int ok)
1523{
Hai Shalom021b0b52019-04-10 11:17:58 -07001524 struct dpp_authentication *auth = hapd->dpp_auth;
1525
1526 if (!auth)
Roshan Pius3a1667e2018-07-03 15:17:14 -07001527 return;
1528
Hai Shalom021b0b52019-04-10 11:17:58 -07001529 wpa_printf(MSG_DEBUG, "DPP: Configuration exchange completed (ok=%d)",
1530 ok);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001531 eloop_cancel_timeout(hostapd_dpp_reply_wait_timeout, hapd, NULL);
1532 eloop_cancel_timeout(hostapd_dpp_auth_resp_retry_timeout, hapd, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07001533#ifdef CONFIG_DPP2
1534 if (ok && auth->peer_version >= 2 &&
1535 auth->conf_resp_status == DPP_STATUS_OK) {
1536 wpa_printf(MSG_DEBUG, "DPP: Wait for Configuration Result");
1537 auth->waiting_conf_result = 1;
1538 eloop_cancel_timeout(hostapd_dpp_config_result_wait_timeout,
1539 hapd, NULL);
1540 eloop_register_timeout(2, 0,
1541 hostapd_dpp_config_result_wait_timeout,
1542 hapd, NULL);
1543 return;
1544 }
1545#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001546 hostapd_drv_send_action_cancel_wait(hapd);
1547
1548 if (ok)
1549 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONF_SENT);
1550 else
1551 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONF_FAILED);
1552 dpp_auth_deinit(hapd->dpp_auth);
1553 hapd->dpp_auth = NULL;
1554}
1555
1556
Roshan Pius3a1667e2018-07-03 15:17:14 -07001557int hostapd_dpp_configurator_sign(struct hostapd_data *hapd, const char *cmd)
1558{
1559 struct dpp_authentication *auth;
1560 int ret = -1;
1561 char *curve = NULL;
1562
1563 auth = os_zalloc(sizeof(*auth));
1564 if (!auth)
1565 return -1;
1566
1567 curve = get_param(cmd, " curve=");
Hai Shalom74f70d42019-02-11 14:42:39 -08001568 hostapd_dpp_set_testing_options(hapd, auth);
Hai Shalom021b0b52019-04-10 11:17:58 -07001569 if (dpp_set_configurator(hapd->iface->interfaces->dpp, hapd->msg_ctx,
1570 auth, cmd) == 0 &&
Hai Shalom74f70d42019-02-11 14:42:39 -08001571 dpp_configurator_own_config(auth, curve, 1) == 0) {
Hai Shalomc3565922019-10-28 11:58:20 -07001572 hostapd_dpp_handle_config_obj(hapd, auth, &auth->conf_obj[0]);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001573 ret = 0;
1574 }
1575
1576 dpp_auth_deinit(auth);
1577 os_free(curve);
1578
1579 return ret;
1580}
1581
1582
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001583int hostapd_dpp_pkex_add(struct hostapd_data *hapd, const char *cmd)
1584{
1585 struct dpp_bootstrap_info *own_bi;
1586 const char *pos, *end;
1587
1588 pos = os_strstr(cmd, " own=");
1589 if (!pos)
1590 return -1;
1591 pos += 5;
Hai Shalom021b0b52019-04-10 11:17:58 -07001592 own_bi = dpp_bootstrap_get_id(hapd->iface->interfaces->dpp, atoi(pos));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001593 if (!own_bi) {
1594 wpa_printf(MSG_DEBUG,
1595 "DPP: Identified bootstrap info not found");
1596 return -1;
1597 }
1598 if (own_bi->type != DPP_BOOTSTRAP_PKEX) {
1599 wpa_printf(MSG_DEBUG,
1600 "DPP: Identified bootstrap info not for PKEX");
1601 return -1;
1602 }
1603 hapd->dpp_pkex_bi = own_bi;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001604 own_bi->pkex_t = 0; /* clear pending errors on new code */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001605
1606 os_free(hapd->dpp_pkex_identifier);
1607 hapd->dpp_pkex_identifier = NULL;
1608 pos = os_strstr(cmd, " identifier=");
1609 if (pos) {
1610 pos += 12;
1611 end = os_strchr(pos, ' ');
1612 if (!end)
1613 return -1;
1614 hapd->dpp_pkex_identifier = os_malloc(end - pos + 1);
1615 if (!hapd->dpp_pkex_identifier)
1616 return -1;
1617 os_memcpy(hapd->dpp_pkex_identifier, pos, end - pos);
1618 hapd->dpp_pkex_identifier[end - pos] = '\0';
1619 }
1620
1621 pos = os_strstr(cmd, " code=");
1622 if (!pos)
1623 return -1;
1624 os_free(hapd->dpp_pkex_code);
1625 hapd->dpp_pkex_code = os_strdup(pos + 6);
1626 if (!hapd->dpp_pkex_code)
1627 return -1;
1628
1629 if (os_strstr(cmd, " init=1")) {
1630 struct wpabuf *msg;
1631
1632 wpa_printf(MSG_DEBUG, "DPP: Initiating PKEX");
1633 dpp_pkex_free(hapd->dpp_pkex);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001634 hapd->dpp_pkex = dpp_pkex_init(hapd->msg_ctx, own_bi,
1635 hapd->own_addr,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001636 hapd->dpp_pkex_identifier,
1637 hapd->dpp_pkex_code);
1638 if (!hapd->dpp_pkex)
1639 return -1;
1640
1641 msg = hapd->dpp_pkex->exchange_req;
1642 /* TODO: Which channel to use? */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001643 wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
1644 " freq=%u type=%d", MAC2STR(broadcast), 2437,
1645 DPP_PA_PKEX_EXCHANGE_REQ);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001646 hostapd_drv_send_action(hapd, 2437, 0, broadcast,
1647 wpabuf_head(msg), wpabuf_len(msg));
1648 }
1649
1650 /* TODO: Support multiple PKEX info entries */
1651
1652 os_free(hapd->dpp_pkex_auth_cmd);
1653 hapd->dpp_pkex_auth_cmd = os_strdup(cmd);
1654
1655 return 1;
1656}
1657
1658
1659int hostapd_dpp_pkex_remove(struct hostapd_data *hapd, const char *id)
1660{
1661 unsigned int id_val;
1662
1663 if (os_strcmp(id, "*") == 0) {
1664 id_val = 0;
1665 } else {
1666 id_val = atoi(id);
1667 if (id_val == 0)
1668 return -1;
1669 }
1670
1671 if ((id_val != 0 && id_val != 1) || !hapd->dpp_pkex_code)
1672 return -1;
1673
1674 /* TODO: Support multiple PKEX entries */
1675 os_free(hapd->dpp_pkex_code);
1676 hapd->dpp_pkex_code = NULL;
1677 os_free(hapd->dpp_pkex_identifier);
1678 hapd->dpp_pkex_identifier = NULL;
1679 os_free(hapd->dpp_pkex_auth_cmd);
1680 hapd->dpp_pkex_auth_cmd = NULL;
1681 hapd->dpp_pkex_bi = NULL;
1682 /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
1683 dpp_pkex_free(hapd->dpp_pkex);
1684 hapd->dpp_pkex = NULL;
1685 return 0;
1686}
1687
1688
Roshan Pius3a1667e2018-07-03 15:17:14 -07001689void hostapd_dpp_stop(struct hostapd_data *hapd)
1690{
1691 dpp_auth_deinit(hapd->dpp_auth);
1692 hapd->dpp_auth = NULL;
1693 dpp_pkex_free(hapd->dpp_pkex);
1694 hapd->dpp_pkex = NULL;
1695}
1696
1697
Hai Shalom81f62d82019-07-22 12:10:00 -07001698#ifdef CONFIG_DPP2
1699
1700static void hostapd_dpp_relay_tx(void *ctx, const u8 *addr, unsigned int freq,
1701 const u8 *msg, size_t len)
1702{
1703 struct hostapd_data *hapd = ctx;
1704 u8 *buf;
1705
1706 wpa_printf(MSG_DEBUG, "DPP: Send action frame dst=" MACSTR " freq=%u",
1707 MAC2STR(addr), freq);
1708 buf = os_malloc(2 + len);
1709 if (!buf)
1710 return;
1711 buf[0] = WLAN_ACTION_PUBLIC;
1712 buf[1] = WLAN_PA_VENDOR_SPECIFIC;
1713 os_memcpy(buf + 2, msg, len);
1714 hostapd_drv_send_action(hapd, freq, 0, addr, buf, 2 + len);
1715 os_free(buf);
1716}
1717
1718
1719static void hostapd_dpp_relay_gas_resp_tx(void *ctx, const u8 *addr,
1720 u8 dialog_token, int prot,
1721 struct wpabuf *buf)
1722{
1723 struct hostapd_data *hapd = ctx;
1724
1725 gas_serv_req_dpp_processing(hapd, addr, dialog_token, prot, buf);
1726}
1727
1728#endif /* CONFIG_DPP2 */
1729
1730
1731static int hostapd_dpp_add_controllers(struct hostapd_data *hapd)
1732{
1733#ifdef CONFIG_DPP2
1734 struct dpp_controller_conf *ctrl;
1735 struct dpp_relay_config config;
1736
1737 os_memset(&config, 0, sizeof(config));
1738 config.cb_ctx = hapd;
1739 config.tx = hostapd_dpp_relay_tx;
1740 config.gas_resp_tx = hostapd_dpp_relay_gas_resp_tx;
1741 for (ctrl = hapd->conf->dpp_controller; ctrl; ctrl = ctrl->next) {
1742 config.ipaddr = &ctrl->ipaddr;
1743 config.pkhash = ctrl->pkhash;
1744 if (dpp_relay_add_controller(hapd->iface->interfaces->dpp,
1745 &config) < 0)
1746 return -1;
1747 }
1748#endif /* CONFIG_DPP2 */
1749
1750 return 0;
1751}
1752
1753
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001754int hostapd_dpp_init(struct hostapd_data *hapd)
1755{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001756 hapd->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR | DPP_CAPAB_ENROLLEE;
1757 hapd->dpp_init_done = 1;
Hai Shalom81f62d82019-07-22 12:10:00 -07001758 return hostapd_dpp_add_controllers(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001759}
1760
1761
1762void hostapd_dpp_deinit(struct hostapd_data *hapd)
1763{
1764#ifdef CONFIG_TESTING_OPTIONS
1765 os_free(hapd->dpp_config_obj_override);
1766 hapd->dpp_config_obj_override = NULL;
1767 os_free(hapd->dpp_discovery_override);
1768 hapd->dpp_discovery_override = NULL;
1769 os_free(hapd->dpp_groups_override);
1770 hapd->dpp_groups_override = NULL;
1771 hapd->dpp_ignore_netaccesskey_mismatch = 0;
1772#endif /* CONFIG_TESTING_OPTIONS */
1773 if (!hapd->dpp_init_done)
1774 return;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001775 eloop_cancel_timeout(hostapd_dpp_reply_wait_timeout, hapd, NULL);
1776 eloop_cancel_timeout(hostapd_dpp_init_timeout, hapd, NULL);
1777 eloop_cancel_timeout(hostapd_dpp_auth_resp_retry_timeout, hapd, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07001778#ifdef CONFIG_DPP2
1779 eloop_cancel_timeout(hostapd_dpp_config_result_wait_timeout, hapd,
1780 NULL);
Hai Shalomc3565922019-10-28 11:58:20 -07001781 eloop_cancel_timeout(hostapd_dpp_conn_status_result_wait_timeout, hapd,
1782 NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07001783#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001784 dpp_auth_deinit(hapd->dpp_auth);
1785 hapd->dpp_auth = NULL;
1786 hostapd_dpp_pkex_remove(hapd, "*");
1787 hapd->dpp_pkex = NULL;
1788 os_free(hapd->dpp_configurator_params);
1789 hapd->dpp_configurator_params = NULL;
1790}