summaryrefslogtreecommitdiff
path: root/emulator
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2022-05-02 12:59:50 -0700
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2022-05-02 14:06:12 -0700
commitc75ff36b77f88821beffabe4d3e60317c243d9b1 (patch)
tree81776d5f29bb2842f68dcd7a7c6afc516ac3f571 /emulator
parentfa7828bddd2164408535a9ac45095564e9ebbeea (diff)
downloadbluez-c75ff36b77f88821beffabe4d3e60317c243d9b1.tar.gz
btdev: Fix not removing connection and advertising set on reset
This makes sure that all connections and advertising sets are cleanup on reset.
Diffstat (limited to 'emulator')
-rw-r--r--emulator/btdev.c76
1 files changed, 40 insertions, 36 deletions
diff --git a/emulator/btdev.c b/emulator/btdev.c
index d3f565438..641e308b3 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -509,6 +509,42 @@ void btdev_set_rl_len(struct btdev *btdev, uint8_t len)
btdev->le_rl_len = len;
}
+static void conn_unlink(struct btdev_conn *conn1, struct btdev_conn *conn2)
+{
+ conn1->link = NULL;
+ conn2->link = NULL;
+}
+
+static void conn_remove(void *data)
+{
+ struct btdev_conn *conn = data;
+
+ if (conn->link) {
+ struct btdev_conn *link = conn->link;
+
+ conn_unlink(conn, conn->link);
+ conn_remove(link);
+ }
+
+ queue_remove(conn->dev->conns, conn);
+
+ free(conn->data);
+ free(conn);
+}
+
+static void le_ext_adv_free(void *data)
+{
+ struct le_ext_adv *ext_adv = data;
+
+ /* Remove to queue */
+ queue_remove(ext_adv->dev->le_ext_adv, ext_adv);
+
+ if (ext_adv->id)
+ timeout_remove(ext_adv->id);
+
+ free(ext_adv);
+}
+
static void btdev_reset(struct btdev *btdev)
{
/* FIXME: include here clearing of all states that should be
@@ -517,12 +553,16 @@ static void btdev_reset(struct btdev *btdev)
btdev->le_scan_enable = 0x00;
btdev->le_adv_enable = 0x00;
+ btdev->le_pa_enable = 0x00;
al_clear(btdev);
rl_clear(btdev);
btdev->le_al_len = AL_SIZE;
btdev->le_rl_len = RL_SIZE;
+
+ queue_remove_all(btdev->conns, NULL, NULL, conn_remove);
+ queue_remove_all(btdev->le_ext_adv, NULL, NULL, le_ext_adv_free);
}
static int cmd_reset(struct btdev *dev, const void *data, uint8_t len)
@@ -674,29 +714,6 @@ static bool match_handle(const void *data, const void *match_data)
return conn->handle == handle;
}
-static void conn_unlink(struct btdev_conn *conn1, struct btdev_conn *conn2)
-{
- conn1->link = NULL;
- conn2->link = NULL;
-}
-
-static void conn_remove(void *data)
-{
- struct btdev_conn *conn = data;
-
- if (conn->link) {
- struct btdev_conn *link = conn->link;
-
- conn_unlink(conn, conn->link);
- conn_remove(link);
- }
-
- queue_remove(conn->dev->conns, conn);
-
- free(conn->data);
- free(conn);
-}
-
static void disconnect_complete(struct btdev *dev, uint16_t handle,
uint8_t status, uint8_t reason)
{
@@ -4627,19 +4644,6 @@ static struct le_ext_adv *le_ext_adv_new(struct btdev *btdev, uint8_t handle)
return ext_adv;
}
-static void le_ext_adv_free(void *data)
-{
- struct le_ext_adv *ext_adv = data;
-
- /* Remove to queue */
- queue_remove(ext_adv->dev->le_ext_adv, ext_adv);
-
- if (ext_adv->id)
- timeout_remove(ext_adv->id);
-
- free(ext_adv);
-}
-
static int cmd_set_adv_rand_addr(struct btdev *dev, const void *data,
uint8_t len)
{