Análise do motivo da indisponibilidade
Em primeiro lugar, o motivo do problema acima é devido à exclusão do nó /dev/rfkill. Quanto ao motivo da exclusão do nó /dev/rfkill, é explicado no código debian11 da versão da comunidade rockchip
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)
Na descrição acima, o arquivo de driver correspondente no kernel é kernel/drivers/bluetooth/btbcm.c, que é o arquivo de driver dos dispositivos Broadcom. Para o driver USB Bluetooth usado em nosso projeto, o arquivo de driver correspondente é kernel/drivers/bluetooth/btusb.c, e a implementação subjacente dos dois arquivos de driver pode diferir ao operar o switch Bluetooth.
De acordo com a descrição acima, depure a ferramenta de gerenciamento Bluetooth. Ao operar o switch Bluetooth, extraia as informações de log como: 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
Existem duas ferramentas de gerenciamento para dispositivos Bluetooth no sistema ubuntu, uma é o gerenciador de bluetooth (blueman) e a outra é o bluetooth nas configurações, que pode ser aberto pelo comando gnome-control-center bluetooth
Use a ferramenta blueman (gerenciador de bluetooth) que acompanha o sistema para ligar/desligar o teste de chave Bluetooth
# Quando o botão bluetooth está desligado
cat /sys/class/rfkill/rfkill0/state = 0
#打开蓝牙开关时
cat /sys/class/rfkill/rfkill0/state = 1
Use a ferramenta bluetooth gnome-control-center para ligar/desligar o teste de chave Bluetooth,
# Quando o botão bluetooth está desligado
cat /sys/class/rfkill/rfkill0/state = 0
#打开蓝牙开关时
cat /sys/class/rfkill/rfkill0/state = 1
Por fim, tente modificar o código da parte do estado rfkill no código-fonte do blueman, para que, quando o blueman operar o switch Bluetooth, o /sys/class/rfkill/rfkill0/state值不发生变化,
arquivo correspondente seja blueman/blueman/plugins/applet/KillSwitch.py
Shield o seguinte código, localizado na função 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)
O número da versão do blueman no sistema ubuntu20.04: blueman_2.1.2-1ubuntu0.3_arm64.deb
baixar, compilar e instalar o código-fonte blueman
git clone https://github.com/blueman-project/blueman.git
Suas tags contêm várias versões, e as informações de confirmação correspondentes à tag 2.1.2 são f7707ea5ab1ee6bf1f938976d67c83e5384199b5
git reset --hard f7707ea5ab1ee6bf1f938976d67c83e5384199b5
Correspondente ao código-fonte da versão 2.1.2
Ou baixe blueman_2.1.2.orig.tar.xz do código-fonte oficial de http://ports.ubuntu.com/ubuntu-ports/pool/universe/b/blueman/
Instalação do ambiente de compilação
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
Se o código-fonte for baixado do git warehouse, você precisará executar ./autogen.sh
a geraçãoconfigure,然后 make && make install
Se for um pacote fonte baixado de ubuntu.ports, ./configure && make && make install
basta executá-lo diretamente
Nota: Após a conclusão da instalação, o bluetoothmanager padrão não pode ser aberto e uma mensagem de erro é relatada
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'
Solução:
https://github.com/blueman-project/blueman/issues/873
make install
colocar o módulo em/usr/lib/python3/dist-packages,默认安装路径为/usr/lib/python3/site-packages
安装成功后,打开bluetooth manager,中turn off时开关无效 cat /sys/class/rfkill/rfkill0/state值一直为1
O objetivo de excluir o nó /dev/rfkill é manter/sys/class/rfkill/rfkill0/state值一直为1
A diferença e conexão entre bluetooth blueman e gnome-control-centor
Ambos blueman e gnome-control-center bluetooth são ferramentas para gerenciar dispositivos bluetooth, mas eles têm algumas diferenças e conexões.
O blueman é uma ferramenta independente de gerenciamento de Bluetooth, que fornece mais funções e opções, como suporte ao gerenciamento de dispositivos de áudio Bluetooth, transferência de arquivos Bluetooth, conexão de rede Bluetooth, etc. blueman também fornece um ícone na bandeja do sistema para acesso rápido a dispositivos bluetooth.
gnome-control-center bluetooth é uma ferramenta de gerenciamento de Bluetooth que vem com o ambiente de área de trabalho GNOME. Ele fornece funções básicas de gerenciamento de dispositivos Bluetooth, como pesquisa, pareamento, conexão, desconexão, etc. gnome-control-center bluetooth também pode ser encontrado nas configurações do sistema.
A conexão entre blueman e gnome-control-center bluetooth é que ambos são ferramentas para gerenciar dispositivos bluetooth e ambos podem ser usados em sistemas Linux. Mas o blueman oferece mais funções e opções, enquanto o gnome-control-center bluetooth é mais conciso e fácil de usar. Os usuários podem escolher qual ferramenta usar de acordo com suas necessidades.
Mecanismo de trabalho da ferramenta de gerenciamento de Bluetooth
DBus é um mecanismo de comunicação entre processos comumente usado em sistemas Linux, que permite que diferentes processos se comuniquem e interajam.
Tome gnome-control-center como exemplo:
gnome-control-center é o centro de controle do ambiente de área de trabalho GNOME, que contém a função de configurações do Bluetooth. No ambiente de área de trabalho GNOME, a implementação do switch Bluetooth é realizada por meio da pilha de protocolo bluez Bluetooth.
Quando o usuário liga ou desliga o switch Bluetooth no gnome-control-center, o gnome-control-center chama a interface DBus fornecida pelo bluez para controlar o status do switch do dispositivo Bluetooth. Especificamente, o gnome-control-center enviará uma solicitação ao DBus pedindo ao bluez para ligar ou desligar o dispositivo bluetooth. O DBus enviará esta solicitação para o gerenciador Bluetooth do bluez (bluetoothd), e o gerenciador Bluetooth controlará o status da chave do dispositivo Bluetooth de acordo com a solicitação.
Quando o status da chave do dispositivo Bluetooth mudar, o gerenciador Bluetooth (bluetoothd) enviará um sinal ao DBus para informar o gnome-control-center que o status do dispositivo Bluetooth mudou. O gnome-control-center atualizará o status do switch Bluetooth de acordo com este sinal para garantir que a conexão e a comunicação com o dispositivo Bluetooth estejam normais.
O mecanismo de trabalho da ferramenta de gerenciamento bluetooth blueman é o mesmo acima, ele se comunica com o bluetoothd através do Dbus, e o bluetoothd é responsável por controlar o dispositivo bluetooth.