Skip to content

Commit

Permalink
WIP: Enable by default
Browse files Browse the repository at this point in the history
  • Loading branch information
LuDuda committed Feb 9, 2025
1 parent 8fc74fc commit 9bad859
Show file tree
Hide file tree
Showing 20 changed files with 1,475 additions and 9 deletions.
2 changes: 1 addition & 1 deletion etc/cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ ot_int_option(OT_RCP_TX_WAIT_TIME_SECS OPENTHREAD_SPINEL_CONFIG_RCP_TX_WAIT_TIME
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

if(NOT OT_EXTERNAL_MBEDTLS)
set(OT_MBEDTLS mbedtls)
set(OT_MBEDTLS mbedtls mbedcrypto)
target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS=1")
else()
set(OT_MBEDTLS ${OT_EXTERNAL_MBEDTLS})
Expand Down
2 changes: 1 addition & 1 deletion examples/apps/cli/ftd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ target_link_libraries(ot-cli-ftd PRIVATE
openthread-cli-ftd
${OT_PLATFORM_LIB_FTD}
openthread-ftd
${OT_PLATFORM_LIB_FTD}
openthread-cli-ftd
${OT_MBEDTLS}
${OT_PLATFORM_LIB_FTD}
ot-config-ftd
ot-config
)
Expand Down
2 changes: 1 addition & 1 deletion examples/apps/cli/mtd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ target_link_libraries(ot-cli-mtd PRIVATE
openthread-cli-mtd
${OT_PLATFORM_LIB_MTD}
openthread-mtd
${OT_PLATFORM_LIB_MTD}
openthread-cli-mtd
${OT_MBEDTLS}
${OT_PLATFORM_LIB_MTD}
ot-config-mtd
ot-config
)
Expand Down
2 changes: 1 addition & 1 deletion examples/apps/ncp/ftd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ target_link_libraries(ot-ncp-ftd PRIVATE
openthread-ncp-ftd
${OT_PLATFORM_LIB_FTD}
openthread-ftd
${OT_PLATFORM_LIB_FTD}
openthread-ncp-ftd
${OT_MBEDTLS}
${OT_PLATFORM_LIB_FTD}
ot-config-ftd
ot-config
)
Expand Down
2 changes: 1 addition & 1 deletion examples/apps/ncp/mtd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ target_link_libraries(ot-ncp-mtd PRIVATE
openthread-ncp-mtd
${OT_PLATFORM_LIB_MTD}
openthread-mtd
${OT_PLATFORM_LIB_MTD}
openthread-ncp-mtd
${OT_MBEDTLS}
${OT_PLATFORM_LIB_MTD}
ot-config-mtd
ot-config
)
Expand Down
3 changes: 2 additions & 1 deletion examples/platforms/simulation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ endif()

target_link_libraries(openthread-simulation PRIVATE
openthread-platform
mbedtls
openthread-native-its-file
ot-simulation-config
ot-config
mbedtls
)

target_compile_options(openthread-simulation PRIVATE
Expand Down
11 changes: 11 additions & 0 deletions examples/platforms/simulation/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ extern otRadioCaps gRadioCaps;

static volatile bool gTerminate = false;

#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE
static char sNativeItsFileName[256];
extern const char *gItsFileNamePrefix;
#endif

static void handleSignal(int aSignal)
{
OT_UNUSED_VARIABLE(aSignal);
Expand Down Expand Up @@ -194,6 +199,12 @@ void otSysInit(int aArgCount, char *aArgVector[])
signal(SIGTERM, &handleSignal);
signal(SIGHUP, &handleSignal);

#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE
snprintf(sNativeItsFileName, sizeof(sNativeItsFileName), "%s/%s_%d_", OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH,
getenv("PORT_OFFSET") ? getenv("PORT_OFFSET") : "0", gNodeId);
gItsFileNamePrefix = sNativeItsFileName;
#endif

platformLoggingInit(basename(aArgVector[0]));
platformAlarmInit(speedUpFactor);
platformRadioInit();
Expand Down
16 changes: 16 additions & 0 deletions src/posix/platform/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
otInstance *gInstance = nullptr;
bool gDryRun = false;

#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE
static char sNativeItsFileName[256];
extern const char *gItsFileNamePrefix;
#endif

CoprocessorType sCoprocessorType = OT_COPROCESSOR_UNKNOWN;

static void processStateChange(otChangedFlags aFlags, void *aContext)
Expand Down Expand Up @@ -206,6 +211,17 @@ void platformInit(otPlatformConfig *aPlatformConfig)
break;
}

#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE
uint64_t nodeId;

otPlatRadioGetIeeeEui64(aInstance, reinterpret_cast<uint8_t *>(&nodeId));
nodeId = ot::BigEndian::HostSwap64(nodeId);

snprintf(sNativeItsFileName, sizeof(sNativeItsFileName), "%s/%s_%d_", OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH,
getenv("PORT_OFFSET"), nodeId);
gItsFileNamePrefix = sNativeItsFileName;
#endif

aPlatformConfig->mCoprocessorType = sCoprocessorType;
}

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ set(COMMON_LIBS
ot-test-platform-ftd
openthread-ftd
ot-test-platform-ftd
${OT_MBEDTLS}
ot-config
openthread-ftd
openthread-url
${OT_MBEDTLS}
openthread-native-its-ram
)

set(COMMON_LIBS_RCP
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/test_dns_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ void TestDnsClient(void)
Dns::ServiceDiscovery::Server::Counters oldServerCounters;
Dns::ServiceDiscovery::Server::Counters newServerCounters;
uint16_t heapAllocations;
uint32_t iter = 0;

Log("--------------------------------------------------------------------------------------------");
Log("TestDnsClient");
Expand Down Expand Up @@ -542,6 +543,8 @@ void TestDnsClient(void)
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Start SRP server.

Log("#################### HEAP ALLOCATIONS = %d [%d]", sHeapAllocatedPtrs.GetLength(), iter++);

SuccessOrQuit(srpServer->SetAddressMode(Srp::Server::kAddressModeUnicast));
VerifyOrQuit(srpServer->GetState() == Srp::Server::kStateDisabled);

Expand All @@ -554,6 +557,9 @@ void TestDnsClient(void)
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Start SRP client.

Log("#################### HEAP ALLOCATIONS = %d [%d]", sHeapAllocatedPtrs.GetLength(), iter++);


srpClient->EnableAutoStartMode(nullptr, nullptr);
VerifyOrQuit(srpClient->IsAutoStartModeEnabled());

Expand Down Expand Up @@ -586,6 +592,9 @@ void TestDnsClient(void)
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Validate DNS Client `Browse()`

Log("#################### HEAP ALLOCATIONS = %d [%d]", sHeapAllocatedPtrs.GetLength(), iter++);


sBrowseInfo.Reset();
Log("Browse(%s)", kService1FullName);
SuccessOrQuit(dnsClient->Browse(kService1FullName, BrowseCallback, sInstance));
Expand Down Expand Up @@ -628,6 +637,9 @@ void TestDnsClient(void)
AdvanceTime(100);
VerifyOrQuit(sBrowseInfo.mCallbackCount == 4);

Log("#################### HEAP ALLOCATIONS = %d [%d]", sHeapAllocatedPtrs.GetLength(), iter++);


//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Validate DNS Client `ResolveService()` using all service modes

Expand Down Expand Up @@ -754,6 +766,9 @@ void TestDnsClient(void)
// Validate DNS Client `ResolveService()` using all service modes
// when sever does not provide any RR in the addition data section.

Log("#################### HEAP ALLOCATIONS = %d [%d]", sHeapAllocatedPtrs.GetLength(), iter++);


for (Dns::Client::QueryConfig::ServiceMode mode : kServiceModes)
{
Log("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
Expand Down Expand Up @@ -796,6 +811,9 @@ void TestDnsClient(void)

dnsServer->SetTestMode(Dns::ServiceDiscovery::Server::kTestModeDisabled);

Log("#################### HEAP ALLOCATIONS = %d [%d]", sHeapAllocatedPtrs.GetLength(), iter++);


//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Validate DNS Client `ResolveServiceAndHostAddress()` using all service modes
// with different TestMode configs on server:
Expand Down Expand Up @@ -873,6 +891,9 @@ void TestDnsClient(void)

dnsServer->SetTestMode(Dns::ServiceDiscovery::Server::kTestModeDisabled);

Log("#################### HEAP ALLOCATIONS = %d [%d]", sHeapAllocatedPtrs.GetLength(), iter++);


Log("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
Log("Set TestMode on server to not include any RR in additional section AND to only accept single question");
dnsServer->SetTestMode(Dns::ServiceDiscovery::Server::kTestModeEmptyAdditionalSection +
Expand Down Expand Up @@ -937,6 +958,9 @@ void TestDnsClient(void)
sResolveServiceInfo.Reset();
SuccessOrQuit(dnsClient->ResolveService(kInstance1Label, kService1FullName, ServiceCallback, sInstance, nullptr));

Log("#################### HEAP ALLOCATIONS = %d [%d]", sHeapAllocatedPtrs.GetLength(), iter++);


AdvanceTime(100);

VerifyOrQuit(sResolveServiceInfo.mCallbackCount == 1);
Expand Down Expand Up @@ -989,9 +1013,13 @@ void TestDnsClient(void)

Log("Disabling SRP server");

Log("#################### HEAP ALLOCATIONS = %d [%d]", sHeapAllocatedPtrs.GetLength(), iter++);

srpServer->SetEnabled(false);
AdvanceTime(100);

Log("#################### heapAllocations= %d sHeapAllocatedPtrs.GetLength() = %d", heapAllocations, sHeapAllocatedPtrs.GetLength());

VerifyOrQuit(heapAllocations == sHeapAllocatedPtrs.GetLength());

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
1 change: 1 addition & 0 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

if(NOT OT_EXTERNAL_MBEDTLS)
add_subdirectory(mbedtls)
add_subdirectory(mbedtls/native_its)
endif()

add_subdirectory(tcplp)
1 change: 1 addition & 0 deletions third_party/mbedtls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,5 @@ target_include_directories(mbedcrypto
PRIVATE
${OT_PUBLIC_INCLUDES}
$<TARGET_PROPERTY:ot-config,INTERFACE_INCLUDE_DIRECTORIES>
native_its/include
)
4 changes: 2 additions & 2 deletions third_party/mbedtls/mbedtls-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
#define MBEDTLS_PSA_CRYPTO_CONFIG

// Temporary for ITS..
#define MBEDTLS_PSA_ITS_FILE_C
#define MBEDTLS_FS_IO
// #define MBEDTLS_PSA_ITS_FILE_C
// #define MBEDTLS_FS_IO

#define MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG

Expand Down
Loading

0 comments on commit 9bad859

Please sign in to comment.