diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-09-24 06:55:21 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-09-26 10:19:53 +0200 |
commit | d2b7ea2eeade7b34654a0e44fde16f8bbb46a790 (patch) | |
tree | 6d4c1d6c847ea46e4bf398933078bf9f823912d4 | |
parent | 4adcc1aa773cbb4c9a0a128b1e475a5639ad5b37 (diff) |
cli: new `--dms-list-stored-images' action
-rw-r--r-- | cli/qmicli-dms.c | 238 |
1 files changed, 238 insertions, 0 deletions
diff --git a/cli/qmicli-dms.c b/cli/qmicli-dms.c index 293b053..d5b21ce 100644 --- a/cli/qmicli-dms.c +++ b/cli/qmicli-dms.c @@ -77,6 +77,7 @@ static gchar *restore_factory_defaults_str; static gchar *validate_service_programming_code_str; static gboolean get_band_capabilities_flag; static gboolean get_factory_sku_flag; +static gboolean list_stored_images_flag; static gboolean reset_flag; static gboolean noop_flag; @@ -221,6 +222,10 @@ static GOptionEntry entries[] = { "Get factory stock keeping unit", NULL }, + { "dms-list-stored-images", 0, 0, G_OPTION_ARG_NONE, &list_stored_images_flag, + "List stored images", + NULL + }, { "dms-reset", 0, 0, G_OPTION_ARG_NONE, &reset_flag, "Reset the service state", NULL @@ -291,6 +296,7 @@ qmicli_dms_options_enabled (void) !!validate_service_programming_code_str + get_band_capabilities_flag + get_factory_sku_flag + + list_stored_images_flag + reset_flag + noop_flag); @@ -2241,6 +2247,226 @@ get_factory_sku_ready (QmiClientDms *client, shutdown (TRUE); } +typedef struct { + QmiMessageDmsListStoredImagesOutput *list_images_output; + guint i; + guint j; +} ListImagesContext; + +static void +list_images_context_free (ListImagesContext *operation_ctx) +{ + qmi_message_dms_list_stored_images_output_unref (operation_ctx->list_images_output); + g_slice_free (ListImagesContext, operation_ctx); +} + +static void get_image_info (ListImagesContext *operation_ctx); + +static void +get_stored_image_info_ready (QmiClientDms *client, + GAsyncResult *res, + ListImagesContext *operation_ctx) +{ + GArray *array; + QmiMessageDmsGetStoredImageInfoOutput *output; + GError *error = NULL; + QmiMessageDmsListStoredImagesOutputListImage *image; + QmiMessageDmsListStoredImagesOutputListImageSublistSublistElement *subimage; + gchar *unique_id_str; + + output = qmi_client_dms_get_stored_image_info_finish (client, res, &error); + if (!output) { + /* Fully ignore errors */ + g_error_free (error); + } else if (!qmi_message_dms_get_stored_image_info_output_get_result (output, &error)) { + /* Fully ignore errors */ + g_error_free (error); + } + + qmi_message_dms_list_stored_images_output_get_list ( + operation_ctx->list_images_output, + &array, + NULL); + image = &g_array_index (array, QmiMessageDmsListStoredImagesOutputListImage, operation_ctx->i); + subimage = &g_array_index (image->sublist, + 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'; + + g_print ("%s" + "\t\t[%s%u]\n" + "\t\tUnique ID: '%s'\n" + "\t\tBuild ID: '%s'\n", + operation_ctx->j == image->index_of_running_image ? "\t\t>>>>>>>>>> [CURRENT] <<<<<<<<<<\n" : "", + qmi_dms_firmware_image_type_get_string (image->type), + operation_ctx->j, + unique_id_str, + subimage->build_id); + + if (subimage->storage_index != 255) + g_print ("\t\tStorage index: '%u'\n", subimage->storage_index); + + if (subimage->failure_count != 255) + g_print ("\t\tFailure count: '%u'\n", subimage->failure_count); + + if (output) { + /* Boot version (optional) */ + { + guint16 boot_major_version; + guint16 boot_minor_version; + + if (qmi_message_dms_get_stored_image_info_output_get_boot_version ( + output, + &boot_major_version, + &boot_minor_version, + NULL)) { + g_print ("\t\tBoot version: '%u.%u'\n", + boot_major_version, + boot_minor_version); + } + } + + /* PRI version (optional) */ + { + guint32 pri_version; + const gchar *pri_info; + + if (qmi_message_dms_get_stored_image_info_output_get_pri_version ( + output, + &pri_version, + &pri_info, + NULL)) { + g_print ("\t\tPRI version: '%u'\n" + "\t\tPRI info: '%s'\n", + pri_version, + pri_info); + } + } + + /* OEM lock ID (optional) */ + { + guint32 lock_id; + + if (qmi_message_dms_get_stored_image_info_output_get_oem_lock_id ( + output, + &lock_id, + NULL)) { + g_print ("\t\tOEM lock ID: '%u'\n", + lock_id); + } + } + + qmi_message_dms_get_stored_image_info_output_unref (output); + } + + g_print ("\n"); + g_free (unique_id_str); + + /* Go on to the next one */ + operation_ctx->j++; + get_image_info (operation_ctx); +} + +static void +get_image_info (ListImagesContext *operation_ctx) +{ + GArray *array; + QmiMessageDmsListStoredImagesOutputListImage *image; + QmiMessageDmsListStoredImagesOutputListImageSublistSublistElement *subimage; + QmiMessageDmsGetStoredImageInfoInputImage image_id; + QmiMessageDmsGetStoredImageInfoInput *input; + + qmi_message_dms_list_stored_images_output_get_list ( + operation_ctx->list_images_output, + &array, + NULL); + + if (operation_ctx->i >= array->len) { + /* We're done */ + list_images_context_free (operation_ctx); + shutdown (TRUE); + return; + } + + image = &g_array_index (array, + QmiMessageDmsListStoredImagesOutputListImage, + operation_ctx->i); + + if (operation_ctx->j >= image->sublist->len) { + /* No more images in the sublist, go to next image type */ + operation_ctx->j = 0; + operation_ctx->i++; + get_image_info (operation_ctx); + return; + } + + /* Print info of the image type */ + if (operation_ctx->j == 0) { + g_print ("\t[%u] Type: '%s'\n" + "\t Maximum: '%u'\n" + "\n", + operation_ctx->i, + qmi_dms_firmware_image_type_get_string (image->type), + image->maximum_images); + } + + subimage = &g_array_index (image->sublist, + QmiMessageDmsListStoredImagesOutputListImageSublistSublistElement, + operation_ctx->j); + + /* Query image info */ + image_id.type = image->type; + image_id.unique_id = subimage->unique_id; + image_id.build_id = subimage->build_id; + input = qmi_message_dms_get_stored_image_info_input_new (); + qmi_message_dms_get_stored_image_info_input_set_image (input, &image_id, NULL); + + qmi_client_dms_get_stored_image_info (ctx->client, + input, + 10, + ctx->cancellable, + (GAsyncReadyCallback)get_stored_image_info_ready, + operation_ctx); + qmi_message_dms_get_stored_image_info_input_unref (input); +} + +static void +list_stored_images_ready (QmiClientDms *client, + GAsyncResult *res) +{ + QmiMessageDmsListStoredImagesOutput *output; + GError *error = NULL; + ListImagesContext *operation_ctx; + + output = qmi_client_dms_list_stored_images_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_list_stored_images_output_get_result (output, &error)) { + g_printerr ("error: couldn't list stored images: %s\n", error->message); + g_error_free (error); + qmi_message_dms_list_stored_images_output_unref (output); + shutdown (FALSE); + return; + } + + g_print ("[%s] Device list of stored images retrieved:\n\n", + qmi_device_get_path_display (ctx->device)); + + operation_ctx = g_slice_new0 (ListImagesContext); + operation_ctx->list_images_output = output; + operation_ctx->i = 0; + operation_ctx->j = 0; + + get_image_info (operation_ctx); +} + static void reset_ready (QmiClientDms *client, GAsyncResult *res) @@ -2822,6 +3048,18 @@ qmicli_dms_run (QmiDevice *device, return; } + /* Request to list stored images? */ + if (list_stored_images_flag) { + g_debug ("Asynchronously listing stored images..."); + qmi_client_dms_list_stored_images (ctx->client, + NULL, + 10, + ctx->cancellable, + (GAsyncReadyCallback)list_stored_images_ready, + NULL); + return; + } + /* Request to reset DMS service? */ if (reset_flag) { g_debug ("Asynchronously resetting DMS service..."); |