Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1560326pxu; Fri, 16 Oct 2020 15:37:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJHU1nw33qm64Tw6xN2FVuZP9/H984ukNh7bOmu8sL3RrwRe9WpJQzpfHp8MkaFFrNJ11T X-Received: by 2002:a17:906:e2d1:: with SMTP id gr17mr5998378ejb.433.1602887831168; Fri, 16 Oct 2020 15:37:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602887831; cv=none; d=google.com; s=arc-20160816; b=p2XLMvO303OlfKaR6Iodujr+mI5QviC0FFCOpxa2cayVAsMNa5EHipPkp5hvk47W0w n/W5zkhNQeBY2nA8L/h2EgCQEbKBUCtemfP0ekNknx8Y4bQViQIPLufz29L/GLExyWVF 2Cuv+7+USNdC5xN/VbX0VYV7o342E3COoQ5j1PXyADaacEWDgdn9pAolkbkHtY76B8zt kiv2eHOgUUaEVpLq7FfX1Lz5CoskOQWAvtOAoen8muh7mEVNVWErZm2CpDycEQ22Uwxo qvhf61JSOIWzoA9A4IR0nVK2xvWwO59Hk1jGTjyfH9+KwJ2AziHSs+1ZvodQSgqCLsbO hwiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:user-agent:date:message-id:to:subject:from :dkim-signature; bh=n1+giSsolW0YEWNRCDDe69POzBrY4Vg661V09byvQ1M=; b=iOuZl2t9BlF4bOCEr3mKi001vU6o77nQuxl68Eq7SrehYZugONvjS00AClo939GX+t XGaQviFt/IDhQqmMfF/2neLS7C7XwIFffkq65midKl2GPlD3aXjAXrcEg3tODw+fkR8b e3b24o30T+ek9soZdySdDb0gL4ieyMiwIUcEXJ1gpFRPuZBwupSU1OXwXZbUYulhHx+g TkyGfGUurDHRgAgeNpNaiuRBSG+LKXxmKlcAycZvVDFng10CwYHWPdcCQM8ZCmtMFiUQ w7wR9d0n7EKCP2anFOze5ukFXfnbATwTKJVwUOZyLcihTRP9b8r32Y19IoQWlWAYVLUO B8MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tcd-ie.20150623.gappssmtp.com header.s=20150623 header.b=gwhDZMwh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v6si2733696edt.456.2020.10.16.15.36.47; Fri, 16 Oct 2020 15:37:11 -0700 (PDT) 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=@tcd-ie.20150623.gappssmtp.com header.s=20150623 header.b=gwhDZMwh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388813AbgJPWJe (ORCPT + 99 others); Fri, 16 Oct 2020 18:09:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388807AbgJPWJe (ORCPT ); Fri, 16 Oct 2020 18:09:34 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE9C8C061755 for ; Fri, 16 Oct 2020 15:09:33 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id hk7so2249502pjb.2 for ; Fri, 16 Oct 2020 15:09:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:subject:to:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=n1+giSsolW0YEWNRCDDe69POzBrY4Vg661V09byvQ1M=; b=gwhDZMwhkvBD1mpqF9lT0hEJgN7e1RoMkyYGvcX8xMH/qKU/jnReOh86d82s8/tKil Zzw8qxn+e0Edfi14Hr4FN+Q5tqBqZzsIaa3dDESNVoZQsaYY4ZfcZRLKLBG2blH4tpiI a1FTn/4cpkWkaXd2wPQrVDFncaL7xA3e24oKnGQU1B7FdQUO/E+1wVhofbWwvcl/CGxX OiaqMSYc77Lc0mAVIrhQk5kor0i/GqING+s4EIqQklmmH2pp8a6tS77jvBADg5h9ioIz iyqY0okw5DVWgjfl/htMpv3kdCIuSve0KxhgiMePMTm/C7A59E3Fv11gOJ8XnHTP46lP rwVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=n1+giSsolW0YEWNRCDDe69POzBrY4Vg661V09byvQ1M=; b=L8hm0cZrTBY5k9abtgy8OxpsbDo1eBVbAo3rwJ4ew7i41rei8/sZNg9Dg3A+Y18gZA AyBpTuJn7SPKm5SA5pJPSewPrRvdxsiCQZ62o/LyVkHKmsK++udPdhxssOYNQau62cwr J/oyynqdmWyn/9RMW0dFCUTUdGNqN3GuQ6yuLcY4i3M4vhPCcDXxqT7Fp1YktGaosU0E 5TBBw7uX3LGJYgVTsucfsEE+VSElPkrPgXI77EMNxx7vCfzQZh9CFEdvzW7VzSADZRFX vv429EDScY/OuXTB17P/PXGRuk20G4W3OLaPMjJ28PsWaITE9wyUlX2u7lo6pxGIS7JH 2i4w== X-Gm-Message-State: AOAM532keU6o6alJc2OU73xMrldAiGXFOvUe0ibbM+YhxdCeMbaPFARr lWCp5CB/yG+v9EG/zwDK8en1KBgItgR3wqEE X-Received: by 2002:a17:902:8348:b029:d3:781a:5857 with SMTP id z8-20020a1709028348b02900d3781a5857mr5940234pln.2.1602886173218; Fri, 16 Oct 2020 15:09:33 -0700 (PDT) Received: from [192.168.2.14] (216-19-182-159.dyn.novuscom.net. [216.19.182.159]) by smtp.gmail.com with ESMTPSA id z18sm3780604pfn.158.2020.10.16.15.09.32 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Oct 2020 15:09:32 -0700 (PDT) From: Peter Mullen Subject: [PATCH BlueZ 1/3] profile: Add Vendor/Product ID profile matching To: "linux-bluetooth@vger.kernel.org" Message-ID: Date: Fri, 16 Oct 2020 15:09:32 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Extend the process for matching profiles to devices by adding vid/pid fields to btd_profile. If no remote_uuid is supplied, attempt to match based on the new fields. If only vid field is set, ignore pid during matching. --- src/device.c | 37 ++++++++++++++++++++++++++----------- src/profile.h | 3 +++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/device.c b/src/device.c index a5ef46730..2cb2ceb2e 100644 --- a/src/device.c +++ b/src/device.c @@ -329,7 +329,8 @@ static GSList *find_service_with_uuid(GSList *list, char *uuid) struct btd_service *service = l->data; struct btd_profile *profile = btd_service_get_profile(service); - if (bt_uuid_strcmp(profile->remote_uuid, uuid) == 0) + if (profile->remote_uuid && + bt_uuid_strcmp(profile->remote_uuid, uuid) == 0) return l; } @@ -1901,11 +1902,19 @@ static struct btd_service *find_connectable_service(struct btd_device *dev, struct btd_service *service = l->data; struct btd_profile *p = btd_service_get_profile(service); - if (!p->connect || !p->remote_uuid) + if (!p->connect) continue; - if (strcasecmp(uuid, p->remote_uuid) == 0) + if (p->remote_uuid && strcasecmp(uuid, p->remote_uuid) == 0) return service; + + if (p->vendor_id && p->vendor_id == + btd_device_get_vendor(dev)) { + if (p->product_id && p->product_id != + btd_device_get_product(dev)) + continue; + return service; + } } return NULL; @@ -3800,14 +3809,18 @@ static bool device_match_profile(struct btd_device *device, struct btd_profile *profile, GSList *uuids) { - if (profile->remote_uuid == NULL) - return false; - - if (g_slist_find_custom(uuids, profile->remote_uuid, - bt_uuid_strcmp) == NULL) - return false; + if (profile->remote_uuid && g_slist_find_custom(uuids, + profile->remote_uuid, bt_uuid_strcmp) != NULL) + return true; - return true; + if (profile->vendor_id && profile->vendor_id == + btd_device_get_vendor(device)) { + if (profile->product_id && profile->product_id != + btd_device_get_product(device)) + return false; + return true; + } + return false; } static void add_gatt_service(struct gatt_db_attribute *attr, void *user_data) @@ -6729,6 +6742,8 @@ void btd_device_set_record(struct btd_device *device, const char *uuid, const sdp_record_t *btd_device_get_record(struct btd_device *device, const char *uuid) { + if (uuid == NULL) + return NULL; /* Load records from storage if there is nothing in cache */ if (!device->tmp_records) { device->tmp_records = read_device_records(device); @@ -6881,7 +6896,7 @@ struct btd_service *btd_device_get_service(struct btd_device *dev, struct btd_service *service = l->data; struct btd_profile *p = btd_service_get_profile(service); - if (g_str_equal(p->remote_uuid, remote_uuid)) + if (p->remote_uuid && g_str_equal(p->remote_uuid, remote_uuid)) return service; } diff --git a/src/profile.h b/src/profile.h index 6827f8481..fe882a843 100644 --- a/src/profile.h +++ b/src/profile.h @@ -21,6 +21,9 @@ struct btd_profile { const char *local_uuid; const char *remote_uuid; + uint16_t vendor_id; + uint16_t product_id; + bool auto_connect; /* Some profiles are considered safe to be handled internally and also * be exposed in the GATT API. This flag give such profiles exception -- 2.28.0