Skip to contentSkip to conversation

doc: document [General].Country main.conf option

PATCH In review James Prestwood 2 participants 3 messages Sep 8, 2022 – Sep 9, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 doc: document [General].Country main.conf option

This lets the user set a country code explicitly.

---
 src/iwd.config.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)
src/iwd.config.rst +10 -0
index 422d4c03..bafb6b85 100644
@@ -206,6 +206,16 @@ The group ``[General]`` contains general settings.
        required are LoadCredentialEncrypted or SetCredentialEncrypted, and the
        secret identifier should be named whatever SystemdEncrypt is set to.
 
+   * - Country
+     - Value: Country Code (ISO Alpha-2)
+
+       Requests the country be set for the system. Note that setting this is
+       simply a **request** to set the country, and does not guarantee the
+       country will be set. For a self-managed wiphy it is never possible to set
+       the country from userspace. For other devices any regulatory domain
+       request is just a 'hint' and ultimately left up to the kernel to set the
+       country.
+
 Network
 -------
 
Signature · 1 line
2.34.3
#1 lore raw

PATCH v2 2/2 manager: add support for [General].Country

This lets the user set a country as the global regulatory domain if the kernel/driver isn't doing it on its own.

---
 src/manager.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
src/manager.c +26 -0
index 6ff642f1..fed02777 100644
@@ -800,6 +800,14 @@ static void manager_config_notify(struct l_genl_msg *msg, void *user_data)
 	}
 }
 
+static void manager_set_reg_cb(struct l_genl_msg *msg, void *user_data)
+{
+	int err = l_genl_msg_get_error(msg);
+
+	if (err < 0)
+		l_error("Failed to set country (%d)", err);
+}
+
 static int manager_init(void)
 {
 	struct l_genl *genl = iwd_get_genl();
@@ -810,6 +818,7 @@ static int manager_init(void)
 	const char *randomize_str;
 	const char *if_whitelist = iwd_get_iface_whitelist();
 	const char *if_blacklist = iwd_get_iface_blacklist();
+	const char *cc;
 
 	nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
 
@@ -853,6 +862,23 @@ static int manager_init(void)
 		goto error;
 	}
 
+	cc = l_settings_get_value(config, "General", "Country");
+	if (cc) {
+		if (strlen(cc) != 2 || !l_ascii_isalpha(cc[0]) ||
+					!l_ascii_isalpha(cc[1])) {
+			l_warn("[General].Country=%s is invalid. Country will "
+				"not be set", cc);
+		} else {
+			msg = l_genl_msg_new(NL80211_CMD_REQ_SET_REG);
+			l_genl_msg_append_attr(msg, NL80211_ATTR_REG_ALPHA2,
+						2, cc);
+			if (!l_genl_family_send(nl80211, msg,
+						manager_set_reg_cb,
+						NULL, NULL))
+				l_warn("Failed to set country");
+		}
+	}
+
 	randomize_str = l_settings_get_value(config, "General",
 							"AddressRandomization");
 	if (randomize_str) {
Signature · 1 line
2.34.3
#2 lore raw
In reply to James Prestwood

Hi James,

Quoted 5 lines · James Prestwood

This lets the user set a country code explicitly.

---
  src/iwd.config.rst | 10 ++++++++++
  1 file changed, 10 insertions(+)

Both applied, thanks.

Regards,
-Denis