Skip to content

Commit

Permalink
Merge branch 'feature/gatt_caching_support_v5.1' into 'release/v5.1'
Browse files Browse the repository at this point in the history
feat(nimble): Gatt caching support (v5.1)

See merge request espressif/esp-idf!28512
  • Loading branch information
jack0c committed Feb 28, 2024
2 parents 96f4468 + 30f01c3 commit 956797e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/bt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions components/bt/host/nimble/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions components/bt/host/nimble/port/include/esp_nimble_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions components/bt/host/nimble/port/src/nvs_port.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#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

0 comments on commit 956797e

Please sign in to comment.