[PATCH] common: put hostapd_set_freq_params() inputs into a struct

Johannes Berg johannes at sipsolutions.net
Thu Apr 23 05:55:59 PDT 2026


From: Johannes Berg <johannes.berg at intel.com>

This function prototype has grown unchecked, and really isn't
sustainable any longer. Move all the arguments into a struct.

Signed-off-by: Johannes Berg <johannes.berg at intel.com>
---
 src/ap/ap_drv_ops.c             | 59 +++++++++++++++++++++------------
 src/ap/beacon.c                 | 36 ++++++++++++--------
 src/ap/dfs.c                    | 39 ++++++++++++----------
 src/ap/hostapd.c                | 41 +++++++++++++----------
 src/common/hw_features_common.c | 29 ++++++++++------
 src/common/hw_features_common.h | 54 ++++++++++++++++++++++++------
 wpa_supplicant/mesh.c           | 40 +++++++++++-----------
 wpa_supplicant/wpa_supplicant.c | 29 +++++++++++-----
 8 files changed, 206 insertions(+), 121 deletions(-)

diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c
index 61b823abe138..dc46b599cfb1 100644
--- a/src/ap/ap_drv_ops.c
+++ b/src/ap/ap_drv_ops.c
@@ -654,18 +654,27 @@ int hostapd_set_freq(struct hostapd_data *hapd, enum hostapd_hw_mode mode,
 {
 	struct hostapd_freq_params data;
 	struct hostapd_hw_modes *cmode = hapd->iface->current_mode;
+	struct hostapd_channel_info info = {
+		.mode = mode,
+		.freq = freq,
+		.channel = channel,
+		.edmg.enabled = edmg,
+		.edmg.channel = edmg_channel,
+		.ht.enabled = ht_enabled,
+		.vht.enabled = vht_enabled,
+		.he.enabled = he_enabled,
+		.eht.enabled = eht_enabled,
+		.ht.sec_channel_offset = sec_channel_offset,
+		.oper_chwidth = oper_chwidth,
+		.center_segment0 = center_segment0,
+		.center_segment1 = center_segment1,
+		.vht.caps = cmode ? cmode->vht_capab : 0,
+		.he.cap = cmode ? &cmode->he_capab[IEEE80211_MODE_AP] : NULL,
+		.eht.cap = cmode ? &cmode->eht_capab[IEEE80211_MODE_AP] : NULL,
+		.eht.punct_bitmap = hostapd_get_punct_bitmap(hapd),
+	};
 
-	if (hostapd_set_freq_params(&data, mode, freq, channel, edmg,
-				    edmg_channel, ht_enabled,
-				    vht_enabled, he_enabled, eht_enabled,
-				    sec_channel_offset, oper_chwidth,
-				    center_segment0, center_segment1,
-				    cmode ? cmode->vht_capab : 0,
-				    cmode ?
-				    &cmode->he_capab[IEEE80211_MODE_AP] : NULL,
-				    cmode ?
-				    &cmode->eht_capab[IEEE80211_MODE_AP] :
-				    NULL, hostapd_get_punct_bitmap(hapd)))
+	if (hostapd_set_freq_params(&data, &info))
 		return -1;
 
 	if (hapd->driver == NULL)
@@ -1084,6 +1093,23 @@ int hostapd_start_dfs_cac(struct hostapd_iface *iface,
 	struct hostapd_freq_params data;
 	int res;
 	struct hostapd_hw_modes *cmode = iface->current_mode;
+	struct hostapd_channel_info info = {
+		.mode = mode,
+		.freq = freq,
+		.channel = channel,
+		.ht.enabled = ht_enabled,
+		.vht.enabled = vht_enabled,
+		.he.enabled = he_enabled,
+		.eht.enabled = eht_enabled,
+		.ht.sec_channel_offset = sec_channel_offset,
+		.oper_chwidth = oper_chwidth,
+		.center_segment0 = center_segment0,
+		.center_segment1 = center_segment1,
+		.vht.caps = cmode ? cmode->vht_capab : 0,
+		.he.cap = cmode ? &cmode->he_capab[IEEE80211_MODE_AP] : NULL,
+		.eht.cap = cmode ? &cmode->eht_capab[IEEE80211_MODE_AP] : NULL,
+		.eht.punct_bitmap = hostapd_get_punct_bitmap(hapd),
+	};
 
 	if (!hapd->driver || !hapd->driver->start_dfs_cac || !cmode)
 		return 0;
@@ -1094,16 +1120,7 @@ int hostapd_start_dfs_cac(struct hostapd_iface *iface,
 		return -1;
 	}
 
-	if (hostapd_set_freq_params(&data, mode, freq, channel, 0, 0,
-				    ht_enabled,
-				    vht_enabled, he_enabled, eht_enabled,
-				    sec_channel_offset,
-				    oper_chwidth, center_segment0,
-				    center_segment1,
-				    cmode->vht_capab,
-				    &cmode->he_capab[IEEE80211_MODE_AP],
-				    &cmode->eht_capab[IEEE80211_MODE_AP],
-				    hostapd_get_punct_bitmap(hapd))) {
+	if (hostapd_set_freq_params(&data, &info)) {
 		wpa_printf(MSG_ERROR, "Can't set freq params");
 		return -1;
 	}
diff --git a/src/ap/beacon.c b/src/ap/beacon.c
index 7e516446c60f..a7a1601c2968 100644
--- a/src/ap/beacon.c
+++ b/src/ap/beacon.c
@@ -2729,6 +2729,7 @@ static int __ieee802_11_set_beacon(struct hostapd_data *hapd)
 	bool twt_he_responder = false;
 	int res, ret = -1, i;
 	struct hostapd_hw_modes *mode;
+	struct hostapd_channel_info info;
 
 	if (!hapd->drv_priv) {
 		wpa_printf(MSG_ERROR, "Interface is disabled");
@@ -2798,20 +2799,27 @@ static int __ieee802_11_set_beacon(struct hostapd_data *hapd)
 	params.punct_bitmap = iconf->punct_bitmap;
 #endif /* CONFIG_IEEE80211BE */
 
-	if (cmode &&
-	    hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
-				    iconf->channel, iconf->enable_edmg,
-				    iconf->edmg_channel, iconf->ieee80211n,
-				    iconf->ieee80211ac, iconf->ieee80211ax,
-				    iconf->ieee80211be,
-				    iconf->secondary_channel,
-				    hostapd_get_oper_chwidth(iconf),
-				    hostapd_get_oper_centr_freq_seg0_idx(iconf),
-				    hostapd_get_oper_centr_freq_seg1_idx(iconf),
-				    cmode->vht_capab,
-				    &cmode->he_capab[IEEE80211_MODE_AP],
-				    &cmode->eht_capab[IEEE80211_MODE_AP],
-				    hostapd_get_punct_bitmap(hapd)) == 0) {
+	info = (struct hostapd_channel_info) {
+		.mode = iconf->hw_mode,
+		.freq = iface->freq,
+		.channel = iconf->channel,
+		.edmg.enabled = iconf->enable_edmg,
+		.edmg.channel = iconf->edmg_channel,
+		.ht.enabled = iconf->ieee80211n,
+		.vht.enabled = iconf->ieee80211ac,
+		.he.enabled = iconf->ieee80211ax,
+		.eht.enabled = iconf->ieee80211be,
+		.ht.sec_channel_offset = iconf->secondary_channel,
+		.oper_chwidth = hostapd_get_oper_chwidth(iconf),
+		.center_segment0 = hostapd_get_oper_centr_freq_seg0_idx(iconf),
+		.center_segment1 = hostapd_get_oper_centr_freq_seg1_idx(iconf),
+		.vht.caps = cmode ? cmode->vht_capab : 0,
+		.he.cap = cmode ? &cmode->he_capab[IEEE80211_MODE_AP] : NULL,
+		.eht.cap = cmode ? &cmode->eht_capab[IEEE80211_MODE_AP] : NULL,
+		.eht.punct_bitmap = hostapd_get_punct_bitmap(hapd),
+	};
+
+	if (cmode && hostapd_set_freq_params(&freq, &info) == 0) {
 		freq.link_id = -1;
 #ifdef CONFIG_IEEE80211BE
 		if (hapd->conf->mld_ap)
diff --git a/src/ap/dfs.c b/src/ap/dfs.c
index d72c8ddb4464..8b85a25558b4 100644
--- a/src/ap/dfs.c
+++ b/src/ap/dfs.c
@@ -983,6 +983,7 @@ static int hostapd_dfs_request_channel_switch(struct hostapd_iface *iface,
 	unsigned int i;
 	unsigned int num_err = 0;
 	u8 op_class, chan;
+	struct hostapd_channel_info info;
 
 	wpa_printf(MSG_DEBUG, "DFS will switch to a new channel %d", channel);
 	wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_NEW_CHANNEL
@@ -1012,24 +1013,28 @@ static int hostapd_dfs_request_channel_switch(struct hostapd_iface *iface,
 	if (iface->mconf)
 		ieee80211_mode = IEEE80211_MODE_MESH;
 #endif /* CONFIG_MESH */
-	err = hostapd_set_freq_params(&csa_settings.freq_params,
-				      iface->conf->hw_mode,
-				      freq, channel,
-				      iface->conf->enable_edmg,
-				      iface->conf->edmg_channel,
-				      iface->conf->ieee80211n,
-				      iface->conf->ieee80211ac,
-				      iface->conf->ieee80211ax,
-				      iface->conf->ieee80211be,
-				      secondary_channel,
-				      new_vht_oper_chwidth,
-				      oper_centr_freq_seg0_idx,
-				      oper_centr_freq_seg1_idx,
-				      cmode->vht_capab,
-				      &cmode->he_capab[ieee80211_mode],
-				      &cmode->eht_capab[ieee80211_mode],
-				      hostapd_get_punct_bitmap(iface->bss[0]));
 
+	info = (struct hostapd_channel_info) {
+		.mode = iface->conf->hw_mode,
+		.freq = freq,
+		.channel = channel,
+		.edmg.enabled = iface->conf->enable_edmg,
+		.edmg.channel = iface->conf->edmg_channel,
+		.ht.enabled = iface->conf->ieee80211n,
+		.vht.enabled = iface->conf->ieee80211ac,
+		.he.enabled = iface->conf->ieee80211ax,
+		.eht.enabled = iface->conf->ieee80211be,
+		.ht.sec_channel_offset = secondary_channel,
+		.oper_chwidth = new_vht_oper_chwidth,
+		.center_segment0 = oper_centr_freq_seg0_idx,
+		.center_segment1 = oper_centr_freq_seg1_idx,
+		.vht.caps = cmode->vht_capab,
+		.he.cap = &cmode->he_capab[ieee80211_mode],
+		.eht.cap = &cmode->eht_capab[ieee80211_mode],
+		.eht.punct_bitmap = hostapd_get_punct_bitmap(iface->bss[0]),
+	};
+
+	err = hostapd_set_freq_params(&csa_settings.freq_params, &info);
 	if (err) {
 		wpa_printf(MSG_ERROR,
 			   "DFS failed to calculate CSA freq params");
diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c
index 93112886755e..761320e80f1b 100644
--- a/src/ap/hostapd.c
+++ b/src/ap/hostapd.c
@@ -4522,23 +4522,30 @@ int hostapd_change_config_freq(struct hostapd_data *hapd,
 	mode = hapd->iface->current_mode;
 
 	/* if a pointer to old_params is provided we save previous state */
-	if (old_params &&
-	    hostapd_set_freq_params(old_params, conf->hw_mode,
-				    hostapd_hw_get_freq(hapd, conf->channel),
-				    conf->channel, conf->enable_edmg,
-				    conf->edmg_channel, conf->ieee80211n,
-				    conf->ieee80211ac, conf->ieee80211ax,
-				    conf->ieee80211be, conf->secondary_channel,
-				    hostapd_get_oper_chwidth(conf),
-				    hostapd_get_oper_centr_freq_seg0_idx(conf),
-				    hostapd_get_oper_centr_freq_seg1_idx(conf),
-				    conf->vht_capab,
-				    mode ? &mode->he_capab[IEEE80211_MODE_AP] :
-				    NULL,
-				    mode ? &mode->eht_capab[IEEE80211_MODE_AP] :
-				    NULL,
-				    hostapd_get_punct_bitmap(hapd)))
-		return -1;
+	if (old_params) {
+		struct hostapd_channel_info info = {
+			.mode = conf->hw_mode,
+			.freq = hostapd_hw_get_freq(hapd, conf->channel),
+			.channel = conf->channel,
+			.edmg.enabled = conf->enable_edmg,
+			.edmg.channel =conf->edmg_channel,
+			.ht.enabled = conf->ieee80211n,
+			.vht.enabled = conf->ieee80211ac,
+			.he.enabled = conf->ieee80211ax,
+			.eht.enabled = conf->ieee80211be,
+			.ht.sec_channel_offset = conf->secondary_channel,
+			.oper_chwidth = hostapd_get_oper_chwidth(conf),
+			.center_segment0 = hostapd_get_oper_centr_freq_seg0_idx(conf),
+			.center_segment1 = hostapd_get_oper_centr_freq_seg1_idx(conf),
+			.vht.caps = conf->vht_capab,
+			.he.cap = mode ? &mode->he_capab[IEEE80211_MODE_AP] : NULL,
+			.eht.cap = mode ? &mode->eht_capab[IEEE80211_MODE_AP] : NULL,
+			.eht.punct_bitmap = hostapd_get_punct_bitmap(hapd),
+		};
+
+		if (hostapd_set_freq_params(old_params, &info))
+			return -1;
+	}
 
 	switch (params->bandwidth) {
 	case 0:
diff --git a/src/common/hw_features_common.c b/src/common/hw_features_common.c
index e928738ee568..ea5d24300048 100644
--- a/src/common/hw_features_common.c
+++ b/src/common/hw_features_common.c
@@ -476,18 +476,25 @@ void punct_update_legacy_bw(u16 bitmap, u8 pri, enum oper_chan_width *width,
 
 
 int hostapd_set_freq_params(struct hostapd_freq_params *data,
-			    enum hostapd_hw_mode mode,
-			    int freq, int channel, int enable_edmg,
-			    u8 edmg_channel, int ht_enabled,
-			    int vht_enabled, int he_enabled,
-			    bool eht_enabled, int sec_channel_offset,
-			    enum oper_chan_width oper_chwidth,
-			    int center_segment0,
-			    int center_segment1, u32 vht_caps,
-			    struct he_capabilities *he_cap,
-			    struct eht_capabilities *eht_cap,
-			    u16 punct_bitmap)
+			    const struct hostapd_channel_info *info)
 {
+	enum hostapd_hw_mode mode = info->mode;
+	int freq = info->freq;
+	int channel = info->channel;
+	int enable_edmg = info->edmg.enabled;
+	u8 edmg_channel = info->edmg.channel;
+	int ht_enabled = info->ht.enabled;
+	int vht_enabled = info->vht.enabled;
+	int he_enabled = info->he.enabled;
+	bool eht_enabled = info->eht.enabled;
+	int sec_channel_offset = info->ht.sec_channel_offset;
+	enum oper_chan_width oper_chwidth = info->oper_chwidth;
+	int center_segment0 = info->center_segment0;
+	int center_segment1 = info->center_segment1;
+	u32 vht_caps = info->vht.caps;
+	const struct he_capabilities *he_cap = info->he.cap;
+	const struct eht_capabilities *eht_cap = info->eht.cap;
+	u16 punct_bitmap = info->eht.punct_bitmap;
 	enum oper_chan_width oper_chwidth_legacy;
 	u8 seg0_legacy, seg1_legacy;
 
diff --git a/src/common/hw_features_common.h b/src/common/hw_features_common.h
index 80e33adf2d5c..224cb4d52fb3 100644
--- a/src/common/hw_features_common.h
+++ b/src/common/hw_features_common.h
@@ -37,18 +37,50 @@ int check_40mhz_2g4(struct hostapd_hw_modes *mode,
 		    int sec_chan);
 void punct_update_legacy_bw(u16 bitmap, u8 pri_chan,
 			    enum oper_chan_width *width, u8 *seg0, u8 *seg1);
+
+/* channel information to derive freq params from */
+struct hostapd_channel_info {
+	enum hostapd_hw_mode mode;
+
+	int freq;
+	int channel;
+	enum oper_chan_width oper_chwidth;
+
+	/* EDMG */
+	struct {
+		int enabled;
+		u8 channel;
+	} edmg;
+
+	struct {
+		int enabled;
+		int sec_channel_offset;
+	} ht;
+
+	int center_segment0;
+
+	/* only valid for 80+80 */
+	int center_segment1;
+
+	struct {
+		int enabled;
+		u32 caps;
+	} vht;
+
+	struct {
+		int enabled;
+		const struct he_capabilities *cap;
+	} he;
+
+	struct {
+		int enabled;
+		const struct eht_capabilities *cap;
+		u16 punct_bitmap;
+	} eht;
+};
+
 int hostapd_set_freq_params(struct hostapd_freq_params *data,
-			    enum hostapd_hw_mode mode,
-			    int freq, int channel, int edmg, u8 edmg_channel,
-			    int ht_enabled,
-			    int vht_enabled, int he_enabled,
-			    bool eht_enabled, int sec_channel_offset,
-			    enum oper_chan_width oper_chwidth,
-			    int center_segment0,
-			    int center_segment1, u32 vht_caps,
-			    struct he_capabilities *he_caps,
-			    struct eht_capabilities *eht_cap,
-			    u16 punct_bitmap);
+			    const struct hostapd_channel_info *info);
 void set_disable_ht40(struct ieee80211_ht_capabilities *htcaps,
 		      int disabled);
 int ieee80211ac_cap_check(u32 hw, u32 conf);
diff --git a/wpa_supplicant/mesh.c b/wpa_supplicant/mesh.c
index 8f7143f6ea63..f49ce68db65b 100644
--- a/wpa_supplicant/mesh.c
+++ b/wpa_supplicant/mesh.c
@@ -190,28 +190,26 @@ static int wpas_mesh_update_freq_params(struct wpa_supplicant *wpa_s)
 {
 	struct wpa_driver_mesh_join_params *params = wpa_s->mesh_params;
 	struct hostapd_iface *ifmsh = wpa_s->ifmsh;
-	struct he_capabilities *he_capab = NULL;
+	struct hostapd_channel_info info = {
+		.mode = ifmsh->conf->hw_mode,
+		.freq = ifmsh->freq,
+		.channel = ifmsh->conf->channel,
+		.edmg.enabled = ifmsh->conf->enable_edmg,
+		.edmg.channel = ifmsh->conf->edmg_channel,
+		.ht.enabled = ifmsh->conf->ieee80211n,
+		.vht.enabled = ifmsh->conf->ieee80211ac,
+		.he.enabled = ifmsh->conf->ieee80211ax,
+		.eht.enabled = ifmsh->conf->ieee80211be,
+		.ht.sec_channel_offset = ifmsh->conf->secondary_channel,
+		.oper_chwidth = hostapd_get_oper_chwidth(ifmsh->conf),
+		.center_segment0 = hostapd_get_oper_centr_freq_seg0_idx(ifmsh->conf),
+		.center_segment1 = hostapd_get_oper_centr_freq_seg1_idx(ifmsh->conf),
+		.vht.caps = ifmsh->conf->vht_capab,
+		.he.cap = ifmsh->current_mode ?
+			&ifmsh->current_mode->he_capab[IEEE80211_MODE_MESH] : NULL,
+	};
 
-	if (ifmsh->current_mode)
-		he_capab = &ifmsh->current_mode->he_capab[IEEE80211_MODE_MESH];
-
-	if (hostapd_set_freq_params(
-		    &params->freq,
-		    ifmsh->conf->hw_mode,
-		    ifmsh->freq,
-		    ifmsh->conf->channel,
-		    ifmsh->conf->enable_edmg,
-		    ifmsh->conf->edmg_channel,
-		    ifmsh->conf->ieee80211n,
-		    ifmsh->conf->ieee80211ac,
-		    ifmsh->conf->ieee80211ax,
-		    ifmsh->conf->ieee80211be,
-		    ifmsh->conf->secondary_channel,
-		    hostapd_get_oper_chwidth(ifmsh->conf),
-		    hostapd_get_oper_centr_freq_seg0_idx(ifmsh->conf),
-		    hostapd_get_oper_centr_freq_seg1_idx(ifmsh->conf),
-		    ifmsh->conf->vht_capab,
-		    he_capab, NULL, 0)) {
+	if (hostapd_set_freq_params(&params->freq, &info)) {
 		wpa_printf(MSG_ERROR, "Error updating mesh frequency params");
 		wpa_supplicant_mesh_deinit(wpa_s, true);
 		return -1;
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 2b9512a15c34..75ccaa12208d 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -3351,6 +3351,7 @@ static bool ibss_mesh_select_80_160mhz(struct wpa_supplicant *wpa_s,
 	};
 
 	struct hostapd_freq_params vht_freq;
+	struct hostapd_channel_info info;
 	int i;
 	unsigned int j, k;
 	int chwidth, seg0, seg1;
@@ -3515,15 +3516,25 @@ static bool ibss_mesh_select_80_160mhz(struct wpa_supplicant *wpa_s,
 	}
 
 skip_80mhz:
-	if (hostapd_set_freq_params(&vht_freq, mode->mode, freq->freq,
-				    freq->channel, ssid->enable_edmg,
-				    ssid->edmg_channel, freq->ht_enabled,
-				    freq->vht_enabled, freq->he_enabled,
-				    freq->eht_enabled,
-				    freq->sec_channel_offset,
-				    chwidth, seg0, seg1, vht_caps,
-				    &mode->he_capab[ieee80211_mode],
-				    &mode->eht_capab[ieee80211_mode], 0) != 0)
+	info = (struct hostapd_channel_info) {
+		.mode = mode->mode,
+		.freq = freq->freq,
+		.channel = freq->channel,
+		.edmg.enabled = ssid->enable_edmg,
+		.edmg.channel = ssid->edmg_channel,
+		.ht.enabled = freq->ht_enabled,
+		.vht.enabled = freq->vht_enabled,
+		.he.enabled = freq->he_enabled,
+		.eht.enabled = freq->eht_enabled,
+		.ht.sec_channel_offset = freq->sec_channel_offset,
+		.oper_chwidth = chwidth,
+		.center_segment0 = seg0,
+		.center_segment1 = seg1,
+		.vht.caps = vht_caps,
+		.he.cap = &mode->he_capab[ieee80211_mode],
+		.eht.cap = &mode->eht_capab[ieee80211_mode],
+	};
+	if (hostapd_set_freq_params(&vht_freq, &info))
 		return false;
 
 	*freq = vht_freq;
-- 
2.53.0




More information about the Hostap mailing list