This series adds supports for reading default system configurations from
a configuration file. This allows a system to override what are
currently kernel hardcoded values from a conf file.
The dependent kernel patch will be posted after some additional parsing
validation on the tlv is completed.
Changes in v3:
- Fixing const decoration warnings on options.
Changes in v2:
- Fixing checkpatch warning that are applicable.
Alain Michaud (4):
mgmt:adding load default system configuration definitions
adapter:set default system configuration if available
main:read default system configuration from the conf file.
fixing const decoration warnins on options.
lib/mgmt.h | 20 ++++
src/adapter.c | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/hcid.h | 39 ++++++++
src/main.c | 174 ++++++++++++++++++++++++++++++++--
src/main.conf | 65 +++++++++++++
5 files changed, 543 insertions(+), 6 deletions(-)
--
2.27.0.rc0.183.gde8f92d652-goog
This change loads any specified system configuration if provided and
supported by the kernel.
---
Changes in v3: None
Changes in v2: None
src/adapter.c | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/hcid.h | 39 ++++++++
2 files changed, 290 insertions(+)
diff --git a/src/adapter.c b/src/adapter.c
index 972d88772..da3777cba 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -120,6 +120,8 @@ static bool kernel_conn_control = false;
static bool kernel_blocked_keys_supported = false;
+static bool kernel_set_system_params = false;
+
static GList *adapter_list = NULL;
static unsigned int adapter_remaining = 0;
static bool powering_down = false;
@@ -4157,6 +4159,250 @@ static void probe_devices(void *user_data)
device_probe_profiles(device, btd_device_get_uuids(device));
}
+static void load_default_system_params(struct btd_adapter *adapter)
+{
+ /* note: for now all params are 2 bytes, if varying size params are
+ * added, calculating the right size of buffer will be necessary first.
+ */
+ struct controller_params_tlv {
+ uint16_t parameter_type;
+ uint8_t length;
+ uint16_t value;
+ } __packed;
+
+ struct controller_params_tlv *params = NULL;
+ uint16_t i = 0;
+ size_t cp_size;
+
+ if (!main_opts.default_params.num_set_params ||
+ !kernel_set_system_params)
+ return;
+
+ cp_size = sizeof(struct controller_params_tlv) *
+ main_opts.default_params.num_set_params;
+ params = g_try_malloc0(cp_size);
+ if (!params)
+ return;
+
+ if (main_opts.default_params.br_page_scan_type != 0xFFFF) {
+ params[i].parameter_type = 0x0000;
+ params[i].length = sizeof(params[i].value);
+ params[i].value = main_opts.default_params.br_page_scan_type;
+ ++i;
+ }
+
+ if (main_opts.default_params.br_page_scan_interval) {
+ params[i].parameter_type = 0x0001;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.br_page_scan_interval;
+ ++i;
+ }
+
+ if (main_opts.default_params.br_page_scan_window) {
+ params[i].parameter_type = 0x0002;
+ params[i].length = sizeof(params[i].value);
+ params[i].value = main_opts.default_params.br_page_scan_window;
+ ++i;
+ }
+
+ if (main_opts.default_params.br_inquiry_scan_type != 0xFFFF) {
+ params[i].parameter_type = 0x0003;
+ params[i].length = sizeof(params[i].value);
+ params[i].value = main_opts.default_params.br_inquiry_scan_type;
+ ++i;
+ }
+
+ if (main_opts.default_params.br_inquiry_scan_interval) {
+ params[i].parameter_type = 0x0004;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.br_inquiry_scan_interval;
+ ++i;
+ }
+
+ if (main_opts.default_params.br_inquiry_scan_window) {
+ params[i].parameter_type = 0x0005;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.br_inquiry_scan_window;
+ ++i;
+ }
+
+ if (main_opts.default_params.br_link_supervision_timeout) {
+ params[i].parameter_type = 0x0006;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.br_link_supervision_timeout;
+ ++i;
+ }
+
+ if (main_opts.default_params.br_page_timeout) {
+ params[i].parameter_type = 0x0007;
+ params[i].length = sizeof(params[i].value);
+ params[i].value = main_opts.default_params.br_page_timeout;
+ ++i;
+ }
+
+ if (main_opts.default_params.br_min_sniff_interval) {
+ params[i].parameter_type = 0x0008;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.br_min_sniff_interval;
+ ++i;
+ }
+
+ if (main_opts.default_params.br_max_sniff_interval) {
+ params[i].parameter_type = 0x0009;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.br_max_sniff_interval;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_min_adv_interval) {
+ params[i].parameter_type = 0x000a;
+ params[i].length = sizeof(params[i].value);
+ params[i].value = main_opts.default_params.le_min_adv_interval;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_max_adv_interval) {
+ params[i].parameter_type = 0x000b;
+ params[i].length = sizeof(params[i].value);
+ params[i].value = main_opts.default_params.le_max_adv_interval;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_multi_adv_rotation_interval) {
+ params[i].parameter_type = 0x000c;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.le_multi_adv_rotation_interval;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_scan_interval_autoconnect) {
+ params[i].parameter_type = 0x000d;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.le_scan_interval_autoconnect;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_scan_window_autoconnect) {
+ params[i].parameter_type = 0x000e;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.le_scan_window_autoconnect;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_scan_interval_suspend) {
+ params[i].parameter_type = 0x000f;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.le_scan_interval_suspend;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_scan_window_suspend) {
+ params[i].parameter_type = 0x0010;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.le_scan_window_suspend;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_scan_interval_discovery) {
+ params[i].parameter_type = 0x0011;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.le_scan_interval_discovery;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_scan_window_discovery) {
+ params[i].parameter_type = 0x0012;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.le_scan_window_discovery;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_scan_interval_adv_monitor) {
+ params[i].parameter_type = 0x0013;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.le_scan_interval_adv_monitor;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_scan_window_adv_monitor) {
+ params[i].parameter_type = 0x0014;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.le_scan_window_adv_monitor;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_scan_interval_connect) {
+ params[i].parameter_type = 0x0015;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.le_scan_interval_connect;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_scan_window_connect) {
+ params[i].parameter_type = 0x0016;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.le_scan_window_connect;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_min_connection_interval) {
+ params[i].parameter_type = 0x0017;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.le_min_connection_interval;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_max_connection_interval) {
+ params[i].parameter_type = 0x0018;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.le_max_connection_interval;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_connection_latency) {
+ params[i].parameter_type = 0x0019;
+ params[i].length = sizeof(params[i].value);
+ params[i].value =
+ main_opts.default_params.le_connection_latency;
+ ++i;
+ }
+
+ if (main_opts.default_params.le_connection_lsto) {
+ params[i].parameter_type = 0x001a;
+ params[i].length = sizeof(params[i].value);
+ params[i].value = main_opts.default_params.le_connection_lsto;
+ ++i;
+ }
+
+ mgmt_send(adapter->mgmt, MGMT_OP_SET_DEFAULT_SYSTEM_PARAMETERS,
+ adapter->dev_id, cp_size, params, NULL, NULL, NULL);
+
+ btd_error(adapter->dev_id,
+ "Failed to set default system params for hci%u",
+ adapter->dev_id);
+
+ g_free(params);
+}
+
static void load_devices(struct btd_adapter *adapter)
{
char dirname[PATH_MAX];
@@ -8265,6 +8511,7 @@ load:
load_drivers(adapter);
btd_profile_foreach(probe_profile, adapter);
clear_blocked(adapter);
+ load_default_system_params(adapter);
load_devices(adapter);
/* restore Service Changed CCC value for bonded devices */
@@ -9158,6 +9405,10 @@ static void read_commands_complete(uint8_t status, uint16_t length,
DBG("kernel supports the set_blocked_keys op");
kernel_blocked_keys_supported = true;
break;
+ case MGMT_OP_SET_DEFAULT_SYSTEM_PARAMETERS:
+ DBG("kernel supports set system params");
+ kernel_set_system_params = true;
+ break;
default:
break;
}
diff --git a/src/hcid.h b/src/hcid.h
index 1bf93784d..e6d966c58 100644
--- a/src/hcid.h
+++ b/src/hcid.h
@@ -49,6 +49,45 @@ struct main_opts {
uint32_t discovto;
uint8_t privacy;
+ struct {
+ uint16_t num_set_params;
+
+ uint16_t br_page_scan_type;
+ uint16_t br_page_scan_interval;
+ uint16_t br_page_scan_window;
+
+ uint16_t br_inquiry_scan_type;
+ uint16_t br_inquiry_scan_interval;
+ uint16_t br_inquiry_scan_window;
+
+ uint16_t br_link_supervision_timeout;
+ uint16_t br_page_timeout;
+
+ uint16_t br_min_sniff_interval;
+ uint16_t br_max_sniff_interval;
+
+ uint16_t le_min_adv_interval;
+ uint16_t le_max_adv_interval;
+ uint16_t le_multi_adv_rotation_interval;
+
+ uint16_t le_scan_interval_autoconnect;
+ uint16_t le_scan_window_autoconnect;
+ uint16_t le_scan_interval_suspend;
+ uint16_t le_scan_window_suspend;
+ uint16_t le_scan_interval_discovery;
+ uint16_t le_scan_window_discovery;
+ uint16_t le_scan_interval_adv_monitor;
+ uint16_t le_scan_window_adv_monitor;
+ uint16_t le_scan_interval_connect;
+ uint16_t le_scan_window_connect;
+
+ uint16_t le_min_connection_interval;
+ uint16_t le_max_connection_interval;
+ uint16_t le_connection_latency;
+ uint16_t le_connection_lsto;
+ } default_params;
+
+
gboolean reverse_discovery;
gboolean name_resolv;
gboolean debug_keys;
--
2.27.0.rc0.183.gde8f92d652-goog
This change adds support for reading the configurations from the
main.conf file.
---
Changes in v3:
- Fixing const decoration warnings on options.
Changes in v2:
- Fixing checkpatch warning that are applicable.
src/main.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/main.conf | 65 ++++++++++++++++++++
2 files changed, 227 insertions(+)
diff --git a/src/main.c b/src/main.c
index 98621fddf..ca27f313d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -54,6 +54,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"
@@ -97,6 +98,37 @@ static const char *supported_options[] = {
NULL
};
+static const char * const 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",
@@ -118,6 +150,7 @@ static const struct group_table {
const char **options;
} valid_groups[] = {
{ "General", supported_options },
+ { "Controller", controller_options },
{ "Policy", policy_options },
{ "GATT", gatt_options },
{ }
@@ -283,6 +316,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_window,
+ 0x0011,
+ 0x1000},
+ { "BRInquiryScanType",
+ &main_opts.default_params.br_inquiry_scan_type,
+ 0,
+ 1},
+ { "BRInquiryScanInterval",
+ &main_opts.default_params.br_inquiry_scan_interval,
+ 0x0012,
+ 0x1000},
+ { "BRInquiryScanWindow",
+ &main_opts.default_params.br_inquiry_scan_window,
+ 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_window_autoconnect,
+ 0x0004,
+ 0x4000},
+ { "LEScanIntervalSuspend",
+ &main_opts.default_params.le_scan_interval_suspend,
+ 0x0004,
+ 0x4000},
+ { "LEScanWindowSuspend",
+ &main_opts.default_params.le_scan_window_suspend,
+ 0x0004,
+ 0x4000},
+ { "LEScanIntervalDiscovery",
+ &main_opts.default_params.le_scan_interval_discovery,
+ 0x0004,
+ 0x4000},
+ { "LEScanWindowDiscovery",
+ &main_opts.default_params.le_scan_window_discovery,
+ 0x0004,
+ 0x4000},
+ { "LEScanIntervalAdvMonitor",
+ &main_opts.default_params.le_scan_interval_adv_monitor,
+ 0x0004,
+ 0x4000},
+ { "LEScanWindowAdvMonitor",
+ &main_opts.default_params.le_scan_window_adv_monitor,
+ 0x0004,
+ 0x4000},
+ { "LEScanIntervalConnect",
+ &main_opts.default_params.le_scan_interval_connect,
+ 0x0004,
+ 0x4000},
+ { "LEScanWindowConnect",
+ &main_opts.default_params.le_scan_window_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_set_params;
+ }
+ }
+}
+
static void parse_config(GKeyFile *config)
{
GError *err = NULL;
@@ -484,6 +640,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)
@@ -500,6 +658,10 @@ static void init_defaults(void)
main_opts.name_resolv = TRUE;
main_opts.debug_keys = FALSE;
+ main_opts.default_params.num_set_params = 0;
+ main_opts.default_params.br_page_scan_type = 0xFFFF;
+ main_opts.default_params.br_inquiry_scan_type = 0xFFFF;
+
if (sscanf(VERSION, "%hhu.%hhu", &major, &minor) != 2)
return;
diff --git a/src/main.conf b/src/main.conf
index 16701ebe4..92d937f0c 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -77,6 +77,71 @@
# 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:
--
2.27.0.rc0.183.gde8f92d652-goog
This changes fixes const decoration warnins on options.
---
Changes in v3: None
Changes in v2: None
src/main.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/main.c b/src/main.c
index ca27f313d..cea50a3d2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -80,7 +80,7 @@ static enum {
MPS_MULTIPLE,
} mps = MPS_OFF;
-static const char *supported_options[] = {
+static const char * const supported_options[] = {
"Name",
"Class",
"DiscoverableTimeout",
@@ -129,7 +129,7 @@ static const char * const controller_options[] = {
NULL
};
-static const char *policy_options[] = {
+static const char * const policy_options[] = {
"ReconnectUUIDs",
"ReconnectAttempts",
"ReconnectIntervals",
@@ -137,7 +137,7 @@ static const char *policy_options[] = {
NULL
};
-static const char *gatt_options[] = {
+static const char * const gatt_options[] = {
"Cache",
"KeySize",
"ExchangeMTU",
@@ -146,8 +146,8 @@ static const char *gatt_options[] = {
};
static const struct group_table {
- const char *name;
- const char **options;
+ const char * const name;
+ const char * const * const options;
} valid_groups[] = {
{ "General", supported_options },
{ "Controller", controller_options },
@@ -243,7 +243,7 @@ static enum jw_repairing_t parse_jw_repairing(const char *jw_repairing)
static void check_options(GKeyFile *config, const char *group,
- const char **options)
+ const char * const * const options)
{
char **keys;
int i;
--
2.27.0.rc0.183.gde8f92d652-goog
This change adds the load default system configuration definitions
---
Changes in v3: None
Changes in v2: None
lib/mgmt.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/lib/mgmt.h b/lib/mgmt.h
index b4fc72069..ea89c46b1 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -628,6 +628,24 @@ struct mgmt_rp_set_exp_feature {
uint32_t flags;
} __packed;
+#define MGMT_OP_READ_DEFAULT_SYSTEM_PARAMETERS 0x004b
+
+struct mgmt_system_parameter_tlv {
+ uint16_t parameter_type;
+ uint8_t length;
+ uint8_t value[];
+} __packed;
+
+struct mgmt_rp_read_default_system_parameters {
+ uint8_t parameters[0]; // mgmt_system_parameter_tlv
+} __packed;
+
+#define MGMT_OP_SET_DEFAULT_SYSTEM_PARAMETERS 0x004c
+
+struct mgmt_cp_set_default_system_parameters {
+ uint8_t parameters[0]; // mgmt_system_parameter_tlv
+} __packed;
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
uint16_t opcode;
@@ -933,6 +951,8 @@ static const char *mgmt_op[] = {
"Read Security Information", /* 0x0048 */
"Read Experimental Features Information",
"Set Experimental Feature",
+ "Read Default System Configuration",
+ "Set Default System Configuration",
};
static const char *mgmt_ev[] = {
--
2.27.0.rc0.183.gde8f92d652-goog
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
While we are preparing for reviewing the patches, we found the following
issue/warning.
Test Result:
checkpatch Failed
Outputs:
ERROR:INITIALISED_STATIC: do not initialise statics to false
#17: FILE: src/adapter.c:123:
+static bool kernel_set_system_params = false;
- total: 1 errors, 0 warnings, 320 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.
Your patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPLIT_STRING
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
---
Regards,
Linux Bluetooth
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
While we are preparing for reviewing the patches, we found the following
issue/warning.
Test Result:
checkgitlint Failed
Outputs:
1: T3 Title has trailing punctuation (.): "main:read default system configuration from the conf file."
---
Regards,
Linux Bluetooth
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
While we are preparing for reviewing the patches, we found the following
issue/warning.
Test Result:
checkgitlint Failed
Outputs:
1: T3 Title has trailing punctuation (.): "fixing const decoration warnins on options."
---
Regards,
Linux Bluetooth
Hi Alain,
On Fri, May 29, 2020 at 8:41 AM Alain Michaud <[email protected]> wrote:
>
> This change loads any specified system configuration if provided and
> supported by the kernel.
>
> ---
>
> Changes in v3: None
> Changes in v2: None
>
> src/adapter.c | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++
> src/hcid.h | 39 ++++++++
> 2 files changed, 290 insertions(+)
>
> diff --git a/src/adapter.c b/src/adapter.c
> index 972d88772..da3777cba 100644
> --- a/src/adapter.c
> +++ b/src/adapter.c
> @@ -120,6 +120,8 @@ static bool kernel_conn_control = false;
>
> static bool kernel_blocked_keys_supported = false;
>
> +static bool kernel_set_system_params = false;
> +
> static GList *adapter_list = NULL;
> static unsigned int adapter_remaining = 0;
> static bool powering_down = false;
> @@ -4157,6 +4159,250 @@ static void probe_devices(void *user_data)
> device_probe_profiles(device, btd_device_get_uuids(device));
> }
>
> +static void load_default_system_params(struct btd_adapter *adapter)
> +{
> + /* note: for now all params are 2 bytes, if varying size params are
> + * added, calculating the right size of buffer will be necessary first.
> + */
> + struct controller_params_tlv {
> + uint16_t parameter_type;
> + uint8_t length;
> + uint16_t value;
> + } __packed;
Don't we have a definition of the tlv entry on mgmt.h? Id use that
instead of redefining it here.
> + struct controller_params_tlv *params = NULL;
> + uint16_t i = 0;
> + size_t cp_size;
> +
> + if (!main_opts.default_params.num_set_params ||
> + !kernel_set_system_params)
> + return;
> +
> + cp_size = sizeof(struct controller_params_tlv) *
> + main_opts.default_params.num_set_params;
> + params = g_try_malloc0(cp_size);
For new code we prefer to use new0 instead of glib allocation.
> + if (!params)
> + return;
> +
> + if (main_opts.default_params.br_page_scan_type != 0xFFFF) {
> + params[i].parameter_type = 0x0000;
> + params[i].length = sizeof(params[i].value);
> + params[i].value = main_opts.default_params.br_page_scan_type;
> + ++i;
> + }
> +
> + if (main_opts.default_params.br_page_scan_interval) {
> + params[i].parameter_type = 0x0001;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.br_page_scan_interval;
> + ++i;
> + }
> +
> + if (main_opts.default_params.br_page_scan_window) {
> + params[i].parameter_type = 0x0002;
> + params[i].length = sizeof(params[i].value);
> + params[i].value = main_opts.default_params.br_page_scan_window;
> + ++i;
> + }
> +
> + if (main_opts.default_params.br_inquiry_scan_type != 0xFFFF) {
> + params[i].parameter_type = 0x0003;
> + params[i].length = sizeof(params[i].value);
> + params[i].value = main_opts.default_params.br_inquiry_scan_type;
> + ++i;
> + }
> +
> + if (main_opts.default_params.br_inquiry_scan_interval) {
> + params[i].parameter_type = 0x0004;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.br_inquiry_scan_interval;
> + ++i;
> + }
> +
> + if (main_opts.default_params.br_inquiry_scan_window) {
> + params[i].parameter_type = 0x0005;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.br_inquiry_scan_window;
> + ++i;
> + }
> +
> + if (main_opts.default_params.br_link_supervision_timeout) {
> + params[i].parameter_type = 0x0006;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.br_link_supervision_timeout;
> + ++i;
> + }
> +
> + if (main_opts.default_params.br_page_timeout) {
> + params[i].parameter_type = 0x0007;
> + params[i].length = sizeof(params[i].value);
> + params[i].value = main_opts.default_params.br_page_timeout;
> + ++i;
> + }
> +
> + if (main_opts.default_params.br_min_sniff_interval) {
> + params[i].parameter_type = 0x0008;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.br_min_sniff_interval;
> + ++i;
> + }
> +
> + if (main_opts.default_params.br_max_sniff_interval) {
> + params[i].parameter_type = 0x0009;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.br_max_sniff_interval;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_min_adv_interval) {
> + params[i].parameter_type = 0x000a;
> + params[i].length = sizeof(params[i].value);
> + params[i].value = main_opts.default_params.le_min_adv_interval;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_max_adv_interval) {
> + params[i].parameter_type = 0x000b;
> + params[i].length = sizeof(params[i].value);
> + params[i].value = main_opts.default_params.le_max_adv_interval;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_multi_adv_rotation_interval) {
> + params[i].parameter_type = 0x000c;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.le_multi_adv_rotation_interval;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_scan_interval_autoconnect) {
> + params[i].parameter_type = 0x000d;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.le_scan_interval_autoconnect;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_scan_window_autoconnect) {
> + params[i].parameter_type = 0x000e;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.le_scan_window_autoconnect;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_scan_interval_suspend) {
> + params[i].parameter_type = 0x000f;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.le_scan_interval_suspend;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_scan_window_suspend) {
> + params[i].parameter_type = 0x0010;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.le_scan_window_suspend;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_scan_interval_discovery) {
> + params[i].parameter_type = 0x0011;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.le_scan_interval_discovery;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_scan_window_discovery) {
> + params[i].parameter_type = 0x0012;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.le_scan_window_discovery;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_scan_interval_adv_monitor) {
> + params[i].parameter_type = 0x0013;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.le_scan_interval_adv_monitor;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_scan_window_adv_monitor) {
> + params[i].parameter_type = 0x0014;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.le_scan_window_adv_monitor;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_scan_interval_connect) {
> + params[i].parameter_type = 0x0015;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.le_scan_interval_connect;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_scan_window_connect) {
> + params[i].parameter_type = 0x0016;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.le_scan_window_connect;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_min_connection_interval) {
> + params[i].parameter_type = 0x0017;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.le_min_connection_interval;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_max_connection_interval) {
> + params[i].parameter_type = 0x0018;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.le_max_connection_interval;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_connection_latency) {
> + params[i].parameter_type = 0x0019;
> + params[i].length = sizeof(params[i].value);
> + params[i].value =
> + main_opts.default_params.le_connection_latency;
> + ++i;
> + }
> +
> + if (main_opts.default_params.le_connection_lsto) {
> + params[i].parameter_type = 0x001a;
> + params[i].length = sizeof(params[i].value);
> + params[i].value = main_opts.default_params.le_connection_lsto;
> + ++i;
> + }
> +
> + mgmt_send(adapter->mgmt, MGMT_OP_SET_DEFAULT_SYSTEM_PARAMETERS,
> + adapter->dev_id, cp_size, params, NULL, NULL, NULL);
> +
> + btd_error(adapter->dev_id,
> + "Failed to set default system params for hci%u",
> + adapter->dev_id);
I guess we are missing a if statement above otherwise this will always
be printing an error.
> +
> + g_free(params);
> +}
> +
> static void load_devices(struct btd_adapter *adapter)
> {
> char dirname[PATH_MAX];
> @@ -8265,6 +8511,7 @@ load:
> load_drivers(adapter);
> btd_profile_foreach(probe_profile, adapter);
> clear_blocked(adapter);
> + load_default_system_params(adapter);
> load_devices(adapter);
>
> /* restore Service Changed CCC value for bonded devices */
> @@ -9158,6 +9405,10 @@ static void read_commands_complete(uint8_t status, uint16_t length,
> DBG("kernel supports the set_blocked_keys op");
> kernel_blocked_keys_supported = true;
> break;
> + case MGMT_OP_SET_DEFAULT_SYSTEM_PARAMETERS:
> + DBG("kernel supports set system params");
> + kernel_set_system_params = true;
> + break;
> default:
> break;
> }
> diff --git a/src/hcid.h b/src/hcid.h
> index 1bf93784d..e6d966c58 100644
> --- a/src/hcid.h
> +++ b/src/hcid.h
> @@ -49,6 +49,45 @@ struct main_opts {
> uint32_t discovto;
> uint8_t privacy;
>
> + struct {
> + uint16_t num_set_params;
> +
> + uint16_t br_page_scan_type;
> + uint16_t br_page_scan_interval;
> + uint16_t br_page_scan_window;
> +
> + uint16_t br_inquiry_scan_type;
> + uint16_t br_inquiry_scan_interval;
> + uint16_t br_inquiry_scan_window;
> +
> + uint16_t br_link_supervision_timeout;
> + uint16_t br_page_timeout;
> +
> + uint16_t br_min_sniff_interval;
> + uint16_t br_max_sniff_interval;
> +
> + uint16_t le_min_adv_interval;
> + uint16_t le_max_adv_interval;
> + uint16_t le_multi_adv_rotation_interval;
> +
> + uint16_t le_scan_interval_autoconnect;
> + uint16_t le_scan_window_autoconnect;
> + uint16_t le_scan_interval_suspend;
> + uint16_t le_scan_window_suspend;
> + uint16_t le_scan_interval_discovery;
> + uint16_t le_scan_window_discovery;
> + uint16_t le_scan_interval_adv_monitor;
> + uint16_t le_scan_window_adv_monitor;
> + uint16_t le_scan_interval_connect;
> + uint16_t le_scan_window_connect;
> +
> + uint16_t le_min_connection_interval;
> + uint16_t le_max_connection_interval;
> + uint16_t le_connection_latency;
> + uint16_t le_connection_lsto;
> + } default_params;
> +
> +
> gboolean reverse_discovery;
> gboolean name_resolv;
> gboolean debug_keys;
> --
> 2.27.0.rc0.183.gde8f92d652-goog
>
--
Luiz Augusto von Dentz
Hi Alain,
On Fri, May 29, 2020 at 8:41 AM Alain Michaud <[email protected]> wrote:
>
> This changes fixes const decoration warnins on options.
What us this fixing?
> ---
>
> Changes in v3: None
> Changes in v2: None
>
> src/main.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/src/main.c b/src/main.c
> index ca27f313d..cea50a3d2 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -80,7 +80,7 @@ static enum {
> MPS_MULTIPLE,
> } mps = MPS_OFF;
>
> -static const char *supported_options[] = {
> +static const char * const supported_options[] = {
> "Name",
> "Class",
> "DiscoverableTimeout",
> @@ -129,7 +129,7 @@ static const char * const controller_options[] = {
> NULL
> };
>
> -static const char *policy_options[] = {
> +static const char * const policy_options[] = {
> "ReconnectUUIDs",
> "ReconnectAttempts",
> "ReconnectIntervals",
> @@ -137,7 +137,7 @@ static const char *policy_options[] = {
> NULL
> };
>
> -static const char *gatt_options[] = {
> +static const char * const gatt_options[] = {
> "Cache",
> "KeySize",
> "ExchangeMTU",
> @@ -146,8 +146,8 @@ static const char *gatt_options[] = {
> };
>
> static const struct group_table {
> - const char *name;
> - const char **options;
> + const char * const name;
> + const char * const * const options;
> } valid_groups[] = {
> { "General", supported_options },
> { "Controller", controller_options },
> @@ -243,7 +243,7 @@ static enum jw_repairing_t parse_jw_repairing(const char *jw_repairing)
>
>
> static void check_options(GKeyFile *config, const char *group,
> - const char **options)
> + const char * const * const options)
> {
> char **keys;
> int i;
> --
> 2.27.0.rc0.183.gde8f92d652-goog
>
I wonder how usufull is to tell it is a constant pointer to a constant
character given that is so rarely in the kernel and userspace,
something like const char * const * const would be very hard to keep
it readable.
--
Luiz Augusto von Dentz
Hi Alain,
On Fri, May 29, 2020 at 10:05 AM Luiz Augusto von Dentz
<[email protected]> wrote:
>
> Hi Alain,
>
> On Fri, May 29, 2020 at 8:41 AM Alain Michaud <[email protected]> wrote:
> >
> > This change loads any specified system configuration if provided and
> > supported by the kernel.
> >
> > ---
> >
> > Changes in v3: None
> > Changes in v2: None
> >
> > src/adapter.c | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++
> > src/hcid.h | 39 ++++++++
> > 2 files changed, 290 insertions(+)
> >
> > diff --git a/src/adapter.c b/src/adapter.c
> > index 972d88772..da3777cba 100644
> > --- a/src/adapter.c
> > +++ b/src/adapter.c
> > @@ -120,6 +120,8 @@ static bool kernel_conn_control = false;
> >
> > static bool kernel_blocked_keys_supported = false;
> >
> > +static bool kernel_set_system_params = false;
> > +
> > static GList *adapter_list = NULL;
> > static unsigned int adapter_remaining = 0;
> > static bool powering_down = false;
> > @@ -4157,6 +4159,250 @@ static void probe_devices(void *user_data)
> > device_probe_profiles(device, btd_device_get_uuids(device));
> > }
> >
> > +static void load_default_system_params(struct btd_adapter *adapter)
> > +{
> > + /* note: for now all params are 2 bytes, if varying size params are
> > + * added, calculating the right size of buffer will be necessary first.
> > + */
> > + struct controller_params_tlv {
> > + uint16_t parameter_type;
> > + uint8_t length;
> > + uint16_t value;
> > + } __packed;
>
> Don't we have a definition of the tlv entry on mgmt.h? Id use that
> instead of redefining it here.
Ive actually end up cleanup up this a bit:
https://gist.github.com/Vudentz/4426a1032e21b73229b9439aba6f0105
Though this code would probably need some rework if we had to support
different sizes for the value, so we probably need the value to be a
union with different types it can assume, but if we were to support
variable length it would be better to use something like an iovec and
make changes to mgmt_send (or add mgmt_send_iov).
>
> > + struct controller_params_tlv *params = NULL;
> > + uint16_t i = 0;
> > + size_t cp_size;
> > +
> > + if (!main_opts.default_params.num_set_params ||
> > + !kernel_set_system_params)
> > + return;
> > +
> > + cp_size = sizeof(struct controller_params_tlv) *
> > + main_opts.default_params.num_set_params;
> > + params = g_try_malloc0(cp_size);
>
> For new code we prefer to use new0 instead of glib allocation.
>
> > + if (!params)
> > + return;
> > +
> > + if (main_opts.default_params.br_page_scan_type != 0xFFFF) {
> > + params[i].parameter_type = 0x0000;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value = main_opts.default_params.br_page_scan_type;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.br_page_scan_interval) {
> > + params[i].parameter_type = 0x0001;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.br_page_scan_interval;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.br_page_scan_window) {
> > + params[i].parameter_type = 0x0002;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value = main_opts.default_params.br_page_scan_window;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.br_inquiry_scan_type != 0xFFFF) {
> > + params[i].parameter_type = 0x0003;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value = main_opts.default_params.br_inquiry_scan_type;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.br_inquiry_scan_interval) {
> > + params[i].parameter_type = 0x0004;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.br_inquiry_scan_interval;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.br_inquiry_scan_window) {
> > + params[i].parameter_type = 0x0005;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.br_inquiry_scan_window;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.br_link_supervision_timeout) {
> > + params[i].parameter_type = 0x0006;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.br_link_supervision_timeout;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.br_page_timeout) {
> > + params[i].parameter_type = 0x0007;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value = main_opts.default_params.br_page_timeout;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.br_min_sniff_interval) {
> > + params[i].parameter_type = 0x0008;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.br_min_sniff_interval;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.br_max_sniff_interval) {
> > + params[i].parameter_type = 0x0009;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.br_max_sniff_interval;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_min_adv_interval) {
> > + params[i].parameter_type = 0x000a;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value = main_opts.default_params.le_min_adv_interval;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_max_adv_interval) {
> > + params[i].parameter_type = 0x000b;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value = main_opts.default_params.le_max_adv_interval;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_multi_adv_rotation_interval) {
> > + params[i].parameter_type = 0x000c;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.le_multi_adv_rotation_interval;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_scan_interval_autoconnect) {
> > + params[i].parameter_type = 0x000d;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.le_scan_interval_autoconnect;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_scan_window_autoconnect) {
> > + params[i].parameter_type = 0x000e;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.le_scan_window_autoconnect;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_scan_interval_suspend) {
> > + params[i].parameter_type = 0x000f;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.le_scan_interval_suspend;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_scan_window_suspend) {
> > + params[i].parameter_type = 0x0010;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.le_scan_window_suspend;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_scan_interval_discovery) {
> > + params[i].parameter_type = 0x0011;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.le_scan_interval_discovery;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_scan_window_discovery) {
> > + params[i].parameter_type = 0x0012;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.le_scan_window_discovery;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_scan_interval_adv_monitor) {
> > + params[i].parameter_type = 0x0013;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.le_scan_interval_adv_monitor;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_scan_window_adv_monitor) {
> > + params[i].parameter_type = 0x0014;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.le_scan_window_adv_monitor;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_scan_interval_connect) {
> > + params[i].parameter_type = 0x0015;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.le_scan_interval_connect;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_scan_window_connect) {
> > + params[i].parameter_type = 0x0016;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.le_scan_window_connect;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_min_connection_interval) {
> > + params[i].parameter_type = 0x0017;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.le_min_connection_interval;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_max_connection_interval) {
> > + params[i].parameter_type = 0x0018;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.le_max_connection_interval;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_connection_latency) {
> > + params[i].parameter_type = 0x0019;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value =
> > + main_opts.default_params.le_connection_latency;
> > + ++i;
> > + }
> > +
> > + if (main_opts.default_params.le_connection_lsto) {
> > + params[i].parameter_type = 0x001a;
> > + params[i].length = sizeof(params[i].value);
> > + params[i].value = main_opts.default_params.le_connection_lsto;
> > + ++i;
> > + }
> > +
> > + mgmt_send(adapter->mgmt, MGMT_OP_SET_DEFAULT_SYSTEM_PARAMETERS,
> > + adapter->dev_id, cp_size, params, NULL, NULL, NULL);
> > +
> > + btd_error(adapter->dev_id,
> > + "Failed to set default system params for hci%u",
> > + adapter->dev_id);
>
> I guess we are missing a if statement above otherwise this will always
> be printing an error.
>
> > +
> > + g_free(params);
> > +}
> > +
> > static void load_devices(struct btd_adapter *adapter)
> > {
> > char dirname[PATH_MAX];
> > @@ -8265,6 +8511,7 @@ load:
> > load_drivers(adapter);
> > btd_profile_foreach(probe_profile, adapter);
> > clear_blocked(adapter);
> > + load_default_system_params(adapter);
> > load_devices(adapter);
> >
> > /* restore Service Changed CCC value for bonded devices */
> > @@ -9158,6 +9405,10 @@ static void read_commands_complete(uint8_t status, uint16_t length,
> > DBG("kernel supports the set_blocked_keys op");
> > kernel_blocked_keys_supported = true;
> > break;
> > + case MGMT_OP_SET_DEFAULT_SYSTEM_PARAMETERS:
> > + DBG("kernel supports set system params");
> > + kernel_set_system_params = true;
> > + break;
> > default:
> > break;
> > }
> > diff --git a/src/hcid.h b/src/hcid.h
> > index 1bf93784d..e6d966c58 100644
> > --- a/src/hcid.h
> > +++ b/src/hcid.h
> > @@ -49,6 +49,45 @@ struct main_opts {
> > uint32_t discovto;
> > uint8_t privacy;
> >
> > + struct {
> > + uint16_t num_set_params;
> > +
> > + uint16_t br_page_scan_type;
> > + uint16_t br_page_scan_interval;
> > + uint16_t br_page_scan_window;
> > +
> > + uint16_t br_inquiry_scan_type;
> > + uint16_t br_inquiry_scan_interval;
> > + uint16_t br_inquiry_scan_window;
> > +
> > + uint16_t br_link_supervision_timeout;
> > + uint16_t br_page_timeout;
> > +
> > + uint16_t br_min_sniff_interval;
> > + uint16_t br_max_sniff_interval;
> > +
> > + uint16_t le_min_adv_interval;
> > + uint16_t le_max_adv_interval;
> > + uint16_t le_multi_adv_rotation_interval;
> > +
> > + uint16_t le_scan_interval_autoconnect;
> > + uint16_t le_scan_window_autoconnect;
> > + uint16_t le_scan_interval_suspend;
> > + uint16_t le_scan_window_suspend;
> > + uint16_t le_scan_interval_discovery;
> > + uint16_t le_scan_window_discovery;
> > + uint16_t le_scan_interval_adv_monitor;
> > + uint16_t le_scan_window_adv_monitor;
> > + uint16_t le_scan_interval_connect;
> > + uint16_t le_scan_window_connect;
> > +
> > + uint16_t le_min_connection_interval;
> > + uint16_t le_max_connection_interval;
> > + uint16_t le_connection_latency;
> > + uint16_t le_connection_lsto;
> > + } default_params;
> > +
> > +
> > gboolean reverse_discovery;
> > gboolean name_resolv;
> > gboolean debug_keys;
> > --
> > 2.27.0.rc0.183.gde8f92d652-goog
> >
>
>
> --
> Luiz Augusto von Dentz
--
Luiz Augusto von Dentz
Hi Luiz,
On Fri, May 29, 2020 at 1:17 PM Luiz Augusto von Dentz
<[email protected]> wrote:
>
> Hi Alain,
>
> On Fri, May 29, 2020 at 8:41 AM Alain Michaud <[email protected]> wrote:
> >
> > This changes fixes const decoration warnins on options.
>
> What us this fixing?
>
> > ---
> >
> > Changes in v3: None
> > Changes in v2: None
> >
> > src/main.c | 12 ++++++------
> > 1 file changed, 6 insertions(+), 6 deletions(-)
> >
> > diff --git a/src/main.c b/src/main.c
> > index ca27f313d..cea50a3d2 100644
> > --- a/src/main.c
> > +++ b/src/main.c
> > @@ -80,7 +80,7 @@ static enum {
> > MPS_MULTIPLE,
> > } mps = MPS_OFF;
> >
> > -static const char *supported_options[] = {
> > +static const char * const supported_options[] = {
> > "Name",
> > "Class",
> > "DiscoverableTimeout",
> > @@ -129,7 +129,7 @@ static const char * const controller_options[] = {
> > NULL
> > };
> >
> > -static const char *policy_options[] = {
> > +static const char * const policy_options[] = {
> > "ReconnectUUIDs",
> > "ReconnectAttempts",
> > "ReconnectIntervals",
> > @@ -137,7 +137,7 @@ static const char *policy_options[] = {
> > NULL
> > };
> >
> > -static const char *gatt_options[] = {
> > +static const char * const gatt_options[] = {
> > "Cache",
> > "KeySize",
> > "ExchangeMTU",
> > @@ -146,8 +146,8 @@ static const char *gatt_options[] = {
> > };
> >
> > static const struct group_table {
> > - const char *name;
> > - const char **options;
> > + const char * const name;
> > + const char * const * const options;
> > } valid_groups[] = {
> > { "General", supported_options },
> > { "Controller", controller_options },
> > @@ -243,7 +243,7 @@ static enum jw_repairing_t parse_jw_repairing(const char *jw_repairing)
> >
> >
> > static void check_options(GKeyFile *config, const char *group,
> > - const char **options)
> > + const char * const * const options)
> > {
> > char **keys;
> > int i;
> > --
> > 2.27.0.rc0.183.gde8f92d652-goog
> >
>
> I wonder how usufull is to tell it is a constant pointer to a constant
> character given that is so rarely in the kernel and userspace,
> something like const char * const * const would be very hard to keep
> it readable.
I'm personally a big fan of leveraging the compiler to find bugs, but
in this case it also allows the compiler to put all the strings into
read only sections. In this example, it will catch code trying to
write into the string or prevent code execution in the read only
sections if there is ever a bug that leverages this data section to
store code that can be manipulated. For readability, I've seen other
platforms use type definitions LPCSTR to typedef const char * const
etc.. I'm happy to follow guidance here.
>
> --
> Luiz Augusto von Dentz
Hi Alain,
On Fri, May 29, 2020 at 8:42 AM Alain Michaud <[email protected]> wrote:
>
> This change adds the load default system configuration definitions
>
> ---
>
> Changes in v3: None
> Changes in v2: None
>
> lib/mgmt.h | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/lib/mgmt.h b/lib/mgmt.h
> index b4fc72069..ea89c46b1 100644
> --- a/lib/mgmt.h
> +++ b/lib/mgmt.h
> @@ -628,6 +628,24 @@ struct mgmt_rp_set_exp_feature {
> uint32_t flags;
> } __packed;
>
> +#define MGMT_OP_READ_DEFAULT_SYSTEM_PARAMETERS 0x004b
> +
> +struct mgmt_system_parameter_tlv {
> + uint16_t parameter_type;
> + uint8_t length;
> + uint8_t value[];
> +} __packed;
> +
> +struct mgmt_rp_read_default_system_parameters {
> + uint8_t parameters[0]; // mgmt_system_parameter_tlv
> +} __packed;
> +
> +#define MGMT_OP_SET_DEFAULT_SYSTEM_PARAMETERS 0x004c
> +
> +struct mgmt_cp_set_default_system_parameters {
> + uint8_t parameters[0]; // mgmt_system_parameter_tlv
> +} __packed;
> +
> #define MGMT_EV_CMD_COMPLETE 0x0001
> struct mgmt_ev_cmd_complete {
> uint16_t opcode;
> @@ -933,6 +951,8 @@ static const char *mgmt_op[] = {
> "Read Security Information", /* 0x0048 */
> "Read Experimental Features Information",
> "Set Experimental Feature",
> + "Read Default System Configuration",
> + "Set Default System Configuration",
> };
>
> static const char *mgmt_ev[] = {
> --
> 2.27.0.rc0.183.gde8f92d652-goog
Applied 1-3, thanks. I could not make up my mind regarding 4/4, while
it seems correct it doesn't seem to be a common practice on C projects
(e.g: linux, zephyr, etc.), most likely because it would not save much
in practice since it just making const pointer while the string
literal is already marked as const.
--
Luiz Augusto von Dentz
Thanks Luiz.
On Thu, Jun 4, 2020 at 6:58 PM Luiz Augusto von Dentz
<[email protected]> wrote:
>
> Hi Alain,
>
> On Fri, May 29, 2020 at 8:42 AM Alain Michaud <[email protected]> wrote:
> >
> > This change adds the load default system configuration definitions
> >
> > ---
> >
> > Changes in v3: None
> > Changes in v2: None
> >
> > lib/mgmt.h | 20 ++++++++++++++++++++
> > 1 file changed, 20 insertions(+)
> >
> > diff --git a/lib/mgmt.h b/lib/mgmt.h
> > index b4fc72069..ea89c46b1 100644
> > --- a/lib/mgmt.h
> > +++ b/lib/mgmt.h
> > @@ -628,6 +628,24 @@ struct mgmt_rp_set_exp_feature {
> > uint32_t flags;
> > } __packed;
> >
> > +#define MGMT_OP_READ_DEFAULT_SYSTEM_PARAMETERS 0x004b
> > +
> > +struct mgmt_system_parameter_tlv {
> > + uint16_t parameter_type;
> > + uint8_t length;
> > + uint8_t value[];
> > +} __packed;
> > +
> > +struct mgmt_rp_read_default_system_parameters {
> > + uint8_t parameters[0]; // mgmt_system_parameter_tlv
> > +} __packed;
> > +
> > +#define MGMT_OP_SET_DEFAULT_SYSTEM_PARAMETERS 0x004c
> > +
> > +struct mgmt_cp_set_default_system_parameters {
> > + uint8_t parameters[0]; // mgmt_system_parameter_tlv
> > +} __packed;
> > +
> > #define MGMT_EV_CMD_COMPLETE 0x0001
> > struct mgmt_ev_cmd_complete {
> > uint16_t opcode;
> > @@ -933,6 +951,8 @@ static const char *mgmt_op[] = {
> > "Read Security Information", /* 0x0048 */
> > "Read Experimental Features Information",
> > "Set Experimental Feature",
> > + "Read Default System Configuration",
> > + "Set Default System Configuration",
> > };
> >
> > static const char *mgmt_ev[] = {
> > --
> > 2.27.0.rc0.183.gde8f92d652-goog
>
> Applied 1-3, thanks. I could not make up my mind regarding 4/4, while
> it seems correct it doesn't seem to be a common practice on C projects
> (e.g: linux, zephyr, etc.), most likely because it would not save much
> in practice since it just making const pointer while the string
> literal is already marked as const.
>
> --
> Luiz Augusto von Dentz
Hi Alain,
>>> ---
>>>
>>> Changes in v3: None
>>> Changes in v2: None
>>>
>>> src/main.c | 12 ++++++------
>>> 1 file changed, 6 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/src/main.c b/src/main.c
>>> index ca27f313d..cea50a3d2 100644
>>> --- a/src/main.c
>>> +++ b/src/main.c
>>> @@ -80,7 +80,7 @@ static enum {
>>> MPS_MULTIPLE,
>>> } mps = MPS_OFF;
>>>
>>> -static const char *supported_options[] = {
>>> +static const char * const supported_options[] = {
>>> "Name",
>>> "Class",
>>> "DiscoverableTimeout",
>>> @@ -129,7 +129,7 @@ static const char * const controller_options[] = {
>>> NULL
>>> };
>>>
>>> -static const char *policy_options[] = {
>>> +static const char * const policy_options[] = {
>>> "ReconnectUUIDs",
>>> "ReconnectAttempts",
>>> "ReconnectIntervals",
>>> @@ -137,7 +137,7 @@ static const char *policy_options[] = {
>>> NULL
>>> };
>>>
>>> -static const char *gatt_options[] = {
>>> +static const char * const gatt_options[] = {
>>> "Cache",
>>> "KeySize",
>>> "ExchangeMTU",
>>> @@ -146,8 +146,8 @@ static const char *gatt_options[] = {
>>> };
>>>
>>> static const struct group_table {
>>> - const char *name;
>>> - const char **options;
>>> + const char * const name;
>>> + const char * const * const options;
>>> } valid_groups[] = {
>>> { "General", supported_options },
>>> { "Controller", controller_options },
>>> @@ -243,7 +243,7 @@ static enum jw_repairing_t parse_jw_repairing(const char *jw_repairing)
>>>
>>>
>>> static void check_options(GKeyFile *config, const char *group,
>>> - const char **options)
>>> + const char * const * const options)
>>> {
>>> char **keys;
>>> int i;
>>> --
>>> 2.27.0.rc0.183.gde8f92d652-goog
>>>
>>
>> I wonder how usufull is to tell it is a constant pointer to a constant
>> character given that is so rarely in the kernel and userspace,
>> something like const char * const * const would be very hard to keep
>> it readable.
>
> I'm personally a big fan of leveraging the compiler to find bugs, but
> in this case it also allows the compiler to put all the strings into
> read only sections. In this example, it will catch code trying to
> write into the string or prevent code execution in the read only
> sections if there is ever a bug that leverages this data section to
> store code that can be manipulated. For readability, I've seen other
> platforms use type definitions LPCSTR to typedef const char * const
> etc.. I'm happy to follow guidance here.
I am a big fan of letting the compiler help us, but the readability concerns me a bit in this case. Can we explore what kind of macros we might be able to introduce to make this easier on the eyes.
Regards
Marcel