Score:8

Bluetooth scan doesn't detect any device on Ubuntu 21.10

us flag

I have just bought a Tp-link bluetooth 5.0 usb adapter (UB500), I've checked and its chip is Realtek RTL8761B. It works just fine on Windows 10, but I'm having problems on Ubuntu. I'm running Ubuntu 21.10 and I've just upgraded to the latest stable kernel version: 5.14.14. Before upgrading I tried this solution but with no success: https://linuxreviews.org/Realtek_RTL8761B

I've tried almost everything I've found online, but most of the solutions don't apply because there is no evident problem: the adapter seems to be correctly installed and properly working, however scanning does not pick up any bluetooth device. I've tried two headsets (that I know are properly working) and my phone, with no success. When performing a scan on my phone, the computer doesn't show up, even if I've set it to visible.

I can't figure out what the problem is.

    dmesg |grep -i bluetooth
    [    3.596913] Bluetooth: Core ver 2.22
    [    3.596935] NET: Registered PF_BLUETOOTH protocol family
    [    3.596936] Bluetooth: HCI device and connection manager initialized
    [    3.596939] Bluetooth: HCI socket layer initialized
    [    3.596941] Bluetooth: L2CAP socket layer initialized
    [    3.596945] Bluetooth: SCO socket layer initialized
    [   93.519895] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
    [   93.519899] Bluetooth: BNEP filters: protocol multicast
    [   93.519903] Bluetooth: BNEP socket layer initialized
    [  144.060814] Bluetooth: RFCOMM TTY layer initialized
    [  144.060821] Bluetooth: RFCOMM socket layer initialized
    [  144.060825] Bluetooth: RFCOMM ver 1.11
    hciconfig -a
    hci0:    Type: Primary  Bus: USB
        BD Address: E8:48:B8:C8:20:00  ACL MTU: 1021:6  SCO MTU: 255:12
        UP RUNNING 
        RX bytes:4264 acl:0 sco:0 events:560 errors:0
        TX bytes:9000 acl:0 sco:0 commands:490 errors:0
        Features: 0xff 0xff 0xff 0xfe 0xdb 0xfd 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
        Link policy: RSWITCH HOLD SNIFF PARK 
        Link mode: SLAVE ACCEPT 
        Name: 'gaia-ubuntu-desktop'
        Class: 0x7c0104
        Service Classes: Rendering, Capturing, Object Transfer, Audio, Telephony
        Device Class: Computer, Desktop workstation
        HCI Version: 5.1 (0xa)  Revision: 0xb
        LMP Version: 5.1 (0xa)  Subversion: 0x8761
        Manufacturer: Realtek Semiconductor Corporation (93)
    rfkill list
    0: hci0: Bluetooth
        Soft blocked: no
        Hard blocked: no
    lsusb
    Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 003 Device 004: ID 046d:0826 Logitech, Inc. HD Webcam C525
    Bus 003 Device 003: ID 04b8:013d Seiko Epson Corp. Epson Perfection V39
    Bus 003 Device 002: ID 0c76:2068 JMTek, LLC. USB MIC-SG01
    Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 001 Device 003: ID 2357:0604 TP-Link TP%Link UB500 Adapter
    Bus 001 Device 002: ID 062a:3633 MosArt Semiconductor Corp. Full-Speed Mouse
    Bus 001 Device 004: ID 145f:0176 Trust Isla Keyboard
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
usb-devices | awk '/0604/' RS=
T:  Bus=01 Lev=01 Prnt=01 Port=07 Cnt=03 Dev#=  3 Spd=12  MxCh= 0
D:  Ver= 1.10 Cls=e0(wlcon) Sub=01 Prot=01 MxPS=64 #Cfgs=  1
P:  Vendor=2357 ProdID=0604 Rev=02.00
S:  Manufacturer= 
S:  Product=TP%Link UB500 Adapter
S:  SerialNumber=E848B8C82000
C:  #Ifs= 2 Cfg#= 1 Atr=e0 MxPwr=500mA
I:  If#=0x0 Alt= 0 #EPs= 3 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
I:  If#=0x1 Alt= 0 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
Pilot6 avatar
cn flag
What does `lsusb` show?
us flag
I've edited the original post and included lsusb.
Pilot6 avatar
cn flag
It is not supported by any existing kernel. Please add output of `usb-devices | awk '/0604/' RS=`
us flag
edited again. thank you btw
Pilot6 avatar
cn flag
It is hard to tell what is the chip? Who told you it was RTL8761B? If it is really that chip, then a simple kernel patch will fix it.
Someone avatar
my flag
Plz give the output of sudo lshw ,
us flag
I googled the ID and found it here: https://usb-ids.gowdy.us/read/UD/2357/0604 @Pilot6
Pilot6 avatar
cn flag
OK. Then it should be added to `btusb.c`. I suggest filing a bug to launchpad. But it is also possible to create a small dkms module with a code.
us flag
@AkshajSingla it's too long to post it
us flag
@Pilot6 good! could you perhaps help me with that? I have no idea how to do it
Pilot6 avatar
cn flag
Somebody may help. You can build a kernel with a patch, or create a dkms module. If the device works a patch should be sent upstream to be added to the mainline code.
Score:6
bt flag

I have faced the same issue with the Tp-Link UB500 adapter and I could solve this problem as suggested by Pilot6. Follow the steps below. Thanks to Pilot6.

Step 1: Download and extract Linux kernel source file.

wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.11.tar.xz
tar xpvf linux-5.11.tar.xz

Be sure to use kernel version according to your system (can be checked with uname -r)

Step 2: Edit btusb.c

cd linux-5.11/drivers/bluetooth
gedit btusb.c

add the following

/* Tp-Link UB500 */
{ USB_DEVICE(0x2357, 0x0604), .driver_info = BTUSB_REALTEK },

Under the section "static const struct usb_device_id blacklist_table[]". After /* Silicon Wave based devices */.

Step 3: Edit hci_ldisc.c

(may not be needed for some versions of kernel)

Replace

static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file,
                 unsigned char __user *buf, size_t nr)

to

static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file,
                 unsigned char __user *buf, size_t nr,
                 void **cookie, unsigned long offset)

Step 4: Compile modules

make -C /lib/modules/$(uname -r)/build M=$(pwd) clean
cp /usr/src/linux-headers-$(uname -r)/.config ./
cp /usr/src/linux-headers-$(uname -r)/Module.symvers Module.symvers
make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
sudo cp btusb.ko /lib/modules/$(uname -r)/kernel/drivers/bluetooth

If you have secure boot, it's also needed to sign the module, search for "How to sign things for Secure Boot".

Step 5: Repalce the old module

sudo cp btusb.ko /lib/modules/$(uname -r)/kernel/drivers/bluetooth

Step 6: Load new btusb

sudo modprobe -r btusb
sudo modprobe -v btusb

It's working for me!

us flag
Thank you so much! Just a question: at what point of btusb.c should I add those lines? just to make sure I don't make further mistakes
bt flag
I have added under the section "static const struct usb_device_id blacklist_table[]". After /* Silicon Wave based devices */.
us flag
omg IT WORKED! Thank you so much!
Pilot6 avatar
cn flag
Can you explain `void **cookie, unsigned long offset`? It looks like a "dirty hack to me". We need to upstream a patch if we want it in Linux.
Pilot6 avatar
cn flag
As a temporary solution it makes sense to create a dkms `btusb` module to have it working with kernel updates. It is quite easy.
de flag
Hrm, doesn't seem to work for me on Ubuntu 21.04.
J. Knoblauch avatar
hk flag
This may be silly, but make sure that you do step 4 while in the drivers/bluetooth directory of the source code rather than the top-level directory, otherwise you get errors. With that in mind, this worked for Ubuntu 20.04. I also reinstalled the firmware according to @Laion's answer.
br flag
I think this does not work on Ubuntu 20.04
Thomas Kimber avatar
cn flag
How soon is this likely to be resolved in an upcoming Ubuntu patch?
us flag
Ash
this didn't resolve my issue, but its not every day you learn how to patch a kernel - thank you this is awesome!
cosmonaut avatar
md
only step 4 needed in the drivers/bluetoth directory? I receive errors ... should I've done step 1 , 2, 3, although there? (Ubunutu 20.04)
We are Borg avatar
cn flag
Not working, getting /hci_vhci.c:181:7: error: ‘HCI_ISODATA_PKT’ undeclared while compiling.
Score:2
cn flag

If the device is RTL8761B, then a patch to btusb.c kernel code is needed, adding this:

 /* Tp-Link UB500 */
{ USB_DEVICE(0x2357, 0x0604), .driver_info = BTUSB_REALTEK },

The problem is that nobody has added this device to Linux kernel yet. The chip seems to be supported, but the Tp-Link id is not there.

I suggest reporting this to Launchpad. Boot with an Ubuntu kernel and run in a terminal

ubuntu-bug linux

That will create a bug report.

us flag
Gosh, I don't know how to do this. I've added those lines to btusb.c but I have no idea what to do after that I will report it anyway. Thank you
Pilot6 avatar
cn flag
After that you need to build a kernel, install it and test if BT works.
us flag
I've just never done it before
us flag
It's still not working :/
Pilot6 avatar
cn flag
So did you build a custom kernel?
us flag
actually I'm not 100% sure what I did, but apparently it didn't work. And I mean uname -r doesn't show the kernel version I thought I was installing, but the one I had before. I'm kinda lost, I'll probably just report the bug
Pilot6 avatar
cn flag
Please drop a link from Launchpad. Maybe I'll make a module if I have time. BTW, you can build only `btusb` module.
us flag
here it is, lousy as it is, since ubuntu-bug doesn't seem to work https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1948502 btw thank you for your time
vn flag
It seems a similar patch has been submitted there : https://www.spinics.net/lists/linux-bluetooth/msg94476.html
vn flag
...which should land in linux kernel 5.16 according to : https://bbs.archlinux.org/viewtopic.php?pid=2003276#p2003276
Recct avatar
tr flag
I started installing the latest kernels waiting for this to be sorted, `5.18.9-051809-generic` still doesn't recognise the BT dongle :D
de flag
I can confirm this is *still* an issue in a fully-updated 22.04
Score:2
in flag

I followed the steps in @gauthsree answer and the system stopped detecting the adapter.

Then (after a lot of searching and reading) i ran lsusb; dmesg | egrep -i 'blue|firm' and got this:

RTL: firmware file rtl_bt/rtl8761b_fw.bin not found

So, i downloaded the file and placed in: /lib/firmware/rtl_bt/

Then, reboot the system and finally works!

I followed this tutorial: Bluetooth 5.0 chipset Realtek RTL8761B to download and copy the firmware.

My system:

  • OS: Ubuntu 20.04.1
  • Kernel: 5.11.0-46-generic

Hope this help!

SRG avatar
jp flag
SRG
Thank you so much, Laion! This was the last step missing from @gauthsree's answer. I also needed to authenticate my keyboard and followed this guide to solve the issue: https://itectec.com/ubuntu/ubuntu-pairing-bluetooth-keyboard-that-needs-code-failed-to-pair-org-bluez-error-authenticationfailed/
Alexander Soare avatar
in flag
Lifesaver! This worked for me on Ubuntu 20.04
Score:0
za flag

Here is a script that does all the steps of Aeolun.

Also Driver is downloaded and copied, like Laion described.

(I am just learning to bash script and I tried this and thougth I share.)

#!/bin/bash

# Initialization

FIX_UB_500_BT_Stick () {
echo -e "This Script is intended to fix the not working BT Stick UB 500 by TP-Link"
echo -e ""
echo -e "As descrbed in https://askubuntu.com/questions/1370663/bluetooth-scan-doesnt-detect-any-device-on-ubuntu-21-10"
echo -e ""
echo -e "This scripts guides you through all necessary steps. However, please take care. This can break your system, or at least  break your bluetooth."
echo -e ""
echo -e "\033[33mStep 1: Download and extract Linux kernel source file."
echo -e "\033[0m"
echo -e ""
echo -e "Your Kernel-Version: "
version=$(uname -r)
echo $version
echo -e "If not 5.13, change script and restart! (Just search and replace 5.13 with your Version, as long as it is a 5.x)"
read -n 1 -p "Do you want to continue? [y/n]" start
  if [ "$start" = "y" ] ; then
    cd /home/max/
    mkdir FIX_UB_500_BT_Stick
    cd FIX_UB_500_BT_Stick
    wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.13.tar.xz
    tar xpvf linux-5.13.tar.xz
    echo -e "\033[33mDownload location and files:"
    echo -e "\033[0m"
    pwd
    ls
    echo -e "\033[33mLocation of files to be changed:"
    echo -e "\033[0m"
    cd linux-5.13/drivers/bluetooth
    pwd
    echo -e "\033[33mStep 2: Edit btusb.c"
    echo -e "\033[31m"
    echo "Add:"
    echo -e "\033[0m"
    echo "/* Tp-Link UB500 */"
    echo "{ USB_DEVICE(0x2357, 0x0604), .driver_info = BTUSB_REALTEK },"
    echo -e "\033[33m"
    echo "Under the section"
    echo -e "\033[0m"
    echo "static const struct usb_device_id blacklist_table[]"
    echo -e "\033[33m"
    echo "After"
    echo -e "\033[0m"
    echo "/* Silicon Wave based devices */"
    echo -e "\033[33m"
    echo "in btusb.c"
    echo ""
    echo "It should look something like this:"
    echo -e "\033[0m"
    echo "/* Silicon Wave based devices */"
    echo "{ USB_DEVICE(0x0c10, 0x0000), .driver_info = BTUSB_SWAVE },"
    echo "/* Tp-Link UB500 */"
    echo "{ USB_DEVICE(0x2357, 0x0604), .driver_info = BTUSB_REALTEK }, "
    echo "{ }/* Terminating entry */"
    echo ""
    echo -e "\033[31m Safe and close KWrite."
    sleep 5
    kwrite btusb.c
    read -n 1 -p "Did you change the file and want to continue? [y/n]" filechange1
    if [ "$filechange1" = "y" ]; then
      echo -e "\033[33m"
      echo "Ok, continuing."
      echo -e "\033[0m"
    elif [ "$filechange1" = "n" ];then
      sudo rm -r /home/max/FIX_UB_500_BT_Stick
      exit
    else
      echo -e "\033[31mDid you change the file and want to continue? [y/n]; Press ctrl+c to abort."
      echo -e "\033[0m"
      read -n 1
    fi
    echo -e "\033[33mStep 3: Edit hci_ldisc.c"
    echo -e "\033[0m"
    echo -e ""
    File="hci_ldisc.c"
    if grep -q "void **cookie, unsigned long offset)" "$File"; then
      echo -e "\033[33mStep not necessary. File already correct."
      echo -e "\033[0m"
    else
      echo -e "\033[33mChange:"
      echo -e "\033[0m"
      echo "static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file,"
      echo "                 unsigned char __user *buf, size_t nr)"
      echo ""
      echo -e "\033[33minto"
      echo -e "\033[0m"
      echo "static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file,"
      echo "                 unsigned char __user *buf, size_t nr, "
      echo "                 void **cookie, unsigned long offset) "
      echo -e "\033[33m"
      echo "in hci_ldisc.c"
      echo ""
      echo "Safe and Close KWrite. (This step might not be necessary for some versions)"
      sleep 5
      kwrite hci_ldisc.c
      read -n 1 -p "Did you change the file and want to continue? [y/n]" filechange2
      if [ "$filechange2" = "y" ]; then
        echo -e "\033[33m"
        echo "Ok, continuing."
        echo -e "\033[0m"
      elif [ "$filechange2" = "n" ];then
        sudo rm -r /home/max/FIX_UB_500_BT_Stick
        exit
      else
      echo -e "\033[31mDid you change the file and want to continue? [y/n];"
        read -n 1
      fi
    fi
    echo -e "\033[33mStep 4: Compile modules."
    echo -e "\033[0m"
    make -C /lib/modules/$(uname -r)/build M=$(pwd) clean
    echo -e "\033[33mMake 1 done."
    echo -e "\033[0m"
    cp /usr/src/linux-headers-$(uname -r)/.config ./
    cp /usr/src/linux-headers-$(uname -r)/Module.symvers Module.symvers
    make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
    echo -e "\033[33mMake 2 done."
    echo -e "\033[33mStep 5: Replace the old module."
      echo -e "\033[0m"
    sudo cp btusb.ko /lib/modules/$(uname -r)/kernel/drivers/bluetooth
    echo -e "\033[33mCopied to current Kernel"
    echo -e ""
    echo -e "\033[33mStep 6: Load new btusb."
    echo -e "\033[0m"
    sudo modprobe -r btusb
    sudo modprobe -v btusb
    echo -e "\033[33mModprobe done"
    echo -e "\033[0m"


    if [[ ! -f "/lib/firmware/rtl_bt/rtl8761b_fw.bin" ]]
    then
        echo -e "\033[33mStep 7: Download Firmware for UB500 from Realteks GIT."
        read -n 1 -p "The FW for the UB500 BT-Dongle is not present in /lib/firmware/rtl_bt/. /n Do you wish to download the file from Realteks Git and copy it to your system? [y/n]" FW_Install
          if [ "$FW_Install" = "y" ]; then
            echo -e "\033[33m"
            echo "Ok, continuing."
            echo -e "\033[0m"
            cd /home/max/FIX_UB_500_BT_Stick
            mkdir FW
            cd FW
            wget https://github.com/Realtek-OpenSource/android_hardware_realtek/raw/rtk1395/bt/rtkbt/Firmware/BT/rtl8761b_fw
            sudo cp /home/max/FIX_UB_500_BT_Stick/FW/rtl8761b_fw /lib/firmware/rtl_bt/rtl8761b_fw.bin
            if [[ -f "/lib/firmware/rtl_bt/rtl8761b_fw.bin" ]]; then
              echo -e "\033[33mFW was successfully copied. Reboot and try your bluetooth stick. It should work now."
            else
              echo -e "\033[33mSomething went wrong.You will have to download the FW yourself and place it in the folder /lib/firmware/rtl_bt/ with the name rtl8761b_fw.bin /n You'll find the file in this Repo: https://github.com/Realtek-OpenSource/android_hardware_realtek/raw/rtk1395/bt/rtkbt/Firmware/BT/rtl8761b_config /n If you placed the file there, reboot and your UB500 should work now."
            fi
          elif [ "$fFW_Install" = "n" ];then
            sudo rm -r /home/max/FIX_UB_500_BT_Stick
            echo -e "\033[33mFW was not downloaded. You will have to download the FW yourself and place it in the folder /lib/firmware/rtl_bt/ with the name rtl8761b_fw.bin /n You'll find the file in this Repo: https://github.com/Realtek-OpenSource/android_hardware_realtek/raw/rtk1395/bt/rtkbt/Firmware/BT/rtl8761b_config /n If you placed the file there, reboot and your UB500 should work now."
            echo -e "\033[0m"
            exit
          else
          echo -e "\033[31mDownload the FW? [y/n];"
            read -n 1
          fi
    else
      echo -e "\033[33mIt looks like, /lib/firmware/rtl_bt/rtl8761b_fw.bin already exists. No further steps needed. Reboot and try your UB500 BT-Stick."
    fi
    sudo rm -r /home/max/FIX_UB_500_BT_Stick
    echo -e "\033[33mDeleted downloaded files and dircetory /home/max/FIX_UB_500_BT_Stick"
    echo -e "\033[0m"
  elif [ "$start" = "n" ];then
    sudo rm -r /home/max/FIX_UB_500_BT_Stick
    exit
  else
    echo -e "\033[33mYou have entered an invallid selection!"
    echo -e "\033[33mPlease try again!"
    echo -e ""
    echo -e "\033[31mPress any key to continue..."
    read -n 1

  fi
  }

FIX_UB_500_BT_Stick

In Step 3 sadly the check in hci_ldisc.c does not work. So you have to check manually.

It uses kwrite as texteditor.

Do not run script as sudo. Wait for it to ask you for sudo.

If you are like myself new to all of it:

For this to work, create a textfile but use extension .sh not .txt

Copy all the code in it and safe.

In your directory open a terminal.

chmod a+x YOURFILE.sh

bash YOURFILE.sh

Follow instructions precisely.

I edited my answer quite a lot, so it is more helpfull.

Pilot6 avatar
cn flag
It is unclear what is this post about? Does it answer the question? Or it is some fix for KDE Neon, which is off-topic here?
Max Christian Potaß avatar
za flag
A script that does all the steps of Aeolun. So a general fix for ubuntu. Which does not work for me anymore.
Pilot6 avatar
cn flag
Why post it if it doesn't work?
Max Christian Potaß avatar
za flag
It does do, what Aeolun posted as a possible fix. The fix did work for me on Kubuntu. It does not work for me on KDE Neon, however. So It might help, it might not help. I don't know. But if you want to try, you can use the script, which makes it easier. I am not sure, what is unclear about that.
Max Christian Potaß avatar
za flag
I did change the part below the script. Maybe it was that?
Max Christian Potaß avatar
za flag
@Pilot6 Check again. I updated my script. It fixes it now completely.
de flag
You should probably replace the `cd /home/max` with some kind of temporary directory, or at least just `cd`, which defaults to the user's home. Personally, I would have created a temp working directory, with something like `TMPDIR=$(mktemp -d -t btfix-XXXXXXXXXX)`
Max Christian Potaß avatar
za flag
You are right. I at least changed it to only "cd"
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.