This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to pair between central/peripheral in lesc mode?

Thanks in advanced. Both platforms are: nrf52832, sdk17.0.2. The peripheral is based on ble_app_gls and I set static passkey 123456, the central is based on ble_app_hrs_c, so both sides have peer manager mechanism, I set sec_param.lesc=1 on both sides. I've implemented nus on both sides, I can use cell phone to pair/bond with the peripheral. But with nrf52832 central, I get below traces:

0> <info> app_timer: RTC: initialized.
 0> <info> app: Heart Rate collector example started.
 0> <info> app: Starting scan.
 0> <info> app: Connecting to target F92A1B6369F4
 0> <info> app: Connected.
 0> <info> app: GATT ATT MTU on connection 0x0 changed to 247.
 0> <info> app: Data length for connection 0x0 updated to 251.
 0> <info> app: BLE_GAP_EVT_LESC_DHKEY_REQUEST
 0> <info> nrf_ble_lesc: Calling sd_ble_gap_lesc_dhkey_reply on conn_handle: 0
 0> <info> app: Discovery complete.
 0> <info> app: Connected to device with Nordic UART Service.
 0> <info> peer_manager_handler: Connection secured: role: Central, conn_handle: 0, procedure: Bonding
 0> <info> app: BLE_GAP_EVT_AUTH_STATUS: status=0x0 bond=0x1 lv4: 0 kdist_own:0x3 kdist_peer:0x2
 0> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Bonding data, action: Update
 0> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update
 0> <info> app: Disconnected.
 0> <info> app: Starting scan.
 0> <info> app: Disconnected, reason 0x13.
 0> <info> app: Starting scan.
 0> <info> app: Connecting to target F92A1B6369F4
 0> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update, no change
 0> <info> app: Connected.
 0> <info> app: GATT ATT MTU on connection 0x0 changed to 247.
 0> <info> peer_manager_handler: Connection security failed: role: Central, conn_handle: 0x0, procedure: Encryption, error: 4352
 0> <info> app: Disconnected.
 0> <info> app: Starting scan.
 0> <info> app: Disconnected, reason 0x13.
 0> <info> app: Starting scan.
 0> <info> app: Connecting to target F92A1B6369F4
 0> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update, no change
 0> <info> app: Connected.
 0> <info> app: GATT ATT MTU on connection 0x0 changed to 247.
 0> <info> peer_manager_handler: Connection security failed: role: Central, conn_handle: 0x0, procedure: Encryption, error: 4352
 0> <info> app: Disconnected.
 0> <info> app: Starting scan.
 0> <info> app: Disconnected, reason 0x13.
 

I don't know how to input passkey in central, the central only has display capability by RTT Viewer. Would anyone tell me how to input passkey and get authority passed?

  • Have you been able to use the static passkey that you set while using another central, such as nRF Connect for Desktop? Did the passkey work?

    Now, on your custom central, do you see any events when you try to bond? Do you initiate bonding? If not, please look at how ble_app_hrs_c does this. (It doesn't use a passkey, but look at what events you receive when you initiate bonding).

    Best regards,

    Edvin

  • Thanks for reply, I can 100% ensure that the peripheral static passkey works normally with other central devices. About my custom central, I see this event:

      0> <info> nrf_ble_lesc: Calling sd_ble_gap_lesc_dhkey_reply on conn_handle: 0

    I think passkey should be input here, but I don't know how. And traces followed even show bonding pass without key......I even flash rom again and still get the result. 

    0> <info> peer_manager_handler: Connection secured: role: Central, conn_handle: 0, procedure: Bonding
    0> <info> app: BLE_GAP_EVT_AUTH_STATUS: status=0x0 bond=0x1 lv4: 0 kdist_own:0x3 kdist_peer:0x2

    My peer manager params are same on peripheral and central:

    sec_param.bond = 1;
    sec_param.mitm = 1;
    sec_param.lesc = 1;
    sec_param.keypress = 0;
    sec_param.io_caps = BLE_GAP_IO_CAPS_DISPLAY_ONLY;
    sec_param.oob = 0;
    sec_param.min_key_size = 7;
    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;

  • Add prints of peripheral when pairing/bonding:

    0> <info> app_timer: RTC: initialized.
     0> <info> app: 6-axis sensor started.
     0> <info> app: Fast advertising
     0> <info> app: TWI device detected at address 0x69
     0> <info> app: MPU6050 init success.
     0> <info> app: MPU6050 reg MPU_REG_WHO_AM_I value: 0x68.
     0> <info> app: Health Thermometer Service is scanned out.
     0> <info> app: Tx power level service is scanned out.
     0> <info> app: Custom service is scanned out.
     0> <info> app: Connected
     0> <info> app: BLE_GAP_EVT_LESC_DHKEY_REQUEST
     0> <info> nrf_ble_lesc: Calling sd_ble_gap_lesc_dhkey_reply on conn_handle: 0
     0> <info> peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 0, procedure: Bonding
     0> <info> app: Collector did not use MITM, disconnecting
     0> <info> app: BLE_GAP_EVT_AUTH_STATUS: status=0x0 bond=0x1 lv4: 0 kdist_own:0x3 kdist_peer:0x2
     0> <info> app: Pair success!
     0> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Bonding data, action: Update
     0> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update
     0> <info> app: Fast advertising
     0> <info> app: Tx power level service disconnected.
     0> <info> app: Custom service disconnected.
     0> <info> app: Disconnected
     0> <error> peer_manager_handler: Peer deleted successfully: peer_id: 0
     0> <info> app: Health Thermometer Service is scanned out.
     0> <info> app: Tx power level service is scanned out.
     0> <info> app: Custom service is scanned out.
     0> <info> app: Connected
     0> <info> peer_manager_handler: Connection security failed: role: Peripheral, conn_handle: 0x0, procedure: Encryption, error: 4102
     0> <warning> peer_manager_handler: Disconnecting conn_handle 0.
     0> <info> app: Fast advertising
     0> <info> app: Disconnected
     ......

  • faithself said:

    About my custom central, I see this event:

      0> <info> nrf_ble_lesc: Calling sd_ble_gap_lesc_dhkey_reply on conn_handle: 0

     dhkey implies that this is a Diffie Hellman key, which is not what you are trying to implement. The DHKey is used in LESC, while your 6-digit passkey is something else. 

    I believe what you are looking for is the event BLE_GAP_EVT_AUTH_KEY_REQUEST, where you are expected to reply with sd_ble_gap_auth_key_reply(), which takes the conn_handle, the key type (@ref BLE_GAP_AUTH_KEY_TYPES, where BLE_GAP_AUTH_KEY_TYPE_PASSKEY is the parameter for passkey), and *p_key, which is a pointer to where this key is stored in ascii, much like you did in the peripheral when you store the static key.

    I agree that the log says DHKEY_REQUEST, but are you sure this is the event that is also generated when you connect with your other peripherals using the static passkey?

    Best regards,

    Edvin

Related