Skip to content

Commit

Permalink
[Ameba] Location Capability (#25647)
Browse files Browse the repository at this point in the history
* [Config] add location capability

* restyle

* Update src/platform/Ameba/ConfigurationManagerImpl.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/platform/Ameba/ConfigurationManagerImpl.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* restyle

---------

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Sep 21, 2023
1 parent 57772b1 commit 1678738
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/platform/Ameba/AmebaConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const AmebaConfig::Key AmebaConfig::kConfigKey_OperationalDeviceCert = { k
const AmebaConfig::Key AmebaConfig::kConfigKey_OperationalDeviceICACerts = { kConfigNamespace_ChipConfig, "op-device-ca-certs" };
const AmebaConfig::Key AmebaConfig::kConfigKey_OperationalDevicePrivateKey = { kConfigNamespace_ChipConfig, "op-device-key" };
const AmebaConfig::Key AmebaConfig::kConfigKey_RegulatoryLocation = { kConfigNamespace_ChipConfig, "regulatory-location" };
const AmebaConfig::Key AmebaConfig::kConfigKey_LocationCapability = { kConfigNamespace_ChipConfig, "location-capability" };
const AmebaConfig::Key AmebaConfig::kConfigKey_CountryCode = { kConfigNamespace_ChipConfig, "country-code" };

// Keys stored in the Chip-counters namespace
Expand Down
1 change: 1 addition & 0 deletions src/platform/Ameba/AmebaConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class AmebaConfig
static const Key kConfigKey_OperationalDevicePrivateKey;
static const Key kConfigKey_SetupDiscriminator;
static const Key kConfigKey_RegulatoryLocation;
static const Key kConfigKey_LocationCapability;
static const Key kConfigKey_CountryCode;
static const Key kConfigKey_Spake2pIterationCount;
static const Key kConfigKey_Spake2pSalt;
Expand Down
29 changes: 29 additions & 0 deletions src/platform/Ameba/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
SuccessOrExit(err);
}

if (!AmebaConfig::ConfigValueExists(AmebaConfig::kConfigKey_RegulatoryLocation))
{
uint32_t regulatoryLocation = to_underlying(app::Clusters::GeneralCommissioning::RegulatoryLocationType::kIndoor);
err = WriteConfigValue(AmebaConfig::kConfigKey_RegulatoryLocation, regulatoryLocation);
SuccessOrExit(err);
}

if (!AmebaConfig::ConfigValueExists(AmebaConfig::kConfigKey_LocationCapability))
{
uint32_t locationCapability = to_underlying(app::Clusters::GeneralCommissioning::RegulatoryLocationType::kIndoorOutdoor);
err = WriteConfigValue(AmebaConfig::kConfigKey_LocationCapability, locationCapability);
SuccessOrExit(err);
}

// Initialize the generic implementation base class.
err = Internal::GenericConfigurationManagerImpl<AmebaConfig>::Init();
SuccessOrExit(err);
Expand Down Expand Up @@ -119,6 +133,21 @@ CHIP_ERROR ConfigurationManagerImpl::StoreBootReason(uint32_t bootReason)
return WriteConfigValue(AmebaConfig::kCounterKey_BootReason, bootReason);
}

CHIP_ERROR ConfigurationManagerImpl::GetLocationCapability(uint8_t & location)
{
uint32_t value = 0;

CHIP_ERROR err = ReadConfigValue(AmebaConfig::kConfigKey_LocationCapability, value);

if (err == CHIP_NO_ERROR)
{
VerifyOrReturnError(value <= UINT8_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE);
location = static_cast<uint8_t>(value);
}

return err;
}

CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)
{
char temp[32];
Expand Down
1 change: 1 addition & 0 deletions src/platform/Ameba/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override;
CHIP_ERROR GetBootReason(uint32_t & bootReason) override;
CHIP_ERROR StoreBootReason(uint32_t bootReason) override;
CHIP_ERROR GetLocationCapability(uint8_t & locationCapability) override;

private:
// ===== Members that implement the ConfigurationManager public interface.
Expand Down

0 comments on commit 1678738

Please sign in to comment.