Created
May 22, 2025 15:03
-
-
Save sasdf/9d7d8b4369e9e30c43acf8c79ddbf869 to your computer and use it in GitHub Desktop.
Linux bluetooth driver patch for MA530
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import lzma | |
import re | |
import struct | |
# Find your current driver in /lib/modules/$(uname -r)/kernel/drivers/bluetooth/btusb.ko.xz | |
with lzma.open('./btusb.ko.xz.org', 'rb') as f: | |
data = bytearray(f.read()) | |
# See also https://patches.linaro.org/project/linux-bluetooth/patch/[email protected]/ | |
# | |
# Instead of adding the device id, we replace an existing one to skip recompilation. | |
src = struct.pack('<HH', 0x2357, 0x0604) | |
dst = struct.pack('<HH', 0x2c4e, 0x0115) | |
idx = data.find(dst) | |
if idx != -1: | |
print('[!] FATAL: Target device id is already supported') | |
exit(-1) | |
idx = data.find(src) | |
if idx == -1: | |
print('[!] FATAL: Source device id not found') | |
exit(-1) | |
print(f'[+] Patch at 0x{idx:x}') | |
print(' ' + re.sub(r'(..)', r'\1 ', data[idx-4:idx+8].hex()), '->') | |
data[idx:idx+len(dst)] = dst | |
print(' ' + re.sub(r'(..)', r'\1 ', data[idx-4:idx+8].hex())) | |
if data.find(src) != -1: | |
print(f'[!] FATAL: Source device id matched too many times') | |
exit(-1) | |
with lzma.open('./btusb.ko.xz', 'wb') as f: | |
f.write(data) | |
print('[+] Success! Please move the patched driver back to the modules folder') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment