All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [PATCH 3/4] wiphy: only do global GET_REG once
Date: Wed,  7 Sep 2022 16:32:00 -0700	[thread overview]
Message-ID: <20220907233201.227577-3-prestwoj@gmail.com> (raw)
In-Reply-To: <20220907233201.227577-1-prestwoj@gmail.com>

Getting the regulatory domain for self-managed wiphys requires
providing the wiphy ID, but this is not the case for any device
under the global regulatory domain. This is not tied to any
specific wiphy so there is no need to supply a wiphy ID or do
a dump for each wiphy.

Now GET_REG will be tracked globally if its a global call and
will only be called once.
---
 src/wiphy.c | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/src/wiphy.c b/src/wiphy.c
index f295d87d..af675694 100644
--- a/src/wiphy.c
+++ b/src/wiphy.c
@@ -64,6 +64,7 @@ static struct l_hwdb *hwdb;
 static char **whitelist_filter;
 static char **blacklist_filter;
 static int mac_randomize_bytes = 6;
+static unsigned int get_reg_id;
 static char regdom_country[2];
 static uint32_t work_ids;
 static unsigned int wiphy_dump_id;
@@ -2076,7 +2077,10 @@ static void wiphy_get_reg_cb(struct l_genl_msg *msg, void *user_data)
 	uint32_t tmp;
 	bool global;
 
-	wiphy->get_reg_id = 0;
+	if (wiphy)
+		wiphy->get_reg_id = 0;
+	else
+		get_reg_id = 0;
 
 	/*
 	 * NL80211_CMD_GET_REG contains an NL80211_ATTR_WIPHY iff the wiphy
@@ -2091,16 +2095,28 @@ static void wiphy_get_reg_cb(struct l_genl_msg *msg, void *user_data)
 static void wiphy_get_reg_domain(struct wiphy *wiphy)
 {
 	struct l_genl_msg *msg;
+	unsigned int id;
+
+	/* Already doing a global dump */
+	if (!wiphy && get_reg_id)
+		return;
 
 	msg = l_genl_msg_new(NL80211_CMD_GET_REG);
-	l_genl_msg_append_attr(msg, NL80211_ATTR_WIPHY, 4, &wiphy->id);
 
-	wiphy->get_reg_id = l_genl_family_send(nl80211, msg, wiphy_get_reg_cb,
-						wiphy, NULL);
-	if (!wiphy->get_reg_id) {
-		l_error("Error sending NL80211_CMD_GET_REG for %s", wiphy->name);
+	if (wiphy)
+		l_genl_msg_append_attr(msg, NL80211_ATTR_WIPHY, 4, &wiphy->id);
+
+	id = l_genl_family_send(nl80211, msg, wiphy_get_reg_cb, wiphy, NULL);
+	if (!id) {
+		l_error("Error sending NL80211_CMD_GET_REG for %s",
+				wiphy ? wiphy->name : "(global)");
 		l_genl_msg_unref(msg);
 	}
+
+	if (wiphy)
+		wiphy->get_reg_id = id;
+	else
+		get_reg_id = id;
 }
 
 void wiphy_create_complete(struct wiphy *wiphy)
@@ -2117,7 +2133,7 @@ void wiphy_create_complete(struct wiphy *wiphy)
 
 	wiphy_set_station_capability_bits(wiphy);
 	wiphy_setup_rm_enabled_capabilities(wiphy);
-	wiphy_get_reg_domain(wiphy);
+	wiphy_get_reg_domain(wiphy->self_managed ? wiphy : NULL);
 
 	wiphy_print_basic_info(wiphy);
 }
@@ -2519,6 +2535,11 @@ static void wiphy_exit(void)
 		wiphy_dump_id = 0;
 	}
 
+	if (get_reg_id) {
+		l_genl_family_cancel(nl80211, get_reg_id);
+		get_reg_id = 0;
+	}
+
 	l_queue_destroy(wiphy_list, wiphy_free);
 	wiphy_list = NULL;
 
-- 
2.34.3


  parent reply	other threads:[~2022-09-07 23:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-07 23:31 [PATCH 1/4] doc: document [General].Country main.conf option James Prestwood
2022-09-07 23:31 ` [PATCH 2/4] wiphy: remove nl80211 from wiphy object James Prestwood
2022-09-08 14:53   ` Denis Kenzior
2022-09-07 23:32 ` James Prestwood [this message]
2022-09-08 15:55   ` [PATCH 3/4] wiphy: only do global GET_REG once Denis Kenzior
2022-09-07 23:32 ` [PATCH 4/4] wiphy: support country code override James Prestwood
2022-09-08 16:00   ` Denis Kenzior

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=20220907233201.227577-3-prestwoj@gmail.com \
    --to=prestwoj@gmail.com \
    --cc=iwd@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.