summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarles Cufi <carles.cufi@nordicsemi.no>2017-01-30 11:24:48 +0100
committerJohan Hedberg <johan.hedberg@intel.com>2017-01-31 06:19:54 +0000
commitbc3f75513b0718665c92eae16006cbe58a54fbf4 (patch)
tree3d01fe126f26998b5d79223bc16b9d7f68d3a45d
parent11d09daf29ae46d0a42fc863b3f89e9a24edcec1 (diff)
Bluetooth: hci_core: Use nRF5x FICR addressbluetooth
The nRF5x come preprogrammed from manufacturing with either a public or random static BLE address in the FICR register. Use the random static one when present instead of generating one during Bluetooth initialization. Change-id: Ic733cb926e0414e56d6f8be65b033692e914b72a Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
-rw-r--r--subsys/bluetooth/host/hci_core.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c
index f3e93b1b1..24c7e31e7 100644
--- a/subsys/bluetooth/host/hci_core.c
+++ b/subsys/bluetooth/host/hci_core.c
@@ -14,6 +14,7 @@
#include <misc/util.h>
#include <misc/byteorder.h>
#include <misc/stack.h>
+#include <soc.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLUETOOTH_DEBUG_HCI_CORE)
#include <bluetooth/log.h>
@@ -3285,6 +3286,29 @@ static int set_static_addr(void)
}
}
+#if defined(CONFIG_SOC_FAMILY_NRF5)
+ /* Read address from nRF5-specific storage
+ * Non-initialized FICR values default to 0xFF, skip if no address
+ * present. Also if a public address lives in FICR, do not use in this
+ * function.
+ */
+ if (((NRF_FICR->DEVICEADDR[0] != UINT32_MAX) ||
+ ((NRF_FICR->DEVICEADDR[1] & UINT16_MAX) != UINT16_MAX)) &&
+ (NRF_FICR->DEVICEADDRTYPE & 0x01)) {
+
+ bt_dev.id_addr.type = BT_ADDR_LE_RANDOM;
+ sys_put_le32(NRF_FICR->DEVICEADDR[0], &bt_dev.id_addr.a.val[0]);
+ sys_put_le16(NRF_FICR->DEVICEADDR[1], &bt_dev.id_addr.a.val[4]);
+ /* The FICR value is a just a random number, with no knowledge
+ * of the Bluetooth Specification requirements for random
+ * static addresses.
+ */
+ BT_ADDR_SET_STATIC(&bt_dev.id_addr.a);
+
+ goto set_addr;
+ }
+#endif /* CONFIG_SOC_FAMILY_NRF5 */
+
BT_DBG("Generating new static random address");
err = bt_addr_le_create_static(&bt_dev.id_addr);