diff mbox series

[Bluez,4/8] input/hog: block connection by policy

Message ID 20210401182328.Bluez.4.I6981df13b7eda6fd9e0a46f11211565a3826ec95@changeid
State New
Headers show
Series Hi Linux-bluetooth, | expand

Commit Message

Yun-hao Chung April 1, 2021, 10:24 a.m. UTC
This blocks HoG connection if ServiceAllowList is set and some of the
mandatory services are not in the allowlist.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
---

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

Patch

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)