BLE_I2C connection counter issue

Hello,

we are using L2CAP CoC and thus, the ble_l2c module, for ASHA streaming in the central role. When the central requests the L2CAP channel and the peripheral accepts the request, the central does not receive the L2CC_LECB_CONNECT_REQ_IND event. Instead the L2CC_LECB_CONNECT_IND event is generated, but the l2c_env.connectionCount is not incremented in ble_l2c. This cause a hard fault, when the L2CAP channel is closed, as the l2c_env.connectionCount is decremented (wrap around occurs, since the counter is zero).
We have fixed this issue by incremented the l2c_env.connectionCount in the L2CC_MsgHandler for L2CC_LECB_CONNECT_IND as follows:

 case L2CC_LECB_CONNECT_IND:
    {
        const struct l2cc_lecb_connect_ind* ind = param;
        for (uint16_t i = 0; i < l2c_env.connectionCount; i++)
        {
            if((ind->le_psm == l2c_env.connectionInfo[i].le_psm) &&
               (ind->peer_cid == l2c_env.connectionInfo[i].peer_cid))
            {
                l2c_env.connectionInfo[i].local_cid = ind->local_cid;
                break;
            }
        }
    	**l2c_env.connectionCount++;**
    }
    break;

Do you agree with this fix? Or is there anything else, that we have to be aware of?
Does this also work, when in peripheral role?

Thanks in advance
cheers Markus.

1 Like

@markus.jellitsch

As can bee seen in our L2C Documentation, the β€˜β€™ L2CC_LECB_CONNECT_IND ’ and the β€˜β€™ L2CC_LECB_DISCONNECT_IND ’ are the safest places to keep track of the connection count by incrementing and decrementing the counter. That is, if a β€˜β€™ L2CC_LECB_CONNECT_IND ’ is received then a β€˜β€™ L2CC_LECB_DISCONNECT_IND ’ will always also be received after disconnect, preventing the negative counter. This can be verified using the screenshots from the documentation below.

Knowing this, I believe that your implementation using the β€˜β€™ L2CC_LECB_CONNECT_IND ’ & β€˜β€™ L2CC_LECB_DISCONNECT_IND ’ will always keep track of the connection count as expected.

Thank you for using our community forum!

@martin.bela The implementation of @markus.jellitsch does not use L2CC_LECB_DISCONNECT_IND as you point out; it uses L2CC_LECB_CONNECT_REQ_IND and L2CC_LECB_CONNECT_IND.

As far as I understand, this is a fix of Onsemi’s SDK, are you planing to fix this in the next release?

@martin.bela thank you for the answer.

The L2CC_LECB_DISCONNECT_IND decrements the counter in ble_l2c.c (SDK with Pack Revision 3.4.0.154).
However, the counter is only incremented when L2CC_LECB_CONNECT_REQ_IND is received, which would not work in central role as modeled in the L2CAP sequence chart. Furthermore, we observed, that the peripheral does not receive L2CC_LECB_CONNECT_IND (only L2CC_LECB_CONNECT_REQ_IND).

In my opinion, the OnSemi implementation for the connection counter is faulty, as it does not incorporate both GAP roles. The module crashes, when the counter is decremented in L2CC_LECB_DISCONNECT_IND event in central role.

Do you agree?
Will you fix this in the next SDK release?

@markus.jellitsch
We are currently in discussion with our internal design team to try and work on a fix for this issue.

We likely cannot include this fix in our next release, but we will apply the fix in any releases that follow.

We will also post any updates on the fix as a response to this topic to keep everyone up to date.

Thank you for using our community forum!

1 Like