factorysetup: Let BLE chip store bond db
What changed, and why it matters
This commit changes the factory-setup firmware so that the Bluetooth chip, rather than the main processor, stores the Bluetooth pairing bond database. It also makes the factory setup reset the Bluetooth chip each time and always report an empty bond database, so the setup can be run repeatedly without leaving old pairing data behind. The change is described as a factory-process improvement; there is no direct evidence it fixes an exploitable security vulnerability.
Treat as a hardening/reliability change rather than an urgent security patch. Review whether factory-setup firmware is exposed to untrusted access and verify that bond-db handling in production firmware remains unchanged. No immediate user action is indicated.
Security signals we found
Change to Bluetooth pairing/bonding data handling
Factory-only conditional compilation (FACTORYSETUP == 1)
Reset of external BLE chip added to factory flow
Bond database now stored by BLE chip during factory setup
Evidence from the diff
The patch modifies the DA14531 Bluetooth handler to set a flag when a bond database is written, exposes that flag in factory-setup builds, and changes factorysetup.c to reset the BLE chip on entry and wait for the bond-db-set flag instead of merely waiting for any UART frame. memory_shared.c is changed so memory_get_ble_bond_db() returns -1 (empty) under FACTORYSETUP, forcing the BLE chip to re-send the bond db on every boot. This makes factory setup idempotent with respect to BLE bonding state.
Changed components
src/da14531/da14531_handler.csrc/da14531/da14531_handler.hsrc/factorysetup.csrc/memory/memory_shared.cInspect captured patch +29 / −4
diff --git a/src/da14531/da14531_handler.c b/src/da14531/da14531_handler.c
index 062cf33..354ba21 100644
--- a/src/da14531/da14531_handler.c
+++ b/src/da14531/da14531_handler.c
@@ -75,6 +75,15 @@ extern bool bootloader_pairing_request;
extern uint8_t bootloader_pairing_code_bytes[4];
#endif
+#if FACTORYSETUP == 1
+bool _bond_db_set = false;
+
+bool da14531_handler_bond_db_set(void)
+{
+ return _bond_db_set;
+}
+#endif
+
static void _ctrl_handler(struct da14531_ctrl_frame* frame, struct ringbuffer* queue)
{
switch (frame->cmd) {
@@ -135,6 +144,9 @@ static void _ctrl_handler(struct da14531_ctrl_frame* frame, struct ringbuffer* q
break;
}
memory_set_ble_bond_db(&frame->cmd_data[0], frame->payload_length - 1);
+#if FACTORYSETUP == 1
+ _bond_db_set = true;
+#endif
break;
case CTRL_CMD_PAIRING_CODE: {
if (frame->payload_length < 5) {
diff --git a/src/da14531/da14531_handler.h b/src/da14531/da14531_handler.h
index f3ec531..de0061b 100644
--- a/src/da14531/da14531_handler.h
+++ b/src/da14531/da14531_handler.h
@@ -16,11 +16,16 @@
#define DA14531_HANDLER_H
#include "da14531_protocol.h"
+#include <platform/platform_config.h>
#include <utils_ringbuffer.h>
extern volatile const uint8_t* da14531_handler_current_product;
extern volatile uint16_t da14531_handler_current_product_len;
+#if FACTORYSETUP == 1
+bool da14531_handler_bond_db_set(void);
+#endif
+
void da14531_handler(struct da14531_protocol_frame* frame, struct ringbuffer* queue);
#endif
diff --git a/src/factorysetup.c b/src/factorysetup.c
index 24185c2..0da06e5 100644
--- a/src/factorysetup.c
+++ b/src/factorysetup.c
@@ -15,6 +15,7 @@
#include "common_main.h"
#include "da14531/da14531.h"
#include "da14531/da14531_binary.h"
+#include "da14531/da14531_handler.h"
#include "da14531/da14531_protocol.h"
#include "driver_init.h"
#include "flags.h"
@@ -554,16 +555,18 @@ static ble_error_code_t _setup_ble(void)
struct ringbuffer uart_write_queue;
ringbuffer_init(&uart_write_queue, uart_write_buf, sizeof(uart_write_buf));
// If the BLE chip already was successfully booted, for example by running the factory-setup
- // once already and not power cycled, we need to ask for something to get a uart frame back.
- // Therefore we schedule a "get connection state".
- da14531_get_connection_state(&uart_write_queue);
+ // once already and not power cycled, we need to reset it to trigger a complete setup again.
+ da14531_reset(&uart_write_queue);
int32_t timeout = 1000000;
while (timeout-- > 0) {
uart_poll(uart_read_buf, sizeof(uart_read_buf), &uart_read_buf_len, &uart_write_queue);
struct da14531_protocol_frame* frame =
da14531_protocol_poll(uart_read_buf, &uart_read_buf_len, NULL, &uart_write_queue);
if (frame) {
- // We have successfully booted the chip, the BLE chips firmware sent its first request
+ da14531_handler(frame, &uart_write_queue);
+ }
+ if (da14531_handler_bond_db_set()) {
+ // We have successfully booted the BLE chip and the bond db is stored.
return BLE_OK;
}
}
diff --git a/src/memory/memory_shared.c b/src/memory/memory_shared.c
index dcf5745..755280c 100644
--- a/src/memory/memory_shared.c
+++ b/src/memory/memory_shared.c
@@ -166,6 +166,11 @@ bool memory_ble_enabled(void)
int16_t memory_get_ble_bond_db(uint8_t* data)
{
+#if FACTORYSETUP == 1
+ // Always return "empty bond db" in factory setup to ensure idempotency. This will force the BLE
+ // chip to always set the bond db when it has booted.
+ return -1;
+#endif
chunk_shared_t chunk = {0};
memory_read_shared_bootdata(&chunk);
int16_t len = chunk.fields.ble_bond_db_len;
Why this scored 25/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.