Skip to content

Commit

Permalink
[Ameba] Use wifi info in persistentstorage for reconnection after reb…
Browse files Browse the repository at this point in the history
…oot (#18661)

* [PersistentStorage] Update DCT domains
- Add chip-failsafe, chip-sessionresumptionindex, chip-sessionresumption
- Remove chip-dns

* [PersistentStorage] Update DCT domains
- Add chip-deviceinfoprovider

* [Connectivity] Use persistent storage wifi info to connect to wifi after reboot
* Implement AmebaUtils for wifi helper functions
* Update ConnectivityManagerImpl and NetworkCommissioningDriverWiFi to use AmebaUtils functions
* Add ChipGroupMessageCounters, ChipOthers2
* Remove ChipSessionResumptionIndex, which will be part of ChipOthers

* [OTA] Initiate OTA requestor after getting IPv6
* Add OTAHelper to initiate ota requestor from DeviceCallback
* Edit ConnectivityManager to allow link local IPv6 addresses

* [Connectivity] Use AmebaUtils function in NetworkCommissioningWiFiDriver

* Restyled by whitespace

* Restyled by clang-format

* [Connectivity] Rename OTAHelper to OTAInitializer

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
pankore and restyled-commits authored May 31, 2022
1 parent f482393 commit 5121bf8
Show file tree
Hide file tree
Showing 19 changed files with 479 additions and 298 deletions.
10 changes: 2 additions & 8 deletions examples/all-clusters-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ list(
${chip_dir}/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp
${chip_dir}/src/app/clusters/ota-requestor/DefaultOTARequestorStorage.cpp
${chip_dir}/src/app/clusters/ota-requestor/ota-requestor-server.cpp
${chip_dir}/examples/platform/ameba/ota/OTAInitializer.cpp
)
endif (matter_enable_ota_requestor)

Expand Down Expand Up @@ -178,6 +179,7 @@ target_include_directories(
${chip_dir}/examples/all-clusters-app/all-clusters-common
${chip_dir}/examples/all-clusters-app/all-clusters-common/include
${chip_dir}/examples/all-clusters-app/ameba/main/include
${chip_dir}/examples/platform/ameba
${chip_dir_output}/gen/include
${chip_dir}/src/include/
${chip_dir}/src/lib/
Expand Down Expand Up @@ -240,14 +242,6 @@ list(
)
endif (matter_enable_rpc)

if (matter_enable_ota_requestor)
list(
APPEND chip_main_flags

-DCONFIG_ENABLE_OTA_REQUESTOR=1
)
endif (matter_enable_ota_requestor)

list(
APPEND chip_main_cpp_flags

Expand Down
25 changes: 24 additions & 1 deletion examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <support/logging/Constants.h>
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
#include <ota/OTAInitializer.h>
#endif

#include "Globals.h"
#include "LEDWidget.h"
Expand All @@ -50,7 +53,15 @@ using namespace ::chip::DeviceManager;
using namespace ::chip::Logging;

uint32_t identifyTimerCount;
constexpr uint32_t kIdentifyTimerDelayMS = 250;
constexpr uint32_t kIdentifyTimerDelayMS = 250;
constexpr uint32_t kInitOTARequestorDelaySec = 3;

#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
void InitOTARequestorHandler(System::Layer * systemLayer, void * appState)
{
OTAInitializer::Instance().InitOTARequestor();
}
#endif

void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg)
{
Expand Down Expand Up @@ -97,6 +108,9 @@ void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, Cluster

void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event)
{
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
static bool isOTAInitialized = false;
#endif
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
{
ChipLogProgress(DeviceLayer, "IPv4 Server ready...");
Expand All @@ -110,6 +124,15 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
{
ChipLogProgress(DeviceLayer, "IPv6 Server ready...");
chip::app::DnssdServer::Instance().StartServer();
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
// Init OTA requestor only when we have gotten IPv6 address
if (!isOTAInitialized)
{
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec),
InitOTARequestorHandler, nullptr);
isOTAInitialized = true;
}
#endif
}
else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost)
{
Expand Down
63 changes: 0 additions & 63 deletions examples/all-clusters-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <support/CHIPMem.h>

#if CONFIG_ENABLE_OTA_REQUESTOR
#include "app/clusters/ota-requestor/DefaultOTARequestorStorage.h"
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorUserConsent.h>
#include <app/clusters/ota-requestor/ExtendedOTARequestorDriver.h>
#include <platform/Ameba/AmebaOTAImageProcessor.h>
#endif

#if CONFIG_ENABLE_PW_RPC
#include "Rpc.h"
#endif
Expand Down Expand Up @@ -100,55 +90,6 @@ Identify gIdentify1 = {

static DeviceCallbacks EchoCallbacks;

#if CONFIG_ENABLE_OTA_REQUESTOR
DefaultOTARequestor gRequestorCore;
DefaultOTARequestorStorage gRequestorStorage;
ExtendedOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
AmebaOTAImageProcessor gImageProcessor;
chip::ota::DefaultOTARequestorUserConsent gUserConsentProvider;
static chip::ota::UserConsentState gUserConsentState = chip::ota::UserConsentState::kGranted;
#endif

#if CONFIG_ENABLE_OTA_REQUESTOR
extern "C" void amebaQueryImageCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling amebaQueryImageCmdHandler");
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->TriggerImmediateQuery(); });
}

extern "C" void amebaApplyUpdateCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling amebaApplyUpdateCmdHandler");
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->ApplyUpdate(); });
}

static void InitOTARequestor(void)
{
// Initialize and interconnect the Requestor and Image Processor objects -- START
SetRequestorInstance(&gRequestorCore);

gRequestorStorage.Init(chip::Server::GetInstance().GetPersistentStorage());

// Set server instance used for session establishment
gRequestorCore.Init(chip::Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);

gImageProcessor.SetOTADownloader(&gDownloader);

// Connect the Downloader and Image Processor objects
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);

if (gUserConsentState != chip::ota::UserConsentState::kUnknown)
{
gUserConsentProvider.SetUserConsentState(gUserConsentState);
gRequestorUser.SetUserConsentDelegate(&gUserConsentProvider);
}

// Initialize and interconnect the Requestor and Image Processor objects -- END
}
#endif // CONFIG_ENABLE_OTA_REQUESTOR

static void InitServer(intptr_t context)
{
// Init ZCL Data Model and CHIP App Server
Expand All @@ -160,10 +101,6 @@ static void InitServer(intptr_t context)
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
NetWorkCommissioningInstInit();

#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif

if (RTW_SUCCESS != wifi_is_connected_to_ap())
{
// QR code will be used with CHIP Tool
Expand Down
10 changes: 2 additions & 8 deletions examples/lighting-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ list(
${chip_dir}/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp
${chip_dir}/src/app/clusters/ota-requestor/DefaultOTARequestorStorage.cpp
${chip_dir}/src/app/clusters/ota-requestor/ota-requestor-server.cpp
${chip_dir}/examples/platform/ameba/ota/OTAInitializer.cpp
)
endif (matter_enable_ota_requestor)

Expand Down Expand Up @@ -59,6 +60,7 @@ target_include_directories(
${chip_dir}/examples/lighting-app/lighting-common
${chip_dir}/examples/lighting-app/lighting-common/include
${chip_dir}/examples/lighting-app/ameba/main/include
${chip_dir}/examples/platform/ameba
${chip_dir_output}/gen/include
${chip_dir}/src/include/
${chip_dir}/src/lib/
Expand All @@ -84,14 +86,6 @@ list(
-DMATTER_LIGHTING_APP=1
)

if (matter_enable_ota_requestor)
list(
APPEND chip_main_flags

-DCONFIG_ENABLE_OTA_REQUESTOR=1
)
endif (matter_enable_ota_requestor)

list(
APPEND chip_main_cpp_flags

Expand Down
27 changes: 26 additions & 1 deletion examples/lighting-app/ameba/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#include <support/logging/CHIPLogging.h>
#include <support/logging/Constants.h>

#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
#include <ota/OTAInitializer.h>
#endif

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

using namespace ::chip;
Expand All @@ -47,7 +51,15 @@ using namespace ::chip::DeviceManager;
using namespace ::chip::Logging;

uint32_t identifyTimerCount;
constexpr uint32_t kIdentifyTimerDelayMS = 250;
constexpr uint32_t kIdentifyTimerDelayMS = 250;
constexpr uint32_t kInitOTARequestorDelaySec = 3;

#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
void InitOTARequestorHandler(System::Layer * systemLayer, void * appState)
{
OTAInitializer::Instance().InitOTARequestor();
}
#endif

void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg)
{
Expand Down Expand Up @@ -76,6 +88,10 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_

void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event)
{
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
static bool isOTAInitialized = false;
#endif

if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
{
printf("IPv4 Server ready...");
Expand All @@ -89,6 +105,15 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
{
printf("IPv6 Server ready...");
chip::app::DnssdServer::Instance().StartServer();
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
// Init OTA requestor only when we have gotten IPv6 address
if (!isOTAInitialized)
{
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec),
InitOTARequestorHandler, nullptr);
isOTAInitialized = true;
}
#endif
}
else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost)
{
Expand Down
63 changes: 0 additions & 63 deletions examples/lighting-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@

#include <lwip_netconf.h>

#if CONFIG_ENABLE_OTA_REQUESTOR
#include "app/clusters/ota-requestor/DefaultOTARequestorStorage.h"
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorUserConsent.h>
#include <app/clusters/ota-requestor/ExtendedOTARequestorDriver.h>
#include <platform/Ameba/AmebaOTAImageProcessor.h>
#endif

using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
Expand Down Expand Up @@ -85,55 +75,6 @@ void NetWorkCommissioningInstInit()

static DeviceCallbacks EchoCallbacks;

#if CONFIG_ENABLE_OTA_REQUESTOR
DefaultOTARequestor gRequestorCore;
DefaultOTARequestorStorage gRequestorStorage;
ExtendedOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
AmebaOTAImageProcessor gImageProcessor;
chip::ota::DefaultOTARequestorUserConsent gUserConsentProvider;
static chip::ota::UserConsentState gUserConsentState = chip::ota::UserConsentState::kGranted;
#endif

#if CONFIG_ENABLE_OTA_REQUESTOR
extern "C" void amebaQueryImageCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling amebaQueryImageCmdHandler");
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->TriggerImmediateQuery(); });
}

extern "C" void amebaApplyUpdateCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling amebaApplyUpdateCmdHandler");
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->ApplyUpdate(); });
}

static void InitOTARequestor(void)
{
// Initialize and interconnect the Requestor and Image Processor objects -- START
SetRequestorInstance(&gRequestorCore);

gRequestorStorage.Init(Server::GetInstance().GetPersistentStorage());

// Set server instance used for session establishment
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);

gImageProcessor.SetOTADownloader(&gDownloader);

// Connect the Downloader and Image Processor objects
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);

if (gUserConsentState != chip::ota::UserConsentState::kUnknown)
{
gUserConsentProvider.SetUserConsentState(gUserConsentState);
gRequestorUser.SetUserConsentDelegate(&gUserConsentProvider);
}

// Initialize and interconnect the Requestor and Image Processor objects -- END
}
#endif // CONFIG_ENABLE_OTA_REQUESTOR

void OnIdentifyStart(Identify *)
{
ChipLogProgress(Zcl, "OnIdentifyStart");
Expand Down Expand Up @@ -181,10 +122,6 @@ static void InitServer(intptr_t context)
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
NetWorkCommissioningInstInit();

#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif

if (RTW_SUCCESS != wifi_is_connected_to_ap())
{
// QR code will be used with CHIP Tool
Expand Down
4 changes: 2 additions & 2 deletions examples/ota-requestor-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ list(
${chip_dir}/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp
${chip_dir}/src/app/clusters/ota-requestor/DefaultOTARequestorStorage.cpp
${chip_dir}/src/app/clusters/ota-requestor/ota-requestor-server.cpp
${chip_dir}/examples/platform/ameba/ota/OTAInitializer.cpp
)

add_library(
Expand Down Expand Up @@ -58,10 +59,9 @@ target_include_directories(
${chip_dir}/src/controller/data_model
${chip_dir}/third_party/nlio/repo/include/
${chip_dir}/third_party/nlunit-test/repo/src

${chip_dir}/src/app/clusters/ota-requestor
${chip_dir}/examples/ota-requestor-app/ameba/main/include

${chip_dir}/examples/platform/ameba
${sdk_root}/component/soc/realtek/amebad/fwlib/include
)

Expand Down
Loading

0 comments on commit 5121bf8

Please sign in to comment.