This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new fe64a70f6 apps/bleprph_oic: Drop direct g_dev_addr use for split stack 
builds
fe64a70f6 is described below

commit fe64a70f6ddf11aa7194a56da792cc4934d32dd6
Author: Wiktor Kwiatkowski <[email protected]>
AuthorDate: Thu Oct 1 15:16:13 2026 +0200

    apps/bleprph_oic: Drop direct g_dev_addr use for split stack builds
    
    Ensure BLE address via host API so the sample links when
    the controller is not in the same image (e.g. nRF5340).
    Use ble_hs_id_infer_auto instead of assuming a public address.
---
 apps/bleprph_oic/pkg.yml    |  1 +
 apps/bleprph_oic/src/main.c | 18 +++++++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/apps/bleprph_oic/pkg.yml b/apps/bleprph_oic/pkg.yml
index 385112390..98bfe7779 100644
--- a/apps/bleprph_oic/pkg.yml
+++ b/apps/bleprph_oic/pkg.yml
@@ -40,3 +40,4 @@ pkg.deps:
     - "@apache-mynewt-core/sys/sysinit"
     - "@apache-mynewt-core/sys/shell"
     - "@apache-mynewt-core/sys/id"
+    - "@apache-mynewt-nimble/nimble/host/util"
diff --git a/apps/bleprph_oic/src/main.c b/apps/bleprph_oic/src/main.c
index 4d865b8c6..4eb9a5ebe 100644
--- a/apps/bleprph_oic/src/main.c
+++ b/apps/bleprph_oic/src/main.c
@@ -34,6 +34,7 @@
 /* BLE */
 #include <nimble/ble.h>
 #include <host/ble_hs.h>
+#include "host/util/util.h"
 #include <services/gap/ble_svc_gap.h>
 
 /* Application-specified header. */
@@ -76,11 +77,18 @@ bleprph_print_conn_desc(struct ble_gap_conn_desc *desc)
 static void
 bleprph_advertise(void)
 {
+    uint8_t own_addr_type;
     struct ble_gap_adv_params adv_params;
     struct ble_hs_adv_fields fields;
     const char *name;
     int rc;
 
+    rc = ble_hs_id_infer_auto(0, &own_addr_type);
+    if (rc != 0) {
+        MODLOG_DFLT(ERROR, "error determining address type; rc=%d\n", rc);
+        return;
+    }
+
     /**
      *  Set the advertisement data included in our advertisements:
      *     o Flags (indicates advertisement type and other general info).
@@ -136,8 +144,8 @@ bleprph_advertise(void)
     memset(&adv_params, 0, sizeof adv_params);
     adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
     adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
-    rc = ble_gap_adv_start(BLE_OWN_ADDR_PUBLIC, NULL, BLE_HS_FOREVER,
-                           &adv_params, bleprph_gap_event, NULL);
+    rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER, &adv_params,
+                           bleprph_gap_event, NULL);
     if (rc != 0) {
         DFLT_LOG_ERROR("error enabling advertisement; rc=%d\n", rc);
         return;
@@ -271,6 +279,9 @@ bleprph_on_reset(int reason)
 static void
 bleprph_on_sync(void)
 {
+    int rc = ble_hs_util_ensure_addr(0);
+    assert(rc == 0);
+
     /* Begin advertising. */
     bleprph_advertise();
 }
@@ -366,9 +377,6 @@ mynewt_main(int argc, char **argv)
 {
     int rc;
 
-    /* Set initial BLE device address. */
-    memcpy(g_dev_addr, (uint8_t[6]){0x0a, 0xfa, 0xcf, 0xac, 0xfa, 0xc0}, 6);
-
     /* Initialize OS */
     sysinit();
 

Reply via email to