linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Mullen <omaolaip@tcd.ie>
To: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: [PATCH BlueZ 1/3] profile: Add Vendor/Product ID profile matching
Date: Fri, 16 Oct 2020 15:09:32 -0700	[thread overview]
Message-ID: <efec3d63-119b-6956-5345-c9b19c71cbd5@tcd.ie> (raw)

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



                 reply	other threads:[~2020-10-16 22:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=efec3d63-119b-6956-5345-c9b19c71cbd5@tcd.ie \
    --to=omaolaip@tcd.ie \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).