Wrong data received for BLE char

Hi,

I am writing to a characteristic, and I have noticed that the data is being truncated.

After establishing the connection, I performed an MTU exchange, and the MTU is set to 100. On the peripheral (server) side, I have defined the MTU as:

#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 110

Additionally, I am setting the MTU as follows:

static void gatt_init(void)
{
ret_code_t err_code = nrf_ble_gatt_init(&m_gatt, NULL);
APP_ERROR_CHECK(err_code);

err_code = nrf_ble_gatt_att_mtu_periph_set(&m_gatt, NRF_SDH_BLE_GATT_MAX_MTU_SIZE);
APP_ERROR_CHECK(err_code);
}

The write operation works perfectly when the data length is around 19 bytes. However, when writing larger data, the actual data seems to get stripped after the 24th byte.

Here's a snippet of my code:

ble_gatts_rw_authorize_reply_params_t response;
memset(&response, 0, sizeof(response));

response.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS;
response.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
response.params.write.update = 1;
response.params.write.offset = 0;
response.params.write.len = BleEvt.evt.gatts_evt.params.authorize_request.request.write.len;
response.params.write.p_data = BleEvt.evt.gatts_evt.params.authorize_request.request.write.data;

In this code, the length matches what I am sending (I am sending 36 bytes and "BleEvt.evt.gatts_evt.params.authorize_request.request.write.len" is 36 bytes but complete data is not present), but the data gets stripped off after the 24th byte. On the Central+client side, I am using nrf connect SDK and I have confirmed the MTU after the connection and it is 100. I used bt_att_get_mtu(Conn) to confirm the MTU after the cinenction and exchange of the MTU.

Characteristic is initialized as given below:


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

add_char_params.uuid = CUSTOM_CHAR_UUID;
add_char_params.uuid_type = 1;

add_char_params.max_len = MAX_CUSTOM_LEN; //50 bytes
add_char_params.is_var_len = true;
add_char_params.char_props.notify = 0;
add_char_params.char_props.write = 1;
add_char_params.cccd_write_access = SEC_OPEN;
add_char_params.write_access = SEC_OPEN;
add_char_params.is_defered_write = 1;

err_code = characteristic_add(p_BleCustom->dc_service_handles, &add_char_params, &(p_BleCustom->Custom_CharHandle));

Could you help me understand what might be causing this issue? I am using nrf5 sdk on the peripheral+server side.


 

Related