Zephyr secure connection example - samples/bluetooth/peripheral_sc_only #bluetooth


When I enter incorrect password, a callback called 'pairing_failed' is triggered, but when I only cancel the pairing dialog, no 'pairing_failed' is triggered, therefore I cannot disconnect explicitly within this callback, but I wonder how it could even connect.
It tries to somehow automatically disconnect, but when I click on anything in android app, the applications stays connected, but when I do not touch anything in the app, it automatically disconnects, but it shows 'connected' for few seconds therefore I can open found services.


Dear all,

I am trying to develop an application on Nordic nrf52840_dongle utilizing bluetooth and Nordic Led Button Service. The application running on the dongle is supposed to notify button click on usb dongle and activate LED diode upon Nordic Android Blinky application or nRF Connect. Such a logic is very well working, but I wanted to implement sort of a security that not everyone is able to connect to the dongle and let the LED flash or have press button results available, so I wanted to base my secure connection on Zephyr example:
Since my dongle is headless (I do not know any other better way, how to pair one headless device and Android phone) and I am a newbie in Zephyr, the only way which came to my mind was to set up fixed key.
The Android application correctly asks for a key and it gets paired and successfully connected when correct passkey is entered and disconnected when incorrect passkey is entered. The problem arises when I press connect button in nRF Connect application, dialog with pairing request pops up and I cancel the dialog.
The application gets connected to the dongle automatically and stays connected, practically bypassing any security code I have added.
Could anyone help me with this issue?
Maybe there is a callback upon rejection of such a dialog, but I do not know where.
If possible, could anyone help me what is the reccommended way to implement pairing with single headless BT device so far I cannot see the generated passkey when using anything more sophisticated than fixed passkey. The same way probably bluetooth mouse and keyboards do, no way to enter any security passkey and their are secure and probably get paired automatically upon start.
I am enclosing modified 'samples/bluetooth/peripheral_sc_only' example.

Thank you all