Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move random number generation to shim #30

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion nrf70_bm_lib/docs/source/nrf70_bm_porting_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The reference implementation of the BM Driver for the Zephyr RTOS uses build-tim
* - Pseudo-Random Number Generator (PRNG)
- Used to generate random numbers for the nRF70 Series random MAC address generation,
(if random MAC address generation support is enabled).
- NA
- nrf_wifi_osal_rand8_get()
- sys_rand8_get()


Expand Down
2 changes: 1 addition & 1 deletion nrf70_bm_lib/include/nrf70_bm_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <stdarg.h>
#include <string.h>


#include "nrf70_bm_lib.h"
#include <fmac_api.h>

extern struct nrf70_wifi_drv_priv_bm nrf70_bm_priv;
Expand Down
12 changes: 4 additions & 8 deletions nrf70_bm_lib/source/nrf70_bm_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +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"

#include "util.h"
Expand Down Expand Up @@ -508,11 +503,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 +560,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
Loading