diff --git a/android/gatt.c b/android/gatt.c
index 448bcb8..89748d2 100644
--- a/android/gatt.c
+++ b/android/gatt.c
device_set_state(dev, DEVICE_CONNECTED);
+ bt_auto_connect_remove(&dev->bdaddr);
+
/* Send exchange mtu request as we assume being client and server */
/* TODO: Dont exchange mtu if no client apps */
send_exchange_mtu_request(dev);
sizeof(*ev) + ev->len, ev);
connect:
+ /* We use auto connect feature from kernel if possible */
+ if (bt_kernel_conn_control())
+ return;
+
dev = find_device_by_addr(addr);
if (!dev) {
if (!bonded)
return 0;
}
+static bool auto_connect(struct gatt_device *dev)
+{
+ bool err;
+
+ err = bt_auto_connect_add(&dev->bdaddr);
+ if (!err)
+ return false;
+
+ device_set_state(dev, DEVICE_CONNECT_INIT);
+
+ return true;
+}
+
static bool trigger_connection(struct app_connection *connection)
{
bool ret;
BDADDR_BREDR)
return connect_bredr(connection->device) == 0;
+ /*
+ * For LE devices use auto connect feature if possible
+ * Note: Connection state is handled inside auto_connect() func
+ */
+ if (bt_kernel_conn_control())
+ return auto_connect(connection->device);
+
/* Trigger discovery if not already started */
if (!scanning) {
if (!bt_le_discovery_start()) {
break;
}
}
+
ret = true;
device_set_state(connection->device, DEVICE_CONNECT_INIT);
break;
dev->bdaddr_type = dst_type;
} else {
- if (dev->state != DEVICE_DISCONNECTED) {
+ if ((dev->state != DEVICE_DISCONNECTED) &&
+ !(dev->state == DEVICE_CONNECT_INIT &&
+ bt_kernel_conn_control())) {
char addr[18];
ba2str(&dst, addr);