From patchwork Fri Jul 7 22:44:31 2023 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: 13305399 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 05D4FEB64D9 for ; Fri, 7 Jul 2023 22:44:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229629AbjGGWok (ORCPT ); Fri, 7 Jul 2023 18:44:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjGGWoj (ORCPT ); Fri, 7 Jul 2023 18:44:39 -0400 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C44310C for ; Fri, 7 Jul 2023 15:44:38 -0700 (PDT) Received: by mail-qv1-xf29.google.com with SMTP id 6a1803df08f44-635eb3a1d93so16935506d6.1 for ; Fri, 07 Jul 2023 15:44:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688769876; x=1691361876; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=X9w9UJ+qBqEaJm9FE++i1BQ1SA/D9TEIP9yW0WOBcmo=; b=jWJyURyyU4BmURbLNXVLKYTUBkDoAHaxfkyXRyCWBcAsYbACFdIRJ0LPGLs+jAdKYp E6yDXqcrL3/4rrYvBL0egz/Jg4H5wsQIP00mXSTwBi4+2Do5Hv5xsdAhumESOVJ+hUsU ILKiU/9eo/GDy2bZLcHrZUxD0A97b3TQJnVCaDRQjUpl+0GwZJow23D901FbSeZA8MbW /h7jplJNLBc1GLRCASe4yEHehpZeuO+mZvrRmdsme45LjA0DQ5O5VHgpnKEWitArI3vV qv2aYc8/K7PVxmDG/Afe9UQSc+vg1oN2mxZqDPC1PyzTTltk6oeYBXH10L3ER0BMm/gD gCqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688769876; x=1691361876; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=X9w9UJ+qBqEaJm9FE++i1BQ1SA/D9TEIP9yW0WOBcmo=; b=AwUI6S+foW5eJaeBDXaxe2U6HsH+aIHQoFCFigS6lECrPVUWIEIA+sD+D60HCkChP4 rWbXa7vt9t+U9aOKMsz7QkPucFQr1zvicE+SOxuE10nUkPva/sPTE6ITiX5vndIG3wRK cE+6Sh8hDsYyFHxg6JxZDYaAkodvYTnd2MF28YfaQqUCqh+Oiz0G1Ctgmyw4eT1P05t0 i4f1HE29dNWY/T7PHeY851NFeEh0TsrS7r2VPsqBK1WVcBzw6B4ELtfxu6TWaQ0Gqo7j G07A5JCPJihSFRi1+SV/PSu+kJTmvyPvyTokHRx5DG1O92D/MH+OwEfk4m8mJdIIdfwv Qz3Q== X-Gm-Message-State: ABy/qLbKwkicBqk+aVhdXDB8drVFYZL2gg5520I8UDcTras4AIHcS5Xi 9JMpSdFzXfYhD6VFxI7RlEx6MeDGG/8= X-Google-Smtp-Source: APBJJlHlGTtO+Rxi3e+yQZTbC7AfV1Do08UEFkdUD/A6NSr13/L5YT2xhqW7efLFa6mlPcStlwZG4w== X-Received: by 2002:a0c:cb8e:0:b0:636:14d4:4450 with SMTP id p14-20020a0ccb8e000000b0063614d44450mr5549427qvk.3.1688769876462; Fri, 07 Jul 2023 15:44:36 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id z28-20020a05620a101c00b0076730d0b0b9sm2274482qkj.14.2023.07.07.15.44.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 15:44:35 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 1/4] mgmt-tester: Fix tests that consider 31 bytes the max adv lenght Date: Fri, 7 Jul 2023 15:44:31 -0700 Message-Id: <20230707224434.677627-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This fixes a couple of tests that consider 31 bytes the max advertising length since in case of extended advertising that number is actually 251. --- tools/mgmt-tester.c | 71 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c index aec91fb41d3b..7dfd1b0c747d 100644 --- a/tools/mgmt-tester.c +++ b/tools/mgmt-tester.c @@ -5904,8 +5904,8 @@ static const char ext_adv_hci_params_valid[] = { static const char ext_adv_params_mgmt_rsp_valid_50[] = { 0x01, /* instance */ 0x00, /* tx_power defaults to 0 on BT5 platform*/ - 0x1f, /* max_adv_data_len */ - 0x1f, /* max_scan_rsp_len */ + 0xfb, /* max_adv_data_len */ + 0xfb, /* max_scan_rsp_len */ }; static const char ext_adv_params_mgmt_rsp_valid[] = { @@ -7725,6 +7725,23 @@ static const uint8_t add_advertising_param_scrsp_data_only_too_long[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; @@ -7778,6 +7795,29 @@ static const uint8_t add_advertising_param_scrsp_appear_data_too_long[] = { /* scan rsp data: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; @@ -7991,6 +8031,29 @@ static const uint8_t add_advertising_param_name_data_inv[] = { /* adv data: */ /* scan rsp data: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -8084,8 +8147,8 @@ static const struct generic_data set_appearance_success = { static const uint8_t read_adv_features_rsp_3[] = { 0xff, 0xff, 0x01, 0x00, /* supported flags */ - 0x1f, /* max_adv_data_len */ - 0x1f, /* max_scan_rsp_len */ + 0xfb, /* max_adv_data_len */ + 0xfb, /* max_scan_rsp_len */ 0x03, /* max_instances */ 0x00, /* num_instances */ }; From patchwork Fri Jul 7 22:44:32 2023 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: 13305400 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 731CCC0015E for ; Fri, 7 Jul 2023 22:44:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229643AbjGGWom (ORCPT ); Fri, 7 Jul 2023 18:44:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjGGWol (ORCPT ); Fri, 7 Jul 2023 18:44:41 -0400 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C21EAF for ; Fri, 7 Jul 2023 15:44:39 -0700 (PDT) Received: by mail-qv1-xf36.google.com with SMTP id 6a1803df08f44-635d9e0aa6dso16927136d6.1 for ; Fri, 07 Jul 2023 15:44:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688769878; x=1691361878; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=hpLSwl04snW1yWSJjZV1KQKdbZR59341rse1foBpb18=; b=ia/6mXPTFytRQ5xbo/j1hWAFP/BrcYlLhBAkovWUaE2yWV4BeRqflUXIBYecfOJw+v oW3D6/e5wHo7Xfe5aHgJPky/mh36afSvJDG8Yx8/1KOyNnsNp9Xp9vmf1JGGHfGput07 q4U84dOuk6lZ87OoMSi40KsG77qNoJuA7wGPTuq8miahwP9FcoJjRPNpE8JvGPie5huZ AA6uBhd/GyL8mfRZUrRU1dGlbDRUhoZfO/5GizazGwBt21okmwm2KSzbet4v/jjUL/zN I+cx1AN3yIo/6hKTmQ3tO+K1+hk2cib2OKKvyJ3b7b5dsYCq78Ip+fY5aia+4nzhQGnE Xt1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688769878; x=1691361878; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hpLSwl04snW1yWSJjZV1KQKdbZR59341rse1foBpb18=; b=RUNBWRDfZBIgF/G4Esc4ikiqQWkvPi79FxLjrUGMFf2t5K5DKm+xV6MhRf6I3YfnxA utUnazHGL5wMiguZEPS5h0wCCx980JDQCJ1bkb74jL/vc7LFLzDNLrWJ1+hD5ukkVtYj VHV6mCeDEZrs4OkS7JXYVEhGorlJSUdcYw6cUl468HgtN0nf8HTv+xdVN4PVi4eKmYxu i2w8P1iP1QaM3nW1y+Kse528J4jVld3WsSq09BS+k+EabPlf+Fmbj3uvW6Sj6nyRv4lX TnQ/FGAeEcHSYpOVqqXmyxJn7VJZ4CngnOgl/ZEURU+2QmryJ6PucDWJQGzEVBKpChip gL9A== X-Gm-Message-State: ABy/qLYCZIaqlH09fIds9L1DJJKhh1lFgfR/Xj/LeqVGnet5MpMLj3C1 toNWkcPPzgfALq8OSNq7A2hp+cr7OSI= X-Google-Smtp-Source: APBJJlHjE7mKlpCmbZ0RzFdnA2DZj/yox/lOzZxm72Exvfmjl8mQUAETJZtW1jm8O7H2bN/tH/lqyA== X-Received: by 2002:a0c:e449:0:b0:635:dd9a:ade4 with SMTP id d9-20020a0ce449000000b00635dd9aade4mr6134961qvm.16.1688769877957; Fri, 07 Jul 2023 15:44:37 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id z28-20020a05620a101c00b0076730d0b0b9sm2274482qkj.14.2023.07.07.15.44.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 15:44:37 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 2/4] shared/ad: Fix hardcoding maximum data length Date: Fri, 7 Jul 2023 15:44:32 -0700 Message-Id: <20230707224434.677627-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230707224434.677627-1-luiz.dentz@gmail.com> References: <20230707224434.677627-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 Instances shall not assume BT_AD_MAX_DATA_LEN is always the maximum length as they could be used with EA which supports bigger length. --- src/shared/ad.c | 56 ++++++++++++++++++++++++++++++------------------- src/shared/ad.h | 2 ++ 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/shared/ad.c b/src/shared/ad.c index 7350aa206d1e..8b3fde2b1dcd 100644 --- a/src/shared/ad.c +++ b/src/shared/ad.c @@ -22,6 +22,7 @@ struct bt_ad { int ref_count; + uint8_t max_len; char *name; uint16_t appearance; struct queue *service_uuids; @@ -42,6 +43,7 @@ struct bt_ad *bt_ad_new(void) struct bt_ad *ad; ad = new0(struct bt_ad, 1); + ad->max_len = BT_AD_MAX_DATA_LEN; ad->service_uuids = queue_new(); ad->manufacturer_data = queue_new(); ad->solicit_uuids = queue_new(); @@ -52,6 +54,16 @@ struct bt_ad *bt_ad_new(void) return bt_ad_ref(ad); } +bool bt_ad_set_max_len(struct bt_ad *ad, uint8_t len) +{ + if (!ad || len < BT_AD_MAX_DATA_LEN) + return false; + + ad->max_len = len; + + return true; +} + static bool ad_replace_data(struct bt_ad *ad, uint8_t type, const void *data, size_t len); @@ -298,17 +310,17 @@ static size_t uuid_data_length(struct queue *uuid_data) return length; } -static size_t name_length(const char *name, size_t *pos) +static size_t name_length(struct bt_ad *ad, size_t *pos) { size_t len; - if (!name) + if (!ad->name) return 0; - len = 2 + strlen(name); + len = 2 + strlen(ad->name); - if (len > BT_AD_MAX_DATA_LEN - *pos) - len = BT_AD_MAX_DATA_LEN - *pos; + if (len > ad->max_len - (*pos)) + len = ad->max_len - (*pos); return len; } @@ -343,7 +355,7 @@ static size_t calculate_length(struct bt_ad *ad) length += uuid_data_length(ad->service_data); - length += name_length(ad->name, &length); + length += name_length(ad, &length); length += ad->appearance != UINT16_MAX ? 4 : 0; @@ -467,36 +479,36 @@ static void serialize_service_data(struct queue *service_data, uint8_t *buf, } } -static void serialize_name(const char *name, uint8_t *buf, uint8_t *pos) +static void serialize_name(struct bt_ad *ad, uint8_t *buf, uint8_t *pos) { int len; uint8_t type = BT_AD_NAME_COMPLETE; - if (!name) + if (!ad->name) return; - len = strlen(name); - if (len > BT_AD_MAX_DATA_LEN - (*pos + 2)) { + len = strlen(ad->name); + if (len > ad->max_len - (*pos + 2)) { type = BT_AD_NAME_SHORT; - len = BT_AD_MAX_DATA_LEN - (*pos + 2); + len = ad->max_len - (*pos + 2); } buf[(*pos)++] = len + 1; buf[(*pos)++] = type; - memcpy(buf + *pos, name, len); + memcpy(buf + *pos, ad->name, len); *pos += len; } -static void serialize_appearance(uint16_t value, uint8_t *buf, uint8_t *pos) +static void serialize_appearance(struct bt_ad *ad, uint8_t *buf, uint8_t *pos) { - if (value == UINT16_MAX) + if (ad->appearance == UINT16_MAX) return; - buf[(*pos)++] = sizeof(value) + 1; + buf[(*pos)++] = sizeof(ad->appearance) + 1; buf[(*pos)++] = BT_AD_GAP_APPEARANCE; - bt_put_le16(value, buf + (*pos)); + bt_put_le16(ad->appearance, buf + (*pos)); *pos += 2; } @@ -528,7 +540,7 @@ uint8_t *bt_ad_generate(struct bt_ad *ad, size_t *length) *length = calculate_length(ad); - if (*length > BT_AD_MAX_DATA_LEN) + if (*length > ad->max_len) return NULL; adv_data = malloc0(*length); @@ -543,9 +555,9 @@ uint8_t *bt_ad_generate(struct bt_ad *ad, size_t *length) serialize_service_data(ad->service_data, adv_data, &pos); - serialize_name(ad->name, adv_data, &pos); + serialize_name(ad, adv_data, &pos); - serialize_appearance(ad->appearance, adv_data, &pos); + serialize_appearance(ad, adv_data, &pos); serialize_data(ad->data, adv_data, &pos); @@ -653,7 +665,7 @@ bool bt_ad_add_manufacturer_data(struct bt_ad *ad, uint16_t manufacturer_id, if (!ad) return false; - if (len > (BT_AD_MAX_DATA_LEN - 2 - sizeof(uint16_t))) + if (len > (ad->max_len - 2 - sizeof(uint16_t))) return false; new_data = queue_find(ad->manufacturer_data, manufacturer_id_data_match, @@ -790,7 +802,7 @@ bool bt_ad_add_service_data(struct bt_ad *ad, const bt_uuid_t *uuid, void *data, if (!ad) return false; - if (len > (BT_AD_MAX_DATA_LEN - 2 - (size_t)bt_uuid_len(uuid))) + if (len > (ad->max_len - 2 - (size_t)bt_uuid_len(uuid))) return false; new_data = queue_find(ad->service_data, service_uuid_match, uuid); @@ -1009,7 +1021,7 @@ bool bt_ad_add_data(struct bt_ad *ad, uint8_t type, void *data, size_t len) if (!ad) return false; - if (len > (BT_AD_MAX_DATA_LEN - 2)) + if (len > (size_t)(ad->max_len - 2)) return false; for (i = 0; i < sizeof(type_reject_list); i++) { diff --git a/src/shared/ad.h b/src/shared/ad.h index b100a6796109..93ba1b6cfa0b 100644 --- a/src/shared/ad.h +++ b/src/shared/ad.h @@ -98,6 +98,8 @@ struct bt_ad_pattern { struct bt_ad *bt_ad_new(void); +bool bt_ad_set_max_len(struct bt_ad *ad, uint8_t len); + struct bt_ad *bt_ad_new_with_data(size_t len, const uint8_t *data); struct bt_ad *bt_ad_ref(struct bt_ad *ad); From patchwork Fri Jul 7 22:44:33 2023 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: 13305401 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 573FAC001DC for ; Fri, 7 Jul 2023 22:44:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbjGGWom (ORCPT ); Fri, 7 Jul 2023 18:44:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229914AbjGGWom (ORCPT ); Fri, 7 Jul 2023 18:44:42 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4298D10C for ; Fri, 7 Jul 2023 15:44:41 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-76758b855edso174677285a.0 for ; Fri, 07 Jul 2023 15:44:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688769880; x=1691361880; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ADvqDfko4egt573z7+F2x034ETB5fF2C/fp4gxT2McM=; b=Ey64wEw+8/SkM6wySDpMvjvtqMvc6IVrKOyVrWQpB9cYfeBuHU7IPCS2Or6O8TKtEH Prcvlek8eYIyPIbTdRmSLIPd+Sw0sVZevaieNeZpRo7ngF2H+LSqH/H2iyvQrd6kvSmS R2GZH+ODW+pJ+FCWIDu1U2kvX2gW700vWENis/XEcz27jmiqZZp0rbODSJPnw1qJ4DOI QL5Mx06w3LOsYF1nJIJrqiz18qXNqBBv2IpMs3LW5+zcb6zVAmefbwvCPh1KZSdIx3gK usQtCjlWT1jy5j1aqWtCQP2cdslQBGZXBK79iNjcHpRg3YmLR1q0l5H2bzajNtW/uJWa iJow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688769880; x=1691361880; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ADvqDfko4egt573z7+F2x034ETB5fF2C/fp4gxT2McM=; b=XbN6R1Nszu5ulr6TvGs6VkFPsiPAGapucYTQEgPSPNfpSxYRRcErwZeqh63aliriex 7S2rRTOHPbpROFGDEpCoVC3VuZnUZ3I6BvniNRigvk6UBAkgQVkh1z3+b92yuO6fanve j6AZxRfVKRx9PkSm/B6xT+SfI2yTjtqwI43zcDRBfDP8LiIoRAoKP+Q8yR41facjc9RC Jda1XxzDLotKPcl9xpro5EY6+Er8xsrtKGrH2zkBttpnx83r9LihlOf/xWi4v18MwbXc 45HGTi1TOsIVQEHpGAOmZuyZbwd7Wonn6PqcKmr5wGNjuV88A/ayCgDHSX3iYIcxvLqj SajQ== X-Gm-Message-State: ABy/qLZ6OMvgaVFTV0F7PXOm5NMu38mIp5ACs/tw5u7WkJdvXOJVo1Rg bIADKDN88Ej4L99vJUzkwdPCpR8npNo= X-Google-Smtp-Source: APBJJlE9AAozS8/HYByK/JlggCDlav7mkaoj1LqbWOtS7o8yp2ZqxkQidY+JEF/zRK+2WzlrtD1Dzg== X-Received: by 2002:a05:620a:f03:b0:765:ac1b:9218 with SMTP id v3-20020a05620a0f0300b00765ac1b9218mr13711855qkl.22.1688769879776; Fri, 07 Jul 2023 15:44:39 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id z28-20020a05620a101c00b0076730d0b0b9sm2274482qkj.14.2023.07.07.15.44.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 15:44:39 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 3/4] advertising: Use bt_ad_set_max_len Date: Fri, 7 Jul 2023 15:44:33 -0700 Message-Id: <20230707224434.677627-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230707224434.677627-1-luiz.dentz@gmail.com> References: <20230707224434.677627-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_ad_set_max_len to properly set the maximum data length of the bt_ad instances based on what the kernel returns. --- src/advertising.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/advertising.c b/src/advertising.c index 0dceb14c3be4..6332ec8f9222 100644 --- a/src/advertising.c +++ b/src/advertising.c @@ -1556,10 +1556,14 @@ static struct btd_adv_client *client_create(struct btd_adv_manager *manager, if (!client->data) goto fail; + bt_ad_set_max_len(client->data, manager->max_adv_len); + client->scan = bt_ad_new(); if (!client->scan) goto fail; + bt_ad_set_max_len(client->scan, manager->max_scan_rsp_len); + client->manager = manager; client->appearance = UINT16_MAX; client->tx_power = ADV_TX_POWER_NO_PREFERENCE; From patchwork Fri Jul 7 22:44:34 2023 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: 13305402 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 432E2EB64D9 for ; Fri, 7 Jul 2023 22:44:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230134AbjGGWoo (ORCPT ); Fri, 7 Jul 2023 18:44:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229914AbjGGWon (ORCPT ); Fri, 7 Jul 2023 18:44:43 -0400 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DEAFAF for ; Fri, 7 Jul 2023 15:44:42 -0700 (PDT) Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-7659db6339eso121742885a.1 for ; Fri, 07 Jul 2023 15:44:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688769881; x=1691361881; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=dIvf/Hcd2SdfnTN2hhITh3CzA7mpuuX9g5aHh7kP08g=; b=okzUbMwxq3KpeBm9dqgFPB8ksGMLzJHrPNzV8jNI39Oc5NnQ3y0cipFD6yJZacVEY6 plP+6uc3DR4WCzxc/q9mq9MUD0IQ9YbjOBis/W8iPTPP7ZDSm8rlyi/8oFbmFLUUf6WJ 0g6VafAoKapxJEu1J/teoPWzwLBe7K2qJMSJg94SklxAkC0QsxyRn2ZR/mCqPGNEGgLi Bn+9Pxti1IUtkS7LnHFnVh/BRKtaluy8YEfqN5JZqXcP/EBj9VYxxtzoCkG2xUmlWme2 L7CxkjFGhzlyxU8ds+uQE1lLjYnt63EVZJf+3tv9icpSHWgg8ygtoGHmnzx8G9wxrG+w kfkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688769881; x=1691361881; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dIvf/Hcd2SdfnTN2hhITh3CzA7mpuuX9g5aHh7kP08g=; b=T7wyiEk4f+i7WzNIiG8INfdfyJN794RdVWZ3LQA5Ynvd29OllePI+cei8yf6svrDUk Bx5AkFIvx+wf/Fc28y9S+C1qEfUk9DwXCdV5Ks+U0e4nrq/xy6WmR7krnMvhIDhaGjQ3 R0YY9dN8wRJUE+LaVetj8H6bBDqmjdFYURznDeou/BL+j8VXPO2oTQLc8QpYV+uIoRC+ X7sDw3Z338dY0eabDA8tb3UJc523ZEjUA4/bqe+LmSi70BpjEZHDkkUaM8lKCgNjfmPi 16Td0wpOkIElYOeAh+dCPCJMP975eIYlPwyUpAwjutg4IR1X7vAVO5otzdGMYpS5qO4V fZJA== X-Gm-Message-State: ABy/qLbjLleq5QyMPYkg12rciYlUVouljQIfQh4N4fLZcNoYwmb2cdNz tg3pkAccPGxaj+5Mv57kzjygYVO2Fy0= X-Google-Smtp-Source: APBJJlHqyKsyhKY78sxG7gbfV295RlgbTEHEy3gpC3sKt/Y5IuTRvc6Cgwhq3p3cXePcFeUcPZOmVA== X-Received: by 2002:a05:620a:45ac:b0:75d:49e6:26c0 with SMTP id bp44-20020a05620a45ac00b0075d49e626c0mr7106076qkb.5.1688769881166; Fri, 07 Jul 2023 15:44:41 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id z28-20020a05620a101c00b0076730d0b0b9sm2274482qkj.14.2023.07.07.15.44.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 15:44:40 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 4/4] client/advetising: Allow use of EA data length Date: Fri, 7 Jul 2023 15:44:34 -0700 Message-Id: <20230707224434.677627-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230707224434.677627-1-luiz.dentz@gmail.com> References: <20230707224434.677627-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 The code was supporting a maximum of 25 bytes (31 - 6) to be entered as advertising data, but in case of EA is used that allows up to 245 bytes (251 - 6) to be entered. --- client/advertising.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/advertising.c b/client/advertising.c index 24852d93d1ec..a7474d6a2984 100644 --- a/client/advertising.c +++ b/client/advertising.c @@ -28,7 +28,7 @@ #define AD_IFACE "org.bluez.LEAdvertisement1" struct ad_data { - uint8_t data[25]; + uint8_t data[245]; uint8_t len; };