Skip to content

Commit

Permalink
[ESP32] Implement few methods from DeviceInstanceInfoProvider (#19995)
Browse files Browse the repository at this point in the history
* [ESP32] Implement few methods from DeviceInstanceInfoProvider

GenericDeviceInstanceInfoProvider do not read all the device instance
info from the flash. This overrides few methods to read VendorId,
VendorName, ProductId, ProductName, and HardwareVersionString from
the flash.

* Support ESP32FactoryDataProvider in all apps

* Move invalid string length check to ESP32Config
  • Loading branch information
shubhamdp authored and pull[bot] committed Jul 20, 2023
1 parent 55b8d15 commit fa1abc9
Show file tree
Hide file tree
Showing 18 changed files with 296 additions and 35 deletions.
1 change: 1 addition & 0 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ endif()

if (CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER)
chip_gn_arg_append("chip_use_transitional_commissionable_data_provider" "false")
chip_gn_arg_append("chip_use_factory_data_provider" "true")
endif()

set(args_gn_input "${CMAKE_CURRENT_BINARY_DIR}/args.gn.in")
Expand Down
10 changes: 10 additions & 0 deletions config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,16 @@ menu "CHIP Device Layer"
nvs partition. Factory partition can be configured using CONFIG_CHIP_FACTORY_NAMESPACE_PARTITION_LABEL
option, default is "nvs".

config ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER
depends on ENABLE_ESP32_FACTORY_DATA_PROVIDER
bool "Use ESP32 Device Instance Info Provider"
default n
help
Use ESP32 Device Instance Info Provider to get device instance info from factory partition.
Details like Vendor Name, Vendor Id, Product Name, Product Id, Serial Number, Manufacturing Date,
Hardware Version, Hardware Version String, and Rotating Device Id UniqueId will be read from factory
partition.

endmenu


Expand Down
21 changes: 21 additions & 0 deletions examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "platform/PlatformManager.h"
#include "shell_extension/launch.h"
#include <common/CHIPDeviceManager.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>

#include <app/server/OnboardingCodesUtil.h>
#include <app/util/af.h>
Expand All @@ -53,9 +55,14 @@
#include <platform/ThreadStackManager.h>
#endif

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
#include <platform/ESP32/ESP32FactoryDataProvider.h>
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

using namespace ::chip;
using namespace ::chip::Shell;
using namespace ::chip::DeviceManager;
using namespace ::chip::Credentials;

// Used to indicate that an IP address has been added to the QRCode
#define EXAMPLE_VENDOR_TAG_IP 1
Expand Down Expand Up @@ -83,6 +90,10 @@ AppCallbacks sCallbacks;

constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
chip::DeviceLayer::ESP32FactoryDataProvider sFactoryDataProvider;
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

} // namespace

static void InitServer(intptr_t context)
Expand Down Expand Up @@ -135,6 +146,16 @@ extern "C" void app_main()
return;
}

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
SetCommissionableDataProvider(&sFactoryDataProvider);
SetDeviceAttestationCredentialsProvider(&sFactoryDataProvider);
#if CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER
SetDeviceInstanceInfoProvider(&sFactoryDataProvider);
#endif
#else
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

ESP_LOGI(TAG, "------------------------Starting App Task---------------------------");
error = GetAppTask().StartAppTask();
if (error != CHIP_NO_ERROR)
Expand Down
21 changes: 21 additions & 0 deletions examples/all-clusters-minimal-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <app/util/af.h>
#include <binding-handler.h>
#include <common/Esp32AppServer.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>

#if CONFIG_HAVE_DISPLAY
#include "DeviceWithDisplay.h"
Expand All @@ -53,8 +55,13 @@
#include <platform/ThreadStackManager.h>
#endif

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
#include <platform/ESP32/ESP32FactoryDataProvider.h>
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

using namespace ::chip;
using namespace ::chip::Shell;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;

// Used to indicate that an IP address has been added to the QRCode
Expand Down Expand Up @@ -83,6 +90,10 @@ AppCallbacks sCallbacks;

constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
chip::DeviceLayer::ESP32FactoryDataProvider sFactoryDataProvider;
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

} // namespace

static void InitServer(intptr_t context)
Expand Down Expand Up @@ -135,6 +146,16 @@ extern "C" void app_main()
return;
}

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
SetCommissionableDataProvider(&sFactoryDataProvider);
SetDeviceAttestationCredentialsProvider(&sFactoryDataProvider);
#if CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER
SetDeviceInstanceInfoProvider(&sFactoryDataProvider);
#endif
#else
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

ESP_LOGI(TAG, "------------------------Starting App Task---------------------------");
error = GetAppTask().StartAppTask();
if (error != CHIP_NO_ERROR)
Expand Down
23 changes: 23 additions & 0 deletions examples/bridge-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,30 @@
#include <app/reporting/reporting.h>
#include <app/util/attribute-storage.h>
#include <common/Esp32AppServer.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <lib/core/CHIPError.h>
#include <lib/support/CHIPMemString.h>
#include <lib/support/ErrorStr.h>

#include <app/server/Server.h>

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
#include <platform/ESP32/ESP32FactoryDataProvider.h>
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

namespace {
#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
chip::DeviceLayer::ESP32FactoryDataProvider sFactoryDataProvider;
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
} // namespace

const char * TAG = "bridge-app";

using namespace ::chip;
using namespace ::chip::DeviceManager;
using namespace ::chip::Platform;
using namespace ::chip::Credentials;

static AppDeviceCallbacks AppCallback;

Expand Down Expand Up @@ -397,5 +410,15 @@ extern "C" void app_main()
return;
}

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
SetCommissionableDataProvider(&sFactoryDataProvider);
SetDeviceAttestationCredentialsProvider(&sFactoryDataProvider);
#if CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER
SetDeviceInstanceInfoProvider(&sFactoryDataProvider);
#endif
#else
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, reinterpret_cast<intptr_t>(nullptr));
}
24 changes: 24 additions & 0 deletions examples/light-switch-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,21 @@
#include "shell_extension/launch.h"

#include <app/server/OnboardingCodesUtil.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
#include <platform/ESP32/ESP32FactoryDataProvider.h>
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

namespace {
#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
chip::DeviceLayer::ESP32FactoryDataProvider sFactoryDataProvider;
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
} // namespace

using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;

static const char * TAG = "light-switch-app";
Expand Down Expand Up @@ -75,6 +88,17 @@ extern "C" void app_main()
ESP_LOGE(TAG, "device.Init() failed: %s", ErrorStr(error));
return;
}

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
SetCommissionableDataProvider(&sFactoryDataProvider);
SetDeviceAttestationCredentialsProvider(&sFactoryDataProvider);
#if CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER
SetDeviceInstanceInfoProvider(&sFactoryDataProvider);
#endif
#else
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
if (ThreadStackMgr().InitThreadStack() != CHIP_NO_ERROR)
{
Expand Down
20 changes: 15 additions & 5 deletions examples/lighting-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
#include "shell_extension/launch.h"
#include <app/server/Dnssd.h>
#include <app/server/OnboardingCodesUtil.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
#include <platform/ESP32/ESP32FactoryDataProvider.h>
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;

Expand All @@ -45,7 +48,7 @@ static AppDeviceCallbacks EchoCallbacks;

namespace {
#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
ESP32FactoryDataProvider sFactoryDataProvider;
chip::DeviceLayer::ESP32FactoryDataProvider sFactoryDataProvider;
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
} // namespace

Expand All @@ -71,10 +74,6 @@ extern "C" void app_main()
ESP_LOGI(TAG, "chip-esp32-light-example starting");
ESP_LOGI(TAG, "==================================================");

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
SetCommissionableDataProvider(&sFactoryDataProvider);
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

#if CONFIG_ENABLE_CHIP_SHELL
chip::LaunchShell();
#endif
Expand All @@ -86,6 +85,17 @@ extern "C" void app_main()
ESP_LOGE(TAG, "device.Init() failed: %s", ErrorStr(error));
return;
}

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
SetCommissionableDataProvider(&sFactoryDataProvider);
SetDeviceAttestationCredentialsProvider(&sFactoryDataProvider);
#if CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER
SetDeviceInstanceInfoProvider(&sFactoryDataProvider);
#endif
#else
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
if (ThreadStackMgr().InitThreadStack() != CHIP_NO_ERROR)
{
Expand Down
23 changes: 23 additions & 0 deletions examples/lock-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "shell_extension/launch.h"
#include <common/CHIPDeviceManager.h>
#include <common/Esp32AppServer.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>

#include <cmath>
#include <cstdio>
Expand All @@ -42,8 +44,19 @@
#include "Rpc.h"
#endif

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
#include <platform/ESP32/ESP32FactoryDataProvider.h>
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

namespace {
#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
chip::DeviceLayer::ESP32FactoryDataProvider sFactoryDataProvider;
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
} // namespace

using namespace ::chip;
using namespace ::chip::DeviceManager;
using namespace ::chip::Credentials;

static const char * TAG = "lock-app";

Expand Down Expand Up @@ -92,5 +105,15 @@ extern "C" void app_main()
return;
}

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
SetCommissionableDataProvider(&sFactoryDataProvider);
SetDeviceAttestationCredentialsProvider(&sFactoryDataProvider);
#if CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER
SetDeviceInstanceInfoProvider(&sFactoryDataProvider);
#endif
#else
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, reinterpret_cast<intptr_t>(nullptr));
}
21 changes: 21 additions & 0 deletions examples/ota-provider-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <app/server/Server.h>
#include <common/CHIPDeviceManager.h>
#include <common/Esp32AppServer.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <lib/support/ErrorStr.h>
#include <lib/support/logging/CHIPLogging.h>

Expand All @@ -32,12 +34,17 @@
#include <ota-provider-common/OTAProviderExample.h>
#include <shell_extension/launch.h>

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
#include <platform/ESP32/ESP32FactoryDataProvider.h>
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

using chip::Callback::Callback;
using namespace chip;
using namespace chip::Shell;
using namespace chip::System;
using namespace chip::DeviceManager;
using namespace chip::app::Clusters::OtaSoftwareUpdateProvider;
using namespace ::chip::Credentials;

CHIP_ERROR OnBlockQuery(void * context, chip::System::PacketBufferHandle & blockBuf, size_t & size, bool & isEof, uint32_t offset);
void OnTransferComplete(void * context);
Expand Down Expand Up @@ -130,6 +137,10 @@ static void InitServer(intptr_t context)
otaProviderCommands.Register();
}

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
chip::DeviceLayer::ESP32FactoryDataProvider sFactoryDataProvider;
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

} // namespace

CHIP_ERROR OnBlockQuery(void * context, chip::System::PacketBufferHandle & blockBuf, size_t & size, bool & isEof, uint32_t offset)
Expand Down Expand Up @@ -229,5 +240,15 @@ extern "C" void app_main()
return;
}

#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
SetCommissionableDataProvider(&sFactoryDataProvider);
SetDeviceAttestationCredentialsProvider(&sFactoryDataProvider);
#if CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER
SetDeviceInstanceInfoProvider(&sFactoryDataProvider);
#endif
#else
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER

chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, reinterpret_cast<intptr_t>(nullptr));
}
Loading

0 comments on commit fa1abc9

Please sign in to comment.