[RFC 1/3] hostapd: Move CSA structures to hostapd_data
Michal Kazior
michal.kazior
Tue Mar 18 06:55:08 PDT 2014
This prepares CSA structure and logic in hostapd for multi-BSS support.
Signed-hostap: Michal Kazior <michal.kazior at tieto.com>
---
src/ap/beacon.c | 20 ++++++++++----------
src/ap/dfs.c | 14 ++++++++++++--
src/ap/drv_callbacks.c | 8 +++++---
src/ap/hostapd.c | 40 ++++++++++++++++++++--------------------
src/ap/hostapd.h | 16 ++++++++--------
src/drivers/driver_nl80211.c | 4 ++--
6 files changed, 57 insertions(+), 45 deletions(-)
diff --git a/src/ap/beacon.c b/src/ap/beacon.c
index e06ce77..c4341f2 100644
--- a/src/ap/beacon.c
+++ b/src/ap/beacon.c
@@ -265,18 +265,18 @@ static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
{
u8 chan;
- if (!hapd->iface->cs_freq_params.freq)
+ if (!hapd->cs_freq_params.freq)
return eid;
- if (ieee80211_freq_to_chan(hapd->iface->cs_freq_params.freq, &chan) ==
+ if (ieee80211_freq_to_chan(hapd->cs_freq_params.freq, &chan) ==
NUM_HOSTAPD_MODES)
return eid;
*eid++ = WLAN_EID_CHANNEL_SWITCH;
*eid++ = 3;
- *eid++ = hapd->iface->cs_block_tx;
+ *eid++ = hapd->cs_block_tx;
*eid++ = chan;
- *eid++ = hapd->iface->cs_count;
+ *eid++ = hapd->cs_count;
return eid;
}
@@ -286,12 +286,12 @@ static u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid)
{
u8 sec_ch;
- if (!hapd->iface->cs_freq_params.sec_channel_offset)
+ if (!hapd->cs_freq_params.sec_channel_offset)
return eid;
- if (hapd->iface->cs_freq_params.sec_channel_offset == -1)
+ if (hapd->cs_freq_params.sec_channel_offset == -1)
sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
- else if (hapd->iface->cs_freq_params.sec_channel_offset == 1)
+ else if (hapd->cs_freq_params.sec_channel_offset == 1)
sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
else
return eid;
@@ -409,7 +409,7 @@ static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
pos = hostapd_eid_roaming_consortium(hapd, pos);
pos = hostapd_add_csa_elems(hapd, pos, (u8 *)resp,
- &hapd->iface->cs_c_off_proberesp);
+ &hapd->cs_c_off_proberesp);
#ifdef CONFIG_IEEE80211AC
pos = hostapd_eid_vht_capabilities(hapd, pos);
pos = hostapd_eid_vht_operation(hapd, pos);
@@ -823,7 +823,7 @@ int ieee802_11_build_ap_params(struct hostapd_data *hapd,
tailpos = hostapd_eid_adv_proto(hapd, tailpos);
tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
tailpos = hostapd_add_csa_elems(hapd, tailpos, tail,
- &hapd->iface->cs_c_off_beacon);
+ &hapd->cs_c_off_beacon);
#ifdef CONFIG_IEEE80211AC
tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
tailpos = hostapd_eid_vht_operation(hapd, tailpos);
@@ -953,7 +953,7 @@ int ieee802_11_set_beacon(struct hostapd_data *hapd)
struct wpabuf *beacon, *proberesp, *assocresp;
int res, ret = -1;
- if (hapd->iface->csa_in_progress) {
+ if (hapd->csa_in_progress) {
wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
return -1;
}
diff --git a/src/ap/dfs.c b/src/ap/dfs.c
index 0f262ce..9e8389f 100644
--- a/src/ap/dfs.c
+++ b/src/ap/dfs.c
@@ -729,6 +729,16 @@ static int hostapd_dfs_start_channel_switch_cac(struct hostapd_iface *iface)
}
+static int hostapd_csa_in_progress(struct hostapd_iface *iface)
+{
+ int i;
+ for (i = 0; i < iface->num_bss; i++)
+ if (iface->bss[0]->csa_in_progress)
+ return 1;
+ return 0;
+}
+
+
static int hostapd_dfs_start_channel_switch(struct hostapd_iface *iface)
{
struct hostapd_channel_data *channel;
@@ -742,10 +752,10 @@ static int hostapd_dfs_start_channel_switch(struct hostapd_iface *iface)
wpa_printf(MSG_DEBUG, "%s called (CAC active: %s, CSA active: %s)",
__func__, iface->cac_started ? "yes" : "no",
- iface->csa_in_progress ? "yes" : "no");
+ hostapd_csa_in_progress(iface) ? "yes" : "no");
/* Check if CSA in progress */
- if (iface->csa_in_progress)
+ if (hostapd_csa_in_progress(iface))
return 0;
/* Check if active CAC */
diff --git a/src/ap/drv_callbacks.c b/src/ap/drv_callbacks.c
index 3c6a376..e3b1e7b 100644
--- a/src/ap/drv_callbacks.c
+++ b/src/ap/drv_callbacks.c
@@ -30,6 +30,7 @@
#include "ap_config.h"
#include "hw_features.h"
#include "dfs.h"
+#include "beacon.h"
int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
@@ -483,11 +484,12 @@ void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
else
hapd->iconf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
- if (hapd->iface->csa_in_progress &&
- freq == hapd->iface->cs_freq_params.freq) {
- hapd->iconf->ieee80211ac = hapd->iface->cs_freq_params.vht_enabled;
+ if (hapd->csa_in_progress &&
+ freq == hapd->cs_freq_params.freq) {
+ hapd->iconf->ieee80211ac = hapd->cs_freq_params.vht_enabled;
hostapd_cleanup_cs_params(hapd);
+ ieee802_11_set_beacon(hapd);
wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED "freq=%d",
freq);
diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c
index 4ed718c..06b3f5b 100644
--- a/src/ap/hostapd.c
+++ b/src/ap/hostapd.c
@@ -2118,13 +2118,12 @@ static void free_beacon_data(struct beacon_data *beacon)
}
-static int hostapd_build_beacon_data(struct hostapd_iface *iface,
+static int hostapd_build_beacon_data(struct hostapd_data *hapd,
struct beacon_data *beacon)
{
struct wpabuf *beacon_extra, *proberesp_extra, *assocresp_extra;
struct wpa_driver_ap_params params;
int ret;
- struct hostapd_data *hapd = iface->bss[0];
os_memset(beacon, 0, sizeof(*beacon));
ret = ieee802_11_build_ap_params(hapd, ¶ms);
@@ -2248,14 +2247,15 @@ static int hostapd_change_config_freq(struct hostapd_data *hapd,
}
-static int hostapd_fill_csa_settings(struct hostapd_iface *iface,
+static int hostapd_fill_csa_settings(struct hostapd_data *hapd,
struct csa_settings *settings)
{
+ struct hostapd_iface *iface = hapd->iface;
struct hostapd_freq_params old_freq;
int ret;
os_memset(&old_freq, 0, sizeof(old_freq));
- if (!iface || !iface->freq || iface->csa_in_progress)
+ if (!iface || !iface->freq || hapd->csa_in_progress)
return -1;
ret = hostapd_change_config_freq(iface->bss[0], iface->conf,
@@ -2264,7 +2264,7 @@ static int hostapd_fill_csa_settings(struct hostapd_iface *iface,
if (ret)
return ret;
- ret = hostapd_build_beacon_data(iface, &settings->beacon_after);
+ ret = hostapd_build_beacon_data(hapd, &settings->beacon_after);
/* change back the configuration */
hostapd_change_config_freq(iface->bss[0], iface->conf,
@@ -2274,18 +2274,18 @@ static int hostapd_fill_csa_settings(struct hostapd_iface *iface,
return ret;
/* set channel switch parameters for csa ie */
- iface->cs_freq_params = settings->freq_params;
- iface->cs_count = settings->cs_count;
- iface->cs_block_tx = settings->block_tx;
+ hapd->cs_freq_params = settings->freq_params;
+ hapd->cs_count = settings->cs_count;
+ hapd->cs_block_tx = settings->block_tx;
- ret = hostapd_build_beacon_data(iface, &settings->beacon_csa);
+ ret = hostapd_build_beacon_data(hapd, &settings->beacon_csa);
if (ret) {
free_beacon_data(&settings->beacon_after);
return ret;
}
- settings->counter_offset_beacon = iface->cs_c_off_beacon;
- settings->counter_offset_presp = iface->cs_c_off_proberesp;
+ settings->counter_offset_beacon = hapd->cs_c_off_beacon;
+ settings->counter_offset_presp = hapd->cs_c_off_proberesp;
return 0;
}
@@ -2293,13 +2293,13 @@ static int hostapd_fill_csa_settings(struct hostapd_iface *iface,
void hostapd_cleanup_cs_params(struct hostapd_data *hapd)
{
- os_memset(&hapd->iface->cs_freq_params, 0,
- sizeof(hapd->iface->cs_freq_params));
- hapd->iface->cs_count = 0;
- hapd->iface->cs_block_tx = 0;
- hapd->iface->cs_c_off_beacon = 0;
- hapd->iface->cs_c_off_proberesp = 0;
- hapd->iface->csa_in_progress = 0;
+ os_memset(&hapd->cs_freq_params, 0,
+ sizeof(hapd->cs_freq_params));
+ hapd->cs_count = 0;
+ hapd->cs_block_tx = 0;
+ hapd->cs_c_off_beacon = 0;
+ hapd->cs_c_off_proberesp = 0;
+ hapd->csa_in_progress = 0;
}
@@ -2307,7 +2307,7 @@ int hostapd_switch_channel(struct hostapd_data *hapd,
struct csa_settings *settings)
{
int ret;
- ret = hostapd_fill_csa_settings(hapd->iface, settings);
+ ret = hostapd_fill_csa_settings(hapd, settings);
if (ret)
return ret;
@@ -2321,7 +2321,7 @@ int hostapd_switch_channel(struct hostapd_data *hapd,
return ret;
}
- hapd->iface->csa_in_progress = 1;
+ hapd->csa_in_progress = 1;
return 0;
}
diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h
index 9a705a4..ad1a0ee 100644
--- a/src/ap/hostapd.h
+++ b/src/ap/hostapd.h
@@ -210,6 +210,14 @@ struct hostapd_data {
size_t psk_len);
void *new_psk_cb_ctx;
+ /* channel switch parameters */
+ struct hostapd_freq_params cs_freq_params;
+ u8 cs_count;
+ int cs_block_tx;
+ unsigned int cs_c_off_beacon;
+ unsigned int cs_c_off_proberesp;
+ int csa_in_progress;
+
#ifdef CONFIG_P2P
struct p2p_data *p2p;
struct p2p_group *p2p_group;
@@ -340,14 +348,6 @@ struct hostapd_iface {
/* lowest observed noise floor in dBm */
s8 lowest_nf;
- /* channel switch parameters */
- struct hostapd_freq_params cs_freq_params;
- u8 cs_count;
- int cs_block_tx;
- unsigned int cs_c_off_beacon;
- unsigned int cs_c_off_proberesp;
- int csa_in_progress;
-
#ifdef CONFIG_ACS
unsigned int acs_num_completed_scans;
#endif /* CONFIG_ACS */
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index d60f95b..dd119c4 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -1653,7 +1653,7 @@ static void mlme_event_ch_switch(struct wpa_driver_nl80211_data *drv,
bss->freq = data.ch_switch.freq;
- wpa_supplicant_event(drv->ctx, EVENT_CH_SWITCH, &data);
+ wpa_supplicant_event(bss->ctx, EVENT_CH_SWITCH, &data);
}
@@ -11700,7 +11700,7 @@ static int nl80211_switch_channel(void *priv, struct csa_settings *settings)
return -ENOMEM;
nl80211_cmd(drv, msg, 0, NL80211_CMD_CHANNEL_SWITCH);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
+ NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
NLA_PUT_U32(msg, NL80211_ATTR_CH_SWITCH_COUNT, settings->cs_count);
ret = nl80211_put_freq_params(msg, &settings->freq_params);
if (ret)
--
1.8.5.3
More information about the Hostap
mailing list