From 0df92e866112262dd1fea4f218d4fbe1b15793f1 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Tue, 24 Mar 2020 10:58:05 -0700 Subject: [PATCH 1/6] Import VendorIdentifiers --- src/lib/core/WeaveVendorIdentifiers.hpp | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/lib/core/WeaveVendorIdentifiers.hpp diff --git a/src/lib/core/WeaveVendorIdentifiers.hpp b/src/lib/core/WeaveVendorIdentifiers.hpp new file mode 100644 index 00000000000000..8f2bd6e418d184 --- /dev/null +++ b/src/lib/core/WeaveVendorIdentifiers.hpp @@ -0,0 +1,52 @@ +/* + * + * Copyright (c) 2014-2017 Nest Labs, Inc. + * All rights reserved. + * + * 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 + * This file defines Weave vendor identifiers. + * + * Vendor identifiers are assigned and administered by Nest Labs. + * + */ + +#ifndef WEAVE_VENDOR_IDENTIFIERS_HPP +#define WEAVE_VENDOR_IDENTIFIERS_HPP + +namespace nl { + +namespace Weave { + +// +// Weave Vendor Identifiers (16 bits max) +// + +enum WeaveVendorId +{ + kWeaveVendor_Common = 0x0000, + kWeaveVendor_NestLabs = 0x235A, + kWeaveVendor_Yale = 0xE727, + kWeaveVendor_Google = 0xE100, + + kWeaveVendor_NotSpecified = 0xFFFF +}; + +}; // namespace Weave + +}; // namespace nl + +#endif // WEAVE_VENDOR_IDENTIFIERS_HPP From c651f296698fe737bbeda1f84f22c8ae94979a22 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Tue, 24 Mar 2020 11:29:00 -0700 Subject: [PATCH 2/6] Fix namespace for vendor identifiers --- ...ntifiers.hpp => CHIPVendorIdentifiers.hpp} | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) rename src/lib/core/{WeaveVendorIdentifiers.hpp => CHIPVendorIdentifiers.hpp} (50%) diff --git a/src/lib/core/WeaveVendorIdentifiers.hpp b/src/lib/core/CHIPVendorIdentifiers.hpp similarity index 50% rename from src/lib/core/WeaveVendorIdentifiers.hpp rename to src/lib/core/CHIPVendorIdentifiers.hpp index 8f2bd6e418d184..c99810b32084d8 100644 --- a/src/lib/core/WeaveVendorIdentifiers.hpp +++ b/src/lib/core/CHIPVendorIdentifiers.hpp @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2014-2017 Nest Labs, Inc. - * All rights reserved. + * * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,33 +19,25 @@ * @file * This file defines Weave vendor identifiers. * - * Vendor identifiers are assigned and administered by Nest Labs. + * Vendor identifiers are assigned and administered by CHIP. * */ -#ifndef WEAVE_VENDOR_IDENTIFIERS_HPP -#define WEAVE_VENDOR_IDENTIFIERS_HPP +#ifndef CHIP_VENDOR_IDENTIFIERS_HPP +#define CHIP_VENDOR_IDENTIFIERS_HPP -namespace nl { - -namespace Weave { +namespace chip { // -// Weave Vendor Identifiers (16 bits max) +// CHIP Vendor Identifiers (16 bits max) // -enum WeaveVendorId +enum ChipVendorId { - kWeaveVendor_Common = 0x0000, - kWeaveVendor_NestLabs = 0x235A, - kWeaveVendor_Yale = 0xE727, - kWeaveVendor_Google = 0xE100, - - kWeaveVendor_NotSpecified = 0xFFFF + kChipVendor_Common = 0x0000, + kChipVendor_NotSpecified = 0xFFFF }; -}; // namespace Weave - -}; // namespace nl +}; // namespace chip -#endif // WEAVE_VENDOR_IDENTIFIERS_HPP +#endif // CHIP_VENDOR_IDENTIFIERS_HPP From 250a97abe83418892817a597c6b252e5d180d581 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Tue, 24 Mar 2020 11:34:13 -0700 Subject: [PATCH 3/6] Import Key IDs --- src/lib/core/WeaveKeyIds.cpp | 376 +++++++++++++++++++++++++++++++ src/lib/core/WeaveKeyIds.h | 415 +++++++++++++++++++++++++++++++++++ 2 files changed, 791 insertions(+) create mode 100644 src/lib/core/WeaveKeyIds.cpp create mode 100644 src/lib/core/WeaveKeyIds.h diff --git a/src/lib/core/WeaveKeyIds.cpp b/src/lib/core/WeaveKeyIds.cpp new file mode 100644 index 00000000000000..16e64680a3940a --- /dev/null +++ b/src/lib/core/WeaveKeyIds.cpp @@ -0,0 +1,376 @@ +/* + * + * Copyright (c) 2016-2017 Nest Labs, Inc. + * All rights reserved. + * + * 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 + * This file implements Weave key types helper functions. + * + */ + +#include +#include "WeaveKeyIds.h" +#include + +namespace nl { +namespace Weave { + +/** + * Determine whether the specified key ID belongs to one of the application + * group key types (static or rotating). + * + * @param[in] keyId Weave key identifier. + * @return true if the keyId is of rotating or static key type. + * + */ +bool WeaveKeyId::IsAppGroupKey(uint32_t keyId) +{ + return IsAppStaticKey(keyId) || IsAppRotatingKey(keyId); +} + +/** + * Determine whether the specified application group key ID uses "current" epoch key. + * + * @param[in] keyId Weave application group key identifier. + * @return true if the keyId indicates usage of the current epoch key. + * + */ +bool WeaveKeyId::UsesCurrentEpochKey(uint32_t keyId) +{ + return IncorporatesEpochKey(keyId) && ((keyId & kFlag_UseCurrentEpochKey) != 0); +} + +/** + * Determine whether the specified application group key ID incorporates root key. + * + * @param[in] keyId Weave application group key identifier. + * @return true if the keyId incorporates root key. + * + */ +bool WeaveKeyId::IncorporatesRootKey(uint32_t keyId) +{ + uint32_t keyType = GetType(keyId); + return keyType == kType_AppStaticKey || + keyType == kType_AppRotatingKey || + keyType == kType_AppRootKey || + keyType == kType_AppIntermediateKey; +} + +/** + * Determine whether the specified application group key ID incorporates group master key. + * + * @param[in] keyId Weave application group key identifier. + * @return true if the keyId incorporates group master key. + * + */ +bool WeaveKeyId::IncorporatesAppGroupMasterKey(uint32_t keyId) +{ + uint32_t keyType = GetType(keyId); + return keyType == kType_AppStaticKey || + keyType == kType_AppRotatingKey || + keyType == kType_AppGroupMasterKey; +} + +/** + * Construct application group key ID given constituent key IDs and other information. + * + * @param[in] keyType Derived application group key type. + * @param[in] rootKeyId Root key ID used to derive application group key. + * @param[in] epochKeyId Epoch key ID used to derive application group key. + * @param[in] appGroupMasterKeyId Application group master key ID used to derive + * application group key. + * @param[in] useCurrentEpochKey A boolean flag that indicates if key should be derived + * using "current" epoch key. + * @return application group key ID. + * + */ +uint32_t WeaveKeyId::MakeAppKeyId(uint32_t keyType, uint32_t rootKeyId, uint32_t epochKeyId, + uint32_t appGroupMasterKeyId, bool useCurrentEpochKey) +{ + return (keyType | + (rootKeyId & kMask_RootKeyNumber) | + (appGroupMasterKeyId & kMask_GroupLocalNumber) | + (useCurrentEpochKey ? kFlag_UseCurrentEpochKey : (epochKeyId & kMask_EpochKeyNumber))); +} + +/** + * Construct application intermediate key ID given constituent key IDs. + * + * @param[in] rootKeyId Root key ID used to derive application intermediate key. + * @param[in] epochKeyId Epoch key ID used to derive application intermediate key. + * @param[in] useCurrentEpochKey A boolean flag that indicates if key should be derived + * using "current" epoch key. + * @return application intermediate key ID. + * + */ +uint32_t WeaveKeyId::MakeAppIntermediateKeyId(uint32_t rootKeyId, uint32_t epochKeyId, bool useCurrentEpochKey) +{ + return MakeAppKeyId(kType_AppIntermediateKey, rootKeyId, epochKeyId, kNone, useCurrentEpochKey); +} + +/** + * Construct application rotating key ID given constituent key IDs and other information. + * + * @param[in] rootKeyId Root key ID used to derive application rotating key. + * @param[in] epochKeyId Epoch key ID used to derive application rotating key. + * @param[in] appGroupMasterKeyId Application group master key ID used to derive + * application rotating key. + * @param[in] useCurrentEpochKey A boolean flag that indicates if key should be derived + * using "current" epoch key. + * @return application rotating key ID. + * + */ +uint32_t WeaveKeyId::MakeAppRotatingKeyId(uint32_t rootKeyId, uint32_t epochKeyId, + uint32_t appGroupMasterKeyId, bool useCurrentEpochKey) +{ + return MakeAppKeyId(kType_AppRotatingKey, rootKeyId, epochKeyId, appGroupMasterKeyId, useCurrentEpochKey); +} + +/** + * Construct application static key ID given constituent key IDs. + * + * @param[in] rootKeyId Root key ID used to derive application static key. + * @param[in] appGroupMasterKeyId Application group master key ID used to derive + * application static key. + * @return application static key ID. + * + */ +uint32_t WeaveKeyId::MakeAppStaticKeyId(uint32_t rootKeyId, uint32_t appGroupMasterKeyId) +{ + return MakeAppKeyId(kType_AppStaticKey, rootKeyId, kNone, appGroupMasterKeyId, false); +} + +/** + * Convert application key ID to application static key ID. + * + * @param[in] keyId Application key ID. + * @return application static key ID. + * + */ +uint32_t WeaveKeyId::ConvertToStaticAppKeyId(uint32_t keyId) +{ + return MakeAppStaticKeyId(GetRootKeyId(keyId), GetAppGroupMasterKeyId(keyId)); +} + +/** + * Update application group key ID with new epoch key number. + * + * @param[in] keyId Application key ID. + * @param[in] epochKeyId Epoch key ID, which will be used in construction + * of the updated application key ID. + * @return application key ID. + * + */ +uint32_t WeaveKeyId::UpdateEpochKeyId(uint32_t keyId, uint32_t epochKeyId) +{ + return (keyId & ~(kFlag_UseCurrentEpochKey | kMask_EpochKeyNumber)) | + (epochKeyId & kMask_EpochKeyNumber); +} + +/** + * Determine whether key identifier has valid (legal) value. + * + * @param[in] keyId Weave key ID. + * @return true if key ID value is valid. + * + */ +bool WeaveKeyId::IsValidKeyId(uint32_t keyId) +{ + bool retval; + int usedBits = kMask_KeyType; + + switch (GetType(keyId)) { + case kType_None: + ExitNow(retval = false); + case kType_General: + case kType_Session: + usedBits |= kMask_KeyNumber; + break; + case kType_AppStaticKey: + usedBits |= kMask_RootKeyNumber | + kMask_GroupLocalNumber; + break; + case kType_AppRotatingKey: + usedBits |= kFlag_UseCurrentEpochKey | + kMask_RootKeyNumber | + kMask_GroupLocalNumber; + if (!UsesCurrentEpochKey(keyId)) + { + usedBits |= kMask_EpochKeyNumber; + } + break; + case kType_AppRootKey: + usedBits |= kMask_RootKeyNumber; + break; + case kType_AppIntermediateKey: + usedBits |= kFlag_UseCurrentEpochKey | + kMask_RootKeyNumber; + if (!UsesCurrentEpochKey(keyId)) + { + usedBits |= kMask_EpochKeyNumber; + } + break; + case kType_AppEpochKey: + usedBits |= kFlag_UseCurrentEpochKey; + if (!UsesCurrentEpochKey(keyId)) + { + usedBits |= kMask_EpochKeyNumber; + } + break; + case kType_AppGroupMasterKey: + usedBits |= kMask_GroupLocalNumber; + break; + default: + ExitNow(retval = false); + } + + if (IncorporatesRootKey(keyId)) + { + int rootKeyId = GetRootKeyId(keyId); + VerifyOrExit(rootKeyId == kFabricRootKey || + rootKeyId == kClientRootKey || + rootKeyId == kServiceRootKey, retval = false); + } + + retval = (keyId & ~usedBits) == 0; + +exit: + return retval; +} + +/** + * Determine whether a given key ID identifies a key that is suitable for Weave message encryption. + * + * @param[in] keyId Weave key ID. + * @param[in] allowLogicalKeys Specifies whether logical keys IDs (such as the "current" rotating key) + * should be considered suitable for message encryption. + * @return true If the identified key can be used to encrypt Weave messages. + * + */ +bool WeaveKeyId::IsMessageEncryptionKeyId(uint32_t keyId, bool allowLogicalKeys) +{ + switch (GetType(keyId)) + { + case kType_Session: + case kType_AppStaticKey: + return true; + case kType_AppRotatingKey: + return allowLogicalKeys || !UsesCurrentEpochKey(keyId); + default: + return false; + } +} + +/** + * Determines whether two key IDs identify the same key, or in the case of rotating keys, the same + * group of keys independent of any particular epoch. + * + * @param[in] keyId1 The first key ID to test. + * @param[in] keyId2 The second key ID to test. + * + * @return True if the keys IDs represent the same key. + */ +bool WeaveKeyId::IsSameKeyOrGroup(uint32_t keyId1, uint32_t keyId2) +{ + enum { kIgnoreEpochMask = ~(kMask_EpochKeyNumber | kFlag_UseCurrentEpochKey) }; + + // If the key ids are identical then they represent the same key. + if (keyId1 == keyId2) + return true; + + // For rotating keys, treat the key ids as the same if they differ only in their choice of epoch + // key number. + if (IncorporatesEpochKey(keyId1) && !IsAppEpochKey(keyId1) && (keyId1 & kIgnoreEpochMask) == (keyId2 & kIgnoreEpochMask)) + return true; + + // Otherwise the key ids identify different keys. + return false; +} + +/** + * Decode a Weave key identifier with a descriptive string. + * + * @param[in] keyId Weave key ID to decode and for which to return + * a descriptive string. + * + * @return A pointer to a NULL-terminated string describing the specified key ID. + * + */ +const char *WeaveKeyId::DescribeKey(uint32_t keyId) +{ + const char *retval; + + switch (GetType(keyId)) + { + case kType_None: + retval = "No Key"; + break; + case kType_General: + if (keyId == kFabricSecret) + { + retval = "Fabric Secret"; + } + else + { + retval = "Other General Key"; + } + break; + case kType_Session: + retval = "Session Key"; + break; + case kType_AppStaticKey: + retval = "Application Static Key"; + break; + case kType_AppRotatingKey: + retval = "Application Rotating Key"; + break; + case kType_AppRootKey: + if (keyId == kFabricRootKey) + { + retval = "Fabric Root Key"; + } + else if (keyId == kClientRootKey) + { + retval = "Client Root Key"; + } + else if (keyId == kServiceRootKey) + { + retval = "Service Root Key"; + } + else + { + retval = "Other Root Key"; + } + break; + case kType_AppIntermediateKey: + retval = "Application Intermediate Key"; + break; + case kType_AppEpochKey: + retval = "Application Epoch Key"; + break; + case kType_AppGroupMasterKey: + retval = "Application Group Master Key"; + break; + default: + retval = "Unknown Key Type"; + } + + return retval; +} + +} // namespace Weave +} // namespace nl diff --git a/src/lib/core/WeaveKeyIds.h b/src/lib/core/WeaveKeyIds.h new file mode 100644 index 00000000000000..7e9c57e032a30c --- /dev/null +++ b/src/lib/core/WeaveKeyIds.h @@ -0,0 +1,415 @@ +/* + * + * Copyright (c) 2016-2017 Nest Labs, Inc. + * All rights reserved. + * + * 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 + * This file defines constant enumerations for all Weave key types, + * key flags, key ID fields, and helper API functions. + * + */ + +#ifndef WEAVEKEYS_H_ +#define WEAVEKEYS_H_ + +namespace nl { +namespace Weave { + +/** + * @class WeaveKeyId + * + * @brief + * The definition of the Weave Key identifier. This class contains + * key types, key flags, key ID fields definition, and API functions. + * + */ +class WeaveKeyId +{ +private: + /** + * @brief + * Private Weave key ID fields, flags, and types. + */ + enum + { + kMask_KeyFlags = 0xF0000000, /**< Weave key flag field mask. */ + kMask_KeyType = 0x0FFFF000, /**< Weave key type field mask. */ + kMask_KeyNumber = 0x00000FFF, /**< Weave key number field mask. */ + kMask_RootKeyNumber = 0x00000C00, /**< Application group root key number field mask. */ + kMask_EpochKeyNumber = 0x00000380, /**< Application group epoch key number field mask. */ + kMask_GroupLocalNumber = 0x0000007F, /**< Application group local number field mask. */ + + kShift_RootKeyNumber = 10, /**< Application group root key number field shift. */ + kShift_EpochKeyNumber = 7, /**< Application group epoch key number field shift. */ + kShift_GroupLocalNumber = 0, /**< Application group local number field shift. */ + + kFlag_UseCurrentEpochKey = 0x80000000, /**< Used to indicate that the key is of logical current type. */ + + kTypeModifier_IncorporatesEpochKey = 0x00001000, /**< Used to indicate that the key incorporates group epoch key. */ + }; + + +public: + /** + * @brief + * Public Weave key ID fields, flags, and types. + */ + enum + { + /** + * @brief Weave key types used for Weave message encryption. + * + * @note 16 (out of 32) most significant bits of the message encryption key + * type should be zero because only 16 least significant bits of the ID + * are encoded in the Weave message. + * @{ + */ + kType_None = 0x00000000, /**< Weave message is unencrypted. */ + kType_General = 0x00001000, /**< General key type. */ + kType_Session = 0x00002000, /**< Session key type. */ + kType_AppStaticKey = 0x00004000, /**< Application static key type. */ + /** Application rotating key type. */ + kType_AppRotatingKey = kType_AppStaticKey | kTypeModifier_IncorporatesEpochKey, + /** @} */ + + /** + * @brief Weave key types (other than Weave message encryption types). + * + * @note 16 (out of 32) most significant bits of these types cannot be all zeros, + * because these values are reserved for the Weave message encryption keys only. + * @{ + */ + + /** + * @brief Constituent group key types. + * @{ + */ + /** Application group root key type. */ + kType_AppRootKey = 0x00010000, + /** Application group epoch key type. */ + kType_AppEpochKey = 0x00020000 | kTypeModifier_IncorporatesEpochKey, + /** Application group master key type. */ + kType_AppGroupMasterKey = 0x00030000, + /** Application group intermediate key type. */ + kType_AppIntermediateKey = kType_AppRootKey | kTypeModifier_IncorporatesEpochKey, + /** @} */ + + /** + * @brief Weave global key IDs. + * @{ + */ + /** Unspecified Weave key ID. */ + kNone = kType_None | 0x0000, + /** Weave fabric secret ID. */ + kFabricSecret = kType_General | 0x0001, + /** Fabric root key ID. */ + kFabricRootKey = kType_AppRootKey | (0 << kShift_RootKeyNumber), + /** Client root key ID. */ + kClientRootKey = kType_AppRootKey | (1 << kShift_RootKeyNumber), + /** Service root key ID. */ + kServiceRootKey = kType_AppRootKey | (2 << kShift_RootKeyNumber), + /** @} */ + + + /** + * @brief Maximum values for key ID subfields. + * @{ + */ + kKeyNumber_Max = kMask_KeyNumber, + kRootKeyNumber_Max = (kMask_RootKeyNumber >> kShift_RootKeyNumber), + kEpochKeyNumber_Max = (kMask_EpochKeyNumber >> kShift_EpochKeyNumber), + kGroupLocalNumber_Max = (kMask_GroupLocalNumber >> kShift_GroupLocalNumber), + /** @} */ + }; + + /** + * Get Weave key type of the specified key ID. + * + * @param[in] keyId Weave key identifier. + * @return type of the key ID. + * + */ + static uint32_t GetType(uint32_t keyId) + { + return keyId & kMask_KeyType; + } + + /** + * Determine whether the specified key ID is of a general type. + * + * @param[in] keyId Weave key identifier. + * @return true if the keyId has General type. + * + */ + static bool IsGeneralKey(uint32_t keyId) + { + return GetType(keyId) == kType_General; + } + + /** + * Determine whether the specified key ID is of a session type. + * + * @param[in] keyId Weave key identifier. + * @return true if the keyId of a session type. + * + */ + static bool IsSessionKey(uint32_t keyId) + { + return GetType(keyId) == kType_Session; + } + + /** + * Determine whether the specified key ID is of an application static type. + * + * @param[in] keyId Weave key identifier. + * @return true if the keyId of an application static type. + * + */ + static bool IsAppStaticKey(uint32_t keyId) + { + return GetType(keyId) == kType_AppStaticKey; + } + + /** + * Determine whether the specified key ID is of an application rotating type. + * + * @param[in] keyId Weave key identifier. + * @return true if the keyId of an application rotating type. + * + */ + static bool IsAppRotatingKey(uint32_t keyId) + { + return GetType(keyId) == kType_AppRotatingKey; + } + + static bool IsAppGroupKey(uint32_t keyId); + + /** + * Determine whether the specified key ID is of an application root key type. + * + * @param[in] keyId Weave key identifier. + * @return true if the keyId of an application root key type. + * + */ + static bool IsAppRootKey(uint32_t keyId) + { + return GetType(keyId) == kType_AppRootKey; + } + + /** + * Determine whether the specified key ID is of an application epoch key type. + * + * @param[in] keyId Weave key identifier. + * @return true if the keyId of an application epoch key type. + * + */ + static bool IsAppEpochKey(uint32_t keyId) + { + return GetType(keyId) == kType_AppEpochKey; + } + + /** + * Determine whether the specified key ID is of an application group master key type. + * + * @param[in] keyId Weave key identifier. + * @return true if the keyId of an application group master key type. + * + */ + static bool IsAppGroupMasterKey(uint32_t keyId) + { + return GetType(keyId) == kType_AppGroupMasterKey; + } + + /** + * Construct session key ID given session key number. + * + * @param[in] sessionKeyNumber Session key number. + * @return session key ID. + * + */ + static uint16_t MakeSessionKeyId(uint16_t sessionKeyNumber) + { + return kType_Session | (sessionKeyNumber & kMask_KeyNumber); + } + + /** + * Construct general key ID given general key number. + * + * @param[in] generalKeyNumber General key number. + * @return general key ID. + * + */ + static uint16_t MakeGeneralKeyId(uint16_t generalKeyNumber) + { + return kType_General | (generalKeyNumber & kMask_KeyNumber); + } + + /** + * Get application group root key ID that was used to derive specified application key. + * + * @param[in] keyId Weave application group key identifier. + * @return root key ID. + * + */ + static uint32_t GetRootKeyId(uint32_t keyId) + { + return kType_AppRootKey | (keyId & kMask_RootKeyNumber); + } + + /** + * Get application group epoch key ID that was used to derive specified application key. + * + * @param[in] keyId Weave application group key identifier. + * @return epoch key ID. + * + */ + static uint32_t GetEpochKeyId(uint32_t keyId) + { + return kType_AppEpochKey | (keyId & kMask_EpochKeyNumber); + } + + /** + * Get application group master key ID that was used to derive specified application key. + * + * @param[in] keyId Weave application group key identifier. + * @return application group master key ID. + * + */ + static uint32_t GetAppGroupMasterKeyId(uint32_t keyId) + { + return kType_AppGroupMasterKey | (keyId & kMask_GroupLocalNumber); + } + + /** + * Get application group root key number that was used to derive specified application key. + * + * @param[in] keyId Weave application group key identifier. + * @return root key number. + * + */ + static uint8_t GetRootKeyNumber(uint32_t keyId) + { + return (keyId & kMask_RootKeyNumber) >> kShift_RootKeyNumber; + } + + /** + * Get application group epoch key number that was used to derive specified application key. + * + * @param[in] keyId Weave application group key identifier. + * @return epoch key number. + * + */ + static uint8_t GetEpochKeyNumber(uint32_t keyId) + { + return (keyId & kMask_EpochKeyNumber) >> kShift_EpochKeyNumber; + } + + /** + * Get application group local number that was used to derive specified application key. + * + * @param[in] keyId Weave application group key identifier. + * @return application group local number. + * + */ + static uint8_t GetAppGroupLocalNumber(uint32_t keyId) + { + return (keyId & kMask_GroupLocalNumber) >> kShift_GroupLocalNumber; + } + + /** + * Construct application group root key ID given root key number. + * + * @param[in] rootKeyNumber Root key number. + * @return root key ID. + * + */ + static uint32_t MakeRootKeyId(uint8_t rootKeyNumber) + { + return kType_AppRootKey | (rootKeyNumber << kShift_RootKeyNumber); + } + + /** + * Construct application group root key ID given epoch key number. + * + * @param[in] epochKeyNumber Epoch key number. + * @return epoch key ID. + * + */ + static uint32_t MakeEpochKeyId(uint8_t epochKeyNumber) + { + return kType_AppEpochKey | (epochKeyNumber << kShift_EpochKeyNumber); + } + + /** + * Construct application group master key ID given application group local number. + * + * @param[in] appGroupLocalNumber Application group local number. + * @return application group master key ID. + * + */ + static uint32_t MakeAppGroupMasterKeyId(uint8_t appGroupLocalNumber) + { + return kType_AppGroupMasterKey | (appGroupLocalNumber << kShift_GroupLocalNumber); + } + + /** + * Convert application group key ID to application current key ID. + * + * @param[in] keyId Application key ID. + * @return application current key ID. + * + */ + static uint32_t ConvertToCurrentAppKeyId(uint32_t keyId) + { + return (keyId & ~kMask_EpochKeyNumber) | kFlag_UseCurrentEpochKey; + } + + /** + * Determine whether the specified application group key ID incorporates epoch key. + * + * @param[in] keyId Weave application group key identifier. + * @return true if the keyId incorporates epoch key. + * + */ + static bool IncorporatesEpochKey(uint32_t keyId) + { + return (keyId & kTypeModifier_IncorporatesEpochKey) != 0; + } + + static bool UsesCurrentEpochKey(uint32_t keyId); + static bool IncorporatesRootKey(uint32_t keyId); + static bool IncorporatesAppGroupMasterKey(uint32_t keyId); + + static uint32_t MakeAppKeyId(uint32_t keyType, uint32_t rootKeyId, uint32_t epochKeyId, + uint32_t appGroupMasterKeyId, bool useCurrentEpochKey); + static uint32_t MakeAppIntermediateKeyId(uint32_t rootKeyId, uint32_t epochKeyId, bool useCurrentEpochKey); + static uint32_t MakeAppRotatingKeyId(uint32_t rootKeyId, uint32_t epochKeyId, + uint32_t appGroupMasterKeyId, bool useCurrentEpochKey); + static uint32_t MakeAppStaticKeyId(uint32_t rootKeyId, uint32_t appGroupMasterKeyId); + static uint32_t ConvertToStaticAppKeyId(uint32_t keyId); + static uint32_t UpdateEpochKeyId(uint32_t keyId, uint32_t epochKeyId); + + static bool IsValidKeyId(uint32_t keyId); + static bool IsMessageEncryptionKeyId(uint32_t keyId, bool allowLogicalKeys = true); + static bool IsSameKeyOrGroup(uint32_t keyId1, uint32_t keyId2); + static const char *DescribeKey(uint32_t keyId); +}; + +} // namespace Weave +} // namespace nl + +#endif /* WEAVEKEYS_H_ */ From a30f563089b5dbba001fd168766e98c4bf463a55 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Tue, 24 Mar 2020 13:21:30 -0700 Subject: [PATCH 4/6] Fix namespace for ChipKeyIDs --- src/lib/core/{WeaveKeyIds.cpp => CHIPKeyIds.cpp} | 0 src/lib/core/{WeaveKeyIds.h => CHIPKeyIds.h} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/lib/core/{WeaveKeyIds.cpp => CHIPKeyIds.cpp} (100%) rename src/lib/core/{WeaveKeyIds.h => CHIPKeyIds.h} (100%) diff --git a/src/lib/core/WeaveKeyIds.cpp b/src/lib/core/CHIPKeyIds.cpp similarity index 100% rename from src/lib/core/WeaveKeyIds.cpp rename to src/lib/core/CHIPKeyIds.cpp diff --git a/src/lib/core/WeaveKeyIds.h b/src/lib/core/CHIPKeyIds.h similarity index 100% rename from src/lib/core/WeaveKeyIds.h rename to src/lib/core/CHIPKeyIds.h From e26cd7a1cc801e429fe3b36b4acba063a552a63c Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Tue, 24 Mar 2020 13:22:28 -0700 Subject: [PATCH 5/6] Fixes for building nRF5 platform code --- src/ble/CHIPBleServiceData.h | 4 +- src/include/platform/CHIPDeviceConfig.h | 2 +- src/include/platform/CHIPDeviceEvent.h | 5 +- src/include/platform/ConfigurationManager.h | 41 +---- .../platform/EFR32/ConfigurationManagerImpl.h | 1 - src/include/platform/GeneralUtils.h | 6 +- src/include/platform/PlatformManager.h | 32 ++-- src/include/platform/SoftwareUpdateManager.h | 14 +- .../platform/SoftwareUpdateManagerImpl.h | 8 +- src/include/platform/internal/BLEManager.h | 4 +- .../GenericConfigurationManagerImpl.h | 5 +- .../GenericConfigurationManagerImpl.ipp | 103 +---------- .../internal/GenericConnectivityManagerImpl.h | 11 +- .../internal/GenericPlatformManagerImpl.h | 2 - .../internal/GenericPlatformManagerImpl.ipp | 41 +---- .../GenericSoftwareUpdateManagerImpl.h | 22 +-- .../GenericSoftwareUpdateManagerImpl.ipp | 173 +----------------- .../internal/testing/ConfigUnitTest.h | 1 + src/include/platform/nRF5/BLEManagerImpl.h | 8 +- .../platform/nRF5/CHIPDevicePlatformConfig.h | 2 +- .../platform/nRF5/ConfigurationManagerImpl.h | 2 - src/include/platform/nRF5/GroupKeyStoreImpl.h | 17 +- src/lib/core/CHIPKeyIds.cpp | 65 ++++--- src/lib/core/CHIPKeyIds.h | 81 ++++---- src/lib/core/CHIPTLV.h | 6 +- src/lib/core/CHIPVendorIdentifiers.hpp | 2 +- src/lib/core/CoreLayer.am | 2 + src/lwip/Makefile.am | 118 +++++++++++- .../EFR32/ConfigurationManagerImpl.cpp | 13 -- src/platform/Makefile.am | 12 -- src/platform/nRF5/BLEManagerImpl.cpp | 13 +- .../nRF5/ConfigurationManagerImpl.cpp | 25 +-- src/platform/nRF5/ConnectivityManagerImpl.cpp | 14 +- src/platform/nRF5/PlatformManagerImpl.cpp | 2 +- .../nRF5/SoftwareUpdateManagerImpl.cpp | 8 +- src/platform/nRF5/nRF5Config.cpp | 18 +- src/platform/nRF5/nRF5Utils.cpp | 5 + 37 files changed, 315 insertions(+), 573 deletions(-) diff --git a/src/ble/CHIPBleServiceData.h b/src/ble/CHIPBleServiceData.h index c9c992e6c0c2a2..de63e3d21d0ec8 100644 --- a/src/ble/CHIPBleServiceData.h +++ b/src/ble/CHIPBleServiceData.h @@ -23,6 +23,8 @@ #ifndef CHIP_BLE_SERVICE_DATA_H #define CHIP_BLE_SERVICE_DATA_H +#include + namespace chip { namespace Ble { @@ -41,7 +43,7 @@ enum chipBLEServiceDataType * Defines the over-the-air encoded format of the device identification information block that appears * within chip BLE service advertisement data. */ -struct chipBLEDeviceIdentificationInfo +struct ChipBLEDeviceIdentificationInfo { enum { diff --git a/src/include/platform/CHIPDeviceConfig.h b/src/include/platform/CHIPDeviceConfig.h index 11551da3c50a07..6689b6e016929b 100644 --- a/src/include/platform/CHIPDeviceConfig.h +++ b/src/include/platform/CHIPDeviceConfig.h @@ -403,7 +403,7 @@ * using the chip Time Sync protocol. */ #ifndef CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC -#define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 1 +#define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 0 #endif /** diff --git a/src/include/platform/CHIPDeviceEvent.h b/src/include/platform/CHIPDeviceEvent.h index 92049068ccf9aa..ac6eca2898a34b 100644 --- a/src/include/platform/CHIPDeviceEvent.h +++ b/src/include/platform/CHIPDeviceEvent.h @@ -270,6 +270,8 @@ typedef void (*AsyncWorkFunct)(intptr_t arg); #include CHIPDEVICEPLATFORMEVENT_HEADER #endif +#include + namespace chip { namespace DeviceLayer { @@ -353,7 +355,6 @@ struct ChipDeviceEvent final uint64_t PeerNodeId; uint16_t SessionKeyId; uint8_t EncType; - ::chip::ChipAuthMode AuthMode; bool IsCommissioner; } SessionEstablished; struct @@ -367,7 +368,7 @@ struct ChipDeviceEvent final struct { BLE_CONNECTION_OBJECT ConId; - PacketBuffer * Data; + chip::System::PacketBuffer * Data; } CHIPoBLEWriteReceived; struct { diff --git a/src/include/platform/ConfigurationManager.h b/src/include/platform/ConfigurationManager.h index 0355efa190c868..3aa9d712744d3b 100644 --- a/src/include/platform/ConfigurationManager.h +++ b/src/include/platform/ConfigurationManager.h @@ -24,8 +24,6 @@ #define CONFIGURATION_MANAGER_H #include -#include -#include namespace chip { namespace Ble { @@ -38,11 +36,8 @@ namespace DeviceLayer { class PlatformManagerImpl; class ConfigurationManagerImpl; -class TraitManager; namespace Internal { template class GenericPlatformManagerImpl; -class DeviceControlServer; -class NetworkProvisioningServer; } /** @@ -50,8 +45,6 @@ class NetworkProvisioningServer; */ class ConfigurationManager { - using ChipDeviceDescriptor = ::chip::Profiles::DeviceDescription::ChipDeviceDescriptor; - public: // ===== Members that define the public interface of the ConfigurationManager @@ -59,8 +52,8 @@ class ConfigurationManager enum { kMaxPairingCodeLength = 15, - kMaxSerialNumberLength = ChipDeviceDescriptor::kMaxSerialNumberLength, - kMaxFirmwareRevisionLength = ChipDeviceDescriptor::kMaxSoftwareVersionLength, + kMaxSerialNumberLength = 32, + kMaxFirmwareRevisionLength = 32, }; CHIP_ERROR GetVendorId(uint16_t & vendorId); @@ -109,8 +102,6 @@ class ConfigurationManager CHIP_ERROR StoreServiceConfig(const uint8_t * serviceConfig, size_t serviceConfigLen); CHIP_ERROR StorePairedAccountId(const char * accountId, size_t accountIdLen); - CHIP_ERROR GetDeviceDescriptor(ChipDeviceDescriptor & deviceDesc); - CHIP_ERROR GetDeviceDescriptorTLV(uint8_t * buf, size_t bufSize, size_t & encodedLen); CHIP_ERROR GetQRCodeString(char * buf, size_t bufSize); CHIP_ERROR GetWiFiAPSSID(char * buf, size_t bufSize); @@ -135,17 +126,14 @@ class ConfigurationManager friend class ::chip::DeviceLayer::PlatformManagerImpl; template friend class ::chip::DeviceLayer::Internal::GenericPlatformManagerImpl; - friend class ::chip::DeviceLayer::TraitManager; - friend class ::chip::DeviceLayer::Internal::DeviceControlServer; // 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)); + 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); using ImplClass = ConfigurationManagerImpl; CHIP_ERROR Init(); CHIP_ERROR ConfigureChipStack(); - ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase * GetGroupKeyStore(); bool CanFactoryReset(); CHIP_ERROR GetFailSafeArmed(bool & val); CHIP_ERROR SetFailSafeArmed(bool val); @@ -429,16 +417,6 @@ inline CHIP_ERROR ConfigurationManager::WritePersistedStorageValue(::chip::Platf return static_cast(this)->_WritePersistedStorageValue(key, value); } -inline CHIP_ERROR ConfigurationManager::GetDeviceDescriptor(chipDeviceDescriptor & deviceDesc) -{ - return static_cast(this)->_GetDeviceDescriptor(deviceDesc); -} - -inline CHIP_ERROR ConfigurationManager::GetDeviceDescriptorTLV(uint8_t * buf, size_t bufSize, size_t & encodedLen) -{ - return static_cast(this)->_GetDeviceDescriptorTLV(buf, bufSize, encodedLen); -} - inline CHIP_ERROR ConfigurationManager::GetQRCodeString(char * buf, size_t bufSize) { return static_cast(this)->_GetQRCodeString(buf, bufSize); @@ -449,7 +427,7 @@ inline CHIP_ERROR ConfigurationManager::GetWiFiAPSSID(char * buf, size_t bufSize return static_cast(this)->_GetWiFiAPSSID(buf, bufSize); } -inline CHIP_ERROR ConfigurationManager::GetBLEDeviceIdentificationInfo(Ble::chipBLEDeviceIdentificationInfo & deviceIdInfo) +inline CHIP_ERROR ConfigurationManager::GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) { return static_cast(this)->_GetBLEDeviceIdentificationInfo(deviceIdInfo); } @@ -489,14 +467,9 @@ inline CHIP_ERROR ConfigurationManager::Init() return static_cast(this)->_Init(); } -inline CHIP_ERROR ConfigurationManager::ConfigurechipStack() -{ - return static_cast(this)->_ConfigurechipStack(); -} - -inline ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase * ConfigurationManager::GetGroupKeyStore() +inline CHIP_ERROR ConfigurationManager::ConfigureChipStack() { - return static_cast(this)->_GetGroupKeyStore(); + return static_cast(this)->_ConfigureChipStack(); } inline bool ConfigurationManager::CanFactoryReset() diff --git a/src/include/platform/EFR32/ConfigurationManagerImpl.h b/src/include/platform/EFR32/ConfigurationManagerImpl.h index 06df533f3a0479..15427b39ce7637 100644 --- a/src/include/platform/EFR32/ConfigurationManagerImpl.h +++ b/src/include/platform/EFR32/ConfigurationManagerImpl.h @@ -54,7 +54,6 @@ class ConfigurationManagerImpl final : public ConfigurationManager, CHIP_ERROR _Init(void); CHIP_ERROR _GetPrimaryWiFiMACAddress(uint8_t *buf); - CHIP_ERROR _GetDeviceDescriptor(::chip::Profiles::DeviceDescription::ChipDeviceDescriptor &deviceDesc); ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase *_GetGroupKeyStore(void); bool _CanFactoryReset(void); void _InitiateFactoryReset(void); diff --git a/src/include/platform/GeneralUtils.h b/src/include/platform/GeneralUtils.h index e73abaa0506e93..c383f9905c1826 100644 --- a/src/include/platform/GeneralUtils.h +++ b/src/include/platform/GeneralUtils.h @@ -20,13 +20,15 @@ * General utility functions available on all platforms. */ +#include + namespace chip { namespace DeviceLayer { extern CHIP_ERROR ParseCompilerDateStr(const char * dateStr, uint16_t & year, uint8_t & month, uint8_t & dayOfMonth); extern CHIP_ERROR Parse24HourTimeStr(const char * timeStr, uint8_t & hour, uint8_t & minute, uint8_t & second); -extern const char * CharacterizeIPv6Address(const ::Inet::IPAddress & ipAddr); -extern const char * CharacterizeIPv6Prefix(const Inet::IPPrefix & inPrefix); +extern const char * CharacterizeIPv6Address(const chip::Inet::IPAddress &ipAddr); +extern const char * CharacterizeIPv6Prefix(const chip::Inet::IPPrefix &inPrefix); extern void RegisterDeviceLayerErrorFormatter(void); extern bool FormatDeviceLayerError(char * buf, uint16_t bufSize, int32_t err); diff --git a/src/include/platform/PlatformManager.h b/src/include/platform/PlatformManager.h index be6af27e68b694..934d838c04b645 100644 --- a/src/include/platform/PlatformManager.h +++ b/src/include/platform/PlatformManager.h @@ -102,10 +102,10 @@ class PlatformManager template friend class Internal::GenericThreadStackManagerImpl_OpenThread_LwIP; template friend class Internal::GenericConfigurationManagerImpl; // Parentheses used to fix clang parsing issue with these declarations - friend ::chip::System::Error (::chip::System::Platform::Layer::PostEvent(::chip::System::Layer & aLayer, void * aContext, ::chip::System::Object & aTarget, ::chip::System::EventType aType, uintptr_t aArgument)); - friend ::chip::System::Error (::chip::System::Platform::Layer::DispatchEvents(::chip::System::Layer & aLayer, void * aContext)); - friend ::chip::System::Error (::chip::System::Platform::Layer::DispatchEvent(::chip::System::Layer & aLayer, void * aContext, ::chip::System::Event aEvent)); - friend ::chip::System::Error (::chip::System::Platform::Layer::StartTimer(::chip::System::Layer & aLayer, void * aContext, uint32_t aMilliseconds)); + friend ::chip::System::Error ::chip::System::Platform::Layer::PostEvent(::chip::System::Layer & aLayer, void * aContext, ::chip::System::Object & aTarget, ::chip::System::EventType aType, uintptr_t aArgument); + friend ::chip::System::Error ::chip::System::Platform::Layer::DispatchEvents(::chip::System::Layer & aLayer, void * aContext); + friend ::chip::System::Error ::chip::System::Platform::Layer::DispatchEvent(::chip::System::Layer & aLayer, void * aContext, ::chip::System::Event aEvent); + friend ::chip::System::Error ::chip::System::Platform::Layer::StartTimer(::chip::System::Layer & aLayer, void * aContext, uint32_t aMilliseconds); void PostEvent(const ChipDeviceEvent * event); void DispatchEvent(const ChipDeviceEvent * event); @@ -155,9 +155,9 @@ extern PlatformManagerImpl & PlatformMgrImpl(void); namespace chip { namespace DeviceLayer { -inline CHIP_ERROR PlatformManager::InitchipStack() +inline CHIP_ERROR PlatformManager::InitChipStack() { - return static_cast(this)->_InitchipStack(); + return static_cast(this)->_InitChipStack(); } inline CHIP_ERROR PlatformManager::AddEventHandler(EventHandlerFunct handler, intptr_t arg) @@ -185,34 +185,34 @@ inline CHIP_ERROR PlatformManager::StartEventLoopTask(void) return static_cast(this)->_StartEventLoopTask(); } -inline void PlatformManager::LockchipStack(void) +inline void PlatformManager::LockChipStack(void) { - static_cast(this)->_LockchipStack(); + static_cast(this)->_LockChipStack(); } -inline bool PlatformManager::TryLockchipStack(void) +inline bool PlatformManager::TryLockChipStack(void) { - return static_cast(this)->_TryLockchipStack(); + return static_cast(this)->_TryLockChipStack(); } -inline void PlatformManager::UnlockchipStack(void) +inline void PlatformManager::UnlockChipStack(void) { - static_cast(this)->_UnlockchipStack(); + static_cast(this)->_UnlockChipStack(); } -inline void PlatformManager::PostEvent(const chipDeviceEvent * event) +inline void PlatformManager::PostEvent(const ChipDeviceEvent * event) { static_cast(this)->_PostEvent(event); } -inline void PlatformManager::DispatchEvent(const chipDeviceEvent * event) +inline void PlatformManager::DispatchEvent(const ChipDeviceEvent * event) { static_cast(this)->_DispatchEvent(event); } -inline CHIP_ERROR PlatformManager::StartchipTimer(uint32_t durationMS) +inline CHIP_ERROR PlatformManager::StartChipTimer(uint32_t durationMS) { - return static_cast(this)->_StartchipTimer(durationMS); + return static_cast(this)->_StartChipTimer(durationMS); } } // namespace DeviceLayer diff --git a/src/include/platform/SoftwareUpdateManager.h b/src/include/platform/SoftwareUpdateManager.h index 7b5386ab401b3b..f55ecc2823ae0e 100644 --- a/src/include/platform/SoftwareUpdateManager.h +++ b/src/include/platform/SoftwareUpdateManager.h @@ -25,20 +25,18 @@ #if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER -#include #include +#include namespace chip { namespace DeviceLayer { +using namespace chip::TLV; + class SoftwareUpdateManagerImpl; class SoftwareUpdateManager { - typedef ::chip::TLV::TLVWriter TLVWriter; - typedef ::chip::Profiles::SoftwareUpdate::UpdatePriority UpdatePriority; - typedef ::chip::Profiles::SoftwareUpdate::UpdateCondition UpdateCondition; - using ImplClass = SoftwareUpdateManagerImpl; @@ -363,6 +361,8 @@ extern SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void); namespace chip { namespace DeviceLayer { +using namespace chip::TLV; + union SoftwareUpdateManager::InEventParam { void Clear(void) { memset(this, 0, sizeof(*this)); } @@ -376,13 +376,10 @@ union SoftwareUpdateManager::InEventParam struct { CHIP_ERROR Error; - Profiles::StatusReporting::StatusReport *StatusReport; } QueryPrepareFailed; struct { - UpdatePriority Priority; - UpdateCondition Condition; uint8_t IntegrityType; const char *URI; const char *Version; @@ -415,7 +412,6 @@ union SoftwareUpdateManager::InEventParam struct { CHIP_ERROR Error; - Profiles::StatusReporting::StatusReport *StatusReport; } Finished; }; diff --git a/src/include/platform/SoftwareUpdateManagerImpl.h b/src/include/platform/SoftwareUpdateManagerImpl.h index ec94bda0a9ac96..b8c76ab899b0af 100644 --- a/src/include/platform/SoftwareUpdateManagerImpl.h +++ b/src/include/platform/SoftwareUpdateManagerImpl.h @@ -21,7 +21,6 @@ #if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER #include -#include namespace chip { namespace DeviceLayer { @@ -32,8 +31,7 @@ namespace DeviceLayer { */ class SoftwareUpdateManagerImpl final : public SoftwareUpdateManager, - public Internal::GenericSoftwareUpdateManagerImpl, - public Internal::GenericSoftwareUpdateManagerImpl_BDX + public Internal::GenericSoftwareUpdateManagerImpl { // Allow the SoftwareUpdateManager interface class to delegate method calls to // the implementation methods provided by this class. @@ -43,10 +41,6 @@ class SoftwareUpdateManagerImpl final // and types defined on this class. friend class Internal::GenericSoftwareUpdateManagerImpl; - // Allow the GenericSoftwareUpdateManagerImpl_BDX base class to access helper methods - // and types defined on this class. - friend class Internal::GenericSoftwareUpdateManagerImpl_BDX; - public: // ===== Members for internal use by the following friends. diff --git a/src/include/platform/internal/BLEManager.h b/src/include/platform/internal/BLEManager.h index c6b84177e24568..62fb2513118b3a 100644 --- a/src/include/platform/internal/BLEManager.h +++ b/src/include/platform/internal/BLEManager.h @@ -62,7 +62,7 @@ class BLEManager CHIP_ERROR SetDeviceName(const char * deviceName); uint16_t NumConnections(void); void OnPlatformEvent(const ChipDeviceEvent * event); - ::Ble::BleLayer * GetBleLayer(void) const; + chip::Ble::BleLayer * GetBleLayer(void) const; protected: @@ -170,7 +170,7 @@ inline void BLEManager::OnPlatformEvent(const ChipDeviceEvent * event) static_cast(this)->_OnPlatformEvent(event); } -inline ::Ble::BleLayer * BLEManager::GetBleLayer(void) const +inline BleLayer * BLEManager::GetBleLayer(void) const { return static_cast(this)->_GetBleLayer(); } diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.h b/src/include/platform/internal/GenericConfigurationManagerImpl.h index c53cc2c266b4ac..c4edfa4d83b860 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -96,11 +96,10 @@ class GenericConfigurationManagerImpl CHIP_ERROR _ClearServiceProvisioningData(); CHIP_ERROR _GetFailSafeArmed(bool & val); CHIP_ERROR _SetFailSafeArmed(bool val); - CHIP_ERROR _GetDeviceDescriptor(::chip::Profiles::DeviceDescription::ChipeviceDescriptor & deviceDesc); - CHIP_ERROR _GetDeviceDescriptorTLV(uint8_t * buf, size_t bufSize, size_t & encodedLen); CHIP_ERROR _GetQRCodeString(char * buf, size_t bufSize); CHIP_ERROR _GetWiFiAPSSID(char * buf, size_t bufSize); CHIP_ERROR _GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo); + CHIP_ERROR _ConfigureChipStack(); bool _IsServiceProvisioned(); bool _IsMemberOfFabric(); bool _IsPairedToAccount(); @@ -131,7 +130,7 @@ class GenericConfigurationManagerImpl ImplClass * Impl() { return static_cast(this); } - static void HashLengthAndBase64Value(Platform::Security::SHA256 & hash, const uint8_t * val, uint16_t valLen); + // static void HashLengthAndBase64Value(Platform::Security::SHA256 & hash, const uint8_t * val, uint16_t valLen); #if CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING bool UseManufacturerCredentialsAsOperational(); diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp index 961899e20e475b..b55806733ffd1a 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp @@ -84,9 +84,6 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ConfigureChipStack() } SuccessOrExit(err); - // Configure the FabricState object with a reference to the GroupKeyStore object. - FabricState.GroupKeyStore = Impl()->_GetGroupKeyStore(); - #if CHIP_PROGRESS_LOGGING Impl()->LogDeviceConfig(); @@ -704,96 +701,11 @@ CHIP_ERROR GenericConfigurationManagerImpl::_SetFailSafeArmed(bool va return Impl()->WriteConfigValue(ImplClass::kConfigKey_FailSafeArmed, val); } -template -CHIP_ERROR GenericConfigurationManagerImpl::_GetDeviceDescriptor(::chip::Profiles::DeviceDescription::ChipDeviceDescriptor & deviceDesc) -{ - CHIP_ERROR err; - size_t outLen; - - deviceDesc.Clear(); - - deviceDesc.DeviceId = FabricState.LocalNodeId; - - deviceDesc.FabricId = FabricState.FabricId; - - err = Impl()->_GetVendorId(deviceDesc.VendorId); - SuccessOrExit(err); - - err = Impl()->_GetProductId(deviceDesc.ProductId); - SuccessOrExit(err); - - err = Impl()->_GetProductRevision(deviceDesc.ProductRevision); - SuccessOrExit(err); - - err = Impl()->_GetManufacturingDate(deviceDesc.ManufacturingDate.Year, deviceDesc.ManufacturingDate.Month, deviceDesc.ManufacturingDate.Day); - if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) - { - err = CHIP_NO_ERROR; - } - SuccessOrExit(err); - - err = Impl()->_GetPrimaryWiFiMACAddress(deviceDesc.PrimaryWiFiMACAddress); - if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) - { - err = CHIP_NO_ERROR; - } - SuccessOrExit(err); - - err = Impl()->_GetPrimary802154MACAddress(deviceDesc.Primary802154MACAddress); - if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) - { - err = CHIP_NO_ERROR; - } - SuccessOrExit(err); - - err = Impl()->_GetWiFiAPSSID(deviceDesc.RendezvousWiFiESSID, sizeof(deviceDesc.RendezvousWiFiESSID)); - if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) - { - err = CHIP_NO_ERROR; - } - SuccessOrExit(err); - - err = Impl()->_GetSerialNumber(deviceDesc.SerialNumber, sizeof(deviceDesc.SerialNumber), outLen); - if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) - { - err = CHIP_NO_ERROR; - } - SuccessOrExit(err); - - err = Impl()->_GetFirmwareRevision(deviceDesc.SoftwareVersion, sizeof(deviceDesc.SoftwareVersion), outLen); - if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) - { - err = CHIP_NO_ERROR; - } - SuccessOrExit(err); - -exit: - return err; -} - -template -CHIP_ERROR GenericConfigurationManagerImpl::_GetDeviceDescriptorTLV(uint8_t * buf, size_t bufSize, size_t & encodedLen) -{ - CHIP_ERROR err; - ::chip::Profiles::DeviceDescription::ChipDeviceDescriptor deviceDesc; - - err = Impl()->_GetDeviceDescriptor(deviceDesc); - SuccessOrExit(err); - - { - uint32_t tmp = 0; - err = ::chip::Profiles::DeviceDescription::ChipDeviceDescriptor::EncodeTLV(deviceDesc, buf, (uint32_t)bufSize, tmp); - SuccessOrExit(err); - encodedLen = tmp; - } - -exit: - return err; -} - template CHIP_ERROR GenericConfigurationManagerImpl::_GetQRCodeString(char * buf, size_t bufSize) { + return CHIP_ERROR_NOT_IMPLEMENTED; +/* Commented out for time being, until we have Device Description service CHIP_ERROR err; ::chip::Profiles::DeviceDescription::ChipDeviceDescriptor deviceDesc; uint32_t encodedLen; @@ -809,6 +721,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetQRCodeString(char * b exit: return err; +*/ } template @@ -969,7 +882,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ComputeProvisioningHash( SuccessOrExit(err); // Hash the length and value of the device certificate in base-64 form. - HashLengthAndBase64Value(hash, dataBuf, (uint16_t)certLen); + // HashLengthAndBase64Value(hash, dataBuf, (uint16_t)certLen); } // Hash the device intermediate CA certificates @@ -997,7 +910,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ComputeProvisioningHash( SuccessOrExit(err); // Hash the length and value of the device intermediate CA certificates in base-64 form. - HashLengthAndBase64Value(hash, dataBuf, (uint16_t)certsLen); + // HashLengthAndBase64Value(hash, dataBuf, (uint16_t)certsLen); } // Hash the device private key @@ -1015,7 +928,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ComputeProvisioningHash( SuccessOrExit(err); // Hash the length and value of the private key in base-64 form. - HashLengthAndBase64Value(hash, dataBuf, (uint16_t)keyLen); + // HashLengthAndBase64Value(hash, dataBuf, (uint16_t)keyLen); } // Hash the device pairing code. If the device does not have a pairing code, hash a zero-length value. @@ -1048,7 +961,7 @@ exit: } return err; } - +/* template void GenericConfigurationManagerImpl::HashLengthAndBase64Value(Platform::Security::SHA256 & hash, const uint8_t * val, uint16_t valLen) { @@ -1072,7 +985,7 @@ void GenericConfigurationManagerImpl::HashLengthAndBase64Value(Platfo valLen -= chunkLen; } } - +*/ #if CHIP_PROGRESS_LOGGING template diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl.h b/src/include/platform/internal/GenericConnectivityManagerImpl.h index 2e563ecbdb6232..c57779cfc2bd32 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl.h @@ -24,9 +24,6 @@ #ifndef GENERIC_CONNECTIVITY_MANAGER_IMPL_H #define GENERIC_CONNECTIVITY_MANAGER_IMPL_H -#include - - namespace chip { namespace DeviceLayer { namespace Internal { @@ -59,25 +56,25 @@ class GenericConnectivityManagerImpl template inline bool GenericConnectivityManagerImpl::_IsUserSelectedModeActive(void) { - return DeviceDescriptionSvr().IsUserSelectedModeActive(); + return false; //DeviceDescriptionSvr().IsUserSelectedModeActive(); } template inline void GenericConnectivityManagerImpl::_SetUserSelectedMode(bool val) { - DeviceDescriptionSvr().SetUserSelectedMode(val); + //DeviceDescriptionSvr().SetUserSelectedMode(val); } template inline uint16_t GenericConnectivityManagerImpl::_GetUserSelectedModeTimeout(void) { - return DeviceDescriptionSvr().GetUserSelectedModeTimeout(); + return 0; //DeviceDescriptionSvr().GetUserSelectedModeTimeout(); } template inline void GenericConnectivityManagerImpl::_SetUserSelectedModeTimeout(uint16_t val) { - DeviceDescriptionSvr().SetUserSelectedModeTimeout(val); + //DeviceDescriptionSvr().SetUserSelectedModeTimeout(val); } diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.h b/src/include/platform/internal/GenericPlatformManagerImpl.h index 5d5eb3e887ded0..e7091c3b878721 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl.h +++ b/src/include/platform/internal/GenericPlatformManagerImpl.h @@ -63,8 +63,6 @@ class GenericPlatformManagerImpl void DispatchEventToSystemLayer(const ChipDeviceEvent * event); void DispatchEventToDeviceLayer(const ChipDeviceEvent * event); void DispatchEventToApplication(const ChipDeviceEvent * event); - static void HandleSessionEstablished(ChipSecurityManager * sm, ChipConnection * con, - void * reqState, uint16_t sessionKeyId, uint64_t peerNodeId, uint8_t encType); static void HandleMessageLayerActivityChanged(bool messageLayerIsActive); private: diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.ipp b/src/include/platform/internal/GenericPlatformManagerImpl.ipp index 2ec741cf6f49b0..6e583292fc0beb 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl.ipp +++ b/src/include/platform/internal/GenericPlatformManagerImpl.ipp @@ -32,6 +32,9 @@ #include #include +#include +#include + namespace chip { namespace DeviceLayer { namespace Internal { @@ -81,18 +84,6 @@ CHIP_ERROR GenericPlatformManagerImpl::_InitChipStack(void) } SuccessOrExit(err); - { - ChipMessageLayer::InitContext initContext; - initContext.systemLayer = &SystemLayer; - initContext.inet = &InetLayer; - initContext.listenTCP = true; - initContext.listenUDP = true; -#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - initContext.ble = BLEMgr().GetBleLayer(); - initContext.listenBLE = true; -#endif - } - // Perform dynamic configuration of the core CHIP objects based on stored settings. // // NB: In general, initialization of Device Layer objects should happen *after* this call @@ -303,32 +294,6 @@ void GenericPlatformManagerImpl::DispatchEventToApplication(const Chi } } -template -void GenericPlatformManagerImpl::HandleSessionEstablished(ChipSecurityManager * sm, ChipConnection * con, void * reqState, uint16_t sessionKeyId, uint64_t peerNodeId, uint8_t encType) -{ - // Get the auth mode for the newly established session key. - ChipSessionKey * sessionKey; - FabricState.GetSessionKey(sessionKeyId, peerNodeId, sessionKey); - ChipAuthMode authMode = (sessionKey != NULL) ? sessionKey->AuthMode : (ChipAuthMode)kChipAuthMode_NotSpecified; - - // Post a SessionEstablished event for the new session. If a PASE session is established - // using the device's pairing code, presume that this is a commissioner and set the - // IsCommissioner flag as a convenience to the application. - ChipDeviceEvent event; - event.Type = DeviceEventType::kSessionEstablished; - event.SessionEstablished.PeerNodeId = peerNodeId; - event.SessionEstablished.SessionKeyId = sessionKeyId; - event.SessionEstablished.EncType = encType; - event.SessionEstablished.AuthMode = authMode; - event.SessionEstablished.IsCommissioner = (authMode == kChipAuthMode_PASE_PairingCode); - PlatformMgr().PostEvent(&event); - - if (event.SessionEstablished.IsCommissioner) - { - ChipLogProgress(DeviceLayer, "Commissioner session established"); - } -} - template void GenericPlatformManagerImpl::HandleMessageLayerActivityChanged(bool messageLayerIsActive) { diff --git a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.h b/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.h index 642f459ea2de35..cb073b1225f0c3 100644 --- a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.h +++ b/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.h @@ -32,6 +32,8 @@ namespace chip { namespace DeviceLayer { namespace Internal { +using namespace chip::Inet; + /** * Provides a generic implementation of Software Update Manager features that works on multiple platforms. * @@ -43,7 +45,6 @@ namespace Internal { template class GenericSoftwareUpdateManagerImpl { - using StatusReport = ::chip::Profiles::StatusReporting::StatusReport; protected: // ===== Methods that implement the SoftwareUpdateManager abstract interface. @@ -68,13 +69,10 @@ class GenericSoftwareUpdateManagerImpl void DoInit(); void DownloadComplete(void); - void SoftwareUpdateFailed(CHIP_ERROR aError, StatusReport * aStatusReport); void SoftwareUpdateFinished(CHIP_ERROR aError); CHIP_ERROR InstallImage(void); CHIP_ERROR StoreImageBlock(uint32_t aLength, uint8_t *aData); - CHIP_ERROR GetIntegrityTypeList(::chip::Profiles::SoftwareUpdate::IntegrityTypeList * aIntegrityTypeList); - private: // ===== Private members reserved for use by this class only. @@ -84,7 +82,6 @@ class GenericSoftwareUpdateManagerImpl void DriveState(SoftwareUpdateManager::State aNextState); void GetEventState(int32_t& aEventState); void HandleImageQueryResponse(PacketBuffer * aPayload); - void HandleStatusReport(PacketBuffer * aPayload); void SendQuery(void); void StartImageInstall(void); void PrepareImageStorage(void); @@ -99,17 +96,6 @@ class GenericSoftwareUpdateManagerImpl static void HandleHoldOffTimerExpired(::chip::System::Layer * aLayer, void * aAppState, ::chip::System::Error aError); - static void HandleServiceBindingEvent(void * appState, ::chip::Binding::EventType eventType, - const ::chip::Binding::InEventParam & inParam, - ::chip::Binding::OutEventParam & outParam); - static void HandleResponse(ExchangeContext * ec, - const IPPacketInfo * pktInfo, - const ChipMessageInfo * msgInfo, - uint32_t profileId, - uint8_t msgType, - PacketBuffer * payload); - static void OnKeyError(ExchangeContext *aEc, CHIP_ERROR aKeyError); - static void OnResponseTimeout(ExchangeContext * aEC); static void DefaultRetryPolicyCallback(void * const aAppState, SoftwareUpdateManager::RetryParam & aRetryParam, uint32_t & aOutIntervalMsec); @@ -121,7 +107,6 @@ class GenericSoftwareUpdateManagerImpl void * mAppState; char mURI[CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_URI_LEN]; - ::chip::Profiles::SoftwareUpdate::IntegritySpec mIntegritySpec; SoftwareUpdateManager::EventCallback mEventHandlerCallback; SoftwareUpdateManager::RetryPolicyCallback mRetryPolicyCallback; @@ -141,9 +126,6 @@ class GenericSoftwareUpdateManagerImpl uint16_t mRetryCounter; - Binding * mBinding; - ExchangeContext * mExchangeCtx; - ImplClass * Impl() { return static_cast(this); } }; diff --git a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.ipp b/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.ipp index c501f26bb30d8a..b7148675d0e2b8 100644 --- a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.ipp +++ b/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.ipp @@ -36,16 +36,18 @@ #include #include +#include +#include + namespace chip { namespace DeviceLayer { namespace Internal { using namespace ::chip; using namespace ::chip::TLV; -using namespace ::chip::Profiles; -using namespace ::chip::Profiles::Common; -using namespace ::chip::Profiles::DataManagement; -using namespace ::chip::Profiles::SoftwareUpdate; + +#define LogEvent(...) +#define NullifyAllEventFields(...) // Fully instantiate the generic implementation class in whatever compilation unit includes this file. template class GenericSoftwareUpdateManagerImpl; @@ -120,16 +122,6 @@ void GenericSoftwareUpdateManagerImpl::PrepareBinding(intptr_t arg) ExitNow(err = CHIP_ERROR_NOT_CONNECTED); } - self->mBinding = ExchangeMgr.NewBinding(HandleServiceBindingEvent, NULL); - VerifyOrExit(self->mBinding != NULL, err = CHIP_ERROR_NO_MEMORY); - - err = self->mBinding->BeginConfiguration() - .Target_ServiceEndpoint(CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_ENDPOINT_ID) - .Transport_UDP_WRM() - .Exchange_ResponseTimeoutMsec(CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_RESPOSNE_TIMEOUT) - .Security_SharedCASESession() - .PrepareBinding(); - exit: if (err != CHIP_NO_ERROR) { @@ -317,8 +309,7 @@ void GenericSoftwareUpdateManagerImpl::GetEventState(int32_t& aEventS } template -void GenericSoftwareUpdateManagerImpl::SoftwareUpdateFailed(CHIP_ERROR aError, - Profiles::StatusReporting::StatusReport * aStatusReport) +void GenericSoftwareUpdateManagerImpl::SoftwareUpdateFailed(CHIP_ERROR aError) { SoftwareUpdateManager::InEventParam inParam; SoftwareUpdateManager::OutEventParam outParam; @@ -349,16 +340,7 @@ void GenericSoftwareUpdateManagerImpl::SoftwareUpdateFailed(CHIP_ERRO ev.platformReturnCode = aError; ev.SetPrimaryStatusCodeNull(); - if (aStatusReport) - { - ev. SetRemoteStatusCodePresent(); - ev.remoteStatusCode.profileId = aStatusReport->mProfileId; - ev.remoteStatusCode.statusCode = aStatusReport->mStatusCode; - } - else - { - ev.SetRemoteStatusCodeNull(); - } + ev.SetRemoteStatusCodeNull(); LogEvent(&ev, evOptions); } @@ -366,13 +348,11 @@ void GenericSoftwareUpdateManagerImpl::SoftwareUpdateFailed(CHIP_ERRO if (mState == SoftwareUpdateManager::kState_PrepareQuery) { inParam.QueryPrepareFailed.Error = aError; - inParam.QueryPrepareFailed.StatusReport = aStatusReport; mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_QueryPrepareFailed, inParam, outParam); } else { inParam.Finished.Error = aError; - inParam.Finished.StatusReport = aStatusReport; mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_Finished, inParam, outParam); } @@ -445,19 +425,6 @@ void GenericSoftwareUpdateManagerImpl::SendQuery(void) inParam.Clear(); outParam.Clear(); - // Configure the context - mExchangeCtx->AppState = this; - mExchangeCtx->OnMessageReceived = HandleResponse; - mExchangeCtx->OnResponseTimeout = OnResponseTimeout; - mExchangeCtx->OnKeyError = OnKeyError; - - // Send the query - err = mExchangeCtx->SendMessage(kChipProfile_SWU, - kMsgType_ImageQuery, - mImageQueryPacketBuffer, - ExchangeContext::kSendFlag_ExpectResponse | ExchangeContext::kSendFlag_RequestAck); - SuccessOrExit(err); - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_QuerySent, inParam, outParam); VerifyOrExit(mState == SoftwareUpdateManager::kState_Query, err = CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED); @@ -468,56 +435,6 @@ exit: } } -template -void GenericSoftwareUpdateManagerImpl::OnResponseTimeout(ExchangeContext * aEC) -{ - GenericSoftwareUpdateManagerImpl * self = &SoftwareUpdateMgrImpl(); - self->Impl()->SoftwareUpdateFailed(CHIP_ERROR_TIMEOUT, NULL); -} - -template -void GenericSoftwareUpdateManagerImpl::OnKeyError(ExchangeContext *aEc, CHIP_ERROR aKeyError) -{ - GenericSoftwareUpdateManagerImpl * self = &SoftwareUpdateMgrImpl(); - self->Impl()->SoftwareUpdateFailed(aKeyError, NULL); -} - -template -void GenericSoftwareUpdateManagerImpl::HandleResponse(ExchangeContext * ec, const IPPacketInfo * pktInfo, const ChipMessageInfo * msgInfo, - uint32_t profileId, uint8_t msgType, PacketBuffer * payload) -{ - GenericSoftwareUpdateManagerImpl * self = &SoftwareUpdateMgrImpl(); - - VerifyOrDie(ec == self->mExchangeCtx); - - // Close the exchange. When using WRM, this will force an standalone-ACK to be - // sent immediately. - self->mExchangeCtx->Close(); - self->mExchangeCtx = NULL; - - // We expect to receive one of two possible responses: - // 1. An ImageQueryResponse message under the CHIP software update profile indicating - // an update might be available or - // 2. A StatusReport indicating no software update available or a problem with the query. - // - // NOTE: the Handle* methods are responsible for releasing the buffer. - // - if (profileId == kChipProfile_SWU && msgType == kMsgType_ImageQueryResponse) - { - self->HandleImageQueryResponse(payload); - } - else if (profileId == kChipProfile_Common && msgType == kMsgType_StatusReport) - { - self->HandleStatusReport(payload); - } - else - { - // If any other message type is received, fail with an error. - PacketBuffer::Free(payload); - self->Impl()->SoftwareUpdateFailed(CHIP_ERROR_INVALID_MESSAGE_TYPE, NULL); - } -} - template void GenericSoftwareUpdateManagerImpl::HandleStatusReport(PacketBuffer * payload) { @@ -840,59 +757,6 @@ void GenericSoftwareUpdateManagerImpl::_DefaultEventHandler(void *apA aOutParam.DefaultHandlerCalled = true; } -template -void GenericSoftwareUpdateManagerImpl::HandleServiceBindingEvent(void * appState, ::chip::Binding::EventType eventType, - const ::chip::Binding::InEventParam & aInParam, ::chip::Binding::OutEventParam & aOutParam) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - StatusReport *statusReport = NULL; - GenericSoftwareUpdateManagerImpl * self = &SoftwareUpdateMgrImpl(); - - switch (eventType) - { - case chip::Binding::kEvent_PrepareFailed: - ChipLogProgress(DeviceLayer, "Failed to prepare Software Update binding: %s", ErrorStr(aInParam.PrepareFailed.Reason)); - statusReport = aInParam.PrepareFailed.StatusReport; - err = aInParam.PrepareFailed.Reason; - break; - - case chip::Binding::kEvent_BindingFailed: - ChipLogProgress(DeviceLayer, "Software Update binding failed: %s", ErrorStr(aInParam.BindingFailed.Reason)); - err = aInParam.PrepareFailed.Reason; - break; - - case chip::Binding::kEvent_BindingReady: - ChipLogProgress(DeviceLayer, "Software Update binding ready"); - - err = self->mBinding->NewExchangeContext(self->mExchangeCtx); - SuccessOrExit(err); - - self->mBinding->Release(); - self->mBinding = NULL; - - err = self->PrepareQuery(); - SuccessOrExit(err); - - self->DriveState(SoftwareUpdateManager::kState_Query); - break; - - default: - chip::Binding::DefaultEventHandler(appState, eventType, aInParam, aOutParam); - } - -exit: - if (err != CHIP_NO_ERROR) - { - if (self->mBinding != NULL) - { - self->mBinding->Release(); - self->mBinding = NULL; - } - - self->Impl()->SoftwareUpdateFailed(err, statusReport); - } -} - template CHIP_ERROR GenericSoftwareUpdateManagerImpl::StoreImageBlock(uint32_t aLength, uint8_t *aData) { @@ -1129,18 +993,6 @@ exit: template void GenericSoftwareUpdateManagerImpl::Cleanup(void) { - if (mBinding) - { - mBinding->Close(); - mBinding = NULL; - } - - // Shutdown the exchange if its active - if (mExchangeCtx) - { - mExchangeCtx->Abort(); - mExchangeCtx = NULL; - } } template @@ -1263,15 +1115,6 @@ CHIP_ERROR GenericSoftwareUpdateManagerImpl::_ImageInstallComplete(CH return err; } -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl::GetIntegrityTypeList(::chip::Profiles::SoftwareUpdate::IntegrityTypeList * aIntegrityTypeList) -{ - uint8_t supportedTypes[] = { Profiles::SoftwareUpdate::kIntegrityType_SHA256 }; - aIntegrityTypeList->init(ArraySize(supportedTypes), supportedTypes); - - return CHIP_NO_ERROR; -} - template CHIP_ERROR GenericSoftwareUpdateManagerImpl::InstallImage(void) { diff --git a/src/include/platform/internal/testing/ConfigUnitTest.h b/src/include/platform/internal/testing/ConfigUnitTest.h index 11a0c62df38c27..7f041f8d76c2f4 100644 --- a/src/include/platform/internal/testing/ConfigUnitTest.h +++ b/src/include/platform/internal/testing/ConfigUnitTest.h @@ -19,6 +19,7 @@ #define CHIP_DEVICE_CONFIG_UNIT_TEST_H #include +#include namespace chip { namespace DeviceLayer { diff --git a/src/include/platform/nRF5/BLEManagerImpl.h b/src/include/platform/nRF5/BLEManagerImpl.h index f2337e66e0e8cd..0eaf25e02fc4bc 100644 --- a/src/include/platform/nRF5/BLEManagerImpl.h +++ b/src/include/platform/nRF5/BLEManagerImpl.h @@ -33,12 +33,14 @@ namespace chip { namespace DeviceLayer { namespace Internal { +using namespace chip::Ble; + /** * Concrete implementation of the NetworkProvisioningServer singleton object for the nRF5 platforms. */ class BLEManagerImpl final : public BLEManager, - private ::Ble::BleLayer, + private BleLayer, private BlePlatformDelegate, private BleApplicationDelegate { @@ -69,7 +71,7 @@ class BLEManagerImpl final CHIP_ERROR _SetDeviceName(const char * deviceName); uint16_t _NumConnections(void); void _OnPlatformEvent(const ChipDeviceEvent * event); - ::Ble::BleLayer * _GetBleLayer(void) const; + BleLayer * _GetBleLayer(void) const; // ===== Members that implement virtual methods on BlePlatformDelegate. @@ -172,7 +174,7 @@ inline void BLEManagerImpl::SetAdvertisingHandle(uint8_t handle) mAdvHandle = handle; } -inline ::Ble::BleLayer * BLEManagerImpl::_GetBleLayer() const +inline BleLayer * BLEManagerImpl::_GetBleLayer() const { return (BleLayer *)(this); } diff --git a/src/include/platform/nRF5/CHIPDevicePlatformConfig.h b/src/include/platform/nRF5/CHIPDevicePlatformConfig.h index 2e4f0cbb3f054f..5f93dae6dbfff4 100644 --- a/src/include/platform/nRF5/CHIPDevicePlatformConfig.h +++ b/src/include/platform/nRF5/CHIPDevicePlatformConfig.h @@ -40,7 +40,7 @@ #define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1 -#define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 1 +#define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 0 #define CHIP_DEVICE_CONFIG_ENABLE_SERVICE_DIRECTORY_TIME_SYNC 0 #define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY 2 diff --git a/src/include/platform/nRF5/ConfigurationManagerImpl.h b/src/include/platform/nRF5/ConfigurationManagerImpl.h index f939ea3be1023f..bf7783bec18ba2 100644 --- a/src/include/platform/nRF5/ConfigurationManagerImpl.h +++ b/src/include/platform/nRF5/ConfigurationManagerImpl.h @@ -52,8 +52,6 @@ class ConfigurationManagerImpl final CHIP_ERROR _Init(void); CHIP_ERROR _GetPrimaryWiFiMACAddress(uint8_t * buf); - CHIP_ERROR _GetDeviceDescriptor(::chip::Profiles::DeviceDescription::ChipDeviceDescriptor & deviceDesc); - ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase * _GetGroupKeyStore(void); bool _CanFactoryReset(void); void _InitiateFactoryReset(void); CHIP_ERROR _ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value); diff --git a/src/include/platform/nRF5/GroupKeyStoreImpl.h b/src/include/platform/nRF5/GroupKeyStoreImpl.h index 55f3c60ced6c96..9fe8c281df507c 100644 --- a/src/include/platform/nRF5/GroupKeyStoreImpl.h +++ b/src/include/platform/nRF5/GroupKeyStoreImpl.h @@ -23,13 +23,28 @@ #include #include -#include #include namespace chip { namespace DeviceLayer { namespace Internal { +class ChipGroupKey +{ +public: + enum + { + MaxKeySize = 36 + }; + uint32_t KeyId; /**< The key ID. */ + uint8_t KeyLen; /**< The key length. */ + uint8_t Key[MaxKeySize]; /**< The secret key material. */ + union { + uint32_t StartTime; /**< The epoch key start time. */ + uint32_t GlobalId; /**< The application group key global ID. */ + }; +}; + /** * An implementation of the chip GroupKeyStoreBase API for platforms based * on the Nordic nRF5 SDK. diff --git a/src/lib/core/CHIPKeyIds.cpp b/src/lib/core/CHIPKeyIds.cpp index 16e64680a3940a..953dbde140ad64 100644 --- a/src/lib/core/CHIPKeyIds.cpp +++ b/src/lib/core/CHIPKeyIds.cpp @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2016-2017 Nest Labs, Inc. - * All rights reserved. + * * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,26 +17,25 @@ /** * @file - * This file implements Weave key types helper functions. + * This file implements CHIP key types helper functions. * */ -#include -#include "WeaveKeyIds.h" -#include +#include +#include "CHIPKeyIds.h" +#include -namespace nl { -namespace Weave { +namespace chip { /** * Determine whether the specified key ID belongs to one of the application * group key types (static or rotating). * - * @param[in] keyId Weave key identifier. + * @param[in] keyId CHIP key identifier. * @return true if the keyId is of rotating or static key type. * */ -bool WeaveKeyId::IsAppGroupKey(uint32_t keyId) +bool ChipKeyId::IsAppGroupKey(uint32_t keyId) { return IsAppStaticKey(keyId) || IsAppRotatingKey(keyId); } @@ -45,11 +43,11 @@ bool WeaveKeyId::IsAppGroupKey(uint32_t keyId) /** * Determine whether the specified application group key ID uses "current" epoch key. * - * @param[in] keyId Weave application group key identifier. + * @param[in] keyId CHIP application group key identifier. * @return true if the keyId indicates usage of the current epoch key. * */ -bool WeaveKeyId::UsesCurrentEpochKey(uint32_t keyId) +bool ChipKeyId::UsesCurrentEpochKey(uint32_t keyId) { return IncorporatesEpochKey(keyId) && ((keyId & kFlag_UseCurrentEpochKey) != 0); } @@ -57,11 +55,11 @@ bool WeaveKeyId::UsesCurrentEpochKey(uint32_t keyId) /** * Determine whether the specified application group key ID incorporates root key. * - * @param[in] keyId Weave application group key identifier. + * @param[in] keyId CHIP application group key identifier. * @return true if the keyId incorporates root key. * */ -bool WeaveKeyId::IncorporatesRootKey(uint32_t keyId) +bool ChipKeyId::IncorporatesRootKey(uint32_t keyId) { uint32_t keyType = GetType(keyId); return keyType == kType_AppStaticKey || @@ -73,11 +71,11 @@ bool WeaveKeyId::IncorporatesRootKey(uint32_t keyId) /** * Determine whether the specified application group key ID incorporates group master key. * - * @param[in] keyId Weave application group key identifier. + * @param[in] keyId CHIP application group key identifier. * @return true if the keyId incorporates group master key. * */ -bool WeaveKeyId::IncorporatesAppGroupMasterKey(uint32_t keyId) +bool ChipKeyId::IncorporatesAppGroupMasterKey(uint32_t keyId) { uint32_t keyType = GetType(keyId); return keyType == kType_AppStaticKey || @@ -98,7 +96,7 @@ bool WeaveKeyId::IncorporatesAppGroupMasterKey(uint32_t keyId) * @return application group key ID. * */ -uint32_t WeaveKeyId::MakeAppKeyId(uint32_t keyType, uint32_t rootKeyId, uint32_t epochKeyId, +uint32_t ChipKeyId::MakeAppKeyId(uint32_t keyType, uint32_t rootKeyId, uint32_t epochKeyId, uint32_t appGroupMasterKeyId, bool useCurrentEpochKey) { return (keyType | @@ -117,7 +115,7 @@ uint32_t WeaveKeyId::MakeAppKeyId(uint32_t keyType, uint32_t rootKeyId, uint32_t * @return application intermediate key ID. * */ -uint32_t WeaveKeyId::MakeAppIntermediateKeyId(uint32_t rootKeyId, uint32_t epochKeyId, bool useCurrentEpochKey) +uint32_t ChipKeyId::MakeAppIntermediateKeyId(uint32_t rootKeyId, uint32_t epochKeyId, bool useCurrentEpochKey) { return MakeAppKeyId(kType_AppIntermediateKey, rootKeyId, epochKeyId, kNone, useCurrentEpochKey); } @@ -134,7 +132,7 @@ uint32_t WeaveKeyId::MakeAppIntermediateKeyId(uint32_t rootKeyId, uint32_t epoch * @return application rotating key ID. * */ -uint32_t WeaveKeyId::MakeAppRotatingKeyId(uint32_t rootKeyId, uint32_t epochKeyId, +uint32_t ChipKeyId::MakeAppRotatingKeyId(uint32_t rootKeyId, uint32_t epochKeyId, uint32_t appGroupMasterKeyId, bool useCurrentEpochKey) { return MakeAppKeyId(kType_AppRotatingKey, rootKeyId, epochKeyId, appGroupMasterKeyId, useCurrentEpochKey); @@ -149,7 +147,7 @@ uint32_t WeaveKeyId::MakeAppRotatingKeyId(uint32_t rootKeyId, uint32_t epochKeyI * @return application static key ID. * */ -uint32_t WeaveKeyId::MakeAppStaticKeyId(uint32_t rootKeyId, uint32_t appGroupMasterKeyId) +uint32_t ChipKeyId::MakeAppStaticKeyId(uint32_t rootKeyId, uint32_t appGroupMasterKeyId) { return MakeAppKeyId(kType_AppStaticKey, rootKeyId, kNone, appGroupMasterKeyId, false); } @@ -161,7 +159,7 @@ uint32_t WeaveKeyId::MakeAppStaticKeyId(uint32_t rootKeyId, uint32_t appGroupMas * @return application static key ID. * */ -uint32_t WeaveKeyId::ConvertToStaticAppKeyId(uint32_t keyId) +uint32_t ChipKeyId::ConvertToStaticAppKeyId(uint32_t keyId) { return MakeAppStaticKeyId(GetRootKeyId(keyId), GetAppGroupMasterKeyId(keyId)); } @@ -175,7 +173,7 @@ uint32_t WeaveKeyId::ConvertToStaticAppKeyId(uint32_t keyId) * @return application key ID. * */ -uint32_t WeaveKeyId::UpdateEpochKeyId(uint32_t keyId, uint32_t epochKeyId) +uint32_t ChipKeyId::UpdateEpochKeyId(uint32_t keyId, uint32_t epochKeyId) { return (keyId & ~(kFlag_UseCurrentEpochKey | kMask_EpochKeyNumber)) | (epochKeyId & kMask_EpochKeyNumber); @@ -184,11 +182,11 @@ uint32_t WeaveKeyId::UpdateEpochKeyId(uint32_t keyId, uint32_t epochKeyId) /** * Determine whether key identifier has valid (legal) value. * - * @param[in] keyId Weave key ID. + * @param[in] keyId CHIP key ID. * @return true if key ID value is valid. * */ -bool WeaveKeyId::IsValidKeyId(uint32_t keyId) +bool ChipKeyId::IsValidKeyId(uint32_t keyId) { bool retval; int usedBits = kMask_KeyType; @@ -253,15 +251,15 @@ bool WeaveKeyId::IsValidKeyId(uint32_t keyId) } /** - * Determine whether a given key ID identifies a key that is suitable for Weave message encryption. + * Determine whether a given key ID identifies a key that is suitable for CHIP message encryption. * - * @param[in] keyId Weave key ID. + * @param[in] keyId CHIP key ID. * @param[in] allowLogicalKeys Specifies whether logical keys IDs (such as the "current" rotating key) * should be considered suitable for message encryption. - * @return true If the identified key can be used to encrypt Weave messages. + * @return true If the identified key can be used to encrypt CHIP messages. * */ -bool WeaveKeyId::IsMessageEncryptionKeyId(uint32_t keyId, bool allowLogicalKeys) +bool ChipKeyId::IsMessageEncryptionKeyId(uint32_t keyId, bool allowLogicalKeys) { switch (GetType(keyId)) { @@ -284,7 +282,7 @@ bool WeaveKeyId::IsMessageEncryptionKeyId(uint32_t keyId, bool allowLogicalKeys) * * @return True if the keys IDs represent the same key. */ -bool WeaveKeyId::IsSameKeyOrGroup(uint32_t keyId1, uint32_t keyId2) +bool ChipKeyId::IsSameKeyOrGroup(uint32_t keyId1, uint32_t keyId2) { enum { kIgnoreEpochMask = ~(kMask_EpochKeyNumber | kFlag_UseCurrentEpochKey) }; @@ -302,15 +300,15 @@ bool WeaveKeyId::IsSameKeyOrGroup(uint32_t keyId1, uint32_t keyId2) } /** - * Decode a Weave key identifier with a descriptive string. + * Decode a CHIP key identifier with a descriptive string. * - * @param[in] keyId Weave key ID to decode and for which to return + * @param[in] keyId CHIP key ID to decode and for which to return * a descriptive string. * * @return A pointer to a NULL-terminated string describing the specified key ID. * */ -const char *WeaveKeyId::DescribeKey(uint32_t keyId) +const char *ChipKeyId::DescribeKey(uint32_t keyId) { const char *retval; @@ -372,5 +370,4 @@ const char *WeaveKeyId::DescribeKey(uint32_t keyId) return retval; } -} // namespace Weave -} // namespace nl +} // namespace chip diff --git a/src/lib/core/CHIPKeyIds.h b/src/lib/core/CHIPKeyIds.h index 7e9c57e032a30c..59541dd9842dc9 100644 --- a/src/lib/core/CHIPKeyIds.h +++ b/src/lib/core/CHIPKeyIds.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2016-2017 Nest Labs, Inc. - * All rights reserved. + * * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,37 +17,36 @@ /** * @file - * This file defines constant enumerations for all Weave key types, + * This file defines constant enumerations for all CHIP key types, * key flags, key ID fields, and helper API functions. * */ -#ifndef WEAVEKEYS_H_ -#define WEAVEKEYS_H_ +#ifndef CHIPKEYS_H_ +#define CHIPKEYS_H_ -namespace nl { -namespace Weave { +namespace chip { /** - * @class WeaveKeyId + * @class ChipKeyId * * @brief - * The definition of the Weave Key identifier. This class contains + * The definition of the CHIP Key identifier. This class contains * key types, key flags, key ID fields definition, and API functions. * */ -class WeaveKeyId +class ChipKeyId { private: /** * @brief - * Private Weave key ID fields, flags, and types. + * Private CHIP key ID fields, flags, and types. */ enum { - kMask_KeyFlags = 0xF0000000, /**< Weave key flag field mask. */ - kMask_KeyType = 0x0FFFF000, /**< Weave key type field mask. */ - kMask_KeyNumber = 0x00000FFF, /**< Weave key number field mask. */ + kMask_KeyFlags = 0xF0000000, /**< CHIP key flag field mask. */ + kMask_KeyType = 0x0FFFF000, /**< CHIP key type field mask. */ + kMask_KeyNumber = 0x00000FFF, /**< CHIP key number field mask. */ kMask_RootKeyNumber = 0x00000C00, /**< Application group root key number field mask. */ kMask_EpochKeyNumber = 0x00000380, /**< Application group epoch key number field mask. */ kMask_GroupLocalNumber = 0x0000007F, /**< Application group local number field mask. */ @@ -66,19 +64,19 @@ class WeaveKeyId public: /** * @brief - * Public Weave key ID fields, flags, and types. + * Public CHIP key ID fields, flags, and types. */ enum { /** - * @brief Weave key types used for Weave message encryption. + * @brief CHIP key types used for CHIP message encryption. * * @note 16 (out of 32) most significant bits of the message encryption key * type should be zero because only 16 least significant bits of the ID - * are encoded in the Weave message. + * are encoded in the CHIP message. * @{ */ - kType_None = 0x00000000, /**< Weave message is unencrypted. */ + kType_None = 0x00000000, /**< CHIP message is unencrypted. */ kType_General = 0x00001000, /**< General key type. */ kType_Session = 0x00002000, /**< Session key type. */ kType_AppStaticKey = 0x00004000, /**< Application static key type. */ @@ -87,10 +85,10 @@ class WeaveKeyId /** @} */ /** - * @brief Weave key types (other than Weave message encryption types). + * @brief CHIP key types (other than CHIP message encryption types). * * @note 16 (out of 32) most significant bits of these types cannot be all zeros, - * because these values are reserved for the Weave message encryption keys only. + * because these values are reserved for the CHIP message encryption keys only. * @{ */ @@ -109,12 +107,12 @@ class WeaveKeyId /** @} */ /** - * @brief Weave global key IDs. + * @brief CHIP global key IDs. * @{ */ - /** Unspecified Weave key ID. */ + /** Unspecified CHIP key ID. */ kNone = kType_None | 0x0000, - /** Weave fabric secret ID. */ + /** CHIP fabric secret ID. */ kFabricSecret = kType_General | 0x0001, /** Fabric root key ID. */ kFabricRootKey = kType_AppRootKey | (0 << kShift_RootKeyNumber), @@ -137,9 +135,9 @@ class WeaveKeyId }; /** - * Get Weave key type of the specified key ID. + * Get CHIP key type of the specified key ID. * - * @param[in] keyId Weave key identifier. + * @param[in] keyId CHIP key identifier. * @return type of the key ID. * */ @@ -151,7 +149,7 @@ class WeaveKeyId /** * Determine whether the specified key ID is of a general type. * - * @param[in] keyId Weave key identifier. + * @param[in] keyId CHIP key identifier. * @return true if the keyId has General type. * */ @@ -163,7 +161,7 @@ class WeaveKeyId /** * Determine whether the specified key ID is of a session type. * - * @param[in] keyId Weave key identifier. + * @param[in] keyId CHIP key identifier. * @return true if the keyId of a session type. * */ @@ -175,7 +173,7 @@ class WeaveKeyId /** * Determine whether the specified key ID is of an application static type. * - * @param[in] keyId Weave key identifier. + * @param[in] keyId CHIP key identifier. * @return true if the keyId of an application static type. * */ @@ -187,7 +185,7 @@ class WeaveKeyId /** * Determine whether the specified key ID is of an application rotating type. * - * @param[in] keyId Weave key identifier. + * @param[in] keyId CHIP key identifier. * @return true if the keyId of an application rotating type. * */ @@ -201,7 +199,7 @@ class WeaveKeyId /** * Determine whether the specified key ID is of an application root key type. * - * @param[in] keyId Weave key identifier. + * @param[in] keyId CHIP key identifier. * @return true if the keyId of an application root key type. * */ @@ -213,7 +211,7 @@ class WeaveKeyId /** * Determine whether the specified key ID is of an application epoch key type. * - * @param[in] keyId Weave key identifier. + * @param[in] keyId CHIP key identifier. * @return true if the keyId of an application epoch key type. * */ @@ -225,7 +223,7 @@ class WeaveKeyId /** * Determine whether the specified key ID is of an application group master key type. * - * @param[in] keyId Weave key identifier. + * @param[in] keyId CHIP key identifier. * @return true if the keyId of an application group master key type. * */ @@ -261,7 +259,7 @@ class WeaveKeyId /** * Get application group root key ID that was used to derive specified application key. * - * @param[in] keyId Weave application group key identifier. + * @param[in] keyId CHIP application group key identifier. * @return root key ID. * */ @@ -273,7 +271,7 @@ class WeaveKeyId /** * Get application group epoch key ID that was used to derive specified application key. * - * @param[in] keyId Weave application group key identifier. + * @param[in] keyId CHIP application group key identifier. * @return epoch key ID. * */ @@ -285,7 +283,7 @@ class WeaveKeyId /** * Get application group master key ID that was used to derive specified application key. * - * @param[in] keyId Weave application group key identifier. + * @param[in] keyId CHIP application group key identifier. * @return application group master key ID. * */ @@ -297,7 +295,7 @@ class WeaveKeyId /** * Get application group root key number that was used to derive specified application key. * - * @param[in] keyId Weave application group key identifier. + * @param[in] keyId CHIP application group key identifier. * @return root key number. * */ @@ -309,7 +307,7 @@ class WeaveKeyId /** * Get application group epoch key number that was used to derive specified application key. * - * @param[in] keyId Weave application group key identifier. + * @param[in] keyId CHIP application group key identifier. * @return epoch key number. * */ @@ -321,7 +319,7 @@ class WeaveKeyId /** * Get application group local number that was used to derive specified application key. * - * @param[in] keyId Weave application group key identifier. + * @param[in] keyId CHIP application group key identifier. * @return application group local number. * */ @@ -381,7 +379,7 @@ class WeaveKeyId /** * Determine whether the specified application group key ID incorporates epoch key. * - * @param[in] keyId Weave application group key identifier. + * @param[in] keyId CHIP application group key identifier. * @return true if the keyId incorporates epoch key. * */ @@ -409,7 +407,6 @@ class WeaveKeyId static const char *DescribeKey(uint32_t keyId); }; -} // namespace Weave -} // namespace nl +} // namespace chip -#endif /* WEAVEKEYS_H_ */ +#endif /* CHIPKEYS_H_ */ diff --git a/src/lib/core/CHIPTLV.h b/src/lib/core/CHIPTLV.h index 83284df3ff437a..ca9a4a55750990 100644 --- a/src/lib/core/CHIPTLV.h +++ b/src/lib/core/CHIPTLV.h @@ -31,9 +31,9 @@ #include #include -#include -#include "CHIPTLVTags.h" -#include "CHIPTLVTypes.h" +#include +#include "core/CHIPTLVTags.h" +#include "core/CHIPTLVTypes.h" // forward declaration of the PacketBuffer class used within the header. namespace chip { diff --git a/src/lib/core/CHIPVendorIdentifiers.hpp b/src/lib/core/CHIPVendorIdentifiers.hpp index c99810b32084d8..ef9b284fc86eee 100644 --- a/src/lib/core/CHIPVendorIdentifiers.hpp +++ b/src/lib/core/CHIPVendorIdentifiers.hpp @@ -17,7 +17,7 @@ /** * @file - * This file defines Weave vendor identifiers. + * This file defines chip vendor identifiers. * * Vendor identifiers are assigned and administered by CHIP. * diff --git a/src/lib/core/CoreLayer.am b/src/lib/core/CoreLayer.am index c29fe4d8006e9f..b8ebe152a17141 100644 --- a/src/lib/core/CoreLayer.am +++ b/src/lib/core/CoreLayer.am @@ -30,6 +30,7 @@ CHIP_BUILD_CORE_LAYER_SOURCE_FILES = \ core/CHIPTLVUtilities.cpp \ core/CHIPTLVWriter.cpp \ core/CHIPTLVUpdater.cpp \ + core/CHIPKeyIds.cpp \ $(NULL) CHIP_BUILD_CORE_LAYER_HEADER_FILES = \ @@ -46,4 +47,5 @@ CHIP_BUILD_CORE_LAYER_HEADER_FILES = \ core/CHIPTLVUtilities.hpp \ core/CHIPTimeConfig.h \ core/CHIPTunnelConfig.h \ + core/CHIPKeyIds.h \ $(NULL) diff --git a/src/lwip/Makefile.am b/src/lwip/Makefile.am index 9d0491bc88cea2..8a831278f84eae 100644 --- a/src/lwip/Makefile.am +++ b/src/lwip/Makefile.am @@ -25,15 +25,121 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am -SUBDIRS = tests +if CHIP_WITH_LWIP_INTERNAL -EXTRA_DIST = \ - efr32 \ - freertos \ - standalone \ - nrf5 \ +lib_LIBRARIES = liblwip.a + +liblwip_API_SOURCES = \ + @top_builddir@/third_party/lwip/repo/lwip/src/api/api_lib.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/api/api_msg.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/api/err.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/api/netbuf.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/api/netdb.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/api/netifapi.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/api/sockets.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/api/tcpip.c \ + $(NULL) + +liblwip_CORE_SOURCES = \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/def.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/dns.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/inet_chksum.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/init.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv4/autoip.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv4/icmp.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv4/igmp.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv4/ip4.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv4/ip4_addr.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv4/etharp.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv4/ip4_frag.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv4/dhcp.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv6/ip6_route_table.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv6/dhcp6.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv6/ethip6.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv6/icmp6.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv6/inet6.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv6/ip6.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv6/ip6_addr.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv6/ip6_frag.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv6/mld6.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ipv6/nd6.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/mem.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/memp.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/netif.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/pbuf.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/raw.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/stats.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/sys.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/tcp.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/tcp_in.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/tcp_out.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/udp.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/ip.c \ + @top_builddir@/third_party/lwip/repo/lwip/src/core/timeouts.c \ + $(NULL) + +liblwip_NETIF_SOURCES = \ + @top_builddir@/third_party/lwip/repo/lwip/src/netif/ethernet.c \ + $(NULL) + +if CHIP_LWIP_TARGET_STANDALONE + +liblwip_TARGET_SOURCES = \ + standalone/sys_arch.c \ + standalone/TapInterface.c \ + $(NULL) + +EXTRA_DIST = \ + standalone/arch \ + standalone/lwipopts.h \ + standalone/TapInterface.h \ + $(NULL) + +endif # CHIP_LWIP_TARGET_STANDALONE + +if CHIP_LWIP_TARGET_NRF5 + +liblwip_TARGET_SOURCES = \ + freertos/sys_arch.c \ $(NULL) +EXTRA_DIST = \ + freertos/arch \ + nrf5/arch \ + nrf5/lwipopts.h \ + nrf5/lwippools.h \ + $(NULL) + +endif # CHIP_LWIP_TARGET_NRF5 + +if CHIP_LWIP_TARGET_EFR32 + +liblwip_TARGET_SOURCES = \ + freertos/sys_arch.c \ + $(NULL) + +EXTRA_DIST = \ + freertos/arch \ + efr32/arch \ + efr32/lwipopts.h \ + efr32/lwippools.h \ + $(NULL) + +endif # CHIP_LWIP_TARGET_EFR32 + +liblwip_a_SOURCES = \ + $(liblwip_API_SOURCES) \ + $(liblwip_CORE_SOURCES) \ + $(liblwip_NETIF_SOURCES) \ + $(liblwip_TARGET_SOURCES) \ + $(NULL) + +liblwip_a_CPPFLAGS = \ + $(LWIP_CPPFLAGS) \ + $(NULL) + +endif # CHIP_WITH_LWIP_INTERNAL + PRETTY_FILES := $(NULL) include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/src/platform/EFR32/ConfigurationManagerImpl.cpp b/src/platform/EFR32/ConfigurationManagerImpl.cpp index 4161fc94469bc2..f033e805b40199 100644 --- a/src/platform/EFR32/ConfigurationManagerImpl.cpp +++ b/src/platform/EFR32/ConfigurationManagerImpl.cpp @@ -71,19 +71,6 @@ CHIP_ERROR ConfigurationManagerImpl::_Init() return err; } -CHIP_ERROR ConfigurationManagerImpl::_GetDeviceDescriptor( - ::chip::Profiles::DeviceDescription::ChipDeviceDescriptor &deviceDesc) -{ - CHIP_ERROR err; - - // Call the generic version of _GetDeviceDescriptor() supplied by the base class. - err = Internal::GenericConfigurationManagerImpl::_GetDeviceDescriptor(deviceDesc); - SuccessOrExit(err); - -exit: - return err; -} - ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase *ConfigurationManagerImpl::_GetGroupKeyStore() { return &gGroupKeyStore; diff --git a/src/platform/Makefile.am b/src/platform/Makefile.am index 35f1a16ec22571..9ad81025101322 100644 --- a/src/platform/Makefile.am +++ b/src/platform/Makefile.am @@ -34,7 +34,6 @@ noinst_HEADERS = \ @top_srcdir@/src/include/platform/ConnectivityManagerImpl.h \ @top_srcdir@/src/include/platform/PlatformManagerImpl.h \ @top_srcdir@/src/include/platform/SoftwareUpdateManagerImpl.h \ - @top_srcdir@/src/include/platform/nRF5/ConfigurationManagerImpl.h \ @top_srcdir@/src/include/platform/nRF5/nRF5Config.h \ @top_srcdir@/src/include/platform/nRF5/CHIPDevicePlatformConfig.h \ @top_srcdir@/src/include/platform/nRF5/CHIPDevicePlatformEvent.h \ @@ -49,16 +48,11 @@ noinst_HEADERS = \ @top_srcdir@/src/include/platform/CHIPDeviceEvent.h \ @top_srcdir@/src/include/platform/CHIPDeviceLayer.h \ @top_srcdir@/src/include/platform/internal/BLEManager.h \ - @top_srcdir@/src/include/platform/internal/DeviceDescriptionServer.h \ @top_srcdir@/src/include/platform/internal/EventLogging.h \ - @top_srcdir@/src/include/platform/internal/GenericConfigurationManagerImpl.h \ - @top_srcdir@/src/include/platform/internal/GenericConfigurationManagerImpl.ipp \ @top_srcdir@/src/include/platform/internal/GenericPlatformManagerImpl.h \ @top_srcdir@/src/include/platform/internal/GenericPlatformManagerImpl.ipp \ @top_srcdir@/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.h \ @top_srcdir@/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.ipp \ - @top_srcdir@/src/include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.h \ - @top_srcdir@/src/include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.ipp \ @top_srcdir@/src/include/platform/internal/CHIPDeviceLayerInternal.h \ $(NULL) @@ -83,16 +77,11 @@ if CHIP_DEVICE_LAYER_TARGET_NRF5 libDeviceLayer_a_SOURCES += \ nRF5/BLEManagerImpl.cpp \ - nRF5/ConfigurationManagerImpl.cpp \ nRF5/PlatformManagerImpl.cpp \ nRF5/ConnectivityManagerImpl.cpp \ - nRF5/ThreadStackManagerImpl.cpp \ - nRF5/GroupKeyStoreImpl.cpp \ nRF5/nRF5Config.cpp \ nRF5/nRF5Utils.cpp \ - nRF5/Entropy.cpp \ nRF5/Logging.cpp \ - nRF5/SoftwareUpdateManagerImpl.cpp \ $(NULL) endif # CHIP_DEVICE_LAYER_TARGET_NRF5 @@ -103,7 +92,6 @@ libDeviceLayer_a_SOURCES += \ EFR32/BLEManagerImpl.cpp \ EFR32/freertos_bluetooth.c \ EFR32/gatt_db.c \ - EFR32/ConfigurationManagerImpl.cpp \ EFR32/PlatformManagerImpl.cpp \ EFR32/ConnectivityManagerImpl.cpp \ EFR32/NetworkProvisioningServerImpl.cpp \ diff --git a/src/platform/nRF5/BLEManagerImpl.cpp b/src/platform/nRF5/BLEManagerImpl.cpp index cd93d5ec1e228a..16fa7b74361cda 100644 --- a/src/platform/nRF5/BLEManagerImpl.cpp +++ b/src/platform/nRF5/BLEManagerImpl.cpp @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE @@ -39,7 +41,7 @@ #define NRF_LOG_MODULE_NAME chip #include "nrf_log.h" -using namespace ::Ble; +using namespace chip::Ble; namespace chip { namespace DeviceLayer { @@ -77,6 +79,9 @@ CHIP_ERROR RegisterVendorUUID(ble_uuid_t & uuid, const ble_uuid128_t & vendorUUI BLEManagerImpl BLEManagerImpl::sInstance; +#ifndef CHIP_DEVICE_LAYER_BLE_OBSERVER_PRIORITY +#define CHIP_DEVICE_LAYER_BLE_OBSERVER_PRIORITY 3 +#endif // CHIP_DEVICE_LAYER_BLE_OBSERVER_PRIORITY CHIP_ERROR BLEManagerImpl::_Init() { @@ -245,7 +250,7 @@ CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * devName) { snprintf(devNameBuf, sizeof(devNameBuf), "%s%04" PRIX32, CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, - (uint32_t)FabricState.LocalNodeId); + (uint32_t)0); devNameBuf[kMaxDeviceNameLength] = 0; } @@ -442,6 +447,10 @@ void BLEManagerImpl::DriveBLEState(void) } } +#ifndef CHIP_DEVICE_LAYER_BLE_CONN_CFG_TAG +#define CHIP_DEVICE_LAYER_BLE_CONN_CFG_TAG 1 +#endif // CHIP_DEVICE_LAYER_BLE_CONN_CFG_TAG + CHIP_ERROR BLEManagerImpl::StartAdvertising(void) { CHIP_ERROR err = CHIP_NO_ERROR; diff --git a/src/platform/nRF5/ConfigurationManagerImpl.cpp b/src/platform/nRF5/ConfigurationManagerImpl.cpp index 22a234f6adc79a..5b52284ff83262 100644 --- a/src/platform/nRF5/ConfigurationManagerImpl.cpp +++ b/src/platform/nRF5/ConfigurationManagerImpl.cpp @@ -23,10 +23,7 @@ #include #include -#include #include -#include -#include #include #include @@ -34,11 +31,12 @@ #include #endif // CHIP_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING +#include +#include + namespace chip { namespace DeviceLayer { -using namespace ::chip::Profiles::Security::AppKeys; -using namespace ::chip::Profiles::DeviceDescription; using namespace ::chip::DeviceLayer::Internal; namespace { @@ -93,23 +91,6 @@ CHIP_ERROR ConfigurationManagerImpl::_Init() return err; } -CHIP_ERROR ConfigurationManagerImpl::_GetDeviceDescriptor(::chip::Profiles::DeviceDescription::ChipDeviceDescriptor & deviceDesc) -{ - CHIP_ERROR err; - - // Call the generic version of _GetDeviceDescriptor() supplied by the base class. - err = Internal::GenericConfigurationManagerImpl::_GetDeviceDescriptor(deviceDesc); - SuccessOrExit(err); - -exit: - return err; -} - -::chip::Profiles::Security::AppKeys::GroupKeyStoreBase * ConfigurationManagerImpl::_GetGroupKeyStore() -{ - return &gGroupKeyStore; -} - bool ConfigurationManagerImpl::_CanFactoryReset() { // TODO: query the application to determine if factory reset is allowed. diff --git a/src/platform/nRF5/ConnectivityManagerImpl.cpp b/src/platform/nRF5/ConnectivityManagerImpl.cpp index 52a2d91efceeb1..90d77423bf760f 100644 --- a/src/platform/nRF5/ConnectivityManagerImpl.cpp +++ b/src/platform/nRF5/ConnectivityManagerImpl.cpp @@ -17,12 +17,7 @@ #include #include -#include -#include -#include #include -#include -#include #include #include @@ -31,6 +26,8 @@ #include +#include +#include #if CHIP_DEVICE_CONFIG_ENABLE_WOBLE #include @@ -43,13 +40,8 @@ using namespace ::chip; using namespace ::chip::TLV; -using namespace ::chip::Profiles::Common; -using namespace ::chip::Profiles::NetworkProvisioning; using namespace ::chip::DeviceLayer::Internal; -using Profiles::kChipProfile_Common; -using Profiles::kChipProfile_NetworkProvisioning; - namespace chip { namespace DeviceLayer { @@ -65,8 +57,6 @@ CHIP_ERROR ConnectivityManagerImpl::_Init() GenericConnectivityManagerImpl_Thread::_Init(); #endif - // Initialize the CHIP Addressing and Routing Module. - err = Warm::Init(FabricState); SuccessOrExit(err); exit: diff --git a/src/platform/nRF5/PlatformManagerImpl.cpp b/src/platform/nRF5/PlatformManagerImpl.cpp index 151a31c3a84576..6b1bbd8ff9c7c6 100644 --- a/src/platform/nRF5/PlatformManagerImpl.cpp +++ b/src/platform/nRF5/PlatformManagerImpl.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include diff --git a/src/platform/nRF5/SoftwareUpdateManagerImpl.cpp b/src/platform/nRF5/SoftwareUpdateManagerImpl.cpp index ba471986abf413..852634ec5b254b 100644 --- a/src/platform/nRF5/SoftwareUpdateManagerImpl.cpp +++ b/src/platform/nRF5/SoftwareUpdateManagerImpl.cpp @@ -16,14 +16,10 @@ */ -#include +#include #if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER -#include -#include - -#include #include namespace chip { @@ -33,7 +29,7 @@ SoftwareUpdateManagerImpl SoftwareUpdateManagerImpl::sInstance; CHIP_ERROR SoftwareUpdateManagerImpl::_Init(void) { - Internal::GenericSoftwareUpdateManagerImpl_BDX::DoInit(); + //Internal::GenericSoftwareUpdateManagerImpl_BDX::DoInit(); Internal::GenericSoftwareUpdateManagerImpl::DoInit(); return CHIP_NO_ERROR; diff --git a/src/platform/nRF5/nRF5Config.cpp b/src/platform/nRF5/nRF5Config.cpp index f87402673e30a6..1cc7bc985694f2 100644 --- a/src/platform/nRF5/nRF5Config.cpp +++ b/src/platform/nRF5/nRF5Config.cpp @@ -28,6 +28,9 @@ #include #include +#include +#include + #include "FreeRTOS.h" #include "semphr.h" @@ -382,7 +385,7 @@ bool NRF5Config::ConfigValueExists(Key key) fdsRes = fds_record_find(GetFileId(key), GetRecordKey(key), &recDesc, &findToken); // Return true iff the record was found. - return fdsRes == FDS_SUCCESS; + return fdsRes == NRF_SUCCESS; } CHIP_ERROR NRF5Config::FactoryResetConfig(void) @@ -409,9 +412,10 @@ CHIP_ERROR NRF5Config::FactoryResetConfig(void) return err; } +#define CHIP_DEVICE_CONFIG_NRF5_FDS_ERROR_MIN 10000000 CHIP_ERROR NRF5Config::MapFDSError(ret_code_t fdsRes) { - return (fdsRes == FDS_SUCCESS) ? CHIP_NO_ERROR : CHIP_DEVICE_CONFIG_NRF5_FDS_ERROR_MIN + fdsRes; + return (fdsRes == NRF_SUCCESS) ? CHIP_NO_ERROR : CHIP_DEVICE_CONFIG_NRF5_FDS_ERROR_MIN + fdsRes; } CHIP_ERROR NRF5Config::OpenRecord(NRF5Config::Key key, fds_record_desc_t & recDesc, fds_flash_record_t & rec) @@ -513,10 +517,10 @@ CHIP_ERROR NRF5Config::DoAsyncFDSOp(FDSAsyncOp & asyncOp) fds_find_token_t findToken; memset(&findToken, 0, sizeof(findToken)); fdsRes = fds_record_find(asyncOp.FileId, asyncOp.RecordKey, &asyncOp.RecordDesc, &findToken); - VerifyOrExit(fdsRes == FDS_SUCCESS || fdsRes == FDS_ERR_NOT_FOUND, err = MapFDSError(fdsRes)); + VerifyOrExit(fdsRes == NRF_SUCCESS || fdsRes == FDS_ERR_NOT_FOUND, err = MapFDSError(fdsRes)); // Remember if we found an existing record. - existingRecFound = (fdsRes == FDS_SUCCESS); + existingRecFound = (fdsRes == NRF_SUCCESS); } // If adding or updating a record, prepare the FDS record structure with the record data. @@ -573,7 +577,7 @@ CHIP_ERROR NRF5Config::DoAsyncFDSOp(FDSAsyncOp & asyncOp) case FDSAsyncOp::kWaitQueueSpaceAvailable: // In this case, arrange to wait for any operation to complete, which coincides with // space on the operation queue being available. - fdsRes = FDS_SUCCESS; + fdsRes = NRF_SUCCESS; break; default: ChipDie(); @@ -583,7 +587,7 @@ CHIP_ERROR NRF5Config::DoAsyncFDSOp(FDSAsyncOp & asyncOp) // If the FreeRTOS scheduler is not running, poll the completion semaphore; otherwise wait // indefinitely. // - if (fdsRes == FDS_SUCCESS) + if (fdsRes == NRF_SUCCESS) { if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) { @@ -602,7 +606,7 @@ CHIP_ERROR NRF5Config::DoAsyncFDSOp(FDSAsyncOp & asyncOp) sActiveAsyncOp = NULL; // Return immediately if the operation completed successfully. - if (fdsRes == FDS_SUCCESS) + if (fdsRes == NRF_SUCCESS) { ExitNow(err = CHIP_NO_ERROR); } diff --git a/src/platform/nRF5/nRF5Utils.cpp b/src/platform/nRF5/nRF5Utils.cpp index e8e62486290bd1..e69ebdab61d513 100644 --- a/src/platform/nRF5/nRF5Utils.cpp +++ b/src/platform/nRF5/nRF5Utils.cpp @@ -22,11 +22,16 @@ #include #include +#include namespace chip { namespace DeviceLayer { namespace Internal { +#define CHIP_DEVICE_CONFIG_NRF5_ERROR_MIN 1 +#define CHIP_DEVICE_CONFIG_NRF5_ERROR_MAX 1000000 +#define CHIP_DEVICE_CONFIG_NRF5_FDS_ERROR_MIN 10000000 +#define CHIP_DEVICE_CONFIG_NRF5_FDS_ERROR_MAX 10000999 /** * Register a text error formatter for nRF SDK errors. */ From b9b31bc49f519db3d2b84e538604ff8c5a7c945f Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Tue, 24 Mar 2020 15:55:06 -0700 Subject: [PATCH 6/6] Remove commented out code --- .../GenericConfigurationManagerImpl.h | 2 - .../GenericConfigurationManagerImpl.ipp | 50 ------------------- .../internal/GenericConnectivityManagerImpl.h | 6 +-- .../nRF5/SoftwareUpdateManagerImpl.cpp | 1 - 4 files changed, 2 insertions(+), 57 deletions(-) diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.h b/src/include/platform/internal/GenericConfigurationManagerImpl.h index c4edfa4d83b860..d08232e811f3ee 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -130,8 +130,6 @@ class GenericConfigurationManagerImpl ImplClass * Impl() { return static_cast(this); } - // static void HashLengthAndBase64Value(Platform::Security::SHA256 & hash, const uint8_t * val, uint16_t valLen); - #if CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING bool UseManufacturerCredentialsAsOperational(); #endif diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp index b55806733ffd1a..f9a282f5f92b29 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp @@ -705,23 +705,6 @@ template CHIP_ERROR GenericConfigurationManagerImpl::_GetQRCodeString(char * buf, size_t bufSize) { return CHIP_ERROR_NOT_IMPLEMENTED; -/* Commented out for time being, until we have Device Description service - CHIP_ERROR err; - ::chip::Profiles::DeviceDescription::ChipDeviceDescriptor deviceDesc; - uint32_t encodedLen; - - err = Impl()->_GetDeviceDescriptor(deviceDesc); - SuccessOrExit(err); - - strncpy(deviceDesc.PairingCode, FabricState.PairingCode, ::chip::Profiles::DeviceDescription::ChipDeviceDescriptor::kMaxPairingCodeLength); - deviceDesc.PairingCode[::chip::Profiles::DeviceDescription::ChipDeviceDescriptor::kMaxPairingCodeLength] = 0; - - err = ::chip::Profiles::DeviceDescription::ChipDeviceDescriptor::EncodeText(deviceDesc, buf, (uint32_t)bufSize, encodedLen); - SuccessOrExit(err); - -exit: - return err; -*/ } template @@ -880,9 +863,6 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ComputeProvisioningHash( // Read the certificate. err = Impl()->_GetManufacturerDeviceCertificate(dataBuf, certLen, certLen); SuccessOrExit(err); - - // Hash the length and value of the device certificate in base-64 form. - // HashLengthAndBase64Value(hash, dataBuf, (uint16_t)certLen); } // Hash the device intermediate CA certificates @@ -908,9 +888,6 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ComputeProvisioningHash( // Read the device intermediate CA certificates. err = Impl()->_GetManufacturerDeviceIntermediateCACerts(dataBuf, certsLen, certsLen); SuccessOrExit(err); - - // Hash the length and value of the device intermediate CA certificates in base-64 form. - // HashLengthAndBase64Value(hash, dataBuf, (uint16_t)certsLen); } // Hash the device private key @@ -926,9 +903,6 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ComputeProvisioningHash( // unlikely event that this is not the case.) err = Impl()->_GetManufacturerDevicePrivateKey(dataBuf, dataBufSize, keyLen); SuccessOrExit(err); - - // Hash the length and value of the private key in base-64 form. - // HashLengthAndBase64Value(hash, dataBuf, (uint16_t)keyLen); } // Hash the device pairing code. If the device does not have a pairing code, hash a zero-length value. @@ -961,31 +935,7 @@ exit: } return err; } -/* -template -void GenericConfigurationManagerImpl::HashLengthAndBase64Value(Platform::Security::SHA256 & hash, const uint8_t * val, uint16_t valLen) -{ - constexpr uint16_t kInputBufSize = 80; - static_assert(kInputBufSize > 0 && kInputBufSize % 4 == 0, "kInputBufSize must be a positive multiple of 4"); - char inputBuf[kInputBufSize]; - constexpr uint16_t kMaxChunkLen = BASE64_MAX_DECODED_LEN(kInputBufSize); - // Hash the length of the base-64 value as 4 hex digits. - snprintf(inputBuf, sizeof(inputBuf), "%04" PRIX16, (uint16_t)BASE64_ENCODED_LEN(valLen)); - hash.AddData((uint8_t *)inputBuf, 4); - - // Repeatedly encode and hash chunks of the value in base-64 format. - while (valLen > 0) - { - uint16_t chunkLen = (valLen > kMaxChunkLen) ? kMaxChunkLen : valLen; - uint16_t encodedLen = Base64Encode(val, chunkLen, inputBuf); - inputBuf[encodedLen] = 0; - hash.AddData((uint8_t *)inputBuf, encodedLen); - val += chunkLen; - valLen -= chunkLen; - } -} -*/ #if CHIP_PROGRESS_LOGGING template diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl.h b/src/include/platform/internal/GenericConnectivityManagerImpl.h index c57779cfc2bd32..b9c98bb223f857 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl.h @@ -56,25 +56,23 @@ class GenericConnectivityManagerImpl template inline bool GenericConnectivityManagerImpl::_IsUserSelectedModeActive(void) { - return false; //DeviceDescriptionSvr().IsUserSelectedModeActive(); + return false; } template inline void GenericConnectivityManagerImpl::_SetUserSelectedMode(bool val) { - //DeviceDescriptionSvr().SetUserSelectedMode(val); } template inline uint16_t GenericConnectivityManagerImpl::_GetUserSelectedModeTimeout(void) { - return 0; //DeviceDescriptionSvr().GetUserSelectedModeTimeout(); + return 0; } template inline void GenericConnectivityManagerImpl::_SetUserSelectedModeTimeout(uint16_t val) { - //DeviceDescriptionSvr().SetUserSelectedModeTimeout(val); } diff --git a/src/platform/nRF5/SoftwareUpdateManagerImpl.cpp b/src/platform/nRF5/SoftwareUpdateManagerImpl.cpp index 852634ec5b254b..32c8e7377e5312 100644 --- a/src/platform/nRF5/SoftwareUpdateManagerImpl.cpp +++ b/src/platform/nRF5/SoftwareUpdateManagerImpl.cpp @@ -29,7 +29,6 @@ SoftwareUpdateManagerImpl SoftwareUpdateManagerImpl::sInstance; CHIP_ERROR SoftwareUpdateManagerImpl::_Init(void) { - //Internal::GenericSoftwareUpdateManagerImpl_BDX::DoInit(); Internal::GenericSoftwareUpdateManagerImpl::DoInit(); return CHIP_NO_ERROR;