From 0032fa8580bdd717e57d1f871af9a7a95fde5505 Mon Sep 17 00:00:00 2001 From: Olivier Lesage Date: Sun, 13 Jul 2025 22:18:28 +0200 Subject: [PATCH 1/5] [nrf noup] bluetooth: mesh: replace bt_hci_cmd_create with bt_hci_cmd_alloc bt_hci_cmd_create will be deprecated. Signed-off-by: Olivier Lesage --- subsys/bluetooth/mesh/adv_ext.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 537cdacf924..c74f0a40d99 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -158,7 +158,7 @@ static int set_adv_randomness(uint8_t handle, int rand_us) struct net_buf *buf; sdc_hci_cmd_vs_set_adv_randomness_t *cmd_params; - buf = bt_hci_cmd_create(SDC_HCI_OPCODE_CMD_VS_SET_ADV_RANDOMNESS, sizeof(*cmd_params)); + buf = bt_hci_cmd_alloc(K_FOREVER); if (!buf) { LOG_ERR("Could not allocate command buffer"); return -ENOMEM; From 082d442fd20fc80704ee6f70cd261578311c537d Mon Sep 17 00:00:00 2001 From: Nirav Agrawal Date: Fri, 6 Jun 2025 10:30:11 +0530 Subject: [PATCH 2/5] [nrf fromtree] drivers: bluetooth: add BT-CAL data load for NXP IW612/IW416 SoC - Add support for default Annex-55 Bluetooth calibration data load for both IW612 and IW416 SoC. - Add support for default Annex-100 Bluetooth calibration data load for both IW612 and IW416 SoC. Signed-off-by: Nirav Agrawal (cherry picked from commit ffe8daa767b876a3d5a8c86352c6924aa48162d9) --- drivers/bluetooth/hci/Kconfig.nxp | 8 +- drivers/bluetooth/hci/hci_nxp_setup.c | 216 +++++++++++++++++++++++++- 2 files changed, 217 insertions(+), 7 deletions(-) diff --git a/drivers/bluetooth/hci/Kconfig.nxp b/drivers/bluetooth/hci/Kconfig.nxp index 1f6983ee989..9fb0850fa8e 100644 --- a/drivers/bluetooth/hci/Kconfig.nxp +++ b/drivers/bluetooth/hci/Kconfig.nxp @@ -13,14 +13,14 @@ config HCI_NXP_ENABLE_AUTO_SLEEP message to the Controller as the Host will need to wake it up. config HCI_NXP_SET_CAL_DATA - bool "BLE Controller calibration data" + bool "Bluetooth Controller calibration data" help - If enabled, the Host will send calibration data to the BLE Controller during HCI init. + If enabled, the Host will send calibration data to the Bluetooth Controller during HCI init. config HCI_NXP_SET_CAL_DATA_ANNEX100 - bool "BLE Controller calibration data annex 100" + bool "Bluetooth Controller calibration data annex 100" help - If enabled, the Host will send calibration data annex 100 to the BLE Controller during HCI + If enabled, the Host will send calibration data annex 100 to the Bluetooth Controller during HCI init. config HCI_NXP_RX_THREAD diff --git a/drivers/bluetooth/hci/hci_nxp_setup.c b/drivers/bluetooth/hci/hci_nxp_setup.c index 6fa34d0a24e..a217ffc53bd 100644 --- a/drivers/bluetooth/hci/hci_nxp_setup.c +++ b/drivers/bluetooth/hci/hci_nxp_setup.c @@ -29,13 +29,25 @@ LOG_MODULE_REGISTER(bt_nxp_ctlr); #define DT_DRV_COMPAT nxp_bt_hci_uart -#define FW_UPLOAD_CHANGE_TIMEOUT_RETRY_COUNT 6 +#define FW_UPLOAD_CHANGE_TIMEOUT_RETRY_COUNT 6 +#define HCI_CMD_STORE_BT_CAL_DATA_ANNEX100_OCF 0xFF +#define HCI_CMD_STORE_BT_CAL_DATA_PARAM_ANNEX100_LENGTH 16 +#define HCI_CMD_STORE_BT_CAL_DATA_OCF 0x61 +#define HCI_CMD_STORE_BT_CAL_DATA_PARAM_LENGTH 32 extern const unsigned char *bt_fw_bin; extern const unsigned int bt_fw_bin_len; static const struct device *uart_dev = DEVICE_DT_GET(DT_INST_GPARENT(0)); +#if !defined(CONFIG_HCI_NXP_SET_CAL_DATA) +#define bt_nxp_set_calibration_data_annex55() 0 +#endif + +#if !defined(CONFIG_HCI_NXP_SET_CAL_DATA_ANNEX100) +#define bt_nxp_set_calibration_data_annex100() 0 +#endif + #if DT_NODE_HAS_PROP(DT_DRV_INST(0), sdio_reset_gpios) struct gpio_dt_spec sdio_reset = GPIO_DT_SPEC_GET(DT_DRV_INST(0), sdio_reset_gpios); #endif /* DT_NODE_HAS_PROP(DT_DRV_INST(0), sdio_reset_gpios) */ @@ -1171,6 +1183,189 @@ static int bt_nxp_ctlr_init(void) return 0; } +#if defined(CONFIG_HCI_NXP_SET_CAL_DATA) + +static int bt_nxp_set_calibration_data_annex55(void) +{ + int ret = 0; + uint16_t opcode = BT_OP(BT_OGF_VS, HCI_CMD_STORE_BT_CAL_DATA_OCF); + + const uint8_t hci_cal_data_annex55[HCI_CMD_STORE_BT_CAL_DATA_PARAM_LENGTH] = { +#if defined(CONFIG_BT_NXP_NW612) + 0x00, /* Sequence Number : 0x00 */ + 0x01, /* Action : 0x01 */ + 0x01, /* Type : Not use CheckSum */ + 0x1C, /* File Length : 0x1C */ + 0x37, /* BT Annex Type : BT CFG */ + 0x33, /* Checksum : 0x71 */ + 0x1C, /* Annex Length LSB: 0x001C */ + 0x00, /* Annex Length MSB: 0x001C */ + 0x00, /* Pointer For Next Annex[0] : 0x00000000 */ + 0x00, /* Pointer For Next Annex[1] : 0x00000000 */ + 0x00, /* Pointer For Next Annex[2] : 0x00000000 */ + 0x00, /* Pointer For Next Annex[3] : 0x00000000 */ + 0x01, /* Annex Version : 0x01 */ + 0x81, /* External Xtal Calibration Value : 0x7d */ + 0x0D, /* Initial TX Power : 13 */ + 0x07, /* Front End Loss : 0x07 */ + 0x28, /* BT Options : */ + /* BIT[0] Force Class 2 operation = 0 */ + /* BIT[1] Disable Pwr-ctrl for class 2=0 */ + /* BIT[2] MiscFlg(to indicate ext.XTAL)=0 */ + /* BIT[3] Used Internal Sleep Clock = 1 */ + /* BIT[4] BT AOA location support = 0 */ + /* BIT[5] Force Class 1 mode = 1 */ + /* BIT[7:6] Reserved */ + 0x00, /* AOANumberOfAntennas: 0x00 */ + 0x00, /* RSSI Golden Low : 0 */ + 0x00, /* RSSI Golden High : 0 */ + 0xC0, /* UART Baud Rate[0] : 0x002DC6C0(3000000) */ + 0xC6, /* UART Baud Rate[1] : 0x002DC6C0(3000000) */ + 0x2D, /* UART Baud Rate[2] : 0x002DC6C0(3000000) */ + 0x00, /* UART Baud Rate[3] : 0x002DC6C0(3000000) */ + 0x00, /* BdAddress[0] : 0x000000000000 */ + 0x00, /* BdAddress[1] : 0x000000000000 */ + 0x00, /* BdAddress[2] : 0x000000000000 */ + 0x00, /* BdAddress[3] : 0x000000000000 */ + 0x00, /* BdAddress[4] : 0x000000000000 */ + 0x00, /* BdAddress[5] : 0x000000000000 */ + 0xF0, /* Encr_Key_Len[3:0]: MinEncrKeyLen = 0x0 */ + /* ExEncrKeyLen = 0xF */ + 0x00, /* RegionCode : 0x00 */ +#elif defined(CONFIG_BT_NXP_IW416) + 0x00, /* Sequence Number : 0x00 */ + 0x01, /* Action : 0x01 */ + 0x01, /* Type : Not use CheckSum */ + 0x1C, /* File Length : 0x1C */ + 0x37, /* BT Annex Type : BT CFG */ + 0x33, /* Checksum : 0x71 */ + 0x1C, /* Annex Length LSB: 0x001C */ + 0x00, /* Annex Length MSB: 0x001C */ + 0x00, /* Pointer For Next Annex[0] : 0x00000000 */ + 0x00, /* Pointer For Next Annex[1] : 0x00000000 */ + 0x00, /* Pointer For Next Annex[2] : 0x00000000 */ + 0x00, /* Pointer For Next Annex[3] : 0x00000000 */ + 0x01, /* Annex Version : 0x01 */ + 0x00, /* External Xtal Calibration Value */ + 0x03, /* Initial TX Power : 0x03 */ + 0x03, /* Front End Loss : 0x03 */ + 0x00, /* BT Options : */ + /* BIT[0] Force Class 2 operation = 0 */ + /* BIT[1] Disable Pwr Ctrl for class 2=0 */ + /* BIT[2] MiscFlg(to indicate ext.XTAL)=0 */ + /* BIT[3] Used Internal Sleep Clock = 0 */ + /* BIT[4] BT AOA localtion support = 0 */ + /* BIT[5] Force Class 1 mode = 0 */ + /* BIT[7:6] Reserved */ + 0x00, /* AOANumberOfAntennas: 0x00 */ + 0xBA, /* RSSI Golden Low : 0 */ + 0xCE, /* RSSI Golden High : 0 */ + 0xC0, /* UART Baud Rate[0] : 0x002DC6C0(3000000) */ + 0xC6, /* UART Baud Rate[1] : 0x002DC6C0(3000000) */ + 0x2D, /* UART Baud Rate[2] : 0x002DC6C0(3000000) */ + 0x00, /* UART Baud Rate[3] : 0x002DC6C0(3000000) */ + 0x00, /* BdAddress[0] : 0x000000000000 */ + 0x00, /* BdAddress[1] : 0x000000000000 */ + 0x00, /* BdAddress[2] : 0x000000000000 */ + 0x00, /* BdAddress[3] : 0x000000000000 */ + 0x00, /* BdAddress[4] : 0x000000000000 */ + 0x00, /* BdAddress[5] : 0x000000000000 */ + 0xF0, /* Encr_Key_Len[3:0]: MinEncrKeyLen = 0x0 */ + /* ExEncrKeyLen = 0xF */ + 0x00, /* RegionCode : 0x00 */ +#else +#error "BT Calibration data (annex-55) is not given for selected chipset" +#endif + }; + + if (IS_ENABLED(CONFIG_BT_HCI_HOST)) { + struct net_buf *buf; + + buf = bt_hci_cmd_create(opcode, HCI_CMD_STORE_BT_CAL_DATA_PARAM_LENGTH); + if (buf == NULL) { + LOG_ERR("Unable to allocate command buffer"); + return -ENOMEM; + } + + net_buf_add_mem(buf, hci_cal_data_annex55, HCI_CMD_STORE_BT_CAL_DATA_PARAM_LENGTH); + + ret = bt_hci_cmd_send_sync(opcode, buf, NULL); + if (ret) { + LOG_ERR("Failed to send set-calibration cmd (err %d)", ret); + return ret; + } + + (void)k_msleep(CONFIG_BT_H4_NXP_CTLR_WAIT_TIME_AFTER_BAUDRATE_UPDATE); + } + + return ret; +} +#endif /*CONFIG_HCI_NXP_SET_CAL_DATA*/ + +#if defined(CONFIG_HCI_NXP_SET_CAL_DATA_ANNEX100) + +static int bt_nxp_set_calibration_data_annex100(void) +{ + int ret = 0; + const uint8_t hci_cal_data_annex100[HCI_CMD_STORE_BT_CAL_DATA_PARAM_ANNEX100_LENGTH] = { +#if defined(CONFIG_BT_NXP_NW612) + 0x64, /* Annex Type : 0x64 */ + 0x83, /* Checksum */ + 0x10, 0x00, /* Length */ + 0x00, 0x00, 0x00, 0x00, /* Pointer for next Annex-Structure */ + 0x01, /* Ext PA Present (1 bit) + */ + /* Ext. PA Gain (7 bits) */ + 0x00, /* Ext Antenna Gain(1 bit) + */ + /* Ext. Antenna Gain Val(4 bits) */ + 0x04, 0x00, /* BT / LE Ext PA FEM CTRL Bitmask */ + 0x01, /* Ext LNA Present (1 bit) + */ + /* Ext LNA Gain (7 bits) */ + 0x00, /* Reserved */ + 0x04, 0x00 /* BT / LE Ext LNA FEM CTRL Bitmask */ +#elif defined(CONFIG_BT_NXP_IW416) + 0x64, /* Annex Type : 0x64 */ + 0x83, /* Checksum */ + 0x10, 0x00, /* Length */ + 0x00, 0x00, 0x00, 0x00, /* Pointer for next Annex-Structure */ + 0x01, /* Ext PA Present (1 bit) + */ + /* Ext. PA Gain (7 bits) */ + 0x00, /* Ext Antenna Gain(1 bit) + */ + /* Ext. Antenna Gain Val (4 bits) */ + 0x0C, 0x00, /* BT / LE Ext PA FEM CTRL Bitmask */ + 0x01, /* Ext LNA Present (1 bit) + */ + /* Ext LNA Gain (7 bits) */ + 0x00, /* Reserved */ + 0x0C, 0x00 /* BT/LE Ext LNA FEM CTRL Bitmask */ +#else +#error "BT Calibration data (annex-100) is not given for selected chipset" +#endif + }; + + uint16_t opcode = BT_OP(BT_OGF_VS, HCI_CMD_STORE_BT_CAL_DATA_ANNEX100_OCF); + + if (IS_ENABLED(CONFIG_BT_HCI_HOST)) { + struct net_buf *buf; + + buf = bt_hci_cmd_create(opcode, HCI_CMD_STORE_BT_CAL_DATA_PARAM_ANNEX100_LENGTH); + if (buf == NULL) { + LOG_ERR("Unable to allocate command buffer"); + return -ENOMEM; + } + + net_buf_add_mem(buf, hci_cal_data_annex100, + HCI_CMD_STORE_BT_CAL_DATA_PARAM_ANNEX100_LENGTH); + + ret = bt_hci_cmd_send_sync(opcode, buf, NULL); + if (ret) { + LOG_ERR("Failed to send set-calibration cmd (err %d)", ret); + return ret; + } + } + + return ret; +} +#endif /* defined(CONFIG_HCI_NXP_SET_CAL_DATA_ANNEX100) */ + int bt_hci_transport_setup(const struct device *dev) { int ret = 0; @@ -1231,6 +1426,7 @@ int bt_h4_vnd_setup(const struct device *dev) flowcontrol_of_hci = (bool)DT_PROP_OR(DT_DRV_INST(0), hw_flow_control, false); if (operation_speed == default_speed) { + fw_upload.is_setup_done = true; return 0; } @@ -1240,7 +1436,7 @@ int bt_h4_vnd_setup(const struct device *dev) return err; } - /* BT waiting time after controller bandrate updated */ + /* BT waiting time after controller bandrate updated */ (void)k_msleep(CONFIG_BT_H4_NXP_CTLR_WAIT_TIME_AFTER_BAUDRATE_UPDATE); } @@ -1250,7 +1446,21 @@ int bt_h4_vnd_setup(const struct device *dev) return err; } - fw_upload.is_setup_done = true; + if (!fw_upload.is_setup_done) { + err = bt_nxp_set_calibration_data_annex55(); + if (err) { + LOG_ERR("Fail to load annex-55 calibration data"); + return err; + } + + err = bt_nxp_set_calibration_data_annex100(); + if (err) { + LOG_ERR("Fail to load annex-100 calibration data"); + return err; + } + + fw_upload.is_setup_done = true; + } return 0; } From 8f63985860c8fcfc64d4470eb1fbea0f98ab40b8 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 19 Jun 2025 04:08:29 +0300 Subject: [PATCH 3/5] [nrf fromtree] Bluetooth: drivers: Use bt_hci_cmd_alloc() Use bt_hci_cmd_alloc() instead of the soon to be deprecated bt_hci_cmd_create(). Signed-off-by: Johan Hedberg (cherry picked from commit c186a3110c01c5bd3ad4cc0721f0e579298a4c21) --- drivers/bluetooth/hci/apollox_blue.c | 3 +-- drivers/bluetooth/hci/h4_ifx_cyw43xxx.c | 5 ++--- drivers/bluetooth/hci/hci_ifx_cyw208xx.c | 6 +++--- drivers/bluetooth/hci/hci_ifx_psoc6_bless.c | 2 +- drivers/bluetooth/hci/hci_nxp.c | 2 +- drivers/bluetooth/hci/hci_nxp_setup.c | 7 +++---- drivers/bluetooth/hci/hci_spi_st.c | 2 +- drivers/bluetooth/hci/hci_stm32wba.c | 2 +- drivers/bluetooth/hci/ipm_stm32wb.c | 5 ++--- 9 files changed, 15 insertions(+), 19 deletions(-) diff --git a/drivers/bluetooth/hci/apollox_blue.c b/drivers/bluetooth/hci/apollox_blue.c index 1fb2ab33fb1..9a4bf5440d8 100644 --- a/drivers/bluetooth/hci/apollox_blue.c +++ b/drivers/bluetooth/hci/apollox_blue.c @@ -396,8 +396,7 @@ static int bt_apollo_set_nvds(void) #else uint8_t *p; - buf = bt_hci_cmd_create(HCI_VSC_UPDATE_NVDS_CFG_CMD_OPCODE, - HCI_VSC_UPDATE_NVDS_CFG_CMD_LENGTH); + buf = bt_hci_cmd_alloc(K_FOREVER); if (!buf) { return -ENOBUFS; } diff --git a/drivers/bluetooth/hci/h4_ifx_cyw43xxx.c b/drivers/bluetooth/hci/h4_ifx_cyw43xxx.c index 6bc563fb9f2..e115ea92b47 100644 --- a/drivers/bluetooth/hci/h4_ifx_cyw43xxx.c +++ b/drivers/bluetooth/hci/h4_ifx_cyw43xxx.c @@ -122,8 +122,7 @@ static int bt_update_controller_baudrate(const struct device *bt_uart_dev, uint3 /* Allocate buffer for update uart baudrate command. * It will be BT_HCI_OP_RESET with extra parameters. */ - buf = bt_hci_cmd_create(BT_HCI_VND_OP_UPDATE_BAUDRATE, - HCI_VSC_UPDATE_BAUD_RATE_LENGTH); + buf = bt_hci_cmd_alloc(K_FOREVER); if (buf == NULL) { LOG_ERR("Unable to allocate command buffer"); return -ENOMEM; @@ -172,7 +171,7 @@ static int bt_firmware_download(const uint8_t *firmware_image, uint32_t size) uint16_t op_code = *(uint16_t *)data; /* Allocate buffer for hci_write_ram/hci_launch_ram command. */ - buf = bt_hci_cmd_create(op_code, data_length); + buf = bt_hci_cmd_alloc(K_FOREVER); if (buf == NULL) { LOG_ERR("Unable to allocate command buffer"); return err; diff --git a/drivers/bluetooth/hci/hci_ifx_cyw208xx.c b/drivers/bluetooth/hci/hci_ifx_cyw208xx.c index 1fee53436a6..913d19d514c 100644 --- a/drivers/bluetooth/hci/hci_ifx_cyw208xx.c +++ b/drivers/bluetooth/hci/hci_ifx_cyw208xx.c @@ -146,7 +146,7 @@ static int cyw208xx_bt_firmware_download(const uint8_t *firmware_image, uint32_t } /* Allocate buffer for hci_write_ram/hci_launch_ram command. */ - buf = bt_hci_cmd_create(op_code, data_length); + buf = bt_hci_cmd_alloc(K_FOREVER); if (buf == NULL) { LOG_ERR("Unable to allocate command buffer"); return -ENOBUFS; @@ -211,7 +211,7 @@ static int cyw208xx_setup(const struct device *dev, const struct bt_hci_setup_pa cybt_platform_hci_wait_for_boot_fully_up(false); /* Set public address */ - buf = bt_hci_cmd_create(BT_HCI_VND_OP_SET_LOCAL_DEV_ADDR, BTM_SET_LOCAL_DEV_ADDR_LENGTH); + buf = bt_hci_cmd_alloc(K_FOREVER); if (buf == NULL) { LOG_ERR("Unable to allocate command buffer"); cyhal_syspm_unlock_deepsleep(); @@ -375,7 +375,7 @@ wiced_bt_dev_vendor_specific_command(uint16_t opcode, uint8_t param_len, uint8_t struct net_buf *buf = NULL; /* Allocate a HCI command buffer */ - buf = bt_hci_cmd_create(opcode, param_len); + buf = bt_hci_cmd_alloc(K_FOREVER); if (!buf) { LOG_ERR("Unable to allocate buffer"); return WICED_NO_MEMORY; diff --git a/drivers/bluetooth/hci/hci_ifx_psoc6_bless.c b/drivers/bluetooth/hci/hci_ifx_psoc6_bless.c index db50091c8ae..531a3439d91 100644 --- a/drivers/bluetooth/hci/hci_ifx_psoc6_bless.c +++ b/drivers/bluetooth/hci/hci_ifx_psoc6_bless.c @@ -203,7 +203,7 @@ static int psoc6_bless_setup(const struct device *dev, const struct bt_hci_setup addr[5], addr[4], addr[3], addr[2], addr[1], addr[0], BT_ADDR_LE_PUBLIC, }; - buf = bt_hci_cmd_create(PSOC6_BLESS_OP_SET_PUBLIC_ADDR, sizeof(hci_data)); + buf = bt_hci_cmd_alloc(K_FOREVER); if (buf == NULL) { LOG_ERR("Unable to allocate command buffer"); return -ENOMEM; diff --git a/drivers/bluetooth/hci/hci_nxp.c b/drivers/bluetooth/hci/hci_nxp.c index 2cd5511e7c7..a540e264ac0 100644 --- a/drivers/bluetooth/hci/hci_nxp.c +++ b/drivers/bluetooth/hci/hci_nxp.c @@ -94,7 +94,7 @@ static int nxp_bt_send_vs_command(uint16_t opcode, const uint8_t *params, uint8_ struct net_buf *buf; /* Allocate buffer for the hci command */ - buf = bt_hci_cmd_create(opcode, params_len); + buf = bt_hci_cmd_alloc(K_FOREVER); if (buf == NULL) { LOG_ERR("Unable to allocate command buffer"); return -ENOMEM; diff --git a/drivers/bluetooth/hci/hci_nxp_setup.c b/drivers/bluetooth/hci/hci_nxp_setup.c index a217ffc53bd..a89e1ede677 100644 --- a/drivers/bluetooth/hci/hci_nxp_setup.c +++ b/drivers/bluetooth/hci/hci_nxp_setup.c @@ -1281,7 +1281,7 @@ static int bt_nxp_set_calibration_data_annex55(void) if (IS_ENABLED(CONFIG_BT_HCI_HOST)) { struct net_buf *buf; - buf = bt_hci_cmd_create(opcode, HCI_CMD_STORE_BT_CAL_DATA_PARAM_LENGTH); + buf = bt_hci_cmd_alloc(K_FOREVER); if (buf == NULL) { LOG_ERR("Unable to allocate command buffer"); return -ENOMEM; @@ -1346,7 +1346,7 @@ static int bt_nxp_set_calibration_data_annex100(void) if (IS_ENABLED(CONFIG_BT_HCI_HOST)) { struct net_buf *buf; - buf = bt_hci_cmd_create(opcode, HCI_CMD_STORE_BT_CAL_DATA_PARAM_ANNEX100_LENGTH); + buf = bt_hci_cmd_alloc(K_FOREVER); if (buf == NULL) { LOG_ERR("Unable to allocate command buffer"); return -ENOMEM; @@ -1387,8 +1387,7 @@ static int bt_hci_baudrate_update(const struct device *dev, uint32_t baudrate) int err; struct net_buf *buf; - buf = bt_hci_cmd_create(BT_HCI_VSC_BAUDRATE_UPDATE_OPCODE, - BT_HCI_VSC_BAUDRATE_UPDATE_LENGTH); + buf = bt_hci_cmd_alloc(K_FOREVER); if (!buf) { LOG_ERR("Fail to allocate buffer"); return -ENOBUFS; diff --git a/drivers/bluetooth/hci/hci_spi_st.c b/drivers/bluetooth/hci/hci_spi_st.c index e6201ec0475..ebed8ae1ff4 100644 --- a/drivers/bluetooth/hci/hci_spi_st.c +++ b/drivers/bluetooth/hci/hci_spi_st.c @@ -335,7 +335,7 @@ static int bt_spi_send_aci_config(uint8_t offset, const uint8_t *value, size_t v hdr.param_len = data_len; buf = bt_buf_get_tx(BT_BUF_CMD, K_NO_WAIT, &hdr, sizeof(hdr)); #else - buf = bt_hci_cmd_create(BLUENRG_ACI_WRITE_CONFIG_DATA, data_len); + buf = bt_hci_cmd_alloc(K_FOREVER); #endif /* CONFIG_BT_HCI_RAW */ if (!buf) { diff --git a/drivers/bluetooth/hci/hci_stm32wba.c b/drivers/bluetooth/hci/hci_stm32wba.c index 77654e16bea..57bc54c231a 100644 --- a/drivers/bluetooth/hci/hci_stm32wba.c +++ b/drivers/bluetooth/hci/hci_stm32wba.c @@ -432,7 +432,7 @@ static int bt_hci_stm32wba_setup(const struct device *dev, return -ENOMSG; } - buf = bt_hci_cmd_create(ACI_HAL_WRITE_CONFIG_DATA, sizeof(*param)); + buf = bt_hci_cmd_alloc(K_FOREVER); if (!buf) { return -ENOBUFS; } diff --git a/drivers/bluetooth/hci/ipm_stm32wb.c b/drivers/bluetooth/hci/ipm_stm32wb.c index 3e0dee023dc..0f61f7c36f7 100644 --- a/drivers/bluetooth/hci/ipm_stm32wb.c +++ b/drivers/bluetooth/hci/ipm_stm32wb.c @@ -433,8 +433,7 @@ static int bt_ipm_set_addr(void) return -ENOMSG; } - buf = bt_hci_cmd_create(ACI_HAL_WRITE_CONFIG_DATA, sizeof(*param)); - + buf = bt_hci_cmd_alloc(K_FOREVER); if (!buf) { return -ENOBUFS; } @@ -468,7 +467,7 @@ static int bt_ipm_ble_init(void) LOG_ERR("Can't set BLE UID addr"); } /* Send ACI_WRITE_SET_TX_POWER_LEVEL */ - buf = bt_hci_cmd_create(ACI_WRITE_SET_TX_POWER_LEVEL, 3); + buf = bt_hci_cmd_alloc(K_FOREVER); if (!buf) { return -ENOBUFS; } From 40b19370e863377f9b35eff9b755168b979e458e Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 19 Jun 2025 11:06:11 +0300 Subject: [PATCH 4/5] [nrf fromtree] Bluetooth: Host: Mark bt_hci_cmd_create() as deprecated Mark bt_hci_cmd_create() as deprecated (superceded by bt_hci_cmd_alloc()), and update any references to the new function. Signed-off-by: Johan Hedberg (cherry picked from commit a22a4b1ae432ca8c99d43619099ae67b2c48bf45) --- include/zephyr/bluetooth/hci.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/zephyr/bluetooth/hci.h b/include/zephyr/bluetooth/hci.h index dd9c60c8ae8..cc0843fb7e3 100644 --- a/include/zephyr/bluetooth/hci.h +++ b/include/zephyr/bluetooth/hci.h @@ -56,12 +56,14 @@ static inline const char *bt_hci_err_to_str(uint8_t hci_err) * of the parameters. Upon successful return the buffer is ready to have * the parameters encoded into it. * + * @deprecated Use bt_hci_cmd_alloc() instead. + * * @param opcode Command OpCode. * @param param_len Length of command parameters. * * @return Newly allocated buffer. */ -struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len); +__deprecated struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len); /** Allocate an HCI command buffer. * @@ -80,7 +82,7 @@ struct net_buf *bt_hci_cmd_alloc(k_timeout_t timeout); /** Send a HCI command asynchronously. * * This function is used for sending a HCI command asynchronously. It can - * either be called for a buffer created using bt_hci_cmd_create(), or + * either be called for a buffer created using bt_hci_cmd_alloc(), or * if the command has no parameters a NULL can be passed instead. The * sending of the command will happen asynchronously, i.e. upon successful * return from this function the caller only knows that it was queued @@ -99,7 +101,7 @@ int bt_hci_cmd_send(uint16_t opcode, struct net_buf *buf); /** Send a HCI command synchronously. * * This function is used for sending a HCI command synchronously. It can - * either be called for a buffer created using bt_hci_cmd_create(), or + * either be called for a buffer created using bt_hci_cmd_alloc(), or * if the command has no parameters a NULL can be passed instead. * * The function will block until a Command Status or a Command Complete From f90e9f8108dc6d626c662543d157459366e490f6 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 19 Jun 2025 11:10:21 +0300 Subject: [PATCH 5/5] [nrf fromtree] doc: migration-guide-4.2: Add note about bt_hci_cmd_create() Add a note about bt_hci_cmd_create() deprecation and which API should be used instead. Signed-off-by: Johan Hedberg (cherry picked from commit 607ff8520fef2ce42cdd9642e5184e40e75656f3) --- doc/releases/migration-guide-4.2.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/releases/migration-guide-4.2.rst b/doc/releases/migration-guide-4.2.rst index faad669e379..08a2a3d0e33 100644 --- a/doc/releases/migration-guide-4.2.rst +++ b/doc/releases/migration-guide-4.2.rst @@ -410,6 +410,10 @@ Bluetooth HCI have been deprecated, but are still usable, with the exception that they can only be called once per buffer. +* The :c:func:`bt_hci_cmd_create` function has been depracated and the new :c:func:`bt_hci_cmd_alloc` + function should be used instead. The new function takes no parameters because the command + sending functions have been updated to do the command header encoding. + Bluetooth Host ==============