From 65ba758fd983a3dccc9e381cefd73466444161ba Mon Sep 17 00:00:00 2001 From: Piotr Narajowski Date: Thu, 2 Apr 2026 16:00:26 +0200 Subject: [PATCH 1/2] apps/bttester: add btp command to configure security mode and level This adds command to configure security mode and level. For now, this can't be done dynamically, we can just check if our settings comply with provided mode and level. This is needed for various GAP/SEC/SEM qualification test cases. --- apps/bttester/src/btp/btp_gap.h | 7 +++++++ apps/bttester/src/btp_gap.c | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/apps/bttester/src/btp/btp_gap.h b/apps/bttester/src/btp/btp_gap.h index c95a0d219f..0e7650582e 100644 --- a/apps/bttester/src/btp/btp_gap.h +++ b/apps/bttester/src/btp/btp_gap.h @@ -339,6 +339,13 @@ struct gap_subrate_request_cmd { uint16_t supervision_timeout; } __packed; +#define GAP_CONFIGURE_SECURITY_MODE 0x35 +struct gap_configure_security_mode_cmd { + uint8_t mode; + uint8_t level; + uint8_t flags; +} __packed; + /* events */ #define BTP_GAP_EV_NEW_SETTINGS 0x80 struct btp_gap_new_settings_ev { diff --git a/apps/bttester/src/btp_gap.c b/apps/bttester/src/btp_gap.c index 29fb50a103..6f914c5f22 100644 --- a/apps/bttester/src/btp_gap.c +++ b/apps/bttester/src/btp_gap.c @@ -2270,6 +2270,38 @@ subrate_request(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) } #endif +static uint8_t +configure_security_mode(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) +{ + const struct gap_configure_security_mode_cmd *cp = cmd; + + switch (cp->mode) { + case 1: + if (cp->level != MYNEWT_VAL(BLE_SM_LVL)) { + return BTP_STATUS_FAILED; + } + if (cp->flags & BIT(0)) { + /* TODO: LE SC Only bit is set. */ + } + break; + + case 2: + /* Data signing is not supported */ + return BTP_STATUS_FAILED; + + case 3: + if (cp->level != 1) { + /* Broadcast code encryption (lvl 2,3) is not supported */ + return BTP_STATUS_FAILED; + } + break; + } + + SYS_LOG_DBG(""); + + return BTP_STATUS_SUCCESS; +} + static const struct btp_handler handlers[] = { { .opcode = BTP_GAP_READ_SUPPORTED_COMMANDS, @@ -2447,6 +2479,11 @@ static const struct btp_handler handlers[] = { .func = subrate_request, }, #endif + { + .opcode = GAP_CONFIGURE_SECURITY_MODE, + .expect_len = sizeof(struct gap_configure_security_mode_cmd), + .func = configure_security_mode, + }, }; static void From 92d02d8b3270b000f0df8b517176fc998b5eaa75 Mon Sep 17 00:00:00 2001 From: Piotr Narajowski Date: Tue, 7 Apr 2026 14:49:25 +0200 Subject: [PATCH 2/2] apps/bttester: fix coding style Fix code formatting issues in btp handlers. --- apps/bttester/src/btp_gap.c | 269 ++++++++++++++++++------------------ 1 file changed, 134 insertions(+), 135 deletions(-) diff --git a/apps/bttester/src/btp_gap.c b/apps/bttester/src/btp_gap.c index 6f914c5f22..ae05b0afe4 100644 --- a/apps/bttester/src/btp_gap.c +++ b/apps/bttester/src/btp_gap.c @@ -2304,180 +2304,179 @@ configure_security_mode(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t * static const struct btp_handler handlers[] = { { - .opcode = BTP_GAP_READ_SUPPORTED_COMMANDS, - .index = BTP_INDEX_NONE, - .expect_len = 0, - .func = supported_commands, - }, + .opcode = BTP_GAP_READ_SUPPORTED_COMMANDS, + .index = BTP_INDEX_NONE, + .expect_len = 0, + .func = supported_commands, + }, { - .opcode = BTP_GAP_READ_CONTROLLER_INDEX_LIST, - .index = BTP_INDEX_NONE, - .expect_len = 0, - .func = controller_index_list, - }, + .opcode = BTP_GAP_READ_CONTROLLER_INDEX_LIST, + .index = BTP_INDEX_NONE, + .expect_len = 0, + .func = controller_index_list, + }, { - .opcode = BTP_GAP_READ_CONTROLLER_INFO, - .expect_len = 0, - .func = controller_info, - }, + .opcode = BTP_GAP_READ_CONTROLLER_INFO, + .expect_len = 0, + .func = controller_info, + }, { - .opcode = BTP_GAP_SET_CONNECTABLE, - .expect_len = sizeof(struct btp_gap_set_connectable_cmd), - .func = set_connectable, - }, + .opcode = BTP_GAP_SET_CONNECTABLE, + .expect_len = sizeof(struct btp_gap_set_connectable_cmd), + .func = set_connectable, + }, { - .opcode = BTP_GAP_SET_DISCOVERABLE, - .expect_len = sizeof(struct btp_gap_set_discoverable_cmd), - .func = set_discoverable, - }, + .opcode = BTP_GAP_SET_DISCOVERABLE, + .expect_len = sizeof(struct btp_gap_set_discoverable_cmd), + .func = set_discoverable, + }, { - .opcode = BTP_GAP_SET_BONDABLE, - .expect_len = sizeof(struct btp_gap_set_bondable_cmd), - .func = set_bondable, - }, + .opcode = BTP_GAP_SET_BONDABLE, + .expect_len = sizeof(struct btp_gap_set_bondable_cmd), + .func = set_bondable, + }, { - .opcode = BTP_GAP_START_ADVERTISING, - .expect_len = BTP_HANDLER_LENGTH_VARIABLE, - .func = start_advertising, - }, + .opcode = BTP_GAP_START_ADVERTISING, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, + .func = start_advertising, + }, { - .opcode = BTP_GAP_START_DIRECT_ADV, - .expect_len = sizeof(struct btp_gap_start_direct_adv_cmd), - .func = start_direct_adv, - }, + .opcode = BTP_GAP_START_DIRECT_ADV, + .expect_len = sizeof(struct btp_gap_start_direct_adv_cmd), + .func = start_direct_adv, + }, { - .opcode = BTP_GAP_STOP_ADVERTISING, - .expect_len = 0, - .func = stop_advertising, - }, + .opcode = BTP_GAP_STOP_ADVERTISING, + .expect_len = 0, + .func = stop_advertising, + }, { - .opcode = BTP_GAP_START_DISCOVERY, - .expect_len = sizeof(struct btp_gap_start_discovery_cmd), - .func = start_discovery, - }, + .opcode = BTP_GAP_START_DISCOVERY, + .expect_len = sizeof(struct btp_gap_start_discovery_cmd), + .func = start_discovery, + }, { - .opcode = BTP_GAP_STOP_DISCOVERY, - .expect_len = 0, - .func = stop_discovery, - }, + .opcode = BTP_GAP_STOP_DISCOVERY, + .expect_len = 0, + .func = stop_discovery, + }, { - .opcode = BTP_GAP_CONNECT, - .expect_len = sizeof(struct btp_gap_connect_cmd), - .func = connect, - }, + .opcode = BTP_GAP_CONNECT, + .expect_len = sizeof(struct btp_gap_connect_cmd), + .func = connect, + }, { - .opcode = BTP_GAP_DISCONNECT, - .expect_len = sizeof(struct btp_gap_disconnect_cmd), - .func = disconnect, - }, + .opcode = BTP_GAP_DISCONNECT, + .expect_len = sizeof(struct btp_gap_disconnect_cmd), + .func = disconnect, + }, { - .opcode = BTP_GAP_SET_IO_CAP, - .expect_len = sizeof(struct btp_gap_set_io_cap_cmd), - .func = set_io_cap, - }, + .opcode = BTP_GAP_SET_IO_CAP, + .expect_len = sizeof(struct btp_gap_set_io_cap_cmd), + .func = set_io_cap, + }, { - .opcode = BTP_GAP_PAIR, - .expect_len = sizeof(struct btp_gap_pair_cmd), - .func = pair, - }, + .opcode = BTP_GAP_PAIR, + .expect_len = sizeof(struct btp_gap_pair_cmd), + .func = pair, + }, { - .opcode = BTP_GAP_UNPAIR, - .expect_len = sizeof(struct btp_gap_unpair_cmd), - .func = unpair, - }, + .opcode = BTP_GAP_UNPAIR, + .expect_len = sizeof(struct btp_gap_unpair_cmd), + .func = unpair, + }, { - .opcode = BTP_GAP_PASSKEY_ENTRY, - .expect_len = sizeof(struct btp_gap_passkey_entry_cmd), - .func = passkey_entry, - }, + .opcode = BTP_GAP_PASSKEY_ENTRY, + .expect_len = sizeof(struct btp_gap_passkey_entry_cmd), + .func = passkey_entry, + }, { - .opcode = BTP_GAP_PASSKEY_CONFIRM, - .expect_len = sizeof(struct btp_gap_passkey_confirm_cmd), - .func = passkey_confirm, - }, + .opcode = BTP_GAP_PASSKEY_CONFIRM, + .expect_len = sizeof(struct btp_gap_passkey_confirm_cmd), + .func = passkey_confirm, + }, { - .opcode = BTP_GAP_CONN_PARAM_UPDATE, - .expect_len = sizeof(struct btp_gap_conn_param_update_cmd), - .func = conn_param_update_async, - }, + .opcode = BTP_GAP_CONN_PARAM_UPDATE, + .expect_len = sizeof(struct btp_gap_conn_param_update_cmd), + .func = conn_param_update_async, + }, { - .opcode = BTP_GAP_OOB_LEGACY_SET_DATA, - .expect_len = sizeof(struct btp_gap_oob_legacy_set_data_cmd), - .func = set_oob_legacy_data, - }, + .opcode = BTP_GAP_OOB_LEGACY_SET_DATA, + .expect_len = sizeof(struct btp_gap_oob_legacy_set_data_cmd), + .func = set_oob_legacy_data, + }, { - .opcode = BTP_GAP_OOB_SC_GET_LOCAL_DATA, - .expect_len = 0, - .func = get_oob_sc_local_data, - }, + .opcode = BTP_GAP_OOB_SC_GET_LOCAL_DATA, + .expect_len = 0, + .func = get_oob_sc_local_data, + }, { - .opcode = BTP_GAP_OOB_SC_SET_REMOTE_DATA, - .expect_len = sizeof(struct btp_gap_oob_sc_set_remote_data_cmd), - .func = set_oob_sc_remote_data, - }, + .opcode = BTP_GAP_OOB_SC_SET_REMOTE_DATA, + .expect_len = sizeof(struct btp_gap_oob_sc_set_remote_data_cmd), + .func = set_oob_sc_remote_data, + }, { - .opcode = BTP_GAP_SET_MITM, - .expect_len = sizeof(struct btp_gap_set_mitm_cmd), - .func = set_mitm, - }, + .opcode = BTP_GAP_SET_MITM, + .expect_len = sizeof(struct btp_gap_set_mitm_cmd), + .func = set_mitm, + }, { - .opcode = BTP_GAP_SET_FILTER_ACCEPT_LIST, - .expect_len = BTP_HANDLER_LENGTH_VARIABLE, - .func = set_filter_accept_list, - }, + .opcode = BTP_GAP_SET_FILTER_ACCEPT_LIST, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, + .func = set_filter_accept_list, + }, #if MYNEWT_VAL(BLE_EXT_ADV) { - .opcode = GAP_SET_EXT_ADV, - .expect_len = sizeof(struct btp_gap_set_ext_advertising_cmd), - .func = set_ext_advertising, - }, + .opcode = GAP_SET_EXT_ADV, + .expect_len = sizeof(struct btp_gap_set_ext_advertising_cmd), + .func = set_ext_advertising, + }, #endif /* BLE_EXT_ADV*/ #if MYNEWT_VAL(BLE_PERIODIC_ADV) { - .opcode = GAP_PADV_CONFIGURE, - .expect_len = sizeof(struct gap_periodic_adv_configure_cmd), - .func = periodic_adv_configure, - }, + .opcode = GAP_PADV_CONFIGURE, + .expect_len = sizeof(struct gap_periodic_adv_configure_cmd), + .func = periodic_adv_configure, + }, { - .opcode = GAP_PADV_START, - .expect_len = sizeof(struct gap_periodic_adv_start_cmd), - .func = periodic_adv_start, - }, + .opcode = GAP_PADV_START, + .expect_len = sizeof(struct gap_periodic_adv_start_cmd), + .func = periodic_adv_start, + }, { - .opcode = GAP_PADV_SET_DATA, - .expect_len = BTP_HANDLER_LENGTH_VARIABLE, - .func = periodic_adv_set_data, - }, + .opcode = GAP_PADV_SET_DATA, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, + .func = periodic_adv_set_data, + }, { - .opcode = GAP_PADV_CREATE_SYNC, - .expect_len = sizeof(struct gap_periodic_adv_create_sync_cmd), - .func = periodic_adv_create_sync, - }, + .opcode = GAP_PADV_CREATE_SYNC, + .expect_len = sizeof(struct gap_periodic_adv_create_sync_cmd), + .func = periodic_adv_create_sync, + }, #endif #if MYNEWT_VAL(BLE_PERIODIC_ADV_SYNC_TRANSFER) { - .opcode = GAP_PADV_SYNC_TRANSFER_SET_INFO, - .expect_len = - sizeof(struct gap_periodic_adv_sync_transfer_set_info_cmd), - .func = periodic_adv_sync_transfer_set_info, - }, + .opcode = GAP_PADV_SYNC_TRANSFER_SET_INFO, + .expect_len = sizeof(struct gap_periodic_adv_sync_transfer_set_info_cmd), + .func = periodic_adv_sync_transfer_set_info, + }, { - .opcode = GAP_PADV_SYNC_TRANSFER_START, - .expect_len = sizeof(struct gap_periodic_adv_sync_transfer_start_cmd), - .func = periodic_adv_sync_transfer_start, - }, + .opcode = GAP_PADV_SYNC_TRANSFER_START, + .expect_len = sizeof(struct gap_periodic_adv_sync_transfer_start_cmd), + .func = periodic_adv_sync_transfer_start, + }, { - .opcode = GAP_PADV_SYNC_TRANSFER_RECV, - .expect_len = sizeof(struct gap_periodic_adv_sync_transfer_recv_cmd), - .func = periodic_adv_sync_transfer_recv, - }, + .opcode = GAP_PADV_SYNC_TRANSFER_RECV, + .expect_len = sizeof(struct gap_periodic_adv_sync_transfer_recv_cmd), + .func = periodic_adv_sync_transfer_recv, + }, #endif #if MYNEWT_VAL(BLE_CONN_SUBRATING) { - .opcode = GAP_SUBRATE_REQUEST, - .expect_len = sizeof(struct gap_subrate_request_cmd), - .func = subrate_request, - }, + .opcode = GAP_SUBRATE_REQUEST, + .expect_len = sizeof(struct gap_subrate_request_cmd), + .func = subrate_request, + }, #endif { .opcode = GAP_CONFIGURE_SECURITY_MODE,