Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Write over QWR max length causes error

Firstly, I have the following definitions in sdk_config.h and when declaring the qwr buffers:

#ifndef NRF_SDH_BLE_GATT_MAX_MTU_SIZE
#ifndef TR_SLU_CONFIG_MAX_MSG_LEN
#define TR_SLU_CONFIG_MAX_MSG_LEN 240
#endif

#if TR_SLU_CONFIG_MAX_MSG_LEN > (251-5)
#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 251
#else
#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE TR_SLU_CONFIG_MAX_MSG_LEN + 5
#endif
#endif

#ifndef NRF_SDH_BLE_GAP_DATA_LENGTH
#if NRF_SDH_BLE_GATT_MAX_MTU_SIZE < 251
#define NRF_SDH_BLE_GAP_DATA_LENGTH NRF_SDH_BLE_GATT_MAX_MTU_SIZE
#else
#define NRF_SDH_BLE_GAP_DATA_LENGTH 251
#endif
#endif

#define PREPARE_WRITE_REQUEST_OVERHEAD 5
#define MIN_DATA_LENGTH 20
#define MAX_NUM_PREPARE_WRITE_REQS (TR_SLU_CONFIG_MAX_MSG_LEN / MIN_DATA_LENGTH)
#define QWR_MEM_BUFF_SIZE TR_SLU_CONFIG_MAX_MSG_LEN + (PREPARE_WRITE_REQUEST_OVERHEAD * MAX_NUM_PREPARE_WRITE_REQS)
static uint8_t qwr_buffers[NRF_SDH_BLE_TOTAL_LINK_COUNT][QWR_MEM_BUFF_SIZE];

Note that in the above, the intention is that TR_SLU_CONFIG_MAX_LENGTH could be modified to be larger (e.g. 600) without modifying the other definitions.

I am not sure if these are correct as I couldn't find detailed documentation on these configurations, i.e. what is the maximum possible value of NRF_SDH_BLE_GATT_MAX_MTU_SIZE? What is the relationship between NRF_SDH_BLE_GATT_MAX_MTU_SIZE and NRF_SDH_BLE_GAP_DATA_LENGTH? Does NRF_SDH_BLE_GAP_DATA_LENGTH have to be less than NRF_SDH_BLE_GATT_MAX_MTU_SIZE? Is there any overhead that should be considered between NRF_SDH_BLE_GAP_DATA_LENGTH and NRF_SDH_BLE_GATT_MAX_MTU_SIZE? Is the overhead of 5 bytes used here correct for QWR packets? Perhaps you could help me with these questions.

With the above configuration, if I write a packet that is larger than the QWR buffer e.g. 1kb from my iPhone to the QWR characteristic, I get an error code of 8 (NRF_ERROR_INVALID_STATE) when the qwr library sends a response to the write request:

I can see from a packet log that the softdevice has already responded with 0x09 Prepare Queue Full, so this error must be because the QWR library is attempting to respond again - why? Is there any way to avoid this issue or should I just ignore NRF_ERROR_INVALID_STATE errors from the QWR library?

Related