Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3377713ybv; Tue, 25 Feb 2020 00:07:14 -0800 (PST) X-Google-Smtp-Source: APXvYqwbuq3nPfkYl6v/8pmTUntwpqadxnAY8mtMeKhADRjZPCkF0Y0lgNjFlqI47ll+MKWWdL3c X-Received: by 2002:a54:4e96:: with SMTP id c22mr2653060oiy.110.1582618034699; Tue, 25 Feb 2020 00:07:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582618034; cv=none; d=google.com; s=arc-20160816; b=0SdtVSRY75/0/ejUURY+9kmaNm4XWxq0kKtWGn4eKvPwWwSwM8Z6/Dh07LL/DpCPDL T79kAV406EAueWBHsdKd95l6xr7PwXUqdfzaNFiKNVSHz0JZRAgtrfTefL2QIoRe/QLG XZzGbO6UtIWqQq0FaE5+ItWQgUNAmPYD8up7GN5uZrfhtkAjXep7rH9AVaMzmFkIPR4z jgPVedT4+uAFzyGE6FJj3HubAYmTXvDZUHlMwTfR/Tr8S0uUgNcBsc4A8ZVVVzI4Bcej PXyL3ApTbMdvr4cxlfRBCavp1dludtz3rif7HruAAKI+1b0ZfOr/Vb3WxfdS6z+rDJIA 8KcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=OAPj1XBZLNFAf4SineVPDvFpHYh1qFQIuQAZtHLdUtc=; b=LKUSqplrh+eWIL+aZm0gkK1uGfkmTDxSW1dLZMFF3lbIvhL+EovA62lbsO9+Bz3erq 9XMKnyYDB/JWJcV3J1UfFBdu5vVO5XCCBC1TLtWNxn5D8Fy8KTS+Su49183vj5BkFQWG PjZoN/YS6xLfcS4zATfN+7TBQJEFp3S4A310MMDfYP5xTBmHuFqqbnKRL1PuyZenSh22 l8ZFbNcqVjBlRsVPzliie214D7LLROnYXxzEcGBcDYTlga+jqPX3dXE8SdoQO43s5g2S RhisUOgiBBL/ZocY/ds+/IC0nHTB3Ob7Nq8lpjkEV0dSKx9MNotT+Q1Ynp8+BnbowWJY 9ZTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lXwPT+Nq; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id d23si6371806oij.270.2020.02.25.00.06.50; Tue, 25 Feb 2020 00:07:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lXwPT+Nq; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 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 S1729475AbgBYIEx (ORCPT + 99 others); Tue, 25 Feb 2020 03:04:53 -0500 Received: from mail-ot1-f67.google.com ([209.85.210.67]:40876 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729443AbgBYIEx (ORCPT ); Tue, 25 Feb 2020 03:04:53 -0500 Received: by mail-ot1-f67.google.com with SMTP id i6so11268119otr.7 for ; Tue, 25 Feb 2020 00:04:51 -0800 (PST) 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; bh=OAPj1XBZLNFAf4SineVPDvFpHYh1qFQIuQAZtHLdUtc=; b=lXwPT+Nq93BPpcUK+ygkKpiqn2heGVdf9eFTnq0l7k6/xDENj4479/5RYmP7NE0oUy Dshf65ACoUiaZQsm/ePnf7/bW7KS+h72QutFuXX+WBKufZDjdUBy/4gSK3E9uIDA3RF1 T1lOOk07CYTa7IErSk16DdikvJc4/pKmUti5b0fWBsLzlP2w/2cC7VbZ5vs6olOX4S/K TpMV6F3rXtS1SMWdd3KNrizHX6MkLDdgHmVLUycnVLxesE/5TCIhppe9tf/vSOnyQ5g+ cAEw/6UzwOYBZ3TYRxiPx8KvJoJNc4uxe151f3iiMbBEPWZvUKlPIbQSm4Pfx1nvDO8P nHuw== 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=OAPj1XBZLNFAf4SineVPDvFpHYh1qFQIuQAZtHLdUtc=; b=iCoeK2Il66bsNAJjGAbC7hv1S2X8k2a4V37/rigXsqD5jQUNKLCRxQga50VlIsjjcw JGnNbXg+uRYWXoqqnxITnQKhpaZ7uhbPmxUZwoN5Jzect0ABVsqjHcdMHKVaO2MNYnlv EYs6qXJHKJFSCHN70nfKvydQMkSwAsLIemD2x+gfVo0p/CoSU2lwWnYjdG2JJ1IWFXMz 7BfTT/I6axh+6sJh6qPl4Th1lVcIZ7MMM1vEY8IAGWGv+KefkF7SEdMYxKruriGNHgzG fGpYcEfBFs4blJ7Mlko2GgHuyEWD3d0ed70zFamrvosYKSaeJNrNO+l5Xe2CAuUjFowq kgRQ== X-Gm-Message-State: APjAAAVaNmpmYdcGW9ZWUC7Db616BHFJ0v4Vi4GrWyPXKduCQlSMujom +JkWn3vlgDffeeslfrtp9aEes+v4vhWXyVHHF6U= X-Received: by 2002:a9d:6d10:: with SMTP id o16mr45080894otp.28.1582617890863; Tue, 25 Feb 2020 00:04:50 -0800 (PST) MIME-Version: 1.0 References: <20200221163911.Bluez.v1.1.I3c505b4307094eb7a6f2c5949125a17c89b2e099@changeid> In-Reply-To: From: Luiz Augusto von Dentz Date: Tue, 25 Feb 2020 00:04:38 -0800 Message-ID: Subject: Re: [Bluez PATCH v1] src/profile: Ensure class UUID matches before connecting profile To: Archie Pusaka Cc: linux-bluetooth Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Archie, On Mon, Feb 24, 2020 at 10:59 PM Archie Pusaka wrote: > > Hi Luiz, > > After looking at the code for device.c you pointed out, > apparently the function update_bredr_services() is called two times > upon connecting to a device, the first one for UUID 0x0100 (L2CAP), > then the second one for UUID 0x1200 (PNP). > > I am not clear as to why BlueZ needs to search for those two records, > but this might impacted the decision to move the service class ID > filtering to sdp-client.c, because the service class ID of the records > will never match 0x0100, so it will all be filtered out. Right that is looking for all records basically, since L2CAP is included everytime, so we need to keep that working, so perhaps a better alternative would be to have a second helper function that does the filtering or extend bt_search_service with another parameter, but I guess doing the former is cleaner, though I rename bt_search_service to just bt_search and the later since that doesn't do any filtering and leave bt_search_service to actually filter out base on service class. > Could you confirm that it is okay to filter all records based on the > service class ID, especially considering all records related to L2CAP > query will not execute this part of the code? > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/device.c#n4630 > > Thanks, > Archie > > On Tue, 25 Feb 2020 at 13:58, Archie Pusaka wrote: > > > > Hi Luiz, > > > > On Tue, 25 Feb 2020 at 03:30, Luiz Augusto von Dentz > > wrote: > > > > > > Hi Archie, > > > > > > On Fri, Feb 21, 2020 at 12:41 AM Archie Pusaka wrote: > > > > > > > > From: Archie Pusaka > > > > > > > > According to bluetooth spec Ver 5.1, Vol 3, Part B, 4.7.2, there > > > > might be multiple service records returned in a SDP Service Search > > > > Attribute Response. Also, according to 2.5.2, the service pattern > > > > can match any UUID contained within the service record, it doesn't > > > > have to match only some specific attributes of the record. > > > > > > > > Therefore, before using the service record to connect to any > > > > profile, first we must check that the service class ID of the > > > > service record matches with whatever UUID specified in the service > > > > pattern we are looking for. > > > > > > Im surprised we were not doing this currently, Im fairly sure we do > > > that for the services/plugin though since there are only probed if the > > > service UUID matches > > > > > > > --- > > > > > > > > src/profile.c | 26 ++++++++++++++++++++++++++ > > > > 1 file changed, 26 insertions(+) > > > > > > > > diff --git a/src/profile.c b/src/profile.c > > > > index 192fd0245..1b481836e 100644 > > > > --- a/src/profile.c > > > > +++ b/src/profile.c > > > > @@ -1568,8 +1568,34 @@ static void record_cb(sdp_list_t *recs, int err, gpointer user_data) > > > > > > > > for (r = recs; r != NULL; r = r->next) { > > > > sdp_record_t *rec = r->data; > > > > + sdp_list_t *svcclass; > > > > + sdp_list_t *svcclass_iter; > > > > sdp_list_t *protos; > > > > int port; > > > > + bool matches_class_uuid = false; > > > > + > > > > + if (sdp_get_service_classes(rec, &svcclass) < 0) { > > > > + error("Unable to get svc class ID list from %s record", > > > > + ext->name); > > > > + continue; > > > > + } > > > > + > > > > + for (svcclass_iter = svcclass; svcclass_iter != NULL; > > > > + svcclass_iter = svcclass_iter->next) { > > > > + char *uuid = bt_uuid2string(svcclass_iter->data); > > > > + int cmp_result = bt_uuid_strcmp(uuid, ext->uuid); > > > > > > I think it would be probably more efficient to convert to data to > > > binary format (bt_uuid_t) and then do the comparision with > > > bt_uuid_cmp, also there might not be needed to iterate at all see > > > device.c:update_bredr_service which has the logic for updating > > > records: > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/device.c#n4602 > > > > I was uncertain whether we need to iterate or not, so I went for the safer side. > > However if there is no need to do that then this shall be updated. > > I also agree that comparison in binary should be faster. > > > > > > > > Btw, we should probably have bt_search_service doing the matching if > > > the uuid is set instead of returning all records like it seems to be > > > doing that way we don't have to maintain duplicate logic in both > > > device.c and profile.c > > > > Got it. somewhere in sdp-client.c is a good idea. > > Aside from device.c and profile.c, is this also used somewhere else > > though? We might also want to take them out if we are to implement > > the check in sdp-client.c. > > > > > > > > > > > > + free(uuid); > > > > + if (cmp_result == 0) { > > > > + matches_class_uuid = true; > > > > + break; > > > > + } > > > > + } > > > > + > > > > + sdp_list_free(svcclass, free); > > > > + > > > > + if (!matches_class_uuid) > > > > + continue; > > > > > > > > if (sdp_get_access_protos(rec, &protos) < 0) { > > > > error("Unable to get proto list from %s record", > > > > -- > > > > 2.25.0.265.gbab2e86ba0-goog > > > > > > > > > > > > > -- > > > Luiz Augusto von Dentz > > > > > > Thanks, > > Archie -- Luiz Augusto von Dentz