Hi,
I think I have properly configured my application to authorize reads on characteristic, yet I do not see an event generated. I get write events, but I don't get read events. Can anyone see what I'm doing wrong, or not doing at all? Here are some code snippets from my application.
I create custom services as follows:
ret_code_t ble_vpe_init(ble_vpe_t * p_vpe, ble_vpe_init_t * p_vpe_init)
{
ret_code_t err_code;
ble_uuid_t ble_uuid;
ble_uuid128_t vpe_base_uuid = VECTOR_PUMP_BASE_UUID;
VERIFY_PARAM_NOT_NULL(p_vpe);
VERIFY_PARAM_NOT_NULL(p_vpe_init);
/**@snippet [Adding proprietary Service to the SoftDevice] */
// Add a custom base UUID.
err_code = sd_ble_uuid_vs_add(&vpe_base_uuid, &p_vpe->uuid_type);
VERIFY_SUCCESS(err_code);
ble_uuid.type = p_vpe->uuid_type;
ble_uuid.uuid = BLE_UUID_VECTOR_PUMP;
// Add service
err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
&ble_uuid,
&p_vpe->service_handle);
VERIFY_SUCCESS(err_code);
// Add the characteristics
err_code = vpe_command_char_add(p_vpe);
return err_code;
}
I add the custom characteristic to the service as follows:
static ret_code_t vpe_command_char_add(ble_vpe_t *p_vpe)
{
ret_code_t err_code;
uint8_t init_value = 0;
ble_uuid_t char_uuid;
ble_uuid128_t base_uuid = COMMAND_BASE_UUID;
ble_add_char_user_desc_t user_desc;
ble_gatts_attr_md_t attr_md;
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
// Add a custom base UUID.
err_code = sd_ble_uuid_vs_add(&base_uuid, &char_uuid.type);
VERIFY_SUCCESS(err_code);
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.char_props.write = 1;
ble_gatts_attr_md_t cccd_md;
memset(&cccd_md, 0, sizeof(cccd_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
cccd_md.vloc = BLE_GATTS_VLOC_STACK;
char_md.p_cccd_md = &cccd_md;
char_md.char_props.notify = 1;
memset(&attr_md, 0, sizeof(attr_md));
attr_md.rd_auth = 1;
attr_md.wr_auth = 0;
attr_md.vlen = 0;
attr_md.vloc = BLE_GATTS_VLOC_STACK;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
memset(&attr_char_value, 0, sizeof(attr_char_value));
char_uuid.uuid = BLE_UUID_VECTOR_PUMP;
attr_char_value.p_uuid = &char_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = BLE_COMMAND_CHAR_LEN;
attr_char_value.init_offs = 0;
attr_char_value.max_len = BLE_COMMAND_CHAR_LEN;
attr_char_value.p_value = &init_value;
err_code = sd_ble_gatts_characteristic_add(p_vpe->service_handle,
&char_md,
&attr_char_value,
&p_vpe->command_char_handle);
VERIFY_SUCCESS(err_code);
return err_code;
}
I get write events, but I don't get any read events. My event handler is as follows:
void ble_vpe_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
{
if ((p_context == NULL) || (p_ble_evt == NULL))
{
return;
}
ble_vpe_t * p_vpe = (ble_vpe_t *)p_context;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
on_connect(p_vpe, p_ble_evt);
break;
case BLE_GATTS_EVT_WRITE:
on_write(p_vpe, p_ble_evt);
break;
case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
if((p_ble_evt->evt.gatts_evt.params.authorize_request.type) == BLE_GATTS_AUTHORIZE_TYPE_READ){
NRF_LOG_INFO(0,"BLE Read request. \n");
on_read(p_vpe, p_ble_evt);
}
//If there is a write request
else if((p_ble_evt->evt.gatts_evt.params.authorize_request.type) == BLE_GATTS_AUTHORIZE_TYPE_WRITE){
NRF_LOG_INFO(0,"BLE Write request. \n");
on_write(p_vpe, p_ble_evt);
}
break;
default:
// No implementation needed.
break;
}
}