From a210e722d53571f2edc90f03dc2814f954031e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Sat, 24 Feb 2018 12:31:36 +0100 Subject: qmi-codegen: TLVs < 0x10 are mandatory by default The fallback logic of specifying an explicit value has been retained because the following fields: CTL Set Data Format: Protocol id=0x10 mandatory=True NAS Attach Detach: Action id=0x10 mandatory=True DMS Set Time: Time Reference Type id=0x10 mandatory=True WDS Get Current Settings: Requested Settings id=0x10 mandatory=True PDC Register: Enable Reporting id=0x10 mandatory=True PDC List Configs: Config Type id=0x11 mandatory=True PDC Delete Config: Id id=0x11 mandatory=True This was also true for the following, but changed because testing revealed that they should be indeed mandatory: LOC Start: Session ID id=0x01 mandatory=False LOC Stop: Session ID id=0x01 mandatory=False LOC Start: Session ID id=0x01 mandatory=False LOC Stop: Session ID id=0x01 mandatory=False Also the old code did not regard any TLVs as mandatory, as Field.mandatory was a boolean but was compared to the string "yes", breaking the logic. --- build-aux/qmi-codegen/Field.py | 11 +++++++++-- build-aux/qmi-codegen/Message.py | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'build-aux') diff --git a/build-aux/qmi-codegen/Field.py b/build-aux/qmi-codegen/Field.py index 631890ff..fde9ed40 100644 --- a/build-aux/qmi-codegen/Field.py +++ b/build-aux/qmi-codegen/Field.py @@ -41,8 +41,8 @@ class Field: self.name = dictionary['name'] # The specific TLV ID self.id = dictionary['id'] - # Whether the field is to be considered mandatory in the message - self.mandatory = True if dictionary['mandatory'] == 'yes' else False + # Overridden mandatory field, the default is calculated from id + self._mandatory = dictionary.get('mandatory') # The type, which must always be "TLV" self.type = dictionary['type'] # The container type, which must be either "Input" or "Output" @@ -87,6 +87,13 @@ class Field: raise RuntimeError('Common type \'%s\' not found' % prerequisite_dictionary['name']) + @property + def mandatory(self): + if self._mandatory is None: + return int(self.id, 0) < 0x10 + return self._mandatory == 'yes' + + """ Emit new types required by this field """ diff --git a/build-aux/qmi-codegen/Message.py b/build-aux/qmi-codegen/Message.py index ea6622ba..8a1d1500 100644 --- a/build-aux/qmi-codegen/Message.py +++ b/build-aux/qmi-codegen/Message.py @@ -125,7 +125,7 @@ class Message: # Count how many mandatory fields we have n_mandatory = 0 for field in self.input.fields: - if field.mandatory == 'yes': + if field.mandatory: n_mandatory += 1 if n_mandatory == 0: @@ -164,7 +164,7 @@ class Message: # Emit the TLV getter field.emit_input_tlv_add(cfile, ' ') - if field.mandatory == 'yes': + if field.mandatory: template = ( ' } else {\n' ' g_set_error (error,\n' -- cgit v1.2.1