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

Make ota-requestor-app build and run #9740

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
8 changes: 8 additions & 0 deletions .github/workflows/examples-linux-standalone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ jobs:
linux debug ota-provider-app \
out/ota_provider_debug/chip-ota-provider-app \
/tmp/bloat_reports/
- name: Build example OTA Requestor
timeout-minutes: 5
run: |
scripts/examples/gn_build_example.sh examples/ota-requestor-app/linux out/ota_requestor_debug
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
linux debug ota-requestor-app \
out/ota_requestor_debug/chip-ota-requestor-app \
/tmp/bloat_reports/
- name: Binary artifact suffix
id: outsuffix
uses: haya14busa/[email protected]
Expand Down
1 change: 1 addition & 0 deletions examples/ota-requestor-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import("//build_overrides/chip.gni")

executable("chip-ota-requestor-app") {
sources = [
"ExampleSelfCommissioning.h",
"PersistentStorage.cpp",
"main.cpp",
]
Expand Down
78 changes: 78 additions & 0 deletions examples/ota-requestor-app/linux/ExampleSelfCommissioning.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <controller/CHIPDeviceController.h>
#include <controller/ExampleOperationalCredentialsIssuer.h>
#include <crypto/CHIPCryptoPAL.h>
#include <lib/core/CHIPError.h>
#include <lib/core/CHIPPersistentStorageDelegate.h>
#include <lib/support/ScopedBuffer.h>

using chip::PersistentStorageDelegate;
using chip::Controller::DeviceController;
using chip::Controller::ExampleOperationalCredentialsIssuer;

CHIP_ERROR DoExampleSelfCommissioning(DeviceController & controller, ExampleOperationalCredentialsIssuer * opCredsIssuer,
PersistentStorageDelegate * storage, chip::NodeId localNodeId)
{
CHIP_ERROR err = CHIP_NO_ERROR;
chip::Platform::ScopedMemoryBuffer<uint8_t> noc;
chip::Platform::ScopedMemoryBuffer<uint8_t> icac;
chip::Platform::ScopedMemoryBuffer<uint8_t> rcac;
chip::Controller::ControllerInitParams initParams;

VerifyOrExit(storage != nullptr && opCredsIssuer != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);

err = opCredsIssuer->Initialize(*storage);
VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init failure! Operational Cred Issuer: %s", chip::ErrorStr(err)));

VerifyOrExit(rcac.Alloc(chip::Controller::kMaxCHIPDERCertLength), err = CHIP_ERROR_NO_MEMORY);
VerifyOrExit(noc.Alloc(chip::Controller::kMaxCHIPDERCertLength), err = CHIP_ERROR_NO_MEMORY);
VerifyOrExit(icac.Alloc(chip::Controller::kMaxCHIPDERCertLength), err = CHIP_ERROR_NO_MEMORY);

{
chip::MutableByteSpan nocSpan(noc.Get(), chip::Controller::kMaxCHIPDERCertLength);
chip::MutableByteSpan icacSpan(icac.Get(), chip::Controller::kMaxCHIPDERCertLength);
chip::MutableByteSpan rcacSpan(rcac.Get(), chip::Controller::kMaxCHIPDERCertLength);

chip::Crypto::P256Keypair ephemeralKey;
SuccessOrExit(err = ephemeralKey.Initialize());

// TODO - OpCreds should only be generated for pairing command
// store the credentials in persistent storage, and
// generate when not available in the storage.
err = opCredsIssuer->GenerateNOCChainAfterValidation(localNodeId, 0, ephemeralKey.Pubkey(), rcacSpan, icacSpan, nocSpan);
SuccessOrExit(err);

initParams.ephemeralKeypair = &ephemeralKey;
initParams.controllerRCAC = rcacSpan;
initParams.controllerICAC = icacSpan;
initParams.controllerNOC = nocSpan;
initParams.operationalCredentialsDelegate = opCredsIssuer;

initParams.storageDelegate = storage;

err = controller.Init(initParams);
VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Controller init failure! %s", chip::ErrorStr(err)));
}

exit:
return err;
}
30 changes: 23 additions & 7 deletions examples/ota-requestor-app/linux/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
# ota-requestor-app (Linux)

WARNING: this app currently does not build successfully. It is being submitted
as a starting point for further OTA Requestor development.

This is a reference application that is both a server for the OTA Requestor
Cluster, as well as a client of the OTA Provider Cluster. It should initiate a
Software Update with a given OTA Provider node, and download a file.

## Usage

Due to #9518, this app must pretend to be `chip-tool` in order to establish a
connection to the OTA Provider. It does this by reading the CASE session and
other necessary credentials stored in persistent memory on startup.

Therefore, to use this app you should call these commands in the following
order:

In one terminal:

```
./chip-ota-provider-app [-f <filepath>]
```

In a second terminal:

```
./chip-tool pairing onnetwork 0 20202021 3840 ::1 5540
./chip-ota-requestor-app [-p <provider node id>]
```

## Current Features / Limitations

### Features

- Code for running a full BDX download exists in BDX
- Sends QueryImage command
- Takes a peer Node ID as an argument

### Limitations

- needs chip-tool to pair to the Provider device first, so it can steal the
CASE session from persisted memory
- uses Controller class to load the CASE session
- Controller does not provide any way to access a new ExchangeContext for the
BDX exchange
- doesn't wait for QueryImageResponse to begin the BDX exchange
- does not verify QueryImageResponse message contents
- stores the downloaded file at a hardcoded filepath
- doesn't close the BDX ExchangeContext when the exchange is over
- only uses hardcoded node IDs
- does not support AnnounceOTAProvider command or OTA Requestor attributes
Loading