Updating data length on peripheral/server side

Hello,

I have followed 2.2 from this blog post to try and get my application to update its data length and MTU size when connecting to the nRF Connect for Mobile app. It's not clear from the blog post when to call the 'request_...' functions, but I implemented it such that request_data_len_update is called at the end of my on_connected() callback and request_mtu_exchange is called if the data length update was successful. I made sure to set the same configurations.

However, when I do connect, I see in my debug log "bt_hci_core: bt_hci_cmd_send_sync: opcode 0x2022 status 0x12" and 

bt_conn_le_data_len_update returns -EIO (-5). 
From this Q&A I found that the opcodes and status codes should be defined in the Bluetooth Spec, so I set out to try and find what was going on, I'll summarize it here in case someone else might find it useful.
From Vol 4, Part E, 5.4.1 it seems that HCI Command packet opcodes are a combination of a 6 bit Opcode Group Field (OGF) and a 10 bit Opcode Command Field (OCF).
From Vol 4, Part E, 7.8 it became clear that LE Controller commands have an OGF of 0x08 so the OCF would be 0x0022 which matches HCI_LE_Set_Data_Length, as expected from the thing I'm trying to achieve.
The status code 0x12 seems to indicate Invalid HCI Command Parameters.
So now I'm wondering, why are these invalidate parameters? Did I forget something in the configurations, or is trying to update the Data Length not possible in the on_connected callback and should it take place at a different moment?
  • Hi,

    Can you say more about which device you are using, how you are testing (perhaps show the code and configs) and which nRF Connect SDK version you are using?

  • Hi Einar,

    I am using nRF Connect SDK 2.5.0 on a custom board with a nRF52840-QFAA

    These are my relevant configurations

    custom board defconfig

    prj.conf

    I created a ble.c file to take care of all BLE related activity

    The call to update_phy is commented out for now because I'm testing with the app on my phone which doesn't seem to support the coded PHY, but I intend to eventually connect to another device which does have a Nordic processor that will allow coded PHY as well.

    Hope this helps to clear things up.

  • Hi,

    I see you call bt_conn_le_data_len_update() like this, which I assume you got a warning about when building?

    CONFIG_BT_CTLR_DATA_LENGTH_MAX is a number, and you are supposed to pass a struct (bt_conn_le_data_len_param). So it is expected that this fails. You can build the struct using BT_CONN_LE_DATA_LEN_PARAM.

  • Hi Einar,

    Thanks! Seems like I was going too quickly. There was indeed a build warning, seems like I overlooked that. And seems like I misread the blogpost and wrote the wrong macro as parameter for bt_conn_le_data_len_update.

    Works beautifully now!