summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2016-01-30 10:25:41 -0800
committerAleksander Morgado <aleksander@aleksander.es>2016-01-30 10:25:41 -0800
commit517af334d1c6b3130481ed5bbea6408915f2f49f (patch)
treed54d569ed6fd0b000bfb50a6bc612fb4a67f9f05
parent08ee7e9f1bcb8fc58305240de54f29b5e1282ce2 (diff)
downloadlibqmi-517af334d1c6b3130481ed5bbea6408915f2f49f.tar.gz
uim: implement 'UIM Unblock PIN'
-rw-r--r--data/qmi-service-uim.json60
-rw-r--r--docs/reference/libqmi-glib/libqmi-glib-docs.xml1
-rw-r--r--src/qmicli/qmicli-uim.c116
3 files changed, 177 insertions, 0 deletions
diff --git a/data/qmi-service-uim.json b/data/qmi-service-uim.json
index 02620dd5..ab9d9b78 100644
--- a/data/qmi-service-uim.json
+++ b/data/qmi-service-uim.json
@@ -402,6 +402,66 @@
"format" : "guint8" } ] } ] },
// *********************************************************************************
+ { "name" : "Unblock PIN",
+ "type" : "Message",
+ "service" : "UIM",
+ "id" : "0x0027",
+ "version" : "1.0",
+ "input" : [ { "name" : "Session Information",
+ "id" : "0x01",
+ "mandatory" : "yes",
+ "type" : "TLV",
+ "format" : "sequence",
+ "contents" : [ { "name" : "Session Type",
+ "format" : "guint8",
+ "public-format" : "QmiUimSessionType" },
+ { "name" : "Application Identifier",
+ "format" : "string" } ] },
+ { "name" : "Info",
+ "id" : "0x02",
+ "mandatory" : "yes",
+ "type" : "TLV",
+ "format" : "sequence",
+ "contents" : [ { "name" : "PIN ID",
+ "format" : "guint8",
+ "public-format" : "QmiUimPinId" },
+ { "name" : "PUK",
+ "format" : "string" },
+ { "name" : "New PIN",
+ "format" : "string" } ] },
+ { "name" : "Response In Indication Token",
+ "id" : "0x11",
+ "mandatory" : "no",
+ "type" : "TLV",
+ "format" : "guint32" } ],
+ "output" : [ { "common-ref" : "Operation Result" },
+ { "name" : "Retries Remaining",
+ "id" : "0x10",
+ "mandatory" : "no",
+ "type" : "TLV",
+ "format" : "sequence",
+ "contents" : [ { "name" : "Verify Retries Left",
+ "format" : "guint8" },
+ { "name" : "Unblock Retries Left",
+ "format" : "guint8" } ],
+ "prerequisites": [ { "common-ref" : "No Success" } ] },
+ { "name" : "Response In Indication Token",
+ "id" : "0x12",
+ "mandatory" : "no",
+ "type" : "TLV",
+ "format" : "guint32",
+ "prerequisites" : [ { "common-ref" : "Success" } ] },
+ { "name" : "Card Result",
+ "id" : "0x13",
+ "mandatory" : "no",
+ "type" : "TLV",
+ "format" : "sequence",
+ "contents" : [ { "name" : "SW1",
+ "format" : "guint8" },
+ { "name" : "SW2",
+ "format" : "guint8" } ] } ] },
+
+ // *********************************************************************************
{ "name" : "Get Card Status",
"type" : "Message",
"service" : "UIM",
diff --git a/docs/reference/libqmi-glib/libqmi-glib-docs.xml b/docs/reference/libqmi-glib/libqmi-glib-docs.xml
index 73af0f42..417ad4e5 100644
--- a/docs/reference/libqmi-glib/libqmi-glib-docs.xml
+++ b/docs/reference/libqmi-glib/libqmi-glib-docs.xml
@@ -249,6 +249,7 @@
<xi:include href="xml/qmi-message-uim-reset.xml"/>
<xi:include href="xml/qmi-message-uim-set-pin-protection.xml"/>
<xi:include href="xml/qmi-message-uim-verify-pin.xml"/>
+ <xi:include href="xml/qmi-message-uim-unblock-pin.xml"/>
<xi:include href="xml/qmi-message-uim-read-transparent.xml"/>
<xi:include href="xml/qmi-message-uim-read-record.xml"/>
<xi:include href="xml/qmi-message-uim-get-file-attributes.xml"/>
diff --git a/src/qmicli/qmicli-uim.c b/src/qmicli/qmicli-uim.c
index feb23549..9ab1be5c 100644
--- a/src/qmicli/qmicli-uim.c
+++ b/src/qmicli/qmicli-uim.c
@@ -45,6 +45,7 @@ static Context *ctx;
static gchar *read_transparent_str;
static gchar *set_pin_protection_str;
static gchar *verify_pin_str;
+static gchar *unblock_pin_str;
static gchar *get_file_attributes_str;
static gboolean get_card_status_flag;
static gboolean get_supported_messages_flag;
@@ -60,6 +61,10 @@ static GOptionEntry entries[] = {
"Verify PIN",
"[(PIN1|PIN2|UPIN),(current PIN)]",
},
+ { "uim-unblock-pin", 0, 0, G_OPTION_ARG_STRING, &unblock_pin_str,
+ "Unblock PIN",
+ "[(PIN1|PIN2|UPIN),(PUK),(new PIN)]",
+ },
{ "uim-read-transparent", 0, 0, G_OPTION_ARG_STRING, &read_transparent_str,
"Read a transparent file given the file path",
"[0xNNNN,0xNNNN,...]"
@@ -113,6 +118,7 @@ qmicli_uim_options_enabled (void)
n_actions = (!!set_pin_protection_str +
!!verify_pin_str +
+ !!unblock_pin_str +
!!read_transparent_str +
!!get_file_attributes_str +
get_card_status_flag +
@@ -327,6 +333,96 @@ verify_pin_ready (QmiClientUim *client,
operation_shutdown (TRUE);
}
+static QmiMessageUimUnblockPinInput *
+unblock_pin_input_create (const gchar *str)
+{
+ QmiMessageUimUnblockPinInput *input = NULL;
+ gchar **split;
+ QmiUimPinId pin_id;
+ gchar *puk;
+ gchar *new_pin;
+
+ /* Prepare inputs.
+ * Format of the string is:
+ * "[(PIN|PIN2),(PUK),(new PIN)]"
+ */
+ split = g_strsplit (str, ",", -1);
+ if (qmicli_read_uim_pin_id_from_string (split[0], &pin_id) &&
+ qmicli_read_non_empty_string (split[1], "PUK", &puk) &&
+ qmicli_read_non_empty_string (split[2], "new PIN", &new_pin)) {
+ GError *error = NULL;
+
+ input = qmi_message_uim_unblock_pin_input_new ();
+ if (!qmi_message_uim_unblock_pin_input_set_info (
+ input,
+ pin_id,
+ puk,
+ new_pin,
+ &error) ||
+ !qmi_message_uim_unblock_pin_input_set_session_information (
+ input,
+ QMI_UIM_SESSION_TYPE_CARD_SLOT_1,
+ "", /* ignored */
+ &error)) {
+ g_printerr ("error: couldn't create input data bundle: '%s'\n",
+ error->message);
+ g_error_free (error);
+ qmi_message_uim_unblock_pin_input_unref (input);
+ input = NULL;
+ }
+ }
+ g_strfreev (split);
+
+ return input;
+}
+
+static void
+unblock_pin_ready (QmiClientUim *client,
+ GAsyncResult *res)
+{
+ QmiMessageUimUnblockPinOutput *output;
+ GError *error = NULL;
+
+ output = qmi_client_uim_unblock_pin_finish (client, res, &error);
+ if (!output) {
+ g_printerr ("error: operation failed: %s\n", error->message);
+ g_error_free (error);
+ operation_shutdown (FALSE);
+ return;
+ }
+
+ if (!qmi_message_uim_unblock_pin_output_get_result (output, &error)) {
+ guint8 verify_retries_left;
+ guint8 unblock_retries_left;
+
+ g_printerr ("error: couldn't unblock PIN: %s\n", error->message);
+ g_error_free (error);
+
+ if (qmi_message_uim_unblock_pin_output_get_retries_remaining (
+ output,
+ &verify_retries_left,
+ &unblock_retries_left,
+ NULL)) {
+ g_printerr ("[%s] Retries left:\n"
+ "\tVerify: %u\n"
+ "\tUnblock: %u\n",
+ qmi_device_get_path_display (ctx->device),
+ verify_retries_left,
+ unblock_retries_left);
+ }
+
+ qmi_message_uim_unblock_pin_output_unref (output);
+ operation_shutdown (FALSE);
+ return;
+ }
+
+ g_print ("[%s] PIN unblocked successfully\n",
+ qmi_device_get_path_display (ctx->device));
+
+ qmi_message_uim_unblock_pin_output_unref (output);
+ operation_shutdown (TRUE);
+}
+
static void
get_supported_messages_ready (QmiClientUim *client,
GAsyncResult *res)
@@ -919,6 +1015,26 @@ qmicli_uim_run (QmiDevice *device,
return;
}
+ /* Request to unblock PIN? */
+ if (unblock_pin_str) {
+ QmiMessageUimUnblockPinInput *input;
+
+ g_debug ("Asynchronously unblocking PIN...");
+ input = unblock_pin_input_create (unblock_pin_str);
+ if (!input) {
+ operation_shutdown (FALSE);
+ return;
+ }
+ qmi_client_uim_unblock_pin (ctx->client,
+ input,
+ 10,
+ ctx->cancellable,
+ (GAsyncReadyCallback)unblock_pin_ready,
+ NULL);
+ qmi_message_uim_unblock_pin_input_unref (input);
+ return;
+ }
+
/* Request to read a transparent file? */
if (read_transparent_str) {
QmiMessageUimReadTransparentInput *input;