Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1017639ybt; Fri, 19 Jun 2020 21:45:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNuzxDd3533I6mWqIug4PEiVZD6m7vLM177QKCAvDklSNV+5DF81pumuMlUL+VjNqF5NrE X-Received: by 2002:a17:906:bcf3:: with SMTP id op19mr6475680ejb.208.1592628344077; Fri, 19 Jun 2020 21:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592628344; cv=none; d=google.com; s=arc-20160816; b=URTkrD9Qt777d5vlGlZf/Ncx9s3w6rZuho4wob4fGk1gLkNgzW8Xz613D4bfVJH8fK B8OXqupki/d8DQnroOZ7X7jzUbyCrNr7Zh4u9T1ikCq4LdbVx/lQSJ920eJ2h37DoaUv 2jM+hU83mS0XXDFGN5o7zLgqbXeO5ZkNtA4NXn1Jk3fMddQ7HNXVaizuFKli0JHcw3Di aU021Ds3RKepOGh4J0S2/b60g6iucfZ1gOyXSeOnk7BFFpeWO1E+UKcp6u8HrekX0sLF 0y5cUCE/wxeqXZK5Ro35nj+nmTUNBt0JL3Bsb8Uox46eBLJiHlg0BfaJVTkOBDbHqcYW 61Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=pi9mUfjZECkUpQIGYMQo/6NQ4L6ym2cDBq1A7qT/6+c=; b=oAdJ9gNYLKRjfF91CNERV9xHao1GMWWwo9tkXsuwOyDhMk6dSTlyCGhQ3o2Wbk/xFS edvnJZPYCunESNnWGqKPv4syWf/o3+HiGFx8S0Nq3/MW3o6v7PHkdKJwHp7436CX/ViP 0JGekGjDT9id6hz9jXejB7hN3h4Uacp61VPTr3azuuLXN5bbz1TMzJ/Y3+HYOrFAUVzJ zxVyfA/+w7Yv6ebP/f7N1dv61b6b6rw9IvEuIYefi3wQYLF9SrDjZ5qrlhwNTqg2Mf0G Gr3FTspuoxSuod/9ieqT1WtqDazFTu7n/zgDheyZgcT0z1h+t0UmUVaKee2YXrGSEzRH ufuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NaVeHMAh; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o19si5143029eja.256.2020.06.19.21.45.12; Fri, 19 Jun 2020 21:45:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NaVeHMAh; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389280AbgFSU67 (ORCPT + 99 others); Fri, 19 Jun 2020 16:58:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392002AbgFSU6B (ORCPT ); Fri, 19 Jun 2020 16:58:01 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C6E1C06174E for ; Fri, 19 Jun 2020 13:58:01 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id i8so6336316lfo.4 for ; Fri, 19 Jun 2020 13:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=pi9mUfjZECkUpQIGYMQo/6NQ4L6ym2cDBq1A7qT/6+c=; b=NaVeHMAhn1KzZRQfD+wOu8UDQc2/X47vPbkvAkuoM9QmnXCM2STUL3kkpHYcBlSANj Va8BJRJqYIB5AwD6NUyGwEAGz69yx1wwRwdlt07r/17YRmZSGTZpbQByKs4ueh7Gn3oL yPanYqZIpO/bR8ELl7Y9vmcMru6ECFmmliPDudiaL4nki3jY5NDuCkfRWWDVZX6zD84k kIpVttarjUqKnh06uhVAyiclsIOT9FcNGaSxltUUJoXwvZwSLKNBfUOs6zRbtLtQow6s imD//ySH407H4QXsosemfugBvrTJsz2kTDw4VwL1Q873+Fr98PcjB6wCf+mdPYoMuMUZ NFqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=pi9mUfjZECkUpQIGYMQo/6NQ4L6ym2cDBq1A7qT/6+c=; b=XDB5WYwLPHpb2PQhL6QJaume4kInTR4W6LjOBcC+Q55WVHCLTbMy6rKnvnd9XO+/1r t2VAxI1tdaANVrDNHgWLekUtdqP14FaN39nZ9oKP8LOHXptsGNiya2Ryle3I22ya58Yg 4ARq1igH1vXff4zBFL56Coe15MYXeTGJUBvVGhnw6HOLLI+pTBUMAby9HNz9QucQN0yt kl39VgIsySAPyGfl0USEBQ6n0dBD+hy0PER0D31PAsCeZugXCubSW3m2X4JZTvuK0vYo jjg6exdRkSqigmQfn1kDvoexvi8qXrrCuLzQrh2CCRpfUWQD2U9LChSEZNouTK3ECFz9 gTrw== X-Gm-Message-State: AOAM530WRGyRFbNaBBcNseZmCGdMWpMaQ6C5vPNlEmQ4SfMSi6a50F8x OTIoCCpqdw1wiMbCy7oVTuOQ0d/3CvhdoEpWE1fiaQ== X-Received: by 2002:a19:701:: with SMTP id 1mr2890270lfh.138.1592600278354; Fri, 19 Jun 2020 13:57:58 -0700 (PDT) MIME-Version: 1.0 References: <20200618210659.142284-1-alainm@chromium.org> In-Reply-To: From: Alain Michaud Date: Fri, 19 Jun 2020 16:57:47 -0400 Message-ID: Subject: Re: [PATCH v1] bluetooth: use configured params for ext adv To: Luiz Augusto von Dentz Cc: Marcel Holtmann , Alain Michaud , BlueZ , Abhishek Pandit-Subedi , Daniel Winkler Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Luiz, On Fri, Jun 19, 2020 at 2:42 PM Luiz Augusto von Dentz wrote: > > Hi Alain, Marcel, > > On Fri, Jun 19, 2020 at 6:54 AM Alain Michaud w= rote: > > > > Hi Marcel, > > > > On Fri, Jun 19, 2020 at 3:46 AM Marcel Holtmann w= rote: > > > > > > Hi Alain, > > > > > > please use =E2=80=9CBluetooth: =E2=80=9C prefix for the subject. > > > > ack. > > > > > > > > > > When the extended advertisement feature is enabled, a hardcoded min= and > > > > max interval of 0x8000 is used. This patches fixes this issue by u= sing > > > > the configured min/max value. > > > > > > > > This was validated by setting min/max in main.conf and making sure = the > > > > right setting is applied: > > > > > > > > < HCI Command: LE Set Extended Advertising Parameters (0x08|0x0036)= plen > > > > 25 #93 [hci0] 10.953011 > > > > =E2=80=A6 > > > > Min advertising interval: 181.250 msec (0x0122) > > > > Max advertising interval: 181.250 msec (0x0122) > > > > =E2=80=A6 > > > > > > > > Reviewed-by: Abhishek Pandit-Subedi > > > > Reviewed-by: Daniel Winkler > > > > > > > > Signed-off-by: Alain Michaud > > > > > > The Reviewed-by lines go after your Signed-off-by. > > > > ack. > > > > > > > > > > --- > > > > > > > > net/bluetooth/hci_request.c | 10 ++++++---- > > > > 1 file changed, 6 insertions(+), 4 deletions(-) > > > > > > > > diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_reques= t.c > > > > index 29decd7e8051..08818b9bf89f 100644 > > > > --- a/net/bluetooth/hci_request.c > > > > +++ b/net/bluetooth/hci_request.c > > > > @@ -1799,8 +1799,9 @@ int __hci_req_setup_ext_adv_instance(struct h= ci_request *req, u8 instance) > > > > int err; > > > > struct adv_info *adv_instance; > > > > bool secondary_adv; > > > > - /* In ext adv set param interval is 3 octets */ > > > > - const u8 adv_interval[3] =3D { 0x00, 0x08, 0x00 }; > > > > + /* In ext adv set param interval is 3 octets in le format */ > > > > + const __le32 min_adv_interval =3D cpu_to_le32(hdev->le_adv_mi= n_interval); > > > > + const __le32 max_adv_interval =3D cpu_to_le32(hdev->le_adv_ma= x_interval); > > > > > > Scrap the const here. > > > > I'd like to understand why it isn't prefered to use const when you > > don't intend to modify it in the code. > > > > > > > > > And it is wrong since your hdev->le_adv_{min,max}_interval is actuall= y __u16. So that first needs to be extended to a __u16 value. > > > > The macro actually leads to a function call that has a __u32 as a > > parameter so the __u16 gets upcasted to a __u32 already. > > > > > > > > > That said, if we have this in the Load Default System Configuration l= ist, we should extended it to __le32 there as well. > > > > I agree, this means the range of default system configuration may not > > be sufficient to accept all possible values that the newer command > > supports, although I think this is a separate issue from what this > > patch is trying to solve. > > > > > > > > > > if (instance > 0) { > > > > adv_instance =3D hci_find_adv_instance(hdev, instance= ); > > > > @@ -1833,8 +1834,9 @@ int __hci_req_setup_ext_adv_instance(struct h= ci_request *req, u8 instance) > > > > > > > > memset(&cp, 0, sizeof(cp)); > > > > > > > > - memcpy(cp.min_interval, adv_interval, sizeof(cp.min_interval)= ); > > > > - memcpy(cp.max_interval, adv_interval, sizeof(cp.max_interval)= ); > > > > + /* take least significant 3 bytes */ > > > > + memcpy(cp.min_interval, &min_adv_interval, sizeof(cp.min_inte= rval)); > > > > + memcpy(cp.max_interval, &max_adv_interval, sizeof(cp.max_inte= rval)); > > > > > > This is dangerous and I think it actually break in case of unaligned = access platforms. > > > > Since it is in le format already and the 3 bytes from the cmd struct > > are raw, I'm not sure how this can be dangerous. It effectively > > yields the exact same results as your suggestions below. > > In zephyr we end up doing helper functions for 24 bits: > > https://github.com/zephyrproject-rtos/zephyr/blob/master/include/sys/byte= order.h#L316 > > I guess that is safer in terms of alignment access and it would work > independent of the host order which apparently was not the case in the > code above since it doesn't do the conversion to le32 (or perhaps the > intervals are already in le32), anyway having something like that is > probably much simpler to maintain given that most intervals use for > things like ISO are also 24 bits long. I like this. Would you put this in hci.h or keep to a lower scope? static inline void hci_cpu_to_le24(__u32 val, __u8 dst[3]) { dst[0] =3D val & 0xff; dst[1] =3D (val & 0xff00) >> 8; dst[2] =3D (val & 0xff0000) >> 16; } > > > > > > > > > In this case I prefer to actually do this manually. > > > > > > /* In ext adv min interval is 3 octets */ > > > cp.min_interval[0] =3D cp.min_interval & 0xff; > > > cp.min_interval[1] =3D (cp.min_interval & 0xff00) >> = 8; > > > cp.min_interval[2] =3D (cp.min_interval & 0xff0000) >= > 12; > > > > > > Regards > > > > > > Marcel > > > > > > > -- > Luiz Augusto von Dentz