From c4f59aebe00c0cd25c4d27ed9e58b690e6b4b878 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 7 Jan 2022 12:53:30 +0100 Subject: mmcli,modem: new '--get-cell-info' action --- cli/mmcli-modem.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'cli/mmcli-modem.c') diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c index 2ab6438a..f8fa6c1b 100644 --- a/cli/mmcli-modem.c +++ b/cli/mmcli-modem.c @@ -64,6 +64,7 @@ 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 get_cell_info_flag; static gboolean inhibit_flag; static GOptionEntry entries[] = { @@ -131,6 +132,10 @@ static GOptionEntry entries[] = { "Switch to the selected SIM slot", "[SLOT NUMBER]" }, + { "get-cell-info", 0, 0, G_OPTION_ARG_NONE, &get_cell_info_flag, + "Get cell info", + NULL + }, { "inhibit", 0, 0, G_OPTION_ARG_NONE, &inhibit_flag, "Inhibit the modem", NULL @@ -179,6 +184,7 @@ mmcli_modem_options_enabled (void) !!set_preferred_mode_str + !!set_current_bands_str + (set_primary_sim_slot_int > 0) + + get_cell_info_flag + inhibit_flag); if (n_actions == 0 && mmcli_get_common_modem_string ()) { @@ -939,6 +945,35 @@ set_primary_sim_slot_ready (MMModem *modem, mmcli_async_operation_done (); } +static void +get_cell_info_process_reply (GList *list, + const GError *error) +{ + if (!list) { + g_printerr ("error: couldn't get cell info in the modem: '%s'\n", + error ? error->message : "unknown error"); + exit (EXIT_FAILURE); + } + + mmcli_output_cell_info (list); + mmcli_output_dump (); + + g_list_free_full (list, (GDestroyNotify) g_object_unref); +} + +static void +get_cell_info_ready (MMModem *modem, + GAsyncResult *result) +{ + GList *list; + g_autoptr(GError) error = NULL; + + list = mm_modem_get_cell_info_finish (modem, result, &error); + get_cell_info_process_reply (list, error); + + mmcli_async_operation_done (); +} + static void state_changed (MMModem *modem, MMModemState old_state, @@ -1191,6 +1226,15 @@ get_modem_ready (GObject *source, return; } + /* Request to get cell info? */ + if (get_cell_info_flag) { + mm_modem_get_cell_info (ctx->modem, + ctx->cancellable, + (GAsyncReadyCallback)get_cell_info_ready, + NULL); + return; + } + /* Request to inhibit the modem? */ if (inhibit_flag) { gchar *uid; @@ -1459,5 +1503,14 @@ mmcli_modem_run_synchronous (GDBusConnection *connection) return; } + /* Request to get cell info? */ + if (get_cell_info_flag) { + GList *list; + + list = mm_modem_get_cell_info_sync (ctx->modem, NULL, &error); + get_cell_info_process_reply (list, error); + return; + } + g_warn_if_reached (); } -- cgit v1.2.3-70-g09d2