diff mbox series

[BlueZ,1/3] profile: Add Vendor/Product ID profile matching

Message ID efec3d63-119b-6956-5345-c9b19c71cbd5@tcd.ie (mailing list archive)
State New, archived
Headers show
Series [BlueZ,1/3] profile: Add Vendor/Product ID profile matching | expand

Commit Message

Peter Mullen Oct. 16, 2020, 10:09 p.m. UTC
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 mbox series

Patch

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