set_advertising returns in_progress error even if the restart is scheduled by le... 97/242897/1 accepted/tizen/unified/20200904.035416 submit/tizen/20200902.223427
authorDeokhyun Kim <dukan.kim@samsung.com>
Tue, 25 Aug 2020 06:44:37 +0000 (15:44 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Wed, 2 Sep 2020 00:03:19 +0000 (09:03 +0900)
le_discovering should be set before remove_watch is called

[Model] 5.5
[BinType] AP
[Customer] OPEN

[Issue#] P200824-01952
[Request] PLM
[Occurrence Version] R825USQE1BTH8

[Problem] set_advertising fails
[Cause & Measure] advertising is already stopped by le connection.
  And the restart is scheduled with 300ms delay.
  set_advertising returns in_progress error even if the restart is scheduled
  by le connection.
[Checking Method] Try to stop advertising right after le is connected.

[Team] Bluetooth
[Developer] Deokhyun Kim
[Solution company] Samsung
[Change Type] Specification change

Change-Id: I7fef2e0b5fba1219dfe8f02b223d870450ccb651
Signed-off-by: Deokhyun Kim <dukan.kim@samsung.com>
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/adapter.c

index 6dcf288..a57dccd 100644 (file)
@@ -321,6 +321,7 @@ struct btd_adapter {
        bool advertising;               /* Advertising active */
        gchar *version;                 /* Bluetooth Version */
        uint8_t adv_tx_power;
+       guint adv_restart_timeout;
        bool le_discovering;                    /* LE Discovery active */
        GSList *le_discovery_list;              /* list of LE discovery clients */
 #endif
@@ -2440,8 +2441,8 @@ static void discovering_callback(uint16_t index, uint16_t length,
                        if (adapter->le_discovering == true) {
                                struct watch_client *client;
                                client = adapter->le_discovery_list->data;
-                               g_dbus_remove_watch(dbus_conn, client->watch);
                                adapter->le_discovering = false;
+                               g_dbus_remove_watch(dbus_conn, client->watch);
                        }
                } else {
                        hci_set_bit(BDADDR_LE_PUBLIC, &adapter->discovery_type);
@@ -4406,8 +4407,8 @@ static DBusMessage *adapter_stop_le_discovery(DBusConnection *conn,
        DBG("cp.type %d", cp.type);
        DBG("adapter->discovery_enable %d", adapter->discovery_enable);
        if (adapter->discovery_enable == 0x00) {
-               g_dbus_remove_watch(dbus_conn, client->watch);
                adapter->le_discovering = false;
+               g_dbus_remove_watch(dbus_conn, client->watch);
                g_dbus_emit_property_changed(dbus_conn, adapter->path,
                                        ADAPTER_INTERFACE, "LEDiscovering");
 
@@ -4442,6 +4443,9 @@ static DBusMessage *adapter_set_advertising(DBusConnection *conn,
                                                DBUS_TYPE_INVALID))
                return btd_error_invalid_args(msg);
 
+       if (adapter->adv_restart_timeout > 0)
+               return btd_error_in_progress(msg);
+
        DBG("%s advertising slot_id %d", enable ? "Enable" : "Disable", slot_id);
 
        if (adapter_le_is_supported_multi_advertising() && slot_id > 0)
@@ -12416,6 +12420,8 @@ static gboolean multi_adv_start_timeout_cb(gpointer user_data)
        struct btd_adapter *adapter = data->adapter;
        dbus_bool_t err;
 
+       adapter->adv_restart_timeout = 0;
+
        err = adapter_le_enable_multi_adv(adapter, TRUE, data->slot_id);
        if (!err)
                advertising_state_changed(adapter, data->slot_id, FALSE);
@@ -12447,7 +12453,8 @@ static void multi_adv_state_change_callback(uint16_t index, uint16_t length,
                data->adapter = adapter;
                data->slot_id = ev->adv_instance;
 
-               g_timeout_add(300, multi_adv_start_timeout_cb, data);
+               adapter->adv_restart_timeout =
+                       g_timeout_add(300, multi_adv_start_timeout_cb, data);
        }
 }