Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Is this a bug in the nrf_ble_gatt in SDK 16 ?

Hi,

I found some thing not seems to be right in SDK 16.  I wonder if this is intentional or a bug.  Bluetooth 5 max MTU can be up to 512 bytes.  I found the definitions in the structures bellow that MTU size is uint16_t but data length is uint8_t.  This seems not rights also nrf_ble_gatt sets a hardcoded max data length to 251.  Which is Bluetooth 4.2 max data length.  That too is bad.  So how did the Bluetooth 5 throughput test demo able to set data length to 512 bytes when it is hard coded in nrf_ble_gatt to 251 ?  

Data length defined as uint8_t in nrf_ble_gatt.h which is max at 255.  So cannot use 512 bytes of Bluetooth 5.

Data length is hardcoded inside nrf_ble_gatt.c

Parents
  • Hi,

    The data length is referring to the LL packet length sent on air which actually can be smaller than the size of the MTU. An ATT packet will be split into multiple radio packets in that case. This is explained a bit more in the SDK documentation here: GATT Module. The "Bluetooth Low Energy data throughput" chapter of the SDS may also be interesting to read if you are looking to increase the transfer speed.

Reply
  • Hi,

    The data length is referring to the LL packet length sent on air which actually can be smaller than the size of the MTU. An ATT packet will be split into multiple radio packets in that case. This is explained a bit more in the SDK documentation here: GATT Module. The "Bluetooth Low Energy data throughput" chapter of the SDS may also be interesting to read if you are looking to increase the transfer speed.

Children
  • I understand that the data length can be smaller than MTU.  The question is that this is supposed to be Bluetooth 5 compatible therefore the length could be up to 512 bytes.  The nrf_ble_gatt hardcoded a limit of 251 of Bluetooth 4.2, so an uint8_t is sufficient but 512 will not and cause length corruption.  Is this a bug and should be changed to uint16_t instead ?  

  • The length value will not overflow with the current implementation because neither the RADIO or Softdevice support data lengths above 251. Also, the max. length is 251 bytes according to the table in core spec 5, vol 6, part b, section 4.5.10

  • oh, thanks for the explanation.  That's weird sd_ble_gap_data_length_update takes data length parameter as uint16_t. 

  • I haven't noticed that the SD API used uin16_t. Maybe it would have made more sense to keep the same data type in the GATT module as well. I guess it was done to make it more clear what the actual range is. Anyway, the Softdevice will return an error if you try to enable it with data lenght support above 251. 

  • Got ya! thanks.  I was confused about the fact that the data length was hardcoded at 251. Now I know where that comes from.  I would make the define in the .h so the firmware can validate forehand instead of let the SDK causing an assert. and with a comment as the reason why.