diff options
-rw-r--r-- | docs/reference/libmm-glib/libmm-glib-sections.txt | 7 | ||||
-rw-r--r-- | introspection/org.freedesktop.ModemManager1.Modem.xml | 10 | ||||
-rw-r--r-- | libmm-glib/mm-modem.c | 82 | ||||
-rw-r--r-- | libmm-glib/mm-modem.h | 13 | ||||
-rw-r--r-- | src/mm-iface-modem.c | 140 | ||||
-rw-r--r-- | src/mm-iface-modem.h | 9 |
6 files changed, 261 insertions, 0 deletions
diff --git a/docs/reference/libmm-glib/libmm-glib-sections.txt b/docs/reference/libmm-glib/libmm-glib-sections.txt index 4bc13686..36a80f60 100644 --- a/docs/reference/libmm-glib/libmm-glib-sections.txt +++ b/docs/reference/libmm-glib/libmm-glib-sections.txt @@ -140,6 +140,9 @@ mm_modem_set_current_modes_sync mm_modem_set_current_bands mm_modem_set_current_bands_finish mm_modem_set_current_bands_sync +mm_modem_set_current_capabilities +mm_modem_set_current_capabilities_finish +mm_modem_set_current_capabilities_sync mm_modem_reset mm_modem_reset_finish mm_modem_reset_sync @@ -1490,6 +1493,9 @@ mm_gdbus_modem_call_set_current_modes_sync mm_gdbus_modem_call_set_current_bands mm_gdbus_modem_call_set_current_bands_finish mm_gdbus_modem_call_set_current_bands_sync +mm_gdbus_modem_call_set_current_capabilities +mm_gdbus_modem_call_set_current_capabilities_finish +mm_gdbus_modem_call_set_current_capabilities_sync mm_gdbus_modem_call_command mm_gdbus_modem_call_command_finish mm_gdbus_modem_call_command_sync @@ -1532,6 +1538,7 @@ mm_gdbus_modem_complete_list_bearers mm_gdbus_modem_complete_reset mm_gdbus_modem_complete_set_current_modes mm_gdbus_modem_complete_set_current_bands +mm_gdbus_modem_complete_set_current_capabilities mm_gdbus_modem_interface_info mm_gdbus_modem_override_properties <SUBSECTION Standard> diff --git a/introspection/org.freedesktop.ModemManager1.Modem.xml b/introspection/org.freedesktop.ModemManager1.Modem.xml index 46fa97dd..3f9af1aa 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.xml @@ -137,6 +137,16 @@ </method> <!-- + SetCurrentCapabilities: + @capabilities: Bitmask of <link linkend="MMModemCapability">MMModemCapability</link> values, to specify the capabilities to use. + + Set the capabilities of the device. A restart of the modem may be required. + --> + <method name="SetCurrentCapabilities"> + <arg name="capabilities" type="u" direction="in" /> + </method> + + <!-- SetCurrentModes: @modes: A pair of <link linkend="MMModemMode">MMModemMode</link> values, where the first one is a bitmask of allowed modes, and the second one the preferred mode, if any. diff --git a/libmm-glib/mm-modem.c b/libmm-glib/mm-modem.c index 39c7ff2e..95685e68 100644 --- a/libmm-glib/mm-modem.c +++ b/libmm-glib/mm-modem.c @@ -2415,6 +2415,88 @@ mm_modem_set_power_state_sync (MMModem *self, /*****************************************************************************/ /** + * mm_modem_set_current_capabilities_finish: + * @self: A #MMModem. + * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_set_current_capabilities(). + * @error: Return location for error or %NULL. + * + * Finishes an operation started with mm_modem_set_current_capabilities(). + * + * Returns: %TRUE if the capabilities were successfully set, %FALSE if @error is set. + */ +gboolean +mm_modem_set_current_capabilities_finish (MMModem *self, + GAsyncResult *res, + GError **error) +{ + g_return_val_if_fail (MM_IS_MODEM (self), FALSE); + + return mm_gdbus_modem_call_set_current_capabilities_finish (MM_GDBUS_MODEM (self), res, error); +} + +/** + * mm_modem_set_current_capabilities: + * @self: A #MMModem. + * @capabilities: A #MMModemCapability mask. + * @cancellable: (allow-none): A #GCancellable or %NULL. + * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. + * @user_data: User data to pass to @callback. + * + * Asynchronously sets the capabilities of the device. A restart of the modem may be required. + * + * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from. + * You can then call mm_modem_set_current_capabilities_finish() to get the result of the operation. + * + * See mm_modem_set_current_capabilities_sync() for the synchronous, blocking version of this method. + */ +void +mm_modem_set_current_capabilities (MMModem *self, + MMModemCapability capabilities, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + g_return_if_fail (MM_IS_MODEM (self)); + + mm_gdbus_modem_call_set_current_capabilities (MM_GDBUS_MODEM (self), + capabilities, + cancellable, + callback, + user_data); +} + +/** + * mm_modem_set_current_capabilities_sync: + * @self: A #MMModem. + * @capabilities: A #MMModemCapability mask. + * @cancellable: (allow-none): A #GCancellable or %NULL. + * @error: Return location for error or %NULL. + * + * Synchronously sets the capabilities of the device. A restart of the modem may be required. + * + * The calling thread is blocked until a reply is received. See mm_modem_set_current_capabilities() + * for the asynchronous version of this method. + * + * Returns: %TRUE if the capabilities were successfully set, %FALSE if @error is set. + */ +gboolean +mm_modem_set_current_capabilities_sync (MMModem *self, + MMModemCapability capabilities, + GCancellable *cancellable, + GError **error) +{ + g_return_val_if_fail (MM_IS_MODEM (self), FALSE); + + return (mm_gdbus_modem_call_set_current_capabilities_sync ( + MM_GDBUS_MODEM (self), + capabilities, + cancellable, + error)); +} + +/*****************************************************************************/ + +/** * mm_modem_set_current_modes_finish: * @self: A #MMModem. * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_set_current_modes(). diff --git a/libmm-glib/mm-modem.h b/libmm-glib/mm-modem.h index 3990a59d..a2ece5af 100644 --- a/libmm-glib/mm-modem.h +++ b/libmm-glib/mm-modem.h @@ -271,6 +271,19 @@ gboolean mm_modem_set_power_state_sync (MMModem *self, GCancellable *cancellable, GError **error); +void mm_modem_set_current_capabilities (MMModem *self, + MMModemCapability capabilities, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mm_modem_set_current_capabilities_finish (MMModem *self, + GAsyncResult *res, + GError **error); +gboolean mm_modem_set_current_capabilities_sync (MMModem *self, + MMModemCapability capabilities, + GCancellable *cancellable, + GError **error); + void mm_modem_set_current_modes (MMModem *self, MMModemMode modes, MMModemMode preferred, diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 9f9ad50d..86ecead7 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -1791,6 +1791,142 @@ handle_factory_reset (MmGdbusModem *skeleton, } /*****************************************************************************/ +/* Current capabilities setting */ + +typedef struct { + MmGdbusModem *skeleton; + GDBusMethodInvocation *invocation; + MMIfaceModem *self; + MMModemCapability capabilities; +} HandleSetCurrentCapabilitiesContext; + +static void +handle_set_current_capabilities_context_free (HandleSetCurrentCapabilitiesContext *ctx) +{ + g_object_unref (ctx->skeleton); + g_object_unref (ctx->invocation); + g_object_unref (ctx->self); + g_slice_free (HandleSetCurrentCapabilitiesContext, ctx); +} + +static void +set_current_capabilities_ready (MMIfaceModem *self, + GAsyncResult *res, + HandleSetCurrentCapabilitiesContext *ctx) +{ + GError *error = NULL; + + if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_current_capabilities_finish (self, res, &error)) + g_dbus_method_invocation_take_error (ctx->invocation, error); + else + mm_gdbus_modem_complete_set_current_capabilities (ctx->skeleton, ctx->invocation); + handle_set_current_capabilities_context_free (ctx); +} + +static void +handle_set_current_capabilities_auth_ready (MMBaseModem *self, + GAsyncResult *res, + HandleSetCurrentCapabilitiesContext *ctx) +{ + GError *error = NULL; + gchar *capabilities_string; + GArray *supported; + gboolean matched = FALSE; + guint i; + + if (!mm_base_modem_authorize_finish (self, res, &error)) { + g_dbus_method_invocation_take_error (ctx->invocation, error); + handle_set_current_capabilities_context_free (ctx); + return; + } + + /* Get list of supported capabilities */ + supported = mm_common_capability_combinations_variant_to_garray ( + mm_gdbus_modem_get_supported_capabilities (ctx->skeleton)); + + /* Don't allow capability switching if only one item given in the supported list */ + if (supported->len == 1) { + g_dbus_method_invocation_return_error (ctx->invocation, + MM_CORE_ERROR, + MM_CORE_ERROR_UNSUPPORTED, + "Cannot change capabilities: only one combination supported"); + handle_set_current_capabilities_context_free (ctx); + g_array_unref (supported); + return; + } + + /* Check if the given combination is supported */ + for (i = 0; !matched && i < supported->len; i++) { + MMModemCapability supported_capability; + + supported_capability = g_array_index (supported, MMModemCapability, i); + if (supported_capability == ctx->capabilities) + matched = TRUE; + } + g_array_unref (supported); + + if (!matched) { + g_dbus_method_invocation_return_error (ctx->invocation, + MM_CORE_ERROR, + MM_CORE_ERROR_UNSUPPORTED, + "The given combination of capabilities is not supported"); + handle_set_current_capabilities_context_free (ctx); + return; + } + + /* Check if we already are in the requested setup */ + if (mm_gdbus_modem_get_current_capabilities (ctx->skeleton) == ctx->capabilities) { + /* Nothing to do */ + mm_gdbus_modem_complete_set_current_capabilities (ctx->skeleton, ctx->invocation); + handle_set_current_capabilities_context_free (ctx); + return; + } + + /* If setting current capabilities is not implemented, report an error */ + if (!MM_IFACE_MODEM_GET_INTERFACE (self)->set_current_capabilities || + !MM_IFACE_MODEM_GET_INTERFACE (self)->set_current_capabilities_finish) { + g_dbus_method_invocation_return_error (ctx->invocation, + MM_CORE_ERROR, + MM_CORE_ERROR_UNSUPPORTED, + "Setting current capabilities not supported"); + handle_set_current_capabilities_context_free (ctx); + return; + } + + capabilities_string = mm_modem_capability_build_string_from_mask (ctx->capabilities); + mm_dbg ("Setting new list of capabilities: '%s'", capabilities_string); + g_free (capabilities_string); + + MM_IFACE_MODEM_GET_INTERFACE (self)->set_current_capabilities ( + MM_IFACE_MODEM (self), + ctx->capabilities, + (GAsyncReadyCallback)set_current_capabilities_ready, + ctx); +} + +static gboolean +handle_set_current_capabilities (MmGdbusModem *skeleton, + GDBusMethodInvocation *invocation, + guint capabilities, + MMIfaceModem *self) +{ + HandleSetCurrentCapabilitiesContext *ctx; + + ctx = g_slice_new (HandleSetCurrentCapabilitiesContext); + ctx->skeleton = g_object_ref (skeleton); + ctx->invocation = g_object_ref (invocation); + ctx->self = g_object_ref (self); + ctx->capabilities = capabilities; + + mm_base_modem_authorize (MM_BASE_MODEM (self), + invocation, + MM_AUTHORIZATION_DEVICE_CONTROL, + (GAsyncReadyCallback)handle_set_current_capabilities_auth_ready, + ctx); + return TRUE; +} + +/*****************************************************************************/ /* Current bands setting */ typedef struct { @@ -4312,6 +4448,10 @@ interface_initialization_step (InitializationContext *ctx) G_CALLBACK (handle_factory_reset), ctx->self); g_signal_connect (ctx->skeleton, + "handle-set-current-capabilities", + G_CALLBACK (handle_set_current_capabilities), + ctx->self); + g_signal_connect (ctx->skeleton, "handle-set-current-bands", G_CALLBACK (handle_set_current_bands), ctx->self); diff --git a/src/mm-iface-modem.h b/src/mm-iface-modem.h index 8f87bc6b..cadf31eb 100644 --- a/src/mm-iface-modem.h +++ b/src/mm-iface-modem.h @@ -217,6 +217,15 @@ struct _MMIfaceModem { GAsyncResult *res, GError **error); + /* Asynchronous capabilities setting operation */ + void (*set_current_capabilities) (MMIfaceModem *self, + MMModemCapability, + GAsyncReadyCallback callback, + gpointer user_data); + gboolean (*set_current_capabilities_finish) (MMIfaceModem *self, + GAsyncResult *res, + GError **error); + /* Asynchronous current band setting operation */ void (*set_current_bands) (MMIfaceModem *self, GArray *bands_array, |