blob: 3a48ae63a66fc28949c4ad53207839a1a7b1f946 [file]
/*
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* Provides an implementation of the ConfigurationManager object
* for Darwin platforms.
*/
#pragma once
#include <platform/internal/GenericConfigurationManagerImpl.h>
#include <platform/Darwin/PosixConfig.h>
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
#include <platform/Darwin/WiFi/WiFiNetworkInfos.h>
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
namespace chip {
namespace DeviceLayer {
inline constexpr int kCountryCodeLength = 2;
/**
* Concrete implementation of the ConfigurationManager singleton object for the Darwin platform.
*/
class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl<Internal::PosixConfig>
{
public:
/**
* General-purpose callback for providing configuration values at runtime.
* Mirrors Android's ConfigurationManager.readConfigValueStr(namespace, name).
*
* @param configNamespace The config namespace (e.g. "chip-factory")
* @param name The config key name (e.g. "device-name")
* @param buf Buffer to write the null-terminated value into
* @param bufSize Size of the buffer
* @param outLen Set to the length of the value written (excluding null terminator)
* @return CHIP_NO_ERROR if a value was provided,
* CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND to fall through to the next source
*/
using ConfigValueProvider = CHIP_ERROR (*)(const char * configNamespace, const char * name, char * buf, size_t bufSize,
size_t & outLen);
CHIP_ERROR StoreVendorId(uint16_t vendorId);
CHIP_ERROR StoreProductId(uint16_t productId);
CHIP_ERROR GetCommissionableDeviceName(char * buf, size_t bufSize) override;
/**
* Set a general-purpose config value provider that is consulted at runtime
* before PosixConfig or compile-time defaults. Analogous to Android's
* PreferencesConfigurationManager.readConfigValueStr().
*/
void SetConfigValueProvider(ConfigValueProvider provider) { mConfigValueProvider = provider; }
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
CHIP_ERROR GetWiFiNetworkInformations(WiFiNetworkInfos & infos);
CHIP_ERROR StoreWiFiNetworkInformations(WiFiNetworkInfos & infos);
CHIP_ERROR ClearWiFiNetworkInformations();
bool HasWiFiNetworkInformations();
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
// This returns an instance of this class.
static ConfigurationManagerImpl & GetDefaultInstance();
private:
// ===== Members that implement the ConfigurationManager public interface.
CHIP_ERROR Init(void) override;
CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) override;
bool CanFactoryReset(void) override;
void InitiateFactoryReset(void) override;
CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override;
CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override;
CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override;
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override;
CHIP_ERROR GetBootReason(uint32_t & bootReason) override;
CHIP_ERROR StoreBootReason(uint32_t bootReason) override;
CHIP_ERROR GetRegulatoryLocation(uint8_t & location) override;
CHIP_ERROR GetLocationCapability(uint8_t & location) override;
CHIP_ERROR GetConfigurationVersion(uint32_t & configurationVersion) override;
CHIP_ERROR StoreConfigurationVersion(uint32_t configurationVersion) override;
CHIP_ERROR ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) override;
CHIP_ERROR WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) override;
// NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>.
CHIP_ERROR WriteConfigValue(Key key, uint16_t val);
CHIP_ERROR ReadConfigValue(Key key, uint16_t & val);
ConfigValueProvider mConfigValueProvider = nullptr;
// ===== Members that implement the GenericConfigurationManagerImpl protected interface.
CHIP_ERROR ReadConfigValue(Key key, bool & val) override;
CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override;
CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override;
CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override;
CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override;
CHIP_ERROR WriteConfigValue(Key key, bool val) override;
CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override;
CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override;
CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override;
CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override;
CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override;
void RunConfigUnitTest(void) override;
};
/**
* Returns the platform-specific implementation of the ConfigurationManager object.
*
* Applications can use this to gain access to features of the ConfigurationManager
* that are specific to the selected platform.
*/
ConfigurationManager & ConfigurationMgrImpl();
} // namespace DeviceLayer
} // namespace chip