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 @@ + + + + +