blob: 32a447914ced9a76fb7d8f386e8486d8de141f60 [file] [log] [blame]
developer29c4d2d2022-12-26 19:41:22 +08001From fc8ea40f6130ac18d9c66797de2cf1d5af55d496 Mon Sep 17 00:00:00 2001
2From: Markus Theil <markus.theil@tu-ilmenau.de>
3Date: Tue, 30 Jun 2020 14:19:07 +0200
4Subject: [PATCH 19/19] mesh: use deterministic channel on channel switch
5
6This patch uses a deterministic channel on DFS channel switch
7in mesh networks. Otherwise, when switching to a usable but not
8available channel, no CSA can be sent and a random channel is choosen
9without notification of other nodes. It is then quite likely, that
10the mesh network gets disconnected.
11
12Fix this by using a deterministic number, based on the sha256 hash
13of the mesh ID, in order to use at least a different number in each
14mesh network.
15
16Signed-off-by: Markus Theil <markus.theil@tu-ilmenau.de>
17---
18 src/ap/dfs.c | 20 +++++++++++++++++++-
19 src/drivers/driver_nl80211.c | 4 ++++
20 2 files changed, 23 insertions(+), 1 deletion(-)
21
22--- a/src/ap/dfs.c
23+++ b/src/ap/dfs.c
24@@ -17,6 +17,7 @@
25 #include "ap_drv_ops.h"
26 #include "drivers/driver.h"
27 #include "dfs.h"
28+#include "crypto/crypto.h"
29
30
31 enum dfs_channel_type {
32@@ -515,9 +516,14 @@ dfs_get_valid_channel(struct hostapd_ifa
33 int num_available_chandefs;
34 int chan_idx, chan_idx2;
35 int sec_chan_idx_80p80 = -1;
36+ bool is_mesh = false;
37 int i;
38 u32 _rand;
39
40+#ifdef CONFIG_MESH
41+ is_mesh = iface->mconf;
42+#endif
43+
44 wpa_printf(MSG_DEBUG, "DFS: Selecting random channel");
45 *secondary_channel = 0;
46 *oper_centr_freq_seg0_idx = 0;
47@@ -537,8 +543,20 @@ dfs_get_valid_channel(struct hostapd_ifa
48 if (num_available_chandefs == 0)
49 return NULL;
50
51- if (os_get_random((u8 *) &_rand, sizeof(_rand)) < 0)
52+ /* try to use deterministic channel in mesh, so that both sides
53+ * have a chance to switch to the same channel */
54+ if (is_mesh) {
55+#ifdef CONFIG_MESH
56+ u64 hash[4];
57+ const u8 *meshid[1] = { &iface->mconf->meshid[0] };
58+ const size_t meshid_len = iface->mconf->meshid_len;
59+
60+ sha256_vector(1, meshid, &meshid_len, (u8 *)&hash[0]);
61+ _rand = hash[0] + hash[1] + hash[2] + hash[3];
62+#endif
63+ } else if (os_get_random((u8 *) &_rand, sizeof(_rand)) < 0)
64 return NULL;
65+
66 chan_idx = _rand % num_available_chandefs;
67 dfs_find_channel(iface, &chan, chan_idx, type);
68 if (!chan) {
69--- a/src/drivers/driver_nl80211.c
70+++ b/src/drivers/driver_nl80211.c
71@@ -9948,6 +9948,10 @@ static int nl80211_switch_channel(void *
72 if (ret)
73 goto error;
74
75+ if (drv->nlmode == NL80211_IFTYPE_MESH_POINT) {
76+ nla_put_flag(msg, NL80211_ATTR_HANDLE_DFS);
77+ }
78+
79 /* beacon_csa params */
80 beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES);
81 if (!beacon_csa)