diff --git a/src/attrib-server.c b/src/attrib-server.c
index aa0012f..5f353df 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
return channel->id;
}
-static int channel_id_cmp(gconstpointer data, gconstpointer user_data)
+static struct gatt_channel *find_channel(guint id)
{
- const struct gatt_channel *channel = data;
- guint id = GPOINTER_TO_UINT(user_data);
-
- return channel->id - id;
-}
-
-gboolean attrib_channel_detach(GAttrib *attrib, guint id)
-{
- struct gatt_server *server;
- struct gatt_channel *channel;
- GError *gerr = NULL;
- GIOChannel *io;
- bdaddr_t src;
GSList *l;
- io = g_attrib_get_channel(attrib);
+ for (l = servers; l; l = g_slist_next(l)) {
+ struct gatt_server *server = l->data;
+ GSList *c;
- bt_io_get(io, &gerr, BT_IO_OPT_SOURCE_BDADDR, &src, BT_IO_OPT_INVALID);
+ for (c = server->clients; c; c = g_slist_next(c)) {
+ struct gatt_channel *channel = c->data;
- if (gerr != NULL) {
- error("bt_io_get: %s", gerr->message);
- g_error_free(gerr);
- return FALSE;
+ if (channel->id == id)
+ return channel;
+ }
}
- server = find_gatt_server(&src);
- if (server == NULL)
- return FALSE;
+ return NULL;
+}
- l = g_slist_find_custom(server->clients, GUINT_TO_POINTER(id),
- channel_id_cmp);
- if (!l)
- return FALSE;
+gboolean attrib_channel_detach(GAttrib *attrib, guint id)
+{
+ struct gatt_channel *channel;
- channel = l->data;
+ channel = find_channel(id);
+ if (channel == NULL)
+ return FALSE;
g_attrib_unregister(channel->attrib, channel->id);
channel_remove(channel);
diff --git a/src/device.c b/src/device.c
index 59e4dea..2a5a883 100644
--- a/src/device.c
+++ b/src/device.c
static void attio_cleanup(struct btd_device *device)
{
- if (device->attachid) {
- attrib_channel_detach(device->attrib, device->attachid);
- device->attachid = 0;
- }
-
if (device->att_disconn_id)
bt_att_unregister_disconnect(device->att,
device->att_disconn_id);
if (device->attrib) {
GAttrib *attrib = device->attrib;
+
device->attrib = NULL;
+
+ if (device->attachid) {
+ guint attachid = device->attachid;
+
+ device->attachid = 0;
+ attrib_channel_detach(attrib, attachid);
+ }
+
g_attrib_cancel_all(attrib);
g_attrib_unref(attrib);
}