From 8862be5c05f3723da2304d9f0c66e0489b02d792 Mon Sep 17 00:00:00 2001 From: Felipe Martins Diel <41558831+felipediel@users.noreply.github.com> Date: Mon, 8 Jun 2020 07:22:27 -0300 Subject: [PATCH] Use little-endian for the MAC address and connection ID (#370) --- broadlink/__init__.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/broadlink/__init__.py b/broadlink/__init__.py index a3b94a8..ccb5840 100644 --- a/broadlink/__init__.py +++ b/broadlink/__init__.py @@ -137,7 +137,7 @@ def discover(timeout=None, local_ip_address=None, discover_ip_address='255.255.2 responsepacket = bytearray(response[0]) host = response[1] devtype = responsepacket[0x34] | responsepacket[0x35] << 8 - mac = responsepacket[0x3a:0x40] + mac = responsepacket[0x3f:0x39:-1] name = responsepacket[0x40:].split(b'\x00')[0].decode('utf-8') cloud = bool(responsepacket[-1]) device = gendevice(devtype, host, mac, name=name, cloud=cloud) @@ -154,7 +154,7 @@ def discover(timeout=None, local_ip_address=None, discover_ip_address='255.255.2 responsepacket = bytearray(response[0]) host = response[1] devtype = responsepacket[0x34] | responsepacket[0x35] << 8 - mac = responsepacket[0x3a:0x40] + mac = responsepacket[0x3f:0x39:-1] name = responsepacket[0x40:].split(b'\x00')[0].decode('utf-8') cloud = bool(responsepacket[-1]) device = gendevice(devtype, host, mac, name=name, cloud=cloud) @@ -230,7 +230,7 @@ class device: if len(key) % 16 != 0: return False - self.id = payload[0x00:0x04] + self.id = payload[0x03::-1] self.update_aes(key) return True @@ -267,16 +267,16 @@ class device: packet[0x26] = command packet[0x28] = self.count & 0xff packet[0x29] = self.count >> 8 - packet[0x2a] = self.mac[0] - packet[0x2b] = self.mac[1] - packet[0x2c] = self.mac[2] - packet[0x2d] = self.mac[3] - packet[0x2e] = self.mac[4] - packet[0x2f] = self.mac[5] - packet[0x30] = self.id[0] - packet[0x31] = self.id[1] - packet[0x32] = self.id[2] - packet[0x33] = self.id[3] + packet[0x2a] = self.mac[5] + packet[0x2b] = self.mac[4] + packet[0x2c] = self.mac[3] + packet[0x2d] = self.mac[2] + packet[0x2e] = self.mac[1] + packet[0x2f] = self.mac[0] + packet[0x30] = self.id[3] + packet[0x31] = self.id[2] + packet[0x32] = self.id[1] + packet[0x33] = self.id[0] # pad the payload for AES encryption if payload: