Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions subsys/bluetooth/rpc/common/bt_rpc_gatt_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ const struct bt_gatt_attr *bt_rpc_gatt_index_to_attr(uint32_t index)
{
uint32_t service_index = index >> ATTR_INDEX_POS;
uint32_t attr_index = index & ATTR_INDEX_MASK;
const struct bt_gatt_service *service = svc_cache.services[service_index];
const struct bt_gatt_service *service;

if (service_index >= svc_cache.count) {
return NULL;
}

if ((service_index >= svc_cache.count) || (attr_index >= service->attr_count)) {
service = svc_cache.services[service_index];
if (!service || (attr_index >= service->attr_count)) {
return NULL;
}

Expand All @@ -92,7 +97,7 @@ const struct bt_gatt_attr *bt_rpc_gatt_index_to_attr(uint32_t index)

const struct bt_gatt_service *bt_rpc_gatt_get_service_by_index(uint16_t svc_index)
{
if (svc_index > svc_cache.count) {
if (svc_index >= svc_cache.count) {
return NULL;
}

Expand Down Expand Up @@ -203,7 +208,7 @@ void bt_rpc_gatt_foreach_attr_type(uint16_t start_handle, uint16_t end_handle,
}

for (size_t j = 0; j < svc->attr_count; j++) {
struct bt_gatt_attr *attr = &svc->attrs[j];
const struct bt_gatt_attr *attr = &svc->attrs[j];

handle = bt_gatt_attr_get_handle(attr);

Expand Down
1 change: 1 addition & 0 deletions subsys/bluetooth/rpc/host/bt_rpc_gatt_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ static void bt_rpc_gatt_service_unregister_rpc_handler(const struct nrf_rpc_grou

svc = bt_rpc_gatt_get_service_by_index(svc_index);
if (!svc) {
LOG_ERR("Service unregister: Invalid service index %u", svc_index);
result = -EINVAL;
}

Expand Down
29 changes: 29 additions & 0 deletions tests/subsys/bluetooth/rpc_gatt_service/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Copyright (c) 2025 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(bluetooth_rpc_gatt_service_test)

FILE(GLOB app_sources src/*.c)

target_include_directories(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${ZEPHYR_NRF_MODULE_DIR}/subsys/bluetooth/rpc/common
)

# Include the source file directly for unit testing
target_sources(app PRIVATE
${app_sources}
${ZEPHYR_NRF_MODULE_DIR}/subsys/bluetooth/rpc/common/bt_rpc_gatt_common.c
)

# Include test config header before compilation to define config values
# that aren't available via Kconfig without CONFIG_BT_RPC
target_compile_options(app PRIVATE
-include ${CMAKE_CURRENT_SOURCE_DIR}/src/test_config.h
)
10 changes: 10 additions & 0 deletions tests/subsys/bluetooth/rpc_gatt_service/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CONFIG_ZTEST=y



# Minimal configuration for testing service cache only
# Note: CONFIG_BT_RPC_GATT_SRV_MAX and CONFIG_BT_RPC_LOG_LEVEL are defined
# via compile definitions in CMakeLists.txt since they require CONFIG_BT_RPC

# Logging (minimal)
CONFIG_LOG=y
13 changes: 13 additions & 0 deletions tests/subsys/bluetooth/rpc_gatt_service/src/log_stub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*
* Stub implementation for logging module to avoid linker errors
* when testing without full BT RPC stack
*/

#include <zephyr/logging/log.h>

/* Stub the log constant structure that's normally generated */
LOG_MODULE_REGISTER(BT_RPC, 4);
Loading
Loading