tests: Bluetooth: LLCP unittests for Periodic Sync Procedure

Added LLCP PDU Periodic Sync Indication unittests

Signed-off-by: Lucas Mathias Balling <lutb@demant.com>
This commit is contained in:
Lucas Mathias Balling 2024-10-04 13:22:40 +02:00 committed by Carles Cufí
parent 39fcf02181
commit c7ffce3eb2
20 changed files with 1074 additions and 1 deletions

View file

@ -62,6 +62,8 @@ void helper_pdu_encode_cis_terminate_ind(struct pdu_data *pdu, void *param);
void helper_pdu_encode_sca_req(struct pdu_data *pdu, void *param); void helper_pdu_encode_sca_req(struct pdu_data *pdu, void *param);
void helper_pdu_encode_sca_rsp(struct pdu_data *pdu, void *param); void helper_pdu_encode_sca_rsp(struct pdu_data *pdu, void *param);
void helper_pdu_encode_periodic_sync_ind(struct pdu_data *pdu, void *param);
void helper_pdu_verify_ping_req(const char *file, uint32_t line, struct pdu_data *pdu, void *param); void helper_pdu_verify_ping_req(const char *file, uint32_t line, struct pdu_data *pdu, void *param);
void helper_pdu_verify_ping_rsp(const char *file, uint32_t line, struct pdu_data *pdu, void *param); void helper_pdu_verify_ping_rsp(const char *file, uint32_t line, struct pdu_data *pdu, void *param);
@ -155,6 +157,9 @@ void helper_pdu_verify_cis_terminate_ind(const char *file, uint32_t line, struct
void helper_pdu_verify_sca_req(const char *file, uint32_t line, struct pdu_data *pdu, void *param); void helper_pdu_verify_sca_req(const char *file, uint32_t line, struct pdu_data *pdu, void *param);
void helper_pdu_verify_sca_rsp(const char *file, uint32_t line, struct pdu_data *pdu, void *param); void helper_pdu_verify_sca_rsp(const char *file, uint32_t line, struct pdu_data *pdu, void *param);
void helper_pdu_verify_periodic_sync_ind(const char *file, uint32_t line, struct pdu_data *pdu,
void *param);
void helper_node_verify_peer_sca_update(const char *file, uint32_t line, struct node_rx_pdu *rx, void helper_node_verify_peer_sca_update(const char *file, uint32_t line, struct node_rx_pdu *rx,
void *param); void *param);
@ -193,6 +198,7 @@ enum helper_pdu_opcode {
LL_CIS_RSP, LL_CIS_RSP,
LL_CIS_IND, LL_CIS_IND,
LL_CIS_TERMINATE_IND, LL_CIS_TERMINATE_IND,
LL_PERIODIC_SYNC_IND,
LL_ZERO, LL_ZERO,
}; };

View file

@ -504,6 +504,33 @@ void helper_pdu_encode_sca_rsp(struct pdu_data *pdu, void *param)
pdu->llctrl.clock_accuracy_rsp.sca = p->sca; pdu->llctrl.clock_accuracy_rsp.sca = p->sca;
} }
void helper_pdu_encode_periodic_sync_ind(struct pdu_data *pdu, void *param)
{
struct pdu_data_llctrl_periodic_sync_ind *p = param;
pdu->ll_id = PDU_DATA_LLID_CTRL;
pdu->len = offsetof(struct pdu_data_llctrl, periodic_sync_ind) +
sizeof(struct pdu_data_llctrl_periodic_sync_ind);
pdu->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_PERIODIC_SYNC_IND;
pdu->llctrl.periodic_sync_ind.id = sys_cpu_to_le16(p->id);
memcpy(&pdu->llctrl.periodic_sync_ind.sync_info, &p->sync_info,
sizeof(struct pdu_adv_sync_info));
pdu->llctrl.periodic_sync_ind.conn_event_count = sys_cpu_to_le16(p->conn_event_count);
pdu->llctrl.periodic_sync_ind.last_pa_event_counter =
sys_cpu_to_le16(p->last_pa_event_counter);
pdu->llctrl.periodic_sync_ind.sid = p->sid;
pdu->llctrl.periodic_sync_ind.addr_type = p->addr_type;
pdu->llctrl.periodic_sync_ind.sca = p->sca;
pdu->llctrl.periodic_sync_ind.phy = p->phy;
memcpy(pdu->llctrl.periodic_sync_ind.adv_addr, p->adv_addr, sizeof(p->adv_addr));
pdu->llctrl.periodic_sync_ind.sync_conn_event_count = p->sync_conn_event_count;
}
void helper_pdu_verify_version_ind(const char *file, uint32_t line, struct pdu_data *pdu, void helper_pdu_verify_version_ind(const char *file, uint32_t line, struct pdu_data *pdu,
void *param) void *param)
{ {
@ -1253,3 +1280,46 @@ void helper_pdu_verify_sca_rsp(const char *file, uint32_t line, struct pdu_data
zassert_equal(pdu->llctrl.opcode, PDU_DATA_LLCTRL_TYPE_CLOCK_ACCURACY_RSP, zassert_equal(pdu->llctrl.opcode, PDU_DATA_LLCTRL_TYPE_CLOCK_ACCURACY_RSP,
"Not a LL_CLOCK_ACCURACY_RSP.\nCalled at %s:%d\n", file, line); "Not a LL_CLOCK_ACCURACY_RSP.\nCalled at %s:%d\n", file, line);
} }
void helper_pdu_verify_periodic_sync_ind(const char *file, uint32_t line, struct pdu_data *pdu,
void *param)
{
struct pdu_data_llctrl_periodic_sync_ind *p = param;
zassert_equal(pdu->ll_id, PDU_DATA_LLID_CTRL, "Not a Control PDU.\nCalled at %s:%d\n", file,
line);
zassert_equal(pdu->llctrl.opcode, PDU_DATA_LLCTRL_TYPE_PERIODIC_SYNC_IND,
"Not a LL_PERIODIC_SYNC_IND.\nCalled at %s:%d\n", file, line);
zassert_equal(pdu->llctrl.periodic_sync_ind.id, p->id,
"id mismatch.\nCalled at %s:%d\n", file, line);
zassert_equal(pdu->llctrl.periodic_sync_ind.conn_event_count, p->conn_event_count,
"conn_event_count mismatch.\nCalled at %s:%d\n", file, line);
zassert_equal(pdu->llctrl.periodic_sync_ind.last_pa_event_counter, p->last_pa_event_counter,
"last_pa_event_counter mismatch.\nCalled at %s:%d\n", file, line);
zassert_equal(pdu->llctrl.periodic_sync_ind.sid, p->sid,
"sid mismatch.\nCalled at %s:%d\n", file, line);
zassert_equal(pdu->llctrl.periodic_sync_ind.addr_type, p->addr_type,
"addr_type mismatch.\nCalled at %s:%d\n", file, line);
zassert_equal(pdu->llctrl.periodic_sync_ind.sca, p->sca,
"sca mismatch.\nCalled at %s:%d\n", file, line);
zassert_equal(pdu->llctrl.periodic_sync_ind.phy, p->phy,
"phy mismatch.\nCalled at %s:%d\n", file, line);
zassert_equal(pdu->llctrl.periodic_sync_ind.sync_conn_event_count, p->sync_conn_event_count,
"sync_conn_event_count mismatch.\nCalled at %s:%d\n", file, line);
zassert_mem_equal(&pdu->llctrl.periodic_sync_ind.sync_info, &p->sync_info,
sizeof(struct pdu_adv_sync_info),
"sync_info mismatch.\nCalled at %s:%d\n", file, line);
zassert_mem_equal(pdu->llctrl.periodic_sync_ind.adv_addr, p->adv_addr,
sizeof(p->adv_addr),
"adv_addr mismatch.\nCalled at %s:%d\n", file, line);
}

View file

@ -96,6 +96,7 @@ helper_pdu_encode_func_t *const helper_pdu_encode[] = {
[LL_CIS_RSP] = helper_pdu_encode_cis_rsp, [LL_CIS_RSP] = helper_pdu_encode_cis_rsp,
[LL_CIS_IND] = helper_pdu_encode_cis_ind, [LL_CIS_IND] = helper_pdu_encode_cis_ind,
[LL_CIS_TERMINATE_IND] = helper_pdu_encode_cis_terminate_ind, [LL_CIS_TERMINATE_IND] = helper_pdu_encode_cis_terminate_ind,
[LL_PERIODIC_SYNC_IND] = helper_pdu_encode_periodic_sync_ind,
[LL_ZERO] = helper_pdu_encode_zero, [LL_ZERO] = helper_pdu_encode_zero,
}; };
@ -134,6 +135,7 @@ helper_pdu_verify_func_t *const helper_pdu_verify[] = {
[LL_CIS_RSP] = helper_pdu_verify_cis_rsp, [LL_CIS_RSP] = helper_pdu_verify_cis_rsp,
[LL_CIS_IND] = helper_pdu_verify_cis_ind, [LL_CIS_IND] = helper_pdu_verify_cis_ind,
[LL_CIS_TERMINATE_IND] = helper_pdu_verify_cis_terminate_ind, [LL_CIS_TERMINATE_IND] = helper_pdu_verify_cis_terminate_ind,
[LL_PERIODIC_SYNC_IND] = helper_pdu_verify_periodic_sync_ind,
}; };
helper_pdu_ntf_verify_func_t *const helper_pdu_ntf_verify[] = { helper_pdu_ntf_verify_func_t *const helper_pdu_ntf_verify[] = {
@ -170,6 +172,7 @@ helper_pdu_ntf_verify_func_t *const helper_pdu_ntf_verify[] = {
[LL_CIS_RSP] = NULL, [LL_CIS_RSP] = NULL,
[LL_CIS_IND] = NULL, [LL_CIS_IND] = NULL,
[LL_CIS_TERMINATE_IND] = NULL, [LL_CIS_TERMINATE_IND] = NULL,
[LL_PERIODIC_SYNC_IND] = NULL,
}; };
helper_node_encode_func_t *const helper_node_encode[] = { helper_node_encode_func_t *const helper_node_encode[] = {
@ -203,6 +206,7 @@ helper_node_encode_func_t *const helper_node_encode[] = {
[LL_CIS_RSP] = NULL, [LL_CIS_RSP] = NULL,
[LL_CIS_IND] = NULL, [LL_CIS_IND] = NULL,
[LL_CIS_TERMINATE_IND] = NULL, [LL_CIS_TERMINATE_IND] = NULL,
[LL_PERIODIC_SYNC_IND] = NULL,
}; };
helper_node_verify_func_t *const helper_node_verify[] = { helper_node_verify_func_t *const helper_node_verify[] = {

View file

@ -20,6 +20,11 @@
#include <zephyr/bluetooth/bluetooth.h> #include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/sys/byteorder.h> #include <zephyr/sys/byteorder.h>
#include "hal/cpu.h"
#include "hal/ccm.h"
#include "hal/cntr.h"
#include "hal/ticker.h"
#include "util/memq.h" #include "util/memq.h"
#include "pdu_df.h" #include "pdu_df.h"
@ -35,6 +40,8 @@
#include "isoal_test_common.h" #include "isoal_test_common.h"
#include "isoal_test_debug.h" #include "isoal_test_debug.h"
#define ULL_TIME_WRAPPING_POINT_US (HAL_TICKER_TICKS_TO_US_64BIT(HAL_TICKER_CNTR_MASK))
#define ULL_TIME_SPAN_FULL_US (ULL_TIME_WRAPPING_POINT_US + 1)
/** /**
* Intializes a RX PDU buffer * Intializes a RX PDU buffer
@ -270,3 +277,17 @@ void init_test_data_buffer(uint8_t *buf, uint16_t size)
buf[i] = (uint8_t)(i & 0x00FF); buf[i] = (uint8_t)(i & 0x00FF);
} }
} }
/**
* @brief Wraps given time within the range of 0 to ULL_TIME_WRAPPING_POINT_US
* @param time_now Current time value
* @param time_diff Time difference (signed)
* @return Wrapped time after difference
*/
uint32_t ull_get_wrapped_time_us(uint32_t time_now_us, int32_t time_diff_us)
{
uint32_t result = ((uint64_t)time_now_us + ULL_TIME_SPAN_FULL_US + time_diff_us) %
((uint64_t)ULL_TIME_SPAN_FULL_US);
return result;
}

View file

@ -0,0 +1,16 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
project(bluetooth_ull_llcp_periodic_sync)
find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE})
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/controller/common common)
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/controller/uut uut)
target_link_libraries(testbinary PRIVATE uut common)
target_sources(testbinary
PRIVATE
src/main.c
)

View file

@ -0,0 +1,31 @@
# Copyright (c) 2022 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
# some of the control procedures in the BT LL depend on
# the following configs been set
config SOC_COMPATIBLE_NRF
default y
config BT_CTLR_DATA_LEN_UPDATE_SUPPORT
default y
config BT_CTLR_PHY_UPDATE_SUPPORT
default y
config BT_CTLR_PHY_CODED_SUPPORT
default y
config BT_CTLR_PHY_2M_SUPPORT
default y
config ENTROPY_NRF_FORCE_ALT
default n
config ENTROPY_NRF5_RNG
default n
source "tests/bluetooth/controller/common/Kconfig"
# Include Zephyr's Kconfig
source "Kconfig"

View file

@ -0,0 +1,43 @@
CONFIG_ZTEST=y
CONFIG_ASSERT=y
CONFIG_ASSERT_LEVEL=2
CONFIG_ASSERT_VERBOSE=y
CONFIG_BT=y
CONFIG_BT_HCI=y
CONFIG_BT_CTLR=y
CONFIG_BT_CTLR_PRIVACY=y
CONFIG_BT_LL_SW_SPLIT=y
CONFIG_BT_LLL_VENDOR_NORDIC=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_BUF_ACL_RX_SIZE=251
CONFIG_BT_DATA_LEN_UPDATE=y
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
CONFIG_BT_ASSERT=y
CONFIG_BT_CTLR_ASSERT_HANDLER=y
CONFIG_BT_CTLR_PER_INIT_FEAT_XCHG=y
CONFIG_BT_CTLR_SCA_UPDATE=y
CONFIG_BT_SCA_UPDATE=y
CONFIG_BT_PER_ADV=y
CONFIG_BT_PER_ADV_SYNC=y
CONFIG_BT_EXT_ADV=y
CONFIG_BT_CTLR_ADV_PERIODIC=y
CONFIG_BT_CTLR_ADV_PERIODIC_ADI_SUPPORT=n
CONFIG_BT_CTLR_ADV_EXT=y
CONFIG_BT_CTLR_SYNC_TRANSFER_SENDER=y
CONFIG_BT_CTLR_SYNC_TRANSFER_RECEIVER=y
CONFIG_BT_PER_ADV_SYNC_MAX=2
CONFIG_BT_CTLR_RL_SIZE=8
CONFIG_BT_PHY_UPDATE=y
CONFIG_BT_CTLR_PHY_2M=y
CONFIG_BT_CTLR_PHY_CODED=y

View file

@ -0,0 +1,656 @@
/*
* Copyright (c) 2024 Demant
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#include <zephyr/ztest.h>
#include <zephyr/fff.h>
DEFINE_FFF_GLOBALS;
#include <zephyr/bluetooth/hci.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/sys/slist.h>
#include <zephyr/sys/util.h>
#include "hal/ccm.h"
#include "util/util.h"
#include "util/mem.h"
#include "util/memq.h"
#include "util/mayfly.h"
#include "util/dbuf.h"
#include "pdu_df.h"
#include "lll/pdu_vendor.h"
#include "pdu.h"
#include "ll.h"
#include "ll_settings.h"
#include "ll_feat.h"
#include "lll.h"
#include "lll/lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "lll/lll_adv_types.h"
#include "lll_adv.h"
#include "lll/lll_adv_pdu.h"
#include "lll_chan.h"
#include "lll_scan.h"
#include "lll_sync.h"
#include "lll_sync_iso.h"
#include "ull_adv_types.h"
#include "ull_scan_types.h"
#include "ull_sync_types.h"
#include "ull_tx_queue.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_conn_types.h"
#include "ull_llcp.h"
#include "ull_llcp_internal.h"
#include "ull_sync_internal.h"
#include "ull_internal.h"
#include "helper_pdu.h"
#include "helper_util.h"
static struct ll_conn conn;
static struct ll_sync_set *sync;
static struct ll_adv_sync_set *adv_sync;
static void periodic_sync_setup(void *data)
{
test_setup(&conn);
}
/* Custom fakes for this test suite */
/* uint32_t mayfly_enqueue(uint8_t caller_id, uint8_t callee_id,
* uint8_t chain, struct mayfly *m);
*/
FAKE_VALUE_FUNC(uint32_t, mayfly_enqueue, uint8_t, uint8_t, uint8_t, struct mayfly *);
uint32_t mayfly_enqueue_custom_fake(uint8_t caller_id, uint8_t callee_id,
uint8_t chain, struct mayfly *m)
{
/* Only proceed if it is the right mayfly enqueue used for getting the offset */
if (m->param == &conn && chain == 1U) {
/* Mock that mayfly has run and ull_lp_past_offset_calc_reply()
* is called with the found past offset
*/
ull_lp_past_offset_calc_reply(&conn, 0, 0, 0);
}
return 0;
}
/* void ull_sync_transfer_received(struct ll_conn *conn, uint16_t service_data,
* struct pdu_adv_sync_info *si, uint16_t conn_event_count,
* uint16_t last_pa_event_counter, uint8_t sid,
* uint8_t addr_type, uint8_t sca, uint8_t phy,
* uint8_t *adv_addr, uint16_t sync_conn_event_count,
* uint8_t addr_resolved);
*/
FAKE_VOID_FUNC(ull_sync_transfer_received, struct ll_conn *, uint16_t,
struct pdu_adv_sync_info *,
uint16_t,
uint16_t,
uint8_t,
uint8_t,
uint8_t,
uint8_t,
uint8_t *,
uint16_t,
uint8_t);
void ull_sync_transfer_received_custom_fake(struct ll_conn *conn, uint16_t service_data,
struct pdu_adv_sync_info *si, uint16_t conn_event_count,
uint16_t last_pa_event_counter, uint8_t sid,
uint8_t addr_type, uint8_t sca, uint8_t phy,
uint8_t *adv_addr, uint16_t sync_conn_event_count,
uint8_t addr_resolved)
{
}
/* +-----+ +-------+ +-----+
* | UT | | LL_A | | LT |
* +-----+ +-------+ +-----+
* | | |
* | Start | |
* | Periodic Adv. Sync Transfer| |
* | Proc. | |
* |--------------------------->| |
* | | |
* | | LL_PERIODIC_SYNC_IND|
* | |------------------> |
* | | 'll_ack'|
* | | |
* |Periodic Adv. Sync Transfer | |
* | Proc. Complete | |
* |<---------------------------| |
* | | |
*/
ZTEST(periodic_sync_transfer, test_periodic_sync_transfer_loc)
{
uint8_t err;
struct node_tx *tx;
struct proc_ctx *ctx;
uint16_t service_data = 0;
adv_sync = NULL;
sync = ull_sync_is_enabled_get(0);
struct pdu_data_llctrl_periodic_sync_ind local_periodic_sync_ind = {
.id = 0x00,
.conn_event_count = 0x00,
.last_pa_event_counter = 0x00,
.sid = 0x00,
.addr_type = 0x00,
.sca = 0x00,
.phy = 0x00,
.adv_addr = { 0, 0, 0, 0, 0, 0},
.sync_conn_event_count = 0
};
/* Reset and setup mayfly_enqueue_custom_fake */
RESET_FAKE(mayfly_enqueue);
mayfly_enqueue_fake .custom_fake = mayfly_enqueue_custom_fake;
/* Initialise sync_info */
memset(&local_periodic_sync_ind.sync_info, 0, sizeof(struct pdu_adv_sync_info));
/* Role */
test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
/* Connect */
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
conn.llcp.fex.features_peer |= BIT64(BT_LE_FEAT_BIT_PAST_RECV);
/* Initiate a Periodic Adv. Sync Transfer Procedure */
err = ull_cp_periodic_sync(&conn, sync, adv_sync, service_data);
zassert_equal(err, BT_HCI_ERR_SUCCESS);
/* Connection event done with successful rx from peer */
ctx = llcp_lr_peek_proc(&conn, PROC_PERIODIC_SYNC);
if (ctx) {
ctx->data.periodic_sync.conn_start_to_actual_us = 0;
ctx->data.periodic_sync.conn_evt_trx = 1;
llcp_lp_past_conn_evt_done(&conn, ctx);
}
/* Prepare */
event_prepare(&conn);
/* Tx Queue should have one LL Control PDU */
lt_rx(LL_PERIODIC_SYNC_IND, &conn, &tx, &local_periodic_sync_ind);
lt_rx_q_is_empty(&conn);
/* TX Ack */
event_tx_ack(&conn, tx);
/* Done */
event_done(&conn);
/* Release tx node */
ull_cp_release_tx(&conn, tx);
/* There should be no host notifications */
ut_rx_q_is_empty();
zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
"Free CTX buffers %d and ctx_buffers_cnt is %d", llcp_ctx_buffers_free(),
test_ctx_buffers_cnt());
}
ZTEST(periodic_sync_transfer, test_periodic_sync_transfer_loc_2)
{
uint8_t err;
uint16_t service_data = 0;
sync = ull_sync_is_enabled_get(0);
adv_sync = NULL;
ull_cp_init();
ull_tx_q_init(&conn.tx_q);
ull_llcp_init(&conn);
conn.llcp.fex.features_peer |= BIT64(BT_LE_FEAT_BIT_PAST_RECV);
err = ull_cp_periodic_sync(&conn, sync, adv_sync, service_data);
for (int i = 0U; i < CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM; i++) {
zassert_equal(err, BT_HCI_ERR_SUCCESS);
err = ull_cp_periodic_sync(&conn, sync, adv_sync, service_data);
}
zassert_not_equal(err, BT_HCI_ERR_SUCCESS, NULL);
zassert_equal(llcp_ctx_buffers_free(),
test_ctx_buffers_cnt() - CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM,
"Free CTX buffers %d", llcp_ctx_buffers_free());
}
/* +-----+ +-------+ +-----+
* | UT | | LL_A | | LT |
* +-----+ +-------+ +-----+
* | | |
* | | LL_PERIODIC_SYNC_IND |
* | |<----------------------- |
* | | |
* | | |
* | | |
* | | |
*/
ZTEST(periodic_sync_transfer, test_periodic_sync_transfer_rem)
{
struct pdu_data_llctrl_periodic_sync_ind remote_periodic_sync_ind = {
.id = 0x01,
.conn_event_count = 0x00,
.last_pa_event_counter = 0x00,
.sid = 0x00,
.addr_type = 0x01,
.sca = 0x00,
.phy = 0x01,
.adv_addr = { 0, 0, 0, 0, 0, 0},
.sync_conn_event_count = 0
};
/* Reset and setup fake functions */
RESET_FAKE(ull_sync_transfer_received);
ull_sync_transfer_received_fake.custom_fake = ull_sync_transfer_received_custom_fake;
RESET_FAKE(mayfly_enqueue);
mayfly_enqueue_fake .custom_fake = mayfly_enqueue_custom_fake;
/* Initialise sync_info */
memset(&remote_periodic_sync_ind.sync_info, 0, sizeof(struct pdu_adv_sync_info));
/* Role */
test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
/* Connect */
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
conn.llcp.fex.features_peer |= BIT64(BT_LE_FEAT_BIT_PAST_RECV);
/* Prepare */
event_prepare(&conn);
/* Rx */
lt_tx(LL_PERIODIC_SYNC_IND, &conn, &remote_periodic_sync_ind);
/* Done */
event_done(&conn);
/* Prepare */
event_prepare(&conn);
/* Tx Queue should have one LL Control PDU */
lt_rx_q_is_empty(&conn);
/* Done */
event_done(&conn);
/* There should not be a host notifications */
ut_rx_q_is_empty();
zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
"Free CTX buffers %d and ctx_buffers_cnt is %d", llcp_ctx_buffers_free(),
test_ctx_buffers_cnt());
/* Verify that ull_sync_transfer_received was called,
* hence the phy invalidation mechanism works
*/
zassert_equal(ull_sync_transfer_received_fake.call_count, 1,
"ull_sync_transfer_received_fake.call_count is %d and expected: %d",
ull_sync_transfer_received_fake.call_count, 1);
}
/* +-----+ +-------+ +-----+
* | UT | | LL_A | | LT |
* +-----+ +-------+ +-----+
* | | |
* | | LL_PERIODIC_SYNC_IND |
* | |<------------------------|
* | | |
* | | |
* | | |
* | | |
* | Start | |
* | Periodic Adv. Sync Transfer| |
* | Proc. | |
* |--------------------------->| |
* | | |
* | | |
* | | LL_PERIODIC_SYNC_IND |
* | |------------------------>|
* | | 'll_ack'|
* |Periodic Adv. Sync Transfer | |
* | Proc. Complete | |
* |<---------------------------| |
* | | |
*/
ZTEST(periodic_sync_transfer, test_periodic_sync_transfer_rem_2)
{
uint8_t err;
struct node_tx *tx;
uint16_t service_data = 0;
struct proc_ctx *ctx;
sync = ull_sync_is_enabled_get(0);
adv_sync = NULL;
struct pdu_data_llctrl_periodic_sync_ind local_periodic_sync_ind = {
.id = 0x00,
.conn_event_count = 0x01,
.last_pa_event_counter = 0x00,
.sid = 0x00,
.addr_type = 0x00,
.sca = 0x00,
.phy = 0x00,
.adv_addr = { 0, 0, 0, 0, 0, 0},
.sync_conn_event_count = 0x01
};
struct pdu_data_llctrl_periodic_sync_ind remote_periodic_sync_ind = {
.id = 0x01,
.conn_event_count = 0x00,
.last_pa_event_counter = 0x00,
.sid = 0x00,
.addr_type = 0x01,
.sca = 0x00,
.phy = 0x01,
.adv_addr = { 0, 0, 0, 0, 0, 0},
.sync_conn_event_count = 0
};
/* Reset and setup fake functions */
RESET_FAKE(ull_sync_transfer_received);
ull_sync_transfer_received_fake.custom_fake = ull_sync_transfer_received_custom_fake;
RESET_FAKE(mayfly_enqueue);
mayfly_enqueue_fake .custom_fake = mayfly_enqueue_custom_fake;
/* Initialise sync_info */
memset(&local_periodic_sync_ind.sync_info, 0, sizeof(struct pdu_adv_sync_info));
memset(&remote_periodic_sync_ind.sync_info, 0, sizeof(struct pdu_adv_sync_info));
/* Role */
test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
/* Connect */
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
conn.llcp.fex.features_peer |= BIT64(BT_LE_FEAT_BIT_PAST_RECV);
/* Prepare */
event_prepare(&conn);
/* Rx */
lt_tx(LL_PERIODIC_SYNC_IND, &conn, &remote_periodic_sync_ind);
/* Done */
event_done(&conn);
/* Initiate a Periodic Adv. Sync Transfer Procedure */
err = ull_cp_periodic_sync(&conn, sync, adv_sync, service_data);
zassert_equal(err, BT_HCI_ERR_SUCCESS);
/* Connection event done with successful rx from peer */
ctx = llcp_lr_peek_proc(&conn, PROC_PERIODIC_SYNC);
if (ctx) {
ctx->data.periodic_sync.conn_start_to_actual_us = 0;
ctx->data.periodic_sync.conn_evt_trx = 1;
llcp_lp_past_conn_evt_done(&conn, ctx);
}
/* Prepare */
event_prepare(&conn);
/* Tx Queue should have one LL Control PDU */
lt_rx(LL_PERIODIC_SYNC_IND, &conn, &tx, &local_periodic_sync_ind);
lt_rx_q_is_empty(&conn);
/* TX Ack */
event_tx_ack(&conn, tx);
/* Done */
event_done(&conn);
/* Release tx node */
ull_cp_release_tx(&conn, tx);
/* There should be no host notifications */
ut_rx_q_is_empty();
zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
"Free CTX buffers %d and ctx_buffers_cnt is %d", llcp_ctx_buffers_free(),
test_ctx_buffers_cnt());
/* Verify that ull_sync_transfer_received was called,
* hence the phy invalidation mechanism works
*/
zassert_equal(ull_sync_transfer_received_fake.call_count, 1,
"ull_sync_transfer_received_fake.call_count is %d and expected: %d",
ull_sync_transfer_received_fake.call_count, 1);
}
/* +-----+ +-------+ +-----+
* | UT | | LL_A | | LT |
* +-----+ +-------+ +-----+
* | | |
* | Start | |
* | Periodic Adv. Sync Transfer| |
* | Proc. | |
* |--------------------------->| |
* | | |
* | | LL_PERIODIC_SYNC_IND|
* | |------------------> |
* | | 'll_ack'|
* | | |
* | | |
* | | |
* |Periodic Adv. Sync Transfer | |
* |Proc. Complete | |
* |<---------------------------| |
* | Start | |
* | Periodic Adv. Sync Transfer| |
* | Proc. | |
* |--------------------------->| |
* | | |
* | | |
* | | LL_PERIODIC_SYNC_IND|
* | |------------------> |
* |Periodic Adv. Sync Transfer | 'll_ack'|
* | Proc. Complete | |
* |<---------------------------| |
* | | |
*/
ZTEST(periodic_sync_transfer, test_periodic_sync_transfer_loc_twice)
{
uint8_t err;
struct node_tx *tx;
uint16_t service_data = 0;
struct proc_ctx *ctx;
sync = ull_sync_is_enabled_get(0);
adv_sync = NULL;
struct pdu_data_llctrl_periodic_sync_ind local_periodic_sync_ind = {
.id = 0x00,
.conn_event_count = 0x00,
.last_pa_event_counter = 0x00,
.sid = 0x00,
.addr_type = 0x00,
.sca = 0x00,
.phy = 0x00,
.adv_addr = { 0, 0, 0, 0, 0, 0},
.sync_conn_event_count = 0
};
/* Reset and setup mayfly_enqueue_custom_fake */
RESET_FAKE(mayfly_enqueue);
mayfly_enqueue_fake .custom_fake = mayfly_enqueue_custom_fake;
/* Initialise sync_info */
memset(&local_periodic_sync_ind.sync_info, 0, sizeof(struct pdu_adv_sync_info));
/* Role */
test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
/* Connect */
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
conn.llcp.fex.features_peer |= BIT64(BT_LE_FEAT_BIT_PAST_RECV);
/* Initiate a periodic_sync Procedure */
err = ull_cp_periodic_sync(&conn, sync, adv_sync, service_data);
zassert_equal(err, BT_HCI_ERR_SUCCESS);
/* Connection event done with successful rx from peer */
ctx = llcp_lr_peek_proc(&conn, PROC_PERIODIC_SYNC);
if (ctx) {
ctx->data.periodic_sync.conn_start_to_actual_us = 0;
ctx->data.periodic_sync.conn_evt_trx = 1;
llcp_lp_past_conn_evt_done(&conn, ctx);
}
/* Initiate a periodic_sync Procedure */
err = ull_cp_periodic_sync(&conn, sync, adv_sync, service_data);
zassert_equal(err, BT_HCI_ERR_SUCCESS);
/* Prepare */
event_prepare(&conn);
/* Tx Queue should have one LL Control PDU */
lt_rx(LL_PERIODIC_SYNC_IND, &conn, &tx, &local_periodic_sync_ind);
lt_rx_q_is_empty(&conn);
/* TX Ack */
event_tx_ack(&conn, tx);
/* Done */
event_done(&conn);
/* Increase connection event count */
local_periodic_sync_ind.conn_event_count++;
local_periodic_sync_ind.sync_conn_event_count++;
/* There should be no host notifications */
ut_rx_q_is_empty();
/* Connection event done with successful rx from peer */
ctx = llcp_lr_peek_proc(&conn, PROC_PERIODIC_SYNC);
if (ctx) {
ctx->data.periodic_sync.conn_start_to_actual_us = 0;
ctx->data.periodic_sync.conn_evt_trx = 1;
llcp_lp_past_conn_evt_done(&conn, ctx);
}
/* Prepare */
event_prepare(&conn);
/* Tx Queue should have one LL Control PDU */
lt_rx(LL_PERIODIC_SYNC_IND, &conn, &tx, &local_periodic_sync_ind);
lt_rx_q_is_empty(&conn);
/* TX Ack */
event_tx_ack(&conn, tx);
/* Done */
event_done(&conn);
/* Release tx node */
ull_cp_release_tx(&conn, tx);
/* There should be no host notifications */
ut_rx_q_is_empty();
/* Second attempt to run the periodic_sync completes immediately in idle state.
* The context is released just after that.
*/
zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
"Free CTX buffers %d and ctx_buffers_cnt is %d", llcp_ctx_buffers_free(),
test_ctx_buffers_cnt());
}
/*
* +-----+ +-------+ +-----+
* | UT | | LL_A | | LT |
* +-----+ +-------+ +-----+
* | | |
* | | LL_PERIODIC_SYNC_IND |
* | | (Invalid PHY) |
* | |<----------------------- |
* | | |
* | | |
* | | |
* | | |
*/
ZTEST(periodic_sync_transfer, test_periodic_sync_transfer_invalid_phy)
{
struct pdu_data_llctrl_periodic_sync_ind remote_periodic_sync_ind = {
.id = 0x01,
.conn_event_count = 0x00,
.last_pa_event_counter = 0x00,
.sid = 0x00,
.addr_type = 0x01,
.sca = 0x00,
.phy = 0x03,
.adv_addr = { 0, 0, 0, 0, 0, 0},
.sync_conn_event_count = 0
};
/* Reset and setup ull_sync_transfer_received fake */
RESET_FAKE(ull_sync_transfer_received);
ull_sync_transfer_received_fake.custom_fake = ull_sync_transfer_received_custom_fake;
RESET_FAKE(mayfly_enqueue);
mayfly_enqueue_fake .custom_fake = mayfly_enqueue_custom_fake;
/* Initialise sync_info */
memset(&remote_periodic_sync_ind.sync_info, 0, sizeof(struct pdu_adv_sync_info));
/* Role */
test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
/* Connect */
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
conn.llcp.fex.features_peer |= BIT64(BT_LE_FEAT_BIT_PAST_RECV);
/* Prepare */
event_prepare(&conn);
/* Rx */
lt_tx(LL_PERIODIC_SYNC_IND, &conn, &remote_periodic_sync_ind);
/* Done */
event_done(&conn);
/* Prepare */
event_prepare(&conn);
/* Tx Queue should have one LL Control PDU */
lt_rx_q_is_empty(&conn);
/* Done */
event_done(&conn);
/* There should not be a host notifications */
ut_rx_q_is_empty();
zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
"Free CTX buffers %d and ctx_buffers_cnt is %d", llcp_ctx_buffers_free(),
test_ctx_buffers_cnt());
/* Verify that ull_sync_transfer_received was not called,
* hence the phy invalidation mechanism works
*/
zassert_equal(ull_sync_transfer_received_fake.call_count, 0,
"ull_sync_transfer_received_fake.call_count is %d and expected: %d",
ull_sync_transfer_received_fake.call_count, 0);
}
ZTEST_SUITE(periodic_sync_transfer, NULL, NULL, periodic_sync_setup, NULL, NULL);

View file

@ -0,0 +1,8 @@
common:
tags:
- bluetooth
- bt_periodic_sync
- bt_ull_llcp
tests:
bluetooth.controller.ctrl_periodic_sync.test:
type: unit

View file

@ -16,12 +16,16 @@ add_library(mocks STATIC
src/assert.c src/assert.c
src/util.c src/util.c
src/ticker.c src/ticker.c
src/isoal.c
src/ull.c src/ull.c
src/ull_conn_iso.c src/ull_conn_iso.c
src/ull_peripheral.c src/ull_peripheral.c
src/ull_peripheral_iso.c src/ull_peripheral_iso.c
src/ull_central.c src/ull_central.c
src/ull_scan.c src/ull_scan.c
src/ull_sync.c
src/ull_adv_sync.c
src/ull_filter.c
src/lll_clock.c src/lll_clock.c
) )

View file

@ -68,3 +68,30 @@
/* Macro defining the margin for positioning re-scheduled nodes */ /* Macro defining the margin for positioning re-scheduled nodes */
#define HAL_TICKER_RESCHEDULE_MARGIN \ #define HAL_TICKER_RESCHEDULE_MARGIN \
HAL_TICKER_US_TO_TICKS(150) HAL_TICKER_US_TO_TICKS(150)
/* Remove ticks and return positive remainder value in microseconds */
static inline void hal_ticker_remove_jitter(uint32_t *ticks,
uint32_t *remainder)
{
/* Is remainder less than 1 us */
if ((*remainder & BIT(31)) || !(*remainder / HAL_TICKER_PSEC_PER_USEC)) {
*ticks -= 1U;
*remainder += HAL_TICKER_CNTR_CLK_UNIT_FSEC / HAL_TICKER_FSEC_PER_PSEC;
}
/* pico seconds to micro seconds unit */
*remainder /= HAL_TICKER_PSEC_PER_USEC;
}
/* Add ticks and return positive remainder value in microseconds */
static inline void hal_ticker_add_jitter(uint32_t *ticks, uint32_t *remainder)
{
/* Is remainder less than 1 us */
if ((*remainder & BIT(31)) || !(*remainder / HAL_TICKER_PSEC_PER_USEC)) {
*ticks += 1U;
*remainder += HAL_TICKER_CNTR_CLK_UNIT_FSEC / HAL_TICKER_FSEC_PER_PSEC;
}
/* pico seconds to micro seconds unit */
*remainder /= HAL_TICKER_PSEC_PER_USEC;
}

View file

@ -113,5 +113,11 @@ static inline struct pdu_adv *lll_adv_sync_data_peek(struct lll_adv_sync *lll, v
return (void *)lll->data.pdu[last]; return (void *)lll->data.pdu[last];
} }
static inline struct pdu_adv *lll_adv_sync_data_curr_get(struct lll_adv_sync *lll)
{
return (void *)lll->data.pdu[lll->data.first];
}
#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ #endif /* CONFIG_BT_CTLR_ADV_PERIODIC */
#endif /* CONFIG_BT_CTLR_ADV_EXT */ #endif /* CONFIG_BT_CTLR_ADV_EXT */

View file

@ -0,0 +1,13 @@
/*
* Copyright (c) 2024 Demant A/S
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#include <zephyr/ztest.h>
uint32_t isoal_get_wrapped_time_us(uint32_t time_now_us, int32_t time_diff_us)
{
return time_now_us;
}

View file

@ -25,7 +25,8 @@ uint32_t mayfly_is_enabled(uint8_t caller_id, uint8_t callee_id)
return 0; return 0;
} }
uint32_t mayfly_enqueue(uint8_t caller_id, uint8_t callee_id, uint8_t chain, struct mayfly *m) __weak uint32_t mayfly_enqueue(uint8_t caller_id, uint8_t callee_id,
uint8_t chain, struct mayfly *m)
{ {
return 0; return 0;
} }

View file

@ -32,3 +32,18 @@ uint8_t ticker_stop(uint8_t instance_index, uint8_t user_id, uint8_t ticker_id,
{ {
return TICKER_STATUS_SUCCESS; return TICKER_STATUS_SUCCESS;
} }
void ticker_job_sched(uint8_t instance_index, uint8_t user_id)
{
}
uint8_t ticker_next_slot_get_ext(uint8_t instance_index, uint8_t user_id,
uint8_t *ticker_id, uint32_t *ticks_current,
uint32_t *ticks_to_expire,
uint32_t *remainder, uint16_t *lazy,
ticker_op_match_func fp_match_op_func,
void *match_op_context,
ticker_op_func fp_op_func, void *op_context)
{
return TICKER_STATUS_SUCCESS;
}

View file

@ -384,3 +384,15 @@ static inline void rx_alloc(uint8_t max)
ll_rx_link_inc_quota(-1); ll_rx_link_inc_quota(-1);
} }
} }
#if defined(CONFIG_BT_CTLR_ISO) || \
defined(CONFIG_BT_CTLR_SYNC_TRANSFER_SENDER) || \
defined(CONFIG_BT_CTLR_SYNC_TRANSFER_RECEIVER)
uint32_t ull_get_wrapped_time_us(uint32_t time_now_us, int32_t time_diff_us)
{
return 0;
}
#endif /* CONFIG_BT_CTLR_ISO ||
* CONFIG_BT_CTLR_SYNC_TRANSFER_SENDER ||
* CONFIG_BT_CTLR_SYNC_TRANSFER_RECEIVER
*/

View file

@ -0,0 +1,29 @@
/*
* Copyright (c) 2024 Demant A/S
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#include <zephyr/ztest.h>
#include <zephyr/bluetooth/hci_types.h>
#include "util/mem.h"
#include "util/memq.h"
#include "pdu_df.h"
#include "lll/pdu_vendor.h"
#include "pdu.h"
#include "lll.h"
struct ll_adv_sync_set *ull_adv_sync_get(uint8_t handle)
{
return NULL;
}
uint16_t ull_adv_sync_handle_get(const struct ll_adv_sync_set *sync)
{
return 0;
}

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2016 Nordic Semiconductor ASA
* Copyright (c) 2016 Vinayak Kariappa Chettimada
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#include <zephyr/ztest.h>
#include <zephyr/bluetooth/hci_types.h>
#include "util/mem.h"
#include "util/memq.h"
#include "pdu_df.h"
#include "lll/pdu_vendor.h"
#include "pdu.h"
#include "lll.h"
#include "lll_filter.h"
static uint8_t bt_addr[BDADDR_SIZE] = { 0, 0, 0, 0, 0, 0};
#define BT_CTLR_RL_SIZE 8
uint8_t ll_rl_size_get(void)
{
return BT_CTLR_RL_SIZE;
}
uint8_t ull_filter_rl_find(uint8_t id_addr_type, uint8_t const *const id_addr,
uint8_t *const free_idx)
{
return FILTER_IDX_NONE;
}
void ull_filter_rpa_update(bool timeout)
{
}
const uint8_t *ull_filter_tgta_get(uint8_t rl_idx)
{
return bt_addr;
}

View file

@ -0,0 +1,59 @@
/*
* Copyright (c) 2016 Nordic Semiconductor ASA
* Copyright (c) 2016 Vinayak Kariappa Chettimada
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#include <zephyr/ztest.h>
#include <zephyr/bluetooth/hci_types.h>
#include "hal/cpu.h"
#include "hal/ccm.h"
#include "util/util.h"
#include "util/mem.h"
#include "util/memq.h"
#include "pdu_df.h"
#include "lll/pdu_vendor.h"
#include "pdu.h"
#include "lll.h"
#include "lll/lll_adv_types.h"
#include "lll_adv.h"
#include "ull_adv_types.h"
#include "lll_sync.h"
#include "lll_sync_iso.h"
#include "ull_sync_types.h"
#define BT_PER_ADV_SYNC_MAX 1
static struct ll_sync_set ll_sync[BT_PER_ADV_SYNC_MAX];
struct ll_sync_set *ull_sync_set_get(uint16_t handle)
{
if (handle >= BT_PER_ADV_SYNC_MAX) {
return NULL;
}
return &ll_sync[handle];
}
struct ll_sync_set *ull_sync_is_enabled_get(uint16_t handle)
{
struct ll_sync_set *sync;
sync = ull_sync_set_get(handle);
if (!sync) {
return NULL;
}
return sync;
}
uint16_t ull_sync_handle_get(struct ll_sync_set *sync)
{
return 0;
}

View file

@ -34,6 +34,12 @@ if (CONFIG_BT_CTLR_LE_ENC)
) )
endif() endif()
if (CONFIG_BT_CTLR_SYNC_TRANSFER_SENDER OR CONFIG_BT_CTLR_SYNC_TRANSFER_RECEIVER)
target_sources(uut PRIVATE
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/ull_llcp_past.c
)
endif()
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl mocks) add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl mocks)