connman.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] wifi: Choose a random channel when opening an ap
@ 2021-09-23 12:44 Vivien Henriet
  2021-09-29  8:57 ` HENRIET Vivien
  0 siblings, 1 reply; 8+ messages in thread
From: Vivien Henriet @ 2021-09-23 12:44 UTC (permalink / raw)
  To: connman; +Cc: Vivien Henriet

When the tethering mode is started, a WiFi ap is created using the fixed
channel 1 (2412 MHz). There is no way to configure this channel.

This patch make connman choose a random channel every time the ap is created.
---
 plugins/wifi.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index 578b4be7..936f1750 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -3344,11 +3344,19 @@ static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
 	if (!ap)
 		return NULL;
 
+	/**
+	 * Choose a random channel in the range 1-11. Channels 12-14 are not
+	 * available worlwide.
+	 * Channels within this range are spaced 5 MHz apart from each other.
+	 */
+	int channel = (rand() % 11) + 1;
+	int freq = 2407 + channel * 5;
+
 	ap->mode = G_SUPPLICANT_MODE_MASTER;
 	ap->ssid = ssid;
 	ap->ssid_len = strlen(ssid);
 	ap->scan_ssid = 0;
-	ap->freq = 2412;
+	ap->freq = freq;
 
 	if (!passphrase || strlen(passphrase) == 0) {
 		ap->security = G_SUPPLICANT_SECURITY_NONE;
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-10-04 21:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-23 12:44 [PATCH] wifi: Choose a random channel when opening an ap Vivien Henriet
2021-09-29  8:57 ` HENRIET Vivien
2021-09-29  9:16   ` Daniel Wagner
2021-10-04  6:45     ` Michael Nazzareno Trimarchi
2021-10-04  7:09       ` Daniel Wagner
2021-10-04  7:34         ` Michael Nazzareno Trimarchi
2021-10-04  7:46           ` Daniel Wagner
2021-10-04 21:21             ` Michael Nazzareno Trimarchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).