diff --git a/src/device.c b/src/device.c
index c7c741c..311dca1 100644
--- a/src/device.c
+++ b/src/device.c
static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
{
struct btd_device *device = user_data;
- struct browse_req *req = device->browse;
GAttrib *attrib;
if (gerr) {
- DBusMessage *reply;
-
DBG("%s", gerr->message);
- if (req) {
- reply = btd_error_failed(req->msg, gerr->message);
- g_dbus_send_message(req->conn, reply);
-
- device->browse = NULL;
- browse_request_free(req, TRUE);
- } else if (device->auto_connect)
+ if (device->auto_connect)
device->auto_id = g_timeout_add_seconds_full(
G_PRIORITY_DEFAULT_IDLE,
AUTO_CONNECTION_INTERVAL,
if (device->attachid == 0)
error("Attribute server attach failure!");
- if (req) {
- req->attrib = attrib;
- gatt_discover_primary(req->attrib, NULL, primary_cb, req);
- } else if (device->attios) {
+ if (device->attios) {
device->attrib = attrib;
g_attrib_set_disconnect_function(device->attrib,
attrib_disconnected, device);
return FALSE;
}
+static void browse_primary_connect_cb(GIOChannel *io, GError *gerr,
+ gpointer user_data)
+{
+ struct btd_device *device = user_data;
+ struct browse_req *req = device->browse;
+ GAttrib *attrib;
+
+ if (gerr) {
+ DBusMessage *reply;
+
+ DBG("%s", gerr->message);
+
+ reply = btd_error_failed(req->msg, gerr->message);
+ g_dbus_send_message(req->conn, reply);
+
+ device->browse = NULL;
+ browse_request_free(req, TRUE);
+
+ return;
+ }
+
+ attrib = g_attrib_new(io);
+ device->attachid = attrib_channel_attach(attrib, TRUE);
+ if (device->attachid == 0)
+ error("Attribute server attach failure!");
+
+ req->attrib = attrib;
+ gatt_discover_primary(req->attrib, NULL, primary_cb, req);
+}
+
int device_browse_primary(struct btd_device *device, DBusConnection *conn,
DBusMessage *msg, gboolean secure)
{
sec_level = secure ? BT_IO_SEC_HIGH : BT_IO_SEC_LOW;
- req->io = bt_io_connect(BT_IO_L2CAP, att_connect_cb,
+ req->io = bt_io_connect(BT_IO_L2CAP, browse_primary_connect_cb,
device, NULL, NULL,
BT_IO_OPT_SOURCE_BDADDR, &src,
BT_IO_OPT_DEST_BDADDR, &device->bdaddr,