From fa07bbfe1c11cdde9f79b6c5870f2eae3923a5d6 Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Wed, 18 Mar 2020 12:49:08 -0700 Subject: [PATCH 1/2] Bring in EFR32 platform files --- src/include/platform/EFR32/BLEManagerImpl.h | 212 ++++ .../platform/EFR32/BlePlatformConfig.h | 47 + .../platform/EFR32/ConfigurationManagerImpl.h | 112 ++ .../platform/EFR32/ConnectivityManagerImpl.h | 128 +++ src/include/platform/EFR32/EFR32Config.h | 151 +++ .../platform/EFR32/GroupKeyStoreImpl.h | 78 ++ .../platform/EFR32/InetPlatformConfig.h | 50 + .../EFR32/NetworkProvisioningServerImpl.h | 85 ++ .../platform/EFR32/PlatformManagerImpl.h | 95 ++ .../EFR32/SoftwareUpdateManagerImpl.h | 92 ++ .../platform/EFR32/SystemPlatformConfig.h | 63 ++ .../platform/EFR32/ThreadStackManagerImpl.h | 122 +++ .../platform/EFR32/WarmPlatformConfig.h | 42 + .../EFR32/WeaveDevicePlatformConfig.h | 134 +++ .../platform/EFR32/WeaveDevicePlatformEvent.h | 78 ++ .../platform/EFR32/WeavePlatformConfig.h | 150 +++ .../EFR32/efr32-weave-mbedtls-config.h | 130 +++ .../platform/EFR32/freertos_bluetooth.h | 87 ++ src/include/platform/EFR32/gatt.xml | 98 ++ src/include/platform/EFR32/gatt_db.h | 42 + src/platform/EFR32/BLEManagerImpl.cpp | 986 ++++++++++++++++++ .../EFR32/ConfigurationManagerImpl.cpp | 171 +++ .../EFR32/ConnectivityManagerImpl.cpp | 87 ++ src/platform/EFR32/EFR32Config.cpp | 641 ++++++++++++ src/platform/EFR32/Entropy.cpp | 133 +++ src/platform/EFR32/GroupKeyStoreImpl.cpp | 396 +++++++ src/platform/EFR32/Logging.cpp | 387 +++++++ .../EFR32/NetworkProvisioningServerImpl.cpp | 43 + src/platform/EFR32/PlatformManagerImpl.cpp | 59 ++ .../EFR32/SoftwareUpdateManagerImpl.cpp | 47 + src/platform/EFR32/ThreadStackManagerImpl.cpp | 89 ++ src/platform/EFR32/freertos_bluetooth.c | 395 +++++++ src/platform/EFR32/gatt_db.c | 261 +++++ 33 files changed, 5691 insertions(+) create mode 100644 src/include/platform/EFR32/BLEManagerImpl.h create mode 100644 src/include/platform/EFR32/BlePlatformConfig.h create mode 100644 src/include/platform/EFR32/ConfigurationManagerImpl.h create mode 100644 src/include/platform/EFR32/ConnectivityManagerImpl.h create mode 100644 src/include/platform/EFR32/EFR32Config.h create mode 100644 src/include/platform/EFR32/GroupKeyStoreImpl.h create mode 100644 src/include/platform/EFR32/InetPlatformConfig.h create mode 100644 src/include/platform/EFR32/NetworkProvisioningServerImpl.h create mode 100644 src/include/platform/EFR32/PlatformManagerImpl.h create mode 100644 src/include/platform/EFR32/SoftwareUpdateManagerImpl.h create mode 100644 src/include/platform/EFR32/SystemPlatformConfig.h create mode 100644 src/include/platform/EFR32/ThreadStackManagerImpl.h create mode 100644 src/include/platform/EFR32/WarmPlatformConfig.h create mode 100644 src/include/platform/EFR32/WeaveDevicePlatformConfig.h create mode 100644 src/include/platform/EFR32/WeaveDevicePlatformEvent.h create mode 100644 src/include/platform/EFR32/WeavePlatformConfig.h create mode 100644 src/include/platform/EFR32/efr32-weave-mbedtls-config.h create mode 100644 src/include/platform/EFR32/freertos_bluetooth.h create mode 100644 src/include/platform/EFR32/gatt.xml create mode 100644 src/include/platform/EFR32/gatt_db.h create mode 100644 src/platform/EFR32/BLEManagerImpl.cpp create mode 100644 src/platform/EFR32/ConfigurationManagerImpl.cpp create mode 100644 src/platform/EFR32/ConnectivityManagerImpl.cpp create mode 100644 src/platform/EFR32/EFR32Config.cpp create mode 100644 src/platform/EFR32/Entropy.cpp create mode 100644 src/platform/EFR32/GroupKeyStoreImpl.cpp create mode 100644 src/platform/EFR32/Logging.cpp create mode 100644 src/platform/EFR32/NetworkProvisioningServerImpl.cpp create mode 100644 src/platform/EFR32/PlatformManagerImpl.cpp create mode 100644 src/platform/EFR32/SoftwareUpdateManagerImpl.cpp create mode 100644 src/platform/EFR32/ThreadStackManagerImpl.cpp create mode 100644 src/platform/EFR32/freertos_bluetooth.c create mode 100644 src/platform/EFR32/gatt_db.c diff --git a/src/include/platform/EFR32/BLEManagerImpl.h b/src/include/platform/EFR32/BLEManagerImpl.h new file mode 100644 index 00000000000000..2ce1b9c2734a9c --- /dev/null +++ b/src/include/platform/EFR32/BLEManagerImpl.h @@ -0,0 +1,212 @@ +/* + * + * Copyright (c) 2019 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 + * Provides an implementation of the BLEManager singleton object + * for the Silicon Labs EFR32 platforms. + */ + +#ifndef BLE_MANAGER_IMPL_H +#define BLE_MANAGER_IMPL_H + +#if WEAVE_DEVICE_CONFIG_ENABLE_WOBLE + +#include "bg_types.h" +#include "rtos_gecko.h" +#include "gatt_db.h" + +namespace nl { +namespace Weave { +namespace DeviceLayer { +namespace Internal { + +/** + * Concrete implementation of the NetworkProvisioningServer singleton object for the EFR32 platforms. + */ +class BLEManagerImpl final : public BLEManager, + private ::nl::Ble::BleLayer, + private BlePlatformDelegate, + private BleApplicationDelegate +{ + // Allow the BLEManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend BLEManager; + + // ===== Members that implement the BLEManager internal interface. + + WEAVE_ERROR _Init(void); + WoBLEServiceMode _GetWoBLEServiceMode(void); + WEAVE_ERROR _SetWoBLEServiceMode(WoBLEServiceMode val); + bool _IsAdvertisingEnabled(void); + WEAVE_ERROR _SetAdvertisingEnabled(bool val); + bool _IsFastAdvertisingEnabled(void); + WEAVE_ERROR _SetFastAdvertisingEnabled(bool val); + bool _IsAdvertising(void); + WEAVE_ERROR _GetDeviceName(char *buf, size_t bufSize); + WEAVE_ERROR _SetDeviceName(const char *deviceName); + uint16_t _NumConnections(void); + void _OnPlatformEvent(const WeaveDeviceEvent *event); + ::nl::Ble::BleLayer *_GetBleLayer(void) const; + + // ===== Members that implement virtual methods on BlePlatformDelegate. + + bool SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, + const WeaveBleUUID * svcId, + const WeaveBleUUID * charId) override; + bool UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, + const WeaveBleUUID * svcId, + const WeaveBleUUID * charId) override; + bool CloseConnection(BLE_CONNECTION_OBJECT conId) override; + uint16_t GetMTU(BLE_CONNECTION_OBJECT conId) const override; + bool SendIndication(BLE_CONNECTION_OBJECT conId, + const WeaveBleUUID * svcId, + const WeaveBleUUID * charId, + PacketBuffer * pBuf) override; + bool SendWriteRequest(BLE_CONNECTION_OBJECT conId, + const WeaveBleUUID * svcId, + const WeaveBleUUID * charId, + PacketBuffer * pBuf) override; + bool SendReadRequest(BLE_CONNECTION_OBJECT conId, + const WeaveBleUUID * svcId, + const WeaveBleUUID * charId, + PacketBuffer * pBuf) override; + bool SendReadResponse(BLE_CONNECTION_OBJECT conId, + BLE_READ_REQUEST_CONTEXT requestContext, + const WeaveBleUUID * svcId, + const WeaveBleUUID * charId) override; + + // ===== Members that implement virtual methods on BleApplicationDelegate. + + void NotifyWeaveConnectionClosed(BLE_CONNECTION_OBJECT conId) override; + + // ===== Members for internal use by the following friends. + + friend BLEManager & BLEMgr(void); + friend BLEManagerImpl &BLEMgrImpl(void); + + static BLEManagerImpl sInstance; + + // ===== Private members reserved for use by this class only. + + enum + { + kFlag_AdvertisingEnabled = 0x0001, + kFlag_FastAdvertisingEnabled = 0x0002, + kFlag_Advertising = 0x0004, + kFlag_RestartAdvertising = 0x0008, + kFlag_EFRBLEStackInitialized = 0x0010, + kFlag_DeviceNameSet = 0x0020, + }; + + enum + { + kMaxConnections = BLE_LAYER_NUM_BLE_ENDPOINTS, + kMaxDeviceNameLength = 16, + kUnusedIndex = 0xFF, + }; + + struct WoBLEConState + { + bd_addr address; + uint16_t mtu : 10; + uint16_t allocated : 1; + uint16_t subscribed : 1; + uint16_t unused : 4; + uint8_t connectionHandle; + uint8_t bondingHandle; + }; + + WoBLEConState mBleConnections[kMaxConnections]; + uint8_t mIndConfId[kMaxConnections]; + WoBLEServiceMode mServiceMode; + uint16_t mFlags; + char mDeviceName[kMaxDeviceNameLength + 1]; + + WEAVE_ERROR MapBLEError(int bleErr); + void DriveBLEState(void); + WEAVE_ERROR ConfigureAdvertisingData(void); + WEAVE_ERROR StartAdvertising(void); + WEAVE_ERROR StopAdvertising(void); + void UpdateMtu(volatile struct gecko_cmd_packet *evt); + void HandleBootEvent(void); + void HandleConnectEvent(volatile struct gecko_cmd_packet *evt); + void HandleConnectionCloseEvent(volatile struct gecko_cmd_packet *evt); + void HandleWriteEvent(volatile struct gecko_cmd_packet *evt); + void HandleTXCharCCCDWrite(volatile struct gecko_cmd_packet *evt); + void HandleRXCharWrite(volatile struct gecko_cmd_packet *evt); + void HandleTxConfirmationEvent(volatile struct gecko_cmd_packet *evt); + void HandleSoftTimerEvent(volatile struct gecko_cmd_packet *evt); + bool RemoveConnection(uint8_t connectionHandle); + void AddConnection(uint8_t connectionHandle, uint8_t bondingHandle); + WoBLEConState *GetConnectionState(uint8_t conId, bool allocate = false); + uint8_t GetTimerHandle(uint8_t connectionHandle, bool allocate = false); + static void DriveBLEState(intptr_t arg); + static void bluetoothStackEventHandler(void *p_arg); +}; + +/** + * Returns a reference to the public interface of the BLEManager singleton object. + * + * Internal components should use this to access features of the BLEManager object + * that are common to all platforms. + */ +inline BLEManager &BLEMgr(void) +{ + return BLEManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the BLEManager singleton object. + * + * Internal components can use this to gain access to features of the BLEManager + * that are specific to the EFR32 platforms. + */ +inline BLEManagerImpl &BLEMgrImpl(void) +{ + return BLEManagerImpl::sInstance; +} + +inline ::nl::Ble::BleLayer *BLEManagerImpl::_GetBleLayer() const +{ + return (BleLayer *)(this); +} + +inline BLEManager::WoBLEServiceMode BLEManagerImpl::_GetWoBLEServiceMode(void) +{ + return mServiceMode; +} + +inline bool BLEManagerImpl::_IsAdvertisingEnabled(void) +{ + return GetFlag(mFlags, kFlag_AdvertisingEnabled); +} + +inline bool BLEManagerImpl::_IsFastAdvertisingEnabled(void) +{ + return GetFlag(mFlags, kFlag_FastAdvertisingEnabled); +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl + +#endif // WEAVE_DEVICE_CONFIG_ENABLE_WOBLE + +#endif // BLE_MANAGER_IMPL_H diff --git a/src/include/platform/EFR32/BlePlatformConfig.h b/src/include/platform/EFR32/BlePlatformConfig.h new file mode 100644 index 00000000000000..efbceb9a80c776 --- /dev/null +++ b/src/include/platform/EFR32/BlePlatformConfig.h @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2019 Google LLC. + * 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 + * Platform-specific configuration overrides for the OpenWeave BLE + * Layer on EFR32 platforms using the Silicon Labs SDK. + * + */ + +#ifndef BLE_PLATFORM_CONFIG_H +#define BLE_PLATFORM_CONFIG_H + +#include "bg_errorcodes.h" + +// ==================== Platform Adaptations ==================== + +#define BLE_CONNECTION_OBJECT uint8_t +#define BLE_CONNECTION_UNINITIALIZED ((uint8_t)-1) +#define BLE_MAX_RECEIVE_WINDOW_SIZE 5 + +#define BLE_CONFIG_ERROR_TYPE int32_t +#define BLE_CONFIG_NO_ERROR 0 +#define BLE_CONFIG_ERROR_MIN 6000000 +#define BLE_CONFIG_ERROR_MAX 6000999 +#define _BLE_CONFIG_ERROR(e) (BLE_CONFIG_ERROR_MIN + (e)) + +// ========== Platform-specific Configuration Overrides ========= + +/* none so far */ + +#endif // BLE_PLATFORM_CONFIG_H diff --git a/src/include/platform/EFR32/ConfigurationManagerImpl.h b/src/include/platform/EFR32/ConfigurationManagerImpl.h new file mode 100644 index 00000000000000..4911509a3f6b5a --- /dev/null +++ b/src/include/platform/EFR32/ConfigurationManagerImpl.h @@ -0,0 +1,112 @@ +/* + * + * Copyright (c) 2019 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 + * Provides an implementation of the ConfigurationManager object + * for EFR32 platforms using the Silicon Labs SDK. + */ + +#ifndef CONFIGURATION_MANAGER_IMPL_H +#define CONFIGURATION_MANAGER_IMPL_H + +#include +#include "EFR32Config.h" + +namespace nl { +namespace Weave { +namespace DeviceLayer { + +namespace Internal { +class NetworkProvisioningServerImpl; +} + +/** + * Concrete implementation of the ConfigurationManager singleton object for the EFR32 platform. + */ +class ConfigurationManagerImpl final : public ConfigurationManager, + public Internal::GenericConfigurationManagerImpl, + private Internal::EFR32Config +{ + // Allow the ConfigurationManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend class ConfigurationManager; + + // Allow the GenericConfigurationManagerImpl base class to access helper methods and types + // defined on this class. + friend class Internal::GenericConfigurationManagerImpl; + +private: + // ===== Members that implement the ConfigurationManager public interface. + + WEAVE_ERROR _Init(void); + WEAVE_ERROR _GetPrimaryWiFiMACAddress(uint8_t *buf); + WEAVE_ERROR _GetDeviceDescriptor(::nl::Weave::Profiles::DeviceDescription::WeaveDeviceDescriptor &deviceDesc); + ::nl::Weave::Profiles::Security::AppKeys::GroupKeyStoreBase *_GetGroupKeyStore(void); + bool _CanFactoryReset(void); + void _InitiateFactoryReset(void); + WEAVE_ERROR _ReadPersistedStorageValue(::nl::Weave::Platform::PersistedStorage::Key key, uint32_t &value); + WEAVE_ERROR _WritePersistedStorageValue(::nl::Weave::Platform::PersistedStorage::Key key, uint32_t value); + + // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + + // ===== Members for internal use by the following friends. + + friend class Internal::NetworkProvisioningServerImpl; + friend ConfigurationManager & ConfigurationMgr(void); + friend ConfigurationManagerImpl &ConfigurationMgrImpl(void); + + static ConfigurationManagerImpl sInstance; + + // ===== Private members reserved for use by this class only. + + static void DoFactoryReset(intptr_t arg); +}; + +/** + * Returns the public interface of the ConfigurationManager singleton object. + * + * Weave applications should use this to access features of the ConfigurationManager object + * that are common to all platforms. + */ +inline ConfigurationManager &ConfigurationMgr(void) +{ + return ConfigurationManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the ConfigurationManager singleton object. + * + * Weave applications can use this to gain access to features of the ConfigurationManager + * that are specific to the ESP32 platform. + */ +inline ConfigurationManagerImpl &ConfigurationMgrImpl(void) +{ + return ConfigurationManagerImpl::sInstance; +} + +inline WEAVE_ERROR ConfigurationManagerImpl::_GetPrimaryWiFiMACAddress(uint8_t *buf) +{ + return WEAVE_ERROR_UNSUPPORTED_WEAVE_FEATURE; +} + +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl + +#endif // CONFIGURATION_MANAGER_IMPL_H diff --git a/src/include/platform/EFR32/ConnectivityManagerImpl.h b/src/include/platform/EFR32/ConnectivityManagerImpl.h new file mode 100644 index 00000000000000..2fea69e5cf9520 --- /dev/null +++ b/src/include/platform/EFR32/ConnectivityManagerImpl.h @@ -0,0 +1,128 @@ +/* + * + * Copyright (c) 2019 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. + */ + +#ifndef CONNECTIVITY_MANAGER_IMPL_H +#define CONNECTIVITY_MANAGER_IMPL_H + +#include +#include +#if WEAVE_DEVICE_CONFIG_ENABLE_WOBLE +#include +#else +#include +#endif +#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD +#include +#else +#include +#endif +#include +#include +#include + +namespace nl { +namespace Inet { +class IPAddress; +} // namespace Inet +} // namespace nl + +namespace nl { +namespace Weave { +namespace DeviceLayer { + +/** + * Concrete implementation of the ConnectivityManager singleton object for Silicon Labs EFR32 platforms. + */ +class ConnectivityManagerImpl final : public ConnectivityManager, + public Internal::GenericConnectivityManagerImpl, +#if WEAVE_DEVICE_CONFIG_ENABLE_WOBLE + public Internal::GenericConnectivityManagerImpl_BLE, +#else + public Internal::GenericConnectivityManagerImpl_NoBLE, +#endif +#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD + public Internal::GenericConnectivityManagerImpl_Thread, +#else + public Internal::GenericConnectivityManagerImpl_NoThread, +#endif + public Internal::GenericConnectivityManagerImpl_NoWiFi, + public Internal::GenericConnectivityManagerImpl_NoTunnel +{ + // Allow the ConnectivityManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend class ConnectivityManager; + +private: + // ===== Members that implement the ConnectivityManager abstract interface. + + bool _HaveIPv4InternetConnectivity(void); + bool _HaveIPv6InternetConnectivity(void); + bool _HaveServiceConnectivity(void); + WEAVE_ERROR _Init(void); + void _OnPlatformEvent(const WeaveDeviceEvent *event); + + // ===== Members for internal use by the following friends. + + friend ConnectivityManager & ConnectivityMgr(void); + friend ConnectivityManagerImpl &ConnectivityMgrImpl(void); + + static ConnectivityManagerImpl sInstance; +}; + +inline bool ConnectivityManagerImpl::_HaveIPv4InternetConnectivity(void) +{ + return false; +} + +inline bool ConnectivityManagerImpl::_HaveIPv6InternetConnectivity(void) +{ + return false; +} + +inline bool ConnectivityManagerImpl::_HaveServiceConnectivity(void) +{ + return _HaveServiceConnectivityViaThread(); +} + +/** + * Returns the public interface of the ConnectivityManager singleton object. + * + * Weave applications should use this to access features of the ConnectivityManager object + * that are common to all platforms. + */ +inline ConnectivityManager &ConnectivityMgr(void) +{ + return ConnectivityManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the ConnectivityManager singleton object. + * + * Weave applications can use this to gain access to features of the ConnectivityManager + * that are specific to the ESP32 platform. + */ +inline ConnectivityManagerImpl &ConnectivityMgrImpl(void) +{ + return ConnectivityManagerImpl::sInstance; +} + +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl + +#endif // CONNECTIVITY_MANAGER_IMPL_H diff --git a/src/include/platform/EFR32/EFR32Config.h b/src/include/platform/EFR32/EFR32Config.h new file mode 100644 index 00000000000000..3799e2afece7b0 --- /dev/null +++ b/src/include/platform/EFR32/EFR32Config.h @@ -0,0 +1,151 @@ +/* + * + * Copyright (c) 2019 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 + * Utilities for accessing persisted device configuration on + * platforms based on the Silicon Labs SDK. + */ + +#ifndef EFR32_CONFIG_H +#define EFR32_CONFIG_H + +#include + +#include + +#include "nvm3.h" +#include "nvm3_hal_flash.h" + +namespace nl { +namespace Weave { +namespace DeviceLayer { +namespace Internal { + +/** + * + * This implementation uses the Silicon Labs EFR32 NVM3 flash data storage library + * as the underlying storage layer. + * + * NOTE: This class is designed to be mixed-in to the concrete subclass of the + * GenericConfigurationManagerImpl<> template. When used this way, the class + * naturally provides implementations for the delegated members referenced by + * the template class (e.g. the ReadConfigValue() method). + */ + +// Silabs NVM3 objects use a 20-bit number, however User key range is +// restricted to 16 bits i.e. 0x0000 -> 0xFFFF. +// e.g. key = 0xA201 +// 'A2' = the nv group base offest (Factory, Config or Counter) +// '01' = the id offset inside the group. +constexpr inline uint32_t EFR32ConfigKey(uint8_t keyBaseOffset, uint8_t id) +{ + return static_cast(keyBaseOffset) << 8 | id; +} + +class EFR32Config +{ +public: +public: + // Definitions for Silicon Labs EFR32 NVM3 driver:- + + using Key = uint32_t; + + // NVM3 key base offsets used by the OpenWeave Device Layer. + static constexpr uint8_t kWeaveFactory_KeyBase = + 0xA2; // Persistent config values set at manufacturing time. Retained during factory reset. + static constexpr uint8_t kWeaveConfig_KeyBase = + 0xA3; // Persistent config values set at runtime. Cleared during factory reset. + static constexpr uint8_t kWeaveCounter_KeyBase = + 0xA4; // Persistent counter values set at runtime. Retained during factory reset. + + // Key definitions for well-known configuration values. + // Factory config keys + static constexpr Key kConfigKey_SerialNum = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x00); + static constexpr Key kConfigKey_MfrDeviceId = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x01); + static constexpr Key kConfigKey_MfrDeviceCert = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x02); + static constexpr Key kConfigKey_MfrDevicePrivateKey = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x03); + static constexpr Key kConfigKey_ManufacturingDate = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x04); + static constexpr Key kConfigKey_PairingCode = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x05); + static constexpr Key kConfigKey_MfrDeviceICACerts = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x06); + // Weave Config Keys + static constexpr Key kConfigKey_FabricId = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x00); + static constexpr Key kConfigKey_ServiceConfig = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x01); + static constexpr Key kConfigKey_PairedAccountId = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x02); + static constexpr Key kConfigKey_ServiceId = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x03); + static constexpr Key kConfigKey_FabricSecret = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x04); + static constexpr Key kConfigKey_LastUsedEpochKeyId = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x05); + static constexpr Key kConfigKey_FailSafeArmed = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x06); + static constexpr Key kConfigKey_GroupKey = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x07); + static constexpr Key kConfigKey_ProductRevision = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x08); + static constexpr Key kConfigKey_OperationalDeviceId = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x09); + static constexpr Key kConfigKey_OperationalDeviceCert = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x0A); + static constexpr Key kConfigKey_OperationalDeviceICACerts = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x0B); + static constexpr Key kConfigKey_OperationalDevicePrivateKey = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x0C); + + static constexpr Key kConfigKey_GroupKeyBase = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x0D); + static constexpr Key kConfigKey_GroupKeyMax = + EFR32ConfigKey(kWeaveConfig_KeyBase, 0x1C); // Allows 16 Group Keys to be created. + + // Set key id limits for each group. + static constexpr Key kMinConfigKey_WeaveFactory = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x00); + static constexpr Key kMaxConfigKey_WeaveFactory = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x06); + static constexpr Key kMinConfigKey_WeaveConfig = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x00); + static constexpr Key kMaxConfigKey_WeaveConfig = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x1C); + static constexpr Key kMinConfigKey_WeaveCounter = EFR32ConfigKey(kWeaveCounter_KeyBase, 0x00); + static constexpr Key kMaxConfigKey_WeaveCounter = + EFR32ConfigKey(kWeaveCounter_KeyBase, 0x1F); // Allows 32 Counters to be created. + + static WEAVE_ERROR Init(void); + + // Configuration methods used by the GenericConfigurationManagerImpl<> template. + static WEAVE_ERROR ReadConfigValue(Key key, bool &val); + static WEAVE_ERROR ReadConfigValue(Key key, uint32_t &val); + static WEAVE_ERROR ReadConfigValue(Key key, uint64_t &val); + static WEAVE_ERROR ReadConfigValueStr(Key key, char *buf, size_t bufSize, size_t &outLen); + static WEAVE_ERROR ReadConfigValueBin(Key key, uint8_t *buf, size_t bufSize, size_t &outLen); + static WEAVE_ERROR ReadConfigValueCounter(uint8_t counterIdx, uint32_t &val); + static WEAVE_ERROR WriteConfigValue(Key key, bool val); + static WEAVE_ERROR WriteConfigValue(Key key, uint32_t val); + static WEAVE_ERROR WriteConfigValue(Key key, uint64_t val); + static WEAVE_ERROR WriteConfigValueStr(Key key, const char *str); + static WEAVE_ERROR WriteConfigValueStr(Key key, const char *str, size_t strLen); + static WEAVE_ERROR WriteConfigValueBin(Key key, const uint8_t *data, size_t dataLen); + static WEAVE_ERROR WriteConfigValueCounter(uint8_t counterIdx, uint32_t val); + static WEAVE_ERROR ClearConfigValue(Key key); + static bool ConfigValueExists(Key key); + static WEAVE_ERROR FactoryResetConfig(void); + static bool ValidConfigKey(Key key); + + static void RunConfigUnitTest(void); + static void RepackNvm3Flash(void); + +protected: + using ForEachRecordFunct = std::function; + static WEAVE_ERROR ForEachRecord(Key firstKey, Key lastKey, bool addNewRecord, ForEachRecordFunct funct); + +private: + static WEAVE_ERROR MapNvm3Error(Ecode_t nvm3Res); +}; + +} // namespace Internal +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl + +#endif // EFR32_CONFIG_H diff --git a/src/include/platform/EFR32/GroupKeyStoreImpl.h b/src/include/platform/EFR32/GroupKeyStoreImpl.h new file mode 100644 index 00000000000000..63e1eed732f9d7 --- /dev/null +++ b/src/include/platform/EFR32/GroupKeyStoreImpl.h @@ -0,0 +1,78 @@ +/* + * + * Copyright (c) 2019 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 + * Provides an implementation of the Weave Group Key Store interface + * for platforms based on the Silicon Labs SDK. + */ + +#include +#include +#include +#include + +namespace nl { +namespace Weave { +namespace DeviceLayer { +namespace Internal { + +/** + * An implementation of the Weave GroupKeyStoreBase API for platforms based + * on the Silicon Labs SDK. + */ +class GroupKeyStoreImpl final : public ::nl::Weave::Profiles::Security::AppKeys::GroupKeyStoreBase, private EFR32Config +{ + using WeaveGroupKey = ::nl::Weave::Profiles::Security::AppKeys::WeaveGroupKey; + +public: + WEAVE_ERROR Init(); + + WEAVE_ERROR RetrieveGroupKey(uint32_t keyId, WeaveGroupKey &key) override; + WEAVE_ERROR StoreGroupKey(const WeaveGroupKey &key) override; + WEAVE_ERROR DeleteGroupKey(uint32_t keyId) override; + WEAVE_ERROR DeleteGroupKeysOfAType(uint32_t keyType) override; + WEAVE_ERROR EnumerateGroupKeys(uint32_t keyType, + uint32_t *keyIds, + uint8_t keyIdsArraySize, + uint8_t & keyCount) override; + WEAVE_ERROR Clear(void) override; + WEAVE_ERROR RetrieveLastUsedEpochKeyId(void) override; + WEAVE_ERROR StoreLastUsedEpochKeyId(void) override; + +private: + static constexpr size_t kFixedEncodedKeySize = 4U + // key id + 4U + // start time / global id + 1U; // key data length + + static constexpr size_t kMaxEncodedKeySize = kFixedEncodedKeySize + WeaveGroupKey::MaxKeySize; + + /* Not used + static constexpr uint16_t kGroupKeyFileId = GetFileId(kConfigKey_GroupKey); + static constexpr uint16_t kGroupKeyRecordKey = GetRecordKey(kConfigKey_GroupKey); + */ + + static WEAVE_ERROR EncodeGroupKey(const WeaveGroupKey &key, uint8_t *buf, size_t bufSize, size_t &encodedKeyLen); + static WEAVE_ERROR DecodeGroupKey(const uint8_t *encodedKey, size_t encodedKeyLen, WeaveGroupKey &key); + static WEAVE_ERROR DecodeGroupKeyId(const uint8_t *encodedKey, size_t encodedKeyLen, uint32_t &keyId); +}; + +} // namespace Internal +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl diff --git a/src/include/platform/EFR32/InetPlatformConfig.h b/src/include/platform/EFR32/InetPlatformConfig.h new file mode 100644 index 00000000000000..4c8fe1b7ecb6bc --- /dev/null +++ b/src/include/platform/EFR32/InetPlatformConfig.h @@ -0,0 +1,50 @@ +/* + * + * Copyright (c) 2019 Google LLC. + * 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 + * Platform-specific configuration overrides for the OpenWeave Inet + * Layer on EFR32 platforms using the Silicon Labs SDK. + * + */ + +#ifndef INET_PLATFORM_CONFIG_H +#define INET_PLATFORM_CONFIG_H + +#include + +// ==================== Platform Adaptations ==================== + +#define INET_CONFIG_ERROR_TYPE int32_t +#define INET_CONFIG_NO_ERROR 0 +#define INET_CONFIG_ERROR_MIN 1000000 +#define INET_CONFIG_ERROR_MAX 1000999 + +#define INET_CONFIG_ENABLE_IPV4 0 + +// ========== Platform-specific Configuration Overrides ========= + +#ifndef INET_CONFIG_NUM_TCP_ENDPOINTS +#define INET_CONFIG_NUM_TCP_ENDPOINTS 4 +#endif // INET_CONFIG_NUM_TCP_ENDPOINTS + +#ifndef INET_CONFIG_NUM_UDP_ENDPOINTS +#define INET_CONFIG_NUM_UDP_ENDPOINTS 4 +#endif // INET_CONFIG_NUM_UDP_ENDPOINTS + +#endif // INET_PLATFORM_CONFIG_H diff --git a/src/include/platform/EFR32/NetworkProvisioningServerImpl.h b/src/include/platform/EFR32/NetworkProvisioningServerImpl.h new file mode 100644 index 00000000000000..2be56af369d51b --- /dev/null +++ b/src/include/platform/EFR32/NetworkProvisioningServerImpl.h @@ -0,0 +1,85 @@ +/* + * + * Copyright (c) 2019 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. + */ + +#ifndef NETWORK_PROVISIONING_SERVER_IMPL_H +#define NETWORK_PROVISIONING_SERVER_IMPL_H + +#include + +namespace nl { +namespace Weave { +namespace DeviceLayer { +namespace Internal { + +/** + * Concrete implementation of the NetworkProvisioningServer singleton object for the + * Silicon Labs EFR32 platforms. + */ +class NetworkProvisioningServerImpl final + : public NetworkProvisioningServer, + public Internal::GenericNetworkProvisioningServerImpl +{ + // Allow the NetworkProvisioningServer interface class to delegate method calls to + // the implementation methods provided by this class. + friend class Internal::NetworkProvisioningServer; + + // Allow the GenericNetworkProvisioningServerImpl base class to access helper methods + // and types defined on this class. + friend class Internal::GenericNetworkProvisioningServerImpl; + +private: + // ===== Members that implement the NetworkProvisioningServer public interface. + + WEAVE_ERROR _Init(void); + + // ===== Members for internal use by the following friends. + + friend ::nl::Weave::DeviceLayer::Internal::NetworkProvisioningServer &NetworkProvisioningSvr(void); + friend NetworkProvisioningServerImpl & NetworkProvisioningSvrImpl(void); + + static NetworkProvisioningServerImpl sInstance; +}; + +/** + * Returns a reference to the public interface of the NetworkProvisioningServer singleton object. + * + * Internal components should use this to access features of the NetworkProvisioningServer object + * that are common to all platforms. + */ +inline NetworkProvisioningServer &NetworkProvisioningSvr(void) +{ + return NetworkProvisioningServerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the NetworkProvisioningServer singleton object. + * + * Internal components can use this to gain access to features of the NetworkProvisioningServer + * that are specific to the ESP32 platform. + */ +inline NetworkProvisioningServerImpl &NetworkProvisioningSvrImpl(void) +{ + return NetworkProvisioningServerImpl::sInstance; +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl + +#endif // NETWORK_PROVISIONING_SERVER_IMPL_H diff --git a/src/include/platform/EFR32/PlatformManagerImpl.h b/src/include/platform/EFR32/PlatformManagerImpl.h new file mode 100644 index 00000000000000..761c702af83e14 --- /dev/null +++ b/src/include/platform/EFR32/PlatformManagerImpl.h @@ -0,0 +1,95 @@ +/* + * + * Copyright (c) 2019 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 + * Provides an implementation of the PlatformManager object + * for EFR32 platforms using the Silicon Labs SDK. + */ + +#ifndef PLATFORM_MANAGER_IMPL_H +#define PLATFORM_MANAGER_IMPL_H + +#include + +namespace nl { +namespace Weave { +namespace DeviceLayer { + +/** + * Concrete implementation of the PlatformManager singleton object for the EFR32 platform. + */ +class PlatformManagerImpl final : public PlatformManager, + public Internal::GenericPlatformManagerImpl_FreeRTOS +{ + // Allow the PlatformManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend PlatformManager; + + // Allow the generic implementation base class to call helper methods on + // this class. + friend Internal::GenericPlatformManagerImpl_FreeRTOS; + +public: + // ===== Platform-specific members that may be accessed directly by the application. + + /* none so far */ + +private: + // ===== Methods that implement the PlatformManager abstract interface. + + WEAVE_ERROR _InitWeaveStack(void); + + // ===== Members for internal use by the following friends. + + friend PlatformManager & PlatformMgr(void); + friend PlatformManagerImpl &PlatformMgrImpl(void); + friend class Internal::BLEManagerImpl; + + static PlatformManagerImpl sInstance; + + using Internal::GenericPlatformManagerImpl_FreeRTOS::PostEventFromISR; +}; + +/** + * Returns the public interface of the PlatformManager singleton object. + * + * Weave applications should use this to access features of the PlatformManager object + * that are common to all platforms. + */ +inline PlatformManager &PlatformMgr(void) +{ + return PlatformManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the PlatformManager singleton object. + * + * Weave applications can use this to gain access to features of the PlatformManager + * that are specific to the ESP32 platform. + */ +inline PlatformManagerImpl &PlatformMgrImpl(void) +{ + return PlatformManagerImpl::sInstance; +} + +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl + +#endif // PLATFORM_MANAGER_IMPL_H diff --git a/src/include/platform/EFR32/SoftwareUpdateManagerImpl.h b/src/include/platform/EFR32/SoftwareUpdateManagerImpl.h new file mode 100644 index 00000000000000..c5438759f2fd02 --- /dev/null +++ b/src/include/platform/EFR32/SoftwareUpdateManagerImpl.h @@ -0,0 +1,92 @@ +/* + * + * Copyright (c) 2019 Google LLC. + * 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. + */ + +#ifndef SOFTWARE_UPDATE_MANAGER_IMPL_H +#define SOFTWARE_UPDATE_MANAGER_IMPL_H + +#if WEAVE_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER + +#include +#include + +namespace nl { +namespace Weave { +namespace DeviceLayer { + +/** + * Concrete implementation of the SoftwareUpdateManager singleton object for the + * Silicon Labs EFR32 platforms. + */ +class SoftwareUpdateManagerImpl final : public SoftwareUpdateManager, + public Internal::GenericSoftwareUpdateManagerImpl, + public Internal::GenericSoftwareUpdateManagerImpl_BDX +{ + // Allow the SoftwareUpdateManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend class SoftwareUpdateManager; + + // Allow the GenericSoftwareUpdateManagerImpl base class to access helper methods + // 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. + + friend ::nl::Weave::DeviceLayer::SoftwareUpdateManager &SoftwareUpdateMgr(void); + friend SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void); + + static SoftwareUpdateManagerImpl sInstance; + +private: + // ===== Members that implement the SoftwareUpdateManager abstract interface. + + WEAVE_ERROR _Init(void); +}; + +/** + * Returns a reference to the public interface of the SoftwareUpdateManager singleton object. + * + * Internal components should use this to access features of the SoftwareUpdateManager object + * that are common to all platforms. + */ +inline SoftwareUpdateManager &SoftwareUpdateMgr(void) +{ + return SoftwareUpdateManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the SoftwareUpdateManager singleton object. + * + * Internal components can use this to gain access to features of the SoftwareUpdateManager + * that are specific to the EFR32 platform. + */ +inline SoftwareUpdateManagerImpl &SoftwareUpdateMgrImpl(void) +{ + return SoftwareUpdateManagerImpl::sInstance; +} + +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl + +#endif // WEAVE_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER +#endif // SOFTWARE_UPDATE_MANAGER_IMPL_H diff --git a/src/include/platform/EFR32/SystemPlatformConfig.h b/src/include/platform/EFR32/SystemPlatformConfig.h new file mode 100644 index 00000000000000..ff765daf3994e7 --- /dev/null +++ b/src/include/platform/EFR32/SystemPlatformConfig.h @@ -0,0 +1,63 @@ +/* + * + * Copyright (c) 2019 Google LLC. + * 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 + * Platform-specific configuration overrides for the OpenWeave System + * Layer on Silcon Labs EFR32 Platforms. + * + */ + +#ifndef SYSTEM_PLATFORM_CONFIG_H +#define SYSTEM_PLATFORM_CONFIG_H + +#include + +namespace nl { +namespace Weave { +namespace DeviceLayer { +struct WeaveDeviceEvent; +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl + +// ==================== Platform Adaptations ==================== + +#define WEAVE_SYSTEM_CONFIG_POSIX_LOCKING 0 +#define WEAVE_SYSTEM_CONFIG_FREERTOS_LOCKING 0 +#define WEAVE_SYSTEM_CONFIG_NO_LOCKING 1 +#define WEAVE_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 1 +#define WEAVE_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 +#define WEAVE_SYSTEM_CONFIG_LWIP_EVENT_TYPE int +#define WEAVE_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE const struct ::nl::Weave::DeviceLayer::WeaveDeviceEvent * + +#define WEAVE_SYSTEM_CONFIG_ERROR_TYPE int32_t +#define WEAVE_SYSTEM_CONFIG_NO_ERROR 0 +#define WEAVE_SYSTEM_CONFIG_ERROR_MIN 7000000 +#define WEAVE_SYSTEM_CONFIG_ERROR_MAX 7000999 +#define _WEAVE_SYSTEM_CONFIG_ERROR(e) (WEAVE_SYSTEM_CONFIG_ERROR_MIN + (e)) +#define WEAVE_SYSTEM_LWIP_ERROR_MIN 3000000 +#define WEAVE_SYSTEM_LWIP_ERROR_MAX 3000999 + +// ========== Platform-specific Configuration Overrides ========= + +#ifndef WEAVE_SYSTEM_CONFIG_NUM_TIMERS +#define WEAVE_SYSTEM_CONFIG_NUM_TIMERS 16 +#endif // WEAVE_SYSTEM_CONFIG_NUM_TIMERS + +#endif // SYSTEM_PLATFORM_CONFIG_H diff --git a/src/include/platform/EFR32/ThreadStackManagerImpl.h b/src/include/platform/EFR32/ThreadStackManagerImpl.h new file mode 100644 index 00000000000000..5ca73409dd254d --- /dev/null +++ b/src/include/platform/EFR32/ThreadStackManagerImpl.h @@ -0,0 +1,122 @@ +/* + * + * Copyright (c) 2019 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 + * Provides an implementation of the ThreadStackManager object + * for EFR32 platforms using the Silicon Labs SDK and the OpenThread + * stack. + */ + +#ifndef THREAD_STACK_MANAGER_IMPL_H +#define THREAD_STACK_MANAGER_IMPL_H + +#include +#include +#include +#include + +extern "C" void otSysEventSignalPending(void); + +namespace nl { +namespace Weave { +namespace DeviceLayer { + +class ThreadStackManager; +class ThreadStackManagerImpl; +namespace Internal { +extern int GetEntropy_EFR32(uint8_t *buf, size_t bufSize); +} + +/** + * Concrete implementation of the ThreadStackManager singleton object for EFR32 platforms + * using the Silicon Labs SDK and the OpenThread stack. + */ +class ThreadStackManagerImpl final + : public ThreadStackManager, + public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP, + public Internal::GenericThreadStackManagerImpl_FreeRTOS +{ + // Allow the ThreadStackManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend class ThreadStackManager; + + // Allow the generic implementation base classes to call helper methods on + // this class. + friend Internal::GenericThreadStackManagerImpl_OpenThread; + friend Internal::GenericThreadStackManagerImpl_OpenThread_LwIP; + friend Internal::GenericThreadStackManagerImpl_FreeRTOS; + + // Allow glue functions called by OpenThread to call helper methods on this + // class. + friend void ::otTaskletsSignalPending(otInstance *otInst); + friend void ::otSysEventSignalPending(void); + +public: + // ===== Platform-specific members that may be accessed directly by the application. + + using ThreadStackManager::InitThreadStack; + WEAVE_ERROR InitThreadStack(otInstance *otInst); + +private: + // ===== Methods that implement the ThreadStackManager abstract interface. + + WEAVE_ERROR _InitThreadStack(void); + + // ===== Members for internal use by the following friends. + + friend ThreadStackManager & ::nl::Weave::DeviceLayer::ThreadStackMgr(void); + friend ThreadStackManagerImpl & ::nl::Weave::DeviceLayer::ThreadStackMgrImpl(void); + friend int Internal::GetEntropy_EFR32(uint8_t *buf, size_t bufSize); + + static ThreadStackManagerImpl sInstance; + + static bool IsInitialized(); + + // ===== Private members for use by this class only. + + ThreadStackManagerImpl() = default; +}; + +/** + * Returns the public interface of the ThreadStackManager singleton object. + * + * Weave applications should use this to access features of the ThreadStackManager object + * that are common to all platforms. + */ +inline ThreadStackManager &ThreadStackMgr(void) +{ + return ThreadStackManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the ThreadStackManager singleton object. + * + * Weave applications can use this to gain access to features of the ThreadStackManager + * that are specific to EFR32 platforms. + */ +inline ThreadStackManagerImpl &ThreadStackMgrImpl(void) +{ + return ThreadStackManagerImpl::sInstance; +} + +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl + +#endif // THREAD_STACK_MANAGER_IMPL_H diff --git a/src/include/platform/EFR32/WarmPlatformConfig.h b/src/include/platform/EFR32/WarmPlatformConfig.h new file mode 100644 index 00000000000000..d60755163aa513 --- /dev/null +++ b/src/include/platform/EFR32/WarmPlatformConfig.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2019 Google LLC. + * 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 + * Platform-specific configuration overrides for the Weave + * Addressing and Routing Module (WARM) on EFR32 platforms + * using the Silcon Labs SDK. + * + */ + +#ifndef WARM_PLATFORM_CONFIG_H +#define WARM_PLATFORM_CONFIG_H + +// ==================== Platform Adaptations ==================== + +#define WARM_CONFIG_SUPPORT_THREAD 1 +#define WARM_CONFIG_SUPPORT_THREAD_ROUTING 0 +#define WARM_CONFIG_SUPPORT_LEGACY6LOWPAN_NETWORK 0 +#define WARM_CONFIG_SUPPORT_WIFI 0 +#define WARM_CONFIG_SUPPORT_CELLULAR 0 + +// ========== Platform-specific Configuration Overrides ========= + +/* none so far */ + +#endif // WARM_PLATFORM_CONFIG_H diff --git a/src/include/platform/EFR32/WeaveDevicePlatformConfig.h b/src/include/platform/EFR32/WeaveDevicePlatformConfig.h new file mode 100644 index 00000000000000..6b697e41a746ff --- /dev/null +++ b/src/include/platform/EFR32/WeaveDevicePlatformConfig.h @@ -0,0 +1,134 @@ +/* + * + * Copyright (c) 2019 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 + * Platform-specific configuration overrides for the Weave Device Layer + * on EFR32 platforms using the Silicon Labs SDK. + */ + +#ifndef WEAVE_DEVICE_PLATFORM_CONFIG_H +#define WEAVE_DEVICE_PLATFORM_CONFIG_H + +// ==================== Platform Adaptations ==================== + +#define WEAVE_DEVICE_CONFIG_EFR32_NVM3_ERROR_MIN 12000000 +#define WEAVE_DEVICE_CONFIG_EFR32_BLE_ERROR_MIN 13000000 + +#define WEAVE_DEVICE_CONFIG_ENABLE_WIFI_STATION 0 +#define WEAVE_DEVICE_CONFIG_ENABLE_WIFI_AP 0 + +#define WEAVE_DEVICE_CONFIG_ENABLE_THREAD 1 +#define WEAVE_DEVICE_CONFIG_ENABLE_WOBLE 1 + +#define WEAVE_DEVICE_CONFIG_ENABLE_WEAVE_TIME_SERVICE_TIME_SYNC 1 +#define WEAVE_DEVICE_CONFIG_ENABLE_SERVICE_DIRECTORY_TIME_SYNC 0 + +#define WEAVE_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY 2 +#define WEAVE_DEVICE_CONFIG_PERSISTED_STORAGE_PROD_EIDC_KEY 3 +#define WEAVE_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY 4 +#define WEAVE_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY 5 + +// ========== Platform-specific Configuration ========= + +// These are configuration options that are unique to the EFR32 platform. +// These can be overridden by the application as needed. +/** + * @def WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE + * + * The maximum size of any log message. + */ +#ifndef WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE +#define WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE 150 +#endif // WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE + +// -------------- EFR32 NVM3 Storage Configuration ------------- + +/** + * @def WEAVE_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS + * + * @brief + * Configures the size of the nvm3 cache and should be set >= the + * maximum number of Weave Config objects, e.g... + * Factory configs[5], System configs[23], Counter configs[32] + margin[4] = 64. + * + */ +#ifndef WEAVE_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS +#define WEAVE_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS 64 +#endif // WEAVE_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS + +/** + * @def WEAVE_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE + * + * @brief + * This determines the max size for any Weave nvm3 object + * (e.g. for Config 'string' or 'binary' types). + */ +#ifndef WEAVE_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE +#define WEAVE_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE 1000 +#endif // WEAVE_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE + +/** + * @def WEAVE_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE + * + * @brief + * This determines the Flash size used for nvm3 data storage:- + * (assuming 2k Flash page size) => Total Flash size for nvm3: 8 * 2k = 16k + * The total size should allow sufficient margin for wear-levelling and + * repacking. + */ +#ifndef WEAVE_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE +#define WEAVE_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE 8 +#endif // WEAVE_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE + +// ========== Platform-specific Configuration Overrides ========= + +#ifndef WEAVE_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY +#define WEAVE_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY (configTIMER_TASK_PRIORITY - 1) +#endif // WEAVE_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY + +#ifndef WEAVE_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY +#define WEAVE_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY (WEAVE_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY - 1) +#endif // WEAVE_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY + +#ifndef WEAVE_DEVICE_CONFIG_BLE_APP_TASK_PRIORITY +#define WEAVE_DEVICE_CONFIG_BLE_APP_TASK_PRIORITY (WEAVE_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY - 1) +#endif // WEAVE_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY + +#ifndef WEAVE_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE +#define WEAVE_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE 1024 +#endif // WEAVE_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE + +#ifndef WEAVE_DEVICE_CONFIG_WEAVE_TASK_STACK_SIZE +#define WEAVE_DEVICE_CONFIG_WEAVE_TASK_STACK_SIZE 8192 +#endif // WEAVE_DEVICE_CONFIG_WEAVE_TASK_STACK_SIZE + +#ifndef WEAVE_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE +#define WEAVE_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE 8192 +#endif // WEAVE_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE + +#define WEAVE_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY 0 +#define WEAVE_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY 1 +#define WEAVE_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL 0 +#define WEAVE_DEVICE_CONFIG_ENABLE_TUNNEL_TELEMETRY 0 + +#ifndef WEAVE_DEVICE_CONFIG_BLE_APP_TASK_NAME +#define WEAVE_DEVICE_CONFIG_BLE_APP_TASK_NAME "Bluetooth App Task" +#endif // WEAVE_DEVICE_CONFIG_BLE_APP_TASK_NAME + +#endif // WEAVE_DEVICE_PLATFORM_CONFIG_H diff --git a/src/include/platform/EFR32/WeaveDevicePlatformEvent.h b/src/include/platform/EFR32/WeaveDevicePlatformEvent.h new file mode 100644 index 00000000000000..e686c20a95f513 --- /dev/null +++ b/src/include/platform/EFR32/WeaveDevicePlatformEvent.h @@ -0,0 +1,78 @@ +/* + * + * Copyright (c) 2019 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 + * Defines platform-specific event types and data for the Weave + * Device Layer on EFR32 platforms using the Silicon Labs SDK. + */ + +#ifndef WEAVE_DEVICE_PLATFORM_EVENT_H +#define WEAVE_DEVICE_PLATFORM_EVENT_H + +#include + +namespace nl { +namespace Weave { +namespace System { +class PacketBuffer; +} +} // namespace Weave +} // namespace nl + +namespace nl { +namespace Weave { +namespace DeviceLayer { + +namespace DeviceEventType { + +/** + * Enumerates EFR32 platform-specific event types that are visible to the application. + */ +enum PublicPlatformSpecificEventTypes +{ + /* None currently defined */ +}; + +/** + * Enumerates EFR32 platform-specific event types that are internal to the Weave Device Layer. + */ +enum InternalPlatformSpecificEventTypes +{ + /* None currently defined */ +}; + +} // namespace DeviceEventType + +/** + * Represents platform-specific event information for Silicon Labs EFR32 platforms. + */ + +struct WeaveDevicePlatformEvent final +{ + union + { + /* None currently defined */ + }; +}; + +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl + +#endif // WEAVE_DEVICE_PLATFORM_EVENT_H diff --git a/src/include/platform/EFR32/WeavePlatformConfig.h b/src/include/platform/EFR32/WeavePlatformConfig.h new file mode 100644 index 00000000000000..59876904196bde --- /dev/null +++ b/src/include/platform/EFR32/WeavePlatformConfig.h @@ -0,0 +1,150 @@ +/* + * + * Copyright (c) 2019 Google LLC. + * 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 + * Platform-specific configuration overrides for OpenWeave on + * Silcon Labs EFR32 platforms. + */ + +#ifndef WEAVE_PLATFORM_CONFIG_H +#define WEAVE_PLATFORM_CONFIG_H + +#include + +// ==================== General Platform Adaptations ==================== + +#define WEAVE_CONFIG_ERROR_TYPE int32_t +#define WEAVE_CONFIG_NO_ERROR 0 +#define WEAVE_CONFIG_ERROR_MIN 4000000 +#define WEAVE_CONFIG_ERROR_MAX 4000999 + +#define ASN1_CONFIG_ERROR_TYPE int32_t +#define ASN1_CONFIG_NO_ERROR 0 +#define ASN1_CONFIG_ERROR_MIN 5000000 +#define ASN1_CONFIG_ERROR_MAX 5000999 + +#define WeaveDie() abort() + +#define WEAVE_CONFIG_ENABLE_TUNNELING 0 +#define WEAVE_CONFIG_MAX_TUNNELS 0 +#define WEAVE_CONFIG_ENABLE_SERVICE_DIRECTORY 0 + +#define WEAVE_CONFIG_PERSISTED_STORAGE_KEY_TYPE uint8_t +#define WEAVE_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_ID 1 +#define WEAVE_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH 2 + +#define WEAVE_CONFIG_TIME_ENABLE_CLIENT 1 +#define WEAVE_CONFIG_TIME_ENABLE_SERVER 0 + +// ==================== Security Adaptations ==================== + +#define WEAVE_CONFIG_USE_OPENSSL_ECC 0 +#define WEAVE_CONFIG_USE_MICRO_ECC 1 + +#define WEAVE_CONFIG_HASH_IMPLEMENTATION_OPENSSL 0 +#define WEAVE_CONFIG_HASH_IMPLEMENTATION_MINCRYPT 1 +#define WEAVE_CONFIG_HASH_IMPLEMENTATION_MBEDTLS 0 +#define WEAVE_CONFIG_HASH_IMPLEMENTATION_PLATFORM 0 + +// FIXME: EFR32 set to MBED-TLS (But this is third-party repo in OpenWeave, not SDK) + +#define WEAVE_CONFIG_AES_IMPLEMENTATION_OPENSSL 0 +#define WEAVE_CONFIG_AES_IMPLEMENTATION_AESNI 0 +#define WEAVE_CONFIG_AES_IMPLEMENTATION_MBEDTLS 1 +#define WEAVE_CONFIG_AES_IMPLEMENTATION_PLATFORM 0 + +// FIXME: EFR32 currently set to Nest (Does this use Entropy.cpp ?) + +#define WEAVE_CONFIG_RNG_IMPLEMENTATION_OPENSSL 0 +#define WEAVE_CONFIG_RNG_IMPLEMENTATION_NESTDRBG 1 +#define WEAVE_CONFIG_RNG_IMPLEMENTATION_PLATFORM 0 + +#define WEAVE_CONFIG_ENABLE_PASE_INITIATOR 0 +#define WEAVE_CONFIG_ENABLE_PASE_RESPONDER 1 +#define WEAVE_CONFIG_ENABLE_CASE_INITIATOR 1 + +#define WEAVE_CONFIG_SUPPORT_PASE_CONFIG0 0 +#define WEAVE_CONFIG_SUPPORT_PASE_CONFIG1 0 +#define WEAVE_CONFIG_SUPPORT_PASE_CONFIG2 0 +#define WEAVE_CONFIG_SUPPORT_PASE_CONFIG3 0 +#define WEAVE_CONFIG_SUPPORT_PASE_CONFIG4 1 + +#define WEAVE_CONFIG_ENABLE_KEY_EXPORT_INITIATOR 0 + +#define WEAVE_CONFIG_ENABLE_PROVISIONING_BUNDLE_SUPPORT 0 + +// ==================== General Configuration Overrides ==================== + +#ifndef WEAVE_CONFIG_MAX_PEER_NODES +#define WEAVE_CONFIG_MAX_PEER_NODES 16 +#endif // WEAVE_CONFIG_MAX_PEER_NODES + +#ifndef WEAVE_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS +#define WEAVE_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS 16 +#endif // WEAVE_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS + +#ifndef WEAVE_CONFIG_MAX_EXCHANGE_CONTEXTS +#define WEAVE_CONFIG_MAX_EXCHANGE_CONTEXTS 8 +#endif // WEAVE_CONFIG_MAX_EXCHANGE_CONTEXTS + +#ifndef WEAVE_CONFIG_WRMP_TIMER_DEFAULT_PERIOD +#define WEAVE_CONFIG_WRMP_TIMER_DEFAULT_PERIOD 50 +#endif // WEAVE_CONFIG_WRMP_TIMER_DEFAULT_PERIOD + +#ifndef WEAVE_LOG_FILTERING +#define WEAVE_LOG_FILTERING 0 +#endif // WEAVE_LOG_FILTERING + +#ifndef WEAVE_CONFIG_MAX_INTERFACES +#define WEAVE_CONFIG_MAX_INTERFACES 4 +#endif // WEAVE_CONFIG_MAX_INTERFACES + +#ifndef WEAVE_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS +#define WEAVE_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS 4 +#endif // WEAVE_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS + +// ==================== Security Configuration Overrides ==================== + +#ifndef WEAVE_CONFIG_MAX_APPLICATION_GROUPS +#define WEAVE_CONFIG_MAX_APPLICATION_GROUPS 4 +#endif // WEAVE_CONFIG_MAX_APPLICATION_GROUPS + +#ifndef WEAVE_CONFIG_DEBUG_CERT_VALIDATION +#define WEAVE_CONFIG_DEBUG_CERT_VALIDATION 0 +#endif // WEAVE_CONFIG_DEBUG_CERT_VALIDATION + +#ifndef WEAVE_CONFIG_ENABLE_CASE_RESPONDER +#define WEAVE_CONFIG_ENABLE_CASE_RESPONDER 1 +#endif // WEAVE_CONFIG_ENABLE_CASE_RESPONDER + +// ==================== WDM Configuration Overrides ==================== + +#ifndef WDM_MAX_NUM_SUBSCRIPTION_CLIENTS +#define WDM_MAX_NUM_SUBSCRIPTION_CLIENTS 2 +#endif // WDM_MAX_NUM_SUBSCRIPTION_CLIENTS + +#ifndef WDM_MAX_NUM_SUBSCRIPTION_HANDLERS +#define WDM_MAX_NUM_SUBSCRIPTION_HANDLERS 2 +#endif // WDM_MAX_NUM_SUBSCRIPTION_HANDLERS + +#ifndef WDM_PUBLISHER_MAX_NOTIFIES_IN_FLIGHT +#define WDM_PUBLISHER_MAX_NOTIFIES_IN_FLIGHT 2 +#endif // WDM_PUBLISHER_MAX_NOTIFIES_IN_FLIGHT + +#endif /* WEAVE_PLATFORM_CONFIG_H */ diff --git a/src/include/platform/EFR32/efr32-weave-mbedtls-config.h b/src/include/platform/EFR32/efr32-weave-mbedtls-config.h new file mode 100644 index 00000000000000..7fe934c2a4ec5b --- /dev/null +++ b/src/include/platform/EFR32/efr32-weave-mbedtls-config.h @@ -0,0 +1,130 @@ +/* + * + * Copyright (c) 2019 Google LLC. + * 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. + */ + +#ifndef EFR32_MBEDTLS_CONFIG_H +#define EFR32_MBEDTLS_CONFIG_H + +#include "em_device.h" +#include "em_se.h" + +/** + * Enable FreeRTOS threading support + */ +#define MBEDTLS_FREERTOS +#define MBEDTLS_THREADING_C +#define MBEDTLS_THREADING_ALT + +/** + * Enable Crypto and Entropy modules + */ +#define MBEDTLS_AES_C +#define MBEDTLS_ECP_C +#define MBEDTLS_ECDH_C +#define MBEDTLS_ENTROPY_C +#define MBEDTLS_SHA1_C +#define MBEDTLS_SHA256_C +#define MBEDTLS_TRNG_C +#define MBEDTLS_CIPHER_MODE_CTR + +/** + * \def MBEDTLS_AES_ALT + * + * Enable hardware acceleration for the AES block cipher + * + * Module: sl_crypto/src/crypto_aes.c for devices with CRYPTO + * sl_crypto/src/aes_aes.c for devices with AES + * + * See MBEDTLS_AES_C for more information. + */ +#define MBEDTLS_AES_ALT + +/** + * \def MBEDTLS_ENTROPY_HARDWARE_ALT + * + * Integrate the provided default entropy source into the mbed + * TLS entropy infrastructure. + * + */ +#define MBEDTLS_ENTROPY_HARDWARE_ALT + +/** + * \def MBEDTLS_ECP_INTERNAL_ALT + * \def ECP_SHORTWEIERSTRASS + * \def MBEDTLS_ECP_ADD_MIXED_ALT + * \def MBEDTLS_ECP_DOUBLE_JAC_ALT + * \def MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT + * \def MBEDTLS_ECP_NORMALIZE_JAC_ALT + * + * Enable hardware acceleration for the elliptic curve over GF(p) library. + * + * Module: sl_crypto/src/crypto_ecp.c + * Caller: library/ecp.c + * + * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_ECP_C and at least one + * MBEDTLS_ECP_DP_XXX_ENABLED and (CRYPTO_COUNT > 0) + */ +#if defined(CRYPTO_COUNT) && (CRYPTO_COUNT > 0) +#define MBEDTLS_ECP_INTERNAL_ALT +#define ECP_SHORTWEIERSTRASS +#define MBEDTLS_ECP_ADD_MIXED_ALT +#define MBEDTLS_ECP_DOUBLE_JAC_ALT +#define MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT +#define MBEDTLS_ECP_NORMALIZE_JAC_ALT +#define MBEDTLS_ECP_RANDOMIZE_JAC_ALT +#endif + +/** + * \def MBEDTLS_SHA1_ALT + * + * Enable hardware acceleration for the SHA-224 and SHA-256 cryptographic + * hash algorithms. + * Module: sl_crypto/src/crypto_sha.c + * Caller: library/mbedtls_md.c + * library/ssl_cli.c + * library/ssl_srv.c + * library/ssl_tls.c + * library/x509write_crt.c + * + * Requires: MBEDTLS_SHA1_C and (CRYPTO_COUNT > 0) + * See MBEDTLS_SHA1_C for more information. + */ +#if defined(CRYPTO_COUNT) && (CRYPTO_COUNT > 0) +#define MBEDTLS_SHA1_ALT +#endif + +/** + * \def MBEDTLS_SHA256_ALT + * + * Enable hardware acceleration for the SHA-224 and SHA-256 cryptographic + * hash algorithms. + * + * Module: sl_crypto/src/crypto_sha.c + * Caller: library/entropy.c + * library/mbedtls_md.c + * library/ssl_cli.c + * library/ssl_srv.c + * library/ssl_tls.c + * + * Requires: MBEDTLS_SHA256_C and (CRYPTO_COUNT > 0) + * See MBEDTLS_SHA256_C for more information. + */ +#if defined(CRYPTO_COUNT) && (CRYPTO_COUNT > 0) +#define MBEDTLS_SHA256_ALT +#endif + +#endif // EFR32_MBEDTLS_CONFIG_H diff --git a/src/include/platform/EFR32/freertos_bluetooth.h b/src/include/platform/EFR32/freertos_bluetooth.h new file mode 100644 index 00000000000000..9321ec3ed8e827 --- /dev/null +++ b/src/include/platform/EFR32/freertos_bluetooth.h @@ -0,0 +1,87 @@ +/* + * + * Copyright (c) 2020 Google LLC. + * 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. + */ + +#ifndef FREERTOS_BLUETOOTH_H +#define FREERTOS_BLUETOOTH_H + +#if __cplusplus +extern "C" { +#endif + +#include "rtos_gecko.h" +#include "FreeRTOS.h" +#include "task.h" +#include "timers.h" +#include "semphr.h" +#include "event_groups.h" + +// Bluetooth event flag group +extern EventGroupHandle_t bluetooth_event_flags; +// Bluetooth event flag definitions +#define BLUETOOTH_EVENT_FLAG_STACK (0x01) // Bluetooth task needs an update +#define BLUETOOTH_EVENT_FLAG_LL (0x02) // Linklayer task needs an update +#define BLUETOOTH_EVENT_FLAG_CMD_WAITING (0x04) // BGAPI command is waiting to be processed +#define BLUETOOTH_EVENT_FLAG_RSP_WAITING (0x08) // BGAPI response is waiting to be processed +#define BLUETOOTH_EVENT_FLAG_EVT_WAITING (0x10) // BGAPI event is waiting to be processed +#define BLUETOOTH_EVENT_FLAG_EVT_HANDLED (0x20) // BGAPI event is handled + +// Bluetooth event data pointer +extern volatile struct gecko_cmd_packet *bluetooth_evt; + +// Function prototype for initializing Bluetooth stack. +typedef errorcode_t (*bluetooth_stack_init_func)(); + +/** + * Start Bluetooth tasks. The given Bluetooth stack initialization function + * will be called at a proper time. Application should not initialize + * Bluetooth stack anywhere else. + * + * @param ll_priority link layer task priority + * @param stack_priority Bluetooth stack task priority + * @param initialize_bluetooth_stack The function for initializing Bluetooth stack + */ +errorcode_t bluetooth_start(UBaseType_t ll_priority, + UBaseType_t stack_priority, + bluetooth_stack_init_func initialize_bluetooth_stack); + +// Set the callback for wakeup, Bluetooth task will call this when it has a new event +// It must only used to wake up application task, for example by posting task semaphore +typedef void (*wakeupCallback)(void); +void BluetoothSetWakeupCallback(wakeupCallback cb); +// Bluetooth stack needs an update +extern void BluetoothUpdate(void); +// Linklayer is updated +extern void BluetoothLLCallback(void); + +// Mutex functions for using Bluetooth from multiple tasks +void BluetoothPend(void); +void BluetoothPost(void); + +EventBits_t vRaiseEventFlagBasedOnContext(EventGroupHandle_t xEventGroup, + EventBits_t uxBitsToWaitFor, + BaseType_t * pxHigherPriorityTaskWoken); +EventBits_t vSendToQueueBasedOnContext(QueueHandle_t xQueue, + void * xItemToQueue, + TickType_t xTicksToWait, + BaseType_t * pxHigherPriorityTaskWoken); + +#if __cplusplus +} +#endif + +#endif // FREERTOS_BLUETOOTH_H diff --git a/src/include/platform/EFR32/gatt.xml b/src/include/platform/EFR32/gatt.xml new file mode 100644 index 00000000000000..4b985a085973d5 --- /dev/null +++ b/src/include/platform/EFR32/gatt.xml @@ -0,0 +1,98 @@ + + + + + + + + + Abstract: The generic_access service contains generic information about the device. All available Characteristics are readonly. + + + + + Empty Example + + + + + + Abstract: The external appearance of this device. The values are composed of a category (10-bits) and sub-categories (6-bits). + 0000 + + + + + + + Abstract: The Device Information Service exposes manufacturer and/or vendor information about a device. Summary: This service exposes manufacturer information about a device. The Device Information Service is instantiated as a Primary Service. Only one instance of the Device Information Service is exposed on a device. + + + + Abstract: The value of this characteristic is a UTF-8 string representing the name of the manufacturer of the device. + Silicon Labs + + + + + + Abstract: The value of this characteristic is a UTF-8 string representing the model number assigned by the device vendor. + Blue Gecko + + + + + + Abstract: The SYSTEM ID characteristic consists of a structure with two fields. The first field are the LSOs and the second field contains the MSOs. This is a 64-bit structure which consists of a 40-bit manufacturer-defined identifier concatenated with a 24 bit unique Organizationally Unique Identifier (OUI). The OUI is issued by the IEEE Registration Authority (http://standards.ieee.org/regauth/index.html) and is required to be used in accordance with IEEE Standard 802-2001.6 while the least significant 40 bits are manufacturer defined. If System ID generated based on a Bluetooth Device Address, it is required to be done as follows. System ID and the Bluetooth Device Address have a very similar structure: a Bluetooth Device Address is 48 bits in length and consists of a 24 bit Company Assigned Identifier (manufacturer defined identifier) concatenated with a 24 bit Company Identifier (OUI). In order to encapsulate a Bluetooth Device Address as System ID, the Company Identifier is concatenated with 0xFFFE followed by the Company Assigned Identifier of the Bluetooth Address. For more guidelines related to EUI-64, refer to http://standards.ieee.org/develop/regauth/tut/eui64.pdf. Examples: If the system ID is based of a Bluetooth Device Address with a Company Identifier (OUI) is 0x123456 and the Company Assigned Identifier is 0x9ABCDE, then the System Identifier is required to be 0x123456FFFE9ABCDE. + 000102030405 + + + + + + + Abstract: The Silicon Labs OTA Service enables over-the-air firmware update of the device. + + + + Abstract: Silicon Labs OTA Control. + + + + + + + + Custom service + + + + Custom characteristic + 0x00 + + + + + + Custom characteristic + 0x00 + + + + diff --git a/src/include/platform/EFR32/gatt_db.h b/src/include/platform/EFR32/gatt_db.h new file mode 100644 index 00000000000000..cb35f90cb01dda --- /dev/null +++ b/src/include/platform/EFR32/gatt_db.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2020 Google LLC. + * 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. + */ + +#ifndef __GATT_DB_H +#define __GATT_DB_H + +#if __cplusplus +extern "C" { +#endif + +#include "bg_gattdb_def.h" + +extern const struct bg_gattdb_def bg_gattdb_data; + +#define gattdb_service_changed_char 3 +#define gattdb_database_hash 6 +#define gattdb_client_support_features 8 +#define gattdb_device_name 11 +#define gattdb_ota_control 23 +#define gattdb_WoBLEChar_Rx 26 +#define gattdb_WoBLEChar_Tx 28 + +#if __cplusplus +} +#endif + +#endif diff --git a/src/platform/EFR32/BLEManagerImpl.cpp b/src/platform/EFR32/BLEManagerImpl.cpp new file mode 100644 index 00000000000000..28142b1e194e9d --- /dev/null +++ b/src/platform/EFR32/BLEManagerImpl.cpp @@ -0,0 +1,986 @@ +/* + * + * Copyright (c) 2019 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 + * Provides an implementation of the BLEManager singleton object + * for the Silicon Labs EFR32 platforms. + */ + +#include +#include +#include +#include + +#if WEAVE_DEVICE_CONFIG_ENABLE_WOBLE + +#include +#include "rtos_gecko.h" + +using namespace ::nl; +using namespace ::nl::Ble; + +namespace nl { +namespace Weave { +namespace DeviceLayer { +namespace Internal { + +namespace { + +#define WEAVE_ADV_DATA_TYPE_FLAGS 0x01 +#define WEAVE_ADV_DATA_TYPE_UUID 0x03 +#define WEAVE_ADV_DATA_TYPE_NAME 0x09 +#define WEAVE_ADV_DATA_TYPE_SERVICE_DATA 0x16 + +#define WEAVE_ADV_DATA_FLAGS 0x06 +#define WEAVE_ADV_WOBLE_SERVICE_HANDLE 0 + +#define WEAVE_ADV_DATA 0 +#define WEAVE_ADV_SCAN_RESPONSE_DATA 1 +#define WEAVE_ADV_SHORT_UUID_LEN 2 + +#define MAX_RESPONSE_DATA_LEN 31 +#define MAX_ADV_DATA_LEN 31 + +// Timer Frequency used. +#define TIMER_CLK_FREQ ((uint32)32768) +// Convert msec to timer ticks. +#define TIMER_MS_2_TIMERTICK(ms) ((TIMER_CLK_FREQ * ms) / 1000) +#define TIMER_S_2_TIMERTICK(s) (TIMER_CLK_FREQ * s) + +uint8_t bluetooth_stack_heap[DEFAULT_BLUETOOTH_HEAP(BLE_LAYER_NUM_BLE_ENDPOINTS)]; + +/* Bluetooth stack configuration parameters (see "UG136: Silicon Labs Bluetooth C Application Developer's Guide" for + * details on each parameter) */ +static gecko_configuration_t config; + +const uint8_t UUID_WoBLEService[] = {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, + 0x00, 0x10, 0x00, 0x00, 0xAF, 0xFE, 0x00, 0x00}; +const uint8_t ShortUUID_WoBLEService[] = {0xAF, 0xFE}; +const WeaveBleUUID WeaveUUID_WoBLEChar_RX = { + {0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, 0x9D, 0x11}}; +const WeaveBleUUID WeaveUUID_WoBLEChar_TX = { + {0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, 0x9D, 0x12}}; + +} // namespace + +BLEManagerImpl BLEManagerImpl::sInstance; + +/***************************************************************************/ /** + * Setup the bluetooth init function. + * + * @return error code for the gecko_init + *function + * + * All bluetooth specific initialization + *code should be here like gecko_init(), + * gecko_init_whitelisting(), + *gecko_init_multiprotocol() and so on. + ******************************************************************************/ +extern "C" errorcode_t initialize_bluetooth() +{ + errorcode_t err = gecko_init(&config); + + if (err == bg_err_success) + { + gecko_init_multiprotocol(NULL); + } + return err; +} + +static void initBleConfig(void) +{ + memset(&config, 0, sizeof(gecko_configuration_t)); + config.config_flags = GECKO_CONFIG_FLAG_RTOS; /* Check flag options from UG136 */ + config.bluetooth.max_connections = BLE_LAYER_NUM_BLE_ENDPOINTS; /* Maximum number of simultaneous connections */ + config.bluetooth.heap = bluetooth_stack_heap; /* Bluetooth stack memory for connection management */ + config.bluetooth.heap_size = sizeof(bluetooth_stack_heap); /* Size of Heap */ + config.gattdb = &bg_gattdb_data; /* Pointer to GATT database */ + config.scheduler_callback = BluetoothLLCallback; + config.stack_schedule_callback = BluetoothUpdate; +#if (HAL_PA_ENABLE) + config.pa.config_enable = 1; /* Set this to be a valid PA config */ +#if defined(FEATURE_PA_INPUT_FROM_VBAT) + config.pa.input = GECKO_RADIO_PA_INPUT_VBAT; /* Configure PA input to VBAT */ +#else + config.pa.input = GECKO_RADIO_PA_INPUT_DCDC; /* Configure PA input to DCDC */ +#endif // defined(FEATURE_PA_INPUT_FROM_VBAT) +#endif // (HAL_PA_ENABLE) + config.mbedtls.flags = GECKO_MBEDTLS_FLAGS_NO_MBEDTLS_DEVICE_INIT; + config.mbedtls.dev_number = 0; +} + +WEAVE_ERROR BLEManagerImpl::_Init() +{ + WEAVE_ERROR err; + errorcode_t ret; + + // Initialize the Weave BleLayer. + err = BleLayer::Init(this, this, &SystemLayer); + SuccessOrExit(err); + + memset(mBleConnections, 0, sizeof(mBleConnections)); + memset(mIndConfId, kUnusedIndex, sizeof(mIndConfId)); + mServiceMode = ConnectivityManager::kWoBLEServiceMode_Enabled; + + initBleConfig(); + + // Start Bluetooth Link Layer and stack tasks + ret = bluetooth_start(WEAVE_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY, WEAVE_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY, + initialize_bluetooth); + + VerifyOrExit(ret == bg_err_success, err = MapBLEError(ret)); + + // Create the Bluetooth Application task + xTaskCreate(bluetoothStackEventHandler, /* Function that implements the task. */ + WEAVE_DEVICE_CONFIG_BLE_APP_TASK_NAME, /* Text name for the task. */ + WEAVE_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE / + sizeof(StackType_t), /* Number of indexes in the xStack array. */ + this, /* Parameter passed into the task. */ + WEAVE_DEVICE_CONFIG_BLE_APP_TASK_PRIORITY, /* Priority at which the task is created. */ + NULL); /* Variable to hold the task's data structure. */ + + mFlags = kFlag_AdvertisingEnabled; + PlatformMgr().ScheduleWork(DriveBLEState, 0); + +exit: + return err; +} + +uint16_t BLEManagerImpl::_NumConnections(void) +{ + uint16_t numCons = 0; + for (uint16_t i = 0; i < kMaxConnections; i++) + { + if (mBleConnections[i].allocated) + { + numCons++; + } + } + + return numCons; +} + +void BLEManagerImpl::bluetoothStackEventHandler(void *p_arg) +{ + EventBits_t flags = 0; + + while (1) + { + // wait for Bluetooth stack events, do not consume set flag + flags |= + xEventGroupWaitBits(bluetooth_event_flags, /* The event group being tested. */ + BLUETOOTH_EVENT_FLAG_EVT_WAITING, /* The bits within the event group to wait for. */ + pdFALSE, /* Dont clear flags before returning */ + pdFALSE, /* Any flag will do, dont wait for all flags to be set */ + portMAX_DELAY); /* Wait for maximum duration for bit to be set */ + + if (flags & BLUETOOTH_EVENT_FLAG_EVT_WAITING) + { + flags &= ~BLUETOOTH_EVENT_FLAG_EVT_WAITING; + xEventGroupClearBits(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_EVT_WAITING); + + // As this is running in a separate thread, we need to block Weave from operating, + // until the events are handled. + PlatformMgr().LockWeaveStack(); + + // handle bluetooth events + switch (BGLIB_MSG_ID(bluetooth_evt->header)) + { + case gecko_evt_system_boot_id: + { + sInstance.HandleBootEvent(); + } + break; + + case gecko_evt_le_connection_opened_id: + { + sInstance.HandleConnectEvent(bluetooth_evt); + } + break; + + case gecko_evt_le_connection_closed_id: + { + sInstance.HandleConnectionCloseEvent(bluetooth_evt); + } + break; + + /* This event indicates that a remote GATT client is attempting to write a value of an + * attribute in to the local GATT database, where the attribute was defined in the GATT + * XML firmware configuration file to have type="user". */ + case gecko_evt_gatt_server_attribute_value_id: + { + sInstance.HandleWriteEvent(bluetooth_evt); + } + break; + + case gecko_evt_gatt_mtu_exchanged_id: + { + sInstance.UpdateMtu(bluetooth_evt); + } + break; + + // confirmation of indication received from remote GATT client + case gecko_evt_gatt_server_characteristic_status_id: + { + enum gatt_server_characteristic_status_flag StatusFlags; + + StatusFlags = (enum gatt_server_characteristic_status_flag) + bluetooth_evt->data.evt_gatt_server_characteristic_status.status_flags; + + if (gatt_server_confirmation == StatusFlags) + { + sInstance.HandleTxConfirmationEvent(bluetooth_evt); + } + else if ((bluetooth_evt->data.evt_gatt_server_characteristic_status.characteristic == + gattdb_WoBLEChar_Tx) && + (bluetooth_evt->data.evt_gatt_server_characteristic_status.status_flags == + gatt_server_client_config)) + { + sInstance.HandleTXCharCCCDWrite(bluetooth_evt); + } + } + break; + + /* Software Timer event */ + case gecko_evt_hardware_soft_timer_id: + { + sInstance.HandleSoftTimerEvent(bluetooth_evt); + } + break; + + default: + WeaveLogProgress(DeviceLayer, "evt_UNKNOWN id = %08x", BGLIB_MSG_ID(bluetooth_evt->header)); + break; + } + } + + PlatformMgr().UnlockWeaveStack(); + + flags = vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_EVT_HANDLED, NULL); + } +} + +WEAVE_ERROR BLEManagerImpl::_SetWoBLEServiceMode(WoBLEServiceMode val) +{ + WEAVE_ERROR err = WEAVE_NO_ERROR; + + VerifyOrExit(val != ConnectivityManager::kWoBLEServiceMode_NotSupported, err = WEAVE_ERROR_INVALID_ARGUMENT); + VerifyOrExit(mServiceMode != ConnectivityManager::kWoBLEServiceMode_NotSupported, + err = WEAVE_ERROR_UNSUPPORTED_WEAVE_FEATURE); + + if (val != mServiceMode) + { + mServiceMode = val; + PlatformMgr().ScheduleWork(DriveBLEState, 0); + } + +exit: + return err; +} + +WEAVE_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val) +{ + WEAVE_ERROR err = WEAVE_NO_ERROR; + + VerifyOrExit(mServiceMode != ConnectivityManager::kWoBLEServiceMode_NotSupported, + err = WEAVE_ERROR_UNSUPPORTED_WEAVE_FEATURE); + + if (GetFlag(mFlags, kFlag_AdvertisingEnabled) != val) + { + SetFlag(mFlags, kFlag_AdvertisingEnabled, val); + PlatformMgr().ScheduleWork(DriveBLEState, 0); + } + +exit: + return err; +} + +WEAVE_ERROR BLEManagerImpl::_SetFastAdvertisingEnabled(bool val) +{ + WEAVE_ERROR err = WEAVE_NO_ERROR; + + VerifyOrExit(mServiceMode == ConnectivityManager::kWoBLEServiceMode_NotSupported, + err = WEAVE_ERROR_UNSUPPORTED_WEAVE_FEATURE); + + if (GetFlag(mFlags, kFlag_FastAdvertisingEnabled) != val) + { + SetFlag(mFlags, kFlag_FastAdvertisingEnabled, val); + PlatformMgr().ScheduleWork(DriveBLEState, 0); + } + +exit: + return err; +} + +WEAVE_ERROR BLEManagerImpl::_GetDeviceName(char *buf, size_t bufSize) +{ + if (strlen(mDeviceName) >= bufSize) + { + return WEAVE_ERROR_BUFFER_TOO_SMALL; + } + strcpy(buf, mDeviceName); + return WEAVE_NO_ERROR; +} + +WEAVE_ERROR BLEManagerImpl::_SetDeviceName(const char *deviceName) +{ + if (mServiceMode == ConnectivityManager::kWoBLEServiceMode_NotSupported) + { + return WEAVE_ERROR_UNSUPPORTED_WEAVE_FEATURE; + } + if (deviceName != NULL && deviceName[0] != 0) + { + if (strlen(deviceName) >= kMaxDeviceNameLength) + { + return WEAVE_ERROR_INVALID_ARGUMENT; + } + strcpy(mDeviceName, deviceName); + SetFlag(mFlags, kFlag_DeviceNameSet, true); + WeaveLogProgress(DeviceLayer, "Setting device name to : \"%s\"", deviceName); + gecko_cmd_gatt_server_write_attribute_value(gattdb_device_name, 0, strlen(deviceName), (uint8_t *)deviceName); + } + else + { + mDeviceName[0] = 0; + } + return WEAVE_NO_ERROR; +} + +void BLEManagerImpl::_OnPlatformEvent(const WeaveDeviceEvent *event) +{ + switch (event->Type) + { + case DeviceEventType::kWoBLESubscribe: + { + WeaveDeviceEvent connEstEvent; + + WeaveLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLESubscribe"); + HandleSubscribeReceived(event->WoBLESubscribe.ConId, &WEAVE_BLE_SVC_ID, &WeaveUUID_WoBLEChar_TX); + connEstEvent.Type = DeviceEventType::kWoBLEConnectionEstablished; + PlatformMgr().PostEvent(&connEstEvent); + } + break; + + case DeviceEventType::kWoBLEUnsubscribe: + { + WeaveLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLEUnsubscribe"); + HandleUnsubscribeReceived(event->WoBLEUnsubscribe.ConId, &WEAVE_BLE_SVC_ID, &WeaveUUID_WoBLEChar_TX); + } + break; + + case DeviceEventType::kWoBLEWriteReceived: + { + WeaveLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLEWriteReceived"); + HandleWriteReceived(event->WoBLEWriteReceived.ConId, &WEAVE_BLE_SVC_ID, &WeaveUUID_WoBLEChar_RX, + event->WoBLEWriteReceived.Data); + } + break; + + case DeviceEventType::kWoBLEConnectionError: + { + WeaveLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLEConnectionError"); + HandleConnectionError(event->WoBLEConnectionError.ConId, event->WoBLEConnectionError.Reason); + } + break; + + case DeviceEventType::kWoBLEIndicateConfirm: + { + WeaveLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLEIndicateConfirm"); + HandleIndicationConfirmation(event->WoBLEIndicateConfirm.ConId, &WEAVE_BLE_SVC_ID, &WeaveUUID_WoBLEChar_TX); + } + break; + + default: + WeaveLogProgress(DeviceLayer, "_OnPlatformEvent default: event->Type = %d", event->Type); + break; + } +} + +bool BLEManagerImpl::SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, + const WeaveBleUUID * svcId, + const WeaveBleUUID * charId) +{ + WeaveLogProgress(DeviceLayer, "BLEManagerImpl::SubscribeCharacteristic() not supported"); + return false; +} + +bool BLEManagerImpl::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, + const WeaveBleUUID * svcId, + const WeaveBleUUID * charId) +{ + WeaveLogProgress(DeviceLayer, "BLEManagerImpl::UnsubscribeCharacteristic() not supported"); + return false; +} + +bool BLEManagerImpl::CloseConnection(BLE_CONNECTION_OBJECT conId) +{ + WEAVE_ERROR err = WEAVE_NO_ERROR; + gecko_msg_le_connection_close_rsp_t *rsp; + + WeaveLogProgress(DeviceLayer, "Closing BLE GATT connection (con %u)", conId); + + rsp = gecko_cmd_le_connection_close(conId); + err = MapBLEError(rsp->result); + + if (err != WEAVE_NO_ERROR) + { + WeaveLogError(DeviceLayer, "gecko_cmd_le_connection_close() failed: %s", ErrorStr(err)); + } + + return (err == WEAVE_NO_ERROR); +} + +uint16_t BLEManagerImpl::GetMTU(BLE_CONNECTION_OBJECT conId) const +{ + WoBLEConState *conState = const_cast(this)->GetConnectionState(conId); + return (conState != NULL) ? conState->mtu : 0; +} + +bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, + const WeaveBleUUID * svcId, + const WeaveBleUUID * charId, + PacketBuffer * data) +{ + WEAVE_ERROR err = WEAVE_NO_ERROR; + WoBLEConState * conState = GetConnectionState(conId); + gecko_msg_gatt_server_send_characteristic_notification_rsp_t *rsp; + uint16_t cId = (UUIDsMatch(&WeaveUUID_WoBLEChar_RX, charId) ? gattdb_WoBLEChar_Rx : gattdb_WoBLEChar_Tx); + uint8_t timerHandle = GetTimerHandle(conId, true); + + VerifyOrExit(((conState != NULL) && (conState->subscribed != 0)), err = WEAVE_ERROR_INVALID_ARGUMENT); + VerifyOrExit(timerHandle != kMaxConnections, err = WEAVE_ERROR_NO_MEMORY); + + // start timer for light indication confirmation + gecko_cmd_hardware_set_soft_timer(TIMER_S_2_TIMERTICK(1), timerHandle, true); + + rsp = gecko_cmd_gatt_server_send_characteristic_notification(conId, cId, data->DataLength(), data->Start()); + + err = MapBLEError(rsp->result); + +exit: + PacketBuffer::Free(data); + if (err != WEAVE_NO_ERROR) + { + WeaveLogError(DeviceLayer, "BLEManagerImpl::SendIndication() failed: %s", ErrorStr(err)); + return false; + } + return true; +} + +bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, + const WeaveBleUUID * svcId, + const WeaveBleUUID * charId, + PacketBuffer * pBuf) +{ + WeaveLogProgress(DeviceLayer, "BLEManagerImpl::SendWriteRequest() not supported"); + return false; +} + +bool BLEManagerImpl::SendReadRequest(BLE_CONNECTION_OBJECT conId, + const WeaveBleUUID * svcId, + const WeaveBleUUID * charId, + PacketBuffer * pBuf) +{ + WeaveLogProgress(DeviceLayer, "BLEManagerImpl::SendReadRequest() not supported"); + return false; +} + +bool BLEManagerImpl::SendReadResponse(BLE_CONNECTION_OBJECT conId, + BLE_READ_REQUEST_CONTEXT requestContext, + const WeaveBleUUID * svcId, + const WeaveBleUUID * charId) +{ + WeaveLogProgress(DeviceLayer, "BLEManagerImpl::SendReadResponse() not supported"); + return false; +} + +void BLEManagerImpl::NotifyWeaveConnectionClosed(BLE_CONNECTION_OBJECT conId) +{ + // Nothing to do +} + +WEAVE_ERROR BLEManagerImpl::MapBLEError(int bleErr) +{ + WEAVE_ERROR err; + + if (bleErr == bg_err_success) { + err = WEAVE_NO_ERROR; + } else { + err = (WEAVE_ERROR) bleErr + WEAVE_DEVICE_CONFIG_EFR32_BLE_ERROR_MIN; + } + + return err; +} + +void BLEManagerImpl::DriveBLEState(void) +{ + WEAVE_ERROR err = WEAVE_NO_ERROR; + + // Check if BLE stack is initialized + VerifyOrExit(GetFlag(mFlags, kFlag_EFRBLEStackInitialized), /* */); + + // Start advertising if needed... + if (mServiceMode == ConnectivityManager::kWoBLEServiceMode_Enabled && GetFlag(mFlags, kFlag_AdvertisingEnabled)) + { + // Start/re-start advertising if not already started, or if there is a pending change + // to the advertising configuration. + if (!GetFlag(mFlags, kFlag_Advertising) || GetFlag(mFlags, kFlag_RestartAdvertising)) + { + err = StartAdvertising(); + SuccessOrExit(err); + } + } + + // Otherwise, stop advertising if it is enabled. + else if (GetFlag(mFlags, kFlag_AdvertisingEnabled)) + { + err = StopAdvertising(); + SuccessOrExit(err); + } + +exit: + if (err != WEAVE_NO_ERROR) + { + WeaveLogError(DeviceLayer, "Disabling WoBLE service due to error: %s", ErrorStr(err)); + mServiceMode = ConnectivityManager::kWoBLEServiceMode_Disabled; + } +} + +WEAVE_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) +{ + struct gecko_msg_le_gap_bt5_set_adv_data_rsp_t *setAdvDataRsp; + WeaveBLEDeviceIdentificationInfo mDeviceIdInfo; + WEAVE_ERROR err; + uint8_t responseData[MAX_RESPONSE_DATA_LEN]; + uint8_t advData[MAX_ADV_DATA_LEN]; + uint8_t index = 0; + uint8_t mDeviceNameLength = 0; + uint8_t mDeviceIdInfoLength = 0; + + memset(responseData, 0, MAX_RESPONSE_DATA_LEN); + memset(advData, 0, MAX_ADV_DATA_LEN); + + err = ConfigurationMgr().GetBLEDeviceIdentificationInfo(mDeviceIdInfo); + SuccessOrExit(err); + + if (!GetFlag(mFlags, kFlag_DeviceNameSet)) + { + snprintf(mDeviceName, sizeof(mDeviceName), "%s%04" PRIX32, WEAVE_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, + (uint32_t)FabricState.LocalNodeId); + + mDeviceName[kMaxDeviceNameLength] = 0; + + gecko_cmd_gatt_server_write_attribute_value(gattdb_device_name, 0, strlen(mDeviceName), (uint8_t *)mDeviceName); + } + + mDeviceNameLength = strlen(mDeviceName); // Device Name length + length field + mDeviceIdInfoLength = sizeof(mDeviceIdInfo); // Servicedatalen + length+ UUID (Short) + + index = 0; + responseData[index++] = 0x02; // length + responseData[index++] = WEAVE_ADV_DATA_TYPE_FLAGS; // AD type : flags + responseData[index++] = WEAVE_ADV_DATA_FLAGS; // AD value + + responseData[index++] = mDeviceNameLength + 1; // length + responseData[index++] = WEAVE_ADV_DATA_TYPE_NAME; // AD type : name + memcpy(&responseData[index], mDeviceName, mDeviceNameLength); // AD value + index += mDeviceNameLength; + + responseData[index++] = WEAVE_ADV_SHORT_UUID_LEN + 1; // AD length + responseData[index++] = WEAVE_ADV_DATA_TYPE_UUID; // AD type : uuid + responseData[index++] = ShortUUID_WoBLEService[0]; // AD value + responseData[index++] = ShortUUID_WoBLEService[1]; + + setAdvDataRsp = gecko_cmd_le_gap_bt5_set_adv_data(WEAVE_ADV_WOBLE_SERVICE_HANDLE, WEAVE_ADV_SCAN_RESPONSE_DATA, + index, (uint8_t *)&responseData); + + if (setAdvDataRsp->result != 0) + { + err = MapBLEError(setAdvDataRsp->result); + WeaveLogError(DeviceLayer, "gecko_cmd_le_gap_bt5_set_adv_data() failed: %s", ErrorStr(err)); + ExitNow(); + } + + index = 0; + + advData[index++] = mDeviceIdInfoLength + WEAVE_ADV_SHORT_UUID_LEN + 1; // AD length + advData[index++] = WEAVE_ADV_DATA_TYPE_SERVICE_DATA; // AD type : Service Data + advData[index++] = ShortUUID_WoBLEService[0]; // AD value + advData[index++] = ShortUUID_WoBLEService[1]; + memcpy(&advData[index], (void *)&mDeviceIdInfo, mDeviceIdInfoLength); // AD value + index += mDeviceIdInfoLength; + + setAdvDataRsp = + gecko_cmd_le_gap_bt5_set_adv_data(WEAVE_ADV_WOBLE_SERVICE_HANDLE, WEAVE_ADV_DATA, index, (uint8_t *)&advData); + + err = MapBLEError(setAdvDataRsp->result); + +exit: + return err; +} + +WEAVE_ERROR BLEManagerImpl::StartAdvertising(void) +{ + WEAVE_ERROR err; + struct gecko_msg_le_gap_start_advertising_rsp_t *startAdvRsp; + uint32_t interval_min; + uint32_t interval_max; + uint16_t numConnectionss = NumConnections(); + uint8_t connectableAdv = + (numConnectionss < kMaxConnections) ? le_gap_connectable_scannable : le_gap_scannable_non_connectable; + + err = ConfigureAdvertisingData(); + SuccessOrExit(err); + + ClearFlag(mFlags, kFlag_RestartAdvertising); + + interval_min = interval_max = ((numConnectionss == 0 && !ConfigurationMgr().IsPairedToAccount()) || + GetFlag(mFlags, kFlag_FastAdvertisingEnabled)) + ? WEAVE_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL + : WEAVE_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL; + + gecko_cmd_le_gap_set_advertise_timing(WEAVE_ADV_WOBLE_SERVICE_HANDLE, interval_min, interval_max, 0, 0); + + startAdvRsp = gecko_cmd_le_gap_start_advertising(WEAVE_ADV_WOBLE_SERVICE_HANDLE, le_gap_user_data, connectableAdv); + + err = MapBLEError(startAdvRsp->result); + +exit: + return err; +} + +WEAVE_ERROR BLEManagerImpl::StopAdvertising(void) +{ + WEAVE_ERROR err = WEAVE_NO_ERROR; + gecko_msg_le_gap_stop_advertising_rsp_t *rsp; + + if (GetFlag(mFlags, kFlag_Advertising)) + { + ClearFlag(mFlags, kFlag_Advertising); + ClearFlag(mFlags, kFlag_RestartAdvertising); + + rsp = gecko_cmd_le_gap_stop_advertising(WEAVE_ADV_WOBLE_SERVICE_HANDLE); + err = MapBLEError(rsp->result); + SuccessOrExit(err); + } + +exit: + return err; +} + +void BLEManagerImpl::UpdateMtu(volatile struct gecko_cmd_packet *evt) +{ + WoBLEConState *bleConnState = GetConnectionState(evt->data.evt_gatt_mtu_exchanged.connection); + bleConnState->mtu = evt->data.evt_gatt_mtu_exchanged.mtu; + ; +} + +void BLEManagerImpl::HandleBootEvent(void) +{ + SetFlag(mFlags, kFlag_EFRBLEStackInitialized, true); + PlatformMgr().ScheduleWork(DriveBLEState, 0); +} + +void BLEManagerImpl::HandleConnectEvent(volatile struct gecko_cmd_packet *evt) +{ + struct gecko_msg_le_connection_opened_evt_t *conn_evt = (struct gecko_msg_le_connection_opened_evt_t *)&(evt->data); + uint8_t connHandle = conn_evt->connection; + uint8_t bondingHandle = conn_evt->bonding; + + WeaveLogProgress(DeviceLayer, "Connect Event for handle : %d", connHandle); + + AddConnection(connHandle, bondingHandle); + + SetFlag(mFlags, kFlag_RestartAdvertising, true); + PlatformMgr().ScheduleWork(DriveBLEState, 0); +} + +void BLEManagerImpl::HandleConnectionCloseEvent(volatile struct gecko_cmd_packet *evt) +{ + struct gecko_msg_le_connection_closed_evt_t *conn_evt = (struct gecko_msg_le_connection_closed_evt_t *)&(evt->data); + uint8_t connHandle = conn_evt->connection; + + WeaveLogProgress(DeviceLayer, "Disconnect Event for handle : %d", connHandle); + + if (RemoveConnection(connHandle)) + { + WeaveDeviceEvent event; + event.Type = DeviceEventType::kWoBLEConnectionError; + event.WoBLEConnectionError.ConId = connHandle; + + switch (conn_evt->reason) + { + case bg_err_bt_remote_user_terminated: + case bg_err_bt_remote_device_terminated_connection_due_to_low_resources: + case bg_err_bt_remote_powering_off: + event.WoBLEConnectionError.Reason = BLE_ERROR_REMOTE_DEVICE_DISCONNECTED; + break; + + case bg_err_bt_connection_terminated_by_local_host: + event.WoBLEConnectionError.Reason = BLE_ERROR_APP_CLOSED_CONNECTION; + break; + + default: + event.WoBLEConnectionError.Reason = BLE_ERROR_WOBLE_PROTOCOL_ABORT; + break; + } + + WeaveLogProgress(DeviceLayer, "BLE GATT connection closed (con %u, reason %u)", connHandle, conn_evt->reason); + + PlatformMgr().PostEvent(&event); + + // Arrange to re-enable connectable advertising in case it was disabled due to the + // maximum connection limit being reached. + ClearFlag(mFlags, kFlag_Advertising); + PlatformMgr().ScheduleWork(DriveBLEState, 0); + } +} + +void BLEManagerImpl::HandleWriteEvent(volatile struct gecko_cmd_packet *evt) +{ + struct gecko_msg_gatt_server_read_attribute_type_rsp_t *rsp; + uint16_t attribute = evt->data.evt_gatt_server_user_write_request.characteristic; + + WeaveLogProgress(DeviceLayer, "Char Write Req, char : %d", attribute); + + if (gattdb_WoBLEChar_Rx == attribute) + { + HandleRXCharWrite(evt); + } +} + +void BLEManagerImpl::HandleTXCharCCCDWrite(volatile struct gecko_cmd_packet *evt) +{ + WEAVE_ERROR err = WEAVE_NO_ERROR; + WoBLEConState * bleConnState; + bool indicationsEnabled; + WeaveDeviceEvent event; + + bleConnState = GetConnectionState(evt->data.evt_gatt_server_user_write_request.connection); + + VerifyOrExit(bleConnState != NULL, err = WEAVE_ERROR_NO_MEMORY); + + // Determine if the client is enabling or disabling indications. + indicationsEnabled = (evt->data.evt_gatt_server_characteristic_status.client_config_flags == gatt_indication); + + WeaveLogProgress(DeviceLayer, "WoBLE %s received", indicationsEnabled ? "subscribe" : "unsubscribe"); + + if (indicationsEnabled) + { + // If indications are not already enabled for the connection... + if (!bleConnState->subscribed) + { + bleConnState->subscribed = 1; + // Post an event to the Weave queue to process either a WoBLE Subscribe or Unsubscribe based on + // whether the client is enabling or disabling indications. + { + event.Type = DeviceEventType::kWoBLESubscribe; + event.WoBLESubscribe.ConId = evt->data.evt_gatt_server_user_write_request.connection; + PlatformMgr().PostEvent(&event); + } + } + } + else + { + bleConnState->subscribed = 0; + event.Type = DeviceEventType::kWoBLEUnsubscribe; + event.WoBLESubscribe.ConId = evt->data.evt_gatt_server_user_write_request.connection; + PlatformMgr().PostEvent(&event); + } + +exit: + if (err != WEAVE_NO_ERROR) + { + WeaveLogError(DeviceLayer, "HandleTXCharCCCDWrite() failed: %s", ErrorStr(err)); + } +} + +void BLEManagerImpl::HandleRXCharWrite(volatile struct gecko_cmd_packet *evt) +{ + WEAVE_ERROR err = WEAVE_NO_ERROR; + PacketBuffer *buf; + uint16_t writeLen = evt->data.evt_gatt_server_user_write_request.value.len; + uint8_t * data = (uint8_t *)evt->data.evt_gatt_server_user_write_request.value.data; + + // Copy the data to a PacketBuffer. + buf = PacketBuffer::New(0); + VerifyOrExit(buf != NULL, err = WEAVE_ERROR_NO_MEMORY); + VerifyOrExit(buf->AvailableDataLength() >= writeLen, err = WEAVE_ERROR_BUFFER_TOO_SMALL); + memcpy(buf->Start(), data, writeLen); + buf->SetDataLength(writeLen); + + WeaveLogDetail(DeviceLayer, + "Write request/command received for WoBLE RX characteristic (con %" PRIu16 ", len %" PRIu16 ")", + evt->data.evt_gatt_server_user_write_request.connection, buf->DataLength()); + + // Post an event to the Weave queue to deliver the data into the Weave stack. + { + WeaveDeviceEvent event; + event.Type = DeviceEventType::kWoBLEWriteReceived; + event.WoBLEWriteReceived.ConId = evt->data.evt_gatt_server_user_write_request.connection; + event.WoBLEWriteReceived.Data = buf; + PlatformMgr().PostEvent(&event); + buf = NULL; + } + +exit: + if (err != WEAVE_NO_ERROR) + { + WeaveLogError(DeviceLayer, "HandleRXCharWrite() failed: %s", ErrorStr(err)); + } + PacketBuffer::Free(buf); +} + +void BLEManagerImpl::HandleTxConfirmationEvent(volatile struct gecko_cmd_packet *evt) +{ + WeaveDeviceEvent event; + uint8_t timerHandle = sInstance.GetTimerHandle(evt->data.evt_gatt_server_characteristic_status.connection); + + WeaveLogProgress(DeviceLayer, "Tx Confirmation received"); + + // stop indication confirmation timer + + if (timerHandle < kMaxConnections) + { + WeaveLogProgress(DeviceLayer, " stop soft timer"); + gecko_cmd_hardware_set_soft_timer(0, timerHandle, false); + } + + event.Type = DeviceEventType::kWoBLEIndicateConfirm; + event.WoBLEIndicateConfirm.ConId = evt->data.evt_gatt_server_characteristic_status.connection; + PlatformMgr().PostEvent(&event); +} + +void BLEManagerImpl::HandleSoftTimerEvent(volatile struct gecko_cmd_packet *evt) +{ + // BLE Manager starts soft timers with timer handles less than kMaxConnections + // If we receive a callback for unknown timer handle ignore this. + if (evt->data.evt_hardware_soft_timer.handle < kMaxConnections) + { + WeaveLogProgress(DeviceLayer, "BLEManagerImpl::HandleSoftTimerEvent WOBLE_PROTOCOL_ABORT"); + WeaveDeviceEvent event; + event.Type = DeviceEventType::kWoBLEConnectionError; + event.WoBLEConnectionError.ConId = mIndConfId[evt->data.evt_hardware_soft_timer.handle]; + sInstance.mIndConfId[evt->data.evt_hardware_soft_timer.handle] = kUnusedIndex; + event.WoBLEConnectionError.Reason = BLE_ERROR_WOBLE_PROTOCOL_ABORT; + PlatformMgr().PostEvent(&event); + } +} + +bool BLEManagerImpl::RemoveConnection(uint8_t connectionHandle) +{ + WoBLEConState *bleConnState = GetConnectionState(connectionHandle, true); + bool status = false; + + if (bleConnState != NULL) + { + memset(bleConnState, 0, sizeof(WoBLEConState)); + status = true; + } + + return status; +} + +void BLEManagerImpl::AddConnection(uint8_t connectionHandle, uint8_t bondingHandle) +{ + WoBLEConState *bleConnState = GetConnectionState(connectionHandle, true); + + if (bleConnState != NULL) + { + memset(bleConnState, 0, sizeof(WoBLEConState)); + bleConnState->allocated = 1; + bleConnState->connectionHandle = connectionHandle; + bleConnState->bondingHandle = bondingHandle; + } +} + +BLEManagerImpl::WoBLEConState *BLEManagerImpl::GetConnectionState(uint8_t connectionHandle, bool allocate) +{ + uint8_t freeIndex = kMaxConnections; + + for (uint8_t i = 0; i < kMaxConnections; i++) + { + if (mBleConnections[i].allocated == 1) + { + if (mBleConnections[i].connectionHandle == connectionHandle) + { + return &mBleConnections[i]; + } + } + + else if (i < freeIndex) + { + freeIndex = i; + } + } + + if (allocate) + { + if (freeIndex < kMaxConnections) + { + return &mBleConnections[freeIndex]; + } + + WeaveLogError(DeviceLayer, "Failed to allocate WoBLEConState"); + } + + return NULL; +} + +uint8_t BLEManagerImpl::GetTimerHandle(uint8_t connectionHandle, bool allocate) +{ + uint8_t freeIndex = kMaxConnections; + + for (uint8_t i = 0; i < kMaxConnections; i++) + { + if (mIndConfId[i] == connectionHandle) + { + return i; + } + else if (allocate) + { + if (i < freeIndex) + { + freeIndex = i; + } + } + } + + if (freeIndex < kMaxConnections) + { + mIndConfId[freeIndex] = connectionHandle; + } + else + { + WeaveLogError(DeviceLayer, "Failed to Save Conn Handle for indication"); + } + + return freeIndex; +} + +void BLEManagerImpl::DriveBLEState(intptr_t arg) +{ + sInstance.DriveBLEState(); +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl +#endif // WEAVE_DEVICE_CONFIG_ENABLE_WOBLE diff --git a/src/platform/EFR32/ConfigurationManagerImpl.cpp b/src/platform/EFR32/ConfigurationManagerImpl.cpp new file mode 100644 index 00000000000000..4385d5dc0edb16 --- /dev/null +++ b/src/platform/EFR32/ConfigurationManagerImpl.cpp @@ -0,0 +1,171 @@ +/* + * + * Copyright (c) 2019 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 + * Provides the implementation of the Device Layer ConfigurationManager object + * for EFR32 platforms using the Silicon Labs SDK. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace nl { +namespace Weave { +namespace DeviceLayer { + +using namespace ::nl::Weave::Profiles::Security::AppKeys; +using namespace ::nl::Weave::Profiles::DeviceDescription; +using namespace ::nl::Weave::DeviceLayer::Internal; + +namespace { + +// Singleton instance of Weave Group Key Store. +GroupKeyStoreImpl gGroupKeyStore; + +} // unnamed namespace + +/** Singleton instance of the ConfigurationManager implementation object. + */ +ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; + +WEAVE_ERROR ConfigurationManagerImpl::_Init() +{ + WEAVE_ERROR err; + bool failSafeArmed; + + // Initialize the generic implementation base class. + err = Internal::GenericConfigurationManagerImpl::_Init(); + SuccessOrExit(err); + + // Initialize the global GroupKeyStore object. + err = gGroupKeyStore.Init(); + SuccessOrExit(err); + + // If the fail-safe was armed when the device last shutdown, initiate a factory reset. + if (_GetFailSafeArmed(failSafeArmed) == WEAVE_NO_ERROR && failSafeArmed) + { + WeaveLogProgress(DeviceLayer, "Detected fail-safe armed on reboot; initiating factory reset"); + _InitiateFactoryReset(); + } + err = WEAVE_NO_ERROR; + +exit: + return err; +} + +WEAVE_ERROR ConfigurationManagerImpl::_GetDeviceDescriptor( + ::nl::Weave::Profiles::DeviceDescription::WeaveDeviceDescriptor &deviceDesc) +{ + WEAVE_ERROR err; + + // Call the generic version of _GetDeviceDescriptor() supplied by the base class. + err = Internal::GenericConfigurationManagerImpl::_GetDeviceDescriptor(deviceDesc); + SuccessOrExit(err); + +exit: + return err; +} + +::nl::Weave::Profiles::Security::AppKeys::GroupKeyStoreBase *ConfigurationManagerImpl::_GetGroupKeyStore() +{ + return &gGroupKeyStore; +} + +bool ConfigurationManagerImpl::_CanFactoryReset() +{ + // TODO: query the application to determine if factory reset is allowed. + return true; +} + +void ConfigurationManagerImpl::_InitiateFactoryReset() +{ + PlatformMgr().ScheduleWork(DoFactoryReset); +} + +WEAVE_ERROR ConfigurationManagerImpl::_ReadPersistedStorageValue( + ::nl::Weave::Platform::PersistedStorage::Key persistedStorageKey, + uint32_t & value) +{ + // This method reads Weave Persisted Counter type nvm3 objects. + // (where persistedStorageKey represents an index to the counter). + WEAVE_ERROR err; + + err = ReadConfigValueCounter(persistedStorageKey, value); + if (err == WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND) + { + err = WEAVE_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; + } + SuccessOrExit(err); + +exit: + return err; +} + +WEAVE_ERROR ConfigurationManagerImpl::_WritePersistedStorageValue( + ::nl::Weave::Platform::PersistedStorage::Key persistedStorageKey, + uint32_t value) +{ + // This method reads Weave Persisted Counter type nvm3 objects. + // (where persistedStorageKey represents an index to the counter). + WEAVE_ERROR err; + + err = WriteConfigValueCounter(persistedStorageKey, value); + if (err == WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND) + { + err = WEAVE_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; + } + SuccessOrExit(err); + +exit: + return err; +} + +void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) +{ + WEAVE_ERROR err; + + WeaveLogProgress(DeviceLayer, "Performing factory reset"); + + err = FactoryResetConfig(); + if (err != WEAVE_NO_ERROR) + { + WeaveLogError(DeviceLayer, "FactoryResetConfig() failed: %s", nl::ErrorStr(err)); + } + +#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD + + WeaveLogProgress(DeviceLayer, "Clearing Thread provision"); + ThreadStackMgr().ClearThreadProvision(); + +#endif // WEAVE_DEVICE_CONFIG_ENABLE_THREAD + + // Restart the system. + WeaveLogProgress(DeviceLayer, "System restarting"); + NVIC_SystemReset(); +} + +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl diff --git a/src/platform/EFR32/ConnectivityManagerImpl.cpp b/src/platform/EFR32/ConnectivityManagerImpl.cpp new file mode 100644 index 00000000000000..8bf8813bc1e68f --- /dev/null +++ b/src/platform/EFR32/ConnectivityManagerImpl.cpp @@ -0,0 +1,87 @@ +/* + * + * Copyright (c) 2019 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#if WEAVE_DEVICE_CONFIG_ENABLE_WOBLE +#include +#endif + +#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD +#include +#endif + +using namespace ::nl; +using namespace ::nl::Weave; +using namespace ::nl::Weave::TLV; +using namespace ::nl::Weave::Profiles::Common; +using namespace ::nl::Weave::Profiles::NetworkProvisioning; +using namespace ::nl::Weave::DeviceLayer::Internal; + +using Profiles::kWeaveProfile_Common; +using Profiles::kWeaveProfile_NetworkProvisioning; + +namespace nl { +namespace Weave { +namespace DeviceLayer { + +ConnectivityManagerImpl ConnectivityManagerImpl::sInstance; + +WEAVE_ERROR ConnectivityManagerImpl::_Init() +{ + WEAVE_ERROR err = WEAVE_NO_ERROR; + + // Initialize the generic base classes that require it. +#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD + GenericConnectivityManagerImpl_Thread::_Init(); +#endif + + // Initialize the Weave Addressing and Routing Module. + err = Warm::Init(FabricState); + SuccessOrExit(err); + +exit: + return err; +} + +void ConnectivityManagerImpl::_OnPlatformEvent(const WeaveDeviceEvent *event) +{ + // Forward the event to the generic base classes as needed. +#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD + GenericConnectivityManagerImpl_Thread::_OnPlatformEvent(event); +#endif +} + +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl diff --git a/src/platform/EFR32/EFR32Config.cpp b/src/platform/EFR32/EFR32Config.cpp new file mode 100644 index 00000000000000..5b61bf73eba4fc --- /dev/null +++ b/src/platform/EFR32/EFR32Config.cpp @@ -0,0 +1,641 @@ +/* + * + * Copyright (c) 2019 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 + * Utilities for accessing persisted device configuration on + * platforms based on the Silicon Labs SDK. + */ + +#include +#include +#include +#include + +#include "nvm3.h" +#include "nvm3_hal_flash.h" +#include "FreeRTOS.h" + +namespace nl { +namespace Weave { +namespace DeviceLayer { +namespace Internal { + +// Two macros are provided to support the creation of the Silicon Labs NVM3 area and +// initialization data- NVM3_DEFINE_SECTION_STATIC_DATA() and NVM3_DEFINE_SECTION_INIT_DATA(). +// A linker section called 'name'_section is defined by NVM3_DEFINE_SECTION_STATIC_DATA(). +// The NVM3 area is placed at the top of the device FLASH section by the linker +// script file: openweave-efr32-bringup-MG12P.ld. An error is returned +// by nvm3_open() on alignment or size violation. + +// Local version of SDK macro (avoids uninitialized var compile error). +#define WEAVE_NVM3_DEFINE_SECTION_STATIC_DATA(name, nvmSize, cacheSize) \ + static nvm3_CacheEntry_t name##_cache[cacheSize]; \ + static uint8_t name##_nvm[nvmSize] SL_ATTRIBUTE_SECTION(STRINGIZE(name##_section)) + +// Local version of SDK macro (allows Weave to configure the maximum nvm3 object size and headroom). +#define WEAVE_NVM3_DEFINE_SECTION_INIT_DATA(name, maxObjectSize, repackHeadroom) \ + static nvm3_Init_t name = { \ + (nvm3_HalPtr_t)name##_nvm, \ + sizeof(name##_nvm), \ + name##_cache, \ + sizeof(name##_cache) / sizeof(nvm3_CacheEntry_t), \ + maxObjectSize, \ + repackHeadroom, \ + &nvm3_halFlashHandle, \ + } + +#define WEAVE_NVM3_REPACK_HEADROOM 64 // Threshold for User non-forced nvm3 flash repacking. + +static nvm3_Handle_t handle; + +// Declare NVM3 data area and cache. + +WEAVE_NVM3_DEFINE_SECTION_STATIC_DATA(weaveNvm3, + WEAVE_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE *FLASH_PAGE_SIZE, + WEAVE_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS); + +WEAVE_NVM3_DEFINE_SECTION_INIT_DATA(weaveNvm3, WEAVE_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE, WEAVE_NVM3_REPACK_HEADROOM); + +WEAVE_ERROR EFR32Config::Init() +{ + WEAVE_ERROR err; + bool needClose = false; + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + +exit: + if (needClose) + { + nvm3_close(&handle); + } + + return err; +} + +WEAVE_ERROR EFR32Config::ReadConfigValue(Key key, bool &val) +{ + WEAVE_ERROR err; + bool needClose = false; + uint32_t objectType; + size_t dataLen; + bool tmpVal; + + VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + + // Get nvm3 object info. + err = MapNvm3Error(nvm3_getObjectInfo(&handle, key, &objectType, &dataLen)); + SuccessOrExit(err); + + // Read nvm3 bytes into tmp. + err = MapNvm3Error(nvm3_readData(&handle, key, &tmpVal, dataLen)); + SuccessOrExit(err); + val = tmpVal; + +exit: + if (needClose) + { + nvm3_close(&handle); + } + return err; +} + +WEAVE_ERROR EFR32Config::ReadConfigValue(Key key, uint32_t &val) +{ + WEAVE_ERROR err; + bool needClose = false; + uint32_t objectType; + size_t dataLen; + uint32_t tmpVal; + + VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + + // Get nvm3 object info. + err = MapNvm3Error(nvm3_getObjectInfo(&handle, key, &objectType, &dataLen)); + SuccessOrExit(err); + + // Read nvm3 bytes into tmp. + err = MapNvm3Error(nvm3_readData(&handle, key, &tmpVal, dataLen)); + SuccessOrExit(err); + val = tmpVal; + +exit: + if (needClose) + { + nvm3_close(&handle); + } + return err; +} + +WEAVE_ERROR EFR32Config::ReadConfigValue(Key key, uint64_t &val) +{ + WEAVE_ERROR err; + bool needClose = false; + uint32_t objectType; + size_t dataLen; + uint64_t tmpVal; + + VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + + // Get nvm3 object info. + err = MapNvm3Error(nvm3_getObjectInfo(&handle, key, &objectType, &dataLen)); + SuccessOrExit(err); + + // Read nvm3 bytes into tmp. + err = MapNvm3Error(nvm3_readData(&handle, key, &tmpVal, dataLen)); + SuccessOrExit(err); + val = tmpVal; + +exit: + if (needClose) + { + nvm3_close(&handle); + } + return err; +} + +WEAVE_ERROR EFR32Config::ReadConfigValueStr(Key key, char *buf, size_t bufSize, size_t &outLen) +{ + WEAVE_ERROR err; + bool needClose = false; + uint32_t objectType; + size_t dataLen; + + outLen = 0; + + VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + + // Get nvm3 object info. + err = MapNvm3Error(nvm3_getObjectInfo(&handle, key, &objectType, &dataLen)); + SuccessOrExit(err); + VerifyOrExit(dataLen > 0, err = WEAVE_ERROR_INVALID_STRING_LENGTH); + + if (buf != NULL) + { + // Read nvm3 bytes directly into the output buffer- check buffer is + // long enough to take the string (nvm3 string does not include the + // terminator char). + VerifyOrExit((bufSize > dataLen), err = WEAVE_ERROR_BUFFER_TOO_SMALL); + + err = MapNvm3Error(nvm3_readData(&handle, key, buf, dataLen)); + SuccessOrExit(err); + + outLen = ((dataLen == 1) && (buf[0] == 0)) ? 0 : dataLen; + buf[outLen] = 0; // Add the terminator char. + } + else + { + if (dataLen > 1) + { + outLen = dataLen; + } + else + { + // Read the first byte of the nvm3 string into a tmp var. + char firstByte; + err = MapNvm3Error(nvm3_readData(&handle, key, &firstByte, 1)); + SuccessOrExit(err); + + outLen = (firstByte == 0) ? 0 : dataLen; + } + } + +exit: + if (needClose) + { + nvm3_close(&handle); + } + return err; +} + +WEAVE_ERROR EFR32Config::ReadConfigValueBin(Key key, uint8_t *buf, size_t bufSize, size_t &outLen) +{ + WEAVE_ERROR err; + bool needClose = false; + uint32_t objectType; + size_t dataLen; + + outLen = 0; + + VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + + // Get nvm3 object info. + err = MapNvm3Error(nvm3_getObjectInfo(&handle, key, &objectType, &dataLen)); + SuccessOrExit(err); + VerifyOrExit(dataLen > 0, err = WEAVE_ERROR_INVALID_STRING_LENGTH); + + if (buf != NULL) + { + // Read nvm3 bytes directly into output buffer- check buffer is long + // enough to take the data. + VerifyOrExit((bufSize >= dataLen), err = WEAVE_ERROR_BUFFER_TOO_SMALL); + + err = MapNvm3Error(nvm3_readData(&handle, key, buf, dataLen)); + SuccessOrExit(err); + } + + outLen = dataLen; + +exit: + if (needClose) + { + nvm3_close(&handle); + } + return err; +} + +WEAVE_ERROR EFR32Config::ReadConfigValueCounter(uint8_t counterIdx, uint32_t &val) +{ + WEAVE_ERROR err; + bool needClose = false; + uint32_t tmpVal; + + Key key = kMinConfigKey_WeaveCounter + counterIdx; + VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + + // Read bytes into tmp. + err = MapNvm3Error(nvm3_readCounter(&handle, key, &tmpVal)); + SuccessOrExit(err); + val = tmpVal; + +exit: + if (needClose) + { + nvm3_close(&handle); + } + return err; +} + +WEAVE_ERROR EFR32Config::WriteConfigValue(Key key, bool val) +{ + WEAVE_ERROR err; + bool needClose = false; + + VerifyOrExit(ValidConfigKey(key), err = WEAVE_ERROR_INVALID_ARGUMENT); // Verify key id. + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + + err = MapNvm3Error(nvm3_writeData(&handle, key, &val, sizeof(val))); + SuccessOrExit(err); + +exit: + if (needClose) + { + nvm3_close(&handle); + } + return err; +} + +WEAVE_ERROR EFR32Config::WriteConfigValue(Key key, uint32_t val) +{ + WEAVE_ERROR err; + bool needClose = false; + + VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + + err = MapNvm3Error(nvm3_writeData(&handle, key, &val, sizeof(val))); + SuccessOrExit(err); + +exit: + if (needClose) + { + nvm3_close(&handle); + } + return err; +} + +WEAVE_ERROR EFR32Config::WriteConfigValue(Key key, uint64_t val) +{ + WEAVE_ERROR err; + bool needClose = false; + + VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + + err = MapNvm3Error(nvm3_writeData(&handle, key, &val, sizeof(val))); + SuccessOrExit(err); + +exit: + if (needClose) + { + nvm3_close(&handle); + } + return err; +} + +WEAVE_ERROR EFR32Config::WriteConfigValueStr(Key key, const char *str) +{ + return WriteConfigValueStr(key, str, (str != NULL) ? strlen(str) : 0); +} + +WEAVE_ERROR EFR32Config::WriteConfigValueStr(Key key, const char *str, size_t strLen) +{ + WEAVE_ERROR err; + bool needClose = false; + + VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + + if (str != NULL) + { + // Write the string to nvm3 without the terminator char (apart from + // empty strings where only the terminator char is stored in nvm3). + err = MapNvm3Error(nvm3_writeData(&handle, key, str, (strLen > 0) ? strLen : 1)); + SuccessOrExit(err); + } + else + { + nvm3_deleteObject(&handle, key); // no error checking here. + } + +exit: + if (needClose) + { + nvm3_close(&handle); + } + + return err; +} + +WEAVE_ERROR EFR32Config::WriteConfigValueBin(Key key, const uint8_t *data, size_t dataLen) +{ + WEAVE_ERROR err; + bool needClose = false; + + VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + + if (data != NULL) + { + if (dataLen > 0) + { + // Write the binary data to nvm3. + err = MapNvm3Error(nvm3_writeData(&handle, key, data, dataLen)); + SuccessOrExit(err); + } + } + else + { + nvm3_deleteObject(&handle, key); // no error checking here. + } + +exit: + if (needClose) + { + nvm3_close(&handle); + } + return err; +} + +WEAVE_ERROR EFR32Config::WriteConfigValueCounter(uint8_t counterIdx, uint32_t val) +{ + WEAVE_ERROR err; + bool needClose = false; + + Key key = kMinConfigKey_WeaveCounter + counterIdx; + VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + + err = MapNvm3Error(nvm3_writeCounter(&handle, key, val)); + SuccessOrExit(err); + +exit: + if (needClose) + { + nvm3_close(&handle); + } + return err; +} + +WEAVE_ERROR EFR32Config::ClearConfigValue(Key key) +{ + WEAVE_ERROR err; + bool needClose = false; + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + + // Delete the nvm3 object with the given key id. + err = MapNvm3Error(nvm3_deleteObject(&handle, key)); + SuccessOrExit(err); + +exit: + if (needClose) + { + nvm3_close(&handle); + } + return err; +} + +bool EFR32Config::ConfigValueExists(Key key) +{ + WEAVE_ERROR err; + bool needClose = false; + uint32_t objectType; + size_t dataLen; + + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + needClose = true; + + // Find object with key id. + err = MapNvm3Error(nvm3_getObjectInfo(&handle, key, &objectType, &dataLen)); + +exit: + if (needClose) + { + nvm3_close(&handle); + } + return (err == WEAVE_NO_ERROR); +} + +WEAVE_ERROR EFR32Config::FactoryResetConfig(void) +{ + // Deletes all nvm3 'Config' type objects. + // Note- 'Factory' and 'Counter' type nvm3 objects are NOT deleted. + + WEAVE_ERROR err; + + // Iterate over all the Weave Config nvm3 records and delete each one... + err = ForEachRecord(kMinConfigKey_WeaveConfig, kMaxConfigKey_WeaveConfig, false, + [](const Key &nvm3Key, const size_t &length) -> WEAVE_ERROR { + WEAVE_ERROR err2; + + err2 = ClearConfigValue(nvm3Key); + SuccessOrExit(err2); + + exit: + return err2; + }); + + // Return success at end of iterations. + if (err == WEAVE_END_OF_INPUT) + { + err = WEAVE_NO_ERROR; + } + + return err; +} + +WEAVE_ERROR EFR32Config::MapNvm3Error(Ecode_t nvm3Res) +{ + WEAVE_ERROR err; + + switch (nvm3Res) + { + case ECODE_NVM3_OK: + err = WEAVE_NO_ERROR; + break; + case ECODE_NVM3_ERR_KEY_NOT_FOUND: + err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND; + break; + default: + err = (nvm3Res & 0xFF) + WEAVE_DEVICE_CONFIG_EFR32_NVM3_ERROR_MIN; + break; + } + + return err; +} + +WEAVE_ERROR EFR32Config::ForEachRecord(Key firstNvm3Key, Key lastNvm3Key, bool addNewRecord, ForEachRecordFunct funct) +{ + // Iterates through the specified range of nvm3 object key ids. + // Invokes the callers CB function when appropriate. + + WEAVE_ERROR err = WEAVE_NO_ERROR; + + for (Key nvm3Key = firstNvm3Key; nvm3Key <= lastNvm3Key; ++nvm3Key) + { + Ecode_t nvm3Res; + uint32_t objectType; + size_t dataLen; + + // Open nvm3 handle for reading on each iteration. + err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + SuccessOrExit(err); + + // Find nvm3 object with current nvm3 iteration key. + nvm3Res = nvm3_getObjectInfo(&handle, nvm3Key, &objectType, &dataLen); + switch (nvm3Res) + { + case ECODE_NVM3_OK: + if (!addNewRecord) + { + // Invoke the caller's function + // (for retrieve,store,delete,enumerate GroupKey operations). + err = funct(nvm3Key, dataLen); + } + break; + case ECODE_NVM3_ERR_KEY_NOT_FOUND: + if (addNewRecord) + { + // Invoke caller's function + // (for add GroupKey operation). + err = funct(nvm3Key, dataLen); + } + break; + default: + err = MapNvm3Error(nvm3Res); + break; + } + + SuccessOrExit(err); + } + +exit: + // Always close handle. + nvm3_close(&handle); + + return err; +} + +bool EFR32Config::ValidConfigKey(Key key) +{ + // Returns true if the key is in the valid Weave Config nvm3 key range. + + if ((key >= kMinConfigKey_WeaveFactory) && (key <= kMaxConfigKey_WeaveCounter)) + { + return true; + } + + return false; +} + +void EFR32Config::RunConfigUnitTest() +{ + // Run common unit test. + ::nl::Weave::DeviceLayer::Internal::RunConfigUnitTest(); +} + +void EFR32Config::RepackNvm3Flash(void) +{ + // Repack nvm3 flash if nvm3 space < headroom threshold. + // Note- checking periodically during idle periods should prevent + // forced repack events on any write operation. + nvm3_repack(&handle); +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl diff --git a/src/platform/EFR32/Entropy.cpp b/src/platform/EFR32/Entropy.cpp new file mode 100644 index 00000000000000..7c3ef4a58a1b8a --- /dev/null +++ b/src/platform/EFR32/Entropy.cpp @@ -0,0 +1,133 @@ +/* + * + * Copyright (c) 2019 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 + * Provides implementations for the Weave entropy sourcing functions + * on the Silcon Labs EFR32 platforms. + */ + +#include +#include +#include +#include +#include + +#if defined(_SILICON_LABS_32B_SERIES_1) +#include +#elif defined(_SILICON_LABS_32B_SERIES_2) +extern "C" int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t *olen); +#else // !defined(_SILICON_LABS_32B_SERIES_1) && !defined(_SILICON_LABS_32B_SERIES_2) +#error "Unsupported EFR32 series" +#endif + +using namespace ::nl; +using namespace ::nl::Weave; + +#if !WEAVE_CONFIG_RNG_IMPLEMENTATION_NESTDRBG +#error "Nest DRBG implementation must be enabled on EFR32 platforms" +#endif // !WEAVE_CONFIG_RNG_IMPLEMENTATION_NESTDRBG + +namespace nl { +namespace Weave { +namespace DeviceLayer { +namespace Internal { + +/** + * Retrieve entropy from the underlying RNG source. + * + * This function is called by the Nest DRBG to acquire entropy. + */ +int GetEntropy_EFR32(uint8_t *buf, size_t count) +{ + int res = 0; + + VerifyOrDie(count <= UINT16_MAX); + +#if defined(_SILICON_LABS_32B_SERIES_1) +#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD + if (ThreadStackManagerImpl::IsInitialized()) + { + ThreadStackMgr().LockThreadStack(); + } +#endif // WEAVE_DEVICE_CONFIG_ENABLE_THREAD + + +#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD + if (ThreadStackManagerImpl::IsInitialized()) + { + ThreadStackMgr().LockThreadStack(); + } +#endif // WEAVE_DEVICE_CONFIG_ENABLE_THREAD + + otError otErr = otPlatEntropyGet(buf, (uint16_t)count); + if (otErr != OT_ERROR_NONE) + { + res = WEAVE_ERROR_DRBG_ENTROPY_SOURCE_FAILED; + } + +#elif defined(_SILICON_LABS_32B_SERIES_2) + size_t entropy_len = 0; + size_t olen = 0; + + while (entropy_len < count) + { + res = mbedtls_hardware_poll(NULL, buf + entropy_len, count - entropy_len, &olen); + if (res != 0) + { + res = WEAVE_ERROR_DRBG_ENTROPY_SOURCE_FAILED; + break; + } + + entropy_len += olen; + } +#else // !defined(_SILICON_LABS_32B_SERIES_1) && !defined(_SILICON_LABS_32B_SERIES_2) +#error "Unsupported EFR32 series" +#endif + + return res; +} + +WEAVE_ERROR InitEntropy() +{ + WEAVE_ERROR err; + + // Initialize the Nest DRBG. + err = Platform::Security::InitSecureRandomDataSource(GetEntropy_EFR32, 64, NULL, 0); + SuccessOrExit(err); + + // Seed the standard rand() pseudo-random generator with data from the secure random source. + { + unsigned int seed; + err = Platform::Security::GetSecureRandomData((uint8_t *)&seed, sizeof(seed)); + SuccessOrExit(err); + srand(seed); + } + +exit: + if (err != WEAVE_NO_ERROR) + { + WeaveLogError(Crypto, "InitEntropy() failed: 0x%08" PRIX32, err); + } + return err; +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl diff --git a/src/platform/EFR32/GroupKeyStoreImpl.cpp b/src/platform/EFR32/GroupKeyStoreImpl.cpp new file mode 100644 index 00000000000000..af7d9d33c3b244 --- /dev/null +++ b/src/platform/EFR32/GroupKeyStoreImpl.cpp @@ -0,0 +1,396 @@ +/* + * + * Copyright (c) 2019 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 + * Provides an implementation of the Weave GroupKeyStore interface + * for platforms based on the Silicon Labs SDK. + */ + +#include +#include + +using namespace ::nl; +using namespace ::nl::Weave; +using namespace ::nl::Weave::Profiles::Security::AppKeys; + +namespace nl { +namespace Weave { +namespace DeviceLayer { +namespace Internal { + +WEAVE_ERROR GroupKeyStoreImpl::RetrieveGroupKey(uint32_t keyId, WeaveGroupKey &key) +{ + WEAVE_ERROR err; + + // Iterate over all the GroupKey nvm3 records looking for a matching key... + err = ForEachRecord(kConfigKey_GroupKeyBase, kConfigKey_GroupKeyMax, false, + [keyId, &key](const Key &nvm3Key, const size_t &length) -> WEAVE_ERROR { + WEAVE_ERROR err2; + size_t keyLen; + uint8_t buf[kMaxEncodedKeySize]; // (buf length == 45 bytes) + uint32_t curKeyId; + + // Read the nvm3 obj binary data data into the buffer. + err2 = ReadConfigValueBin(nvm3Key, buf, sizeof(buf), keyLen); + + // Decode the Weave key id for the current key. + err2 = DecodeGroupKeyId(buf, keyLen, curKeyId); + SuccessOrExit(err2); + + // If it matches the key we're looking for... + if (curKeyId == keyId) + { + // Decode the associated key data. + err2 = DecodeGroupKey(buf, keyLen, key); + SuccessOrExit(err2); + + // End the iteration by returning a WEAVE_END_OF_INPUT result. + ExitNow(err2 = WEAVE_END_OF_INPUT); + } + + exit: + return err2; + }); + + // Modify error code for return. + switch (err) + { + case WEAVE_END_OF_INPUT: + err = WEAVE_NO_ERROR; // Match found. + break; + case WEAVE_NO_ERROR: + err = WEAVE_ERROR_KEY_NOT_FOUND; // Match not found. + break; + default: + break; + } + + return err; +} + +WEAVE_ERROR GroupKeyStoreImpl::StoreGroupKey(const WeaveGroupKey &key) +{ + WEAVE_ERROR err; + + // Delete any existing group key with the same id (this may or may not exit). + DeleteGroupKey(key.KeyId); // no error checking here. + + // Iterate over all the GroupKey nvm3 records looking for the first + // empty nvm3 key where we can store the data. (Note- use arg addNewrecord=true) + err = ForEachRecord(kConfigKey_GroupKeyBase, kConfigKey_GroupKeyMax, true, + [&key](const Key &nvm3Key, const size_t &length) -> WEAVE_ERROR { + WEAVE_ERROR err2; + size_t keyLen; + uint8_t buf[kMaxEncodedKeySize]; // (buf length == 45 bytes) + + // Encode the key for storage in an nvm3 record. + err2 = EncodeGroupKey(key, buf, sizeof(buf), keyLen); + SuccessOrExit(err2); + + // Write the encoded binary data into the nvm3 object. + err2 = WriteConfigValueBin(nvm3Key, buf, keyLen); + SuccessOrExit(err2); + + // End the iteration by returning a WEAVE_END_OF_INPUT result. + ExitNow(err2 = WEAVE_END_OF_INPUT); + + exit: + return err2; + }); + + // Modify error code for return. + switch (err) + { + case WEAVE_END_OF_INPUT: + err = WEAVE_NO_ERROR; // Key entry was stored. + break; + case WEAVE_NO_ERROR: + err = WEAVE_ERROR_KEY_NOT_FOUND; // Key entry was not stored. + break; + default: + break; + } + + if (err == WEAVE_NO_ERROR) + { +#if WEAVE_PROGRESS_LOGGING + { + char extraKeyInfo[32]; + if (WeaveKeyId::IsAppEpochKey(key.KeyId)) + { + snprintf(extraKeyInfo, sizeof(extraKeyInfo), ", start time %" PRId32, key.StartTime); + } + else if (WeaveKeyId::IsAppGroupMasterKey(key.KeyId)) + { + snprintf(extraKeyInfo, sizeof(extraKeyInfo), ", global id 0x%08" PRIX32, key.GlobalId); + } + else + { + extraKeyInfo[0] = 0; + } + +#if WEAVE_CONFIG_SECURITY_TEST_MODE + WeaveLogProgress(SecurityManager, + "GroupKeyStore: storing key 0x%08" PRIX32 " (%s), len %" PRId8 ", data 0x%02" PRIX8 + "...%s", + key.KeyId, WeaveKeyId::DescribeKey(key.KeyId), key.KeyLen, key.Key[0], extraKeyInfo); +#else + WeaveLogProgress(SecurityManager, "GroupKeyStore: storing key 0x%08" PRIX32 " (%s), len %" PRId8 "%s", + key.KeyId, WeaveKeyId::DescribeKey(key.KeyId), key.KeyLen, extraKeyInfo); +#endif + } + +#endif // WEAVE_PROGRESS_LOGGING + } + + return err; +} + +WEAVE_ERROR GroupKeyStoreImpl::DeleteGroupKey(uint32_t keyId) +{ + WEAVE_ERROR err; + + // Iterate over all the GroupKey nvm3 records looking for a matching key... + err = ForEachRecord(kConfigKey_GroupKeyBase, kConfigKey_GroupKeyMax, false, + [keyId](const Key &nvm3Key, const size_t &length) -> WEAVE_ERROR { + WEAVE_ERROR err2; + size_t keyLen; + uint8_t buf[kMaxEncodedKeySize]; // (buf length == 45 bytes) + uint32_t curKeyId; + + // Read the nvm3 obj binary data data into the buffer. + err2 = ReadConfigValueBin(nvm3Key, buf, sizeof(buf), keyLen); + SuccessOrExit(err2); + + // Decode the Weave key id for the current group key. + err2 = DecodeGroupKeyId(buf, keyLen, curKeyId); + SuccessOrExit(err2); + + // If it matches the key we are looking for, delete the nvm3 record. + if (curKeyId == keyId) + { + err2 = ClearConfigValue(nvm3Key); + WeaveLogProgress(DeviceLayer, "GroupKeyStore: deleting key 0x%08" PRIX32, curKeyId); + + // End the iteration by returning a WEAVE_END_OF_INPUT result. + ExitNow(err2 = WEAVE_END_OF_INPUT); + } + + exit: + return err2; + }); + + // Modify error code for return. + switch (err) + { + case WEAVE_END_OF_INPUT: + err = WEAVE_NO_ERROR; // Key entry was deleted. + break; + case WEAVE_NO_ERROR: + err = WEAVE_ERROR_KEY_NOT_FOUND; // Key entry was not deleted. + break; + default: + break; + } + + return err; +} + +WEAVE_ERROR GroupKeyStoreImpl::DeleteGroupKeysOfAType(uint32_t keyType) +{ + WEAVE_ERROR err; + + // Iterate over all the GroupKey nvm3 records looking for a matching key... + err = ForEachRecord(kConfigKey_GroupKeyBase, kConfigKey_GroupKeyMax, false, + [keyType](const Key &nvm3Key, const size_t &length) -> WEAVE_ERROR { + WEAVE_ERROR err2; + size_t keyLen; + uint8_t buf[kMaxEncodedKeySize]; // (buf length == 45 bytes) + uint32_t curKeyId; + + // Read the nvm3 obj binary data data into the buffer. + err2 = ReadConfigValueBin(nvm3Key, buf, sizeof(buf), keyLen); + SuccessOrExit(err2); + + // Decode the Weave key id for the current group key. + err2 = DecodeGroupKeyId(buf, keyLen, curKeyId); + SuccessOrExit(err2); + + // If the current key matches the type we are looking for, delete the nvm3 record. + if (WeaveKeyId::GetType(curKeyId) == keyType) + { + err2 = ClearConfigValue(nvm3Key); + WeaveLogProgress(DeviceLayer, "GroupKeyStore: deleting key 0x%08" PRIX32, curKeyId); + } + + exit: + return err2; + }); + + return err; +} + +WEAVE_ERROR GroupKeyStoreImpl::EnumerateGroupKeys(uint32_t keyType, + uint32_t *keyIds, + uint8_t keyIdsArraySize, + uint8_t & keyCount) +{ + WEAVE_ERROR err; + + keyCount = 0; + + // Iterate over all the GroupKey records looking for keys of the specified type... + err = ForEachRecord( + kConfigKey_GroupKeyBase, kConfigKey_GroupKeyMax, false, + [keyType, keyIds, keyIdsArraySize, &keyCount](const Key &nvm3Key, const size_t &length) -> WEAVE_ERROR { + WEAVE_ERROR err2; + size_t keyLen; + uint8_t buf[kMaxEncodedKeySize]; // (buf length == 45 bytes) + uint32_t curKeyId; + + // Read the nvm3 obj binary data data into the buffer. + err2 = ReadConfigValueBin(nvm3Key, buf, sizeof(buf), keyLen); + SuccessOrExit(err2); + + // Decode the Weave key id for the current group key. + err2 = DecodeGroupKeyId(buf, keyLen, curKeyId); + SuccessOrExit(err2); + + // If the current key matches the type we're looking for, add it to the keyIds array. + if ((keyType == WeaveKeyId::kType_None) || (WeaveKeyId::GetType(curKeyId) == keyType)) + { + keyIds[keyCount++] = curKeyId; + + // Stop iterating if there's no more room in the keyIds array. + VerifyOrExit(keyCount < keyIdsArraySize, err2 = WEAVE_ERROR_BUFFER_TOO_SMALL); + } + + exit: + return err2; + }); + + // Simply return a truncated list if there are more matching keys than will fit in the array. + if (err == WEAVE_ERROR_BUFFER_TOO_SMALL) + { + err = WEAVE_NO_ERROR; + } + + return err; +} + +WEAVE_ERROR GroupKeyStoreImpl::Clear(void) +{ + WEAVE_ERROR err; + + // Iterate over all the GroupKey nvm3 records deleting each one... + err = ForEachRecord(kConfigKey_GroupKeyBase, kConfigKey_GroupKeyMax, false, + [](const Key &nvm3Key, const size_t &length) -> WEAVE_ERROR { + WEAVE_ERROR err2; + + err2 = ClearConfigValue(nvm3Key); + SuccessOrExit(err2); + + exit: + return err2; + }); + + return err; +} + +WEAVE_ERROR GroupKeyStoreImpl::RetrieveLastUsedEpochKeyId(void) +{ + WEAVE_ERROR err; + + err = ReadConfigValue(kConfigKey_LastUsedEpochKeyId, LastUsedEpochKeyId); + if (err == WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND) + { + LastUsedEpochKeyId = WeaveKeyId::kNone; + err = WEAVE_NO_ERROR; + } + return err; +} + +WEAVE_ERROR GroupKeyStoreImpl::StoreLastUsedEpochKeyId(void) +{ + return WriteConfigValue(kConfigKey_LastUsedEpochKeyId, LastUsedEpochKeyId); +} + +WEAVE_ERROR GroupKeyStoreImpl::Init() +{ + // Nothing to do + return WEAVE_NO_ERROR; +} + +WEAVE_ERROR GroupKeyStoreImpl::EncodeGroupKey(const WeaveGroupKey &key, + uint8_t * buf, + size_t bufSize, + size_t & encodedKeyLen) +{ + WEAVE_ERROR err = WEAVE_NO_ERROR; + uint8_t * p = buf; + + VerifyOrExit(bufSize >= kFixedEncodedKeySize + key.KeyLen, err = WEAVE_ERROR_BUFFER_TOO_SMALL); + + Encoding::LittleEndian::Write32(p, key.KeyId); + Encoding::LittleEndian::Write32(p, key.StartTime); + Encoding::Write8(p, key.KeyLen); + memcpy(p, key.Key, key.KeyLen); + p += key.KeyLen; + + encodedKeyLen = p - buf; + +exit: + return err; +} + +WEAVE_ERROR GroupKeyStoreImpl::DecodeGroupKeyId(const uint8_t *encodedKey, size_t encodedKeyLen, uint32_t &keyId) +{ + WEAVE_ERROR err = WEAVE_NO_ERROR; + + VerifyOrExit(encodedKeyLen >= kFixedEncodedKeySize, err = WEAVE_ERROR_INVALID_ARGUMENT); + + keyId = Encoding::LittleEndian::Get32(encodedKey); + +exit: + return err; +} + +WEAVE_ERROR GroupKeyStoreImpl::DecodeGroupKey(const uint8_t *encodedKey, size_t encodedKeyLen, WeaveGroupKey &key) +{ + WEAVE_ERROR err = WEAVE_NO_ERROR; + const uint8_t *p = encodedKey; + + VerifyOrExit(encodedKeyLen >= kFixedEncodedKeySize, err = WEAVE_ERROR_INVALID_ARGUMENT); + + key.KeyId = Encoding::LittleEndian::Read32(p); + key.StartTime = Encoding::LittleEndian::Read32(p); + key.KeyLen = Encoding::Read8(p); + + VerifyOrExit(encodedKeyLen >= kFixedEncodedKeySize + key.KeyLen, err = WEAVE_ERROR_INVALID_ARGUMENT); + + memcpy(key.Key, p, key.KeyLen); + +exit: + return err; +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl diff --git a/src/platform/EFR32/Logging.cpp b/src/platform/EFR32/Logging.cpp new file mode 100644 index 00000000000000..ba68860b491dd9 --- /dev/null +++ b/src/platform/EFR32/Logging.cpp @@ -0,0 +1,387 @@ +/* + * + * Copyright (c) 2019 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 + * Provides implementations for the OpenWeave and LwIP logging + * functions on Silicon Labs EFR32 platforms. + * + * Logging should be initialized by a call to efr32LogInit(). A + * spooler task is created that sends the logs to the UART. Log + * entries are queued. If the queue is full then by default error + * logs wait indefinitely until a slot is available whereas + * non-error logs are dropped to avoid delays. + */ + +#include +#include +#include +#include +#include +#include + +// FreeRTOS includes +#include "SEGGER_RTT.h" +#include "SEGGER_RTT_Conf.h" + +// RTT Buffer size and name +#ifndef LOG_RTT_BUFFER_INDEX +#define LOG_RTT_BUFFER_INDEX 0 +#endif + +#ifndef LOG_RTT_BUFFER_NAME +#define LOG_RTT_BUFFER_NAME "Terminal" +#endif + +#ifndef LOG_RTT_BUFFER_SIZE +#define LOG_RTT_BUFFER_SIZE 256 +#endif + +#define LOG_ERROR " " +#define LOG_WARN " " +#define LOG_INFO " " +#define LOG_DETAIL " " +#define LOG_LWIP " " +#define LOG_EFR32 " " + + +#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD +#include +#endif // WEAVE_DEVICE_CONFIG_ENABLE_THREAD + +using namespace ::nl::Weave; +using namespace ::nl::Weave::DeviceLayer; +using namespace ::nl::Weave::DeviceLayer::Internal; + +static bool sLogInitialized = false; +static uint8_t sLogBuffer[LOG_RTT_BUFFER_SIZE]; + +/** + * Print a log message to RTT + */ +static void PrintLog(const char *msg) +{ +#if EFR32_LOG_ENABLED + if (sLogInitialized) + { + size_t sz; + sz = strlen(msg); + SEGGER_RTT_WriteNoLock(0, msg, sz); + + const char *newline = "\r\n"; + sz = strlen(newline); + SEGGER_RTT_WriteNoLock(0, newline, sz); + } +#endif // EFR32_LOG_ENABLED +} + +/** + * Initialize Segger RTT for logging + */ +extern "C" int efr32LogInit(void) +{ +#if EFR32_LOG_ENABLED + SEGGER_RTT_ConfigUpBuffer(LOG_RTT_BUFFER_INDEX, LOG_RTT_BUFFER_NAME, sLogBuffer, LOG_RTT_BUFFER_SIZE, + SEGGER_RTT_MODE_NO_BLOCK_TRIM); + sLogInitialized = true; +#endif // EFR32_LOG_ENABLED + + return 0; +} + +/** + * General-purpose logging function + */ +extern "C" void efr32Log(const char *aFormat, ...) +{ + va_list v; + + va_start(v, aFormat); +#if EFR32_LOG_ENABLED + char formattedMsg[WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE]; + + strcpy(formattedMsg, LOG_EFR32); + size_t prefixLen = strlen(formattedMsg); + size_t len = vsnprintf(formattedMsg + prefixLen, sizeof formattedMsg - prefixLen, aFormat, v); + + if (len >= sizeof formattedMsg - prefixLen) + { + formattedMsg[sizeof formattedMsg - 1] = '\0'; + } + + PrintLog(formattedMsg); +#endif // EFR32_LOG_ENABLED + + va_end(v); +} + +namespace { + +void GetModuleName(char *buf, uint8_t module) +{ + if (module == ::nl::Weave::Logging::kLogModule_DeviceLayer) + { + memcpy(buf, "DL", 3); + } + else + { + ::nl::Weave::Logging::GetModuleName(buf, module); + } +} + +} // unnamed namespace + +namespace nl { +namespace Weave { +namespace DeviceLayer { + +/** + * Called whenever a log message is emitted by Weave or LwIP. + * + * This function is intended be overridden by the application to, e.g., + * schedule output of queued log entries. + */ +void __attribute__((weak)) OnLogOutput(void) +{ +} + +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl + +namespace nl { +namespace Weave { +namespace Logging { + +/** + * OpenWeave log output function. + */ +void Log(uint8_t module, uint8_t category, const char *aFormat, ...) +{ + va_list v; + + va_start(v, aFormat); +#if EFR32_LOG_ENABLED && _WEAVE_USE_LOGGING + if (IsCategoryEnabled(category)) + { + char formattedMsg[WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE]; + size_t formattedMsgLen; + + constexpr size_t maxPrefixLen = nlWeaveLoggingModuleNameLen + 3; + static_assert(sizeof(formattedMsg) > maxPrefixLen); + + switch (category) + { + case kLogCategory_Error: + strcpy(formattedMsg, LOG_ERROR); + break; + case kLogCategory_Progress: + case kLogCategory_Retain: + default: + strcpy(formattedMsg, LOG_INFO); + break; + case kLogCategory_Detail: + strcpy(formattedMsg, LOG_DETAIL); + break; + } + + formattedMsgLen = strlen(formattedMsg); + + // Form the log prefix, e.g. "[DL] " + formattedMsg[formattedMsgLen++] = '['; + ::GetModuleName(formattedMsg + formattedMsgLen, module); + formattedMsgLen = strlen(formattedMsg); + formattedMsg[formattedMsgLen++] = ']'; + formattedMsg[formattedMsgLen++] = ' '; + + size_t len = vsnprintf(formattedMsg + formattedMsgLen, sizeof formattedMsg - formattedMsgLen, aFormat, v); + + if (len >= sizeof formattedMsg - formattedMsgLen) + { + formattedMsg[sizeof formattedMsg - 1] = '\0'; + } + + PrintLog(formattedMsg); + } + + // Let the application know that a log message has been emitted. + DeviceLayer::OnLogOutput(); +#endif // EFR32_LOG_ENABLED && _WEAVE_USE_LOGGING + va_end(v); +} + +} // namespace Logging +} // namespace Weave +} // namespace nl + +/** + * LwIP log output function. + */ +extern "C" void LwIPLog(const char *aFormat, ...) +{ + va_list v; + + va_start(v, aFormat); +#if EFR32_LOG_ENABLED + char formattedMsg[WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE]; + + strcpy(formattedMsg, LOG_LWIP); + size_t prefixLen = strlen(formattedMsg); + size_t len = vsnprintf(formattedMsg + prefixLen, sizeof formattedMsg - prefixLen, aFormat, v); + + if (len >= sizeof formattedMsg - prefixLen) + { + formattedMsg[sizeof formattedMsg - 1] = '\0'; + } + + PrintLog(formattedMsg); + // Let the application know that a log message has been emitted. + DeviceLayer::OnLogOutput(); +#endif // EFR32_LOG_ENABLED + va_end(v); +} + +/** + * Platform logging function for OpenThread + */ +#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD +extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) +{ + IgnoreUnusedVariable(aLogRegion); + va_list v; + + va_start(v, aFormat); +#if EFR32_LOG_ENABLED + char formattedMsg[WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE]; + + if (sLogInitialized) + { + switch (aLogLevel) + { + case OT_LOG_LEVEL_CRIT: + strcpy(formattedMsg, LOG_ERROR "[ot] "); + break; + case OT_LOG_LEVEL_WARN: + strcpy(formattedMsg, LOG_WARN "[ot] "); + break; + case OT_LOG_LEVEL_NOTE: + strcpy(formattedMsg, LOG_INFO "[ot] "); + break; + case OT_LOG_LEVEL_INFO: + strcpy(formattedMsg, LOG_INFO "[ot] "); + break; + case OT_LOG_LEVEL_DEBG: + strcpy(formattedMsg, LOG_DETAIL "[ot] "); + break; + default: + strcpy(formattedMsg, LOG_DETAIL "[ot] "); + break; + } + + size_t prefixLen = strlen(formattedMsg); + size_t len = vsnprintf(formattedMsg + prefixLen, sizeof(formattedMsg) - prefixLen, aFormat, v); + + if (len >= sizeof formattedMsg - prefixLen) + { + formattedMsg[sizeof formattedMsg - 1] = '\0'; + } + + PrintLog(formattedMsg); + } + + // Let the application know that a log message has been emitted. + DeviceLayer::OnLogOutput(); +#endif // EFR32_LOG_ENABLED + va_end(v); +} +#endif // WEAVE_DEVICE_CONFIG_ENABLE_THREAD + +#if HARD_FAULT_LOG_ENABLE && EFR32_LOG_ENABLED + +/** + * Log register contents to UART when a hard fault occurs. + */ +extern "C" void debugHardfault(uint32_t *sp) +{ + uint32_t cfsr = SCB->CFSR; + uint32_t hfsr = SCB->HFSR; + uint32_t mmfar = SCB->MMFAR; + uint32_t bfar = SCB->BFAR; + uint32_t r0 = sp[0]; + uint32_t r1 = sp[1]; + uint32_t r2 = sp[2]; + uint32_t r3 = sp[3]; + uint32_t r12 = sp[4]; + uint32_t lr = sp[5]; + uint32_t pc = sp[6]; + uint32_t psr = sp[7]; + char formattedMsg[32]; + + if (sLogInitialized == false) + { + efr32LogInit(); + } + + snprintf(formattedMsg, sizeof formattedMsg, LOG_ERROR "HardFault:\n"); + PrintLog(formattedMsg); + snprintf(formattedMsg, sizeof formattedMsg, "SCB->CFSR 0x%08lx", cfsr); + PrintLog(formattedMsg); + snprintf(formattedMsg, sizeof formattedMsg, "SCB->HFSR 0x%08lx", hfsr); + PrintLog(formattedMsg); + snprintf(formattedMsg, sizeof formattedMsg, "SCB->MMFAR 0x%08lx", mmfar); + PrintLog(formattedMsg); + snprintf(formattedMsg, sizeof formattedMsg, "SCB->BFAR 0x%08lx", bfar); + PrintLog(formattedMsg); + snprintf(formattedMsg, sizeof formattedMsg, "SP 0x%08lx", (uint32_t)sp); + PrintLog(formattedMsg); + snprintf(formattedMsg, sizeof formattedMsg, "R0 0x%08lx\n", r0); + PrintLog(formattedMsg); + snprintf(formattedMsg, sizeof formattedMsg, "R1 0x%08lx\n", r1); + PrintLog(formattedMsg); + snprintf(formattedMsg, sizeof formattedMsg, "R2 0x%08lx\n", r2); + PrintLog(formattedMsg); + snprintf(formattedMsg, sizeof formattedMsg, "R3 0x%08lx\n", r3); + PrintLog(formattedMsg); + snprintf(formattedMsg, sizeof formattedMsg, "R12 0x%08lx\n", r12); + PrintLog(formattedMsg); + snprintf(formattedMsg, sizeof formattedMsg, "LR 0x%08lx\n", lr); + PrintLog(formattedMsg); + snprintf(formattedMsg, sizeof formattedMsg, "PC 0x%08lx\n", pc); + PrintLog(formattedMsg); + snprintf(formattedMsg, sizeof formattedMsg, "PSR 0x%08lx\n", psr); + PrintLog(formattedMsg); + + while (1) + ; +} + +/** + * Override default hard-fault handler + */ +extern "C" __attribute__((naked)) void HardFault_Handler(void) +{ + __asm volatile("tst lr, #4 \n" + "ite eq \n" + "mrseq r0, msp \n" + "mrsne r0, psp \n" + "ldr r1, debugHardfault_address \n" + "bx r1 \n" + "debugHardfault_address: .word debugHardfault \n"); +} + +#endif // HARD_FAULT_LOG_ENABLE && EFR32_LOG_ENABLED diff --git a/src/platform/EFR32/NetworkProvisioningServerImpl.cpp b/src/platform/EFR32/NetworkProvisioningServerImpl.cpp new file mode 100644 index 00000000000000..c055f2d37a81df --- /dev/null +++ b/src/platform/EFR32/NetworkProvisioningServerImpl.cpp @@ -0,0 +1,43 @@ +/* + * + * Copyright (c) 2019 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. + */ + +#include +#include +#include +#include +#include +#include + +#include + +namespace nl { +namespace Weave { +namespace DeviceLayer { +namespace Internal { + +NetworkProvisioningServerImpl NetworkProvisioningServerImpl::sInstance; + +WEAVE_ERROR NetworkProvisioningServerImpl::_Init(void) +{ + return GenericNetworkProvisioningServerImpl::DoInit(); +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl diff --git a/src/platform/EFR32/PlatformManagerImpl.cpp b/src/platform/EFR32/PlatformManagerImpl.cpp new file mode 100644 index 00000000000000..bfdcb5670b9562 --- /dev/null +++ b/src/platform/EFR32/PlatformManagerImpl.cpp @@ -0,0 +1,59 @@ +/* + * + * Copyright (c) 2019 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 + * Provides an implementation of the PlatformManager object + * for EFR32 platforms using the Silicon Labs EFR32 SDK. + */ + +#include +#include +#include + +#include + +namespace nl { +namespace Weave { +namespace DeviceLayer { + +PlatformManagerImpl PlatformManagerImpl::sInstance; + +WEAVE_ERROR PlatformManagerImpl::_InitWeaveStack(void) +{ + WEAVE_ERROR err; + + // Initialize the configuration system. + err = Internal::EFR32Config::Init(); + SuccessOrExit(err); + + // Initialize LwIP. + tcpip_init(NULL, NULL); + + // Call _InitWeaveStack() on the generic implementation base class + // to finish the initialization process. + err = Internal::GenericPlatformManagerImpl_FreeRTOS::_InitWeaveStack(); + SuccessOrExit(err); + +exit: + return err; +} + +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl diff --git a/src/platform/EFR32/SoftwareUpdateManagerImpl.cpp b/src/platform/EFR32/SoftwareUpdateManagerImpl.cpp new file mode 100644 index 00000000000000..609faf96a664de --- /dev/null +++ b/src/platform/EFR32/SoftwareUpdateManagerImpl.cpp @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2019 Google LLC. + * 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. + */ + +#include + +#if WEAVE_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER + +#include +#include + +#include +#include + +namespace nl { +namespace Weave { +namespace DeviceLayer { + +SoftwareUpdateManagerImpl SoftwareUpdateManagerImpl::sInstance; + +WEAVE_ERROR SoftwareUpdateManagerImpl::_Init(void) +{ + Internal::GenericSoftwareUpdateManagerImpl_BDX::DoInit(); + Internal::GenericSoftwareUpdateManagerImpl::DoInit(); + + return WEAVE_NO_ERROR; +} + +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl + +#endif // WEAVE_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/platform/EFR32/ThreadStackManagerImpl.cpp b/src/platform/EFR32/ThreadStackManagerImpl.cpp new file mode 100644 index 00000000000000..0d527abecb7428 --- /dev/null +++ b/src/platform/EFR32/ThreadStackManagerImpl.cpp @@ -0,0 +1,89 @@ +/* + * + * Copyright (c) 2019 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 + * Provides an implementation of the ThreadStackManager object for + * EFR32 platforms using the Silicon Labs SDK and the OpenThread + * stack. + * + */ + +#include +#include +#include + +#include +#include + +namespace nl { +namespace Weave { +namespace DeviceLayer { + +using namespace ::nl::Weave::DeviceLayer::Internal; + +ThreadStackManagerImpl ThreadStackManagerImpl::sInstance; + +WEAVE_ERROR ThreadStackManagerImpl::_InitThreadStack(void) +{ + return InitThreadStack(NULL); +} + +WEAVE_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance *otInst) +{ + WEAVE_ERROR err = WEAVE_NO_ERROR; + + // Initialize the generic implementation base classes. + err = GenericThreadStackManagerImpl_FreeRTOS::DoInit(); + SuccessOrExit(err); + err = GenericThreadStackManagerImpl_OpenThread_LwIP::DoInit(otInst); + SuccessOrExit(err); + +exit: + return err; +} + +bool ThreadStackManagerImpl::IsInitialized() +{ + return sInstance.mThreadStackLock != NULL; +} + +} // namespace DeviceLayer +} // namespace Weave +} // namespace nl + +using namespace ::nl::Weave::DeviceLayer; + +/** + * Glue function called directly by the OpenThread stack when tasklet processing work + * is pending. + */ +extern "C" void otTaskletsSignalPending(otInstance *p_instance) +{ + ThreadStackMgrImpl().SignalThreadActivityPending(); +} + +/** + * Glue function called directly by the OpenThread stack when system event processing work + * is pending. + */ +extern "C" void otSysEventSignalPending(void) +{ + BaseType_t yieldRequired = ThreadStackMgrImpl().SignalThreadActivityPendingFromISR(); + portYIELD_FROM_ISR(yieldRequired); +} diff --git a/src/platform/EFR32/freertos_bluetooth.c b/src/platform/EFR32/freertos_bluetooth.c new file mode 100644 index 00000000000000..6ff58476d0d35b --- /dev/null +++ b/src/platform/EFR32/freertos_bluetooth.c @@ -0,0 +1,395 @@ +/* + * + * Copyright (c) 2020 Google LLC. + * 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. + */ + +#include +#include +#include + +#include "rtos_gecko.h" +#include "gecko_configuration.h" +#include + +#ifdef CONFIGURATION_HEADER +#include CONFIGURATION_HEADER +#endif // CONFIGURATION_HEADER + +void BluetoothUpdate(); +volatile struct gecko_cmd_packet *bluetooth_evt; +SemaphoreHandle_t BluetoothMutex = NULL; + +volatile static uint32_t command_header; +volatile static void * command_data; +volatile static gecko_cmd_handler command_handler_func = NULL; + +// Bluetooth task +#ifndef BLUETOOTH_STACK_SIZE +#define BLUETOOTH_STACK_SIZE (2048) +#endif +static void BluetoothTask(void *p_arg); +static TaskHandle_t BluetoothTaskHandle = NULL; + +// Linklayer task +#ifndef LINKLAYER_STACK_SIZE +#define LINKLAYER_STACK_SIZE (2048) +#endif +static void LinklayerTask(void *p_arg); +static TaskHandle_t LinklayerTaskHandle = NULL; +// +#define RTOS_TICK_HZ 1024 +#define BLUETOOTH_TICK_HZ 32768 +#define BLUETOOTH_TO_RTOS_TICK (BLUETOOTH_TICK_HZ / RTOS_TICK_HZ) + +static volatile wakeupCallback wakeupCB = NULL; +// Set the task to post semaphore +void BluetoothSetWakeupCallback(wakeupCallback cb) +{ + wakeupCB = (volatile wakeupCallback)cb; +} +EventGroupHandle_t bluetooth_event_flags; + +errorcode_t bluetooth_start(UBaseType_t ll_priority, + UBaseType_t stack_priority, + bluetooth_stack_init_func initialize_bluetooth_stack) +{ + errorcode_t err; + bluetooth_event_flags = xEventGroupCreate(); + configASSERT(bluetooth_event_flags); + + BluetoothMutex = xSemaphoreCreateMutex(); + + err = initialize_bluetooth_stack(); + + if (err == 0) + { + // create tasks for Bluetooth host stack + xTaskCreate(BluetoothTask, /* Function that implements the task. */ + "Bluetooth Task", /* Text name for the task. */ + BLUETOOTH_STACK_SIZE / sizeof(StackType_t), /* Number of indexes in the xStack array. */ + NULL, /* Parameter passed into the task. */ + stack_priority, /* Priority at which the task is created. */ + &BluetoothTaskHandle); /* Variable to hold the task's data structure. */ + + // create tasks for Linklayer + xTaskCreate(LinklayerTask, /* Function that implements the task. */ + "Linklayer Task", /* Text name for the task. */ + LINKLAYER_STACK_SIZE / sizeof(StackType_t), /* Number of indexes in the xStack array. */ + NULL, /* Parameter passed into the task. */ + ll_priority, /* Priority at which the task is created. */ + &LinklayerTaskHandle); /* Variable to hold the task's data structure. */ + } + + return err; +} + +// This callback is called from interrupt context (Kernel Aware) +// sets flag to trigger Link Layer Task +void BluetoothLLCallback() +{ + EventBits_t eventBits; + BaseType_t pxHigherPriorityTaskWoken = pdFALSE; + eventBits = + vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_LL, &pxHigherPriorityTaskWoken); + (void)eventBits; +} +// This callback is called from Bluetooth stack +// Called from kernel aware interrupt context (RTCC interrupt) and from Bluetooth task +// sets flag to trigger running Bluetooth stack +void BluetoothUpdate() +{ + EventBits_t eventBits; + BaseType_t pxHigherPriorityTaskWoken = pdFALSE; + eventBits = + vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_STACK, &pxHigherPriorityTaskWoken); + (void)eventBits; +} +// Bluetooth task, it waits for events from bluetooth and handles them +void BluetoothTask(void *p) +{ + EventBits_t flags = BLUETOOTH_EVENT_FLAG_EVT_HANDLED | BLUETOOTH_EVENT_FLAG_STACK; + EventBits_t eventBits; + TickType_t xTicksToWait; + + while (1) + { + // Command needs to be sent to Bluetooth stack + if (flags & BLUETOOTH_EVENT_FLAG_CMD_WAITING) + { + uint32_t header = command_header; + gecko_cmd_handler cmd_handler = command_handler_func; + sli_bt_cmd_handler_delegate(header, cmd_handler, (void *)command_data); + command_handler_func = NULL; + flags &= ~BLUETOOTH_EVENT_FLAG_CMD_WAITING; + eventBits = vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_RSP_WAITING, NULL); + (void)eventBits; + } + + // Bluetooth stack needs updating, and evt can be used + if ((flags & BLUETOOTH_EVENT_FLAG_STACK) && (flags & BLUETOOTH_EVENT_FLAG_EVT_HANDLED)) + { // update bluetooth & read event + bluetooth_evt = gecko_wait_event(); + if (bluetooth_evt != NULL) + { // we got event, notify event handler. evt state is now waiting handling + eventBits = + vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_EVT_WAITING, NULL); + (void)eventBits; + flags &= ~(BLUETOOTH_EVENT_FLAG_EVT_HANDLED); + if (wakeupCB != NULL) + { + wakeupCB(); + } + } + else + { // nothing to do in stack, clear the flag + flags &= ~(BLUETOOTH_EVENT_FLAG_STACK); + } + } + + // Ask from Bluetooth stack how long we can sleep + // UINT32_MAX = sleep indefinitely + // 0 = cannot sleep, stack needs update and we need to check if evt is handled that we can actually update it + uint32_t timeout = gecko_can_sleep_ms(); + if (timeout == 0 && (flags & BLUETOOTH_EVENT_FLAG_EVT_HANDLED)) + { + flags |= BLUETOOTH_EVENT_FLAG_STACK; + continue; + } + + if (timeout == 0x07CFFFFF) + { + xTicksToWait = portMAX_DELAY; + } + else if (timeout == 0) + { + xTicksToWait = 10 / portTICK_PERIOD_MS; + } + else + { + // round up to RTOS ticks + xTicksToWait = timeout / portTICK_PERIOD_MS; + } + flags |= + xEventGroupWaitBits(bluetooth_event_flags, /* The event group being tested. */ + (BLUETOOTH_EVENT_FLAG_STACK + BLUETOOTH_EVENT_FLAG_EVT_HANDLED + + BLUETOOTH_EVENT_FLAG_CMD_WAITING), /* The bits within the event group to wait for. */ + pdTRUE, /* BLUETOOTH_EVENT_FLAG_LL should be cleared before returning. */ + pdFALSE, /* Wait for all the bits to be set, not needed for single bit. */ + xTicksToWait); /* Wait for maximum duration for bit to be set. With 1 ms tick, + portMAX_DELAY will result in wait of 50 days*/ + + if (((flags & BLUETOOTH_EVENT_FLAG_STACK) == 0) && ((flags & BLUETOOTH_EVENT_FLAG_EVT_HANDLED) == 0) && + ((flags & BLUETOOTH_EVENT_FLAG_CMD_WAITING) == 0)) + { + // timeout occurred, set the flag to update the Bluetooth stack + flags |= BLUETOOTH_EVENT_FLAG_STACK; + } + } +} + +static void LinklayerTask(void *p_arg) +{ + (void)p_arg; + + while (1) + { + EventBits_t uxBits; + + uxBits = xEventGroupWaitBits(bluetooth_event_flags, /* The event group being tested. */ + BLUETOOTH_EVENT_FLAG_LL, /* The bits within the event group to wait for. */ + pdTRUE, /* BLUETOOTH_EVENT_FLAG_LL should be cleared before returning. */ + pdTRUE, /* Wait for all the bits to be set, not needed for single bit. */ + portMAX_DELAY); /* Wait for maximum duration for bit to be set. With 1 ms tick, + portMAX_DELAY will result in wait of 50 days*/ + + if (uxBits & BLUETOOTH_EVENT_FLAG_LL) + { + gecko_priority_handle(); + } + } +} + +// hooks for API +// called from tasks using BGAPI +void rtos_gecko_handle_command(uint32_t header, void *payload) +{ + sli_bt_cmd_handler_rtos_delegate(header, NULL, payload); +} +void rtos_gecko_handle_command_noresponse(uint32_t header, void *payload) +{ + sli_bt_cmd_handler_rtos_delegate(header, NULL, payload); +} +void sli_bt_cmd_handler_rtos_delegate(uint32_t header, gecko_cmd_handler handler, const void *payload) +{ + EventBits_t uxBits; + + command_header = header; + command_handler_func = handler; + command_data = (void *)payload; + // Command structure is filled, notify the stack + uxBits = vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_CMD_WAITING, NULL); + + // wait for response + uxBits = xEventGroupWaitBits(bluetooth_event_flags, /* The event group being tested. */ + BLUETOOTH_EVENT_FLAG_RSP_WAITING, /* The bits within the event group to wait for. */ + pdTRUE, /* BLUETOOTH_EVENT_FLAG_LL should be cleared before returning. */ + pdTRUE, /* Wait for all the bits to be set, not needed for single bit. */ + portMAX_DELAY); /* Wait for maximum duration for bit to be set. With 1 ms tick, + portMAX_DELAY will result in wait of 50 days*/ + (void)uxBits; +} + +void BluetoothPend(void) +{ + xSemaphoreTake(BluetoothMutex, portMAX_DELAY); +} +void BluetoothPost(void) +{ + xSemaphoreGive(BluetoothMutex); +} + +void vApplicationMallocFailedHook(void) +{ + /* Called if a call to pvPortMalloc() fails because there is insufficient + free memory available in the FreeRTOS heap. pvPortMalloc() is called + internally by FreeRTOS API functions that create tasks, queues, software + timers, and semaphores. The size of the FreeRTOS heap is set by the + configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */ + + /* Force an assert. */ + configASSERT((volatile void *)NULL); +} +/*-----------------------------------------------------------*/ + +void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName) +{ + (void)pcTaskName; + (void)pxTask; + + /* Run time stack overflow checking is performed if + configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook + function is called if a stack overflow is detected. */ + + /* Force an assert. */ + configASSERT((volatile void *)NULL); +} + +void vApplicationTickHook(void) +{ +} + +/*-----------------------------------------------------------*/ + +/* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an +implementation of vApplicationGetIdleTaskMemory() to provide the memory that is +used by the Idle task. */ +void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, + StackType_t ** ppxIdleTaskStackBuffer, + uint32_t * pulIdleTaskStackSize) +{ + /* If the buffers to be provided to the Idle task are declared inside this + function then they must be declared static - otherwise they will be allocated on + the stack and so not exists after this function exits. */ + static StaticTask_t xIdleTaskTCB; + static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE]; + + /* Pass out a pointer to the StaticTask_t structure in which the Idle task's + state will be stored. */ + *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; + + /* Pass out the array that will be used as the Idle task's stack. */ + *ppxIdleTaskStackBuffer = uxIdleTaskStack; + + /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer. + Note that, as the array is necessarily of type StackType_t, + configMINIMAL_STACK_SIZE is specified in words, not bytes. */ + *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; +} +/*-----------------------------------------------------------*/ + +/* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the +application must provide an implementation of vApplicationGetTimerTaskMemory() +to provide the memory that is used by the Timer service task. */ +void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, + StackType_t ** ppxTimerTaskStackBuffer, + uint32_t * pulTimerTaskStackSize) +{ + /* If the buffers to be provided to the Timer task are declared inside this + function then they must be declared static - otherwise they will be allocated on + the stack and so not exists after this function exits. */ + static StaticTask_t xTimerTaskTCB; + static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH]; + + /* Pass out a pointer to the StaticTask_t structure in which the Timer + task's state will be stored. */ + *ppxTimerTaskTCBBuffer = &xTimerTaskTCB; + + /* Pass out the array that will be used as the Timer task's stack. */ + *ppxTimerTaskStackBuffer = uxTimerTaskStack; + + /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer. + Note that, as the array is necessarily of type StackType_t, + configMINIMAL_STACK_SIZE is specified in words, not bytes. */ + *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; +} + +EventBits_t vRaiseEventFlagBasedOnContext(EventGroupHandle_t xEventGroup, + EventBits_t uxBitsToWaitFor, + BaseType_t * pxHigherPriorityTaskWoken) +{ + EventBits_t eventBits; + BaseType_t higherPrioTaskWoken = pdFALSE; + + if (xPortIsInsideInterrupt()) + { + eventBits = xEventGroupSetBitsFromISR(xEventGroup, uxBitsToWaitFor, &higherPrioTaskWoken); + } + else + { + eventBits = xEventGroupSetBits(xEventGroup, uxBitsToWaitFor); + } + + if (pxHigherPriorityTaskWoken != NULL) + { + *pxHigherPriorityTaskWoken = higherPrioTaskWoken; + } + return eventBits; +} + +EventBits_t vSendToQueueBasedOnContext(QueueHandle_t xQueue, + void * xItemToQueue, + TickType_t xTicksToWait, + BaseType_t * pxHigherPriorityTaskWoken) +{ + BaseType_t status; + BaseType_t higherPrioTaskWoken = pdFALSE; + + if (xPortIsInsideInterrupt()) + { + status = xQueueSendFromISR(xQueue, xItemToQueue, &higherPrioTaskWoken); + } + else + { + status = xQueueSend(xQueue, xItemToQueue, xTicksToWait); + } + + if (pxHigherPriorityTaskWoken != NULL) + { + *pxHigherPriorityTaskWoken = higherPrioTaskWoken; + } + + return status; +} diff --git a/src/platform/EFR32/gatt_db.c b/src/platform/EFR32/gatt_db.c new file mode 100644 index 00000000000000..dfb982ac34c82a --- /dev/null +++ b/src/platform/EFR32/gatt_db.c @@ -0,0 +1,261 @@ +/* + * + * Copyright (c) 2020 Google LLC. + * 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. + */ + +/******************************************************************** + * Autogenerated file, do not edit. + *******************************************************************/ + +#include +#include "bg_gattdb_def.h" + +#define GATT_HEADER(F) F +#define GATT_DATA(F) F +GATT_DATA(const uint16_t bg_gattdb_data_uuidtable_16_map [])= +{ + 0x2800, + 0x2801, + 0x2803, + 0x1800, + 0x2a00, + 0x2a01, + 0x180a, + 0x2a29, + 0x2a24, + 0x2a23, + 0xfeaf, + 0x1801, + 0x2a05, + 0x2b2a, + 0x2b29, + 0x2902, +}; + +GATT_DATA(const uint8_t bg_gattdb_data_uuidtable_128_map [])= +{ +0xf0, 0x19, 0x21, 0xb4, 0x47, 0x8f, 0xa4, 0xbf, 0xa1, 0x4f, 0x63, 0xfd, 0xee, 0xd6, 0x14, 0x1d, +0x63, 0x60, 0x32, 0xe0, 0x37, 0x5e, 0xa4, 0x88, 0x53, 0x4e, 0x6d, 0xfb, 0x64, 0x35, 0xbf, 0xf7, +0x11, 0x9d, 0x9f, 0x42, 0x9c, 0x4f, 0x9f, 0x95, 0x59, 0x45, 0x3d, 0x26, 0xf5, 0x2e, 0xee, 0x18, +0x12, 0x9d, 0x9f, 0x42, 0x9c, 0x4f, 0x9f, 0x95, 0x59, 0x45, 0x3d, 0x26, 0xf5, 0x2e, 0xee, 0x18, +}; + + + + +struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_27_data = { + .len=1, + .data={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,} +}; +GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_27 ) = { + .properties=0x2e, + .index=6, + .max_len=247, + .data_varlen=&bg_gattdb_data_attribute_field_27_data, +}; + +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_26 ) = { + .len=19, + .data={0x2e,0x1c,0x00,0x12,0x9d,0x9f,0x42,0x9c,0x4f,0x9f,0x95,0x59,0x45,0x3d,0x26,0xf5,0x2e,0xee,0x18,} +}; +struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_25_data = { + .len=1, + .data={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,} +}; +GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_25 ) = { + .properties=0x0a, + .index=5, + .max_len=247, + .data_varlen=&bg_gattdb_data_attribute_field_25_data, +}; + +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_24 ) = { + .len=19, + .data={0x0a,0x1a,0x00,0x11,0x9d,0x9f,0x42,0x9c,0x4f,0x9f,0x95,0x59,0x45,0x3d,0x26,0xf5,0x2e,0xee,0x18,} +}; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_23 ) = { + .len=2, + .data={0xaf,0xfe,} +}; +GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_22 ) = { + .properties=0x08, + .index=4, + .max_len=0, + .data=NULL, +}; + +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_21 ) = { + .len=19, + .data={0x08,0x17,0x00,0x63,0x60,0x32,0xe0,0x37,0x5e,0xa4,0x88,0x53,0x4e,0x6d,0xfb,0x64,0x35,0xbf,0xf7,} +}; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_20 ) = { + .len=16, + .data={0xf0,0x19,0x21,0xb4,0x47,0x8f,0xa4,0xbf,0xa1,0x4f,0x63,0xfd,0xee,0xd6,0x14,0x1d,} +}; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_19 ) = { + .len=6, + .data={0x00,0x01,0x02,0x03,0x04,0x05,} +}; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_18 ) = { + .len=5, + .data={0x02,0x14,0x00,0x23,0x2a,} +}; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_17 ) = { + .len=10, + .data={0x42,0x6c,0x75,0x65,0x20,0x47,0x65,0x63,0x6b,0x6f,} +}; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_16 ) = { + .len=5, + .data={0x02,0x12,0x00,0x24,0x2a,} +}; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_15 ) = { + .len=12, + .data={0x53,0x69,0x6c,0x69,0x63,0x6f,0x6e,0x20,0x4c,0x61,0x62,0x73,} +}; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_14 ) = { + .len=5, + .data={0x02,0x10,0x00,0x29,0x2a,} +}; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_13 ) = { + .len=2, + .data={0x0a,0x18,} +}; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_12 ) = { + .len=2, + .data={0x00,0x00,} +}; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_11 ) = { + .len=5, + .data={0x02,0x0d,0x00,0x01,0x2a,} +}; +uint8_t bg_gattdb_data_attribute_field_10_data[13]={0x45,0x6d,0x70,0x74,0x79,0x20,0x45,0x78,0x61,0x6d,0x70,0x6c,0x65,}; +GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_10 ) = { + .properties=0x0a, + .index=3, + .max_len=13, + .data=bg_gattdb_data_attribute_field_10_data, +}; + +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_9 ) = { + .len=5, + .data={0x0a,0x0b,0x00,0x00,0x2a,} +}; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_8 ) = { + .len=2, + .data={0x00,0x18,} +}; +uint8_t bg_gattdb_data_attribute_field_7_data[1]={0x00,}; +GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_7 ) = { + .properties=0x0a, + .index=2, + .max_len=1, + .data=bg_gattdb_data_attribute_field_7_data, +}; + +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_6 ) = { + .len=5, + .data={0x0a,0x08,0x00,0x29,0x2b,} +}; +uint8_t bg_gattdb_data_attribute_field_5_data[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,}; +GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_5 ) = { + .properties=0x02, + .index=1, + .max_len=16, + .data=bg_gattdb_data_attribute_field_5_data, +}; + +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_4 ) = { + .len=5, + .data={0x02,0x06,0x00,0x2a,0x2b,} +}; +uint8_t bg_gattdb_data_attribute_field_2_data[4]={0x00,0x00,0x00,0x00,}; +GATT_DATA(const struct bg_gattdb_attribute_chrvalue bg_gattdb_data_attribute_field_2 ) = { + .properties=0x20, + .index=0, + .max_len=4, + .data=bg_gattdb_data_attribute_field_2_data, +}; + +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_1 ) = { + .len=5, + .data={0x20,0x03,0x00,0x05,0x2a,} +}; +GATT_DATA(const struct bg_gattdb_buffer_with_len bg_gattdb_data_attribute_field_0 ) = { + .len=2, + .data={0x01,0x18,} +}; +GATT_DATA(const struct bg_gattdb_attribute bg_gattdb_data_attributes_map[])={ + {.uuid=0x0000,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_0}, + {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_1}, + {.uuid=0x000c,.permissions=0x800,.caps=0xffff,.datatype=0x01,.dynamicdata=&bg_gattdb_data_attribute_field_2}, + {.uuid=0x000f,.permissions=0x807,.caps=0xffff,.datatype=0x03,.configdata={.flags=0x02,.index=0x00,.clientconfig_index=0x00}}, + {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_4}, + {.uuid=0x000d,.permissions=0x801,.caps=0xffff,.datatype=0x01,.dynamicdata=&bg_gattdb_data_attribute_field_5}, + {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_6}, + {.uuid=0x000e,.permissions=0x803,.caps=0xffff,.datatype=0x01,.dynamicdata=&bg_gattdb_data_attribute_field_7}, + {.uuid=0x0000,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_8}, + {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_9}, + {.uuid=0x0004,.permissions=0x803,.caps=0xffff,.datatype=0x01,.dynamicdata=&bg_gattdb_data_attribute_field_10}, + {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_11}, + {.uuid=0x0005,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_12}, + {.uuid=0x0000,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_13}, + {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_14}, + {.uuid=0x0007,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_15}, + {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_16}, + {.uuid=0x0008,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_17}, + {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_18}, + {.uuid=0x0009,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_19}, + {.uuid=0x0000,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_20}, + {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_21}, + {.uuid=0x8001,.permissions=0x802,.caps=0xffff,.datatype=0x07,.dynamicdata=&bg_gattdb_data_attribute_field_22}, + {.uuid=0x0000,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_23}, + {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_24}, + {.uuid=0x8002,.permissions=0x803,.caps=0xffff,.datatype=0x02,.dynamicdata=&bg_gattdb_data_attribute_field_25}, + {.uuid=0x0002,.permissions=0x801,.caps=0xffff,.datatype=0x00,.constdata=&bg_gattdb_data_attribute_field_26}, + {.uuid=0x8003,.permissions=0x807,.caps=0xffff,.datatype=0x02,.dynamicdata=&bg_gattdb_data_attribute_field_27}, + {.uuid=0x000f,.permissions=0x807,.caps=0xffff,.datatype=0x03,.configdata={.flags=0x02,.index=0x06,.clientconfig_index=0x01}}, +}; + +GATT_DATA(const uint16_t bg_gattdb_data_attributes_dynamic_mapping_map[])={ + 0x0003, + 0x0006, + 0x0008, + 0x000b, + 0x0017, + 0x001a, + 0x001c, +}; + +GATT_DATA(const uint8_t bg_gattdb_data_adv_uuid16_map[])={0x0}; +GATT_DATA(const uint8_t bg_gattdb_data_adv_uuid128_map[])={0x0}; +GATT_HEADER(const struct bg_gattdb_def bg_gattdb_data)={ + .attributes=bg_gattdb_data_attributes_map, + .attributes_max=29, + .uuidtable_16_size=16, + .uuidtable_16=bg_gattdb_data_uuidtable_16_map, + .uuidtable_128_size=4, + .uuidtable_128=bg_gattdb_data_uuidtable_128_map, + .attributes_dynamic_max=7, + .attributes_dynamic_mapping=bg_gattdb_data_attributes_dynamic_mapping_map, + .adv_uuid16=bg_gattdb_data_adv_uuid16_map, + .adv_uuid16_num=0, + .adv_uuid128=bg_gattdb_data_adv_uuid128_map, + .adv_uuid128_num=0, + .caps_mask=0xffff, + .enabled_caps=0xffff, +}; + +const struct bg_gattdb_def *bg_gattdb=&bg_gattdb_data; From 5cacfa32b3ca47186c94d6805e0c8c7822b0391a Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Wed, 18 Mar 2020 13:28:05 -0700 Subject: [PATCH 2/2] Rename to CHIP and fix imports --- src/include/platform/EFR32/BLEManagerImpl.h | 67 ++-- .../platform/EFR32/BlePlatformConfig.h | 5 +- .../platform/EFR32/CHIPDevicePlatformConfig.h | 133 ++++++++ ...tformEvent.h => CHIPDevicePlatformEvent.h} | 31 +- .../platform/EFR32/CHIPPlatformConfig.h | 149 +++++++++ .../platform/EFR32/ConfigurationManagerImpl.h | 31 +- .../platform/EFR32/ConnectivityManagerImpl.h | 45 ++- src/include/platform/EFR32/EFR32Config.h | 119 ++++--- .../platform/EFR32/GroupKeyStoreImpl.h | 51 ++- .../platform/EFR32/InetPlatformConfig.h | 5 +- .../EFR32/NetworkProvisioningServerImpl.h | 15 +- .../platform/EFR32/PlatformManagerImpl.h | 17 +- .../EFR32/SoftwareUpdateManagerImpl.h | 21 +- .../platform/EFR32/SystemPlatformConfig.h | 49 ++- .../platform/EFR32/ThreadStackManagerImpl.h | 27 +- .../platform/EFR32/WarmPlatformConfig.h | 5 +- .../EFR32/WeaveDevicePlatformConfig.h | 134 -------- .../platform/EFR32/WeavePlatformConfig.h | 150 --------- .../EFR32/efr32-weave-mbedtls-config.h | 3 +- .../platform/EFR32/freertos_bluetooth.h | 3 +- src/include/platform/EFR32/gatt.xml | 27 +- src/include/platform/EFR32/gatt_db.h | 3 +- .../internal/testing/ConfigUnitTest.h | 205 ++++++++++++ src/platform/EFR32/BLEManagerImpl.cpp | 307 +++++++++--------- .../EFR32/ConfigurationManagerImpl.cpp | 91 +++--- .../EFR32/ConnectivityManagerImpl.cpp | 63 ++-- src/platform/EFR32/EFR32Config.cpp | 201 ++++++------ src/platform/EFR32/Entropy.cpp | 54 ++- src/platform/EFR32/GroupKeyStoreImpl.cpp | 183 +++++------ src/platform/EFR32/Logging.cpp | 64 ++-- .../EFR32/NetworkProvisioningServerImpl.cpp | 26 +- src/platform/EFR32/PlatformManagerImpl.cpp | 23 +- .../EFR32/SoftwareUpdateManagerImpl.cpp | 27 +- src/platform/EFR32/ThreadStackManagerImpl.cpp | 29 +- src/platform/EFR32/freertos_bluetooth.c | 5 +- src/platform/EFR32/gatt_db.c | 3 +- 36 files changed, 1243 insertions(+), 1128 deletions(-) create mode 100644 src/include/platform/EFR32/CHIPDevicePlatformConfig.h rename src/include/platform/EFR32/{WeaveDevicePlatformEvent.h => CHIPDevicePlatformEvent.h} (75%) create mode 100644 src/include/platform/EFR32/CHIPPlatformConfig.h delete mode 100644 src/include/platform/EFR32/WeaveDevicePlatformConfig.h delete mode 100644 src/include/platform/EFR32/WeavePlatformConfig.h create mode 100644 src/include/platform/internal/testing/ConfigUnitTest.h diff --git a/src/include/platform/EFR32/BLEManagerImpl.h b/src/include/platform/EFR32/BLEManagerImpl.h index 2ce1b9c2734a9c..d348095f4aa007 100644 --- a/src/include/platform/EFR32/BLEManagerImpl.h +++ b/src/include/platform/EFR32/BLEManagerImpl.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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. @@ -25,14 +24,13 @@ #ifndef BLE_MANAGER_IMPL_H #define BLE_MANAGER_IMPL_H -#if WEAVE_DEVICE_CONFIG_ENABLE_WOBLE +#if CHIP_DEVICE_CONFIG_ENABLE_WOBLE #include "bg_types.h" #include "rtos_gecko.h" #include "gatt_db.h" -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { namespace Internal { @@ -40,7 +38,7 @@ namespace Internal { * Concrete implementation of the NetworkProvisioningServer singleton object for the EFR32 platforms. */ class BLEManagerImpl final : public BLEManager, - private ::nl::Ble::BleLayer, + private ::chip::Ble::BleLayer, private BlePlatformDelegate, private BleApplicationDelegate { @@ -50,50 +48,50 @@ class BLEManagerImpl final : public BLEManager, // ===== Members that implement the BLEManager internal interface. - WEAVE_ERROR _Init(void); + CHIP_ERROR _Init(void); WoBLEServiceMode _GetWoBLEServiceMode(void); - WEAVE_ERROR _SetWoBLEServiceMode(WoBLEServiceMode val); + CHIP_ERROR _SetWoBLEServiceMode(WoBLEServiceMode val); bool _IsAdvertisingEnabled(void); - WEAVE_ERROR _SetAdvertisingEnabled(bool val); + CHIP_ERROR _SetAdvertisingEnabled(bool val); bool _IsFastAdvertisingEnabled(void); - WEAVE_ERROR _SetFastAdvertisingEnabled(bool val); + CHIP_ERROR _SetFastAdvertisingEnabled(bool val); bool _IsAdvertising(void); - WEAVE_ERROR _GetDeviceName(char *buf, size_t bufSize); - WEAVE_ERROR _SetDeviceName(const char *deviceName); + CHIP_ERROR _GetDeviceName(char *buf, size_t bufSize); + CHIP_ERROR _SetDeviceName(const char *deviceName); uint16_t _NumConnections(void); - void _OnPlatformEvent(const WeaveDeviceEvent *event); - ::nl::Ble::BleLayer *_GetBleLayer(void) const; + void _OnPlatformEvent(const ChipDeviceEvent *event); + ::chip::Ble::BleLayer *_GetBleLayer(void) const; // ===== Members that implement virtual methods on BlePlatformDelegate. bool SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, - const WeaveBleUUID * svcId, - const WeaveBleUUID * charId) override; + const ChipBleUUID * svcId, + const ChipBleUUID * charId) override; bool UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, - const WeaveBleUUID * svcId, - const WeaveBleUUID * charId) override; + const ChipBleUUID * svcId, + const ChipBleUUID * charId) override; bool CloseConnection(BLE_CONNECTION_OBJECT conId) override; uint16_t GetMTU(BLE_CONNECTION_OBJECT conId) const override; bool SendIndication(BLE_CONNECTION_OBJECT conId, - const WeaveBleUUID * svcId, - const WeaveBleUUID * charId, + const ChipBleUUID * svcId, + const ChipBleUUID * charId, PacketBuffer * pBuf) override; bool SendWriteRequest(BLE_CONNECTION_OBJECT conId, - const WeaveBleUUID * svcId, - const WeaveBleUUID * charId, + const ChipBleUUID * svcId, + const ChipBleUUID * charId, PacketBuffer * pBuf) override; bool SendReadRequest(BLE_CONNECTION_OBJECT conId, - const WeaveBleUUID * svcId, - const WeaveBleUUID * charId, + const ChipBleUUID * svcId, + const ChipBleUUID * charId, PacketBuffer * pBuf) override; bool SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, - const WeaveBleUUID * svcId, - const WeaveBleUUID * charId) override; + const ChipBleUUID * svcId, + const ChipBleUUID * charId) override; // ===== Members that implement virtual methods on BleApplicationDelegate. - void NotifyWeaveConnectionClosed(BLE_CONNECTION_OBJECT conId) override; + void NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) override; // ===== Members for internal use by the following friends. @@ -138,11 +136,11 @@ class BLEManagerImpl final : public BLEManager, uint16_t mFlags; char mDeviceName[kMaxDeviceNameLength + 1]; - WEAVE_ERROR MapBLEError(int bleErr); + CHIP_ERROR MapBLEError(int bleErr); void DriveBLEState(void); - WEAVE_ERROR ConfigureAdvertisingData(void); - WEAVE_ERROR StartAdvertising(void); - WEAVE_ERROR StopAdvertising(void); + CHIP_ERROR ConfigureAdvertisingData(void); + CHIP_ERROR StartAdvertising(void); + CHIP_ERROR StopAdvertising(void); void UpdateMtu(volatile struct gecko_cmd_packet *evt); void HandleBootEvent(void); void HandleConnectEvent(volatile struct gecko_cmd_packet *evt); @@ -182,7 +180,7 @@ inline BLEManagerImpl &BLEMgrImpl(void) return BLEManagerImpl::sInstance; } -inline ::nl::Ble::BleLayer *BLEManagerImpl::_GetBleLayer() const +inline ::chip::Ble::BleLayer *BLEManagerImpl::_GetBleLayer() const { return (BleLayer *)(this); } @@ -204,9 +202,8 @@ inline bool BLEManagerImpl::_IsFastAdvertisingEnabled(void) } // namespace Internal } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip -#endif // WEAVE_DEVICE_CONFIG_ENABLE_WOBLE +#endif // CHIP_DEVICE_CONFIG_ENABLE_WOBLE #endif // BLE_MANAGER_IMPL_H diff --git a/src/include/platform/EFR32/BlePlatformConfig.h b/src/include/platform/EFR32/BlePlatformConfig.h index efbceb9a80c776..15901fb59e4537 100644 --- a/src/include/platform/EFR32/BlePlatformConfig.h +++ b/src/include/platform/EFR32/BlePlatformConfig.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 Google LLC. - * 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,7 +17,7 @@ /** * @file - * Platform-specific configuration overrides for the OpenWeave BLE + * Platform-specific configuration overrides for the OpenChip BLE * Layer on EFR32 platforms using the Silicon Labs SDK. * */ diff --git a/src/include/platform/EFR32/CHIPDevicePlatformConfig.h b/src/include/platform/EFR32/CHIPDevicePlatformConfig.h new file mode 100644 index 00000000000000..30e9c641aaff31 --- /dev/null +++ b/src/include/platform/EFR32/CHIPDevicePlatformConfig.h @@ -0,0 +1,133 @@ +/* + * + * + * + * 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 + * Platform-specific configuration overrides for the Chip Device Layer + * on EFR32 platforms using the Silicon Labs SDK. + */ + +#ifndef CHIP_DEVICE_PLATFORM_CONFIG_H +#define CHIP_DEVICE_PLATFORM_CONFIG_H + +// ==================== Platform Adaptations ==================== + +#define CHIP_DEVICE_CONFIG_EFR32_NVM3_ERROR_MIN 12000000 +#define CHIP_DEVICE_CONFIG_EFR32_BLE_ERROR_MIN 13000000 + +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0 +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0 + +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD 1 +#define CHIP_DEVICE_CONFIG_ENABLE_WOBLE 1 + +#define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 1 +#define CHIP_DEVICE_CONFIG_ENABLE_SERVICE_DIRECTORY_TIME_SYNC 0 + +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY 2 +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_PROD_EIDC_KEY 3 +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY 4 +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY 5 + +// ========== Platform-specific Configuration ========= + +// These are configuration options that are unique to the EFR32 platform. +// These can be overridden by the application as needed. +/** + * @def CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE + * + * The maximum size of any log message. + */ +#ifndef CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE +#define CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE 150 +#endif // CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE + +// -------------- EFR32 NVM3 Storage Configuration ------------- + +/** + * @def CHIP_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS + * + * @brief + * Configures the size of the nvm3 cache and should be set >= the + * maximum number of Chip Config objects, e.g... + * Factory configs[5], System configs[23], Counter configs[32] + margin[4] = 64. + * + */ +#ifndef CHIP_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS +#define CHIP_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS 64 +#endif // CHIP_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS + +/** + * @def CHIP_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE + * + * @brief + * This determines the max size for any Chip nvm3 object + * (e.g. for Config 'string' or 'binary' types). + */ +#ifndef CHIP_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE +#define CHIP_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE 1000 +#endif // CHIP_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE + +/** + * @def CHIP_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE + * + * @brief + * This determines the Flash size used for nvm3 data storage:- + * (assuming 2k Flash page size) => Total Flash size for nvm3: 8 * 2k = 16k + * The total size should allow sufficient margin for wear-levelling and + * repacking. + */ +#ifndef CHIP_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE +#define CHIP_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE 8 +#endif // CHIP_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE + +// ========== Platform-specific Configuration Overrides ========= + +#ifndef CHIP_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY +#define CHIP_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY (configTIMER_TASK_PRIORITY - 1) +#endif // CHIP_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY + +#ifndef CHIP_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY +#define CHIP_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY (CHIP_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY - 1) +#endif // CHIP_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY + +#ifndef CHIP_DEVICE_CONFIG_BLE_APP_TASK_PRIORITY +#define CHIP_DEVICE_CONFIG_BLE_APP_TASK_PRIORITY (CHIP_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY - 1) +#endif // CHIP_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY + +#ifndef CHIP_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE +#define CHIP_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE 1024 +#endif // CHIP_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE + +#ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE +#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE 8192 +#endif // CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE + +#ifndef CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE +#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE 8192 +#endif // CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE + +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY 0 +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY 1 +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL 0 +#define CHIP_DEVICE_CONFIG_ENABLE_TUNNEL_TELEMETRY 0 + +#ifndef CHIP_DEVICE_CONFIG_BLE_APP_TASK_NAME +#define CHIP_DEVICE_CONFIG_BLE_APP_TASK_NAME "Bluetooth App Task" +#endif // CHIP_DEVICE_CONFIG_BLE_APP_TASK_NAME + +#endif // CHIP_DEVICE_PLATFORM_CONFIG_H diff --git a/src/include/platform/EFR32/WeaveDevicePlatformEvent.h b/src/include/platform/EFR32/CHIPDevicePlatformEvent.h similarity index 75% rename from src/include/platform/EFR32/WeaveDevicePlatformEvent.h rename to src/include/platform/EFR32/CHIPDevicePlatformEvent.h index e686c20a95f513..f820aa71daf920 100644 --- a/src/include/platform/EFR32/WeaveDevicePlatformEvent.h +++ b/src/include/platform/EFR32/CHIPDevicePlatformEvent.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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,25 +17,22 @@ /** * @file - * Defines platform-specific event types and data for the Weave + * Defines platform-specific event types and data for the Chip * Device Layer on EFR32 platforms using the Silicon Labs SDK. */ -#ifndef WEAVE_DEVICE_PLATFORM_EVENT_H -#define WEAVE_DEVICE_PLATFORM_EVENT_H +#ifndef CHIP_DEVICE_PLATFORM_EVENT_H +#define CHIP_DEVICE_PLATFORM_EVENT_H -#include +#include -namespace nl { -namespace Weave { +namespace chip { namespace System { class PacketBuffer; -} -} // namespace Weave -} // namespace nl +} // namespace System +} // namespace chip -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { namespace DeviceEventType { @@ -50,7 +46,7 @@ enum PublicPlatformSpecificEventTypes }; /** - * Enumerates EFR32 platform-specific event types that are internal to the Weave Device Layer. + * Enumerates EFR32 platform-specific event types that are internal to the Chip Device Layer. */ enum InternalPlatformSpecificEventTypes { @@ -63,7 +59,7 @@ enum InternalPlatformSpecificEventTypes * Represents platform-specific event information for Silicon Labs EFR32 platforms. */ -struct WeaveDevicePlatformEvent final +struct ChipDevicePlatformEvent final { union { @@ -72,7 +68,6 @@ struct WeaveDevicePlatformEvent final }; } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip -#endif // WEAVE_DEVICE_PLATFORM_EVENT_H +#endif // CHIP_DEVICE_PLATFORM_EVENT_H diff --git a/src/include/platform/EFR32/CHIPPlatformConfig.h b/src/include/platform/EFR32/CHIPPlatformConfig.h new file mode 100644 index 00000000000000..2922f8bd579d36 --- /dev/null +++ b/src/include/platform/EFR32/CHIPPlatformConfig.h @@ -0,0 +1,149 @@ +/* + * + * + * + * 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 + * Platform-specific configuration overrides for OpenChip on + * Silcon Labs EFR32 platforms. + */ + +#ifndef CHIP_PLATFORM_CONFIG_H +#define CHIP_PLATFORM_CONFIG_H + +#include + +// ==================== General Platform Adaptations ==================== + +#define CHIP_CONFIG_ERROR_TYPE int32_t +#define CHIP_CONFIG_NO_ERROR 0 +#define CHIP_CONFIG_ERROR_MIN 4000000 +#define CHIP_CONFIG_ERROR_MAX 4000999 + +#define ASN1_CONFIG_ERROR_TYPE int32_t +#define ASN1_CONFIG_NO_ERROR 0 +#define ASN1_CONFIG_ERROR_MIN 5000000 +#define ASN1_CONFIG_ERROR_MAX 5000999 + +#define ChipDie() abort() + +#define CHIP_CONFIG_ENABLE_TUNNELING 0 +#define CHIP_CONFIG_MAX_TUNNELS 0 +#define CHIP_CONFIG_ENABLE_SERVICE_DIRECTORY 0 + +#define CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE uint8_t +#define CHIP_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_ID 1 +#define CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH 2 + +#define CHIP_CONFIG_TIME_ENABLE_CLIENT 1 +#define CHIP_CONFIG_TIME_ENABLE_SERVER 0 + +// ==================== Security Adaptations ==================== + +#define CHIP_CONFIG_USE_OPENSSL_ECC 0 +#define CHIP_CONFIG_USE_MICRO_ECC 1 + +#define CHIP_CONFIG_HASH_IMPLEMENTATION_OPENSSL 0 +#define CHIP_CONFIG_HASH_IMPLEMENTATION_MINCRYPT 1 +#define CHIP_CONFIG_HASH_IMPLEMENTATION_MBEDTLS 0 +#define CHIP_CONFIG_HASH_IMPLEMENTATION_PLATFORM 0 + +// FIXME: EFR32 set to MBED-TLS (But this is third-party repo in OpenChip, not SDK) + +#define CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL 0 +#define CHIP_CONFIG_AES_IMPLEMENTATION_AESNI 0 +#define CHIP_CONFIG_AES_IMPLEMENTATION_MBEDTLS 1 +#define CHIP_CONFIG_AES_IMPLEMENTATION_PLATFORM 0 + +// FIXME: EFR32 currently set to CHIP (Does this use Entropy.cpp ?) + +#define CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL 0 +#define CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG 1 +#define CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM 0 + +#define CHIP_CONFIG_ENABLE_PASE_INITIATOR 0 +#define CHIP_CONFIG_ENABLE_PASE_RESPONDER 1 +#define CHIP_CONFIG_ENABLE_CASE_INITIATOR 1 + +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG0 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG1 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG2 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG3 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG4 1 + +#define CHIP_CONFIG_ENABLE_KEY_EXPORT_INITIATOR 0 + +#define CHIP_CONFIG_ENABLE_PROVISIONING_BUNDLE_SUPPORT 0 + +// ==================== General Configuration Overrides ==================== + +#ifndef CHIP_CONFIG_MAX_PEER_NODES +#define CHIP_CONFIG_MAX_PEER_NODES 16 +#endif // CHIP_CONFIG_MAX_PEER_NODES + +#ifndef CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS +#define CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS 16 +#endif // CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS + +#ifndef CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS +#define CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS 8 +#endif // CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS + +#ifndef CHIP_CONFIG_WRMP_TIMER_DEFAULT_PERIOD +#define CHIP_CONFIG_WRMP_TIMER_DEFAULT_PERIOD 50 +#endif // CHIP_CONFIG_WRMP_TIMER_DEFAULT_PERIOD + +#ifndef CHIP_LOG_FILTERING +#define CHIP_LOG_FILTERING 0 +#endif // CHIP_LOG_FILTERING + +#ifndef CHIP_CONFIG_MAX_INTERFACES +#define CHIP_CONFIG_MAX_INTERFACES 4 +#endif // CHIP_CONFIG_MAX_INTERFACES + +#ifndef CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS +#define CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS 4 +#endif // CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS + +// ==================== Security Configuration Overrides ==================== + +#ifndef CHIP_CONFIG_MAX_APPLICATION_GROUPS +#define CHIP_CONFIG_MAX_APPLICATION_GROUPS 4 +#endif // CHIP_CONFIG_MAX_APPLICATION_GROUPS + +#ifndef CHIP_CONFIG_DEBUG_CERT_VALIDATION +#define CHIP_CONFIG_DEBUG_CERT_VALIDATION 0 +#endif // CHIP_CONFIG_DEBUG_CERT_VALIDATION + +#ifndef CHIP_CONFIG_ENABLE_CASE_RESPONDER +#define CHIP_CONFIG_ENABLE_CASE_RESPONDER 1 +#endif // CHIP_CONFIG_ENABLE_CASE_RESPONDER + +// ==================== WDM Configuration Overrides ==================== + +#ifndef WDM_MAX_NUM_SUBSCRIPTION_CLIENTS +#define WDM_MAX_NUM_SUBSCRIPTION_CLIENTS 2 +#endif // WDM_MAX_NUM_SUBSCRIPTION_CLIENTS + +#ifndef WDM_MAX_NUM_SUBSCRIPTION_HANDLERS +#define WDM_MAX_NUM_SUBSCRIPTION_HANDLERS 2 +#endif // WDM_MAX_NUM_SUBSCRIPTION_HANDLERS + +#ifndef WDM_PUBLISHER_MAX_NOTIFIES_IN_FLIGHT +#define WDM_PUBLISHER_MAX_NOTIFIES_IN_FLIGHT 2 +#endif // WDM_PUBLISHER_MAX_NOTIFIES_IN_FLIGHT + +#endif /* CHIP_PLATFORM_CONFIG_H */ diff --git a/src/include/platform/EFR32/ConfigurationManagerImpl.h b/src/include/platform/EFR32/ConfigurationManagerImpl.h index 4911509a3f6b5a..06df533f3a0479 100644 --- a/src/include/platform/EFR32/ConfigurationManagerImpl.h +++ b/src/include/platform/EFR32/ConfigurationManagerImpl.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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. @@ -25,11 +24,10 @@ #ifndef CONFIGURATION_MANAGER_IMPL_H #define CONFIGURATION_MANAGER_IMPL_H -#include +#include #include "EFR32Config.h" -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { namespace Internal { @@ -54,14 +52,14 @@ class ConfigurationManagerImpl final : public ConfigurationManager, private: // ===== Members that implement the ConfigurationManager public interface. - WEAVE_ERROR _Init(void); - WEAVE_ERROR _GetPrimaryWiFiMACAddress(uint8_t *buf); - WEAVE_ERROR _GetDeviceDescriptor(::nl::Weave::Profiles::DeviceDescription::WeaveDeviceDescriptor &deviceDesc); - ::nl::Weave::Profiles::Security::AppKeys::GroupKeyStoreBase *_GetGroupKeyStore(void); + 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); - WEAVE_ERROR _ReadPersistedStorageValue(::nl::Weave::Platform::PersistedStorage::Key key, uint32_t &value); - WEAVE_ERROR _WritePersistedStorageValue(::nl::Weave::Platform::PersistedStorage::Key key, uint32_t value); + CHIP_ERROR _ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t &value); + CHIP_ERROR _WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value); // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. @@ -81,7 +79,7 @@ class ConfigurationManagerImpl final : public ConfigurationManager, /** * Returns the public interface of the ConfigurationManager singleton object. * - * Weave applications should use this to access features of the ConfigurationManager object + * Chip applications should use this to access features of the ConfigurationManager object * that are common to all platforms. */ inline ConfigurationManager &ConfigurationMgr(void) @@ -92,7 +90,7 @@ inline ConfigurationManager &ConfigurationMgr(void) /** * Returns the platform-specific implementation of the ConfigurationManager singleton object. * - * Weave applications can use this to gain access to features of the ConfigurationManager + * Chip applications can use this to gain access to features of the ConfigurationManager * that are specific to the ESP32 platform. */ inline ConfigurationManagerImpl &ConfigurationMgrImpl(void) @@ -100,13 +98,12 @@ inline ConfigurationManagerImpl &ConfigurationMgrImpl(void) return ConfigurationManagerImpl::sInstance; } -inline WEAVE_ERROR ConfigurationManagerImpl::_GetPrimaryWiFiMACAddress(uint8_t *buf) +inline CHIP_ERROR ConfigurationManagerImpl::_GetPrimaryWiFiMACAddress(uint8_t *buf) { - return WEAVE_ERROR_UNSUPPORTED_WEAVE_FEATURE; + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip #endif // CONFIGURATION_MANAGER_IMPL_H diff --git a/src/include/platform/EFR32/ConnectivityManagerImpl.h b/src/include/platform/EFR32/ConnectivityManagerImpl.h index 2fea69e5cf9520..79d6483ef075da 100644 --- a/src/include/platform/EFR32/ConnectivityManagerImpl.h +++ b/src/include/platform/EFR32/ConnectivityManagerImpl.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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. @@ -19,30 +18,27 @@ #ifndef CONNECTIVITY_MANAGER_IMPL_H #define CONNECTIVITY_MANAGER_IMPL_H -#include -#include -#if WEAVE_DEVICE_CONFIG_ENABLE_WOBLE -#include +#include +#include +#if CHIP_DEVICE_CONFIG_ENABLE_WOBLE +#include #else -#include +#include #endif -#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD -#include +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#include #else -#include +#include #endif -#include -#include -#include +#include +#include +#include -namespace nl { namespace Inet { class IPAddress; } // namespace Inet -} // namespace nl -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { /** @@ -50,12 +46,12 @@ namespace DeviceLayer { */ class ConnectivityManagerImpl final : public ConnectivityManager, public Internal::GenericConnectivityManagerImpl, -#if WEAVE_DEVICE_CONFIG_ENABLE_WOBLE +#if CHIP_DEVICE_CONFIG_ENABLE_WOBLE public Internal::GenericConnectivityManagerImpl_BLE, #else public Internal::GenericConnectivityManagerImpl_NoBLE, #endif -#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD public Internal::GenericConnectivityManagerImpl_Thread, #else public Internal::GenericConnectivityManagerImpl_NoThread, @@ -73,8 +69,8 @@ class ConnectivityManagerImpl final : public ConnectivityManager, bool _HaveIPv4InternetConnectivity(void); bool _HaveIPv6InternetConnectivity(void); bool _HaveServiceConnectivity(void); - WEAVE_ERROR _Init(void); - void _OnPlatformEvent(const WeaveDeviceEvent *event); + CHIP_ERROR _Init(void); + void _OnPlatformEvent(const ChipDeviceEvent *event); // ===== Members for internal use by the following friends. @@ -102,7 +98,7 @@ inline bool ConnectivityManagerImpl::_HaveServiceConnectivity(void) /** * Returns the public interface of the ConnectivityManager singleton object. * - * Weave applications should use this to access features of the ConnectivityManager object + * Chip applications should use this to access features of the ConnectivityManager object * that are common to all platforms. */ inline ConnectivityManager &ConnectivityMgr(void) @@ -113,7 +109,7 @@ inline ConnectivityManager &ConnectivityMgr(void) /** * Returns the platform-specific implementation of the ConnectivityManager singleton object. * - * Weave applications can use this to gain access to features of the ConnectivityManager + * Chip applications can use this to gain access to features of the ConnectivityManager * that are specific to the ESP32 platform. */ inline ConnectivityManagerImpl &ConnectivityMgrImpl(void) @@ -122,7 +118,6 @@ inline ConnectivityManagerImpl &ConnectivityMgrImpl(void) } } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip #endif // CONNECTIVITY_MANAGER_IMPL_H diff --git a/src/include/platform/EFR32/EFR32Config.h b/src/include/platform/EFR32/EFR32Config.h index 3799e2afece7b0..681fe38f93b93c 100644 --- a/src/include/platform/EFR32/EFR32Config.h +++ b/src/include/platform/EFR32/EFR32Config.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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. @@ -27,13 +26,12 @@ #include -#include +#include #include "nvm3.h" #include "nvm3_hal_flash.h" -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { namespace Internal { @@ -66,86 +64,85 @@ class EFR32Config using Key = uint32_t; - // NVM3 key base offsets used by the OpenWeave Device Layer. - static constexpr uint8_t kWeaveFactory_KeyBase = + // NVM3 key base offsets used by the OpenChip Device Layer. + static constexpr uint8_t kChipFactory_KeyBase = 0xA2; // Persistent config values set at manufacturing time. Retained during factory reset. - static constexpr uint8_t kWeaveConfig_KeyBase = + static constexpr uint8_t kChipConfig_KeyBase = 0xA3; // Persistent config values set at runtime. Cleared during factory reset. - static constexpr uint8_t kWeaveCounter_KeyBase = + static constexpr uint8_t kChipCounter_KeyBase = 0xA4; // Persistent counter values set at runtime. Retained during factory reset. // Key definitions for well-known configuration values. // Factory config keys - static constexpr Key kConfigKey_SerialNum = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x00); - static constexpr Key kConfigKey_MfrDeviceId = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x01); - static constexpr Key kConfigKey_MfrDeviceCert = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x02); - static constexpr Key kConfigKey_MfrDevicePrivateKey = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x03); - static constexpr Key kConfigKey_ManufacturingDate = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x04); - static constexpr Key kConfigKey_PairingCode = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x05); - static constexpr Key kConfigKey_MfrDeviceICACerts = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x06); - // Weave Config Keys - static constexpr Key kConfigKey_FabricId = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x00); - static constexpr Key kConfigKey_ServiceConfig = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x01); - static constexpr Key kConfigKey_PairedAccountId = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x02); - static constexpr Key kConfigKey_ServiceId = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x03); - static constexpr Key kConfigKey_FabricSecret = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x04); - static constexpr Key kConfigKey_LastUsedEpochKeyId = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x05); - static constexpr Key kConfigKey_FailSafeArmed = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x06); - static constexpr Key kConfigKey_GroupKey = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x07); - static constexpr Key kConfigKey_ProductRevision = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x08); - static constexpr Key kConfigKey_OperationalDeviceId = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x09); - static constexpr Key kConfigKey_OperationalDeviceCert = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x0A); - static constexpr Key kConfigKey_OperationalDeviceICACerts = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x0B); - static constexpr Key kConfigKey_OperationalDevicePrivateKey = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x0C); - - static constexpr Key kConfigKey_GroupKeyBase = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x0D); + static constexpr Key kConfigKey_SerialNum = EFR32ConfigKey(kChipFactory_KeyBase, 0x00); + static constexpr Key kConfigKey_MfrDeviceId = EFR32ConfigKey(kChipFactory_KeyBase, 0x01); + static constexpr Key kConfigKey_MfrDeviceCert = EFR32ConfigKey(kChipFactory_KeyBase, 0x02); + static constexpr Key kConfigKey_MfrDevicePrivateKey = EFR32ConfigKey(kChipFactory_KeyBase, 0x03); + static constexpr Key kConfigKey_ManufacturingDate = EFR32ConfigKey(kChipFactory_KeyBase, 0x04); + static constexpr Key kConfigKey_PairingCode = EFR32ConfigKey(kChipFactory_KeyBase, 0x05); + static constexpr Key kConfigKey_MfrDeviceICACerts = EFR32ConfigKey(kChipFactory_KeyBase, 0x06); + // Chip Config Keys + static constexpr Key kConfigKey_FabricId = EFR32ConfigKey(kChipConfig_KeyBase, 0x00); + static constexpr Key kConfigKey_ServiceConfig = EFR32ConfigKey(kChipConfig_KeyBase, 0x01); + static constexpr Key kConfigKey_PairedAccountId = EFR32ConfigKey(kChipConfig_KeyBase, 0x02); + static constexpr Key kConfigKey_ServiceId = EFR32ConfigKey(kChipConfig_KeyBase, 0x03); + static constexpr Key kConfigKey_FabricSecret = EFR32ConfigKey(kChipConfig_KeyBase, 0x04); + static constexpr Key kConfigKey_LastUsedEpochKeyId = EFR32ConfigKey(kChipConfig_KeyBase, 0x05); + static constexpr Key kConfigKey_FailSafeArmed = EFR32ConfigKey(kChipConfig_KeyBase, 0x06); + static constexpr Key kConfigKey_GroupKey = EFR32ConfigKey(kChipConfig_KeyBase, 0x07); + static constexpr Key kConfigKey_ProductRevision = EFR32ConfigKey(kChipConfig_KeyBase, 0x08); + static constexpr Key kConfigKey_OperationalDeviceId = EFR32ConfigKey(kChipConfig_KeyBase, 0x09); + static constexpr Key kConfigKey_OperationalDeviceCert = EFR32ConfigKey(kChipConfig_KeyBase, 0x0A); + static constexpr Key kConfigKey_OperationalDeviceICACerts = EFR32ConfigKey(kChipConfig_KeyBase, 0x0B); + static constexpr Key kConfigKey_OperationalDevicePrivateKey = EFR32ConfigKey(kChipConfig_KeyBase, 0x0C); + + static constexpr Key kConfigKey_GroupKeyBase = EFR32ConfigKey(kChipConfig_KeyBase, 0x0D); static constexpr Key kConfigKey_GroupKeyMax = - EFR32ConfigKey(kWeaveConfig_KeyBase, 0x1C); // Allows 16 Group Keys to be created. + EFR32ConfigKey(kChipConfig_KeyBase, 0x1C); // Allows 16 Group Keys to be created. // Set key id limits for each group. - static constexpr Key kMinConfigKey_WeaveFactory = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x00); - static constexpr Key kMaxConfigKey_WeaveFactory = EFR32ConfigKey(kWeaveFactory_KeyBase, 0x06); - static constexpr Key kMinConfigKey_WeaveConfig = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x00); - static constexpr Key kMaxConfigKey_WeaveConfig = EFR32ConfigKey(kWeaveConfig_KeyBase, 0x1C); - static constexpr Key kMinConfigKey_WeaveCounter = EFR32ConfigKey(kWeaveCounter_KeyBase, 0x00); - static constexpr Key kMaxConfigKey_WeaveCounter = - EFR32ConfigKey(kWeaveCounter_KeyBase, 0x1F); // Allows 32 Counters to be created. + static constexpr Key kMinConfigKey_ChipFactory = EFR32ConfigKey(kChipFactory_KeyBase, 0x00); + static constexpr Key kMaxConfigKey_ChipFactory = EFR32ConfigKey(kChipFactory_KeyBase, 0x06); + static constexpr Key kMinConfigKey_ChipConfig = EFR32ConfigKey(kChipConfig_KeyBase, 0x00); + static constexpr Key kMaxConfigKey_ChipConfig = EFR32ConfigKey(kChipConfig_KeyBase, 0x1C); + static constexpr Key kMinConfigKey_ChipCounter = EFR32ConfigKey(kChipCounter_KeyBase, 0x00); + static constexpr Key kMaxConfigKey_ChipCounter = + EFR32ConfigKey(kChipCounter_KeyBase, 0x1F); // Allows 32 Counters to be created. - static WEAVE_ERROR Init(void); + static CHIP_ERROR Init(void); // Configuration methods used by the GenericConfigurationManagerImpl<> template. - static WEAVE_ERROR ReadConfigValue(Key key, bool &val); - static WEAVE_ERROR ReadConfigValue(Key key, uint32_t &val); - static WEAVE_ERROR ReadConfigValue(Key key, uint64_t &val); - static WEAVE_ERROR ReadConfigValueStr(Key key, char *buf, size_t bufSize, size_t &outLen); - static WEAVE_ERROR ReadConfigValueBin(Key key, uint8_t *buf, size_t bufSize, size_t &outLen); - static WEAVE_ERROR ReadConfigValueCounter(uint8_t counterIdx, uint32_t &val); - static WEAVE_ERROR WriteConfigValue(Key key, bool val); - static WEAVE_ERROR WriteConfigValue(Key key, uint32_t val); - static WEAVE_ERROR WriteConfigValue(Key key, uint64_t val); - static WEAVE_ERROR WriteConfigValueStr(Key key, const char *str); - static WEAVE_ERROR WriteConfigValueStr(Key key, const char *str, size_t strLen); - static WEAVE_ERROR WriteConfigValueBin(Key key, const uint8_t *data, size_t dataLen); - static WEAVE_ERROR WriteConfigValueCounter(uint8_t counterIdx, uint32_t val); - static WEAVE_ERROR ClearConfigValue(Key key); + static CHIP_ERROR ReadConfigValue(Key key, bool &val); + static CHIP_ERROR ReadConfigValue(Key key, uint32_t &val); + static CHIP_ERROR ReadConfigValue(Key key, uint64_t &val); + static CHIP_ERROR ReadConfigValueStr(Key key, char *buf, size_t bufSize, size_t &outLen); + static CHIP_ERROR ReadConfigValueBin(Key key, uint8_t *buf, size_t bufSize, size_t &outLen); + static CHIP_ERROR ReadConfigValueCounter(uint8_t counterIdx, uint32_t &val); + static CHIP_ERROR WriteConfigValue(Key key, bool val); + static CHIP_ERROR WriteConfigValue(Key key, uint32_t val); + static CHIP_ERROR WriteConfigValue(Key key, uint64_t val); + static CHIP_ERROR WriteConfigValueStr(Key key, const char *str); + static CHIP_ERROR WriteConfigValueStr(Key key, const char *str, size_t strLen); + static CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t *data, size_t dataLen); + static CHIP_ERROR WriteConfigValueCounter(uint8_t counterIdx, uint32_t val); + static CHIP_ERROR ClearConfigValue(Key key); static bool ConfigValueExists(Key key); - static WEAVE_ERROR FactoryResetConfig(void); + static CHIP_ERROR FactoryResetConfig(void); static bool ValidConfigKey(Key key); static void RunConfigUnitTest(void); static void RepackNvm3Flash(void); protected: - using ForEachRecordFunct = std::function; - static WEAVE_ERROR ForEachRecord(Key firstKey, Key lastKey, bool addNewRecord, ForEachRecordFunct funct); + using ForEachRecordFunct = std::function; + static CHIP_ERROR ForEachRecord(Key firstKey, Key lastKey, bool addNewRecord, ForEachRecordFunct funct); private: - static WEAVE_ERROR MapNvm3Error(Ecode_t nvm3Res); + static CHIP_ERROR MapNvm3Error(Ecode_t nvm3Res); }; } // namespace Internal } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip #endif // EFR32_CONFIG_H diff --git a/src/include/platform/EFR32/GroupKeyStoreImpl.h b/src/include/platform/EFR32/GroupKeyStoreImpl.h index 63e1eed732f9d7..a108a82d9a60c8 100644 --- a/src/include/platform/EFR32/GroupKeyStoreImpl.h +++ b/src/include/platform/EFR32/GroupKeyStoreImpl.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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,61 +17,59 @@ /** * @file - * Provides an implementation of the Weave Group Key Store interface + * Provides an implementation of the Chip Group Key Store interface * for platforms based on the Silicon Labs SDK. */ -#include -#include -#include -#include +#include +#include +#include +#include -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { namespace Internal { /** - * An implementation of the Weave GroupKeyStoreBase API for platforms based + * An implementation of the Chip GroupKeyStoreBase API for platforms based * on the Silicon Labs SDK. */ -class GroupKeyStoreImpl final : public ::nl::Weave::Profiles::Security::AppKeys::GroupKeyStoreBase, private EFR32Config +class GroupKeyStoreImpl final : public ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase, private EFR32Config { - using WeaveGroupKey = ::nl::Weave::Profiles::Security::AppKeys::WeaveGroupKey; + using ChipGroupKey = ::chip::Profiles::Security::AppKeys::ChipGroupKey; public: - WEAVE_ERROR Init(); + CHIP_ERROR Init(); - WEAVE_ERROR RetrieveGroupKey(uint32_t keyId, WeaveGroupKey &key) override; - WEAVE_ERROR StoreGroupKey(const WeaveGroupKey &key) override; - WEAVE_ERROR DeleteGroupKey(uint32_t keyId) override; - WEAVE_ERROR DeleteGroupKeysOfAType(uint32_t keyType) override; - WEAVE_ERROR EnumerateGroupKeys(uint32_t keyType, + CHIP_ERROR RetrieveGroupKey(uint32_t keyId, ChipGroupKey &key) override; + CHIP_ERROR StoreGroupKey(const ChipGroupKey &key) override; + CHIP_ERROR DeleteGroupKey(uint32_t keyId) override; + CHIP_ERROR DeleteGroupKeysOfAType(uint32_t keyType) override; + CHIP_ERROR EnumerateGroupKeys(uint32_t keyType, uint32_t *keyIds, uint8_t keyIdsArraySize, uint8_t & keyCount) override; - WEAVE_ERROR Clear(void) override; - WEAVE_ERROR RetrieveLastUsedEpochKeyId(void) override; - WEAVE_ERROR StoreLastUsedEpochKeyId(void) override; + CHIP_ERROR Clear(void) override; + CHIP_ERROR RetrieveLastUsedEpochKeyId(void) override; + CHIP_ERROR StoreLastUsedEpochKeyId(void) override; private: static constexpr size_t kFixedEncodedKeySize = 4U + // key id 4U + // start time / global id 1U; // key data length - static constexpr size_t kMaxEncodedKeySize = kFixedEncodedKeySize + WeaveGroupKey::MaxKeySize; + static constexpr size_t kMaxEncodedKeySize = kFixedEncodedKeySize + ChipGroupKey::MaxKeySize; /* Not used static constexpr uint16_t kGroupKeyFileId = GetFileId(kConfigKey_GroupKey); static constexpr uint16_t kGroupKeyRecordKey = GetRecordKey(kConfigKey_GroupKey); */ - static WEAVE_ERROR EncodeGroupKey(const WeaveGroupKey &key, uint8_t *buf, size_t bufSize, size_t &encodedKeyLen); - static WEAVE_ERROR DecodeGroupKey(const uint8_t *encodedKey, size_t encodedKeyLen, WeaveGroupKey &key); - static WEAVE_ERROR DecodeGroupKeyId(const uint8_t *encodedKey, size_t encodedKeyLen, uint32_t &keyId); + static CHIP_ERROR EncodeGroupKey(const ChipGroupKey &key, uint8_t *buf, size_t bufSize, size_t &encodedKeyLen); + static CHIP_ERROR DecodeGroupKey(const uint8_t *encodedKey, size_t encodedKeyLen, ChipGroupKey &key); + static CHIP_ERROR DecodeGroupKeyId(const uint8_t *encodedKey, size_t encodedKeyLen, uint32_t &keyId); }; } // namespace Internal } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip diff --git a/src/include/platform/EFR32/InetPlatformConfig.h b/src/include/platform/EFR32/InetPlatformConfig.h index 4c8fe1b7ecb6bc..e90cd11c1b9b2f 100644 --- a/src/include/platform/EFR32/InetPlatformConfig.h +++ b/src/include/platform/EFR32/InetPlatformConfig.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 Google LLC. - * 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,7 +17,7 @@ /** * @file - * Platform-specific configuration overrides for the OpenWeave Inet + * Platform-specific configuration overrides for the OpenChip Inet * Layer on EFR32 platforms using the Silicon Labs SDK. * */ diff --git a/src/include/platform/EFR32/NetworkProvisioningServerImpl.h b/src/include/platform/EFR32/NetworkProvisioningServerImpl.h index 2be56af369d51b..87e3ef631e2ea0 100644 --- a/src/include/platform/EFR32/NetworkProvisioningServerImpl.h +++ b/src/include/platform/EFR32/NetworkProvisioningServerImpl.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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. @@ -19,10 +18,9 @@ #ifndef NETWORK_PROVISIONING_SERVER_IMPL_H #define NETWORK_PROVISIONING_SERVER_IMPL_H -#include +#include -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { namespace Internal { @@ -45,11 +43,11 @@ class NetworkProvisioningServerImpl final private: // ===== Members that implement the NetworkProvisioningServer public interface. - WEAVE_ERROR _Init(void); + CHIP_ERROR _Init(void); // ===== Members for internal use by the following friends. - friend ::nl::Weave::DeviceLayer::Internal::NetworkProvisioningServer &NetworkProvisioningSvr(void); + friend ::chip::DeviceLayer::Internal::NetworkProvisioningServer &NetworkProvisioningSvr(void); friend NetworkProvisioningServerImpl & NetworkProvisioningSvrImpl(void); static NetworkProvisioningServerImpl sInstance; @@ -79,7 +77,6 @@ inline NetworkProvisioningServerImpl &NetworkProvisioningSvrImpl(void) } // namespace Internal } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip #endif // NETWORK_PROVISIONING_SERVER_IMPL_H diff --git a/src/include/platform/EFR32/PlatformManagerImpl.h b/src/include/platform/EFR32/PlatformManagerImpl.h index 761c702af83e14..bdd094ccdf03b8 100644 --- a/src/include/platform/EFR32/PlatformManagerImpl.h +++ b/src/include/platform/EFR32/PlatformManagerImpl.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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. @@ -25,10 +24,9 @@ #ifndef PLATFORM_MANAGER_IMPL_H #define PLATFORM_MANAGER_IMPL_H -#include +#include -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { /** @@ -53,7 +51,7 @@ class PlatformManagerImpl final : public PlatformManager, private: // ===== Methods that implement the PlatformManager abstract interface. - WEAVE_ERROR _InitWeaveStack(void); + CHIP_ERROR _InitChipStack(void); // ===== Members for internal use by the following friends. @@ -69,7 +67,7 @@ class PlatformManagerImpl final : public PlatformManager, /** * Returns the public interface of the PlatformManager singleton object. * - * Weave applications should use this to access features of the PlatformManager object + * Chip applications should use this to access features of the PlatformManager object * that are common to all platforms. */ inline PlatformManager &PlatformMgr(void) @@ -80,7 +78,7 @@ inline PlatformManager &PlatformMgr(void) /** * Returns the platform-specific implementation of the PlatformManager singleton object. * - * Weave applications can use this to gain access to features of the PlatformManager + * Chip applications can use this to gain access to features of the PlatformManager * that are specific to the ESP32 platform. */ inline PlatformManagerImpl &PlatformMgrImpl(void) @@ -89,7 +87,6 @@ inline PlatformManagerImpl &PlatformMgrImpl(void) } } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip #endif // PLATFORM_MANAGER_IMPL_H diff --git a/src/include/platform/EFR32/SoftwareUpdateManagerImpl.h b/src/include/platform/EFR32/SoftwareUpdateManagerImpl.h index c5438759f2fd02..5927d36853aba4 100644 --- a/src/include/platform/EFR32/SoftwareUpdateManagerImpl.h +++ b/src/include/platform/EFR32/SoftwareUpdateManagerImpl.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 Google LLC. - * 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. @@ -19,13 +18,12 @@ #ifndef SOFTWARE_UPDATE_MANAGER_IMPL_H #define SOFTWARE_UPDATE_MANAGER_IMPL_H -#if WEAVE_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER +#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER -#include -#include +#include +#include -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { /** @@ -51,7 +49,7 @@ class SoftwareUpdateManagerImpl final : public SoftwareUpdateManager, public: // ===== Members for internal use by the following friends. - friend ::nl::Weave::DeviceLayer::SoftwareUpdateManager &SoftwareUpdateMgr(void); + friend ::chip::DeviceLayer::SoftwareUpdateManager &SoftwareUpdateMgr(void); friend SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void); static SoftwareUpdateManagerImpl sInstance; @@ -59,7 +57,7 @@ class SoftwareUpdateManagerImpl final : public SoftwareUpdateManager, private: // ===== Members that implement the SoftwareUpdateManager abstract interface. - WEAVE_ERROR _Init(void); + CHIP_ERROR _Init(void); }; /** @@ -85,8 +83,7 @@ inline SoftwareUpdateManagerImpl &SoftwareUpdateMgrImpl(void) } } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip -#endif // WEAVE_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER +#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER #endif // SOFTWARE_UPDATE_MANAGER_IMPL_H diff --git a/src/include/platform/EFR32/SystemPlatformConfig.h b/src/include/platform/EFR32/SystemPlatformConfig.h index ff765daf3994e7..020ac8c4f6c3d0 100644 --- a/src/include/platform/EFR32/SystemPlatformConfig.h +++ b/src/include/platform/EFR32/SystemPlatformConfig.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 Google LLC. - * 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,7 +17,7 @@ /** * @file - * Platform-specific configuration overrides for the OpenWeave System + * Platform-specific configuration overrides for the OpenChip System * Layer on Silcon Labs EFR32 Platforms. * */ @@ -28,36 +27,34 @@ #include -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { -struct WeaveDeviceEvent; +struct ChipDeviceEvent; } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip // ==================== Platform Adaptations ==================== -#define WEAVE_SYSTEM_CONFIG_POSIX_LOCKING 0 -#define WEAVE_SYSTEM_CONFIG_FREERTOS_LOCKING 0 -#define WEAVE_SYSTEM_CONFIG_NO_LOCKING 1 -#define WEAVE_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 1 -#define WEAVE_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 -#define WEAVE_SYSTEM_CONFIG_LWIP_EVENT_TYPE int -#define WEAVE_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE const struct ::nl::Weave::DeviceLayer::WeaveDeviceEvent * - -#define WEAVE_SYSTEM_CONFIG_ERROR_TYPE int32_t -#define WEAVE_SYSTEM_CONFIG_NO_ERROR 0 -#define WEAVE_SYSTEM_CONFIG_ERROR_MIN 7000000 -#define WEAVE_SYSTEM_CONFIG_ERROR_MAX 7000999 -#define _WEAVE_SYSTEM_CONFIG_ERROR(e) (WEAVE_SYSTEM_CONFIG_ERROR_MIN + (e)) -#define WEAVE_SYSTEM_LWIP_ERROR_MIN 3000000 -#define WEAVE_SYSTEM_LWIP_ERROR_MAX 3000999 +#define CHIP_SYSTEM_CONFIG_POSIX_LOCKING 0 +#define CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING 0 +#define CHIP_SYSTEM_CONFIG_NO_LOCKING 1 +#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 1 +#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 +#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE int +#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * + +#define CHIP_SYSTEM_CONFIG_ERROR_TYPE int32_t +#define CHIP_SYSTEM_CONFIG_NO_ERROR 0 +#define CHIP_SYSTEM_CONFIG_ERROR_MIN 7000000 +#define CHIP_SYSTEM_CONFIG_ERROR_MAX 7000999 +#define _CHIP_SYSTEM_CONFIG_ERROR(e) (CHIP_SYSTEM_CONFIG_ERROR_MIN + (e)) +#define CHIP_SYSTEM_LWIP_ERROR_MIN 3000000 +#define CHIP_SYSTEM_LWIP_ERROR_MAX 3000999 // ========== Platform-specific Configuration Overrides ========= -#ifndef WEAVE_SYSTEM_CONFIG_NUM_TIMERS -#define WEAVE_SYSTEM_CONFIG_NUM_TIMERS 16 -#endif // WEAVE_SYSTEM_CONFIG_NUM_TIMERS +#ifndef CHIP_SYSTEM_CONFIG_NUM_TIMERS +#define CHIP_SYSTEM_CONFIG_NUM_TIMERS 16 +#endif // CHIP_SYSTEM_CONFIG_NUM_TIMERS #endif // SYSTEM_PLATFORM_CONFIG_H diff --git a/src/include/platform/EFR32/ThreadStackManagerImpl.h b/src/include/platform/EFR32/ThreadStackManagerImpl.h index 5ca73409dd254d..f17101d5cd8a0d 100644 --- a/src/include/platform/EFR32/ThreadStackManagerImpl.h +++ b/src/include/platform/EFR32/ThreadStackManagerImpl.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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. @@ -26,15 +25,12 @@ #ifndef THREAD_STACK_MANAGER_IMPL_H #define THREAD_STACK_MANAGER_IMPL_H -#include -#include -#include -#include +#include +#include extern "C" void otSysEventSignalPending(void); -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { class ThreadStackManager; @@ -71,17 +67,17 @@ class ThreadStackManagerImpl final // ===== Platform-specific members that may be accessed directly by the application. using ThreadStackManager::InitThreadStack; - WEAVE_ERROR InitThreadStack(otInstance *otInst); + CHIP_ERROR InitThreadStack(otInstance *otInst); private: // ===== Methods that implement the ThreadStackManager abstract interface. - WEAVE_ERROR _InitThreadStack(void); + CHIP_ERROR _InitThreadStack(void); // ===== Members for internal use by the following friends. - friend ThreadStackManager & ::nl::Weave::DeviceLayer::ThreadStackMgr(void); - friend ThreadStackManagerImpl & ::nl::Weave::DeviceLayer::ThreadStackMgrImpl(void); + friend ThreadStackManager & ::chip::DeviceLayer::ThreadStackMgr(void); + friend ThreadStackManagerImpl & ::chip::DeviceLayer::ThreadStackMgrImpl(void); friend int Internal::GetEntropy_EFR32(uint8_t *buf, size_t bufSize); static ThreadStackManagerImpl sInstance; @@ -96,7 +92,7 @@ class ThreadStackManagerImpl final /** * Returns the public interface of the ThreadStackManager singleton object. * - * Weave applications should use this to access features of the ThreadStackManager object + * Chip applications should use this to access features of the ThreadStackManager object * that are common to all platforms. */ inline ThreadStackManager &ThreadStackMgr(void) @@ -107,7 +103,7 @@ inline ThreadStackManager &ThreadStackMgr(void) /** * Returns the platform-specific implementation of the ThreadStackManager singleton object. * - * Weave applications can use this to gain access to features of the ThreadStackManager + * Chip applications can use this to gain access to features of the ThreadStackManager * that are specific to EFR32 platforms. */ inline ThreadStackManagerImpl &ThreadStackMgrImpl(void) @@ -116,7 +112,6 @@ inline ThreadStackManagerImpl &ThreadStackMgrImpl(void) } } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip #endif // THREAD_STACK_MANAGER_IMPL_H diff --git a/src/include/platform/EFR32/WarmPlatformConfig.h b/src/include/platform/EFR32/WarmPlatformConfig.h index d60755163aa513..6527495315d4ec 100644 --- a/src/include/platform/EFR32/WarmPlatformConfig.h +++ b/src/include/platform/EFR32/WarmPlatformConfig.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 Google LLC. - * 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,7 +17,7 @@ /** * @file - * Platform-specific configuration overrides for the Weave + * Platform-specific configuration overrides for the Chip * Addressing and Routing Module (WARM) on EFR32 platforms * using the Silcon Labs SDK. * diff --git a/src/include/platform/EFR32/WeaveDevicePlatformConfig.h b/src/include/platform/EFR32/WeaveDevicePlatformConfig.h deleted file mode 100644 index 6b697e41a746ff..00000000000000 --- a/src/include/platform/EFR32/WeaveDevicePlatformConfig.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * - * Copyright (c) 2019 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 - * Platform-specific configuration overrides for the Weave Device Layer - * on EFR32 platforms using the Silicon Labs SDK. - */ - -#ifndef WEAVE_DEVICE_PLATFORM_CONFIG_H -#define WEAVE_DEVICE_PLATFORM_CONFIG_H - -// ==================== Platform Adaptations ==================== - -#define WEAVE_DEVICE_CONFIG_EFR32_NVM3_ERROR_MIN 12000000 -#define WEAVE_DEVICE_CONFIG_EFR32_BLE_ERROR_MIN 13000000 - -#define WEAVE_DEVICE_CONFIG_ENABLE_WIFI_STATION 0 -#define WEAVE_DEVICE_CONFIG_ENABLE_WIFI_AP 0 - -#define WEAVE_DEVICE_CONFIG_ENABLE_THREAD 1 -#define WEAVE_DEVICE_CONFIG_ENABLE_WOBLE 1 - -#define WEAVE_DEVICE_CONFIG_ENABLE_WEAVE_TIME_SERVICE_TIME_SYNC 1 -#define WEAVE_DEVICE_CONFIG_ENABLE_SERVICE_DIRECTORY_TIME_SYNC 0 - -#define WEAVE_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY 2 -#define WEAVE_DEVICE_CONFIG_PERSISTED_STORAGE_PROD_EIDC_KEY 3 -#define WEAVE_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY 4 -#define WEAVE_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY 5 - -// ========== Platform-specific Configuration ========= - -// These are configuration options that are unique to the EFR32 platform. -// These can be overridden by the application as needed. -/** - * @def WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE - * - * The maximum size of any log message. - */ -#ifndef WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE -#define WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE 150 -#endif // WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE - -// -------------- EFR32 NVM3 Storage Configuration ------------- - -/** - * @def WEAVE_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS - * - * @brief - * Configures the size of the nvm3 cache and should be set >= the - * maximum number of Weave Config objects, e.g... - * Factory configs[5], System configs[23], Counter configs[32] + margin[4] = 64. - * - */ -#ifndef WEAVE_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS -#define WEAVE_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS 64 -#endif // WEAVE_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS - -/** - * @def WEAVE_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE - * - * @brief - * This determines the max size for any Weave nvm3 object - * (e.g. for Config 'string' or 'binary' types). - */ -#ifndef WEAVE_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE -#define WEAVE_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE 1000 -#endif // WEAVE_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE - -/** - * @def WEAVE_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE - * - * @brief - * This determines the Flash size used for nvm3 data storage:- - * (assuming 2k Flash page size) => Total Flash size for nvm3: 8 * 2k = 16k - * The total size should allow sufficient margin for wear-levelling and - * repacking. - */ -#ifndef WEAVE_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE -#define WEAVE_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE 8 -#endif // WEAVE_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE - -// ========== Platform-specific Configuration Overrides ========= - -#ifndef WEAVE_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY -#define WEAVE_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY (configTIMER_TASK_PRIORITY - 1) -#endif // WEAVE_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY - -#ifndef WEAVE_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY -#define WEAVE_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY (WEAVE_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY - 1) -#endif // WEAVE_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY - -#ifndef WEAVE_DEVICE_CONFIG_BLE_APP_TASK_PRIORITY -#define WEAVE_DEVICE_CONFIG_BLE_APP_TASK_PRIORITY (WEAVE_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY - 1) -#endif // WEAVE_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY - -#ifndef WEAVE_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE -#define WEAVE_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE 1024 -#endif // WEAVE_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE - -#ifndef WEAVE_DEVICE_CONFIG_WEAVE_TASK_STACK_SIZE -#define WEAVE_DEVICE_CONFIG_WEAVE_TASK_STACK_SIZE 8192 -#endif // WEAVE_DEVICE_CONFIG_WEAVE_TASK_STACK_SIZE - -#ifndef WEAVE_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE -#define WEAVE_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE 8192 -#endif // WEAVE_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE - -#define WEAVE_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY 0 -#define WEAVE_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY 1 -#define WEAVE_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL 0 -#define WEAVE_DEVICE_CONFIG_ENABLE_TUNNEL_TELEMETRY 0 - -#ifndef WEAVE_DEVICE_CONFIG_BLE_APP_TASK_NAME -#define WEAVE_DEVICE_CONFIG_BLE_APP_TASK_NAME "Bluetooth App Task" -#endif // WEAVE_DEVICE_CONFIG_BLE_APP_TASK_NAME - -#endif // WEAVE_DEVICE_PLATFORM_CONFIG_H diff --git a/src/include/platform/EFR32/WeavePlatformConfig.h b/src/include/platform/EFR32/WeavePlatformConfig.h deleted file mode 100644 index 59876904196bde..00000000000000 --- a/src/include/platform/EFR32/WeavePlatformConfig.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * - * Copyright (c) 2019 Google LLC. - * 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 - * Platform-specific configuration overrides for OpenWeave on - * Silcon Labs EFR32 platforms. - */ - -#ifndef WEAVE_PLATFORM_CONFIG_H -#define WEAVE_PLATFORM_CONFIG_H - -#include - -// ==================== General Platform Adaptations ==================== - -#define WEAVE_CONFIG_ERROR_TYPE int32_t -#define WEAVE_CONFIG_NO_ERROR 0 -#define WEAVE_CONFIG_ERROR_MIN 4000000 -#define WEAVE_CONFIG_ERROR_MAX 4000999 - -#define ASN1_CONFIG_ERROR_TYPE int32_t -#define ASN1_CONFIG_NO_ERROR 0 -#define ASN1_CONFIG_ERROR_MIN 5000000 -#define ASN1_CONFIG_ERROR_MAX 5000999 - -#define WeaveDie() abort() - -#define WEAVE_CONFIG_ENABLE_TUNNELING 0 -#define WEAVE_CONFIG_MAX_TUNNELS 0 -#define WEAVE_CONFIG_ENABLE_SERVICE_DIRECTORY 0 - -#define WEAVE_CONFIG_PERSISTED_STORAGE_KEY_TYPE uint8_t -#define WEAVE_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_ID 1 -#define WEAVE_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH 2 - -#define WEAVE_CONFIG_TIME_ENABLE_CLIENT 1 -#define WEAVE_CONFIG_TIME_ENABLE_SERVER 0 - -// ==================== Security Adaptations ==================== - -#define WEAVE_CONFIG_USE_OPENSSL_ECC 0 -#define WEAVE_CONFIG_USE_MICRO_ECC 1 - -#define WEAVE_CONFIG_HASH_IMPLEMENTATION_OPENSSL 0 -#define WEAVE_CONFIG_HASH_IMPLEMENTATION_MINCRYPT 1 -#define WEAVE_CONFIG_HASH_IMPLEMENTATION_MBEDTLS 0 -#define WEAVE_CONFIG_HASH_IMPLEMENTATION_PLATFORM 0 - -// FIXME: EFR32 set to MBED-TLS (But this is third-party repo in OpenWeave, not SDK) - -#define WEAVE_CONFIG_AES_IMPLEMENTATION_OPENSSL 0 -#define WEAVE_CONFIG_AES_IMPLEMENTATION_AESNI 0 -#define WEAVE_CONFIG_AES_IMPLEMENTATION_MBEDTLS 1 -#define WEAVE_CONFIG_AES_IMPLEMENTATION_PLATFORM 0 - -// FIXME: EFR32 currently set to Nest (Does this use Entropy.cpp ?) - -#define WEAVE_CONFIG_RNG_IMPLEMENTATION_OPENSSL 0 -#define WEAVE_CONFIG_RNG_IMPLEMENTATION_NESTDRBG 1 -#define WEAVE_CONFIG_RNG_IMPLEMENTATION_PLATFORM 0 - -#define WEAVE_CONFIG_ENABLE_PASE_INITIATOR 0 -#define WEAVE_CONFIG_ENABLE_PASE_RESPONDER 1 -#define WEAVE_CONFIG_ENABLE_CASE_INITIATOR 1 - -#define WEAVE_CONFIG_SUPPORT_PASE_CONFIG0 0 -#define WEAVE_CONFIG_SUPPORT_PASE_CONFIG1 0 -#define WEAVE_CONFIG_SUPPORT_PASE_CONFIG2 0 -#define WEAVE_CONFIG_SUPPORT_PASE_CONFIG3 0 -#define WEAVE_CONFIG_SUPPORT_PASE_CONFIG4 1 - -#define WEAVE_CONFIG_ENABLE_KEY_EXPORT_INITIATOR 0 - -#define WEAVE_CONFIG_ENABLE_PROVISIONING_BUNDLE_SUPPORT 0 - -// ==================== General Configuration Overrides ==================== - -#ifndef WEAVE_CONFIG_MAX_PEER_NODES -#define WEAVE_CONFIG_MAX_PEER_NODES 16 -#endif // WEAVE_CONFIG_MAX_PEER_NODES - -#ifndef WEAVE_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS -#define WEAVE_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS 16 -#endif // WEAVE_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS - -#ifndef WEAVE_CONFIG_MAX_EXCHANGE_CONTEXTS -#define WEAVE_CONFIG_MAX_EXCHANGE_CONTEXTS 8 -#endif // WEAVE_CONFIG_MAX_EXCHANGE_CONTEXTS - -#ifndef WEAVE_CONFIG_WRMP_TIMER_DEFAULT_PERIOD -#define WEAVE_CONFIG_WRMP_TIMER_DEFAULT_PERIOD 50 -#endif // WEAVE_CONFIG_WRMP_TIMER_DEFAULT_PERIOD - -#ifndef WEAVE_LOG_FILTERING -#define WEAVE_LOG_FILTERING 0 -#endif // WEAVE_LOG_FILTERING - -#ifndef WEAVE_CONFIG_MAX_INTERFACES -#define WEAVE_CONFIG_MAX_INTERFACES 4 -#endif // WEAVE_CONFIG_MAX_INTERFACES - -#ifndef WEAVE_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS -#define WEAVE_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS 4 -#endif // WEAVE_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS - -// ==================== Security Configuration Overrides ==================== - -#ifndef WEAVE_CONFIG_MAX_APPLICATION_GROUPS -#define WEAVE_CONFIG_MAX_APPLICATION_GROUPS 4 -#endif // WEAVE_CONFIG_MAX_APPLICATION_GROUPS - -#ifndef WEAVE_CONFIG_DEBUG_CERT_VALIDATION -#define WEAVE_CONFIG_DEBUG_CERT_VALIDATION 0 -#endif // WEAVE_CONFIG_DEBUG_CERT_VALIDATION - -#ifndef WEAVE_CONFIG_ENABLE_CASE_RESPONDER -#define WEAVE_CONFIG_ENABLE_CASE_RESPONDER 1 -#endif // WEAVE_CONFIG_ENABLE_CASE_RESPONDER - -// ==================== WDM Configuration Overrides ==================== - -#ifndef WDM_MAX_NUM_SUBSCRIPTION_CLIENTS -#define WDM_MAX_NUM_SUBSCRIPTION_CLIENTS 2 -#endif // WDM_MAX_NUM_SUBSCRIPTION_CLIENTS - -#ifndef WDM_MAX_NUM_SUBSCRIPTION_HANDLERS -#define WDM_MAX_NUM_SUBSCRIPTION_HANDLERS 2 -#endif // WDM_MAX_NUM_SUBSCRIPTION_HANDLERS - -#ifndef WDM_PUBLISHER_MAX_NOTIFIES_IN_FLIGHT -#define WDM_PUBLISHER_MAX_NOTIFIES_IN_FLIGHT 2 -#endif // WDM_PUBLISHER_MAX_NOTIFIES_IN_FLIGHT - -#endif /* WEAVE_PLATFORM_CONFIG_H */ diff --git a/src/include/platform/EFR32/efr32-weave-mbedtls-config.h b/src/include/platform/EFR32/efr32-weave-mbedtls-config.h index 7fe934c2a4ec5b..141e4fe1a4fe82 100644 --- a/src/include/platform/EFR32/efr32-weave-mbedtls-config.h +++ b/src/include/platform/EFR32/efr32-weave-mbedtls-config.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 Google LLC. - * 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. diff --git a/src/include/platform/EFR32/freertos_bluetooth.h b/src/include/platform/EFR32/freertos_bluetooth.h index 9321ec3ed8e827..eae82717551233 100644 --- a/src/include/platform/EFR32/freertos_bluetooth.h +++ b/src/include/platform/EFR32/freertos_bluetooth.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2020 Google LLC. - * 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. diff --git a/src/include/platform/EFR32/gatt.xml b/src/include/platform/EFR32/gatt.xml index 4b985a085973d5..edf9706b313144 100644 --- a/src/include/platform/EFR32/gatt.xml +++ b/src/include/platform/EFR32/gatt.xml @@ -1,8 +1,7 @@ - + Abstract: The generic_access service contains generic information about the device. All available Characteristics are readonly. - + Empty Example - + Abstract: The external appearance of this device. The values are composed of a category (10-bits) and sub-categories (6-bits). @@ -38,25 +37,25 @@ - + Abstract: The Device Information Service exposes manufacturer and/or vendor information about a device. Summary: This service exposes manufacturer information about a device. The Device Information Service is instantiated as a Primary Service. Only one instance of the Device Information Service is exposed on a device. - + Abstract: The value of this characteristic is a UTF-8 string representing the name of the manufacturer of the device. Silicon Labs - + Abstract: The value of this characteristic is a UTF-8 string representing the model number assigned by the device vendor. Blue Gecko - + Abstract: The SYSTEM ID characteristic consists of a structure with two fields. The first field are the LSOs and the second field contains the MSOs. This is a 64-bit structure which consists of a 40-bit manufacturer-defined identifier concatenated with a 24 bit unique Organizationally Unique Identifier (OUI). The OUI is issued by the IEEE Registration Authority (http://standards.ieee.org/regauth/index.html) and is required to be used in accordance with IEEE Standard 802-2001.6 while the least significant 40 bits are manufacturer defined. If System ID generated based on a Bluetooth Device Address, it is required to be done as follows. System ID and the Bluetooth Device Address have a very similar structure: a Bluetooth Device Address is 48 bits in length and consists of a 24 bit Company Assigned Identifier (manufacturer defined identifier) concatenated with a 24 bit Company Identifier (OUI). In order to encapsulate a Bluetooth Device Address as System ID, the Company Identifier is concatenated with 0xFFFE followed by the Company Assigned Identifier of the Bluetooth Address. For more guidelines related to EUI-64, refer to http://standards.ieee.org/develop/regauth/tut/eui64.pdf. Examples: If the system ID is based of a Bluetooth Device Address with a Company Identifier (OUI) is 0x123456 and the Company Assigned Identifier is 0x9ABCDE, then the System Identifier is required to be 0x123456FFFE9ABCDE. @@ -64,11 +63,11 @@ - + Abstract: The Silicon Labs OTA Service enables over-the-air firmware update of the device. - + Abstract: Silicon Labs OTA Control. @@ -76,18 +75,18 @@ - + Custom service - + Custom characteristic 0x00 - + Custom characteristic diff --git a/src/include/platform/EFR32/gatt_db.h b/src/include/platform/EFR32/gatt_db.h index cb35f90cb01dda..281d4d1aab78cf 100644 --- a/src/include/platform/EFR32/gatt_db.h +++ b/src/include/platform/EFR32/gatt_db.h @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2020 Google LLC. - * 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. diff --git a/src/include/platform/internal/testing/ConfigUnitTest.h b/src/include/platform/internal/testing/ConfigUnitTest.h new file mode 100644 index 00000000000000..11a0c62df38c27 --- /dev/null +++ b/src/include/platform/internal/testing/ConfigUnitTest.h @@ -0,0 +1,205 @@ +/* + * + * + * + * 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. + */ + +#ifndef CHIP_DEVICE_CONFIG_UNIT_TEST_H +#define CHIP_DEVICE_CONFIG_UNIT_TEST_H + +#include + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +template +void RunConfigUnitTest(void) +{ + CHIP_ERROR err; + + // ===== Test 1: Store and read uint32_t + { + uint32_t v = 42; + + err = ConfigClass::WriteConfigValue(ConfigClass::kConfigKey_LastUsedEpochKeyId, v); + VerifyOrDie(err == CHIP_NO_ERROR); + + v = 0; + + err = ConfigClass::ReadConfigValue(ConfigClass::kConfigKey_LastUsedEpochKeyId, v); + VerifyOrDie(err == CHIP_NO_ERROR); + + VerifyOrDie(v == 42); + } + + // ===== Test 2: Store and read uint64_t + { + uint64_t v = 9872349687345; + + err = ConfigClass::WriteConfigValue(ConfigClass::kConfigKey_MfrDeviceId, v); + VerifyOrDie(err == CHIP_NO_ERROR); + + v = 0; + + err = ConfigClass::ReadConfigValue(ConfigClass::kConfigKey_MfrDeviceId, v); + VerifyOrDie(err == CHIP_NO_ERROR); + + VerifyOrDie(v == 9872349687345); + } + + // ===== Test 3: Store and read bool value + { + bool v = true; + + err = ConfigClass::WriteConfigValue(ConfigClass::kConfigKey_FailSafeArmed, v); + VerifyOrDie(err == CHIP_NO_ERROR); + + v = false; + + err = ConfigClass::ReadConfigValue(ConfigClass::kConfigKey_FailSafeArmed, v); + VerifyOrDie(err == CHIP_NO_ERROR); + + VerifyOrDie(v == true); + } + + // ===== Test 4: Clear value + { + uint32_t v; + + err = ConfigClass::ClearConfigValue(ConfigClass::kConfigKey_LastUsedEpochKeyId); + VerifyOrDie(err == CHIP_NO_ERROR); + + err = ConfigClass::ReadConfigValue(ConfigClass::kConfigKey_LastUsedEpochKeyId, v); + VerifyOrDie(err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); + } + + // ===== Test 5: Store and read string + { + const static char kTestString1[] = "This is a test"; + const static char kTestString2[] = ""; + char buf[64]; + size_t strLen; + + err = ConfigClass::WriteConfigValueStr(ConfigClass::kConfigKey_PairedAccountId, kTestString1); + VerifyOrDie(err == CHIP_NO_ERROR); + + err = ConfigClass::ReadConfigValueStr(ConfigClass::kConfigKey_PairedAccountId, buf, sizeof(buf), strLen); + VerifyOrDie(err == CHIP_NO_ERROR); + + VerifyOrDie(strLen == strlen(kTestString1)); + VerifyOrDie(memcmp(buf, kTestString1, strLen + 1) == 0); + + err = ConfigClass::WriteConfigValueStr(ConfigClass::kConfigKey_PairedAccountId, kTestString2); + VerifyOrDie(err == CHIP_NO_ERROR); + + err = ConfigClass::ReadConfigValueStr(ConfigClass::kConfigKey_PairedAccountId, buf, sizeof(buf), strLen); + VerifyOrDie(err == CHIP_NO_ERROR); + + VerifyOrDie(strLen == strlen(kTestString2)); + VerifyOrDie(memcmp(buf, kTestString2, strLen + 1) == 0); + } + + // ===== Test 6: Clear string + { + char buf[64]; + size_t strLen; + + err = ConfigClass::WriteConfigValueStr(ConfigClass::kConfigKey_PairedAccountId, NULL); + VerifyOrDie(err == CHIP_NO_ERROR); + + err = ConfigClass::ReadConfigValueStr(ConfigClass::kConfigKey_PairedAccountId, buf, sizeof(buf), strLen); + VerifyOrDie(err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); + } + + // ===== Test 7: Store and read binary data + { + const static uint8_t kTestData[] = + { + 0xD5, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x30, 0x01, 0x08, 0x79, 0x55, 0x9F, 0x15, 0x1F, 0x66, + 0x3D, 0x8F, 0x24, 0x02, 0x05, 0x37, 0x03, 0x27, 0x13, 0x02, 0x00, 0x00, 0xEE, 0xEE, 0x30, 0xB4, + 0x18, 0x18, 0x26, 0x04, 0x80, 0x41, 0x1B, 0x23, 0x26, 0x05, 0x7F, 0xFF, 0xFF, 0x52, 0x37, 0x06, + 0x27, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x30, 0xB4, 0x18, 0x18, 0x24, 0x07, 0x02, 0x26, 0x08, + 0x25, 0x00, 0x5A, 0x23, 0x30, 0x0A, 0x39, 0x04, 0x9E, 0xC7, 0x77, 0xC5, 0xA4, 0x13, 0x31, 0xF7, + 0x72, 0x2E, 0x27, 0xC2, 0x86, 0x3D, 0xC5, 0x2E, 0xD5, 0xD2, 0x3C, 0xCF, 0x7E, 0x06, 0xE3, 0x48, + 0x53, 0x87, 0xE8, 0x4D, 0xB0, 0x27, 0x07, 0x58, 0x4A, 0x38, 0xB4, 0xF3, 0xB2, 0x47, 0x94, 0x45, + 0x58, 0x65, 0x80, 0x08, 0x17, 0x6B, 0x8E, 0x4F, 0x07, 0x41, 0xA3, 0x3D, 0x5D, 0xCE, 0x76, 0x86, + 0x35, 0x83, 0x29, 0x01, 0x18, 0x35, 0x82, 0x29, 0x01, 0x24, 0x02, 0x05, 0x18, 0x35, 0x84, 0x29, + 0x01, 0x36, 0x02, 0x04, 0x02, 0x04, 0x01, 0x18, 0x18, 0x35, 0x81, 0x30, 0x02, 0x08, 0x42, 0xBD, + 0x2C, 0x6B, 0x5B, 0x3A, 0x18, 0x16, 0x18, 0x35, 0x80, 0x30, 0x02, 0x08, 0x44, 0xE3, 0x40, 0x38, + 0xA9, 0xD4, 0xB5, 0xA7, 0x18, 0x35, 0x0C, 0x30, 0x01, 0x19, 0x00, 0xA6, 0x5D, 0x54, 0xF5, 0xAE, + 0x5D, 0x63, 0xEB, 0x69, 0xD8, 0xDB, 0xCB, 0xE2, 0x20, 0x0C, 0xD5, 0x6F, 0x43, 0x5E, 0x96, 0xA8, + 0x54, 0xB2, 0x74, 0x30, 0x02, 0x19, 0x00, 0xE0, 0x37, 0x02, 0x8B, 0xB3, 0x04, 0x06, 0xDD, 0xBD, + 0x28, 0xAA, 0xC4, 0xF1, 0xFF, 0xFB, 0xB1, 0xD4, 0x1C, 0x78, 0x40, 0xDA, 0x2C, 0xD8, 0x40, 0x18, + 0x18, + }; + uint8_t buf[512]; + size_t dataLen; + + err = ConfigClass::WriteConfigValueBin(ConfigClass::kConfigKey_MfrDeviceCert, kTestData, sizeof(kTestData)); + VerifyOrDie(err == CHIP_NO_ERROR); + + err = ConfigClass::ReadConfigValueBin(ConfigClass::kConfigKey_MfrDeviceCert, buf, sizeof(buf), dataLen); + VerifyOrDie(err == CHIP_NO_ERROR); + + VerifyOrDie(dataLen == sizeof(kTestData)); + VerifyOrDie(memcmp(buf, kTestData, dataLen) == 0); + } + + // ===== Test 8: Clear binary data + { + uint8_t buf[512]; + size_t dataLen; + + err = ConfigClass::WriteConfigValueBin(ConfigClass::kConfigKey_MfrDeviceCert, NULL, 0); + VerifyOrDie(err == CHIP_NO_ERROR); + + err = ConfigClass::ReadConfigValueBin(ConfigClass::kConfigKey_MfrDeviceCert, buf, sizeof(buf), dataLen); + VerifyOrDie(err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); + } + + // ===== Test 9: Config value exists + { + bool v; + + v = ConfigClass::ConfigValueExists(ConfigClass::kConfigKey_MfrDeviceId); + VerifyOrDie(v == true); + + v = ConfigClass::ConfigValueExists(ConfigClass::kConfigKey_FailSafeArmed); + VerifyOrDie(v == true); + + v = ConfigClass::ConfigValueExists(ConfigClass::kConfigKey_MfrDeviceCert); + VerifyOrDie(v == false); + } + + // ===== Test 10: Factory reset config + { + bool v; + + err = ConfigClass::FactoryResetConfig(); + VerifyOrDie(err == CHIP_NO_ERROR); + + v = ConfigClass::ConfigValueExists(ConfigClass::kConfigKey_MfrDeviceId); + VerifyOrDie(v == true); + + v = ConfigClass::ConfigValueExists(ConfigClass::kConfigKey_FailSafeArmed); + VerifyOrDie(v == false); + } +} + +} // namespace internal +} // namespace DeviceLayer +} // namespace chip + +#endif // CHIP_DEVICE_CONFIG_UNIT_TEST_H diff --git a/src/platform/EFR32/BLEManagerImpl.cpp b/src/platform/EFR32/BLEManagerImpl.cpp index 28142b1e194e9d..56aebded005238 100644 --- a/src/platform/EFR32/BLEManagerImpl.cpp +++ b/src/platform/EFR32/BLEManagerImpl.cpp @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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. @@ -22,37 +21,36 @@ * for the Silicon Labs EFR32 platforms. */ -#include -#include -#include +#include +#include +#include #include -#if WEAVE_DEVICE_CONFIG_ENABLE_WOBLE +#if CHIP_DEVICE_CONFIG_ENABLE_WOBLE -#include +#include #include "rtos_gecko.h" -using namespace ::nl; -using namespace ::nl::Ble; +using namespace ::chip; +using namespace ::chip::Ble; -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { namespace Internal { namespace { -#define WEAVE_ADV_DATA_TYPE_FLAGS 0x01 -#define WEAVE_ADV_DATA_TYPE_UUID 0x03 -#define WEAVE_ADV_DATA_TYPE_NAME 0x09 -#define WEAVE_ADV_DATA_TYPE_SERVICE_DATA 0x16 +#define CHIP_ADV_DATA_TYPE_FLAGS 0x01 +#define CHIP_ADV_DATA_TYPE_UUID 0x03 +#define CHIP_ADV_DATA_TYPE_NAME 0x09 +#define CHIP_ADV_DATA_TYPE_SERVICE_DATA 0x16 -#define WEAVE_ADV_DATA_FLAGS 0x06 -#define WEAVE_ADV_WOBLE_SERVICE_HANDLE 0 +#define CHIP_ADV_DATA_FLAGS 0x06 +#define CHIP_ADV_WOBLE_SERVICE_HANDLE 0 -#define WEAVE_ADV_DATA 0 -#define WEAVE_ADV_SCAN_RESPONSE_DATA 1 -#define WEAVE_ADV_SHORT_UUID_LEN 2 +#define CHIP_ADV_DATA 0 +#define CHIP_ADV_SCAN_RESPONSE_DATA 1 +#define CHIP_ADV_SHORT_UUID_LEN 2 #define MAX_RESPONSE_DATA_LEN 31 #define MAX_ADV_DATA_LEN 31 @@ -72,9 +70,9 @@ static gecko_configuration_t config; const uint8_t UUID_WoBLEService[] = {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xAF, 0xFE, 0x00, 0x00}; const uint8_t ShortUUID_WoBLEService[] = {0xAF, 0xFE}; -const WeaveBleUUID WeaveUUID_WoBLEChar_RX = { +const ChipBleUUID ChipUUID_WoBLEChar_RX = { {0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, 0x9D, 0x11}}; -const WeaveBleUUID WeaveUUID_WoBLEChar_TX = { +const ChipBleUUID ChipUUID_WoBLEChar_TX = { {0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, 0x9D, 0x12}}; } // namespace @@ -125,12 +123,12 @@ static void initBleConfig(void) config.mbedtls.dev_number = 0; } -WEAVE_ERROR BLEManagerImpl::_Init() +CHIP_ERROR BLEManagerImpl::_Init() { - WEAVE_ERROR err; + CHIP_ERROR err; errorcode_t ret; - // Initialize the Weave BleLayer. + // Initialize the Chip BleLayer. err = BleLayer::Init(this, this, &SystemLayer); SuccessOrExit(err); @@ -141,18 +139,18 @@ WEAVE_ERROR BLEManagerImpl::_Init() initBleConfig(); // Start Bluetooth Link Layer and stack tasks - ret = bluetooth_start(WEAVE_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY, WEAVE_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY, - initialize_bluetooth); + ret = bluetooth_start(CHIP_DEVICE_CONFIG_BLE_LL_TASK_PRIORITY, CHIP_DEVICE_CONFIG_BLE_STACK_TASK_PRIORITY, + initialize_bluetooth); VerifyOrExit(ret == bg_err_success, err = MapBLEError(ret)); // Create the Bluetooth Application task xTaskCreate(bluetoothStackEventHandler, /* Function that implements the task. */ - WEAVE_DEVICE_CONFIG_BLE_APP_TASK_NAME, /* Text name for the task. */ - WEAVE_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE / + CHIP_DEVICE_CONFIG_BLE_APP_TASK_NAME, /* Text name for the task. */ + CHIP_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE / sizeof(StackType_t), /* Number of indexes in the xStack array. */ this, /* Parameter passed into the task. */ - WEAVE_DEVICE_CONFIG_BLE_APP_TASK_PRIORITY, /* Priority at which the task is created. */ + CHIP_DEVICE_CONFIG_BLE_APP_TASK_PRIORITY, /* Priority at which the task is created. */ NULL); /* Variable to hold the task's data structure. */ mFlags = kFlag_AdvertisingEnabled; @@ -195,9 +193,9 @@ void BLEManagerImpl::bluetoothStackEventHandler(void *p_arg) flags &= ~BLUETOOTH_EVENT_FLAG_EVT_WAITING; xEventGroupClearBits(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_EVT_WAITING); - // As this is running in a separate thread, we need to block Weave from operating, + // As this is running in a separate thread, we need to block Chip from operating, // until the events are handled. - PlatformMgr().LockWeaveStack(); + PlatformMgr().LockChipStack(); // handle bluetooth events switch (BGLIB_MSG_ID(bluetooth_evt->header)) @@ -265,24 +263,24 @@ void BLEManagerImpl::bluetoothStackEventHandler(void *p_arg) break; default: - WeaveLogProgress(DeviceLayer, "evt_UNKNOWN id = %08x", BGLIB_MSG_ID(bluetooth_evt->header)); + ChipLogProgress(DeviceLayer, "evt_UNKNOWN id = %08x", BGLIB_MSG_ID(bluetooth_evt->header)); break; } } - PlatformMgr().UnlockWeaveStack(); + PlatformMgr().UnlockChipStack(); flags = vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_EVT_HANDLED, NULL); } } -WEAVE_ERROR BLEManagerImpl::_SetWoBLEServiceMode(WoBLEServiceMode val) +CHIP_ERROR BLEManagerImpl::_SetWoBLEServiceMode(WoBLEServiceMode val) { - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit(val != ConnectivityManager::kWoBLEServiceMode_NotSupported, err = WEAVE_ERROR_INVALID_ARGUMENT); + VerifyOrExit(val != ConnectivityManager::kWoBLEServiceMode_NotSupported, err = CHIP_ERROR_INVALID_ARGUMENT); VerifyOrExit(mServiceMode != ConnectivityManager::kWoBLEServiceMode_NotSupported, - err = WEAVE_ERROR_UNSUPPORTED_WEAVE_FEATURE); + err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); if (val != mServiceMode) { @@ -294,12 +292,12 @@ WEAVE_ERROR BLEManagerImpl::_SetWoBLEServiceMode(WoBLEServiceMode val) return err; } -WEAVE_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val) +CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val) { - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; VerifyOrExit(mServiceMode != ConnectivityManager::kWoBLEServiceMode_NotSupported, - err = WEAVE_ERROR_UNSUPPORTED_WEAVE_FEATURE); + err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); if (GetFlag(mFlags, kFlag_AdvertisingEnabled) != val) { @@ -311,12 +309,12 @@ WEAVE_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val) return err; } -WEAVE_ERROR BLEManagerImpl::_SetFastAdvertisingEnabled(bool val) +CHIP_ERROR BLEManagerImpl::_SetFastAdvertisingEnabled(bool val) { - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; VerifyOrExit(mServiceMode == ConnectivityManager::kWoBLEServiceMode_NotSupported, - err = WEAVE_ERROR_UNSUPPORTED_WEAVE_FEATURE); + err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); if (GetFlag(mFlags, kFlag_FastAdvertisingEnabled) != val) { @@ -328,50 +326,50 @@ WEAVE_ERROR BLEManagerImpl::_SetFastAdvertisingEnabled(bool val) return err; } -WEAVE_ERROR BLEManagerImpl::_GetDeviceName(char *buf, size_t bufSize) +CHIP_ERROR BLEManagerImpl::_GetDeviceName(char *buf, size_t bufSize) { if (strlen(mDeviceName) >= bufSize) { - return WEAVE_ERROR_BUFFER_TOO_SMALL; + return CHIP_ERROR_BUFFER_TOO_SMALL; } strcpy(buf, mDeviceName); - return WEAVE_NO_ERROR; + return CHIP_NO_ERROR; } -WEAVE_ERROR BLEManagerImpl::_SetDeviceName(const char *deviceName) +CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char *deviceName) { if (mServiceMode == ConnectivityManager::kWoBLEServiceMode_NotSupported) { - return WEAVE_ERROR_UNSUPPORTED_WEAVE_FEATURE; + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } if (deviceName != NULL && deviceName[0] != 0) { if (strlen(deviceName) >= kMaxDeviceNameLength) { - return WEAVE_ERROR_INVALID_ARGUMENT; + return CHIP_ERROR_INVALID_ARGUMENT; } strcpy(mDeviceName, deviceName); SetFlag(mFlags, kFlag_DeviceNameSet, true); - WeaveLogProgress(DeviceLayer, "Setting device name to : \"%s\"", deviceName); + ChipLogProgress(DeviceLayer, "Setting device name to : \"%s\"", deviceName); gecko_cmd_gatt_server_write_attribute_value(gattdb_device_name, 0, strlen(deviceName), (uint8_t *)deviceName); } else { mDeviceName[0] = 0; } - return WEAVE_NO_ERROR; + return CHIP_NO_ERROR; } -void BLEManagerImpl::_OnPlatformEvent(const WeaveDeviceEvent *event) +void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent *event) { switch (event->Type) { case DeviceEventType::kWoBLESubscribe: { - WeaveDeviceEvent connEstEvent; + ChipDeviceEvent connEstEvent; - WeaveLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLESubscribe"); - HandleSubscribeReceived(event->WoBLESubscribe.ConId, &WEAVE_BLE_SVC_ID, &WeaveUUID_WoBLEChar_TX); + ChipLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLESubscribe"); + HandleSubscribeReceived(event->WoBLESubscribe.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_WoBLEChar_TX); connEstEvent.Type = DeviceEventType::kWoBLEConnectionEstablished; PlatformMgr().PostEvent(&connEstEvent); } @@ -379,71 +377,71 @@ void BLEManagerImpl::_OnPlatformEvent(const WeaveDeviceEvent *event) case DeviceEventType::kWoBLEUnsubscribe: { - WeaveLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLEUnsubscribe"); - HandleUnsubscribeReceived(event->WoBLEUnsubscribe.ConId, &WEAVE_BLE_SVC_ID, &WeaveUUID_WoBLEChar_TX); + ChipLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLEUnsubscribe"); + HandleUnsubscribeReceived(event->WoBLEUnsubscribe.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_WoBLEChar_TX); } break; case DeviceEventType::kWoBLEWriteReceived: { - WeaveLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLEWriteReceived"); - HandleWriteReceived(event->WoBLEWriteReceived.ConId, &WEAVE_BLE_SVC_ID, &WeaveUUID_WoBLEChar_RX, + ChipLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLEWriteReceived"); + HandleWriteReceived(event->WoBLEWriteReceived.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_WoBLEChar_RX, event->WoBLEWriteReceived.Data); } break; case DeviceEventType::kWoBLEConnectionError: { - WeaveLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLEConnectionError"); + ChipLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLEConnectionError"); HandleConnectionError(event->WoBLEConnectionError.ConId, event->WoBLEConnectionError.Reason); } break; case DeviceEventType::kWoBLEIndicateConfirm: { - WeaveLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLEIndicateConfirm"); - HandleIndicationConfirmation(event->WoBLEIndicateConfirm.ConId, &WEAVE_BLE_SVC_ID, &WeaveUUID_WoBLEChar_TX); + ChipLogProgress(DeviceLayer, "_OnPlatformEvent kWoBLEIndicateConfirm"); + HandleIndicationConfirmation(event->WoBLEIndicateConfirm.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_WoBLEChar_TX); } break; default: - WeaveLogProgress(DeviceLayer, "_OnPlatformEvent default: event->Type = %d", event->Type); + ChipLogProgress(DeviceLayer, "_OnPlatformEvent default: event->Type = %d", event->Type); break; } } bool BLEManagerImpl::SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, - const WeaveBleUUID * svcId, - const WeaveBleUUID * charId) + const ChipBleUUID * svcId, + const ChipBleUUID * charId) { - WeaveLogProgress(DeviceLayer, "BLEManagerImpl::SubscribeCharacteristic() not supported"); + ChipLogProgress(DeviceLayer, "BLEManagerImpl::SubscribeCharacteristic() not supported"); return false; } bool BLEManagerImpl::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, - const WeaveBleUUID * svcId, - const WeaveBleUUID * charId) + const ChipBleUUID * svcId, + const ChipBleUUID * charId) { - WeaveLogProgress(DeviceLayer, "BLEManagerImpl::UnsubscribeCharacteristic() not supported"); + ChipLogProgress(DeviceLayer, "BLEManagerImpl::UnsubscribeCharacteristic() not supported"); return false; } bool BLEManagerImpl::CloseConnection(BLE_CONNECTION_OBJECT conId) { - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; gecko_msg_le_connection_close_rsp_t *rsp; - WeaveLogProgress(DeviceLayer, "Closing BLE GATT connection (con %u)", conId); + ChipLogProgress(DeviceLayer, "Closing BLE GATT connection (con %u)", conId); rsp = gecko_cmd_le_connection_close(conId); err = MapBLEError(rsp->result); - if (err != WEAVE_NO_ERROR) + if (err != CHIP_NO_ERROR) { - WeaveLogError(DeviceLayer, "gecko_cmd_le_connection_close() failed: %s", ErrorStr(err)); + ChipLogError(DeviceLayer, "gecko_cmd_le_connection_close() failed: %s", ErrorStr(err)); } - return (err == WEAVE_NO_ERROR); + return (err == CHIP_NO_ERROR); } uint16_t BLEManagerImpl::GetMTU(BLE_CONNECTION_OBJECT conId) const @@ -453,18 +451,18 @@ uint16_t BLEManagerImpl::GetMTU(BLE_CONNECTION_OBJECT conId) const } bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, - const WeaveBleUUID * svcId, - const WeaveBleUUID * charId, + const ChipBleUUID * svcId, + const ChipBleUUID * charId, PacketBuffer * data) { - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; WoBLEConState * conState = GetConnectionState(conId); gecko_msg_gatt_server_send_characteristic_notification_rsp_t *rsp; - uint16_t cId = (UUIDsMatch(&WeaveUUID_WoBLEChar_RX, charId) ? gattdb_WoBLEChar_Rx : gattdb_WoBLEChar_Tx); + uint16_t cId = (UUIDsMatch(&ChipUUID_WoBLEChar_RX, charId) ? gattdb_WoBLEChar_Rx : gattdb_WoBLEChar_Tx); uint8_t timerHandle = GetTimerHandle(conId, true); - VerifyOrExit(((conState != NULL) && (conState->subscribed != 0)), err = WEAVE_ERROR_INVALID_ARGUMENT); - VerifyOrExit(timerHandle != kMaxConnections, err = WEAVE_ERROR_NO_MEMORY); + VerifyOrExit(((conState != NULL) && (conState->subscribed != 0)), err = CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrExit(timerHandle != kMaxConnections, err = CHIP_ERROR_NO_MEMORY); // start timer for light indication confirmation gecko_cmd_hardware_set_soft_timer(TIMER_S_2_TIMERTICK(1), timerHandle, true); @@ -475,62 +473,62 @@ bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, exit: PacketBuffer::Free(data); - if (err != WEAVE_NO_ERROR) + if (err != CHIP_NO_ERROR) { - WeaveLogError(DeviceLayer, "BLEManagerImpl::SendIndication() failed: %s", ErrorStr(err)); + ChipLogError(DeviceLayer, "BLEManagerImpl::SendIndication() failed: %s", ErrorStr(err)); return false; } return true; } bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, - const WeaveBleUUID * svcId, - const WeaveBleUUID * charId, + const ChipBleUUID * svcId, + const ChipBleUUID * charId, PacketBuffer * pBuf) { - WeaveLogProgress(DeviceLayer, "BLEManagerImpl::SendWriteRequest() not supported"); + ChipLogProgress(DeviceLayer, "BLEManagerImpl::SendWriteRequest() not supported"); return false; } bool BLEManagerImpl::SendReadRequest(BLE_CONNECTION_OBJECT conId, - const WeaveBleUUID * svcId, - const WeaveBleUUID * charId, + const ChipBleUUID * svcId, + const ChipBleUUID * charId, PacketBuffer * pBuf) { - WeaveLogProgress(DeviceLayer, "BLEManagerImpl::SendReadRequest() not supported"); + ChipLogProgress(DeviceLayer, "BLEManagerImpl::SendReadRequest() not supported"); return false; } bool BLEManagerImpl::SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, - const WeaveBleUUID * svcId, - const WeaveBleUUID * charId) + const ChipBleUUID * svcId, + const ChipBleUUID * charId) { - WeaveLogProgress(DeviceLayer, "BLEManagerImpl::SendReadResponse() not supported"); + ChipLogProgress(DeviceLayer, "BLEManagerImpl::SendReadResponse() not supported"); return false; } -void BLEManagerImpl::NotifyWeaveConnectionClosed(BLE_CONNECTION_OBJECT conId) +void BLEManagerImpl::NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) { // Nothing to do } -WEAVE_ERROR BLEManagerImpl::MapBLEError(int bleErr) +CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr) { - WEAVE_ERROR err; - + CHIP_ERROR err; + if (bleErr == bg_err_success) { - err = WEAVE_NO_ERROR; + err = CHIP_NO_ERROR; } else { - err = (WEAVE_ERROR) bleErr + WEAVE_DEVICE_CONFIG_EFR32_BLE_ERROR_MIN; + err = (CHIP_ERROR) bleErr + CHIP_DEVICE_CONFIG_EFR32_BLE_ERROR_MIN; } - return err; + return err; } void BLEManagerImpl::DriveBLEState(void) { - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; // Check if BLE stack is initialized VerifyOrExit(GetFlag(mFlags, kFlag_EFRBLEStackInitialized), /* */); @@ -555,18 +553,18 @@ void BLEManagerImpl::DriveBLEState(void) } exit: - if (err != WEAVE_NO_ERROR) + if (err != CHIP_NO_ERROR) { - WeaveLogError(DeviceLayer, "Disabling WoBLE service due to error: %s", ErrorStr(err)); + ChipLogError(DeviceLayer, "Disabling WoBLE service due to error: %s", ErrorStr(err)); mServiceMode = ConnectivityManager::kWoBLEServiceMode_Disabled; } } -WEAVE_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) +CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) { struct gecko_msg_le_gap_bt5_set_adv_data_rsp_t *setAdvDataRsp; - WeaveBLEDeviceIdentificationInfo mDeviceIdInfo; - WEAVE_ERROR err; + ChipBLEDeviceIdentificationInfo mDeviceIdInfo; + CHIP_ERROR err; uint8_t responseData[MAX_RESPONSE_DATA_LEN]; uint8_t advData[MAX_ADV_DATA_LEN]; uint8_t index = 0; @@ -581,7 +579,7 @@ WEAVE_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) if (!GetFlag(mFlags, kFlag_DeviceNameSet)) { - snprintf(mDeviceName, sizeof(mDeviceName), "%s%04" PRIX32, WEAVE_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, + snprintf(mDeviceName, sizeof(mDeviceName), "%s%04" PRIX32, CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, (uint32_t)FabricState.LocalNodeId); mDeviceName[kMaxDeviceNameLength] = 0; @@ -594,40 +592,40 @@ WEAVE_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) index = 0; responseData[index++] = 0x02; // length - responseData[index++] = WEAVE_ADV_DATA_TYPE_FLAGS; // AD type : flags - responseData[index++] = WEAVE_ADV_DATA_FLAGS; // AD value + responseData[index++] = CHIP_ADV_DATA_TYPE_FLAGS; // AD type : flags + responseData[index++] = CHIP_ADV_DATA_FLAGS; // AD value responseData[index++] = mDeviceNameLength + 1; // length - responseData[index++] = WEAVE_ADV_DATA_TYPE_NAME; // AD type : name + responseData[index++] = CHIP_ADV_DATA_TYPE_NAME; // AD type : name memcpy(&responseData[index], mDeviceName, mDeviceNameLength); // AD value index += mDeviceNameLength; - responseData[index++] = WEAVE_ADV_SHORT_UUID_LEN + 1; // AD length - responseData[index++] = WEAVE_ADV_DATA_TYPE_UUID; // AD type : uuid + responseData[index++] = CHIP_ADV_SHORT_UUID_LEN + 1; // AD length + responseData[index++] = CHIP_ADV_DATA_TYPE_UUID; // AD type : uuid responseData[index++] = ShortUUID_WoBLEService[0]; // AD value responseData[index++] = ShortUUID_WoBLEService[1]; - setAdvDataRsp = gecko_cmd_le_gap_bt5_set_adv_data(WEAVE_ADV_WOBLE_SERVICE_HANDLE, WEAVE_ADV_SCAN_RESPONSE_DATA, + setAdvDataRsp = gecko_cmd_le_gap_bt5_set_adv_data(CHIP_ADV_WOBLE_SERVICE_HANDLE, CHIP_ADV_SCAN_RESPONSE_DATA, index, (uint8_t *)&responseData); if (setAdvDataRsp->result != 0) { err = MapBLEError(setAdvDataRsp->result); - WeaveLogError(DeviceLayer, "gecko_cmd_le_gap_bt5_set_adv_data() failed: %s", ErrorStr(err)); + ChipLogError(DeviceLayer, "gecko_cmd_le_gap_bt5_set_adv_data() failed: %s", ErrorStr(err)); ExitNow(); } index = 0; - advData[index++] = mDeviceIdInfoLength + WEAVE_ADV_SHORT_UUID_LEN + 1; // AD length - advData[index++] = WEAVE_ADV_DATA_TYPE_SERVICE_DATA; // AD type : Service Data + advData[index++] = mDeviceIdInfoLength + CHIP_ADV_SHORT_UUID_LEN + 1; // AD length + advData[index++] = CHIP_ADV_DATA_TYPE_SERVICE_DATA; // AD type : Service Data advData[index++] = ShortUUID_WoBLEService[0]; // AD value advData[index++] = ShortUUID_WoBLEService[1]; memcpy(&advData[index], (void *)&mDeviceIdInfo, mDeviceIdInfoLength); // AD value index += mDeviceIdInfoLength; setAdvDataRsp = - gecko_cmd_le_gap_bt5_set_adv_data(WEAVE_ADV_WOBLE_SERVICE_HANDLE, WEAVE_ADV_DATA, index, (uint8_t *)&advData); + gecko_cmd_le_gap_bt5_set_adv_data(CHIP_ADV_WOBLE_SERVICE_HANDLE, CHIP_ADV_DATA, index, (uint8_t *)&advData); err = MapBLEError(setAdvDataRsp->result); @@ -635,9 +633,9 @@ WEAVE_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) return err; } -WEAVE_ERROR BLEManagerImpl::StartAdvertising(void) +CHIP_ERROR BLEManagerImpl::StartAdvertising(void) { - WEAVE_ERROR err; + CHIP_ERROR err; struct gecko_msg_le_gap_start_advertising_rsp_t *startAdvRsp; uint32_t interval_min; uint32_t interval_max; @@ -652,12 +650,12 @@ WEAVE_ERROR BLEManagerImpl::StartAdvertising(void) interval_min = interval_max = ((numConnectionss == 0 && !ConfigurationMgr().IsPairedToAccount()) || GetFlag(mFlags, kFlag_FastAdvertisingEnabled)) - ? WEAVE_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL - : WEAVE_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL; + ? CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL + : CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL; - gecko_cmd_le_gap_set_advertise_timing(WEAVE_ADV_WOBLE_SERVICE_HANDLE, interval_min, interval_max, 0, 0); + gecko_cmd_le_gap_set_advertise_timing(CHIP_ADV_WOBLE_SERVICE_HANDLE, interval_min, interval_max, 0, 0); - startAdvRsp = gecko_cmd_le_gap_start_advertising(WEAVE_ADV_WOBLE_SERVICE_HANDLE, le_gap_user_data, connectableAdv); + startAdvRsp = gecko_cmd_le_gap_start_advertising(CHIP_ADV_WOBLE_SERVICE_HANDLE, le_gap_user_data, connectableAdv); err = MapBLEError(startAdvRsp->result); @@ -665,9 +663,9 @@ WEAVE_ERROR BLEManagerImpl::StartAdvertising(void) return err; } -WEAVE_ERROR BLEManagerImpl::StopAdvertising(void) +CHIP_ERROR BLEManagerImpl::StopAdvertising(void) { - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; gecko_msg_le_gap_stop_advertising_rsp_t *rsp; if (GetFlag(mFlags, kFlag_Advertising)) @@ -675,7 +673,7 @@ WEAVE_ERROR BLEManagerImpl::StopAdvertising(void) ClearFlag(mFlags, kFlag_Advertising); ClearFlag(mFlags, kFlag_RestartAdvertising); - rsp = gecko_cmd_le_gap_stop_advertising(WEAVE_ADV_WOBLE_SERVICE_HANDLE); + rsp = gecko_cmd_le_gap_stop_advertising(CHIP_ADV_WOBLE_SERVICE_HANDLE); err = MapBLEError(rsp->result); SuccessOrExit(err); } @@ -703,7 +701,7 @@ void BLEManagerImpl::HandleConnectEvent(volatile struct gecko_cmd_packet *evt) uint8_t connHandle = conn_evt->connection; uint8_t bondingHandle = conn_evt->bonding; - WeaveLogProgress(DeviceLayer, "Connect Event for handle : %d", connHandle); + ChipLogProgress(DeviceLayer, "Connect Event for handle : %d", connHandle); AddConnection(connHandle, bondingHandle); @@ -716,11 +714,11 @@ void BLEManagerImpl::HandleConnectionCloseEvent(volatile struct gecko_cmd_packet struct gecko_msg_le_connection_closed_evt_t *conn_evt = (struct gecko_msg_le_connection_closed_evt_t *)&(evt->data); uint8_t connHandle = conn_evt->connection; - WeaveLogProgress(DeviceLayer, "Disconnect Event for handle : %d", connHandle); + ChipLogProgress(DeviceLayer, "Disconnect Event for handle : %d", connHandle); if (RemoveConnection(connHandle)) { - WeaveDeviceEvent event; + ChipDeviceEvent event; event.Type = DeviceEventType::kWoBLEConnectionError; event.WoBLEConnectionError.ConId = connHandle; @@ -741,7 +739,7 @@ void BLEManagerImpl::HandleConnectionCloseEvent(volatile struct gecko_cmd_packet break; } - WeaveLogProgress(DeviceLayer, "BLE GATT connection closed (con %u, reason %u)", connHandle, conn_evt->reason); + ChipLogProgress(DeviceLayer, "BLE GATT connection closed (con %u, reason %u)", connHandle, conn_evt->reason); PlatformMgr().PostEvent(&event); @@ -757,7 +755,7 @@ void BLEManagerImpl::HandleWriteEvent(volatile struct gecko_cmd_packet *evt) struct gecko_msg_gatt_server_read_attribute_type_rsp_t *rsp; uint16_t attribute = evt->data.evt_gatt_server_user_write_request.characteristic; - WeaveLogProgress(DeviceLayer, "Char Write Req, char : %d", attribute); + ChipLogProgress(DeviceLayer, "Char Write Req, char : %d", attribute); if (gattdb_WoBLEChar_Rx == attribute) { @@ -767,19 +765,19 @@ void BLEManagerImpl::HandleWriteEvent(volatile struct gecko_cmd_packet *evt) void BLEManagerImpl::HandleTXCharCCCDWrite(volatile struct gecko_cmd_packet *evt) { - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; WoBLEConState * bleConnState; bool indicationsEnabled; - WeaveDeviceEvent event; + ChipDeviceEvent event; bleConnState = GetConnectionState(evt->data.evt_gatt_server_user_write_request.connection); - VerifyOrExit(bleConnState != NULL, err = WEAVE_ERROR_NO_MEMORY); + VerifyOrExit(bleConnState != NULL, err = CHIP_ERROR_NO_MEMORY); // Determine if the client is enabling or disabling indications. indicationsEnabled = (evt->data.evt_gatt_server_characteristic_status.client_config_flags == gatt_indication); - WeaveLogProgress(DeviceLayer, "WoBLE %s received", indicationsEnabled ? "subscribe" : "unsubscribe"); + ChipLogProgress(DeviceLayer, "WoBLE %s received", indicationsEnabled ? "subscribe" : "unsubscribe"); if (indicationsEnabled) { @@ -787,7 +785,7 @@ void BLEManagerImpl::HandleTXCharCCCDWrite(volatile struct gecko_cmd_packet *evt if (!bleConnState->subscribed) { bleConnState->subscribed = 1; - // Post an event to the Weave queue to process either a WoBLE Subscribe or Unsubscribe based on + // Post an event to the Chip queue to process either a WoBLE Subscribe or Unsubscribe based on // whether the client is enabling or disabling indications. { event.Type = DeviceEventType::kWoBLESubscribe; @@ -805,33 +803,33 @@ void BLEManagerImpl::HandleTXCharCCCDWrite(volatile struct gecko_cmd_packet *evt } exit: - if (err != WEAVE_NO_ERROR) + if (err != CHIP_NO_ERROR) { - WeaveLogError(DeviceLayer, "HandleTXCharCCCDWrite() failed: %s", ErrorStr(err)); + ChipLogError(DeviceLayer, "HandleTXCharCCCDWrite() failed: %s", ErrorStr(err)); } } void BLEManagerImpl::HandleRXCharWrite(volatile struct gecko_cmd_packet *evt) { - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; PacketBuffer *buf; uint16_t writeLen = evt->data.evt_gatt_server_user_write_request.value.len; uint8_t * data = (uint8_t *)evt->data.evt_gatt_server_user_write_request.value.data; // Copy the data to a PacketBuffer. buf = PacketBuffer::New(0); - VerifyOrExit(buf != NULL, err = WEAVE_ERROR_NO_MEMORY); - VerifyOrExit(buf->AvailableDataLength() >= writeLen, err = WEAVE_ERROR_BUFFER_TOO_SMALL); + VerifyOrExit(buf != NULL, err = CHIP_ERROR_NO_MEMORY); + VerifyOrExit(buf->AvailableDataLength() >= writeLen, err = CHIP_ERROR_BUFFER_TOO_SMALL); memcpy(buf->Start(), data, writeLen); buf->SetDataLength(writeLen); - WeaveLogDetail(DeviceLayer, + ChipLogDetail(DeviceLayer, "Write request/command received for WoBLE RX characteristic (con %" PRIu16 ", len %" PRIu16 ")", evt->data.evt_gatt_server_user_write_request.connection, buf->DataLength()); - // Post an event to the Weave queue to deliver the data into the Weave stack. + // Post an event to the Chip queue to deliver the data into the Chip stack. { - WeaveDeviceEvent event; + ChipDeviceEvent event; event.Type = DeviceEventType::kWoBLEWriteReceived; event.WoBLEWriteReceived.ConId = evt->data.evt_gatt_server_user_write_request.connection; event.WoBLEWriteReceived.Data = buf; @@ -840,25 +838,25 @@ void BLEManagerImpl::HandleRXCharWrite(volatile struct gecko_cmd_packet *evt) } exit: - if (err != WEAVE_NO_ERROR) + if (err != CHIP_NO_ERROR) { - WeaveLogError(DeviceLayer, "HandleRXCharWrite() failed: %s", ErrorStr(err)); + ChipLogError(DeviceLayer, "HandleRXCharWrite() failed: %s", ErrorStr(err)); } PacketBuffer::Free(buf); } void BLEManagerImpl::HandleTxConfirmationEvent(volatile struct gecko_cmd_packet *evt) { - WeaveDeviceEvent event; + ChipDeviceEvent event; uint8_t timerHandle = sInstance.GetTimerHandle(evt->data.evt_gatt_server_characteristic_status.connection); - WeaveLogProgress(DeviceLayer, "Tx Confirmation received"); + ChipLogProgress(DeviceLayer, "Tx Confirmation received"); // stop indication confirmation timer if (timerHandle < kMaxConnections) { - WeaveLogProgress(DeviceLayer, " stop soft timer"); + ChipLogProgress(DeviceLayer, " stop soft timer"); gecko_cmd_hardware_set_soft_timer(0, timerHandle, false); } @@ -873,8 +871,8 @@ void BLEManagerImpl::HandleSoftTimerEvent(volatile struct gecko_cmd_packet *evt) // If we receive a callback for unknown timer handle ignore this. if (evt->data.evt_hardware_soft_timer.handle < kMaxConnections) { - WeaveLogProgress(DeviceLayer, "BLEManagerImpl::HandleSoftTimerEvent WOBLE_PROTOCOL_ABORT"); - WeaveDeviceEvent event; + ChipLogProgress(DeviceLayer, "BLEManagerImpl::HandleSoftTimerEvent WOBLE_PROTOCOL_ABORT"); + ChipDeviceEvent event; event.Type = DeviceEventType::kWoBLEConnectionError; event.WoBLEConnectionError.ConId = mIndConfId[evt->data.evt_hardware_soft_timer.handle]; sInstance.mIndConfId[evt->data.evt_hardware_soft_timer.handle] = kUnusedIndex; @@ -937,7 +935,7 @@ BLEManagerImpl::WoBLEConState *BLEManagerImpl::GetConnectionState(uint8_t connec return &mBleConnections[freeIndex]; } - WeaveLogError(DeviceLayer, "Failed to allocate WoBLEConState"); + ChipLogError(DeviceLayer, "Failed to allocate WoBLEConState"); } return NULL; @@ -968,7 +966,7 @@ uint8_t BLEManagerImpl::GetTimerHandle(uint8_t connectionHandle, bool allocate) } else { - WeaveLogError(DeviceLayer, "Failed to Save Conn Handle for indication"); + ChipLogError(DeviceLayer, "Failed to Save Conn Handle for indication"); } return freeIndex; @@ -981,6 +979,5 @@ void BLEManagerImpl::DriveBLEState(intptr_t arg) } // namespace Internal } // namespace DeviceLayer -} // namespace Weave -} // namespace nl -#endif // WEAVE_DEVICE_CONFIG_ENABLE_WOBLE +} // namespace chip +#endif // CHIP_DEVICE_CONFIG_ENABLE_WOBLE diff --git a/src/platform/EFR32/ConfigurationManagerImpl.cpp b/src/platform/EFR32/ConfigurationManagerImpl.cpp index 4385d5dc0edb16..f066fa9a74882d 100644 --- a/src/platform/EFR32/ConfigurationManagerImpl.cpp +++ b/src/platform/EFR32/ConfigurationManagerImpl.cpp @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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. @@ -22,26 +21,23 @@ * for EFR32 platforms using the Silicon Labs SDK. */ -#include -#include -#include -#include -#include -#include -#include -#include - -namespace nl { -namespace Weave { +#include +#include +#include +#include +#include +#include + +namespace chip { namespace DeviceLayer { -using namespace ::nl::Weave::Profiles::Security::AppKeys; -using namespace ::nl::Weave::Profiles::DeviceDescription; -using namespace ::nl::Weave::DeviceLayer::Internal; +using namespace ::chip::Profiles::Security::AppKeys; +using namespace ::chip::Profiles::DeviceDescription; +using namespace ::chip::DeviceLayer::Internal; namespace { -// Singleton instance of Weave Group Key Store. +// Singleton instance of Chip Group Key Store. GroupKeyStoreImpl gGroupKeyStore; } // unnamed namespace @@ -50,9 +46,9 @@ GroupKeyStoreImpl gGroupKeyStore; */ ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; -WEAVE_ERROR ConfigurationManagerImpl::_Init() +CHIP_ERROR ConfigurationManagerImpl::_Init() { - WEAVE_ERROR err; + CHIP_ERROR err; bool failSafeArmed; // Initialize the generic implementation base class. @@ -64,21 +60,21 @@ WEAVE_ERROR ConfigurationManagerImpl::_Init() SuccessOrExit(err); // If the fail-safe was armed when the device last shutdown, initiate a factory reset. - if (_GetFailSafeArmed(failSafeArmed) == WEAVE_NO_ERROR && failSafeArmed) + if (_GetFailSafeArmed(failSafeArmed) == CHIP_NO_ERROR && failSafeArmed) { - WeaveLogProgress(DeviceLayer, "Detected fail-safe armed on reboot; initiating factory reset"); + ChipLogProgress(DeviceLayer, "Detected fail-safe armed on reboot; initiating factory reset"); _InitiateFactoryReset(); } - err = WEAVE_NO_ERROR; + err = CHIP_NO_ERROR; exit: return err; } -WEAVE_ERROR ConfigurationManagerImpl::_GetDeviceDescriptor( - ::nl::Weave::Profiles::DeviceDescription::WeaveDeviceDescriptor &deviceDesc) +CHIP_ERROR ConfigurationManagerImpl::_GetDeviceDescriptor( + ::chip::Profiles::DeviceDescription::ChipDeviceDescriptor &deviceDesc) { - WEAVE_ERROR err; + CHIP_ERROR err; // Call the generic version of _GetDeviceDescriptor() supplied by the base class. err = Internal::GenericConfigurationManagerImpl::_GetDeviceDescriptor(deviceDesc); @@ -88,7 +84,7 @@ WEAVE_ERROR ConfigurationManagerImpl::_GetDeviceDescriptor( return err; } -::nl::Weave::Profiles::Security::AppKeys::GroupKeyStoreBase *ConfigurationManagerImpl::_GetGroupKeyStore() +::chip::Profiles::Security::AppKeys::GroupKeyStoreBase *ConfigurationManagerImpl::_GetGroupKeyStore() { return &gGroupKeyStore; } @@ -104,18 +100,18 @@ void ConfigurationManagerImpl::_InitiateFactoryReset() PlatformMgr().ScheduleWork(DoFactoryReset); } -WEAVE_ERROR ConfigurationManagerImpl::_ReadPersistedStorageValue( - ::nl::Weave::Platform::PersistedStorage::Key persistedStorageKey, +CHIP_ERROR ConfigurationManagerImpl::_ReadPersistedStorageValue( + ::chip::Platform::PersistedStorage::Key persistedStorageKey, uint32_t & value) { - // This method reads Weave Persisted Counter type nvm3 objects. + // This method reads Chip Persisted Counter type nvm3 objects. // (where persistedStorageKey represents an index to the counter). - WEAVE_ERROR err; + CHIP_ERROR err; err = ReadConfigValueCounter(persistedStorageKey, value); - if (err == WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND) + if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { - err = WEAVE_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; + err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; } SuccessOrExit(err); @@ -123,18 +119,18 @@ WEAVE_ERROR ConfigurationManagerImpl::_ReadPersistedStorageValue( return err; } -WEAVE_ERROR ConfigurationManagerImpl::_WritePersistedStorageValue( - ::nl::Weave::Platform::PersistedStorage::Key persistedStorageKey, +CHIP_ERROR ConfigurationManagerImpl::_WritePersistedStorageValue( + ::chip::Platform::PersistedStorage::Key persistedStorageKey, uint32_t value) { - // This method reads Weave Persisted Counter type nvm3 objects. + // This method reads Chip Persisted Counter type nvm3 objects. // (where persistedStorageKey represents an index to the counter). - WEAVE_ERROR err; + CHIP_ERROR err; err = WriteConfigValueCounter(persistedStorageKey, value); - if (err == WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND) + if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { - err = WEAVE_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; + err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; } SuccessOrExit(err); @@ -144,28 +140,27 @@ WEAVE_ERROR ConfigurationManagerImpl::_WritePersistedStorageValue( void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { - WEAVE_ERROR err; + CHIP_ERROR err; - WeaveLogProgress(DeviceLayer, "Performing factory reset"); + ChipLogProgress(DeviceLayer, "Performing factory reset"); err = FactoryResetConfig(); - if (err != WEAVE_NO_ERROR) + if (err != CHIP_NO_ERROR) { - WeaveLogError(DeviceLayer, "FactoryResetConfig() failed: %s", nl::ErrorStr(err)); + ChipLogError(DeviceLayer, "FactoryResetConfig() failed: %s", chip::ErrorStr(err)); } -#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD - WeaveLogProgress(DeviceLayer, "Clearing Thread provision"); + ChipLogProgress(DeviceLayer, "Clearing Thread provision"); ThreadStackMgr().ClearThreadProvision(); -#endif // WEAVE_DEVICE_CONFIG_ENABLE_THREAD +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD // Restart the system. - WeaveLogProgress(DeviceLayer, "System restarting"); + ChipLogProgress(DeviceLayer, "System restarting"); NVIC_SystemReset(); } } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip diff --git a/src/platform/EFR32/ConnectivityManagerImpl.cpp b/src/platform/EFR32/ConnectivityManagerImpl.cpp index 8bf8813bc1e68f..5762f880fd2e29 100644 --- a/src/platform/EFR32/ConnectivityManagerImpl.cpp +++ b/src/platform/EFR32/ConnectivityManagerImpl.cpp @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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. @@ -16,15 +15,15 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -33,40 +32,39 @@ #include -#if WEAVE_DEVICE_CONFIG_ENABLE_WOBLE -#include +#if CHIP_DEVICE_CONFIG_ENABLE_WOBLE +#include #endif -#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD -#include +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#include #endif -using namespace ::nl; -using namespace ::nl::Weave; -using namespace ::nl::Weave::TLV; -using namespace ::nl::Weave::Profiles::Common; -using namespace ::nl::Weave::Profiles::NetworkProvisioning; -using namespace ::nl::Weave::DeviceLayer::Internal; +using namespace ::chip; +using namespace ::chip::Chip; +using namespace ::chip::TLV; +using namespace ::chip::Profiles::Common; +using namespace ::chip::Profiles::NetworkProvisioning; +using namespace ::chip::DeviceLayer::Internal; -using Profiles::kWeaveProfile_Common; -using Profiles::kWeaveProfile_NetworkProvisioning; +using Profiles::kChipProfile_Common; +using Profiles::kChipProfile_NetworkProvisioning; -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { ConnectivityManagerImpl ConnectivityManagerImpl::sInstance; -WEAVE_ERROR ConnectivityManagerImpl::_Init() +CHIP_ERROR ConnectivityManagerImpl::_Init() { - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; // Initialize the generic base classes that require it. -#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD GenericConnectivityManagerImpl_Thread::_Init(); #endif - // Initialize the Weave Addressing and Routing Module. + // Initialize the Chip Addressing and Routing Module. err = Warm::Init(FabricState); SuccessOrExit(err); @@ -74,14 +72,13 @@ WEAVE_ERROR ConnectivityManagerImpl::_Init() return err; } -void ConnectivityManagerImpl::_OnPlatformEvent(const WeaveDeviceEvent *event) +void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent *event) { // Forward the event to the generic base classes as needed. -#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD GenericConnectivityManagerImpl_Thread::_OnPlatformEvent(event); #endif } } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip diff --git a/src/platform/EFR32/EFR32Config.cpp b/src/platform/EFR32/EFR32Config.cpp index 5b61bf73eba4fc..5f895d71a47f19 100644 --- a/src/platform/EFR32/EFR32Config.cpp +++ b/src/platform/EFR32/EFR32Config.cpp @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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. @@ -22,17 +21,16 @@ * platforms based on the Silicon Labs SDK. */ -#include -#include -#include -#include +#include +#include +#include +#include #include "nvm3.h" #include "nvm3_hal_flash.h" #include "FreeRTOS.h" -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { namespace Internal { @@ -40,16 +38,16 @@ namespace Internal { // initialization data- NVM3_DEFINE_SECTION_STATIC_DATA() and NVM3_DEFINE_SECTION_INIT_DATA(). // A linker section called 'name'_section is defined by NVM3_DEFINE_SECTION_STATIC_DATA(). // The NVM3 area is placed at the top of the device FLASH section by the linker -// script file: openweave-efr32-bringup-MG12P.ld. An error is returned +// script file: chip-efr32-bringup-MG12P.ld. An error is returned // by nvm3_open() on alignment or size violation. // Local version of SDK macro (avoids uninitialized var compile error). -#define WEAVE_NVM3_DEFINE_SECTION_STATIC_DATA(name, nvmSize, cacheSize) \ +#define CHIP_NVM3_DEFINE_SECTION_STATIC_DATA(name, nvmSize, cacheSize) \ static nvm3_CacheEntry_t name##_cache[cacheSize]; \ static uint8_t name##_nvm[nvmSize] SL_ATTRIBUTE_SECTION(STRINGIZE(name##_section)) -// Local version of SDK macro (allows Weave to configure the maximum nvm3 object size and headroom). -#define WEAVE_NVM3_DEFINE_SECTION_INIT_DATA(name, maxObjectSize, repackHeadroom) \ +// Local version of SDK macro (allows Chip to configure the maximum nvm3 object size and headroom). +#define CHIP_NVM3_DEFINE_SECTION_INIT_DATA(name, maxObjectSize, repackHeadroom) \ static nvm3_Init_t name = { \ (nvm3_HalPtr_t)name##_nvm, \ sizeof(name##_nvm), \ @@ -60,24 +58,24 @@ namespace Internal { &nvm3_halFlashHandle, \ } -#define WEAVE_NVM3_REPACK_HEADROOM 64 // Threshold for User non-forced nvm3 flash repacking. +#define CHIP_NVM3_REPACK_HEADROOM 64 // Threshold for User non-forced nvm3 flash repacking. static nvm3_Handle_t handle; // Declare NVM3 data area and cache. -WEAVE_NVM3_DEFINE_SECTION_STATIC_DATA(weaveNvm3, - WEAVE_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE *FLASH_PAGE_SIZE, - WEAVE_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS); +CHIP_NVM3_DEFINE_SECTION_STATIC_DATA(chipNvm3, + CHIP_DEVICE_CONFIG_NVM3_NUM_FLASH_PAGES_FOR_STORAGE *FLASH_PAGE_SIZE, + CHIP_DEVICE_CONFIG_NVM3_MAX_NUM_OBJECTS); -WEAVE_NVM3_DEFINE_SECTION_INIT_DATA(weaveNvm3, WEAVE_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE, WEAVE_NVM3_REPACK_HEADROOM); +CHIP_NVM3_DEFINE_SECTION_INIT_DATA(chipNvm3, CHIP_DEVICE_CONFIG_NVM3_MAX_OBJECT_SIZE, CHIP_NVM3_REPACK_HEADROOM); -WEAVE_ERROR EFR32Config::Init() +CHIP_ERROR EFR32Config::Init() { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; @@ -90,17 +88,17 @@ WEAVE_ERROR EFR32Config::Init() return err; } -WEAVE_ERROR EFR32Config::ReadConfigValue(Key key, bool &val) +CHIP_ERROR EFR32Config::ReadConfigValue(Key key, bool &val) { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; uint32_t objectType; size_t dataLen; bool tmpVal; - VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; @@ -121,17 +119,17 @@ WEAVE_ERROR EFR32Config::ReadConfigValue(Key key, bool &val) return err; } -WEAVE_ERROR EFR32Config::ReadConfigValue(Key key, uint32_t &val) +CHIP_ERROR EFR32Config::ReadConfigValue(Key key, uint32_t &val) { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; uint32_t objectType; size_t dataLen; uint32_t tmpVal; - VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; @@ -152,17 +150,17 @@ WEAVE_ERROR EFR32Config::ReadConfigValue(Key key, uint32_t &val) return err; } -WEAVE_ERROR EFR32Config::ReadConfigValue(Key key, uint64_t &val) +CHIP_ERROR EFR32Config::ReadConfigValue(Key key, uint64_t &val) { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; uint32_t objectType; size_t dataLen; uint64_t tmpVal; - VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; @@ -183,32 +181,32 @@ WEAVE_ERROR EFR32Config::ReadConfigValue(Key key, uint64_t &val) return err; } -WEAVE_ERROR EFR32Config::ReadConfigValueStr(Key key, char *buf, size_t bufSize, size_t &outLen) +CHIP_ERROR EFR32Config::ReadConfigValueStr(Key key, char *buf, size_t bufSize, size_t &outLen) { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; uint32_t objectType; size_t dataLen; outLen = 0; - VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; // Get nvm3 object info. err = MapNvm3Error(nvm3_getObjectInfo(&handle, key, &objectType, &dataLen)); SuccessOrExit(err); - VerifyOrExit(dataLen > 0, err = WEAVE_ERROR_INVALID_STRING_LENGTH); + VerifyOrExit(dataLen > 0, err = CHIP_ERROR_INVALID_STRING_LENGTH); if (buf != NULL) { // Read nvm3 bytes directly into the output buffer- check buffer is // long enough to take the string (nvm3 string does not include the // terminator char). - VerifyOrExit((bufSize > dataLen), err = WEAVE_ERROR_BUFFER_TOO_SMALL); + VerifyOrExit((bufSize > dataLen), err = CHIP_ERROR_BUFFER_TOO_SMALL); err = MapNvm3Error(nvm3_readData(&handle, key, buf, dataLen)); SuccessOrExit(err); @@ -241,31 +239,31 @@ WEAVE_ERROR EFR32Config::ReadConfigValueStr(Key key, char *buf, size_t bufSize, return err; } -WEAVE_ERROR EFR32Config::ReadConfigValueBin(Key key, uint8_t *buf, size_t bufSize, size_t &outLen) +CHIP_ERROR EFR32Config::ReadConfigValueBin(Key key, uint8_t *buf, size_t bufSize, size_t &outLen) { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; uint32_t objectType; size_t dataLen; outLen = 0; - VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; // Get nvm3 object info. err = MapNvm3Error(nvm3_getObjectInfo(&handle, key, &objectType, &dataLen)); SuccessOrExit(err); - VerifyOrExit(dataLen > 0, err = WEAVE_ERROR_INVALID_STRING_LENGTH); + VerifyOrExit(dataLen > 0, err = CHIP_ERROR_INVALID_STRING_LENGTH); if (buf != NULL) { // Read nvm3 bytes directly into output buffer- check buffer is long // enough to take the data. - VerifyOrExit((bufSize >= dataLen), err = WEAVE_ERROR_BUFFER_TOO_SMALL); + VerifyOrExit((bufSize >= dataLen), err = CHIP_ERROR_BUFFER_TOO_SMALL); err = MapNvm3Error(nvm3_readData(&handle, key, buf, dataLen)); SuccessOrExit(err); @@ -281,16 +279,16 @@ WEAVE_ERROR EFR32Config::ReadConfigValueBin(Key key, uint8_t *buf, size_t bufSiz return err; } -WEAVE_ERROR EFR32Config::ReadConfigValueCounter(uint8_t counterIdx, uint32_t &val) +CHIP_ERROR EFR32Config::ReadConfigValueCounter(uint8_t counterIdx, uint32_t &val) { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; uint32_t tmpVal; - Key key = kMinConfigKey_WeaveCounter + counterIdx; - VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + Key key = kMinConfigKey_ChipCounter + counterIdx; + VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; @@ -307,14 +305,14 @@ WEAVE_ERROR EFR32Config::ReadConfigValueCounter(uint8_t counterIdx, uint32_t &va return err; } -WEAVE_ERROR EFR32Config::WriteConfigValue(Key key, bool val) +CHIP_ERROR EFR32Config::WriteConfigValue(Key key, bool val) { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; - VerifyOrExit(ValidConfigKey(key), err = WEAVE_ERROR_INVALID_ARGUMENT); // Verify key id. + VerifyOrExit(ValidConfigKey(key), err = CHIP_ERROR_INVALID_ARGUMENT); // Verify key id. - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; @@ -329,14 +327,14 @@ WEAVE_ERROR EFR32Config::WriteConfigValue(Key key, bool val) return err; } -WEAVE_ERROR EFR32Config::WriteConfigValue(Key key, uint32_t val) +CHIP_ERROR EFR32Config::WriteConfigValue(Key key, uint32_t val) { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; - VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; @@ -351,14 +349,14 @@ WEAVE_ERROR EFR32Config::WriteConfigValue(Key key, uint32_t val) return err; } -WEAVE_ERROR EFR32Config::WriteConfigValue(Key key, uint64_t val) +CHIP_ERROR EFR32Config::WriteConfigValue(Key key, uint64_t val) { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; - VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; @@ -373,19 +371,19 @@ WEAVE_ERROR EFR32Config::WriteConfigValue(Key key, uint64_t val) return err; } -WEAVE_ERROR EFR32Config::WriteConfigValueStr(Key key, const char *str) +CHIP_ERROR EFR32Config::WriteConfigValueStr(Key key, const char *str) { return WriteConfigValueStr(key, str, (str != NULL) ? strlen(str) : 0); } -WEAVE_ERROR EFR32Config::WriteConfigValueStr(Key key, const char *str, size_t strLen) +CHIP_ERROR EFR32Config::WriteConfigValueStr(Key key, const char *str, size_t strLen) { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; - VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; @@ -410,14 +408,14 @@ WEAVE_ERROR EFR32Config::WriteConfigValueStr(Key key, const char *str, size_t st return err; } -WEAVE_ERROR EFR32Config::WriteConfigValueBin(Key key, const uint8_t *data, size_t dataLen) +CHIP_ERROR EFR32Config::WriteConfigValueBin(Key key, const uint8_t *data, size_t dataLen) { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; - VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; @@ -443,15 +441,15 @@ WEAVE_ERROR EFR32Config::WriteConfigValueBin(Key key, const uint8_t *data, size_ return err; } -WEAVE_ERROR EFR32Config::WriteConfigValueCounter(uint8_t counterIdx, uint32_t val) +CHIP_ERROR EFR32Config::WriteConfigValueCounter(uint8_t counterIdx, uint32_t val) { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; - Key key = kMinConfigKey_WeaveCounter + counterIdx; - VerifyOrExit(ValidConfigKey(key), err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + Key key = kMinConfigKey_ChipCounter + counterIdx; + VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; @@ -466,12 +464,12 @@ WEAVE_ERROR EFR32Config::WriteConfigValueCounter(uint8_t counterIdx, uint32_t va return err; } -WEAVE_ERROR EFR32Config::ClearConfigValue(Key key) +CHIP_ERROR EFR32Config::ClearConfigValue(Key key) { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; @@ -489,12 +487,12 @@ WEAVE_ERROR EFR32Config::ClearConfigValue(Key key) bool EFR32Config::ConfigValueExists(Key key) { - WEAVE_ERROR err; + CHIP_ERROR err; bool needClose = false; uint32_t objectType; size_t dataLen; - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); needClose = true; @@ -506,20 +504,20 @@ bool EFR32Config::ConfigValueExists(Key key) { nvm3_close(&handle); } - return (err == WEAVE_NO_ERROR); + return (err == CHIP_NO_ERROR); } -WEAVE_ERROR EFR32Config::FactoryResetConfig(void) +CHIP_ERROR EFR32Config::FactoryResetConfig(void) { // Deletes all nvm3 'Config' type objects. // Note- 'Factory' and 'Counter' type nvm3 objects are NOT deleted. - WEAVE_ERROR err; + CHIP_ERROR err; - // Iterate over all the Weave Config nvm3 records and delete each one... - err = ForEachRecord(kMinConfigKey_WeaveConfig, kMaxConfigKey_WeaveConfig, false, - [](const Key &nvm3Key, const size_t &length) -> WEAVE_ERROR { - WEAVE_ERROR err2; + // Iterate over all the Chip Config nvm3 records and delete each one... + err = ForEachRecord(kMinConfigKey_ChipConfig, kMaxConfigKey_ChipConfig, false, + [](const Key &nvm3Key, const size_t &length) -> CHIP_ERROR { + CHIP_ERROR err2; err2 = ClearConfigValue(nvm3Key); SuccessOrExit(err2); @@ -529,40 +527,40 @@ WEAVE_ERROR EFR32Config::FactoryResetConfig(void) }); // Return success at end of iterations. - if (err == WEAVE_END_OF_INPUT) + if (err == CHIP_END_OF_INPUT) { - err = WEAVE_NO_ERROR; + err = CHIP_NO_ERROR; } return err; } -WEAVE_ERROR EFR32Config::MapNvm3Error(Ecode_t nvm3Res) +CHIP_ERROR EFR32Config::MapNvm3Error(Ecode_t nvm3Res) { - WEAVE_ERROR err; + CHIP_ERROR err; switch (nvm3Res) { case ECODE_NVM3_OK: - err = WEAVE_NO_ERROR; + err = CHIP_NO_ERROR; break; case ECODE_NVM3_ERR_KEY_NOT_FOUND: - err = WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND; + err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; break; default: - err = (nvm3Res & 0xFF) + WEAVE_DEVICE_CONFIG_EFR32_NVM3_ERROR_MIN; + err = (nvm3Res & 0xFF) + CHIP_DEVICE_CONFIG_EFR32_NVM3_ERROR_MIN; break; } return err; } -WEAVE_ERROR EFR32Config::ForEachRecord(Key firstNvm3Key, Key lastNvm3Key, bool addNewRecord, ForEachRecordFunct funct) +CHIP_ERROR EFR32Config::ForEachRecord(Key firstNvm3Key, Key lastNvm3Key, bool addNewRecord, ForEachRecordFunct funct) { // Iterates through the specified range of nvm3 object key ids. // Invokes the callers CB function when appropriate. - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; for (Key nvm3Key = firstNvm3Key; nvm3Key <= lastNvm3Key; ++nvm3Key) { @@ -571,7 +569,7 @@ WEAVE_ERROR EFR32Config::ForEachRecord(Key firstNvm3Key, Key lastNvm3Key, bool a size_t dataLen; // Open nvm3 handle for reading on each iteration. - err = MapNvm3Error(nvm3_open(&handle, &weaveNvm3)); + err = MapNvm3Error(nvm3_open(&handle, &chipNvm3)); SuccessOrExit(err); // Find nvm3 object with current nvm3 iteration key. @@ -611,9 +609,9 @@ WEAVE_ERROR EFR32Config::ForEachRecord(Key firstNvm3Key, Key lastNvm3Key, bool a bool EFR32Config::ValidConfigKey(Key key) { - // Returns true if the key is in the valid Weave Config nvm3 key range. + // Returns true if the key is in the valid Chip Config nvm3 key range. - if ((key >= kMinConfigKey_WeaveFactory) && (key <= kMaxConfigKey_WeaveCounter)) + if ((key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_ChipCounter)) { return true; } @@ -624,7 +622,7 @@ bool EFR32Config::ValidConfigKey(Key key) void EFR32Config::RunConfigUnitTest() { // Run common unit test. - ::nl::Weave::DeviceLayer::Internal::RunConfigUnitTest(); + ::chip::DeviceLayer::Internal::RunConfigUnitTest(); } void EFR32Config::RepackNvm3Flash(void) @@ -637,5 +635,4 @@ void EFR32Config::RepackNvm3Flash(void) } // namespace Internal } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip diff --git a/src/platform/EFR32/Entropy.cpp b/src/platform/EFR32/Entropy.cpp index 7c3ef4a58a1b8a..85910b4c7db502 100644 --- a/src/platform/EFR32/Entropy.cpp +++ b/src/platform/EFR32/Entropy.cpp @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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,17 +17,16 @@ /** * @file - * Provides implementations for the Weave entropy sourcing functions + * Provides implementations for the Chip entropy sourcing functions * on the Silcon Labs EFR32 platforms. */ -#include -#include -#include +#include +#include #include #include -#if defined(_SILICON_LABS_32B_SERIES_1) +#if defined(_SILICON_LABS_32B_SERIES_1) #include #elif defined(_SILICON_LABS_32B_SERIES_2) extern "C" int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t *olen); @@ -36,22 +34,21 @@ extern "C" int mbedtls_hardware_poll(void *data, unsigned char *output, size_t l #error "Unsupported EFR32 series" #endif -using namespace ::nl; -using namespace ::nl::Weave; +using namespace ::chip; +using namespace ::chip::Chip; -#if !WEAVE_CONFIG_RNG_IMPLEMENTATION_NESTDRBG -#error "Nest DRBG implementation must be enabled on EFR32 platforms" -#endif // !WEAVE_CONFIG_RNG_IMPLEMENTATION_NESTDRBG +#if !CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG +#error "CHIP DRBG implementation must be enabled on EFR32 platforms" +#endif // !CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { namespace Internal { /** * Retrieve entropy from the underlying RNG source. * - * This function is called by the Nest DRBG to acquire entropy. + * This function is called by the CHIP DRBG to acquire entropy. */ int GetEntropy_EFR32(uint8_t *buf, size_t count) { @@ -59,26 +56,26 @@ int GetEntropy_EFR32(uint8_t *buf, size_t count) VerifyOrDie(count <= UINT16_MAX); -#if defined(_SILICON_LABS_32B_SERIES_1) -#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD +#if defined(_SILICON_LABS_32B_SERIES_1) +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD if (ThreadStackManagerImpl::IsInitialized()) { ThreadStackMgr().LockThreadStack(); } -#endif // WEAVE_DEVICE_CONFIG_ENABLE_THREAD +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD -#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD if (ThreadStackManagerImpl::IsInitialized()) { ThreadStackMgr().LockThreadStack(); } -#endif // WEAVE_DEVICE_CONFIG_ENABLE_THREAD +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD otError otErr = otPlatEntropyGet(buf, (uint16_t)count); if (otErr != OT_ERROR_NONE) { - res = WEAVE_ERROR_DRBG_ENTROPY_SOURCE_FAILED; + res = CHIP_ERROR_DRBG_ENTROPY_SOURCE_FAILED; } #elif defined(_SILICON_LABS_32B_SERIES_2) @@ -90,7 +87,7 @@ int GetEntropy_EFR32(uint8_t *buf, size_t count) res = mbedtls_hardware_poll(NULL, buf + entropy_len, count - entropy_len, &olen); if (res != 0) { - res = WEAVE_ERROR_DRBG_ENTROPY_SOURCE_FAILED; + res = CHIP_ERROR_DRBG_ENTROPY_SOURCE_FAILED; break; } @@ -103,11 +100,11 @@ int GetEntropy_EFR32(uint8_t *buf, size_t count) return res; } -WEAVE_ERROR InitEntropy() +CHIP_ERROR InitEntropy() { - WEAVE_ERROR err; + CHIP_ERROR err; - // Initialize the Nest DRBG. + // Initialize the CHIP DRBG. err = Platform::Security::InitSecureRandomDataSource(GetEntropy_EFR32, 64, NULL, 0); SuccessOrExit(err); @@ -120,14 +117,13 @@ WEAVE_ERROR InitEntropy() } exit: - if (err != WEAVE_NO_ERROR) + if (err != CHIP_NO_ERROR) { - WeaveLogError(Crypto, "InitEntropy() failed: 0x%08" PRIX32, err); + ChipLogError(Crypto, "InitEntropy() failed: 0x%08" PRIX32, err); } return err; } } // namespace Internal } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip diff --git a/src/platform/EFR32/GroupKeyStoreImpl.cpp b/src/platform/EFR32/GroupKeyStoreImpl.cpp index af7d9d33c3b244..6e2a4741374d03 100644 --- a/src/platform/EFR32/GroupKeyStoreImpl.cpp +++ b/src/platform/EFR32/GroupKeyStoreImpl.cpp @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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,30 +17,29 @@ /** * @file - * Provides an implementation of the Weave GroupKeyStore interface + * Provides an implementation of the Chip GroupKeyStore interface * for platforms based on the Silicon Labs SDK. */ -#include -#include +#include +#include -using namespace ::nl; -using namespace ::nl::Weave; -using namespace ::nl::Weave::Profiles::Security::AppKeys; +using namespace ::chip; +using namespace ::chip::Chip; +using namespace ::chip::Profiles::Security::AppKeys; -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { namespace Internal { -WEAVE_ERROR GroupKeyStoreImpl::RetrieveGroupKey(uint32_t keyId, WeaveGroupKey &key) +CHIP_ERROR GroupKeyStoreImpl::RetrieveGroupKey(uint32_t keyId, ChipGroupKey &key) { - WEAVE_ERROR err; + CHIP_ERROR err; // Iterate over all the GroupKey nvm3 records looking for a matching key... err = ForEachRecord(kConfigKey_GroupKeyBase, kConfigKey_GroupKeyMax, false, - [keyId, &key](const Key &nvm3Key, const size_t &length) -> WEAVE_ERROR { - WEAVE_ERROR err2; + [keyId, &key](const Key &nvm3Key, const size_t &length) -> CHIP_ERROR { + CHIP_ERROR err2; size_t keyLen; uint8_t buf[kMaxEncodedKeySize]; // (buf length == 45 bytes) uint32_t curKeyId; @@ -49,7 +47,7 @@ WEAVE_ERROR GroupKeyStoreImpl::RetrieveGroupKey(uint32_t keyId, WeaveGroupKey &k // Read the nvm3 obj binary data data into the buffer. err2 = ReadConfigValueBin(nvm3Key, buf, sizeof(buf), keyLen); - // Decode the Weave key id for the current key. + // Decode the Chip key id for the current key. err2 = DecodeGroupKeyId(buf, keyLen, curKeyId); SuccessOrExit(err2); @@ -60,8 +58,8 @@ WEAVE_ERROR GroupKeyStoreImpl::RetrieveGroupKey(uint32_t keyId, WeaveGroupKey &k err2 = DecodeGroupKey(buf, keyLen, key); SuccessOrExit(err2); - // End the iteration by returning a WEAVE_END_OF_INPUT result. - ExitNow(err2 = WEAVE_END_OF_INPUT); + // End the iteration by returning a CHIP_END_OF_INPUT result. + ExitNow(err2 = CHIP_END_OF_INPUT); } exit: @@ -71,11 +69,11 @@ WEAVE_ERROR GroupKeyStoreImpl::RetrieveGroupKey(uint32_t keyId, WeaveGroupKey &k // Modify error code for return. switch (err) { - case WEAVE_END_OF_INPUT: - err = WEAVE_NO_ERROR; // Match found. + case CHIP_END_OF_INPUT: + err = CHIP_NO_ERROR; // Match found. break; - case WEAVE_NO_ERROR: - err = WEAVE_ERROR_KEY_NOT_FOUND; // Match not found. + case CHIP_NO_ERROR: + err = CHIP_ERROR_KEY_NOT_FOUND; // Match not found. break; default: break; @@ -84,9 +82,9 @@ WEAVE_ERROR GroupKeyStoreImpl::RetrieveGroupKey(uint32_t keyId, WeaveGroupKey &k return err; } -WEAVE_ERROR GroupKeyStoreImpl::StoreGroupKey(const WeaveGroupKey &key) +CHIP_ERROR GroupKeyStoreImpl::StoreGroupKey(const ChipGroupKey &key) { - WEAVE_ERROR err; + CHIP_ERROR err; // Delete any existing group key with the same id (this may or may not exit). DeleteGroupKey(key.KeyId); // no error checking here. @@ -94,8 +92,8 @@ WEAVE_ERROR GroupKeyStoreImpl::StoreGroupKey(const WeaveGroupKey &key) // Iterate over all the GroupKey nvm3 records looking for the first // empty nvm3 key where we can store the data. (Note- use arg addNewrecord=true) err = ForEachRecord(kConfigKey_GroupKeyBase, kConfigKey_GroupKeyMax, true, - [&key](const Key &nvm3Key, const size_t &length) -> WEAVE_ERROR { - WEAVE_ERROR err2; + [&key](const Key &nvm3Key, const size_t &length) -> CHIP_ERROR { + CHIP_ERROR err2; size_t keyLen; uint8_t buf[kMaxEncodedKeySize]; // (buf length == 45 bytes) @@ -107,8 +105,8 @@ WEAVE_ERROR GroupKeyStoreImpl::StoreGroupKey(const WeaveGroupKey &key) err2 = WriteConfigValueBin(nvm3Key, buf, keyLen); SuccessOrExit(err2); - // End the iteration by returning a WEAVE_END_OF_INPUT result. - ExitNow(err2 = WEAVE_END_OF_INPUT); + // End the iteration by returning a CHIP_END_OF_INPUT result. + ExitNow(err2 = CHIP_END_OF_INPUT); exit: return err2; @@ -117,26 +115,26 @@ WEAVE_ERROR GroupKeyStoreImpl::StoreGroupKey(const WeaveGroupKey &key) // Modify error code for return. switch (err) { - case WEAVE_END_OF_INPUT: - err = WEAVE_NO_ERROR; // Key entry was stored. + case CHIP_END_OF_INPUT: + err = CHIP_NO_ERROR; // Key entry was stored. break; - case WEAVE_NO_ERROR: - err = WEAVE_ERROR_KEY_NOT_FOUND; // Key entry was not stored. + case CHIP_NO_ERROR: + err = CHIP_ERROR_KEY_NOT_FOUND; // Key entry was not stored. break; default: break; } - if (err == WEAVE_NO_ERROR) + if (err == CHIP_NO_ERROR) { -#if WEAVE_PROGRESS_LOGGING +#if CHIP_PROGRESS_LOGGING { char extraKeyInfo[32]; - if (WeaveKeyId::IsAppEpochKey(key.KeyId)) + if (ChipKeyId::IsAppEpochKey(key.KeyId)) { snprintf(extraKeyInfo, sizeof(extraKeyInfo), ", start time %" PRId32, key.StartTime); } - else if (WeaveKeyId::IsAppGroupMasterKey(key.KeyId)) + else if (ChipKeyId::IsAppGroupMasterKey(key.KeyId)) { snprintf(extraKeyInfo, sizeof(extraKeyInfo), ", global id 0x%08" PRIX32, key.GlobalId); } @@ -145,31 +143,31 @@ WEAVE_ERROR GroupKeyStoreImpl::StoreGroupKey(const WeaveGroupKey &key) extraKeyInfo[0] = 0; } -#if WEAVE_CONFIG_SECURITY_TEST_MODE - WeaveLogProgress(SecurityManager, +#if CHIP_CONFIG_SECURITY_TEST_MODE + ChipLogProgress(SecurityManager, "GroupKeyStore: storing key 0x%08" PRIX32 " (%s), len %" PRId8 ", data 0x%02" PRIX8 "...%s", - key.KeyId, WeaveKeyId::DescribeKey(key.KeyId), key.KeyLen, key.Key[0], extraKeyInfo); + key.KeyId, ChipKeyId::DescribeKey(key.KeyId), key.KeyLen, key.Key[0], extraKeyInfo); #else - WeaveLogProgress(SecurityManager, "GroupKeyStore: storing key 0x%08" PRIX32 " (%s), len %" PRId8 "%s", - key.KeyId, WeaveKeyId::DescribeKey(key.KeyId), key.KeyLen, extraKeyInfo); + ChipLogProgress(SecurityManager, "GroupKeyStore: storing key 0x%08" PRIX32 " (%s), len %" PRId8 "%s", + key.KeyId, ChipKeyId::DescribeKey(key.KeyId), key.KeyLen, extraKeyInfo); #endif } -#endif // WEAVE_PROGRESS_LOGGING +#endif // CHIP_PROGRESS_LOGGING } return err; } -WEAVE_ERROR GroupKeyStoreImpl::DeleteGroupKey(uint32_t keyId) +CHIP_ERROR GroupKeyStoreImpl::DeleteGroupKey(uint32_t keyId) { - WEAVE_ERROR err; + CHIP_ERROR err; // Iterate over all the GroupKey nvm3 records looking for a matching key... err = ForEachRecord(kConfigKey_GroupKeyBase, kConfigKey_GroupKeyMax, false, - [keyId](const Key &nvm3Key, const size_t &length) -> WEAVE_ERROR { - WEAVE_ERROR err2; + [keyId](const Key &nvm3Key, const size_t &length) -> CHIP_ERROR { + CHIP_ERROR err2; size_t keyLen; uint8_t buf[kMaxEncodedKeySize]; // (buf length == 45 bytes) uint32_t curKeyId; @@ -178,7 +176,7 @@ WEAVE_ERROR GroupKeyStoreImpl::DeleteGroupKey(uint32_t keyId) err2 = ReadConfigValueBin(nvm3Key, buf, sizeof(buf), keyLen); SuccessOrExit(err2); - // Decode the Weave key id for the current group key. + // Decode the Chip key id for the current group key. err2 = DecodeGroupKeyId(buf, keyLen, curKeyId); SuccessOrExit(err2); @@ -186,10 +184,10 @@ WEAVE_ERROR GroupKeyStoreImpl::DeleteGroupKey(uint32_t keyId) if (curKeyId == keyId) { err2 = ClearConfigValue(nvm3Key); - WeaveLogProgress(DeviceLayer, "GroupKeyStore: deleting key 0x%08" PRIX32, curKeyId); + ChipLogProgress(DeviceLayer, "GroupKeyStore: deleting key 0x%08" PRIX32, curKeyId); - // End the iteration by returning a WEAVE_END_OF_INPUT result. - ExitNow(err2 = WEAVE_END_OF_INPUT); + // End the iteration by returning a CHIP_END_OF_INPUT result. + ExitNow(err2 = CHIP_END_OF_INPUT); } exit: @@ -199,11 +197,11 @@ WEAVE_ERROR GroupKeyStoreImpl::DeleteGroupKey(uint32_t keyId) // Modify error code for return. switch (err) { - case WEAVE_END_OF_INPUT: - err = WEAVE_NO_ERROR; // Key entry was deleted. + case CHIP_END_OF_INPUT: + err = CHIP_NO_ERROR; // Key entry was deleted. break; - case WEAVE_NO_ERROR: - err = WEAVE_ERROR_KEY_NOT_FOUND; // Key entry was not deleted. + case CHIP_NO_ERROR: + err = CHIP_ERROR_KEY_NOT_FOUND; // Key entry was not deleted. break; default: break; @@ -212,14 +210,14 @@ WEAVE_ERROR GroupKeyStoreImpl::DeleteGroupKey(uint32_t keyId) return err; } -WEAVE_ERROR GroupKeyStoreImpl::DeleteGroupKeysOfAType(uint32_t keyType) +CHIP_ERROR GroupKeyStoreImpl::DeleteGroupKeysOfAType(uint32_t keyType) { - WEAVE_ERROR err; + CHIP_ERROR err; // Iterate over all the GroupKey nvm3 records looking for a matching key... err = ForEachRecord(kConfigKey_GroupKeyBase, kConfigKey_GroupKeyMax, false, - [keyType](const Key &nvm3Key, const size_t &length) -> WEAVE_ERROR { - WEAVE_ERROR err2; + [keyType](const Key &nvm3Key, const size_t &length) -> CHIP_ERROR { + CHIP_ERROR err2; size_t keyLen; uint8_t buf[kMaxEncodedKeySize]; // (buf length == 45 bytes) uint32_t curKeyId; @@ -228,15 +226,15 @@ WEAVE_ERROR GroupKeyStoreImpl::DeleteGroupKeysOfAType(uint32_t keyType) err2 = ReadConfigValueBin(nvm3Key, buf, sizeof(buf), keyLen); SuccessOrExit(err2); - // Decode the Weave key id for the current group key. + // Decode the Chip key id for the current group key. err2 = DecodeGroupKeyId(buf, keyLen, curKeyId); SuccessOrExit(err2); // If the current key matches the type we are looking for, delete the nvm3 record. - if (WeaveKeyId::GetType(curKeyId) == keyType) + if (ChipKeyId::GetType(curKeyId) == keyType) { err2 = ClearConfigValue(nvm3Key); - WeaveLogProgress(DeviceLayer, "GroupKeyStore: deleting key 0x%08" PRIX32, curKeyId); + ChipLogProgress(DeviceLayer, "GroupKeyStore: deleting key 0x%08" PRIX32, curKeyId); } exit: @@ -246,20 +244,20 @@ WEAVE_ERROR GroupKeyStoreImpl::DeleteGroupKeysOfAType(uint32_t keyType) return err; } -WEAVE_ERROR GroupKeyStoreImpl::EnumerateGroupKeys(uint32_t keyType, +CHIP_ERROR GroupKeyStoreImpl::EnumerateGroupKeys(uint32_t keyType, uint32_t *keyIds, uint8_t keyIdsArraySize, uint8_t & keyCount) { - WEAVE_ERROR err; + CHIP_ERROR err; keyCount = 0; // Iterate over all the GroupKey records looking for keys of the specified type... err = ForEachRecord( kConfigKey_GroupKeyBase, kConfigKey_GroupKeyMax, false, - [keyType, keyIds, keyIdsArraySize, &keyCount](const Key &nvm3Key, const size_t &length) -> WEAVE_ERROR { - WEAVE_ERROR err2; + [keyType, keyIds, keyIdsArraySize, &keyCount](const Key &nvm3Key, const size_t &length) -> CHIP_ERROR { + CHIP_ERROR err2; size_t keyLen; uint8_t buf[kMaxEncodedKeySize]; // (buf length == 45 bytes) uint32_t curKeyId; @@ -268,17 +266,17 @@ WEAVE_ERROR GroupKeyStoreImpl::EnumerateGroupKeys(uint32_t keyType, err2 = ReadConfigValueBin(nvm3Key, buf, sizeof(buf), keyLen); SuccessOrExit(err2); - // Decode the Weave key id for the current group key. + // Decode the Chip key id for the current group key. err2 = DecodeGroupKeyId(buf, keyLen, curKeyId); SuccessOrExit(err2); // If the current key matches the type we're looking for, add it to the keyIds array. - if ((keyType == WeaveKeyId::kType_None) || (WeaveKeyId::GetType(curKeyId) == keyType)) + if ((keyType == ChipKeyId::kType_None) || (ChipKeyId::GetType(curKeyId) == keyType)) { keyIds[keyCount++] = curKeyId; // Stop iterating if there's no more room in the keyIds array. - VerifyOrExit(keyCount < keyIdsArraySize, err2 = WEAVE_ERROR_BUFFER_TOO_SMALL); + VerifyOrExit(keyCount < keyIdsArraySize, err2 = CHIP_ERROR_BUFFER_TOO_SMALL); } exit: @@ -286,22 +284,22 @@ WEAVE_ERROR GroupKeyStoreImpl::EnumerateGroupKeys(uint32_t keyType, }); // Simply return a truncated list if there are more matching keys than will fit in the array. - if (err == WEAVE_ERROR_BUFFER_TOO_SMALL) + if (err == CHIP_ERROR_BUFFER_TOO_SMALL) { - err = WEAVE_NO_ERROR; + err = CHIP_NO_ERROR; } return err; } -WEAVE_ERROR GroupKeyStoreImpl::Clear(void) +CHIP_ERROR GroupKeyStoreImpl::Clear(void) { - WEAVE_ERROR err; + CHIP_ERROR err; // Iterate over all the GroupKey nvm3 records deleting each one... err = ForEachRecord(kConfigKey_GroupKeyBase, kConfigKey_GroupKeyMax, false, - [](const Key &nvm3Key, const size_t &length) -> WEAVE_ERROR { - WEAVE_ERROR err2; + [](const Key &nvm3Key, const size_t &length) -> CHIP_ERROR { + CHIP_ERROR err2; err2 = ClearConfigValue(nvm3Key); SuccessOrExit(err2); @@ -313,39 +311,39 @@ WEAVE_ERROR GroupKeyStoreImpl::Clear(void) return err; } -WEAVE_ERROR GroupKeyStoreImpl::RetrieveLastUsedEpochKeyId(void) +CHIP_ERROR GroupKeyStoreImpl::RetrieveLastUsedEpochKeyId(void) { - WEAVE_ERROR err; + CHIP_ERROR err; err = ReadConfigValue(kConfigKey_LastUsedEpochKeyId, LastUsedEpochKeyId); - if (err == WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND) + if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { - LastUsedEpochKeyId = WeaveKeyId::kNone; - err = WEAVE_NO_ERROR; + LastUsedEpochKeyId = ChipKeyId::kNone; + err = CHIP_NO_ERROR; } return err; } -WEAVE_ERROR GroupKeyStoreImpl::StoreLastUsedEpochKeyId(void) +CHIP_ERROR GroupKeyStoreImpl::StoreLastUsedEpochKeyId(void) { return WriteConfigValue(kConfigKey_LastUsedEpochKeyId, LastUsedEpochKeyId); } -WEAVE_ERROR GroupKeyStoreImpl::Init() +CHIP_ERROR GroupKeyStoreImpl::Init() { // Nothing to do - return WEAVE_NO_ERROR; + return CHIP_NO_ERROR; } -WEAVE_ERROR GroupKeyStoreImpl::EncodeGroupKey(const WeaveGroupKey &key, +CHIP_ERROR GroupKeyStoreImpl::EncodeGroupKey(const ChipGroupKey &key, uint8_t * buf, size_t bufSize, size_t & encodedKeyLen) { - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; uint8_t * p = buf; - VerifyOrExit(bufSize >= kFixedEncodedKeySize + key.KeyLen, err = WEAVE_ERROR_BUFFER_TOO_SMALL); + VerifyOrExit(bufSize >= kFixedEncodedKeySize + key.KeyLen, err = CHIP_ERROR_BUFFER_TOO_SMALL); Encoding::LittleEndian::Write32(p, key.KeyId); Encoding::LittleEndian::Write32(p, key.StartTime); @@ -359,11 +357,11 @@ WEAVE_ERROR GroupKeyStoreImpl::EncodeGroupKey(const WeaveGroupKey &key, return err; } -WEAVE_ERROR GroupKeyStoreImpl::DecodeGroupKeyId(const uint8_t *encodedKey, size_t encodedKeyLen, uint32_t &keyId) +CHIP_ERROR GroupKeyStoreImpl::DecodeGroupKeyId(const uint8_t *encodedKey, size_t encodedKeyLen, uint32_t &keyId) { - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit(encodedKeyLen >= kFixedEncodedKeySize, err = WEAVE_ERROR_INVALID_ARGUMENT); + VerifyOrExit(encodedKeyLen >= kFixedEncodedKeySize, err = CHIP_ERROR_INVALID_ARGUMENT); keyId = Encoding::LittleEndian::Get32(encodedKey); @@ -371,18 +369,18 @@ WEAVE_ERROR GroupKeyStoreImpl::DecodeGroupKeyId(const uint8_t *encodedKey, size_ return err; } -WEAVE_ERROR GroupKeyStoreImpl::DecodeGroupKey(const uint8_t *encodedKey, size_t encodedKeyLen, WeaveGroupKey &key) +CHIP_ERROR GroupKeyStoreImpl::DecodeGroupKey(const uint8_t *encodedKey, size_t encodedKeyLen, ChipGroupKey &key) { - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; const uint8_t *p = encodedKey; - VerifyOrExit(encodedKeyLen >= kFixedEncodedKeySize, err = WEAVE_ERROR_INVALID_ARGUMENT); + VerifyOrExit(encodedKeyLen >= kFixedEncodedKeySize, err = CHIP_ERROR_INVALID_ARGUMENT); key.KeyId = Encoding::LittleEndian::Read32(p); key.StartTime = Encoding::LittleEndian::Read32(p); key.KeyLen = Encoding::Read8(p); - VerifyOrExit(encodedKeyLen >= kFixedEncodedKeySize + key.KeyLen, err = WEAVE_ERROR_INVALID_ARGUMENT); + VerifyOrExit(encodedKeyLen >= kFixedEncodedKeySize + key.KeyLen, err = CHIP_ERROR_INVALID_ARGUMENT); memcpy(key.Key, p, key.KeyLen); @@ -392,5 +390,4 @@ WEAVE_ERROR GroupKeyStoreImpl::DecodeGroupKey(const uint8_t *encodedKey, size_t } // namespace Internal } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip diff --git a/src/platform/EFR32/Logging.cpp b/src/platform/EFR32/Logging.cpp index ba68860b491dd9..3c501a3b505178 100644 --- a/src/platform/EFR32/Logging.cpp +++ b/src/platform/EFR32/Logging.cpp @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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,7 +17,7 @@ /** * @file - * Provides implementations for the OpenWeave and LwIP logging + * Provides implementations for the OpenChip and LwIP logging * functions on Silicon Labs EFR32 platforms. * * Logging should be initialized by a call to efr32LogInit(). A @@ -30,8 +29,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -60,13 +59,9 @@ #define LOG_EFR32 " " -#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD -#include -#endif // WEAVE_DEVICE_CONFIG_ENABLE_THREAD - -using namespace ::nl::Weave; -using namespace ::nl::Weave::DeviceLayer; -using namespace ::nl::Weave::DeviceLayer::Internal; +using namespace ::chip::Chip; +using namespace ::chip::DeviceLayer; +using namespace ::chip::DeviceLayer::Internal; static bool sLogInitialized = false; static uint8_t sLogBuffer[LOG_RTT_BUFFER_SIZE]; @@ -75,13 +70,13 @@ static uint8_t sLogBuffer[LOG_RTT_BUFFER_SIZE]; * Print a log message to RTT */ static void PrintLog(const char *msg) -{ +{ #if EFR32_LOG_ENABLED if (sLogInitialized) { size_t sz; sz = strlen(msg); - SEGGER_RTT_WriteNoLock(0, msg, sz); + SEGGER_RTT_WriteNoLock(0, msg, sz); const char *newline = "\r\n"; sz = strlen(newline); @@ -113,7 +108,7 @@ extern "C" void efr32Log(const char *aFormat, ...) va_start(v, aFormat); #if EFR32_LOG_ENABLED - char formattedMsg[WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE]; + char formattedMsg[CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE]; strcpy(formattedMsg, LOG_EFR32); size_t prefixLen = strlen(formattedMsg); @@ -134,24 +129,23 @@ namespace { void GetModuleName(char *buf, uint8_t module) { - if (module == ::nl::Weave::Logging::kLogModule_DeviceLayer) + if (module == ::chip::Logging::kLogModule_DeviceLayer) { memcpy(buf, "DL", 3); } else { - ::nl::Weave::Logging::GetModuleName(buf, module); + ::chip::Logging::GetModuleName(buf, module); } } } // unnamed namespace -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { /** - * Called whenever a log message is emitted by Weave or LwIP. + * Called whenever a log message is emitted by Chip or LwIP. * * This function is intended be overridden by the application to, e.g., * schedule output of queued log entries. @@ -161,28 +155,26 @@ void __attribute__((weak)) OnLogOutput(void) } } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip -namespace nl { -namespace Weave { +namespace chip { namespace Logging { /** - * OpenWeave log output function. + * OpenChip log output function. */ void Log(uint8_t module, uint8_t category, const char *aFormat, ...) { va_list v; va_start(v, aFormat); -#if EFR32_LOG_ENABLED && _WEAVE_USE_LOGGING +#if EFR32_LOG_ENABLED && _CHIP_USE_LOGGING if (IsCategoryEnabled(category)) { - char formattedMsg[WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE]; + char formattedMsg[CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE]; size_t formattedMsgLen; - constexpr size_t maxPrefixLen = nlWeaveLoggingModuleNameLen + 3; + constexpr size_t maxPrefixLen = nlChipLoggingModuleNameLen + 3; static_assert(sizeof(formattedMsg) > maxPrefixLen); switch (category) @@ -215,19 +207,19 @@ void Log(uint8_t module, uint8_t category, const char *aFormat, ...) { formattedMsg[sizeof formattedMsg - 1] = '\0'; } - + PrintLog(formattedMsg); } // Let the application know that a log message has been emitted. DeviceLayer::OnLogOutput(); -#endif // EFR32_LOG_ENABLED && _WEAVE_USE_LOGGING +#endif // EFR32_LOG_ENABLED && _CHIP_USE_LOGGING va_end(v); } } // namespace Logging -} // namespace Weave -} // namespace nl +} // namespace chip + /** * LwIP log output function. @@ -238,7 +230,7 @@ extern "C" void LwIPLog(const char *aFormat, ...) va_start(v, aFormat); #if EFR32_LOG_ENABLED - char formattedMsg[WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE]; + char formattedMsg[CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE]; strcpy(formattedMsg, LOG_LWIP); size_t prefixLen = strlen(formattedMsg); @@ -259,7 +251,7 @@ extern "C" void LwIPLog(const char *aFormat, ...) /** * Platform logging function for OpenThread */ -#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) { IgnoreUnusedVariable(aLogRegion); @@ -267,7 +259,7 @@ extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const ch va_start(v, aFormat); #if EFR32_LOG_ENABLED - char formattedMsg[WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE]; + char formattedMsg[CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE]; if (sLogInitialized) { @@ -309,7 +301,7 @@ extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const ch #endif // EFR32_LOG_ENABLED va_end(v); } -#endif // WEAVE_DEVICE_CONFIG_ENABLE_THREAD +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD #if HARD_FAULT_LOG_ENABLE && EFR32_LOG_ENABLED diff --git a/src/platform/EFR32/NetworkProvisioningServerImpl.cpp b/src/platform/EFR32/NetworkProvisioningServerImpl.cpp index c055f2d37a81df..0d8f99d888df59 100644 --- a/src/platform/EFR32/NetworkProvisioningServerImpl.cpp +++ b/src/platform/EFR32/NetworkProvisioningServerImpl.cpp @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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. @@ -16,28 +15,27 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include -#include +#include -namespace nl { -namespace Weave { + +namespace chip { namespace DeviceLayer { namespace Internal { NetworkProvisioningServerImpl NetworkProvisioningServerImpl::sInstance; -WEAVE_ERROR NetworkProvisioningServerImpl::_Init(void) +CHIP_ERROR NetworkProvisioningServerImpl::_Init(void) { return GenericNetworkProvisioningServerImpl::DoInit(); } } // namespace Internal } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip diff --git a/src/platform/EFR32/PlatformManagerImpl.cpp b/src/platform/EFR32/PlatformManagerImpl.cpp index bfdcb5670b9562..3fd57ebf16005d 100644 --- a/src/platform/EFR32/PlatformManagerImpl.cpp +++ b/src/platform/EFR32/PlatformManagerImpl.cpp @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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. @@ -22,21 +21,20 @@ * for EFR32 platforms using the Silicon Labs EFR32 SDK. */ -#include -#include -#include +#include +#include +#include #include -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { PlatformManagerImpl PlatformManagerImpl::sInstance; -WEAVE_ERROR PlatformManagerImpl::_InitWeaveStack(void) +CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) { - WEAVE_ERROR err; + CHIP_ERROR err; // Initialize the configuration system. err = Internal::EFR32Config::Init(); @@ -45,9 +43,9 @@ WEAVE_ERROR PlatformManagerImpl::_InitWeaveStack(void) // Initialize LwIP. tcpip_init(NULL, NULL); - // Call _InitWeaveStack() on the generic implementation base class + // Call _InitChipStack() on the generic implementation base class // to finish the initialization process. - err = Internal::GenericPlatformManagerImpl_FreeRTOS::_InitWeaveStack(); + err = Internal::GenericPlatformManagerImpl_FreeRTOS::_InitChipStack(); SuccessOrExit(err); exit: @@ -55,5 +53,4 @@ WEAVE_ERROR PlatformManagerImpl::_InitWeaveStack(void) } } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip diff --git a/src/platform/EFR32/SoftwareUpdateManagerImpl.cpp b/src/platform/EFR32/SoftwareUpdateManagerImpl.cpp index 609faf96a664de..9cb2daf8842574 100644 --- a/src/platform/EFR32/SoftwareUpdateManagerImpl.cpp +++ b/src/platform/EFR32/SoftwareUpdateManagerImpl.cpp @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 Google LLC. - * 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. @@ -16,32 +15,30 @@ * limitations under the License. */ -#include +#include -#if WEAVE_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER +#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER -#include -#include +#include +#include -#include -#include +#include +#include -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { SoftwareUpdateManagerImpl SoftwareUpdateManagerImpl::sInstance; -WEAVE_ERROR SoftwareUpdateManagerImpl::_Init(void) +CHIP_ERROR SoftwareUpdateManagerImpl::_Init(void) { Internal::GenericSoftwareUpdateManagerImpl_BDX::DoInit(); Internal::GenericSoftwareUpdateManagerImpl::DoInit(); - return WEAVE_NO_ERROR; + return CHIP_NO_ERROR; } } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip -#endif // WEAVE_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER +#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/platform/EFR32/ThreadStackManagerImpl.cpp b/src/platform/EFR32/ThreadStackManagerImpl.cpp index 0d527abecb7428..abbfc0aa075539 100644 --- a/src/platform/EFR32/ThreadStackManagerImpl.cpp +++ b/src/platform/EFR32/ThreadStackManagerImpl.cpp @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2019 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. @@ -24,29 +23,28 @@ * */ -#include -#include -#include +#include +#include +#include -#include -#include +#include +#include -namespace nl { -namespace Weave { +namespace chip { namespace DeviceLayer { -using namespace ::nl::Weave::DeviceLayer::Internal; +using namespace ::chip::DeviceLayer::Internal; ThreadStackManagerImpl ThreadStackManagerImpl::sInstance; -WEAVE_ERROR ThreadStackManagerImpl::_InitThreadStack(void) +CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack(void) { return InitThreadStack(NULL); } -WEAVE_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance *otInst) +CHIP_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance *otInst) { - WEAVE_ERROR err = WEAVE_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; // Initialize the generic implementation base classes. err = GenericThreadStackManagerImpl_FreeRTOS::DoInit(); @@ -64,10 +62,9 @@ bool ThreadStackManagerImpl::IsInitialized() } } // namespace DeviceLayer -} // namespace Weave -} // namespace nl +} // namespace chip -using namespace ::nl::Weave::DeviceLayer; +using namespace ::chip::DeviceLayer; /** * Glue function called directly by the OpenThread stack when tasklet processing work diff --git a/src/platform/EFR32/freertos_bluetooth.c b/src/platform/EFR32/freertos_bluetooth.c index 6ff58476d0d35b..0301b9be62aae3 100644 --- a/src/platform/EFR32/freertos_bluetooth.c +++ b/src/platform/EFR32/freertos_bluetooth.c @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2020 Google LLC. - * 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. @@ -22,7 +21,7 @@ #include "rtos_gecko.h" #include "gecko_configuration.h" -#include +#include #ifdef CONFIGURATION_HEADER #include CONFIGURATION_HEADER diff --git a/src/platform/EFR32/gatt_db.c b/src/platform/EFR32/gatt_db.c index dfb982ac34c82a..89e56c72006917 100644 --- a/src/platform/EFR32/gatt_db.c +++ b/src/platform/EFR32/gatt_db.c @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2020 Google LLC. - * 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.