aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/mmcli-modem-cell-broadcast.c115
-rw-r--r--cli/mmcli-output.c2
-rw-r--r--cli/mmcli-output.h3
3 files changed, 117 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 ();
}
diff --git a/cli/mmcli-output.c b/cli/mmcli-output.c
index 1884e906..440d6059 100644
--- a/cli/mmcli-output.c
+++ b/cli/mmcli-output.c
@@ -50,6 +50,7 @@ static SectionInfo section_infos[] = {
[MMC_S_MODEM_3GPP_USSD] = { "3GPP USSD" },
[MMC_S_MODEM_3GPP_PROFILE_MANAGER] = { "3GPP profile manager" },
[MMC_S_MODEM_CDMA] = { "CDMA" },
+ [MMC_S_MODEM_CELL_BROADCAST] = { "Cell Broadcast" },
[MMC_S_MODEM_SIM] = { "SIM" },
[MMC_S_MODEM_BEARER] = { "Bearer" },
[MMC_S_MODEM_TIME] = { "Time" },
@@ -167,6 +168,7 @@ static FieldInfo field_infos[] = {
[MMC_F_CDMA_REGISTRATION_CDMA1X] = { "modem.cdma.cdma1x-registration-state", "registration cdma1x", MMC_S_MODEM_CDMA, },
[MMC_F_CDMA_REGISTRATION_EVDO] = { "modem.cdma.evdo-registration-state", "registration evdo", MMC_S_MODEM_CDMA, },
[MMC_F_CDMA_ACTIVATION] = { "modem.cdma.activation-state", "activation", MMC_S_MODEM_CDMA, },
+ [MMC_F_CELL_BROADCAST_CHANNELS] = { "modem.cellbroadcast.channels", "channels", MMC_S_MODEM_CELL_BROADCAST, },
[MMC_F_SIM_PATH] = { "modem.generic.sim", "primary sim path", MMC_S_MODEM_SIM, },
[MMC_F_SIM_PRIMARY_SLOT] = { "modem.generic.primary-sim-slot", NULL, MMC_S_MODEM_SIM, },
[MMC_F_SIM_SLOT_PATHS] = { "modem.generic.sim-slots", "sim slot paths", MMC_S_MODEM_SIM, },
diff --git a/cli/mmcli-output.h b/cli/mmcli-output.h
index 8dde1412..a9f050d8 100644
--- a/cli/mmcli-output.h
+++ b/cli/mmcli-output.h
@@ -46,6 +46,7 @@ typedef enum {
MMC_S_MODEM_3GPP_USSD,
MMC_S_MODEM_3GPP_PROFILE_MANAGER,
MMC_S_MODEM_CDMA,
+ MMC_S_MODEM_CELL_BROADCAST,
MMC_S_MODEM_SIM,
MMC_S_MODEM_BEARER,
MMC_S_MODEM_TIME,
@@ -173,6 +174,8 @@ typedef enum {
MMC_F_CDMA_REGISTRATION_CDMA1X,
MMC_F_CDMA_REGISTRATION_EVDO,
MMC_F_CDMA_ACTIVATION,
+ /* CellBroadcast section */
+ MMC_F_CELL_BROADCAST_CHANNELS,
/* SIM section */
MMC_F_SIM_PATH,
MMC_F_SIM_PRIMARY_SLOT,