Message ID | 20241107220121.97417-3-VAnPushkarev@salutedevices.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Introduce option to limit A2DP channels | expand |
Context | Check | Description |
---|---|---|
tedd_an/pre-ci_am | success | Success |
tedd_an/CheckPatch | warning | WARNING:BLOCK_COMMENT_STYLE: Block comments should align the * on each line #116: FILE: profiles/audio/a2dp.c:721: + /* Reject connection from SEP + * and clear configuration. WARNING:LONG_LINE: line length of 95 exceeds 80 columns #118: FILE: profiles/audio/a2dp.c:723: + DBG("Reject connection from %s", device_get_path(setup->chan->device)); WARNING:LONG_LINE: line length of 95 exceeds 80 columns #119: FILE: profiles/audio/a2dp.c:724: + a2dp_sep->endpoint->clear_configuration(a2dp_sep, a2dp_sep->user_data); /github/workspace/src/src/13867231.patch total: 0 errors, 3 warnings, 50 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /github/workspace/src/src/13867231.patch has style problems, please review. NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. |
tedd_an/GitLint | success | Gitlint PASS |
tedd_an/IncrementalBuild | success | Incremental Build PASS |
Hi Victor, On Thu, Nov 7, 2024 at 5:10 PM Victor Pushkarev <VAnPushkarev@salutedevices.com> wrote: > > 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; > + } This is a global limit? Not really following the reasoning here, if the platform don't want to connect to more devices just don't connect them, or in case of incoming connection don't authorize the connections, make the endpoints return an error to SetConfiguration, suspend the streams, etc. There are so many ways to block this that I don't really feel like introducing a new one will do us any good. > data = g_new0(struct a2dp_config_data, 1); > data->setup = setup; > data->cb = cb; > -- > 2.39.3 (Apple Git-146) > >
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;