From c1d23e27d1b64a84bbe2f617f10304f188159989 Mon Sep 17 00:00:00 2001 From: vlad Date: Wed, 2 Dec 2026 10:11:49 +0200 Subject: [PATCH 1/2] Bluetooth: btcentauri_t6050: skip malformed RX descriptors One event descriptor with a bad length stopped the transport: the work handler cleared running and left HCI registered. The bad descriptor stayed at rx_head, so a reset or reopen hit it again and Bluetooth was dead until the module was reloaded. The LE ACL ring and the auxiliary ACL, SCO and ISO rings did the same for a length above the footer. Count such a descriptor as an RX error, log it rate-limited, and return the slot to the firmware the same way as a consumed packet. An invalid ring index still stops the transport. Signed-off-by: vlad --- drivers/bluetooth/btcentauri_t6050.c | 44 ++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/drivers/bluetooth/btcentauri_t6050.c b/drivers/bluetooth/btcentauri_t6050.c index 4060ca7f9ce7f..3f8e090776fba 100644 --- a/drivers/bluetooth/btcentauri_t6050.c +++ b/drivers/bluetooth/btcentauri_t6050.c @@ -410,9 +410,13 @@ static int cen_aux_drain(struct cen_bt *bt, bool repost) dma_rmb(); length = get_unaligned_le32(descriptor) >> 8; - if (length > spec->footer) - return -EPROTO; - if (repost) { + if (length > spec->footer) { + bt->hdev->stat.err_rx++; + dev_warn_ratelimited(&bt->pdev->dev, + "Dropping RX descriptor with bad length (ring=%u head=%u tail=%u len=%u)\n", + spec->id, state->head, tail, + length); + } else if (repost) { if (spec->id == 8) cen_receive_acl(bt, descriptor + 16, length); @@ -755,6 +759,14 @@ static bool cen_tx_ready(struct cen_bt *bt, struct sk_buff_head *queue, return (head + 1) % slots != cen_tail(bt, ring); } +static void cen_rx_consume(struct cen_bt *bt) +{ + bt->rx_head = (bt->rx_head + 1) % CEN_RX_SLOTS; + cen_rx_buffer(bt, bt->rx_post); + bt->rx_post = (bt->rx_post + 1) % CEN_RX_SLOTS; + cen_post(bt, 7, bt->rx_post); +} + static void cen_io_work(struct work_struct *work) { struct cen_bt *bt = container_of(work, struct cen_bt, io_work); @@ -784,10 +796,14 @@ static void cen_io_work(struct work_struct *work) descriptor = bt->arena + CEN_LE_RX + bt->le_rx_head * CEN_LE_STRIDE; length = get_unaligned_le32(descriptor) >> 8; - if (length > CEN_LE_FOOTER) - goto protocol_error; - if (cen_receive_acl(bt, descriptor + 16, length)) + if (length > CEN_LE_FOOTER) { + hdev->stat.err_rx++; + dev_warn_ratelimited(&bt->pdev->dev, + "Dropping RX descriptor with bad length (ring=10 head=%u tail=%u len=%u)\n", + bt->le_rx_head, tail, length); + } else if (cen_receive_acl(bt, descriptor + 16, length)) { goto protocol_error; + } bt->le_rx_head = (bt->le_rx_head + 1) % CEN_LE_SLOTS; cen_le_rx_buffer(bt, bt->le_rx_post); bt->le_rx_post = (bt->le_rx_post + 1) % CEN_LE_SLOTS; @@ -803,8 +819,15 @@ static void cen_io_work(struct work_struct *work) descriptor = bt->arena + CEN_RX + bt->rx_head * CEN_STRIDE; length = get_unaligned_le32(descriptor) >> 8; if (length < HCI_EVENT_HDR_SIZE || length > CEN_FOOTER || - length != descriptor[17] + HCI_EVENT_HDR_SIZE) - goto protocol_error; + length != descriptor[17] + HCI_EVENT_HDR_SIZE) { + hdev->stat.err_rx++; + dev_warn_ratelimited(&bt->pdev->dev, + "Dropping malformed event (ring=7 head=%u tail=%u len=%u plen=%u)\n", + bt->rx_head, tail, length, + descriptor[17]); + cen_rx_consume(bt); + continue; + } skb = bt_skb_alloc(length, GFP_KERNEL); if (skb) { skb_put_data(skb, descriptor + 16, length); @@ -870,10 +893,7 @@ static void cen_io_work(struct work_struct *work) } else { hdev->stat.err_rx++; } - bt->rx_head = (bt->rx_head + 1) % CEN_RX_SLOTS; - cen_rx_buffer(bt, bt->rx_post); - bt->rx_post = (bt->rx_post + 1) % CEN_RX_SLOTS; - cen_post(bt, 7, bt->rx_post); + cen_rx_consume(bt); } if (cen_transmit(bt, &bt->txq, 1, CEN_TX_SLOTS, CEN_TX, CEN_FOOTER, &bt->tx_head)) From 4ce92d06cd6d2b26c330c38ce52e5f4a405b3503 Mon Sep 17 00:00:00 2001 From: vlad Date: Wed, 2 Dec 2026 10:12:05 +0200 Subject: [PATCH 2/2] Bluetooth: btcentauri_t6050: fall back to host duplicate filtering When the firmware refuses the vendor command that flushes its duplicate filter, reset_dup_filter returned the error and hci_sync gave up before sending LE Scan Enable. LE scanning then failed, so BLE discovery and HID reconnects did not work. A refusal arrives as a negative errno from bt_to_errno(). For Unknown Command, Command Disallowed, Unsupported Feature and Invalid Parameters, log it once, remember it and return 0. While the fallback is set, clear Filter_Duplicates in the copy of LE Set Scan Enable and LE Set Extended Scan Enable written to the command ring, so the host handles repeated reports. Send, cancel and timeout errors are still returned. Signed-off-by: vlad --- drivers/bluetooth/btcentauri_t6050.c | 33 +++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/btcentauri_t6050.c b/drivers/bluetooth/btcentauri_t6050.c index 3f8e090776fba..d044a66eeada8 100644 --- a/drivers/bluetooth/btcentauri_t6050.c +++ b/drivers/bluetooth/btcentauri_t6050.c @@ -100,6 +100,7 @@ struct cen_bt { int suspend_error; u8 native_startup_steps; bool connection_command_supported, connection_status_pending; + bool dup_filter_fallback; u16 sync_pending_wire, sync_pending_orig; struct cen_hrb_conn hrb_conns[CEN_MAX_HRB_CONNS]; }; @@ -621,6 +622,19 @@ static int cen_transmit(struct cen_bt *bt, struct sk_buff_head *queue, u16 ring, } if (ring == 1 && get_unaligned_le16(skb->data) == HCI_OP_RESET) cen_hrb_clear(bt); + /* + * If the firmware refused to reset its duplicate filter, enable + * scans with Filter_Duplicates = 0 (byte 4 of both commands); + * the host copes with repeated reports. + */ + if (ring == 1 && skb->len >= 5 && + READ_ONCE(bt->dup_filter_fallback) && + (get_unaligned_le16(skb->data) == + HCI_OP_LE_SET_EXT_SCAN_ENABLE || + get_unaligned_le16(skb->data) == + HCI_OP_LE_SET_SCAN_ENABLE) && + descriptor[16 + 3]) + descriptor[16 + 4] = 0; if (ring == 1 && READ_ONCE(bt->connection_command_supported) && get_unaligned_le16(skb->data) == HCI_OP_CREATE_CONN) { u8 *command = descriptor + 16; @@ -1012,15 +1026,32 @@ static int cen_vendor_command(struct hci_dev *hdev, u16 opcode, static int cen_hci_reset_dup_filter(struct hci_dev *hdev) { + struct cen_bt *bt = hci_get_drvdata(hdev); static const u8 flags; int ret; + if (READ_ONCE(bt->dup_filter_fallback)) + return 0; + /* + * A refusal in Command Complete or Command Status reaches us as a + * negative errno from bt_to_errno(), not as a positive status. Only + * the codes of Unknown Command (0x01), Command Disallowed (0x0c), + * Unsupported Feature (0x11) and Invalid Parameters (0x12) select + * host filtering; send, cancel and timeout errors are passed on. + */ ret = __hci_cmd_sync_status(hdev, CEN_OP_FLUSH_DUPLICATES, sizeof(flags), &flags, HCI_CMD_TIMEOUT); - if (ret) { + if (ret < 0 && ret != -EBADRQC && ret != -EBUSY && + ret != -EOPNOTSUPP && ret != -EINVAL) { bt_dev_warn(hdev, "Duplicate filter reset failed: %d", ret); return ret; } + if (ret) { + bt_dev_warn(hdev, + "Duplicate filter reset refused (%d); falling back to host filtering", + ret); + WRITE_ONCE(bt->dup_filter_fallback, true); + } return 0; }