Skip to content

Commit 9e9daac

Browse files
committed
Add custom nvs namespace feature.
* Adds the function `set_nvs_namespace(const char*)` for users to switch bond data stores.
1 parent 4746c60 commit 9e9daac

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/nimble/nimble/host/store/config/src/ble_store_nvs.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#define NIMBLE_NVS_CCCD_SEC_KEY "cccd_sec"
4343
#define NIMBLE_NVS_CSFC_SEC_KEY "csfc_sec"
4444
#define NIMBLE_NVS_PEER_RECORDS_KEY "p_dev_rec"
45-
#define NIMBLE_NVS_NAMESPACE "nimble_bond"
45+
#define NIMBLE_NVS_DEFAULT_NAMESPACE "nimble_bond"
4646

4747
#if MYNEWT_VAL(ENC_ADV_DATA)
4848
#define NIMBLE_NVS_EAD_SEC_KEY "ead_sec"
@@ -53,11 +53,23 @@
5353
typedef uint32_t nvs_handle_t;
5454

5555
static const char *LOG_TAG = "NIMBLE_NVS";
56+
static const char *NIMBLE_NVS_NAMESPACE = NIMBLE_NVS_DEFAULT_NAMESPACE;
5657

5758
/*****************************************************************************
5859
* $ MISC *
5960
*****************************************************************************/
6061

62+
void
63+
set_nvs_namespace(const char *ns)
64+
{
65+
if (ns != NULL && strlen(ns) < NIMBLE_NVS_STR_NAME_MAX_LEN) {
66+
NIMBLE_NVS_NAMESPACE = ns;
67+
} else {
68+
ESP_LOGE(LOG_TAG, "Namespace string is too long, using default namespace");
69+
NIMBLE_NVS_NAMESPACE = NIMBLE_NVS_DEFAULT_NAMESPACE;
70+
}
71+
}
72+
6173
static void
6274
get_nvs_key_string(int obj_type, int index, char *key_string)
6375
{

src/nimconfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@
190190
# define MYNEWT_VAL_BLE_HCI_VS (0)
191191
# endif
192192

193+
# ifdef __cplusplus
194+
extern "C" void set_nvs_namespace(const char *ns);
195+
# endif
196+
193197
#else // !ESP_PLATFORM
194198
# if defined(NRF51)
195199
# include "syscfg/devcfg/nrf51cfg.h"

0 commit comments

Comments
 (0)