summaryrefslogtreecommitdiff
path: root/android/gatt.c
diff options
context:
space:
mode:
authorSzymon Janc <szymon.janc@tieto.com>2015-03-05 12:46:23 +0100
committerSzymon Janc <szymon.janc@tieto.com>2015-03-05 16:58:49 +0100
commit44e395c1b03c3d69f86be4ce51be7b297fed74f8 (patch)
treed9d59ecf9bbbafaa94b735f501f49d48da689f69 /android/gatt.c
parentfb865d80db38bdb9ac044c863ca8695c5be86bad (diff)
downloadbluez-44e395c1b03c3d69f86be4ce51be7b297fed74f8.tar.gz
android/gatt: Handle device state in connect functions
Depending on kernel connection management support and type of connection (direct or not) different states are expected after connect. To make sure device state is correct set it connect functions.
Diffstat (limited to 'android/gatt.c')
-rw-r--r--android/gatt.c42
1 files changed, 18 insertions, 24 deletions
diff --git a/android/gatt.c b/android/gatt.c
index 7263e317f..9c2a28034 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -573,6 +573,9 @@ static void device_set_state(struct gatt_device *dev, uint32_t state)
{
char bda[18];
+ if (dev->state == state)
+ return;
+
ba2str(&dev->bdaddr, bda);
DBG("gatt: Device %s state changed %s -> %s", bda,
device_state_str[dev->state], device_state_str[state]);
@@ -583,17 +586,18 @@ static void device_set_state(struct gatt_device *dev, uint32_t state)
static bool auto_connect_le(struct gatt_device *dev)
{
/* For LE devices use auto connect feature if possible */
- if (bt_kernel_conn_control())
- return bt_auto_connect_add(bt_get_id_addr(&dev->bdaddr, NULL));
-
- /* Trigger discovery if not already started */
- if (!scanning) {
- if (!bt_le_discovery_start()) {
+ if (bt_kernel_conn_control()) {
+ if (!bt_auto_connect_add(bt_get_id_addr(&dev->bdaddr, NULL)))
+ return false;
+ } else {
+ /* Trigger discovery if not already started */
+ if (!scanning && !bt_le_discovery_start()) {
error("gatt: Could not start scan");
return false;
}
}
+ device_set_state(dev, DEVICE_CONNECT_INIT);
return true;
}
@@ -640,12 +644,10 @@ static void connection_cleanup(struct gatt_device *device)
device_set_state(device, DEVICE_DISCONNECTED);
- if (!queue_isempty(device->autoconnect_apps)) {
+ if (!queue_isempty(device->autoconnect_apps))
auto_connect_le(device);
- device_set_state(device, DEVICE_CONNECT_INIT);
- } else {
+ else
bt_auto_connect_remove(&device->bdaddr);
- }
}
static void destroy_gatt_app(void *data)
@@ -1649,6 +1651,8 @@ static int connect_le(struct gatt_device *dev)
/* Keep this, so we can cancel the connection */
dev->att_io = io;
+ device_set_state(dev, DEVICE_CONNECT_READY);
+
return 0;
}
@@ -1899,8 +1903,6 @@ static int connect_bredr(struct gatt_device *dev)
static bool trigger_connection(struct app_connection *conn, bool direct)
{
- bool ret;
-
switch (conn->device->state) {
case DEVICE_DISCONNECTED:
/*
@@ -1912,26 +1914,18 @@ static bool trigger_connection(struct app_connection *conn, bool direct)
return connect_bredr(conn->device) == 0;
if (direct)
- ret = connect_le(conn->device) == 0;
- else
- ret = auto_connect_le(conn->device);
+ return connect_le(conn->device) == 0;
- if (ret)
- device_set_state(conn->device, DEVICE_CONNECT_INIT);
- break;
+ return auto_connect_le(conn->device);
case DEVICE_CONNECTED:
notify_app_connect_status(conn, GATT_SUCCESS);
- ret = true;
- break;
+ return true;
case DEVICE_CONNECT_READY:
case DEVICE_CONNECT_INIT:
default:
/* In those cases connection is already triggered. */
- ret = true;
- break;
+ return true;
}
-
- return ret;
}
static void remove_autoconnect_device(struct gatt_device *dev)