diff --git a/src/attrib-server.c b/src/attrib-server.c
index 200a8a7..3f68fea 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
g_attrib_send(channel->attrib, 0, opdu, length, NULL, NULL, NULL);
}
+GAttrib *attrib_from_device(struct btd_device *device)
+{
+ struct btd_adapter *adapter = device_get_adapter(device);
+ struct gatt_server *server;
+ GSList *l;
+
+ l = g_slist_find_custom(servers, adapter, adapter_cmp);
+ if (!l)
+ return NULL;
+
+ server = l->data;
+
+ for (l = server->clients; l; l = l->next) {
+ struct gatt_channel *channel = l->data;
+
+ if (channel->device == device)
+ return g_attrib_ref(channel->attrib);
+ }
+
+ return NULL;
+}
+
guint attrib_channel_attach(GAttrib *attrib)
{
struct gatt_server *server;
diff --git a/src/attrib-server.h b/src/attrib-server.h
index 90ba17c..063cb66 100644
--- a/src/attrib-server.h
+++ b/src/attrib-server.h
uint32_t attrib_create_sdp(struct btd_adapter *adapter, uint16_t handle,
const char *name);
void attrib_free_sdp(struct btd_adapter *adapter, uint32_t sdp_handle);
+GAttrib *attrib_from_device(struct btd_device *device);
guint attrib_channel_attach(GAttrib *attrib);
gboolean attrib_channel_detach(GAttrib *attrib, guint id);
diff --git a/src/device.c b/src/device.c
index a52faea..127b280 100644
--- a/src/device.c
+++ b/src/device.c
device_set_auto_connect(device, TRUE);
+ /* Check if there is no GAttrib associated to the device created by a
+ * incoming connection */
+ if (!device->attrib)
+ device->attrib = attrib_from_device(device);
+
if (device->attrib && cfunc) {
device->attios_offline = g_slist_append(device->attios_offline,
attio);