diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-06-27 17:06:15 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-03 16:08:57 +0200 |
commit | 0cdad572f53d1401252d3f950e55a30445ce6acd (patch) | |
tree | 0abe033c5dfbc9baaf27e67abc62657eff426fb5 | |
parent | a74dd19cdb5cbb3f02eff034aeb0a66337a39743 (diff) |
cli: new `--dms-verify-pin' action
Allows to verify the PIN, e.g:
$> sudo qmicli -d /dev/cdc-wdm0 \
--dms-verify-pin="PIN,1234"
-rw-r--r-- | cli/qmicli-dms.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/cli/qmicli-dms.c b/cli/qmicli-dms.c index f7e8d5e..05d7043 100644 --- a/cli/qmicli-dms.c +++ b/cli/qmicli-dms.c @@ -49,6 +49,7 @@ static gboolean get_revision_flag; static gboolean get_msisdn_flag; static gboolean get_power_state_flag; static gchar *set_pin_protection_str; +static gchar *verify_pin_str; static gboolean noop_flag; static GOptionEntry entries[] = { @@ -84,6 +85,10 @@ static GOptionEntry entries[] = { "Set PIN protection", "[(PIN|PIN2),(disable|enable),(current PIN)]", }, + { "dms-verify-pin", 0, 0, G_OPTION_ARG_STRING, &verify_pin_str, + "Verify PIN", + "[(PIN|PIN2),(current PIN)]", + }, { "dms-noop", 0, 0, G_OPTION_ARG_NONE, &noop_flag, "Just allocate or release a DMS client. Use with `--client-no-release-cid' and/or `--client-cid'", NULL @@ -123,6 +128,7 @@ qmicli_dms_options_enabled (void) get_msisdn_flag + get_power_state_flag + !!set_pin_protection_str + + !!verify_pin_str + noop_flag); if (n_actions > 1) { @@ -544,6 +550,87 @@ set_pin_protection_ready (QmiClientDms *client, shutdown (TRUE); } +static QmiMessageDmsVerifyPinInput * +verify_pin_input_create (const gchar *str) +{ + QmiMessageDmsVerifyPinInput *input; + QmiMessageDmsVerifyPinInputInfo info; + gchar **split; + + /* Prepare inputs. + * Format of the string is: + * "[(PIN|PIN2),(current PIN)]" + */ + input = qmi_message_dms_verify_pin_input_new (); + + split = g_strsplit (str, ",", -1); + + if (g_str_equal (split[0], "PIN")) + info.pin_id = QMI_DMS_PIN_ID_PIN; + else if (g_str_equal (split[0], "PIN2")) + info.pin_id = QMI_DMS_PIN_ID_PIN2; + else { + g_printerr ("error: expected 'PIN' or 'PIN2', got: '%s'\n", + split[0]); + exit (EXIT_FAILURE); + } + + info.pin = split[1]; + if (info.pin[0] == '\0') { + g_printerr ("error: empty current PIN given\n"); + exit (EXIT_FAILURE); + } + + qmi_message_dms_verify_pin_input_set_info (input, info, NULL); + g_strfreev (split); + + return input; +} + +static void +verify_pin_ready (QmiClientDms *client, + GAsyncResult *res) +{ + QmiMessageDmsVerifyPinOutput *output; + GError *error = NULL; + + output = qmi_client_dms_verify_pin_finish (client, res, &error); + if (!output) { + g_printerr ("error: operation failed: %s\n", error->message); + g_error_free (error); + shutdown (FALSE); + return; + } + + if (!qmi_message_dms_verify_pin_output_get_result (output, &error)) { + QmiMessageDmsVerifyPinOutputPinRetriesStatus retry_status; + + g_printerr ("error: couldn't verify PIN: %s\n", error->message); + g_error_free (error); + + if (qmi_message_dms_verify_pin_output_get_pin_retries_status (output, + &retry_status, + NULL)) { + g_printerr ("[%s] Retries left:\n" + "\tVerify: %u\n" + "\tUnblock: %u\n", + qmi_device_get_path_display (ctx->device), + retry_status.verify_retries_left, + retry_status.unblock_retries_left); + } + + qmi_message_dms_verify_pin_output_unref (output); + shutdown (FALSE); + return; + } + + g_print ("[%s] PIN verified successfully\n", + qmi_device_get_path_display (ctx->device)); + + qmi_message_dms_verify_pin_output_unref (output); + shutdown (TRUE); +} + static gboolean noop_cb (gpointer unused) { @@ -663,6 +750,22 @@ qmicli_dms_run (QmiDevice *device, return; } + /* Request to verify PIN? */ + if (verify_pin_str) { + QmiMessageDmsVerifyPinInput *input; + + g_debug ("Asynchronously verifying PIN..."); + input = verify_pin_input_create (verify_pin_str); + qmi_client_dms_verify_pin (ctx->client, + input, + 10, + ctx->cancellable, + (GAsyncReadyCallback)verify_pin_ready, + NULL); + qmi_message_dms_verify_pin_input_unref (input); + return; + } + /* Just client allocate/release? */ if (noop_flag) { g_idle_add (noop_cb, NULL); |