You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/03/05 22:10:30 UTC

[GitHub] jacobrosenthal closed pull request #860: blecent and blesplit remove set g_dev_addr

jacobrosenthal closed pull request #860: blecent and blesplit remove set g_dev_addr
URL: https://github.com/apache/mynewt-core/pull/860
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/apps/blecent/pkg.yml b/apps/blecent/pkg.yml
index 7a7f3cc36..29dae6394 100644
--- a/apps/blecent/pkg.yml
+++ b/apps/blecent/pkg.yml
@@ -26,6 +26,7 @@ pkg.deps:
     - kernel/os 
     - net/nimble/controller
     - net/nimble/host
+    - net/nimble/host/util
     - net/nimble/host/services/gap
     - net/nimble/host/services/gatt
     - net/nimble/host/store/ram
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index 18849bee8..0516de416 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -28,6 +28,7 @@
 #include "nimble/ble.h"
 #include "controller/ble_ll.h"
 #include "host/ble_hs.h"
+#include "host/util/util.h"
 
 /* RAM HCI transport. */
 #include "transport/ram/ble_hci_ram.h"
@@ -223,9 +224,17 @@ blecent_on_disc_complete(const struct peer *peer, int status, void *arg)
 static void
 blecent_scan(void)
 {
+    uint8_t own_addr_type;
     struct ble_gap_disc_params disc_params;
     int rc;
 
+    /* Figure out address to use while advertising (no privacy for now) */
+    rc = ble_hs_id_infer_auto(0, &own_addr_type);
+    if (rc != 0) {
+        BLECENT_LOG(ERROR, "error determining address type; rc=%d\n", rc);
+        return;
+    }
+
     /* Tell the controller to filter duplicates; we don't want to process
      * repeated advertisements from the same device.
      */
@@ -243,7 +252,7 @@ blecent_scan(void)
     disc_params.filter_policy = 0;
     disc_params.limited = 0;
 
-    rc = ble_gap_disc(BLE_OWN_ADDR_PUBLIC, BLE_HS_FOREVER, &disc_params,
+    rc = ble_gap_disc(own_addr_type, BLE_HS_FOREVER, &disc_params,
                       blecent_gap_event, NULL);
     if (rc != 0) {
         BLECENT_LOG(ERROR, "Error initiating GAP discovery procedure; rc=%d\n",
@@ -470,6 +479,12 @@ blecent_on_reset(int reason)
 static void
 blecent_on_sync(void)
 {
+    int rc;
+
+    /* Make sure we have proper identity address set (public preferred) */
+    rc = ble_hs_util_ensure_addr(0);
+    assert(rc == 0);
+
     /* Begin scanning for a peripheral to connect to. */
     blecent_scan();
 }
@@ -486,9 +501,6 @@ main(void)
 {
     int rc;
 
-    /* Set initial BLE device address. */
-    memcpy(g_dev_addr, (uint8_t[6]){0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a}, 6);
-
     /* Initialize OS */
     sysinit();
 
diff --git a/apps/blesplit/pkg.yml b/apps/blesplit/pkg.yml
index c72f443fc..f82c59f99 100644
--- a/apps/blesplit/pkg.yml
+++ b/apps/blesplit/pkg.yml
@@ -32,6 +32,7 @@ pkg.deps:
     - mgmt/newtmgr
     - mgmt/newtmgr/transport/ble
     - net/nimble/host
+    - net/nimble/host/util
     - net/nimble/host/services/ans
     - net/nimble/host/services/gap
     - net/nimble/host/services/gatt
diff --git a/apps/blesplit/src/main.c b/apps/blesplit/src/main.c
index b757c55fc..ce0500b23 100755
--- a/apps/blesplit/src/main.c
+++ b/apps/blesplit/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. */
@@ -79,11 +80,19 @@ blesplit_print_conn_desc(struct ble_gap_conn_desc *desc)
 static void
 blesplit_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;
 
+    /* Figure out address to use while advertising (no privacy for now) */
+    rc = ble_hs_id_infer_auto(0, &own_addr_type);
+    if (rc != 0) {
+        BLESPLIT_LOG(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).
@@ -129,7 +138,7 @@ blesplit_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,
+    rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER,
                            &adv_params, blesplit_gap_event, NULL);
     if (rc != 0) {
         BLESPLIT_LOG(ERROR, "error enabling advertisement; rc=%d\n", rc);
@@ -261,6 +270,12 @@ blesplit_on_reset(int reason)
 static void
 blesplit_on_sync(void)
 {
+    int rc;
+
+    /* Make sure we have proper identity address set (public preferred) */
+    rc = ble_hs_util_ensure_addr(0);
+    assert(rc == 0);
+
     /* Begin advertising. */
     blesplit_advertise();
 }
@@ -281,9 +296,6 @@ main(void)
     /* Initialize OS */
     sysinit();
 
-    /* Set initial BLE device address. */
-    memcpy(g_dev_addr, (uint8_t[6]){0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a}, 6);
-
     /* Initialize the blesplit log. */
     log_register("blesplit", &blesplit_log, &log_console_handler, NULL,
                  LOG_SYSLEVEL);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services