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

Link attribute reads to Content Apps, refactor content app platform to leverage latest cluster lib conventions #12969

Merged
merged 63 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
4ef5cdd
link attribute reads to Content Apps
chrisdecenzo Dec 13, 2021
8cb6fb7
Merge branch 'master' of github.com:project-chip/connectedhomeip into…
chrisdecenzo Dec 15, 2021
43ea264
address some comments
chrisdecenzo Dec 15, 2021
ec99cc2
Merge branch 'master' of github.com:project-chip/connectedhomeip into…
chrisdecenzo Dec 16, 2021
7478963
route attribute reads and writes to per-cluster handlers
chrisdecenzo Dec 16, 2021
5e5a152
Merge branch 'master' of github.com:project-chip/connectedhomeip into…
decenzo Dec 17, 2021
8505e03
refactor content app
decenzo Dec 21, 2021
8a11b4e
straggler
decenzo Dec 21, 2021
03868a3
use MEI log format commands
decenzo Dec 22, 2021
c0e2690
Merge branch 'master' of github.com:project-chip/connectedhomeip into…
decenzo Dec 22, 2021
cdc026a
fix tv-app test suites
chrisdecenzo Dec 23, 2021
5b1ea4e
fix tv-app test suites
chrisdecenzo Dec 23, 2021
ba53262
sync to TOT
chrisdecenzo Dec 23, 2021
6ded4c7
fix CI test suites
chrisdecenzo Dec 23, 2021
f31ce97
fix CI test suites
chrisdecenzo Dec 24, 2021
0152677
add bindings call
chrisdecenzo Jan 4, 2022
efd362d
sync to TOT
chrisdecenzo Jan 4, 2022
0507e85
migrate content app to use new account login delegate
chrisdecenzo Jan 4, 2022
2356cc9
refactor ContentApp to use delegates
chrisdecenzo Jan 5, 2022
d4ef9c9
Merge branch 'master' of github.com:project-chip/connectedhomeip into…
chrisdecenzo Jan 5, 2022
aa395e8
fix CI errors
chrisdecenzo Jan 5, 2022
07da92d
fix CI errors
chrisdecenzo Jan 5, 2022
71b9a43
fix CI errors
chrisdecenzo Jan 5, 2022
b8e6657
more ContentApp to app-platform directory
chrisdecenzo Jan 6, 2022
4fe3715
address issue 13144
chrisdecenzo Jan 6, 2022
bd5db22
address issue 12543
chrisdecenzo Jan 7, 2022
db9d88d
sync to TOT
chrisdecenzo Jan 12, 2022
5a97eb1
address comments
chrisdecenzo Jan 12, 2022
b04b81c
address comments
chrisdecenzo Jan 14, 2022
edd266e
fix handling of application launcher, application basic status and co…
chrisdecenzo Jan 16, 2022
55f37a7
sync TOT
chrisdecenzo Jan 16, 2022
04e3793
fix build
chrisdecenzo Jan 16, 2022
159ec20
fix android build
chrisdecenzo Jan 16, 2022
dffd77b
fix android build
chrisdecenzo Jan 16, 2022
840df4a
Merge branch 'master' of github.com:project-chip/connectedhomeip into…
chrisdecenzo Jan 17, 2022
2d39958
add Commissioner Discovery Controller to manage UDC workflow
chrisdecenzo Jan 20, 2022
0d0c71d
address comments
chrisdecenzo Jan 23, 2022
fa48726
address comments
chrisdecenzo Jan 24, 2022
fb76264
fix builds
chrisdecenzo Jan 24, 2022
d0b5b7f
fix builds
chrisdecenzo Jan 24, 2022
514cbcf
fix builds
chrisdecenzo Jan 24, 2022
9c20d42
address comments
chrisdecenzo Jan 24, 2022
024f5dd
fix potential leak on commands
chrisdecenzo Jan 24, 2022
0b147d2
fix potential leak on attribute reads
chrisdecenzo Jan 25, 2022
ea68629
fix potential leak on attribute reads
chrisdecenzo Jan 25, 2022
e176842
merge with TOT
chrisdecenzo Jan 25, 2022
f165fc7
Merge branch 'master' of github.com:project-chip/connectedhomeip into…
chrisdecenzo Jan 25, 2022
98326ef
argument and naming consistency
chrisdecenzo Jan 25, 2022
58929fd
fix android build
chrisdecenzo Jan 25, 2022
dad1adc
fix android build
chrisdecenzo Jan 25, 2022
76f19fd
fix android build
chrisdecenzo Jan 25, 2022
9edc45a
fix android build
chrisdecenzo Jan 25, 2022
8c5df04
address easy comments
chrisdecenzo Jan 25, 2022
d3cb64a
fix android build
chrisdecenzo Jan 26, 2022
f71f4ba
sync to TOT
chrisdecenzo Jan 26, 2022
c6bc7b9
fix android
chrisdecenzo Jan 26, 2022
4988e77
fix merge issue
chrisdecenzo Jan 26, 2022
b7dc8fb
optimize image size
chrisdecenzo Jan 26, 2022
6514946
fix build
chrisdecenzo Jan 26, 2022
940011d
attempt to fix CI build
chrisdecenzo Jan 26, 2022
7abcd0f
attempt to fix CI build
chrisdecenzo Jan 26, 2022
9de31b4
attempt to fix CI build
chrisdecenzo Jan 26, 2022
d37b84b
reduce dependencies
chrisdecenzo Jan 27, 2022
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
141 changes: 100 additions & 41 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ static constexpr uint8_t kWiFiStartCheckAttempts = 5;
#endif

namespace {
void EventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg)
void EventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg)
{
(void) arg;
if (event->Type == chip::DeviceLayer::DeviceEventType::kCHIPoBLEConnectionEstablished)
if (event->Type == DeviceLayer::DeviceEventType::kCHIPoBLEConnectionEstablished)
{
ChipLogProgress(DeviceLayer, "Receive kCHIPoBLEConnectionEstablished");
}
Expand All @@ -95,35 +95,35 @@ static bool EnsureWiFiIsStarted()
{
for (int cnt = 0; cnt < kWiFiStartCheckAttempts; cnt++)
{
if (chip::DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted())
if (DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted())
{
return true;
}

usleep(kWiFiStartCheckTimeUsec);
}

return chip::DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted();
return DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted();
}
#endif

int ChipLinuxAppInit(int argc, char ** argv)
{
CHIP_ERROR err = CHIP_NO_ERROR;
#if CONFIG_NETWORK_LAYER_BLE
chip::RendezvousInformationFlags rendezvousFlags = chip::RendezvousInformationFlag::kBLE;
RendezvousInformationFlags rendezvousFlags = RendezvousInformationFlag::kBLE;
#else // CONFIG_NETWORK_LAYER_BLE
chip::RendezvousInformationFlag rendezvousFlags = RendezvousInformationFlag::kOnNetwork;
RendezvousInformationFlag rendezvousFlags = RendezvousInformationFlag::kOnNetwork;
#endif // CONFIG_NETWORK_LAYER_BLE

#ifdef CONFIG_RENDEZVOUS_MODE
rendezvousFlags = static_cast<chip::RendezvousInformationFlags>(CONFIG_RENDEZVOUS_MODE);
rendezvousFlags = static_cast<RendezvousInformationFlags>(CONFIG_RENDEZVOUS_MODE);
#endif

err = chip::Platform::MemoryInit();
err = Platform::MemoryInit();
SuccessOrExit(err);

err = chip::DeviceLayer::PlatformMgr().InitChipStack();
err = DeviceLayer::PlatformMgr().InitChipStack();
SuccessOrExit(err);

err = GetSetupPayload(LinuxDeviceOptions::GetInstance().payload, rendezvousFlags);
Expand All @@ -137,22 +137,22 @@ int ChipLinuxAppInit(int argc, char ** argv)
PrintOnboardingCodes(LinuxDeviceOptions::GetInstance().payload);

#if defined(PW_RPC_ENABLED)
chip::rpc::Init();
rpc::Init();
ChipLogProgress(NotSpecified, "PW_RPC initialized.");
#endif // defined(PW_RPC_ENABLED)

chip::DeviceLayer::PlatformMgrImpl().AddEventHandler(EventHandler, 0);
DeviceLayer::PlatformMgrImpl().AddEventHandler(EventHandler, 0);

#if CONFIG_NETWORK_LAYER_BLE
chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName(nullptr); // Use default device name (CHIP-XXXX)
chip::DeviceLayer::Internal::BLEMgrImpl().ConfigureBle(LinuxDeviceOptions::GetInstance().mBleDevice, false);
chip::DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(true);
DeviceLayer::ConnectivityMgr().SetBLEDeviceName(nullptr); // Use default device name (CHIP-XXXX)
DeviceLayer::Internal::BLEMgrImpl().ConfigureBle(LinuxDeviceOptions::GetInstance().mBleDevice, false);
DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(true);
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_WPA
if (LinuxDeviceOptions::GetInstance().mWiFi)
{
chip::DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement();
DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement();
if (!EnsureWiFiIsStarted())
{
ChipLogError(NotSpecified, "Wi-Fi Management taking too long to start - device configuration will be reset.");
Expand All @@ -163,7 +163,7 @@ int ChipLinuxAppInit(int argc, char ** argv)
#if CHIP_ENABLE_OPENTHREAD
if (LinuxDeviceOptions::GetInstance().mThread)
{
SuccessOrExit(err = chip::DeviceLayer::ThreadStackMgrImpl().InitThreadStack());
SuccessOrExit(err = DeviceLayer::ThreadStackMgrImpl().InitThreadStack());
ChipLogProgress(NotSpecified, "Thread initialized.");
}
#endif // CHIP_ENABLE_OPENTHREAD
Expand Down Expand Up @@ -209,17 +209,26 @@ class MyServerStorageDelegate : public PersistentStorageDelegate
}
};

class MyCommissionerCallback : public CommissionerCallback
{
void ReadyForCommissioning(uint32_t pincode, uint16_t longDiscriminator, PeerAddress peerAddress) override
{
CommissionerPairOnNetwork(pincode, longDiscriminator, peerAddress);
}
};

DeviceCommissioner gCommissioner;
CommissionerDiscoveryController gCommissionerDiscoveryController;
MyCommissionerCallback gCommissionerCallback;
MyServerStorageDelegate gServerStorage;
chip::SimpleFabricStorage gFabricStorage;
SimpleFabricStorage gFabricStorage;
ExampleOperationalCredentialsIssuer gOpCredsIssuer;
NodeId gLocalId = kPlaceholderNodeId;

CHIP_ERROR InitCommissioner()
{
NodeId localId = chip::kPlaceholderNodeId;

chip::Controller::FactoryInitParams factoryParams;
chip::Controller::SetupParams params;
Controller::FactoryInitParams factoryParams;
Controller::SetupParams params;

ReturnErrorOnFailure(gFabricStorage.Initialize(&gServerStorage));

Expand All @@ -237,49 +246,60 @@ CHIP_ERROR InitCommissioner()

// Initialize device attestation verifier
// TODO: Replace testingRootStore with a AttestationTrustStore that has the necessary official PAA roots available
const chip::Credentials::AttestationTrustStore * testingRootStore = chip::Credentials::GetTestAttestationTrustStore();
const Credentials::AttestationTrustStore * testingRootStore = Credentials::GetTestAttestationTrustStore();
SetDeviceAttestationVerifier(GetDefaultDACVerifier(testingRootStore));

chip::Platform::ScopedMemoryBuffer<uint8_t> noc;
VerifyOrReturnError(noc.Alloc(chip::Controller::kMaxCHIPDERCertLength), CHIP_ERROR_NO_MEMORY);
chip::MutableByteSpan nocSpan(noc.Get(), chip::Controller::kMaxCHIPDERCertLength);
Platform::ScopedMemoryBuffer<uint8_t> noc;
VerifyOrReturnError(noc.Alloc(Controller::kMaxCHIPDERCertLength), CHIP_ERROR_NO_MEMORY);
MutableByteSpan nocSpan(noc.Get(), Controller::kMaxCHIPDERCertLength);

chip::Platform::ScopedMemoryBuffer<uint8_t> icac;
VerifyOrReturnError(icac.Alloc(chip::Controller::kMaxCHIPDERCertLength), CHIP_ERROR_NO_MEMORY);
chip::MutableByteSpan icacSpan(icac.Get(), chip::Controller::kMaxCHIPDERCertLength);
Platform::ScopedMemoryBuffer<uint8_t> icac;
VerifyOrReturnError(icac.Alloc(Controller::kMaxCHIPDERCertLength), CHIP_ERROR_NO_MEMORY);
MutableByteSpan icacSpan(icac.Get(), Controller::kMaxCHIPDERCertLength);

chip::Platform::ScopedMemoryBuffer<uint8_t> rcac;
VerifyOrReturnError(rcac.Alloc(chip::Controller::kMaxCHIPDERCertLength), CHIP_ERROR_NO_MEMORY);
chip::MutableByteSpan rcacSpan(rcac.Get(), chip::Controller::kMaxCHIPDERCertLength);
Platform::ScopedMemoryBuffer<uint8_t> rcac;
VerifyOrReturnError(rcac.Alloc(Controller::kMaxCHIPDERCertLength), CHIP_ERROR_NO_MEMORY);
MutableByteSpan rcacSpan(rcac.Get(), Controller::kMaxCHIPDERCertLength);

chip::Crypto::P256Keypair ephemeralKey;
Crypto::P256Keypair ephemeralKey;
ReturnErrorOnFailure(ephemeralKey.Initialize());

ReturnErrorOnFailure(
gOpCredsIssuer.GenerateNOCChainAfterValidation(localId, 0, ephemeralKey.Pubkey(), rcacSpan, icacSpan, nocSpan));
gOpCredsIssuer.GenerateNOCChainAfterValidation(gLocalId, 0, ephemeralKey.Pubkey(), rcacSpan, icacSpan, nocSpan));

params.ephemeralKeypair = &ephemeralKey;
params.controllerRCAC = rcacSpan;
params.controllerICAC = icacSpan;
params.controllerNOC = nocSpan;

auto & factory = chip::Controller::DeviceControllerFactory::GetInstance();
auto & factory = Controller::DeviceControllerFactory::GetInstance();
ReturnErrorOnFailure(factory.Init(factoryParams));
ReturnErrorOnFailure(factory.SetupCommissioner(params, gCommissioner));
gCommissionerDiscoveryController.SetUserDirectedCommissioningServer(gCommissioner.GetUserDirectedCommissioningServer());
gCommissionerDiscoveryController.SetCommissionerCallback(&gCommissionerCallback);

return CHIP_NO_ERROR;
}

CHIP_ERROR ShutdownCommissioner()
{
UserDirectedCommissioningServer * udcServer = gCommissioner.GetUserDirectedCommissioningServer();
if (udcServer != nullptr)
{
udcServer->SetUserConfirmationProvider(nullptr);
}

gCommissioner.Shutdown();
return CHIP_NO_ERROR;
}

class PairingCommand : public chip::Controller::DevicePairingDelegate, public chip::Controller::DeviceAddressUpdateDelegate
class PairingCommand : public Controller::DevicePairingDelegate, public Controller::DeviceAddressUpdateDelegate
{
public:
PairingCommand() : mSuccessCallback(OnSuccessResponse, this), mFailureCallback(OnFailureResponse, this){};

/////////// DevicePairingDelegate Interface /////////
void OnStatusUpdate(chip::Controller::DevicePairingDelegate::Status status) override;
void OnStatusUpdate(Controller::DevicePairingDelegate::Status status) override;
void OnPairingComplete(CHIP_ERROR error) override;
void OnPairingDeleted(CHIP_ERROR error) override;
void OnCommissioningComplete(NodeId deviceId, CHIP_ERROR error) override;
Expand All @@ -288,6 +308,14 @@ class PairingCommand : public chip::Controller::DevicePairingDelegate, public ch
void OnAddressUpdateComplete(NodeId nodeId, CHIP_ERROR error) override;

CHIP_ERROR UpdateNetworkAddress();

/* Callback when command results in success */
static void OnSuccessResponse(void * context);
/* Callback when command results in failure */
static void OnFailureResponse(void * context, uint8_t status);

Callback::Callback<DefaultSuccessCallback> mSuccessCallback;
Callback::Callback<DefaultFailureCallback> mFailureCallback;
};

PairingCommand gPairingCommand;
Expand Down Expand Up @@ -346,19 +374,45 @@ void PairingCommand::OnPairingDeleted(CHIP_ERROR err)
}
}

void PairingCommand::OnSuccessResponse(void * context)
{
ChipLogProgress(Controller, "OnSuccessResponse");
}

void PairingCommand::OnFailureResponse(void * context, uint8_t status)
{
ChipLogProgress(Controller, "OnFailureResponse");
}

void PairingCommand::OnCommissioningComplete(NodeId nodeId, CHIP_ERROR err)
{
if (err == CHIP_NO_ERROR)
{
ChipLogProgress(AppServer, "Device commissioning completed with success");

// TODO:
// - this code needs to be conditional based upon Content App Platform enablement
// - the endpointId chosen should come from the App Platform (determined based upon vid/pid of node)
// - the cluster(s) chosen should come from the App Platform
constexpr EndpointId kBindingClusterEndpoint = 0;

Callback::Cancelable * successCallback = mSuccessCallback.Cancel();
Callback::Cancelable * failureCallback = mFailureCallback.Cancel();

GroupId groupId = kUndefinedGroupId;
EndpointId endpointId = 1;
ClusterId clusterId = kInvalidClusterId;

gCommissioner.CreateBindingWithCallback(nodeId, kBindingClusterEndpoint, gLocalId, groupId, endpointId, clusterId,
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
successCallback, failureCallback);
}
else
{
ChipLogProgress(AppServer, "Device commissioning Failure: %s", ErrorStr(err));
}
}

CHIP_ERROR CommissionerPairOnNetwork(uint32_t pincode, uint16_t disc, chip::Transport::PeerAddress address)
CHIP_ERROR CommissionerPairOnNetwork(uint32_t pincode, uint16_t disc, Transport::PeerAddress address)
{
RendezvousParameters params = RendezvousParameters().SetSetupPINCode(pincode).SetDiscriminator(disc).SetPeerAddress(address);

Expand Down Expand Up @@ -392,14 +446,19 @@ DeviceCommissioner * GetDeviceCommissioner()
return &gCommissioner;
}

CommissionerDiscoveryController * GetCommissionerDiscoveryController()
{
return &gCommissionerDiscoveryController;
}

#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE

void ChipLinuxAppMainLoop()
{
#if defined(ENABLE_CHIP_SHELL)
Engine::Root().Init();
std::thread shellThread([]() { Engine::Root().RunMainLoop(); });
chip::Shell::RegisterCommissioneeCommands();
Shell::RegisterCommissioneeCommands();
#endif
uint16_t securePort = CHIP_PORT;
uint16_t unsecurePort = CHIP_UDC_PORT;
Expand All @@ -411,7 +470,7 @@ void ChipLinuxAppMainLoop()
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE

// Init ZCL Data Model and CHIP App Server
chip::Server::GetInstance().Init(nullptr, securePort, unsecurePort);
Server::GetInstance().Init(nullptr, securePort, unsecurePort);

// 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
Expand All @@ -426,13 +485,13 @@ void ChipLinuxAppMainLoop()
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
InitCommissioner();
#if defined(ENABLE_CHIP_SHELL)
chip::Shell::RegisterControllerCommands();
Shell::RegisterControllerCommands();
#endif // defined(ENABLE_CHIP_SHELL)
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE

ApplicationInit();

chip::DeviceLayer::PlatformMgr().RunEventLoop();
DeviceLayer::PlatformMgr().RunEventLoop();

#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
ShutdownCommissioner();
Expand Down
8 changes: 5 additions & 3 deletions examples/platform/linux/AppMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <thread>

#include <controller/CHIPDeviceController.h>
#include <controller/CommissionerDiscoveryController.h>
#include <lib/core/CHIPError.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/PlatformManager.h>
Expand All @@ -32,13 +33,14 @@ void ChipLinuxAppMainLoop();

#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE

using namespace chip::Transport;
using namespace ::chip::Controller;
using chip::Controller::DeviceCommissioner;
using chip::Transport::PeerAddress;

CHIP_ERROR CommissionerPairOnNetwork(uint32_t pincode, uint16_t disc, chip::Transport::PeerAddress address);
CHIP_ERROR CommissionerPairOnNetwork(uint32_t pincode, uint16_t disc, PeerAddress address);
CHIP_ERROR CommissionerPairUDC(uint32_t pincode, size_t index);

DeviceCommissioner * GetDeviceCommissioner();
CommissionerDiscoveryController * GetCommissionerDiscoveryController();

#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE

Expand Down
Loading