Skip to content

Commit

Permalink
[OTA] Add Network Commissioning support for Thread, Wifi and Ethernet (
Browse files Browse the repository at this point in the history
  • Loading branch information
carol-apple authored and pull[bot] committed Jul 13, 2022
1 parent 183bcc6 commit e5b9661
Show file tree
Hide file tree
Showing 5 changed files with 778 additions and 272 deletions.
95 changes: 95 additions & 0 deletions examples/ota-requestor-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
*/

#include "AppMain.h"
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorUserConsent.h>
#include <app/clusters/ota-requestor/ExtendedOTARequestorDriver.h>
#include <app/util/af.h>
#include <platform/Linux/OTAImageProcessorImpl.h>

using chip::BDXDownloader;
Expand All @@ -43,7 +45,9 @@ using chip::Callback::Callback;
using chip::System::Layer;
using chip::Transport::PeerAddress;
using namespace chip;
using namespace chip::app;
using namespace chip::ArgParser;
using namespace chip::DeviceLayer;
using namespace chip::Messaging;
using namespace chip::app::Clusters::OtaSoftwareUpdateProvider::Commands;

Expand Down Expand Up @@ -117,6 +121,33 @@ OptionSet cmdLineOptions = {

OptionSet * allOptions[] = { &cmdLineOptions, nullptr };

// Network commissioning
namespace {
constexpr EndpointId kNetworkCommissioningEndpointMain = 0;
constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

// This file is being used by platforms other than Linux, so we need this check to disable related features since we only
// implemented them on linux.
#if CHIP_DEVICE_LAYER_TARGET_LINUX
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
NetworkCommissioning::LinuxThreadDriver sLinuxThreadDriver;
Clusters::NetworkCommissioning::Instance sThreadNetworkCommissioningInstance(kNetworkCommissioningEndpointMain,
&sLinuxThreadDriver);
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
NetworkCommissioning::LinuxWiFiDriver sLinuxWiFiDriver;
Clusters::NetworkCommissioning::Instance sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointSecondary,
&sLinuxWiFiDriver);
#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA
NetworkCommissioning::LinuxEthernetDriver sLinuxEthernetDriver;
Clusters::NetworkCommissioning::Instance sEthernetNetworkCommissioningInstance(kNetworkCommissioningEndpointMain,
&sLinuxEthernetDriver);
#else // CHIP_DEVICE_LAYER_TARGET_LINUX
Clusters::NetworkCommissioning::NullNetworkDriver sNullNetworkDriver;
Clusters::NetworkCommissioning::Instance sNullNetworkCommissioningInstance(kNetworkCommissioningEndpointMain, &sNullNetworkDriver);
#endif // CHIP_DEVICE_LAYER_TARGET_LINUX
} // namespace

bool CustomOTARequestorDriver::CanConsent()
{
return gRequestorCanConsent.ValueOr(DeviceLayer::ExtendedOTARequestorDriver::CanConsent());
Expand Down Expand Up @@ -168,6 +199,68 @@ static void InitOTARequestor(void)
}
}

static void InitNetworkCommissioning(void)
{
(void) kNetworkCommissioningEndpointMain;
// Enable secondary endpoint only when we need it, this should be applied to all platforms.
emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false);

#if CHIP_DEVICE_LAYER_TARGET_LINUX
const bool kThreadEnabled = {
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
LinuxDeviceOptions::GetInstance().mThread
#else
false
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD
};

const bool kWiFiEnabled = {
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
LinuxDeviceOptions::GetInstance().mWiFi
#else
false
#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA
};

if (kThreadEnabled && kWiFiEnabled)
{
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
sThreadNetworkCommissioningInstance.Init();
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
sWiFiNetworkCommissioningInstance.Init();
#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA
// Only enable secondary endpoint for network commissioning cluster when both WiFi and Thread are enabled.
emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, true);
}
else if (kThreadEnabled)
{
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
sThreadNetworkCommissioningInstance.Init();
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD
}
else if (kWiFiEnabled)
{
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
// If we only enable WiFi on this device, "move" WiFi instance to main NetworkCommissioning cluster endpoint.
sWiFiNetworkCommissioningInstance.~Instance();
new (&sWiFiNetworkCommissioningInstance)
Clusters::NetworkCommissioning::Instance(kNetworkCommissioningEndpointMain, &sLinuxWiFiDriver);
sWiFiNetworkCommissioningInstance.Init();
#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA
}
else
#endif // CHIP_DEVICE_LAYER_TARGET_LINUX
{
#if CHIP_DEVICE_LAYER_TARGET_LINUX
sEthernetNetworkCommissioningInstance.Init();
#else
// Use NullNetworkCommissioningInstance to disable the network commissioning functions.
sNullNetworkCommissioningInstance.Init();
#endif // CHIP_DEVICE_LAYER_TARGET_LINUX
}
}

bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue)
{
bool retval = true;
Expand Down Expand Up @@ -233,6 +326,8 @@ void ApplicationInit()
{
// Initialize all OTA download components
InitOTARequestor();
// Initialize Network Commissioning instances
InitNetworkCommissioning();
}

int main(int argc, char * argv[])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -941,5 +941,21 @@ endpoint 0 {
ram attribute clusterRevision default = 1;
}
}
endpoint 65534 {
device type anonymousEndpointType = 61442;

server cluster NetworkCommissioning {
callback attribute maxNetworks;
callback attribute networks;
callback attribute scanMaxTimeSeconds;
callback attribute connectMaxTimeSeconds;
callback attribute interfaceEnabled;
callback attribute lastNetworkingStatus;
callback attribute lastNetworkID;
callback attribute lastConnectErrorValue;
callback attribute featureMap;
callback attribute clusterRevision default = 1;
}
}


Loading

0 comments on commit e5b9661

Please sign in to comment.