From patchwork Thu Nov 7 22:01:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Pushkarev X-Patchwork-Id: 841516 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47498216A32 for ; Thu, 7 Nov 2024 22:10:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.89.224.132 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731017433; cv=none; b=FOtETt94DOrSzCwnBFdg1CFMijPc384buAMfp2tsDOLRvciXyG9s+OJb4zVcMCCkt2ooEr9M3N4v19YBEBMfWgvfk7gj6XazyNOvLtVE1c9ZAz7NPXs+8UKmgKxP4uYnHsEOM45RasSouvlMdnzpQSYNxOgc31XkLYKiej5bA50= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731017433; c=relaxed/simple; bh=Rn/BY28/ETQUFLWQfJ6nuJQOVRYy4ed4OPZqlCHCESM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dk5UHylAF+kBWvzZmNs7WE9RXpq+ZFNsHbTJLGPUCquDlzgSMtz/n06erxObsrdlsbkwJTxb5OltkFAqT76T4wNSCKUOsSgEIkHyu2c+dQIgGhoOsA1bO+WrEOnfm3KldQhLqo8judTWO7aUx6J+K0fXVCMND0kE/8smF4syY+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=salutedevices.com; spf=pass smtp.mailfrom=salutedevices.com; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b=YuiLEwU8; arc=none smtp.client-ip=45.89.224.132 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=salutedevices.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=salutedevices.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b="YuiLEwU8" Received: from p-infra-ksmg-sc-msk02.sberdevices.ru (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 4354C120031; Fri, 8 Nov 2024 01:01:46 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 4354C120031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1731016906; bh=n7SQcs1cKIWDl0CRKGv9rkGajvtlhngagBse4iZlLTY=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=YuiLEwU80wdroM7bf2vI14zm9dtR1rBAbpzdtcChyVWUGzRSrGRDl34FhnBr1z/OY RQLRAO5C4ckVEuTYc98wesOi64mBm5WD5F80XqykTZcGJQwzmx32itVaqexFosZa2e E+148ehHH9Q9wfb1fxD/YgbXrLxGlA+A1tYr8p0TcbySZFA3MEyMEoGiLSf1ukuIlz PuLCBWQC+LlmZr9mRKU5Q1atIObaqgBiQlAjPxoXTSQ4yclh//JNJUOTBR9yRZUIgx MhlWT5duh1ijbZoeNgiUScN1q1o0IHZv9yWPKQiPx70Q2/mFZU3+U4KNu2QtLv+KTa XF1fjo/oJ7u1A== Received: from smtp.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Fri, 8 Nov 2024 01:01:46 +0300 (MSK) From: Victor Pushkarev To: CC: , , Victor Pushkarev Subject: [PATCH BlueZ 1/2] main.conf: Introduce option to limit A2DP channels Date: Fri, 8 Nov 2024 01:01:19 +0300 Message-ID: <20241107220121.97417-2-VAnPushkarev@salutedevices.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20241107220121.97417-1-VAnPushkarev@salutedevices.com> References: <20241107220121.97417-1-VAnPushkarev@salutedevices.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: p-i-exch-a-m2.sberdevices.ru (172.24.196.120) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 189034 [Nov 07 2024] X-KSMG-AntiSpam-Version: 6.1.1.7 X-KSMG-AntiSpam-Envelope-From: vanpushkarev@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 41 0.3.41 623e98d5198769c015c72f45fabbb9f77bdb702b, {Tracking_from_domain_doesnt_match_to}, smtp.sberdevices.ru:5.0.1,7.1.1; salutedevices.com:7.1.1; 127.0.0.199:7.1.2; d41d8cd98f00b204e9800998ecf8427e.com:7.1.1, FromAlignment: s X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2024/11/07 18:44:00 #26832432 X-KSMG-AntiVirus-Status: Clean, skipped This introduces 'Channels' which can be used to limit the number of A2DP channels. For new option this also adds a new group A2DP to config. --- src/btd.h | 6 ++++++ src/main.c | 15 +++++++++++++++ src/main.conf | 5 +++++ 3 files changed, 26 insertions(+) diff --git a/src/btd.h b/src/btd.h index 07205aa69..c2b6a456e 100644 --- a/src/btd.h +++ b/src/btd.h @@ -109,6 +109,10 @@ struct btd_avrcp_opts { bool volume_category; }; +struct btd_a2dp_opts { + uint8_t channels; +}; + struct btd_advmon_opts { uint8_t rssi_sampling_period; }; @@ -152,6 +156,8 @@ struct btd_opts { struct btd_avdtp_opts avdtp; struct btd_avrcp_opts avrcp; + struct btd_a2dp_opts a2dp; + uint8_t key_size; enum jw_repairing_t jw_repairing; diff --git a/src/main.c b/src/main.c index 41c3271a7..2c583e611 100644 --- a/src/main.c +++ b/src/main.c @@ -168,6 +168,10 @@ static const char *avdtp_options[] = { static const char *avrcp_options[] = { "VolumeWithoutTarget", "VolumeCategory", +}; + +static const char *a2dp_options[] = { + "Channels", NULL }; @@ -188,6 +192,7 @@ static const struct group_table { { "CSIS", csip_options }, { "AVDTP", avdtp_options }, { "AVRCP", avrcp_options }, + { "A2DP", a2dp_options }, { "AdvMon", advmon_options }, { } }; @@ -1157,6 +1162,13 @@ static void parse_avrcp(GKeyFile *config) &btd_opts.avrcp.volume_category); } +static void parse_a2dp(GKeyFile *config) +{ + parse_config_u8(config, "A2DP", "Channels", + &btd_opts.a2dp.channels, + 0, UINT8_MAX); +} + static void parse_advmon(GKeyFile *config) { parse_config_u8(config, "AdvMon", "RSSISamplingPeriod", @@ -1181,6 +1193,7 @@ static void parse_config(GKeyFile *config) parse_csis(config); parse_avdtp(config); parse_avrcp(config); + parse_a2dp(config); parse_advmon(config); } @@ -1226,6 +1239,8 @@ static void init_defaults(void) btd_opts.avrcp.volume_without_target = false; btd_opts.avrcp.volume_category = true; + btd_opts.a2dp.channels = 0; + btd_opts.advmon.rssi_sampling_period = 0xFF; btd_opts.csis.encrypt = true; } diff --git a/src/main.conf b/src/main.conf index fff13ed2f..323a2fbbe 100644 --- a/src/main.conf +++ b/src/main.conf @@ -316,6 +316,11 @@ # notifications. #VolumeCategory = true +[A2DP] +# Maximum number of A2DP channels +# Defaults to 0 (unlimited) +#Channels = 0 + [Policy] # # The ReconnectUUIDs defines the set of remote services that should try From patchwork Thu Nov 7 22:01:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Pushkarev X-Patchwork-Id: 841799 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47438215C6D for ; Thu, 7 Nov 2024 22:10:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.89.224.132 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731017433; cv=none; b=KE2i+5e41wDcgY76xUug0hllYVrQg6VARXXbrJalcZvW7/sra/0nwmvEvZ0b1guZVUIV1Yuuh0FxC31eCd4uoL/94p9iuisxzk7Jn5GlP6kLMwXnw3TiR/z/J64AYyfKPMSG0jX9xao1RDvASTX4EVoE6cv6Jlx6M6QDhjNOCkU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731017433; c=relaxed/simple; bh=+ORDH0V3L+rdOqMv/DGYKl6/roIqDWPeI6SjQqpseYE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DIpBIQ2tTCle+rha0DY1Du+DZVeq1xLL0OKQgHAN/AIROAHfjAbTolw/FoK0NoYdDLjxRCFPO4EsWmKuY0yud0IjO+OB5IE/wkpY7/7NEcrvInpnMch/KYYo1BW6E0ZIxjAU5KxSGdMgc5e0XVUaTXz4b37QTyUxGZDYfViXffQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=salutedevices.com; spf=pass smtp.mailfrom=salutedevices.com; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b=ahfL/HmW; arc=none smtp.client-ip=45.89.224.132 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=salutedevices.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=salutedevices.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b="ahfL/HmW" Received: from p-infra-ksmg-sc-msk02.sberdevices.ru (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 69FCC120032; Fri, 8 Nov 2024 01:01:46 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 69FCC120032 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1731016906; bh=SWgkR9fhVPZ4h/1TCyD08IAmuTcMER+tqy9lZ8jnq/Q=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=ahfL/HmW+QISTj7j6YJ7BSimMJm2U1gpM5uKTxDrIBYKejY6mrJ8bb+gNX+6gx9mG QLvR9nVL4E5Ne6bkKAgIfXAH+jnCU65PMzwNI4sbwZtpAE5dfjR63JN+rvZHvTAlZL JWhsLNARa1Ij4oviBvNsREMz4SpnOq2Kpwhly7oXVz/5YxVUlCdY4N4kTyvks3I7g9 15zUp2lnYR4n/jPfYVoDqkbC5aLIntelHbhqgkA8ld7u/lkRKPLeuwFAOk4d7MmGud gg3DcJLxXYLblktGvtGsx/FmYEvX4k+D7nhGvsG8ouxWa6M223kmSSKwPCjZBGeuPO 4lew4LUsovS6Q== Received: from smtp.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Fri, 8 Nov 2024 01:01:46 +0300 (MSK) From: Victor Pushkarev To: CC: , , Victor Pushkarev Subject: [PATCH BlueZ 2/2] a2dp: Reject incoming connection when channel limit is exceeded Date: Fri, 8 Nov 2024 01:01:20 +0300 Message-ID: <20241107220121.97417-3-VAnPushkarev@salutedevices.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20241107220121.97417-1-VAnPushkarev@salutedevices.com> References: <20241107220121.97417-1-VAnPushkarev@salutedevices.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: p-i-exch-a-m2.sberdevices.ru (172.24.196.120) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 189034 [Nov 07 2024] X-KSMG-AntiSpam-Version: 6.1.1.7 X-KSMG-AntiSpam-Envelope-From: vanpushkarev@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 41 0.3.41 623e98d5198769c015c72f45fabbb9f77bdb702b, {Tracking_phishing_log_reg_50_60}, {Tracking_from_domain_doesnt_match_to}, smtp.sberdevices.ru:5.0.1,7.1.1; salutedevices.com:7.1.1; 127.0.0.199:7.1.2; d41d8cd98f00b204e9800998ecf8427e.com:7.1.1, FromAlignment: s X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2024/11/07 18:44:00 #26832432 X-KSMG-AntiVirus-Status: Clean, skipped Add counting of active audio streams at MediaEndpoint level. Reject incoming connection at the audio stream setting stage when the configured A2DP channel limit is exceeded. --- profiles/audio/a2dp.c | 9 +++++++++ profiles/audio/media.c | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c index c97bd6e89..935873d07 100644 --- a/profiles/audio/a2dp.c +++ b/profiles/audio/a2dp.c @@ -716,6 +716,15 @@ static gboolean endpoint_setconf_ind(struct avdtp *session, return TRUE; } + if (ret == -1) { + /* Reject connection from SEP + * and clear configuration. + */ + DBG("Reject connection from %s", device_get_path(setup->chan->device)); + a2dp_sep->endpoint->clear_configuration(a2dp_sep, a2dp_sep->user_data); + device_request_disconnect(setup->chan->device, NULL); + } + setup_error_init(setup, AVDTP_MEDIA_CODEC, AVDTP_UNSUPPORTED_CONFIGURATION); setup_unref(setup); diff --git a/profiles/audio/media.c b/profiles/audio/media.c index 746e538fc..20b860f6a 100644 --- a/profiles/audio/media.c +++ b/profiles/audio/media.c @@ -33,6 +33,7 @@ #include "src/dbus-common.h" #include "src/profile.h" #include "src/service.h" +#include "src/btd.h" #include "src/uuid-helper.h" #include "src/log.h" @@ -134,6 +135,7 @@ struct media_player { }; static GSList *adapters = NULL; +static unsigned int active_streams; static void endpoint_request_free(struct endpoint_request *request) { @@ -302,6 +304,9 @@ done: static void clear_endpoint(struct media_endpoint *endpoint) { + if (active_streams > 0) + active_streams--; + media_endpoint_cancel_all(endpoint); while (endpoint->transports != NULL) @@ -659,6 +664,12 @@ static int set_config(struct a2dp_sep *sep, uint8_t *configuration, struct media_endpoint *endpoint = user_data; struct a2dp_config_data *data; + active_streams++; + if (active_streams > btd_opts.a2dp.channels) { + DBG("A2DP channel limit (%u) exceeded", btd_opts.a2dp.channels); + return -1; + } + data = g_new0(struct a2dp_config_data, 1); data->setup = setup; data->cb = cb;