Browse Source

bluetooth-fw/nimble: unload store elements when stopping

Because prv_comm_start in bluetooth_ctl() registers bondings on every
stack start. This is probably inefficient, as is the whole BT
pseudo-stack in PebbleOS, but for now just keep impedances matching
until one day we can make things better.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Gerard Marull-Paretas 1 month ago
parent
commit
8650f49dd6

+ 2 - 0
src/bluetooth-fw/nimble/init.c

@@ -141,6 +141,8 @@ void bt_driver_stop(void) {
   PBL_ASSERT(f_rc == pdTRUE, "NimBLE host stop timed out");
 
   ble_gatts_reset();
+
+  nimble_store_unload();
 }
 
 void bt_driver_power_down_controller_on_boot(void) {}

+ 17 - 0
src/bluetooth-fw/nimble/nimble_store.c

@@ -318,6 +318,23 @@ void nimble_store_init(void) {
   ble_hs_cfg.store_gen_key_cb = prv_nimble_store_gen_key;
 }
 
+static bool prv_store_value_free(ListNode *node, void *context) {
+  kernel_free(node);
+  return false;
+}
+
+void nimble_store_unload(void) {
+  bt_lock();
+
+  list_foreach((ListNode *)s_peer_value_secs, prv_store_value_free, NULL);
+  list_foreach((ListNode *)s_our_value_secs, prv_store_value_free, NULL);
+
+  s_peer_value_secs = NULL;
+  s_our_value_secs = NULL;
+
+  bt_unlock();
+}
+
 static void prv_convert_bonding_remote_to_store_val(const BleBonding *bonding,
                                                     struct ble_store_value_sec *value_sec) {
   memset(value_sec, 0, sizeof(struct ble_store_value_sec));

+ 1 - 0
src/bluetooth-fw/nimble/nimble_store.h

@@ -18,5 +18,6 @@
 #define _NIMBLE_STORE_H_
 
 void nimble_store_init(void);
+void nimble_store_unload(void);
 
 #endif