-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[YAML] Add a simple pairing API for YAML (#15075)
* [YAML] Add a simple pairing API for YAML * Update src/app/zap-templates/common/simulated-clusters/clusters/CommissionerCommands.js
- Loading branch information
1 parent
f625d9f
commit 9007363
Showing
14 changed files
with
249 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (c) 2022 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. | ||
|
||
import("//build_overrides/build.gni") | ||
import("//build_overrides/chip.gni") | ||
|
||
static_library("commissioner") { | ||
output_name = "libCommissionerCommands" | ||
|
||
sources = [ | ||
"CommissionerCommands.cpp", | ||
"CommissionerCommands.h", | ||
] | ||
|
||
cflags = [ "-Wconversion" ] | ||
|
||
public_deps = [ | ||
"${chip_root}/src/controller", | ||
"${chip_root}/src/lib/support", | ||
] | ||
} |
90 changes: 90 additions & 0 deletions
90
src/app/tests/suites/commands/commissioner/CommissionerCommands.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (c) 2022 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. | ||
* | ||
*/ | ||
|
||
#include "CommissionerCommands.h" | ||
|
||
constexpr uint16_t kPayloadMaxSize = 64; | ||
|
||
CHIP_ERROR CommissionerCommands::PairWithQRCode(chip::NodeId nodeId, const chip::CharSpan payload) | ||
{ | ||
VerifyOrReturnError(payload.size() > 0 && payload.size() < kPayloadMaxSize, CHIP_ERROR_INVALID_ARGUMENT); | ||
|
||
GetCurrentCommissioner().RegisterPairingDelegate(this); | ||
|
||
char qrCode[kPayloadMaxSize]; | ||
memcpy(qrCode, payload.data(), payload.size()); | ||
return GetCurrentCommissioner().PairDevice(nodeId, qrCode); | ||
} | ||
|
||
CHIP_ERROR CommissionerCommands::PairWithManualCode(chip::NodeId nodeId, const chip::CharSpan payload) | ||
{ | ||
VerifyOrReturnError(payload.size() > 0 && payload.size() < kPayloadMaxSize, CHIP_ERROR_INVALID_ARGUMENT); | ||
|
||
GetCurrentCommissioner().RegisterPairingDelegate(this); | ||
|
||
char manualCode[kPayloadMaxSize]; | ||
memcpy(manualCode, payload.data(), payload.size()); | ||
return GetCurrentCommissioner().PairDevice(nodeId, manualCode); | ||
} | ||
|
||
CHIP_ERROR CommissionerCommands::Unpair(chip::NodeId nodeId) | ||
{ | ||
return GetCurrentCommissioner().UnpairDevice(nodeId); | ||
} | ||
|
||
void CommissionerCommands::OnStatusUpdate(DevicePairingDelegate::Status status) | ||
{ | ||
switch (status) | ||
{ | ||
case DevicePairingDelegate::Status::SecurePairingSuccess: | ||
ChipLogProgress(chipTool, "Secure Pairing Success"); | ||
break; | ||
case DevicePairingDelegate::Status::SecurePairingFailed: | ||
ChipLogError(chipTool, "Secure Pairing Failed"); | ||
break; | ||
} | ||
} | ||
|
||
void CommissionerCommands::OnPairingComplete(CHIP_ERROR err) | ||
{ | ||
if (CHIP_NO_ERROR != err) | ||
{ | ||
ChipLogError(chipTool, "Pairing Complete Failure: %s", ErrorStr(err)); | ||
LogErrorOnFailure(ContinueOnChipMainThread(err)); | ||
} | ||
} | ||
|
||
void CommissionerCommands::OnPairingDeleted(CHIP_ERROR err) | ||
{ | ||
if (CHIP_NO_ERROR != err) | ||
{ | ||
ChipLogError(chipTool, "Pairing Delete Failure: %s", ErrorStr(err)); | ||
} | ||
|
||
LogErrorOnFailure(ContinueOnChipMainThread(err)); | ||
} | ||
|
||
void CommissionerCommands::OnCommissioningComplete(chip::NodeId nodeId, CHIP_ERROR err) | ||
{ | ||
if (CHIP_NO_ERROR != err) | ||
{ | ||
ChipLogError(chipTool, "Commissioning Complete Failure: %s", ErrorStr(err)); | ||
} | ||
|
||
LogErrorOnFailure(ContinueOnChipMainThread(err)); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/app/tests/suites/commands/commissioner/CommissionerCommands.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2022 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 <lib/support/CodeUtils.h> | ||
|
||
class CommissionerCommands : public chip::Controller::DevicePairingDelegate | ||
{ | ||
public: | ||
CommissionerCommands(){}; | ||
virtual ~CommissionerCommands(){}; | ||
|
||
virtual CHIP_ERROR ContinueOnChipMainThread(CHIP_ERROR err) = 0; | ||
virtual chip::Controller::DeviceCommissioner & GetCurrentCommissioner() = 0; | ||
|
||
CHIP_ERROR PairWithQRCode(chip::NodeId nodeId, const chip::CharSpan payload); | ||
CHIP_ERROR PairWithManualCode(chip::NodeId nodeId, const chip::CharSpan payload); | ||
CHIP_ERROR Unpair(chip::NodeId nodeId); | ||
|
||
/////////// DevicePairingDelegate Interface ///////// | ||
void OnStatusUpdate(chip::Controller::DevicePairingDelegate::Status status) override; | ||
void OnPairingComplete(CHIP_ERROR error) override; | ||
void OnPairingDeleted(CHIP_ERROR error) override; | ||
void OnCommissioningComplete(chip::NodeId deviceId, CHIP_ERROR error) override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/app/zap-templates/common/simulated-clusters/clusters/CommissionerCommands.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 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. | ||
*/ | ||
|
||
/* | ||
* This file declare test suites utilities methods for commissioner commands. | ||
* | ||
* Each method declared in this file needs to be implemented on a per-language | ||
* basis and permits to exposes methods to the test suites that are not part | ||
* of the regular cluster set of APIs. | ||
* | ||
*/ | ||
|
||
const PairWithQRCode = { | ||
name : 'PairWithQRCode', | ||
arguments : [ { type : 'NODE_ID', name : 'nodeId' }, { type : 'CHAR_STRING', name : 'payload' } ], | ||
response : { arguments : [] } | ||
}; | ||
|
||
const PairWithManualCode = { | ||
name : 'PairWithManualCode', | ||
arguments : [ { type : 'NODE_ID', name : 'nodeId' }, { type : 'CHAR_STRING', name : 'payload' } ], | ||
response : { arguments : [] } | ||
}; | ||
|
||
const Unpair = { | ||
name : 'Unpair', | ||
arguments : [ { type : 'NODE_ID', name : 'nodeId' } ], | ||
response : { arguments : [] } | ||
}; | ||
|
||
const name = 'CommissionerCommands'; | ||
const commands = [ PairWithQRCode, PairWithManualCode, Unpair ]; | ||
|
||
const CommissionerCommands = { | ||
name, | ||
commands | ||
}; | ||
|
||
// | ||
// Module exports | ||
// | ||
exports.cluster = CommissionerCommands; |