From: Jouni Malinen Date: Thu, 7 Jul 2022 21:12:07 +0000 (+0300) Subject: DPP3: Allow external configuration to be specified on AP for PB X-Git-Tag: hostap_2_11~1845 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7bbe859873565ac111eac6607d15f9fd11a3e70c;p=thirdparty%2Fhostap.git DPP3: Allow external configuration to be specified on AP for PB While the most likely production use case for DPP push button is to provision the AP's current configuration, there might be some use cases for providing different configuration. Add possibility for doing this by extending the DPP_PUSH_BUTTON command to accept an optional set of parameters similarly to the other DPP commands for the Configurator. Signed-off-by: Jouni Malinen --- diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index e0b582030..a976e8fca 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -3676,7 +3676,10 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, #endif /* CONFIG_DPP2 */ #ifdef CONFIG_DPP3 } else if (os_strcmp(buf, "DPP_PUSH_BUTTON") == 0) { - if (hostapd_dpp_push_button(hapd) < 0) + if (hostapd_dpp_push_button(hapd, NULL) < 0) + reply_len = -1; + } else if (os_strncmp(buf, "DPP_PUSH_BUTTON ", 16) == 0) { + if (hostapd_dpp_push_button(hapd, buf + 15) < 0) reply_len = -1; #endif /* CONFIG_DPP3 */ #endif /* CONFIG_DPP */ diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c index 7ab978179..56a7cadcc 100644 --- a/hostapd/hostapd_cli.c +++ b/hostapd/hostapd_cli.c @@ -1509,7 +1509,7 @@ static int hostapd_cli_cmd_dpp_stop_chirp(struct wpa_ctrl *ctrl, int argc, static int hostapd_cli_cmd_dpp_push_button(struct wpa_ctrl *ctrl, int argc, char *argv[]) { - return wpa_ctrl_command(ctrl, "DPP_PUSH_BUTTON"); + return hostapd_cli_cmd(ctrl, "DPP_PUSH_BUTTON", 1, argc, argv); } #endif /* CONFIG_DPP3 */ #endif /* CONFIG_DPP */ diff --git a/src/ap/dpp_hostapd.c b/src/ap/dpp_hostapd.c index 1c4be2430..5a6fab628 100644 --- a/src/ap/dpp_hostapd.c +++ b/src/ap/dpp_hostapd.c @@ -2348,6 +2348,18 @@ static void hostapd_dpp_pb_pkex_init(struct hostapd_data *hapd, pkex->exch_req_wait_time = 2000; pkex->exch_req_tries = 1; + if (ifaces->dpp_pb_cmd) { + /* Use the externally provided configuration */ + os_free(hapd->dpp_pkex_auth_cmd); + hapd->dpp_pkex_auth_cmd = os_strdup(ifaces->dpp_pb_cmd); + if (!hapd->dpp_pkex_auth_cmd) { + hostapd_dpp_push_button_stop(hapd); + return; + } + return; + } + + /* Build config based on the current AP configuration */ wpa_snprintf_hex(ssid_hex, sizeof(ssid_hex), (const u8 *) hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len); @@ -3487,7 +3499,7 @@ static void hostapd_dpp_push_button_expire(void *eloop_ctx, void *timeout_ctx) } -int hostapd_dpp_push_button(struct hostapd_data *hapd) +int hostapd_dpp_push_button(struct hostapd_data *hapd, const char *cmd) { struct hapd_interfaces *ifaces = hapd->iface->interfaces; @@ -3496,6 +3508,13 @@ int hostapd_dpp_push_button(struct hostapd_data *hapd) os_get_reltime(&ifaces->dpp_pb_time); ifaces->dpp_pb_announce_time.sec = 0; ifaces->dpp_pb_announce_time.usec = 0; + str_clear_free(ifaces->dpp_pb_cmd); + ifaces->dpp_pb_cmd = NULL; + if (cmd) { + ifaces->dpp_pb_cmd = os_strdup(cmd); + if (!ifaces->dpp_pb_cmd) + return -1; + } eloop_register_timeout(100, 0, hostapd_dpp_push_button_expire, hapd, NULL); @@ -3532,6 +3551,9 @@ void hostapd_dpp_push_button_stop(struct hostapd_data *hapd) } ifaces->dpp_pb_result_indicated = false; + + str_clear_free(ifaces->dpp_pb_cmd); + ifaces->dpp_pb_cmd = NULL; } #endif /* CONFIG_DPP3 */ diff --git a/src/ap/dpp_hostapd.h b/src/ap/dpp_hostapd.h index 6b7716428..e7276e889 100644 --- a/src/ap/dpp_hostapd.h +++ b/src/ap/dpp_hostapd.h @@ -45,7 +45,7 @@ int hostapd_dpp_controller_start(struct hostapd_data *hapd, const char *cmd); int hostapd_dpp_chirp(struct hostapd_data *hapd, const char *cmd); void hostapd_dpp_chirp_stop(struct hostapd_data *hapd); void hostapd_dpp_remove_bi(void *ctx, struct dpp_bootstrap_info *bi); -int hostapd_dpp_push_button(struct hostapd_data *hapd); +int hostapd_dpp_push_button(struct hostapd_data *hapd, const char *cmd); void hostapd_dpp_push_button_stop(struct hostapd_data *hapd); #endif /* DPP_HOSTAPD_H */ diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index 2e9a89890..33d4cb784 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -92,6 +92,7 @@ struct hapd_interfaces { u8 dpp_pb_resp_hash[SHA256_MAC_LEN]; struct os_reltime dpp_pb_last_resp; bool dpp_pb_result_indicated; + char *dpp_pb_cmd; #endif /* CONFIG_DPP3 */ #endif /* CONFIG_DPP */