Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2532387ybt; Mon, 22 Jun 2020 00:14:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxU4ipVGozvK8K6Ry0pKWrhmvnBDC892eLG+/K+hKUgqqaGnhizsUVyh8P0UgjnCIjMm40L X-Received: by 2002:a17:907:40c0:: with SMTP id nu24mr15230221ejb.141.1592810080174; Mon, 22 Jun 2020 00:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592810080; cv=none; d=google.com; s=arc-20160816; b=xRfwX1EI2LHDRsDuDlaEC0R5WqTL8ZBBM7LULZIdcPvVBVg3bJBUO6dUJ4fm7vXyHi 41oOpu11p6ZAB5d06r/J2+I5P1l3bBOkJBEhqMsG3Z5M++UD2KDV1+B6AplKIRvRGObw 6ypZN7DcKlur2/WxnXRgvInDAgda03D6fmC4LkPt2T45VRCcxzl1+rSdrNGXODF9j5Nh Mp9YeiMNsvbDeb8bs2ekQ2Hh+PiBumSYxckD3e7zrexl5pGXpJ7Vy5LbePPL34D9N7cg JxIK5UxqgkOuhbHuQ7xQc8Gk0zJiktZZZ8a994zM1cW1R7/xmrSZ79f8i9QoC6oU3Kgl aPQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=VwvRCNaKbE8vv2WbxfScuI0wvOVDYkRn6erkWZRgDqU=; b=s3ZaSXwDJKDNb9h6U5bzh6z7jSb9C/IKAX0eXrw42xjFeXeQIsyntkZXENebqcGUKR zQKDScASRyavKuL3VqMjtyDNddxP7htl+6HKJhVrg3LBqPVb6z4mKyiv/2kCJwHk1vXR MTVzRkJZaZT3mLnt6bF2nnFpdgY/Gl/buXeYDWTcBoU6JYRkPJc4yCgTYLA7YuhSo6GJ FIBQy/q3MTEbgGRbDeFqZikMzt8qL2GwIXOekFzIsBLDUGyKFVmtrX+NISm2dAE1CSsu Y35LbauVKfWRoP5x9eJ8rKiXnaQn/xpOuOnH34XlPNYOy3ywK+MXl6/IhZfwqm/mZkE7 hDKA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m9si8639482edp.531.2020.06.22.00.14.16; Mon, 22 Jun 2020 00:14:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731332AbgFVHOL convert rfc822-to-8bit (ORCPT + 99 others); Mon, 22 Jun 2020 03:14:11 -0400 Received: from coyote.holtmann.net ([212.227.132.17]:34556 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726850AbgFVHOL (ORCPT ); Mon, 22 Jun 2020 03:14:11 -0400 Received: from marcel-macpro.fritz.box (p5b3d2638.dip0.t-ipconnect.de [91.61.38.56]) by mail.holtmann.org (Postfix) with ESMTPSA id 74625CED25; Mon, 22 Jun 2020 09:24:01 +0200 (CEST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: Re: [PATCH v1] bluetooth: use configured params for ext adv From: Marcel Holtmann In-Reply-To: Date: Mon, 22 Jun 2020 09:14:08 +0200 Cc: Luiz Augusto von Dentz , Alain Michaud , BlueZ , Abhishek Pandit-Subedi , Daniel Winkler Content-Transfer-Encoding: 8BIT Message-Id: <9DA76AAC-F625-408C-8C74-DAE3ED42AC45@holtmann.org> References: <20200618210659.142284-1-alainm@chromium.org> To: Alain Michaud X-Mailer: Apple Mail (2.3608.80.23.2.2) Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Alain, >>>> please use “Bluetooth: “ 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 using >>>>> 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 >>>>> … >>>>> Min advertising interval: 181.250 msec (0x0122) >>>>> Max advertising interval: 181.250 msec (0x0122) >>>>> … >>>>> >>>>> 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] = { 0x00, 0x08, 0x00 }; >>>>> + /* In ext adv set param interval is 3 octets in le format */ >>>>> + const __le32 min_adv_interval = cpu_to_le32(hdev->le_adv_min_interval); >>>>> + const __le32 max_adv_interval = 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 list, 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 = 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_interval)); >>>>> + memcpy(cp.max_interval, &max_adv_interval, sizeof(cp.max_interval)); >>>> >>>> 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/byteorder.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] = val & 0xff; > dst[1] = (val & 0xff00) >> 8; > dst[2] = (val & 0xff0000) >> 16; > } hmmm, how many 24-bit fields do we have in Bluetooth HCI spec? If it is just one, then lets keep it close to the usage, if not, I have also no object to put it in a higher level. Regards Marcel