From 5b526d5a4ec3eadbdde6edda949e45f8b459b6c0 Mon Sep 17 00:00:00 2001 From: Michael Toner <22949655+mtoner23@users.noreply.github.com> Date: Mon, 27 Nov 2023 22:34:16 -0600 Subject: [PATCH 1/2] Changing mqtt padding from zeros to bytes --- .gitignore | 1 + libflagship/mqtt.py | 6 +++--- libflagship/mqttapi.py | 3 ++- specification/mqtt.stf | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 16ba6fdd..a1e488b0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__ .DS_Store /settings.json +.vscode/ diff --git a/libflagship/mqtt.py b/libflagship/mqtt.py index 40da6935..18b80022 100644 --- a/libflagship/mqtt.py +++ b/libflagship/mqtt.py @@ -89,7 +89,7 @@ class _MqttMsg: packet_num : u16le # maybe for fragmented messages?set to 1 for unfragmented messages. time : u32le # `gettimeofday()` in whole seconds device_guid: bytes # device guid, as hex string - padding : bytes = field(repr=False, kw_only=True, default='\x00' * 11) # padding bytes, allways zero + padding : bytes # padding bytes, unknown usage data : bytes # payload data @classmethod @@ -105,7 +105,7 @@ def parse(cls, p): packet_num, p = u16le.parse(p) time, p = u32le.parse(p) device_guid, p = String.parse(p, 37) - padding, p = Zeroes.parse(p, 11) + padding, p = Bytes.parse(p, 11) data, p = Tail.parse(p) return cls(signature=signature, size=size, m3=m3, m4=m4, m5=m5, m6=m6, m7=m7, packet_type=packet_type, packet_num=packet_num, time=time, device_guid=device_guid, padding=padding, data=data), p @@ -121,7 +121,7 @@ def pack(self): p += u16le.pack(self.packet_num) p += u32le.pack(self.time) p += String.pack(self.device_guid, 37) - p += Zeroes.pack(self.padding, 11) + p += Bytes.pack(self.padding, 11) p += Tail.pack(self.data) return p diff --git a/libflagship/mqttapi.py b/libflagship/mqttapi.py index 13dc6627..6d45ee4d 100644 --- a/libflagship/mqttapi.py +++ b/libflagship/mqttapi.py @@ -51,7 +51,8 @@ def _on_message(self, client, userdata, msg): try: pkt, tail = MqttMsg.parse(msg.payload, key=self._key) except Exception as E: - log.error(f"Failed to decode mqtt message: {E}") + hexStr =' '.join([f'0x{byte:02x}' for byte in msg.payload]) + log.error(f"Failed to decode mqtt message\n Exception: {E}\n Message : {hexStr}") return data = json.loads(pkt.data) diff --git a/specification/mqtt.stf b/specification/mqtt.stf index 47cb0f1e..dd562700 100644 --- a/specification/mqtt.stf +++ b/specification/mqtt.stf @@ -50,8 +50,8 @@ struct _MqttMsg # device guid, as hex string device_guid: string<37> - # padding bytes, allways zero - padding: zeroes<11> + # padding bytes, unknown usage + padding: bytes<11> # payload data data: tail From c1bdf07a31a249e6def7def75764815dd0f172e0 Mon Sep 17 00:00:00 2001 From: Michael Toner <22949655+mtoner23@users.noreply.github.com> Date: Tue, 28 Nov 2023 22:13:38 -0600 Subject: [PATCH 2/2] remove .vscode from git ignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index a1e488b0..16ba6fdd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ __pycache__ .DS_Store /settings.json -.vscode/