Skip to content

Commit

Permalink
Merge branch 'master' into ota-clusters-update
Browse files Browse the repository at this point in the history
  • Loading branch information
holbrookt committed Sep 21, 2021
2 parents 4158726 + 1d12139 commit 1e2b55d
Show file tree
Hide file tree
Showing 38 changed files with 1,162 additions and 377 deletions.
11 changes: 11 additions & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ AppConfig
ApplicationBasic
ApplicationLauncher
approver
appspot
aps
arg
argc
Expand All @@ -56,6 +57,7 @@ autocrlf
autogenerated
automake
autotools
avL
AwaitNextAction
AXXXF
babaf
Expand Down Expand Up @@ -137,6 +139,8 @@ ChipMessageLayer
CHIPTool
chmod
chrpath
cipd
CIPD
CircleCI
cJTAG
CKIT
Expand Down Expand Up @@ -202,6 +206,7 @@ CurrentHue
CurrentLevel
CurrentSaturation
customizations
cvfJ
cxx
CY
DAC
Expand All @@ -222,6 +227,7 @@ DEDEDEDE
DelayedActionTime
demangle
deployable
depottools
deps
desc
descheduled
Expand Down Expand Up @@ -377,6 +383,7 @@ gni
GNinja
gnuarmemb
GNUARMEMB
gnueabihf
googleapis
googlesource
GPG
Expand All @@ -389,6 +396,7 @@ GroupId
GroupKeyManagement
gtk
Gv
gz
hardcoded
hardknott
HardwareVersion
Expand Down Expand Up @@ -745,6 +753,7 @@ RPCs
RPi
rsn
RSSI
rsync
rtld
RTOS
RTT
Expand Down Expand Up @@ -821,6 +830,7 @@ sudo
svg
SVR
SWD
symlinks
sysconfdir
SysConfig
sysctl
Expand Down Expand Up @@ -866,6 +876,7 @@ TODO
toolchain
toolchains
topologies
tos
totalTests
trackAlloc
trackFree
Expand Down
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
18 changes: 18 additions & 0 deletions build_overrides/tizen.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2021 Project CHIP Authors
#
# 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.

declare_args() {
# Root directory for tizen.
tizen_root = "//config/tizen/chip-gn/platform"
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c
uint32_t delayedActionTimeSec = 0;
uint32_t newSoftwareVersion = softwareVersion + 1; // This implementation will always indicate that an update is available
// (if the user provides a file).
bool userConsentNeeded = false;
uint8_t updateToken[kUpdateTokenLen] = { 0 };
char strBuf[kUpdateTokenStrLen] = { 0 };
char uriBuf[kUriMaxLen] = { 0 };
constexpr char kExampleSoftwareString[] = "Example-Image-V0.1";
bool userConsentNeeded = false;
uint8_t updateToken[kUpdateTokenLen] = { 0 };
char strBuf[kUpdateTokenStrLen] = { 0 };
char uriBuf[kUriMaxLen] = { 0 };

GenerateUpdateToken(updateToken, kUpdateTokenLen);
GetUpdateTokenString(ByteSpan(updateToken), strBuf, kUpdateTokenStrLen);
Expand All @@ -133,6 +134,7 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c
VerifyOrReturnError(writer->Put(ContextTag(tagNum++), delayedActionTimeSec) == CHIP_NO_ERROR, EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError(writer->PutString(ContextTag(tagNum++), uriBuf) == CHIP_NO_ERROR, EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError(writer->Put(ContextTag(tagNum++), newSoftwareVersion) == CHIP_NO_ERROR, EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError(writer->PutString(ContextTag(tagNum++), kExampleSoftwareString) == CHIP_NO_ERROR, EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError(writer->PutBytes(ContextTag(tagNum++), updateToken, kUpdateTokenLen) == CHIP_NO_ERROR,
EMBER_ZCL_STATUS_FAILURE);
VerifyOrReturnError(writer->Put(ContextTag(tagNum++), userConsentNeeded) == CHIP_NO_ERROR, EMBER_ZCL_STATUS_FAILURE);
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 1e2b55d

Please sign in to comment.