ubuntu18.04 rtl8761a bluetooth driver

 最近想给我的台式机上加个蓝牙适配器,蓝牙5.0那种,支持BLE设备,这样我就可以基于我的手环以及手机之类的BLE设备做一些东西玩玩。不幸的是,蓝牙适配器买回来后没法驱动,dmesg | tail -f 可以看到加载/lib/firmware/rtl_bt/下面的firmware失败了,我进目录看了下,并没有现成的firmware。Google了一下,在linux git repo中找到了需要的文件,然后就是下载解压复制,重新插拔usb蓝牙适配器,提示加载firmware成功了,hciconfig -a也可以看到hci0设备了,但是执行部分指令的时候失败,blueman也无法操作蓝牙适配器。

蓝牙适配器型号是:

uGreen Bluetooth 5.0 USB Adapter CM390

(base) ➜  ~ dmesg | tail -f
[  406.634801] usb 1-12.4.2: Product: Bluetooth Radio
[  406.634802] usb 1-12.4.2: Manufacturer: Realtek
[  406.634803] usb 1-12.4.2: SerialNumber: 00E04C239987
[  406.646215] Bluetooth: hci0: RTL: examining hci_ver=0a hci_rev=000b lmp_ver=0a lmp_subver=8761
[  406.647209] Bluetooth: hci0: RTL: rom_version status=0 version=1
[  406.647212] Bluetooth: hci0: RTL: loading rtl_bt/rtl8761a_fw.bin
[  406.647312] Bluetooth: hci0: RTL: loading rtl_bt/rtl8761a_config.bin
[  406.647339] Bluetooth: hci0: RTL: cfg_sz 44, total sz 14808
[  408.725601] Bluetooth: hci0: command 0xfc20 tx timeout
[  416.789322] Bluetooth: hci0: RTL: download fw command failed (-110)
(base) ➜  ~ hciconfig -a
hci0:	Type: Primary  Bus: USB
	BD Address: 00:00:00:00:00:00  ACL MTU: 0:0  SCO MTU: 0:0
	DOWN 
	RX bytes:427 acl:0 sco:0 events:60 errors:0
	TX bytes:15050 acl:0 sco:0 commands:61 errors:0
	Features: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	Packet type: DM1 DH1 HV1 
	Link policy: 
	Link mode: SLAVE ACCEPT 

虽然log中显示的型号是rtl8761a,但是不知道识别得是否正确,这个型号信息有可能不是它的真实型号。网上查不到关于这个cm390的更多的芯片信息。

百般查找,发现这个蓝牙适配器芯片的型号为:rtl8761buv!!!

尝试了一种取巧的办法,就是将找到的rtl8761bu的firmware改名,改成rtl8761a,但是加载的时候报错“unknow project id 14”,使用hcitool操作的时候也报错,显然这种办法也是不行的。

[ 1185.809177] Bluetooth: hci0: RTL: rom_version status=0 version=1
[ 1185.809197] Bluetooth: hci0: RTL: rtl: loading rtl_bt/rtl8761a_fw.bin
[ 1185.809911] Bluetooth: hci0: RTL: rtl: loading rtl_bt/rtl8761a_config.bin
[ 1185.810051] Bluetooth: hci0: RTL: unknown project id 14
[ 1186.430001] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[ 1186.430016] Bluetooth: BNEP filters: protocol multicast
[ 1186.430046] Bluetooth: BNEP socket layer initialized

“hci0: RTL: unknown project id 14”所以,log中显示出来加载rtl8761a的firmware明显是不对的。之所以识别不正确,从网上可以查到的信息来看,是因为kernel的驱动btusb.c中有bug,需要修改后重新编译安装。

接下来下载我的kernel版本对应的源码。

uname -a
5.4.0-80-generic #90~18.04.1-Ubuntu
git clone git://kernel.ubuntu.com/ubuntu/ubuntu-bionic.git

checkout与我的内核版本一致的tag,然后主要参照下面两篇文章,问题搞定。

https://github.com/torvalds/linux/blob/master/drivers/bluetooth/btrtl.c

https://gist.github.com/rometsch/dfd24fb09c85c1ad2f25223dc1481aaa

在第二个地址中,它解决的是rtl8761b芯片的驱动,直接照着改还是不行的,因为我的芯片是rtl8761bu,所以将firmware改正确就好了,然后编译,替换,重启,蓝牙适配器插上

(base) ➜  ~ dmesg|grep "Bluetooth"

[   43.647082] usb 1-12.4.2: Product: Bluetooth Radio
[   43.677827] Bluetooth: Core ver 2.22
[   43.677845] Bluetooth: HCI device and connection manager initialized
[   43.677847] Bluetooth: HCI socket layer initialized
[   43.677848] Bluetooth: L2CAP socket layer initialized
[   43.677849] Bluetooth: SCO socket layer initialized
[   43.685124] Bluetooth: hci0: RTL: examining hci_ver=0a hci_rev=000b lmp_ver=0a lmp_subver=8761
[   43.686127] Bluetooth: hci0: RTL: rom_version status=0 version=1
[   43.686128] Bluetooth: hci0: RTL: loading rtl_bt/rtl8761bu_fw.bin
[   43.686487] Bluetooth: hci0: RTL: loading rtl_bt/rtl8761bu_config.bin
[   43.686560] Bluetooth: hci0: RTL: cfg_sz 6, total sz 20522
[   43.721049] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   43.721050] Bluetooth: BNEP filters: protocol multicast
[   43.721052] Bluetooth: BNEP socket layer initialized
[   43.797228] Bluetooth: hci0: RTL: fw version 0x0999646b
[   43.869262] Bluetooth: RFCOMM TTY layer initialized
[   43.869267] Bluetooth: RFCOMM socket layer initialized
[   43.869269] Bluetooth: RFCOMM ver 1.11
[ 1202.463538] Bluetooth: hci0: hardware error 0x33

可以看到蓝牙适配器正常驱动起来了,使用Bluetooth Manager程序搜索一下,成功发现N多蓝牙设备,试了一下与我的手环链接,都是正常的。到此结束。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值