Nordic softdevice provides APIS regarding BLE and MAC address on nRF51 and 52. (function calls may be slightly different depending on the softdevice version).
1. Get BLE MAC Address
sd_ble_gap_address_get((*ble_gapp_addr_t))
2. Change MAC Address
There are two ways; one is randomised mac, another is change as given address.
(ble_gapp_addr_t).addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE // Random
sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_AUTO,(*ble_gapp_addr_t));
// OR
(ble_gapp_addr_t).addr_type = BLE_GAP_ADDR_TYPE_PUBLIC // Fixed
sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE,(*ble_gapp_addr_t));
3. How to check factory BLE address and H/W Serial No. using Segger and nrfjprog(nRFgo Studio)
MAC Address
./nrfjprog --memrd 0x100000a4 --n 8 --family nrf52
H/W Serial No.
./nrfjprog --memrd 0x1000005c --n 8 --family nrf52
ref :
https://devzone.nordicsemi.com/question/49876/switching-between-random-and-normal-mac-address/
https://devzone.nordicsemi.com/question/43047/sd_ble_gap_address_set-works-for-normal-mode-only/