Skip to content

Commit

Permalink
Implement general commissioning cluster callbacks (#6361)
Browse files Browse the repository at this point in the history
* Implement general commisioning callbacks

* Address review comments

* Return CHIP_ERROR_NOT_IMPLEMENTED for unimplemented functions

* Use static memeber function instead of friend member function
  • Loading branch information
yufengwangca authored and pull[bot] committed Aug 17, 2021
1 parent d0e661a commit 2543076
Show file tree
Hide file tree
Showing 22 changed files with 351 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,35 @@
#include <app/Command.h>
#include <app/util/af.h>
#include <lib/support/Span.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/internal/DeviceControlServer.h>

using namespace chip;

bool emberAfGeneralCommissioningClusterArmFailSafeCallback(chip::app::Command * commandObj, uint16_t expiryLengthSeconds,
uint64_t breadcrumb, uint32_t timeoutMs)
{
EmberAfStatus status = EMBER_ZCL_STATUS_FAILURE;
emberAfSendImmediateDefaultResponse(status);
CHIP_ERROR err = DeviceLayer::Internal::DeviceControlServer::DeviceControlSvr().ArmFailSafe(expiryLengthSeconds);
emberAfSendImmediateDefaultResponse(err == CHIP_NO_ERROR ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);

return true;
}

bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(chip::app::Command * commandObj)
{
EmberAfStatus status = EMBER_ZCL_STATUS_FAILURE;
emberAfSendImmediateDefaultResponse(status);
CHIP_ERROR err = DeviceLayer::Internal::DeviceControlServer::DeviceControlSvr().CommissioningComplete();
emberAfSendImmediateDefaultResponse(err == CHIP_NO_ERROR ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);

return true;
}

bool emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(chip::app::Command * commandObj, uint8_t location,
uint8_t * countryCode, uint64_t breadcrumb, uint32_t timeoutMs)
{
EmberAfStatus status = EMBER_ZCL_STATUS_FAILURE;
emberAfSendImmediateDefaultResponse(status);
CHIP_ERROR err = DeviceLayer::Internal::DeviceControlServer::DeviceControlSvr().SetRegulatoryConfig(
location, reinterpret_cast<const char *>(countryCode), breadcrumb);

emberAfSendImmediateDefaultResponse(err == CHIP_NO_ERROR ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);

return true;
}
36 changes: 36 additions & 0 deletions src/include/platform/ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class ConfigurationManager
// Lifetime counter is monotonic counter that is incremented only in the case of a factory reset
CHIP_ERROR GetLifetimeCounter(uint16_t & lifetimeCounter);
#endif
CHIP_ERROR GetRegulatoryLocation(uint32_t & location);
CHIP_ERROR GetCountryCode(char * buf, size_t bufSize, size_t & codeLen);
CHIP_ERROR GetBreadcrumb(uint64_t & breadcrumb);
CHIP_ERROR StoreSerialNumber(const char * serialNum, size_t serialNumLen);
CHIP_ERROR StorePrimaryWiFiMACAddress(const uint8_t * buf);
CHIP_ERROR StorePrimary802154MACAddress(const uint8_t * buf);
Expand All @@ -116,6 +119,9 @@ class ConfigurationManager
CHIP_ERROR ClearServiceProvisioningData();
CHIP_ERROR StoreServiceConfig(const uint8_t * serviceConfig, size_t serviceConfigLen);
CHIP_ERROR StorePairedAccountId(const char * accountId, size_t accountIdLen);
CHIP_ERROR StoreRegulatoryLocation(uint32_t location);
CHIP_ERROR StoreCountryCode(const char * code, size_t codeLen);
CHIP_ERROR StoreBreadcrumb(uint64_t breadcrumb);

CHIP_ERROR GetQRCodeString(char * buf, size_t bufSize);

Expand Down Expand Up @@ -371,6 +377,21 @@ inline CHIP_ERROR ConfigurationManager::GetLifetimeCounter(uint16_t & lifetimeCo
}
#endif

inline CHIP_ERROR ConfigurationManager::GetRegulatoryLocation(uint32_t & location)
{
return static_cast<ImplClass *>(this)->_GetRegulatoryLocation(location);
}

inline CHIP_ERROR ConfigurationManager::GetCountryCode(char * buf, size_t bufSize, size_t & codeLen)
{
return static_cast<ImplClass *>(this)->_GetCountryCode(buf, bufSize, codeLen);
}

inline CHIP_ERROR ConfigurationManager::GetBreadcrumb(uint64_t & breadcrumb)
{
return static_cast<ImplClass *>(this)->_GetBreadcrumb(breadcrumb);
}

inline CHIP_ERROR ConfigurationManager::StoreSerialNumber(const char * serialNum, size_t serialNumLen)
{
return static_cast<ImplClass *>(this)->_StoreSerialNumber(serialNum, serialNumLen);
Expand Down Expand Up @@ -463,6 +484,21 @@ inline CHIP_ERROR ConfigurationManager::StoreServiceProvisioningData(uint64_t se
accountIdLen);
}

inline CHIP_ERROR ConfigurationManager::StoreRegulatoryLocation(uint32_t location)
{
return static_cast<ImplClass *>(this)->_StoreRegulatoryLocation(location);
}

inline CHIP_ERROR ConfigurationManager::StoreCountryCode(const char * code, size_t codeLen)
{
return static_cast<ImplClass *>(this)->_StoreCountryCode(code, codeLen);
}

inline CHIP_ERROR ConfigurationManager::StoreBreadcrumb(uint64_t breadcrumb)
{
return static_cast<ImplClass *>(this)->_StoreBreadcrumb(breadcrumb);
}

inline CHIP_ERROR ConfigurationManager::ClearServiceProvisioningData()
{
return static_cast<ImplClass *>(this)->_ClearServiceProvisioningData();
Expand Down
60 changes: 60 additions & 0 deletions src/include/platform/internal/DeviceControlServer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
*
* Copyright (c) 2021 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
* Defines the Device Layer DeviceControlServer object.
*/

#pragma once

#include <platform/internal/CHIPDeviceLayerInternal.h>

namespace chip {
namespace DeviceLayer {
namespace Internal {

class DeviceControlServer final
{
public:
// ===== Members for internal use by other Device Layer components.

CHIP_ERROR ArmFailSafe(uint16_t expiryLengthSeconds);
CHIP_ERROR DisarmFailSafe();
CHIP_ERROR CommissioningComplete();
CHIP_ERROR SetRegulatoryConfig(uint8_t location, const char * countryCode, uint64_t breadcrumb);

static DeviceControlServer & DeviceControlSvr();

private:
// ===== Members for internal use by the following friends.
static DeviceControlServer sInstance;

// ===== Private members reserved for use by this class only.

DeviceControlServer() = default;
~DeviceControlServer() = default;

// No copy, move or assignment.
DeviceControlServer(const DeviceControlServer &) = delete;
DeviceControlServer(const DeviceControlServer &&) = delete;
DeviceControlServer & operator=(const DeviceControlServer &) = delete;
};

} // namespace Internal
} // namespace DeviceLayer
} // namespace chip
94 changes: 0 additions & 94 deletions src/include/platform/internal/DeviceDescriptionServer.h

This file was deleted.

36 changes: 36 additions & 0 deletions src/include/platform/internal/GenericConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,42 @@ CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_StoreFabricId(uint64_t f
return err;
}

template <class ImplClass>
CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_GetRegulatoryLocation(uint32_t & location)
{
return Impl()->ReadConfigValue(ImplClass::kConfigKey_RegulatoryLocation, location);
}

template <class ImplClass>
CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_StoreRegulatoryLocation(uint32_t location)
{
return Impl()->WriteConfigValue(ImplClass::kConfigKey_RegulatoryLocation, location);
}

template <class ImplClass>
CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_GetCountryCode(char * buf, size_t bufSize, size_t & codeLen)
{
return Impl()->ReadConfigValueStr(ImplClass::kConfigKey_CountryCode, buf, bufSize, codeLen);
}

template <class ImplClass>
CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_StoreCountryCode(const char * code, size_t codeLen)
{
return Impl()->WriteConfigValueStr(ImplClass::kConfigKey_CountryCode, code, codeLen);
}

template <class ImplClass>
CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_GetBreadcrumb(uint64_t & breadcrumb)
{
return Impl()->ReadConfigValue(ImplClass::kConfigKey_Breadcrumb, breadcrumb);
}

template <class ImplClass>
CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_StoreBreadcrumb(uint64_t breadcrumb)
{
return Impl()->WriteConfigValue(ImplClass::kConfigKey_Breadcrumb, breadcrumb);
}

template <class ImplClass>
CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::_GetServiceId(uint64_t & serviceId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ class GenericConfigurationManagerImpl
CHIP_ERROR _GetQRCodeString(char * buf, size_t bufSize);
CHIP_ERROR _GetWiFiAPSSID(char * buf, size_t bufSize);
CHIP_ERROR _GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo);
CHIP_ERROR _GetRegulatoryLocation(uint32_t & location);
CHIP_ERROR _StoreRegulatoryLocation(uint32_t location);
CHIP_ERROR _GetCountryCode(char * buf, size_t bufSize, size_t & codeLen);
CHIP_ERROR _StoreCountryCode(const char * code, size_t codeLen);
CHIP_ERROR _GetBreadcrumb(uint64_t & breadcrumb);
CHIP_ERROR _StoreBreadcrumb(uint64_t breadcrumb);
CHIP_ERROR _ConfigureChipStack();
#if !defined(NDEBUG)
CHIP_ERROR _RunUnitTests(void);
Expand Down
3 changes: 2 additions & 1 deletion src/platform/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {
"../include/platform/TimeSyncManager.h",
"../include/platform/internal/BLEManager.h",
"../include/platform/internal/CHIPDeviceLayerInternal.h",
"../include/platform/internal/DeviceDescriptionServer.h",
"../include/platform/internal/DeviceControlServer.h",
"../include/platform/internal/DeviceNetworkInfo.h",
"../include/platform/internal/DeviceNetworkProvisioning.h",
"../include/platform/internal/EventLogging.h",
Expand All @@ -222,6 +222,7 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {
"../include/platform/internal/GenericSoftwareUpdateManagerImpl.h",
"../include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.h",
"../include/platform/internal/testing/ConfigUnitTest.h",
"DeviceControlServer.cpp",
"GeneralUtils.cpp",
"Globals.cpp",
"PersistedStorage.cpp",
Expand Down
3 changes: 3 additions & 0 deletions src/platform/Darwin/PosixConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ const PosixConfig::Key PosixConfig::kConfigKey_OperationalDeviceId = { k
const PosixConfig::Key PosixConfig::kConfigKey_OperationalDeviceCert = { kConfigNamespace_ChipConfig, "op-device-cert" };
const PosixConfig::Key PosixConfig::kConfigKey_OperationalDeviceICACerts = { kConfigNamespace_ChipConfig, "op-device-ca-certs" };
const PosixConfig::Key PosixConfig::kConfigKey_OperationalDevicePrivateKey = { kConfigNamespace_ChipConfig, "op-device-key" };
const PosixConfig::Key PosixConfig::kConfigKey_RegulatoryLocation = { kConfigNamespace_ChipConfig, "regulatory-location" };
const PosixConfig::Key PosixConfig::kConfigKey_CountryCode = { kConfigNamespace_ChipConfig, "country-code" };
const PosixConfig::Key PosixConfig::kConfigKey_Breadcrumb = { kConfigNamespace_ChipConfig, "breadcrumb" };

// Prefix used for NVS keys that contain Chip group encryption keys.
const char PosixConfig::kGroupKeyNamePrefix[] = "gk-";
Expand Down
3 changes: 3 additions & 0 deletions src/platform/Darwin/PosixConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class PosixConfig
static const Key kConfigKey_OperationalDeviceICACerts;
static const Key kConfigKey_OperationalDevicePrivateKey;
static const Key kConfigKey_SetupDiscriminator;
static const Key kConfigKey_RegulatoryLocation;
static const Key kConfigKey_CountryCode;
static const Key kConfigKey_Breadcrumb;

static const char kGroupKeyNamePrefix[];

Expand Down
Loading

0 comments on commit 2543076

Please sign in to comment.