From nobody Wed Nov 06 23:31:53 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 4XkM162N4Kz5c01D; Wed, 06 Nov 2024 23:31:54 +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 4XkM160MLGz4Lt4; Wed, 6 Nov 2024 23:31:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730935914; 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=cMg8Nx8HrRnwSr3p2o4JWwa8gEOOiTDJBxYoTEvPfw8=; b=X/TtGEHoFJpl0KPOzZ973qVlI2WSv0rxEp1In09XZZcaYuF7+3ZGDhMxxcuoAvFkFgpArj huMcIQ9GLR5iDwyssaAqRj4ajiaHQqEh+6zWJWZ/q06DJz/4AAiKIbktajAP/9b5f5G38G SAWEIT9qOdyMqImvRGwjv4rwwTOg76aZFgp+rxC6loeiGZPqd5lwer6bNmAZZ4I4FkN8gO 625ToTF8OLOp9qkelW6QriY6ShPkTN2t3qRJNrWv+424WGagGR052nMD+w9HD+51lw4xPd uD1JEzY6QVGtrzrzTZdVVBxkJKfEMEyeoGxYFJ/hSt1F4LzJ1KtfxGcpbReDkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730935914; 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=cMg8Nx8HrRnwSr3p2o4JWwa8gEOOiTDJBxYoTEvPfw8=; b=yDMad+ITRg0X0CDo2nKSn0zC2RCHcwrUb5aeOC0ufn/DFiDD6bMTdpjrqtch6RFMehTHLI mBz519fp68iPTsYVMhaGN6Q0BPpTLPPIOPJQAxHgX1if93S89l9jYTUoGSZORppN8G+v/U 4U2a6MCmZzfzP3qsuMsk1gIOFkVXFxvqghFJXZG5qGIwVrHZPPW7qNO+knOmWe8yoO55t/ QS20fc8hm00hSfsmHz9KKnJc4FmYKI5nA2sZ4wK03oVFb3xz5LSLZJ2xB/Aqmr399wVN0R f+JV+/mWAhLQRwZ1duN7HmpSzSyduhcPCF4XuAg/bic2R9AQkQ9f1SfvImSJNQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730935914; a=rsa-sha256; cv=none; b=RSo0+bKw8yR0AjJ6xKP6R5noRWIOxINAtK+7Fek1D9n9aMR/SOBq2ZxO9QtSo4WCZ0+ksL eESTipJClbPd/jhKwytPa3+UppOOK6wLEt3amo+wveNkJVI0PTmad8eI68vWElB504wLl3 J5K7v5ZuGIR9h6L3KmwACOcoSTk/1cYiieovjgeAVlOzM6gI6FnPZf2H6laelSUwClpviP OCiTWoBcWm0wu/iprA2+QGRccQPmA0q53FGCEweEcgIF+3tBSsCpyPhkI+2Zfk6h2EKb+v XLq7syDLsx3ws45jO9je6i+H3+JVNLJH9cRSniTuxiemWr2h9EspK/+GxkkLBA== 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 4XkM1575VzzLc7; Wed, 6 Nov 2024 23:31:53 +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 4A6NVrNW069918; Wed, 6 Nov 2024 23:31:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A6NVrCG069915; Wed, 6 Nov 2024 23:31:53 GMT (envelope-from git) Date: Wed, 6 Nov 2024 23:31:53 GMT Message-Id: <202411062331.4A6NVrCG069915@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 0b23c50ae834 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 0b23c50ae834d11842810304e4ddad2754298ada Auto-Submitted: auto-generated The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=0b23c50ae834d11842810304e4ddad2754298ada commit 0b23c50ae834d11842810304e4ddad2754298ada Author: Vladimir Kondratyev AuthorDate: 2024-11-06 23:27:20 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-11-06 23:27:20 +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 --- 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 a63ccae3cc03..59405629efb1 100644 --- a/sys/netgraph/bluetooth/drivers/ubt/ng_ubt.c +++ b/sys/netgraph/bluetooth/drivers/ubt/ng_ubt.c @@ -534,6 +534,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. */ @@ -572,6 +573,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); @@ -842,6 +849,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); @@ -849,7 +858,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);