Bluetooth scan doesn't detect any device on Ubuntu 21.10

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

Solution 1:

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!

Solution 2:

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.