Bluetooth

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Bluetooth and the translation is 60% complete.
Outdated translations are marked like this.
Resources

Cet article décrit la configuration et l'usage des contrôleurs Bluetooth et des appareils Bluetooth.

Pour suivre cet article, l'utilisateur doit avoir préalablement configuré udev et USB.

Installation

Noyau

Le plus souvent, il suffira d'activer les protocoles RFCOMM (CONFIG_RFCOMM), HIDP (CONFIG_BT_HIDP), HCI USB (CONFIG_BT_HCIBTUSB) et/ou HCI UART (CONFIG_BT_HCIUART). Le pilote d'entrée-sortie utilisateur pour les équipements récepteurs HID (CONFIG_UHID) doit être activé dans le cas des claviers et souris Bluetooth.

KERNEL Enabling Bluetooth support
[*] Networking support --->
      <M>   Bluetooth subsystem support --->
              [*]   Bluetooth Classic (BR/EDR) features
              <*>     RFCOMM protocol support
              [ ]       RFCOMM TTY support
              < >     BNEP protocol support
              [ ]       Multicast filter support
              [ ]       Protocol filter support
              <*>     HIDP protocol support
              [*]     Bluetooth High Speed (HS) features
              [*]   Bluetooth Low Energy (LE) features
                    Bluetooth device drivers --->
                      <M> HCI USB driver
                      <M> HCI UART driver
      <*>   RF switch subsystem support --->
    Device Drivers --->
          HID support --->
            <*>   User-space I/O driver support for HID subsystem
Important
Kernel may fail to initialize RFCOMM/BNEP being compiled as built-in. System log for bluetooth service in this case will mention the lack of RFCOMM/BNEP support. And this in turn for example may break HSP/HFP headset profile initialization. So if dmesg says nothing about RFCOMM, better recompile as a module.

Les micrologiciels

La plupart des contrôleurs Bluetooth ont besoin de micrologiciel (firmware) pour pouvoir fonctionner. Si le contrôleur est compatible avec Linux, dmesg indiquera la plupart du temps si un micrologiciel est nécessaire. Le paquet sys-kernel/linux-firmware doit, en règle générale, proposer un micrologiciel mais parfois certains équipements ne pourront fonctionner qu'avec un micrologiciel propriétaire.

root #emerge --ask --noreplace sys-kernel/linux-firmware

Options de la variable USE

BlueZ est une implémentation du protocole Bluetooth pour Linux disponible en installant le paquet net-wireless/bluez.

USE flags for net-wireless/bluez Bluetooth Tools and System Daemons for Linux

btpclient Enable BTP client
cups Add support for CUPS (Common Unix Printing System)
debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
deprecated Build deprecated plugins
doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
experimental Build experimental plugins
extra-tools Install tools that upstream doesn't install on purpose by default. All this tools shouldn't be used. Then, please notify upstream about you still need them to let them know the situation.
mesh Add support for Bluetooth Mesh control application and advertising bearer.
midi Enable MIDI support
obex Enable OBEX transfer support
readline Enable support for libreadline, a GNU line-editing library that almost everyone wants
selinux !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
systemd Enable use of systemd-specific libraries and features like socket activation or session tracking
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)
test-programs Install tools for testing of various Bluetooth functions
udev Enable virtual/udev integration (device discovery, power and storage device support, etc)

Bluetooth peut être globalement activé en donnant la valeur bluetooth à la variable USE :

FILE /etc/portage/make.conf
USE="bluetooth"

Installation

Le système doit être mis à jour si la variable USE a été modifiée pour prendre la valeur bluetooth:

root #emerge --ask --changed-use --deep @world

Installer BlueZ:

root #emerge --ask --noreplace net-wireless/bluez

Configuration

Droits d'accès

Les droits d'accès pour les équipements Bluetooth sont automatiquement gérés par D-Bus, et l'accès est automatiquement accordé à tous les utilisateurs par défaut.

Services

OpenRC

Démarrer Bluetooth :

root #rc-service bluetooth start

Lancer Bluetooth au démarrage :

root #rc-update add bluetooth default

systemd

Démarrer Bluetooth :

root #systemctl start bluetooth

Lancer Bluetooth au démarrage :

root #systemctl enable bluetooth

Enabling battery reporting

Remarque
The experimental USE flag needs to be enabled in net-wireless/bluez.
Attention !
Using bluezs experimental mode may prevent some bluetooth microphones from connecting automatically.[1]

Bluez has a feature to report a devices battery level to upower. This feature is currently experimental and not stable. Enable experimental mode:

FILE /etc/bluetooth/main.conf
[General]
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Experimental=true

Restart bluetooth to apply the configuration changes:

root #rc-service bluetooth restart

Now upower should know the battery level of every device which supports sending its own battery level.

Utilisation

Configuration du contrôleur

Afficher l'information sur le contrôleur :

Remarque
hciconfig et d'autres fonctionnalités peuvent être utilisées à la condition que le paquet net-wireless/bluez soit installé avec la valeur de la variable USE deprecated.
root #hciconfig -a
hci0:   Type: BR/EDR  Bus: USB
        BD Address: 00:02:72:2F:A9:33  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING PSCAN 
        RX bytes:1166 acl:0 sco:0 events:43 errors:0
        TX bytes:960 acl:0 sco:0 commands:43 errors:0
        Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
        Link policy: RSWITCH SNIFF 
        Link mode: SLAVE ACCEPT 
        Name: 'BlueZ 5.21'
        Class: 0x000104
        Service Classes: Unspecified
        Device Class: Computer, Desktop workstation
        HCI Version: 4.0 (0x6)  Revision: 0x1000
        LMP Version: 4.0 (0x6)  Subversion: 0x220e
        Manufacturer: Broadcom Corporation (15)

hci0 est le nom du contrôleur et UP (3ème ligne) indique que le contrôleur est activé.

Activer le contrôleur si hciconfig indique (avec DOWN) (3ème ligne) que le contrôleur est désactivé:

root #hciconfig hci0 up
Important
Au moment de l'essai d'activation du contrôleur, peut s'afficher le message suivant: Can't init device hci0: Operation not possible due to RF-kill

Dans ce cas, requêter l'état de l'émetteur radio Bluetooth à l'aide de rfkill :

root #rfkill list bluetooth
0: hci0: Bluetooth
        Soft blocked: no
        Hard blocked: no

rfkill est fourni par >=sys-apps/util-linux-2.31. Il peut aussi être installé par le paquet net-wireless/rfkill (non maintenu).

Remarque
Si Bluetooth est bloqué ou désactivé dans le BIOS/UEFI, rfkill peut incorrectement indiquer que le contrôleur est dans l'état Hard blocked: no.

Débloquer le contrôler si rfkill indique (par le message Soft blocked: yes) que le contrôleur est bloqué :

root #rfkill unblock bluetooth

Si rfkill indique (par le message Hard blocked: yes) que le contrôleur est bloqué, débloquer le contrôleur en changeant la position d'un interrupteur physique ou en appuyant sur une touche de fonction du clavier.

Les contrôleurs Blutooth peuvent être automatiquement activés en spécifiant AutoEnable=true dans le fichier /etc/bluetooth/main.conf:

FILE /etc/bluetooth/main.conf
[Policy]
AutoEnable=true

Il peut arriver que les contrôleurs Bluetooth aient été bloqués par l'action d'un des outils logiciels de gestion de l'énergie (udev). S'assurer dans ce cas que la valeur de state est fixée à 1 dans le fichier de règles correspondant ou sinon effacer complètement la ligne suivante :

FILE /etc/udev/rules.d/10-local-powersave.rules
SUBSYSTEM=="rfkill", ATTR{type}=="bluetooth", ATTR{state}="1"

Appairage

Les appareils Bluetooth doivent être appairés avec un contrôleur Bluetooth avant toute utilisation. Pour cela, il faut entrer un code PIN (ou tout autre type de code) dans les deux équipements par le biais d'un agent interactif. Certains appareils, comme les casques audio, ne permettent pas d'entrer un code PIN arbitraire. Ces appareils utilisent un code PIN statique, qui est d'habitude 0000, 1111, 1234 or 9999. D'autres appareils (par exemple La télécommande BD de Sony) ne demandent pas d'entrer un code PIN et, dans ce cas, essayer de rentrer un code PIN à l'invite fera échouer l'appairage. Avec ce type d'appareil, l'étape de l'appairage peut être sautée.

Cet article ne porte que sur l'appairage des appareils avec bluetoothctl, qui est un agent interactif en ligne de commande fourni avec le paquet net-wireless/bluez. Si un environnement de bureau graphique est utilisé, l'appairage peut être mené à bien à l'aide d'un agent interactif doté d'une interface graphique. Pour KDE, utiliser kde-plasma/bluedevil, pour GNOME, net-wireless/gnome-bluetooth, et pour GTK choisir entre net-wireless/blueman ou net-wireless/blueberry.

Remarque
Les appareils antérieurement appairés devront l'être à nouveau après une mise à jour logicielle vers BlueZ 4.

Démarrer bluetoothctl :

user $bluetoothctl

Lister les contrôleurs disponibles :

[bluetooth]#list

Afficher l'information sur un contrôleur :

[bluetooth]#show controller_mac_address

Etablir le contrôleur par défaut :

[bluetooth]#select controller_mac_address

Mettre en route le contrôleur :

[bluetooth]#power on

Activer l'agent et en faire l'agent par défaut :

[bluetooth]#agent on
[bluetooth]#default-agent

Rendre le contrôleur visible (pour une durée temporaire de 3 minutes) et appairable :

[bluetooth]#discoverable on
[bluetooth]#pairable on

Analyser l'environnement pour trouver des appareils appairables :

[bluetooth]#scan on

Mettre l'appareil en mode d'appairage, ce qui en général nécessite d'appuyer sur un bouton ou une combinaison de boutons, d'habitude pour plusieurs secondes.

Découvrir l'adresse MAC de l'appareil :

[bluetooth]#devices

Appairer avec l'appareil :

[bluetooth]#pair mac_address_de_appareil

Entrer le PIN s'il est demandé :

[agent]PIN code: ####

In case the pin is not prompted but needed, this command may need to be added before pairing with the device (see this post):

[bluetooth]#agent NoInputNoOutput

Autoriser le service si cela est demandé :

[agent]Authorize service uuid_du_service (yes/no): yes

Considérer l'appareil comme un appareil de confiance :

[bluetooth]#trust address_mac_de_appareil

Connecter l'appareil :

[bluetooth]#connect device_mac_address

Afficher l'information sur l'appareil :

[bluetooth]#info adresse_mac_de_appareil

L'appareil est désormais appairé :

[bluetooth]#quit

hciconfig

Open and initialize HCI device:
root #hciconfig -a <hci0> up
Close HCI device:
root #hciconfig -a <hci0> down
Reset HCI device:
root #hciconfig -a <hci0> reset
Reset statistic counters:
root #hciconfig -a <hci0> rstat
Enable Authentication:
root #hciconfig -a <hci0> auth
Disable Authentication:
root #hciconfig -a <hci0> noauth
Enable Encryption:
root #hciconfig -a <hci0> encrypt
Disable Encryption:
root #hciconfig -a <hci0> noencrypt
Enable Page and Inquiry scan:
root #hciconfig -a <hci0> piscan
Disable scan:
root #hciconfig -a <hci0> noscan
Enable Inquiry scan:
root #hciconfig -a <hci0> iscan
Enable Page scan:
root #hciconfig -a <hci0> pscan
Get/Set default packet type:
root #hciconfig -a <hci0> ptype [type]
Get/Set default link mode:
root #hciconfig -a <hci0> lm [mode]
Get/Set default link policy:
root #hciconfig -a <hci0> lp [policy]
Get/Set local name:
root #hciconfig -a <hci0> name [name]
Get/Set class of device:
root #hciconfig -a <hci0> class [class]
Get/Set voice setting:
root #hciconfig -a <hci0> voice [voice]
Get/Set inquiry access code:
root #hciconfig -a <hci0> iac [iac]
Get/Set inquiry transmit power level:
root #hciconfig -a <hci0> nqtpl [level]
Get/Set inquiry mode:
root #hciconfig -a <hci0> inqmode [mode]
Get/Set inquiry data:
root #hciconfig -a <hci0> inqdata [data]
Get/Set inquiry scan type:
root #hciconfig -a <hci0> inqtype [type]
Get/Set inquiry scan window and interval:
root #hciconfig -a <hci0> inqparms [win:int]
Get/Set page scan window and interval:
root #hciconfig -a <hci0> pageparms [win:int]
Get/Set page timeout:
root #hciconfig -a <hci0> ageto [to]
Get/Set AFH mode:
root #hciconfig -a <hci0> afhmode [mode]
Get/Set Simple Pairing Mode:
root #hciconfig -a <hci0> sspmode [mode]
Set ACL MTU and number of packets:
root #hciconfig -a <hci0> clmtu <mtu:pkt>
Set SCO MTU and number of packets:
root #hciconfig -a <hci0> scomtu <mtu:pkt>
Delete link key from the device:
root #hciconfig -a <hci0> delkey <bdaddr>
Get local OOB data:
root #hciconfig -a <hci0> oobdata
Display supported commands:
root #hciconfig -a <hci0> commands
Display device features:
root #hciconfig -a <hci0> features
Display version information:
root #hciconfig -a <hci0> version
Display revision information:
root #hciconfig -a <hci0> revision
Add a device to the blacklist:
root #hciconfig -a <hci0> block <bdaddr>
Remove a device from the blacklist:
root #hciconfig -a <hci0> unblock <bdaddr>
Set LE Random Address:
root #hciconfig -a <hci0> lerandaddr <bdaddr>
Enable LE advertising:
root #hciconfig -a <hci0> leadv [type]
Show all commands device has support for:
root #hciconfig get commands

Désactiver le Bluetooth

Pour désactiver Bluetooth pendant qu'il s'exécute, exécuter la commande suivante:

root #rfkill block bluetooth

Pour désactiver Bluetooth automatiquement à chaque démarrage, choisir entre les possibilités suivantes :

Utiliser udev pour déactiver Bluetooth

En cas d'utilisation de UDEV, il suffit d'installer la règle suivante, ce qui va désactiver Bluetooth :

FILE /etc/udev/rules.d/80-disable-bluetooth.rules
SUBSYSTEM=="rfkill", ATTR{type}=="bluetooth", ATTR{state}="0"

Utiliser OpenRc pour déactiver Bluetooth

En cas d'utilisation de sys-apps/openrc, il faut installer le script suivant pour les services locaux ; ne pas oublier de le rendre exécutable :

FILE /etc/local.d/disable-bluetooth.start
#!/bin/sh
rfkill block bluetooth
root #chmod o+x /etc/local.d/disable-bluetooth.start

Désactiver Bluetooth au niveau du noyau

Quand le noyau intègre Bluetooth comme fonctionnalité modulaire, il faut désactiver le chargement des modules Bluetooth :

FILE /etc/modprobe.d/blacklist-bluetooth.conf
blacklist bnep
blacklist bluetooth
blacklist btusb

En cas de problème

TLP et laptop_mode

TLP and laptop_mode

Si laptop-mode-tools est installé ou TLP, s'assurer qu'ils ne désactivent pas Bluetooth pour économiser de l'énergie.

XBOX ONE controller pairing

It's a known issue that XBOX ONE wireless controllers will refuse to pair out of the box on most linux systems. To solve this issue ERTM needs to be disabled.

To disable it manually:

root #echo 'Y' > /sys/module/bluetooth/parameters/disable_ertm

This will disable ERTM only until the system is rebooted. To disable it permanently, install the xpadneo kernel module.

root #emerge --ask games-util/xpadneo

In most cases, this will automatically solve the issue. If it doesn't, add this line into xpadneo config manually:

FILE /etc/modprobe.d/xpadneo.conf
options bluetooth disable\_ertm=Y

Notebook has a Synopsys DesignWare Controller

Bluetooth support for this controller needs also these options in kernel config[2]:

KERNEL
Device Drivers  --->
    Character devices  --->
        Serial drivers  --->
            [*] 8250/16550 and compatible serial support
            [*] Support for Synopsys DesignWare 8250 quirks

Resolving firmware problems

It happens that the firmware of bluetooth adapters enters a state where it is unable to pair with a certain (or all) bluetooth devices. Resetting the adapter might solve such problems.

In the case of a laptop with a built-in bluetooth adapter this might be achieved by:

  • Enter the laptop's firmware settings (BIOS) and disable the built-in adapter
  • Save settings and restart the laptop
  • Enter the firmware settings a second time and enable the bluetooth adapter again
  • Save and restart
  • Now try to pair the device again

Voir aussi

References