Diff between c2f09ece207ea5f08ac937bd64c66f5fb685984f and 9e065d93547997bbfa9a18ea7bf99114c60b9d79

Changed Files

File Additions Deletions Status
emulator/bthost.c +16 -10 modified

Full Patch

diff --git a/emulator/bthost.c b/emulator/bthost.c
index e80a1f4..952faf3 100644
--- a/emulator/bthost.c
+++ b/emulator/bthost.c
@@ -483,24 +483,16 @@ static void evt_conn_request(struct bthost *bthost, const void *data,
 								sizeof(cmd));
 }
 
-static void evt_conn_complete(struct bthost *bthost, const void *data,
-								uint8_t len)
+static void init_conn(struct bthost *bthost, uint16_t handle)
 {
-	const struct bt_hci_evt_conn_complete *ev = data;
 	struct btconn *conn;
 
-	if (len < sizeof(*ev))
-		return;
-
-	if (ev->status)
-		return;
-
 	conn = malloc(sizeof(*conn));
 	if (!conn)
 		return;
 
 	memset(conn, 0, sizeof(*conn));
-	conn->handle = le16_to_cpu(ev->handle);
+	conn->handle = handle;
 	conn->next_cid = 0x0040;
 
 	conn->next = bthost->conns;
@@ -510,6 +502,20 @@ static void evt_conn_complete(struct bthost *bthost, const void *data,
 		bthost->new_conn_cb(conn->handle, bthost->new_conn_data);
 }
 
+static void evt_conn_complete(struct bthost *bthost, const void *data,
+								uint8_t len)
+{
+	const struct bt_hci_evt_conn_complete *ev = data;
+
+	if (len < sizeof(*ev))
+		return;
+
+	if (ev->status)
+		return;
+
+	init_conn(bthost, le16_to_cpu(ev->handle));
+}
+
 static void evt_disconn_complete(struct bthost *bthost, const void *data,
 								uint8_t len)
 {