Fast Reconnection Causes 13313 (0x3401) from sd_ble_gatts_hvx

When the nrf device momentarily disconnects from my app, and the app immediately reconnects, the sd_ble_gatts_hvx function returns an error 13313 (0x3401).

I understand that this means that system attributes are missing. As suggested elsewhere on the forum, I have

case BLE_GATTS_EVT_SYS_ATTR_MISSING:
err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0);
APP_ERROR_CHECK(err_code);
break

in my ble_evt handler, but that event never fires.

Instead, when the sd_ble_gatts_hvx fails with error 13313 I run:

ret = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);

This returns 0, however subsequent calls to sd_ble_gatts_hvx return 8 (invalid state).

In the original, valid, connection I observe:

  1. GATT write to attribue 16, length 2
  2. GATT write to attribute 13, length 1
  3. GATT write to attribute 13, length 20
  4. GATT read of attribute 13, length 1

After the reconnection, the connection id is that same number and I see only

  1. GATT read of attribute 13, length 1 

I think what is happening is that the app client expects the device to remember some parameters (I suppose the CCCD), but the device has erased that information.

I am not using bonding, just connecting to the device. This is for SDK 17.1.0 Softdevice S112. The application is using FlutterBluePlus to manage the connection.

I suspect that the solution is that the GATT handshake needs to be completed, but I'm not sure if that needs to be fixed on the device or the app.

Parents
  • I have this note which might be a guide:

    Secure pairing: Start by adding the relevant peer manger code to your main.c, with ble_app_hrs as reference. Remember to remove handling of the BLE_GAP_EVT_SEC_PARAMS_REQUEST and the BLE_GATTS_EVT_SYS_ATTR_MISSING event in the on_ble_evt() callback as these shall be handled internally by the peer manager.

    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        uint32_t err_code;
        ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;
        static int8_t rssi_value = 0;
    
        switch (p_ble_evt->header.evt_id)
        {
    //      case BLE_GATTS_EVT_SYS_ATTR_MISSING:           // 82 0x52 A persistent system attribute access is pending

Reply
  • I have this note which might be a guide:

    Secure pairing: Start by adding the relevant peer manger code to your main.c, with ble_app_hrs as reference. Remember to remove handling of the BLE_GAP_EVT_SEC_PARAMS_REQUEST and the BLE_GATTS_EVT_SYS_ATTR_MISSING event in the on_ble_evt() callback as these shall be handled internally by the peer manager.

    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        uint32_t err_code;
        ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;
        static int8_t rssi_value = 0;
    
        switch (p_ble_evt->header.evt_id)
        {
    //      case BLE_GATTS_EVT_SYS_ATTR_MISSING:           // 82 0x52 A persistent system attribute access is pending

Children
No Data
Related