Wireless Daemon for Linux
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [PATCH v3 7/7] wiphy: don't re-dump wiphy if the regdom didn't change
Date: Thu,  4 Aug 2022 11:51:12 -0700	[thread overview]
Message-ID: <20220804185112.457670-7-prestwoj@gmail.com> (raw)
In-Reply-To: <20220804185112.457670-1-prestwoj@gmail.com>

For whatever reason the kernel will send regdom updates even if
the regdom didn't change. This ends up causing wiphy to dump
which isn't needed since there should be no changes in disabled
frequencies.

Now the previous country is checked against the new one, and if
they match the wiphy is not dumped again.
---
 src/wiphy.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/src/wiphy.c b/src/wiphy.c
index 3beb351c..28d4b66e 100644
--- a/src/wiphy.c
+++ b/src/wiphy.c
@@ -2026,10 +2026,19 @@ static void wiphy_dump_after_regdom(struct wiphy *wiphy)
 	}
 }
 
-static void wiphy_update_reg_domain(struct wiphy *wiphy, bool global,
+static bool wiphy_update_reg_domain(struct wiphy *wiphy, bool global,
 					struct l_genl_msg *msg)
 {
-	char *out_country;
+	char out_country[2];
+	char *orig;
+
+	/*
+	 * Write the new country code or XX if the reg domain is not a
+	 * country domain.
+	 */
+	if (nl80211_parse_attrs(msg, NL80211_ATTR_REG_ALPHA2, out_country,
+				NL80211_ATTR_UNSPEC) < 0)
+		out_country[0] = out_country[1] = 'X';
 
 	if (global)
 		/*
@@ -2043,21 +2052,26 @@ static void wiphy_update_reg_domain(struct wiphy *wiphy, bool global,
 		 * wiphy created (that is not self-managed anyway) and we
 		 * haven't received any REG_CHANGE events yet.
 		 */
-		out_country = regdom_country;
+		orig = regdom_country;
+
 	else
-		out_country = wiphy->regdom_country;
+		orig = wiphy->regdom_country;
 
 	/*
-	 * Write the new country code or XX if the reg domain is not a
-	 * country domain.
+	 * The kernel seems to send regdom updates even if the country didn't
+	 * change. Skip these as there is no reason to re-dump.
 	 */
-	if (nl80211_parse_attrs(msg, NL80211_ATTR_REG_ALPHA2, out_country,
-				NL80211_ATTR_UNSPEC) < 0)
-		out_country[0] = out_country[1] = 'X';
+	if (orig[0] == out_country[0] && orig[1] == out_country[1])
+		return false;
 
 	l_debug("New reg domain country code for %s is %c%c",
 		global ? "(global)" : wiphy->name,
 		out_country[0], out_country[1]);
+
+	orig[0] = out_country[0];
+	orig[1] = out_country[1];
+
+	return true;
 }
 
 static void wiphy_get_reg_cb(struct l_genl_msg *msg, void *user_data)
@@ -2305,7 +2319,8 @@ static void wiphy_reg_notify(struct l_genl_msg *msg, void *user_data)
 
 	switch (cmd) {
 	case NL80211_CMD_REG_CHANGE:
-		wiphy_update_reg_domain(NULL, true, msg);
+		if (!wiphy_update_reg_domain(NULL, true, msg))
+			return;
 		break;
 	case NL80211_CMD_WIPHY_REG_CHANGE:
 		if (nl80211_parse_attrs(msg, NL80211_ATTR_WIPHY, &wiphy_id,
@@ -2316,7 +2331,9 @@ static void wiphy_reg_notify(struct l_genl_msg *msg, void *user_data)
 		if (!wiphy)
 			return;
 
-		wiphy_update_reg_domain(wiphy, false, msg);
+		if (!wiphy_update_reg_domain(wiphy, false, msg))
+			return;
+
 		break;
 	default:
 		return;
-- 
2.34.3


  parent reply	other threads:[~2022-08-04 18:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-04 18:51 [PATCH v3 1/7] wiphy: track GET_REG ID James Prestwood
2022-08-04 18:51 ` [PATCH v3 2/7] wiphy: dump wiphy's on regulatory domain change James Prestwood
2022-08-04 18:51 ` [PATCH v3 3/7] wiphy: add wiphy_regdom_is_updating James Prestwood
2022-08-04 18:51 ` [PATCH v3 4/7] station: do full passive scan if 6GHz is supported but disabled James Prestwood
2022-08-04 19:20   ` Denis Kenzior
2022-08-04 18:51 ` [PATCH v3 5/7] scan: split full scans by band to enable 6GHz James Prestwood
2022-08-04 18:51 ` [PATCH v3 6/7] scan: watch for regdom updates " James Prestwood
2022-08-04 18:51 ` James Prestwood [this message]
2022-08-04 19:18 ` [PATCH v3 1/7] wiphy: track GET_REG ID 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=20220804185112.457670-7-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox