2022-03-24 19:46:18

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [RFC BlueZ] adapter: Introduce BTD_ADAPTER_DBG

From: Luiz Augusto von Dentz <[email protected]>

This introduces BTD_ADAPTER_DBG which includes the controller index
when using DBG_IDX, in addition to it also add similar macro for
devices in the form of BTD_DEVICE_DBG which resolves the adapter and
before calling BTD_ADAPTER_DBG.
---
src/adapter.h | 4 ++++
src/device.h | 4 ++++
2 files changed, 8 insertions(+)

diff --git a/src/adapter.h b/src/adapter.h
index 35deb1d11..515be3210 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -23,6 +23,10 @@
/* Invalid SSP passkey value used to indicate negative replies */
#define INVALID_PASSKEY 0xffffffff

+#define BTD_ADAPTER_DBG(adapter, fmt, arg...) \
+ DBG_IDX(btd_adapter_get_index(adapter), "%s:%s() " fmt, __FILE__, \
+ __func__ , ## arg)
+
struct btd_adapter;
struct btd_device;
struct queue;
diff --git a/src/device.h b/src/device.h
index 071576d6b..4d40d1d22 100644
--- a/src/device.h
+++ b/src/device.h
@@ -11,6 +11,10 @@

#define DEVICE_INTERFACE "org.bluez.Device1"

+#define BTD_DEVICE_DBG(device, fmt, arg...) \
+ BTD_ADAPTER_DBG(device_get_adapter(device), "%s:%s() " fmt, __FILE__, \
+ __func__ , ## arg)
+
struct btd_device;

struct btd_device *device_create(struct btd_adapter *adapter,
--
2.35.1


2022-03-25 07:16:05

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ v4 2/9] mgmt: Add DBG macro

From: Luiz Augusto von Dentz <[email protected]>

This adds mgmt_log wrapper for util_debug and DBG so file and function
names are printed with the logs.
---
src/shared/mgmt.c | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index 95229c248..c7e6a6c1d 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c
@@ -27,6 +27,9 @@
#include "src/shared/mgmt.h"
#include "src/shared/timeout.h"

+#define DBG(_mgmt, _format, arg...) \
+ mgmt_log(_mgmt, "%s:%s() " _format, __FILE__, __func__, ## arg)
+
struct mgmt {
int ref_count;
int fd;
@@ -177,6 +180,18 @@ static bool request_timeout(void *data)
return false;
}

+static void mgmt_log(struct mgmt *mgmt, const char *format, ...)
+{
+ va_list ap;
+
+ if (!mgmt || !format || !mgmt->debug_callback)
+ return;
+
+ va_start(ap, format);
+ util_debug_va(mgmt->debug_callback, mgmt->debug_data, format, ap);
+ va_end(ap);
+}
+
static bool send_request(struct mgmt *mgmt, struct mgmt_request *request)
{
struct iovec iov;
@@ -187,8 +202,8 @@ static bool send_request(struct mgmt *mgmt, struct mgmt_request *request)

ret = io_send(mgmt->io, &iov, 1);
if (ret < 0) {
- util_debug(mgmt->debug_callback, mgmt->debug_data,
- "write failed: %s", strerror(-ret));
+ DBG(mgmt, "write failed: %s", strerror(-ret));
+
if (request->callback)
request->callback(MGMT_STATUS_FAILED, 0, NULL,
request->user_data);
@@ -202,9 +217,7 @@ static bool send_request(struct mgmt *mgmt, struct mgmt_request *request)
request,
NULL);

- util_debug(mgmt->debug_callback, mgmt->debug_data,
- "[0x%04x] command 0x%04x",
- request->index, request->opcode);
+ DBG(mgmt, "[0x%04x] command 0x%04x", request->index, request->opcode);

util_hexdump('<', request->buf, ret, mgmt->debug_callback,
mgmt->debug_data);
@@ -283,9 +296,7 @@ static void request_complete(struct mgmt *mgmt, uint8_t status,
request = queue_remove_if(mgmt->pending_list,
match_request_opcode_index, &match);
if (!request) {
- util_debug(mgmt->debug_callback, mgmt->debug_data,
- "Unable to find request for opcode 0x%04x",
- opcode);
+ DBG(mgmt, "Unable to find request for opcode 0x%04x", opcode);

/* Attempt to remove with no opcode */
request = queue_remove_if(mgmt->pending_list,
@@ -383,8 +394,7 @@ static bool can_read_data(struct io *io, void *user_data)
cc = mgmt->buf + MGMT_HDR_SIZE;
opcode = btohs(cc->opcode);

- util_debug(mgmt->debug_callback, mgmt->debug_data,
- "[0x%04x] command 0x%04x complete: 0x%02x",
+ DBG(mgmt, "[0x%04x] command 0x%04x complete: 0x%02x",
index, opcode, cc->status);

request_complete(mgmt, cc->status, opcode, index, length - 3,
@@ -394,15 +404,13 @@ static bool can_read_data(struct io *io, void *user_data)
cs = mgmt->buf + MGMT_HDR_SIZE;
opcode = btohs(cs->opcode);

- util_debug(mgmt->debug_callback, mgmt->debug_data,
- "[0x%04x] command 0x%02x status: 0x%02x",
+ DBG(mgmt, "[0x%04x] command 0x%02x status: 0x%02x",
index, opcode, cs->status);

request_complete(mgmt, cs->status, opcode, index, 0, NULL);
break;
default:
- util_debug(mgmt->debug_callback, mgmt->debug_data,
- "[0x%04x] event 0x%04x", index, event);
+ DBG(mgmt, "[0x%04x] event 0x%04x", index, event);

process_notify(mgmt, event, index, length,
mgmt->buf + MGMT_HDR_SIZE);
--
2.35.1

2022-03-25 18:19:47

by patchwork-bot+bluetooth

[permalink] [raw]
Subject: Re: [RFC BlueZ] adapter: Introduce BTD_ADAPTER_DBG

Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <[email protected]>:

On Wed, 23 Mar 2022 15:39:54 -0700 you wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> This introduces BTD_ADAPTER_DBG which includes the controller index
> when using DBG_IDX, in addition to it also add similar macro for
> devices in the form of BTD_DEVICE_DBG which resolves the adapter and
> before calling BTD_ADAPTER_DBG.
>
> [...]

Here is the summary with links:
- [RFC,BlueZ] adapter: Introduce BTD_ADAPTER_DBG
(no matching commit)
- [BlueZ,v4,2/9] mgmt: Add DBG macro
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f9cb7c802f27
- [BlueZ,v4,3/9] mgmt: Introduce mgmt_set_verbose
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=b7c807269f1f
- [BlueZ,v4,4/9] adapter: Don't use DBG in mgmt_debug
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=62c6037ea02b
- [BlueZ,v4,5/9] att: Log file and function names
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=8039d42687fd
- [BlueZ,v4,6/9] gatt-client: Add DBG macro
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=e0870ce5e1fe
- [BlueZ,v4,7/9] gatt-server: Add DBG macro
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=55c25d91e4d6
- [BlueZ,v4,8/9] att: Rename att_debug and att_verbose to DBG and VERBOSE
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=e1b808c128fa
- [BlueZ,v4,9/9] device: Don't use DBG in gatt_debug
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=71cec503c8da

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html


2022-03-25 20:12:02

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ v4 7/9] gatt-server: Add DBG macro

From: Luiz Augusto von Dentz <[email protected]>

This adds gatt_log wrapper for util_debug and DBG so file and function
names are printed with the logs.
---
src/shared/gatt-server.c | 64 ++++++++++++++++++++--------------------
1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/src/shared/gatt-server.c b/src/shared/gatt-server.c
index 776e5ce2b..2adb4afbf 100644
--- a/src/shared/gatt-server.c
+++ b/src/shared/gatt-server.c
@@ -41,6 +41,9 @@

#define NFY_MULT_TIMEOUT 10

+#define DBG(_server, _format, arg...) \
+ gatt_log(_server, "%s:%s() " _format, __FILE__, __func__, ## arg)
+
struct async_read_op {
struct bt_att_chan *chan;
struct bt_gatt_server *server;
@@ -233,6 +236,18 @@ static bool encode_read_by_grp_type_rsp(struct gatt_db *db, struct queue *q,
return true;
}

+static void gatt_log(struct bt_gatt_server *server, const char *format, ...)
+{
+ va_list ap;
+
+ if (!server || !format || !server->debug_callback)
+ return;
+
+ va_start(ap, format);
+ util_debug_va(server->debug_callback, server->debug_data, format, ap);
+ va_end(ap);
+}
+
static void read_by_grp_type_cb(struct bt_att_chan *chan, uint8_t opcode,
const void *pdu, uint16_t length,
void *user_data)
@@ -259,9 +274,7 @@ static void read_by_grp_type_cb(struct bt_att_chan *chan, uint8_t opcode,
end = get_le16(pdu + 2);
get_uuid_le(pdu + 4, length - 4, &type);

- util_debug(server->debug_callback, server->debug_data,
- "Read By Grp Type - start: 0x%04x end: 0x%04x",
- start, end);
+ DBG(server, "Read By Grp Type - start: 0x%04x end: 0x%04x", start, end);

if (!start || !end) {
ecode = BT_ATT_ERROR_INVALID_HANDLE;
@@ -483,9 +496,7 @@ static void read_by_type_cb(struct bt_att_chan *chan, uint8_t opcode,
end = get_le16(pdu + 2);
get_uuid_le(pdu + 4, length - 4, &type);

- util_debug(server->debug_callback, server->debug_data,
- "Read By Type - start: 0x%04x end: 0x%04x",
- start, end);
+ DBG(server, "Read By Type - start: 0x%04x end: 0x%04x", start, end);

if (!start || !end) {
ecode = BT_ATT_ERROR_INVALID_HANDLE;
@@ -605,9 +616,7 @@ static void find_info_cb(struct bt_att_chan *chan, uint8_t opcode,
start = get_le16(pdu);
end = get_le16(pdu + 2);

- util_debug(server->debug_callback, server->debug_data,
- "Find Info - start: 0x%04x end: 0x%04x",
- start, end);
+ DBG(server, "Find Info - start: 0x%04x end: 0x%04x", start, end);

if (!start || !end) {
ecode = BT_ATT_ERROR_INVALID_HANDLE;
@@ -708,9 +717,10 @@ static void find_by_type_val_cb(struct bt_att_chan *chan, uint8_t opcode,
end = get_le16(pdu + 2);
uuid16 = get_le16(pdu + 4);

- util_debug(server->debug_callback, server->debug_data,
- "Find By Type Value - start: 0x%04x end: 0x%04x uuid: 0x%04x",
- start, end, uuid16);
+ DBG(server,
+ "Find By Type Value - start: 0x%04x end: 0x%04x uuid: 0x%04x",
+ start, end, uuid16);
+
ehandle = start;
if (start > end) {
data.ecode = BT_ATT_ERROR_INVALID_HANDLE;
@@ -756,8 +766,7 @@ static void write_complete_cb(struct gatt_db_attribute *attr, int err,
return;
}

- util_debug(server->debug_callback, server->debug_data,
- "Write Complete: err %d", err);
+ DBG(server, "Write Complete: err %d", err);

handle = gatt_db_attribute_get_handle(attr);

@@ -818,10 +827,8 @@ static void write_cb(struct bt_att_chan *chan, uint8_t opcode, const void *pdu,
goto error;
}

- util_debug(server->debug_callback, server->debug_data,
- "Write %s - handle: 0x%04x",
- (opcode == BT_ATT_OP_WRITE_REQ) ? "Req" : "Cmd",
- handle);
+ DBG(server, "Write %s - handle: 0x%04x",
+ (opcode == BT_ATT_OP_WRITE_REQ) ? "Req" : "Cmd", handle);

ecode = check_length(length, 0);
if (ecode)
@@ -885,8 +892,7 @@ static void read_complete_cb(struct gatt_db_attribute *attr, int err,
uint16_t mtu;
uint16_t handle;

- util_debug(server->debug_callback, server->debug_data,
- "Read Complete: err %d", err);
+ DBG(server, "Read Complete: err %d", err);

mtu = bt_att_get_mtu(server->att);
handle = gatt_db_attribute_get_handle(attr);
@@ -922,10 +928,8 @@ static void handle_read_req(struct bt_att_chan *chan,
goto error;
}

- util_debug(server->debug_callback, server->debug_data,
- "Read %sReq - handle: 0x%04x",
- opcode == BT_ATT_OP_READ_BLOB_REQ ? "Blob " : "",
- handle);
+ DBG(server, "Read %sReq - handle: 0x%04x",
+ opcode == BT_ATT_OP_READ_BLOB_REQ ? "Blob " : "", handle);

ecode = check_permissions(server, attr, BT_ATT_PERM_READ_MASK);
if (ecode)
@@ -1125,8 +1129,7 @@ static void read_multiple_cb(struct bt_att_chan *chan, uint8_t opcode,

handle = data->handles[0];

- util_debug(server->debug_callback, server->debug_data,
- "%s Req - %zu handles, 1st: 0x%04x",
+ DBG(server, "%s Req - %zu handles, 1st: 0x%04x",
data->opcode == BT_ATT_OP_READ_MULT_REQ ?
"Read Multiple" : "Read Multiple Variable Length",
data->num_handles, handle);
@@ -1312,8 +1315,7 @@ static void prep_write_cb(struct bt_att_chan *chan, uint8_t opcode,
goto error;
}

- util_debug(server->debug_callback, server->debug_data,
- "Prep Write Req - handle: 0x%04x", handle);
+ DBG(server, "Prep Write Req - handle: 0x%04x", handle);

ecode = check_length(length, offset);
if (ecode)
@@ -1433,8 +1435,7 @@ static void exec_write_cb(struct bt_att_chan *chan, uint8_t opcode,

flags = ((uint8_t *) pdu)[0];

- util_debug(server->debug_callback, server->debug_data,
- "Exec Write Req - flags: 0x%02x", flags);
+ DBG(server, "Exec Write Req - flags: 0x%02x", flags);

if (flags == 0x00)
write = false;
@@ -1505,8 +1506,7 @@ static void exchange_mtu_cb(struct bt_att_chan *chan, uint8_t opcode,
server->mtu = final_mtu;
bt_att_set_mtu(server->att, final_mtu);

- util_debug(server->debug_callback, server->debug_data,
- "MTU exchange complete, with MTU: %u", final_mtu);
+ DBG(server, "MTU exchange complete, with MTU: %u", final_mtu);
}

static bool gatt_server_register_att_handlers(struct bt_gatt_server *server)
--
2.35.1