Listen and process remote name resolving failure
authorArchie Pusaka <apusaka@chromium.org>
Thu, 25 Nov 2021 07:06:24 +0000 (15:06 +0800)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:38 +0000 (19:08 +0530)
When Remote Name Resolve ends with failure, record this occurrence and
prevent remote name resolving for the same device for some time.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/adapter.c
src/adapter.h
src/adv_monitor.c
src/device.c
src/device.h

index 227595d..f3c2dc4 100644 (file)
@@ -12088,6 +12088,7 @@ void btd_adapter_update_found_device(struct btd_adapter *adapter,
                                        const bdaddr_t *bdaddr,
                                        uint8_t bdaddr_type, int8_t rssi,
                                        bool confirm, bool legacy, uint8_t adv_type,
+                                       bool name_resolve_failed,
                                        const uint8_t *data, uint8_t data_len,
                                        bool monitoring)
 #else
@@ -12096,6 +12097,7 @@ void btd_adapter_update_found_device(struct btd_adapter *adapter,
                                        uint8_t bdaddr_type, int8_t rssi,
                                        bool confirm, bool legacy,
                                        bool not_connectable,
+                                       bool name_resolve_failed,
                                        const uint8_t *data, uint8_t data_len,
                                        bool monitoring)
 #endif
@@ -12263,6 +12265,9 @@ void btd_adapter_update_found_device(struct btd_adapter *adapter,
 
        device_set_legacy(dev, legacy);
 
+       if (name_resolve_failed)
+               device_name_resolve_fail(dev);
+
        if (adapter->filtered_discovery)
                device_set_rssi_with_delta(dev, rssi, 0);
        else
@@ -12367,7 +12372,10 @@ void btd_adapter_update_found_device(struct btd_adapter *adapter,
        if (g_slist_find(adapter->discovery_found, dev))
                return;
 
-       if (confirm)
+       /* If name is unknown but it's not allowed to resolve, don't send
+        * MGMT_OP_CONFIRM_NAME.
+        */
+       if (confirm && (name_known || device_is_name_resolve_allowed(dev)))
                confirm_name(adapter, bdaddr, bdaddr_type, name_known);
 
        adapter->discovery_found = g_slist_prepend(adapter->discovery_found,
@@ -12419,10 +12427,11 @@ static void device_found_callback(uint16_t index, uint16_t length,
        uint32_t flags;
        bool confirm_name;
        bool legacy;
-       char addr[18];
 #ifndef TIZEN_FEATURE_BLUEZ_MODIFY
        bool not_connectable;
 #endif
+       bool name_resolve_failed;
+       char addr[18];
        if (length < sizeof(*ev)) {
                btd_error(adapter->dev_id,
                        "Too short device found event (%u bytes)", length);
@@ -12453,14 +12462,16 @@ static void device_found_callback(uint16_t index, uint16_t length,
 #ifndef TIZEN_FEATURE_BLUEZ_MODIFY
        not_connectable = (flags & MGMT_DEV_FOUND_NOT_CONNECTABLE);
 #endif
+       name_resolve_failed = (flags & MGMT_DEV_FOUND_NAME_REQUEST_FAILED);
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        btd_adapter_update_found_device(adapter, &ev->addr.bdaddr, ev->addr.type,
                                        ev->rssi, confirm_name, legacy, 0,
+                                       name_resolve_failed,
                                        eir, eir_len, false);
 #else
        btd_adapter_update_found_device(adapter, &ev->addr.bdaddr, ev->addr.type,
                                        ev->rssi, confirm_name, legacy,
-                                       not_connectable,
+                                       not_connectable, name_resolve_failed,
                                        eir, eir_len, false);
 #endif
 }
@@ -12477,6 +12488,7 @@ static void le_device_found_callback(uint16_t index, uint16_t length,
        bool confirm_name;
        bool legacy;
        char addr[18];
+       bool name_resolve_failed;
 
        if (length < sizeof(*ev)) {
                error("Too short device found event (%u bytes)", length);
@@ -12506,10 +12518,10 @@ static void le_device_found_callback(uint16_t index, uint16_t length,
 
        /*DBG("hci%u addr %s, addr_type %d rssi %d flags 0x%04x eir_len %u confirm_name %d legacy %d, adv_type %02x",
                        index, addr, ev->addr.type, ev->rssi, flags, eir_len, confirm_name, legacy, ev->adv_type);*/
-
+       name_resolve_failed = (flags & MGMT_DEV_FOUND_NAME_REQUEST_FAILED);
        btd_adapter_update_found_device(adapter, &ev->addr.bdaddr, ev->addr.type,
                                        ev->rssi, confirm_name, legacy, ev->adv_type,
-                                       eir, eir_len, false);
+                                       name_resolve_failed, eir, eir_len, false);
 }
 #endif
 
index cdd334d..a21bdc7 100644 (file)
@@ -168,6 +168,7 @@ void btd_adapter_update_found_device(struct btd_adapter *adapter,
                                        const bdaddr_t *bdaddr,
                                        uint8_t bdaddr_type, int8_t rssi,
                                        bool confirm, bool legacy, uint8_t adv_type,
+                                       bool name_resolve_failed,
                                        const uint8_t *data, uint8_t data_len,
                                        bool monitoring);
 #else
@@ -176,6 +177,7 @@ void btd_adapter_update_found_device(struct btd_adapter *adapter,
                                        uint8_t bdaddr_type, int8_t rssi,
                                        bool confirm, bool legacy,
                                        bool not_connectable,
+                                       bool name_resolve_failed,
                                        const uint8_t *data, uint8_t data_len,
                                        bool monitored);
 #endif
index 04646c1..57e7973 100644 (file)
@@ -1584,8 +1584,9 @@ static void adv_monitor_device_found_callback(uint16_t index, uint16_t length,
        uint32_t flags;
        bool confirm_name;
        bool legacy;
-       char addr[18];
        bool not_connectable;
+       bool name_resolve_failed;
+       char addr[18];
 
        if (length < sizeof(*ev)) {
                btd_error(adapter_id,
@@ -1612,10 +1613,12 @@ static void adv_monitor_device_found_callback(uint16_t index, uint16_t length,
        confirm_name = (flags & MGMT_DEV_FOUND_CONFIRM_NAME);
        legacy = (flags & MGMT_DEV_FOUND_LEGACY_PAIRING);
        not_connectable = (flags & MGMT_DEV_FOUND_NOT_CONNECTABLE);
+       name_resolve_failed = (flags & MGMT_DEV_FOUND_NAME_REQUEST_FAILED);
 
        btd_adapter_update_found_device(adapter, &ev->addr.bdaddr,
                                        ev->addr.type, ev->rssi, confirm_name,
-                                       legacy, not_connectable, ad_data,
+                                       legacy, not_connectable,
+                                       name_resolve_failed, ad_data,
                                        ad_data_len, true);
 
        if (handle) {
index 2439977..9b7a343 100644 (file)
@@ -84,6 +84,7 @@
 #define GATT_SND_SVC_UUID_STR  "2801"
 #define GATT_INCLUDE_UUID_STR "2802"
 #define GATT_CHARAC_UUID_STR "2803"
+#define NAME_RESOLVE_RETRY_DELAY       300 /* seconds */
 
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
 #define DEV_MAX_MANUFACTURER_DATA_LEN  248
@@ -318,6 +319,8 @@ struct btd_device {
 
        GIOChannel      *att_io;
        guint           store_id;
+
+       time_t          name_resolve_failed_time;
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        bool    legacy_pairing;
        char            *manufacturer_data;
@@ -6975,6 +6978,29 @@ bool device_name_known(struct btd_device *device)
        return device->name[0] != '\0';
 }
 
+bool device_is_name_resolve_allowed(struct btd_device *device)
+{
+       struct timespec now;
+
+       if (!device)
+               return false;
+
+       clock_gettime(CLOCK_MONOTONIC, &now);
+       return now.tv_sec >= device->name_resolve_failed_time +
+                                               NAME_RESOLVE_RETRY_DELAY;
+}
+
+void device_name_resolve_fail(struct btd_device *device)
+{
+       struct timespec now;
+
+       if (!device)
+               return;
+
+       clock_gettime(CLOCK_MONOTONIC, &now);
+       device->name_resolve_failed_time = now.tv_sec;
+}
+
 void device_set_class(struct btd_device *device, uint32_t class)
 {
        if (device->class == class)
index 8a6cf1a..7f97ac4 100644 (file)
@@ -39,6 +39,8 @@ void btd_device_device_set_name(struct btd_device *device, const char *name);
 void device_store_cached_name(struct btd_device *dev, const char *name);
 void device_get_name(struct btd_device *device, char *name, size_t len);
 bool device_name_known(struct btd_device *device);
+bool device_is_name_resolve_allowed(struct btd_device *device);
+void device_name_resolve_fail(struct btd_device *device);
 void device_set_class(struct btd_device *device, uint32_t class);
 void device_update_addr(struct btd_device *device, const bdaddr_t *bdaddr,
                                                        uint8_t bdaddr_type);