AP: Share a common helper function for determining length of TPE elements

There is no need to maintain three copies of almost identical code.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2023-12-22 20:54:19 +02:00
parent 924f328df4
commit 24baffc8b6

View file

@ -563,6 +563,45 @@ static u8 * hostapd_eid_mbssid_config(struct hostapd_data *hapd, u8 *eid,
} }
static size_t he_elem_len(struct hostapd_data *hapd)
{
size_t len = 0;
#ifdef CONFIG_IEEE80211AX
if (!hapd->iconf->ieee80211ax || hapd->conf->disable_11ax)
return len;
len += 3 + sizeof(struct ieee80211_he_capabilities) +
3 + sizeof(struct ieee80211_he_operation) +
3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
3 + sizeof(struct ieee80211_spatial_reuse);
if (is_6ghz_op_class(hapd->iconf->op_class)) {
len += sizeof(struct ieee80211_he_6ghz_oper_info) +
3 + sizeof(struct ieee80211_he_6ghz_band_cap);
/* An additional Transmit Power Envelope element for
* subordinate client */
if (hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_INDOOR ||
hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_INDOOR_SP)
len += 4;
/* An additional Transmit Power Envelope element for
* default client with unit interpretation of regulatory
* client EIRP */
if (hapd->iconf->reg_def_cli_eirp != -1 &&
(hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_SP ||
hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_INDOOR_SP))
len += 4;
}
#endif /* CONFIG_IEEE80211AX */
return len;
}
struct probe_resp_params { struct probe_resp_params {
const struct ieee80211_mgmt *req; const struct ieee80211_mgmt *req;
bool is_p2p; bool is_p2p;
@ -608,35 +647,7 @@ static size_t hostapd_probe_resp_elems_len(struct hostapd_data *hapd,
2 + sizeof(struct ieee80211_vht_operation); 2 + sizeof(struct ieee80211_vht_operation);
} }
#ifdef CONFIG_IEEE80211AX buflen += he_elem_len(hapd);
if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
3 + sizeof(struct ieee80211_he_operation) +
3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
3 + sizeof(struct ieee80211_spatial_reuse);
if (is_6ghz_op_class(hapd->iconf->op_class)) {
buflen += sizeof(struct ieee80211_he_6ghz_oper_info) +
3 + sizeof(struct ieee80211_he_6ghz_band_cap);
/* An additional Transmit Power Envelope element for
* subordinate client */
if (hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_INDOOR ||
hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_INDOOR_SP)
buflen += 4;
/* An additional Transmit Power Envelope element for
* default client with unit interpretation of regulatory
* client EIRP */
if (hapd->iconf->reg_def_cli_eirp != -1 &&
(hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_SP ||
hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_INDOOR_SP))
buflen += 4;
}
}
#endif /* CONFIG_IEEE80211AX */
#ifdef CONFIG_IEEE80211BE #ifdef CONFIG_IEEE80211BE
if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) { if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
@ -1938,27 +1949,9 @@ static u8 * hostapd_gen_fils_discovery(struct hostapd_data *hapd, size_t *len)
buf_len = pos - buf; buf_len = pos - buf;
total_len += buf_len; total_len += buf_len;
#ifdef CONFIG_IEEE80211AX /* he_elem_len() may return too large a value for FD frame, but that is
/* Transmit Power Envelope element(s) */ * fine here since this is used as the maximum length of the buffer. */
if (is_6ghz_op_class(hapd->iconf->op_class)) { total_len += he_elem_len(hapd);
total_len += 4;
if (hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_INDOOR ||
hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_INDOOR_SP)
total_len += 4;
/* An additional Transmit Power Envelope element for
* default client with unit interpretation of regulatory
* client EIRP */
if (hapd->iconf->reg_def_cli_eirp != -1 &&
(hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_SP ||
hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_INDOOR_SP))
total_len += 4;
}
#endif /* CONFIG_IEEE80211AX */
head = os_zalloc(total_len); head = os_zalloc(total_len);
if (!head) if (!head)
@ -2108,35 +2101,7 @@ int ieee802_11_build_ap_params(struct hostapd_data *hapd,
} }
#endif /* CONFIG_IEEE80211AC */ #endif /* CONFIG_IEEE80211AC */
#ifdef CONFIG_IEEE80211AX tail_len += he_elem_len(hapd);
if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
3 + sizeof(struct ieee80211_he_operation) +
3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
3 + sizeof(struct ieee80211_spatial_reuse);
if (is_6ghz_op_class(hapd->iconf->op_class)) {
tail_len += sizeof(struct ieee80211_he_6ghz_oper_info) +
3 + sizeof(struct ieee80211_he_6ghz_band_cap);
/* An additional Transmit Power Envelope element for
* subordinate client */
if (hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_INDOOR ||
hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_INDOOR_SP)
tail_len += 4;
/* An additional Transmit Power Envelope element for
* default client with unit interpretation of regulatory
* client EIRP */
if (hapd->iconf->reg_def_cli_eirp != -1 &&
(hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_SP ||
hapd->iconf->he_6ghz_reg_pwr_type ==
HE_REG_INFO_6GHZ_AP_TYPE_INDOOR_SP))
tail_len += 4;
}
}
#endif /* CONFIG_IEEE80211AX */
#ifdef CONFIG_IEEE80211BE #ifdef CONFIG_IEEE80211BE
if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) { if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {