Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SDK14.1 Multilink with NUS data sent issue

I have refer to this topic for setup multilink with NUS. https://devzone.nordicsemi.com/f/nordic-q-a/18804/mismatch-between-connection-handles-in-ble_nus

But, i met a  wrong 'BLE_GATTC_EVT_HVX' event issue, below is the situation, i test with two peripheral and one central,

1.  Two peripherals connected with central

2.  Two peripherals disconnected with central a few minutes after step 1

3.  Then, if just one peripheral connect with central again, and this peripheral send data to central, then central will get BLE_GATTC_EVT_HVX event twice at each data transmission from the peripheral, that means central get two package data, the same package data twice. But the peripheral was just sent once package.

4. If the other peripheral connect again, this issue would be gone away, central will get the right BLE_GATTC_EVT_HVX event, and every data  transmission will be ok.

BTW, if only one peripheral connected with central after central power up, or two peripherals always connected with central after central power, it will be without this issue. But if anyone disconnected, this issue will be happened, until all peripherals connected, this issue will be gone...

 I don't  understand why SD triggered two BLE_GATTC_EVT_HVX event in this situation, hope Nordic engineer or someone can help on this issue.

Thanks a lot.

Parents
  • I got exactly the same problem with the SDK 15.3.0 and I think I found the root cause.

    It looks like there is a bug within the ble_nus_c.c at the ble_nus_c_on_ble_evt function. After a peripheral disconnects, its connection handle gets set to invalid (BLE_CONN_HANDLE_INVALID) but neither the on_hvx function nor ble_nus_c_on_ble_evt itself will discard events for an invalid connection handle. The on_hvx function only checks the TX characteristic's handle (p_ble_nus_c->handles.nus_tx_handle) for an invalid value.

    As far as I can tell this can be fixed by dropping events for ble_nus_c_t instances that got an invalid connection handle within the function ble_nus_c_on_ble_evt by replacing this code...

        if ( (p_ble_nus_c->conn_handle != BLE_CONN_HANDLE_INVALID)
           &&(p_ble_nus_c->conn_handle != p_ble_evt->evt.gap_evt.conn_handle)
           )
        {
            return;
        }

    ... with that code ...

        if ( (p_ble_nus_c->conn_handle == BLE_CONN_HANDLE_INVALID)
           ||(p_ble_nus_c->conn_handle != p_ble_evt->evt.gap_evt.conn_handle)
           )
        {
            return;
        }

    Furthermore I think that the characteristic's handles should also get invalidated during disconnect to prevent other parts of the code from thinking that a reused instances got already discovered:

                    p_ble_nus_c->handles.nus_tx_handle = BLE_GATT_HANDLE_INVALID;
                    p_ble_nus_c->handles.nus_rx_handle = BLE_GATT_HANDLE_INVALID;

    I attached the patch that I applied to my instance of then nRF5_SDK_15.3.0_59ac345:

    8203.0001-Drop-events-for-invalid-connection-handles.patch

    Can someone from Nordic check, if this is really a bug within the SDK and if so, that my fix is enough to solve the problem?

    BTW Is there an official GitHub repository for the SDK to submit pull requests?

Reply
  • I got exactly the same problem with the SDK 15.3.0 and I think I found the root cause.

    It looks like there is a bug within the ble_nus_c.c at the ble_nus_c_on_ble_evt function. After a peripheral disconnects, its connection handle gets set to invalid (BLE_CONN_HANDLE_INVALID) but neither the on_hvx function nor ble_nus_c_on_ble_evt itself will discard events for an invalid connection handle. The on_hvx function only checks the TX characteristic's handle (p_ble_nus_c->handles.nus_tx_handle) for an invalid value.

    As far as I can tell this can be fixed by dropping events for ble_nus_c_t instances that got an invalid connection handle within the function ble_nus_c_on_ble_evt by replacing this code...

        if ( (p_ble_nus_c->conn_handle != BLE_CONN_HANDLE_INVALID)
           &&(p_ble_nus_c->conn_handle != p_ble_evt->evt.gap_evt.conn_handle)
           )
        {
            return;
        }

    ... with that code ...

        if ( (p_ble_nus_c->conn_handle == BLE_CONN_HANDLE_INVALID)
           ||(p_ble_nus_c->conn_handle != p_ble_evt->evt.gap_evt.conn_handle)
           )
        {
            return;
        }

    Furthermore I think that the characteristic's handles should also get invalidated during disconnect to prevent other parts of the code from thinking that a reused instances got already discovered:

                    p_ble_nus_c->handles.nus_tx_handle = BLE_GATT_HANDLE_INVALID;
                    p_ble_nus_c->handles.nus_rx_handle = BLE_GATT_HANDLE_INVALID;

    I attached the patch that I applied to my instance of then nRF5_SDK_15.3.0_59ac345:

    8203.0001-Drop-events-for-invalid-connection-handles.patch

    Can someone from Nordic check, if this is really a bug within the SDK and if so, that my fix is enough to solve the problem?

    BTW Is there an official GitHub repository for the SDK to submit pull requests?

Children
Related