diff --git a/src/ap/dfs.c b/src/ap/dfs.c index 0cac194b2..4ba953f56 100644 --- a/src/ap/dfs.c +++ b/src/ap/dfs.c @@ -18,6 +18,7 @@ #include "ap_drv_ops.h" #include "drivers/driver.h" #include "dfs.h" +#include "crypto/crypto.h" enum dfs_channel_type { @@ -534,9 +535,14 @@ dfs_get_valid_channel(struct hostapd_iface *iface, int num_available_chandefs; int chan_idx, chan_idx2; int sec_chan_idx_80p80 = -1; + bool is_mesh = false; int i; u32 _rand; +#ifdef CONFIG_MESH + is_mesh = iface->mconf; +#endif + wpa_printf(MSG_DEBUG, "DFS: Selecting random channel"); *secondary_channel = 0; *oper_centr_freq_seg0_idx = 0; @@ -556,8 +562,20 @@ dfs_get_valid_channel(struct hostapd_iface *iface, if (num_available_chandefs == 0) return NULL; - if (os_get_random((u8 *) &_rand, sizeof(_rand)) < 0) + /* try to use deterministic channel in mesh, so that both sides + * have a chance to switch to the same channel */ + if (is_mesh) { +#ifdef CONFIG_MESH + u64 hash[4]; + const u8 *meshid[1] = { &iface->mconf->meshid[0] }; + const size_t meshid_len = iface->mconf->meshid_len; + + sha256_vector(1, meshid, &meshid_len, (u8 *)&hash[0]); + _rand = hash[0] + hash[1] + hash[2] + hash[3]; +#endif + } else if (os_get_random((u8 *) &_rand, sizeof(_rand)) < 0) return NULL; + chan_idx = _rand % num_available_chandefs; wpa_printf(MSG_DEBUG, "DFS: Picked random entry from the list: %d/%d", chan_idx, num_available_chandefs); diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index 1356d325d..f69b5b8dc 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -11465,6 +11465,10 @@ static int nl80211_switch_channel(void *priv, struct csa_settings *settings) if (ret) goto error; + if (drv->nlmode == NL80211_IFTYPE_MESH_POINT) { + nla_put_flag(msg, NL80211_ATTR_HANDLE_DFS); + } + /* beacon_csa params */ beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); if (!beacon_csa)