static const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+static struct dpp_configurator *
+hostapd_dpp_configurator_get_id(struct hostapd_data *hapd, unsigned int id)
+{
+ struct dpp_configurator *conf;
+
+ dl_list_for_each(conf, &hapd->dpp_configurator,
+ struct dpp_configurator, list) {
+ if (conf->id == id)
+ return conf;
+ }
+ return NULL;
+}
+
+
static unsigned int hapd_dpp_next_id(struct hostapd_data *hapd)
{
struct dpp_bootstrap_info *bi;
}
-int hostapd_dpp_auth_init(struct hostapd_data *hapd, const char *cmd)
+static void hostapd_dpp_set_configurator(struct hostapd_data *hapd,
+ struct dpp_authentication *auth,
+ const char *cmd)
{
- const char *pos;
- struct dpp_bootstrap_info *peer_bi, *own_bi = NULL;
- struct wpabuf *msg;
- const u8 *dst;
- int res;
- int configurator = 1;
+ const char *pos, *end;
struct dpp_configuration *conf_sta = NULL, *conf_ap = NULL;
+ struct dpp_configurator *conf = NULL;
+ u8 ssid[32] = { "test" };
+ size_t ssid_len = 4;
+ char pass[64] = { };
+ size_t pass_len = 0;
- pos = os_strstr(cmd, " peer=");
- if (!pos)
- return -1;
- pos += 6;
- peer_bi = dpp_bootstrap_get_id(hapd, atoi(pos));
- if (!peer_bi) {
- wpa_printf(MSG_INFO,
- "DPP: Could not find bootstrapping info for the identified peer");
- return -1;
- }
+ if (!cmd)
+ return;
- pos = os_strstr(cmd, " own=");
+ wpa_printf(MSG_DEBUG, "DPP: Set configurator parameters: %s", cmd);
+ pos = os_strstr(cmd, " ssid=");
if (pos) {
- pos += 5;
- own_bi = dpp_bootstrap_get_id(hapd, atoi(pos));
- if (!own_bi) {
- wpa_printf(MSG_INFO,
- "DPP: Could not find bootstrapping info for the identified local entry");
- return -1;
- }
-
- if (peer_bi->curve != own_bi->curve) {
- wpa_printf(MSG_INFO,
- "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
- peer_bi->curve->name, own_bi->curve->name);
- return -1;
- }
+ pos += 6;
+ end = os_strchr(pos, ' ');
+ ssid_len = end ? (size_t) (end - pos) : os_strlen(pos);
+ ssid_len /= 2;
+ if (ssid_len > sizeof(ssid) ||
+ hexstr2bin(pos, ssid, ssid_len) < 0)
+ goto fail;
}
- pos = os_strstr(cmd, " role=");
+ pos = os_strstr(cmd, " pass=");
if (pos) {
pos += 6;
- if (os_strncmp(pos, "configurator", 12) == 0)
- configurator = 1;
- else if (os_strncmp(pos, "enrollee", 8) == 0)
- configurator = 0;
- else
+ end = os_strchr(pos, ' ');
+ pass_len = end ? (size_t) (end - pos) : os_strlen(pos);
+ pass_len /= 2;
+ if (pass_len > sizeof(pass) - 1 || pass_len < 8 ||
+ hexstr2bin(pos, (u8 *) pass, pass_len) < 0)
goto fail;
}
conf_sta = os_zalloc(sizeof(struct dpp_configuration));
if (!conf_sta)
goto fail;
- /* TODO: Configuration of network parameters from upper layers
- */
- os_memcpy(conf_sta->ssid, "test", 4);
- conf_sta->ssid_len = 4;
+ os_memcpy(conf_sta->ssid, ssid, ssid_len);
+ conf_sta->ssid_len = ssid_len;
if (os_strstr(cmd, " conf=sta-psk")) {
conf_sta->dpp = 0;
- conf_sta->passphrase = os_strdup("secret passphrase");
+ conf_sta->passphrase = os_strdup(pass);
if (!conf_sta->passphrase)
goto fail;
} else if (os_strstr(cmd, " conf=sta-dpp")) {
conf_ap = os_zalloc(sizeof(struct dpp_configuration));
if (!conf_ap)
goto fail;
- /* TODO: Configuration of network parameters from upper layers
- */
- os_memcpy(conf_ap->ssid, "test", 4);
- conf_ap->ssid_len = 4;
+ os_memcpy(conf_ap->ssid, ssid, ssid_len);
+ conf_ap->ssid_len = ssid_len;
if (os_strstr(cmd, " conf=ap-psk")) {
conf_ap->dpp = 0;
- conf_ap->passphrase = os_strdup("secret passphrase");
+ conf_ap->passphrase = os_strdup(pass);
if (!conf_ap->passphrase)
goto fail;
} else if (os_strstr(cmd, " conf=ap-dpp")) {
conf_ap->netaccesskey_expiry = val;
}
+ pos = os_strstr(cmd, " configurator=");
+ if (pos) {
+ auth->configurator = 1;
+ pos += 14;
+ conf = hostapd_dpp_configurator_get_id(hapd, atoi(pos));
+ if (!conf) {
+ wpa_printf(MSG_INFO,
+ "DPP: Could not find the specified configurator");
+ goto fail;
+ }
+ }
+ auth->conf_sta = conf_sta;
+ auth->conf_ap = conf_ap;
+ auth->conf = conf;
+ return;
+
+fail:
+ wpa_printf(MSG_DEBUG, "DPP: Failed to set configurator parameters");
+ dpp_configuration_free(conf_sta);
+ dpp_configuration_free(conf_ap);
+}
+
+
+int hostapd_dpp_auth_init(struct hostapd_data *hapd, const char *cmd)
+{
+ const char *pos;
+ struct dpp_bootstrap_info *peer_bi, *own_bi = NULL;
+ struct wpabuf *msg;
+ const u8 *dst;
+ int res;
+ int configurator = 1;
+ struct dpp_configuration *conf_sta = NULL, *conf_ap = NULL;
+
+ pos = os_strstr(cmd, " peer=");
+ if (!pos)
+ return -1;
+ pos += 6;
+ peer_bi = dpp_bootstrap_get_id(hapd, atoi(pos));
+ if (!peer_bi) {
+ wpa_printf(MSG_INFO,
+ "DPP: Could not find bootstrapping info for the identified peer");
+ return -1;
+ }
+
+ pos = os_strstr(cmd, " own=");
+ if (pos) {
+ pos += 5;
+ own_bi = dpp_bootstrap_get_id(hapd, atoi(pos));
+ if (!own_bi) {
+ wpa_printf(MSG_INFO,
+ "DPP: Could not find bootstrapping info for the identified local entry");
+ return -1;
+ }
+
+ if (peer_bi->curve != own_bi->curve) {
+ wpa_printf(MSG_INFO,
+ "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
+ peer_bi->curve->name, own_bi->curve->name);
+ return -1;
+ }
+ }
+
+ pos = os_strstr(cmd, " role=");
+ if (pos) {
+ pos += 6;
+ if (os_strncmp(pos, "configurator", 12) == 0)
+ configurator = 1;
+ else if (os_strncmp(pos, "enrollee", 8) == 0)
+ configurator = 0;
+ else
+ goto fail;
+ }
+
if (hapd->dpp_auth)
dpp_auth_deinit(hapd->dpp_auth);
hapd->dpp_auth = dpp_auth_init(hapd, peer_bi, own_bi, configurator);
if (!hapd->dpp_auth)
goto fail;
hostapd_dpp_set_testing_options(hapd, hapd->dpp_auth);
- hapd->dpp_auth->conf_sta = conf_sta;
- hapd->dpp_auth->conf_ap = conf_ap;
+ hostapd_dpp_set_configurator(hapd, hapd->dpp_auth, cmd);
/* TODO: Support iteration over all frequencies and filtering of
* frequencies based on locally enabled channels that allow initiation
return;
}
hostapd_dpp_set_testing_options(hapd, hapd->dpp_auth);
+ hostapd_dpp_set_configurator(hapd, hapd->dpp_auth,
+ hapd->dpp_configurator_params);
os_memcpy(hapd->dpp_auth->peer_mac_addr, src, ETH_ALEN);
msg = dpp_alloc_msg(DPP_PA_AUTHENTICATION_RESP,
hapd->dpp_auth = NULL;
hostapd_dpp_pkex_remove(hapd, "*");
hapd->dpp_pkex = NULL;
+ os_free(hapd->dpp_configurator_params);
+ hapd->dpp_configurator_params = NULL;
}