aboutsummaryrefslogtreecommitdiff
path: root/cli/mmcli-modem.c
diff options
context:
space:
mode:
Diffstat (limited to 'cli/mmcli-modem.c')
-rw-r--r--cli/mmcli-modem.c51
1 files changed, 51 insertions, 0 deletions
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 ()) {
@@ -891,6 +897,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,
MMModemState new_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 ();
}