aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2016-11-28 14:55:11 +0100
committerAleksander Morgado <aleksander@aleksander.es>2016-11-28 14:55:11 +0100
commit56d8b97684ca40a1d44d97a1be0a067adaca8480 (patch)
tree248abf4826dde356a0697c6b53889d6106c432f6
parent93e5025ca6d52badd04d5e452f9db524b7e63b46 (diff)
qmicli,dms: firmware image unique id seems to be ASCII
But just in case leave the raw-hex printable string fallback if it isn't.
-rw-r--r--src/qmicli/qmicli-dms.c9
-rw-r--r--src/qmicli/qmicli-helpers.c26
-rw-r--r--src/qmicli/qmicli-helpers.h2
3 files changed, 31 insertions, 6 deletions
diff --git a/src/qmicli/qmicli-dms.c b/src/qmicli/qmicli-dms.c
index f85e7e3..e8d51e0 100644
--- a/src/qmicli/qmicli-dms.c
+++ b/src/qmicli/qmicli-dms.c
@@ -2431,8 +2431,7 @@ get_stored_image_info_ready (QmiClientDms *client,
QmiMessageDmsListStoredImagesOutputListImageSublistSublistElement,
operation_ctx->j);
- unique_id_str = qmicli_get_raw_data_printable (subimage->unique_id, 80, "");
- unique_id_str[strlen(unique_id_str) - 1] = '\0';
+ unique_id_str = qmicli_get_firmware_image_unique_id_printable (subimage->unique_id);
g_print ("%s"
"\t\t[%s%u]\n"
@@ -2713,8 +2712,7 @@ get_stored_image_list_stored_images_ready (QmiClientDms *client,
QmiMessageDmsListStoredImagesOutputListImageSublistSublistElement,
image_index);
- unique_id_str = qmicli_get_raw_data_printable (subimage->unique_id, 80, "");
- unique_id_str[strlen (unique_id_str) - 1] = '\0';
+ unique_id_str = qmicli_get_firmware_image_unique_id_printable (subimage->unique_id);
g_debug ("Found [%s%d]: Unique ID: '%s', Build ID: '%s'",
qmi_dms_firmware_image_type_get_string (image->type),
image_index,
@@ -3043,8 +3041,7 @@ dms_get_firmware_preference_ready (QmiClientDms *client,
image = &g_array_index (array, QmiMessageDmsGetFirmwarePreferenceOutputListImage, i);
- unique_id_str = qmicli_get_raw_data_printable (image->unique_id, 80, "");
- unique_id_str[strlen(unique_id_str) - 1] = '\0';
+ unique_id_str = qmicli_get_firmware_image_unique_id_printable (image->unique_id);
g_print ("[image %u]\n"
"\tImage type: '%s'\n"
diff --git a/src/qmicli/qmicli-helpers.c b/src/qmicli/qmicli-helpers.c
index d1bc3ca..bc04afb 100644
--- a/src/qmicli/qmicli-helpers.c
+++ b/src/qmicli/qmicli-helpers.c
@@ -104,6 +104,32 @@ qmicli_get_raw_data_printable (const GArray *data,
return new_str;
}
+gchar *
+qmicli_get_firmware_image_unique_id_printable (const GArray *unique_id)
+{
+ gchar *unique_id_str;
+
+#define UNIQUE_ID_LEN 16
+
+ g_warn_if_fail (unique_id->len <= UNIQUE_ID_LEN);
+ unique_id_str = g_malloc0 (UNIQUE_ID_LEN + 1);
+ memcpy (unique_id_str, unique_id->data, UNIQUE_ID_LEN);
+
+#undef UNIQUE_ID_LEN
+
+ /* If this is ASCII (more than likely), return it */
+ if (g_str_is_ascii (unique_id_str))
+ return unique_id_str;
+
+ g_free (unique_id_str);
+
+ /* Get a raw hex string otherwise */
+ unique_id_str = qmicli_get_raw_data_printable (unique_id, 80, "");
+ unique_id_str[strlen (unique_id_str) - 1] = '\0'; /* remove EOL */
+
+ return unique_id_str;
+}
+
gboolean
qmicli_read_dms_uim_pin_id_from_string (const gchar *str,
QmiDmsUimPinId *out)
diff --git a/src/qmicli/qmicli-helpers.h b/src/qmicli/qmicli-helpers.h
index f5cf1ff..708af53 100644
--- a/src/qmicli/qmicli-helpers.h
+++ b/src/qmicli/qmicli-helpers.h
@@ -30,6 +30,8 @@ gchar *qmicli_get_raw_data_printable (const GArray *data,
gsize max_line_length,
const gchar *new_line_prefix);
+gchar *qmicli_get_firmware_image_unique_id_printable (const GArray *unique_id);
+
gboolean qmicli_read_dms_uim_pin_id_from_string (const gchar *str,
QmiDmsUimPinId *out);
gboolean qmicli_read_uim_pin_id_from_string (const gchar *str,