2022-05-25 01:52:17

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 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(-)

diff --git a/monitor/att.c b/monitor/att.c
index d4fd18fd2..27d4730fc 100644
--- a/monitor/att.c
+++ b/monitor/att.c
@@ -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)
--
2.35.1



2022-05-25 09:08:32

by bluez.test.bot

[permalink] [raw]
Subject: RE: [BlueZ,1/2] monitor/att: Attempt to reload if database is empty

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