diff --git a/android/gatt.c b/android/gatt.c
index 7263e31..9c2a280 100644
--- a/android/gatt.c
+++ b/android/gatt.c
{
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]);
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;
}
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)
/* Keep this, so we can cancel the connection */
dev->att_io = io;
+ device_set_state(dev, DEVICE_CONNECT_READY);
+
return 0;
}
static bool trigger_connection(struct app_connection *conn, bool direct)
{
- bool ret;
-
switch (conn->device->state) {
case DEVICE_DISCONNECTED:
/*
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)