From 9e065d93547997bbfa9a18ea7bf99114c60b9d79 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 19 Sep 2013 21:35:29 +0300 Subject: [PATCH] emulator: Refactor bthost ACL connection tracking --- emulator/bthost.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/emulator/bthost.c b/emulator/bthost.c index e80a1f45a..952faf300 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) { -- 2.47.3