fix(nimble): Corrected storing method of csfc to nvs

This commit is contained in:
Rahul Tank
2025-01-06 10:55:45 +05:30
parent 16d59c062d
commit d7a585dcf0
3 changed files with 26 additions and 22 deletions
+4
View File
@@ -2264,6 +2264,7 @@ ble_gatts_peer_cl_sup_feat_update(uint16_t conn_handle, struct os_mbuf *om)
goto done;
}
memset(&value_csfc, 0, sizeof value_csfc);
value_csfc.peer_addr = conn->bhc_peer_addr;
memcpy(value_csfc.csfc, feat, MYNEWT_VAL(BLE_GATT_CSFC_SIZE));
@@ -2433,6 +2434,9 @@ ble_gatts_bonding_established(uint16_t conn_handle)
}
csfc.peer_addr = conn->bhc_peer_addr;
csfc.peer_addr.type =
ble_hs_misc_peer_addr_type_to_id(conn->bhc_peer_addr.type);
memcpy(csfc.csfc, conn->bhc_gatt_svr.peer_cl_sup_feat, MYNEWT_VAL(BLE_GATT_CSFC_SIZE));
ble_hs_unlock();
+20 -20
View File
@@ -52,8 +52,8 @@ int ble_store_config_num_cccds;
#if MYNEWT_VAL(BLE_STORE_MAX_CSFCS)
struct ble_store_value_csfc
ble_store_config_csfcs[MYNEWT_VAL(BLE_STORE_MAX_CSFCS)];
int ble_store_config_num_csfcs;
#endif
int ble_store_config_num_csfcs;
#if MYNEWT_VAL(ENC_ADV_DATA)
struct ble_store_value_ead
@@ -911,28 +911,25 @@ ble_store_config_delete_rpa_rec(const struct ble_store_key_rpa_rec *key_rpa_rec)
*****************************************************************************/
static int
ble_store_config_find_csfc(const struct ble_store_key_csfc *key)
ble_store_config_find_csfc(const struct ble_store_key_csfc *key,
const struct ble_store_value_csfc *value_csfc,
int num_value_csfc)
{
struct ble_store_value_csfc *csfc;
int skipped;
const struct ble_store_value_csfc *cur;
int i;
skipped = 0;
for (i = 0; i < ble_store_config_num_csfcs; i++) {
csfc = ble_store_config_csfcs + i;
if (!ble_addr_cmp(&key->peer_addr, BLE_ADDR_ANY)) {
if (key->idx < num_value_csfc) {
return key->idx;
}
} else if (key->idx == 0) {
for (i = 0; i < num_value_csfc; i++) {
cur = &value_csfc[i];
if (ble_addr_cmp(&key->peer_addr, BLE_ADDR_ANY)) {
if (ble_addr_cmp(&csfc->peer_addr, &key->peer_addr)) {
continue;
if (!ble_addr_cmp(&cur->peer_addr, &key->peer_addr)) {
return i;
}
}
if (key->idx > skipped) {
skipped++;
continue;
}
return i;
}
return -1;
@@ -944,7 +941,8 @@ ble_store_config_delete_csfc(const struct ble_store_key_csfc *key_csfc)
int idx;
int rc;
idx = ble_store_config_find_csfc(key_csfc);
idx = ble_store_config_find_csfc(key_csfc, ble_store_config_csfcs,
ble_store_config_num_csfcs);
if (idx == -1) {
return BLE_HS_ENOENT;
}
@@ -971,7 +969,8 @@ ble_store_config_read_csfc(const struct ble_store_key_csfc *key_csfc,
{
int idx;
idx = ble_store_config_find_csfc(key_csfc);
idx = ble_store_config_find_csfc(key_csfc, ble_store_config_csfcs,
ble_store_config_num_csfcs);
if (idx == -1) {
return BLE_HS_ENOENT;
}
@@ -988,7 +987,8 @@ ble_store_config_write_csfc(const struct ble_store_value_csfc *value_csfc)
int rc;
ble_store_key_from_value_csfc(&key_csfc, value_csfc);
idx = ble_store_config_find_csfc(&key_csfc);
idx = ble_store_config_find_csfc(&key_csfc, ble_store_config_csfcs,
ble_store_config_num_csfcs);
if (idx == -1) {
if (ble_store_config_num_csfcs >= MYNEWT_VAL(BLE_STORE_MAX_CSFCS)) {
BLE_HS_LOG(DEBUG, "error persisting csfc; too many entries (%d)\n",
@@ -60,8 +60,8 @@ static struct conf_handler ble_store_config_conf_handler = {
#define BLE_STORE_CONFIG_CSFC_ENCODE_SZ \
BASE64_ENCODE_SIZE(sizeof (struct ble_store_value_csfc))
#define BLE_STORE_CONFIG_CSFC_ENCODE_SZ \
BASE64_ENCODE_SIZE(sizeof (struct ble_store_value_csfc))
#define BLE_STORE_CONFIG_CSFC_SET_ENCODE_SZ \
(MYNEWT_VAL(BLE_STORE_MAX_CSFCS) * BLE_STORE_CONFIG_CSFC_ENCODE_SZ + 1)
#if MYNEWT_VAL(ENC_ADV_DATA)
#define BLE_STORE_CONFIG_EAD_ENCODE_SZ \