diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index 629f7a7069..9cad15b996 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -609,11 +609,14 @@ if(CONFIG_BT_ENABLED) "host/nimble/nimble/nimble/host/store/ram/src/ble_store_ram.c" "host/nimble/nimble/nimble/host/store/config/src/ble_store_config.c" "host/nimble/nimble/nimble/host/store/config/src/ble_store_nvs.c" + "host/nimble/nimble/nimble/host/src/ble_gattc_cache.c" + "host/nimble/nimble/nimble/host/src/ble_gattc_cache_conn.c" ) list(APPEND srcs "host/nimble/nimble/porting/nimble/src/nimble_port.c" "host/nimble/nimble/porting/npl/freertos/src/nimble_port_freertos.c" + "host/nimble/port/src/nvs_port.c" ) list(APPEND include_dirs porting/include diff --git a/components/bt/host/nimble/Kconfig.in b/components/bt/host/nimble/Kconfig.in index c035ccbb16..09dfd663b6 100644 --- a/components/bt/host/nimble/Kconfig.in +++ b/components/bt/host/nimble/Kconfig.in @@ -619,6 +619,36 @@ config BT_NIMBLE_PERIODIC_ADV_ENH help Enable the periodic advertising enhancements +menuconfig BT_NIMBLE_GATT_CACHING + bool "Enable GATT caching" + depends on BT_NIMBLE_ENABLED && BT_NIMBLE_50_FEATURE_SUPPORT + help + Enable GATT caching +config BT_NIMBLE_GATT_CACHING_MAX_CONNS + int "Maximum connections to be cached" + depends on BT_NIMBLE_GATT_CACHING + default 1 + help + Set this option to set the upper limit on number of connections to be cached. +config BT_NIMBLE_GATT_CACHING_MAX_SVCS + int "Maximum number of services per connection" + depends on BT_NIMBLE_GATT_CACHING + default 64 + help + Set this option to set the upper limit on number of services per connection to be cached. +config BT_NIMBLE_GATT_CACHING_MAX_CHRS + int "Maximum number of characteristics per connection" + depends on BT_NIMBLE_GATT_CACHING + default 64 + help + Set this option to set the upper limit on number of characteristics per connection to be cached. +config BT_NIMBLE_GATT_CACHING_MAX_DSCS + int "Maximum number of descriptors per connection" + depends on BT_NIMBLE_GATT_CACHING + default 64 + help + Set this option to set the upper limit on number of discriptors per connection to be cached. + config BT_NIMBLE_WHITELIST_SIZE int "BLE white list size" depends on BT_NIMBLE_ENABLED diff --git a/components/bt/host/nimble/port/include/esp_nimble_cfg.h b/components/bt/host/nimble/port/include/esp_nimble_cfg.h index 6d0701d026..fead96289a 100644 --- a/components/bt/host/nimble/port/include/esp_nimble_cfg.h +++ b/components/bt/host/nimble/port/include/esp_nimble_cfg.h @@ -129,6 +129,16 @@ #define MYNEWT_VAL_BLE_MAX_PERIODIC_ADVERTISER_LIST (CONFIG_BT_NIMBLE_MAX_PERIODIC_ADVERTISER_LIST) #endif +#ifndef CONFIG_BT_NIMBLE_GATT_CACHING +#define MYNEWT_VAL_BLE_GATT_CACHING (0) +#else +#define MYNEWT_VAL_BLE_GATT_CACHING (CONFIG_BT_NIMBLE_GATT_CACHING) +#define MYNEWT_VAL_BLE_GATT_CACHING_MAX_CONNS (CONFIG_BT_NIMBLE_GATT_CACHING_MAX_CONNS) +#define MYNEWT_VAL_BLE_GATT_CACHING_MAX_SVCS (CONFIG_BT_NIMBLE_GATT_CACHING_MAX_SVCS) +#define MYNEWT_VAL_BLE_GATT_CACHING_MAX_CHRS (CONFIG_BT_NIMBLE_GATT_CACHING_MAX_CHRS) +#define MYNEWT_VAL_BLE_GATT_CACHING_MAX_DSCS (CONFIG_BT_NIMBLE_GATT_CACHING_MAX_DSCS) +#endif + #ifndef CONFIG_BT_NIMBLE_MAX_EXT_ADV_INSTANCES #define MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES (1) #else diff --git a/components/bt/host/nimble/port/src/nvs_port.c b/components/bt/host/nimble/port/src/nvs_port.c new file mode 100644 index 0000000000..19d89a063c --- /dev/null +++ b/components/bt/host/nimble/port/src/nvs_port.c @@ -0,0 +1,40 @@ +/* + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef _NVS_H +#define _NVS_H + +#include +#include "nvs.h" +#include "nimble/storage_port.h" + +static int +nvs_open_custom(const char* namespace_name, open_mode_t open_mode, cache_handle_t *out_handle) +{ + switch (open_mode) { + case READONLY: + return nvs_open(namespace_name, NVS_READONLY, out_handle); + + case READWRITE: + return nvs_open(namespace_name, NVS_READWRITE, out_handle); + + default: + return -1; + } +} + +struct cache_fn_mapping +link_storage_fn(void *storage_cb) +{ + struct cache_fn_mapping cache_fn; + cache_fn.open = nvs_open_custom; + cache_fn.close = nvs_close; + cache_fn.erase_all = nvs_erase_all; + cache_fn.write = nvs_set_blob; + cache_fn.read = nvs_get_blob; + return cache_fn; +} +#endif