ubuntu系统中settings/bluetooth不可用

不可用的原因分析

首先,以上问题定位到的原因是由于删除了/dev/rfkill节点导致的,至于删除/dev/rfkill节点的原因,rockchip社区版的debian11代码中有进行了解释

https://github.com/Fruit-Pi/debian/commit/805962083a941a8ee27c45de05a6fe55d9737591

mkrootfs-bullseye.sh: fix the blueman ui issue

The blueman[0]'s BT power supply will be operated through rfkill when
switching.

Generally, BT can only be used after initialization (loading firmware and other
operations) after power on. The upstream standard is to execute automatically
in the kernel driver (btbcm.c driver). The embedded platform generally uses
the upper tool command.

In general, we perhaps have some solutions as below.
1) Modify the blueMan code and call the command initialization when it is
  turned on.

2) Modify the blueMan code, and do not operate rfkill when switching (or try to
  delete /dev/rfkill directly).

3) In addition, monitor the rfkill status, and automatically call the command
   initialization after power on (https://github.com/hmallat/bluetooth-rfkill-event/blob/master/
     bluetooth-rfkill-event/bluetooth_rfkill_event.c)

以上描述中,对应kernel中的驱动文件为kernel/drivers/bluetooth/btbcm.c,是Broadcom devices的驱动文件。而我们项目中使用的Bluetooth USB driver,对应驱动文件为kernel/drivers/bluetooth/btusb.c,两个驱动文件在操作蓝牙开关时底层实现部分可能会存在差异。

根据以上描述,对蓝牙管理工具进行调试,操作蓝牙开关时,提取日志信息为:journalctl -f 

##### 关闭蓝牙开关
Jun 06 10:17:13 Ubuntu20-04 kernel: rtk_btusb: btusb_flush add delay 
Jun 06 10:17:13 Ubuntu20-04 kernel: rtk_btusb: btusb_close
Jun 06 10:17:13 Ubuntu20-04 kernel: rtk_btcoex: Close BTCOEX
Jun 06 10:17:13 Ubuntu20-04 kernel: rtk_btcoex: -x
Jun 06 10:17:13 Ubuntu20-04 kernel: [BT_RFKILL]: bt shut off power
##### 打开蓝牙开关
[ 4153.594469] rtk_btusb: btusb_open hdev->promisc ==0
[ 4153.668740] debugfs: File 'force_bredr_smp' in directory 'hci0' already present!
Jun 06 10:17:15 Ubuntu20-04 kernel: [BT_RFKILL]: rfkill_rk_set_power: set bt wake_host high!
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btusb: btusb_open start
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btusb: btusb_open hdev->promisc ==0
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btusb: download_patch start
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btusb: chip type value: 0x73
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btusb: HCI reset.
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btusb: read_ver_rsp->lmp_subver = 0xcbc9
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btusb: read_ver_rsp->hci_rev = 0x9a8
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btusb: patch_entry->lmp_sub = 0x8822
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btusb: Firmware already exists
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btusb: Rtk patch end 1
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btusb: btusb_open set HCI_RUNNING
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btcoex: Open BTCOEX
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btusb: btusb_open end
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btcoex: BTCOEX hci_rev 0x09a8
Jun 06 10:17:15 Ubuntu20-04 kernel: rtk_btcoex: BTCOEX lmp_subver 0xcbc9
Jun 06 10:17:15 Ubuntu20-04 kernel: [BT_RFKILL]: bt turn on power
Jun 06 10:17:15 Ubuntu20-04 kernel: [BT_RFKILL]: Request irq for bt wakeup host
Jun 06 10:17:15 Ubuntu20-04 kernel: [BT_RFKILL]: ** disable irq

ubuntu系统中有两个蓝牙设备的管理工具,一个是bluetooth manager(blueman),另外一个就是settings中的bluetooth,可通过gnome-control-center bluetooth指令打开

分别使用系统中自带blueman(bluetooth manager)工具,打开/关闭蓝牙开关测试 

#关闭蓝牙开关时 

cat /sys/class/rfkill/rfkill0/state = 0

#打开蓝牙开关时 

cat /sys/class/rfkill/rfkill0/state = 1

使用gnome-control-center bluetooth工具,打开/关闭蓝牙开关测试,

#关闭蓝牙开关时 

cat /sys/class/rfkill/rfkill0/state = 0

#打开蓝牙开关时

cat /sys/class/rfkill/rfkill0/state = 1

最后,试图修改blueman源码中修改rfkill state部分的代码,使blueman操作蓝牙开关时,/sys/class/rfkill/rfkill0/state值不发生变化,对应文件为blueman/blueman/plugins/applet/KillSwitch.py

屏蔽掉以下代码,位于函数 def on_power_state_change_requested(self, _, state, cb):中

if self._connman_proxy:
            logging.debug("Using connman to set state: %s" % state)
            #self._connman_proxy.SetProperty('(sv)', 'Powered', GLib.Variant.new_boolean(state),
                                            #result_handler=reply, error_handler=error)
        else:
            logging.debug("Using mechanism to set state: %s" % state)
            #Mechanism().SetRfkillState('(b)', state, result_handler=reply, error_handler=error)

ubuntu20.04系统中blueman的版本号: blueman_2.1.2-1ubuntu0.3_arm64.deb

blueman源码下载、编译和安装

git clone https://github.com/blueman-project/blueman.git

其tags中包含了各个版本,2.1.2 tag对应的commit信息为f7707ea5ab1ee6bf1f938976d67c83e5384199b5

git reset --hard f7707ea5ab1ee6bf1f938976d67c83e5384199b5

对应2.1.2版本的源码

或者从http://ports.ubuntu.com/ubuntu-ports/pool/universe/b/blueman/官方发布的源码下载blueman_2.1.2.orig.tar.xz

编译环境的安装

apt-get install automake autoconf
apt-get install libtool
apt-get install intltool
cd /usr/bin/
ln -sf python3 python
apt-get install python3-dev
apt-get install python-gi-dev
apt-get install cython
apt-get install bluez
apt-get install libbluetooth-dev

如果是从git仓库下载的源码,需要执行./autogen.sh生成configure,然后 make && make install

如果是从ubuntu.ports下载的源码包,直接运行./configure && make && make install即可

注意:安装完成后默认bluetoothmanager无法打开,报错信息

Traceback (most recent call last):
  File "/usr/local/bin/blueman-manager", line 18, in <module>
    from blueman.main.Manager import Blueman
ModuleNotFoundError: No module named 'blueman'

解决方法:

https://github.com/blueman-project/blueman/issues/873

make install put the module into /usr/lib/python3/dist-packages,默认安装路径为/usr/lib/python3/site-packages

安装成功后,打开bluetooth manager,中turn off时开关无效 cat /sys/class/rfkill/rfkill0/state值一直为1

删除/dev/rfkill节点的目的,也就是为了保持/sys/class/rfkill/rfkill0/state值一直为1

blueman和gnome-control-centor bluetooth的区别和联系

blueman和gnome-control-center bluetooth都是用于管理蓝牙设备的工具,但它们有一些区别和联系。

blueman是一个独立的蓝牙管理工具,它提供了更多的功能和选项,比如支持蓝牙音频设备的管理、蓝牙文件传输、蓝牙网络连接等。blueman还提供了一个系统托盘图标,方便用户快速访问蓝牙设备。

gnome-control-center bluetooth是GNOME桌面环境自带的蓝牙管理工具,它提供了基本的蓝牙设备管理功能,比如搜索、配对、连接、断开连接等。gnome-control-center bluetooth也可以在系统设置中找到。

blueman和gnome-control-center bluetooth的联系在于它们都是用于管理蓝牙设备的工具,而且都可以在Linux系统中使用。但blueman提供了更多的功能和选项,而gnome-control-center bluetooth则更加简洁易用。用户可以根据自己的需求选择使用哪个工具。

蓝牙管理工具工作机制

DBus是Linux系统中常用的进程间通信机制,它可以让不同的进程之间进行通信和交互。

以gnome-control-center为例说明:

gnome-control-center是GNOME桌面环境的控制中心,其中包含了蓝牙设置的功能。在GNOME桌面环境中,蓝牙开关的实现是通过bluez这个蓝牙协议栈来实现的。

当用户在gnome-control-center中打开或关闭蓝牙开关时,gnome-control-center会调用bluez提供的DBus接口来控制蓝牙设备的开关状态。具体来说,gnome-control-center会向DBus发送一个请求,请求bluez来打开或关闭蓝牙设备。DBus会将这个请求发送给bluez的蓝牙管理器(bluetoothd),蓝牙管理器会根据请求来控制蓝牙设备的开关状态。

在蓝牙设备开关状态发生变化时,蓝牙管理器(bluetoothd)会向DBus发送一个信号,告知gnome-control-center蓝牙设备的状态已经发生了改变。gnome-control-center会根据这个信号来更新蓝牙开关的状态,以确保与蓝牙设备的连接和通信正常进行。

blueman蓝牙管理工具的工作机制和以上相同,都是通过Dbus与bluetoothd通信,bluetoothd负责控制蓝牙设备。

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值