diff --git a/config/esp32/components/chip/Kconfig b/config/esp32/components/chip/Kconfig index cd179a2ff2e066..0e926f9b6a9f8e 100644 --- a/config/esp32/components/chip/Kconfig +++ b/config/esp32/components/chip/Kconfig @@ -487,8 +487,8 @@ menu "CHIP Device Layer" menu "BLE Options" - config ENABLE_WOBLE - bool "Enable CHIP-over-BLE (WoBLE) Support" + config ENABLE_CHIPOBLE + bool "Enable CHIP-over-BLE (CHIPoBLE) Support" default y help Enables support for sending and receiving CHIP messages over a BLE connection. @@ -500,7 +500,7 @@ menu "CHIP Device Layer" config BLE_DEVICE_NAME_PREFIX string "BLE Device Name Prefix" default "CHIP-" - depends on ENABLE_WOBLE + depends on ENABLE_CHIPOBLE help A prefix string used in forming the BLE device name. The remainder of the name consists of the final two bytes of the device's CHIP node id in hex. @@ -512,7 +512,7 @@ menu "CHIP Device Layer" config BLE_FAST_ADVERTISING_INTERVAL int "Fast Advertising Interval" default 800 - depends on ENABLE_WOBLE + depends on ENABLE_CHIPOBLE help The interval (in units of 0.625ms) at which the device will send BLE advertisements while in fast advertising mode. @@ -520,24 +520,24 @@ menu "CHIP Device Layer" config BLE_SLOW_ADVERTISING_INTERVAL int "Slow Advertising Interval" default 3200 - depends on ENABLE_WOBLE + depends on ENABLE_CHIPOBLE help The interval (in units of 0.625ms) at which the device will send BLE advertisements while in slow advertising mode. - config WOBLE_SINGLE_CONNECTION + config CHIPOBLE_SINGLE_CONNECTION bool "Single Connection Mode" default n - depends on ENABLE_WOBLE + depends on ENABLE_CHIPOBLE help Limit support for CHIP-over-BLE (WoBLE) to a single inbound connection. When set, WoBLE advertisements will stop while a WoBLE connection is active. - config WOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED + config CHIPOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED bool "Disable Advertising when Provisioned" default n - depends on ENABLE_WOBLE + depends on ENABLE_CHIPOBLE help Automatically disable CHIP-over-BLE (WoBLE) advertising when the device transitions to a fully provisioned state. diff --git a/examples/wifi-echo/server/esp32/sdkconfig.defaults b/examples/wifi-echo/server/esp32/sdkconfig.defaults index 14a0599c065e96..77969f49798d47 100644 --- a/examples/wifi-echo/server/esp32/sdkconfig.defaults +++ b/examples/wifi-echo/server/esp32/sdkconfig.defaults @@ -27,6 +27,9 @@ CONFIG_ESPTOOLPY_COMPRESSED=y CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 +#enable BT +CONFIG_BT_ENABLED=y + #enable lwip ipv6 autoconfig CONFIG_LWIP_IPV6_AUTOCONFIG=y diff --git a/examples/wifi-echo/server/esp32/sdkconfig_devkit.defaults b/examples/wifi-echo/server/esp32/sdkconfig_devkit.defaults index 6750625dde0db7..336d38da857b99 100644 --- a/examples/wifi-echo/server/esp32/sdkconfig_devkit.defaults +++ b/examples/wifi-echo/server/esp32/sdkconfig_devkit.defaults @@ -28,6 +28,9 @@ CONFIG_ESPTOOLPY_COMPRESSED=y CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 +#enable BT +CONFIG_BT_ENABLED=y + #enable lwip ipv6 autoconfig CONFIG_LWIP_IPV6_AUTOCONFIG=y diff --git a/examples/wifi-echo/server/esp32/sdkconfig_m5stack.defaults b/examples/wifi-echo/server/esp32/sdkconfig_m5stack.defaults index 497991c0b9256a..ca53405dcc9842 100644 --- a/examples/wifi-echo/server/esp32/sdkconfig_m5stack.defaults +++ b/examples/wifi-echo/server/esp32/sdkconfig_m5stack.defaults @@ -28,6 +28,9 @@ CONFIG_ESPTOOLPY_COMPRESSED=y CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 +#enable BT +CONFIG_BT_ENABLED=y + #enable lwip ipv6 autoconfig CONFIG_LWIP_IPV6_AUTOCONFIG=y diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp index d93f49a4236b1b..53cbb3e1015f86 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp @@ -26,9 +26,9 @@ #ifndef GENERIC_CONFIGURATION_MANAGER_IMPL_IPP #define GENERIC_CONFIGURATION_MANAGER_IMPL_IPP +#include #include #include -#include #include #include @@ -43,7 +43,7 @@ namespace Internal { // Fully instantiate the generic implementation class in whatever compilation unit includes this file. template class GenericConfigurationManagerImpl; -template +template CHIP_ERROR GenericConfigurationManagerImpl::_Init() { mFlags = 0; @@ -53,20 +53,22 @@ CHIP_ERROR GenericConfigurationManagerImpl::_Init() SetFlag(mFlags, kFlag_IsServiceProvisioned, Impl()->ConfigValueExists(ImplClass::kConfigKey_ServiceConfig)); SetFlag(mFlags, kFlag_IsMemberOfFabric, Impl()->ConfigValueExists(ImplClass::kConfigKey_FabricId)); SetFlag(mFlags, kFlag_IsPairedToAccount, Impl()->ConfigValueExists(ImplClass::kConfigKey_PairedAccountId)); - SetFlag(mFlags, kFlag_OperationalDeviceCredentialsProvisioned, Impl()->ConfigValueExists(ImplClass::kConfigKey_OperationalDeviceCert)); + SetFlag(mFlags, kFlag_OperationalDeviceCredentialsProvisioned, + Impl()->ConfigValueExists(ImplClass::kConfigKey_OperationalDeviceCert)); return CHIP_NO_ERROR; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_ConfigureChipStack() { CHIP_ERROR err = CHIP_NO_ERROR; + +#if CHIP_CONFIG_ENABLE_FABRIC_STATE size_t pairingCodeLen; static char sPairingCodeBuf[ConfigurationManager::kMaxPairingCodeLength + 1]; -#if CHIP_CONFIG_ENABLE_FABRIC_STATE // Configure the CHIP FabricState object with the local node id. err = Impl()->_GetDeviceId(FabricState.LocalNodeId); SuccessOrExit(err); @@ -114,11 +116,13 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ConfigureChipStack() #endif // CHIP_PROGRESS_LOGGING + SuccessOrExit(err); + exit: return err; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetFirmwareRevision(char * buf, size_t bufSize, size_t & outLen) { #ifdef CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION @@ -136,9 +140,9 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetFirmwareRevision(char } } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetFirmwareBuildTime(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth, - uint8_t & hour, uint8_t & minute, uint8_t & second) + uint8_t & hour, uint8_t & minute, uint8_t & second) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -154,7 +158,7 @@ exit: return err; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetManufacturerDeviceId(uint64_t & deviceId) { CHIP_ERROR err; @@ -165,20 +169,20 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetManufacturerDeviceId( if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { deviceId = TestDeviceId; - err = CHIP_NO_ERROR; + err = CHIP_NO_ERROR; } #endif return err; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StoreManufacturerDeviceId(uint64_t deviceId) { return Impl()->WriteConfigValue(ImplClass::kConfigKey_MfrDeviceId, deviceId); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetSerialNumber(char * buf, size_t bufSize, size_t & serialNumLen) { CHIP_ERROR err; @@ -200,25 +204,25 @@ exit: return err; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StoreSerialNumber(const char * serialNum, size_t serialNumLen) { return Impl()->WriteConfigValueStr(ImplClass::kConfigKey_SerialNum, serialNum, serialNumLen); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetPrimaryWiFiMACAddress(uint8_t * buf) { return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StorePrimaryWiFiMACAddress(const uint8_t * buf) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetPrimary802154MACAddress(uint8_t * buf) { #if CHIP_DEVICE_CONFIG_ENABLE_THREAD @@ -228,13 +232,13 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetPrimary802154MACAddre #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StorePrimary802154MACAddress(const uint8_t * buf) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template +template inline CHIP_ERROR GenericConfigurationManagerImpl::_GetProductRevision(uint16_t & productRev) { CHIP_ERROR err; @@ -243,33 +247,34 @@ inline CHIP_ERROR GenericConfigurationManagerImpl::_GetProductRevisio err = Impl()->ReadConfigValue(ImplClass::kConfigKey_ProductRevision, val); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { - productRev = (uint16_t)CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION; - err = CHIP_NO_ERROR; + productRev = (uint16_t) CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION; + err = CHIP_NO_ERROR; } else { - productRev = (uint16_t)val; + productRev = (uint16_t) val; } return err; } -template +template inline CHIP_ERROR GenericConfigurationManagerImpl::_StoreProductRevision(uint16_t productRev) { - return Impl()->WriteConfigValue(ImplClass::kConfigKey_ProductRevision, (uint32_t)productRev); + return Impl()->WriteConfigValue(ImplClass::kConfigKey_ProductRevision, (uint32_t) productRev); } -template -CHIP_ERROR GenericConfigurationManagerImpl::_GetManufacturingDate(uint16_t& year, uint8_t& month, uint8_t& dayOfMonth) +template +CHIP_ERROR GenericConfigurationManagerImpl::_GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth) { CHIP_ERROR err; - enum { + enum + { kDateStringLength = 10 // YYYY-MM-DD }; char dateStr[kDateStringLength + 1]; size_t dateLen; - char *parseEnd; + char * parseEnd; err = Impl()->ReadConfigValueStr(ImplClass::kConfigKey_ManufacturingDate, dateStr, sizeof(dateStr), dateLen); SuccessOrExit(err); @@ -293,14 +298,15 @@ exit: return err; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen) { return Impl()->WriteConfigValueStr(ImplClass::kConfigKey_ManufacturingDate, mfgDate, mfgDateLen); } -template -CHIP_ERROR GenericConfigurationManagerImpl::_GetManufacturerDeviceCertificate(uint8_t * buf, size_t bufSize, size_t & certLen) +template +CHIP_ERROR GenericConfigurationManagerImpl::_GetManufacturerDeviceCertificate(uint8_t * buf, size_t bufSize, + size_t & certLen) { CHIP_ERROR err; @@ -326,14 +332,15 @@ exit: return err; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StoreManufacturerDeviceCertificate(const uint8_t * cert, size_t certLen) { return Impl()->WriteConfigValueBin(ImplClass::kConfigKey_MfrDeviceCert, cert, certLen); } -template -CHIP_ERROR GenericConfigurationManagerImpl::_GetManufacturerDeviceIntermediateCACerts(uint8_t * buf, size_t bufSize, size_t & certsLen) +template +CHIP_ERROR GenericConfigurationManagerImpl::_GetManufacturerDeviceIntermediateCACerts(uint8_t * buf, size_t bufSize, + size_t & certsLen) { CHIP_ERROR err; @@ -359,14 +366,16 @@ exit: return err; } -template -CHIP_ERROR GenericConfigurationManagerImpl::_StoreManufacturerDeviceIntermediateCACerts(const uint8_t * certs, size_t certsLen) +template +CHIP_ERROR GenericConfigurationManagerImpl::_StoreManufacturerDeviceIntermediateCACerts(const uint8_t * certs, + size_t certsLen) { return Impl()->WriteConfigValueBin(ImplClass::kConfigKey_MfrDeviceICACerts, certs, certsLen); } -template -CHIP_ERROR GenericConfigurationManagerImpl::_GetManufacturerDevicePrivateKey(uint8_t * buf, size_t bufSize, size_t & keyLen) +template +CHIP_ERROR GenericConfigurationManagerImpl::_GetManufacturerDevicePrivateKey(uint8_t * buf, size_t bufSize, + size_t & keyLen) { CHIP_ERROR err; @@ -392,13 +401,13 @@ exit: return err; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StoreManufacturerDevicePrivateKey(const uint8_t * key, size_t keyLen) { return Impl()->WriteConfigValueBin(ImplClass::kConfigKey_MfrDevicePrivateKey, key, keyLen); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetDeviceId(uint64_t & deviceId) { CHIP_ERROR err; @@ -417,7 +426,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetDeviceId(uint64_t & d return err; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetDeviceCertificate(uint8_t * buf, size_t bufSize, size_t & certLen) { CHIP_ERROR err; @@ -436,8 +445,9 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetDeviceCertificate(uin return err; } -template -CHIP_ERROR GenericConfigurationManagerImpl::_GetDeviceIntermediateCACerts(uint8_t * buf, size_t bufSize, size_t & certsLen) +template +CHIP_ERROR GenericConfigurationManagerImpl::_GetDeviceIntermediateCACerts(uint8_t * buf, size_t bufSize, + size_t & certsLen) { CHIP_ERROR err; @@ -455,7 +465,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetDeviceIntermediateCAC return err; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetDevicePrivateKey(uint8_t * buf, size_t bufSize, size_t & keyLen) { CHIP_ERROR err; @@ -476,31 +486,31 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetDevicePrivateKey(uint #if CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StoreDeviceId(uint64_t deviceId) { return Impl()->WriteConfigValue(ImplClass::kConfigKey_OperationalDeviceId, deviceId); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StoreDeviceCertificate(const uint8_t * cert, size_t certLen) { return Impl()->WriteConfigValueBin(ImplClass::kConfigKey_OperationalDeviceCert, cert, certLen); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StoreDeviceIntermediateCACerts(const uint8_t * certs, size_t certsLen) { return Impl()->WriteConfigValueBin(ImplClass::kConfigKey_OperationalDeviceICACerts, certs, certsLen); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StoreDevicePrivateKey(const uint8_t * key, size_t keyLen) { return Impl()->WriteConfigValueBin(ImplClass::kConfigKey_OperationalDevicePrivateKey, key, keyLen); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_ClearOperationalDeviceCredentials(void) { Impl()->ClearConfigValue(ImplClass::kConfigKey_OperationalDeviceId); @@ -513,19 +523,19 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ClearOperationalDeviceCr return CHIP_NO_ERROR; } -template +template bool GenericConfigurationManagerImpl::_OperationalDeviceCredentialsProvisioned() { return ::chip::GetFlag(mFlags, kFlag_OperationalDeviceCredentialsProvisioned); } -template +template bool GenericConfigurationManagerImpl::UseManufacturerCredentialsAsOperational() { return ::chip::GetFlag(mFlags, kFlag_UseManufacturerCredentialsAsOperational); } -template +template void GenericConfigurationManagerImpl::_UseManufacturerCredentialsAsOperational(bool val) { SetFlag(mFlags, kFlag_UseManufacturerCredentialsAsOperational, val); @@ -533,7 +543,7 @@ void GenericConfigurationManagerImpl::_UseManufacturerCredentialsAsOp #endif // CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetPairingCode(char * buf, size_t bufSize, size_t & pairingCodeLen) { CHIP_ERROR err; @@ -555,19 +565,19 @@ exit: return err; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StorePairingCode(const char * pairingCode, size_t pairingCodeLen) { return Impl()->WriteConfigValueStr(ImplClass::kConfigKey_PairingCode, pairingCode, pairingCodeLen); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetFabricId(uint64_t & fabricId) { return Impl()->ReadConfigValue(ImplClass::kConfigKey_FabricId, fabricId); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StoreFabricId(uint64_t fabricId) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -592,31 +602,31 @@ exit: return err; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetServiceId(uint64_t & serviceId) { return Impl()->ReadConfigValue(ImplClass::kConfigKey_ServiceId, serviceId); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetServiceConfig(uint8_t * buf, size_t bufSize, size_t & serviceConfigLen) { return Impl()->ReadConfigValueBin(ImplClass::kConfigKey_ServiceConfig, buf, bufSize, serviceConfigLen); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StoreServiceConfig(const uint8_t * serviceConfig, size_t serviceConfigLen) { return Impl()->WriteConfigValueBin(ImplClass::kConfigKey_ServiceConfig, serviceConfig, serviceConfigLen); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetPairedAccountId(char * buf, size_t bufSize, size_t & accountIdLen) { return Impl()->ReadConfigValueStr(ImplClass::kConfigKey_PairedAccountId, buf, bufSize, accountIdLen); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StorePairedAccountId(const char * accountId, size_t accountIdLen) { CHIP_ERROR err; @@ -630,10 +640,11 @@ exit: return err; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_StoreServiceProvisioningData(uint64_t serviceId, - const uint8_t * serviceConfig, size_t serviceConfigLen, - const char * accountId, size_t accountIdLen) + const uint8_t * serviceConfig, + size_t serviceConfigLen, + const char * accountId, size_t accountIdLen) { CHIP_ERROR err; @@ -661,7 +672,7 @@ exit: return err; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_ClearServiceProvisioningData() { Impl()->ClearConfigValue(ImplClass::kConfigKey_ServiceId); @@ -675,7 +686,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ClearServiceProvisioning if (_IsPairedToAccount()) { ChipDeviceEvent event; - event.Type = DeviceEventType::kAccountPairingChange; + event.Type = DeviceEventType::kAccountPairingChange; event.AccountPairingChange.IsPairedToAccount = false; PlatformMgr().PostEvent(&event); } @@ -685,7 +696,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ClearServiceProvisioning if (_IsServiceProvisioned()) { ChipDeviceEvent event; - event.Type = DeviceEventType::kServiceProvisioningChange; + event.Type = DeviceEventType::kServiceProvisioningChange; event.ServiceProvisioningChange.IsServiceProvisioned = false; event.ServiceProvisioningChange.ServiceConfigUpdated = false; PlatformMgr().PostEvent(&event); @@ -697,25 +708,25 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ClearServiceProvisioning return CHIP_NO_ERROR; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetFailSafeArmed(bool & val) { return Impl()->ReadConfigValue(ImplClass::kConfigKey_FailSafeArmed, val); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_SetFailSafeArmed(bool val) { return Impl()->WriteConfigValue(ImplClass::kConfigKey_FailSafeArmed, val); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetQRCodeString(char * buf, size_t bufSize) { return CHIP_ERROR_NOT_IMPLEMENTED; } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_GetWiFiAPSSID(char * buf, size_t bufSize) { CHIP_ERROR err; @@ -742,8 +753,9 @@ exit: return err; } -template -CHIP_ERROR GenericConfigurationManagerImpl::_GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) +template +CHIP_ERROR +GenericConfigurationManagerImpl::_GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) { CHIP_ERROR err; uint16_t id; @@ -762,52 +774,51 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetBLEDeviceIdentificati deviceIdInfo.SetDeviceId(FabricState.LocalNodeId); #endif - deviceIdInfo.PairingStatus = Impl()->_IsPairedToAccount() - ? Ble::ChipBLEDeviceIdentificationInfo::kPairingStatus_Paired - : Ble::ChipBLEDeviceIdentificationInfo::kPairingStatus_Unpaired; + deviceIdInfo.PairingStatus = Impl()->_IsPairedToAccount() ? Ble::ChipBLEDeviceIdentificationInfo::kPairingStatus_Paired + : Ble::ChipBLEDeviceIdentificationInfo::kPairingStatus_Unpaired; exit: return err; } -template +template bool GenericConfigurationManagerImpl::_IsServiceProvisioned() { return ::chip::GetFlag(mFlags, kFlag_IsServiceProvisioned); } -template +template bool GenericConfigurationManagerImpl::_IsMemberOfFabric() { return ::chip::GetFlag(mFlags, kFlag_IsMemberOfFabric); } -template +template bool GenericConfigurationManagerImpl::_IsPairedToAccount() { return ::chip::GetFlag(mFlags, kFlag_IsPairedToAccount); } -template +template bool GenericConfigurationManagerImpl::_IsFullyProvisioned() { return #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION - ConnectivityMgr().IsWiFiStationProvisioned() && + ConnectivityMgr().IsWiFiStationProvisioned() && #endif #if CHIP_DEVICE_CONFIG_ENABLE_THREAD - ConnectivityMgr().IsThreadProvisioned() && + ConnectivityMgr().IsThreadProvisioned() && #endif #if !CHIP_DEVICE_CONFIG_DISABLE_ACCOUNT_PAIRING - Impl()->IsPairedToAccount() && + Impl()->IsPairedToAccount() && #endif #if CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING - (!UseManufacturerCredentialsAsOperational() && _OperationalDeviceCredentialsProvisioned()) && + (!UseManufacturerCredentialsAsOperational() && _OperationalDeviceCredentialsProvisioned()) && #endif - Impl()->IsMemberOfFabric(); + Impl()->IsMemberOfFabric(); } -template +template CHIP_ERROR GenericConfigurationManagerImpl::_ComputeProvisioningHash(uint8_t * hashBuf, size_t hashBufSize) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -839,16 +850,16 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ComputeProvisioningHash( // DDDD is the length of the dddddddddddddddd field (the device id), represented as 4 uppercase hex digits. // Because the device id is always the same size, this field is always '0010'. // CCCC is the length of the cccc…cccc field (the device certificate), represented as 4 uppercase hex digits. - // IIII is the length of the iiii…iiii field (the device intermediate CA certificates), represented as 4 uppercase hex digits. - // KKKK is the length of the kkkk…kkkk field (the device private key), represented as 4 uppercase hex digits. - // PPPP is the length of the pppppp field (the device pairing code), represented as 4 uppercase hex digits. + // IIII is the length of the iiii…iiii field (the device intermediate CA certificates), represented as 4 uppercase hex + // digits. KKKK is the length of the kkkk…kkkk field (the device private key), represented as 4 uppercase hex digits. PPPP + // is the length of the pppppp field (the device pairing code), represented as 4 uppercase hex digits. hash.Begin(); // Hash the device id { uint64_t deviceId; - constexpr uint16_t kDeviceIdLen = 16; // 16 hex characters + constexpr uint16_t kDeviceIdLen = 16; // 16 hex characters char inputBuf[kLenFieldLen + kDeviceIdLen + 1]; // +1 for terminator err = Impl()->_GetManufacturerDeviceId(deviceId); @@ -856,7 +867,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ComputeProvisioningHash( snprintf(inputBuf, sizeof(inputBuf), "0010%016" PRIX64, deviceId); - hash.AddData((uint8_t *)inputBuf, kLenFieldLen + kDeviceIdLen); + hash.AddData((uint8_t *) inputBuf, kLenFieldLen + kDeviceIdLen); } // Hash the device certificate @@ -864,13 +875,13 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ComputeProvisioningHash( size_t certLen; // Determine the length of the device certificate. - err = Impl()->_GetManufacturerDeviceCertificate((uint8_t *)NULL, 0, certLen); + err = Impl()->_GetManufacturerDeviceCertificate((uint8_t *) NULL, 0, certLen); SuccessOrExit(err); // Create a temporary buffer to hold the certificate. (This will also be used for // the private key). dataBufSize = certLen; - dataBuf = (uint8_t *)Platform::Security::MemoryAlloc(dataBufSize); + dataBuf = (uint8_t *) Platform::Security::MemoryAlloc(dataBufSize); VerifyOrExit(dataBuf != NULL, err = CHIP_ERROR_NO_MEMORY); // Read the certificate. @@ -884,7 +895,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ComputeProvisioningHash( size_t certsLen; // Determine the length of the device intermediate CA certificates. - err = Impl()->_GetManufacturerDeviceIntermediateCACerts((uint8_t *)NULL, 0, certsLen); + err = Impl()->_GetManufacturerDeviceIntermediateCACerts((uint8_t *) NULL, 0, certsLen); SuccessOrExit(err); // Allocate larger buffer to hold the intermediate CA certificates. @@ -894,7 +905,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ComputeProvisioningHash( Platform::Security::MemoryFree(dataBuf); dataBufSize = certsLen; - dataBuf = (uint8_t *)Platform::Security::MemoryAlloc(dataBufSize); + dataBuf = (uint8_t *) Platform::Security::MemoryAlloc(dataBufSize); VerifyOrExit(dataBuf != NULL, err = CHIP_ERROR_NO_MEMORY); } @@ -908,7 +919,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ComputeProvisioningHash( size_t keyLen; // Determine the length of the device private key. - err = Impl()->_GetManufacturerDevicePrivateKey((uint8_t *)NULL, 0, keyLen); + err = Impl()->_GetManufacturerDevicePrivateKey((uint8_t *) NULL, 0, keyLen); SuccessOrExit(err); // Read the private key. (Note that we presume the buffer allocated to hold the certificate @@ -921,21 +932,21 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ComputeProvisioningHash( // Hash the device pairing code. If the device does not have a pairing code, hash a zero-length value. { char pairingCode[ConfigurationManager::kMaxPairingCodeLength + 1]; // +1 for terminator - char lenStr[kLenFieldLen + 1]; // +1 for terminator + char lenStr[kLenFieldLen + 1]; // +1 for terminator size_t pairingCodeLen; err = Impl()->_GetPairingCode(pairingCode, sizeof(pairingCode), pairingCodeLen); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { pairingCodeLen = 0; - err = CHIP_NO_ERROR; + err = CHIP_NO_ERROR; } SuccessOrExit(err); - snprintf(lenStr, sizeof(lenStr), "%04" PRIX16, (uint16_t)pairingCodeLen); + snprintf(lenStr, sizeof(lenStr), "%04" PRIX16, (uint16_t) pairingCodeLen); - hash.AddData((uint8_t *)lenStr, kLenFieldLen); - hash.AddData((uint8_t *)pairingCode, pairingCodeLen); + hash.AddData((uint8_t *) lenStr, kLenFieldLen); + hash.AddData((uint8_t *) pairingCode, pairingCodeLen); } hash.Finish(hashBuf); @@ -964,7 +975,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_RunUnitTests() #if CHIP_PROGRESS_LOGGING -template +template void GenericConfigurationManagerImpl::LogDeviceConfig() { CHIP_ERROR err; diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.ipp b/src/include/platform/internal/GenericPlatformManagerImpl.ipp index f43103862942c9..9a846393135176 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl.ipp +++ b/src/include/platform/internal/GenericPlatformManagerImpl.ipp @@ -78,7 +78,15 @@ CHIP_ERROR GenericPlatformManagerImpl::_InitChipStack(void) // TODO Perform dynamic configuration of the core CHIP objects based on stored settings. - // TODO Initialize the BLE manager. + // Initialize the CHIP BLE manager. +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE + err = BLEMgr().Init(); + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "BLEManager initialization failed: %s", ErrorStr(err)); + } + SuccessOrExit(err); +#endif // Initialize the Connectivity Manager object. err = ConnectivityMgr().Init(); diff --git a/src/platform/ESP32/BLEManagerImpl.cpp b/src/platform/ESP32/BLEManagerImpl.cpp index eb010bc0f726db..3fe144202a899a 100644 --- a/src/platform/ESP32/BLEManagerImpl.cpp +++ b/src/platform/ESP32/BLEManagerImpl.cpp @@ -29,6 +29,8 @@ #include #include +#include +#include #include "esp_bt.h" #include "esp_bt_main.h" @@ -620,10 +622,12 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) // If a custom device name has not been specified, generate a CHIP-standard name based on the // bottom digits of the Chip device id. + + // TODO Get a real device id + uint16_t deviceId = 0x0F00; if (!GetFlag(mFlags, kFlag_UseCustomDeviceName)) { - snprintf(mDeviceName, sizeof(mDeviceName), "%s%04" PRIX32, CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, - (uint32_t) FabricState.LocalNodeId); + snprintf(mDeviceName, sizeof(mDeviceName), "%s%04" PRIX16, CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, deviceId); mDeviceName[kMaxDeviceNameLength] = 0; } diff --git a/src/platform/ESP32/ConfigurationManagerImpl.cpp b/src/platform/ESP32/ConfigurationManagerImpl.cpp index 15b9f5a08d52a8..83d61bde0af125 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.cpp +++ b/src/platform/ESP32/ConfigurationManagerImpl.cpp @@ -25,18 +25,11 @@ /* this file behaves like a config.h, comes first */ #include -#include -#include - #include -#include -// #include +#include #include -#include - -#if CHIP_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING -#include -#endif // CHIP_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING +#include +#include #include "esp_wifi.h" #include "nvs.h" @@ -44,12 +37,8 @@ namespace chip { namespace DeviceLayer { -using namespace ::chip::Profiles::Security::AppKeys; -using namespace ::chip::Profiles::DeviceDescription; using namespace ::chip::DeviceLayer::Internal; -using ::chip::kChipVendor_Common; - namespace { enum @@ -57,16 +46,10 @@ enum kChipProduct_Connect = 0x0016 }; -// Singleton instance of Chip Group Key Store for the ESP32 -// -// NOTE: This is declared as a private global variable, rather than a static -// member of ConfigurationManagerImpl, to reduce the number of headers that -// must be included by the application when using the ConfigurationManager API. -// -GroupKeyStoreImpl gGroupKeyStore; - } // unnamed namespace +// TODO: Define a Singleton instance of CHIP Group Key Store here (#1266) + /** Singleton instance of the ConfigurationManager implementation object for the ESP32. */ ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; @@ -88,9 +71,7 @@ CHIP_ERROR ConfigurationManagerImpl::_Init() err = Internal::GenericConfigurationManagerImpl::_Init(); SuccessOrExit(err); - // Initialize the global GroupKeyStore object. - err = gGroupKeyStore.Init(); - SuccessOrExit(err); + // TODO: Initialize the global GroupKeyStore object here (#1266) #if CHIP_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING @@ -124,32 +105,6 @@ CHIP_ERROR ConfigurationManagerImpl::_GetPrimaryWiFiMACAddress(uint8_t * buf) return esp_wifi_get_mac(ESP_IF_WIFI_STA, buf); } -CHIP_ERROR ConfigurationManagerImpl::_GetDeviceDescriptor(::chip::Profiles::DeviceDescription::ChipDeviceDescriptor & deviceDesc) -{ - CHIP_ERROR err; - - // Call the generic version of _GetDeviceDescriptor() supplied by the base class. - err = Internal::GenericConfigurationManagerImpl::_GetDeviceDescriptor(deviceDesc); - SuccessOrExit(err); - - // If we're pretending to be a CHIP Connect, fake the presence of a 805.15.4 radio by returning - // the Chip device id as the Primary 802.15.4 MAC address field. This is necessary to fool - // the CHIP mobile app into believing we are indeed a Connect. - if (CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID == kChipVendor_Common && CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID == kChipProduct_Connect) - { - Encoding::BigEndian::Put64(deviceDesc.Primary802154MACAddress, deviceDesc.DeviceId); - deviceDesc.DeviceId = kNodeIdNotSpecified; - } - -exit: - return err; -} - -::chip::Profiles::Security::AppKeys::GroupKeyStoreBase * ConfigurationManagerImpl::_GetGroupKeyStore() -{ - return &gGroupKeyStore; -} - bool ConfigurationManagerImpl::_CanFactoryReset() { // TODO: query the application to determine if factory reset is allowed. @@ -179,44 +134,6 @@ CHIP_ERROR ConfigurationManagerImpl::_WritePersistedStorageValue(::chip::Platfor return WriteConfigValue(configKey, value); } -CHIP_ERROR ConfigurationManagerImpl::GetWiFiStationSecurityType(Profiles::NetworkProvisioning::WiFiSecurityType & secType) -{ - CHIP_ERROR err; - uint32_t secTypeInt; - - err = ReadConfigValue(kConfigKey_WiFiStationSecType, secTypeInt); - if (err == CHIP_NO_ERROR) - { - secType = (Profiles::NetworkProvisioning::WiFiSecurityType) secTypeInt; - } - return err; -} - -CHIP_ERROR ConfigurationManagerImpl::UpdateWiFiStationSecurityType(Profiles::NetworkProvisioning::WiFiSecurityType secType) -{ - CHIP_ERROR err; - Profiles::NetworkProvisioning::WiFiSecurityType curSecType; - - if (secType != Profiles::NetworkProvisioning::kWiFiSecurityType_NotSpecified) - { - err = GetWiFiStationSecurityType(curSecType); - if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || (err == CHIP_NO_ERROR && secType != curSecType)) - { - uint32_t secTypeInt = secType; - err = WriteConfigValue(kConfigKey_WiFiStationSecType, secTypeInt); - } - SuccessOrExit(err); - } - else - { - err = ClearConfigValue(kConfigKey_WiFiStationSecType); - SuccessOrExit(err); - } - -exit: - return err; -} - void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { CHIP_ERROR err; diff --git a/src/platform/ESP32/ConfigurationManagerImpl.h b/src/platform/ESP32/ConfigurationManagerImpl.h index 66e4005e1740ce..3077036e817f03 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.h +++ b/src/platform/ESP32/ConfigurationManagerImpl.h @@ -26,7 +26,13 @@ #ifndef CONFIGURATION_MANAGER_IMPL_H #define CONFIGURATION_MANAGER_IMPL_H +#include #include +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#include +#else +#include +#endif #include @@ -42,6 +48,11 @@ class NetworkProvisioningServerImpl; */ class ConfigurationManagerImpl final : public ConfigurationManager, public Internal::GenericConfigurationManagerImpl, +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE + public Internal::GenericConnectivityManagerImpl_BLE, +#else + public Internal::GenericConnectivityManagerImpl_NoBLE, +#endif private Internal::ESP32Config { // Allow the ConfigurationManager interface class to delegate method calls to diff --git a/src/platform/ESP32/ESP32Config.cpp b/src/platform/ESP32/ESP32Config.cpp index a105c3dd501f3d..9c01cf2a87a632 100644 --- a/src/platform/ESP32/ESP32Config.cpp +++ b/src/platform/ESP32/ESP32Config.cpp @@ -584,6 +584,8 @@ CHIP_ERROR ESP32Config::ClearNamespace(const char * ns) return err; } +void ESP32Config::RunConfigUnitTest() {} + } // namespace Internal } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/ESP32/ESP32Config.h b/src/platform/ESP32/ESP32Config.h index 8a74bbb2221710..a5bbf77dee543c 100644 --- a/src/platform/ESP32/ESP32Config.h +++ b/src/platform/ESP32/ESP32Config.h @@ -96,6 +96,8 @@ class ESP32Config // NVS Namespace helper functions. static CHIP_ERROR EnsureNamespace(const char * ns); static CHIP_ERROR ClearNamespace(const char * ns); + + static void RunConfigUnitTest(void); }; struct ESP32Config::Key diff --git a/src/platform/Makefile.am b/src/platform/Makefile.am index a936eaffe7874f..9812eb1f58c985 100644 --- a/src/platform/Makefile.am +++ b/src/platform/Makefile.am @@ -184,6 +184,7 @@ if CHIP_DEVICE_LAYER_TARGET_ESP32 libDeviceLayer_a_SOURCES += \ ESP32/BLEManagerImpl.cpp \ + ESP32/ConfigurationManagerImpl.cpp \ ESP32/PlatformManagerImpl.cpp \ ESP32/ConnectivityManagerImpl.cpp \ ESP32/ESP32Config.cpp \ diff --git a/src/test_driver/esp32/sdkconfig.defaults b/src/test_driver/esp32/sdkconfig.defaults index c1408689565959..78f0bdd4979f41 100644 --- a/src/test_driver/esp32/sdkconfig.defaults +++ b/src/test_driver/esp32/sdkconfig.defaults @@ -24,7 +24,10 @@ CONFIG_ESPTOOLPY_BAUD_921600B=y CONFIG_ESPTOOLPY_BAUD=921600 CONFIG_ESPTOOLPY_COMPRESSED=y -CONFIG_MONITOR_BAUD_115200B=y -CONFIG_MONITOR_BAUD=115200 +CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y +CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 CONFIG_CHIP_TASK_STACK_SIZE=32768 CONFIG_ESP_MAIN_TASK_STACK_SIZE=32768 + +#enable BT +CONFIG_BT_ENABLED=y diff --git a/src/test_driver/esp32/sdkconfig_qemu.defaults b/src/test_driver/esp32/sdkconfig_qemu.defaults index 6dc3a45e29dd6c..95fc3a69ad41e2 100644 --- a/src/test_driver/esp32/sdkconfig_qemu.defaults +++ b/src/test_driver/esp32/sdkconfig_qemu.defaults @@ -24,8 +24,8 @@ CONFIG_ESPTOOLPY_BAUD_921600B=y CONFIG_ESPTOOLPY_BAUD=921600 CONFIG_ESPTOOLPY_COMPRESSED=y -CONFIG_MONITOR_BAUD_115200B=y -CONFIG_MONITOR_BAUD=115200 +CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y +CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 CONFIG_MBEDTLS_HARDWARE_AES=n CONFIG_MBEDTLS_HARDWARE_MPI=n CONFIG_MBEDTLS_HARDWARE_SHA=n @@ -33,3 +33,6 @@ CONFIG_CHIP_TASK_STACK_SIZE=32768 CONFIG_ESP_MAIN_TASK_STACK_SIZE=32768 CONFIG_ESP32_PANIC_PRINT_REBOOT=y CONFIG_ESP32_PANIC_PRINT_HALT=n + +#enable BT +CONFIG_BT_ENABLED=y