Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp130742pxf; Wed, 24 Mar 2021 00:43:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx23pCHIelryyWoRDS58zANZigOLbOKvTmv4emBajteo3iU5YlaczSTaGePQWYdL+oAITj2 X-Received: by 2002:a05:6402:34c4:: with SMTP id w4mr2032670edc.367.1616571812920; Wed, 24 Mar 2021 00:43:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616571812; cv=none; d=google.com; s=arc-20160816; b=iziwGHe8pHDBI0DcJfXhZLcmNFdkbSMcTkXyb+iNO++IjaduRWIocScAE7QVp99jNQ XS1KlqHBCffRrMDztUynGwnnayd3aRjfhHiR3xAe7eO6GjYrIXpnlubjT52l6iHeP/FF nQq4kygVGtSH+mHMztL/iehn6i4HNJ7kDl9Y2VtGEQ1uO6wMvgN9Z3RXQGeBz7suwC9G 3MgOkbZN7ZfYvaX/NEqGcYrFEwcfKK6Vts5uHd7Jb0ROdqOY7MFpKNFdi1l+XS4MdsCi dVvIg5mPzRoaGYQMq/SENGzBbonRaYevNksEocugcKFKl0u5R/cGJ6Dyge0X//4jiIJc NAHQ== 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=o4VR66b72NDwj9AcA+Kn10dg4DS4Df355mwoHIeLOss=; b=bv6Mt3q6n/F8kiAJ+Be8jaegS1jYGZbLt9zq3kT2ZiFsMjuVHzSyIsuElqUke4DW3t mss2qXBf31oi+rkTjDo95vZtVNPSP51Jjy7kTAz5TT+DY4odu8kmVB+cOiluc2rxUGtf ehK6OZzHtJi5clLjpvcojvs2svKtdO3uyuLs2p/M/cK+WI/VzgbRUShPhr79KDnyeiml 2uI26SR5dyDnqTrxODqLC7+05+R9VbpzMh0FISoigOKdvZy6lml2Gn4MtiOXvJBDyDzf 0vTPdeu8UoAqIN2J4gpbBy2/AEbfyyhr0ABdAxdFNxiYdykoLRtcvGM6TsyVi6QgTm3l WjOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rfI78seF; 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 nb32si1270549ejc.369.2021.03.24.00.43.10; Wed, 24 Mar 2021 00:43:32 -0700 (PDT) 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=rfI78seF; 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 S232376AbhCWS7P (ORCPT + 99 others); Tue, 23 Mar 2021 14:59:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232408AbhCWS7H (ORCPT ); Tue, 23 Mar 2021 14:59:07 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77C04C061574 for ; Tue, 23 Mar 2021 11:59:07 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id ot17-20020a17090b3b51b0290109c9ac3c34so10329377pjb.4 for ; Tue, 23 Mar 2021 11:59:07 -0700 (PDT) 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=o4VR66b72NDwj9AcA+Kn10dg4DS4Df355mwoHIeLOss=; b=rfI78seF8S79HpN3BHKZZmyhWVANags/XVD87Hb8wQX07fTh13Ab7iBxQ5AoNLfhls B32NDXV51awBnyChHbvqytHn9h729uX3FCUYL+MDcUWucg3GYE1y7bb+JA+SezTb4NYl VtDjWKFf0IlJj7dp4/bmdHNo7vaZA2i9TRtJCFIulmY2eKsBULd0vnWik7SWES8ZkF0v O4g+ISoiaYPQL6k0CFlTlVH3l2pLyZa04YaSpqnr/xlG0Rvn1ma9j0MfTWgoilEaxVjR ajDc1IRCv8yNknPzu8MTP0a8/CvNG27p/J0RImGSk3eHaGaifiBhwpjetupc74P1INxa PXTQ== 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=o4VR66b72NDwj9AcA+Kn10dg4DS4Df355mwoHIeLOss=; b=oWBrAI+OUAhe07ezc1IwcUjU3VjCK18MfVf3YMXBChVZOnIDIVQFasuGUNu2YYEg5/ 3ta/kaMgcK9GosAvLFRqm15ER0lNGZ4VyipFZo+dHZ3+Idpud0b3PejWSjqo5lma/jat 1cUrZNt7P70z9mh0hwi7WA266g/ks3LmPclLYUKLGdq0yJRui92r5Jr2xv+HRL2T3j6g gXHyqGhs0IX2oYldBDMRxDtUyK1NLGRD+GV4oaMdmkhFGr8koxtkLSNXpBLABHNPOLQu ND2nGR3hEcytWXiqZ84b9zGCUf/fbYfbXTtDOJSySK7jffB+QZtvLS5AHEG1oJnEO5V8 NmJA== X-Gm-Message-State: AOAM531n06w2qH2TxFQYZ7sk1rfcBHy76Or77I6hhBKfcP/Jxbr0+WH8 Y/3//CKWmFyEhNqCNtvfd61/nzhdzJd6sA== X-Received: by 2002:a17:90a:ff91:: with SMTP id hf17mr6129435pjb.34.1616525946626; Tue, 23 Mar 2021 11:59:06 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b10sm16132325pgm.76.2021.03.23.11.59.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 11:59:06 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v10 2/9] Bluetooth: btintel: Move operational checks after version check Date: Tue, 23 Mar 2021 11:58:57 -0700 Message-Id: <20210323185904.3372987-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210323185904.3372987-1-luiz.dentz@gmail.com> References: <20210323185904.3372987-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 In order to allow new firmware to load, it first needs to check if the firmware version on file matches the one loaded if it doesn't, then it needs to revert to bootloader mode in order to load the new firmware. Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel.c | 22 ++++++++++++ drivers/bluetooth/btusb.c | 68 +++++++++++++------------------------ 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index 3ff698a0bd25..13bc93a986c7 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -958,6 +958,17 @@ int btintel_download_firmware(struct hci_dev *hdev, } } + /* The firmware variant determines if the device is in bootloader + * mode or is running operational firmware. The value 0x06 identifies + * the bootloader and the value 0x23 identifies the operational + * firmware. + * + * If the firmware version has changed that means it needs to be reset + * to bootloader when operational so the new firmware can be loaded. + */ + if (ver->fw_variant == 0x23) + return -EINVAL; + err = btintel_sfi_rsa_header_secure_send(hdev, fw); if (err) return err; @@ -985,6 +996,17 @@ int btintel_download_firmware_newgen(struct hci_dev *hdev, return -EALREADY; } + /* The firmware variant determines if the device is in bootloader + * mode or is running operational firmware. The value 0x01 identifies + * the bootloader and the value 0x03 identifies the operational + * firmware. + * + * If the firmware version has changed that means it needs to be reset + * to bootloader when operational so the new firmware can be loaded. + */ + if (ver->img_type == 0x03) + return -EINVAL; + /* iBT hardware variants 0x0b, 0x0c, 0x11, 0x12, 0x13, 0x14 support * only RSA secure boot engine. Hence, the corresponding sfi file will * have RSA header of 644 bytes followed by Command Buffer. diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index de220ab7f231..a30f7ea9be36 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -2402,11 +2402,17 @@ static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb) return -EILSEQ; } -static bool btusb_setup_intel_new_get_fw_name(struct intel_version *ver, +static int btusb_setup_intel_new_get_fw_name(struct intel_version *ver, struct intel_boot_params *params, char *fw_name, size_t len, const char *suffix) { + /* The hardware platform number has a fixed value of 0x37 and + * for now only accept this single value. + */ + if (ver->hw_platform != 0x37) + return -EINVAL; + switch (ver->hw_variant) { case 0x0b: /* SfP */ case 0x0c: /* WsP */ @@ -2426,9 +2432,10 @@ static bool btusb_setup_intel_new_get_fw_name(struct intel_version *ver, suffix); break; default: - return false; + return -EINVAL; } - return true; + + return 0; } static void btusb_setup_intel_newgen_get_fw_name(const struct intel_version_tlv *ver_tlv, @@ -2483,7 +2490,6 @@ static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev, if (ver->img_type == 0x03) { clear_bit(BTUSB_BOOTLOADER, &data->flags); btintel_check_bdaddr(hdev); - return 0; } /* Check for supported iBT hardware variants of this firmware @@ -2628,35 +2634,6 @@ static int btusb_intel_download_firmware(struct hci_dev *hdev, if (!ver || !params) return -EINVAL; - /* The hardware platform number has a fixed value of 0x37 and - * for now only accept this single value. - */ - if (ver->hw_platform != 0x37) { - bt_dev_err(hdev, "Unsupported Intel hardware platform (%u)", - ver->hw_platform); - 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 (ver->hw_variant) { - case 0x0b: /* SfP */ - case 0x0c: /* WsP */ - case 0x11: /* JfP */ - case 0x12: /* ThP */ - case 0x13: /* HrP */ - case 0x14: /* CcP */ - break; - default: - bt_dev_err(hdev, "Unsupported Intel hardware variant (%u)", - ver->hw_variant); - return -EINVAL; - } - btintel_version_info(hdev, ver); /* The firmware variant determines if the device is in bootloader @@ -2675,16 +2652,18 @@ static int btusb_intel_download_firmware(struct hci_dev *hdev, if (ver->fw_variant == 0x23) { clear_bit(BTUSB_BOOTLOADER, &data->flags); btintel_check_bdaddr(hdev); - return 0; - } - /* 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->fw_variant != 0x06) { - bt_dev_err(hdev, "Unsupported Intel firmware variant (%u)", - ver->fw_variant); - return -ENODEV; + /* SfP and WsP don't seem to update the firmware version on file + * so version checking is currently possible. + */ + switch (ver->hw_variant) { + case 0x0b: /* SfP */ + case 0x0c: /* WsP */ + return 0; + } + + /* Proceed to download to check if the version matches */ + goto download; } /* Read the secure boot parameters to identify the operating @@ -2712,6 +2691,7 @@ static int btusb_intel_download_firmware(struct hci_dev *hdev, set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); } +download: /* With this Intel bootloader only the hardware variant and device * revision information are used to select the right firmware for SfP * and WsP. @@ -2735,7 +2715,7 @@ static int btusb_intel_download_firmware(struct hci_dev *hdev, */ err = btusb_setup_intel_new_get_fw_name(ver, params, fwname, sizeof(fwname), "sfi"); - if (!err) { + if (err < 0) { bt_dev_err(hdev, "Unsupported Intel firmware naming"); return -EINVAL; } @@ -2908,7 +2888,7 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) err = btusb_setup_intel_new_get_fw_name(&ver, ¶ms, ddcname, sizeof(ddcname), "ddc"); - if (!err) { + if (err < 0) { bt_dev_err(hdev, "Unsupported Intel firmware naming"); } else { /* Once the device is running in operational mode, it needs to -- 2.30.2