main.conf: Introduce MaxControllers
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 11 Feb 2022 21:48:46 +0000 (13:48 -0800)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:53 +0000 (14:55 +0530)
This introduces MaxControllers which can be used to limit the number of
adapters exposed in the system.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/adapter.c
src/btd.h
src/main.c
src/main.conf

index 8e01a1d..e540468 100644 (file)
@@ -16548,6 +16548,13 @@ static void index_added(uint16_t index, uint16_t length, const void *param,
                return;
        }
 
+       /* Check if at maximum adapters allowed in the system then ignore the
+        * adapter.
+        */
+       if (btd_opts.max_adapters &&
+                       btd_opts.max_adapters == g_slist_length(adapters))
+               return;
+
        reset_adv_monitors(index);
 
        adapter = btd_adapter_new(index);
index aae2298..097e3ea 100755 (executable)
--- a/src/btd.h
+++ b/src/btd.h
@@ -126,6 +126,7 @@ struct btd_opts {
        uint16_t        did_version;
 
        bt_mode_t       mode;
+       uint16_t        max_adapters;
        bt_gatt_cache_t gatt_cache;
        uint16_t        gatt_mtu;
        uint8_t         gatt_channels;
index eee773b..12c84be 100755 (executable)
@@ -76,6 +76,7 @@ static const char *supported_options[] = {
        "NameResolving",
        "DebugKeys",
        "ControllerMode",
+       "MaxControllers"
        "MultiProfile",
        "FastConnectable",
        "Privacy",
@@ -783,6 +784,14 @@ static void parse_config(GKeyFile *config)
                g_free(str);
        }
 
+       val = g_key_file_get_integer(config, "General", "MaxControllers", &err);
+       if (err) {
+               g_clear_error(&err);
+       } else {
+               DBG("MaxControllers=%d", val);
+               btd_opts.max_adapters = val;
+       }
+
        str = g_key_file_get_string(config, "General", "MultiProfile", &err);
        if (err) {
                g_clear_error(&err);
index b285995..f735ff7 100755 (executable)
 # Possible values: "dual", "bredr", "le"
 #ControllerMode = dual
 
+# Maximum number of controllers allowed to be exposed to the system.
+# Default=0 (unlimited)
+#MaxControllers=0
+
 # Enables Multi Profile Specification support. This allows to specify if
 # system supports only Multiple Profiles Single Device (MPSD) configuration
 # or both Multiple Profiles Single Device (MPSD) and Multiple Profiles Multiple