Bluetooth

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Bluetooth and the translation is 99% complete.
Resources

この記事では、Bluetooth コントローラーとデバイスの設定・使用について説明します。

前提条件

この記事では、udevUSB が事前に設定されていることを前提としています。

インストール

カーネル

ほとんどの場合、RFCOMM (CONFIG_BT_RFCOMM)、HIDP (CONFIG_BT_HIDP)、HCI USB (CONFIG_BT_HCIBTUSB) および/または HCI UART (CONFIG_BT_HCIUART) があれば十分です。Bluetooth キーボードやマウスを使うなら、HID 入力デバイス用のユーザースペース I/O ドライバー(CONFIG_UHID)を有効にすべきです。

カーネル Bluetooth サポートを有効化する
[*] 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 bus support --->
            <*>   User-space I/O driver support for HID subsystem
重要
RFCOMM/BNEP がビルトインでコンパイルされていると、カーネルはRFCOMM/BNEP の初期化に失敗するかもしれません。この場合、bluetooth サービスに関するシステムログで RFCOMM/BNEP サポートの欠如について言及されているでしょう。これがさらに、例えば HSP/HFP ヘッドセットプロファイルの初期化の失敗を引き起こすかもしれません。なので、dmesg で RFCOMM について何も言及が無ければ、モジュールとして再コンパイルしたほうがよいでしょう。

ファームウェア

多くの Bluetooth コントローラーは、動作するためにファームウェアが必要です。コントローラーが Linux でサポートされていれば、たいていは dmesg がファームウェアが必要であると表示します。多くの場合、必要なファームウェアは sys-kernel/linux-firmware パッケージで提供されているはずですが、他のパッケージから入手可能だったり、製造元からしか提供されていないファームウェアを必要とするものもあります。

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

USE フラグ

BlueZ は、Bluetooth プロトコルスタックのLinux 向け実装の1つであり、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)

USE 変数を bluetooth にセットすることで、Bluetooth サポートをシステム全体で有効にすることができます:

ファイル /etc/portage/make.conf
USE="bluetooth"

Emerge

USE 変数を bluetooth にセットした場合、システムをアップデートする必要があります:

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

BlueZ をインストールします:

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

設定

パーミッション

Bluetooth デバイスのパーミッションは D-Bus によって自動的に処理され、デフォルトではすべてのユーザにアクセスが許可されます。

サービス

OpenRC

Bluetoothを起動します。

root #rc-service bluetooth start

起動時にBluetoothを起動します。

root #rc-update add bluetooth default

systemd

Bluetoothを起動します:

root #systemctl start bluetooth

ブート時に bluetooth を起動します:

root #systemctl enable bluetooth

バッテリーレポートを有効化する

メモ
net-wireless/bluezexperimental USE フラグが有効化されている必要があります。
警告
bluez の experimental モードを使用していると、一部の bluetooth マイクの自動接続が動作しなくなることがあります。[1]

Bluez には upower にデバイスのバッテリーレベルを報告する機能があります。この機能は現在実験段階にあり、安定化されていません。experimental モードを有効化してください:

ファイル /etc/bluetooth/main.conf
[General]

Experimental=true

設定変更を反映させるために bluetooth を再起動してください:

root #rc-service bluetooth restart

これで、自身のバッテリーレベルの送信に対応する各デバイスのバッテリーレベルが、upower によって認識されるはずです。

使い方

コントローラーのセットアップ

コントローラー情報の表示:

メモ
hciconfig やその他のユーティリティーは、net-wireless/bluezdeprecated USE フラグを有効にしてインストールされている場合のみ使用可能です。
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 はコントローラーの名前であり、UP (3行目)はそのコントローラーが有効であることを表しています。

hciconfig でコントローラーが (DOWN となっており) (3行目) 無効であると表示されている場合は、コントローラーを有効にします:

root #hciconfig hci0 up
重要
コントローラーを有効にしようとした際に、以下のようなメッセージが表示される場合があります: Can't init device hci0: Operation not possible due to RF-kill

この場合、rfkill を使って Bluetooth の無線送信器の状態を確認します:

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

rfkill は >=sys-apps/util-linux-2.31 パッケージでインストールできます。保守されていない net-wireless/rfkill パッケージからインストールすることもできます。

メモ
Bluetooth が BIOS/UEFI でブロックまたは無効化されている場合、rfkill はコントローラーを Hard blocked: no と誤って表示する可能性があります。

rfkill が (Soft blocked: yes となっており)コントローラーがブロックされていると表示している場合は、コントローラーのブロックを解除します:

root #rfkill unblock bluetooth

rfkill が (Hard blocked: yes となっており)コントローラーがブロックされていると表示している場合は、物理スイッチやキーボードのファンクションキーを使ってコントローラーのブロックを解除します。

Bluetooth コントローラーは、/etc/bluetooth/main.confAutoEnable=true と設定することで自動的に有効化することができます:

ファイル /etc/bluetooth/main.conf
[Policy]
AutoEnable=true

場合によっては、Bluetooth コントローラーが udev の電源管理ツールによってソフトブロックされているかもしれません。対応するルールファイルで state1 に設定されていることを確認するか、または以下の行全体を削除してください:

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

デバイスのペアリング

Bluetoothデバイスは、使用する前にBluetoothコントローラーとペアリングする必要があります。これは、相互作用エージェントを介して両方のデバイスにPIN(または他のコード)を入力することにより行われます。ヘッドセットなどの特定のデバイスでは、任意のPINを入力できません。これらのデバイスは、通常0000、1111、1234、または9999の静的PINを使用します。PIN入力を必要としないデバイス(Sony BD Remote Controlなど)もあり、プロンプトが表示されたときにPINを入力しようとすると失敗します。このようなデバイスでは、ペアリングをスキップできます。

この記事では、net-wireless/bluez パッケージで提供されているコマンドライン対話エージェントである bluetoothctl を使用したデバイスのペアリングのみを扱います。グラフィカルデスクトップ環境を使用している場合は、デバイスのペアリングをグラフィカルな対話エージェントを使って行うことができます。KDE なら kde-plasma/bluedevil を、GNOME なら net-wireless/gnome-bluetoothを、GTK なら net-wireless/blueman または net-wireless/blueberry を使用してください。

メモ
BlueZ 4 からアップグレードした場合、以前ペアリングしたデバイスを再度ペアリングする必要があります。

bluetoothctl を起動します:

user $bluetoothctl

使用可能なコントローラーを表示します:

[bluetooth]#list

コントローラーに関する情報を表示します:

[bluetooth]#show controller_mac_address

デフォルトのコントローラーを設定します:

[bluetooth]#select controller_mac_address

コントローラーの電源を入れます:

[bluetooth]#power on

エージェントを有効にし、それをデフォルトに設定します:

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

コントローラーを(3分間一時的に)探索可能にし、またペアリング可能にします:

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

デバイスをスキャンします:

[bluetooth]#scan on

デバイスをペアリングモードにします。一般的には、これは、ボタンまたはいくつかのボタンの組み合わせを、通常は数秒間押すことによって行います。

デバイスの MAC アドレスを探索します:

[bluetooth]#devices

デバイスをペアリングします:

[bluetooth]#pair device_mac_address

尋ねられた場合、PINを入力します:

[agent]PIN code: ####

pin が尋ねられないが必要である場合、デバイスとペアリングする前にこのコマンドを追加する必要があるかもしれません (この投稿を参照してください):

[bluetooth]#agent NoInputNoOutput

求められた場合、サービスを許可します:

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

デバイスを信頼します:

[bluetooth]#trust device_mac_address

デバイスに接続します:

[bluetooth]#connect device_mac_address

デバイスに関する情報を表示します:

[bluetooth]#info device_mac_address

これで、デバイスがペアリングされました:

[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

Bluetooth を無効化する

実行中の Bluetooth を無効化するには、次のコマンドを実行してください:

root #rfkill block bluetooth

Bluetooth が起動時に自動的に開始するのを無効化するには、以下の選択肢からひとつを選んでください:

udev を使用して Bluetooth を無効化する

UDEV を使う場合は、Bluetooth を無効化する次のルールをインストールしてください:

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

OpenRC を使用して Bluetooth を無効化する

sys-apps/openrc を使用する場合は、次のスクリプトを local サービスに追加して、実行可能にしてください:

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

カーネルレベルで Bluetooth を無効化する

カーネルが Bluetooth サポートをモジュールとして持っている場合は、Bluetooth モジュールの読み込みを無効化してください:

ファイル /etc/modprobe.d/blacklist-bluetooth.conf
blacklist bnep
blacklist bluetooth
blacklist btusb

トラブルシューティング

TLP と laptop_mode

laptop-mode-tools または TLP がインストールされている場合は、それらが節電のために Bluetooth を無効化していないか確認してください。

XBOX ONE コントローラのペアリング

ほとんどの linux システム上のデフォルトだと、XBOX ONE 無線コントローラはペアリングを拒否する問題が知られています。この問題を解決するには、ERTM を無効化する必要があります。

手動で無効化するには:

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

これは、システムが再起動されるまでの間のみ、ERTM を無効化するでしょう。恒久的に無効化するには、xpadneo カーネルモジュールをインストールしてください。

root #emerge --ask games-util/xpadneo

ほとんどの場合はこれで自動的に問題が解消されるでしょう。そうでない場合は、手動で xpadneo の設定にこの行を追加してください:

ファイル /etc/modprobe.d/xpadneo.conf
options bluetooth disable\_ertm=Y

ノート PC が Synopsys DesignWare Controller を備えている場合

このコントローラの Bluetooth サポートには、カーネルコンフィグで以下のオプションも必要です[2]:

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

ファームウェアの問題を解決する

bluetooth アダプタのファームウェアが、特定の (またはすべての) bluetooth デバイスとペアリングできない状態になることがあります。アダプタをリセットすることで、そのような問題を解決することができるかもしれません。

内蔵 bluetooth アダプタを持つノート PC の場合、これは次のようにして達成できるかもしれません:

  • ノート PC のファームウェア設定 (BIOS) 画面に入り、内蔵アダプタを無効化する
  • 設定を保存してノート PC を再起動する
  • 再度ファームウェア設定画面に入り、再度 bluetooth アダプタを有効化する
  • 保存して再起動する
  • デバイスを再度ペアリングしてみる

関連項目

  • Bluetooth headset — Gentoo Linux 内での Bluetooth ヘッドセットの構成について記載しています。
  • Bluetooth input devicesBluetooth 入力デバイス、例えば bluetooth マウス等の、Linux システム上でのセットアップについて記述します。
  • Bluetooth Network Aggregation Point — covers the setup of a Bluetooth Network Aggregation Point (NAP) on Gentoo Linux.
  • Broadcom Bluetooth — 主に BCM20702、BCM4354、および BCM4356 チップセットベースの Broadcom Bluetooth 4.x デバイスの詳細なセットアップについて解説します。

参照