From fec9eb178d5fee5b39cd49d5d55a7ac202bb9894 Mon Sep 17 00:00:00 2001 From: "Igor V. Kovalenko" Date: Thu, 15 Apr 2021 20:19:27 +0300 Subject: [PATCH] bluetooth: disable HSP HS profile by default A few headsets have issues if HFP HF profile connection is attempted before HSP HS profile connection is closed. Looks like this could happen because bluez bluetoothd alows to make simultaneous HSP HS and HFP HF peer connections. One of affected headsets is WH-1000XM2 Until we find out how to prevent simultaneous HSP HS and HFP HF connections, when native backend has HFP HF profile enabled (this is the default) do disable HSP HS completely unless user explicitly request it via discovery modarg. Do this by adding module-bluetooth-discover arg enable_native_hsp_hs, default to inverse of enable_native_hfp_hf. Part-of: --- src/modules/bluetooth/backend-native.c | 11 +++++++++-- src/modules/bluetooth/bluez5-util.c | 12 +++++++++++- src/modules/bluetooth/bluez5-util.h | 3 ++- src/modules/bluetooth/module-bluez5-discover.c | 13 +++++++++++-- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/modules/bluetooth/backend-native.c b/src/modules/bluetooth/backend-native.c index d3dd0bd7c..3ad6bd741 100644 --- a/src/modules/bluetooth/backend-native.c +++ b/src/modules/bluetooth/backend-native.c @@ -44,6 +44,7 @@ struct pa_bluetooth_backend { pa_dbus_connection *connection; pa_bluetooth_discovery *discovery; bool enable_shared_profiles; + bool enable_hsp_hs; bool enable_hfp_hf; PA_LLIST_HEAD(pa_dbus_pending, pending); @@ -1069,8 +1070,13 @@ pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_d backend->discovery = y; backend->enable_shared_profiles = enable_shared_profiles; backend->enable_hfp_hf = pa_bluetooth_discovery_get_enable_native_hfp_hf(y); + backend->enable_hsp_hs = pa_bluetooth_discovery_get_enable_native_hsp_hs(y); - profile_init(backend, PA_BLUETOOTH_PROFILE_HSP_HS); + if (!backend->enable_hsp_hs && !backend->enable_hfp_hf) + pa_log_warn("Both HSP HS and HFP HF bluetooth profiles disabled in native backend. Native backend will not register for headset connections."); + + if (backend->enable_hsp_hs) + profile_init(backend, PA_BLUETOOTH_PROFILE_HSP_HS); if (backend->enable_shared_profiles) native_backend_apply_profile_registration_change(backend, true); @@ -1086,7 +1092,8 @@ void pa_bluetooth_native_backend_free(pa_bluetooth_backend *backend) { if (backend->enable_shared_profiles) native_backend_apply_profile_registration_change(backend, false); - profile_done(backend, PA_BLUETOOTH_PROFILE_HSP_HS); + if (backend->enable_hsp_hs) + profile_done(backend, PA_BLUETOOTH_PROFILE_HSP_HS); pa_dbus_connection_unref(backend->connection); diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c index bea1d999e..f6d73a832 100644 --- a/src/modules/bluetooth/bluez5-util.c +++ b/src/modules/bluetooth/bluez5-util.c @@ -117,6 +117,7 @@ struct pa_bluetooth_discovery { int headset_backend; pa_bluetooth_backend *ofono_backend, *native_backend; PA_LLIST_HEAD(pa_dbus_pending, pending); + bool enable_native_hsp_hs; bool enable_native_hfp_hf; bool enable_msbc; }; @@ -808,6 +809,14 @@ pa_bluetooth_device* pa_bluetooth_discovery_get_device_by_path(pa_bluetooth_disc return NULL; } +bool pa_bluetooth_discovery_get_enable_native_hsp_hs(pa_bluetooth_discovery *y) +{ + pa_assert(y); + pa_assert(PA_REFCNT_VALUE(y) > 0); + + return y->enable_native_hsp_hs; +} + bool pa_bluetooth_discovery_get_enable_native_hfp_hf(pa_bluetooth_discovery *y) { pa_assert(y); @@ -2277,7 +2286,7 @@ static void object_manager_done(pa_bluetooth_discovery *y) { A2DP_OBJECT_MANAGER_PATH); } -pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c, int headset_backend, bool enable_native_hfp_hf, bool enable_msbc) { +pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c, int headset_backend, bool enable_native_hsp_hs, bool enable_native_hfp_hf, bool enable_msbc) { pa_bluetooth_discovery *y; DBusError err; DBusConnection *conn; @@ -2290,6 +2299,7 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c, int headset_backe PA_REFCNT_INIT(y); y->core = c; y->headset_backend = headset_backend; + y->enable_native_hsp_hs = enable_native_hsp_hs; y->enable_native_hfp_hf = enable_native_hfp_hf; y->enable_msbc = enable_msbc; y->adapters = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, diff --git a/src/modules/bluetooth/bluez5-util.h b/src/modules/bluetooth/bluez5-util.h index f561d78f6..dd1f7bdad 100644 --- a/src/modules/bluetooth/bluez5-util.h +++ b/src/modules/bluetooth/bluez5-util.h @@ -209,10 +209,11 @@ static inline bool pa_bluetooth_uuid_is_hsp_hs(const char *uuid) { #define HEADSET_BACKEND_NATIVE 1 #define HEADSET_BACKEND_AUTO 2 -pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core, int headset_backend, bool default_profile_hfp, bool enable_msbc); +pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core, int headset_backend, bool enable_native_hsp_hs, bool enable_native_hfp_hf, bool enable_msbc); pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y); void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y); void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is_running); +bool pa_bluetooth_discovery_get_enable_native_hsp_hs(pa_bluetooth_discovery *y); bool pa_bluetooth_discovery_get_enable_native_hfp_hf(pa_bluetooth_discovery *y); bool pa_bluetooth_discovery_get_enable_msbc(pa_bluetooth_discovery *y); #endif diff --git a/src/modules/bluetooth/module-bluez5-discover.c b/src/modules/bluetooth/module-bluez5-discover.c index 09c68a331..6c6988b3f 100644 --- a/src/modules/bluetooth/module-bluez5-discover.c +++ b/src/modules/bluetooth/module-bluez5-discover.c @@ -39,6 +39,7 @@ PA_MODULE_USAGE( "autodetect_mtu=" "enable_msbc=" "output_rate_refresh_interval_ms=" + "enable_native_hsp_hs=" "enable_native_hfp_hf=" ); @@ -47,6 +48,7 @@ static const char* const valid_modargs[] = { "autodetect_mtu", "enable_msbc", "output_rate_refresh_interval_ms", + "enable_native_hsp_hs", "enable_native_hfp_hf", NULL }; @@ -115,7 +117,8 @@ int pa__init(pa_module *m) { bool autodetect_mtu; bool enable_msbc; uint32_t output_rate_refresh_interval_ms; - bool enable_native_hfp_hf = true; + bool enable_native_hsp_hs; + bool enable_native_hfp_hf; pa_assert(m); @@ -147,10 +150,16 @@ int pa__init(pa_module *m) { if (pa_modargs_get_value_boolean(ma, "enable_msbc", &enable_msbc) < 0) { pa_log("Invalid boolean value for enable_msbc parameter"); } + enable_native_hfp_hf = true; if (pa_modargs_get_value_boolean(ma, "enable_native_hfp_hf", &enable_native_hfp_hf) < 0) { pa_log("enable_native_hfp_hf must be true or false"); goto fail; } + enable_native_hsp_hs = !enable_native_hfp_hf; + if (pa_modargs_get_value_boolean(ma, "enable_native_hsp_hs", &enable_native_hsp_hs) < 0) { + pa_log("enable_native_hsp_hs must be true or false"); + goto fail; + } output_rate_refresh_interval_ms = DEFAULT_OUTPUT_RATE_REFRESH_INTERVAL_MS; if (pa_modargs_get_value_u32(ma, "output_rate_refresh_interval_ms", &output_rate_refresh_interval_ms) < 0) { @@ -165,7 +174,7 @@ int pa__init(pa_module *m) { u->output_rate_refresh_interval_ms = output_rate_refresh_interval_ms; u->loaded_device_paths = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); - if (!(u->discovery = pa_bluetooth_discovery_get(u->core, headset_backend, enable_native_hfp_hf, enable_msbc))) + if (!(u->discovery = pa_bluetooth_discovery_get(u->core, headset_backend, enable_native_hsp_hs, enable_native_hfp_hf, enable_msbc))) goto fail; u->device_connection_changed_slot =