Skip to content

Commit

Permalink
Added code to random address generation using hardware API's.
Browse files Browse the repository at this point in the history
  • Loading branch information
arun-silabs committed Jan 8, 2024
1 parent 7381d76 commit 2015519
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
22 changes: 22 additions & 0 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

struct wfx_rsi wfx_rsi;

/* Declare a variable to hold the data associated with the created event group. */
Expand Down Expand Up @@ -301,6 +306,23 @@ static sl_status_t wfx_rsi_init(void)
SILABS_LOG("sl_wifi_get_mac_address failed: %x", status);
return status;
}
#ifdef SIWX_917
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, 4);
if (status != SL_STATUS_OK) {
SILABS_LOG("TRNG Key Programming Failed");
return status;
}
#endif
wfx_rsi.events = xEventGroupCreateStatic(&rsiDriverEventGroup);
wfx_rsi.dev_state |= WFX_RSI_ST_DEV_READY;
osSemaphoreRelease(sl_rs_ble_init_sem);
Expand Down
24 changes: 21 additions & 3 deletions src/platform/silabs/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ extern "C" {
#include <platform/DeviceInstanceInfoProvider.h>
#include <string.h>

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

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

void sl_ble_init()
{
uint8_t randomAddrBLE[6] = { 0 };
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 ;
}
#else
uint64_t randomAddr = chip::Crypto::GetRandU64();
memcpy(randomAddrBLE, &randomAddr, RSI_BLE_ADDR_LENGTH);
#endif

// 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,
Expand All @@ -93,10 +110,11 @@ void sl_ble_init()
// Exchange of GATT info with BLE stack

rsi_ble_add_matter_service();

// 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;
// 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();
}
Expand Down
1 change: 1 addition & 0 deletions src/platform/silabs/rs911x/rsi_ble_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions third_party/silabs/SiWx917_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 2015519

Please sign in to comment.