Fixed "stop LE scan" fail issue 33/173033/1
authorAtul Rai <a.rai@samsung.com>
Wed, 14 Mar 2018 11:47:50 +0000 (17:17 +0530)
committerAtul Rai <a.rai@samsung.com>
Mon, 19 Mar 2018 08:35:42 +0000 (14:05 +0530)
Change-Id: I86b977bbdc3b110eb21db025cf72ffe22f89aad9
Signed-off-by: Atul Rai <a.rai@samsung.com>
src/adapter.c

index 3cb315d..4511a32 100644 (file)
@@ -2564,25 +2564,46 @@ done:
 static void stop_le_discovery_complete(uint8_t status, uint16_t length,
                                        const void *param, void *user_data)
 {
-       struct btd_adapter *adapter = user_data;
+       struct watch_client *client = user_data;
+       struct btd_adapter *adapter = client->adapter;
+       DBusMessage *reply;
 
        DBG("status 0x%02x", status);
 
-       if (status == MGMT_STATUS_SUCCESS) {
-               adapter->discovery_type &= (~0x06);
-               DBG("Discovery Type 0x%02x", adapter->discovery_type);
+       if (status != MGMT_STATUS_SUCCESS) {
+               if (client->msg) {
+                       reply = btd_error_busy(client->msg);
+                       g_dbus_send_message(dbus_conn, reply);
+               }
 
-               adapter->filtered_discovery = false;
-               adapter->no_scan_restart_delay = false;
-               adapter->le_discovering = false;
-               g_dbus_emit_property_changed(dbus_conn, adapter->path,
-                                       ADAPTER_INTERFACE, "LEDiscovering");
+               goto done;
+       }
 
-               if (adapter->discovery_list == NULL && adapter->le_discovery_list == NULL) {
-                       adapter->discovery_enable = 0x00;
-                       trigger_passive_scanning(adapter);
-               }
+       if (client->msg) {
+               reply = g_dbus_create_reply(client->msg, DBUS_TYPE_INVALID);
+               g_dbus_send_message(dbus_conn, reply);
+       }
+
+       adapter->discovery_type &= (~0x06);
+       DBG("Discovery Type 0x%02x", adapter->discovery_type);
+
+       adapter->filtered_discovery = false;
+       adapter->no_scan_restart_delay = false;
+       adapter->le_discovering = false;
+       g_dbus_emit_property_changed(dbus_conn, adapter->path,
+                       ADAPTER_INTERFACE, "LEDiscovering");
+
+       if (adapter->discovery_list == NULL && adapter->le_discovery_list == NULL) {
+               adapter->discovery_enable = 0x00;
+               trigger_passive_scanning(adapter);
        }
+
+done:
+       /*
+        * The destroy function will cleanup the client information and
+        * also remove it from the list of discovery clients.
+        */
+       g_dbus_remove_watch(dbus_conn, client->watch);
 }
 #else
 
@@ -4244,19 +4265,18 @@ static DBusMessage *adapter_stop_le_discovery(DBusConnection *conn,
        DBG("cp.type %d", cp.type);
 
        /*
-        * The destroy function will cleanup the client information and
-        * also remove it from the list of discovery clients.
-        */
-       g_dbus_remove_watch(dbus_conn, client->watch);
-
-       /*
         * As long as other discovery clients are still active, just
-        * return success.
+        * clenup client info and return success.
         */
-       DBG("cp.type %d", cp.type);
-       DBG("adapter->le_discovery_list %d", adapter->discovery_type);
-       if (adapter->le_discovery_list)
+       DBG("adapter->le_discovery_list %p", adapter->le_discovery_list);
+       if (g_slist_next(adapter->le_discovery_list)) {
+               /*
+                * The destroy function will cleanup the client information and
+                * also remove it from the list of discovery clients.
+                */
+               g_dbus_remove_watch(dbus_conn, client->watch);
                return dbus_message_new_method_return(msg);
+       }
 
        /*
         * In the idle phase of a discovery, there is no need to stop it
@@ -4270,17 +4290,18 @@ static DBusMessage *adapter_stop_le_discovery(DBusConnection *conn,
                                        ADAPTER_INTERFACE, "LEDiscovering");
 
                trigger_passive_scanning(adapter);
-
                return dbus_message_new_method_return(msg);
        }
+
        DBG("adapter->discovery_type %d", adapter->discovery_type);
        cp.type = 0x06;
        DBG("cp.type %d", cp.type);
        mgmt_send(adapter->mgmt, MGMT_OP_STOP_LE_DISCOVERY,
                                adapter->dev_id, sizeof(cp), &cp,
-                               stop_le_discovery_complete, adapter, NULL);
+                               stop_le_discovery_complete, client, NULL);
 
-       return dbus_message_new_method_return(msg);
+       client->msg = dbus_message_ref(msg);
+       return NULL;
 }
 
 static DBusMessage *adapter_set_advertising(DBusConnection *conn,