monitor/att: Attempt to reload if database is empty
Luiz Augusto von Dentz
maintainerPATCH 1/2 monitor/att: Attempt to reload if database is empty
From: Luiz Augusto von Dentz <[email protected]>
If database is empty attempt to reload since the daemon may have updated its cache in the meantime.
--- monitor/att.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-)
monitor/att.c +26 -21
@@ -1232,32 +1232,39 @@ static void att_conn_data_free(void *data)static void load_gatt_db (struct packet_conn_data *conn) { -struct att_conn_data *data; +struct att_conn_data *data = conn->data;char filename[PATH_MAX ];bdaddr_t src;char local[18 ];char peer[18 ]; +if (!data) { + data = new0(struct att_conn_data, 1); + data->rdb =gatt_db_new (); + data->ldb =gatt_db_new (); + conn->data = data; + conn->destroy = att_conn_data_free; + } + +if (!gatt_db_isempty (data->ldb) && !gatt_db_isempty (data->rdb)) +return ; +if (hci_devba (conn->index, &src) <0 )return ; - data = new0(struct att_conn_data, 1); - data->rdb =gatt_db_new (); - data->ldb =gatt_db_new (); - conn->data = data; - conn->destroy = att_conn_data_free; -ba2str (&src, local); - -create_filename (filename,PATH_MAX ,"/%s/attributes" , local); - -btd_settings_gatt_db_load (data->ldb, filename); -ba2str ((bdaddr_t *)conn->dst, peer); -create_filename (filename,PATH_MAX ,"/%s/cache/%s" , local, peer); +if (gatt_db_isempty (data->ldb)) { +create_filename (filename,PATH_MAX ,"/%s/attributes" , local); +btd_settings_gatt_db_load (data->ldb, filename); + } -btd_settings_gatt_db_load (data->rdb, filename); +if (gatt_db_isempty (data->rdb)) { +create_filename (filename,PATH_MAX ,"/%s/cache/%s" , local, + peer); +btd_settings_gatt_db_load (data->rdb, filename); + } } static struct gatt_db_attribute *get_attribute(const struct l2cap_frame *frame,
@@ -1271,14 +1278,12 @@ static struct gatt_db_attribute *get_attribute(const struct l2cap_frame *frame,if (!conn)return NULL ; - data = conn->data;/* Try loading local and remote gatt_db if not loaded yet */ -if (!data) { -load_gatt_db (conn); - data = conn->data; -if (!data) -return NULL ; - } +load_gatt_db (conn); + + data = conn->data; +if (!data) +return NULL ;if (frame->in) {if (rsp)
Signature · 1 line
2.35.1
Luiz Augusto von Dentz
maintainerPATCH 2/2 monitor/att: Fix parsing of notifications
From: Luiz Augusto von Dentz <[email protected]>
If there are multiple notifications in the same frame the callback may alter it when using l2cap_frame_pull helpers, so instead this passes a cloned frame with just the expected length so callbacks cannot alter original frame.
--- monitor/att.c | 10 ++++++++++ monitor/l2cap.h | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-)
monitor/att.c +10 -0
@@ -1547,6 +1547,7 @@ static void print_notify(const struct l2cap_frame *frame, uint16_t handle, {struct gatt_db_attribute *attr;struct gatt_handler *handler; +struct l2cap_frame clone;print_handle (frame, handle, false);print_hex_field (" Data" , frame->data, len);
@@ -1564,6 +1565,15 @@ static void print_notify(const struct l2cap_frame *frame, uint16_t handle,if (!handler)return ; +/* Use a clone if the callback is not expected to parse the whole +* frame. +*/ +if (len != frame->size) { +l2cap_frame_clone (&clone, frame); + clone.size = len; + frame = &clone; + } + handler->notify (frame); }
monitor/l2cap.h +12 -4
@@ -31,11 +31,9 @@ void l2cap_frame_init(struct l2cap_frame *frame, uint16_t index, bool in, uint16_t cid, uint16_t psm, const void *data, uint16_t size); -static inline void *l2cap_frame_pull (struct l2cap_frame *frame, -const struct l2cap_frame *source,uint16_t len) +static inline void l2cap_frame_clone (struct l2cap_frame *frame, +const struct l2cap_frame *source) { -void *data; -if (frame != source) { frame->index = source->index; frame->in = source->in;
@@ -45,7 +43,17 @@ static inline void *l2cap_frame_pull(struct l2cap_frame *frame, frame->psm = source->psm; frame->chan = source->chan; frame->mode = source->mode; + frame->data = source->data; + frame->size = source->size; } +} + +static inline void *l2cap_frame_pull (struct l2cap_frame *frame, +const struct l2cap_frame *source,uint16_t len) +{ +void *data; + +l2cap_frame_clone (frame, source);if (source->size < len)return NULL ;
Signature · 1 line
2.35.1
This is an automated email and please do not reply to this email.
Dear Submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.
----- Output -----
error: patch failed: monitor/l2cap.h:31
error: monitor/l2cap.h: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch
Please resolve the issue and submit the patches again.
---
Regards,
Linux Bluetooth