From 4e0dd434b99dc855b0461c8d5ee0e028c60d239f Mon Sep 17 00:00:00 2001 From: Wootak Jung Date: Thu, 11 Jan 2024 09:09:19 +0900 Subject: [PATCH] adapter: Fix issue where adv stop request disables unintended instance 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 --- src/adapter.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index df93118e..9630bea5 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -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); } -- 2.34.1