KB: How to support BLE passkey paring mode

Question

How do we set up a server device to request a PIN code and then connect with a client device (usually a smartphone)?

image

Recommendation

Use the ble_peripheral_server_bond sample code, and modify it as shown below:

image

image

3 Likes

This looks interesting!

So in order to bond with the RSL10 I have to enter a numeric PIN on the smartphone?
And the PIN is hard coded in the application flashed into RSL10 due to no IO options available on the evaluation board.

yes. if you want to connect with RSL10 use your phone, you must input the right PIN which you defined in RSL10 in phone side. otherwise, you will received an reject connect response from RSL10

1 Like

if you want to support by IOS. you may need to refer ble_peripheral_server_bond_passkey_ios.zip (916.8 KB) to meet some rulars of APPLE

Hello,
Can i please understand the reason of having GAP_IO_CAP_DISPLAY_ONLY.
Since my device doesn’t have any keyboard nor display on it. Is it fine if i use GAP_IO_CAP_NO_INPUT_NO_OUTPUT ? Will i still be able to enter the passkey on my smart phone and connect to the device?

@rakshith.bn

The peripheral server device does not have keyboard and display. It can use GAP_IO_CAP_DISPLAY_ONLY.
That means the device could generate key and can display it. This does not mean that device has to have the display.

Thank you for using our community forum!

Hello,
This only constitues the use of 6 digit passkey (decimal equivalent). However, the max length of the passkey that could be used is 16 bytes. Is it possible to have ASCII based passkey or atleast use the entire 16 bytes of the passkey? If so, how is it represented?

@rakshith.bn

A Bluetooth passkey is a numeric code used to establish a pairing between two Bluetooth-enabled devices.
it is not possible to have ASCII based passkey.

Thank you for using our community forum!

After doing this changes i am seeing two different behavior on two different platforms.
After scanning the device from windows when i am trying to connect my device, Windows is asking for the passkey which is expected.
But when I am doing the same thing in nRF app, nRF app is not asking for the passkey. There is one more bond option in nRF app. When I use that option at that time the app is asking for the passkey. I want that it should ask for the passkey even when I press the connect button in nRF app.

Can you explain what additional changes I have to do?

@niket.shah

This is caused by the nRF app not by our examples.
If you are using the default bluetooth of smartphone’s settings , you should also see the passkey request. So this is caused by the custom application, that we can’t control., as it didn’t enable the passkey feature .

Thank you for using our community forum!

Please see the attached Image. When I send the highlighted frame from the device, nRF app also asks for the pairing key. Can you explain why?
Main problem is, the device should not allow connection without the valid key but when I press connect button on nRF app, device allows connection. We want to avoid this connection. Even the example code allows connection without the key. We can see that connection frames on sniffer.

@niket.shah

The issue you are seeing is because the Passkey validation is a part of the Pairing Process, and a BLE Connection does not require Pairing unless it is done at the application level by the Central or Peripheral.

In the case of nRF connect, there is no way for a Peripheral to force it to Pair as it is considered the slave, and therefore you cannot force Passkey entry on Connection. Pairing can only be forced from the Central side application e.g Phone or PC.

What can be done on the Peripheral side is to enable Authentication requirements for all of the Services and Profiles present on the Peripheral, and then the Passkey will be forced to pair when Central tries to interact with the Services/Profiles.

Peripheral can also implement a timer at the application level, such that if pairing is not initiated within a certain time window the Peripheral will force a disconnect.

Thank you for using our community forum!