Skip to content

Commit

Permalink
Add Bose manufacturer data implementation (issue #18)
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Jun 13, 2020
1 parent f2ed225 commit 30e046d
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions bose_manufacturer_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import hashlib


def unextract_manufacturer_id(manufacturer_id: int, manufacturer_data: bytes) -> bytes:
manufacturer_id_bytes = bytes([manufacturer_id & 0xFF, (manufacturer_id >> 8) & 0xFF])
return manufacturer_id_bytes + manufacturer_data


def mac_hash(mac: bytes, data: bytes) -> bytes:
new_data = data[:4] + mac + data[9:]
hash_data = new_data.hex().upper().encode("utf-8")
return hashlib.sha256(hash_data).digest()


def is_bose_device(mac: bytes, data: bytes) -> bool:
partial_mac_hash = data[4:9]
return partial_mac_hash in mac_hash(mac, data) # possibly ok implementation?
# return partial_mac_hash.hex() in mac_hash(mac, data).hex() # official implementation via .hex()


# from bluez dbus
mac = bytes([0x4C, 0x87, 0x5D, 0x53, 0xF2, 0xCF])
manufacturer_id = 2305
manufacturer_data = bytes([113, 18, 177, 27, 65, 149, 232, 52, 213, 174, 45, 195, 82])

# reconstruct full manufacturer data
# bose doesn't use manufacturer id correctly
# data = bytes([1, 9, 113, 18, 177, 27, 65, 149, 232, 52, 213, 174, 45, 195, 82])
data = unextract_manufacturer_id(manufacturer_id, manufacturer_data)

print(is_bose_device(mac, data))

0 comments on commit 30e046d

Please sign in to comment.