Fix l2cap segmentation error in concurrent subscription
We are having some issues when we subscribe to different characteristics in the same server and get data from them simultaneously, we are getting corrupted packages. After some research we discovered that the problem was in l2cap layer, segments were being mixed and this was causing reassembly inconsistencies. When l2cap layer needs to fragment the packets, it seems this layer does not support unordered segments. With this patch we ensure these segments are sent in order for each upper-layer's packet.
As an example, we need to send two packets of 135 bytes, so l2cap layer needs to fragment it in 5 segments of 27 bytes.
Packet 1 starts being sent, so l2cap layer starts sending segment 1,2,3
In the middle of that transmission, Packet 2 is requested to be sent, so its segments start being sent: 1,2,3, etc.
On the other side, we would receive something like (P1=Packet1, P2=Packet2):
P1.1, P1.2., P1.3, P2.1, P1.4 -> which is reassembled as Packet1 but it's not correct.
P1.5, P2.2, P2.3, P2.4, P2.5 -> which is reassembled as Packet1 but it's not correct.
With this patch we aim to solve this. See https://github.com/orca-io/gatt/pull/2/commits/edd7ec2591f2d47ce6112300313236a5bc426f66