
/* GENERATED CODE... DO NOT EDIT */

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2013 - 2018 Aleksander Morgado <aleksander@aleksander.es>
 */


#include <string.h>

#include "mbim-qdu.h"
#include "mbim-message-private.h"
#include "mbim-tlv-private.h"
#include "mbim-enum-types.h"
#include "mbim-flag-types.h"
#include "mbim-error-types.h"
#include "mbim-device.h"
#include "mbim-utils.h"

/*****************************************************************************/
/* Message (Query): MBIM Message QDU Update Session */

MbimMessage *
mbim_message_qdu_update_session_query_new (
    GError **error)
{
    MbimMessageCommandBuilder *builder;

    builder = _mbim_message_command_builder_new (0,
                                                 MBIM_SERVICE_QDU,
                                                 MBIM_CID_QDU_UPDATE_SESSION,
                                                 MBIM_MESSAGE_COMMAND_TYPE_QUERY);

    return _mbim_message_command_builder_complete (builder);
}

static gchar *
mbim_message_qdu_update_session_query_get_printable (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    GString *str;

    str = g_string_new ("");

    return g_string_free (str, FALSE);
}

/*****************************************************************************/
/* Message (Set): MBIM Message QDU Update Session */

MbimMessage *
mbim_message_qdu_update_session_set_new (
    MbimQduSessionAction session_action,
    MbimQduSessionType session_type,
    GError **error)
{
    MbimMessageCommandBuilder *builder;

    builder = _mbim_message_command_builder_new (0,
                                                 MBIM_SERVICE_QDU,
                                                 MBIM_CID_QDU_UPDATE_SESSION,
                                                 MBIM_MESSAGE_COMMAND_TYPE_SET);
    {
        _mbim_message_command_builder_append_guint32 (builder, session_action);
    }
    {
        _mbim_message_command_builder_append_guint32 (builder, session_type);
    }

    return _mbim_message_command_builder_complete (builder);
}

static gchar *
mbim_message_qdu_update_session_set_get_printable (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    GString *str;
    GError *inner_error = NULL;
    guint32 offset = 0;

    if (!mbim_message_command_get_raw_information_buffer (message, NULL))
        return NULL;

    str = g_string_new ("");

    g_string_append_printf (str, "%s  SessionAction = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
#if defined __MBIM_QDU_SESSION_ACTION_IS_ENUM__
            g_string_append_printf (str, "'%s'", mbim_qdu_session_action_get_string ((MbimQduSessionAction)tmp));
#elif defined __MBIM_QDU_SESSION_ACTION_IS_FLAGS__
            g_autofree gchar *tmpstr = NULL;

            tmpstr = mbim_qdu_session_action_build_string_from_mask ((MbimQduSessionAction)tmp);
            g_string_append_printf (str, "'%s'", tmpstr);
#else
# error neither enum nor flags
#endif
        }

    }
    g_string_append (str, "\n");

    g_string_append_printf (str, "%s  SessionType = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
#if defined __MBIM_QDU_SESSION_TYPE_IS_ENUM__
            g_string_append_printf (str, "'%s'", mbim_qdu_session_type_get_string ((MbimQduSessionType)tmp));
#elif defined __MBIM_QDU_SESSION_TYPE_IS_FLAGS__
            g_autofree gchar *tmpstr = NULL;

            tmpstr = mbim_qdu_session_type_build_string_from_mask ((MbimQduSessionType)tmp);
            g_string_append_printf (str, "'%s'", tmpstr);
#else
# error neither enum nor flags
#endif
        }

    }
    g_string_append (str, "\n");

 out:
    if (inner_error) {
        g_string_append_printf (str, "n/a: %s", inner_error->message);
        g_clear_error (&inner_error);
    }

    return g_string_free (str, FALSE);
}

/*****************************************************************************/
/* Message (Response): MBIM Message QDU Update Session */

gboolean
mbim_message_qdu_update_session_response_parse (
    const MbimMessage *message,
    MbimQduSessionType *out_current_session_type,
    MbimQduSessionStatus *out_current_session_status,
    MbimQduSessionType *out_last_session_type,
    MbimQduSessionResult *out_last_session_result,
    guint32 *out_last_session_error_offset,
    guint32 *out_last_session_error_size,
    GError **error)
{
    gboolean success = FALSE;
    guint32 offset = 0;

    if (mbim_message_get_message_type (message) != MBIM_MESSAGE_TYPE_COMMAND_DONE) {
        g_set_error (error,
                     MBIM_CORE_ERROR,
                     MBIM_CORE_ERROR_INVALID_MESSAGE,
                     "Message is not a response");
        return FALSE;
    }

    if (!mbim_message_command_done_get_raw_information_buffer (message, NULL)) {
        g_set_error (error,
                     MBIM_CORE_ERROR,
                     MBIM_CORE_ERROR_INVALID_MESSAGE,
                     "Message does not have information buffer");
        return FALSE;
    }

    /* Read the 'CurrentSessionType' variable */
    {
        if (out_current_session_type != NULL) {
            guint32 aux;

            if (!_mbim_message_read_guint32 (message, offset, &aux, error))
                goto out;
            *out_current_session_type = (MbimQduSessionType)aux;
        }
        offset += 4;
    }

    /* Read the 'CurrentSessionStatus' variable */
    {
        if (out_current_session_status != NULL) {
            guint32 aux;

            if (!_mbim_message_read_guint32 (message, offset, &aux, error))
                goto out;
            *out_current_session_status = (MbimQduSessionStatus)aux;
        }
        offset += 4;
    }

    /* Read the 'LastSessionType' variable */
    {
        if (out_last_session_type != NULL) {
            guint32 aux;

            if (!_mbim_message_read_guint32 (message, offset, &aux, error))
                goto out;
            *out_last_session_type = (MbimQduSessionType)aux;
        }
        offset += 4;
    }

    /* Read the 'LastSessionResult' variable */
    {
        if (out_last_session_result != NULL) {
            guint32 aux;

            if (!_mbim_message_read_guint32 (message, offset, &aux, error))
                goto out;
            *out_last_session_result = (MbimQduSessionResult)aux;
        }
        offset += 4;
    }

    /* Read the 'LastSessionErrorOffset' variable */
    {
        if ((out_last_session_error_offset != NULL) && !_mbim_message_read_guint32 (message, offset, out_last_session_error_offset, error))
            goto out;
        offset += 4;
    }

    /* Read the 'LastSessionErrorSize' variable */
    {
        if ((out_last_session_error_size != NULL) && !_mbim_message_read_guint32 (message, offset, out_last_session_error_size, error))
            goto out;
        offset += 4;
    }

    /* All variables successfully parsed */
    success = TRUE;

 out:


    return success;
}

static gchar *
mbim_message_qdu_update_session_response_get_printable (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    GString *str;
    GError *inner_error = NULL;
    guint32 offset = 0;

    if (!mbim_message_command_done_get_raw_information_buffer (message, NULL))
        return NULL;

    str = g_string_new ("");

    g_string_append_printf (str, "%s  CurrentSessionType = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
#if defined __MBIM_QDU_SESSION_TYPE_IS_ENUM__
            g_string_append_printf (str, "'%s'", mbim_qdu_session_type_get_string ((MbimQduSessionType)tmp));
#elif defined __MBIM_QDU_SESSION_TYPE_IS_FLAGS__
            g_autofree gchar *tmpstr = NULL;

            tmpstr = mbim_qdu_session_type_build_string_from_mask ((MbimQduSessionType)tmp);
            g_string_append_printf (str, "'%s'", tmpstr);
#else
# error neither enum nor flags
#endif
        }

    }
    g_string_append (str, "\n");

    g_string_append_printf (str, "%s  CurrentSessionStatus = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
#if defined __MBIM_QDU_SESSION_STATUS_IS_ENUM__
            g_string_append_printf (str, "'%s'", mbim_qdu_session_status_get_string ((MbimQduSessionStatus)tmp));
#elif defined __MBIM_QDU_SESSION_STATUS_IS_FLAGS__
            g_autofree gchar *tmpstr = NULL;

            tmpstr = mbim_qdu_session_status_build_string_from_mask ((MbimQduSessionStatus)tmp);
            g_string_append_printf (str, "'%s'", tmpstr);
#else
# error neither enum nor flags
#endif
        }

    }
    g_string_append (str, "\n");

    g_string_append_printf (str, "%s  LastSessionType = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
#if defined __MBIM_QDU_SESSION_TYPE_IS_ENUM__
            g_string_append_printf (str, "'%s'", mbim_qdu_session_type_get_string ((MbimQduSessionType)tmp));
#elif defined __MBIM_QDU_SESSION_TYPE_IS_FLAGS__
            g_autofree gchar *tmpstr = NULL;

            tmpstr = mbim_qdu_session_type_build_string_from_mask ((MbimQduSessionType)tmp);
            g_string_append_printf (str, "'%s'", tmpstr);
#else
# error neither enum nor flags
#endif
        }

    }
    g_string_append (str, "\n");

    g_string_append_printf (str, "%s  LastSessionResult = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
#if defined __MBIM_QDU_SESSION_RESULT_IS_ENUM__
            g_string_append_printf (str, "'%s'", mbim_qdu_session_result_get_string ((MbimQduSessionResult)tmp));
#elif defined __MBIM_QDU_SESSION_RESULT_IS_FLAGS__
            g_autofree gchar *tmpstr = NULL;

            tmpstr = mbim_qdu_session_result_build_string_from_mask ((MbimQduSessionResult)tmp);
            g_string_append_printf (str, "'%s'", tmpstr);
#else
# error neither enum nor flags
#endif
        }

    }
    g_string_append (str, "\n");

    g_string_append_printf (str, "%s  LastSessionErrorOffset = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
            g_string_append_printf (str, "'%" G_GUINT32_FORMAT "'", tmp);
        }
    }
    g_string_append (str, "\n");

    g_string_append_printf (str, "%s  LastSessionErrorSize = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
            g_string_append_printf (str, "'%" G_GUINT32_FORMAT "'", tmp);
        }
    }
    g_string_append (str, "\n");

 out:
    if (inner_error) {
        g_string_append_printf (str, "n/a: %s", inner_error->message);
        g_clear_error (&inner_error);
    }

    return g_string_free (str, FALSE);
}

/*****************************************************************************/
/* Message (Query): MBIM Message QDU File Open */

MbimMessage *
mbim_message_qdu_file_open_query_new (
    GError **error)
{
    MbimMessageCommandBuilder *builder;

    builder = _mbim_message_command_builder_new (0,
                                                 MBIM_SERVICE_QDU,
                                                 MBIM_CID_QDU_FILE_OPEN,
                                                 MBIM_MESSAGE_COMMAND_TYPE_QUERY);

    return _mbim_message_command_builder_complete (builder);
}

static gchar *
mbim_message_qdu_file_open_query_get_printable (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    GString *str;

    str = g_string_new ("");

    return g_string_free (str, FALSE);
}

/*****************************************************************************/
/* Message (Set): MBIM Message QDU File Open */

MbimMessage *
mbim_message_qdu_file_open_set_new (
    MbimQduFileType file_type,
    guint32 file_size,
    GError **error)
{
    MbimMessageCommandBuilder *builder;

    builder = _mbim_message_command_builder_new (0,
                                                 MBIM_SERVICE_QDU,
                                                 MBIM_CID_QDU_FILE_OPEN,
                                                 MBIM_MESSAGE_COMMAND_TYPE_SET);
    {
        _mbim_message_command_builder_append_guint32 (builder, file_type);
    }
    {
        _mbim_message_command_builder_append_guint32 (builder, file_size);
    }

    return _mbim_message_command_builder_complete (builder);
}

static gchar *
mbim_message_qdu_file_open_set_get_printable (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    GString *str;
    GError *inner_error = NULL;
    guint32 offset = 0;

    if (!mbim_message_command_get_raw_information_buffer (message, NULL))
        return NULL;

    str = g_string_new ("");

    g_string_append_printf (str, "%s  FileType = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
#if defined __MBIM_QDU_FILE_TYPE_IS_ENUM__
            g_string_append_printf (str, "'%s'", mbim_qdu_file_type_get_string ((MbimQduFileType)tmp));
#elif defined __MBIM_QDU_FILE_TYPE_IS_FLAGS__
            g_autofree gchar *tmpstr = NULL;

            tmpstr = mbim_qdu_file_type_build_string_from_mask ((MbimQduFileType)tmp);
            g_string_append_printf (str, "'%s'", tmpstr);
#else
# error neither enum nor flags
#endif
        }

    }
    g_string_append (str, "\n");

    g_string_append_printf (str, "%s  FileSize = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
            g_string_append_printf (str, "'%" G_GUINT32_FORMAT "'", tmp);
        }
    }
    g_string_append (str, "\n");

 out:
    if (inner_error) {
        g_string_append_printf (str, "n/a: %s", inner_error->message);
        g_clear_error (&inner_error);
    }

    return g_string_free (str, FALSE);
}

/*****************************************************************************/
/* Message (Response): MBIM Message QDU File Open */

gboolean
mbim_message_qdu_file_open_response_parse (
    const MbimMessage *message,
    guint32 *out_max_transfer_size,
    guint32 *out_max_window_size,
    GError **error)
{
    gboolean success = FALSE;
    guint32 offset = 0;

    if (mbim_message_get_message_type (message) != MBIM_MESSAGE_TYPE_COMMAND_DONE) {
        g_set_error (error,
                     MBIM_CORE_ERROR,
                     MBIM_CORE_ERROR_INVALID_MESSAGE,
                     "Message is not a response");
        return FALSE;
    }

    if (!mbim_message_command_done_get_raw_information_buffer (message, NULL)) {
        g_set_error (error,
                     MBIM_CORE_ERROR,
                     MBIM_CORE_ERROR_INVALID_MESSAGE,
                     "Message does not have information buffer");
        return FALSE;
    }

    /* Read the 'MaxTransferSize' variable */
    {
        if ((out_max_transfer_size != NULL) && !_mbim_message_read_guint32 (message, offset, out_max_transfer_size, error))
            goto out;
        offset += 4;
    }

    /* Read the 'MaxWindowSize' variable */
    {
        if ((out_max_window_size != NULL) && !_mbim_message_read_guint32 (message, offset, out_max_window_size, error))
            goto out;
        offset += 4;
    }

    /* All variables successfully parsed */
    success = TRUE;

 out:


    return success;
}

static gchar *
mbim_message_qdu_file_open_response_get_printable (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    GString *str;
    GError *inner_error = NULL;
    guint32 offset = 0;

    if (!mbim_message_command_done_get_raw_information_buffer (message, NULL))
        return NULL;

    str = g_string_new ("");

    g_string_append_printf (str, "%s  MaxTransferSize = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
            g_string_append_printf (str, "'%" G_GUINT32_FORMAT "'", tmp);
        }
    }
    g_string_append (str, "\n");

    g_string_append_printf (str, "%s  MaxWindowSize = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
            g_string_append_printf (str, "'%" G_GUINT32_FORMAT "'", tmp);
        }
    }
    g_string_append (str, "\n");

 out:
    if (inner_error) {
        g_string_append_printf (str, "n/a: %s", inner_error->message);
        g_clear_error (&inner_error);
    }

    return g_string_free (str, FALSE);
}

/*****************************************************************************/
/* Message (Set): MBIM Message QDU File Write */

MbimMessage *
mbim_message_qdu_file_write_set_new (
    const guint32 data_buffer_size,
    const guint8 *data_buffer,
    GError **error)
{
    MbimMessageCommandBuilder *builder;

    builder = _mbim_message_command_builder_new (0,
                                                 MBIM_SERVICE_QDU,
                                                 MBIM_CID_QDU_FILE_WRITE,
                                                 MBIM_MESSAGE_COMMAND_TYPE_SET);
    {
        _mbim_message_command_builder_append_byte_array (builder, FALSE, FALSE, FALSE, data_buffer, data_buffer_size, FALSE);
    }

    return _mbim_message_command_builder_complete (builder);
}

static gchar *
mbim_message_qdu_file_write_set_get_printable (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    GString *str;
    GError *inner_error = NULL;
    guint32 offset = 0;

    if (!mbim_message_command_get_raw_information_buffer (message, NULL))
        return NULL;

    str = g_string_new ("");

    g_string_append_printf (str, "%s  DataBuffer = ", line_prefix);
    {
        guint i;
        const guint8 *tmp;
        guint32 tmpsize;

        if (!_mbim_message_read_byte_array (message, 0, offset, FALSE, FALSE, 0, &tmp, &tmpsize, &inner_error, FALSE))
            goto out;
        offset += tmpsize;
        {
            g_string_append (str, "'");
            for (i = 0; i  < tmpsize; i++)
                g_string_append_printf (str, "%02x%s", tmp[i], (i == (tmpsize - 1)) ? "" : ":" );
            g_string_append (str, "'");
        }
    }
    g_string_append (str, "\n");

 out:
    if (inner_error) {
        g_string_append_printf (str, "n/a: %s", inner_error->message);
        g_clear_error (&inner_error);
    }

    return g_string_free (str, FALSE);
}

/*****************************************************************************/
/* Message (Response): MBIM Message QDU File Write */

gboolean
mbim_message_qdu_file_write_response_parse (
    const MbimMessage *message,
    GError **error)
{

    if (mbim_message_get_message_type (message) != MBIM_MESSAGE_TYPE_COMMAND_DONE) {
        g_set_error (error,
                     MBIM_CORE_ERROR,
                     MBIM_CORE_ERROR_INVALID_MESSAGE,
                     "Message is not a response");
        return FALSE;
    }

    return TRUE;
}

static gchar *
mbim_message_qdu_file_write_response_get_printable (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    GString *str;

    str = g_string_new ("");

    return g_string_free (str, FALSE);
}

/*****************************************************************************/
/* Message (Set): MBIM Message QDU Quectel Reboot */

MbimMessage *
mbim_message_qdu_quectel_reboot_set_new (
    MbimQduQuectelRebootType reboot_type,
    GError **error)
{
    MbimMessageCommandBuilder *builder;

    builder = _mbim_message_command_builder_new (0,
                                                 MBIM_SERVICE_QDU,
                                                 MBIM_CID_QDU_QUECTEL_REBOOT,
                                                 MBIM_MESSAGE_COMMAND_TYPE_SET);
    {
        _mbim_message_command_builder_append_guint16 (builder, reboot_type);
    }

    return _mbim_message_command_builder_complete (builder);
}

static gchar *
mbim_message_qdu_quectel_reboot_set_get_printable (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    GString *str;
    GError *inner_error = NULL;
    guint32 offset = 0;

    if (!mbim_message_command_get_raw_information_buffer (message, NULL))
        return NULL;

    str = g_string_new ("");

    g_string_append_printf (str, "%s  RebootType = ", line_prefix);
    {
        guint16 tmp;

        if (!_mbim_message_read_guint16 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 2;
        {
#if defined __MBIM_QDU_QUECTEL_REBOOT_TYPE_IS_ENUM__
            g_string_append_printf (str, "'%s'", mbim_qdu_quectel_reboot_type_get_string ((MbimQduQuectelRebootType)tmp));
#elif defined __MBIM_QDU_QUECTEL_REBOOT_TYPE_IS_FLAGS__
            g_autofree gchar *tmpstr = NULL;

            tmpstr = mbim_qdu_quectel_reboot_type_build_string_from_mask ((MbimQduQuectelRebootType)tmp);
            g_string_append_printf (str, "'%s'", tmpstr);
#else
# error neither enum nor flags
#endif
        }

    }
    g_string_append (str, "\n");

 out:
    if (inner_error) {
        g_string_append_printf (str, "n/a: %s", inner_error->message);
        g_clear_error (&inner_error);
    }

    return g_string_free (str, FALSE);
}

/*****************************************************************************/
/* Message (Response): MBIM Message QDU Quectel Reboot */

gboolean
mbim_message_qdu_quectel_reboot_response_parse (
    const MbimMessage *message,
    GError **error)
{

    if (mbim_message_get_message_type (message) != MBIM_MESSAGE_TYPE_COMMAND_DONE) {
        g_set_error (error,
                     MBIM_CORE_ERROR,
                     MBIM_CORE_ERROR_INVALID_MESSAGE,
                     "Message is not a response");
        return FALSE;
    }

    return TRUE;
}

static gchar *
mbim_message_qdu_quectel_reboot_response_get_printable (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    GString *str;

    str = g_string_new ("");

    return g_string_free (str, FALSE);
}

/*****************************************************************************/
/* Message (Set): MBIM Message QDU Quectel Read Version */

MbimMessage *
mbim_message_qdu_quectel_read_version_set_new (
    MbimQduQuectelVersionType version_type,
    GError **error)
{
    MbimMessageCommandBuilder *builder;

    builder = _mbim_message_command_builder_new (0,
                                                 MBIM_SERVICE_QDU,
                                                 MBIM_CID_QDU_QUECTEL_READ_VERSION,
                                                 MBIM_MESSAGE_COMMAND_TYPE_SET);
    {
        _mbim_message_command_builder_append_guint16 (builder, version_type);
    }

    return _mbim_message_command_builder_complete (builder);
}

static gchar *
mbim_message_qdu_quectel_read_version_set_get_printable (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    GString *str;
    GError *inner_error = NULL;
    guint32 offset = 0;

    if (!mbim_message_command_get_raw_information_buffer (message, NULL))
        return NULL;

    str = g_string_new ("");

    g_string_append_printf (str, "%s  VersionType = ", line_prefix);
    {
        guint16 tmp;

        if (!_mbim_message_read_guint16 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 2;
        {
#if defined __MBIM_QDU_QUECTEL_VERSION_TYPE_IS_ENUM__
            g_string_append_printf (str, "'%s'", mbim_qdu_quectel_version_type_get_string ((MbimQduQuectelVersionType)tmp));
#elif defined __MBIM_QDU_QUECTEL_VERSION_TYPE_IS_FLAGS__
            g_autofree gchar *tmpstr = NULL;

            tmpstr = mbim_qdu_quectel_version_type_build_string_from_mask ((MbimQduQuectelVersionType)tmp);
            g_string_append_printf (str, "'%s'", tmpstr);
#else
# error neither enum nor flags
#endif
        }

    }
    g_string_append (str, "\n");

 out:
    if (inner_error) {
        g_string_append_printf (str, "n/a: %s", inner_error->message);
        g_clear_error (&inner_error);
    }

    return g_string_free (str, FALSE);
}

/*****************************************************************************/
/* Message (Response): MBIM Message QDU Quectel Read Version */

gboolean
mbim_message_qdu_quectel_read_version_response_parse (
    const MbimMessage *message,
    guint32 *out_version_id,
    gchar **out_version,
    GError **error)
{
    gboolean success = FALSE;
    guint32 offset = 0;
    gchar *_version = NULL;

    if (mbim_message_get_message_type (message) != MBIM_MESSAGE_TYPE_COMMAND_DONE) {
        g_set_error (error,
                     MBIM_CORE_ERROR,
                     MBIM_CORE_ERROR_INVALID_MESSAGE,
                     "Message is not a response");
        return FALSE;
    }

    if (!mbim_message_command_done_get_raw_information_buffer (message, NULL)) {
        g_set_error (error,
                     MBIM_CORE_ERROR,
                     MBIM_CORE_ERROR_INVALID_MESSAGE,
                     "Message does not have information buffer");
        return FALSE;
    }

    /* Read the 'VersionId' variable */
    {
        if ((out_version_id != NULL) && !_mbim_message_read_guint32 (message, offset, out_version_id, error))
            goto out;
        offset += 4;
    }

    /* Read the 'Version' variable */
    {
        if ((out_version != NULL) && !_mbim_message_read_string (message, 0, offset, MBIM_STRING_ENCODING_UTF16, &_version, NULL, error))
            goto out;
        offset += 8;
    }

    /* All variables successfully parsed */
    success = TRUE;

 out:

    if (success) {
        /* Memory allocated variables as output */
        if (out_version != NULL)
            *out_version = _version;
    } else {
        g_free (_version);
    }

    return success;
}

static gchar *
mbim_message_qdu_quectel_read_version_response_get_printable (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    GString *str;
    GError *inner_error = NULL;
    guint32 offset = 0;

    if (!mbim_message_command_done_get_raw_information_buffer (message, NULL))
        return NULL;

    str = g_string_new ("");

    g_string_append_printf (str, "%s  VersionId = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
            g_string_append_printf (str, "'%" G_GUINT32_FORMAT "'", tmp);
        }
    }
    g_string_append (str, "\n");

    g_string_append_printf (str, "%s  Version = ", line_prefix);
    {
        g_autofree gchar *tmp = NULL;

        if (!_mbim_message_read_string (message, 0, offset, MBIM_STRING_ENCODING_UTF16, &tmp, NULL, &inner_error))
            goto out;
        offset += 8;
        {
            g_string_append_printf (str, "'%s'", tmp);
        }
    }
    g_string_append (str, "\n");

 out:
    if (inner_error) {
        g_string_append_printf (str, "n/a: %s", inner_error->message);
        g_clear_error (&inner_error);
    }

    return g_string_free (str, FALSE);
}

/*****************************************************************************/
/* Message (Set): MBIM Message QDU Command */

MbimMessage *
mbim_message_qdu_command_set_new (
    MbimQuectelCommandType command_type,
    const guint32 command_string_size,
    const guint8 *command_string,
    GError **error)
{
    MbimMessageCommandBuilder *builder;

    builder = _mbim_message_command_builder_new (0,
                                                 MBIM_SERVICE_QDU,
                                                 MBIM_CID_QDU_COMMAND,
                                                 MBIM_MESSAGE_COMMAND_TYPE_SET);
    {
        _mbim_message_command_builder_append_guint32 (builder, command_type);
    }
    {
        _mbim_message_command_builder_append_byte_array (builder, FALSE, FALSE, FALSE, command_string, command_string_size, FALSE);
    }

    return _mbim_message_command_builder_complete (builder);
}

static gchar *
mbim_message_qdu_command_set_get_printable (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    GString *str;
    GError *inner_error = NULL;
    guint32 offset = 0;
    gboolean show_field;

    show_field = mbim_utils_get_show_personal_info ();

    if (!mbim_message_command_get_raw_information_buffer (message, NULL))
        return NULL;

    str = g_string_new ("");

    g_string_append_printf (str, "%s  CommandType = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
#if defined __MBIM_QUECTEL_COMMAND_TYPE_IS_ENUM__
            g_string_append_printf (str, "'%s'", mbim_quectel_command_type_get_string ((MbimQuectelCommandType)tmp));
#elif defined __MBIM_QUECTEL_COMMAND_TYPE_IS_FLAGS__
            g_autofree gchar *tmpstr = NULL;

            tmpstr = mbim_quectel_command_type_build_string_from_mask ((MbimQuectelCommandType)tmp);
            g_string_append_printf (str, "'%s'", tmpstr);
#else
# error neither enum nor flags
#endif
        }

    }
    g_string_append (str, "\n");

    g_string_append_printf (str, "%s  CommandString = ", line_prefix);
    {
        guint i;
        const guint8 *tmp;
        guint32 tmpsize;

        if (!_mbim_message_read_byte_array (message, 0, offset, FALSE, FALSE, 0, &tmp, &tmpsize, &inner_error, FALSE))
            goto out;
        offset += tmpsize;
        if (show_field) {
            g_string_append (str, "'");
            for (i = 0; i  < tmpsize; i++)
                g_string_append_printf (str, "%02x%s", tmp[i], (i == (tmpsize - 1)) ? "" : ":" );
            g_string_append (str, "'");
        }
        if (!show_field)
           g_string_append (str, "'###'");
    }
    g_string_append (str, "\n");

 out:
    if (inner_error) {
        g_string_append_printf (str, "n/a: %s", inner_error->message);
        g_clear_error (&inner_error);
    }

    return g_string_free (str, FALSE);
}

/*****************************************************************************/
/* Message (Response): MBIM Message QDU Command */

gboolean
mbim_message_qdu_command_response_parse (
    const MbimMessage *message,
    MbimQuectelCommandResponseStatus *out_command_response_status,
    guint32 *out_command_response_string_size,
    const guint8 **out_command_response_string,
    GError **error)
{
    gboolean success = FALSE;
    guint32 offset = 0;

    if (mbim_message_get_message_type (message) != MBIM_MESSAGE_TYPE_COMMAND_DONE) {
        g_set_error (error,
                     MBIM_CORE_ERROR,
                     MBIM_CORE_ERROR_INVALID_MESSAGE,
                     "Message is not a response");
        return FALSE;
    }

    if (!mbim_message_command_done_get_raw_information_buffer (message, NULL)) {
        g_set_error (error,
                     MBIM_CORE_ERROR,
                     MBIM_CORE_ERROR_INVALID_MESSAGE,
                     "Message does not have information buffer");
        return FALSE;
    }

    /* Read the 'CommandResponseStatus' variable */
    {
        if (out_command_response_status != NULL) {
            guint32 aux;

            if (!_mbim_message_read_guint32 (message, offset, &aux, error))
                goto out;
            *out_command_response_status = (MbimQuectelCommandResponseStatus)aux;
        }
        offset += 4;
    }

    /* Read the 'CommandResponseString' variable */
    {
        const guint8 *tmp;
        guint32 tmpsize;

        if (!_mbim_message_read_byte_array (message, 0, offset, FALSE, FALSE, 0, &tmp, &tmpsize, error, FALSE))
            goto out;
        if (out_command_response_string != NULL)
            *out_command_response_string = tmp;
        if (out_command_response_string_size != NULL)
            *out_command_response_string_size = tmpsize;
        offset += tmpsize;
    }

    /* All variables successfully parsed */
    success = TRUE;

 out:


    return success;
}

static gchar *
mbim_message_qdu_command_response_get_printable (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    GString *str;
    GError *inner_error = NULL;
    guint32 offset = 0;
    gboolean show_field;

    show_field = mbim_utils_get_show_personal_info ();

    if (!mbim_message_command_done_get_raw_information_buffer (message, NULL))
        return NULL;

    str = g_string_new ("");

    g_string_append_printf (str, "%s  CommandResponseStatus = ", line_prefix);
    {
        guint32 tmp;

        if (!_mbim_message_read_guint32 (message, offset, &tmp, &inner_error))
            goto out;
        offset += 4;
        {
#if defined __MBIM_QUECTEL_COMMAND_RESPONSE_STATUS_IS_ENUM__
            g_string_append_printf (str, "'%s'", mbim_quectel_command_response_status_get_string ((MbimQuectelCommandResponseStatus)tmp));
#elif defined __MBIM_QUECTEL_COMMAND_RESPONSE_STATUS_IS_FLAGS__
            g_autofree gchar *tmpstr = NULL;

            tmpstr = mbim_quectel_command_response_status_build_string_from_mask ((MbimQuectelCommandResponseStatus)tmp);
            g_string_append_printf (str, "'%s'", tmpstr);
#else
# error neither enum nor flags
#endif
        }

    }
    g_string_append (str, "\n");

    g_string_append_printf (str, "%s  CommandResponseString = ", line_prefix);
    {
        guint i;
        const guint8 *tmp;
        guint32 tmpsize;

        if (!_mbim_message_read_byte_array (message, 0, offset, FALSE, FALSE, 0, &tmp, &tmpsize, &inner_error, FALSE))
            goto out;
        offset += tmpsize;
        if (show_field) {
            g_string_append (str, "'");
            for (i = 0; i  < tmpsize; i++)
                g_string_append_printf (str, "%02x%s", tmp[i], (i == (tmpsize - 1)) ? "" : ":" );
            g_string_append (str, "'");
        }
        if (!show_field)
           g_string_append (str, "'###'");
    }
    g_string_append (str, "\n");

 out:
    if (inner_error) {
        g_string_append_printf (str, "n/a: %s", inner_error->message);
        g_clear_error (&inner_error);
    }

    return g_string_free (str, FALSE);
}

typedef struct {
  gchar * (* query_cb)        (const MbimMessage *message, const gchar *line_prefix, GError **error);
  gchar * (* set_cb)          (const MbimMessage *message, const gchar *line_prefix, GError **error);
  gchar * (* response_cb)     (const MbimMessage *message, const gchar *line_prefix, GError **error);
  gchar * (* notification_cb) (const MbimMessage *message, const gchar *line_prefix, GError **error);
} GetPrintableCallbacks;

static const GetPrintableCallbacks qdu_get_printable_callbacks[] = {
    [MBIM_CID_QDU_UPDATE_SESSION] = {
        .query_cb = mbim_message_qdu_update_session_query_get_printable,
        .set_cb = mbim_message_qdu_update_session_set_get_printable,
        .response_cb = mbim_message_qdu_update_session_response_get_printable,
    },
    [MBIM_CID_QDU_FILE_OPEN] = {
        .query_cb = mbim_message_qdu_file_open_query_get_printable,
        .set_cb = mbim_message_qdu_file_open_set_get_printable,
        .response_cb = mbim_message_qdu_file_open_response_get_printable,
    },
    [MBIM_CID_QDU_FILE_WRITE] = {
        .set_cb = mbim_message_qdu_file_write_set_get_printable,
        .response_cb = mbim_message_qdu_file_write_response_get_printable,
    },
    [MBIM_CID_QDU_QUECTEL_REBOOT] = {
        .set_cb = mbim_message_qdu_quectel_reboot_set_get_printable,
        .response_cb = mbim_message_qdu_quectel_reboot_response_get_printable,
    },
    [MBIM_CID_QDU_QUECTEL_READ_VERSION] = {
        .set_cb = mbim_message_qdu_quectel_read_version_set_get_printable,
        .response_cb = mbim_message_qdu_quectel_read_version_response_get_printable,
    },
    [MBIM_CID_QDU_COMMAND] = {
        .set_cb = mbim_message_qdu_command_set_get_printable,
        .response_cb = mbim_message_qdu_command_response_get_printable,
    },
};

gchar *
__mbim_message_qdu_get_printable_fields (
    const MbimMessage *message,
    const gchar *line_prefix,
    GError **error)
{
    guint32 cid;

    switch (mbim_message_get_message_type (message)) {
        case MBIM_MESSAGE_TYPE_COMMAND: {
            cid = mbim_message_command_get_cid (message);
            if (cid < G_N_ELEMENTS (qdu_get_printable_callbacks)) {
                switch (mbim_message_command_get_command_type (message)) {
                    case MBIM_MESSAGE_COMMAND_TYPE_QUERY:
                        if (qdu_get_printable_callbacks[cid].query_cb)
                            return qdu_get_printable_callbacks[cid].query_cb (message, line_prefix, error);
                        break;
                    case MBIM_MESSAGE_COMMAND_TYPE_SET:
                        if (qdu_get_printable_callbacks[cid].set_cb)
                            return qdu_get_printable_callbacks[cid].set_cb (message, line_prefix, error);
                        break;
                    case MBIM_MESSAGE_COMMAND_TYPE_UNKNOWN:
                    default:
                        g_set_error (error,
                                     MBIM_CORE_ERROR,
                                     MBIM_CORE_ERROR_INVALID_MESSAGE,
                                     "Invalid command type");
                        return NULL;
                }
            }
            break;
        }

        case MBIM_MESSAGE_TYPE_COMMAND_DONE:
            cid = mbim_message_command_done_get_cid (message);
            if (cid < G_N_ELEMENTS (qdu_get_printable_callbacks)) {
                if (qdu_get_printable_callbacks[cid].response_cb)
                    return qdu_get_printable_callbacks[cid].response_cb (message, line_prefix, error);
            }
            break;

        case MBIM_MESSAGE_TYPE_INDICATE_STATUS:
            cid = mbim_message_indicate_status_get_cid (message);
            if (cid < G_N_ELEMENTS (qdu_get_printable_callbacks)) {
                if (qdu_get_printable_callbacks[cid].notification_cb)
                    return qdu_get_printable_callbacks[cid].notification_cb (message, line_prefix, error);
            }
            break;

        case MBIM_MESSAGE_TYPE_OPEN: 
        case MBIM_MESSAGE_TYPE_CLOSE: 
        case MBIM_MESSAGE_TYPE_INVALID: 
        case MBIM_MESSAGE_TYPE_HOST_ERROR: 
        case MBIM_MESSAGE_TYPE_OPEN_DONE: 
        case MBIM_MESSAGE_TYPE_CLOSE_DONE: 
        case MBIM_MESSAGE_TYPE_FUNCTION_ERROR: 
        default:
            g_set_error (error,
                         MBIM_CORE_ERROR,
                         MBIM_CORE_ERROR_INVALID_MESSAGE,
                         "No contents expected in this message type");
            return NULL;
    }

    g_set_error (error,
                 MBIM_CORE_ERROR,
                 MBIM_CORE_ERROR_UNSUPPORTED,
                 "Unsupported message");
    return NULL;
}
