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

Improve UpdateConfig command #1586

Merged
merged 1 commit into from
Mar 12, 2020
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
2 changes: 1 addition & 1 deletion src/CLR/Debugger/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ bool CLR_DBG_Debugger::Monitor_UpdateConfiguration(WP_Message* message)
case DeviceConfigurationOption_Wireless80211Network:
case DeviceConfigurationOption_X509CaRootBundle:
case DeviceConfigurationOption_All:
if(ConfigurationManager_StoreConfigurationBlock(cmd->Data, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex, cmd->Length, cmd->Offset) == true)
if(ConfigurationManager_StoreConfigurationBlock(cmd->Data, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex, cmd->Length, cmd->Offset, cmd->Done) == true)
{
cmdReply.ErrorCode = 0;
success = true;
Expand Down
4 changes: 3 additions & 1 deletion src/CLR/Include/WireProtocol_MonitorCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "WireProtocol.h"
#include "WireProtocol_Message.h"
#include <nanoPackStruct.h>

//////////////////////////////////////////
// enums
Expand Down Expand Up @@ -156,12 +157,13 @@ typedef struct Monitor_QueryConfiguration_Command

}Monitor_QueryConfiguration_Command;

typedef struct Monitor_UpdateConfiguration_Command
typedef struct __nfpack Monitor_UpdateConfiguration_Command
{
uint32_t Configuration;
uint32_t BlockIndex;
uint32_t Length;
uint32_t Offset;
uint32_t Done;
uint8_t Data[1];

}Monitor_UpdateConfiguration_Command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ HRESULT Library_sys_net_native_System_Net_Security_CertificateManager::AddCaCert
if(g_TargetConfiguration.CertificateStore->Count == 0)
{
// not found, add the certificate bundle
if(ConfigurationManager_StoreConfigurationBlock(certificateBinary, DeviceConfigurationOption_X509CaRootBundle, configIndex, certificateSize, 0) != TRUE)
if(ConfigurationManager_StoreConfigurationBlock(certificateBinary, DeviceConfigurationOption_X509CaRootBundle, configIndex, certificateSize, 0, false) != TRUE)
{
NANOCLR_SET_AND_LEAVE(CLR_E_FAIL);
}
Expand Down
2 changes: 1 addition & 1 deletion src/HAL/Include/nanoHAL_ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bool ConfigurationManager_GetConfigurationBlock(void* configurationBlock, Device

// StoreConfigurationBlock() is defined in targetHAL_ConfigurationManager.cpp at target level because the target
// needs to be free to implement the storage of the configuration block as they see fit
bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset);
bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset, bool done);

// UpdateConfigurationBlock() is defined in targetHAL_ConfigurationManager.cpp at target level because the target
// needs to be free to implement the storage of the configuration block as they see fit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ __nfweak void ConfigurationManager_EnumerateConfigurationBlocks()
if(InitialiseNetworkDefaultConfig(networkConfig, 0))
{
// config block created, store it
ConfigurationManager_StoreConfigurationBlock(networkConfig, DeviceConfigurationOption_Network, 0, sizeof(HAL_Configuration_NetworkInterface), 0);
ConfigurationManager_StoreConfigurationBlock(networkConfig, DeviceConfigurationOption_Network, 0, sizeof(HAL_Configuration_NetworkInterface), 0, false);

// have to enumerate again to pick it up
networkConfigs = (HAL_CONFIGURATION_NETWORK*)ConfigurationManager_FindNetworkConfigurationBlocks((uint32_t)&__nanoConfig_start__, (uint32_t)&__nanoConfig_end__);
Expand Down Expand Up @@ -146,7 +146,7 @@ __nfweak bool ConfigurationManager_GetConfigurationBlock(void* configurationBloc
// NOTE: because inserting or removing a configuration block it's very 'RAM expensive' we choose not to support those operations
// the host debugger will have to be used to manage these operations on the device configuration collection
// it's implemented with 'weak' attribute so it can be replaced at target level if a different persistance mechanism is used
__nfweak bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset)
__nfweak bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset, bool done)
{
ByteAddress storageAddress = 0;
bool requiresEnumeration = FALSE;
Expand Down Expand Up @@ -233,9 +233,6 @@ __nfweak bool ConfigurationManager_StoreConfigurationBlock(void* configurationBl
// set storage address as the start of the flash configuration sector, plus the requested offset
storageAddress = (ByteAddress)&__nanoConfig_start__ + offset;

// always enumerate the blocks again after storing it
requiresEnumeration = TRUE;

// for save all the block size has to be provided, check that
if(blockSize == 0)
{
Expand All @@ -246,7 +243,10 @@ __nfweak bool ConfigurationManager_StoreConfigurationBlock(void* configurationBl
// copy the config block content to the config block storage
success = STM32FlashDriver_Write(NULL, storageAddress, blockSize, (unsigned char*)configurationBlock, true);

if(success == TRUE && requiresEnumeration)
// enumeration is required after we are DONE with SUCCESSFULLY storing all the config chunks
requiresEnumeration = (success && done);

if(requiresEnumeration)
{
// free the current allocation(s)
platform_free(g_TargetConfiguration.NetworkInterfaceConfigs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ int Monitor_UpdateConfiguration(WP_Message* message)
case DeviceConfigurationOption_Wireless80211Network:
case DeviceConfigurationOption_X509CaRootBundle:
case DeviceConfigurationOption_All:
if(ConfigurationManager_StoreConfigurationBlock(cmd->Data, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex, cmd->Length, cmd->Offset) == true)
if(ConfigurationManager_StoreConfigurationBlock(cmd->Data, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex, cmd->Length, cmd->Offset, cmd->Done) == true)
{
cmdReply.ErrorCode = 0;
success = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ bool ConfigurationManager_GetConfigurationBlock(void* configurationBlock, Device
// Stores the configuration block to the configuration flash sector
// NOTE: because inserting or removing a configuration block it's very 'RAM expensive' we choose not to support those operations
// the host debugger will have to be used to manage these operations on the device configuration collection
bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset)
bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset, bool done)
{
ByteAddress storageAddress = 0;
bool requiresEnumeration = FALSE;
Expand Down Expand Up @@ -216,7 +216,10 @@ bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, Devi
// copy the config block content to the config block storage
success = iMXRTFlexSPIDriver_Write(NULL, storageAddress, blockSize, (unsigned char*)configurationBlock, false);

if(success == TRUE && requiresEnumeration)
// enumeration is required after we are DONE with SUCCESSFULLY storing all the config chunks
requiresEnumeration = (success && done);

if(requiresEnumeration)
{
// free the current allocation(s)
platform_free(g_TargetConfiguration.NetworkInterfaceConfigs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ bool ConfigurationManager_StoreConfigurationBlockAll(void* configurationBlock, u
// true - OK
// false- Error/Not found
//
bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset)
bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset, bool done)
{
bool result = false;
bool requiresEnumeration = false;
Expand All @@ -662,38 +662,45 @@ bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, Devi
#endif

if (configuration == DeviceConfigurationOption_All)
return ConfigurationManager_StoreConfigurationBlockAll(configurationBlock, blockSize, offset);

if (configuration == DeviceConfigurationOption_Network)
{
// set blob size
blobSize = sizeof(HAL_Configuration_NetworkInterface);
}
else if (configuration == DeviceConfigurationOption_Wireless80211Network)
{
// set blob size
blobSize = sizeof(HAL_Configuration_Wireless80211);
}
else if (configuration == DeviceConfigurationOption_WirelessNetworkAP)
{
// set blob size
blobSize = sizeof(HAL_Configuration_WirelessAP);
}
else if (configuration == DeviceConfigurationOption_X509CaRootBundle)
{
// set blob size ( Total size of X509 certificate )
// because X509 certificate has a variable length need to compute the block size in two steps
blobSize = offsetof(HAL_Configuration_X509CaRootBundle, Certificate);
blobSize += ((HAL_Configuration_X509CaRootBundle*)configurationBlock)->CertificateSize;
result = ConfigurationManager_StoreConfigurationBlockAll(configurationBlock, blockSize, offset);

#ifdef DEBUG_CONFIG
ets_printf("StoreConfig x509 blobSize:%d, certsize:%d", blobSize, ((HAL_Configuration_X509CaRootBundle*)configurationBlock)->CertificateSize);
#endif
// enumeration is required after we are DONE with SUCCESSFULLY storing all the config chunks
requiresEnumeration = (result && done);
}
else
{
// Invalid Config
return false;
if (configuration == DeviceConfigurationOption_Network)
{
// set blob size
blobSize = sizeof(HAL_Configuration_NetworkInterface);
}
else if (configuration == DeviceConfigurationOption_Wireless80211Network)
{
// set blob size
blobSize = sizeof(HAL_Configuration_Wireless80211);
}
else if (configuration == DeviceConfigurationOption_WirelessNetworkAP)
{
// set blob size
blobSize = sizeof(HAL_Configuration_WirelessAP);
}
else if (configuration == DeviceConfigurationOption_X509CaRootBundle)
{
// set blob size ( Total size of X509 certificate )
// because X509 certificate has a variable length need to compute the block size in two steps
blobSize = offsetof(HAL_Configuration_X509CaRootBundle, Certificate);
blobSize += ((HAL_Configuration_X509CaRootBundle*)configurationBlock)->CertificateSize;

#ifdef DEBUG_CONFIG
ets_printf("StoreConfig x509 blobSize:%d, certsize:%d", blobSize, ((HAL_Configuration_X509CaRootBundle*)configurationBlock)->CertificateSize);
#endif
}
else
{
// Invalid Config
return false;
}
}

// Anything to save
Expand Down Expand Up @@ -745,5 +752,5 @@ bool ConfigurationManager_UpdateConfigurationBlock(void* configurationBlock, Dev
return FALSE;
}

return ConfigurationManager_StoreConfigurationBlock(configurationBlock, configuration, configurationIndex, blockSize, 0);
return ConfigurationManager_StoreConfigurationBlock(configurationBlock, configuration, configurationIndex, blockSize, 0, false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void ConfigurationManager_EnumerateConfigurationBlocks()
if(InitialiseNetworkDefaultConfig(networkConfig, 0))
{
// config block created, store it
ConfigurationManager_StoreConfigurationBlock(networkConfig, DeviceConfigurationOption_Network, 0, sizeof(HAL_Configuration_NetworkInterface), 0);
ConfigurationManager_StoreConfigurationBlock(networkConfig, DeviceConfigurationOption_Network, 0, sizeof(HAL_Configuration_NetworkInterface), 0, false);

// have to enumerate again to pick it up
networkConfigs = (HAL_CONFIGURATION_NETWORK*)ConfigurationManagerCC13x2_26x2_FindNetworkConfigurationBlocks();
Expand Down Expand Up @@ -359,8 +359,11 @@ uint8_t GetSecurityType(AuthenticationType authentication)
}

// Stores the configuration block to the file system
bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset)
bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset, bool done)
{
// this platform doesn't need to handle this
(void)done;

bool requiresEnumeration = false;
bool success = false;

Expand Down Expand Up @@ -470,7 +473,7 @@ bool ConfigurationManager_UpdateConfigurationBlock(void* configurationBlock, Dev
{
case DeviceConfigurationOption_Network:
case DeviceConfigurationOption_Wireless80211Network:
return ConfigurationManager_StoreConfigurationBlock(configurationBlock, configuration, configurationIndex, 0, 0);
return ConfigurationManager_StoreConfigurationBlock(configurationBlock, configuration, configurationIndex, 0, 0, false);

// this configuration option is not supported
case DeviceConfigurationOption_X509CaRootBundle:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void ConfigurationManager_EnumerateConfigurationBlocks()
if(InitialiseNetworkDefaultConfig(networkConfig, 0))
{
// config block created, store it
ConfigurationManager_StoreConfigurationBlock(networkConfig, DeviceConfigurationOption_Network, 0, sizeof(HAL_Configuration_NetworkInterface), 0);
ConfigurationManager_StoreConfigurationBlock(networkConfig, DeviceConfigurationOption_Network, 0, sizeof(HAL_Configuration_NetworkInterface), 0, false);

// have to enumerate again to pick it up
networkConfigs = (HAL_CONFIGURATION_NETWORK*)ConfigurationManagerCC32xx_FindNetworkConfigurationBlocks();
Expand Down Expand Up @@ -359,8 +359,11 @@ uint8_t GetSecurityType(AuthenticationType authentication)
}

// Stores the configuration block to the file system
bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset)
bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset, bool done)
{
// this platform doesn't need to handle this
(void)done;

bool requiresEnumeration = false;
bool success = false;

Expand Down Expand Up @@ -470,7 +473,7 @@ bool ConfigurationManager_UpdateConfigurationBlock(void* configurationBlock, Dev
{
case DeviceConfigurationOption_Network:
case DeviceConfigurationOption_Wireless80211Network:
return ConfigurationManager_StoreConfigurationBlock(configurationBlock, configuration, configurationIndex, 0, 0);
return ConfigurationManager_StoreConfigurationBlock(configurationBlock, configuration, configurationIndex, 0, 0, false);

// this configuration option is not supported
case DeviceConfigurationOption_X509CaRootBundle:
Expand Down
2 changes: 1 addition & 1 deletion targets/os/win32/nanoCLR/Various.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool ConfigurationManager_GetConfigurationBlock(void* configurationBlock, Device
return true;
}

bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize)
bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, bool done)
{
return true;
}
Expand Down