Bluetooth
この記事では、Bluetooth コントローラーとデバイスの設定・使用について説明します。
前提条件
この記事では、 udev と USB が事前に設定されていることを前提としています。
インストール
カーネル
ほとんどの場合、 RFCOMM ( CONFIG_BT_RFCOMM )、 HIDP ( CONFIG_BT_HIDP )、 HCI USB ( CONFIG_BT_HCIBTUSB ) および/または HCI UART ( CONFIG_BT_HCIUART ) があれば十分です。Bluetooth キーボードやマウスを使うなら、HID 入力デバイス用のユーザースペース I/O ドライバー( CONFIG_UHID )を有効にすべきです。
[*] 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
+mesh
|
Add support for Bluetooth Mesh control application and advertising bearer. |
+obex
|
Enable OBEX transfer support |
+readline
|
Enable support for libreadline, a GNU line-editing library that almost everyone wants |
+udev
|
Enable virtual/udev integration (device discovery, power and storage device support, etc) |
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. |
man
|
Build and install man pages |
midi
|
Enable MIDI support |
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 |
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
バッテリーレポートを有効化する
Bluez には upower にデバイスのバッテリーレベルを報告する機能があります。この機能は現在実験段階にあり、安定化されていません。experimental モードを有効化してください:
/etc/bluetooth/main.conf
[General]
Experimental=true
設定変更を反映させるために bluetooth を再起動してください:
root
#
rc-service bluetooth restart
これで、自身のバッテリーレベルの送信に対応する各デバイスのバッテリーレベルが、upower によって認識されるはずです。
使い方
コントローラーのセットアップ
コントローラー情報の表示:
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.conf
で
AutoEnable=true
と設定することで自動的に有効化することができます:
/etc/bluetooth/main.conf
[Policy]
AutoEnable=true
場合によっては、Bluetooth コントローラーが udev の電源管理ツールによってソフトブロックされているかもしれません。対応するルールファイルで
state
が
1
に設定されていることを確認するか、または以下の行全体を削除してください:
/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 を使用してください。
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
-
HCI デバイスを開いて初期化する:
root #hciconfig -a <hci0> up -
HCI デバイスを閉じる:
root #hciconfig -a <hci0> down -
HCI デバイスをリセットする:
root #hciconfig -a <hci0> reset -
統計カウンターをリセットする:
root #hciconfig -a <hci0> rstat -
認証を有功にする:
root #hciconfig -a <hci0> auth -
認証を無効にする:
root #hciconfig -a <hci0> noauth -
暗号化を有功にする:
root #hciconfig -a <hci0> encrypt -
暗号化を無効にする:
root #hciconfig -a <hci0> noencrypt -
ページ・呼び出し・問い合わせスキャンを有功にする:
root #hciconfig -a <hci0> piscan -
スキャンを無効にする:
root #hciconfig -a <hci0> noscan -
問い合わせスキャンを有功にする:
root #hciconfig -a <hci0> iscan -
呼び出しスキャンを有功にする:
root #hciconfig -a <hci0> pscan -
デフォルトのパケットタイプを取得/設定する:
root #hciconfig -a <hci0> ptype [type] -
デフォルトの接続モードを取得/設定する:
root #hciconfig -a <hci0> lm [mode] -
デフォルトの接続ポリシーを取得/設定する:
root #hciconfig -a <hci0> lp [policy] -
ローカル名を取得/設定する:
root #hciconfig -a <hci0> name [name] -
デバイスクラスを取得/設定する:
root #hciconfig -a <hci0> class [class] -
音声設定を取得/設定する:
root #hciconfig -a <hci0> voice [voice] -
問い合わせアクセスコードを取得/設定する:
root #hciconfig -a <hci0> iac [iac] -
問い合わせ送信出力レベルを取得/設定する:
root #hciconfig -a <hci0> nqtpl [level] -
問い合わせモードを取得/設定する:
root #hciconfig -a <hci0> inqmode [mode] -
問い合わせデータを取得/設定する:
root #hciconfig -a <hci0> inqdata [data] -
問い合わせスキャンタイプを取得/設定する:
root #hciconfig -a <hci0> inqtype [type] -
問い合わせスキャンの期間・間隔を取得/設定する:
root #hciconfig -a <hci0> inqparms [win:int] -
呼び出しスキャンの期間・間隔を取得/設定する:
root #hciconfig -a <hci0> pageparms [win:int] -
呼び出しのタイムアウトを取得/設定する:
root #hciconfig -a <hci0> ageto [to] -
AFH モードを取得/設定する:
root #hciconfig -a <hci0> afhmode [mode] -
シンプルペアリングモードを取得/設定する:
root #hciconfig -a <hci0> sspmode [mode] -
ACL MTU とパケット数を設定する:
root #hciconfig -a <hci0> clmtu <mtu:pkt> -
SCO MTU とパケット数を設定する:
root #hciconfig -a <hci0> scomtu <mtu:pkt> -
デバイスからリンクキーを削除する:
root #hciconfig -a <hci0> delkey <bdaddr> -
ローカル OOB データを取得する:
root #hciconfig -a <hci0> oobdata -
サポートされているコマンドを表示する:
root #hciconfig -a <hci0> commands -
デバイスの機能を表示する:
root #hciconfig -a <hci0> features -
バージョン情報を表示する:
root #hciconfig -a <hci0> version -
リビジョン情報を表示する:
root #hciconfig -a <hci0> revision -
デバイスをブラックリストに追加する:
root #hciconfig -a <hci0> block <bdaddr> -
デバイスをブラックリストから削除する:
root #hciconfig -a <hci0> unblock <bdaddr> -
LE ランダムアドレスを設定する:
root #hciconfig -a <hci0> lerandaddr <bdaddr> -
LE アドバタイズを有功にする:
root #hciconfig -a <hci0> leadv [type] -
デバイスでサポートされているコマンドを表示する:
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 devices — Bluetooth 入力デバイス、例えば bluetooth マウス等の、Linux システム上でのセットアップについて記述します。
- Bluetooth Network Aggregation Point — Gentoo Linux 上での Bluetooth ネットワークアグリゲーションポイント (NAP) の構築について扱います。
- Broadcom Bluetooth — 主に BCM20702、BCM4354、および BCM4356 チップセットベースの Broadcom Bluetooth 4.x デバイスの詳細なセットアップについて解説します。