core: Add new policy for Just-Works repairing
authorhowardchung@google.com <howardchung@google.com>
Sat, 15 Feb 2020 03:44:33 +0000 (11:44 +0800)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 12 Apr 2021 09:00:48 +0000 (14:30 +0530)
When kernel find out that the incoming Just-Works pairing is
initiated by a paired device, it is user space's responsibility to
decide the next action.

This patch includes the following:
- add JustWorksRepairing policy as an option in main.conf
- handle the confirmation request from kernel

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/device.c
src/hcid.h
src/main.c
src/main.conf

index fc6bfd8..9ecc27b 100644 (file)
@@ -8750,6 +8750,21 @@ int device_confirm_passkey(struct btd_device *device, uint8_t type,
        struct authentication_req *auth;
        int err;
 
+       /* Just-Works repairing policy */
+       if (confirm_hint && device_is_paired(device, type)) {
+               if (main_opts.jw_repairing == JW_REPAIRING_NEVER) {
+                       btd_adapter_confirm_reply(device->adapter,
+                                                 &device->bdaddr,
+                                                 type, FALSE);
+                       return 0;
+               } else if (main_opts.jw_repairing == JW_REPAIRING_ALWAYS) {
+                       btd_adapter_confirm_reply(device->adapter,
+                                                 &device->bdaddr,
+                                                 type, TRUE);
+                       return 0;
+               }
+       }
+
        auth = new_auth(device, type, AUTH_TYPE_CONFIRM, FALSE);
        if (!auth)
                return -EPERM;
index 29c3083..b874c22 100755 (executable)
@@ -35,6 +35,12 @@ typedef enum {
        BT_GATT_CACHE_NO,
 } bt_gatt_cache_t;
 
+enum jw_repairing_t {
+       JW_REPAIRING_NEVER,
+       JW_REPAIRING_CONFIRM,
+       JW_REPAIRING_ALWAYS,
+};
+
 struct main_opts {
        char            *name;
        uint32_t        class;
@@ -63,6 +69,8 @@ struct main_opts {
        uint16_t        gatt_mtu;
 
        uint8_t         key_size;
+
+       enum jw_repairing_t jw_repairing;
 };
 
 extern struct main_opts main_opts;
index ff8c020..5585f4f 100755 (executable)
@@ -92,6 +92,7 @@ static const char *supported_options[] = {
        "MultiProfile",
        "FastConnectable",
        "Privacy",
+       "JustWorksRepairing",
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        "EnableLEPrivacy",
        "PinCode",
@@ -197,6 +198,20 @@ static bt_gatt_cache_t parse_gatt_cache(const char *cache)
        }
 }
 
+static enum jw_repairing_t parse_jw_repairing(const char *jw_repairing)
+{
+       if (!strcmp(jw_repairing, "never")) {
+               return JW_REPAIRING_NEVER;
+       } else if (!strcmp(jw_repairing, "confirm")) {
+               return JW_REPAIRING_CONFIRM;
+       } else if (!strcmp(jw_repairing, "always")) {
+               return JW_REPAIRING_ALWAYS;
+       } else {
+               return JW_REPAIRING_NEVER;
+       }
+}
+
+
 static void check_options(GKeyFile *config, const char *group,
                                                const char **options)
 {
@@ -335,6 +350,18 @@ static void parse_config(GKeyFile *config)
                g_free(str);
        }
 
+       str = g_key_file_get_string(config, "General",
+                                               "JustWorksRepairing", &err);
+       if (err) {
+               DBG("%s", err->message);
+               g_clear_error(&err);
+               main_opts.jw_repairing = JW_REPAIRING_NEVER;
+       } else {
+               DBG("just_works_repairing=%s", str);
+               main_opts.jw_repairing = parse_jw_repairing(str);
+               g_free(str);
+       }
+
        str = g_key_file_get_string(config, "General", "Name", &err);
        if (err) {
                DBG("%s", err->message);
index d947260..9cdc6d5 100755 (executable)
 # Defaults to "off"
 # Privacy = off
 
+# Specify the policy to the JUST-WORKS repairing initiated by peer
+# Possible values: "never", "confirm", "always"
+# Defaults to "never"
+#JustWorksRepairing = never
+
 [GATT]
 # GATT attribute cache.
 # Possible values: