connman.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: connman@lists.linux.dev
Cc: Denis Kenzior <denkenz@gmail.com>
Subject: [PATCH 4/4] ofono: delay device creation until lte settings are provisioned
Date: Wed, 27 Mar 2024 14:43:35 -0500	[thread overview]
Message-ID: <20240327194337.2735677-4-denkenz@gmail.com> (raw)
In-Reply-To: <20240327194337.2735677-1-denkenz@gmail.com>

For LTE capable devices, successful network registration typically
requires the default attach APN to be configured.  Some carriers will
allow the device to register to the network even if this setting is
empty or missing.  Sometimes devices will utilize carrier specific
settings present on the device itself (such as profiles in modem NVRAM,
etc).  However, there may be situations where missing default
attach APN settings preclude successful registration, or registration is
performed with an incorrect profile.

Currently ConnMan does not take oFono's LTE support into consideration
when setting the modem 'Online'.  This can result in the modem
attempting registration too early, when the default attach settings have
not been applied.

oFono has recently introduced Modem.Capabilities property which can
provide an early hint whether the modem is LTE capable.  If the modem
is LTE capable, then ConnMan should wait until oFono LongTermEvolution
interface is available (and thus default attach settings have been
applied) prior to setting the device 'Online'.
---
 plugins/ofono.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/plugins/ofono.c b/plugins/ofono.c
index ad85c55d3df3..062905c8a3a6 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -52,6 +52,7 @@
 #define OFONO_NETREG_INTERFACE		OFONO_SERVICE ".NetworkRegistration"
 #define OFONO_CM_INTERFACE		OFONO_SERVICE ".ConnectionManager"
 #define OFONO_CONTEXT_INTERFACE		OFONO_SERVICE ".ConnectionContext"
+#define OFONO_LTE_INTERFACE		OFONO_SERVICE ".LongTermEvolution"
 
 #define MODEM_ADDED			"ModemAdded"
 #define MODEM_REMOVED			"ModemRemoved"
@@ -70,6 +71,11 @@ enum ofono_api {
 	OFONO_API_SIM =		0x1,
 	OFONO_API_NETREG =	0x2,
 	OFONO_API_CM =		0x4,
+	OFONO_API_LTE =		0x8,
+};
+
+enum capabilities {
+	LTE_CAPABLE = 0x1,
 };
 
 /*
@@ -137,6 +143,7 @@ struct modem_data {
 	bool powered;
 	bool online;
 	uint8_t interfaces;
+	uint8_t capabilities;
 	bool ignore;
 
 	bool set_powered;
@@ -169,6 +176,8 @@ static const char *api2string(enum ofono_api api)
 		return "netreg";
 	case OFONO_API_CM:
 		return "cm";
+	case OFONO_API_LTE:
+		return "lte";
 	}
 
 	return "unknown";
@@ -730,6 +739,7 @@ static uint8_t extract_interfaces(DBusMessageIter *array)
 		{ .value = OFONO_SIM_INTERFACE, .flag = OFONO_API_SIM },
 		{ .value = OFONO_NETREG_INTERFACE, .flag = OFONO_API_NETREG },
 		{ .value = OFONO_CM_INTERFACE, .flag = OFONO_API_CM },
+		{ .value = OFONO_LTE_INTERFACE, .flag = OFONO_API_LTE },
 	};
 	uint32_t flags;
 
@@ -741,6 +751,21 @@ static uint8_t extract_interfaces(DBusMessageIter *array)
 	return flags;
 }
 
+static uint8_t extract_capabilities(DBusMessageIter *array)
+{
+	static const struct flag_map capabilities_map[] = {
+		{ .value = "lte", .flag = LTE_CAPABLE },
+	};
+	uint32_t flags;
+
+	if (string_list_to_flags(array, capabilities_map,
+					G_N_ELEMENTS(capabilities_map),
+					&flags) < 0)
+		return 0;
+
+	return flags;
+}
+
 static char *extract_nameservers(DBusMessageIter *array)
 {
 	DBusMessageIter entry;
@@ -972,6 +997,9 @@ static bool try_create_device(struct modem_data *modem)
 	if (!modem->imsi)
 		return false;
 
+	if ((modem->capabilities & LTE_CAPABLE) &&
+			!has_interface(modem->interfaces, OFONO_API_LTE))
+		return false;
 
 	/*
 	 * Create the device and register it at the core. Enabling (setting
@@ -1940,6 +1968,9 @@ static void modem_update_interfaces(struct modem_data *modem,
 			netreg_get_properties(modem);
 	}
 
+	if (api_added(old_ifaces, new_ifaces, OFONO_API_LTE))
+		try_create_device(modem);
+
 	if (api_removed(old_ifaces, new_ifaces, OFONO_API_CM)) {
 		if (modem->call_get_contexts) {
 			DBG("cancelling pending GetContexts call");
@@ -2017,6 +2048,9 @@ static gboolean modem_changed(DBusConnection *conn, DBusMessage *message,
 		modem->serial = g_strdup(serial);
 
 		DBG("%s Serial %s", modem->path, modem->serial);
+	} else if (g_str_equal(key, "Capabilities")) {
+		modem->capabilities = extract_capabilities(&value);
+		return TRUE;
 	}
 
 	return TRUE;
@@ -2092,6 +2126,12 @@ static void add_modem(const char *path, DBusMessageIter *prop)
 				DBG("%s Ignore this modem", modem->path);
 				modem->ignore = true;
 			}
+		} else if (g_str_equal(key, "Capabilities")) {
+			modem->capabilities = extract_capabilities(&value);
+
+			DBG("lte capable: %s",
+					modem->capabilities & LTE_CAPABLE ?
+					"yes" : "no");
 		}
 
 		dbus_message_iter_next(prop);
-- 
2.43.0


  parent reply	other threads:[~2024-03-27 19:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27 19:43 [PATCH 1/4] ofono: Add generic method to convert a list of strings to flags Denis Kenzior
2024-03-27 19:43 ` [PATCH 2/4] ofono: Set modem->interfaces earlier Denis Kenzior
2024-03-27 19:43 ` [PATCH 3/4] ofono: combine create_device and ready_to_create_device Denis Kenzior
2024-03-27 19:43 ` Denis Kenzior [this message]
2024-04-17 17:00 ` [PATCH 1/4] ofono: Add generic method to convert a list of strings to flags patchwork-bot+connman

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=20240327194337.2735677-4-denkenz@gmail.com \
    --to=denkenz@gmail.com \
    --cc=connman@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;
as well as URLs for NNTP newsgroup(s).