Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1633358pxb; Thu, 4 Mar 2021 17:03:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxq3fxW57l1AMcP5gW2ItyNEY8hI0oqydIfrZQbKW1jmcjPT+fCjaDL+67zFzmbJFSYXnh X-Received: by 2002:a02:a691:: with SMTP id j17mr7223874jam.14.1614906186038; Thu, 04 Mar 2021 17:03:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614906186; cv=none; d=google.com; s=arc-20160816; b=CKoBhWXcD0W51R2awHJvs0h+n3waT4oHF8cCXQPXIIQf2ZQEXlmde4maeDRdWDiD5g h1WULdGEeTi21gpAvjBqsEoz3Q+yG6Fu3HnAdut4L4MJjI+G714iyb+R2Sa/627SyhsB /Jm8pWV70NMIKHkS2gYl1ZWhEczafw267AyzEBDWUV1AG08ZQ+xfUVmDtSOQ+zwg/zFU q7GoK/56h6y9CwEpGCwq6A36/I8IJ822CtlXBwwdejBwSy86aiACc9iLrtVefDphXtfV 54PDvSmCId3Z8Tfgjmw9zDWCiwNl0Kr8cXGJrdbb52056Ew5AkLZXRlk15yoINuhyUEc 1osw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KacgFyzdye2Cbf20jsjd7FBpDYM6VB8mV2nlx2f4VB4=; b=Pg1OfBfMR9ZwJp9KfvBmRVuVd1BJpCzyaLTyyiFnl+iDZwr4KmhSDbrOTiHClGJfse NgD22iJnNQ+HFOuk7VQ8pWb2g/tK7frnK7w9exLAdOapOkr6QTgrJo6fDRs6HxTAyJNu BFBaWVKzfxp4sH92yZX+oypIMoBtERekKEA/9pJrCb17mePIj+3P2I35eRWZLmh7U1es hLFdhOzzNMeDbSw9IFq4VnGdY2fi8tqat6vsOio5egl45HOoeR5rJDJee7ZpDX/UaA5L Z0+Rl5hh1JvLT1cL74+DumWvjmaug7htAWP/GawGap/VS4l645Kead77EaMxE4FtkJpk QMFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="n0L/AKhH"; 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 n12si829087ilk.3.2021.03.04.17.02.51; Thu, 04 Mar 2021 17:03:06 -0800 (PST) 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="n0L/AKhH"; 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 S231742AbhCDX1u (ORCPT + 99 others); Thu, 4 Mar 2021 18:27:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233167AbhCDX1t (ORCPT ); Thu, 4 Mar 2021 18:27:49 -0500 Received: from mail-ua1-x933.google.com (mail-ua1-x933.google.com [IPv6:2607:f8b0:4864:20::933]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 545C9C061574 for ; Thu, 4 Mar 2021 15:27:49 -0800 (PST) Received: by mail-ua1-x933.google.com with SMTP id a31so106243uae.11 for ; Thu, 04 Mar 2021 15:27:49 -0800 (PST) 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; bh=KacgFyzdye2Cbf20jsjd7FBpDYM6VB8mV2nlx2f4VB4=; b=n0L/AKhHewL6b/WMEg21txsmz06264S1nEYpYuhdAY210KA3cyJsR3nIUZANTdX59p 1b75yVF8wmgALqokfz2Gyi+iBHhPZq5T6Mb59EauoTqoeBYEkG1WLXwVEhmPeKW/91Ii KsZOgkJXR/NWY+bMcfK5/NSwJzjWoEEIDAVGpZvQata2IhlTeSmrv96+SjXMicPQWKBc 0CDomz5snY4FeGOqI9/QUCGJLNrmblUGVMQRY5kvT5j890PRtWoPMZOLT1wGAOtwlJjp WeQFO/QGowoki9CPaMbOXMiEeb25Q+IiYbRGlCe3A59yWFDZ/mWWvml9Pku8LZatebyl LENg== 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; bh=KacgFyzdye2Cbf20jsjd7FBpDYM6VB8mV2nlx2f4VB4=; b=ALUEKAwSBdLHhv/hLKR24uQESyRjTyJqL4iUtOtw/91A8p2LxDRCuiEfuoDUIGf2sX DKH4AW8h3nIpGTbtcQ5Qfmsg/AJYw7zSSGWEYsxnk9ghPvBj1uDQ7q+8CVGQng6ZU+mE gufdP6rX6ZIxG3u6OuDrZUiso03uAqnnUm0aZgoIsNGYAnHE9+hxCqxQPOLkBXtay0py EjO85bYVnzj9vmpBRUkkd2FG+IBzgp0lVqbTB4FKLk5HI3hYjM+gKux7n/tfrbkrE10q JwVzXHCXaVhNn1QjwpNu42Ws4MT1cUG23fpYX9UjQ9YWBR8YgX32nEcUQlW4Zq2q48wK kdWA== X-Gm-Message-State: AOAM533eH2l1AtW1tBFy6gCyw3yc4bF0X1LnnkdmW52CJJoYlO9MLeLX UurZg+XOVocsz8WRIBrZkS3m51mdrRrAKM0D7dXTGA== X-Received: by 2002:a9f:2f11:: with SMTP id x17mr4371121uaj.31.1614900468135; Thu, 04 Mar 2021 15:27:48 -0800 (PST) MIME-Version: 1.0 References: <20210304202452.1998022-1-danielwinkler@google.com> <20210304122005.Bluez.v2.1.I1411482bfff45aecdec1bc8c895fc7148ee3f50c@changeid> In-Reply-To: From: Daniel Winkler Date: Thu, 4 Mar 2021 15:27:36 -0800 Message-ID: Subject: Re: [Bluez PATCH v2 1/3] advertising: Generate advertising data earlier in pipeline To: Luiz Augusto von Dentz Cc: "linux-bluetooth@vger.kernel.org" , ChromeOS Bluetooth Upstreaming , Alain Michaud , Sonny Sasaka Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Luiz, Can you please clarify your suggestion? The issue here is that some properties (local name, for instance) aren't incorporated into the bt_ad object until generate_scan_rsp is called. I decided to move the generation of data/scan response to be earlier because otherwise the logic to determine if the scan response was empty would require some repetitive logic that already exists in generate_scan_rsp. Or are you suggesting that we not store adv_data_len and scan_rsp_len in the btd_adv_client, but instead store it in the bt_ad object? This seems possible to me, but it might require a bit more effort to keep the length property in sync. I'll wait for your clarification. Thanks! Daniel On Thu, Mar 4, 2021 at 2:49 PM Luiz Augusto von Dentz wrote: > > Hi Daniel, > > On Thu, Mar 4, 2021 at 12:25 PM Daniel Winkler wrote: > > > > This change moves the advertising data generation to the beginning of > > the registration pipeline. This is necessary for the following patch, > > which will need to know whether the scan response data is existent so > > that the parameter request can be populated correctly. > > > > Reviewed-by: Alain Michaud > > Reviewed-by: Sonny Sasaka > > > > --- > > > > Changes in v2: None > > > > src/advertising.c | 79 +++++++++++++++++++++++++---------------------- > > 1 file changed, 42 insertions(+), 37 deletions(-) > > > > diff --git a/src/advertising.c b/src/advertising.c > > index 15a343e52..f3dc357a1 100644 > > --- a/src/advertising.c > > +++ b/src/advertising.c > > @@ -80,6 +80,10 @@ struct btd_adv_client { > > uint32_t flags; > > struct bt_ad *data; > > struct bt_ad *scan; > > + uint8_t *adv_data; > > + uint8_t *scan_rsp; > > + size_t adv_data_len; > > + size_t scan_rsp_len; > > I'm debating if we should really just encode it early or we could just > introduce something like bt_ad_length so we don't have to have copies > of the same data in 2 different formats since bt_ad already represents > that. > > > uint8_t instance; > > uint32_t min_interval; > > uint32_t max_interval; > > @@ -141,6 +145,16 @@ static void client_free(void *data) > > bt_ad_unref(client->data); > > bt_ad_unref(client->scan); > > > > + if (client->adv_data) { > > + free(client->adv_data); > > + client->adv_data = NULL; > > + } > > + > > + if (client->scan_rsp) { > > + free(client->scan_rsp); > > + client->scan_rsp = NULL; > > + } > > + > > g_dbus_proxy_unref(client->proxy); > > > > if (client->owner) > > @@ -915,6 +929,22 @@ static int refresh_extended_adv(struct btd_adv_client *client, > > flags |= MGMT_ADV_PARAM_TX_POWER; > > } > > > > + client->adv_data = generate_adv_data(client, &flags, > > + &client->adv_data_len); > > + if (!client->adv_data || > > + (client->adv_data_len > calc_max_adv_len(client, flags))) { > > + error("Advertising data too long or couldn't be generated."); > > + return -EINVAL; > > + } > > + > > + client->scan_rsp = generate_scan_rsp(client, &flags, > > + &client->scan_rsp_len); > > + if (!client->scan_rsp && client->scan_rsp_len) { > > + error("Scan data couldn't be generated."); > > + free(client->adv_data); > > + return -EINVAL; > > + } > > + > > cp.flags = htobl(flags); > > > > mgmt_ret = mgmt_send(client->manager->mgmt, MGMT_OP_ADD_EXT_ADV_PARAMS, > > @@ -1222,11 +1252,6 @@ static void add_adv_params_callback(uint8_t status, uint16_t length, > > const struct mgmt_rp_add_ext_adv_params *rp = param; > > struct mgmt_cp_add_ext_adv_data *cp = NULL; > > uint8_t param_len; > > - uint8_t *adv_data = NULL; > > - size_t adv_data_len; > > - uint8_t *scan_rsp = NULL; > > - size_t scan_rsp_len = -1; > > - uint32_t flags = 0; > > unsigned int mgmt_ret; > > dbus_int16_t tx_power; > > > > @@ -1248,23 +1273,8 @@ static void add_adv_params_callback(uint8_t status, uint16_t length, > > > > client->instance = rp->instance; > > > > - flags = get_adv_flags(client); > > - > > - adv_data = generate_adv_data(client, &flags, &adv_data_len); > > - if (!adv_data || (adv_data_len > rp->max_adv_data_len)) { > > - error("Advertising data too long or couldn't be generated."); > > - goto fail; > > - } > > - > > - scan_rsp = generate_scan_rsp(client, &flags, &scan_rsp_len); > > - if ((!scan_rsp && scan_rsp_len) || > > - scan_rsp_len > rp->max_scan_rsp_len) { > > - error("Scan data couldn't be generated."); > > - goto fail; > > - } > > - > > - param_len = sizeof(struct mgmt_cp_add_advertising) + adv_data_len + > > - scan_rsp_len; > > + param_len = sizeof(struct mgmt_cp_add_advertising) + > > + client->adv_data_len + client->scan_rsp_len; > > > > cp = malloc0(param_len); > > if (!cp) { > > @@ -1273,15 +1283,11 @@ static void add_adv_params_callback(uint8_t status, uint16_t length, > > } > > > > cp->instance = client->instance; > > - cp->adv_data_len = adv_data_len; > > - cp->scan_rsp_len = scan_rsp_len; > > - memcpy(cp->data, adv_data, adv_data_len); > > - memcpy(cp->data + adv_data_len, scan_rsp, scan_rsp_len); > > - > > - free(adv_data); > > - free(scan_rsp); > > - adv_data = NULL; > > - scan_rsp = NULL; > > + cp->adv_data_len = client->adv_data_len; > > + cp->scan_rsp_len = client->scan_rsp_len; > > + memcpy(cp->data, client->adv_data, client->adv_data_len); > > + memcpy(cp->data + client->adv_data_len, client->scan_rsp, > > + client->scan_rsp_len); > > > > /* Submit request to update instance data */ > > mgmt_ret = mgmt_send(client->manager->mgmt, MGMT_OP_ADD_EXT_ADV_DATA, > > @@ -1305,12 +1311,6 @@ static void add_adv_params_callback(uint8_t status, uint16_t length, > > return; > > > > fail: > > - if (adv_data) > > - free(adv_data); > > - > > - if (scan_rsp) > > - free(scan_rsp); > > - > > if (cp) > > free(cp); > > > > @@ -1454,6 +1454,11 @@ static struct btd_adv_client *client_create(struct btd_adv_manager *manager, > > if (!client->scan) > > goto fail; > > > > + client->adv_data = NULL; > > + client->scan_rsp = NULL; > > + client->adv_data_len = 0; > > + client->scan_rsp_len = 0; > > + > > client->manager = manager; > > client->appearance = UINT16_MAX; > > client->tx_power = ADV_TX_POWER_NO_PREFERENCE; > > -- > > 2.30.1.766.gb4fecdf3b7-goog > > > > > -- > Luiz Augusto von Dentz