How to send write requests from central to peripheral when service is set up with is_defered_write = 1

This is the first time I come across with this configuration. I am trying to send a write request from the central to a peripheral device and I get "Insufficient Authentication" from the peripheral. After looking into the setup of the specific service at the peripheral side, I can see the following:

// Add the Command Characteristic.
memset(&add_char_params, 0, sizeof(add_char_params));
add_char_params.uuid = BLE_UUID_XXX_CONTROL_COMMAND_CHAR;
add_char_params.uuid_type = p_xxx_control->uuid_type;
add_char_params.max_len = BLE_LEN_XXX_CONTROL_COMMAND_CHAR;
add_char_params.init_len = BLE_LEN_XXX_CONTROL_COMMAND_CHAR;
add_char_params.is_var_len = true;//false;
add_char_params.char_props.write = 1;
add_char_params.char_props.write_wo_resp = 0; // Disable write without response
add_char_params.is_defered_write = 1; // Enable write authentication

How do they above impact the central side of things? This is currently how I prepare and send the write request to the specific service from the central:

uint32_t ble_wh_control_c_send_BufferSizeCmd_WriteRequest(ble_wh_control_c_t * p_ble_wh_control_c, uint8_t * p_string, uint16_t length)
{
VERIFY_PARAM_NOT_NULL(p_ble_wh_control_c);

nrf_ble_gq_req_t write_req;

memset(&write_req, 0, sizeof(nrf_ble_gq_req_t));

if (length > BLE_WH_CONTROL_MAX_DATA_LEN)
{
NRF_LOG_WARNING("Content too long.");
return NRF_ERROR_INVALID_PARAM;
}
if (p_ble_wh_control_c->conn_handle == BLE_CONN_HANDLE_INVALID)
{
NRF_LOG_WARNING("Connection handle invalid.");
return NRF_ERROR_INVALID_STATE;
}

write_req.type = NRF_BLE_GQ_REQ_GATTC_WRITE;
write_req.error_handler.cb = gatt_error_handler;
write_req.error_handler.p_ctx = p_ble_wh_control_c;
write_req.params.gattc_write.handle = p_ble_wh_control_c->handles.control_cmd_req_handle;
write_req.params.gattc_write.len = length;
write_req.params.gattc_write.offset = 0;
write_req.params.gattc_write.p_value = p_string;
write_req.params.gattc_write.write_op = BLE_GATT_OP_WRITE_REQ;
write_req.params.gattc_write.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE;

return nrf_ble_gq_item_add(p_ble_wh_control_c->p_gatt_queue, &write_req, p_ble_wh_control_c->conn_handle);
}

I also see the following event handled at the peripheral side (when I use nRF Connect app and things work), is this a hint of me needed to do any additional handshake with the peripheral?

BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST

Can you please help? 

Regards

George

Parents Reply Children
No Data
Related