You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2017/04/07 18:45:04 UTC

[30/50] [abbrv] incubator-mynewt-core git commit: MYNEWT-707: Add API to retrieve public and random static address

MYNEWT-707: Add API to retrieve public and random static address

Please read the Jira ticket for more information on how to use
these API. The controller now calls ble_hw_get_public_addr() and
will use that address for its public address. The global
device address has not been hidden yet since some apps rely on
the ability to modify it.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/95c7d3e5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/95c7d3e5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/95c7d3e5

Branch: refs/heads/master
Commit: 95c7d3e5f951e381bd8dbfc82335a3a3384d9f56
Parents: 832fa2d
Author: William San Filippo <wi...@runtime.io>
Authored: Tue Apr 4 14:00:11 2017 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Tue Apr 4 14:03:08 2017 -0700

----------------------------------------------------------------------
 apps/bleprph/src/main.c                         |  6 +--
 hw/drivers/nimble/nrf51/src/ble_hw.c            | 52 ++++++++++++++++++++
 hw/drivers/nimble/nrf52/src/ble_hw.c            | 52 ++++++++++++++++++++
 .../controller/include/controller/ble_hw.h      |  6 +++
 net/nimble/controller/src/ble_ll.c              | 13 +++++
 net/nimble/controller/syscfg.yml                |  9 ++++
 6 files changed, 135 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/95c7d3e5/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index 3bdbbcd..1f45fa9 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -255,12 +255,12 @@ main(void)
 {
     int rc;
 
-    /* Initialize OS */
-    sysinit();
-
     /* Set initial BLE device address. */
     memcpy(g_dev_addr, (uint8_t[6]){0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a}, 6);
 
+    /* Initialize OS */
+    sysinit();
+
     /* Initialize the bleprph log. */
     log_register("bleprph", &bleprph_log, &log_console_handler, NULL,
                  LOG_SYSLEVEL);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/95c7d3e5/hw/drivers/nimble/nrf51/src/ble_hw.c
----------------------------------------------------------------------
diff --git a/hw/drivers/nimble/nrf51/src/ble_hw.c b/hw/drivers/nimble/nrf51/src/ble_hw.c
index 9f268cc..c9e6989 100644
--- a/hw/drivers/nimble/nrf51/src/ble_hw.c
+++ b/hw/drivers/nimble/nrf51/src/ble_hw.c
@@ -56,6 +56,58 @@ uint8_t g_nrf_num_irks;
 
 #endif
 
+/* Returns public device address or -1 if not present */
+int
+ble_hw_get_public_addr(ble_addr_t *addr)
+{
+    int rc;
+    uint32_t addr_high;
+    uint32_t addr_low;
+
+    /* Does FICR have a public address */
+    rc = -1;
+    if ((NRF_FICR->DEVICEADDRTYPE & 1) == 0) {
+        addr_low = NRF_FICR->DEVICEADDR[0];
+        addr_high = NRF_FICR->DEVICEADDR[1];
+        rc = 0;
+    } else {
+        /* See if programmed in UICR. Upper 16 bits must all be zero */
+        addr_high = NRF_UICR->CUSTOMER[1];
+        if (addr_high < 65536) {
+            addr_low = NRF_UICR->CUSTOMER[0];
+            rc = 0;
+        }
+    }
+
+    if (!rc) {
+        /* Copy into device address. We can do this because we know platform */
+        memcpy(addr->val, &addr_low, 4);
+        memcpy(&addr->val[4], &addr_high, 2);
+        addr->type = BLE_ADDR_PUBLIC;
+    }
+
+    return rc;
+}
+
+/* Returns random static address or -1 if not present */
+int
+ble_hw_get_static_addr(ble_addr_t *addr)
+{
+    int rc;
+
+    if ((NRF_FICR->DEVICEADDRTYPE & 1) == 1) {
+        memcpy(addr->val, (void *)&NRF_FICR->DEVICEADDR[0], 4);
+        memcpy(&addr->val[4], (void *)&NRF_FICR->DEVICEADDR[1], 2);
+        addr->val[5] |= 0xc0;
+        addr->type = BLE_ADDR_RANDOM;
+        rc = 0;
+    } else {
+        rc = -1;
+    }
+
+    return rc;
+}
+
 /**
  * Clear the whitelist
  *

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/95c7d3e5/hw/drivers/nimble/nrf52/src/ble_hw.c
----------------------------------------------------------------------
diff --git a/hw/drivers/nimble/nrf52/src/ble_hw.c b/hw/drivers/nimble/nrf52/src/ble_hw.c
index ad5af49..dd1323a 100644
--- a/hw/drivers/nimble/nrf52/src/ble_hw.c
+++ b/hw/drivers/nimble/nrf52/src/ble_hw.c
@@ -58,6 +58,58 @@ uint8_t g_nrf_num_irks;
 
 #endif
 
+/* Returns public device address or -1 if not present */
+int
+ble_hw_get_public_addr(ble_addr_t *addr)
+{
+    int rc;
+    uint32_t addr_high;
+    uint32_t addr_low;
+
+    /* Does FICR have a public address */
+    rc = -1;
+    if ((NRF_FICR->DEVICEADDRTYPE & 1) == 0) {
+        addr_low = NRF_FICR->DEVICEADDR[0];
+        addr_high = NRF_FICR->DEVICEADDR[1];
+        rc = 0;
+    } else {
+        /* See if programmed in UICR. Upper 16 bits must all be zero */
+        addr_high = NRF_UICR->CUSTOMER[1];
+        if (addr_high < 65536) {
+            addr_low = NRF_UICR->CUSTOMER[0];
+            rc = 0;
+        }
+    }
+
+    if (!rc) {
+        /* Copy into device address. We can do this because we know platform */
+        memcpy(addr->val, &addr_low, 4);
+        memcpy(&addr->val[4], &addr_high, 2);
+        addr->type = BLE_ADDR_PUBLIC;
+    }
+
+    return rc;
+}
+
+/* Returns random static address or -1 if not present */
+int
+ble_hw_get_static_addr(ble_addr_t *addr)
+{
+    int rc;
+
+    if ((NRF_FICR->DEVICEADDRTYPE & 1) == 1) {
+        memcpy(addr->val, (void *)&NRF_FICR->DEVICEADDR[0], 4);
+        memcpy(&addr->val[4], (void *)&NRF_FICR->DEVICEADDR[1], 2);
+        addr->val[5] |= 0xc0;
+        addr->type = BLE_ADDR_RANDOM;
+        rc = 0;
+    } else {
+        rc = -1;
+    }
+
+    return rc;
+}
+
 /**
  * Clear the whitelist
  *

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/95c7d3e5/net/nimble/controller/include/controller/ble_hw.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_hw.h b/net/nimble/controller/include/controller/ble_hw.h
index 022e2cb..a1941ac 100644
--- a/net/nimble/controller/include/controller/ble_hw.h
+++ b/net/nimble/controller/include/controller/ble_hw.h
@@ -101,6 +101,12 @@ void ble_hw_resolv_list_disable(void);
 /* Returns index of resolved address; -1 if not resolved */
 int ble_hw_resolv_list_match(void);
 
+/* Returns public device address or -1 if not present */
+int ble_hw_get_public_addr(ble_addr_t *addr);
+
+/* Returns random static address or -1 if not present */
+int ble_hw_get_static_addr(ble_addr_t *addr);
+
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/95c7d3e5/net/nimble/controller/src/ble_ll.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll.c b/net/nimble/controller/src/ble_ll.c
index 72ec9cd..360a203 100644
--- a/net/nimble/controller/src/ble_ll.c
+++ b/net/nimble/controller/src/ble_ll.c
@@ -1235,11 +1235,24 @@ ble_ll_init(void)
 #ifdef BLE_XCVR_RFCLK
     uint32_t xtal_ticks;
 #endif
+    ble_addr_t addr;
     struct ble_ll_obj *lldata;
 
     /* Ensure this function only gets called by sysinit. */
     SYSINIT_ASSERT_ACTIVE();
 
+    /* Retrieve the public device address if not set by syscfg */
+    memcpy(&addr.val[0], MYNEWT_VAL_BLE_PUBLIC_DEV_ADDR, BLE_DEV_ADDR_LEN);
+    if (!memcmp(&addr.val[0], ((ble_addr_t *)BLE_ADDR_ANY)->val,
+                BLE_DEV_ADDR_LEN)) {
+        rc = ble_hw_get_public_addr(&addr);
+        if (!rc) {
+            memcpy(g_dev_addr, &addr.val[0], BLE_DEV_ADDR_LEN);
+        }
+    } else {
+        memcpy(g_dev_addr, &addr.val[0], BLE_DEV_ADDR_LEN);
+    }
+
 #ifdef BLE_XCVR_RFCLK
     /* Settling time of crystal, in ticks */
     xtal_ticks = MYNEWT_VAL(BLE_XTAL_SETTLE_TIME);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/95c7d3e5/net/nimble/controller/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/controller/syscfg.yml b/net/nimble/controller/syscfg.yml
index 569010f..fd4f48a 100644
--- a/net/nimble/controller/syscfg.yml
+++ b/net/nimble/controller/syscfg.yml
@@ -203,3 +203,12 @@ syscfg.defs:
             policy feature. Currently, this feature is not supported by the
             nimble controller.
         value: '0'
+
+    BLE_PUBLIC_DEV_ADDR:
+        description: >
+            Allows the target or app to override the public device address
+            used by the controller. If all zero, the controller will
+            attempt to retrieve the public device address from its
+            chip specific location. If non-zero, this address will
+            be used.
+        value: "(uint8_t[6]){0x00, 0x00, 0x00, 0x00, 0x00, 0x00}"