diff options
-rw-r--r-- | common/glib-helper.c | 17 | ||||
-rw-r--r-- | common/glib-helper.h | 2 | ||||
-rw-r--r-- | hcid/device.c | 5 |
3 files changed, 15 insertions, 9 deletions
diff --git a/common/glib-helper.c b/common/glib-helper.c index ed203eb4..eab30b5e 100644 --- a/common/glib-helper.c +++ b/common/glib-helper.c @@ -314,7 +314,7 @@ static int find_by_bdaddr(const void *data, const void *user_data) bacmp(&ctxt->src, &search->src)); } -void bt_cancel_discovery(const bdaddr_t *src, const bdaddr_t *dst) +int bt_cancel_discovery(const bdaddr_t *src, const bdaddr_t *dst) { struct search_context search, *ctxt; GSList *match; @@ -323,14 +323,17 @@ void bt_cancel_discovery(const bdaddr_t *src, const bdaddr_t *dst) bacpy(&search.src, src); bacpy(&search.dst, dst); + /* Ongoing SDP Discovery */ match = g_slist_find_custom(context_list, &search, find_by_bdaddr); + if (!match) + return -ENODATA; - /* Ongoing SDP Discovery */ - if (match) { - ctxt = match->data; - if (ctxt->session) - close(ctxt->session->sock); - } + ctxt = match->data; + if (!ctxt->session) + return -ENOTCONN; + + close(ctxt->session->sock); + return 0; } char *bt_uuid2string(uuid_t *uuid) diff --git a/common/glib-helper.h b/common/glib-helper.h index 6c9b89b0..8bb6b284 100644 --- a/common/glib-helper.h +++ b/common/glib-helper.h @@ -34,7 +34,7 @@ int bt_discover_services(const bdaddr_t *src, const bdaddr_t *dst, int bt_search_service(const bdaddr_t *src, const bdaddr_t *dst, uuid_t *uuid, bt_callback_t cb, void *user_data, bt_destroy_t destroy); -void bt_cancel_discovery(const bdaddr_t *src, const bdaddr_t *dst); +int bt_cancel_discovery(const bdaddr_t *src, const bdaddr_t *dst); gchar *bt_uuid2string(uuid_t *uuid); int bt_string2uuid(uuid_t *uuid, const char *string); diff --git a/hcid/device.c b/hcid/device.c index f0e57e91..6b9ccac9 100644 --- a/hcid/device.c +++ b/hcid/device.c @@ -1061,7 +1061,10 @@ static DBusMessage *cancel_discover(DBusConnection *conn, str2ba(adapter->address, &src); str2ba(device->address, &dst); - bt_cancel_discovery(&src, &dst); + if (bt_cancel_discovery(&src, &dst) < 0) + return g_dbus_create_error(msg, + ERROR_INTERFACE ".Failed", + "No pending discover"); return dbus_message_new_method_return(msg); } |