Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1633068ybv; Fri, 21 Feb 2020 00:40:22 -0800 (PST) X-Google-Smtp-Source: APXvYqz8FojL36wdnqxU4CNVxW6jCUV5rDumTgiI5qkNWrwU2qG9fkn+l2g/I9wzLA5XE2Z1tjaX X-Received: by 2002:a9d:2c2a:: with SMTP id f39mr26494766otb.301.1582274422415; Fri, 21 Feb 2020 00:40:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582274422; cv=none; d=google.com; s=arc-20160816; b=XblXUqeVaPtIdNuRThOOnRH5B81aXRDNCbNWaUF0xMBcCvw/ke2gLT2DxBvEQHy3Ik imUEzY7WcTBb59On1mxDmPtlPhsqpQU5WRz2osEzFwB5ujj5GRJf1zTi6/yEafddPc9O DP7gAHBLGA1z2zvX4V7S6srYSUH95RETKSq2kWZHfzWy5CQslOXYRdcHIvIk3l/sjok9 1qKO2fkwQRoo3NFqzu+Fn8wtu8zK6/+UY7CjepAqXzJwglIbwJzff4H9p2JwgIFKv7Fa WWG2Jp0aBFNoU+3KT8DVlc6nWxfKzCjM5B2rb02NG1xqZUQGcca5DswNLB17q1kbNqYJ EgiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=qabS3Yt4uR7Wnjipl66o4GWZ5y8XuRMfgvjQy7cEXTE=; b=EiDwJ8bLGyCeMhaGCrUokgA72wb18e4LW6++GjY5GyeIqlLLYR4eDYDLhwqx72JGl2 JCAdW5wzlFlD5PYJgE3+6SQs77Wn+auZx0/kaRZgfVgsDnuklP/wPeNSHOlja0IR2GfU TqgOfQsV31Gq6qjvr3fLTp6XVWNVocAGEpVE/3aH5DQ2KFXN1mPZ/UXiiO/Fo6U+zRZa LI3pnEvfQHZYUrdjZ8ux4bNOXrboJfvatrr0l8tdT5kQ5AeozQYNbCwLl+2LgUoH3cTY DAgxKwtXnzVsuA4SrCyLVeWmeqDOs95WQmHEboV0zc9pC0r230c7hRm5/KniGZdlck8l gbow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nvNcbWKu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r10si1208639otn.241.2020.02.21.00.40.10; Fri, 21 Feb 2020 00:40:22 -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=@google.com header.s=20161025 header.b=nvNcbWKu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731131AbgBUIjf (ORCPT + 99 others); Fri, 21 Feb 2020 03:39:35 -0500 Received: from mail-pl1-f202.google.com ([209.85.214.202]:33253 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731537AbgBUIje (ORCPT ); Fri, 21 Feb 2020 03:39:34 -0500 Received: by mail-pl1-f202.google.com with SMTP id bd7so779040plb.0 for ; Fri, 21 Feb 2020 00:39:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=qabS3Yt4uR7Wnjipl66o4GWZ5y8XuRMfgvjQy7cEXTE=; b=nvNcbWKu8TZNixlQBARlGWvQL9w2bfJZsHHUJB/opCZ64YXTz5gE1urGDpo+gRSCru ODY+TPoZeb0nOaehsVaJEbGtE58GPgpSRYb2shnRFE50uGpj+9B3fAyxnJDFxS+vmCLi o0Pd3d0cGDn3ldlssZpu/bccNKRtyGP1eXHT+JkwshorviJoNEvRzLSDnLN2KuFbDxB8 N51pucLgRPl59FtYxPYUWZpD/Qa8Tl82Grx3akhZFbC4eUrbLTonRrd6wINl32sf+9y/ gBmkJhjNm50H+TBHEwF65c8TUa0kKvLem17I3/RbtVV0+lPSxRWTV/3EhbR2EoPWLWzk xqFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=qabS3Yt4uR7Wnjipl66o4GWZ5y8XuRMfgvjQy7cEXTE=; b=g+tKT+O+gGDGof3lPiUOwMDLJcd6433vG7GUXGiKfuSDNo5R9+7N73EMp+wL6lFLBx bwYzRtfq394WoFhzQ8OWR8+GMJ6WbxWME/dV7coQvqdiH8r9aIh44jfJCUWC/WqCwDn8 nIErWZRF2s/IXULe35q39BSJ8zi+kZo7MthSLqWpl8Eo181ipBKf+9rwEr5HJLxLUnV1 8iR+qg1zRF97UF/2ERAJyqtKfE2l+zLV7o8ImIYTispVCQ42KWexJoEJ8PiAMphFNSy9 BpGhdtXd6Y6yQIBi8SsjpK3QzsqkotMviN7OnQUgn/SB0YvJjR5FEtYw1jikHsSTdPr4 mW6A== X-Gm-Message-State: APjAAAU1zWjwDnsy5kR2LCeW5wuEZHs+o8p0lp0ZfX2L8AkCn5WIMvlM ipN+B01FUe+rTBYHUUKK49ZROcEfIhtfnryCm7TmIEhD5Cp9MTT94nyIlyHNNZM3MKvXbZa10DJ 9tT3zBzb0pCzGlEMGaKyVLBZB1qtqh3hfGAvonuXPphni4mRMWULWEwsB8RTkK7Cuxm7l6kqnPu hN X-Received: by 2002:a63:ad0c:: with SMTP id g12mr36851945pgf.228.1582274373240; Fri, 21 Feb 2020 00:39:33 -0800 (PST) Date: Fri, 21 Feb 2020 16:39:23 +0800 Message-Id: <20200221163911.Bluez.v1.1.I3c505b4307094eb7a6f2c5949125a17c89b2e099@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [Bluez PATCH v1] src/profile: Ensure class UUID matches before connecting profile From: Archie Pusaka To: linux-bluetooth Cc: Archie Pusaka 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 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. --- 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); + + 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