aboutsummaryrefslogtreecommitdiffstats
path: root/build-aux/qmi-codegen/VariableArray.py
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-10-30 15:08:02 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-10-30 20:42:59 +0100
commit4c98ff41cca3c83498c8f8b6f502fa56e4e31653 (patch)
tree7935c2d8132809eeb74c7cd655d9f87b560f8db3 /build-aux/qmi-codegen/VariableArray.py
parent7cce18820ef2142781c334d20e162d814695a409 (diff)
downloadexternal_libqmi-4c98ff41cca3c83498c8f8b6f502fa56e4e31653.zip
external_libqmi-4c98ff41cca3c83498c8f8b6f502fa56e4e31653.tar.gz
external_libqmi-4c98ff41cca3c83498c8f8b6f502fa56e4e31653.tar.bz2
qmi-codegen: validate TLV before really reading it
Try to handle buggy firmware, or just make the library more robust, by validating the read TLV before really reading it. If a TLV is not considered valid, we just skip it for now. E.g.: the "Detailed Service Status" TLV (0x21) in the "NAS Get Serving System" message is supposed to be a sequence of 5 bytes, but some models (e.g. ZTE MF683) end up sending only the first 4 bytes.
Diffstat (limited to 'build-aux/qmi-codegen/VariableArray.py')
-rw-r--r--build-aux/qmi-codegen/VariableArray.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/build-aux/qmi-codegen/VariableArray.py b/build-aux/qmi-codegen/VariableArray.py
index d582a6a..f2b122c 100644
--- a/build-aux/qmi-codegen/VariableArray.py
+++ b/build-aux/qmi-codegen/VariableArray.py
@@ -190,6 +190,63 @@ class VariableArray(Variable):
"""
+ Emits the code involved in computing the size of the variable.
+ """
+ def emit_size_read(self, f, line_prefix, variable_name, buffer_name, buffer_len):
+ common_var_prefix = utils.build_underscore_name(self.name)
+ translations = { 'lp' : line_prefix,
+ 'variable_name' : variable_name,
+ 'buffer_name' : buffer_name,
+ 'buffer_len' : buffer_len,
+ 'common_var_prefix' : common_var_prefix }
+
+ template = (
+ '${lp}{\n'
+ '${lp} guint ${common_var_prefix}_i;\n')
+ f.write(string.Template(template).substitute(translations))
+
+ if self.fixed_size:
+ translations['fixed_size'] = self.fixed_size
+
+ template = (
+ '${lp} guint16 ${common_var_prefix}_n_items = ${fixed_size};\n'
+ '\n')
+ f.write(string.Template(template).substitute(translations))
+ else:
+ translations['array_size_element_format'] = self.array_size_element.public_format
+ if self.array_size_element.public_format == 'guint8':
+ translations['array_size_element_size'] = '1'
+ elif self.array_size_element.public_format == 'guint16':
+ translations['array_size_element_size'] = '2'
+ elif self.array_size_element.public_format == 'guint32':
+ translations['array_size_element_size'] = '4'
+ else:
+ translations['array_size_element_size'] = '0'
+
+ template = (
+ '${lp} ${array_size_element_format} ${common_var_prefix}_n_items;\n'
+ '${lp} const guint8 *${common_var_prefix}_aux_buffer = &${buffer_name}[${variable_name}];\n'
+ '${lp} guint16 ${common_var_prefix}_aux_buffer_len = ${buffer_len} - ${variable_name};\n'
+ '\n'
+ '${lp} ${variable_name} += ${array_size_element_size};\n'
+ '\n')
+ f.write(string.Template(template).substitute(translations))
+
+ self.array_size_element.emit_buffer_read(f, line_prefix + ' ', common_var_prefix + '_n_items', common_var_prefix + '_aux_buffer', common_var_prefix + '_aux_buffer_len')
+
+ template = (
+ '${lp} for (${common_var_prefix}_i = 0; ${common_var_prefix}_i < ${common_var_prefix}_n_items; ${common_var_prefix}_i++) {\n'
+ '\n')
+ f.write(string.Template(template).substitute(translations))
+
+ self.array_element.emit_size_read(f, line_prefix + ' ', variable_name, buffer_name, buffer_len)
+
+ template = (
+ '${lp} }\n'
+ '${lp}}\n')
+ f.write(string.Template(template).substitute(translations))
+
+ """
Writing an array to the raw byte buffer is just about providing a loop to
write every array element one by one.
"""