From 924cf1af3c5e1aec1df680d50e4b9ae6dd8e0ba9 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 1 Aug 2020 09:59:37 +0200 Subject: [PATCH] api,modem: new 'SetPrimarySimSlot' method This new method allows changing the SIM slot considered as primary, when the modem supports multiple SIM slots. The generic handling of this method will make sure that the modem object and all its SIM objects are re-probed from scratch as soon as a successful SIM slot switch happens. Implementations may report MM_CORE_ERROR_EXISTS when the switch doesn't need to happen (e.g. if the requested SIM slot is already the active one). --- cli/mmcli-modem.c | 51 ++++++++ docs/man/mmcli.1 | 6 + .../libmm-glib/libmm-glib-sections.txt | 7 ++ .../org.freedesktop.ModemManager1.Modem.xml | 18 +++ libmm-glib/mm-modem.c | 87 ++++++++++++++ libmm-glib/mm-modem.h | 13 ++ src/mm-iface-modem.c | 112 ++++++++++++++++++ src/mm-iface-modem.h | 9 ++ 8 files changed, 303 insertions(+) diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c index 2ca24495..9d82fa33 100644 --- a/cli/mmcli-modem.c +++ b/cli/mmcli-modem.c @@ -63,6 +63,7 @@ static gchar *set_current_capabilities_str; static gchar *set_allowed_modes_str; static gchar *set_preferred_mode_str; static gchar *set_current_bands_str; +static gint set_primary_sim_slot_int; static gboolean inhibit_flag; static GOptionEntry entries[] = { @@ -126,6 +127,10 @@ static GOptionEntry entries[] = { "Set bands to be used by a given modem.", "[BAND1|BAND2...]" }, + { "set-primary-sim-slot", 0, 0, G_OPTION_ARG_INT, &set_primary_sim_slot_int, + "Switch to the selected SIM slot", + "[SLOT NUMBER]" + }, { "inhibit", 0, 0, G_OPTION_ARG_NONE, &inhibit_flag, "Inhibit the modem", NULL @@ -173,6 +178,7 @@ mmcli_modem_options_enabled (void) !!set_allowed_modes_str + !!set_preferred_mode_str + !!set_current_bands_str + + (set_primary_sim_slot_int > 0) + inhibit_flag); if (n_actions == 0 && mmcli_get_common_modem_string ()) { @@ -890,6 +896,32 @@ parse_current_bands (MMModemBand **bands, } } +static void +set_primary_sim_slot_process_reply (gboolean result, + const GError *error) +{ + if (!result) { + g_printerr ("error: couldn't request primary SIM switch: '%s'\n", + error ? error->message : "unknown error"); + exit (EXIT_FAILURE); + } + + g_print ("successfully requested primary SIM switch in modem\n"); +} + +static void +set_primary_sim_slot_ready (MMModem *modem, + GAsyncResult *result) +{ + gboolean operation_result; + g_autoptr(GError) error = NULL; + + operation_result = mm_modem_set_primary_sim_slot_finish (modem, result, &error); + set_primary_sim_slot_process_reply (operation_result, error); + + mmcli_async_operation_done (); +} + static void state_changed (MMModem *modem, MMModemState old_state, @@ -1132,6 +1164,16 @@ get_modem_ready (GObject *source, return; } + /* Request to switch SIM? */ + if (set_primary_sim_slot_int > 0) { + mm_modem_set_primary_sim_slot (ctx->modem, + set_primary_sim_slot_int, + ctx->cancellable, + (GAsyncReadyCallback)set_primary_sim_slot_ready, + NULL); + return; + } + /* Request to inhibit the modem? */ if (inhibit_flag) { gchar *uid; @@ -1391,5 +1433,14 @@ mmcli_modem_run_synchronous (GDBusConnection *connection) return; } + /* Request to switch current SIM? */ + if (set_primary_sim_slot_int > 0) { + gboolean result; + + result = mm_modem_set_primary_sim_slot_sync (ctx->modem, set_primary_sim_slot_int, NULL, &error); + set_primary_sim_slot_process_reply (result, error); + return; + } + g_warn_if_reached (); } diff --git a/docs/man/mmcli.1 b/docs/man/mmcli.1 index 3730a883..3e86931c 100644 --- a/docs/man/mmcli.1 +++ b/docs/man/mmcli.1 @@ -281,6 +281,12 @@ MMModemBand documentation. An example would be: 'egsm|dcs|pcs|g850' to select all the GSM frequency bands. .TP +.B \-\-set\-primary\-sim\-slot=[SLOT] +Request to switch the primary SIM slot. + +The given \fBSLOT\fR must be a valid slot number in the [1,N] range, where +N is the amount of SIM slots available in the system. +.TP .B \-\-inhibit Inhibit the specific modem from being used by ModemManager. This method is completely equivalent to \fB\-\-inhibit\-device\fR, with the only diff --git a/docs/reference/libmm-glib/libmm-glib-sections.txt b/docs/reference/libmm-glib/libmm-glib-sections.txt index eb8d66e2..1e283f2c 100644 --- a/docs/reference/libmm-glib/libmm-glib-sections.txt +++ b/docs/reference/libmm-glib/libmm-glib-sections.txt @@ -188,6 +188,9 @@ mm_modem_get_primary_sim_slot mm_modem_list_sim_slots mm_modem_list_sim_slots_finish mm_modem_list_sim_slots_sync +mm_modem_set_primary_sim_slot +mm_modem_set_primary_sim_slot_finish +mm_modem_set_primary_sim_slot_sync mm_modem_enable mm_modem_enable_finish @@ -2135,6 +2138,9 @@ 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_set_primary_sim_slot +mm_gdbus_modem_call_set_primary_sim_slot_finish +mm_gdbus_modem_call_set_primary_sim_slot_sync mm_gdbus_modem_call_command mm_gdbus_modem_call_command_finish mm_gdbus_modem_call_command_sync @@ -2185,6 +2191,7 @@ 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_complete_set_primary_sim_slot mm_gdbus_modem_interface_info mm_gdbus_modem_override_properties diff --git a/introspection/org.freedesktop.ModemManager1.Modem.xml b/introspection/org.freedesktop.ModemManager1.Modem.xml index 9b8d2d6d..d9dbd436 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.xml @@ -182,6 +182,24 @@ + + + + +