Message ID | 20201028215824.608794-1-luiz.dentz@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [BlueZ,1/5] mgmt: Add support of mgmt TLV API | expand |
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=372299 ---Test result--- ############################## Test: CheckPatch - FAIL Output: core: Split LE and BR/EDR parameters WARNING:STATIC_CONST_CHAR_ARRAY: static const char * array should probably be static const char * const #602: FILE: src/main.c:84: +static const char *br_options[] = { WARNING:STATIC_CONST_CHAR_ARRAY: static const char * array should probably be static const char * const #616: FILE: src/main.c:98: +static const char *le_options[] = { - total: 0 errors, 2 warnings, 1036 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
Hi, On Wed, Oct 28, 2020 at 2:58 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote: > > From: Howard Chung <howardchung@google.com> > > This adds API to send multiple TLVs to kernel, it is useful for > mgmt set system config command. > --- > src/shared/mgmt.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++ > src/shared/mgmt.h | 9 +++++ > 2 files changed, 103 insertions(+) > > diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c > index b327b4088..9ea9974f5 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 6608faa7e..74b8befd8 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, > -- > 2.26.2 > Pushed.
diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c index b327b4088..9ea9974f5 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 6608faa7e..74b8befd8 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,
From: Howard Chung <howardchung@google.com> This adds API to send multiple TLVs to kernel, it is useful for mgmt set system config command. --- src/shared/mgmt.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++ src/shared/mgmt.h | 9 +++++ 2 files changed, 103 insertions(+)