Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp959833ybh; Tue, 10 Mar 2020 11:38:46 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsRzgU4ToYzX6+P91uEhjHb2V2Od84GLI57vN+jfxFMkjmdVdzHSqPYUGXpSZ/KsCvmoLm/ X-Received: by 2002:aca:4b95:: with SMTP id y143mr2118351oia.36.1583865526315; Tue, 10 Mar 2020 11:38:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583865526; cv=none; d=google.com; s=arc-20160816; b=YhQtWMJgzndJPXeoQW6Zzx3KlJUZFJrmzUDPsQz3ZzO5yhLL2QW5XT3l1bKHKSfFnA SJUHvHORhlyZjCFB465rJw2oKbaFKm/Ddbm9qFKdnrmg3WDUNRzQmfpm/mMxpAFVq2Sk FxoOAdz2scDccv7Q/8bMDtIA8pm7HyAJAzKQX6oiYOjvGbo1lsIO/7mflrIg2Mm6L2Rf MnmChEQfW43PcQ2iGnguKZ4f65spmNCEskCKNzm4Q79D6hwo80WtHO4iMP6y38HKx4NN BlhQVh+srgYAkY7aaPbf+w2Kbgk0iX0UfEMd9/Z9qFA9/EmEEmbIiARor7XGyXFccCZ4 80wQ== 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=DVW9btlrE9WxdPGCCpJUK2ALvJluBH0kWl1F121tkv8=; b=fOVp5BpBLtywI+Un945i1JK9x8qvTN9RXKss3xDHARpwW+yBDCwuutB6yrPMuUx/+l VSPA3Yp0y/DQcwi55XiJfIakZHRXuojlLkqxhzg3Rf169bSNjB0P1C+AMXf9Lrq7/9lc 1NSd8NKIxmVSC1QzC7P6iNNE+Niz53xHpJYyOkdlnPGGuy/l5JYGZici21czdpum6bo/ yXIMwXccb6xUjaycNPmQntfgltcA6UJhy4KCz/Ld7Ns8iQ1ib5qNahsXGOXIGRVg0ZX8 Fnff10dOg/Uo4w5O5uNowNaCDndLJuU72hGrSc+An42PX8NDi9S5Fg+V2yMIRZuHVET4 SMcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IOTPbncC; 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 v1si1362190oix.209.2020.03.10.11.38.35; Tue, 10 Mar 2020 11:38:46 -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=IOTPbncC; 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 S1726391AbgCJSid (ORCPT + 99 others); Tue, 10 Mar 2020 14:38:33 -0400 Received: from mail-qt1-f202.google.com ([209.85.160.202]:55560 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726283AbgCJSid (ORCPT ); Tue, 10 Mar 2020 14:38:33 -0400 Received: by mail-qt1-f202.google.com with SMTP id o10so9700084qtk.22 for ; Tue, 10 Mar 2020 11:38:33 -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=DVW9btlrE9WxdPGCCpJUK2ALvJluBH0kWl1F121tkv8=; b=IOTPbncCEhJ6Tlz1Iw6Gu+n2Ojfh6tB5pWO5AS2+hXov1EUWbLSoF7wSBUH20ovyt7 zxQlcZcCR/aX7jbuBwKpop15IyvI5jXWDoBQ2bMeD5UarniqqgyoP6g8a2UCA3SFd7l4 gs8EqISUW8RauHWE3mWMnRQFsk3kB4EQwyss7hkvcD7jGfOyr0mD4ZNXbVPzmQRKa4XG 3tMuVRUC351yCD4XC9LcUIumBkpJFggMJpk22rPpdmmjpx6mHT5dKqudgULcsj8HzLh5 5KFvUzlCPS1HyTGUrmGKaEuGzu9Xo/yq+rY1aul7UuhME44YuhNJueGBdclGJrLKxXPt W5eA== 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=DVW9btlrE9WxdPGCCpJUK2ALvJluBH0kWl1F121tkv8=; b=kGB8Dn43KBJlTJESA9H81PqcooUYdiOfJyQEkooOlYBGL5mUq0VQ0OWNrEz4RXHGbm Fn8LAy1quRW91l2dkcr2UTqnkKPZQdSeis1zr5ah2RLFZPP9WDv8+aHv9YiApvjTZ6N8 zfwo7avEBMO6Wxb1TdoFqBodFOVAOedA3iiJZfFVTbmWiFaP3hadgYNfIAmNJ35xDz9d eQ8gbZ3bixfMBTBq3/dW3XMRNMmcKp/vKdQm5ZLgsmU5/XRZIkiGN7ZphBsurmgRqmRA u4rrlxgZfyK5z4xoohmYU3hWFx4iQJDTvnzuwT0KRB30PIFsf9hCElXcvx1CniC4c1xJ 1igQ== X-Gm-Message-State: ANhLgQ00p3V1RScTiMxm5bGktszv5g6+QmbjVLvCvO9kwRiOiypzxKCO tHDYQJg1oNAj1MYTQ/R0U+CU8zAXCXXEfQ== X-Received: by 2002:a0c:90a2:: with SMTP id p31mr11609515qvp.2.1583865512672; Tue, 10 Mar 2020 11:38:32 -0700 (PDT) Date: Tue, 10 Mar 2020 11:38:27 -0700 Message-Id: <20200310113816.1.I12c0712e93f74506385b67c6df287658c8fdad04@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog Subject: [PATCH] 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 --- 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..7f7e5ba3974a8 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2191,6 +2191,7 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status) { struct hci_cp_disconnect *cp; struct hci_conn *conn; + u8 type; if (!status) return; @@ -2202,10 +2203,21 @@ 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) { 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. + */ + type = conn->type; + hci_conn_del(conn); + if (type == LE_LINK) + hci_req_reenable_advertising(hdev); + } + hci_dev_unlock(hdev); } -- 2.25.1.481.gfbce0eb801-goog