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

nRF52832 BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM failed

Hi,

I got a problem that when I try to use BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM for characteristic.

As I follow the tutorial to create the custom service, when I changed "BLE_GAP_CONN_SEC_MODE_SET_OPEN" to "BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM" then the application run failed and show fatal error.

Is there any point that I miss it ? Or how to create the characteristic with encryption correctly ?

I used SDK v15 BTY.

Thanks.

  • Hi,

    Can you be more specific to what error you get? The simplest way to see where it fails and with what error code is to enable/define DEBUG and logging. Then you should see which file and line number the error is caught, and what the error code was.

  • Hi

    Sorry, the error code is 7.

    I follow the custom service to build my own service, but in this tutorial using the OPEN characteristic.

    But I want to use the encryption character, so follow the final step in Step6 in tutorial to set "BLE_GAP_CONN_SEC_MODE_SET_OPEN", and change it to "BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM"  in main.c, then I got the error.

  • I see. 7 is NRF_ERROR_INVALID_PARAM. From which function do you get that returned?

  • Hi 

    Sorry for the late reply, I was deal with another task.

    I got it when I called service init from main.c file.

    here's my code

    // In main.c
    static void btp_info_initiate(void) {
        ret_code_t     err_code;
        btp_info_init_t info_init;
    
        memset(&info_init, 0, sizeof(info_init));
    
        BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&info_init.btp_info_value_char_attr_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&info_init.btp_info_value_char_attr_md.write_perm);
    
        //BLE_GAP_CONN_SEC_MODE_SET_OPEN(&info_init.btp_info_value_char_attr_md.read_perm);
        //BLE_GAP_CONN_SEC_MODE_SET_OPEN(&info_init.btp_info_value_char_attr_md.write_perm);
    
        info_init.evt_handler = btp_info_evt;
    
        err_code = btp_info_init(&btp_info, &info_init);  // err_code return 7 on this line
        APP_ERROR_CHECK(err_code);
    }

    P.S This function will be call in service_init in main.c

    Then I trace with error, see the error code will return 7 when called btp_info_init function.

    // In cus_srv.c
    ret_code_t btp_info_init(btp_info_t * p_info, const btp_info_init_t * p_info_init) {
    
        if (p_info == NULL || p_info_init == NULL)
            return NRF_ERROR_NULL;
    
        ret_code_t err_code;
        ble_uuid_t ble_uuid;
    
        p_info->evt_handler = p_info_init->evt_handler;
        p_info->conn_handle = BLE_CONN_HANDLE_INVALID;
    
        // Add BTP Info Service UUID
        ble_uuid128_t base_uuid = {BTP_INFO_SERVICE_BASE};
        err_code = sd_ble_uuid_vs_add(&base_uuid, &p_info->uuid_type);
        VERIFY_SUCCESS(err_code);
    
        // Add BTP Info Service
        ble_uuid.type = p_info->uuid_type;
        ble_uuid.uuid = BTP_UUID_INFO_SERVICE;
    
        err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_info->service_handle);
        if(err_code != NRF_SUCCESS)
            return err_code;
        
        err_code = btp_info_trek_stat_char_add(p_info, p_info_init);
        VERIFY_SUCCESS(err_code);
    }

    And I keep trace into it, I see the error comes from btp_info_trek_stat_char_add function

    static uint32_t btp_info_trek_stat_char_add(btp_info_t * p_info, const btp_info_init_t * p_info_init) {
        ble_uuid_t          ble_uuid;
        ble_gatts_char_md_t char_md;
        ble_gatts_attr_md_t attr_md;
        ble_gatts_attr_t    attr_char_value;
    
        // The ble_gatts_char_md_t structure uses bit fields. So we reset the memory to zero.
        memset(&char_md, 0, sizeof(char_md));
    
        char_md.char_props.write = 0;
        char_md.char_props.read  = 1;
        char_md.char_props.notify = 1;
        char_md.p_char_pf = NULL;
        char_md.p_cccd_md = &attr_md;
        char_md.p_sccd_md = NULL;
        char_md.p_user_desc_md = NULL;
    
        memset(&attr_md, 0, sizeof(attr_md));
    
        attr_md.read_perm  = p_info_init->btp_info_value_char_attr_md.read_perm;
        attr_md.write_perm = p_info_init->btp_info_value_char_attr_md.write_perm;
        attr_md.vloc       = BLE_GATTS_VLOC_STACK;
        attr_md.rd_auth    = 0;
        attr_md.wr_auth    = 0;
        attr_md.vlen       = 0;
    
        uint32_t err_code;
        ble_uuid128_t base_uuid = BTP_INFO_TRACKING_STAT_BASE;
        ble_uuid.uuid = BTP_UUID_INFO_TRACKING_STAT;
        err_code = sd_ble_uuid_vs_add(&base_uuid, &ble_uuid.type);
        LOG_INFO("err_code: %d", err_code);
        APP_ERROR_CHECK(err_code);  
    
        memset(&attr_char_value, 0, sizeof(attr_char_value));
    
        attr_char_value.p_uuid    = &ble_uuid;
        attr_char_value.p_attr_md = &attr_md;
        attr_char_value.init_len  = sizeof(uint8_t);
        attr_char_value.init_offs = 0;
        attr_char_value.max_len   = sizeof(uint8_t);
        //attr_char_value.p_value   = p_char_value;
    
        return sd_ble_gatts_characteristic_add(p_info->service_handle, &char_md,
                                               &attr_char_value,
                                               &p_info->btp_info_trek_stat_handles);
    }

    And in final the error comes from the sd_ble_gatts_characteristic_add function.

    So is there something that I miss?

  • I see,

    So you get the NRF_ERROR_INVALID_PARAM return code from the call to sd_ble_gatts_characteristic_add(). From the API documentation, this indicate that

    Invalid parameter(s) supplied, service handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.

    I do not immediately see the exact problem, though.

Related