From nobody Sun Dec 22 03:37:57 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YG6LG2H5pz5hwn4; Sun, 22 Dec 2024 03:37:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YG6LF2Hvbz4DFd; Sun, 22 Dec 2024 03:37:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734838677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Y5xefTgf2nOoYmWMc+5H1QL9vxxkMpqc57cjL1Tg6j0=; b=Ijz6WE5m0tJy0Bpg1LLPe61chC1yyC+iGpKjDcO5uydMswpyl9//SfvG6av01h8keF5Xxr lpJWHTFR9EURzMSc7+zzKVYjuj2+DkKiHI5yblwCN/47YAd/+X5P5sHobhc1KQwwDWldzS 6GzVCmjwOzO41zjDZBh0djwoQftnC2NtChsczqXdRohmo24GThkFVG0EgSUXmz6oYdZ/z2 BdQP3bA0PvsSnvi7JjBgMoEiXbW/MLNIUywPWdOZjNzbRZ71/4g9K/tt/TD378Jd/Uv/OR HX17RBF8/f3CNsviXsWIOkv0sipYIoT8AjP60gBBQUPrISFbDPoAbkedwVUMkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734838677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Y5xefTgf2nOoYmWMc+5H1QL9vxxkMpqc57cjL1Tg6j0=; b=rJovLy2S+iRyJa2YtdVMyT73bK+VlRG/tqAnRrngoU7imQ/YWbNzWLZos7Bbmsb1nlZd90 ckXcUAeHuvvWJQBZKUT/f95dlbOXZA3QUMSne1RklcBxCXX8AuF8ETA/J0wHKbs0x6gca6 XXaKve92oTZgJxaCtbqGpV7OqPlC0F+sSjLXlygHyogduoJPuhw9oLW7BRsHx3XxBrJhnP QyA3rrSTfFvx9+9E5LHJsOcprQx0afaqMbzPoGZ8BhBvBmb+BSAQEsUT3PHjHr5F4cEJRK yU8fdCNCwIkoKJI543ZbceqnKZV7ivR6hg/u7bwmOlchNp2FAzFLvkXDI62f1A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734838677; a=rsa-sha256; cv=none; b=S/9zl+ziNNFqUGh9xCvTg3R7WVIgL9w7Ye2nvsioMhYZfXV6hx8xIGvt7xCbPypvqHxjy4 qHJ8P+kdDGGl24fSWCVWmlHREEzIAIVg2zsXcIvEuD2dnzOihltt+R/fFXxb4ENF/ov7Nx L7orJ5CcxW+jAnzMM2q0Ee4tPqqMToOCNAsTajpPIfLi6cJqOz0XRO5qsCH6n1IQdrVn+P LDUSoRC+7fMppe14EEdUleIelUVUMsuTndpuN20OoyFTo/hagDa3LJBzlfVNxkh/psF9pB OxVWQ+jhB5h7EfpNXVI+mbd/xaEBSWaEonUTGDBVzzSeeYR/mx6cL5AM7+DyYw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YG6LF1F4YzsRw; Sun, 22 Dec 2024 03:37:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BM3bveV053311; Sun, 22 Dec 2024 03:37:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BM3bvK0053308; Sun, 22 Dec 2024 03:37:57 GMT (envelope-from git) Date: Sun, 22 Dec 2024 03:37:57 GMT Message-Id: <202412220337.4BM3bvK0053308@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: e908df969af2 - stable/14 - ng_ubt_intel: Ignore unexpected HCI events List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: e908df969af2384def482c0629ce1c83c018b415 Auto-Submitted: auto-generated The branch stable/14 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=e908df969af2384def482c0629ce1c83c018b415 commit e908df969af2384def482c0629ce1c83c018b415 Author: Vladimir Kondratyev AuthorDate: 2024-11-06 23:27:20 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-12-22 03:35:08 +0000 ng_ubt_intel: Ignore unexpected HCI events If Intel firmware is already in operational mode at boot that takes place at warm boot, BT adaptor can generate extra HCI events which interferes with firmware mode detection logic. Ignore them. Sponsored by: Future Crew LLC MFC after: 1 month Reviewed by: bz Differential Revision: https://reviews.freebsd.org/D46736 (cherry picked from commit 0b23c50ae834d11842810304e4ddad2754298ada) --- sys/netgraph/bluetooth/drivers/ubt/ng_ubt.c | 27 +++++++++++++++++++++++ sys/netgraph/bluetooth/drivers/ubt/ng_ubt_intel.c | 5 +++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/sys/netgraph/bluetooth/drivers/ubt/ng_ubt.c b/sys/netgraph/bluetooth/drivers/ubt/ng_ubt.c index 649c479d1d9f..64b41c0a328d 100644 --- a/sys/netgraph/bluetooth/drivers/ubt/ng_ubt.c +++ b/sys/netgraph/bluetooth/drivers/ubt/ng_ubt.c @@ -530,6 +530,7 @@ static const STRUCT_USB_HOST_ID ubt_devs[] = * Size of both command and response buffers are passed in length field of * corresponding structures in "Parameter Total Length" format i.e. * not including HCI packet headers. + * Expected event code must be placed into "Event code" of the response buffer. * * Must not be used after USB transfers have been configured in attach routine. */ @@ -568,6 +569,12 @@ ubt_do_hci_request(struct usb_device *udev, struct ubt_hci_cmd *cmd, if (evt == NULL) return (USB_ERR_NORMAL_COMPLETION); + /* Save operation code if we expect completion event in response */ + if(((struct ubt_hci_event *)evt)->header.event == + NG_HCI_EVENT_COMMAND_COMPL) + ((struct ubt_hci_event_command_compl *)evt)->opcode = + cmd->opcode; + /* Initialize INTR endpoint xfer and wait for response */ mtx_init(&mtx, "ubt pb", NULL, MTX_DEF | MTX_NEW); @@ -841,6 +848,8 @@ ubt_probe_intr_callback(struct usb_xfer *xfer, usb_error_t error) struct ubt_hci_event *evt = usbd_xfer_softc(xfer); struct usb_page_cache *pc; int actlen; + struct ubt_hci_evhdr evhdr; + uint16_t opcode; usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); @@ -848,7 +857,25 @@ ubt_probe_intr_callback(struct usb_xfer *xfer, usb_error_t error) case USB_ST_TRANSFERRED: if (actlen > UBT_HCI_EVENT_SIZE(evt)) actlen = UBT_HCI_EVENT_SIZE(evt); + if (actlen < sizeof(evhdr)) + goto submit_next; pc = usbd_xfer_get_frame(xfer, 0); + usbd_copy_out(pc, 0, &evhdr, sizeof(evhdr)); + /* Check for expected event code */ + if (evt->header.event != 0 && + (evt->header.event != evhdr.event)) + goto submit_next; + /* For completion events check operation code as well */ + if (evt->header.event == NG_HCI_EVENT_COMMAND_COMPL) { + if (actlen < sizeof(struct ubt_hci_event_command_compl)) + goto submit_next; + usbd_copy_out(pc, + offsetof(struct ubt_hci_event_command_compl, opcode), + &opcode, sizeof(opcode)); + if (opcode != + ((struct ubt_hci_event_command_compl *)evt)->opcode) + goto submit_next; + } usbd_copy_out(pc, 0, evt, actlen); /* OneShot mode */ wakeup(evt); diff --git a/sys/netgraph/bluetooth/drivers/ubt/ng_ubt_intel.c b/sys/netgraph/bluetooth/drivers/ubt/ng_ubt_intel.c index f93b74b264ad..c4410b7b2c80 100644 --- a/sys/netgraph/bluetooth/drivers/ubt/ng_ubt_intel.c +++ b/sys/netgraph/bluetooth/drivers/ubt/ng_ubt_intel.c @@ -119,14 +119,14 @@ ubt_intel_do_hci_request(struct usb_device *udev, uint16_t opcode, cmd.opcode = htole16(opcode); evt = malloc(offsetof(struct ubt_hci_event_command_compl, data) + resp_len, M_TEMP, M_ZERO | M_WAITOK); + evt->header.event = NG_HCI_EVENT_COMMAND_COMPL; evt->header.length = resp_len + UBT_HCI_EVENT_COMPL_HEAD_SIZE; error = ubt_do_hci_request(udev, &cmd, evt, UBT_INTEL_HCICMD_TIMEOUT); if (error != USB_ERR_NORMAL_COMPLETION) goto exit; - if (evt->header.event == NG_HCI_EVENT_COMMAND_COMPL && - evt->header.length == resp_len + UBT_HCI_EVENT_COMPL_HEAD_SIZE) + if (evt->header.length == resp_len + UBT_HCI_EVENT_COMPL_HEAD_SIZE) memcpy(resp, evt->data, resp_len); else error = USB_ERR_INVAL; @@ -150,6 +150,7 @@ ubt_intel_get_img_type(struct usb_device *udev) uint8_t *data; evt = malloc(UBT_INTEL_MAX_EVT_SIZE, M_TEMP, M_ZERO | M_WAITOK); + evt->header.event = NG_HCI_EVENT_COMMAND_COMPL; evt->header.length = UBT_INTEL_MAX_EVT_SIZE - sizeof(struct ubt_hci_evhdr);