Linux-Bluetooth Archive on lore.kernel.org
 help / color / Atom feed
* [BlueZ PATCH v2] core: Add support of variable length params in mgmt_config
@ 2020-10-15  4:01 Howard Chung
  2020-10-15  4:35 ` [BlueZ,v2] " bluez.test.bot
  2020-10-15 16:10 ` [BlueZ PATCH v2] " Luiz Augusto von Dentz
  0 siblings, 2 replies; 3+ messages in thread
From: Howard Chung @ 2020-10-15  4:01 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: mmandlik, apusaka, alainm, luiz.dentz, mcchou, Howard Chung

This adds support of variable length parameters in mgmt_config.
Also fixed the endian issue.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
---

Changes in v2:
- fix multiple line dereference issue

 src/adapter.c | 268 +++++++++++++++++++-------------------------------
 src/hcid.h    |   1 +
 src/main.c    |  36 ++++++-
 3 files changed, 138 insertions(+), 167 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index c0053000ac19..9c61e7bf204f 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -4163,269 +4163,207 @@ static void probe_devices(void *user_data)
 	device_probe_profiles(device, btd_device_get_uuids(device));
 }
 
+static uint8_t *set_mgmt_tlv(uint8_t *cur, uint16_t type, uint8_t length,
+								void *value)
+{
+	struct mgmt_tlv *entry = (struct mgmt_tlv *)cur;
+
+	entry->type = htobs(type);
+	entry->length = length;
+	memcpy(entry->value, value, length);
+	cur += sizeof(*entry) + length;
+	return cur;
+}
+
 static void load_default_system_params(struct btd_adapter *adapter)
 {
-	struct {
-		struct mgmt_tlv entry;
-		union {
-			uint16_t u16;
-		};
-	} __packed *params;
-	uint16_t i = 0;
-	size_t len = 0;
+	uint8_t *buf, *cur;
 	unsigned int err;
 
 	if (!main_opts.default_params.num_entries ||
 	    !btd_has_kernel_features(KERNEL_SET_SYSTEM_CONFIG))
 		return;
 
-	params = malloc0(sizeof(*params) *
-			main_opts.default_params.num_entries);
-
-	len = sizeof(params->entry) * main_opts.default_params.num_entries;
+	buf = malloc0(sizeof(struct mgmt_tlv) *
+			main_opts.default_params.num_entries +
+			main_opts.default_params.total_size);
+	cur = buf;
 
 	if (main_opts.default_params.br_page_scan_type != 0xFFFF) {
-		params[i].entry.type = 0x0000;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.br_page_scan_type;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0000,
+			sizeof(main_opts.default_params.br_page_scan_type),
+			&main_opts.default_params.br_page_scan_type);
 	}
 
 	if (main_opts.default_params.br_page_scan_interval) {
-		params[i].entry.type = 0x0001;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.br_page_scan_interval;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0001,
+			sizeof(main_opts.default_params.br_page_scan_interval),
+			&main_opts.default_params.br_page_scan_interval);
 	}
 
 	if (main_opts.default_params.br_page_scan_win) {
-		params[i].entry.type = 0x0002;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.br_page_scan_win;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0002,
+			sizeof(main_opts.default_params.br_page_scan_win),
+			&main_opts.default_params.br_page_scan_win);
 	}
 
 	if (main_opts.default_params.br_scan_type != 0xFFFF) {
-		params[i].entry.type = 0x0003;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.br_scan_type;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0003,
+			sizeof(main_opts.default_params.br_scan_type),
+			&main_opts.default_params.br_scan_type);
 	}
 
 	if (main_opts.default_params.br_scan_interval) {
-		params[i].entry.type = 0x0004;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.br_scan_interval;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0004,
+			sizeof(main_opts.default_params.br_scan_interval),
+			&main_opts.default_params.br_scan_interval);
 	}
 
 	if (main_opts.default_params.br_scan_win) {
-		params[i].entry.type = 0x0005;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.br_scan_win;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0005,
+			sizeof(main_opts.default_params.br_scan_win),
+			&main_opts.default_params.br_scan_win);
 	}
 
 	if (main_opts.default_params.br_link_supervision_timeout) {
-		params[i].entry.type = 0x0006;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 =
-			main_opts.default_params.br_link_supervision_timeout;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0006,
+			sizeof(main_opts.default_params.br_link_supervision_timeout),
+			&main_opts.default_params.br_link_supervision_timeout);
 	}
 
 	if (main_opts.default_params.br_page_timeout) {
-		params[i].entry.type = 0x0007;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.br_page_timeout;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0007,
+			sizeof(main_opts.default_params.br_page_timeout),
+			&main_opts.default_params.br_page_timeout);
 	}
 
 	if (main_opts.default_params.br_min_sniff_interval) {
-		params[i].entry.type = 0x0008;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.br_min_sniff_interval;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0008,
+			sizeof(main_opts.default_params.br_min_sniff_interval),
+			&main_opts.default_params.br_min_sniff_interval);
 	}
 
 	if (main_opts.default_params.br_max_sniff_interval) {
-		params[i].entry.type = 0x0009;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.br_max_sniff_interval;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0009,
+			sizeof(main_opts.default_params.br_max_sniff_interval),
+			&main_opts.default_params.br_max_sniff_interval);
 	}
 
 	if (main_opts.default_params.le_min_adv_interval) {
-		params[i].entry.type = 0x000a;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.le_min_adv_interval;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x000a,
+			sizeof(main_opts.default_params.le_min_adv_interval),
+			&main_opts.default_params.le_min_adv_interval);
 	}
 
 	if (main_opts.default_params.le_max_adv_interval) {
-		params[i].entry.type = 0x000b;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.le_max_adv_interval;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x000b,
+			sizeof(main_opts.default_params.le_max_adv_interval),
+			&main_opts.default_params.le_max_adv_interval);
 	}
 
 	if (main_opts.default_params.le_multi_adv_rotation_interval) {
-		params[i].entry.type = 0x000c;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 =
-			main_opts.default_params.le_multi_adv_rotation_interval;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x000c,
+			sizeof(main_opts.default_params.le_multi_adv_rotation_interval),
+			&main_opts.default_params.le_multi_adv_rotation_interval);
 	}
 
 	if (main_opts.default_params.le_scan_interval_autoconnect) {
-		params[i].entry.type = 0x000d;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 =
-			main_opts.default_params.le_scan_interval_autoconnect;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x000d,
+			sizeof(main_opts.default_params.le_scan_interval_autoconnect),
+			&main_opts.default_params.le_scan_interval_autoconnect);
 	}
 
 	if (main_opts.default_params.le_scan_win_autoconnect) {
-		params[i].entry.type = 0x000e;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 =
-			main_opts.default_params.le_scan_win_autoconnect;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x000e,
+			sizeof(main_opts.default_params.le_scan_win_autoconnect),
+			&main_opts.default_params.le_scan_win_autoconnect);
 	}
 
 	if (main_opts.default_params.le_scan_interval_suspend) {
-		params[i].entry.type = 0x000f;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 =
-			main_opts.default_params.le_scan_interval_suspend;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x000f,
+			sizeof(main_opts.default_params.le_scan_interval_suspend),
+			&main_opts.default_params.le_scan_interval_suspend);
 	}
 
 	if (main_opts.default_params.le_scan_win_suspend) {
-		params[i].entry.type = 0x0010;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.le_scan_win_suspend;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0010,
+			sizeof(main_opts.default_params.le_scan_win_suspend),
+			&main_opts.default_params.le_scan_win_suspend);
 	}
 
 	if (main_opts.default_params.le_scan_interval_discovery) {
-		params[i].entry.type = 0x0011;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 =
-			main_opts.default_params.le_scan_interval_discovery;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0011,
+			sizeof(main_opts.default_params.le_scan_interval_discovery),
+			&main_opts.default_params.le_scan_interval_discovery);
 	}
 
 	if (main_opts.default_params.le_scan_win_discovery) {
-		params[i].entry.type = 0x0012;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 =
-			main_opts.default_params.le_scan_win_discovery;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0012,
+			sizeof(main_opts.default_params.le_scan_win_discovery),
+			&main_opts.default_params.le_scan_win_discovery);
 	}
 
 	if (main_opts.default_params.le_scan_interval_adv_monitor) {
-		params[i].entry.type = 0x0013;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 =
-			main_opts.default_params.le_scan_interval_adv_monitor;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0013,
+			sizeof(main_opts.default_params.le_scan_interval_adv_monitor),
+			&main_opts.default_params.le_scan_interval_adv_monitor);
 	}
 
 	if (main_opts.default_params.le_scan_win_adv_monitor) {
-		params[i].entry.type = 0x0014;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 =
-			main_opts.default_params.le_scan_win_adv_monitor;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0014,
+			sizeof(main_opts.default_params.le_scan_win_adv_monitor),
+			&main_opts.default_params.le_scan_win_adv_monitor);
 	}
 
 	if (main_opts.default_params.le_scan_interval_connect) {
-		params[i].entry.type = 0x0015;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 =
-			main_opts.default_params.le_scan_interval_connect;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0015,
+			sizeof(main_opts.default_params.le_scan_interval_connect),
+			&main_opts.default_params.le_scan_interval_connect);
 	}
 
 	if (main_opts.default_params.le_scan_win_connect) {
-		params[i].entry.type = 0x0016;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.le_scan_win_connect;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0016,
+			sizeof(main_opts.default_params.le_scan_win_connect),
+			&main_opts.default_params.le_scan_win_connect);
 	}
 
 	if (main_opts.default_params.le_min_conn_interval) {
-		params[i].entry.type = 0x0017;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.le_min_conn_interval;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0017,
+			sizeof(main_opts.default_params.le_min_conn_interval),
+			&main_opts.default_params.le_min_conn_interval);
 	}
 
 	if (main_opts.default_params.le_max_conn_interval) {
-		params[i].entry.type = 0x0018;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.le_max_conn_interval;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0018,
+			sizeof(main_opts.default_params.le_max_conn_interval),
+			&main_opts.default_params.le_max_conn_interval);
 	}
 
 	if (main_opts.default_params.le_conn_latency) {
-		params[i].entry.type = 0x0019;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.le_conn_latency;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x0019,
+			sizeof(main_opts.default_params.le_conn_latency),
+			&main_opts.default_params.le_conn_latency);
 	}
 
 	if (main_opts.default_params.le_conn_lsto) {
-		params[i].entry.type = 0x001a;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.le_conn_lsto;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x001a,
+			sizeof(main_opts.default_params.le_conn_lsto),
+			&main_opts.default_params.le_conn_lsto);
 	}
 
 	if (main_opts.default_params.le_autoconnect_timeout) {
-		params[i].entry.type = 0x001b;
-		params[i].entry.length = sizeof(params[i].u16);
-		params[i].u16 = main_opts.default_params.le_autoconnect_timeout;
-		++i;
-		len += sizeof(params[i].u16);
+		cur = set_mgmt_tlv(cur, 0x001b,
+			sizeof(main_opts.default_params.le_autoconnect_timeout),
+			&main_opts.default_params.le_autoconnect_timeout);
 	}
 
 	err = mgmt_send(adapter->mgmt, MGMT_OP_SET_DEF_SYSTEM_CONFIG,
-			adapter->dev_id, len, params, NULL, NULL, NULL);
+			adapter->dev_id, cur-buf, buf, NULL, NULL, NULL);
 	if (!err)
 		btd_error(adapter->dev_id,
 				"Failed to set default system config for hci%u",
 				adapter->dev_id);
-
-	free(params);
+	free(buf);
 }
 
 static void load_devices(struct btd_adapter *adapter)
diff --git a/src/hcid.h b/src/hcid.h
index 95d4b9665193..adeb1f92333c 100644
--- a/src/hcid.h
+++ b/src/hcid.h
@@ -45,6 +45,7 @@ struct main_opts {
 
 	struct {
 		uint16_t	num_entries;
+		uint16_t	total_size;
 
 		uint16_t	br_page_scan_type;
 		uint16_t	br_page_scan_interval;
diff --git a/src/main.c b/src/main.c
index 77be776686a8..243470b6eb88 100644
--- a/src/main.c
+++ b/src/main.c
@@ -305,120 +305,149 @@ static void parse_controller_config(GKeyFile *config)
 {
 	static const struct {
 		const char * const val_name;
-		uint16_t * const val;
+		void * const val;
+		const size_t size;
 		const uint16_t min;
 		const uint16_t max;
 	} params[] = {
 		{ "BRPageScanType",
 		  &main_opts.default_params.br_page_scan_type,
+		  sizeof(main_opts.default_params.br_page_scan_type),
 		  0,
 		  1},
 		{ "BRPageScanInterval",
 		  &main_opts.default_params.br_page_scan_interval,
+		  sizeof(main_opts.default_params.br_page_scan_interval),
 		  0x0012,
 		  0x1000},
 		{ "BRPageScanWindow",
 		  &main_opts.default_params.br_page_scan_win,
+		  sizeof(main_opts.default_params.br_page_scan_win),
 		  0x0011,
 		  0x1000},
 		{ "BRInquiryScanType",
 		  &main_opts.default_params.br_scan_type,
+		  sizeof(main_opts.default_params.br_scan_type),
 		  0,
 		  1},
 		{ "BRInquiryScanInterval",
 		  &main_opts.default_params.br_scan_interval,
+		  sizeof(main_opts.default_params.br_scan_interval),
 		  0x0012,
 		  0x1000},
 		{ "BRInquiryScanWindow",
 		  &main_opts.default_params.br_scan_win,
+		  sizeof(main_opts.default_params.br_scan_win),
 		  0x0011,
 		  0x1000},
 		{ "BRLinkSupervisionTimeout",
 		  &main_opts.default_params.br_link_supervision_timeout,
+		  sizeof(main_opts.default_params.br_link_supervision_timeout),
 		  0x0001,
 		  0xFFFF},
 		{ "BRPageTimeout",
 		  &main_opts.default_params.br_page_timeout,
+		  sizeof(main_opts.default_params.br_page_scan_win),
 		  0x0001,
 		  0xFFFF},
 		{ "BRMinSniffInterval",
 		  &main_opts.default_params.br_min_sniff_interval,
+		  sizeof(main_opts.default_params.br_min_sniff_interval),
 		  0x0001,
 		  0xFFFE},
 		{ "BRMaxSniffInterval",
 		  &main_opts.default_params.br_max_sniff_interval,
+		  sizeof(main_opts.default_params.br_max_sniff_interval),
 		  0x0001,
 		  0xFFFE},
 		{ "LEMinAdvertisementInterval",
 		  &main_opts.default_params.le_min_adv_interval,
+		  sizeof(main_opts.default_params.le_min_adv_interval),
 		  0x0020,
 		  0x4000},
 		{ "LEMaxAdvertisementInterval",
 		  &main_opts.default_params.le_max_adv_interval,
+		  sizeof(main_opts.default_params.le_max_adv_interval),
 		  0x0020,
 		  0x4000},
 		{ "LEMultiAdvertisementRotationInterval",
 		  &main_opts.default_params.le_multi_adv_rotation_interval,
+		  sizeof(main_opts.default_params.le_multi_adv_rotation_interval),
 		  0x0001,
 		  0xFFFF},
 		{ "LEScanIntervalAutoConnect",
 		  &main_opts.default_params.le_scan_interval_autoconnect,
+		  sizeof(main_opts.default_params.le_scan_interval_autoconnect),
 		  0x0004,
 		  0x4000},
 		{ "LEScanWindowAutoConnect",
 		  &main_opts.default_params.le_scan_win_autoconnect,
+		  sizeof(main_opts.default_params.le_scan_win_autoconnect),
 		  0x0004,
 		  0x4000},
 		{ "LEScanIntervalSuspend",
 		  &main_opts.default_params.le_scan_interval_suspend,
+		  sizeof(main_opts.default_params.le_scan_interval_suspend),
 		  0x0004,
 		  0x4000},
 		{ "LEScanWindowSuspend",
 		  &main_opts.default_params.le_scan_win_suspend,
+		  sizeof(main_opts.default_params.le_scan_win_suspend),
 		  0x0004,
 		  0x4000},
 		{ "LEScanIntervalDiscovery",
 		  &main_opts.default_params.le_scan_interval_discovery,
+		  sizeof(main_opts.default_params.le_scan_interval_discovery),
 		  0x0004,
 		  0x4000},
 		{ "LEScanWindowDiscovery",
 		  &main_opts.default_params.le_scan_win_discovery,
+		  sizeof(main_opts.default_params.le_scan_win_discovery),
 		  0x0004,
 		  0x4000},
 		{ "LEScanIntervalAdvMonitor",
 		  &main_opts.default_params.le_scan_interval_adv_monitor,
+		  sizeof(main_opts.default_params.le_scan_interval_adv_monitor),
 		  0x0004,
 		  0x4000},
 		{ "LEScanWindowAdvMonitor",
 		  &main_opts.default_params.le_scan_win_adv_monitor,
+		  sizeof(main_opts.default_params.le_scan_win_adv_monitor),
 		  0x0004,
 		  0x4000},
 		{ "LEScanIntervalConnect",
 		  &main_opts.default_params.le_scan_interval_connect,
+		  sizeof(main_opts.default_params.le_scan_interval_connect),
 		  0x0004,
 		  0x4000},
 		{ "LEScanWindowConnect",
 		  &main_opts.default_params.le_scan_win_connect,
+		  sizeof(main_opts.default_params.le_scan_win_connect),
 		  0x0004,
 		  0x4000},
 		{ "LEMinConnectionInterval",
 		  &main_opts.default_params.le_min_conn_interval,
+		  sizeof(main_opts.default_params.le_min_conn_interval),
 		  0x0006,
 		  0x0C80},
 		{ "LEMaxConnectionInterval",
 		  &main_opts.default_params.le_max_conn_interval,
+		  sizeof(main_opts.default_params.le_max_conn_interval),
 		  0x0006,
 		  0x0C80},
 		{ "LEConnectionLatency",
 		  &main_opts.default_params.le_conn_latency,
+		  sizeof(main_opts.default_params.le_conn_latency),
 		  0x0000,
 		  0x01F3},
 		{ "LEConnectionSupervisionTimeout",
 		  &main_opts.default_params.le_conn_lsto,
+		  sizeof(main_opts.default_params.le_conn_lsto),
 		  0x000A,
 		  0x0C80},
 		{ "LEAutoconnecttimeout",
 		  &main_opts.default_params.le_autoconnect_timeout,
+		  sizeof(main_opts.default_params.le_autoconnect_timeout),
 		  0x0001,
 		  0x4000},
 	};
@@ -439,7 +468,10 @@ static void parse_controller_config(GKeyFile *config)
 
 			val = MAX(val, params[i].min);
 			val = MIN(val, params[i].max);
-			*params[i].val = val;
+
+			val = htobl(val);
+			memcpy(params[i].val, &val, params[i].size);
+			main_opts.default_params.total_size += params[i].size;
 			++main_opts.default_params.num_entries;
 		}
 	}
-- 
2.29.0.rc1.297.gfa9743e501-goog


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [BlueZ,v2] core: Add support of variable length params in mgmt_config
  2020-10-15  4:01 [BlueZ PATCH v2] core: Add support of variable length params in mgmt_config Howard Chung
@ 2020-10-15  4:35 ` bluez.test.bot
  2020-10-15 16:10 ` [BlueZ PATCH v2] " Luiz Augusto von Dentz
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2020-10-15  4:35 UTC (permalink / raw)
  To: linux-bluetooth, howardchung


[-- Attachment #1: Type: text/plain, Size: 2691 bytes --]

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.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=364849

---Test result---

##############################
Test: CheckPatch - FAIL
Output:
core: Add support of variable length params in mgmt_config
WARNING:LONG_LINE: line over 80 characters
#131: FILE: src/adapter.c:4230:
+			sizeof(main_opts.default_params.br_link_supervision_timeout),

WARNING:LONG_LINE: line over 80 characters
#198: FILE: src/adapter.c:4266:
+			sizeof(main_opts.default_params.le_multi_adv_rotation_interval),

WARNING:LONG_LINE: line over 80 characters
#199: FILE: src/adapter.c:4267:
+			&main_opts.default_params.le_multi_adv_rotation_interval);

WARNING:LONG_LINE: line over 80 characters
#210: FILE: src/adapter.c:4272:
+			sizeof(main_opts.default_params.le_scan_interval_autoconnect),

WARNING:LONG_LINE: line over 80 characters
#222: FILE: src/adapter.c:4278:
+			sizeof(main_opts.default_params.le_scan_win_autoconnect),

WARNING:LONG_LINE: line over 80 characters
#234: FILE: src/adapter.c:4284:
+			sizeof(main_opts.default_params.le_scan_interval_suspend),

WARNING:LONG_LINE: line over 80 characters
#257: FILE: src/adapter.c:4296:
+			sizeof(main_opts.default_params.le_scan_interval_discovery),

WARNING:LONG_LINE: line over 80 characters
#281: FILE: src/adapter.c:4308:
+			sizeof(main_opts.default_params.le_scan_interval_adv_monitor),

WARNING:LONG_LINE: line over 80 characters
#293: FILE: src/adapter.c:4314:
+			sizeof(main_opts.default_params.le_scan_win_adv_monitor),

WARNING:LONG_LINE: line over 80 characters
#305: FILE: src/adapter.c:4320:
+			sizeof(main_opts.default_params.le_scan_interval_connect),

WARNING:LONG_LINE: line over 80 characters
#476: FILE: src/main.c:375:
+		  sizeof(main_opts.default_params.le_multi_adv_rotation_interval),

- total: 0 errors, 11 warnings, 540 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 SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: CheckGitLint - PASS

##############################
Test: CheckBuild - PASS

##############################
Test: MakeCheck - PASS



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BlueZ PATCH v2] core: Add support of variable length params in mgmt_config
  2020-10-15  4:01 [BlueZ PATCH v2] core: Add support of variable length params in mgmt_config Howard Chung
  2020-10-15  4:35 ` [BlueZ,v2] " bluez.test.bot
@ 2020-10-15 16:10 ` Luiz Augusto von Dentz
  1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2020-10-15 16:10 UTC (permalink / raw)
  To: Howard Chung
  Cc: linux-bluetooth, Manish Mandlik, Archie Pusaka, Alain Michaud,
	Miao-chen Chou

Hi Howard,

On Wed, Oct 14, 2020 at 9:02 PM Howard Chung <howardchung@google.com> wrote:
>
> This adds support of variable length parameters in mgmt_config.
> Also fixed the endian issue.
>
> Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
> ---
>
> Changes in v2:
> - fix multiple line dereference issue
>
>  src/adapter.c | 268 +++++++++++++++++++-------------------------------
>  src/hcid.h    |   1 +
>  src/main.c    |  36 ++++++-
>  3 files changed, 138 insertions(+), 167 deletions(-)
>
> diff --git a/src/adapter.c b/src/adapter.c
> index c0053000ac19..9c61e7bf204f 100644
> --- a/src/adapter.c
> +++ b/src/adapter.c
> @@ -4163,269 +4163,207 @@ static void probe_devices(void *user_data)
>         device_probe_profiles(device, btd_device_get_uuids(device));
>  }
>
> +static uint8_t *set_mgmt_tlv(uint8_t *cur, uint16_t type, uint8_t length,
> +                                                               void *value)
> +{
> +       struct mgmt_tlv *entry = (struct mgmt_tlv *)cur;
> +
> +       entry->type = htobs(type);
> +       entry->length = length;
> +       memcpy(entry->value, value, length);
> +       cur += sizeof(*entry) + length;
> +       return cur;
> +}
> +
>  static void load_default_system_params(struct btd_adapter *adapter)
>  {
> -       struct {
> -               struct mgmt_tlv entry;
> -               union {
> -                       uint16_t u16;
> -               };
> -       } __packed *params;
> -       uint16_t i = 0;
> -       size_t len = 0;
> +       uint8_t *buf, *cur;
>         unsigned int err;
>
>         if (!main_opts.default_params.num_entries ||
>             !btd_has_kernel_features(KERNEL_SET_SYSTEM_CONFIG))
>                 return;
>
> -       params = malloc0(sizeof(*params) *
> -                       main_opts.default_params.num_entries);
> -
> -       len = sizeof(params->entry) * main_opts.default_params.num_entries;
> +       buf = malloc0(sizeof(struct mgmt_tlv) *
> +                       main_opts.default_params.num_entries +
> +                       main_opts.default_params.total_size);

I really wonder if we wouldn't be better off supporting iovec/scatter
transfer for these parameters, we would need to introduce something
like mgmt_sendv but the code should be a lot cleaner than everything
manually like we are currently doing.

> +       cur = buf;
>
>         if (main_opts.default_params.br_page_scan_type != 0xFFFF) {
> -               params[i].entry.type = 0x0000;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.br_page_scan_type;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0000,
> +                       sizeof(main_opts.default_params.br_page_scan_type),
> +                       &main_opts.default_params.br_page_scan_type);
>         }
>
>         if (main_opts.default_params.br_page_scan_interval) {
> -               params[i].entry.type = 0x0001;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.br_page_scan_interval;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0001,
> +                       sizeof(main_opts.default_params.br_page_scan_interval),
> +                       &main_opts.default_params.br_page_scan_interval);
>         }
>
>         if (main_opts.default_params.br_page_scan_win) {
> -               params[i].entry.type = 0x0002;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.br_page_scan_win;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0002,
> +                       sizeof(main_opts.default_params.br_page_scan_win),
> +                       &main_opts.default_params.br_page_scan_win);
>         }
>
>         if (main_opts.default_params.br_scan_type != 0xFFFF) {
> -               params[i].entry.type = 0x0003;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.br_scan_type;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0003,
> +                       sizeof(main_opts.default_params.br_scan_type),
> +                       &main_opts.default_params.br_scan_type);
>         }
>
>         if (main_opts.default_params.br_scan_interval) {
> -               params[i].entry.type = 0x0004;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.br_scan_interval;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0004,
> +                       sizeof(main_opts.default_params.br_scan_interval),
> +                       &main_opts.default_params.br_scan_interval);
>         }
>
>         if (main_opts.default_params.br_scan_win) {
> -               params[i].entry.type = 0x0005;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.br_scan_win;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0005,
> +                       sizeof(main_opts.default_params.br_scan_win),
> +                       &main_opts.default_params.br_scan_win);
>         }
>
>         if (main_opts.default_params.br_link_supervision_timeout) {
> -               params[i].entry.type = 0x0006;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 =
> -                       main_opts.default_params.br_link_supervision_timeout;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0006,
> +                       sizeof(main_opts.default_params.br_link_supervision_timeout),
> +                       &main_opts.default_params.br_link_supervision_timeout);
>         }
>
>         if (main_opts.default_params.br_page_timeout) {
> -               params[i].entry.type = 0x0007;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.br_page_timeout;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0007,
> +                       sizeof(main_opts.default_params.br_page_timeout),
> +                       &main_opts.default_params.br_page_timeout);
>         }
>
>         if (main_opts.default_params.br_min_sniff_interval) {
> -               params[i].entry.type = 0x0008;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.br_min_sniff_interval;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0008,
> +                       sizeof(main_opts.default_params.br_min_sniff_interval),
> +                       &main_opts.default_params.br_min_sniff_interval);
>         }
>
>         if (main_opts.default_params.br_max_sniff_interval) {
> -               params[i].entry.type = 0x0009;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.br_max_sniff_interval;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0009,
> +                       sizeof(main_opts.default_params.br_max_sniff_interval),
> +                       &main_opts.default_params.br_max_sniff_interval);
>         }
>
>         if (main_opts.default_params.le_min_adv_interval) {
> -               params[i].entry.type = 0x000a;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.le_min_adv_interval;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x000a,
> +                       sizeof(main_opts.default_params.le_min_adv_interval),
> +                       &main_opts.default_params.le_min_adv_interval);
>         }
>
>         if (main_opts.default_params.le_max_adv_interval) {
> -               params[i].entry.type = 0x000b;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.le_max_adv_interval;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x000b,
> +                       sizeof(main_opts.default_params.le_max_adv_interval),
> +                       &main_opts.default_params.le_max_adv_interval);
>         }
>
>         if (main_opts.default_params.le_multi_adv_rotation_interval) {
> -               params[i].entry.type = 0x000c;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 =
> -                       main_opts.default_params.le_multi_adv_rotation_interval;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x000c,
> +                       sizeof(main_opts.default_params.le_multi_adv_rotation_interval),
> +                       &main_opts.default_params.le_multi_adv_rotation_interval);
>         }
>
>         if (main_opts.default_params.le_scan_interval_autoconnect) {
> -               params[i].entry.type = 0x000d;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 =
> -                       main_opts.default_params.le_scan_interval_autoconnect;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x000d,
> +                       sizeof(main_opts.default_params.le_scan_interval_autoconnect),
> +                       &main_opts.default_params.le_scan_interval_autoconnect);
>         }
>
>         if (main_opts.default_params.le_scan_win_autoconnect) {
> -               params[i].entry.type = 0x000e;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 =
> -                       main_opts.default_params.le_scan_win_autoconnect;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x000e,
> +                       sizeof(main_opts.default_params.le_scan_win_autoconnect),
> +                       &main_opts.default_params.le_scan_win_autoconnect);
>         }
>
>         if (main_opts.default_params.le_scan_interval_suspend) {
> -               params[i].entry.type = 0x000f;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 =
> -                       main_opts.default_params.le_scan_interval_suspend;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x000f,
> +                       sizeof(main_opts.default_params.le_scan_interval_suspend),
> +                       &main_opts.default_params.le_scan_interval_suspend);
>         }
>
>         if (main_opts.default_params.le_scan_win_suspend) {
> -               params[i].entry.type = 0x0010;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.le_scan_win_suspend;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0010,
> +                       sizeof(main_opts.default_params.le_scan_win_suspend),
> +                       &main_opts.default_params.le_scan_win_suspend);
>         }
>
>         if (main_opts.default_params.le_scan_interval_discovery) {
> -               params[i].entry.type = 0x0011;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 =
> -                       main_opts.default_params.le_scan_interval_discovery;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0011,
> +                       sizeof(main_opts.default_params.le_scan_interval_discovery),
> +                       &main_opts.default_params.le_scan_interval_discovery);
>         }
>
>         if (main_opts.default_params.le_scan_win_discovery) {
> -               params[i].entry.type = 0x0012;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 =
> -                       main_opts.default_params.le_scan_win_discovery;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0012,
> +                       sizeof(main_opts.default_params.le_scan_win_discovery),
> +                       &main_opts.default_params.le_scan_win_discovery);
>         }
>
>         if (main_opts.default_params.le_scan_interval_adv_monitor) {
> -               params[i].entry.type = 0x0013;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 =
> -                       main_opts.default_params.le_scan_interval_adv_monitor;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0013,
> +                       sizeof(main_opts.default_params.le_scan_interval_adv_monitor),
> +                       &main_opts.default_params.le_scan_interval_adv_monitor);
>         }
>
>         if (main_opts.default_params.le_scan_win_adv_monitor) {
> -               params[i].entry.type = 0x0014;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 =
> -                       main_opts.default_params.le_scan_win_adv_monitor;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0014,
> +                       sizeof(main_opts.default_params.le_scan_win_adv_monitor),
> +                       &main_opts.default_params.le_scan_win_adv_monitor);
>         }
>
>         if (main_opts.default_params.le_scan_interval_connect) {
> -               params[i].entry.type = 0x0015;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 =
> -                       main_opts.default_params.le_scan_interval_connect;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0015,
> +                       sizeof(main_opts.default_params.le_scan_interval_connect),
> +                       &main_opts.default_params.le_scan_interval_connect);
>         }
>
>         if (main_opts.default_params.le_scan_win_connect) {
> -               params[i].entry.type = 0x0016;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.le_scan_win_connect;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0016,
> +                       sizeof(main_opts.default_params.le_scan_win_connect),
> +                       &main_opts.default_params.le_scan_win_connect);
>         }
>
>         if (main_opts.default_params.le_min_conn_interval) {
> -               params[i].entry.type = 0x0017;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.le_min_conn_interval;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0017,
> +                       sizeof(main_opts.default_params.le_min_conn_interval),
> +                       &main_opts.default_params.le_min_conn_interval);
>         }
>
>         if (main_opts.default_params.le_max_conn_interval) {
> -               params[i].entry.type = 0x0018;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.le_max_conn_interval;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0018,
> +                       sizeof(main_opts.default_params.le_max_conn_interval),
> +                       &main_opts.default_params.le_max_conn_interval);
>         }
>
>         if (main_opts.default_params.le_conn_latency) {
> -               params[i].entry.type = 0x0019;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.le_conn_latency;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x0019,
> +                       sizeof(main_opts.default_params.le_conn_latency),
> +                       &main_opts.default_params.le_conn_latency);
>         }
>
>         if (main_opts.default_params.le_conn_lsto) {
> -               params[i].entry.type = 0x001a;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.le_conn_lsto;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x001a,
> +                       sizeof(main_opts.default_params.le_conn_lsto),
> +                       &main_opts.default_params.le_conn_lsto);
>         }
>
>         if (main_opts.default_params.le_autoconnect_timeout) {
> -               params[i].entry.type = 0x001b;
> -               params[i].entry.length = sizeof(params[i].u16);
> -               params[i].u16 = main_opts.default_params.le_autoconnect_timeout;
> -               ++i;
> -               len += sizeof(params[i].u16);
> +               cur = set_mgmt_tlv(cur, 0x001b,
> +                       sizeof(main_opts.default_params.le_autoconnect_timeout),
> +                       &main_opts.default_params.le_autoconnect_timeout);
>         }
>
>         err = mgmt_send(adapter->mgmt, MGMT_OP_SET_DEF_SYSTEM_CONFIG,
> -                       adapter->dev_id, len, params, NULL, NULL, NULL);
> +                       adapter->dev_id, cur-buf, buf, NULL, NULL, NULL);
>         if (!err)
>                 btd_error(adapter->dev_id,
>                                 "Failed to set default system config for hci%u",
>                                 adapter->dev_id);
> -
> -       free(params);
> +       free(buf);
>  }
>
>  static void load_devices(struct btd_adapter *adapter)
> diff --git a/src/hcid.h b/src/hcid.h
> index 95d4b9665193..adeb1f92333c 100644
> --- a/src/hcid.h
> +++ b/src/hcid.h
> @@ -45,6 +45,7 @@ struct main_opts {
>
>         struct {
>                 uint16_t        num_entries;
> +               uint16_t        total_size;
>
>                 uint16_t        br_page_scan_type;
>                 uint16_t        br_page_scan_interval;
> diff --git a/src/main.c b/src/main.c
> index 77be776686a8..243470b6eb88 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -305,120 +305,149 @@ static void parse_controller_config(GKeyFile *config)
>  {
>         static const struct {
>                 const char * const val_name;
> -               uint16_t * const val;
> +               void * const val;
> +               const size_t size;
>                 const uint16_t min;
>                 const uint16_t max;
>         } params[] = {
>                 { "BRPageScanType",
>                   &main_opts.default_params.br_page_scan_type,
> +                 sizeof(main_opts.default_params.br_page_scan_type),
>                   0,
>                   1},
>                 { "BRPageScanInterval",
>                   &main_opts.default_params.br_page_scan_interval,
> +                 sizeof(main_opts.default_params.br_page_scan_interval),
>                   0x0012,
>                   0x1000},
>                 { "BRPageScanWindow",
>                   &main_opts.default_params.br_page_scan_win,
> +                 sizeof(main_opts.default_params.br_page_scan_win),
>                   0x0011,
>                   0x1000},
>                 { "BRInquiryScanType",
>                   &main_opts.default_params.br_scan_type,
> +                 sizeof(main_opts.default_params.br_scan_type),
>                   0,
>                   1},
>                 { "BRInquiryScanInterval",
>                   &main_opts.default_params.br_scan_interval,
> +                 sizeof(main_opts.default_params.br_scan_interval),
>                   0x0012,
>                   0x1000},
>                 { "BRInquiryScanWindow",
>                   &main_opts.default_params.br_scan_win,
> +                 sizeof(main_opts.default_params.br_scan_win),
>                   0x0011,
>                   0x1000},
>                 { "BRLinkSupervisionTimeout",
>                   &main_opts.default_params.br_link_supervision_timeout,
> +                 sizeof(main_opts.default_params.br_link_supervision_timeout),
>                   0x0001,
>                   0xFFFF},
>                 { "BRPageTimeout",
>                   &main_opts.default_params.br_page_timeout,
> +                 sizeof(main_opts.default_params.br_page_scan_win),
>                   0x0001,
>                   0xFFFF},
>                 { "BRMinSniffInterval",
>                   &main_opts.default_params.br_min_sniff_interval,
> +                 sizeof(main_opts.default_params.br_min_sniff_interval),
>                   0x0001,
>                   0xFFFE},
>                 { "BRMaxSniffInterval",
>                   &main_opts.default_params.br_max_sniff_interval,
> +                 sizeof(main_opts.default_params.br_max_sniff_interval),
>                   0x0001,
>                   0xFFFE},
>                 { "LEMinAdvertisementInterval",
>                   &main_opts.default_params.le_min_adv_interval,
> +                 sizeof(main_opts.default_params.le_min_adv_interval),
>                   0x0020,
>                   0x4000},
>                 { "LEMaxAdvertisementInterval",
>                   &main_opts.default_params.le_max_adv_interval,
> +                 sizeof(main_opts.default_params.le_max_adv_interval),
>                   0x0020,
>                   0x4000},
>                 { "LEMultiAdvertisementRotationInterval",
>                   &main_opts.default_params.le_multi_adv_rotation_interval,
> +                 sizeof(main_opts.default_params.le_multi_adv_rotation_interval),
>                   0x0001,
>                   0xFFFF},
>                 { "LEScanIntervalAutoConnect",
>                   &main_opts.default_params.le_scan_interval_autoconnect,
> +                 sizeof(main_opts.default_params.le_scan_interval_autoconnect),
>                   0x0004,
>                   0x4000},
>                 { "LEScanWindowAutoConnect",
>                   &main_opts.default_params.le_scan_win_autoconnect,
> +                 sizeof(main_opts.default_params.le_scan_win_autoconnect),
>                   0x0004,
>                   0x4000},
>                 { "LEScanIntervalSuspend",
>                   &main_opts.default_params.le_scan_interval_suspend,
> +                 sizeof(main_opts.default_params.le_scan_interval_suspend),
>                   0x0004,
>                   0x4000},
>                 { "LEScanWindowSuspend",
>                   &main_opts.default_params.le_scan_win_suspend,
> +                 sizeof(main_opts.default_params.le_scan_win_suspend),
>                   0x0004,
>                   0x4000},
>                 { "LEScanIntervalDiscovery",
>                   &main_opts.default_params.le_scan_interval_discovery,
> +                 sizeof(main_opts.default_params.le_scan_interval_discovery),
>                   0x0004,
>                   0x4000},
>                 { "LEScanWindowDiscovery",
>                   &main_opts.default_params.le_scan_win_discovery,
> +                 sizeof(main_opts.default_params.le_scan_win_discovery),
>                   0x0004,
>                   0x4000},
>                 { "LEScanIntervalAdvMonitor",
>                   &main_opts.default_params.le_scan_interval_adv_monitor,
> +                 sizeof(main_opts.default_params.le_scan_interval_adv_monitor),
>                   0x0004,
>                   0x4000},
>                 { "LEScanWindowAdvMonitor",
>                   &main_opts.default_params.le_scan_win_adv_monitor,
> +                 sizeof(main_opts.default_params.le_scan_win_adv_monitor),
>                   0x0004,
>                   0x4000},
>                 { "LEScanIntervalConnect",
>                   &main_opts.default_params.le_scan_interval_connect,
> +                 sizeof(main_opts.default_params.le_scan_interval_connect),
>                   0x0004,
>                   0x4000},
>                 { "LEScanWindowConnect",
>                   &main_opts.default_params.le_scan_win_connect,
> +                 sizeof(main_opts.default_params.le_scan_win_connect),
>                   0x0004,
>                   0x4000},
>                 { "LEMinConnectionInterval",
>                   &main_opts.default_params.le_min_conn_interval,
> +                 sizeof(main_opts.default_params.le_min_conn_interval),
>                   0x0006,
>                   0x0C80},
>                 { "LEMaxConnectionInterval",
>                   &main_opts.default_params.le_max_conn_interval,
> +                 sizeof(main_opts.default_params.le_max_conn_interval),
>                   0x0006,
>                   0x0C80},
>                 { "LEConnectionLatency",
>                   &main_opts.default_params.le_conn_latency,
> +                 sizeof(main_opts.default_params.le_conn_latency),
>                   0x0000,
>                   0x01F3},
>                 { "LEConnectionSupervisionTimeout",
>                   &main_opts.default_params.le_conn_lsto,
> +                 sizeof(main_opts.default_params.le_conn_lsto),
>                   0x000A,
>                   0x0C80},
>                 { "LEAutoconnecttimeout",
>                   &main_opts.default_params.le_autoconnect_timeout,
> +                 sizeof(main_opts.default_params.le_autoconnect_timeout),
>                   0x0001,
>                   0x4000},
>         };
> @@ -439,7 +468,10 @@ static void parse_controller_config(GKeyFile *config)
>
>                         val = MAX(val, params[i].min);
>                         val = MIN(val, params[i].max);
> -                       *params[i].val = val;
> +
> +                       val = htobl(val);
> +                       memcpy(params[i].val, &val, params[i].size);
> +                       main_opts.default_params.total_size += params[i].size;
>                         ++main_opts.default_params.num_entries;
>                 }
>         }
> --
> 2.29.0.rc1.297.gfa9743e501-goog
>


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-15  4:01 [BlueZ PATCH v2] core: Add support of variable length params in mgmt_config Howard Chung
2020-10-15  4:35 ` [BlueZ,v2] " bluez.test.bot
2020-10-15 16:10 ` [BlueZ PATCH v2] " Luiz Augusto von Dentz

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org
	public-inbox-index linux-bluetooth

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git