connman.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Michael Trimarchi <michael@amarulasolutions.com>
To: connman@lists.linux.dev, Daniel Wagner <wagi@monom.org>
Subject: [PATCH 2/4] tethering: Add possibility to configure the access point frequency
Date: Thu,  7 Oct 2021 23:30:19 +0200	[thread overview]
Message-ID: <20211007213021.58712-2-michael@amarulasolutions.com> (raw)
In-Reply-To: <20211007213021.58712-1-michael@amarulasolutions.com>

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

Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
---
 include/technology.h |  4 ++--
 plugins/neard.c      |  3 ++-
 plugins/wifi.c       |  9 +++++++--
 src/technology.c     | 45 +++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/include/technology.h b/include/technology.h
index 7febd109..d89c8164 100644
--- a/include/technology.h
+++ b/include/technology.h
@@ -46,10 +46,10 @@ enum connman_service_type connman_technology_get_type
 				(struct connman_technology *technology);
 
 bool connman_get_wifi_tethering_from_technology(const struct connman_technology *technology,
-						const char **ssid, const char **psk);
+						const char **ssid, const char **psk, int *freq);
 
 bool connman_technology_get_wifi_tethering(const char **ssid,
-						const char **psk);
+						const char **psk, int *freq);
 
 bool connman_technology_is_tethering_allowed(enum connman_service_type type);
 
diff --git a/plugins/neard.c b/plugins/neard.c
index 45effd44..b0cdbde0 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -222,10 +222,11 @@ static DBusMessage *create_request_oob_reply(DBusMessage *message)
 	DBusMessageIter iter;
 	DBusMessageIter dict;
 	const char *ssid, *psk;
+	int freq;
 	uint8_t *tlv_msg;
 	int length;
 
-	if (!connman_technology_get_wifi_tethering(&ssid, &psk))
+	if (!connman_technology_get_wifi_tethering(&ssid, &psk, &freq))
 		return get_reply_on_error(message, ENOTSUP);
 
 	tlv_msg = encode_to_tlv(ssid, psk, &length);
diff --git a/plugins/wifi.c b/plugins/wifi.c
index cebe6886..4f859e31 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -3337,13 +3337,15 @@ static GSupplicantSSID *ssid_ap_init(const struct connman_technology *technology
 {
 	GSupplicantSSID *ap;
 	const char *ssid, *passphrase;
+	int freq;
 	bool ret;
 
 	ap = g_try_malloc0(sizeof(GSupplicantSSID));
 	if (!ap)
 		return NULL;
 
-	ret = connman_get_wifi_tethering_from_technology(technology, &ssid, &passphrase);
+	ret = connman_get_wifi_tethering_from_technology(technology, &ssid, &passphrase,
+							 &freq);
 	if (ret == false)
 		return NULL;
 
@@ -3351,7 +3353,10 @@ static GSupplicantSSID *ssid_ap_init(const struct connman_technology *technology
 	ap->ssid = ssid;
 	ap->ssid_len = strlen(ssid);
 	ap->scan_ssid = 0;
-	ap->freq = 2412;
+	if (freq)
+		ap->freq = freq;
+	else
+		ap->freq = 2412;
 
 	if (!passphrase || strlen(passphrase) == 0) {
 		ap->security = G_SUPPLICANT_SECURITY_NONE;
diff --git a/src/technology.c b/src/technology.c
index e0457890..7d5f6a4b 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -66,6 +66,7 @@ struct connman_technology {
 					      */
 	char *tethering_ident;
 	char *tethering_passphrase;
+	int tethering_freq;
 
 	bool enable_persistent; /* Save the tech state */
 
@@ -192,6 +193,13 @@ static void technology_save(struct connman_technology *technology)
 		g_free(enc);
 	}
 
+	if (technology->tethering_freq == 0)
+		technology->tethering_freq = 2412;
+
+	g_key_file_set_integer(keyfile, identifier,
+				"Tethering.Freq",
+				technology->tethering_freq);
+
 done:
 	g_free(identifier);
 
@@ -356,15 +364,17 @@ enum connman_service_type connman_technology_get_type
 }
 
 bool connman_get_wifi_tethering_from_technology(const struct connman_technology *technology,
-						const char **ssid, const char **psk)
+						const char **ssid, const char **psk, int *freq)
 {
 	*ssid = technology->tethering_ident;
 	*psk = technology->tethering_passphrase;
+	*freq = technology->tethering_freq;
 
 	return true;
 }
 
-bool connman_technology_get_wifi_tethering(const char **ssid, const char **psk)
+bool connman_technology_get_wifi_tethering(const char **ssid,
+					const char **psk, int *freq)
 {
 	struct connman_technology *technology;
 
@@ -380,7 +390,7 @@ bool connman_technology_get_wifi_tethering(const char **ssid, const char **psk)
 	if (!technology->tethering)
 		return false;
 
-	return connman_get_wifi_tethering_from_technology(technology, ssid, psk);
+	return connman_get_wifi_tethering_from_technology(technology, ssid, psk, freq);
 }
 
 static void free_rfkill(gpointer data)
@@ -447,6 +457,10 @@ static void technology_load(struct connman_technology *technology)
 				identifier, "Tethering.Passphrase", NULL);
 	if (enc)
 		technology->tethering_passphrase = g_strcompress(enc);
+
+	technology->tethering_freq = g_key_file_get_integer(keyfile,
+				identifier, "Tethering.Freq", NULL);
+
 done:
 	g_free(identifier);
 
@@ -558,6 +572,10 @@ static void append_properties(DBusMessageIter *iter,
 					DBUS_TYPE_STRING,
 					&technology->tethering_passphrase);
 
+	connman_dbus_dict_append_basic(&dict, "TetheringFreq",
+				DBUS_TYPE_INT32,
+				&technology->tethering_freq);
+
 	connman_dbus_dict_close(iter, &dict);
 }
 
@@ -972,6 +990,27 @@ static DBusMessage *set_property(DBusConnection *conn,
 					DBUS_TYPE_STRING,
 					&technology->tethering_passphrase);
 		}
+	} else if (g_str_equal(name, "TetheringFreq")) {
+		dbus_int32_t freq;
+
+		if (type != DBUS_TYPE_INT32)
+			return __connman_error_invalid_arguments(msg);
+
+		dbus_message_iter_get_basic(&value, &freq);
+
+		if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
+			return __connman_error_not_supported(msg);
+
+		if (freq >= 0) {
+			technology->tethering_freq = freq;
+			technology_save(technology);
+
+			connman_dbus_property_changed_basic(technology->path,
+					CONNMAN_TECHNOLOGY_INTERFACE,
+					"TetheringFreq",
+					DBUS_TYPE_INT32,
+					&technology->tethering_freq);
+		}
 	} else if (g_str_equal(name, "Powered")) {
 		dbus_bool_t enable;
 
-- 
2.25.1


  reply	other threads:[~2021-10-07 21:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07 21:30 [PATCH 1/4] tethering: Reduce the number of parameters of tech_set_tethering Michael Trimarchi
2021-10-07 21:30 ` Michael Trimarchi [this message]
2021-10-15  6:52   ` [PATCH 2/4] tethering: Add possibility to configure the access point frequency Daniel Wagner
2021-10-15  7:01     ` Michael Nazzareno Trimarchi
2021-10-15  7:04       ` Daniel Wagner
2021-10-15  7:09         ` Michael Nazzareno Trimarchi
2021-10-15  7:18           ` Daniel Wagner
2021-10-07 21:30 ` [PATCH 3/4] tethering: Add TetheringFreq parameter documentation Michael Trimarchi
2021-10-07 21:30 ` [PATCH 4/4] client: Update the connmactl to support optional tethering channel Michael Trimarchi
2021-10-14  6:31 ` [PATCH 1/4] tethering: Reduce the number of parameters of tech_set_tethering Julien Barrault
2021-10-15  6:53   ` Daniel Wagner
2021-10-22 15:20     ` Julien Barrault
2021-10-22 15:33       ` Michael Nazzareno Trimarchi
2021-10-15  6:51 ` Daniel Wagner

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=20211007213021.58712-2-michael@amarulasolutions.com \
    --to=michael@amarulasolutions.com \
    --cc=connman@lists.linux.dev \
    --cc=wagi@monom.org \
    --subject='Re: [PATCH 2/4] tethering: Add possibility to configure the access point frequency' \
    /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

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).