[riot-notifications] [RIOT-OS/RIOT] pkg/nimble/netif: fix randomized conn intervals (#16601)

Hauke Petersen notifications at github.com
Thu Jul 1 10:07:21 CEST 2021


### Contribution description
This is a bug fix for the changes introduced in #16372.

It turns out, that once a node maintains multiple connections, its state can break after a GAP-slave node rejects a new incoming connection by closing it in the `GAP` event callback: 
- the master node opens a GAP connection
- the slave node triggers the `_on_gap_slave_evt` callback, Here it did check the connection interval and initiated a connection teardown if the iinterval was not spaced sufficiently
- in the mean time, the master node did not know about the connection teardown, yet, and creates the L2CAP channel
- this leads to the `_on_l2cap_server_evt()` event callback being triggered on the slave, despite the fact that it already triggered the connection to be closed
--> the slave node ends up with broken state and hangs

This PR fixes this behavior by checking the connection interval spacing only after the L2CAP channel was created. This keeps the slaves state consistent at all time.

Included in this fix is also a code optimization for `nimble_netif_conn`, where the connection interval is now simply buffered inside the `nimble_netif_conn_t` struct, saving significant lookup overhead and making the code better readable.

### Testing procedure
While building with `NIMBLE_NETIF_CONN_ITVL_SPACING >= 1`:
Build a network with at least 3 nodes, opening a BLE connection between two of them, and then connect a third node (as master) so that one of the other nodes is the connection slave. Close and reopen the latter connection until the new connection is rejected due to invalid connection spacing by the slave node. When repeating this multiple times, the slave node should not fail...

OR:

trust me that it works :-) Here is some evidence. I have been running multiple experiments including this fix with 15 IP over BLE 
nodes, encountering the above situation:

Here is one of these occurrences when node `nrf52dk-3` tries to connect to `nrf52dk-1` and the connection is rejected due to invalid connection interval spacing:
```
1625066387.467399;nrf52dk-3;[mc] INIT MASTER 0 nrf52dk-1
1625066388.270845;nrf52dk-1;[mc] INIT_SLAVE 2 nrf52dk-3
1625066388.275944;nrf52dk-1;netif: l2cap_slave_conn: itvl in use, closing now
1625066388.403657;nrf52dk-3;[mc] CONNECTED_MASTER 0 nrf52dk-1
1625066388.404199;nrf52dk-1;[mc] ABORT_SLAVE 2 nrf52dk-3
1625066388.420467;nrf52dk-3;[mc] CLOSED_MASTER 0 nrf52dk-1
```
At the same time I can veriify, that (a) the experiment finiished successful, without any node failing, and that (b) the connection interval spacing did function as expected:
```
Connection Interval Summary:
      nrf52dk-1 min spacing:  4 itvls:[65, 71, 75]
      nrf52dk-2 min spacing:  3 itvls:[60, 65, 68]
      nrf52dk-3 min spacing:  - itvls:[60]
      nrf52dk-4 min spacing:  - itvls:[77]
      nrf52dk-5 min spacing:  2 itvls:[65, 75, 77]
      nrf52dk-6 min spacing:  3 itvls:[65, 72, 75]
      nrf52dk-7 min spacing:  - itvls:[71]
      nrf52dk-8 min spacing:  - itvls:[60]
      nrf52dk-9 min spacing:  - itvls:[65]
     nrf52dk-10 min spacing:  - itvls:[68]
   nrf52840dk-6 min spacing:  - itvls:[63]
   nrf52840dk-7 min spacing:  2 itvls:[61, 63, 72]
   nrf52840dk-8 min spacing: 10 itvls:[61, 71]
   nrf52840dk-9 min spacing:  5 itvls:[60, 65, 75]
  nrf52840dk-10 min spacing:  - itvls:[71]
```

### Issues/PRs references
Fixes a bug introduces with #16372

You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/16601

-- Commit Summary --

  * pkg/nimble/netif: fix randomized conn intervals

-- File Changes --

    M pkg/nimble/netif/include/nimble_netif_conn.h (16)
    M pkg/nimble/netif/nimble_netif.c (37)
    M pkg/nimble/netif/nimble_netif_conn.c (42)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/16601.patch
https://github.com/RIOT-OS/RIOT/pull/16601.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/16601
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210701/6dd81e15/attachment.htm>


More information about the notifications mailing list