Skip to content

Commit

Permalink
Make ota-requestor-app build and run (#9740)
Browse files Browse the repository at this point in the history
* add build changes and program arguments to make requestor work

* remove requestor cluster and regen

* fix SystemLayer reference

* print output file name at transfer end and edit README

and remove dead code

* add ota-requestor-app to CI

* apply changes from Tennessee:

- move self-commissioning code into its own file
- rename example args for QueryImage
- remove location param null-terminator
- leave metadata empty
- change "peerId" to "providerLocation"

* add new file for slef-commissioning code
  • Loading branch information
holbrookt authored and pull[bot] committed Sep 30, 2021
1 parent 2f7262a commit 7e0c1a2
Show file tree
Hide file tree
Showing 12 changed files with 307 additions and 343 deletions.
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/action-cond@v1.0.0
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

0 comments on commit 7e0c1a2

Please sign in to comment.