From 906e7a1c642a44290c0d7a2b7107aae5854fb72e Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Sun, 18 Aug 2024 18:36:24 -0700 Subject: [PATCH] uvk5: Add a restricted version for unsupported firmwares Since this is such a problem (new firmwares popping up everywhere), add a fallback version-agnostic implementation of the base class that is fully read-only (and won't upload). This will mean that anyone with an unsupported firmware will be able to download the image for inspection and make it easier for us to determine if we should just whitelist the version. --- chirp/drivers/uvk5.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/chirp/drivers/uvk5.py b/chirp/drivers/uvk5.py index 2065c1261..4216a0a18 100644 --- a/chirp/drivers/uvk5.py +++ b/chirp/drivers/uvk5.py @@ -2075,7 +2075,8 @@ def detect_from_serial(cls, pipe): for rclass in cls.detected_models(): if rclass.k5_approve_firmware(firmware): return rclass - raise errors.RadioError('Firmware %r not supported' % firmware) + + return UVK5RestrictedRadio @directory.register @@ -2083,3 +2084,36 @@ class RA79Radio(UVK5Radio): """Retevis RA79""" VENDOR = "Retevis" MODEL = "RA79" + + +@directory.register +@directory.detected_by(UVK5Radio) +class UVK5RestrictedRadio(UVK5RadioBase): + VARIANT = 'unsupported' + + @classmethod + def k5_approve_firmware(cls, firmware): + return False + + def process_mmap(self): + firmware = self.metadata.get('uvk5_firmware', '') + LOG.warning('Firmware %s is not supported by CHIRP. ' + 'Image data will be read-only.', firmware) + self._memobj = bitwise.parse(MEM_FORMAT, self._mmap) + + def sync_out(self): + raise errors.RadioError( + _('Upload is disabled due to unsupported firmware version')) + + def get_memory(self, n): + mem = super().get_memory(n) + mem.immutable = dir(mem) + return mem + + def set_memory(self, m): + raise errors.InvalidValueError( + _('Memories are read-only due to unsupported firmware version')) + + def set_settings(self, settings): + raise errors.InvalidValueError( + _('Settings are read-only due to unsupported firmware version'))