2021-04-01 10:32:38

by Yun-hao Chung

[permalink] [raw]
Subject: [Bluez PATCH 4/8] input/hog: block connection by policy

This blocks HoG connection if ServiceAllowList is set and some of the
mandatory services are not in the allowlist.

Reviewed-by: Miao-chen Chou <[email protected]>
---

profiles/input/hog.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/profiles/input/hog.c b/profiles/input/hog.c
index d50b823213b5..af4f73daf2b1 100644
--- a/profiles/input/hog.c
+++ b/profiles/input/hog.c
@@ -168,6 +168,27 @@ static void hog_remove(struct btd_service *service)
hog_device_free(dev);
}

+static bool mandatory_services_are_allowed(struct btd_service *service)
+{
+ static const char * const mandatory_uuids[] = {DEVICE_INFORMATION_UUID,
+ BATTERY_UUID, HOG_UUID, NULL};
+ struct btd_device *device = btd_service_get_device(service);
+ struct btd_adapter *adapter = device_get_adapter(device);
+ struct btd_profile *p = btd_service_get_profile(service);
+
+ int i;
+
+ for (i = 0; mandatory_uuids[i] != NULL; i++) {
+ if (!btd_adapter_uuid_is_allowed(adapter, mandatory_uuids[i])) {
+ DBG("mandatory service %s is blocked by policy",
+ mandatory_uuids[i]);
+ return false;
+ }
+ }
+
+ return true;
+}
+
static int hog_accept(struct btd_service *service)
{
struct hog_device *dev = btd_service_get_user_data(service);
@@ -221,6 +242,7 @@ static struct btd_profile hog_profile = {
.accept = hog_accept,
.disconnect = hog_disconnect,
.auto_connect = true,
+ .mandatory_services_are_allowed = mandatory_services_are_allowed,
};

static int hog_init(void)
--
2.31.0.291.g576ba9dcdaf-goog