Bluetooth
この記事では、Bluetooth コントローラーとデバイスの設定・使用について説明します。
前提条件
この記事では、udevとUSBが事前に設定されていることを前提としています。
インストール
カーネル
ほとんどの場合、RFCOMM (CONFIG_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 support ---> <*> User-space I/O driver support for HID subsystem
ファームウェア
多くの 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
使い方
コントローラーのセットアップ
コントローラー情報の表示:
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 または 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: ####
求められた場合、サービスを許可します:
[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
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 を無効化していないか確認してください。
関連項目
- Bluetooth headset — Gentoo Linux 内での Bluetooth ヘッドセットの構成について記載しています。
- Bluetooth input devices — Bluetooth 入力デバイス、例えば 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 デバイスの詳細なセットアップについて解説します。