OSDN Git Service

android/gatt: Do not disconnect immediately after discovering primaries
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 10 Jun 2014 12:46:34 +0000 (15:46 +0300)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 13 Jun 2014 12:47:34 +0000 (15:47 +0300)
This is needed in Android in order react to services found.

android/gatt.c

index 0a8684e..d63efc9 100644 (file)
@@ -68,6 +68,8 @@
 #define GATT_PERM_WRITE_SIGNED         0x00010000
 #define GATT_PERM_WRITE_SIGNED_MITM    0x00020000
 
+#define GATT_CONN_TIMEOUT 2
+
 static const uint8_t BLUETOOTH_UUID[] = {
        0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
        0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
@@ -169,6 +171,8 @@ struct app_connection {
        struct queue *transactions;
        int32_t id;
 
+       guint timeout_id;
+
        bool wait_execute_write;
 };
 
@@ -832,6 +836,9 @@ static void destroy_connection(void *data)
 {
        struct app_connection *conn = data;
 
+       if (conn->timeout_id > 0)
+               g_source_remove(conn->timeout_id);
+
        if (!queue_find(gatt_devices, match_by_value, conn->device))
                goto cleanup;
 
@@ -1213,6 +1220,17 @@ reply:
        send_client_search_complete_notify(gatt_status, cb_data->conn->id);
        free(cb_data);
 }
+static gboolean connection_timeout(void *user_data)
+{
+       struct app_connection *conn = user_data;
+
+       conn->timeout_id = 0;
+
+       queue_remove(app_connections, conn);
+       destroy_connection(conn);
+
+       return FALSE;
+}
 
 static void discover_primary_cb(uint8_t status, GSList *services,
                                                                void *user_data)
@@ -1255,8 +1273,9 @@ static void discover_primary_cb(uint8_t status, GSList *services,
        bt_device_set_uuids(&dev->bdaddr, uuids);
 
        free(cb_data);
-       queue_remove(app_connections, conn);
-       destroy_connection(conn);
+
+       conn->timeout_id = g_timeout_add_seconds(GATT_CONN_TIMEOUT,
+                                               connection_timeout, conn);
 }
 
 static guint search_dev_for_srvc(struct app_connection *conn, bt_uuid_t *uuid)