diff mbox series

[1/3] technology: Add global regdom and regdom getter

Message ID 20231222154645.278128-2-jussi.laakkonen@jolla.com (mailing list archive)
State New
Headers show
Series Ensure resolving and setting of proper ISO3166 code | expand

Commit Message

Jussi Laakkonen Dec. 22, 2023, 3:46 p.m. UTC
Add a global regdom to be saved when setting technology regdom because
the technologies are not loaded yet at bootup. Loading of plugins
initializes technologies which then sets up the regdom if it has been set
up earlier by timezone.c. The getter prioritizes the technology regdom
and then the global regdom and is to be used by devices when powering
up.
---
 src/connman.h    |  1 +
 src/technology.c | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
diff mbox series

Patch

diff --git a/src/connman.h b/src/connman.h
index 622a7785..34e1463e 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -595,6 +595,7 @@  void __connman_technology_remove_interface(enum connman_service_type type,
 				int index, const char *ident);
 void __connman_technology_notify_regdom_by_device(struct connman_device *device,
 						int result, const char *alpha2);
+const char *__connman_technology_get_regdom(enum connman_service_type type);
 
 #include <connman/device.h>
 
diff --git a/src/technology.c b/src/technology.c
index 5c469111..65fb9854 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -43,6 +43,8 @@  static GHashTable *rfkill_list;
 
 static bool global_offlinemode;
 
+static char *global_regdom = NULL;
+
 struct connman_rfkill {
 	unsigned int index;
 	enum connman_service_type type;
@@ -333,8 +335,14 @@  int connman_technology_set_regdom(const char *alpha2)
 					driver->set_regdom(technology, alpha2);
 			}
 		}
+
+		/* Save regdom for this technology */
+		connman_technology_regdom_notify(technology, alpha2);
 	}
 
+	g_free(global_regdom);
+	global_regdom = g_strdup(alpha2);
+
 	return 0;
 }
 
@@ -354,6 +362,22 @@  static struct connman_technology *technology_find(enum connman_service_type type
 	return NULL;
 }
 
+const char *__connman_technology_get_regdom(enum connman_service_type type)
+{
+	struct connman_technology *technology;
+
+	DBG("type %d/%s", type, get_name(type));
+
+	technology = technology_find(type);
+	if (!technology)
+		return NULL;
+
+	if (technology->regdom)
+		return technology->regdom;
+
+	return global_regdom;
+}
+
 enum connman_service_type connman_technology_get_type
 				(struct connman_technology *technology)
 {
@@ -1283,6 +1307,7 @@  static struct connman_technology *technology_get(enum connman_service_type type)
 	technology_load(technology);
 	technology_list = g_slist_prepend(technology_list, technology);
 	technology->driver_list = tech_drivers;
+	technology->regdom = g_strdup(global_regdom);
 
 	for (list = tech_drivers; list; list = list->next) {
 		driver = list->data;
@@ -1905,4 +1930,6 @@  void __connman_technology_cleanup(void)
 	g_hash_table_destroy(rfkill_list);
 
 	dbus_connection_unref(connection);
+
+	g_free(global_regdom);
 }