1 /*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8 #include <stddef.h>
9 #include <zephyr/ztest.h>
10
11 #include <util/util.h>
12 #include <util/memq.h>
13 #include <util/dbuf.h>
14
15 #include <hal/ccm.h>
16
17 #include <zephyr/bluetooth/hci.h>
18 #include <pdu_df.h>
19 #include <lll/pdu_vendor.h>
20 #include <pdu.h>
21 #include <lll.h>
22 #include <lll/lll_df_types.h>
23 #include <lll_conn.h>
24
25 #include <ull_tx_queue.h>
26 #include <ull_conn_types.h>
27 #include <ull_conn_internal.h>
28
29 #define PEER_FEATURES_ARE_VALID 1U
30
ut_bt_create_connection(void)31 uint16_t ut_bt_create_connection(void)
32 {
33 struct ll_conn *conn;
34
35 conn = ll_conn_acquire();
36 zassert_not_equal(conn, NULL, "Failed acquire ll_conn instance");
37
38 conn->lll.latency = 0;
39 conn->lll.handle = ll_conn_handle_get(conn);
40
41 #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RX)
42 conn->lll.df_rx_cfg.is_initialized = 0U;
43 #endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RX */
44
45 #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_REQ)
46 conn->llcp.cte_req.is_enabled = 0U;
47
48 conn->llcp.fex.features_used |= BIT(BT_LE_FEAT_BIT_CONN_CTE_REQ);
49 #endif /* CONFIG_BT_CTLR_DF_CONN_CTE_REQ */
50
51 return conn->lll.handle;
52 }
53
ut_bt_destroy_connection(uint16_t handle)54 void ut_bt_destroy_connection(uint16_t handle)
55 {
56 struct ll_conn *conn;
57
58 conn = ll_conn_get(handle);
59 zassert_not_equal(conn, NULL, "Failed ll_conn instance for given handle");
60
61 ll_conn_release(conn);
62 }
63
ut_bt_set_peer_features(uint16_t conn_handle,uint64_t features)64 void ut_bt_set_peer_features(uint16_t conn_handle, uint64_t features)
65 {
66 struct ll_conn *conn;
67
68 conn = ll_conn_get(conn_handle);
69 zassert_not_equal(conn, NULL, "Failed ll_conn instance for given handle");
70
71 conn->llcp.fex.valid = PEER_FEATURES_ARE_VALID;
72 conn->llcp.fex.features_peer = features;
73 }
74
ut_bt_set_periph_latency(uint16_t conn_handle,uint16_t periph_latency)75 void ut_bt_set_periph_latency(uint16_t conn_handle, uint16_t periph_latency)
76 {
77 struct ll_conn *conn;
78
79 conn = ll_conn_get(conn_handle);
80 zassert_not_equal(conn, NULL, "Failed ll_conn instance for given handle");
81
82 conn->lll.latency = periph_latency;
83 }
84