input: encrypt on receive conn req if classic_bonded_only
authorArchie Pusaka <apusaka@chromium.org>
Wed, 22 Jul 2020 16:20:33 +0000 (00:20 +0800)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 12 Apr 2021 09:00:50 +0000 (14:30 +0530)
According to bluetooth HID1.1 spec, section 5.4.3.5.3:
If the Bluetooth HID Host is bonded to a Bluetooth HID device:
If encryption is not already enabled, the Bluetooth HID Host shall
enable encryption with the Bluetooth HID device before sending an
L2CAP Connect Response with a result code of “Connection Successful”
(0x0000) after an L2CAP Connect Request is received.

This patch raises the security level to medium when listening for
incoming connection if the flag classic_bonded_only is set,
effectively starting encryption.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
profiles/input/device.c
profiles/input/device.h
profiles/input/server.c

index fc02b64..2870bea 100644 (file)
@@ -111,6 +111,11 @@ void input_set_classic_bonded_only(bool state)
        classic_bonded_only = state;
 }
 
+bool input_get_classic_bonded_only(void)
+{
+       return classic_bonded_only;
+}
+
 static void input_device_enter_reconnect_mode(struct input_device *idev);
 static int connection_disconnect(struct input_device *idev, uint32_t flags);
 
index 3174027..e3dcbce 100755 (executable)
@@ -30,6 +30,7 @@ struct input_conn;
 void input_set_idle_timeout(int timeout);
 void input_enable_userspace_hid(bool state);
 void input_set_classic_bonded_only(bool state);
+bool input_get_classic_bonded_only(void);
 
 #ifndef TIZEN_FEATURE_BLUEZ_MODIFY
 void input_set_auto_sec(bool state);
index 279694c..974b615 100755 (executable)
@@ -308,6 +308,10 @@ int server_start(const bdaddr_t *src)
        struct input_server *server;
        GError *err = NULL;
 
+#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
+       BtIOSecLevel sec_level = input_get_classic_bonded_only() ?
+                                       BT_IO_SEC_MEDIUM : BT_IO_SEC_LOW;
+#endif
        server = g_new0(struct input_server, 1);
        bacpy(&server->src, src);
 
@@ -318,7 +322,7 @@ int server_start(const bdaddr_t *src)
 #ifdef TIZEN_BT_HID_DEVICE_ENABLE
                                BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
 #else
-                               BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
+                               BT_IO_OPT_SEC_LEVEL, sec_level,
 #endif
                                BT_IO_OPT_INVALID);
        if (!server->ctrl) {
@@ -335,7 +339,7 @@ int server_start(const bdaddr_t *src)
 #ifdef TIZEN_BT_HID_DEVICE_ENABLE
                                BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
 #else
-                               BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
+                               BT_IO_OPT_SEC_LEVEL, sec_level,
 #endif
                                BT_IO_OPT_INVALID);
        if (!server->intr) {