From patchwork Wed Mar 23 00:06:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 553804 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96697C433F5 for ; Wed, 23 Mar 2022 00:06:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240852AbiCWAIZ (ORCPT ); Tue, 22 Mar 2022 20:08:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbiCWAIY (ORCPT ); Tue, 22 Mar 2022 20:08:24 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CD5E5DE5A for ; Tue, 22 Mar 2022 17:06:56 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id i184so2947665pgc.1 for ; Tue, 22 Mar 2022 17:06:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=IP07YkQg0rPEBTHMn8DcG1oqgtBsAiOLeh56Bth5JYA=; b=FMSZabAKhK5Lvv0HUAAPvBv4X+AIDYep4Kt0rJhgVKw5qhJlR2vv+HXcDp4qXSI8CP D8d2GRljxU7LByflhPjZNHAFecRceeeCLufc1xRIG5YUKnObwh8NLemmp5t1dlSkVogz yQaF2/OiZ++tlXvhB9bP0PamDHHR7jQHPdvmRze1KOseM04HjwbBe6erX/UUDNGq/zIy 056eXBwi0ZdnT8tc2uSAJM6quhhtk7eFl37YCOIS3+r1gW44YW/BBRVrk84H+1DZqOsd EDEF8BZbrVTayprydameDJDBT85WLlthf2qB7TZZoukakiL9AJO/DHaif9d+pQsv5kV0 tbMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=IP07YkQg0rPEBTHMn8DcG1oqgtBsAiOLeh56Bth5JYA=; b=AefJXC3GIRkboMkUHD77lB2+6ju6b3CspBLxuKitqEyLmLyRCSGyCcqjNrBUE2kIEV moBV0ehovpfYu250Ixp8cWlrNgF+RraGlA91uBOPha/sJp46xKYeTcvPV1wD16SMryhj /DR8wrENhprp9xzrW39pAUJhjGjNgx8kKYgn/YXjAQ2zWSF2/T4H4sxptF5Ahp8aDGDA U8vu3/AT9aoahQmMMqHGuGUw4YkaeHuRVOBB79LnPZ/XB6k7pDk3c5y9rpv+9syCEg9o MJBwihvSgJ2pyowK9ANVQS/U763zzxlSDfIONgvkGOoDDPirXWb/33Fu3uODpQ4aDzgs OVqg== X-Gm-Message-State: AOAM531OUYCebMxiCFPEpetuFUWvDaGv1pWZ3rhOwIuaTYtVD8aWVtWi oR+G5oJlPsHAUATqhGnqFxB6YM0m590= X-Google-Smtp-Source: ABdhPJyhaTxC1d9RPb4ldK07rxIjj2IKzrm6BprOZmhx6mpUSf/shZIba1QlA16i6nB7hH5CM6PUAg== X-Received: by 2002:a63:ce58:0:b0:380:103:64ee with SMTP id r24-20020a63ce58000000b00380010364eemr23929298pgi.213.1647994015496; Tue, 22 Mar 2022 17:06:55 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id bx22-20020a056a00429600b004fa936a64b0sm10098423pfb.196.2022.03.22.17.06.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 17:06:55 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 1/9] log: Introduce DBG_IS_ENABLED Date: Tue, 22 Mar 2022 17:06:46 -0700 Message-Id: <20220323000654.3157833-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This introduces DBG_IS_ENABLE macro which can be used to check if BTD_DEBUG_FLAG_PRINT has been enabled for the current file. --- src/log.c | 12 ++++++++++++ src/log.h | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/log.c b/src/log.c index 0155a6bba..1157859ef 100644 --- a/src/log.c +++ b/src/log.c @@ -179,6 +179,18 @@ void __btd_log_init(const char *debug, int detach) info("Bluetooth daemon %s", VERSION); } +bool __btd_log_is_enabled(const char *file) +{ + struct btd_debug_desc *desc; + + for (desc = __start___debug; desc < __stop___debug; desc++) { + if (desc->file && g_pattern_match_simple(file, desc->file)) + return desc->flags & BTD_DEBUG_FLAG_PRINT; + } + + return false; +} + void __btd_log_cleanup(void) { closelog(); diff --git a/src/log.h b/src/log.h index 74941beb2..e35238870 100644 --- a/src/log.h +++ b/src/log.h @@ -9,6 +9,7 @@ */ #include +#include void info(const char *format, ...) __attribute__((format(printf, 1, 2))); @@ -27,6 +28,7 @@ void btd_debug(uint16_t index, const char *format, ...) void __btd_log_init(const char *debug, int detach); void __btd_log_cleanup(void); void __btd_toggle_debug(void); +bool __btd_log_is_enabled(const char *file); struct btd_debug_desc { const char *file; @@ -38,6 +40,15 @@ struct btd_debug_desc { void __btd_enable_debug(struct btd_debug_desc *start, struct btd_debug_desc *stop); +/* DBG_IS_ENABLED: + * + * Simple macro that can be used to check if debug has been enabled for the + * __FILE__. + * Note: This does a lookup thus why it was not used by the likes of + * DBG/DBG_IDX which loads it directly from section("__debug"). + */ +#define DBG_IS_ENABLED() __btd_log_is_enabled(__FILE__) + /** * DBG: * @fmt: format string From patchwork Wed Mar 23 00:06:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 554675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 064F8C433FE for ; Wed, 23 Mar 2022 00:06:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240858AbiCWAI0 (ORCPT ); Tue, 22 Mar 2022 20:08:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240849AbiCWAIZ (ORCPT ); Tue, 22 Mar 2022 20:08:25 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1791A5DE7F for ; Tue, 22 Mar 2022 17:06:57 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id c2so13748720pga.10 for ; Tue, 22 Mar 2022 17:06:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=lMeVwZRc+kCFv6ywPENuuniweobbSTLYVjAmAjxzwIE=; b=C8mcyl3j3WaP25KR/Vc8jrR+A7k5VEF6+DF3AuzoxWRU/87dfMC2hbZsENmTL3Of7A oB2Ur7tOp1wOclI8gnQNLXvjVHj5GUZ/lCxBZJpojvXEiN3x5zkBgnkUP3ZCOxaLCRl5 z3nDXWTF0z6FtftFCwgsEIxmHvVoLkG9JMzxEebrGwA15fhbhB7ZTWthOyiP4NI5CA+L EAUKhqtAbquQSHgKOr6ZNlxw/YjKzQBhZ8AGWm31SHhmnrcB/ayPDLzty+d1pDeGjJiW jjsUnfoW0Ky4GCExp/zlSzt5T4Kkgar3MEWFt4yUeIYkduTdSBtGaLXPRw5tcGqxI8HD d5EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lMeVwZRc+kCFv6ywPENuuniweobbSTLYVjAmAjxzwIE=; b=J5evYvWBl1DG4mp3/E4EBENKVnHcWqYiW6PFwvIsczXz7UL11u4bsPpcKMjzFdjFLt LWwuo47Byyp2Q4aHyXXfRlW1yFac4yD8yJKsUGnck1HwBr8woZh7/nlfWG7t3w5mnGyj ksTTGgJK74Z/VzCLE6olmejGzM7ZmddBLJhYppPXbJ76pPe+Bfcm8Tulw3a2auDTo33A e9tAyGI33Sc94NSLLA65n5vJk3JNf5Hbp8mliHM1OJldhlfjEg+gpCNze85NoRBsZ4i0 wQ5UxJYmKuXELNXjtgLKNfShrNhUXfOc0Jteo6ap7nRz2pRf9KpiM8G0R0IXY++S87uB +dxA== X-Gm-Message-State: AOAM530+ecXFkSLYh3Zgj0tC5MS46yhjiTowa+DihsPIYTsfzWtzgXlm XheH0IoxFtJjy5Ji3iw4Z/1m1tZhCSo= X-Google-Smtp-Source: ABdhPJyIevS5o+52IYgKdOZVr3H527FjsPm4eD22VY7YMusdMF5A8C+7/1H3MYEOA/TfyqYdoQ+jfg== X-Received: by 2002:a63:f966:0:b0:380:5d50:ba72 with SMTP id q38-20020a63f966000000b003805d50ba72mr8954848pgk.403.1647994016237; Tue, 22 Mar 2022 17:06:56 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id bx22-20020a056a00429600b004fa936a64b0sm10098423pfb.196.2022.03.22.17.06.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 17:06:55 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 2/9] mgmt: Add DBG macro Date: Tue, 22 Mar 2022 17:06:47 -0700 Message-Id: <20220323000654.3157833-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323000654.3157833-1-luiz.dentz@gmail.com> References: <20220323000654.3157833-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz 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); From patchwork Wed Mar 23 00:06:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 553803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2107C433EF for ; Wed, 23 Mar 2022 00:06:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240860AbiCWAI0 (ORCPT ); Tue, 22 Mar 2022 20:08:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240853AbiCWAIZ (ORCPT ); Tue, 22 Mar 2022 20:08:25 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83B625E143 for ; Tue, 22 Mar 2022 17:06:57 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id c23so93753plo.0 for ; Tue, 22 Mar 2022 17:06:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=oA2b2MSFZ5xMIcZQftlPk/BJnbKEpfSvA/B3B3AZtBo=; b=S+ACimeHKf47x+75YpDn69/Ldbv0OJymFBKcQqFOdIPso+b8VZ+YN01psvbsnJizhM zhiW/8rm0kbwUwZPoP0zFEyW2O5uTxTEzBe3YCtq75NXY3GkruZ5yj9NUxnujG8I9+b2 6Yj1JpX6Y3pOetnrDBkjVgdyFGoNgRs6eCSagp63hUpDHvgS4YI1CUpqnLG/4kQ7yuxx TcHjnRKxFrY5n5S4te62FXawSP7BjNTZWJFh2l/x0G7V+T65ZF322E/GFYvKxHoZtJyE xDT1GJQfwwn/OeqMTsz2/vu5v19/t4QiR6JcychiVFLAmqkpb3g46jJqCyRBPNeaIpwG Haeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oA2b2MSFZ5xMIcZQftlPk/BJnbKEpfSvA/B3B3AZtBo=; b=N6cR/yMAMy9np6wyVMW5TZ0DhttKRiHoIGn/wd5U3lXReGcNBs+uwu4NZ7LkQXboiM FMzvDRM968ZAQaBVsQNTyoemolUdxpuWadj8xKqMUPs4hLr5i104ZjwoP3Jx5Ppg/3PN f2pxdgHLOBcp5bUpxpgSZtTcBk5EbzlRc4elJSDTtuAKTKJdpOeGLM5JA49iMN3qIRI1 Z9pWGjeJrLzX1POp0XQWsvbdHBlTAw0QB2sSREn8mowDCbACKu/cTxNfex544TSbeRyJ w+Y4sLXcThs+LpUCxs3/WFWkSf204jDGE2VNUlzmWHp/XxoWF5F/SOGaHLOCzAUU6UYZ UpXw== X-Gm-Message-State: AOAM531ID2ShBZc3psYIX3ku6BZPn3woY5ZJbI7vY9aq2Q9tIfQZYSic rNAoz4/6JjwjZp4l+XKHclY6Bvi1bBk= X-Google-Smtp-Source: ABdhPJx3gzXoOPQfoQY5i9y0jNOekjrbGNXTGeqz178v+rkSw5WDfX3xSbC9tiRD4Ztrhc1LRzsSGg== X-Received: by 2002:a17:903:1209:b0:14e:e31c:b8c4 with SMTP id l9-20020a170903120900b0014ee31cb8c4mr20951542plh.153.1647994016832; Tue, 22 Mar 2022 17:06:56 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id bx22-20020a056a00429600b004fa936a64b0sm10098423pfb.196.2022.03.22.17.06.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 17:06:56 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 3/9] mgmt: Introduce mgmt_set_verbose Date: Tue, 22 Mar 2022 17:06:48 -0700 Message-Id: <20220323000654.3157833-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323000654.3157833-1-luiz.dentz@gmail.com> References: <20220323000654.3157833-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This introduces mgmt_set_verbose which can be used to enable printing the the likes hexdump of packets, by default it is disabled since in most cases the hexdump is not very useful and there are better tools to collect the hexdumo like btmon. --- src/shared/mgmt.c | 24 ++++++++++++++++++++---- src/shared/mgmt.h | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c index c7e6a6c1d..cf518cc2b 100644 --- a/src/shared/mgmt.c +++ b/src/shared/mgmt.c @@ -50,6 +50,7 @@ struct mgmt { mgmt_debug_func_t debug_callback; mgmt_destroy_func_t debug_destroy; void *debug_data; + bool verbose; }; struct mgmt_request { @@ -192,6 +193,15 @@ static void mgmt_log(struct mgmt *mgmt, const char *format, ...) va_end(ap); } +static void mgmt_hexdump(struct mgmt *mgmt, char dir, const void *data, + size_t len) +{ + if (!mgmt->verbose) + return; + + util_hexdump(dir, data, len, mgmt->debug_callback, mgmt->debug_data); +} + static bool send_request(struct mgmt *mgmt, struct mgmt_request *request) { struct iovec iov; @@ -219,8 +229,7 @@ static bool send_request(struct mgmt *mgmt, struct mgmt_request *request) DBG(mgmt, "[0x%04x] command 0x%04x", request->index, request->opcode); - util_hexdump('<', request->buf, ret, mgmt->debug_callback, - mgmt->debug_data); + mgmt_hexdump(mgmt, '<', request->buf, ret); queue_push_tail(mgmt->pending_list, request); @@ -373,8 +382,7 @@ static bool can_read_data(struct io *io, void *user_data) if (bytes_read < 0) return false; - util_hexdump('>', mgmt->buf, bytes_read, - mgmt->debug_callback, mgmt->debug_data); + mgmt_hexdump(mgmt, '>', mgmt->buf, bytes_read); if (bytes_read < MGMT_HDR_SIZE) return true; @@ -594,6 +602,14 @@ bool mgmt_set_debug(struct mgmt *mgmt, mgmt_debug_func_t callback, return true; } +void mgmt_set_verbose(struct mgmt *mgmt, bool value) +{ + if (!mgmt) + return; + + mgmt->verbose = value; +} + bool mgmt_set_close_on_unref(struct mgmt *mgmt, bool do_close) { if (!mgmt) diff --git a/src/shared/mgmt.h b/src/shared/mgmt.h index b413cea78..0f3e54c16 100644 --- a/src/shared/mgmt.h +++ b/src/shared/mgmt.h @@ -28,6 +28,7 @@ typedef void (*mgmt_debug_func_t)(const char *str, void *user_data); bool mgmt_set_debug(struct mgmt *mgmt, mgmt_debug_func_t callback, void *user_data, mgmt_destroy_func_t destroy); +void mgmt_set_verbose(struct mgmt *mgmt, bool value); bool mgmt_set_close_on_unref(struct mgmt *mgmt, bool do_close); From patchwork Wed Mar 23 00:06:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 554674 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 841B0C433F5 for ; Wed, 23 Mar 2022 00:07:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240862AbiCWAI1 (ORCPT ); Tue, 22 Mar 2022 20:08:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240861AbiCWAI0 (ORCPT ); Tue, 22 Mar 2022 20:08:26 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B8965DE5A for ; Tue, 22 Mar 2022 17:06:58 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id s11so109638pfu.13 for ; Tue, 22 Mar 2022 17:06:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZWwrOcoxBDXqjSVBr0WOOPq65eimqcjTTFuXG01fWSw=; b=FFDcxP7F/BAmV90G8UnrFkAqYaHJvGIABmomAZ82Mh4UTjrdzeryRWqcluETMrfXY6 2PlWnLWEKghj6w3e7+whD31eZpZuOmnT+pk9qBcfQ2a4xH6WgQ5o+iYb9bAEJoeHj45X T4xa+XABI0FAlFXqI1GZU2gevxUpEwdU3ZfXCyoxpo/sLBTZriHHvhuMZCBTmhPAPOlH NtMypxQGXdSeWTJjP9ZnJ29gNk2S751x3gQAl+kTb3/YqIIXg0YUD67iojsPOvvDb+mn vJWopy1pBJA1RYDRiNVJMum5jl2oDx2+3LhLPf0N6BePqrASjhDOQzxe2soJHRqn5Asr RqJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZWwrOcoxBDXqjSVBr0WOOPq65eimqcjTTFuXG01fWSw=; b=MZ1aOyzmu519HP2TL9qnCZwY927vmxd+VV3isibJ1HegqzNbzgBug47PxMgCivYdiW PjbO1qSgm/ZUb+CxU3HJAcQ2vuX3BvXbhgfGK/PIGdkReCvOIJoYkf1lRlAEUWUUjCay OavK45i1QKKeswo4Axpm7A1J9dsYrk4nf8OzdekgGbq13wvKCJjndQ4JiC3vzuWzQuJI 3CmkVVImpWpSmXiLbHzWTpuFD8+JTSzHFKzl5CelBpmpgU0CTdoeei+Zhv4QxvE/0Cur SxTVfyNR5kDmV5WFHG3JGqb9CQTTHXdd+/3J11OP4mvE5vfMzAXyUJACXMBP0ne7EdSp r/Sg== X-Gm-Message-State: AOAM530wpyGycdOGfSgHxyxm5uawHXd3GRpAKe2iEEZSyPRmQAU6yjt7 l2S5WAhjVz2E0yGLWT6bNngKD0uwAnM= X-Google-Smtp-Source: ABdhPJzLSVvyK2OJBKP8uZgbMjxt+nRX0L52FZGTS7TakTwPArLextq5+L8zqqJBzA6HGCFUPqw3fQ== X-Received: by 2002:a63:df14:0:b0:381:309f:10bc with SMTP id u20-20020a63df14000000b00381309f10bcmr23756132pgg.77.1647994017634; Tue, 22 Mar 2022 17:06:57 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id bx22-20020a056a00429600b004fa936a64b0sm10098423pfb.196.2022.03.22.17.06.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 17:06:57 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 4/9] adapter: Don't use DBG in mgmt_debug Date: Tue, 22 Mar 2022 17:06:49 -0700 Message-Id: <20220323000654.3157833-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323000654.3157833-1-luiz.dentz@gmail.com> References: <20220323000654.3157833-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz mgmt_debug callback is used to print debug strings from mgmt instances which includes the file and function names so using DBG would add yet another set of file and function prefixes which makes the logs confusing. --- src/adapter.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 97ce26f8e..6680c5410 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -10327,9 +10327,8 @@ static void read_version_complete(uint8_t status, uint16_t length, static void mgmt_debug(const char *str, void *user_data) { - const char *prefix = user_data; - - info("%s%s", prefix, str); + if (DBG_IS_ENABLED()) + btd_debug(0xffff, "%s", str); } int adapter_init(void) @@ -10342,8 +10341,7 @@ int adapter_init(void) return -EIO; } - if (getenv("MGMT_DEBUG")) - mgmt_set_debug(mgmt_primary, mgmt_debug, "mgmt: ", NULL); + mgmt_set_debug(mgmt_primary, mgmt_debug, NULL, NULL); DBG("sending read version command"); From patchwork Wed Mar 23 00:06:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 553802 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC44EC433FE for ; Wed, 23 Mar 2022 00:07:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240864AbiCWAI2 (ORCPT ); Tue, 22 Mar 2022 20:08:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240863AbiCWAI1 (ORCPT ); Tue, 22 Mar 2022 20:08:27 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C59D5DE5A for ; Tue, 22 Mar 2022 17:06:59 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id jx9so123718pjb.5 for ; Tue, 22 Mar 2022 17:06:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=/j7e/CWw6oRrnkQVp/KphTi81K+8ZW6pXdZNgewlKz0=; b=qPbTf1MCnBva0zGGEK9LeauLScXkFY63tlXFzaD+bNymnigqq3Yl2Bl7OySCUdJ2uw KS2TioG4dSjb+LQwztfyBx4erLxiu5GlC0ptrATW/oXLjON6r6VTGxawHYWMpHzxnpH2 NTChqFHriu5j7+9y6Hb/OYMQBff/ban9KDRHKh7j2wUV2O8S83/iSKt/Ue3T8lfNDuFa pSg7LIoBAoLXmexXAv9eCd1+vy6YXL89b28OmQ5l+QsixefI+2s2Z1zNKxnyq5XwncaV 1mID25wifZIJxI8zsBMHZrig3M6mhCpMZ2mi375NVZSqqA2KONi3wNa5HFEZizwz6w5b vi1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/j7e/CWw6oRrnkQVp/KphTi81K+8ZW6pXdZNgewlKz0=; b=Ve0tBPVv8q3QpLX5+c4JU90XH4kmsptIUl/+NY3pCu0/HuXnG6z0qffmks0I0qdSqo EO6E22gy5gdpVqoy3DKW1qfT2jLinVEtpa2xV8AGlHcWQBIjyfQPoFxQ+mLhYLRR2U/B LY+YdzJSG1yrVAJ+qs0pNDApn6LYRHLxYjt6RKPOxHZj2b3RMonlypnJ+RRIUJR5SsI2 QV5hhPc81PA7ENe23BMbYLGTmFHqvbbdemVgJmVVOnl7Q8H+uVgnwCGM4oCokKTgaHFU La3MsdzUZ2+DxJsHI8so8/sv5Nwpw15pZeGM0e7kb2d0Q4y4Fm4lf5GQw1ybqNHlBVZZ lHVg== X-Gm-Message-State: AOAM530ULLuOpI7t4IR6d/owH5F5kR3MLgV971ngRR33d3yH0GlgL303 4lgoAadcdlCVxhx9u4MldQPx+OJ08bk= X-Google-Smtp-Source: ABdhPJwG2FkwMToS8je/jzbRjig145RgGdinAuooHVloxI855HK7BmeoCmi5tN3E6mi+WGD8i8lssw== X-Received: by 2002:a17:902:b490:b0:151:6ee1:8034 with SMTP id y16-20020a170902b49000b001516ee18034mr20895015plr.28.1647994018515; Tue, 22 Mar 2022 17:06:58 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id bx22-20020a056a00429600b004fa936a64b0sm10098423pfb.196.2022.03.22.17.06.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 17:06:58 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 5/9] att: Log file and function names Date: Tue, 22 Mar 2022 17:06:50 -0700 Message-Id: <20220323000654.3157833-5-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323000654.3157833-1-luiz.dentz@gmail.com> References: <20220323000654.3157833-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds logging of file and function names. --- src/shared/att.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/shared/att.c b/src/shared/att.c index 169f726e4..7344b0c46 100644 --- a/src/shared/att.c +++ b/src/shared/att.c @@ -308,10 +308,12 @@ static void att_log(struct bt_att *att, uint8_t level, const char *format, } #define att_debug(_att, _format, _arg...) \ - att_log(_att, BT_ATT_DEBUG, _format, ## _arg) + att_log(_att, BT_ATT_DEBUG, "%s:%s() " _format, __FILE__, __func__,\ + ## _arg) #define att_verbose(_att, _format, _arg...) \ - att_log(_att, BT_ATT_DEBUG_VERBOSE, _format, ## _arg) + att_log(_att, BT_ATT_DEBUG_VERBOSE, "%s:%s() " _format, __FILE__, \ + __func__, ## _arg) static void att_hexdump(struct bt_att *att, char dir, const void *data, size_t len) From patchwork Wed Mar 23 00:06:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 554673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18999C433F5 for ; Wed, 23 Mar 2022 00:07:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240869AbiCWAI3 (ORCPT ); Tue, 22 Mar 2022 20:08:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240863AbiCWAI3 (ORCPT ); Tue, 22 Mar 2022 20:08:29 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 581215DE5A for ; Tue, 22 Mar 2022 17:07:00 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id mz9-20020a17090b378900b001c657559290so4820613pjb.2 for ; Tue, 22 Mar 2022 17:07:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=YgL1QjGsntEM/sKI8J2WatVdiyjYA18RaC7riKp34Dw=; b=inHQgya4SkmzVTHegivMz4jpirNwlj3kIlYeIvbWj21sADkCbT0PZfkVJMVohzn2Cr 0oVI1tpUaxqaEzDNZcFEn+TXacvR6wkfVMRhxQrPi8jjLGWgkY5g2blI6IMPpqBbMpQT +ZMFsLQAU8tgfNdsSFKnIiXekhiB8WbVTUROK0yMmhvNMk+WXv6KrG3Lg3pIJYc9ShhC zluLRcBR1npFLFVjgJV2ou1s5FgwLSt3eqfqMaZbTW0oo9c9P4fq9xovfLmWTftMXLVO cB7vDa79GOjkPuMc8caw9OjE+Y2gikEjOqeGuBvZGQyctM+jpcxh/F4lLL5A+BTTmGEw zEMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YgL1QjGsntEM/sKI8J2WatVdiyjYA18RaC7riKp34Dw=; b=S5H7bJ2+F4JwkfSNPDIftOF9znDlf7ANxADlNkFeuLAsOOjb0ftjDbJHB1K0dbTlYR p9INoOVP51+q6j8MNsfcXGYQOg/PX+op62JQ+jgLQX23lX1c+WJHvA481I3kD3Dy4gU7 hYZiL23yjG5VVhenfekWxKEDjiWwg+yitjZndC2VHgtzQQ7bukxHB3XUad1XIgKVOXqs 8v5rqdUVzGhSb+VeUz6SEyiGxqzfZJaxpQZ/LnKic2GNZTyhs3jLtttgsVHOaFsXaoeB hDt8j17nfJgJaHoOsZwadZ2shQ9faOqjAPt4BuoCT3NceNcjmukKBPOSFYXONvdMbNnZ AudQ== X-Gm-Message-State: AOAM532aWcKORU7EWhAt84/sxNDUvwwBTop9eiMh72YAz3WajYcV0Ngt h3ipJ4xh/KE+97CdXWHutmBIz2aiEdE= X-Google-Smtp-Source: ABdhPJwqj34vm1quNwnBAqGk6rnSK5ZwICuKeMlKUJmEQqe9mzjj3GqU3ppBTBJoC+mY+t/jJevogA== X-Received: by 2002:a17:903:1206:b0:151:7d67:2924 with SMTP id l6-20020a170903120600b001517d672924mr20592820plh.45.1647994019253; Tue, 22 Mar 2022 17:06:59 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id bx22-20020a056a00429600b004fa936a64b0sm10098423pfb.196.2022.03.22.17.06.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 17:06:58 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 6/9] gatt-client: Add DBG macro Date: Tue, 22 Mar 2022 17:06:51 -0700 Message-Id: <20220323000654.3157833-6-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323000654.3157833-1-luiz.dentz@gmail.com> References: <20220323000654.3157833-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds gatt_log wrapper for util_debug and DBG macro so file and function names are printed which is more consistent with other parts of the daemon code. --- src/shared/gatt-client.c | 160 +++++++++++++++++---------------------- 1 file changed, 70 insertions(+), 90 deletions(-) diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c index e24c9603c..ba9228ddf 100644 --- a/src/shared/gatt-client.c +++ b/src/shared/gatt-client.c @@ -37,6 +37,8 @@ #define GATT_SVC_UUID 0x1801 #define SVC_CHNGD_UUID 0x2a05 +#define DBG(_client, _format, arg...) \ + gatt_log(_client, "%s:%s() " _format, __FILE__, __func__, ## arg) struct ready_cb { bt_gatt_client_callback_t callback; @@ -376,6 +378,18 @@ static void discovery_op_free(struct discovery_op *op) static bool read_db_hash(struct discovery_op *op); +static void gatt_log(struct bt_gatt_client *client, const char *format, ...) +{ + va_list ap; + + if (!client || !format || !client->debug_callback) + return; + + va_start(ap, format); + util_debug_va(client->debug_callback, client->debug_data, format, ap); + va_end(ap); +} + static void discovery_op_complete(struct discovery_op *op, bool success, uint8_t err) { @@ -406,9 +420,8 @@ static void discovery_op_complete(struct discovery_op *op, bool success, gatt_db_attribute_get_service_data(attr, &start, &end, NULL, NULL); - util_debug(op->client->debug_callback, op->client->debug_data, - "service disappeared: start 0x%04x end 0x%04x", - start, end); + DBG(op->client, "service disappeared: start 0x%04x end 0x%04x", + start, end); gatt_db_remove_service(op->client->db, attr); } @@ -542,9 +555,7 @@ static void discover_incl_cb(bool success, uint8_t att_ecode, if (includes_count == 0) goto failed; - util_debug(client->debug_callback, client->debug_data, - "Included services found: %u", - includes_count); + DBG(client, "Included services found: %u", includes_count); for (i = 0; i < includes_count; i++) { if (!bt_gatt_iter_next_included_service(&iter, &handle, &start, @@ -555,13 +566,12 @@ static void discover_incl_cb(bool success, uint8_t att_ecode, /* Log debug message */ bt_uuid_to_string(&uuid, uuid_str, sizeof(uuid_str)); - util_debug(client->debug_callback, client->debug_data, - "handle: 0x%04x, start: 0x%04x, end: 0x%04x," + DBG(client, "handle: 0x%04x, start: 0x%04x, end: 0x%04x," "uuid: %s", handle, start, end, uuid_str); attr = gatt_db_get_attribute(client->db, start); if (!attr) { - util_debug(client->debug_callback, client->debug_data, + DBG(client, "Unable to find attribute at 0x%04x: skipping", start); continue; @@ -569,7 +579,7 @@ static void discover_incl_cb(bool success, uint8_t att_ecode, attr = gatt_db_insert_included(client->db, handle, attr); if (!attr) { - util_debug(client->debug_callback, client->debug_data, + DBG(client, "Unable to add include attribute at 0x%04x", handle); goto failed; @@ -582,7 +592,7 @@ static void discover_incl_cb(bool success, uint8_t att_ecode, * attribute. */ if (gatt_db_attribute_get_handle(attr) != handle) { - util_debug(client->debug_callback, client->debug_data, + DBG(client, "Invalid attribute 0x%04x expect it at 0x%04x", gatt_db_attribute_get_handle(attr), handle); goto failed; @@ -604,8 +614,8 @@ next: if (client->discovery_req) return; - util_debug(client->debug_callback, client->debug_data, - "Failed to start characteristic discovery"); + DBG(client, "Failed to start characteristic discovery"); + discovery_op_unref(op); failed: discovery_op_complete(op, false, att_ecode); @@ -656,7 +666,7 @@ static bool discover_descs(struct discovery_op *op, bool *discovering) NULL, NULL, NULL); if (!attr) { - util_debug(client->debug_callback, client->debug_data, + DBG(client, "Failed to insert characteristic at 0x%04x", chrc_data->value_handle); @@ -729,8 +739,8 @@ static bool discover_descs(struct discovery_op *op, bool *discovering) goto done; } - util_debug(client->debug_callback, client->debug_data, - "Failed to start descriptor discovery"); + DBG(client, "Failed to start descriptor discovery"); + discovery_op_unref(op); goto failed; @@ -750,8 +760,7 @@ static void ext_prop_write_cb(struct gatt_db_attribute *attrib, { struct bt_gatt_client *client = user_data; - util_debug(client->debug_callback, client->debug_data, - "Value set status: %d", err); + DBG(client, "Value set status: %d", err); } static void ext_prop_read_cb(bool success, uint8_t att_ecode, @@ -790,8 +799,7 @@ static void ext_prop_read_cb(bool success, uint8_t att_ecode, if (!success) goto done; - util_debug(client->debug_callback, client->debug_data, - "Ext. prop value: 0x%04x", (uint16_t)value[0]); + DBG(client, "Ext. prop value: 0x%04x", (uint16_t)value[0]); desc_attr = queue_pop_head(op->ext_prop_desc); if (!desc_attr) @@ -857,8 +865,7 @@ static void discover_descs_cb(bool success, uint8_t att_ecode, if (desc_count == 0) goto failed; - util_debug(client->debug_callback, client->debug_data, - "Descriptors found: %u", desc_count); + DBG(client, "Descriptors found: %u", desc_count); bt_uuid16_create(&ext_prop_uuid, GATT_CHARAC_EXT_PROPER_UUID); @@ -867,9 +874,8 @@ static void discover_descs_cb(bool success, uint8_t att_ecode, /* Log debug message */ bt_uuid_to_string(&uuid, uuid_str, sizeof(uuid_str)); - util_debug(client->debug_callback, client->debug_data, - "handle: 0x%04x, uuid: %s", - handle, uuid_str); + + DBG(client, "handle: 0x%04x, uuid: %s", handle, uuid_str); attr = gatt_db_insert_descriptor(client->db, handle, &uuid, 0, NULL, NULL, @@ -880,8 +886,7 @@ static void discover_descs_cb(bool success, uint8_t att_ecode, gatt_db_attribute_get_type(attr))) continue; - util_debug(client->debug_callback, client->debug_data, - "Failed to insert descriptor at 0x%04x", + DBG(client, "Failed to insert descriptor at 0x%04x", handle); goto failed; } @@ -947,8 +952,8 @@ static void discover_chrcs_cb(bool success, uint8_t att_ecode, goto failed; chrc_count = bt_gatt_result_characteristic_count(result); - util_debug(client->debug_callback, client->debug_data, - "Characteristics found: %u", chrc_count); + + DBG(client, "Characteristics found: %u", chrc_count); if (chrc_count == 0) goto failed; @@ -959,8 +964,7 @@ static void discover_chrcs_cb(bool success, uint8_t att_ecode, /* Log debug message */ bt_uuid_to_string(&uuid, uuid_str, sizeof(uuid_str)); - util_debug(client->debug_callback, client->debug_data, - "start: 0x%04x, end: 0x%04x, value: 0x%04x, " + DBG(client, "start: 0x%04x, end: 0x%04x, value: 0x%04x, " "props: 0x%02x, uuid: %s", start, end, value, properties, uuid_str); @@ -997,8 +1001,7 @@ next: if (client->discovery_req) return; - util_debug(client->debug_callback, client->debug_data, - "Failed to start included services discovery"); + DBG(client, "Failed to start included services discovery"); discovery_op_unref(op); @@ -1110,8 +1113,7 @@ static bool discovery_parse_services(struct discovery_op *op, bool primary, /* Log debug message */ bt_uuid_to_string(&uuid, uuid_str, sizeof(uuid_str)); - util_debug(client->debug_callback, client->debug_data, - "start: 0x%04x, end: 0x%04x, uuid: %s", + DBG(client, "start: 0x%04x, end: 0x%04x, uuid: %s", start, end, uuid_str); /* Store the service */ @@ -1122,9 +1124,7 @@ static bool discovery_parse_services(struct discovery_op *op, bool primary, attr = gatt_db_insert_service(client->db, start, &uuid, false, end - start + 1); if (!attr) { - util_debug(client->debug_callback, - client->debug_data, - "Failed to store service"); + DBG(client, "Failed to store service"); return false; } /* Database has changed adjust last handle */ @@ -1157,8 +1157,7 @@ static void discover_secondary_cb(bool success, uint8_t att_ecode, att_ecode = 0; goto next; default: - util_debug(client->debug_callback, client->debug_data, - "Secondary service discovery failed." + DBG(client, "Secondary service discovery failed." " ATT ECODE: 0x%02x", att_ecode); goto done; } @@ -1169,8 +1168,7 @@ static void discover_secondary_cb(bool success, uint8_t att_ecode, goto done; } - util_debug(client->debug_callback, client->debug_data, - "Secondary services found: %u", + DBG(client, "Secondary services found: %u", bt_gatt_result_service_count(result)); if (!discovery_parse_services(op, false, &iter)) { @@ -1199,8 +1197,8 @@ next: if (client->discovery_req) return; - util_debug(client->debug_callback, client->debug_data, - "Failed to start included services discovery"); + DBG(client, "Failed to start included services discovery"); + discovery_op_unref(op); success = false; @@ -1226,8 +1224,7 @@ static void discover_primary_cb(bool success, uint8_t att_ecode, att_ecode = 0; goto secondary; default: - util_debug(client->debug_callback, client->debug_data, - "Primary service discovery failed." + DBG(client, "Primary service discovery failed." " ATT ECODE: 0x%02x", att_ecode); goto done; } @@ -1238,8 +1235,7 @@ static void discover_primary_cb(bool success, uint8_t att_ecode, goto done; } - util_debug(client->debug_callback, client->debug_data, - "Primary services found: %u", + DBG(client, "Primary services found: %u", bt_gatt_result_service_count(result)); if (!discovery_parse_services(op, true, &iter)) { @@ -1266,8 +1262,8 @@ secondary: if (client->discovery_req) return; - util_debug(client->debug_callback, client->debug_data, - "Failed to start secondary service discovery"); + DBG(client, "Failed to start secondary service discovery"); + discovery_op_unref(op); success = false; @@ -1331,8 +1327,7 @@ static void discover_all(struct discovery_op *op) if (client->discovery_req) return; - util_debug(client->debug_callback, client->debug_data, - "Failed to initiate primary service discovery"); + DBG(client, "Failed to initiate primary service discovery"); client->in_init = false; notify_client_ready(client, false, BT_ATT_ERROR_UNLIKELY); @@ -1345,8 +1340,7 @@ static void db_hash_write_value_cb(struct gatt_db_attribute *attrib, { struct bt_gatt_client *client = user_data; - util_debug(client->debug_callback, client->debug_data, - "Value set status: %d", err); + DBG(client, "Value set status: %d", err); } static void db_hash_read_value_cb(struct gatt_db_attribute *attrib, @@ -1377,9 +1371,8 @@ static void db_hash_read_cb(bool success, uint8_t att_ecode, bt_gatt_iter_init(&iter, result); bt_gatt_iter_next_read_by_type(&iter, &handle, &len, &value); - util_debug(client->debug_callback, client->debug_data, - "DB Hash found: handle 0x%04x length 0x%04x", - handle, len); + DBG(client, "DB Hash found: handle 0x%04x length 0x%04x", + handle, len); if (len != 16) goto discover; @@ -1390,15 +1383,14 @@ static void db_hash_read_cb(bool success, uint8_t att_ecode, /* Check if the has has changed since last time */ if (hash && !memcmp(hash, value, len)) { - util_debug(client->debug_callback, client->debug_data, - "DB Hash match: skipping discovery"); + DBG(client, "DB Hash match: skipping discovery"); queue_remove_all(op->pending_svcs, NULL, NULL, NULL); discovery_op_complete(op, true, 0); return; } - util_debug(client->debug_callback, client->debug_data, - "DB Hash value:"); + DBG(client, "DB Hash value:"); + util_hexdump(' ', value, len, client->debug_callback, client->debug_data); @@ -1469,8 +1461,7 @@ static void db_server_feat_read(bool success, uint8_t att_ecode, bt_gatt_iter_init(&iter, result); bt_gatt_iter_next_read_by_type(&iter, &handle, &len, &value); - util_debug(client->debug_callback, client->debug_data, - "Server Features found: handle 0x%04x " + DBG(client, "Server Features found: handle 0x%04x " "length 0x%04x value 0x%02x", handle, len, value[0]); @@ -1524,8 +1515,7 @@ static void exchange_mtu_cb(bool success, uint8_t att_ecode, void *user_data) client->mtu_req_id = 0; if (!success) { - util_debug(client->debug_callback, client->debug_data, - "MTU Exchange failed. ATT ECODE: 0x%02x", + DBG(client, "MTU Exchange failed. ATT ECODE: 0x%02x", att_ecode); /* @@ -1543,8 +1533,7 @@ static void exchange_mtu_cb(bool success, uint8_t att_ecode, void *user_data) return; } - util_debug(client->debug_callback, client->debug_data, - "MTU exchange complete, with MTU: %u", + DBG(client, "MTU exchange complete, with MTU: %u", bt_att_get_mtu(client->att)); discover: @@ -1749,7 +1738,7 @@ static void service_changed_register_cb(uint16_t att_ecode, void *user_data) struct bt_gatt_client *client = user_data; if (att_ecode) { - util_debug(client->debug_callback, client->debug_data, + DBG(client, "Failed to register handler for \"Service Changed\""); success = false; client->svc_chngd_ind_id = 0; @@ -1758,8 +1747,7 @@ static void service_changed_register_cb(uint16_t att_ecode, void *user_data) client->svc_chngd_registered = true; success = true; - util_debug(client->debug_callback, client->debug_data, - "Registered handler for \"Service Changed\": %u", + DBG(client, "Registered handler for \"Service Changed\": %u", client->svc_chngd_ind_id); done: @@ -1807,7 +1795,7 @@ static void service_changed_complete(struct discovery_op *op, bool success, client->in_svc_chngd = false; if (!success && att_ecode != BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND) { - util_debug(client->debug_callback, client->debug_data, + DBG(client, "Failed to discover services within changed range - " "error: 0x%02x", att_ecode); @@ -1841,7 +1829,7 @@ static void service_changed_complete(struct discovery_op *op, bool success, if (register_service_changed(client)) return; - util_debug(client->debug_callback, client->debug_data, + DBG(client, "Failed to re-register handler for \"Service Changed\""); } @@ -1877,9 +1865,8 @@ static void process_service_changed(struct bt_gatt_client *client, discovery_op_free(op); fail: - util_debug(client->debug_callback, client->debug_data, - "Failed to initiate service discovery" - " after Service Changed"); + DBG(client, + "Failed to initiate service discovery after Service Changed"); } static void service_changed_cb(uint16_t value_handle, const uint8_t *value, @@ -1896,13 +1883,12 @@ static void service_changed_cb(uint16_t value_handle, const uint8_t *value, end = get_le16(value + 2); if (start > end) { - util_debug(client->debug_callback, client->debug_data, + DBG(client, "Service Changed received with invalid handles"); return; } - util_debug(client->debug_callback, client->debug_data, - "Service Changed received - start: 0x%04x end: 0x%04x", + DBG(client, "Service Changed received - start: 0x%04x end: 0x%04x", start, end); if (!client->in_svc_chngd) { @@ -1923,8 +1909,7 @@ static void server_feat_write_value(struct gatt_db_attribute *attrib, { struct bt_gatt_client *client = user_data; - util_debug(client->debug_callback, client->debug_data, - "Server Features Value set status: %d", err); + DBG(client, "Server Features Value set status: %d", err); } static void write_server_features(struct bt_gatt_client *client, uint8_t feat) @@ -1943,8 +1928,7 @@ static void write_server_features(struct bt_gatt_client *client, uint8_t feat) if (!gatt_db_attribute_write(attr, 0, &feat, sizeof(feat), 0, NULL, server_feat_write_value, client)) - util_debug(client->debug_callback, client->debug_data, - "Unable to store Server Features"); + DBG(client, "Unable to store Server Features"); } static void write_client_features(struct bt_gatt_client *client) @@ -1981,8 +1965,7 @@ static void write_client_features(struct bt_gatt_client *client) client->features |= BT_GATT_CHRC_CLI_FEAT_NFY_MULTI; - util_debug(client->debug_callback, client->debug_data, - "Writing Client Features 0x%02x", client->features); + DBG(client, "Writing Client Features 0x%02x", client->features); bt_gatt_client_write_value(client, handle, &client->features, sizeof(client->features), NULL, NULL, NULL); @@ -2006,13 +1989,11 @@ static void init_complete(struct discovery_op *op, bool success, if (register_service_changed(client)) goto done; - util_debug(client->debug_callback, client->debug_data, - "Failed to register handler for \"Service Changed\""); + DBG(client, "Failed to register handler for \"Service Changed\""); success = false; fail: - util_debug(client->debug_callback, client->debug_data, - "Failed to initialize gatt-client"); + DBG(client, "Failed to initialize gatt-client"); op->success = false; @@ -3501,8 +3482,7 @@ unsigned int bt_gatt_client_prepare_write(struct bt_gatt_client *client, * prepare writes or this is brand new reliable session (id == 0) */ if (id != client->reliable_write_session_id) { - util_debug(client->debug_callback, client->debug_data, - "There is other reliable write session ongoing %u", + DBG(client, "There is other reliable write session ongoing %u", client->reliable_write_session_id); return 0; From patchwork Wed Mar 23 00:06:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 553801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A98AC433EF for ; Wed, 23 Mar 2022 00:07:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240882AbiCWAIa (ORCPT ); Tue, 22 Mar 2022 20:08:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240865AbiCWAI3 (ORCPT ); Tue, 22 Mar 2022 20:08:29 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E71376EB32 for ; Tue, 22 Mar 2022 17:07:00 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id k14so2779325pga.0 for ; Tue, 22 Mar 2022 17:07:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=GFc9sXDCUSGMKzcmjKZL85zsIJOnPsCDkSf/Z7ucJ1E=; b=BAye/e910aNWz4MFoxjrXvPlbrA+WBp0ejzIZQ1/Ej/6pAkAqli+zyytCjcJYSK0At VQ16W/gvAk+sT7m5oISYCG+apy83lWZk0e4keqs8otD/8FT7McQptwztmKFLwfnSSC5c rwh3YvSmV2WwZNafR+9mEKIPJ41ZNCKE+fUL0kT3jNYjM/FUp7clC691LCAyNwh3Dmxu yeNjRpMWwP1JVPeqTeNguRO/n+r0SEniKjO/AHtuNND9TOKQ4Kch6NgeF9LS6/VgZYHs ZfPVggKrcNoXsOzapidHnmXA4oFxEdrkfQzQhMWAzwS507zUIucRj+x7Wkva136AWA6+ 0eJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GFc9sXDCUSGMKzcmjKZL85zsIJOnPsCDkSf/Z7ucJ1E=; b=B6WKqFHUD35+pHIp3XdMIwaE3dtZJIp/nKFrCwNOEm+Xx0WKBqcIkA9eHKvfkzQEn/ Bd97dWUGUp8TdpkTATj/jORxamhGWfPcmJeiSeF4R+c0rkqRsWfLKvFUHYQ6Ti1a9h/+ j01Q+HXkiNP6iF/HdycNx5ib6BfcWF1imTJ5VuNyo+c9agjB9AFD02/DviEx2EM/5beb ESuZPPSVWpVOBEdM2kv11Wf9Qf5u9zCPdrJTeXep0g6+ByFtcMZ4mSvFNasI8F7KKGBU HkZFX0iTTw6va1X+5DMXPPJTo6gC+tchCPJu9n0ZpKrlEv/t0/TXwe13xZDAafrDWj5L 4QqA== X-Gm-Message-State: AOAM530M+7UkYoVqRZm4r98S/C54IePfJZXGXB5MPly8++mbnPgCx31g qCNIZGV6kcvaNrPAuHKKp+bG4qdiaVE= X-Google-Smtp-Source: ABdhPJx0GV6EvoG7c5Obi5f+WsB8UcOGyUBVR21JQ5uZFZ9XhqEX3dS3yHGREkhBYYt+VJGfwPIusA== X-Received: by 2002:a65:61a2:0:b0:380:caf8:cbb3 with SMTP id i2-20020a6561a2000000b00380caf8cbb3mr23727794pgv.249.1647994019975; Tue, 22 Mar 2022 17:06:59 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id bx22-20020a056a00429600b004fa936a64b0sm10098423pfb.196.2022.03.22.17.06.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 17:06:59 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 7/9] gatt-server: Add DBG macro Date: Tue, 22 Mar 2022 17:06:52 -0700 Message-Id: <20220323000654.3157833-7-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323000654.3157833-1-luiz.dentz@gmail.com> References: <20220323000654.3157833-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz 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) From patchwork Wed Mar 23 00:06:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 553800 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF8C7C4332F for ; Wed, 23 Mar 2022 00:07:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240871AbiCWAIb (ORCPT ); Tue, 22 Mar 2022 20:08:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240868AbiCWAI3 (ORCPT ); Tue, 22 Mar 2022 20:08:29 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D89F6EC5D for ; Tue, 22 Mar 2022 17:07:01 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id q11so48057pln.11 for ; Tue, 22 Mar 2022 17:07:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=A5mU7ZW/EoX09OtoTGJHt6b6/ozCCsZy6iGJ/CCN76Y=; b=DmdJBhISL/pXTGTXZJ66h1qF46+0nfgaUmE/JD3DyoVNe1xU3Rsz07rnr6OJjQMeEL HpxavFsQYCd6QuwpgJrhYehTWa7BWxLzVXsnbMjMhswul7t8RvVCbd+SppI7gf89X/jJ TzGYoXk8hARXpL82kM6nDTbfyaTNmcobOkJIz4Ld/aoo+WV/QHq8IAQhwzOVmJy/SZ9J ydSNZGjDywgI/Hl496//lKm6LsOCvCaY65j4T8anAAnvTcooXusvsDn3r9O9kHloh0+H NkKXzsII9kfj7IooQ1HnbkXXXl4eT55DouiDRGOawGDLQnPJAeSjbfXKo5xLSiMH59qk 8Ylw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=A5mU7ZW/EoX09OtoTGJHt6b6/ozCCsZy6iGJ/CCN76Y=; b=syQtLSJNpec3RvsKQl4b6X/FEYkxBEls8IaLTzP2C3VPCRiNRDYmGSB/mQfdC7pShX Ws94dfQQ5L2dqreORSAzp8XawP7psEN2jElx5ohB0j/ExpWnJhuPI+cz2LXQoipAMvJe K4jNYjm8Onuwbt15IUg34SsxlSPVbzdLQCFwxtv979bi7JlPLCPhZoXmSar/swvcPNFZ FRAcDvXcIB0+CSuEMP1sX0h+bVCiLGL1wwubxra2bFDbk73rv+ZHgUu1bo+dtMkBta8x F2ISuXtjy46nrHBhYw+i3UblZoVexnUZZD7GRVJYM3/kBGI65fgjlwjY9PlxcC7RwQuB TloQ== X-Gm-Message-State: AOAM530rxhwnR7BLXGVpBfKMB14/WS9HXoOGu0veHmFkdIYDhY284NYD oGQr5P7MF9ce3Or3vO3+9CakbriyhoI= X-Google-Smtp-Source: ABdhPJwAfIhRtff9n+VZ0fRaQIkaRR6/7mIyUmgVfzhz3e6bHiAjyaI4qRfxRLNupIdYXz0DUr4/8Q== X-Received: by 2002:a17:90a:541:b0:1c6:68cc:8b68 with SMTP id h1-20020a17090a054100b001c668cc8b68mr8007392pjf.172.1647994020616; Tue, 22 Mar 2022 17:07:00 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id bx22-20020a056a00429600b004fa936a64b0sm10098423pfb.196.2022.03.22.17.07.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 17:07:00 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 8/9] att: Rename att_debug and att_verbose to DBG and VERBOSE Date: Tue, 22 Mar 2022 17:06:53 -0700 Message-Id: <20220323000654.3157833-8-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323000654.3157833-1-luiz.dentz@gmail.com> References: <20220323000654.3157833-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz att_debug and att_verbose are macros which are more common to be used as uppercase, this also change them to use DBG like other parts of the code. --- src/shared/att.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/shared/att.c b/src/shared/att.c index 7344b0c46..f7bef08bc 100644 --- a/src/shared/att.c +++ b/src/shared/att.c @@ -307,11 +307,11 @@ static void att_log(struct bt_att *att, uint8_t level, const char *format, va_end(va); } -#define att_debug(_att, _format, _arg...) \ +#define DBG(_att, _format, _arg...) \ att_log(_att, BT_ATT_DEBUG, "%s:%s() " _format, __FILE__, __func__,\ ## _arg) -#define att_verbose(_att, _format, _arg...) \ +#define VERBOSE(_att, _format, _arg...) \ att_log(_att, BT_ATT_DEBUG_VERBOSE, "%s:%s() " _format, __FILE__, \ __func__, ## _arg) @@ -359,7 +359,7 @@ static bool encode_pdu(struct bt_att *att, struct att_send_op *op, sign_cnt, &((uint8_t *) op->pdu)[1 + length]))) return true; - att_debug(att, "ATT unable to generate signature"); + DBG(att, "ATT unable to generate signature"); fail: free(op->pdu); @@ -488,7 +488,7 @@ static bool timeout_cb(void *user_data) if (!op) return false; - att_debug(att, "(chan %p) Operation timed out: 0x%02x", chan, + DBG(att, "(chan %p) Operation timed out: 0x%02x", chan, op->opcode); if (att->timeout_callback) @@ -524,11 +524,11 @@ static ssize_t bt_att_chan_write(struct bt_att_chan *chan, uint8_t opcode, iov.iov_base = (void *) pdu; iov.iov_len = len; - att_verbose(att, "(chan %p) ATT op 0x%02x", chan, opcode); + VERBOSE(att, "(chan %p) ATT op 0x%02x", chan, opcode); ret = io_send(chan->io, &iov, 1); if (ret < 0) { - att_debug(att, "(chan %p) write failed: %s", chan, + DBG(att, "(chan %p) write failed: %s", chan, strerror(-ret)); return ret; } @@ -661,12 +661,12 @@ static bool disconnect_cb(struct io *io, void *user_data) len = sizeof(err); if (getsockopt(chan->fd, SOL_SOCKET, SO_ERROR, &err, &len) < 0) { - att_debug(att, "(chan %p) Failed to obtain disconnect " + DBG(att, "(chan %p) Failed to obtain disconnect " "error: %s", chan, strerror(errno)); err = 0; } - att_debug(att, "Channel %p disconnected: %s", chan, strerror(err)); + DBG(att, "Channel %p disconnected: %s", chan, strerror(err)); /* Dettach channel */ queue_remove(att->chans, chan); @@ -795,7 +795,7 @@ static bool handle_error_rsp(struct bt_att_chan *chan, uint8_t *pdu, op->timeout_id = 0; } - att_debug(att, "(chan %p) Retrying operation %p", chan, op); + DBG(att, "(chan %p) Retrying operation %p", chan, op); chan->pending_req = NULL; @@ -818,7 +818,7 @@ static void handle_rsp(struct bt_att_chan *chan, uint8_t opcode, uint8_t *pdu, * the bearer. */ if (!op) { - att_debug(att, "(chan %p) Received unexpected ATT response", + DBG(att, "(chan %p) Received unexpected ATT response", chan); io_shutdown(chan->io); return; @@ -850,7 +850,7 @@ static void handle_rsp(struct bt_att_chan *chan, uint8_t opcode, uint8_t *pdu, goto done; fail: - att_debug(att, "(chan %p) Failed to handle response PDU; opcode: " + DBG(att, "(chan %p) Failed to handle response PDU; opcode: " "0x%02x", chan, opcode); rsp_opcode = BT_ATT_OP_ERROR_RSP; @@ -875,7 +875,7 @@ static void handle_conf(struct bt_att_chan *chan, uint8_t *pdu, ssize_t pdu_len) * invalid. */ if (!op || pdu_len) { - att_debug(att, "(chan %p) Received unexpected/invalid ATT " + DBG(att, "(chan %p) Received unexpected/invalid ATT " "confirmation", chan); io_shutdown(chan->io); return; @@ -949,7 +949,7 @@ static bool handle_signed(struct bt_att *att, uint8_t *pdu, ssize_t pdu_len) return true; fail: - att_debug(att, "ATT failed to verify signature: 0x%02x", opcode); + DBG(att, "ATT failed to verify signature: 0x%02x", opcode); return false; } @@ -1032,7 +1032,7 @@ static bool can_read_data(struct io *io, void *user_data) if (bytes_read < 0) return false; - att_verbose(att, "(chan %p) ATT received: %zd", chan, bytes_read); + VERBOSE(att, "(chan %p) ATT received: %zd", chan, bytes_read); att_hexdump(att, '>', chan->buf, bytes_read); @@ -1047,12 +1047,12 @@ static bool can_read_data(struct io *io, void *user_data) /* Act on the received PDU based on the opcode type */ switch (get_op_type(opcode)) { case ATT_OP_TYPE_RSP: - att_verbose(att, "(chan %p) ATT response received: 0x%02x", + VERBOSE(att, "(chan %p) ATT response received: 0x%02x", chan, opcode); handle_rsp(chan, opcode, pdu + 1, bytes_read - 1); break; case ATT_OP_TYPE_CONF: - att_verbose(att, "(chan %p) ATT confirmation received: 0x%02x", + VERBOSE(att, "(chan %p) ATT confirmation received: 0x%02x", chan, opcode); handle_conf(chan, pdu + 1, bytes_read - 1); break; @@ -1063,7 +1063,7 @@ static bool can_read_data(struct io *io, void *user_data) * promptly notify the upper layer via disconnect handlers. */ if (chan->in_req) { - att_debug(att, "(chan %p) Received request while " + DBG(att, "(chan %p) Received request while " "another is pending: 0x%02x", chan, opcode); io_shutdown(chan->io); @@ -1083,7 +1083,7 @@ static bool can_read_data(struct io *io, void *user_data) /* For all other opcodes notify the upper layer of the PDU and * let them act on it. */ - att_debug(att, "(chan %p) ATT PDU received: 0x%02x", chan, + DBG(att, "(chan %p) ATT PDU received: 0x%02x", chan, opcode); handle_notify(chan, pdu, bytes_read); break; @@ -1237,7 +1237,7 @@ static void bt_att_attach_chan(struct bt_att *att, struct bt_att_chan *chan) io_set_close_on_destroy(chan->io, att->close_on_unref); - att_debug(att, "Channel %p attached", chan); + DBG(att, "Channel %p attached", chan); wakeup_chan_writer(chan, NULL); } From patchwork Wed Mar 23 00:06:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 554672 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23D82C433FE for ; Wed, 23 Mar 2022 00:07:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240880AbiCWAIc (ORCPT ); Tue, 22 Mar 2022 20:08:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240875AbiCWAIa (ORCPT ); Tue, 22 Mar 2022 20:08:30 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E63AF6F480 for ; Tue, 22 Mar 2022 17:07:01 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id l4-20020a17090a49c400b001c6840df4a3so192207pjm.0 for ; Tue, 22 Mar 2022 17:07:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZdXcpJ++BFmfknFeg44qJ8tEEL3KH7uJgQPggfHVUP8=; b=PueIhsT8DkDqPL4PUbAHKBe+ToxqDSQ0w22yAREsuYCcmD7oocTIXQCX/JwO7Hm/el mwmOp91oo48xjrd+xSrUzq8Css2I/pQnV1gzp5vlUs2RWGH9P9fmxlUUs6RtA3I57VI4 tzvAGG7qvLgZIuumYNMm7+DVSYwqkpWdmh/rUIe7toAJsQyC7D7XOTks0ThvfEEuJQMf AMCfolSWRYt1JnjrEjREyblLRoCmtk3H8R268lOi8tWBgX7/Q9v+vlzqsUh72fPjUvXm qUfs+ezPKtZMuI2gMKmA8tbo4nro9svg6ghPTBuz3qkdsGLEKbkMw8uyCQqxnsldCyAg o0IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZdXcpJ++BFmfknFeg44qJ8tEEL3KH7uJgQPggfHVUP8=; b=jOhSLE5UEczrWw2zz64zbe+lmW7wpYtmDICs62aVQ+xGvSd8DZAWpaPVEXPKBD8EiA TXX8KWnbC2oTPV+wEF36N3DUVWA56m43GmWzW8qhefki1pJD34nmImgDKqB8q2xChdDu Q5qLHQXklweUAsecMryiBj7RBQG2zIcfMqUhcyE7OE8uRYBcOGm19sXGqdgDIfMsL+4w fl6srKvtvDhHZUSLiG2Jw80/CT61KHiP6XjYzMAxr+MDhAWYINEU5+qPoI+aPJgBjQQS IajRswpNb9YxxaSNOMXaP9kxlrQTx+okl3zBrgFdHUVefCYRr0Z5L8tz7A4Gq8i1cQQS w8rQ== X-Gm-Message-State: AOAM532qywLyAeP+wrxRX9iQwnZzZIWS/dIWv17ZwBp6xU8UNfNaXkJ5 5YbzHkTDGcU827IDfRapSAVPUOqJPXE= X-Google-Smtp-Source: ABdhPJx0uQWLnz1s/ynIcF1nc+a2OSvDy3LlgBgnSwid7jd3nZouPDUlIAbxExzI7TtCkfebFjKWcg== X-Received: by 2002:a17:90b:4f4e:b0:1bf:88f6:e5b5 with SMTP id pj14-20020a17090b4f4e00b001bf88f6e5b5mr8137288pjb.47.1647994021192; Tue, 22 Mar 2022 17:07:01 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id bx22-20020a056a00429600b004fa936a64b0sm10098423pfb.196.2022.03.22.17.07.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 17:07:00 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 9/9] device: Don't use DBG in gatt_debug Date: Tue, 22 Mar 2022 17:06:54 -0700 Message-Id: <20220323000654.3157833-9-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323000654.3157833-1-luiz.dentz@gmail.com> References: <20220323000654.3157833-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz gatt_debug callback is used to print debug strings from bt_att which includes the file and function names so using DBG would add yet another set of file and function prefixes which makes the logs confusing. --- src/device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/device.c b/src/device.c index 3992f9a0c..860155b6e 100644 --- a/src/device.c +++ b/src/device.c @@ -5545,7 +5545,8 @@ static void gatt_client_service_changed(uint16_t start_handle, static void gatt_debug(const char *str, void *user_data) { - DBG("%s", str); + if (DBG_IS_ENABLED()) + btd_debug(0xffff, "%s", str); } static void gatt_client_init(struct btd_device *device)