我的旧车没有原生蓝牙音频功能,因此要使用手机听音乐,我将蓝牙接收器连接到车上的 3.5 毫米辅助插孔。问题是控制手机上的播放,而无需在驾驶时操作手机(您知道这是违法的>:))。
因此,我想到一个有趣的周末项目是将我的 Banana Pi 连接到汽车的 CAN 总线,以便监听方向盘上的媒体按钮(在从 aux 播放时不使用),同时还拥有 Banana Pi充当手机的 A/V 媒体控制器,通过蓝牙连接来控制手机媒体播放器。
所有这一切中最简单的部分是连接和嗅探 CAN 总线。蓝牙部分,没有那么多。 (还记得为什么我大约 20 年没有碰过任何蓝牙东西吗?)
我在 Arch Linux 下使用 BlueZ-5.69。我已禁用除 AVRCP 配置文件之外的所有功能。
[bluetooth]# show
Controller AA:AA:AA:AA:AA:AA (public)
Name: "Car Controller"
Alias: "Car Controller"
Class: 0x0000050c (1292)
Powered: yes
PowerState: on
Discoverable: no
DiscoverableTimeout: 0x000000b4 (180)
Pairable: yes
UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
Modalias: usb:v1D6Bp0246d0545
Discovering: no
Roles: central
Roles: peripheral
ExperimentalFeatures: BlueZ Experimental ISO... (6fbaf188-05e0-496a-9885-d6ddfdb4e03e)
据我了解,这应该允许手机连接,并且媒体播放器控件应该通过dbus
.发现和配对似乎工作正常,但配对完成后,手机断开连接并拒绝再次连接(我实际上尝试使用 bt-network 设置 NAP 配置文件,现在手机实际上使用提供的网络保持连接) 。
这就是从角度来看手机配对时所发生的情况bluetoothctl
。
[NEW] Device 3C:38:F4:93:55:61 Xperia 10 Ⅳ
Request confirmation
[agent] Confirm passkey 935792 (yes/no): yes
[CHG] Device 3C:38:F4:93:55:61 Bonded: yes
[CHG] Device 3C:38:F4:93:55:61 Modalias: usb:v0FCEp020Cd0010
[CHG] Device 3C:38:F4:93:55:61 UUIDs: 00001105-0000-1000-8000-00805f9b34fb
[CHG] Device 3C:38:F4:93:55:61 UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device 3C:38:F4:93:55:61 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 3C:38:F4:93:55:61 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 3C:38:F4:93:55:61 UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device 3C:38:F4:93:55:61 UUIDs: 00001115-0000-1000-8000-00805f9b34fb
[CHG] Device 3C:38:F4:93:55:61 UUIDs: 00001116-0000-1000-8000-00805f9b34fb
[CHG] Device 3C:38:F4:93:55:61 UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device 3C:38:F4:93:55:61 UUIDs: 0000112f-0000-1000-8000-00805f9b34fb
[CHG] Device 3C:38:F4:93:55:61 UUIDs: 00001132-0000-1000-8000-00805f9b34fb
[CHG] Device 3C:38:F4:93:55:61 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device 3C:38:F4:93:55:61 UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device 3C:38:F4:93:55:61 UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device 3C:38:F4:93:55:61 UUIDs: a82efa21-ae5c-3dde-9bbc-f16da7b16c5a
[CHG] Device 3C:38:F4:93:55:61 ServicesResolved: yes
[CHG] Device 3C:38:F4:93:55:61 Paired: yes
[CHG] Device 3C:38:F4:93:55:61 ServicesResolved: no
[CHG] Device 3C:38:F4:93:55:61 Connected: no
还有bleutoothd
日志
Sep 22 14:52:32 alarm bluetoothd[628]: src/shared/mgmt.c:can_read_data() [0x0000] event 0x000b
Sep 22 14:52:32 alarm bluetoothd[628]: src/adapter.c:connected_callback() hci0 device 3C:38:F4:93:55:61 connected eir_len 20
Sep 22 14:52:32 alarm bluetoothd[628]: src/device.c:device_create() dst 3C:38:F4:93:55:61
Sep 22 14:52:32 alarm bluetoothd[628]: src/device.c:device_new() address 3C:38:F4:93:55:61
Sep 22 14:52:32 alarm bluetoothd[628]: src/device.c:device_new() Creating device /org/bluez/hci0/dev_3C_38_F4_93_55_61
Sep 22 14:52:32 alarm bluetoothd[628]: src/device.c:device_set_class() /org/bluez/hci0/dev_3C_38_F4_93_55_61 0x5A020C
Sep 22 14:52:32 alarm bluetoothd[628]: src/shared/mgmt.c:can_read_data() [0x0000] event 0x000f
Sep 22 14:52:32 alarm bluetoothd[628]: src/adapter.c:user_confirm_request_callback() hci0 3C:38:F4:93:55:61 confirm_hint 0
Sep 22 14:52:32 alarm bluetoothd[628]: src/device.c:new_auth() Requesting agent authentication for 3C:38:F4:93:55:61
Sep 22 14:52:32 alarm bluetoothd[628]: src/agent.c:agent_ref() 0x1752050: ref=2
Sep 22 14:52:32 alarm bluetoothd[628]: src/agent.c:agent_request_confirmation() Calling Agent.RequestConfirmation: name=:1.62, path=/org/bluez/agent, passkey=935792
Sep 22 14:52:37 alarm bluetoothd[628]: src/agent.c:agent_ref() 0x1752050: ref=3
Sep 22 14:52:37 alarm bluetoothd[628]: src/adapter.c:btd_adapter_confirm_reply() hci0 addr 3C:38:F4:93:55:61 success 1
Sep 22 14:52:37 alarm bluetoothd[628]: src/agent.c:agent_unref() 0x1752050: ref=2
Sep 22 14:52:37 alarm bluetoothd[628]: src/agent.c:agent_unref() 0x1752050: ref=1
Sep 22 14:52:37 alarm bluetoothd[628]: src/shared/mgmt.c:send_request() [0x0000] command 0x001c
Sep 22 14:52:37 alarm bluetoothd[628]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x001c complete: 0x00
Sep 22 14:52:39 alarm bluetoothd[628]: src/shared/mgmt.c:can_read_data() [0x0000] event 0x0009
Sep 22 14:52:39 alarm bluetoothd[628]: src/adapter.c:new_link_key_callback() hci0 new key for 3C:38:F4:93:55:61 type 8 pin_len 0 store_hint 1
Sep 22 14:52:39 alarm bluetoothd[628]: src/device.c:device_set_bonded() setting bonded for device to true
Sep 22 14:52:39 alarm bluetoothd[628]: src/device.c:btd_device_set_temporary() temporary 0
Sep 22 14:52:39 alarm bluetoothd[628]: src/device.c:device_bonding_complete() bonding (nil) status 0x00
Sep 22 14:52:39 alarm bluetoothd[628]: src/device.c:device_bonding_complete() setting timer for reverse service discovery
Sep 22 14:52:39 alarm bluetoothd[628]: src/adapter.c:resume_discovery()
Sep 22 14:52:39 alarm bluetoothd[628]: src/shared/mgmt.c:send_request() [0x0000] command 0x0033
Sep 22 14:52:39 alarm bluetoothd[628]: src/shared/mgmt.c:can_read_data() [0x0000] event 0x002a
Sep 22 14:52:39 alarm bluetoothd[628]: src/shared/mgmt.c:can_read_data() [0x0000] command 0x0033 complete: 0x00
Sep 22 14:52:39 alarm bluetoothd[628]: src/adapter.c:add_accept_list_complete() 3C:38:F4:93:55:61 added to kernel accept list
Sep 22 14:52:41 alarm bluetoothd[628]: profiles/audio/avrcp.c:avrcp_controller_probe() path /org/bluez/hci0/dev_3C_38_F4_93_55_61
Sep 22 14:52:41 alarm bluetoothd[628]: profiles/audio/control.c:control_init() Registered interface org.bluez.MediaControl1 on path /org/bluez/hci0/dev_3C_38_F4_93_55_61
Sep 22 14:52:41 alarm bluetoothd[628]: src/service.c:btd_service_ref() 0x17458d0: ref=2
Sep 22 14:52:41 alarm bluetoothd[628]: src/service.c:change_state() 0x17458d0: device 3C:38:F4:93:55:61 profile avrcp-controller state changed: unavailable -> disconnected (0)
Sep 22 14:52:41 alarm bluetoothd[628]: profiles/audio/avrcp.c:avrcp_target_probe() path /org/bluez/hci0/dev_3C_38_F4_93_55_61
Sep 22 14:52:41 alarm bluetoothd[628]: src/service.c:btd_service_ref() 0x17524c0: ref=2
Sep 22 14:52:41 alarm bluetoothd[628]: src/service.c:change_state() 0x17524c0: device 3C:38:F4:93:55:61 profile audio-avrcp-target state changed: unavailable -> disconnected (0)
Sep 22 14:52:41 alarm bluetoothd[628]: src/device.c:device_svc_resolved() /org/bluez/hci0/dev_3C_38_F4_93_55_61 err 0
Sep 22 14:52:47 alarm bluetoothd[628]: src/shared/mgmt.c:can_read_data() [0x0000] event 0x000c
Sep 22 14:52:47 alarm bluetoothd[628]: src/adapter.c:dev_disconnected() Device 3C:38:F4:93:55:61 disconnected, reason 3
Sep 22 14:52:47 alarm bluetoothd[628]: src/adapter.c:adapter_remove_connection()
Sep 22 14:52:47 alarm bluetoothd[628]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr 3C:38:F4:93:55:61 type 0 status 0xe
Sep 22 14:52:47 alarm bluetoothd[628]: src/device.c:device_bonding_complete() bonding (nil) status 0x0e
Sep 22 14:52:47 alarm bluetoothd[628]: src/device.c:device_bonding_failed() status 14
阅读这一行Sep 22 14:52:41 alarm bluetoothd[628]: profiles/audio/control.c:control_init() Registered interface org.bluez.MediaControl1 on path /org/bluez/hci0/dev_3C_38_F4_93_55_61
,它看起来很有希望,但仅一秒或更短时间后就会断开连接。
因此,在走到这一步之后,我在蓝牙标准的兔子洞里摸索了大约一周,实现了我自己的 AVRCP 配置文件和服务,直到我放弃。然后我挖出一部旧 iPhone 并将其与 Banana Pi 配对,然后按下手机上的连接按钮,这就是我得到的结果
[agent] Authorize service 0000110e-0000-1000-8000-00805f9b34fb (yes/no): yes
[NEW] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 [default]
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Repeat: off
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Shuffle: off
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Status: stopped
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Track Key: Title
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Track Value:
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Track Key: TrackNumber
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Track Value: 0x00000000 (0)
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Track Key: NumberOfTracks
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Track Value: 0x00000000 (0)
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Track Key: Duration
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Track Value: 0x00000000 (0)
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Track Key: Album
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Track Value:
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Track Key: Artist
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Track Value:
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Track Key: Genre
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Track Value:
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Position: 0x00000000 (0)
[CHG] Player /org/bluez/hci0/dev_58_E2_8F_62_31_7C/player0 Position: 0x00000000 (0)
有用!
所以我现在的问题是,为什么 iPhone 连接到媒体控制器服务没有任何问题,而任何 Android 手机(我有 3 部)在配对后甚至无法尝试连接?我在这里真的很茫然,所以任何见解将不胜感激。