From cb5851e7000d063bf8ff8917d15f9882d2612473 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 19 Oct 2012 19:26:15 -0500 Subject: libqmi-glib,qmi-codegen: add endian-ness annotation capability Some values are sent by the firmware in big endian byte order, specifically IP addresses, which are sent in network byte order (ie, big endian). Add the ability to specify the byte order the firmware handles the value as, and convert that to host byte order when reading/writing QMI buffers. --- build-aux/qmi-codegen/FieldResult.py | 2 ++ build-aux/qmi-codegen/Variable.py | 9 +++++++++ build-aux/qmi-codegen/VariableInteger.py | 18 ++++++++++++++---- 3 files changed, 25 insertions(+), 4 deletions(-) (limited to 'build-aux') diff --git a/build-aux/qmi-codegen/FieldResult.py b/build-aux/qmi-codegen/FieldResult.py index c249492..cc298ee 100644 --- a/build-aux/qmi-codegen/FieldResult.py +++ b/build-aux/qmi-codegen/FieldResult.py @@ -138,10 +138,12 @@ class FieldResult(Field): ' qmi_utils_read_guint16_from_buffer (\n' ' &buffer,\n' ' &buffer_len,\n' + ' QMI_ENDIAN_LITTLE,\n' ' &error_status);\n' ' qmi_utils_read_guint16_from_buffer (\n' ' &buffer,\n' ' &buffer_len,\n' + ' QMI_ENDIAN_LITTLE,\n' ' &error_code);\n' '\n' ' g_warn_if_fail (buffer_len == 0);\n' diff --git a/build-aux/qmi-codegen/Variable.py b/build-aux/qmi-codegen/Variable.py index 6eb65d6..3f3fcec 100644 --- a/build-aux/qmi-codegen/Variable.py +++ b/build-aux/qmi-codegen/Variable.py @@ -44,6 +44,15 @@ class Variable: """ self.needs_dispose = False + self.endian = "QMI_ENDIAN_LITTLE" + if dictionary.has_key('endian'): + endian = dictionary['endian'] + if endian == 'network' or endian == 'big': + self.endian = "QMI_ENDIAN_BIG" + elif endian == 'little': + pass + else: + raise ValueError("Invalid endian value %s" % endian) """ Emits the code to declare specific new types required by the variable. diff --git a/build-aux/qmi-codegen/VariableInteger.py b/build-aux/qmi-codegen/VariableInteger.py index 0bb2a2c..68692a0 100644 --- a/build-aux/qmi-codegen/VariableInteger.py +++ b/build-aux/qmi-codegen/VariableInteger.py @@ -48,7 +48,6 @@ class VariableInteger(Variable): self.private_format = self.format self.public_format = dictionary['public-format'] if 'public-format' in dictionary else self.private_format - """ Read a single integer from the raw byte buffer """ @@ -59,7 +58,8 @@ class VariableInteger(Variable): 'len' : self.guint_sized_size, 'variable_name' : variable_name, 'buffer_name' : buffer_name, - 'buffer_len' : buffer_len } + 'buffer_len' : buffer_len, + 'endian' : self.endian } if self.format == 'guint-sized': template = ( @@ -68,6 +68,7 @@ class VariableInteger(Variable): '${lp} &${buffer_name},\n' '${lp} &${buffer_len},\n' '${lp} ${len},\n' + '${lp} ${endian},\n' '${lp} &(${variable_name}));\n') elif self.private_format == self.public_format: template = ( @@ -75,6 +76,7 @@ class VariableInteger(Variable): '${lp}qmi_utils_read_${private_format}_from_buffer (\n' '${lp} &${buffer_name},\n' '${lp} &${buffer_len},\n' + '${lp} ${endian},\n' '${lp} &(${variable_name}));\n') else: template = ( @@ -85,6 +87,7 @@ class VariableInteger(Variable): '${lp} qmi_utils_read_${private_format}_from_buffer (\n' '${lp} &${buffer_name},\n' '${lp} &${buffer_len},\n' + '${lp} ${endian},\n' '${lp} &tmp);\n' '${lp} ${variable_name} = (${public_format})tmp;\n' '${lp}}\n') @@ -100,7 +103,8 @@ class VariableInteger(Variable): 'len' : self.guint_sized_size, 'variable_name' : variable_name, 'buffer_name' : buffer_name, - 'buffer_len' : buffer_len } + 'buffer_len' : buffer_len, + 'endian' : self.endian } if self.format == 'guint-sized': template = ( @@ -109,6 +113,7 @@ class VariableInteger(Variable): '${lp} &${buffer_name},\n' '${lp} &${buffer_len},\n' '${lp} ${len},\n' + '${lp} ${endian},\n' '${lp} &(${variable_name}));\n') elif self.private_format == self.public_format: template = ( @@ -116,6 +121,7 @@ class VariableInteger(Variable): '${lp}qmi_utils_write_${private_format}_to_buffer (\n' '${lp} &${buffer_name},\n' '${lp} &${buffer_len},\n' + '${lp} ${endian},\n' '${lp} &(${variable_name}));\n') else: template = ( @@ -127,6 +133,7 @@ class VariableInteger(Variable): '${lp} qmi_utils_write_${private_format}_to_buffer (\n' '${lp} &${buffer_name},\n' '${lp} &${buffer_len},\n' + '${lp} ${endian},\n' '${lp} &tmp);\n' '${lp}}\n') f.write(string.Template(template).substitute(translations)) @@ -164,7 +171,8 @@ class VariableInteger(Variable): 'buffer_name' : buffer_name, 'buffer_len' : buffer_len, 'common_format' : common_format, - 'common_cast' : common_cast } + 'common_cast' : common_cast, + 'endian' : self.endian } if self.format == 'guint-sized': template = ( @@ -177,6 +185,7 @@ class VariableInteger(Variable): '${lp} &${buffer_name},\n' '${lp} &${buffer_len},\n' '${lp} ${len},\n' + '${lp} ${endian},\n' '${lp} &tmp);\n' '\n' '${lp} g_string_append_printf (${printable}, "${common_format}", ${common_cast}tmp);\n' @@ -191,6 +200,7 @@ class VariableInteger(Variable): '${lp} qmi_utils_read_${private_format}_from_buffer (\n' '${lp} &${buffer_name},\n' '${lp} &${buffer_len},\n' + '${lp} ${endian},\n' '${lp} &tmp);\n' '\n' '${lp} g_string_append_printf (${printable}, "${common_format}", ${common_cast}tmp);\n' -- cgit v1.1