diff options
author | Konrad ZapaĆowicz <konrad.zapalowicz@rigado.com> | 2022-04-18 21:35:12 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2023-04-10 09:52:26 +0000 |
commit | 4f4bd48db90ce329dc491db57a5e17b9002ea380 (patch) | |
tree | 3be3829121bc26d81a30209c00175cfc43f1f182 | |
parent | fdb9c1f06788072d3f803bc8a868a1a26c6c789a (diff) |
cinterion: use port type hints on modem probe
The Cinterion plugin is using the output of the SQPORT? to guess which
ports can be used for AT commands and data connection.
Yet at the same time the udev adds port type hints to the Cinterion
modem upon its discovery.
This commit changes the initialization in a way that from now on it
skips sending SQPORT? when the port type hints are already assigned. By
doing this we make sure that the udev port type hints are being used
when they are available. In case they are not the initialization relies
on the outout of SQPORT? as it did do far.
See: https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/782
-rw-r--r-- | src/plugins/cinterion/mm-plugin-cinterion.c | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/src/plugins/cinterion/mm-plugin-cinterion.c b/src/plugins/cinterion/mm-plugin-cinterion.c index 0dad015f..c4e46f00 100644 --- a/src/plugins/cinterion/mm-plugin-cinterion.c +++ b/src/plugins/cinterion/mm-plugin-cinterion.c @@ -27,6 +27,8 @@ #define _LIBMM_INSIDE_MM #include <libmm-glib.h> +#include <ModemManager-tags.h> + #include "mm-plugin-common.h" #include "mm-broadband-modem-cinterion.h" #include "mm-log-object.h" @@ -45,8 +47,9 @@ MM_DEFINE_PLUGIN (CINTERION, cinterion, Cinterion) /*****************************************************************************/ /* Custom init */ -#define TAG_CINTERION_APP_PORT "cinterion-app-port" -#define TAG_CINTERION_MODEM_PORT "cinterion-modem-port" +/* helps shorten a long if */ +#define CHECK_PORT_HAS_TAG(p, t) ( \ + mm_kernel_device_get_property_as_boolean (mm_port_probe_peek_port (p), t) ) static gboolean cinterion_custom_init_finish (MMPortProbe *probe, @@ -56,6 +59,21 @@ cinterion_custom_init_finish (MMPortProbe *probe, return g_task_propagate_boolean (G_TASK (result), error); } +/* is_port_already_tagged checks whether a port provided by probe has + * already tags assigned. */ +gboolean +is_port_already_tagged (MMPortProbe *probe) +{ + if (CHECK_PORT_HAS_TAG (probe, ID_MM_PORT_TYPE_AT_PRIMARY) || + CHECK_PORT_HAS_TAG (probe, ID_MM_PORT_TYPE_AT_SECONDARY) || + CHECK_PORT_HAS_TAG (probe, ID_MM_PORT_TYPE_AT_PPP) || + CHECK_PORT_HAS_TAG (probe, ID_MM_PORT_TYPE_GPS) ) { + return TRUE; + } + + return FALSE; +} + static void sqport_ready (MMPortSerialAt *port, GAsyncResult *res, @@ -73,9 +91,9 @@ sqport_ready (MMPortSerialAt *port, mm_port_probe_set_result_at (probe, TRUE); if (strstr (response, "Application")) - g_object_set_data (G_OBJECT (probe), TAG_CINTERION_APP_PORT, GUINT_TO_POINTER (TRUE)); + g_object_set_data (G_OBJECT (probe), ID_MM_PORT_TYPE_AT_PRIMARY, GUINT_TO_POINTER (TRUE)); else if (strstr (response, "Modem")) - g_object_set_data (G_OBJECT (probe), TAG_CINTERION_MODEM_PORT, GUINT_TO_POINTER (TRUE)); + g_object_set_data (G_OBJECT (probe), ID_MM_PORT_TYPE_AT_PPP, GUINT_TO_POINTER (TRUE)); } g_task_return_boolean (task, TRUE); @@ -93,6 +111,17 @@ cinterion_custom_init (MMPortProbe *probe, task = g_task_new (probe, cancellable, callback, user_data); + /* if the port is already tagged then it means that, most likely, udev + * has sorted things out. in that case it is not needed to run SQPORT? + * to try to guess whether this is AT-capable port. lets skip it. */ + if (is_port_already_tagged (probe)) { + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; + } + + /* alright, no tags on this port whatsoever so lets figure things out + * using SQPORT? */ mm_port_serial_at_command ( port, "AT^SQPORT?", @@ -156,17 +185,17 @@ grab_port (MMPlugin *self, ptype = mm_port_probe_get_port_type (probe); - if (g_object_get_data (G_OBJECT (probe), TAG_CINTERION_APP_PORT)) { - mm_obj_dbg (self, "port '%s/%s' flagged as primary", - mm_port_probe_get_port_subsys (probe), - mm_port_probe_get_port_name (probe)); + if (g_object_get_data (G_OBJECT (probe), ID_MM_PORT_TYPE_AT_PRIMARY)) { + mm_obj_dbg ("(%s/%s)' Port flagged as primary", + mm_port_probe_get_port_subsys (probe), + mm_port_probe_get_port_name (probe)); pflags = MM_PORT_SERIAL_AT_FLAG_PRIMARY; - } else if (g_object_get_data (G_OBJECT (probe), TAG_CINTERION_MODEM_PORT)) { - mm_obj_dbg (self, "port '%s/%s' flagged as PPP", - mm_port_probe_get_port_subsys (probe), - mm_port_probe_get_port_name (probe)); + } else if (g_object_get_data (G_OBJECT (probe), ID_MM_PORT_TYPE_AT_PPP)) { + mm_obj_dbg ("(%s/%s)' Port flagged as PPP", + mm_port_probe_get_port_subsys (probe), + mm_port_probe_get_port_name (probe)); pflags = MM_PORT_SERIAL_AT_FLAG_PPP; - } + } /* else unknown or set via generic udev tags */ return mm_base_modem_grab_port (modem, mm_port_probe_peek_port (probe), |