Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Android pairing pop-up appears twice

Hi,

I am writing an app for nRF52840 with sdk 17.0.2 and freeRTOS.

The device should be a peripheral which a android app should be able to connect to.

Everthing works but when I use an android app for connecting like "NRF Connect" the pairing popup on android shows twice. 

I am using secure manager with following options

#define SEC_PARAM_BOND 1                               /**< Perform bonding. */
#define SEC_PARAM_MITM 0                               /**< Man In The Middle protection not required. */
#define SEC_PARAM_LESC 1                               /**< LE Secure Connections  enabled. */
#define SEC_PARAM_KEYPRESS 0                           /**< Keypress notifications not enabled. */
#define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_NONE /**< No I/O capabilities. */
#define SEC_PARAM_OOB 0                                /**< Out Of Band data not available. */
#define SEC_PARAM_MIN_KEY_SIZE 7                       /**< Minimum encryption key size. */
#define SEC_PARAM_MAX_KEY_SIZE 16                      /**< Maximum encryption key size. */


  // Security parameters to be used for all security procedures.
    sec_param.bond = SEC_PARAM_BOND;
    sec_param.mitm = SEC_PARAM_MITM;
    sec_param.lesc = SEC_PARAM_LESC;

    sec_param.keypress = SEC_PARAM_KEYPRESS;
    sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES;
    sec_param.oob = SEC_PARAM_OOB;
    sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE;
    sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE;
    sec_param.kdist_own.enc = 1;
    sec_param.kdist_own.id = 1;
    sec_param.kdist_peer.enc = 1;
    sec_param.kdist_peer.id = 1;

I found a similar question but was instructed to open a new topic.

https://devzone.nordicsemi.com/f/nordic-q-a/73160/android-pairing-pop-up-appears-twice/336662#336662 

This is the log of nRF Connect:

nRF Connect, 2021-10-29
xxx Mobile (C0:E3:F7:8A:4F:76)
V	13:37:12.490	Connecting to C0:E3:F7:8A:4F:76...
D	13:37:12.491	gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)
D	13:37:12.599	[Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
I	13:37:12.599	Connected to C0:E3:F7:8A:4F:76
V	13:37:12.603	Discovering services...
D	13:37:12.603	gatt.discoverServices()
D	13:37:12.636	[Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
D	13:37:12.739	[Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_BONDING (11)
D	13:37:12.757	[Broadcast] Action received: android.bluetooth.device.action.PAIRING_REQUEST, pairing variant: PAIRING_VARIANT_CONSENT (3)
I	13:37:13.532	Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
D	13:37:13.678	[Callback] Services discovered with status: 0
I	13:37:13.678	Services discovered
V	13:37:13.684	Generic Access (0x1800)
- Device Name [R] (0x2A00)
- Appearance [R] (0x2A01)
- Peripheral Preferred Connection Parameters [R] (0x2A04)
- Central Address Resolution [R] (0x2AA6)
Generic Attribute (0x1801)
Nordic UART Service (6e400001-b5a3-f393-e0a9-e50e24dcca9e)
- RX Characteristic [W WNR] (6e400002-b5a3-f393-e0a9-e50e24dcca9e)
- TX Characteristic [N] (6e400003-b5a3-f393-e0a9-e50e24dcca9e)
   Client Characteristic Configuration (0x2902)
D	13:37:13.684	gatt.setCharacteristicNotification(6e400003-b5a3-f393-e0a9-e50e24dcca9e, true)
I	13:37:13.775	Connection parameters updated (interval: 45.0ms, latency: 0, timeout: 5000ms)
I	13:37:18.127	Connection parameters updated (interval: 11.25ms, latency: 0, timeout: 4000ms)
D	13:37:18.132	[Broadcast] Action received: android.bluetooth.device.action.PAIRING_REQUEST, pairing variant: PAIRING_VARIANT_CONSENT (3)
V	13:37:30.890	Disconnecting...
D	13:37:30.890	gatt.disconnect()
D	13:37:30.896	[Callback] Connection state changed with status: 0 and new state: DISCONNECTED (0)
I	13:37:30.896	Disconnected
D	13:37:37.542	[Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_NONE (10)
I	13:37:37.542	Bonding failed
D	13:37:37.573	[Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED
D	13:46:26.833	gatt.close()
D	13:46:26.838	wait(200)
V	13:46:27.039	Connecting to C0:E3:F7:8A:4F:76...
D	13:46:27.039	gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)
D	13:46:27.088	[Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
I	13:46:27.088	Connected to C0:E3:F7:8A:4F:76
V	13:46:27.122	Discovering services...
D	13:46:27.122	gatt.discoverServices()
D	13:46:27.124	[Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
D	13:46:27.235	[Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_BONDING (11)
D	13:46:27.260	[Broadcast] Action received: android.bluetooth.device.action.PAIRING_REQUEST, pairing variant: PAIRING_VARIANT_CONSENT (3)
I	13:46:28.198	Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
D	13:46:28.364	[Callback] Services discovered with status: 0
I	13:46:28.364	Services discovered
V	13:46:28.370	Generic Access (0x1800)
- Device Name [R] (0x2A00)
- Appearance [R] (0x2A01)
- Peripheral Preferred Connection Parameters [R] (0x2A04)
- Central Address Resolution [R] (0x2AA6)
Generic Attribute (0x1801)
Nordic UART Service (6e400001-b5a3-f393-e0a9-e50e24dcca9e)
- RX Characteristic [W WNR] (6e400002-b5a3-f393-e0a9-e50e24dcca9e)
- TX Characteristic [N] (6e400003-b5a3-f393-e0a9-e50e24dcca9e)
   Client Characteristic Configuration (0x2902)
D	13:46:28.370	gatt.setCharacteristicNotification(6e400003-b5a3-f393-e0a9-e50e24dcca9e, true)
I	13:46:28.469	Connection parameters updated (interval: 45.0ms, latency: 0, timeout: 5000ms)
D	13:46:31.320	[Broadcast] Action received: android.bluetooth.device.action.PAIRING_REQUEST, pairing variant: PAIRING_VARIANT_CONSENT (3)
I	13:46:32.563	Connection parameters updated (interval: 11.25ms, latency: 0, timeout: 4000ms)
D	13:47:03.040	[Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_NONE (10)
I	13:47:03.040	Bonding failed
D	13:47:06.036	[Callback] Connection state changed with status: 0 and new state: DISCONNECTED (0)
I	13:47:06.036	Disconnected
D	13:47:06.086	[Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED
D	14:18:46.683	gatt.close()
D	14:18:46.688	wait(200)
V	14:18:46.894	Connecting to C0:E3:F7:8A:4F:76...
D	14:18:46.894	gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)
D	14:18:46.984	[Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
I	14:18:46.984	Connected to C0:E3:F7:8A:4F:76
V	14:18:46.990	Discovering services...
D	14:18:46.990	gatt.discoverServices()
D	14:18:47.012	[Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
D	14:18:47.082	[Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_BONDING (11)
D	14:18:47.106	[Broadcast] Action received: android.bluetooth.device.action.PAIRING_REQUEST, pairing variant: PAIRING_VARIANT_CONSENT (3)
I	14:18:47.871	Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
D	14:18:47.964	[Callback] Services discovered with status: 0
I	14:18:47.965	Services discovered
V	14:18:47.970	Generic Access (0x1800)
- Device Name [R] (0x2A00)
- Appearance [R] (0x2A01)
- Peripheral Preferred Connection Parameters [R] (0x2A04)
- Central Address Resolution [R] (0x2AA6)
Generic Attribute (0x1801)
Nordic UART Service (6e400001-b5a3-f393-e0a9-e50e24dcca9e)
- RX Characteristic [W WNR] (6e400002-b5a3-f393-e0a9-e50e24dcca9e)
- TX Characteristic [N] (6e400003-b5a3-f393-e0a9-e50e24dcca9e)
   Client Characteristic Configuration (0x2902)
D	14:18:47.970	gatt.setCharacteristicNotification(6e400003-b5a3-f393-e0a9-e50e24dcca9e, true)
I	14:18:48.055	Connection parameters updated (interval: 45.0ms, latency: 0, timeout: 5000ms)
D	14:18:52.035	[Broadcast] Action received: android.bluetooth.device.action.PAIRING_REQUEST, pairing variant: PAIRING_VARIANT_CONSENT (3)
I	14:18:52.462	Connection parameters updated (interval: 11.25ms, latency: 0, timeout: 4000ms)
D	14:19:24.902	[Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_NONE (10)
I	14:19:24.903	Bonding failed
D	14:19:27.908	[Callback] Connection state changed with status: 0 and new state: DISCONNECTED (0)
I	14:19:27.908	Disconnected
D	14:19:27.959	[Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED

Can anyone help me out?

Thanks, Andreas

Parents
  • Hi

    We have taken another look at your sniffer trace, and it seems like the peripheral is issuing a security request on connection before the client has a chance to perform service discovery. Are you calling pm_handler_on_pm_evt() from your PM callback? If so, you can try adding a delay using pm_handler_sec_delay_ms or comment out pm_handler_on_pm_evt() entirely.

    Best regards,

    Simon

  • Hi,

    thank you for looking into that again.

    I changed my code. Now I invoke "smd_link_secure" a few seconds after mobile gets connected. Now I see "services discovered" on my mobile app before sending "smd_link_secure". I changed to "smd_link_secure":

    ble_gap_sec_params_t sec_param;
    memset(&sec_param, 0, sizeof(ble_gap_sec_params_t));
    
    // Security parameters to be used for all security procedures.
    sec_param.bond = SEC_PARAM_BOND; // =1
    sec_param.mitm = SEC_PARAM_MITM; // =0
    sec_param.lesc = SEC_PARAM_LESC;// =1
    
    sec_param.keypress = SEC_PARAM_KEYPRESS; // =0
    sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES; // =3
    sec_param.oob = SEC_PARAM_OOB; // =0
    sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE; // = 7
    sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE; // = 16
    sec_param.kdist_own.enc = 1;
    sec_param.kdist_own.id = 1;
    sec_param.kdist_peer.enc = 1;
    sec_param.kdist_peer.id = 1;
    
    smd_link_secure(handle, &sec_param, true);

    But I still get "PM_EVT_CONN_SEC_PARAMS_REQ" in pm_evt_handler twice after that.

    I see pairing popup on mobile after invoking "smd_link_secure" but when I accept that I get the second "PM_EVT_CONN_SEC_PARAMS_REQ " request and after I see this a second pairing popup on the mobile.

    It looks like the mobile tries to pair again or use other settings? This is a breakpoint at second "PM_EVT_CONN_SEC_PARAMS_REQ"

    I found some who has the same problem, but he also got no answer:

    https://stackoverflow.com/questions/67701354/why-do-i-receive-a-message-twice-asking-me-if-i-want-to-pair-with-lesc-just-work

    Many thanks on your effort! Maybe you can help further?

    Andreas

Reply
  • Hi,

    thank you for looking into that again.

    I changed my code. Now I invoke "smd_link_secure" a few seconds after mobile gets connected. Now I see "services discovered" on my mobile app before sending "smd_link_secure". I changed to "smd_link_secure":

    ble_gap_sec_params_t sec_param;
    memset(&sec_param, 0, sizeof(ble_gap_sec_params_t));
    
    // Security parameters to be used for all security procedures.
    sec_param.bond = SEC_PARAM_BOND; // =1
    sec_param.mitm = SEC_PARAM_MITM; // =0
    sec_param.lesc = SEC_PARAM_LESC;// =1
    
    sec_param.keypress = SEC_PARAM_KEYPRESS; // =0
    sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES; // =3
    sec_param.oob = SEC_PARAM_OOB; // =0
    sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE; // = 7
    sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE; // = 16
    sec_param.kdist_own.enc = 1;
    sec_param.kdist_own.id = 1;
    sec_param.kdist_peer.enc = 1;
    sec_param.kdist_peer.id = 1;
    
    smd_link_secure(handle, &sec_param, true);

    But I still get "PM_EVT_CONN_SEC_PARAMS_REQ" in pm_evt_handler twice after that.

    I see pairing popup on mobile after invoking "smd_link_secure" but when I accept that I get the second "PM_EVT_CONN_SEC_PARAMS_REQ " request and after I see this a second pairing popup on the mobile.

    It looks like the mobile tries to pair again or use other settings? This is a breakpoint at second "PM_EVT_CONN_SEC_PARAMS_REQ"

    I found some who has the same problem, but he also got no answer:

    https://stackoverflow.com/questions/67701354/why-do-i-receive-a-message-twice-asking-me-if-i-want-to-pair-with-lesc-just-work

    Many thanks on your effort! Maybe you can help further?

    Andreas

Children
No Data
Related