From 9550bd568371995acca003d6250ba4535db7d59f Mon Sep 17 00:00:00 2001 From: Emil Ljungdahl Date: Wed, 6 Apr 2016 19:25:27 +0200 Subject: [PATCH 3/3] Avoid affecting the padding behavior for other services than QMI --- build-aux/mbim-codegen/Message.py | 9 +++++---- build-aux/mbim-codegen/Struct.py | 9 +++++---- data/mbim-service-qmi.json | 6 ++++-- src/libmbim-glib/mbim-message-private.h | 4 ++-- src/libmbim-glib/mbim-message.c | 10 +++++----- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/build-aux/mbim-codegen/Message.py b/build-aux/mbim-codegen/Message.py index e66335d..a569685 100644 --- a/build-aux/mbim-codegen/Message.py +++ b/build-aux/mbim-codegen/Message.py @@ -381,6 +381,7 @@ class Message: translations['struct'] = field['struct-type'] if 'struct-type' in field else '' translations['struct_underscore'] = utils.build_underscore_name_from_camelcase (translations['struct']) translations['array_size'] = field['array-size'] if 'array-size' in field else '' + translations['pad_array'] = field['pad-array'] if 'pad-array' in field else 'TRUE' inner_template = '' if 'available-if' in field: @@ -394,13 +395,13 @@ class Message: inner_template += (' {\n') if field['format'] == 'byte-array': - inner_template += (' _mbim_message_command_builder_append_byte_array (builder, FALSE, FALSE, TRUE, ${field}, ${array_size});\n') + inner_template += (' _mbim_message_command_builder_append_byte_array (builder, FALSE, FALSE, ${pad_array}, ${field}, ${array_size});\n') elif field['format'] == 'unsized-byte-array': - inner_template += (' _mbim_message_command_builder_append_byte_array (builder, FALSE, FALSE, FALSE, ${field}, ${field}_size);\n') + inner_template += (' _mbim_message_command_builder_append_byte_array (builder, FALSE, FALSE, ${pad_array}, ${field}, ${field}_size);\n') elif field['format'] == 'ref-byte-array': - inner_template += (' _mbim_message_command_builder_append_byte_array (builder, TRUE, TRUE, TRUE, ${field}, ${field}_size);\n') + inner_template += (' _mbim_message_command_builder_append_byte_array (builder, TRUE, TRUE, ${pad_array}, ${field}, ${field}_size);\n') elif field['format'] == 'ref-byte-array-no-offset': - inner_template += (' _mbim_message_command_builder_append_byte_array (builder, FALSE, TRUE, TRUE, ${field}, ${field}_size);\n') + inner_template += (' _mbim_message_command_builder_append_byte_array (builder, FALSE, TRUE, ${pad_array}, ${field}, ${field}_size);\n') elif field['format'] == 'uuid': inner_template += (' _mbim_message_command_builder_append_uuid (builder, ${field});\n') elif field['format'] == 'guint32': diff --git a/build-aux/mbim-codegen/Struct.py b/build-aux/mbim-codegen/Struct.py index 8797f3a..84570de 100644 --- a/build-aux/mbim-codegen/Struct.py +++ b/build-aux/mbim-codegen/Struct.py @@ -494,18 +494,19 @@ class Struct: translations['field'] = utils.build_underscore_name_from_camelcase(field['name']) translations['array_size'] = field['array-size'] if 'array-size' in field else '' translations['array_size_field'] = utils.build_underscore_name_from_camelcase(field['array-size-field']) if 'array-size-field' in field else '' + translations['pad_array'] = field['pad-array'] if 'pad-array' in field else 'TRUE' if field['format'] == 'uuid': inner_template = (' _mbim_struct_builder_append_uuid (builder, &(value->${field}));\n') elif field['format'] == 'byte-array': - inner_template = (' _mbim_struct_builder_append_byte_array (builder, FALSE, FALSE, TRUE, value->${field}, ${array_size});\n') + inner_template = (' _mbim_struct_builder_append_byte_array (builder, FALSE, FALSE, ${pad_array}, value->${field}, ${array_size});\n') elif field['format'] == 'unsized-byte-array': - inner_template = (' _mbim_struct_builder_append_byte_array (builder, FALSE, FALSE, FALSE, value->${field}, value->${field}_size);\n') + inner_template = (' _mbim_struct_builder_append_byte_array (builder, FALSE, FALSE, ${pad_array}, value->${field}, value->${field}_size);\n') elif field['format'] == 'ref-byte-array': if 'array-size-field' in field: - inner_template = (' _mbim_struct_builder_append_byte_array (builder, TRUE, FALSE, TRUE, value->${field}, value->${array_size_field});\n') + inner_template = (' _mbim_struct_builder_append_byte_array (builder, TRUE, FALSE, ${pad_array}, value->${field}, value->${array_size_field});\n') else: - inner_template = (' _mbim_struct_builder_append_byte_array (builder, TRUE, TRUE, TRUE, value->${field}, value->${field}_size);\n') + inner_template = (' _mbim_struct_builder_append_byte_array (builder, TRUE, TRUE, ${pad_array}, value->${field}, value->${field}_size);\n') elif field['format'] == 'guint32': inner_template = (' _mbim_struct_builder_append_guint32 (builder, value->${field});\n') elif field['format'] == 'guint32-array': diff --git a/data/mbim-service-qmi.json b/data/mbim-service-qmi.json index b764d01..c11857f 100644 --- a/data/mbim-service-qmi.json +++ b/data/mbim-service-qmi.json @@ -9,7 +9,9 @@ "service" : "QMI", "type" : "Command", "set" : [ { "name" : "QmiMsg", - "format" : "unsized-byte-array" } ], + "format" : "unsized-byte-array", + "pad-array" : "FALSE" } ], "response" : [ { "name" : "QMUX", - "format" : "unsized-byte-array" } ] } + "format" : "unsized-byte-array", + "pad-array" : "FALSE" } ] } ] diff --git a/src/libmbim-glib/mbim-message-private.h b/src/libmbim-glib/mbim-message-private.h index 0082026..79071d8 100644 --- a/src/libmbim-glib/mbim-message-private.h +++ b/src/libmbim-glib/mbim-message-private.h @@ -177,7 +177,7 @@ GByteArray *_mbim_struct_builder_complete (MbimStructBuilder void _mbim_struct_builder_append_byte_array (MbimStructBuilder *builder, gboolean with_offset, gboolean with_length, - gboolean permit_padding, + gboolean pad_buffer, const guint8 *buffer, guint32 buffer_len); void _mbim_struct_builder_append_uuid (MbimStructBuilder *builder, @@ -226,7 +226,7 @@ MbimMessage *_mbim_message_command_builder_complete (M void _mbim_message_command_builder_append_byte_array (MbimMessageCommandBuilder *builder, gboolean with_offset, gboolean with_length, - gboolean permit_padding, + gboolean pad_buffer, const guint8 *buffer, guint32 buffer_len); void _mbim_message_command_builder_append_uuid (MbimMessageCommandBuilder *builder, diff --git a/src/libmbim-glib/mbim-message.c b/src/libmbim-glib/mbim-message.c index ad67059..1a0d492 100644 --- a/src/libmbim-glib/mbim-message.c +++ b/src/libmbim-glib/mbim-message.c @@ -492,7 +492,7 @@ void _mbim_struct_builder_append_byte_array (MbimStructBuilder *builder, gboolean with_offset, gboolean with_length, - gboolean permit_padding, + gboolean pad_buffer, const guint8 *buffer, guint32 buffer_len) { @@ -502,7 +502,7 @@ _mbim_struct_builder_append_byte_array (MbimStructBuilder *builder, */ if (!with_offset && !with_length) { g_byte_array_append (builder->fixed_buffer, buffer, buffer_len); - if(permit_padding) { + if(pad_buffer) { while (buffer_len % 4 != 0) { const guint8 padding = 0; @@ -554,7 +554,7 @@ _mbim_struct_builder_append_byte_array (MbimStructBuilder *builder, g_byte_array_append (builder->variable_buffer, (const guint8 *)buffer, (guint)buffer_len); /* Note: adding zero padding causes trouble for QMI service */ - if(permit_padding) { + if(pad_buffer) { while (buffer_len % 4 != 0) { const guint8 padding = 0; @@ -830,11 +830,11 @@ void _mbim_message_command_builder_append_byte_array (MbimMessageCommandBuilder *builder, gboolean with_offset, gboolean with_length, - gboolean permit_padding, + gboolean pad_buffer, const guint8 *buffer, guint32 buffer_len) { - _mbim_struct_builder_append_byte_array (builder->contents_builder, with_offset, with_length, permit_padding, buffer, buffer_len); + _mbim_struct_builder_append_byte_array (builder->contents_builder, with_offset, with_length, pad_buffer, buffer, buffer_len); } void -- 1.9.1