Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp133300ybj; Wed, 6 May 2020 13:21:37 -0700 (PDT) X-Google-Smtp-Source: APiQypKFeieT4dssX570//kb42HhAv3grpnxSZ62kiWkY2NlZYerEW73E5Cuo/ly1s1Z/17cl8j6 X-Received: by 2002:a17:906:85c3:: with SMTP id i3mr6881230ejy.280.1588796497510; Wed, 06 May 2020 13:21:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588796497; cv=none; d=google.com; s=arc-20160816; b=rdlpRm5z2YVEE7I5DqUR8Q1+RKxvI/diONErvUOLAdiyYOOwFoKEtS79fW9nOM3cEH l+rUjdnxhutWUeBykQBB5L0OFK0LW+RJ3ry3WoX0km+ZPAl6RGbfEK1N1dBb+jmQ/8MO UrlgB63bI6liwUlvsp1dXYt6svHjpehurt9psLH6DrMyiXuDK/P6TehLowNFI0/1pavB tIDsrNXLk91mXKn0PkmsiT0cpiG2E68B5+2ALtVPILqVCBRIs/b6TCnuD8DyHS2QpJ6I pYVgVaIDsI3LKT73kGAJGbgIQXV174qQdeQp/Ypz0SziwdQg5+te7/TgnyxYoXpGm7z8 7ZLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=1mIMJgVSnAO/W/jn4dWXlCE37Art7UsCVU3EaRnqhxo=; b=I9wN5pesYe6IfMnvCX7qDDUA1Jfllo1K6A8lxQnd2xwFOQX4Y6omxONRmcUJcdiBbd VjPoNCaRC2TtoZzfjbcy6CKBac/6wCNU6d99sp+CZTW2P3GZ0FTMpVslo6JMNNcqi2N0 8rUiD3/cljF5mHMf6mqgg5POiHwhX3HK0xefONRuPjqlzxTMePqhLb7THxtWOtnn3p3N MRnZizX3C5pWtdWt6xWoXD1hx5Se30pDHppWo5oYstp665CAaHAnUpbpdporatvO0laU RyxFKdYBmemBF6+sSOum3k9ofBhC0wVo307Bo/3mrrbp7neRX5qQ1RFPFbn+bOVo6WSU MRZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Aw2HFcIH; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d4si1941603edy.155.2020.05.06.13.21.13; Wed, 06 May 2020 13:21:37 -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=@chromium.org header.s=google header.b=Aw2HFcIH; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726885AbgEFTzo (ORCPT + 99 others); Wed, 6 May 2020 15:55:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726495AbgEFTzo (ORCPT ); Wed, 6 May 2020 15:55:44 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55D81C061A0F for ; Wed, 6 May 2020 12:55:44 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id 18so1598710pfx.6 for ; Wed, 06 May 2020 12:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1mIMJgVSnAO/W/jn4dWXlCE37Art7UsCVU3EaRnqhxo=; b=Aw2HFcIHfekl9CQ54N9ZMus/UDga8fS8CMbjm3nCVs1WWNMGLZnGA4MagsDyudclq4 MVm2W1KT1Tot5gpAI4SffCZnLBYm3zjxi9dONdd/IuBbBpnfyoZV56Iv4a97QoU6VwaX de6DjfG755LlzUN0TNTH4mniejGFiLIb6LLUI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1mIMJgVSnAO/W/jn4dWXlCE37Art7UsCVU3EaRnqhxo=; b=Ptr8NX29viBgVvWRpT/N9kj2bVpMcR14eAkyGBp+bYNdMWGn3oJBWv6odnWLtq9H6f oj6K8yaILBXWfbhrTkRM55wmRiFSTAy42WyweaM2/pqaksNseEsLJbzPSebmwiHykRmH 6X4fcH1hYsMlgQf5LcZ2kbLyZ72Oibzqaj+hkD+zywnxMxmZtVHyfAK0TTVQYgYVbsbB qMSdb3YDO9C54Y3P3N9k5Y7eAKNFT+dH77pD513QcfgLfpKiCetLba1Wwygt3UFj3+94 IkZBwHNzW90IzX9ypSn0qQfS8qzLdSyKb7blXi+XhmQlaDXu4adSrhmXtx07bLIlsSlO p1gg== X-Gm-Message-State: AGi0PuakkO2So/EJ9hFU6BYdAqupNCgt4yyDQf5jlMyjBHThF+6bCUiW WL193y6dnlZlQWYzIGGfmg4gEBDkyQk= X-Received: by 2002:a63:1161:: with SMTP id 33mr8802415pgr.313.1588794943373; Wed, 06 May 2020 12:55:43 -0700 (PDT) Received: from localhost.localdomain (c-73-231-41-185.hsd1.ca.comcast.net. [73.231.41.185]) by smtp.googlemail.com with ESMTPSA id x4sm619986pff.67.2020.05.06.12.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 12:55:42 -0700 (PDT) From: Sonny Sasaka To: linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka Subject: [PATCH] Bluetooth: Handle Inquiry Cancel error after Inquiry Complete Date: Wed, 6 May 2020 12:55:03 -0700 Message-Id: <20200506195503.5837-1-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <89566A98-F0CE-4E70-A344-915E81FB0C14@holtmann.org> References: <89566A98-F0CE-4E70-A344-915E81FB0C14@holtmann.org> Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org After sending Inquiry Cancel command to the controller, it is possible that Inquiry Complete event comes before Inquiry Cancel command complete event. In this case the Inquiry Cancel command will have status of Command Disallowed since there is no Inquiry session to be cancelled. This case should not be treated as error, otherwise we can reach an inconsistent state. Example of a btmon trace when this happened: < HCI Command: Inquiry Cancel (0x01|0x0002) plen 0 > HCI Event: Inquiry Complete (0x01) plen 1 Status: Success (0x00) > HCI Event: Command Complete (0x0e) plen 4 Inquiry Cancel (0x01|0x0002) ncmd 1 Status: Command Disallowed (0x0c) --- net/bluetooth/hci_event.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 3e7badb3ac2d..e8047175de10 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -41,12 +41,28 @@ /* Handle HCI Event packets */ -static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb) +static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb, + u8 *new_status) { __u8 status = *((__u8 *) skb->data); BT_DBG("%s status 0x%2.2x", hdev->name, status); + /* It is possible that we receive Inquiry Complete event right + * before we receive Inquiry Cancel Command Complete event, in + * which case the latter event should have status of Command + * Disallowed (0x0c). This should not be treated as error, since + * we actually achieve what Inquiry Cancel wants to achieve, + * which is to end the last Inquiry session. + */ + if (status == 0x0c && !test_bit(HCI_INQUIRY, &hdev->flags)) { + bt_dev_err(hdev, "Ignoring error of " + "HCI Inquiry Cancel command"); + status = 0x00; + } + + *new_status = status; + if (status) return; @@ -3036,7 +3052,7 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, switch (*opcode) { case HCI_OP_INQUIRY_CANCEL: - hci_cc_inquiry_cancel(hdev, skb); + hci_cc_inquiry_cancel(hdev, skb, status); break; case HCI_OP_PERIODIC_INQ: -- 2.17.1