Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1.2-branch][ESP32][cherry-pick]Cherry pick some necessary fixes for v1.2-branch #33161

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ if(NOT "${IDF_TARGET}" STREQUAL "esp32h2")
endif()

if (NOT CMAKE_BUILD_EARLY_EXPANSION)
if (CONFIG_COMPILER_OPTIMIZATION_DEFAULT OR CONFIG_COMPILER_OPTIMIZATION_NONE)
if (CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE)
set(is_debug TRUE)
else()
if (NOT CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE)
message(FATAL_ERROR "CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE shall be set")
endif()
set(is_debug FALSE)
endif()
endif()
Expand Down
20 changes: 14 additions & 6 deletions config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ menu "CHIP Core"
help
Enable this option to use LwIP default IPv6 route hook for Route Information Option(RIO) feature.

config ENABLE_ENDPOINT_QUEUE_FILTER
bool "Enable UDP Endpoint queue filter for mDNS Broadcast packets"
depends on USE_MINIMAL_MDNS
default y
help
Enable this option to start a UDP Endpoint queue filter for mDNS Broadcast packets

config ENABLE_LWIP_THREAD_SAFETY
bool "Enable LwIP Thread safety options"
default y
Expand Down Expand Up @@ -625,12 +632,13 @@ menu "CHIP Device Layer"
When set, WoBLE advertisements will stop while a WoBLE connection is active.

config USE_BLE_ONLY_FOR_COMMISSIONING
bool "Use BLE only for commissioning"
default y
help
Disable this flag if BLE is used for any other purpose than commissioning.
When enabled, it deinitialized the BLE on successful commissioning, and on
bootup do not initialize the BLE if device is already provisioned with Wi-Fi/Thread credentials.
depends on BT_ENABLED
bool "Use BLE only for commissioning"
default y
help
Disable this flag if BLE is used for any other purpose than commissioning.
When enabled, it deinitialized the BLE on successful commissioning, and on
bootup do not initialize the BLE if device is already provisioned with Wi-Fi/Thread credentials.

endmenu

Expand Down
1 change: 1 addition & 0 deletions docs/guides/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ example on ESP32 series of SoCs
- [Matter OTA](ota.md)
- [Generating and Using ESP Secure Cert Partition](secure_cert_partition.md)
- [BLE Settings](ble_settings.md)
- [Providers](providers.md)
10 changes: 3 additions & 7 deletions docs/guides/esp32/factory_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@ Following data can be added to the manufacturing partition using
- Serial Number
- Unique identifier

- Device information
- Fixed Labels
- Supported locales
- Supported calendar types
- Supported modes
- Note: As per spec at max size of label should be 64 and `\0` will be
added at the end.
- Supported modes
- Note: As per spec at max size of label should be 64 and `\0` will be
added at the end.

### Configuration Options

Expand Down
76 changes: 76 additions & 0 deletions docs/guides/esp32/providers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
## Providers Implemented for ESP32 Platform

The ESP32 platform has implemented several providers that can be used with data
stored in the factory or by setting fixed data.

Below are the providers that have been implemented:

- [Commissionable Data Provider](https://github.com/project-chip/connectedhomeip/blob/master/src/platform/ESP32/ESP32FactoryDataProvider.h#L47)
This provider reads the discriminator and setup pincode related parameters
from the factory partition.
- [Device Attestation Credentials Provider](https://github.com/project-chip/connectedhomeip/blob/master/src/platform/ESP32/ESP32FactoryDataProvider.h#L56)
This provider manages the attestation data.
- [Device Instance Info Provider](https://github.com/project-chip/connectedhomeip/blob/master/src/platform/ESP32/ESP32FactoryDataProvider.h#L86)
This provider reads basic device information from the factory partition.
- [Device Info Provider](https://github.com/project-chip/connectedhomeip/blob/master/src/platform/ESP32/ESP32DeviceInfoProvider.h#L31)
This provider provides fixed labels, supported calendar types, and supported
locales from the factory partition.
- [Supported Modes](https://github.com/project-chip/connectedhomeip/blob/master/examples/platform/esp32/mode-support/static-supported-modes-manager.h#L28)
This provider offers the supported modes for the mode-select cluster.

More information can be found in the [factory data guide](factory_data.md).

### Device Info Provider

Currently, there are two implementations for this provider:

1. [Reads data stored in the factory partition](https://github.com/project-chip/connectedhomeip/blob/master/src/platform/ESP32/ESP32FactoryDataProvider.h#L56)
_(This will be deprecated in the future)_
2. [Provides APIs to set fixed data that gets read later](https://github.com/project-chip/connectedhomeip/blob/master/src/platform/ESP32/StaticESP32DeviceInfoProvider.h)

- New products should use the `StaticESP32DeviceInfoProvider`. Utilize the
`Set...()` APIs to set the fixed data.
- Existing products using the first implementation can continue to use it if
they do not wish to change the data.
- For products using the first implementation and wanting to change the fixed
data via OTA, they should switch to the second implementation in the OTA
image and use the `Set...()` APIs to set the fixed data.

#### Example:

```cpp
#include <platform/ESP32/StaticESP32FactoryDataProvider.h>

DeviceLayer::StaticESP32DeviceInfoProvider deviceInfoProvider;

// Define array for Supported Calendar Types
using namespace chip::app::Clusters::TimeFormatLocalization::CalendarTypeEnum;
CalendarTypeEnum supportedCalendarTypes[] = {
CalendarTypeEnum::kGregorian, CalendarTypeEnum::kCoptic,
CalendarTypeEnum::kEthiopian, CalendarTypeEnum::kChinese,
};

// Define array for Supported Locales
const char* supportedLocales[] = {
"en-US",
"en-EU",
};

// Define array for Fixed labels { EndpointId, Label, Value }
struct StaticESP32DeviceInfoProvider::FixedLabelEntry fixedLabels[] = {
{ 0, "Room", "Bedroom 2" },
{ 0, "Orientation", "North" },
{ 0, "Direction", "Up" },
};

Span<CalendarTypeEnum> sSupportedCalendarTypes(supportedCalendarTypes);
Span<const char*> sSupportedLocales(supportedLocales);
Span<StaticESP32DeviceInfoProvider::FixedLabelEntry> sFixedLabels(fixedLabels);

{
deviceInfoProvider.SetSupportedLocales(sSupportedLocales);
deviceInfoProvider.SetSupportedCalendarTypes(sSupportedCalendarTypes);
deviceInfoProvider.SetFixedLabels(sFixedLabels);
DeviceLayer::SetDeviceInfoProvider(&deviceInfoProvider);
}
```
2 changes: 1 addition & 1 deletion examples/platform/esp32/common/CommonDeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i

case DeviceEventType::kCHIPoBLEConnectionClosed:
ESP_LOGI(TAG, "CHIPoBLE disconnected");
Esp32AppServer::DeInitBLEIfCommissioned();
break;

case DeviceEventType::kDnssdInitialized:
Expand All @@ -67,6 +66,7 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i

case DeviceEventType::kCommissioningComplete: {
ESP_LOGI(TAG, "Commissioning complete");
Esp32AppServer::DeInitBLEIfCommissioned();
}
break;

Expand Down
44 changes: 5 additions & 39 deletions examples/platform/esp32/common/Esp32AppServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,46 +115,12 @@ static size_t hex_string_to_binary(const char * hex_string, uint8_t * buf, size_

void Esp32AppServer::DeInitBLEIfCommissioned(void)
{
#if CONFIG_BT_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING
#ifdef CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING
if (chip::Server::GetInstance().GetFabricTable().FabricCount() > 0)
{
esp_err_t err = ESP_OK;

#if CONFIG_BT_NIMBLE_ENABLED
if (!ble_hs_is_enabled())
{
ESP_LOGI(TAG, "BLE already deinited");
return;
}
if (nimble_port_stop() != 0)
{
ESP_LOGE(TAG, "nimble_port_stop() failed");
return;
}
vTaskDelay(100);
nimble_port_deinit();

#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
err = esp_nimble_hci_and_controller_deinit();
#endif
#endif /* CONFIG_BT_NIMBLE_ENABLED */

#if CONFIG_IDF_TARGET_ESP32
err |= esp_bt_mem_release(ESP_BT_MODE_BTDM);
#elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2
err |= esp_bt_mem_release(ESP_BT_MODE_BLE);
#endif

if (err != ESP_OK)
{
ESP_LOGE(TAG, "BLE deinit failed");
}
else
{
ESP_LOGI(TAG, "BLE deinit successful and memory reclaimed");
}
chip::DeviceLayer::Internal::BLEMgr().Shutdown();
}
#endif /* CONFIG_BT_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING */
#endif /* CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING */
}

void Esp32AppServer::Init(AppDelegate * sAppDelegate)
Expand All @@ -165,7 +131,7 @@ void Esp32AppServer::Init(AppDelegate * sAppDelegate)
if (hex_string_to_binary(CONFIG_TEST_EVENT_TRIGGER_ENABLE_KEY, sTestEventTriggerEnableKey,
sizeof(sTestEventTriggerEnableKey)) == 0)
{
ESP_LOGE(TAG, "Failed to convert the EnableKey string to octstr type value");
ChipLogError(DeviceLayer, "Failed to convert the EnableKey string to octstr type value");
memset(sTestEventTriggerEnableKey, 0, sizeof(sTestEventTriggerEnableKey));
}
static OTATestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) };
Expand All @@ -189,7 +155,7 @@ void Esp32AppServer::Init(AppDelegate * sAppDelegate)
if (chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned() &&
(chip::Server::GetInstance().GetFabricTable().FabricCount() != 0))
{
ESP_LOGI(TAG, "Thread has been provisioned, publish the dns service now");
ChipLogProgress(DeviceLayer, "Thread has been provisioned, publish the dns service now");
chip::app::DnssdServer::Instance().StartServer();
}
#endif
Expand Down
12 changes: 12 additions & 0 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,18 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)
// Init ZCL Data Model and CHIP App Server
Server::GetInstance().Init(initParams);

#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
// Set ReadHandler Capacity for Subscriptions
chip::app::InteractionModelEngine::GetInstance()->SetHandlerCapacityForSubscriptions(
LinuxDeviceOptions::GetInstance().subscriptionCapacity);
chip::app::InteractionModelEngine::GetInstance()->SetForceHandlerQuota(true);
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
// Set subscription time resumption retry interval seconds
chip::app::InteractionModelEngine::GetInstance()->SetSubscriptionTimeoutResumptionRetryIntervalSeconds(
LinuxDeviceOptions::GetInstance().subscriptionResumptionRetryIntervalSec);
#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
#endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST

// Now that the server has started and we are done with our startup logging,
// log our discovery/onboarding information again so it's not lost in the
// noise.
Expand Down
40 changes: 40 additions & 0 deletions examples/platform/linux/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ enum
kCommissionerOption_FabricID = 0x1020,
kTraceTo = 0x1021,
kOptionSimulateNoInternalTime = 0x1022,
#if defined(PW_RPC_ENABLED)
kOptionRpcServerPort = 0x1023,
#endif
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
kDeviceOption_SubscriptionCapacity = 0x1024,
#endif
kDeviceOption_WiFiSupports5g = 0x1025,
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
kDeviceOption_SubscriptionResumptionRetryIntervalSec = 0x1026,
#endif
};

constexpr unsigned kAppUsageLength = 64;
Expand Down Expand Up @@ -138,6 +148,13 @@ OptionDef sDeviceOptionDefs[] = {
{ "trace-to", kArgumentRequired, kTraceTo },
#endif
{ "simulate-no-internal-time", kNoArgument, kOptionSimulateNoInternalTime },
#if defined(PW_RPC_ENABLED)
{ "rpc-server-port", kArgumentRequired, kOptionRpcServerPort },
#endif
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
{ "subscription-capacity", kArgumentRequired, kDeviceOption_SubscriptionCapacity },
{ "subscription-resumption-retry-interval", kArgumentRequired, kDeviceOption_SubscriptionResumptionRetryIntervalSec },
#endif
{}
};

Expand Down Expand Up @@ -254,6 +271,16 @@ const char * sDeviceOptionHelp =
#endif
" --simulate-no-internal-time\n"
" Time cluster does not use internal platform time\n"
#if defined(PW_RPC_ENABLED)
" --rpc-server-port\n"
" Start RPC server on specified port\n"
#endif
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
" --subscription-capacity\n"
" Max number of subscriptions the device will allow\n"
" --subscription-resumption-retry-interval\n"
" subscription timeout resumption retry interval in seconds\n"
#endif
"\n";

bool Base64ArgToVector(const char * arg, size_t maxSize, std::vector<uint8_t> & outVector)
Expand Down Expand Up @@ -507,6 +534,19 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
case kOptionSimulateNoInternalTime:
LinuxDeviceOptions::GetInstance().mSimulateNoInternalTime = true;
break;
#if defined(PW_RPC_ENABLED)
case kOptionRpcServerPort:
LinuxDeviceOptions::GetInstance().rpcServerPort = static_cast<uint16_t>(atoi(aValue));
break;
#endif
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
case kDeviceOption_SubscriptionCapacity:
LinuxDeviceOptions::GetInstance().subscriptionCapacity = static_cast<int32_t>(atoi(aValue));
break;
case kDeviceOption_SubscriptionResumptionRetryIntervalSec:
LinuxDeviceOptions::GetInstance().subscriptionResumptionRetryIntervalSec = static_cast<int32_t>(atoi(aValue));
break;
#endif
default:
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
retval = false;
Expand Down
8 changes: 7 additions & 1 deletion examples/platform/linux/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ struct LinuxDeviceOptions
chip::FabricId commissionerFabricId = chip::kUndefinedFabricId;
std::vector<std::string> traceTo;
bool mSimulateNoInternalTime = false;

#if defined(PW_RPC_ENABLED)
uint16_t rpcServerPort = 33000;
#endif
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
int32_t subscriptionCapacity = CHIP_IM_MAX_NUM_SUBSCRIPTIONS;
int32_t subscriptionResumptionRetryIntervalSec = -1;
#endif
static LinuxDeviceOptions & GetInstance();
};

Expand Down
3 changes: 3 additions & 0 deletions scripts/tests/cirque_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ CIRQUE_TESTS=(
"CommissioningFailureOnReportTest"
"PythonCommissioningTest"
"CommissioningWindowTest"
"SubscriptionResumptionTest"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thse seem to fail .... are these supposed to be added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will create another PR to fix this issue

"SubscriptionResumptionCapacityTest"
"SubscriptionResumptionTimeoutTest"
)

BOLD_GREEN_TEXT="\033[1;32m"
Expand Down
Loading
Loading