From 4203209755e2e8738712d4c3c27d2b52cb05a010 Mon Sep 17 00:00:00 2001 From: rgoliver Date: Fri, 18 Nov 2022 10:03:32 -0500 Subject: [PATCH] RPC: SetPairingState open CommissioningWindow (#23622) If the commissioning window isn't already open open a basic one when SetPairingState is true. Similarily close the commissioining window if SetPairingState is false. --- examples/common/pigweed/rpc_services/Device.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/common/pigweed/rpc_services/Device.h b/examples/common/pigweed/rpc_services/Device.h index 65bc2494484957..758ecc9c454259 100644 --- a/examples/common/pigweed/rpc_services/Device.h +++ b/examples/common/pigweed/rpc_services/Device.h @@ -270,14 +270,22 @@ class Device : public pw_rpc::nanopb::Device::Service virtual pw::Status SetPairingState(const chip_rpc_PairingState & request, pw_protobuf_Empty & response) { - if (request.pairing_enabled) + if (request.pairing_enabled && !chip::Server::GetInstance().GetCommissioningWindowManager().IsCommissioningWindowOpen()) { - DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(true); - DeviceLayer::ConnectivityMgr().SetBLEAdvertisingMode(DeviceLayer::ConnectivityMgr().kFastAdvertising); + DeviceLayer::StackLock lock; + chip::ChipError err = chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow(); + if (err != CHIP_NO_ERROR) + { + ChipLogError(NotSpecified, "RPC SetPairingState failed to open commissioning window: %" CHIP_ERROR_FORMAT, + err.Format()); + return pw::Status::Internal(); + } } - else + else if (!request.pairing_enabled && + chip::Server::GetInstance().GetCommissioningWindowManager().IsCommissioningWindowOpen()) { - DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(false); + DeviceLayer::StackLock lock; + chip::Server::GetInstance().GetCommissioningWindowManager().CloseCommissioningWindow(); } return pw::OkStatus(); }