From patchwork Fri Jan 8 21:15:10 2021 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: 12007607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19619C433DB for ; Fri, 8 Jan 2021 21:15:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D110423A80 for ; Fri, 8 Jan 2021 21:15:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729515AbhAHVP4 (ORCPT ); Fri, 8 Jan 2021 16:15:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727325AbhAHVPz (ORCPT ); Fri, 8 Jan 2021 16:15:55 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65876C061757 for ; Fri, 8 Jan 2021 13:15:15 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id v1so4332259pjr.2 for ; Fri, 08 Jan 2021 13:15:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ylsb5NyQ3oFVpAQCIHeIiDlXNUKeqObj9MTroL10KcE=; b=WiQa6uLaEAImOKmyuyDkdvQ877KCudHQbVvHf1T2Zca+yH1uQmCceYKH2ba9F3N11G CX8EOw2ZK6BU0Gz0lgwkgT1jw9Us5yHg+w41SwS2sRs3e53T1nAW/JfxVQqgKiLujb18 sM2AxQOWdIycL5Lz1dIE4BoRSruZ5mecFfg/U5ee5bEDhvJmF/8lM5Txa4kj/6sxd57y uX3Evd+GSWE9NiXXkz+aEvSahZZM7sKNeO+GbKMTLk0ZegI05t+f5k3eprCDymI+aPQi saIJ3O90NQf8wnsVHTR5I3DF/g/c3Z0882q0QnLPC5dCNTb+PlmfPegWZWydyamn66uv ybCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ylsb5NyQ3oFVpAQCIHeIiDlXNUKeqObj9MTroL10KcE=; b=d8K74mRiisZnr+fpP0/Jogh0UucESoD2E+SxHQackjSNGeyRVDGJXhSwO3uhC0O1Ts x4GtkOJFaXeTmhzFEfzqf8IU1kDspnmyEn0kXLw1srxknwnBbVR6doogjyFVbibyBSJI 3PpjwMbohw8JdBse73428oRO0wN0974p0LxPhRb3XzDSZjTl/ajTTYmIs/ZtKlDy6xnW s/Q2rp4lkeSJJKDNatxeHx4YlO+86gl+C9BbRWAnPC6c4AKdHEtk6v8ZZMXxQAOgdZVS IVk7W6zuLHkllHUdSw1r7k2/G4yoJw0qHGcv9BFwN3bnpanTFCpASDgmDmkDm8KazpT3 zM0g== X-Gm-Message-State: AOAM5308/hzBpJ3dN3JmdlKDdh4FUKZSjBdiuuJAN4AUoLr/6/e8/6si ZwWoXIifGHGe5Wu6T3zEAnDsXzTfK5U= X-Google-Smtp-Source: ABdhPJwOsM4zWjcQej4XxaOUdbDnNZeZGHN1qm2MIoTWahGyUfo8cKZDKmr4m5NGcTisl1kfZtJ3mw== X-Received: by 2002:a17:902:ea94:b029:da:a547:b6a6 with SMTP id x20-20020a170902ea94b02900daa547b6a6mr5703029plb.78.1610140514709; Fri, 08 Jan 2021 13:15:14 -0800 (PST) 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 21sm9721699pfx.84.2021.01.08.13.15.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 13:15:14 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/4] util: Introduce util_debug_va Date: Fri, 8 Jan 2021 13:15:10 -0800 Message-Id: <20210108211513.5180-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This introduces util_debug_va which can take a va_list that enables callers to create wrapper functions if they need to. --- src/shared/util.c | 19 ++++++++++++++----- src/shared/util.h | 4 ++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/shared/util.c b/src/shared/util.c index 525302164..9c2054211 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -15,7 +15,6 @@ #define _GNU_SOURCE #include #include -#include #include #include #include @@ -42,20 +41,30 @@ void *btd_malloc(size_t size) return NULL; } +void util_debug_va(util_debug_func_t function, void *user_data, + const char *format, va_list va) +{ + char str[78]; + + if (!function || !format) + return; + + vsnprintf(str, sizeof(str), format, va); + + function(str, user_data); +} + void util_debug(util_debug_func_t function, void *user_data, const char *format, ...) { - char str[78]; va_list ap; if (!function || !format) return; va_start(ap, format); - vsnprintf(str, sizeof(str), format, ap); + util_debug_va(function, user_data, format, ap); va_end(ap); - - function(str, user_data); } void util_hexdump(const char dir, const unsigned char *buf, size_t len, diff --git a/src/shared/util.h b/src/shared/util.h index 6fb702797..d6de55885 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -89,6 +90,9 @@ void *btd_malloc(size_t size); typedef void (*util_debug_func_t)(const char *str, void *user_data); +void util_debug_va(util_debug_func_t function, void *user_data, + const char *format, va_list va); + void util_debug(util_debug_func_t function, void *user_data, const char *format, ...) __attribute__((format(printf, 3, 4))); From patchwork Fri Jan 8 21:15:11 2021 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: 12007609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E0A1C433E0 for ; Fri, 8 Jan 2021 21:15:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43E7D23A9B for ; Fri, 8 Jan 2021 21:15:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729602AbhAHVP6 (ORCPT ); Fri, 8 Jan 2021 16:15:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729535AbhAHVP5 (ORCPT ); Fri, 8 Jan 2021 16:15:57 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3A13C061786 for ; Fri, 8 Jan 2021 13:15:16 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id i7so8417269pgc.8 for ; Fri, 08 Jan 2021 13:15:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=yGO0/O9TdjJe02BtFsztUjYvEiNDX4bPcn9FA5513Ag=; b=HDdOu/hYRHGEw6l5RkqIdf/Sv2VLJVGZJlfzb2VU+GVqtoqRmLyJR4FsGaOQ8gMYg8 JFozEoIJw3SowUl7qZVoYi53dye50PrGWMnNUMp1EkZG+HYAobmeJjNaURO90xdlFx69 AnJX6QdALg0YsABiQKR5xqrSXDqQJN+oxhGc1ri/DVL1l+3OhXucib9VwDtNfwpSCGYr aLRmJAwaEj11b/dvlVzNu7QkU7uYNlympN4JPBf+Gjzh+ZgTzwSrtS1zLZdhnwGnlljH klDmSNLEUbbczrZDrIMdeaG35CwS32d2DYtadBQiwxsR3acxWQdJEX7Ufv+uLsBTH3sH P9vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yGO0/O9TdjJe02BtFsztUjYvEiNDX4bPcn9FA5513Ag=; b=PPkchra6F4Jor0uUoKV6C0Pv3hDZMqJWRVYbXxFCOayjl5osm4+iOSNNbovbH4rxCs z77N9bUAC4d58RWl5N9IVPOkC2p5pfUtOhFKRtJjbGiAw/ORvStvA3JE4fkoatO0Q4yq K/ujD7AqGcTdqjOitkjDvqou9inFyEJFKPAsrNsGkPSL1fv0D5AhzBGnKSn362HA+RRI JzvbQ0QDrvbfl5tDOBIKSFWw7v0BZTMjcXMf6lwLY6K/BASrcSKhpRv4lpYzOaTW9yHs DE6PMxvdUp8r8FZcD+0MDQxUQqnzHZcc3QaMFDrULkeniZEM5BU5OmHT6wbsUS12iu9j uYCQ== X-Gm-Message-State: AOAM530X3DZLx7xyjLLNAKbKcjCMcmERP3qV5/oxPHOj7ccpyU0WHR1f +Ll7Hnj+qkssxvBozQ3XwM+I/o4BnNc= X-Google-Smtp-Source: ABdhPJyE8DsAa55G/wctrZZLGVMjRsq5ubwmMPX+zzUunFl3nyPIJ76nJE4Abr5WwBywvemrcINQlQ== X-Received: by 2002:a63:c205:: with SMTP id b5mr8801191pgd.281.1610140516086; Fri, 08 Jan 2021 13:15:16 -0800 (PST) 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 21sm9721699pfx.84.2021.01.08.13.15.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 13:15:15 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/4] shared/att: Add debug level to bt_att_set_debug Date: Fri, 8 Jan 2021 13:15:11 -0800 Message-Id: <20210108211513.5180-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108211513.5180-1-luiz.dentz@gmail.com> References: <20210108211513.5180-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 creates different levels of debugging which can be passed to bt_att_set_debug as depending on the application it may not need to print everything which can pollute the logs quite a bit. --- src/shared/att.c | 108 +++++++++++++++++++++++------------------- src/shared/att.h | 9 +++- tools/btgatt-client.c | 3 +- tools/btgatt-server.c | 3 +- unit/test-gatt.c | 2 +- 5 files changed, 71 insertions(+), 54 deletions(-) diff --git a/src/shared/att.c b/src/shared/att.c index 429ba6696..ccc753c4e 100644 --- a/src/shared/att.c +++ b/src/shared/att.c @@ -77,6 +77,7 @@ struct bt_att { bt_att_destroy_func_t timeout_destroy; void *timeout_data; + uint8_t debug_level; bt_att_debug_func_t debug_callback; bt_att_destroy_func_t debug_destroy; void *debug_data; @@ -274,6 +275,34 @@ static bool match_disconn_id(const void *a, const void *b) return disconn->id == id; } +static void att_log(struct bt_att *att, uint8_t level, const char *format, + ...) +{ + va_list va; + + if (att->debug_level < level) + return; + + va_start(va, format); + util_debug_va(att->debug_callback, att->debug_data, format, va); + va_end(va); +} + +#define att_debug(_att, _format, _arg...) \ + att_log(_att, BT_ATT_DEBUG, _format, ## _arg) + +#define att_verbose(_att, _format, _arg...) \ + att_log(_att, BT_ATT_DEBUG_VERBOSE, _format, ## _arg) + +static void att_hexdump(struct bt_att *att, char dir, const void *data, + size_t len) +{ + if (att->debug_level < 2) + return; + + util_hexdump(dir, data, len, att->debug_callback, att->debug_data); +} + static bool encode_pdu(struct bt_att *att, struct att_send_op *op, const void *pdu, uint16_t length) { @@ -309,8 +338,7 @@ static bool encode_pdu(struct bt_att *att, struct att_send_op *op, sign_cnt, &((uint8_t *) op->pdu)[1 + length]))) return true; - util_debug(att->debug_callback, att->debug_data, - "ATT unable to generate signature"); + att_debug(att, "ATT unable to generate signature"); fail: free(op->pdu); @@ -432,9 +460,8 @@ static bool timeout_cb(void *user_data) if (!op) return false; - util_debug(att->debug_callback, att->debug_data, - "(chan %p) Operation timed out: 0x%02x", - chan, op->opcode); + att_debug(att, "(chan %p) Operation timed out: 0x%02x", chan, + op->opcode); if (att->timeout_callback) att->timeout_callback(op->id, op->opcode, att->timeout_data); @@ -469,20 +496,18 @@ static ssize_t bt_att_chan_write(struct bt_att_chan *chan, uint8_t opcode, iov.iov_base = (void *) pdu; iov.iov_len = len; - util_debug(att->debug_callback, att->debug_data, - "(chan %p) ATT op 0x%02x", - chan, opcode); + att_verbose(att, "(chan %p) ATT op 0x%02x", chan, opcode); ret = io_send(chan->io, &iov, 1); if (ret < 0) { - util_debug(att->debug_callback, att->debug_data, - "(chan %p) write failed: %s", - chan, strerror(-ret)); - + att_debug(att, "(chan %p) write failed: %s", chan, + strerror(-ret)); return ret; } - util_hexdump('<', pdu, ret, att->debug_callback, att->debug_data); + if (att->debug_level) + util_hexdump('<', pdu, ret, att->debug_callback, + att->debug_data); return ret; } @@ -608,15 +633,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) { - util_debug(chan->att->debug_callback, chan->att->debug_data, - "(chan %p) Failed to obtain disconnect" - " error: %s", chan, strerror(errno)); + att_debug(att, "(chan %p) Failed to obtain disconnect " + "error: %s", chan, strerror(errno)); err = 0; } - util_debug(chan->att->debug_callback, chan->att->debug_data, - "Channel %p disconnected: %s", - chan, strerror(err)); + att_debug(att, "Channel %p disconnected: %s", chan, strerror(err)); /* Dettach channel */ queue_remove(att->chans, chan); @@ -745,9 +767,7 @@ static bool handle_error_rsp(struct bt_att_chan *chan, uint8_t *pdu, op->timeout_id = 0; } - util_debug(att->debug_callback, att->debug_data, - "(chan %p) Retrying operation " - "%p", chan, op); + att_debug(att, "(chan %p) Retrying operation %p", chan, op); chan->pending_req = NULL; @@ -770,9 +790,8 @@ static void handle_rsp(struct bt_att_chan *chan, uint8_t opcode, uint8_t *pdu, * the bearer. */ if (!op) { - util_debug(att->debug_callback, att->debug_data, - "(chan %p) Received unexpected ATT " - "response", chan); + att_debug(att, "(chan %p) Received unexpected ATT response", + chan); io_shutdown(chan->io); return; } @@ -803,8 +822,7 @@ static void handle_rsp(struct bt_att_chan *chan, uint8_t opcode, uint8_t *pdu, goto done; fail: - util_debug(att->debug_callback, att->debug_data, - "(chan %p) Failed to handle response PDU; opcode: " + att_debug(att, "(chan %p) Failed to handle response PDU; opcode: " "0x%02x", chan, opcode); rsp_opcode = BT_ATT_OP_ERROR_RSP; @@ -829,8 +847,7 @@ static void handle_conf(struct bt_att_chan *chan, uint8_t *pdu, ssize_t pdu_len) * invalid. */ if (!op || pdu_len) { - util_debug(att->debug_callback, att->debug_data, - "(chan %p) Received unexpected/invalid ATT " + att_debug(att, "(chan %p) Received unexpected/invalid ATT " "confirmation", chan); io_shutdown(chan->io); return; @@ -904,8 +921,7 @@ static bool handle_signed(struct bt_att *att, uint8_t *pdu, ssize_t pdu_len) return true; fail: - util_debug(att->debug_callback, att->debug_data, - "ATT failed to verify signature: 0x%02x", opcode); + att_debug(att, "ATT failed to verify signature: 0x%02x", opcode); return false; } @@ -987,12 +1003,9 @@ static bool can_read_data(struct io *io, void *user_data) if (bytes_read < 0) return false; - util_debug(att->debug_callback, att->debug_data, - "(chan %p) ATT received: %zd", - chan, bytes_read); + att_verbose(att, "(chan %p) ATT received: %zd", chan, bytes_read); - util_hexdump('>', chan->buf, bytes_read, - att->debug_callback, att->debug_data); + att_hexdump(att, '>', chan->buf, bytes_read); if (bytes_read < ATT_MIN_PDU_LEN) return true; @@ -1005,14 +1018,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: - util_debug(att->debug_callback, att->debug_data, - "(chan %p) ATT response received: 0x%02x", + att_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: - util_debug(att->debug_callback, att->debug_data, - "(chan %p) ATT confirmation received: 0x%02x", + att_verbose(att, "(chan %p) ATT confirmation received: 0x%02x", chan, opcode); handle_conf(chan, pdu + 1, bytes_read - 1); break; @@ -1023,8 +1034,7 @@ static bool can_read_data(struct io *io, void *user_data) * promptly notify the upper layer via disconnect handlers. */ if (chan->in_req) { - util_debug(att->debug_callback, att->debug_data, - "(chan %p) Received request while " + att_debug(att, "(chan %p) Received request while " "another is pending: 0x%02x", chan, opcode); io_shutdown(chan->io); @@ -1044,9 +1054,8 @@ 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. */ - util_debug(att->debug_callback, att->debug_data, - "(chan %p) ATT PDU received: 0x%02x", - chan, opcode); + att_debug(att, "(chan %p) ATT PDU received: 0x%02x", chan, + opcode); handle_notify(chan, pdu, bytes_read); break; } @@ -1198,8 +1207,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); - util_debug(att->debug_callback, att->debug_data, "Channel %p attached", - chan); + att_debug(att, "Channel %p attached", chan); wakeup_chan_writer(chan, NULL); } @@ -1315,8 +1323,9 @@ int bt_att_get_channels(struct bt_att *att) return queue_length(att->chans); } -bool bt_att_set_debug(struct bt_att *att, bt_att_debug_func_t callback, - void *user_data, bt_att_destroy_func_t destroy) +bool bt_att_set_debug(struct bt_att *att, uint8_t level, + bt_att_debug_func_t callback, void *user_data, + bt_att_destroy_func_t destroy) { if (!att) return false; @@ -1324,6 +1333,7 @@ bool bt_att_set_debug(struct bt_att *att, bt_att_debug_func_t callback, if (att->debug_destroy) att->debug_destroy(att->debug_data); + att->debug_level = level; att->debug_callback = callback; att->debug_destroy = destroy; att->debug_data = user_data; diff --git a/src/shared/att.h b/src/shared/att.h index 1938fc724..03a450988 100644 --- a/src/shared/att.h +++ b/src/shared/att.h @@ -13,6 +13,10 @@ #include "src/shared/att-types.h" +#define BT_ATT_DEBUG 0x00 +#define BT_ATT_DEBUG_VERBOSE 0x01 +#define BT_ATT_DEBUG_HEXDUMP 0x02 + struct bt_att; struct bt_att_chan; @@ -41,8 +45,9 @@ typedef void (*bt_att_timeout_func_t)(unsigned int id, uint8_t opcode, typedef void (*bt_att_disconnect_func_t)(int err, void *user_data); typedef bool (*bt_att_counter_func_t)(uint32_t *sign_cnt, void *user_data); -bool bt_att_set_debug(struct bt_att *att, bt_att_debug_func_t callback, - void *user_data, bt_att_destroy_func_t destroy); +bool bt_att_set_debug(struct bt_att *att, uint8_t level, + bt_att_debug_func_t callback, void *user_data, + bt_att_destroy_func_t destroy); uint16_t bt_att_get_mtu(struct bt_att *att); bool bt_att_set_mtu(struct bt_att *att, uint16_t mtu); diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c index 523d6ec30..8c9365aa2 100644 --- a/tools/btgatt-client.c +++ b/tools/btgatt-client.c @@ -218,7 +218,8 @@ static struct client *client_create(int fd, uint16_t mtu) NULL, NULL); if (verbose) { - bt_att_set_debug(cli->att, att_debug_cb, "att: ", NULL); + bt_att_set_debug(cli->att, BT_ATT_DEBUG_VERBOSE, att_debug_cb, + "att: ", NULL); bt_gatt_client_set_debug(cli->gatt, gatt_debug_cb, "gatt: ", NULL); } diff --git a/tools/btgatt-server.c b/tools/btgatt-server.c index aa3448765..000145a3d 100644 --- a/tools/btgatt-server.c +++ b/tools/btgatt-server.c @@ -584,7 +584,8 @@ static struct server *server_create(int fd, uint16_t mtu, bool hr_visible) server->hr_visible = hr_visible; if (verbose) { - bt_att_set_debug(server->att, att_debug_cb, "att: ", NULL); + bt_att_set_debug(server->att, BT_ATT_DEBUG_VERBOSE, + att_debug_cb, "att: ", NULL); bt_gatt_server_set_debug(server->gatt, gatt_debug_cb, "server: ", NULL); } diff --git a/unit/test-gatt.c b/unit/test-gatt.c index 6a49210c5..4aa87d09c 100644 --- a/unit/test-gatt.c +++ b/unit/test-gatt.c @@ -658,7 +658,7 @@ static struct context *create_context(uint16_t mtu, gconstpointer data) switch (test_data->context_type) { case ATT: - bt_att_set_debug(context->att, print_debug, "bt_att:", NULL); + bt_att_set_debug(context->att, 1, print_debug, "bt_att:", NULL); bt_gatt_exchange_mtu(context->att, mtu, NULL, NULL, NULL); break; From patchwork Fri Jan 8 21:15:12 2021 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: 12007611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49731C433DB for ; Fri, 8 Jan 2021 21:16:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C8E923A9B for ; Fri, 8 Jan 2021 21:16:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729614AbhAHVP7 (ORCPT ); Fri, 8 Jan 2021 16:15:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729606AbhAHVP6 (ORCPT ); Fri, 8 Jan 2021 16:15:58 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C72E7C061793 for ; Fri, 8 Jan 2021 13:15:17 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id b5so6902804pjl.0 for ; Fri, 08 Jan 2021 13:15:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=JEXWlJdDePFBm/HsaJp0B5wQRXw/bAWWRY47hJSwmwk=; b=aVqkssl8SOQPvp8wTGTwTEDaW2fcPgFHKle6CEVwCykstkoauJBEK7EoGXcfqQgv08 qtKkj+5gYRDjprZA2V8Agj5QvPK/QeGBe7WKE73pyx7NqwGJp27fXd2FDFB7jk0qy8/N P+PnRiEKClnpqAjCl+DtyDvS+pMY45i+BXMU3fTVABO5dsFfg0WHsg7PQ/ecQ0CVqk+Y duAC6xS0LaencojiL63AVKZO4CFvs9T8c1rGCBEamnUAHvsBG3pWXpV5LYPyEAwKZHst /xxqeqphpfYPz9gjWsCCGwS6T5jXKhS+nBv/nV7Bq52KnxZE0+NWpfnm6TjWGDfY8+Gp 10ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JEXWlJdDePFBm/HsaJp0B5wQRXw/bAWWRY47hJSwmwk=; b=LhYpeFPGL6SduyY4JjThj4iayK4zcG0fll8GyCQTbDjAs9sQiS6BE2UXKC5HKO+0gY kz+2X+vpLzOZDRn9D+TMgz3Wipy2XK2YTNjwmW0iY1FpRDUtYeKjkMEmyreDNLuns2kS C2KXODbGvpk0t8KYepCiAwE3ZI3XroL85DPt6RXG0+XA/G/CxV6p08HDdcxEJmL+y/hE ZIiKmEkglD2b329LvTiuFKqodiU2DAYj3wIN3J/blMUn/KYK0PXwrn0z7fWDHRvMRDXj vLU/pzePgUnx/BLsw1yuiHu2GOzP2l/HNdLBBByas0qhPLBZEkeZNF5mCuQphs4lmDGL BCww== X-Gm-Message-State: AOAM530ebGffsFDBHZP8qPgV4maoDfJB4vxTj62mSxvmYLNKawAGCZvi XJj1ThKVAtkcsoeqO3/XO8/sjsayVsA= X-Google-Smtp-Source: ABdhPJyM1zlkQtHqgGeBjMPsTlB5iO5hsX68FOGD/oIFRuTWeA+ld2WLin+4iv88w6fpNOOiLa/U4Q== X-Received: by 2002:a17:902:6807:b029:db:f60f:52f7 with SMTP id h7-20020a1709026807b02900dbf60f52f7mr5752345plk.54.1610140517167; Fri, 08 Jan 2021 13:15:17 -0800 (PST) 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 21sm9721699pfx.84.2021.01.08.13.15.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 13:15:16 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 3/4] device: Enable ATT layer debugging Date: Fri, 8 Jan 2021 13:15:12 -0800 Message-Id: <20210108211513.5180-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108211513.5180-1-luiz.dentz@gmail.com> References: <20210108211513.5180-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 uses bt_att_set_debug to enable ATT debugging which is useful for detecting error such as an ATT transaction timing out. --- src/device.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/device.c b/src/device.c index 2e97876ec..fe885aa64 100644 --- a/src/device.c +++ b/src/device.c @@ -5336,6 +5336,8 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io) bt_att_ref(dev->att); + bt_att_set_debug(dev->att, BT_ATT_DEBUG, gatt_debug, NULL, NULL); + dev->att_disconn_id = bt_att_register_disconnect(dev->att, att_disconnected_cb, dev, NULL); bt_att_set_close_on_unref(dev->att, true); From patchwork Fri Jan 8 21:15:13 2021 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: 12007613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06A1AC433E9 for ; Fri, 8 Jan 2021 21:16:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B18E423A9B for ; Fri, 8 Jan 2021 21:16:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729616AbhAHVQA (ORCPT ); Fri, 8 Jan 2021 16:16:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729486AbhAHVP7 (ORCPT ); Fri, 8 Jan 2021 16:15:59 -0500 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEE37C061796 for ; Fri, 8 Jan 2021 13:15:18 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id c13so4338131pfi.12 for ; Fri, 08 Jan 2021 13:15:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=od4kyhO8B6Ups457tn7S8TzdwrA5OCwrTrq+s7sYrME=; b=GxdykE+DobF8eM8ACQxN9PmHumAZSVLOx9hWOAb2gns+cz5CLvfCZR/PXoHzJdjpxs oX/lxp1lRn9SriuKCwk3C5Jfb0xzeFkkbnh4L2lJlvLUN7imshrOjF4qgmFunahSNMtp rVLi6bjIYla+kpw6tMmbkUK+rWuVInyaFspPHTTjvEMd4t9OpwFswP4abjEbqmHTIu6R A/CjPYwud8j1ghxYAaHEvHPn1gWswHe0k6St7LtHYpOrtTv0ynEOwkK5wMpTcSwSxbwd v9LPQEYCSG+Jhk0K6HASUBNLOsmH/VSyzbSIEpxKXC9MT3yxMnflO2CUGMQcrum4nuVk PPdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=od4kyhO8B6Ups457tn7S8TzdwrA5OCwrTrq+s7sYrME=; b=qSQgAibaqfxWaotpNrovQ0SG1HnpXDoTo1HHZPwEBxABxxRbIgigfKrIuxIdOmgvo4 ulsgflRYReD+XYka0lh6qBgiR5dO/Fcz4pp9cLmfKGiieRJ1jay/QQCNcuHtUy9Ugd7b HVd2s/vRSWFdeJm9c1Q5X7kzKzu9oMnXA9OJMl6PH7k+7HHxfQ6c/Rmov9gGwjwDxQD8 7A1lUJOMENXHGpQ0ur1d0lA91QRJvz7mesxfNcAE25rmK1J9tlm1hnz/ii1rrEBsYe6r Dkg1l5EfZ6c9MW6diLr+OP0mPZgx+LUkWdYF46E4WpAYmerCB/qc4F3qPcOcxMr/XALr Q7/g== X-Gm-Message-State: AOAM530ul9vnk/1x/QZxD27v7kBF4qH1ThHRj/CiBCCIDbfcRgY/n5qZ ZkvATAxXlDkyGM0m1D7mYWON6g/j4xk= X-Google-Smtp-Source: ABdhPJzh6Umwc27pthbMvB82TT1WzZ1cnsD2FTgMhU2DmS4KbgYWrR4okhhuj9sTRFy/IG1IpEFk9Q== X-Received: by 2002:a63:4c09:: with SMTP id z9mr9102333pga.260.1610140518117; Fri, 08 Jan 2021 13:15:18 -0800 (PST) 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 21sm9721699pfx.84.2021.01.08.13.15.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 13:15:17 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 4/4] gatt: Fix assuming service changed has been subscribed Date: Fri, 8 Jan 2021 13:15:13 -0800 Message-Id: <20210108211513.5180-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108211513.5180-1-luiz.dentz@gmail.com> References: <20210108211513.5180-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 Unfortunately assuming service changed has been subscribed may cause indication to time out in some peripherals (Logitech M720 Triathlon, Mx Anywhere 2, Lenovo Mice N700, RAPOO BleMouse and Microsoft Designer Mouse) even though the expect actually mandates that the client responds with confirmation these peripherals just ignores it completely which leads them to be disconnected whenever bluetoothd is restarted or the system reboots. --- src/device.c | 11 ++--------- src/gatt-database.c | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/device.c b/src/device.c index fe885aa64..af13badfc 100644 --- a/src/device.c +++ b/src/device.c @@ -5831,18 +5831,11 @@ void device_load_svc_chng_ccc(struct btd_device *device, uint16_t *ccc_le, key_file = g_key_file_new(); g_key_file_load_from_file(key_file, filename, 0, NULL); - /* - * If there is no "ServiceChanged" section we may be loading data from - * old version which did not persist Service Changed CCC values. Let's - * check if we are bonded and assume indications were enabled by peer - * in such case - it should have done this anyway. - */ if (!g_key_file_has_group(key_file, "ServiceChanged")) { if (ccc_le) - *ccc_le = device->le_state.bonded ? 0x0002 : 0x0000; + *ccc_le = 0x0000; if (ccc_bredr) - *ccc_bredr = device->bredr_state.bonded ? - 0x0002 : 0x0000; + *ccc_bredr = 0x0000; g_key_file_free(key_file); return; } diff --git a/src/gatt-database.c b/src/gatt-database.c index b7d2bea1d..d99604826 100644 --- a/src/gatt-database.c +++ b/src/gatt-database.c @@ -333,7 +333,7 @@ static void att_disconnected(int err, void *user_data) handle = gatt_db_attribute_get_handle(state->db->svc_chngd_ccc); ccc = find_ccc_state(state, handle); - if (ccc) + if (ccc && ccc->value) device_store_svc_chng_ccc(device, state->bdaddr_type, ccc->value);