Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BLE: Relationship between MTU and maximum characteristic size?

How do I find out the relationship between MTU and maximum characteristic size in Bluetooth Low Energy (BLE)?

I have a BLE developer board running an 'echo' program - so whatever it receives, it just immediately replies.

On my Android device, if I request an MTU of 247 bytes (which succeeds) and then write a 247-byte characteristic, it gets sent as two packets: one with 242 bytes and one with 5 bytes. Any attempt to write a characteristic with more than 244 bytes results in 2 packets - the first one with 242 bytes, the second one with the remaining bytes. Not sure why the first packet is 242 bytes long instead of 244, but there it is.

If, instead, I request a 100-byte MTU, the same kind of thing happens, but the packets get split when the characteristic is more than 97 bytes long, and the first packet is always 95 bytes long.

So it seems pretty clear that on this particular Android device, the maximum packet length is 3 bytes shorter than the MTU value. I've seen pages talking about MTU on the iOS where the packet length is 3 bytes shorter than the MTU value.

Am I guaranteed that the difference between MTU and maximum characteristic length will be 3 bytes, on all mobile devices and all BLE implementations?

like image 622
Betty Crokker Avatar asked Aug 07 '17 21:08

Betty Crokker


People also ask

What is the maximum MTU size for BLE?

Per the Bluetooth Core Specification, the maximum length of an attribute can be 512 bytes. In reality, it can be slightly larger than this to accommodate the ATT header. On Android, the maximum MTU can be 517 bytes.

How is BLE throughput measured?

For a link with a connection interval of 40 ms, max throughput will be 6 * 20 B * 1/(0.040 s) = 3 kB/s if your devices are capable of transferring six packet per interval and 1 * 20 B * 1/(0.040 s) = 0.5 kB/s if you transfer one packets per interval.

What is ATT MTU?

ATT Maximum Transmission Unit (MTU) is the maximum length of an ATT packet. The ATT MTU is defined by the L2CAP and can be anywhere between 23 and infinity. The implementation of the Bluetooth stack is the key factor of determining the ATT MTU on both client and peripheral.

What is connection interval in BLE?

For Android devices, the minimum connection interval is 7.5 milliseconds. The “Bluetooth Accessory Design Guidelines for Apple Products” does mention a minimum interval of 20ms, but this is not seen in practice.


1 Answers

Almost. The ATT header consists of one byte opcode and two bytes for the ATT handle. If you use the "Write Long Characteristic Values" there is also a two byte offset parameter. If you use the "Signed Write Without Response" procedure (which nobody uses and almost no stacks support) there is also a 12 byte signature.

Also note that the maximum characteristic length is 512 bytes. The maximum allowed MTU is however 65535 bytes. You can never write a characteristic value larger than 512 bytes, no matter how large your MTU is.

If you're interested in the low level details of the ATT protocol you can read the Bluetooth Core specification at https://www.bluetooth.com/specifications/bluetooth-core-specification, Vol 3 Part F.

like image 188
Emil Avatar answered Oct 14 '22 05:10

Emil