adapter: Fix issue where adv stop request disables unintended instance 88/304188/1 accepted/tizen_unified_riscv accepted/tizen/unified/20240117.163238 accepted/tizen/unified/riscv/20240118.054605
authorWootak Jung <wootak.jung@samsung.com>
Thu, 11 Jan 2024 00:09:19 +0000 (09:09 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Thu, 11 Jan 2024 23:21:11 +0000 (08:21 +0900)
Reproduction steps:
1. adv1, adv2 are in progress
2. LE connected and adv2 has stopped for a while and is scheduled(timer) to restart
3. adv1 stop request before restart timer is run
4. timer is removed and adv1 is stopped
5. adv2 is not restarted even though it should

Change-Id: I5d2f7a2ae87d87d180e92f380505e8118fc973b0
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/adapter.c

index 3b159a3..10c57b2 100644 (file)
@@ -397,6 +397,7 @@ struct btd_adapter {
        bool advertising;               /* Advertising active */
        gchar *version;                 /* Bluetooth Version */
        uint8_t adv_tx_power;
+       uint8_t adv_restart_instance;
        guint adv_restart_timeout;
        bool le_discovering;                    /* LE Discovery active */
        GSList *le_discovery_list;              /* list of LE discovery clients */
@@ -4825,14 +4826,9 @@ static DBusMessage *adapter_set_advertising(DBusConnection *conn,
                                                DBUS_TYPE_INVALID))
                return btd_error_invalid_args(msg);
 
-       if (adapter->adv_restart_timeout) {
-               if (enable) {
-                       return btd_error_in_progress(msg);
-               } else {
-                       DBG("Advertising stop received. No need to restart advertising");
-                       g_source_remove(adapter->adv_restart_timeout);
-                       adapter->adv_restart_timeout = 0;
-               }
+       if (adapter->adv_restart_timeout && adapter->adv_restart_instance == slot_id) {
+               DBG("restart advertising slot_id %d restart is in progress", slot_id);
+               return btd_error_in_progress(msg);
        }
 
        DBG("%s advertising slot_id %d", enable ? "Enable" : "Disable", slot_id);
@@ -13781,6 +13777,7 @@ static void multi_adv_state_change_callback(uint16_t index, uint16_t length,
                data->adapter = adapter;
                data->slot_id = ev->adv_instance;
 
+               adapter->adv_restart_instance = ev->adv_instance;
                adapter->adv_restart_timeout =
                        g_timeout_add(300, multi_adv_start_timeout_cb, data);
        }