ofono: Make the oFono Plugin Modem Interface Order Tolerant
cover ofono: Make the oFono Plugin Modem Interface Order Tolerant
This addresses and closes #135 by providing a secondary opportunity to send D-Bus request to get Connection Manager interface properties and contexts at the successful closure of 'try_create_device' since the primary opportunity in 'modem_update_interfaces' is missed in the following test case:
# connmanctl disable cellular
# /etc/init.d/connman stop
# /etc/init.d/ofono stop
# rm -rf /var/lib/ofono/*
# rm -rf /var/lib/connman/cellular*
# /etc/init.d/ofono start
# /etc/init.d/connman start
# connmanctl enable cellularAt this point, ofonod will create a fully-provisioned and -functional Cellular service, with both IPv4 and IPv6 Cellular network contexts. However, connmand has no network and no service associated with it so, so any Connection Manager client observing the Cellular service state will observe it failing, on timeout.
In this use case, the ordering of the oFono 'lte' (Long-term Evolution) and 'cm' (Connection Manager) modem interfaces shared between 'ofonod' and 'connmand' is different from what they normally are in the case where a Cellular connection has already been established. Consequently, when the 'cm' interface state change notification addition arrives, the connman device has not yet been created because in 'modem_update_interfaces' executing 'cm_get_properties' and 'cm_get_contexts' is dependent on the presence of 'modem->device':
if (api_added(old_ifaces, new_ifaces, OFONO_API_CM)) {
if (modem->device) {
cm_get_properties(modem);
cm_get_contexts(modem);
}
}Unfortunately, that does not and cannot happen until the 'lte' modem interface is added because 'try_create_device' has these conditionals:
if ((modem->capabilities & LTE_CAPABLE) &&
!has_interface(modem->interfaces, OFONO_API_LTE))
return false;and the 'lte' interface is added only moments later (rather than moments earlier as is normal outside this use case), but too late nonetheless. So, the ofono plugin will never get 'cm' interface properties or Cellular network contexts.
With this change, each call to 'try_create_device' now has an opportunity to check if the 'cm' interface has been added and, if it has, to request 'cm' properties and contexts.
Grant Erickson (4):
ofono: Add additional 'DBG' statements.
ofono: Use goto error-handling semantics in 'add_cm_context'.
ofono: Documentation: Add comment about entry condition for
'context_changed'.
ofono: Provide a secondary opportunity to get CM props and contexts.
plugins/ofono.c | 78 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 7 deletions(-)
Signature · 1 line
2.45.0
PATCH 1/4 ofono: Add additional 'DBG' statements.
Adds additional 'DBG' statements to make debugging current and future ofono integration and interactions easier.
--- plugins/ofono.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-)
plugins/ofono.c +30 -3
@@ -289,7 +289,7 @@ static void set_connected(struct modem_data *modem,char *nameservers;int index; -DBG ("%s" , modem->path); +DBG ("modem %p path %s context %p path %s" , modem, modem->path, context, context->path); index = context->index;
@@ -300,10 +300,14 @@ static void set_connected(struct modem_data *modem,return ; } +DBG ("context->network %p" , context->network); + service =connman_service_lookup_from_network (context->network);if (!service)return ; +DBG ("service %p" , service); +connman_service_create_ip4config (service, index);connman_network_set_ipv4_method (context->network, method);
@@ -1054,7 +1058,9 @@ static void add_network(struct modem_data *modem, {const char *group; -DBG ("%s" , modem->path); +DBG ("modem %p path %s context %p path %s network %p" , + modem, modem->path, + context, context->path, context->network);if (context->network)return ;
@@ -1295,10 +1301,14 @@ static gboolean context_changed(DBusConnection *conn,if (!modem)return TRUE; +DBG ("modem %p" , modem); + context =get_context_with_path (modem->context_list, context_path);if (!context)return TRUE; +DBG ("context %p" , context); +if (!dbus_message_iter_init (message, &iter))return TRUE;
@@ -1371,6 +1381,8 @@ static gboolean context_changed(DBusConnection *conn,dbus_message_iter_get_basic (&value, &ip_protocol); +DBG ("%s Protocol %s" , modem->path, ip_protocol); +set_context_ipconfig (context, ip_protocol); }
@@ -1520,7 +1532,12 @@ static gboolean cm_context_removed(DBusConnection *conn,if (!modem)return TRUE; +DBG ("modem %p" , modem); + context =get_context_with_path (modem->context_list, context_path); + +DBG ("context %p" , context); +remove_cm_context (modem, context);return TRUE;
@@ -1772,10 +1789,14 @@ static gboolean cm_changed(DBusConnection *conn, DBusMessage *message,DBusMessageIter iter, value;const char *key; +DBG ("" ); + modem =g_hash_table_lookup (modem_hash, path);if (!modem)return TRUE; +DBG ("modem %p modem->ignore %u" , modem, modem->ignore); +if (modem->ignore)return TRUE;
@@ -1849,6 +1870,8 @@ static gboolean sim_changed(DBusConnection *conn, DBusMessage *message,if (!modem)return TRUE; +DBG ("modem %p modem->ignore %u" , modem, modem->ignore); +if (modem->ignore)return TRUE;
@@ -1860,6 +1883,8 @@ static gboolean sim_changed(DBusConnection *conn, DBusMessage *message,dbus_message_iter_next (&iter);dbus_message_iter_recurse (&iter, &value); +DBG ("key %s" , key); +if (g_str_equal (key,"SubscriberIdentity" )) {sim_update_imsi (modem, &value);try_create_device (modem);
@@ -1943,9 +1968,10 @@ static void modem_update_interfaces(struct modem_data *modem, uint8_t old_ifaces, uint8_t new_ifaces) { -DBG ("%s" , modem->path); +DBG ("modem %p path %s" , modem, modem->path);if (api_added (old_ifaces, new_ifaces,OFONO_API_SIM )) { +DBG ("modem->imsi %p modem->set_powered %u" , modem->imsi, modem->set_powered);if (!modem->imsi && !modem->set_powered) {/*
@@ -1957,6 +1983,7 @@ static void modem_update_interfaces(struct modem_data *modem, }if (api_added (old_ifaces, new_ifaces,OFONO_API_CM )) { +DBG ("modem->device %p" , modem->device);if (modem->device) {cm_get_properties (modem);cm_get_contexts (modem);
Signature · 1 line
2.45.0
PATCH 2/4 ofono: Use goto error-handling semantics in 'add_cm_context'.
In reply to Grant EricksonEases current and future debugging of ofono cellular context additions by allowing for a single point of DBG instrumentation for the 'add_cm_context' return value, indicating whether or not the proposed context was added successfully.
--- plugins/ofono.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
plugins/ofono.c +11 -4
@@ -1160,12 +1160,15 @@ static int add_cm_context(struct modem_data *modem, const char *context_path,struct network_context *context =NULL ;dbus_bool_t active = FALSE;const char *ip_protocol =NULL ; +int err =0 ;DBG ("%s context path %s" , modem->path, context_path); context =network_context_alloc (context_path); -if (!context) -return -ENOMEM ; +if (!context) { + err = -ENOMEM ; + goto done; + }while (dbus_message_iter_get_arg_type (dict) ==DBUS_TYPE_DICT_ENTRY ) {DBusMessageIter entry, value;
@@ -1217,7 +1220,8 @@ static int add_cm_context(struct modem_data *modem, const char *context_path,if (g_strcmp0 (context_type,"internet" ) !=0 ) {network_context_unref (context); -return -EINVAL ; + err = -EINVAL ; + goto done; }if (ip_protocol)
@@ -1232,7 +1236,10 @@ static int add_cm_context(struct modem_data *modem, const char *context_path, has_interface(modem->interfaces, OFONO_API_NETREG))add_network (modem, context); -return 0 ; +done: +DBG ("err %d" , err); + +return err; } static void remove_cm_context(struct modem_data *modem,
Signature · 1 line
2.45.0
PATCH 3/4 ofono: Documentation: Add comment about entry condition for 'context_changed'.
In reply to Grant EricksonAdds a comment to the head of 'context_changed' detailing why the early exit condition exists: changed cellular contexts cannot be processed before they are added.
--- plugins/ofono.c | 6 ++++++ 1 file changed, 6 insertions(+)
plugins/ofono.c +6 -0
@@ -1304,6 +1304,12 @@ static gboolean context_changed(DBusConnection *conn,DBG ("context_path %s" , context_path); +/* +* If there is no modem in the context hash for the associated +* context path, then there is nothing to do at the moment as +* the context must first be added before we can process changes +* to it. +*/ modem =g_hash_table_lookup (context_hash, context_path);if (!modem)return TRUE;
Signature · 1 line
2.45.0
PATCH 4/4 ofono: Provide a secondary opportunity to get CM props and contexts.
In reply to Grant EricksonProvides a secondary opportunity to send D-Bus request to get Connection Manager interface properties and contexts at the successful closure of 'try_create_device' since the primary opportunity in 'modem_update_interfaces' is missed in the following test case:
# connmanctl disable cellular
# /etc/init.d/connman stop
# /etc/init.d/ofono stop
# rm -rf /var/lib/ofono/*
# rm -rf /var/lib/connman/cellular*
# /etc/init.d/ofono start
# /etc/init.d/connman start
# connmanctl enable cellularAt this point, ofonod will create a fully-provisioned and -functional Cellular service, with both IPv4 and IPv6 Cellular network contexts. However, connmand has no network and no service associated with it so, so any Connection Manager client observing the Cellular service state will observe it failing, on timeout.
In this use case, the ordering of the oFono 'lte' (Long-term Evolution) and 'cm' (Connection Manager) modem interfaces shared between ofonod and connmand is different from what they normally are in the case where a Cellular connection has already been established. Consequently, when the 'cm' interface state change notification addition arrives, the connman device has not yet been created because in 'modem_update_interfaces' executing 'cm_get_properties' and 'cm_get_contexts' is dependent on the presence of 'modem->device':
if (api_added(old_ifaces, new_ifaces, OFONO_API_CM)) {
if (modem->device) {
cm_get_properties(modem);
cm_get_contexts(modem);
}
}Unfortunately, that does not and cannot happen until the 'lte' modem interface is added because 'try_create_device' has these conditionals:
if ((modem->capabilities & LTE_CAPABLE) && !has_interface(modem->interfaces, OFONO_API_LTE)) return false;
and the 'lte' interface is added only moments later (rather than moments earlier as is normal outside this use case), but too late nonetheless. So, the ofono plugin will never get 'cm' interface properties or Cellular network contexts.
With this change, each call to 'try_create_device' now has an opportunity to check if the 'cm' interface has been added and, if it has, to request 'cm' properties and contexts.
--- plugins/ofono.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
plugins/ofono.c +24 -0
@@ -167,6 +167,9 @@ struct modem_data {DBusPendingCall *call_get_contexts; }; +static int cm_get_contexts (struct modem_data *modem); +static int cm_get_properties (struct modem_data *modem); +static const char *api2string (enum ofono_api api) {switch (api) {
@@ -1038,6 +1041,27 @@ static bool try_create_device(struct modem_data *modem) modem->device = device;connman_device_set_powered (modem->device, modem->online); +/* +* The order in which the LTE and Connection Manager interfaces +* arrive may not always be the same. +* +* If the latter arrived before the former and a modem device was +* successfully created, this represents a secondary opportunity +* to get Connection Manager properties and contexts, both +* essential to successfully creating a Connection Manager +* Cellular network and service. +* +* The primary opportunity would have been with api_added in +* modem_update_interfaces; however, that would have been skipped +* since the LTE interface did not yet exist in such a scenario +* and this call would exit early due to the LTE_CAPABLE and +* OFONO_API_LTE conditional checks above. +*/ +if (has_interface (modem->interfaces,OFONO_API_CM )) { +cm_get_properties (modem); +cm_get_contexts (modem); + } +return true; }
Signature · 1 line
2.45.0
This series was applied to connman.git (master) by Denis Kenzior <[email protected]>:
Hello:
This series was applied to connman.git (master)
by Denis Kenzior <[email protected]>:
Quoted 15 lines · On Wed, 12 Feb 2025 15:39:29 -0800 you wrote:
This addresses and closes #135 by providing a secondary opportunity to send D-Bus request to get Connection Manager interface properties and contexts at the successful closure of '
try_create_device' since the primary opportunity in 'modem_update_interfaces' is missed in the following test case:# connmanctl disable cellular # /etc/init.d/connman stop # /etc/init.d/ofono stop # rm -rf /var/lib/ofono/* # rm -rf /var/lib/connman/cellular* # /etc/init.d/ofono start # /etc/init.d/connman start # connmanctl enable cellular
Quoted 1 line
[...]
Here is the summary with links:
- [1/4] ofono: Add additional 'DBG' statements.
(no matching commit)
- [2/4] ofono: Use goto error-handling semantics in 'add_cm_context'.
https://git.kernel.org/pub/scm/network/connman/connman.git/?id=36154342e546 - [3/4] ofono: Documentation: Add comment about entry condition for 'context_changed'. https://git.kernel.org/pub/scm/network/connman/connman.git/?id=00e7dc2d528f - [4/4] ofono: Provide a secondary opportunity to get CM props and contexts. https://git.kernel.org/pub/scm/network/connman/connman.git/?id=0b091dd8fc8f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html