From 05c45c1318cb74c3d690d238a42f7408aa80b51a Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Mon, 14 Jan 2019 23:48:48 +0100 Subject: [PATCH] nimble/hw: Remove reading public address fom UICR If public address was not present in FICR there was fallback to try to read this address from UICR. However, how address is stored in UICR is not standarized anywhere so it's just a vendor decision how and where to put it. In worst case this may read some other data from UICR and use them as public address in case vendor is not aware of this behavior. To avoid such problems, let's remove this fallback code. If needed, public address can now be read from virtually anywhere (also UICR) and set using new API: ble_ll_set_public_addr(). This should be done in e.g. BSP code and it's up to vendor. --- nimble/drivers/nrf51/src/ble_hw.c | 30 +++++++----------------------- nimble/drivers/nrf52/src/ble_hw.c | 29 +++++++++-------------------- 2 files changed, 16 insertions(+), 43 deletions(-) diff --git a/nimble/drivers/nrf51/src/ble_hw.c b/nimble/drivers/nrf51/src/ble_hw.c index 61d2dff28..b45cd0233 100644 --- a/nimble/drivers/nrf51/src/ble_hw.c +++ b/nimble/drivers/nrf51/src/ble_hw.c @@ -60,33 +60,17 @@ uint8_t g_nrf_num_irks; 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 ((NRF_FICR->DEVICEADDRTYPE & 1) != 0) { + return -1; } - 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; - } + /* Copy into device address. We can do this because we know platform */ + memcpy(addr->val, &NRF_FICR->DEVICEADDR[0], 4); + memcpy(&addr->val[4], &NRF_FICR->DEVICEADDR[1], 2); + addr->type = BLE_ADDR_PUBLIC; - return rc; + return 0; } /* Returns random static address or -1 if not present */ diff --git a/nimble/drivers/nrf52/src/ble_hw.c b/nimble/drivers/nrf52/src/ble_hw.c index a32e665d5..738f06abb 100644 --- a/nimble/drivers/nrf52/src/ble_hw.c +++ b/nimble/drivers/nrf52/src/ble_hw.c @@ -66,33 +66,22 @@ uint8_t g_nrf_num_irks; 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 ((NRF_FICR->DEVICEADDRTYPE & 1) != 0) { + return -1; } - 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; - } + /* Copy into device address. We can do this because we know platform */ + addr_low = NRF_FICR->DEVICEADDR[0]; + addr_high = NRF_FICR->DEVICEADDR[1]; + memcpy(addr->val, &addr_low, 4); + memcpy(&addr->val[4], &addr_high, 2); + addr->type = BLE_ADDR_PUBLIC; - return rc; + return 0; } /* Returns random static address or -1 if not present */