common: Simplify and avoid confusing defragmentation API

Three functions were provided for defragmentation. First
ieee802_11_defrag(), ieee802_11_defrag_mle() and then
ieee802_11_defrag_data() which would do the actual job. With
ieee802_11_defrag() picking the member in the elements struct for an
EID. The problem with this is, that for the Multi-Link element, there
are multiple entries in the elems struct depending on its type. As such,
remove the intermediate function and simply pass the correct members
directly.

Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
Signed-off-by: Andrei Otcheretianski <andrei.otcheretianski@intel.com>
This commit is contained in:
Benjamin Berg 2023-11-21 01:51:18 +02:00 committed by Jouni Malinen
parent 0f7d15dd38
commit b3aafd5a87
13 changed files with 33 additions and 127 deletions

View file

@ -158,7 +158,7 @@ static int hostapd_update_sta_links_status(struct hostapd_data *hapd,
return -1; return -1;
} }
mlebuf = ieee802_11_defrag_mle(&elems, MULTI_LINK_CONTROL_TYPE_BASIC); mlebuf = ieee802_11_defrag(elems.basic_mle, elems.basic_mle_len, true);
if (!mlebuf) { if (!mlebuf) {
wpa_printf(MSG_ERROR, wpa_printf(MSG_ERROR,
"MLO: Basic Multi-Link element not found in (Re)Association Response frame"); "MLO: Basic Multi-Link element not found in (Re)Association Response frame");

View file

@ -2520,8 +2520,8 @@ static int pasn_wd_handle_fils(struct hostapd_data *hapd, struct sta_info *sta,
FILS_SESSION_LEN); FILS_SESSION_LEN);
os_memcpy(fils->session, elems.fils_session, FILS_SESSION_LEN); os_memcpy(fils->session, elems.fils_session, FILS_SESSION_LEN);
fils_wd = ieee802_11_defrag(&elems, WLAN_EID_EXTENSION, fils_wd = ieee802_11_defrag(elems.wrapped_data, elems.wrapped_data_len,
WLAN_EID_EXT_WRAPPED_DATA); true);
if (!fils_wd) { if (!fils_wd) {
wpa_printf(MSG_DEBUG, "PASN: FILS: Missing wrapped data"); wpa_printf(MSG_DEBUG, "PASN: FILS: Missing wrapped data");
@ -2690,8 +2690,8 @@ static void hapd_pasn_update_params(struct hostapd_data *hapd,
return; return;
} }
if (pasn_params.wrapped_data_format != WPA_PASN_WRAPPED_DATA_NO) { if (pasn_params.wrapped_data_format != WPA_PASN_WRAPPED_DATA_NO) {
wrapped_data = ieee802_11_defrag(&elems, WLAN_EID_EXTENSION, wrapped_data = ieee802_11_defrag(elems.wrapped_data,
WLAN_EID_EXT_WRAPPED_DATA); elems.wrapped_data_len, true);
if (!wrapped_data) { if (!wrapped_data) {
wpa_printf(MSG_DEBUG, "PASN: Missing wrapped data"); wpa_printf(MSG_DEBUG, "PASN: Missing wrapped data");
return; return;
@ -4401,7 +4401,7 @@ static void ieee80211_ml_process_link(struct hostapd_data *hapd,
goto out; goto out;
} }
mlbuf = ieee802_11_defrag_mle(&elems, MULTI_LINK_CONTROL_TYPE_BASIC); mlbuf = ieee802_11_defrag(elems.basic_mle, elems.basic_mle_len, true);
if (!mlbuf) if (!mlbuf)
goto out; goto out;

View file

@ -919,7 +919,7 @@ u16 hostapd_process_ml_assoc_req(struct hostapd_data *hapd,
int ret = -1; int ret = -1;
u16 ml_control; u16 ml_control;
mlbuf = ieee802_11_defrag_mle(elems, MULTI_LINK_CONTROL_TYPE_BASIC); mlbuf = ieee802_11_defrag(elems->basic_mle, elems->basic_mle_len, true);
if (!mlbuf) if (!mlbuf)
return WLAN_STATUS_SUCCESS; return WLAN_STATUS_SUCCESS;

View file

@ -3201,8 +3201,7 @@ enum oper_chan_width op_class_to_ch_width(u8 op_class)
} }
struct wpabuf * ieee802_11_defrag_data(const u8 *data, size_t len, struct wpabuf * ieee802_11_defrag(const u8 *data, size_t len, bool ext_elem)
bool ext_elem)
{ {
struct wpabuf *buf; struct wpabuf *buf;
const u8 *pos, *end = data + len; const u8 *pos, *end = data + len;
@ -3242,44 +3241,6 @@ struct wpabuf * ieee802_11_defrag_data(const u8 *data, size_t len,
} }
struct wpabuf * ieee802_11_defrag(struct ieee802_11_elems *elems,
u8 eid, u8 eid_ext)
{
const u8 *data;
size_t len;
/*
* TODO: Defragmentation mechanism can be supported for all IEs. For now
* handle only those that are used (or use ieee802_11_defrag_data()).
*/
switch (eid) {
case WLAN_EID_EXTENSION:
switch (eid_ext) {
case WLAN_EID_EXT_FILS_HLP_CONTAINER:
data = elems->fils_hlp;
len = elems->fils_hlp_len;
break;
case WLAN_EID_EXT_WRAPPED_DATA:
data = elems->wrapped_data;
len = elems->wrapped_data_len;
break;
default:
wpa_printf(MSG_DEBUG,
"Defragmentation not supported. eid_ext=%u",
eid_ext);
return NULL;
}
break;
default:
wpa_printf(MSG_DEBUG,
"Defragmentation not supported. eid=%u", eid);
return NULL;
}
return ieee802_11_defrag_data(data, len, true);
}
const u8 * get_ml_ie(const u8 *ies, size_t len, u8 type) const u8 * get_ml_ie(const u8 *ies, size_t len, u8 type)
{ {
const struct element *elem; const struct element *elem;
@ -3314,40 +3275,3 @@ const u8 * get_basic_mle_mld_addr(const u8 *buf, size_t len)
return &buf[mld_addr_pos]; return &buf[mld_addr_pos];
} }
struct wpabuf * ieee802_11_defrag_mle(struct ieee802_11_elems *elems, u8 type)
{
const u8 *data;
size_t len;
switch (type) {
case MULTI_LINK_CONTROL_TYPE_BASIC:
data = elems->basic_mle;
len = elems->basic_mle_len;
break;
case MULTI_LINK_CONTROL_TYPE_PROBE_REQ:
data = elems->probe_req_mle;
len = elems->probe_req_mle_len;
break;
case MULTI_LINK_CONTROL_TYPE_RECONF:
data = elems->reconf_mle;
len = elems->reconf_mle_len;
break;
case MULTI_LINK_CONTROL_TYPE_TDLS:
data = elems->tdls_mle;
len = elems->tdls_mle_len;
break;
case MULTI_LINK_CONTROL_TYPE_PRIOR_ACCESS:
data = elems->prior_access_mle;
len = elems->prior_access_mle_len;
break;
default:
wpa_printf(MSG_DEBUG,
"Defragmentation not supported for Multi-Link element type=%u",
type);
return NULL;
}
return ieee802_11_defrag_data(data, len, true);
}

View file

@ -350,11 +350,7 @@ void hostapd_encode_edmg_chan(int edmg_enable, u8 edmg_channel,
int ieee802_edmg_is_allowed(struct ieee80211_edmg_config allowed, int ieee802_edmg_is_allowed(struct ieee80211_edmg_config allowed,
struct ieee80211_edmg_config requested); struct ieee80211_edmg_config requested);
struct wpabuf * ieee802_11_defrag_data(const u8 *data, size_t len, struct wpabuf * ieee802_11_defrag(const u8 *data, size_t len, bool ext_elem);
bool ext_elem);
struct wpabuf * ieee802_11_defrag(struct ieee802_11_elems *elems,
u8 eid, u8 eid_ext);
struct wpabuf * ieee802_11_defrag_mle(struct ieee802_11_elems *elems, u8 type);
const u8 * get_ml_ie(const u8 *ies, size_t len, u8 type); const u8 * get_ml_ie(const u8 *ies, size_t len, u8 type);
const u8 * get_basic_mle_mld_addr(const u8 *buf, size_t len); const u8 * get_basic_mle_mld_addr(const u8 *buf, size_t len);

View file

@ -1329,8 +1329,7 @@ int wpa_ft_parse_ies(const u8 *ies, size_t ies_len, struct wpa_ft_ies *parse,
if (fte_len < 255) { if (fte_len < 255) {
res = wpa_ft_parse_fte(key_mgmt, fte, fte_len, parse); res = wpa_ft_parse_fte(key_mgmt, fte, fte_len, parse);
} else { } else {
parse->fte_buf = ieee802_11_defrag_data(fte, fte_len, parse->fte_buf = ieee802_11_defrag(fte, fte_len, false);
false);
if (!parse->fte_buf) if (!parse->fte_buf)
goto fail; goto fail;
res = wpa_ft_parse_fte(key_mgmt, res = wpa_ft_parse_fte(key_mgmt,

View file

@ -660,7 +660,8 @@ static int nl80211_update_rejected_links_info(struct driver_sta_mlo_info *mlo,
return -1; return -1;
} }
mle = ieee802_11_defrag_mle(&req_elems, MULTI_LINK_CONTROL_TYPE_BASIC); mle = ieee802_11_defrag(req_elems.basic_mle, req_elems.basic_mle_len,
true);
if (!mle) { if (!mle) {
wpa_printf(MSG_INFO, wpa_printf(MSG_INFO,
"nl80211: MLO: Basic Multi-Link element not found in Association Request"); "nl80211: MLO: Basic Multi-Link element not found in Association Request");
@ -671,7 +672,8 @@ static int nl80211_update_rejected_links_info(struct driver_sta_mlo_info *mlo,
&req_info); &req_info);
wpabuf_free(mle); wpabuf_free(mle);
mle = ieee802_11_defrag_mle(&resp_elems, MULTI_LINK_CONTROL_TYPE_BASIC); mle = ieee802_11_defrag(resp_elems.basic_mle, resp_elems.basic_mle_len,
true);
if (!mle) { if (!mle) {
wpa_printf(MSG_ERROR, wpa_printf(MSG_ERROR,
"nl80211: MLO: Basic Multi-Link element not found in Association Response"); "nl80211: MLO: Basic Multi-Link element not found in Association Response");

View file

@ -378,8 +378,8 @@ static int wpas_pasn_wd_fils_rx(struct pasn_data *pasn, struct wpabuf *wd)
return -1; return -1;
} }
fils_wd = ieee802_11_defrag(&elems, WLAN_EID_EXTENSION, fils_wd = ieee802_11_defrag(elems.wrapped_data, elems.wrapped_data_len,
WLAN_EID_EXT_WRAPPED_DATA); true);
if (!fils_wd) { if (!fils_wd) {
wpa_printf(MSG_DEBUG, wpa_printf(MSG_DEBUG,
@ -1200,9 +1200,9 @@ int wpa_pasn_auth_rx(struct pasn_data *pasn, const u8 *data, size_t len,
} }
if (pasn_params->wrapped_data_format != WPA_PASN_WRAPPED_DATA_NO) { if (pasn_params->wrapped_data_format != WPA_PASN_WRAPPED_DATA_NO) {
wrapped_data = ieee802_11_defrag(&elems, wrapped_data = ieee802_11_defrag(elems.wrapped_data,
WLAN_EID_EXTENSION, elems.wrapped_data_len,
WLAN_EID_EXT_WRAPPED_DATA); true);
if (!wrapped_data) { if (!wrapped_data) {
wpa_printf(MSG_DEBUG, "PASN: Missing wrapped data"); wpa_printf(MSG_DEBUG, "PASN: Missing wrapped data");

View file

@ -753,9 +753,8 @@ int handle_auth_pasn_1(struct pasn_data *pasn,
derive_keys = true; derive_keys = true;
if (pasn_params.wrapped_data_format != WPA_PASN_WRAPPED_DATA_NO) { if (pasn_params.wrapped_data_format != WPA_PASN_WRAPPED_DATA_NO) {
wrapped_data = ieee802_11_defrag(&elems, wrapped_data = ieee802_11_defrag(elems.wrapped_data,
WLAN_EID_EXTENSION, elems.wrapped_data_len, true);
WLAN_EID_EXT_WRAPPED_DATA);
if (!wrapped_data) { if (!wrapped_data) {
wpa_printf(MSG_DEBUG, "PASN: Missing wrapped data"); wpa_printf(MSG_DEBUG, "PASN: Missing wrapped data");
status = WLAN_STATUS_UNSPECIFIED_FAILURE; status = WLAN_STATUS_UNSPECIFIED_FAILURE;
@ -979,9 +978,9 @@ int handle_auth_pasn_3(struct pasn_data *pasn, const u8 *own_addr,
} }
if (pasn_params.wrapped_data_format != WPA_PASN_WRAPPED_DATA_NO) { if (pasn_params.wrapped_data_format != WPA_PASN_WRAPPED_DATA_NO) {
wrapped_data = ieee802_11_defrag(&elems, wrapped_data = ieee802_11_defrag(elems.wrapped_data,
WLAN_EID_EXTENSION, elems.wrapped_data_len,
WLAN_EID_EXT_WRAPPED_DATA); true);
if (!wrapped_data) { if (!wrapped_data) {
wpa_printf(MSG_DEBUG, "PASN: Missing wrapped data"); wpa_printf(MSG_DEBUG, "PASN: Missing wrapped data");

View file

@ -390,7 +390,7 @@ static void parse_basic_ml_elems(struct ieee802_11_elems *elems, bool ap,
{ {
struct wpabuf *mlbuf; struct wpabuf *mlbuf;
mlbuf = ieee802_11_defrag_mle(elems, MULTI_LINK_CONTROL_TYPE_BASIC); mlbuf = ieee802_11_defrag(elems->basic_mle, elems->basic_mle_len, true);
if (mlbuf) { if (mlbuf) {
parse_basic_ml(wpabuf_head(mlbuf), wpabuf_len(mlbuf), ap, sta, parse_basic_ml(wpabuf_head(mlbuf), wpabuf_len(mlbuf), ap, sta,
fields_len); fields_len);

View file

@ -1497,24 +1497,6 @@ int wpa_bss_ext_capab(const struct wpa_bss *bss, unsigned int capab)
} }
/**
* wpa_bss_defrag_mle - Get a buffer holding a de-fragmented ML element
* @bss: BSS table entry
* @type: ML control type
*/
struct wpabuf * wpa_bss_defrag_mle(const struct wpa_bss *bss, u8 type)
{
struct ieee802_11_elems elems;
const u8 *pos = wpa_bss_ie_ptr(bss);
size_t len = bss->ie_len;
if (ieee802_11_parse_elems(pos, len, &elems, 1) == ParseFailed)
return NULL;
return ieee802_11_defrag_mle(&elems, type);
}
static void static void
wpa_bss_parse_ml_rnr_ap_info(struct wpa_supplicant *wpa_s, wpa_bss_parse_ml_rnr_ap_info(struct wpa_supplicant *wpa_s,
struct wpa_bss *bss, u8 mbssid_idx, struct wpa_bss *bss, u8 mbssid_idx,
@ -1634,7 +1616,7 @@ int wpa_bss_parse_basic_ml_element(struct wpa_supplicant *wpa_s,
return ret; return ret;
} }
mlbuf = ieee802_11_defrag_mle(&elems, MULTI_LINK_CONTROL_TYPE_BASIC); mlbuf = ieee802_11_defrag(elems.basic_mle, elems.basic_mle_len, true);
if (!mlbuf) { if (!mlbuf) {
wpa_dbg(wpa_s, MSG_DEBUG, "MLD: No Multi-Link element"); wpa_dbg(wpa_s, MSG_DEBUG, "MLD: No Multi-Link element");
return ret; return ret;
@ -1770,7 +1752,7 @@ u16 wpa_bss_parse_reconf_ml_element(struct wpa_supplicant *wpa_s,
if (!elems.reconf_mle || !elems.reconf_mle_len) if (!elems.reconf_mle || !elems.reconf_mle_len)
return 0; return 0;
mlbuf = ieee802_11_defrag_mle(&elems, MULTI_LINK_CONTROL_TYPE_RECONF); mlbuf = ieee802_11_defrag(elems.reconf_mle, elems.reconf_mle_len, true);
if (!mlbuf) if (!mlbuf)
return 0; return 0;

View file

@ -213,7 +213,6 @@ void calculate_update_time(const struct os_reltime *fetch_time,
unsigned int age_ms, unsigned int age_ms,
struct os_reltime *update_time); struct os_reltime *update_time);
struct wpabuf * wpa_bss_defrag_mle(const struct wpa_bss *bss, u8 type);
int wpa_bss_parse_basic_ml_element(struct wpa_supplicant *wpa_s, int wpa_bss_parse_basic_ml_element(struct wpa_supplicant *wpa_s,
struct wpa_bss *bss, struct wpa_bss *bss,
u8 *ap_mld_addr, u8 *ap_mld_addr,

View file

@ -485,6 +485,7 @@ static bool wpas_ml_element(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
u8 ml_ie_len; u8 ml_ie_len;
const struct ieee80211_eht_ml *eht_ml; const struct ieee80211_eht_ml *eht_ml;
const struct eht_ml_basic_common_info *ml_basic_common_info; const struct eht_ml_basic_common_info *ml_basic_common_info;
struct ieee802_11_elems elems;
u8 i; u8 i;
const u16 control = const u16 control =
host_to_le16(MULTI_LINK_CONTROL_TYPE_BASIC | host_to_le16(MULTI_LINK_CONTROL_TYPE_BASIC |
@ -497,7 +498,11 @@ static bool wpas_ml_element(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
if (!(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO)) if (!(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO))
return false; return false;
mlbuf = wpa_bss_defrag_mle(bss, MULTI_LINK_CONTROL_TYPE_BASIC); if (ieee802_11_parse_elems(wpa_bss_ie_ptr(bss),
bss->ie_len, &elems, 1) == ParseFailed)
return false;
mlbuf = ieee802_11_defrag(elems.basic_mle, elems.basic_mle_len, true);
if (!mlbuf) { if (!mlbuf) {
wpa_dbg(wpa_s, MSG_DEBUG, "MLD: No ML element"); wpa_dbg(wpa_s, MSG_DEBUG, "MLD: No ML element");
return false; return false;