Reply to read request with sd_ble_gatts_rw_authorize_reply(...) with data greater than 20 bytes


This is my first time working on BLE and Nordic, so this might sound strange. I am trying to update data on the fly when the central requests char data.

I have been setting the is_defered_read bit in the char config so I get the event BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST and it works well.

I have then inserted code in on_rw_authorize_request() with something like:

else if (p_auth_req->type == BLE_GATTS_AUTHORIZE_TYPE_READ)
	NRF_LOG_INFO("Constructing configuration data");
	protobufFormatCB_t formatter = GetCfgServiceFormatter();
	uint8_t formatResult = 0;
	memset(data, 0, sizeof(data));
	size_t len = 0;
	if (p_parameter_service->conn_handle != BLE_CONN_HANDLE_INVALID)
		formatResult = formatter.cb(
					sizeof(data), &len);

	ble_gatts_rw_authorize_reply_params_t params;
	params.type = BLE_GATTS_AUTHORIZE_TYPE_READ; = formatResult
			: BLE_GATT_STATUS_ATTERR_UNLIKELY_ERROR; = 1; = p_auth_req->; = (int16_t)len;
	// = 20;	//Passed 20 bytes, receiving NRF_ERROR_INVALID_PARAM = data;

	uint32_t error_code = sd_ble_gatts_rw_authorize_reply(p_parameter_service->conn_handle, &params);
		NRF_LOG_ERROR("Error constructing data: %i", error_code);

It seems that whenever the lenght is greater than 20 bytes, sd_ble_gatts_rw_authorize_reply returns 7 (invalid params). This seems tied to the MTU somehow, but I haven't found where yet.

What is strange is that I am able the send the whole (110bytes) message via sd_ble_gatts_value_set(...) or sd_ble_gatts_hvx(...), but would rather compute it on the fly with the central request.

I'm sure this is an easy fix, please enlighten me.. :)