Skip to content

Commit 8e60f7c

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

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

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

Lines changed: 21 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,31 @@
5353
typedef uint32_t nvs_handle_t;
5454

5555
static const char *LOG_TAG = "NIMBLE_NVS";
56+
static char nimble_nvs_namespace_buf[NIMBLE_NVS_STR_NAME_MAX_LEN];
57+
static const char *NIMBLE_NVS_NAMESPACE = NIMBLE_NVS_DEFAULT_NAMESPACE;
5658

5759
/*****************************************************************************
5860
* $ MISC *
5961
*****************************************************************************/
6062

63+
void
64+
set_nimble_nvs_namespace(const char *ns)
65+
{
66+
if (ns == NULL) {
67+
NIMBLE_NVS_NAMESPACE = NIMBLE_NVS_DEFAULT_NAMESPACE;
68+
return;
69+
}
70+
71+
if (strlen(ns) < NIMBLE_NVS_STR_NAME_MAX_LEN) {
72+
strncpy(nimble_nvs_namespace_buf, ns, NIMBLE_NVS_STR_NAME_MAX_LEN - 1);
73+
nimble_nvs_namespace_buf[NIMBLE_NVS_STR_NAME_MAX_LEN - 1] = '\0';
74+
NIMBLE_NVS_NAMESPACE = nimble_nvs_namespace_buf;
75+
} else {
76+
ESP_LOGE(LOG_TAG, "Namespace string is too long, using default namespace");
77+
NIMBLE_NVS_NAMESPACE = NIMBLE_NVS_DEFAULT_NAMESPACE;
78+
}
79+
}
80+
6181
static void
6282
get_nvs_key_string(int obj_type, int index, char *key_string)
6383
{

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_nimble_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)