Skip to content

Commit 42fda4d

Browse files
axelnxpnordicjm
authored andcommitted
[nrf fromtree] drivers: bluetooth: hci_nxp: fix unexpected command complete event
As the previous version of the MCXW71 BLE Controller wasn't sending a command complete event after setting the BD address, we used a workaround to directly send the HCI command without using zephyr's API. Now, on the latest version of MCXW72 and MCXW71, this issue is fixed, so we need to use `bt_hci_cmd_send_sync` to properly expect the command complete event. Signed-off-by: Axel Le Bourhis <[email protected]> (cherry picked from commit e5a1c0b)
1 parent 7eed945 commit 42fda4d

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

drivers/bluetooth/hci/hci_nxp.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ LOG_MODULE_REGISTER(bt_driver);
7979
/* Private functions */
8080
/* -------------------------------------------------------------------------- */
8181

82-
#if defined(CONFIG_HCI_NXP_ENABLE_AUTO_SLEEP) || defined(CONFIG_HCI_NXP_SET_CAL_DATA)
82+
#if defined(CONFIG_HCI_NXP_ENABLE_AUTO_SLEEP) || defined(CONFIG_HCI_NXP_SET_CAL_DATA) ||\
83+
defined(CONFIG_BT_HCI_SET_PUBLIC_ADDR)
8384
static int nxp_bt_send_vs_command(uint16_t opcode, const uint8_t *params, uint8_t params_len)
8485
{
8586
if (IS_ENABLED(CONFIG_BT_HCI_HOST)) {
@@ -101,7 +102,7 @@ static int nxp_bt_send_vs_command(uint16_t opcode, const uint8_t *params, uint8_
101102
return 0;
102103
}
103104
}
104-
#endif /* CONFIG_HCI_NXP_ENABLE_AUTO_SLEEP || CONFIG_HCI_NXP_SET_CAL_DATA */
105+
#endif
105106

106107
#if defined(CONFIG_HCI_NXP_ENABLE_AUTO_SLEEP)
107108
static int nxp_bt_enable_controller_autosleep(void)
@@ -170,7 +171,10 @@ static int bt_nxp_set_mac_address(const bt_addr_t *public_addr)
170171
uint8_t addrOUI[BD_ADDR_OUI_PART_SIZE] = {BD_ADDR_OUI};
171172
uint8_t uid[16] = {0};
172173
uint8_t uuidLen;
173-
uint8_t hciBuffer[12];
174+
uint8_t params[HCI_CMD_BT_HOST_SET_MAC_ADDR_PARAM_LENGTH] = {
175+
BT_USER_BD,
176+
0x06U
177+
};
174178

175179
/* If no public address is provided by the user, use a unique address made
176180
* from the device's UID (unique ID)
@@ -190,18 +194,12 @@ static int bt_nxp_set_mac_address(const bt_addr_t *public_addr)
190194
bt_addr_copy((bt_addr_t *)bleDeviceAddress, public_addr);
191195
}
192196

193-
hciBuffer[0] = BT_HCI_H4_CMD;
194-
memcpy((void *)&hciBuffer[1], (const void *)&opcode, 2U);
195-
/* Set HCI parameter length */
196-
hciBuffer[3] = HCI_CMD_BT_HOST_SET_MAC_ADDR_PARAM_LENGTH;
197-
/* Set command parameter ID */
198-
hciBuffer[4] = BT_USER_BD;
199-
/* Set command parameter length */
200-
hciBuffer[5] = (uint8_t)6U;
201-
memcpy(hciBuffer + 6U, (const void *)bleDeviceAddress,
202-
BD_ADDR_UUID_PART_SIZE + BD_ADDR_OUI_PART_SIZE);
197+
memcpy(&params[2], (const void *)bleDeviceAddress,
198+
BD_ADDR_UUID_PART_SIZE + BD_ADDR_OUI_PART_SIZE);
199+
203200
/* Send the command */
204-
return PLATFORM_SendHciMessage(hciBuffer, 12U);
201+
return nxp_bt_send_vs_command(opcode, params,
202+
HCI_CMD_BT_HOST_SET_MAC_ADDR_PARAM_LENGTH);
205203
}
206204
#endif /* CONFIG_BT_HCI_SET_PUBLIC_ADDR */
207205

0 commit comments

Comments
 (0)