DPP: Move GAS encapsulation into dpp_build_conf_req()
Avoid duplicated code in each user of dpp_build_conf_req() by moving the common encapsulation case into this helper function. Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
This commit is contained in:
parent
be609c6fc6
commit
bd23daa8e6
3 changed files with 58 additions and 50 deletions
|
@ -755,7 +755,7 @@ fail2:
|
||||||
static void hostapd_dpp_start_gas_client(struct hostapd_data *hapd)
|
static void hostapd_dpp_start_gas_client(struct hostapd_data *hapd)
|
||||||
{
|
{
|
||||||
struct dpp_authentication *auth = hapd->dpp_auth;
|
struct dpp_authentication *auth = hapd->dpp_auth;
|
||||||
struct wpabuf *buf, *conf_req;
|
struct wpabuf *buf;
|
||||||
char json[100];
|
char json[100];
|
||||||
int res;
|
int res;
|
||||||
int netrole_ap = 1;
|
int netrole_ap = 1;
|
||||||
|
@ -767,34 +767,13 @@ static void hostapd_dpp_start_gas_client(struct hostapd_data *hapd)
|
||||||
netrole_ap ? "ap" : "sta");
|
netrole_ap ? "ap" : "sta");
|
||||||
wpa_printf(MSG_DEBUG, "DPP: GAS Config Attributes: %s", json);
|
wpa_printf(MSG_DEBUG, "DPP: GAS Config Attributes: %s", json);
|
||||||
|
|
||||||
conf_req = dpp_build_conf_req(auth, json);
|
buf = dpp_build_conf_req(auth, json);
|
||||||
if (!conf_req) {
|
if (!buf) {
|
||||||
wpa_printf(MSG_DEBUG,
|
wpa_printf(MSG_DEBUG,
|
||||||
"DPP: No configuration request data available");
|
"DPP: No configuration request data available");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req));
|
|
||||||
if (!buf) {
|
|
||||||
wpabuf_free(conf_req);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Advertisement Protocol IE */
|
|
||||||
wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO);
|
|
||||||
wpabuf_put_u8(buf, 8); /* Length */
|
|
||||||
wpabuf_put_u8(buf, 0x7f);
|
|
||||||
wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
|
|
||||||
wpabuf_put_u8(buf, 5);
|
|
||||||
wpabuf_put_be24(buf, OUI_WFA);
|
|
||||||
wpabuf_put_u8(buf, DPP_OUI_TYPE);
|
|
||||||
wpabuf_put_u8(buf, 0x01);
|
|
||||||
|
|
||||||
/* GAS Query */
|
|
||||||
wpabuf_put_le16(buf, wpabuf_len(conf_req));
|
|
||||||
wpabuf_put_buf(buf, conf_req);
|
|
||||||
wpabuf_free(conf_req);
|
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
|
wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
|
||||||
MAC2STR(auth->peer_mac_addr), auth->curr_freq);
|
MAC2STR(auth->peer_mac_addr), auth->curr_freq);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "common/ieee802_11_common.h"
|
#include "common/ieee802_11_common.h"
|
||||||
#include "common/ieee802_11_defs.h"
|
#include "common/ieee802_11_defs.h"
|
||||||
#include "common/wpa_ctrl.h"
|
#include "common/wpa_ctrl.h"
|
||||||
|
#include "common/gas.h"
|
||||||
#include "crypto/crypto.h"
|
#include "crypto/crypto.h"
|
||||||
#include "crypto/random.h"
|
#include "crypto/random.h"
|
||||||
#include "crypto/aes.h"
|
#include "crypto/aes.h"
|
||||||
|
@ -2228,8 +2229,8 @@ fail:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
|
static struct wpabuf * dpp_build_conf_req_attr(struct dpp_authentication *auth,
|
||||||
const char *json)
|
const char *json)
|
||||||
{
|
{
|
||||||
size_t nonce_len;
|
size_t nonce_len;
|
||||||
size_t json_len, clear_len;
|
size_t json_len, clear_len;
|
||||||
|
@ -2333,6 +2334,55 @@ fail:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void dpp_write_adv_proto(struct wpabuf *buf)
|
||||||
|
{
|
||||||
|
/* Advertisement Protocol IE */
|
||||||
|
wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO);
|
||||||
|
wpabuf_put_u8(buf, 8); /* Length */
|
||||||
|
wpabuf_put_u8(buf, 0x7f);
|
||||||
|
wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
|
||||||
|
wpabuf_put_u8(buf, 5);
|
||||||
|
wpabuf_put_be24(buf, OUI_WFA);
|
||||||
|
wpabuf_put_u8(buf, DPP_OUI_TYPE);
|
||||||
|
wpabuf_put_u8(buf, 0x01);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void dpp_write_gas_query(struct wpabuf *buf, struct wpabuf *query)
|
||||||
|
{
|
||||||
|
/* GAS Query */
|
||||||
|
wpabuf_put_le16(buf, wpabuf_len(query));
|
||||||
|
wpabuf_put_buf(buf, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
|
||||||
|
const char *json)
|
||||||
|
{
|
||||||
|
struct wpabuf *buf, *conf_req;
|
||||||
|
|
||||||
|
conf_req = dpp_build_conf_req_attr(auth, json);
|
||||||
|
if (!conf_req) {
|
||||||
|
wpa_printf(MSG_DEBUG,
|
||||||
|
"DPP: No configuration request data available");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req));
|
||||||
|
if (!buf) {
|
||||||
|
wpabuf_free(conf_req);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dpp_write_adv_proto(buf);
|
||||||
|
dpp_write_gas_query(buf, conf_req);
|
||||||
|
wpabuf_free(conf_req);
|
||||||
|
wpa_hexdump_buf(MSG_MSGDUMP, "DPP: GAS Config Request", buf);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void dpp_auth_success(struct dpp_authentication *auth)
|
static void dpp_auth_success(struct dpp_authentication *auth)
|
||||||
{
|
{
|
||||||
wpa_printf(MSG_DEBUG,
|
wpa_printf(MSG_DEBUG,
|
||||||
|
|
|
@ -1066,7 +1066,7 @@ fail2:
|
||||||
static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
|
static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
|
||||||
{
|
{
|
||||||
struct dpp_authentication *auth = wpa_s->dpp_auth;
|
struct dpp_authentication *auth = wpa_s->dpp_auth;
|
||||||
struct wpabuf *buf, *conf_req;
|
struct wpabuf *buf;
|
||||||
char json[100];
|
char json[100];
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
|
@ -1087,34 +1087,13 @@ static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
|
||||||
offchannel_send_action_done(wpa_s);
|
offchannel_send_action_done(wpa_s);
|
||||||
wpas_dpp_listen_stop(wpa_s);
|
wpas_dpp_listen_stop(wpa_s);
|
||||||
|
|
||||||
conf_req = dpp_build_conf_req(auth, json);
|
buf = dpp_build_conf_req(auth, json);
|
||||||
if (!conf_req) {
|
if (!buf) {
|
||||||
wpa_printf(MSG_DEBUG,
|
wpa_printf(MSG_DEBUG,
|
||||||
"DPP: No configuration request data available");
|
"DPP: No configuration request data available");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req));
|
|
||||||
if (!buf) {
|
|
||||||
wpabuf_free(conf_req);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Advertisement Protocol IE */
|
|
||||||
wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO);
|
|
||||||
wpabuf_put_u8(buf, 8); /* Length */
|
|
||||||
wpabuf_put_u8(buf, 0x7f);
|
|
||||||
wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
|
|
||||||
wpabuf_put_u8(buf, 5);
|
|
||||||
wpabuf_put_be24(buf, OUI_WFA);
|
|
||||||
wpabuf_put_u8(buf, DPP_OUI_TYPE);
|
|
||||||
wpabuf_put_u8(buf, 0x01);
|
|
||||||
|
|
||||||
/* GAS Query */
|
|
||||||
wpabuf_put_le16(buf, wpabuf_len(conf_req));
|
|
||||||
wpabuf_put_buf(buf, conf_req);
|
|
||||||
wpabuf_free(conf_req);
|
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
|
wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
|
||||||
MAC2STR(auth->peer_mac_addr), auth->curr_freq);
|
MAC2STR(auth->peer_mac_addr), auth->curr_freq);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue