core: Add AlwaysPairable to main.conf
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 27 Jul 2018 08:14:04 +0000 (11:14 +0300)
committerhimanshu <h.himanshu@samsung.com>
Tue, 14 Jan 2020 08:53:35 +0000 (14:23 +0530)
This adds a new option called AlwaysPairable to main.conf, it can be
used to enable Adapter.Pairable even in case there is no Agent
available.

Since that could be consider a security problem to allow pairing
without user's consent the option defaults to false.

Change-Id: I67e534d5e8a6490ed2c99950c629d6e1ab493e30
Signed-off-by: himanshu <h.himanshu@samsung.com>
src/adapter.c
src/agent.h
src/device.c
src/hcid.h
src/main.c
src/main.conf

index b0207e2..5d5b3cc 100644 (file)
@@ -13143,6 +13143,19 @@ int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap)
 {
        struct mgmt_cp_set_io_capability cp;
 
+       if (!main_opts.pairable) {
+               if (io_cap == IO_CAPABILITY_INVALID) {
+                       if (adapter->current_settings & MGMT_SETTING_BONDABLE)
+                               set_mode(adapter, MGMT_OP_SET_BONDABLE, 0x00);
+
+                       return 0;
+               }
+
+               if (!(adapter->current_settings & MGMT_SETTING_BONDABLE))
+                       set_mode(adapter, MGMT_OP_SET_BONDABLE, 0x01);
+       } else if (io_cap == IO_CAPABILITY_INVALID)
+               io_cap = IO_CAPABILITY_NOINPUTNOOUTPUT;
+
        memset(&cp, 0, sizeof(cp));
        cp.io_capability = io_cap;
 
@@ -14609,7 +14622,8 @@ static void read_info_complete(uint8_t status, uint16_t length,
 
        set_name(adapter, btd_adapter_get_name(adapter));
 
-       if (!(adapter->current_settings & MGMT_SETTING_BONDABLE))
+       if (main_opts.pairable &&
+                       !(adapter->current_settings & MGMT_SETTING_BONDABLE))
                set_mode(adapter, MGMT_OP_SET_BONDABLE, 0x01);
 
        if (!kernel_conn_control)
index 1e46920..f14d143 100755 (executable)
  *
  */
 
+#define IO_CAPABILITY_DISPLAYONLY      0x00
+#define IO_CAPABILITY_DISPLAYYESNO     0x01
+#define IO_CAPABILITY_KEYBOARDONLY     0x02
+#define IO_CAPABILITY_NOINPUTNOOUTPUT  0x03
+#define IO_CAPABILITY_KEYBOARDDISPLAY  0x04
+#define IO_CAPABILITY_INVALID          0xFF
+
 struct agent;
 
 typedef void (*agent_cb) (struct agent *agent, DBusError *err,
index d105c83..0aedf9d 100644 (file)
@@ -82,8 +82,6 @@
 #endif /* TIZEN_FEATURE_BLUEZ_BATTERY_WATCH */
 #endif
 
-#define IO_CAPABILITY_NOINPUTNOOUTPUT  0x03
-
 #define DISCONNECT_TIMER       2
 #define DISCOVERY_TIMER                1
 #define INVALID_FLAGS          0xff
index 93ab5db..04de724 100755 (executable)
@@ -38,6 +38,7 @@ typedef enum {
 struct main_opts {
        char            *name;
        uint32_t        class;
+       gboolean        pairable;
        uint32_t        pairto;
        uint32_t        discovto;
        uint8_t         privacy;
index ec7f40b..8435e4e 100755 (executable)
@@ -82,6 +82,7 @@ static const char *supported_options[] = {
        "Name",
        "Class",
        "DiscoverableTimeout",
+       "AlwaysPairable"
        "PairableTimeout",
        "DeviceID",
        "ReverseServiceDiscovery",
@@ -294,6 +295,16 @@ static void parse_config(GKeyFile *config)
                main_opts.discovto = val;
        }
 
+       boolean = g_key_file_get_boolean(config, "General",
+                                               "AlwaysPairable", &err);
+       if (err) {
+               DBG("%s", err->message);
+               g_clear_error(&err);
+       } else {
+               DBG("pairable=%s", boolean ? "true" : "false");
+               main_opts.pairable = boolean;
+       }
+
        val = g_key_file_get_integer(config, "General",
                                                "PairableTimeout", &err);
        if (err) {
index 89b7922..e66b1d9 100755 (executable)
 # 0 = disable timer, i.e. stay discoverable forever
 #DiscoverableTimeout = 0
 
+# Always allow pairing even if there are no agent registered
+# Possible values: true, false
+# Default: false
+#AlwaysPairable = false
+
 # How long to stay in pairable mode before going back to non-discoverable
 # The value is in seconds. Default is 0.
 # 0 = disable timer, i.e. stay pairable forever