ユーザ用ツール

サイト用ツール


tips:bluetooth_keyboard_のセットアップ

差分

このページの2つのバージョン間の差分を表示します。


tips:bluetooth_keyboard_のセットアップ [2023/04/07 21:30] (現在) – 作成 - 外部編集 127.0.0.1
行 1: 行 1:
 +===== Bluetooth keyboard のセットアップ =====
 +
 +Bluetooth 経由で keyboard を使用する方法についてまとめます。
 +
 +==== loader.conf の設定 ====
 +
 +USB の Bluetooth ドングルを指すと Bluetooth オーディオ向けにアイソクロナス転送 (isochronous transfer) の割り込みが非常にたくさん発生します。''systat -vmstat'' で xhci の割り込みを確認すると毎秒 1000〜2000 の割り込みが発生している様子を観察することができます。ehci の場合は比較的穏やかなので気にならないでしょう。
 +
 +Bluetooth オーディオを使わないのであれば、システムに余計な負荷をかけるだけですので、OFF にすることができます。
 +
 +FreeBSD 13.1 以降であれば、loader.conf に以下の設定を書き、再起動するとアイソクロナス転送を無効にできます。
 +
 +<code>
 +net.bluetooth.usb_isoc_enable=0
 +</code>
 +
 +sysctl でも設定できますが、その場合は sysctl で設定後に Bluetooth ドングルを挿してください。
 +既に挿してある場合には一度抜き差しする必要があります。
 +
 +
 +==== 暗号化の設定 ====
 +
 +デフォルトの設定では Bluetooth の通信は暗号化されていません。うっかり root のパスワードをキーボードから打ち込み、それが盗聴されていた場合、パスワードの流出に繋がります。
 +
 +Bluetooth デバイスのデフォルトの設定は ''/etc/defaults/bluetooth.device.conf'' にあります。これを使用するデバイス毎に設定を上書きすることができます。
 +
 +Bluetooth のドングルが ubt0 として認識されている場合、''/etc/bluetooth/ubt0.conf'' を作成して、以下の設定を書き込みます。
 +
 +<code>
 +authentication_enable="YES"
 +discoverable="NO"
 +encryption_mode="P2P"
 +</code>
 +
 +この例では認証を有効にして、ホストアダプタを検出されないように設定し、データ通信を暗号化します。
 +
 +もし、Bluetoothドングルが複数ある場合にはその分のファイル (ubt1.conf, ubt2.conf, ...) を作成します。
 +
 +==== デーモン起動 ====
 +
 +Bluetooth キーボードを使うために必要なデーモンを起動します。
 +
 +<code>
 +service bthidd enable
 +service bthidd start
 +service hcsecd enable
 +service hcsecd start
 +</code>
 +
 +==== bluetooth-config ====
 +
 +Bluetooth のペアリングを簡単に行うためのスクリプトが FreeBSD 12.1 から用意されています。rootで ''bluetooth-config scan'' を実行すると、ペアリングモードのデバイスを検索し、対話的に必要な設定を行ってくれます。
 +
 +以下に動作例を示します。
 +
 +<code>
 +<予め bluetooth キーボードをペアリングモードにしておく>
 +
 +# bluetooth-config scan
 +Scanning for new Bluetooth devices (Attempt 1 of 5) ... done.
 +Found 2 new bluetooth devices (now scanning for names):
 +[ 1] b8:f6:b1:00:e7:97  "AppleWirelessKeyboard" ()
 +[ 2] 28:c1:3c:6e:ce:2f  "AQUOS-4KTVJ17" ()
 +Select device to pair with [1-2, or 0 to rescan]: <1 を入力>
 +
 +Adding device b8:f6:b1:00:e7:97 to /etc/bluetooth/hosts.
 +Enter friendly name. [AppleWirelessKeyboard]:  <リターンキー入力>
 +Notice: Using sanitized name"AppleWirelessKeyboard" in /etc/bluetooth/hosts.
 +
 +Writing pairing information description block to /etc/bluetooth/hcsecd.conf.
 +(To get PIN, put device in pairing mode first.)
 +Enter PIN [nopin]: <pin 番号入力>
 +Stopping hcsecd.
 +Waiting for PIDS: 3027.
 +Starting hcsecd.
 +
 +<ここで bluetooth キーボードから pin を入力しリターンキーを押す>
 +
 +This device provides human interface device services.
 +Set it up? [yes]: <リターンキー入力>
 +syntax error in line 1
 +Writing HID descriptor block to /etc/bluetooth/bthidd.conf ... success.
 +To re-read its config, bthidd must be restarted.
 +Warning: If a Bluetooth keyboard is being used, the connectionmight be lost.
 +It can be manually restarted later with
 + service bthidd restart
 +Restart bthidd now? [yes]: <リターンキー入力>
 +Stopping bthidd.
 +Waiting for PIDS: 1813.
 +Starting bthidd.
 +</code>
 +
 +もし、エラーが発生した場合は ''bluetooth-config scan'' を再度実行する、もしくは ''bthidd'' や ''hcsecd'' を再起動するなどしてください。機器との相性によってはこれらを複数回行うこともあるかもしれません。
 +
 +
 +==== 接続確認 ====
 +
 +Bluetooth ドングルが ubt0 で認識されている場合、以下のコマンドで接続を確認できます。
 +
 +<code>
 +$ hccontrol -n ubt0hci read_connection_list
 +Remote BD_ADDR    Handle Type Mode Role Encrypt Pending Queue State
 +AppleWireless_        71  ACL    2 MAST     P2P           0 OPEN
 +</code>
 +
 +Encrypt が P2P になっていれば、データ通信が暗号化されています。
  
tips/bluetooth_keyboard_のセットアップ.txt · 最終更新: 2023/04/07 21:30 by 127.0.0.1

特に明示されていない限り、本Wikiの内容は次のライセンスに従います: 2-Clause BSD License
Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki