connman.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Vivien Henriet <v.henriet@overkiz.com>
To: connman@lists.linux.dev
Cc: Vivien Henriet <v.henriet@overkiz.com>
Subject: [PATCH] wifi: Choose a random channel when opening an ap
Date: Thu, 23 Sep 2021 14:44:29 +0200	[thread overview]
Message-ID: <20210923124429.1123-1-v.henriet@overkiz.com> (raw)

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


             reply	other threads:[~2021-09-23 12:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-23 12:44 Vivien Henriet [this message]
2021-09-29  8:57 ` [PATCH] wifi: Choose a random channel when opening an ap 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210923124429.1123-1-v.henriet@overkiz.com \
    --to=v.henriet@overkiz.com \
    --cc=connman@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).