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

Central role sec_params_reply() returns NRF_ERROR_INVALID_ADDR

Hello!

I'm trying to read data off of a commercial blood pressure monitor (Qardio arm) using an nrf51822 with the nrf51 SDK v10.0.0 as the central role (s120). I am able to connect using sd_ble_gap_connect() and run sd_ble_gap_authenticate(). Next I am inside BLE_GAP_EVT_SEC_PARAMS_REQUEST, which I should respond with sd_ble_gap_sec_params_reply(). However, I keep running into the INVALID_ADDR error whenever I try to use the params_reply() function. Below shows how I set up this function:

    ble_gap_sec_keyset_t ble_sec_keyset;
    const ble_gap_sec_keyset_t * p_keyset = &ble_sec_keyset;
    static ble_gap_id_key_t id_key;
    
    static void ble_var_init(){
        uint8_t addr_arr[6] = {0x51, 0xB7, 0x5B, 0x46, 0x46, 0xc0};  //addr of nrf51822
        id_key.id_addr_info.addr_type = BLE_GAP_ADDR_TYPE_PUBLIC;
    
        int i;
        for(i=0; i<6; i++){
            id_key.id_addr_info.addr[i] = addr_arr[i];
        }
        
        ble_sec_keyset.keys_central.p_enc_key  = NULL;
        ble_sec_keyset.keys_central.p_id_key   = NULL;
        ble_sec_keyset.keys_central.p_sign_key = NULL;
        ble_sec_keyset.keys_periph.p_enc_key   = NULL;
        ble_sec_keyset.keys_periph.p_id_key    = &id_key;
        ble_sec_keyset.keys_periph.p_sign_key  = NULL;
    
    }

Then these are the parameters I pass in my params_reply(): qardio_handle is the conn_handle of the BP monitor. This was stored upon initial BLE_GAP_EVT_CONNECTED.

sd_ble_gap_sec_params_reply(qardio_handle, NRF_SUCCESS, NULL, p_keyset);

I am still new with paring/bonding/encryption. My guess is that the error is coming from the 4th parameter. The API says "Bluetooth addresses distributed by the local device constitute an exception, since those will have to be filled in by the user before calling this function" for this function. I'm not quite sure what this means, but I've attempted to fill out the "addr" and "addr_type" fields in the id_key. Is this how it is done? I can't seem to find much documentation on how the keyset is used during this phase of the transaction.

Any help would be appreciated, thanks.

some extra information: I've tried setting the 4th parameter to NULL, still same error. Also, I can make the bonding work with my nrf Connect mobile app (I have a google pixel running android 7). I've also used wireshark to sniff the exact pairing process. Below shows the exhanged, and the attached sniffer trace:

image description

tien_android_qardio.pcapng

Related