This will allow us to determine if we can scan for other devices to
connect or postpone it until previous connection is handled.
---
android/gatt.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/android/gatt.c b/android/gatt.c
index b224c28..b533661 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -58,13 +58,15 @@ typedef enum {
DEVICE_DISCONNECTED = 0,
DEVICE_CONNECT_INIT, /* connection procedure initiated */
DEVICE_CONNECT_READY, /* dev found during LE scan */
- DEVICE_CONNECTED, /* connection has been established */
+ DEVICE_CONNECTING, /* io connection triggered */
+ DEVICE_CONNECTED, /* io connection has been established */
} gatt_device_state_t;
static const char const *device_state_str[] = {
"DISCONNECTED",
"CONNECT INIT",
"CONNECT READY",
+ "CONNECTING",
"CONNECTED",
};
@@ -953,7 +955,7 @@ static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
uint32_t status;
GAttrib *attrib;
- if (dev->state != DEVICE_CONNECT_READY) {
+ if (dev->state != DEVICE_CONNECTING) {
error("gatt: Device not in a connecting state!?");
g_io_channel_shutdown(io, TRUE, NULL);
return;
@@ -993,7 +995,7 @@ reply:
device_unref(dev);
/* Check if we should restart scan */
- if (scanning)
+ if (scanning || find_device_by_state(DEVICE_CONNECT_INIT))
bt_le_discovery_start(le_device_found_handler);
/* FIXME: What to do if discovery won't start here. */
@@ -1040,6 +1042,7 @@ 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_CONNECTING);
return 0;
}
@@ -1207,8 +1210,9 @@ static bool trigger_connection(struct connection *connection)
break;
}
- /* after state change trigger discovering */
- if (!scanning && (connection->device->state == DEVICE_CONNECT_INIT))
+ /* after state change - trigger discovering (if ACL is not creating) */
+ if (!scanning && (connection->device->state == DEVICE_CONNECT_INIT) &&
+ !find_device_by_state(DEVICE_CONNECTING))
if (!bt_le_discovery_start(le_device_found_handler)) {
error("gatt: Could not start scan");
--
1.9.1
Hi Jakub,
On Monday 28 of April 2014 15:17:50 Jakub Tyszkowski wrote:
> Framework should know which request failed.
> ---
> android/gatt.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/android/gatt.c b/android/gatt.c
> index 7c59e12..a7b8659 100644
> --- a/android/gatt.c
> +++ b/android/gatt.c
> @@ -3105,7 +3105,6 @@ static void handle_server_register(const void *buf, uint16_t len)
>
> ev.status = GATT_SUCCESS;
> ev.server_if = server->id;
> - memcpy(ev.uuid, server->uuid, sizeof(server->uuid));
>
> status = HAL_STATUS_SUCCESS;
>
> @@ -3113,6 +3112,8 @@ failed:
> if (status != HAL_STATUS_SUCCESS)
> ev.status = GATT_FAILURE;
>
> + memcpy(ev.uuid, cmd->uuid, sizeof(ev.uuid));
> +
> ipc_send_notif(hal_ipc, HAL_SERVICE_ID_GATT,
> HAL_EV_GATT_SERVER_REGISTER, sizeof(ev), &ev);
>
This patch is now pushed, thanks.
--
Best regards,
Szymon Janc
Framework should know which request failed.
---
android/gatt.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/android/gatt.c b/android/gatt.c
index 7c59e12..a7b8659 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -3105,7 +3105,6 @@ static void handle_server_register(const void *buf, uint16_t len)
ev.status = GATT_SUCCESS;
ev.server_if = server->id;
- memcpy(ev.uuid, server->uuid, sizeof(server->uuid));
status = HAL_STATUS_SUCCESS;
@@ -3113,6 +3112,8 @@ failed:
if (status != HAL_STATUS_SUCCESS)
ev.status = GATT_FAILURE;
+ memcpy(ev.uuid, cmd->uuid, sizeof(ev.uuid));
+
ipc_send_notif(hal_ipc, HAL_SERVICE_ID_GATT,
HAL_EV_GATT_SERVER_REGISTER, sizeof(ev), &ev);
--
1.9.1
This changes device connect triggering on le scan stop.
We should be setting proper state for devices for which connection
failed and then check if we should retry the scan and connect. If we do
that there is no need for error codes. Previously we were using both,
error codes and device search results to decide if we should rescan.
---
android/gatt.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/android/gatt.c b/android/gatt.c
index b533661..7c59e12 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -1001,7 +1001,7 @@ reply:
/* FIXME: What to do if discovery won't start here. */
}
-static int connect_le(struct gatt_device *dev)
+static void connect_le(struct gatt_device *dev)
{
BtIOSecLevel sec_level;
GIOChannel *io;
@@ -1013,7 +1013,8 @@ static int connect_le(struct gatt_device *dev)
/* There is one connection attempt going on */
if (dev->att_io) {
info("gatt: connection to dev %s is ongoing", addr);
- return -EALREADY;
+ device_set_state(dev, DEVICE_CONNECTING);
+ return;
}
DBG("Connection attempt to: %s", addr);
@@ -1037,14 +1038,13 @@ static int connect_le(struct gatt_device *dev)
error("gatt: Failed bt_io_connect(%s): %s", addr,
gerr->message);
g_error_free(gerr);
- return -EIO;
+ device_set_state(dev, DEVICE_CONNECT_INIT);
+ return;
}
/* Keep this, so we can cancel the connection */
dev->att_io = io;
device_set_state(dev, DEVICE_CONNECTING);
-
- return 0;
}
static void handle_client_scan(const void *buf, uint16_t len)
@@ -1095,25 +1095,19 @@ reply:
status);
}
-static int connect_next_dev(void)
+static void bt_le_discovery_stop_cb(void)
{
struct gatt_device *dev;
DBG("");
+ /* connect ready devices */
dev = find_device_by_state(DEVICE_CONNECT_READY);
- if (!dev)
- return -ENODEV;
-
- return connect_le(dev);
-}
-
-static void bt_le_discovery_stop_cb(void)
-{
- DBG("");
+ if (dev)
+ connect_le(dev);
- /* Check now if there is any device ready to connect */
- if (connect_next_dev() < 0)
+ /* In case of some pending connections */
+ if (find_device_by_state(DEVICE_CONNECT_INIT))
bt_le_discovery_start(le_device_found_handler);
}
--
1.9.1