Diff between 34cd14d15ed11d76c87cbfad221b2de12aa77239 and ad6d9178cee0d6af97ae958de33cb2cc56c8ab2c

Changed Files

File Additions Deletions Status
android/gatt.c +31 -30 modified

Full Patch

diff --git a/android/gatt.c b/android/gatt.c
index f53884b..69f591f 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -1253,56 +1253,57 @@ static struct app_connection *find_conn(const bdaddr_t *addr, int32_t app_id,
 								&conn_match);
 }
 
-static void handle_client_connect(const void *buf, uint16_t len)
+static uint8_t handle_connect(int32_t app_id, const bdaddr_t *addr)
 {
-	const struct hal_cmd_gatt_client_connect *cmd = buf;
 	struct app_connection conn_match;
 	struct app_connection *conn;
 	struct gatt_device *device;
-	struct gatt_app *client;
-	bdaddr_t addr;
-	uint8_t status;
+	struct gatt_app *app;
 
 	DBG("");
 
-	client = find_app_by_id(cmd->client_if);
-	if (!client) {
-		status = HAL_STATUS_FAILED;
-		goto reply;
-	}
-
-	android2bdaddr(&cmd->bdaddr, &addr);
+	app = find_app_by_id(app_id);
+	if (!app)
+		return HAL_STATUS_FAILED;
 
-	device = find_device_by_addr(&addr);
+	device = find_device_by_addr(addr);
 	if (!device) {
-		device = create_device(&addr);
-		if (!device) {
-			status = HAL_STATUS_FAILED;
-			goto reply;
-		}
+		device = create_device(addr);
+		if (!device)
+			return HAL_STATUS_FAILED;
 	}
 
 	conn_match.device = device;
-	conn_match.app = client;
+	conn_match.app = app;
 
 	conn = queue_find(app_connections, match_connection_by_device_and_app,
 								&conn_match);
 	if (!conn) {
-		conn = create_connection(device, client);
-		if (!conn) {
-			status = HAL_STATUS_NOMEM;
-			goto reply;
-		}
+		conn = create_connection(device, app);
+		if (!conn)
+			return HAL_STATUS_NOMEM;
 	}
 
-	if (!trigger_connection(conn)) {
-		status = HAL_STATUS_FAILED;
-		goto reply;
-	}
+	if (!trigger_connection(conn))
+		return HAL_STATUS_FAILED;
 
-	status = HAL_STATUS_SUCCESS;
+	return HAL_STATUS_SUCCESS;
+}
+
+static void handle_client_connect(const void *buf, uint16_t len)
+{
+	const struct hal_cmd_gatt_client_connect *cmd = buf;
+	uint8_t status;
+	bdaddr_t addr;
+
+	DBG("");
+
+	android2bdaddr(&cmd->bdaddr, &addr);
+
+	/* TODO handle is_direct flag */
+
+	status = handle_connect(cmd->client_if, &addr);
 
-reply:
 	ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT, HAL_OP_GATT_CLIENT_CONNECT,
 								status);
 }