diff mbox series

[Bluez,v1,1/4] shared/mgmt: Add supports of parsing mgmt tlv list

Message ID 20201228144543.Bluez.v1.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid
State New
Headers show
Series [Bluez,v1,1/4] shared/mgmt: Add supports of parsing mgmt tlv list | expand

Commit Message

Howard Chung Dec. 28, 2020, 6:46 a.m. UTC
Response from Read System Default Configuration is a list of mgmt_tlv,
which requires further processing to get the values of each parameters.

This adds APIs for parsing response into mgmt_tlv_list, retrieving
parameter from mgmt_tlv_list.

Reviewed-by: apusaka@chromium.org
---

 src/shared/mgmt.c | 38 ++++++++++++++++++++++++++++++++++++++
 src/shared/mgmt.h |  6 ++++++
 2 files changed, 44 insertions(+)

Comments

bluez.test.bot@gmail.com Dec. 28, 2020, 7:08 a.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=406659

---Test result---

##############################
Test: CheckPatch - FAIL
Output:
btmgmt: Add command set-sysconfig
WARNING:NAKED_SSCANF: unchecked sscanf return value
#42: FILE: tools/btmgmt.c:1818:
+		if (!sscanf(input + i * 2, "%2hhx", &value[i]))
+			return false;

- total: 0 errors, 1 warnings, 121 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.

"[PATCH] btmgmt: Add command set-sysconfig" 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 - FAIL
Output:
btmgmt: Add command set-sysconfig
8: B3 Line contains hard tab characters (\t): "	-v <type:length:value>..."
10: B3 Line contains hard tab characters (\t): "	set-sysconfig -v 001a:2:1234 001f:1:00"


##############################
Test: CheckBuild - FAIL
Output:
src/shared/mgmt.c: In function ‘mgmt_tlv_list_free’:
src/shared/mgmt.c:598:37: error: passing argument 2 of ‘queue_destroy’ from incompatible pointer type [-Werror=incompatible-pointer-types]
  598 |  queue_destroy(tlv_list->tlv_queue, mgmt_tlv_free);
      |                                     ^~~~~~~~~~~~~
      |                                     |
      |                                     void (*)(struct mgmt_tlv *)
In file included from src/shared/mgmt.c:25:
./src/shared/queue.h:23:62: note: expected ‘queue_destroy_func_t’ {aka ‘void (*)(void *)’} but argument is of type ‘void (*)(struct mgmt_tlv *)’
   23 | void queue_destroy(struct queue *queue, queue_destroy_func_t destroy);
      |                                         ~~~~~~~~~~~~~~~~~~~~~^~~~~~~
src/shared/mgmt.c: In function ‘mgmt_tlv_list_load_from_buf’:
src/shared/mgmt.c:641:28: error: initialization of ‘struct mgmt_tlv *’ from incompatible pointer type ‘const uint8_t *’ {aka ‘const unsigned char *’} [-Werror=incompatible-pointer-types]
  641 |   struct mgmt_tlv *entry = cur;
      |                            ^~~
cc1: all warnings being treated as errors
make[1]: *** [Makefile:6808: src/shared/mgmt.lo] Error 1
make: *** [Makefile:4023: all] Error 2


##############################
Test: MakeCheck - SKIPPED
Output:
checkbuild not success



---
Regards,
Linux Bluetooth
diff mbox series

Patch

diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index 9ea9974f5535..bdc4bdd9e66b 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c
@@ -626,6 +626,44 @@  static void mgmt_tlv_to_buf(void *data, void *user_data)
 	*buf_ptr += entry_size;
 }
 
+struct mgmt_tlv_list *mgmt_tlv_list_load_from_buf(const uint8_t *buf,
+								uint16_t len)
+{
+	struct mgmt_tlv_list *tlv_list;
+	const uint8_t *cur = buf;
+
+	if (!len || !buf)
+		return NULL;
+
+	tlv_list = mgmt_tlv_list_new();
+
+	while (cur < buf + len) {
+		struct mgmt_tlv *entry = cur;
+
+		cur += sizeof(*entry) + entry->length;
+		if (cur > buf + len)
+			goto failed;
+
+		if (!mgmt_tlv_add(tlv_list, entry->type, entry->length,
+								entry->value)) {
+			goto failed;
+		}
+	}
+
+	return tlv_list;
+failed:
+	mgmt_tlv_list_free(tlv_list);
+
+	return NULL;
+}
+
+void mgmt_tlv_list_foreach(struct mgmt_tlv_list *tlv_list,
+				mgmt_tlv_list_foreach_func_t callback,
+				void *user_data)
+{
+	queue_foreach(tlv_list->tlv_queue, callback, user_data);
+}
+
 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,
diff --git a/src/shared/mgmt.h b/src/shared/mgmt.h
index 319beb62f9eb..808bf4c7ff09 100644
--- a/src/shared/mgmt.h
+++ b/src/shared/mgmt.h
@@ -41,6 +41,12 @@  bool mgmt_tlv_add(struct mgmt_tlv_list *tlv_list, uint16_t type, uint8_t length,
 #define mgmt_tlv_add_fixed(_list, _type, _value) \
 	mgmt_tlv_add(_list, _type, sizeof(*(_value)), _value)
 
+struct mgmt_tlv_list *mgmt_tlv_list_load_from_buf(const uint8_t *buf,
+								uint16_t len);
+typedef void (*mgmt_tlv_list_foreach_func_t)(void *data, void *user_data);
+void mgmt_tlv_list_foreach(struct mgmt_tlv_list *tlv_list,
+				mgmt_tlv_list_foreach_func_t callback,
+				void *user_data);
 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,