Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1856ybh; Wed, 11 Mar 2020 19:21:36 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtYyiiH+9q6dxVTpqArA9XZBz+o3P3OI4i65hVofJnB7a32e3yfCYToiYqHRAxTFetN/jry X-Received: by 2002:a9d:4e16:: with SMTP id p22mr4832027otf.152.1583979695587; Wed, 11 Mar 2020 19:21:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583979695; cv=none; d=google.com; s=arc-20160816; b=Z52kYDIMlYKJ6HCtFHQKDuhk5OJuWhizbQ49tj7LsFL4wV5iaHkLhV451RlYctLm3r JD06JlX5KI8b8ysr+a3wco12FEnDJTCXptYfqGEweQ2LSPm3kFS1RDNOeEP5EoVdqNQD 2gF3jFDlawT6JTBfEZs3/18xNxjxRTeSX5OFSW5Oq0xXAMc35lwf/VtukN3NEqbr8DJk MU50yeZRmlP+GUgcYsM6QCo7z4wu+kYgTfl9suuCK8aCekyiI7jM99EzKV6MBOx3nwVG nOXJ2KepcasOvU2sMVYvfuEzasoI9fcZ9hHDs4N8MMKWeNbyfe6ioWzAF7M/g/aRsXFb vgEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=rcj6bBjC8eeTo0oFTOG03100dOPRd+sT+MeVFj1k6mA=; b=TULO/8je+S6RxFPNQbJjlR7cpDuYQMJHwZ/oDbtH7Pa7xxtDdbAaWOOXCHEEeHqeTD RCajT0DJGKC/tBZh62996ox9XKQZ44hiCx8W7O95Paz7KzpYADMptawqwDu6HsTaprUh Pgj/i6cPaXzVL7BRe+n55Zuk955NaML9r5ZNa8wR0M4YvVEzBVsexX0Vi+fhEWSUP72F Wq3BQv4X9RaEbanJGX2bClhM2fckEbZE1uVEhJQ0Vho07o6C0k25ih3SxsLcGt9LKUmF jACDuYxU2Y55koDBJy5MnJIYpXVbLE0TldMbHzjpKJZEFYVyDw4fCKSOdlX9wiVeQ00k q37A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TN0Hk9Vl; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si928778ooq.16.2020.03.11.19.20.55; Wed, 11 Mar 2020 19:21:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TN0Hk9Vl; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387656AbgCLCUW (ORCPT + 99 others); Wed, 11 Mar 2020 22:20:22 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:34406 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387404AbgCLCUW (ORCPT ); Wed, 11 Mar 2020 22:20:22 -0400 Received: by mail-pf1-f202.google.com with SMTP id s13so2767413pfe.1 for ; Wed, 11 Mar 2020 19:20:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=rcj6bBjC8eeTo0oFTOG03100dOPRd+sT+MeVFj1k6mA=; b=TN0Hk9Vlr9nUe66Kfks1oZvflGet0NTOh+FTOaukrvmsiQhyz1hkirVE+pcJxrjokZ tWHYqt2TtIzz6QyFRErqrCDZwcVWklLYXQZDzeVDAuhDgfxSOz+cAALYjVcLaf318zoq rYRp9b3Mr5gbqIBu20VCBrksnpjvymocYkKKwwqzWWzy6vCuxvYc7jRZ122sol6tkEG2 JNxlRbJeYLeThZ2E8c/nXi5wrlyGbVPjq+WstnjMY3t5Fed27YW9+Thl1iVkflatHe0O HLpcY2gt0NQUocPF6a1eJLfZkrCYL8h/SStFxJXpeH74sZTNpuxv1c21ofZyHAWGZMfT iLZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=rcj6bBjC8eeTo0oFTOG03100dOPRd+sT+MeVFj1k6mA=; b=NnghNo1wXSx1nXaG9eIw/bfG3YW4qZ4zaRzZJ7cgqsqQ1Gp+rO8ZZyn69a8AHM03Mx C6tA9RJWQhcqDU4/u1QP8AUiNMkThsCCAEuTUnUlxewPoh5mG/wjpldLiw/yFil4q8mt fl7yqvSeNR8/vclTDrcLCyAGbq1jcT/RyIuWibyfVlbf3MT4LlaE3kyKbu4WUmCpW8Tc VTWJRccpYiODprvt35KRQz086E0aSw4JKsIO+P/gyE9tbXqBB9MV2P4andno0z9THd8/ Hby21mGI2iR9GS9Fx9egce8rfLAT0oGWS7Y6igV/4gGkxbpNNv+2QyRO7YzbJEuSLMKe 4UBQ== X-Gm-Message-State: ANhLgQ3Y81MkCIqBnS/g1rkWnb7UOihXzZ967qAOv37YzzCw//QPxLIg NEE56fyqCeLj5EC1uQFgUUlA11kIRx2Epw== X-Received: by 2002:a17:90a:cf0c:: with SMTP id h12mr1679625pju.164.1583979619855; Wed, 11 Mar 2020 19:20:19 -0700 (PDT) Date: Wed, 11 Mar 2020 19:20:14 -0700 Message-Id: <20200311191939.v2.1.I12c0712e93f74506385b67c6df287658c8fdad04@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog Subject: [PATCH v2] Bluetooth: clean up connection in hci_cs_disconnect From: Manish Mandlik To: marcel@holtmann.org Cc: Alain Michaud , linux-bluetooth@vger.kernel.org, Miao-chen Chou , Joseph Hwang , Yoni Shavit , Manish Mandlik , "David S. Miller" , Johan Hedberg , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jakub Kicinski Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Joseph Hwang In bluetooth core specification 4.2, Vol 2, Part E, 7.8.9 LE Set Advertise Enable Command, it says The Controller shall continue advertising until ... or until a connection is created or ... In these cases, advertising is then disabled. Hence, advertising would be disabled before a connection is established. In current kernel implementation, advertising would be re-enabled when all connections are terminated. The correct disconnection flow looks like < HCI Command: Disconnect > HCI Event: Command Status Status: Success > HCI Event: Disconnect Complete Status: Success Specifically, the last Disconnect Complete Event would trigger a callback function hci_event.c:hci_disconn_complete_evt() to cleanup the connection and re-enable advertising when proper. However, sometimes, there might occur an exception in the controller when disconnection is being executed. The disconnection flow might then look like < HCI Command: Disconnect > HCI Event: Command Status Status: Unknown Connection Identifier Note that "> HCI Event: Disconnect Complete" is missing when such an exception occurs. This would result in advertising staying disabled forever since the connection in question is not cleaned up correctly. To fix the controller exception issue, we need to do some connection cleanup when the disconnect command status indicates an error. Signed-off-by: Joseph Hwang Signed-off-by: Manish Mandlik --- Changes in v2: - Moved "u8 type" declaration inside if block net/bluetooth/hci_event.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index a40ed31f6eb8f..a116114279107 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2202,10 +2202,22 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status) hci_dev_lock(hdev); conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); - if (conn) + if (conn) { + u8 type = conn->type; + mgmt_disconnect_failed(hdev, &conn->dst, conn->type, conn->dst_type, status); + /* If the disconnection failed for any reason, the upper layer + * does not retry to disconnect in current implementation. + * Hence, we need to do some basic cleanup here and re-enable + * advertising if necessary. + */ + hci_conn_del(conn); + if (type == LE_LINK) + hci_req_reenable_advertising(hdev); + } + hci_dev_unlock(hdev); } -- 2.25.1.481.gfbce0eb801-goog