input: Add LEAutoSecurity setting to input.conf
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 11 Mar 2020 18:43:21 +0000 (11:43 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 12 Apr 2021 09:00:48 +0000 (14:30 +0530)
LEAutoSecurity can be used to enable/disable automatic upgrades of
security for LE devices, by default it is enabled so existing devices
that did not require security and were not bonded will automatically
upgrade the security.

Note: Platforms disabling this setting would require users to manually
bond the device which may require changes to the user interface to
always force bonding for input devices as APIs such as Device.Connect
will no longer work which maybe perceived as a regression.

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

index e8cad27..3174027 100755 (executable)
@@ -31,6 +31,9 @@ void input_set_idle_timeout(int timeout);
 void input_enable_userspace_hid(bool state);
 void input_set_classic_bonded_only(bool state);
 
+#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
+void input_set_auto_sec(bool state);
+#endif
 int input_device_register(struct btd_service *service);
 void input_device_unregister(struct btd_service *service);
 
index f0226eb..d496f22 100755 (executable)
 #include "src/shared/gatt-client.h"
 #include "src/plugin.h"
 
+#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
+#include "device.h"
+#endif
+
 #include "suspend.h"
 #include "attrib/att.h"
 #include "attrib/gattrib.h"
@@ -67,8 +71,16 @@ struct hog_device {
 };
 
 static gboolean suspend_supported = FALSE;
+#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
+static bool auto_sec = true;
+#endif
 static struct queue *devices = NULL;
-
+#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
+void input_set_auto_sec(bool state)
+{
+       auto_sec = state;
+}
+#endif
 static void hog_device_accept(struct hog_device *dev, struct gatt_db *db)
 {
        char name[248];
@@ -191,12 +203,14 @@ static int hog_accept(struct btd_service *service)
        /* HOGP 1.0 Section 6.1 requires bonding */
        if (!device_is_bonded(device, btd_device_get_bdaddr_type(device))) {
                struct bt_gatt_client *client;
-
+#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
+               if (!auto_sec)
+                       return -ECONNREFUSED;
+#endif
                client = btd_device_get_gatt_client(device);
                if (!bt_gatt_client_set_security(client,
-                                               BT_ATT_SECURITY_MEDIUM)) {
+                                               BT_ATT_SECURITY_MEDIUM))
                        return -ECONNREFUSED;
-               }
        }
 
        /* TODO: Replace GAttrib with bt_gatt_client */
index 166aff4..2c18fa1 100755 (executable)
 # pairing/encryption.
 # Defaults to false to maximize device compatibility.
 #ClassicBondedOnly=true
+
+#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
+# LE upgrade security
+# Enables upgrades of security automatically if required.
+# Defaults to true to maximize device compatibility.
+#LEAutoSecurity=true
+#endif
index 696dbc9..d3322b2 100755 (executable)
@@ -127,8 +127,11 @@ static int input_init(void)
        config = load_config_file(CONFIGDIR "/input.conf");
        if (config) {
                int idle_timeout;
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
                gboolean uhid_enabled, classic_bonded_only;
-
+#else
+               gboolean uhid_enabled, classic_bonded_only, auto_sec;
+#endif
                idle_timeout = g_key_file_get_integer(config, "General",
                                                        "IdleTimeout", &err);
                if (!err) {
@@ -155,7 +158,16 @@ static int input_init(void)
                        input_set_classic_bonded_only(classic_bonded_only);
                } else
                        g_clear_error(&err);
-
+#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
+               auto_sec = g_key_file_get_boolean(config, "General",
+                                               "LEAutoSecurity", &err);
+               if (!err) {
+                       DBG("input.conf: LEAutoSecurity=%s",
+                                       auto_sec ? "true" : "false");
+                       input_set_auto_sec(auto_sec);
+               } else
+                       g_clear_error(&err);
+#endif
        }
 
        btd_profile_register(&input_profile);