Skip to content

Instantly share code, notes, and snippets.

@mamemomonga
Last active June 1, 2020 03:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamemomonga/b63d8dedf36604218aa823999bb42506 to your computer and use it in GitHub Desktop.
Save mamemomonga/b63d8dedf36604218aa823999bb42506 to your computer and use it in GitHub Desktop.
HHKB-BTをHIDとして認識させる(失敗)

HHKB-BTをHIDとして認識させる(失敗)

HID化はうまくいかなかったけど、bluetoothctl で普通のHCIデバイスとしての設定メモとして残しておく。

参考資料: BIOS 画面でもBluetooth LE な無線キーボードを使いたい

使用デバイス

Raspberry Pi 3

  • Bluetoothを内蔵しているが、もちろんそれは使わない
  • 以下の例では 内蔵BluetoothデバイスのBDアドレスを 00:00:00:00:00:01 とする

Raspbian

  • 2018/03/07に最新版にアップデートしたもの

サンワサプライ MM-BTUD43

  • CSR8510 A10 使用のUSBドングル これをHIDドングルとして使用する
  • 以下の例では BDアドレスを 00:00:00:00:00:02 とする

PFU Happy Hacking Keyboard BT(HHKB-BT)

  • Bluetooth キーボード
  • 以下の例では BDアドレスを 00:00:00:00:00:03 とする

HHKB-BTの認識・ペアリング・削除

まずはHCIモード(通常のBTキーボード)で認識させる

$ sudo bluetoothctl

help でヘルプを表示でき、tab補完も使える

[bluetooth]# list
Controller 00:00:00:00:00:02 raspi3 #1 [default]
Controller 00:00:00:00:00:01 raspi3

MM-BTUD43 がデフォルトになっているようだ

[bluetooth]# agent KeyboardDisplay
Agent registered

[bluetooth]# default-agent
Default agent request successful

HHKB-BTの電源を入れて、Fn+Q でペアリングモードに入り、検索を開始する

[bluetooth]# scan on
Discovery started
[CHG] Controller 00:00:00:00:00:02 Discovering: yes
...
[NEW] Device 00:00:00:00:00:03 HHKB-BT

[bluetooth]# scan off
Discovery stopped

[bluetooth]# devices
Device 00:00:00:00:00:03 HHKB-BT

HHKB-BTがみつかったので、ペアリング

[bluetooth]# pair 00:00:00:00:00:03
Attempting to pair with 00:00:00:00:00:03
[CHG] Device 00:00:00:00:00:03 Connected: yes
[agent] PIN code: 123456

PINコードがでるのでHHKB-BTから入力してEnter

[CHG] Device 00:00:00:00:00:03 Modalias: usb:...
[CHG] Device 00:00:00:00:00:03 UUIDs:
...
[CHG] Device 00:00:00:00:00:03 Paired: yes
Pairing successful

接続

[bluetooth]# connect 00:00:00:00:00:03
Attempting to connect to 00:00:00:00:00:03
Connection successful

bluetoothctl から出る

[bluetooth]# exit
Agent unregistered
[DEL] Controller 00:00:00:00:00:02 raspi3 #1 [default]
[DEL] Controller 00:00:00:00:00:01 raspi3

これでHHKB-BTがRaspberry Pi3でBluetooth HCIキーボードとして使えるようになった。

MM-BTUD43 のHID Proxyデバイスとして使う

hid2hci のビルド

HIDからHCIに戻すためにはhid2hciを使うらしいが、 --method=csr2を使うためには新しいバージョンがいるらしいのでビルドする。

$ sudo apt install libglib2.0-dev \
  libdbus-1-dev libudev-dev libical-dev \
  libreadline-dev libbluetooth-dev

$ wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.48.tar.xz
$ tar Jxf bluez-5.48.tar.xz
$ cd bluez-5.48
$ ./configure
$ make tools/hid2hci

MM-BTUD43 のVID,PIDを確認する

$ lsusb
...
Bus 001 Device 005: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)

Cambridge Silicon Radio, Ltd のチップなのでこれですね。

VID:0a12 / PID:0001 らしい

tools/hid2hci を実行してみる

$ sudo tools/hid2hci --method=csr2 \
  --devpath=$( udevadm trigger --verbose --subsystem-match=usb \
  --attr-match=idVendor=0a12 --attr-match=idProduct=0001 \
  | cut -d '/' -f 3- )

HCIモードからHCIモードに切り替えただけなので何も起こらない。 エラーがでなかったので動いたようだ。

実行後はドングルの抜き差しがいる様子。

HIDモードに切り替えてみる

現在のBOOTMODEを確認する

$ sudo bccmd -d 00:00:00:00:00:02 psget bootmode
Initial device bootmode: 0x0000 (0)

現在は0x0000、これがHCIモードらしい

$ sudo bccmd -d 00:00:00:00:00:02 psread -s 0 | grep 'INITIAL_BOOTMODE' -A 1
// PSKEY_INITIAL_BOOTMODE
&03cd = 0000

BOOTMODE設定アドレスは 03cd らしい

切り替えを実行、0x0002 がHID Proxyモードらしい

$ sudo bccmd -d 00:00:00:00:00:02 psset -s 0 0x03cd 0x0002

確認

$ sudo bccmd -d 00:00:00:00:00:02 psget bootmode
Initial device bootmode: 0x0002 (2)

いったん抜き差ししてみる

$ lsusb
Bus 001 Device 009: ID 0a12:100b Cambridge Silicon Radio, Ltd

[HCI Mode]が消えて、PIDが変わっている。

さて、見事HIDデバイスになるのだが、接続が切れてしまい使えない。うーん、残念。

HCIモードに切り替える

$ sudo tools/hid2hci --method=csr2 \
 	  --devpath=$( udevadm trigger --verbose --subsystem-match=usb \
       --attr-match=idVendor=0a12 --attr-match=idProduct=100b \
       | cut -d '/' -f 3- )

$ sudo bccmd -d 00:00:00:00:00:02 psset -s 0 0x03cd 0x0000
$ sudo bccmd -d 00:00:00:00:00:02 psget bootmode
Initial device bootmode: 0x0000 (0)

おしまい

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment