base-modem: support non-serial ports when peeking the best AT port
When we don't care about the type of AT port to use, prefer the QMI or MBIM based ones if any available.
This commit is contained in:
committed by
Aleksander Morgado
parent
480e12c34e
commit
939be0fbf8
+1
-1
@@ -1052,7 +1052,7 @@ call_start (MMBaseCall *self,
|
||||
|
||||
task = g_task_new (self, NULL, callback, user_data);
|
||||
|
||||
port = MM_IFACE_PORT_AT (mm_base_modem_peek_best_at_port (MM_BASE_MODEM (self->priv->modem), &error));
|
||||
port = mm_base_modem_peek_best_at_port (MM_BASE_MODEM (self->priv->modem), &error);
|
||||
if (!port) {
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
|
||||
@@ -323,7 +323,7 @@ mm_base_modem_at_sequence (MMBaseModem *self,
|
||||
GError *error = NULL;
|
||||
|
||||
/* No port given, so we'll try to guess which is best */
|
||||
port = MM_IFACE_PORT_AT (mm_base_modem_peek_best_at_port (self, &error));
|
||||
port = mm_base_modem_peek_best_at_port (self, &error);
|
||||
if (!port) {
|
||||
g_task_report_error (self, callback, user_data, mm_base_modem_at_sequence, error);
|
||||
return;
|
||||
@@ -599,7 +599,7 @@ mm_base_modem_at_command (MMBaseModem *self,
|
||||
GError *error = NULL;
|
||||
|
||||
/* No port given, so we'll try to guess which is best */
|
||||
port = MM_IFACE_PORT_AT (mm_base_modem_peek_best_at_port (self, &error));
|
||||
port = mm_base_modem_peek_best_at_port (self, &error);
|
||||
if (!port) {
|
||||
g_task_report_error (self, callback, user_data, mm_base_modem_at_command, error);
|
||||
return;
|
||||
|
||||
+48
-16
@@ -1102,35 +1102,67 @@ mm_base_modem_peek_data_ports (MMBaseModem *self)
|
||||
return self->priv->data;
|
||||
}
|
||||
|
||||
MMPortSerialAt *
|
||||
mm_base_modem_get_best_at_port (MMBaseModem *self,
|
||||
GError **error)
|
||||
MMIfacePortAt *
|
||||
mm_base_modem_get_best_at_port (MMBaseModem *self,
|
||||
GError **error)
|
||||
{
|
||||
MMPortSerialAt *best;
|
||||
MMIfacePortAt *best;
|
||||
|
||||
best = mm_base_modem_peek_best_at_port (self, error);
|
||||
return (best ? g_object_ref (best) : NULL);
|
||||
}
|
||||
|
||||
MMPortSerialAt *
|
||||
mm_base_modem_peek_best_at_port (MMBaseModem *self,
|
||||
GError **error)
|
||||
MMIfacePortAt *
|
||||
mm_base_modem_peek_best_at_port (MMBaseModem *self,
|
||||
GError **error)
|
||||
{
|
||||
gboolean supported;
|
||||
|
||||
#if defined WITH_MBIM
|
||||
/* Prefer an AT-capable MBIM port instead of a serial port */
|
||||
if (self->priv->mbim) {
|
||||
GList *l;
|
||||
|
||||
for (l = self->priv->mbim; l; l = g_list_next (l)) {
|
||||
if (MM_IS_IFACE_PORT_AT (l->data) &&
|
||||
mm_iface_port_at_check_support (MM_IFACE_PORT_AT (l->data), &supported, NULL) &&
|
||||
supported)
|
||||
return MM_IFACE_PORT_AT (l->data);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined WITH_QMI
|
||||
/* Prefer an AT-capable QMI port instead of a serial port */
|
||||
if (self->priv->qmi) {
|
||||
GList *l;
|
||||
|
||||
for (l = self->priv->qmi; l; l = g_list_next (l)) {
|
||||
if (MM_IS_IFACE_PORT_AT (l->data) &&
|
||||
mm_iface_port_at_check_support (MM_IFACE_PORT_AT (l->data), &supported, NULL) &&
|
||||
supported)
|
||||
return MM_IFACE_PORT_AT (l->data);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Decide which port to use */
|
||||
if (self->priv->primary &&
|
||||
!mm_port_get_connected (MM_PORT (self->priv->primary)))
|
||||
return self->priv->primary;
|
||||
if (self->priv->primary && !mm_port_get_connected (MM_PORT (self->priv->primary))) {
|
||||
g_assert (MM_IS_IFACE_PORT_AT (self->priv->primary));
|
||||
g_assert (mm_iface_port_at_check_support (MM_IFACE_PORT_AT (self->priv->primary), &supported, NULL) && supported);
|
||||
return MM_IFACE_PORT_AT (self->priv->primary);
|
||||
}
|
||||
|
||||
/* If primary port is connected, check if we can get the secondary
|
||||
* port */
|
||||
if (self->priv->secondary &&
|
||||
!mm_port_get_connected (MM_PORT (self->priv->secondary)))
|
||||
return self->priv->secondary;
|
||||
if (self->priv->secondary && !mm_port_get_connected (MM_PORT (self->priv->secondary))) {
|
||||
g_assert (MM_IS_IFACE_PORT_AT (self->priv->secondary));
|
||||
g_assert (mm_iface_port_at_check_support (MM_IFACE_PORT_AT (self->priv->secondary), &supported, NULL) && supported);
|
||||
return MM_IFACE_PORT_AT (self->priv->secondary);
|
||||
}
|
||||
|
||||
/* Otherwise, we cannot get any port */
|
||||
g_set_error (error,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_CONNECTED,
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"No AT port available to run command");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+3
-2
@@ -35,6 +35,7 @@
|
||||
#include "mm-port-serial-at.h"
|
||||
#include "mm-port-serial-qcdm.h"
|
||||
#include "mm-port-serial-gps.h"
|
||||
#include "mm-iface-port-at.h"
|
||||
|
||||
#if defined WITH_QMI
|
||||
#include "mm-port-qmi.h"
|
||||
@@ -166,7 +167,7 @@ MMPortSerialQcdm *mm_base_modem_peek_port_qcdm (MMBaseModem *self);
|
||||
MMPortSerialAt *mm_base_modem_peek_port_gps_control (MMBaseModem *self);
|
||||
MMPortSerialGps *mm_base_modem_peek_port_gps (MMBaseModem *self);
|
||||
MMPortSerial *mm_base_modem_peek_port_audio (MMBaseModem *self);
|
||||
MMPortSerialAt *mm_base_modem_peek_best_at_port (MMBaseModem *self, GError **error);
|
||||
MMIfacePortAt *mm_base_modem_peek_best_at_port (MMBaseModem *self, GError **error);
|
||||
MMPort *mm_base_modem_peek_best_data_port (MMBaseModem *self, MMPortType type);
|
||||
GList *mm_base_modem_peek_data_ports (MMBaseModem *self);
|
||||
|
||||
@@ -176,7 +177,7 @@ MMPortSerialQcdm *mm_base_modem_get_port_qcdm (MMBaseModem *self);
|
||||
MMPortSerialAt *mm_base_modem_get_port_gps_control (MMBaseModem *self);
|
||||
MMPortSerialGps *mm_base_modem_get_port_gps (MMBaseModem *self);
|
||||
MMPortSerial *mm_base_modem_get_port_audio (MMBaseModem *self);
|
||||
MMPortSerialAt *mm_base_modem_get_best_at_port (MMBaseModem *self, GError **error);
|
||||
MMIfacePortAt *mm_base_modem_get_best_at_port (MMBaseModem *self, GError **error);
|
||||
MMPort *mm_base_modem_get_best_data_port (MMBaseModem *self, MMPortType type);
|
||||
GList *mm_base_modem_get_data_ports (MMBaseModem *self);
|
||||
|
||||
|
||||
+2
-2
@@ -1030,7 +1030,7 @@ sms_store (MMBaseSms *self,
|
||||
task = g_task_new (self, NULL, callback, user_data);
|
||||
|
||||
/* Select port for the operation */
|
||||
port = MM_IFACE_PORT_AT (mm_base_modem_peek_best_at_port (self->priv->modem, &error));
|
||||
port = mm_base_modem_peek_best_at_port (self->priv->modem, &error);
|
||||
if (!port) {
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
@@ -1333,7 +1333,7 @@ sms_send (MMBaseSms *self,
|
||||
task = g_task_new (self, NULL, callback, user_data);
|
||||
|
||||
/* Select port for the operation */
|
||||
port = MM_IFACE_PORT_AT (mm_base_modem_peek_best_at_port (self->priv->modem, &error));
|
||||
port = mm_base_modem_peek_best_at_port (self->priv->modem, &error);
|
||||
if (!port) {
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
|
||||
@@ -1707,7 +1707,7 @@ load_connection_status (MMBaseBearer *self,
|
||||
}
|
||||
|
||||
/* If no control port available, error out */
|
||||
port = MM_IFACE_PORT_AT (mm_base_modem_peek_best_at_port (modem, NULL));
|
||||
port = mm_base_modem_peek_best_at_port (modem, NULL);
|
||||
if (!port) {
|
||||
g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
|
||||
"Couldn't load connection status: no control port available");
|
||||
|
||||
@@ -2444,7 +2444,7 @@ modem_load_signal_quality (MMIfaceModem *_self,
|
||||
g_task_set_task_data (task, ctx, (GDestroyNotify)signal_quality_context_free);
|
||||
|
||||
/* Check whether we can get a non-connected AT port */
|
||||
ctx->at_port = MM_IFACE_PORT_AT (mm_base_modem_get_best_at_port (MM_BASE_MODEM (self), &error));
|
||||
ctx->at_port = mm_base_modem_get_best_at_port (MM_BASE_MODEM (self), &error);
|
||||
if (ctx->at_port) {
|
||||
if (!self->priv->modem_cind_disabled &&
|
||||
self->priv->modem_cind_supported &&
|
||||
@@ -5107,7 +5107,7 @@ modem_3gpp_register_in_network (MMIfaceModem3gpp *self,
|
||||
|
||||
task = g_task_new (self, cancellable, callback, user_data);
|
||||
|
||||
port = MM_IFACE_PORT_AT (mm_base_modem_peek_best_at_port (MM_BASE_MODEM (self), &error));
|
||||
port = mm_base_modem_peek_best_at_port (MM_BASE_MODEM (self), &error);
|
||||
if (!port) {
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
|
||||
@@ -138,7 +138,7 @@ load_connection_status (MMBaseBearer *self,
|
||||
g_task_set_task_data (task, GUINT_TO_POINTER ((guint)profile_id), NULL);
|
||||
|
||||
/* If no control port available, error out */
|
||||
port = MM_IFACE_PORT_AT (mm_base_modem_peek_best_at_port (modem, NULL));
|
||||
port = mm_base_modem_peek_best_at_port (modem, NULL);
|
||||
if (!port) {
|
||||
g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
|
||||
"Couldn't load connection status: no control port available");
|
||||
|
||||
Reference in New Issue
Block a user