Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1008482ybt; Fri, 19 Jun 2020 21:27:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlC1rZJxLwWtTNi0gTxbce+RZonD1uzlYkLPw/xmcCZTgSmpU/mFThP4OEA4VPUHCjn2gN X-Received: by 2002:aa7:d0c5:: with SMTP id u5mr6342417edo.51.1592627247999; Fri, 19 Jun 2020 21:27:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592627247; cv=none; d=google.com; s=arc-20160816; b=pmM4cRkYXFEv2gKozJDkNDO07n5HlclVqheFxOuneROnce0ERbS4yC+bD/Zyr9hoVf NzXBevXOzAjf6XSFp1ovYDJwgX0nij+CL8DWpL6EdmsrolEyKeCuKvXBYfXT2F9heOFM wDSn0PhQSYvb6GVssbhYoflO13sn8MyVaW39+3xG+cfaAHuuLOTpSCDJfn+Txxttg8lZ +ywBakqZVJHdMkgrH6H0mIucnLZZCFbRHgxIvHZPTNp9tyRQM/15N0TgVLWsfJPAVUR7 Me+G5IRu5iA0Yna5o2b+OXKm/zfjh8bq+qug5V9aPeK4fUn6T6F3v46ByDkjfScmTP54 +qXg== 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=kV3/TnPlRElMR4EpGS3Wr6fOtcvyfVlWAo5KVqV268M=; b=oZ/ur6z/QvF34UQIP4kQ+bXN4TqBMUPS8SKCQGH9rDm2N7jvGfw2i8JjJKbaUskqCU V+oc7YBVjChBzsJNVvQZoLguMEiaVOpnxs5Cib2p99LLiff7zGqp0EKr+GPZM3zAGofI 3STW0nTgDTaocNgsBHP7kszFv/90cG1B1TeCDwphUHUTJTLKrhg210Za/NOVLLdIVOLT bEy6Lsne5yC38bNBIHMfXEjX3f/JGY4BTjfvHwGb3a97e3aFfCyVNqQMksGpM6i+Ew/K in70QdfusRdDl/yjEb4kev6+XqydFK00SK3qdhD+1J+Xul6RJ3xdr3NgbRj6+2SBnTwJ NZPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Zq6G4WsF; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d3si6051381edl.218.2020.06.19.21.27.03; Fri, 19 Jun 2020 21:27:27 -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=@gmail.com header.s=20161025 header.b=Zq6G4WsF; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733178AbgFSSmG (ORCPT + 99 others); Fri, 19 Jun 2020 14:42:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732225AbgFSSmF (ORCPT ); Fri, 19 Jun 2020 14:42:05 -0400 Received: from mail-ot1-x344.google.com (mail-ot1-x344.google.com [IPv6:2607:f8b0:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFCD9C06174E for ; Fri, 19 Jun 2020 11:42:05 -0700 (PDT) Received: by mail-ot1-x344.google.com with SMTP id s13so8036121otd.7 for ; Fri, 19 Jun 2020 11:42:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=kV3/TnPlRElMR4EpGS3Wr6fOtcvyfVlWAo5KVqV268M=; b=Zq6G4WsF6kx8s1jgjdDacU5DSUJ7HVNKI9JBwWsWJ4eSKRXWp5E7IBA2UDPI8+eUho +Wiken+yHOM26E5jkAaZMq3R4Ge8Sy1OfEIwc/Ean9/+aK4IX+ixDCM0uoa3OasTD7yN 8b4eqFnRfMWKMDTl7kPGXcay63z8sMJlgnU3OyYI0jdcUJTygxXyinw2cHoWCoOCIcv/ qhOORxeRywrHMt4hNt9/Um3VLl9cMxymtCVorvQgtkxLXXSxsGQfPgz/aEFNY9XO28oK S3H2qdF+2E78fNw8jum4XtixmumvBLOa9ce/2r66zs8Vjdlfkll1jhsE+F6NlRXI2P5h zKNw== 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=kV3/TnPlRElMR4EpGS3Wr6fOtcvyfVlWAo5KVqV268M=; b=sqvpExek8NwGRFHos5iPwEciZk6XoulyUqXQo9SmdQVxsvSI/3JleUmDEX6JbuTA/9 olF6GrJgBUzsBVzQTmPLRMGnmC8KlvL58YE0zfQ1UhHziAWlOKR1rXr0E5exn/R2zgiC JsryPSIKVsSpVL/q+FFXijjBqpvejSveeS7vRAXvaG5cPj2cMRXxmI55iCUmAJ/lFdJw XDPbLru3ksytERl4+C2sieELOSPchmOysQ3+67mDaoo6LG1tC0oDIDouBqYGB/beIsJJ nXyorWTg6jd2biqRksuoUEPOc7qzybVKmdVGMx2gZ7YPbD0WerX3IJGq7YyyDWX+zvNn DMYg== X-Gm-Message-State: AOAM532ThPUcgLMK92ACj27STcFHGKwCvZ+eppsAPXDTf/HvoBeYsiby S313pAfqBny3I/H0ubNv0SmZW8RqVICtZ553e9XmC2dD X-Received: by 2002:a9d:4691:: with SMTP id z17mr4107616ote.88.1592592124884; Fri, 19 Jun 2020 11:42:04 -0700 (PDT) MIME-Version: 1.0 References: <20200618210659.142284-1-alainm@chromium.org> In-Reply-To: From: Luiz Augusto von Dentz Date: Fri, 19 Jun 2020 11:41:53 -0700 Message-ID: Subject: Re: [PATCH v1] bluetooth: use configured params for ext adv To: Alain Michaud 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 Alain, Marcel, On Fri, Jun 19, 2020 at 6:54 AM Alain Michaud wro= te: > > Hi Marcel, > > On Fri, Jun 19, 2020 at 3:46 AM Marcel Holtmann wro= te: > > > > 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 a= nd > > > max interval of 0x8000 is used. This patches fixes this issue by usi= ng > > > the configured min/max value. > > > > > > This was validated by setting min/max in main.conf and making sure th= e > > > right setting is applied: > > > > > > < HCI Command: LE Set Extended Advertising Parameters (0x08|0x0036) p= len > > > 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_request.= 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 hci= _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_min_= interval); > > > + const __le32 max_adv_interval =3D cpu_to_le32(hdev->le_adv_max_= 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 actually = __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 lis= t, 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 hci= _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_interv= al)); > > > + memcpy(cp.max_interval, &max_adv_interval, sizeof(cp.max_interv= al)); > > > > This is dangerous and I think it actually break in case of unaligned ac= cess 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/byteor= der.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. > > > > > > 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 > > --=20 Luiz Augusto von Dentz