Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1735091pxb; Wed, 10 Feb 2021 15:52:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxVy8V/EqsOI8Tf8Rg1ANAy2WoGmTccNKy3Kf3TYjoLIyjtC3ue2GdLNq0GQqp/oxEaLp4b X-Received: by 2002:aa7:d7d3:: with SMTP id e19mr5432702eds.288.1613001137047; Wed, 10 Feb 2021 15:52:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613001137; cv=none; d=google.com; s=arc-20160816; b=Fs15veLrLCJ33a41lD//OYAbvH1O/hnG3w1J0MHER/RQlgwnFaCMPghBK7sNa2I0WV Cmbb5ZdeWZnFKtlVXqbAGQcRBeWckIAMcKZGZ1w8BMx2QstQwZb8jp51n8BgdGJ+Pyrv clz9AiF+pm2Vf20cmgz3WY59LoYxK1Gds7WGEHCvDJOMcRzDeTgTGXSNJQr3Vb1cXQQM MR27H017b3i8CcISsDEZrt0fmjMVg/wFmkOvSK81HP49u9a7VKKyTPgKAfWmvHRL2I3K M9ElBnytb3jOufNWda+VmwNgtKeh9o2jbxyzp/OXwRyHRplo5lS2rQF9bYFz5+7rXf17 o+YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=kQSg2i/Ac80K0jAziGOYyPLFhndPkdJmNK9JQDMSPxs=; b=mqArSFWRMjPcMZo898Sx3qcIDL5AsVRfneFhJGpP67jWyQIhbUZt22xrZv/qnKlHxt T8hNMFaS9Af+F8Lm1QmU6AAKq7+/fxv+gsRpUbowj6QU1wSp0oTvyXCtzsntYys7sl1p Q1hszfjGhLt4ZhcKKo4g1su9BDZJFLAd1hDs8hP4ZoKPrzPzlQqZsd62kwk1oJpBSoi4 UVQalwKHaiHyshO9jYiW9EJHjgRkPLtY/FpiZ5SMwtWpKmP/RB00+NfdMrA5/8+nxjP/ 3q3vcxChTyWCc972TuoEE4W93NBK1gc5h3Exbum75mZ3CugUSFA+wOwhqZU7x46qku3M IymQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h4OMprpQ; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m13si2315355edb.227.2021.02.10.15.50.43; Wed, 10 Feb 2021 15:52:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h4OMprpQ; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233779AbhBJXqe (ORCPT + 99 others); Wed, 10 Feb 2021 18:46:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233928AbhBJXqd (ORCPT ); Wed, 10 Feb 2021 18:46:33 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A8AFC061788 for ; Wed, 10 Feb 2021 15:45:53 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id nm1so2106482pjb.3 for ; Wed, 10 Feb 2021 15:45:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=kQSg2i/Ac80K0jAziGOYyPLFhndPkdJmNK9JQDMSPxs=; b=h4OMprpQNPAER+ZVxljOgF8xl6Q6E+Rd8++H4CaW5Bo54stI2DQ+6trufnq+VSdYMo mhjem58a7sbBgLlukvPsCmiKfIqKwHCDtNl3v01NTShmZ0KmvARCAcYs3HDPaKsxiUkT kuhpfeFEqcAoSd4kaH98A9AayZBc9KDntrfs6fjHfl5I2hGQOC50HnQiQt0ZLVx9m7rY p0IIxgubjwvkqdJkZOYgHYY0X3Wq1WRkEHbMwpUQKXudiOqqgjTEue5sP6ID8sjHfC8v B5i0xbLNU5iISFtC7fTJ6dSQ5cjN3FfqHWsvklsORUoO7N8dNeZCgIg15lKH9Y9HFLmS NGDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kQSg2i/Ac80K0jAziGOYyPLFhndPkdJmNK9JQDMSPxs=; b=LYI4znxMvxf7vQBeISu7DV0gEWj7cQmsKP4Yp6KffFJJeEOSa2xCt4rNZF6jfHvEj5 SrsvIu/FSGLM8pLjhq3ulZZnjpU2qHq9YkozMqJFmkWRTqUu6ScDeNX1tnvJdRsvb+yF 9rYhL7jcXYqx8tzQAtU5KtTroUZxZQiyxnGHDWCufRIFv8D+WIcOP3nnTkQ0slE2L/Vo kH5EYQUID12aoq2sjeWScUfzAxJ0TEz+ds8Mi69zaTeM+olWxiB83WskbgSB3XLUg+oy N8p3xLBO4XJNOwmpVR0HMz0wsjeqr4KiXwztg2Ziic2EOiNfeMPJpUN2fCVU9X0ZrXmK 8q7w== X-Gm-Message-State: AOAM531RvJaVbO/+3v0uhwQm46L/q8xvg8mFVQM3yVc0B4bvcSkKuet6 nH7KySruyx8j8wtK4DwN7wg25ClZgFhL8Q== X-Received: by 2002:a17:90a:fe89:: with SMTP id co9mr1293740pjb.83.1613000752495; Wed, 10 Feb 2021 15:45:52 -0800 (PST) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id w124sm3377569pfw.176.2021.02.10.15.45.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 15:45:52 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v7 3/6] Bluetooth: btintel: Consolidate intel_version_tlv parsing Date: Wed, 10 Feb 2021 15:45:46 -0800 Message-Id: <20210210234549.2293917-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210210234549.2293917-1-luiz.dentz@gmail.com> References: <20210210234549.2293917-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This moves checks version checks of intel_version_tlv to btintel_version_info_tlv. Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel.c | 50 ++++++++++++++++++++++++++++++--- drivers/bluetooth/btintel.h | 2 +- drivers/bluetooth/btusb.c | 56 ++----------------------------------- 3 files changed, 50 insertions(+), 58 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index 6c45e86a8a72..c907a4d6b37c 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -372,10 +372,53 @@ int btintel_read_version(struct hci_dev *hdev, struct intel_version *ver) } EXPORT_SYMBOL_GPL(btintel_read_version); -void btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *version) +int btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *version) { const char *variant; + /* The hardware platform number has a fixed value of 0x37 and + * for now only accept this single value. + */ + if (INTEL_HW_PLATFORM(version->cnvi_bt) != 0x37) { + bt_dev_err(hdev, "Unsupported Intel hardware platform (0x%2x)", + INTEL_HW_PLATFORM(version->cnvi_bt)); + return -EINVAL; + } + + /* Check for supported iBT hardware variants of this firmware + * loading method. + * + * This check has been put in place to ensure correct forward + * compatibility options when newer hardware variants come along. + */ + switch (INTEL_HW_VARIANT(version->cnvi_bt)) { + case 0x17: /* TyP */ + case 0x18: /* Slr */ + case 0x19: /* Slr-F */ + break; + default: + bt_dev_err(hdev, "Unsupported Intel hardware variant (0x%x)", + INTEL_HW_VARIANT(version->cnvi_bt)); + return -EINVAL; + } + + /* It is required that every single firmware fragment is acknowledged + * with a command complete event. If the boot parameters indicate + * that this bootloader does not send them, then abort the setup. + */ + if (version->limited_cce != 0x00) { + bt_dev_err(hdev, "Unsupported Intel firmware loading method (0x%x)", + version->limited_cce); + return -EINVAL; + } + + /* Secure boot engine type should be either 1 (ECDSA) or 0 (RSA) */ + if (version->sbe_type > 0x01) { + bt_dev_err(hdev, "Unsupported Intel secure boot engine type (0x%x)", + version->sbe_type); + return -EINVAL; + } + switch (version->img_type) { case 0x01: variant = "Bootloader"; @@ -397,15 +440,14 @@ void btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *ve break; default: bt_dev_err(hdev, "Unsupported image type(%02x)", version->img_type); - goto done; + return -EINVAL; } bt_dev_info(hdev, "%s timestamp %u.%u buildtype %u build %u", variant, 2000 + (version->timestamp >> 8), version->timestamp & 0xff, version->build_type, version->build_num); -done: - return; + return 0; } EXPORT_SYMBOL_GPL(btintel_version_info_tlv); diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h index 51f1f2c883b4..94a63e898826 100644 --- a/drivers/bluetooth/btintel.h +++ b/drivers/bluetooth/btintel.h @@ -149,7 +149,7 @@ int btintel_set_diag_mfg(struct hci_dev *hdev, bool enable); void btintel_hw_error(struct hci_dev *hdev, u8 code); void btintel_version_info(struct hci_dev *hdev, struct intel_version *ver); -void btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *version); +int btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *version); int btintel_secure_send(struct hci_dev *hdev, u8 fragment_type, u32 plen, const void *param); int btintel_load_ddc_config(struct hci_dev *hdev, const char *ddc_name); diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 115a8ccb1468..23d2af4b0433 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -2532,15 +2532,6 @@ static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev, if (!ver || !boot_param) return -EINVAL; - /* The hardware platform number has a fixed value of 0x37 and - * for now only accept this single value. - */ - if (INTEL_HW_PLATFORM(ver->cnvi_bt) != 0x37) { - bt_dev_err(hdev, "Unsupported Intel hardware platform (0x%2x)", - INTEL_HW_PLATFORM(ver->cnvi_bt)); - return -EINVAL; - } - /* The firmware variant determines if the device is in bootloader * mode or is running operational firmware. The value 0x03 identifies * the bootloader and the value 0x23 identifies the operational @@ -2559,49 +2550,6 @@ static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev, btintel_check_bdaddr(hdev); } - /* Check for supported iBT hardware variants of this firmware - * loading method. - * - * This check has been put in place to ensure correct forward - * compatibility options when newer hardware variants come along. - */ - switch (INTEL_HW_VARIANT(ver->cnvi_bt)) { - case 0x17: /* TyP */ - case 0x18: /* Slr */ - case 0x19: /* Slr-F */ - break; - default: - bt_dev_err(hdev, "Unsupported Intel hardware variant (0x%x)", - INTEL_HW_VARIANT(ver->cnvi_bt)); - return -EINVAL; - } - - /* If the device is not in bootloader mode, then the only possible - * choice is to return an error and abort the device initialization. - */ - if (ver->img_type != 0x01) { - bt_dev_err(hdev, "Unsupported Intel firmware variant (0x%x)", - ver->img_type); - return -ENODEV; - } - - /* It is required that every single firmware fragment is acknowledged - * with a command complete event. If the boot parameters indicate - * that this bootloader does not send them, then abort the setup. - */ - if (ver->limited_cce != 0x00) { - bt_dev_err(hdev, "Unsupported Intel firmware loading method (0x%x)", - ver->limited_cce); - return -EINVAL; - } - - /* Secure boot engine type should be either 1 (ECDSA) or 0 (RSA) */ - if (ver->sbe_type > 0x01) { - bt_dev_err(hdev, "Unsupported Intel secure boot engine type (0x%x)", - ver->sbe_type); - return -EINVAL; - } - /* If the OTP has no valid Bluetooth device address, then there will * also be no valid address for the operational firmware. */ @@ -3036,7 +2984,9 @@ static int btusb_setup_intel_newgen(struct hci_dev *hdev) return err; } - btintel_version_info_tlv(hdev, &version); + err = btintel_version_info_tlv(hdev, &version); + if (err) + return err; err = btusb_intel_download_firmware_newgen(hdev, &version, &boot_param); if (err) -- 2.26.2