Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp3015561rdb; Mon, 4 Dec 2023 14:12:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFYM0zsM0FfpZkJuLyjIwXUA/sGCpMLSD1u3JoJ7ToKeV9CcjGs0f2tn84/IbtahLBfYvVo X-Received: by 2002:a05:6808:1291:b0:3b8:b1e2:ceb3 with SMTP id a17-20020a056808129100b003b8b1e2ceb3mr4956449oiw.43.1701727954646; Mon, 04 Dec 2023 14:12:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701727954; cv=none; d=google.com; s=arc-20160816; b=VwOl7K4okserAdUEZYQhHJlQSXFKB0wKRwcmU+geWSVRGJJxAUQ2PxCwZ8GAGpDtab x/ejXQg3oSbUCffEG5r4MYidDKh6wnrYBmRz0l/mZsjZ7xTaWMYQmpnbizkk8y5sYwe3 7eEX6C3vVgkcu26y76ubP8nbyoj/bcKGvR/NQLfaxcY+eH8hvSxGPviuzYhZcq2HkZZW r1EbeGtZLKEJ2YJqSl1Idc5g2cFWWInbZtpdM9mHauPz/ljhxpur3kmVDNJWEAK2CCAD rccKcbhdxsY2lLu5O70LRX51rcQdTIItYCFUqLmee4GJ2XHK60V/EHD2XYegfpKinCfW R+Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=0xVhVmrxuCJ/G4r+tPgWlTU9BM/7xdXt7jEBnmEO76Q=; fh=DAQcRl3x1Lkd4zhWG6WpPW+omdhGfuKDYyGi7DGpk4k=; b=QwUD5u7bIk7CerTSiqqi0vYqTKxdBUwucNTcLEy9cF7z3vfIayOg2/FMUecrmsv78i EYrJZASXeHf62VcUvI104m9GF7yOvNEVzxBO67p4zUTe/oEOTw94HFSaLlmyGkbt/1f4 wiYIe6mQAF6gSrbXmYGY12sj2xpTwNgS4kKerKpqcMPNiTEk8JP5vesEtUzKo7W9+YOw XO7fu5oUwUwlyP8GciIF0pmVmmShghxW0dty/phRlKUGJP22vzqbq25FYQ1h4R+nZQB0 MVelLogMhaK2VEctN5UR6EXv5AqeGESYK2Ix7UN0GT3P1dnOODj+C98QQIyQeeLZA3W1 zu/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=P2TjxS1O; spf=pass (google.com: domain of linux-bluetooth+bounces-375-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-375-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id qr20-20020a05620a391400b0077d94e32f22si10969649qkn.280.2023.12.04.14.12.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 14:12:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-375-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=P2TjxS1O; spf=pass (google.com: domain of linux-bluetooth+bounces-375-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-375-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 632171C20BA9 for ; Mon, 4 Dec 2023 22:12:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6636A3A29E; Mon, 4 Dec 2023 22:12:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P2TjxS1O" X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69560CB for ; Mon, 4 Dec 2023 14:12:26 -0800 (PST) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2ca0c36f5beso13700341fa.1 for ; Mon, 04 Dec 2023 14:12:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701727944; x=1702332744; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0xVhVmrxuCJ/G4r+tPgWlTU9BM/7xdXt7jEBnmEO76Q=; b=P2TjxS1O0T/k3Vej4+dd0Zyg302dA7v2W3/MpxsaI494drvxyL0L1xWkTn+0cUDL/o /xzO/UZSqKhHR1JLN8rzvaaApFopkSbnPbDb2P4hI9OB+YFwBgMGFUgfNX+IulmaAC/1 0ilYHVbrRfwkUEVioCQJVSRgwwcCKNWTsUpyDbK3A57TeHd8QzPrYX90TlEbbji6pFgf 5AzJmoyTr8YeFeqpLWhYEtcQRQKUxdWBl5hL81590epmiTsA9ya5IP7zYQJxsaC2cF2O OE2oUryfvn3FwxnxEOUK/eqhT2hnfUi2ow607MmuWIJxq8lHrbA784pvziGAmbLS7eTO 0Shg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701727944; x=1702332744; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0xVhVmrxuCJ/G4r+tPgWlTU9BM/7xdXt7jEBnmEO76Q=; b=dXsMozgg7blZOi0VEn5ZUCQQlc1VwPCy/gJ3W5HdWBSiXJbA+Pp9EFnotx1ibiheJ3 WqEO1ObE3vYRAd92oy++2bmfFfQfdH+78c1TYyeezco39IwlsPohVUso7hUErmW4GFAC p/yhbL2SjhjTrHUbnxhQX5dfanahyj56Qe4i+xW8rQlmOhixQxCxhcUWI12ny6du1QxJ 34aCkiwZX5eEdj4fVedrWbwwDkoJlOjQQver2JZaxcbFwh7nqbKW/Lebo+pctRfEIp4n E/C6dJQmE2JoU+tHMnntFpKTkkl29utPz4yFJjE54dIcPLaK3uBuyOUfFi+vbCfk1unP 7wLA== X-Gm-Message-State: AOJu0YwBCwuW1CiRiBftq2clRNyTgvpWgW+/TkyHmKnBMG/Y1A0rmdot dnWUVRiRSjRNg7dA/qZVtMCqaDI5Ce501gZs/+o= X-Received: by 2002:a2e:9902:0:b0:2c9:f696:4510 with SMTP id v2-20020a2e9902000000b002c9f6964510mr1380009lji.43.1701727944321; Mon, 04 Dec 2023 14:12:24 -0800 (PST) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231130195750.1732-1-sebastif@axis.com> In-Reply-To: <20231130195750.1732-1-sebastif@axis.com> From: Luiz Augusto von Dentz Date: Mon, 4 Dec 2023 17:12:11 -0500 Message-ID: Subject: Re: [PATCH BlueZ 1/1] Pattern match on service- and manufacturer data To: "sebastif@axis.com" Cc: linux-bluetooth@vger.kernel.org, Sebastian Forslund Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Sebastian, On Thu, Nov 30, 2023 at 2:58=E2=80=AFPM sebastif@axis.com wrote: > > From: Sebastian Forslund > > When advertisement monitoring, manufacturer data and service data was > not being matched against. This made it so that advertisement monitoring > with or_patterns did not work that type of data. > > We must start matching against the data in the manufacturer_data and > service_data queues. Run a different match-function depending on the > type of monitor that is being matched against. > > Fixes: https://github.com/bluez/bluez/issues/652 > --- > src/shared/ad.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 80 insertions(+), 1 deletion(-) > mode change 100644 =3D> 100755 src/shared/ad.c > > diff --git a/src/shared/ad.c b/src/shared/ad.c > old mode 100644 > new mode 100755 > index 951c56c60..a95079dc1 > --- a/src/shared/ad.c > +++ b/src/shared/ad.c > @@ -1324,6 +1324,72 @@ struct bt_ad_pattern *bt_ad_pattern_new(uint8_t ty= pe, size_t offset, size_t len, > return pattern; > } > > +static void pattern_manufacturer_data_match(void *data, void *user_data) > +{ > + struct bt_ad_manufacturer_data *manufacturer_data =3D data; > + struct pattern_match_info *info =3D user_data; > + struct bt_ad_pattern *pattern; > + uint8_t all_data[BT_AD_MAX_DATA_LEN]; > + > + if (!manufacturer_data || !info) > + return; > + > + if (info->matched_pattern) > + return; > + > + pattern =3D info->current_pattern; > + > + if (!pattern || pattern->type !=3D BT_AD_MANUFACTURER_DATA) > + return; > + > + /* Take the manufacturer ID into account */ > + if (manufacturer_data->len + 2 < pattern->offset + pattern->len) > + return; > + > + memcpy(&all_data[0], &manufacturer_data->manufacturer_id, 2); > + memcpy(&all_data[2], manufacturer_data->data, manufacturer_data->= len); > + > + if (!memcmp(all_data + pattern->offset, pattern->data, > + pattern->len)) { > + info->matched_pattern =3D pattern; > + } > +} > + > +static void pattern_service_data_match(void *data, void *user_data) > +{ > + struct bt_ad_service_data *service_data =3D data; > + struct pattern_match_info *info =3D user_data; > + struct bt_ad_pattern *pattern; > + > + if (!service_data || !info) > + return; > + > + if (info->matched_pattern) > + return; > + > + pattern =3D info->current_pattern; > + > + if (!pattern) > + return; > + > + switch (pattern->type) { > + case BT_AD_SERVICE_DATA16: > + case BT_AD_SERVICE_DATA32: > + case BT_AD_SERVICE_DATA128: > + break; > + default: > + return; > + } > + > + if (service_data->len < pattern->offset + pattern->len) > + return; > + > + if (!memcmp(service_data->data + pattern->offset, pattern->data, > + pattern->len)) { > + info->matched_pattern =3D pattern; > + } > +} > + > static void pattern_ad_data_match(void *data, void *user_data) > { > struct bt_ad_data *ad_data =3D data; > @@ -1363,7 +1429,20 @@ static void pattern_match(void *data, void *user_d= ata) > > info->current_pattern =3D pattern; > > - bt_ad_foreach_data(info->ad, pattern_ad_data_match, info); > + switch (pattern->type) { > + case BT_AD_MANUFACTURER_DATA: > + queue_foreach(info->ad->manufacturer_data, pattern_manufa= cturer_data_match, > + info); I'd use queue_find instead so you can stop the lookup earlier if there is a match, also for the match function you can use something like match_manufacturer. > + break; > + case BT_AD_SERVICE_DATA16: > + case BT_AD_SERVICE_DATA32: > + case BT_AD_SERVICE_DATA128: > + queue_foreach(info->ad->service_data, pattern_service_dat= a_match, info); Ditto, Id also suggest to use something like match_service. > + break; > + default: > + bt_ad_foreach_data(info->ad, pattern_ad_data_match, info)= ; > + break; > + } > } > > struct bt_ad_pattern *bt_ad_pattern_match(struct bt_ad *ad, > -- > 2.39.2 > > --=20 Luiz Augusto von Dentz