shared/mgmt: Add supports of parsing mgmt tlv list
authorHoward Chung <howardchung@google.com>
Tue, 5 Jan 2021 03:12:54 +0000 (11:12 +0800)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:34 +0000 (19:08 +0530)
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.

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

index 9ea9974..dc81078 100755 (executable)
@@ -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 = (struct mgmt_tlv *)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,
index 319beb6..808bf4c 100755 (executable)
@@ -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,