解決した。 編集: 以下を参照してください。
私はこの問題についてインターネットを十分に精査してきたと思います。それは何度も尋ねられましたが、解決策のどれも私のために機能しません。最終的に低エネルギー機能を使用できるようにしたいので、BlueZ 5にアップグレードしました。しかし今のところ、デバイスをペアリングすることすらできません。GUIは使用できません。これは最終的に組み込みLinuxシステム用になるためです。したがって、インタラクティブセッションが必要なため、bluetoothctlも使用できないと思います。(私はそれについて間違っているかもしれません。)したがって、私はすべてがBASH、C、またはpythonの順であるようにしたいと思っています。また、自動化する必要があるため、ペアリングと接続はLinuxボックスからではなく、Bluetoothデバイスから開始する必要があります。最後に、すべてのデバイスはa2dpプロファイルを使用する必要があります。
多くのアプローチがあるようですが、私はどちらが終わりどこが始まるかはっきりしていません:
アプローチ1:
a)$ sudo bluetoothd -d -n
#bluetoothdを冗長モードで実行します
b)$ hciconfig hci1 up
#デバイスの電源を入れます
$ hciconfig -a
#デバイスのプロパティを参照
Type: BR/EDR Bus: USB
BD Address: 00:02:72:C5:D8:E0 ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING PSCAN ISCAN
RX bytes:32875 acl:761 sco:0 events:1037 errors:0
TX bytes:20178 acl:780 sco:0 commands:329 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: 'Adapter-1'
Class: 0x00010c
Service Classes: Unspecified
Device Class: Computer, Laptop
HCI Version: 4.0 (0x6) Revision: 0x1000
LMP Version: 4.0 (0x6) Subversion: 0x220e
Manufacturer: Broadcom Corporation (15)
c)デバイスからペアリングしてみます。
結果:Bluetoothから:
bluetoothd[5359]: src/adapter.c:connected_callback() hci1 device 70:72:3C:62:49:7F connected eir_len 15
bluetoothd[5359]: src/adapter.c:user_confirm_request_callback() hci1 70:72:3C:62:49:7F confirm_hint 1
bluetoothd[5359]: src/device.c:new_auth() Requesting agent authentication for 70:72:3C:62:49:7F
** bluetoothd[5359]: No agent available for request type 2
** bluetoothd[5359]: device_confirm_passkey: Operation not permitted
bluetoothd[5359]: src/adapter.c:btd_adapter_confirm_reply() hci1 addr 70:72:3C:62:49:7F success 0
bluetoothd[5359]: src/adapter.c:bonding_attempt_complete() hci1 bdaddr 70:72:3C:62:49:7F type 0 status 0x5
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x05
bluetoothd[5359]: src/device.c:device_bonding_failed() status 5
bluetoothd[5359]: src/adapter.c:resume_discovery()
bluetoothd[5359]: src/adapter.c:dev_disconnected() Device 70:72:3C:62:49:7F disconnected, reason 3
bluetoothd[5359]: src/adapter.c:adapter_remove_connection()
bluetoothd[5359]: src/adapter.c:bonding_attempt_complete() hci1 bdaddr 70:72:3C:62:49:7F type 0 status 0xe
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x0e
bluetoothd[5359]: src/device.c:device_bonding_failed() status 14
bluetoothd[5359]: src/adapter.c:resume_discovery()
PINまたはパスキーが正しくないため、デバイスはアダプタ1とペアリングできませんでした。
上記のスター付きの回答に基づいて、エージェントが存在しない理由を調査しました。エージェントとは何ですか?誰にもわかりませんが、私のデバイスとbluetoothデーモンの間の仲介者であると推測しました。
d)$ ../bluey-5.15/test/simple-agent
#これらのコマンドでsudoも使用してみました
または $ ../bluey-5.15/test/simple-agent hci1
これは、着信ペアリング要求を処理するPythonスクリプトです。成功した場合、「信頼」と「接続」も試みます
出力: Agent registered
e)次に、デバイスからペアリングを再試行します。
単純なエージェントの出力:
RequestConfirmation (/org/bluez/hci1/dev_70_72_3C_62_49_7F, 110643)
Confirm passkey (yes/no): yes
BTデバイスでペアリングを実行すると、ペアリング済みと表示されますが、シンプルエージェントがハングします。BlueZ 4を使用しましたが、「新しいデバイスXX_XX_XX_XX_XX_XX」のようなメッセージが表示されるはずです。
bluetoothd出力:
** bluetoothd[5359]: src/agent.c:set_default_agent() Default agent set to :1.126 /test/agent
bluetoothd[5359]: src/adapter.c:connected_callback() hci1 device 70:72:3C:62:49:7F connected eir_len 15
bluetoothd[5359]: src/adapter.c:user_confirm_request_callback() hci1 70:72:3C:62:49:7F confirm_hint 0
bluetoothd[5359]: src/device.c:new_auth() Requesting agent authentication for 70:72:3C:62:49:7F
bluetoothd[5359]: src/agent.c:agent_ref() 0xa59290: ref=2
bluetoothd[5359]: src/agent.c:agent_request_confirmation() Calling Agent.RequestConfirmation: name=:1.126, path=/test/agent, passkey=110643
bluetoothd[5359]: src/agent.c:agent_ref() 0xa59290: ref=3
bluetoothd[5359]: src/adapter.c:btd_adapter_confirm_reply() hci1 addr 70:72:3C:62:49:7F success 1
bluetoothd[5359]: src/agent.c:agent_unref() 0xa59290: ref=2
bluetoothd[5359]: src/agent.c:agent_unref() 0xa59290: ref=1
bluetoothd[5359]: src/adapter.c:new_link_key_callback() hci1 new key for 70:72:3C:62:49:7F type 5 pin_len 0
bluetoothd[5359]: src/device.c:device_set_bonded()
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x00
bluetoothd[5359]: src/adapter.c:resume_discovery()
bluetoothd[5359]: src/adapter.c:dev_disconnected() Device 70:72:3C:62:49:7F disconnected, reason 3
bluetoothd[5359]: src/adapter.c:adapter_remove_connection()
bluetoothd[5359]: src/adapter.c:bonding_attempt_complete() hci1 bdaddr 70:72:3C:62:49:7F type 0 status 0xe
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x0e
bluetoothd[5359]: src/device.c:device_bonding_failed() status 14
bluetoothd[5359]: src/adapter.c:resume_discovery()
これは何かをします。
hcidump出力:
$ hcidump -i hci1
HCI sniffer - Bluetooth packet analyzer ver 5.15
device: hci1 snap_len: 1500 filter: 0xffffffffffffffff
> HCI Event: Connect Request (0x04) plen 10
bdaddr 70:72:3C:62:49:7F class 0x5a020c type ACL
> HCI Event: Command Status (0x0f) plen 4
Accept Connection Request (0x01|0x0009) status 0x00 ncmd 1
> HCI Event: Connect Complete (0x03) plen 11
status 0x00 handle 11 bdaddr 70:72:3C:62:49:7F type ACL encrypt 0x00
> HCI Event: Command Status (0x0f) plen 4
Read Remote Supported Features (0x01|0x001b) status 0x00 ncmd 1
> HCI Event: Read Remote Supported Features (0x0b) plen 11
status 0x00 handle 11
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
> HCI Event: Command Status (0x0f) plen 4
Read Remote Extended Features (0x01|0x001c) status 0x00 ncmd 1
> HCI Event: Command Complete (0x0e) plen 10
IO Capability Request Reply (0x01|0x002b) ncmd 1
status 0x00 bdaddr 70:72:3C:62:49:7F
> HCI Event: Read Remote Extended Features (0x23) plen 13
status 0x00 handle 11 page 1 max 1
Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> HCI Event: Command Status (0x0f) plen 4
Remote Name Request (0x01|0x0019) status 0x00 ncmd 1
> HCI Event: Remote Name Req Complete (0x07) plen 255
status 0x00 bdaddr 70:72:3C:62:49:7F name 'Prism II'
> HCI Event: Command Complete (0x0e) plen 10
User Confirmation Request Reply (0x01|0x002c) ncmd 1
status 0x00 bdaddr 70:72:3C:62:49:7F
> HCI Event: Disconn Complete (0x05) plen 4
status 0x00 handle 11 reason 0x13
Reason: Remote User Terminated Connection
bluetoothctlも試しましたが、結果は同じです。面白いことに、BlueZの一部のスクリプト(test-deviceなど)は、BTデバイスをいくつかのコマンドで認識できますが、他のコマンドは認識できません。たとえば、test-deviceはデバイスを「信頼」しますが、「削除」しようとしたときにデバイスは存在しません。
アプローチ2:
dbus-send --systemコマンドを直接使用したDBUS。デバイスをペアリングして接続するまで、これらのコマンドはどれもうまくいきません。
アプローチ3:
私はこの投稿の提案をすべて試しました。BlueZ 5には/etc/bluetooth/hcid.confはありません。作成する必要がありますか?rfcommコマンドは接続しますが、直後に切断します。
$ sudo rfcomm connect /dev/rfcomm0 70:72:3C:62:49:7F 1
Connected /dev/rfcomm0 to 70:72:3C:62:49:7F on channel 1
Press CTRL-C for hangup
Disconnected
bluetoothd出力:
bluetoothd[5359]: src/adapter.c:connected_callback() hci1 device 70:72:3C:62:49:7F connected eir_len 10
bluetoothd[5359]: src/adapter.c:dev_disconnected() Device 70:72:3C:62:49:7F disconnected, reason 3
bluetoothd[5359]: src/adapter.c:adapter_remove_connection()
bluetoothd[5359]: src/adapter.c:bonding_attempt_complete() hci1 bdaddr 70:72:3C:62:49:7F type 0 status 0xe
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x0e
bluetoothd[5359]: src/device.c:device_bonding_failed() status 14
bluetoothd[5359]: src/adapter.c:resume_discovery()
hcidump出力:
$ hcidump -i hci1
HCI sniffer - Bluetooth packet analyzer ver 5.15
device: hci1 snap_len: 1500 filter: 0xffffffffffffffff
> HCI Event: Command Status (0x0f) plen 4
Create Connection (0x01|0x0005) status 0x00 ncmd 1
> HCI Event: Connect Complete (0x03) plen 11
status 0x00 handle 11 bdaddr 70:72:3C:62:49:7F type ACL encrypt 0x00
> HCI Event: Command Status (0x0f) plen 4
Read Remote Supported Features (0x01|0x001b) status 0x00 ncmd 1
> HCI Event: Read Remote Supported Features (0x0b) plen 11
status 0x00 handle 11
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
> HCI Event: Command Status (0x0f) plen 4
Read Remote Extended Features (0x01|0x001c) status 0x00 ncmd 1
> HCI Event: Read Remote Extended Features (0x23) plen 13
status 0x00 handle 11 page 1 max 1
Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> HCI Event: Command Status (0x0f) plen 4
Remote Name Request (0x01|0x0019) status 0x00 ncmd 1
> HCI Event: Remote Name Req Complete (0x07) plen 255
status 0x00 bdaddr 70:72:3C:62:49:7F name 'Prism II'
> HCI Event: Command Status (0x0f) plen 4
Authentication Requested (0x01|0x0011) status 0x00 ncmd 1
> HCI Event: Command Complete (0x0e) plen 10
Link Key Request Reply (0x01|0x000b) ncmd 1
status 0x00 bdaddr 70:72:3C:62:49:7F
> HCI Event: Auth Complete (0x06) plen 3
status 0x00 handle 11
> HCI Event: Command Status (0x0f) plen 4
Set Connection Encryption (0x01|0x0013) status 0x00 ncmd 1
> HCI Event: Encrypt Change (0x08) plen 4
status 0x00 handle 11 encrypt 0x01
> HCI Event: Command Status (0x0f) plen 4
Exit Sniff Mode (0x02|0x0004) status 0x0c ncmd 1
Error: Command Disallowed
> HCI Event: Disconn Complete (0x05) plen 4
status 0x00 handle 11 reason 0x13
Reason: Remote User Terminated Connection
助言がありますか?私は:
本当に明らかなことを忘れましたか?
ツールを誤って使用していますか?
設定ファイルを設定するのを忘れましたか?
編集:
bluez simple-agentは有用なエラーを出さなかったので、自分でペアリングエージェントを作成しました。一度接続すると、ペアリングはできましたが接続できませんでした。bluetoothdは私にこの新しいエラーを与えました:
bluetoothd[3078]: profiles/audio/a2dp.c:a2dp_source_connect() path /org/bluez/hci0/dev_70_72_3C_62_49_7F
bluetoothd[3078]: a2dp-source profile connect failed for 70:72:3C:62:49:7F: Protocol not available
この投稿は、おそらく私のローカルBluetoothアダプターが私のオーディオソースのa2dpプロファイルをサポートしていないことを指摘しました。(シンクのように機能しない)次に、BlueZ4からBlueZ5にアップグレードする多くの人が同じ問題を経験していることを確認しました。この問題はBlueZメーリングリストにも投稿されました。
これまでのところ、このプロトコルをアダプターに追加する方法を見つけていません。