-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathConfigurationManager.h
241 lines (208 loc) · 11.3 KB
/
ConfigurationManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
*
* Copyright (c) 2020-2022 Project CHIP Authors
* Copyright (c) 2019-2020 Google LLC.
* Copyright (c) 2018 Nest Labs, Inc.
*
* 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 public interface for the Device Layer ConfigurationManager object.
*/
#pragma once
#include <cstdint>
#include <platform/CHIPDeviceConfig.h>
#if CHIP_HAVE_CONFIG_H
#include <setup_payload/CHIPAdditionalDataPayloadBuildConfig.h>
#endif
#include <lib/core/ClusterEnums.h>
#include <lib/support/Span.h>
#include <platform/PersistedStorage.h>
#include <platform/internal/CHIPDeviceLayerInternal.h>
namespace chip {
namespace Ble {
struct ChipBLEDeviceIdentificationInfo;
}
} // namespace chip
namespace chip {
namespace DeviceLayer {
class PlatformManagerImpl;
class ConfigurationManagerImpl;
namespace Internal {
template <class>
class GenericPlatformManagerImpl;
template <class>
class GenericPlatformManagerImpl_POSIX;
} // namespace Internal
/**
* Provides access to runtime and build-time configuration information for a chip device.
*/
class ConfigurationManager
{
public:
// ===== Members that define the public interface of the ConfigurationManager
enum
{
kMaxVendorNameLength = 32,
kMaxProductNameLength = 32,
kMaxLocationLength = 2,
kMaxHardwareVersionStringLength = 64,
kMaxSoftwareVersionStringLength = 64,
kMaxManufacturingDateLength = 16,
kMaxPartNumberLength = 32,
kMaxProductURLLength = 256,
kMaxProductLabelLength = 64,
kMaxSerialNumberLength = 32,
kMaxUniqueIDLength = 32,
#if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID)
kMinRotatingDeviceIDUniqueIDLength = 16,
kRotatingDeviceIDUniqueIDLength = CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID_LENGTH,
#endif
kEthernetMACAddressLength = 6,
kThreadMACAddressLength = 8,
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
kPrimaryMACAddressLength = kThreadMACAddressLength,
#else
kPrimaryMACAddressLength = kEthernetMACAddressLength,
#endif
kMaxMACAddressLength = 8,
kMaxLanguageTagLength = 5 // ISO 639-1 standard language codes
};
// Copies the primary MAC into a mutable span, which must be of size kPrimaryMACAddressLength.
// Upon success, the span will be reduced to the size of the MAC address being returned, which
// can be less than kPrimaryMACAddressLength on a device that supports Thread.
virtual CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan buf) = 0;
// Copies the primary WiFi MAC into a buffer of size kEthernetMACAddressLength
virtual CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) = 0;
// Copies the primary Thread (802.15.4) MAC into a buffer of size kThreadMACAddressLength
virtual CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf) = 0;
virtual CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize) = 0;
virtual CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) = 0;
virtual CHIP_ERROR GetFirmwareBuildChipEpochTime(System::Clock::Seconds32 & buildTime) = 0;
virtual CHIP_ERROR SetFirmwareBuildChipEpochTime(System::Clock::Seconds32 buildTime) { return CHIP_ERROR_NOT_IMPLEMENTED; }
#if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID)
// Lifetime counter is monotonic counter that is incremented upon each commencement of advertising
virtual CHIP_ERROR GetLifetimeCounter(uint16_t & lifetimeCounter) = 0;
virtual CHIP_ERROR IncrementLifetimeCounter() = 0;
virtual CHIP_ERROR SetRotatingDeviceIdUniqueId(const ByteSpan & uniqueIdSpan) = 0;
virtual CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) = 0;
#endif
virtual CHIP_ERROR GetRegulatoryLocation(uint8_t & location) = 0;
virtual CHIP_ERROR GetCountryCode(char * buf, size_t bufSize, size_t & codeLen) = 0;
virtual CHIP_ERROR StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen) = 0;
virtual CHIP_ERROR StoreSoftwareVersion(uint32_t softwareVer) = 0;
virtual CHIP_ERROR StoreHardwareVersion(uint16_t hardwareVer) = 0;
virtual CHIP_ERROR StoreRegulatoryLocation(uint8_t location) = 0;
virtual CHIP_ERROR StoreCountryCode(const char * code, size_t codeLen) = 0;
virtual CHIP_ERROR GetRebootCount(uint32_t & rebootCount) = 0;
virtual CHIP_ERROR StoreRebootCount(uint32_t rebootCount) = 0;
virtual CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) = 0;
virtual CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) = 0;
virtual CHIP_ERROR GetBootReason(uint32_t & bootReason) = 0;
virtual CHIP_ERROR StoreBootReason(uint32_t bootReason) = 0;
virtual CHIP_ERROR GetUniqueId(char * buf, size_t bufSize) = 0;
virtual CHIP_ERROR StoreUniqueId(const char * uniqueId, size_t uniqueIdLen) = 0;
virtual CHIP_ERROR GenerateUniqueId(char * buf, size_t bufSize) = 0;
virtual CHIP_ERROR GetFailSafeArmed(bool & val) = 0;
virtual CHIP_ERROR SetFailSafeArmed(bool val) = 0;
virtual CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) = 0;
virtual CHIP_ERROR StoreSerialNumber(CharSpan serialNumber) = 0;
virtual CHIP_ERROR StoreVendorName(CharSpan vendorName) = 0;
virtual CHIP_ERROR StoreProductName(CharSpan productName) = 0;
virtual CHIP_ERROR StoreHardwareVersionString(CharSpan hardwareVersionString) = 0;
virtual CHIP_ERROR StoreSoftwareVersionString(CharSpan softwareVersionString) = 0;
virtual CHIP_ERROR StoreVendorName(const char * vendorName, size_t vendorNameLen) = 0;
virtual CHIP_ERROR StoreProductName(const char * productName, size_t productNameLen) = 0;
virtual CHIP_ERROR StoreHardwareVersionString(const char * hardwareVersionString, size_t hardwareVersionStringLen) = 0;
virtual CHIP_ERROR StoreSoftwareVersionString(const char * softwareVersionString, size_t softwareVersionStringLen) = 0;
#if CHIP_CONFIG_TEST
virtual void RunUnitTests() = 0;
#endif
virtual bool IsFullyProvisioned() = 0;
virtual void InitiateFactoryReset() = 0;
// Gets called when starting BLE/DNS-SD advertisement
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
virtual void NotifyOfAdvertisementStart() {}
#else
void NotifyOfAdvertisementStart() {}
#endif
virtual void LogDeviceConfig() = 0;
virtual bool IsCommissionableDeviceTypeEnabled() = 0;
virtual CHIP_ERROR GetDeviceTypeId(uint32_t & deviceType) = 0;
virtual bool IsCommissionableDeviceNameEnabled() = 0;
virtual CHIP_ERROR GetCommissionableDeviceName(char * buf, size_t bufSize) = 0;
virtual CHIP_ERROR GetInitialPairingHint(uint16_t & pairingHint) = 0;
virtual CHIP_ERROR GetInitialPairingInstruction(char * buf, size_t bufSize) = 0;
virtual CHIP_ERROR GetSecondaryPairingHint(uint16_t & pairingHint) = 0;
virtual CHIP_ERROR GetSecondaryPairingInstruction(char * buf, size_t bufSize) = 0;
virtual CHIP_ERROR GetLocationCapability(uint8_t & location);
protected:
// ===== Members for internal use by the following friends.
friend class ::chip::DeviceLayer::PlatformManagerImpl;
template <class>
friend class ::chip::DeviceLayer::Internal::GenericPlatformManagerImpl;
template <class>
friend class ::chip::DeviceLayer::Internal::GenericPlatformManagerImpl_POSIX;
// Parentheses used to fix clang parsing issue with these declarations
friend CHIP_ERROR(::chip::Platform::PersistedStorage::Read)(::chip::Platform::PersistedStorage::Key key, uint32_t & value);
friend CHIP_ERROR(::chip::Platform::PersistedStorage::Write)(::chip::Platform::PersistedStorage::Key key, uint32_t value);
virtual CHIP_ERROR Init() = 0;
virtual bool CanFactoryReset() = 0;
virtual CHIP_ERROR ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) = 0;
virtual CHIP_ERROR WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) = 0;
// Construction/destruction limited to subclasses.
ConfigurationManager() = default;
virtual ~ConfigurationManager() = default;
// No copy, move or assignment.
ConfigurationManager(const ConfigurationManager &) = delete;
ConfigurationManager(const ConfigurationManager &&) = delete;
ConfigurationManager & operator=(const ConfigurationManager &) = delete;
};
/**
* Returns a reference to a ConfigurationManager object.
*
* Applications should use this to access features of the ConfigurationManager object
* that are common to all platforms.
*/
ConfigurationManager & ConfigurationMgr();
/**
* 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.
*/
extern ConfigurationManager & ConfigurationMgrImpl();
/**
* Sets a reference to a ConfigurationManager object.
*
* This must be called before any calls to ConfigurationMgr. If a nullptr is passed in,
* no changes will be made.
*/
void SetConfigurationMgr(ConfigurationManager * configurationManager);
inline CHIP_ERROR ConfigurationManager::GetLocationCapability(uint8_t & location)
{
location = to_underlying(chip::app::Clusters::GeneralCommissioning::RegulatoryLocationTypeEnum::kIndoor);
return CHIP_NO_ERROR;
}
} // namespace DeviceLayer
} // namespace chip
/* Include a header file containing the implementation of the ConfigurationManager
* object for the selected platform.
*/
#ifdef EXTERNAL_CONFIGURATIONMANAGERIMPL_HEADER
#include EXTERNAL_CONFIGURATIONMANAGERIMPL_HEADER
#elif defined(CHIP_DEVICE_LAYER_TARGET)
#define CONFIGURATIONMANAGERIMPL_HEADER <platform/CHIP_DEVICE_LAYER_TARGET/ConfigurationManagerImpl.h>
#include CONFIGURATIONMANAGERIMPL_HEADER
#endif // defined(CHIP_DEVICE_LAYER_TARGET)