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
This commit is contained in:
Konrad Zapałowicz
2022-04-18 21:35:12 +02:00
committed by Aleksander Morgado
parent fdb9c1f067
commit 4f4bd48db9

View File

@@ -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),