diff options
Diffstat (limited to 'cli/mmcli-modem-cell-broadcast.c')
-rw-r--r-- | cli/mmcli-modem-cell-broadcast.c | 115 |
1 files changed, 112 insertions, 3 deletions
diff --git a/cli/mmcli-modem-cell-broadcast.c b/cli/mmcli-modem-cell-broadcast.c index 8121e8a5..2e6c975f 100644 --- a/cli/mmcli-modem-cell-broadcast.c +++ b/cli/mmcli-modem-cell-broadcast.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * Copyright (C) 2024 Guido Günther <agx@sigxcpu.org> + * Copyright (C) 2024-2025 Guido Günther <agx@sigxcpu.org> */ #include "config.h" @@ -49,8 +49,13 @@ static Context *ctx; static gboolean status_flag; static gboolean list_flag; static gchar *delete_str; +static gchar *channels_str; static GOptionEntry entries[] = { + { "cell-broadcast-status", 0, 0, G_OPTION_ARG_NONE, &status_flag, + "Show cell broadcast status", + NULL + }, { "cell-broadcast-list-cbm", 0, 0, G_OPTION_ARG_NONE, &list_flag, "List cell broadcast messages available in a given modem", NULL @@ -59,6 +64,10 @@ static GOptionEntry entries[] = { "Delete a cell broadcast message from a given modem", "[PATH|INDEX]" }, + { "cell-broadcast-set-channels", 0, 0, G_OPTION_ARG_STRING, &channels_str, + "Set the channel list", + "[FIRST_CHANNEL-LAST_CHANNEL,FIRST_CHANNEL-LAST_CHANNEL...]" + }, { NULL } }; @@ -86,8 +95,10 @@ mmcli_modem_cell_broadcast_options_enabled (void) if (checked) return !!n_actions; - n_actions = (list_flag + - !!delete_str); + n_actions = (status_flag + + list_flag + + !!delete_str + + !!channels_str); if (n_actions > 1) { g_printerr ("error: too many Cell Broadcast actions requested\n"); @@ -156,6 +167,21 @@ output_cbm_info (MMCbm *cbm) } static void +print_cell_broadcast_status (void) +{ + g_autofree MMCellBroadcastChannels *channels = NULL; + guint channels_len = 0; + gchar *str = NULL; + + mm_modem_cell_broadcast_get_channels (ctx->modem_cell_broadcast, &channels, &channels_len); + if (channels) + str = mm_common_build_channels_string (channels, channels_len); + + mmcli_output_string_take (MMC_F_CELL_BROADCAST_CHANNELS, str); + mmcli_output_dump (); +} + +static void list_process_reply (GList *result, const GError *error) { @@ -238,6 +264,50 @@ get_cbm_to_delete_ready (GDBusConnection *connection, } static void +set_channels_process_reply (gboolean result, + const GError *error) +{ + if (!result) { + g_printerr ("error: couldn't set channels: '%s'\n", + error ? error->message : "unknown error"); + exit (EXIT_FAILURE); + } + + g_print ("successfully set channels in the modem\n"); +} + +static void +set_channels_ready (MMModemCellBroadcast *cell_broadcast, + GAsyncResult *result, + gpointer nothing) +{ + gboolean operation_result; + GError *error = NULL; + + operation_result = mm_modem_cell_broadcast_set_channels_finish (cell_broadcast, result, &error); + set_channels_process_reply (operation_result, error); + + mmcli_async_operation_done (); +} + +static void +parse_channels (MMCellBroadcastChannels **channels, + guint *n_channels) +{ + GError *error = NULL; + + mm_common_get_cell_broadcast_channels_from_string (channels_str, + channels, + n_channels, + &error); + if (error) { + g_printerr ("error: couldn't parse list of channels: '%s'\n", + error->message); + exit (EXIT_FAILURE); + } +} + +static void get_modem_ready (GObject *source, GAsyncResult *result, gpointer none) @@ -274,6 +344,21 @@ get_modem_ready (GObject *source, return; } + if (channels_str) { + g_autofree MMCellBroadcastChannels *channels = NULL; + guint n_channels; + + parse_channels (&channels, &n_channels); + g_debug ("Asynchronously setting channels..."); + mm_modem_cell_broadcast_set_channels (ctx->modem_cell_broadcast, + channels, + n_channels, + ctx->cancellable, + (GAsyncReadyCallback)set_channels_ready, + NULL); + return; + } + g_warn_if_reached (); } @@ -313,6 +398,13 @@ mmcli_modem_cell_broadcast_run_synchronous (GDBusConnection *connection) ensure_modem_cell_broadcast (); + /* Request to get cell broadcst status? */ + if (status_flag) { + g_debug ("Printing cell broadcast status..."); + print_cell_broadcast_status (); + return; + } + /* Request to list the CBM? */ if (list_flag) { GList *result; @@ -351,5 +443,22 @@ mmcli_modem_cell_broadcast_run_synchronous (GDBusConnection *connection) return; } + /* Set channels */ + if (channels_str) { + gboolean result; + g_autofree MMCellBroadcastChannels *channels = NULL; + guint n_channels; + + parse_channels (&channels, &n_channels); + g_debug ("Synchronously setting channels..."); + result = mm_modem_cell_broadcast_set_channels_sync (ctx->modem_cell_broadcast, + channels, + n_channels, + NULL, + &error); + set_channels_process_reply (result, error); + return; + } + g_warn_if_reached (); } |