Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp894828iog; Mon, 13 Jun 2022 15:35:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u6+mf3V8n40wE5mLZ3GoTTFy1q3558QoataaXyq3wpVAAZt3RnL7V2o9WnGRNIC4Ok5uAv X-Received: by 2002:a17:906:610:b0:715:79ac:7db9 with SMTP id s16-20020a170906061000b0071579ac7db9mr1679088ejb.226.1655159755503; Mon, 13 Jun 2022 15:35:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655159755; cv=none; d=google.com; s=arc-20160816; b=HajLuuv6nxxi792FbjoJjo/FwF29LGtmKWuKaK2h6YyzZxHEkuqteKIspP/X7X7who yBM1NdPnLCItd1uyJ1nOQtC9o3CJJkbEg/8rDjX/dNMhDQkziYyCBPQ4RB5KvTiK5LFK qw+Piski8+VuMosyqONDafskSC9r2MjryM+joFlzIJF3NQdSJTvo+uOoHRIEN6Y6Zo1e o4cw3hx0EMEmAqBtzeKMKWL+iR0WroiaMhqXWoILj00rxNH6FyVhvVzXN6b37D8wBINm TFADazmYYgh2Kw5GKf48AoZKT1w+gyPg5Un8n4Un6oKm34H7O9yjTri6Mt7FCTrvpYbX u+JQ== 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=0mRUAXK6ebsJ5++EX64A/OLMF5HZn19tvc9idLLSyZ8=; b=oxon+HsneBvw2k8RhvffzJKdAS0T02w024+QDO7LZbaiDFuLRglJ4HDuvWuS3jA86n LJxMJ6uVm/TrMVQAY6xW9od8MC7KbSyDWiOPlJdftY3NBc/1Psw63y1ZrrGJDccpWk8I OBdQ8hMiTlWNof/I+1DcC9mjnGHwEhFeTqFD45co9pQIkiyTyOPNC35n6Ff8hHT9Ebrl cl4XJrgqP83Ia36avXtkuwdlME7zyHSPdtP9XkByolS+TzCqu54ZA2i+o1KZ314ZInqD rmrRYxWD9h+7NRr3Nd3eL1fUhT8LM74jV0GyA2E/d2aSwHJcyL8FzaSUvpg8HGoWaSdl DaWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=NE0UgYWJ; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r10-20020a05640251ca00b0042de92db2b7si10389059edd.625.2022.06.13.15.35.27; Mon, 13 Jun 2022 15:35:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=NE0UgYWJ; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229837AbiFMW2x (ORCPT + 99 others); Mon, 13 Jun 2022 18:28:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229808AbiFMW2w (ORCPT ); Mon, 13 Jun 2022 18:28:52 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54C17AE43 for ; Mon, 13 Jun 2022 15:28:51 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id s10so7696851ljh.12 for ; Mon, 13 Jun 2022 15:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0mRUAXK6ebsJ5++EX64A/OLMF5HZn19tvc9idLLSyZ8=; b=NE0UgYWJesclme8vHImffH8jiVix/YZA2uuIVHWM6GPRYjwzS2EnOdwISO08fTNrTR lx8dHn412eaheMGnhEuWP9SvpsBEha6p7VoUIj3k39L5F5IdFEkB8L/r7bnlGUyI6M0Q XcxBoyWtTEHk5otvhhIYPSoj06J0RqL+5rziXHpgeBoi5kR+i4Imzz7RCapL5qW3K6JW ya6qy9IvGTWKdnz6X2M/7SPB+ildDNWfCXIc25xcF/vQ7Lo5wn8LaoU+b0QnR3veBDbS F7PxHyHEScqt64Znw2qgpe5JiD3sGD2O5OZAG5fyvMvM+D/fCX9Is5LvGd4IzAoFhxJ3 FAVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0mRUAXK6ebsJ5++EX64A/OLMF5HZn19tvc9idLLSyZ8=; b=buTAUgNrOZiGJaB/Ex8hvS70yhPnKT5FzgP2nMWmIBmVC93T0Hgx11Z85SSvlaa9H6 hacSvDBjevpCTYvDM8qKm4RBArfiyqSsiOKfnPlHazEvrPZnKDB2B8o//MmB6pzYxGRb BdMDSBDErxAtLwFOqFRXQeaX9McL6fZzjI2Jzx75hmdc2xwlk8JeAm7DZtw4PY7jSyyg Ovxilxm4k/7ItjOf1RULY8wKEtClqdJroSp1vypQobqMOL93u+nSMdZk3dsLfkqdM8pI KxkeGFjIb7CZxoPLk++oa/x6Xb6fPxfE3aP0JYt3ZMtodysITRojVTk1euUtqgTqCKqO UVgw== X-Gm-Message-State: AJIora9dWSHzuK61PbrYxL0yJgbqjDMAUTHszHV52WzECZ1r3lwQmRmv XtnTW0URZnDtQQOb2E8Qejb3gvBYQrUp/pYDvx4= X-Received: by 2002:a2e:a315:0:b0:259:e8b:5b23 with SMTP id l21-20020a2ea315000000b002590e8b5b23mr860176lje.115.1655159329638; Mon, 13 Jun 2022 15:28:49 -0700 (PDT) MIME-Version: 1.0 References: <20220610221124.18591-1-puffy.taco@gmail.com> <20220610221124.18591-2-puffy.taco@gmail.com> In-Reply-To: From: Mike Brudevold Date: Mon, 13 Jun 2022 17:28:35 -0500 Message-ID: Subject: Re: [PATCH v2 1/3] eir: parse data types for LE OOB pairing To: Luiz Augusto von Dentz Cc: "linux-bluetooth@vger.kernel.org" , Michael Brudevold Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Luiz, On Mon, Jun 13, 2022 at 4:55 PM Luiz Augusto von Dentz wrote: > > Hi Mike, > > On Mon, Jun 13, 2022 at 2:42 PM Mike Brudevold wrote: > > > > Hi Luiz, > > > > > It might be better to handle this via bt_ad instance instead of > > > eir_data, in fact the plan was always to switch to bt_ad but it seems > > > we forgot about it at some point. > > > > Are you thinking something like below (doesn't fully compile, > > name2utf8 is static in eir so I did nothing about that yet)? > > Basically where the ad code parses the EIR data, but the neard plugin > > still manages what to do with the data? The alternative would be > > where device.c became smarter to consume the ad struct itself and the > > neard plugin becomes a simple conduit for the ad data. > > The later is probably better alternative, like I said I wrote bt_ad to > replace eir handling completely so we could also write proper unit > testing for it, Im fine if you want to take the time to change the > daemon core itself but at least introduce support for the types you > will be using in the plugin and then make use of them. > > > index 77a4630da..3d4064515 100644 > > --- a/plugins/neard.c > > +++ b/plugins/neard.c > > @@ -31,6 +31,7 @@ > > #include "src/agent.h" > > #include "src/btd.h" > > #include "src/shared/util.h" > > +#include "src/shared/ad.h" > > > > #define NEARD_NAME "org.neard" > > #define NEARD_PATH "/org/neard" > > @@ -336,6 +337,52 @@ static int check_device(struct btd_device *device) > > return 0; > > } > > > > +static void process_oob_adv(void *data, void *user_data) > > +{ > > + struct bt_ad_data *ad_data = data; > > + struct oob_params *remote = user_data; > > + uint8_t name_len; > > + > > + switch (ad_data->type) { > > + case EIR_NAME_SHORT: > > + case EIR_NAME_COMPLETE: > > + name_len = ad_data->len; > > + > > + /* Some vendors put a NUL byte terminator into > > + * the name */ > > + while (name_len > 0 && ad_data->data[name_len - 1] == '\0') > > + name_len--; > > + > > + g_free(remote->name); > > + > > + remote->name = name2utf8(ad_data->data, name_len); > > + break; > > + > > + case BT_AD_LE_DEVICE_ADDRESS: > > + if (ad_data->len < sizeof(bdaddr_t) + 1) > > + break; > > + > > + memcpy(&remote->address, ad_data->data, sizeof(bdaddr_t)); > > + remote->address_type = ad_data->data[sizeof(bdaddr_t)] & 0x1 ? > > + BDADDR_LE_RANDOM : BDADDR_LE_PUBLIC; > > + break; > > + > > + case EIR_LE_SC_CONF: > > + if (ad_data->len < 16) > > + break; > > + free(remote->hash256); > > + remote->hash256 = util_memdup(ad_data->data, 16); > > + break; > > + > > + case EIR_LE_SC_RAND: > > + if (ad_data->len < 16) > > + break; > > + free(remote->randomizer256); > > + remote->randomizer256 = util_memdup(ad_data->data, 16); > > + break; > > + } > > +} > > Do we need to duplicate this information? I'd consider just using the > bt_ad instance to parse and store them, well perhaps we want to > introduce something like bt_ad_foreach_type so you can locate the data > by type? That's partly what I was checking on. The ad code doesn't have much functionality right now to be able to parse the meaning of the data, beyond storing them in TLV format (bt_ad_data). Which is the opposite to how the data is given to ad if you're creating an advertisement (e.g., service UUIDs are stored in bt_uuid_t format inside the service queue when using bt_ad_add_service_uuid, not in the data queue). This means the ad code likely has to get smarter, but I wanted to make sure I wasn't missing something that should have been obvious. If the ad code can present the data back in a usable format, then it wouldn't really have to be duplicated. Otherwise this code would have been an easy way to not use the eir code while the ad code gets developed. With some concern still that there's a type_reject_list related to the data ad queue, but that can be completely bypassed when using bt_ad_new_with_data - so this method is doing something that seems unintended. > > > static int process_eir(uint8_t *eir, size_t size, struct oob_params *remote) > > { > > struct eir_data eir_data; > > @@ -370,32 +417,17 @@ static int process_eir(uint8_t *eir, size_t > > size, struct oob_params *remote) > > > > static void process_eir_le(uint8_t *eir, size_t size, struct > > oob_params *remote) > > { > > - struct eir_data eir_data; > > + struct bt_ad *ad; > > > > DBG("size %zu", size); > > > > - memset(&eir_data, 0, sizeof(eir_data)); > > - > > - eir_parse(&eir_data, eir, size); > > - > > - bacpy(&remote->address, &eir_data.addr); > > - remote->address_type = eir_data.addr_type; > > - > > - remote->class = eir_data.class; > > - > > - remote->name = eir_data.name; > > - eir_data.name = NULL; > > - > > - remote->services = eir_data.services; > > - eir_data.services = NULL; > > - > > - remote->hash256 = eir_data.hash256; > > - eir_data.hash256 = NULL; > > + ad = bt_ad_new_with_data(size, eir); > > > > - remote->randomizer256 = eir_data.randomizer256; > > - eir_data.randomizer256 = NULL; > > + if (ad) { > > + bt_ad_foreach_data(ad, process_oob_adv, remote); > > > > - eir_data_free(&eir_data); > > + bt_ad_unref(ad); > > + } > > } > > > > -- > Luiz Augusto von Dentz