Search code examples
androidiosbluetooth-lowenergymtu

BLE 4.0/4.1 supporting data transfer of 64 bytes in Android


We have some android devices which have BT stack 4.0 and 4.1. As per theory, 4.0 and 4.1 support data transfer of only 23 (20 +3) bytes. While BT stack 4.2 and 5.0 support data transfer upto 251 bytes MTU.

But in our app, we requested MTU size of 64 bytes and its working fine. We are able to send and receive data of this size. We are able to send 500-700 packets continuously of 64 bytes.

Does any body has idea why it is working differently? or is it just a few android devices which are working this way?

We want to eliminate devices which won't support our application.


Solution

  • You are confused with the terms here. Per the spec all BLE versions since Bluetooth 4.0 have maximum possible MTU of 64 kilobyte, even though Android limits it to 517 for GATT.

    The new feature that was added in BLE 4.2 was the "LE Data Packet Length Extension" which is an enhancement of the Link Layer that increases the maximum packet length over the air from 27 bytes to 251 bytes that does not affect the host layer in any way. If the host sends a packet that is bigger than what the link layer can handle, it is automatically fragmented by the sender stack and reassembled at the receiver.

    So your Android app will work the same regardless of the link layer capabilities. The only concern you should have is whether the remote application supports your desired MTU of 64.

    UPDATE

    Bluetooth Core v4.0 specification Volume 6 Part B section 2.4:

    The LLID field has two different values for start and continuation fragment.

    10b = LL Data PDU: Start of an L2CAP message or a complete L2CAP message with no fragmentation.
    01b = LL Data PDU: Continuation fragment of an L2CAP message, or an Empty PDU.
    

    The feature of continuing an earlier packet is important when the host packet is larger than the link layer can handle (normally 27 or 251 bytes with LE Data Length Extension). That is how you can get an MTU of for example 517 when the packets over the air are never longer than 27 bytes.

    See Bluetooth Core specification Volume 3 Part A section 7.2 for more info about L2CAP fragmentation and recombination.