1

对于一个项目,我需要使用蓝牙 SSP 密码条目连接两个 Raspberry Pi。出于项目的考虑,应在两个设备中选择并输入密钥。这应该由一个脚本来处理,该脚本以伪随机方式定期更改密钥(如 Passkey = Hash(time+seed))。

硬件:

2x Raspberry Pi 4 Model b Rev 1.2

        Operating System: Raspbian GNU/Linux 10 (buster)
        Kernel: Linux 5.4.79-v7l+
        Architecture: arm

BlueZ 版本 5.50

蓝牙核心规范 5.0 第 1441 页的状态

“当一台设备只有数字输入而另一台设备具有显示或数字输入能力时,或者当两个设备都只有数字输入能力时。在此步骤中,一台设备显示一个由另一台设备输入或用户输入的数字两个设备上都有一个号码。”

据我了解,如果一个设备具有输出能力,而另一个设备具有 KeyboardOnly/DisyplayYes/No IOCapability,则密钥将由具有输出能力的设备生成。如果两个设备都只具有 KeyboardOnly 功能,那么密码由用户选择并输入到两个设备中(这是我的目标)。

这是我尝试过的:

当我尝试将这两个设备与 IOCapabilities KeyboardOnly 配对时,它们的行为就像是 DisplayOnly 和 DisplayYes/No 但即使我用是确认密码,它们也不会连接。如果我将两个设备都置于可配对模式,则不会询问密码。

我如何告诉 bluetoothctl 使用我提供的密码?遗憾的是,bluetoothctl 和 btmgmt 的文档不存在,并且我在进行过程中遇到了问题。

Bluetoothctl 联机帮助页

btmgmt 联机帮助页

设备 A:

root@PiAlice:/home/alicepi# bluetoothctl
Agent registered
[bluetooth]# agent off                  //unregister the agent to chose the right IOCaps
Agent unregistered
[bluetooth]# agent KeyboardOnly 
Agent registered
[bluetooth]# show
Controller DC:A6:32:99:5C:AC (public)
    Name: PiAlice
    Alias: PiAlice
    Class: 0x00480000
    Powered: yes
    Discoverable: no
    Pairable: no
    UUID: Headset AG                (00001112-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
    UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
    UUID: Handsfree Audio Gateway   (0000111f-0000-1000-8000-00805f9b34fb)
    Modalias: usb:v1D6Bp0246d0532
    Discovering: no
[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller DC:A6:32:99:5C:AC Discoverable: yes
[NEW] Device DC:A6:32:AB:71:D9 bobpi
[CHG] Device DC:A6:32:AB:71:D9 Connected: no
[DEL] Device DC:A6:32:AB:71:D9 bobpi
[bluetooth]# pairable on
Changing pairable on succeeded
[CHG] Controller DC:A6:32:99:5C:AC Pairable: yes
[NEW] Device DC:A6:32:AB:71:D9 bobpi
[CHG] Device DC:A6:32:AB:71:D9 Modalias: usb:v1D6Bp0246d0532
[CHG] Device DC:A6:32:AB:71:D9 UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:AB:71:D9 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:AB:71:D9 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:AB:71:D9 UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:AB:71:D9 UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:AB:71:D9 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:AB:71:D9 ServicesResolved: yes
[CHG] Device DC:A6:32:AB:71:D9 Paired: yes
[CHG] Device DC:A6:32:AB:71:D9 ServicesResolved: no
[CHG] Device DC:A6:32:AB:71:D9 Connected: no

设备 B:

root@bobpi:/home/bobpi# bluetoothctl
Agent registered
[bluetooth]# agent off
Agent unregistered
[bluetooth]# agent KeyboardOnly 
Agent registered
[bluetooth]# show
Controller DC:A6:32:AB:71:D9 (public)
    Name: bobpi
    Alias: bobpi
    Class: 0x00480000
    Powered: yes
    Discoverable: no
    Pairable: no
    UUID: Headset AG                (00001112-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
    UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
    UUID: Handsfree Audio Gateway   (0000111f-0000-1000-8000-00805f9b34fb)
    Modalias: usb:v1D6Bp0246d0532
    Discovering: no
[bluetooth]# scan on
Discovery started
[CHG] Controller DC:A6:32:AB:71:D9 Discovering: yes
[NEW] Device DC:A6:32:99:5C:AC PiAlice
[bluetooth]# pair DC:A6:32:99:5C:AC 
Attempting to pair with DC:A6:32:99:5C:AC
[CHG] Device DC:A6:32:99:5C:AC Connected: yes
Request confirmation
[agent] Confirm passkey 896560 (yes/no): yes
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device DC:A6:32:99:5C:AC Connected: no
[bluetooth]# pairable on
Changing pairable on succeeded
[CHG] Controller DC:A6:32:AB:71:D9 Pairable: yes
[bluetooth]# pair DC:A6:32:99:5C:AC 
Attempting to pair with DC:A6:32:99:5C:AC
[CHG] Device DC:A6:32:99:5C:AC Connected: yes
[CHG] Device DC:A6:32:99:5C:AC UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:99:5C:AC UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:99:5C:AC UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:99:5C:AC UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:99:5C:AC UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:99:5C:AC UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:99:5C:AC ServicesResolved: yes
[CHG] Device DC:A6:32:99:5C:AC Paired: yes
Pairing successful
[CHG] Device DC:A6:32:99:5C:AC ServicesResolved: no
[CHG] Device DC:A6:32:99:5C:AC Connected: no
4

0 回答 0