DPP: Replace ap boolean with netRole enum in Configurator params
The netRole enum is more generic and can be extended to include new roles (e.g., Configurator) more easily. Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
This commit is contained in:
parent
053ce8bff7
commit
7404574458
5 changed files with 45 additions and 26 deletions
|
@ -787,7 +787,8 @@ static void hostapd_dpp_start_gas_client(struct hostapd_data *hapd)
|
||||||
struct wpabuf *buf;
|
struct wpabuf *buf;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
buf = dpp_build_conf_req_helper(auth, hapd->conf->dpp_name, 1,
|
buf = dpp_build_conf_req_helper(auth, hapd->conf->dpp_name,
|
||||||
|
DPP_NETROLE_AP,
|
||||||
hapd->conf->dpp_mud_url, NULL);
|
hapd->conf->dpp_mud_url, NULL);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
wpa_printf(MSG_DEBUG,
|
wpa_printf(MSG_DEBUG,
|
||||||
|
|
|
@ -33,6 +33,8 @@
|
||||||
#include "dpp.h"
|
#include "dpp.h"
|
||||||
|
|
||||||
|
|
||||||
|
static const char * dpp_netrole_str(enum dpp_netrole netrole);
|
||||||
|
|
||||||
#ifdef CONFIG_TESTING_OPTIONS
|
#ifdef CONFIG_TESTING_OPTIONS
|
||||||
enum dpp_test_behavior dpp_test = DPP_TEST_DISABLED;
|
enum dpp_test_behavior dpp_test = DPP_TEST_DISABLED;
|
||||||
u8 dpp_pkex_own_mac_override[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
|
u8 dpp_pkex_own_mac_override[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
|
||||||
|
@ -2531,7 +2533,8 @@ struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
|
||||||
|
|
||||||
|
|
||||||
struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth,
|
struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth,
|
||||||
const char *name, int netrole_ap,
|
const char *name,
|
||||||
|
enum dpp_netrole netrole,
|
||||||
const char *mud_url, int *opclasses)
|
const char *mud_url, int *opclasses)
|
||||||
{
|
{
|
||||||
size_t len, name_len;
|
size_t len, name_len;
|
||||||
|
@ -2566,7 +2569,7 @@ struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth,
|
||||||
json_value_sep(json);
|
json_value_sep(json);
|
||||||
json_add_string(json, "wi-fi_tech", tech);
|
json_add_string(json, "wi-fi_tech", tech);
|
||||||
json_value_sep(json);
|
json_value_sep(json);
|
||||||
json_add_string(json, "netRole", netrole_ap ? "ap" : "sta");
|
json_add_string(json, "netRole", dpp_netrole_str(netrole));
|
||||||
if (mud_url && mud_url[0]) {
|
if (mud_url && mud_url[0]) {
|
||||||
json_value_sep(json);
|
json_value_sep(json);
|
||||||
json_add_string(json, "mudurl", mud_url);
|
json_add_string(json, "mudurl", mud_url);
|
||||||
|
@ -5012,9 +5015,10 @@ dpp_build_conf_obj_legacy(struct dpp_authentication *auth,
|
||||||
|
|
||||||
|
|
||||||
static struct wpabuf *
|
static struct wpabuf *
|
||||||
dpp_build_conf_obj(struct dpp_authentication *auth, int ap, int idx)
|
dpp_build_conf_obj(struct dpp_authentication *auth, enum dpp_netrole netrole,
|
||||||
|
int idx)
|
||||||
{
|
{
|
||||||
struct dpp_configuration *conf;
|
struct dpp_configuration *conf = NULL;
|
||||||
|
|
||||||
#ifdef CONFIG_TESTING_OPTIONS
|
#ifdef CONFIG_TESTING_OPTIONS
|
||||||
if (auth->config_obj_override) {
|
if (auth->config_obj_override) {
|
||||||
|
@ -5026,17 +5030,22 @@ dpp_build_conf_obj(struct dpp_authentication *auth, int ap, int idx)
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_TESTING_OPTIONS */
|
#endif /* CONFIG_TESTING_OPTIONS */
|
||||||
|
|
||||||
if (idx == 0)
|
if (idx == 0) {
|
||||||
conf = ap ? auth->conf_ap : auth->conf_sta;
|
if (netrole == DPP_NETROLE_STA)
|
||||||
else if (idx == 1)
|
conf = auth->conf_sta;
|
||||||
conf = ap ? auth->conf2_ap : auth->conf2_sta;
|
else if (netrole == DPP_NETROLE_AP)
|
||||||
else
|
conf = auth->conf_ap;
|
||||||
conf = NULL;
|
} else if (idx == 1) {
|
||||||
|
if (netrole == DPP_NETROLE_STA)
|
||||||
|
conf = auth->conf2_sta;
|
||||||
|
else if (netrole == DPP_NETROLE_AP)
|
||||||
|
conf = auth->conf2_ap;
|
||||||
|
}
|
||||||
if (!conf) {
|
if (!conf) {
|
||||||
if (idx == 0)
|
if (idx == 0)
|
||||||
wpa_printf(MSG_DEBUG,
|
wpa_printf(MSG_DEBUG,
|
||||||
"DPP: No configuration available for Enrollee(%s) - reject configuration request",
|
"DPP: No configuration available for Enrollee(%s) - reject configuration request",
|
||||||
ap ? "ap" : "sta");
|
dpp_netrole_str(netrole));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5048,7 +5057,7 @@ dpp_build_conf_obj(struct dpp_authentication *auth, int ap, int idx)
|
||||||
|
|
||||||
static struct wpabuf *
|
static struct wpabuf *
|
||||||
dpp_build_conf_resp(struct dpp_authentication *auth, const u8 *e_nonce,
|
dpp_build_conf_resp(struct dpp_authentication *auth, const u8 *e_nonce,
|
||||||
u16 e_nonce_len, int ap)
|
u16 e_nonce_len, enum dpp_netrole netrole)
|
||||||
{
|
{
|
||||||
struct wpabuf *conf, *conf2 = NULL;
|
struct wpabuf *conf, *conf2 = NULL;
|
||||||
size_t clear_len, attr_len;
|
size_t clear_len, attr_len;
|
||||||
|
@ -5058,11 +5067,11 @@ dpp_build_conf_resp(struct dpp_authentication *auth, const u8 *e_nonce,
|
||||||
size_t len[1];
|
size_t len[1];
|
||||||
enum dpp_status_error status;
|
enum dpp_status_error status;
|
||||||
|
|
||||||
conf = dpp_build_conf_obj(auth, ap, 0);
|
conf = dpp_build_conf_obj(auth, netrole, 0);
|
||||||
if (conf) {
|
if (conf) {
|
||||||
wpa_hexdump_ascii(MSG_DEBUG, "DPP: configurationObject JSON",
|
wpa_hexdump_ascii(MSG_DEBUG, "DPP: configurationObject JSON",
|
||||||
wpabuf_head(conf), wpabuf_len(conf));
|
wpabuf_head(conf), wpabuf_len(conf));
|
||||||
conf2 = dpp_build_conf_obj(auth, ap, 1);
|
conf2 = dpp_build_conf_obj(auth, netrole, 1);
|
||||||
}
|
}
|
||||||
status = conf ? DPP_STATUS_OK : DPP_STATUS_CONFIGURE_FAILURE;
|
status = conf ? DPP_STATUS_OK : DPP_STATUS_CONFIGURE_FAILURE;
|
||||||
auth->conf_resp_status = status;
|
auth->conf_resp_status = status;
|
||||||
|
@ -5073,7 +5082,8 @@ dpp_build_conf_resp(struct dpp_authentication *auth, const u8 *e_nonce,
|
||||||
clear_len += 4 + wpabuf_len(conf);
|
clear_len += 4 + wpabuf_len(conf);
|
||||||
if (conf2)
|
if (conf2)
|
||||||
clear_len += 4 + wpabuf_len(conf2);
|
clear_len += 4 + wpabuf_len(conf2);
|
||||||
if (auth->peer_version >= 2 && auth->send_conn_status && !ap)
|
if (auth->peer_version >= 2 && auth->send_conn_status &&
|
||||||
|
netrole == DPP_NETROLE_STA)
|
||||||
clear_len += 4;
|
clear_len += 4;
|
||||||
clear = wpabuf_alloc(clear_len);
|
clear = wpabuf_alloc(clear_len);
|
||||||
attr_len = 4 + 1 + 4 + clear_len + AES_BLOCK_SIZE;
|
attr_len = 4 + 1 + 4 + clear_len + AES_BLOCK_SIZE;
|
||||||
|
@ -5131,7 +5141,8 @@ skip_e_nonce:
|
||||||
"DPP: Second Config Object available, but peer does not support more than one");
|
"DPP: Second Config Object available, but peer does not support more than one");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auth->peer_version >= 2 && auth->send_conn_status && !ap) {
|
if (auth->peer_version >= 2 && auth->send_conn_status &&
|
||||||
|
netrole == DPP_NETROLE_STA) {
|
||||||
wpa_printf(MSG_DEBUG, "DPP: sendConnStatus");
|
wpa_printf(MSG_DEBUG, "DPP: sendConnStatus");
|
||||||
wpabuf_put_le16(clear, DPP_ATTR_SEND_CONN_STATUS);
|
wpabuf_put_le16(clear, DPP_ATTR_SEND_CONN_STATUS);
|
||||||
wpabuf_put_le16(clear, 0);
|
wpabuf_put_le16(clear, 0);
|
||||||
|
@ -5205,7 +5216,7 @@ dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start,
|
||||||
size_t unwrapped_len = 0;
|
size_t unwrapped_len = 0;
|
||||||
struct wpabuf *resp = NULL;
|
struct wpabuf *resp = NULL;
|
||||||
struct json_token *root = NULL, *token;
|
struct json_token *root = NULL, *token;
|
||||||
int ap;
|
enum dpp_netrole netrole;
|
||||||
|
|
||||||
#ifdef CONFIG_TESTING_OPTIONS
|
#ifdef CONFIG_TESTING_OPTIONS
|
||||||
if (dpp_test == DPP_TEST_STOP_AT_CONF_REQ) {
|
if (dpp_test == DPP_TEST_STOP_AT_CONF_REQ) {
|
||||||
|
@ -5303,9 +5314,9 @@ dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start,
|
||||||
}
|
}
|
||||||
wpa_printf(MSG_DEBUG, "DPP: netRole = '%s'", token->string);
|
wpa_printf(MSG_DEBUG, "DPP: netRole = '%s'", token->string);
|
||||||
if (os_strcmp(token->string, "sta") == 0) {
|
if (os_strcmp(token->string, "sta") == 0) {
|
||||||
ap = 0;
|
netrole = DPP_NETROLE_STA;
|
||||||
} else if (os_strcmp(token->string, "ap") == 0) {
|
} else if (os_strcmp(token->string, "ap") == 0) {
|
||||||
ap = 1;
|
netrole = DPP_NETROLE_AP;
|
||||||
} else {
|
} else {
|
||||||
wpa_printf(MSG_DEBUG, "DPP: Unsupported netRole '%s'",
|
wpa_printf(MSG_DEBUG, "DPP: Unsupported netRole '%s'",
|
||||||
token->string);
|
token->string);
|
||||||
|
@ -5333,7 +5344,7 @@ dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = dpp_build_conf_resp(auth, e_nonce, e_nonce_len, ap);
|
resp = dpp_build_conf_resp(auth, e_nonce, e_nonce_len, netrole);
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
json_free(root);
|
json_free(root);
|
||||||
|
|
|
@ -437,7 +437,8 @@ dpp_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr,
|
||||||
struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
|
struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
|
||||||
const char *json);
|
const char *json);
|
||||||
struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth,
|
struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth,
|
||||||
const char *name, int netrole_ap,
|
const char *name,
|
||||||
|
enum dpp_netrole netrole,
|
||||||
const char *mud_url, int *opclasses);
|
const char *mud_url, int *opclasses);
|
||||||
int dpp_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr,
|
int dpp_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr,
|
||||||
const u8 *attr_start, size_t attr_len);
|
const u8 *attr_start, size_t attr_len);
|
||||||
|
|
|
@ -678,7 +678,10 @@ int wpas_dpp_auth_init(struct wpa_supplicant *wpa_s, const char *cmd)
|
||||||
pos = os_strstr(cmd, " netrole=");
|
pos = os_strstr(cmd, " netrole=");
|
||||||
if (pos) {
|
if (pos) {
|
||||||
pos += 9;
|
pos += 9;
|
||||||
wpa_s->dpp_netrole_ap = os_strncmp(pos, "ap", 2) == 0;
|
if (os_strncmp(pos, "ap", 2) == 0)
|
||||||
|
wpa_s->dpp_netrole = DPP_NETROLE_AP;
|
||||||
|
else
|
||||||
|
wpa_s->dpp_netrole = DPP_NETROLE_STA;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = os_strstr(cmd, " neg_freq=");
|
pos = os_strstr(cmd, " neg_freq=");
|
||||||
|
@ -830,7 +833,10 @@ int wpas_dpp_listen(struct wpa_supplicant *wpa_s, const char *cmd)
|
||||||
wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
|
wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
|
||||||
DPP_CAPAB_ENROLLEE;
|
DPP_CAPAB_ENROLLEE;
|
||||||
wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
|
wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
|
||||||
wpa_s->dpp_netrole_ap = os_strstr(cmd, " netrole=ap") != NULL;
|
if (os_strstr(cmd, " netrole=ap"))
|
||||||
|
wpa_s->dpp_netrole = DPP_NETROLE_AP;
|
||||||
|
else
|
||||||
|
wpa_s->dpp_netrole = DPP_NETROLE_STA;
|
||||||
if (wpa_s->dpp_listen_freq == (unsigned int) freq) {
|
if (wpa_s->dpp_listen_freq == (unsigned int) freq) {
|
||||||
wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz",
|
wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz",
|
||||||
freq);
|
freq);
|
||||||
|
@ -1296,7 +1302,7 @@ static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
|
||||||
|
|
||||||
supp_op_classes = wpas_supp_op_classes(wpa_s);
|
supp_op_classes = wpas_supp_op_classes(wpa_s);
|
||||||
buf = dpp_build_conf_req_helper(auth, wpa_s->conf->dpp_name,
|
buf = dpp_build_conf_req_helper(auth, wpa_s->conf->dpp_name,
|
||||||
wpa_s->dpp_netrole_ap,
|
wpa_s->dpp_netrole,
|
||||||
wpa_s->conf->dpp_mud_url,
|
wpa_s->conf->dpp_mud_url,
|
||||||
supp_op_classes);
|
supp_op_classes);
|
||||||
os_free(supp_op_classes);
|
os_free(supp_op_classes);
|
||||||
|
|
|
@ -1230,7 +1230,7 @@ struct wpa_supplicant {
|
||||||
unsigned int dpp_listen_freq;
|
unsigned int dpp_listen_freq;
|
||||||
u8 dpp_allowed_roles;
|
u8 dpp_allowed_roles;
|
||||||
int dpp_qr_mutual;
|
int dpp_qr_mutual;
|
||||||
int dpp_netrole_ap;
|
int dpp_netrole;
|
||||||
int dpp_auth_ok_on_ack;
|
int dpp_auth_ok_on_ack;
|
||||||
int dpp_in_response_listen;
|
int dpp_in_response_listen;
|
||||||
int dpp_gas_client;
|
int dpp_gas_client;
|
||||||
|
|
Loading…
Reference in a new issue