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

INVALID_PARAMETER returned when setting CCCD to secure

This question was asked, not answered, and locked. So I will ask it again

I changed the security settings on a CCCD for a heart rate measurement characteristic and got INVALID PARAMETER

Here is the code (comes from the BleHeartRateMonitor example in the pc-ble-driver).

static uint32_t characteristic_init()
{
uint32_t error_code;
ble_gatts_char_md_t char_md;
ble_gatts_attr_md_t cccd_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
uint8_t encoded_initial_hrm[MAX_HRM_LEN];
uint16_t attr_char_value_init_len;

memset(&cccd_md, 0, sizeof(cccd_md));

cccd_md.rd_auth = 1;
//BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
//BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);

BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&cccd_md.read_perm);  // This is what I did
BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&cccd_md.write_perm);
cccd_md.vloc = BLE_GATTS_VLOC_STACK;

memset(&char_md, 0, sizeof(char_md));

char_md.char_props.notify = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = &cccd_md;
char_md.p_sccd_md = NULL;

BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_HEART_RATE_MEASUREMENT_CHAR);

memset(&attr_md, 0, sizeof(attr_md));

BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 1;

memset(&attr_char_value, 0, sizeof(attr_char_value));

attr_char_value_init_len = heart_rate_measurement_encode(encoded_initial_hrm, 0);

attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = attr_char_value_init_len;
attr_char_value.init_offs = 0;
attr_char_value.max_len = MAX_HRM_LEN;
attr_char_value.p_value = encoded_initial_hrm;

error_code = sd_ble_gatts_characteristic_add(m_adapter, m_heart_rate_service_handle,
&char_md,
&attr_char_value,
&m_heart_rate_measurement_handle);

if (error_code != NRF_SUCCESS)
{
printf("Failed to initialize characteristics. Error code: 0x%02X\n", error_code);
fflush(stdout);
return error_code;
}

printf("Characteristics initiated\n");
fflush(stdout);
return NRF_SUCCESS;
}

I know that I have tried to set the CCCDs on devices and got an insufficient authentication (5) error, so I SHOULD be able to do this. What is wrong?

Parents Reply Children
No Data
Related