This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new a0e3af355b2 wireless/bluetooth: Continue without flow control if it is
rejected.
a0e3af355b2 is described below
commit a0e3af355b20527c7624248cbeec4fd51d3b08cc
Author: ViezeVingertjes <[email protected]>
AuthorDate: Thu Nov 26 18:42:57 2026 +0100
wireless/bluetooth: Continue without flow control if it is rejected.
Since commit 038e17eb46 ("wireless/bluetooth: Check Controller to Host
flow control support") Host Buffer Size and Set Controller To Host Flow
Control are sent synchronously and a failure of either is fatal. Before,
Host Buffer Size was sent without waiting for its result.
The ESP32-S3 BLE controller lists these commands as supported, but
rejects Host Buffer Size with status 0x11 (Unsupported Feature or
Parameter Value) unless the host takes ACL packets of at least 251
bytes, the maximum LE data length. The NuttX host buffer is smaller
(74 bytes), so the host now fails to initialize on ESP32-S3:
hci_cmd_done: WARNING: status 17
bt_hci_cmd_send_sync: ERROR: Failed get return parameters
hci_initialize: ERROR: bt_hci_cmd_send_sync failed: -5
esp32s3_ble_initialize: bt_driver_register error: -5
Controller to Host flow control is optional, so treat a rejection of
either command (-EIO, the controller returned an error status) like a
controller that does not support it: warn and continue without flow
control. Other errors, such as a timeout, stay fatal.
Tested on Waveshare ESP32-S3-Touch-AMOLED-2.16 (ESP32-S3) with btsak:
the host initializes with a warning that flow control is not available,
"bt bnep0 scan" finds nearby devices and "bt bnep0 advertise start" is
seen by a Linux host. A probe of the controller accepted Host Buffer
Size with ACL lengths of 251 and 1021 bytes and rejected 27 and 74.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: ViezeVingertjes <[email protected]>
---
wireless/bluetooth/bt_hcicore.c | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/wireless/bluetooth/bt_hcicore.c b/wireless/bluetooth/bt_hcicore.c
index fb0575fdd73..a7c0f92f00f 100644
--- a/wireless/bluetooth/bt_hcicore.c
+++ b/wireless/bluetooth/bt_hcicore.c
@@ -1603,13 +1603,26 @@ static int hci_initialize(void)
g_btdev.btdev->head_reserve);
hbs->acl_pkts = BT_HOST2LE16(CONFIG_BLUETOOTH_BUFFER_PREALLOC);
+ /* A controller may reject the buffer size of the host, e.g. one that
+ * needs ACL packets of the maximum LE length (251 bytes). Flow
+ * control is optional, so continue without it if the controller
+ * rejects either command (-EIO); other errors are fatal.
+ */
+
ret = bt_hci_cmd_send_sync(BT_HCI_OP_HOST_BUFFER_SIZE, buf, NULL);
- if (ret < 0)
+ if (ret == -EIO)
+ {
+ flow_control = false;
+ }
+ else if (ret < 0)
{
wlerr("ERROR: bt_hci_cmd_send_sync failed: %d\n", ret);
return ret;
}
+ }
+ if (flow_control)
+ {
buf = bt_hci_cmd_create(BT_HCI_OP_SET_CTL_TO_HOST_FLOW, 1);
if (buf == NULL)
{
@@ -1621,19 +1634,26 @@ static int hci_initialize(void)
*enable = 1;
ret = bt_hci_cmd_send_sync(BT_HCI_OP_SET_CTL_TO_HOST_FLOW, buf, NULL);
- if (ret < 0)
+ if (ret == -EIO)
+ {
+ flow_control = false;
+ }
+ else if (ret < 0)
{
wlerr("ERROR: bt_hci_cmd_send_sync failed: %d\n", ret);
return ret;
}
+ }
+ if (flow_control)
+ {
/* Report completed packets only after flow control is enabled. */
g_btdev.flow_control_enable = true;
}
else
{
- wlwarn("WARNING: Controller to Host flow control is not supported\n");
+ wlwarn("WARNING: Controller to Host flow control is not available\n");
}
#endif