foxconn: don't assume parent location is available

If ModemManager is not built with QMI support, the generic MBIM modem
object will not have any location support, so we cannot assume that
iface_modem_location_parent will be valid and that it will have all
load_location_capabilities(), enable_location_gathering() and
disable_location_gathering() implemented.

Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/362
This commit is contained in:
Aleksander Morgado
2021-05-03 00:10:00 +02:00
parent 9e2c9cce97
commit e1567c30df

View File

@@ -188,6 +188,26 @@ location_load_capabilities_finish (MMIfaceModemLocation *self,
return (MMModemLocationSource)value; return (MMModemLocationSource)value;
} }
static void
custom_location_load_capabilities (GTask *task,
MMModemLocationSource sources)
{
MMBroadbandModemMbimFoxconn *self;
self = g_task_get_source_object (task);
/* If we have a GPS port and an AT port, enable unmanaged GPS support */
if (mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)) &&
mm_base_modem_peek_port_gps (MM_BASE_MODEM (self))) {
self->priv->unmanaged_gps_support = FEATURE_SUPPORTED;
sources |= MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED;
}
/* So we're done, complete */
g_task_return_int (task, sources);
g_object_unref (task);
}
static void static void
parent_load_capabilities_ready (MMIfaceModemLocation *self, parent_load_capabilities_ready (MMIfaceModemLocation *self,
GAsyncResult *res, GAsyncResult *res,
@@ -203,16 +223,7 @@ parent_load_capabilities_ready (MMIfaceModemLocation *self,
return; return;
} }
/* If we have a GPS port and an AT port, enable unmanaged GPS support */ custom_location_load_capabilities (task, sources);
if (mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)) &&
mm_base_modem_peek_port_gps (MM_BASE_MODEM (self))) {
MM_BROADBAND_MODEM_MBIM_FOXCONN (self)->priv->unmanaged_gps_support = FEATURE_SUPPORTED;
sources |= MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED;
}
/* So we're done, complete */
g_task_return_int (task, sources);
g_object_unref (task);
} }
static void static void
@@ -224,10 +235,18 @@ location_load_capabilities (MMIfaceModemLocation *self,
task = g_task_new (self, NULL, callback, user_data); task = g_task_new (self, NULL, callback, user_data);
/* Chain up parent's setup */ /* Chain up parent's setup, if any. If MM is built without QMI support,
iface_modem_location_parent->load_capabilities (self, * the MBIM modem won't have any location capabilities. */
(GAsyncReadyCallback)parent_load_capabilities_ready, if (iface_modem_location_parent &&
task); iface_modem_location_parent->load_capabilities &&
iface_modem_location_parent->load_capabilities_finish) {
iface_modem_location_parent->load_capabilities (self,
(GAsyncReadyCallback)parent_load_capabilities_ready,
task);
return;
}
custom_location_load_capabilities (task, MM_MODEM_LOCATION_SOURCE_NONE);
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -264,10 +283,19 @@ parent_disable_location_gathering (GTask *task)
self = MM_IFACE_MODEM_LOCATION (g_task_get_source_object (task)); self = MM_IFACE_MODEM_LOCATION (g_task_get_source_object (task));
source = GPOINTER_TO_UINT (g_task_get_task_data (task)); source = GPOINTER_TO_UINT (g_task_get_task_data (task));
iface_modem_location_parent->disable_location_gathering (self, if (iface_modem_location_parent &&
source, iface_modem_location_parent->disable_location_gathering &&
(GAsyncReadyCallback)parent_disable_location_gathering_ready, iface_modem_location_parent->disable_location_gathering_finish) {
task); iface_modem_location_parent->disable_location_gathering (
self,
source,
(GAsyncReadyCallback)parent_disable_location_gathering_ready,
task);
return;
}
g_task_return_boolean (task, TRUE);
g_object_unref (task);
} }
static void static void
@@ -339,22 +367,15 @@ unmanaged_gps_enabled_ready (MMBaseModem *self,
} }
static void static void
parent_enable_location_gathering_ready (MMIfaceModemLocation *_self, custom_enable_location_gathering (GTask *task)
GAsyncResult *res,
GTask *task)
{ {
MMBroadbandModemMbimFoxconn *self = MM_BROADBAND_MODEM_MBIM_FOXCONN (_self); MMBroadbandModemMbimFoxconn *self;
GError *error = NULL;
MMModemLocationSource source; MMModemLocationSource source;
if (!iface_modem_location_parent->enable_location_gathering_finish (_self, res, &error)) { self = g_task_get_source_object (task);
g_task_return_error (task, error); source = GPOINTER_TO_UINT (g_task_get_task_data (task));
g_object_unref (task);
return;
}
/* We only support Unmanaged GPS at this level */ /* We only support Unmanaged GPS at this level */
source = GPOINTER_TO_UINT (g_task_get_task_data (task));
if ((self->priv->unmanaged_gps_support != FEATURE_SUPPORTED) || if ((self->priv->unmanaged_gps_support != FEATURE_SUPPORTED) ||
(source != MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) { (source != MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) {
g_task_return_boolean (task, TRUE); g_task_return_boolean (task, TRUE);
@@ -362,7 +383,7 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *_self,
return; return;
} }
mm_base_modem_at_command (MM_BASE_MODEM (_self), mm_base_modem_at_command (MM_BASE_MODEM (self),
"^NV=30007,01,\"01\"", "^NV=30007,01,\"01\"",
3, 3,
FALSE, FALSE,
@@ -370,6 +391,22 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *_self,
task); task);
} }
static void
parent_enable_location_gathering_ready (MMIfaceModemLocation *self,
GAsyncResult *res,
GTask *task)
{
GError *error = NULL;
if (!iface_modem_location_parent->enable_location_gathering_finish (self, res, &error)) {
g_task_return_error (task, error);
g_object_unref (task);
return;
}
custom_enable_location_gathering (task);
}
static void static void
enable_location_gathering (MMIfaceModemLocation *self, enable_location_gathering (MMIfaceModemLocation *self,
MMModemLocationSource source, MMModemLocationSource source,
@@ -382,10 +419,18 @@ enable_location_gathering (MMIfaceModemLocation *self,
g_task_set_task_data (task, GUINT_TO_POINTER (source), NULL); g_task_set_task_data (task, GUINT_TO_POINTER (source), NULL);
/* Chain up parent's gathering enable */ /* Chain up parent's gathering enable */
iface_modem_location_parent->enable_location_gathering (self, if (iface_modem_location_parent &&
source, iface_modem_location_parent->enable_location_gathering &&
(GAsyncReadyCallback)parent_enable_location_gathering_ready, iface_modem_location_parent->enable_location_gathering_finish) {
task); iface_modem_location_parent->enable_location_gathering (
self,
source,
(GAsyncReadyCallback)parent_enable_location_gathering_ready,
task);
return;
}
custom_enable_location_gathering (task);
} }
/*****************************************************************************/ /*****************************************************************************/