OSDN Git Service

emulator: Refactor bthost ACL connection tracking
authorJohan Hedberg <johan.hedberg@intel.com>
Thu, 19 Sep 2013 18:35:29 +0000 (21:35 +0300)
committerJohan Hedberg <johan.hedberg@intel.com>
Thu, 19 Sep 2013 18:42:36 +0000 (21:42 +0300)
emulator/bthost.c

index e80a1f4..952faf3 100644 (file)
@@ -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)
 {