From patchwork Tue Dec 21 22:33:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 526655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0E70C433EF for ; Tue, 21 Dec 2021 22:34:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237978AbhLUWeA (ORCPT ); Tue, 21 Dec 2021 17:34:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231282AbhLUWd7 (ORCPT ); Tue, 21 Dec 2021 17:33:59 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CE1CC061574 for ; Tue, 21 Dec 2021 14:33:59 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id iy13so520041pjb.5 for ; Tue, 21 Dec 2021 14:33:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=6iNVXPe8Wr5X4KioCLQOVekdEYA1Qv5pozxb090b5Pc=; b=EOyANWbVxt1kC8EKI/n+SeAxMuJkWO2cUOdmLmGGAOjLkFyDuyOwgIsDcAj2utlImF WlckEM5jV/Q+vxAeFcKvyVRRgqXu14EOms76XSVEdHwj7XD9Yif5I3U2rdg/QIZidx9b O90fq4CZy/cQP1CxR0mOqJePAIEiUfILinG92Pb2MhoCbL3iYlz6YzdRmfqraizB1iyl AsLxZq4TUqs+ZQvp57k5q88+45R4EtEFzCUSQ4B8H0zKaf0iuAns8p2RzGkLqY3L1BBX wpK4/s/2KDKTws0cuRmJQgxiveXJazY+Otf0gbEXgMgbw/4w8bMfggboUmvbmBjOzDth sLYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=6iNVXPe8Wr5X4KioCLQOVekdEYA1Qv5pozxb090b5Pc=; b=XmI/QRyavDkycL5UQ5l9YiKw7IdsNYrkFKLBMcfHx2ZsILKlp+UdU98+Ib+rIrNAQu L3qeCIz4A2QBjUUBHPzCrKVPYNbeArRy2hU4Ght6xfVHxsd7QBoDZjhIbweMNEFOrPiy EqubJFkXTtGMLrERx4CCrikcLogpp2J9JyN+OYMM+g7vpAUm8f8c6GaB1Z7zxn/YOMQ9 uaOd4v/vxo0LmH/7NwWGl6H/dtJkKC4de4GtytkVa8x1vCgdnRFGQ7L9QausrNOcB4dO Iu2VayyMt/MhN5uZthvNz90CMXgM4E7RWHsXNMORN3CUfYBzS9zqzZsx59rlIzSOTfg8 4fkw== X-Gm-Message-State: AOAM531SZ9aRgMEtX6vr44pqS0WIkFWIQr1UxE6tli2Wdp+V5vIui7IX vNrOTVtK8fhptQtDrkq+wZRCH+LAiiM= X-Google-Smtp-Source: ABdhPJzrmkZURRWz3pbCJq0vJ3pCH/i42lmuAl/pynWan9Szgti3RUz98O8qlbgJoAS0+Hu4bQ2bqQ== X-Received: by 2002:a17:90b:3e8b:: with SMTP id rj11mr570508pjb.237.1640126038719; Tue, 21 Dec 2021 14:33:58 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id np1sm3872209pjb.22.2021.12.21.14.33.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 14:33:58 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v4 1/4] Bluetooth: hci_sync: Wait for proper events when connecting LE Date: Tue, 21 Dec 2021 14:33:54 -0800 Message-Id: <20211221223357.742863-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz When using HCI_OP_LE_CREATE_CONN wait for HCI_EV_LE_CONN_COMPLETE before completing it and for HCI_OP_LE_EXT_CREATE_CONN wait for HCI_EV_LE_ENHANCED_CONN_COMPLETE before resuming advertising. Signed-off-by: Luiz Augusto von Dentz --- v2: Remove setting of direct_rpa as random address and add a patch checking hdev->le_states if simultaneous roles are supported. v3: Fix checkpatch warnings. v4: Add patch fixing LE simultaneous roles supported vs enabled. net/bluetooth/hci_sync.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 917652b67194..28d62273d67c 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5157,8 +5157,10 @@ int hci_le_ext_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, plen += sizeof(*p); } - return __hci_cmd_sync_status(hdev, HCI_OP_LE_EXT_CREATE_CONN, - plen, data, HCI_CMD_TIMEOUT); + return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_EXT_CREATE_CONN, + plen, data, + HCI_EV_LE_ENHANCED_CONN_COMPLETE, + HCI_CMD_TIMEOUT, NULL); } int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn) @@ -5244,8 +5246,9 @@ int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn) cp.min_ce_len = cpu_to_le16(0x0000); cp.max_ce_len = cpu_to_le16(0x0000); - err = __hci_cmd_sync_status(hdev, HCI_OP_LE_CREATE_CONN, - sizeof(cp), &cp, HCI_CMD_TIMEOUT); + err = __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CREATE_CONN, + sizeof(cp), &cp, HCI_EV_LE_CONN_COMPLETE, + HCI_CMD_TIMEOUT, NULL); done: hci_resume_advertising_sync(hdev); From patchwork Tue Dec 21 22:33:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 527756 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B585C433F5 for ; Tue, 21 Dec 2021 22:34:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237988AbhLUWeA (ORCPT ); Tue, 21 Dec 2021 17:34:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231282AbhLUWeA (ORCPT ); Tue, 21 Dec 2021 17:34:00 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D01FC061574 for ; Tue, 21 Dec 2021 14:34:00 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id j13so362603plx.4 for ; Tue, 21 Dec 2021 14:34:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=soKYwwyCOJe4z6Gm98ynrJwO8MuiwZwsIPVOpruozLU=; b=QBI69fCroG9UJh37eitzVOrMrBJuK6AWIgLBfs54yY56QZtoLO3PuOViYmhih14VTK EoG0KANA3Qxp45hOqwn8knBqKFtL2FG/BrhmEr/WLB4iMHl8pMSvr4xux/ZA+SjANihW B2CmZXf3E+Rm1IKlTvbR5OlNfFbfAQdp0qIE//9/IxOuMqgNjKNSim3yE8d1lhv19DVU iMyoqfPQv143lXirbx4it/RHQaWDntNAMisw4Z5iRJ5YVKLTcA8maDPbqkGIpXknerU/ ZbVx0MiEw8jbUGLNp8eEiK2HJrH4Mhzz8KhBqPdo6DohnFyR5TMvdApsOYheoNf4PSW9 rsJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=soKYwwyCOJe4z6Gm98ynrJwO8MuiwZwsIPVOpruozLU=; b=vaqtElq+zmqZVuLifaCv+dT+7c13i9R3J2mvceE7JcbVDFudaXdSmXeTuas58RSTLT EJ/GNfOwxNa3bQDBs5USFyy2GA3C1sWcLbN7EUsqza5jMWTyuVYE8YeiwsdmWFeAAcJB 0Ebio7isl3ittPhdc6XdXRSbTHK1VTLPSLKvHsFWT2unxSAOacl0/bdXueqGlqouiSxL 4qzoNiqB4swTmTIV0pobXmTGw0T72x6RF46YQJEi4O8CLjsEqSaseX1asFBxfbC9bJ2z HGJFzE7Za8tGU/4lYvBjho6EObwyhjU0wPXH3Z3R2oliFHh6JI1A+I63EO3wrFcCcv4k 0mmQ== X-Gm-Message-State: AOAM531CQ1Oof1/Su378iap2KqZNKJP14RNLCW1/vdJOvcwndN92tiCn yWB0tAo3eaaaVGxt6yl/CX7D1DlfZJA= X-Google-Smtp-Source: ABdhPJxw7y1Qlt8JlY2mWf16v1i0GFcwbTWkoEdjGkScG0eiRFO+sfu2eJAfEC+/rkoSQ7Xtj4Friw== X-Received: by 2002:a17:903:244a:b0:149:14a4:fd36 with SMTP id l10-20020a170903244a00b0014914a4fd36mr187987pls.107.1640126039346; Tue, 21 Dec 2021 14:33:59 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id np1sm3872209pjb.22.2021.12.21.14.33.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 14:33:59 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v4 2/4] Bluetooth: hci_sync: Add check simultaneous roles support Date: Tue, 21 Dec 2021 14:33:55 -0800 Message-Id: <20211221223357.742863-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211221223357.742863-1-luiz.dentz@gmail.com> References: <20211221223357.742863-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This attempts to check if the controller can act as both central and peripheral simultaneously and in case it does skip suspending advertising or in case of directed advertising don't fail if scanning. Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/hci_core.h | 6 ++++++ net/bluetooth/hci_sync.c | 24 ++++++++++++------------ net/bluetooth/mgmt.c | 5 +---- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 1e479ba25c31..cc95b6c3f839 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -782,6 +782,12 @@ extern struct mutex hci_cb_list_lock; hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT); \ } while (0) +#define hci_dev_le_state_simultaneous(hdev) \ + (test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) && \ + (hdev->le_states[4] & 0x08) && /* Central */ \ + (hdev->le_states[4] & 0x40) && /* Peripheral */ \ + (hdev->le_states[3] & 0x10)) /* Simultaneous */ + /* ----- HCI interface to upper protocols ----- */ int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr); int l2cap_disconn_ind(struct hci_conn *hcon); diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 28d62273d67c..6abcf966d001 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5170,30 +5170,29 @@ int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn) u8 own_addr_type; int err; - /* Disable advertising if we're active. For central role - * connections most controllers will refuse to connect if - * advertising is enabled, and for peripheral role connections we - * anyway have to disable it in order to start directed - * advertising. Any registered advertisements will be - * re-enabled after the connection attempt is finished. - */ - hci_pause_advertising_sync(hdev); - /* If requested to connect as peripheral use directed advertising */ if (conn->role == HCI_ROLE_SLAVE) { - /* If we're active scanning most controllers are unable - * to initiate advertising. Simply reject the attempt. + /* If we're active scanning and the controller doesn't support + * simultaneous roles simply reject the attempt. */ if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && - hdev->le_scan_type == LE_SCAN_ACTIVE) { + hdev->le_scan_type == LE_SCAN_ACTIVE && + !hci_dev_le_state_simultaneous(hdev)) { hci_conn_del(conn); return -EBUSY; } + /* Pause advertising while doing directed advertising. */ + hci_pause_advertising_sync(hdev); + err = hci_le_directed_advertising_sync(hdev, conn); goto done; } + /* Disable advertising if simultaneous roles is not supported. */ + if (!hci_dev_le_state_simultaneous(hdev)) + hci_pause_advertising_sync(hdev); + params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); if (params) { conn->le_conn_min_interval = params->conn_min_interval; @@ -5251,6 +5250,7 @@ int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn) HCI_CMD_TIMEOUT, NULL); done: + /* Re-enable advertising after the connection attempt is finished. */ hci_resume_advertising_sync(hdev); return err; } diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 962bb747d2cd..3326d9459dd3 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -3916,10 +3916,7 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, #endif if (hdev) { - if (test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) && - (hdev->le_states[4] & 0x08) && /* Central */ - (hdev->le_states[4] & 0x40) && /* Peripheral */ - (hdev->le_states[3] & 0x10)) /* Simultaneous */ + if (hci_dev_le_state_simultaneous(hdev)) flags = BIT(0); else flags = 0; From patchwork Tue Dec 21 22:33:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 526654 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8F9AC433EF for ; Tue, 21 Dec 2021 22:34:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237985AbhLUWeC (ORCPT ); Tue, 21 Dec 2021 17:34:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237991AbhLUWeC (ORCPT ); Tue, 21 Dec 2021 17:34:02 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D74B0C061574 for ; Tue, 21 Dec 2021 14:34:01 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id v19so351342plo.7 for ; Tue, 21 Dec 2021 14:34:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=BEXaedUJRVwWvaV5+UNIhAI2QJKsPXAblefkp9KOo/s=; b=j3sisNaEsKXNQiNTWvVRZhDLkXfaWM4ev+7FDw884kkvBNXUZPI30Yjyuk0wVio9fU eDmquV1YOyIQSidlG5JsAScWJ+sLuies1oSdBmkitGWdrbujeMySfX1EuJMNloVC/PMt u0yjtYYcXS1kU4FWn9FYuWNbpTo39W4zSYW6rydZiZ8vClr8qTk75R4zqoxyZ2L1F0Pg mZ9MbjdUdah4yWOwNm7Cn//WSqrSB5a2VwOhr/0KHgMPCB5lWUghnHvOJcLJa/In6+88 pIBXrRDPpTrzyYd5H9yn9uZpJHpl96FT1CvGR8Nh9FxmqB3YTzOSOTa9KKxsIylQOEb7 oXYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BEXaedUJRVwWvaV5+UNIhAI2QJKsPXAblefkp9KOo/s=; b=YP/jqI3B0DC0UTKHHLK7YuXp1TEJmGo05EyPPhUJxCI10f6DKRny/0uCFHrDY6IXIg JR1iKZk3k1HmAU+Ey1BHDl5R/GTGEOmqCYOh1Qr9lgjTMXoYHyKWqopO8QOLZ1eOmwU4 sVqQ5bd9FHD20bIS6E2afwCanNzrjk7wikn3DYMlvrNGBy6Zz0TrOs27IIYgFFKjgGW2 60Wn9bUrSiz1gtJ/bvaKhmscDyEb6qaOwo9pKVedf0PI96+0JDQSNasu3qwxMNA+yc6J Te0EeXMwSJXkL0G+bLIE4xBHkaPu4jWljd8E5vRwCgZyFJSGOFPJ60C7KtYJScMYEqhP D37w== X-Gm-Message-State: AOAM532f+UEht/mqaPUz87ul1IodhPzQAMt+2KViGGjOFpYZvYXYpcXN HcqVRNMexM9eWKs2cp2vg4UQDsH4haE= X-Google-Smtp-Source: ABdhPJySiWU/UIbHedpO8MEV0eOtq+SeZ5Iak05UqRjhJGWzgcq3+b7h2VNSma737bkq2Hu8sTH0aA== X-Received: by 2002:a17:902:e749:b0:148:a4e1:4fb4 with SMTP id p9-20020a170902e74900b00148a4e14fb4mr388758plf.111.1640126040974; Tue, 21 Dec 2021 14:34:00 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id np1sm3872209pjb.22.2021.12.21.14.33.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 14:33:59 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v4 3/4] Bluetooth: hci_event: Use skb_pull_data when processing inquiry results Date: Tue, 21 Dec 2021 14:33:56 -0800 Message-Id: <20211221223357.742863-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211221223357.742863-1-luiz.dentz@gmail.com> References: <20211221223357.742863-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This makes each result entry to be checked using skb_pull_data instead of acessing them by index. Signed-off-by: Luiz Augusto von Dentz --- 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 9151d70b36b0..f1082b7c0218 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -4530,7 +4530,15 @@ static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, void *edata, for (i = 0; i < ev->res2->num; i++) { u32 flags; - info = &ev->res2->info[i]; + info = hci_ev_skb_pull(hdev, skb, + HCI_EV_INQUIRY_RESULT_WITH_RSSI, + sizeof(*info)); + if (!info) { + bt_dev_err(hdev, "Malformed HCI Event: 0x%2.2x", + HCI_EV_INQUIRY_RESULT_WITH_RSSI); + return; + } + bacpy(&data.bdaddr, &info->bdaddr); data.pscan_rep_mode = info->pscan_rep_mode; data.pscan_period_mode = info->pscan_period_mode; @@ -4552,7 +4560,15 @@ static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, void *edata, for (i = 0; i < ev->res1->num; i++) { u32 flags; - info = &ev->res1->info[i]; + info = hci_ev_skb_pull(hdev, skb, + HCI_EV_INQUIRY_RESULT_WITH_RSSI, + sizeof(*info)); + if (!info) { + bt_dev_err(hdev, "Malformed HCI Event: 0x%2.2x", + HCI_EV_INQUIRY_RESULT_WITH_RSSI); + return; + } + bacpy(&data.bdaddr, &info->bdaddr); data.pscan_rep_mode = info->pscan_rep_mode; data.pscan_period_mode = info->pscan_period_mode; From patchwork Tue Dec 21 22:33:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 527755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 577AFC433F5 for ; Tue, 21 Dec 2021 22:34:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238008AbhLUWeD (ORCPT ); Tue, 21 Dec 2021 17:34:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237998AbhLUWeD (ORCPT ); Tue, 21 Dec 2021 17:34:03 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2323C061574 for ; Tue, 21 Dec 2021 14:34:02 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id n15-20020a17090a160f00b001a75089daa3so3915427pja.1 for ; Tue, 21 Dec 2021 14:34:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=i4c+OkZqK8xy0FDxlDGdXHUXP3WrkkWpTGWZicu9RTU=; b=lJAsJ7NsCbVD3LQOXYSWUdejrVKGzFBGOwD019A/MIzsNM+XJnC6ryP8ZeWsmEDov3 Qy8nQTU7sKaHPFGE7d4dKfzkUci36oAkWYH/32HGKtvhVornBIMEovZIKhxoKDtwmrLe h4sgQ7tqECpqvsEJlfHZ+ro/VqZ9JoAVr7Er3sgyad93YlcCtxasslk5KQRvqhZ4PYVd SzOAY2J5d4KT5jWKc0NhbawvfTDv797Pc140uIFt03LbvlQp2uGpq0rgzcKC0RO2TyLR hxBp2+P8dQCPUZKW7m8MNg29z58wAEjkwPcYQnvQRmnGUP5BFmLF8IMzyMf2cgPUmSNh 0fzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i4c+OkZqK8xy0FDxlDGdXHUXP3WrkkWpTGWZicu9RTU=; b=q853CK2LC9haSIkNhjvzaPCjwXNcAOykh5eADm9Hf/0XVIIVVzIkXwmaSib8UBUusZ Y1VgbW32FWoPt44lAGlbo5dPzFNE+m80XLp0Dqses6Iz03zOq02amg1wiToLP06kb60F xB8bFa3ER2fNV4uqJ8VpOuXbV7dCWe//cq+5RCw25hDxmF6bxu/qj0/wjH8rm/HNqox1 OzzigfBYHDmrOxtmUZwSDUCzZoh/VUm/LLEWN8Zb1vNSP3FkObmobri1v0KEBfG5iWtY skQvKflc6pyfrMB39ngrsyzPbSvNtgN8iyorgrzmwQHQ7h7tSQezidRYakyBLv6P5HmG m7gQ== X-Gm-Message-State: AOAM531IWBMC33f3EFSDoOx3AEzYdb1NXYVp3zh/dE90DuZ+v+3iyyro shX9UvdNtmFPD2YZ+lAIgywY/ERu8U4= X-Google-Smtp-Source: ABdhPJz59/e8XekAteMKQXwp9FE8N2+O7bnEl/93QEAZXiUYEDl46wQNwL25Jt/PIcdwiMEhsFJqKQ== X-Received: by 2002:a17:902:6a8a:b0:143:905f:aec7 with SMTP id n10-20020a1709026a8a00b00143905faec7mr162000plk.8.1640126042030; Tue, 21 Dec 2021 14:34:02 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id np1sm3872209pjb.22.2021.12.21.14.34.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 14:34:01 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v4 4/4] Bluetooth: MGMT: Fix LE simultaneous roles UUID if not supported Date: Tue, 21 Dec 2021 14:33:57 -0800 Message-Id: <20211221223357.742863-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211221223357.742863-1-luiz.dentz@gmail.com> References: <20211221223357.742863-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz If controller/driver don't support LE simultaneous roles its UUID shall be omitted when responding to MGMT_OP_READ_EXP_FEATURES_INFO. This also rework the support introducing HCI_LE_SIMULTANEOUS_ROLES flag so it can be detected when userspace wants to use or not. Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_sync.c | 10 ++-- net/bluetooth/mgmt.c | 114 +++++++++++++++++++++++------------- 3 files changed, 78 insertions(+), 47 deletions(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 7f5f00ff53da..e2b06bb79e2e 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -341,6 +341,7 @@ enum { HCI_FORCE_NO_MITM, HCI_QUALITY_REPORT, HCI_OFFLOAD_CODECS_ENABLED, + HCI_LE_SIMULTANEOUS_ROLES, __HCI_NUM_FLAGS, }; diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 6abcf966d001..7565238f2b58 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5172,12 +5172,12 @@ int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn) /* If requested to connect as peripheral use directed advertising */ if (conn->role == HCI_ROLE_SLAVE) { - /* If we're active scanning and the controller doesn't support - * simultaneous roles simply reject the attempt. + /* If we're active scanning and simultaneous roles is not + * enabled simply reject the attempt. */ if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && hdev->le_scan_type == LE_SCAN_ACTIVE && - !hci_dev_le_state_simultaneous(hdev)) { + !hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) { hci_conn_del(conn); return -EBUSY; } @@ -5189,8 +5189,8 @@ int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn) goto done; } - /* Disable advertising if simultaneous roles is not supported. */ - if (!hci_dev_le_state_simultaneous(hdev)) + /* Disable advertising if simultaneous roles is not in use. */ + if (!hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) hci_pause_advertising_sync(hdev); params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 3326d9459dd3..6f192efd9da0 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -3882,7 +3882,7 @@ static const u8 offload_codecs_uuid[16] = { }; /* 671b10b5-42c0-4696-9227-eb28d1b049d6 */ -static const u8 simult_central_periph_uuid[16] = { +static const u8 le_simultaneous_roles_uuid[16] = { 0xd6, 0x49, 0xb0, 0xd1, 0x28, 0xeb, 0x27, 0x92, 0x96, 0x46, 0xc0, 0x42, 0xb5, 0x10, 0x1b, 0x67, }; @@ -3915,13 +3915,13 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, } #endif - if (hdev) { - if (hci_dev_le_state_simultaneous(hdev)) + if (hdev && hci_dev_le_state_simultaneous(hdev)) { + if (hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) flags = BIT(0); else flags = 0; - memcpy(rp->features[idx].uuid, simult_central_periph_uuid, 16); + memcpy(rp->features[idx].uuid, le_simultaneous_roles_uuid, 16); rp->features[idx].flags = cpu_to_le32(flags); idx++; } @@ -3992,29 +3992,13 @@ static int exp_ll_privacy_feature_changed(bool enabled, struct hci_dev *hdev, } -#ifdef CONFIG_BT_FEATURE_DEBUG -static int exp_debug_feature_changed(bool enabled, struct sock *skip) -{ - struct mgmt_ev_exp_feature_changed ev; - - memset(&ev, 0, sizeof(ev)); - memcpy(ev.uuid, debug_uuid, 16); - ev.flags = cpu_to_le32(enabled ? BIT(0) : 0); - - return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, NULL, - &ev, sizeof(ev), - HCI_MGMT_EXP_FEATURE_EVENTS, skip); -} -#endif - -static int exp_quality_report_feature_changed(bool enabled, - struct hci_dev *hdev, - struct sock *skip) +static int exp_feature_changed(struct hci_dev *hdev, const u8 *uuid, + bool enabled, struct sock *skip) { struct mgmt_ev_exp_feature_changed ev; memset(&ev, 0, sizeof(ev)); - memcpy(ev.uuid, quality_report_uuid, 16); + memcpy(ev.uuid, uuid, 16); ev.flags = cpu_to_le32(enabled ? BIT(0) : 0); return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, hdev, @@ -4044,7 +4028,7 @@ static int set_zero_key_func(struct sock *sk, struct hci_dev *hdev, bt_dbg_set(false); if (changed) - exp_debug_feature_changed(false, sk); + exp_feature_changed(NULL, ZERO_KEY, false, sk); } #endif @@ -4054,7 +4038,8 @@ static int set_zero_key_func(struct sock *sk, struct hci_dev *hdev, changed = hci_dev_test_and_clear_flag(hdev, HCI_ENABLE_LL_PRIVACY); if (changed) - exp_ll_privacy_feature_changed(false, hdev, sk); + exp_feature_changed(hdev, rpa_resolution_uuid, false, + sk); } hci_sock_set_flag(sk, HCI_MGMT_EXP_FEATURE_EVENTS); @@ -4105,7 +4090,7 @@ static int set_debug_func(struct sock *sk, struct hci_dev *hdev, &rp, sizeof(rp)); if (changed) - exp_debug_feature_changed(val, sk); + exp_feature_changed(hdev, debug_uuid, val, sk); return err; } @@ -4243,27 +4228,13 @@ static int set_quality_report_func(struct sock *sk, struct hci_dev *hdev, &rp, sizeof(rp)); if (changed) - exp_quality_report_feature_changed(val, hdev, sk); + exp_feature_changed(hdev, quality_report_uuid, val, sk); unlock_quality_report: hci_req_sync_unlock(hdev); return err; } -static int exp_offload_codec_feature_changed(bool enabled, struct hci_dev *hdev, - struct sock *skip) -{ - struct mgmt_ev_exp_feature_changed ev; - - memset(&ev, 0, sizeof(ev)); - memcpy(ev.uuid, offload_codecs_uuid, 16); - ev.flags = cpu_to_le32(enabled ? BIT(0) : 0); - - return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, hdev, - &ev, sizeof(ev), - HCI_MGMT_EXP_FEATURE_EVENTS, skip); -} - static int set_offload_codec_func(struct sock *sk, struct hci_dev *hdev, struct mgmt_cp_set_exp_feature *cp, u16 data_len) @@ -4317,7 +4288,65 @@ static int set_offload_codec_func(struct sock *sk, struct hci_dev *hdev, &rp, sizeof(rp)); if (changed) - exp_offload_codec_feature_changed(val, hdev, sk); + exp_feature_changed(hdev, offload_codecs_uuid, val, sk); + + return err; +} + +static int set_le_simultaneous_roles_func(struct sock *sk, struct hci_dev *hdev, + struct mgmt_cp_set_exp_feature *cp, + u16 data_len) +{ + bool val, changed; + int err; + struct mgmt_rp_set_exp_feature rp; + + /* Command requires to use a valid controller index */ + if (!hdev) + return mgmt_cmd_status(sk, MGMT_INDEX_NONE, + MGMT_OP_SET_EXP_FEATURE, + MGMT_STATUS_INVALID_INDEX); + + /* Parameters are limited to a single octet */ + if (data_len != MGMT_SET_EXP_FEATURE_SIZE + 1) + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_EXP_FEATURE, + MGMT_STATUS_INVALID_PARAMS); + + /* Only boolean on/off is supported */ + if (cp->param[0] != 0x00 && cp->param[0] != 0x01) + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_EXP_FEATURE, + MGMT_STATUS_INVALID_PARAMS); + + val = !!cp->param[0]; + changed = (val != hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)); + + if (!hci_dev_le_state_simultaneous(hdev)) { + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_EXP_FEATURE, + MGMT_STATUS_NOT_SUPPORTED); + } + + if (changed) { + if (val) + hci_dev_set_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES); + else + hci_dev_clear_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES); + } + + bt_dev_info(hdev, "LE simultanous roles enable %d changed %d", + val, changed); + + memcpy(rp.uuid, le_simultaneous_roles_uuid, 16); + rp.flags = cpu_to_le32(val ? BIT(0) : 0); + hci_sock_set_flag(sk, HCI_MGMT_EXP_FEATURE_EVENTS); + err = mgmt_cmd_complete(sk, hdev->id, + MGMT_OP_SET_EXP_FEATURE, 0, + &rp, sizeof(rp)); + + if (changed) + exp_feature_changed(hdev, le_simultaneous_roles_uuid, val, sk); return err; } @@ -4334,6 +4363,7 @@ static const struct mgmt_exp_feature { EXP_FEAT(rpa_resolution_uuid, set_rpa_resolution_func), EXP_FEAT(quality_report_uuid, set_quality_report_func), EXP_FEAT(offload_codecs_uuid, set_offload_codec_func), + EXP_FEAT(le_simultaneous_roles_uuid, set_le_simultaneous_roles_func), /* end with a null feature */ EXP_FEAT(NULL, NULL)