From patchwork Mon Feb 26 22:00:30 2024 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: 776659 Received: from mail-vk1-f175.google.com (mail-vk1-f175.google.com [209.85.221.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D12512DDBB for ; Mon, 26 Feb 2024 22:00:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708984836; cv=none; b=mxPPsIP9zcTIbSkDM+LAMiXFgxfdL64Secx6ztjIwAbe1dtgiTVx0nt8ByDNWAC5JW/4yzwyw4/UI0K1PTTaL4A4umOJ1fBNmTMpCpfaZ1dGtbhj7exHtexWyt6UeMIpuseDxkjlp5x9rVIOSB6PQ+bnrcHUIAR3tlPCByGLWQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708984836; c=relaxed/simple; bh=yAwVjnii4gOdKjVBPRKqszUhbHC1xKlL80xFSv2WaF0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=N/Z7kHKGIthAbqe0O2qGLcN2ki+uwatPnRQKBd/0nqsVndUHVWZOk6H3zPSzQrJbtgaLmXtkvjUS9AVUkf/KF1V2lIcmFIGy9V17Jv/OGRlhLjgDEVY0LUs8+0BFbAz7GA+Kc2fQm2VVA9hGaSuyF9wOyoScaYA8w9YSGnhCGTQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gy9zCMtf; arc=none smtp.client-ip=209.85.221.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gy9zCMtf" Received: by mail-vk1-f175.google.com with SMTP id 71dfb90a1353d-4d158faf527so457296e0c.0 for ; Mon, 26 Feb 2024 14:00:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708984833; x=1709589633; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=ef5cxWS/DHX003FFu3ZV3XHChZLsTqEMaAm7lSIlAsk=; b=gy9zCMtfTvoKzYbW8aTTJYMFVR8zK477zWdopfnRCH/o7VsSNcuveA8lHMnvFmPn26 JT16CzH/eovc3f0XEIwUuFMfQt3P+DTs6LpP3+2uy9oUWEHxZ31VpD8HFxz2OskQlraT IhR9eFTpXjd6sKxT+MAMpJJ5lbn7v5axI8Rjw+W62KSNPrnxedcTvnP1+Nq8mqmBgS2g 4aXkvRRp4U8WJDr8oyTSsRYxLH8sRkmT0XbmlyVWJWBW61FqtCNSIhtgIAhPwrQtcR6C qJK8pyTLDHyy4fK6+A0Y6T5dCT8dW1ZC1BATqYtH5y984Q8ANScric10Z07GXN0uAzsM fOlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708984833; x=1709589633; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ef5cxWS/DHX003FFu3ZV3XHChZLsTqEMaAm7lSIlAsk=; b=DXLzawVQyPQTYG/zw8LTVVJAqG5SE0jVeqlmUwMw/rqIIkZhfenUR/66tBwBrkUbg+ a5NwlLq8o2Wvqx0h4vsQc0lAz3K4J34TjEGsHX9XdTmAlyCFu684TRJ+mSJekMp/xSPu 312A/C5Lr/Arq/9dcAbJuAzC82hIJoPsMwaUmNuVOHoN404XcjMj87XtCxAylsjQ/S9i l5pK05suR3uCp+uj+FoFn9xLCUWTwzlh6C3P56Y+ePymABl0pW7BvG92LaB7NOsy78z6 Z/eAjg1mJfwrsv8rDZWf4+/+OR7lRPanOWG02lZHni3USINVcV92N4kzeKBccpK9e6Pk IL4A== X-Gm-Message-State: AOJu0YzqrIXevJPh/DVZH0+mSukDn45zFhIVEMBj1wp03vN+WG8IVJy5 gkJQ21i/pGNPQ8D2y/a8bKmvfQ3Rtg4/ailvHUYR0G9DFD/9HIGhLxA11ax+ X-Google-Smtp-Source: AGHT+IEQHh1jDmfdo6K/I+v5UyRos86Z+LjZU28SoRfLYGj9l2uFDFZY/sj909Ib22yBrkFgzYdQPQ== X-Received: by 2002:a1f:c4c2:0:b0:4ca:b623:7786 with SMTP id u185-20020a1fc4c2000000b004cab6237786mr4721051vkf.2.1708984833415; Mon, 26 Feb 2024 14:00:33 -0800 (PST) Received: from lvondent-mobl4.. (071-047-239-151.res.spectrum.com. [71.47.239.151]) by smtp.gmail.com with ESMTPSA id n15-20020a1f720f000000b004c04a84d80csm815764vkc.56.2024.02.26.14.00.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 14:00:32 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v4 1/2] Bluetooth: hci_sync: Use address filtering when HCI_PA_SYNC is set Date: Mon, 26 Feb 2024 17:00:30 -0500 Message-ID: <20240226220031.1686256-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz If HCI_PA_SYNC flag is set it means there is a Periodic Advertising Synchronization pending, so this attempts to locate the address passed to HCI_OP_LE_PA_CREATE_SYNC and program it in the accept list so only reports with that address are processed. Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 45 +++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 669099cf9b1a..ab609089ac4c 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -2566,6 +2566,16 @@ static struct conn_params *conn_params_copy(struct list_head *list, size_t *n) return p; } +/* Clear LE Accept List */ +static int hci_le_clear_accept_list_sync(struct hci_dev *hdev) +{ + if (!(hdev->commands[26] & 0x80)) + return 0; + + return __hci_cmd_sync_status(hdev, HCI_OP_LE_CLEAR_ACCEPT_LIST, 0, NULL, + HCI_CMD_TIMEOUT); +} + /* Device must not be scanning when updating the accept list. * * Update is done using the following sequence: @@ -2614,6 +2624,31 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev) goto done; } + /* Force address filtering if PA Sync is in progress */ + if (hci_dev_test_flag(hdev, HCI_PA_SYNC)) { + struct hci_cp_le_pa_create_sync *sent; + + sent = hci_sent_cmd_data(hdev, HCI_OP_LE_PA_CREATE_SYNC); + if (sent) { + struct conn_params pa; + + memset(&pa, 0, sizeof(pa)); + + bacpy(&pa.addr, &sent->addr); + pa.addr_type = sent->addr_type; + + /* Clear first since there could be addresses left + * behind. + */ + hci_le_clear_accept_list_sync(hdev); + + num_entries = 1; + err = hci_le_add_accept_list_sync(hdev, &pa, + &num_entries); + goto done; + } + } + /* Go through the current accept list programmed into the * controller one by one and check if that address is connected or is * still in the list of pending connections or list of devices to @@ -4220,16 +4255,6 @@ static int hci_le_read_accept_list_size_sync(struct hci_dev *hdev) 0, NULL, HCI_CMD_TIMEOUT); } -/* Clear LE Accept List */ -static int hci_le_clear_accept_list_sync(struct hci_dev *hdev) -{ - if (!(hdev->commands[26] & 0x80)) - return 0; - - return __hci_cmd_sync_status(hdev, HCI_OP_LE_CLEAR_ACCEPT_LIST, 0, NULL, - HCI_CMD_TIMEOUT); -} - /* Read LE Resolving List Size */ static int hci_le_read_resolv_list_size_sync(struct hci_dev *hdev) { From patchwork Mon Feb 26 22:00:31 2024 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: 776021 Received: from mail-vk1-f173.google.com (mail-vk1-f173.google.com [209.85.221.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6055131733 for ; Mon, 26 Feb 2024 22:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708984838; cv=none; b=bMYHqoyp+DihSNKT+tIEPS8Or//oQV+JpK2DXh5RM41whV6E846ux2oEJnC3BZFnDwKW3ZaqoBVMuZShkNXFe3KaIYZzZSHf/b7D/8UnU+i9OTCKT4jt340yNk0E98knpx6fhjWAUXzCVks15Ki8TY6YPXPfamUKDF/q49y3lmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708984838; c=relaxed/simple; bh=PBemC8eLkTVfNh0dwYJ2wYP2+UQNVZyPXP0l+8IDzyk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LGZfE+XIsXSH9k4Qb3nO81F5h/TeqE1fV04yI8VooVjuJD8b0AK/SHzRNwO+c1Kx1aNB7EB+U5BI7MONi9phvcFUrOapINA2cQrBTJepIRy4IJUvagmZUmE0bkXrRThLBDtoq5kbRR5wXOG+kBtVk/3gLDrjYLY64yms/iZPXwY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Am6PoLyV; arc=none smtp.client-ip=209.85.221.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Am6PoLyV" Received: by mail-vk1-f173.google.com with SMTP id 71dfb90a1353d-4ccfb94ee5cso410835e0c.2 for ; Mon, 26 Feb 2024 14:00:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708984835; x=1709589635; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=VQwU9BZ8ZHeA+YsMY+rfVU1i7tvh/Zon3HuyxPG4BIM=; b=Am6PoLyV/lif+rp6BKmdR0F9TlRVopCxm51sugYAT/nDHa8LPeNcCGzj2Qu+l4DkxF 41qT8tMSlBHGzVQpku/vg+puwlZ4rGoj6kSXqJ9dI3QMqunf97KC6VxvorvfdLcxd66N C0lETPGGCSS3rWBWNpOMIZlRJZclxa1DUHjzPunqm9tctw2OSaeAvKQW/58WhnHKd/79 kwakC7qNyqc36qsB3Md81dCqo+EubcSG8remLtHYRJJ0aix5VcVYCjQQPK4xHMvmcm2c P/jOmIA8hwUdnnVsZ/tJc/TJ+sq5mjTfZ0ihbh2UY8EaLzIxetM2r9M06sNTPwy4NtwD GTag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708984835; x=1709589635; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VQwU9BZ8ZHeA+YsMY+rfVU1i7tvh/Zon3HuyxPG4BIM=; b=MgeaYfowUO93hPC3x20X3NX3bWXS4QWDqse5m9S2kUy5N6Cf6aHx6qiJMy5R/Z/96G sBTIFr2G01I993y59QOnx8PSAWS3zPq91O0kav9gZehatY2Gic0aSFrKRzMEDcoRWb/S 7SvUQMjUVonVw54hloyYqKq/1jGtPuzlggvHYOuVQGshIbumkSaLvYKL7tWH0AeQqPqX dbwIFPfyfHWT9vK50raVGkLd29zkegoFogs47j+kZunRxV7Pguni44xSfcLwNnrSqC0e 5+BGnbPC88swuA5+Xt8hVwf55Vq64f1EWQ3CyCBrKPIIShBxiUSvSM6E6WrdTeBFqQ3I l7qQ== X-Gm-Message-State: AOJu0YwJdvFggZLzNndWs9Sq7Vbt6MdNoSiUZg+FAg6lbARxhVPXodct EJL1BjUZXZsl1zZAlcN55+nIkl+6766GpVvK82i3pgZxKPNgwHpp0uqHh0oa X-Google-Smtp-Source: AGHT+IF22kHNYduO9xdAKzXB76fXX1k5FANuajR/VdnAG+3qYS5e/yGlS4NPZMC/Jpia4M029yvOXw== X-Received: by 2002:a1f:c703:0:b0:4cc:9cee:7cbd with SMTP id x3-20020a1fc703000000b004cc9cee7cbdmr4187709vkf.6.1708984835135; Mon, 26 Feb 2024 14:00:35 -0800 (PST) Received: from lvondent-mobl4.. (071-047-239-151.res.spectrum.com. [71.47.239.151]) by smtp.gmail.com with ESMTPSA id n15-20020a1f720f000000b004c04a84d80csm815764vkc.56.2024.02.26.14.00.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 14:00:34 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v4 2/2] Bluetooth: hci_sync: Use QoS to determine which PHY to scan Date: Mon, 26 Feb 2024 17:00:31 -0500 Message-ID: <20240226220031.1686256-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226220031.1686256-1-luiz.dentz@gmail.com> References: <20240226220031.1686256-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This used the hci_conn QoS to determine which PHY to scan when creating a PA Sync. Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 65 +++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index ab609089ac4c..2bd9b6b050e0 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -2758,6 +2758,14 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev) return filter_policy; } +static void hci_le_scan_phy_params(struct hci_cp_le_scan_phy_params *cp, + u8 type, u16 interval, u16 window) +{ + cp->type = type; + cp->interval = cpu_to_le16(interval); + cp->window = cpu_to_le16(window); +} + static int hci_le_set_ext_scan_param_sync(struct hci_dev *hdev, u8 type, u16 interval, u16 window, u8 own_addr_type, u8 filter_policy) @@ -2765,7 +2773,7 @@ static int hci_le_set_ext_scan_param_sync(struct hci_dev *hdev, u8 type, struct hci_cp_le_set_ext_scan_params *cp; struct hci_cp_le_scan_phy_params *phy; u8 data[sizeof(*cp) + sizeof(*phy) * 2]; - u8 num_phy = 0; + u8 num_phy = 0x00; cp = (void *)data; phy = (void *)cp->data; @@ -2775,28 +2783,63 @@ static int hci_le_set_ext_scan_param_sync(struct hci_dev *hdev, u8 type, cp->own_addr_type = own_addr_type; cp->filter_policy = filter_policy; + /* Check if PA Sync is in progress then select the PHY based on the + * hci_conn.iso_qos. + */ + if (hci_dev_test_flag(hdev, HCI_PA_SYNC)) { + struct hci_cp_le_add_to_accept_list *sent; + + sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST); + if (sent) { + struct hci_conn *conn; + + conn = hci_conn_hash_lookup_ba(hdev, ISO_LINK, + &sent->bdaddr); + if (conn) { + struct bt_iso_qos *qos = &conn->iso_qos; + + if (qos->bcast.in.phy & BT_ISO_PHY_1M || + qos->bcast.in.phy & BT_ISO_PHY_2M) { + cp->scanning_phys |= LE_SCAN_PHY_1M; + hci_le_scan_phy_params(phy, type, + interval, + window); + num_phy++; + phy++; + } + + if (qos->bcast.in.phy & BT_ISO_PHY_CODED) { + cp->scanning_phys |= LE_SCAN_PHY_CODED; + hci_le_scan_phy_params(phy, type, + interval, + window); + num_phy++; + phy++; + } + + goto done; + } + } + } + if (scan_1m(hdev) || scan_2m(hdev)) { cp->scanning_phys |= LE_SCAN_PHY_1M; - - phy->type = type; - phy->interval = cpu_to_le16(interval); - phy->window = cpu_to_le16(window); - + hci_le_scan_phy_params(phy, type, interval, window); num_phy++; phy++; } if (scan_coded(hdev)) { cp->scanning_phys |= LE_SCAN_PHY_CODED; - - phy->type = type; - phy->interval = cpu_to_le16(interval); - phy->window = cpu_to_le16(window); - + hci_le_scan_phy_params(phy, type, interval, window); num_phy++; phy++; } +done: + if (!num_phy) + return -EINVAL; + return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_PARAMS, sizeof(*cp) + sizeof(*phy) * num_phy, data, HCI_CMD_TIMEOUT);