Skip to content

Commit

Permalink
Move random number generation to shim
Browse files Browse the repository at this point in the history
Remove any Zephyr references in the BM code.

Signed-off-by: Chaitanya Tata <[email protected]>
  • Loading branch information
krish2718 committed Dec 11, 2024
1 parent 6a5a517 commit f02c059
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion nrf70_bm_lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ config NRF70_FIXED_MAC_ADDRESS_ENABLED

config NRF70_RANDOM_MAC_ADDRESS
bool "Random MAC address generation at runtime"
select TEST_RANDOM_GENERATOR
help
This option enables random MAC address generation at runtime.
The random MAC address is generated using the libc srand() function.
Expand Down
11 changes: 4 additions & 7 deletions nrf70_bm_lib/source/nrf70_bm_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
/** @file
* @brief nRF70 Bare Metal initialization.
*/
#ifdef CONFIG_NRF70_RANDOM_MAC_ADDRESS
#include <zephyr/random/random.h>
#endif /* CONFIG_NRF70_RANDOM_MAC_ADDRESS */

#include "nrf70_bm_lib.h"
#include "nrf70_bm_core.h"

Expand Down Expand Up @@ -508,11 +504,12 @@ int nrf70_fmac_init(void)
}

#ifdef CONFIG_NRF70_RANDOM_MAC_ADDRESS
static void generate_random_mac_address(uint8_t *mac_addr)
static void generate_random_mac_address(void *opriv,
uint8_t *mac_addr)
{
// For simplicty use Zephyr API to generate random number
for (int i = 0; i < 6; i++) {
mac_addr[i] = sys_rand8_get();
mac_addr[i] = nrf_wifi_osal_rand8_get(opriv);
}

// Set the locally administered bit (bit 1 of the first byte)
Expand Down Expand Up @@ -564,7 +561,7 @@ enum nrf_wifi_status nrf_wifi_get_mac_addr(struct nrf70_wifi_vif_bm *vif,

memcpy(vif->mac_addr, fixed_mac_addr, NR70_MAC_ADDR_LEN);
#elif CONFIG_NRF70_RANDOM_MAC_ADDRESS
generate_random_mac_address(vif->mac_addr);
generate_random_mac_address(nrf70_bm_priv.fmac_priv->opriv, vif->mac_addr);
#elif CONFIG_NRF70_OTP_MAC_ADDRESS
status = nrf_wifi_fmac_otp_mac_addr_get(rpu_ctx,
vif->vif_idx,
Expand Down
2 changes: 2 additions & 0 deletions nrf70_zephyr_shim/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ DT_COMPAT_NORDIC_NRF700X_SPI := nordic,nrf700x-spi
menuconfig NRF70_ZEPHYR_SHIM
bool "Enable nRF70 Zephyr shim"
default y if NRF70_BM_LIB
# For Random MAC address generation
select TEST_RANDOM_GENERATOR
help
Enable the nRF70 Zephyr shim.

Expand Down
2 changes: 2 additions & 0 deletions nrf70_zephyr_shim/source/os/shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/logging/log.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/random/random.h>

#include "rpu_hw_if.h"
#include "shim.h"
Expand Down Expand Up @@ -972,6 +973,7 @@ static const struct nrf_wifi_osal_ops nrf_wifi_os_zep_ops = {

.assert = zep_shim_assert,
.strlen = zep_shim_strlen,
.rand8_get = sys_rand8_get,
};

const struct nrf_wifi_osal_ops *get_os_ops(void)
Expand Down

0 comments on commit f02c059

Please sign in to comment.