tests: Bluetooth: Test invalid LLCP opcodes
Test the rejection (LL_UNKNOWN_RSP) of invalid remotely initiated procedures in both the central and peripheral role. Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
This commit is contained in:
parent
0b0a90ae84
commit
250075d3dd
6 changed files with 305 additions and 2 deletions
|
|
@ -15,6 +15,8 @@ void event_done(struct ll_conn *conn);
|
|||
uint16_t event_counter(struct ll_conn *conn);
|
||||
|
||||
#define lt_tx(_opcode, _conn, _param) lt_tx_real(__FILE__, __LINE__, _opcode, _conn, _param)
|
||||
#define lt_tx_no_encode(_pdu, _conn, _param) \
|
||||
lt_tx_real_no_encode(__FILE__, __LINE__, _pdu, _conn, _param)
|
||||
#define lt_rx(_opcode, _conn, _tx_ref, _param) \
|
||||
lt_rx_real(__FILE__, __LINE__, _opcode, _conn, _tx_ref, _param)
|
||||
#define lt_rx_q_is_empty(_conn) lt_rx_q_is_empty_real(__FILE__, __LINE__, _conn)
|
||||
|
|
@ -27,6 +29,8 @@ uint16_t event_counter(struct ll_conn *conn);
|
|||
|
||||
void lt_tx_real(const char *file, uint32_t line, enum helper_pdu_opcode opcode,
|
||||
struct ll_conn *conn, void *param);
|
||||
void lt_tx_real_no_encode(const char *file, uint32_t line, struct pdu_data *pdu,
|
||||
struct ll_conn *conn, void *param);
|
||||
void lt_rx_real(const char *file, uint32_t line, enum helper_pdu_opcode opcode,
|
||||
struct ll_conn *conn, struct node_tx **tx_ref, void *param);
|
||||
void lt_rx_q_is_empty_real(const char *file, uint32_t line, struct ll_conn *conn);
|
||||
|
|
@ -35,3 +39,5 @@ void ut_rx_pdu_real(const char *file, uint32_t line, enum helper_pdu_opcode opco
|
|||
void ut_rx_node_real(const char *file, uint32_t line, enum helper_node_opcode opcode,
|
||||
struct node_rx_pdu **ntf_ref, void *param);
|
||||
void ut_rx_q_is_empty_real(const char *file, uint32_t line);
|
||||
|
||||
void encode_pdu(enum helper_pdu_opcode opcode, struct pdu_data *pdu, void *param);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include "zephyr/types.h"
|
||||
#include "ztest.h"
|
||||
#include "kconfig.h"
|
||||
|
||||
#include <bluetooth/hci.h>
|
||||
#include <sys/byteorder.h>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#include "zephyr/types.h"
|
||||
#include "ztest.h"
|
||||
#include <stdlib.h>
|
||||
#include "kconfig.h"
|
||||
|
||||
#include <bluetooth/hci.h>
|
||||
#include <sys/slist.h>
|
||||
|
|
@ -323,6 +322,17 @@ void lt_tx_real(const char *file, uint32_t line, enum helper_pdu_opcode opcode,
|
|||
sys_slist_append(<_tx_q, (sys_snode_t *)rx);
|
||||
}
|
||||
|
||||
void lt_tx_real_no_encode(const char *file, uint32_t line, struct pdu_data *pdu,
|
||||
struct ll_conn *conn, void *param)
|
||||
{
|
||||
struct node_rx_pdu *rx;
|
||||
|
||||
rx = malloc(PDU_RX_NODE_SIZE);
|
||||
zassert_not_null(rx, "Out of memory.\nCalled at %s:%d\n", file, line);
|
||||
memcpy((struct pdu_data *)rx->pdu, pdu, sizeof(struct pdu_data));
|
||||
sys_slist_append(<_tx_q, (sys_snode_t *)rx);
|
||||
}
|
||||
|
||||
void lt_rx_real(const char *file, uint32_t line, enum helper_pdu_opcode opcode,
|
||||
struct ll_conn *conn, struct node_tx **tx_ref, void *param)
|
||||
{
|
||||
|
|
@ -396,3 +406,9 @@ void ut_rx_q_is_empty_real(const char *file, uint32_t line)
|
|||
ntf = (struct node_rx_pdu *)sys_slist_get(&ut_rx_q);
|
||||
zassert_is_null(ntf, "Ntf Q not empty.\nCalled at %s:%d\n", file, line);
|
||||
}
|
||||
|
||||
void encode_pdu(enum helper_pdu_opcode opcode, struct pdu_data *pdu, void *param)
|
||||
{
|
||||
zassert_not_null(helper_pdu_encode[opcode], "PDU encode function cannot be NULL\n");
|
||||
helper_pdu_encode[opcode](pdu, param);
|
||||
}
|
||||
|
|
|
|||
17
tests/bluetooth/controller/ctrl_unsupported/CMakeLists.txt
Normal file
17
tests/bluetooth/controller/ctrl_unsupported/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
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_unsupported)
|
||||
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})
|
||||
260
tests/bluetooth/controller/ctrl_unsupported/src/main.c
Normal file
260
tests/bluetooth/controller/ctrl_unsupported/src/main.c
Normal file
|
|
@ -0,0 +1,260 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Demant
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/types.h>
|
||||
#include <ztest.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 "ll_feat.h"
|
||||
|
||||
#include "lll.h"
|
||||
#include "lll_df_types.h"
|
||||
#include "lll_conn.h"
|
||||
#include "ull_tx_queue.h"
|
||||
|
||||
#include "ull_conn_types.h"
|
||||
#include "ull_llcp.h"
|
||||
#include "ull_llcp_internal.h"
|
||||
|
||||
#include "helper_pdu.h"
|
||||
#include "helper_util.h"
|
||||
|
||||
struct ll_conn test_conn;
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
test_setup(&test_conn);
|
||||
}
|
||||
|
||||
#define LLCTRL_PDU_SIZE (offsetof(struct pdu_data, llctrl) + sizeof(struct pdu_data_llctrl))
|
||||
|
||||
/* +-----+ +-------+ +-----+
|
||||
* | UT | | LL_A | | LT |
|
||||
* +-----+ +-------+ +-----+
|
||||
* | | |
|
||||
* | | <PDU> |
|
||||
* | |<------------------|
|
||||
* | | |
|
||||
* | | LL_UNKNOWN_RSP |
|
||||
* | |------------------>|
|
||||
* | | |
|
||||
*/
|
||||
static void lt_tx_pdu_and_rx_unknown_rsp(enum helper_pdu_opcode opcode)
|
||||
{
|
||||
struct node_tx *tx;
|
||||
struct pdu_data pdu;
|
||||
/* PDU contents does not matter when testing for invalid PDU opcodes */
|
||||
uint8_t data[LLCTRL_PDU_SIZE] = { 0 };
|
||||
|
||||
/* Encode a PDU for the opcode */
|
||||
encode_pdu(opcode, &pdu, &data);
|
||||
|
||||
/* Setup the LL_UNKNOWN_RSP expected for the PDU */
|
||||
struct pdu_data_llctrl_unknown_rsp unknown_rsp = {
|
||||
.type = pdu.llctrl.opcode
|
||||
};
|
||||
|
||||
/* Connect */
|
||||
ull_cp_state_set(&test_conn, ULL_CP_CONNECTED);
|
||||
|
||||
/* Prepare */
|
||||
event_prepare(&test_conn);
|
||||
|
||||
/* Rx */
|
||||
lt_tx(opcode, &test_conn, &pdu.llctrl.unknown_rsp);
|
||||
|
||||
/* Done */
|
||||
event_done(&test_conn);
|
||||
|
||||
/* Prepare */
|
||||
event_prepare(&test_conn);
|
||||
|
||||
/* Tx Queue should have one LL Control PDU */
|
||||
lt_rx(LL_UNKNOWN_RSP, &test_conn, &tx, &unknown_rsp);
|
||||
lt_rx_q_is_empty(&test_conn);
|
||||
|
||||
/* Done */
|
||||
event_done(&test_conn);
|
||||
|
||||
/* Release Tx */
|
||||
ull_cp_release_tx(&test_conn, tx);
|
||||
|
||||
/* There should not be a host notifications */
|
||||
ut_rx_q_is_empty();
|
||||
|
||||
zassert_equal(ctx_buffers_free(), CONFIG_BT_CTLR_LLCP_PROC_CTX_BUF_NUM,
|
||||
"Free CTX buffers %d", ctx_buffers_free());
|
||||
}
|
||||
|
||||
static void lt_tx_undef_opcode_and_rx_unknown_rsp(uint8_t opcode)
|
||||
{
|
||||
struct node_tx *tx;
|
||||
struct pdu_data pdu;
|
||||
/* PDU contents does not matter when testing for invalid PDU opcodes */
|
||||
uint8_t data[LLCTRL_PDU_SIZE] = { 0 };
|
||||
|
||||
/* Undefined opcodes cannot be encoded, so encode a LL_UNKNOWN_RSP as
|
||||
* a placeholder and override the opcode
|
||||
*/
|
||||
encode_pdu(LL_UNKNOWN_RSP, &pdu, &data);
|
||||
pdu.llctrl.opcode = opcode;
|
||||
|
||||
/* Setup the LL_UNKNOWN_RSP expected for the PDU */
|
||||
struct pdu_data_llctrl_unknown_rsp unknown_rsp = {
|
||||
.type = pdu.llctrl.opcode
|
||||
};
|
||||
|
||||
/* Connect */
|
||||
ull_cp_state_set(&test_conn, ULL_CP_CONNECTED);
|
||||
|
||||
/* Prepare */
|
||||
event_prepare(&test_conn);
|
||||
|
||||
/* Rx */
|
||||
lt_tx_no_encode(&pdu, &test_conn, &pdu.llctrl.unknown_rsp);
|
||||
|
||||
/* Done */
|
||||
event_done(&test_conn);
|
||||
|
||||
/* Prepare */
|
||||
event_prepare(&test_conn);
|
||||
|
||||
/* Tx Queue should have one LL Control PDU */
|
||||
lt_rx(LL_UNKNOWN_RSP, &test_conn, &tx, &unknown_rsp);
|
||||
lt_rx_q_is_empty(&test_conn);
|
||||
|
||||
/* Done */
|
||||
event_done(&test_conn);
|
||||
|
||||
/* Release Tx */
|
||||
ull_cp_release_tx(&test_conn, tx);
|
||||
|
||||
/* There should not be a host notifications */
|
||||
ut_rx_q_is_empty();
|
||||
|
||||
zassert_equal(ctx_buffers_free(), CONFIG_BT_CTLR_LLCP_PROC_CTX_BUF_NUM,
|
||||
"Free CTX buffers %d", ctx_buffers_free());
|
||||
}
|
||||
|
||||
void test_invalid_per_rem(void)
|
||||
{
|
||||
/* Role */
|
||||
test_set_role(&test_conn, BT_HCI_ROLE_PERIPHERAL);
|
||||
|
||||
/* Test opcodes that cannot initiate a remote procedure */
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_ENC_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_START_ENC_REQ);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_START_ENC_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_UNKNOWN_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_FEATURE_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_PAUSE_ENC_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_REJECT_IND);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_CONNECTION_PARAM_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_REJECT_EXT_IND);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_LE_PING_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_LENGTH_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_PHY_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_PHY_UPDATE_IND);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_CTE_RSP);
|
||||
|
||||
/* Test opcodes that can initiate a remote procedure but use the wrong
|
||||
* role
|
||||
*/
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_PERIPH_FEAT_XCHG);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_MIN_USED_CHANS_IND);
|
||||
}
|
||||
|
||||
void test_invalid_cen_rem(void)
|
||||
{
|
||||
/* Role */
|
||||
test_set_role(&test_conn, BT_HCI_ROLE_CENTRAL);
|
||||
|
||||
/* Test opcodes that cannot initiate a remote procedure */
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_ENC_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_START_ENC_REQ);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_START_ENC_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_UNKNOWN_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_FEATURE_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_PAUSE_ENC_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_REJECT_IND);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_CONNECTION_PARAM_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_REJECT_EXT_IND);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_LE_PING_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_LENGTH_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_PHY_RSP);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_PHY_UPDATE_IND);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_CTE_RSP);
|
||||
|
||||
/* Test opcodes that can initiate a remote procedure but use the wrong
|
||||
* role
|
||||
*/
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_CONNECTION_UPDATE_IND);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_CHAN_MAP_UPDATE_IND);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_ENC_REQ);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_FEATURE_REQ);
|
||||
lt_tx_pdu_and_rx_unknown_rsp(LL_PAUSE_ENC_REQ);
|
||||
}
|
||||
|
||||
void test_undefined_per_rem(void)
|
||||
{
|
||||
/* Role */
|
||||
test_set_role(&test_conn, BT_HCI_ROLE_PERIPHERAL);
|
||||
|
||||
/* Test undefined opcodes that cannot initiate a remote procedure */
|
||||
|
||||
/* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 6, Part B, Table 2.18:
|
||||
* LL Control PDU opcodes
|
||||
*/
|
||||
for (uint16_t opcode = 0x30; opcode < 0x100; opcode++) {
|
||||
lt_tx_undef_opcode_and_rx_unknown_rsp(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
void test_undefined_cen_rem(void)
|
||||
{
|
||||
/* Role */
|
||||
test_set_role(&test_conn, BT_HCI_ROLE_CENTRAL);
|
||||
|
||||
/* Test undefined opcodes that cannot initiate a remote procedure */
|
||||
|
||||
/* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 6, Part B, Table 2.18:
|
||||
* LL Control PDU opcodes
|
||||
*/
|
||||
for (uint16_t opcode = 0x30; opcode < 0x100; opcode++) {
|
||||
lt_tx_undef_opcode_and_rx_unknown_rsp(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(invalid,
|
||||
ztest_unit_test_setup_teardown(test_invalid_per_rem, setup,
|
||||
unit_test_noop),
|
||||
ztest_unit_test_setup_teardown(test_invalid_cen_rem, setup,
|
||||
unit_test_noop));
|
||||
|
||||
ztest_test_suite(undefined,
|
||||
ztest_unit_test_setup_teardown(test_undefined_per_rem, setup,
|
||||
unit_test_noop),
|
||||
ztest_unit_test_setup_teardown(test_undefined_cen_rem, setup,
|
||||
unit_test_noop));
|
||||
|
||||
ztest_run_test_suite(invalid);
|
||||
ztest_run_test_suite(undefined);
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
common:
|
||||
tags: test_framework bluetooth bt_unsupported bt_ull_llcp
|
||||
tests:
|
||||
bluetooth.controller.ctrl_unsupported.default.test:
|
||||
type: unit
|
||||
Loading…
Reference in a new issue