device: Add connectable flag to bearer state
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 9 Jun 2022 18:08:23 +0000 (11:08 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
This adds connectable flag to state so it can be used to detect which is
the last seen connectable bearer.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/adapter.c
src/device.c
src/device.h

index 91d8a39..e7867de 100644 (file)
@@ -7781,7 +7781,11 @@ static void device_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
 
        /* continue with service discovery and connection */
        btd_device_set_temporary(device, false);
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        device_update_last_seen(device, data->dst_type);
+#else
+       device_update_last_seen(device, data->dst_type, true);
+#endif
 
        if (data->dst_type != BDADDR_BREDR){
                g_io_channel_set_close_on_unref(io, FALSE);
@@ -12158,9 +12162,11 @@ void btd_adapter_update_found_device(struct btd_adapter *adapter,
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        if (device_get_rpa_exist(dev) == true)
                bdaddr_type = BDADDR_LE_RANDOM;
-#endif
 
        device_update_last_seen(dev, bdaddr_type);
+#else
+       device_update_last_seen(dev, bdaddr_type, !not_connectable);
+#endif
 
        /*
         * FIXME: We need to check for non-zero flags first because
@@ -12180,7 +12186,7 @@ void btd_adapter_update_found_device(struct btd_adapter *adapter,
                                        !(eir_data.flags & EIR_BREDR_UNSUP)) {
                device_set_bredr_support(dev);
                /* Update last seen for BR/EDR in case its flag is set */
-               device_update_last_seen(dev, BDADDR_BREDR);
+               device_update_last_seen(dev, BDADDR_BREDR, !not_connectable);
        }
 #endif
 
index 60f13a0..cbb2925 100644 (file)
@@ -174,6 +174,10 @@ struct bearer_state {
        bool connected;
        bool svc_resolved;
        bool initiator;
+#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
+       bool connectable;
+       time_t last_seen;
+#endif
 };
 
 struct csrk_info {
@@ -299,8 +303,10 @@ struct btd_device {
 
        sdp_list_t      *tmp_records;
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        time_t          bredr_seen;
        time_t          le_seen;
+#endif
 
        gboolean        trusted;
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
@@ -2876,14 +2882,24 @@ static uint8_t select_conn_bearer(struct btd_device *dev)
        if (dev->bdaddr_type == BDADDR_LE_RANDOM)
                return dev->bdaddr_type;
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        if (dev->bredr_seen) {
                bredr_last = current - dev->bredr_seen;
+#else
+       if (dev->bredr_state.last_seen) {
+               bredr_last = current - dev->bredr_state.last_seen;
+#endif
                if (bredr_last > SEEN_TRESHHOLD)
                        bredr_last = NVAL_TIME;
        }
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        if (dev->le_seen) {
                le_last = current - dev->le_seen;
+#else
+       if (dev->le_state.last_seen) {
+               le_last = current - dev->le_state.last_seen;
+#endif
                if (le_last > SEEN_TRESHHOLD)
                        le_last = NVAL_TIME;
        }
@@ -5431,7 +5447,11 @@ void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type)
 {
        struct bearer_state *state = get_state(dev, bdaddr_type);
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        device_update_last_seen(dev, bdaddr_type);
+#else
+       device_update_last_seen(dev, bdaddr_type, true);
+#endif
 
        if (state->connected) {
                char addr[18];
@@ -5606,7 +5626,11 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type)
        if (device->bredr_state.connected || device->le_state.connected)
                return;
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        device_update_last_seen(device, bdaddr_type);
+#else
+       device_update_last_seen(device, bdaddr_type, true);
+#endif
 
        g_slist_free_full(device->eir_uuids, g_free);
        device->eir_uuids = NULL;
@@ -6776,9 +6800,11 @@ void device_set_bredr_support(struct btd_device *device)
                                                                addr_str);
                return;
        }
-#endif
 
        if (device->bredr)
+#else
+       if (btd_opts.mode == BT_MODE_LE || device->bredr)
+#endif
                return;
 
        device->bredr = true;
@@ -6803,7 +6829,11 @@ void device_set_irk_value(struct btd_device *device, const uint8_t *val)
 
 void device_set_le_support(struct btd_device *device, uint8_t bdaddr_type)
 {
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        if (device->le)
+#else
+       if (btd_opts.mode == BT_MODE_BREDR || device->le)
+#endif
                return;
 
        device->le = true;
@@ -6812,12 +6842,26 @@ void device_set_le_support(struct btd_device *device, uint8_t bdaddr_type)
        store_device_info(device);
 }
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
 void device_update_last_seen(struct btd_device *device, uint8_t bdaddr_type)
+#else
+void device_update_last_seen(struct btd_device *device, uint8_t bdaddr_type,
+                                                       bool connectable)
+#endif
 {
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        if (bdaddr_type == BDADDR_BREDR)
                device->bredr_seen = time(NULL);
        else
                device->le_seen = time(NULL);
+#else
+       struct bearer_state *state;
+
+       state = get_state(device, bdaddr_type);
+
+       state->last_seen = time(NULL);
+       state->connectable = connectable;
+#endif
 
        if (!device_is_temporary(device))
                return;
@@ -9155,8 +9199,10 @@ bool device_is_connectable(struct btd_device *device)
        /* Check the ADV type. Some beacon device can be connectable regardless adv flags  */
        return device->le_connectable;
 #else
-       /* Check if either Limited or General discoverable are set */
-       return (device->ad_flags[0] & 0x03);
+       struct bearer_state *state;
+       state = get_state(device, device->bdaddr_type);
+
+       return state->connectable;
 #endif
 }
 
index 40ab265..c231e31 100644 (file)
@@ -47,7 +47,12 @@ void device_update_addr(struct btd_device *device, const bdaddr_t *bdaddr,
                                                        uint8_t bdaddr_type);
 void device_set_bredr_support(struct btd_device *device);
 void device_set_le_support(struct btd_device *device, uint8_t bdaddr_type);
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
 void device_update_last_seen(struct btd_device *device, uint8_t bdaddr_type);
+#else
+void device_update_last_seen(struct btd_device *device, uint8_t bdaddr_type,
+                                                       bool connectable);
+#endif
 void device_merge_duplicate(struct btd_device *dev, struct btd_device *dup);
 uint32_t btd_device_get_class(struct btd_device *device);
 uint16_t btd_device_get_vendor(struct btd_device *device);