bluetooth: controller: CIS Terminate Procedure PDU flow and unittest

Implementing PDU flow and unittest for PDU flow of CIS Terminate.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
This commit is contained in:
Erik Brockhoff 2022-07-06 15:55:16 +02:00 committed by Carles Cufí
parent f6ee9362cd
commit 22ddc01f36
39 changed files with 542 additions and 6 deletions

View file

@ -38,6 +38,7 @@
#include "lll/lll_df_types.h"
#include "lll_conn.h"
#include "lll_filter.h"
#include "lll_conn_iso.h"
#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY)
#include "ll_sw/ull_tx_queue.h"
@ -58,7 +59,11 @@
#include "ll_settings.h"
#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY)
#include "ll_sw/ull_llcp.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_llcp.h"
#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)

View file

@ -36,6 +36,7 @@
#include "lll_conn.h"
#include "lll_central.h"
#include "lll_filter.h"
#include "lll_conn_iso.h"
#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY)
#include "ull_tx_queue.h"
@ -57,7 +58,11 @@
#include "ll_settings.h"
#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY)
#include "ll_sw/ull_llcp.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_llcp.h"
#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)

View file

@ -29,15 +29,19 @@
#include "lll/lll_df_types.h"
#include "lll_sync.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "lll_df.h"
#include "lll/lll_df_internal.h"
#include "isoal.h"
#include "ull_scan_types.h"
#include "ull_sync_types.h"
#include "ull_sync_internal.h"
#include "ull_adv_types.h"
#include "ull_tx_queue.h"
#include "ull_conn_types.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_conn_internal.h"
#include "ull_df_types.h"
#include "ull_df_internal.h"

View file

@ -26,9 +26,15 @@
#include "lll.h"
#include "lll/lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "ull_tx_queue.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_conn_iso_internal.h"
#include "ull_internal.h"
#include "ull_conn_types.h"
#include "ull_conn_internal.h"
@ -358,6 +364,9 @@ struct proc_ctx *llcp_create_local_procedure(enum llcp_proc proc)
llcp_lp_comm_init_proc(ctx);
break;
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_REQ */
case PROC_CIS_TERMINATE:
llcp_lp_comm_init_proc(ctx);
break;
default:
/* Unknown procedure */
LL_ASSERT(0);
@ -429,6 +438,9 @@ struct proc_ctx *llcp_create_remote_procedure(enum llcp_proc proc)
llcp_rp_comm_init_proc(ctx);
break;
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_REQ */
case PROC_CIS_TERMINATE:
llcp_rp_comm_init_proc(ctx);
break;
default:
/* Unknown procedure */
LL_ASSERT(0);
@ -801,6 +813,31 @@ uint8_t ull_cp_terminate(struct ll_conn *conn, uint8_t error_code)
return BT_HCI_ERR_SUCCESS;
}
#if defined(CONFIG_BT_CTLR_CENTRAL_ISO) || defined(CONFIG_BT_CTLR_PERIPHERAL_ISO)
uint8_t ull_cp_cis_terminate(struct ll_conn *conn,
struct ll_conn_iso_stream *cis,
uint8_t error_code)
{
struct proc_ctx *ctx;
if (conn->lll.handle != cis->lll.acl_handle) {
return BT_HCI_ERR_CMD_DISALLOWED;
}
ctx = llcp_create_local_procedure(PROC_CIS_TERMINATE);
if (!ctx) {
return BT_HCI_ERR_CMD_DISALLOWED;
}
ctx->data.cis_term.cig_id = cis->group->cig_id;
ctx->data.cis_term.cis_id = cis->cis_id;
ctx->data.cis_term.error_code = error_code;
llcp_lr_enqueue(conn, ctx);
return BT_HCI_ERR_SUCCESS;
}
#endif /* defined(CONFIG_BT_CTLR_CENTRAL_ISO) || defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) */
#if defined(CONFIG_BT_CENTRAL)
uint8_t ull_cp_chan_map_update(struct ll_conn *conn, const uint8_t chm[5])

View file

@ -152,6 +152,12 @@ uint8_t ull_cp_remote_cpr_pending(struct ll_conn *conn);
*/
uint8_t ull_cp_terminate(struct ll_conn *conn, uint8_t error_code);
/**
* @brief Initiate a CIS Termination Procedure.
*/
uint8_t ull_cp_cis_terminate(struct ll_conn *conn, struct ll_conn_iso_stream *cis,
uint8_t error_code);
/**
* @brief Initiate a Channel Map Update Procedure.
*/

View file

@ -25,8 +25,15 @@
#include "lll.h"
#include "lll/lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "ull_tx_queue.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_conn_iso_internal.h"
#include "ull_conn_types.h"
#include "ull_llcp.h"
#include "ull_llcp_internal.h"

View file

@ -26,9 +26,15 @@
#include "ll_feat.h"
#include "lll/lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "ull_tx_queue.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_conn_iso_internal.h"
#include "ull_conn_types.h"
#include "ull_chan_internal.h"
#include "ull_llcp.h"
@ -141,6 +147,13 @@ static void lp_comm_tx(struct ll_conn *conn, struct proc_ctx *ctx)
ctx->tx_ack = tx;
ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED;
break;
#if defined(CONFIG_BT_CTLR_CENTRAL_ISO) || defined(CONFIG_BT_CTLR_PERIPHERAL_ISO)
case PROC_CIS_TERMINATE:
llcp_pdu_encode_cis_terminate_ind(ctx, pdu);
ctx->tx_ack = tx;
ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED;
break;
#endif /* CONFIG_BT_CTLR_CENTRAL_ISO || CONFIG_BT_CTLR_PERIPHERAL_ISO */
#if defined(CONFIG_BT_CTLR_DATA_LENGTH)
case PROC_DATA_LENGTH_UPDATE:
llcp_pdu_encode_length_req(conn, pdu);
@ -415,6 +428,16 @@ static void lp_comm_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t
/* Mark the connection for termination */
conn->llcp_terminate.reason_final = BT_HCI_ERR_LOCALHOST_TERM_CONN;
break;
#if defined(CONFIG_BT_CTLR_CENTRAL_ISO) || defined(CONFIG_BT_CTLR_PERIPHERAL_ISO)
case PROC_CIS_TERMINATE:
/* No notification */
llcp_lr_complete(conn);
ctx->state = LP_COMMON_STATE_IDLE;
/* Handle CIS termination */
/* TODO: Do termination */
break;
#endif /* CONFIG_BT_CTLR_CENTRAL_ISO || CONFIG_BT_CTLR_PERIPHERAL_ISO */
#if defined(CONFIG_BT_CTLR_DATA_LENGTH)
case PROC_DATA_LENGTH_UPDATE:
if (ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_LENGTH_RSP) {
@ -520,6 +543,16 @@ static void lp_comm_send_req(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t
ctx->state = LP_COMMON_STATE_WAIT_TX_ACK;
}
break;
#if defined(CONFIG_BT_CTLR_CENTRAL_ISO) || defined(CONFIG_BT_CTLR_PERIPHERAL_ISO)
case PROC_CIS_TERMINATE:
if (ctx->pause || !llcp_tx_alloc_peek(conn, ctx)) {
ctx->state = LP_COMMON_STATE_WAIT_TX;
} else {
lp_comm_tx(conn, ctx);
ctx->state = LP_COMMON_STATE_WAIT_TX_ACK;
}
break;
#endif /* CONFIG_BT_CTLR_CENTRAL_ISO || CONFIG_BT_CTLR_PERIPHERAL_ISO */
#if defined(CONFIG_BT_CTLR_DATA_LENGTH)
case PROC_DATA_LENGTH_UPDATE:
if (!ull_cp_remote_dle_pending(conn)) {
@ -624,6 +657,12 @@ static void lp_comm_st_wait_tx_ack(struct ll_conn *conn, struct proc_ctx *ctx, u
ctx->tx_ack = NULL;
lp_comm_complete(conn, ctx, evt, param);
break;
#if defined(CONFIG_BT_CTLR_CENTRAL_ISO) || defined(CONFIG_BT_CTLR_PERIPHERAL_ISO)
case PROC_CIS_TERMINATE:
ctx->tx_ack = NULL;
lp_comm_complete(conn, ctx, evt, param);
break;
#endif /* CONFIG_BT_CTLR_CENTRAL_ISO || CONFIG_BT_CTLR_PERIPHERAL_ISO */
default:
/* Ignore for other procedures */
break;
@ -835,6 +874,9 @@ static void rp_comm_rx_decode(struct ll_conn *conn, struct proc_ctx *ctx, struct
/* Make sure no data is tx'ed after RX of terminate ind */
llcp_tx_pause_data(conn, LLCP_TX_QUEUE_PAUSE_DATA_TERMINATE);
break;
case PDU_DATA_LLCTRL_TYPE_CIS_TERMINATE_IND:
llcp_pdu_decode_cis_terminate_ind(ctx, pdu);
break;
#if defined(CONFIG_BT_CTLR_DATA_LENGTH)
case PDU_DATA_LLCTRL_TYPE_LENGTH_REQ:
llcp_pdu_decode_length_req(conn, pdu);
@ -1080,6 +1122,14 @@ static void rp_comm_send_rsp(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t
rp_comm_terminate(conn, ctx);
#endif
break;
#if defined(CONFIG_BT_CTLR_CENTRAL_ISO) || defined(CONFIG_BT_CTLR_PERIPHERAL_ISO)
case PROC_CIS_TERMINATE:
/* No response */
llcp_rr_complete(conn);
ctx->state = RP_COMMON_STATE_IDLE;
break;
#endif /* CONFIG_BT_CTLR_CENTRAL_ISO || CONFIG_BT_CTLR_PERIPHERAL_ISO */
#if defined(CONFIG_BT_CTLR_DATA_LENGTH)
case PROC_DATA_LENGTH_UPDATE:
if (llcp_rr_ispaused(conn) || !llcp_tx_alloc_peek(conn, ctx)) {

View file

@ -27,7 +27,15 @@
#include "lll/lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "ull_tx_queue.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_conn_iso_internal.h"
#include "ull_conn_internal.h"
#include "ull_conn_types.h"
#include "ull_internal.h"

View file

@ -27,9 +27,15 @@
#include "lll.h"
#include "lll/lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "ull_tx_queue.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_conn_iso_internal.h"
#include "ull_conn_types.h"
#include "ull_internal.h"
#include "ull_llcp.h"

View file

@ -26,9 +26,11 @@ enum llcp_proc {
PROC_CHAN_MAP_UPDATE,
PROC_DATA_LENGTH_UPDATE,
PROC_CTE_REQ,
PROC_CIS_TERMINATE,
/* A helper enum entry, to use in pause procedure context */
PROC_NONE = 0x0,
};
enum llcp_tx_q_pause_data_mask {
LLCP_TX_QUEUE_PAUSE_DATA_ENCRYPTION = 0x01,
LLCP_TX_QUEUE_PAUSE_DATA_PHY_UPDATE = 0x02,
@ -240,7 +242,6 @@ struct proc_ctx {
uint8_t has_cte;
} cte_remote_rsp;
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_REQ */
#if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RSP)
/* Use by CTE Response Procedure */
struct llcp_df_cte_remote_req {
@ -248,7 +249,11 @@ struct proc_ctx {
uint8_t min_cte_len;
} cte_remote_req;
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RSP */
struct {
uint8_t cig_id;
uint8_t cis_id;
uint8_t error_code;
} cis_term;
} data;
struct {
@ -637,6 +642,9 @@ void llcp_pdu_decode_cte_req(struct proc_ctx *ctx, struct pdu_data *pdu);
void llcp_pdu_encode_cte_rsp(const struct proc_ctx *ctx, struct pdu_data *pdu);
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RSP */
void llcp_pdu_encode_cis_terminate_ind(struct proc_ctx *ctx, struct pdu_data *pdu);
void llcp_pdu_decode_cis_terminate_ind(struct proc_ctx *ctx, struct pdu_data *pdu);
#ifdef ZTEST_UNITTEST
bool lr_is_disconnected(struct ll_conn *conn);
bool lr_is_idle(struct ll_conn *conn);

View file

@ -25,9 +25,15 @@
#include "lll.h"
#include "lll/lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "ull_tx_queue.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_conn_iso_internal.h"
#include "ull_conn_types.h"
#include "ull_llcp.h"
#include "ull_llcp_internal.h"
@ -190,6 +196,9 @@ void llcp_lr_rx(struct ll_conn *conn, struct proc_ctx *ctx, struct node_rx_pdu *
llcp_lp_comm_rx(conn, ctx, rx);
break;
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_REQ */
case PROC_CIS_TERMINATE:
llcp_lp_comm_rx(conn, ctx, rx);
break;
default:
/* Unknown procedure */
LL_ASSERT(0);
@ -220,6 +229,9 @@ void llcp_lr_tx_ack(struct ll_conn *conn, struct proc_ctx *ctx, struct node_tx *
llcp_lp_pu_tx_ack(conn, ctx, tx);
break;
#endif /* CONFIG_BT_CTLR_PHY */
case PROC_CIS_TERMINATE:
llcp_lp_comm_tx_ack(conn, ctx, tx);
break;
default:
break;
/* Ignore tx_ack */
@ -284,6 +296,9 @@ static void lr_act_run(struct ll_conn *conn)
llcp_lp_comm_run(conn, ctx, NULL);
break;
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_REQ */
case PROC_CIS_TERMINATE:
llcp_lp_comm_run(conn, ctx, NULL);
break;
default:
/* Unknown procedure */
LL_ASSERT(0);

View file

@ -25,9 +25,15 @@
#include "lll.h"
#include "lll/lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "ull_tx_queue.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_conn_iso_internal.h"
#include "ull_conn_types.h"
#include "ull_llcp.h"
#include "ull_llcp_internal.h"
@ -828,3 +834,26 @@ void llcp_pdu_encode_cte_rsp(const struct proc_ctx *ctx, struct pdu_data *pdu)
pdu->cte_info.type = ctx->data.cte_remote_req.cte_type;
}
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RSP */
void llcp_pdu_encode_cis_terminate_ind(struct proc_ctx *ctx, struct pdu_data *pdu)
{
struct pdu_data_llctrl_cis_terminate_ind *p;
pdu->ll_id = PDU_DATA_LLID_CTRL;
pdu->len =
offsetof(struct pdu_data_llctrl, cis_terminate_ind) +
sizeof(struct pdu_data_llctrl_cis_terminate_ind);
pdu->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_CIS_TERMINATE_IND;
p = &pdu->llctrl.cis_terminate_ind;
p->cig_id = ctx->data.cis_term.cig_id;
p->cis_id = ctx->data.cis_term.cis_id;
p->error_code = ctx->data.cis_term.error_code;
}
void llcp_pdu_decode_cis_terminate_ind(struct proc_ctx *ctx, struct pdu_data *pdu)
{
ctx->data.cis_term.cig_id = pdu->llctrl.cis_terminate_ind.cig_id;
ctx->data.cis_term.cis_id = pdu->llctrl.cis_terminate_ind.cis_id;
ctx->data.cis_term.error_code = pdu->llctrl.cis_terminate_ind.error_code;
}

View file

@ -26,9 +26,15 @@
#include "ll_feat.h"
#include "lll/lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "ull_tx_queue.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_conn_iso_internal.h"
#include "ull_conn_types.h"
#include "ull_internal.h"
#include "ull_llcp.h"

View file

@ -26,9 +26,15 @@
#include "lll.h"
#include "lll/lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "ull_tx_queue.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_conn_iso_internal.h"
#include "ull_conn_types.h"
#include "ull_conn_internal.h"
#include "ull_llcp.h"
@ -86,6 +92,7 @@ static bool proc_with_instant(struct proc_ctx *ctx)
case PROC_TERMINATE:
case PROC_DATA_LENGTH_UPDATE:
case PROC_CTE_REQ:
case PROC_CIS_TERMINATE:
return 0U;
case PROC_PHY_UPDATE:
case PROC_CONN_UPDATE:
@ -260,6 +267,11 @@ void llcp_rr_rx(struct ll_conn *conn, struct proc_ctx *ctx, struct node_rx_pdu *
llcp_rp_comm_rx(conn, ctx, rx);
break;
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RSP */
#if defined(CONFIG_BT_CTLR_CENTRAL_ISO) || defined(CONFIG_BT_CTLR_PERIPHERAL_ISO)
case PROC_CIS_TERMINATE:
llcp_rp_comm_rx(conn, ctx, rx);
break;
#endif /* CONFIG_BT_CTLR_CENTRAL_ISO || CONFIG_BT_CTLR_PERIPHERAL_ISO */
default:
/* Unknown procedure */
LL_ASSERT(0);
@ -350,6 +362,11 @@ static void rr_act_run(struct ll_conn *conn)
llcp_rp_comm_run(conn, ctx, NULL);
break;
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RSP */
#if defined(CONFIG_BT_CTLR_CENTRAL_ISO) || defined(CONFIG_BT_CTLR_PERIPHERAL_ISO)
case PROC_CIS_TERMINATE:
llcp_rp_comm_run(conn, ctx, NULL);
break;
#endif /* CONFIG_BT_CTLR_CENTRAL_ISO || CONFIG_BT_CTLR_PERIPHERAL_ISO */
default:
/* Unknown procedure */
LL_ASSERT(0);
@ -776,6 +793,9 @@ static const struct proc_role new_proc_lut[] = {
[PDU_DATA_LLCTRL_TYPE_CTE_REQ] = { PROC_CTE_REQ, ACCEPT_ROLE_BOTH },
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RSP */
[PDU_DATA_LLCTRL_TYPE_CTE_RSP] = { PROC_UNKNOWN, ACCEPT_ROLE_NONE },
#if defined(CONFIG_BT_CTLR_CENTRAL_ISO) || defined(CONFIG_BT_CTLR_PERIPHERAL_ISO)
[PDU_DATA_LLCTRL_TYPE_CIS_TERMINATE_IND] = { PROC_CIS_TERMINATE, ACCEPT_ROLE_BOTH },
#endif /* CONFIG_BT_CTLR_CENTRAL_ISO || CONFIG_BT_CTLR_PERIPHERAL_ISO */
};
void llcp_rr_new(struct ll_conn *conn, struct node_rx_pdu *rx, bool valid_pdu)
@ -786,7 +806,6 @@ void llcp_rr_new(struct ll_conn *conn, struct node_rx_pdu *rx, bool valid_pdu)
pdu = (struct pdu_data *)rx->pdu;
/* Is this a valid opcode */
if (valid_pdu && pdu->llctrl.opcode < ARRAY_SIZE(new_proc_lut)) {
/* Lookup procedure */

View file

@ -35,6 +35,7 @@
#include "lll_conn.h"
#include "lll_peripheral.h"
#include "lll_filter.h"
#include "lll_conn_iso.h"
#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY)
#include "ull_tx_queue.h"
@ -52,7 +53,11 @@
#include "ll.h"
#if (!defined(CONFIG_BT_LL_SW_LLCP_LEGACY))
#include "ll_sw/ull_llcp.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_llcp.h"
#endif
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)

View file

@ -53,6 +53,7 @@ void helper_pdu_encode_cte_rsp(struct pdu_data *pdu, void *param);
void helper_node_encode_cte_rsp(struct node_rx_pdu *rx, void *param);
void helper_pdu_encode_zero(struct pdu_data *pdu, void *param);
void helper_pdu_encode_cis_terminate_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_rsp(const char *file, uint32_t line, struct pdu_data *pdu, void *param);
@ -134,6 +135,9 @@ void helper_node_verify_cte_rsp(const char *file, uint32_t line, struct node_rx_
void helper_pdu_ntf_verify_cte_rsp(const char *file, uint32_t line, struct pdu_data *pdu,
void *param);
void helper_pdu_verify_cis_terminate_ind(const char *file, uint32_t line, struct pdu_data *pdu,
void *param);
enum helper_pdu_opcode {
LL_VERSION_IND,
LL_LE_PING_REQ,
@ -163,6 +167,7 @@ enum helper_pdu_opcode {
LL_LENGTH_RSP,
LL_CTE_REQ,
LL_CTE_RSP,
LL_CIS_TERMINATE_IND,
LL_ZERO,
};

View file

@ -27,9 +27,14 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn_iso.h"
#include "lll_conn.h"
#include "ull_tx_queue.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_types.h"
#include "ull_conn_iso_types.h"
#include "ull_llcp.h"
@ -402,6 +407,19 @@ void helper_node_encode_cte_rsp(struct node_rx_pdu *rx, void *param)
rx->hdr.rx_ftr.iq_report = (struct cte_conn_iq_report *)param;
}
void helper_pdu_encode_cis_terminate_ind(struct pdu_data *pdu, void *param)
{
struct pdu_data_llctrl_cis_terminate_ind *p = param;
pdu->ll_id = PDU_DATA_LLID_CTRL;
pdu->len = offsetof(struct pdu_data_llctrl, cis_terminate_ind) +
sizeof(struct pdu_data_llctrl_cis_terminate_ind);
pdu->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_CIS_TERMINATE_IND;
pdu->llctrl.cis_terminate_ind.cig_id = p->cig_id;
pdu->llctrl.cis_terminate_ind.cis_id = p->cis_id;
pdu->llctrl.cis_terminate_ind.error_code = p->error_code;
}
void helper_pdu_verify_version_ind(const char *file, uint32_t line, struct pdu_data *pdu,
void *param)
{
@ -964,3 +982,24 @@ void helper_pdu_ntf_verify_cte_rsp(const char *file, uint32_t line, struct pdu_d
zassert_equal(pdu->llctrl.opcode, PDU_DATA_LLCTRL_TYPE_CTE_RSP,
"Not a LL_CTE_RSP. Called at %s:%d\n", file, line);
}
void helper_pdu_verify_cis_terminate_ind(const char *file, uint32_t line, struct pdu_data *pdu,
void *param)
{
struct pdu_data_llctrl_cis_terminate_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->len,
offsetof(struct pdu_data_llctrl, cis_terminate_ind) +
sizeof(struct pdu_data_llctrl_cis_terminate_ind),
"Wrong length.\nCalled at %s:%d\n", file, line);
zassert_equal(pdu->llctrl.opcode, PDU_DATA_LLCTRL_TYPE_CIS_TERMINATE_IND,
"Not a LL_CIS_TERMINATE_IND.\nCalled at %s:%d\n", file, line);
zassert_equal(pdu->llctrl.cis_terminate_ind.cig_id, p->cig_id,
"CIG ID mismatch.\nCalled at %s:%d\n", file, line);
zassert_equal(pdu->llctrl.cis_terminate_ind.cis_id, p->cis_id,
"CIS ID mismatch.\nCalled at %s:%d\n", file, line);
zassert_equal(pdu->llctrl.cis_terminate_ind.error_code, p->error_code,
"Error code mismatch.\nCalled at %s:%d\n", file, line);
}

View file

@ -28,7 +28,14 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "ull_tx_queue.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_conn_iso_internal.h"
#include "ull_conn_types.h"
#include "ull_conn_internal.h"
@ -80,6 +87,7 @@ helper_pdu_encode_func_t *const helper_pdu_encode[] = {
[LL_LENGTH_RSP] = helper_pdu_encode_length_rsp,
[LL_CTE_REQ] = helper_pdu_encode_cte_req,
[LL_CTE_RSP] = helper_pdu_encode_cte_rsp,
[LL_CIS_TERMINATE_IND] = helper_pdu_encode_cis_terminate_ind,
[LL_ZERO] = helper_pdu_encode_zero,
};
@ -112,6 +120,7 @@ helper_pdu_verify_func_t *const helper_pdu_verify[] = {
[LL_LENGTH_RSP] = helper_pdu_verify_length_rsp,
[LL_CTE_REQ] = helper_pdu_verify_cte_req,
[LL_CTE_RSP] = helper_pdu_verify_cte_rsp,
[LL_CIS_TERMINATE_IND] = helper_pdu_verify_cis_terminate_ind,
};
helper_pdu_ntf_verify_func_t *const helper_pdu_ntf_verify[] = {
@ -141,6 +150,8 @@ helper_pdu_ntf_verify_func_t *const helper_pdu_ntf_verify[] = {
[LL_LENGTH_RSP] = NULL,
[LL_CTE_REQ] = NULL,
[LL_CTE_RSP] = helper_pdu_ntf_verify_cte_rsp,
[LL_CTE_RSP] = NULL,
[LL_CIS_TERMINATE_IND] = NULL,
};
helper_node_encode_func_t *const helper_node_encode[] = {
@ -168,6 +179,7 @@ helper_node_encode_func_t *const helper_node_encode[] = {
[LL_CHAN_MAP_UPDATE_IND] = NULL,
[LL_CTE_REQ] = NULL,
[LL_CTE_RSP] = helper_node_encode_cte_rsp,
[LL_CIS_TERMINATE_IND] = NULL,
};
helper_node_verify_func_t *const helper_node_verify[] = {

View file

@ -27,8 +27,13 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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"

View file

@ -28,8 +28,13 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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_conn_internal.h"

View file

@ -0,0 +1,16 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.13.1)
if (NOT BOARD STREQUAL unit_testing)
message(FATAL_ERROR "This project can only be used with '-DBOARD=unit_testing'.")
endif()
FILE(GLOB SOURCES
src/*.c
)
project(bluetooth_ull_llcp_cis_terminate)
find_package(ZephyrUnittest HINTS $ENV{ZEPHYR_BASE})
include(${ZEPHYR_BASE}/tests/bluetooth/controller/common/defaults_cmake.txt)
target_sources(testbinary PRIVATE ${ll_sw_sources} ${mock_sources} ${common_sources})

View file

@ -0,0 +1,159 @@
/*
* Copyright (c) 2022 Demant
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#include <ztest.h>
#include "kconfig.h"
#include <bluetooth/hci.h>
#include <sys/byteorder.h>
#include <sys/slist.h>
#include <sys/util.h>
#include "hal/ccm.h"
#include "util/util.h"
#include "util/mem.h"
#include "util/memq.h"
#include "util/dbuf.h"
#include "pdu.h"
#include "ll.h"
#include "ll_settings.h"
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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_conn_internal.h"
#include "ull_llcp_internal.h"
#include "helper_pdu.h"
#include "helper_util.h"
struct ll_conn conn;
static void setup(void)
{
test_setup(&conn);
}
static void test_cis_terminate_rem(uint8_t role)
{
struct pdu_data_llctrl_cis_terminate_ind remote_cis_terminate_ind;
/* Role */
test_set_role(&conn, role);
/* Connect */
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
/* Prepare */
event_prepare(&conn);
/* Rx */
lt_tx(LL_CIS_TERMINATE_IND, &conn, &remote_cis_terminate_ind);
/* Done */
event_done(&conn);
/* There should be no host notification */
ut_rx_q_is_empty();
zassert_equal(ctx_buffers_free(), test_ctx_buffers_cnt(),
"Free CTX buffers %d", ctx_buffers_free());
}
void test_cis_terminate_cen_rem(void)
{
test_cis_terminate_rem(BT_HCI_ROLE_CENTRAL);
}
void test_cis_terminate_per_rem(void)
{
test_cis_terminate_rem(BT_HCI_ROLE_PERIPHERAL);
}
void test_cis_terminate_loc(uint8_t role)
{
uint8_t err;
struct node_tx *tx;
struct ll_conn_iso_stream cis = { 0 };
struct ll_conn_iso_group group = { 0 };
struct pdu_data_llctrl_cis_terminate_ind local_cis_terminate_ind = {
.cig_id = 0x03,
.cis_id = 0x04,
.error_code = 0x06,
};
/* Role */
test_set_role(&conn, role);
/* Connect */
ull_cp_state_set(&conn, ULL_CP_CONNECTED);
/* Mock CIS/ACL */
cis.lll.acl_handle = conn.lll.handle;
group.cig_id = local_cis_terminate_ind.cig_id;
cis.cis_id = local_cis_terminate_ind.cis_id;
cis.group = &group;
/* Initiate an CIS Terminate Procedure */
err = ull_cp_cis_terminate(&conn, &cis, local_cis_terminate_ind.error_code);
zassert_equal(err, BT_HCI_ERR_SUCCESS, NULL);
/* Prepare */
event_prepare(&conn);
/* Tx Queue should have one LL Control PDU */
lt_rx(LL_CIS_TERMINATE_IND, &conn, &tx, &local_cis_terminate_ind);
lt_rx_q_is_empty(&conn);
/* RX Ack */
event_tx_ack(&conn, tx);
/* Done */
event_done(&conn);
/* Release tx node */
ull_cp_release_tx(&conn, tx);
/* There should be no host notification */
ut_rx_q_is_empty();
zassert_equal(ctx_buffers_free(), test_ctx_buffers_cnt(),
"Free CTX buffers %d", ctx_buffers_free());
}
void test_cis_terminate_cen_loc(void)
{
test_cis_terminate_loc(BT_HCI_ROLE_CENTRAL);
}
void test_cis_terminate_per_loc(void)
{
test_cis_terminate_loc(BT_HCI_ROLE_PERIPHERAL);
}
void test_main(void)
{
ztest_test_suite(
cis_term,
ztest_unit_test_setup_teardown(test_cis_terminate_cen_rem, setup, unit_test_noop),
ztest_unit_test_setup_teardown(test_cis_terminate_per_rem, setup, unit_test_noop),
ztest_unit_test_setup_teardown(test_cis_terminate_cen_loc, setup, unit_test_noop),
ztest_unit_test_setup_teardown(test_cis_terminate_per_loc, setup, unit_test_noop));
ztest_run_test_suite(cis_term);
}

View file

@ -0,0 +1,5 @@
common:
tags: test_framework bluetooth bt_cis_terminate bt_ull_llcp
tests:
bluetooth.controller.ctrl_cis_terminate.test:
type: unit

View file

@ -28,9 +28,13 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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_conn_internal.h"

View file

@ -27,8 +27,13 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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_conn_internal.h"

View file

@ -27,8 +27,13 @@
#include "ll_feat.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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_conn_internal.h"

View file

@ -29,8 +29,13 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "ull_tx_queue.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_internal.h"
#include "ull_conn_types.h"
#include "ull_llcp.h"

View file

@ -29,9 +29,14 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "ull_tx_queue.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_internal.h"
#include "ull_conn_types.h"
#include "ull_llcp.h"

View file

@ -29,9 +29,13 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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_internal.h"

View file

@ -29,7 +29,13 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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"

View file

@ -26,10 +26,15 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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_conn_internal.h"
#include "ull_llcp_internal.h"
#include "helper_pdu.h"

View file

@ -26,8 +26,13 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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_conn_internal.h"

View file

@ -26,8 +26,13 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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_conn_internal.h"

View file

@ -28,9 +28,14 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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_conn_internal.h"

View file

@ -27,9 +27,14 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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_conn_internal.h"

View file

@ -28,9 +28,14 @@
#include "lll.h"
#include "lll/lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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_conn_internal.h"

View file

@ -26,8 +26,13 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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"

View file

@ -27,8 +27,14 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.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"

View file

@ -29,8 +29,13 @@
#include "lll.h"
#include "lll_df_types.h"
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "ull_tx_queue.h"
#include "ull_conn_types.h"
#include "isoal.h"
#include "ull_iso_types.h"
#include "ull_conn_iso_types.h"
#include "ull_llcp.h"