For a project i need to connect two Raspberry Pis with Bluetooth SSP Passkey entry. For the sake of the project, the passkey should be chosen and entered in both devices. This should be handled by a script which changes the passkey periodically in a pseudo-random fashion( like Passkey = Hash(time+seed)).
Hardware:
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 Version 5.50
The Bluetooth Core Spec 5.0 states on page 1441
"when one device has numeric input only and the other device has either a display or numeric input capability or when both devices only have numeric input capability. In this step, one device display a number to be entered by the other device or the user enters a number on both devices."
From my understanding, the passkey will be generated by the device with output capability if one device possesses an Output capability and the other device possesses an KeyboardOnly/DisyplayYes/No IOCapability. If both devices only possess the KeyboardOnly capability, then the passkey is chosen by the user and entered in both devices (which is my goal).
Here is what i tried:
When i try to pair both devices with IOCapabilities KeyboardOnly, they behave like they are DisplayOnly and DisplayYes/No but even if i confirm the Passkey with yes, they wont connect. If i put both devices in Pairable mode, no passkey is asked.
How do i tell bluetoothctl to use a passkey provided by me? The documentation of bluetoothctl and btmgmt is sadly non existent and i have problems progressing.
Device 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
Device 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