From 8f8c423a51edc82a7da2cf494bb0890ddedaf379 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Thu, 19 Sep 2019 00:00:46 +0300 Subject: [PATCH] DPP: Add bandSupport JSON array into config request Indicate supported global operating classes when wpa_supplicant is operating as an Enrollee. Signed-off-by: Jouni Malinen --- src/ap/dpp_hostapd.c | 2 +- src/common/dpp.c | 14 +++++++++++--- src/common/dpp.h | 2 +- wpa_supplicant/dpp_supplicant.c | 6 +++++- wpa_supplicant/op_classes.c | 27 ++++++++++++++++++++++++--- wpa_supplicant/wpa_supplicant_i.h | 1 + 6 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/ap/dpp_hostapd.c b/src/ap/dpp_hostapd.c index 91bbb0186..effcc7ab1 100644 --- a/src/ap/dpp_hostapd.c +++ b/src/ap/dpp_hostapd.c @@ -768,7 +768,7 @@ static void hostapd_dpp_start_gas_client(struct hostapd_data *hapd) int res; buf = dpp_build_conf_req_helper(auth, hapd->conf->dpp_name, 1, - hapd->conf->dpp_mud_url); + hapd->conf->dpp_mud_url, NULL); if (!buf) { wpa_printf(MSG_DEBUG, "DPP: No configuration request data available"); diff --git a/src/common/dpp.c b/src/common/dpp.c index 6d6fbfbae..5b8d6a547 100644 --- a/src/common/dpp.c +++ b/src/common/dpp.c @@ -2514,7 +2514,7 @@ struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth, struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth, const char *name, int netrole_ap, - const char *mud_url) + const char *mud_url, int *opclasses) { size_t len, nlen; const char *tech = "infra"; @@ -2539,7 +2539,7 @@ struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth, return NULL; json_escape_string(nbuf, nlen, dpp_name, len); - len = 100 + os_strlen(nbuf); + len = 100 + os_strlen(nbuf) + int_array_len(opclasses) * 4; if (mud_url && mud_url[0]) len += 10 + os_strlen(mud_url); json = wpabuf_alloc(len); @@ -2555,6 +2555,14 @@ struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth, nbuf, tech, netrole_ap ? "ap" : "sta"); if (mud_url && mud_url[0]) wpabuf_printf(json, ",\"mudurl\":\"%s\"", mud_url); + if (opclasses) { + int i; + + wpabuf_put_str(json, ",\"bandSupport\":["); + for (i = 0; opclasses[i]; i++) + wpabuf_printf(json, "%s%u", i ? "," : "", opclasses[i]); + wpabuf_put_str(json, "]"); + } wpabuf_put_str(json, "}"); os_free(nbuf); @@ -9253,7 +9261,7 @@ static void dpp_controller_start_gas_client(struct dpp_connection *conn) struct wpabuf *buf; int netrole_ap = 0; /* TODO: make this configurable */ - buf = dpp_build_conf_req_helper(auth, "Test", netrole_ap, NULL); + buf = dpp_build_conf_req_helper(auth, "Test", netrole_ap, NULL, NULL); if (!buf) { wpa_printf(MSG_DEBUG, "DPP: No configuration request data available"); diff --git a/src/common/dpp.h b/src/common/dpp.h index 9870e3d35..21b58ddcc 100644 --- a/src/common/dpp.h +++ b/src/common/dpp.h @@ -422,7 +422,7 @@ struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth, const char *json); struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth, const char *name, int netrole_ap, - const char *mud_url); + const char *mud_url, int *opclasses); int dpp_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr, const u8 *attr_start, size_t attr_len); int dpp_notify_new_qr_code(struct dpp_authentication *auth, diff --git a/wpa_supplicant/dpp_supplicant.c b/wpa_supplicant/dpp_supplicant.c index 29a50f3b0..b4341f187 100644 --- a/wpa_supplicant/dpp_supplicant.c +++ b/wpa_supplicant/dpp_supplicant.c @@ -1252,14 +1252,18 @@ static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s) struct dpp_authentication *auth = wpa_s->dpp_auth; struct wpabuf *buf; int res; + int *supp_op_classes; wpa_s->dpp_gas_client = 1; offchannel_send_action_done(wpa_s); wpas_dpp_listen_stop(wpa_s); + supp_op_classes = wpas_supp_op_classes(wpa_s); buf = dpp_build_conf_req_helper(auth, wpa_s->conf->dpp_name, wpa_s->dpp_netrole_ap, - wpa_s->conf->dpp_mud_url); + wpa_s->conf->dpp_mud_url, + supp_op_classes); + os_free(supp_op_classes); if (!buf) { wpa_printf(MSG_DEBUG, "DPP: No configuration request data available"); diff --git a/wpa_supplicant/op_classes.c b/wpa_supplicant/op_classes.c index 6a85af4ea..5c103ec7e 100644 --- a/wpa_supplicant/op_classes.c +++ b/wpa_supplicant/op_classes.c @@ -225,7 +225,7 @@ static int wpas_op_class_supported(struct wpa_supplicant *wpa_s, /* If we are configured to disable certain things, take that into * account here. */ - if (ssid->freq_list && ssid->freq_list[0]) { + if (ssid && ssid->freq_list && ssid->freq_list[0]) { for (z = 0; ; z++) { int f = ssid->freq_list[z]; @@ -248,7 +248,7 @@ static int wpas_op_class_supported(struct wpa_supplicant *wpa_s, return 0; #ifdef CONFIG_HT_OVERRIDES - if (ssid->disable_ht) { + if (ssid && ssid->disable_ht) { switch (op_class->op_class) { case 83: case 84: @@ -272,7 +272,7 @@ static int wpas_op_class_supported(struct wpa_supplicant *wpa_s, #endif /* CONFIG_HT_OVERRIDES */ #ifdef CONFIG_VHT_OVERRIDES - if (ssid->disable_vht) { + if (ssid && ssid->disable_vht) { if (op_class->op_class >= 128 && op_class->op_class <= 130) { /* Disable >= 80 MHz channels if VHT is disabled */ return 0; @@ -385,3 +385,24 @@ size_t wpas_supp_op_class_ie(struct wpa_supplicant *wpa_s, wpabuf_free(buf); return res; } + + +int * wpas_supp_op_classes(struct wpa_supplicant *wpa_s) +{ + int op; + unsigned int pos, max_num = 0; + int *classes; + + for (op = 0; global_op_class[op].op_class; op++) + max_num++; + classes = os_zalloc((max_num + 1) * sizeof(int)); + if (!classes) + return NULL; + + for (op = 0, pos = 0; global_op_class[op].op_class; op++) { + if (wpas_op_class_supported(wpa_s, NULL, &global_op_class[op])) + classes[pos++] = global_op_class[op].op_class; + } + + return classes; +} diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index 872c19c84..63f2f5960 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -1424,6 +1424,7 @@ enum chan_allowed verify_channel(struct hostapd_hw_modes *mode, u8 channel, size_t wpas_supp_op_class_ie(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, int freq, u8 *pos, size_t len); +int * wpas_supp_op_classes(struct wpa_supplicant *wpa_s); int wpas_enable_mac_addr_randomization(struct wpa_supplicant *wpa_s, unsigned int type, const u8 *addr,