This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Maximum ATT MTU for BLE NUS

Hi,

What is the maximum ATT MTU size for the BLE NUS?

While programming my BLE NUS server application I constantly ran into the problem that my MTU and length updates cause NRF_ERROR_INVALID_PARAM errors. I solved it by setting the MTU size for my connection configuration (ble_cfg_t.conn_cfg.params.gatt_conn_cfg.att_mtu) and the next established connection (nrf_ble_gatt_att_mtu_periph_set()) to 248 (found by trial-and-error and only working in that particular case...).

Where does this magical number come from? Does this mean my max. transmittable data length is 245 (ATT_MTU - OPCODE_LENGTH - HANDLE_LENGTH)?

I also found some information in the specification of another SoftDevice stack (S132, I think...) saying something about a GATT server ATT MTU with the value 247... Is it connected somehow? If yes - why 247?

Environment

  • nRF52 (nRF52840)
  • SDK 13 (13.1.0)
  • SoftDevice S140 (5.0.0-2.alpha)
  • 247 was probably used since this is the maximum packet length of 255 - headers - 1byte because of some old issue(254 max length). 248 should be fine with the nRF52840. In fact the ATT MTU size is not really depending on the Packet size. It is possible to have longer att mtu's than the maximum pdu size.

  • I figured it out a while ago and want to share...
    (I stick to Bluetooth 5 BLE and uncoded PHY - just in case it matters.)

    • Maximum PDU size = 257 bytes
          [BLUETOOTH SPECIFICATION Version 5.0 | Vol 6, Part B | 2.1 PACKET FORMAT FOR THE LE UNCODED PHYS]
    • Data channel PDU header = 2 bytes
      Data channel PDU MIC (Message Integrity Check) = 4 bytes
          [BLUETOOTH SPECIFICATION Version 5.0 | Vol 6, Part B | 2.4 DATA CHANNEL PDU]
    • Basic L2CAP PDU header = 4 bytes
          [BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part A | 3 DATA PACKET FORMAT]

    Using this we get a max. MTU of 257-2-4-4 = 247 bytes.

    For the NUS this results in an max. transmittable data size of 244 bytes (3 bytes NUS header: see `BLE_NUS_MAX_DATA_LEN` inside `ble_nus.h` or `ble_nus_c.h`).

Related