Skip to content

Instantly share code, notes, and snippets.

@andsens
Created February 2, 2021 07:34
Show Gist options
  • Save andsens/10abada615b69b8ca9b1f2b439288b30 to your computer and use it in GitHub Desktop.
Save andsens/10abada615b69b8ca9b1f2b439288b30 to your computer and use it in GitHub Desktop.
Patches the linux bluetooth driver to handle dongles that report they are CSR, but really aren't
#!/usr/bin/env bash
# https://askubuntu.com/questions/1168123/how-do-i-get-my-bluetooth-device-working/1192200#1192200
set -e
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
main() {
local kernver
kernver=$(uname -r)
sudo apt update
rm -rf "$SCRIPTDIR"/linux{-,_}*
apt source linux
local drvdir="$SCRIPTDIR/linux-${kernver/%-*}/drivers/bluetooth"
patch -d "$drvdir" <<<"--- btusb.c 2021-01-28 10:00:00.000000000 +0000
+++ btusb.c 2021-01-28 10:00:00.000000000 +0000
@@ -1642,8 +1642,8 @@
rp = (struct hci_rp_read_local_version *)skb->data;
/* Detect controllers which aren't real CSR ones. */
- if (le16_to_cpu(rp->manufacturer) != 10 ||
- le16_to_cpu(rp->lmp_subver) == 0x0c5c) {
+ /* if (le16_to_cpu(rp->manufacturer) != 10 ||
+ le16_to_cpu(rp->lmp_subver) == 0x0c5c) */ {
/* Clear the reset quirk since this is not an actual
* early Bluetooth 1.1 device from CSR.
*/
@@ -3899,7 +3899,7 @@
set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
/* Fake CSR devices with broken commands */
- if (bcdDevice <= 0x100 || bcdDevice == 0x134)
+ // if (bcdDevice <= 0x100 || bcdDevice == 0x134)
hdev->setup = btusb_setup_csr;
set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
"
make -C "/lib/modules/$kernver/build" M="$drvdir" clean
cp "/usr/src/linux-headers-$kernver/.config" "$drvdir/"
cp "/usr/src/linux-headers-$kernver/Module.symvers" "$drvdir/Module.symvers"
make -C "/lib/modules/$kernver/build" M="$drvdir" modules
local backupdir="$SCRIPTDIR/backup/$kernver"
mkdir -p "$backupdir"
sudo cp "/lib/modules/$kernver/kernel/drivers/bluetooth/btusb.ko" "$backupdir/btusb.ko"
sudo cp "$drvdir/btusb.ko" "/lib/modules/$kernver/kernel/drivers/bluetooth/btusb.ko"
sudo modprobe -r btusb
sudo modprobe -v btusb
}
main "$@"
@bv7
Copy link

bv7 commented Feb 23, 2022

metod don't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment