main: Read default system configuration from the conf file
authorAlain Michaud <alainm@chromium.org>
Fri, 29 May 2020 15:38:15 +0000 (15:38 +0000)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 12 Apr 2021 09:00:49 +0000 (14:30 +0530)
This change adds support for reading the configurations from the
main.conf file.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/main.c
src/main.conf

index 3d33e22..6c0444f 100755 (executable)
@@ -53,6 +53,7 @@
 #include "shared/att-types.h"
 #include "shared/mainloop.h"
 #include "lib/uuid.h"
+#include "shared/util.h"
 #include "hcid.h"
 #include "sdpd.h"
 #include "adapter.h"
@@ -101,6 +102,37 @@ static const char *supported_options[] = {
        NULL
 };
 
+static const char *controller_options[] = {
+       "BRPageScanType",
+       "BRPageScanInterval",
+       "BRPageScanWindow",
+       "BRInquiryScanType",
+       "BRInquiryScanInterval",
+       "BRInquiryScanWindow",
+       "BRLinkSupervisionTimeout",
+       "BRPageTimeout",
+       "BRMinSniffInterval",
+       "BRMaxSniffInterval",
+       "LEMinAdvertisementInterval",
+       "LEMaxAdvertisementInterval",
+       "LEMultiAdvertisementRotationInterval",
+       "LEScanIntervalAutoConnect",
+       "LEScanWindowAutoConnect",
+       "LEScanIntervalSuspend",
+       "LEScanWindowSuspend",
+       "LEScanIntervalDiscovery",
+       "LEScanWindowDiscovery",
+       "LEScanIntervalAdvMonitoring",
+       "LEScanWindowAdvMonitoring",
+       "LEScanIntervalConnect",
+       "LEScanWindowConnect",
+       "LEMinConnectionInterval",
+       "LEMaxConnectionInterval",
+       "LEConnectionLatency",
+       "LEConnectionSupervisionTimeout",
+       NULL
+};
+
 static const char *policy_options[] = {
        "ReconnectUUIDs",
        "ReconnectAttempts",
@@ -122,6 +154,7 @@ static const struct group_table {
        const char **options;
 } valid_groups[] = {
        { "General",    supported_options },
+       { "Controller", controller_options },
        { "Policy",     policy_options },
        { "GATT",       gatt_options },
        { }
@@ -287,6 +320,129 @@ static int get_mode(const char *str)
        return BT_MODE_DUAL;
 }
 
+static void parse_controller_config(GKeyFile *config)
+{
+       static const struct {
+               const char * const val_name;
+               uint16_t * const val;
+               const uint16_t min;
+               const uint16_t max;
+       } params[] = {
+               { "BRPageScanType",
+                 &main_opts.default_params.br_page_scan_type,
+                 0,
+                 1},
+               { "BRPageScanInterval",
+                 &main_opts.default_params.br_page_scan_interval,
+                 0x0012,
+                 0x1000},
+               { "BRPageScanWindow",
+                 &main_opts.default_params.br_page_scan_win,
+                 0x0011,
+                 0x1000},
+               { "BRInquiryScanType",
+                 &main_opts.default_params.br_scan_type,
+                 0,
+                 1},
+               { "BRInquiryScanInterval",
+                 &main_opts.default_params.br_scan_interval,
+                 0x0012,
+                 0x1000},
+               { "BRInquiryScanWindow",
+                 &main_opts.default_params.br_scan_win,
+                 0x0011,
+                 0x1000},
+               { "BRLinkSupervisionTimeout",
+                 &main_opts.default_params.br_link_supervision_timeout,
+                 0x0001,
+                 0xFFFF},
+               { "BRPageTimeout",
+                 &main_opts.default_params.br_page_timeout,
+                 0x0001,
+                 0xFFFF},
+               { "BRMinSniffInterval",
+                 &main_opts.default_params.br_min_sniff_interval,
+                 0x0001,
+                 0xFFFE},
+               { "BRMaxSniffInterval",
+                 &main_opts.default_params.br_max_sniff_interval,
+                 0x0001,
+                 0xFFFE},
+               { "LEMinAdvertisementInterval",
+                 &main_opts.default_params.le_min_adv_interval,
+                 0x0020,
+                 0x4000},
+               { "LEMaxAdvertisementInterval",
+                 &main_opts.default_params.le_max_adv_interval,
+                 0x0020,
+                 0x4000},
+               { "LEMultiAdvertisementRotationInterval",
+                 &main_opts.default_params.le_multi_adv_rotation_interval,
+                 0x0001,
+                 0xFFFF},
+               { "LEScanIntervalAutoConnect",
+                 &main_opts.default_params.le_scan_interval_autoconnect,
+                 0x0004,
+                 0x4000},
+               { "LEScanWindowAutoConnect",
+                 &main_opts.default_params.le_scan_win_autoconnect,
+                 0x0004,
+                 0x4000},
+               { "LEScanIntervalSuspend",
+                 &main_opts.default_params.le_scan_interval_suspend,
+                 0x0004,
+                 0x4000},
+               { "LEScanWindowSuspend",
+                 &main_opts.default_params.le_scan_win_suspend,
+                 0x0004,
+                 0x4000},
+               { "LEScanIntervalDiscovery",
+                 &main_opts.default_params.le_scan_interval_discovery,
+                 0x0004,
+                 0x4000},
+               { "LEScanWindowDiscovery",
+                 &main_opts.default_params.le_scan_win_discovery,
+                 0x0004,
+                 0x4000},
+               { "LEScanIntervalAdvMonitor",
+                 &main_opts.default_params.le_scan_interval_adv_monitor,
+                 0x0004,
+                 0x4000},
+               { "LEScanWindowAdvMonitor",
+                 &main_opts.default_params.le_scan_win_adv_monitor,
+                 0x0004,
+                 0x4000},
+               { "LEScanIntervalConnect",
+                 &main_opts.default_params.le_scan_interval_connect,
+                 0x0004,
+                 0x4000},
+               { "LEScanWindowConnect",
+                 &main_opts.default_params.le_scan_win_connect,
+                 0x0004,
+                 0x4000},
+       };
+       uint16_t i;
+
+       if (!config)
+               return;
+
+       for (i = 0; i < ARRAY_SIZE(params); ++i) {
+               GError *err = NULL;
+               int val = g_key_file_get_integer(config, "Controller",
+                                               params[i].val_name, &err);
+               if (err) {
+                       g_clear_error(&err);
+               } else {
+                       DBG("%s=%d", params[i].val_name, val);
+
+                       val = MIN(val, params[i].min);
+                       val = MAX(val, params[i].max);
+                       *params[i].val = val;
+                       ++main_opts.default_params.num_entries;
+               }
+       }
+}
+
 static void parse_config(GKeyFile *config)
 {
        GError *err = NULL;
@@ -514,6 +670,8 @@ static void parse_config(GKeyFile *config)
                val = MAX(val, 1);
                main_opts.gatt_channels = val;
        }
+
+       parse_controller_config(config);
 }
 
 static void init_defaults(void)
@@ -529,6 +687,9 @@ static void init_defaults(void)
        main_opts.reverse_discovery = TRUE;
        main_opts.name_resolv = TRUE;
        main_opts.debug_keys = FALSE;
+       main_opts.default_params.num_entries = 0;
+       main_opts.default_params.br_page_scan_type = 0xFFFF;
+       main_opts.default_params.br_scan_type = 0xFFFF;
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        main_opts.le_privacy = FALSE;
        main_opts.pin_code = NULL;
index 4dbb60a..fbd60bb 100755 (executable)
 # Defaults to "never"
 #JustWorksRepairing = never
 
+[Controller]
+# The following values are used to load default adapter parameters.  BlueZ loads
+# the values into the kernel before the adapter is powered if the kernel
+# supports the MGMT_LOAD_DEFAULT_PARAMETERS command. If a value isn't provided,
+# the kernel will be initialized to it's default value.  The actual value will
+# vary based on the kernel version and thus aren't provided here.
+# The Bluetooth Core Specification should be consulted for the meaning and valid
+# domain of each of these values.
+
+# BR/EDR Page scan activity configuration
+#BRPageScanType=
+#BRPageScanInterval=
+#BRPageScanWindow=
+
+# BR/EDR Inquiry scan activity configuration
+#BRInquiryScanType=
+#BRInquiryScanInterval=
+#BRInquiryScanWindow=
+
+# BR/EDR Link supervision timeout
+#BRLinkSupervisionTimeout=
+
+# BR/EDR Page Timeout
+#BRPageTimeout=
+
+# BR/EDR Sniff Intervals
+#BRMinSniffInterval=
+#BRMaxSniffInterval=
+
+# LE advertisement interval (used for legacy advertisement interface only)
+#LEMinAdvertisementInterval=
+#LEMaxAdvertisementInterval=
+#LEMultiAdvertisementRotationInterval=
+
+# LE scanning parameters used for passive scanning supporting auto connect
+# scenarios
+#LEScanIntervalAutoConnect=
+#LEScanWindowAutoConnect=
+
+# LE scanning parameters used for passive scanning supporting wake from suspend
+# scenarios
+#LEScanIntervalSuspend=
+#LEScanWindowSuspend=
+
+# LE scanning parameters used for active scanning supporting discovery
+# proceedure
+#LEScanIntervalDiscovery=
+#LEScanWindowDiscovery=
+
+# LE scanning parameters used for passive scanning supporting the advertisement
+# monitor Apis
+#LEScanIntervalAdvMonitor=
+#LEScanWindowAdvMonitor=
+
+# LE scanning parameters used for connection establishment.
+#LEScanIntervalConnect=
+#LEScanWindowConnect=
+
+# LE default connection parameters.  These values are superceeded by any
+# specific values provided via the Load Connection Parameters interface
+#LEMinConnectionInterval=
+#LEMaxConnectionInterval=
+#LEConnectionLatency=
+#LEConnectionSupervisionTimeout=
+
 [GATT]
 # GATT attribute cache.
 # Possible values: