-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[network-manager-app] pending dataset support over ubus #73309
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
Draft
LorbusChris
wants to merge
5
commits into
project-chip:master
Choose a base branch
from
LorbusChris:network-manager-pending-dataset
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ae08c19
[network-manager] implement RevertActiveDataset in the fake delegate
LorbusChris 5987352
[network-manager] support pending datasets in the ubus delegate
LorbusChris 2d28f10
[network-manager] invoke provision and deprovision asynchronously
LorbusChris 10e7c26
[network-manager] publish a matter ubus object
LorbusChris 19b112e
[network-manager] guard revert and advertise the device name
LorbusChris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
171 changes: 171 additions & 0 deletions
171
examples/network-manager-app/linux/MatterUbusService.cpp
This file contains hidden or 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,171 @@ | ||
| /* | ||
| * Copyright (c) 2026 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 "MatterUbusService.h" | ||
|
|
||
| #include "UboxUtils.h" | ||
|
|
||
| #include <app/server/Server.h> | ||
| #include <lib/support/CodeUtils.h> | ||
| #include <platform/CHIPDeviceLayer.h> | ||
| #include <setup_payload/OnboardingCodesUtil.h> | ||
|
|
||
| extern "C" { | ||
| #include <libubus.h> | ||
| #undef fallthrough | ||
| } | ||
|
|
||
| using namespace chip::app::Clusters::AdministratorCommissioning; | ||
|
|
||
| namespace chip { | ||
|
|
||
| namespace { | ||
|
|
||
| // The spec caps a commissioning window at 15 minutes; default to the maximum, | ||
| // since the code is meant to be typed into a controller by a person. | ||
| constexpr uint32_t kDefaultWindowSeconds = 900; | ||
| constexpr uint32_t kMinWindowSeconds = 180; | ||
|
|
||
| const char * WindowStatusString() | ||
| { | ||
| // Not CommissioningWindowStatusForCluster(): that deliberately reports | ||
| // locally opened windows as closed, because the cluster attribute only | ||
| // covers windows opened through it. Here the local ones are the point. | ||
| auto & mgr = Server::GetInstance().GetCommissioningWindowManager(); | ||
| if (!mgr.IsCommissioningWindowOpen()) | ||
| { | ||
| return "closed"; | ||
| } | ||
| switch (mgr.CommissioningWindowStatusForCluster()) | ||
| { | ||
| case CommissioningWindowStatusEnum::kEnhancedWindowOpen: | ||
| return "enhanced"; | ||
| case CommissioningWindowStatusEnum::kBasicWindowOpen: | ||
| default: | ||
| // A window opened locally is always a basic window. | ||
| return "basic"; | ||
| } | ||
| } | ||
|
|
||
| void AddOnboarding(ubus::BlobMsgBuf & buf) | ||
| { | ||
| PayloadContents payload; | ||
| if (GetPayloadContents(payload, RendezvousInformationFlag::kOnNetwork) == CHIP_NO_ERROR) | ||
| { | ||
| char code[32] = {}; | ||
| char qr[128] = {}; | ||
| MutableCharSpan codeSpan(code), qrSpan(qr); | ||
| if (GetManualPairingCode(codeSpan, payload) == CHIP_NO_ERROR) | ||
| { | ||
| buf.Add("ManualCode", static_cast<const char *>(code)); | ||
| } | ||
| if (GetQRCode(qrSpan, payload) == CHIP_NO_ERROR) | ||
| { | ||
| buf.Add("QrCode", static_cast<const char *>(qr)); | ||
| } | ||
| buf.Add("VendorId", static_cast<uint32_t>(payload.vendorID)); | ||
| buf.Add("ProductId", static_cast<uint32_t>(payload.productID)); | ||
| buf.Add("Discriminator", static_cast<uint32_t>(payload.discriminator.GetLongValue())); | ||
| } | ||
| } | ||
|
|
||
| int HandleStatus(ubus_context * ctx, ubus_object * obj, ubus_request_data * req, const char * method, blob_attr * msg) | ||
| { | ||
| ubus::BlobMsgBuf buf; | ||
| buf.Add("Fabrics", static_cast<uint32_t>(Server::GetInstance().GetFabricTable().FabricCount())); | ||
| buf.Add("Window", WindowStatusString()); | ||
| // The initial onboarding code authenticates commissioning only while no | ||
| // fabric is on the device (the initial basic window) or while a basic | ||
| // window is open; report it so a UI can decide what to show. | ||
| AddOnboarding(buf); | ||
| ubus_send_reply(ctx, req, buf.head); | ||
| return 0; | ||
| } | ||
|
|
||
| enum | ||
| { | ||
| OPEN_WINDOW_TIMEOUT, | ||
| __OPEN_WINDOW_MAX, | ||
| }; | ||
|
|
||
| const blobmsg_policy kOpenWindowPolicy[__OPEN_WINDOW_MAX] = { | ||
| [OPEN_WINDOW_TIMEOUT] = { .name = "timeout", .type = BLOBMSG_TYPE_INT32 }, | ||
| }; | ||
|
|
||
| int HandleOpenWindow(ubus_context * ctx, ubus_object * obj, ubus_request_data * req, const char * method, blob_attr * msg) | ||
| { | ||
| // A caller can omit the argument table entirely; msg is NULL then. | ||
| blob_attr * tb[__OPEN_WINDOW_MAX] = {}; | ||
| if (msg != nullptr) | ||
| { | ||
| blobmsg_parse(kOpenWindowPolicy, __OPEN_WINDOW_MAX, tb, blobmsg_data(msg), blobmsg_len(msg)); | ||
| } | ||
|
|
||
| uint32_t timeout = kDefaultWindowSeconds; | ||
| if (tb[OPEN_WINDOW_TIMEOUT] != nullptr) | ||
| { | ||
| timeout = blobmsg_get_u32(tb[OPEN_WINDOW_TIMEOUT]); | ||
| VerifyOrReturnValue(timeout >= kMinWindowSeconds && timeout <= kDefaultWindowSeconds, UBUS_STATUS_INVALID_ARGUMENT); | ||
| } | ||
|
|
||
| // Opens a basic window: the device's own onboarding code becomes valid | ||
| // for the duration, which is what lets a router UI show a code that a | ||
| // controller can actually use after the device is already commissioned. | ||
| auto & mgr = Server::GetInstance().GetCommissioningWindowManager(); | ||
| CHIP_ERROR err = mgr.OpenBasicCommissioningWindow(System::Clock::Seconds32(timeout)); | ||
|
LorbusChris marked this conversation as resolved.
LorbusChris marked this conversation as resolved.
LorbusChris marked this conversation as resolved.
LorbusChris marked this conversation as resolved.
|
||
|
|
||
| ubus::BlobMsgBuf buf; | ||
| buf.Add("Error", static_cast<uint32_t>(err == CHIP_NO_ERROR ? 0 : 1)); | ||
| buf.Add("Window", WindowStatusString()); | ||
| ubus_send_reply(ctx, req, buf.head); | ||
| return 0; | ||
| } | ||
|
|
||
| int HandleCloseWindow(ubus_context * ctx, ubus_object * obj, ubus_request_data * req, const char * method, blob_attr * msg) | ||
| { | ||
| Server::GetInstance().GetCommissioningWindowManager().CloseCommissioningWindow(); | ||
|
LorbusChris marked this conversation as resolved.
|
||
|
|
||
| ubus::BlobMsgBuf buf; | ||
| buf.Add("Error", static_cast<uint32_t>(0)); | ||
| buf.Add("Window", WindowStatusString()); | ||
| ubus_send_reply(ctx, req, buf.head); | ||
| return 0; | ||
| } | ||
|
|
||
| ubus_method sMethods[] = { | ||
| UBUS_METHOD_NOARG("status", HandleStatus), | ||
| UBUS_METHOD("open_commissioning_window", HandleOpenWindow, kOpenWindowPolicy), | ||
| UBUS_METHOD_NOARG("close_commissioning_window", HandleCloseWindow), | ||
| }; | ||
|
|
||
| ubus_object_type sObjectType = UBUS_OBJECT_TYPE("matter", sMethods); | ||
|
|
||
| ubus_object sObject = { | ||
| .name = "matter", | ||
| .type = &sObjectType, | ||
| .methods = sMethods, | ||
| .n_methods = MATTER_ARRAY_SIZE(sMethods), | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| CHIP_ERROR MatterUbusService::Init() | ||
| { | ||
| return mUbusManager.Host(sObject); | ||
| } | ||
|
|
||
| } // namespace chip | ||
This file contains hidden or 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,38 @@ | ||
| /* | ||
| * Copyright (c) 2026 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 "UbusManager.h" | ||
|
|
||
| namespace chip { | ||
|
|
||
| // Publishes a "matter" ubus object exposing this node's onboarding | ||
| // information and local control of the commissioning window, so a router UI | ||
| // can pair the device with a controller without access to the daemon's log. | ||
| class MatterUbusService | ||
| { | ||
| public: | ||
| MatterUbusService(ubus::UbusManager & ubusManager) : mUbusManager(ubusManager) {} | ||
|
|
||
| CHIP_ERROR Init(); | ||
|
|
||
| private: | ||
| ubus::UbusManager & mUbusManager; | ||
| }; | ||
|
|
||
| } // namespace chip |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.