diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-12-06 08:04:13 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2018-12-06 15:05:25 +0100 |
commit | 05522137e2e423f4ce2231ff71f25bbcfdd2f9c8 (patch) | |
tree | b60a0054e4bb14ade8d8a7a0f89d260c24cb7276 | |
parent | e974b3dd4181a8e45843ba8c9bfc18a1018fd877 (diff) | |
download | ModemManager-05522137e2e423f4ce2231ff71f25bbcfdd2f9c8.tar.gz |
api,modem-3gpp: new 'SetInitialEpsBearerSettings' method
This method allows users to modify the settings used during the
initial LTE attach procedure.
-rw-r--r-- | cli/mmcli-modem-3gpp.c | 76 | ||||
-rw-r--r-- | docs/reference/libmm-glib/libmm-glib-sections.txt | 7 | ||||
-rw-r--r-- | introspection/org.freedesktop.ModemManager1.Modem.Modem3gpp.xml | 28 | ||||
-rw-r--r-- | libmm-glib/mm-modem-3gpp.c | 86 | ||||
-rw-r--r-- | libmm-glib/mm-modem-3gpp.h | 13 | ||||
-rw-r--r-- | src/mm-iface-modem-3gpp.c | 161 | ||||
-rw-r--r-- | src/mm-iface-modem-3gpp.h | 9 |
7 files changed, 380 insertions, 0 deletions
diff --git a/cli/mmcli-modem-3gpp.c b/cli/mmcli-modem-3gpp.c index 18ff955c0..234fdf83b 100644 --- a/cli/mmcli-modem-3gpp.c +++ b/cli/mmcli-modem-3gpp.c @@ -51,6 +51,7 @@ static gboolean scan_flag; static gboolean register_home_flag; static gchar *register_in_operator_str; static gchar *set_eps_ue_mode_operation_str; +static gchar *set_initial_eps_bearer_settings_str; static gboolean ussd_status_flag; static gchar *ussd_initiate_str; static gchar *ussd_respond_str; @@ -73,6 +74,10 @@ static GOptionEntry entries[] = { "Set the UE mode of operation for EPS", "[ps-1|ps-2|csps-1|csps-2]" }, + { "3gpp-set-initial-eps-bearer-settings", 0, 0, G_OPTION_ARG_STRING, &set_initial_eps_bearer_settings_str, + "Set the initial EPS bearer settings", + "[\"key=value,...\"]" + }, { "3gpp-ussd-status", 0, 0, G_OPTION_ARG_NONE, &ussd_status_flag, "Show status of any ongoing USSD session", NULL @@ -120,6 +125,7 @@ mmcli_modem_3gpp_options_enabled (void) register_home_flag + !!register_in_operator_str + !!set_eps_ue_mode_operation_str + + !!set_initial_eps_bearer_settings_str + ussd_status_flag + !!ussd_initiate_str + !!ussd_respond_str + @@ -262,6 +268,32 @@ register_ready (MMModem3gpp *modem_3gpp, } static void +set_initial_eps_bearer_settings_process_reply (gboolean result, + const GError *error) +{ + if (!result) { + g_printerr ("error: couldn't set initial EPS bearer properties: '%s'\n", + error ? error->message : "unknown error"); + exit (EXIT_FAILURE); + } + + g_print ("Successfully set initial EPS bearer properties\n"); +} + +static void +set_initial_eps_bearer_settings_ready (MMModem3gpp *modem, + GAsyncResult *res) +{ + gboolean result; + GError *error = NULL; + + result = mm_modem_3gpp_set_initial_eps_bearer_settings_finish (modem, res, &error); + set_initial_eps_bearer_settings_process_reply (result, error); + + mmcli_async_operation_done (); +} + +static void set_eps_ue_mode_operation_process_reply (gboolean result, const GError *error) { @@ -452,6 +484,28 @@ get_modem_ready (GObject *source, return; } + /* Request to set initial EPS bearer properties? */ + if (set_initial_eps_bearer_settings_str) { + GError *error = NULL; + MMBearerProperties *config; + + config = mm_bearer_properties_new_from_string (set_initial_eps_bearer_settings_str, &error); + if (!config) { + g_printerr ("Error parsing properties string: '%s'\n", error->message); + exit (EXIT_FAILURE); + } + + g_debug ("Asynchronously setting initial EPS bearer properties..."); + mm_modem_3gpp_set_initial_eps_bearer_settings (ctx->modem_3gpp, + config, + ctx->cancellable, + (GAsyncReadyCallback)set_initial_eps_bearer_settings_ready, + NULL); + g_object_unref (config); + return; + + } + /* Request to initiate USSD session? */ if (ussd_initiate_str) { ensure_modem_3gpp_ussd (); @@ -568,6 +622,28 @@ mmcli_modem_3gpp_run_synchronous (GDBusConnection *connection) return; } + /* Request to set initial EPS bearer properties? */ + if (set_initial_eps_bearer_settings_str) { + GError *error = NULL; + gboolean result; + MMBearerProperties *config; + + config = mm_bearer_properties_new_from_string (set_initial_eps_bearer_settings_str, &error); + if (!config) { + g_printerr ("Error parsing properties string: '%s'\n", error->message); + exit (EXIT_FAILURE); + } + + g_debug ("Synchronously setting initial EPS bearer properties..."); + result = mm_modem_3gpp_set_initial_eps_bearer_settings_sync (ctx->modem_3gpp, + config, + NULL, + &error); + set_initial_eps_bearer_settings_process_reply (result, error); + g_object_unref (config); + return; + } + /* Request to show USSD status? */ if (ussd_status_flag) { ensure_modem_3gpp_ussd (); diff --git a/docs/reference/libmm-glib/libmm-glib-sections.txt b/docs/reference/libmm-glib/libmm-glib-sections.txt index 251dce823..b4e837c24 100644 --- a/docs/reference/libmm-glib/libmm-glib-sections.txt +++ b/docs/reference/libmm-glib/libmm-glib-sections.txt @@ -295,6 +295,9 @@ mm_modem_3gpp_scan_sync mm_modem_3gpp_set_eps_ue_mode_operation mm_modem_3gpp_set_eps_ue_mode_operation_finish mm_modem_3gpp_set_eps_ue_mode_operation_sync +mm_modem_3gpp_set_initial_eps_bearer_settings +mm_modem_3gpp_set_initial_eps_bearer_settings_finish +mm_modem_3gpp_set_initial_eps_bearer_settings_sync <SUBSECTION Standard> MMModem3gppClass MMModem3gppPrivate @@ -1783,10 +1786,14 @@ mm_gdbus_modem3gpp_call_scan_sync mm_gdbus_modem3gpp_call_set_eps_ue_mode_operation mm_gdbus_modem3gpp_call_set_eps_ue_mode_operation_finish mm_gdbus_modem3gpp_call_set_eps_ue_mode_operation_sync +mm_gdbus_modem3gpp_call_set_initial_eps_bearer_settings +mm_gdbus_modem3gpp_call_set_initial_eps_bearer_settings_finish +mm_gdbus_modem3gpp_call_set_initial_eps_bearer_settings_sync <SUBSECTION Private> mm_gdbus_modem3gpp_complete_register mm_gdbus_modem3gpp_complete_scan mm_gdbus_modem3gpp_complete_set_eps_ue_mode_operation +mm_gdbus_modem3gpp_complete_set_initial_eps_bearer_settings mm_gdbus_modem3gpp_interface_info mm_gdbus_modem3gpp_override_properties mm_gdbus_modem3gpp_set_enabled_facility_locks diff --git a/introspection/org.freedesktop.ModemManager1.Modem.Modem3gpp.xml b/introspection/org.freedesktop.ModemManager1.Modem.Modem3gpp.xml index f58683f6a..b0b078d94 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.Modem3gpp.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.Modem3gpp.xml @@ -96,6 +96,30 @@ </method> <!-- + SetInitialEpsBearerSettings: + @settings: List of properties to use when requesting the LTE attach procedure. + + Updates the default settings to be used in the initial default EPS bearer when registering to the LTE network. + + Allowed properties are: + <variablelist> + <varlistentry><term><literal>"apn"</literal></term> + <listitem><para>Access Point Name, given as a string value (signature <literal>"s"</literal>).</para></listitem></varlistentry> + <varlistentry><term><literal>"ip-type"</literal></term> + <listitem><para>Addressing type, given as a <link linkend="MMBearerIpFamily">MMBearerIpFamily</link> value (signature <literal>"u"</literal>).</para></listitem></varlistentry> + <varlistentry><term><literal>"allowed-auth"</literal></term> + <listitem><para>The authentication method to use, given as a <link linkend="MMBearerAllowedAuth">MMBearerAllowedAuth</link> value (signature <literal>"u"</literal>).</para></listitem></varlistentry> + <varlistentry><term><literal>"user"</literal></term> + <listitem><para>User name (if any) required by the network, given as a string value (signature <literal>"s"</literal>).</para></listitem></varlistentry> + <varlistentry><term><literal>"password"</literal></term> + <listitem><para>Password (if any) required by the network, given as a string value (signature <literal>"s"</literal>).</para></listitem></varlistentry> + </variablelist> + --> + <method name="SetInitialEpsBearerSettings"> + <arg name="settings" type="a{sv}" direction="in" /> + </method> + + <!-- Imei: The <ulink url="http://en.wikipedia.org/wiki/Imei">IMEI</ulink> of the device. @@ -192,6 +216,10 @@ procedure, e.g. if the device is roaming or no explicit settings were requested, so the properties shown in the #org.freedesktop.ModemManager1.Modem.Modem3gpp.InitialEpsBearer:InitialEpsBearer may be totally different. + + This is a read-only property, updating these settings should be done using the + <link linkend="gdbus-method-org-freedesktop-ModemManager1-Modem-Modem3gpp.SetInitialEpsBearerSettings">SetInitialEpsBearerSettings()</link> + method. --> <property name="InitialEpsBearerSettings" type="a{sv}" access="read" /> diff --git a/libmm-glib/mm-modem-3gpp.c b/libmm-glib/mm-modem-3gpp.c index 9be4cece7..7e99da851 100644 --- a/libmm-glib/mm-modem-3gpp.c +++ b/libmm-glib/mm-modem-3gpp.c @@ -1029,6 +1029,92 @@ mm_modem_3gpp_get_initial_eps_bearer_sync (MMModem3gpp *self, /*****************************************************************************/ +/** + * mm_modem_3gpp_set_initial_eps_bearer_settings_finish: + * @self: A #MMModem3gpp. + * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_3gpp_set_initial_eps_bearer_settings(). + * @error: Return location for error or %NULL. + * + * Finishes an operation started with mm_modem_3gpp_set_initial_eps_bearer_settings(). + * + * Returns: %TRUE if the operation was successful, %FALSE if @error is set. + */ +gboolean +mm_modem_3gpp_set_initial_eps_bearer_settings_finish (MMModem3gpp *self, + GAsyncResult *res, + GError **error) +{ + return mm_gdbus_modem3gpp_call_set_initial_eps_bearer_settings_finish (MM_GDBUS_MODEM3GPP (self), res, error); +} + +/** + * mm_modem_3gpp_set_initial_eps_bearer_settings: + * @self: A #MMModem3gpp. + * @config: A #MMBearerProperties object with the properties to use. + * @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 configures the settings for the initial LTE default bearer. + * + * 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_3gpp_set_initial_eps_bearer_settings_finish() to get the result of the operation. + */ +void +mm_modem_3gpp_set_initial_eps_bearer_settings (MMModem3gpp *self, + MMBearerProperties *config, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GVariant *dictionary; + + dictionary = mm_bearer_properties_get_dictionary (config); + mm_gdbus_modem3gpp_call_set_initial_eps_bearer_settings (MM_GDBUS_MODEM3GPP (self), + dictionary, + cancellable, + callback, + user_data); + g_variant_unref (dictionary); +} + +/** + * mm_modem_3gpp_set_initial_eps_bearer_settings_sync: + * @self: A #MMModem3gpp. + * @config: A #MMBearerProperties object with the properties to use. + * @cancellable: (allow-none): A #GCancellable or %NULL. + * @error: Return location for error or %NULL. + * + * Synchronously configures the settings for the initial LTE default bearer. + * + * The calling thread is blocked until a reply is received. See + * mm_modem_3gpp_set_initial_eps_bearer_settings() for the asynchronous + * version of this method. + * + * Returns: %TRUE if the operation was successful, %FALSE if @error is set. + */ +gboolean +mm_modem_3gpp_set_initial_eps_bearer_settings_sync (MMModem3gpp *self, + MMBearerProperties *config, + GCancellable *cancellable, + GError **error) +{ + gboolean result; + GVariant *dictionary; + + dictionary = mm_bearer_properties_get_dictionary (config); + result = mm_gdbus_modem3gpp_call_set_initial_eps_bearer_settings_sync (MM_GDBUS_MODEM3GPP (self), + dictionary, + cancellable, + error); + g_variant_unref (dictionary); + return result; +} + +/*****************************************************************************/ + static void mm_modem_3gpp_init (MMModem3gpp *self) { diff --git a/libmm-glib/mm-modem-3gpp.h b/libmm-glib/mm-modem-3gpp.h index ce7df740f..916a58de4 100644 --- a/libmm-glib/mm-modem-3gpp.h +++ b/libmm-glib/mm-modem-3gpp.h @@ -154,6 +154,19 @@ MMBearer *mm_modem_3gpp_get_initial_eps_bearer_sync (MMModem3gpp *sel GCancellable *cancellable, GError **error); +void mm_modem_3gpp_set_initial_eps_bearer_settings (MMModem3gpp *self, + MMBearerProperties *config, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mm_modem_3gpp_set_initial_eps_bearer_settings_finish (MMModem3gpp *self, + GAsyncResult *res, + GError **error); +gboolean mm_modem_3gpp_set_initial_eps_bearer_settings_sync (MMModem3gpp *self, + MMBearerProperties *config, + GCancellable *cancellable, + GError **error); + /* Deprecated APIs */ G_DEPRECATED MMModem3gppSubscriptionState mm_modem_3gpp_get_subscription_state (MMModem3gpp *self); diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index 5966b4c13..e5b40a14c 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -913,6 +913,163 @@ handle_set_eps_ue_mode_operation (MmGdbusModem3gpp *skeleton, /*****************************************************************************/ +typedef struct { + MmGdbusModem3gpp *skeleton; + GDBusMethodInvocation *invocation; + MMIfaceModem3gpp *self; + GVariant *dictionary; + MMBearerProperties *config; +} HandleSetInitialEpsBearerSettingsContext; + +static void +handle_set_initial_eps_bearer_settings_context_free (HandleSetInitialEpsBearerSettingsContext *ctx) +{ + g_clear_object (&ctx->config); + g_variant_unref (ctx->dictionary); + g_object_unref (ctx->skeleton); + g_object_unref (ctx->invocation); + g_object_unref (ctx->self); + g_slice_free (HandleSetInitialEpsBearerSettingsContext, ctx); +} + +static void +after_set_load_initial_eps_bearer_settings_ready (MMIfaceModem3gpp *self, + GAsyncResult *res, + HandleSetInitialEpsBearerSettingsContext *ctx) +{ + GError *error = NULL; + MMBearerProperties *new_config; + + new_config = MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->load_initial_eps_bearer_settings_finish (self, res, &error); + if (error) { + g_dbus_method_invocation_take_error (ctx->invocation, error); + handle_set_initial_eps_bearer_settings_context_free (ctx); + return; + } + + if (!mm_bearer_properties_cmp (new_config, ctx->config)) { + g_dbus_method_invocation_return_error_literal (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Initial EPS bearer settings were not updated"); + } else { + GVariant *dictionary; + + dictionary = mm_bearer_properties_get_dictionary (new_config); + mm_gdbus_modem3gpp_set_initial_eps_bearer_settings (ctx->skeleton, dictionary); + if (dictionary) + g_variant_unref (dictionary); + mm_gdbus_modem3gpp_complete_set_initial_eps_bearer_settings (ctx->skeleton, ctx->invocation); + } + + handle_set_initial_eps_bearer_settings_context_free (ctx); + g_object_unref (new_config); +} + +static void +set_initial_eps_bearer_settings_ready (MMIfaceModem3gpp *self, + GAsyncResult *res, + HandleSetInitialEpsBearerSettingsContext *ctx) +{ + GError *error = NULL; + + if (!MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->set_initial_eps_bearer_settings_finish (self, res, &error)) { + g_dbus_method_invocation_take_error (ctx->invocation, error); + handle_set_initial_eps_bearer_settings_context_free (ctx); + return; + } + + if (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->load_initial_eps_bearer_settings && + MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->load_initial_eps_bearer_settings_finish) { + MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->load_initial_eps_bearer_settings ( + self, + (GAsyncReadyCallback)after_set_load_initial_eps_bearer_settings_ready, + ctx); + return; + } + + /* Assume we're ok */ + mm_gdbus_modem3gpp_complete_set_initial_eps_bearer_settings (ctx->skeleton, ctx->invocation); + handle_set_initial_eps_bearer_settings_context_free (ctx); +} + +static void +set_initial_eps_bearer_settings_auth_ready (MMBaseModem *self, + GAsyncResult *res, + HandleSetInitialEpsBearerSettingsContext *ctx) +{ + GError *error = NULL; + MMBearerProperties *old_config = NULL; + GVariant *old_dictionary; + + if (!mm_base_modem_authorize_finish (self, res, &error)) { + g_dbus_method_invocation_take_error (ctx->invocation, error); + handle_set_initial_eps_bearer_settings_context_free (ctx); + return; + } + + /* If UE mode update is not implemented, report an error */ + if (!MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->set_initial_eps_bearer_settings || + !MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->set_initial_eps_bearer_settings_finish) { + g_dbus_method_invocation_return_error (ctx->invocation, + MM_CORE_ERROR, + MM_CORE_ERROR_UNSUPPORTED, + "Cannot set initial EPS bearer settings: operation not supported"); + handle_set_initial_eps_bearer_settings_context_free (ctx); + return; + } + + ctx->config = mm_bearer_properties_new_from_dictionary (ctx->dictionary, &error); + if (!ctx->config) { + g_dbus_method_invocation_take_error (ctx->invocation, error); + handle_set_initial_eps_bearer_settings_context_free (ctx); + return; + } + + /* If the user doesn't specify explicit auth settings, assume NONE as default */ + if (mm_bearer_properties_get_allowed_auth (ctx->config) == MM_BEARER_ALLOWED_AUTH_UNKNOWN) + mm_bearer_properties_set_allowed_auth (ctx->config, MM_BEARER_ALLOWED_AUTH_NONE); + + old_dictionary = mm_gdbus_modem3gpp_get_initial_eps_bearer_settings (ctx->skeleton); + if (old_dictionary) + old_config = mm_bearer_properties_new_from_dictionary (old_dictionary, NULL); + + if (old_config && mm_bearer_properties_cmp (ctx->config, old_config)) { + mm_gdbus_modem3gpp_complete_set_initial_eps_bearer_settings (ctx->skeleton, ctx->invocation); + handle_set_initial_eps_bearer_settings_context_free (ctx); + } else { + MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->set_initial_eps_bearer_settings ( + MM_IFACE_MODEM_3GPP (self), + ctx->config, + (GAsyncReadyCallback)set_initial_eps_bearer_settings_ready, + ctx); + } + + g_clear_object (&old_config); +} + +static gboolean +handle_set_initial_eps_bearer_settings (MmGdbusModem3gpp *skeleton, + GDBusMethodInvocation *invocation, + GVariant *dictionary, + MMIfaceModem3gpp *self) +{ + HandleSetInitialEpsBearerSettingsContext *ctx; + + ctx = g_slice_new0 (HandleSetInitialEpsBearerSettingsContext); + ctx->skeleton = g_object_ref (skeleton); + ctx->invocation = g_object_ref (invocation); + ctx->self = g_object_ref (self); + ctx->dictionary = g_variant_ref (dictionary); + + mm_base_modem_authorize (MM_BASE_MODEM (self), + invocation, + MM_AUTHORIZATION_DEVICE_CONTROL, + (GAsyncReadyCallback)set_initial_eps_bearer_settings_auth_ready, + ctx); + return TRUE; +} + +/*****************************************************************************/ + gboolean mm_iface_modem_3gpp_run_registration_checks_finish (MMIfaceModem3gpp *self, GAsyncResult *res, @@ -2288,6 +2445,10 @@ interface_initialization_step (GTask *task) "handle-set-eps-ue-mode-operation", G_CALLBACK (handle_set_eps_ue_mode_operation), self); + g_signal_connect (ctx->skeleton, + "handle-set-initial-eps-bearer-settings", + G_CALLBACK (handle_set_initial_eps_bearer_settings), + self); /* Finally, export the new interface */ mm_gdbus_object_skeleton_set_modem3gpp (MM_GDBUS_OBJECT_SKELETON (self), diff --git a/src/mm-iface-modem-3gpp.h b/src/mm-iface-modem-3gpp.h index 66bf4cddf..5e0928774 100644 --- a/src/mm-iface-modem-3gpp.h +++ b/src/mm-iface-modem-3gpp.h @@ -222,6 +222,15 @@ struct _MMIfaceModem3gpp { gboolean (* set_eps_ue_mode_operation_finish) (MMIfaceModem3gpp *self, GAsyncResult *res, GError **error); + + /* Set initial EPS bearer settings */ + void (* set_initial_eps_bearer_settings) (MMIfaceModem3gpp *self, + MMBearerProperties *properties, + GAsyncReadyCallback callback, + gpointer user_data); + gboolean (* set_initial_eps_bearer_settings_finish) (MMIfaceModem3gpp *self, + GAsyncResult *res, + GError **error); }; GType mm_iface_modem_3gpp_get_type (void); |