summaryrefslogtreecommitdiff
path: root/src/device.c
diff options
context:
space:
mode:
authorYun-Hao Chung <howardchung@chromium.org>2021-08-03 19:43:07 +0800
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2021-08-04 15:01:33 -0700
commitb084a69a067dd520b4eabcd8ddfaa15b614166b4 (patch)
tree543a2af83affa9650f1981ed44d86a0bf4d92205 /src/device.c
parent86aa6bc91d5458b1c2ef1138e97fb37af4f7939c (diff)
downloadbluez-b084a69a067dd520b4eabcd8ddfaa15b614166b4.tar.gz
core: add adapter and device allowed_uuid functions
This implements functions in src/adapter.c and src/device.c for plugins setting a list of allowed services. Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/src/device.c b/src/device.c
index 49dd57166..807106812 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1929,6 +1929,56 @@ static int service_prio_cmp(gconstpointer a, gconstpointer b)
return p2->priority - p1->priority;
}
+bool btd_device_all_services_allowed(struct btd_device *dev)
+{
+ GSList *l;
+ struct btd_adapter *adapter = dev->adapter;
+ struct btd_service *service;
+ struct btd_profile *profile;
+
+ for (l = dev->services; l != NULL; l = g_slist_next(l)) {
+ service = l->data;
+ profile = btd_service_get_profile(service);
+
+ if (!profile || !profile->auto_connect)
+ continue;
+
+ if (!btd_adapter_is_uuid_allowed(adapter, profile->remote_uuid))
+ return false;
+ }
+
+ return true;
+}
+
+void btd_device_update_allowed_services(struct btd_device *dev)
+{
+ struct btd_adapter *adapter = dev->adapter;
+ struct btd_service *service;
+ struct btd_profile *profile;
+ GSList *l;
+ bool is_allowed;
+ char addr[18];
+
+ /* If service discovery is ongoing, let the service discovery complete
+ * callback call this function.
+ */
+ if (dev->browse) {
+ ba2str(&dev->bdaddr, addr);
+ DBG("service discovery of %s is ongoing. Skip updating allowed "
+ "services", addr);
+ return;
+ }
+
+ for (l = dev->services; l != NULL; l = g_slist_next(l)) {
+ service = l->data;
+ profile = btd_service_get_profile(service);
+
+ is_allowed = btd_adapter_is_uuid_allowed(adapter,
+ profile->remote_uuid);
+ btd_service_set_allowed(service, is_allowed);
+ }
+}
+
static GSList *create_pending_list(struct btd_device *dev, const char *uuid)
{
struct btd_service *service;
@@ -1937,9 +1987,14 @@ static GSList *create_pending_list(struct btd_device *dev, const char *uuid)
if (uuid) {
service = find_connectable_service(dev, uuid);
- if (service)
+
+ if (!service)
+ return dev->pending;
+
+ if (btd_service_is_allowed(service))
return g_slist_prepend(dev->pending, service);
+ info("service %s is blocked", uuid);
return dev->pending;
}
@@ -1950,6 +2005,11 @@ static GSList *create_pending_list(struct btd_device *dev, const char *uuid)
if (!p->auto_connect)
continue;
+ if (!btd_service_is_allowed(service)) {
+ info("service %s is blocked", p->remote_uuid);
+ continue;
+ }
+
if (g_slist_find(dev->pending, service))
continue;
@@ -2634,6 +2694,7 @@ static void device_svc_resolved(struct btd_device *dev, uint8_t browse_type,
g_free(cb);
}
+ btd_device_update_allowed_services(dev);
device_resolved_drivers(dev->adapter, dev);
}