diff mbox series

[BlueZ,v5,1/2] mgmt: Add support of mgmt TLV API

Message ID 20201028195132.BlueZ.v5.1.I2fa28644a012f69c4665977e5816bcf8a51963f5@changeid (mailing list archive)
State New, archived
Headers show
Series [BlueZ,v5,1/2] mgmt: Add support of mgmt TLV API | expand

Commit Message

Howard Chung Oct. 28, 2020, 11:52 a.m. UTC
This adds API to send multiple TLVs to kernel, it is useful for
mgmt set system config command.
---

Changes in v5:
- Implement mgmt_tlv API in src/shared/mgmt.c

Changes in v4:
- fix type of buf_len

Changes in v3:
- use iovec to fill buffer

Changes in v2:
- fix multiple line dereference issue

 src/shared/mgmt.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++
 src/shared/mgmt.h |  9 +++++
 2 files changed, 103 insertions(+)

Comments

bluez.test.bot@gmail.com Oct. 28, 2020, 11:53 p.m. UTC | #1
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=372511

---Test result---

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

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

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

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

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

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

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

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

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

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

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

- total: 0 errors, 11 warnings, 524 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
diff mbox series

Patch

diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index b327b4088c6f..9ea9974f5535 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c
@@ -68,6 +68,11 @@  struct mgmt_notify {
 	void *user_data;
 };
 
+struct mgmt_tlv_list {
+	struct queue *tlv_queue;
+	uint16_t size;
+};
+
 static void destroy_request(void *data)
 {
 	struct mgmt_request *request = data;
@@ -558,6 +563,95 @@  static struct mgmt_request *create_request(uint16_t opcode, uint16_t index,
 	return request;
 }
 
+struct mgmt_tlv_list *mgmt_tlv_list_new(void)
+{
+	struct mgmt_tlv_list *tlv_list = new0(struct mgmt_tlv_list, 1);
+
+	tlv_list->tlv_queue = queue_new();
+	tlv_list->size = 0;
+
+	return tlv_list;
+}
+
+static struct mgmt_tlv *mgmt_tlv_new(uint16_t type, uint8_t length,
+								void *value)
+{
+	struct mgmt_tlv *entry = malloc(sizeof(*entry) + length);
+
+	if (!entry)
+		return NULL;
+
+	entry->type = htobs(type);
+	entry->length = length;
+	memcpy(entry->value, value, length);
+
+	return entry;
+}
+
+static void mgmt_tlv_free(struct mgmt_tlv *entry)
+{
+	free(entry);
+}
+
+void mgmt_tlv_list_free(struct mgmt_tlv_list *tlv_list)
+{
+	queue_destroy(tlv_list->tlv_queue, NULL);
+	free(tlv_list);
+}
+
+bool mgmt_tlv_add(struct mgmt_tlv_list *tlv_list, uint16_t type, uint8_t length,
+								void *value)
+{
+	struct mgmt_tlv *entry = mgmt_tlv_new(type, length, value);
+
+	if (!entry)
+		return false;
+
+	if (!queue_push_tail(tlv_list->tlv_queue, entry)) {
+		mgmt_tlv_free(entry);
+		return false;
+	}
+
+	tlv_list->size += sizeof(*entry) + entry->length;
+	return true;
+}
+
+static void mgmt_tlv_to_buf(void *data, void *user_data)
+{
+	struct mgmt_tlv *entry = data;
+	uint8_t **buf_ptr = user_data;
+	size_t entry_size = sizeof(*entry) + entry->length;
+
+	memcpy(*buf_ptr, entry, entry_size);
+	*buf_ptr += entry_size;
+}
+
+unsigned int mgmt_send_tlv(struct mgmt *mgmt, uint16_t opcode, uint16_t index,
+				struct mgmt_tlv_list *tlv_list,
+				mgmt_request_func_t callback,
+				void *user_data, mgmt_destroy_func_t destroy)
+{
+	uint8_t *buf, *buf_ptr;
+	unsigned int ret;
+
+	if (!tlv_list)
+		return 0;
+
+	buf = malloc(tlv_list->size);
+
+	if (!buf)
+		return 0;
+
+	buf_ptr = buf;
+
+	queue_foreach(tlv_list->tlv_queue, mgmt_tlv_to_buf, &buf_ptr);
+
+	ret = mgmt_send(mgmt, opcode, index, tlv_list->size, (void *)buf,
+						callback, user_data, destroy);
+	free(buf);
+	return ret;
+}
+
 unsigned int mgmt_send(struct mgmt *mgmt, uint16_t opcode, uint16_t index,
 				uint16_t length, const void *param,
 				mgmt_request_func_t callback,
diff --git a/src/shared/mgmt.h b/src/shared/mgmt.h
index 6608faa7ed0f..74b8befd87bd 100644
--- a/src/shared/mgmt.h
+++ b/src/shared/mgmt.h
@@ -16,6 +16,7 @@ 
 typedef void (*mgmt_destroy_func_t)(void *user_data);
 
 struct mgmt;
+struct mgmt_tlv_list;
 
 struct mgmt *mgmt_new(int fd);
 struct mgmt *mgmt_new_default(void);
@@ -33,6 +34,14 @@  bool mgmt_set_close_on_unref(struct mgmt *mgmt, bool do_close);
 typedef void (*mgmt_request_func_t)(uint8_t status, uint16_t length,
 					const void *param, void *user_data);
 
+struct mgmt_tlv_list *mgmt_tlv_list_new(void);
+void mgmt_tlv_list_free(struct mgmt_tlv_list *tlv_list);
+bool mgmt_tlv_add(struct mgmt_tlv_list *tlv_list, uint16_t type, uint8_t length,
+								void *value);
+unsigned int mgmt_send_tlv(struct mgmt *mgmt, uint16_t opcode, uint16_t index,
+				struct mgmt_tlv_list *tlv_list,
+				mgmt_request_func_t callback,
+				void *user_data, mgmt_destroy_func_t destroy);
 unsigned int mgmt_send(struct mgmt *mgmt, uint16_t opcode, uint16_t index,
 				uint16_t length, const void *param,
 				mgmt_request_func_t callback,