Android-nRF-Connect-Device-Manager icon indicating copy to clipboard operation
Android-nRF-Connect-Device-Manager copied to clipboard

Data length is negative (-9 bytes)

Open ball-hayden opened this issue 1 year ago • 2 comments

With the latest version (2.1.0) of the library, I'm seeing the following error:

java.lang.NegativeArraySizeException: Data length is negative (-9 bytes) (MTU = 62, CBOR overhead = 71, data length = 303236, offset = 0)

I feel like this should have been caught by some of the validations around MTU length, but that seems to be hard coded to a minimum of 20: https://github.com/NordicSemiconductor/Android-nRF-Connect-Device-Manager/blob/113121fa6166c826bf07917ce20aace95548e7fc/mcumgr-core/src/main/java/io/runtime/mcumgr/McuManager.java#L146

ball-hayden avatar Sep 23 '24 09:09 ball-hayden

This is reproducible by configuring the MCU to have a small max MTU.

ball-hayden avatar Sep 23 '24 09:09 ball-hayden

Hi, In version 2.1 instead of fixing it I added the values to the log for better undestanding.

As you see, the "CBOR overhead", which has to be sent in a single SMP packet, is bigger than MTU. Solutions:

  1. increase MTU
  2. Add support for McuMgrParams command and add buffering, so that one SMP command (header+CBOR) could be split into multiple BLE packets. Then, the MTU in the McuManager will be the total buffer size, not the ATT MTU from transport layer.

Without 2. it is not possible to send such a big packet. I admit, that crashing tha lib isn't the best way to notify the user :)

philips77 avatar Sep 23 '24 10:09 philips77

Yeah - this just wasn't particularly friendly.

I spent a while trying to work out why Android had failed to negotiate a higher MTU, before I realised by running the iOS version of the library (which provided a more helpful message) that the MCU's MTU was too small.

ball-hayden avatar Sep 24 '24 14:09 ball-hayden