From 4e3d0ec3fd4a40b9c38e6278b0e70aadf9fbfb42 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 15 Jul 2013 12:31:23 +0200 Subject: mmcli,cdma: new '--cdma-activate-manual' action Along with a new '--cdma-activate-manual-with-prl'. These can be used to request CDMA Manual Activation, like: $> sudo mmcli \ -m 0 \ --cdma-activate-manual="spc=123456,sid=ab,mdn=0123456789abcde,min=0123456789abcde" Or: $> sudo mmcli \ -m 0 \ --cdma-activate-manual="spc=123456,sid=ab,mdn=0123456789abcde,min=0123456789abcde" \ --cdma-activate-manual-with-prl=/path/to/my/prl.data --- cli/mmcli-modem-cdma.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 1 deletion(-) (limited to 'cli/mmcli-modem-cdma.c') diff --git a/cli/mmcli-modem-cdma.c b/cli/mmcli-modem-cdma.c index 8841f7e8..1fc077ee 100644 --- a/cli/mmcli-modem-cdma.c +++ b/cli/mmcli-modem-cdma.c @@ -45,12 +45,22 @@ static Context *ctx; /* Options */ static gchar *activate_str; +static gchar *activate_manual_str; +static gchar *activate_manual_with_prl_str; static GOptionEntry entries[] = { { "cdma-activate", 0, 0, G_OPTION_ARG_STRING, &activate_str, "Provision the modem to use with a given carrier using OTA settings.", "[CARRIER]" }, + { "cdma-activate-manual", 0, 0, G_OPTION_ARG_STRING, &activate_manual_str, + "Provision the modem with the given settings. 'spc', 'sid', 'mdn' and 'min' are mandatory, 'mn-ha-key' and 'mn-aaa-key' are optional.", + "[\"key=value,...\"]" + }, + { "cdma-activate-manual-with-prl", 0, 0, G_OPTION_ARG_STRING, &activate_manual_with_prl_str, + "Use the given file contents as data for the PRL.", + "[File path]" + }, { NULL } }; @@ -78,13 +88,20 @@ mmcli_modem_cdma_options_enabled (void) if (checked) return !!n_actions; - n_actions = (!!activate_str); + n_actions = (!!activate_str + + !!activate_manual_str); if (n_actions > 1) { g_printerr ("error: too many CDMA actions requested\n"); exit (EXIT_FAILURE); } + if (activate_manual_with_prl_str && !activate_manual_str) { + g_printerr ("error: `--cdma-activate-manual-with-prl' must be given along " + "with `--cdma-activate-manual'\n"); + exit (EXIT_FAILURE); + } + checked = TRUE; return !!n_actions; } @@ -155,6 +172,81 @@ activate_ready (MMModemCdma *modem_cdma, mmcli_async_operation_done (); } +static void +activate_manual_process_reply (gboolean result, + const GError *error) +{ + if (!result) { + g_printerr ("error: couldn't manually activate the modem: '%s'\n", + error ? error->message : "unknown error"); + exit (EXIT_FAILURE); + } + + g_print ("successfully activated the modem manually\n"); +} + +static void +activate_manual_ready (MMModemCdma *modem_cdma, + GAsyncResult *result, + gpointer nothing) +{ + gboolean operation_result; + GError *error = NULL; + + operation_result = mm_modem_cdma_activate_manual_finish (modem_cdma, result, &error); + activate_manual_process_reply (operation_result, error); + + mmcli_async_operation_done (); +} + +static MMCdmaManualActivationProperties * +build_activate_manual_properties_from_input (const gchar *properties_string, + const gchar *prl_file) +{ + GError *error = NULL; + MMCdmaManualActivationProperties *properties; + + properties = mm_cdma_manual_activation_properties_new_from_string (properties_string, &error); + + if (!properties) { + g_printerr ("error: cannot parse properties string: '%s'\n", error->message); + exit (EXIT_FAILURE); + } + + if (prl_file) { + gchar *path; + GFile *file; + gchar *contents; + gsize contents_size; + + g_debug ("Reading data from file '%s'", prl_file); + + file = g_file_new_for_commandline_arg (prl_file); + path = g_file_get_path (file); + if (!g_file_get_contents (path, + &contents, + &contents_size, + &error)) { + g_printerr ("error: cannot read from file '%s': '%s'\n", + prl_file, error->message); + exit (EXIT_FAILURE); + } + g_free (path); + g_object_unref (file); + + if (!mm_cdma_manual_activation_properties_set_prl (properties, + (guint8 *)contents, + contents_size, + &error)) { + g_printerr ("error: cannot set PRL: '%s'\n", error->message); + exit (EXIT_FAILURE); + } + g_free (contents); + } + + return properties; +} + static void get_modem_ready (GObject *source, GAsyncResult *result, @@ -180,6 +272,23 @@ get_modem_ready (GObject *source, return; } + /* Request to manually activate the modem? */ + if (activate_manual_str) { + MMCdmaManualActivationProperties *properties; + + properties = build_activate_manual_properties_from_input (activate_manual_str, + activate_manual_with_prl_str); + + g_debug ("Asynchronously manually activating the modem..."); + mm_modem_cdma_activate_manual (ctx->modem_cdma, + properties, + ctx->cancellable, + (GAsyncReadyCallback)activate_manual_ready, + NULL); + g_object_unref (properties); + return; + } + g_warn_if_reached (); } @@ -232,5 +341,24 @@ mmcli_modem_cdma_run_synchronous (GDBusConnection *connection) return; } + /* Request to manually activate the modem? */ + if (activate_manual_str) { + MMCdmaManualActivationProperties *properties; + gboolean result; + + properties = build_activate_manual_properties_from_input (activate_manual_str, + activate_manual_with_prl_str); + + g_debug ("Synchronously manually activating the modem..."); + result = mm_modem_cdma_activate_manual_sync ( + ctx->modem_cdma, + properties, + NULL, + &error); + activate_manual_process_reply (result, error); + g_object_unref (properties); + return; + } + g_warn_if_reached (); } -- cgit v1.2.3-70-g09d2