adapter: Fix issue where adv stop request disables unintended instance 54/304154/1 accepted/tizen/7.0/unified/20240115.170647
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 00:18:30 +0000 (09:18 +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 df93118e69e5c8bfc778336c771929c0410fc350..9630bea5afb78cea4fc9383939943f2c1c894146 100644 (file)
@@ -376,6 +376,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 */
@@ -4665,14 +4666,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);
@@ -13588,6 +13584,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);
        }