Skip to content

Commit

Permalink
[Silabs] Added code to random address generation using hardware API's. (
Browse files Browse the repository at this point in the history
#31277)

* Added code to random address generation using hardware API's.

* Made changes as per review comments

* Restyled by clang-format

* Made trng key array constant as per comments.

---------

Co-authored-by: Restyled.io <[email protected]>
arun-silabs and restyled-commits authored Jan 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 6ae3e2a commit 548e4f3
Showing 4 changed files with 54 additions and 4 deletions.
24 changes: 24 additions & 0 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c
Original file line number Diff line number Diff line change
@@ -52,6 +52,11 @@
#define ADV_MULTIPROBE 1
#define ADV_SCAN_PERIODICITY 10

#ifdef SIWX_917
#include "sl_si91x_trng.h"
#define TRNGKEY_SIZE 4
#endif // SIWX_917

struct wfx_rsi wfx_rsi;

/* Declare a variable to hold the data associated with the created event group. */
@@ -301,6 +306,25 @@ static sl_status_t wfx_rsi_init(void)
SILABS_LOG("sl_wifi_get_mac_address failed: %x", status);
return status;
}
#ifdef SIWX_917
const uint32_t trngKey[TRNGKEY_SIZE] = { 0x16157E2B, 0xA6D2AE28, 0x8815F7AB, 0x3C4FCF09 };

// To check the Entropy of TRNG and verify TRNG functioning.
status = sl_si91x_trng_entropy();
if (status != SL_STATUS_OK)
{
SILABS_LOG("TRNG Entropy Failed");
return status;
}

// Initiate and program the key required for TRNG hardware engine
status = sl_si91x_trng_program_key(trngKey, TRNGKEY_SIZE);
if (status != SL_STATUS_OK)
{
SILABS_LOG("TRNG Key Programming Failed");
return status;
}
#endif // SIWX_917
wfx_rsi.events = xEventGroupCreateStatic(&rsiDriverEventGroup);
wfx_rsi.dev_state |= WFX_RSI_ST_DEV_READY;
osSemaphoreRelease(sl_rs_ble_init_sem);
28 changes: 24 additions & 4 deletions src/platform/silabs/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
@@ -58,6 +58,12 @@ extern "C" {
#include <platform/DeviceInstanceInfoProvider.h>
#include <string.h>

#ifdef SIWX_917
extern "C" {
#include "sl_si91x_trng.h"
}
#endif // SIWX_917

#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
#include <setup_payload/AdditionalDataPayloadGenerator.h>
#endif
@@ -78,8 +84,23 @@ using namespace ::chip::DeviceLayer::Internal;

void sl_ble_init()
{
uint8_t randomAddrBLE[6] = { 0 };
uint64_t randomAddr = chip::Crypto::GetRandU64();
uint8_t randomAddrBLE[RSI_BLE_ADDR_LENGTH] = { 0 };
#if SIWX_917
sl_status_t sl_status;
//! Get Random number of desired length
sl_status = sl_si91x_trng_get_random_num((uint32_t *) randomAddrBLE, RSI_BLE_ADDR_LENGTH);
if (sl_status != SL_STATUS_OK)
{
ChipLogError(DeviceLayer, " TRNG Random number generation Failed ");
return;
}
// Set the two least significant bits as the first 2 bits of the address has to be '11' to ensure the address is a random
// non-resolvable private address
randomAddrBLE[5] |= 0xC0;
#else
uint64_t randomAddr = chip::Crypto::GetRandU64();
memcpy(randomAddrBLE, &randomAddr, RSI_BLE_ADDR_LENGTH);
#endif // SIWX_917

// registering the GAP callback functions
rsi_ble_gap_register_callbacks(NULL, NULL, rsi_ble_on_disconnect_event, NULL, NULL, NULL, rsi_ble_on_enhance_conn_status_event,
@@ -93,10 +114,9 @@ void sl_ble_init()
// Exchange of GATT info with BLE stack

rsi_ble_add_matter_service();

// initializing the application events map
rsi_ble_app_init_events();
memcpy(randomAddrBLE, &randomAddr, 6);

rsi_ble_set_random_address_with_value(randomAddrBLE);
chip::DeviceLayer::Internal::BLEMgrImpl().HandleBootEvent();
}
1 change: 1 addition & 0 deletions src/platform/silabs/rs911x/rsi_ble_config.h
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@
#define RSI_BLE_DEV_NAME "CCP_DEVICE"
#define RSI_BLE_SET_RAND_ADDR "00:23:A7:12:34:56"
#define RSI_BLE_EVENT_GATT_RD (0x08)
#define RSI_BLE_ADDR_LENGTH 6

#define CLEAR_WHITELIST (0x00)
#define ADD_DEVICE_TO_WHITELIST (0x01)
5 changes: 5 additions & 0 deletions third_party/silabs/SiWx917_sdk.gni
Original file line number Diff line number Diff line change
@@ -57,6 +57,10 @@ template("siwx917_sdk") {
# ble component
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/ble/inc",

# trng component
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/crypto/inc",
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/crypto/trng/inc",

# si91x component
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/ahb_interface/inc",
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/inc",
@@ -337,6 +341,7 @@ template("siwx917_sdk") {
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/ble/src/rsi_common_apis.c",
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/ble/src/rsi_utils.c",
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/ble/src/sl_si91x_ble.c",
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/crypto/trng/src/sl_si91x_trng.c",

# si91x_basic_buffers component
"${wifi_sdk_root}/components/board/silabs/src/rsi_board.c",

0 comments on commit 548e4f3

Please sign in to comment.